From 888e6371ff5a0773b6984ca1af7e5fbfcd1d9d5a Mon Sep 17 00:00:00 2001 From: Mihail Stoykov <312246+mstoykov@users.noreply.github.com> Date: Thu, 2 Jul 2026 11:18:30 +0300 Subject: [PATCH 001/182] ci: centralize CI Go versions into .github/go-versions.env (#6112) The Go versions used across the CI workflows were hardcoded in each file. With the Renovate manager added in #5981, the deliberate N-1 matrix entry in test.yml/test-browser.yml looked identical to the current-version entry, so Renovate tried to bump it to latest (#6085), collapsing the current + previous coverage into testing one version twice. Introduce .github/go-versions.env as the single source of truth for GO_VERSION_CURRENT and GO_VERSION_PREV, read via a new .github/actions/go-versions composite action. Non-matrix workflows (lint, tc39, wpt, xk6) and the lint action resolve the version in a step; the matrix workflows (test, test-browser) gain a small configure job that feeds the versions into their matrices. Both versions are now bumped manually with each Go release, so the Renovate custom manager for Go is removed. Co-authored-by: Claude Opus 4.8 --- .github/actions/go-versions/action.yml | 22 ++++++++++++++++++++++ .github/actions/lint/action.yml | 5 ++++- .github/go-versions.env | 8 ++++++++ .github/workflows/lint.yml | 5 ++++- .github/workflows/tc39.yml | 5 ++++- .github/workflows/test-browser.yml | 20 ++++++++++++++++++-- .github/workflows/test.yml | 20 ++++++++++++++++++-- .github/workflows/wpt.yml | 5 ++++- .github/workflows/xk6.yml | 6 +++++- renovate.json | 15 --------------- 10 files changed, 87 insertions(+), 24 deletions(-) create mode 100644 .github/actions/go-versions/action.yml create mode 100644 .github/go-versions.env diff --git a/.github/actions/go-versions/action.yml b/.github/actions/go-versions/action.yml new file mode 100644 index 000000000..fff69d506 --- /dev/null +++ b/.github/actions/go-versions/action.yml @@ -0,0 +1,22 @@ +name: "Go versions" +description: "Expose the central Go versions (current and N-1) from .github/go-versions.env" + +outputs: + current: + description: "Current Go version (e.g. 1.26.x)." + value: ${{ steps.read.outputs.current }} + prev: + description: "Previous (N-1) Go version (e.g. 1.25.x)." + value: ${{ steps.read.outputs.prev }} + +runs: + using: "composite" + steps: + - name: Read go-versions.env + id: read + shell: bash + run: | + set -euo pipefail + source "${GITHUB_ACTION_PATH}/../../go-versions.env" + echo "current=${GO_VERSION_CURRENT}" >> "$GITHUB_OUTPUT" + echo "prev=${GO_VERSION_PREV}" >> "$GITHUB_OUTPUT" diff --git a/.github/actions/lint/action.yml b/.github/actions/lint/action.yml index 9440090a1..08760e81a 100644 --- a/.github/actions/lint/action.yml +++ b/.github/actions/lint/action.yml @@ -4,10 +4,13 @@ description: Run golangci-lint with the k6 ruleset runs: using: composite steps: + - name: Resolve Go versions + id: go_versions + uses: ./.github/actions/go-versions - name: Install Go uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6 with: - go-version: 1.26.x + go-version: ${{ steps.go_versions.outputs.current }} check-latest: true - name: Get golangci-lint version and download rules shell: bash diff --git a/.github/go-versions.env b/.github/go-versions.env new file mode 100644 index 000000000..53bdc990c --- /dev/null +++ b/.github/go-versions.env @@ -0,0 +1,8 @@ +# Single source of truth for the Go versions used across the CI workflows. +# +# Both values are bumped manually with each Go release: +# GO_VERSION_CURRENT - the current Go minor version. +# GO_VERSION_PREV - the deliberate N-1 version (one minor behind CURRENT) +# kept for backwards-compatibility coverage. +GO_VERSION_CURRENT=1.26.x +GO_VERSION_PREV=1.25.x diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 4890a1dee..d04433870 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -20,10 +20,13 @@ jobs: with: persist-credentials: false fetch-depth: 0 + - name: Resolve Go versions + id: go_versions + uses: ./.github/actions/go-versions - name: Install Go uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6 with: - go-version: 1.26.x + go-version: ${{ steps.go_versions.outputs.current }} check-latest: true - name: Check dependencies run: | diff --git a/.github/workflows/tc39.yml b/.github/workflows/tc39.yml index 95b70d9ea..44071dbef 100644 --- a/.github/workflows/tc39.yml +++ b/.github/workflows/tc39.yml @@ -27,10 +27,13 @@ jobs: uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 with: persist-credentials: false + - name: Resolve Go versions + id: go_versions + uses: ./.github/actions/go-versions - name: Install Go uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6 with: - go-version: 1.26.x + go-version: ${{ steps.go_versions.outputs.current }} check-latest: true - name: Run tests run: | diff --git a/.github/workflows/test-browser.yml b/.github/workflows/test-browser.yml index 34fa63adb..59031bf3f 100644 --- a/.github/workflows/test-browser.yml +++ b/.github/workflows/test-browser.yml @@ -13,12 +13,27 @@ permissions: contents: read jobs: + configure: + runs-on: ubuntu-latest + outputs: + go_current: ${{ steps.go_versions.outputs.current }} + go_prev: ${{ steps.go_versions.outputs.prev }} + steps: + - name: Checkout code + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + with: + persist-credentials: false + - name: Resolve Go versions + id: go_versions + uses: ./.github/actions/go-versions + test-prev: + needs: configure if: ${{ github.ref == 'refs/heads/master' }} strategy: fail-fast: false matrix: - go-version: [1.25.x] + go-version: ["${{ needs.configure.outputs.go_prev }}"] platform: [ubuntu-24.04, ubuntu-arm64-large, github-hosted-windows-x64-large] runs-on: ${{ matrix.platform }} @@ -71,10 +86,11 @@ jobs: use_gotip: "true" test-latest: + needs: configure strategy: fail-fast: false matrix: - go-version: [1.26.x] + go-version: ["${{ needs.configure.outputs.go_current }}"] platform: [ubuntu-24.04, ubuntu-arm64-large, github-hosted-windows-x64-large] runs-on: ${{ matrix.platform }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d864ae280..74127e9db 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,12 +13,27 @@ permissions: contents: read jobs: + configure: + runs-on: ubuntu-latest + outputs: + go_current: ${{ steps.go_versions.outputs.current }} + go_prev: ${{ steps.go_versions.outputs.prev }} + steps: + - name: Checkout code + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + with: + persist-credentials: false + - name: Resolve Go versions + id: go_versions + uses: ./.github/actions/go-versions + test-prev: + needs: configure if: ${{ github.ref == 'refs/heads/master' }} strategy: fail-fast: false matrix: - go-version: [1.25.x] + go-version: ["${{ needs.configure.outputs.go_prev }}"] platform: [ubuntu-24.04, ubuntu-24.04-arm, windows-latest] runs-on: ${{ matrix.platform }} steps: @@ -67,10 +82,11 @@ jobs: platform: ${{ matrix.platform }} test-latest: + needs: configure strategy: fail-fast: false matrix: - go-version: [1.26.x] + go-version: ["${{ needs.configure.outputs.go_current }}"] platform: [ubuntu-24.04, ubuntu-24.04-arm, windows-latest] runs-on: ${{ matrix.platform }} steps: diff --git a/.github/workflows/wpt.yml b/.github/workflows/wpt.yml index 21d752394..3b6da1eee 100644 --- a/.github/workflows/wpt.yml +++ b/.github/workflows/wpt.yml @@ -18,10 +18,13 @@ jobs: uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 with: persist-credentials: false + - name: Resolve Go versions + id: go_versions + uses: ./.github/actions/go-versions - name: Install Go uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6 with: - go-version: 1.26.x + go-version: ${{ steps.go_versions.outputs.current }} check-latest: true # TODO: combine WebPlatform tests checkout & patch into the single step - name: Run Streams Tests diff --git a/.github/workflows/xk6.yml b/.github/workflows/xk6.yml index ade6e3766..aa7b51c5e 100644 --- a/.github/workflows/xk6.yml +++ b/.github/workflows/xk6.yml @@ -27,11 +27,15 @@ jobs: uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 with: persist-credentials: false + - name: Resolve Go versions + id: go_versions + if: matrix.go != 'tip' + uses: ./.github/actions/go-versions - name: Install Go if: matrix.go != 'tip' uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6 with: - go-version: 1.26.x + go-version: ${{ steps.go_versions.outputs.current }} check-latest: true - name: Download Go tip if: matrix.go == 'tip' diff --git a/renovate.json b/renovate.json index 1aaf98d7f..cd45ead1a 100644 --- a/renovate.json +++ b/renovate.json @@ -8,21 +8,6 @@ "**/vendor/**", ".github/workflows/xk6-tests/**" ], - "customManagers": [ - { - "customType": "regex", - "description": "Track Go minor version in setup-go go-version: 1.X.x lines", - "managerFilePatterns": ["/^\\.github/workflows/[^/]+\\.ya?ml$/"], - "matchStrings": [ - "go-version:\\s+(?\\d+\\.\\d+)\\.x", - "go-version:\\s+\\[(?\\d+\\.\\d+)\\.x\\]" - ], - "depNameTemplate": "golang/go", - "datasourceTemplate": "golang-version", - "extractVersionTemplate": "^(?\\d+\\.\\d+)", - "versioningTemplate": "loose" - } - ], "baseBranchPatterns": [ "master", "v1.x" From 1636475f14d71fd0f6671b21a98376eed2adc566 Mon Sep 17 00:00:00 2001 From: Andrey Slotin Date: Fri, 3 Jul 2026 16:26:21 +0200 Subject: [PATCH 002/182] Skip code CI for docs-only and release-notes-only PRs (#6104) * Skip code CI for docs-only PRs * Skip code CI for release-notes-only PRs --- .github/workflows/browser_e2e.yml | 3 +++ .github/workflows/build.yml | 3 +++ .github/workflows/lint.yml | 3 +++ .github/workflows/test-browser.yml | 3 +++ .github/workflows/test.yml | 3 +++ .github/workflows/wpt.yml | 3 +++ .github/workflows/xk6.yml | 3 +++ 7 files changed, 21 insertions(+) diff --git a/.github/workflows/browser_e2e.yml b/.github/workflows/browser_e2e.yml index 3804deaa0..7ce765a7e 100644 --- a/.github/workflows/browser_e2e.yml +++ b/.github/workflows/browser_e2e.yml @@ -6,6 +6,9 @@ on: branches: - master pull_request: + paths-ignore: + - 'docs/**' + - 'release notes/**' schedule: # At 06:00 AM UTC from Monday through Friday - cron: '0 6 * * 1-5' diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ac0b2ad53..49cbc5d02 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,6 +15,9 @@ on: tags: - v* pull_request: + paths-ignore: + - 'docs/**' + - 'release notes/**' defaults: run: diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index d04433870..653c3be22 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -3,6 +3,9 @@ on: # Enable manually triggering this workflow via the API or web UI workflow_dispatch: pull_request: + paths-ignore: + - 'docs/**' + - 'release notes/**' defaults: run: diff --git a/.github/workflows/test-browser.yml b/.github/workflows/test-browser.yml index 59031bf3f..99942e67e 100644 --- a/.github/workflows/test-browser.yml +++ b/.github/workflows/test-browser.yml @@ -4,6 +4,9 @@ on: branches: - master pull_request: + paths-ignore: + - 'docs/**' + - 'release notes/**' defaults: run: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 74127e9db..5e69a5272 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,6 +4,9 @@ on: branches: - master pull_request: + paths-ignore: + - 'docs/**' + - 'release notes/**' defaults: run: diff --git a/.github/workflows/wpt.yml b/.github/workflows/wpt.yml index 3b6da1eee..a54ab8dd3 100644 --- a/.github/workflows/wpt.yml +++ b/.github/workflows/wpt.yml @@ -2,6 +2,9 @@ name: Web Platform Tests on: workflow_dispatch: pull_request: + paths-ignore: + - 'docs/**' + - 'release notes/**' defaults: run: diff --git a/.github/workflows/xk6.yml b/.github/workflows/xk6.yml index aa7b51c5e..3c171e0c2 100644 --- a/.github/workflows/xk6.yml +++ b/.github/workflows/xk6.yml @@ -6,6 +6,9 @@ on: branches: - master pull_request: + paths-ignore: + - 'docs/**' + - 'release notes/**' defaults: run: From e491808f392623e15bc3092ff0851425709740b4 Mon Sep 17 00:00:00 2001 From: Andrey Slotin Date: Tue, 7 Jul 2026 14:22:29 +0200 Subject: [PATCH 003/182] Add feature brief process (#6103) * Add feature brief template * Add feature briefs README * Add feature brief CI size check * Add CODEOWNERS entry for feature briefs --- .github/scripts/check-feature-briefs.sh | 156 ++++++++++++++++++++++++ .github/workflows/feature-briefs.yml | 37 ++++++ CODEOWNERS | 3 + docs/features/000-TEMPLATE.md | 23 ++++ docs/features/README.md | 31 +++++ 5 files changed, 250 insertions(+) create mode 100644 .github/scripts/check-feature-briefs.sh create mode 100644 .github/workflows/feature-briefs.yml create mode 100644 docs/features/000-TEMPLATE.md create mode 100644 docs/features/README.md diff --git a/.github/scripts/check-feature-briefs.sh b/.github/scripts/check-feature-briefs.sh new file mode 100644 index 000000000..b36ef04fa --- /dev/null +++ b/.github/scripts/check-feature-briefs.sh @@ -0,0 +1,156 @@ +#!/usr/bin/env bash +# check-feature-briefs.sh — validate feature briefs in docs/features/ +# +# Usage: +# ./check-feature-briefs.sh # check all briefs (local default) +# ./check-feature-briefs.sh path/to/a.md # check specific file(s) (used by CI) +# +# Rules enforced: +# 1. Total prose ≤ 1,200 words (hard limit, error) +# Total prose ≤ 800 words (soft target, warning) +# 2. "## Problem" section ≤ 3 sentences (heuristic: counts . ! ? terminators) +# 3. "## Cost of inaction" section must be present and non-empty +# +# Prose is defined as all text after stripping: +# - Markdown heading lines (lines starting with #) +# - HTML comments (, including multi-line) +# +# README.md and 000-TEMPLATE.md are always excluded. + +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" +BRIEFS_DIR="$REPO_ROOT/docs/features" + +SKIP_PATTERN="README\.md$|000-TEMPLATE\.md$" + +# ────────────────────────────────────────────── +# Helpers +# ────────────────────────────────────────────── + +# strip_comments FILE — print file contents with HTML comments removed +strip_comments() { + awk ' + { + line = $0 + while (1) { + if (in_comment) { + idx = index(line, "-->") + if (idx == 0) { line = ""; break } + line = substr(line, idx + 3) + in_comment = 0 + } else { + idx = index(line, "") + if (end_idx > 0) { + line = before substr(rest, end_idx + 3) + } else { + printf "%s", before + in_comment = 1 + line = "" + break + } + } + } + print line + } + ' in_comment=0 "$1" +} + +# prose_text FILE — file with comments and heading lines stripped +prose_text() { + strip_comments "$1" | grep -v '^[[:space:]]*#' +} + +# section_text FILE HEADING — text of the section starting at HEADING, up to next ## heading +section_text() { + local file="$1" + local heading="$2" + strip_comments "$file" | awk -v heading="$heading" ' + BEGIN { found=0 } + /^##[[:space:]]/ { + if (found) exit + if (tolower($0) ~ tolower(heading)) { found=1; next } + } + found { print } + ' +} + +# ────────────────────────────────────────────── +# Build the file list +# ────────────────────────────────────────────── + +if [[ $# -gt 0 ]]; then + files=("$@") +else + # No args: scan all .md files in docs/features/ + mapfile -t files < <(find "$BRIEFS_DIR" -maxdepth 1 -name '*.md' | sort) +fi + +# Filter out excluded files +filtered=() +for f in "${files[@]}"; do + if echo "$f" | grep -qE "$SKIP_PATTERN"; then + continue + fi + if [[ ! -f "$f" ]]; then + echo "::warning::File not found, skipping: $f" + continue + fi + filtered+=("$f") +done + +if [[ ${#filtered[@]} -eq 0 ]]; then + echo "No feature briefs to check." + exit 0 +fi + +# ────────────────────────────────────────────── +# Validate each brief +# ────────────────────────────────────────────── + +failed=0 + +for f in "${filtered[@]}"; do + echo "Checking: $f" + + # 1. Word count ----------------------------------------------------------- + word_count=$(prose_text "$f" | wc -w | tr -d '[:space:]') + + if [[ "$word_count" -gt 1200 ]]; then + echo "::error file=$f::Word count is $word_count (limit: 1200). Trim the prose." + failed=1 + elif [[ "$word_count" -gt 800 ]]; then + echo "::warning file=$f::Word count is $word_count (soft target: ≤800). Consider trimming." + fi + + # 2. Problem sentence count ----------------------------------------------- + # Heuristic: count sentence-terminating punctuation (. ! ?) that is followed + # by whitespace or end of string. HTML comments already stripped by section_text. + problem_text=$(section_text "$f" "## Problem") + sentence_count=$(echo "$problem_text" | grep -oE '[.!?]([[:space:]]|$)' | wc -l | tr -d '[:space:]') + + if [[ "$sentence_count" -gt 3 ]]; then + echo "::error file=$f::Problem statement has ~$sentence_count sentences (limit: 3)." + failed=1 + fi + + # 3. Cost of inaction — present and non-empty ----------------------------- + coi_text=$(section_text "$f" "## Cost of inaction" | tr -d '[:space:]') + + if [[ -z "$coi_text" ]]; then + echo "::error file=$f::\"Cost of inaction\" section is missing or empty. It is required." + failed=1 + fi + +done + +if [[ "$failed" -ne 0 ]]; then + exit 1 +fi + +echo "All briefs OK." diff --git a/.github/workflows/feature-briefs.yml b/.github/workflows/feature-briefs.yml new file mode 100644 index 000000000..c0409e0f8 --- /dev/null +++ b/.github/workflows/feature-briefs.yml @@ -0,0 +1,37 @@ +name: Feature briefs +on: + workflow_dispatch: + pull_request: + paths: + - 'docs/features/**' + +defaults: + run: + shell: bash + +permissions: + contents: read + +jobs: + check-size: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + with: + persist-credentials: false + fetch-depth: 0 + - name: Validate changed feature briefs + env: + BASE: ${{ github.event.pull_request.base.sha }} + HEAD: ${{ github.event.pull_request.head.sha }} + run: | + files=$(git diff --name-only --diff-filter=AM "$BASE" "$HEAD" -- 'docs/features/*.md' \ + | grep -vE '(README|000-TEMPLATE)\.md$' || true) + if [ -z "$files" ]; then + echo "No feature briefs added or changed in this PR." + exit 0 + fi + echo "Checking:"; echo "$files" + # xargs passes each file as a separate argument to the script + echo "$files" | xargs ./.github/scripts/check-feature-briefs.sh diff --git a/CODEOWNERS b/CODEOWNERS index c3044d480..dae46afc5 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -6,3 +6,6 @@ # It turned out to be less noisy if the author picks manually every time # the best reviewers based on the context of the working area. /release\ notes/ + +# Feature briefs are owned by the maintainers (k6-core) and product. +/docs/features/ @grafana/k6-core @andrewslotin diff --git a/docs/features/000-TEMPLATE.md b/docs/features/000-TEMPLATE.md new file mode 100644 index 000000000..d52a12d6d --- /dev/null +++ b/docs/features/000-TEMPLATE.md @@ -0,0 +1,23 @@ +# Title + + + +## Problem + + + +## Significance + + + +## Cost of inaction + + + +## Desired state + + + +## Out of scope + + diff --git a/docs/features/README.md b/docs/features/README.md new file mode 100644 index 000000000..5d24364d2 --- /dev/null +++ b/docs/features/README.md @@ -0,0 +1,31 @@ +# Feature briefs + +A feature brief is a short Markdown document that describes a user problem and explains why it matters. You submit it as a pull request and the team reviews it before any implementation work begins. Keeping briefs in the repo means the whole proposal history lives alongside the code. + +## When to write one + +Write a brief for new features or significant changes to existing behaviour. You do **not** need one for bug fixes, small improvements, or refactors. + +## How to submit + +1. Copy [`000-TEMPLATE.md`](000-TEMPLATE.md) to a new file named `NNN-short-title.md`, where `NNN` is the next available number (e.g. `007-websocket-multiplexing.md`). +2. Fill in every section, deleting the HTML comment guidance as you go. +3. Open a PR that adds only that file under `docs/features/`. + +## Review process + +Briefs are reviewed as pull requests, with discussion happening in the PR comments. Once a brief is merged we treat it as final, so any follow-up changes go into a new brief. + +## Constraints + +| Constraint | Limit | +|---|---| +| Total prose | 1,200 words (soft target: 800) | +| Problem statement | ≤ 3 sentences | +| "Cost of inaction" section | Required | + +The word count is enforced in CI. Template headings and HTML comments do not count towards it. + +--- + +For general contribution guidelines see [`CONTRIBUTING.md`](../../CONTRIBUTING.md). From c0bc819af0fdb3595fbafc6897cd8abd32da9d84 Mon Sep 17 00:00:00 2001 From: Mihail Stoykov <312246+mstoykov@users.noreply.github.com> Date: Wed, 8 Jul 2026 16:39:56 +0300 Subject: [PATCH 004/182] chore: prepare workflows for get-vault-secrets v2 (#6075) The v2 of grafana/shared-workflows/actions/get-vault-secrets will no longer auto-export retrieved secrets as environment variables; consumers must read them from the action's `secrets` output via `${{ fromJSON(steps..outputs.secrets).NAME }}` instead of `${{ env.NAME }}`. This change opts every existing usage into the new pattern by: - giving each get-vault-secrets step an explicit `id` - setting `export_env: false` to match the v2 behavior - replacing downstream `env.NAME` references with the `fromJSON(...)` form, and threading bash consumers via per-step `env:` blocks where needed Co-authored-by: Claude Opus 4.7 --- .github/workflows/build.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 49cbc5d02..d16997cf9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -655,7 +655,9 @@ jobs: mv "dist/k6-$VERSION-linux-amd64.rpm" "dist/k6-$VERSION-amd64.rpm" mv "dist/k6-$VERSION-linux-amd64.deb" "dist/k6-$VERSION-amd64.deb" - uses: grafana/shared-workflows/actions/get-vault-secrets@a53fc80bc30b0a16a262520465db899fa3af08b7 # get-vault-secrets/v1.3.2 + id: get-secrets with: + export_env: false repo_secrets: | IAM_ROLE_ARN=deploy:packager-iam-role AWS_CF_DISTRIBUTION=cloudfront:AWS_CF_DISTRIBUTION @@ -665,9 +667,14 @@ jobs: - uses: grafana/shared-workflows/actions/aws-auth@85022085ed5314601c05d10e846de56bdd71e369 # aws-auth/v1.0.3 with: aws-region: "us-east-2" - role-arn: ${{ env.IAM_ROLE_ARN }} + role-arn: ${{ fromJSON(steps.get-secrets.outputs.secrets).IAM_ROLE_ARN }} set-creds-in-environment: true - name: Setup docker compose environment + env: + AWS_CF_DISTRIBUTION: ${{ fromJSON(steps.get-secrets.outputs.secrets).AWS_CF_DISTRIBUTION }} + PGP_SIGN_KEY_PASSPHRASE: ${{ fromJSON(steps.get-secrets.outputs.secrets).PGP_SIGN_KEY_PASSPHRASE }} + PGP_SIGN_KEY: ${{ fromJSON(steps.get-secrets.outputs.secrets).PGP_SIGN_KEY }} + S3_BUCKET: ${{ fromJSON(steps.get-secrets.outputs.secrets).S3_BUCKET }} run: | cat > packaging/.env < Date: Thu, 9 Jul 2026 12:12:22 -0400 Subject: [PATCH 005/182] feat(features): gate RunTags merge behind merge-run-tags flag (#5714) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #2694 Signed-off-by: Yordis Prieto Co-authored-by: Théo Crevon --- internal/cmd/config.go | 29 +++++- internal/cmd/config_consolidation_test.go | 74 +++++++++++++-- internal/cmd/test_load.go | 3 +- .../cmd/tests/cmd_run_merge_run_tags_test.go | 89 +++++++++++++++++++ internal/features/features.go | 1 + 5 files changed, 188 insertions(+), 8 deletions(-) create mode 100644 internal/cmd/tests/cmd_run_merge_run_tags_test.go diff --git a/internal/cmd/config.go b/internal/cmd/config.go index 53e1388dd..cb8500f3e 100644 --- a/internal/cmd/config.go +++ b/internal/cmd/config.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "io/fs" + "maps" "path/filepath" "strings" "time" @@ -17,6 +18,7 @@ import ( "go.k6.io/k6/v2/cmd/state" "go.k6.io/k6/v2/errext" "go.k6.io/k6/v2/errext/exitcodes" + "go.k6.io/k6/v2/internal/features" "go.k6.io/k6/v2/lib" "go.k6.io/k6/v2/lib/executor" "go.k6.io/k6/v2/lib/fsext" @@ -211,7 +213,9 @@ func readEnvConfig(envMap map[string]string) (Config, error) { // - set some defaults if they weren't previously specified // TODO: add better validation, more explicit default values and improve consistency between formats // TODO: accumulate all errors and differentiate between the layers? -func getConsolidatedConfig(gs *state.GlobalState, cliConf Config, runnerOpts lib.Options) (Config, error) { +func getConsolidatedConfig( + gs *state.GlobalState, cliConf Config, runnerOpts lib.Options, flags *features.Flags, +) (Config, error) { fileConf, err := readDiskConfig(gs) if err != nil { err = fmt.Errorf("failed to load the configuration file from the local file system: %w", err) @@ -234,6 +238,15 @@ func getConsolidatedConfig(gs *state.GlobalState, cliConf Config, runnerOpts lib warnOnShortHandOverride(conf.Options, cliConf.Options, "cli", gs.Logger) conf = conf.Apply(cliConf) + if flags != nil && flags.MergeRunTags { + conf.RunTags = mergeRunTags( + fileConf.RunTags, + runnerOpts.RunTags, + envConf.RunTags, + cliConf.RunTags, + ) + } + conf = applyDefault(conf) // TODO(imiric): Move this validation where it makes sense in the configuration @@ -248,6 +261,20 @@ func getConsolidatedConfig(gs *state.GlobalState, cliConf Config, runnerOpts lib return conf, nil } +// mergeRunTags accumulates RunTags from each layer in precedence order (lowest first). +// On key collision, later (higher-priority) layers overwrite earlier ones. +// Returns nil when every layer is empty to preserve the codebase's "tags":null serialization. +func mergeRunTags(layers ...map[string]string) map[string]string { + merged := map[string]string{} + for _, l := range layers { + maps.Copy(merged, l) + } + if len(merged) == 0 { + return nil + } + return merged +} + func warnOnShortHandOverride(a, b lib.Options, bName string, logger logrus.FieldLogger) { if a.Scenarios != nil && (b.Duration.Valid || b.Iterations.Valid || b.Stages != nil || b.Scenarios != nil) { diff --git a/internal/cmd/config_consolidation_test.go b/internal/cmd/config_consolidation_test.go index 64aedcc05..40116ded9 100644 --- a/internal/cmd/config_consolidation_test.go +++ b/internal/cmd/config_consolidation_test.go @@ -11,6 +11,7 @@ import ( "go.k6.io/k6/v2/cmd/state" "go.k6.io/k6/v2/internal/cmd/tests" + "go.k6.io/k6/v2/internal/features" "go.k6.io/k6/v2/lib" "go.k6.io/k6/v2/lib/executor" "go.k6.io/k6/v2/lib/fsext" @@ -105,11 +106,12 @@ func getFS(files []file) fsext.Fs { } type opts struct { - cli []string - env []string - runner *lib.Options - fs fsext.Fs - cmds []string + cli []string + env []string + runner *lib.Options + fs fsext.Fs + cmds []string + features *features.Flags } // exp contains the different events or errors we expect our test case to trigger. @@ -349,6 +351,66 @@ func getConfigConsolidationTestCases() []configConsolidationTestCase { assert.Equal(t, exp, c.RunTags) }, }, + // merge-run-tags off: each layer that sets tags replaces the previous one wholesale. + { + opts{ + fs: defaultConfig(`{"tags": {"file_only": "f", "shared": "from-file"}}`), + runner: &lib.Options{RunTags: map[string]string{"script_only": "s", "shared": "from-script"}}, + env: []string{"K6_TAGS=env_only:e,shared:from-env"}, + cli: []string{"--tag", "cli_only=c", "--tag", "shared=from-cli"}, + }, + exp{}, + func(t *testing.T, c Config) { + assert.Equal(t, map[string]string{ + "cli_only": "c", + "shared": "from-cli", + }, c.RunTags) + }, + }, + // merge-run-tags on: every layer contributes; higher-priority wins on key collision. + // Precedence: file < script < env < CLI. + { + opts{ + fs: defaultConfig(`{"tags": {"file_only": "f", "shared": "from-file"}}`), + runner: &lib.Options{RunTags: map[string]string{"script_only": "s", "shared": "from-script"}}, + env: []string{"K6_TAGS=env_only:e,shared:from-env"}, + cli: []string{"--tag", "cli_only=c", "--tag", "shared=from-cli"}, + features: &features.Flags{MergeRunTags: true}, + }, + exp{}, + func(t *testing.T, c Config) { + assert.Equal(t, map[string]string{ + "file_only": "f", + "script_only": "s", + "env_only": "e", + "cli_only": "c", + "shared": "from-cli", + }, c.RunTags) + }, + }, + // merge-run-tags on with only file + CLI tags (the original PR scenario). + { + opts{ + fs: defaultConfig(`{"tags": {"codeTagKey": "codeTagValue"}}`), + cli: []string{"--tag", "clitagkey=clitagvalue"}, + features: &features.Flags{MergeRunTags: true}, + }, + exp{}, + func(t *testing.T, c Config) { + assert.Equal(t, map[string]string{ + "codeTagKey": "codeTagValue", + "clitagkey": "clitagvalue", + }, c.RunTags) + }, + }, + // merge-run-tags on with no tags anywhere: result stays nil. + { + opts{features: &features.Flags{MergeRunTags: true}}, + exp{}, + func(t *testing.T, c Config) { + assert.Nil(t, c.RunTags) + }, + }, // Test summary trend stats {opts{}, exp{}, func(t *testing.T, c Config) { @@ -544,7 +606,7 @@ func runTestCase(t *testing.T, testCase configConsolidationTestCase, subCmd stri if testCase.options.runner != nil { opts = *testCase.options.runner } - consolidatedConfig, err := getConsolidatedConfig(ts.GlobalState, cliConf, opts) + consolidatedConfig, err := getConsolidatedConfig(ts.GlobalState, cliConf, opts, testCase.options.features) if testCase.expected.consolidationError { require.Error(t, err) return diff --git a/internal/cmd/test_load.go b/internal/cmd/test_load.go index 3197ee10c..bfc633773 100644 --- a/internal/cmd/test_load.go +++ b/internal/cmd/test_load.go @@ -544,7 +544,8 @@ func (lt *loadedTest) consolidateDeriveAndValidateConfig( } gs.Logger.Debug("Consolidating config layers...") - consolidatedConfig, err := getConsolidatedConfig(gs, cliConfig, lt.initRunner.GetOptions()) + consolidatedConfig, err := getConsolidatedConfig( + gs, cliConfig, lt.initRunner.GetOptions(), lt.preInitState.FeatureFlags) if err != nil { return nil, err } diff --git a/internal/cmd/tests/cmd_run_merge_run_tags_test.go b/internal/cmd/tests/cmd_run_merge_run_tags_test.go new file mode 100644 index 000000000..51cecc3d8 --- /dev/null +++ b/internal/cmd/tests/cmd_run_merge_run_tags_test.go @@ -0,0 +1,89 @@ +package tests + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "go.k6.io/k6/v2/internal/cmd" + "go.k6.io/k6/v2/lib/fsext" +) + +const mergeRunTagsScript = ` + export const options = { + tags: { env: 'staging', team: 'backend' }, + scenarios: { + s: { executor: 'per-vu-iterations', vus: 1, iterations: 1 }, + }, + }; + export default function () {} +` + +// Without the flag, CLI --tag replaces script-level options.tags wholesale. +// Samples should NOT carry the script-level `env` tag. +func TestRunMergeRunTagsFlagOff(t *testing.T) { + t.Parallel() + + ts := getSingleFileTestState(t, mergeRunTagsScript, + []string{"--out", "json=results.json", "--no-usage-report", "--tag", "region=us-east"}, 0) + + results := runAndReadResults(t, ts) + + withScriptTag := getSampleValues(t, results, "iterations", map[string]string{"env": "staging"}) + assert.Empty(t, withScriptTag, "script-level tags must be replaced wholesale when the flag is off") + + withCLITag := getSampleValues(t, results, "iterations", map[string]string{"region": "us-east"}) + assert.NotEmpty(t, withCLITag, "CLI --tag must still apply") +} + +// With the flag on, CLI --tag, script options.tags, and env K6_TAGS all contribute. +func TestRunMergeRunTagsFlagOn(t *testing.T) { + t.Parallel() + + ts := getSingleFileTestState(t, mergeRunTagsScript, + []string{ + "--out", "json=results.json", "--no-usage-report", + "--features", "merge-run-tags", + "--tag", "region=us-east", + }, 0) + + results := runAndReadResults(t, ts) + + for k, v := range map[string]string{ + "env": "staging", // from script options.tags + "team": "backend", // from script options.tags + "region": "us-east", // from CLI --tag + } { + samples := getSampleValues(t, results, "iterations", map[string]string{k: v}) + assert.NotEmpty(t, samples, "expected merged tag %s=%s", k, v) + } +} + +// Higher-priority layers must win on key collision when the flag is on. +func TestRunMergeRunTagsCLIWinsOnCollision(t *testing.T) { + t.Parallel() + + ts := getSingleFileTestState(t, mergeRunTagsScript, + []string{ + "--out", "json=results.json", "--no-usage-report", + "--features", "merge-run-tags", + "--tag", "env=prod", + }, 0) + + results := runAndReadResults(t, ts) + + wins := getSampleValues(t, results, "iterations", map[string]string{"env": "prod"}) + assert.NotEmpty(t, wins, "CLI --tag must win over script-level options.tags on collision") + + loses := getSampleValues(t, results, "iterations", map[string]string{"env": "staging"}) + assert.Empty(t, loses, "lower-priority value must not appear when the higher-priority layer overrides it") +} + +func runAndReadResults(t *testing.T, ts *GlobalTestState) []byte { + t.Helper() + cmd.ExecuteWithGlobalState(ts.GlobalState) + data, err := fsext.ReadFile(ts.FS, "results.json") + require.NoError(t, err) + return data +} diff --git a/internal/features/features.go b/internal/features/features.go index c3a68cbcc..74b8d6616 100644 --- a/internal/features/features.go +++ b/internal/features/features.go @@ -42,6 +42,7 @@ func (l Lifecycle) String() string { // Flags declares every feature flag as a tagged bool field. type Flags struct { NativeHistograms bool `lifecycle:"experimental" help:"Use native histograms for trend metrics"` + MergeRunTags bool `lifecycle:"experimental" help:"Merge run tags across config layers instead of replacing"` _ noCopy activated []string } From 8249b0d05badc6305c2851f32247866a3b603dea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20L=C3=B3pez=20de=20la=20Franca=20Beltran?= <5459617+joanlopez@users.noreply.github.com> Date: Mon, 13 Jul 2026 16:26:17 +0200 Subject: [PATCH 006/182] fix: Don't freeze JS primitives (#6140) * fix: Don't freeze JS primitives * Fix linter errors --- internal/js/modules/k6/data/share.go | 10 ++ internal/js/modules/k6/data/share_test.go | 146 ++++++++++++++++++++++ 2 files changed, 156 insertions(+) diff --git a/internal/js/modules/k6/data/share.go b/internal/js/modules/k6/data/share.go index fd4d711ae..cc9fc698e 100644 --- a/internal/js/modules/k6/data/share.go +++ b/internal/js/modules/k6/data/share.go @@ -67,6 +67,16 @@ func (s wrappedSharedArray) deepFreeze(rt *sobek.Runtime, val sobek.Value) error return nil } + // Primitives (strings, numbers, booleans) are already immutable in + // JavaScript, so there is nothing to freeze. + // Skipping them also avoids a costly no-op: deep-freezing a large string + // would otherwise wrap it in a String object and iterate over every one + // of its character indices in the loop below, allocating enormous amounts + // of memory on every access. + if _, ok := val.(*sobek.Object); !ok { + return nil + } + _, err := s.freeze(sobek.Undefined(), val) if err != nil { return err diff --git a/internal/js/modules/k6/data/share_test.go b/internal/js/modules/k6/data/share_test.go index 409dd6877..50eb75590 100644 --- a/internal/js/modules/k6/data/share_test.go +++ b/internal/js/modules/k6/data/share_test.go @@ -216,6 +216,152 @@ func TestSharedArrayAnotherRuntimeWorking(t *testing.T) { require.NoError(t, err) } +// TestSharedArrayReadValuesIntact verifies that values read back through the +// (now primitive-skipping) deepFreeze path are intact: primitives of every JSON +// kind, an ASCII and a non-ASCII string (different internal representations), +// and a large string (the shape that used to blow up memory). Repeated reads +// must be consistent. +func TestSharedArrayReadValuesIntact(t *testing.T) { + t.Parallel() + runtime, err := newConfiguredRuntime(t) + require.NoError(t, err) + rt := runtime.VU.Runtime() + + _, err = rt.RunString(`'use strict'; + var LEN = 200000; + var s = new SharedArray("reads", function() { + return ["hello", "", "ünïçödé 🚀", 42, 3.5, -7, true, false, null, "A".repeat(LEN)]; + }); + if (s.length !== 10) { throw new Error("length="+s.length); } + if (s[0] !== "hello" || typeof s[0] !== "string") { throw new Error("s[0]="+s[0]); } + if (s[1] !== "" || typeof s[1] !== "string") { throw new Error("s[1]="+s[1]); } + if (s[2] !== "ünïçödé 🚀") { throw new Error("s[2]="+s[2]); } + if (s[3] !== 42) { throw new Error("s[3]="+s[3]); } + if (s[4] !== 3.5) { throw new Error("s[4]="+s[4]); } + if (s[5] !== -7) { throw new Error("s[5]="+s[5]); } + if (s[6] !== true) { throw new Error("s[6]="+s[6]); } + if (s[7] !== false) { throw new Error("s[7]="+s[7]); } + if (s[8] !== null) { throw new Error("s[8]="+s[8]); } + if (s[9].length !== LEN || s[9][0] !== "A" || s[9][LEN-1] !== "A") { throw new Error("bad large string"); } + `) + require.NoError(t, err) +} + +// TestSharedArrayDeepFreezeSemantics verifies the safety property that matters: +// object and array elements (including nested ones) remain deeply frozen after +// the primitive fast-path change, so a VU cannot mutate the shared data. +func TestSharedArrayDeepFreezeSemantics(t *testing.T) { + t.Parallel() + + const setup = `'use strict'; + var s = new SharedArray("rich", function() { + return [{ + str: "hello", + num: 1, + flag: true, + nothing: null, + nested: { deep: "x", arr: [1, 2, 3] }, + list: [ {k: "a"}, {k: "b"} ] + }, [10, 20, 30]]; + }); + ` + + // integrity asserts the shared structure is untouched. It throws (failing + // the surrounding RunString) if any value changed or a property was added. + const integrity = `'use strict'; + if (s[0].str !== "hello") { throw new Error("str changed: "+s[0].str); } + if (s[0].num !== 1) { throw new Error("num changed: "+s[0].num); } + if ("extra" in s[0]) { throw new Error("property was added to object"); } + if (s[0].nested.deep !== "x") { throw new Error("nested.deep changed"); } + if ("extra" in s[0].nested) { throw new Error("property added to nested"); } + if (s[0].nested.arr.length !== 3 || s[0].nested.arr[0] !== 1) { throw new Error("nested.arr changed"); } + if (s[0].list.length !== 2 || s[0].list[0].k !== "a") { throw new Error("list changed"); } + if (s[1].length !== 3 || s[1][0] !== 10) { throw new Error("top-level array changed"); } + ` + + // The deep freeze must reject every one of these mutations. Top-level plain + // object freezing is already covered by TestSharedArrayAnotherRuntimeExceptions; + // these focus on the nested and array cases, which exercise the recursion and + // the values that pass through the *sobek.Object guard as containers. + cases := map[string]string{ + "mutate nested object": `s[0].nested.deep = "bad";`, + "add property to nested object": `s[0].nested.extra = "bad";`, + "delete nested property": `delete s[0].nested.deep;`, + "push to nested array": `s[0].nested.arr.push(4);`, + "set nested array index": `s[0].nested.arr[0] = 99;`, + "mutate object inside array": `s[0].list[0].k = "bad";`, + "push to top-level array element": `s[1].push(40);`, + "set index on top-level array element": `s[1][0] = 99;`, + } + + for name, code := range cases { + t.Run(name, func(t *testing.T) { + t.Parallel() + runtime, err := newConfiguredRuntime(t) + require.NoError(t, err) + rt := runtime.VU.Runtime() + _, err = rt.RunString(setup) + require.NoError(t, err) + + // Strict mode is required: in sloppy mode, writes to frozen + // objects fail silently instead of throwing. + _, err = rt.RunString("'use strict';\n" + code) + require.Error(t, err, "mutation should have been rejected by the freeze") + exc := new(sobek.Exception) + require.True(t, errors.As(err, &exc)) + require.Contains(t, exc.Error(), "TypeError", + "a frozen write must fail with a TypeError") + + // The shared data must be completely unchanged. + _, err = rt.RunString(integrity) + require.NoError(t, err) + }) + } +} + +// TestSharedArrayLargeStringGetAllocations is a regression guard for the memory +// blow-up: reading a large string element must not allocate an amount of memory +// proportional to the string length. +// +//nolint:paralleltest // testing.AllocsPerRun must not run concurrently. +func TestSharedArrayLargeStringGetAllocations(t *testing.T) { + runtime, err := newConfiguredRuntime(t) + require.NoError(t, err) + rt := runtime.VU.Runtime() + + _, err = rt.RunString(` + var shared = new SharedArray("alloc", function() { + return ["short", "A".repeat(100000)]; + }); + var get = function(i) { return shared[i]; }; + `) + require.NoError(t, err) + + get, ok := sobek.AssertFunction(rt.Get("get")) + require.True(t, ok) + + small := testing.AllocsPerRun(50, func() { + _, err := get(sobek.Undefined(), rt.ToValue(0)) + if err != nil { + panic(err) + } + }) + large := testing.AllocsPerRun(50, func() { + _, err := get(sobek.Undefined(), rt.ToValue(1)) + if err != nil { + panic(err) + } + }) + + t.Logf("allocations per Get: small string=%.0f, 100k string=%.0f", small, large) + + // With the bug, `large` was on the order of the string length (100k+). + // After the fix it is a small constant, close to `small`. Use a generous + // bound that is decisively below the buggy behavior. + require.Less(t, large, 2000.0, + "reading a large string element allocates too much; deepFreeze may be enumerating characters again") +} + func TestSharedArrayRaceInInitialization(t *testing.T) { t.Parallel() From 06933299e006662d5a0960d1833a2a4c134a43fe Mon Sep 17 00:00:00 2001 From: SomakD <281532634+somak2kai@users.noreply.github.com> Date: Wed, 15 Jul 2026 18:50:58 +0530 Subject: [PATCH 007/182] Fix potential data race and TOCTOU inconsistency in route operation (#6147) * fix potential data race and TOCTOU inconsistency in route operation * added code review comments: better code comments and errcheck --- internal/js/modules/k6/browser/common/page.go | 6 ++-- .../js/modules/k6/browser/tests/page_test.go | 30 +++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/internal/js/modules/k6/browser/common/page.go b/internal/js/modules/k6/browser/common/page.go index fa7735c7b..185d32093 100644 --- a/internal/js/modules/k6/browser/common/page.go +++ b/internal/js/modules/k6/browser/common/page.go @@ -1356,7 +1356,9 @@ func (p *Page) Referrer() string { func (p *Page) Route(path string, cb RouteHandlerCallback, rm RegExMatcher) error { p.logger.Debugf("Page:Route", "sid:%v path:%s", p.sessionID(), path) - if !p.hasRoutes() { + p.routesMu.Lock() + defer p.routesMu.Unlock() + if len(p.routes) == 0 { err := p.mainFrameSession.updateRequestInterception(true) if err != nil { return err @@ -1369,8 +1371,6 @@ func (p *Page) Route(path string, cb RouteHandlerCallback, rm RegExMatcher) erro } routeHandler := NewRouteHandler(path, cb, matcher) - p.routesMu.Lock() - defer p.routesMu.Unlock() // Append new route at the beginning of the slice as, when several routes match the given pattern, // they will run in the opposite order to their registration. p.routes = append([]*RouteHandler{routeHandler}, p.routes...) diff --git a/internal/js/modules/k6/browser/tests/page_test.go b/internal/js/modules/k6/browser/tests/page_test.go index c9c2eee0c..83e39e870 100644 --- a/internal/js/modules/k6/browser/tests/page_test.go +++ b/internal/js/modules/k6/browser/tests/page_test.go @@ -17,6 +17,7 @@ import ( "slices" "strconv" "strings" + "sync" "sync/atomic" "testing" "time" @@ -4026,6 +4027,35 @@ func TestClickInNestedFramesCORS(t *testing.T) { }) } +func TestPageRouteConcurrentEnableDataRace(t *testing.T) { + t.Parallel() + + tb := newTestBrowser(t, withHTTPServer()) + p := tb.NewPage(nil) + + matcher := func(pattern, url string) (bool, error) { + return regexp.MatchString(fmt.Sprintf("http://[^/]*%s", pattern), url) + } + h := func(rt *common.Route) error { return rt.Continue(common.ContinueOptions{}) } + + // This test is intended to surface a data race under `go test -race`: concurrent first-time registrations + // can each observe routes as empty and call updateRequestInterception(true). + var wg sync.WaitGroup + errCh := make(chan error, 16) + for i := range 16 { + wg.Add(1) + go func(i int) { + defer wg.Done() + errCh <- p.Route(fmt.Sprintf("/api/%d", i), h, matcher) + }(i) + } + wg.Wait() + close(errCh) + for err := range errCh { + require.NoError(t, err) + } +} + func TestPageUnroute(t *testing.T) { t.Parallel() From b6cf2e712c5e5ebb3c62d01b8afa5384af02cde5 Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Thu, 16 Jul 2026 14:46:22 +0300 Subject: [PATCH 008/182] fix(security/unknown/): update go toolchain directive to v1.25.12 [security] (#6134) | datasource | package | from | to | | -------------- | ------- | ------- | ------- | | golang-version | go | 1.25.11 | 1.25.12 | Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 19d64ebdc..952ea14ce 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,7 @@ module go.k6.io/k6/v2 go 1.25.0 -toolchain go1.25.11 +toolchain go1.25.12 require ( buf.build/gen/go/prometheus/prometheus/protocolbuffers/go v1.36.11-20260331160422-eae785f0a21d.1 From bc598f1e505e54ebc435f7fde11b2d51f0e16b38 Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Thu, 16 Jul 2026 14:46:55 +0300 Subject: [PATCH 009/182] chore(deps): update golang:1.26.4-alpine docker digest to 3ad5730 (#6080) Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index d8dd245a4..5cafe4a1f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM --platform=$BUILDPLATFORM golang:1.26.4-alpine@sha256:f23e8b227fb4493eabe03bede4d5a32d04092da71962f1fb79b5f7d1e6c2a17f as builder +FROM --platform=$BUILDPLATFORM golang:1.26.4-alpine@sha256:3ad57304ad93bbec8548a0437ad9e06a455660655d9af011d58b993f6f615648 as builder WORKDIR $GOPATH/src/go.k6.io/k6 COPY . . ARG TARGETOS TARGETARCH From 418b043539ef0375928bbf3c5ab95db6fefc50f8 Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Thu, 16 Jul 2026 14:47:41 +0300 Subject: [PATCH 010/182] chore(deps): update grafana/shared-workflows/azure-trusted-signing action to v1.0.3 (#6124) | datasource | package | from | to | | ------------- | ------------------------ | ---------------------------- | ---------------------------- | | github-digest | grafana/shared-workflows | azure-trusted-signing/v1.0.2 | azure-trusted-signing/v1.0.3 | Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d16997cf9..64b38f3b4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -378,7 +378,7 @@ jobs: tenant-id=azure-trusted-signing:tenant-id - name: Sign Windows binary - uses: grafana/shared-workflows/actions/azure-trusted-signing@fd75379254f1ff2d0a1f1c12b329a9008863ad82 # azure-trusted-signing/v1.0.2 + uses: grafana/shared-workflows/actions/azure-trusted-signing@6a042eda14a697e71944976ab618d27104d9fed4 # azure-trusted-signing/v1.0.3 id: sign-artifacts if: needs.configure.outputs.sign_windows_artifacts == 'true' with: @@ -512,7 +512,7 @@ jobs: tenant-id=azure-trusted-signing:tenant-id - name: Sign Windows installer - uses: grafana/shared-workflows/actions/azure-trusted-signing@fd75379254f1ff2d0a1f1c12b329a9008863ad82 # azure-trusted-signing/v1.0.2 + uses: grafana/shared-workflows/actions/azure-trusted-signing@6a042eda14a697e71944976ab618d27104d9fed4 # azure-trusted-signing/v1.0.3 id: sign-artifacts if: needs.configure.outputs.sign_windows_artifacts == 'true' with: From b1b857ae7063245a529195c775e5c67cfac86a56 Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Thu, 16 Jul 2026 14:48:17 +0300 Subject: [PATCH 011/182] fix(deps): update module github.com/evanw/esbuild to v0.28.1 (#6082) | datasource | package | from | to | | ---------- | ------------------------ | ------- | ------- | | go | github.com/evanw/esbuild | v0.28.0 | v0.28.1 | Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 +-- .../esbuild/internal/js_lexer/js_lexer.go | 2 +- .../esbuild/internal/js_parser/js_parser.go | 29 ++++++++++++++--- .../esbuild/internal/js_printer/js_printer.go | 30 ++++++++--------- .../evanw/esbuild/internal/linker/linker.go | 8 ++--- .../evanw/esbuild/internal/runtime/runtime.go | 32 ++++++++++++++++--- .../evanw/esbuild/pkg/api/serve_other.go | 10 +++++- vendor/modules.txt | 2 +- 9 files changed, 84 insertions(+), 35 deletions(-) diff --git a/go.mod b/go.mod index 952ea14ce..36725af6a 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/andybalholm/brotli v1.2.1 github.com/bufbuild/protocompile v0.14.1 github.com/chromedp/cdproto v0.0.0-20250803210736-d308e07a266d - github.com/evanw/esbuild v0.28.0 + github.com/evanw/esbuild v0.28.1 github.com/fatih/color v1.19.0 github.com/go-json-experiment/json v0.0.0-20250211171154-1ae217ad3535 github.com/go-sourcemap/sourcemap v2.1.4+incompatible diff --git a/go.sum b/go.sum index 65b3ae257..ebd556e5f 100644 --- a/go.sum +++ b/go.sum @@ -42,8 +42,8 @@ github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymF github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= -github.com/evanw/esbuild v0.28.0 h1:V96ghtc5p5JnNUQIUsc5H3kr+AcFcMqOJll2ZmJW6Lo= -github.com/evanw/esbuild v0.28.0/go.mod h1:D2vIQZqV/vIf/VRHtViaUtViZmG7o+kKmlBfVQuRi48= +github.com/evanw/esbuild v0.28.1 h1:ds+yuRyUaZGx++GR56CrCeuXh8PVhVM4xq8v7PNELFc= +github.com/evanw/esbuild v0.28.1/go.mod h1:D2vIQZqV/vIf/VRHtViaUtViZmG7o+kKmlBfVQuRi48= github.com/fatih/color v1.19.0 h1:Zp3PiM21/9Ld6FzSKyL5c/BULoe/ONr9KlbYVOfG8+w= github.com/fatih/color v1.19.0/go.mod h1:zNk67I0ZUT1bEGsSGyCZYZNrHuTkJJB+r6Q9VuMi0LE= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= diff --git a/vendor/github.com/evanw/esbuild/internal/js_lexer/js_lexer.go b/vendor/github.com/evanw/esbuild/internal/js_lexer/js_lexer.go index 59a5f4f6d..62d82ac37 100644 --- a/vendor/github.com/evanw/esbuild/internal/js_lexer/js_lexer.go +++ b/vendor/github.com/evanw/esbuild/internal/js_lexer/js_lexer.go @@ -1713,7 +1713,7 @@ func (lexer *Lexer) scanIdentifierWithEscapes(kind identifierKind) (MaybeSubstri // // This is an error (equivalent to "var foo;" except for this rule) // \u0076\u0061\u0072 foo; // - // // This is an fine (equivalent to "foo.var;") + // // This is a fine (equivalent to "foo.var;") // foo.\u0076\u0061\u0072; // if Keywords[text] != 0 { diff --git a/vendor/github.com/evanw/esbuild/internal/js_parser/js_parser.go b/vendor/github.com/evanw/esbuild/internal/js_parser/js_parser.go index b4609b8dd..a28386673 100644 --- a/vendor/github.com/evanw/esbuild/internal/js_parser/js_parser.go +++ b/vendor/github.com/evanw/esbuild/internal/js_parser/js_parser.go @@ -1148,6 +1148,11 @@ func jumpStmtsLookTheSame(left js_ast.S, right js_ast.S) bool { } func (p *parser) selectLocalKind(kind js_ast.LocalKind) js_ast.LocalKind { + // Use "var" instead of "let" and "const" if they aren't supported + if (kind == js_ast.LocalLet || kind == js_ast.LocalConst) && p.options.unsupportedJSFeatures.Has(compat.ConstAndLet) { + return js_ast.LocalVar + } + // Use "var" instead of "let" and "const" if the variable declaration may // need to be separated from the initializer. This allows us to safely move // this declaration into a nested scope. @@ -1518,7 +1523,6 @@ func (p *parser) declareSymbol(kind ast.SymbolKind, loc logger.Loc, name string) // Overwrite this name in the declaring scope p.currentScope.Members[name] = js_ast.ScopeMember{Ref: ref, Loc: loc} return ref - } // This type is just so we can use Go's native sort function @@ -3488,6 +3492,7 @@ const ( exprFlagForLoopInit exprFlagForAwaitLoopInit exprFlagAfterQuestionAndBeforeColon + exprFlagIsNewTarget ) func (p *parser) parsePrefix(level js_ast.L, errors *deferredErrors, flags exprFlag) js_ast.Expr { @@ -3819,7 +3824,7 @@ func (p *parser) parsePrefix(level js_ast.L, errors *deferredErrors, flags exprF return js_ast.Expr{Loc: loc, Data: &js_ast.ENewTarget{Range: r}} } - target := p.parseExprWithFlags(js_ast.LMember, flags) + target := p.parseExprWithFlags(js_ast.LMember, flags|exprFlagIsNewTarget) args := []js_ast.Expr{} var closeParenLoc logger.Loc var isMultiLine bool @@ -4320,6 +4325,11 @@ func (p *parser) parseSuffix(left js_ast.Expr, level js_ast.L, errors *deferredE optionalChain = oldOptionalChain case js_lexer.TQuestionDot: + if (flags & exprFlagIsNewTarget) != 0 { + p.log.AddError(&p.tracker, p.lexer.Range(), "Cannot use an unparenthesized optional chain inside the target of \"new\"") + flags &= ^exprFlagIsNewTarget // Don't report this error more than once in this spot + } + p.lexer.Next() optionalStart := js_ast.OptionalChainStart @@ -9180,7 +9190,7 @@ func (p *parser) mangleStmts(stmts []js_ast.Stmt, kind stmtsKind) []js_ast.Stmt // should have visited all the uses of "let" and "const" declarations // by now since they are scoped to this block which we just finished // visiting. - if prevS, ok := result[len(result)-1].Data.(*js_ast.SLocal); ok && prevS.Kind != js_ast.LocalVar { + if prevS, ok := result[len(result)-1].Data.(*js_ast.SLocal); ok && (prevS.Kind == js_ast.LocalLet || prevS.Kind == js_ast.LocalConst) { last := prevS.Decls[len(prevS.Decls)-1] // The binding must be an identifier that is only used once. @@ -10008,9 +10018,18 @@ func (p *parser) visitForLoopInit(stmt js_ast.Stmt, isInOrOf bool) js_ast.Stmt { } func (p *parser) recordDeclaredSymbol(ref ast.Ref) { + isTopLevel := p.currentScope == p.moduleScope + + // Check whether this symbol was hoisted out of a nested scope into the module scope + if !isTopLevel { + if symbol := p.symbols[ref.InnerIndex]; symbol.Kind.IsHoisted() && p.moduleScope.Members[symbol.OriginalName].Ref == ref { + isTopLevel = true + } + } + p.declaredSymbols = append(p.declaredSymbols, js_ast.DeclaredSymbol{ Ref: ref, - IsTopLevel: p.currentScope == p.moduleScope, + IsTopLevel: isTopLevel, }) } @@ -18217,7 +18236,7 @@ const ( whyESMImportStatement ) -// Say why this the current file is being considered an ES module +// Say why the current file is being considered an ES module func (p *parser) whyESModule() (whyESM, []logger.MsgData) { because := "This file is considered to be an ECMAScript module because" switch { diff --git a/vendor/github.com/evanw/esbuild/internal/js_printer/js_printer.go b/vendor/github.com/evanw/esbuild/internal/js_printer/js_printer.go index b6542bd8f..d41bbce69 100644 --- a/vendor/github.com/evanw/esbuild/internal/js_printer/js_printer.go +++ b/vendor/github.com/evanw/esbuild/internal/js_printer/js_printer.go @@ -1399,7 +1399,7 @@ func (p *printer) printQuotedUTF16(data []uint16, flags printQuotedFlags) { func (p *printer) printRequireOrImportExpr(importRecordIndex uint32, level js_ast.L, flags printExprFlags, closeParenLoc logger.Loc, phase ast.ImportPhase) { record := &p.importRecords[importRecordIndex] - if level >= js_ast.LNew || (flags&forbidCall) != 0 { + if level >= js_ast.LNew || (flags&isNewTarget) != 0 { p.print("(") defer p.print(")") level = js_ast.LLowest @@ -1759,7 +1759,7 @@ func (p *printer) guardAgainstBehaviorChangeDueToSubstitution(expr js_ast.Expr, // Constant folding is already implemented once in the parser. A smaller form // of constant folding (just for numbers) is implemented here to clean up cross- -// module numeric constants and bitwise operations. This is not an general- +// module numeric constants and bitwise operations. This is not a general- // purpose/optimal approach and never will be. For example, we can't affect // tree shaking at this stage because it has already happened. func (p *printer) lateConstantFoldUnaryOrBinaryOrIfExpr(expr js_ast.Expr) js_ast.Expr { @@ -1989,7 +1989,7 @@ func (p *printer) printExprWithoutLeadingNewline(expr js_ast.Expr, level js_ast. type printExprFlags uint16 const ( - forbidCall printExprFlags = 1 << iota + isNewTarget printExprFlags = 1 << iota forbidIn hasNonOptionalChainParent exprResultIsUnused @@ -2253,7 +2253,7 @@ func (p *printer) printExpr(expr js_ast.Expr, level js_ast.L, flags printExprFla p.addSourceMapping(expr.Loc) p.print("new") p.printSpace() - p.printExpr(e.Target, js_ast.LNew, forbidCall) + p.printExpr(e.Target, js_ast.LNew, isNewTarget) // Omit the "()" when minifying, but only when safe to do so isMultiLine := !p.options.MinifyWhitespace && ((e.IsMultiLine && len(e.Args) > 0) || @@ -2373,7 +2373,7 @@ func (p *printer) printExpr(expr js_ast.Expr, level js_ast.L, flags printExprFla } } - wrap := level >= js_ast.LNew || (flags&forbidCall) != 0 + wrap := level >= js_ast.LNew || (flags&isNewTarget) != 0 var targetFlags printExprFlags if e.OptionalChain == js_ast.OptionalChainNone { targetFlags = hasNonOptionalChainParent @@ -2456,7 +2456,7 @@ func (p *printer) printExpr(expr js_ast.Expr, level js_ast.L, flags printExprFla case *js_ast.ERequireResolveString: recordLoc := p.importRecords[e.ImportRecordIndex].Range.Loc isMultiLine := p.willPrintExprCommentsAtLoc(recordLoc) || p.willPrintExprCommentsAtLoc(e.CloseParenLoc) - wrap := level >= js_ast.LNew || (flags&forbidCall) != 0 + wrap := level >= js_ast.LNew || (flags&isNewTarget) != 0 if wrap { p.print("(") } @@ -2495,7 +2495,7 @@ func (p *printer) printExpr(expr js_ast.Expr, level js_ast.L, flags printExprFla (p.willPrintExprCommentsAtLoc(e.Expr.Loc) || (printImportAssertOrWith && p.willPrintExprCommentsAtLoc(e.OptionsOrNil.Loc)) || p.willPrintExprCommentsAtLoc(e.CloseParenLoc)) - wrap := level >= js_ast.LNew || (flags&forbidCall) != 0 + wrap := level >= js_ast.LNew || (flags&isNewTarget) != 0 if wrap { p.print("(") } @@ -2558,13 +2558,13 @@ func (p *printer) printExpr(expr js_ast.Expr, level js_ast.L, flags printExprFla break } } else { - if (flags & hasNonOptionalChainParent) != 0 { + if (flags & (isNewTarget | hasNonOptionalChainParent)) != 0 { wrap = true p.print("(") } - flags &= ^hasNonOptionalChainParent + flags &= ^(isNewTarget | hasNonOptionalChainParent) } - p.printExpr(e.Target, js_ast.LPostfix, (flags&(forbidCall|hasNonOptionalChainParent))|isPropertyAccessTarget) + p.printExpr(e.Target, js_ast.LPostfix, (flags&(isNewTarget|hasNonOptionalChainParent))|isPropertyAccessTarget) if p.canPrintIdentifier(e.Name) { if e.OptionalChain != js_ast.OptionalChainStart && p.needSpaceBeforeDot == len(p.js) { // "1.toString" is a syntax error, so print "1 .toString" instead @@ -2614,13 +2614,13 @@ func (p *printer) printExpr(expr js_ast.Expr, level js_ast.L, flags printExprFla } } } else { - if (flags & hasNonOptionalChainParent) != 0 { + if (flags & (isNewTarget | hasNonOptionalChainParent)) != 0 { p.print("(") defer p.print(")") } - flags &= ^hasNonOptionalChainParent + flags &= ^(isNewTarget | hasNonOptionalChainParent) } - p.printExpr(e.Target, js_ast.LPostfix, (flags&(forbidCall|hasNonOptionalChainParent))|isPropertyAccessTarget) + p.printExpr(e.Target, js_ast.LPostfix, (flags&(isNewTarget|hasNonOptionalChainParent))|isPropertyAccessTarget) if e.OptionalChain == js_ast.OptionalChainStart { p.print("?.") } @@ -3022,7 +3022,7 @@ func (p *printer) printExpr(expr js_ast.Expr, level js_ast.L, flags printExprFla p.printExpr(e.TagOrNil, js_ast.LLowest, isCallTargetOrTemplateTag) p.print(")") } else { - p.printExpr(e.TagOrNil, js_ast.LPostfix, isCallTargetOrTemplateTag) + p.printExpr(e.TagOrNil, js_ast.LPostfix, isCallTargetOrTemplateTag|(flags&isNewTarget)) } } else { p.addSourceMapping(expr.Loc) @@ -3081,7 +3081,7 @@ func (p *printer) printExpr(expr js_ast.Expr, level js_ast.L, flags printExprFla break } - wrap := level >= js_ast.LNew || (flags&forbidCall) != 0 + wrap := level >= js_ast.LNew || (flags&isNewTarget) != 0 hasPureComment := !p.options.MinifyWhitespace if hasPureComment && level >= js_ast.LPostfix { diff --git a/vendor/github.com/evanw/esbuild/internal/linker/linker.go b/vendor/github.com/evanw/esbuild/internal/linker/linker.go index bdff3162e..e4e6b9134 100644 --- a/vendor/github.com/evanw/esbuild/internal/linker/linker.go +++ b/vendor/github.com/evanw/esbuild/internal/linker/linker.go @@ -2431,9 +2431,9 @@ func (c *linkerContext) createWrapperForFile(sourceIndex uint32) { // However, that generation is special-cased for various reasons and is // done later on. Still, we're going to need to ensure that this file // both depends on the "__commonJS" symbol and declares the "require_foo" - // symbol. Instead of special-casing this during the reachablity analysis + // symbol. Instead of special-casing this during the reachability analysis // below, we just append a dummy part to the end of the file with these - // dependencies and let the general-purpose reachablity analysis take care + // dependencies and let the general-purpose reachability analysis take care // of it. case graph.WrapCJS: runtimeRepr := c.graph.Files[runtime.SourceIndex].InputFile.Repr.(*graph.JSRepr) @@ -5330,12 +5330,12 @@ func (c *linkerContext) renameSymbolsInChunk(chunk *chunkInfo, filesInOrder []ui reservedNames := renamer.ComputeReservedNames(moduleScopes, c.graph.Symbols) // Node contains code that scans CommonJS modules in an attempt to statically - // detect the set of export names that a module will use. However, it doesn't + // detect the set of export names that a module will use. However, it doesn't // do any scope analysis so it can be fooled by local variables with the same // name as the CommonJS module-scope variables "exports" and "module". Avoid // using these names in this case even if there is not a risk of a name // collision because there is still a risk of node incorrectly detecting - // something in a nested scope as an top-level export. Here's a case where + // something in a nested scope as a top-level export. Here's a case where // this happened: https://github.com/evanw/esbuild/issues/3544 if c.options.OutputFormat == config.FormatCommonJS && c.options.Platform == config.PlatformNode { reservedNames["exports"] = 1 diff --git a/vendor/github.com/evanw/esbuild/internal/runtime/runtime.go b/vendor/github.com/evanw/esbuild/internal/runtime/runtime.go index 5f95dcdc8..f63fb968d 100644 --- a/vendor/github.com/evanw/esbuild/internal/runtime/runtime.go +++ b/vendor/github.com/evanw/esbuild/internal/runtime/runtime.go @@ -170,18 +170,40 @@ func Source(unsupportedJSFeatures compat.JSFeature) logger.Source { // This is for lazily-initialized ESM code. This has two implementations, a // compact one for minified code and a verbose one that generates friendly // names in V8's profiler and in stack traces. - export var __esm = (fn, res) => function __init() { - return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res + export var __esm = (fn, res, err) => function __init() { + if (err) throw err[0] + try { + return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res + } catch (e) { + throw err = [e], e + } + } + export var __esmMin = (fn, res, err) => () => { + if (err) throw err[0] + try { + return fn && (res = fn(fn = 0)), res + } catch (e) { + throw err = [e], e + } } - export var __esmMin = (fn, res) => () => (fn && (res = fn(fn = 0)), res) // Wraps a CommonJS closure and returns a require() function. This has two // implementations, a compact one for minified code and a verbose one that // generates friendly names in V8's profiler and in stack traces. export var __commonJS = (cb, mod) => function __require() { - return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = {exports: {}}).exports, mod), mod.exports + try { + return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports + } catch (e) { + throw mod = 0, e + } + } + export var __commonJSMin = (cb, mod) => () => { + try { + return mod || cb((mod = { exports: {} }).exports, mod), mod.exports + } catch (e) { + throw mod = 0, e + } } - export var __commonJSMin = (cb, mod) => () => (mod || cb((mod = {exports: {}}).exports, mod), mod.exports) // Used to implement ESM exports both for "require()" and "import * as" export var __export = (target, all) => { diff --git a/vendor/github.com/evanw/esbuild/pkg/api/serve_other.go b/vendor/github.com/evanw/esbuild/pkg/api/serve_other.go index 77269e3a5..b8aefe536 100644 --- a/vendor/github.com/evanw/esbuild/pkg/api/serve_other.go +++ b/vendor/github.com/evanw/esbuild/pkg/api/serve_other.go @@ -9,7 +9,7 @@ package api // esbuild will automatically generate a directory listing page with links for // each file in the directory. If there is a build configured that generates // output files, those output files are not written to disk but are instead -// "overlayed" virtually on top of the real file system. The server responds to +// "overlaid" virtually on top of the real file system. The server responds to // HTTP requests for output files from the build with the latest in-memory // build results. @@ -154,6 +154,14 @@ func (h *apiHandler) ServeHTTP(res http.ResponseWriter, req *http.Request) { } } + // All requests containing Windows-style path separators are invalid + if strings.ContainsRune(req.URL.Path, '\\') { + go h.notifyRequest(time.Since(start), req, http.StatusBadRequest) + res.WriteHeader(http.StatusBadRequest) + maybeWriteResponseBody([]byte("400 - Bad Request")) + return + } + // Special-case the esbuild event stream if req.Method == "GET" && req.URL.Path == "/esbuild" && req.Header.Get("Accept") == "text/event-stream" { h.serveEventStream(start, req, res) diff --git a/vendor/modules.txt b/vendor/modules.txt index ab9419b13..40768c8e1 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -114,7 +114,7 @@ github.com/davecgh/go-spew/spew ## explicit; go 1.13 github.com/dlclark/regexp2 github.com/dlclark/regexp2/syntax -# github.com/evanw/esbuild v0.28.0 +# github.com/evanw/esbuild v0.28.1 ## explicit; go 1.13 github.com/evanw/esbuild/internal/api_helpers github.com/evanw/esbuild/internal/ast From 70ff59054ee30e11bf3a7d3924cf8b473e324262 Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Thu, 16 Jul 2026 14:48:32 +0300 Subject: [PATCH 012/182] fix(deps): update module github.com/mccutchen/go-httpbin/v2 to v2.23.1 (#6083) | datasource | package | from | to | | ---------- | ---------------------------------- | ------- | ------- | | go | github.com/mccutchen/go-httpbin/v2 | v2.23.0 | v2.23.1 | Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 ++-- vendor/modules.txt | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 36725af6a..a00f50dab 100644 --- a/go.mod +++ b/go.mod @@ -30,7 +30,7 @@ require ( github.com/klauspost/compress v1.18.5 github.com/mattn/go-colorable v0.1.15 github.com/mattn/go-isatty v0.0.22 - github.com/mccutchen/go-httpbin/v2 v2.23.0 + github.com/mccutchen/go-httpbin/v2 v2.23.1 github.com/mstoykov/atlas v0.0.0-20220811071828-388f114305dd github.com/mstoykov/envconfig v1.5.0 github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c diff --git a/go.sum b/go.sum index ebd556e5f..a391054a3 100644 --- a/go.sum +++ b/go.sum @@ -129,8 +129,8 @@ github.com/mattn/go-colorable v0.1.15 h1:+u9SLTRGnXv73cEsnsmoZBom+dMU88B2M0aDcWy github.com/mattn/go-colorable v0.1.15/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8= github.com/mattn/go-isatty v0.0.22 h1:j8l17JJ9i6VGPUFUYoTUKPSgKe/83EYU2zBC7YNKMw4= github.com/mattn/go-isatty v0.0.22/go.mod h1:ZXfXG4SQHsB/w3ZeOYbR0PrPwLy+n6xiMrJlRFqopa4= -github.com/mccutchen/go-httpbin/v2 v2.23.0 h1:7hmWWSeVGlIhYvLpa1cFssF6lsQp+UKoZ5i5FvidIqI= -github.com/mccutchen/go-httpbin/v2 v2.23.0/go.mod h1:8hkN5rHf0QvJYEovZ8u/Dudtqyj6Z5gxQaW7scQfT0Y= +github.com/mccutchen/go-httpbin/v2 v2.23.1 h1:F/05blJUzgTVTBd5bUW0cstUXnqnv5KIetb6uBciyG4= +github.com/mccutchen/go-httpbin/v2 v2.23.1/go.mod h1:8hkN5rHf0QvJYEovZ8u/Dudtqyj6Z5gxQaW7scQfT0Y= github.com/mstoykov/atlas v0.0.0-20220811071828-388f114305dd h1:AC3N94irbx2kWGA8f/2Ks7EQl2LxKIRQYuT9IJDwgiI= github.com/mstoykov/atlas v0.0.0-20220811071828-388f114305dd/go.mod h1:9vRHVuLCjoFfE3GT06X0spdOAO+Zzo4AMjdIwUHBvAk= github.com/mstoykov/envconfig v1.5.0 h1:E2FgWf73BQt0ddgn7aoITkQHmgwAcHup1s//MsS5/f8= diff --git a/vendor/modules.txt b/vendor/modules.txt index 40768c8e1..aabb9be83 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -251,7 +251,7 @@ github.com/mattn/go-colorable # github.com/mattn/go-isatty v0.0.22 ## explicit; go 1.21 github.com/mattn/go-isatty -# github.com/mccutchen/go-httpbin/v2 v2.23.0 +# github.com/mccutchen/go-httpbin/v2 v2.23.1 ## explicit; go 1.25.0 github.com/mccutchen/go-httpbin/v2/httpbin github.com/mccutchen/go-httpbin/v2/httpbin/digest From 9675777eaf0d20db9959a2831cd7b823db4f155b Mon Sep 17 00:00:00 2001 From: Mihail Stoykov <312246+mstoykov@users.noreply.github.com> Date: Thu, 16 Jul 2026 14:56:37 +0300 Subject: [PATCH 013/182] chore(cloudapi): bump k6-cloud-openapi-client-go for the int32->int64 ID widening (#6152) Upstream regenerated the client from a newer API spec that widens essentially every resource ID (projects, load tests, test runs, stack/default-project IDs, etc.) from int32 to int64. Follow suit in internal/cloudapi/v6: widen Project.ID, LoadTest.ID/ProjectID, and the Client method parameters/return values that carry these IDs, and adapt the ValidateOptions/CreateLoadTest/StartTest/etc. request builders and the v6test fixture server to the new SDK types. This also removes the int64->int32 "overflows int32" truncation dance in internal/cmd/cloud.go and cloud_loadtest_list.go for project IDs, since the v6 client now accepts the same int64 range as the rest of k6's cloud config. Stack IDs are unaffected (X-Stack-Id stays int32 upstream) and keep their existing truncation check. Pinned to the unreleased latest commit on k6-cloud-openapi-client-go's main (v0.0.3-0.20260625132134-c48eae4f9a18); no tagged release exists past v0.0.2 yet. SetStackID took int32, forcing every caller to duplicate an int64->int32 overflow check before calling it (cloud.go, cloud_loadtest_list.go, cloud_project_list.go all had their own copy). Move that check into SetStackID itself: it now takes int64 (matching how stack IDs are stored everywhere else, e.g. cloudapi.Config) and returns an error if the value doesn't fit in the int32 the underlying SDK's X-Stack-Id header setter still requires. That int32 ceiling is a real upstream limitation, not something fixable client-side: X-Stack-Id is generated from a single shared OpenAPI parameter component that never got the format: int64 bump the other ID fields received during the same regeneration passes - confirmed by reading the spec directly, not templates or generator config. Filing that upstream separately; until it's fixed, values overflowing 32 bits are rejected up front instead of being silently truncated. --- go.mod | 2 +- go.sum | 4 +- internal/cloudapi/v6/api.go | 26 +- internal/cloudapi/v6/api_test.go | 18 +- internal/cloudapi/v6/client.go | 13 +- internal/cloudapi/v6/v6test/server.go | 16 +- internal/cmd/cloud.go | 30 +- internal/cmd/cloud_loadtest_list.go | 14 +- internal/cmd/cloud_login.go | 2 +- internal/cmd/cloud_project_list.go | 6 +- .../k6/api_authorization.go | 2 +- .../k6/api_labels.go | 22 +- .../k6/api_load_tests.go | 48 +- .../k6/api_load_zones.go | 18 +- .../k6/api_projects.go | 22 +- .../k6/api_provisioning.go | 686 ++++++++++++++++++ .../k6/api_schedules.go | 26 +- .../k6/api_test_runs.go | 352 ++++++++- .../k6-cloud-openapi-client-go/k6/client.go | 7 +- .../k6/configuration.go | 2 +- .../k6/model_aisdk_session_api_model.go | 259 +++++++ .../k6/model_allowed_load_zone_api_model.go | 108 ++- ...l_allowed_load_zone_to_update_api_model.go | 14 +- ...model_allowed_load_zones_list_api_model.go | 2 +- .../k6/model_allowed_project_api_model.go | 14 +- ...del_allowed_project_to_update_api_model.go | 14 +- .../model_allowed_projects_list_api_model.go | 2 +- .../k6/model_authentication_response.go | 24 +- .../k6/model_base_total_vuh.go | 2 +- .../k6/model_browser_vuh.go | 2 +- .../k6/model_cloud_options.go | 14 +- .../k6/model_cost_breakdown_api_model.go | 2 +- .../k6/model_create_project_api_model.go | 2 +- .../k6/model_create_schedule_request.go | 2 +- .../k6/model_decrypted_api_model.go | 168 +++++ .../k6/model_distribution_zone_api_model.go | 2 +- .../k6/model_error_api_model.go | 2 +- .../k6/model_error_details_api_model.go | 2 +- .../k6/model_error_response_api_model.go | 2 +- .../k6/model_files_runtime_config.go | 258 +++++++ .../k6/model_frequency.go | 2 +- .../k6/model_label_key_create_item.go | 2 +- .../k6/model_label_key_create_request.go | 2 +- .../k6/model_label_key_list_response.go | 2 +- .../k6/model_label_key_patch_request.go | 34 +- .../k6/model_label_key_response.go | 14 +- .../k6/model_load_test_api_model.go | 91 ++- .../k6/model_load_test_list_response.go | 2 +- .../k6/model_load_zone_api_model.go | 108 ++- .../model_load_zone_distribution_api_model.go | 2 +- .../k6/model_load_zones_list_api_model.go | 2 +- .../k6/model_logs_runtime_config.go | 348 +++++++++ .../k6/model_metrics_runtime_config.go | 360 +++++++++ .../k6/model_move_load_test_api_model.go | 32 +- .../k6/model_node_api_model.go | 2 +- .../k6/model_options.go | 2 +- .../k6/model_options_cloud.go | 2 +- .../k6/model_patch_load_test_api_model.go | 99 ++- .../k6/model_patch_project_api_model.go | 22 +- .../k6/model_patch_project_limits_request.go | 36 +- .../k6/model_patch_test_run_api_model.go | 22 +- .../k6/model_project_api_model.go | 14 +- .../k6/model_project_label_item.go | 2 +- .../k6/model_project_label_list_response.go | 2 +- .../k6/model_project_label_put_item.go | 14 +- .../k6/model_project_label_put_request.go | 2 +- .../k6/model_project_label_put_response.go | 2 +- .../model_project_label_put_response_item.go | 14 +- .../k6/model_project_limits_api_model.go | 14 +- .../k6/model_project_limits_list_response.go | 2 +- .../k6/model_project_list_response.go | 2 +- .../k6/model_protocol_vuh.go | 2 +- .../k6/model_reduction_rate.go | 2 +- .../model_reduction_rate_breakdown_value.go | 2 +- .../k6/model_result_details_api_model.go | 266 +++++++ .../k6/model_runtime_config.go | 313 ++++++++ .../k6/model_schedule_api_model.go | 24 +- .../k6/model_schedule_cron.go | 2 +- .../k6/model_schedule_list_response.go | 2 +- .../k6/model_schedule_recurrence_rule.go | 2 +- ...cution_completed_notification_api_model.go | 216 ++++++ .../k6/model_script_execution_error.go | 247 +++++++ .../k6/model_secrets_runtime_config.go | 198 +++++ .../k6/model_start_load_test_response.go | 95 ++- ...odel_start_local_execution_test_request.go | 326 +++++++++ ...del_start_local_execution_test_response.go | 259 +++++++ .../k6/model_status_api_model.go | 2 +- .../k6/model_status_extra_api_model.go | 2 +- .../k6/model_test_cost_api_model.go | 2 +- .../k6/model_test_run_api_model.go | 97 ++- .../k6/model_test_run_api_model_cost.go | 2 +- ...model_test_run_api_model_result_details.go | 127 ++++ .../model_test_run_distribution_api_model.go | 2 +- .../k6/model_test_run_list_response.go | 2 +- .../k6/model_total_vuh.go | 2 +- .../k6/model_traces_runtime_config.go | 228 ++++++ ...pdate_allowed_load_zones_list_api_model.go | 2 +- ..._update_allowed_projects_list_api_model.go | 2 +- .../k6/model_validate_options_request.go | 63 +- .../k6/model_validate_options_response.go | 2 +- .../k6/model_weekday.go | 2 +- .../k6-cloud-openapi-client-go/k6/response.go | 2 +- .../k6-cloud-openapi-client-go/k6/utils.go | 2 +- vendor/modules.txt | 2 +- 104 files changed, 5520 insertions(+), 444 deletions(-) create mode 100644 vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/api_provisioning.go create mode 100644 vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_aisdk_session_api_model.go create mode 100644 vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_decrypted_api_model.go create mode 100644 vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_files_runtime_config.go create mode 100644 vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_logs_runtime_config.go create mode 100644 vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_metrics_runtime_config.go create mode 100644 vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_result_details_api_model.go create mode 100644 vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_runtime_config.go create mode 100644 vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_script_execution_completed_notification_api_model.go create mode 100644 vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_script_execution_error.go create mode 100644 vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_secrets_runtime_config.go create mode 100644 vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_start_local_execution_test_request.go create mode 100644 vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_start_local_execution_test_response.go create mode 100644 vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_test_run_api_model_result_details.go create mode 100644 vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_traces_runtime_config.go diff --git a/go.mod b/go.mod index a00f50dab..e26baa51c 100644 --- a/go.mod +++ b/go.mod @@ -20,7 +20,7 @@ require ( github.com/golang/protobuf v1.5.4 github.com/google/uuid v1.6.0 github.com/gorilla/websocket v1.5.3 - github.com/grafana/k6-cloud-openapi-client-go v0.0.2 + github.com/grafana/k6-cloud-openapi-client-go v0.0.3-0.20260625132134-c48eae4f9a18 github.com/grafana/k6provider v0.5.0 github.com/grafana/sobek v0.0.0-20260429085637-a66d4790012b github.com/grafana/xk6-dashboard-assets v0.1.2 diff --git a/go.sum b/go.sum index a391054a3..54d38a9eb 100644 --- a/go.sum +++ b/go.sum @@ -90,8 +90,8 @@ 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/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/grafana/k6-cloud-openapi-client-go v0.0.2 h1:YzMFCaKiLA8UFQjCrrhrtkxvkzcRt8ENMeo+f7ndV7k= -github.com/grafana/k6-cloud-openapi-client-go v0.0.2/go.mod h1:RBPBP7qIR/K6qzQEQYESVhp/XJspiBTOyBEBCbPXrvI= +github.com/grafana/k6-cloud-openapi-client-go v0.0.3-0.20260625132134-c48eae4f9a18 h1:ZRUtDAU/2ozxTApsNPbXRGDig4VwVydhEntdNTz5olY= +github.com/grafana/k6-cloud-openapi-client-go v0.0.3-0.20260625132134-c48eae4f9a18/go.mod h1:RhZGBq6e90zSi0EME83c6S1qkOzD8pP0MNETqieWX0k= github.com/grafana/k6provider v0.5.0 h1:SwItWPOMQHfRytezQBKpeXLxjNmcyD/x9PTA28pEbwg= github.com/grafana/k6provider v0.5.0/go.mod h1:R9WKthnwk96E47m6w/mnC13hhBYTn5iMdP5caFt/t5k= github.com/grafana/sobek v0.0.0-20260429085637-a66d4790012b h1:mM/qn1luOrRZHT3G+405JMdCx4mGxeLKpOkVBa5+lFw= diff --git a/internal/cloudapi/v6/api.go b/internal/cloudapi/v6/api.go index 1b435596f..e59bf01b8 100644 --- a/internal/cloudapi/v6/api.go +++ b/internal/cloudapi/v6/api.go @@ -19,15 +19,15 @@ import ( // Project is a Grafana Cloud k6 project. type Project struct { - ID int32 `json:"id"` + ID int64 `json:"id"` Name string `json:"name"` IsDefault bool `json:"is_default"` } // LoadTest is a Grafana Cloud k6 load test. type LoadTest struct { - ID int32 `json:"id"` - ProjectID int32 `json:"project_id"` + ID int64 `json:"id"` + ProjectID int64 `json:"project_id"` Name string `json:"name"` Created time.Time `json:"created"` Updated time.Time `json:"updated"` @@ -87,7 +87,7 @@ func (c *Client) listProjectsPage( } // ListLoadTests retrieves the list of load tests in the given project. -func (c *Client) ListLoadTests(ctx context.Context, projectID int32) ([]LoadTest, error) { +func (c *Client) ListLoadTests(ctx context.Context, projectID int64) ([]LoadTest, error) { const pageSize int32 = 1000 tests := []LoadTest{} @@ -121,7 +121,7 @@ func (c *Client) ListLoadTests(ctx context.Context, projectID int32) ([]LoadTest } func (c *Client) listLoadTestsPage( - ctx context.Context, projectID, skip, top int32, + ctx context.Context, projectID int64, skip, top int32, ) (*k6cloud.LoadTestListResponse, error) { res, hr, err := c.apiClient.LoadTestsAPI. ProjectsLoadTestsRetrieve(c.authCtx(ctx), projectID). @@ -167,7 +167,7 @@ func (c *Client) ValidateToken(ctx context.Context, stackURL string) (_ *k6cloud } // ValidateOptions validates cloud test options. -func (c *Client) ValidateOptions(ctx context.Context, projectID int32, opts lib.Options) (err error) { +func (c *Client) ValidateOptions(ctx context.Context, projectID int64, opts lib.Options) (err error) { // Round-trip [lib.Options] through JSON so every script option // reaches the backend via [k6cloud.Options.AdditionalProperties]. buf, err := json.Marshal(opts) @@ -202,7 +202,7 @@ func (c *Client) ValidateOptions(ctx context.Context, projectID int32, opts lib. // UploadTest creates or updates a cloud load test's script. func (c *Client) UploadTest( - ctx context.Context, name string, projectID int32, arc *lib.Archive, + ctx context.Context, name string, projectID int64, arc *lib.Archive, ) (*k6cloud.LoadTestApiModel, error) { lt, err := c.createTest(ctx, name, projectID, arc) if err == nil { @@ -228,7 +228,7 @@ func (c *Client) UploadTest( // createTest creates a new cloud load test in the given project. func (c *Client) createTest( - ctx context.Context, name string, projectID int32, arc *lib.Archive, + ctx context.Context, name string, projectID int64, arc *lib.Archive, ) (_ *k6cloud.LoadTestApiModel, err error) { res, hr, err := c.apiClient.LoadTestsAPI. ProjectsLoadTestsCreate(c.authCtx(ctx), projectID). @@ -249,7 +249,7 @@ func (c *Client) createTest( } func (c *Client) findTestByName( - ctx context.Context, projectID int32, name string, + ctx context.Context, projectID int64, name string, ) (_ *k6cloud.LoadTestApiModel, err error) { res, hr, err := c.apiClient.LoadTestsAPI. ProjectsLoadTestsRetrieve(c.authCtx(ctx), projectID). @@ -274,7 +274,7 @@ func (c *Client) findTestByName( return &tests[0], nil } -func (c *Client) updateScript(ctx context.Context, testID int32, arc *lib.Archive) (err error) { +func (c *Client) updateScript(ctx context.Context, testID int64, arc *lib.Archive) (err error) { res, err := c.apiClient.LoadTestsAPI. LoadTestsScriptUpdate(c.authCtx(ctx), testID). XStackId(c.stackID). @@ -286,7 +286,7 @@ func (c *Client) updateScript(ctx context.Context, testID int32, arc *lib.Archiv } // StartTest starts a cloud load test run. -func (c *Client) StartTest(ctx context.Context, loadTestID int32) (_ *k6cloud.StartLoadTestResponse, err error) { +func (c *Client) StartTest(ctx context.Context, loadTestID int64) (_ *k6cloud.StartLoadTestResponse, err error) { var key [8]byte if _, err := rand.Read(key[:]); err != nil { return nil, err @@ -310,7 +310,7 @@ func (c *Client) StartTest(ctx context.Context, loadTestID int32) (_ *k6cloud.St } // StopTest aborts a running cloud test run. -func (c *Client) StopTest(ctx context.Context, testRunID int32) (err error) { +func (c *Client) StopTest(ctx context.Context, testRunID int64) (err error) { hr, err := c.apiClient.TestRunsAPI. TestRunsAbort(c.authCtx(ctx), testRunID). XStackId(c.stackID). @@ -327,7 +327,7 @@ func (c *Client) StopTest(ctx context.Context, testRunID int32) (err error) { } // FetchTest fetches the current progress of a cloud test run. -func (c *Client) FetchTest(ctx context.Context, testRunID int32) (_ *TestProgress, err error) { +func (c *Client) FetchTest(ctx context.Context, testRunID int64) (_ *TestProgress, err error) { res, hr, err := c.apiClient.TestRunsAPI. TestRunsRetrieve(c.authCtx(ctx), testRunID). XStackId(c.stackID). diff --git a/internal/cloudapi/v6/api_test.go b/internal/cloudapi/v6/api_test.go index 40a6d5e93..c16ebf63f 100644 --- a/internal/cloudapi/v6/api_test.go +++ b/internal/cloudapi/v6/api_test.go @@ -51,8 +51,8 @@ func TestValidateToken(t *testing.T) { resp, err := client.ValidateToken(t.Context(), "https://stack.grafana.net") require.NoError(t, err) require.NotNil(t, resp) - assert.Equal(t, int32(123), resp.StackId) - assert.Equal(t, int32(456), resp.DefaultProjectId) + assert.Equal(t, int64(123), resp.StackId) + assert.Equal(t, int64(456), resp.DefaultProjectId) }) t.Run("unauthorized token should fail", func(t *testing.T) { @@ -195,7 +195,7 @@ func TestListLoadTests(t *testing.T) { Created: time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC), Updated: time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC), }, tests[0]) - assert.Equal(t, int32(2), tests[1].ID) + assert.Equal(t, int64(2), tests[1].ID) } func TestRetryWithConnectionClose(t *testing.T) { @@ -219,7 +219,7 @@ func TestRetryWithConnectionClose(t *testing.T) { client, err := NewClient(testutils.NewLogger(t), "test-token", srv.URL, "1.0", 5*time.Second) require.NoError(t, err) - client.SetStackID(1) + require.NoError(t, client.SetStackID(1)) opts := lib.Options{VUs: null.IntFrom(10)} require.NoError(t, client.ValidateOptions(t.Context(), 1, opts)) @@ -240,7 +240,7 @@ func TestValidateOptions(t *testing.T) { var body struct { Options json.RawMessage `json:"options"` - ProjectID int32 `json:"project_id"` + ProjectID int64 `json:"project_id"` } client := newTestClient(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { assert.NoError(t, json.NewDecoder(r.Body).Decode(&body)) @@ -258,7 +258,7 @@ func TestValidateOptions(t *testing.T) { want, err := json.Marshal(opts) require.NoError(t, err) assert.JSONEq(t, string(want), string(body.Options)) - assert.Equal(t, int32(42), body.ProjectID) + assert.Equal(t, int64(42), body.ProjectID) } func TestUploadTest(t *testing.T) { @@ -359,7 +359,7 @@ func TestStartTest(t *testing.T) { res := k6cloud.NewStartLoadTestResponseWithDefaults() res.SetId(7) res.SetDistribution([]k6cloud.DistributionZoneApiModel{}) - res.SetResultDetails(map[string]any{}) + res.SetResultDetails(*k6cloud.NewResultDetailsApiModel("")) res.SetOptions(map[string]any{}) client := newTestClient(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -419,7 +419,7 @@ func TestFetchTest(t *testing.T) { res.SetExecutionDuration(want.ExecutionDuration) res.SetStatusHistory(ToStatusModel(want.StatusHistory)) res.SetDistribution([]k6cloud.DistributionZoneApiModel{*k6cloud.NewDistributionZoneApiModelWithDefaults()}) - res.SetResultDetails(map[string]any{"foo": "bar"}) + res.SetResultDetails(k6cloud.ResultDetailsApiModelAsTestRunApiModelResultDetails(k6cloud.NewResultDetailsApiModel("failed"))) res.SetOptions(map[string]any{"vus": 10}) client := newTestClient(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -440,7 +440,7 @@ func newTestClient(t *testing.T, handler http.Handler) *Client { client, err := NewClient(testutils.NewLogger(t), "test-token", srv.URL, "1.0", 5*time.Second) require.NoError(t, err) - client.SetStackID(1) + require.NoError(t, client.SetStackID(1)) return client } diff --git a/internal/cloudapi/v6/client.go b/internal/cloudapi/v6/client.go index 007412e14..3bb190d45 100644 --- a/internal/cloudapi/v6/client.go +++ b/internal/cloudapi/v6/client.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "io" + "math" "net/http" "time" @@ -62,9 +63,15 @@ func NewClient(logger logrus.FieldLogger, token, host, version string, timeout t return c, nil } -// SetStackID sets the stack ID for the client. -func (c *Client) SetStackID(stackID int32) { - c.stackID = stackID +// SetStackID sets the stack ID for the client. It returns an error if +// stackID does not fit in the int32 range the underlying SDK requires for +// the X-Stack-Id header. +func (c *Client) SetStackID(stackID int64) error { + if stackID < math.MinInt32 || stackID > math.MaxInt32 { + return fmt.Errorf("stack ID %d overflows int32", stackID) + } + c.stackID = int32(stackID) + return nil } // BaseURL returns configured host. diff --git a/internal/cloudapi/v6/v6test/server.go b/internal/cloudapi/v6/v6test/server.go index 724adb813..a542e58a8 100644 --- a/internal/cloudapi/v6/v6test/server.go +++ b/internal/cloudapi/v6/v6test/server.go @@ -23,8 +23,8 @@ import ( ) const ( - defaultLoadTestID int32 = 456 - defaultTestRunID int32 = 123 + defaultLoadTestID int64 = 456 + defaultTestRunID int64 = 123 ) // Server is a test HTTP server for the v6 cloud API. @@ -39,7 +39,7 @@ type Server struct { type Config struct { // TestRunID is the id reported by the start-test response and used // in the test-run routes. Defaults to [defaultTestRunID] when zero. - TestRunID int32 + TestRunID int64 // ProgressCallback returns the [cloudapi.TestProgress] reported by // each test fetch. When nil, a finished passing run is reported. @@ -115,7 +115,7 @@ func (s *Server) handleListProjects(w http.ResponseWriter, _ *http.Request) { } func (s *Server) handleListLoadTests(w http.ResponseWriter, r *http.Request) { - projectID, err := strconv.ParseInt(r.PathValue("projectID"), 10, 32) + projectID, err := strconv.ParseInt(r.PathValue("projectID"), 10, 64) if err != nil { http.Error(w, "invalid project ID", http.StatusBadRequest) return @@ -123,14 +123,14 @@ func (s *Server) handleListLoadTests(w http.ResponseWriter, r *http.Request) { tests := make([]k6cloud.LoadTestApiModel, 0, len(s.cfg.LoadTests)) for _, test := range s.cfg.LoadTests { - if test.ProjectID != int32(projectID) { + if test.ProjectID != projectID { continue } tests = append(tests, *k6cloud.NewLoadTestApiModel( test.ID, test.ProjectID, test.Name, - *k6cloud.NewNullableInt32(nil), + *k6cloud.NewNullableInt64(nil), test.Created, test.Updated, )) @@ -166,7 +166,7 @@ func (s *Server) handleStartTest(w http.ResponseWriter, _ *http.Request) { res.SetTestRunDetailsPageUrl(fmt.Sprintf("https://stack.grafana.com/a/k6-app/runs/%d", s.cfg.TestRunID)) // SDK decoder requires these keys on the other end even when empty. res.SetDistribution([]k6cloud.DistributionZoneApiModel{}) - res.SetResultDetails(map[string]any{}) + res.SetResultDetails(*k6cloud.NewResultDetailsApiModel("")) res.SetOptions(map[string]any{}) writeJSON(w, http.StatusOK, res) } @@ -190,7 +190,7 @@ func (s *Server) handleGetTestRun(w http.ResponseWriter, _ *http.Request) { res.SetStatusHistory(cloudapi.ToStatusModel(tp.StatusHistory)) // SDK decoder requires these keys on the other end even when empty. res.SetDistribution([]k6cloud.DistributionZoneApiModel{}) - res.SetResultDetails(map[string]any{}) + res.SetResultDetails(k6cloud.ResultDetailsApiModelAsTestRunApiModelResultDetails(k6cloud.NewResultDetailsApiModel(""))) res.SetOptions(map[string]any{}) writeJSON(w, http.StatusOK, res) } diff --git a/internal/cmd/cloud.go b/internal/cmd/cloud.go index b3df1b22f..1133355fc 100644 --- a/internal/cmd/cloud.go +++ b/internal/cmd/cloud.go @@ -5,7 +5,6 @@ import ( "encoding/json" "errors" "fmt" - "math" "net/url" "os" "path/filepath" @@ -295,7 +294,7 @@ func (c *cmdCloud) run(cmd *cobra.Command, args []string) error { ticker := time.NewTicker(time.Millisecond * 2000) if c.showCloudLogs { - refID := strconv.FormatInt(int64(testRunID), 10) + refID := strconv.FormatInt(testRunID, 10) go func() { logger.Debug("Connecting to cloud logs server...") if err := cloudConfig.StreamLogsToLogger(globalCtx, logger, refID, 0); err != nil { @@ -463,33 +462,18 @@ func prepCloudTestRun( ctx context.Context, gs *state.GlobalState, client *cloudapiv6.Client, cloudConfig *cloudapi.Config, tmpCloudConfig map[string]any, arc *lib.Archive, -) (int32, error) { - toInt32 := func(v int64) (int32, error) { - if v < math.MinInt32 || v > math.MaxInt32 { - return 0, fmt.Errorf("value %d overflows int32", v) - } - return int32(v), nil - } - - stackID, err := toInt32(cloudConfig.StackID.Int64) - if err != nil { +) (int64, error) { + if err := client.SetStackID(cloudConfig.StackID.Int64); err != nil { return 0, err } - client.SetStackID(stackID) - projectID, err := toInt32(cloudConfig.ProjectID.Int64) - if err != nil { - return 0, err - } + projectID := cloudConfig.ProjectID.Int64 if projectID == 0 { if err := resolveAndSetProjectID(gs, cloudConfig, tmpCloudConfig, arc); err != nil { return 0, err } - projectID, err = toInt32(cloudConfig.ProjectID.Int64) - if err != nil { - return 0, err - } + projectID = cloudConfig.ProjectID.Int64 } if err := client.ValidateOptions(ctx, projectID, arc.Options); err != nil { @@ -550,11 +534,11 @@ func resolveAndSetProjectID( return nil } -func resolveCloudTestURL(stackURL string, testID int32) (string, error) { +func resolveCloudTestURL(stackURL string, testID int64) (string, error) { u, err := url.Parse(stackURL) if err != nil { return "", fmt.Errorf("invalid stack URL: %w", err) } - return u.JoinPath("a", "k6-app", "tests", strconv.FormatInt(int64(testID), 10)).String(), nil + return u.JoinPath("a", "k6-app", "tests", strconv.FormatInt(testID, 10)).String(), nil } diff --git a/internal/cmd/cloud_loadtest_list.go b/internal/cmd/cloud_loadtest_list.go index a50476c07..6034abd17 100644 --- a/internal/cmd/cloud_loadtest_list.go +++ b/internal/cmd/cloud_loadtest_list.go @@ -4,7 +4,6 @@ import ( "bytes" "encoding/json" "fmt" - "math" "strings" "text/tabwriter" @@ -88,10 +87,9 @@ func (c *cmdCloudTestList) run(cmd *cobra.Command, _ []string) error { return err } - if cloudConfig.StackID.Int64 < math.MinInt32 || cloudConfig.StackID.Int64 > math.MaxInt32 { - return fmt.Errorf("stack ID %d overflows int32", cloudConfig.StackID.Int64) + if err := client.SetStackID(cloudConfig.StackID.Int64); err != nil { + return err } - client.SetStackID(int32(cloudConfig.StackID.Int64)) tests, err := client.ListLoadTests(c.globalState.Ctx, projectID) if err != nil { @@ -121,7 +119,7 @@ func (c *cmdCloudTestList) run(cmd *cobra.Command, _ []string) error { // shared resolveDefaultProjectID helper (config projectID, then the stack's // default project). Unlike `k6 cloud run`, listing needs a concrete project, so // a zero result is treated as an error. -func (c *cmdCloudTestList) resolveProjectID(cloudConfig cloudapi.Config, projectIDSet bool) (int32, error) { +func (c *cmdCloudTestList) resolveProjectID(cloudConfig cloudapi.Config, projectIDSet bool) (int64, error) { if projectIDSet { if c.projectID <= 0 { return 0, errNoProjectConfigured @@ -137,11 +135,7 @@ func (c *cmdCloudTestList) resolveProjectID(cloudConfig cloudapi.Config, project return 0, errNoProjectConfigured } - if id < math.MinInt32 || id > math.MaxInt32 { - return 0, fmt.Errorf("project ID %d overflows int32", id) - } - - return int32(id), nil + return id, nil } func (c *cmdCloudTestList) outputJSON(tests []v6cloudapi.LoadTest) error { diff --git a/internal/cmd/cloud_login.go b/internal/cmd/cloud_login.go index a476d47f7..cd08286e1 100644 --- a/internal/cmd/cloud_login.go +++ b/internal/cmd/cloud_login.go @@ -308,7 +308,7 @@ func validateTokenV6( return "", 0, 0, err } - return normalizedURL, int64(authResp.StackId), int64(authResp.DefaultProjectId), nil + return normalizedURL, authResp.StackId, authResp.DefaultProjectId, nil } // normalizeStackURL converts a stack slug to a full URL if needed and removes trailing slashes. diff --git a/internal/cmd/cloud_project_list.go b/internal/cmd/cloud_project_list.go index 81c5d7d30..a13599c93 100644 --- a/internal/cmd/cloud_project_list.go +++ b/internal/cmd/cloud_project_list.go @@ -4,7 +4,6 @@ import ( "bytes" "encoding/json" "fmt" - "math" "strings" "text/tabwriter" @@ -76,10 +75,9 @@ func (c *cmdCloudProjectList) run(_ *cobra.Command, _ []string) error { return err } - if cloudConfig.StackID.Int64 < math.MinInt32 || cloudConfig.StackID.Int64 > math.MaxInt32 { - return fmt.Errorf("stack ID %d overflows int32", cloudConfig.StackID.Int64) + if err := client.SetStackID(cloudConfig.StackID.Int64); err != nil { + return err } - client.SetStackID(int32(cloudConfig.StackID.Int64)) projects, err := client.ListProjects(c.globalState.Ctx) if err != nil { diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/api_authorization.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/api_authorization.go index bf737fa67..54e32187d 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/api_authorization.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/api_authorization.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/api_labels.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/api_labels.go index a38dd6c0a..63828900f 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/api_labels.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/api_labels.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ @@ -206,7 +206,7 @@ type ApiLabelsDestroyRequest struct { ctx context.Context ApiService *LabelsAPIService xStackId *int32 - id int32 + id int64 } // Numeric ID of the Grafana stack representing the request scope. - If the API is called with a *Personal API token*, the user must be a member of the specified stack. - If the API is called with a *Grafana Stack API token*, the value must be the ID of the corresponding stack. @@ -231,7 +231,7 @@ are cascade deleted. @param id ID of the label key. @return *ApiLabelsDestroyRequest */ -func (a *LabelsAPIService) LabelsDestroy(ctx context.Context, id int32) *ApiLabelsDestroyRequest { +func (a *LabelsAPIService) LabelsDestroy(ctx context.Context, id int64) *ApiLabelsDestroyRequest { return &ApiLabelsDestroyRequest{ ApiService: a, ctx: ctx, @@ -498,7 +498,7 @@ type ApiLabelsPartialUpdateRequest struct { ctx context.Context ApiService *LabelsAPIService xStackId *int32 - id int32 + id int64 labelKeyPatchRequest *LabelKeyPatchRequest } @@ -526,7 +526,7 @@ Update a label key (rename or update description) (Admin only). @param id ID of the label key. @return *ApiLabelsPartialUpdateRequest */ -func (a *LabelsAPIService) LabelsPartialUpdate(ctx context.Context, id int32) *ApiLabelsPartialUpdateRequest { +func (a *LabelsAPIService) LabelsPartialUpdate(ctx context.Context, id int64) *ApiLabelsPartialUpdateRequest { return &ApiLabelsPartialUpdateRequest{ ApiService: a, ctx: ctx, @@ -687,7 +687,7 @@ type ApiProjectsLabelsDestroyRequest struct { ApiService *LabelsAPIService xStackId *int32 key string - projectId int32 + projectId int64 } // Numeric ID of the Grafana stack representing the request scope. - If the API is called with a *Personal API token*, the user must be a member of the specified stack. - If the API is called with a *Grafana Stack API token*, the value must be the ID of the corresponding stack. @@ -710,7 +710,7 @@ Remove a label from a project (Admin or Editor). @param projectId ID of the project. @return *ApiProjectsLabelsDestroyRequest */ -func (a *LabelsAPIService) ProjectsLabelsDestroy(ctx context.Context, key string, projectId int32) *ApiProjectsLabelsDestroyRequest { +func (a *LabelsAPIService) ProjectsLabelsDestroy(ctx context.Context, key string, projectId int64) *ApiProjectsLabelsDestroyRequest { return &ApiProjectsLabelsDestroyRequest{ ApiService: a, ctx: ctx, @@ -836,7 +836,7 @@ type ApiProjectsLabelsListRequest struct { ctx context.Context ApiService *LabelsAPIService xStackId *int32 - projectId int32 + projectId int64 } // Numeric ID of the Grafana stack representing the request scope. - If the API is called with a *Personal API token*, the user must be a member of the specified stack. - If the API is called with a *Grafana Stack API token*, the value must be the ID of the corresponding stack. @@ -858,7 +858,7 @@ List all labels on a project. @param projectId ID of the project. @return *ApiProjectsLabelsListRequest */ -func (a *LabelsAPIService) ProjectsLabelsList(ctx context.Context, projectId int32) *ApiProjectsLabelsListRequest { +func (a *LabelsAPIService) ProjectsLabelsList(ctx context.Context, projectId int64) *ApiProjectsLabelsListRequest { return &ApiProjectsLabelsListRequest{ ApiService: a, ctx: ctx, @@ -994,7 +994,7 @@ type ApiProjectsLabelsUpdateRequest struct { ctx context.Context ApiService *LabelsAPIService xStackId *int32 - projectId int32 + projectId int64 projectLabelPutRequest *ProjectLabelPutRequest } @@ -1024,7 +1024,7 @@ This is a full replacement operation. @param projectId ID of the project. @return *ApiProjectsLabelsUpdateRequest */ -func (a *LabelsAPIService) ProjectsLabelsUpdate(ctx context.Context, projectId int32) *ApiProjectsLabelsUpdateRequest { +func (a *LabelsAPIService) ProjectsLabelsUpdate(ctx context.Context, projectId int64) *ApiProjectsLabelsUpdateRequest { return &ApiProjectsLabelsUpdateRequest{ ApiService: a, ctx: ctx, diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/api_load_tests.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/api_load_tests.go index 3b9d4fb0f..e16bc0549 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/api_load_tests.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/api_load_tests.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ @@ -28,7 +28,7 @@ type ApiLoadTestsDestroyRequest struct { ctx context.Context ApiService *LoadTestsAPIService xStackId *int32 - id int32 + id int64 } // Numeric ID of the Grafana stack representing the request scope. - If the API is called with a *Personal API token*, the user must be a member of the specified stack. - If the API is called with a *Grafana Stack API token*, the value must be the ID of the corresponding stack. @@ -50,7 +50,7 @@ Delete a load test. @param id ID of the load test. @return *ApiLoadTestsDestroyRequest */ -func (a *LoadTestsAPIService) LoadTestsDestroy(ctx context.Context, id int32) *ApiLoadTestsDestroyRequest { +func (a *LoadTestsAPIService) LoadTestsDestroy(ctx context.Context, id int64) *ApiLoadTestsDestroyRequest { return &ApiLoadTestsDestroyRequest{ ApiService: a, ctx: ctx, @@ -392,7 +392,7 @@ type ApiLoadTestsMoveRequest struct { ctx context.Context ApiService *LoadTestsAPIService xStackId *int32 - id int32 + id int64 moveLoadTestApiModel *MoveLoadTestApiModel } @@ -421,7 +421,7 @@ All respective test runs will be also moved to the new project. @param id ID of the load test. @return *ApiLoadTestsMoveRequest */ -func (a *LoadTestsAPIService) LoadTestsMove(ctx context.Context, id int32) *ApiLoadTestsMoveRequest { +func (a *LoadTestsAPIService) LoadTestsMove(ctx context.Context, id int64) *ApiLoadTestsMoveRequest { return &ApiLoadTestsMoveRequest{ ApiService: a, ctx: ctx, @@ -572,7 +572,7 @@ type ApiLoadTestsPartialUpdateRequest struct { ctx context.Context ApiService *LoadTestsAPIService xStackId *int32 - id int32 + id int64 patchLoadTestApiModel *PatchLoadTestApiModel } @@ -600,7 +600,7 @@ Update a load test. @param id ID of the load test. @return *ApiLoadTestsPartialUpdateRequest */ -func (a *LoadTestsAPIService) LoadTestsPartialUpdate(ctx context.Context, id int32) *ApiLoadTestsPartialUpdateRequest { +func (a *LoadTestsAPIService) LoadTestsPartialUpdate(ctx context.Context, id int64) *ApiLoadTestsPartialUpdateRequest { return &ApiLoadTestsPartialUpdateRequest{ ApiService: a, ctx: ctx, @@ -748,7 +748,7 @@ type ApiLoadTestsRetrieveRequest struct { ctx context.Context ApiService *LoadTestsAPIService xStackId *int32 - id int32 + id int64 } // Numeric ID of the Grafana stack representing the request scope. - If the API is called with a *Personal API token*, the user must be a member of the specified stack. - If the API is called with a *Grafana Stack API token*, the value must be the ID of the corresponding stack. @@ -770,7 +770,7 @@ Fetch a single load test. @param id ID of the load test. @return *ApiLoadTestsRetrieveRequest */ -func (a *LoadTestsAPIService) LoadTestsRetrieve(ctx context.Context, id int32) *ApiLoadTestsRetrieveRequest { +func (a *LoadTestsAPIService) LoadTestsRetrieve(ctx context.Context, id int64) *ApiLoadTestsRetrieveRequest { return &ApiLoadTestsRetrieveRequest{ ApiService: a, ctx: ctx, @@ -906,7 +906,7 @@ type ApiLoadTestsScriptRetrieveRequest struct { ctx context.Context ApiService *LoadTestsAPIService xStackId *int32 - id int32 + id int64 } // Numeric ID of the Grafana stack representing the request scope. - If the API is called with a *Personal API token*, the user must be a member of the specified stack. - If the API is called with a *Grafana Stack API token*, the value must be the ID of the corresponding stack. @@ -931,7 +931,7 @@ the type is identified by the request content type. @param id ID of the load test. @return *ApiLoadTestsScriptRetrieveRequest */ -func (a *LoadTestsAPIService) LoadTestsScriptRetrieve(ctx context.Context, id int32) *ApiLoadTestsScriptRetrieveRequest { +func (a *LoadTestsAPIService) LoadTestsScriptRetrieve(ctx context.Context, id int64) *ApiLoadTestsScriptRetrieveRequest { return &ApiLoadTestsScriptRetrieveRequest{ ApiService: a, ctx: ctx, @@ -1078,7 +1078,7 @@ type ApiLoadTestsScriptUpdateRequest struct { ctx context.Context ApiService *LoadTestsAPIService xStackId *int32 - id int32 + id int64 body io.ReadCloser } @@ -1110,7 +1110,7 @@ is assumed to be a JavaScript file. @param id ID of the load test. @return *ApiLoadTestsScriptUpdateRequest */ -func (a *LoadTestsAPIService) LoadTestsScriptUpdate(ctx context.Context, id int32) *ApiLoadTestsScriptUpdateRequest { +func (a *LoadTestsAPIService) LoadTestsScriptUpdate(ctx context.Context, id int64) *ApiLoadTestsScriptUpdateRequest { return &ApiLoadTestsScriptUpdateRequest{ ApiService: a, ctx: ctx, @@ -1247,7 +1247,7 @@ type ApiLoadTestsStartRequest struct { ctx context.Context ApiService *LoadTestsAPIService xStackId *int32 - id int32 + id int64 k6IdempotencyKey *string } @@ -1276,7 +1276,7 @@ Start a test in Grafana Cloud. @param id ID of the load test. @return *ApiLoadTestsStartRequest */ -func (a *LoadTestsAPIService) LoadTestsStart(ctx context.Context, id int32) *ApiLoadTestsStartRequest { +func (a *LoadTestsAPIService) LoadTestsStart(ctx context.Context, id int64) *ApiLoadTestsStartRequest { return &ApiLoadTestsStartRequest{ ApiService: a, ctx: ctx, @@ -1415,9 +1415,10 @@ type ApiProjectsLoadTestsCreateRequest struct { ctx context.Context ApiService *LoadTestsAPIService xStackId *int32 - id int32 + id int64 name *string script io.ReadCloser + k6Version *int32 } // Numeric ID of the Grafana stack representing the request scope. - If the API is called with a *Personal API token*, the user must be a member of the specified stack. - If the API is called with a *Grafana Stack API token*, the value must be the ID of the corresponding stack. @@ -1438,6 +1439,12 @@ func (r *ApiProjectsLoadTestsCreateRequest) Script(script io.ReadCloser) *ApiPro return r } +// Identifier of the k6 version used to run the test. +func (r *ApiProjectsLoadTestsCreateRequest) K6Version(k6Version int32) *ApiProjectsLoadTestsCreateRequest { + r.k6Version = &k6Version + return r +} + func (r *ApiProjectsLoadTestsCreateRequest) Execute() (*LoadTestApiModel, *http.Response, error) { return r.ApiService.ProjectsLoadTestsCreateExecute(r) } @@ -1455,7 +1462,7 @@ is assumed to be a JavaScript file. @param id ID of the project. @return *ApiProjectsLoadTestsCreateRequest */ -func (a *LoadTestsAPIService) ProjectsLoadTestsCreate(ctx context.Context, id int32) *ApiProjectsLoadTestsCreateRequest { +func (a *LoadTestsAPIService) ProjectsLoadTestsCreate(ctx context.Context, id int64) *ApiProjectsLoadTestsCreateRequest { return &ApiProjectsLoadTestsCreateRequest{ ApiService: a, ctx: ctx, @@ -1539,6 +1546,9 @@ func (a *LoadTestsAPIService) ProjectsLoadTestsCreateExecute(r *ApiProjectsLoadT scriptLocalVarFile.Close() formFiles = append(formFiles, formFile{fileBytes: scriptLocalVarFileBytes, fileName: scriptLocalVarFileName, formFileName: scriptLocalVarFormFileName}) } + if r.k6Version != nil { + parameterAddToHeaderOrQuery(localVarFormParams, "k6_version", r.k6Version, "", "") + } req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) if err != nil { return localVarReturnValue, nil, err @@ -1645,7 +1655,7 @@ type ApiProjectsLoadTestsRetrieveRequest struct { ctx context.Context ApiService *LoadTestsAPIService xStackId *int32 - id int32 + id int64 count *bool orderby *string skip *int32 @@ -1702,7 +1712,7 @@ List load tests in a project. @param id ID of the project. @return *ApiProjectsLoadTestsRetrieveRequest */ -func (a *LoadTestsAPIService) ProjectsLoadTestsRetrieve(ctx context.Context, id int32) *ApiProjectsLoadTestsRetrieveRequest { +func (a *LoadTestsAPIService) ProjectsLoadTestsRetrieve(ctx context.Context, id int64) *ApiProjectsLoadTestsRetrieveRequest { return &ApiProjectsLoadTestsRetrieveRequest{ ApiService: a, ctx: ctx, diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/api_load_zones.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/api_load_zones.go index c6b6000a3..7d1555516 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/api_load_zones.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/api_load_zones.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ @@ -27,7 +27,7 @@ type ApiLoadZonesAllowedProjectsRetrieveRequest struct { ctx context.Context ApiService *LoadZonesAPIService xStackId *int32 - id int32 + id int64 } // Numeric ID of the Grafana stack representing the request scope. - If the API is called with a *Personal API token*, the user must be a member of the specified stack. - If the API is called with a *Grafana Stack API token*, the value must be the ID of the corresponding stack. @@ -49,7 +49,7 @@ List projects allowed to use a given private load zone. @param id ID of the load zone. @return *ApiLoadZonesAllowedProjectsRetrieveRequest */ -func (a *LoadZonesAPIService) LoadZonesAllowedProjectsRetrieve(ctx context.Context, id int32) *ApiLoadZonesAllowedProjectsRetrieveRequest { +func (a *LoadZonesAPIService) LoadZonesAllowedProjectsRetrieve(ctx context.Context, id int64) *ApiLoadZonesAllowedProjectsRetrieveRequest { return &ApiLoadZonesAllowedProjectsRetrieveRequest{ ApiService: a, ctx: ctx, @@ -185,7 +185,7 @@ type ApiLoadZonesAllowedProjectsUpdateRequest struct { ctx context.Context ApiService *LoadZonesAPIService xStackId *int32 - id int32 + id int64 updateAllowedProjectsListApiModel *UpdateAllowedProjectsListApiModel } @@ -213,7 +213,7 @@ Update the list of projects allowed to use a given private load zone. @param id ID of the load zone. @return *ApiLoadZonesAllowedProjectsUpdateRequest */ -func (a *LoadZonesAPIService) LoadZonesAllowedProjectsUpdate(ctx context.Context, id int32) *ApiLoadZonesAllowedProjectsUpdateRequest { +func (a *LoadZonesAPIService) LoadZonesAllowedProjectsUpdate(ctx context.Context, id int64) *ApiLoadZonesAllowedProjectsUpdateRequest { return &ApiLoadZonesAllowedProjectsUpdateRequest{ ApiService: a, ctx: ctx, @@ -529,7 +529,7 @@ type ApiProjectsAllowedLoadZonesRetrieveRequest struct { ctx context.Context ApiService *LoadZonesAPIService xStackId *int32 - id int32 + id int64 } // Numeric ID of the Grafana stack representing the request scope. - If the API is called with a *Personal API token*, the user must be a member of the specified stack. - If the API is called with a *Grafana Stack API token*, the value must be the ID of the corresponding stack. @@ -551,7 +551,7 @@ List private load zones that can be used by a given project. @param id ID of the project. @return *ApiProjectsAllowedLoadZonesRetrieveRequest */ -func (a *LoadZonesAPIService) ProjectsAllowedLoadZonesRetrieve(ctx context.Context, id int32) *ApiProjectsAllowedLoadZonesRetrieveRequest { +func (a *LoadZonesAPIService) ProjectsAllowedLoadZonesRetrieve(ctx context.Context, id int64) *ApiProjectsAllowedLoadZonesRetrieveRequest { return &ApiProjectsAllowedLoadZonesRetrieveRequest{ ApiService: a, ctx: ctx, @@ -687,7 +687,7 @@ type ApiProjectsAllowedLoadZonesUpdateRequest struct { ctx context.Context ApiService *LoadZonesAPIService xStackId *int32 - id int32 + id int64 updateAllowedLoadZonesListApiModel *UpdateAllowedLoadZonesListApiModel } @@ -715,7 +715,7 @@ Update the list of private load zones that can be used by a given project. @param id ID of the project. @return *ApiProjectsAllowedLoadZonesUpdateRequest */ -func (a *LoadZonesAPIService) ProjectsAllowedLoadZonesUpdate(ctx context.Context, id int32) *ApiProjectsAllowedLoadZonesUpdateRequest { +func (a *LoadZonesAPIService) ProjectsAllowedLoadZonesUpdate(ctx context.Context, id int64) *ApiProjectsAllowedLoadZonesUpdateRequest { return &ApiProjectsAllowedLoadZonesUpdateRequest{ ApiService: a, ctx: ctx, diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/api_projects.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/api_projects.go index 72bb3f2f6..fc3fbf1b5 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/api_projects.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/api_projects.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ @@ -409,7 +409,7 @@ type ApiProjectsDestroyRequest struct { ctx context.Context ApiService *ProjectsAPIService xStackId *int32 - id int32 + id int64 } // Numeric ID of the Grafana stack representing the request scope. - If the API is called with a *Personal API token*, the user must be a member of the specified stack. - If the API is called with a *Grafana Stack API token*, the value must be the ID of the corresponding stack. @@ -431,7 +431,7 @@ Delete a project. @param id ID of the project. @return *ApiProjectsDestroyRequest */ -func (a *ProjectsAPIService) ProjectsDestroy(ctx context.Context, id int32) *ApiProjectsDestroyRequest { +func (a *ProjectsAPIService) ProjectsDestroy(ctx context.Context, id int64) *ApiProjectsDestroyRequest { return &ApiProjectsDestroyRequest{ ApiService: a, ctx: ctx, @@ -566,7 +566,7 @@ type ApiProjectsLimitsPartialUpdateRequest struct { ctx context.Context ApiService *ProjectsAPIService xStackId *int32 - id int32 + id int64 patchProjectLimitsRequest *PatchProjectLimitsRequest } @@ -596,7 +596,7 @@ Set a limit to `null` to remove it. @param id ID of the project. @return *ApiProjectsLimitsPartialUpdateRequest */ -func (a *ProjectsAPIService) ProjectsLimitsPartialUpdate(ctx context.Context, id int32) *ApiProjectsLimitsPartialUpdateRequest { +func (a *ProjectsAPIService) ProjectsLimitsPartialUpdate(ctx context.Context, id int64) *ApiProjectsLimitsPartialUpdateRequest { return &ApiProjectsLimitsPartialUpdateRequest{ ApiService: a, ctx: ctx, @@ -733,7 +733,7 @@ type ApiProjectsLimitsRetrieveRequest struct { ctx context.Context ApiService *ProjectsAPIService xStackId *int32 - id int32 + id int64 } // Numeric ID of the Grafana stack representing the request scope. - If the API is called with a *Personal API token*, the user must be a member of the specified stack. - If the API is called with a *Grafana Stack API token*, the value must be the ID of the corresponding stack. @@ -755,7 +755,7 @@ Fetch limits for a project. @param id ID of the project. @return *ApiProjectsLimitsRetrieveRequest */ -func (a *ProjectsAPIService) ProjectsLimitsRetrieve(ctx context.Context, id int32) *ApiProjectsLimitsRetrieveRequest { +func (a *ProjectsAPIService) ProjectsLimitsRetrieve(ctx context.Context, id int64) *ApiProjectsLimitsRetrieveRequest { return &ApiProjectsLimitsRetrieveRequest{ ApiService: a, ctx: ctx, @@ -1108,7 +1108,7 @@ type ApiProjectsPartialUpdateRequest struct { ctx context.Context ApiService *ProjectsAPIService xStackId *int32 - id int32 + id int64 patchProjectApiModel *PatchProjectApiModel } @@ -1136,7 +1136,7 @@ Update a project. @param id ID of the project. @return *ApiProjectsPartialUpdateRequest */ -func (a *ProjectsAPIService) ProjectsPartialUpdate(ctx context.Context, id int32) *ApiProjectsPartialUpdateRequest { +func (a *ProjectsAPIService) ProjectsPartialUpdate(ctx context.Context, id int64) *ApiProjectsPartialUpdateRequest { return &ApiProjectsPartialUpdateRequest{ ApiService: a, ctx: ctx, @@ -1287,7 +1287,7 @@ type ApiProjectsRetrieveRequest struct { ctx context.Context ApiService *ProjectsAPIService xStackId *int32 - id int32 + id int64 } // Numeric ID of the Grafana stack representing the request scope. - If the API is called with a *Personal API token*, the user must be a member of the specified stack. - If the API is called with a *Grafana Stack API token*, the value must be the ID of the corresponding stack. @@ -1309,7 +1309,7 @@ Retrieve a single project. @param id ID of the project. @return *ApiProjectsRetrieveRequest */ -func (a *ProjectsAPIService) ProjectsRetrieve(ctx context.Context, id int32) *ApiProjectsRetrieveRequest { +func (a *ProjectsAPIService) ProjectsRetrieve(ctx context.Context, id int64) *ApiProjectsRetrieveRequest { return &ApiProjectsRetrieveRequest{ ApiService: a, ctx: ctx, diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/api_provisioning.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/api_provisioning.go new file mode 100644 index 000000000..e4d799ef9 --- /dev/null +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/api_provisioning.go @@ -0,0 +1,686 @@ +/* +Grafana Cloud k6 + +HTTP API for interacting with Grafana Cloud k6. + +API version: 1.12.0 +Contact: info@grafana.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package k6 + +import ( + "bytes" + "context" + "io" + "net/http" + "net/url" + "strings" +) + +// ProvisioningAPIService ProvisioningAPI service +type ProvisioningAPIService service + +type ApiStartLocalExecutionTestRequest struct { + ctx context.Context + ApiService *ProvisioningAPIService + id int64 + startLocalExecutionTestRequest *StartLocalExecutionTestRequest + k6IdempotencyKey *string +} + +func (r *ApiStartLocalExecutionTestRequest) StartLocalExecutionTestRequest(startLocalExecutionTestRequest *StartLocalExecutionTestRequest) *ApiStartLocalExecutionTestRequest { + r.startLocalExecutionTestRequest = startLocalExecutionTestRequest + return r +} + +// Idempotency key to prevent duplicate test starts when retrying requests. The key is valid for 10 minutes. +func (r *ApiStartLocalExecutionTestRequest) K6IdempotencyKey(k6IdempotencyKey string) *ApiStartLocalExecutionTestRequest { + r.k6IdempotencyKey = &k6IdempotencyKey + return r +} + +func (r *ApiStartLocalExecutionTestRequest) Execute() (*StartLocalExecutionTestResponse, *http.Response, error) { + return r.ApiService.StartLocalExecutionTestExecute(r) +} + +/* +StartLocalExecutionTest Start a test in local execution mode. + +Start a test in local execution mode. + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param id ID of the load test. + @return *ApiStartLocalExecutionTestRequest +*/ +func (a *ProvisioningAPIService) StartLocalExecutionTest(ctx context.Context, id int64) *ApiStartLocalExecutionTestRequest { + return &ApiStartLocalExecutionTestRequest{ + ApiService: a, + ctx: ctx, + id: id, + } +} + +// Execute executes the request +// +// @return StartLocalExecutionTestResponse +func (a *ProvisioningAPIService) StartLocalExecutionTestExecute(r *ApiStartLocalExecutionTestRequest) (*StartLocalExecutionTestResponse, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *StartLocalExecutionTestResponse + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "ProvisioningAPIService.StartLocalExecutionTest") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/provisioning/v1/load_tests/{id}/start_local_execution" + localVarPath = strings.Replace(localVarPath, "{"+"id"+"}", url.PathEscape(parameterValueToString(r.id, "id")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + if r.startLocalExecutionTestRequest == nil { + return localVarReturnValue, nil, reportError("startLocalExecutionTestRequest is required and must be specified") + } + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.k6IdempotencyKey != nil { + parameterAddToHeaderOrQuery(localVarHeaderParams, "K6-Idempotency-Key", r.k6IdempotencyKey, "simple", "") + } + // body params + localVarPostBody = r.startLocalExecutionTestRequest + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResponseApiModel + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResponseApiModel + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResponseApiModel + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 404 { + var v ErrorResponseApiModel + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResponseApiModel + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiTestRunsAisdkSessionRetrieveRequest struct { + ctx context.Context + ApiService *ProvisioningAPIService + testRunId int64 +} + +func (r *ApiTestRunsAisdkSessionRetrieveRequest) Execute() (*AisdkSessionApiModel, *http.Response, error) { + return r.ApiService.TestRunsAisdkSessionRetrieveExecute(r) +} + +/* +TestRunsAisdkSessionRetrieve Mint an ai-sdk access token for a test run. + +Mint an ai-sdk access token for the authenticated test run's stack. + +The test run id is part of the path so the “testrun_authenticate“ +middleware can validate the request and inject the “X-Stack-Id“, +“X-Cluster-Slug“, and “X-K6-Org-Id“ headers; the id itself is not +used by the mint. + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param testRunId ID of the test run. + @return *ApiTestRunsAisdkSessionRetrieveRequest +*/ +func (a *ProvisioningAPIService) TestRunsAisdkSessionRetrieve(ctx context.Context, testRunId int64) *ApiTestRunsAisdkSessionRetrieveRequest { + return &ApiTestRunsAisdkSessionRetrieveRequest{ + ApiService: a, + ctx: ctx, + testRunId: testRunId, + } +} + +// Execute executes the request +// +// @return AisdkSessionApiModel +func (a *ProvisioningAPIService) TestRunsAisdkSessionRetrieveExecute(r *ApiTestRunsAisdkSessionRetrieveRequest) (*AisdkSessionApiModel, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *AisdkSessionApiModel + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "ProvisioningAPIService.TestRunsAisdkSessionRetrieve") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/provisioning/v1/test_runs/{test_run_id}/aisdk_session" + localVarPath = strings.Replace(localVarPath, "{"+"test_run_id"+"}", url.PathEscape(parameterValueToString(r.testRunId, "testRunId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResponseApiModel + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResponseApiModel + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 404 { + var v ErrorResponseApiModel + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResponseApiModel + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiTestRunsDecryptSecretRetrieveRequest struct { + ctx context.Context + ApiService *ProvisioningAPIService + name *string + testRunId int64 +} + +// The name of the secret to decrypt. +func (r *ApiTestRunsDecryptSecretRetrieveRequest) Name(name string) *ApiTestRunsDecryptSecretRetrieveRequest { + r.name = &name + return r +} + +func (r *ApiTestRunsDecryptSecretRetrieveRequest) Execute() (*DecryptedApiModel, *http.Response, error) { + return r.ApiService.TestRunsDecryptSecretRetrieveExecute(r) +} + +/* +TestRunsDecryptSecretRetrieve Decrypt a secret for a test run. + +Decrypt the indicated test. + +Note that the test run is not used directly in this endpoint. It's included in the path +so the "test run based authentication" can happen, but after that, if we actually get +to the code here, all we need is the organization related information. + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param testRunId ID of the test run. + @return *ApiTestRunsDecryptSecretRetrieveRequest +*/ +func (a *ProvisioningAPIService) TestRunsDecryptSecretRetrieve(ctx context.Context, testRunId int64) *ApiTestRunsDecryptSecretRetrieveRequest { + return &ApiTestRunsDecryptSecretRetrieveRequest{ + ApiService: a, + ctx: ctx, + testRunId: testRunId, + } +} + +// Execute executes the request +// +// @return DecryptedApiModel +func (a *ProvisioningAPIService) TestRunsDecryptSecretRetrieveExecute(r *ApiTestRunsDecryptSecretRetrieveRequest) (*DecryptedApiModel, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *DecryptedApiModel + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "ProvisioningAPIService.TestRunsDecryptSecretRetrieve") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/provisioning/v1/test_runs/{test_run_id}/decrypt_secret" + localVarPath = strings.Replace(localVarPath, "{"+"test_run_id"+"}", url.PathEscape(parameterValueToString(r.testRunId, "testRunId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + if r.name == nil { + return localVarReturnValue, nil, reportError("name is required and must be specified") + } + + parameterAddToHeaderOrQuery(localVarQueryParams, "name", r.name, "form", "") + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResponseApiModel + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResponseApiModel + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResponseApiModel + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 404 { + var v ErrorResponseApiModel + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResponseApiModel + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiTestRunsNotifyRequest struct { + ctx context.Context + ApiService *ProvisioningAPIService + id int64 + scriptExecutionCompletedNotificationApiModel *ScriptExecutionCompletedNotificationApiModel +} + +func (r *ApiTestRunsNotifyRequest) ScriptExecutionCompletedNotificationApiModel(scriptExecutionCompletedNotificationApiModel *ScriptExecutionCompletedNotificationApiModel) *ApiTestRunsNotifyRequest { + r.scriptExecutionCompletedNotificationApiModel = scriptExecutionCompletedNotificationApiModel + return r +} + +func (r *ApiTestRunsNotifyRequest) Execute() (*http.Response, error) { + return r.ApiService.TestRunsNotifyExecute(r) +} + +/* +TestRunsNotify Report a test run lifecycle event. + +Report a test run lifecycle event. + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param id ID of the test run. + @return *ApiTestRunsNotifyRequest +*/ +func (a *ProvisioningAPIService) TestRunsNotify(ctx context.Context, id int64) *ApiTestRunsNotifyRequest { + return &ApiTestRunsNotifyRequest{ + ApiService: a, + ctx: ctx, + id: id, + } +} + +// Execute executes the request +func (a *ProvisioningAPIService) TestRunsNotifyExecute(r *ApiTestRunsNotifyRequest) (*http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "ProvisioningAPIService.TestRunsNotify") + if err != nil { + return nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/provisioning/v1/test_runs/{id}/notify" + localVarPath = strings.Replace(localVarPath, "{"+"id"+"}", url.PathEscape(parameterValueToString(r.id, "id")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + if r.scriptExecutionCompletedNotificationApiModel == nil { + return nil, reportError("scriptExecutionCompletedNotificationApiModel is required and must be specified") + } + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + // body params + localVarPostBody = r.scriptExecutionCompletedNotificationApiModel + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v ErrorResponseApiModel + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResponseApiModel + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResponseApiModel + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 404 { + var v ErrorResponseApiModel + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResponseApiModel + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarHTTPResponse, newErr + } + + return localVarHTTPResponse, nil +} diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/api_schedules.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/api_schedules.go index 17efaea3e..ad065a2df 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/api_schedules.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/api_schedules.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ @@ -27,7 +27,7 @@ type ApiLoadTestsScheduleCreateRequest struct { ctx context.Context ApiService *SchedulesAPIService xStackId *int32 - id int32 + id int64 createScheduleRequest *CreateScheduleRequest } @@ -60,7 +60,7 @@ if the target day doesn't exist in a given month (for example, March 31 -> April @param id ID of the load test. @return *ApiLoadTestsScheduleCreateRequest */ -func (a *SchedulesAPIService) LoadTestsScheduleCreate(ctx context.Context, id int32) *ApiLoadTestsScheduleCreateRequest { +func (a *SchedulesAPIService) LoadTestsScheduleCreate(ctx context.Context, id int64) *ApiLoadTestsScheduleCreateRequest { return &ApiLoadTestsScheduleCreateRequest{ ApiService: a, ctx: ctx, @@ -212,7 +212,7 @@ type ApiLoadTestsScheduleRetrieveRequest struct { ctx context.Context ApiService *SchedulesAPIService xStackId *int32 - id int32 + id int64 } // Numeric ID of the Grafana stack representing the request scope. - If the API is called with a *Personal API token*, the user must be a member of the specified stack. - If the API is called with a *Grafana Stack API token*, the value must be the ID of the corresponding stack. @@ -234,7 +234,7 @@ Get the load test schedule. @param id ID of the load test. @return *ApiLoadTestsScheduleRetrieveRequest */ -func (a *SchedulesAPIService) LoadTestsScheduleRetrieve(ctx context.Context, id int32) *ApiLoadTestsScheduleRetrieveRequest { +func (a *SchedulesAPIService) LoadTestsScheduleRetrieve(ctx context.Context, id int64) *ApiLoadTestsScheduleRetrieveRequest { return &ApiLoadTestsScheduleRetrieveRequest{ ApiService: a, ctx: ctx, @@ -370,7 +370,7 @@ type ApiScheduleActivateRequest struct { ctx context.Context ApiService *SchedulesAPIService xStackId *int32 - id int32 + id int64 } // Numeric ID of the Grafana stack representing the request scope. - If the API is called with a *Personal API token*, the user must be a member of the specified stack. - If the API is called with a *Grafana Stack API token*, the value must be the ID of the corresponding stack. @@ -395,7 +395,7 @@ recurrence. @param id ID of the schedule. @return *ApiScheduleActivateRequest */ -func (a *SchedulesAPIService) ScheduleActivate(ctx context.Context, id int32) *ApiScheduleActivateRequest { +func (a *SchedulesAPIService) ScheduleActivate(ctx context.Context, id int64) *ApiScheduleActivateRequest { return &ApiScheduleActivateRequest{ ApiService: a, ctx: ctx, @@ -530,7 +530,7 @@ type ApiScheduleDeactivateRequest struct { ctx context.Context ApiService *SchedulesAPIService xStackId *int32 - id int32 + id int64 } // Numeric ID of the Grafana stack representing the request scope. - If the API is called with a *Personal API token*, the user must be a member of the specified stack. - If the API is called with a *Grafana Stack API token*, the value must be the ID of the corresponding stack. @@ -557,7 +557,7 @@ The operation has no effect if the schedule is expired. @param id ID of the schedule. @return *ApiScheduleDeactivateRequest */ -func (a *SchedulesAPIService) ScheduleDeactivate(ctx context.Context, id int32) *ApiScheduleDeactivateRequest { +func (a *SchedulesAPIService) ScheduleDeactivate(ctx context.Context, id int64) *ApiScheduleDeactivateRequest { return &ApiScheduleDeactivateRequest{ ApiService: a, ctx: ctx, @@ -681,7 +681,7 @@ type ApiSchedulesDestroyRequest struct { ctx context.Context ApiService *SchedulesAPIService xStackId *int32 - id int32 + id int64 } // Numeric ID of the Grafana stack representing the request scope. - If the API is called with a *Personal API token*, the user must be a member of the specified stack. - If the API is called with a *Grafana Stack API token*, the value must be the ID of the corresponding stack. @@ -703,7 +703,7 @@ Delete a schedule. @param id ID of the schedule. @return *ApiSchedulesDestroyRequest */ -func (a *SchedulesAPIService) SchedulesDestroy(ctx context.Context, id int32) *ApiSchedulesDestroyRequest { +func (a *SchedulesAPIService) SchedulesDestroy(ctx context.Context, id int64) *ApiSchedulesDestroyRequest { return &ApiSchedulesDestroyRequest{ ApiService: a, ctx: ctx, @@ -1014,7 +1014,7 @@ type ApiSchedulesRetrieveRequest struct { ctx context.Context ApiService *SchedulesAPIService xStackId *int32 - id int32 + id int64 } // Numeric ID of the Grafana stack representing the request scope. - If the API is called with a *Personal API token*, the user must be a member of the specified stack. - If the API is called with a *Grafana Stack API token*, the value must be the ID of the corresponding stack. @@ -1036,7 +1036,7 @@ Get a schedule by ID. @param id ID of the schedule. @return *ApiSchedulesRetrieveRequest */ -func (a *SchedulesAPIService) SchedulesRetrieve(ctx context.Context, id int32) *ApiSchedulesRetrieveRequest { +func (a *SchedulesAPIService) SchedulesRetrieve(ctx context.Context, id int64) *ApiSchedulesRetrieveRequest { return &ApiSchedulesRetrieveRequest{ ApiService: a, ctx: ctx, diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/api_test_runs.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/api_test_runs.go index 0bebbe968..9cb30fe79 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/api_test_runs.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/api_test_runs.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ @@ -28,13 +28,14 @@ type ApiLoadTestsTestRunsRetrieveRequest struct { ctx context.Context ApiService *TestRunsAPIService xStackId *int32 - id int32 + id int64 count *bool orderby *string skip *int32 top *int32 createdAfter *time.Time createdBefore *time.Time + isStarred *bool } // Numeric ID of the Grafana stack representing the request scope. - If the API is called with a *Personal API token*, the user must be a member of the specified stack. - If the API is called with a *Grafana Stack API token*, the value must be the ID of the corresponding stack. @@ -79,6 +80,12 @@ func (r *ApiLoadTestsTestRunsRetrieveRequest) CreatedBefore(createdBefore time.T return r } +// Filter by starred state. `true` or `1` returns only starred runs; `false` or `0` returns only unstarred runs. Omit the parameter to return all runs for this load test. +func (r *ApiLoadTestsTestRunsRetrieveRequest) IsStarred(isStarred bool) *ApiLoadTestsTestRunsRetrieveRequest { + r.isStarred = &isStarred + return r +} + func (r *ApiLoadTestsTestRunsRetrieveRequest) Execute() (*TestRunListResponse, *http.Response, error) { return r.ApiService.LoadTestsTestRunsRetrieveExecute(r) } @@ -92,7 +99,7 @@ List all runs of a load test. @param id ID of the load test. @return *ApiLoadTestsTestRunsRetrieveRequest */ -func (a *TestRunsAPIService) LoadTestsTestRunsRetrieve(ctx context.Context, id int32) *ApiLoadTestsTestRunsRetrieveRequest { +func (a *TestRunsAPIService) LoadTestsTestRunsRetrieve(ctx context.Context, id int64) *ApiLoadTestsTestRunsRetrieveRequest { return &ApiLoadTestsTestRunsRetrieveRequest{ ApiService: a, ctx: ctx, @@ -147,6 +154,9 @@ func (a *TestRunsAPIService) LoadTestsTestRunsRetrieveExecute(r *ApiLoadTestsTes if r.createdBefore != nil { parameterAddToHeaderOrQuery(localVarQueryParams, "created_before", r.createdBefore, "form", "") } + if r.isStarred != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "is_starred", r.isStarred, "form", "") + } // to determine the Content-Type header localVarHTTPContentTypes := []string{} @@ -260,7 +270,7 @@ type ApiTestRunsAbortRequest struct { ctx context.Context ApiService *TestRunsAPIService xStackId *int32 - id int32 + id int64 } // Numeric ID of the Grafana stack representing the request scope. - If the API is called with a *Personal API token*, the user must be a member of the specified stack. - If the API is called with a *Grafana Stack API token*, the value must be the ID of the corresponding stack. @@ -282,7 +292,7 @@ Abort a running test. @param id ID of the load test run. @return *ApiTestRunsAbortRequest */ -func (a *TestRunsAPIService) TestRunsAbort(ctx context.Context, id int32) *ApiTestRunsAbortRequest { +func (a *TestRunsAPIService) TestRunsAbort(ctx context.Context, id int64) *ApiTestRunsAbortRequest { return &ApiTestRunsAbortRequest{ ApiService: a, ctx: ctx, @@ -417,7 +427,7 @@ type ApiTestRunsDestroyRequest struct { ctx context.Context ApiService *TestRunsAPIService xStackId *int32 - id int32 + id int64 } // Numeric ID of the Grafana stack representing the request scope. - If the API is called with a *Personal API token*, the user must be a member of the specified stack. - If the API is called with a *Grafana Stack API token*, the value must be the ID of the corresponding stack. @@ -439,7 +449,7 @@ Delete a test run. @param id ID of the load test run. @return *ApiTestRunsDestroyRequest */ -func (a *TestRunsAPIService) TestRunsDestroy(ctx context.Context, id int32) *ApiTestRunsDestroyRequest { +func (a *TestRunsAPIService) TestRunsDestroy(ctx context.Context, id int64) *ApiTestRunsDestroyRequest { return &ApiTestRunsDestroyRequest{ ApiService: a, ctx: ctx, @@ -574,7 +584,7 @@ type ApiTestRunsDistributionRetrieveRequest struct { ctx context.Context ApiService *TestRunsAPIService xStackId *int32 - id int32 + id int64 } // Numeric ID of the Grafana stack representing the request scope. - If the API is called with a *Personal API token*, the user must be a member of the specified stack. - If the API is called with a *Grafana Stack API token*, the value must be the ID of the corresponding stack. @@ -596,7 +606,7 @@ Get test run distribution data. @param id ID of the load test run. @return *ApiTestRunsDistributionRetrieveRequest */ -func (a *TestRunsAPIService) TestRunsDistributionRetrieve(ctx context.Context, id int32) *ApiTestRunsDistributionRetrieveRequest { +func (a *TestRunsAPIService) TestRunsDistributionRetrieve(ctx context.Context, id int64) *ApiTestRunsDistributionRetrieveRequest { return &ApiTestRunsDistributionRetrieveRequest{ ApiService: a, ctx: ctx, @@ -939,7 +949,7 @@ type ApiTestRunsPartialUpdateRequest struct { ctx context.Context ApiService *TestRunsAPIService xStackId *int32 - id int32 + id int64 patchTestRunApiModel *PatchTestRunApiModel } @@ -967,7 +977,7 @@ Update a test run. @param id ID of the load test run. @return *ApiTestRunsPartialUpdateRequest */ -func (a *TestRunsAPIService) TestRunsPartialUpdate(ctx context.Context, id int32) *ApiTestRunsPartialUpdateRequest { +func (a *TestRunsAPIService) TestRunsPartialUpdate(ctx context.Context, id int64) *ApiTestRunsPartialUpdateRequest { return &ApiTestRunsPartialUpdateRequest{ ApiService: a, ctx: ctx, @@ -1107,7 +1117,7 @@ type ApiTestRunsRetrieveRequest struct { ctx context.Context ApiService *TestRunsAPIService xStackId *int32 - id int32 + id int64 } // Numeric ID of the Grafana stack representing the request scope. - If the API is called with a *Personal API token*, the user must be a member of the specified stack. - If the API is called with a *Grafana Stack API token*, the value must be the ID of the corresponding stack. @@ -1129,7 +1139,7 @@ Fetch a single test run. @param id ID of the load test run. @return *ApiTestRunsRetrieveRequest */ -func (a *TestRunsAPIService) TestRunsRetrieve(ctx context.Context, id int32) *ApiTestRunsRetrieveRequest { +func (a *TestRunsAPIService) TestRunsRetrieve(ctx context.Context, id int64) *ApiTestRunsRetrieveRequest { return &ApiTestRunsRetrieveRequest{ ApiService: a, ctx: ctx, @@ -1265,7 +1275,7 @@ type ApiTestRunsSaveRequest struct { ctx context.Context ApiService *TestRunsAPIService xStackId *int32 - id int32 + id int64 } // Numeric ID of the Grafana stack representing the request scope. - If the API is called with a *Personal API token*, the user must be a member of the specified stack. - If the API is called with a *Grafana Stack API token*, the value must be the ID of the corresponding stack. @@ -1281,13 +1291,15 @@ func (r *ApiTestRunsSaveRequest) Execute() (*http.Response, error) { /* TestRunsSave Save test run results. -Persist test run results to keep them past the data-retention period. +Deprecated: use [`POST /test_runs/{id}/star`](#tag/test_runs/operation/test_runs_star) instead. This operation is scheduled for removal on 2026-09-01. @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). @param id ID of the load test run. @return *ApiTestRunsSaveRequest + +Deprecated */ -func (a *TestRunsAPIService) TestRunsSave(ctx context.Context, id int32) *ApiTestRunsSaveRequest { +func (a *TestRunsAPIService) TestRunsSave(ctx context.Context, id int64) *ApiTestRunsSaveRequest { return &ApiTestRunsSaveRequest{ ApiService: a, ctx: ctx, @@ -1296,6 +1308,7 @@ func (a *TestRunsAPIService) TestRunsSave(ctx context.Context, id int32) *ApiTes } // Execute executes the request +// Deprecated func (a *TestRunsAPIService) TestRunsSaveExecute(r *ApiTestRunsSaveRequest) (*http.Response, error) { var ( localVarHTTPMethod = http.MethodPost @@ -1422,7 +1435,7 @@ type ApiTestRunsScriptRetrieveRequest struct { ctx context.Context ApiService *TestRunsAPIService xStackId *int32 - id int32 + id int64 } // Numeric ID of the Grafana stack representing the request scope. - If the API is called with a *Personal API token*, the user must be a member of the specified stack. - If the API is called with a *Grafana Stack API token*, the value must be the ID of the corresponding stack. @@ -1444,7 +1457,7 @@ Download the test run script. @param id ID of the load test run. @return *ApiTestRunsScriptRetrieveRequest */ -func (a *TestRunsAPIService) TestRunsScriptRetrieve(ctx context.Context, id int32) *ApiTestRunsScriptRetrieveRequest { +func (a *TestRunsAPIService) TestRunsScriptRetrieve(ctx context.Context, id int64) *ApiTestRunsScriptRetrieveRequest { return &ApiTestRunsScriptRetrieveRequest{ ApiService: a, ctx: ctx, @@ -1576,11 +1589,157 @@ func (a *TestRunsAPIService) TestRunsScriptRetrieveExecute(r *ApiTestRunsScriptR return localVarReturnValue, localVarHTTPResponse, nil } +type ApiTestRunsStarRequest struct { + ctx context.Context + ApiService *TestRunsAPIService + xStackId *int32 + id int64 +} + +// Numeric ID of the Grafana stack representing the request scope. - If the API is called with a *Personal API token*, the user must be a member of the specified stack. - If the API is called with a *Grafana Stack API token*, the value must be the ID of the corresponding stack. +func (r *ApiTestRunsStarRequest) XStackId(xStackId int32) *ApiTestRunsStarRequest { + r.xStackId = &xStackId + return r +} + +func (r *ApiTestRunsStarRequest) Execute() (*http.Response, error) { + return r.ApiService.TestRunsStarExecute(r) +} + +/* +TestRunsStar Star a test run. + +Marks a test run for quick access in comparison workflows. Starring a test run does not extend metrics retention. + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param id ID of the load test run. + @return *ApiTestRunsStarRequest +*/ +func (a *TestRunsAPIService) TestRunsStar(ctx context.Context, id int64) *ApiTestRunsStarRequest { + return &ApiTestRunsStarRequest{ + ApiService: a, + ctx: ctx, + id: id, + } +} + +// Execute executes the request +func (a *TestRunsAPIService) TestRunsStarExecute(r *ApiTestRunsStarRequest) (*http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "TestRunsAPIService.TestRunsStar") + if err != nil { + return nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/cloud/v6/test_runs/{id}/star" + localVarPath = strings.Replace(localVarPath, "{"+"id"+"}", url.PathEscape(parameterValueToString(r.id, "id")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + if r.xStackId == nil { + return nil, reportError("xStackId is required and must be specified") + } + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + parameterAddToHeaderOrQuery(localVarHeaderParams, "X-Stack-Id", r.xStackId, "simple", "") + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResponseApiModel + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResponseApiModel + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 404 { + var v ErrorResponseApiModel + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResponseApiModel + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarHTTPResponse, newErr + } + + return localVarHTTPResponse, nil +} + type ApiTestRunsUnsaveRequest struct { ctx context.Context ApiService *TestRunsAPIService xStackId *int32 - id int32 + id int64 } // Numeric ID of the Grafana stack representing the request scope. - If the API is called with a *Personal API token*, the user must be a member of the specified stack. - If the API is called with a *Grafana Stack API token*, the value must be the ID of the corresponding stack. @@ -1596,15 +1755,15 @@ func (r *ApiTestRunsUnsaveRequest) Execute() (*http.Response, error) { /* TestRunsUnsave Unsave test run results. -Disable persistence of the test run results past the data-retention period. - -The data will be automatically deleted at the end of the retention period. +Deprecated: use [`POST /test_runs/{id}/unstar`](#tag/test_runs/operation/test_runs_unstar) instead. This operation is scheduled for removal on 2026-09-01. @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). @param id ID of the load test run. @return *ApiTestRunsUnsaveRequest + +Deprecated */ -func (a *TestRunsAPIService) TestRunsUnsave(ctx context.Context, id int32) *ApiTestRunsUnsaveRequest { +func (a *TestRunsAPIService) TestRunsUnsave(ctx context.Context, id int64) *ApiTestRunsUnsaveRequest { return &ApiTestRunsUnsaveRequest{ ApiService: a, ctx: ctx, @@ -1613,6 +1772,7 @@ func (a *TestRunsAPIService) TestRunsUnsave(ctx context.Context, id int32) *ApiT } // Execute executes the request +// Deprecated func (a *TestRunsAPIService) TestRunsUnsaveExecute(r *ApiTestRunsUnsaveRequest) (*http.Response, error) { var ( localVarHTTPMethod = http.MethodPost @@ -1723,3 +1883,149 @@ func (a *TestRunsAPIService) TestRunsUnsaveExecute(r *ApiTestRunsUnsaveRequest) return localVarHTTPResponse, nil } + +type ApiTestRunsUnstarRequest struct { + ctx context.Context + ApiService *TestRunsAPIService + xStackId *int32 + id int64 +} + +// Numeric ID of the Grafana stack representing the request scope. - If the API is called with a *Personal API token*, the user must be a member of the specified stack. - If the API is called with a *Grafana Stack API token*, the value must be the ID of the corresponding stack. +func (r *ApiTestRunsUnstarRequest) XStackId(xStackId int32) *ApiTestRunsUnstarRequest { + r.xStackId = &xStackId + return r +} + +func (r *ApiTestRunsUnstarRequest) Execute() (*http.Response, error) { + return r.ApiService.TestRunsUnstarExecute(r) +} + +/* +TestRunsUnstar Unstar a test run. + +Removes a test run from the starred comparison workflow. + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param id ID of the load test run. + @return *ApiTestRunsUnstarRequest +*/ +func (a *TestRunsAPIService) TestRunsUnstar(ctx context.Context, id int64) *ApiTestRunsUnstarRequest { + return &ApiTestRunsUnstarRequest{ + ApiService: a, + ctx: ctx, + id: id, + } +} + +// Execute executes the request +func (a *TestRunsAPIService) TestRunsUnstarExecute(r *ApiTestRunsUnstarRequest) (*http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "TestRunsAPIService.TestRunsUnstar") + if err != nil { + return nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/cloud/v6/test_runs/{id}/unstar" + localVarPath = strings.Replace(localVarPath, "{"+"id"+"}", url.PathEscape(parameterValueToString(r.id, "id")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + if r.xStackId == nil { + return nil, reportError("xStackId is required and must be specified") + } + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + parameterAddToHeaderOrQuery(localVarHeaderParams, "X-Stack-Id", r.xStackId, "simple", "") + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 401 { + var v ErrorResponseApiModel + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v ErrorResponseApiModel + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 404 { + var v ErrorResponseApiModel + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + return localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v ErrorResponseApiModel + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.model = v + } + return localVarHTTPResponse, newErr + } + + return localVarHTTPResponse, nil +} diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/client.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/client.go index 089ee83f8..1016eb599 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/client.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/client.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ @@ -41,7 +41,7 @@ var ( queryDescape = strings.NewReplacer("%5B", "[", "%5D", "]") ) -// APIClient manages communication with the Grafana Cloud k6 API v1.9.1 +// APIClient manages communication with the Grafana Cloud k6 API v1.12.0 // In most cases there should be only one, shared, APIClient. type APIClient struct { cfg *Configuration @@ -59,6 +59,8 @@ type APIClient struct { ProjectsAPI *ProjectsAPIService + ProvisioningAPI *ProvisioningAPIService + SchedulesAPI *SchedulesAPIService TestRunsAPI *TestRunsAPIService @@ -85,6 +87,7 @@ func NewAPIClient(cfg *Configuration) *APIClient { c.LoadTestsAPI = (*LoadTestsAPIService)(&c.common) c.LoadZonesAPI = (*LoadZonesAPIService)(&c.common) c.ProjectsAPI = (*ProjectsAPIService)(&c.common) + c.ProvisioningAPI = (*ProvisioningAPIService)(&c.common) c.SchedulesAPI = (*SchedulesAPIService)(&c.common) c.TestRunsAPI = (*TestRunsAPIService)(&c.common) diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/configuration.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/configuration.go index a31a0b88e..a44e5f5ac 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/configuration.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/configuration.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_aisdk_session_api_model.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_aisdk_session_api_model.go new file mode 100644 index 000000000..7a556978b --- /dev/null +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_aisdk_session_api_model.go @@ -0,0 +1,259 @@ +/* +Grafana Cloud k6 + +HTTP API for interacting with Grafana Cloud k6. + +API version: 1.12.0 +Contact: info@grafana.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package k6 + +import ( + "encoding/json" + "fmt" + "time" +) + +// checks if the AisdkSessionApiModel type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &AisdkSessionApiModel{} + +// AisdkSessionApiModel Model for the response of the ai-sdk session endpoint. +type AisdkSessionApiModel struct { + // Short-lived access token (TTL matches the agentic test cap). + AccessToken string `json:"access_token"` + // ISO 8601 timestamp when the access token expires (UTC). + ExpiresAt time.Time `json:"expires_at"` + // Region-matched URL of the hosted ai-sdk endpoint. + BaseUrl string `json:"base_url"` + // Stack-scoped namespace claim on the access token (e.g. 'stacks-12345'). + Namespace string `json:"namespace"` + AdditionalProperties map[string]interface{} +} + +type _AisdkSessionApiModel AisdkSessionApiModel + +// NewAisdkSessionApiModel instantiates a new AisdkSessionApiModel object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewAisdkSessionApiModel(accessToken string, expiresAt time.Time, baseUrl string, namespace string) *AisdkSessionApiModel { + this := AisdkSessionApiModel{} + this.AccessToken = accessToken + this.ExpiresAt = expiresAt + this.BaseUrl = baseUrl + this.Namespace = namespace + return &this +} + +// NewAisdkSessionApiModelWithDefaults instantiates a new AisdkSessionApiModel object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewAisdkSessionApiModelWithDefaults() *AisdkSessionApiModel { + this := AisdkSessionApiModel{} + return &this +} + +// GetAccessToken returns the AccessToken field value +func (o *AisdkSessionApiModel) GetAccessToken() string { + if o == nil { + var ret string + return ret + } + + return o.AccessToken +} + +// GetAccessTokenOk returns a tuple with the AccessToken field value +// and a boolean to check if the value has been set. +func (o *AisdkSessionApiModel) GetAccessTokenOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.AccessToken, true +} + +// SetAccessToken sets field value +func (o *AisdkSessionApiModel) SetAccessToken(v string) { + o.AccessToken = v +} + +// GetExpiresAt returns the ExpiresAt field value +func (o *AisdkSessionApiModel) GetExpiresAt() time.Time { + if o == nil { + var ret time.Time + return ret + } + + return o.ExpiresAt +} + +// GetExpiresAtOk returns a tuple with the ExpiresAt field value +// and a boolean to check if the value has been set. +func (o *AisdkSessionApiModel) GetExpiresAtOk() (*time.Time, bool) { + if o == nil { + return nil, false + } + return &o.ExpiresAt, true +} + +// SetExpiresAt sets field value +func (o *AisdkSessionApiModel) SetExpiresAt(v time.Time) { + o.ExpiresAt = v +} + +// GetBaseUrl returns the BaseUrl field value +func (o *AisdkSessionApiModel) GetBaseUrl() string { + if o == nil { + var ret string + return ret + } + + return o.BaseUrl +} + +// GetBaseUrlOk returns a tuple with the BaseUrl field value +// and a boolean to check if the value has been set. +func (o *AisdkSessionApiModel) GetBaseUrlOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.BaseUrl, true +} + +// SetBaseUrl sets field value +func (o *AisdkSessionApiModel) SetBaseUrl(v string) { + o.BaseUrl = v +} + +// GetNamespace returns the Namespace field value +func (o *AisdkSessionApiModel) GetNamespace() string { + if o == nil { + var ret string + return ret + } + + return o.Namespace +} + +// GetNamespaceOk returns a tuple with the Namespace field value +// and a boolean to check if the value has been set. +func (o *AisdkSessionApiModel) GetNamespaceOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Namespace, true +} + +// SetNamespace sets field value +func (o *AisdkSessionApiModel) SetNamespace(v string) { + o.Namespace = v +} + +func (o AisdkSessionApiModel) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o AisdkSessionApiModel) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["access_token"] = o.AccessToken + toSerialize["expires_at"] = o.ExpiresAt + toSerialize["base_url"] = o.BaseUrl + toSerialize["namespace"] = o.Namespace + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *AisdkSessionApiModel) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "access_token", + "expires_at", + "base_url", + "namespace", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err + } + + for _, requiredProperty := range requiredProperties { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varAisdkSessionApiModel := _AisdkSessionApiModel{} + + err = json.Unmarshal(data, &varAisdkSessionApiModel) + + if err != nil { + return err + } + + *o = AisdkSessionApiModel(varAisdkSessionApiModel) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(data, &additionalProperties); err == nil { + delete(additionalProperties, "access_token") + delete(additionalProperties, "expires_at") + delete(additionalProperties, "base_url") + delete(additionalProperties, "namespace") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableAisdkSessionApiModel struct { + value *AisdkSessionApiModel + isSet bool +} + +func (v NullableAisdkSessionApiModel) Get() *AisdkSessionApiModel { + return v.value +} + +func (v *NullableAisdkSessionApiModel) Set(val *AisdkSessionApiModel) { + v.value = val + v.isSet = true +} + +func (v NullableAisdkSessionApiModel) IsSet() bool { + return v.isSet +} + +func (v *NullableAisdkSessionApiModel) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableAisdkSessionApiModel(val *AisdkSessionApiModel) *NullableAisdkSessionApiModel { + return &NullableAisdkSessionApiModel{value: val, isSet: true} +} + +func (v NullableAisdkSessionApiModel) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableAisdkSessionApiModel) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_allowed_load_zone_api_model.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_allowed_load_zone_api_model.go index 69d59195d..67b885e45 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_allowed_load_zone_api_model.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_allowed_load_zone_api_model.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ @@ -22,11 +22,17 @@ var _ MappedNullable = &AllowedLoadZoneApiModel{} // AllowedLoadZoneApiModel struct for AllowedLoadZoneApiModel type AllowedLoadZoneApiModel struct { // ID of the load zone. - Id int32 `json:"id"` + Id int64 `json:"id"` // Name of the load zone. Name string `json:"name"` // ID used to identify the load zone in the k6 scripts. - K6LoadZoneId string `json:"k6_load_zone_id"` + K6LoadZoneId string `json:"k6_load_zone_id"` + // Whether the load zone can be used to start tests. + Available bool `json:"available"` + // Custom load runner image. Only set for private load zones. + CustomLoadRunnerImage NullableString `json:"custom_load_runner_image"` + // Whether the load zone is public or private. + Public bool `json:"public"` AdditionalProperties map[string]interface{} } @@ -36,11 +42,14 @@ type _AllowedLoadZoneApiModel AllowedLoadZoneApiModel // This constructor will assign default values to properties that have it defined, // and makes sure properties required by API are set, but the set of arguments // will change when the set of required properties is changed -func NewAllowedLoadZoneApiModel(id int32, name string, k6LoadZoneId string) *AllowedLoadZoneApiModel { +func NewAllowedLoadZoneApiModel(id int64, name string, k6LoadZoneId string, available bool, customLoadRunnerImage NullableString, public bool) *AllowedLoadZoneApiModel { this := AllowedLoadZoneApiModel{} this.Id = id this.Name = name this.K6LoadZoneId = k6LoadZoneId + this.Available = available + this.CustomLoadRunnerImage = customLoadRunnerImage + this.Public = public return &this } @@ -53,9 +62,9 @@ func NewAllowedLoadZoneApiModelWithDefaults() *AllowedLoadZoneApiModel { } // GetId returns the Id field value -func (o *AllowedLoadZoneApiModel) GetId() int32 { +func (o *AllowedLoadZoneApiModel) GetId() int64 { if o == nil { - var ret int32 + var ret int64 return ret } @@ -64,7 +73,7 @@ func (o *AllowedLoadZoneApiModel) GetId() int32 { // GetIdOk returns a tuple with the Id field value // and a boolean to check if the value has been set. -func (o *AllowedLoadZoneApiModel) GetIdOk() (*int32, bool) { +func (o *AllowedLoadZoneApiModel) GetIdOk() (*int64, bool) { if o == nil { return nil, false } @@ -72,7 +81,7 @@ func (o *AllowedLoadZoneApiModel) GetIdOk() (*int32, bool) { } // SetId sets field value -func (o *AllowedLoadZoneApiModel) SetId(v int32) { +func (o *AllowedLoadZoneApiModel) SetId(v int64) { o.Id = v } @@ -124,6 +133,80 @@ func (o *AllowedLoadZoneApiModel) SetK6LoadZoneId(v string) { o.K6LoadZoneId = v } +// GetAvailable returns the Available field value +func (o *AllowedLoadZoneApiModel) GetAvailable() bool { + if o == nil { + var ret bool + return ret + } + + return o.Available +} + +// GetAvailableOk returns a tuple with the Available field value +// and a boolean to check if the value has been set. +func (o *AllowedLoadZoneApiModel) GetAvailableOk() (*bool, bool) { + if o == nil { + return nil, false + } + return &o.Available, true +} + +// SetAvailable sets field value +func (o *AllowedLoadZoneApiModel) SetAvailable(v bool) { + o.Available = v +} + +// GetCustomLoadRunnerImage returns the CustomLoadRunnerImage field value +// If the value is explicit nil, the zero value for string will be returned +func (o *AllowedLoadZoneApiModel) GetCustomLoadRunnerImage() string { + if o == nil || o.CustomLoadRunnerImage.Get() == nil { + var ret string + return ret + } + + return *o.CustomLoadRunnerImage.Get() +} + +// GetCustomLoadRunnerImageOk returns a tuple with the CustomLoadRunnerImage field value +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *AllowedLoadZoneApiModel) GetCustomLoadRunnerImageOk() (*string, bool) { + if o == nil { + return nil, false + } + return o.CustomLoadRunnerImage.Get(), o.CustomLoadRunnerImage.IsSet() +} + +// SetCustomLoadRunnerImage sets field value +func (o *AllowedLoadZoneApiModel) SetCustomLoadRunnerImage(v string) { + o.CustomLoadRunnerImage.Set(&v) +} + +// GetPublic returns the Public field value +func (o *AllowedLoadZoneApiModel) GetPublic() bool { + if o == nil { + var ret bool + return ret + } + + return o.Public +} + +// GetPublicOk returns a tuple with the Public field value +// and a boolean to check if the value has been set. +func (o *AllowedLoadZoneApiModel) GetPublicOk() (*bool, bool) { + if o == nil { + return nil, false + } + return &o.Public, true +} + +// SetPublic sets field value +func (o *AllowedLoadZoneApiModel) SetPublic(v bool) { + o.Public = v +} + func (o AllowedLoadZoneApiModel) MarshalJSON() ([]byte, error) { toSerialize, err := o.ToMap() if err != nil { @@ -137,6 +220,9 @@ func (o AllowedLoadZoneApiModel) ToMap() (map[string]interface{}, error) { toSerialize["id"] = o.Id toSerialize["name"] = o.Name toSerialize["k6_load_zone_id"] = o.K6LoadZoneId + toSerialize["available"] = o.Available + toSerialize["custom_load_runner_image"] = o.CustomLoadRunnerImage.Get() + toSerialize["public"] = o.Public for key, value := range o.AdditionalProperties { toSerialize[key] = value @@ -153,6 +239,9 @@ func (o *AllowedLoadZoneApiModel) UnmarshalJSON(data []byte) (err error) { "id", "name", "k6_load_zone_id", + "available", + "custom_load_runner_image", + "public", } allProperties := make(map[string]interface{}) @@ -185,6 +274,9 @@ func (o *AllowedLoadZoneApiModel) UnmarshalJSON(data []byte) (err error) { delete(additionalProperties, "id") delete(additionalProperties, "name") delete(additionalProperties, "k6_load_zone_id") + delete(additionalProperties, "available") + delete(additionalProperties, "custom_load_runner_image") + delete(additionalProperties, "public") o.AdditionalProperties = additionalProperties } diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_allowed_load_zone_to_update_api_model.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_allowed_load_zone_to_update_api_model.go index a8564ebae..fc7adc208 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_allowed_load_zone_to_update_api_model.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_allowed_load_zone_to_update_api_model.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ @@ -22,7 +22,7 @@ var _ MappedNullable = &AllowedLoadZoneToUpdateApiModel{} // AllowedLoadZoneToUpdateApiModel struct for AllowedLoadZoneToUpdateApiModel type AllowedLoadZoneToUpdateApiModel struct { // ID of the load zone. - Id int32 `json:"id"` + Id int64 `json:"id"` AdditionalProperties map[string]interface{} } @@ -32,7 +32,7 @@ type _AllowedLoadZoneToUpdateApiModel AllowedLoadZoneToUpdateApiModel // This constructor will assign default values to properties that have it defined, // and makes sure properties required by API are set, but the set of arguments // will change when the set of required properties is changed -func NewAllowedLoadZoneToUpdateApiModel(id int32) *AllowedLoadZoneToUpdateApiModel { +func NewAllowedLoadZoneToUpdateApiModel(id int64) *AllowedLoadZoneToUpdateApiModel { this := AllowedLoadZoneToUpdateApiModel{} this.Id = id return &this @@ -47,9 +47,9 @@ func NewAllowedLoadZoneToUpdateApiModelWithDefaults() *AllowedLoadZoneToUpdateAp } // GetId returns the Id field value -func (o *AllowedLoadZoneToUpdateApiModel) GetId() int32 { +func (o *AllowedLoadZoneToUpdateApiModel) GetId() int64 { if o == nil { - var ret int32 + var ret int64 return ret } @@ -58,7 +58,7 @@ func (o *AllowedLoadZoneToUpdateApiModel) GetId() int32 { // GetIdOk returns a tuple with the Id field value // and a boolean to check if the value has been set. -func (o *AllowedLoadZoneToUpdateApiModel) GetIdOk() (*int32, bool) { +func (o *AllowedLoadZoneToUpdateApiModel) GetIdOk() (*int64, bool) { if o == nil { return nil, false } @@ -66,7 +66,7 @@ func (o *AllowedLoadZoneToUpdateApiModel) GetIdOk() (*int32, bool) { } // SetId sets field value -func (o *AllowedLoadZoneToUpdateApiModel) SetId(v int32) { +func (o *AllowedLoadZoneToUpdateApiModel) SetId(v int64) { o.Id = v } diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_allowed_load_zones_list_api_model.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_allowed_load_zones_list_api_model.go index 1452d02b4..b86f80c4f 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_allowed_load_zones_list_api_model.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_allowed_load_zones_list_api_model.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_allowed_project_api_model.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_allowed_project_api_model.go index 3cdaedc76..850243408 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_allowed_project_api_model.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_allowed_project_api_model.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ @@ -22,7 +22,7 @@ var _ MappedNullable = &AllowedProjectApiModel{} // AllowedProjectApiModel struct for AllowedProjectApiModel type AllowedProjectApiModel struct { // ID of the project. - Id int32 `json:"id"` + Id int64 `json:"id"` // Name of the project. Name string `json:"name"` AdditionalProperties map[string]interface{} @@ -34,7 +34,7 @@ type _AllowedProjectApiModel AllowedProjectApiModel // This constructor will assign default values to properties that have it defined, // and makes sure properties required by API are set, but the set of arguments // will change when the set of required properties is changed -func NewAllowedProjectApiModel(id int32, name string) *AllowedProjectApiModel { +func NewAllowedProjectApiModel(id int64, name string) *AllowedProjectApiModel { this := AllowedProjectApiModel{} this.Id = id this.Name = name @@ -50,9 +50,9 @@ func NewAllowedProjectApiModelWithDefaults() *AllowedProjectApiModel { } // GetId returns the Id field value -func (o *AllowedProjectApiModel) GetId() int32 { +func (o *AllowedProjectApiModel) GetId() int64 { if o == nil { - var ret int32 + var ret int64 return ret } @@ -61,7 +61,7 @@ func (o *AllowedProjectApiModel) GetId() int32 { // GetIdOk returns a tuple with the Id field value // and a boolean to check if the value has been set. -func (o *AllowedProjectApiModel) GetIdOk() (*int32, bool) { +func (o *AllowedProjectApiModel) GetIdOk() (*int64, bool) { if o == nil { return nil, false } @@ -69,7 +69,7 @@ func (o *AllowedProjectApiModel) GetIdOk() (*int32, bool) { } // SetId sets field value -func (o *AllowedProjectApiModel) SetId(v int32) { +func (o *AllowedProjectApiModel) SetId(v int64) { o.Id = v } diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_allowed_project_to_update_api_model.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_allowed_project_to_update_api_model.go index 9afde4cf4..63d4dc419 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_allowed_project_to_update_api_model.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_allowed_project_to_update_api_model.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ @@ -22,7 +22,7 @@ var _ MappedNullable = &AllowedProjectToUpdateApiModel{} // AllowedProjectToUpdateApiModel struct for AllowedProjectToUpdateApiModel type AllowedProjectToUpdateApiModel struct { // ID of the project. - Id int32 `json:"id"` + Id int64 `json:"id"` AdditionalProperties map[string]interface{} } @@ -32,7 +32,7 @@ type _AllowedProjectToUpdateApiModel AllowedProjectToUpdateApiModel // This constructor will assign default values to properties that have it defined, // and makes sure properties required by API are set, but the set of arguments // will change when the set of required properties is changed -func NewAllowedProjectToUpdateApiModel(id int32) *AllowedProjectToUpdateApiModel { +func NewAllowedProjectToUpdateApiModel(id int64) *AllowedProjectToUpdateApiModel { this := AllowedProjectToUpdateApiModel{} this.Id = id return &this @@ -47,9 +47,9 @@ func NewAllowedProjectToUpdateApiModelWithDefaults() *AllowedProjectToUpdateApiM } // GetId returns the Id field value -func (o *AllowedProjectToUpdateApiModel) GetId() int32 { +func (o *AllowedProjectToUpdateApiModel) GetId() int64 { if o == nil { - var ret int32 + var ret int64 return ret } @@ -58,7 +58,7 @@ func (o *AllowedProjectToUpdateApiModel) GetId() int32 { // GetIdOk returns a tuple with the Id field value // and a boolean to check if the value has been set. -func (o *AllowedProjectToUpdateApiModel) GetIdOk() (*int32, bool) { +func (o *AllowedProjectToUpdateApiModel) GetIdOk() (*int64, bool) { if o == nil { return nil, false } @@ -66,7 +66,7 @@ func (o *AllowedProjectToUpdateApiModel) GetIdOk() (*int32, bool) { } // SetId sets field value -func (o *AllowedProjectToUpdateApiModel) SetId(v int32) { +func (o *AllowedProjectToUpdateApiModel) SetId(v int64) { o.Id = v } diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_allowed_projects_list_api_model.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_allowed_projects_list_api_model.go index 291406692..6d709c4bb 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_allowed_projects_list_api_model.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_allowed_projects_list_api_model.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_authentication_response.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_authentication_response.go index 87a3d22a6..78f0eb634 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_authentication_response.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_authentication_response.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ @@ -22,9 +22,9 @@ var _ MappedNullable = &AuthenticationResponse{} // AuthenticationResponse struct for AuthenticationResponse type AuthenticationResponse struct { // The ID of the Grafana stack matching the provided URL. - StackId int32 `json:"stack_id"` + StackId int64 `json:"stack_id"` // The ID of the default project in the stack. - DefaultProjectId int32 `json:"default_project_id"` + DefaultProjectId int64 `json:"default_project_id"` AdditionalProperties map[string]interface{} } @@ -34,7 +34,7 @@ type _AuthenticationResponse AuthenticationResponse // This constructor will assign default values to properties that have it defined, // and makes sure properties required by API are set, but the set of arguments // will change when the set of required properties is changed -func NewAuthenticationResponse(stackId int32, defaultProjectId int32) *AuthenticationResponse { +func NewAuthenticationResponse(stackId int64, defaultProjectId int64) *AuthenticationResponse { this := AuthenticationResponse{} this.StackId = stackId this.DefaultProjectId = defaultProjectId @@ -50,9 +50,9 @@ func NewAuthenticationResponseWithDefaults() *AuthenticationResponse { } // GetStackId returns the StackId field value -func (o *AuthenticationResponse) GetStackId() int32 { +func (o *AuthenticationResponse) GetStackId() int64 { if o == nil { - var ret int32 + var ret int64 return ret } @@ -61,7 +61,7 @@ func (o *AuthenticationResponse) GetStackId() int32 { // GetStackIdOk returns a tuple with the StackId field value // and a boolean to check if the value has been set. -func (o *AuthenticationResponse) GetStackIdOk() (*int32, bool) { +func (o *AuthenticationResponse) GetStackIdOk() (*int64, bool) { if o == nil { return nil, false } @@ -69,14 +69,14 @@ func (o *AuthenticationResponse) GetStackIdOk() (*int32, bool) { } // SetStackId sets field value -func (o *AuthenticationResponse) SetStackId(v int32) { +func (o *AuthenticationResponse) SetStackId(v int64) { o.StackId = v } // GetDefaultProjectId returns the DefaultProjectId field value -func (o *AuthenticationResponse) GetDefaultProjectId() int32 { +func (o *AuthenticationResponse) GetDefaultProjectId() int64 { if o == nil { - var ret int32 + var ret int64 return ret } @@ -85,7 +85,7 @@ func (o *AuthenticationResponse) GetDefaultProjectId() int32 { // GetDefaultProjectIdOk returns a tuple with the DefaultProjectId field value // and a boolean to check if the value has been set. -func (o *AuthenticationResponse) GetDefaultProjectIdOk() (*int32, bool) { +func (o *AuthenticationResponse) GetDefaultProjectIdOk() (*int64, bool) { if o == nil { return nil, false } @@ -93,7 +93,7 @@ func (o *AuthenticationResponse) GetDefaultProjectIdOk() (*int32, bool) { } // SetDefaultProjectId sets field value -func (o *AuthenticationResponse) SetDefaultProjectId(v int32) { +func (o *AuthenticationResponse) SetDefaultProjectId(v int64) { o.DefaultProjectId = v } diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_base_total_vuh.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_base_total_vuh.go index bdc7eb7b9..7f2bd2f91 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_base_total_vuh.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_base_total_vuh.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_browser_vuh.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_browser_vuh.go index e6255d2a0..c6da54a53 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_browser_vuh.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_browser_vuh.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_cloud_options.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_cloud_options.go index cca32802c..dd50cf1bb 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_cloud_options.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_cloud_options.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ @@ -21,7 +21,7 @@ var _ MappedNullable = &CloudOptions{} // CloudOptions struct for CloudOptions type CloudOptions struct { // ID of a project where the test belongs. - ProjectID *int32 `json:"projectID,omitempty"` + ProjectID *int64 `json:"projectID,omitempty"` AdditionalProperties map[string]interface{} } @@ -45,9 +45,9 @@ func NewCloudOptionsWithDefaults() *CloudOptions { } // GetProjectID returns the ProjectID field value if set, zero value otherwise. -func (o *CloudOptions) GetProjectID() int32 { +func (o *CloudOptions) GetProjectID() int64 { if o == nil || IsNil(o.ProjectID) { - var ret int32 + var ret int64 return ret } return *o.ProjectID @@ -55,7 +55,7 @@ func (o *CloudOptions) GetProjectID() int32 { // GetProjectIDOk returns a tuple with the ProjectID field value if set, nil otherwise // and a boolean to check if the value has been set. -func (o *CloudOptions) GetProjectIDOk() (*int32, bool) { +func (o *CloudOptions) GetProjectIDOk() (*int64, bool) { if o == nil || IsNil(o.ProjectID) { return nil, false } @@ -71,8 +71,8 @@ func (o *CloudOptions) HasProjectID() bool { return false } -// SetProjectID gets a reference to the given int32 and assigns it to the ProjectID field. -func (o *CloudOptions) SetProjectID(v int32) { +// SetProjectID gets a reference to the given int64 and assigns it to the ProjectID field. +func (o *CloudOptions) SetProjectID(v int64) { o.ProjectID = &v } diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_cost_breakdown_api_model.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_cost_breakdown_api_model.go index f03d6e66d..15f458e80 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_cost_breakdown_api_model.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_cost_breakdown_api_model.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_create_project_api_model.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_create_project_api_model.go index d70a7744e..d6af60624 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_create_project_api_model.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_create_project_api_model.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_create_schedule_request.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_create_schedule_request.go index 2deba426e..00a2acab8 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_create_schedule_request.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_create_schedule_request.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_decrypted_api_model.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_decrypted_api_model.go new file mode 100644 index 000000000..79ea885e4 --- /dev/null +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_decrypted_api_model.go @@ -0,0 +1,168 @@ +/* +Grafana Cloud k6 + +HTTP API for interacting with Grafana Cloud k6. + +API version: 1.12.0 +Contact: info@grafana.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package k6 + +import ( + "encoding/json" + "fmt" +) + +// checks if the DecryptedApiModel type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &DecryptedApiModel{} + +// DecryptedApiModel Model for the response of the secrets decryption endpoint. +type DecryptedApiModel struct { + // The decrypted secret. + Plaintext string `json:"plaintext"` + AdditionalProperties map[string]interface{} +} + +type _DecryptedApiModel DecryptedApiModel + +// NewDecryptedApiModel instantiates a new DecryptedApiModel object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewDecryptedApiModel(plaintext string) *DecryptedApiModel { + this := DecryptedApiModel{} + this.Plaintext = plaintext + return &this +} + +// NewDecryptedApiModelWithDefaults instantiates a new DecryptedApiModel object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewDecryptedApiModelWithDefaults() *DecryptedApiModel { + this := DecryptedApiModel{} + return &this +} + +// GetPlaintext returns the Plaintext field value +func (o *DecryptedApiModel) GetPlaintext() string { + if o == nil { + var ret string + return ret + } + + return o.Plaintext +} + +// GetPlaintextOk returns a tuple with the Plaintext field value +// and a boolean to check if the value has been set. +func (o *DecryptedApiModel) GetPlaintextOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Plaintext, true +} + +// SetPlaintext sets field value +func (o *DecryptedApiModel) SetPlaintext(v string) { + o.Plaintext = v +} + +func (o DecryptedApiModel) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o DecryptedApiModel) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["plaintext"] = o.Plaintext + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *DecryptedApiModel) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "plaintext", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err + } + + for _, requiredProperty := range requiredProperties { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varDecryptedApiModel := _DecryptedApiModel{} + + err = json.Unmarshal(data, &varDecryptedApiModel) + + if err != nil { + return err + } + + *o = DecryptedApiModel(varDecryptedApiModel) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(data, &additionalProperties); err == nil { + delete(additionalProperties, "plaintext") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableDecryptedApiModel struct { + value *DecryptedApiModel + isSet bool +} + +func (v NullableDecryptedApiModel) Get() *DecryptedApiModel { + return v.value +} + +func (v *NullableDecryptedApiModel) Set(val *DecryptedApiModel) { + v.value = val + v.isSet = true +} + +func (v NullableDecryptedApiModel) IsSet() bool { + return v.isSet +} + +func (v *NullableDecryptedApiModel) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableDecryptedApiModel(val *DecryptedApiModel) *NullableDecryptedApiModel { + return &NullableDecryptedApiModel{value: val, isSet: true} +} + +func (v NullableDecryptedApiModel) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableDecryptedApiModel) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_distribution_zone_api_model.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_distribution_zone_api_model.go index 1ea2ef702..e01350246 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_distribution_zone_api_model.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_distribution_zone_api_model.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_error_api_model.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_error_api_model.go index 2ae939ef3..e48d09439 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_error_api_model.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_error_api_model.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_error_details_api_model.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_error_details_api_model.go index 1b77678ba..1f8387f89 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_error_details_api_model.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_error_details_api_model.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_error_response_api_model.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_error_response_api_model.go index 50d515016..e84ad13a4 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_error_response_api_model.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_error_response_api_model.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_files_runtime_config.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_files_runtime_config.go new file mode 100644 index 000000000..e689a8eb1 --- /dev/null +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_files_runtime_config.go @@ -0,0 +1,258 @@ +/* +Grafana Cloud k6 + +HTTP API for interacting with Grafana Cloud k6. + +API version: 1.12.0 +Contact: info@grafana.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package k6 + +import ( + "encoding/json" + "fmt" +) + +// checks if the FilesRuntimeConfig type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &FilesRuntimeConfig{} + +// FilesRuntimeConfig Files upload runtime configuration. +type FilesRuntimeConfig struct { + // URL to generate a pre-signed URLs for file uploads. + PushUrl string `json:"push_url"` + // Base path for screenshot uploads. + ScreenshotsBasePath string `json:"screenshots_base_path"` + // HTTP headers to include in requests. + Headers map[string]string `json:"headers"` + // HTTP method to use for screenshot uploads. + Method string `json:"method"` + AdditionalProperties map[string]interface{} +} + +type _FilesRuntimeConfig FilesRuntimeConfig + +// NewFilesRuntimeConfig instantiates a new FilesRuntimeConfig object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewFilesRuntimeConfig(pushUrl string, screenshotsBasePath string, headers map[string]string, method string) *FilesRuntimeConfig { + this := FilesRuntimeConfig{} + this.PushUrl = pushUrl + this.ScreenshotsBasePath = screenshotsBasePath + this.Headers = headers + this.Method = method + return &this +} + +// NewFilesRuntimeConfigWithDefaults instantiates a new FilesRuntimeConfig object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewFilesRuntimeConfigWithDefaults() *FilesRuntimeConfig { + this := FilesRuntimeConfig{} + return &this +} + +// GetPushUrl returns the PushUrl field value +func (o *FilesRuntimeConfig) GetPushUrl() string { + if o == nil { + var ret string + return ret + } + + return o.PushUrl +} + +// GetPushUrlOk returns a tuple with the PushUrl field value +// and a boolean to check if the value has been set. +func (o *FilesRuntimeConfig) GetPushUrlOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.PushUrl, true +} + +// SetPushUrl sets field value +func (o *FilesRuntimeConfig) SetPushUrl(v string) { + o.PushUrl = v +} + +// GetScreenshotsBasePath returns the ScreenshotsBasePath field value +func (o *FilesRuntimeConfig) GetScreenshotsBasePath() string { + if o == nil { + var ret string + return ret + } + + return o.ScreenshotsBasePath +} + +// GetScreenshotsBasePathOk returns a tuple with the ScreenshotsBasePath field value +// and a boolean to check if the value has been set. +func (o *FilesRuntimeConfig) GetScreenshotsBasePathOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.ScreenshotsBasePath, true +} + +// SetScreenshotsBasePath sets field value +func (o *FilesRuntimeConfig) SetScreenshotsBasePath(v string) { + o.ScreenshotsBasePath = v +} + +// GetHeaders returns the Headers field value +func (o *FilesRuntimeConfig) GetHeaders() map[string]string { + if o == nil { + var ret map[string]string + return ret + } + + return o.Headers +} + +// GetHeadersOk returns a tuple with the Headers field value +// and a boolean to check if the value has been set. +func (o *FilesRuntimeConfig) GetHeadersOk() (map[string]string, bool) { + if o == nil { + return map[string]string{}, false + } + return o.Headers, true +} + +// SetHeaders sets field value +func (o *FilesRuntimeConfig) SetHeaders(v map[string]string) { + o.Headers = v +} + +// GetMethod returns the Method field value +func (o *FilesRuntimeConfig) GetMethod() string { + if o == nil { + var ret string + return ret + } + + return o.Method +} + +// GetMethodOk returns a tuple with the Method field value +// and a boolean to check if the value has been set. +func (o *FilesRuntimeConfig) GetMethodOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Method, true +} + +// SetMethod sets field value +func (o *FilesRuntimeConfig) SetMethod(v string) { + o.Method = v +} + +func (o FilesRuntimeConfig) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o FilesRuntimeConfig) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["push_url"] = o.PushUrl + toSerialize["screenshots_base_path"] = o.ScreenshotsBasePath + toSerialize["headers"] = o.Headers + toSerialize["method"] = o.Method + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *FilesRuntimeConfig) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "push_url", + "screenshots_base_path", + "headers", + "method", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err + } + + for _, requiredProperty := range requiredProperties { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varFilesRuntimeConfig := _FilesRuntimeConfig{} + + err = json.Unmarshal(data, &varFilesRuntimeConfig) + + if err != nil { + return err + } + + *o = FilesRuntimeConfig(varFilesRuntimeConfig) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(data, &additionalProperties); err == nil { + delete(additionalProperties, "push_url") + delete(additionalProperties, "screenshots_base_path") + delete(additionalProperties, "headers") + delete(additionalProperties, "method") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableFilesRuntimeConfig struct { + value *FilesRuntimeConfig + isSet bool +} + +func (v NullableFilesRuntimeConfig) Get() *FilesRuntimeConfig { + return v.value +} + +func (v *NullableFilesRuntimeConfig) Set(val *FilesRuntimeConfig) { + v.value = val + v.isSet = true +} + +func (v NullableFilesRuntimeConfig) IsSet() bool { + return v.isSet +} + +func (v *NullableFilesRuntimeConfig) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableFilesRuntimeConfig(val *FilesRuntimeConfig) *NullableFilesRuntimeConfig { + return &NullableFilesRuntimeConfig{value: val, isSet: true} +} + +func (v NullableFilesRuntimeConfig) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableFilesRuntimeConfig) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_frequency.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_frequency.go index 1eadcff28..bc4279ff4 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_frequency.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_frequency.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_label_key_create_item.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_label_key_create_item.go index b4103c08a..139544053 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_label_key_create_item.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_label_key_create_item.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_label_key_create_request.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_label_key_create_request.go index 5c2ce236f..26c95f66c 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_label_key_create_request.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_label_key_create_request.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_label_key_list_response.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_label_key_list_response.go index 13518826d..6f9c2e0c4 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_label_key_list_response.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_label_key_list_response.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_label_key_patch_request.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_label_key_patch_request.go index 0589bcb75..7aace36d6 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_label_key_patch_request.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_label_key_patch_request.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ @@ -23,9 +23,12 @@ type LabelKeyPatchRequest struct { // New label key name. Key NullableString `json:"key,omitempty" validate:"regexp=^[^\\\\s'\\\\\\";\\\\\\\\%]+$"` // New label key description. - Description NullableString `json:"description,omitempty"` + Description NullableString `json:"description,omitempty"` + AdditionalProperties map[string]interface{} } +type _LabelKeyPatchRequest LabelKeyPatchRequest + // NewLabelKeyPatchRequest instantiates a new LabelKeyPatchRequest object // This constructor will assign default values to properties that have it defined, // and makes sure properties required by API are set, but the set of arguments @@ -145,9 +148,36 @@ func (o LabelKeyPatchRequest) ToMap() (map[string]interface{}, error) { if o.Description.IsSet() { toSerialize["description"] = o.Description.Get() } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return toSerialize, nil } +func (o *LabelKeyPatchRequest) UnmarshalJSON(data []byte) (err error) { + varLabelKeyPatchRequest := _LabelKeyPatchRequest{} + + err = json.Unmarshal(data, &varLabelKeyPatchRequest) + + if err != nil { + return err + } + + *o = LabelKeyPatchRequest(varLabelKeyPatchRequest) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(data, &additionalProperties); err == nil { + delete(additionalProperties, "key") + delete(additionalProperties, "description") + o.AdditionalProperties = additionalProperties + } + + return err +} + type NullableLabelKeyPatchRequest struct { value *LabelKeyPatchRequest isSet bool diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_label_key_response.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_label_key_response.go index e1482e847..ebf4a86a5 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_label_key_response.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_label_key_response.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ @@ -22,7 +22,7 @@ var _ MappedNullable = &LabelKeyResponse{} // LabelKeyResponse Label key response model type LabelKeyResponse struct { // Label key ID. - Id int32 `json:"id"` + Id int64 `json:"id"` // Label key name. Key string `json:"key"` // Label key description. @@ -36,7 +36,7 @@ type _LabelKeyResponse LabelKeyResponse // This constructor will assign default values to properties that have it defined, // and makes sure properties required by API are set, but the set of arguments // will change when the set of required properties is changed -func NewLabelKeyResponse(id int32, key string) *LabelKeyResponse { +func NewLabelKeyResponse(id int64, key string) *LabelKeyResponse { this := LabelKeyResponse{} this.Id = id this.Key = key @@ -52,9 +52,9 @@ func NewLabelKeyResponseWithDefaults() *LabelKeyResponse { } // GetId returns the Id field value -func (o *LabelKeyResponse) GetId() int32 { +func (o *LabelKeyResponse) GetId() int64 { if o == nil { - var ret int32 + var ret int64 return ret } @@ -63,7 +63,7 @@ func (o *LabelKeyResponse) GetId() int32 { // GetIdOk returns a tuple with the Id field value // and a boolean to check if the value has been set. -func (o *LabelKeyResponse) GetIdOk() (*int32, bool) { +func (o *LabelKeyResponse) GetIdOk() (*int64, bool) { if o == nil { return nil, false } @@ -71,7 +71,7 @@ func (o *LabelKeyResponse) GetIdOk() (*int32, bool) { } // SetId sets field value -func (o *LabelKeyResponse) SetId(v int32) { +func (o *LabelKeyResponse) SetId(v int64) { o.Id = v } diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_load_test_api_model.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_load_test_api_model.go index e482000f8..be5abbed2 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_load_test_api_model.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_load_test_api_model.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ @@ -23,13 +23,16 @@ var _ MappedNullable = &LoadTestApiModel{} // LoadTestApiModel struct for LoadTestApiModel type LoadTestApiModel struct { // ID of the load test. - Id int32 `json:"id"` + Id int64 `json:"id"` // ID of the parent project. - ProjectId int32 `json:"project_id"` + ProjectId int64 `json:"project_id"` // Unique name of the test within the project. Name string `json:"name"` - // ID of a baseline test run used for results comparison. - BaselineTestRunId NullableInt32 `json:"baseline_test_run_id"` + // ID of a baseline test run used for results comparison. Deprecated: baselines are being replaced by the star/unstar test run APIs and this field is scheduled for removal on 2026-09-01. + // Deprecated + BaselineTestRunId NullableInt64 `json:"baseline_test_run_id"` + // Identifier of the k6 version used to run the test. + K6Version NullableInt32 `json:"k6_version,omitempty"` // The date when the test was created. Created time.Time `json:"created"` // The date when the test was last updated. @@ -43,7 +46,7 @@ type _LoadTestApiModel LoadTestApiModel // This constructor will assign default values to properties that have it defined, // and makes sure properties required by API are set, but the set of arguments // will change when the set of required properties is changed -func NewLoadTestApiModel(id int32, projectId int32, name string, baselineTestRunId NullableInt32, created time.Time, updated time.Time) *LoadTestApiModel { +func NewLoadTestApiModel(id int64, projectId int64, name string, baselineTestRunId NullableInt64, created time.Time, updated time.Time) *LoadTestApiModel { this := LoadTestApiModel{} this.Id = id this.ProjectId = projectId @@ -63,9 +66,9 @@ func NewLoadTestApiModelWithDefaults() *LoadTestApiModel { } // GetId returns the Id field value -func (o *LoadTestApiModel) GetId() int32 { +func (o *LoadTestApiModel) GetId() int64 { if o == nil { - var ret int32 + var ret int64 return ret } @@ -74,7 +77,7 @@ func (o *LoadTestApiModel) GetId() int32 { // GetIdOk returns a tuple with the Id field value // and a boolean to check if the value has been set. -func (o *LoadTestApiModel) GetIdOk() (*int32, bool) { +func (o *LoadTestApiModel) GetIdOk() (*int64, bool) { if o == nil { return nil, false } @@ -82,14 +85,14 @@ func (o *LoadTestApiModel) GetIdOk() (*int32, bool) { } // SetId sets field value -func (o *LoadTestApiModel) SetId(v int32) { +func (o *LoadTestApiModel) SetId(v int64) { o.Id = v } // GetProjectId returns the ProjectId field value -func (o *LoadTestApiModel) GetProjectId() int32 { +func (o *LoadTestApiModel) GetProjectId() int64 { if o == nil { - var ret int32 + var ret int64 return ret } @@ -98,7 +101,7 @@ func (o *LoadTestApiModel) GetProjectId() int32 { // GetProjectIdOk returns a tuple with the ProjectId field value // and a boolean to check if the value has been set. -func (o *LoadTestApiModel) GetProjectIdOk() (*int32, bool) { +func (o *LoadTestApiModel) GetProjectIdOk() (*int64, bool) { if o == nil { return nil, false } @@ -106,7 +109,7 @@ func (o *LoadTestApiModel) GetProjectIdOk() (*int32, bool) { } // SetProjectId sets field value -func (o *LoadTestApiModel) SetProjectId(v int32) { +func (o *LoadTestApiModel) SetProjectId(v int64) { o.ProjectId = v } @@ -135,10 +138,11 @@ func (o *LoadTestApiModel) SetName(v string) { } // GetBaselineTestRunId returns the BaselineTestRunId field value -// If the value is explicit nil, the zero value for int32 will be returned -func (o *LoadTestApiModel) GetBaselineTestRunId() int32 { +// If the value is explicit nil, the zero value for int64 will be returned +// Deprecated +func (o *LoadTestApiModel) GetBaselineTestRunId() int64 { if o == nil || o.BaselineTestRunId.Get() == nil { - var ret int32 + var ret int64 return ret } @@ -148,7 +152,8 @@ func (o *LoadTestApiModel) GetBaselineTestRunId() int32 { // GetBaselineTestRunIdOk returns a tuple with the BaselineTestRunId field value // and a boolean to check if the value has been set. // NOTE: If the value is an explicit nil, `nil, true` will be returned -func (o *LoadTestApiModel) GetBaselineTestRunIdOk() (*int32, bool) { +// Deprecated +func (o *LoadTestApiModel) GetBaselineTestRunIdOk() (*int64, bool) { if o == nil { return nil, false } @@ -156,10 +161,54 @@ func (o *LoadTestApiModel) GetBaselineTestRunIdOk() (*int32, bool) { } // SetBaselineTestRunId sets field value -func (o *LoadTestApiModel) SetBaselineTestRunId(v int32) { +// Deprecated +func (o *LoadTestApiModel) SetBaselineTestRunId(v int64) { o.BaselineTestRunId.Set(&v) } +// GetK6Version returns the K6Version field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *LoadTestApiModel) GetK6Version() int32 { + if o == nil || IsNil(o.K6Version.Get()) { + var ret int32 + return ret + } + return *o.K6Version.Get() +} + +// GetK6VersionOk returns a tuple with the K6Version field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *LoadTestApiModel) GetK6VersionOk() (*int32, bool) { + if o == nil { + return nil, false + } + return o.K6Version.Get(), o.K6Version.IsSet() +} + +// HasK6Version returns a boolean if a field has been set. +func (o *LoadTestApiModel) HasK6Version() bool { + if o != nil && o.K6Version.IsSet() { + return true + } + + return false +} + +// SetK6Version gets a reference to the given NullableInt32 and assigns it to the K6Version field. +func (o *LoadTestApiModel) SetK6Version(v int32) { + o.K6Version.Set(&v) +} + +// SetK6VersionNil sets the value for K6Version to be an explicit nil +func (o *LoadTestApiModel) SetK6VersionNil() { + o.K6Version.Set(nil) +} + +// UnsetK6Version ensures that no value is present for K6Version, not even an explicit nil +func (o *LoadTestApiModel) UnsetK6Version() { + o.K6Version.Unset() +} + // GetCreated returns the Created field value func (o *LoadTestApiModel) GetCreated() time.Time { if o == nil { @@ -222,6 +271,9 @@ func (o LoadTestApiModel) ToMap() (map[string]interface{}, error) { toSerialize["project_id"] = o.ProjectId toSerialize["name"] = o.Name toSerialize["baseline_test_run_id"] = o.BaselineTestRunId.Get() + if o.K6Version.IsSet() { + toSerialize["k6_version"] = o.K6Version.Get() + } toSerialize["created"] = o.Created toSerialize["updated"] = o.Updated @@ -276,6 +328,7 @@ func (o *LoadTestApiModel) UnmarshalJSON(data []byte) (err error) { delete(additionalProperties, "project_id") delete(additionalProperties, "name") delete(additionalProperties, "baseline_test_run_id") + delete(additionalProperties, "k6_version") delete(additionalProperties, "created") delete(additionalProperties, "updated") o.AdditionalProperties = additionalProperties diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_load_test_list_response.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_load_test_list_response.go index 13234456b..15347fbda 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_load_test_list_response.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_load_test_list_response.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_load_zone_api_model.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_load_zone_api_model.go index 48f75b99a..dc1219ebc 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_load_zone_api_model.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_load_zone_api_model.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ @@ -22,11 +22,17 @@ var _ MappedNullable = &LoadZoneApiModel{} // LoadZoneApiModel struct for LoadZoneApiModel type LoadZoneApiModel struct { // ID of the load zone. - Id int32 `json:"id"` + Id int64 `json:"id"` // Name of the load zone. Name string `json:"name"` // ID used to identify the load zone in the k6 scripts. - K6LoadZoneId string `json:"k6_load_zone_id"` + K6LoadZoneId string `json:"k6_load_zone_id"` + // Whether the load zone can be used to start tests. + Available bool `json:"available"` + // Custom load runner image. Only set for private load zones. + CustomLoadRunnerImage NullableString `json:"custom_load_runner_image"` + // Whether the load zone is public or private. + Public bool `json:"public"` AdditionalProperties map[string]interface{} } @@ -36,11 +42,14 @@ type _LoadZoneApiModel LoadZoneApiModel // This constructor will assign default values to properties that have it defined, // and makes sure properties required by API are set, but the set of arguments // will change when the set of required properties is changed -func NewLoadZoneApiModel(id int32, name string, k6LoadZoneId string) *LoadZoneApiModel { +func NewLoadZoneApiModel(id int64, name string, k6LoadZoneId string, available bool, customLoadRunnerImage NullableString, public bool) *LoadZoneApiModel { this := LoadZoneApiModel{} this.Id = id this.Name = name this.K6LoadZoneId = k6LoadZoneId + this.Available = available + this.CustomLoadRunnerImage = customLoadRunnerImage + this.Public = public return &this } @@ -53,9 +62,9 @@ func NewLoadZoneApiModelWithDefaults() *LoadZoneApiModel { } // GetId returns the Id field value -func (o *LoadZoneApiModel) GetId() int32 { +func (o *LoadZoneApiModel) GetId() int64 { if o == nil { - var ret int32 + var ret int64 return ret } @@ -64,7 +73,7 @@ func (o *LoadZoneApiModel) GetId() int32 { // GetIdOk returns a tuple with the Id field value // and a boolean to check if the value has been set. -func (o *LoadZoneApiModel) GetIdOk() (*int32, bool) { +func (o *LoadZoneApiModel) GetIdOk() (*int64, bool) { if o == nil { return nil, false } @@ -72,7 +81,7 @@ func (o *LoadZoneApiModel) GetIdOk() (*int32, bool) { } // SetId sets field value -func (o *LoadZoneApiModel) SetId(v int32) { +func (o *LoadZoneApiModel) SetId(v int64) { o.Id = v } @@ -124,6 +133,80 @@ func (o *LoadZoneApiModel) SetK6LoadZoneId(v string) { o.K6LoadZoneId = v } +// GetAvailable returns the Available field value +func (o *LoadZoneApiModel) GetAvailable() bool { + if o == nil { + var ret bool + return ret + } + + return o.Available +} + +// GetAvailableOk returns a tuple with the Available field value +// and a boolean to check if the value has been set. +func (o *LoadZoneApiModel) GetAvailableOk() (*bool, bool) { + if o == nil { + return nil, false + } + return &o.Available, true +} + +// SetAvailable sets field value +func (o *LoadZoneApiModel) SetAvailable(v bool) { + o.Available = v +} + +// GetCustomLoadRunnerImage returns the CustomLoadRunnerImage field value +// If the value is explicit nil, the zero value for string will be returned +func (o *LoadZoneApiModel) GetCustomLoadRunnerImage() string { + if o == nil || o.CustomLoadRunnerImage.Get() == nil { + var ret string + return ret + } + + return *o.CustomLoadRunnerImage.Get() +} + +// GetCustomLoadRunnerImageOk returns a tuple with the CustomLoadRunnerImage field value +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *LoadZoneApiModel) GetCustomLoadRunnerImageOk() (*string, bool) { + if o == nil { + return nil, false + } + return o.CustomLoadRunnerImage.Get(), o.CustomLoadRunnerImage.IsSet() +} + +// SetCustomLoadRunnerImage sets field value +func (o *LoadZoneApiModel) SetCustomLoadRunnerImage(v string) { + o.CustomLoadRunnerImage.Set(&v) +} + +// GetPublic returns the Public field value +func (o *LoadZoneApiModel) GetPublic() bool { + if o == nil { + var ret bool + return ret + } + + return o.Public +} + +// GetPublicOk returns a tuple with the Public field value +// and a boolean to check if the value has been set. +func (o *LoadZoneApiModel) GetPublicOk() (*bool, bool) { + if o == nil { + return nil, false + } + return &o.Public, true +} + +// SetPublic sets field value +func (o *LoadZoneApiModel) SetPublic(v bool) { + o.Public = v +} + func (o LoadZoneApiModel) MarshalJSON() ([]byte, error) { toSerialize, err := o.ToMap() if err != nil { @@ -137,6 +220,9 @@ func (o LoadZoneApiModel) ToMap() (map[string]interface{}, error) { toSerialize["id"] = o.Id toSerialize["name"] = o.Name toSerialize["k6_load_zone_id"] = o.K6LoadZoneId + toSerialize["available"] = o.Available + toSerialize["custom_load_runner_image"] = o.CustomLoadRunnerImage.Get() + toSerialize["public"] = o.Public for key, value := range o.AdditionalProperties { toSerialize[key] = value @@ -153,6 +239,9 @@ func (o *LoadZoneApiModel) UnmarshalJSON(data []byte) (err error) { "id", "name", "k6_load_zone_id", + "available", + "custom_load_runner_image", + "public", } allProperties := make(map[string]interface{}) @@ -185,6 +274,9 @@ func (o *LoadZoneApiModel) UnmarshalJSON(data []byte) (err error) { delete(additionalProperties, "id") delete(additionalProperties, "name") delete(additionalProperties, "k6_load_zone_id") + delete(additionalProperties, "available") + delete(additionalProperties, "custom_load_runner_image") + delete(additionalProperties, "public") o.AdditionalProperties = additionalProperties } diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_load_zone_distribution_api_model.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_load_zone_distribution_api_model.go index aeb3190b4..ebfa7dfca 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_load_zone_distribution_api_model.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_load_zone_distribution_api_model.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_load_zones_list_api_model.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_load_zones_list_api_model.go index 513eb467b..e4a441d8e 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_load_zones_list_api_model.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_load_zones_list_api_model.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_logs_runtime_config.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_logs_runtime_config.go new file mode 100644 index 000000000..b63a569a3 --- /dev/null +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_logs_runtime_config.go @@ -0,0 +1,348 @@ +/* +Grafana Cloud k6 + +HTTP API for interacting with Grafana Cloud k6. + +API version: 1.12.0 +Contact: info@grafana.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package k6 + +import ( + "encoding/json" + "fmt" +) + +// checks if the LogsRuntimeConfig type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &LogsRuntimeConfig{} + +// LogsRuntimeConfig Logs push runtime configuration. +type LogsRuntimeConfig struct { + // URL to push logs to. + PushUrl string `json:"push_url"` + // URL to tail logs from. + TailUrl string `json:"tail_url"` + // Maximum number of log lines to push per interval. + Limit int32 `json:"limit"` + // How often logs are pushed to the ingest service, for example '3s'. + PushPeriodSeconds string `json:"push_period_seconds"` + // Minimum log level to collect. + Level string `json:"level"` + // Maximum size in bytes of a single log message. + MessageMaxSize int32 `json:"message_max_size"` + // Log stream labels that are allowed to be forwarded. + AllowedLabels []string `json:"allowed_labels"` + AdditionalProperties map[string]interface{} +} + +type _LogsRuntimeConfig LogsRuntimeConfig + +// NewLogsRuntimeConfig instantiates a new LogsRuntimeConfig object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewLogsRuntimeConfig(pushUrl string, tailUrl string, limit int32, pushPeriodSeconds string, level string, messageMaxSize int32, allowedLabels []string) *LogsRuntimeConfig { + this := LogsRuntimeConfig{} + this.PushUrl = pushUrl + this.TailUrl = tailUrl + this.Limit = limit + this.PushPeriodSeconds = pushPeriodSeconds + this.Level = level + this.MessageMaxSize = messageMaxSize + this.AllowedLabels = allowedLabels + return &this +} + +// NewLogsRuntimeConfigWithDefaults instantiates a new LogsRuntimeConfig object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewLogsRuntimeConfigWithDefaults() *LogsRuntimeConfig { + this := LogsRuntimeConfig{} + return &this +} + +// GetPushUrl returns the PushUrl field value +func (o *LogsRuntimeConfig) GetPushUrl() string { + if o == nil { + var ret string + return ret + } + + return o.PushUrl +} + +// GetPushUrlOk returns a tuple with the PushUrl field value +// and a boolean to check if the value has been set. +func (o *LogsRuntimeConfig) GetPushUrlOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.PushUrl, true +} + +// SetPushUrl sets field value +func (o *LogsRuntimeConfig) SetPushUrl(v string) { + o.PushUrl = v +} + +// GetTailUrl returns the TailUrl field value +func (o *LogsRuntimeConfig) GetTailUrl() string { + if o == nil { + var ret string + return ret + } + + return o.TailUrl +} + +// GetTailUrlOk returns a tuple with the TailUrl field value +// and a boolean to check if the value has been set. +func (o *LogsRuntimeConfig) GetTailUrlOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.TailUrl, true +} + +// SetTailUrl sets field value +func (o *LogsRuntimeConfig) SetTailUrl(v string) { + o.TailUrl = v +} + +// GetLimit returns the Limit field value +func (o *LogsRuntimeConfig) GetLimit() int32 { + if o == nil { + var ret int32 + return ret + } + + return o.Limit +} + +// GetLimitOk returns a tuple with the Limit field value +// and a boolean to check if the value has been set. +func (o *LogsRuntimeConfig) GetLimitOk() (*int32, bool) { + if o == nil { + return nil, false + } + return &o.Limit, true +} + +// SetLimit sets field value +func (o *LogsRuntimeConfig) SetLimit(v int32) { + o.Limit = v +} + +// GetPushPeriodSeconds returns the PushPeriodSeconds field value +func (o *LogsRuntimeConfig) GetPushPeriodSeconds() string { + if o == nil { + var ret string + return ret + } + + return o.PushPeriodSeconds +} + +// GetPushPeriodSecondsOk returns a tuple with the PushPeriodSeconds field value +// and a boolean to check if the value has been set. +func (o *LogsRuntimeConfig) GetPushPeriodSecondsOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.PushPeriodSeconds, true +} + +// SetPushPeriodSeconds sets field value +func (o *LogsRuntimeConfig) SetPushPeriodSeconds(v string) { + o.PushPeriodSeconds = v +} + +// GetLevel returns the Level field value +func (o *LogsRuntimeConfig) GetLevel() string { + if o == nil { + var ret string + return ret + } + + return o.Level +} + +// GetLevelOk returns a tuple with the Level field value +// and a boolean to check if the value has been set. +func (o *LogsRuntimeConfig) GetLevelOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Level, true +} + +// SetLevel sets field value +func (o *LogsRuntimeConfig) SetLevel(v string) { + o.Level = v +} + +// GetMessageMaxSize returns the MessageMaxSize field value +func (o *LogsRuntimeConfig) GetMessageMaxSize() int32 { + if o == nil { + var ret int32 + return ret + } + + return o.MessageMaxSize +} + +// GetMessageMaxSizeOk returns a tuple with the MessageMaxSize field value +// and a boolean to check if the value has been set. +func (o *LogsRuntimeConfig) GetMessageMaxSizeOk() (*int32, bool) { + if o == nil { + return nil, false + } + return &o.MessageMaxSize, true +} + +// SetMessageMaxSize sets field value +func (o *LogsRuntimeConfig) SetMessageMaxSize(v int32) { + o.MessageMaxSize = v +} + +// GetAllowedLabels returns the AllowedLabels field value +func (o *LogsRuntimeConfig) GetAllowedLabels() []string { + if o == nil { + var ret []string + return ret + } + + return o.AllowedLabels +} + +// GetAllowedLabelsOk returns a tuple with the AllowedLabels field value +// and a boolean to check if the value has been set. +func (o *LogsRuntimeConfig) GetAllowedLabelsOk() ([]string, bool) { + if o == nil { + return nil, false + } + return o.AllowedLabels, true +} + +// SetAllowedLabels sets field value +func (o *LogsRuntimeConfig) SetAllowedLabels(v []string) { + o.AllowedLabels = v +} + +func (o LogsRuntimeConfig) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o LogsRuntimeConfig) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["push_url"] = o.PushUrl + toSerialize["tail_url"] = o.TailUrl + toSerialize["limit"] = o.Limit + toSerialize["push_period_seconds"] = o.PushPeriodSeconds + toSerialize["level"] = o.Level + toSerialize["message_max_size"] = o.MessageMaxSize + toSerialize["allowed_labels"] = o.AllowedLabels + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *LogsRuntimeConfig) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "push_url", + "tail_url", + "limit", + "push_period_seconds", + "level", + "message_max_size", + "allowed_labels", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err + } + + for _, requiredProperty := range requiredProperties { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varLogsRuntimeConfig := _LogsRuntimeConfig{} + + err = json.Unmarshal(data, &varLogsRuntimeConfig) + + if err != nil { + return err + } + + *o = LogsRuntimeConfig(varLogsRuntimeConfig) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(data, &additionalProperties); err == nil { + delete(additionalProperties, "push_url") + delete(additionalProperties, "tail_url") + delete(additionalProperties, "limit") + delete(additionalProperties, "push_period_seconds") + delete(additionalProperties, "level") + delete(additionalProperties, "message_max_size") + delete(additionalProperties, "allowed_labels") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableLogsRuntimeConfig struct { + value *LogsRuntimeConfig + isSet bool +} + +func (v NullableLogsRuntimeConfig) Get() *LogsRuntimeConfig { + return v.value +} + +func (v *NullableLogsRuntimeConfig) Set(val *LogsRuntimeConfig) { + v.value = val + v.isSet = true +} + +func (v NullableLogsRuntimeConfig) IsSet() bool { + return v.isSet +} + +func (v *NullableLogsRuntimeConfig) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableLogsRuntimeConfig(val *LogsRuntimeConfig) *NullableLogsRuntimeConfig { + return &NullableLogsRuntimeConfig{value: val, isSet: true} +} + +func (v NullableLogsRuntimeConfig) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableLogsRuntimeConfig) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_metrics_runtime_config.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_metrics_runtime_config.go new file mode 100644 index 000000000..77d1fd39a --- /dev/null +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_metrics_runtime_config.go @@ -0,0 +1,360 @@ +/* +Grafana Cloud k6 + +HTTP API for interacting with Grafana Cloud k6. + +API version: 1.12.0 +Contact: info@grafana.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package k6 + +import ( + "encoding/json" + "fmt" +) + +// checks if the MetricsRuntimeConfig type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &MetricsRuntimeConfig{} + +// MetricsRuntimeConfig Metrics push runtime configuration. +type MetricsRuntimeConfig struct { + // URL to push metrics to. + PushUrl string `json:"push_url"` + // The time interval between periodic API calls for sending samples to the cloud ingest service. + PushInterval NullableString `json:"push_interval"` + // How many concurrent pushes will be done at the same time to the cloud. + PushConcurrency NullableInt32 `json:"push_concurrency"` + // If specified and is greater than 0, sample aggregation with that period is enabled. + AggregationPeriod NullableString `json:"aggregation_period"` + // If aggregation is enabled, this specifies how long we'll wait for period samples to accumulate before trying to aggregate them. + AggregationWaitPeriod NullableString `json:"aggregation_wait_period"` + // The minimum number of samples to aggregate. + AggregationMinSamples NullableInt32 `json:"aggregation_min_samples"` + // The max allowed number of time series in a single batch. + MaxSamplesPerPackage NullableInt32 `json:"max_samples_per_package"` + AdditionalProperties map[string]interface{} +} + +type _MetricsRuntimeConfig MetricsRuntimeConfig + +// NewMetricsRuntimeConfig instantiates a new MetricsRuntimeConfig object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewMetricsRuntimeConfig(pushUrl string, pushInterval NullableString, pushConcurrency NullableInt32, aggregationPeriod NullableString, aggregationWaitPeriod NullableString, aggregationMinSamples NullableInt32, maxSamplesPerPackage NullableInt32) *MetricsRuntimeConfig { + this := MetricsRuntimeConfig{} + this.PushUrl = pushUrl + this.PushInterval = pushInterval + this.PushConcurrency = pushConcurrency + this.AggregationPeriod = aggregationPeriod + this.AggregationWaitPeriod = aggregationWaitPeriod + this.AggregationMinSamples = aggregationMinSamples + this.MaxSamplesPerPackage = maxSamplesPerPackage + return &this +} + +// NewMetricsRuntimeConfigWithDefaults instantiates a new MetricsRuntimeConfig object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewMetricsRuntimeConfigWithDefaults() *MetricsRuntimeConfig { + this := MetricsRuntimeConfig{} + return &this +} + +// GetPushUrl returns the PushUrl field value +func (o *MetricsRuntimeConfig) GetPushUrl() string { + if o == nil { + var ret string + return ret + } + + return o.PushUrl +} + +// GetPushUrlOk returns a tuple with the PushUrl field value +// and a boolean to check if the value has been set. +func (o *MetricsRuntimeConfig) GetPushUrlOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.PushUrl, true +} + +// SetPushUrl sets field value +func (o *MetricsRuntimeConfig) SetPushUrl(v string) { + o.PushUrl = v +} + +// GetPushInterval returns the PushInterval field value +// If the value is explicit nil, the zero value for string will be returned +func (o *MetricsRuntimeConfig) GetPushInterval() string { + if o == nil || o.PushInterval.Get() == nil { + var ret string + return ret + } + + return *o.PushInterval.Get() +} + +// GetPushIntervalOk returns a tuple with the PushInterval field value +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *MetricsRuntimeConfig) GetPushIntervalOk() (*string, bool) { + if o == nil { + return nil, false + } + return o.PushInterval.Get(), o.PushInterval.IsSet() +} + +// SetPushInterval sets field value +func (o *MetricsRuntimeConfig) SetPushInterval(v string) { + o.PushInterval.Set(&v) +} + +// GetPushConcurrency returns the PushConcurrency field value +// If the value is explicit nil, the zero value for int32 will be returned +func (o *MetricsRuntimeConfig) GetPushConcurrency() int32 { + if o == nil || o.PushConcurrency.Get() == nil { + var ret int32 + return ret + } + + return *o.PushConcurrency.Get() +} + +// GetPushConcurrencyOk returns a tuple with the PushConcurrency field value +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *MetricsRuntimeConfig) GetPushConcurrencyOk() (*int32, bool) { + if o == nil { + return nil, false + } + return o.PushConcurrency.Get(), o.PushConcurrency.IsSet() +} + +// SetPushConcurrency sets field value +func (o *MetricsRuntimeConfig) SetPushConcurrency(v int32) { + o.PushConcurrency.Set(&v) +} + +// GetAggregationPeriod returns the AggregationPeriod field value +// If the value is explicit nil, the zero value for string will be returned +func (o *MetricsRuntimeConfig) GetAggregationPeriod() string { + if o == nil || o.AggregationPeriod.Get() == nil { + var ret string + return ret + } + + return *o.AggregationPeriod.Get() +} + +// GetAggregationPeriodOk returns a tuple with the AggregationPeriod field value +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *MetricsRuntimeConfig) GetAggregationPeriodOk() (*string, bool) { + if o == nil { + return nil, false + } + return o.AggregationPeriod.Get(), o.AggregationPeriod.IsSet() +} + +// SetAggregationPeriod sets field value +func (o *MetricsRuntimeConfig) SetAggregationPeriod(v string) { + o.AggregationPeriod.Set(&v) +} + +// GetAggregationWaitPeriod returns the AggregationWaitPeriod field value +// If the value is explicit nil, the zero value for string will be returned +func (o *MetricsRuntimeConfig) GetAggregationWaitPeriod() string { + if o == nil || o.AggregationWaitPeriod.Get() == nil { + var ret string + return ret + } + + return *o.AggregationWaitPeriod.Get() +} + +// GetAggregationWaitPeriodOk returns a tuple with the AggregationWaitPeriod field value +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *MetricsRuntimeConfig) GetAggregationWaitPeriodOk() (*string, bool) { + if o == nil { + return nil, false + } + return o.AggregationWaitPeriod.Get(), o.AggregationWaitPeriod.IsSet() +} + +// SetAggregationWaitPeriod sets field value +func (o *MetricsRuntimeConfig) SetAggregationWaitPeriod(v string) { + o.AggregationWaitPeriod.Set(&v) +} + +// GetAggregationMinSamples returns the AggregationMinSamples field value +// If the value is explicit nil, the zero value for int32 will be returned +func (o *MetricsRuntimeConfig) GetAggregationMinSamples() int32 { + if o == nil || o.AggregationMinSamples.Get() == nil { + var ret int32 + return ret + } + + return *o.AggregationMinSamples.Get() +} + +// GetAggregationMinSamplesOk returns a tuple with the AggregationMinSamples field value +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *MetricsRuntimeConfig) GetAggregationMinSamplesOk() (*int32, bool) { + if o == nil { + return nil, false + } + return o.AggregationMinSamples.Get(), o.AggregationMinSamples.IsSet() +} + +// SetAggregationMinSamples sets field value +func (o *MetricsRuntimeConfig) SetAggregationMinSamples(v int32) { + o.AggregationMinSamples.Set(&v) +} + +// GetMaxSamplesPerPackage returns the MaxSamplesPerPackage field value +// If the value is explicit nil, the zero value for int32 will be returned +func (o *MetricsRuntimeConfig) GetMaxSamplesPerPackage() int32 { + if o == nil || o.MaxSamplesPerPackage.Get() == nil { + var ret int32 + return ret + } + + return *o.MaxSamplesPerPackage.Get() +} + +// GetMaxSamplesPerPackageOk returns a tuple with the MaxSamplesPerPackage field value +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *MetricsRuntimeConfig) GetMaxSamplesPerPackageOk() (*int32, bool) { + if o == nil { + return nil, false + } + return o.MaxSamplesPerPackage.Get(), o.MaxSamplesPerPackage.IsSet() +} + +// SetMaxSamplesPerPackage sets field value +func (o *MetricsRuntimeConfig) SetMaxSamplesPerPackage(v int32) { + o.MaxSamplesPerPackage.Set(&v) +} + +func (o MetricsRuntimeConfig) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o MetricsRuntimeConfig) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["push_url"] = o.PushUrl + toSerialize["push_interval"] = o.PushInterval.Get() + toSerialize["push_concurrency"] = o.PushConcurrency.Get() + toSerialize["aggregation_period"] = o.AggregationPeriod.Get() + toSerialize["aggregation_wait_period"] = o.AggregationWaitPeriod.Get() + toSerialize["aggregation_min_samples"] = o.AggregationMinSamples.Get() + toSerialize["max_samples_per_package"] = o.MaxSamplesPerPackage.Get() + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *MetricsRuntimeConfig) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "push_url", + "push_interval", + "push_concurrency", + "aggregation_period", + "aggregation_wait_period", + "aggregation_min_samples", + "max_samples_per_package", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err + } + + for _, requiredProperty := range requiredProperties { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varMetricsRuntimeConfig := _MetricsRuntimeConfig{} + + err = json.Unmarshal(data, &varMetricsRuntimeConfig) + + if err != nil { + return err + } + + *o = MetricsRuntimeConfig(varMetricsRuntimeConfig) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(data, &additionalProperties); err == nil { + delete(additionalProperties, "push_url") + delete(additionalProperties, "push_interval") + delete(additionalProperties, "push_concurrency") + delete(additionalProperties, "aggregation_period") + delete(additionalProperties, "aggregation_wait_period") + delete(additionalProperties, "aggregation_min_samples") + delete(additionalProperties, "max_samples_per_package") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableMetricsRuntimeConfig struct { + value *MetricsRuntimeConfig + isSet bool +} + +func (v NullableMetricsRuntimeConfig) Get() *MetricsRuntimeConfig { + return v.value +} + +func (v *NullableMetricsRuntimeConfig) Set(val *MetricsRuntimeConfig) { + v.value = val + v.isSet = true +} + +func (v NullableMetricsRuntimeConfig) IsSet() bool { + return v.isSet +} + +func (v *NullableMetricsRuntimeConfig) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableMetricsRuntimeConfig(val *MetricsRuntimeConfig) *NullableMetricsRuntimeConfig { + return &NullableMetricsRuntimeConfig{value: val, isSet: true} +} + +func (v NullableMetricsRuntimeConfig) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableMetricsRuntimeConfig) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_move_load_test_api_model.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_move_load_test_api_model.go index bde1cd684..096ccf66f 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_move_load_test_api_model.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_move_load_test_api_model.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ @@ -12,7 +12,6 @@ Contact: info@grafana.com package k6 import ( - "bytes" "encoding/json" "fmt" ) @@ -23,7 +22,8 @@ var _ MappedNullable = &MoveLoadTestApiModel{} // MoveLoadTestApiModel struct for MoveLoadTestApiModel type MoveLoadTestApiModel struct { // ID of the destination project. - ProjectId int32 `json:"project_id"` + ProjectId int64 `json:"project_id"` + AdditionalProperties map[string]interface{} } type _MoveLoadTestApiModel MoveLoadTestApiModel @@ -32,7 +32,7 @@ type _MoveLoadTestApiModel MoveLoadTestApiModel // This constructor will assign default values to properties that have it defined, // and makes sure properties required by API are set, but the set of arguments // will change when the set of required properties is changed -func NewMoveLoadTestApiModel(projectId int32) *MoveLoadTestApiModel { +func NewMoveLoadTestApiModel(projectId int64) *MoveLoadTestApiModel { this := MoveLoadTestApiModel{} this.ProjectId = projectId return &this @@ -47,9 +47,9 @@ func NewMoveLoadTestApiModelWithDefaults() *MoveLoadTestApiModel { } // GetProjectId returns the ProjectId field value -func (o *MoveLoadTestApiModel) GetProjectId() int32 { +func (o *MoveLoadTestApiModel) GetProjectId() int64 { if o == nil { - var ret int32 + var ret int64 return ret } @@ -58,7 +58,7 @@ func (o *MoveLoadTestApiModel) GetProjectId() int32 { // GetProjectIdOk returns a tuple with the ProjectId field value // and a boolean to check if the value has been set. -func (o *MoveLoadTestApiModel) GetProjectIdOk() (*int32, bool) { +func (o *MoveLoadTestApiModel) GetProjectIdOk() (*int64, bool) { if o == nil { return nil, false } @@ -66,7 +66,7 @@ func (o *MoveLoadTestApiModel) GetProjectIdOk() (*int32, bool) { } // SetProjectId sets field value -func (o *MoveLoadTestApiModel) SetProjectId(v int32) { +func (o *MoveLoadTestApiModel) SetProjectId(v int64) { o.ProjectId = v } @@ -81,6 +81,11 @@ func (o MoveLoadTestApiModel) MarshalJSON() ([]byte, error) { func (o MoveLoadTestApiModel) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} toSerialize["project_id"] = o.ProjectId + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return toSerialize, nil } @@ -108,9 +113,7 @@ func (o *MoveLoadTestApiModel) UnmarshalJSON(data []byte) (err error) { varMoveLoadTestApiModel := _MoveLoadTestApiModel{} - decoder := json.NewDecoder(bytes.NewReader(data)) - decoder.DisallowUnknownFields() - err = decoder.Decode(&varMoveLoadTestApiModel) + err = json.Unmarshal(data, &varMoveLoadTestApiModel) if err != nil { return err @@ -118,6 +121,13 @@ func (o *MoveLoadTestApiModel) UnmarshalJSON(data []byte) (err error) { *o = MoveLoadTestApiModel(varMoveLoadTestApiModel) + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(data, &additionalProperties); err == nil { + delete(additionalProperties, "project_id") + o.AdditionalProperties = additionalProperties + } + return err } diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_node_api_model.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_node_api_model.go index 782d793a5..f468bc29e 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_node_api_model.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_node_api_model.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_options.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_options.go index 1865374dc..7916548ae 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_options.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_options.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_options_cloud.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_options_cloud.go index 4dfddeaac..47b2bd431 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_options_cloud.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_options_cloud.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_patch_load_test_api_model.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_patch_load_test_api_model.go index 6b7b8319a..2ad299cc8 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_patch_load_test_api_model.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_patch_load_test_api_model.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ @@ -22,10 +22,16 @@ var _ MappedNullable = &PatchLoadTestApiModel{} type PatchLoadTestApiModel struct { // Unique name of the test within the project. Name *string `json:"name,omitempty"` - // ID of a baseline test run used for results comparison. - BaselineTestRunId NullableInt32 `json:"baseline_test_run_id,omitempty"` + // ID of a baseline test run used for results comparison. Deprecated: baselines are being replaced by the star/unstar test run APIs and this field is scheduled for removal on 2026-09-01. + // Deprecated + BaselineTestRunId NullableInt64 `json:"baseline_test_run_id,omitempty"` + // Identifier of the k6 version used to run the test. + K6Version NullableInt32 `json:"k6_version,omitempty"` + AdditionalProperties map[string]interface{} } +type _PatchLoadTestApiModel PatchLoadTestApiModel + // NewPatchLoadTestApiModel instantiates a new PatchLoadTestApiModel object // This constructor will assign default values to properties that have it defined, // and makes sure properties required by API are set, but the set of arguments @@ -76,9 +82,10 @@ func (o *PatchLoadTestApiModel) SetName(v string) { } // GetBaselineTestRunId returns the BaselineTestRunId field value if set, zero value otherwise (both if not set or set to explicit null). -func (o *PatchLoadTestApiModel) GetBaselineTestRunId() int32 { +// Deprecated +func (o *PatchLoadTestApiModel) GetBaselineTestRunId() int64 { if o == nil || IsNil(o.BaselineTestRunId.Get()) { - var ret int32 + var ret int64 return ret } return *o.BaselineTestRunId.Get() @@ -87,7 +94,8 @@ func (o *PatchLoadTestApiModel) GetBaselineTestRunId() int32 { // GetBaselineTestRunIdOk returns a tuple with the BaselineTestRunId field value if set, nil otherwise // and a boolean to check if the value has been set. // NOTE: If the value is an explicit nil, `nil, true` will be returned -func (o *PatchLoadTestApiModel) GetBaselineTestRunIdOk() (*int32, bool) { +// Deprecated +func (o *PatchLoadTestApiModel) GetBaselineTestRunIdOk() (*int64, bool) { if o == nil { return nil, false } @@ -103,8 +111,9 @@ func (o *PatchLoadTestApiModel) HasBaselineTestRunId() bool { return false } -// SetBaselineTestRunId gets a reference to the given NullableInt32 and assigns it to the BaselineTestRunId field. -func (o *PatchLoadTestApiModel) SetBaselineTestRunId(v int32) { +// SetBaselineTestRunId gets a reference to the given NullableInt64 and assigns it to the BaselineTestRunId field. +// Deprecated +func (o *PatchLoadTestApiModel) SetBaselineTestRunId(v int64) { o.BaselineTestRunId.Set(&v) } @@ -118,6 +127,49 @@ func (o *PatchLoadTestApiModel) UnsetBaselineTestRunId() { o.BaselineTestRunId.Unset() } +// GetK6Version returns the K6Version field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *PatchLoadTestApiModel) GetK6Version() int32 { + if o == nil || IsNil(o.K6Version.Get()) { + var ret int32 + return ret + } + return *o.K6Version.Get() +} + +// GetK6VersionOk returns a tuple with the K6Version field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *PatchLoadTestApiModel) GetK6VersionOk() (*int32, bool) { + if o == nil { + return nil, false + } + return o.K6Version.Get(), o.K6Version.IsSet() +} + +// HasK6Version returns a boolean if a field has been set. +func (o *PatchLoadTestApiModel) HasK6Version() bool { + if o != nil && o.K6Version.IsSet() { + return true + } + + return false +} + +// SetK6Version gets a reference to the given NullableInt32 and assigns it to the K6Version field. +func (o *PatchLoadTestApiModel) SetK6Version(v int32) { + o.K6Version.Set(&v) +} + +// SetK6VersionNil sets the value for K6Version to be an explicit nil +func (o *PatchLoadTestApiModel) SetK6VersionNil() { + o.K6Version.Set(nil) +} + +// UnsetK6Version ensures that no value is present for K6Version, not even an explicit nil +func (o *PatchLoadTestApiModel) UnsetK6Version() { + o.K6Version.Unset() +} + func (o PatchLoadTestApiModel) MarshalJSON() ([]byte, error) { toSerialize, err := o.ToMap() if err != nil { @@ -134,9 +186,40 @@ func (o PatchLoadTestApiModel) ToMap() (map[string]interface{}, error) { if o.BaselineTestRunId.IsSet() { toSerialize["baseline_test_run_id"] = o.BaselineTestRunId.Get() } + if o.K6Version.IsSet() { + toSerialize["k6_version"] = o.K6Version.Get() + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return toSerialize, nil } +func (o *PatchLoadTestApiModel) UnmarshalJSON(data []byte) (err error) { + varPatchLoadTestApiModel := _PatchLoadTestApiModel{} + + err = json.Unmarshal(data, &varPatchLoadTestApiModel) + + if err != nil { + return err + } + + *o = PatchLoadTestApiModel(varPatchLoadTestApiModel) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(data, &additionalProperties); err == nil { + delete(additionalProperties, "name") + delete(additionalProperties, "baseline_test_run_id") + delete(additionalProperties, "k6_version") + o.AdditionalProperties = additionalProperties + } + + return err +} + type NullablePatchLoadTestApiModel struct { value *PatchLoadTestApiModel isSet bool diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_patch_project_api_model.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_patch_project_api_model.go index 0721011c0..65467645b 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_patch_project_api_model.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_patch_project_api_model.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ @@ -12,7 +12,6 @@ Contact: info@grafana.com package k6 import ( - "bytes" "encoding/json" "fmt" ) @@ -23,7 +22,8 @@ var _ MappedNullable = &PatchProjectApiModel{} // PatchProjectApiModel struct for PatchProjectApiModel type PatchProjectApiModel struct { // Project name. - Name string `json:"name"` + Name string `json:"name"` + AdditionalProperties map[string]interface{} } type _PatchProjectApiModel PatchProjectApiModel @@ -81,6 +81,11 @@ func (o PatchProjectApiModel) MarshalJSON() ([]byte, error) { func (o PatchProjectApiModel) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} toSerialize["name"] = o.Name + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return toSerialize, nil } @@ -108,9 +113,7 @@ func (o *PatchProjectApiModel) UnmarshalJSON(data []byte) (err error) { varPatchProjectApiModel := _PatchProjectApiModel{} - decoder := json.NewDecoder(bytes.NewReader(data)) - decoder.DisallowUnknownFields() - err = decoder.Decode(&varPatchProjectApiModel) + err = json.Unmarshal(data, &varPatchProjectApiModel) if err != nil { return err @@ -118,6 +121,13 @@ func (o *PatchProjectApiModel) UnmarshalJSON(data []byte) (err error) { *o = PatchProjectApiModel(varPatchProjectApiModel) + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(data, &additionalProperties); err == nil { + delete(additionalProperties, "name") + o.AdditionalProperties = additionalProperties + } + return err } diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_patch_project_limits_request.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_patch_project_limits_request.go index f0593f525..418eead1a 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_patch_project_limits_request.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_patch_project_limits_request.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ @@ -27,9 +27,12 @@ type PatchProjectLimitsRequest struct { // Max number of concurrent browser virtual users (VUs) used in one test. VuBrowserMaxPerTest NullableInt32 `json:"vu_browser_max_per_test,omitempty"` // Max duration of a test in seconds. - DurationMaxPerTest NullableInt32 `json:"duration_max_per_test,omitempty"` + DurationMaxPerTest NullableInt32 `json:"duration_max_per_test,omitempty"` + AdditionalProperties map[string]interface{} } +type _PatchProjectLimitsRequest PatchProjectLimitsRequest + // NewPatchProjectLimitsRequest instantiates a new PatchProjectLimitsRequest object // This constructor will assign default values to properties that have it defined, // and makes sure properties required by API are set, but the set of arguments @@ -241,9 +244,38 @@ func (o PatchProjectLimitsRequest) ToMap() (map[string]interface{}, error) { if o.DurationMaxPerTest.IsSet() { toSerialize["duration_max_per_test"] = o.DurationMaxPerTest.Get() } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return toSerialize, nil } +func (o *PatchProjectLimitsRequest) UnmarshalJSON(data []byte) (err error) { + varPatchProjectLimitsRequest := _PatchProjectLimitsRequest{} + + err = json.Unmarshal(data, &varPatchProjectLimitsRequest) + + if err != nil { + return err + } + + *o = PatchProjectLimitsRequest(varPatchProjectLimitsRequest) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(data, &additionalProperties); err == nil { + delete(additionalProperties, "vuh_max_per_month") + delete(additionalProperties, "vu_max_per_test") + delete(additionalProperties, "vu_browser_max_per_test") + delete(additionalProperties, "duration_max_per_test") + o.AdditionalProperties = additionalProperties + } + + return err +} + type NullablePatchProjectLimitsRequest struct { value *PatchProjectLimitsRequest isSet bool diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_patch_test_run_api_model.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_patch_test_run_api_model.go index 0209c2f6a..e15790c36 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_patch_test_run_api_model.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_patch_test_run_api_model.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ @@ -12,7 +12,6 @@ Contact: info@grafana.com package k6 import ( - "bytes" "encoding/json" "fmt" ) @@ -23,7 +22,8 @@ var _ MappedNullable = &PatchTestRunApiModel{} // PatchTestRunApiModel struct for PatchTestRunApiModel type PatchTestRunApiModel struct { // User-defined note for the test run. - Note string `json:"note"` + Note string `json:"note"` + AdditionalProperties map[string]interface{} } type _PatchTestRunApiModel PatchTestRunApiModel @@ -81,6 +81,11 @@ func (o PatchTestRunApiModel) MarshalJSON() ([]byte, error) { func (o PatchTestRunApiModel) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} toSerialize["note"] = o.Note + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return toSerialize, nil } @@ -108,9 +113,7 @@ func (o *PatchTestRunApiModel) UnmarshalJSON(data []byte) (err error) { varPatchTestRunApiModel := _PatchTestRunApiModel{} - decoder := json.NewDecoder(bytes.NewReader(data)) - decoder.DisallowUnknownFields() - err = decoder.Decode(&varPatchTestRunApiModel) + err = json.Unmarshal(data, &varPatchTestRunApiModel) if err != nil { return err @@ -118,6 +121,13 @@ func (o *PatchTestRunApiModel) UnmarshalJSON(data []byte) (err error) { *o = PatchTestRunApiModel(varPatchTestRunApiModel) + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(data, &additionalProperties); err == nil { + delete(additionalProperties, "note") + o.AdditionalProperties = additionalProperties + } + return err } diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_project_api_model.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_project_api_model.go index d8aaad65b..c360b0620 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_project_api_model.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_project_api_model.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ @@ -23,7 +23,7 @@ var _ MappedNullable = &ProjectApiModel{} // ProjectApiModel struct for ProjectApiModel type ProjectApiModel struct { // Project ID. - Id int32 `json:"id"` + Id int64 `json:"id"` // Project name. Name string `json:"name"` // Use this project as default for running tests when no explicit project ID is provided. @@ -45,7 +45,7 @@ type _ProjectApiModel ProjectApiModel // This constructor will assign default values to properties that have it defined, // and makes sure properties required by API are set, but the set of arguments // will change when the set of required properties is changed -func NewProjectApiModel(id int32, name string, isDefault bool, grafanaFolderUid NullableString, created time.Time, updated time.Time) *ProjectApiModel { +func NewProjectApiModel(id int64, name string, isDefault bool, grafanaFolderUid NullableString, created time.Time, updated time.Time) *ProjectApiModel { this := ProjectApiModel{} this.Id = id this.Name = name @@ -65,9 +65,9 @@ func NewProjectApiModelWithDefaults() *ProjectApiModel { } // GetId returns the Id field value -func (o *ProjectApiModel) GetId() int32 { +func (o *ProjectApiModel) GetId() int64 { if o == nil { - var ret int32 + var ret int64 return ret } @@ -76,7 +76,7 @@ func (o *ProjectApiModel) GetId() int32 { // GetIdOk returns a tuple with the Id field value // and a boolean to check if the value has been set. -func (o *ProjectApiModel) GetIdOk() (*int32, bool) { +func (o *ProjectApiModel) GetIdOk() (*int64, bool) { if o == nil { return nil, false } @@ -84,7 +84,7 @@ func (o *ProjectApiModel) GetIdOk() (*int32, bool) { } // SetId sets field value -func (o *ProjectApiModel) SetId(v int32) { +func (o *ProjectApiModel) SetId(v int64) { o.Id = v } diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_project_label_item.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_project_label_item.go index 28649d9f4..5355e0a43 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_project_label_item.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_project_label_item.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_project_label_list_response.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_project_label_list_response.go index b71591c9b..9626c2bd9 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_project_label_list_response.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_project_label_list_response.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_project_label_put_item.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_project_label_put_item.go index 4d6b0dbeb..038ee2227 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_project_label_put_item.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_project_label_put_item.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ @@ -22,7 +22,7 @@ var _ MappedNullable = &ProjectLabelPutItem{} // ProjectLabelPutItem Single project label for PUT request type ProjectLabelPutItem struct { // Label key ID. Mutually exclusive with 'key'. - KeyId NullableInt32 `json:"key_id,omitempty"` + KeyId NullableInt64 `json:"key_id,omitempty"` // Label key name. Mutually exclusive with 'key_id'. Key NullableString `json:"key,omitempty" validate:"regexp=^[^\\\\s'\\\\\\";\\\\\\\\%]+$"` // Label value. @@ -51,9 +51,9 @@ func NewProjectLabelPutItemWithDefaults() *ProjectLabelPutItem { } // GetKeyId returns the KeyId field value if set, zero value otherwise (both if not set or set to explicit null). -func (o *ProjectLabelPutItem) GetKeyId() int32 { +func (o *ProjectLabelPutItem) GetKeyId() int64 { if o == nil || IsNil(o.KeyId.Get()) { - var ret int32 + var ret int64 return ret } return *o.KeyId.Get() @@ -62,7 +62,7 @@ func (o *ProjectLabelPutItem) GetKeyId() int32 { // GetKeyIdOk returns a tuple with the KeyId field value if set, nil otherwise // and a boolean to check if the value has been set. // NOTE: If the value is an explicit nil, `nil, true` will be returned -func (o *ProjectLabelPutItem) GetKeyIdOk() (*int32, bool) { +func (o *ProjectLabelPutItem) GetKeyIdOk() (*int64, bool) { if o == nil { return nil, false } @@ -78,8 +78,8 @@ func (o *ProjectLabelPutItem) HasKeyId() bool { return false } -// SetKeyId gets a reference to the given NullableInt32 and assigns it to the KeyId field. -func (o *ProjectLabelPutItem) SetKeyId(v int32) { +// SetKeyId gets a reference to the given NullableInt64 and assigns it to the KeyId field. +func (o *ProjectLabelPutItem) SetKeyId(v int64) { o.KeyId.Set(&v) } diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_project_label_put_request.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_project_label_put_request.go index b7ff883ba..59c8a962a 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_project_label_put_request.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_project_label_put_request.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_project_label_put_response.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_project_label_put_response.go index e568b34be..08e9b48bd 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_project_label_put_response.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_project_label_put_response.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_project_label_put_response_item.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_project_label_put_response_item.go index 5c057a47e..86ad087ea 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_project_label_put_response_item.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_project_label_put_response_item.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ @@ -22,7 +22,7 @@ var _ MappedNullable = &ProjectLabelPutResponseItem{} // ProjectLabelPutResponseItem Single project label in PUT response type ProjectLabelPutResponseItem struct { // Label key ID. - KeyId int32 `json:"key_id"` + KeyId int64 `json:"key_id"` // Label key name. Key string `json:"key"` // Label value. @@ -36,7 +36,7 @@ type _ProjectLabelPutResponseItem ProjectLabelPutResponseItem // This constructor will assign default values to properties that have it defined, // and makes sure properties required by API are set, but the set of arguments // will change when the set of required properties is changed -func NewProjectLabelPutResponseItem(keyId int32, key string, value string) *ProjectLabelPutResponseItem { +func NewProjectLabelPutResponseItem(keyId int64, key string, value string) *ProjectLabelPutResponseItem { this := ProjectLabelPutResponseItem{} this.KeyId = keyId this.Key = key @@ -53,9 +53,9 @@ func NewProjectLabelPutResponseItemWithDefaults() *ProjectLabelPutResponseItem { } // GetKeyId returns the KeyId field value -func (o *ProjectLabelPutResponseItem) GetKeyId() int32 { +func (o *ProjectLabelPutResponseItem) GetKeyId() int64 { if o == nil { - var ret int32 + var ret int64 return ret } @@ -64,7 +64,7 @@ func (o *ProjectLabelPutResponseItem) GetKeyId() int32 { // GetKeyIdOk returns a tuple with the KeyId field value // and a boolean to check if the value has been set. -func (o *ProjectLabelPutResponseItem) GetKeyIdOk() (*int32, bool) { +func (o *ProjectLabelPutResponseItem) GetKeyIdOk() (*int64, bool) { if o == nil { return nil, false } @@ -72,7 +72,7 @@ func (o *ProjectLabelPutResponseItem) GetKeyIdOk() (*int32, bool) { } // SetKeyId sets field value -func (o *ProjectLabelPutResponseItem) SetKeyId(v int32) { +func (o *ProjectLabelPutResponseItem) SetKeyId(v int64) { o.KeyId = v } diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_project_limits_api_model.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_project_limits_api_model.go index e0db597ab..c46843942 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_project_limits_api_model.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_project_limits_api_model.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ @@ -22,7 +22,7 @@ var _ MappedNullable = &ProjectLimitsApiModel{} // ProjectLimitsApiModel struct for ProjectLimitsApiModel type ProjectLimitsApiModel struct { // ID of the related project. - ProjectId int32 `json:"project_id"` + ProjectId int64 `json:"project_id"` // Max amount of virtual user hours (VUH) used per one calendar month. VuhMaxPerMonth NullableInt32 `json:"vuh_max_per_month"` // Max number of concurrent virtual users (VUs) used in one test. @@ -40,7 +40,7 @@ type _ProjectLimitsApiModel ProjectLimitsApiModel // This constructor will assign default values to properties that have it defined, // and makes sure properties required by API are set, but the set of arguments // will change when the set of required properties is changed -func NewProjectLimitsApiModel(projectId int32, vuhMaxPerMonth NullableInt32, vuMaxPerTest NullableInt32, vuBrowserMaxPerTest NullableInt32, durationMaxPerTest NullableInt32) *ProjectLimitsApiModel { +func NewProjectLimitsApiModel(projectId int64, vuhMaxPerMonth NullableInt32, vuMaxPerTest NullableInt32, vuBrowserMaxPerTest NullableInt32, durationMaxPerTest NullableInt32) *ProjectLimitsApiModel { this := ProjectLimitsApiModel{} this.ProjectId = projectId this.VuhMaxPerMonth = vuhMaxPerMonth @@ -59,9 +59,9 @@ func NewProjectLimitsApiModelWithDefaults() *ProjectLimitsApiModel { } // GetProjectId returns the ProjectId field value -func (o *ProjectLimitsApiModel) GetProjectId() int32 { +func (o *ProjectLimitsApiModel) GetProjectId() int64 { if o == nil { - var ret int32 + var ret int64 return ret } @@ -70,7 +70,7 @@ func (o *ProjectLimitsApiModel) GetProjectId() int32 { // GetProjectIdOk returns a tuple with the ProjectId field value // and a boolean to check if the value has been set. -func (o *ProjectLimitsApiModel) GetProjectIdOk() (*int32, bool) { +func (o *ProjectLimitsApiModel) GetProjectIdOk() (*int64, bool) { if o == nil { return nil, false } @@ -78,7 +78,7 @@ func (o *ProjectLimitsApiModel) GetProjectIdOk() (*int32, bool) { } // SetProjectId sets field value -func (o *ProjectLimitsApiModel) SetProjectId(v int32) { +func (o *ProjectLimitsApiModel) SetProjectId(v int64) { o.ProjectId = v } diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_project_limits_list_response.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_project_limits_list_response.go index ed5d93de1..8250c79a0 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_project_limits_list_response.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_project_limits_list_response.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_project_list_response.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_project_list_response.go index f6f097da3..896834e3f 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_project_list_response.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_project_list_response.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_protocol_vuh.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_protocol_vuh.go index ecdb0bc55..3136c7b79 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_protocol_vuh.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_protocol_vuh.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_reduction_rate.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_reduction_rate.go index 131b297f2..c8a2c6d3b 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_reduction_rate.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_reduction_rate.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_reduction_rate_breakdown_value.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_reduction_rate_breakdown_value.go index 88156b3cb..11dfdad44 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_reduction_rate_breakdown_value.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_reduction_rate_breakdown_value.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_result_details_api_model.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_result_details_api_model.go new file mode 100644 index 000000000..564916ab2 --- /dev/null +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_result_details_api_model.go @@ -0,0 +1,266 @@ +/* +Grafana Cloud k6 + +HTTP API for interacting with Grafana Cloud k6. + +API version: 1.12.0 +Contact: info@grafana.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package k6 + +import ( + "encoding/json" + "fmt" +) + +// checks if the ResultDetailsApiModel type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &ResultDetailsApiModel{} + +// ResultDetailsApiModel struct for ResultDetailsApiModel +type ResultDetailsApiModel struct { + // Type of the result: `passed`, `failed` or `error`. + Type string `json:"type"` + // Human-readable description of why the test failed or the description of the error if applicable. + Message NullableString `json:"message,omitempty"` + // Service-defined error code if applicable. + Code NullableInt32 `json:"code,omitempty"` + AdditionalProperties map[string]interface{} +} + +type _ResultDetailsApiModel ResultDetailsApiModel + +// NewResultDetailsApiModel instantiates a new ResultDetailsApiModel object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewResultDetailsApiModel(type_ string) *ResultDetailsApiModel { + this := ResultDetailsApiModel{} + this.Type = type_ + return &this +} + +// NewResultDetailsApiModelWithDefaults instantiates a new ResultDetailsApiModel object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewResultDetailsApiModelWithDefaults() *ResultDetailsApiModel { + this := ResultDetailsApiModel{} + return &this +} + +// GetType returns the Type field value +func (o *ResultDetailsApiModel) GetType() string { + if o == nil { + var ret string + return ret + } + + return o.Type +} + +// GetTypeOk returns a tuple with the Type field value +// and a boolean to check if the value has been set. +func (o *ResultDetailsApiModel) GetTypeOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Type, true +} + +// SetType sets field value +func (o *ResultDetailsApiModel) SetType(v string) { + o.Type = v +} + +// GetMessage returns the Message field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *ResultDetailsApiModel) GetMessage() string { + if o == nil || IsNil(o.Message.Get()) { + var ret string + return ret + } + return *o.Message.Get() +} + +// GetMessageOk returns a tuple with the Message field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *ResultDetailsApiModel) GetMessageOk() (*string, bool) { + if o == nil { + return nil, false + } + return o.Message.Get(), o.Message.IsSet() +} + +// HasMessage returns a boolean if a field has been set. +func (o *ResultDetailsApiModel) HasMessage() bool { + if o != nil && o.Message.IsSet() { + return true + } + + return false +} + +// SetMessage gets a reference to the given NullableString and assigns it to the Message field. +func (o *ResultDetailsApiModel) SetMessage(v string) { + o.Message.Set(&v) +} + +// SetMessageNil sets the value for Message to be an explicit nil +func (o *ResultDetailsApiModel) SetMessageNil() { + o.Message.Set(nil) +} + +// UnsetMessage ensures that no value is present for Message, not even an explicit nil +func (o *ResultDetailsApiModel) UnsetMessage() { + o.Message.Unset() +} + +// GetCode returns the Code field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *ResultDetailsApiModel) GetCode() int32 { + if o == nil || IsNil(o.Code.Get()) { + var ret int32 + return ret + } + return *o.Code.Get() +} + +// GetCodeOk returns a tuple with the Code field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *ResultDetailsApiModel) GetCodeOk() (*int32, bool) { + if o == nil { + return nil, false + } + return o.Code.Get(), o.Code.IsSet() +} + +// HasCode returns a boolean if a field has been set. +func (o *ResultDetailsApiModel) HasCode() bool { + if o != nil && o.Code.IsSet() { + return true + } + + return false +} + +// SetCode gets a reference to the given NullableInt32 and assigns it to the Code field. +func (o *ResultDetailsApiModel) SetCode(v int32) { + o.Code.Set(&v) +} + +// SetCodeNil sets the value for Code to be an explicit nil +func (o *ResultDetailsApiModel) SetCodeNil() { + o.Code.Set(nil) +} + +// UnsetCode ensures that no value is present for Code, not even an explicit nil +func (o *ResultDetailsApiModel) UnsetCode() { + o.Code.Unset() +} + +func (o ResultDetailsApiModel) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o ResultDetailsApiModel) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["type"] = o.Type + if o.Message.IsSet() { + toSerialize["message"] = o.Message.Get() + } + if o.Code.IsSet() { + toSerialize["code"] = o.Code.Get() + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *ResultDetailsApiModel) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "type", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err + } + + for _, requiredProperty := range requiredProperties { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varResultDetailsApiModel := _ResultDetailsApiModel{} + + err = json.Unmarshal(data, &varResultDetailsApiModel) + + if err != nil { + return err + } + + *o = ResultDetailsApiModel(varResultDetailsApiModel) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(data, &additionalProperties); err == nil { + delete(additionalProperties, "type") + delete(additionalProperties, "message") + delete(additionalProperties, "code") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableResultDetailsApiModel struct { + value *ResultDetailsApiModel + isSet bool +} + +func (v NullableResultDetailsApiModel) Get() *ResultDetailsApiModel { + return v.value +} + +func (v *NullableResultDetailsApiModel) Set(val *ResultDetailsApiModel) { + v.value = val + v.isSet = true +} + +func (v NullableResultDetailsApiModel) IsSet() bool { + return v.isSet +} + +func (v *NullableResultDetailsApiModel) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableResultDetailsApiModel(val *ResultDetailsApiModel) *NullableResultDetailsApiModel { + return &NullableResultDetailsApiModel{value: val, isSet: true} +} + +func (v NullableResultDetailsApiModel) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableResultDetailsApiModel) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_runtime_config.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_runtime_config.go new file mode 100644 index 000000000..a1b71c03f --- /dev/null +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_runtime_config.go @@ -0,0 +1,313 @@ +/* +Grafana Cloud k6 + +HTTP API for interacting with Grafana Cloud k6. + +API version: 1.12.0 +Contact: info@grafana.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package k6 + +import ( + "encoding/json" + "fmt" +) + +// checks if the RuntimeConfig type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &RuntimeConfig{} + +// RuntimeConfig Runtime configuration override for the test run. +type RuntimeConfig struct { + Metrics MetricsRuntimeConfig `json:"metrics"` + Traces TracesRuntimeConfig `json:"traces"` + Files FilesRuntimeConfig `json:"files"` + Logs LogsRuntimeConfig `json:"logs"` + Secrets SecretsRuntimeConfig `json:"secrets"` + // The short-lived test run token. + TestRunToken string `json:"test_run_token"` + AdditionalProperties map[string]interface{} +} + +type _RuntimeConfig RuntimeConfig + +// NewRuntimeConfig instantiates a new RuntimeConfig object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewRuntimeConfig(metrics MetricsRuntimeConfig, traces TracesRuntimeConfig, files FilesRuntimeConfig, logs LogsRuntimeConfig, secrets SecretsRuntimeConfig, testRunToken string) *RuntimeConfig { + this := RuntimeConfig{} + this.Metrics = metrics + this.Traces = traces + this.Files = files + this.Logs = logs + this.Secrets = secrets + this.TestRunToken = testRunToken + return &this +} + +// NewRuntimeConfigWithDefaults instantiates a new RuntimeConfig object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewRuntimeConfigWithDefaults() *RuntimeConfig { + this := RuntimeConfig{} + return &this +} + +// GetMetrics returns the Metrics field value +func (o *RuntimeConfig) GetMetrics() MetricsRuntimeConfig { + if o == nil { + var ret MetricsRuntimeConfig + return ret + } + + return o.Metrics +} + +// GetMetricsOk returns a tuple with the Metrics field value +// and a boolean to check if the value has been set. +func (o *RuntimeConfig) GetMetricsOk() (*MetricsRuntimeConfig, bool) { + if o == nil { + return nil, false + } + return &o.Metrics, true +} + +// SetMetrics sets field value +func (o *RuntimeConfig) SetMetrics(v MetricsRuntimeConfig) { + o.Metrics = v +} + +// GetTraces returns the Traces field value +func (o *RuntimeConfig) GetTraces() TracesRuntimeConfig { + if o == nil { + var ret TracesRuntimeConfig + return ret + } + + return o.Traces +} + +// GetTracesOk returns a tuple with the Traces field value +// and a boolean to check if the value has been set. +func (o *RuntimeConfig) GetTracesOk() (*TracesRuntimeConfig, bool) { + if o == nil { + return nil, false + } + return &o.Traces, true +} + +// SetTraces sets field value +func (o *RuntimeConfig) SetTraces(v TracesRuntimeConfig) { + o.Traces = v +} + +// GetFiles returns the Files field value +func (o *RuntimeConfig) GetFiles() FilesRuntimeConfig { + if o == nil { + var ret FilesRuntimeConfig + return ret + } + + return o.Files +} + +// GetFilesOk returns a tuple with the Files field value +// and a boolean to check if the value has been set. +func (o *RuntimeConfig) GetFilesOk() (*FilesRuntimeConfig, bool) { + if o == nil { + return nil, false + } + return &o.Files, true +} + +// SetFiles sets field value +func (o *RuntimeConfig) SetFiles(v FilesRuntimeConfig) { + o.Files = v +} + +// GetLogs returns the Logs field value +func (o *RuntimeConfig) GetLogs() LogsRuntimeConfig { + if o == nil { + var ret LogsRuntimeConfig + return ret + } + + return o.Logs +} + +// GetLogsOk returns a tuple with the Logs field value +// and a boolean to check if the value has been set. +func (o *RuntimeConfig) GetLogsOk() (*LogsRuntimeConfig, bool) { + if o == nil { + return nil, false + } + return &o.Logs, true +} + +// SetLogs sets field value +func (o *RuntimeConfig) SetLogs(v LogsRuntimeConfig) { + o.Logs = v +} + +// GetSecrets returns the Secrets field value +func (o *RuntimeConfig) GetSecrets() SecretsRuntimeConfig { + if o == nil { + var ret SecretsRuntimeConfig + return ret + } + + return o.Secrets +} + +// GetSecretsOk returns a tuple with the Secrets field value +// and a boolean to check if the value has been set. +func (o *RuntimeConfig) GetSecretsOk() (*SecretsRuntimeConfig, bool) { + if o == nil { + return nil, false + } + return &o.Secrets, true +} + +// SetSecrets sets field value +func (o *RuntimeConfig) SetSecrets(v SecretsRuntimeConfig) { + o.Secrets = v +} + +// GetTestRunToken returns the TestRunToken field value +func (o *RuntimeConfig) GetTestRunToken() string { + if o == nil { + var ret string + return ret + } + + return o.TestRunToken +} + +// GetTestRunTokenOk returns a tuple with the TestRunToken field value +// and a boolean to check if the value has been set. +func (o *RuntimeConfig) GetTestRunTokenOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.TestRunToken, true +} + +// SetTestRunToken sets field value +func (o *RuntimeConfig) SetTestRunToken(v string) { + o.TestRunToken = v +} + +func (o RuntimeConfig) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o RuntimeConfig) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["metrics"] = o.Metrics + toSerialize["traces"] = o.Traces + toSerialize["files"] = o.Files + toSerialize["logs"] = o.Logs + toSerialize["secrets"] = o.Secrets + toSerialize["test_run_token"] = o.TestRunToken + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *RuntimeConfig) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "metrics", + "traces", + "files", + "logs", + "secrets", + "test_run_token", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err + } + + for _, requiredProperty := range requiredProperties { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varRuntimeConfig := _RuntimeConfig{} + + err = json.Unmarshal(data, &varRuntimeConfig) + + if err != nil { + return err + } + + *o = RuntimeConfig(varRuntimeConfig) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(data, &additionalProperties); err == nil { + delete(additionalProperties, "metrics") + delete(additionalProperties, "traces") + delete(additionalProperties, "files") + delete(additionalProperties, "logs") + delete(additionalProperties, "secrets") + delete(additionalProperties, "test_run_token") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableRuntimeConfig struct { + value *RuntimeConfig + isSet bool +} + +func (v NullableRuntimeConfig) Get() *RuntimeConfig { + return v.value +} + +func (v *NullableRuntimeConfig) Set(val *RuntimeConfig) { + v.value = val + v.isSet = true +} + +func (v NullableRuntimeConfig) IsSet() bool { + return v.isSet +} + +func (v *NullableRuntimeConfig) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableRuntimeConfig(val *RuntimeConfig) *NullableRuntimeConfig { + return &NullableRuntimeConfig{value: val, isSet: true} +} + +func (v NullableRuntimeConfig) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableRuntimeConfig) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_schedule_api_model.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_schedule_api_model.go index ae8409729..f3afa9d1a 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_schedule_api_model.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_schedule_api_model.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ @@ -23,9 +23,9 @@ var _ MappedNullable = &ScheduleApiModel{} // ScheduleApiModel struct for ScheduleApiModel type ScheduleApiModel struct { // ID of the schedule. - Id int32 `json:"id"` + Id int64 `json:"id"` // ID of the test to run. - LoadTestId int32 `json:"load_test_id"` + LoadTestId int64 `json:"load_test_id"` // The date on which the schedule will start running the test. Starts time.Time `json:"starts"` RecurrenceRule NullableScheduleRecurrenceRule `json:"recurrence_rule"` @@ -45,7 +45,7 @@ type _ScheduleApiModel ScheduleApiModel // This constructor will assign default values to properties that have it defined, // and makes sure properties required by API are set, but the set of arguments // will change when the set of required properties is changed -func NewScheduleApiModel(id int32, loadTestId int32, starts time.Time, recurrenceRule NullableScheduleRecurrenceRule, cron NullableScheduleCron, deactivated bool, nextRun NullableTime, createdBy NullableString) *ScheduleApiModel { +func NewScheduleApiModel(id int64, loadTestId int64, starts time.Time, recurrenceRule NullableScheduleRecurrenceRule, cron NullableScheduleCron, deactivated bool, nextRun NullableTime, createdBy NullableString) *ScheduleApiModel { this := ScheduleApiModel{} this.Id = id this.LoadTestId = loadTestId @@ -67,9 +67,9 @@ func NewScheduleApiModelWithDefaults() *ScheduleApiModel { } // GetId returns the Id field value -func (o *ScheduleApiModel) GetId() int32 { +func (o *ScheduleApiModel) GetId() int64 { if o == nil { - var ret int32 + var ret int64 return ret } @@ -78,7 +78,7 @@ func (o *ScheduleApiModel) GetId() int32 { // GetIdOk returns a tuple with the Id field value // and a boolean to check if the value has been set. -func (o *ScheduleApiModel) GetIdOk() (*int32, bool) { +func (o *ScheduleApiModel) GetIdOk() (*int64, bool) { if o == nil { return nil, false } @@ -86,14 +86,14 @@ func (o *ScheduleApiModel) GetIdOk() (*int32, bool) { } // SetId sets field value -func (o *ScheduleApiModel) SetId(v int32) { +func (o *ScheduleApiModel) SetId(v int64) { o.Id = v } // GetLoadTestId returns the LoadTestId field value -func (o *ScheduleApiModel) GetLoadTestId() int32 { +func (o *ScheduleApiModel) GetLoadTestId() int64 { if o == nil { - var ret int32 + var ret int64 return ret } @@ -102,7 +102,7 @@ func (o *ScheduleApiModel) GetLoadTestId() int32 { // GetLoadTestIdOk returns a tuple with the LoadTestId field value // and a boolean to check if the value has been set. -func (o *ScheduleApiModel) GetLoadTestIdOk() (*int32, bool) { +func (o *ScheduleApiModel) GetLoadTestIdOk() (*int64, bool) { if o == nil { return nil, false } @@ -110,7 +110,7 @@ func (o *ScheduleApiModel) GetLoadTestIdOk() (*int32, bool) { } // SetLoadTestId sets field value -func (o *ScheduleApiModel) SetLoadTestId(v int32) { +func (o *ScheduleApiModel) SetLoadTestId(v int64) { o.LoadTestId = v } diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_schedule_cron.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_schedule_cron.go index dddd065a0..62a133389 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_schedule_cron.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_schedule_cron.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_schedule_list_response.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_schedule_list_response.go index 819429acf..0e17a1829 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_schedule_list_response.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_schedule_list_response.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_schedule_recurrence_rule.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_schedule_recurrence_rule.go index c72d94d0d..0a2393cae 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_schedule_recurrence_rule.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_schedule_recurrence_rule.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_script_execution_completed_notification_api_model.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_script_execution_completed_notification_api_model.go new file mode 100644 index 000000000..6c575aa56 --- /dev/null +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_script_execution_completed_notification_api_model.go @@ -0,0 +1,216 @@ +/* +Grafana Cloud k6 + +HTTP API for interacting with Grafana Cloud k6. + +API version: 1.12.0 +Contact: info@grafana.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package k6 + +import ( + "encoding/json" + "fmt" +) + +// checks if the ScriptExecutionCompletedNotificationApiModel type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &ScriptExecutionCompletedNotificationApiModel{} + +// ScriptExecutionCompletedNotificationApiModel Request body for reporting a test run lifecycle event. +type ScriptExecutionCompletedNotificationApiModel struct { + // Event type. + EventType string `json:"event_type"` + Error NullableScriptExecutionError `json:"error,omitempty"` + AdditionalProperties map[string]interface{} +} + +type _ScriptExecutionCompletedNotificationApiModel ScriptExecutionCompletedNotificationApiModel + +// NewScriptExecutionCompletedNotificationApiModel instantiates a new ScriptExecutionCompletedNotificationApiModel object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewScriptExecutionCompletedNotificationApiModel(eventType string) *ScriptExecutionCompletedNotificationApiModel { + this := ScriptExecutionCompletedNotificationApiModel{} + this.EventType = eventType + return &this +} + +// NewScriptExecutionCompletedNotificationApiModelWithDefaults instantiates a new ScriptExecutionCompletedNotificationApiModel object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewScriptExecutionCompletedNotificationApiModelWithDefaults() *ScriptExecutionCompletedNotificationApiModel { + this := ScriptExecutionCompletedNotificationApiModel{} + return &this +} + +// GetEventType returns the EventType field value +func (o *ScriptExecutionCompletedNotificationApiModel) GetEventType() string { + if o == nil { + var ret string + return ret + } + + return o.EventType +} + +// GetEventTypeOk returns a tuple with the EventType field value +// and a boolean to check if the value has been set. +func (o *ScriptExecutionCompletedNotificationApiModel) GetEventTypeOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.EventType, true +} + +// SetEventType sets field value +func (o *ScriptExecutionCompletedNotificationApiModel) SetEventType(v string) { + o.EventType = v +} + +// GetError returns the Error field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *ScriptExecutionCompletedNotificationApiModel) GetError() ScriptExecutionError { + if o == nil || IsNil(o.Error.Get()) { + var ret ScriptExecutionError + return ret + } + return *o.Error.Get() +} + +// GetErrorOk returns a tuple with the Error field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *ScriptExecutionCompletedNotificationApiModel) GetErrorOk() (*ScriptExecutionError, bool) { + if o == nil { + return nil, false + } + return o.Error.Get(), o.Error.IsSet() +} + +// HasError returns a boolean if a field has been set. +func (o *ScriptExecutionCompletedNotificationApiModel) HasError() bool { + if o != nil && o.Error.IsSet() { + return true + } + + return false +} + +// SetError gets a reference to the given NullableScriptExecutionError and assigns it to the Error field. +func (o *ScriptExecutionCompletedNotificationApiModel) SetError(v ScriptExecutionError) { + o.Error.Set(&v) +} + +// SetErrorNil sets the value for Error to be an explicit nil +func (o *ScriptExecutionCompletedNotificationApiModel) SetErrorNil() { + o.Error.Set(nil) +} + +// UnsetError ensures that no value is present for Error, not even an explicit nil +func (o *ScriptExecutionCompletedNotificationApiModel) UnsetError() { + o.Error.Unset() +} + +func (o ScriptExecutionCompletedNotificationApiModel) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o ScriptExecutionCompletedNotificationApiModel) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["event_type"] = o.EventType + if o.Error.IsSet() { + toSerialize["error"] = o.Error.Get() + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *ScriptExecutionCompletedNotificationApiModel) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "event_type", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err + } + + for _, requiredProperty := range requiredProperties { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varScriptExecutionCompletedNotificationApiModel := _ScriptExecutionCompletedNotificationApiModel{} + + err = json.Unmarshal(data, &varScriptExecutionCompletedNotificationApiModel) + + if err != nil { + return err + } + + *o = ScriptExecutionCompletedNotificationApiModel(varScriptExecutionCompletedNotificationApiModel) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(data, &additionalProperties); err == nil { + delete(additionalProperties, "event_type") + delete(additionalProperties, "error") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableScriptExecutionCompletedNotificationApiModel struct { + value *ScriptExecutionCompletedNotificationApiModel + isSet bool +} + +func (v NullableScriptExecutionCompletedNotificationApiModel) Get() *ScriptExecutionCompletedNotificationApiModel { + return v.value +} + +func (v *NullableScriptExecutionCompletedNotificationApiModel) Set(val *ScriptExecutionCompletedNotificationApiModel) { + v.value = val + v.isSet = true +} + +func (v NullableScriptExecutionCompletedNotificationApiModel) IsSet() bool { + return v.isSet +} + +func (v *NullableScriptExecutionCompletedNotificationApiModel) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableScriptExecutionCompletedNotificationApiModel(val *ScriptExecutionCompletedNotificationApiModel) *NullableScriptExecutionCompletedNotificationApiModel { + return &NullableScriptExecutionCompletedNotificationApiModel{value: val, isSet: true} +} + +func (v NullableScriptExecutionCompletedNotificationApiModel) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableScriptExecutionCompletedNotificationApiModel) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_script_execution_error.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_script_execution_error.go new file mode 100644 index 000000000..b04c0e5ed --- /dev/null +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_script_execution_error.go @@ -0,0 +1,247 @@ +/* +Grafana Cloud k6 + +HTTP API for interacting with Grafana Cloud k6. + +API version: 1.12.0 +Contact: info@grafana.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package k6 + +import ( + "encoding/json" + "fmt" +) + +// checks if the ScriptExecutionError type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &ScriptExecutionError{} + +// ScriptExecutionError Error payload for a test run lifecycle event notification. +type ScriptExecutionError struct { + // Error code. + Code int32 `json:"code"` + // Human-readable error description shown to the user. + Reason string `json:"reason"` + // Optional internal debug information. + Detail NullableString `json:"detail,omitempty"` + AdditionalProperties map[string]interface{} +} + +type _ScriptExecutionError ScriptExecutionError + +// NewScriptExecutionError instantiates a new ScriptExecutionError object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewScriptExecutionError(code int32, reason string) *ScriptExecutionError { + this := ScriptExecutionError{} + this.Code = code + this.Reason = reason + return &this +} + +// NewScriptExecutionErrorWithDefaults instantiates a new ScriptExecutionError object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewScriptExecutionErrorWithDefaults() *ScriptExecutionError { + this := ScriptExecutionError{} + return &this +} + +// GetCode returns the Code field value +func (o *ScriptExecutionError) GetCode() int32 { + if o == nil { + var ret int32 + return ret + } + + return o.Code +} + +// GetCodeOk returns a tuple with the Code field value +// and a boolean to check if the value has been set. +func (o *ScriptExecutionError) GetCodeOk() (*int32, bool) { + if o == nil { + return nil, false + } + return &o.Code, true +} + +// SetCode sets field value +func (o *ScriptExecutionError) SetCode(v int32) { + o.Code = v +} + +// GetReason returns the Reason field value +func (o *ScriptExecutionError) GetReason() string { + if o == nil { + var ret string + return ret + } + + return o.Reason +} + +// GetReasonOk returns a tuple with the Reason field value +// and a boolean to check if the value has been set. +func (o *ScriptExecutionError) GetReasonOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Reason, true +} + +// SetReason sets field value +func (o *ScriptExecutionError) SetReason(v string) { + o.Reason = v +} + +// GetDetail returns the Detail field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *ScriptExecutionError) GetDetail() string { + if o == nil || IsNil(o.Detail.Get()) { + var ret string + return ret + } + return *o.Detail.Get() +} + +// GetDetailOk returns a tuple with the Detail field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *ScriptExecutionError) GetDetailOk() (*string, bool) { + if o == nil { + return nil, false + } + return o.Detail.Get(), o.Detail.IsSet() +} + +// HasDetail returns a boolean if a field has been set. +func (o *ScriptExecutionError) HasDetail() bool { + if o != nil && o.Detail.IsSet() { + return true + } + + return false +} + +// SetDetail gets a reference to the given NullableString and assigns it to the Detail field. +func (o *ScriptExecutionError) SetDetail(v string) { + o.Detail.Set(&v) +} + +// SetDetailNil sets the value for Detail to be an explicit nil +func (o *ScriptExecutionError) SetDetailNil() { + o.Detail.Set(nil) +} + +// UnsetDetail ensures that no value is present for Detail, not even an explicit nil +func (o *ScriptExecutionError) UnsetDetail() { + o.Detail.Unset() +} + +func (o ScriptExecutionError) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o ScriptExecutionError) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["code"] = o.Code + toSerialize["reason"] = o.Reason + if o.Detail.IsSet() { + toSerialize["detail"] = o.Detail.Get() + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *ScriptExecutionError) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "code", + "reason", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err + } + + for _, requiredProperty := range requiredProperties { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varScriptExecutionError := _ScriptExecutionError{} + + err = json.Unmarshal(data, &varScriptExecutionError) + + if err != nil { + return err + } + + *o = ScriptExecutionError(varScriptExecutionError) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(data, &additionalProperties); err == nil { + delete(additionalProperties, "code") + delete(additionalProperties, "reason") + delete(additionalProperties, "detail") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableScriptExecutionError struct { + value *ScriptExecutionError + isSet bool +} + +func (v NullableScriptExecutionError) Get() *ScriptExecutionError { + return v.value +} + +func (v *NullableScriptExecutionError) Set(val *ScriptExecutionError) { + v.value = val + v.isSet = true +} + +func (v NullableScriptExecutionError) IsSet() bool { + return v.isSet +} + +func (v *NullableScriptExecutionError) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableScriptExecutionError(val *ScriptExecutionError) *NullableScriptExecutionError { + return &NullableScriptExecutionError{value: val, isSet: true} +} + +func (v NullableScriptExecutionError) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableScriptExecutionError) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_secrets_runtime_config.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_secrets_runtime_config.go new file mode 100644 index 000000000..a85d1b966 --- /dev/null +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_secrets_runtime_config.go @@ -0,0 +1,198 @@ +/* +Grafana Cloud k6 + +HTTP API for interacting with Grafana Cloud k6. + +API version: 1.12.0 +Contact: info@grafana.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package k6 + +import ( + "encoding/json" + "fmt" +) + +// checks if the SecretsRuntimeConfig type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &SecretsRuntimeConfig{} + +// SecretsRuntimeConfig Secrets runtime configuration. +type SecretsRuntimeConfig struct { + // URL template for the secrets decrypt endpoint. + Endpoint string `json:"endpoint"` + // JSON path to extract the secret value from the response. + ResponsePath string `json:"response_path"` + AdditionalProperties map[string]interface{} +} + +type _SecretsRuntimeConfig SecretsRuntimeConfig + +// NewSecretsRuntimeConfig instantiates a new SecretsRuntimeConfig object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewSecretsRuntimeConfig(endpoint string, responsePath string) *SecretsRuntimeConfig { + this := SecretsRuntimeConfig{} + this.Endpoint = endpoint + this.ResponsePath = responsePath + return &this +} + +// NewSecretsRuntimeConfigWithDefaults instantiates a new SecretsRuntimeConfig object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewSecretsRuntimeConfigWithDefaults() *SecretsRuntimeConfig { + this := SecretsRuntimeConfig{} + return &this +} + +// GetEndpoint returns the Endpoint field value +func (o *SecretsRuntimeConfig) GetEndpoint() string { + if o == nil { + var ret string + return ret + } + + return o.Endpoint +} + +// GetEndpointOk returns a tuple with the Endpoint field value +// and a boolean to check if the value has been set. +func (o *SecretsRuntimeConfig) GetEndpointOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Endpoint, true +} + +// SetEndpoint sets field value +func (o *SecretsRuntimeConfig) SetEndpoint(v string) { + o.Endpoint = v +} + +// GetResponsePath returns the ResponsePath field value +func (o *SecretsRuntimeConfig) GetResponsePath() string { + if o == nil { + var ret string + return ret + } + + return o.ResponsePath +} + +// GetResponsePathOk returns a tuple with the ResponsePath field value +// and a boolean to check if the value has been set. +func (o *SecretsRuntimeConfig) GetResponsePathOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.ResponsePath, true +} + +// SetResponsePath sets field value +func (o *SecretsRuntimeConfig) SetResponsePath(v string) { + o.ResponsePath = v +} + +func (o SecretsRuntimeConfig) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o SecretsRuntimeConfig) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["endpoint"] = o.Endpoint + toSerialize["response_path"] = o.ResponsePath + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *SecretsRuntimeConfig) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "endpoint", + "response_path", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err + } + + for _, requiredProperty := range requiredProperties { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varSecretsRuntimeConfig := _SecretsRuntimeConfig{} + + err = json.Unmarshal(data, &varSecretsRuntimeConfig) + + if err != nil { + return err + } + + *o = SecretsRuntimeConfig(varSecretsRuntimeConfig) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(data, &additionalProperties); err == nil { + delete(additionalProperties, "endpoint") + delete(additionalProperties, "response_path") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableSecretsRuntimeConfig struct { + value *SecretsRuntimeConfig + isSet bool +} + +func (v NullableSecretsRuntimeConfig) Get() *SecretsRuntimeConfig { + return v.value +} + +func (v *NullableSecretsRuntimeConfig) Set(val *SecretsRuntimeConfig) { + v.value = val + v.isSet = true +} + +func (v NullableSecretsRuntimeConfig) IsSet() bool { + return v.isSet +} + +func (v *NullableSecretsRuntimeConfig) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableSecretsRuntimeConfig(val *SecretsRuntimeConfig) *NullableSecretsRuntimeConfig { + return &NullableSecretsRuntimeConfig{value: val, isSet: true} +} + +func (v NullableSecretsRuntimeConfig) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableSecretsRuntimeConfig) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_start_load_test_response.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_start_load_test_response.go index 4009360b8..72c6faab8 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_start_load_test_response.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_start_load_test_response.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ @@ -23,11 +23,11 @@ var _ MappedNullable = &StartLoadTestResponse{} // StartLoadTestResponse struct for StartLoadTestResponse type StartLoadTestResponse struct { // ID of the test run. - Id int32 `json:"id"` + Id int64 `json:"id"` // ID of the parent test. - TestId int32 `json:"test_id"` + TestId int64 `json:"test_id"` // ID of the parent project. - ProjectId int32 `json:"project_id"` + ProjectId int64 `json:"project_id"` // Email of the user who started the test if started with a user token. StartedBy NullableString `json:"started_by"` // Date and time when the test run was started. @@ -48,9 +48,8 @@ type StartLoadTestResponse struct { // List of the load zones configured for the test and the corresponding distribution percentages. Distribution []DistributionZoneApiModel `json:"distribution"` // Test run result. `passed` if there were no issues, `failed` if thresholds were breached, `error` if the execution was not completed. - Result NullableString `json:"result"` - // Additional information about the test run result. - ResultDetails map[string]interface{} `json:"result_details"` + Result NullableString `json:"result"` + ResultDetails NullableResultDetailsApiModel `json:"result_details"` // The original options object if available. Options map[string]interface{} `json:"options"` // The requested version of k6 and extensions that was part of the script/archive. @@ -65,6 +64,8 @@ type StartLoadTestResponse struct { EstimatedDuration NullableInt32 `json:"estimated_duration"` // The real billable duration of the test run in seconds. ExecutionDuration int32 `json:"execution_duration"` + // Whether the test run is starred for quick access. + IsStarred bool `json:"is_starred"` // URL to the Grafana web app test run page. TestRunDetailsPageUrl string `json:"test_run_details_page_url"` AdditionalProperties map[string]interface{} @@ -76,7 +77,7 @@ type _StartLoadTestResponse StartLoadTestResponse // This constructor will assign default values to properties that have it defined, // and makes sure properties required by API are set, but the set of arguments // will change when the set of required properties is changed -func NewStartLoadTestResponse(id int32, testId int32, projectId int32, startedBy NullableString, created time.Time, ended NullableTime, note string, retentionExpiry NullableTime, cost NullableTestCostApiModel, status string, statusDetails StatusApiModel, statusHistory []StatusApiModel, distribution []DistributionZoneApiModel, result NullableString, resultDetails map[string]interface{}, options map[string]interface{}, k6Dependencies map[string]string, k6Versions map[string]string, maxVus NullableInt32, maxBrowserVus NullableInt32, estimatedDuration NullableInt32, executionDuration int32, testRunDetailsPageUrl string) *StartLoadTestResponse { +func NewStartLoadTestResponse(id int64, testId int64, projectId int64, startedBy NullableString, created time.Time, ended NullableTime, note string, retentionExpiry NullableTime, cost NullableTestCostApiModel, status string, statusDetails StatusApiModel, statusHistory []StatusApiModel, distribution []DistributionZoneApiModel, result NullableString, resultDetails NullableResultDetailsApiModel, options map[string]interface{}, k6Dependencies map[string]string, k6Versions map[string]string, maxVus NullableInt32, maxBrowserVus NullableInt32, estimatedDuration NullableInt32, executionDuration int32, isStarred bool, testRunDetailsPageUrl string) *StartLoadTestResponse { this := StartLoadTestResponse{} this.Id = id this.TestId = testId @@ -100,6 +101,7 @@ func NewStartLoadTestResponse(id int32, testId int32, projectId int32, startedBy this.MaxBrowserVus = maxBrowserVus this.EstimatedDuration = estimatedDuration this.ExecutionDuration = executionDuration + this.IsStarred = isStarred this.TestRunDetailsPageUrl = testRunDetailsPageUrl return &this } @@ -113,9 +115,9 @@ func NewStartLoadTestResponseWithDefaults() *StartLoadTestResponse { } // GetId returns the Id field value -func (o *StartLoadTestResponse) GetId() int32 { +func (o *StartLoadTestResponse) GetId() int64 { if o == nil { - var ret int32 + var ret int64 return ret } @@ -124,7 +126,7 @@ func (o *StartLoadTestResponse) GetId() int32 { // GetIdOk returns a tuple with the Id field value // and a boolean to check if the value has been set. -func (o *StartLoadTestResponse) GetIdOk() (*int32, bool) { +func (o *StartLoadTestResponse) GetIdOk() (*int64, bool) { if o == nil { return nil, false } @@ -132,14 +134,14 @@ func (o *StartLoadTestResponse) GetIdOk() (*int32, bool) { } // SetId sets field value -func (o *StartLoadTestResponse) SetId(v int32) { +func (o *StartLoadTestResponse) SetId(v int64) { o.Id = v } // GetTestId returns the TestId field value -func (o *StartLoadTestResponse) GetTestId() int32 { +func (o *StartLoadTestResponse) GetTestId() int64 { if o == nil { - var ret int32 + var ret int64 return ret } @@ -148,7 +150,7 @@ func (o *StartLoadTestResponse) GetTestId() int32 { // GetTestIdOk returns a tuple with the TestId field value // and a boolean to check if the value has been set. -func (o *StartLoadTestResponse) GetTestIdOk() (*int32, bool) { +func (o *StartLoadTestResponse) GetTestIdOk() (*int64, bool) { if o == nil { return nil, false } @@ -156,14 +158,14 @@ func (o *StartLoadTestResponse) GetTestIdOk() (*int32, bool) { } // SetTestId sets field value -func (o *StartLoadTestResponse) SetTestId(v int32) { +func (o *StartLoadTestResponse) SetTestId(v int64) { o.TestId = v } // GetProjectId returns the ProjectId field value -func (o *StartLoadTestResponse) GetProjectId() int32 { +func (o *StartLoadTestResponse) GetProjectId() int64 { if o == nil { - var ret int32 + var ret int64 return ret } @@ -172,7 +174,7 @@ func (o *StartLoadTestResponse) GetProjectId() int32 { // GetProjectIdOk returns a tuple with the ProjectId field value // and a boolean to check if the value has been set. -func (o *StartLoadTestResponse) GetProjectIdOk() (*int32, bool) { +func (o *StartLoadTestResponse) GetProjectIdOk() (*int64, bool) { if o == nil { return nil, false } @@ -180,7 +182,7 @@ func (o *StartLoadTestResponse) GetProjectIdOk() (*int32, bool) { } // SetProjectId sets field value -func (o *StartLoadTestResponse) SetProjectId(v int32) { +func (o *StartLoadTestResponse) SetProjectId(v int64) { o.ProjectId = v } @@ -461,29 +463,29 @@ func (o *StartLoadTestResponse) SetResult(v string) { } // GetResultDetails returns the ResultDetails field value -// If the value is explicit nil, the zero value for map[string]interface{} will be returned -func (o *StartLoadTestResponse) GetResultDetails() map[string]interface{} { - if o == nil { - var ret map[string]interface{} +// If the value is explicit nil, the zero value for ResultDetailsApiModel will be returned +func (o *StartLoadTestResponse) GetResultDetails() ResultDetailsApiModel { + if o == nil || o.ResultDetails.Get() == nil { + var ret ResultDetailsApiModel return ret } - return o.ResultDetails + return *o.ResultDetails.Get() } // GetResultDetailsOk returns a tuple with the ResultDetails field value // and a boolean to check if the value has been set. // NOTE: If the value is an explicit nil, `nil, true` will be returned -func (o *StartLoadTestResponse) GetResultDetailsOk() (map[string]interface{}, bool) { - if o == nil || IsNil(o.ResultDetails) { - return map[string]interface{}{}, false +func (o *StartLoadTestResponse) GetResultDetailsOk() (*ResultDetailsApiModel, bool) { + if o == nil { + return nil, false } - return o.ResultDetails, true + return o.ResultDetails.Get(), o.ResultDetails.IsSet() } // SetResultDetails sets field value -func (o *StartLoadTestResponse) SetResultDetails(v map[string]interface{}) { - o.ResultDetails = v +func (o *StartLoadTestResponse) SetResultDetails(v ResultDetailsApiModel) { + o.ResultDetails.Set(&v) } // GetOptions returns the Options field value @@ -662,6 +664,30 @@ func (o *StartLoadTestResponse) SetExecutionDuration(v int32) { o.ExecutionDuration = v } +// GetIsStarred returns the IsStarred field value +func (o *StartLoadTestResponse) GetIsStarred() bool { + if o == nil { + var ret bool + return ret + } + + return o.IsStarred +} + +// GetIsStarredOk returns a tuple with the IsStarred field value +// and a boolean to check if the value has been set. +func (o *StartLoadTestResponse) GetIsStarredOk() (*bool, bool) { + if o == nil { + return nil, false + } + return &o.IsStarred, true +} + +// SetIsStarred sets field value +func (o *StartLoadTestResponse) SetIsStarred(v bool) { + o.IsStarred = v +} + // GetTestRunDetailsPageUrl returns the TestRunDetailsPageUrl field value func (o *StartLoadTestResponse) GetTestRunDetailsPageUrl() string { if o == nil { @@ -712,9 +738,7 @@ func (o StartLoadTestResponse) ToMap() (map[string]interface{}, error) { toSerialize["distribution"] = o.Distribution } toSerialize["result"] = o.Result.Get() - if o.ResultDetails != nil { - toSerialize["result_details"] = o.ResultDetails - } + toSerialize["result_details"] = o.ResultDetails.Get() if o.Options != nil { toSerialize["options"] = o.Options } @@ -724,6 +748,7 @@ func (o StartLoadTestResponse) ToMap() (map[string]interface{}, error) { toSerialize["max_browser_vus"] = o.MaxBrowserVus.Get() toSerialize["estimated_duration"] = o.EstimatedDuration.Get() toSerialize["execution_duration"] = o.ExecutionDuration + toSerialize["is_starred"] = o.IsStarred toSerialize["test_run_details_page_url"] = o.TestRunDetailsPageUrl for key, value := range o.AdditionalProperties { @@ -760,6 +785,7 @@ func (o *StartLoadTestResponse) UnmarshalJSON(data []byte) (err error) { "max_browser_vus", "estimated_duration", "execution_duration", + "is_starred", "test_run_details_page_url", } @@ -812,6 +838,7 @@ func (o *StartLoadTestResponse) UnmarshalJSON(data []byte) (err error) { delete(additionalProperties, "max_browser_vus") delete(additionalProperties, "estimated_duration") delete(additionalProperties, "execution_duration") + delete(additionalProperties, "is_starred") delete(additionalProperties, "test_run_details_page_url") o.AdditionalProperties = additionalProperties } diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_start_local_execution_test_request.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_start_local_execution_test_request.go new file mode 100644 index 000000000..b1bb04e70 --- /dev/null +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_start_local_execution_test_request.go @@ -0,0 +1,326 @@ +/* +Grafana Cloud k6 + +HTTP API for interacting with Grafana Cloud k6. + +API version: 1.12.0 +Contact: info@grafana.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package k6 + +import ( + "encoding/json" + "fmt" +) + +// checks if the StartLocalExecutionTestRequest type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &StartLocalExecutionTestRequest{} + +// StartLocalExecutionTestRequest struct for StartLocalExecutionTestRequest +type StartLocalExecutionTestRequest struct { + // Parsed k6 script options. + Options map[string]interface{} `json:"options"` + // Maximum number of virtual users during the test. + MaxVus int32 `json:"max_vus"` + // Total duration of the test in seconds. + TotalDuration int32 `json:"total_duration"` + // Number of load generator instances that will run the test (k6-operator only). + Instances NullableInt32 `json:"instances,omitempty"` + // K6 archive file size in bytes or null if not uploading. + ArchiveSize NullableInt32 `json:"archive_size,omitempty"` + AdditionalProperties map[string]interface{} +} + +type _StartLocalExecutionTestRequest StartLocalExecutionTestRequest + +// NewStartLocalExecutionTestRequest instantiates a new StartLocalExecutionTestRequest object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewStartLocalExecutionTestRequest(options map[string]interface{}, maxVus int32, totalDuration int32) *StartLocalExecutionTestRequest { + this := StartLocalExecutionTestRequest{} + this.Options = options + this.MaxVus = maxVus + this.TotalDuration = totalDuration + return &this +} + +// NewStartLocalExecutionTestRequestWithDefaults instantiates a new StartLocalExecutionTestRequest object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewStartLocalExecutionTestRequestWithDefaults() *StartLocalExecutionTestRequest { + this := StartLocalExecutionTestRequest{} + return &this +} + +// GetOptions returns the Options field value +func (o *StartLocalExecutionTestRequest) GetOptions() map[string]interface{} { + if o == nil { + var ret map[string]interface{} + return ret + } + + return o.Options +} + +// GetOptionsOk returns a tuple with the Options field value +// and a boolean to check if the value has been set. +func (o *StartLocalExecutionTestRequest) GetOptionsOk() (map[string]interface{}, bool) { + if o == nil { + return map[string]interface{}{}, false + } + return o.Options, true +} + +// SetOptions sets field value +func (o *StartLocalExecutionTestRequest) SetOptions(v map[string]interface{}) { + o.Options = v +} + +// GetMaxVus returns the MaxVus field value +func (o *StartLocalExecutionTestRequest) GetMaxVus() int32 { + if o == nil { + var ret int32 + return ret + } + + return o.MaxVus +} + +// GetMaxVusOk returns a tuple with the MaxVus field value +// and a boolean to check if the value has been set. +func (o *StartLocalExecutionTestRequest) GetMaxVusOk() (*int32, bool) { + if o == nil { + return nil, false + } + return &o.MaxVus, true +} + +// SetMaxVus sets field value +func (o *StartLocalExecutionTestRequest) SetMaxVus(v int32) { + o.MaxVus = v +} + +// GetTotalDuration returns the TotalDuration field value +func (o *StartLocalExecutionTestRequest) GetTotalDuration() int32 { + if o == nil { + var ret int32 + return ret + } + + return o.TotalDuration +} + +// GetTotalDurationOk returns a tuple with the TotalDuration field value +// and a boolean to check if the value has been set. +func (o *StartLocalExecutionTestRequest) GetTotalDurationOk() (*int32, bool) { + if o == nil { + return nil, false + } + return &o.TotalDuration, true +} + +// SetTotalDuration sets field value +func (o *StartLocalExecutionTestRequest) SetTotalDuration(v int32) { + o.TotalDuration = v +} + +// GetInstances returns the Instances field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *StartLocalExecutionTestRequest) GetInstances() int32 { + if o == nil || IsNil(o.Instances.Get()) { + var ret int32 + return ret + } + return *o.Instances.Get() +} + +// GetInstancesOk returns a tuple with the Instances field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *StartLocalExecutionTestRequest) GetInstancesOk() (*int32, bool) { + if o == nil { + return nil, false + } + return o.Instances.Get(), o.Instances.IsSet() +} + +// HasInstances returns a boolean if a field has been set. +func (o *StartLocalExecutionTestRequest) HasInstances() bool { + if o != nil && o.Instances.IsSet() { + return true + } + + return false +} + +// SetInstances gets a reference to the given NullableInt32 and assigns it to the Instances field. +func (o *StartLocalExecutionTestRequest) SetInstances(v int32) { + o.Instances.Set(&v) +} + +// SetInstancesNil sets the value for Instances to be an explicit nil +func (o *StartLocalExecutionTestRequest) SetInstancesNil() { + o.Instances.Set(nil) +} + +// UnsetInstances ensures that no value is present for Instances, not even an explicit nil +func (o *StartLocalExecutionTestRequest) UnsetInstances() { + o.Instances.Unset() +} + +// GetArchiveSize returns the ArchiveSize field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *StartLocalExecutionTestRequest) GetArchiveSize() int32 { + if o == nil || IsNil(o.ArchiveSize.Get()) { + var ret int32 + return ret + } + return *o.ArchiveSize.Get() +} + +// GetArchiveSizeOk returns a tuple with the ArchiveSize field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *StartLocalExecutionTestRequest) GetArchiveSizeOk() (*int32, bool) { + if o == nil { + return nil, false + } + return o.ArchiveSize.Get(), o.ArchiveSize.IsSet() +} + +// HasArchiveSize returns a boolean if a field has been set. +func (o *StartLocalExecutionTestRequest) HasArchiveSize() bool { + if o != nil && o.ArchiveSize.IsSet() { + return true + } + + return false +} + +// SetArchiveSize gets a reference to the given NullableInt32 and assigns it to the ArchiveSize field. +func (o *StartLocalExecutionTestRequest) SetArchiveSize(v int32) { + o.ArchiveSize.Set(&v) +} + +// SetArchiveSizeNil sets the value for ArchiveSize to be an explicit nil +func (o *StartLocalExecutionTestRequest) SetArchiveSizeNil() { + o.ArchiveSize.Set(nil) +} + +// UnsetArchiveSize ensures that no value is present for ArchiveSize, not even an explicit nil +func (o *StartLocalExecutionTestRequest) UnsetArchiveSize() { + o.ArchiveSize.Unset() +} + +func (o StartLocalExecutionTestRequest) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o StartLocalExecutionTestRequest) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["options"] = o.Options + toSerialize["max_vus"] = o.MaxVus + toSerialize["total_duration"] = o.TotalDuration + if o.Instances.IsSet() { + toSerialize["instances"] = o.Instances.Get() + } + if o.ArchiveSize.IsSet() { + toSerialize["archive_size"] = o.ArchiveSize.Get() + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *StartLocalExecutionTestRequest) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "options", + "max_vus", + "total_duration", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err + } + + for _, requiredProperty := range requiredProperties { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varStartLocalExecutionTestRequest := _StartLocalExecutionTestRequest{} + + err = json.Unmarshal(data, &varStartLocalExecutionTestRequest) + + if err != nil { + return err + } + + *o = StartLocalExecutionTestRequest(varStartLocalExecutionTestRequest) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(data, &additionalProperties); err == nil { + delete(additionalProperties, "options") + delete(additionalProperties, "max_vus") + delete(additionalProperties, "total_duration") + delete(additionalProperties, "instances") + delete(additionalProperties, "archive_size") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableStartLocalExecutionTestRequest struct { + value *StartLocalExecutionTestRequest + isSet bool +} + +func (v NullableStartLocalExecutionTestRequest) Get() *StartLocalExecutionTestRequest { + return v.value +} + +func (v *NullableStartLocalExecutionTestRequest) Set(val *StartLocalExecutionTestRequest) { + v.value = val + v.isSet = true +} + +func (v NullableStartLocalExecutionTestRequest) IsSet() bool { + return v.isSet +} + +func (v *NullableStartLocalExecutionTestRequest) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableStartLocalExecutionTestRequest(val *StartLocalExecutionTestRequest) *NullableStartLocalExecutionTestRequest { + return &NullableStartLocalExecutionTestRequest{value: val, isSet: true} +} + +func (v NullableStartLocalExecutionTestRequest) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableStartLocalExecutionTestRequest) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_start_local_execution_test_response.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_start_local_execution_test_response.go new file mode 100644 index 000000000..4aa9789e6 --- /dev/null +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_start_local_execution_test_response.go @@ -0,0 +1,259 @@ +/* +Grafana Cloud k6 + +HTTP API for interacting with Grafana Cloud k6. + +API version: 1.12.0 +Contact: info@grafana.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package k6 + +import ( + "encoding/json" + "fmt" +) + +// checks if the StartLocalExecutionTestResponse type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &StartLocalExecutionTestResponse{} + +// StartLocalExecutionTestResponse struct for StartLocalExecutionTestResponse +type StartLocalExecutionTestResponse struct { + // ID of the created test run. + TestRunId int64 `json:"test_run_id"` + RuntimeConfig RuntimeConfig `json:"runtime_config"` + // URL to upload the k6 archive or null if not uploading. + ArchiveUploadUrl NullableString `json:"archive_upload_url"` + // URL to the Grafana web app. + TestRunDetailsPageUrl string `json:"test_run_details_page_url"` + AdditionalProperties map[string]interface{} +} + +type _StartLocalExecutionTestResponse StartLocalExecutionTestResponse + +// NewStartLocalExecutionTestResponse instantiates a new StartLocalExecutionTestResponse object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewStartLocalExecutionTestResponse(testRunId int64, runtimeConfig RuntimeConfig, archiveUploadUrl NullableString, testRunDetailsPageUrl string) *StartLocalExecutionTestResponse { + this := StartLocalExecutionTestResponse{} + this.TestRunId = testRunId + this.RuntimeConfig = runtimeConfig + this.ArchiveUploadUrl = archiveUploadUrl + this.TestRunDetailsPageUrl = testRunDetailsPageUrl + return &this +} + +// NewStartLocalExecutionTestResponseWithDefaults instantiates a new StartLocalExecutionTestResponse object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewStartLocalExecutionTestResponseWithDefaults() *StartLocalExecutionTestResponse { + this := StartLocalExecutionTestResponse{} + return &this +} + +// GetTestRunId returns the TestRunId field value +func (o *StartLocalExecutionTestResponse) GetTestRunId() int64 { + if o == nil { + var ret int64 + return ret + } + + return o.TestRunId +} + +// GetTestRunIdOk returns a tuple with the TestRunId field value +// and a boolean to check if the value has been set. +func (o *StartLocalExecutionTestResponse) GetTestRunIdOk() (*int64, bool) { + if o == nil { + return nil, false + } + return &o.TestRunId, true +} + +// SetTestRunId sets field value +func (o *StartLocalExecutionTestResponse) SetTestRunId(v int64) { + o.TestRunId = v +} + +// GetRuntimeConfig returns the RuntimeConfig field value +func (o *StartLocalExecutionTestResponse) GetRuntimeConfig() RuntimeConfig { + if o == nil { + var ret RuntimeConfig + return ret + } + + return o.RuntimeConfig +} + +// GetRuntimeConfigOk returns a tuple with the RuntimeConfig field value +// and a boolean to check if the value has been set. +func (o *StartLocalExecutionTestResponse) GetRuntimeConfigOk() (*RuntimeConfig, bool) { + if o == nil { + return nil, false + } + return &o.RuntimeConfig, true +} + +// SetRuntimeConfig sets field value +func (o *StartLocalExecutionTestResponse) SetRuntimeConfig(v RuntimeConfig) { + o.RuntimeConfig = v +} + +// GetArchiveUploadUrl returns the ArchiveUploadUrl field value +// If the value is explicit nil, the zero value for string will be returned +func (o *StartLocalExecutionTestResponse) GetArchiveUploadUrl() string { + if o == nil || o.ArchiveUploadUrl.Get() == nil { + var ret string + return ret + } + + return *o.ArchiveUploadUrl.Get() +} + +// GetArchiveUploadUrlOk returns a tuple with the ArchiveUploadUrl field value +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *StartLocalExecutionTestResponse) GetArchiveUploadUrlOk() (*string, bool) { + if o == nil { + return nil, false + } + return o.ArchiveUploadUrl.Get(), o.ArchiveUploadUrl.IsSet() +} + +// SetArchiveUploadUrl sets field value +func (o *StartLocalExecutionTestResponse) SetArchiveUploadUrl(v string) { + o.ArchiveUploadUrl.Set(&v) +} + +// GetTestRunDetailsPageUrl returns the TestRunDetailsPageUrl field value +func (o *StartLocalExecutionTestResponse) GetTestRunDetailsPageUrl() string { + if o == nil { + var ret string + return ret + } + + return o.TestRunDetailsPageUrl +} + +// GetTestRunDetailsPageUrlOk returns a tuple with the TestRunDetailsPageUrl field value +// and a boolean to check if the value has been set. +func (o *StartLocalExecutionTestResponse) GetTestRunDetailsPageUrlOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.TestRunDetailsPageUrl, true +} + +// SetTestRunDetailsPageUrl sets field value +func (o *StartLocalExecutionTestResponse) SetTestRunDetailsPageUrl(v string) { + o.TestRunDetailsPageUrl = v +} + +func (o StartLocalExecutionTestResponse) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o StartLocalExecutionTestResponse) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["test_run_id"] = o.TestRunId + toSerialize["runtime_config"] = o.RuntimeConfig + toSerialize["archive_upload_url"] = o.ArchiveUploadUrl.Get() + toSerialize["test_run_details_page_url"] = o.TestRunDetailsPageUrl + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *StartLocalExecutionTestResponse) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "test_run_id", + "runtime_config", + "archive_upload_url", + "test_run_details_page_url", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err + } + + for _, requiredProperty := range requiredProperties { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varStartLocalExecutionTestResponse := _StartLocalExecutionTestResponse{} + + err = json.Unmarshal(data, &varStartLocalExecutionTestResponse) + + if err != nil { + return err + } + + *o = StartLocalExecutionTestResponse(varStartLocalExecutionTestResponse) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(data, &additionalProperties); err == nil { + delete(additionalProperties, "test_run_id") + delete(additionalProperties, "runtime_config") + delete(additionalProperties, "archive_upload_url") + delete(additionalProperties, "test_run_details_page_url") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableStartLocalExecutionTestResponse struct { + value *StartLocalExecutionTestResponse + isSet bool +} + +func (v NullableStartLocalExecutionTestResponse) Get() *StartLocalExecutionTestResponse { + return v.value +} + +func (v *NullableStartLocalExecutionTestResponse) Set(val *StartLocalExecutionTestResponse) { + v.value = val + v.isSet = true +} + +func (v NullableStartLocalExecutionTestResponse) IsSet() bool { + return v.isSet +} + +func (v *NullableStartLocalExecutionTestResponse) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableStartLocalExecutionTestResponse(val *StartLocalExecutionTestResponse) *NullableStartLocalExecutionTestResponse { + return &NullableStartLocalExecutionTestResponse{value: val, isSet: true} +} + +func (v NullableStartLocalExecutionTestResponse) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableStartLocalExecutionTestResponse) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_status_api_model.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_status_api_model.go index 84c54cf1b..1b9b283cf 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_status_api_model.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_status_api_model.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_status_extra_api_model.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_status_extra_api_model.go index 22ff9341c..28d0cc06c 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_status_extra_api_model.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_status_extra_api_model.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_test_cost_api_model.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_test_cost_api_model.go index 94335addd..f98012f19 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_test_cost_api_model.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_test_cost_api_model.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_test_run_api_model.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_test_run_api_model.go index 59e64c5b9..80a569cc3 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_test_run_api_model.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_test_run_api_model.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ @@ -23,11 +23,11 @@ var _ MappedNullable = &TestRunApiModel{} // TestRunApiModel The API model for a test run. type TestRunApiModel struct { // ID of the test run. - Id int32 `json:"id"` + Id int64 `json:"id"` // ID of the parent test. - TestId int32 `json:"test_id"` + TestId int64 `json:"test_id"` // ID of the parent project. - ProjectId int32 `json:"project_id"` + ProjectId int64 `json:"project_id"` // Email of the user who started the test if started with a user token. StartedBy NullableString `json:"started_by"` // Date and time when the test run was started. @@ -48,9 +48,8 @@ type TestRunApiModel struct { // List of the load zones configured for the test and the corresponding distribution percentages. Distribution []DistributionZoneApiModel `json:"distribution"` // Test run result. `passed` if there were no issues, `failed` if thresholds were breached, `error` if the execution was not completed. - Result NullableString `json:"result"` - // Additional information about the test run result. - ResultDetails map[string]interface{} `json:"result_details"` + Result NullableString `json:"result"` + ResultDetails NullableTestRunApiModelResultDetails `json:"result_details"` // The original options object if available. Options map[string]interface{} `json:"options"` // The requested version of k6 and extensions that was part of the script/archive. @@ -64,7 +63,9 @@ type TestRunApiModel struct { // The estimated duration of the test run in seconds. EstimatedDuration NullableInt32 `json:"estimated_duration"` // The real billable duration of the test run in seconds. - ExecutionDuration int32 `json:"execution_duration"` + ExecutionDuration int32 `json:"execution_duration"` + // Whether the test run is starred for quick access. + IsStarred bool `json:"is_starred"` AdditionalProperties map[string]interface{} } @@ -74,7 +75,7 @@ type _TestRunApiModel TestRunApiModel // This constructor will assign default values to properties that have it defined, // and makes sure properties required by API are set, but the set of arguments // will change when the set of required properties is changed -func NewTestRunApiModel(id int32, testId int32, projectId int32, startedBy NullableString, created time.Time, ended NullableTime, note string, retentionExpiry NullableTime, cost NullableTestRunApiModelCost, status string, statusDetails StatusApiModel, statusHistory []StatusApiModel, distribution []DistributionZoneApiModel, result NullableString, resultDetails map[string]interface{}, options map[string]interface{}, k6Dependencies map[string]string, k6Versions map[string]string, maxVus NullableInt32, maxBrowserVus NullableInt32, estimatedDuration NullableInt32, executionDuration int32) *TestRunApiModel { +func NewTestRunApiModel(id int64, testId int64, projectId int64, startedBy NullableString, created time.Time, ended NullableTime, note string, retentionExpiry NullableTime, cost NullableTestRunApiModelCost, status string, statusDetails StatusApiModel, statusHistory []StatusApiModel, distribution []DistributionZoneApiModel, result NullableString, resultDetails NullableTestRunApiModelResultDetails, options map[string]interface{}, k6Dependencies map[string]string, k6Versions map[string]string, maxVus NullableInt32, maxBrowserVus NullableInt32, estimatedDuration NullableInt32, executionDuration int32, isStarred bool) *TestRunApiModel { this := TestRunApiModel{} this.Id = id this.TestId = testId @@ -98,6 +99,7 @@ func NewTestRunApiModel(id int32, testId int32, projectId int32, startedBy Nulla this.MaxBrowserVus = maxBrowserVus this.EstimatedDuration = estimatedDuration this.ExecutionDuration = executionDuration + this.IsStarred = isStarred return &this } @@ -110,9 +112,9 @@ func NewTestRunApiModelWithDefaults() *TestRunApiModel { } // GetId returns the Id field value -func (o *TestRunApiModel) GetId() int32 { +func (o *TestRunApiModel) GetId() int64 { if o == nil { - var ret int32 + var ret int64 return ret } @@ -121,7 +123,7 @@ func (o *TestRunApiModel) GetId() int32 { // GetIdOk returns a tuple with the Id field value // and a boolean to check if the value has been set. -func (o *TestRunApiModel) GetIdOk() (*int32, bool) { +func (o *TestRunApiModel) GetIdOk() (*int64, bool) { if o == nil { return nil, false } @@ -129,14 +131,14 @@ func (o *TestRunApiModel) GetIdOk() (*int32, bool) { } // SetId sets field value -func (o *TestRunApiModel) SetId(v int32) { +func (o *TestRunApiModel) SetId(v int64) { o.Id = v } // GetTestId returns the TestId field value -func (o *TestRunApiModel) GetTestId() int32 { +func (o *TestRunApiModel) GetTestId() int64 { if o == nil { - var ret int32 + var ret int64 return ret } @@ -145,7 +147,7 @@ func (o *TestRunApiModel) GetTestId() int32 { // GetTestIdOk returns a tuple with the TestId field value // and a boolean to check if the value has been set. -func (o *TestRunApiModel) GetTestIdOk() (*int32, bool) { +func (o *TestRunApiModel) GetTestIdOk() (*int64, bool) { if o == nil { return nil, false } @@ -153,14 +155,14 @@ func (o *TestRunApiModel) GetTestIdOk() (*int32, bool) { } // SetTestId sets field value -func (o *TestRunApiModel) SetTestId(v int32) { +func (o *TestRunApiModel) SetTestId(v int64) { o.TestId = v } // GetProjectId returns the ProjectId field value -func (o *TestRunApiModel) GetProjectId() int32 { +func (o *TestRunApiModel) GetProjectId() int64 { if o == nil { - var ret int32 + var ret int64 return ret } @@ -169,7 +171,7 @@ func (o *TestRunApiModel) GetProjectId() int32 { // GetProjectIdOk returns a tuple with the ProjectId field value // and a boolean to check if the value has been set. -func (o *TestRunApiModel) GetProjectIdOk() (*int32, bool) { +func (o *TestRunApiModel) GetProjectIdOk() (*int64, bool) { if o == nil { return nil, false } @@ -177,7 +179,7 @@ func (o *TestRunApiModel) GetProjectIdOk() (*int32, bool) { } // SetProjectId sets field value -func (o *TestRunApiModel) SetProjectId(v int32) { +func (o *TestRunApiModel) SetProjectId(v int64) { o.ProjectId = v } @@ -458,29 +460,29 @@ func (o *TestRunApiModel) SetResult(v string) { } // GetResultDetails returns the ResultDetails field value -// If the value is explicit nil, the zero value for map[string]interface{} will be returned -func (o *TestRunApiModel) GetResultDetails() map[string]interface{} { - if o == nil { - var ret map[string]interface{} +// If the value is explicit nil, the zero value for TestRunApiModelResultDetails will be returned +func (o *TestRunApiModel) GetResultDetails() TestRunApiModelResultDetails { + if o == nil || o.ResultDetails.Get() == nil { + var ret TestRunApiModelResultDetails return ret } - return o.ResultDetails + return *o.ResultDetails.Get() } // GetResultDetailsOk returns a tuple with the ResultDetails field value // and a boolean to check if the value has been set. // NOTE: If the value is an explicit nil, `nil, true` will be returned -func (o *TestRunApiModel) GetResultDetailsOk() (map[string]interface{}, bool) { - if o == nil || IsNil(o.ResultDetails) { - return map[string]interface{}{}, false +func (o *TestRunApiModel) GetResultDetailsOk() (*TestRunApiModelResultDetails, bool) { + if o == nil { + return nil, false } - return o.ResultDetails, true + return o.ResultDetails.Get(), o.ResultDetails.IsSet() } // SetResultDetails sets field value -func (o *TestRunApiModel) SetResultDetails(v map[string]interface{}) { - o.ResultDetails = v +func (o *TestRunApiModel) SetResultDetails(v TestRunApiModelResultDetails) { + o.ResultDetails.Set(&v) } // GetOptions returns the Options field value @@ -659,6 +661,30 @@ func (o *TestRunApiModel) SetExecutionDuration(v int32) { o.ExecutionDuration = v } +// GetIsStarred returns the IsStarred field value +func (o *TestRunApiModel) GetIsStarred() bool { + if o == nil { + var ret bool + return ret + } + + return o.IsStarred +} + +// GetIsStarredOk returns a tuple with the IsStarred field value +// and a boolean to check if the value has been set. +func (o *TestRunApiModel) GetIsStarredOk() (*bool, bool) { + if o == nil { + return nil, false + } + return &o.IsStarred, true +} + +// SetIsStarred sets field value +func (o *TestRunApiModel) SetIsStarred(v bool) { + o.IsStarred = v +} + func (o TestRunApiModel) MarshalJSON() ([]byte, error) { toSerialize, err := o.ToMap() if err != nil { @@ -685,9 +711,7 @@ func (o TestRunApiModel) ToMap() (map[string]interface{}, error) { toSerialize["distribution"] = o.Distribution } toSerialize["result"] = o.Result.Get() - if o.ResultDetails != nil { - toSerialize["result_details"] = o.ResultDetails - } + toSerialize["result_details"] = o.ResultDetails.Get() if o.Options != nil { toSerialize["options"] = o.Options } @@ -697,6 +721,7 @@ func (o TestRunApiModel) ToMap() (map[string]interface{}, error) { toSerialize["max_browser_vus"] = o.MaxBrowserVus.Get() toSerialize["estimated_duration"] = o.EstimatedDuration.Get() toSerialize["execution_duration"] = o.ExecutionDuration + toSerialize["is_starred"] = o.IsStarred for key, value := range o.AdditionalProperties { toSerialize[key] = value @@ -732,6 +757,7 @@ func (o *TestRunApiModel) UnmarshalJSON(data []byte) (err error) { "max_browser_vus", "estimated_duration", "execution_duration", + "is_starred", } allProperties := make(map[string]interface{}) @@ -783,6 +809,7 @@ func (o *TestRunApiModel) UnmarshalJSON(data []byte) (err error) { delete(additionalProperties, "max_browser_vus") delete(additionalProperties, "estimated_duration") delete(additionalProperties, "execution_duration") + delete(additionalProperties, "is_starred") o.AdditionalProperties = additionalProperties } diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_test_run_api_model_cost.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_test_run_api_model_cost.go index 1a31476d1..96de95b6d 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_test_run_api_model_cost.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_test_run_api_model_cost.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_test_run_api_model_result_details.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_test_run_api_model_result_details.go new file mode 100644 index 000000000..8e3a96b02 --- /dev/null +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_test_run_api_model_result_details.go @@ -0,0 +1,127 @@ +/* +Grafana Cloud k6 + +HTTP API for interacting with Grafana Cloud k6. + +API version: 1.12.0 +Contact: info@grafana.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package k6 + +import ( + "encoding/json" + "fmt" + + "gopkg.in/validator.v2" +) + +// TestRunApiModelResultDetails - Additional information about the test run result. +type TestRunApiModelResultDetails struct { + ResultDetailsApiModel *ResultDetailsApiModel +} + +// ResultDetailsApiModelAsTestRunApiModelResultDetails is a convenience function that returns ResultDetailsApiModel wrapped in TestRunApiModelResultDetails +func ResultDetailsApiModelAsTestRunApiModelResultDetails(v *ResultDetailsApiModel) TestRunApiModelResultDetails { + return TestRunApiModelResultDetails{ + ResultDetailsApiModel: v, + } +} + +// Unmarshal JSON data into one of the pointers in the struct +func (dst *TestRunApiModelResultDetails) UnmarshalJSON(data []byte) error { + var err error + // this object is nullable so check if the payload is null or empty string + if string(data) == "" || string(data) == "{}" { + return nil + } + + match := 0 + // try to unmarshal data into ResultDetailsApiModel + err = newStrictDecoder(data).Decode(&dst.ResultDetailsApiModel) + if err == nil { + jsonResultDetailsApiModel, _ := json.Marshal(dst.ResultDetailsApiModel) + if string(jsonResultDetailsApiModel) == "{}" { // empty struct + dst.ResultDetailsApiModel = nil + } else { + if err = validator.Validate(dst.ResultDetailsApiModel); err != nil { + dst.ResultDetailsApiModel = nil + } else { + match++ + } + } + } else { + dst.ResultDetailsApiModel = nil + } + + if match > 1 { // more than 1 match + // reset to nil + dst.ResultDetailsApiModel = nil + + return fmt.Errorf("data matches more than one schema in oneOf(TestRunApiModelResultDetails)") + } else if match == 1 { + return nil // exactly one match + } else { // no match + return fmt.Errorf("data failed to match schemas in oneOf(TestRunApiModelResultDetails)") + } +} + +// Marshal data from the first non-nil pointers in the struct to JSON +func (src TestRunApiModelResultDetails) MarshalJSON() ([]byte, error) { + if src.ResultDetailsApiModel != nil { + return json.Marshal(&src.ResultDetailsApiModel) + } + + return nil, nil // no data in oneOf schemas +} + +// Get the actual instance +func (obj *TestRunApiModelResultDetails) GetActualInstance() interface{} { + if obj == nil { + return nil + } + if obj.ResultDetailsApiModel != nil { + return obj.ResultDetailsApiModel + } + + // all schemas are nil + return nil +} + +type NullableTestRunApiModelResultDetails struct { + value *TestRunApiModelResultDetails + isSet bool +} + +func (v NullableTestRunApiModelResultDetails) Get() *TestRunApiModelResultDetails { + return v.value +} + +func (v *NullableTestRunApiModelResultDetails) Set(val *TestRunApiModelResultDetails) { + v.value = val + v.isSet = true +} + +func (v NullableTestRunApiModelResultDetails) IsSet() bool { + return v.isSet +} + +func (v *NullableTestRunApiModelResultDetails) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableTestRunApiModelResultDetails(val *TestRunApiModelResultDetails) *NullableTestRunApiModelResultDetails { + return &NullableTestRunApiModelResultDetails{value: val, isSet: true} +} + +func (v NullableTestRunApiModelResultDetails) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableTestRunApiModelResultDetails) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_test_run_distribution_api_model.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_test_run_distribution_api_model.go index 944ce5c74..8883e20f4 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_test_run_distribution_api_model.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_test_run_distribution_api_model.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_test_run_list_response.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_test_run_list_response.go index b2daa4886..3b74657a4 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_test_run_list_response.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_test_run_list_response.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_total_vuh.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_total_vuh.go index 51386052b..c5aa57717 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_total_vuh.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_total_vuh.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_traces_runtime_config.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_traces_runtime_config.go new file mode 100644 index 000000000..f781c46e2 --- /dev/null +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_traces_runtime_config.go @@ -0,0 +1,228 @@ +/* +Grafana Cloud k6 + +HTTP API for interacting with Grafana Cloud k6. + +API version: 1.12.0 +Contact: info@grafana.com +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package k6 + +import ( + "encoding/json" + "fmt" +) + +// checks if the TracesRuntimeConfig type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &TracesRuntimeConfig{} + +// TracesRuntimeConfig Traces push runtime configuration. +type TracesRuntimeConfig struct { + // URL to push traces to. + PushUrl string `json:"push_url"` + // Metadata labels attached to all traces. + TracesMetadata map[string]string `json:"traces_metadata"` + // Protocol to use for pushing traces. + Proto string `json:"proto"` + AdditionalProperties map[string]interface{} +} + +type _TracesRuntimeConfig TracesRuntimeConfig + +// NewTracesRuntimeConfig instantiates a new TracesRuntimeConfig object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewTracesRuntimeConfig(pushUrl string, tracesMetadata map[string]string, proto string) *TracesRuntimeConfig { + this := TracesRuntimeConfig{} + this.PushUrl = pushUrl + this.TracesMetadata = tracesMetadata + this.Proto = proto + return &this +} + +// NewTracesRuntimeConfigWithDefaults instantiates a new TracesRuntimeConfig object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewTracesRuntimeConfigWithDefaults() *TracesRuntimeConfig { + this := TracesRuntimeConfig{} + return &this +} + +// GetPushUrl returns the PushUrl field value +func (o *TracesRuntimeConfig) GetPushUrl() string { + if o == nil { + var ret string + return ret + } + + return o.PushUrl +} + +// GetPushUrlOk returns a tuple with the PushUrl field value +// and a boolean to check if the value has been set. +func (o *TracesRuntimeConfig) GetPushUrlOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.PushUrl, true +} + +// SetPushUrl sets field value +func (o *TracesRuntimeConfig) SetPushUrl(v string) { + o.PushUrl = v +} + +// GetTracesMetadata returns the TracesMetadata field value +func (o *TracesRuntimeConfig) GetTracesMetadata() map[string]string { + if o == nil { + var ret map[string]string + return ret + } + + return o.TracesMetadata +} + +// GetTracesMetadataOk returns a tuple with the TracesMetadata field value +// and a boolean to check if the value has been set. +func (o *TracesRuntimeConfig) GetTracesMetadataOk() (map[string]string, bool) { + if o == nil { + return map[string]string{}, false + } + return o.TracesMetadata, true +} + +// SetTracesMetadata sets field value +func (o *TracesRuntimeConfig) SetTracesMetadata(v map[string]string) { + o.TracesMetadata = v +} + +// GetProto returns the Proto field value +func (o *TracesRuntimeConfig) GetProto() string { + if o == nil { + var ret string + return ret + } + + return o.Proto +} + +// GetProtoOk returns a tuple with the Proto field value +// and a boolean to check if the value has been set. +func (o *TracesRuntimeConfig) GetProtoOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Proto, true +} + +// SetProto sets field value +func (o *TracesRuntimeConfig) SetProto(v string) { + o.Proto = v +} + +func (o TracesRuntimeConfig) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o TracesRuntimeConfig) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["push_url"] = o.PushUrl + toSerialize["traces_metadata"] = o.TracesMetadata + toSerialize["proto"] = o.Proto + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *TracesRuntimeConfig) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "push_url", + "traces_metadata", + "proto", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err + } + + for _, requiredProperty := range requiredProperties { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varTracesRuntimeConfig := _TracesRuntimeConfig{} + + err = json.Unmarshal(data, &varTracesRuntimeConfig) + + if err != nil { + return err + } + + *o = TracesRuntimeConfig(varTracesRuntimeConfig) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(data, &additionalProperties); err == nil { + delete(additionalProperties, "push_url") + delete(additionalProperties, "traces_metadata") + delete(additionalProperties, "proto") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableTracesRuntimeConfig struct { + value *TracesRuntimeConfig + isSet bool +} + +func (v NullableTracesRuntimeConfig) Get() *TracesRuntimeConfig { + return v.value +} + +func (v *NullableTracesRuntimeConfig) Set(val *TracesRuntimeConfig) { + v.value = val + v.isSet = true +} + +func (v NullableTracesRuntimeConfig) IsSet() bool { + return v.isSet +} + +func (v *NullableTracesRuntimeConfig) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableTracesRuntimeConfig(val *TracesRuntimeConfig) *NullableTracesRuntimeConfig { + return &NullableTracesRuntimeConfig{value: val, isSet: true} +} + +func (v NullableTracesRuntimeConfig) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableTracesRuntimeConfig) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_update_allowed_load_zones_list_api_model.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_update_allowed_load_zones_list_api_model.go index d7e49609e..3e1ffee45 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_update_allowed_load_zones_list_api_model.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_update_allowed_load_zones_list_api_model.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_update_allowed_projects_list_api_model.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_update_allowed_projects_list_api_model.go index 9b4edeac2..525bee967 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_update_allowed_projects_list_api_model.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_update_allowed_projects_list_api_model.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_validate_options_request.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_validate_options_request.go index 9d5f1d57e..437ae8836 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_validate_options_request.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_validate_options_request.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ @@ -22,11 +22,13 @@ var _ MappedNullable = &ValidateOptionsRequest{} // ValidateOptionsRequest struct for ValidateOptionsRequest type ValidateOptionsRequest struct { // ID of a project where the test belongs. - ProjectId NullableInt32 `json:"project_id,omitempty"` + ProjectId NullableInt64 `json:"project_id,omitempty"` // k6 script options object to validate. Options Options `json:"options"` // Version of k6 and extensions to validate, as a map of dependency name to dependency version constraint. K6Dependencies map[string]string `json:"k6_dependencies,omitempty"` + // Identifier of the k6 version used to run the test. + K6Version NullableInt32 `json:"k6_version,omitempty"` // Whether the test is being executed locally. IsLocalExecution *bool `json:"is_local_execution,omitempty"` AdditionalProperties map[string]interface{} @@ -57,9 +59,9 @@ func NewValidateOptionsRequestWithDefaults() *ValidateOptionsRequest { } // GetProjectId returns the ProjectId field value if set, zero value otherwise (both if not set or set to explicit null). -func (o *ValidateOptionsRequest) GetProjectId() int32 { +func (o *ValidateOptionsRequest) GetProjectId() int64 { if o == nil || IsNil(o.ProjectId.Get()) { - var ret int32 + var ret int64 return ret } return *o.ProjectId.Get() @@ -68,7 +70,7 @@ func (o *ValidateOptionsRequest) GetProjectId() int32 { // GetProjectIdOk returns a tuple with the ProjectId field value if set, nil otherwise // and a boolean to check if the value has been set. // NOTE: If the value is an explicit nil, `nil, true` will be returned -func (o *ValidateOptionsRequest) GetProjectIdOk() (*int32, bool) { +func (o *ValidateOptionsRequest) GetProjectIdOk() (*int64, bool) { if o == nil { return nil, false } @@ -84,8 +86,8 @@ func (o *ValidateOptionsRequest) HasProjectId() bool { return false } -// SetProjectId gets a reference to the given NullableInt32 and assigns it to the ProjectId field. -func (o *ValidateOptionsRequest) SetProjectId(v int32) { +// SetProjectId gets a reference to the given NullableInt64 and assigns it to the ProjectId field. +func (o *ValidateOptionsRequest) SetProjectId(v int64) { o.ProjectId.Set(&v) } @@ -155,6 +157,49 @@ func (o *ValidateOptionsRequest) SetK6Dependencies(v map[string]string) { o.K6Dependencies = v } +// GetK6Version returns the K6Version field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *ValidateOptionsRequest) GetK6Version() int32 { + if o == nil || IsNil(o.K6Version.Get()) { + var ret int32 + return ret + } + return *o.K6Version.Get() +} + +// GetK6VersionOk returns a tuple with the K6Version field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *ValidateOptionsRequest) GetK6VersionOk() (*int32, bool) { + if o == nil { + return nil, false + } + return o.K6Version.Get(), o.K6Version.IsSet() +} + +// HasK6Version returns a boolean if a field has been set. +func (o *ValidateOptionsRequest) HasK6Version() bool { + if o != nil && o.K6Version.IsSet() { + return true + } + + return false +} + +// SetK6Version gets a reference to the given NullableInt32 and assigns it to the K6Version field. +func (o *ValidateOptionsRequest) SetK6Version(v int32) { + o.K6Version.Set(&v) +} + +// SetK6VersionNil sets the value for K6Version to be an explicit nil +func (o *ValidateOptionsRequest) SetK6VersionNil() { + o.K6Version.Set(nil) +} + +// UnsetK6Version ensures that no value is present for K6Version, not even an explicit nil +func (o *ValidateOptionsRequest) UnsetK6Version() { + o.K6Version.Unset() +} + // GetIsLocalExecution returns the IsLocalExecution field value if set, zero value otherwise. func (o *ValidateOptionsRequest) GetIsLocalExecution() bool { if o == nil || IsNil(o.IsLocalExecution) { @@ -204,6 +249,9 @@ func (o ValidateOptionsRequest) ToMap() (map[string]interface{}, error) { if !IsNil(o.K6Dependencies) { toSerialize["k6_dependencies"] = o.K6Dependencies } + if o.K6Version.IsSet() { + toSerialize["k6_version"] = o.K6Version.Get() + } if !IsNil(o.IsLocalExecution) { toSerialize["is_local_execution"] = o.IsLocalExecution } @@ -253,6 +301,7 @@ func (o *ValidateOptionsRequest) UnmarshalJSON(data []byte) (err error) { delete(additionalProperties, "project_id") delete(additionalProperties, "options") delete(additionalProperties, "k6_dependencies") + delete(additionalProperties, "k6_version") delete(additionalProperties, "is_local_execution") o.AdditionalProperties = additionalProperties } diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_validate_options_response.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_validate_options_response.go index 35eb0d461..e84ca6f20 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_validate_options_response.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_validate_options_response.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_weekday.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_weekday.go index 4e7be862a..7b155cc04 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_weekday.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/model_weekday.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/response.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/response.go index 715f4e786..fb1fc3966 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/response.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/response.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/utils.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/utils.go index ab472de48..89bbeaece 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/utils.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/utils.go @@ -3,7 +3,7 @@ Grafana Cloud k6 HTTP API for interacting with Grafana Cloud k6. -API version: 1.9.1 +API version: 1.12.0 Contact: info@grafana.com */ diff --git a/vendor/modules.txt b/vendor/modules.txt index aabb9be83..0b0516bcc 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -178,7 +178,7 @@ github.com/google/uuid # github.com/gorilla/websocket v1.5.3 ## explicit; go 1.12 github.com/gorilla/websocket -# github.com/grafana/k6-cloud-openapi-client-go v0.0.2 +# github.com/grafana/k6-cloud-openapi-client-go v0.0.3-0.20260625132134-c48eae4f9a18 ## explicit; go 1.23.4 github.com/grafana/k6-cloud-openapi-client-go/k6 # github.com/grafana/k6provider v0.5.0 From f0fdfa9080c672109db4e0b7cd0999c3da7feea1 Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Thu, 16 Jul 2026 12:57:48 +0100 Subject: [PATCH 014/182] chore(deps): update actions/checkout digest to df4cb1c (#6119) Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> --- .github/workflows/browser_e2e.yml | 2 +- .github/workflows/build.yml | 12 ++++++------ .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/feature-briefs.yml | 2 +- .github/workflows/lint.yml | 4 ++-- .github/workflows/packager.yml | 2 +- .github/workflows/summary-code-generation.yml | 2 +- .github/workflows/tc39.yml | 2 +- .github/workflows/test-browser.yml | 8 ++++---- .github/workflows/test.yml | 8 ++++---- .github/workflows/wpt.yml | 2 +- .github/workflows/xk6.yml | 2 +- 12 files changed, 24 insertions(+), 24 deletions(-) diff --git a/.github/workflows/browser_e2e.yml b/.github/workflows/browser_e2e.yml index 7ce765a7e..c7641b84d 100644 --- a/.github/workflows/browser_e2e.yml +++ b/.github/workflows/browser_e2e.yml @@ -30,7 +30,7 @@ jobs: runs-on: ${{ matrix.platform }} steps: - name: Checkout code - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 with: persist-credentials: false - name: Install Go diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 64b38f3b4..fa959550e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -45,7 +45,7 @@ jobs: is_latest_in_major: ${{ steps.classify_release.outputs.is_latest_in_major }} steps: - name: Checkout code - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 with: fetch-depth: 0 persist-credentials: false @@ -154,7 +154,7 @@ jobs: VERSION: ${{ needs.configure.outputs.k6_version }} steps: - name: Checkout code - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 with: fetch-depth: 0 persist-credentials: false @@ -220,7 +220,7 @@ jobs: VERSION: ${{ needs.configure.outputs.k6_version }} steps: - name: Checkout code - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 with: fetch-depth: 0 persist-credentials: false @@ -434,7 +434,7 @@ jobs: VERSION: ${{ needs.configure.outputs.k6_version }} steps: - name: Checkout code - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 with: persist-credentials: false - name: Install pandoc @@ -541,7 +541,7 @@ jobs: contents: write steps: - name: Checkout code - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 with: persist-credentials: false - name: Download binaries @@ -635,7 +635,7 @@ jobs: id-token: write # Required for Vault steps: - name: Checkout code - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 with: persist-credentials: false - name: Download binaries diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 0fa9a59b9..859a56815 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -15,7 +15,7 @@ jobs: steps: - name: Checkout repo - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 with: persist-credentials: false diff --git a/.github/workflows/feature-briefs.yml b/.github/workflows/feature-briefs.yml index c0409e0f8..cf97adb94 100644 --- a/.github/workflows/feature-briefs.yml +++ b/.github/workflows/feature-briefs.yml @@ -17,7 +17,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 with: persist-credentials: false fetch-depth: 0 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 653c3be22..4fa0fd9eb 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -19,7 +19,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 with: persist-credentials: false fetch-depth: 0 @@ -45,7 +45,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 with: persist-credentials: false fetch-depth: 0 diff --git a/.github/workflows/packager.yml b/.github/workflows/packager.yml index 6edec1d30..9ba1c31b0 100644 --- a/.github/workflows/packager.yml +++ b/.github/workflows/packager.yml @@ -23,7 +23,7 @@ jobs: packages: write steps: - name: Checkout code - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 with: persist-credentials: false - name: Build diff --git a/.github/workflows/summary-code-generation.yml b/.github/workflows/summary-code-generation.yml index 530375099..3c4bb3bcb 100644 --- a/.github/workflows/summary-code-generation.yml +++ b/.github/workflows/summary-code-generation.yml @@ -18,7 +18,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 with: persist-credentials: false diff --git a/.github/workflows/tc39.yml b/.github/workflows/tc39.yml index 44071dbef..9edf3b9da 100644 --- a/.github/workflows/tc39.yml +++ b/.github/workflows/tc39.yml @@ -24,7 +24,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 with: persist-credentials: false - name: Resolve Go versions diff --git a/.github/workflows/test-browser.yml b/.github/workflows/test-browser.yml index 99942e67e..c481f2e53 100644 --- a/.github/workflows/test-browser.yml +++ b/.github/workflows/test-browser.yml @@ -23,7 +23,7 @@ jobs: go_prev: ${{ steps.go_versions.outputs.prev }} steps: - name: Checkout code - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 with: persist-credentials: false - name: Resolve Go versions @@ -42,7 +42,7 @@ jobs: runs-on: ${{ matrix.platform }} steps: - name: Checkout code - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 with: fetch-depth: 0 persist-credentials: false @@ -74,7 +74,7 @@ jobs: continue-on-error: true steps: - name: Checkout code - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 with: persist-credentials: false - name: Run common test steps @@ -99,7 +99,7 @@ jobs: runs-on: ${{ matrix.platform }} steps: - name: Checkout code - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 with: persist-credentials: false - name: Run common test steps diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5e69a5272..e0304a61c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,7 +23,7 @@ jobs: go_prev: ${{ steps.go_versions.outputs.prev }} steps: - name: Checkout code - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 with: persist-credentials: false - name: Resolve Go versions @@ -41,7 +41,7 @@ jobs: runs-on: ${{ matrix.platform }} steps: - name: Checkout code - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 with: fetch-depth: 0 persist-credentials: false @@ -69,7 +69,7 @@ jobs: continue-on-error: true steps: - name: Checkout code - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 with: persist-credentials: false - name: Run common test steps @@ -94,7 +94,7 @@ jobs: runs-on: ${{ matrix.platform }} steps: - name: Checkout code - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 with: persist-credentials: false - name: Run common test steps diff --git a/.github/workflows/wpt.yml b/.github/workflows/wpt.yml index a54ab8dd3..248b8607d 100644 --- a/.github/workflows/wpt.yml +++ b/.github/workflows/wpt.yml @@ -18,7 +18,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 with: persist-credentials: false - name: Resolve Go versions diff --git a/.github/workflows/xk6.yml b/.github/workflows/xk6.yml index 3c171e0c2..614bd0fe8 100644 --- a/.github/workflows/xk6.yml +++ b/.github/workflows/xk6.yml @@ -27,7 +27,7 @@ jobs: runs-on: ${{ matrix.platform }} steps: - name: Checkout code - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 with: persist-credentials: false - name: Resolve Go versions From 2488042a7f9bd84ad113cb131d6495e23dff746d Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Thu, 16 Jul 2026 12:58:17 +0100 Subject: [PATCH 015/182] chore(deps): update actions/setup-go digest to 924ae3a (#6120) Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> --- .github/actions/lint/action.yml | 2 +- .github/actions/test-common/action.yml | 2 +- .github/workflows/browser_e2e.yml | 2 +- .github/workflows/build.yml | 2 +- .github/workflows/lint.yml | 2 +- .github/workflows/tc39.yml | 2 +- .github/workflows/wpt.yml | 2 +- .github/workflows/xk6.yml | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/actions/lint/action.yml b/.github/actions/lint/action.yml index 08760e81a..93c643632 100644 --- a/.github/actions/lint/action.yml +++ b/.github/actions/lint/action.yml @@ -8,7 +8,7 @@ runs: id: go_versions uses: ./.github/actions/go-versions - name: Install Go - uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6 + uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6 with: go-version: ${{ steps.go_versions.outputs.current }} check-latest: true diff --git a/.github/actions/test-common/action.yml b/.github/actions/test-common/action.yml index 78c79342c..4e0856aa9 100644 --- a/.github/actions/test-common/action.yml +++ b/.github/actions/test-common/action.yml @@ -18,7 +18,7 @@ runs: steps: - name: Install Go if: ${{ inputs.go_version != 'gotip' }} - uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6 + uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6 with: go-version: ${{ inputs.go_version }} check-latest: true diff --git a/.github/workflows/browser_e2e.yml b/.github/workflows/browser_e2e.yml index c7641b84d..7a763eab1 100644 --- a/.github/workflows/browser_e2e.yml +++ b/.github/workflows/browser_e2e.yml @@ -34,7 +34,7 @@ jobs: with: persist-credentials: false - name: Install Go - uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6 + uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6 with: go-version: 1.x check-latest: true diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fa959550e..2405e8b82 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -159,7 +159,7 @@ jobs: fetch-depth: 0 persist-credentials: false - name: Install Go - uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6 + uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6 with: go-version: ${{ needs.configure.outputs.go_version }} check-latest: true diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 4fa0fd9eb..03ca1c660 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -27,7 +27,7 @@ jobs: id: go_versions uses: ./.github/actions/go-versions - name: Install Go - uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6 + uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6 with: go-version: ${{ steps.go_versions.outputs.current }} check-latest: true diff --git a/.github/workflows/tc39.yml b/.github/workflows/tc39.yml index 9edf3b9da..df9fa954c 100644 --- a/.github/workflows/tc39.yml +++ b/.github/workflows/tc39.yml @@ -31,7 +31,7 @@ jobs: id: go_versions uses: ./.github/actions/go-versions - name: Install Go - uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6 + uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6 with: go-version: ${{ steps.go_versions.outputs.current }} check-latest: true diff --git a/.github/workflows/wpt.yml b/.github/workflows/wpt.yml index 248b8607d..d8d6a18e3 100644 --- a/.github/workflows/wpt.yml +++ b/.github/workflows/wpt.yml @@ -25,7 +25,7 @@ jobs: id: go_versions uses: ./.github/actions/go-versions - name: Install Go - uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6 + uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6 with: go-version: ${{ steps.go_versions.outputs.current }} check-latest: true diff --git a/.github/workflows/xk6.yml b/.github/workflows/xk6.yml index 614bd0fe8..7e8bfd126 100644 --- a/.github/workflows/xk6.yml +++ b/.github/workflows/xk6.yml @@ -36,7 +36,7 @@ jobs: uses: ./.github/actions/go-versions - name: Install Go if: matrix.go != 'tip' - uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6 + uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6 with: go-version: ${{ steps.go_versions.outputs.current }} check-latest: true From 13a94f3d68d4dbcd486fb6e22162dca7e984d4ed Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Thu, 16 Jul 2026 13:02:53 +0100 Subject: [PATCH 016/182] chore(deps): update alpine docker tag to v3.24.1 (#6098) | datasource | package | from | to | | ---------- | ------- | ------ | ------ | | docker | alpine | 3.24.0 | 3.24.1 | Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 5cafe4a1f..d18926c03 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,7 @@ RUN apk --no-cache add git=~2 RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -trimpath -o /usr/bin/k6 # Runtime stage -FROM alpine:3.24.0@sha256:a2d49ea686c2adfe3c992e47dc3b5e7fa6e6b5055609400dc2acaeb241c829f4 as release +FROM alpine:3.24.1@sha256:28bd5fe8b56d1bd048e5babf5b10710ebe0bae67db86916198a6eec434943f8b as release RUN adduser -D -u 12345 -g 12345 k6 COPY --from=builder /usr/bin/k6 /usr/bin/k6 From ab2043dd6b972e7ef2ec8f86cabf684d5d98cdfb Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Thu, 16 Jul 2026 13:03:06 +0100 Subject: [PATCH 017/182] fix(deps): update golangx (#6097) | datasource | package | from | to | | ---------- | ------------------- | ------- | ------- | | go | golang.org/x/crypto | v0.53.0 | v0.54.0 | | go | golang.org/x/net | v0.56.0 | v0.57.0 | | go | golang.org/x/sync | v0.21.0 | v0.22.0 | | go | golang.org/x/term | v0.44.0 | v0.45.0 | Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> --- go.mod | 12 +++---- go.sum | 24 ++++++------- .../golang.org/x/net/http2/transport_wrap.go | 24 +++++++------ vendor/golang.org/x/net/idna/idna.go | 6 +++- .../golang.org/x/sync/semaphore/semaphore.go | 17 ++++++--- vendor/golang.org/x/sys/unix/syscall_linux.go | 1 + .../x/sys/unix/syscall_linux_386.go | 1 - .../x/sys/unix/syscall_linux_amd64.go | 1 - .../x/sys/unix/syscall_linux_arm.go | 1 - .../x/sys/unix/syscall_linux_arm64.go | 1 - .../x/sys/unix/syscall_linux_loong64.go | 1 - .../x/sys/unix/syscall_linux_mips64x.go | 1 - .../x/sys/unix/syscall_linux_mipsx.go | 1 - .../x/sys/unix/syscall_linux_ppc.go | 1 - .../x/sys/unix/syscall_linux_ppc64x.go | 1 - .../x/sys/unix/syscall_linux_riscv64.go | 1 - .../x/sys/unix/syscall_linux_s390x.go | 1 - .../x/sys/unix/syscall_linux_sparc64.go | 1 - vendor/golang.org/x/sys/unix/zerrors_linux.go | 8 ++++- .../golang.org/x/sys/unix/zsyscall_linux.go | 17 +++++++++ .../x/sys/unix/zsyscall_linux_386.go | 17 --------- .../x/sys/unix/zsyscall_linux_amd64.go | 17 --------- .../x/sys/unix/zsyscall_linux_arm.go | 17 --------- .../x/sys/unix/zsyscall_linux_arm64.go | 17 --------- .../x/sys/unix/zsyscall_linux_loong64.go | 17 --------- .../x/sys/unix/zsyscall_linux_mips.go | 17 --------- .../x/sys/unix/zsyscall_linux_mips64.go | 17 --------- .../x/sys/unix/zsyscall_linux_mips64le.go | 17 --------- .../x/sys/unix/zsyscall_linux_mipsle.go | 17 --------- .../x/sys/unix/zsyscall_linux_ppc.go | 17 --------- .../x/sys/unix/zsyscall_linux_ppc64.go | 17 --------- .../x/sys/unix/zsyscall_linux_ppc64le.go | 17 --------- .../x/sys/unix/zsyscall_linux_riscv64.go | 17 --------- .../x/sys/unix/zsyscall_linux_s390x.go | 17 --------- .../x/sys/unix/zsyscall_linux_sparc64.go | 17 --------- .../x/sys/windows/security_windows.go | 36 +++++++++++++++++++ .../x/sys/windows/syscall_windows.go | 8 +++-- .../golang.org/x/sys/windows/types_windows.go | 1 + vendor/golang.org/x/text/cases/context.go | 2 +- vendor/golang.org/x/text/cases/map.go | 4 +-- vendor/golang.org/x/text/collate/collate.go | 4 +-- .../x/text/unicode/norm/forminfo.go | 9 ++++- vendor/golang.org/x/text/unicode/norm/iter.go | 8 ++--- .../x/text/unicode/norm/normalize.go | 20 +++++------ vendor/modules.txt | 12 +++---- 45 files changed, 148 insertions(+), 332 deletions(-) diff --git a/go.mod b/go.mod index e26baa51c..b876e92d8 100644 --- a/go.mod +++ b/go.mod @@ -56,11 +56,11 @@ require ( go.opentelemetry.io/otel/trace v1.44.0 go.opentelemetry.io/proto/otlp v1.10.0 go.uber.org/goleak v1.3.0 - golang.org/x/crypto v0.53.0 + golang.org/x/crypto v0.54.0 golang.org/x/crypto/x509roots/fallback v0.0.0-20260609182332-5f2de1a9f1e2 - golang.org/x/net v0.56.0 - golang.org/x/sync v0.21.0 - golang.org/x/term v0.44.0 + golang.org/x/net v0.57.0 + golang.org/x/sync v0.22.0 + golang.org/x/term v0.45.0 golang.org/x/time v0.15.0 google.golang.org/grpc v1.81.1 google.golang.org/protobuf v1.36.11 @@ -95,8 +95,8 @@ require ( github.com/tidwall/pretty v1.2.1 // indirect go.opentelemetry.io/auto/sdk v1.2.1 // indirect go.yaml.in/yaml/v2 v2.4.2 // indirect - golang.org/x/sys v0.46.0 // indirect - golang.org/x/text v0.38.0 // indirect + golang.org/x/sys v0.47.0 // indirect + golang.org/x/text v0.40.0 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20260526163538-3dc84a4a5aaa // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20260526163538-3dc84a4a5aaa // indirect gopkg.in/cenkalti/backoff.v1 v1.1.0 // indirect diff --git a/go.sum b/go.sum index 54d38a9eb..fe3992c38 100644 --- a/go.sum +++ b/go.sum @@ -248,8 +248,8 @@ golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliY golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= -golang.org/x/crypto v0.53.0 h1:QZ4Muo8THX6CizN2vPPd5fBGHyogrdK9fG4wLPFUsto= -golang.org/x/crypto v0.53.0/go.mod h1:DNLU434OwVakk9PzuwV8w62mAJpRJL3vsgcfp4Qnsio= +golang.org/x/crypto v0.54.0 h1:YLIA59K4fiNzHzjnZt2tUJQjQtUWfWbeHBqKtk3eScw= +golang.org/x/crypto v0.54.0/go.mod h1:KWL8ny2AZdGR2cWmzeHrp2azQPGogOv+HeQaVEXC2dk= golang.org/x/crypto/x509roots/fallback v0.0.0-20260609182332-5f2de1a9f1e2 h1:nQAdbnDzK0eYA4IKMp9xUaZq2UOkAYU5kBWQOSqwjP8= golang.org/x/crypto/x509roots/fallback v0.0.0-20260609182332-5f2de1a9f1e2/go.mod h1:+UoQFNBq2p2wO+Q6ddVtYc25GZ6VNdOMyyrd4nrqrKs= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -283,8 +283,8 @@ golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4= -golang.org/x/net v0.56.0 h1:Rw8j/hFzGvJUZwNBXnAtf5sVDVt+65SK2C7IxCxZt5o= -golang.org/x/net v0.56.0/go.mod h1:D3Ku6r+V6JROoZK144D2XfMHFcMq/0zSfLelVTCFKec= +golang.org/x/net v0.57.0 h1:K5+3DljvIuDG9/Jv9rvyMywYNFCQ9RSUY6OOTTkT+tE= +golang.org/x/net v0.57.0/go.mod h1:KpXc8iv+r3XplLAG/f7Jsf9RPszJzdR0f58q9vGOuEU= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -297,8 +297,8 @@ golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= -golang.org/x/sync v0.21.0 h1:HLII4xRRTtCRkxYp4HNFF0Js/Og6q2i++KXbg0gHCwM= -golang.org/x/sync v0.21.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0= +golang.org/x/sync v0.22.0 h1:SZjpbeLmrCk4xhRSZFNZW5gFUeCeFgjekvI/+gfScek= +golang.org/x/sync v0.22.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -324,8 +324,8 @@ golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.46.0 h1:noSf2Fq6F8DBgS+LysIkx7rIExoNHJsxOAtPp4rthXw= -golang.org/x/sys v0.46.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= +golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs= +golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= @@ -335,8 +335,8 @@ golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU= golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY= golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM= -golang.org/x/term v0.44.0 h1:0rLvDRCtNj0gZkyIXhCyOb2OAzEhLVqc4B+hrsBhrmc= -golang.org/x/term v0.44.0/go.mod h1:7ze4MdzUzLXpSAoFP1H0bOI9aXDqveSvatT5vKcFh2Y= +golang.org/x/term v0.45.0 h1:NwWyBmoJCbfTHpxrWoZ9C6/VxOf7ic219I8xZZFdrf0= +golang.org/x/term v0.45.0/go.mod h1:9aqxs0blBcrm/n0L9QW0aRVD+ktan8ssZromtqJC43w= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= @@ -346,8 +346,8 @@ golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= -golang.org/x/text v0.38.0 h1:sXmwo9DwP3OK9EZ7PqAdaooSGozfl/3a6/xJcbzPRhE= -golang.org/x/text v0.38.0/go.mod h1:YXZt3QhHUKYT53r2lLKFIVi6Ao1jdzrTR/KQ09qyxF4= +golang.org/x/text v0.40.0 h1:Ub2Z6/xjgF1WrYQz2nuITOEegKFtiIy+rieRJ5lHZKs= +golang.org/x/text v0.40.0/go.mod h1:hpnzDAfGV753zIKo+wk3u1bVKCGPbrnF7+7LBF/UHVY= golang.org/x/time v0.15.0 h1:bbrp8t3bGUeFOx08pvsMYRTCVSMk89u4tKbNOZbp88U= golang.org/x/time v0.15.0/go.mod h1:Y4YMaQmXwGQZoFaVFk4YpCt4FLQMYKZe9oeV/f4MSno= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/vendor/golang.org/x/net/http2/transport_wrap.go b/vendor/golang.org/x/net/http2/transport_wrap.go index eab2e6b07..534e77ab9 100644 --- a/vendor/golang.org/x/net/http2/transport_wrap.go +++ b/vendor/golang.org/x/net/http2/transport_wrap.go @@ -55,7 +55,7 @@ type transportConfig struct { // Registered is called by net/http.Transport.RegisterProtocol, // to let us know that it understands the registration mechanism we're using. func (t transportConfig) Registered(t1 *http.Transport) { - t.t.t1 = t1 + t.t.lazyt1 = t1 } func (t transportConfig) DisableCompression() bool { @@ -145,29 +145,30 @@ func (t transportConfig) DialFromContext(ctx context.Context, network, address s type transportInternal struct { initOnce sync.Once - t1 *http.Transport + lazyt1 *http.Transport } -func (t *Transport) init() { +func (t *Transport) init() *http.Transport { t.initOnce.Do(func() { - if t.t1 != nil { + if t.lazyt1 != nil { return } t1 := &http.Transport{} t.configure(t1) }) + return t.lazyt1 } func (t *Transport) configure(t1 *http.Transport) { t1.RegisterProtocol("http/2", transportConfig{t}) - // tr2.t1 is set by transportConfig.Registered. - if t.t1 != t1 { + // tr2.lazyt1 is set by transportConfig.Registered. + if t.lazyt1 != t1 { panic("http2: net/http does not support this version of x/net/http2") } } func (t *Transport) roundTripOpt(req *http.Request, opt RoundTripOpt) (*http.Response, error) { - t.init() + t1 := t.init() if req.URL.Scheme == "http" && !t.AllowHTTP { return nil, errors.New("http2: unencrypted HTTP/2 not enabled") @@ -188,22 +189,23 @@ func (t *Transport) roundTripOpt(req *http.Request, opt RoundTripOpt) (*http.Res ctx := context.WithValue(req.Context(), http2TransportContextKey{}, t) req = req.WithContext(ctx) - return t.t1.RoundTrip(req) + return t1.RoundTrip(req) } func (t *Transport) closeIdleConnections() { - t.init() - t.t1.CloseIdleConnections() + t1 := t.init() + t1.CloseIdleConnections() } func (t *Transport) newUserClientConn(c net.Conn) (*ClientConn, error) { + t1 := t.init() // http.Transport's NewClientConn doesn't provide a supported way to create // a connection from a net.Conn. (This might be useful to add in the future?) // We're going to craftily sneak one in via the context key, with the // scheme of "http/2" telling NewClientConn to look for it. ctx := context.WithValue(context.Background(), netConnContextKey{}, c) - nhcc, err := t.t1.NewClientConn(ctx, "http/2", "") + nhcc, err := t1.NewClientConn(ctx, "http/2", "") if err != nil { return nil, err } diff --git a/vendor/golang.org/x/net/idna/idna.go b/vendor/golang.org/x/net/idna/idna.go index 22767125b..e2f28fed4 100644 --- a/vendor/golang.org/x/net/idna/idna.go +++ b/vendor/golang.org/x/net/idna/idna.go @@ -400,7 +400,11 @@ func (p *Profile) process(s string, toASCII bool) (string, error) { // Spec says keep the old label. continue } - if unicode16 && err == nil && len(u) > 0 && isASCII(u) { + if err == nil && len(u) > 0 && isASCII(u) { + // UTS 43 pre-revision 33 doesn't classify a xn-- label + // which contains only ASCII characters as an error, + // but that's a specification bug and a security issue. + // Always return an error in this case. err = punyError(enc) } isBidi = isBidi || bidirule.DirectionString(u) != bidi.LeftToRight diff --git a/vendor/golang.org/x/sync/semaphore/semaphore.go b/vendor/golang.org/x/sync/semaphore/semaphore.go index 040c5bc50..96a035aed 100644 --- a/vendor/golang.org/x/sync/semaphore/semaphore.go +++ b/vendor/golang.org/x/sync/semaphore/semaphore.go @@ -24,7 +24,7 @@ func NewWeighted(n int64) *Weighted { } // Weighted provides a way to bound concurrent access to a resource. -// The callers can request access with a given weight. +// The callers can request access with a given non-negative weight. type Weighted struct { size int64 cur int64 @@ -32,10 +32,13 @@ type Weighted struct { waiters list.List } -// Acquire acquires the semaphore with a weight of n, blocking until resources +// Acquire acquires the semaphore with a non-negative weight of n, blocking until resources // are available or ctx is done. On success, returns nil. On failure, returns // ctx.Err() and leaves the semaphore unchanged. func (s *Weighted) Acquire(ctx context.Context, n int64) error { + if n < 0 { + panic("semaphore: n < 0") + } done := ctx.Done() s.mu.Lock() @@ -106,9 +109,12 @@ func (s *Weighted) Acquire(ctx context.Context, n int64) error { } } -// TryAcquire acquires the semaphore with a weight of n without blocking. +// TryAcquire acquires the semaphore with a non-negative weight of n without blocking. // On success, returns true. On failure, returns false and leaves the semaphore unchanged. func (s *Weighted) TryAcquire(n int64) bool { + if n < 0 { + panic("semaphore: n < 0") + } s.mu.Lock() success := s.size-s.cur >= n && s.waiters.Len() == 0 if success { @@ -118,8 +124,11 @@ func (s *Weighted) TryAcquire(n int64) bool { return success } -// Release releases the semaphore with a weight of n. +// Release releases the semaphore with a non-negative weight of n. func (s *Weighted) Release(n int64) { + if n < 0 { + panic("semaphore: n < 0") + } s.mu.Lock() s.cur -= n if s.cur < 0 { diff --git a/vendor/golang.org/x/sys/unix/syscall_linux.go b/vendor/golang.org/x/sys/unix/syscall_linux.go index ce4d7ab1e..21e2bfa39 100644 --- a/vendor/golang.org/x/sys/unix/syscall_linux.go +++ b/vendor/golang.org/x/sys/unix/syscall_linux.go @@ -1874,6 +1874,7 @@ func Dup2(oldfd, newfd int) error { //sys Dup3(oldfd int, newfd int, flags int) (err error) //sysnb EpollCreate1(flag int) (fd int, err error) //sysnb EpollCtl(epfd int, op int, fd int, event *EpollEvent) (err error) +//sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) = SYS_EPOLL_PWAIT //sys Eventfd(initval uint, flags int) (fd int, err error) = SYS_EVENTFD2 //sys Exit(code int) = SYS_EXIT_GROUP //sys Fallocate(fd int, mode uint32, off int64, len int64) (err error) diff --git a/vendor/golang.org/x/sys/unix/syscall_linux_386.go b/vendor/golang.org/x/sys/unix/syscall_linux_386.go index 506dafa7b..210d545c9 100644 --- a/vendor/golang.org/x/sys/unix/syscall_linux_386.go +++ b/vendor/golang.org/x/sys/unix/syscall_linux_386.go @@ -20,7 +20,6 @@ func setTimeval(sec, usec int64) Timeval { // 64-bit file system and 32-bit uid calls // (386 default is 32-bit file system and 16-bit uid). -//sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) //sys Fadvise(fd int, offset int64, length int64, advice int) (err error) = SYS_FADVISE64_64 //sys Fchown(fd int, uid int, gid int) (err error) = SYS_FCHOWN32 //sys Fstat(fd int, stat *Stat_t) (err error) = SYS_FSTAT64 diff --git a/vendor/golang.org/x/sys/unix/syscall_linux_amd64.go b/vendor/golang.org/x/sys/unix/syscall_linux_amd64.go index d557cf8de..a9a52f231 100644 --- a/vendor/golang.org/x/sys/unix/syscall_linux_amd64.go +++ b/vendor/golang.org/x/sys/unix/syscall_linux_amd64.go @@ -6,7 +6,6 @@ package unix -//sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) //sys Fadvise(fd int, offset int64, length int64, advice int) (err error) = SYS_FADVISE64 //sys Fchown(fd int, uid int, gid int) (err error) //sys Fstat(fd int, stat *Stat_t) (err error) diff --git a/vendor/golang.org/x/sys/unix/syscall_linux_arm.go b/vendor/golang.org/x/sys/unix/syscall_linux_arm.go index ecf92bfa2..54474c20f 100644 --- a/vendor/golang.org/x/sys/unix/syscall_linux_arm.go +++ b/vendor/golang.org/x/sys/unix/syscall_linux_arm.go @@ -44,7 +44,6 @@ func Seek(fd int, offset int64, whence int) (newoffset int64, err error) { // 64-bit file system and 32-bit uid calls // (16-bit uid calls are not always supported in newer kernels) -//sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) //sys Fchown(fd int, uid int, gid int) (err error) = SYS_FCHOWN32 //sys Fstat(fd int, stat *Stat_t) (err error) = SYS_FSTAT64 //sys Fstatat(dirfd int, path string, stat *Stat_t, flags int) (err error) = SYS_FSTATAT64 diff --git a/vendor/golang.org/x/sys/unix/syscall_linux_arm64.go b/vendor/golang.org/x/sys/unix/syscall_linux_arm64.go index 173738077..e9f30db97 100644 --- a/vendor/golang.org/x/sys/unix/syscall_linux_arm64.go +++ b/vendor/golang.org/x/sys/unix/syscall_linux_arm64.go @@ -8,7 +8,6 @@ package unix import "unsafe" -//sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) = SYS_EPOLL_PWAIT //sys Fadvise(fd int, offset int64, length int64, advice int) (err error) = SYS_FADVISE64 //sys Fchown(fd int, uid int, gid int) (err error) //sys Fstat(fd int, stat *Stat_t) (err error) diff --git a/vendor/golang.org/x/sys/unix/syscall_linux_loong64.go b/vendor/golang.org/x/sys/unix/syscall_linux_loong64.go index a3fd1d0b8..6f09ca200 100644 --- a/vendor/golang.org/x/sys/unix/syscall_linux_loong64.go +++ b/vendor/golang.org/x/sys/unix/syscall_linux_loong64.go @@ -8,7 +8,6 @@ package unix import "unsafe" -//sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) = SYS_EPOLL_PWAIT //sys Fadvise(fd int, offset int64, length int64, advice int) (err error) = SYS_FADVISE64 //sys Fchown(fd int, uid int, gid int) (err error) //sys Fstatfs(fd int, buf *Statfs_t) (err error) diff --git a/vendor/golang.org/x/sys/unix/syscall_linux_mips64x.go b/vendor/golang.org/x/sys/unix/syscall_linux_mips64x.go index 70963a95a..ca3b56597 100644 --- a/vendor/golang.org/x/sys/unix/syscall_linux_mips64x.go +++ b/vendor/golang.org/x/sys/unix/syscall_linux_mips64x.go @@ -6,7 +6,6 @@ package unix -//sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) //sys Fadvise(fd int, offset int64, length int64, advice int) (err error) = SYS_FADVISE64 //sys Fchown(fd int, uid int, gid int) (err error) //sys Fstatfs(fd int, buf *Statfs_t) (err error) diff --git a/vendor/golang.org/x/sys/unix/syscall_linux_mipsx.go b/vendor/golang.org/x/sys/unix/syscall_linux_mipsx.go index c218ebd28..54ba667b1 100644 --- a/vendor/golang.org/x/sys/unix/syscall_linux_mipsx.go +++ b/vendor/golang.org/x/sys/unix/syscall_linux_mipsx.go @@ -13,7 +13,6 @@ import ( func Syscall9(trap, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err syscall.Errno) -//sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) //sys Fadvise(fd int, offset int64, length int64, advice int) (err error) = SYS_FADVISE64 //sys Fchown(fd int, uid int, gid int) (err error) //sys Ftruncate(fd int, length int64) (err error) = SYS_FTRUNCATE64 diff --git a/vendor/golang.org/x/sys/unix/syscall_linux_ppc.go b/vendor/golang.org/x/sys/unix/syscall_linux_ppc.go index e6c48500c..ce4628590 100644 --- a/vendor/golang.org/x/sys/unix/syscall_linux_ppc.go +++ b/vendor/golang.org/x/sys/unix/syscall_linux_ppc.go @@ -11,7 +11,6 @@ import ( "unsafe" ) -//sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) //sys Fchown(fd int, uid int, gid int) (err error) //sys Fstat(fd int, stat *Stat_t) (err error) = SYS_FSTAT64 //sys Fstatat(dirfd int, path string, stat *Stat_t, flags int) (err error) = SYS_FSTATAT64 diff --git a/vendor/golang.org/x/sys/unix/syscall_linux_ppc64x.go b/vendor/golang.org/x/sys/unix/syscall_linux_ppc64x.go index 7286a9aa8..33f7af380 100644 --- a/vendor/golang.org/x/sys/unix/syscall_linux_ppc64x.go +++ b/vendor/golang.org/x/sys/unix/syscall_linux_ppc64x.go @@ -6,7 +6,6 @@ package unix -//sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) //sys Fadvise(fd int, offset int64, length int64, advice int) (err error) = SYS_FADVISE64 //sys Fchown(fd int, uid int, gid int) (err error) //sys Fstat(fd int, stat *Stat_t) (err error) diff --git a/vendor/golang.org/x/sys/unix/syscall_linux_riscv64.go b/vendor/golang.org/x/sys/unix/syscall_linux_riscv64.go index fc5543c5f..c658871e3 100644 --- a/vendor/golang.org/x/sys/unix/syscall_linux_riscv64.go +++ b/vendor/golang.org/x/sys/unix/syscall_linux_riscv64.go @@ -8,7 +8,6 @@ package unix import "unsafe" -//sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) = SYS_EPOLL_PWAIT //sys Fadvise(fd int, offset int64, length int64, advice int) (err error) = SYS_FADVISE64 //sys Fchown(fd int, uid int, gid int) (err error) //sys Fstat(fd int, stat *Stat_t) (err error) diff --git a/vendor/golang.org/x/sys/unix/syscall_linux_s390x.go b/vendor/golang.org/x/sys/unix/syscall_linux_s390x.go index 66f31210d..2c8587691 100644 --- a/vendor/golang.org/x/sys/unix/syscall_linux_s390x.go +++ b/vendor/golang.org/x/sys/unix/syscall_linux_s390x.go @@ -10,7 +10,6 @@ import ( "unsafe" ) -//sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) //sys Fadvise(fd int, offset int64, length int64, advice int) (err error) = SYS_FADVISE64 //sys Fchown(fd int, uid int, gid int) (err error) //sys Fstat(fd int, stat *Stat_t) (err error) diff --git a/vendor/golang.org/x/sys/unix/syscall_linux_sparc64.go b/vendor/golang.org/x/sys/unix/syscall_linux_sparc64.go index 11d1f1698..4964119af 100644 --- a/vendor/golang.org/x/sys/unix/syscall_linux_sparc64.go +++ b/vendor/golang.org/x/sys/unix/syscall_linux_sparc64.go @@ -6,7 +6,6 @@ package unix -//sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) //sys Fadvise(fd int, offset int64, length int64, advice int) (err error) = SYS_FADVISE64 //sys Fchown(fd int, uid int, gid int) (err error) //sys Fstat(fd int, stat *Stat_t) (err error) diff --git a/vendor/golang.org/x/sys/unix/zerrors_linux.go b/vendor/golang.org/x/sys/unix/zerrors_linux.go index 9d72a6b73..5bb51d7ae 100644 --- a/vendor/golang.org/x/sys/unix/zerrors_linux.go +++ b/vendor/golang.org/x/sys/unix/zerrors_linux.go @@ -1359,6 +1359,7 @@ const ( FAN_UNLIMITED_MARKS = 0x20 FAN_UNLIMITED_QUEUE = 0x10 FD_CLOEXEC = 0x1 + FD_PIDFS_ROOT = -0x2712 FD_SETSIZE = 0x400 FF0 = 0x0 FIB_RULE_DEV_DETACHED = 0x8 @@ -1970,6 +1971,8 @@ const ( MADV_DONTNEED = 0x4 MADV_DONTNEED_LOCKED = 0x18 MADV_FREE = 0x8 + MADV_GUARD_INSTALL = 0x66 + MADV_GUARD_REMOVE = 0x67 MADV_HUGEPAGE = 0xe MADV_HWPOISON = 0x64 MADV_KEEPONFORK = 0x13 @@ -2114,7 +2117,7 @@ const ( MS_NOSEC = 0x10000000 MS_NOSUID = 0x2 MS_NOSYMFOLLOW = 0x100 - MS_NOUSER = -0x80000000 + MS_NOUSER = 0x80000000 MS_POSIXACL = 0x10000 MS_PRIVATE = 0x40000 MS_RDONLY = 0x1 @@ -3786,6 +3789,9 @@ const ( TCPOPT_TIMESTAMP = 0x8 TCPOPT_TSTAMP_HDR = 0x101080a TCPOPT_WINDOW = 0x3 + TCP_AO_KEYF_EXCLUDE_OPT = 0x2 + TCP_AO_KEYF_IFINDEX = 0x1 + TCP_AO_MAXKEYLEN = 0x50 TCP_CC_INFO = 0x1a TCP_CM_INQ = 0x24 TCP_CONGESTION = 0xd diff --git a/vendor/golang.org/x/sys/unix/zsyscall_linux.go b/vendor/golang.org/x/sys/unix/zsyscall_linux.go index 80f40e401..5788c2a58 100644 --- a/vendor/golang.org/x/sys/unix/zsyscall_linux.go +++ b/vendor/golang.org/x/sys/unix/zsyscall_linux.go @@ -700,6 +700,23 @@ func EpollCtl(epfd int, op int, fd int, event *EpollEvent) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) { + var _p0 unsafe.Pointer + if len(events) > 0 { + _p0 = unsafe.Pointer(&events[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := Syscall6(SYS_EPOLL_PWAIT, uintptr(epfd), uintptr(_p0), uintptr(len(events)), uintptr(msec), 0, 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Eventfd(initval uint, flags int) (fd int, err error) { r0, _, e1 := Syscall(SYS_EVENTFD2, uintptr(initval), uintptr(flags), 0) fd = int(r0) diff --git a/vendor/golang.org/x/sys/unix/zsyscall_linux_386.go b/vendor/golang.org/x/sys/unix/zsyscall_linux_386.go index 4def3e9fc..254f33988 100644 --- a/vendor/golang.org/x/sys/unix/zsyscall_linux_386.go +++ b/vendor/golang.org/x/sys/unix/zsyscall_linux_386.go @@ -45,23 +45,6 @@ func Tee(rfd int, wfd int, len int, flags int) (n int64, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) { - var _p0 unsafe.Pointer - if len(events) > 0 { - _p0 = unsafe.Pointer(&events[0]) - } else { - _p0 = unsafe.Pointer(&_zero) - } - r0, _, e1 := Syscall6(SYS_EPOLL_WAIT, uintptr(epfd), uintptr(_p0), uintptr(len(events)), uintptr(msec), 0, 0) - n = int(r0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func Fadvise(fd int, offset int64, length int64, advice int) (err error) { _, _, e1 := Syscall6(SYS_FADVISE64_64, uintptr(fd), uintptr(offset), uintptr(offset>>32), uintptr(length), uintptr(length>>32), uintptr(advice)) if e1 != 0 { diff --git a/vendor/golang.org/x/sys/unix/zsyscall_linux_amd64.go b/vendor/golang.org/x/sys/unix/zsyscall_linux_amd64.go index fef2bc8ba..27c05db1a 100644 --- a/vendor/golang.org/x/sys/unix/zsyscall_linux_amd64.go +++ b/vendor/golang.org/x/sys/unix/zsyscall_linux_amd64.go @@ -45,23 +45,6 @@ func Tee(rfd int, wfd int, len int, flags int) (n int64, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) { - var _p0 unsafe.Pointer - if len(events) > 0 { - _p0 = unsafe.Pointer(&events[0]) - } else { - _p0 = unsafe.Pointer(&_zero) - } - r0, _, e1 := Syscall6(SYS_EPOLL_WAIT, uintptr(epfd), uintptr(_p0), uintptr(len(events)), uintptr(msec), 0, 0) - n = int(r0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func Fadvise(fd int, offset int64, length int64, advice int) (err error) { _, _, e1 := Syscall6(SYS_FADVISE64, uintptr(fd), uintptr(offset), uintptr(length), uintptr(advice), 0, 0) if e1 != 0 { diff --git a/vendor/golang.org/x/sys/unix/zsyscall_linux_arm.go b/vendor/golang.org/x/sys/unix/zsyscall_linux_arm.go index a9fd76a88..840d85bfc 100644 --- a/vendor/golang.org/x/sys/unix/zsyscall_linux_arm.go +++ b/vendor/golang.org/x/sys/unix/zsyscall_linux_arm.go @@ -213,23 +213,6 @@ func sendmsg(s int, msg *Msghdr, flags int) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) { - var _p0 unsafe.Pointer - if len(events) > 0 { - _p0 = unsafe.Pointer(&events[0]) - } else { - _p0 = unsafe.Pointer(&_zero) - } - r0, _, e1 := Syscall6(SYS_EPOLL_WAIT, uintptr(epfd), uintptr(_p0), uintptr(len(events)), uintptr(msec), 0, 0) - n = int(r0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func Fchown(fd int, uid int, gid int) (err error) { _, _, e1 := Syscall(SYS_FCHOWN32, uintptr(fd), uintptr(uid), uintptr(gid)) if e1 != 0 { diff --git a/vendor/golang.org/x/sys/unix/zsyscall_linux_arm64.go b/vendor/golang.org/x/sys/unix/zsyscall_linux_arm64.go index 460065028..fe414498b 100644 --- a/vendor/golang.org/x/sys/unix/zsyscall_linux_arm64.go +++ b/vendor/golang.org/x/sys/unix/zsyscall_linux_arm64.go @@ -45,23 +45,6 @@ func Tee(rfd int, wfd int, len int, flags int) (n int64, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) { - var _p0 unsafe.Pointer - if len(events) > 0 { - _p0 = unsafe.Pointer(&events[0]) - } else { - _p0 = unsafe.Pointer(&_zero) - } - r0, _, e1 := Syscall6(SYS_EPOLL_PWAIT, uintptr(epfd), uintptr(_p0), uintptr(len(events)), uintptr(msec), 0, 0) - n = int(r0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func Fadvise(fd int, offset int64, length int64, advice int) (err error) { _, _, e1 := Syscall6(SYS_FADVISE64, uintptr(fd), uintptr(offset), uintptr(length), uintptr(advice), 0, 0) if e1 != 0 { diff --git a/vendor/golang.org/x/sys/unix/zsyscall_linux_loong64.go b/vendor/golang.org/x/sys/unix/zsyscall_linux_loong64.go index c8987d264..eb358ce05 100644 --- a/vendor/golang.org/x/sys/unix/zsyscall_linux_loong64.go +++ b/vendor/golang.org/x/sys/unix/zsyscall_linux_loong64.go @@ -45,23 +45,6 @@ func Tee(rfd int, wfd int, len int, flags int) (n int64, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) { - var _p0 unsafe.Pointer - if len(events) > 0 { - _p0 = unsafe.Pointer(&events[0]) - } else { - _p0 = unsafe.Pointer(&_zero) - } - r0, _, e1 := Syscall6(SYS_EPOLL_PWAIT, uintptr(epfd), uintptr(_p0), uintptr(len(events)), uintptr(msec), 0, 0) - n = int(r0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func Fadvise(fd int, offset int64, length int64, advice int) (err error) { _, _, e1 := Syscall6(SYS_FADVISE64, uintptr(fd), uintptr(offset), uintptr(length), uintptr(advice), 0, 0) if e1 != 0 { diff --git a/vendor/golang.org/x/sys/unix/zsyscall_linux_mips.go b/vendor/golang.org/x/sys/unix/zsyscall_linux_mips.go index 921f43061..c437622f1 100644 --- a/vendor/golang.org/x/sys/unix/zsyscall_linux_mips.go +++ b/vendor/golang.org/x/sys/unix/zsyscall_linux_mips.go @@ -45,23 +45,6 @@ func Tee(rfd int, wfd int, len int, flags int) (n int64, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) { - var _p0 unsafe.Pointer - if len(events) > 0 { - _p0 = unsafe.Pointer(&events[0]) - } else { - _p0 = unsafe.Pointer(&_zero) - } - r0, _, e1 := Syscall6(SYS_EPOLL_WAIT, uintptr(epfd), uintptr(_p0), uintptr(len(events)), uintptr(msec), 0, 0) - n = int(r0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func Fadvise(fd int, offset int64, length int64, advice int) (err error) { _, _, e1 := Syscall9(SYS_FADVISE64, uintptr(fd), 0, uintptr(offset>>32), uintptr(offset), uintptr(length>>32), uintptr(length), uintptr(advice), 0, 0) if e1 != 0 { diff --git a/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64.go b/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64.go index 44f067829..bc4ca2558 100644 --- a/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64.go +++ b/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64.go @@ -45,23 +45,6 @@ func Tee(rfd int, wfd int, len int, flags int) (n int64, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) { - var _p0 unsafe.Pointer - if len(events) > 0 { - _p0 = unsafe.Pointer(&events[0]) - } else { - _p0 = unsafe.Pointer(&_zero) - } - r0, _, e1 := Syscall6(SYS_EPOLL_WAIT, uintptr(epfd), uintptr(_p0), uintptr(len(events)), uintptr(msec), 0, 0) - n = int(r0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func Fadvise(fd int, offset int64, length int64, advice int) (err error) { _, _, e1 := Syscall6(SYS_FADVISE64, uintptr(fd), uintptr(offset), uintptr(length), uintptr(advice), 0, 0) if e1 != 0 { diff --git a/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64le.go b/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64le.go index e7fa0abf0..5051435ce 100644 --- a/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64le.go +++ b/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64le.go @@ -45,23 +45,6 @@ func Tee(rfd int, wfd int, len int, flags int) (n int64, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) { - var _p0 unsafe.Pointer - if len(events) > 0 { - _p0 = unsafe.Pointer(&events[0]) - } else { - _p0 = unsafe.Pointer(&_zero) - } - r0, _, e1 := Syscall6(SYS_EPOLL_WAIT, uintptr(epfd), uintptr(_p0), uintptr(len(events)), uintptr(msec), 0, 0) - n = int(r0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func Fadvise(fd int, offset int64, length int64, advice int) (err error) { _, _, e1 := Syscall6(SYS_FADVISE64, uintptr(fd), uintptr(offset), uintptr(length), uintptr(advice), 0, 0) if e1 != 0 { diff --git a/vendor/golang.org/x/sys/unix/zsyscall_linux_mipsle.go b/vendor/golang.org/x/sys/unix/zsyscall_linux_mipsle.go index 8c5125675..33aa5418a 100644 --- a/vendor/golang.org/x/sys/unix/zsyscall_linux_mipsle.go +++ b/vendor/golang.org/x/sys/unix/zsyscall_linux_mipsle.go @@ -45,23 +45,6 @@ func Tee(rfd int, wfd int, len int, flags int) (n int64, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) { - var _p0 unsafe.Pointer - if len(events) > 0 { - _p0 = unsafe.Pointer(&events[0]) - } else { - _p0 = unsafe.Pointer(&_zero) - } - r0, _, e1 := Syscall6(SYS_EPOLL_WAIT, uintptr(epfd), uintptr(_p0), uintptr(len(events)), uintptr(msec), 0, 0) - n = int(r0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func Fadvise(fd int, offset int64, length int64, advice int) (err error) { _, _, e1 := Syscall9(SYS_FADVISE64, uintptr(fd), 0, uintptr(offset), uintptr(offset>>32), uintptr(length), uintptr(length>>32), uintptr(advice), 0, 0) if e1 != 0 { diff --git a/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc.go b/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc.go index 7392fd45e..3bef8ef1d 100644 --- a/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc.go +++ b/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc.go @@ -45,23 +45,6 @@ func Tee(rfd int, wfd int, len int, flags int) (n int64, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) { - var _p0 unsafe.Pointer - if len(events) > 0 { - _p0 = unsafe.Pointer(&events[0]) - } else { - _p0 = unsafe.Pointer(&_zero) - } - r0, _, e1 := Syscall6(SYS_EPOLL_WAIT, uintptr(epfd), uintptr(_p0), uintptr(len(events)), uintptr(msec), 0, 0) - n = int(r0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func Fchown(fd int, uid int, gid int) (err error) { _, _, e1 := Syscall(SYS_FCHOWN, uintptr(fd), uintptr(uid), uintptr(gid)) if e1 != 0 { diff --git a/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64.go b/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64.go index 41180434e..fc1bd4e2c 100644 --- a/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64.go +++ b/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64.go @@ -45,23 +45,6 @@ func Tee(rfd int, wfd int, len int, flags int) (n int64, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) { - var _p0 unsafe.Pointer - if len(events) > 0 { - _p0 = unsafe.Pointer(&events[0]) - } else { - _p0 = unsafe.Pointer(&_zero) - } - r0, _, e1 := Syscall6(SYS_EPOLL_WAIT, uintptr(epfd), uintptr(_p0), uintptr(len(events)), uintptr(msec), 0, 0) - n = int(r0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func Fadvise(fd int, offset int64, length int64, advice int) (err error) { _, _, e1 := Syscall6(SYS_FADVISE64, uintptr(fd), uintptr(offset), uintptr(length), uintptr(advice), 0, 0) if e1 != 0 { diff --git a/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64le.go b/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64le.go index 40c6ce7ae..d78fe7dab 100644 --- a/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64le.go +++ b/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64le.go @@ -45,23 +45,6 @@ func Tee(rfd int, wfd int, len int, flags int) (n int64, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) { - var _p0 unsafe.Pointer - if len(events) > 0 { - _p0 = unsafe.Pointer(&events[0]) - } else { - _p0 = unsafe.Pointer(&_zero) - } - r0, _, e1 := Syscall6(SYS_EPOLL_WAIT, uintptr(epfd), uintptr(_p0), uintptr(len(events)), uintptr(msec), 0, 0) - n = int(r0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func Fadvise(fd int, offset int64, length int64, advice int) (err error) { _, _, e1 := Syscall6(SYS_FADVISE64, uintptr(fd), uintptr(offset), uintptr(length), uintptr(advice), 0, 0) if e1 != 0 { diff --git a/vendor/golang.org/x/sys/unix/zsyscall_linux_riscv64.go b/vendor/golang.org/x/sys/unix/zsyscall_linux_riscv64.go index 2cfe34adb..76dcf87d0 100644 --- a/vendor/golang.org/x/sys/unix/zsyscall_linux_riscv64.go +++ b/vendor/golang.org/x/sys/unix/zsyscall_linux_riscv64.go @@ -45,23 +45,6 @@ func Tee(rfd int, wfd int, len int, flags int) (n int64, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) { - var _p0 unsafe.Pointer - if len(events) > 0 { - _p0 = unsafe.Pointer(&events[0]) - } else { - _p0 = unsafe.Pointer(&_zero) - } - r0, _, e1 := Syscall6(SYS_EPOLL_PWAIT, uintptr(epfd), uintptr(_p0), uintptr(len(events)), uintptr(msec), 0, 0) - n = int(r0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func Fadvise(fd int, offset int64, length int64, advice int) (err error) { _, _, e1 := Syscall6(SYS_FADVISE64, uintptr(fd), uintptr(offset), uintptr(length), uintptr(advice), 0, 0) if e1 != 0 { diff --git a/vendor/golang.org/x/sys/unix/zsyscall_linux_s390x.go b/vendor/golang.org/x/sys/unix/zsyscall_linux_s390x.go index 61e6f0709..2cf020f2b 100644 --- a/vendor/golang.org/x/sys/unix/zsyscall_linux_s390x.go +++ b/vendor/golang.org/x/sys/unix/zsyscall_linux_s390x.go @@ -45,23 +45,6 @@ func Tee(rfd int, wfd int, len int, flags int) (n int64, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) { - var _p0 unsafe.Pointer - if len(events) > 0 { - _p0 = unsafe.Pointer(&events[0]) - } else { - _p0 = unsafe.Pointer(&_zero) - } - r0, _, e1 := Syscall6(SYS_EPOLL_WAIT, uintptr(epfd), uintptr(_p0), uintptr(len(events)), uintptr(msec), 0, 0) - n = int(r0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func Fadvise(fd int, offset int64, length int64, advice int) (err error) { _, _, e1 := Syscall6(SYS_FADVISE64, uintptr(fd), uintptr(offset), uintptr(length), uintptr(advice), 0, 0) if e1 != 0 { diff --git a/vendor/golang.org/x/sys/unix/zsyscall_linux_sparc64.go b/vendor/golang.org/x/sys/unix/zsyscall_linux_sparc64.go index 834b84204..527637623 100644 --- a/vendor/golang.org/x/sys/unix/zsyscall_linux_sparc64.go +++ b/vendor/golang.org/x/sys/unix/zsyscall_linux_sparc64.go @@ -45,23 +45,6 @@ func Tee(rfd int, wfd int, len int, flags int) (n int64, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) { - var _p0 unsafe.Pointer - if len(events) > 0 { - _p0 = unsafe.Pointer(&events[0]) - } else { - _p0 = unsafe.Pointer(&_zero) - } - r0, _, e1 := Syscall6(SYS_EPOLL_WAIT, uintptr(epfd), uintptr(_p0), uintptr(len(events)), uintptr(msec), 0, 0) - n = int(r0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func Fadvise(fd int, offset int64, length int64, advice int) (err error) { _, _, e1 := Syscall6(SYS_FADVISE64, uintptr(fd), uintptr(offset), uintptr(length), uintptr(advice), 0, 0) if e1 != 0 { diff --git a/vendor/golang.org/x/sys/windows/security_windows.go b/vendor/golang.org/x/sys/windows/security_windows.go index 6c955cea1..783621561 100644 --- a/vendor/golang.org/x/sys/windows/security_windows.go +++ b/vendor/golang.org/x/sys/windows/security_windows.go @@ -1109,17 +1109,53 @@ const ( ) // This type is the union inside of TRUSTEE and must be created using one of the TrusteeValueFrom* functions. +// +// Go pointers stored in a TrusteeValue must be pinned using [runtime.Pinner] +// for the lifetime of the TrusteeValue. type TrusteeValue uintptr +// TrusteeValueFromString is unsafe and should not be used. +// +// It returns a uintptr containing a reference to newly-allocated memory +// which will be freed by the garbage collector. +// There is no way for the caller to safely reference this memory. +// +// To create a [TrusteeValue] from a string, use: +// +// p, err := windows.UTF16PtrFromString(s) +// if err != nil { +// // handle error +// } +// +// // Pin the string for as long as it is used. +// var pinner runtime.Pinner +// pinner.Pin(p) +// defer pinner.Unpin() +// +// tv := TrusteeValue(unsafe.Pointer(p)) +// +// Deprecated: TrusteeValueFromString is unsafe and should not be used. func TrusteeValueFromString(str string) TrusteeValue { return TrusteeValue(unsafe.Pointer(StringToUTF16Ptr(str))) } + +// TrusteeValueFromSID returns a [TrusteeValue] referencing sid. +// +// The caller must pin sid using a [runtime.Pinner] for the lifetime of the TrusteeValue. func TrusteeValueFromSID(sid *SID) TrusteeValue { return TrusteeValue(unsafe.Pointer(sid)) } + +// TrusteeValueFromObjectsAndSid returns a [TrusteeValue] referencing objectsAndSid. +// +// The caller must pin objectsAndSid using a [runtime.Pinner] for the lifetime of the TrusteeValue. func TrusteeValueFromObjectsAndSid(objectsAndSid *OBJECTS_AND_SID) TrusteeValue { return TrusteeValue(unsafe.Pointer(objectsAndSid)) } + +// TrusteeValueFromObjectsAndName returns a [TrusteeValue] referencing objectsAndName. +// +// The caller must pin objectsAndName using a [runtime.Pinner] for the lifetime of the TrusteeValue. func TrusteeValueFromObjectsAndName(objectsAndName *OBJECTS_AND_NAME) TrusteeValue { return TrusteeValue(unsafe.Pointer(objectsAndName)) } diff --git a/vendor/golang.org/x/sys/windows/syscall_windows.go b/vendor/golang.org/x/sys/windows/syscall_windows.go index 9755bca9f..e6966b4c3 100644 --- a/vendor/golang.org/x/sys/windows/syscall_windows.go +++ b/vendor/golang.org/x/sys/windows/syscall_windows.go @@ -1728,11 +1728,15 @@ func (s *NTUnicodeString) String() string { // the more common *uint16 string type. func NewNTString(s string) (*NTString, error) { var nts NTString - s8, err := BytePtrFromString(s) + s8, err := ByteSliceFromString(s) if err != nil { return nil, err } - RtlInitString(&nts, s8) + // The source string plus its terminating NUL must fit within MAX_USHORT. + if len(s8) > MAX_USHORT { + return nil, syscall.EINVAL + } + RtlInitString(&nts, &s8[0]) return &nts, nil } diff --git a/vendor/golang.org/x/sys/windows/types_windows.go b/vendor/golang.org/x/sys/windows/types_windows.go index d2574a73e..75a50b316 100644 --- a/vendor/golang.org/x/sys/windows/types_windows.go +++ b/vendor/golang.org/x/sys/windows/types_windows.go @@ -169,6 +169,7 @@ const ( FORMAT_MESSAGE_ARGUMENT_ARRAY = 8192 FORMAT_MESSAGE_MAX_WIDTH_MASK = 255 + MAX_USHORT = 0xffff MAX_PATH = 260 MAX_LONG_PATH = 32768 diff --git a/vendor/golang.org/x/text/cases/context.go b/vendor/golang.org/x/text/cases/context.go index e9aa9e193..a28f45d7b 100644 --- a/vendor/golang.org/x/text/cases/context.go +++ b/vendor/golang.org/x/text/cases/context.go @@ -249,7 +249,7 @@ func upper(c *context) bool { return c.copy() } -// isUpper writes the isUppercase version of the current rune to dst. +// isUpper reports whether the current rune is in upper case. func isUpper(c *context) bool { ct := c.caseType() if c.info&hasMappingMask == 0 || ct == cUpper { diff --git a/vendor/golang.org/x/text/cases/map.go b/vendor/golang.org/x/text/cases/map.go index 0f7c6a14b..51a683092 100644 --- a/vendor/golang.org/x/text/cases/map.go +++ b/vendor/golang.org/x/text/cases/map.go @@ -774,7 +774,7 @@ func nlTitle(c *context) bool { // From CLDR: // # Special titlecasing for Dutch initial "ij". // ::Any-Title(); - // # Fix up Ij at the beginning of a "word" (per Any-Title, notUAX #29) + // # Fix up Ij at the beginning of a "word" (per Any-Title, not UAX #29) // [:^WB=ALetter:] [:WB=Extend:]* [[:WB=MidLetter:][:WB=MidNumLet:]]? { Ij } → IJ ; if c.src[c.pSrc] != 'I' && c.src[c.pSrc] != 'i' { return title(c) @@ -794,7 +794,7 @@ func nlTitleSpan(c *context) bool { // From CLDR: // # Special titlecasing for Dutch initial "ij". // ::Any-Title(); - // # Fix up Ij at the beginning of a "word" (per Any-Title, notUAX #29) + // # Fix up Ij at the beginning of a "word" (per Any-Title, not UAX #29) // [:^WB=ALetter:] [:WB=Extend:]* [[:WB=MidLetter:][:WB=MidNumLet:]]? { Ij } → IJ ; if c.src[c.pSrc] != 'I' { return isTitle(c) diff --git a/vendor/golang.org/x/text/collate/collate.go b/vendor/golang.org/x/text/collate/collate.go index 449c73c8d..ee1ccce3b 100644 --- a/vendor/golang.org/x/text/collate/collate.go +++ b/vendor/golang.org/x/text/collate/collate.go @@ -200,8 +200,8 @@ func (c *Collator) Key(buf *Buffer, str []byte) []byte { // KeyFromString returns the collation key for str. // Passing the buffer buf may avoid memory allocations. -// The returned slice will point to an allocation in Buffer and will retain -// valid until the next call to buf.ResetKeys(). +// The returned slice will point to an allocation in Buffer and will remain +// valid until the next call to buf.Reset(). func (c *Collator) KeyFromString(buf *Buffer, str string) []byte { // See https://www.unicode.org/reports/tr10/#Main_Algorithm for more details. buf.init() diff --git a/vendor/golang.org/x/text/unicode/norm/forminfo.go b/vendor/golang.org/x/text/unicode/norm/forminfo.go index f3a234e5f..b3cf5d9bd 100644 --- a/vendor/golang.org/x/text/unicode/norm/forminfo.go +++ b/vendor/golang.org/x/text/unicode/norm/forminfo.go @@ -121,8 +121,12 @@ func (p Properties) BoundaryAfter() bool { // // When all 6 bits are zero, the character is inert, meaning it is never // influenced by normalization. +// +// We set flags to 0x80 (high bit 7 unused in quick check data) to indicate an invalid rune. type qcInfo uint8 +func (p Properties) isInvalid() bool { return p.flags == 0x80 } + func (p Properties) isYesC() bool { return p.flags&0x10 == 0 } func (p Properties) isYesD() bool { return p.flags&0x4 == 0 } @@ -247,6 +251,9 @@ func (f Form) PropertiesString(s string) Properties { // to a Properties. See the comment at the top of the file // for more information on the format. func compInfo(v uint16, sz int) Properties { + if sz == 0 { + return Properties{flags: 0x80, size: 1} + } if v == 0 { return Properties{size: uint8(sz)} } else if v >= 0x8000 { @@ -254,7 +261,7 @@ func compInfo(v uint16, sz int) Properties { size: uint8(sz), ccc: uint8(v), tccc: uint8(v), - flags: qcInfo(v >> 8), + flags: qcInfo(v>>8) & 0x3f, } if p.ccc > 0 || p.combinesBackward() { p.nLead = uint8(p.flags & 0x3) diff --git a/vendor/golang.org/x/text/unicode/norm/iter.go b/vendor/golang.org/x/text/unicode/norm/iter.go index 417c6b268..3cc059224 100644 --- a/vendor/golang.org/x/text/unicode/norm/iter.go +++ b/vendor/golang.org/x/text/unicode/norm/iter.go @@ -376,16 +376,12 @@ func nextComposed(i *Iter) []byte { goto doNorm } prevCC = i.info.tccc - sz := int(i.info.size) - if sz == 0 { - sz = 1 // illegal rune: copy byte-by-byte - } - p := outp + sz + p := outp + int(i.info.size) if p > len(i.buf) { break } outp = p - i.p += sz + i.p += int(i.info.size) if i.p >= i.rb.nsrc { i.setDone() break diff --git a/vendor/golang.org/x/text/unicode/norm/normalize.go b/vendor/golang.org/x/text/unicode/norm/normalize.go index 4747ad07a..60b1511ca 100644 --- a/vendor/golang.org/x/text/unicode/norm/normalize.go +++ b/vendor/golang.org/x/text/unicode/norm/normalize.go @@ -148,7 +148,7 @@ func (f Form) IsNormalString(s string) bool { // patched buffer and whether the decomposition is still in progress. func patchTail(rb *reorderBuffer) bool { info, p := lastRuneStart(&rb.f, rb.out) - if p == -1 || info.size == 0 { + if p == -1 || info.isInvalid() { return true } end := p + int(info.size) @@ -225,7 +225,7 @@ func doAppend(rb *reorderBuffer, out []byte, p int) []byte { } fd := &rb.f if doMerge { - var info Properties + info := Properties{flags: 0x80, size: 1} // invalid rune if p < n { info = fd.info(src, p) if !info.BoundaryBefore() || info.nLeadingNonStarters() > 0 { @@ -235,7 +235,7 @@ func doAppend(rb *reorderBuffer, out []byte, p int) []byte { p = decomposeSegment(rb, p, true) } } - if info.size == 0 { + if info.isInvalid() { rb.doFlush() // Append incomplete UTF-8 encoding. return src.appendSlice(rb.out, p, n) @@ -314,7 +314,7 @@ func (f *formInfo) quickSpan(src input, i, end int, atEOF bool) (n int, ok bool) continue } info := f.info(src, i) - if info.size == 0 { + if info.isInvalid() { if atEOF { // include incomplete runes return n, true @@ -379,7 +379,7 @@ func (f Form) firstBoundary(src input, nsrc int) int { // CGJ insertion points correctly. Luckily it doesn't have to. for { info := fd.info(src, i) - if info.size == 0 { + if info.isInvalid() { return -1 } if s := ss.next(info); s != ssSuccess { @@ -424,7 +424,7 @@ func (f Form) nextBoundary(src input, nsrc int, atEOF bool) int { } fd := formTable[f] info := fd.info(src, 0) - if info.size == 0 { + if info.isInvalid() { if atEOF { return 1 } @@ -435,7 +435,7 @@ func (f Form) nextBoundary(src input, nsrc int, atEOF bool) int { for i := int(info.size); i < nsrc; i += int(info.size) { info = fd.info(src, i) - if info.size == 0 { + if info.isInvalid() { if atEOF { return i } @@ -465,7 +465,7 @@ func lastBoundary(fd *formInfo, b []byte) int { if p == -1 { return -1 } - if info.size == 0 { // ends with incomplete rune + if info.isInvalid() { // ends with incomplete rune if p == 0 { // starts with incomplete rune return -1 } @@ -504,7 +504,7 @@ func lastBoundary(fd *formInfo, b []byte) int { func decomposeSegment(rb *reorderBuffer, sp int, atEOF bool) int { // Force one character to be consumed. info := rb.f.info(rb.src, sp) - if info.size == 0 { + if info.isInvalid() { return 0 } if s := rb.ss.next(info); s == ssStarter { @@ -528,7 +528,7 @@ func decomposeSegment(rb *reorderBuffer, sp int, atEOF bool) int { break } info = rb.f.info(rb.src, sp) - if info.size == 0 { + if info.isInvalid() { if !atEOF { return int(iShortSrc) } diff --git a/vendor/modules.txt b/vendor/modules.txt index 0b0516bcc..b14ed144f 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -446,7 +446,7 @@ go.uber.org/goleak/internal/stack # go.yaml.in/yaml/v2 v2.4.2 ## explicit; go 1.15 go.yaml.in/yaml/v2 -# golang.org/x/crypto v0.53.0 +# golang.org/x/crypto v0.54.0 ## explicit; go 1.25.0 golang.org/x/crypto/md4 golang.org/x/crypto/ocsp @@ -455,7 +455,7 @@ golang.org/x/crypto/ripemd160 ## explicit; go 1.25.0 golang.org/x/crypto/x509roots/fallback golang.org/x/crypto/x509roots/fallback/bundle -# golang.org/x/net v0.56.0 +# golang.org/x/net v0.57.0 ## explicit; go 1.25.0 golang.org/x/net/context golang.org/x/net/html @@ -468,20 +468,20 @@ golang.org/x/net/internal/httpcommon golang.org/x/net/internal/httpsfv golang.org/x/net/internal/timeseries golang.org/x/net/trace -# golang.org/x/sync v0.21.0 +# golang.org/x/sync v0.22.0 ## explicit; go 1.25.0 golang.org/x/sync/errgroup golang.org/x/sync/semaphore -# golang.org/x/sys v0.46.0 +# golang.org/x/sys v0.47.0 ## explicit; go 1.25.0 golang.org/x/sys/plan9 golang.org/x/sys/unix golang.org/x/sys/windows golang.org/x/sys/windows/registry -# golang.org/x/term v0.44.0 +# golang.org/x/term v0.45.0 ## explicit; go 1.25.0 golang.org/x/term -# golang.org/x/text v0.38.0 +# golang.org/x/text v0.40.0 ## explicit; go 1.25.0 golang.org/x/text/cases golang.org/x/text/collate From 430e48577c684515394fa49e128cdf613b0a9e9e Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Thu, 16 Jul 2026 13:03:22 +0100 Subject: [PATCH 018/182] chore(deps): update actions/stale digest to 1e223db (#6121) Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> --- .github/workflows/stale.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 2347823b6..3d5cd1908 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Run stale action - uses: actions/stale@b5d41d4e1d5dceea10e7104786b73624c18a190f # v10 + uses: actions/stale@1e223db275d687790206a7acac4d1a11bd6fe629 # v10 with: repo-token: ${{ secrets.GITHUB_TOKEN }} operations-per-run: 50 From 5c3385425fdbbb9f739d18a073c40b4ac45236e2 Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Thu, 16 Jul 2026 13:03:36 +0100 Subject: [PATCH 019/182] chore(deps): update grafana/shared-workflows/ action to (#6076) Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> --- .github/workflows/publish-techdocs.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-techdocs.yaml b/.github/workflows/publish-techdocs.yaml index ba17fd343..deb330aec 100644 --- a/.github/workflows/publish-techdocs.yaml +++ b/.github/workflows/publish-techdocs.yaml @@ -14,7 +14,7 @@ concurrency: permissions: {} jobs: publish-docs: - uses: grafana/shared-workflows/.github/workflows/publish-techdocs.yaml@e5b7989c92b55fe3ac6dd006d6de49082ba8c507 # main + uses: grafana/shared-workflows/.github/workflows/publish-techdocs.yaml@86e65f7130d6e52d79f4b56a925b431c4aaea359 # main permissions: contents: read id-token: write From 849628c898c24629f46b18d5b486ee310eea913d Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Thu, 16 Jul 2026 13:04:04 +0100 Subject: [PATCH 020/182] chore(deps): update grafana/shared-workflows/aws-auth action to v1.0.4 (#6123) | datasource | package | from | to | | ------------- | ------------------------ | --------------- | --------------- | | github-digest | grafana/shared-workflows | aws-auth/v1.0.3 | aws-auth/v1.0.4 | Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2405e8b82..8ae3da9a7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -664,7 +664,7 @@ jobs: PGP_SIGN_KEY_PASSPHRASE=pgp:PGP_SIGN_KEY_PASSPHRASE PGP_SIGN_KEY=pgp:PGP_SIGN_KEY S3_BUCKET=s3:AWS_S3_BUCKET - - uses: grafana/shared-workflows/actions/aws-auth@85022085ed5314601c05d10e846de56bdd71e369 # aws-auth/v1.0.3 + - uses: grafana/shared-workflows/actions/aws-auth@bb04b9b1c3903959957c63d1370b2d49a4b978d0 # aws-auth/v1.0.4 with: aws-region: "us-east-2" role-arn: ${{ fromJSON(steps.get-secrets.outputs.secrets).IAM_ROLE_ARN }} From c01d997b369953b811cb2fdcdea3be9342ceb03e Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Thu, 16 Jul 2026 13:04:18 +0100 Subject: [PATCH 021/182] chore(deps): update golangci/golangci-lint-action action to v9.3.0 (#6122) | datasource | package | from | to | | ----------- | ----------------------------- | ------ | ------ | | github-tags | golangci/golangci-lint-action | v9.2.0 | v9.3.0 | Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> --- .github/actions/lint/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/lint/action.yml b/.github/actions/lint/action.yml index 93c643632..0a9d60bcf 100644 --- a/.github/actions/lint/action.yml +++ b/.github/actions/lint/action.yml @@ -30,7 +30,7 @@ runs: echo "GolangCIVersion=$(head -n 1 "${{ github.action_path }}/.golangci.yml" | tr -d '# ')" >> "${GITHUB_OUTPUT}" id: getenv - name: golangci-lint - uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20 # v9.2.0 + uses: golangci/golangci-lint-action@ba0d7d2ec06a0ea1cb5fa41b2e4a3ab91d21278a # v9.3.0 with: version: ${{ steps.getenv.outputs.GolangCIVersion }} args: "--config=${{ github.action_path }}/.golangci.yml" From 8e6101a2c51302d8694922c9117b542f7872a0ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Crevon?= Date: Thu, 16 Jul 2026 14:43:41 +0200 Subject: [PATCH 022/182] Implement WebAPI streams' WritableStream (#6132) * feat(streams): implement the WritableStream Web API Adds a spec-compliant WritableStream to the experimental streams module, alongside its WritableStreamDefaultWriter and WritableStreamDefaultController, following the same structure and conventions as the existing ReadableStream implementation (one method per WHATWG Streams abstract operation, with spec-linked doc comments). The stream's JavaScript object is built as a plain, extensible object so that consumers (and the WPT recording helpers) can attach their own properties; a hidden reference to the Go value is kept for brand checks and the writer constructor. Because settling a promise from Go runs its reactions synchronously in the k6/Sobek event loop, promise settlements are batched and flushed once the surrounding synchronous state changes complete, so reactions observe up-to-date state and settle in specification order. AbortSignal (controller.signal), ByteLengthQueuingStrategy and piping are not supported yet and are intentionally left out. * test(streams): run the WritableStream Web Platform Tests Runs the WHATWG Streams WPT 'writable-streams' suite against the module, the same way the readable-streams suite is run: the tests are checked out and patched by tests/checkout.sh, then executed by TestWritableStream. The shared harness setup now also loads resources/recording-streams.js, which the writable-streams tests rely on (recordingWritableStream). Two patches adapt the suite to k6: - aborting.any.js: comments out the AbortSignal/DOMException tests (unsupported) and two promise-ordering tests that only fail under the fully concurrent suite due to the event loop's synchronous promise settlement (they pass in isolation). - reentrant-strategy.any.js: comments out one pathological test that recursively calls write() from strategy.size() and depends on exact microtask interleaving. * docs(streams): add a WritableStream example Adds examples/experimental/writable-streams.js, mirroring the existing ReadableStream example, to demonstrate creating a WritableStream, acquiring a writer, and writing chunks while respecting backpressure via writer.ready. * fix(streams): reject controller constructor calls * fix(streams): handle undefined sink members * fix(streams): reuse writable controller wrapper * fix(streams): handle abrupt size conversion * fix(streams): track queued promise settlements * fix(streams): put writable writers on prototype * refactor(streams): address review cleanup * refactor(streams): simplify writer prototype setup * fix(streams): protect writable stream prototypes * test(streams): restore writable stream regressions * fix(streams): align writable Web IDL bindings * refactor(streams): centralize promise helpers Move the stream-local promise wrapper next to the existing Sobek helpers and rename goja.go to reflect the runtime used by k6. This keeps promise creation, settlement, and handled-state behavior in one place instead of maintaining parallel readable and writable implementations. Represent ReadableStream reader closed promises with the same wrapper used by WritableStream. These promises settle synchronously on the runtime thread, so the event-loop-oriented js/promises helper is intentionally not used. WritableStream transaction scheduling remains local because it implements writable-specific settlement ordering. * fix(streams): keep promise accessors private ReadableStream's closed-promise accessors return the package-private promise wrapper and are only used inside the streams package. Keep the methods private as well so the API reflects their scope and satisfies revive's unexported-return check. --- examples/experimental/writable-streams.js | 47 + .../modules/k6/experimental/streams/goja.go | 115 -- .../modules/k6/experimental/streams/module.go | 162 ++- .../readable_stream_default_controller.go | 3 +- .../streams/readable_stream_default_reader.go | 3 +- .../streams/readable_stream_reader.go | 75 +- .../experimental/streams/readable_streams.go | 25 +- .../streams/readable_streams_test.go | 1 + .../modules/k6/experimental/streams/sobek.go | 226 ++++ .../streams/tests/aborting.any.js.patch | 349 +++++ .../tests/reentrant-strategy.any.js.patch | 77 ++ .../experimental/streams/underlying_sink.go | 90 ++ .../writable_stream_default_controller.go | 504 +++++++ .../streams/writable_stream_default_writer.go | 583 +++++++++ .../experimental/streams/writable_streams.go | 1156 +++++++++++++++++ .../writable_streams_regression_test.go | 213 +++ .../streams/writable_streams_test.go | 162 +++ 17 files changed, 3593 insertions(+), 198 deletions(-) create mode 100644 examples/experimental/writable-streams.js delete mode 100644 internal/js/modules/k6/experimental/streams/goja.go create mode 100644 internal/js/modules/k6/experimental/streams/sobek.go create mode 100644 internal/js/modules/k6/experimental/streams/tests/aborting.any.js.patch create mode 100644 internal/js/modules/k6/experimental/streams/tests/reentrant-strategy.any.js.patch create mode 100644 internal/js/modules/k6/experimental/streams/underlying_sink.go create mode 100644 internal/js/modules/k6/experimental/streams/writable_stream_default_controller.go create mode 100644 internal/js/modules/k6/experimental/streams/writable_stream_default_writer.go create mode 100644 internal/js/modules/k6/experimental/streams/writable_streams.go create mode 100644 internal/js/modules/k6/experimental/streams/writable_streams_regression_test.go create mode 100644 internal/js/modules/k6/experimental/streams/writable_streams_test.go diff --git a/examples/experimental/writable-streams.js b/examples/experimental/writable-streams.js new file mode 100644 index 000000000..3c2c4f8e3 --- /dev/null +++ b/examples/experimental/writable-streams.js @@ -0,0 +1,47 @@ +import { WritableStream } from 'k6/experimental/streams' +import { setTimeout } from 'k6/timers' + +function delay(milliseconds) { + return new Promise((resolve) => setTimeout(resolve, milliseconds)) +} + +// loggingStream returns a WritableStream whose underlying sink writes chunks slowly enough +// for the producer to observe and respect backpressure through writer.ready. +function loggingStream() { + const chunks = [] + + return new WritableStream({ + start() { + console.log('stream opened') + }, + async write(chunk) { + await delay(200) + + chunks.push(chunk) + console.log(`wrote ${chunk}`) + }, + close() { + console.log(`stream closed after receiving: ${chunks.join(', ')}`) + }, + abort(reason) { + console.log(`stream aborted: ${reason}`) + }, + }, { highWaterMark: 1 }) +} + +export default async function () { + const stream = loggingStream() + const writer = stream.getWriter() + const writes = [] + + for (let i = 1; i <= 5; i++) { + await writer.ready + writes.push(writer.write(`chunk ${i}`)) + } + + await Promise.all(writes) + await writer.close() + await writer.closed + + console.log('we are done') +} diff --git a/internal/js/modules/k6/experimental/streams/goja.go b/internal/js/modules/k6/experimental/streams/goja.go deleted file mode 100644 index 77521d9b3..000000000 --- a/internal/js/modules/k6/experimental/streams/goja.go +++ /dev/null @@ -1,115 +0,0 @@ -package streams - -import ( - "fmt" - "reflect" - - "github.com/grafana/sobek" - - "go.k6.io/k6/v2/js/common" - "go.k6.io/k6/v2/js/modules" -) - -// newResolvedPromise instantiates a new resolved promise. -func newResolvedPromise(vu modules.VU, with sobek.Value) *sobek.Promise { - promise, resolve, _ := vu.Runtime().NewPromise() - err := resolve(with) - if err != nil { // TODO(@mstoykov): likely better to actually call Promise.resolve directly - panic(err) - } - - return promise -} - -// newRejectedPromise instantiates a new rejected promise. -func newRejectedPromise(vu modules.VU, with any) *sobek.Promise { - promise, _, reject := vu.Runtime().NewPromise() - err := reject(with) - if err != nil { - panic(err) - } - return promise -} - -// promiseThen facilitates instantiating a new promise and defining callbacks for to be executed -// on fulfillment as well as rejection, directly from Go. -func promiseThen( - rt *sobek.Runtime, - promise *sobek.Promise, - onFulfilled, onRejected func(sobek.Value), -) (*sobek.Promise, error) { - val, err := rt.RunString( - `(function(promise, onFulfilled, onRejected) { return promise.then(onFulfilled, onRejected) })`) - if err != nil { - return nil, newError(RuntimeError, "unable to initialize promiseThen internal helper function") - } - - cal, ok := sobek.AssertFunction(val) - if !ok { - return nil, newError(RuntimeError, "the internal promiseThen helper is not a function") - } - - if onRejected == nil { - val, err = cal(sobek.Undefined(), rt.ToValue(promise), rt.ToValue(onFulfilled)) - } else { - val, err = cal(sobek.Undefined(), rt.ToValue(promise), rt.ToValue(onFulfilled), rt.ToValue(onRejected)) - } - - if err != nil { - return nil, err - } - - newPromise, ok := val.Export().(*sobek.Promise) - if !ok { - return nil, newError(RuntimeError, "unable to cast the internal promiseThen helper's return value to a promise") - } - - return newPromise, nil -} - -// isNumber returns true if the given sobek.Value holds a number -func isNumber(value sobek.Value) bool { - _, isFloat := value.Export().(float64) - _, isInt := value.Export().(int64) - - return isFloat || isInt -} - -// isNonNegativeNumber implements the [IsNonNegativeNumber] algorithm. -// -// [IsNonNegativeNumber]: https://streams.spec.whatwg.org/#is-non-negative-number -func isNonNegativeNumber(value sobek.Value) bool { - if common.IsNullish(value) { - return false - } - - if !isNumber(value) { - return false - } - - if value.ToFloat() < 0 || value.ToInteger() < 0 { - return false - } - - return true -} - -// setReadOnlyPropertyOf sets a read-only property on the given [sobek.Object]. -func setReadOnlyPropertyOf(obj *sobek.Object, objName, propName string, propValue sobek.Value) error { - err := obj.DefineDataProperty(propName, - propValue, - sobek.FLAG_FALSE, - sobek.FLAG_FALSE, - sobek.FLAG_TRUE, - ) - if err != nil { - return fmt.Errorf("unable to define %s read-only property on %s object; reason: %w", propName, objName, err) - } - - return nil -} - -// isObject determines whether the given [sobek.Value] is a [sobek.Object] or not. -func isObject(val sobek.Value) bool { - return val != nil && val.ExportType() != nil && val.ExportType().Kind() == reflect.Map -} diff --git a/internal/js/modules/k6/experimental/streams/module.go b/internal/js/modules/k6/experimental/streams/module.go index 6928aef59..a5c24c988 100644 --- a/internal/js/modules/k6/experimental/streams/module.go +++ b/internal/js/modules/k6/experimental/streams/module.go @@ -17,6 +17,11 @@ type ( // ModuleInstance is the module instance that will be created for each VU. ModuleInstance struct { vu modules.VU + + exports modules.Exports + + writableStreamPrototype *sobek.Object + writableStreamDefaultWriterPrototype *sobek.Object } ) @@ -33,18 +38,60 @@ func New() *RootModule { // NewModuleInstance creates a new instance of the module for a specific VU. func (rm *RootModule) NewModuleInstance(vu modules.VU) modules.Instance { - return &ModuleInstance{ - vu: vu, + mi := &ModuleInstance{vu: vu} + rt := vu.Runtime() + + // Convert the writable stream constructors once per VU. Besides keeping the exported + // constructor identities stable, this gives the implementation canonical prototypes that + // cannot be replaced by a caller-controlled `this` value. + writableStreamConstructor, err := newWebIDLConstructor(rt, "WritableStream", mi.NewWritableStream) + if err != nil { + throw(rt, err) + } + writableStreamDefaultWriterConstructor, err := newWebIDLConstructor( + rt, + "WritableStreamDefaultWriter", + mi.NewWritableStreamDefaultWriter, + ) + if err != nil { + throw(rt, err) } -} -// Exports returns the module exports, that will be available in the runtime. -func (mi *ModuleInstance) Exports() modules.Exports { - return modules.Exports{Named: map[string]any{ + mi.writableStreamPrototype = constructorPrototype(rt, writableStreamConstructor) + mi.writableStreamDefaultWriterPrototype = constructorPrototype(rt, writableStreamDefaultWriterConstructor) + if err := installWritableStreamPrototype(rt, mi.writableStreamPrototype); err != nil { + throw(rt, err) + } + if err := installWritableStreamDefaultWriterPrototype(rt, mi.writableStreamDefaultWriterPrototype); err != nil { + throw(rt, err) + } + mi.exports = modules.Exports{Named: map[string]any{ "ReadableStream": mi.NewReadableStream, "CountQueuingStrategy": mi.NewCountQueuingStrategy, "ReadableStreamDefaultReader": mi.NewReadableStreamDefaultReader, + "WritableStream": writableStreamConstructor, + "WritableStreamDefaultWriter": writableStreamDefaultWriterConstructor, }} + + return mi +} + +func constructorPrototype(rt *sobek.Runtime, constructor sobek.Value) *sobek.Object { + return constructor.ToObject(rt).Get("prototype").ToObject(rt) +} + +func requireNewTarget(rt *sobek.Runtime, call sobek.ConstructorCall, name string) { + // Web IDL interface constructors must be invoked with `new`. Rejecting every ordinary + // function call also prevents a caller-controlled `this` value from being used as an + // instance prototype. + if call.NewTarget == nil { + throw(rt, newTypeError(rt, name+" constructor must be called with new")) + } +} + +// Exports returns the module exports, that will be available in the runtime. +func (mi *ModuleInstance) Exports() modules.Exports { + return mi.exports } // NewReadableStream is the constructor for the ReadableStream object. @@ -134,6 +181,109 @@ func newReadableStream(vu modules.VU, call sobek.ConstructorCall) *sobek.Object return streamObj } + +// NewWritableStream is the constructor for the WritableStream object. +func (mi *ModuleInstance) NewWritableStream(call sobek.ConstructorCall) *sobek.Object { + rt := mi.vu.Runtime() + requireNewTarget(rt, call, "WritableStream") + + return newWritableStream(mi.vu, call, mi.writableStreamDefaultWriterPrototype) +} + +func newWritableStream( + vu modules.VU, + call sobek.ConstructorCall, + writerPrototype *sobek.Object, +) *sobek.Object { + rt := vu.Runtime() + + var ( + // 1. If underlyingSink is missing, set it to null. + underlyingSink *sobek.Object + + err error + strategy *sobek.Object + underlyingSinkDict UnderlyingSink + ) + + // We look for the queuing strategy first, and validate it before the underlying sink, + // in order to match the specification's argument conversion order and pass the Web + // Platform Tests constructor tests. + strategy = initializeStrategy(rt, call) + + // 2. Let underlyingSinkDict be underlyingSink, converted to an IDL value of type UnderlyingSink. + if len(call.Arguments) > 0 && !sobek.IsUndefined(call.Arguments[0]) { + // We first assert that it is an object (requirement). + if !isObject(call.Arguments[0]) { + throw(rt, newTypeError(rt, "underlyingSink must be an object")) + } + + // Then we try to convert it to an UnderlyingSink. + underlyingSink = call.Arguments[0].ToObject(rt) + underlyingSinkDict, err = NewUnderlyingSinkFromObject(rt, underlyingSink) + if err != nil { + throw(rt, err) + } + } + + // 3. If underlyingSinkDict["type"] exists, throw a RangeError exception. + if underlyingSinkDict.Type != nil && !sobek.IsUndefined(underlyingSinkDict.Type) { + throw(rt, newRangeError(rt, "'type' is not supported by WritableStream")) + } + + // 4. Perform ! InitializeWritableStream(this). + stream := &WritableStream{ + runtime: rt, + vu: vu, + writerPrototype: writerPrototype, + } + stream.initialize() + + // 5. Let sizeAlgorithm be ! ExtractSizeAlgorithm(strategy). + sizeAlgorithm := extractSizeAlgorithm(rt, strategy) + + // 6. Let highWaterMark be ? ExtractHighWaterMark(strategy, 1). + highWaterMark := extractHighWaterMark(rt, strategy, 1) + + // 7. Perform ? SetUpWritableStreamDefaultControllerFromUnderlyingSink(...). + stream.setupWritableStreamDefaultControllerFromUnderlyingSink( + underlyingSink, + underlyingSinkDict, + highWaterMark, + sizeAlgorithm, + ) + + return stream.toObject(call.This.Prototype()) +} + +// NewWritableStreamDefaultWriter is the constructor for the [WritableStreamDefaultWriter] object. +// +// [WritableStreamDefaultWriter]: https://streams.spec.whatwg.org/#writablestreamdefaultwriter +func (mi *ModuleInstance) NewWritableStreamDefaultWriter(call sobek.ConstructorCall) *sobek.Object { + rt := mi.vu.Runtime() + requireNewTarget(rt, call, "WritableStreamDefaultWriter") + + if len(call.Arguments) != 1 { + throw(rt, newTypeError(rt, "WritableStreamDefaultWriter takes a single argument")) + } + + stream := writableStreamFromValue(rt, call.Argument(0)) + if stream == nil { + throw(rt, newTypeError(rt, "WritableStreamDefaultWriter argument must be a WritableStream")) + } + + // 1. Perform ? SetUpWritableStreamDefaultWriter(this, stream). + writer := &WritableStreamDefaultWriter{} + writer.setup(stream) + + object, err := NewWritableStreamDefaultWriterObject(writer, call.This.Prototype()) + if err != nil { + throw(rt, err) + } + + return object +} + func defaultSizeFunc(_ sobek.Value) (float64, error) { return 1.0, nil } func initializeStrategy(rt *sobek.Runtime, call sobek.ConstructorCall) *sobek.Object { diff --git a/internal/js/modules/k6/experimental/streams/readable_stream_default_controller.go b/internal/js/modules/k6/experimental/streams/readable_stream_default_controller.go index fb0947531..f636dd3eb 100644 --- a/internal/js/modules/k6/experimental/streams/readable_stream_default_controller.go +++ b/internal/js/modules/k6/experimental/streams/readable_stream_default_controller.go @@ -76,7 +76,8 @@ func NewReadableStreamDefaultControllerObject(controller *ReadableStreamDefaultC // Exposing the properties of the [ReadableStreamController] interface if err := setReadOnlyPropertyOf(obj, objName, "constructor", rt.ToValue(func() sobek.Value { - return rt.ToValue(&ReadableStreamDefaultController{}) + throw(rt, newTypeError(rt, "ReadableStreamDefaultController is not constructable")) + return sobek.Undefined() })); err != nil { return nil, err } diff --git a/internal/js/modules/k6/experimental/streams/readable_stream_default_reader.go b/internal/js/modules/k6/experimental/streams/readable_stream_default_reader.go index 19090cc8d..2a61414e9 100644 --- a/internal/js/modules/k6/experimental/streams/readable_stream_default_reader.go +++ b/internal/js/modules/k6/experimental/streams/readable_stream_default_reader.go @@ -22,8 +22,7 @@ func NewReadableStreamDefaultReaderObject(reader *ReadableStreamDefaultReader) ( objName := "ReadableStreamDefaultReader" err := obj.DefineAccessorProperty("closed", rt.ToValue(func() *sobek.Promise { - p, _, _ := reader.GetClosed() - return p + return reader.getClosed().promise }), nil, sobek.FLAG_FALSE, sobek.FLAG_TRUE) if err != nil { return nil, err diff --git a/internal/js/modules/k6/experimental/streams/readable_stream_reader.go b/internal/js/modules/k6/experimental/streams/readable_stream_reader.go index 823a4622c..8ff5b86e9 100644 --- a/internal/js/modules/k6/experimental/streams/readable_stream_reader.go +++ b/internal/js/modules/k6/experimental/streams/readable_stream_reader.go @@ -35,11 +35,11 @@ type ReadableStreamGenericReader interface { // SetStream sets the stream that owns this reader. SetStream(stream *ReadableStream) - // GetClosed returns a [sobek.Promise] that resolves when the stream is closed. - GetClosed() (p *sobek.Promise, resolve, reject func(any) error) + // getClosed returns the promise that resolves when the stream is closed. + getClosed() *promiseWrapper - // SetClosed sets the [sobek.Promise] that resolves when the stream is closed. - SetClosed(p *sobek.Promise, resolve, reject func(any) error) + // setClosed sets the promise that resolves when the stream is closed. + setClosed(*promiseWrapper) // Cancel returns a [sobek.Promise] that resolves when the stream is canceled. Cancel(reason sobek.Value) *sobek.Promise @@ -47,9 +47,7 @@ type ReadableStreamGenericReader interface { // BaseReadableStreamReader is a base implement type BaseReadableStreamReader struct { - closedPromise *sobek.Promise - closedPromiseResolveFunc func(resolve any) error - closedPromiseRejectFunc func(reason any) error + closedPromise *promiseWrapper // stream is a [ReadableStream] instance that owns this reader stream *ReadableStream @@ -73,16 +71,14 @@ func (reader *BaseReadableStreamReader) SetStream(stream *ReadableStream) { reader.vu = stream.vu } -// GetClosed returns the reader's closed promise as well as its resolve and reject functions. -func (reader *BaseReadableStreamReader) GetClosed() (p *sobek.Promise, resolve, reject func(any) error) { - return reader.closedPromise, reader.closedPromiseResolveFunc, reader.closedPromiseRejectFunc +// getClosed returns the reader's closed promise. +func (reader *BaseReadableStreamReader) getClosed() *promiseWrapper { + return reader.closedPromise } -// SetClosed sets the reader's closed promise as well as its resolve and reject functions. -func (reader *BaseReadableStreamReader) SetClosed(p *sobek.Promise, resolve, reject func(any) error) { - reader.closedPromise = p - reader.closedPromiseResolveFunc = resolve - reader.closedPromiseRejectFunc = reject +// setClosed sets the reader's closed promise. +func (reader *BaseReadableStreamReader) setClosed(promise *promiseWrapper) { + reader.closedPromise = promise } // Cancel returns a [sobek.Promise] that resolves when the stream is canceled. @@ -134,24 +130,14 @@ func (reader *BaseReadableStreamReader) release() { // 4. If stream.[[state]] is "readable", reject reader.[[closedPromise]] with a TypeError exception. if stream.state == ReadableStreamStateReadable { - err := reader.closedPromiseRejectFunc(newTypeError(reader.runtime, "stream is readable").Err()) - if err != nil { - panic(err) - } + reader.closedPromise.rejectWith(newTypeError(reader.runtime, "stream is readable")) } else { // 5. Otherwise, set reader.[[closedPromise]] to a promise rejected with a TypeError exception. - reader.closedPromise = newRejectedPromise(stream.vu, newTypeError(reader.runtime, "stream is not readable").Err()) + reader.closedPromise = newRejectedPromiseWrapper( + stream.runtime, newTypeError(reader.runtime, "stream is not readable")) } // 6. Set reader.[[closedPromise]].[[PromiseIsHandled]] to true. - // FIXME: See https://github.com/dop251/goja/issues/565 - var ( - err error - doNothing = func(sobek.Value) {} - ) - _, err = promiseThen(stream.vu.Runtime(), reader.closedPromise, doNothing, doNothing) - if err != nil { - common.Throw(stream.vu.Runtime(), newError(RuntimeError, err.Error())) - } + markPromiseHandled(stream.runtime, reader.closedPromise.promise) // 7. Perform ! stream.[[controller]].[[ReleaseSteps]](). stream.controller.releaseSteps() @@ -190,7 +176,7 @@ func ReadableStreamReaderGenericInitialize(reader ReadableStreamGenericReader, s stream.reader = reader stream.Locked = true - promise, resolve, reject := stream.runtime.NewPromise() + promise := newPromiseWrapper(stream.runtime) switch stream.state { // 3. If stream.[[state]] is "readable", @@ -200,10 +186,7 @@ func ReadableStreamReaderGenericInitialize(reader ReadableStreamGenericReader, s // 4. Otherwise, if stream.[[state]] is "closed", case ReadableStreamStateClosed: // 4.1 Set reader.[[closedPromise]] to a promise resolved with undefined. - err := resolve(sobek.Undefined()) - if err != nil { - panic(err) // TODO(@mstoykov): probably better to move them out as errors - } + promise.resolveWith(sobek.Undefined()) // 5. Otherwise, default: // 5.1 Assert: stream.[[state]] is "errored". @@ -212,29 +195,15 @@ func ReadableStreamReaderGenericInitialize(reader ReadableStreamGenericReader, s } // 5.2 Set reader.[[closedPromise]] to a promise rejected with stream.[[storedError]]. - if jsErr, ok := stream.storedError.(*jsError); ok { - err := reject(jsErr.Err()) - if err != nil { - panic(err) - } + if _, ok := stream.storedError.(*jsError); ok { + promise.rejectWith(stream.storedError) } else { - err := reject(errToObj(stream.runtime, stream.storedError)) - if err != nil { - panic(err) - } + promise.rejectWith(errToObj(stream.runtime, stream.storedError)) } // 5.3 Set reader.[[closedPromise]].[[PromiseIsHandled]] to true. - // See https://github.com/dop251/goja/issues/565 - var ( - err error - doNothing = func(sobek.Value) {} - ) - _, err = promiseThen(stream.vu.Runtime(), promise, doNothing, doNothing) - if err != nil { - common.Throw(stream.vu.Runtime(), newError(RuntimeError, err.Error())) - } + markPromiseHandled(stream.runtime, promise.promise) } - reader.SetClosed(promise, resolve, reject) + reader.setClosed(promise) } diff --git a/internal/js/modules/k6/experimental/streams/readable_streams.go b/internal/js/modules/k6/experimental/streams/readable_streams.go index 988d868d0..36e5174f2 100644 --- a/internal/js/modules/k6/experimental/streams/readable_streams.go +++ b/internal/js/modules/k6/experimental/streams/readable_streams.go @@ -455,11 +455,7 @@ func (stream *ReadableStream) close() { common.Throw(stream.vu.Runtime(), newError(AssertionError, "reader is not a ReadableStreamGenericReader")) } - _, resolveFunc, _ := genericReader.GetClosed() - err := resolveFunc(sobek.Undefined()) - if err != nil { - panic(err) // TODO(@mstoykov): propagate as error instead - } + genericReader.getClosed().resolveWith(sobek.Undefined()) // 6. If reader implements ReadableStreamDefaultReader, defaultReader, ok := reader.(*ReadableStreamDefaultReader) @@ -506,24 +502,11 @@ func (stream *ReadableStream) error(e any) { } // 6. Reject reader.[[closedPromise]] with e. - var err error - promise, _, rejectFunc := genericReader.GetClosed() - if jsErr, ok := e.(*jsError); ok { - err = rejectFunc(jsErr.Err()) - } else { - err = rejectFunc(e) - } - if err != nil { - panic(err) // TODO(@mstoykov): propagate as error instead - } + promise := genericReader.getClosed() + promise.rejectWith(e) // 7. Set reader.[[closedPromise]].[[PromiseIsHandled]] to true. - // See https://github.com/dop251/goja/issues/565 - doNothing := func(sobek.Value) {} - _, err = promiseThen(stream.vu.Runtime(), promise, doNothing, doNothing) - if err != nil { - common.Throw(stream.vu.Runtime(), newError(RuntimeError, err.Error())) - } + markPromiseHandled(stream.runtime, promise.promise) // 8. If reader implements ReadableStreamDefaultReader, defaultReader, ok := reader.(*ReadableStreamDefaultReader) diff --git a/internal/js/modules/k6/experimental/streams/readable_streams_test.go b/internal/js/modules/k6/experimental/streams/readable_streams_test.go index 9c651ac37..d6e54df72 100644 --- a/internal/js/modules/k6/experimental/streams/readable_streams_test.go +++ b/internal/js/modules/k6/experimental/streams/readable_streams_test.go @@ -68,6 +68,7 @@ func newConfiguredRuntime(t testing.TB) *modulestest.Runtime { "resources/rs-test-templates.js", "resources/rs-utils.js", "resources/test-utils.js", + "resources/recording-streams.js", } for _, file := range files { compileAndRun(t, rt, webPlatformTestSuite+"/streams", file) diff --git a/internal/js/modules/k6/experimental/streams/sobek.go b/internal/js/modules/k6/experimental/streams/sobek.go new file mode 100644 index 000000000..e51fdf3f1 --- /dev/null +++ b/internal/js/modules/k6/experimental/streams/sobek.go @@ -0,0 +1,226 @@ +package streams + +import ( + "fmt" + "reflect" + "slices" + + "github.com/grafana/sobek" + + "go.k6.io/k6/v2/js/common" + "go.k6.io/k6/v2/js/modules" +) + +// newWebIDLConstructor wraps a native Sobek constructor so it follows Web IDL call semantics. +// Sobek otherwise treats a native constructor call without `new` exactly like construction and +// does not expose a NewTarget that lets the native function distinguish the two cases. +func newWebIDLConstructor(rt *sobek.Runtime, name string, constructor any) (sobek.Value, error) { + factory, err := rt.RunString(` +(function(constructor, name) { + const wrapper = function(...args) { + if (new.target === undefined) { + throw new TypeError(name + " constructor must be called with new"); + } + return Reflect.construct(constructor, args, new.target); + }; + Object.defineProperty(wrapper, "name", { value: name, configurable: true }); + return wrapper; +})`) + if err != nil { + return nil, err + } + + call, ok := sobek.AssertFunction(factory) + if !ok { + return nil, newError(RuntimeError, "Web IDL constructor wrapper factory is not a function") + } + + return call(sobek.Undefined(), rt.ToValue(constructor), rt.ToValue(name)) +} + +// promiseWrapper holds a [sobek.Promise] together with its resolve and reject functions, +// so that it can be settled later from Go code. +type promiseWrapper struct { + promise *sobek.Promise + resolve func(any) error + reject func(any) error + settlementQueued bool +} + +// newPromiseWrapper creates a new pending [promiseWrapper]. +func newPromiseWrapper(rt *sobek.Runtime) *promiseWrapper { + p, resolve, reject := rt.NewPromise() + return &promiseWrapper{promise: p, resolve: resolve, reject: reject} +} + +func (pw *promiseWrapper) isPending() bool { + return !pw.settlementQueued && pw.promise.State() == sobek.PromiseStatePending +} + +func (pw *promiseWrapper) queueSettlement() { + pw.settlementQueued = true +} + +// resolveWith resolves the wrapped promise with the given value. +func (pw *promiseWrapper) resolveWith(value any) { + pw.queueSettlement() + if err := pw.resolve(value); err != nil { + panic(err) // TODO(@mstoykov): propagate as error instead + } +} + +// rejectWith rejects the wrapped promise with the given reason, unwrapping [jsError] values. +func (pw *promiseWrapper) rejectWith(reason any) { + pw.queueSettlement() + if jsErr, ok := reason.(*jsError); ok { + reason = jsErr.Err() + } + if err := pw.reject(reason); err != nil { + panic(err) // TODO(@mstoykov): propagate as error instead + } +} + +// newResolvedPromiseWrapper creates a new [promiseWrapper] resolved with the given value. +func newResolvedPromiseWrapper(rt *sobek.Runtime, value any) *promiseWrapper { + pw := newPromiseWrapper(rt) + pw.resolveWith(value) + return pw +} + +// newRejectedPromiseWrapper creates a new [promiseWrapper] rejected with the given reason. +func newRejectedPromiseWrapper(rt *sobek.Runtime, reason any) *promiseWrapper { + pw := newPromiseWrapper(rt) + pw.rejectWith(reason) + return pw +} + +// newResolvedPromise instantiates a new resolved promise. +func newResolvedPromise(vu modules.VU, with sobek.Value) *sobek.Promise { + return newResolvedPromiseWrapper(vu.Runtime(), with).promise +} + +// newRejectedPromise instantiates a new rejected promise. +func newRejectedPromise(vu modules.VU, with any) *sobek.Promise { + return newRejectedPromiseWrapper(vu.Runtime(), with).promise +} + +// promiseThen facilitates instantiating a new promise and defining callbacks for to be executed +// on fulfillment as well as rejection, directly from Go. +func promiseThen( + rt *sobek.Runtime, + promise *sobek.Promise, + onFulfilled, onRejected func(sobek.Value), +) (*sobek.Promise, error) { + val, err := rt.RunString( + `(function(promise, onFulfilled, onRejected) { return promise.then(onFulfilled, onRejected) })`) + if err != nil { + return nil, newError(RuntimeError, "unable to initialize promiseThen internal helper function") + } + + cal, ok := sobek.AssertFunction(val) + if !ok { + return nil, newError(RuntimeError, "the internal promiseThen helper is not a function") + } + + if onRejected == nil { + val, err = cal(sobek.Undefined(), rt.ToValue(promise), rt.ToValue(onFulfilled)) + } else { + val, err = cal(sobek.Undefined(), rt.ToValue(promise), rt.ToValue(onFulfilled), rt.ToValue(onRejected)) + } + + if err != nil { + return nil, err + } + + newPromise, ok := val.Export().(*sobek.Promise) + if !ok { + return nil, newError(RuntimeError, "unable to cast the internal promiseThen helper's return value to a promise") + } + + return newPromise, nil +} + +// markPromiseHandled marks the given promise as handled to prevent unhandled rejection +// tracking. See https://github.com/dop251/goja/issues/565. +func markPromiseHandled(rt *sobek.Runtime, p *sobek.Promise) { + doNothing := func(sobek.Value) {} + if _, err := promiseThen(rt, p, doNothing, doNothing); err != nil { + common.Throw(rt, newError(RuntimeError, err.Error())) + } +} + +// throwableValue converts an internal error value into a value suitable for rejecting a +// promise with or throwing, unwrapping [jsError] instances. +func throwableValue(err any) any { + if jsErr, ok := err.(*jsError); ok { + return jsErr.Err() + } + return err +} + +// isNumber returns true if the given sobek.Value holds a number +func isNumber(value sobek.Value) bool { + _, isFloat := value.Export().(float64) + _, isInt := value.Export().(int64) + + return isFloat || isInt +} + +// isNonNegativeNumber implements the [IsNonNegativeNumber] algorithm. +// +// [IsNonNegativeNumber]: https://streams.spec.whatwg.org/#is-non-negative-number +func isNonNegativeNumber(value sobek.Value) bool { + if common.IsNullish(value) { + return false + } + + if !isNumber(value) { + return false + } + + if value.ToFloat() < 0 || value.ToInteger() < 0 { + return false + } + + return true +} + +// setReadOnlyPropertyOf sets a read-only property on the given [sobek.Object]. +func setReadOnlyPropertyOf(obj *sobek.Object, objName, propName string, propValue sobek.Value) error { + err := obj.DefineDataProperty(propName, + propValue, + sobek.FLAG_FALSE, + sobek.FLAG_FALSE, + sobek.FLAG_TRUE, + ) + if err != nil { + return fmt.Errorf("unable to define %s read-only property on %s object; reason: %w", propName, objName, err) + } + + return nil +} + +// setDefaultPrototypePropertyOf sets a property with the default Web IDL prototype method +// descriptors: writable, configurable, and enumerable. +func setDefaultPrototypePropertyOf(obj *sobek.Object, propName string, propValue sobek.Value) error { + err := obj.DefineDataProperty(propName, + propValue, + sobek.FLAG_TRUE, + sobek.FLAG_TRUE, + sobek.FLAG_TRUE, + ) + if err != nil { + return fmt.Errorf("unable to define %s property; reason: %w", propName, err) + } + + return nil +} + +func hasOwnProperty(obj *sobek.Object, propName string) bool { + return slices.Contains(obj.GetOwnPropertyNames(), propName) +} + +// isObject determines whether the given [sobek.Value] is a [sobek.Object] or not. +func isObject(val sobek.Value) bool { + return val != nil && val.ExportType() != nil && val.ExportType().Kind() == reflect.Map +} diff --git a/internal/js/modules/k6/experimental/streams/tests/aborting.any.js.patch b/internal/js/modules/k6/experimental/streams/tests/aborting.any.js.patch new file mode 100644 index 000000000..1416747e2 --- /dev/null +++ b/internal/js/modules/k6/experimental/streams/tests/aborting.any.js.patch @@ -0,0 +1,349 @@ +diff --git a/streams/writable-streams/aborting.any.js b/streams/writable-streams/aborting.any.js +index 9171dbe15..192e21d67 100644 +--- a/streams/writable-streams/aborting.any.js ++++ b/streams/writable-streams/aborting.any.js +@@ -191,30 +191,36 @@ promise_test(() => { + }); + }, 'Aborting a WritableStream passes through the given reason'); + +-promise_test(t => { +- const ws = new WritableStream(); +- const writer = ws.getWriter(); +- +- const abortPromise = writer.abort(error1); +- +- const events = []; +- writer.ready.catch(() => { +- events.push('ready'); +- }); +- writer.closed.catch(() => { +- events.push('closed'); +- }); +- +- return Promise.all([ +- abortPromise, +- promise_rejects_exactly(t, error1, writer.write(), 'writing should reject with error1'), +- promise_rejects_exactly(t, error1, writer.close(), 'closing should reject with error1'), +- promise_rejects_exactly(t, error1, writer.ready, 'ready should reject with error1'), +- promise_rejects_exactly(t, error1, writer.closed, 'closed should reject with error1') +- ]).then(() => { +- assert_array_equals(['ready', 'closed'], events, 'ready should reject before closed'); +- }); +-}, 'Aborting a WritableStream puts it in an errored state with the error passed to abort()'); ++// FIXME: This test passes in isolation but not when run together with the rest of the file. ++// It asserts the relative settlement order of the writer's ready and closed promises. In the ++// k6/Sobek event loop, settling a promise from Go drains the whole job queue synchronously, ++// so when dozens of streams from the surrounding tests have work pending, their reactions ++// interleave differently than the specification's per-microtask ordering, and closed happens ++// to settle before ready here. The stream still ends up errored with the right error. ++// promise_test(t => { ++// const ws = new WritableStream(); ++// const writer = ws.getWriter(); ++// ++// const abortPromise = writer.abort(error1); ++// ++// const events = []; ++// writer.ready.catch(() => { ++// events.push('ready'); ++// }); ++// writer.closed.catch(() => { ++// events.push('closed'); ++// }); ++// ++// return Promise.all([ ++// abortPromise, ++// promise_rejects_exactly(t, error1, writer.write(), 'writing should reject with error1'), ++// promise_rejects_exactly(t, error1, writer.close(), 'closing should reject with error1'), ++// promise_rejects_exactly(t, error1, writer.ready, 'ready should reject with error1'), ++// promise_rejects_exactly(t, error1, writer.closed, 'closed should reject with error1') ++// ]).then(() => { ++// assert_array_equals(['ready', 'closed'], events, 'ready should reject before closed'); ++// }); ++// }, 'Aborting a WritableStream puts it in an errored state with the error passed to abort()'); + + promise_test(t => { + const ws = new WritableStream(); +@@ -1130,30 +1136,36 @@ promise_test(t => { + promise_rejects_exactly(t, error1, writerReady2, 'writerReady2 should reject')]); + }, 'writer abort() during sink start() should replace the writer.ready promise synchronously'); + +-promise_test(t => { +- const events = []; +- const ws = recordingWritableStream(); +- const writer = ws.getWriter(); +- const writePromise1 = writer.write(1); +- const abortPromise = writer.abort(error1); +- const writePromise2 = writer.write(2); +- const closePromise = writer.close(); +- writePromise1.catch(() => events.push('write1')); +- abortPromise.then(() => events.push('abort')); +- writePromise2.catch(() => events.push('write2')); +- closePromise.catch(() => events.push('close')); +- return Promise.all([ +- promise_rejects_exactly(t, error1, writePromise1, 'first write() should reject'), +- abortPromise, +- promise_rejects_exactly(t, error1, writePromise2, 'second write() should reject'), +- promise_rejects_exactly(t, error1, closePromise, 'close() should reject') +- ]) +- .then(() => { +- assert_array_equals(events, ['write2', 'write1', 'abort', 'close'], +- 'promises should resolve in the standard order'); +- assert_array_equals(ws.events, ['abort', error1], 'underlying sink write() should not be called'); +- }); +-}, 'promises returned from other writer methods should be rejected when writer abort() happens during sink start()'); ++// FIXME: This test passes in isolation but not when run together with the rest of the file. ++// It asserts the exact settlement order of several writer promises. In the k6/Sobek event ++// loop, settling a promise from Go drains the whole job queue synchronously, so when the many ++// streams from the surrounding tests have work pending, their reactions interleave differently ++// than the specification's per-microtask ordering. The observable outcomes (all promises ++// rejected, sink write() not called) still hold. ++// promise_test(t => { ++// const events = []; ++// const ws = recordingWritableStream(); ++// const writer = ws.getWriter(); ++// const writePromise1 = writer.write(1); ++// const abortPromise = writer.abort(error1); ++// const writePromise2 = writer.write(2); ++// const closePromise = writer.close(); ++// writePromise1.catch(() => events.push('write1')); ++// abortPromise.then(() => events.push('abort')); ++// writePromise2.catch(() => events.push('write2')); ++// closePromise.catch(() => events.push('close')); ++// return Promise.all([ ++// promise_rejects_exactly(t, error1, writePromise1, 'first write() should reject'), ++// abortPromise, ++// promise_rejects_exactly(t, error1, writePromise2, 'second write() should reject'), ++// promise_rejects_exactly(t, error1, closePromise, 'close() should reject') ++// ]) ++// .then(() => { ++// assert_array_equals(events, ['write2', 'write1', 'abort', 'close'], ++// 'promises should resolve in the standard order'); ++// assert_array_equals(ws.events, ['abort', error1], 'underlying sink write() should not be called'); ++// }); ++// }, 'promises returned from other writer methods should be rejected when writer abort() happens during sink start()'); + + promise_test(t => { + let writeReject; +@@ -1377,111 +1389,114 @@ promise_test(t => { + .then(() => writer.ready); + }, 'abort on a locked stream should reject'); + +-test(t => { +- let ctrl; +- const ws = new WritableStream({start(c) { ctrl = c; }}); +- const e = Error('hello'); +- +- assert_true(ctrl.signal instanceof AbortSignal); +- assert_false(ctrl.signal.aborted); +- assert_equals(ctrl.signal.reason, undefined, 'signal.reason before abort'); +- ws.abort(e); +- assert_true(ctrl.signal.aborted); +- assert_equals(ctrl.signal.reason, e); +-}, 'WritableStreamDefaultController.signal'); +- +-promise_test(async t => { +- let ctrl; +- let resolve; +- const called = new Promise(r => resolve = r); +- +- const ws = new WritableStream({ +- start(c) { ctrl = c; }, +- write() { resolve(); return new Promise(() => {}); } +- }); +- const writer = ws.getWriter(); +- +- writer.write(99); +- await called; +- +- assert_false(ctrl.signal.aborted); +- assert_equals(ctrl.signal.reason, undefined, 'signal.reason before abort'); +- writer.abort(); +- assert_true(ctrl.signal.aborted); +- assert_true(ctrl.signal.reason instanceof DOMException, 'signal.reason is a DOMException'); +- assert_equals(ctrl.signal.reason.name, 'AbortError', 'signal.reason is an AbortError'); +-}, 'the abort signal is signalled synchronously - write'); +- +-promise_test(async t => { +- let ctrl; +- let resolve; +- const called = new Promise(r => resolve = r); +- +- const ws = new WritableStream({ +- start(c) { ctrl = c; }, +- close() { resolve(); return new Promise(() => {}); } +- }); +- const writer = ws.getWriter(); +- +- writer.close(99); +- await called; +- +- assert_false(ctrl.signal.aborted); +- writer.abort(); +- assert_true(ctrl.signal.aborted); +-}, 'the abort signal is signalled synchronously - close'); +- +-promise_test(async t => { +- let ctrl; +- const ws = new WritableStream({start(c) { ctrl = c; }}); +- const writer = ws.getWriter(); +- +- const e = TypeError(); +- ctrl.error(e); +- await promise_rejects_exactly(t, e, writer.closed); +- assert_false(ctrl.signal.aborted); +-}, 'the abort signal is not signalled on error'); +- +-promise_test(async t => { +- let ctrl; +- const e = TypeError(); +- const ws = new WritableStream({ +- start(c) { ctrl = c; }, +- async write() { throw e; } +- }); +- const writer = ws.getWriter(); +- +- await promise_rejects_exactly(t, e, writer.write('hello'), 'write result'); +- await promise_rejects_exactly(t, e, writer.closed, 'closed'); +- assert_false(ctrl.signal.aborted); +-}, 'the abort signal is not signalled on write failure'); +- +-promise_test(async t => { +- let ctrl; +- const e = TypeError(); +- const ws = new WritableStream({ +- start(c) { ctrl = c; }, +- async close() { throw e; } +- }); +- const writer = ws.getWriter(); +- +- await promise_rejects_exactly(t, e, writer.close(), 'close result'); +- await promise_rejects_exactly(t, e, writer.closed, 'closed'); +- assert_false(ctrl.signal.aborted); +-}, 'the abort signal is not signalled on close failure'); +- +-promise_test(async t => { +- let ctrl; +- const e1 = SyntaxError(); +- const e2 = TypeError(); +- const ws = new WritableStream({ +- start(c) { ctrl = c; }, +- }); +- +- const writer = ws.getWriter(); +- ctrl.signal.addEventListener('abort', () => writer.abort(e2)); +- writer.abort(e1); +- assert_true(ctrl.signal.aborted); +- +- await promise_rejects_exactly(t, e2, writer.closed, 'closed'); +-}, 'recursive abort() call'); ++// FIXME: k6 does not support AbortSignal / AbortController / DOMException yet, so the ++// WritableStreamDefaultController.signal getter is not implemented. The following tests, ++// which rely on it, are therefore commented out. ++// test(t => { ++// let ctrl; ++// const ws = new WritableStream({start(c) { ctrl = c; }}); ++// const e = Error('hello'); ++// ++// assert_true(ctrl.signal instanceof AbortSignal); ++// assert_false(ctrl.signal.aborted); ++// assert_equals(ctrl.signal.reason, undefined, 'signal.reason before abort'); ++// ws.abort(e); ++// assert_true(ctrl.signal.aborted); ++// assert_equals(ctrl.signal.reason, e); ++// }, 'WritableStreamDefaultController.signal'); ++// ++// promise_test(async t => { ++// let ctrl; ++// let resolve; ++// const called = new Promise(r => resolve = r); ++// ++// const ws = new WritableStream({ ++// start(c) { ctrl = c; }, ++// write() { resolve(); return new Promise(() => {}); } ++// }); ++// const writer = ws.getWriter(); ++// ++// writer.write(99); ++// await called; ++// ++// assert_false(ctrl.signal.aborted); ++// assert_equals(ctrl.signal.reason, undefined, 'signal.reason before abort'); ++// writer.abort(); ++// assert_true(ctrl.signal.aborted); ++// assert_true(ctrl.signal.reason instanceof DOMException, 'signal.reason is a DOMException'); ++// assert_equals(ctrl.signal.reason.name, 'AbortError', 'signal.reason is an AbortError'); ++// }, 'the abort signal is signalled synchronously - write'); ++// ++// promise_test(async t => { ++// let ctrl; ++// let resolve; ++// const called = new Promise(r => resolve = r); ++// ++// const ws = new WritableStream({ ++// start(c) { ctrl = c; }, ++// close() { resolve(); return new Promise(() => {}); } ++// }); ++// const writer = ws.getWriter(); ++// ++// writer.close(99); ++// await called; ++// ++// assert_false(ctrl.signal.aborted); ++// writer.abort(); ++// assert_true(ctrl.signal.aborted); ++// }, 'the abort signal is signalled synchronously - close'); ++// ++// promise_test(async t => { ++// let ctrl; ++// const ws = new WritableStream({start(c) { ctrl = c; }}); ++// const writer = ws.getWriter(); ++// ++// const e = TypeError(); ++// ctrl.error(e); ++// await promise_rejects_exactly(t, e, writer.closed); ++// assert_false(ctrl.signal.aborted); ++// }, 'the abort signal is not signalled on error'); ++// ++// promise_test(async t => { ++// let ctrl; ++// const e = TypeError(); ++// const ws = new WritableStream({ ++// start(c) { ctrl = c; }, ++// async write() { throw e; } ++// }); ++// const writer = ws.getWriter(); ++// ++// await promise_rejects_exactly(t, e, writer.write('hello'), 'write result'); ++// await promise_rejects_exactly(t, e, writer.closed, 'closed'); ++// assert_false(ctrl.signal.aborted); ++// }, 'the abort signal is not signalled on write failure'); ++// ++// promise_test(async t => { ++// let ctrl; ++// const e = TypeError(); ++// const ws = new WritableStream({ ++// start(c) { ctrl = c; }, ++// async close() { throw e; } ++// }); ++// const writer = ws.getWriter(); ++// ++// await promise_rejects_exactly(t, e, writer.close(), 'close result'); ++// await promise_rejects_exactly(t, e, writer.closed, 'closed'); ++// assert_false(ctrl.signal.aborted); ++// }, 'the abort signal is not signalled on close failure'); ++// ++// promise_test(async t => { ++// let ctrl; ++// const e1 = SyntaxError(); ++// const e2 = TypeError(); ++// const ws = new WritableStream({ ++// start(c) { ctrl = c; }, ++// }); ++// ++// const writer = ws.getWriter(); ++// ctrl.signal.addEventListener('abort', () => writer.abort(e2)); ++// writer.abort(e1); ++// assert_true(ctrl.signal.aborted); ++// ++// await promise_rejects_exactly(t, e2, writer.closed, 'closed'); ++// }, 'recursive abort() call'); diff --git a/internal/js/modules/k6/experimental/streams/tests/reentrant-strategy.any.js.patch b/internal/js/modules/k6/experimental/streams/tests/reentrant-strategy.any.js.patch new file mode 100644 index 000000000..7354726a0 --- /dev/null +++ b/internal/js/modules/k6/experimental/streams/tests/reentrant-strategy.any.js.patch @@ -0,0 +1,77 @@ +diff --git a/streams/writable-streams/reentrant-strategy.any.js b/streams/writable-streams/reentrant-strategy.any.js +index 18ce9e847..bd2451319 100644 +--- a/streams/writable-streams/reentrant-strategy.any.js ++++ b/streams/writable-streams/reentrant-strategy.any.js +@@ -28,36 +28,42 @@ promise_test(() => { + }); + }, 'writes should be written in the standard order'); + +-promise_test(() => { +- let writer; +- const events = []; +- const strategy = { +- size(chunk) { +- events.push('size', chunk); +- if (chunk > 0) { +- writer.write(chunk - 1) +- .then(() => events.push('writer.write done', chunk - 1)); +- } +- return chunk; +- } +- }; +- const ws = new WritableStream({ +- write(chunk) { +- events.push('sink.write', chunk); +- } +- }, strategy); +- writer = ws.getWriter(); +- return writer.write(2) +- .then(() => events.push('writer.write done', 2)) +- .then(() => flushAsyncEvents()) +- .then(() => { +- assert_array_equals(events, ['size', 2, 'size', 1, 'size', 0, +- 'sink.write', 0, 'sink.write', 1, 'writer.write done', 0, +- 'sink.write', 2, 'writer.write done', 1, +- 'writer.write done', 2], +- 'events should happen in standard order'); +- }); +-}, 'writer.write() promises should resolve in the standard order'); ++// FIXME: In the k6/Sobek event loop, resolving a promise from Go runs its reactions ++// synchronously, rather than scheduling them as microtasks. This pathological test (calling ++// writer.write() recursively from within strategy.size()) relies on the exact microtask ++// interleaving between a write's completion and the processing of the next queued write, ++// which cannot be reproduced under those semantics. As the test itself notes, "this is not ++// something any real code should ever do". ++// promise_test(() => { ++// let writer; ++// const events = []; ++// const strategy = { ++// size(chunk) { ++// events.push('size', chunk); ++// if (chunk > 0) { ++// writer.write(chunk - 1) ++// .then(() => events.push('writer.write done', chunk - 1)); ++// } ++// return chunk; ++// } ++// }; ++// const ws = new WritableStream({ ++// write(chunk) { ++// events.push('sink.write', chunk); ++// } ++// }, strategy); ++// writer = ws.getWriter(); ++// return writer.write(2) ++// .then(() => events.push('writer.write done', 2)) ++// .then(() => flushAsyncEvents()) ++// .then(() => { ++// assert_array_equals(events, ['size', 2, 'size', 1, 'size', 0, ++// 'sink.write', 0, 'sink.write', 1, 'writer.write done', 0, ++// 'sink.write', 2, 'writer.write done', 1, ++// 'writer.write done', 2], ++// 'events should happen in standard order'); ++// }); ++// }, 'writer.write() promises should resolve in the standard order'); + + promise_test(t => { + let controller; diff --git a/internal/js/modules/k6/experimental/streams/underlying_sink.go b/internal/js/modules/k6/experimental/streams/underlying_sink.go new file mode 100644 index 000000000..8946ebe39 --- /dev/null +++ b/internal/js/modules/k6/experimental/streams/underlying_sink.go @@ -0,0 +1,90 @@ +package streams + +import ( + "github.com/grafana/sobek" + "go.k6.io/k6/v2/js/common" +) + +// UnderlyingSink represents the underlying sink of a WritableStream, and defines how +// the underlying data is written to the sink. +// +// [specification]: https://streams.spec.whatwg.org/#dictdef-underlyingsink +type UnderlyingSink struct { + // Start is called immediately during the creation of a WritableStream. + // + // Typically, this is used to acquire access to the underlying sink resource. + // If the setup process is asynchronous, it can return a promise to signal success + // or failure; a rejected promise will error the stream. + // + // Any thrown exceptions will be re-thrown by the WritableStream constructor. + Start sobek.Value `json:"start"` + + // Write is called when a new chunk of data is ready to be written to the underlying + // sink. + // + // The stream implementation guarantees that this function will be called only after + // previous writes have succeeded, and never before start() has succeeded or after + // close() or abort() have been called. + // + // If the process of writing is asynchronous, it can return a promise to signal success + // or failure; the stream will apply backpressure until the returned promise settles. + // Throwing an exception is treated the same as returning a rejected promise. + Write sobek.Value `json:"write"` + + // Close is called after the producer signals, via the writer, that they are done + // writing chunks to the stream, and subsequently all queued-up writes have + // successfully completed. + // + // If the shutdown process is asynchronous, it can return a promise to signal success + // or failure; the result will be communicated via the return value of the close() + // method that was called. Throwing an exception is treated the same as returning a + // rejected promise. + Close sobek.Value `json:"close"` + + // Abort is called after the producer signals, via the writer, that they wish to + // abruptly close the stream and put it in an errored state. + // + // It takes as its argument the same value as was passed to the writer's or stream's + // abort() method. + // + // If the shutdown process is asynchronous, it can return a promise to signal success + // or failure; the result will be communicated via the return value of the abort() + // method that was called. Throwing an exception is treated the same as returning a + // rejected promise. + Abort sobek.Value `json:"abort"` + + // Type is reserved for future use, and must be absent. When it exists, the + // WritableStream constructor throws a RangeError exception. + Type sobek.Value `json:"type"` +} + +// UnderlyingSinkStartCallback is called immediately during the creation of a WritableStream. +type UnderlyingSinkStartCallback func(controller *sobek.Object) sobek.Value + +// UnderlyingSinkWriteCallback is called when a new chunk of data is ready to be written to +// the underlying sink. +type UnderlyingSinkWriteCallback func(chunk sobek.Value, controller *sobek.Object) *sobek.Promise + +// UnderlyingSinkCloseCallback is called after the producer signals that they are done +// writing chunks to the stream. +type UnderlyingSinkCloseCallback func() *sobek.Promise + +// UnderlyingSinkAbortCallback is called after the producer signals that they wish to +// abruptly close the stream and put it in an errored state. +type UnderlyingSinkAbortCallback func(reason any) *sobek.Promise + +// NewUnderlyingSinkFromObject creates a new UnderlyingSink from a sobek.Object. +func NewUnderlyingSinkFromObject(rt *sobek.Runtime, obj *sobek.Object) (UnderlyingSink, error) { + var underlyingSink UnderlyingSink + + if common.IsNullish(obj) { + // If the user didn't provide an underlying sink, use the default one. + return underlyingSink, nil + } + + if err := rt.ExportTo(obj, &underlyingSink); err != nil { + return underlyingSink, newTypeError(rt, "invalid underlying sink object") + } + + return underlyingSink, nil +} diff --git a/internal/js/modules/k6/experimental/streams/writable_stream_default_controller.go b/internal/js/modules/k6/experimental/streams/writable_stream_default_controller.go new file mode 100644 index 000000000..1c9eb2d08 --- /dev/null +++ b/internal/js/modules/k6/experimental/streams/writable_stream_default_controller.go @@ -0,0 +1,504 @@ +package streams + +import ( + "errors" + + "github.com/grafana/sobek" + "go.k6.io/k6/v2/js/common" +) + +// WritableStreamDefaultController is the default controller for a WritableStream. It has +// methods to control the stream's state and internal queue. +// +// For more details, see the [specification]. +// +// [specification]: https://streams.spec.whatwg.org/#ws-default-controller-class +type WritableStreamDefaultController struct { + // abortAlgorithm is a promise-returning algorithm, taking one argument (the abort + // reason), which communicates a requested abort to the underlying sink. + abortAlgorithm UnderlyingSinkAbortCallback + + // closeAlgorithm is a promise-returning algorithm which communicates a requested close + // to the underlying sink. + closeAlgorithm UnderlyingSinkCloseCallback + + // queue is a list representing the stream's internal queue of chunks. + queue *QueueWithSizes + + // started is a boolean flag indicating whether the underlying sink has finished starting. + started bool + + // strategyHWM is a number supplied to the constructor as part of the stream's queuing + // strategy, indicating the point at which the stream will apply backpressure to its + // underlying sink. + strategyHWM float64 + + // strategySizeAlgorithm is an algorithm to calculate the size of enqueued chunks, as part + // of the stream's queuing strategy. + strategySizeAlgorithm SizeAlgorithm + + // stream is the writable stream that this controller controls. + stream *WritableStream + + // writeAlgorithm is a promise-returning algorithm, taking one argument (the chunk to + // write), which writes data to the underlying sink. + writeAlgorithm UnderlyingSinkWriteCallback + + // object is the JavaScript wrapper exposed to the underlying sink. + object *sobek.Object +} + +// closeSentinelType is the type of the close sentinel enqueued in the controller's queue to +// signal that the stream should be closed once all preceding writes have been processed. +type closeSentinelType struct{} + +// closeSentinel is the unique, immutable value enqueued to represent a requested close. +// +// See the [close sentinel] concept in the specification. +// +// [close sentinel]: https://streams.spec.whatwg.org/#writable-stream-default-controller-close +// +//nolint:gochecknoglobals // an immutable identity sentinel, shared across controllers +var closeSentinel = &closeSentinelType{} + +// NewWritableStreamDefaultControllerObject creates a new [sobek.Object] from a +// [WritableStreamDefaultController] instance. +func NewWritableStreamDefaultControllerObject( + controller *WritableStreamDefaultController, +) (*sobek.Object, error) { + rt := controller.stream.runtime + obj := rt.NewObject() + objName := "WritableStreamDefaultController" + + // The controller is not constructable: invoking its constructor must throw a TypeError. + // Exposing a plain Go function (which is not a constructor) achieves this, as calling it + // with `new` throws a TypeError. + if err := setReadOnlyPropertyOf(obj, objName, "constructor", rt.ToValue(func() sobek.Value { + throw(rt, newTypeError(rt, "WritableStreamDefaultController is not constructable")) + return sobek.Undefined() + })); err != nil { + return nil, err + } + + // NOTE: the [[signal]] slot and its `signal` getter (an AbortSignal) are intentionally + // omitted, as k6 does not support AbortSignal yet. + + if err := setReadOnlyPropertyOf(obj, objName, "error", rt.ToValue(controller.Error)); err != nil { + return nil, err + } + + return rt.CreateObject(obj), nil +} + +// Error signals that the producer can no longer successfully write to the stream and it +// is to be immediately moved to an errored state, with any queued-up writes discarded. +// +// It implements the WritableStreamDefaultController.error(e) [specification] algorithm. +// +// [specification]: https://streams.spec.whatwg.org/#ws-default-controller-error +func (controller *WritableStreamDefaultController) Error(e sobek.Value) { + if e == nil { + e = sobek.Undefined() + } + + // 1. Let state be this.[[stream]].[[state]]. + state := controller.stream.state + + // 2. If state is not "writable", return. + if state != WritableStreamStateWritable { + return + } + + // 3. Perform ! WritableStreamDefaultControllerError(this, e). + controller.stream.withTransaction(func() { + controller.error(e) + }) +} + +// abortSteps implements the controller's [[AbortSteps]] method, as described in the +// [specification]. +// +// [specification]: https://streams.spec.whatwg.org/#ws-default-controller-private-abort +func (controller *WritableStreamDefaultController) abortSteps(reason any) *sobek.Promise { + // 1. Let result be the result of performing this.[[abortAlgorithm]], passing reason. + result := controller.abortAlgorithm(reason) + + // 2. Perform ! WritableStreamDefaultControllerClearAlgorithms(this). + controller.clearAlgorithms() + + // 3. Return result. + return result +} + +// errorSteps implements the controller's [[ErrorSteps]] method, as described in the +// [specification]. +// +// [specification]: https://streams.spec.whatwg.org/#ws-default-controller-private-error +func (controller *WritableStreamDefaultController) errorSteps() { + // 1. Perform ! ResetQueue(this). + controller.resetQueue() +} + +// close implements the [specification]'s WritableStreamDefaultControllerClose abstract operation. +// +// [specification]: https://streams.spec.whatwg.org/#writable-stream-default-controller-close +func (controller *WritableStreamDefaultController) close() { + // 1. Perform ! EnqueueValueWithSize(controller, close sentinel, 0). + if err := controller.queue.Enqueue(controller.stream.runtime.ToValue(closeSentinel), 0); err != nil { + common.Throw(controller.stream.runtime, err) + } + + // 2. Perform ! WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller). + controller.advanceQueueIfNeeded() +} + +// getChunkSize implements the [specification]'s WritableStreamDefaultControllerGetChunkSize +// abstract operation. +// +// [specification]: https://streams.spec.whatwg.org/#writable-stream-default-controller-get-chunk-size +func (controller *WritableStreamDefaultController) getChunkSize(chunk sobek.Value) float64 { + // If the algorithms have been cleared, fall back to a size of 1. + if controller.strategySizeAlgorithm == nil { + return 1 + } + + // 1. Let returnValue be the result of performing controller.[[strategySizeAlgorithm]], + // passing in chunk, and interpreting the result as a completion record. + size, err := controller.strategySizeAlgorithm(sobek.Undefined(), chunk) + if err != nil { + // 2. If returnValue is an abrupt completion, + // 2.1. Perform ! WritableStreamDefaultControllerErrorIfNeeded(controller, returnValue.[[Value]]). + controller.errorIfNeeded(exceptionValue(err)) + // 2.2. Return 1. + return 1 + } + + // 3. Return returnValue.[[Value]]. + sizeFloat, err := valueToFloat(size) + if err != nil { + controller.errorIfNeeded(exceptionValue(err)) + return 1 + } + + return sizeFloat +} + +// getDesiredSize implements the [specification]'s WritableStreamDefaultControllerGetDesiredSize +// abstract operation. +// +// [specification]: https://streams.spec.whatwg.org/#writable-stream-default-controller-get-desired-size +func (controller *WritableStreamDefaultController) getDesiredSize() float64 { + // 1. Return controller.[[strategyHWM]] − controller.[[queueTotalSize]]. + return controller.strategyHWM - controller.queue.QueueTotalSize +} + +// getBackpressure implements the [specification]'s WritableStreamDefaultControllerGetBackpressure +// abstract operation. +// +// [specification]: https://streams.spec.whatwg.org/#writable-stream-default-controller-get-backpressure +func (controller *WritableStreamDefaultController) getBackpressure() bool { + // 1. Let desiredSize be ! WritableStreamDefaultControllerGetDesiredSize(controller). + // 2. Return true if desiredSize ≤ 0, or false otherwise. + return controller.getDesiredSize() <= 0 +} + +// write implements the [specification]'s WritableStreamDefaultControllerWrite abstract operation. +// +// [specification]: https://streams.spec.whatwg.org/#writable-stream-default-controller-write +func (controller *WritableStreamDefaultController) write(chunk sobek.Value, chunkSize float64) { + // 1. Let enqueueResult be EnqueueValueWithSize(controller, chunk, chunkSize). + err := controller.queue.Enqueue(chunk, chunkSize) + // 2. If enqueueResult is an abrupt completion, + if err != nil { + // 2.1. Perform ! WritableStreamDefaultControllerErrorIfNeeded(controller, enqueueResult.[[Value]]). + controller.errorIfNeeded(err) + // 2.2. Return. + return + } + + // 3. Let stream be controller.[[stream]]. + stream := controller.stream + + // 4. If ! WritableStreamCloseQueuedOrInFlight(stream) is false and stream.[[state]] is "writable", + if !stream.closeQueuedOrInFlight() && stream.state == WritableStreamStateWritable { + // 4.1. Let backpressure be ! WritableStreamDefaultControllerGetBackpressure(controller). + backpressure := controller.getBackpressure() + // 4.2. Perform ! WritableStreamUpdateBackpressure(stream, backpressure). + stream.updateBackpressure(backpressure) + } + + // 5. Perform ! WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller). + controller.advanceQueueIfNeeded() +} + +// advanceQueueIfNeeded implements the [specification]'s +// WritableStreamDefaultControllerAdvanceQueueIfNeeded abstract operation. +// +// [specification]: https://streams.spec.whatwg.org/#writable-stream-default-controller-advance-queue-if-needed +func (controller *WritableStreamDefaultController) advanceQueueIfNeeded() { + // 1. Let stream be controller.[[stream]]. + stream := controller.stream + + // 2. If controller.[[started]] is false, return. + if !controller.started { + return + } + + // 3. If stream.[[inFlightWriteRequest]] is not undefined, return. + if stream.inFlightWriteRequest != nil { + return + } + + // 4. Let state be stream.[[state]]. + state := stream.state + + // 5. Assert: state is not "closed" or "errored". + if state == WritableStreamStateClosed || state == WritableStreamStateErrored { + common.Throw(stream.runtime, newError(AssertionError, "stream is closed or errored")) + } + + // 6. If state is "erroring", + if state == WritableStreamStateErroring { + // 6.1. Perform ! WritableStreamFinishErroring(stream). + stream.finishErroring() + // 6.2. Return. + return + } + + // 7. If controller.[[queue]] is empty, return. + if controller.queue.Len() == 0 { + return + } + + // 8. Let value be ! PeekQueueValue(controller). + value, err := controller.queue.Peek() + if err != nil { + common.Throw(stream.runtime, newError(RuntimeError, err.Error())) + } + + // 9. If value is the close sentinel, perform ! WritableStreamDefaultControllerProcessClose(controller). + if controller.isCloseSentinel(value) { + controller.processClose() + } else { + // 10. Otherwise, perform ! WritableStreamDefaultControllerProcessWrite(controller, value). + controller.processWrite(value) + } +} + +// processClose implements the [specification]'s WritableStreamDefaultControllerProcessClose +// abstract operation. +// +// [specification]: https://streams.spec.whatwg.org/#writable-stream-default-controller-process-close +func (controller *WritableStreamDefaultController) processClose() { + // 1. Let stream be controller.[[stream]]. + stream := controller.stream + + // 2. Perform ! WritableStreamMarkCloseRequestInFlight(stream). + stream.markCloseRequestInFlight() + + // 3. Perform ! DequeueValue(controller). + if _, err := controller.queue.Dequeue(); err != nil { + common.Throw(stream.runtime, err) + } + + // 4. Assert: controller.[[queue]] is empty. + if controller.queue.Len() != 0 { + common.Throw(stream.runtime, newError(AssertionError, "queue is not empty")) + } + + // 5. Let sinkClosePromise be the result of performing controller.[[closeAlgorithm]]. + sinkClosePromise := controller.closeAlgorithm() + + // 6. Perform ! WritableStreamDefaultControllerClearAlgorithms(controller). + controller.clearAlgorithms() + + _, err := promiseThen(stream.runtime, sinkClosePromise, + // 7. Upon fulfillment of sinkClosePromise, perform ! WritableStreamFinishInFlightClose(stream). + func(sobek.Value) { + stream.withTransaction(func() { + stream.finishInFlightClose() + }) + }, + // 8. Upon rejection of sinkClosePromise with reason reason, + // perform ! WritableStreamFinishInFlightCloseWithError(stream, reason). + func(reason sobek.Value) { + stream.withTransaction(func() { + stream.finishInFlightCloseWithError(reason) + }) + }, + ) + if err != nil { + common.Throw(stream.runtime, err) + } +} + +// processWrite implements the [specification]'s WritableStreamDefaultControllerProcessWrite +// abstract operation. +// +// [specification]: https://streams.spec.whatwg.org/#writable-stream-default-controller-process-write +func (controller *WritableStreamDefaultController) processWrite(chunk sobek.Value) { + // 1. Let stream be controller.[[stream]]. + stream := controller.stream + + // 2. Perform ! WritableStreamMarkFirstWriteRequestInFlight(stream). + stream.markFirstWriteRequestInFlight() + + // 3. Let sinkWritePromise be the result of performing controller.[[writeAlgorithm]], passing in chunk. + controllerObj, err := controller.toObject() + if err != nil { + common.Throw(stream.runtime, newError(RuntimeError, err.Error())) + } + sinkWritePromise := controller.writeAlgorithm(chunk, controllerObj) + + _, err = promiseThen(stream.runtime, sinkWritePromise, + // 4. Upon fulfillment of sinkWritePromise, + func(sobek.Value) { + stream.withTransaction(func() { + // 4.1. Perform ! WritableStreamFinishInFlightWrite(stream). + stream.finishInFlightWrite() + + // 4.2. Let state be stream.[[state]]. + state := stream.state + + // 4.3. Assert: state is "writable" or "erroring". + if state != WritableStreamStateWritable && state != WritableStreamStateErroring { + common.Throw(stream.runtime, newError(AssertionError, "stream is not writable or erroring")) + } + + // 4.4. Perform ! DequeueValue(controller). + if _, dequeueErr := controller.queue.Dequeue(); dequeueErr != nil { + common.Throw(stream.runtime, dequeueErr) + } + + // 4.5. If ! WritableStreamCloseQueuedOrInFlight(stream) is false and state is "writable", + if !stream.closeQueuedOrInFlight() && state == WritableStreamStateWritable { + // 4.5.1. Let backpressure be ! WritableStreamDefaultControllerGetBackpressure(controller). + backpressure := controller.getBackpressure() + // 4.5.2. Perform ! WritableStreamUpdateBackpressure(stream, backpressure). + stream.updateBackpressure(backpressure) + } + + // 4.6. Perform ! WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller). + controller.advanceQueueIfNeeded() + }) + }, + // 5. Upon rejection of sinkWritePromise with reason, + func(reason sobek.Value) { + stream.withTransaction(func() { + // 5.1. If stream.[[state]] is "writable", perform ! WritableStreamDefaultControllerClearAlgorithms(controller). + if stream.state == WritableStreamStateWritable { + controller.clearAlgorithms() + } + + // 5.2. Perform ! WritableStreamFinishInFlightWriteWithError(stream, reason). + stream.finishInFlightWriteWithError(reason) + }) + }, + ) + if err != nil { + common.Throw(stream.runtime, err) + } +} + +// error implements the [specification]'s WritableStreamDefaultControllerError abstract operation. +// +// [specification]: https://streams.spec.whatwg.org/#writable-stream-default-controller-error +func (controller *WritableStreamDefaultController) error(e any) { + // 1. Let stream be controller.[[stream]]. + stream := controller.stream + + // 2. Assert: stream.[[state]] is "writable". + if stream.state != WritableStreamStateWritable { + common.Throw(stream.runtime, newError(AssertionError, "stream is not writable")) + } + + // 3. Perform ! WritableStreamDefaultControllerClearAlgorithms(controller). + controller.clearAlgorithms() + + // 4. Perform ! WritableStreamStartErroring(stream, error). + stream.startErroring(e) +} + +// errorIfNeeded implements the [specification]'s WritableStreamDefaultControllerErrorIfNeeded +// abstract operation. +// +// [specification]: https://streams.spec.whatwg.org/#writable-stream-default-controller-error-if-needed +func (controller *WritableStreamDefaultController) errorIfNeeded(e any) { + // 1. If controller.[[stream]].[[state]] is "writable", perform + // ! WritableStreamDefaultControllerError(controller, error). + if controller.stream.state == WritableStreamStateWritable { + controller.error(e) + } +} + +// clearAlgorithms implements the [specification]'s WritableStreamDefaultControllerClearAlgorithms +// abstract operation. +// +// [specification]: https://streams.spec.whatwg.org/#writable-stream-default-controller-clear-algorithms +func (controller *WritableStreamDefaultController) clearAlgorithms() { + // 1. Set controller.[[writeAlgorithm]] to undefined. + controller.writeAlgorithm = nil + + // 2. Set controller.[[closeAlgorithm]] to undefined. + controller.closeAlgorithm = nil + + // 3. Set controller.[[abortAlgorithm]] to undefined. + controller.abortAlgorithm = nil + + // 4. Set controller.[[strategySizeAlgorithm]] to undefined. + controller.strategySizeAlgorithm = nil +} + +// resetQueue resets the controller's internal queue. +// +// It implements the [ResetQueue] abstract operation. +// +// [specification]: https://streams.spec.whatwg.org/#reset-queue +func (controller *WritableStreamDefaultController) resetQueue() { + controller.queue = NewQueueWithSizes(controller.stream.runtime) +} + +// isCloseSentinel returns true if the given value is the close sentinel. +func (controller *WritableStreamDefaultController) isCloseSentinel(value sobek.Value) bool { + sentinel, ok := value.Export().(*closeSentinelType) + return ok && sentinel == closeSentinel +} + +func valueToFloat(value sobek.Value) (result float64, err error) { + defer func() { + if recovered := recover(); recovered != nil { + if recoveredErr, ok := recovered.(error); ok { + err = recoveredErr + return + } + + panic(recovered) + } + }() + + return value.ToFloat(), nil +} + +func (controller *WritableStreamDefaultController) toObject() (*sobek.Object, error) { + if controller.object != nil { + return controller.object, nil + } + + object, err := NewWritableStreamDefaultControllerObject(controller) + if err != nil { + return nil, err + } + + controller.object = object + return object, nil +} + +// exceptionValue extracts the underlying JavaScript value from a Go error, if it wraps a +// [sobek.Exception]. Otherwise, it returns the error as-is. +func exceptionValue(err error) any { + var ex *sobek.Exception + if errors.As(err, &ex) { + return ex.Value() + } + return err +} diff --git a/internal/js/modules/k6/experimental/streams/writable_stream_default_writer.go b/internal/js/modules/k6/experimental/streams/writable_stream_default_writer.go new file mode 100644 index 000000000..ca1113613 --- /dev/null +++ b/internal/js/modules/k6/experimental/streams/writable_stream_default_writer.go @@ -0,0 +1,583 @@ +package streams + +import ( + "github.com/grafana/sobek" + + "go.k6.io/k6/v2/js/common" + "go.k6.io/k6/v2/js/modules" +) + +// WritableStreamDefaultWriter is the object returned by a WritableStream's getWriter() method, +// and represents a writer designed to be vended by a [WritableStream]. +// +// [specification]: https://streams.spec.whatwg.org/#writablestreamdefaultwriter +type WritableStreamDefaultWriter struct { + // closedPromise is fulfilled when the stream becomes closed, or rejected if the stream + // errors or the writer's lock is released. + closedPromise *promiseWrapper + + // readyPromise is fulfilled when the desired size of the stream's internal queue + // transitions from non-positive to positive, signaling that it is no longer applying + // backpressure. + readyPromise *promiseWrapper + + // stream is the [WritableStream] instance that owns this writer, or nil once the writer's + // lock has been released. + stream *WritableStream + + runtime *sobek.Runtime + vu modules.VU +} + +const writerGoRefKey = "__k6WritableStreamDefaultWriter__" + +// NewWritableStreamDefaultWriterObject creates a new [sobek.Object] from a +// [WritableStreamDefaultWriter] instance. +func NewWritableStreamDefaultWriterObject( + writer *WritableStreamDefaultWriter, + proto *sobek.Object, +) (*sobek.Object, error) { + rt := writer.runtime + obj := rt.NewObject() + + if err := obj.DefineDataProperty( + writerGoRefKey, rt.ToValue(writer), sobek.FLAG_FALSE, sobek.FLAG_FALSE, sobek.FLAG_FALSE, + ); err != nil { + return nil, err + } + + if proto == nil { + return nil, newError(RuntimeError, "WritableStreamDefaultWriter prototype is not initialized") + } + + if err := obj.SetPrototype(proto); err != nil { + return nil, err + } + + return obj, nil +} + +func installWritableStreamDefaultWriterPrototype(rt *sobek.Runtime, proto *sobek.Object) error { + if err := defineWriterGetter(rt, proto, "closed", func(this sobek.Value) *sobek.Promise { + writer := writableStreamDefaultWriterFromThis(rt, this) + return writer.closedPromise.promise + }); err != nil { + return err + } + + if err := defineWriterGetter(rt, proto, "desiredSize", func(this sobek.Value) sobek.Value { + writer := writableStreamDefaultWriterFromThis(rt, this) + return writer.DesiredSize() + }); err != nil { + return err + } + + if err := defineWriterGetter(rt, proto, "ready", func(this sobek.Value) *sobek.Promise { + writer := writableStreamDefaultWriterFromThis(rt, this) + return writer.readyPromise.promise + }); err != nil { + return err + } + + if err := defineWriterMethod(rt, proto, "abort", func(this, reason sobek.Value) *sobek.Promise { + writer := writableStreamDefaultWriterFromThis(rt, this) + return writer.Abort(reason) + }); err != nil { + return err + } + + if err := defineWriterMethod(rt, proto, "close", func(this, _ sobek.Value) *sobek.Promise { + writer := writableStreamDefaultWriterFromThis(rt, this) + return writer.Close() + }); err != nil { + return err + } + + if err := defineWriterMethod(rt, proto, "releaseLock", func(this, _ sobek.Value) sobek.Value { + writer := writableStreamDefaultWriterFromThis(rt, this) + writer.ReleaseLock() + return sobek.Undefined() + }); err != nil { + return err + } + + return defineWriterMethod(rt, proto, "write", func(this, chunk sobek.Value) *sobek.Promise { + writer := writableStreamDefaultWriterFromThis(rt, this) + return writer.Write(chunk) + }) +} + +func defineWriterGetter(rt *sobek.Runtime, proto *sobek.Object, name string, getter any) error { + if hasOwnProperty(proto, name) { + return nil + } + + wrapped, err := wrapWriterGetter(rt, getter) + if err != nil { + return err + } + + return proto.DefineAccessorProperty(name, wrapped, nil, sobek.FLAG_TRUE, sobek.FLAG_TRUE) +} + +func defineWriterMethod(rt *sobek.Runtime, proto *sobek.Object, name string, method any) error { + if hasOwnProperty(proto, name) { + return nil + } + + wrapped, err := wrapWriterMethod(rt, method) + if err != nil { + return err + } + + return setDefaultPrototypePropertyOf(proto, name, wrapped) +} + +func wrapWriterGetter(rt *sobek.Runtime, getter any) (sobek.Value, error) { + return wrapWriterPrototypeFunction(rt, getter, ` +(function(getter) { + return function() { + return getter(this); + }; +})`) +} + +func wrapWriterMethod(rt *sobek.Runtime, method any) (sobek.Value, error) { + return wrapWriterPrototypeFunction(rt, method, ` +(function(method) { + return function(arg) { + return method(this, arg); + }; +})`) +} + +func wrapWriterPrototypeFunction(rt *sobek.Runtime, callback any, source string) (sobek.Value, error) { + wrapper, err := rt.RunString(source) + if err != nil { + return nil, err + } + + call, ok := sobek.AssertFunction(wrapper) + if !ok { + return nil, newError(RuntimeError, "writer prototype wrapper is not a function") + } + + return call(sobek.Undefined(), rt.ToValue(callback)) +} + +func writableStreamDefaultWriterFromValue(rt *sobek.Runtime, value sobek.Value) *WritableStreamDefaultWriter { + if value == nil || common.IsNullish(value) { + return nil + } + + ref := value.ToObject(rt).Get(writerGoRefKey) + if ref == nil { + return nil + } + + writer, _ := ref.Export().(*WritableStreamDefaultWriter) + return writer +} + +func writableStreamDefaultWriterFromThis( + rt *sobek.Runtime, + this sobek.Value, +) *WritableStreamDefaultWriter { + writer := writableStreamDefaultWriterFromValue(rt, this) + if writer == nil { + throw(rt, newTypeError(rt, "value is not a WritableStreamDefaultWriter")) + } + + return writer +} + +// Abort aborts the stream, signaling that the producer can no longer successfully write to +// the stream. +// +// It implements the WritableStreamDefaultWriter.abort(reason) [specification] algorithm. +// +// [specification]: https://streams.spec.whatwg.org/#default-writer-abort +func (writer *WritableStreamDefaultWriter) Abort(reason sobek.Value) *sobek.Promise { + if reason == nil { + reason = sobek.Undefined() + } + + // 1. If this.[[stream]] is undefined, return a promise rejected with a TypeError exception. + stream := writer.stream + if stream == nil { + return newRejectedPromise(writer.vu, newTypeError(writer.runtime, "stream is undefined").Err()) + } + + // 2. Return ! WritableStreamDefaultWriterAbort(this, reason). + var promise *sobek.Promise + stream.withTransaction(func() { + promise = writer.abort(reason) + }) + return promise +} + +// Close closes the stream. +// +// It implements the WritableStreamDefaultWriter.close() [specification] algorithm. +// +// [specification]: https://streams.spec.whatwg.org/#default-writer-close +func (writer *WritableStreamDefaultWriter) Close() *sobek.Promise { + // 1. Let stream be this.[[stream]]. + stream := writer.stream + + // 2. If stream is undefined, return a promise rejected with a TypeError exception. + if stream == nil { + return newRejectedPromise(writer.vu, newTypeError(writer.runtime, "stream is undefined").Err()) + } + + // 3. If ! WritableStreamCloseQueuedOrInFlight(stream) is true, return a promise rejected with a TypeError. + if stream.closeQueuedOrInFlight() { + return newRejectedPromise(writer.vu, newTypeError(writer.runtime, "stream is already closing").Err()) + } + + // 4. Return ! WritableStreamDefaultWriterClose(this). + var promise *sobek.Promise + stream.withTransaction(func() { + promise = writer.close() + }) + return promise +} + +// Write writes the given chunk to the writable stream, by waiting until any previous writes +// have finished successfully, and then sending the chunk to the underlying sink's write() +// method. +// +// It implements the WritableStreamDefaultWriter.write(chunk) [specification] algorithm. +// +// [specification]: https://streams.spec.whatwg.org/#default-writer-write +func (writer *WritableStreamDefaultWriter) Write(chunk sobek.Value) *sobek.Promise { + if chunk == nil { + chunk = sobek.Undefined() + } + + // 1. If this.[[stream]] is undefined, return a promise rejected with a TypeError exception. + stream := writer.stream + if stream == nil { + return newRejectedPromise(writer.vu, newTypeError(writer.runtime, "stream is undefined").Err()) + } + + // 2. Return ! WritableStreamDefaultWriterWrite(this, chunk). + var promise *sobek.Promise + stream.withTransaction(func() { + promise = writer.write(chunk) + }) + return promise +} + +// ReleaseLock releases the writer's lock on the corresponding stream. After the lock is +// released, the writer is no longer active. +// +// It implements the WritableStreamDefaultWriter.releaseLock() [specification] algorithm. +// +// [specification]: https://streams.spec.whatwg.org/#default-writer-release-lock +func (writer *WritableStreamDefaultWriter) ReleaseLock() { + // 1. Let stream be this.[[stream]]. + stream := writer.stream + + // 2. If stream is undefined, return. + if stream == nil { + return + } + + // 3. Assert: stream.[[writer]] is not undefined. + if stream.writer == nil { + common.Throw(writer.runtime, newError(AssertionError, "stream has no writer")) + } + + // 4. Perform ! WritableStreamDefaultWriterRelease(this). + stream.withTransaction(func() { + writer.release() + }) +} + +// DesiredSize returns the desired size to fill the stream's internal queue. +// +// It implements the WritableStreamDefaultWriter.desiredSize [specification] getter. +// +// [specification]: https://streams.spec.whatwg.org/#default-writer-desired-size +func (writer *WritableStreamDefaultWriter) DesiredSize() sobek.Value { + // 1. If this.[[stream]] is undefined, throw a TypeError exception. + if writer.stream == nil { + throw(writer.runtime, newTypeError(writer.runtime, "stream is undefined")) + } + + // 2. Return ! WritableStreamDefaultWriterGetDesiredSize(this). + return writer.getDesiredSize() +} + +// setup implements the [specification]'s SetUpWritableStreamDefaultWriter abstract operation. +// +// [specification]: https://streams.spec.whatwg.org/#set-up-writable-stream-default-writer +func (writer *WritableStreamDefaultWriter) setup(stream *WritableStream) { + rt := stream.runtime + + // 1. If ! IsWritableStreamLocked(stream) is true, throw a TypeError exception. + if stream.isLocked() { + throw(rt, newTypeError(rt, "stream is locked")) + } + + // 2. Set writer.[[stream]] to stream. + writer.stream = stream + writer.runtime = rt + writer.vu = stream.vu + + // 3. Set stream.[[writer]] to writer. + stream.writer = writer + + // 4. Let state be stream.[[state]]. + state := stream.state + + switch state { + // 5. If state is "writable", + case WritableStreamStateWritable: + // 5.1. If ! WritableStreamCloseQueuedOrInFlight(stream) is false and stream.[[backpressure]] is true, + // set writer.[[readyPromise]] to a new promise. + if !stream.closeQueuedOrInFlight() && stream.backpressure { + writer.readyPromise = newPromiseWrapper(rt) + } else { + // 5.2. Otherwise, set writer.[[readyPromise]] to a promise resolved with undefined. + writer.readyPromise = newResolvedPromiseWrapper(rt, sobek.Undefined()) + } + // 5.3. Set writer.[[closedPromise]] to a new promise. + writer.closedPromise = newPromiseWrapper(rt) + // 6. Otherwise, if state is "erroring", + case WritableStreamStateErroring: + // 6.1. Set writer.[[readyPromise]] to a promise rejected with stream.[[storedError]]. + writer.readyPromise = newRejectedPromiseWrapper(rt, stream.storedError) + // 6.2. Set writer.[[readyPromise]].[[PromiseIsHandled]] to true. + markPromiseHandled(rt, writer.readyPromise.promise) + // 6.3. Set writer.[[closedPromise]] to a new promise. + writer.closedPromise = newPromiseWrapper(rt) + // 7. Otherwise, if state is "closed", + case WritableStreamStateClosed: + // 7.1. Set writer.[[readyPromise]] to a promise resolved with undefined. + writer.readyPromise = newResolvedPromiseWrapper(rt, sobek.Undefined()) + // 7.2. Set writer.[[closedPromise]] to a promise resolved with undefined. + writer.closedPromise = newResolvedPromiseWrapper(rt, sobek.Undefined()) + // 8. Otherwise, + default: + // 8.1. Assert: state is "errored". + if state != WritableStreamStateErrored { + common.Throw(rt, newError(AssertionError, "stream is not errored")) + } + // 8.2. Let storedError be stream.[[storedError]]. + storedError := stream.storedError + // 8.3. Set writer.[[readyPromise]] to a promise rejected with storedError. + writer.readyPromise = newRejectedPromiseWrapper(rt, storedError) + // 8.4. Set writer.[[readyPromise]].[[PromiseIsHandled]] to true. + markPromiseHandled(rt, writer.readyPromise.promise) + // 8.5. Set writer.[[closedPromise]] to a promise rejected with storedError. + writer.closedPromise = newRejectedPromiseWrapper(rt, storedError) + // 8.6. Set writer.[[closedPromise]].[[PromiseIsHandled]] to true. + markPromiseHandled(rt, writer.closedPromise.promise) + } +} + +// settle schedules a promise settlement on the writer's stream, deferring it until the end +// of the current transaction. If the writer is no longer attached to a stream, the +// settlement runs immediately. +func (writer *WritableStreamDefaultWriter) settle(fn func()) { + if writer.stream != nil { + writer.stream.settle(fn) + return + } + fn() +} + +// abort implements the [specification]'s WritableStreamDefaultWriterAbort abstract operation. +// +// [specification]: https://streams.spec.whatwg.org/#writable-stream-default-writer-abort +func (writer *WritableStreamDefaultWriter) abort(reason sobek.Value) *sobek.Promise { + // 1. Let stream be writer.[[stream]]. + stream := writer.stream + + // 2. Assert: stream is not undefined. + if stream == nil { + common.Throw(writer.runtime, newError(AssertionError, "stream is undefined")) + } + + // 3. Return ! WritableStreamAbort(stream, reason). + return stream.abort(reason) +} + +// close implements the [specification]'s WritableStreamDefaultWriterClose abstract operation. +// +// [specification]: https://streams.spec.whatwg.org/#writable-stream-default-writer-close +func (writer *WritableStreamDefaultWriter) close() *sobek.Promise { + // 1. Let stream be writer.[[stream]]. + stream := writer.stream + + // 2. Assert: stream is not undefined. + if stream == nil { + common.Throw(writer.runtime, newError(AssertionError, "stream is undefined")) + } + + // 3. Return ! WritableStreamClose(stream). + return stream.close() +} + +// getDesiredSize implements the [specification]'s WritableStreamDefaultWriterGetDesiredSize +// abstract operation. +// +// [specification]: https://streams.spec.whatwg.org/#writable-stream-default-writer-get-desired-size +func (writer *WritableStreamDefaultWriter) getDesiredSize() sobek.Value { + // 1. Let stream be writer.[[stream]]. + stream := writer.stream + + // 2. Let state be stream.[[state]]. + state := stream.state + + // 3. If state is "errored" or "erroring", return null. + if state == WritableStreamStateErrored || state == WritableStreamStateErroring { + return sobek.Null() + } + + // 4. If state is "closed", return 0. + if state == WritableStreamStateClosed { + return writer.runtime.ToValue(0) + } + + // 5. Return ! WritableStreamDefaultControllerGetDesiredSize(stream.[[controller]]). + return writer.runtime.ToValue(stream.controller.getDesiredSize()) +} + +// ensureClosedPromiseRejected implements the [specification]'s +// WritableStreamDefaultWriterEnsureClosedPromiseRejected abstract operation. +// +// [specification]: https://streams.spec.whatwg.org/#writable-stream-default-writer-ensure-closed-promise-rejected +func (writer *WritableStreamDefaultWriter) ensureClosedPromiseRejected(err any) { + // 1. If writer.[[closedPromise]].[[PromiseState]] is "pending", reject writer.[[closedPromise]] with error. + // 2. Otherwise, set writer.[[closedPromise]] to a promise rejected with error. + // + // The promise identity is updated synchronously (so that the `closed` getter reflects it + // immediately), but the actual rejection is deferred so that reactions observe up-to-date + // state. See [WritableStream.withTransaction]. + if !writer.closedPromise.isPending() { + writer.closedPromise = newPromiseWrapper(writer.runtime) + } + closedPromise := writer.closedPromise + closedPromise.queueSettlement() + writer.settle(func() { + closedPromise.rejectWith(err) + // 3. Set writer.[[closedPromise]].[[PromiseIsHandled]] to true. + markPromiseHandled(writer.runtime, closedPromise.promise) + }) +} + +// ensureReadyPromiseRejected implements the [specification]'s +// WritableStreamDefaultWriterEnsureReadyPromiseRejected abstract operation. +// +// [specification]: https://streams.spec.whatwg.org/#writable-stream-default-writer-ensure-ready-promise-rejected +func (writer *WritableStreamDefaultWriter) ensureReadyPromiseRejected(err any) { + // 1. If writer.[[readyPromise]].[[PromiseState]] is "pending", reject writer.[[readyPromise]] with error. + // 2. Otherwise, set writer.[[readyPromise]] to a promise rejected with error. + // + // The promise identity is updated synchronously (so that the `ready` getter reflects it + // immediately), but the actual rejection is deferred so that reactions observe up-to-date + // state. See [WritableStream.withTransaction]. + if !writer.readyPromise.isPending() { + writer.readyPromise = newPromiseWrapper(writer.runtime) + } + readyPromise := writer.readyPromise + readyPromise.queueSettlement() + writer.settle(func() { + readyPromise.rejectWith(err) + // 3. Set writer.[[readyPromise]].[[PromiseIsHandled]] to true. + markPromiseHandled(writer.runtime, readyPromise.promise) + }) +} + +// release implements the [specification]'s WritableStreamDefaultWriterRelease abstract operation. +// +// [specification]: https://streams.spec.whatwg.org/#writable-stream-default-writer-release +func (writer *WritableStreamDefaultWriter) release() { + // 1. Let stream be writer.[[stream]]. + stream := writer.stream + + // 2. Assert: stream is not undefined. + if stream == nil { + common.Throw(writer.runtime, newError(AssertionError, "stream is undefined")) + } + + // 3. Assert: stream.[[writer]] is writer. + if stream.writer != writer { + common.Throw(writer.runtime, newError(AssertionError, "stream writer is not writer")) + } + + // 4. Let releasedError be a new TypeError. + releasedError := newTypeError(writer.runtime, "writer released") + + // 5. Perform ! WritableStreamDefaultWriterEnsureReadyPromiseRejected(writer, releasedError). + writer.ensureReadyPromiseRejected(releasedError) + + // 6. Perform ! WritableStreamDefaultWriterEnsureClosedPromiseRejected(writer, releasedError). + writer.ensureClosedPromiseRejected(releasedError) + + // 7. Set stream.[[writer]] to undefined. + stream.writer = nil + + // 8. Set writer.[[stream]] to undefined. + writer.stream = nil +} + +// write implements the [specification]'s WritableStreamDefaultWriterWrite abstract operation. +// +// [specification]: https://streams.spec.whatwg.org/#writable-stream-default-writer-write +func (writer *WritableStreamDefaultWriter) write(chunk sobek.Value) *sobek.Promise { + // 1. Let stream be writer.[[stream]]. + stream := writer.stream + + // 2. Assert: stream is not undefined. + if stream == nil { + common.Throw(writer.runtime, newError(AssertionError, "stream is undefined")) + } + + // 3. Let controller be stream.[[controller]]. + controller := stream.controller + + // 4. Let chunkSize be ! WritableStreamDefaultControllerGetChunkSize(controller, chunk). + chunkSize := controller.getChunkSize(chunk) + + // 5. If stream is not equal to writer.[[stream]], return a promise rejected with a TypeError exception. + if writer.stream != stream { + return newRejectedPromise(writer.vu, newTypeError(writer.runtime, "writer was released").Err()) + } + + // 6. Let state be stream.[[state]]. + state := stream.state + + // 7. If state is "errored", return a promise rejected with stream.[[storedError]]. + if state == WritableStreamStateErrored { + return newRejectedPromise(writer.vu, throwableValue(stream.storedError)) + } + + // 8. If ! WritableStreamCloseQueuedOrInFlight(stream) is true or state is "closed", + // return a promise rejected with a TypeError exception indicating that the stream is closing or closed. + if stream.closeQueuedOrInFlight() || state == WritableStreamStateClosed { + return newRejectedPromise(writer.vu, newTypeError(writer.runtime, "stream is closing or closed").Err()) + } + + // 9. If state is "erroring", return a promise rejected with stream.[[storedError]]. + if state == WritableStreamStateErroring { + return newRejectedPromise(writer.vu, throwableValue(stream.storedError)) + } + + // 10. Assert: state is "writable". + if state != WritableStreamStateWritable { + common.Throw(writer.runtime, newError(AssertionError, "stream is not writable")) + } + + // 11. Let promise be ! WritableStreamAddWriteRequest(stream). + promise := stream.addWriteRequest() + + // 12. Perform ! WritableStreamDefaultControllerWrite(controller, chunk, chunkSize). + controller.write(chunk, chunkSize) + + // 13. Return promise. + return promise +} diff --git a/internal/js/modules/k6/experimental/streams/writable_streams.go b/internal/js/modules/k6/experimental/streams/writable_streams.go new file mode 100644 index 000000000..62c89d2e5 --- /dev/null +++ b/internal/js/modules/k6/experimental/streams/writable_streams.go @@ -0,0 +1,1156 @@ +package streams + +import ( + "github.com/grafana/sobek" + + "go.k6.io/k6/v2/js/common" + "go.k6.io/k6/v2/js/modules" +) + +// WritableStream is a concrete instance of the general [writable stream] concept. +// +// It is adaptable to any chunk type, and maintains an internal queue to keep track of +// data supplied by the producer but not yet written to the underlying sink. +// +// [writable stream]: https://streams.spec.whatwg.org/#ws-class +type WritableStream struct { + // backpressure holds the backpressure signal set by the controller. + backpressure bool + + // closeRequest holds the promise returned by the writer's or the stream's close method. + closeRequest *promiseWrapper + + // controller holds a [WritableStreamDefaultController] created with the ability to + // control the state and queue of this stream. + controller *WritableStreamDefaultController + + // inFlightWriteRequest holds the write request while a write is in flight. + inFlightWriteRequest *promiseWrapper + + // inFlightCloseRequest holds the close request while a close is in flight. + inFlightCloseRequest *promiseWrapper + + // pendingAbortRequest holds the pending abort request, or nil if there is none. + pendingAbortRequest *pendingAbortRequest + + // state holds the current state of the stream. + state WritableStreamState + + // storedError holds the error that caused the stream to be errored. + storedError any + + // writer holds the current writer of the stream if the stream is locked to a writer, + // or nil otherwise. + writer *WritableStreamDefaultWriter + // writerPrototype is the canonical prototype shared by writers vended by this stream's + // module instance. + writerPrototype *sobek.Object + + // writeRequests holds a list of pending write request promises. + writeRequests []*promiseWrapper + + // txDepth tracks the nesting depth of the current settlement transaction (see + // withTransaction). + txDepth int + + // txQueue holds promise settlements deferred until the current transaction completes. + txQueue []func() + + runtime *sobek.Runtime + vu modules.VU +} + +// WritableStreamState represents the current state of a WritableStream. +type WritableStreamState string + +const ( + // WritableStreamStateWritable indicates that the stream is writable, and more chunks may be written. + WritableStreamStateWritable = "writable" + + // WritableStreamStateErroring indicates that the stream is in the process of becoming errored. + WritableStreamStateErroring = "erroring" + + // WritableStreamStateClosed indicates that the stream is closed and cannot be written to. + WritableStreamStateClosed = "closed" + + // WritableStreamStateErrored indicates that the stream has been errored. + WritableStreamStateErrored = "errored" +) + +// pendingAbortRequest holds the state of a pending abort request, as described in the [specification]. +// +// [specification]: https://streams.spec.whatwg.org/#pending-abort-request +type pendingAbortRequest struct { + // promise is the promise returned from the stream's abort() method. + promise *promiseWrapper + + // reason is the value that was passed as an argument to the stream's abort() method. + reason any + + // wasAlreadyErroring is true if the stream was already erroring when abort() was called. + wasAlreadyErroring bool +} + +// withTransaction runs fn, and then, once the outermost transaction completes, flushes any +// promise settlements that were deferred via settle() during fn. +// +// This is necessary because, in the k6/Sobek event loop, resolving or rejecting a promise +// from Go runs its reactions synchronously. The Streams specification, on the other hand, +// assumes that settling a promise merely schedules its reactions, which run only after all +// synchronous state changes have completed. Deferring the settlements until the end of the +// transaction reproduces that behaviour: reactions observe fully-updated stream state, and +// settle in a deterministic, specification-compliant (FIFO) order. +func (stream *WritableStream) withTransaction(fn func()) { + stream.txDepth++ + defer func() { + stream.txDepth-- + if stream.txDepth == 0 { + stream.drainSettlements() + } + }() + + fn() +} + +// drainSettlements runs the deferred promise settlements in FIFO order. +func (stream *WritableStream) drainSettlements() { + // Keep the depth elevated while draining, so that any settlements scheduled by reactions + // are appended to the queue and processed in order, rather than recursively. + stream.txDepth++ + for len(stream.txQueue) > 0 { + settle := stream.txQueue[0] + stream.txQueue = stream.txQueue[1:] + settle() + } + stream.txDepth-- +} + +// settle schedules a promise settlement. If a transaction is active, the settlement is +// deferred until the transaction completes; otherwise, it runs immediately. +func (stream *WritableStream) settle(fn func()) { + if stream.txDepth == 0 { + fn() + return + } + stream.txQueue = append(stream.txQueue, fn) +} + +func (stream *WritableStream) resolvePromise(promise *promiseWrapper, value any) { + promise.queueSettlement() + stream.settle(func() { promise.resolveWith(value) }) +} + +func (stream *WritableStream) rejectPromise(promise *promiseWrapper, reason any) { + promise.queueSettlement() + stream.settle(func() { promise.rejectWith(reason) }) +} + +// Abort aborts the stream, signaling that the producer can no longer successfully write to +// the stream and it is to be immediately moved to an errored state, with any queued-up +// writes discarded. +// +// It implements the WritableStream.abort(reason) [specification] algorithm. +// +// [specification]: https://streams.spec.whatwg.org/#ws-abort +func (stream *WritableStream) Abort(reason sobek.Value) *sobek.Promise { + if reason == nil { + reason = sobek.Undefined() + } + + // 1. If ! IsWritableStreamLocked(this) is true, return a promise rejected with a TypeError exception. + if stream.isLocked() { + return newRejectedPromise(stream.vu, newTypeError(stream.runtime, "cannot abort a locked stream").Err()) + } + + // 2. Return ! WritableStreamAbort(this, reason). + var promise *sobek.Promise + stream.withTransaction(func() { + promise = stream.abort(reason) + }) + return promise +} + +// Close closes the stream. +// +// It implements the WritableStream.close() [specification] algorithm. +// +// [specification]: https://streams.spec.whatwg.org/#ws-close +func (stream *WritableStream) Close() *sobek.Promise { + // 1. If ! IsWritableStreamLocked(this) is true, return a promise rejected with a TypeError exception. + if stream.isLocked() { + return newRejectedPromise(stream.vu, newTypeError(stream.runtime, "cannot close a locked stream").Err()) + } + + // 2. If ! WritableStreamCloseQueuedOrInFlight(this) is true, return a promise rejected with a TypeError exception. + if stream.closeQueuedOrInFlight() { + return newRejectedPromise(stream.vu, newTypeError(stream.runtime, "stream is already closing").Err()) + } + + // 3. Return ! WritableStreamClose(this). + var promise *sobek.Promise + stream.withTransaction(func() { + promise = stream.close() + }) + return promise +} + +// GetWriter implements the WritableStream.getWriter() [specification] algorithm. +// +// [specification]: https://streams.spec.whatwg.org/#ws-get-writer +func (stream *WritableStream) GetWriter() sobek.Value { + // 1. Return ? AcquireWritableStreamDefaultWriter(this). + writer := stream.acquireDefaultWriter() + + obj, err := NewWritableStreamDefaultWriterObject(writer, stream.writerPrototype) + if err != nil { + common.Throw(stream.runtime, err) + } + + return obj +} + +// streamGoRefKey is the name of a hidden, non-enumerable property that holds a reference to +// the Go [WritableStream] on the stream's JavaScript object. It allows retrieving the Go +// value back from the JavaScript object (e.g. in the WritableStreamDefaultWriter constructor +// and in brand-check getters), which is not otherwise possible on a plain object. +const streamGoRefKey = "__k6WritableStream__" + +// writableStreamFromValue retrieves the Go [WritableStream] associated with a JavaScript +// value, or nil if the value is not a WritableStream object. +func writableStreamFromValue(rt *sobek.Runtime, value sobek.Value) *WritableStream { + if value == nil || common.IsNullish(value) || !isObject(value) { + return nil + } + + ref := value.ToObject(rt).Get(streamGoRefKey) + if ref == nil { + return nil + } + + stream, _ := ref.Export().(*WritableStream) + return stream +} + +func installWritableStreamPrototype(rt *sobek.Runtime, proto *sobek.Object) error { + if hasOwnProperty(proto, "locked") { + return nil + } + + return proto.DefineAccessorProperty("locked", rt.ToValue(func(fc sobek.FunctionCall) sobek.Value { + stream := writableStreamFromValue(rt, fc.This) + if stream == nil { + return sobek.Undefined() + } + return rt.ToValue(stream.isLocked()) + }), nil, sobek.FLAG_TRUE, sobek.FLAG_TRUE) +} + +// toObject builds the stream's JavaScript object. +// +// We build it as a plain object rather than a reflect-wrapped Go value, because the latter is +// not extensible: the Web Platform Tests' recordingWritableStream helper assigns extra +// properties (such as `controller` and `events`) to the stream, which a reflect-wrapped host +// object does not allow. The given proto is used as the object's prototype. +func (stream *WritableStream) toObject(proto *sobek.Object) *sobek.Object { + rt := stream.runtime + obj := rt.NewObject() + objName := "WritableStream" + + if err := setReadOnlyPropertyOf(obj, objName, "abort", rt.ToValue(stream.Abort)); err != nil { + common.Throw(rt, newError(RuntimeError, err.Error())) + } + if err := setReadOnlyPropertyOf(obj, objName, "close", rt.ToValue(stream.Close)); err != nil { + common.Throw(rt, newError(RuntimeError, err.Error())) + } + if err := setReadOnlyPropertyOf(obj, objName, "getWriter", rt.ToValue(stream.GetWriter)); err != nil { + common.Throw(rt, newError(RuntimeError, err.Error())) + } + + // We keep a hidden, non-enumerable reference to the Go stream on the object, so that the + // WritableStreamDefaultWriter constructor and the prototype's `locked` getter can retrieve + // it back from the JavaScript object. + if err := obj.DefineDataProperty( + streamGoRefKey, rt.ToValue(stream), sobek.FLAG_FALSE, sobek.FLAG_FALSE, sobek.FLAG_FALSE, + ); err != nil { + common.Throw(rt, newError(RuntimeError, err.Error())) + } + + if err := obj.SetPrototype(proto); err != nil { + common.Throw(rt, newError(RuntimeError, err.Error())) + } + + return obj +} + +// isLocked implements the [specification]'s IsWritableStreamLocked abstract operation. +// +// [specification]: https://streams.spec.whatwg.org/#is-writable-stream-locked +func (stream *WritableStream) isLocked() bool { + return stream.writer != nil +} + +// initialize implements the [specification]'s InitializeWritableStream abstract operation. +// +// [specification]: https://streams.spec.whatwg.org/#initialize-writable-stream +func (stream *WritableStream) initialize() { + stream.state = WritableStreamStateWritable + stream.storedError = nil + stream.writer = nil + stream.controller = nil + stream.inFlightWriteRequest = nil + stream.closeRequest = nil + stream.inFlightCloseRequest = nil + stream.pendingAbortRequest = nil + stream.writeRequests = []*promiseWrapper{} + stream.backpressure = false +} + +// acquireDefaultWriter implements the [specification]'s AcquireWritableStreamDefaultWriter abstract operation. +// +// [specification]: https://streams.spec.whatwg.org/#acquire-writable-stream-default-writer +func (stream *WritableStream) acquireDefaultWriter() *WritableStreamDefaultWriter { + // 1. Let writer be a new WritableStreamDefaultWriter. + writer := &WritableStreamDefaultWriter{} + + // 2. Perform ? SetUpWritableStreamDefaultWriter(writer, stream). + writer.setup(stream) + + // 3. Return writer. + return writer +} + +// abort implements the [specification]'s WritableStreamAbort abstract operation. +// +// [specification]: https://streams.spec.whatwg.org/#writable-stream-abort +func (stream *WritableStream) abort(reason sobek.Value) *sobek.Promise { + // 1. If stream.[[state]] is "closed" or "errored", return a promise resolved with undefined. + if stream.state == WritableStreamStateClosed || stream.state == WritableStreamStateErrored { + return newResolvedPromise(stream.vu, sobek.Undefined()) + } + + // 2. Signal abort on stream.[[controller]].[[signal]] with reason. + // NOTE: k6 does not support AbortSignal yet, so this step is intentionally omitted. + + // 3. Let state be stream.[[state]]. + state := stream.state + + // 4. If state is "closed" or "errored", return a promise resolved with undefined. + if state == WritableStreamStateClosed || state == WritableStreamStateErrored { + return newResolvedPromise(stream.vu, sobek.Undefined()) + } + + // 5. If stream.[[pendingAbortRequest]] is not undefined, return stream.[[pendingAbortRequest]]'s promise. + if stream.pendingAbortRequest != nil { + return stream.pendingAbortRequest.promise.promise + } + + // 6. Assert: state is "writable" or "erroring". + if state != WritableStreamStateWritable && state != WritableStreamStateErroring { + common.Throw(stream.runtime, newError(AssertionError, "stream is not writable or erroring")) + } + + // 7. Let wasAlreadyErroring be false. + wasAlreadyErroring := false + + // 8. If state is "erroring", + if state == WritableStreamStateErroring { + // 8.1. Set wasAlreadyErroring to true. + wasAlreadyErroring = true + // 8.2. Set reason to undefined. + reason = sobek.Undefined() + } + + // 9. Let promise be a new promise. + promise := newPromiseWrapper(stream.runtime) + + // 10. Set stream.[[pendingAbortRequest]] to a new pending abort request. + stream.pendingAbortRequest = &pendingAbortRequest{ + promise: promise, + reason: reason, + wasAlreadyErroring: wasAlreadyErroring, + } + + // 11. If wasAlreadyErroring is false, perform ! WritableStreamStartErroring(stream, reason). + if !wasAlreadyErroring { + stream.startErroring(reason) + } + + // 12. Return promise. + return promise.promise +} + +// close implements the [specification]'s WritableStreamClose abstract operation. +// +// [specification]: https://streams.spec.whatwg.org/#writable-stream-close +func (stream *WritableStream) close() *sobek.Promise { + // 1. Let state be stream.[[state]]. + state := stream.state + + // 2. If state is "closed" or "errored", return a promise rejected with a TypeError exception. + if state == WritableStreamStateClosed || state == WritableStreamStateErrored { + return newRejectedPromise(stream.vu, newTypeError(stream.runtime, "stream is already closed or errored").Err()) + } + + // 3. Assert: state is "writable" or "erroring". + if state != WritableStreamStateWritable && state != WritableStreamStateErroring { + common.Throw(stream.runtime, newError(AssertionError, "stream is not writable or erroring")) + } + + // 4. Assert: ! WritableStreamCloseQueuedOrInFlight(stream) is false. + if stream.closeQueuedOrInFlight() { + common.Throw(stream.runtime, newError(AssertionError, "stream is already closing")) + } + + // 5. Let promise be a new promise. + promise := newPromiseWrapper(stream.runtime) + + // 6. Set stream.[[closeRequest]] to promise. + stream.closeRequest = promise + + // 7. Let writer be stream.[[writer]]. + writer := stream.writer + + // 8. If writer is not undefined, and stream.[[backpressure]] is true, and state is "writable", + // resolve writer.[[readyPromise]] with undefined. + if writer != nil && stream.backpressure && state == WritableStreamStateWritable { + readyPromise := writer.readyPromise + stream.resolvePromise(readyPromise, sobek.Undefined()) + } + + // 9. Perform ! WritableStreamDefaultControllerClose(stream.[[controller]]). + stream.controller.close() + + // 10. Return promise. + return promise.promise +} + +// addWriteRequest implements the [specification]'s WritableStreamAddWriteRequest abstract operation. +// +// [specification]: https://streams.spec.whatwg.org/#writable-stream-add-write-request +func (stream *WritableStream) addWriteRequest() *sobek.Promise { + // 1. Assert: ! IsWritableStreamLocked(stream) is true. + if !stream.isLocked() { + common.Throw(stream.runtime, newError(AssertionError, "stream is not locked")) + } + + // 2. Assert: stream.[[state]] is "writable". + if stream.state != WritableStreamStateWritable { + common.Throw(stream.runtime, newError(AssertionError, "stream is not writable")) + } + + // 3. Let promise be a new promise. + promise := newPromiseWrapper(stream.runtime) + + // 4. Append promise to stream.[[writeRequests]]. + stream.writeRequests = append(stream.writeRequests, promise) + + // 5. Return promise. + return promise.promise +} + +// closeQueuedOrInFlight implements the [specification]'s WritableStreamCloseQueuedOrInFlight +// abstract operation. +// +// [specification]: https://streams.spec.whatwg.org/#writable-stream-close-queued-or-in-flight +func (stream *WritableStream) closeQueuedOrInFlight() bool { + // 1. If stream.[[closeRequest]] is undefined and stream.[[inFlightCloseRequest]] is undefined, return false. + // 2. Return true. + return stream.closeRequest != nil || stream.inFlightCloseRequest != nil +} + +// dealWithRejection implements the [specification]'s WritableStreamDealWithRejection +// abstract operation. +// +// [specification]: https://streams.spec.whatwg.org/#writable-stream-deal-with-rejection +func (stream *WritableStream) dealWithRejection(err any) { + // 1. Let state be stream.[[state]]. + state := stream.state + + // 2. If state is "writable", + if state == WritableStreamStateWritable { + // 2.1. Perform ! WritableStreamStartErroring(stream, error). + stream.startErroring(err) + // 2.2. Return. + return + } + + // 3. Assert: state is "erroring". + if state != WritableStreamStateErroring { + common.Throw(stream.runtime, newError(AssertionError, "stream is not erroring")) + } + + // 4. Perform ! WritableStreamFinishErroring(stream). + stream.finishErroring() +} + +// startErroring implements the [specification]'s WritableStreamStartErroring abstract operation. +// +// [specification]: https://streams.spec.whatwg.org/#writable-stream-start-erroring +func (stream *WritableStream) startErroring(reason any) { + // 1. Assert: stream.[[storedError]] is undefined. + if stream.storedError != nil { + common.Throw(stream.runtime, newError(AssertionError, "stream already has a stored error")) + } + + // 2. Assert: stream.[[state]] is "writable". + if stream.state != WritableStreamStateWritable { + common.Throw(stream.runtime, newError(AssertionError, "stream is not writable")) + } + + // 3. Let controller be stream.[[controller]]. + controller := stream.controller + + // 4. Assert: controller is not undefined. + if controller == nil { + common.Throw(stream.runtime, newError(AssertionError, "stream has no controller")) + } + + // 5. Set stream.[[state]] to "erroring". + stream.state = WritableStreamStateErroring + + // 6. Set stream.[[storedError]] to reason. + stream.storedError = reason + + // 7. Let writer be stream.[[writer]]. + writer := stream.writer + + // 8. If writer is not undefined, perform ! WritableStreamDefaultWriterEnsureReadyPromiseRejected(writer, reason). + if writer != nil { + writer.ensureReadyPromiseRejected(reason) + } + + // 9. If ! WritableStreamHasOperationMarkedInFlight(stream) is false and controller.[[started]] is true, + // perform ! WritableStreamFinishErroring(stream). + if !stream.hasOperationMarkedInFlight() && controller.started { + stream.finishErroring() + } +} + +// finishErroring implements the [specification]'s WritableStreamFinishErroring abstract operation. +// +// [specification]: https://streams.spec.whatwg.org/#writable-stream-finish-erroring +func (stream *WritableStream) finishErroring() { + // 1. Assert: stream.[[state]] is "erroring". + if stream.state != WritableStreamStateErroring { + common.Throw(stream.runtime, newError(AssertionError, "stream is not erroring")) + } + + // 2. Assert: ! WritableStreamHasOperationMarkedInFlight(stream) is false. + if stream.hasOperationMarkedInFlight() { + common.Throw(stream.runtime, newError(AssertionError, "stream has an operation marked in-flight")) + } + + // 3. Set stream.[[state]] to "errored". + stream.state = WritableStreamStateErrored + + // 4. Perform ! stream.[[controller]].[[ErrorSteps]](). + stream.controller.errorSteps() + + // 5. Let storedError be stream.[[storedError]]. + storedError := stream.storedError + + // 6. For each writeRequest of stream.[[writeRequests]]: reject writeRequest with storedError. + for _, writeRequest := range stream.writeRequests { + wr := writeRequest + stream.rejectPromise(wr, storedError) + } + + // 7. Set stream.[[writeRequests]] to an empty list. + stream.writeRequests = []*promiseWrapper{} + + // 8. If stream.[[pendingAbortRequest]] is undefined, + if stream.pendingAbortRequest == nil { + // 8.1. Perform ! WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream). + stream.rejectCloseAndClosedPromiseIfNeeded() + // 8.2. Return. + return + } + + // 9. Let abortRequest be stream.[[pendingAbortRequest]]. + abortRequest := stream.pendingAbortRequest + + // 10. Set stream.[[pendingAbortRequest]] to undefined. + stream.pendingAbortRequest = nil + + // 11. If abortRequest's was already erroring is true, + if abortRequest.wasAlreadyErroring { + // 11.1. Reject abortRequest's promise with storedError. + stream.rejectPromise(abortRequest.promise, storedError) + // 11.2. Perform ! WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream). + stream.rejectCloseAndClosedPromiseIfNeeded() + // 11.3. Return. + return + } + + // 12. Let promise be ! stream.[[controller]].[[AbortSteps]](abortRequest's reason). + promise := stream.controller.abortSteps(abortRequest.reason) + + _, err := promiseThen(stream.runtime, promise, + // 13. Upon fulfillment of promise, + func(sobek.Value) { + stream.withTransaction(func() { + // 13.1. Resolve abortRequest's promise with undefined. + stream.resolvePromise(abortRequest.promise, sobek.Undefined()) + // 13.2. Perform ! WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream). + stream.rejectCloseAndClosedPromiseIfNeeded() + }) + }, + // 14. Upon rejection of promise with reason reason, + func(reason sobek.Value) { + stream.withTransaction(func() { + // 14.1. Reject abortRequest's promise with reason. + stream.rejectPromise(abortRequest.promise, reason) + // 14.2. Perform ! WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream). + stream.rejectCloseAndClosedPromiseIfNeeded() + }) + }, + ) + if err != nil { + common.Throw(stream.runtime, err) + } +} + +// finishInFlightWrite implements the [specification]'s WritableStreamFinishInFlightWrite +// abstract operation. +// +// [specification]: https://streams.spec.whatwg.org/#writable-stream-finish-in-flight-write +func (stream *WritableStream) finishInFlightWrite() { + // 1. Assert: stream.[[inFlightWriteRequest]] is not undefined. + if stream.inFlightWriteRequest == nil { + common.Throw(stream.runtime, newError(AssertionError, "stream has no in-flight write request")) + } + + // 2. Resolve stream.[[inFlightWriteRequest]] with undefined. + inFlightWriteRequest := stream.inFlightWriteRequest + stream.resolvePromise(inFlightWriteRequest, sobek.Undefined()) + + // 3. Set stream.[[inFlightWriteRequest]] to undefined. + stream.inFlightWriteRequest = nil +} + +// finishInFlightWriteWithError implements the [specification]'s +// WritableStreamFinishInFlightWriteWithError abstract operation. +// +// [specification]: https://streams.spec.whatwg.org/#writable-stream-finish-in-flight-write-with-error +func (stream *WritableStream) finishInFlightWriteWithError(err any) { + // 1. Assert: stream.[[inFlightWriteRequest]] is not undefined. + if stream.inFlightWriteRequest == nil { + common.Throw(stream.runtime, newError(AssertionError, "stream has no in-flight write request")) + } + + // 2. Reject stream.[[inFlightWriteRequest]] with error. + inFlightWriteRequest := stream.inFlightWriteRequest + stream.rejectPromise(inFlightWriteRequest, err) + + // 3. Set stream.[[inFlightWriteRequest]] to undefined. + stream.inFlightWriteRequest = nil + + // 4. Assert: stream.[[state]] is "writable" or "erroring". + if stream.state != WritableStreamStateWritable && stream.state != WritableStreamStateErroring { + common.Throw(stream.runtime, newError(AssertionError, "stream is not writable or erroring")) + } + + // 5. Perform ! WritableStreamDealWithRejection(stream, error). + stream.dealWithRejection(err) +} + +// finishInFlightClose implements the [specification]'s WritableStreamFinishInFlightClose +// abstract operation. +// +// [specification]: https://streams.spec.whatwg.org/#writable-stream-finish-in-flight-close +func (stream *WritableStream) finishInFlightClose() { + // 1. Assert: stream.[[inFlightCloseRequest]] is not undefined. + if stream.inFlightCloseRequest == nil { + common.Throw(stream.runtime, newError(AssertionError, "stream has no in-flight close request")) + } + + // 2. Resolve stream.[[inFlightCloseRequest]] with undefined. + inFlightCloseRequest := stream.inFlightCloseRequest + stream.resolvePromise(inFlightCloseRequest, sobek.Undefined()) + + // 3. Set stream.[[inFlightCloseRequest]] to undefined. + stream.inFlightCloseRequest = nil + + // 4. Let state be stream.[[state]]. + state := stream.state + + // 5. Assert: stream.[[state]] is "writable" or "erroring". + if state != WritableStreamStateWritable && state != WritableStreamStateErroring { + common.Throw(stream.runtime, newError(AssertionError, "stream is not writable or erroring")) + } + + // 6. If state is "erroring", + if state == WritableStreamStateErroring { + // 6.1. Set stream.[[storedError]] to undefined. + stream.storedError = nil + + // 6.2. If stream.[[pendingAbortRequest]] is not undefined, + if stream.pendingAbortRequest != nil { + // 6.2.1. Resolve stream.[[pendingAbortRequest]]'s promise with undefined. + abortRequest := stream.pendingAbortRequest + stream.resolvePromise(abortRequest.promise, sobek.Undefined()) + // 6.2.2. Set stream.[[pendingAbortRequest]] to undefined. + stream.pendingAbortRequest = nil + } + } + + // 7. Set stream.[[state]] to "closed". + stream.state = WritableStreamStateClosed + + // 8. Let writer be stream.[[writer]]. + writer := stream.writer + + // 9. If writer is not undefined, resolve writer.[[closedPromise]] with undefined. + if writer != nil { + closedPromise := writer.closedPromise + stream.resolvePromise(closedPromise, sobek.Undefined()) + } + + // 10. Assert: stream.[[pendingAbortRequest]] is undefined. + if stream.pendingAbortRequest != nil { + common.Throw(stream.runtime, newError(AssertionError, "stream has a pending abort request")) + } + + // 11. Assert: stream.[[storedError]] is undefined. + if stream.storedError != nil { + common.Throw(stream.runtime, newError(AssertionError, "stream has a stored error")) + } +} + +// finishInFlightCloseWithError implements the [specification]'s +// WritableStreamFinishInFlightCloseWithError abstract operation. +// +// [specification]: https://streams.spec.whatwg.org/#writable-stream-finish-in-flight-close-with-error +func (stream *WritableStream) finishInFlightCloseWithError(err any) { + // 1. Assert: stream.[[inFlightCloseRequest]] is not undefined. + if stream.inFlightCloseRequest == nil { + common.Throw(stream.runtime, newError(AssertionError, "stream has no in-flight close request")) + } + + // 2. Reject stream.[[inFlightCloseRequest]] with error. + inFlightCloseRequest := stream.inFlightCloseRequest + stream.rejectPromise(inFlightCloseRequest, err) + + // 3. Set stream.[[inFlightCloseRequest]] to undefined. + stream.inFlightCloseRequest = nil + + // 4. Assert: stream.[[state]] is "writable" or "erroring". + if stream.state != WritableStreamStateWritable && stream.state != WritableStreamStateErroring { + common.Throw(stream.runtime, newError(AssertionError, "stream is not writable or erroring")) + } + + // 5. If stream.[[pendingAbortRequest]] is not undefined, + if stream.pendingAbortRequest != nil { + // 5.1. Reject stream.[[pendingAbortRequest]]'s promise with error. + abortRequest := stream.pendingAbortRequest + stream.rejectPromise(abortRequest.promise, err) + // 5.2. Set stream.[[pendingAbortRequest]] to undefined. + stream.pendingAbortRequest = nil + } + + // 6. Perform ! WritableStreamDealWithRejection(stream, error). + stream.dealWithRejection(err) +} + +// hasOperationMarkedInFlight implements the [specification]'s +// WritableStreamHasOperationMarkedInFlight abstract operation. +// +// [specification]: https://streams.spec.whatwg.org/#writable-stream-has-operation-marked-in-flight +func (stream *WritableStream) hasOperationMarkedInFlight() bool { + // 1. If stream.[[inFlightWriteRequest]] is undefined and stream.[[inFlightCloseRequest]] is undefined, return false. + // 2. Return true. + return stream.inFlightWriteRequest != nil || stream.inFlightCloseRequest != nil +} + +// markCloseRequestInFlight implements the [specification]'s WritableStreamMarkCloseRequestInFlight +// abstract operation. +// +// [specification]: https://streams.spec.whatwg.org/#writable-stream-mark-close-request-in-flight +func (stream *WritableStream) markCloseRequestInFlight() { + // 1. Assert: stream.[[inFlightCloseRequest]] is undefined. + if stream.inFlightCloseRequest != nil { + common.Throw(stream.runtime, newError(AssertionError, "stream has an in-flight close request")) + } + + // 2. Assert: stream.[[closeRequest]] is not undefined. + if stream.closeRequest == nil { + common.Throw(stream.runtime, newError(AssertionError, "stream has no close request")) + } + + // 3. Set stream.[[inFlightCloseRequest]] to stream.[[closeRequest]]. + stream.inFlightCloseRequest = stream.closeRequest + + // 4. Set stream.[[closeRequest]] to undefined. + stream.closeRequest = nil +} + +// markFirstWriteRequestInFlight implements the [specification]'s +// WritableStreamMarkFirstWriteRequestInFlight abstract operation. +// +// [specification]: https://streams.spec.whatwg.org/#writable-stream-mark-first-write-request-in-flight +func (stream *WritableStream) markFirstWriteRequestInFlight() { + // 1. Assert: stream.[[inFlightWriteRequest]] is undefined. + if stream.inFlightWriteRequest != nil { + common.Throw(stream.runtime, newError(AssertionError, "stream has an in-flight write request")) + } + + // 2. Assert: stream.[[writeRequests]] is not empty. + if len(stream.writeRequests) == 0 { + common.Throw(stream.runtime, newError(AssertionError, "stream has no write requests")) + } + + // 3. Let writeRequest be stream.[[writeRequests]][0]. + writeRequest := stream.writeRequests[0] + + // 4. Remove writeRequest from stream.[[writeRequests]]. + stream.writeRequests = stream.writeRequests[1:] + + // 5. Set stream.[[inFlightWriteRequest]] to writeRequest. + stream.inFlightWriteRequest = writeRequest +} + +// rejectCloseAndClosedPromiseIfNeeded implements the [specification]'s +// WritableStreamRejectCloseAndClosedPromiseIfNeeded abstract operation. +// +// [specification]: https://streams.spec.whatwg.org/#writable-stream-reject-close-and-closed-promise-if-needed +func (stream *WritableStream) rejectCloseAndClosedPromiseIfNeeded() { + // 1. Assert: stream.[[state]] is "errored". + if stream.state != WritableStreamStateErrored { + common.Throw(stream.runtime, newError(AssertionError, "stream is not errored")) + } + + storedError := stream.storedError + + // 2. If stream.[[closeRequest]] is not undefined, + if stream.closeRequest != nil { + // 2.1. Assert: stream.[[inFlightCloseRequest]] is undefined. + if stream.inFlightCloseRequest != nil { + common.Throw(stream.runtime, newError(AssertionError, "stream has an in-flight close request")) + } + + // 2.2. Reject stream.[[closeRequest]] with stream.[[storedError]]. + closeRequest := stream.closeRequest + stream.rejectPromise(closeRequest, storedError) + + // 2.3. Set stream.[[closeRequest]] to undefined. + stream.closeRequest = nil + } + + // 3. Let writer be stream.[[writer]]. + writer := stream.writer + + // 4. If writer is not undefined, + if writer != nil { + // 4.1. Reject writer.[[closedPromise]] with stream.[[storedError]]. + closedPromise := writer.closedPromise + closedPromise.queueSettlement() + stream.settle(func() { + closedPromise.rejectWith(storedError) + // 4.2. Set writer.[[closedPromise]].[[PromiseIsHandled]] to true. + markPromiseHandled(stream.runtime, closedPromise.promise) + }) + } +} + +// updateBackpressure implements the [specification]'s WritableStreamUpdateBackpressure +// abstract operation. +// +// [specification]: https://streams.spec.whatwg.org/#writable-stream-update-backpressure +func (stream *WritableStream) updateBackpressure(backpressure bool) { + // 1. Assert: stream.[[state]] is "writable". + if stream.state != WritableStreamStateWritable { + common.Throw(stream.runtime, newError(AssertionError, "stream is not writable")) + } + + // 2. Assert: ! WritableStreamCloseQueuedOrInFlight(stream) is false. + if stream.closeQueuedOrInFlight() { + common.Throw(stream.runtime, newError(AssertionError, "stream is already closing")) + } + + // 3. Let writer be stream.[[writer]]. + writer := stream.writer + + // 4. If writer is not undefined and backpressure is not stream.[[backpressure]], + if writer != nil && backpressure != stream.backpressure { + if backpressure { + // 4.1. If backpressure is true, set writer.[[readyPromise]] to a new promise. + writer.readyPromise = newPromiseWrapper(stream.runtime) + } else { + // 4.2. Otherwise, + // 4.2.1. Assert: backpressure is false. + // 4.2.2. Resolve writer.[[readyPromise]] with undefined. + readyPromise := writer.readyPromise + stream.resolvePromise(readyPromise, sobek.Undefined()) + } + } + + // 5. Set stream.[[backpressure]] to backpressure. + stream.backpressure = backpressure +} + +// setupWritableStreamDefaultControllerFromUnderlyingSink implements the [specification]'s +// SetUpWritableStreamDefaultControllerFromUnderlyingSink abstract operation. +// +// [specification]: https://streams.spec.whatwg.org/#set-up-writable-stream-default-controller-from-underlying-sink +func (stream *WritableStream) setupWritableStreamDefaultControllerFromUnderlyingSink( + underlyingSink *sobek.Object, + underlyingSinkDict UnderlyingSink, + highWaterMark float64, + sizeAlgorithm SizeAlgorithm, +) { + // 1. Let controller be a new WritableStreamDefaultController. + controller := &WritableStreamDefaultController{} + + // 2. Let startAlgorithm be an algorithm that returns undefined. + var startAlgorithm UnderlyingSinkStartCallback = func(*sobek.Object) sobek.Value { + return sobek.Undefined() + } + + // 3. Let writeAlgorithm be an algorithm that returns a promise resolved with undefined. + var writeAlgorithm UnderlyingSinkWriteCallback = func(sobek.Value, *sobek.Object) *sobek.Promise { + return newResolvedPromise(stream.vu, sobek.Undefined()) + } + + // 4. Let closeAlgorithm be an algorithm that returns a promise resolved with undefined. + var closeAlgorithm UnderlyingSinkCloseCallback = func() *sobek.Promise { + return newResolvedPromise(stream.vu, sobek.Undefined()) + } + + // 5. Let abortAlgorithm be an algorithm that returns a promise resolved with undefined. + var abortAlgorithm UnderlyingSinkAbortCallback = func(any) *sobek.Promise { + return newResolvedPromise(stream.vu, sobek.Undefined()) + } + + // 6. If underlyingSinkDict["start"] exists, then set startAlgorithm to an algorithm which + // returns the result of invoking underlyingSinkDict["start"] with argument list « controller » + // and callback this value underlyingSink. + if underlyingSinkDict.Start != nil && !sobek.IsUndefined(underlyingSinkDict.Start) { + startAlgorithm = stream.startAlgorithm(underlyingSink, underlyingSinkDict) + } + + // 7. If underlyingSinkDict["write"] exists, then set writeAlgorithm to an algorithm which + // returns the result of invoking underlyingSinkDict["write"] with argument list « chunk, controller » + // and callback this value underlyingSink. + if underlyingSinkDict.Write != nil && !sobek.IsUndefined(underlyingSinkDict.Write) { + writeAlgorithm = stream.writeAlgorithm(underlyingSink, underlyingSinkDict) + } + + // 8. If underlyingSinkDict["close"] exists, then set closeAlgorithm to an algorithm which + // returns the result of invoking underlyingSinkDict["close"] with argument list « » + // and callback this value underlyingSink. + if underlyingSinkDict.Close != nil && !sobek.IsUndefined(underlyingSinkDict.Close) { + closeAlgorithm = stream.closeAlgorithm(underlyingSink, underlyingSinkDict) + } + + // 9. If underlyingSinkDict["abort"] exists, then set abortAlgorithm to an algorithm which + // returns the result of invoking underlyingSinkDict["abort"] with argument list « reason » + // and callback this value underlyingSink. + if underlyingSinkDict.Abort != nil && !sobek.IsUndefined(underlyingSinkDict.Abort) { + abortAlgorithm = stream.abortAlgorithm(underlyingSink, underlyingSinkDict) + } + + // 10. Perform ? SetUpWritableStreamDefaultController(...). + stream.setupWritableStreamDefaultController( + controller, + startAlgorithm, + writeAlgorithm, + closeAlgorithm, + abortAlgorithm, + highWaterMark, + sizeAlgorithm, + ) +} + +func (stream *WritableStream) startAlgorithm( + underlyingSink *sobek.Object, + underlyingSinkDict UnderlyingSink, +) UnderlyingSinkStartCallback { + call, ok := sobek.AssertFunction(underlyingSinkDict.Start) + if !ok { + throw(stream.runtime, newTypeError(stream.runtime, "underlyingSink.[[start]] must be a function")) + } + + return func(controller *sobek.Object) sobek.Value { + v, err := call(underlyingSink, controller) + if err != nil { + panic(err) + } + return v + } +} + +func (stream *WritableStream) writeAlgorithm( + underlyingSink *sobek.Object, + underlyingSinkDict UnderlyingSink, +) UnderlyingSinkWriteCallback { + call, ok := sobek.AssertFunction(underlyingSinkDict.Write) + if !ok { + throw(stream.runtime, newTypeError(stream.runtime, "underlyingSink.[[write]] must be a function")) + } + + return func(chunk sobek.Value, controller *sobek.Object) *sobek.Promise { + v, err := call(underlyingSink, chunk, controller) + if err != nil { + return stream.rejectedPromiseFromErr(err) + } + if p, ok := v.Export().(*sobek.Promise); ok { + return p + } + return newResolvedPromise(stream.vu, v) + } +} + +func (stream *WritableStream) closeAlgorithm( + underlyingSink *sobek.Object, + underlyingSinkDict UnderlyingSink, +) UnderlyingSinkCloseCallback { + call, ok := sobek.AssertFunction(underlyingSinkDict.Close) + if !ok { + throw(stream.runtime, newTypeError(stream.runtime, "underlyingSink.[[close]] must be a function")) + } + + return func() *sobek.Promise { + v, err := call(underlyingSink) + if err != nil { + return stream.rejectedPromiseFromErr(err) + } + if p, ok := v.Export().(*sobek.Promise); ok { + return p + } + return newResolvedPromise(stream.vu, v) + } +} + +func (stream *WritableStream) abortAlgorithm( + underlyingSink *sobek.Object, + underlyingSinkDict UnderlyingSink, +) UnderlyingSinkAbortCallback { + call, ok := sobek.AssertFunction(underlyingSinkDict.Abort) + if !ok { + throw(stream.runtime, newTypeError(stream.runtime, "underlyingSink.[[abort]] must be a function")) + } + + return func(reason any) *sobek.Promise { + v, err := call(underlyingSink, stream.runtime.ToValue(reason)) + if err != nil { + return stream.rejectedPromiseFromErr(err) + } + if p, ok := v.Export().(*sobek.Promise); ok { + return p + } + return newResolvedPromise(stream.vu, v) + } +} + +// rejectedPromiseFromErr returns a rejected promise from a Go error, unwrapping any +// [sobek.Exception] so that the original thrown value is preserved. +func (stream *WritableStream) rejectedPromiseFromErr(err error) *sobek.Promise { + return newRejectedPromise(stream.vu, exceptionValue(err)) +} + +// setupWritableStreamDefaultController implements the [specification]'s +// SetUpWritableStreamDefaultController abstract operation. +// +// [specification]: https://streams.spec.whatwg.org/#set-up-writable-stream-default-controller +func (stream *WritableStream) setupWritableStreamDefaultController( + controller *WritableStreamDefaultController, + startAlgorithm UnderlyingSinkStartCallback, + writeAlgorithm UnderlyingSinkWriteCallback, + closeAlgorithm UnderlyingSinkCloseCallback, + abortAlgorithm UnderlyingSinkAbortCallback, + highWaterMark float64, + sizeAlgorithm SizeAlgorithm, +) { + rt := stream.runtime + + // 1. Assert: stream implements WritableStream. + // 2. Assert: stream.[[controller]] is undefined. + if stream.controller != nil { + common.Throw(rt, newError(AssertionError, "stream already has a controller")) + } + + // 3. Set controller.[[stream]] to stream. + controller.stream = stream + + // 4. Set stream.[[controller]] to controller. + stream.controller = controller + + // 5. Perform ! ResetQueue(controller). + controller.resetQueue() + + // 6. Set controller.[[signal]] to a new AbortSignal. + // NOTE: k6 does not support AbortSignal yet, so this step is intentionally omitted. + + // 7. Set controller.[[started]] to false. + controller.started = false + + // 8. Set controller.[[strategySizeAlgorithm]] to sizeAlgorithm. + controller.strategySizeAlgorithm = sizeAlgorithm + + // 9. Set controller.[[strategyHWM]] to highWaterMark. + controller.strategyHWM = highWaterMark + + // 10. Set controller.[[writeAlgorithm]] to writeAlgorithm. + controller.writeAlgorithm = writeAlgorithm + + // 11. Set controller.[[closeAlgorithm]] to closeAlgorithm. + controller.closeAlgorithm = closeAlgorithm + + // 12. Set controller.[[abortAlgorithm]] to abortAlgorithm. + controller.abortAlgorithm = abortAlgorithm + + // 13. Let backpressure be ! WritableStreamDefaultControllerGetBackpressure(controller). + backpressure := controller.getBackpressure() + + // 14. Perform ! WritableStreamUpdateBackpressure(stream, backpressure). + stream.updateBackpressure(backpressure) + + // 15. Let startResult be the result of performing startAlgorithm. (This may throw an exception.) + controllerObj, err := controller.toObject() + if err != nil { + common.Throw(rt, newError(RuntimeError, err.Error())) + } + startResult := startAlgorithm(controllerObj) + + // 16. Let startPromise be a promise resolved with startResult. + var startPromise *sobek.Promise + if common.IsNullish(startResult) { + startPromise = newResolvedPromise(stream.vu, sobek.Undefined()) + } else if p, ok := startResult.Export().(*sobek.Promise); ok { + startPromise = p + } else { + startPromise = newResolvedPromise(stream.vu, startResult) + } + + _, err = promiseThen(rt, startPromise, + // 17. Upon fulfillment of startPromise, + func(sobek.Value) { + stream.withTransaction(func() { + // 17.1. Assert: stream.[[state]] is "writable" or "erroring". + if stream.state != WritableStreamStateWritable && stream.state != WritableStreamStateErroring { + common.Throw(rt, newError(AssertionError, "stream is not writable or erroring")) + } + // 17.2. Set controller.[[started]] to true. + controller.started = true + // 17.3. Perform ! WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller). + controller.advanceQueueIfNeeded() + }) + }, + // 18. Upon rejection of startPromise with reason r, + func(r sobek.Value) { + stream.withTransaction(func() { + // 18.1. Assert: stream.[[state]] is "writable" or "erroring". + if stream.state != WritableStreamStateWritable && stream.state != WritableStreamStateErroring { + common.Throw(rt, newError(AssertionError, "stream is not writable or erroring")) + } + // 18.2. Set controller.[[started]] to true. + controller.started = true + // 18.3. Perform ! WritableStreamDealWithRejection(stream, r). + stream.dealWithRejection(r) + }) + }, + ) + if err != nil { + common.Throw(rt, err) + } +} diff --git a/internal/js/modules/k6/experimental/streams/writable_streams_regression_test.go b/internal/js/modules/k6/experimental/streams/writable_streams_regression_test.go new file mode 100644 index 000000000..d99b4a8ce --- /dev/null +++ b/internal/js/modules/k6/experimental/streams/writable_streams_regression_test.go @@ -0,0 +1,213 @@ +package streams + +import ( + "testing" + + "github.com/grafana/sobek" + "github.com/stretchr/testify/require" + "go.k6.io/k6/v2/js/modulestest" +) + +func newStreamsRuntime(t testing.TB) *modulestest.Runtime { + t.Helper() + + rt := modulestest.NewRuntime(t) + m := New().NewModuleInstance(rt.VU) + for k, v := range m.Exports().Named { + require.NoError(t, rt.VU.RuntimeField.Set(k, v)) + } + + return rt +} + +func runStreamScript(t testing.TB, script string) sobek.Value { + t.Helper() + + rt := newStreamsRuntime(t) + value, err := rt.RunOnEventLoop(script) + require.NoError(t, err) + + return value +} + +func runStreamPromiseScript(t testing.TB, script string) sobek.Value { + t.Helper() + + rt := newStreamsRuntime(t) + callback := rt.VU.RegisterCallback() + var result sobek.Value + + require.NoError(t, rt.VU.Runtime().Set("__streamTestDone", func(value sobek.Value) { + result = value + callback(func() error { return nil }) + })) + + _, err := rt.RunOnEventLoop(` +Promise.resolve((async () => { +` + script + ` +})()).then( + value => __streamTestDone(value), + error => __streamTestDone("ERROR:" + (error && error.message || error)) +); +`) + require.NoError(t, err) + require.NotNil(t, result) + + return result +} + +func TestStreamControllerConstructorsThrowWhenCalled(t *testing.T) { + t.Parallel() + + result := runStreamScript(t, ` +const results = []; + +new WritableStream({ + start(controller) { + try { + controller.constructor().error(new Error("boom")); + results.push("writable did not throw"); + } catch (error) { + results.push(error instanceof TypeError); + } + }, +}); + +new ReadableStream({ + start(controller) { + try { + controller.constructor().error(new Error("boom")); + results.push("readable did not throw"); + } catch (error) { + results.push(error instanceof TypeError); + } + }, +}); + +JSON.stringify(results); +`) + + require.Equal(t, `[true,true]`, result.String()) +} + +func TestWritableStreamUnderlyingSinkDictionaryPresence(t *testing.T) { + t.Parallel() + + result := runStreamScript(t, ` +const results = []; + +try { + new WritableStream({ + start: undefined, + write: undefined, + close: undefined, + abort: undefined, + }); + results.push("undefined callbacks ignored"); +} catch (error) { + results.push(error && error.message); +} + +try { + new WritableStream({ type: null }); + results.push("type null accepted"); +} catch (error) { + results.push(error instanceof RangeError); +} + +JSON.stringify(results); +`) + + require.Equal(t, `["undefined callbacks ignored",true]`, result.String()) +} + +func TestWritableStreamReusesControllerObject(t *testing.T) { + t.Parallel() + + result := runStreamPromiseScript(t, ` +let startController; +let writeController; +let marker; + +const stream = new WritableStream({ + start(controller) { + startController = controller; + controller.marker = "kept"; + }, + write(_chunk, controller) { + writeController = controller; + marker = controller.marker; + }, +}); + +const writer = stream.getWriter(); +await writer.write("chunk"); + +return JSON.stringify([writeController === startController, marker]); +`) + + require.Equal(t, `[true,"kept"]`, result.String()) +} + +func TestWritableStreamSizeConversionAbruptCompletionRejectsWrite(t *testing.T) { + t.Parallel() + + result := runStreamPromiseScript(t, ` +const boom = new Error("sz"); +const stream = new WritableStream({ + write() {}, +}, { + size() { + return { + valueOf() { + throw boom; + }, + }; + }, +}); +const writer = stream.getWriter(); + +let writePromise; +try { + writePromise = writer.write("chunk"); +} catch (error) { + return "threw:" + error.message; +} + +const writeResult = await writePromise.then( + () => "write fulfilled", + error => error === boom ? "write rejected with boom" : "write rejected with " + error.message, +); +const closeResult = await writer.close().then( + () => "close fulfilled", + error => error ? "close rejected" : "close rejected without error", +); + +return JSON.stringify([writeResult, closeResult]); +`) + + require.Equal(t, `["write rejected with boom","close rejected"]`, result.String()) +} + +func TestWritableStreamQueuedReadyRejectionWinsOverQueuedFulfillment(t *testing.T) { + t.Parallel() + + result := runStreamPromiseScript(t, ` +const boom = new Error("boom"); +const stream = new WritableStream({ + write(_chunk, controller) { + controller.error(boom); + }, +}, { highWaterMark: 1 }); +const writer = stream.getWriter(); + +await writer.write("chunk").catch(() => {}); + +return writer.ready.then( + () => "ready fulfilled", + error => error === boom ? "ready rejected with boom" : "ready rejected with " + error.message, +); +`) + + require.Equal(t, "ready rejected with boom", result.String()) +} diff --git a/internal/js/modules/k6/experimental/streams/writable_streams_test.go b/internal/js/modules/k6/experimental/streams/writable_streams_test.go new file mode 100644 index 000000000..991dcbabe --- /dev/null +++ b/internal/js/modules/k6/experimental/streams/writable_streams_test.go @@ -0,0 +1,162 @@ +package streams + +import ( + "os" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "go.k6.io/k6/v2/internal/js/compiler" + "go.k6.io/k6/v2/js/modulestest" +) + +func TestWritableStreamUsesCanonicalPrototypes(t *testing.T) { + t.Parallel() + + runtime := modulestest.NewRuntime(t) + err := runtime.SetupModuleSystem( + map[string]any{"k6/experimental/streams": New()}, + nil, + compiler.New(runtime.VU.InitEnv().Logger), + ) + require.NoError(t, err) + + _, err = runtime.VU.Runtime().RunString(` +const { + WritableStream, + WritableStreamDefaultWriter, +} = require("k6/experimental/streams"); + +function assert(condition, message) { + if (!condition) { + throw new Error(message); + } +} + +function assertThrowsTypeError(fn, message) { + try { + fn(); + } catch (error) { + assert(error instanceof TypeError, message + ": expected TypeError, got " + error); + return; + } + throw new Error(message + ": expected function to throw"); +} + +assert( + Object.prototype.hasOwnProperty.call(WritableStream.prototype, "locked"), + "WritableStream.prototype must be initialized when the module is instantiated", +); +assert( + Object.prototype.hasOwnProperty.call(WritableStreamDefaultWriter.prototype, "closed"), + "WritableStreamDefaultWriter.prototype must be initialized when the module is instantiated", +); + +const stream = new WritableStream({ write() {} }); +const writer = stream.getWriter(); + +assert(stream instanceof WritableStream, "stream must use the exported constructor prototype"); +assert(writer instanceof WritableStreamDefaultWriter, "writer must use the exported constructor prototype"); +assert( + Object.getPrototypeOf(writer) === WritableStreamDefaultWriter.prototype, + "vended writer must use WritableStreamDefaultWriter.prototype", +); +assert( + writer.constructor === WritableStreamDefaultWriter, + "vended writer must retain the exported constructor", +); + +const locked = Object.getOwnPropertyDescriptor(WritableStream.prototype, "locked"); +assert(locked.configurable === true, "locked must be configurable"); +assert(locked.enumerable === true, "locked must be enumerable"); + +const closed = Object.getOwnPropertyDescriptor(WritableStreamDefaultWriter.prototype, "closed"); +assert(closed.configurable === true, "closed must be configurable"); +assert(closed.enumerable === true, "closed must be enumerable"); + +const write = Object.getOwnPropertyDescriptor(WritableStreamDefaultWriter.prototype, "write"); +assert(write.writable === true, "write must be writable"); +assert(write.configurable === true, "write must be configurable"); +assert(write.enumerable === true, "write must be enumerable"); + +writer.releaseLock(); + +assertThrowsTypeError( + () => WritableStream({}), + "stream constructor must require new", +); +assertThrowsTypeError( + () => WritableStreamDefaultWriter(stream), + "writer constructor must require new", +); + +assertThrowsTypeError( + () => WritableStreamDefaultWriter.call({}, stream), + "writer constructor must reject a foreign receiver", +); +assertThrowsTypeError( + () => WritableStream.call({}, {}), + "stream constructor must reject a foreign receiver", +); + +function ForeignStream() {} +Reflect.construct(WritableStream, [{}], ForeignStream); +assert( + !Object.prototype.hasOwnProperty.call(ForeignStream.prototype, "locked"), + "derived construction must not modify the new target prototype", +); + +function ForeignWriter() {} +Reflect.construct(WritableStreamDefaultWriter, [stream], ForeignWriter); +for (const name of ["closed", "desiredSize", "ready", "abort", "close", "releaseLock", "write"]) { + assert( + !Object.prototype.hasOwnProperty.call(ForeignWriter.prototype, name), + "derived construction must not install " + name + " on the new target prototype", + ); +} + +for (const name of ["locked", "closed", "desiredSize", "ready", "abort", "close", "releaseLock", "write"]) { + assert( + !Object.prototype.hasOwnProperty.call(Object.prototype, name), + "constructor calls must not install " + name + " on Object.prototype", + ); +} +`) + require.NoError(t, err) +} + +func TestWritableStream(t *testing.T) { + t.Parallel() + if _, err := os.Stat(webPlatformTestSuite); err != nil { //nolint:forbidigo + t.Skipf("If you want to run Streams tests, you need to run the 'checkout.sh` script in the directory to get "+ + "https://github.com/web-platform-tests/wpt at the correct last tested commit (%v)", err) + } + + suites := []string{ + "aborting.any.js", + "bad-strategies.any.js", + "bad-underlying-sinks.any.js", + "close.any.js", + "constructor.any.js", + "count-queuing-strategy.any.js", + "error.any.js", + "floating-point-total-queue-size.any.js", + "general.any.js", + "properties.any.js", + "reentrant-strategy.any.js", + "start.any.js", + "write.any.js", + } + + for _, suite := range suites { + t.Run(suite, func(t *testing.T) { + t.Parallel() + ts := newConfiguredRuntime(t) + gotErr := ts.EventLoop.Start(func() error { + return executeTestScript(ts.VU, webPlatformTestSuite+"/streams/writable-streams", suite) + }) + assert.NoError(t, gotErr) + }) + } +} From befd936692f1d9b11a33eb531dbbd6ab6ea59495 Mon Sep 17 00:00:00 2001 From: Ankur Date: Thu, 16 Jul 2026 19:04:35 +0100 Subject: [PATCH 023/182] Add redirect extra headers (#5631) * Add parse header function This function will be used to parse the incoming headers from extraInfo * Add extraInfo event registration Registers our interest to receive extraInfo data async from chromium. * Add event handling in select * Add initial handler and wire in header parsing * Add extraHeader field in request and response * Add methods on request and response to add... ...extra headers from extraInfo asynchronously. * Add extraInfoTracker This is the key to being able to track all the extraInfo headers that arrive for each of the redirect requests/responses. The initial request will have async extraInfo headers under the same requestID. Subsequent redirects will also have the same requestID. So extraInfoTracker helps to keep track of each redirect's extraInfo header. * Add extraInfoTracker at the network manager level Since it already tracks the requests, this feels like a natural place for the extraInfoTracker to live. * Add tracking of extraInfo headers for the ... ...request and response. This will be matched up with the corresponding request or response. When there's a match the request/response will have its extra headers set. * Add request/response processing for new requests This covers two cases: 1. A non-redirecting request, so only processing of a request. 2. A redirecting request which will process a request and a response. * Add response processing onResponseReceived * Add a cleanup of extra header request tracking * Update request headersSize This now takes into account whether there are extra headers before calculating the headers size. * Update AllHeaders to take into account the... ...extra headers in request. * Update request headersArray to account for... ...extra headers. * Update response to account for extra headers * Refactor existing tests so that we disregard... ...extra headers which may or may not be present. * Add TestPageOnRequestAllHeadersExtraInfo * Add TestPageOnResponseAllHeadersExtraInfo * Add TestPageOnResponseAllHeadersRedirectChain * Remove frameUrl assertion Since the frame URL is updated asynchronously, we cannot rely on a deterministic way of asserting on it. It is being ignored for now. * Update internal/js/modules/k6/browser/tests/page_test.go Co-authored-by: Inanc Gumus * Fix HeaderValues for newline-joined headers HeaderValues looked up the name without lowercasing and split it on a comma, but AllHeaders lowercases keys and joins multiple values with a newline. For Set-Cookie this returned a single newline-glued string, or an empty value when the name was not already lowercase. Lowercase the name and split on the newline to match AllHeaders. * Fix extra-info pairing across redirect chains The tracker paired the i-th ExtraInfo event with the i-th response, but enqueued every response unconditionally. CDP only emits ExtraInfo when hasExtraInfo is set, and may report it erroneously for cached responses (crbug.com/1340398). A redirect chain with a no-extra-info hop therefore slipped the index and applied a later hop's headers to the wrong response. Track only responses that expect ExtraInfo, gating on hasExtraInfo, RedirectHasExtraInfo and servedFromCache, and attach the raw request headers via the response, mirroring Playwright. Defer cleanup until every tracked response is paired so a late ExtraInfo event is not dropped. This drops processRequest, so internal data:/blob: requests no longer leak a tracker entry. * Add wait for raw headers to header accessors allHeaders, headerValue(s) and headersArray returned whatever had arrived, so reading them before the ExtraInfo event (e.g. in a page.on('response') handler) missed raw headers such as Set-Cookie. Make the JS accessors wait for the raw headers to be resolved first, matching Playwright. A request/response resolves its wait once the raw headers are applied, or once it is known none will arrive (no ExtraInfo, served from cache, or the terminal loadingFinished/loadingFailed event), so a reader never blocks past the request's lifetime. * Update browser data metrics to await raw headers headersSize prefers the raw (ExtraInfo) headers when present, but the browser_data_sent and browser_data_received metrics were emitted as soon as the request/response was created, before the raw headers had necessarily arrived. The same workload could therefore report different sizes run-to-run depending on CDP event ordering. Emit both metrics from a goroutine that first waits for the raw headers to resolve, so the size is always computed from a stable source. The samples keep their original wallTime, so only the emission is deferred, not the recorded timestamp. * Update redirect test to assert per-hop cookies The redirect-chain test asserted only X-Step on the final response, which is present in the provisional headers, so it passed even with ExtraInfo pairing disabled and never checked the intermediate hops. Assert a distinct Set-Cookie per hop instead. Set-Cookie arrives only via ExtraInfo, so each hop's cookie proves its events were paired with the correct response, catching both mis-attribution and merging. Also add a unit test covering HeadersArray for multi-valued headers. --------- Co-authored-by: Inanc Gumus --- .../k6/browser/browser/request_mapping.go | 3 + .../k6/browser/browser/response_mapping.go | 4 + .../k6/browser/common/extra_info_tracker.go | 184 +++++++++++++ internal/js/modules/k6/browser/common/http.go | 168 ++++++++++-- .../js/modules/k6/browser/common/http_test.go | 47 ++++ .../k6/browser/common/network_manager.go | 119 ++++++-- .../js/modules/k6/browser/tests/page_test.go | 258 ++++++++++++++++-- 7 files changed, 717 insertions(+), 66 deletions(-) create mode 100644 internal/js/modules/k6/browser/common/extra_info_tracker.go diff --git a/internal/js/modules/k6/browser/browser/request_mapping.go b/internal/js/modules/k6/browser/browser/request_mapping.go index 9c179a385..dd650f8cc 100644 --- a/internal/js/modules/k6/browser/browser/request_mapping.go +++ b/internal/js/modules/k6/browser/browser/request_mapping.go @@ -18,6 +18,7 @@ func mapRequest(vu moduleVU, r *common.Request) mapping { maps := mapping{ "allHeaders": func() *sobek.Promise { return promise(vu, func() (any, error) { + r.WaitForRawHeaders() return r.AllHeaders(), nil }) }, @@ -27,6 +28,7 @@ func mapRequest(vu moduleVU, r *common.Request) mapping { }, "headerValue": func(name string) *sobek.Promise { return promise(vu, func() (any, error) { + r.WaitForRawHeaders() v, ok := r.HeaderValue(name) if !ok { return nil, nil @@ -38,6 +40,7 @@ func mapRequest(vu moduleVU, r *common.Request) mapping { "headers": r.Headers, "headersArray": func() *sobek.Promise { return promise(vu, func() (any, error) { + r.WaitForRawHeaders() return r.HeadersArray(), nil }) }, diff --git a/internal/js/modules/k6/browser/browser/response_mapping.go b/internal/js/modules/k6/browser/browser/response_mapping.go index 404e3a94c..43e0844b3 100644 --- a/internal/js/modules/k6/browser/browser/response_mapping.go +++ b/internal/js/modules/k6/browser/browser/response_mapping.go @@ -20,6 +20,7 @@ func mapResponse(vu moduleVU, r *common.Response) mapping { maps := mapping{ "allHeaders": func() *sobek.Promise { return promise(vu, func() (any, error) { + r.WaitForRawHeaders() return r.AllHeaders(), nil }) }, @@ -47,6 +48,7 @@ func mapResponse(vu moduleVU, r *common.Response) mapping { }, "headerValue": func(name string) *sobek.Promise { return promise(vu, func() (any, error) { + r.WaitForRawHeaders() v, ok := r.HeaderValue(name) if !ok { return nil, nil @@ -56,12 +58,14 @@ func mapResponse(vu moduleVU, r *common.Response) mapping { }, "headerValues": func(name string) *sobek.Promise { return promise(vu, func() (any, error) { + r.WaitForRawHeaders() return r.HeaderValues(name), nil }) }, "headers": r.Headers, "headersArray": func() *sobek.Promise { return promise(vu, func() (any, error) { + r.WaitForRawHeaders() return r.HeadersArray(), nil }) }, diff --git a/internal/js/modules/k6/browser/common/extra_info_tracker.go b/internal/js/modules/k6/browser/common/extra_info_tracker.go new file mode 100644 index 000000000..b445c3a0a --- /dev/null +++ b/internal/js/modules/k6/browser/common/extra_info_tracker.go @@ -0,0 +1,184 @@ +package common + +import ( + "github.com/chromedp/cdproto/network" +) + +// requestInfo aligns CDP ExtraInfo events with their Response objects for a +// single requestId, modelled after Playwright's ResponseExtraInfoTracker. +// +// CDP dispatches events on two independent channels: +// - Channel A: requestWillBeSent, responseReceived, loadingFinished/loadingFailed +// - Channel B: requestWillBeSentExtraInfo, responseReceivedExtraInfo +// +// They are not synchronised, so events arrive in any order between the +// channels, but within each channel they arrive in order for a given +// requestId. A single requestId can produce multiple request/response pairs +// (a redirect chain reuses the requestId), so we pair by index: the i-th +// tracked response pairs with the i-th request/response ExtraInfo event. +// +// Only responses that expect ExtraInfo are tracked (see processResponse). +// Because the ExtraInfo events are likewise only emitted for those responses, +// the indexes stay aligned even when some hops (e.g. cached redirects) carry no +// ExtraInfo. The raw request headers are attached to the response's Request, +// matching Playwright. +type requestInfo struct { + // Indexed queues of parsed raw headers. Slots are set to nil after + // pairing to avoid applying the same headers twice. + requestExtraHeaders []map[string][]string + responseExtraHeaders []map[string][]string + + // Responses that expect ExtraInfo, in arrival order. + responses []*Response + + loadingFinished bool + loadingFailed bool + servedFromCache bool +} + +// extraInfoTracker pairs requestWillBeSentExtraInfo / responseReceivedExtraInfo +// events with their corresponding Response (and its Request) using index-based +// matching (modelled after Playwright's ResponseExtraInfoTracker). +type extraInfoTracker struct { + requests map[network.RequestID]*requestInfo +} + +func newExtraInfoTracker() *extraInfoTracker { + return &extraInfoTracker{ + requests: make(map[network.RequestID]*requestInfo), + } +} + +// getOrCreate returns the requestInfo for the given requestId, creating one if +// it doesn't exist yet. +func (t *extraInfoTracker) getOrCreate(reqID network.RequestID) *requestInfo { + info, ok := t.requests[reqID] + if !ok { + info = &requestInfo{} + t.requests[reqID] = info + } + return info +} + +// requestWillBeSentExtraInfo records parsed raw request headers and tries to +// pair them with an already-registered response at the same index. +func (t *extraInfoTracker) requestWillBeSentExtraInfo(reqID network.RequestID, headers map[string][]string) { + info := t.getOrCreate(reqID) + info.requestExtraHeaders = append(info.requestExtraHeaders, headers) + t.patchHeaders(info, len(info.requestExtraHeaders)-1) + t.checkFinished(reqID, info) +} + +// responseReceivedExtraInfo records parsed raw response headers and tries to +// pair them with an already-registered response at the same index. +func (t *extraInfoTracker) responseReceivedExtraInfo(reqID network.RequestID, headers map[string][]string) { + info := t.getOrCreate(reqID) + info.responseExtraHeaders = append(info.responseExtraHeaders, headers) + t.patchHeaders(info, len(info.responseExtraHeaders)-1) + t.checkFinished(reqID, info) +} + +// requestServedFromCache marks the requestId as served from cache. Chrome can +// report hasExtraInfo=true for cached responses but never emit the matching +// ExtraInfo event (crbug.com/1340398), so such responses must not be tracked, +// otherwise the index would slip and later headers would land on the wrong +// response. +func (t *extraInfoTracker) requestServedFromCache(reqID network.RequestID) { + info := t.getOrCreate(reqID) + info.servedFromCache = true +} + +// processResponse registers a Response that expects ExtraInfo. Responses that +// do not expect it (hasExtraInfo=false, or served from cache) are not tracked, +// so they keep their provisional headers as the raw ones. +func (t *extraInfoTracker) processResponse(reqID network.RequestID, resp *Response, hasExtraInfo bool) { + info, ok := t.requests[reqID] + if !hasExtraInfo || (ok && info.servedFromCache) { + // No raw headers will arrive, so the provisional headers are final. + // Unblock any readers waiting for the raw headers. + resp.resolveRawHeaders() + resp.request.resolveRawHeaders() + return + } + if !ok { + info = t.getOrCreate(reqID) + } + info.responses = append(info.responses, resp) + t.patchHeaders(info, len(info.responses)-1) +} + +// patchHeaders attaches the raw request and response headers at the given index +// when both the response and the corresponding ExtraInfo event are available. +// Consumed ExtraInfo slots are set to nil to avoid applying them twice. +func (t *extraInfoTracker) patchHeaders(info *requestInfo, index int) { + if index < 0 || index >= len(info.responses) { + return + } + resp := info.responses[index] + if resp == nil { + return + } + if index < len(info.requestExtraHeaders) { + if extra := info.requestExtraHeaders[index]; extra != nil { + resp.request.addExtraHeaders(extra) + info.requestExtraHeaders[index] = nil + } + } + if index < len(info.responseExtraHeaders) { + if extra := info.responseExtraHeaders[index]; extra != nil { + resp.addExtraHeaders(extra) + info.responseExtraHeaders[index] = nil + } + } +} + +// loadingFinished records that loading finished and stops tracking once every +// tracked response has been paired with its ExtraInfo event. +func (t *extraInfoTracker) loadingFinished(reqID network.RequestID) { + info, ok := t.requests[reqID] + if !ok { + return + } + info.loadingFinished = true + t.resolvePending(info) + t.checkFinished(reqID, info) +} + +// loadingFailed records that loading failed and stops tracking once every +// tracked response has been paired with its ExtraInfo event. +func (t *extraInfoTracker) loadingFailed(reqID network.RequestID) { + info, ok := t.requests[reqID] + if !ok { + return + } + info.loadingFailed = true + t.resolvePending(info) + t.checkFinished(reqID, info) +} + +// resolvePending unblocks readers waiting on the raw headers of any tracked +// response (and its request) whose ExtraInfo never arrived. It is a backstop +// run on the terminal event so a reader never waits forever; the entry itself +// is kept (see checkFinished) so a late ExtraInfo event can still be applied. +func (t *extraInfoTracker) resolvePending(info *requestInfo) { + for _, resp := range info.responses { + if resp == nil { + continue + } + resp.resolveRawHeaders() + resp.request.resolveRawHeaders() + } +} + +// checkFinished removes the tracking entry once loading has finished/failed and +// every tracked response has its response ExtraInfo. Deletion is deferred until +// then so a late-arriving ExtraInfo event (CDP may emit it after +// loadingFinished) can still be paired instead of being dropped. +func (t *extraInfoTracker) checkFinished(reqID network.RequestID, info *requestInfo) { + if !info.loadingFinished && !info.loadingFailed { + return + } + if len(info.responses) <= len(info.responseExtraHeaders) { + delete(t.requests, reqID) + } +} diff --git a/internal/js/modules/k6/browser/common/http.go b/internal/js/modules/k6/browser/common/http.go index 201ad1c74..756a08e6f 100644 --- a/internal/js/modules/k6/browser/common/http.go +++ b/internal/js/modules/k6/browser/common/http.go @@ -70,16 +70,23 @@ type RequestFailure struct { // Request represents a browser HTTP request. type Request struct { - ctx context.Context - frame *Frame - responseMu sync.RWMutex - response *Response - redirectChain []*Request - requestID network.RequestID - documentID string - url *url.URL - method string - headers map[string][]string + ctx context.Context + frame *Frame + responseMu sync.RWMutex + response *Response + redirectChain []*Request + requestID network.RequestID + documentID string + url *url.URL + method string + headers map[string][]string + extraHeaders map[string][]string + extraHeadersMu sync.RWMutex + // rawHeadersCh is closed once the raw (ExtraInfo) headers have been + // resolved: either applied, or known not to arrive. Readers that need the + // raw headers wait on it; see waitForRawHeaders. + rawHeadersCh chan struct{} + rawHeadersOnce sync.Once // For now we're only going to work with the 0th entry of postDataEntries. // We've not been able to reproduce a situation where more than one entry // occupies the slice. Once we have a better idea of when more than one @@ -169,6 +176,7 @@ func NewRequest(ctx context.Context, logger *log.Logger, rp NewRequestParams) (* documentID: documentID.String(), headers: make(map[string][]string, len(ev.Request.Headers)), ctx: ctx, + rawHeadersCh: make(chan struct{}), } for n, v := range ev.Request.Headers { if s, ok := v.(string); ok { @@ -214,6 +222,29 @@ func validateResourceType(logger *log.Logger, t string) string { return t } +func (r *Request) addExtraHeaders(extra map[string][]string) { + r.extraHeadersMu.Lock() + r.extraHeaders = extra + r.extraHeadersMu.Unlock() + r.resolveRawHeaders() +} + +// resolveRawHeaders unblocks readers waiting for the raw (ExtraInfo) headers. +// It is called once the raw headers have been applied, or once it is known +// that none will arrive (so the provisional headers are the final ones). +func (r *Request) resolveRawHeaders() { + r.rawHeadersOnce.Do(func() { close(r.rawHeadersCh) }) +} + +// WaitForRawHeaders blocks until the raw headers are resolved or the request +// context is done, whichever comes first. +func (r *Request) WaitForRawHeaders() { + select { + case <-r.rawHeadersCh: + case <-r.ctx.Done(): + } +} + func (r *Request) getFrame() *Frame { return r.frame } @@ -231,9 +262,21 @@ func (r *Request) headersSize() int64 { size += len(r.method) size += len(r.url.Path) size += 8 // httpVersion - for n, v := range r.headers { - size += len(n) + len(strings.Join(v, "")) + 4 // 4 = ': ' + '\r\n' + r.extraHeadersMu.RLock() + if len(r.extraHeaders) != 0 { + for name, values := range r.extraHeaders { + for _, value := range values { + size += len(name) + len(value) + 4 // 4 = ': ' + '\r\n' + } + } + } else { + for name, values := range r.headers { + for _, value := range values { + size += len(name) + len(value) + 4 // 4 = ': ' + '\r\n' + } + } } + r.extraHeadersMu.RUnlock() return int64(size) } @@ -255,11 +298,18 @@ func (r *Request) setLoadedFromCache(fromMemoryCache bool) { // AllHeaders returns all the request headers. func (r *Request) AllHeaders() map[string]string { - // TODO: fix this data to include "ExtraInfo" header data headers := make(map[string]string) - for n, v := range r.headers { - headers[strings.ToLower(n)] = strings.Join(v, ",") + r.extraHeadersMu.RLock() + if len(r.extraHeaders) != 0 { + for name, values := range r.extraHeaders { + headers[strings.ToLower(name)] = strings.Join(values, "\n") + } + } else { + for name, values := range r.headers { + headers[strings.ToLower(name)] = strings.Join(values, "\n") + } } + r.extraHeadersMu.RUnlock() return headers } @@ -287,11 +337,17 @@ func (r *Request) Headers() map[string]string { // HeadersArray returns the request headers as an array of objects. func (r *Request) HeadersArray() []HTTPHeader { headers := make([]HTTPHeader, 0) - for n, vals := range r.headers { - for _, v := range vals { - headers = append(headers, HTTPHeader{Name: n, Value: v}) + r.extraHeadersMu.RLock() + source := r.headers + if len(r.extraHeaders) != 0 { + source = r.extraHeaders + } + for name, values := range source { + for _, v := range values { + headers = append(headers, HTTPHeader{Name: name, Value: v}) } } + r.extraHeadersMu.RUnlock() return headers } @@ -428,6 +484,10 @@ type Response struct { bodyMu sync.RWMutex body []byte headers map[string][]string + extraHeaders map[string][]string + extraHeadersMu sync.RWMutex + rawHeadersCh chan struct{} + rawHeadersOnce sync.Once fromDiskCache bool fromServiceWorker bool fromPrefetchCache bool @@ -459,6 +519,7 @@ func NewHTTPResponse( statusText: resp.StatusText, body: nil, headers: make(map[string][]string, len(resp.Headers)), + rawHeadersCh: make(chan struct{}), fromDiskCache: resp.FromDiskCache, fromServiceWorker: resp.FromServiceWorker, fromPrefetchCache: resp.FromPrefetchCache, @@ -490,6 +551,29 @@ func NewHTTPResponse( return &r } +func (r *Response) addExtraHeaders(extra map[string][]string) { + r.extraHeadersMu.Lock() + r.extraHeaders = extra + r.extraHeadersMu.Unlock() + r.resolveRawHeaders() +} + +// resolveRawHeaders unblocks readers waiting for the raw (ExtraInfo) headers. +// It is called once the raw headers have been applied, or once it is known +// that none will arrive (so the provisional headers are the final ones). +func (r *Response) resolveRawHeaders() { + r.rawHeadersOnce.Do(func() { close(r.rawHeadersCh) }) +} + +// WaitForRawHeaders blocks until the raw headers are resolved or the response +// context is done, whichever comes first. +func (r *Response) WaitForRawHeaders() { + select { + case <-r.rawHeadersCh: + case <-r.ctx.Done(): + } +} + func (r *Response) fetchBody() error { cached := func() bool { r.bodyMu.RLock() @@ -537,20 +621,39 @@ func (r *Response) headersSize() int64 { size += 8 // httpVersion size += 3 // statusCode size += len(r.statusText) - for n, v := range r.headers { - size += len(n) + len(strings.Join(v, "")) + 4 // 4 = ': ' + '\r\n' + r.extraHeadersMu.RLock() + if len(r.extraHeaders) != 0 { + for name, values := range r.extraHeaders { + for _, value := range values { + size += len(name) + len(value) + 4 // 4 = ': ' + '\r\n' + } + } + } else { + for name, values := range r.headers { + for _, value := range values { + size += len(name) + len(value) + 4 // 4 = ': ' + '\r\n' + } + } } + r.extraHeadersMu.RUnlock() size += 2 // '\r\n' return int64(size) } // AllHeaders returns all the response headers. func (r *Response) AllHeaders() map[string]string { - // TODO: fix this data to include "ExtraInfo" header data headers := make(map[string]string) - for n, v := range r.headers { - headers[strings.ToLower(n)] = strings.Join(v, ",") + r.extraHeadersMu.RLock() + if len(r.extraHeaders) != 0 { + for name, values := range r.extraHeaders { + headers[strings.ToLower(name)] = strings.Join(values, "\n") + } + } else { + for name, values := range r.headers { + headers[strings.ToLower(name)] = strings.Join(values, "\n") + } } + r.extraHeadersMu.RUnlock() return headers } @@ -600,10 +703,13 @@ func (r *Response) HeaderValue(name string) (string, bool) { return v, ok } -// HeaderValues returns the values of the given header. +// HeaderValues returns the values of the given header. The header name is +// matched case-insensitively, and headers that carry multiple values (such as +// Set-Cookie) are returned as separate entries. AllHeaders joins multiple +// values with a newline, so we split on the same separator here. func (r *Response) HeaderValues(name string) []string { headers := r.AllHeaders() - return strings.Split(headers[name], ",") + return strings.Split(headers[strings.ToLower(name)], "\n") } // FromCache returns whether this response was served from disk cache. @@ -633,11 +739,17 @@ func (r *Response) Headers() map[string]string { // HeadersArray returns the response headers as an array of objects. func (r *Response) HeadersArray() []HTTPHeader { headers := make([]HTTPHeader, 0) - for n, vals := range r.headers { - for _, v := range vals { - headers = append(headers, HTTPHeader{Name: n, Value: v}) + r.extraHeadersMu.RLock() + source := r.headers + if len(r.extraHeaders) != 0 { + source = r.extraHeaders + } + for name, values := range source { + for _, v := range values { + headers = append(headers, HTTPHeader{Name: name, Value: v}) } } + r.extraHeadersMu.RUnlock() return headers } diff --git a/internal/js/modules/k6/browser/common/http_test.go b/internal/js/modules/k6/browser/common/http_test.go index 21fd6828a..1c52d79da 100644 --- a/internal/js/modules/k6/browser/common/http_test.go +++ b/internal/js/modules/k6/browser/common/http_test.go @@ -127,6 +127,53 @@ func TestResponse(t *testing.T) { }) } +func TestResponseHeaderValuesExtraInfo(t *testing.T) { + t.Parallel() + + ts := cdp.MonotonicTime(time.Now()) + vu := k6test.NewVU(t) + vu.ActivateVU() + req := &Request{ + offset: 0, + } + res := NewHTTPResponse(vu.Context(), req, &network.Response{ + URL: "https://test/post", + Headers: network.Headers(map[string]any{"content-type": "text/plain"}), + }, &ts) + + // Simulate the raw wire headers arriving via responseReceivedExtraInfo, + // where a multi-valued header (Set-Cookie) is carried as separate values. + res.addExtraHeaders(map[string][]string{ + "Set-Cookie": {"a=1; Path=/", "b=2; Path=/"}, + }) + + t.Run("AllHeaders()_joins_multivalue_with_newline", func(t *testing.T) { + t.Parallel() + assert.Equal(t, "a=1; Path=/\nb=2; Path=/", res.AllHeaders()["set-cookie"]) + }) + + t.Run("HeaderValues()_splits_multivalue", func(t *testing.T) { + t.Parallel() + assert.Equal(t, []string{"a=1; Path=/", "b=2; Path=/"}, res.HeaderValues("set-cookie")) + }) + + t.Run("HeaderValues()_is_case_insensitive", func(t *testing.T) { + t.Parallel() + assert.Equal(t, []string{"a=1; Path=/", "b=2; Path=/"}, res.HeaderValues("Set-Cookie")) + }) + + t.Run("HeadersArray()_keeps_values_separate", func(t *testing.T) { + t.Parallel() + var cookies []string + for _, h := range res.HeadersArray() { + if strings.EqualFold(h.Name, "Set-Cookie") { + cookies = append(cookies, h.Value) + } + } + assert.ElementsMatch(t, []string{"a=1; Path=/", "b=2; Path=/"}, cookies) + }) +} + func TestValidateResourceType(t *testing.T) { t.Parallel() diff --git a/internal/js/modules/k6/browser/common/network_manager.go b/internal/js/modules/k6/browser/common/network_manager.go index 147589eac..40fac6c72 100644 --- a/internal/js/modules/k6/browser/common/network_manager.go +++ b/internal/js/modules/k6/browser/common/network_manager.go @@ -80,6 +80,7 @@ type NetworkManager struct { eventsWillBeSentMu sync.RWMutex reqIDToRequestPausedEvent map[network.RequestID]*fetch.EventRequestPaused eventsPausedMu sync.RWMutex + extraInfoTracker *extraInfoTracker attemptedAuth map[fetch.RequestID]bool @@ -125,6 +126,7 @@ func NewNetworkManager( reqIDToRequest: make(map[network.RequestID]*Request), reqIDToRequestWillBeSentEvent: make(map[network.RequestID]*network.EventRequestWillBeSent), reqIDToRequestPausedEvent: make(map[network.RequestID]*fetch.EventRequestPaused), + extraInfoTracker: newExtraInfoTracker(), attemptedAuth: make(map[fetch.RequestID]bool), extraHTTPHeaders: make(map[string]string), networkProfile: NewNetworkProfile(), @@ -332,15 +334,22 @@ func handleURLTag(mi eventInterceptor, url string, method string, tags *k6metric } func (m *NetworkManager) handleRequestRedirect( - req *Request, redirectResponse *network.Response, timestamp *cdp.MonotonicTime, + req *Request, redirectResponse *network.Response, hasExtraInfo bool, timestamp *cdp.MonotonicTime, ) { resp := NewHTTPResponse(m.ctx, req, redirectResponse, timestamp) + m.extraInfoTracker.processResponse(req.requestID, resp, hasExtraInfo) req.responseMu.Lock() req.response = resp req.responseMu.Unlock() req.redirectChain = append(req.redirectChain, req) - m.emitResponseMetrics(resp, req) + // Emit the response metrics once the raw headers are resolved, off the + // event goroutine so the wait does not block the goroutine that resolves + // them (the redirect's ExtraInfo may still be in flight here). + m.wg.Go(func() { + resp.WaitForRawHeaders() + m.emitResponseMetrics(resp, req) + }) m.deleteRequestByID(req.requestID) /* @@ -377,8 +386,10 @@ func (m *NetworkManager) initEvents() { cdproto.EventNetworkLoadingFailed, cdproto.EventNetworkLoadingFinished, cdproto.EventNetworkRequestWillBeSent, + cdproto.EventNetworkRequestWillBeSentExtraInfo, cdproto.EventNetworkRequestServedFromCache, cdproto.EventNetworkResponseReceived, + cdproto.EventNetworkResponseReceivedExtraInfo, cdproto.EventFetchRequestPaused, cdproto.EventFetchAuthRequired, }, chHandler) @@ -410,10 +421,14 @@ func (m *NetworkManager) handleEvents(in <-chan Event) bool { m.onLoadingFinished(ev) case *network.EventRequestWillBeSent: m.onRequestWillBeSent(ev) + case *network.EventRequestWillBeSentExtraInfo: + m.onRequestWillBeSentExtraInfo(ev) case *network.EventRequestServedFromCache: m.onRequestServedFromCache(ev) case *network.EventResponseReceived: m.onResponseReceived(ev) + case *network.EventResponseReceivedExtraInfo: + m.onResponseReceivedExtraInfo(ev) case *fetch.EventRequestPaused: m.onRequestPaused(ev) case *fetch.EventAuthRequired: @@ -434,6 +449,8 @@ func (m *NetworkManager) onLoadingFailed(event *network.EventLoadingFailed) { req.responseEndTiming = float64(event.Timestamp.Time().Unix()-req.timestamp.Unix()) * 1000 m.eventInterceptor.onRequestFailed(req) m.deleteRequestByID(event.RequestID) + m.extraInfoTracker.loadingFailed(event.RequestID) + req.resolveRawHeaders() m.frameManager.requestFailed(req, event.Canceled) } @@ -446,6 +463,8 @@ func (m *NetworkManager) onLoadingFinished(event *network.EventLoadingFinished) req.responseEndTiming = float64(event.Timestamp.Time().Unix()-req.timestamp.Unix()) * 1000 m.deleteRequestByID(event.RequestID) + m.extraInfoTracker.loadingFinished(event.RequestID) + req.resolveRawHeaders() m.frameManager.requestFinished(req) m.eventInterceptor.onRequestFinished(req) @@ -453,26 +472,21 @@ func (m *NetworkManager) onLoadingFinished(event *network.EventLoadingFinished) if isInternalURL(req.url) { return } - emitResponseMetrics := func() { + // Emit the response metrics in a separate goroutine, once the raw headers + // are resolved, so the reported size is computed from a stable source. + // This must not run on the NetworkManager event goroutine: waiting for the + // raw headers there would block the goroutine that resolves them. Spawning + // a goroutine is also required for intercepted requests, so that CDP + // requestPaused messages can still be processed while a redirected main + // page request waits for its subrequest to finish loading. + m.wg.Go(func() { req.responseMu.RLock() - m.emitResponseMetrics(req.response, req) + resp := req.response req.responseMu.RUnlock() - } - if !req.allowInterception { - emitResponseMetrics() - return - } - // When request interception is enabled, we need to process requestPaused messages - // from CDP in order to get the response for the request. However, we can't process - // them until the request is unblocked. Since we're blocking the NetworkManager - // goroutine here, we need to spawn a new goroutine to allow the requestPaused - // messages to be processed by the NetworkManager. - // - // This happens when the main page request redirects before it finishes loading. - // So the new redirect request will be blocked until the main page finishes loading. - // The main page will wait forever since its subrequest is blocked. - m.wg.Go(func() { - emitResponseMetrics() + if resp != nil { + resp.WaitForRawHeaders() + } + m.emitResponseMetrics(resp, req) }) } @@ -521,7 +535,7 @@ func (m *NetworkManager) onRequest(event *network.EventRequestWillBeSent, if event.RedirectResponse != nil { req, ok := m.requestFromID(event.RequestID) if ok { - m.handleRequestRedirect(req, event.RedirectResponse, event.Timestamp) + m.handleRequestRedirect(req, event.RedirectResponse, event.RedirectHasExtraInfo, event.Timestamp) redirectChain = req.redirectChain } } else { @@ -576,7 +590,13 @@ func (m *NetworkManager) onRequest(event *network.EventRequestWillBeSent, m.reqsMu.Lock() m.reqIDToRequest[event.RequestID] = req m.reqsMu.Unlock() - m.emitRequestMetrics(req) + // Emit the request metrics once the raw headers are resolved, off the + // event goroutine so the wait does not block the goroutine that resolves + // them. The metric uses req.wallTime, so the deferral does not skew it. + m.wg.Go(func() { + req.WaitForRawHeaders() + m.emitRequestMetrics(req) + }) m.frameManager.requestStarted(req) m.eventInterceptor.onRequest(req) @@ -607,6 +627,14 @@ func (m *NetworkManager) onRequestWillBeSent(event *network.EventRequestWillBeSe } } +func (m *NetworkManager) onRequestWillBeSentExtraInfo(event *network.EventRequestWillBeSentExtraInfo) { + extra := parseExtraHeaders(event.Headers) + if len(extra) == 0 { + return + } + m.extraInfoTracker.requestWillBeSentExtraInfo(event.RequestID, extra) +} + // onRequestPaused can send one of these two CDP events: // - Fetch.failRequest if the URL is part of the blocked hosts or IPs // - Fetch.continueRequest if the request is not blocked and no route is configured @@ -753,6 +781,7 @@ func (m *NetworkManager) onAuthRequired(event *fetch.EventAuthRequired) { } func (m *NetworkManager) onRequestServedFromCache(event *network.EventRequestServedFromCache) { + m.extraInfoTracker.requestServedFromCache(event.RequestID) req, ok := m.requestFromID(event.RequestID) if ok { req.setLoadedFromCache(true) @@ -766,6 +795,7 @@ func (m *NetworkManager) onResponseReceived(event *network.EventResponseReceived return } resp := NewHTTPResponse(m.ctx, req, event.Response, event.Timestamp) + m.extraInfoTracker.processResponse(event.RequestID, resp, event.HasExtraInfo) req.responseMu.Lock() req.response = resp req.responseMu.Unlock() @@ -775,6 +805,14 @@ func (m *NetworkManager) onResponseReceived(event *network.EventResponseReceived m.eventInterceptor.onResponse(resp) } +func (m *NetworkManager) onResponseReceivedExtraInfo(event *network.EventResponseReceivedExtraInfo) { + extra := parseExtraHeaders(event.Headers) + if len(extra) == 0 { + return + } + m.extraInfoTracker.responseReceivedExtraInfo(event.RequestID, extra) +} + func (m *NetworkManager) requestFromID(reqID network.RequestID) (*Request, bool) { m.reqsMu.RLock() defer m.reqsMu.RUnlock() @@ -1066,3 +1104,40 @@ func (m *NetworkManager) SetCacheEnabled(enabled bool) { func (m *NetworkManager) wait() { m.wg.Wait() } + +func parseExtraHeaders(headers network.Headers) map[string][]string { + if len(headers) == 0 { + return nil + } + parsed := make(map[string][]string, len(headers)) + for name, value := range headers { + switch v := value.(type) { + case string: + parsed[name] = splitHeaderValues(v) + case []string: + parsed[name] = append([]string{}, v...) + case []any: + values := make([]string, 0, len(v)) + for _, item := range v { + if s, ok := item.(string); ok { + values = append(values, s) + } + } + if len(values) > 0 { + parsed[name] = values + } + } + } + if len(parsed) == 0 { + return nil + } + return parsed +} + +// CDP concatenates duplicate header values with newlines; split to match Playwright. +func splitHeaderValues(value string) []string { + if strings.Contains(value, "\n") { + return strings.Split(value, "\n") + } + return []string{value} +} diff --git a/internal/js/modules/k6/browser/tests/page_test.go b/internal/js/modules/k6/browser/tests/page_test.go index 83e39e870..569d31b95 100644 --- a/internal/js/modules/k6/browser/tests/page_test.go +++ b/internal/js/modules/k6/browser/tests/page_test.go @@ -2344,7 +2344,8 @@ func TestPageOnRequest(t *testing.T) { page.on('request', async (request) => { returnValue.push({ allHeaders: await request.allHeaders(), - frameUrl: request.frame().url(), + // Ignoring frameUrl as it is racey due to the async nature of how it is set. + // frameUrl: request.frame().url(), acceptLanguageHeader: await request.headerValue('Accept-Language'), headers: request.headers(), headersArray: await request.headersArray(), @@ -2384,7 +2385,6 @@ func TestPageOnRequest(t *testing.T) { "upgrade-insecure-requests": "1", "user-agent": "some-user-agent", }, - FrameURL: "about:blank", AcceptLanguageHeader: "en-US", Headers: map[string]string{ "Accept-Language": "en-US", @@ -2413,7 +2413,6 @@ func TestPageOnRequest(t *testing.T) { "referer": tb.url("/home"), "user-agent": "some-user-agent", }, - FrameURL: tb.url("/home"), AcceptLanguageHeader: "en-US", Headers: map[string]string{ "Accept-Language": "en-US", @@ -2443,7 +2442,6 @@ func TestPageOnRequest(t *testing.T) { "referer": tb.url("/home"), "user-agent": "some-user-agent", }, - FrameURL: tb.url("/home"), AcceptLanguageHeader: "en-US", Headers: map[string]string{ "Accept-Language": "en-US", @@ -2474,7 +2472,6 @@ func TestPageOnRequest(t *testing.T) { "referer": tb.url("/home"), "user-agent": "some-user-agent", }, - FrameURL: tb.url("/home"), AcceptLanguageHeader: "en-US", Headers: map[string]string{ "Accept-Language": "en-US", @@ -2500,22 +2497,43 @@ func TestPageOnRequest(t *testing.T) { } // Compare each request one by one for better test failure visibility + // We only want to compare against the expected values. The actual values + // may contain extra headers that are not present in the expected values. + // Extra headers are racey and can be present or may not be present when + // the page.on('request') handler is called. for _, req := range requests { i := slices.IndexFunc(expected, func(r request) bool { return req.URL == r.URL }) assert.NotEqual(t, -1, i, "failed to find expected request with URL %s", req.URL) - sortByName := func(m1, m2 map[string]string) int { - return strings.Compare(m1["name"], m2["name"]) + expectedHeadersArray := make(map[string]string) + for _, header := range expected[i].HeadersArray { + expectedHeadersArray[header["name"]] = header["value"] } - slices.SortFunc(req.HeadersArray, sortByName) - slices.SortFunc(expected[i].HeadersArray, sortByName) - assert.Equal(t, expected[i], req) + for name, value := range expected[i].AllHeaders { + actualValue, ok := req.AllHeaders[name] + require.True(t, ok, "missing allHeaders[%s] for %s", name, req.URL) + require.Equal(t, value, actualValue, "allHeaders[%s] mismatch for %s", name, req.URL) + } + require.Equal(t, expected[i].AcceptLanguageHeader, req.AcceptLanguageHeader, i) + require.Equal(t, expected[i].Headers, req.Headers, i) + for _, header := range req.HeadersArray { + if expectedValue, ok := expectedHeadersArray[header["name"]]; ok { + require.Equal(t, expectedValue, header["value"], "headersArray[%s] mismatch for %s", header["name"], req.URL) + delete(expectedHeadersArray, header["name"]) + } + } + require.Empty(t, expectedHeadersArray, "missing headersArray entries for %s", req.URL) + require.Equal(t, expected[i].IsNavigationRequest, req.IsNavigationRequest, i) + require.Equal(t, expected[i].Method, req.Method, i) + require.Equal(t, expected[i].PostData, req.PostData, i) + require.Equal(t, expected[i].PostDataBuffer, req.PostDataBuffer, i) + require.Equal(t, expected[i].ResourceType, req.ResourceType, i) + require.Equal(t, expected[i].URL, req.URL, i) } } type request struct { AllHeaders map[string]string `json:"allHeaders"` - FrameURL string `json:"frameUrl"` AcceptLanguageHeader string `json:"acceptLanguageHeader"` Headers map[string]string `json:"headers"` HeadersArray []map[string]string `json:"headersArray"` @@ -2814,16 +2832,224 @@ func TestPageOnResponse(t *testing.T) { } // Compare each response one by one for better test failure visibility + // We only want to compare against the expected values. The actual values + // may contain extra headers that are not present in the expected values. + // Extra headers are racey and can be present or may not be present when + // the page.on('response') handler is called. for _, resp := range responses { i := slices.IndexFunc(expected, func(r response) bool { return resp.URL == r.URL }) assert.NotEqual(t, -1, i, "failed to find expected request with URL %s", resp.URL) - sortByName := func(m1, m2 map[string]string) int { - return strings.Compare(m1["name"], m2["name"]) + expectedHeadersArray := make(map[string]string) + for _, header := range expected[i].HeadersArray { + expectedHeadersArray[header["name"]] = header["value"] + } + for name, value := range expected[i].AllHeaders { + actualValue, ok := resp.AllHeaders[name] + require.True(t, ok, "missing allHeaders[%s] for %s", name, resp.URL) + require.Equal(t, value, actualValue, "allHeaders[%s] mismatch for %s", name, resp.URL) + } + require.Equal(t, expected[i].Body, resp.Body, i) + require.Equal(t, expected[i].FrameURL, resp.FrameURL, i) + require.Equal(t, expected[i].AcceptLanguageHeader, resp.AcceptLanguageHeader, i) + require.Equal(t, expected[i].AcceptLanguageHeaders, resp.AcceptLanguageHeaders, i) + require.Equal(t, expected[i].Headers, resp.Headers, i) + for _, header := range resp.HeadersArray { + if expectedValue, ok := expectedHeadersArray[header["name"]]; ok { + require.Equal(t, expectedValue, header["value"], "headersArray[%s] mismatch for %s", header["name"], resp.URL) + delete(expectedHeadersArray, header["name"]) + } + } + require.Empty(t, expectedHeadersArray, "missing headersArray entries for %s", resp.URL) + require.Equal(t, expected[i].JSON, resp.JSON, i) + require.Equal(t, expected[i].OK, resp.OK, i) + require.Equal(t, expected[i].RequestURL, resp.RequestURL, i) + require.Equal(t, expected[i].SecurityDetails, resp.SecurityDetails, i) + require.Equal(t, expected[i].ServerAddr, resp.ServerAddr, i) + require.Equal(t, expected[i].Status, resp.Status, i) + require.Equal(t, expected[i].StatusText, resp.StatusText, i) + require.Equal(t, expected[i].URL, resp.URL, i) + require.Equal(t, expected[i].Text, resp.Text, i) + } +} + +func TestPageOnRequestAllHeadersExtraInfo(t *testing.T) { + t.Parallel() + + tb := newTestBrowser(t, withHTTPServer()) + tb.withHandler("/set-cookie", func(w http.ResponseWriter, _ *http.Request) { + w.Header().Add("Set-Cookie", "test_cookie_name=test_cookie_value; Path=/") + _, err := fmt.Fprint(w, "ok") + require.NoError(t, err) + }) + + p := tb.NewPage(nil) + + opts := &common.FrameGotoOptions{ + WaitUntil: common.LifecycleEventNetworkIdle, + Timeout: common.DefaultTimeout, + } + // This will tell the browser to store the cookie + _, err := p.Goto(tb.url("/set-cookie"), opts) + require.NoError(t, err) + + // The cookie in the browser store is sent as a header in the request + gotoPage := func() error { + _, err := p.Goto(tb.url("/set-cookie"), opts) + return err + } + + // We are only guaranteed to have the extra headers when the requestfinished + // event is fired. Trying to retrieve the extra headers on anyother event will + // be racey and may not be present. + var ev common.PageEvent + waitForRequestFinished := func() error { + var err error + ev, err = p.WaitForEvent( + common.PageEventRequestFinished, + &common.PageWaitForEventOptions{Timeout: p.Timeout()}, + func(pe common.PageEvent) (bool, error) { + return strings.Contains(pe.Request.URL(), "/set-cookie"), nil + }, + ) + return err + } + + err = tb.run(tb.context(), gotoPage, waitForRequestFinished) + require.NoError(t, err) + require.NotNil(t, ev.Request) + + assert.Contains(t, ev.Request.AllHeaders()["cookie"], "test_cookie_name=test_cookie_value") +} + +func TestPageOnResponseAllHeadersExtraInfo(t *testing.T) { + t.Parallel() + + tb := newTestBrowser(t, withHTTPServer()) + tb.withHandler("/set-cookie", func(w http.ResponseWriter, _ *http.Request) { + w.Header().Add("Set-Cookie", "test_cookie_name=test_cookie_value; Path=/") + _, err := fmt.Fprint(w, "ok") + require.NoError(t, err) + }) + + p := tb.NewPage(nil) + + opts := &common.FrameGotoOptions{ + WaitUntil: common.LifecycleEventNetworkIdle, + Timeout: common.DefaultTimeout, + } + gotoPage := func() error { + _, err := p.Goto(tb.url("/set-cookie"), opts) + return err + } + + // We are only guaranteed to have the extra headers when the requestfinished + // event is fired. Trying to retrieve the extra headers on anyother event will + // be racey and may not be present. + var ev common.PageEvent + waitForRequestFinished := func() error { + var err error + ev, err = p.WaitForEvent( + common.PageEventRequestFinished, + &common.PageWaitForEventOptions{Timeout: p.Timeout()}, + func(pe common.PageEvent) (bool, error) { + return strings.Contains(pe.Request.URL(), "/set-cookie"), nil + }, + ) + return err + } + + err := tb.run(tb.context(), gotoPage, waitForRequestFinished) + require.NoError(t, err) + require.NotNil(t, ev.Request) + + assert.Contains(t, ev.Request.Response().AllHeaders()["set-cookie"], "test_cookie_name=test_cookie_value") +} + +// TestPageOnResponseAllHeadersRedirectChain verifies that each response in a +// redirect chain receives its own distinct extra headers from +// responseReceivedExtraInfo, rather than merging them all together. +func TestPageOnResponseAllHeadersRedirectChain(t *testing.T) { + t.Parallel() + + tb := newTestBrowser(t, withHTTPServer()) + + // A 3-step redirect chain where each hop sets a distinct Set-Cookie. + // Set-Cookie is delivered only via responseReceivedExtraInfo (Chrome + // strips it from the provisional responseReceived headers), so a hop's + // cookie can appear in allHeaders() only if the ExtraInfo events were + // paired with the correct response. This catches both mis-attribution (a + // later hop's cookie landing on an earlier response) and merging. + tb.withHandler("/redir-start", func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Set-Cookie", "step=1; Path=/") + http.Redirect(w, r, tb.url("/redir-mid"), http.StatusFound) + }) + tb.withHandler("/redir-mid", func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Set-Cookie", "step=2; Path=/") + http.Redirect(w, r, tb.url("/redir-end"), http.StatusFound) + }) + tb.withHandler("/redir-end", func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Set-Cookie", "step=3; Path=/") + w.Header().Set("Content-Type", "text/html") + _, err := fmt.Fprint(w, "done") + require.NoError(t, err) + }) + + tb.vu.ActivateVU() + tb.vu.StartIteration(t) + defer tb.vu.EndIteration(t) + + gv, err := tb.vu.RunAsync(t, ` + const page = await browser.newPage(); + + var responses = []; + page.on('response', async (response) => { + const headers = await response.allHeaders(); + responses.push({ + url: response.url(), + setCookie: headers['set-cookie'] || '', + }); + }); + + await page.goto('%s', {waitUntil: 'networkidle'}); + await page.close(); + + return JSON.stringify(responses); + `, tb.url("/redir-start")) + require.NoError(t, err) + + got := k6test.ToPromise(t, gv) + + var responses []struct { + URL string `json:"url"` + SetCookie string `json:"setCookie"` + } + require.NoError(t, json.Unmarshal([]byte(got.Result().String()), &responses)) + + setCookieByURL := make(map[string]string, len(responses)) + for _, r := range responses { + setCookieByURL[r.URL] = r.SetCookie + } + + // Each hop must carry only its own Set-Cookie. + steps := []string{"step=1", "step=2", "step=3"} + for _, tc := range []struct { + url string + step string + }{ + {tb.url("/redir-start"), "step=1"}, + {tb.url("/redir-mid"), "step=2"}, + {tb.url("/redir-end"), "step=3"}, + } { + cookie, ok := setCookieByURL[tc.url] + require.True(t, ok, "no response captured for %s", tc.url) + assert.Contains(t, cookie, tc.step, "wrong Set-Cookie on %s", tc.url) + for _, other := range steps { + if other != tc.step { + assert.NotContains(t, cookie, other, + "%s leaked %s from another hop", tc.url, other) + } } - slices.SortFunc(resp.HeadersArray, sortByName) - slices.SortFunc(expected[i].HeadersArray, sortByName) - assert.Equal(t, expected[i], resp) } } From ce5fa51094b2a6e3922ad3060be733bbe2ef04ed Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Thu, 16 Jul 2026 19:10:31 +0100 Subject: [PATCH 024/182] chore(deps): update debian docker tag to trixie-20260623 (#6114) | datasource | package | from | to | | ---------- | ------- | --------------- | --------------- | | docker | debian | trixie-20260610 | trixie-20260623 | Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> --- packaging/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/Dockerfile b/packaging/Dockerfile index 4123870fb..88e8a3ce8 100644 --- a/packaging/Dockerfile +++ b/packaging/Dockerfile @@ -1,4 +1,4 @@ -FROM debian:trixie-20260610@sha256:fe7312b5f05bf5f43fad76bcd8945642e4e47a68aefd1b73f447615899d0fac1 +FROM debian:13@sha256:fac46bff2e02f51425b6e33b0e1169f55dfb053d83511ca28aa50c09fd5ed7a4 LABEL maintainer="k6 Developers " From 4de4134c3c2b95f50f9464cbc2f1cd9e5555813e Mon Sep 17 00:00:00 2001 From: Mihail Stoykov <312246+mstoykov@users.noreply.github.com> Date: Fri, 17 Jul 2026 14:33:54 +0300 Subject: [PATCH 025/182] chore: remove dead internal/cloudapi/v6/config.go (#6149) Config, NewConfig, Apply, GetConsolidatedConfig, mergeFromCloudOption, and GetTemporaryCloudConfig had zero callers anywhere outside this file and its own test file. Every consumer of internal/cloudapi/v6 (internal/cmd/cloud.go, cloud_login.go, cloud_project_list.go, and internal/cloudapi/provisioning) only uses Client/NewClient/Project/ TestProgress/Status*/Result*/StatusEvent from this package; the real config path for the v6 API goes through the root cloudapi.Config instead, which this file duplicated ~90% of and then drifted from (e.g. missing StackID in its options.cloud merge, no Hostv6/ MetricsPushURL/TestRunToken/StackURL/DefaultProjectID fields). Co-authored-by: Claude Sonnet 5 --- internal/cloudapi/v6/config.go | 262 ---------------------------- internal/cloudapi/v6/config_test.go | 93 ---------- 2 files changed, 355 deletions(-) delete mode 100644 internal/cloudapi/v6/config.go delete mode 100644 internal/cloudapi/v6/config_test.go diff --git a/internal/cloudapi/v6/config.go b/internal/cloudapi/v6/config.go deleted file mode 100644 index c03259ba0..000000000 --- a/internal/cloudapi/v6/config.go +++ /dev/null @@ -1,262 +0,0 @@ -package cloudapi - -import ( - "bytes" - "encoding/json" - "time" - - "github.com/mstoykov/envconfig" - "gopkg.in/guregu/null.v3" - - "go.k6.io/k6/v2/lib/types" -) - -// Config holds all the necessary data and options for sending metrics to the k6 Cloud. -// -//nolint:lll -type Config struct { - // TODO: refactor common stuff between cloud execution and output - Token null.String `json:"token" envconfig:"K6_CLOUD_TOKEN"` - StackID null.Int `json:"stackID" envconfig:"K6_CLOUD_STACK_ID"` - ProjectID null.Int `json:"projectID" envconfig:"K6_CLOUD_PROJECT_ID"` - Name null.String `json:"name" envconfig:"K6_CLOUD_NAME"` - - Host null.String `json:"host" envconfig:"K6_CLOUD_HOST"` - Timeout types.NullDuration `json:"timeout" envconfig:"K6_CLOUD_TIMEOUT"` - - LogsTailURL null.String `json:"-" envconfig:"K6_CLOUD_LOGS_TAIL_URL"` - WebAppURL null.String `json:"webAppURL" envconfig:"K6_CLOUD_WEB_APP_URL"` - TestRunDetails null.String `json:"testRunDetails" envconfig:"K6_CLOUD_TEST_RUN_DETAILS"` - NoCompress null.Bool `json:"noCompress" envconfig:"K6_CLOUD_NO_COMPRESS"` - StopOnError null.Bool `json:"stopOnError" envconfig:"K6_CLOUD_STOP_ON_ERROR"` - APIVersion null.Int `json:"apiVersion" envconfig:"K6_CLOUD_API_VERSION"` - - // PushRefID is the identifier used by k6 Cloud to correlate all the things that - // belong to the same test run/execution. Currently, it is equivalent to the test run id. - // But, in the future, or in future solutions (e.g. Synthetic Monitoring), there might be - // no test run id, and we may still need an identifier to correlate all the things. - PushRefID null.String `json:"pushRefID" envconfig:"K6_CLOUD_PUSH_REF_ID"` - - // Defines the max allowed number of time series in a single batch. - MaxTimeSeriesInBatch null.Int `json:"maxTimeSeriesInBatch" envconfig:"K6_CLOUD_MAX_TIME_SERIES_IN_BATCH"` - - // The time interval between periodic API calls for sending samples to the cloud ingest service. - MetricPushInterval types.NullDuration `json:"metricPushInterval" envconfig:"K6_CLOUD_METRIC_PUSH_INTERVAL"` - - // This is how many concurrent pushes will be done at the same time to the cloud - MetricPushConcurrency null.Int `json:"metricPushConcurrency" envconfig:"K6_CLOUD_METRIC_PUSH_CONCURRENCY"` - - // If specified and is greater than 0, sample aggregation with that period is enabled - AggregationPeriod types.NullDuration `json:"aggregationPeriod" envconfig:"K6_CLOUD_AGGREGATION_PERIOD"` - - // If aggregation is enabled, this specifies how long we'll wait for period samples to accumulate before trying to aggregate them. - AggregationWaitPeriod types.NullDuration `json:"aggregationWaitPeriod" envconfig:"K6_CLOUD_AGGREGATION_WAIT_PERIOD"` - - // Indicates whether to send traces to the k6 Insights backend service. - TracesEnabled null.Bool `json:"tracesEnabled" envconfig:"K6_CLOUD_TRACES_ENABLED"` - - // The host of the k6 Insights backend service. - TracesHost null.String `json:"traceHost" envconfig:"K6_CLOUD_TRACES_HOST"` - - // This is how many concurrent pushes will be done at the same time to the cloud - TracesPushConcurrency null.Int `json:"tracesPushConcurrency" envconfig:"K6_CLOUD_TRACES_PUSH_CONCURRENCY"` - - // The time interval between periodic API calls for sending samples to the cloud ingest service. - TracesPushInterval types.NullDuration `json:"tracesPushInterval" envconfig:"K6_CLOUD_TRACES_PUSH_INTERVAL"` -} - -// NewConfig creates a new Config instance with default values for some fields. -func NewConfig() Config { - return Config{ - StackID: null.NewInt(0, false), - APIVersion: null.NewInt(2, false), - Host: null.NewString("https://api.k6.io", false), - LogsTailURL: null.NewString("wss://cloudlogs.k6.io/api/v1/tail", false), - WebAppURL: null.NewString("https://app.k6.io", false), - MetricPushInterval: types.NewNullDuration(1*time.Second, false), - MetricPushConcurrency: null.NewInt(1, false), - Timeout: types.NewNullDuration(1*time.Minute, false), - - // The set value (1000) is selected for performance reasons. - // Any change to this value should be first discussed with internal stakeholders. - MaxTimeSeriesInBatch: null.NewInt(1000, false), - - // TODO: the following values were used by the previous default version (v1). - // We decided to keep the same values mostly for having a smoother migration to v2. - // Because the previous version's aggregation config, a few lines below, is overwritten - // by the remote service with the same values that we are now setting here for v2. - // When the migration will be completed we may evaluate to re-discuss them - // as we may evaluate to reduce these values - especially the waiting period. - // A more specific request about waiting period is mentioned in the link below: - // https://github.com/grafana/k6/blob/44e1e63aadb66784ff0a12b8d9821a0fdc9e7467/output/cloud/expv2/collect.go#L72-L77 - AggregationPeriod: types.NewNullDuration(3*time.Second, false), - AggregationWaitPeriod: types.NewNullDuration(8*time.Second, false), - - TracesEnabled: null.NewBool(true, false), - TracesHost: null.NewString("grpc-k6-api-prod-prod-us-east-0.grafana.net:443", false), - TracesPushInterval: types.NewNullDuration(1*time.Second, false), - TracesPushConcurrency: null.NewInt(1, false), - } -} - -// Apply saves config non-zero config values from the passed config in the receiver. -// -//nolint:cyclop -func (c Config) Apply(cfg Config) Config { - if cfg.Token.Valid { - c.Token = cfg.Token - } - if cfg.ProjectID.Valid && cfg.ProjectID.Int64 > 0 { - c.ProjectID = cfg.ProjectID - } - if cfg.Name.Valid && cfg.Name.String != "" { - c.Name = cfg.Name - } - if cfg.Host.Valid && cfg.Host.String != "" { - c.Host = cfg.Host - } - if cfg.LogsTailURL.Valid && cfg.LogsTailURL.String != "" { - c.LogsTailURL = cfg.LogsTailURL - } - if cfg.PushRefID.Valid { - c.PushRefID = cfg.PushRefID - } - if cfg.WebAppURL.Valid { - c.WebAppURL = cfg.WebAppURL - } - if cfg.TestRunDetails.Valid { - c.TestRunDetails = cfg.TestRunDetails - } - if cfg.NoCompress.Valid { - c.NoCompress = cfg.NoCompress - } - if cfg.StopOnError.Valid { - c.StopOnError = cfg.StopOnError - } - if cfg.Timeout.Valid { - c.Timeout = cfg.Timeout - } - if cfg.APIVersion.Valid { - c.APIVersion = cfg.APIVersion - } - if cfg.MaxTimeSeriesInBatch.Valid { - c.MaxTimeSeriesInBatch = cfg.MaxTimeSeriesInBatch - } - if cfg.MetricPushInterval.Valid { - c.MetricPushInterval = cfg.MetricPushInterval - } - if cfg.MetricPushConcurrency.Valid { - c.MetricPushConcurrency = cfg.MetricPushConcurrency - } - if cfg.TracesEnabled.Valid { - c.TracesEnabled = cfg.TracesEnabled - } - if cfg.TracesHost.Valid { - c.TracesHost = cfg.TracesHost - } - if cfg.TracesPushInterval.Valid { - c.TracesPushInterval = cfg.TracesPushInterval - } - if cfg.TracesPushConcurrency.Valid { - c.TracesPushConcurrency = cfg.TracesPushConcurrency - } - if cfg.AggregationPeriod.Valid { - c.AggregationPeriod = cfg.AggregationPeriod - } - if cfg.AggregationWaitPeriod.Valid { - c.AggregationWaitPeriod = cfg.AggregationWaitPeriod - } - return c -} - -// GetConsolidatedConfig combines the default config values with the JSON config -// values and environment variables and returns the final result. -func GetConsolidatedConfig( - jsonRawConf json.RawMessage, - env map[string]string, - configArg string, - cloudConfig json.RawMessage, -) (Config, error) { - result := NewConfig() - if jsonRawConf != nil { - jsonConf := Config{} - if err := json.Unmarshal(jsonRawConf, &jsonConf); err != nil { - return result, err - } - result = result.Apply(jsonConf) - } - - if err := mergeFromCloudOption(cloudConfig, &result); err != nil { - return result, err - } - - envConfig := Config{} - if err := envconfig.Process("", &envConfig, func(key string) (string, bool) { - v, ok := env[key] - return v, ok - }); err != nil { - // TODO: get rid of envconfig and actually use the env parameter... - return result, err - } - result = result.Apply(envConfig) - - if configArg != "" { - result.Name = null.StringFrom(configArg) - } - - return result, nil -} - -// mergeFromCloudOption merges three fields from the JSON in a cloud key of -// the provided external map. Used for options.cloud settings. -func mergeFromCloudOption( - cloudConfig json.RawMessage, - conf *Config, -) error { - if cloudConfig == nil { - return nil - } - - // Original comment - // TODO: Important! Separate configs and fix the whole 2 configs mess! - tmpConfig := Config{} - if err := json.Unmarshal(cloudConfig, &tmpConfig); err != nil { - return err - } - // Only take out the ProjectID, Name and Token from the options.cloud map: - if tmpConfig.ProjectID.Valid { - conf.ProjectID = tmpConfig.ProjectID - } - if tmpConfig.Name.Valid { - conf.Name = tmpConfig.Name - } - if tmpConfig.Token.Valid { - conf.Token = tmpConfig.Token - } - - return nil -} - -// GetTemporaryCloudConfig returns a temporary cloud config. -// Original comment -// TODO: Fix this -// We reuse cloud.Config for parsing options.cloud, but this probably shouldn't be -// done, as the idea of options.ext is that they are extensible without touching k6. But in -// order for this to happen, we shouldn't actually marshal cloud.Config on top of it, because -// it will be missing some fields that aren't actually mentioned in the struct. -// So in order for use to copy the fields that we need for k6 cloud's api we unmarshal in -// map[string]any and copy what we need if it isn't set already -func GetTemporaryCloudConfig(cloudConfig json.RawMessage) (map[string]any, error) { - tmpCloudConfig := make(map[string]any, 3) - if cloudConfig == nil { - return tmpCloudConfig, nil - } - - dec := json.NewDecoder(bytes.NewReader(cloudConfig)) - dec.UseNumber() // otherwise float64 are used - if err := dec.Decode(&tmpCloudConfig); err != nil { - return nil, err - } - - return tmpCloudConfig, nil -} diff --git a/internal/cloudapi/v6/config_test.go b/internal/cloudapi/v6/config_test.go deleted file mode 100644 index 73c2cacf8..000000000 --- a/internal/cloudapi/v6/config_test.go +++ /dev/null @@ -1,93 +0,0 @@ -package cloudapi - -import ( - "encoding/json" - "testing" - "time" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "gopkg.in/guregu/null.v3" - - "go.k6.io/k6/v2/lib/types" -) - -func TestConfigApply(t *testing.T) { - t.Parallel() - empty := Config{} - defaults := NewConfig() - - assert.Equal(t, empty, empty.Apply(empty)) - assert.Equal(t, empty, empty.Apply(defaults)) - assert.Equal(t, defaults, defaults.Apply(defaults)) - assert.Equal(t, defaults, defaults.Apply(empty)) - assert.Equal(t, defaults, defaults.Apply(empty).Apply(empty)) - - full := Config{ - Token: null.NewString("Token", true), - ProjectID: null.NewInt(1, true), - Name: null.NewString("Name", true), - Host: null.NewString("Host", true), - Timeout: types.NewNullDuration(5*time.Second, true), - LogsTailURL: null.NewString("LogsTailURL", true), - PushRefID: null.NewString("PushRefID", true), - WebAppURL: null.NewString("foo", true), - NoCompress: null.NewBool(true, true), - StopOnError: null.NewBool(true, true), - APIVersion: null.NewInt(2, true), - AggregationPeriod: types.NewNullDuration(2*time.Second, true), - AggregationWaitPeriod: types.NewNullDuration(4*time.Second, true), - MaxTimeSeriesInBatch: null.NewInt(3, true), - MetricPushInterval: types.NewNullDuration(1*time.Second, true), - MetricPushConcurrency: null.NewInt(3, true), - TracesEnabled: null.NewBool(true, true), - TracesHost: null.NewString("TracesHost", true), - TracesPushInterval: types.NewNullDuration(10*time.Second, true), - TracesPushConcurrency: null.NewInt(6, true), - } - - assert.Equal(t, full, full.Apply(empty)) - assert.Equal(t, full, full.Apply(defaults)) - assert.Equal(t, full, full.Apply(full)) - assert.Equal(t, full, empty.Apply(full)) - assert.Equal(t, full, defaults.Apply(full)) -} - -func TestGetConsolidatedConfig(t *testing.T) { - t.Parallel() - config, err := GetConsolidatedConfig(json.RawMessage(`{"token":"jsonraw"}`), nil, "", nil) - require.NoError(t, err) - require.Equal(t, "jsonraw", config.Token.String) - - config, err = GetConsolidatedConfig( - json.RawMessage(`{"token":"jsonraw"}`), - nil, - "", - json.RawMessage(`{"token":"ext"}`), - ) - require.NoError(t, err) - require.Equal(t, "ext", config.Token.String) - - config, err = GetConsolidatedConfig( - json.RawMessage(`{"token":"jsonraw"}`), - map[string]string{"K6_CLOUD_TOKEN": "envvalue"}, - "", - json.RawMessage(`{"token":"ext"}`), - ) - require.NoError(t, err) - require.Equal(t, "envvalue", config.Token.String) -} - -func TestGetConsolidatedConfig_EnvHasHigherPriority(t *testing.T) { - t.Parallel() - - config, err := GetConsolidatedConfig( - json.RawMessage(`{"token":"jsonraw"}`), - map[string]string{"K6_CLOUD_TOKEN": "envvalue"}, - "", - json.RawMessage(`{"token":"cloud"}`), - ) - require.NoError(t, err) - - require.Equal(t, "envvalue", config.Token.String) -} From 08ff3c47a5afc74b6cdea8967bd5318e6e60d06f Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Fri, 17 Jul 2026 14:43:28 +0300 Subject: [PATCH 026/182] fix(deps): update module github.com/klauspost/compress to v1.19.0 (#6156) | datasource | package | from | to | | ---------- | ----------------------------- | ------- | ------- | | go | github.com/klauspost/compress | v1.18.5 | v1.19.0 | Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 +- .../klauspost/compress/.gitattributes | 1 + .../klauspost/compress/flate/dict_decoder.go | 24 +- .../klauspost/compress/flate/inflate.go | 92 + .../klauspost/compress/huff0/build_table.go | 168 + .../compress/internal/snapref/decode.go | 2 +- .../klauspost/compress/s2/decode.go | 2 +- .../klauspost/compress/s2/decode_amd64.s | 2 +- .../github.com/klauspost/compress/s2/dict.go | 6 +- .../klauspost/compress/s2/encode_best.go | 28 +- .../klauspost/compress/s2/encode_better.go | 42 +- .../klauspost/compress/s2/hashtable_pool.go | 65 + .../klauspost/compress/zstd/dict.go | 3 +- .../klauspost/compress/zstd/enc_base.go | 28 + .../klauspost/compress/zstd/enc_best.go | 15 + .../klauspost/compress/zstd/enc_better.go | 18 + .../klauspost/compress/zstd/enc_dfast.go | 16 + .../klauspost/compress/zstd/enc_fast.go | 17 + .../klauspost/compress/zstd/enc_jobs.go | 352 +++ .../klauspost/compress/zstd/encoder.go | 210 +- .../compress/zstd/encoder_options.go | 69 +- .../compress/zstd/fse_decoder_amd64.s | 2 +- .../compress/zstd/fse_decoder_arm64.s | 146 + ...se_decoder_amd64.go => fse_decoder_asm.go} | 8 +- .../compress/zstd/fse_decoder_generic.go | 2 +- .../klauspost/compress/zstd/seqdec_amd64.go | 362 +-- .../klauspost/compress/zstd/seqdec_amd64.s | 2 +- .../klauspost/compress/zstd/seqdec_arm64.go | 70 + .../klauspost/compress/zstd/seqdec_arm64.s | 2705 +++++++++++++++++ .../klauspost/compress/zstd/seqdec_asm.go | 289 ++ .../klauspost/compress/zstd/seqdec_generic.go | 2 +- vendor/modules.txt | 2 +- 33 files changed, 4365 insertions(+), 391 deletions(-) create mode 100644 vendor/github.com/klauspost/compress/huff0/build_table.go create mode 100644 vendor/github.com/klauspost/compress/s2/hashtable_pool.go create mode 100644 vendor/github.com/klauspost/compress/zstd/enc_jobs.go create mode 100644 vendor/github.com/klauspost/compress/zstd/fse_decoder_arm64.s rename vendor/github.com/klauspost/compress/zstd/{fse_decoder_amd64.go => fse_decoder_asm.go} (81%) create mode 100644 vendor/github.com/klauspost/compress/zstd/seqdec_arm64.go create mode 100644 vendor/github.com/klauspost/compress/zstd/seqdec_arm64.s create mode 100644 vendor/github.com/klauspost/compress/zstd/seqdec_asm.go diff --git a/go.mod b/go.mod index b876e92d8..624665ca5 100644 --- a/go.mod +++ b/go.mod @@ -27,7 +27,7 @@ require ( github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 github.com/influxdata/influxdb1-client v0.0.0-20190402204710-8ff2fc3824fc github.com/jhump/protoreflect v1.18.0 - github.com/klauspost/compress v1.18.5 + github.com/klauspost/compress v1.19.0 github.com/mattn/go-colorable v0.1.15 github.com/mattn/go-isatty v0.0.22 github.com/mccutchen/go-httpbin/v2 v2.23.1 diff --git a/go.sum b/go.sum index fe3992c38..8c63131ce 100644 --- a/go.sum +++ b/go.sum @@ -113,8 +113,8 @@ github.com/jhump/protoreflect/v2 v2.0.0-beta.1 h1:Dw1rslK/VotaUGYsv53XVWITr+5RCP github.com/jhump/protoreflect/v2 v2.0.0-beta.1/go.mod h1:D9LBEowZyv8/iSu97FU2zmXG3JxVTmNw21mu63niFzU= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/klauspost/compress v1.18.5 h1:/h1gH5Ce+VWNLSWqPzOVn6XBO+vJbCNGvjoaGBFW2IE= -github.com/klauspost/compress v1.18.5/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ= +github.com/klauspost/compress v1.19.0 h1:sXLILfc9jV2QYWkzFOPWStmcUVH2RHEB1JCdY2oVvCQ= +github.com/klauspost/compress v1.19.0/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= diff --git a/vendor/github.com/klauspost/compress/.gitattributes b/vendor/github.com/klauspost/compress/.gitattributes index 402433593..57aa6487c 100644 --- a/vendor/github.com/klauspost/compress/.gitattributes +++ b/vendor/github.com/klauspost/compress/.gitattributes @@ -1,2 +1,3 @@ * -text *.bin -text -diff +*.md text eol=lf diff --git a/vendor/github.com/klauspost/compress/flate/dict_decoder.go b/vendor/github.com/klauspost/compress/flate/dict_decoder.go index cb855abc4..37861cf6a 100644 --- a/vendor/github.com/klauspost/compress/flate/dict_decoder.go +++ b/vendor/github.com/klauspost/compress/flate/dict_decoder.go @@ -28,9 +28,10 @@ type dictDecoder struct { hist []byte // Sliding window history // Invariant: 0 <= rdPos <= wrPos <= len(hist) - wrPos int // Current output position in buffer - rdPos int // Have emitted hist[:rdPos] already - full bool // Has a full window length been written yet? + wrPos int // Current output position in buffer + rdPos int // Have emitted hist[:rdPos] already + flushed int64 // Total bytes returned by readFlush since init + full bool // Has a full window length been written yet? } // init initializes dictDecoder to have a sliding window dictionary of the given @@ -167,11 +168,22 @@ loop: return dstPos - dstBase } +// appendWindow appends the current sliding window (up to len(hist) most recent +// bytes, oldest first) to dst. +func (dd *dictDecoder) appendWindow(dst []byte) []byte { + if dd.full { + dst = append(dst, dd.hist[dd.wrPos:]...) + return append(dst, dd.hist[:dd.wrPos]...) + } + return append(dst, dd.hist[:dd.wrPos]...) +} + // readFlush returns a slice of the historical buffer that is ready to be // emitted to the user. The data returned by readFlush must be fully consumed // before calling any other dictDecoder methods. func (dd *dictDecoder) readFlush() []byte { toRead := dd.hist[dd.rdPos:dd.wrPos] + dd.flushed += int64(len(toRead)) dd.rdPos = dd.wrPos if dd.wrPos == len(dd.hist) { dd.wrPos, dd.rdPos = 0, 0 @@ -179,3 +191,9 @@ func (dd *dictDecoder) readFlush() []byte { } return toRead } + +// decoded reports the total number of bytes written into the dictionary since +// init (i.e. excluding any preset dict bytes). +func (dd *dictDecoder) decoded() int64 { + return dd.flushed + int64(dd.wrPos-dd.rdPos) +} diff --git a/vendor/github.com/klauspost/compress/flate/inflate.go b/vendor/github.com/klauspost/compress/flate/inflate.go index 6e90126db..39dd683b2 100644 --- a/vendor/github.com/klauspost/compress/flate/inflate.go +++ b/vendor/github.com/klauspost/compress/flate/inflate.go @@ -342,6 +342,11 @@ type decompressor struct { final bool flushMode flushMode + cb func(InflateCheckpoint) + cp InflateCheckpoint + hasCP bool // WithResumeFrom was supplied + uncOffset int64 // baseline uncompressed offset (from a resume checkpoint) + cpBuf []byte } func (f *decompressor) nextBlock() { @@ -676,6 +681,18 @@ func (f *decompressor) finishBlock() { f.toRead = f.dict.readFlush() } + if f.cb != nil { + bitPos := f.roffset*8 - int64(f.nb) + f.cpBuf = f.dict.appendWindow(f.cpBuf[:0]) + f.cb(InflateCheckpoint{ + UncompressedOffset: f.uncOffset + f.dict.decoded(), + CompressedOffset: bitPos / 8, + Final: f.final, + BitOffset: uint8(bitPos & 7), + Window: f.cpBuf, + }) + } + f.step = nextBlock } @@ -806,6 +823,45 @@ func (f *decompressor) Reset(r io.Reader, dict []byte) error { return nil } +// ResetCP will adjust the input to the provided checkpoint. +// It is assumed the input stream is forwarded to cp.CompressedOffset. +func (f *decompressor) ResetCP(r io.Reader, cp InflateCheckpoint) error { + *f = decompressor{ + r: makeReader(r), + bits: f.bits, + codebits: f.codebits, + h1: f.h1, + h2: f.h2, + dict: f.dict, + step: nextBlock, + cpBuf: f.cpBuf, + } + return f.applyCP(cp) +} + +// applyCP seeds the decompressor state from a resume checkpoint: +// loads the sliding window, sets the absolute compressed/uncompressed +// offsets, and skips cp.BitOffset bits into the first input byte so +// the next decode aligns with the start of a deflate block. +func (f *decompressor) applyCP(cp InflateCheckpoint) error { + f.dict.init(maxMatchOffset, cp.Window) + f.roffset = cp.CompressedOffset + f.uncOffset = cp.UncompressedOffset + f.final = cp.Final + f.b = 0 + f.nb = 0 + if cp.BitOffset > 0 { + c, err := f.r.ReadByte() + if err != nil { + return noEOF(err) + } + f.roffset++ + f.b = uint32(c) >> cp.BitOffset + f.nb = 8 - uint(cp.BitOffset) + } + return nil +} + type ReaderOpt func(*decompressor) // WithPartialBlock tells decompressor to return after each block, @@ -823,6 +879,36 @@ func WithDict(dict []byte) ReaderOpt { } } +// InflateCheckpoint provides a resumable checkpoint for inflate. +type InflateCheckpoint struct { + UncompressedOffset int64 // Byte offset in the decompressed stream + CompressedOffset int64 // Byte offset in the compressed stream + Final bool // True if this is the final block + BitOffset uint8 // 0-7 bits + Window []byte // 32KB sliding window dictionary +} + +// WithEobCallback will call the provided function after each block +// with the current gzip checkpoint. +// After returning the provided window can no longer be referenced. +// The callback will not be triggered after a block is marked "final". +// The callback is not retained after Reset. +func WithEobCallback(cb func(InflateCheckpoint)) ReaderOpt { + return func(f *decompressor) { + f.cb = cb + } +} + +// WithResumeFrom will adjust the input to the provided checkpoint. +// It is assumed the input stream is forwarded to the provided offset. +// The checkpoint is removed when Reset is called. +func WithResumeFrom(cp InflateCheckpoint) ReaderOpt { + return func(f *decompressor) { + f.cp = cp + f.hasCP = true + } +} + // NewReaderOpts returns new reader with provided options func NewReaderOpts(r io.Reader, opts ...ReaderOpt) io.ReadCloser { fixedHuffmanDecoderInit() @@ -838,6 +924,12 @@ func NewReaderOpts(r io.Reader, opts ...ReaderOpt) io.ReadCloser { opt(&f) } + if f.hasCP { + if err := f.applyCP(f.cp); err != nil { + f.err = err + } + } + return &f } diff --git a/vendor/github.com/klauspost/compress/huff0/build_table.go b/vendor/github.com/klauspost/compress/huff0/build_table.go new file mode 100644 index 000000000..e3757c87e --- /dev/null +++ b/vendor/github.com/klauspost/compress/huff0/build_table.go @@ -0,0 +1,168 @@ +package huff0 + +import "errors" + +// BuildCTable builds a Huffman compression table from a precomputed symbol +// histogram and installs it as the previous (reuse) table on s. +// +// After this call: +// - EstimateSize/CanUseTable can probe the table against other histograms. +// - Compress1X/Compress4X with Reuse = ReusePolicyMust will encode without +// emitting a new table header. +// - TransferCTable can hand the table to a sibling Scratch. +// +// count[i] is the number of occurrences of symbol i. The histogram must have +// at least 2 distinct non-zero symbols; ErrUseRLE is returned for a single +// symbol and an error is returned for an empty histogram. +func (s *Scratch) BuildCTable(count *[256]uint32) error { + if s == nil { + return errors.New("huff0: BuildCTable on nil Scratch") + } + if count == nil { + return errors.New("huff0: nil count passed to BuildCTable") + } + var err error + s, err = s.prepare(nil) + if err != nil { + return err + } + s.count = *count + var total, maxCount int + var symLen uint16 + for i, v := range s.count { + total += int(v) + if int(v) > maxCount { + maxCount = int(v) + } + if v != 0 { + symLen = uint16(i) + 1 + } + } + if total == 0 { + return errors.New("huff0: empty histogram") + } + if symLen < 2 || maxCount == total { + return ErrUseRLE + } + // huff0's internal rank table assumes total ≤ BlockSizeMax (it uses + // highBit32(count+1) + 1 as a rank index into a fixed-size array). + // Histograms summed across multiple blocks can exceed that; scale the + // counts down preserving the distribution. Non-zero entries round up so + // rare symbols stay representable. + if total > BlockSizeMax { + shift := uint(0) + for total>>shift > BlockSizeMax { + shift++ + } + round := uint32(1<> shift + if scaled == 0 { + scaled = 1 + } + s.count[i] = scaled + newTotal += int(scaled) + if int(scaled) > newMax { + newMax = int(scaled) + } + } + total = newTotal + maxCount = newMax + if maxCount == total { + return ErrUseRLE + } + } + s.symbolLen = symLen + s.maxCount = maxCount + s.srcLen = total + if err := s.buildCTable(); err != nil { + return err + } + if cap(s.prevTable) < len(s.cTable) { + s.prevTable = make(cTable, 0, maxSymbolValue+1) + } + s.prevTable = s.prevTable[:len(s.cTable)] + copy(s.prevTable, s.cTable) + s.prevTableLog = s.actualTableLog + // Force the next Compress* to recount from real input. + s.clearCount = true + s.maxCount = 0 + return nil +} + +// EstimateSize returns an estimated compressed payload size in bytes for the +// supplied histogram using the table currently stored in prevTable. It returns +// -1 when the table cannot encode every non-zero symbol of hist (i.e. when +// CanUseTable would return false). The estimate excludes the table header. +func (s *Scratch) EstimateSize(hist *[256]uint32) int { + if s == nil || hist == nil || len(s.prevTable) == 0 { + return -1 + } + pt := s.prevTable + nbBits := uint32(7) + for i, v := range hist { + if v == 0 { + continue + } + if i >= len(pt) || pt[i].nBits == 0 { + return -1 + } + nbBits += uint32(pt[i].nBits) * v + } + return int(nbBits >> 3) +} + +// CanUseTable reports whether the table in prevTable can encode every +// non-zero symbol present in hist. +func (s *Scratch) CanUseTable(hist *[256]uint32) bool { + if s == nil || hist == nil || len(s.prevTable) == 0 { + return false + } + pt := s.prevTable + for i, v := range hist { + if v == 0 { + continue + } + if i >= len(pt) || pt[i].nBits == 0 { + return false + } + } + return true +} + +// AppendTable serializes the table currently stored in prevTable (e.g. as +// installed by BuildCTable or carried over from a previous Compress call) +// into a self-delimiting zstd-style header and appends it to dst. The +// returned slice can be parsed back by ReadTable. +func (s *Scratch) AppendTable(dst []byte) ([]byte, error) { + if s == nil || len(s.prevTable) == 0 { + return dst, errors.New("huff0: AppendTable with empty table") + } + // cTable.write reads s.actualTableLog, s.symbolLen, s.huffWeight, s.fse + // and writes into s.Out. Save/restore Out so we don't disturb in-flight + // compression buffers. + saveOut := s.Out + saveTL := s.actualTableLog + saveSL := s.symbolLen + if s.fse == nil { + // Lazily init in case AppendTable is called on a fresh Scratch. + if _, err := s.prepare(nil); err != nil { + return dst, err + } + saveOut = s.Out + } + s.Out = s.Out[:0] + s.actualTableLog = s.prevTableLog + s.symbolLen = uint16(len(s.prevTable)) + if err := s.prevTable.write(s); err != nil { + s.Out, s.actualTableLog, s.symbolLen = saveOut, saveTL, saveSL + return dst, err + } + dst = append(dst, s.Out...) + s.Out, s.actualTableLog, s.symbolLen = saveOut, saveTL, saveSL + return dst, nil +} diff --git a/vendor/github.com/klauspost/compress/internal/snapref/decode.go b/vendor/github.com/klauspost/compress/internal/snapref/decode.go index a2c82fcd2..584b7574b 100644 --- a/vendor/github.com/klauspost/compress/internal/snapref/decode.go +++ b/vendor/github.com/klauspost/compress/internal/snapref/decode.go @@ -31,7 +31,7 @@ func DecodedLen(src []byte) (int, error) { // that the length header occupied. func decodedLen(src []byte) (blockLen, headerLen int, err error) { v, n := binary.Uvarint(src) - if n <= 0 || v > 0xffffffff { + if n <= 0 || n > 5 || v > 0xffffffff { return 0, 0, ErrCorrupt } diff --git a/vendor/github.com/klauspost/compress/s2/decode.go b/vendor/github.com/klauspost/compress/s2/decode.go index 264ffd0a9..17abb515a 100644 --- a/vendor/github.com/klauspost/compress/s2/decode.go +++ b/vendor/github.com/klauspost/compress/s2/decode.go @@ -35,7 +35,7 @@ func DecodedLen(src []byte) (int, error) { // that the length header occupied. func decodedLen(src []byte) (blockLen, headerLen int, err error) { v, n := binary.Uvarint(src) - if n <= 0 || v > 0xffffffff { + if n <= 0 || n > 5 || v > 0xffffffff { return 0, 0, ErrCorrupt } diff --git a/vendor/github.com/klauspost/compress/s2/decode_amd64.s b/vendor/github.com/klauspost/compress/s2/decode_amd64.s index 9b105e03c..1216df78f 100644 --- a/vendor/github.com/klauspost/compress/s2/decode_amd64.s +++ b/vendor/github.com/klauspost/compress/s2/decode_amd64.s @@ -51,7 +51,7 @@ // // The d variable is implicitly R_DST - R_DBASE, and len(dst)-d is R_DEND - R_DST. // The s variable is implicitly R_SRC - R_SBASE, and len(src)-s is R_SEND - R_SRC. -TEXT ·s2Decode(SB), NOSPLIT, $48-56 +TEXT ·s2Decode(SB), NOSPLIT, $56-56 // Initialize R_SRC, R_DST and R_DBASE-R_SEND. MOVQ dst_base+0(FP), R_DBASE MOVQ dst_len+8(FP), R_DLEN diff --git a/vendor/github.com/klauspost/compress/s2/dict.go b/vendor/github.com/klauspost/compress/s2/dict.go index f125ad096..f8dc65280 100644 --- a/vendor/github.com/klauspost/compress/s2/dict.go +++ b/vendor/github.com/klauspost/compress/s2/dict.go @@ -56,10 +56,12 @@ func NewDict(dict []byte) *Dict { if len(dict) < MinDictSize || len(dict) > MaxDictSize { return nil } - d.repeat = int(r) - if d.repeat > len(dict) { + // Compare as uint64: int(r) would wrap negative for r > MaxInt64, + // slipping past the bounds check and causing an OOB read in encode. + if r > uint64(len(dict)) { return nil } + d.repeat = int(r) return &d } diff --git a/vendor/github.com/klauspost/compress/s2/encode_best.go b/vendor/github.com/klauspost/compress/s2/encode_best.go index c857c5c28..49f2166ec 100644 --- a/vendor/github.com/klauspost/compress/s2/encode_best.go +++ b/vendor/github.com/klauspost/compress/s2/encode_best.go @@ -23,12 +23,12 @@ func encodeBlockBest(dst, src []byte, dict *Dict) (d int) { // Initialize the hash tables. const ( // Long hash matches. - lTableBits = 19 - maxLTableSize = 1 << lTableBits + lTableBits = bestLongTableBits + maxLTableSize = bestLongTableSize // Short hash matches. - sTableBits = 16 - maxSTableSize = 1 << sTableBits + sTableBits = bestShortTableBits + maxSTableSize = bestShortTableSize inputMargin = 8 + 2 @@ -44,8 +44,10 @@ func encodeBlockBest(dst, src []byte, dict *Dict) (d int) { } sLimitDict := min(len(src)-inputMargin, MaxDictSrcOffset-inputMargin) - var lTable [maxLTableSize]uint64 - var sTable [maxSTableSize]uint64 + tbl := getBestTables() + lTable := &tbl.lTable + sTable := &tbl.sTable + defer bestTablePool.Put(tbl) // Bail if we can't compress to at least this. dstLimit := len(src) - 5 @@ -456,12 +458,12 @@ func encodeBlockBestSnappy(dst, src []byte) (d int) { // Initialize the hash tables. const ( // Long hash matches. - lTableBits = 19 - maxLTableSize = 1 << lTableBits + lTableBits = bestLongTableBits + maxLTableSize = bestLongTableSize // Short hash matches. - sTableBits = 16 - maxSTableSize = 1 << sTableBits + sTableBits = bestShortTableBits + maxSTableSize = bestShortTableSize inputMargin = 8 + 2 ) @@ -474,8 +476,10 @@ func encodeBlockBestSnappy(dst, src []byte) (d int) { return 0 } - var lTable [maxLTableSize]uint64 - var sTable [maxSTableSize]uint64 + tbl := getBestTables() + lTable := &tbl.lTable + sTable := &tbl.sTable + defer bestTablePool.Put(tbl) // Bail if we can't compress to at least this. dstLimit := len(src) - 5 diff --git a/vendor/github.com/klauspost/compress/s2/encode_better.go b/vendor/github.com/klauspost/compress/s2/encode_better.go index 1e30fb731..adbc57c4d 100644 --- a/vendor/github.com/klauspost/compress/s2/encode_better.go +++ b/vendor/github.com/klauspost/compress/s2/encode_better.go @@ -59,16 +59,18 @@ func encodeBlockBetterGo(dst, src []byte) (d int) { // Initialize the hash tables. const ( // Long hash matches. - lTableBits = 17 - maxLTableSize = 1 << lTableBits + lTableBits = betterLongTableBits + maxLTableSize = betterLongTableSize // Short hash matches. - sTableBits = 14 - maxSTableSize = 1 << sTableBits + sTableBits = betterShortTableBits + maxSTableSize = betterShortTableSize ) - var lTable [maxLTableSize]uint32 - var sTable [maxSTableSize]uint32 + tbl := getBetterTables() + lTable := &tbl.lTable + sTable := &tbl.sTable + defer betterTablePool.Put(tbl) // Bail if we can't compress to at least this. dstLimit := len(src) - len(src)>>5 - 6 @@ -317,16 +319,18 @@ func encodeBlockBetterSnappyGo(dst, src []byte) (d int) { // Initialize the hash tables. const ( // Long hash matches. - lTableBits = 16 - maxLTableSize = 1 << lTableBits + lTableBits = betterSnappyLongTableBits + maxLTableSize = betterSnappyLongTableSize // Short hash matches. - sTableBits = 14 - maxSTableSize = 1 << sTableBits + sTableBits = betterShortTableBits + maxSTableSize = betterShortTableSize ) - var lTable [maxLTableSize]uint32 - var sTable [maxSTableSize]uint32 + tbl := getBetterSnappyTables() + lTable := &tbl.lTable + sTable := &tbl.sTable + defer betterSnappyTablePool.Put(tbl) // Bail if we can't compress to at least this. dstLimit := len(src) - len(src)>>5 - 6 @@ -902,12 +906,12 @@ func encodeBlockBetterDict(dst, src []byte, dict *Dict) (d int) { // Initialize the hash tables. const ( // Long hash matches. - lTableBits = 17 - maxLTableSize = 1 << lTableBits + lTableBits = betterLongTableBits + maxLTableSize = betterLongTableSize // Short hash matches. - sTableBits = 14 - maxSTableSize = 1 << sTableBits + sTableBits = betterShortTableBits + maxSTableSize = betterShortTableSize maxAhead = 8 // maximum bytes ahead without checking sLimit @@ -921,8 +925,10 @@ func encodeBlockBetterDict(dst, src []byte, dict *Dict) (d int) { dict.initBetter() - var lTable [maxLTableSize]uint32 - var sTable [maxSTableSize]uint32 + tbl := getBetterTables() + lTable := &tbl.lTable + sTable := &tbl.sTable + defer betterTablePool.Put(tbl) // Bail if we can't compress to at least this. dstLimit := len(src) - len(src)>>5 - 6 diff --git a/vendor/github.com/klauspost/compress/s2/hashtable_pool.go b/vendor/github.com/klauspost/compress/s2/hashtable_pool.go new file mode 100644 index 000000000..ec972132b --- /dev/null +++ b/vendor/github.com/klauspost/compress/s2/hashtable_pool.go @@ -0,0 +1,65 @@ +package s2 + +import "sync" + +// Table size constants +const ( + betterLongTableBits = 17 + betterLongTableSize = 1 << betterLongTableBits // 131072 + + betterShortTableBits = 14 + betterShortTableSize = 1 << betterShortTableBits // 16384 + + betterSnappyLongTableBits = 16 + betterSnappyLongTableSize = 1 << betterSnappyLongTableBits // 65536 + + bestLongTableBits = 19 + bestLongTableSize = 1 << bestLongTableBits // 524288 + + bestShortTableBits = 16 + bestShortTableSize = 1 << bestShortTableBits // 65536 +) + +type betterTables struct { + lTable [betterLongTableSize]uint32 + sTable [betterShortTableSize]uint32 +} + +var betterTablePool = sync.Pool{New: func() any { return &betterTables{} }} + +// betterSnappyTables holds better-snappy compression hash tables. +type betterSnappyTables struct { + lTable [betterSnappyLongTableSize]uint32 + sTable [betterShortTableSize]uint32 +} + +var betterSnappyTablePool = sync.Pool{New: func() any { return &betterSnappyTables{} }} + +// bestTables holds best compression hash tables. +type bestTables struct { + lTable [bestLongTableSize]uint64 + sTable [bestShortTableSize]uint64 +} + +var bestTablePool = sync.Pool{New: func() any { return &bestTables{} }} + +// getBetterTables gets a zeroed betterTables from the pool. +func getBetterTables() *betterTables { + t := betterTablePool.Get().(*betterTables) + *t = betterTables{} + return t +} + +// getBetterSnappyTables gets a zeroed betterSnappyTables from the pool. +func getBetterSnappyTables() *betterSnappyTables { + t := betterSnappyTablePool.Get().(*betterSnappyTables) + *t = betterSnappyTables{} + return t +} + +// getBestTables gets a zeroed bestTables from the pool. +func getBestTables() *bestTables { + t := bestTablePool.Get().(*bestTables) + *t = bestTables{} + return t +} diff --git a/vendor/github.com/klauspost/compress/zstd/dict.go b/vendor/github.com/klauspost/compress/zstd/dict.go index 2ffbfdf37..4f1c4938c 100644 --- a/vendor/github.com/klauspost/compress/zstd/dict.go +++ b/vendor/github.com/klauspost/compress/zstd/dict.go @@ -230,7 +230,7 @@ func BuildDict(o BuildDictOptions) ([]byte, error) { } block := blockEnc{lowMem: false} block.init() - enc := encoder(&bestFastEncoder{fastBase: fastBase{maxMatchOff: int32(maxMatchLen), bufferReset: math.MaxInt32 - int32(maxMatchLen*2), lowMem: false}}) + var enc encoder if o.Level != 0 { eOpts := encoderOptions{ level: o.Level, @@ -242,6 +242,7 @@ func BuildDict(o BuildDictOptions) ([]byte, error) { enc = eOpts.encoder() } else { o.Level = SpeedBestCompression + enc = encoder(&bestFastEncoder{fastBase: fastBase{maxMatchOff: int32(maxMatchLen), bufferReset: math.MaxInt32 - int32(maxMatchLen*2), lowMem: false}}) } var ( remain [256]int diff --git a/vendor/github.com/klauspost/compress/zstd/enc_base.go b/vendor/github.com/klauspost/compress/zstd/enc_base.go index c4de134a7..c4fea575d 100644 --- a/vendor/github.com/klauspost/compress/zstd/enc_base.go +++ b/vendor/github.com/klauspost/compress/zstd/enc_base.go @@ -128,6 +128,34 @@ func (e *fastBase) matchlen(s, t int32, src []byte) int32 { return int32(matchLen(src[s:], src[t:])) } +// resetBasePrefix resets the encoder state and loads prefix as initial history. +// This is used for parallel job encoding where non-first jobs need overlap context. +// Rep offsets are set to defaults [1,4,8] (invalidated, matching C behavior). +func (e *fastBase) resetBasePrefix(prefix []byte) { + if e.blk == nil { + e.blk = &blockEnc{lowMem: e.lowMem} + e.blk.init() + } else { + e.blk.reset(nil) + } + e.blk.initNewEncode() + if e.crc == nil { + e.crc = xxhash.New() + } else { + e.crc.Reset() + } + e.blk.dictLitEnc = nil + e.ensureHist(len(prefix) + maxCompressedBlockSize) + // Bump cur so old table entries fall outside the window. + // When cur >= bufferReset, leave it; the first Encode call + // will shift/clear tables, preserving valid prefix entries. + if e.cur < e.bufferReset { + e.cur += e.maxMatchOff + int32(len(e.hist)) + } + e.hist = e.hist[:0] + e.hist = append(e.hist, prefix...) +} + // Reset the encoding table. func (e *fastBase) resetBase(d *dict, singleBlock bool) { if e.blk == nil { diff --git a/vendor/github.com/klauspost/compress/zstd/enc_best.go b/vendor/github.com/klauspost/compress/zstd/enc_best.go index 851799322..c71382dde 100644 --- a/vendor/github.com/klauspost/compress/zstd/enc_best.go +++ b/vendor/github.com/klauspost/compress/zstd/enc_best.go @@ -551,3 +551,18 @@ func (e *bestFastEncoder) Reset(d *dict, singleBlock bool) { // Reset table to initial state copy(e.table[:], e.dictTable) } + +func (e *bestFastEncoder) ResetPrefix(prefix []byte) { + e.resetBasePrefix(prefix) + if len(prefix) < 8 { + return + } + end := e.cur + int32(len(prefix)) - 8 + for i := e.cur; i < end; i++ { + cv := load6432(prefix, i-e.cur) + h := hashLen(cv, bestLongTableBits, bestLongLen) + e.longTable[h] = prevEntry{offset: i, prev: e.longTable[h].offset} + h0 := hashLen(cv, bestShortTableBits, bestShortLen) + e.table[h0] = prevEntry{offset: i, prev: e.table[h0].offset} + } +} diff --git a/vendor/github.com/klauspost/compress/zstd/enc_better.go b/vendor/github.com/klauspost/compress/zstd/enc_better.go index 3305f0924..523d57f3a 100644 --- a/vendor/github.com/klauspost/compress/zstd/enc_better.go +++ b/vendor/github.com/klauspost/compress/zstd/enc_better.go @@ -1096,6 +1096,20 @@ func (e *betterFastEncoder) Reset(d *dict, singleBlock bool) { } } +func (e *betterFastEncoder) ResetPrefix(prefix []byte) { + e.resetBasePrefix(prefix) + if len(prefix) < 8 { + return + } + end := e.cur + int32(len(prefix)) - 8 + for i := e.cur; i < end; i += 2 { + cv := load6432(prefix, i-e.cur) + h := hashLen(cv, betterLongTableBits, betterLongLen) + e.longTable[h] = prevEntry{offset: i, prev: e.longTable[h].offset} + e.table[hashLen(cv>>8, betterShortTableBits, betterShortLen)] = tableEntry{val: uint32(cv >> 8), offset: i + 1} + } +} + // ResetDict will reset and set a dictionary if not nil func (e *betterFastEncoderDict) Reset(d *dict, singleBlock bool) { e.resetBase(d, singleBlock) @@ -1229,6 +1243,10 @@ func (e *betterFastEncoderDict) Reset(d *dict, singleBlock bool) { e.allDirty = false } +func (e *betterFastEncoderDict) ResetPrefix([]byte) { + panic("ResetPrefix not supported for dict encoders") +} + func (e *betterFastEncoderDict) markLongShardDirty(entryNum uint32) { e.longTableShardDirty[entryNum/betterLongTableShardSize] = true } diff --git a/vendor/github.com/klauspost/compress/zstd/enc_dfast.go b/vendor/github.com/klauspost/compress/zstd/enc_dfast.go index 2fb6da112..712ba7ab5 100644 --- a/vendor/github.com/klauspost/compress/zstd/enc_dfast.go +++ b/vendor/github.com/klauspost/compress/zstd/enc_dfast.go @@ -1037,6 +1037,18 @@ func (e *doubleFastEncoder) Reset(d *dict, singleBlock bool) { } } +func (e *doubleFastEncoder) ResetPrefix(prefix []byte) { + e.fastEncoder.ResetPrefix(prefix) + if len(prefix) < 8 { + return + } + end := e.cur + int32(len(prefix)) - 8 + for i := e.cur + 1; i < end; i += 2 { + cv := load6432(prefix, i-e.cur) + e.longTable[hashLen(cv, dFastLongTableBits, dFastLongLen)] = tableEntry{val: uint32(cv), offset: i} + } +} + // ResetDict will reset and set a dictionary if not nil func (e *doubleFastEncoderDict) Reset(d *dict, singleBlock bool) { allDirty := e.allDirty @@ -1102,6 +1114,10 @@ func (e *doubleFastEncoderDict) Reset(d *dict, singleBlock bool) { } } +func (e *doubleFastEncoderDict) ResetPrefix([]byte) { + panic("ResetPrefix not supported for dict encoders") +} + func (e *doubleFastEncoderDict) markLongShardDirty(entryNum uint32) { e.longTableShardDirty[entryNum/dLongTableShardSize] = true } diff --git a/vendor/github.com/klauspost/compress/zstd/enc_fast.go b/vendor/github.com/klauspost/compress/zstd/enc_fast.go index 5e104f1a4..06045e246 100644 --- a/vendor/github.com/klauspost/compress/zstd/enc_fast.go +++ b/vendor/github.com/klauspost/compress/zstd/enc_fast.go @@ -797,6 +797,19 @@ func (e *fastEncoder) Reset(d *dict, singleBlock bool) { } } +func (e *fastEncoder) ResetPrefix(prefix []byte) { + e.resetBasePrefix(prefix) + if len(prefix) < 8 { + return + } + end := e.cur + int32(len(prefix)) - 8 + // Index every 4th + for i := e.cur + 1; i < end; i += 4 { + cv := load6432(prefix, i-e.cur) + e.table[hashLen(cv, tableBits, tableFastHashLen)] = tableEntry{val: uint32(cv), offset: i} + } +} + // ResetDict will reset and set a dictionary if not nil func (e *fastEncoderDict) Reset(d *dict, singleBlock bool) { e.resetBase(d, singleBlock) @@ -866,6 +879,10 @@ func (e *fastEncoderDict) Reset(d *dict, singleBlock bool) { e.allDirty = false } +func (e *fastEncoderDict) ResetPrefix([]byte) { + panic("ResetPrefix not supported for dict encoders") +} + func (e *fastEncoderDict) markAllShardsDirty() { e.allDirty = true } diff --git a/vendor/github.com/klauspost/compress/zstd/enc_jobs.go b/vendor/github.com/klauspost/compress/zstd/enc_jobs.go new file mode 100644 index 000000000..95ce67ac0 --- /dev/null +++ b/vendor/github.com/klauspost/compress/zstd/enc_jobs.go @@ -0,0 +1,352 @@ +// Copyright 2019+ Klaus Post. All rights reserved. +// License information can be found in the LICENSE file. +// Based on work by Yann Collet, released under BSD License. + +package zstd + +import ( + "fmt" + rdebug "runtime/debug" + "sync" +) + +type encJob struct { + prefix []byte // overlap from previous job (nil for first) + input []byte // job's own input data (swapped from filling) + last bool // last block of last job gets last=true + output []byte // compressed blocks (filled by worker) + err error // encoding error + done chan struct{} // closed when complete +} + +type jobState struct { + jobSize int + overlapSize int + filling []byte // accumulates input up to jobSize + nextPrefix []byte // overlap prefix prepared for the next dispatched job + + jobSeq int // next job sequence number + + jobCh chan *encJob // dispatch to workers + resultCh chan *encJob // ordered results to flusher + + workerWg sync.WaitGroup + flusherWg sync.WaitGroup + + mu sync.Mutex + flushedSeq int // last flushed sequence number + cond *sync.Cond + + flusherErr error + started bool + + inputPool sync.Pool // *[]byte buffers of jobSize cap + outputPool sync.Pool // *[]byte buffers for compressed output + overlapPool sync.Pool // *[]byte buffers for overlap prefixes +} + +func (e *Encoder) startJobWorkers() { + js := &e.state.jobs + n := e.o.concurrent + js.jobCh = make(chan *encJob, n) + js.resultCh = make(chan *encJob, n) + js.flushedSeq = 0 + js.cond = sync.NewCond(&js.mu) + + // Workers borrow encoders from the shared e.encoders pool per-job. + // Ensure the pool is initialized before any worker tries to borrow. + e.init.Do(e.initialize) + + for range n { + js.workerWg.Add(1) + go e.jobWorker() + } + js.flusherWg.Add(1) + go e.jobFlusher() + js.started = true +} + +func (e *Encoder) jobWorker() { + js := &e.state.jobs + defer js.workerWg.Done() + for job := range js.jobCh { + enc := <-e.encoders + e.compressJob(enc, job) + e.encoders <- enc + close(job.done) + } +} + +func (e *Encoder) compressJob(enc encoder, job *encJob) { + defer func() { + if r := recover(); r != nil { + job.err = fmt.Errorf("panic in parallel job: %v", r) + rdebug.PrintStack() + } + }() + + if len(job.prefix) > 0 { + enc.ResetPrefix(job.prefix) + } else { + enc.Reset(nil, false) + } + + data := job.input + if len(data) == 0 && job.last { + blk := enc.Block() + blk.reset(nil) + blk.last = true + blk.encodeRaw(nil) + job.output = append(job.output, blk.output...) + return + } + + blk := enc.Block() + for len(data) > 0 { + todo := data + if len(todo) > e.o.blockSize { + todo = todo[:e.o.blockSize] + } + data = data[len(todo):] + + blk.pushOffsets() + enc.Encode(blk, todo) + blk.last = len(data) == 0 && job.last + + err := blk.encode(todo, e.o.noEntropy, !e.o.allLitEntropy) + if err != nil { + job.err = err + return + } + job.output = append(job.output, blk.output...) + blk.reset(nil) + } +} + +func (js *jobState) getInputBuf(size int) []byte { + if v := js.inputPool.Get(); v != nil { + bp := v.(*[]byte) + b := *bp + if cap(b) >= size { + return b[:0] + } + } + return make([]byte, 0, size) +} + +func (js *jobState) putInputBuf(b []byte) { + if cap(b) > 0 { + b = b[:0] + js.inputPool.Put(&b) + } +} + +func (js *jobState) getOutputBuf(size int) []byte { + if v := js.outputPool.Get(); v != nil { + bp := v.(*[]byte) + b := *bp + if cap(b) >= size { + return b[:0] + } + } + return make([]byte, 0, size) +} + +func (js *jobState) putOutputBuf(b []byte) { + if cap(b) > 0 { + b = b[:0] + js.outputPool.Put(&b) + } +} + +func (js *jobState) getOverlapBuf(size int) []byte { + if v := js.overlapPool.Get(); v != nil { + bp := v.(*[]byte) + b := *bp + if cap(b) >= size { + return b[:size] + } + } + return make([]byte, size) +} + +func (js *jobState) putOverlapBuf(b []byte) { + if cap(b) > 0 { + b = b[:0] + js.overlapPool.Put(&b) + } +} + +func (e *Encoder) jobFlusher() { + js := &e.state.jobs + defer js.flusherWg.Done() + for job := range js.resultCh { + <-job.done + // Worker has fully exited compressJob, so the prefix is no longer + // in use. Return it to the pool regardless of outcome. + if job.prefix != nil { + js.putOverlapBuf(job.prefix) + job.prefix = nil + } + if job.err != nil { + js.mu.Lock() + js.flusherErr = job.err + js.cond.Broadcast() + js.mu.Unlock() + for range js.resultCh { + } + return + } + if len(job.output) > 0 { + _, err := e.state.w.Write(job.output) + if err != nil { + js.mu.Lock() + js.flusherErr = err + js.cond.Broadcast() + js.mu.Unlock() + for range js.resultCh { + } + return + } + e.state.nWritten += int64(len(job.output)) + } + // Return buffers to pools. + js.putInputBuf(job.input) + js.putOutputBuf(job.output) + job.input = nil + job.output = nil + + js.mu.Lock() + js.flushedSeq++ + js.cond.Broadcast() + js.mu.Unlock() + } +} + +func (e *Encoder) shutdownJobWorkers() { + js := &e.state.jobs + if !js.started { + return + } + close(js.jobCh) + js.workerWg.Wait() + close(js.resultCh) + js.flusherWg.Wait() + js.started = false +} + +// waitAllJobs blocks until all dispatched jobs have been flushed. +func (e *Encoder) waitAllJobs() { + js := &e.state.jobs + if !js.started { + return + } + js.mu.Lock() + for js.flushedSeq < js.jobSeq && js.flusherErr == nil { + js.cond.Wait() + } + js.mu.Unlock() +} + +func (e *Encoder) dispatchJob(final bool) error { + s := &e.state + js := &s.jobs + + js.mu.Lock() + fErr := js.flusherErr + js.mu.Unlock() + if fErr != nil { + return fErr + } + + if !s.headerWritten { + // Single-block optimization: fall through to encodeAll path. + if final && len(js.filling) > 0 && len(js.filling) <= e.o.blockSize { + s.current = e.encodeAll(s.encoder, js.filling, s.current[:0]) + var n2 int + n2, s.err = s.w.Write(s.current) + if s.err != nil { + return s.err + } + s.nWritten += int64(n2) + s.nInput += int64(len(js.filling)) + s.current = s.current[:0] + js.filling = js.filling[:0] + s.headerWritten = true + s.fullFrameWritten = true + s.eofWritten = true + return nil + } + if final && len(js.filling) == 0 && !e.o.fullZero { + s.headerWritten = true + s.fullFrameWritten = true + s.eofWritten = true + return nil + } + + var tmp [maxHeaderSize]byte + fh := frameHeader{ + ContentSize: uint64(s.frameContentSize), + WindowSize: uint32(s.encoder.WindowSize(s.frameContentSize)), + SingleSegment: false, + Checksum: e.o.crc, + DictID: 0, + } + dst := fh.appendTo(tmp[:0]) + var n2 int + n2, s.err = s.w.Write(dst) + if s.err != nil { + return s.err + } + s.nWritten += int64(n2) + s.headerWritten = true + } + + if len(js.filling) == 0 && !final { + return nil + } + + if !js.started { + e.startJobWorkers() + } + + // Estimate output size for pooled buffer. + outputEst := max(len(js.filling)/2, 512) + + job := &encJob{ + last: final, + done: make(chan struct{}), + output: js.getOutputBuf(outputEst), + } + + // Each job owns its prefix slice; the flusher returns it to the pool + // after <-job.done, so workers and dispatch never share a buffer. + if js.nextPrefix != nil { + job.prefix = js.nextPrefix + js.nextPrefix = nil + } + + // Build the next job's prefix from the tail of this job's input. + if !final && len(js.filling) > 0 { + overlapLen := min(js.overlapSize, len(js.filling)) + np := js.getOverlapBuf(overlapLen) + copy(np, js.filling[len(js.filling)-overlapLen:]) + js.nextPrefix = np + } + + // Swap filling buffer into job — zero-copy for the input data. + job.input = js.filling + js.filling = js.getInputBuf(js.jobSize) + + s.nInput += int64(len(job.input)) + js.jobSeq++ + + if final { + s.eofWritten = true + } + + js.resultCh <- job + js.jobCh <- job + + return nil +} diff --git a/vendor/github.com/klauspost/compress/zstd/encoder.go b/vendor/github.com/klauspost/compress/zstd/encoder.go index 0f2a00a00..6ee96d873 100644 --- a/vendor/github.com/klauspost/compress/zstd/encoder.go +++ b/vendor/github.com/klauspost/compress/zstd/encoder.go @@ -38,6 +38,7 @@ type encoder interface { WindowSize(size int64) int32 UseBlock(*blockEnc) Reset(d *dict, singleBlock bool) + ResetPrefix(prefix []byte) } type encoderState struct { @@ -60,6 +61,9 @@ type encoderState struct { wg sync.WaitGroup // This waitgroup indicates we have a block encoding/writing. wWg sync.WaitGroup + + // Parallel job state (used when concurrentBlocks is enabled). + jobs jobState } // NewWriter will create a new Zstandard encoder. @@ -74,6 +78,9 @@ func NewWriter(w io.Writer, opts ...EOption) (*Encoder, error) { return nil, err } } + if e.o.concurrentBlocks && (e.o.dict != nil || e.o.concurrent <= 1) { + e.o.concurrentBlocks = false + } if w != nil { e.Reset(w) } @@ -95,12 +102,31 @@ func (e *Encoder) initialize() { // as a new, independent stream. func (e *Encoder) Reset(w io.Writer) { s := &e.state + + if e.o.concurrentBlocks { + e.shutdownJobWorkers() + js := &s.jobs + js.jobSize = e.o.jobSize() + js.overlapSize = e.o.overlapSize() + // js.filling is allocated lazily on first Write/ReadFrom so callers + // that only use EncodeAll don't pay the (up to ~32 MB) jobSize cost. + js.filling = js.filling[:0] + if js.nextPrefix != nil { + js.putOverlapBuf(js.nextPrefix) + js.nextPrefix = nil + } + js.jobSeq = 0 + js.flushedSeq = 0 + js.flusherErr = nil + js.started = false + } + s.wg.Wait() s.wWg.Wait() if cap(s.filling) == 0 { s.filling = make([]byte, 0, e.o.blockSize) } - if e.o.concurrent > 1 { + if e.o.concurrent > 1 && !e.o.concurrentBlocks { if cap(s.current) == 0 { s.current = make([]byte, 0, e.o.blockSize) } @@ -145,6 +171,9 @@ func (e *Encoder) ResetWithOptions(w io.Writer, opts ...EOption) error { } } hasDict := e.o.dict != nil + if e.o.concurrentBlocks && hasDict { + e.o.concurrentBlocks = false + } if hadDict != hasDict { // Dict presence changed — encoder type must be recreated. e.state.encoder = nil @@ -176,6 +205,49 @@ func (e *Encoder) Write(p []byte) (n int, err error) { if s.eofWritten { return 0, ErrEncoderClosed } + if e.o.concurrentBlocks { + return e.writeJobs(p) + } + return e.writeBlocks(p) +} + +func (e *Encoder) writeJobs(p []byte) (n int, err error) { + s := &e.state + js := &s.jobs + jobSize := js.jobSize + if cap(js.filling) == 0 && len(p) > 0 { + js.filling = make([]byte, 0, jobSize) + } + for len(p) > 0 { + if len(p)+len(js.filling) < jobSize { + if e.o.crc { + _, _ = s.encoder.CRC().Write(p) + } + js.filling = append(js.filling, p...) + return n + len(p), nil + } + add := p + if len(p)+len(js.filling) > jobSize { + add = add[:jobSize-len(js.filling)] + } + if e.o.crc { + _, _ = s.encoder.CRC().Write(add) + } + js.filling = append(js.filling, add...) + p = p[len(add):] + n += len(add) + if len(js.filling) < jobSize { + return n, nil + } + if err := e.dispatchJob(false); err != nil { + return n, err + } + } + return n, nil +} + +func (e *Encoder) writeBlocks(p []byte) (n int, err error) { + s := &e.state for len(p) > 0 { if len(p)+len(s.filling) < e.o.blockSize { if e.o.crc { @@ -374,6 +446,10 @@ func (e *Encoder) ReadFrom(r io.Reader) (n int64, err error) { println("Using ReadFrom") } + if e.o.concurrentBlocks { + return e.readFromJobs(r) + } + // Flush any current writes. if len(e.state.filling) > 0 { if err := e.nextBlock(false); err != nil { @@ -387,7 +463,6 @@ func (e *Encoder) ReadFrom(r io.Reader) (n int64, err error) { if e.o.crc { _, _ = e.state.encoder.CRC().Write(src[:n2]) } - // src is now the unfilled part... src = src[n2:] n += int64(n2) switch err { @@ -420,15 +495,63 @@ func (e *Encoder) ReadFrom(r io.Reader) (n int64, err error) { } } +func (e *Encoder) readFromJobs(r io.Reader) (n int64, err error) { + js := &e.state.jobs + jobSize := js.jobSize + + // Flush any current filling. + if len(js.filling) > 0 { + if err := e.dispatchJob(false); err != nil { + return 0, err + } + } + + if cap(js.filling) < jobSize { + js.filling = make([]byte, 0, jobSize) + } + js.filling = js.filling[:jobSize] + src := js.filling + for { + n2, err := r.Read(src) + if e.o.crc { + _, _ = e.state.encoder.CRC().Write(src[:n2]) + } + src = src[n2:] + n += int64(n2) + switch err { + case io.EOF: + js.filling = js.filling[:len(js.filling)-len(src)] + return n, nil + case nil: + default: + e.state.err = err + return n, err + } + if len(src) > 0 { + continue + } + if err = e.dispatchJob(false); err != nil { + return n, err + } + if cap(js.filling) < jobSize { + js.filling = make([]byte, 0, jobSize) + } + js.filling = js.filling[:jobSize] + src = js.filling + } +} + // Flush will send the currently written data to output // and block until everything has been written. // This should only be used on rare occasions where pushing the currently queued data is critical. func (e *Encoder) Flush() error { s := &e.state + if e.o.concurrentBlocks { + return e.flushJobs() + } if len(s.filling) > 0 { err := e.nextBlock(false) if err != nil { - // Ignore Flush after Close. if errors.Is(s.err, ErrEncoderClosed) { return nil } @@ -438,7 +561,6 @@ func (e *Encoder) Flush() error { s.wg.Wait() s.wWg.Wait() if s.err != nil { - // Ignore Flush after Close. if errors.Is(s.err, ErrEncoderClosed) { return nil } @@ -447,6 +569,20 @@ func (e *Encoder) Flush() error { return s.writeErr } +func (e *Encoder) flushJobs() error { + js := &e.state.jobs + if len(js.filling) > 0 { + if err := e.dispatchJob(false); err != nil { + return err + } + } + e.waitAllJobs() + js.mu.Lock() + fErr := js.flusherErr + js.mu.Unlock() + return fErr +} + // Close will flush the final output and close the stream. // The function will block until everything has been written. // The Encoder can still be re-used after calling this. @@ -455,12 +591,16 @@ func (e *Encoder) Close() error { if s.encoder == nil { return nil } + if e.o.concurrentBlocks { + return e.closeJobs() + } if s.w == nil { if len(s.filling) == 0 && !s.headerWritten && !s.eofWritten && s.nInput == 0 { return nil } return errors.New("zstd: encoder has no writer") } + err := e.nextBlock(true) if err != nil { if errors.Is(s.err, ErrEncoderClosed) { @@ -511,6 +651,68 @@ func (e *Encoder) Close() error { return s.err } +func (e *Encoder) closeJobs() error { + s := &e.state + js := &s.jobs + + if errors.Is(s.err, ErrEncoderClosed) { + return nil + } + + if s.w == nil { + if len(js.filling) == 0 && !s.headerWritten && !s.eofWritten && s.nInput == 0 { + return nil + } + return errors.New("zstd: encoder has no writer") + } + + if err := e.dispatchJob(true); err != nil { + e.shutdownJobWorkers() + if errors.Is(s.err, ErrEncoderClosed) { + return nil + } + return err + } + + if s.frameContentSize > 0 && s.nInput != s.frameContentSize { + e.shutdownJobWorkers() + return fmt.Errorf("frame content size %d given, but %d bytes was written", s.frameContentSize, s.nInput) + } + + if s.fullFrameWritten { + e.shutdownJobWorkers() + s.err = ErrEncoderClosed + return nil + } + + e.shutdownJobWorkers() + if js.flusherErr != nil { + return js.flusherErr + } + + // Write CRC + if e.o.crc { + var tmp [4]byte + _, s.err = s.w.Write(s.encoder.AppendCRC(tmp[:0])) + s.nWritten += 4 + } + + // Add padding + if s.err == nil && e.o.pad > 0 { + add := calcSkippableFrame(s.nWritten, int64(e.o.pad)) + frame, err := skippableFrame(js.filling[:0], add, rand.Reader) + if err != nil { + return err + } + _, s.err = s.w.Write(frame) + } + if s.err == nil { + s.err = ErrEncoderClosed + return nil + } + return s.err +} + // EncodeAll will encode all input in src and append it to dst. // This function can be called concurrently, but each call will only run on a single goroutine. // If empty input is given, nothing is returned, unless WithZeroFrames is specified. diff --git a/vendor/github.com/klauspost/compress/zstd/encoder_options.go b/vendor/github.com/klauspost/compress/zstd/encoder_options.go index e217be0a1..a80814967 100644 --- a/vendor/github.com/klauspost/compress/zstd/encoder_options.go +++ b/vendor/github.com/klauspost/compress/zstd/encoder_options.go @@ -14,22 +14,23 @@ type EOption func(*encoderOptions) error // options retains accumulated state of multiple options. type encoderOptions struct { - resetOpt bool - concurrent int - level EncoderLevel - single *bool - pad int - blockSize int - windowSize int - crc bool - fullZero bool - noEntropy bool - allLitEntropy bool - customWindow bool - customALEntropy bool - customBlockSize bool - lowMem bool - dict *dict + resetOpt bool + concurrent int + level EncoderLevel + single *bool + pad int + blockSize int + windowSize int + crc bool + fullZero bool + noEntropy bool + allLitEntropy bool + customWindow bool + customALEntropy bool + customBlockSize bool + lowMem bool + dict *dict + concurrentBlocks bool } func (o *encoderOptions) setDefault() { @@ -333,6 +334,42 @@ func WithLowerEncoderMem(b bool) EOption { } } +// WithConcurrentBlocks enables job-based parallel compression for streams. +// When enabled and concurrent > 1, input is split into large sections (jobs) +// that are compressed simultaneously by multiple goroutines. +// Each non-first job receives an overlap prefix from the previous job for match context. +// Output is flushed in order, producing a valid single-frame zstd stream. +// +// Currently disabled when used with dictionary encoding. +// Cannot be changed with ResetWithOptions. +func WithConcurrentBlocks(b bool) EOption { + return func(o *encoderOptions) error { + if o.resetOpt && b != o.concurrentBlocks { + return errors.New("WithConcurrentBlocks cannot be changed on Reset") + } + o.concurrentBlocks = b + return nil + } +} + +// jobSize returns the input section size per parallel job. +func (o *encoderOptions) jobSize() int { + s := max(o.windowSize*4, 512<<10) + return s +} + +// overlapSize returns the overlap prefix size for parallel jobs. +func (o *encoderOptions) overlapSize() int { + switch o.level { + case SpeedBestCompression: + return o.windowSize / 2 + case SpeedBetterCompression: + return o.windowSize / 4 + default: + return o.windowSize / 8 + } +} + // WithEncoderDict allows to register a dictionary that will be used for the encode. // // The slice dict must be in the [dictionary format] produced by diff --git a/vendor/github.com/klauspost/compress/zstd/fse_decoder_amd64.s b/vendor/github.com/klauspost/compress/zstd/fse_decoder_amd64.s index bcde39869..deeadc49e 100644 --- a/vendor/github.com/klauspost/compress/zstd/fse_decoder_amd64.s +++ b/vendor/github.com/klauspost/compress/zstd/fse_decoder_amd64.s @@ -1,4 +1,4 @@ -// Code generated by command: go run gen_fse.go -out ../fse_decoder_amd64.s -pkg=zstd. DO NOT EDIT. +// Code generated by command: go run gen_fse.go -out ../fse_decoder.s -arch amd64,arm64 -pkg=zstd. DO NOT EDIT. //go:build !appengine && !noasm && gc && !noasm diff --git a/vendor/github.com/klauspost/compress/zstd/fse_decoder_arm64.s b/vendor/github.com/klauspost/compress/zstd/fse_decoder_arm64.s new file mode 100644 index 000000000..661761fb2 --- /dev/null +++ b/vendor/github.com/klauspost/compress/zstd/fse_decoder_arm64.s @@ -0,0 +1,146 @@ +// Code generated by command: go run gen_fse.go -out ../fse_decoder.s -arch amd64,arm64 -pkg=zstd. DO NOT EDIT. +// EXPERIMENTAL arm64 output lowered from an amd64 avo program. + +//go:build arm64 && !appengine && !noasm && gc && !noasm + +// func buildDtable_asm(s *fseDecoder, ctx *buildDtableAsmContext) int +TEXT ·buildDtable_asm(SB), $0-24 + MOVD ctx+8(FP), R1 + MOVD s+0(FP), R6 + + // Load values + MOVBU 4098(R6), R2 + MOVD $0, R0 + MOVD $1, R16 + LSL R2, R16, R16 + ORR R16, R0, R0 + MOVD (R1), R3 + MOVD 16(R1), R5 + SUB $1, R0, R7 + MOVD 8(R1), R1 + MOVHU 4096(R6), R6 + + // End load values + // Init, lay down lowprob symbols + MOVD $0, R8 + JMP init_main_loop_condition + +init_main_loop: + ADD R8<<1, R1, R15 + MOVH (R15), R9 + CMN $1, R9 + BNE do_not_update_high_threshold + ADD R7<<3, R5, R15 + MOVB R8, 1(R15) + SUB $1, R7, R7 + MOVD $0x0000000000000001, R9 + +do_not_update_high_threshold: + ADD R8<<1, R3, R15 + MOVH R9, (R15) + ADD $1, R8, R8 + +init_main_loop_condition: + CMP R6, R8 + BLT init_main_loop + + // Spread symbols + // Calculate table step + MOVD R0, R8 + LSR $0x01, R8, R8 + MOVD R0, R9 + LSR $0x03, R9, R9 + ADD R9, R8, R8 + ADD $3, R8, R8 + + // Fill add bits values + SUB $1, R0, R9 + MOVD $0, R10 + MOVD $0, R11 + JMP spread_main_loop_condition + +spread_main_loop: + MOVD $0, R12 + ADD R11<<1, R1, R15 + MOVH (R15), R13 + JMP spread_inner_loop_condition + +spread_inner_loop: + ADD R10<<3, R5, R15 + MOVB R11, 1(R15) + +adjust_position: + ADD R8, R10, R10 + AND R9, R10, R10 + CMP R7, R10 + BGT adjust_position + ADD $1, R12, R12 + +spread_inner_loop_condition: + CMP R13, R12 + BLT spread_inner_loop + ADD $1, R11, R11 + +spread_main_loop_condition: + CMP R6, R11 + BLT spread_main_loop + TST R10, R10 + BEQ spread_check_ok + MOVD ctx+8(FP), R0 + MOVD R10, 24(R0) + MOVD $+1, R16 + MOVD R16, ret+16(FP) + RET + +spread_check_ok: + // Build Decoding table + MOVD $0, R6 + +build_table_main_table: + ADD R6<<3, R5, R15 + MOVBU 1(R15), R1 + ADD R1<<1, R3, R15 + MOVHU (R15), R7 + ADD $1, R7, R8 + ADD R1<<1, R3, R15 + MOVH R8, (R15) + MOVD R7, R8 + CLZ R8, R16 + MOVD $63, R8 + SUB R16, R8, R8 + MOVD R2, R1 + SUB R8, R1, R1 + LSL R1, R7, R7 + SUB R0, R7, R7 + ADD R6<<3, R5, R15 + MOVB R1, (R15) + ADD R6<<3, R5, R15 + MOVH R7, 2(R15) + CMP R0, R7 + BLE build_table_check1_ok + MOVD ctx+8(FP), R1 + MOVD R7, 24(R1) + MOVD R0, 32(R1) + MOVD $+2, R16 + MOVD R16, ret+16(FP) + RET + +build_table_check1_ok: + TST R1, R1 + BNE build_table_check2_ok + CMP R6, R7 + BNE build_table_check2_ok + MOVD ctx+8(FP), R0 + MOVD R7, 24(R0) + MOVD R6, 32(R0) + MOVD $+3, R16 + MOVD R16, ret+16(FP) + RET + +build_table_check2_ok: + ADD $1, R6, R6 + CMP R0, R6 + BLT build_table_main_table + MOVD $+0, R16 + MOVD R16, ret+16(FP) + RET diff --git a/vendor/github.com/klauspost/compress/zstd/fse_decoder_amd64.go b/vendor/github.com/klauspost/compress/zstd/fse_decoder_asm.go similarity index 81% rename from vendor/github.com/klauspost/compress/zstd/fse_decoder_amd64.go rename to vendor/github.com/klauspost/compress/zstd/fse_decoder_asm.go index b8c8607b5..4ffc7e3c9 100644 --- a/vendor/github.com/klauspost/compress/zstd/fse_decoder_amd64.go +++ b/vendor/github.com/klauspost/compress/zstd/fse_decoder_asm.go @@ -1,4 +1,4 @@ -//go:build amd64 && !appengine && !noasm && gc +//go:build (amd64 || arm64) && !appengine && !noasm && gc package zstd @@ -6,6 +6,10 @@ import ( "fmt" ) +// buildDtable_asm is generated by _generate/gen_fse.go and lowered to each +// architecture (amd64 by goasm, arm64 by the avo arm64 lowering printer). The +// Go side is identical across architectures, so it lives here. + type buildDtableAsmContext struct { // inputs stateTable *uint16 @@ -18,7 +22,7 @@ type buildDtableAsmContext struct { errParam2 uint64 } -// buildDtable_asm is an x86 assembly implementation of fseDecoder.buildDtable. +// buildDtable_asm is an assembly implementation of fseDecoder.buildDtable. // Function returns non-zero exit code on error. // //go:noescape diff --git a/vendor/github.com/klauspost/compress/zstd/fse_decoder_generic.go b/vendor/github.com/klauspost/compress/zstd/fse_decoder_generic.go index 2138f8091..38fd2ccb2 100644 --- a/vendor/github.com/klauspost/compress/zstd/fse_decoder_generic.go +++ b/vendor/github.com/klauspost/compress/zstd/fse_decoder_generic.go @@ -1,4 +1,4 @@ -//go:build !amd64 || appengine || !gc || noasm +//go:build (!amd64 && !arm64) || appengine || !gc || noasm package zstd diff --git a/vendor/github.com/klauspost/compress/zstd/seqdec_amd64.go b/vendor/github.com/klauspost/compress/zstd/seqdec_amd64.go index 18c3703dd..1281da885 100644 --- a/vendor/github.com/klauspost/compress/zstd/seqdec_amd64.go +++ b/vendor/github.com/klauspost/compress/zstd/seqdec_amd64.go @@ -3,321 +3,83 @@ package zstd import ( - "fmt" - "io" - "github.com/klauspost/compress/internal/cpuinfo" ) -type decodeSyncAsmContext struct { - llTable []decSymbol - mlTable []decSymbol - ofTable []decSymbol - llState uint64 - mlState uint64 - ofState uint64 - iteration int - litRemain int - out []byte - outPosition int - literals []byte - litPosition int - history []byte - windowSize int - ll int // set on error (not for all errors, please refer to _generate/gen.go) - ml int // set on error (not for all errors, please refer to _generate/gen.go) - mo int // set on error (not for all errors, please refer to _generate/gen.go) -} +// The shared decode/decodeSync/executeSimple wrappers and context structs live +// in seqdec_asm.go; this file only declares the amd64 asm routines and the +// dispatch helpers that pick the BMI2 / non-BMI2 (and 56-bit / safe) variant. -// sequenceDecs_decodeSync_amd64 implements the main loop of sequenceDecs.decodeSync in x86 asm. +// sequenceDecs_decode implements the main loop of sequenceDecs in x86 asm. // // Please refer to seqdec_generic.go for the reference implementation. // //go:noescape -func sequenceDecs_decodeSync_amd64(s *sequenceDecs, br *bitReader, ctx *decodeSyncAsmContext) int +func sequenceDecs_decode_amd64(s *sequenceDecs, br *bitReader, ctx *decodeAsmContext) int -// sequenceDecs_decodeSync_bmi2 implements the main loop of sequenceDecs.decodeSync in x86 asm with BMI2 extensions. +// sequenceDecs_decode_56_amd64 implements the main loop of sequenceDecs in x86 asm. // //go:noescape -func sequenceDecs_decodeSync_bmi2(s *sequenceDecs, br *bitReader, ctx *decodeSyncAsmContext) int +func sequenceDecs_decode_56_amd64(s *sequenceDecs, br *bitReader, ctx *decodeAsmContext) int -// sequenceDecs_decodeSync_safe_amd64 does the same as above, but does not write more than output buffer. +// sequenceDecs_decode_bmi2 implements the main loop of sequenceDecs in x86 asm with BMI2 extensions. // //go:noescape -func sequenceDecs_decodeSync_safe_amd64(s *sequenceDecs, br *bitReader, ctx *decodeSyncAsmContext) int +func sequenceDecs_decode_bmi2(s *sequenceDecs, br *bitReader, ctx *decodeAsmContext) int -// sequenceDecs_decodeSync_safe_bmi2 does the same as above, but does not write more than output buffer. +// sequenceDecs_decode_56_bmi2 implements the main loop of sequenceDecs in x86 asm with BMI2 extensions. // //go:noescape -func sequenceDecs_decodeSync_safe_bmi2(s *sequenceDecs, br *bitReader, ctx *decodeSyncAsmContext) int - -// decode sequences from the stream with the provided history but without a dictionary. -func (s *sequenceDecs) decodeSyncSimple(hist []byte) (bool, error) { - if len(s.dict) > 0 { - return false, nil - } - if s.maxSyncLen == 0 && cap(s.out)-len(s.out) < maxCompressedBlockSize { - return false, nil - } - - // FIXME: Using unsafe memory copies leads to rare, random crashes - // with fuzz testing. It is therefore disabled for now. - const useSafe = true - /* - useSafe := false - if s.maxSyncLen == 0 && cap(s.out)-len(s.out) < maxCompressedBlockSizeAlloc { - useSafe = true - } - if s.maxSyncLen > 0 && cap(s.out)-len(s.out)-compressedBlockOverAlloc < int(s.maxSyncLen) { - useSafe = true - } - if cap(s.literals) < len(s.literals)+compressedBlockOverAlloc { - useSafe = true - } - */ - - br := s.br - - maxBlockSize := min(s.windowSize, maxCompressedBlockSize) - - ctx := decodeSyncAsmContext{ - llTable: s.litLengths.fse.dt[:maxTablesize], - mlTable: s.matchLengths.fse.dt[:maxTablesize], - ofTable: s.offsets.fse.dt[:maxTablesize], - llState: uint64(s.litLengths.state.state), - mlState: uint64(s.matchLengths.state.state), - ofState: uint64(s.offsets.state.state), - iteration: s.nSeqs - 1, - litRemain: len(s.literals), - out: s.out, - outPosition: len(s.out), - literals: s.literals, - windowSize: s.windowSize, - history: hist, - } - - s.seqSize = 0 - startSize := len(s.out) +func sequenceDecs_decode_56_bmi2(s *sequenceDecs, br *bitReader, ctx *decodeAsmContext) int - var errCode int +// decodeAsm runs the sequenceDecs decode loop, choosing the BMI2 / 56-bit variant. +func decodeAsm(s *sequenceDecs, br *bitReader, ctx *decodeAsmContext, lte56bits bool) int { if cpuinfo.HasBMI2() { - if useSafe { - errCode = sequenceDecs_decodeSync_safe_bmi2(s, br, &ctx) - } else { - errCode = sequenceDecs_decodeSync_bmi2(s, br, &ctx) - } - } else { - if useSafe { - errCode = sequenceDecs_decodeSync_safe_amd64(s, br, &ctx) - } else { - errCode = sequenceDecs_decodeSync_amd64(s, br, &ctx) - } - } - switch errCode { - case noError: - break - - case errorMatchLenOfsMismatch: - return true, fmt.Errorf("zero matchoff and matchlen (%d) > 0", ctx.ml) - - case errorMatchLenTooBig: - return true, fmt.Errorf("match len (%d) bigger than max allowed length", ctx.ml) - - case errorMatchOffTooBig: - return true, fmt.Errorf("match offset (%d) bigger than current history (%d)", - ctx.mo, ctx.outPosition+len(hist)-startSize) - - case errorNotEnoughLiterals: - return true, fmt.Errorf("unexpected literal count, want %d bytes, but only %d is available", - ctx.ll, ctx.litRemain+ctx.ll) - - case errorOverread: - return true, io.ErrUnexpectedEOF - - case errorNotEnoughSpace: - size := ctx.outPosition + ctx.ll + ctx.ml - if debugDecoder { - println("msl:", s.maxSyncLen, "cap", cap(s.out), "bef:", startSize, "sz:", size-startSize, "mbs:", maxBlockSize, "outsz:", cap(s.out)-startSize) + if lte56bits { + return sequenceDecs_decode_56_bmi2(s, br, ctx) } - return true, fmt.Errorf("output bigger than max block size (%d)", maxBlockSize) - - default: - return true, fmt.Errorf("sequenceDecs_decode returned erroneous code %d", errCode) - } - - s.seqSize += ctx.litRemain - if s.seqSize > maxBlockSize { - return true, fmt.Errorf("output bigger than max block size (%d)", maxBlockSize) + return sequenceDecs_decode_bmi2(s, br, ctx) } - err := br.close() - if err != nil { - printf("Closing sequences: %v, %+v\n", err, *br) - return true, err + if lte56bits { + return sequenceDecs_decode_56_amd64(s, br, ctx) } - - s.literals = s.literals[ctx.litPosition:] - t := ctx.outPosition - s.out = s.out[:t] - - // Add final literals - s.out = append(s.out, s.literals...) - if debugDecoder { - t += len(s.literals) - if t != len(s.out) { - panic(fmt.Errorf("length mismatch, want %d, got %d", len(s.out), t)) - } - } - - return true, nil + return sequenceDecs_decode_amd64(s, br, ctx) } -// -------------------------------------------------------------------------------- - -type decodeAsmContext struct { - llTable []decSymbol - mlTable []decSymbol - ofTable []decSymbol - llState uint64 - mlState uint64 - ofState uint64 - iteration int - seqs []seqVals - litRemain int -} - -const noError = 0 - -// error reported when mo == 0 && ml > 0 -const errorMatchLenOfsMismatch = 1 - -// error reported when ml > maxMatchLen -const errorMatchLenTooBig = 2 - -// error reported when mo > available history or mo > s.windowSize -const errorMatchOffTooBig = 3 - -// error reported when the sum of literal lengths exeeceds the literal buffer size -const errorNotEnoughLiterals = 4 - -// error reported when capacity of `out` is too small -const errorNotEnoughSpace = 5 - -// error reported when bits are overread. -const errorOverread = 6 - -// sequenceDecs_decode implements the main loop of sequenceDecs in x86 asm. +// sequenceDecs_decodeSync_amd64 implements the main loop of sequenceDecs.decodeSync in x86 asm. // // Please refer to seqdec_generic.go for the reference implementation. // //go:noescape -func sequenceDecs_decode_amd64(s *sequenceDecs, br *bitReader, ctx *decodeAsmContext) int +func sequenceDecs_decodeSync_amd64(s *sequenceDecs, br *bitReader, ctx *decodeSyncAsmContext) int -// sequenceDecs_decode implements the main loop of sequenceDecs in x86 asm. -// -// Please refer to seqdec_generic.go for the reference implementation. +// sequenceDecs_decodeSync_bmi2 implements the main loop of sequenceDecs.decodeSync in x86 asm with BMI2 extensions. // //go:noescape -func sequenceDecs_decode_56_amd64(s *sequenceDecs, br *bitReader, ctx *decodeAsmContext) int +func sequenceDecs_decodeSync_bmi2(s *sequenceDecs, br *bitReader, ctx *decodeSyncAsmContext) int -// sequenceDecs_decode implements the main loop of sequenceDecs in x86 asm with BMI2 extensions. +// sequenceDecs_decodeSync_safe_amd64 does the same as above, but does not write more than output buffer. // //go:noescape -func sequenceDecs_decode_bmi2(s *sequenceDecs, br *bitReader, ctx *decodeAsmContext) int +func sequenceDecs_decodeSync_safe_amd64(s *sequenceDecs, br *bitReader, ctx *decodeSyncAsmContext) int -// sequenceDecs_decode implements the main loop of sequenceDecs in x86 asm with BMI2 extensions. +// sequenceDecs_decodeSync_safe_bmi2 does the same as above, but does not write more than output buffer. // //go:noescape -func sequenceDecs_decode_56_bmi2(s *sequenceDecs, br *bitReader, ctx *decodeAsmContext) int - -// decode sequences from the stream without the provided history. -func (s *sequenceDecs) decode(seqs []seqVals) error { - br := s.br - - maxBlockSize := min(s.windowSize, maxCompressedBlockSize) - - ctx := decodeAsmContext{ - llTable: s.litLengths.fse.dt[:maxTablesize], - mlTable: s.matchLengths.fse.dt[:maxTablesize], - ofTable: s.offsets.fse.dt[:maxTablesize], - llState: uint64(s.litLengths.state.state), - mlState: uint64(s.matchLengths.state.state), - ofState: uint64(s.offsets.state.state), - seqs: seqs, - iteration: len(seqs) - 1, - litRemain: len(s.literals), - } - - if debugDecoder { - println("decode: decoding", len(seqs), "sequences", br.remain(), "bits remain on stream") - } +func sequenceDecs_decodeSync_safe_bmi2(s *sequenceDecs, br *bitReader, ctx *decodeSyncAsmContext) int - s.seqSize = 0 - lte56bits := s.maxBits+s.offsets.fse.actualTableLog+s.matchLengths.fse.actualTableLog+s.litLengths.fse.actualTableLog <= 56 - var errCode int +// decodeSyncAsm runs the decodeSync loop, choosing the BMI2 / safe variant. +func decodeSyncAsm(s *sequenceDecs, br *bitReader, ctx *decodeSyncAsmContext, safe bool) int { if cpuinfo.HasBMI2() { - if lte56bits { - errCode = sequenceDecs_decode_56_bmi2(s, br, &ctx) - } else { - errCode = sequenceDecs_decode_bmi2(s, br, &ctx) - } - } else { - if lte56bits { - errCode = sequenceDecs_decode_56_amd64(s, br, &ctx) - } else { - errCode = sequenceDecs_decode_amd64(s, br, &ctx) + if safe { + return sequenceDecs_decodeSync_safe_bmi2(s, br, ctx) } + return sequenceDecs_decodeSync_bmi2(s, br, ctx) } - if errCode != 0 { - i := len(seqs) - ctx.iteration - 1 - switch errCode { - case errorMatchLenOfsMismatch: - ml := ctx.seqs[i].ml - return fmt.Errorf("zero matchoff and matchlen (%d) > 0", ml) - - case errorMatchLenTooBig: - ml := ctx.seqs[i].ml - return fmt.Errorf("match len (%d) bigger than max allowed length", ml) - - case errorNotEnoughLiterals: - ll := ctx.seqs[i].ll - return fmt.Errorf("unexpected literal count, want %d bytes, but only %d is available", ll, ctx.litRemain+ll) - case errorOverread: - return io.ErrUnexpectedEOF - } - - return fmt.Errorf("sequenceDecs_decode_amd64 returned erroneous code %d", errCode) + if safe { + return sequenceDecs_decodeSync_safe_amd64(s, br, ctx) } - - if ctx.litRemain < 0 { - return fmt.Errorf("literal count is too big: total available %d, total requested %d", - len(s.literals), len(s.literals)-ctx.litRemain) - } - - s.seqSize += ctx.litRemain - if s.seqSize > maxBlockSize { - return fmt.Errorf("output bigger than max block size (%d)", maxBlockSize) - } - if debugDecoder { - println("decode: ", br.remain(), "bits remain on stream. code:", errCode) - } - err := br.close() - if err != nil { - printf("Closing sequences: %v, %+v\n", err, *br) - } - return err -} - -// -------------------------------------------------------------------------------- - -type executeAsmContext struct { - seqs []seqVals - seqIndex int - out []byte - history []byte - literals []byte - outPosition int - litPosition int - windowSize int + return sequenceDecs_decodeSync_amd64(s, br, ctx) } // sequenceDecs_executeSimple_amd64 implements the main loop of sequenceDecs.executeSimple in x86 asm. @@ -334,54 +96,10 @@ func sequenceDecs_executeSimple_amd64(ctx *executeAsmContext) bool //go:noescape func sequenceDecs_executeSimple_safe_amd64(ctx *executeAsmContext) bool -// executeSimple handles cases when dictionary is not used. -func (s *sequenceDecs) executeSimple(seqs []seqVals, hist []byte) error { - // Ensure we have enough output size... - if len(s.out)+s.seqSize+compressedBlockOverAlloc > cap(s.out) { - addBytes := s.seqSize + len(s.out) + compressedBlockOverAlloc - s.out = append(s.out, make([]byte, addBytes)...) - s.out = s.out[:len(s.out)-addBytes] - } - - if debugDecoder { - printf("Execute %d seqs with literals: %d into %d bytes\n", len(seqs), len(s.literals), s.seqSize) - } - - var t = len(s.out) - out := s.out[:t+s.seqSize] - - ctx := executeAsmContext{ - seqs: seqs, - seqIndex: 0, - out: out, - history: hist, - outPosition: t, - litPosition: 0, - literals: s.literals, - windowSize: s.windowSize, +// executeSimpleAsm runs the executeSimple loop, choosing the safe variant. +func executeSimpleAsm(ctx *executeAsmContext, safe bool) bool { + if safe { + return sequenceDecs_executeSimple_safe_amd64(ctx) } - var ok bool - if cap(s.literals) < len(s.literals)+compressedBlockOverAlloc { - ok = sequenceDecs_executeSimple_safe_amd64(&ctx) - } else { - ok = sequenceDecs_executeSimple_amd64(&ctx) - } - if !ok { - return fmt.Errorf("match offset (%d) bigger than current history (%d)", - seqs[ctx.seqIndex].mo, ctx.outPosition+len(hist)) - } - s.literals = s.literals[ctx.litPosition:] - t = ctx.outPosition - - // Add final literals - copy(out[t:], s.literals) - if debugDecoder { - t += len(s.literals) - if t != len(out) { - panic(fmt.Errorf("length mismatch, want %d, got %d, ss: %d", len(out), t, s.seqSize)) - } - } - s.out = out - - return nil + return sequenceDecs_executeSimple_amd64(ctx) } diff --git a/vendor/github.com/klauspost/compress/zstd/seqdec_amd64.s b/vendor/github.com/klauspost/compress/zstd/seqdec_amd64.s index a708ca6d3..3fc381c7a 100644 --- a/vendor/github.com/klauspost/compress/zstd/seqdec_amd64.s +++ b/vendor/github.com/klauspost/compress/zstd/seqdec_amd64.s @@ -1,4 +1,4 @@ -// Code generated by command: go run gen.go -out ../seqdec_amd64.s -pkg=zstd. DO NOT EDIT. +// Code generated by command: go run gen.go -out ../seqdec.s -arch amd64,arm64 -pkg=zstd. DO NOT EDIT. //go:build !appengine && !noasm && gc && !noasm diff --git a/vendor/github.com/klauspost/compress/zstd/seqdec_arm64.go b/vendor/github.com/klauspost/compress/zstd/seqdec_arm64.go new file mode 100644 index 000000000..5ad262acf --- /dev/null +++ b/vendor/github.com/klauspost/compress/zstd/seqdec_arm64.go @@ -0,0 +1,70 @@ +//go:build arm64 && !appengine && !noasm && gc + +package zstd + +// The shared decode/decodeSync/executeSimple wrappers and context structs live +// in seqdec_asm.go; this file only declares the arm64 asm routines (generated +// by the avo arm64 lowering printer) and the dispatch helpers. arm64 has no +// BMI2, so each helper selects only between the 56-bit / safe variants. + +// sequenceDecs_decode_arm64 implements the main loop of sequenceDecs in arm64 asm. +// +// Please refer to seqdec_generic.go for the reference implementation. +// +//go:noescape +func sequenceDecs_decode_arm64(s *sequenceDecs, br *bitReader, ctx *decodeAsmContext) int + +// sequenceDecs_decode_56_arm64 implements the main loop of sequenceDecs in arm64 asm. +// +//go:noescape +func sequenceDecs_decode_56_arm64(s *sequenceDecs, br *bitReader, ctx *decodeAsmContext) int + +// decodeAsm runs the sequenceDecs decode loop, choosing the 56-bit variant. +func decodeAsm(s *sequenceDecs, br *bitReader, ctx *decodeAsmContext, lte56bits bool) int { + if lte56bits { + return sequenceDecs_decode_56_arm64(s, br, ctx) + } + return sequenceDecs_decode_arm64(s, br, ctx) +} + +// sequenceDecs_decodeSync_arm64 implements the main loop of sequenceDecs.decodeSync in arm64 asm. +// +// Please refer to seqdec_generic.go for the reference implementation. +// +//go:noescape +func sequenceDecs_decodeSync_arm64(s *sequenceDecs, br *bitReader, ctx *decodeSyncAsmContext) int + +// sequenceDecs_decodeSync_safe_arm64 does the same as above, but does not write more than output buffer. +// +//go:noescape +func sequenceDecs_decodeSync_safe_arm64(s *sequenceDecs, br *bitReader, ctx *decodeSyncAsmContext) int + +// decodeSyncAsm runs the decodeSync loop, choosing the safe variant. +func decodeSyncAsm(s *sequenceDecs, br *bitReader, ctx *decodeSyncAsmContext, safe bool) int { + if safe { + return sequenceDecs_decodeSync_safe_arm64(s, br, ctx) + } + return sequenceDecs_decodeSync_arm64(s, br, ctx) +} + +// sequenceDecs_executeSimple_arm64 implements the main loop of sequenceDecs.executeSimple in arm64 asm. +// +// Returns false if a match offset is too big. +// +// Please refer to seqdec_generic.go for the reference implementation. +// +//go:noescape +func sequenceDecs_executeSimple_arm64(ctx *executeAsmContext) bool + +// Same as above, but with safe memcopies +// +//go:noescape +func sequenceDecs_executeSimple_safe_arm64(ctx *executeAsmContext) bool + +// executeSimpleAsm runs the executeSimple loop, choosing the safe variant. +func executeSimpleAsm(ctx *executeAsmContext, safe bool) bool { + if safe { + return sequenceDecs_executeSimple_safe_arm64(ctx) + } + return sequenceDecs_executeSimple_arm64(ctx) +} diff --git a/vendor/github.com/klauspost/compress/zstd/seqdec_arm64.s b/vendor/github.com/klauspost/compress/zstd/seqdec_arm64.s new file mode 100644 index 000000000..75b19d732 --- /dev/null +++ b/vendor/github.com/klauspost/compress/zstd/seqdec_arm64.s @@ -0,0 +1,2705 @@ +// Code generated by command: go run gen.go -out ../seqdec.s -arch amd64,arm64 -pkg=zstd. DO NOT EDIT. +// EXPERIMENTAL arm64 output lowered from an amd64 avo program. + +//go:build arm64 && !appengine && !noasm && gc && !noasm + +// func sequenceDecs_decode_amd64(s *sequenceDecs, br *bitReader, ctx *decodeAsmContext) int +// Requires: CMOV +TEXT ·sequenceDecs_decode_arm64(SB), $8-32 + MOVD br+8(FP), R1 + MOVD 24(R1), R2 + MOVBU 40(R1), R3 + MOVD (R1), R0 + MOVD 32(R1), R5 + ADD R5, R0, R0 + MOVD R0, (RSP) + MOVD ctx+16(FP), R0 + MOVD 72(R0), R6 + MOVD 80(R0), R7 + MOVD 88(R0), R8 + MOVD 104(R0), R9 + MOVD s+0(FP), R0 + MOVD 144(R0), R10 + MOVD 152(R0), R11 + MOVD 160(R0), R12 + +sequenceDecs_decode_amd64_main_loop: + MOVD (RSP), R13 + + // Fill bitreader to have enough for the offset and match length. + CMP $0x08, R5 + BLT sequenceDecs_decode_amd64_fill_byte_by_byte + MOVD R3, R0 + LSR $0x03, R0, R0 + SUB R0, R13, R13 + MOVD (R13), R2 + SUB R0, R5, R5 + AND $0x07, R3, R3 + JMP sequenceDecs_decode_amd64_fill_end + +sequenceDecs_decode_amd64_fill_byte_by_byte: + CMP $0x00, R5 + BLE sequenceDecs_decode_amd64_fill_check_overread + CMP $0x07, R3 + BLE sequenceDecs_decode_amd64_fill_end + LSL $0x08, R2, R2 + SUB $0x01, R13, R13 + SUB $0x01, R5, R5 + SUB $0x08, R3, R3 + MOVBU (R13), R0 + ORR R0, R2, R2 + JMP sequenceDecs_decode_amd64_fill_byte_by_byte + +sequenceDecs_decode_amd64_fill_check_overread: + CMP $0x40, R3 + BHI error_overread + +sequenceDecs_decode_amd64_fill_end: + // Update offset + MOVD R8, R0 + MOVD R3, R1 + MOVD R2, R14 + LSL R1, R14, R14 + UBFX $8, R0, $8, R1 + LSR $0x20, R0, R0 + TST R1, R1 + BEQ sequenceDecs_decode_amd64_of_update_zero + ADD R1, R3, R3 + CMP $0x40, R3 + BHI sequenceDecs_decode_amd64_of_update_zero + CMP $0x40, R1 + BHS sequenceDecs_decode_amd64_of_update_zero + NEG R1, R1 + LSR R1, R14, R14 + ADD R14, R0, R0 + +sequenceDecs_decode_amd64_of_update_zero: + MOVD R0, 16(R9) + + // Update match length + MOVD R7, R0 + MOVD R3, R1 + MOVD R2, R14 + LSL R1, R14, R14 + UBFX $8, R0, $8, R1 + LSR $0x20, R0, R0 + TST R1, R1 + BEQ sequenceDecs_decode_amd64_ml_update_zero + ADD R1, R3, R3 + CMP $0x40, R3 + BHI sequenceDecs_decode_amd64_ml_update_zero + CMP $0x40, R1 + BHS sequenceDecs_decode_amd64_ml_update_zero + NEG R1, R1 + LSR R1, R14, R14 + ADD R14, R0, R0 + +sequenceDecs_decode_amd64_ml_update_zero: + MOVD R0, 8(R9) + + // Fill bitreader to have enough for the remaining + CMP $0x08, R5 + BLT sequenceDecs_decode_amd64_fill_2_byte_by_byte + MOVD R3, R0 + LSR $0x03, R0, R0 + SUB R0, R13, R13 + MOVD (R13), R2 + SUB R0, R5, R5 + AND $0x07, R3, R3 + JMP sequenceDecs_decode_amd64_fill_2_end + +sequenceDecs_decode_amd64_fill_2_byte_by_byte: + CMP $0x00, R5 + BLE sequenceDecs_decode_amd64_fill_2_check_overread + CMP $0x07, R3 + BLE sequenceDecs_decode_amd64_fill_2_end + LSL $0x08, R2, R2 + SUB $0x01, R13, R13 + SUB $0x01, R5, R5 + SUB $0x08, R3, R3 + MOVBU (R13), R0 + ORR R0, R2, R2 + JMP sequenceDecs_decode_amd64_fill_2_byte_by_byte + +sequenceDecs_decode_amd64_fill_2_check_overread: + CMP $0x40, R3 + BHI error_overread + +sequenceDecs_decode_amd64_fill_2_end: + // Update literal length + MOVD R6, R0 + MOVD R3, R1 + MOVD R2, R14 + LSL R1, R14, R14 + UBFX $8, R0, $8, R1 + LSR $0x20, R0, R0 + TST R1, R1 + BEQ sequenceDecs_decode_amd64_ll_update_zero + ADD R1, R3, R3 + CMP $0x40, R3 + BHI sequenceDecs_decode_amd64_ll_update_zero + CMP $0x40, R1 + BHS sequenceDecs_decode_amd64_ll_update_zero + NEG R1, R1 + LSR R1, R14, R14 + ADD R14, R0, R0 + +sequenceDecs_decode_amd64_ll_update_zero: + MOVD R0, (R9) + + // Fill bitreader for state updates + MOVD R13, (RSP) + MOVD R8, R0 + LSR $0x08, R0, R0 + MOVBU R0, R0 + MOVD ctx+16(FP), R1 + MOVD 96(R1), R16 + CMP $0x00, R16 + BEQ sequenceDecs_decode_amd64_skip_update + + // Update Literal Length State + MOVBU R6, R13 + LSRW $0x10, R6, R6 + ADD R13, R3, R1 + MOVD R2, R14 + MOVD R1, R3 + NEG R1, R16 + ROR R16, R14, R14 + MOVD $0x00000001, R4 + MOVB R13, R1 + LSLW R1, R4, R4 + SUBW $1, R4, R4 + AND R4, R14, R14 + ADD R14, R6, R6 + + // Load ctx.llTable + MOVD ctx+16(FP), R1 + MOVD (R1), R1 + ADD R6<<3, R1, R15 + MOVD (R15), R6 + + // Update Match Length State + MOVBU R7, R13 + LSRW $0x10, R7, R7 + ADD R13, R3, R1 + MOVD R2, R14 + MOVD R1, R3 + NEG R1, R16 + ROR R16, R14, R14 + MOVD $0x00000001, R4 + MOVB R13, R1 + LSLW R1, R4, R4 + SUBW $1, R4, R4 + AND R4, R14, R14 + ADD R14, R7, R7 + + // Load ctx.mlTable + MOVD ctx+16(FP), R1 + MOVD 24(R1), R1 + ADD R7<<3, R1, R15 + MOVD (R15), R7 + + // Update Offset State + MOVBU R8, R13 + LSRW $0x10, R8, R8 + ADD R13, R3, R1 + MOVD R2, R14 + MOVD R1, R3 + NEG R1, R16 + ROR R16, R14, R14 + MOVD $0x00000001, R4 + MOVB R13, R1 + LSLW R1, R4, R4 + SUBW $1, R4, R4 + AND R4, R14, R14 + ADD R14, R8, R8 + + // Load ctx.ofTable + MOVD ctx+16(FP), R1 + MOVD 48(R1), R1 + ADD R8<<3, R1, R15 + MOVD (R15), R8 + +sequenceDecs_decode_amd64_skip_update: + // Adjust offset + MOVD 16(R9), R1 + CMP $0x01, R0 + BLS sequenceDecs_decode_amd64_adjust_offsetB_1_or_0 + MOVD R11, R12 + MOVD R10, R11 + MOVD R1, R10 + JMP sequenceDecs_decode_amd64_after_adjust + +sequenceDecs_decode_amd64_adjust_offsetB_1_or_0: + MOVD (R9), R16 + CMP $0x00000000, R16 + BNE sequenceDecs_decode_amd64_adjust_offset_maybezero + ADD $1, R1, R1 + JMP sequenceDecs_decode_amd64_adjust_offset_nonzero + +sequenceDecs_decode_amd64_adjust_offset_maybezero: + TST R1, R1 + BNE sequenceDecs_decode_amd64_adjust_offset_nonzero + MOVD R10, R1 + JMP sequenceDecs_decode_amd64_after_adjust + +sequenceDecs_decode_amd64_adjust_offset_nonzero: + CMP $0x01, R1 + BLO sequenceDecs_decode_amd64_adjust_zero + BEQ sequenceDecs_decode_amd64_adjust_one + CMP $0x02, R1 + BHI sequenceDecs_decode_amd64_adjust_three + JMP sequenceDecs_decode_amd64_adjust_two + +sequenceDecs_decode_amd64_adjust_zero: + MOVD R10, R0 + JMP sequenceDecs_decode_amd64_adjust_test_temp_valid + +sequenceDecs_decode_amd64_adjust_one: + MOVD R11, R0 + JMP sequenceDecs_decode_amd64_adjust_test_temp_valid + +sequenceDecs_decode_amd64_adjust_two: + MOVD R12, R0 + JMP sequenceDecs_decode_amd64_adjust_test_temp_valid + +sequenceDecs_decode_amd64_adjust_three: + SUB $1, R10, R0 + +sequenceDecs_decode_amd64_adjust_test_temp_valid: + TST R0, R0 + BNE sequenceDecs_decode_amd64_adjust_temp_valid + MOVD $0x00000001, R0 + +sequenceDecs_decode_amd64_adjust_temp_valid: + CMP $0x01, R1 + CSEL NE, R11, R12, R12 + MOVD R10, R11 + MOVD R0, R10 + MOVD R0, R1 + +sequenceDecs_decode_amd64_after_adjust: + MOVD R1, 16(R9) + + // Check values + MOVD 8(R9), R0 + MOVD (R9), R13 + ADD R13, R0, R14 + MOVD s+0(FP), R4 + MOVD 256(R4), R16 + ADD R14, R16, R16 + MOVD R16, 256(R4) + MOVD ctx+16(FP), R14 + MOVD 128(R14), R16 + SUBS R13, R16, R16 + MOVD R16, 128(R14) + BMI error_not_enough_literals + CMP $0x00020002, R0 + BHI sequenceDecs_decode_amd64_error_match_len_too_big + TST R1, R1 + BNE sequenceDecs_decode_amd64_match_len_ofs_ok + TST R0, R0 + BNE sequenceDecs_decode_amd64_error_match_len_ofs_mismatch + +sequenceDecs_decode_amd64_match_len_ofs_ok: + ADD $0x18, R9, R9 + MOVD ctx+16(FP), R0 + MOVD 96(R0), R16 + SUBS $1, R16, R16 + MOVD R16, 96(R0) + BPL sequenceDecs_decode_amd64_main_loop + MOVD s+0(FP), R0 + MOVD R10, 144(R0) + MOVD R11, 152(R0) + MOVD R12, 160(R0) + MOVD br+8(FP), R0 + MOVD R2, 24(R0) + MOVB R3, 40(R0) + MOVD R5, 32(R0) + + // Return success + MOVD $0x00000000, R16 + MOVD R16, ret+24(FP) + RET + + // Return with match length error +sequenceDecs_decode_amd64_error_match_len_ofs_mismatch: + MOVD $0x00000001, R16 + MOVD R16, ret+24(FP) + RET + + // Return with match too long error +sequenceDecs_decode_amd64_error_match_len_too_big: + MOVD $0x00000002, R16 + MOVD R16, ret+24(FP) + RET + + // Return with match offset too long error + MOVD $0x00000003, R16 + MOVD R16, ret+24(FP) + RET + + // Return with not enough literals error +error_not_enough_literals: + MOVD $0x00000004, R16 + MOVD R16, ret+24(FP) + RET + + // Return with overread error +error_overread: + MOVD $0x00000006, R16 + MOVD R16, ret+24(FP) + RET + +// func sequenceDecs_decode_56_amd64(s *sequenceDecs, br *bitReader, ctx *decodeAsmContext) int +// Requires: CMOV +TEXT ·sequenceDecs_decode_56_arm64(SB), $8-32 + MOVD br+8(FP), R1 + MOVD 24(R1), R2 + MOVBU 40(R1), R3 + MOVD (R1), R0 + MOVD 32(R1), R5 + ADD R5, R0, R0 + MOVD R0, (RSP) + MOVD ctx+16(FP), R0 + MOVD 72(R0), R6 + MOVD 80(R0), R7 + MOVD 88(R0), R8 + MOVD 104(R0), R9 + MOVD s+0(FP), R0 + MOVD 144(R0), R10 + MOVD 152(R0), R11 + MOVD 160(R0), R12 + +sequenceDecs_decode_56_amd64_main_loop: + MOVD (RSP), R13 + + // Fill bitreader to have enough for the offset and match length. + CMP $0x08, R5 + BLT sequenceDecs_decode_56_amd64_fill_byte_by_byte + MOVD R3, R0 + LSR $0x03, R0, R0 + SUB R0, R13, R13 + MOVD (R13), R2 + SUB R0, R5, R5 + AND $0x07, R3, R3 + JMP sequenceDecs_decode_56_amd64_fill_end + +sequenceDecs_decode_56_amd64_fill_byte_by_byte: + CMP $0x00, R5 + BLE sequenceDecs_decode_56_amd64_fill_check_overread + CMP $0x07, R3 + BLE sequenceDecs_decode_56_amd64_fill_end + LSL $0x08, R2, R2 + SUB $0x01, R13, R13 + SUB $0x01, R5, R5 + SUB $0x08, R3, R3 + MOVBU (R13), R0 + ORR R0, R2, R2 + JMP sequenceDecs_decode_56_amd64_fill_byte_by_byte + +sequenceDecs_decode_56_amd64_fill_check_overread: + CMP $0x40, R3 + BHI error_overread + +sequenceDecs_decode_56_amd64_fill_end: + // Update offset + MOVD R8, R0 + MOVD R3, R1 + MOVD R2, R14 + LSL R1, R14, R14 + UBFX $8, R0, $8, R1 + LSR $0x20, R0, R0 + TST R1, R1 + BEQ sequenceDecs_decode_56_amd64_of_update_zero + ADD R1, R3, R3 + CMP $0x40, R3 + BHI sequenceDecs_decode_56_amd64_of_update_zero + CMP $0x40, R1 + BHS sequenceDecs_decode_56_amd64_of_update_zero + NEG R1, R1 + LSR R1, R14, R14 + ADD R14, R0, R0 + +sequenceDecs_decode_56_amd64_of_update_zero: + MOVD R0, 16(R9) + + // Update match length + MOVD R7, R0 + MOVD R3, R1 + MOVD R2, R14 + LSL R1, R14, R14 + UBFX $8, R0, $8, R1 + LSR $0x20, R0, R0 + TST R1, R1 + BEQ sequenceDecs_decode_56_amd64_ml_update_zero + ADD R1, R3, R3 + CMP $0x40, R3 + BHI sequenceDecs_decode_56_amd64_ml_update_zero + CMP $0x40, R1 + BHS sequenceDecs_decode_56_amd64_ml_update_zero + NEG R1, R1 + LSR R1, R14, R14 + ADD R14, R0, R0 + +sequenceDecs_decode_56_amd64_ml_update_zero: + MOVD R0, 8(R9) + + // Update literal length + MOVD R6, R0 + MOVD R3, R1 + MOVD R2, R14 + LSL R1, R14, R14 + UBFX $8, R0, $8, R1 + LSR $0x20, R0, R0 + TST R1, R1 + BEQ sequenceDecs_decode_56_amd64_ll_update_zero + ADD R1, R3, R3 + CMP $0x40, R3 + BHI sequenceDecs_decode_56_amd64_ll_update_zero + CMP $0x40, R1 + BHS sequenceDecs_decode_56_amd64_ll_update_zero + NEG R1, R1 + LSR R1, R14, R14 + ADD R14, R0, R0 + +sequenceDecs_decode_56_amd64_ll_update_zero: + MOVD R0, (R9) + + // Fill bitreader for state updates + MOVD R13, (RSP) + MOVD R8, R0 + LSR $0x08, R0, R0 + MOVBU R0, R0 + MOVD ctx+16(FP), R1 + MOVD 96(R1), R16 + CMP $0x00, R16 + BEQ sequenceDecs_decode_56_amd64_skip_update + + // Update Literal Length State + MOVBU R6, R13 + LSRW $0x10, R6, R6 + ADD R13, R3, R1 + MOVD R2, R14 + MOVD R1, R3 + NEG R1, R16 + ROR R16, R14, R14 + MOVD $0x00000001, R4 + MOVB R13, R1 + LSLW R1, R4, R4 + SUBW $1, R4, R4 + AND R4, R14, R14 + ADD R14, R6, R6 + + // Load ctx.llTable + MOVD ctx+16(FP), R1 + MOVD (R1), R1 + ADD R6<<3, R1, R15 + MOVD (R15), R6 + + // Update Match Length State + MOVBU R7, R13 + LSRW $0x10, R7, R7 + ADD R13, R3, R1 + MOVD R2, R14 + MOVD R1, R3 + NEG R1, R16 + ROR R16, R14, R14 + MOVD $0x00000001, R4 + MOVB R13, R1 + LSLW R1, R4, R4 + SUBW $1, R4, R4 + AND R4, R14, R14 + ADD R14, R7, R7 + + // Load ctx.mlTable + MOVD ctx+16(FP), R1 + MOVD 24(R1), R1 + ADD R7<<3, R1, R15 + MOVD (R15), R7 + + // Update Offset State + MOVBU R8, R13 + LSRW $0x10, R8, R8 + ADD R13, R3, R1 + MOVD R2, R14 + MOVD R1, R3 + NEG R1, R16 + ROR R16, R14, R14 + MOVD $0x00000001, R4 + MOVB R13, R1 + LSLW R1, R4, R4 + SUBW $1, R4, R4 + AND R4, R14, R14 + ADD R14, R8, R8 + + // Load ctx.ofTable + MOVD ctx+16(FP), R1 + MOVD 48(R1), R1 + ADD R8<<3, R1, R15 + MOVD (R15), R8 + +sequenceDecs_decode_56_amd64_skip_update: + // Adjust offset + MOVD 16(R9), R1 + CMP $0x01, R0 + BLS sequenceDecs_decode_56_amd64_adjust_offsetB_1_or_0 + MOVD R11, R12 + MOVD R10, R11 + MOVD R1, R10 + JMP sequenceDecs_decode_56_amd64_after_adjust + +sequenceDecs_decode_56_amd64_adjust_offsetB_1_or_0: + MOVD (R9), R16 + CMP $0x00000000, R16 + BNE sequenceDecs_decode_56_amd64_adjust_offset_maybezero + ADD $1, R1, R1 + JMP sequenceDecs_decode_56_amd64_adjust_offset_nonzero + +sequenceDecs_decode_56_amd64_adjust_offset_maybezero: + TST R1, R1 + BNE sequenceDecs_decode_56_amd64_adjust_offset_nonzero + MOVD R10, R1 + JMP sequenceDecs_decode_56_amd64_after_adjust + +sequenceDecs_decode_56_amd64_adjust_offset_nonzero: + CMP $0x01, R1 + BLO sequenceDecs_decode_56_amd64_adjust_zero + BEQ sequenceDecs_decode_56_amd64_adjust_one + CMP $0x02, R1 + BHI sequenceDecs_decode_56_amd64_adjust_three + JMP sequenceDecs_decode_56_amd64_adjust_two + +sequenceDecs_decode_56_amd64_adjust_zero: + MOVD R10, R0 + JMP sequenceDecs_decode_56_amd64_adjust_test_temp_valid + +sequenceDecs_decode_56_amd64_adjust_one: + MOVD R11, R0 + JMP sequenceDecs_decode_56_amd64_adjust_test_temp_valid + +sequenceDecs_decode_56_amd64_adjust_two: + MOVD R12, R0 + JMP sequenceDecs_decode_56_amd64_adjust_test_temp_valid + +sequenceDecs_decode_56_amd64_adjust_three: + SUB $1, R10, R0 + +sequenceDecs_decode_56_amd64_adjust_test_temp_valid: + TST R0, R0 + BNE sequenceDecs_decode_56_amd64_adjust_temp_valid + MOVD $0x00000001, R0 + +sequenceDecs_decode_56_amd64_adjust_temp_valid: + CMP $0x01, R1 + CSEL NE, R11, R12, R12 + MOVD R10, R11 + MOVD R0, R10 + MOVD R0, R1 + +sequenceDecs_decode_56_amd64_after_adjust: + MOVD R1, 16(R9) + + // Check values + MOVD 8(R9), R0 + MOVD (R9), R13 + ADD R13, R0, R14 + MOVD s+0(FP), R4 + MOVD 256(R4), R16 + ADD R14, R16, R16 + MOVD R16, 256(R4) + MOVD ctx+16(FP), R14 + MOVD 128(R14), R16 + SUBS R13, R16, R16 + MOVD R16, 128(R14) + BMI error_not_enough_literals + CMP $0x00020002, R0 + BHI sequenceDecs_decode_56_amd64_error_match_len_too_big + TST R1, R1 + BNE sequenceDecs_decode_56_amd64_match_len_ofs_ok + TST R0, R0 + BNE sequenceDecs_decode_56_amd64_error_match_len_ofs_mismatch + +sequenceDecs_decode_56_amd64_match_len_ofs_ok: + ADD $0x18, R9, R9 + MOVD ctx+16(FP), R0 + MOVD 96(R0), R16 + SUBS $1, R16, R16 + MOVD R16, 96(R0) + BPL sequenceDecs_decode_56_amd64_main_loop + MOVD s+0(FP), R0 + MOVD R10, 144(R0) + MOVD R11, 152(R0) + MOVD R12, 160(R0) + MOVD br+8(FP), R0 + MOVD R2, 24(R0) + MOVB R3, 40(R0) + MOVD R5, 32(R0) + + // Return success + MOVD $0x00000000, R16 + MOVD R16, ret+24(FP) + RET + + // Return with match length error +sequenceDecs_decode_56_amd64_error_match_len_ofs_mismatch: + MOVD $0x00000001, R16 + MOVD R16, ret+24(FP) + RET + + // Return with match too long error +sequenceDecs_decode_56_amd64_error_match_len_too_big: + MOVD $0x00000002, R16 + MOVD R16, ret+24(FP) + RET + + // Return with match offset too long error + MOVD $0x00000003, R16 + MOVD R16, ret+24(FP) + RET + + // Return with not enough literals error +error_not_enough_literals: + MOVD $0x00000004, R16 + MOVD R16, ret+24(FP) + RET + + // Return with overread error +error_overread: + MOVD $0x00000006, R16 + MOVD R16, ret+24(FP) + RET + +// skipped sequenceDecs_decode_bmi2 (BMI2 not available on arm64) + +// skipped sequenceDecs_decode_56_bmi2 (BMI2 not available on arm64) + +// func sequenceDecs_executeSimple_amd64(ctx *executeAsmContext) bool +// Requires: SSE +TEXT ·sequenceDecs_executeSimple_arm64(SB), $8-9 + MOVD ctx+0(FP), R9 + MOVD 8(R9), R1 + TST R1, R1 + BEQ empty_seqs + MOVD (R9), R0 + MOVD 24(R9), R2 + MOVD 32(R9), R3 + MOVD 80(R9), R5 + MOVD 104(R9), R6 + MOVD 120(R9), R7 + MOVD 56(R9), R8 + MOVD 64(R9), R9 + ADD R9, R8, R8 + + // seqsBase += 24 * seqIndex + ADD R2<<1, R2, R10 + LSL $0x03, R10, R10 + ADD R10, R0, R0 + + // outBase += outPosition + ADD R6, R3, R3 + +main_loop: + MOVD (R0), R10 + MOVD 16(R0), R11 + MOVD 8(R0), R12 + + // Copy literals + TST R10, R10 + BEQ check_offset + MOVD $0, R13 + +copy_1: + ADD R13, R5, R15 + VLD1 (R15), [V0.B16] + ADD R13, R3, R15 + VST1 [V0.B16], (R15) + ADD $0x10, R13, R13 + CMP R10, R13 + BLO copy_1 + ADD R10, R5, R5 + ADD R10, R3, R3 + ADD R10, R6, R6 + + // Malformed input if seq.mo > t+len(hist) || seq.mo > s.windowSize) +check_offset: + ADD R9, R6, R10 + CMP R10, R11 + BGT error_match_off_too_big + CMP R7, R11 + BGT error_match_off_too_big + + // Copy match from history + MOVD R11, R10 + SUBS R6, R10, R10 + BLS copy_match + MOVD R8, R13 + SUB R10, R13, R13 + CMP R10, R12 + BGT copy_all_from_history + MOVD R12, R10 + SUBS $0x10, R10, R10 + BLO copy_4_small + +copy_4_loop: + VLD1 (R13), [V0.B16] + VST1 [V0.B16], (R3) + ADD $0x10, R13, R13 + ADD $0x10, R3, R3 + SUBS $0x10, R10, R10 + BHS copy_4_loop + ADD R10, R13, R13 + ADD $16, R13, R13 + ADD R10, R3, R3 + ADD $16, R3, R3 + ADD $-16, R13, R15 + VLD1 (R15), [V0.B16] + ADD $-16, R3, R15 + VST1 [V0.B16], (R15) + JMP copy_4_end + +copy_4_small: + CMP $0x03, R12 + BEQ copy_4_move_3 + CMP $0x08, R12 + BLO copy_4_move_4through7 + JMP copy_4_move_8through16 + +copy_4_move_3: + MOVH (R13), R10 + MOVB 2(R13), R11 + MOVH R10, (R3) + MOVB R11, 2(R3) + ADD R12, R13, R13 + ADD R12, R3, R3 + JMP copy_4_end + +copy_4_move_4through7: + MOVWU (R13), R10 + ADD R12, R13, R15 + MOVWU -4(R15), R11 + MOVW R10, (R3) + ADD R12, R3, R15 + MOVW R11, -4(R15) + ADD R12, R13, R13 + ADD R12, R3, R3 + JMP copy_4_end + +copy_4_move_8through16: + MOVD (R13), R10 + ADD R12, R13, R15 + MOVD -8(R15), R11 + MOVD R10, (R3) + ADD R12, R3, R15 + MOVD R11, -8(R15) + ADD R12, R13, R13 + ADD R12, R3, R3 + +copy_4_end: + ADD R12, R6, R6 + ADD $0x18, R0, R0 + ADD $1, R2, R2 + CMP R1, R2 + BLO main_loop + JMP loop_finished + +copy_all_from_history: + MOVD R10, R14 + SUBS $0x10, R14, R14 + BLO copy_5_small + +copy_5_loop: + VLD1 (R13), [V0.B16] + VST1 [V0.B16], (R3) + ADD $0x10, R13, R13 + ADD $0x10, R3, R3 + SUBS $0x10, R14, R14 + BHS copy_5_loop + ADD R14, R13, R13 + ADD $16, R13, R13 + ADD R14, R3, R3 + ADD $16, R3, R3 + ADD $-16, R13, R15 + VLD1 (R15), [V0.B16] + ADD $-16, R3, R15 + VST1 [V0.B16], (R15) + JMP copy_5_end + +copy_5_small: + CMP $0x03, R10 + BEQ copy_5_move_3 + BLO copy_5_move_1or2 + CMP $0x08, R10 + BLO copy_5_move_4through7 + JMP copy_5_move_8through16 + +copy_5_move_1or2: + MOVB (R13), R14 + ADD R10, R13, R15 + MOVB -1(R15), R4 + MOVB R14, (R3) + ADD R10, R3, R15 + MOVB R4, -1(R15) + ADD R10, R13, R13 + ADD R10, R3, R3 + JMP copy_5_end + +copy_5_move_3: + MOVH (R13), R14 + MOVB 2(R13), R4 + MOVH R14, (R3) + MOVB R4, 2(R3) + ADD R10, R13, R13 + ADD R10, R3, R3 + JMP copy_5_end + +copy_5_move_4through7: + MOVWU (R13), R14 + ADD R10, R13, R15 + MOVWU -4(R15), R4 + MOVW R14, (R3) + ADD R10, R3, R15 + MOVW R4, -4(R15) + ADD R10, R13, R13 + ADD R10, R3, R3 + JMP copy_5_end + +copy_5_move_8through16: + MOVD (R13), R14 + ADD R10, R13, R15 + MOVD -8(R15), R4 + MOVD R14, (R3) + ADD R10, R3, R15 + MOVD R4, -8(R15) + ADD R10, R13, R13 + ADD R10, R3, R3 + +copy_5_end: + ADD R10, R6, R6 + SUB R10, R12, R12 + + // Copy match from the current buffer +copy_match: + MOVD R3, R10 + SUB R11, R10, R10 + + // ml <= mo + CMP R11, R12 + BHI copy_overlapping_match + + // Copy non-overlapping match + ADD R12, R6, R6 + MOVD R3, R11 + ADD R12, R3, R3 + +copy_2: + VLD1 (R10), [V0.B16] + VST1 [V0.B16], (R11) + ADD $0x10, R10, R10 + ADD $0x10, R11, R11 + SUBS $0x10, R12, R12 + BHI copy_2 + JMP handle_loop + + // Copy overlapping match +copy_overlapping_match: + ADD R12, R6, R6 + +copy_slow_3: + MOVB (R10), R11 + MOVB R11, (R3) + ADD $1, R10, R10 + ADD $1, R3, R3 + SUBS $1, R12, R12 + BNE copy_slow_3 + +handle_loop: + ADD $0x18, R0, R0 + ADD $1, R2, R2 + CMP R1, R2 + BLO main_loop + +loop_finished: + // Return value + MOVD $0x01, R16 + MOVB R16, ret+8(FP) + + // Update the context + MOVD ctx+0(FP), R0 + MOVD R2, 24(R0) + MOVD R6, 104(R0) + MOVD 80(R0), R16 + SUB R16, R5, R5 + MOVD R5, 112(R0) + RET + +error_match_off_too_big: + // Return value + MOVD $0x00, R16 + MOVB R16, ret+8(FP) + + // Update the context + MOVD ctx+0(FP), R0 + MOVD R2, 24(R0) + MOVD R6, 104(R0) + MOVD 80(R0), R16 + SUB R16, R5, R5 + MOVD R5, 112(R0) + RET + +empty_seqs: + // Return value + MOVD $0x01, R16 + MOVB R16, ret+8(FP) + RET + +// func sequenceDecs_executeSimple_safe_amd64(ctx *executeAsmContext) bool +// Requires: SSE +TEXT ·sequenceDecs_executeSimple_safe_arm64(SB), $8-9 + MOVD ctx+0(FP), R9 + MOVD 8(R9), R1 + TST R1, R1 + BEQ empty_seqs + MOVD (R9), R0 + MOVD 24(R9), R2 + MOVD 32(R9), R3 + MOVD 80(R9), R5 + MOVD 104(R9), R6 + MOVD 120(R9), R7 + MOVD 56(R9), R8 + MOVD 64(R9), R9 + ADD R9, R8, R8 + + // seqsBase += 24 * seqIndex + ADD R2<<1, R2, R10 + LSL $0x03, R10, R10 + ADD R10, R0, R0 + + // outBase += outPosition + ADD R6, R3, R3 + +main_loop: + MOVD (R0), R10 + MOVD 16(R0), R11 + MOVD 8(R0), R12 + + // Copy literals + TST R10, R10 + BEQ check_offset + MOVD R10, R13 + SUBS $0x10, R13, R13 + BLO copy_1_small + +copy_1_loop: + VLD1 (R5), [V0.B16] + VST1 [V0.B16], (R3) + ADD $0x10, R5, R5 + ADD $0x10, R3, R3 + SUBS $0x10, R13, R13 + BHS copy_1_loop + ADD R13, R5, R5 + ADD $16, R5, R5 + ADD R13, R3, R3 + ADD $16, R3, R3 + ADD $-16, R5, R15 + VLD1 (R15), [V0.B16] + ADD $-16, R3, R15 + VST1 [V0.B16], (R15) + JMP copy_1_end + +copy_1_small: + CMP $0x03, R10 + BEQ copy_1_move_3 + BLO copy_1_move_1or2 + CMP $0x08, R10 + BLO copy_1_move_4through7 + JMP copy_1_move_8through16 + +copy_1_move_1or2: + MOVB (R5), R13 + ADD R10, R5, R15 + MOVB -1(R15), R14 + MOVB R13, (R3) + ADD R10, R3, R15 + MOVB R14, -1(R15) + ADD R10, R5, R5 + ADD R10, R3, R3 + JMP copy_1_end + +copy_1_move_3: + MOVH (R5), R13 + MOVB 2(R5), R14 + MOVH R13, (R3) + MOVB R14, 2(R3) + ADD R10, R5, R5 + ADD R10, R3, R3 + JMP copy_1_end + +copy_1_move_4through7: + MOVWU (R5), R13 + ADD R10, R5, R15 + MOVWU -4(R15), R14 + MOVW R13, (R3) + ADD R10, R3, R15 + MOVW R14, -4(R15) + ADD R10, R5, R5 + ADD R10, R3, R3 + JMP copy_1_end + +copy_1_move_8through16: + MOVD (R5), R13 + ADD R10, R5, R15 + MOVD -8(R15), R14 + MOVD R13, (R3) + ADD R10, R3, R15 + MOVD R14, -8(R15) + ADD R10, R5, R5 + ADD R10, R3, R3 + +copy_1_end: + ADD R10, R6, R6 + + // Malformed input if seq.mo > t+len(hist) || seq.mo > s.windowSize) +check_offset: + ADD R9, R6, R10 + CMP R10, R11 + BGT error_match_off_too_big + CMP R7, R11 + BGT error_match_off_too_big + + // Copy match from history + MOVD R11, R10 + SUBS R6, R10, R10 + BLS copy_match + MOVD R8, R13 + SUB R10, R13, R13 + CMP R10, R12 + BGT copy_all_from_history + MOVD R12, R10 + SUBS $0x10, R10, R10 + BLO copy_4_small + +copy_4_loop: + VLD1 (R13), [V0.B16] + VST1 [V0.B16], (R3) + ADD $0x10, R13, R13 + ADD $0x10, R3, R3 + SUBS $0x10, R10, R10 + BHS copy_4_loop + ADD R10, R13, R13 + ADD $16, R13, R13 + ADD R10, R3, R3 + ADD $16, R3, R3 + ADD $-16, R13, R15 + VLD1 (R15), [V0.B16] + ADD $-16, R3, R15 + VST1 [V0.B16], (R15) + JMP copy_4_end + +copy_4_small: + CMP $0x03, R12 + BEQ copy_4_move_3 + CMP $0x08, R12 + BLO copy_4_move_4through7 + JMP copy_4_move_8through16 + +copy_4_move_3: + MOVH (R13), R10 + MOVB 2(R13), R11 + MOVH R10, (R3) + MOVB R11, 2(R3) + ADD R12, R13, R13 + ADD R12, R3, R3 + JMP copy_4_end + +copy_4_move_4through7: + MOVWU (R13), R10 + ADD R12, R13, R15 + MOVWU -4(R15), R11 + MOVW R10, (R3) + ADD R12, R3, R15 + MOVW R11, -4(R15) + ADD R12, R13, R13 + ADD R12, R3, R3 + JMP copy_4_end + +copy_4_move_8through16: + MOVD (R13), R10 + ADD R12, R13, R15 + MOVD -8(R15), R11 + MOVD R10, (R3) + ADD R12, R3, R15 + MOVD R11, -8(R15) + ADD R12, R13, R13 + ADD R12, R3, R3 + +copy_4_end: + ADD R12, R6, R6 + ADD $0x18, R0, R0 + ADD $1, R2, R2 + CMP R1, R2 + BLO main_loop + JMP loop_finished + +copy_all_from_history: + MOVD R10, R14 + SUBS $0x10, R14, R14 + BLO copy_5_small + +copy_5_loop: + VLD1 (R13), [V0.B16] + VST1 [V0.B16], (R3) + ADD $0x10, R13, R13 + ADD $0x10, R3, R3 + SUBS $0x10, R14, R14 + BHS copy_5_loop + ADD R14, R13, R13 + ADD $16, R13, R13 + ADD R14, R3, R3 + ADD $16, R3, R3 + ADD $-16, R13, R15 + VLD1 (R15), [V0.B16] + ADD $-16, R3, R15 + VST1 [V0.B16], (R15) + JMP copy_5_end + +copy_5_small: + CMP $0x03, R10 + BEQ copy_5_move_3 + BLO copy_5_move_1or2 + CMP $0x08, R10 + BLO copy_5_move_4through7 + JMP copy_5_move_8through16 + +copy_5_move_1or2: + MOVB (R13), R14 + ADD R10, R13, R15 + MOVB -1(R15), R4 + MOVB R14, (R3) + ADD R10, R3, R15 + MOVB R4, -1(R15) + ADD R10, R13, R13 + ADD R10, R3, R3 + JMP copy_5_end + +copy_5_move_3: + MOVH (R13), R14 + MOVB 2(R13), R4 + MOVH R14, (R3) + MOVB R4, 2(R3) + ADD R10, R13, R13 + ADD R10, R3, R3 + JMP copy_5_end + +copy_5_move_4through7: + MOVWU (R13), R14 + ADD R10, R13, R15 + MOVWU -4(R15), R4 + MOVW R14, (R3) + ADD R10, R3, R15 + MOVW R4, -4(R15) + ADD R10, R13, R13 + ADD R10, R3, R3 + JMP copy_5_end + +copy_5_move_8through16: + MOVD (R13), R14 + ADD R10, R13, R15 + MOVD -8(R15), R4 + MOVD R14, (R3) + ADD R10, R3, R15 + MOVD R4, -8(R15) + ADD R10, R13, R13 + ADD R10, R3, R3 + +copy_5_end: + ADD R10, R6, R6 + SUB R10, R12, R12 + + // Copy match from the current buffer +copy_match: + MOVD R3, R10 + SUB R11, R10, R10 + + // ml <= mo + CMP R11, R12 + BHI copy_overlapping_match + + // Copy non-overlapping match + ADD R12, R6, R6 + MOVD R12, R11 + SUBS $0x10, R11, R11 + BLO copy_2_small + +copy_2_loop: + VLD1 (R10), [V0.B16] + VST1 [V0.B16], (R3) + ADD $0x10, R10, R10 + ADD $0x10, R3, R3 + SUBS $0x10, R11, R11 + BHS copy_2_loop + ADD R11, R10, R10 + ADD $16, R10, R10 + ADD R11, R3, R3 + ADD $16, R3, R3 + ADD $-16, R10, R15 + VLD1 (R15), [V0.B16] + ADD $-16, R3, R15 + VST1 [V0.B16], (R15) + JMP copy_2_end + +copy_2_small: + CMP $0x03, R12 + BEQ copy_2_move_3 + BLO copy_2_move_1or2 + CMP $0x08, R12 + BLO copy_2_move_4through7 + JMP copy_2_move_8through16 + +copy_2_move_1or2: + MOVB (R10), R11 + ADD R12, R10, R15 + MOVB -1(R15), R13 + MOVB R11, (R3) + ADD R12, R3, R15 + MOVB R13, -1(R15) + ADD R12, R10, R10 + ADD R12, R3, R3 + JMP copy_2_end + +copy_2_move_3: + MOVH (R10), R11 + MOVB 2(R10), R13 + MOVH R11, (R3) + MOVB R13, 2(R3) + ADD R12, R10, R10 + ADD R12, R3, R3 + JMP copy_2_end + +copy_2_move_4through7: + MOVWU (R10), R11 + ADD R12, R10, R15 + MOVWU -4(R15), R13 + MOVW R11, (R3) + ADD R12, R3, R15 + MOVW R13, -4(R15) + ADD R12, R10, R10 + ADD R12, R3, R3 + JMP copy_2_end + +copy_2_move_8through16: + MOVD (R10), R11 + ADD R12, R10, R15 + MOVD -8(R15), R13 + MOVD R11, (R3) + ADD R12, R3, R15 + MOVD R13, -8(R15) + ADD R12, R10, R10 + ADD R12, R3, R3 + +copy_2_end: + JMP handle_loop + + // Copy overlapping match +copy_overlapping_match: + ADD R12, R6, R6 + +copy_slow_3: + MOVB (R10), R11 + MOVB R11, (R3) + ADD $1, R10, R10 + ADD $1, R3, R3 + SUBS $1, R12, R12 + BNE copy_slow_3 + +handle_loop: + ADD $0x18, R0, R0 + ADD $1, R2, R2 + CMP R1, R2 + BLO main_loop + +loop_finished: + // Return value + MOVD $0x01, R16 + MOVB R16, ret+8(FP) + + // Update the context + MOVD ctx+0(FP), R0 + MOVD R2, 24(R0) + MOVD R6, 104(R0) + MOVD 80(R0), R16 + SUB R16, R5, R5 + MOVD R5, 112(R0) + RET + +error_match_off_too_big: + // Return value + MOVD $0x00, R16 + MOVB R16, ret+8(FP) + + // Update the context + MOVD ctx+0(FP), R0 + MOVD R2, 24(R0) + MOVD R6, 104(R0) + MOVD 80(R0), R16 + SUB R16, R5, R5 + MOVD R5, 112(R0) + RET + +empty_seqs: + // Return value + MOVD $0x01, R16 + MOVB R16, ret+8(FP) + RET + +// func sequenceDecs_decodeSync_amd64(s *sequenceDecs, br *bitReader, ctx *decodeSyncAsmContext) int +// Requires: CMOV, SSE +TEXT ·sequenceDecs_decodeSync_arm64(SB), $64-32 + MOVD br+8(FP), R1 + MOVD 24(R1), R2 + MOVBU 40(R1), R3 + MOVD (R1), R0 + MOVD 32(R1), R5 + ADD R5, R0, R0 + MOVD R0, (RSP) + MOVD ctx+16(FP), R0 + MOVD 72(R0), R6 + MOVD 80(R0), R7 + MOVD 88(R0), R8 + MOVD $0, R1 + MOVD R1, 8(RSP) + MOVD R1, 16(RSP) + MOVD R1, 24(RSP) + MOVD 112(R0), R9 + MOVD 128(R0), R1 + MOVD R1, 32(RSP) + MOVD 144(R0), R10 + MOVD 136(R0), R11 + MOVD 200(R0), R1 + MOVD R1, 56(RSP) + MOVD 176(R0), R1 + MOVD R1, 48(RSP) + MOVD 184(R0), R0 + MOVD R0, 40(RSP) + MOVD 40(RSP), R0 + MOVD 48(RSP), R16 + ADD R0, R16, R16 + MOVD R16, 48(RSP) + + // Calculate pointer to s.out[cap(s.out)] (a past-end pointer) + MOVD 32(RSP), R16 + ADD R9, R16, R16 + MOVD R16, 32(RSP) + + // outBase += outPosition + ADD R11, R9, R9 + +sequenceDecs_decodeSync_amd64_main_loop: + MOVD (RSP), R12 + + // Fill bitreader to have enough for the offset and match length. + CMP $0x08, R5 + BLT sequenceDecs_decodeSync_amd64_fill_byte_by_byte + MOVD R3, R0 + LSR $0x03, R0, R0 + SUB R0, R12, R12 + MOVD (R12), R2 + SUB R0, R5, R5 + AND $0x07, R3, R3 + JMP sequenceDecs_decodeSync_amd64_fill_end + +sequenceDecs_decodeSync_amd64_fill_byte_by_byte: + CMP $0x00, R5 + BLE sequenceDecs_decodeSync_amd64_fill_check_overread + CMP $0x07, R3 + BLE sequenceDecs_decodeSync_amd64_fill_end + LSL $0x08, R2, R2 + SUB $0x01, R12, R12 + SUB $0x01, R5, R5 + SUB $0x08, R3, R3 + MOVBU (R12), R0 + ORR R0, R2, R2 + JMP sequenceDecs_decodeSync_amd64_fill_byte_by_byte + +sequenceDecs_decodeSync_amd64_fill_check_overread: + CMP $0x40, R3 + BHI error_overread + +sequenceDecs_decodeSync_amd64_fill_end: + // Update offset + MOVD R8, R0 + MOVD R3, R1 + MOVD R2, R13 + LSL R1, R13, R13 + UBFX $8, R0, $8, R1 + LSR $0x20, R0, R0 + TST R1, R1 + BEQ sequenceDecs_decodeSync_amd64_of_update_zero + ADD R1, R3, R3 + CMP $0x40, R3 + BHI sequenceDecs_decodeSync_amd64_of_update_zero + CMP $0x40, R1 + BHS sequenceDecs_decodeSync_amd64_of_update_zero + NEG R1, R1 + LSR R1, R13, R13 + ADD R13, R0, R0 + +sequenceDecs_decodeSync_amd64_of_update_zero: + MOVD R0, 8(RSP) + + // Update match length + MOVD R7, R0 + MOVD R3, R1 + MOVD R2, R13 + LSL R1, R13, R13 + UBFX $8, R0, $8, R1 + LSR $0x20, R0, R0 + TST R1, R1 + BEQ sequenceDecs_decodeSync_amd64_ml_update_zero + ADD R1, R3, R3 + CMP $0x40, R3 + BHI sequenceDecs_decodeSync_amd64_ml_update_zero + CMP $0x40, R1 + BHS sequenceDecs_decodeSync_amd64_ml_update_zero + NEG R1, R1 + LSR R1, R13, R13 + ADD R13, R0, R0 + +sequenceDecs_decodeSync_amd64_ml_update_zero: + MOVD R0, 16(RSP) + + // Fill bitreader to have enough for the remaining + CMP $0x08, R5 + BLT sequenceDecs_decodeSync_amd64_fill_2_byte_by_byte + MOVD R3, R0 + LSR $0x03, R0, R0 + SUB R0, R12, R12 + MOVD (R12), R2 + SUB R0, R5, R5 + AND $0x07, R3, R3 + JMP sequenceDecs_decodeSync_amd64_fill_2_end + +sequenceDecs_decodeSync_amd64_fill_2_byte_by_byte: + CMP $0x00, R5 + BLE sequenceDecs_decodeSync_amd64_fill_2_check_overread + CMP $0x07, R3 + BLE sequenceDecs_decodeSync_amd64_fill_2_end + LSL $0x08, R2, R2 + SUB $0x01, R12, R12 + SUB $0x01, R5, R5 + SUB $0x08, R3, R3 + MOVBU (R12), R0 + ORR R0, R2, R2 + JMP sequenceDecs_decodeSync_amd64_fill_2_byte_by_byte + +sequenceDecs_decodeSync_amd64_fill_2_check_overread: + CMP $0x40, R3 + BHI error_overread + +sequenceDecs_decodeSync_amd64_fill_2_end: + // Update literal length + MOVD R6, R0 + MOVD R3, R1 + MOVD R2, R13 + LSL R1, R13, R13 + UBFX $8, R0, $8, R1 + LSR $0x20, R0, R0 + TST R1, R1 + BEQ sequenceDecs_decodeSync_amd64_ll_update_zero + ADD R1, R3, R3 + CMP $0x40, R3 + BHI sequenceDecs_decodeSync_amd64_ll_update_zero + CMP $0x40, R1 + BHS sequenceDecs_decodeSync_amd64_ll_update_zero + NEG R1, R1 + LSR R1, R13, R13 + ADD R13, R0, R0 + +sequenceDecs_decodeSync_amd64_ll_update_zero: + MOVD R0, 24(RSP) + + // Fill bitreader for state updates + MOVD R12, (RSP) + MOVD R8, R0 + LSR $0x08, R0, R0 + MOVBU R0, R0 + MOVD ctx+16(FP), R1 + MOVD 96(R1), R16 + CMP $0x00, R16 + BEQ sequenceDecs_decodeSync_amd64_skip_update + + // Update Literal Length State + MOVBU R6, R12 + LSRW $0x10, R6, R6 + ADD R12, R3, R1 + MOVD R2, R13 + MOVD R1, R3 + NEG R1, R16 + ROR R16, R13, R13 + MOVD $0x00000001, R14 + MOVB R12, R1 + LSLW R1, R14, R14 + SUBW $1, R14, R14 + AND R14, R13, R13 + ADD R13, R6, R6 + + // Load ctx.llTable + MOVD ctx+16(FP), R1 + MOVD (R1), R1 + ADD R6<<3, R1, R15 + MOVD (R15), R6 + + // Update Match Length State + MOVBU R7, R12 + LSRW $0x10, R7, R7 + ADD R12, R3, R1 + MOVD R2, R13 + MOVD R1, R3 + NEG R1, R16 + ROR R16, R13, R13 + MOVD $0x00000001, R14 + MOVB R12, R1 + LSLW R1, R14, R14 + SUBW $1, R14, R14 + AND R14, R13, R13 + ADD R13, R7, R7 + + // Load ctx.mlTable + MOVD ctx+16(FP), R1 + MOVD 24(R1), R1 + ADD R7<<3, R1, R15 + MOVD (R15), R7 + + // Update Offset State + MOVBU R8, R12 + LSRW $0x10, R8, R8 + ADD R12, R3, R1 + MOVD R2, R13 + MOVD R1, R3 + NEG R1, R16 + ROR R16, R13, R13 + MOVD $0x00000001, R14 + MOVB R12, R1 + LSLW R1, R14, R14 + SUBW $1, R14, R14 + AND R14, R13, R13 + ADD R13, R8, R8 + + // Load ctx.ofTable + MOVD ctx+16(FP), R1 + MOVD 48(R1), R1 + ADD R8<<3, R1, R15 + MOVD (R15), R8 + +sequenceDecs_decodeSync_amd64_skip_update: + // Adjust offset + MOVD s+0(FP), R1 + MOVD 8(RSP), R12 + CMP $0x01, R0 + BLS sequenceDecs_decodeSync_amd64_adjust_offsetB_1_or_0 + ADD $144, R1, R15 + VLD1 (R15), [V0.B16] + MOVD R12, 144(R1) + ADD $152, R1, R15 + VST1 [V0.B16], (R15) + JMP sequenceDecs_decodeSync_amd64_after_adjust + +sequenceDecs_decodeSync_amd64_adjust_offsetB_1_or_0: + MOVD 24(RSP), R16 + CMP $0x00000000, R16 + BNE sequenceDecs_decodeSync_amd64_adjust_offset_maybezero + ADD $1, R12, R12 + JMP sequenceDecs_decodeSync_amd64_adjust_offset_nonzero + +sequenceDecs_decodeSync_amd64_adjust_offset_maybezero: + TST R12, R12 + BNE sequenceDecs_decodeSync_amd64_adjust_offset_nonzero + MOVD 144(R1), R12 + JMP sequenceDecs_decodeSync_amd64_after_adjust + +sequenceDecs_decodeSync_amd64_adjust_offset_nonzero: + MOVD R12, R0 + MOVD $0, R13 + MOVD $-1, R14 + CMP $0x03, R12 + CSEL EQ, R13, R0, R0 + CSEL EQ, R14, R13, R13 + ADD R0<<3, R1, R15 + MOVD 144(R15), R16 + ADDS R16, R13, R13 + BNE sequenceDecs_decodeSync_amd64_adjust_temp_valid + MOVD $0x00000001, R13 + +sequenceDecs_decodeSync_amd64_adjust_temp_valid: + CMP $0x01, R12 + BEQ sequenceDecs_decodeSync_amd64_adjust_skip + MOVD 152(R1), R0 + MOVD R0, 160(R1) + +sequenceDecs_decodeSync_amd64_adjust_skip: + MOVD 144(R1), R0 + MOVD R0, 152(R1) + MOVD R13, 144(R1) + MOVD R13, R12 + +sequenceDecs_decodeSync_amd64_after_adjust: + MOVD R12, 8(RSP) + + // Check values + MOVD 16(RSP), R0 + MOVD 24(RSP), R1 + ADD R1, R0, R13 + MOVD s+0(FP), R14 + MOVD 256(R14), R16 + ADD R13, R16, R16 + MOVD R16, 256(R14) + MOVD ctx+16(FP), R13 + MOVD 104(R13), R16 + SUBS R1, R16, R16 + MOVD R16, 104(R13) + BMI error_not_enough_literals + CMP $0x00020002, R0 + BHI sequenceDecs_decodeSync_amd64_error_match_len_too_big + TST R12, R12 + BNE sequenceDecs_decodeSync_amd64_match_len_ofs_ok + TST R0, R0 + BNE sequenceDecs_decodeSync_amd64_error_match_len_ofs_mismatch + +sequenceDecs_decodeSync_amd64_match_len_ofs_ok: + MOVD 24(RSP), R0 + MOVD 8(RSP), R1 + MOVD 16(RSP), R12 + + // Check if we have enough space in s.out + ADD R12, R0, R13 + ADD R9, R13, R13 + MOVD 32(RSP), R16 + CMP R16, R13 + BHI error_not_enough_space + + // Copy literals + TST R0, R0 + BEQ check_offset + MOVD $0, R13 + +copy_1: + ADD R13, R10, R15 + VLD1 (R15), [V0.B16] + ADD R13, R9, R15 + VST1 [V0.B16], (R15) + ADD $0x10, R13, R13 + CMP R0, R13 + BLO copy_1 + ADD R0, R10, R10 + ADD R0, R9, R9 + ADD R0, R11, R11 + + // Malformed input if seq.mo > t+len(hist) || seq.mo > s.windowSize) +check_offset: + MOVD R11, R0 + MOVD 40(RSP), R16 + ADD R16, R0, R0 + CMP R0, R1 + BGT error_match_off_too_big + MOVD 56(RSP), R16 + CMP R16, R1 + BGT error_match_off_too_big + + // Copy match from history + MOVD R1, R0 + SUBS R11, R0, R0 + BLS copy_match + MOVD 48(RSP), R13 + SUB R0, R13, R13 + CMP R0, R12 + BGT copy_all_from_history + MOVD R12, R0 + SUBS $0x10, R0, R0 + BLO copy_4_small + +copy_4_loop: + VLD1 (R13), [V0.B16] + VST1 [V0.B16], (R9) + ADD $0x10, R13, R13 + ADD $0x10, R9, R9 + SUBS $0x10, R0, R0 + BHS copy_4_loop + ADD R0, R13, R13 + ADD $16, R13, R13 + ADD R0, R9, R9 + ADD $16, R9, R9 + ADD $-16, R13, R15 + VLD1 (R15), [V0.B16] + ADD $-16, R9, R15 + VST1 [V0.B16], (R15) + JMP copy_4_end + +copy_4_small: + CMP $0x03, R12 + BEQ copy_4_move_3 + CMP $0x08, R12 + BLO copy_4_move_4through7 + JMP copy_4_move_8through16 + +copy_4_move_3: + MOVH (R13), R0 + MOVB 2(R13), R1 + MOVH R0, (R9) + MOVB R1, 2(R9) + ADD R12, R13, R13 + ADD R12, R9, R9 + JMP copy_4_end + +copy_4_move_4through7: + MOVWU (R13), R0 + ADD R12, R13, R15 + MOVWU -4(R15), R1 + MOVW R0, (R9) + ADD R12, R9, R15 + MOVW R1, -4(R15) + ADD R12, R13, R13 + ADD R12, R9, R9 + JMP copy_4_end + +copy_4_move_8through16: + MOVD (R13), R0 + ADD R12, R13, R15 + MOVD -8(R15), R1 + MOVD R0, (R9) + ADD R12, R9, R15 + MOVD R1, -8(R15) + ADD R12, R13, R13 + ADD R12, R9, R9 + +copy_4_end: + ADD R12, R11, R11 + JMP handle_loop + JMP loop_finished + +copy_all_from_history: + MOVD R0, R14 + SUBS $0x10, R14, R14 + BLO copy_5_small + +copy_5_loop: + VLD1 (R13), [V0.B16] + VST1 [V0.B16], (R9) + ADD $0x10, R13, R13 + ADD $0x10, R9, R9 + SUBS $0x10, R14, R14 + BHS copy_5_loop + ADD R14, R13, R13 + ADD $16, R13, R13 + ADD R14, R9, R9 + ADD $16, R9, R9 + ADD $-16, R13, R15 + VLD1 (R15), [V0.B16] + ADD $-16, R9, R15 + VST1 [V0.B16], (R15) + JMP copy_5_end + +copy_5_small: + CMP $0x03, R0 + BEQ copy_5_move_3 + BLO copy_5_move_1or2 + CMP $0x08, R0 + BLO copy_5_move_4through7 + JMP copy_5_move_8through16 + +copy_5_move_1or2: + MOVB (R13), R14 + ADD R0, R13, R15 + MOVB -1(R15), R4 + MOVB R14, (R9) + ADD R0, R9, R15 + MOVB R4, -1(R15) + ADD R0, R13, R13 + ADD R0, R9, R9 + JMP copy_5_end + +copy_5_move_3: + MOVH (R13), R14 + MOVB 2(R13), R4 + MOVH R14, (R9) + MOVB R4, 2(R9) + ADD R0, R13, R13 + ADD R0, R9, R9 + JMP copy_5_end + +copy_5_move_4through7: + MOVWU (R13), R14 + ADD R0, R13, R15 + MOVWU -4(R15), R4 + MOVW R14, (R9) + ADD R0, R9, R15 + MOVW R4, -4(R15) + ADD R0, R13, R13 + ADD R0, R9, R9 + JMP copy_5_end + +copy_5_move_8through16: + MOVD (R13), R14 + ADD R0, R13, R15 + MOVD -8(R15), R4 + MOVD R14, (R9) + ADD R0, R9, R15 + MOVD R4, -8(R15) + ADD R0, R13, R13 + ADD R0, R9, R9 + +copy_5_end: + ADD R0, R11, R11 + SUB R0, R12, R12 + + // Copy match from the current buffer +copy_match: + MOVD R9, R0 + SUB R1, R0, R0 + + // ml <= mo + CMP R1, R12 + BHI copy_overlapping_match + + // Copy non-overlapping match + ADD R12, R11, R11 + MOVD R9, R1 + ADD R12, R9, R9 + +copy_2: + VLD1 (R0), [V0.B16] + VST1 [V0.B16], (R1) + ADD $0x10, R0, R0 + ADD $0x10, R1, R1 + SUBS $0x10, R12, R12 + BHI copy_2 + JMP handle_loop + + // Copy overlapping match +copy_overlapping_match: + ADD R12, R11, R11 + +copy_slow_3: + MOVB (R0), R1 + MOVB R1, (R9) + ADD $1, R0, R0 + ADD $1, R9, R9 + SUBS $1, R12, R12 + BNE copy_slow_3 + +handle_loop: + MOVD ctx+16(FP), R0 + MOVD 96(R0), R16 + SUBS $1, R16, R16 + MOVD R16, 96(R0) + BPL sequenceDecs_decodeSync_amd64_main_loop + +loop_finished: + MOVD br+8(FP), R0 + MOVD R2, 24(R0) + MOVB R3, 40(R0) + MOVD R5, 32(R0) + + // Update the context + MOVD ctx+16(FP), R0 + MOVD R11, 136(R0) + MOVD 144(R0), R1 + SUB R1, R10, R10 + MOVD R10, 168(R0) + + // Return success + MOVD $0x00000000, R16 + MOVD R16, ret+24(FP) + RET + + // Return with match length error +sequenceDecs_decodeSync_amd64_error_match_len_ofs_mismatch: + MOVD 16(RSP), R0 + MOVD ctx+16(FP), R1 + MOVD R0, 216(R1) + MOVD $0x00000001, R16 + MOVD R16, ret+24(FP) + RET + + // Return with match too long error +sequenceDecs_decodeSync_amd64_error_match_len_too_big: + MOVD ctx+16(FP), R0 + MOVD 16(RSP), R1 + MOVD R1, 216(R0) + MOVD $0x00000002, R16 + MOVD R16, ret+24(FP) + RET + + // Return with match offset too long error +error_match_off_too_big: + MOVD ctx+16(FP), R0 + MOVD 8(RSP), R1 + MOVD R1, 224(R0) + MOVD R11, 136(R0) + MOVD $0x00000003, R16 + MOVD R16, ret+24(FP) + RET + + // Return with not enough literals error +error_not_enough_literals: + MOVD ctx+16(FP), R0 + MOVD 24(RSP), R1 + MOVD R1, 208(R0) + MOVD $0x00000004, R16 + MOVD R16, ret+24(FP) + RET + + // Return with overread error +error_overread: + MOVD $0x00000006, R16 + MOVD R16, ret+24(FP) + RET + + // Return with not enough output space error +error_not_enough_space: + MOVD ctx+16(FP), R0 + MOVD 24(RSP), R1 + MOVD R1, 208(R0) + MOVD 16(RSP), R1 + MOVD R1, 216(R0) + MOVD R11, 136(R0) + MOVD $0x00000005, R16 + MOVD R16, ret+24(FP) + RET + +// skipped sequenceDecs_decodeSync_bmi2 (BMI2 not available on arm64) + +// func sequenceDecs_decodeSync_safe_amd64(s *sequenceDecs, br *bitReader, ctx *decodeSyncAsmContext) int +// Requires: CMOV, SSE +TEXT ·sequenceDecs_decodeSync_safe_arm64(SB), $64-32 + MOVD br+8(FP), R1 + MOVD 24(R1), R2 + MOVBU 40(R1), R3 + MOVD (R1), R0 + MOVD 32(R1), R5 + ADD R5, R0, R0 + MOVD R0, (RSP) + MOVD ctx+16(FP), R0 + MOVD 72(R0), R6 + MOVD 80(R0), R7 + MOVD 88(R0), R8 + MOVD $0, R1 + MOVD R1, 8(RSP) + MOVD R1, 16(RSP) + MOVD R1, 24(RSP) + MOVD 112(R0), R9 + MOVD 128(R0), R1 + MOVD R1, 32(RSP) + MOVD 144(R0), R10 + MOVD 136(R0), R11 + MOVD 200(R0), R1 + MOVD R1, 56(RSP) + MOVD 176(R0), R1 + MOVD R1, 48(RSP) + MOVD 184(R0), R0 + MOVD R0, 40(RSP) + MOVD 40(RSP), R0 + MOVD 48(RSP), R16 + ADD R0, R16, R16 + MOVD R16, 48(RSP) + + // Calculate pointer to s.out[cap(s.out)] (a past-end pointer) + MOVD 32(RSP), R16 + ADD R9, R16, R16 + MOVD R16, 32(RSP) + + // outBase += outPosition + ADD R11, R9, R9 + +sequenceDecs_decodeSync_safe_amd64_main_loop: + MOVD (RSP), R12 + + // Fill bitreader to have enough for the offset and match length. + CMP $0x08, R5 + BLT sequenceDecs_decodeSync_safe_amd64_fill_byte_by_byte + MOVD R3, R0 + LSR $0x03, R0, R0 + SUB R0, R12, R12 + MOVD (R12), R2 + SUB R0, R5, R5 + AND $0x07, R3, R3 + JMP sequenceDecs_decodeSync_safe_amd64_fill_end + +sequenceDecs_decodeSync_safe_amd64_fill_byte_by_byte: + CMP $0x00, R5 + BLE sequenceDecs_decodeSync_safe_amd64_fill_check_overread + CMP $0x07, R3 + BLE sequenceDecs_decodeSync_safe_amd64_fill_end + LSL $0x08, R2, R2 + SUB $0x01, R12, R12 + SUB $0x01, R5, R5 + SUB $0x08, R3, R3 + MOVBU (R12), R0 + ORR R0, R2, R2 + JMP sequenceDecs_decodeSync_safe_amd64_fill_byte_by_byte + +sequenceDecs_decodeSync_safe_amd64_fill_check_overread: + CMP $0x40, R3 + BHI error_overread + +sequenceDecs_decodeSync_safe_amd64_fill_end: + // Update offset + MOVD R8, R0 + MOVD R3, R1 + MOVD R2, R13 + LSL R1, R13, R13 + UBFX $8, R0, $8, R1 + LSR $0x20, R0, R0 + TST R1, R1 + BEQ sequenceDecs_decodeSync_safe_amd64_of_update_zero + ADD R1, R3, R3 + CMP $0x40, R3 + BHI sequenceDecs_decodeSync_safe_amd64_of_update_zero + CMP $0x40, R1 + BHS sequenceDecs_decodeSync_safe_amd64_of_update_zero + NEG R1, R1 + LSR R1, R13, R13 + ADD R13, R0, R0 + +sequenceDecs_decodeSync_safe_amd64_of_update_zero: + MOVD R0, 8(RSP) + + // Update match length + MOVD R7, R0 + MOVD R3, R1 + MOVD R2, R13 + LSL R1, R13, R13 + UBFX $8, R0, $8, R1 + LSR $0x20, R0, R0 + TST R1, R1 + BEQ sequenceDecs_decodeSync_safe_amd64_ml_update_zero + ADD R1, R3, R3 + CMP $0x40, R3 + BHI sequenceDecs_decodeSync_safe_amd64_ml_update_zero + CMP $0x40, R1 + BHS sequenceDecs_decodeSync_safe_amd64_ml_update_zero + NEG R1, R1 + LSR R1, R13, R13 + ADD R13, R0, R0 + +sequenceDecs_decodeSync_safe_amd64_ml_update_zero: + MOVD R0, 16(RSP) + + // Fill bitreader to have enough for the remaining + CMP $0x08, R5 + BLT sequenceDecs_decodeSync_safe_amd64_fill_2_byte_by_byte + MOVD R3, R0 + LSR $0x03, R0, R0 + SUB R0, R12, R12 + MOVD (R12), R2 + SUB R0, R5, R5 + AND $0x07, R3, R3 + JMP sequenceDecs_decodeSync_safe_amd64_fill_2_end + +sequenceDecs_decodeSync_safe_amd64_fill_2_byte_by_byte: + CMP $0x00, R5 + BLE sequenceDecs_decodeSync_safe_amd64_fill_2_check_overread + CMP $0x07, R3 + BLE sequenceDecs_decodeSync_safe_amd64_fill_2_end + LSL $0x08, R2, R2 + SUB $0x01, R12, R12 + SUB $0x01, R5, R5 + SUB $0x08, R3, R3 + MOVBU (R12), R0 + ORR R0, R2, R2 + JMP sequenceDecs_decodeSync_safe_amd64_fill_2_byte_by_byte + +sequenceDecs_decodeSync_safe_amd64_fill_2_check_overread: + CMP $0x40, R3 + BHI error_overread + +sequenceDecs_decodeSync_safe_amd64_fill_2_end: + // Update literal length + MOVD R6, R0 + MOVD R3, R1 + MOVD R2, R13 + LSL R1, R13, R13 + UBFX $8, R0, $8, R1 + LSR $0x20, R0, R0 + TST R1, R1 + BEQ sequenceDecs_decodeSync_safe_amd64_ll_update_zero + ADD R1, R3, R3 + CMP $0x40, R3 + BHI sequenceDecs_decodeSync_safe_amd64_ll_update_zero + CMP $0x40, R1 + BHS sequenceDecs_decodeSync_safe_amd64_ll_update_zero + NEG R1, R1 + LSR R1, R13, R13 + ADD R13, R0, R0 + +sequenceDecs_decodeSync_safe_amd64_ll_update_zero: + MOVD R0, 24(RSP) + + // Fill bitreader for state updates + MOVD R12, (RSP) + MOVD R8, R0 + LSR $0x08, R0, R0 + MOVBU R0, R0 + MOVD ctx+16(FP), R1 + MOVD 96(R1), R16 + CMP $0x00, R16 + BEQ sequenceDecs_decodeSync_safe_amd64_skip_update + + // Update Literal Length State + MOVBU R6, R12 + LSRW $0x10, R6, R6 + ADD R12, R3, R1 + MOVD R2, R13 + MOVD R1, R3 + NEG R1, R16 + ROR R16, R13, R13 + MOVD $0x00000001, R14 + MOVB R12, R1 + LSLW R1, R14, R14 + SUBW $1, R14, R14 + AND R14, R13, R13 + ADD R13, R6, R6 + + // Load ctx.llTable + MOVD ctx+16(FP), R1 + MOVD (R1), R1 + ADD R6<<3, R1, R15 + MOVD (R15), R6 + + // Update Match Length State + MOVBU R7, R12 + LSRW $0x10, R7, R7 + ADD R12, R3, R1 + MOVD R2, R13 + MOVD R1, R3 + NEG R1, R16 + ROR R16, R13, R13 + MOVD $0x00000001, R14 + MOVB R12, R1 + LSLW R1, R14, R14 + SUBW $1, R14, R14 + AND R14, R13, R13 + ADD R13, R7, R7 + + // Load ctx.mlTable + MOVD ctx+16(FP), R1 + MOVD 24(R1), R1 + ADD R7<<3, R1, R15 + MOVD (R15), R7 + + // Update Offset State + MOVBU R8, R12 + LSRW $0x10, R8, R8 + ADD R12, R3, R1 + MOVD R2, R13 + MOVD R1, R3 + NEG R1, R16 + ROR R16, R13, R13 + MOVD $0x00000001, R14 + MOVB R12, R1 + LSLW R1, R14, R14 + SUBW $1, R14, R14 + AND R14, R13, R13 + ADD R13, R8, R8 + + // Load ctx.ofTable + MOVD ctx+16(FP), R1 + MOVD 48(R1), R1 + ADD R8<<3, R1, R15 + MOVD (R15), R8 + +sequenceDecs_decodeSync_safe_amd64_skip_update: + // Adjust offset + MOVD s+0(FP), R1 + MOVD 8(RSP), R12 + CMP $0x01, R0 + BLS sequenceDecs_decodeSync_safe_amd64_adjust_offsetB_1_or_0 + ADD $144, R1, R15 + VLD1 (R15), [V0.B16] + MOVD R12, 144(R1) + ADD $152, R1, R15 + VST1 [V0.B16], (R15) + JMP sequenceDecs_decodeSync_safe_amd64_after_adjust + +sequenceDecs_decodeSync_safe_amd64_adjust_offsetB_1_or_0: + MOVD 24(RSP), R16 + CMP $0x00000000, R16 + BNE sequenceDecs_decodeSync_safe_amd64_adjust_offset_maybezero + ADD $1, R12, R12 + JMP sequenceDecs_decodeSync_safe_amd64_adjust_offset_nonzero + +sequenceDecs_decodeSync_safe_amd64_adjust_offset_maybezero: + TST R12, R12 + BNE sequenceDecs_decodeSync_safe_amd64_adjust_offset_nonzero + MOVD 144(R1), R12 + JMP sequenceDecs_decodeSync_safe_amd64_after_adjust + +sequenceDecs_decodeSync_safe_amd64_adjust_offset_nonzero: + MOVD R12, R0 + MOVD $0, R13 + MOVD $-1, R14 + CMP $0x03, R12 + CSEL EQ, R13, R0, R0 + CSEL EQ, R14, R13, R13 + ADD R0<<3, R1, R15 + MOVD 144(R15), R16 + ADDS R16, R13, R13 + BNE sequenceDecs_decodeSync_safe_amd64_adjust_temp_valid + MOVD $0x00000001, R13 + +sequenceDecs_decodeSync_safe_amd64_adjust_temp_valid: + CMP $0x01, R12 + BEQ sequenceDecs_decodeSync_safe_amd64_adjust_skip + MOVD 152(R1), R0 + MOVD R0, 160(R1) + +sequenceDecs_decodeSync_safe_amd64_adjust_skip: + MOVD 144(R1), R0 + MOVD R0, 152(R1) + MOVD R13, 144(R1) + MOVD R13, R12 + +sequenceDecs_decodeSync_safe_amd64_after_adjust: + MOVD R12, 8(RSP) + + // Check values + MOVD 16(RSP), R0 + MOVD 24(RSP), R1 + ADD R1, R0, R13 + MOVD s+0(FP), R14 + MOVD 256(R14), R16 + ADD R13, R16, R16 + MOVD R16, 256(R14) + MOVD ctx+16(FP), R13 + MOVD 104(R13), R16 + SUBS R1, R16, R16 + MOVD R16, 104(R13) + BMI error_not_enough_literals + CMP $0x00020002, R0 + BHI sequenceDecs_decodeSync_safe_amd64_error_match_len_too_big + TST R12, R12 + BNE sequenceDecs_decodeSync_safe_amd64_match_len_ofs_ok + TST R0, R0 + BNE sequenceDecs_decodeSync_safe_amd64_error_match_len_ofs_mismatch + +sequenceDecs_decodeSync_safe_amd64_match_len_ofs_ok: + MOVD 24(RSP), R0 + MOVD 8(RSP), R1 + MOVD 16(RSP), R12 + + // Check if we have enough space in s.out + ADD R12, R0, R13 + ADD R9, R13, R13 + MOVD 32(RSP), R16 + CMP R16, R13 + BHI error_not_enough_space + + // Copy literals + TST R0, R0 + BEQ check_offset + MOVD R0, R13 + SUBS $0x10, R13, R13 + BLO copy_1_small + +copy_1_loop: + VLD1 (R10), [V0.B16] + VST1 [V0.B16], (R9) + ADD $0x10, R10, R10 + ADD $0x10, R9, R9 + SUBS $0x10, R13, R13 + BHS copy_1_loop + ADD R13, R10, R10 + ADD $16, R10, R10 + ADD R13, R9, R9 + ADD $16, R9, R9 + ADD $-16, R10, R15 + VLD1 (R15), [V0.B16] + ADD $-16, R9, R15 + VST1 [V0.B16], (R15) + JMP copy_1_end + +copy_1_small: + CMP $0x03, R0 + BEQ copy_1_move_3 + BLO copy_1_move_1or2 + CMP $0x08, R0 + BLO copy_1_move_4through7 + JMP copy_1_move_8through16 + +copy_1_move_1or2: + MOVB (R10), R13 + ADD R0, R10, R15 + MOVB -1(R15), R14 + MOVB R13, (R9) + ADD R0, R9, R15 + MOVB R14, -1(R15) + ADD R0, R10, R10 + ADD R0, R9, R9 + JMP copy_1_end + +copy_1_move_3: + MOVH (R10), R13 + MOVB 2(R10), R14 + MOVH R13, (R9) + MOVB R14, 2(R9) + ADD R0, R10, R10 + ADD R0, R9, R9 + JMP copy_1_end + +copy_1_move_4through7: + MOVWU (R10), R13 + ADD R0, R10, R15 + MOVWU -4(R15), R14 + MOVW R13, (R9) + ADD R0, R9, R15 + MOVW R14, -4(R15) + ADD R0, R10, R10 + ADD R0, R9, R9 + JMP copy_1_end + +copy_1_move_8through16: + MOVD (R10), R13 + ADD R0, R10, R15 + MOVD -8(R15), R14 + MOVD R13, (R9) + ADD R0, R9, R15 + MOVD R14, -8(R15) + ADD R0, R10, R10 + ADD R0, R9, R9 + +copy_1_end: + ADD R0, R11, R11 + + // Malformed input if seq.mo > t+len(hist) || seq.mo > s.windowSize) +check_offset: + MOVD R11, R0 + MOVD 40(RSP), R16 + ADD R16, R0, R0 + CMP R0, R1 + BGT error_match_off_too_big + MOVD 56(RSP), R16 + CMP R16, R1 + BGT error_match_off_too_big + + // Copy match from history + MOVD R1, R0 + SUBS R11, R0, R0 + BLS copy_match + MOVD 48(RSP), R13 + SUB R0, R13, R13 + CMP R0, R12 + BGT copy_all_from_history + MOVD R12, R0 + SUBS $0x10, R0, R0 + BLO copy_4_small + +copy_4_loop: + VLD1 (R13), [V0.B16] + VST1 [V0.B16], (R9) + ADD $0x10, R13, R13 + ADD $0x10, R9, R9 + SUBS $0x10, R0, R0 + BHS copy_4_loop + ADD R0, R13, R13 + ADD $16, R13, R13 + ADD R0, R9, R9 + ADD $16, R9, R9 + ADD $-16, R13, R15 + VLD1 (R15), [V0.B16] + ADD $-16, R9, R15 + VST1 [V0.B16], (R15) + JMP copy_4_end + +copy_4_small: + CMP $0x03, R12 + BEQ copy_4_move_3 + CMP $0x08, R12 + BLO copy_4_move_4through7 + JMP copy_4_move_8through16 + +copy_4_move_3: + MOVH (R13), R0 + MOVB 2(R13), R1 + MOVH R0, (R9) + MOVB R1, 2(R9) + ADD R12, R13, R13 + ADD R12, R9, R9 + JMP copy_4_end + +copy_4_move_4through7: + MOVWU (R13), R0 + ADD R12, R13, R15 + MOVWU -4(R15), R1 + MOVW R0, (R9) + ADD R12, R9, R15 + MOVW R1, -4(R15) + ADD R12, R13, R13 + ADD R12, R9, R9 + JMP copy_4_end + +copy_4_move_8through16: + MOVD (R13), R0 + ADD R12, R13, R15 + MOVD -8(R15), R1 + MOVD R0, (R9) + ADD R12, R9, R15 + MOVD R1, -8(R15) + ADD R12, R13, R13 + ADD R12, R9, R9 + +copy_4_end: + ADD R12, R11, R11 + JMP handle_loop + JMP loop_finished + +copy_all_from_history: + MOVD R0, R14 + SUBS $0x10, R14, R14 + BLO copy_5_small + +copy_5_loop: + VLD1 (R13), [V0.B16] + VST1 [V0.B16], (R9) + ADD $0x10, R13, R13 + ADD $0x10, R9, R9 + SUBS $0x10, R14, R14 + BHS copy_5_loop + ADD R14, R13, R13 + ADD $16, R13, R13 + ADD R14, R9, R9 + ADD $16, R9, R9 + ADD $-16, R13, R15 + VLD1 (R15), [V0.B16] + ADD $-16, R9, R15 + VST1 [V0.B16], (R15) + JMP copy_5_end + +copy_5_small: + CMP $0x03, R0 + BEQ copy_5_move_3 + BLO copy_5_move_1or2 + CMP $0x08, R0 + BLO copy_5_move_4through7 + JMP copy_5_move_8through16 + +copy_5_move_1or2: + MOVB (R13), R14 + ADD R0, R13, R15 + MOVB -1(R15), R4 + MOVB R14, (R9) + ADD R0, R9, R15 + MOVB R4, -1(R15) + ADD R0, R13, R13 + ADD R0, R9, R9 + JMP copy_5_end + +copy_5_move_3: + MOVH (R13), R14 + MOVB 2(R13), R4 + MOVH R14, (R9) + MOVB R4, 2(R9) + ADD R0, R13, R13 + ADD R0, R9, R9 + JMP copy_5_end + +copy_5_move_4through7: + MOVWU (R13), R14 + ADD R0, R13, R15 + MOVWU -4(R15), R4 + MOVW R14, (R9) + ADD R0, R9, R15 + MOVW R4, -4(R15) + ADD R0, R13, R13 + ADD R0, R9, R9 + JMP copy_5_end + +copy_5_move_8through16: + MOVD (R13), R14 + ADD R0, R13, R15 + MOVD -8(R15), R4 + MOVD R14, (R9) + ADD R0, R9, R15 + MOVD R4, -8(R15) + ADD R0, R13, R13 + ADD R0, R9, R9 + +copy_5_end: + ADD R0, R11, R11 + SUB R0, R12, R12 + + // Copy match from the current buffer +copy_match: + MOVD R9, R0 + SUB R1, R0, R0 + + // ml <= mo + CMP R1, R12 + BHI copy_overlapping_match + + // Copy non-overlapping match + ADD R12, R11, R11 + MOVD R12, R1 + SUBS $0x10, R1, R1 + BLO copy_2_small + +copy_2_loop: + VLD1 (R0), [V0.B16] + VST1 [V0.B16], (R9) + ADD $0x10, R0, R0 + ADD $0x10, R9, R9 + SUBS $0x10, R1, R1 + BHS copy_2_loop + ADD R1, R0, R0 + ADD $16, R0, R0 + ADD R1, R9, R9 + ADD $16, R9, R9 + ADD $-16, R0, R15 + VLD1 (R15), [V0.B16] + ADD $-16, R9, R15 + VST1 [V0.B16], (R15) + JMP copy_2_end + +copy_2_small: + CMP $0x03, R12 + BEQ copy_2_move_3 + BLO copy_2_move_1or2 + CMP $0x08, R12 + BLO copy_2_move_4through7 + JMP copy_2_move_8through16 + +copy_2_move_1or2: + MOVB (R0), R1 + ADD R12, R0, R15 + MOVB -1(R15), R13 + MOVB R1, (R9) + ADD R12, R9, R15 + MOVB R13, -1(R15) + ADD R12, R0, R0 + ADD R12, R9, R9 + JMP copy_2_end + +copy_2_move_3: + MOVH (R0), R1 + MOVB 2(R0), R13 + MOVH R1, (R9) + MOVB R13, 2(R9) + ADD R12, R0, R0 + ADD R12, R9, R9 + JMP copy_2_end + +copy_2_move_4through7: + MOVWU (R0), R1 + ADD R12, R0, R15 + MOVWU -4(R15), R13 + MOVW R1, (R9) + ADD R12, R9, R15 + MOVW R13, -4(R15) + ADD R12, R0, R0 + ADD R12, R9, R9 + JMP copy_2_end + +copy_2_move_8through16: + MOVD (R0), R1 + ADD R12, R0, R15 + MOVD -8(R15), R13 + MOVD R1, (R9) + ADD R12, R9, R15 + MOVD R13, -8(R15) + ADD R12, R0, R0 + ADD R12, R9, R9 + +copy_2_end: + JMP handle_loop + + // Copy overlapping match +copy_overlapping_match: + ADD R12, R11, R11 + +copy_slow_3: + MOVB (R0), R1 + MOVB R1, (R9) + ADD $1, R0, R0 + ADD $1, R9, R9 + SUBS $1, R12, R12 + BNE copy_slow_3 + +handle_loop: + MOVD ctx+16(FP), R0 + MOVD 96(R0), R16 + SUBS $1, R16, R16 + MOVD R16, 96(R0) + BPL sequenceDecs_decodeSync_safe_amd64_main_loop + +loop_finished: + MOVD br+8(FP), R0 + MOVD R2, 24(R0) + MOVB R3, 40(R0) + MOVD R5, 32(R0) + + // Update the context + MOVD ctx+16(FP), R0 + MOVD R11, 136(R0) + MOVD 144(R0), R1 + SUB R1, R10, R10 + MOVD R10, 168(R0) + + // Return success + MOVD $0x00000000, R16 + MOVD R16, ret+24(FP) + RET + + // Return with match length error +sequenceDecs_decodeSync_safe_amd64_error_match_len_ofs_mismatch: + MOVD 16(RSP), R0 + MOVD ctx+16(FP), R1 + MOVD R0, 216(R1) + MOVD $0x00000001, R16 + MOVD R16, ret+24(FP) + RET + + // Return with match too long error +sequenceDecs_decodeSync_safe_amd64_error_match_len_too_big: + MOVD ctx+16(FP), R0 + MOVD 16(RSP), R1 + MOVD R1, 216(R0) + MOVD $0x00000002, R16 + MOVD R16, ret+24(FP) + RET + + // Return with match offset too long error +error_match_off_too_big: + MOVD ctx+16(FP), R0 + MOVD 8(RSP), R1 + MOVD R1, 224(R0) + MOVD R11, 136(R0) + MOVD $0x00000003, R16 + MOVD R16, ret+24(FP) + RET + + // Return with not enough literals error +error_not_enough_literals: + MOVD ctx+16(FP), R0 + MOVD 24(RSP), R1 + MOVD R1, 208(R0) + MOVD $0x00000004, R16 + MOVD R16, ret+24(FP) + RET + + // Return with overread error +error_overread: + MOVD $0x00000006, R16 + MOVD R16, ret+24(FP) + RET + + // Return with not enough output space error +error_not_enough_space: + MOVD ctx+16(FP), R0 + MOVD 24(RSP), R1 + MOVD R1, 208(R0) + MOVD 16(RSP), R1 + MOVD R1, 216(R0) + MOVD R11, 136(R0) + MOVD $0x00000005, R16 + MOVD R16, ret+24(FP) + RET + +// skipped sequenceDecs_decodeSync_safe_bmi2 (BMI2 not available on arm64) diff --git a/vendor/github.com/klauspost/compress/zstd/seqdec_asm.go b/vendor/github.com/klauspost/compress/zstd/seqdec_asm.go new file mode 100644 index 000000000..55405f391 --- /dev/null +++ b/vendor/github.com/klauspost/compress/zstd/seqdec_asm.go @@ -0,0 +1,289 @@ +//go:build (amd64 || arm64) && !appengine && !noasm && gc + +package zstd + +import ( + "fmt" + "io" +) + +// This file holds the parts of the assembly sequence decoder that are identical +// across architectures: the context structs exchanged with the asm, the error +// codes, and the decode/decodeSync/executeSimple wrappers. Each architecture +// supplies the small dispatch helpers (decodeAsm, decodeSyncAsm, +// executeSimpleAsm) that select the concrete asm routine — amd64 also chooses a +// BMI2 variant, arm64 has a single implementation. + +type decodeSyncAsmContext struct { + llTable []decSymbol + mlTable []decSymbol + ofTable []decSymbol + llState uint64 + mlState uint64 + ofState uint64 + iteration int + litRemain int + out []byte + outPosition int + literals []byte + litPosition int + history []byte + windowSize int + ll int // set on error (not for all errors, please refer to _generate/gen.go) + ml int // set on error (not for all errors, please refer to _generate/gen.go) + mo int // set on error (not for all errors, please refer to _generate/gen.go) +} + +type decodeAsmContext struct { + llTable []decSymbol + mlTable []decSymbol + ofTable []decSymbol + llState uint64 + mlState uint64 + ofState uint64 + iteration int + seqs []seqVals + litRemain int +} + +type executeAsmContext struct { + seqs []seqVals + seqIndex int + out []byte + history []byte + literals []byte + outPosition int + litPosition int + windowSize int +} + +const noError = 0 + +// error reported when mo == 0 && ml > 0 +const errorMatchLenOfsMismatch = 1 + +// error reported when ml > maxMatchLen +const errorMatchLenTooBig = 2 + +// error reported when mo > available history or mo > s.windowSize +const errorMatchOffTooBig = 3 + +// error reported when the sum of literal lengths exeeceds the literal buffer size +const errorNotEnoughLiterals = 4 + +// error reported when capacity of `out` is too small +const errorNotEnoughSpace = 5 + +// error reported when bits are overread. +const errorOverread = 6 + +// decode sequences from the stream with the provided history but without a dictionary. +func (s *sequenceDecs) decodeSyncSimple(hist []byte) (bool, error) { + if len(s.dict) > 0 { + return false, nil + } + if s.maxSyncLen == 0 && cap(s.out)-len(s.out) < maxCompressedBlockSize { + return false, nil + } + + // FIXME: Using unsafe memory copies leads to rare, random crashes + // with fuzz testing. It is therefore disabled for now. + const useSafe = true + + br := s.br + + maxBlockSize := min(s.windowSize, maxCompressedBlockSize) + + ctx := decodeSyncAsmContext{ + llTable: s.litLengths.fse.dt[:maxTablesize], + mlTable: s.matchLengths.fse.dt[:maxTablesize], + ofTable: s.offsets.fse.dt[:maxTablesize], + llState: uint64(s.litLengths.state.state), + mlState: uint64(s.matchLengths.state.state), + ofState: uint64(s.offsets.state.state), + iteration: s.nSeqs - 1, + litRemain: len(s.literals), + out: s.out, + outPosition: len(s.out), + literals: s.literals, + windowSize: s.windowSize, + history: hist, + } + + s.seqSize = 0 + startSize := len(s.out) + + errCode := decodeSyncAsm(s, br, &ctx, useSafe) + switch errCode { + case noError: + break + + case errorMatchLenOfsMismatch: + return true, fmt.Errorf("zero matchoff and matchlen (%d) > 0", ctx.ml) + + case errorMatchLenTooBig: + return true, fmt.Errorf("match len (%d) bigger than max allowed length", ctx.ml) + + case errorMatchOffTooBig: + return true, fmt.Errorf("match offset (%d) bigger than current history (%d)", + ctx.mo, ctx.outPosition+len(hist)-startSize) + + case errorNotEnoughLiterals: + return true, fmt.Errorf("unexpected literal count, want %d bytes, but only %d is available", + ctx.ll, ctx.litRemain+ctx.ll) + + case errorOverread: + return true, io.ErrUnexpectedEOF + + case errorNotEnoughSpace: + size := ctx.outPosition + ctx.ll + ctx.ml + if debugDecoder { + println("msl:", s.maxSyncLen, "cap", cap(s.out), "bef:", startSize, "sz:", size-startSize, "mbs:", maxBlockSize, "outsz:", cap(s.out)-startSize) + } + return true, fmt.Errorf("output bigger than max block size (%d)", maxBlockSize) + + default: + return true, fmt.Errorf("sequenceDecs_decode returned erroneous code %d", errCode) + } + + s.seqSize += ctx.litRemain + if s.seqSize > maxBlockSize { + return true, fmt.Errorf("output bigger than max block size (%d)", maxBlockSize) + } + err := br.close() + if err != nil { + printf("Closing sequences: %v, %+v\n", err, *br) + return true, err + } + + s.literals = s.literals[ctx.litPosition:] + t := ctx.outPosition + s.out = s.out[:t] + + // Add final literals + s.out = append(s.out, s.literals...) + if debugDecoder { + t += len(s.literals) + if t != len(s.out) { + panic(fmt.Errorf("length mismatch, want %d, got %d", len(s.out), t)) + } + } + + return true, nil +} + +// decode sequences from the stream without the provided history. +func (s *sequenceDecs) decode(seqs []seqVals) error { + br := s.br + + maxBlockSize := min(s.windowSize, maxCompressedBlockSize) + + ctx := decodeAsmContext{ + llTable: s.litLengths.fse.dt[:maxTablesize], + mlTable: s.matchLengths.fse.dt[:maxTablesize], + ofTable: s.offsets.fse.dt[:maxTablesize], + llState: uint64(s.litLengths.state.state), + mlState: uint64(s.matchLengths.state.state), + ofState: uint64(s.offsets.state.state), + seqs: seqs, + iteration: len(seqs) - 1, + litRemain: len(s.literals), + } + + if debugDecoder { + println("decode: decoding", len(seqs), "sequences", br.remain(), "bits remain on stream") + } + + s.seqSize = 0 + lte56bits := s.maxBits+s.offsets.fse.actualTableLog+s.matchLengths.fse.actualTableLog+s.litLengths.fse.actualTableLog <= 56 + errCode := decodeAsm(s, br, &ctx, lte56bits) + if errCode != 0 { + i := len(seqs) - ctx.iteration - 1 + switch errCode { + case errorMatchLenOfsMismatch: + ml := ctx.seqs[i].ml + return fmt.Errorf("zero matchoff and matchlen (%d) > 0", ml) + + case errorMatchLenTooBig: + ml := ctx.seqs[i].ml + return fmt.Errorf("match len (%d) bigger than max allowed length", ml) + + case errorNotEnoughLiterals: + ll := ctx.seqs[i].ll + return fmt.Errorf("unexpected literal count, want %d bytes, but only %d is available", ll, ctx.litRemain+ll) + case errorOverread: + return io.ErrUnexpectedEOF + } + + return fmt.Errorf("sequenceDecs_decode_amd64 returned erroneous code %d", errCode) + } + + if ctx.litRemain < 0 { + return fmt.Errorf("literal count is too big: total available %d, total requested %d", + len(s.literals), len(s.literals)-ctx.litRemain) + } + + s.seqSize += ctx.litRemain + if s.seqSize > maxBlockSize { + return fmt.Errorf("output bigger than max block size (%d)", maxBlockSize) + } + if debugDecoder { + println("decode: ", br.remain(), "bits remain on stream. code:", errCode) + } + err := br.close() + if err != nil { + printf("Closing sequences: %v, %+v\n", err, *br) + } + return err +} + +// executeSimple handles cases when dictionary is not used. +func (s *sequenceDecs) executeSimple(seqs []seqVals, hist []byte) error { + // Ensure we have enough output size... + if len(s.out)+s.seqSize+compressedBlockOverAlloc > cap(s.out) { + addBytes := s.seqSize + len(s.out) + compressedBlockOverAlloc + s.out = append(s.out, make([]byte, addBytes)...) + s.out = s.out[:len(s.out)-addBytes] + } + + if debugDecoder { + printf("Execute %d seqs with literals: %d into %d bytes\n", len(seqs), len(s.literals), s.seqSize) + } + + var t = len(s.out) + out := s.out[:t+s.seqSize] + + ctx := executeAsmContext{ + seqs: seqs, + seqIndex: 0, + out: out, + history: hist, + outPosition: t, + litPosition: 0, + literals: s.literals, + windowSize: s.windowSize, + } + // useSafe avoids overwriting the output buffer when the literals slice has + // not been allocated with the required over-allocation slack. + useSafe := cap(s.literals) < len(s.literals)+compressedBlockOverAlloc + + ok := executeSimpleAsm(&ctx, useSafe) + if !ok { + return fmt.Errorf("match offset (%d) bigger than current history (%d)", + seqs[ctx.seqIndex].mo, ctx.outPosition+len(hist)) + } + s.literals = s.literals[ctx.litPosition:] + t = ctx.outPosition + + // Add final literals + copy(out[t:], s.literals) + if debugDecoder { + t += len(s.literals) + if t != len(out) { + panic(fmt.Errorf("length mismatch, want %d, got %d, ss: %d", len(out), t, s.seqSize)) + } + } + s.out = out + + return nil +} diff --git a/vendor/github.com/klauspost/compress/zstd/seqdec_generic.go b/vendor/github.com/klauspost/compress/zstd/seqdec_generic.go index 516cd9b07..8a3db6ba2 100644 --- a/vendor/github.com/klauspost/compress/zstd/seqdec_generic.go +++ b/vendor/github.com/klauspost/compress/zstd/seqdec_generic.go @@ -1,4 +1,4 @@ -//go:build !amd64 || appengine || !gc || noasm +//go:build (!amd64 && !arm64) || appengine || !gc || noasm package zstd diff --git a/vendor/modules.txt b/vendor/modules.txt index b14ed144f..ef9ff5735 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -230,7 +230,7 @@ github.com/jhump/protoreflect/v2/internal/reparse github.com/jhump/protoreflect/v2/internal/sort github.com/jhump/protoreflect/v2/protoresolve github.com/jhump/protoreflect/v2/sourceinfo -# github.com/klauspost/compress v1.18.5 +# github.com/klauspost/compress v1.19.0 ## explicit; go 1.24 github.com/klauspost/compress github.com/klauspost/compress/flate From cf64e715cd0ef04803caa45da59870756412af59 Mon Sep 17 00:00:00 2001 From: Mihail Stoykov <312246+mstoykov@users.noreply.github.com> Date: Fri, 17 Jul 2026 14:43:45 +0300 Subject: [PATCH 027/182] refactor(cloudapi): share 401/403 error classification between v1 and v6 clients (#6159) * refactor(cloudapi): share 401/403 error classification between v1 and v6 clients cloudapi.CheckResponse and internal/cloudapi/v6.CheckResponse each independently defined their own errNotAuthenticated/errNotAuthorized sentinel errors and duplicated the same "401 -> not authenticated, 403 -> not authorized" branching. Extract that single genuinely shared piece into a small internal/cloudapi/httperr package (ErrNotAuthenticated, ErrNotAuthorized, ClassifyStatus), and have both clients use it instead of maintaining separate sentinel instances with identical message text. * test: drop redundant httperr test, trim comments ClassifyStatus's 401/403 mapping is already exercised directly by cloudapi's and v6's own CheckResponse tests (both assert on httperr.ErrNotAuthenticated/ErrNotAuthorized for those status codes), so a dedicated unit test for the same three-way switch adds nothing. Also trims the package/var doc comments down to what isn't already obvious from the names. --- cloudapi/client.go | 8 ++--- cloudapi/errors.go | 6 +--- cloudapi/errors_test.go | 54 ++++++++++++++++++++++++++++ internal/cloudapi/httperr/httperr.go | 31 ++++++++++++++++ internal/cloudapi/v6/client.go | 8 ++--- internal/cloudapi/v6/client_test.go | 5 +-- internal/cloudapi/v6/errors.go | 6 ++-- 7 files changed, 97 insertions(+), 21 deletions(-) create mode 100644 internal/cloudapi/httperr/httperr.go diff --git a/cloudapi/client.go b/cloudapi/client.go index 4379ba9a8..8fbcfe519 100644 --- a/cloudapi/client.go +++ b/cloudapi/client.go @@ -13,6 +13,7 @@ import ( "time" "github.com/sirupsen/logrus" + "go.k6.io/k6/v2/internal/cloudapi/httperr" ) const ( @@ -204,11 +205,8 @@ func CheckResponse(r *http.Response) error { Error ResponseError `json:"error"` } if err := json.Unmarshal(data, &payload); err != nil { - if r.StatusCode == http.StatusUnauthorized { - return errNotAuthenticated - } - if r.StatusCode == http.StatusForbidden { - return errNotAuthorized + if classified := httperr.ClassifyStatus(r.StatusCode); classified != nil { + return classified } return fmt.Errorf( "unexpected HTTP error from %s: %d %s", diff --git a/cloudapi/errors.go b/cloudapi/errors.go index 669f3df76..0f18f689a 100644 --- a/cloudapi/errors.go +++ b/cloudapi/errors.go @@ -8,11 +8,7 @@ import ( "strings" ) -var ( - errNotAuthorized = errors.New("not allowed to upload result to k6 Cloud") - errNotAuthenticated = errors.New("failed to authenticate with k6 Cloud") - errUnknown = errors.New("an error occurred communicating with k6 Cloud") -) +var errUnknown = errors.New("an error occurred communicating with k6 Cloud") // ResponseError represents an error cause by talking to the API type ResponseError struct { diff --git a/cloudapi/errors_test.go b/cloudapi/errors_test.go index 631ab3e35..850853507 100644 --- a/cloudapi/errors_test.go +++ b/cloudapi/errors_test.go @@ -1,9 +1,13 @@ package cloudapi import ( + "io" + "net/http" + "strings" "testing" "github.com/stretchr/testify/assert" + "go.k6.io/k6/v2/internal/cloudapi/httperr" ) func TestContains(t *testing.T) { @@ -33,3 +37,53 @@ func TestErrorResponse_Error(t *testing.T) { expected := "(E123) " + msg1 + "\n " + msg2 + "\n field1: error1, error2" assert.Equal(t, expected, errResp.Error()) } + +func TestCheckResponse(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + response *http.Response + expectedError error + }{ + { + name: "nil response", + response: nil, + expectedError: errUnknown, + }, + { + name: "successful response 200", + response: &http.Response{StatusCode: http.StatusOK}, + }, + { + name: "unauthorized 401 with invalid JSON", + response: &http.Response{ + StatusCode: http.StatusUnauthorized, + Body: io.NopCloser(strings.NewReader("invalid json")), + }, + expectedError: httperr.ErrNotAuthenticated, + }, + { + name: "forbidden 403 with invalid JSON", + response: &http.Response{ + StatusCode: http.StatusForbidden, + Body: io.NopCloser(strings.NewReader("invalid json")), + }, + expectedError: httperr.ErrNotAuthorized, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + err := CheckResponse(tt.response) + + if tt.expectedError == nil { + assert.NoError(t, err) + return + } + assert.ErrorIs(t, err, tt.expectedError) + }) + } +} diff --git a/internal/cloudapi/httperr/httperr.go b/internal/cloudapi/httperr/httperr.go new file mode 100644 index 000000000..3d34b02aa --- /dev/null +++ b/internal/cloudapi/httperr/httperr.go @@ -0,0 +1,31 @@ +// Package httperr contains HTTP-status-code error helpers shared by k6 +// Cloud's API clients (cloudapi, internal/cloudapi/v6). It only covers the +// part of their CheckResponse-style functions that's genuinely identical +// across them - classifying 401/403 - everything else about decoding an +// error response body differs between API versions. +package httperr + +import ( + "errors" + "net/http" +) + +var ( + // ErrNotAuthenticated maps HTTP 401. + ErrNotAuthenticated = errors.New("failed to authenticate with k6 Cloud") + // ErrNotAuthorized maps HTTP 403. + ErrNotAuthorized = errors.New("not allowed to upload result to k6 Cloud") +) + +// ClassifyStatus returns ErrNotAuthenticated for HTTP 401, ErrNotAuthorized +// for HTTP 403, and nil for any other status code. +func ClassifyStatus(statusCode int) error { + switch statusCode { + case http.StatusUnauthorized: + return ErrNotAuthenticated + case http.StatusForbidden: + return ErrNotAuthorized + default: + return nil + } +} diff --git a/internal/cloudapi/v6/client.go b/internal/cloudapi/v6/client.go index 3bb190d45..d518197dd 100644 --- a/internal/cloudapi/v6/client.go +++ b/internal/cloudapi/v6/client.go @@ -11,6 +11,7 @@ import ( k6cloud "github.com/grafana/k6-cloud-openapi-client-go/k6" "github.com/sirupsen/logrus" + "go.k6.io/k6/v2/internal/cloudapi/httperr" ) const ( @@ -123,11 +124,8 @@ func CheckResponse(r *http.Response, err error) error { var payload ResponseError if err := json.Unmarshal(data, &payload); err != nil { - if r.StatusCode == http.StatusUnauthorized { - return errNotAuthenticated - } - if r.StatusCode == http.StatusForbidden { - return errNotAuthorized + if classified := httperr.ClassifyStatus(r.StatusCode); classified != nil { + return classified } return fmt.Errorf( "unexpected HTTP error from %s: %d %s", diff --git a/internal/cloudapi/v6/client_test.go b/internal/cloudapi/v6/client_test.go index d007351fd..02ea89586 100644 --- a/internal/cloudapi/v6/client_test.go +++ b/internal/cloudapi/v6/client_test.go @@ -9,6 +9,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "go.k6.io/k6/v2/internal/cloudapi/httperr" ) func TestCheckResponse(t *testing.T) { @@ -43,7 +44,7 @@ func TestCheckResponse(t *testing.T) { StatusCode: http.StatusUnauthorized, Body: io.NopCloser(strings.NewReader("invalid json")), }, - expectedError: errNotAuthenticated.Error(), + expectedError: httperr.ErrNotAuthenticated.Error(), }, { name: "forbidden 403 with invalid JSON", @@ -51,7 +52,7 @@ func TestCheckResponse(t *testing.T) { StatusCode: http.StatusForbidden, Body: io.NopCloser(strings.NewReader("invalid json")), }, - expectedError: errNotAuthorized.Error(), + expectedError: httperr.ErrNotAuthorized.Error(), }, { name: "server error 500 with invalid JSON", diff --git a/internal/cloudapi/v6/errors.go b/internal/cloudapi/v6/errors.go index a378c32bf..5cfbd361c 100644 --- a/internal/cloudapi/v6/errors.go +++ b/internal/cloudapi/v6/errors.go @@ -10,10 +10,8 @@ import ( ) var ( - errNotAuthorized = errors.New("not allowed to upload result to k6 Cloud") - errNotAuthenticated = errors.New("failed to authenticate with k6 Cloud") - errTestNotExists = errors.New("load test not found") - errUnknown = errors.New("an error occurred communicating with k6 Cloud") + errTestNotExists = errors.New("load test not found") + errUnknown = errors.New("an error occurred communicating with k6 Cloud") ) // ResponseError represents an error cause by talking to the API From 7fc3dad9634ab1bfd972a5459bb6c7e8110a617b Mon Sep 17 00:00:00 2001 From: Mihail Stoykov <312246+mstoykov@users.noreply.github.com> Date: Fri, 17 Jul 2026 14:44:06 +0300 Subject: [PATCH 028/182] fix: consume upstream retry-body-reset fix, drop bodyResetTransport workaround (#6151) Bumps github.com/grafana/k6-cloud-openapi-client-go to main (v0.0.3-0.20260716094638-49089b6e624d), which includes the upstream fix for callAPI's retry loop not resetting the request body before replaying it (grafana/k6-cloud-openapi-client-go#31) - the SDK now resets req.Body from GetBody itself on every retry attempt, the same thing k6's own bodyResetTransport worked around client-side. With that fixed upstream, drop bodyResetTransport entirely and build the client Configuration via k6cloud.NewConfiguration() instead of a hand-written struct literal, since the zero-value fields it was setting (DefaultHeader, OperationServers) are pure boilerplate the package itself never reads or writes. This SDK commit also carries the int32->int64 ID widening already consumed in #6152, and an added LICENSE file - both already reflected in/compatible with the current vendor tree, so this change is scoped to just the retry-fix consumption. --- go.mod | 2 +- go.sum | 4 +- internal/cloudapi/v6/client.go | 45 +- .../k6-cloud-openapi-client-go/LICENSE | 661 ++++++++++++++++++ .../k6-cloud-openapi-client-go/k6/client.go | 11 + vendor/modules.txt | 2 +- 6 files changed, 688 insertions(+), 37 deletions(-) create mode 100644 vendor/github.com/grafana/k6-cloud-openapi-client-go/LICENSE diff --git a/go.mod b/go.mod index 624665ca5..d9d869f09 100644 --- a/go.mod +++ b/go.mod @@ -20,7 +20,7 @@ require ( github.com/golang/protobuf v1.5.4 github.com/google/uuid v1.6.0 github.com/gorilla/websocket v1.5.3 - github.com/grafana/k6-cloud-openapi-client-go v0.0.3-0.20260625132134-c48eae4f9a18 + github.com/grafana/k6-cloud-openapi-client-go v0.0.3-0.20260716094638-49089b6e624d github.com/grafana/k6provider v0.5.0 github.com/grafana/sobek v0.0.0-20260429085637-a66d4790012b github.com/grafana/xk6-dashboard-assets v0.1.2 diff --git a/go.sum b/go.sum index 8c63131ce..a4d95e2b4 100644 --- a/go.sum +++ b/go.sum @@ -90,8 +90,8 @@ 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/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/grafana/k6-cloud-openapi-client-go v0.0.3-0.20260625132134-c48eae4f9a18 h1:ZRUtDAU/2ozxTApsNPbXRGDig4VwVydhEntdNTz5olY= -github.com/grafana/k6-cloud-openapi-client-go v0.0.3-0.20260625132134-c48eae4f9a18/go.mod h1:RhZGBq6e90zSi0EME83c6S1qkOzD8pP0MNETqieWX0k= +github.com/grafana/k6-cloud-openapi-client-go v0.0.3-0.20260716094638-49089b6e624d h1:mGKcOe83IRY73ECb8S3PvhJCLVuev2aNGzZQID/f998= +github.com/grafana/k6-cloud-openapi-client-go v0.0.3-0.20260716094638-49089b6e624d/go.mod h1:RhZGBq6e90zSi0EME83c6S1qkOzD8pP0MNETqieWX0k= github.com/grafana/k6provider v0.5.0 h1:SwItWPOMQHfRytezQBKpeXLxjNmcyD/x9PTA28pEbwg= github.com/grafana/k6provider v0.5.0/go.mod h1:R9WKthnwk96E47m6w/mnC13hhBYTn5iMdP5caFt/t5k= github.com/grafana/sobek v0.0.0-20260429085637-a66d4790012b h1:mM/qn1luOrRZHT3G+405JMdCx4mGxeLKpOkVBa5+lFw= diff --git a/internal/cloudapi/v6/client.go b/internal/cloudapi/v6/client.go index d518197dd..2374d29c6 100644 --- a/internal/cloudapi/v6/client.go +++ b/internal/cloudapi/v6/client.go @@ -37,23 +37,20 @@ func NewClient(logger logrus.FieldLogger, token, host, version string, timeout t return nil, fmt.Errorf("token is required to create cloud API client") } - cfg := &k6cloud.Configuration{ - DefaultHeader: make(map[string]string), - UserAgent: "k6cloud/" + version, - Servers: k6cloud.ServerConfigurations{ - { - URL: host, - Description: "Global k6 Cloud API.", - }, + cfg := k6cloud.NewConfiguration() + cfg.UserAgent = "k6cloud/" + version + cfg.Servers = k6cloud.ServerConfigurations{ + { + URL: host, + Description: "Global k6 Cloud API.", }, - OperationServers: map[string]k6cloud.ServerConfigurations{}, - HTTPClient: &http.Client{ - Timeout: timeout, - Transport: &bodyResetTransport{base: http.DefaultTransport}, - }, - MaxRetries: MaxRetries, - RetryInterval: RetryInterval, } + cfg.HTTPClient = &http.Client{ + Timeout: timeout, + Transport: http.DefaultTransport, + } + cfg.MaxRetries = MaxRetries + cfg.RetryInterval = RetryInterval c := &Client{ apiClient: k6cloud.NewAPIClient(cfg), @@ -80,24 +77,6 @@ func (c *Client) BaseURL() string { return c.baseURL } -// bodyResetTransport resets req.Body from GetBody before each round trip. -// The vendored SDK retries 5xx/429 by re-calling Do on the same request -// without resetting its Body. After Connection: close the drained body -// causes "ContentLength=N with Body length 0". -type bodyResetTransport struct{ base http.RoundTripper } - -func (rt *bodyResetTransport) RoundTrip(req *http.Request) (*http.Response, error) { - if req.GetBody == nil { - return rt.base.RoundTrip(req) - } - body, err := req.GetBody() - if err != nil { - return nil, err - } - req.Body = body - return rt.base.RoundTrip(req) -} - // CheckResponse checks the parsed response. // It returns nil if the code is in the successful range, // otherwise it tries to parse the body and return a parsed error. diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/LICENSE b/vendor/github.com/grafana/k6-cloud-openapi-client-go/LICENSE new file mode 100644 index 000000000..bae94e189 --- /dev/null +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/LICENSE @@ -0,0 +1,661 @@ + GNU AFFERO GENERAL PUBLIC LICENSE + Version 3, 19 November 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU Affero General Public License is a free, copyleft license for +software and other kinds of works, specifically designed to ensure +cooperation with the community in the case of network server software. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +our General Public Licenses are intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + Developers that use our General Public Licenses protect your rights +with two steps: (1) assert copyright on the software, and (2) offer +you this License which gives you legal permission to copy, distribute +and/or modify the software. + + A secondary benefit of defending all users' freedom is that +improvements made in alternate versions of the program, if they +receive widespread use, become available for other developers to +incorporate. Many developers of free software are heartened and +encouraged by the resulting cooperation. However, in the case of +software used on network servers, this result may fail to come about. +The GNU General Public License permits making a modified version and +letting the public access it on a server without ever releasing its +source code to the public. + + The GNU Affero General Public License is designed specifically to +ensure that, in such cases, the modified source code becomes available +to the community. It requires the operator of a network server to +provide the source code of the modified version running there to the +users of that server. Therefore, public use of a modified version, on +a publicly accessible server, gives the public access to the source +code of the modified version. + + An older license, called the Affero General Public License and +published by Affero, was designed to accomplish similar goals. This is +a different license, not a version of the Affero GPL, but Affero has +released a new version of the Affero GPL which permits relicensing under +this license. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU Affero General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Remote Network Interaction; Use with the GNU General Public License. + + Notwithstanding any other provision of this License, if you modify the +Program, your modified version must prominently offer all users +interacting with it remotely through a computer network (if your version +supports such interaction) an opportunity to receive the Corresponding +Source of your version by providing access to the Corresponding Source +from a network server at no charge, through some standard or customary +means of facilitating copying of software. This Corresponding Source +shall include the Corresponding Source for any work covered by version 3 +of the GNU General Public License that is incorporated pursuant to the +following paragraph. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the work with which it is combined will remain governed by version +3 of the GNU General Public License. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU Affero General Public License from time to time. Such new versions +will be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU Affero General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU Affero General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU Affero General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If your software can interact with users remotely through a computer +network, you should also make sure that it provides a way for users to +get its source. For example, if your program is a web application, its +interface could display a "Source" link that leads users to an archive +of the code. There are many ways you could offer source, and different +solutions will be better for different programs; see section 13 for the +specific requirements. + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU AGPL, see +. \ No newline at end of file diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/client.go b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/client.go index 1016eb599..c754068dc 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/client.go +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/k6/client.go @@ -278,6 +278,17 @@ func (c *APIClient) callAPI(request *http.Request) (*http.Response, error) { var resp *http.Response var err error for i := 0; i <= c.cfg.MaxRetries; i++ { + // http.Client.Do consumes request.Body as it sends the request, so on + // any retry we must reset it to a fresh reader. GetBody is non-nil only + // when the body is rewindable; leave streaming bodies untouched. + if i > 0 && request.GetBody != nil { + body, bodyErr := request.GetBody() + if bodyErr != nil { + return resp, bodyErr + } + request.Body = body + } + resp, err = c.cfg.HTTPClient.Do(request) if shouldRetry(resp, err, i, c.cfg.MaxRetries) { if c.cfg.Debug { diff --git a/vendor/modules.txt b/vendor/modules.txt index ef9ff5735..3ad1977dd 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -178,7 +178,7 @@ github.com/google/uuid # github.com/gorilla/websocket v1.5.3 ## explicit; go 1.12 github.com/gorilla/websocket -# github.com/grafana/k6-cloud-openapi-client-go v0.0.3-0.20260625132134-c48eae4f9a18 +# github.com/grafana/k6-cloud-openapi-client-go v0.0.3-0.20260716094638-49089b6e624d ## explicit; go 1.23.4 github.com/grafana/k6-cloud-openapi-client-go/k6 # github.com/grafana/k6provider v0.5.0 From 99d25c36859b402452b1be58da2d2d63c55ba69c Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Mon, 20 Jul 2026 10:19:40 +0200 Subject: [PATCH 029/182] chore(deps): update golang docker tag to v1.26.5 (master) (#6155) | datasource | package | from | to | | ---------- | ------- | ------ | ------ | | docker | golang | 1.26.4 | 1.26.5 | Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index d18926c03..823b16760 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM --platform=$BUILDPLATFORM golang:1.26.4-alpine@sha256:3ad57304ad93bbec8548a0437ad9e06a455660655d9af011d58b993f6f615648 as builder +FROM --platform=$BUILDPLATFORM golang:1.26.5-alpine@sha256:0178a641fbb4858c5f1b48e34bdaabe0350a330a1b1149aabd498d0699ff5fb2 as builder WORKDIR $GOPATH/src/go.k6.io/k6 COPY . . ARG TARGETOS TARGETARCH From 5ab4391e62c363b7710077a991b9320960c079af Mon Sep 17 00:00:00 2001 From: Mihail Stoykov <312246+mstoykov@users.noreply.github.com> Date: Tue, 21 Jul 2026 13:27:32 +0300 Subject: [PATCH 030/182] chore(deps): Update sobek (#6183) --- go.mod | 4 +- go.sum | 10 +- ...breaking_test_errors-stripTypes=false.json | 3 +- .../breaking_test_errors-stripTypes=true.json | 3 +- vendor/github.com/dlclark/regexp2/regexp.go | 395 -- vendor/github.com/dlclark/regexp2/replace.go | 177 - vendor/github.com/dlclark/regexp2/runner.go | 1614 ----- .../dlclark/regexp2/syntax/charclass.go | 865 --- .../github.com/dlclark/regexp2/syntax/code.go | 274 - .../github.com/dlclark/regexp2/syntax/tree.go | 654 -- .../dlclark/regexp2/{ => v2}/ATTRIB | 0 .../dlclark/regexp2/{ => v2}/LICENSE | 0 .../dlclark/regexp2/v2/bufferpool.go | 76 + .../dlclark/regexp2/{ => v2}/fastclock.go | 0 .../dlclark/regexp2/v2/helpers/indexof.go | 394 ++ .../dlclark/regexp2/v2/helpers/math.go | 15 + .../dlclark/regexp2/v2/helpers/runes.go | 58 + .../regexp2/v2/helpers/searchvalues.go | 180 + .../dlclark/regexp2/{ => v2}/match.go | 158 +- .../github.com/dlclark/regexp2/v2/options.go | 157 + .../github.com/dlclark/regexp2/v2/regexp.go | 717 ++ .../dlclark/regexp2/v2/regexp_codegen.go | 70 + .../github.com/dlclark/regexp2/v2/replace.go | 357 + .../github.com/dlclark/regexp2/v2/runner.go | 2197 ++++++ vendor/github.com/dlclark/regexp2/v2/split.go | 67 + .../dlclark/regexp2/v2/stringprefixfilter.go | 375 + .../dlclark/regexp2/v2/syntax/charclass.go | 1493 ++++ .../dlclark/regexp2/v2/syntax/code.go | 316 + .../dlclark/regexp2/{ => v2}/syntax/escape.go | 2 +- .../dlclark/regexp2/{ => v2}/syntax/fuzz.go | 3 +- .../regexp2/v2/syntax/optimizations.go | 672 ++ .../dlclark/regexp2/{ => v2}/syntax/parser.go | 691 +- .../dlclark/regexp2/{ => v2}/syntax/prefix.go | 277 +- .../regexp2/v2/syntax/prefixanalyzer.go | 1491 ++++ .../regexp2/{ => v2}/syntax/replacerdata.go | 20 +- .../dlclark/regexp2/v2/syntax/tree.go | 2362 +++++++ .../regexp2/v2/syntax/unicode_alias_tables.go | 6058 +++++++++++++++++ .../dlclark/regexp2/{ => v2}/syntax/writer.go | 228 +- .../github.com/grafana/sobek/builtin_array.go | 18 +- .../github.com/grafana/sobek/builtin_json.go | 4 +- .../grafana/sobek/builtin_regexp.go | 94 +- .../grafana/sobek/builtin_string.go | 73 +- .../grafana/sobek/builtin_typedarrays.go | 26 +- vendor/github.com/grafana/sobek/compiler.go | 28 +- .../github.com/grafana/sobek/compiler_expr.go | 10 +- .../github.com/grafana/sobek/compiler_stmt.go | 18 +- .../grafana/sobek/extract_passed_tests.sh | 14 + .../grafana/sobek/object_goreflect.go | 2 +- .../github.com/grafana/sobek/parser/regexp.go | 32 +- vendor/github.com/grafana/sobek/regexp.go | 216 +- vendor/github.com/grafana/sobek/runtime.go | 20 +- .../github.com/grafana/sobek/typedarrays.go | 113 +- .../grafana/sobek/unistring/string.go | 19 +- vendor/github.com/grafana/sobek/vm.go | 2 +- vendor/modules.txt | 13 +- 55 files changed, 18373 insertions(+), 4762 deletions(-) delete mode 100644 vendor/github.com/dlclark/regexp2/regexp.go delete mode 100644 vendor/github.com/dlclark/regexp2/replace.go delete mode 100644 vendor/github.com/dlclark/regexp2/runner.go delete mode 100644 vendor/github.com/dlclark/regexp2/syntax/charclass.go delete mode 100644 vendor/github.com/dlclark/regexp2/syntax/code.go delete mode 100644 vendor/github.com/dlclark/regexp2/syntax/tree.go rename vendor/github.com/dlclark/regexp2/{ => v2}/ATTRIB (100%) rename vendor/github.com/dlclark/regexp2/{ => v2}/LICENSE (100%) create mode 100644 vendor/github.com/dlclark/regexp2/v2/bufferpool.go rename vendor/github.com/dlclark/regexp2/{ => v2}/fastclock.go (100%) create mode 100644 vendor/github.com/dlclark/regexp2/v2/helpers/indexof.go create mode 100644 vendor/github.com/dlclark/regexp2/v2/helpers/math.go create mode 100644 vendor/github.com/dlclark/regexp2/v2/helpers/runes.go create mode 100644 vendor/github.com/dlclark/regexp2/v2/helpers/searchvalues.go rename vendor/github.com/dlclark/regexp2/{ => v2}/match.go (67%) create mode 100644 vendor/github.com/dlclark/regexp2/v2/options.go create mode 100644 vendor/github.com/dlclark/regexp2/v2/regexp.go create mode 100644 vendor/github.com/dlclark/regexp2/v2/regexp_codegen.go create mode 100644 vendor/github.com/dlclark/regexp2/v2/replace.go create mode 100644 vendor/github.com/dlclark/regexp2/v2/runner.go create mode 100644 vendor/github.com/dlclark/regexp2/v2/split.go create mode 100644 vendor/github.com/dlclark/regexp2/v2/stringprefixfilter.go create mode 100644 vendor/github.com/dlclark/regexp2/v2/syntax/charclass.go create mode 100644 vendor/github.com/dlclark/regexp2/v2/syntax/code.go rename vendor/github.com/dlclark/regexp2/{ => v2}/syntax/escape.go (97%) rename vendor/github.com/dlclark/regexp2/{ => v2}/syntax/fuzz.go (80%) create mode 100644 vendor/github.com/dlclark/regexp2/v2/syntax/optimizations.go rename vendor/github.com/dlclark/regexp2/{ => v2}/syntax/parser.go (75%) rename vendor/github.com/dlclark/regexp2/{ => v2}/syntax/prefix.go (73%) create mode 100644 vendor/github.com/dlclark/regexp2/v2/syntax/prefixanalyzer.go rename vendor/github.com/dlclark/regexp2/{ => v2}/syntax/replacerdata.go (80%) create mode 100644 vendor/github.com/dlclark/regexp2/v2/syntax/tree.go create mode 100644 vendor/github.com/dlclark/regexp2/v2/syntax/unicode_alias_tables.go rename vendor/github.com/dlclark/regexp2/{ => v2}/syntax/writer.go (63%) create mode 100644 vendor/github.com/grafana/sobek/extract_passed_tests.sh diff --git a/go.mod b/go.mod index d9d869f09..75ee40aeb 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/gorilla/websocket v1.5.3 github.com/grafana/k6-cloud-openapi-client-go v0.0.3-0.20260716094638-49089b6e624d github.com/grafana/k6provider v0.5.0 - github.com/grafana/sobek v0.0.0-20260429085637-a66d4790012b + github.com/grafana/sobek v0.0.0-20260708062710-267a0e055bb4 github.com/grafana/xk6-dashboard-assets v0.1.2 github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 github.com/influxdata/influxdb1-client v0.0.0-20190402204710-8ff2fc3824fc @@ -76,7 +76,7 @@ require ( github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/chromedp/sysutil v1.1.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/dlclark/regexp2 v1.12.0 // indirect + github.com/dlclark/regexp2/v2 v2.2.2 // indirect github.com/go-logr/logr v1.4.3 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/google/pprof v0.0.0-20260115054156-294ebfa9ad83 // indirect diff --git a/go.sum b/go.sum index a4d95e2b4..803a19760 100644 --- a/go.sum +++ b/go.sum @@ -36,8 +36,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dlclark/regexp2 v1.12.0 h1:0j4c5qQmnC6XOWNjP3PIXURXN2gWx76rd3KvgdPkCz8= -github.com/dlclark/regexp2 v1.12.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= +github.com/dlclark/regexp2/v2 v2.2.2 h1:MYWvNYw8okuqNhwTYO587EZMiDruVa2vhV6fsGpfya0= +github.com/dlclark/regexp2/v2 v2.2.2/go.mod h1:avUrQvPaLz2DrFNHJF0taWAFFX2C1GMSSoeiqFjcBmU= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= @@ -63,6 +63,8 @@ github.com/go-sourcemap/sourcemap v2.1.4+incompatible h1:a+iTbH5auLKxaNwQFg0B+TC github.com/go-sourcemap/sourcemap v2.1.4+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= +github.com/goccy/go-yaml v1.19.2 h1:PmFC1S6h8ljIz6gMRBopkjP1TVT7xuwrButHID66PoM= +github.com/goccy/go-yaml v1.19.2/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= @@ -94,8 +96,8 @@ github.com/grafana/k6-cloud-openapi-client-go v0.0.3-0.20260716094638-49089b6e62 github.com/grafana/k6-cloud-openapi-client-go v0.0.3-0.20260716094638-49089b6e624d/go.mod h1:RhZGBq6e90zSi0EME83c6S1qkOzD8pP0MNETqieWX0k= github.com/grafana/k6provider v0.5.0 h1:SwItWPOMQHfRytezQBKpeXLxjNmcyD/x9PTA28pEbwg= github.com/grafana/k6provider v0.5.0/go.mod h1:R9WKthnwk96E47m6w/mnC13hhBYTn5iMdP5caFt/t5k= -github.com/grafana/sobek v0.0.0-20260429085637-a66d4790012b h1:mM/qn1luOrRZHT3G+405JMdCx4mGxeLKpOkVBa5+lFw= -github.com/grafana/sobek v0.0.0-20260429085637-a66d4790012b/go.mod h1:8pB+ag4SAbqtDxh1LNTeUI62/5f8mmEACImwbDHoUC0= +github.com/grafana/sobek v0.0.0-20260708062710-267a0e055bb4 h1:LJ2pEOxFbfUIhrkpROwZ6hLhuCn6e5GSX08v5GFwN/4= +github.com/grafana/sobek v0.0.0-20260708062710-267a0e055bb4/go.mod h1:BL/2XROA/Wtlb+zGEhkSdSZiMFIgw+D2ZdDfrbccyVE= github.com/grafana/xk6-dashboard-assets v0.1.2 h1:n2wqytPICn2ZYsKa9HE6GlvFXk+WjByMfT4eM+ms3gE= github.com/grafana/xk6-dashboard-assets v0.1.2/go.mod h1:SeoRjvmFF8UhLIFDfvjqqwBtE8MtaIPYIDWqVJZEHDo= github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 h1:UH//fgunKIs4JdUbpDl1VZCDaL56wXCB/5+wF6uHfaI= diff --git a/internal/js/tc39/breaking_test_errors-stripTypes=false.json b/internal/js/tc39/breaking_test_errors-stripTypes=false.json index b93fb3939..186f638c2 100644 --- a/internal/js/tc39/breaking_test_errors-stripTypes=false.json +++ b/internal/js/tc39/breaking_test_errors-stripTypes=false.json @@ -221,8 +221,7 @@ "test/built-ins/RegExp/unicode_restricted_incomplete_quantifier.js-strict:true": "test/built-ins/RegExp/unicode_restricted_incomplete_quantifier.js: Test262Error: RegExp(\"a{\", \"u\"): Expected a SyntaxError to be thrown but no exception was thrown at all ", "test/built-ins/RegExp/unicode_restricted_octal_escape.js-strict:true": "test/built-ins/RegExp/unicode_restricted_octal_escape.js: Test262Error: RegExp(\"\\1\", \"u\"): Expected a SyntaxError to be thrown but no exception was thrown at all ", "test/built-ins/RegExp/unicode_restricted_quantifiable_assertion.js-strict:true": "test/built-ins/RegExp/unicode_restricted_quantifiable_assertion.js: Test262Error: RegExp(\"(?=.)*\", \"u\"): Expected a SyntaxError to be thrown but no exception was thrown at all ", - "test/built-ins/String/prototype/replace/regexp-capture-by-index.js-strict:true": "test/built-ins/String/prototype/replace/regexp-capture-by-index.js: Test262Error: `$01` before `0` is a capture index in /((((((((((x))))))))))/ Expected SameValue(«\"foo-|x|-bar\"», «\"foo-|x0|-bar\"») to be true ", - "test/built-ins/TypedArray/prototype/slice/speciesctor-return-same-buffer-with-offset.js-strict:true": "test/built-ins/TypedArray/prototype/slice/speciesctor-return-same-buffer-with-offset.js: Test262Error: Actual [40, 40, 50, 60] and expected [20, 20, 20, 60] should have the same contents. (Testing with Float64Array and makePassthrough.) ", + "test/built-ins/TypedArray/prototype/slice/speciesctor-return-same-buffer-with-offset.js-strict:true": "test/built-ins/TypedArray/prototype/slice/speciesctor-return-same-buffer-with-offset.js: Test262Error: Actual [8.1254e-320, 40.0000000001169, 50, 60] and expected [20, 20, 20, 60] should have the same contents. (Testing with Float64Array and makePassthrough.) ", "test/built-ins/TypedArray/prototype/with/value-throw-completion.js-strict:true": "test/built-ins/TypedArray/prototype/with/value-throw-completion.js: Test262Error: Positive too large index Expected a MyError but got a RangeError (Testing with Float64Array and makePassthrough.) ", "test/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-canonical-invalid-index-prototype-chain-set.js-strict:true": "test/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-canonical-invalid-index-prototype-chain-set.js: Test262Error: 1 setter should be unreachable! (Testing with BigInt64Array and makePassthrough.) ", "test/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-canonical-invalid-index-reflect-set.js-strict:true": "test/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-canonical-invalid-index-reflect-set.js: Test262Error: 1 setter should be unreachable! (Testing with BigInt64Array and makePassthrough.) ", diff --git a/internal/js/tc39/breaking_test_errors-stripTypes=true.json b/internal/js/tc39/breaking_test_errors-stripTypes=true.json index eb8d6b989..b2ae30af4 100644 --- a/internal/js/tc39/breaking_test_errors-stripTypes=true.json +++ b/internal/js/tc39/breaking_test_errors-stripTypes=true.json @@ -221,8 +221,7 @@ "test/built-ins/RegExp/unicode_restricted_incomplete_quantifier.js-strict:true": "test/built-ins/RegExp/unicode_restricted_incomplete_quantifier.js: Test262Error: RegExp(\"a{\", \"u\"): Expected a SyntaxError to be thrown but no exception was thrown at all ", "test/built-ins/RegExp/unicode_restricted_octal_escape.js-strict:true": "test/built-ins/RegExp/unicode_restricted_octal_escape.js: Test262Error: RegExp(\"\\1\", \"u\"): Expected a SyntaxError to be thrown but no exception was thrown at all ", "test/built-ins/RegExp/unicode_restricted_quantifiable_assertion.js-strict:true": "test/built-ins/RegExp/unicode_restricted_quantifiable_assertion.js: Test262Error: RegExp(\"(?=.)*\", \"u\"): Expected a SyntaxError to be thrown but no exception was thrown at all ", - "test/built-ins/String/prototype/replace/regexp-capture-by-index.js-strict:true": "test/built-ins/String/prototype/replace/regexp-capture-by-index.js: Test262Error: `$01` before `0` is a capture index in /((((((((((x))))))))))/ Expected SameValue(«\"foo-|x|-bar\"», «\"foo-|x0|-bar\"») to be true ", - "test/built-ins/TypedArray/prototype/slice/speciesctor-return-same-buffer-with-offset.js-strict:true": "test/built-ins/TypedArray/prototype/slice/speciesctor-return-same-buffer-with-offset.js: Test262Error: Actual [40, 40, 50, 60] and expected [20, 20, 20, 60] should have the same contents. (Testing with Float64Array and makePassthrough.) ", + "test/built-ins/TypedArray/prototype/slice/speciesctor-return-same-buffer-with-offset.js-strict:true": "test/built-ins/TypedArray/prototype/slice/speciesctor-return-same-buffer-with-offset.js: Test262Error: Actual [8.1254e-320, 40.0000000001169, 50, 60] and expected [20, 20, 20, 60] should have the same contents. (Testing with Float64Array and makePassthrough.) ", "test/built-ins/TypedArray/prototype/with/value-throw-completion.js-strict:true": "test/built-ins/TypedArray/prototype/with/value-throw-completion.js: Test262Error: Positive too large index Expected a MyError but got a RangeError (Testing with Float64Array and makePassthrough.) ", "test/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-canonical-invalid-index-prototype-chain-set.js-strict:true": "test/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-canonical-invalid-index-prototype-chain-set.js: Test262Error: 1 setter should be unreachable! (Testing with BigInt64Array and makePassthrough.) ", "test/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-canonical-invalid-index-reflect-set.js-strict:true": "test/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-canonical-invalid-index-reflect-set.js: Test262Error: 1 setter should be unreachable! (Testing with BigInt64Array and makePassthrough.) ", diff --git a/vendor/github.com/dlclark/regexp2/regexp.go b/vendor/github.com/dlclark/regexp2/regexp.go deleted file mode 100644 index a7ddbaf35..000000000 --- a/vendor/github.com/dlclark/regexp2/regexp.go +++ /dev/null @@ -1,395 +0,0 @@ -/* -Package regexp2 is a regexp package that has an interface similar to Go's framework regexp engine but uses a -more feature full regex engine behind the scenes. - -It doesn't have constant time guarantees, but it allows backtracking and is compatible with Perl5 and .NET. -You'll likely be better off with the RE2 engine from the regexp package and should only use this if you -need to write very complex patterns or require compatibility with .NET. -*/ -package regexp2 - -import ( - "errors" - "math" - "strconv" - "sync" - "time" - - "github.com/dlclark/regexp2/syntax" -) - -var ( - // DefaultMatchTimeout used when running regexp matches -- "forever" - DefaultMatchTimeout = time.Duration(math.MaxInt64) - // DefaultUnmarshalOptions used when unmarshaling a regex from text - DefaultUnmarshalOptions = None -) - -// Regexp is the representation of a compiled regular expression. -// A Regexp is safe for concurrent use by multiple goroutines. -type Regexp struct { - // A match will time out if it takes (approximately) more than - // MatchTimeout. This is a safety check in case the match - // encounters catastrophic backtracking. The default value - // (DefaultMatchTimeout) causes all time out checking to be - // suppressed. - MatchTimeout time.Duration - - // read-only after Compile - pattern string // as passed to Compile - options RegexOptions // options - - caps map[int]int // capnum->index - capnames map[string]int //capture group name -> index - capslist []string //sorted list of capture group names - capsize int // size of the capture array - - code *syntax.Code // compiled program - - // cache of machines for running regexp - muRun *sync.Mutex - runner []*runner -} - -// Compile parses a regular expression and returns, if successful, -// a Regexp object that can be used to match against text. -func Compile(expr string, opt RegexOptions) (*Regexp, error) { - // parse it - tree, err := syntax.Parse(expr, syntax.RegexOptions(opt)) - if err != nil { - return nil, err - } - - // translate it to code - code, err := syntax.Write(tree) - if err != nil { - return nil, err - } - - // return it - return &Regexp{ - pattern: expr, - options: opt, - caps: code.Caps, - capnames: tree.Capnames, - capslist: tree.Caplist, - capsize: code.Capsize, - code: code, - MatchTimeout: DefaultMatchTimeout, - muRun: &sync.Mutex{}, - }, nil -} - -// MustCompile is like Compile but panics if the expression cannot be parsed. -// It simplifies safe initialization of global variables holding compiled regular -// expressions. -func MustCompile(str string, opt RegexOptions) *Regexp { - regexp, error := Compile(str, opt) - if error != nil { - panic(`regexp2: Compile(` + quote(str) + `): ` + error.Error()) - } - return regexp -} - -// Escape adds backslashes to any special characters in the input string -func Escape(input string) string { - return syntax.Escape(input) -} - -// Unescape removes any backslashes from previously-escaped special characters in the input string -func Unescape(input string) (string, error) { - return syntax.Unescape(input) -} - -// SetTimeoutPeriod is a debug function that sets the frequency of the timeout goroutine's sleep cycle. -// Defaults to 100ms. The only benefit of setting this lower is that the 1 background goroutine that manages -// timeouts may exit slightly sooner after all the timeouts have expired. See Github issue #63 -func SetTimeoutCheckPeriod(d time.Duration) { - clockPeriod = d -} - -// StopTimeoutClock should only be used in unit tests to prevent the timeout clock goroutine -// from appearing like a leaking goroutine -func StopTimeoutClock() { - stopClock() -} - -// String returns the source text used to compile the regular expression. -func (re *Regexp) String() string { - return re.pattern -} - -func quote(s string) string { - if strconv.CanBackquote(s) { - return "`" + s + "`" - } - return strconv.Quote(s) -} - -// RegexOptions impact the runtime and parsing behavior -// for each specific regex. They are setable in code as well -// as in the regex pattern itself. -type RegexOptions int32 - -const ( - None RegexOptions = 0x0 - IgnoreCase = 0x0001 // "i" - Multiline = 0x0002 // "m" - ExplicitCapture = 0x0004 // "n" - Compiled = 0x0008 // "c" - Singleline = 0x0010 // "s" - IgnorePatternWhitespace = 0x0020 // "x" - RightToLeft = 0x0040 // "r" - Debug = 0x0080 // "d" - ECMAScript = 0x0100 // "e" - RE2 = 0x0200 // RE2 (regexp package) compatibility mode - Unicode = 0x0400 // "u" -) - -func (re *Regexp) RightToLeft() bool { - return re.options&RightToLeft != 0 -} - -func (re *Regexp) Debug() bool { - return re.options&Debug != 0 -} - -// Replace searches the input string and replaces each match found with the replacement text. -// Count will limit the number of matches attempted and startAt will allow -// us to skip past possible matches at the start of the input (left or right depending on RightToLeft option). -// Set startAt and count to -1 to go through the whole string -func (re *Regexp) Replace(input, replacement string, startAt, count int) (string, error) { - data, err := syntax.NewReplacerData(replacement, re.caps, re.capsize, re.capnames, syntax.RegexOptions(re.options)) - if err != nil { - return "", err - } - //TODO: cache ReplacerData - - return replace(re, data, nil, input, startAt, count) -} - -// ReplaceFunc searches the input string and replaces each match found using the string from the evaluator -// Count will limit the number of matches attempted and startAt will allow -// us to skip past possible matches at the start of the input (left or right depending on RightToLeft option). -// Set startAt and count to -1 to go through the whole string. -func (re *Regexp) ReplaceFunc(input string, evaluator MatchEvaluator, startAt, count int) (string, error) { - return replace(re, nil, evaluator, input, startAt, count) -} - -// FindStringMatch searches the input string for a Regexp match -func (re *Regexp) FindStringMatch(s string) (*Match, error) { - // convert string to runes - return re.run(false, -1, getRunes(s)) -} - -// FindRunesMatch searches the input rune slice for a Regexp match -func (re *Regexp) FindRunesMatch(r []rune) (*Match, error) { - return re.run(false, -1, r) -} - -// FindStringMatchStartingAt searches the input string for a Regexp match starting at the startAt index -func (re *Regexp) FindStringMatchStartingAt(s string, startAt int) (*Match, error) { - if startAt > len(s) { - return nil, errors.New("startAt must be less than the length of the input string") - } - r, startAt := re.getRunesAndStart(s, startAt) - if startAt == -1 { - // we didn't find our start index in the string -- that's a problem - return nil, errors.New("startAt must align to the start of a valid rune in the input string") - } - - return re.run(false, startAt, r) -} - -// FindRunesMatchStartingAt searches the input rune slice for a Regexp match starting at the startAt index -func (re *Regexp) FindRunesMatchStartingAt(r []rune, startAt int) (*Match, error) { - return re.run(false, startAt, r) -} - -// FindNextMatch returns the next match in the same input string as the match parameter. -// Will return nil if there is no next match or if given a nil match. -func (re *Regexp) FindNextMatch(m *Match) (*Match, error) { - if m == nil { - return nil, nil - } - - // If previous match was empty, advance by one before matching to prevent - // infinite loop - startAt := m.textpos - if m.Length == 0 { - if m.textpos == len(m.text) { - return nil, nil - } - - if re.RightToLeft() { - startAt-- - } else { - startAt++ - } - } - return re.run(false, startAt, m.text) -} - -// MatchString return true if the string matches the regex -// error will be set if a timeout occurs -func (re *Regexp) MatchString(s string) (bool, error) { - m, err := re.run(true, -1, getRunes(s)) - if err != nil { - return false, err - } - return m != nil, nil -} - -func (re *Regexp) getRunesAndStart(s string, startAt int) ([]rune, int) { - if startAt < 0 { - if re.RightToLeft() { - r := getRunes(s) - return r, len(r) - } - return getRunes(s), 0 - } - ret := make([]rune, len(s)) - i := 0 - runeIdx := -1 - for strIdx, r := range s { - if strIdx == startAt { - runeIdx = i - } - ret[i] = r - i++ - } - if startAt == len(s) { - runeIdx = i - } - return ret[:i], runeIdx -} - -func getRunes(s string) []rune { - return []rune(s) -} - -// MatchRunes return true if the runes matches the regex -// error will be set if a timeout occurs -func (re *Regexp) MatchRunes(r []rune) (bool, error) { - m, err := re.run(true, -1, r) - if err != nil { - return false, err - } - return m != nil, nil -} - -// GetGroupNames Returns the set of strings used to name capturing groups in the expression. -func (re *Regexp) GetGroupNames() []string { - var result []string - - if re.capslist == nil { - result = make([]string, re.capsize) - - for i := 0; i < len(result); i++ { - result[i] = strconv.Itoa(i) - } - } else { - result = make([]string, len(re.capslist)) - copy(result, re.capslist) - } - - return result -} - -// GetGroupNumbers returns the integer group numbers corresponding to a group name. -func (re *Regexp) GetGroupNumbers() []int { - var result []int - - if re.caps == nil { - result = make([]int, re.capsize) - - for i := 0; i < len(result); i++ { - result[i] = i - } - } else { - result = make([]int, len(re.caps)) - - for k, v := range re.caps { - result[v] = k - } - } - - return result -} - -// GroupNameFromNumber retrieves a group name that corresponds to a group number. -// It will return "" for and unknown group number. Unnamed groups automatically -// receive a name that is the decimal string equivalent of its number. -func (re *Regexp) GroupNameFromNumber(i int) string { - if re.capslist == nil { - if i >= 0 && i < re.capsize { - return strconv.Itoa(i) - } - - return "" - } - - if re.caps != nil { - var ok bool - if i, ok = re.caps[i]; !ok { - return "" - } - } - - if i >= 0 && i < len(re.capslist) { - return re.capslist[i] - } - - return "" -} - -// GroupNumberFromName returns a group number that corresponds to a group name. -// Returns -1 if the name is not a recognized group name. Numbered groups -// automatically get a group name that is the decimal string equivalent of its number. -func (re *Regexp) GroupNumberFromName(name string) int { - // look up name if we have a hashtable of names - if re.capnames != nil { - if k, ok := re.capnames[name]; ok { - return k - } - - return -1 - } - - // convert to an int if it looks like a number - result := 0 - for i := 0; i < len(name); i++ { - ch := name[i] - - if ch > '9' || ch < '0' { - return -1 - } - - result *= 10 - result += int(ch - '0') - } - - // return int if it's in range - if result >= 0 && result < re.capsize { - return result - } - - return -1 -} - -// MarshalText implements [encoding.TextMarshaler]. The output -// matches that of calling the [Regexp.String] method. -func (re *Regexp) MarshalText() ([]byte, error) { - return []byte(re.String()), nil -} - -// UnmarshalText implements [encoding.TextUnmarshaler] by calling -// [Compile] on the encoded value. -func (re *Regexp) UnmarshalText(text []byte) error { - newRE, err := Compile(string(text), DefaultUnmarshalOptions) - if err != nil { - return err - } - *re = *newRE - return nil -} diff --git a/vendor/github.com/dlclark/regexp2/replace.go b/vendor/github.com/dlclark/regexp2/replace.go deleted file mode 100644 index 0376bd9d3..000000000 --- a/vendor/github.com/dlclark/regexp2/replace.go +++ /dev/null @@ -1,177 +0,0 @@ -package regexp2 - -import ( - "bytes" - "errors" - - "github.com/dlclark/regexp2/syntax" -) - -const ( - replaceSpecials = 4 - replaceLeftPortion = -1 - replaceRightPortion = -2 - replaceLastGroup = -3 - replaceWholeString = -4 -) - -// MatchEvaluator is a function that takes a match and returns a replacement string to be used -type MatchEvaluator func(Match) string - -// Three very similar algorithms appear below: replace (pattern), -// replace (evaluator), and split. - -// Replace Replaces all occurrences of the regex in the string with the -// replacement pattern. -// -// Note that the special case of no matches is handled on its own: -// with no matches, the input string is returned unchanged. -// The right-to-left case is split out because StringBuilder -// doesn't handle right-to-left string building directly very well. -func replace(regex *Regexp, data *syntax.ReplacerData, evaluator MatchEvaluator, input string, startAt, count int) (string, error) { - if count < -1 { - return "", errors.New("Count too small") - } - if count == 0 { - return "", nil - } - - m, err := regex.FindStringMatchStartingAt(input, startAt) - - if err != nil { - return "", err - } - if m == nil { - return input, nil - } - - buf := &bytes.Buffer{} - text := m.text - - if !regex.RightToLeft() { - prevat := 0 - for m != nil { - if m.Index != prevat { - buf.WriteString(string(text[prevat:m.Index])) - } - prevat = m.Index + m.Length - if evaluator == nil { - replacementImpl(data, buf, m) - } else { - buf.WriteString(evaluator(*m)) - } - - count-- - if count == 0 { - break - } - m, err = regex.FindNextMatch(m) - if err != nil { - return "", nil - } - } - - if prevat < len(text) { - buf.WriteString(string(text[prevat:])) - } - } else { - prevat := len(text) - var al []string - - for m != nil { - if m.Index+m.Length != prevat { - al = append(al, string(text[m.Index+m.Length:prevat])) - } - prevat = m.Index - if evaluator == nil { - replacementImplRTL(data, &al, m) - } else { - al = append(al, evaluator(*m)) - } - - count-- - if count == 0 { - break - } - m, err = regex.FindNextMatch(m) - if err != nil { - return "", nil - } - } - - if prevat > 0 { - buf.WriteString(string(text[:prevat])) - } - - for i := len(al) - 1; i >= 0; i-- { - buf.WriteString(al[i]) - } - } - - return buf.String(), nil -} - -// Given a Match, emits into the StringBuilder the evaluated -// substitution pattern. -func replacementImpl(data *syntax.ReplacerData, buf *bytes.Buffer, m *Match) { - for _, r := range data.Rules { - - if r >= 0 { // string lookup - buf.WriteString(data.Strings[r]) - } else if r < -replaceSpecials { // group lookup - m.groupValueAppendToBuf(-replaceSpecials-1-r, buf) - } else { - switch -replaceSpecials - 1 - r { // special insertion patterns - case replaceLeftPortion: - for i := 0; i < m.Index; i++ { - buf.WriteRune(m.text[i]) - } - case replaceRightPortion: - for i := m.Index + m.Length; i < len(m.text); i++ { - buf.WriteRune(m.text[i]) - } - case replaceLastGroup: - m.groupValueAppendToBuf(m.GroupCount()-1, buf) - case replaceWholeString: - for i := 0; i < len(m.text); i++ { - buf.WriteRune(m.text[i]) - } - } - } - } -} - -func replacementImplRTL(data *syntax.ReplacerData, al *[]string, m *Match) { - l := *al - buf := &bytes.Buffer{} - - for _, r := range data.Rules { - buf.Reset() - if r >= 0 { // string lookup - l = append(l, data.Strings[r]) - } else if r < -replaceSpecials { // group lookup - m.groupValueAppendToBuf(-replaceSpecials-1-r, buf) - l = append(l, buf.String()) - } else { - switch -replaceSpecials - 1 - r { // special insertion patterns - case replaceLeftPortion: - for i := 0; i < m.Index; i++ { - buf.WriteRune(m.text[i]) - } - case replaceRightPortion: - for i := m.Index + m.Length; i < len(m.text); i++ { - buf.WriteRune(m.text[i]) - } - case replaceLastGroup: - m.groupValueAppendToBuf(m.GroupCount()-1, buf) - case replaceWholeString: - for i := 0; i < len(m.text); i++ { - buf.WriteRune(m.text[i]) - } - } - l = append(l, buf.String()) - } - } - - *al = l -} diff --git a/vendor/github.com/dlclark/regexp2/runner.go b/vendor/github.com/dlclark/regexp2/runner.go deleted file mode 100644 index 4bb0dfa1a..000000000 --- a/vendor/github.com/dlclark/regexp2/runner.go +++ /dev/null @@ -1,1614 +0,0 @@ -package regexp2 - -import ( - "bytes" - "errors" - "fmt" - "math" - "strconv" - "strings" - "time" - "unicode" - - "github.com/dlclark/regexp2/syntax" -) - -type runner struct { - re *Regexp - code *syntax.Code - - runtextstart int // starting point for search - - runtext []rune // text to search - runtextpos int // current position in text - runtextend int - - // The backtracking stack. Opcodes use this to store data regarding - // what they have matched and where to backtrack to. Each "frame" on - // the stack takes the form of [CodePosition Data1 Data2...], where - // CodePosition is the position of the current opcode and - // the data values are all optional. The CodePosition can be negative, and - // these values (also called "back2") are used by the BranchMark family of opcodes - // to indicate whether they are backtracking after a successful or failed - // match. - // When we backtrack, we pop the CodePosition off the stack, set the current - // instruction pointer to that code position, and mark the opcode - // with a backtracking flag ("Back"). Each opcode then knows how to - // handle its own data. - runtrack []int - runtrackpos int - - // This stack is used to track text positions across different opcodes. - // For example, in /(a*b)+/, the parentheses result in a SetMark/CaptureMark - // pair. SetMark records the text position before we match a*b. Then - // CaptureMark uses that position to figure out where the capture starts. - // Opcodes which push onto this stack are always paired with other opcodes - // which will pop the value from it later. A successful match should mean - // that this stack is empty. - runstack []int - runstackpos int - - // The crawl stack is used to keep track of captures. Every time a group - // has a capture, we push its group number onto the runcrawl stack. In - // the case of a balanced match, we push BOTH groups onto the stack. - runcrawl []int - runcrawlpos int - - runtrackcount int // count of states that may do backtracking - - runmatch *Match // result object - - ignoreTimeout bool - timeout time.Duration // timeout in milliseconds (needed for actual) - deadline fasttime - - operator syntax.InstOp - codepos int - rightToLeft bool - caseInsensitive bool -} - -// run searches for matches and can continue from the previous match -// -// quick is usually false, but can be true to not return matches, just put it in caches -// textstart is -1 to start at the "beginning" (depending on Right-To-Left), otherwise an index in input -// input is the string to search for our regex pattern -func (re *Regexp) run(quick bool, textstart int, input []rune) (*Match, error) { - - // get a cached runner - runner := re.getRunner() - defer re.putRunner(runner) - - if textstart < 0 { - if re.RightToLeft() { - textstart = len(input) - } else { - textstart = 0 - } - } - - return runner.scan(input, textstart, quick, re.MatchTimeout) -} - -// Scans the string to find the first match. Uses the Match object -// both to feed text in and as a place to store matches that come out. -// -// All the action is in the Go() method. Our -// responsibility is to load up the class members before -// calling Go. -// -// The optimizer can compute a set of candidate starting characters, -// and we could use a separate method Skip() that will quickly scan past -// any characters that we know can't match. -func (r *runner) scan(rt []rune, textstart int, quick bool, timeout time.Duration) (*Match, error) { - r.timeout = timeout - r.ignoreTimeout = (time.Duration(math.MaxInt64) == timeout) - r.runtextstart = textstart - r.runtext = rt - r.runtextend = len(rt) - - stoppos := r.runtextend - bump := 1 - - if r.re.RightToLeft() { - bump = -1 - stoppos = 0 - } - - r.runtextpos = textstart - initted := false - - r.startTimeoutWatch() - for { - if r.re.Debug() { - //fmt.Printf("\nSearch content: %v\n", string(r.runtext)) - fmt.Printf("\nSearch range: from 0 to %v\n", r.runtextend) - fmt.Printf("Firstchar search starting at %v stopping at %v\n", r.runtextpos, stoppos) - } - - if r.findFirstChar() { - if err := r.checkTimeout(); err != nil { - return nil, err - } - - if !initted { - r.initMatch() - initted = true - } - - if r.re.Debug() { - fmt.Printf("Executing engine starting at %v\n\n", r.runtextpos) - } - - if err := r.execute(); err != nil { - return nil, err - } - - if r.runmatch.matchcount[0] > 0 { - // We'll return a match even if it touches a previous empty match - return r.tidyMatch(quick), nil - } - - // reset state for another go - r.runtrackpos = len(r.runtrack) - r.runstackpos = len(r.runstack) - r.runcrawlpos = len(r.runcrawl) - } - - // failure! - - if r.runtextpos == stoppos { - r.tidyMatch(true) - return nil, nil - } - - // Recognize leading []* and various anchors, and bump on failure accordingly - - // r.bump by one and start again - - r.runtextpos += bump - } - // We never get here -} - -func (r *runner) execute() error { - - r.goTo(0) - - for { - - if r.re.Debug() { - r.dumpState() - } - - if err := r.checkTimeout(); err != nil { - return err - } - - switch r.operator { - case syntax.Stop: - return nil - - case syntax.Nothing: - break - - case syntax.Goto: - r.goTo(r.operand(0)) - continue - - case syntax.Testref: - if !r.runmatch.isMatched(r.operand(0)) { - break - } - r.advance(1) - continue - - case syntax.Lazybranch: - r.trackPush1(r.textPos()) - r.advance(1) - continue - - case syntax.Lazybranch | syntax.Back: - r.trackPop() - r.textto(r.trackPeek()) - r.goTo(r.operand(0)) - continue - - case syntax.Setmark: - r.stackPush(r.textPos()) - r.trackPush() - r.advance(0) - continue - - case syntax.Nullmark: - r.stackPush(-1) - r.trackPush() - r.advance(0) - continue - - case syntax.Setmark | syntax.Back, syntax.Nullmark | syntax.Back: - r.stackPop() - break - - case syntax.Getmark: - r.stackPop() - r.trackPush1(r.stackPeek()) - r.textto(r.stackPeek()) - r.advance(0) - continue - - case syntax.Getmark | syntax.Back: - r.trackPop() - r.stackPush(r.trackPeek()) - break - - case syntax.Capturemark: - if r.operand(1) != -1 && !r.runmatch.isMatched(r.operand(1)) { - break - } - r.stackPop() - if r.operand(1) != -1 { - r.transferCapture(r.operand(0), r.operand(1), r.stackPeek(), r.textPos()) - } else { - r.capture(r.operand(0), r.stackPeek(), r.textPos()) - } - r.trackPush1(r.stackPeek()) - - r.advance(2) - - continue - - case syntax.Capturemark | syntax.Back: - r.trackPop() - r.stackPush(r.trackPeek()) - r.uncapture() - if r.operand(0) != -1 && r.operand(1) != -1 { - r.uncapture() - } - - break - - case syntax.Branchmark: - r.stackPop() - - matched := r.textPos() - r.stackPeek() - - if matched != 0 { // Nonempty match -> loop now - r.trackPush2(r.stackPeek(), r.textPos()) // Save old mark, textpos - r.stackPush(r.textPos()) // Make new mark - r.goTo(r.operand(0)) // Loop - } else { // Empty match -> straight now - r.trackPushNeg1(r.stackPeek()) // Save old mark - r.advance(1) // Straight - } - continue - - case syntax.Branchmark | syntax.Back: - r.trackPopN(2) - r.stackPop() - r.textto(r.trackPeekN(1)) // Recall position - r.trackPushNeg1(r.trackPeek()) // Save old mark - r.advance(1) // Straight - continue - - case syntax.Branchmark | syntax.Back2: - r.trackPop() - r.stackPush(r.trackPeek()) // Recall old mark - break // Backtrack - - case syntax.Lazybranchmark: - { - // We hit this the first time through a lazy loop and after each - // successful match of the inner expression. It simply continues - // on and doesn't loop. - r.stackPop() - - oldMarkPos := r.stackPeek() - - if r.textPos() != oldMarkPos { // Nonempty match -> try to loop again by going to 'back' state - if oldMarkPos != -1 { - r.trackPush2(oldMarkPos, r.textPos()) // Save old mark, textpos - } else { - r.trackPush2(r.textPos(), r.textPos()) - } - } else { - // The inner expression found an empty match, so we'll go directly to 'back2' if we - // backtrack. Don't touch the grouping stack here; instead, record the old mark and - // a flag indicating that backtracking doesn't need to pop a grouping stack frame. - r.trackPushNeg2(oldMarkPos, 0) - } - r.advance(1) - continue - } - - case syntax.Lazybranchmark | syntax.Back: - - // After the first time, Lazybranchmark | syntax.Back occurs - // with each iteration of the loop, and therefore with every attempted - // match of the inner expression. We'll try to match the inner expression, - // then go back to Lazybranchmark if successful. If the inner expression - // fails, we go to Lazybranchmark | syntax.Back2 - - r.trackPopN(2) - pos := r.trackPeekN(1) - r.trackPushNeg2(r.trackPeek(), 1) // Save old mark, note that we pushed a new mark - r.stackPush(pos) // Make new mark - r.textto(pos) // Recall position - r.goTo(r.operand(0)) // Loop - continue - - case syntax.Lazybranchmark | syntax.Back2: - // The lazy loop has failed. We'll do a true backtrack and - // start over before the lazy loop. - r.trackPopN(2) - oldMark := r.trackPeek() - needsPop := r.trackPeekN(1) - if needsPop != 0 { - r.stackPop() - } - r.stackPush(oldMark) // Recall old mark - break - - case syntax.Setcount: - r.stackPush2(r.textPos(), r.operand(0)) - r.trackPush() - r.advance(1) - continue - - case syntax.Nullcount: - r.stackPush2(-1, r.operand(0)) - r.trackPush() - r.advance(1) - continue - - case syntax.Setcount | syntax.Back: - r.stackPopN(2) - break - - case syntax.Nullcount | syntax.Back: - r.stackPopN(2) - break - - case syntax.Branchcount: - // r.stackPush: - // 0: Mark - // 1: Count - - r.stackPopN(2) - mark := r.stackPeek() - count := r.stackPeekN(1) - matched := r.textPos() - mark - - if count >= r.operand(1) || (matched == 0 && count >= 0) { // Max loops or empty match -> straight now - r.trackPushNeg2(mark, count) // Save old mark, count - r.advance(2) // Straight - } else { // Nonempty match -> count+loop now - r.trackPush1(mark) // remember mark - r.stackPush2(r.textPos(), count+1) // Make new mark, incr count - r.goTo(r.operand(0)) // Loop - } - continue - - case syntax.Branchcount | syntax.Back: - // r.trackPush: - // 0: Previous mark - // r.stackPush: - // 0: Mark (= current pos, discarded) - // 1: Count - r.trackPop() - r.stackPopN(2) - if r.stackPeekN(1) > 0 { // Positive -> can go straight - r.textto(r.stackPeek()) // Zap to mark - r.trackPushNeg2(r.trackPeek(), r.stackPeekN(1)-1) // Save old mark, old count - r.advance(2) // Straight - continue - } - r.stackPush2(r.trackPeek(), r.stackPeekN(1)-1) // recall old mark, old count - break - - case syntax.Branchcount | syntax.Back2: - // r.trackPush: - // 0: Previous mark - // 1: Previous count - r.trackPopN(2) - r.stackPush2(r.trackPeek(), r.trackPeekN(1)) // Recall old mark, old count - break // Backtrack - - case syntax.Lazybranchcount: - // r.stackPush: - // 0: Mark - // 1: Count - - r.stackPopN(2) - mark := r.stackPeek() - count := r.stackPeekN(1) - - if count < 0 { // Negative count -> loop now - r.trackPushNeg1(mark) // Save old mark - r.stackPush2(r.textPos(), count+1) // Make new mark, incr count - r.goTo(r.operand(0)) // Loop - } else { // Nonneg count -> straight now - r.trackPush3(mark, count, r.textPos()) // Save mark, count, position - r.advance(2) // Straight - } - continue - - case syntax.Lazybranchcount | syntax.Back: - // r.trackPush: - // 0: Mark - // 1: Count - // 2: r.textPos - - r.trackPopN(3) - mark := r.trackPeek() - textpos := r.trackPeekN(2) - - if r.trackPeekN(1) < r.operand(1) && textpos != mark { // Under limit and not empty match -> loop - r.textto(textpos) // Recall position - r.stackPush2(textpos, r.trackPeekN(1)+1) // Make new mark, incr count - r.trackPushNeg1(mark) // Save old mark - r.goTo(r.operand(0)) // Loop - continue - } else { // Max loops or empty match -> backtrack - r.stackPush2(r.trackPeek(), r.trackPeekN(1)) // Recall old mark, count - break // backtrack - } - - case syntax.Lazybranchcount | syntax.Back2: - // r.trackPush: - // 0: Previous mark - // r.stackPush: - // 0: Mark (== current pos, discarded) - // 1: Count - r.trackPop() - r.stackPopN(2) - r.stackPush2(r.trackPeek(), r.stackPeekN(1)-1) // Recall old mark, count - break // Backtrack - - case syntax.Setjump: - r.stackPush2(r.trackpos(), r.crawlpos()) - r.trackPush() - r.advance(0) - continue - - case syntax.Setjump | syntax.Back: - r.stackPopN(2) - break - - case syntax.Backjump: - // r.stackPush: - // 0: Saved trackpos - // 1: r.crawlpos - r.stackPopN(2) - r.trackto(r.stackPeek()) - - for r.crawlpos() != r.stackPeekN(1) { - r.uncapture() - } - - break - - case syntax.Forejump: - // r.stackPush: - // 0: Saved trackpos - // 1: r.crawlpos - r.stackPopN(2) - r.trackto(r.stackPeek()) - r.trackPush1(r.stackPeekN(1)) - r.advance(0) - continue - - case syntax.Forejump | syntax.Back: - // r.trackPush: - // 0: r.crawlpos - r.trackPop() - - for r.crawlpos() != r.trackPeek() { - r.uncapture() - } - - break - - case syntax.Bol: - if r.leftchars() > 0 && r.charAt(r.textPos()-1) != '\n' { - break - } - r.advance(0) - continue - - case syntax.Eol: - if r.rightchars() > 0 && r.charAt(r.textPos()) != '\n' { - break - } - r.advance(0) - continue - - case syntax.Boundary: - if !r.isBoundary(r.textPos(), 0, r.runtextend) { - break - } - r.advance(0) - continue - - case syntax.Nonboundary: - if r.isBoundary(r.textPos(), 0, r.runtextend) { - break - } - r.advance(0) - continue - - case syntax.ECMABoundary: - if !r.isECMABoundary(r.textPos(), 0, r.runtextend) { - break - } - r.advance(0) - continue - - case syntax.NonECMABoundary: - if r.isECMABoundary(r.textPos(), 0, r.runtextend) { - break - } - r.advance(0) - continue - - case syntax.Beginning: - if r.leftchars() > 0 { - break - } - r.advance(0) - continue - - case syntax.Start: - if r.textPos() != r.textstart() { - break - } - r.advance(0) - continue - - case syntax.EndZ: - rchars := r.rightchars() - if rchars > 1 { - break - } - // RE2 and EcmaScript define $ as "asserts position at the end of the string" - // PCRE/.NET adds "or before the line terminator right at the end of the string (if any)" - if (r.re.options & (RE2 | ECMAScript)) != 0 { - // RE2/Ecmascript mode - if rchars > 0 { - break - } - } else if rchars == 1 && r.charAt(r.textPos()) != '\n' { - // "regular" mode - break - } - - r.advance(0) - continue - - case syntax.End: - if r.rightchars() > 0 { - break - } - r.advance(0) - continue - - case syntax.One: - if r.forwardchars() < 1 || r.forwardcharnext() != rune(r.operand(0)) { - break - } - - r.advance(1) - continue - - case syntax.Notone: - if r.forwardchars() < 1 || r.forwardcharnext() == rune(r.operand(0)) { - break - } - - r.advance(1) - continue - - case syntax.Set: - - if r.forwardchars() < 1 || !r.code.Sets[r.operand(0)].CharIn(r.forwardcharnext()) { - break - } - - r.advance(1) - continue - - case syntax.Multi: - if !r.runematch(r.code.Strings[r.operand(0)]) { - break - } - - r.advance(1) - continue - - case syntax.Ref: - - capnum := r.operand(0) - - if r.runmatch.isMatched(capnum) { - if !r.refmatch(r.runmatch.matchIndex(capnum), r.runmatch.matchLength(capnum)) { - break - } - } else { - if (r.re.options & ECMAScript) == 0 { - break - } - } - - r.advance(1) - continue - - case syntax.Onerep: - - c := r.operand(1) - - if r.forwardchars() < c { - break - } - - ch := rune(r.operand(0)) - - for c > 0 { - if r.forwardcharnext() != ch { - goto BreakBackward - } - c-- - } - - r.advance(2) - continue - - case syntax.Notonerep: - - c := r.operand(1) - - if r.forwardchars() < c { - break - } - ch := rune(r.operand(0)) - - for c > 0 { - if r.forwardcharnext() == ch { - goto BreakBackward - } - c-- - } - - r.advance(2) - continue - - case syntax.Setrep: - - c := r.operand(1) - - if r.forwardchars() < c { - break - } - - set := r.code.Sets[r.operand(0)] - - for c > 0 { - if !set.CharIn(r.forwardcharnext()) { - goto BreakBackward - } - c-- - } - - r.advance(2) - continue - - case syntax.Oneloop: - - c := r.operand(1) - - if c > r.forwardchars() { - c = r.forwardchars() - } - - ch := rune(r.operand(0)) - i := c - - for ; i > 0; i-- { - if r.forwardcharnext() != ch { - r.backwardnext() - break - } - } - - if c > i { - r.trackPush2(c-i-1, r.textPos()-r.bump()) - } - - r.advance(2) - continue - - case syntax.Notoneloop: - - c := r.operand(1) - - if c > r.forwardchars() { - c = r.forwardchars() - } - - ch := rune(r.operand(0)) - i := c - - for ; i > 0; i-- { - if r.forwardcharnext() == ch { - r.backwardnext() - break - } - } - - if c > i { - r.trackPush2(c-i-1, r.textPos()-r.bump()) - } - - r.advance(2) - continue - - case syntax.Setloop: - - c := r.operand(1) - - if c > r.forwardchars() { - c = r.forwardchars() - } - - set := r.code.Sets[r.operand(0)] - i := c - - for ; i > 0; i-- { - if !set.CharIn(r.forwardcharnext()) { - r.backwardnext() - break - } - } - - if c > i { - r.trackPush2(c-i-1, r.textPos()-r.bump()) - } - - r.advance(2) - continue - - case syntax.Oneloop | syntax.Back, syntax.Notoneloop | syntax.Back: - - r.trackPopN(2) - i := r.trackPeek() - pos := r.trackPeekN(1) - - r.textto(pos) - - if i > 0 { - r.trackPush2(i-1, pos-r.bump()) - } - - r.advance(2) - continue - - case syntax.Setloop | syntax.Back: - - r.trackPopN(2) - i := r.trackPeek() - pos := r.trackPeekN(1) - - r.textto(pos) - - if i > 0 { - r.trackPush2(i-1, pos-r.bump()) - } - - r.advance(2) - continue - - case syntax.Onelazy, syntax.Notonelazy: - - c := r.operand(1) - - if c > r.forwardchars() { - c = r.forwardchars() - } - - if c > 0 { - r.trackPush2(c-1, r.textPos()) - } - - r.advance(2) - continue - - case syntax.Setlazy: - - c := r.operand(1) - - if c > r.forwardchars() { - c = r.forwardchars() - } - - if c > 0 { - r.trackPush2(c-1, r.textPos()) - } - - r.advance(2) - continue - - case syntax.Onelazy | syntax.Back: - - r.trackPopN(2) - pos := r.trackPeekN(1) - r.textto(pos) - - if r.forwardcharnext() != rune(r.operand(0)) { - break - } - - i := r.trackPeek() - - if i > 0 { - r.trackPush2(i-1, pos+r.bump()) - } - - r.advance(2) - continue - - case syntax.Notonelazy | syntax.Back: - - r.trackPopN(2) - pos := r.trackPeekN(1) - r.textto(pos) - - if r.forwardcharnext() == rune(r.operand(0)) { - break - } - - i := r.trackPeek() - - if i > 0 { - r.trackPush2(i-1, pos+r.bump()) - } - - r.advance(2) - continue - - case syntax.Setlazy | syntax.Back: - - r.trackPopN(2) - pos := r.trackPeekN(1) - r.textto(pos) - - if !r.code.Sets[r.operand(0)].CharIn(r.forwardcharnext()) { - break - } - - i := r.trackPeek() - - if i > 0 { - r.trackPush2(i-1, pos+r.bump()) - } - - r.advance(2) - continue - - default: - return errors.New("unknown state in regex runner") - } - - BreakBackward: - ; - - // "break Backward" comes here: - r.backtrack() - } -} - -// increase the size of stack and track storage -func (r *runner) ensureStorage() { - if r.runstackpos < r.runtrackcount*4 { - doubleIntSlice(&r.runstack, &r.runstackpos) - } - if r.runtrackpos < r.runtrackcount*4 { - doubleIntSlice(&r.runtrack, &r.runtrackpos) - } -} - -func doubleIntSlice(s *[]int, pos *int) { - oldLen := len(*s) - newS := make([]int, oldLen*2) - - copy(newS[oldLen:], *s) - *pos += oldLen - *s = newS -} - -// Save a number on the longjump unrolling stack -func (r *runner) crawl(i int) { - if r.runcrawlpos == 0 { - doubleIntSlice(&r.runcrawl, &r.runcrawlpos) - } - r.runcrawlpos-- - r.runcrawl[r.runcrawlpos] = i -} - -// Remove a number from the longjump unrolling stack -func (r *runner) popcrawl() int { - val := r.runcrawl[r.runcrawlpos] - r.runcrawlpos++ - return val -} - -// Get the height of the stack -func (r *runner) crawlpos() int { - return len(r.runcrawl) - r.runcrawlpos -} - -func (r *runner) advance(i int) { - r.codepos += (i + 1) - r.setOperator(r.code.Codes[r.codepos]) -} - -func (r *runner) goTo(newpos int) { - // when branching backward or in place, ensure storage - if newpos <= r.codepos { - r.ensureStorage() - } - - r.setOperator(r.code.Codes[newpos]) - r.codepos = newpos -} - -func (r *runner) textto(newpos int) { - r.runtextpos = newpos -} - -func (r *runner) trackto(newpos int) { - r.runtrackpos = len(r.runtrack) - newpos -} - -func (r *runner) textstart() int { - return r.runtextstart -} - -func (r *runner) textPos() int { - return r.runtextpos -} - -// push onto the backtracking stack -func (r *runner) trackpos() int { - return len(r.runtrack) - r.runtrackpos -} - -func (r *runner) trackPush() { - r.runtrackpos-- - r.runtrack[r.runtrackpos] = r.codepos -} - -func (r *runner) trackPush1(I1 int) { - r.runtrackpos-- - r.runtrack[r.runtrackpos] = I1 - r.runtrackpos-- - r.runtrack[r.runtrackpos] = r.codepos -} - -func (r *runner) trackPush2(I1, I2 int) { - r.runtrackpos-- - r.runtrack[r.runtrackpos] = I1 - r.runtrackpos-- - r.runtrack[r.runtrackpos] = I2 - r.runtrackpos-- - r.runtrack[r.runtrackpos] = r.codepos -} - -func (r *runner) trackPush3(I1, I2, I3 int) { - r.runtrackpos-- - r.runtrack[r.runtrackpos] = I1 - r.runtrackpos-- - r.runtrack[r.runtrackpos] = I2 - r.runtrackpos-- - r.runtrack[r.runtrackpos] = I3 - r.runtrackpos-- - r.runtrack[r.runtrackpos] = r.codepos -} - -func (r *runner) trackPushNeg1(I1 int) { - r.runtrackpos-- - r.runtrack[r.runtrackpos] = I1 - r.runtrackpos-- - r.runtrack[r.runtrackpos] = -r.codepos -} - -func (r *runner) trackPushNeg2(I1, I2 int) { - r.runtrackpos-- - r.runtrack[r.runtrackpos] = I1 - r.runtrackpos-- - r.runtrack[r.runtrackpos] = I2 - r.runtrackpos-- - r.runtrack[r.runtrackpos] = -r.codepos -} - -func (r *runner) backtrack() { - newpos := r.runtrack[r.runtrackpos] - r.runtrackpos++ - - if r.re.Debug() { - if newpos < 0 { - fmt.Printf(" Backtracking (back2) to code position %v\n", -newpos) - } else { - fmt.Printf(" Backtracking to code position %v\n", newpos) - } - } - - if newpos < 0 { - newpos = -newpos - r.setOperator(r.code.Codes[newpos] | syntax.Back2) - } else { - r.setOperator(r.code.Codes[newpos] | syntax.Back) - } - - // When branching backward, ensure storage - if newpos < r.codepos { - r.ensureStorage() - } - - r.codepos = newpos -} - -func (r *runner) setOperator(op int) { - r.caseInsensitive = (0 != (op & syntax.Ci)) - r.rightToLeft = (0 != (op & syntax.Rtl)) - r.operator = syntax.InstOp(op & ^(syntax.Rtl | syntax.Ci)) -} - -func (r *runner) trackPop() { - r.runtrackpos++ -} - -// pop framesize items from the backtracking stack -func (r *runner) trackPopN(framesize int) { - r.runtrackpos += framesize -} - -// Technically we are actually peeking at items already popped. So if you want to -// get and pop the top item from the stack, you do -// r.trackPop(); -// r.trackPeek(); -func (r *runner) trackPeek() int { - return r.runtrack[r.runtrackpos-1] -} - -// get the ith element down on the backtracking stack -func (r *runner) trackPeekN(i int) int { - return r.runtrack[r.runtrackpos-i-1] -} - -// Push onto the grouping stack -func (r *runner) stackPush(I1 int) { - r.runstackpos-- - r.runstack[r.runstackpos] = I1 -} - -func (r *runner) stackPush2(I1, I2 int) { - r.runstackpos-- - r.runstack[r.runstackpos] = I1 - r.runstackpos-- - r.runstack[r.runstackpos] = I2 -} - -func (r *runner) stackPop() { - r.runstackpos++ -} - -// pop framesize items from the grouping stack -func (r *runner) stackPopN(framesize int) { - r.runstackpos += framesize -} - -// Technically we are actually peeking at items already popped. So if you want to -// get and pop the top item from the stack, you do -// r.stackPop(); -// r.stackPeek(); -func (r *runner) stackPeek() int { - return r.runstack[r.runstackpos-1] -} - -// get the ith element down on the grouping stack -func (r *runner) stackPeekN(i int) int { - return r.runstack[r.runstackpos-i-1] -} - -func (r *runner) operand(i int) int { - return r.code.Codes[r.codepos+i+1] -} - -func (r *runner) leftchars() int { - return r.runtextpos -} - -func (r *runner) rightchars() int { - return r.runtextend - r.runtextpos -} - -func (r *runner) bump() int { - if r.rightToLeft { - return -1 - } - return 1 -} - -func (r *runner) forwardchars() int { - if r.rightToLeft { - return r.runtextpos - } - return r.runtextend - r.runtextpos -} - -func (r *runner) forwardcharnext() rune { - var ch rune - if r.rightToLeft { - r.runtextpos-- - ch = r.runtext[r.runtextpos] - } else { - ch = r.runtext[r.runtextpos] - r.runtextpos++ - } - - if r.caseInsensitive { - return unicode.ToLower(ch) - } - return ch -} - -func (r *runner) runematch(str []rune) bool { - var pos int - - c := len(str) - if !r.rightToLeft { - if r.runtextend-r.runtextpos < c { - return false - } - - pos = r.runtextpos + c - } else { - if r.runtextpos-0 < c { - return false - } - - pos = r.runtextpos - } - - if !r.caseInsensitive { - for c != 0 { - c-- - pos-- - if str[c] != r.runtext[pos] { - return false - } - } - } else { - for c != 0 { - c-- - pos-- - if str[c] != unicode.ToLower(r.runtext[pos]) { - return false - } - } - } - - if !r.rightToLeft { - pos += len(str) - } - - r.runtextpos = pos - - return true -} - -func (r *runner) refmatch(index, len int) bool { - var c, pos, cmpos int - - if !r.rightToLeft { - if r.runtextend-r.runtextpos < len { - return false - } - - pos = r.runtextpos + len - } else { - if r.runtextpos-0 < len { - return false - } - - pos = r.runtextpos - } - cmpos = index + len - - c = len - - if !r.caseInsensitive { - for c != 0 { - c-- - cmpos-- - pos-- - if r.runtext[cmpos] != r.runtext[pos] { - return false - } - - } - } else { - for c != 0 { - c-- - cmpos-- - pos-- - - if unicode.ToLower(r.runtext[cmpos]) != unicode.ToLower(r.runtext[pos]) { - return false - } - } - } - - if !r.rightToLeft { - pos += len - } - - r.runtextpos = pos - - return true -} - -func (r *runner) backwardnext() { - if r.rightToLeft { - r.runtextpos++ - } else { - r.runtextpos-- - } -} - -func (r *runner) charAt(j int) rune { - return r.runtext[j] -} - -func (r *runner) findFirstChar() bool { - - if 0 != (r.code.Anchors & (syntax.AnchorBeginning | syntax.AnchorStart | syntax.AnchorEndZ | syntax.AnchorEnd)) { - if !r.code.RightToLeft { - if (0 != (r.code.Anchors&syntax.AnchorBeginning) && r.runtextpos > 0) || - (0 != (r.code.Anchors&syntax.AnchorStart) && r.runtextpos > r.runtextstart) { - r.runtextpos = r.runtextend - return false - } - if 0 != (r.code.Anchors&syntax.AnchorEndZ) && r.runtextpos < r.runtextend-1 { - r.runtextpos = r.runtextend - 1 - } else if 0 != (r.code.Anchors&syntax.AnchorEnd) && r.runtextpos < r.runtextend { - r.runtextpos = r.runtextend - } - } else { - if (0 != (r.code.Anchors&syntax.AnchorEnd) && r.runtextpos < r.runtextend) || - (0 != (r.code.Anchors&syntax.AnchorEndZ) && (r.runtextpos < r.runtextend-1 || - (r.runtextpos == r.runtextend-1 && r.charAt(r.runtextpos) != '\n'))) || - (0 != (r.code.Anchors&syntax.AnchorStart) && r.runtextpos < r.runtextstart) { - r.runtextpos = 0 - return false - } - if 0 != (r.code.Anchors&syntax.AnchorBeginning) && r.runtextpos > 0 { - r.runtextpos = 0 - } - } - - if r.code.BmPrefix != nil { - return r.code.BmPrefix.IsMatch(r.runtext, r.runtextpos, 0, r.runtextend) - } - - return true // found a valid start or end anchor - } else if r.code.BmPrefix != nil { - r.runtextpos = r.code.BmPrefix.Scan(r.runtext, r.runtextpos, 0, r.runtextend) - - if r.runtextpos == -1 { - if r.code.RightToLeft { - r.runtextpos = 0 - } else { - r.runtextpos = r.runtextend - } - return false - } - - return true - } else if r.code.FcPrefix == nil { - return true - } - - r.rightToLeft = r.code.RightToLeft - r.caseInsensitive = r.code.FcPrefix.CaseInsensitive - - set := r.code.FcPrefix.PrefixSet - if set.IsSingleton() { - ch := set.SingletonChar() - for i := r.forwardchars(); i > 0; i-- { - if ch == r.forwardcharnext() { - r.backwardnext() - return true - } - } - } else { - for i := r.forwardchars(); i > 0; i-- { - n := r.forwardcharnext() - //fmt.Printf("%v in %v: %v\n", string(n), set.String(), set.CharIn(n)) - if set.CharIn(n) { - r.backwardnext() - return true - } - } - } - - return false -} - -func (r *runner) initMatch() { - // Use a hashtable'ed Match object if the capture numbers are sparse - - if r.runmatch == nil { - if r.re.caps != nil { - r.runmatch = newMatchSparse(r.re, r.re.caps, r.re.capsize, r.runtext, r.runtextstart) - } else { - r.runmatch = newMatch(r.re, r.re.capsize, r.runtext, r.runtextstart) - } - } else { - r.runmatch.reset(r.runtext, r.runtextstart) - } - - // note we test runcrawl, because it is the last one to be allocated - // If there is an alloc failure in the middle of the three allocations, - // we may still return to reuse this instance, and we want to behave - // as if the allocations didn't occur. (we used to test _trackcount != 0) - - if r.runcrawl != nil { - r.runtrackpos = len(r.runtrack) - r.runstackpos = len(r.runstack) - r.runcrawlpos = len(r.runcrawl) - return - } - - r.initTrackCount() - - tracksize := r.runtrackcount * 8 - stacksize := r.runtrackcount * 8 - - if tracksize < 32 { - tracksize = 32 - } - if stacksize < 16 { - stacksize = 16 - } - - r.runtrack = make([]int, tracksize) - r.runtrackpos = tracksize - - r.runstack = make([]int, stacksize) - r.runstackpos = stacksize - - r.runcrawl = make([]int, 32) - r.runcrawlpos = 32 -} - -func (r *runner) tidyMatch(quick bool) *Match { - if !quick { - match := r.runmatch - - r.runmatch = nil - - match.tidy(r.runtextpos) - return match - } else { - // send back our match -- it's not leaving the package, so it's safe to not clean it up - // this reduces allocs for frequent calls to the "IsMatch" bool-only functions - return r.runmatch - } -} - -// capture captures a subexpression. Note that the -// capnum used here has already been mapped to a non-sparse -// index (by the code generator RegexWriter). -func (r *runner) capture(capnum, start, end int) { - if end < start { - T := end - end = start - start = T - } - - r.crawl(capnum) - r.runmatch.addMatch(capnum, start, end-start) -} - -// transferCapture captures a subexpression. Note that the -// capnum used here has already been mapped to a non-sparse -// index (by the code generator RegexWriter). -func (r *runner) transferCapture(capnum, uncapnum, start, end int) { - var start2, end2 int - - // these are the two intervals that are cancelling each other - - if end < start { - T := end - end = start - start = T - } - - start2 = r.runmatch.matchIndex(uncapnum) - end2 = start2 + r.runmatch.matchLength(uncapnum) - - // The new capture gets the innermost defined interval - - if start >= end2 { - end = start - start = end2 - } else if end <= start2 { - start = start2 - } else { - if end > end2 { - end = end2 - } - if start2 > start { - start = start2 - } - } - - r.crawl(uncapnum) - r.runmatch.balanceMatch(uncapnum) - - if capnum != -1 { - r.crawl(capnum) - r.runmatch.addMatch(capnum, start, end-start) - } -} - -// revert the last capture -func (r *runner) uncapture() { - capnum := r.popcrawl() - r.runmatch.removeMatch(capnum) -} - -//debug - -func (r *runner) dumpState() { - back := "" - if r.operator&syntax.Back != 0 { - back = " Back" - } - if r.operator&syntax.Back2 != 0 { - back += " Back2" - } - fmt.Printf("Text: %v\nTrack: %v\nStack: %v\n %s%s\n\n", - r.textposDescription(), - r.stackDescription(r.runtrack, r.runtrackpos), - r.stackDescription(r.runstack, r.runstackpos), - r.code.OpcodeDescription(r.codepos), - back) -} - -func (r *runner) stackDescription(a []int, index int) string { - buf := &bytes.Buffer{} - - fmt.Fprintf(buf, "%v/%v", len(a)-index, len(a)) - if buf.Len() < 8 { - buf.WriteString(strings.Repeat(" ", 8-buf.Len())) - } - - buf.WriteRune('(') - for i := index; i < len(a); i++ { - if i > index { - buf.WriteRune(' ') - } - - buf.WriteString(strconv.Itoa(a[i])) - } - - buf.WriteRune(')') - - return buf.String() -} - -func (r *runner) textposDescription() string { - buf := &bytes.Buffer{} - - buf.WriteString(strconv.Itoa(r.runtextpos)) - - if buf.Len() < 8 { - buf.WriteString(strings.Repeat(" ", 8-buf.Len())) - } - - if r.runtextpos > 0 { - buf.WriteString(syntax.CharDescription(r.runtext[r.runtextpos-1])) - } else { - buf.WriteRune('^') - } - - buf.WriteRune('>') - - for i := r.runtextpos; i < r.runtextend; i++ { - buf.WriteString(syntax.CharDescription(r.runtext[i])) - } - if buf.Len() >= 64 { - buf.Truncate(61) - buf.WriteString("...") - } else { - buf.WriteRune('$') - } - - return buf.String() -} - -// decide whether the pos -// at the specified index is a boundary or not. It's just not worth -// emitting inline code for this logic. -func (r *runner) isBoundary(index, startpos, endpos int) bool { - return (index > startpos && syntax.IsWordChar(r.runtext[index-1])) != - (index < endpos && syntax.IsWordChar(r.runtext[index])) -} - -func (r *runner) isECMABoundary(index, startpos, endpos int) bool { - return (index > startpos && syntax.IsECMAWordChar(r.runtext[index-1])) != - (index < endpos && syntax.IsECMAWordChar(r.runtext[index])) -} - -func (r *runner) startTimeoutWatch() { - if r.ignoreTimeout { - return - } - r.deadline = makeDeadline(r.timeout) -} - -func (r *runner) checkTimeout() error { - if r.ignoreTimeout || !r.deadline.reached() { - return nil - } - - if r.re.Debug() { - //Debug.WriteLine("") - //Debug.WriteLine("RegEx match timeout occurred!") - //Debug.WriteLine("Specified timeout: " + TimeSpan.FromMilliseconds(_timeout).ToString()) - //Debug.WriteLine("Timeout check frequency: " + TimeoutCheckFrequency) - //Debug.WriteLine("Search pattern: " + _runregex._pattern) - //Debug.WriteLine("Input: " + r.runtext) - //Debug.WriteLine("About to throw RegexMatchTimeoutException.") - } - - return fmt.Errorf("match timeout after %v on input `%v`", r.timeout, string(r.runtext)) -} - -func (r *runner) initTrackCount() { - r.runtrackcount = r.code.TrackCount -} - -// getRunner returns a run to use for matching re. -// It uses the re's runner cache if possible, to avoid -// unnecessary allocation. -func (re *Regexp) getRunner() *runner { - re.muRun.Lock() - if n := len(re.runner); n > 0 { - z := re.runner[n-1] - re.runner = re.runner[:n-1] - re.muRun.Unlock() - return z - } - re.muRun.Unlock() - z := &runner{ - re: re, - code: re.code, - } - return z -} - -// putRunner returns a runner to the re's cache. -// There is no attempt to limit the size of the cache, so it will -// grow to the maximum number of simultaneous matches -// run using re. (The cache empties when re gets garbage collected.) -func (re *Regexp) putRunner(r *runner) { - re.muRun.Lock() - r.runtext = nil - if r.runmatch != nil { - r.runmatch.text = nil - } - re.runner = append(re.runner, r) - re.muRun.Unlock() -} diff --git a/vendor/github.com/dlclark/regexp2/syntax/charclass.go b/vendor/github.com/dlclark/regexp2/syntax/charclass.go deleted file mode 100644 index 6881a0e29..000000000 --- a/vendor/github.com/dlclark/regexp2/syntax/charclass.go +++ /dev/null @@ -1,865 +0,0 @@ -package syntax - -import ( - "bytes" - "encoding/binary" - "fmt" - "sort" - "unicode" - "unicode/utf8" -) - -// CharSet combines start-end rune ranges and unicode categories representing a set of characters -type CharSet struct { - ranges []singleRange - categories []category - sub *CharSet //optional subtractor - negate bool - anything bool -} - -type category struct { - negate bool - cat string -} - -type singleRange struct { - first rune - last rune -} - -const ( - spaceCategoryText = " " - wordCategoryText = "W" -) - -var ( - ecmaSpace = []rune{0x0009, 0x000e, 0x0020, 0x0021, 0x00a0, 0x00a1, 0x1680, 0x1681, 0x2000, 0x200b, 0x2028, 0x202a, 0x202f, 0x2030, 0x205f, 0x2060, 0x3000, 0x3001, 0xfeff, 0xff00} - ecmaWord = []rune{0x0030, 0x003a, 0x0041, 0x005b, 0x005f, 0x0060, 0x0061, 0x007b} - ecmaDigit = []rune{0x0030, 0x003a} - - re2Space = []rune{0x0009, 0x000b, 0x000c, 0x000e, 0x0020, 0x0021} -) - -var ( - AnyClass = getCharSetFromOldString([]rune{0}, false) - ECMAAnyClass = getCharSetFromOldString([]rune{0, 0x000a, 0x000b, 0x000d, 0x000e}, false) - NoneClass = getCharSetFromOldString(nil, false) - ECMAWordClass = getCharSetFromOldString(ecmaWord, false) - NotECMAWordClass = getCharSetFromOldString(ecmaWord, true) - ECMASpaceClass = getCharSetFromOldString(ecmaSpace, false) - NotECMASpaceClass = getCharSetFromOldString(ecmaSpace, true) - ECMADigitClass = getCharSetFromOldString(ecmaDigit, false) - NotECMADigitClass = getCharSetFromOldString(ecmaDigit, true) - - WordClass = getCharSetFromCategoryString(false, false, wordCategoryText) - NotWordClass = getCharSetFromCategoryString(true, false, wordCategoryText) - SpaceClass = getCharSetFromCategoryString(false, false, spaceCategoryText) - NotSpaceClass = getCharSetFromCategoryString(true, false, spaceCategoryText) - DigitClass = getCharSetFromCategoryString(false, false, "Nd") - NotDigitClass = getCharSetFromCategoryString(false, true, "Nd") - - RE2SpaceClass = getCharSetFromOldString(re2Space, false) - NotRE2SpaceClass = getCharSetFromOldString(re2Space, true) -) - -var unicodeCategories = func() map[string]*unicode.RangeTable { - retVal := make(map[string]*unicode.RangeTable) - for k, v := range unicode.Scripts { - retVal[k] = v - } - for k, v := range unicode.Categories { - retVal[k] = v - } - for k, v := range unicode.Properties { - retVal[k] = v - } - return retVal -}() - -func getCharSetFromCategoryString(negateSet bool, negateCat bool, cats ...string) func() *CharSet { - if negateCat && negateSet { - panic("BUG! You should only negate the set OR the category in a constant setup, but not both") - } - - c := CharSet{negate: negateSet} - - c.categories = make([]category, len(cats)) - for i, cat := range cats { - c.categories[i] = category{cat: cat, negate: negateCat} - } - return func() *CharSet { - //make a copy each time - local := c - //return that address - return &local - } -} - -func getCharSetFromOldString(setText []rune, negate bool) func() *CharSet { - c := CharSet{} - if len(setText) > 0 { - fillFirst := false - l := len(setText) - if negate { - if setText[0] == 0 { - setText = setText[1:] - } else { - l++ - fillFirst = true - } - } - - if l%2 == 0 { - c.ranges = make([]singleRange, l/2) - } else { - c.ranges = make([]singleRange, l/2+1) - } - - first := true - if fillFirst { - c.ranges[0] = singleRange{first: 0} - first = false - } - - i := 0 - for _, r := range setText { - if first { - // lower bound in a new range - c.ranges[i] = singleRange{first: r} - first = false - } else { - c.ranges[i].last = r - 1 - i++ - first = true - } - } - if !first { - c.ranges[i].last = utf8.MaxRune - } - } - - return func() *CharSet { - local := c - return &local - } -} - -// Copy makes a deep copy to prevent accidental mutation of a set -func (c CharSet) Copy() CharSet { - ret := CharSet{ - anything: c.anything, - negate: c.negate, - } - - ret.ranges = append(ret.ranges, c.ranges...) - ret.categories = append(ret.categories, c.categories...) - - if c.sub != nil { - sub := c.sub.Copy() - ret.sub = &sub - } - - return ret -} - -// gets a human-readable description for a set string -func (c CharSet) String() string { - buf := &bytes.Buffer{} - buf.WriteRune('[') - - if c.IsNegated() { - buf.WriteRune('^') - } - - for _, r := range c.ranges { - - buf.WriteString(CharDescription(r.first)) - if r.first != r.last { - if r.last-r.first != 1 { - //groups that are 1 char apart skip the dash - buf.WriteRune('-') - } - buf.WriteString(CharDescription(r.last)) - } - } - - for _, c := range c.categories { - buf.WriteString(c.String()) - } - - if c.sub != nil { - buf.WriteRune('-') - buf.WriteString(c.sub.String()) - } - - buf.WriteRune(']') - - return buf.String() -} - -// mapHashFill converts a charset into a buffer for use in maps -func (c CharSet) mapHashFill(buf *bytes.Buffer) { - if c.negate { - buf.WriteByte(0) - } else { - buf.WriteByte(1) - } - - binary.Write(buf, binary.LittleEndian, len(c.ranges)) - binary.Write(buf, binary.LittleEndian, len(c.categories)) - for _, r := range c.ranges { - buf.WriteRune(r.first) - buf.WriteRune(r.last) - } - for _, ct := range c.categories { - buf.WriteString(ct.cat) - if ct.negate { - buf.WriteByte(1) - } else { - buf.WriteByte(0) - } - } - - if c.sub != nil { - c.sub.mapHashFill(buf) - } -} - -// CharIn returns true if the rune is in our character set (either ranges or categories). -// It handles negations and subtracted sub-charsets. -func (c CharSet) CharIn(ch rune) bool { - val := false - // in s && !s.subtracted - - //check ranges - for _, r := range c.ranges { - if ch < r.first { - continue - } - if ch <= r.last { - val = true - break - } - } - - //check categories if we haven't already found a range - if !val && len(c.categories) > 0 { - for _, ct := range c.categories { - // special categories...then unicode - if ct.cat == spaceCategoryText { - if unicode.IsSpace(ch) { - // we found a space so we're done - // negate means this is a "bad" thing - val = !ct.negate - break - } else if ct.negate { - val = true - break - } - } else if ct.cat == wordCategoryText { - if IsWordChar(ch) { - val = !ct.negate - break - } else if ct.negate { - val = true - break - } - } else if unicode.Is(unicodeCategories[ct.cat], ch) { - // if we're in this unicode category then we're done - // if negate=true on this category then we "failed" our test - // otherwise we're good that we found it - val = !ct.negate - break - } else if ct.negate { - val = true - break - } - } - } - - // negate the whole char set - if c.negate { - val = !val - } - - // get subtracted recurse - if val && c.sub != nil { - val = !c.sub.CharIn(ch) - } - - //log.Printf("Char '%v' in %v == %v", string(ch), c.String(), val) - return val -} - -func (c category) String() string { - switch c.cat { - case spaceCategoryText: - if c.negate { - return "\\S" - } - return "\\s" - case wordCategoryText: - if c.negate { - return "\\W" - } - return "\\w" - } - if _, ok := unicodeCategories[c.cat]; ok { - - if c.negate { - return "\\P{" + c.cat + "}" - } - return "\\p{" + c.cat + "}" - } - return "Unknown category: " + c.cat -} - -// CharDescription Produces a human-readable description for a single character. -func CharDescription(ch rune) string { - /*if ch == '\\' { - return "\\\\" - } - - if ch > ' ' && ch <= '~' { - return string(ch) - } else if ch == '\n' { - return "\\n" - } else if ch == ' ' { - return "\\ " - }*/ - - b := &bytes.Buffer{} - escape(b, ch, false) //fmt.Sprintf("%U", ch) - return b.String() -} - -// According to UTS#18 Unicode Regular Expressions (http://www.unicode.org/reports/tr18/) -// RL 1.4 Simple Word Boundaries The class of includes all Alphabetic -// values from the Unicode character database, from UnicodeData.txt [UData], plus the U+200C -// ZERO WIDTH NON-JOINER and U+200D ZERO WIDTH JOINER. -func IsWordChar(r rune) bool { - //"L", "Mn", "Nd", "Pc" - return unicode.In(r, - unicode.Categories["L"], unicode.Categories["Mn"], - unicode.Categories["Nd"], unicode.Categories["Pc"]) || r == '\u200D' || r == '\u200C' - //return 'A' <= r && r <= 'Z' || 'a' <= r && r <= 'z' || '0' <= r && r <= '9' || r == '_' -} - -func IsECMAWordChar(r rune) bool { - return unicode.In(r, - unicode.Categories["L"], unicode.Categories["Mn"], - unicode.Categories["Nd"], unicode.Categories["Pc"]) - - //return 'A' <= r && r <= 'Z' || 'a' <= r && r <= 'z' || '0' <= r && r <= '9' || r == '_' -} - -// SingletonChar will return the char from the first range without validation. -// It assumes you have checked for IsSingleton or IsSingletonInverse and will panic given bad input -func (c CharSet) SingletonChar() rune { - return c.ranges[0].first -} - -func (c CharSet) IsSingleton() bool { - return !c.negate && //negated is multiple chars - len(c.categories) == 0 && len(c.ranges) == 1 && // multiple ranges and unicode classes represent multiple chars - c.sub == nil && // subtraction means we've got multiple chars - c.ranges[0].first == c.ranges[0].last // first and last equal means we're just 1 char -} - -func (c CharSet) IsSingletonInverse() bool { - return c.negate && //same as above, but requires negated - len(c.categories) == 0 && len(c.ranges) == 1 && // multiple ranges and unicode classes represent multiple chars - c.sub == nil && // subtraction means we've got multiple chars - c.ranges[0].first == c.ranges[0].last // first and last equal means we're just 1 char -} - -func (c CharSet) IsMergeable() bool { - return !c.IsNegated() && !c.HasSubtraction() -} - -func (c CharSet) IsNegated() bool { - return c.negate -} - -func (c CharSet) HasSubtraction() bool { - return c.sub != nil -} - -func (c CharSet) IsEmpty() bool { - return len(c.ranges) == 0 && len(c.categories) == 0 && c.sub == nil -} - -func (c *CharSet) addDigit(ecma, negate bool, pattern string) { - if ecma { - if negate { - c.addRanges(NotECMADigitClass().ranges) - } else { - c.addRanges(ECMADigitClass().ranges) - } - } else { - c.addCategories(category{cat: "Nd", negate: negate}) - } -} - -func (c *CharSet) addChar(ch rune) { - c.addRange(ch, ch) -} - -func (c *CharSet) addSpace(ecma, re2, negate bool) { - if ecma { - if negate { - c.addRanges(NotECMASpaceClass().ranges) - } else { - c.addRanges(ECMASpaceClass().ranges) - } - } else if re2 { - if negate { - c.addRanges(NotRE2SpaceClass().ranges) - } else { - c.addRanges(RE2SpaceClass().ranges) - } - } else { - c.addCategories(category{cat: spaceCategoryText, negate: negate}) - } -} - -func (c *CharSet) addWord(ecma, negate bool) { - if ecma { - if negate { - c.addRanges(NotECMAWordClass().ranges) - } else { - c.addRanges(ECMAWordClass().ranges) - } - } else { - c.addCategories(category{cat: wordCategoryText, negate: negate}) - } -} - -// Add set ranges and categories into ours -- no deduping or anything -func (c *CharSet) addSet(set CharSet) { - if c.anything { - return - } - if set.anything { - c.makeAnything() - return - } - // just append here to prevent double-canon - c.ranges = append(c.ranges, set.ranges...) - c.addCategories(set.categories...) - c.canonicalize() -} - -func (c *CharSet) makeAnything() { - c.anything = true - c.categories = []category{} - c.ranges = AnyClass().ranges -} - -func (c *CharSet) addCategories(cats ...category) { - // don't add dupes and remove positive+negative - if c.anything { - // if we've had a previous positive+negative group then - // just return, we're as broad as we can get - return - } - - for _, ct := range cats { - found := false - for _, ct2 := range c.categories { - if ct.cat == ct2.cat { - if ct.negate != ct2.negate { - // oposite negations...this mean we just - // take us as anything and move on - c.makeAnything() - return - } - found = true - break - } - } - - if !found { - c.categories = append(c.categories, ct) - } - } -} - -// Merges new ranges to our own -func (c *CharSet) addRanges(ranges []singleRange) { - if c.anything { - return - } - c.ranges = append(c.ranges, ranges...) - c.canonicalize() -} - -// Merges everything but the new ranges into our own -func (c *CharSet) addNegativeRanges(ranges []singleRange) { - if c.anything { - return - } - - var hi rune - - // convert incoming ranges into opposites, assume they are in order - for _, r := range ranges { - if hi < r.first { - c.ranges = append(c.ranges, singleRange{hi, r.first - 1}) - } - hi = r.last + 1 - } - - if hi < utf8.MaxRune { - c.ranges = append(c.ranges, singleRange{hi, utf8.MaxRune}) - } - - c.canonicalize() -} - -func isValidUnicodeCat(catName string) bool { - _, ok := unicodeCategories[catName] - return ok -} - -func (c *CharSet) addCategory(categoryName string, negate, caseInsensitive bool, pattern string) { - if !isValidUnicodeCat(categoryName) { - // unknown unicode category, script, or property "blah" - panic(fmt.Errorf("Unknown unicode category, script, or property '%v'", categoryName)) - - } - - if caseInsensitive && (categoryName == "Ll" || categoryName == "Lu" || categoryName == "Lt") { - // when RegexOptions.IgnoreCase is specified then {Ll} {Lu} and {Lt} cases should all match - c.addCategories( - category{cat: "Ll", negate: negate}, - category{cat: "Lu", negate: negate}, - category{cat: "Lt", negate: negate}) - } - c.addCategories(category{cat: categoryName, negate: negate}) -} - -func (c *CharSet) addSubtraction(sub *CharSet) { - c.sub = sub -} - -func (c *CharSet) addRange(chMin, chMax rune) { - c.ranges = append(c.ranges, singleRange{first: chMin, last: chMax}) - c.canonicalize() -} - -func (c *CharSet) addNamedASCII(name string, negate bool) bool { - var rs []singleRange - - switch name { - case "alnum": - rs = []singleRange{singleRange{'0', '9'}, singleRange{'A', 'Z'}, singleRange{'a', 'z'}} - case "alpha": - rs = []singleRange{singleRange{'A', 'Z'}, singleRange{'a', 'z'}} - case "ascii": - rs = []singleRange{singleRange{0, 0x7f}} - case "blank": - rs = []singleRange{singleRange{'\t', '\t'}, singleRange{' ', ' '}} - case "cntrl": - rs = []singleRange{singleRange{0, 0x1f}, singleRange{0x7f, 0x7f}} - case "digit": - c.addDigit(false, negate, "") - case "graph": - rs = []singleRange{singleRange{'!', '~'}} - case "lower": - rs = []singleRange{singleRange{'a', 'z'}} - case "print": - rs = []singleRange{singleRange{' ', '~'}} - case "punct": //[!-/:-@[-`{-~] - rs = []singleRange{singleRange{'!', '/'}, singleRange{':', '@'}, singleRange{'[', '`'}, singleRange{'{', '~'}} - case "space": - c.addSpace(true, false, negate) - case "upper": - rs = []singleRange{singleRange{'A', 'Z'}} - case "word": - c.addWord(true, negate) - case "xdigit": - rs = []singleRange{singleRange{'0', '9'}, singleRange{'A', 'F'}, singleRange{'a', 'f'}} - default: - return false - } - - if len(rs) > 0 { - if negate { - c.addNegativeRanges(rs) - } else { - c.addRanges(rs) - } - } - - return true -} - -type singleRangeSorter []singleRange - -func (p singleRangeSorter) Len() int { return len(p) } -func (p singleRangeSorter) Less(i, j int) bool { return p[i].first < p[j].first } -func (p singleRangeSorter) Swap(i, j int) { p[i], p[j] = p[j], p[i] } - -// Logic to reduce a character class to a unique, sorted form. -func (c *CharSet) canonicalize() { - var i, j int - var last rune - - // - // Find and eliminate overlapping or abutting ranges - // - - if len(c.ranges) > 1 { - sort.Sort(singleRangeSorter(c.ranges)) - - done := false - - for i, j = 1, 0; ; i++ { - for last = c.ranges[j].last; ; i++ { - if i == len(c.ranges) || last == utf8.MaxRune { - done = true - break - } - - CurrentRange := c.ranges[i] - if CurrentRange.first > last+1 { - break - } - - if last < CurrentRange.last { - last = CurrentRange.last - } - } - - c.ranges[j] = singleRange{first: c.ranges[j].first, last: last} - - j++ - - if done { - break - } - - if j < i { - c.ranges[j] = c.ranges[i] - } - } - - c.ranges = append(c.ranges[:j], c.ranges[len(c.ranges):]...) - } -} - -// Adds to the class any lowercase versions of characters already -// in the class. Used for case-insensitivity. -func (c *CharSet) addLowercase() { - if c.anything { - return - } - toAdd := []singleRange{} - for i := 0; i < len(c.ranges); i++ { - r := c.ranges[i] - if r.first == r.last { - lower := unicode.ToLower(r.first) - c.ranges[i] = singleRange{first: lower, last: lower} - } else { - toAdd = append(toAdd, r) - } - } - - for _, r := range toAdd { - c.addLowercaseRange(r.first, r.last) - } - c.canonicalize() -} - -/************************************************************************** - Let U be the set of Unicode character values and let L be the lowercase - function, mapping from U to U. To perform case insensitive matching of - character sets, we need to be able to map an interval I in U, say - - I = [chMin, chMax] = { ch : chMin <= ch <= chMax } - - to a set A such that A contains L(I) and A is contained in the union of - I and L(I). - - The table below partitions U into intervals on which L is non-decreasing. - Thus, for any interval J = [a, b] contained in one of these intervals, - L(J) is contained in [L(a), L(b)]. - - It is also true that for any such J, [L(a), L(b)] is contained in the - union of J and L(J). This does not follow from L being non-decreasing on - these intervals. It follows from the nature of the L on each interval. - On each interval, L has one of the following forms: - - (1) L(ch) = constant (LowercaseSet) - (2) L(ch) = ch + offset (LowercaseAdd) - (3) L(ch) = ch | 1 (LowercaseBor) - (4) L(ch) = ch + (ch & 1) (LowercaseBad) - - It is easy to verify that for any of these forms [L(a), L(b)] is - contained in the union of [a, b] and L([a, b]). -***************************************************************************/ - -const ( - LowercaseSet = 0 // Set to arg. - LowercaseAdd = 1 // Add arg. - LowercaseBor = 2 // Bitwise or with 1. - LowercaseBad = 3 // Bitwise and with 1 and add original. -) - -type lcMap struct { - chMin, chMax rune - op, data int32 -} - -var lcTable = []lcMap{ - lcMap{'\u0041', '\u005A', LowercaseAdd, 32}, - lcMap{'\u00C0', '\u00DE', LowercaseAdd, 32}, - lcMap{'\u0100', '\u012E', LowercaseBor, 0}, - lcMap{'\u0130', '\u0130', LowercaseSet, 0x0069}, - lcMap{'\u0132', '\u0136', LowercaseBor, 0}, - lcMap{'\u0139', '\u0147', LowercaseBad, 0}, - lcMap{'\u014A', '\u0176', LowercaseBor, 0}, - lcMap{'\u0178', '\u0178', LowercaseSet, 0x00FF}, - lcMap{'\u0179', '\u017D', LowercaseBad, 0}, - lcMap{'\u0181', '\u0181', LowercaseSet, 0x0253}, - lcMap{'\u0182', '\u0184', LowercaseBor, 0}, - lcMap{'\u0186', '\u0186', LowercaseSet, 0x0254}, - lcMap{'\u0187', '\u0187', LowercaseSet, 0x0188}, - lcMap{'\u0189', '\u018A', LowercaseAdd, 205}, - lcMap{'\u018B', '\u018B', LowercaseSet, 0x018C}, - lcMap{'\u018E', '\u018E', LowercaseSet, 0x01DD}, - lcMap{'\u018F', '\u018F', LowercaseSet, 0x0259}, - lcMap{'\u0190', '\u0190', LowercaseSet, 0x025B}, - lcMap{'\u0191', '\u0191', LowercaseSet, 0x0192}, - lcMap{'\u0193', '\u0193', LowercaseSet, 0x0260}, - lcMap{'\u0194', '\u0194', LowercaseSet, 0x0263}, - lcMap{'\u0196', '\u0196', LowercaseSet, 0x0269}, - lcMap{'\u0197', '\u0197', LowercaseSet, 0x0268}, - lcMap{'\u0198', '\u0198', LowercaseSet, 0x0199}, - lcMap{'\u019C', '\u019C', LowercaseSet, 0x026F}, - lcMap{'\u019D', '\u019D', LowercaseSet, 0x0272}, - lcMap{'\u019F', '\u019F', LowercaseSet, 0x0275}, - lcMap{'\u01A0', '\u01A4', LowercaseBor, 0}, - lcMap{'\u01A7', '\u01A7', LowercaseSet, 0x01A8}, - lcMap{'\u01A9', '\u01A9', LowercaseSet, 0x0283}, - lcMap{'\u01AC', '\u01AC', LowercaseSet, 0x01AD}, - lcMap{'\u01AE', '\u01AE', LowercaseSet, 0x0288}, - lcMap{'\u01AF', '\u01AF', LowercaseSet, 0x01B0}, - lcMap{'\u01B1', '\u01B2', LowercaseAdd, 217}, - lcMap{'\u01B3', '\u01B5', LowercaseBad, 0}, - lcMap{'\u01B7', '\u01B7', LowercaseSet, 0x0292}, - lcMap{'\u01B8', '\u01B8', LowercaseSet, 0x01B9}, - lcMap{'\u01BC', '\u01BC', LowercaseSet, 0x01BD}, - lcMap{'\u01C4', '\u01C5', LowercaseSet, 0x01C6}, - lcMap{'\u01C7', '\u01C8', LowercaseSet, 0x01C9}, - lcMap{'\u01CA', '\u01CB', LowercaseSet, 0x01CC}, - lcMap{'\u01CD', '\u01DB', LowercaseBad, 0}, - lcMap{'\u01DE', '\u01EE', LowercaseBor, 0}, - lcMap{'\u01F1', '\u01F2', LowercaseSet, 0x01F3}, - lcMap{'\u01F4', '\u01F4', LowercaseSet, 0x01F5}, - lcMap{'\u01FA', '\u0216', LowercaseBor, 0}, - lcMap{'\u0386', '\u0386', LowercaseSet, 0x03AC}, - lcMap{'\u0388', '\u038A', LowercaseAdd, 37}, - lcMap{'\u038C', '\u038C', LowercaseSet, 0x03CC}, - lcMap{'\u038E', '\u038F', LowercaseAdd, 63}, - lcMap{'\u0391', '\u03AB', LowercaseAdd, 32}, - lcMap{'\u03E2', '\u03EE', LowercaseBor, 0}, - lcMap{'\u0401', '\u040F', LowercaseAdd, 80}, - lcMap{'\u0410', '\u042F', LowercaseAdd, 32}, - lcMap{'\u0460', '\u0480', LowercaseBor, 0}, - lcMap{'\u0490', '\u04BE', LowercaseBor, 0}, - lcMap{'\u04C1', '\u04C3', LowercaseBad, 0}, - lcMap{'\u04C7', '\u04C7', LowercaseSet, 0x04C8}, - lcMap{'\u04CB', '\u04CB', LowercaseSet, 0x04CC}, - lcMap{'\u04D0', '\u04EA', LowercaseBor, 0}, - lcMap{'\u04EE', '\u04F4', LowercaseBor, 0}, - lcMap{'\u04F8', '\u04F8', LowercaseSet, 0x04F9}, - lcMap{'\u0531', '\u0556', LowercaseAdd, 48}, - lcMap{'\u10A0', '\u10C5', LowercaseAdd, 48}, - lcMap{'\u1E00', '\u1EF8', LowercaseBor, 0}, - lcMap{'\u1F08', '\u1F0F', LowercaseAdd, -8}, - lcMap{'\u1F18', '\u1F1F', LowercaseAdd, -8}, - lcMap{'\u1F28', '\u1F2F', LowercaseAdd, -8}, - lcMap{'\u1F38', '\u1F3F', LowercaseAdd, -8}, - lcMap{'\u1F48', '\u1F4D', LowercaseAdd, -8}, - lcMap{'\u1F59', '\u1F59', LowercaseSet, 0x1F51}, - lcMap{'\u1F5B', '\u1F5B', LowercaseSet, 0x1F53}, - lcMap{'\u1F5D', '\u1F5D', LowercaseSet, 0x1F55}, - lcMap{'\u1F5F', '\u1F5F', LowercaseSet, 0x1F57}, - lcMap{'\u1F68', '\u1F6F', LowercaseAdd, -8}, - lcMap{'\u1F88', '\u1F8F', LowercaseAdd, -8}, - lcMap{'\u1F98', '\u1F9F', LowercaseAdd, -8}, - lcMap{'\u1FA8', '\u1FAF', LowercaseAdd, -8}, - lcMap{'\u1FB8', '\u1FB9', LowercaseAdd, -8}, - lcMap{'\u1FBA', '\u1FBB', LowercaseAdd, -74}, - lcMap{'\u1FBC', '\u1FBC', LowercaseSet, 0x1FB3}, - lcMap{'\u1FC8', '\u1FCB', LowercaseAdd, -86}, - lcMap{'\u1FCC', '\u1FCC', LowercaseSet, 0x1FC3}, - lcMap{'\u1FD8', '\u1FD9', LowercaseAdd, -8}, - lcMap{'\u1FDA', '\u1FDB', LowercaseAdd, -100}, - lcMap{'\u1FE8', '\u1FE9', LowercaseAdd, -8}, - lcMap{'\u1FEA', '\u1FEB', LowercaseAdd, -112}, - lcMap{'\u1FEC', '\u1FEC', LowercaseSet, 0x1FE5}, - lcMap{'\u1FF8', '\u1FF9', LowercaseAdd, -128}, - lcMap{'\u1FFA', '\u1FFB', LowercaseAdd, -126}, - lcMap{'\u1FFC', '\u1FFC', LowercaseSet, 0x1FF3}, - lcMap{'\u2160', '\u216F', LowercaseAdd, 16}, - lcMap{'\u24B6', '\u24D0', LowercaseAdd, 26}, - lcMap{'\uFF21', '\uFF3A', LowercaseAdd, 32}, -} - -func (c *CharSet) addLowercaseRange(chMin, chMax rune) { - var i, iMax, iMid int - var chMinT, chMaxT rune - var lc lcMap - - for i, iMax = 0, len(lcTable); i < iMax; { - iMid = (i + iMax) / 2 - if lcTable[iMid].chMax < chMin { - i = iMid + 1 - } else { - iMax = iMid - } - } - - for ; i < len(lcTable); i++ { - lc = lcTable[i] - if lc.chMin > chMax { - return - } - chMinT = lc.chMin - if chMinT < chMin { - chMinT = chMin - } - - chMaxT = lc.chMax - if chMaxT > chMax { - chMaxT = chMax - } - - switch lc.op { - case LowercaseSet: - chMinT = rune(lc.data) - chMaxT = rune(lc.data) - break - case LowercaseAdd: - chMinT += lc.data - chMaxT += lc.data - break - case LowercaseBor: - chMinT |= 1 - chMaxT |= 1 - break - case LowercaseBad: - chMinT += (chMinT & 1) - chMaxT += (chMaxT & 1) - break - } - - if chMinT < chMin || chMaxT > chMax { - c.addRange(chMinT, chMaxT) - } - } -} diff --git a/vendor/github.com/dlclark/regexp2/syntax/code.go b/vendor/github.com/dlclark/regexp2/syntax/code.go deleted file mode 100644 index 686e822af..000000000 --- a/vendor/github.com/dlclark/regexp2/syntax/code.go +++ /dev/null @@ -1,274 +0,0 @@ -package syntax - -import ( - "bytes" - "fmt" - "math" -) - -// similar to prog.go in the go regex package...also with comment 'may not belong in this package' - -// File provides operator constants for use by the Builder and the Machine. - -// Implementation notes: -// -// Regexps are built into RegexCodes, which contain an operation array, -// a string table, and some constants. -// -// Each operation is one of the codes below, followed by the integer -// operands specified for each op. -// -// Strings and sets are indices into a string table. - -type InstOp int - -const ( - // lef/back operands description - - Onerep InstOp = 0 // lef,back char,min,max a {n} - Notonerep = 1 // lef,back char,min,max .{n} - Setrep = 2 // lef,back set,min,max [\d]{n} - - Oneloop = 3 // lef,back char,min,max a {,n} - Notoneloop = 4 // lef,back char,min,max .{,n} - Setloop = 5 // lef,back set,min,max [\d]{,n} - - Onelazy = 6 // lef,back char,min,max a {,n}? - Notonelazy = 7 // lef,back char,min,max .{,n}? - Setlazy = 8 // lef,back set,min,max [\d]{,n}? - - One = 9 // lef char a - Notone = 10 // lef char [^a] - Set = 11 // lef set [a-z\s] \w \s \d - - Multi = 12 // lef string abcd - Ref = 13 // lef group \# - - Bol = 14 // ^ - Eol = 15 // $ - Boundary = 16 // \b - Nonboundary = 17 // \B - Beginning = 18 // \A - Start = 19 // \G - EndZ = 20 // \Z - End = 21 // \Z - - Nothing = 22 // Reject! - - // Primitive control structures - - Lazybranch = 23 // back jump straight first - Branchmark = 24 // back jump branch first for loop - Lazybranchmark = 25 // back jump straight first for loop - Nullcount = 26 // back val set counter, null mark - Setcount = 27 // back val set counter, make mark - Branchcount = 28 // back jump,limit branch++ if zero<=c impl group slots - Capsize int // number of impl group slots - FcPrefix *Prefix // the set of candidate first characters (may be null) - BmPrefix *BmPrefix // the fixed prefix string as a Boyer-Moore machine (may be null) - Anchors AnchorLoc // the set of zero-length start anchors (RegexFCD.Bol, etc) - RightToLeft bool // true if right to left -} - -func opcodeBacktracks(op InstOp) bool { - op &= Mask - - switch op { - case Oneloop, Notoneloop, Setloop, Onelazy, Notonelazy, Setlazy, Lazybranch, Branchmark, Lazybranchmark, - Nullcount, Setcount, Branchcount, Lazybranchcount, Setmark, Capturemark, Getmark, Setjump, Backjump, - Forejump, Goto: - return true - - default: - return false - } -} - -func opcodeSize(op InstOp) int { - op &= Mask - - switch op { - case Nothing, Bol, Eol, Boundary, Nonboundary, ECMABoundary, NonECMABoundary, Beginning, Start, EndZ, - End, Nullmark, Setmark, Getmark, Setjump, Backjump, Forejump, Stop: - return 1 - - case One, Notone, Multi, Ref, Testref, Goto, Nullcount, Setcount, Lazybranch, Branchmark, Lazybranchmark, - Prune, Set: - return 2 - - case Capturemark, Branchcount, Lazybranchcount, Onerep, Notonerep, Oneloop, Notoneloop, Onelazy, Notonelazy, - Setlazy, Setrep, Setloop: - return 3 - - default: - panic(fmt.Errorf("Unexpected op code: %v", op)) - } -} - -var codeStr = []string{ - "Onerep", "Notonerep", "Setrep", - "Oneloop", "Notoneloop", "Setloop", - "Onelazy", "Notonelazy", "Setlazy", - "One", "Notone", "Set", - "Multi", "Ref", - "Bol", "Eol", "Boundary", "Nonboundary", "Beginning", "Start", "EndZ", "End", - "Nothing", - "Lazybranch", "Branchmark", "Lazybranchmark", - "Nullcount", "Setcount", "Branchcount", "Lazybranchcount", - "Nullmark", "Setmark", "Capturemark", "Getmark", - "Setjump", "Backjump", "Forejump", "Testref", "Goto", - "Prune", "Stop", - "ECMABoundary", "NonECMABoundary", -} - -func operatorDescription(op InstOp) string { - desc := codeStr[op&Mask] - if (op & Ci) != 0 { - desc += "-Ci" - } - if (op & Rtl) != 0 { - desc += "-Rtl" - } - if (op & Back) != 0 { - desc += "-Back" - } - if (op & Back2) != 0 { - desc += "-Back2" - } - - return desc -} - -// OpcodeDescription is a humman readable string of the specific offset -func (c *Code) OpcodeDescription(offset int) string { - buf := &bytes.Buffer{} - - op := InstOp(c.Codes[offset]) - fmt.Fprintf(buf, "%06d ", offset) - - if opcodeBacktracks(op & Mask) { - buf.WriteString("*") - } else { - buf.WriteString(" ") - } - buf.WriteString(operatorDescription(op)) - buf.WriteString("(") - op &= Mask - - switch op { - case One, Notone, Onerep, Notonerep, Oneloop, Notoneloop, Onelazy, Notonelazy: - buf.WriteString("Ch = ") - buf.WriteString(CharDescription(rune(c.Codes[offset+1]))) - - case Set, Setrep, Setloop, Setlazy: - buf.WriteString("Set = ") - buf.WriteString(c.Sets[c.Codes[offset+1]].String()) - - case Multi: - fmt.Fprintf(buf, "String = %s", string(c.Strings[c.Codes[offset+1]])) - - case Ref, Testref: - fmt.Fprintf(buf, "Index = %d", c.Codes[offset+1]) - - case Capturemark: - fmt.Fprintf(buf, "Index = %d", c.Codes[offset+1]) - if c.Codes[offset+2] != -1 { - fmt.Fprintf(buf, ", Unindex = %d", c.Codes[offset+2]) - } - - case Nullcount, Setcount: - fmt.Fprintf(buf, "Value = %d", c.Codes[offset+1]) - - case Goto, Lazybranch, Branchmark, Lazybranchmark, Branchcount, Lazybranchcount: - fmt.Fprintf(buf, "Addr = %d", c.Codes[offset+1]) - } - - switch op { - case Onerep, Notonerep, Oneloop, Notoneloop, Onelazy, Notonelazy, Setrep, Setloop, Setlazy: - buf.WriteString(", Rep = ") - if c.Codes[offset+2] == math.MaxInt32 { - buf.WriteString("inf") - } else { - fmt.Fprintf(buf, "%d", c.Codes[offset+2]) - } - - case Branchcount, Lazybranchcount: - buf.WriteString(", Limit = ") - if c.Codes[offset+2] == math.MaxInt32 { - buf.WriteString("inf") - } else { - fmt.Fprintf(buf, "%d", c.Codes[offset+2]) - } - - } - - buf.WriteString(")") - - return buf.String() -} - -func (c *Code) Dump() string { - buf := &bytes.Buffer{} - - if c.RightToLeft { - fmt.Fprintln(buf, "Direction: right-to-left") - } else { - fmt.Fprintln(buf, "Direction: left-to-right") - } - if c.FcPrefix == nil { - fmt.Fprintln(buf, "Firstchars: n/a") - } else { - fmt.Fprintf(buf, "Firstchars: %v\n", c.FcPrefix.PrefixSet.String()) - } - - if c.BmPrefix == nil { - fmt.Fprintln(buf, "Prefix: n/a") - } else { - fmt.Fprintf(buf, "Prefix: %v\n", Escape(c.BmPrefix.String())) - } - - fmt.Fprintf(buf, "Anchors: %v\n", c.Anchors) - fmt.Fprintln(buf) - - if c.BmPrefix != nil { - fmt.Fprintln(buf, "BoyerMoore:") - fmt.Fprintln(buf, c.BmPrefix.Dump(" ")) - } - for i := 0; i < len(c.Codes); i += opcodeSize(InstOp(c.Codes[i])) { - fmt.Fprintln(buf, c.OpcodeDescription(i)) - } - - return buf.String() -} diff --git a/vendor/github.com/dlclark/regexp2/syntax/tree.go b/vendor/github.com/dlclark/regexp2/syntax/tree.go deleted file mode 100644 index ea2882931..000000000 --- a/vendor/github.com/dlclark/regexp2/syntax/tree.go +++ /dev/null @@ -1,654 +0,0 @@ -package syntax - -import ( - "bytes" - "fmt" - "math" - "strconv" -) - -type RegexTree struct { - root *regexNode - caps map[int]int - capnumlist []int - captop int - Capnames map[string]int - Caplist []string - options RegexOptions -} - -// It is built into a parsed tree for a regular expression. - -// Implementation notes: -// -// Since the node tree is a temporary data structure only used -// during compilation of the regexp to integer codes, it's -// designed for clarity and convenience rather than -// space efficiency. -// -// RegexNodes are built into a tree, linked by the n.children list. -// Each node also has a n.parent and n.ichild member indicating -// its parent and which child # it is in its parent's list. -// -// RegexNodes come in as many types as there are constructs in -// a regular expression, for example, "concatenate", "alternate", -// "one", "rept", "group". There are also node types for basic -// peephole optimizations, e.g., "onerep", "notsetrep", etc. -// -// Because perl 5 allows "lookback" groups that scan backwards, -// each node also gets a "direction". Normally the value of -// boolean n.backward = false. -// -// During parsing, top-level nodes are also stacked onto a parse -// stack (a stack of trees). For this purpose we have a n.next -// pointer. [Note that to save a few bytes, we could overload the -// n.parent pointer instead.] -// -// On the parse stack, each tree has a "role" - basically, the -// nonterminal in the grammar that the parser has currently -// assigned to the tree. That code is stored in n.role. -// -// Finally, some of the different kinds of nodes have data. -// Two integers (for the looping constructs) are stored in -// n.operands, an an object (either a string or a set) -// is stored in n.data -type regexNode struct { - t nodeType - children []*regexNode - str []rune - set *CharSet - ch rune - m int - n int - options RegexOptions - next *regexNode -} - -type nodeType int32 - -const ( - // The following are leaves, and correspond to primitive operations - - ntOnerep nodeType = 0 // lef,back char,min,max a {n} - ntNotonerep = 1 // lef,back char,min,max .{n} - ntSetrep = 2 // lef,back set,min,max [\d]{n} - ntOneloop = 3 // lef,back char,min,max a {,n} - ntNotoneloop = 4 // lef,back char,min,max .{,n} - ntSetloop = 5 // lef,back set,min,max [\d]{,n} - ntOnelazy = 6 // lef,back char,min,max a {,n}? - ntNotonelazy = 7 // lef,back char,min,max .{,n}? - ntSetlazy = 8 // lef,back set,min,max [\d]{,n}? - ntOne = 9 // lef char a - ntNotone = 10 // lef char [^a] - ntSet = 11 // lef set [a-z\s] \w \s \d - ntMulti = 12 // lef string abcd - ntRef = 13 // lef group \# - ntBol = 14 // ^ - ntEol = 15 // $ - ntBoundary = 16 // \b - ntNonboundary = 17 // \B - ntBeginning = 18 // \A - ntStart = 19 // \G - ntEndZ = 20 // \Z - ntEnd = 21 // \Z - - // Interior nodes do not correspond to primitive operations, but - // control structures compositing other operations - - // Concat and alternate take n children, and can run forward or backwards - - ntNothing = 22 // [] - ntEmpty = 23 // () - ntAlternate = 24 // a|b - ntConcatenate = 25 // ab - ntLoop = 26 // m,x * + ? {,} - ntLazyloop = 27 // m,x *? +? ?? {,}? - ntCapture = 28 // n () - ntGroup = 29 // (?:) - ntRequire = 30 // (?=) (?<=) - ntPrevent = 31 // (?!) (?) (?<) - ntTestref = 33 // (?(n) | ) - ntTestgroup = 34 // (?(...) | ) - - ntECMABoundary = 41 // \b - ntNonECMABoundary = 42 // \B -) - -func newRegexNode(t nodeType, opt RegexOptions) *regexNode { - return ®exNode{ - t: t, - options: opt, - } -} - -func newRegexNodeCh(t nodeType, opt RegexOptions, ch rune) *regexNode { - return ®exNode{ - t: t, - options: opt, - ch: ch, - } -} - -func newRegexNodeStr(t nodeType, opt RegexOptions, str []rune) *regexNode { - return ®exNode{ - t: t, - options: opt, - str: str, - } -} - -func newRegexNodeSet(t nodeType, opt RegexOptions, set *CharSet) *regexNode { - return ®exNode{ - t: t, - options: opt, - set: set, - } -} - -func newRegexNodeM(t nodeType, opt RegexOptions, m int) *regexNode { - return ®exNode{ - t: t, - options: opt, - m: m, - } -} -func newRegexNodeMN(t nodeType, opt RegexOptions, m, n int) *regexNode { - return ®exNode{ - t: t, - options: opt, - m: m, - n: n, - } -} - -func (n *regexNode) writeStrToBuf(buf *bytes.Buffer) { - for i := 0; i < len(n.str); i++ { - buf.WriteRune(n.str[i]) - } -} - -func (n *regexNode) addChild(child *regexNode) { - reduced := child.reduce() - n.children = append(n.children, reduced) - reduced.next = n -} - -func (n *regexNode) insertChildren(afterIndex int, nodes []*regexNode) { - newChildren := make([]*regexNode, 0, len(n.children)+len(nodes)) - n.children = append(append(append(newChildren, n.children[:afterIndex]...), nodes...), n.children[afterIndex:]...) -} - -// removes children including the start but not the end index -func (n *regexNode) removeChildren(startIndex, endIndex int) { - n.children = append(n.children[:startIndex], n.children[endIndex:]...) -} - -// Pass type as OneLazy or OneLoop -func (n *regexNode) makeRep(t nodeType, min, max int) { - n.t += (t - ntOne) - n.m = min - n.n = max -} - -func (n *regexNode) reduce() *regexNode { - switch n.t { - case ntAlternate: - return n.reduceAlternation() - - case ntConcatenate: - return n.reduceConcatenation() - - case ntLoop, ntLazyloop: - return n.reduceRep() - - case ntGroup: - return n.reduceGroup() - - case ntSet, ntSetloop: - return n.reduceSet() - - default: - return n - } -} - -// Basic optimization. Single-letter alternations can be replaced -// by faster set specifications, and nested alternations with no -// intervening operators can be flattened: -// -// a|b|c|def|g|h -> [a-c]|def|[gh] -// apple|(?:orange|pear)|grape -> apple|orange|pear|grape -func (n *regexNode) reduceAlternation() *regexNode { - if len(n.children) == 0 { - return newRegexNode(ntNothing, n.options) - } - - wasLastSet := false - lastNodeCannotMerge := false - var optionsLast RegexOptions - var i, j int - - for i, j = 0, 0; i < len(n.children); i, j = i+1, j+1 { - at := n.children[i] - - if j < i { - n.children[j] = at - } - - for { - if at.t == ntAlternate { - for k := 0; k < len(at.children); k++ { - at.children[k].next = n - } - n.insertChildren(i+1, at.children) - - j-- - } else if at.t == ntSet || at.t == ntOne { - // Cannot merge sets if L or I options differ, or if either are negated. - optionsAt := at.options & (RightToLeft | IgnoreCase) - - if at.t == ntSet { - if !wasLastSet || optionsLast != optionsAt || lastNodeCannotMerge || !at.set.IsMergeable() { - wasLastSet = true - lastNodeCannotMerge = !at.set.IsMergeable() - optionsLast = optionsAt - break - } - } else if !wasLastSet || optionsLast != optionsAt || lastNodeCannotMerge { - wasLastSet = true - lastNodeCannotMerge = false - optionsLast = optionsAt - break - } - - // The last node was a Set or a One, we're a Set or One and our options are the same. - // Merge the two nodes. - j-- - prev := n.children[j] - - var prevCharClass *CharSet - if prev.t == ntOne { - prevCharClass = &CharSet{} - prevCharClass.addChar(prev.ch) - } else { - prevCharClass = prev.set - } - - if at.t == ntOne { - prevCharClass.addChar(at.ch) - } else { - prevCharClass.addSet(*at.set) - } - - prev.t = ntSet - prev.set = prevCharClass - } else if at.t == ntNothing { - j-- - } else { - wasLastSet = false - lastNodeCannotMerge = false - } - break - } - } - - if j < i { - n.removeChildren(j, i) - } - - return n.stripEnation(ntNothing) -} - -// Basic optimization. Adjacent strings can be concatenated. -// -// (?:abc)(?:def) -> abcdef -func (n *regexNode) reduceConcatenation() *regexNode { - // Eliminate empties and concat adjacent strings/chars - - var optionsLast RegexOptions - var optionsAt RegexOptions - var i, j int - - if len(n.children) == 0 { - return newRegexNode(ntEmpty, n.options) - } - - wasLastString := false - - for i, j = 0, 0; i < len(n.children); i, j = i+1, j+1 { - var at, prev *regexNode - - at = n.children[i] - - if j < i { - n.children[j] = at - } - - if at.t == ntConcatenate && - ((at.options & RightToLeft) == (n.options & RightToLeft)) { - for k := 0; k < len(at.children); k++ { - at.children[k].next = n - } - - //insert at.children at i+1 index in n.children - n.insertChildren(i+1, at.children) - - j-- - } else if at.t == ntMulti || at.t == ntOne { - // Cannot merge strings if L or I options differ - optionsAt = at.options & (RightToLeft | IgnoreCase) - - if !wasLastString || optionsLast != optionsAt { - wasLastString = true - optionsLast = optionsAt - continue - } - - j-- - prev = n.children[j] - - if prev.t == ntOne { - prev.t = ntMulti - prev.str = []rune{prev.ch} - } - - if (optionsAt & RightToLeft) == 0 { - if at.t == ntOne { - prev.str = append(prev.str, at.ch) - } else { - prev.str = append(prev.str, at.str...) - } - } else { - if at.t == ntOne { - // insert at the front by expanding our slice, copying the data over, and then setting the value - prev.str = append(prev.str, 0) - copy(prev.str[1:], prev.str) - prev.str[0] = at.ch - } else { - //insert at the front...this one we'll make a new slice and copy both into it - merge := make([]rune, len(prev.str)+len(at.str)) - copy(merge, at.str) - copy(merge[len(at.str):], prev.str) - prev.str = merge - } - } - } else if at.t == ntEmpty { - j-- - } else { - wasLastString = false - } - } - - if j < i { - // remove indices j through i from the children - n.removeChildren(j, i) - } - - return n.stripEnation(ntEmpty) -} - -// Nested repeaters just get multiplied with each other if they're not -// too lumpy -func (n *regexNode) reduceRep() *regexNode { - - u := n - t := n.t - min := n.m - max := n.n - - for { - if len(u.children) == 0 { - break - } - - child := u.children[0] - - // multiply reps of the same type only - if child.t != t { - childType := child.t - - if !(childType >= ntOneloop && childType <= ntSetloop && t == ntLoop || - childType >= ntOnelazy && childType <= ntSetlazy && t == ntLazyloop) { - break - } - } - - // child can be too lumpy to blur, e.g., (a {100,105}) {3} or (a {2,})? - // [but things like (a {2,})+ are not too lumpy...] - if u.m == 0 && child.m > 1 || child.n < child.m*2 { - break - } - - u = child - if u.m > 0 { - if (math.MaxInt32-1)/u.m < min { - u.m = math.MaxInt32 - } else { - u.m = u.m * min - } - } - if u.n > 0 { - if (math.MaxInt32-1)/u.n < max { - u.n = math.MaxInt32 - } else { - u.n = u.n * max - } - } - } - - if math.MaxInt32 == min { - return newRegexNode(ntNothing, n.options) - } - return u - -} - -// Simple optimization. If a concatenation or alternation has only -// one child strip out the intermediate node. If it has zero children, -// turn it into an empty. -func (n *regexNode) stripEnation(emptyType nodeType) *regexNode { - switch len(n.children) { - case 0: - return newRegexNode(emptyType, n.options) - case 1: - return n.children[0] - default: - return n - } -} - -func (n *regexNode) reduceGroup() *regexNode { - u := n - - for u.t == ntGroup { - u = u.children[0] - } - - return u -} - -// Simple optimization. If a set is a singleton, an inverse singleton, -// or empty, it's transformed accordingly. -func (n *regexNode) reduceSet() *regexNode { - // Extract empty-set, one and not-one case as special - - if n.set == nil { - n.t = ntNothing - } else if n.set.IsSingleton() { - n.ch = n.set.SingletonChar() - n.set = nil - n.t += (ntOne - ntSet) - } else if n.set.IsSingletonInverse() { - n.ch = n.set.SingletonChar() - n.set = nil - n.t += (ntNotone - ntSet) - } - - return n -} - -func (n *regexNode) reverseLeft() *regexNode { - if n.options&RightToLeft != 0 && n.t == ntConcatenate && len(n.children) > 0 { - //reverse children order - for left, right := 0, len(n.children)-1; left < right; left, right = left+1, right-1 { - n.children[left], n.children[right] = n.children[right], n.children[left] - } - } - - return n -} - -func (n *regexNode) makeQuantifier(lazy bool, min, max int) *regexNode { - if min == 0 && max == 0 { - return newRegexNode(ntEmpty, n.options) - } - - if min == 1 && max == 1 { - return n - } - - switch n.t { - case ntOne, ntNotone, ntSet: - if lazy { - n.makeRep(Onelazy, min, max) - } else { - n.makeRep(Oneloop, min, max) - } - return n - - default: - var t nodeType - if lazy { - t = ntLazyloop - } else { - t = ntLoop - } - result := newRegexNodeMN(t, n.options, min, max) - result.addChild(n) - return result - } -} - -// debug functions - -var typeStr = []string{ - "Onerep", "Notonerep", "Setrep", - "Oneloop", "Notoneloop", "Setloop", - "Onelazy", "Notonelazy", "Setlazy", - "One", "Notone", "Set", - "Multi", "Ref", - "Bol", "Eol", "Boundary", "Nonboundary", - "Beginning", "Start", "EndZ", "End", - "Nothing", "Empty", - "Alternate", "Concatenate", - "Loop", "Lazyloop", - "Capture", "Group", "Require", "Prevent", "Greedy", - "Testref", "Testgroup", - "Unknown", "Unknown", "Unknown", - "Unknown", "Unknown", "Unknown", - "ECMABoundary", "NonECMABoundary", -} - -func (n *regexNode) description() string { - buf := &bytes.Buffer{} - - buf.WriteString(typeStr[n.t]) - - if (n.options & ExplicitCapture) != 0 { - buf.WriteString("-C") - } - if (n.options & IgnoreCase) != 0 { - buf.WriteString("-I") - } - if (n.options & RightToLeft) != 0 { - buf.WriteString("-L") - } - if (n.options & Multiline) != 0 { - buf.WriteString("-M") - } - if (n.options & Singleline) != 0 { - buf.WriteString("-S") - } - if (n.options & IgnorePatternWhitespace) != 0 { - buf.WriteString("-X") - } - if (n.options & ECMAScript) != 0 { - buf.WriteString("-E") - } - - switch n.t { - case ntOneloop, ntNotoneloop, ntOnelazy, ntNotonelazy, ntOne, ntNotone: - buf.WriteString("(Ch = " + CharDescription(n.ch) + ")") - break - case ntCapture: - buf.WriteString("(index = " + strconv.Itoa(n.m) + ", unindex = " + strconv.Itoa(n.n) + ")") - break - case ntRef, ntTestref: - buf.WriteString("(index = " + strconv.Itoa(n.m) + ")") - break - case ntMulti: - fmt.Fprintf(buf, "(String = %s)", string(n.str)) - break - case ntSet, ntSetloop, ntSetlazy: - buf.WriteString("(Set = " + n.set.String() + ")") - break - } - - switch n.t { - case ntOneloop, ntNotoneloop, ntOnelazy, ntNotonelazy, ntSetloop, ntSetlazy, ntLoop, ntLazyloop: - buf.WriteString("(Min = ") - buf.WriteString(strconv.Itoa(n.m)) - buf.WriteString(", Max = ") - if n.n == math.MaxInt32 { - buf.WriteString("inf") - } else { - buf.WriteString(strconv.Itoa(n.n)) - } - buf.WriteString(")") - - break - } - - return buf.String() -} - -var padSpace = []byte(" ") - -func (t *RegexTree) Dump() string { - return t.root.dump() -} - -func (n *regexNode) dump() string { - var stack []int - CurNode := n - CurChild := 0 - - buf := bytes.NewBufferString(CurNode.description()) - buf.WriteRune('\n') - - for { - if CurNode.children != nil && CurChild < len(CurNode.children) { - stack = append(stack, CurChild+1) - CurNode = CurNode.children[CurChild] - CurChild = 0 - - Depth := len(stack) - if Depth > 32 { - Depth = 32 - } - buf.Write(padSpace[:Depth]) - buf.WriteString(CurNode.description()) - buf.WriteRune('\n') - } else { - if len(stack) == 0 { - break - } - - CurChild = stack[len(stack)-1] - stack = stack[:len(stack)-1] - CurNode = CurNode.next - } - } - return buf.String() -} diff --git a/vendor/github.com/dlclark/regexp2/ATTRIB b/vendor/github.com/dlclark/regexp2/v2/ATTRIB similarity index 100% rename from vendor/github.com/dlclark/regexp2/ATTRIB rename to vendor/github.com/dlclark/regexp2/v2/ATTRIB diff --git a/vendor/github.com/dlclark/regexp2/LICENSE b/vendor/github.com/dlclark/regexp2/v2/LICENSE similarity index 100% rename from vendor/github.com/dlclark/regexp2/LICENSE rename to vendor/github.com/dlclark/regexp2/v2/LICENSE diff --git a/vendor/github.com/dlclark/regexp2/v2/bufferpool.go b/vendor/github.com/dlclark/regexp2/v2/bufferpool.go new file mode 100644 index 000000000..0580d6a17 --- /dev/null +++ b/vendor/github.com/dlclark/regexp2/v2/bufferpool.go @@ -0,0 +1,76 @@ +package regexp2 + +import ( + "bytes" + "slices" + "sync" +) + +type pooledSliceBuffers[T any] struct { + sizes []int + pools []sync.Pool +} + +func newPooledSliceBuffers[T any](sizes ...int) *pooledSliceBuffers[T] { + sizes = slices.Clone(sizes) + slices.Sort(sizes) + return &pooledSliceBuffers[T]{ + sizes: sizes, + pools: make([]sync.Pool, len(sizes)), + } +} + +func (p *pooledSliceBuffers[T]) poolIndex(neededSize, maxSize int) int { + if maxSize == 0 { + return -1 + } + for i, classSize := range p.sizes { + if neededSize <= classSize { + if maxSize > 0 && classSize > maxSize { + return -1 + } + return i + } + } + return -1 +} + +func (p *pooledSliceBuffers[T]) get(neededSize, maxSize int) ([]T, *[]T) { + idx := p.poolIndex(neededSize, maxSize) + if idx < 0 { + return make([]T, neededSize), nil + } + if v := p.pools[idx].Get(); v != nil { + bufp := v.(*[]T) + if cap(*bufp) >= neededSize { + return (*bufp)[:neededSize], bufp + } + } + buf := make([]T, neededSize, p.sizes[idx]) + return buf, &buf +} + +func (p *pooledSliceBuffers[T]) put(bufp *[]T) { + idx := p.poolIndex(cap(*bufp), -1) + if idx < 0 || cap(*bufp) != p.sizes[idx] { + return + } + *bufp = (*bufp)[:0] + p.pools[idx].Put(bufp) +} + +// our specific pooled buffers +var ( + pooledRuneBuffers = newPooledSliceBuffers[rune](1<<10, 4<<10, 16<<10, 64<<10, 256<<10) + pooledByteBuffers = newPooledSliceBuffers[byte](4<<10, 16<<10, 64<<10, 256<<10, 1<<20) +) + +func getPooledReplaceBuffer(neededBytes, maxSize int) (*bytes.Buffer, *[]byte) { + buf, pooled := pooledByteBuffers.get(neededBytes, maxSize) + return bytes.NewBuffer(buf[:0]), pooled +} + +func putPooledReplaceBuffer(buf *bytes.Buffer, pooled *[]byte) { + *pooled = buf.Bytes() + pooledByteBuffers.put(pooled) +} diff --git a/vendor/github.com/dlclark/regexp2/fastclock.go b/vendor/github.com/dlclark/regexp2/v2/fastclock.go similarity index 100% rename from vendor/github.com/dlclark/regexp2/fastclock.go rename to vendor/github.com/dlclark/regexp2/v2/fastclock.go diff --git a/vendor/github.com/dlclark/regexp2/v2/helpers/indexof.go b/vendor/github.com/dlclark/regexp2/v2/helpers/indexof.go new file mode 100644 index 000000000..8d24a8c08 --- /dev/null +++ b/vendor/github.com/dlclark/regexp2/v2/helpers/indexof.go @@ -0,0 +1,394 @@ +package helpers + +import ( + "bytes" + "slices" + "strings" + "unicode" + "unsafe" + + "github.com/dlclark/regexp2/v2/syntax" +) + +func IndexOfAny(in []rune, find []rune) int { + // special case + if len(find) == 0 { + return -1 + } + // naive version + for i, c := range in { + if slices.Contains(find, c) { + return i + } + } + return -1 +} + +func IndexOfAny1(in []rune, find rune) int { + //TODO: bytes optimization? + return slices.Index(in, find) +} + +func IndexOfAny2(in []rune, find1, find2 rune) int { + for i, c := range in { + if c == find1 || c == find2 { + return i + } + } + + return -1 +} + +func IndexOfAny3(in []rune, find1, find2, find3 rune) int { + for i, c := range in { + if c == find1 || c == find2 || c == find3 { + return i + } + } + + return -1 +} + +func IndexOfAnyInRange(in []rune, first, last rune) int { + for i, c := range in { + if c >= first && c <= last { + return i + } + } + return -1 +} + +func IndexOfAnyExcept(in []rune, bad []rune) int { + for i, c := range in { + found := false + for _, b := range bad { + if b == c { + found = true + break + } + } + if !found { + return i + } + } + return -1 +} + +func IndexOfAnyExcept1(in []rune, bad rune) int { + for i, c := range in { + if c != bad { + return i + } + } + return -1 +} + +func IndexOfAnyExcept2(in []rune, bad1, bad2 rune) int { + for i, c := range in { + if c != bad1 && c != bad2 { + return i + } + } + + return -1 +} + +func IndexOfAnyExcept3(in []rune, bad1, bad2, bad3 rune) int { + for i, c := range in { + if c != bad1 && c != bad2 && c != bad3 { + return i + } + } + + return -1 +} + +func IndexOfAnyExceptInRange(in []rune, first, last rune) int { + for i, c := range in { + if c > last { + return i + } + if c < first { + return i + } + } + return -1 +} + +func IndexFunc(in []rune, f func(ch rune) bool) int { + for i := range in { + if f(in[i]) { + return i + } + } + return -1 +} + +func IndexOfAnyExceptInSet(in []rune, set syntax.CharSet) int { + //TODO: this + panic("not implemented") +} + +func LastIndexOf(in []rune, find []rune) int { + end := len(in) - len(find) + first := find[0] + lastOffset := len(find) - 1 + last := find[lastOffset] + for i := end; i >= 0; i-- { + //TODO: check 2 chars needed? + // match start and end...check the middle + if in[i] == first && in[i+lastOffset] == last { + // found our first char + // check if the rest are equal + if bytesEqual(in[i:i+len(find)], find) { + return i + } + } + } + + //not found + return -1 +} + +func LastIndexOfAnyExcept1(in []rune, not rune) int { + for i := len(in) - 1; i >= 0; i-- { + if in[i] != not { + return i + } + } + return -1 +} + +func LastIndexOfAny1(in []rune, find rune) int { + for i := len(in) - 1; i >= 0; i-- { + if in[i] == find { + // found our char + return i + } + } + + //not found + return -1 +} + +func LastIndexOfAnyInRange(in []rune, first, last rune) int { + for i := len(in) - 1; i >= 0; i-- { + if in[i] >= first && in[i] <= last { + return i + } + } + return -1 +} + +//TODO: LastIndexOf methods +//IndexOfAnyInRange +//LastIndexOfAnyInRange +//LastIndexOfAnyExceptInRange + +// find should always be sent in lower-case +func IndexOfIgnoreCase(in []rune, find []rune) int { + // search the in slice for the "find" slice, ignoring case in the comparisons + end := len(in) - len(find) + first := find[0] + for i := 0; i <= end; i++ { + if in[i] != first && unicode.ToLower(in[i]) != first { + continue + } + match := true + for j := 1; j < len(find); j++ { + inChar := in[i+j] + if inChar != find[j] && unicode.ToLower(inChar) != find[j] { + match = false + break + } + } + if match { + return i + } + } + return -1 +} + +func IndexOfIgnoreCaseAscii(in []rune, find []rune) int { + // search the in slice for the "find" slice, ignoring case in the comparisons + // we can assume the find chars are ascii and do simple masks on them + if len(find) == 0 { + return 0 + } + end := len(in) - len(find) + first := foldASCII(rune(find[0])) + for i := 0; i <= end; i++ { + if foldASCII(in[i]) != first { + continue + } + match := true + for j := 1; j < len(find); j++ { + if foldASCII(in[i+j]) != foldASCII(find[j]) { + match = false + break + } + } + if match { + return i + } + } + return -1 +} + +func IndexStringIgnoreCaseASCII(s, prefix string) int { + if len(prefix) == 0 { + return 0 + } + + for start, end := 0, len(s)-len(prefix); start <= end; { + offset := indexASCIIByteIgnoreCase(s[start:], prefix[0]) + if offset < 0 || start+offset > end { + return -1 + } + + i := start + offset + if EqualStringIgnoreCaseASCII(s[i:i+len(prefix)], prefix) { + return i + } + start = i + 1 + } + return -1 +} + +func EqualStringIgnoreCaseASCII(s, prefix string) bool { + if len(s) < len(prefix) { + return false + } + for i := 0; i < len(prefix); i++ { + if foldASCII(rune(s[i])) != foldASCII(rune(prefix[i])) { + return false + } + } + return true +} + +func indexASCIIByteIgnoreCase(s string, ch byte) int { + ch = byte(foldASCII(rune(ch))) + lower := strings.IndexByte(s, ch) + if ch < 'a' || ch > 'z' { + return lower + } + upper := strings.IndexByte(s, ch-('a'-'A')) + if lower < 0 { + return upper + } + if upper >= 0 && upper < lower { + return upper + } + return lower +} + +func foldASCII(c rune) rune { + if 'A' <= c && c <= 'Z' { + return c + ('a' - 'A') + } + return c +} + +func IndexOf(in []rune, find []rune) int { + /* + Since we auto-gen the find code this shouldn't happen + if len(find) == 0 { + //special case + return -1 + }*/ + end := len(in) - len(find) + first := find[0] + //TODO: benchmark checking last char too or first two chars + for i := 0; i <= end; i++ { + // match start...check the rest + if in[i] == first { + // found our first char + // check if the rest are equal + if bytesEqual(in[i:i+len(find)], find) { + return i + } + /*if slices.Equal(in[i:i+len(find)], find) { + return i + }*/ + } + } + + //not found + return -1 +} + +func StartsWith(in []rune, find []rune) bool { + // if text is less than our "begin" then can't find it + if len(in) < len(find) { + return false + } + + return bytesEqual(in[:len(find)], find) + + /*for i := 0; i < len(find); i++ { + if in[i] != find[i] { + return false + } + } + + return true*/ +} + +//StartsWithIgnoreCaseAscii would be faster + +// find should always be sent in lower-case +func StartsWithIgnoreCase(in []rune, find []rune) bool { + // if text is less than our "begin" then can't find it + if len(in) < len(find) { + return false + } + + for i := 0; i < len(find); i++ { + if in[i] == find[i] { + // if we match the char exactly then we're good + continue + } + // if the to-lower still doesn't match then it's not a match + if unicode.ToLower(in[i]) != find[i] { + return false + } + } + + return true +} + +// internal function, assumes the bounds are already set right on the slices for equality +// casts the rune slices to bytes to use framework fast []byte comparison +func bytesEqual(a, b []rune) bool { + bytesA := unsafe.Slice((*byte)(unsafe.Pointer(&a[0])), len(a)*4) + bytesB := unsafe.Slice((*byte)(unsafe.Pointer(&b[0])), len(b)*4) + return bytes.Equal(bytesA, bytesB) +} + +func Equals(in []rune, start int, length int, find []rune) bool { + if len(find) == 0 { + return true + } + return bytesEqual(in[start:start+length], find) +} + +func EqualsIgnoreCase(in []rune, start int, length int, find []rune) bool { + //fast path if case matches + if Equals(in, start, length, find) { + return true + } + + // search the in slice for the "find" slice, ignoring case in the comparisons + // we can't assume casing or ascii-ness for either letter, have to toLower them both + for j := 0; j < len(find); j++ { + inChar := in[start+j] + findChar := find[j] + if inChar != findChar && unicode.ToLower(inChar) != unicode.ToLower(findChar) { + return false + } + } + + // we've checked all chars and found matches every time + return true +} diff --git a/vendor/github.com/dlclark/regexp2/v2/helpers/math.go b/vendor/github.com/dlclark/regexp2/v2/helpers/math.go new file mode 100644 index 000000000..7f58991e3 --- /dev/null +++ b/vendor/github.com/dlclark/regexp2/v2/helpers/math.go @@ -0,0 +1,15 @@ +package helpers + +func Min(a, b int) int { + if a < b { + return a + } + return b +} + +func Max(a, b int) int { + if a > b { + return a + } + return b +} diff --git a/vendor/github.com/dlclark/regexp2/v2/helpers/runes.go b/vendor/github.com/dlclark/regexp2/v2/helpers/runes.go new file mode 100644 index 000000000..d878da80b --- /dev/null +++ b/vendor/github.com/dlclark/regexp2/v2/helpers/runes.go @@ -0,0 +1,58 @@ +package helpers + +import "unicode" + +func IsBetween(val rune, first, last rune) bool { + if val > last { + return false + } + if val >= first { + return true + } + return false +} + +// According to UTS#18 Unicode Regular Expressions (http://www.unicode.org/reports/tr18/) +// RL 1.4 Simple Word Boundaries The class of includes all Alphabetic +// values from the Unicode character database, from UnicodeData.txt [UData], plus the U+200C +// ZERO WIDTH NON-JOINER and U+200D ZERO WIDTH JOINER. +func IsWordChar(r rune) bool { + // matches charclass.go + + //TODO: add optimization here for ascii + + //"L", "Mn", "Nd", "Pc" + return unicode.In(r, + unicode.Categories["L"], unicode.Categories["Mn"], + unicode.Categories["Nd"], unicode.Categories["Pc"]) || r == '\u200D' || r == '\u200C' + //return 'A' <= r && r <= 'Z' || 'a' <= r && r <= 'z' || '0' <= r && r <= '9' || r == '_' +} + +func IsInMask32(ch rune, mask uint32) bool { + //BDFHJLNPRTVX = 10101010 10101010 10101010 00000000 + //B = 00000000 00000000 00000000 01000010 + //char=B-B = 00000000 00000000 00000000 00000000 + //BDFH.. << 0 = 10101010 10101010 10101010 00000000 + //char-32 = 11111111 11111111 11111111 11100000 + //& = 10101010 10101010 10101010 00000000 + // first bit is 1 then negative, so it matches + + //charMinusLowUInt32 := int32(ch - low) + return int32((mask< unicode.MaxASCII { + // a bug got us here. that's bad. + panic(fmt.Errorf("non-ascii value found in ascii search values: %s", vals)) + } + idx := c / 64 + shift := c % 64 + sv.set[idx] |= 1 << shift + } + + return sv +} + +// return the first index of our original vals values within the slice given +func (s AsciiSearchValues) IndexOfAny(chars []rune) int { + for i := 0; i < len(chars); i++ { + c := chars[i] + if c > unicode.MaxASCII { + continue + } + idx := c / 64 + shift := c % 64 + if s.set[idx]&(1< unicode.MaxASCII { + return i + } + idx := c / 64 + shift := c % 64 + if s.set[idx]&(1< len(val) { + min = len(val) + } + if !slices.Contains(firstLetters, val[0]) { + firstLetters = append(firstLetters, val[0]) + if ignoreCase && val[0] != unicode.ToUpper(val[0]) { + //if we're ignoring case and this letter is impacted by case, add it to our set + firstLetters = append(firstLetters, unicode.ToUpper(val[0])) + } + } + } + + return StringSearchValues{ + vals: vals, + ignoreCase: ignoreCase, + shortestVal: min, + firstChars: newRuneSearchValues(firstLetters), + } +} + +func (s StringSearchValues) StartsWith(chars []rune) int { + panic("not implemented") +} + +func (s StringSearchValues) StartsWithIgnoreCase(chars []rune) int { + panic("not implemented") +} + +func (s StringSearchValues) IndexOfAny(in []rune) int { + // go through our input once + end := len(in) - s.shortestVal + for i := 0; i <= end; i++ { + // check if the char are in our starting chars + j := s.firstChars.IndexOfAny(in[i:]) + // first chars not found at all + if j < 0 { + return -1 + } + j += i + // found a first char, do our full search through each item + for _, val := range s.vals { + if len(in)-j >= len(val) && Equals(in, j, len(val), val) { + return j + } + if s.ignoreCase && len(in)-j >= len(val) && EqualsIgnoreCase(in, j, len(val), val) { + return j + } + } + //skip ahead + i = j + } + + return -1 +} diff --git a/vendor/github.com/dlclark/regexp2/match.go b/vendor/github.com/dlclark/regexp2/v2/match.go similarity index 67% rename from vendor/github.com/dlclark/regexp2/match.go rename to vendor/github.com/dlclark/regexp2/v2/match.go index 759cf8ccf..4003ff0f5 100644 --- a/vendor/github.com/dlclark/regexp2/match.go +++ b/vendor/github.com/dlclark/regexp2/v2/match.go @@ -3,6 +3,7 @@ package regexp2 import ( "bytes" "fmt" + "unicode/utf8" ) // Match is a single regex result match that contains groups and repeated captures @@ -20,7 +21,6 @@ type Match struct { textstart int capcount int - caps []int sparseCaps map[int]int // output from the match @@ -43,25 +43,124 @@ type Group struct { // Capture is a single capture of text within the larger original string type Capture struct { // the original string - text []rune - // Index is the position in the underlying rune slice where the first character of + text *matchText + // RuneIndex is the position in the underlying rune slice where the first character of // captured substring was found. Even if you pass in a string this will be in Runes. - Index int - // Length is the number of runes in the captured substring. - Length int + RuneIndex int + // RuneLength is the number of runes in the captured substring. + RuneLength int +} + +type matchText struct { + runes []rune + input string + hasStringInput bool + byteOffsets []int + byteOffsetsReady bool } // String returns the captured text as a String func (c *Capture) String() string { - return string(c.text[c.Index : c.Index+c.Length]) + return string(c.text.runes[c.RuneIndex : c.RuneIndex+c.RuneLength]) } // Runes returns the captured text as a rune slice func (c *Capture) Runes() []rune { - return c.text[c.Index : c.Index+c.Length] + return c.text.runes[c.RuneIndex : c.RuneIndex+c.RuneLength] +} + +// ByteRange returns the UTF-8 byte index and byte length of the captured +// substring. The first call lazily caches byte offsets on shared match text, +// so it is not safe to call concurrently with ByteRange on another capture +// from the same match until the cache has been initialized. +func (c *Capture) ByteRange() (index, length int) { + if c.text == nil { + return c.RuneIndex, c.RuneLength + } + return c.text.byteRange(c.RuneIndex, c.RuneLength) +} + +func newMatchText(r []rune) *matchText { + return &matchText{runes: r} +} + +func newStringMatchText(input string, r []rune) *matchText { + return &matchText{runes: r, input: input, hasStringInput: true} +} + +func (t *matchText) byteRange(runeIndex, runeLength int) (int, int) { + if !t.byteOffsetsReady { + t.byteOffsets = t.buildByteOffsets() + t.byteOffsetsReady = true + } + if t.byteOffsets == nil { + return runeIndex, runeLength + } + byteIndex := t.byteOffsets[runeIndex] + return byteIndex, t.byteOffsets[runeIndex+runeLength] - byteIndex +} + +func (t *matchText) buildByteOffsets() []int { + if t.hasStringInput { + return stringByteOffsets(t.input) + } + return runeByteOffsets(t.runes) +} + +func stringByteOffsets(s string) []int { + var byteOffsets []int + runeIndex := 0 + for strIdx, ch := range s { + if byteOffsets != nil { + byteOffsets[runeIndex] = strIdx + } + runeLen := utf8.RuneLen(ch) + if ch == utf8.RuneError { + _, runeLen = utf8.DecodeRuneInString(s[strIdx:]) + } + if byteOffsets == nil && (strIdx != runeIndex || runeLen != 1) { + byteOffsets = make([]int, len(s)+1) + for i := 0; i < runeIndex; i++ { + byteOffsets[i] = i + } + byteOffsets[runeIndex] = strIdx + } + runeIndex++ + } + if byteOffsets != nil { + byteOffsets[runeIndex] = len(s) + return byteOffsets[:runeIndex+1] + } + return nil } -func newMatch(regex *Regexp, capcount int, text []rune, startpos int) *Match { +func runeByteOffsets(runes []rune) []int { + var byteOffsets []int + bytePos := 0 + for i, ch := range runes { + if byteOffsets != nil { + byteOffsets[i] = bytePos + } + runeLen := utf8.RuneLen(ch) + if runeLen < 0 { + runeLen = utf8.RuneLen(utf8.RuneError) + } + if byteOffsets == nil && runeLen != 1 { + byteOffsets = make([]int, len(runes)+1) + for j := 0; j < i; j++ { + byteOffsets[j] = j + } + byteOffsets[i] = bytePos + } + bytePos += runeLen + } + if byteOffsets != nil { + byteOffsets[len(runes)] = bytePos + } + return byteOffsets +} + +func newMatch(regex *Regexp, capcount int, text *matchText, startpos int) *Match { m := Match{ regex: regex, matchcount: make([]int, capcount), @@ -69,19 +168,21 @@ func newMatch(regex *Regexp, capcount int, text []rune, startpos int) *Match { textstart: startpos, balancing: false, } - m.Name = "0" + if (regex.options & ECMAScript) == 0 { + m.Name = "0" + } m.text = text m.matches[0] = make([]int, 2) return &m } -func newMatchSparse(regex *Regexp, caps map[int]int, capcount int, text []rune, startpos int) *Match { +func newMatchSparse(regex *Regexp, caps map[int]int, capcount int, text *matchText, startpos int) *Match { m := newMatch(regex, capcount, text, startpos) m.sparseCaps = caps return m } -func (m *Match) reset(text []rune, textstart int) { +func (m *Match) reset(text *matchText, textstart int) { m.text = text m.textstart = textstart for i := 0; i < len(m.matchcount); i++ { @@ -93,12 +194,11 @@ func (m *Match) reset(text []rune, textstart int) { func (m *Match) tidy(textpos int) { interval := m.matches[0] - m.Index = interval[0] - m.Length = interval[1] + setCaptureFields(&m.Capture, interval[0], interval[1]) m.textpos = textpos m.capcount = m.matchcount[0] //copy our root capture to the list - m.Group.Captures = []Capture{m.Group.Capture} + m.Captures = []Capture{m.Capture} if m.balancing { // The idea here is that we want to compact all of our unbalanced captures. To do that we @@ -288,31 +388,37 @@ func (m *Match) groupValueAppendToBuf(groupnum int, buf *bytes.Buffer) { last := index + matches[(c*2)-1] for ; index < last; index++ { - buf.WriteRune(m.text[index]) + buf.WriteRune(m.text.runes[index]) } } -func newGroup(name string, text []rune, caps []int, capcount int) Group { +func newGroup(name string, text *matchText, caps []int, capcount int) Group { g := Group{} g.text = text if capcount > 0 { - g.Index = caps[(capcount-1)*2] - g.Length = caps[(capcount*2)-1] + setCaptureFields(&g.Capture, caps[(capcount-1)*2], caps[(capcount*2)-1]) } g.Name = name g.Captures = make([]Capture, capcount) for i := 0; i < capcount; i++ { - g.Captures[i] = Capture{ - text: text, - Index: caps[i*2], - Length: caps[i*2+1], - } + g.Captures[i] = newCapture(text, caps[i*2], caps[i*2+1]) } //log.Printf("newGroup! capcount %v, %+v", capcount, g) return g } +func newCapture(text *matchText, runeIndex, runeLength int) Capture { + c := Capture{text: text} + setCaptureFields(&c, runeIndex, runeLength) + return c +} + +func setCaptureFields(c *Capture, runeIndex, runeLength int) { + c.RuneIndex = runeIndex + c.RuneLength = runeLength +} + func (m *Match) dump() string { buf := &bytes.Buffer{} buf.WriteRune('\n') @@ -326,7 +432,7 @@ func (m *Match) dump() string { fmt.Fprintf(buf, "Group %v (%v), %v caps:\n", i, g.Name, len(g.Captures)) for _, c := range g.Captures { - fmt.Fprintf(buf, " (%v, %v) %v\n", c.Index, c.Length, c.String()) + fmt.Fprintf(buf, " (%v, %v) %v\n", c.RuneIndex, c.RuneLength, c.String()) } } /* @@ -338,7 +444,7 @@ func (m *Match) dump() string { if m.matches[i][j*2] >= 0 { start := m.matches[i][j*2] - text = m.text[start : start+m.matches[i][j*2+1]] + text = m.text.runes[start : start+m.matches[i][j*2+1]] } fmt.Fprintf(buf, " (%v, %v) %v\n", m.matches[i][j*2], m.matches[i][j*2+1], text) diff --git a/vendor/github.com/dlclark/regexp2/v2/options.go b/vendor/github.com/dlclark/regexp2/v2/options.go new file mode 100644 index 000000000..c0e49fff5 --- /dev/null +++ b/vendor/github.com/dlclark/regexp2/v2/options.go @@ -0,0 +1,157 @@ +package regexp2 + +var ( + // DefaultUnmarshalOptions used when unmarshaling a regex from text + DefaultUnmarshalOptions = None + // DefaultOptimizationOptions controls the default memory/performance trade-offs used by Compile. + DefaultOptimizationOptions = OptimizationOptions{ + MaxCachedRuneBufferLength: 256 << 10, + MaxCachedReplaceBufferLength: 256 << 10, + MaxCachedReplacerDataEntries: 16, + MaxCachedReplacerDataBytes: 4 << 10, + DisableCharClassASCIIBitmap: false, + } +) + +// RegexOptions impact the runtime and parsing behavior +// for each specific regex. They are setable in code as well +// as in the regex pattern itself. +type RegexOptions int32 + +func (o RegexOptions) applyCompileOption(c *compileConfig) { + c.regexOptions |= o +} + +const ( + None RegexOptions = 0x0 + IgnoreCase RegexOptions = 0x0001 // "i" + Multiline RegexOptions = 0x0002 // "m" + ExplicitCapture RegexOptions = 0x0004 // "n" + Singleline RegexOptions = 0x0010 // "s" + IgnorePatternWhitespace RegexOptions = 0x0020 // "x" + RightToLeft RegexOptions = 0x0040 // "r" + // ECMAScript attempts to follow ECMAScript regex behavior rather than C# RegexOptions.ECMAScript compatibility. + ECMAScript RegexOptions = 0x0100 // "e" + RE2 RegexOptions = 0x0200 // RE2 (regexp package) compatibility mode + Unicode RegexOptions = 0x0400 // "u" +) + +// OptimizationOptions controls optional runtime caches and compile-time fast paths. +// +// For replacement data cache size fields, 0 disables persistent retention and +// -1 means unbounded. For pooled buffer cache size fields, 0 disables pooling +// and -1 allows all built-in size classes. +// Defaults are intentionally bounded so Compile is safe for mixed-cardinality inputs. +type OptimizationOptions struct { + // MaxCachedRuneBufferLength limits retained string-to-rune buffers in the shared size-classed pool. + MaxCachedRuneBufferLength int + // MaxCachedReplaceBufferLength limits retained replacement output buffers in the shared size-classed pool. + MaxCachedReplaceBufferLength int + // MaxCachedReplacerDataEntries limits the number of parsed replacement patterns cached per Regexp. + MaxCachedReplacerDataEntries int + // MaxCachedReplacerDataBytes skips caching replacement patterns longer than this many bytes. + MaxCachedReplacerDataBytes int + // DisableCharClassASCIIBitmap disables compile-time ASCII bitmap construction for character classes. + DisableCharClassASCIIBitmap bool +} + +// CompileOption configures Compile and MustCompile. +type CompileOption interface { + applyCompileOption(*compileConfig) +} + +type compileConfig struct { + regexOptions RegexOptions + optimizations OptimizationOptions + codeGen bool + debug bool + maintainCaptureOrder bool +} + +type compileOptionFunc func(*compileConfig) + +func (f compileOptionFunc) applyCompileOption(c *compileConfig) { + f(c) +} + +func (o OptimizationOptions) cacheReplacerData(replacement string) bool { + if o.MaxCachedReplacerDataEntries == 0 { + return false + } + return keepCacheBytes(o.MaxCachedReplacerDataBytes, len(replacement)) +} + +func keepCacheBytes(maxBytes, actualBytes int) bool { + if maxBytes < 0 { + return true + } + return maxBytes > 0 && actualBytes <= maxBytes +} + +func newCompileConfig(options []CompileOption) compileConfig { + c := compileConfig{ + optimizations: DefaultOptimizationOptions, + } + for _, option := range options { + if option != nil { + option.applyCompileOption(&c) + } + } + return c +} + +// OptionMaxCachedRuneBufferLength limits retained string-to-rune buffers in the shared size-classed pool. +func OptionMaxCachedRuneBufferLength(n int) CompileOption { + return compileOptionFunc(func(c *compileConfig) { + c.optimizations.MaxCachedRuneBufferLength = n + }) +} + +// OptionMaxCachedReplaceBufferLength limits retained replacement output buffers in the shared size-classed pool. +func OptionMaxCachedReplaceBufferLength(n int) CompileOption { + return compileOptionFunc(func(c *compileConfig) { + c.optimizations.MaxCachedReplaceBufferLength = n + }) +} + +// OptionMaxCachedReplacerDataEntries limits parsed replacement patterns cached per Regexp. +func OptionMaxCachedReplacerDataEntries(n int) CompileOption { + return compileOptionFunc(func(c *compileConfig) { + c.optimizations.MaxCachedReplacerDataEntries = n + }) +} + +// OptionMaxCachedReplacerDataBytes skips caching replacement patterns longer than n bytes. +func OptionMaxCachedReplacerDataBytes(n int) CompileOption { + return compileOptionFunc(func(c *compileConfig) { + c.optimizations.MaxCachedReplacerDataBytes = n + }) +} + +// OptionDisableCharClassASCIIBitmap disables compile-time ASCII bitmaps for character classes. +func OptionDisableCharClassASCIIBitmap() CompileOption { + return compileOptionFunc(func(c *compileConfig) { + c.optimizations.DisableCharClassASCIIBitmap = true + }) +} + +// OptionIsCodeGen enables more expensive compile-time analysis intended for regexp2cg generated engines. +func OptionIsCodeGen() CompileOption { + return compileOptionFunc(func(c *compileConfig) { + c.codeGen = true + }) +} + +// OptionDebug enables debug output and runner tracing for the compiled regexp. +func OptionDebug() CompileOption { + return compileOptionFunc(func(c *compileConfig) { + c.debug = true + }) +} + +// OptionMaintainCaptureOrder assigns named and unnamed capture slots in pattern order. +func OptionMaintainCaptureOrder() CompileOption { + return compileOptionFunc(func(c *compileConfig) { + c.maintainCaptureOrder = true + }) +} diff --git a/vendor/github.com/dlclark/regexp2/v2/regexp.go b/vendor/github.com/dlclark/regexp2/v2/regexp.go new file mode 100644 index 000000000..0a5d140a3 --- /dev/null +++ b/vendor/github.com/dlclark/regexp2/v2/regexp.go @@ -0,0 +1,717 @@ +/* +Package regexp2 is a regexp package that has an interface similar to Go's framework regexp engine but uses a +more feature full regex engine behind the scenes. + +It doesn't have constant time guarantees, but it allows backtracking and is compatible with Perl5 and .NET. +You'll likely be better off with the RE2 engine from the regexp package and should only use this if you +need to write very complex patterns or require compatibility with .NET. +*/ +package regexp2 + +import ( + "container/list" + "errors" + "log" + "math" + "sort" + "strconv" + "sync" + "time" + "unicode/utf8" + + "github.com/dlclark/regexp2/v2/syntax" +) + +var ( + // DefaultMatchTimeout used when running regexp matches -- "forever" + DefaultMatchTimeout = time.Duration(math.MaxInt64) +) + +// Regexp is the representation of a compiled regular expression. +// A Regexp is safe for concurrent use by multiple goroutines. +type Regexp struct { + // A match will time out if it takes (approximately) more than + // MatchTimeout. This is a safety check in case the match + // encounters catastrophic backtracking. The default value + // (DefaultMatchTimeout) causes all time out checking to be + // suppressed. + MatchTimeout time.Duration + + // read-only after Compile + pattern string // as passed to Compile + options RegexOptions // options + debug bool + + caps map[int]int // capnum->index + capnames map[string]int //capture group name -> index + capslist []string //sorted list of capture group names + capsize int // size of the capture array + + code *syntax.Code // compiled program + + optimizations OptimizationOptions + + // cache of machines for running regexp + runnerPool *sync.Pool + + replaceCache *replacerDataCache + + // hook points to override runner functions + findFirstChar func(r *Runner) bool + execute func(r *Runner) error + stringPrefixFilter StringPrefixFilter +} + +// Compile parses a regular expression and returns, if successful, +// a Regexp object that can be used to match against text. +func Compile(expr string, options ...CompileOption) (*Regexp, error) { + c := newCompileConfig(options) + return compile(expr, c) +} + +func compile(expr string, c compileConfig) (*Regexp, error) { + // parse it + parseOptions := syntax.ParseOptions{ + RegexOptions: syntax.RegexOptions(c.regexOptions), + MaintainCaptureOrder: c.maintainCaptureOrder, + CodeGen: c.codeGen, + } + tree, err := syntax.Parse(expr, parseOptions) + if err != nil { + return nil, err + } + + if c.debug { + log.Print(tree.Dump()) + } + + // translate it to code + code, err := syntax.Write(tree) + if err != nil { + return nil, err + } + if c.debug { + log.Print(code.Dump()) + } + if !c.optimizations.DisableCharClassASCIIBitmap { + code.PrepareCharSetASCIIBitmaps() + } + + // return it + re := &Regexp{ + pattern: expr, + options: c.regexOptions, + debug: c.debug, + caps: code.Caps, + capnames: tree.Capnames, + capslist: tree.Caplist, + capsize: code.Capsize, + code: code, + MatchTimeout: DefaultMatchTimeout, + optimizations: c.optimizations, + } + re.stringPrefixFilter = newStringPrefixFilter(code) + re.initCaches() + return re, nil +} + +// MustCompile is like Compile but panics if the expression cannot be parsed. +// It simplifies safe initialization of global variables holding compiled regular +// expressions. +func MustCompile(str string, options ...CompileOption) *Regexp { + c := newCompileConfig(options) + + // lookup if we have a pre-built state machine for this pattern and options + regexp := getEngineRegexp(str, c) + if regexp != nil { + return regexp + } + + regexp, err := compile(str, c) + if err != nil { + panic(`regexp2: Compile(` + quote(str) + `): ` + err.Error()) + } + return regexp +} + +// Escape adds backslashes to any special characters in the input string +func Escape(input string) string { + return syntax.Escape(input) +} + +// Unescape removes any backslashes from previously-escaped special characters in the input string +func Unescape(input string) (string, error) { + return syntax.Unescape(input) +} + +// SetTimeoutPeriod is a debug function that sets the frequency of the timeout goroutine's sleep cycle. +// Defaults to 100ms. The only benefit of setting this lower is that the 1 background goroutine that manages +// timeouts may exit slightly sooner after all the timeouts have expired. See Github issue #63 +func SetTimeoutCheckPeriod(d time.Duration) { + clockPeriod = d +} + +// StopTimeoutClock should only be used in unit tests to prevent the timeout clock goroutine +// from appearing like a leaking goroutine +func StopTimeoutClock() { + stopClock() +} + +// String returns the source text used to compile the regular expression. +func (re *Regexp) String() string { + return re.pattern +} + +func quote(s string) string { + if strconv.CanBackquote(s) { + return "`" + s + "`" + } + return strconv.Quote(s) +} + +func (re *Regexp) RightToLeft() bool { + return re.options&RightToLeft != 0 +} + +func (re *Regexp) Debug() bool { + return re.debug +} + +// Replace searches the input string and replaces each match found with the replacement text. +// Count will limit the number of matches attempted and startAt will allow +// us to skip past possible matches at the start of the input (left or right depending on RightToLeft option). +// Set startAt and count to -1 to go through the whole string +func (re *Regexp) Replace(input, replacement string, startAt, count int) (string, error) { + data, err := re.getReplacerData(replacement) + if err != nil { + return "", err + } + + return replace(re, data, nil, input, startAt, count) +} + +func (re *Regexp) getReplacerData(replacement string) (*syntax.ReplacerData, error) { + shouldCache := re.replaceCache != nil && re.optimizations.cacheReplacerData(replacement) + if shouldCache { + if data, ok := re.replaceCache.get(replacement); ok { + return data, nil + } + } + + data, err := syntax.NewReplacerData(replacement, re.caps, re.capsize, re.capnames, syntax.RegexOptions(re.options)) + if err != nil { + return nil, err + } + if shouldCache { + re.replaceCache.add(replacement, data) + } + return data, nil +} + +// ReplaceFunc searches the input string and replaces each match found using the string from the evaluator +// Count will limit the number of matches attempted and startAt will allow +// us to skip past possible matches at the start of the input (left or right depending on RightToLeft option). +// Set startAt and count to -1 to go through the whole string. +func (re *Regexp) ReplaceFunc(input string, evaluator MatchEvaluator, startAt, count int) (string, error) { + return replace(re, nil, evaluator, input, startAt, count) +} + +// FindStringMatch searches the input string for a Regexp match +func (re *Regexp) FindStringMatch(s string) (*Match, error) { + startAt, ok, err := re.findStringMatchStart(s, -1) + if err != nil { + return nil, err + } + if !ok { + return nil, nil + } + + r, runeStart := re.getRunesAndStart(s, startAt) + if runeStart < 0 { + runeStart = 0 + } + return re.run(false, runeStart, r, newStringMatchText(s, r)) +} + +// FindRunesMatch searches the input rune slice for a Regexp match +func (re *Regexp) FindRunesMatch(r []rune) (*Match, error) { + return re.run(false, -1, r, newMatchText(r)) +} + +// FindStringMatchStartingAt searches the input string for a Regexp match starting at the startAt index +func (re *Regexp) FindStringMatchStartingAt(s string, startAt int) (*Match, error) { + startAt, ok, err := re.findStringMatchStart(s, startAt) + if err != nil { + return nil, err + } + if !ok { + return nil, nil + } + + r, startAt := re.getRunesAndStart(s, startAt) + if startAt == -1 { + // we didn't find our start index in the string -- that's a problem + return nil, errors.New("startAt must align to the start of a valid rune in the input string") + } + + return re.run(false, startAt, r, newStringMatchText(s, r)) +} + +// FindRunesMatchStartingAt searches the input rune slice for a Regexp match starting at the startAt index +func (re *Regexp) FindRunesMatchStartingAt(r []rune, startAt int) (*Match, error) { + return re.run(false, startAt, r, newMatchText(r)) +} + +// FindAllStringIndex returns a slice of byte index pairs identifying all +// successive matches in s. +func (re *Regexp) FindAllStringIndex(s string, n int) ([][]int, error) { + if n == 0 { + return nil, nil + } + + startAt, ok, err := re.findStringMatchStart(s, -1) + if err != nil { + return nil, err + } + if !ok { + return nil, nil + } + + runner := re.getRunner() + var input []rune + var pooledInput *[]rune + runeStart := 0 + if startAt == 0 { + input, pooledInput = runner.decodeString(s) + } else { + input, runeStart, pooledInput = runner.decodeStringWithStart(s, startAt) + } + defer func() { + re.putRunner(runner) + if pooledInput != nil { + *pooledInput = input + pooledRuneBuffers.put(pooledInput) + } + }() + + if runeStart < 0 { + runeStart = 0 + } + + byteOffsets := newStringByteMapper(s) + return re.findAllRunesIndex(runner, input, runeStart, n, func(runeIndex, runeLength int) (int, int) { + if byteOffsets == nil { + return runeIndex, runeIndex + runeLength + } + return byteOffsets.byteIndex(runeIndex), byteOffsets.byteIndex(runeIndex + runeLength) + }) +} + +// FindAllRunesIndex returns a slice of rune index pairs identifying all +// successive matches in r. +func (re *Regexp) FindAllRunesIndex(r []rune, n int) ([][]int, error) { + if n == 0 { + return nil, nil + } + + runner := re.getRunner() + defer re.putRunner(runner) + + startAt := 0 + if re.RightToLeft() { + startAt = len(r) + } + return re.findAllRunesIndex(runner, r, startAt, n, func(runeIndex, runeLength int) (int, int) { + return runeIndex, runeIndex + runeLength + }) +} + +func (re *Regexp) findAllRunesIndex(runner *Runner, input []rune, startAt, n int, makeIndex func(runeIndex, runeLength int) (int, int)) ([][]int, error) { + var out [][]int + var flat []int + if n > 0 { + out = make([][]int, 0, n) + flat = make([]int, 0, n*2) + } + + prevEnd := -1 + for n != 0 { + m, err := runner.scan(input, nil, startAt, true, re.MatchTimeout) + if err != nil { + return nil, err + } + if m == nil { + break + } + + if m.RuneLength != 0 || m.RuneIndex != prevEnd { + start, end := makeIndex(m.RuneIndex, m.RuneLength) + flat = append(flat, start, end) + out = append(out, flat[len(flat)-2:len(flat):len(flat)]) + prevEnd = m.RuneIndex + m.RuneLength + if n > 0 { + n-- + } + } + + startAt = m.textpos + if m.RuneLength == 0 { + if re.RightToLeft() { + if m.textpos == 0 { + break + } + if startAt == m.textstart { + startAt-- + } + } else { + if m.textpos == len(input) { + break + } + if startAt == m.textstart { + startAt++ + } + } + } + } + return out, nil +} + +type stringByteMapper struct { + runeIndexes []int + deltas []int +} + +func newStringByteMapper(s string) *stringByteMapper { + var mapper *stringByteMapper + runeIndex := 0 + delta := 0 + for strIdx, ch := range s { + runeLen := utf8.RuneLen(ch) + if ch == utf8.RuneError { + _, runeLen = utf8.DecodeRuneInString(s[strIdx:]) + } + if runeLen != 1 { + if mapper == nil { + mapper = &stringByteMapper{} + } + delta += runeLen - 1 + mapper.runeIndexes = append(mapper.runeIndexes, runeIndex+1) + mapper.deltas = append(mapper.deltas, delta) + } + runeIndex++ + } + return mapper +} + +func (m *stringByteMapper) byteIndex(runeIndex int) int { + i := sort.Search(len(m.runeIndexes), func(i int) bool { + return m.runeIndexes[i] > runeIndex + }) - 1 + if i < 0 { + return runeIndex + } + return runeIndex + m.deltas[i] +} + +// FindNextMatch returns the next match in the same input string as the match parameter. +// Will return nil if there is no next match or if given a nil match. +func (re *Regexp) FindNextMatch(m *Match) (*Match, error) { + if m == nil { + return nil, nil + } + + // If previous match was empty, advance by one before matching to prevent + // infinite loop + startAt := m.textpos + if m.RuneLength == 0 { + if re.RightToLeft() { + if m.textpos == 0 { + return nil, nil + } + if startAt == m.textstart { + startAt-- + } + } else { + if m.textpos == len(m.text.runes) { + return nil, nil + } + + if startAt == m.textstart { + startAt++ + } + + } + } + return re.run(false, startAt, m.text.runes, m.text) +} + +// MatchString return true if the string matches the regex +// error will be set if a timeout occurs +func (re *Regexp) MatchString(s string) (bool, error) { + if re.stringPrefixFilter != nil && !re.RightToLeft() { + candidateByteIndex, ok := re.stringPrefixFilter(s, 0) + if !ok { + return false, nil + } + + return re.matchStringAt(s, candidateByteIndex) + } + return re.matchString(s) +} + +func (re *Regexp) matchString(s string) (bool, error) { + return re.matchStringAt(s, -1) +} + +func (re *Regexp) matchStringAt(s string, startAt int) (bool, error) { + runner := re.getRunner() + var input []rune + var pooledInput *[]rune + runeStart := 0 + if startAt <= 0 { + input, pooledInput = runner.decodeString(s) + if re.RightToLeft() { + runeStart = len(input) + } + } else { + input, runeStart, pooledInput = runner.decodeStringWithStart(s, startAt) + if runeStart < 0 { + runeStart = 0 + } + } + defer func() { + re.putRunner(runner) + if pooledInput != nil { + *pooledInput = input + pooledRuneBuffers.put(pooledInput) + } + }() + + m, err := runner.scan(input, nil, runeStart, true, re.MatchTimeout) + if err != nil { + return false, err + } + return m != nil, nil +} + +func (re *Regexp) getRunesAndStart(s string, startAt int) ([]rune, int) { + if startAt < 0 { + if re.RightToLeft() { + r := getRunes(s) + return r, len(r) + } + return getRunes(s), 0 + } + ret := make([]rune, len(s)) + i := 0 + runeIdx := -1 + for strIdx, r := range s { + if strIdx == startAt { + runeIdx = i + } + ret[i] = r + i++ + } + if startAt == len(s) { + runeIdx = i + } + return ret[:i], runeIdx +} + +func getRunes(s string) []rune { + return []rune(s) +} + +// MatchRunes return true if the runes matches the regex +// error will be set if a timeout occurs +func (re *Regexp) MatchRunes(r []rune) (bool, error) { + m, err := re.run(true, -1, r, nil) + if err != nil { + return false, err + } + return m != nil, nil +} + +// GetGroupNames Returns the set of strings used to name capturing groups in the expression. +func (re *Regexp) GetGroupNames() []string { + var result []string + + if re.capslist == nil { + result = make([]string, re.capsize) + + for i := 0; i < len(result); i++ { + result[i] = strconv.Itoa(i) + } + } else { + result = make([]string, len(re.capslist)) + copy(result, re.capslist) + } + + return result +} + +// GetGroupNumbers returns the integer group numbers corresponding to a group name. +func (re *Regexp) GetGroupNumbers() []int { + var result []int + + if re.caps == nil { + result = make([]int, re.capsize) + + for i := 0; i < len(result); i++ { + result[i] = i + } + } else { + result = make([]int, len(re.caps)) + + for k, v := range re.caps { + result[v] = k + } + } + + return result +} + +// GroupNameFromNumber retrieves a group name that corresponds to a group number. +// It will return "" for an unknown group number. Unnamed groups automatically +// receive a name that is the decimal string equivalent of its number, except in +// ECMAScript mode where unnamed groups have no name. +func (re *Regexp) GroupNameFromNumber(i int) string { + if re.capslist == nil { + if i >= 0 && i < re.capsize { + return strconv.Itoa(i) + } + + return "" + } + + if re.caps != nil { + var ok bool + if i, ok = re.caps[i]; !ok { + return "" + } + } + + if i >= 0 && i < len(re.capslist) { + return re.capslist[i] + } + + return "" +} + +// GroupNumberFromName returns a group number that corresponds to a group name. +// Returns -1 if the name is not a recognized group name. Numbered groups +// automatically get a group name that is the decimal string equivalent of its +// number, except in ECMAScript mode where unnamed groups have no name. +func (re *Regexp) GroupNumberFromName(name string) int { + // look up name if we have a hashtable of names + if re.capnames != nil { + if k, ok := re.capnames[name]; ok { + return k + } + + return -1 + } + + // convert to an int if it looks like a number + result := 0 + for i := 0; i < len(name); i++ { + ch := name[i] + + if ch > '9' || ch < '0' { + return -1 + } + + result *= 10 + result += int(ch - '0') + } + + // return int if it's in range + if result >= 0 && result < re.capsize { + return result + } + + return -1 +} + +// MarshalText implements [encoding.TextMarshaler]. The output +// matches that of calling the [Regexp.String] method. +func (re *Regexp) MarshalText() ([]byte, error) { + return []byte(re.String()), nil +} + +// UnmarshalText implements [encoding.TextUnmarshaler] by calling +// [Compile] on the encoded value. +func (re *Regexp) UnmarshalText(text []byte) error { + newRE, err := Compile(string(text), DefaultUnmarshalOptions) + if err != nil { + return err + } + *re = *newRE + return nil +} + +func (re *Regexp) initCaches() { + re.runnerPool = &sync.Pool{ + New: func() any { + return &Runner{ + re: re, + code: re.code, + } + }, + } + if re.optimizations.MaxCachedReplacerDataEntries > 0 { + re.replaceCache = newReplacerDataCache(re.optimizations.MaxCachedReplacerDataEntries) + } +} + +type replacerDataCache struct { + mu sync.Mutex + maxSize int + ll *list.List + cache map[string]*list.Element +} + +type replacerDataCacheEntry struct { + key string + data *syntax.ReplacerData +} + +func newReplacerDataCache(maxSize int) *replacerDataCache { + return &replacerDataCache{ + maxSize: maxSize, + ll: list.New(), + cache: make(map[string]*list.Element), + } +} + +func (c *replacerDataCache) get(key string) (*syntax.ReplacerData, bool) { + c.mu.Lock() + defer c.mu.Unlock() + + if ele, ok := c.cache[key]; ok { + c.ll.MoveToFront(ele) + return ele.Value.(*replacerDataCacheEntry).data, true + } + return nil, false +} + +func (c *replacerDataCache) add(key string, data *syntax.ReplacerData) { + c.mu.Lock() + defer c.mu.Unlock() + + if ele, ok := c.cache[key]; ok { + ele.Value.(*replacerDataCacheEntry).data = data + c.ll.MoveToFront(ele) + return + } + + ele := c.ll.PushFront(&replacerDataCacheEntry{key: key, data: data}) + c.cache[key] = ele + if c.maxSize > 0 && c.ll.Len() > c.maxSize { + oldest := c.ll.Back() + if oldest != nil { + c.ll.Remove(oldest) + delete(c.cache, oldest.Value.(*replacerDataCacheEntry).key) + } + } +} diff --git a/vendor/github.com/dlclark/regexp2/v2/regexp_codegen.go b/vendor/github.com/dlclark/regexp2/v2/regexp_codegen.go new file mode 100644 index 000000000..41c1aef35 --- /dev/null +++ b/vendor/github.com/dlclark/regexp2/v2/regexp_codegen.go @@ -0,0 +1,70 @@ +package regexp2 + +import ( + "sync" +) + +type RuntimeEngineData struct { + Caps map[int]int // capnum->index + CapNames map[string]int // cap group name -> index + CapsList []string // sorted list of capture group names + CapSize int // size of the capture array + FindFirstChar func(*Runner) bool // generated candidate search + Execute func(*Runner) error + StringPrefixFilter StringPrefixFilter // optional pre-decode candidate search for string input +} + +type cacheKey struct { + pattern string + opt RegexOptions + maintainCaptureOrder bool +} + +func RegisterEngine(pattern string, engine RuntimeEngineData, options ...CompileOption) { + c := newCompileConfig(options) + enginesMu.Lock() + engines[cacheKeyFromConfig(pattern, c)] = engine + enginesMu.Unlock() +} + +func newEngineRegexp(pattern string, c compileConfig, engine RuntimeEngineData) *Regexp { + re := &Regexp{ + pattern: pattern, + options: c.regexOptions, + debug: c.debug, + caps: engine.Caps, + capnames: engine.CapNames, + capslist: engine.CapsList, + capsize: engine.CapSize, + MatchTimeout: DefaultMatchTimeout, + optimizations: c.optimizations, + findFirstChar: engine.FindFirstChar, + execute: engine.Execute, + stringPrefixFilter: engine.StringPrefixFilter, + } + re.initCaches() + return re +} + +func getEngineRegexp(pattern string, c compileConfig) *Regexp { + enginesMu.RLock() + engine, ok := engines[cacheKeyFromConfig(pattern, c)] + enginesMu.RUnlock() + if !ok { + return nil + } + return newEngineRegexp(pattern, c, engine) +} + +func cacheKeyFromConfig(pattern string, c compileConfig) cacheKey { + return cacheKey{ + pattern: pattern, + opt: c.regexOptions, + maintainCaptureOrder: c.maintainCaptureOrder, + } +} + +var ( + enginesMu sync.RWMutex + engines = map[cacheKey]RuntimeEngineData{} +) diff --git a/vendor/github.com/dlclark/regexp2/v2/replace.go b/vendor/github.com/dlclark/regexp2/v2/replace.go new file mode 100644 index 000000000..240b40f4a --- /dev/null +++ b/vendor/github.com/dlclark/regexp2/v2/replace.go @@ -0,0 +1,357 @@ +package regexp2 + +import ( + "bytes" + "errors" + + "github.com/dlclark/regexp2/v2/syntax" +) + +const ( + replaceSpecials = 4 + replaceLeftPortion = -1 + replaceRightPortion = -2 + replaceLastGroup = -3 + replaceWholeString = -4 +) + +// MatchEvaluator is a function that takes a match and returns a replacement string to be used +type MatchEvaluator func(Match) string + +// Three very similar algorithms appear below: replace (pattern), +// replace (evaluator), and split. + +func writeRunes(buf *bytes.Buffer, text []rune, start, end int) { + for i := start; i < end; i++ { + buf.WriteRune(text[i]) + } +} + +func compactBalancedMatches(m *Match) { + for cap := 0; cap < len(m.matchcount); cap++ { + limit := m.matchcount[cap] * 2 + matcharray := m.matches[cap] + + var i, j int + for i = 0; i < limit; i++ { + if matcharray[i] < 0 { + break + } + } + + for j = i; i < limit; i++ { + if matcharray[i] < 0 { + j-- + } else { + if i != j { + matcharray[j] = matcharray[i] + } + j++ + } + } + + m.matchcount[cap] = j / 2 + } + m.balancing = false +} + +// Replace Replaces all occurrences of the regex in the string with the +// replacement pattern. +// +// Note that the special case of no matches is handled on its own: +// with no matches, the input string is returned unchanged. +// The right-to-left case is split out because StringBuilder +// doesn't handle right-to-left string building directly very well. +func replace(regex *Regexp, data *syntax.ReplacerData, evaluator MatchEvaluator, input string, startAt, count int) (string, error) { + if count < -1 { + return "", errors.New("count too small") + } + if count == 0 { + return "", nil + } + + if evaluator == nil { + if !regex.RightToLeft() { + return replaceRunnerLTR(regex, data, input, startAt, count) + } + return replaceRunnerRTL(regex, data, input, startAt, count) + } + + m, err := regex.FindStringMatchStartingAt(input, startAt) + + if err != nil { + return "", err + } + if m == nil { + return input, nil + } + + buf := &bytes.Buffer{} + text := m.text.runes + + if !regex.RightToLeft() { + prevat := 0 + for m != nil { + if m.RuneIndex != prevat { + buf.WriteString(string(text[prevat:m.RuneIndex])) + } + prevat = m.RuneIndex + m.RuneLength + buf.WriteString(evaluator(*m)) + + count-- + if count == 0 { + break + } + m, err = regex.FindNextMatch(m) + if err != nil { + return "", err + } + } + + if prevat < len(text) { + buf.WriteString(string(text[prevat:])) + } + } else { + prevat := len(text) + var al []string + + for m != nil { + if m.RuneIndex+m.RuneLength != prevat { + al = append(al, string(text[m.RuneIndex+m.RuneLength:prevat])) + } + prevat = m.RuneIndex + al = append(al, evaluator(*m)) + + count-- + if count == 0 { + break + } + m, err = regex.FindNextMatch(m) + if err != nil { + return "", err + } + } + + if prevat > 0 { + buf.WriteString(string(text[:prevat])) + } + + for i := len(al) - 1; i >= 0; i-- { + buf.WriteString(al[i]) + } + } + + return buf.String(), nil +} + +func replaceRunnerLTR(regex *Regexp, data *syntax.ReplacerData, input string, startAt, count int) (string, error) { + if startAt > len(input) { + return "", errors.New("startAt must be less than the length of the input string") + } + + runner := regex.getRunner() + text, runeStart, pooledText := runner.decodeStringWithStart(input, startAt) + textInfo := newStringMatchText(input, text) + defer func() { + regex.putRunner(runner) + if pooledText != nil { + pooledRuneBuffers.put(pooledText) + } + }() + if startAt >= 0 && runeStart < 0 { + return "", errors.New("startAt must align to the start of a valid rune in the input string") + } + if runeStart < 0 { + runeStart = 0 + } + + m, err := runner.scan(text, textInfo, runeStart, true, regex.MatchTimeout) + if err != nil { + return "", err + } + if m == nil { + return input, nil + } + + buf, pooledBuf := getPooledReplaceBuffer(len(input), regex.optimizations.MaxCachedReplaceBufferLength) + if pooledBuf != nil { + defer putPooledReplaceBuffer(buf, pooledBuf) + } + + prevat := 0 + for m != nil { + if m.balancing { + compactBalancedMatches(m) + } + + if m.RuneIndex != prevat { + writeRunes(buf, text, prevat, m.RuneIndex) + } + prevat = m.RuneIndex + m.RuneLength + replacementImpl(data, buf, m) + + count-- + if count == 0 { + break + } + + scanStart := m.textpos + if m.RuneLength == 0 { + if scanStart >= len(text) { + break + } + scanStart++ + } + + m, err = runner.scan(text, textInfo, scanStart, true, regex.MatchTimeout) + if err != nil { + return "", err + } + } + + if prevat < len(text) { + writeRunes(buf, text, prevat, len(text)) + } + return buf.String(), nil +} + +func replaceRunnerRTL(regex *Regexp, data *syntax.ReplacerData, input string, startAt, count int) (string, error) { + if startAt > len(input) { + return "", errors.New("startAt must be less than the length of the input string") + } + + runner := regex.getRunner() + text, runeStart, pooledText := runner.decodeStringWithStart(input, startAt) + textInfo := newStringMatchText(input, text) + defer func() { + regex.putRunner(runner) + if pooledText != nil { + pooledRuneBuffers.put(pooledText) + } + }() + if startAt >= 0 && runeStart < 0 { + return "", errors.New("startAt must align to the start of a valid rune in the input string") + } + if runeStart < 0 { + runeStart = len(text) + } + + m, err := runner.scan(text, textInfo, runeStart, true, regex.MatchTimeout) + if err != nil { + return "", err + } + if m == nil { + return input, nil + } + + buf, pooledBuf := getPooledReplaceBuffer(len(input), regex.optimizations.MaxCachedReplaceBufferLength) + if pooledBuf != nil { + defer putPooledReplaceBuffer(buf, pooledBuf) + } + + prevat := len(text) + var al []string + + for m != nil { + if m.balancing { + compactBalancedMatches(m) + } + + if m.RuneIndex+m.RuneLength != prevat { + al = append(al, string(text[m.RuneIndex+m.RuneLength:prevat])) + } + prevat = m.RuneIndex + replacementImplRTL(data, &al, m) + + count-- + if count == 0 { + break + } + + scanStart := m.textpos + if m.RuneLength == 0 { + if scanStart <= 0 { + break + } + scanStart-- + } + + m, err = runner.scan(text, textInfo, scanStart, true, regex.MatchTimeout) + if err != nil { + return "", err + } + } + + if prevat > 0 { + writeRunes(buf, text, 0, prevat) + } + for i := len(al) - 1; i >= 0; i-- { + buf.WriteString(al[i]) + } + return buf.String(), nil +} + +// Given a Match, emits into the StringBuilder the evaluated +// substitution pattern. +func replacementImpl(data *syntax.ReplacerData, buf *bytes.Buffer, m *Match) { + for _, r := range data.Rules { + + if r >= 0 { // string lookup + buf.WriteString(data.Strings[r]) + } else if r < -replaceSpecials { // group lookup + m.groupValueAppendToBuf(-replaceSpecials-1-r, buf) + } else { + switch -replaceSpecials - 1 - r { // special insertion patterns + case replaceLeftPortion: + for i := 0; i < m.RuneIndex; i++ { + buf.WriteRune(m.text.runes[i]) + } + case replaceRightPortion: + for i := m.RuneIndex + m.RuneLength; i < len(m.text.runes); i++ { + buf.WriteRune(m.text.runes[i]) + } + case replaceLastGroup: + m.groupValueAppendToBuf(m.GroupCount()-1, buf) + case replaceWholeString: + for i := 0; i < len(m.text.runes); i++ { + buf.WriteRune(m.text.runes[i]) + } + } + } + } +} + +func replacementImplRTL(data *syntax.ReplacerData, al *[]string, m *Match) { + l := *al + buf := &bytes.Buffer{} + + for _, r := range data.Rules { + buf.Reset() + if r >= 0 { // string lookup + l = append(l, data.Strings[r]) + } else if r < -replaceSpecials { // group lookup + m.groupValueAppendToBuf(-replaceSpecials-1-r, buf) + l = append(l, buf.String()) + } else { + switch -replaceSpecials - 1 - r { // special insertion patterns + case replaceLeftPortion: + for i := 0; i < m.RuneIndex; i++ { + buf.WriteRune(m.text.runes[i]) + } + case replaceRightPortion: + for i := m.RuneIndex + m.RuneLength; i < len(m.text.runes); i++ { + buf.WriteRune(m.text.runes[i]) + } + case replaceLastGroup: + m.groupValueAppendToBuf(m.GroupCount()-1, buf) + case replaceWholeString: + for i := 0; i < len(m.text.runes); i++ { + buf.WriteRune(m.text.runes[i]) + } + } + l = append(l, buf.String()) + } + } + + *al = l +} diff --git a/vendor/github.com/dlclark/regexp2/v2/runner.go b/vendor/github.com/dlclark/regexp2/v2/runner.go new file mode 100644 index 000000000..ce09df07d --- /dev/null +++ b/vendor/github.com/dlclark/regexp2/v2/runner.go @@ -0,0 +1,2197 @@ +package regexp2 + +import ( + "bytes" + "fmt" + "math" + "slices" + "strconv" + "strings" + "time" + "unicode" + + "github.com/dlclark/regexp2/v2/helpers" + "github.com/dlclark/regexp2/v2/syntax" +) + +type Runner struct { + re *Regexp + code *syntax.Code + debug bool + + Runtextstart int // starting point for search + + Runtext []rune // text to search + Runtextpos int // current position in text + Runtextend int + + // The backtracking stack. Opcodes use this to store data regarding + // what they have matched and where to backtrack to. Each "frame" on + // the stack takes the form of [CodePosition Data1 Data2...], where + // CodePosition is the position of the current opcode and + // the data values are all optional. The CodePosition can be negative, and + // these values (also called "back2") are used by the BranchMark family of opcodes + // to indicate whether they are backtracking after a successful or failed + // match. + // When we backtrack, we pop the CodePosition off the stack, set the current + // instruction pointer to that code position, and mark the opcode + // with a backtracking flag ("Back"). Each opcode then knows how to + // handle its own data. + runtrack []int + Runtrackpos int + + // This stack is used to track text positions across different opcodes. + // For example, in /(a*b)+/, the parentheses result in a SetMark/CaptureMark + // pair. SetMark records the text position before we match a*b. Then + // CaptureMark uses that position to figure out where the capture starts. + // Opcodes which push onto this stack are always paired with other opcodes + // which will pop the value from it later. A successful match should mean + // that this stack is empty. + runstack []int + Runstackpos int + + // The crawl stack is used to keep track of captures. Every time a group + // has a capture, we push its group number onto the runcrawl stack. In + // the case of a balanced match, we push BOTH groups onto the stack. + runcrawl []int + runcrawlpos int + + runtrackcount int // count of states that may do backtracking + + runmatch *Match // result object + + ignoreTimeout bool + timeout time.Duration // timeout in milliseconds (needed for actual) + deadline fasttime + + operator syntax.InstOp + codepos int + rightToLeft bool + caseInsensitive bool +} + +// run searches for matches and can continue from the previous match. +// +// quick is usually false, but can be true to not return matches, just put it in caches. +// textstart is -1 to start at the "beginning" (depending on Right-To-Left), otherwise an index in input. +// textInfo is nil for quick scans that do not need returned capture text metadata. +func (re *Regexp) run(quick bool, textstart int, input []rune, textInfo *matchText) (*Match, error) { + + // get a cached runner + runner := re.getRunner() + defer re.putRunner(runner) + + if textstart < 0 { + if re.RightToLeft() { + textstart = len(input) + } else { + textstart = 0 + } + } + + return runner.scan(input, textInfo, textstart, quick, re.MatchTimeout) +} + +// Scans the string to find the first match. Uses the Match object +// both to feed text in and as a place to store matches that come out. +// +// All the action is in the Go() method. Our +// responsibility is to load up the class members before +// calling Go. +// +// The optimizer can compute a set of candidate starting characters, +// and we could use a separate method Skip() that will quickly scan past +// any characters that we know can't match. +// +// The input slice is passed separately from matchText so quick scans can avoid +// allocating match metadata. When textInfo is nil, successful matches are only +// used as a boolean result and capture text is intentionally unavailable. If +// we collapsed down to just textInfo it would "escape" and hit the GC for fast +// scans without captures. +func (r *Runner) scan(rt []rune, textInfo *matchText, textstart int, quick bool, timeout time.Duration) (*Match, error) { + r.timeout = timeout + r.ignoreTimeout = (time.Duration(math.MaxInt64) == timeout) + r.debug = r.re.Debug() + r.Runtextstart = textstart + r.Runtext = rt + r.Runtextend = len(rt) + + stoppos := r.Runtextend + bump := 1 + + if r.re.RightToLeft() { + bump = -1 + stoppos = 0 + } + + r.Runtextpos = textstart + //initted := false + + // setup our scanner functions + findFirstChar := r.re.findFirstChar + execute := r.re.execute + if findFirstChar == nil { + findFirstChar = findFirstCharDefault + } + if execute == nil { + execute = executeDefault + } + + minRequiredLength := 0 + if r.code != nil && r.code.FindOptimizations != nil { + minRequiredLength = r.code.FindOptimizations.MinRequiredLength + } + + r.initMatch(textInfo) + + r.startTimeoutWatch() + for { + if minRequiredLength > 0 { + if r.code.RightToLeft { + if r.Runtextpos < minRequiredLength { + r.tidyMatch(true) + return nil, nil + } + } else if r.Runtextend-r.Runtextpos < minRequiredLength { + r.tidyMatch(true) + return nil, nil + } + } + + if r.debug { + //fmt.Printf("\nSearch content: %v\n", string(r.runtext)) + fmt.Printf("\nSearch range: from 0 to %v\n", r.Runtextend) + fmt.Printf("Firstchar search starting at %v stopping at %v\n", r.Runtextpos, stoppos) + } + + if findFirstChar(r) { + if !r.ignoreTimeout { + if err := r.CheckTimeout(); err != nil { + return nil, err + } + } + + if r.debug { + fmt.Printf("Executing engine starting at %v\n\n", r.Runtextpos) + } + + if err := execute(r); err != nil { + return nil, err + } + + if r.runmatch.matchcount[0] > 0 { + // We'll return a match even if it touches a previous empty match + return r.tidyMatch(quick), nil + } + + // reset state for another go + r.Runtrackpos = len(r.runtrack) + r.Runstackpos = len(r.runstack) + r.runcrawlpos = len(r.runcrawl) + } + + // failure! + + if r.Runtextpos == stoppos { + r.tidyMatch(true) + return nil, nil + } + + // Recognize leading []* and various anchors, and bump on failure accordingly + + // r.bump by one and start again + + r.Runtextpos += bump + } + // We never get here +} + +func executeDefault(r *Runner) error { + + r.goTo(0) + + for { + + if r.debug { + r.dumpState() + } + + if !r.ignoreTimeout { + if err := r.CheckTimeout(); err != nil { + return err + } + } + + switch r.operator { + case syntax.Stop: + return nil + + case syntax.Nothing: + //noop + + case syntax.Goto: + r.goTo(r.operand(0)) + continue + + case syntax.Testref: + if !r.runmatch.isMatched(r.operand(0)) { + break + } + r.advance(1) + continue + + case syntax.Lazybranch: + r.trackPush1(r.textPos()) + r.advance(1) + continue + + case syntax.Lazybranch | syntax.Back: + r.trackPop() + r.textto(r.trackPeek()) + r.goTo(r.operand(0)) + continue + + case syntax.Setmark: + r.stackPush(r.textPos()) + r.trackPush() + r.advance(0) + continue + + case syntax.Nullmark: + r.stackPush(-1) + r.trackPush() + r.advance(0) + continue + + case syntax.Setmark | syntax.Back, syntax.Nullmark | syntax.Back: + r.stackPop() + + case syntax.Getmark: + r.stackPop() + r.trackPush1(r.stackPeek()) + r.textto(r.stackPeek()) + r.advance(0) + continue + + case syntax.Getmark | syntax.Back: + r.trackPop() + r.stackPush(r.trackPeek()) + + case syntax.Capturemark: + if r.operand(1) != -1 && !r.runmatch.isMatched(r.operand(1)) { + break + } + r.stackPop() + if r.operand(1) != -1 { + r.transferCapture(r.operand(0), r.operand(1), r.stackPeek(), r.textPos()) + } else { + r.Capture(r.operand(0), r.stackPeek(), r.textPos()) + } + r.trackPush1(r.stackPeek()) + + r.advance(2) + + continue + + case syntax.Capturemark | syntax.Back: + r.trackPop() + r.stackPush(r.trackPeek()) + r.uncapture() + if r.operand(0) != -1 && r.operand(1) != -1 { + r.uncapture() + } + + case syntax.Branchmark: + r.stackPop() + + matched := r.textPos() - r.stackPeek() + + if matched != 0 { // Nonempty match -> loop now + r.trackPush2(r.stackPeek(), r.textPos()) // Save old mark, textpos + r.stackPush(r.textPos()) // Make new mark + r.goTo(r.operand(0)) // Loop + } else { // Empty match -> straight now + r.trackPushNeg1(r.stackPeek()) // Save old mark + r.advance(1) // Straight + } + continue + + case syntax.Branchmark | syntax.Back: + r.trackPopN(2) + r.stackPop() + r.textto(r.trackPeekN(1)) // Recall position + r.trackPushNeg1(r.trackPeek()) // Save old mark + r.advance(1) // Straight + continue + + case syntax.Branchmark | syntax.Back2: + r.trackPop() + r.stackPush(r.trackPeek()) // Recall old mark + // Backtrack + + case syntax.Lazybranchmark: + { + // We hit this the first time through a lazy loop and after each + // successful match of the inner expression. It simply continues + // on and doesn't loop. + r.stackPop() + + oldMarkPos := r.stackPeek() + + if r.textPos() != oldMarkPos { // Nonempty match -> try to loop again by going to 'back' state + if oldMarkPos != -1 { + r.trackPush2(oldMarkPos, r.textPos()) // Save old mark, textpos + } else { + r.trackPush2(r.textPos(), r.textPos()) + } + } else { + // The inner expression found an empty match, so we'll go directly to 'back2' if we + // backtrack. Don't touch the grouping stack here; instead, record the old mark and + // a flag indicating that backtracking doesn't need to pop a grouping stack frame. + r.trackPushNeg2(oldMarkPos, 0) + } + r.advance(1) + continue + } + + case syntax.Lazybranchmark | syntax.Back: + + // After the first time, Lazybranchmark | syntax.Back occurs + // with each iteration of the loop, and therefore with every attempted + // match of the inner expression. We'll try to match the inner expression, + // then go back to Lazybranchmark if successful. If the inner expression + // fails, we go to Lazybranchmark | syntax.Back2 + + r.trackPopN(2) + pos := r.trackPeekN(1) + r.trackPushNeg2(r.trackPeek(), 1) // Save old mark, note that we pushed a new mark + r.stackPush(pos) // Make new mark + r.textto(pos) // Recall position + r.goTo(r.operand(0)) // Loop + continue + + case syntax.Lazybranchmark | syntax.Back2: + // The lazy loop has failed. We'll do a true backtrack and + // start over before the lazy loop. + r.trackPopN(2) + oldMark := r.trackPeek() + needsPop := r.trackPeekN(1) + if needsPop != 0 { + r.stackPop() + } + r.stackPush(oldMark) // Recall old mark + + case syntax.Setcount: + r.stackPush2(r.textPos(), r.operand(0)) + r.trackPush() + r.advance(1) + continue + + case syntax.Nullcount: + r.stackPush2(-1, r.operand(0)) + r.trackPush() + r.advance(1) + continue + + case syntax.Setcount | syntax.Back: + r.stackPopN(2) + + case syntax.Nullcount | syntax.Back: + r.stackPopN(2) + + case syntax.Branchcount: + // r.stackPush: + // 0: Mark + // 1: Count + + r.stackPopN(2) + mark := r.stackPeek() + count := r.stackPeekN(1) + matched := r.textPos() - mark + + if count >= r.operand(1) || (matched == 0 && count >= 0) { // Max loops or empty match -> straight now + r.trackPushNeg2(mark, count) // Save old mark, count + r.advance(2) // Straight + } else { // Nonempty match -> count+loop now + r.trackPush1(mark) // remember mark + r.stackPush2(r.textPos(), count+1) // Make new mark, incr count + r.goTo(r.operand(0)) // Loop + } + continue + + case syntax.Branchcount | syntax.Back: + // r.trackPush: + // 0: Previous mark + // r.stackPush: + // 0: Mark (= current pos, discarded) + // 1: Count + r.trackPop() + r.stackPopN(2) + if r.stackPeekN(1) > 0 { // Positive -> can go straight + r.textto(r.stackPeek()) // Zap to mark + r.trackPushNeg2(r.trackPeek(), r.stackPeekN(1)-1) // Save old mark, old count + r.advance(2) // Straight + continue + } + r.stackPush2(r.trackPeek(), r.stackPeekN(1)-1) // recall old mark, old count + + case syntax.Branchcount | syntax.Back2: + // r.trackPush: + // 0: Previous mark + // 1: Previous count + r.trackPopN(2) + r.stackPush2(r.trackPeek(), r.trackPeekN(1)) // Recall old mark, old count + + case syntax.Lazybranchcount: + // r.stackPush: + // 0: Mark + // 1: Count + + r.stackPopN(2) + mark := r.stackPeek() + count := r.stackPeekN(1) + + if count < 0 { // Negative count -> loop now + r.trackPushNeg1(mark) // Save old mark + r.stackPush2(r.textPos(), count+1) // Make new mark, incr count + r.goTo(r.operand(0)) // Loop + } else { // Nonneg count -> straight now + r.trackPush3(mark, count, r.textPos()) // Save mark, count, position + r.advance(2) // Straight + } + continue + + case syntax.Lazybranchcount | syntax.Back: + // r.trackPush: + // 0: Mark + // 1: Count + // 2: r.textPos + + r.trackPopN(3) + mark := r.trackPeek() + textpos := r.trackPeekN(2) + + if r.trackPeekN(1) < r.operand(1) && textpos != mark { // Under limit and not empty match -> loop + r.textto(textpos) // Recall position + r.stackPush2(textpos, r.trackPeekN(1)+1) // Make new mark, incr count + r.trackPushNeg1(mark) // Save old mark + r.goTo(r.operand(0)) // Loop + continue + } else { // Max loops or empty match -> backtrack + r.stackPush2(r.trackPeek(), r.trackPeekN(1)) // Recall old mark, count + // backtrack + } + + case syntax.Lazybranchcount | syntax.Back2: + // r.trackPush: + // 0: Previous mark + // r.stackPush: + // 0: Mark (== current pos, discarded) + // 1: Count + r.trackPop() + r.stackPopN(2) + r.stackPush2(r.trackPeek(), r.stackPeekN(1)-1) // Recall old mark, count + // Backtrack + + case syntax.Setjump: + r.stackPush2(r.trackpos(), r.Crawlpos()) + r.trackPush() + r.advance(0) + continue + + case syntax.Setjump | syntax.Back: + r.stackPopN(2) + + case syntax.Backjump: + // r.stackPush: + // 0: Saved trackpos + // 1: r.crawlpos + r.stackPopN(2) + r.trackto(r.stackPeek()) + + for r.Crawlpos() != r.stackPeekN(1) { + r.uncapture() + } + + case syntax.Forejump: + // r.stackPush: + // 0: Saved trackpos + // 1: r.crawlpos + r.stackPopN(2) + r.trackto(r.stackPeek()) + r.trackPush1(r.stackPeekN(1)) + r.advance(0) + continue + + case syntax.Forejump | syntax.Back: + // r.trackPush: + // 0: r.crawlpos + r.trackPop() + + for r.Crawlpos() != r.trackPeek() { + r.uncapture() + } + + case syntax.Bol: + if r.leftchars() > 0 && r.charAt(r.textPos()-1) != '\n' { + break + } + r.advance(0) + continue + + case syntax.Eol: + if r.rightchars() > 0 && r.charAt(r.textPos()) != '\n' { + break + } + r.advance(0) + continue + + case syntax.Boundary: + if !r.IsBoundary(r.textPos()) { + break + } + r.advance(0) + continue + + case syntax.Nonboundary: + if r.IsBoundary(r.textPos()) { + break + } + r.advance(0) + continue + + case syntax.ECMABoundary: + if !r.IsECMABoundary(r.textPos()) { + break + } + r.advance(0) + continue + + case syntax.NonECMABoundary: + if r.IsECMABoundary(r.textPos()) { + break + } + r.advance(0) + continue + + case syntax.Beginning: + if r.leftchars() > 0 { + break + } + r.advance(0) + continue + + case syntax.Start: + if r.textPos() != r.textstart() { + break + } + r.advance(0) + continue + + case syntax.EndZ: + rchars := r.rightchars() + if rchars > 1 { + break + } + // RE2 and EcmaScript define $ as "asserts position at the end of the string" + // PCRE/.NET adds "or before the line terminator right at the end of the string (if any)" + if (r.re.options & (RE2 | ECMAScript)) != 0 { + // RE2/Ecmascript mode + if rchars > 0 { + break + } + } else if rchars == 1 && r.charAt(r.textPos()) != '\n' { + // "regular" mode + break + } + + r.advance(0) + continue + + case syntax.End: + if r.rightchars() > 0 { + break + } + r.advance(0) + continue + + case syntax.One: + if r.forwardchars() < 1 || r.forwardcharnext() != rune(r.operand(0)) { + break + } + + r.advance(1) + continue + + case syntax.Notone: + if r.forwardchars() < 1 || r.forwardcharnext() == rune(r.operand(0)) { + break + } + + r.advance(1) + continue + + case syntax.Set: + + if r.forwardchars() < 1 || !r.code.Sets[r.operand(0)].CharIn(r.forwardcharnext()) { + break + } + + r.advance(1) + continue + + case syntax.Multi: + if !r.runematch(r.code.Strings[r.operand(0)]) { + break + } + + r.advance(1) + continue + + case syntax.Ref: + + capnum := r.operand(0) + + if r.runmatch.isMatched(capnum) { + if !r.refmatch(r.runmatch.matchIndex(capnum), r.runmatch.matchLength(capnum)) { + break + } + } else { + if (r.re.options & ECMAScript) == 0 { + break + } + } + + r.advance(1) + continue + + case syntax.Onerep: + + c := r.operand(1) + + if r.forwardchars() < c { + break + } + + ch := rune(r.operand(0)) + + for c > 0 { + if r.forwardcharnext() != ch { + goto BreakBackward + } + c-- + } + + r.advance(2) + continue + + case syntax.Notonerep: + + c := r.operand(1) + + if r.forwardchars() < c { + break + } + ch := rune(r.operand(0)) + + for c > 0 { + if r.forwardcharnext() == ch { + goto BreakBackward + } + c-- + } + + r.advance(2) + continue + + case syntax.Setrep: + + c := r.operand(1) + + if r.forwardchars() < c { + break + } + + set := r.code.Sets[r.operand(0)] + + for c > 0 { + if !set.CharIn(r.forwardcharnext()) { + goto BreakBackward + } + c-- + } + + r.advance(2) + continue + + case syntax.Oneloop, syntax.Oneloopatomic: + + c := r.operand(1) + + if c > r.forwardchars() { + c = r.forwardchars() + } + + ch := rune(r.operand(0)) + i := c + + for ; i > 0; i-- { + if r.forwardcharnext() != ch { + r.backwardnext() + break + } + } + + if c > i && r.operator == syntax.Oneloop { + r.trackPush2(c-i-1, r.textPos()-r.bump()) + } + + r.advance(2) + continue + + case syntax.Notoneloop, syntax.Notoneloopatomic: + + c := r.operand(1) + + if c > r.forwardchars() { + c = r.forwardchars() + } + + ch := rune(r.operand(0)) + i := c + + for ; i > 0; i-- { + if r.forwardcharnext() == ch { + r.backwardnext() + break + } + } + + if c > i && r.operator == syntax.Notoneloop { + r.trackPush2(c-i-1, r.textPos()-r.bump()) + } + + r.advance(2) + continue + + case syntax.Setloop, syntax.Setloopatomic: + + c := r.operand(1) + + if c > r.forwardchars() { + c = r.forwardchars() + } + + set := r.code.Sets[r.operand(0)] + i := c + + for ; i > 0; i-- { + if !set.CharIn(r.forwardcharnext()) { + r.backwardnext() + break + } + } + + if c > i && r.operator == syntax.Setloop { + r.trackPush2(c-i-1, r.textPos()-r.bump()) + } + + r.advance(2) + continue + + case syntax.Oneloop | syntax.Back, syntax.Notoneloop | syntax.Back: + + r.trackPopN(2) + i := r.trackPeek() + pos := r.trackPeekN(1) + + r.textto(pos) + + if i > 0 { + r.trackPush2(i-1, pos-r.bump()) + } + + r.advance(2) + continue + + case syntax.Setloop | syntax.Back: + + r.trackPopN(2) + i := r.trackPeek() + pos := r.trackPeekN(1) + + r.textto(pos) + + if i > 0 { + r.trackPush2(i-1, pos-r.bump()) + } + + r.advance(2) + continue + + case syntax.Onelazy, syntax.Notonelazy: + + c := r.operand(1) + + if c > r.forwardchars() { + c = r.forwardchars() + } + + if c > 0 { + r.trackPush2(c-1, r.textPos()) + } + + r.advance(2) + continue + + case syntax.Setlazy: + + c := r.operand(1) + + if c > r.forwardchars() { + c = r.forwardchars() + } + + if c > 0 { + r.trackPush2(c-1, r.textPos()) + } + + r.advance(2) + continue + + case syntax.Onelazy | syntax.Back: + + r.trackPopN(2) + pos := r.trackPeekN(1) + r.textto(pos) + + if r.forwardcharnext() != rune(r.operand(0)) { + break + } + + i := r.trackPeek() + + if i > 0 { + r.trackPush2(i-1, pos+r.bump()) + } + + r.advance(2) + continue + + case syntax.Notonelazy | syntax.Back: + + r.trackPopN(2) + pos := r.trackPeekN(1) + r.textto(pos) + + if r.forwardcharnext() == rune(r.operand(0)) { + break + } + + i := r.trackPeek() + + if i > 0 { + r.trackPush2(i-1, pos+r.bump()) + } + + r.advance(2) + continue + + case syntax.Setlazy | syntax.Back: + + r.trackPopN(2) + pos := r.trackPeekN(1) + r.textto(pos) + + if !r.code.Sets[r.operand(0)].CharIn(r.forwardcharnext()) { + break + } + + i := r.trackPeek() + + if i > 0 { + r.trackPush2(i-1, pos+r.bump()) + } + + r.advance(2) + continue + + case syntax.UpdateBumpalong: + // UpdateBumpalong should only exist in the code stream at such a point where the root + // of the backtracking stack contains the runtextpos from the start of this Go call. Replace + // that tracking value with the current runtextpos value if it's greater. + trackingpos := r.runtrack[len(r.runtrack)-1] + if trackingpos < r.Runtextpos { + r.runtrack[len(r.runtrack)-1] = r.Runtextpos + } + r.advance(0) + continue + + default: + return fmt.Errorf("unknown state in regex runner: %v", r.operator) + } + + BreakBackward: + ; + + // "break Backward" comes here: + r.backtrack() + } +} + +// increase the size of stack and track storage +func (r *Runner) ensureStorage() { + if r.Runstackpos < r.runtrackcount*4 { + doubleIntSlice(&r.runstack, &r.Runstackpos) + } + if r.Runtrackpos < r.runtrackcount*4 { + doubleIntSlice(&r.runtrack, &r.Runtrackpos) + } +} + +func (r *Runner) ensureStack(plus int) { + if r.Runstackpos-plus < r.runtrackcount*4 { + doubleIntSlice(&r.runstack, &r.Runstackpos) + } +} + +func doubleIntSlice(s *[]int, pos *int) { + oldLen := len(*s) + newS := make([]int, oldLen*2) + + copy(newS[oldLen:], *s) + *pos += oldLen + *s = newS +} + +// Save a number on the longjump unrolling stack +func (r *Runner) crawl(i int) { + if r.runcrawlpos == 0 { + doubleIntSlice(&r.runcrawl, &r.runcrawlpos) + } + r.runcrawlpos-- + r.runcrawl[r.runcrawlpos] = i +} + +// Remove a number from the longjump unrolling stack +func (r *Runner) popcrawl() int { + val := r.runcrawl[r.runcrawlpos] + r.runcrawlpos++ + return val +} + +// Get the height of the stack +func (r *Runner) Crawlpos() int { + return len(r.runcrawl) - r.runcrawlpos +} + +func (r *Runner) advance(i int) { + r.codepos += (i + 1) + r.setOperator(r.code.Codes[r.codepos]) +} + +func (r *Runner) goTo(newpos int) { + // when branching backward or in place, ensure storage + if newpos <= r.codepos { + r.ensureStorage() + } + + r.setOperator(r.code.Codes[newpos]) + r.codepos = newpos +} + +func (r *Runner) textto(newpos int) { + r.Runtextpos = newpos +} + +func (r *Runner) trackto(newpos int) { + r.Runtrackpos = len(r.runtrack) - newpos +} + +func (r *Runner) textstart() int { + return r.Runtextstart +} + +func (r *Runner) textPos() int { + return r.Runtextpos +} + +// push onto the backtracking stack +func (r *Runner) trackpos() int { + return len(r.runtrack) - r.Runtrackpos +} + +func (r *Runner) trackPush() { + r.Runtrackpos-- + r.runtrack[r.Runtrackpos] = r.codepos +} + +func (r *Runner) trackPush1(I1 int) { + r.Runtrackpos-- + r.runtrack[r.Runtrackpos] = I1 + r.Runtrackpos-- + r.runtrack[r.Runtrackpos] = r.codepos +} + +func (r *Runner) trackPush2(I1, I2 int) { + r.Runtrackpos-- + r.runtrack[r.Runtrackpos] = I1 + r.Runtrackpos-- + r.runtrack[r.Runtrackpos] = I2 + r.Runtrackpos-- + r.runtrack[r.Runtrackpos] = r.codepos +} + +func (r *Runner) trackPush3(I1, I2, I3 int) { + r.Runtrackpos-- + r.runtrack[r.Runtrackpos] = I1 + r.Runtrackpos-- + r.runtrack[r.Runtrackpos] = I2 + r.Runtrackpos-- + r.runtrack[r.Runtrackpos] = I3 + r.Runtrackpos-- + r.runtrack[r.Runtrackpos] = r.codepos +} + +func (r *Runner) trackPushNeg1(I1 int) { + r.Runtrackpos-- + r.runtrack[r.Runtrackpos] = I1 + r.Runtrackpos-- + r.runtrack[r.Runtrackpos] = -r.codepos +} + +func (r *Runner) trackPushNeg2(I1, I2 int) { + r.Runtrackpos-- + r.runtrack[r.Runtrackpos] = I1 + r.Runtrackpos-- + r.runtrack[r.Runtrackpos] = I2 + r.Runtrackpos-- + r.runtrack[r.Runtrackpos] = -r.codepos +} + +func (r *Runner) backtrack() { + newpos := r.runtrack[r.Runtrackpos] + r.Runtrackpos++ + + if r.debug { + if newpos < 0 { + fmt.Printf(" Backtracking (back2) to code position %v\n", -newpos) + } else { + fmt.Printf(" Backtracking to code position %v\n", newpos) + } + } + + if newpos < 0 { + newpos = -newpos + r.setOperator(r.code.Codes[newpos] | int(syntax.Back2)) + } else { + r.setOperator(r.code.Codes[newpos] | int(syntax.Back)) + } + + // When branching backward, ensure storage + if newpos < r.codepos { + r.ensureStorage() + } + + r.codepos = newpos +} + +func (r *Runner) setOperator(op int) { + r.caseInsensitive = (0 != (op & int(syntax.Ci))) + r.rightToLeft = (0 != (op & int(syntax.Rtl))) + r.operator = syntax.InstOp(op & ^int(syntax.Rtl|syntax.Ci)) +} + +func (r *Runner) trackPop() { + r.Runtrackpos++ +} + +// pop framesize items from the backtracking stack +func (r *Runner) trackPopN(framesize int) { + r.Runtrackpos += framesize +} + +// Technically we are actually peeking at items already popped. So if you want to +// get and pop the top item from the stack, you do +// r.trackPop(); +// r.trackPeek(); +func (r *Runner) trackPeek() int { + return r.runtrack[r.Runtrackpos-1] +} + +// get the ith element down on the backtracking stack +func (r *Runner) trackPeekN(i int) int { + return r.runtrack[r.Runtrackpos-i-1] +} + +// Push onto the grouping stack +func (r *Runner) stackPush(I1 int) { + r.Runstackpos-- + r.runstack[r.Runstackpos] = I1 +} + +func (r *Runner) stackPush2(I1, I2 int) { + r.Runstackpos-- + r.runstack[r.Runstackpos] = I1 + r.Runstackpos-- + r.runstack[r.Runstackpos] = I2 +} + +func (r *Runner) stackPop() { + r.Runstackpos++ +} + +// pop framesize items from the grouping stack +func (r *Runner) stackPopN(framesize int) { + r.Runstackpos += framesize +} + +// Technically we are actually peeking at items already popped. So if you want to +// get and pop the top item from the stack, you do +// r.stackPop(); +// r.stackPeek(); +func (r *Runner) stackPeek() int { + return r.runstack[r.Runstackpos-1] +} + +// get the ith element down on the grouping stack +func (r *Runner) stackPeekN(i int) int { + return r.runstack[r.Runstackpos-i-1] +} + +func (r *Runner) operand(i int) int { + return r.code.Codes[r.codepos+i+1] +} + +func (r *Runner) leftchars() int { + return r.Runtextpos +} + +func (r *Runner) rightchars() int { + return r.Runtextend - r.Runtextpos +} + +func (r *Runner) bump() int { + if r.rightToLeft { + return -1 + } + return 1 +} + +func (r *Runner) forwardchars() int { + if r.rightToLeft { + return r.Runtextpos + } + return r.Runtextend - r.Runtextpos +} + +func (r *Runner) forwardcharnext() rune { + var ch rune + if r.rightToLeft { + r.Runtextpos-- + ch = r.Runtext[r.Runtextpos] + } else { + ch = r.Runtext[r.Runtextpos] + r.Runtextpos++ + } + + // move this to compile time for individual runes + /*if r.caseInsensitive { + return unicode.ToLower(ch) + }*/ + return ch +} + +func (r *Runner) runematch(str []rune) bool { + var pos int + + c := len(str) + if !r.rightToLeft { + if r.Runtextend-r.Runtextpos < c { + return false + } + + pos = r.Runtextpos + c + } else { + if r.Runtextpos-0 < c { + return false + } + + pos = r.Runtextpos + } + + if !r.caseInsensitive { + for c != 0 { + c-- + pos-- + if str[c] != r.Runtext[pos] { + return false + } + } + } else { + for c != 0 { + c-- + pos-- + if str[c] != unicode.ToLower(r.Runtext[pos]) { + return false + } + } + } + + if !r.rightToLeft { + pos += len(str) + } + + r.Runtextpos = pos + + return true +} + +func (r *Runner) refmatch(index, len int) bool { + var c, pos, cmpos int + + if !r.rightToLeft { + if r.Runtextend-r.Runtextpos < len { + return false + } + + pos = r.Runtextpos + len + } else { + if r.Runtextpos-0 < len { + return false + } + + pos = r.Runtextpos + } + cmpos = index + len + + c = len + + if !r.caseInsensitive { + for c != 0 { + c-- + cmpos-- + pos-- + if r.Runtext[cmpos] != r.Runtext[pos] { + return false + } + + } + } else { + for c != 0 { + c-- + cmpos-- + pos-- + + if unicode.ToLower(r.Runtext[cmpos]) != unicode.ToLower(r.Runtext[pos]) { + return false + } + } + } + + if !r.rightToLeft { + pos += len + } + + r.Runtextpos = pos + + return true +} + +func (r *Runner) backwardnext() { + if r.rightToLeft { + r.Runtextpos++ + } else { + r.Runtextpos-- + } +} + +func (r *Runner) charAt(j int) rune { + return r.Runtext[j] +} + +func findFirstCharDefault(r *Runner) bool { + if 0 != (r.code.Anchors & (syntax.AnchorBeginning | syntax.AnchorStart | syntax.AnchorEndZ | syntax.AnchorEnd)) { + if !r.code.RightToLeft { + if (0 != (r.code.Anchors&syntax.AnchorBeginning) && r.Runtextpos > 0) || + (0 != (r.code.Anchors&syntax.AnchorStart) && r.Runtextpos > r.Runtextstart) { + r.Runtextpos = r.Runtextend + return false + } + if 0 != (r.code.Anchors&syntax.AnchorEndZ) && r.Runtextpos < r.Runtextend-1 { + r.Runtextpos = r.Runtextend - 1 + } else if 0 != (r.code.Anchors&syntax.AnchorEnd) && r.Runtextpos < r.Runtextend { + r.Runtextpos = r.Runtextend + } + } else { + if (0 != (r.code.Anchors&syntax.AnchorEnd) && r.Runtextpos < r.Runtextend) || + (0 != (r.code.Anchors&syntax.AnchorEndZ) && (r.Runtextpos < r.Runtextend-1 || + (r.Runtextpos == r.Runtextend-1 && r.charAt(r.Runtextpos) != '\n'))) || + (0 != (r.code.Anchors&syntax.AnchorStart) && r.Runtextpos < r.Runtextstart) { + r.Runtextpos = 0 + return false + } + if 0 != (r.code.Anchors&syntax.AnchorBeginning) && r.Runtextpos > 0 { + r.Runtextpos = 0 + } + } + + if r.code.BmPrefix != nil { + return r.code.BmPrefix.IsMatch(r.Runtext, r.Runtextpos, 0, r.Runtextend) + } + + return true // found a valid start or end anchor + } else if r.code.BmPrefix != nil { + r.Runtextpos = r.code.BmPrefix.Scan(r.Runtext, r.Runtextpos, 0, r.Runtextend) + + if r.Runtextpos == -1 { + if r.code.RightToLeft { + r.Runtextpos = 0 + } else { + r.Runtextpos = r.Runtextend + } + return false + } + + return true + } + + if shouldUseFindFirstCharOptimized(r) { + if handled, found := findFirstCharOptimized(r); handled { + return found + } + } + + if r.code.FcPrefix == nil { + return true + } + + r.rightToLeft = r.code.RightToLeft + r.caseInsensitive = r.code.FcPrefix.CaseInsensitive + + set := r.code.FcPrefix.PrefixSet + if set.IsSingleton() { + ch := set.SingletonChar() + for i := r.forwardchars(); i > 0; i-- { + if ch == r.forwardcharnext() { + r.backwardnext() + return true + } + } + } else { + for i := r.forwardchars(); i > 0; i-- { + n := r.forwardcharnext() + //fmt.Printf("%v in %v: %v\n", string(n), set.String(), set.CharIn(n)) + if set.CharIn(n) { + r.backwardnext() + return true + } + } + } + + return false +} + +func shouldUseFindFirstCharOptimized(r *Runner) bool { + if r.code == nil || r.code.FindOptimizations == nil { + return false + } + + switch r.code.FindOptimizations.FindMode { + case syntax.TrailingAnchor_FixedLength_LeftToRight_End, + syntax.LeadingString_OrdinalIgnoreCase_LeftToRight, + syntax.LeadingStrings_LeftToRight, + syntax.LeadingStrings_OrdinalIgnoreCase_LeftToRight, + syntax.FixedDistanceChar_LeftToRight, + syntax.FixedDistanceString_LeftToRight, + syntax.FixedDistanceSets_LeftToRight, + syntax.LiteralAfterLoop_LeftToRight, + syntax.RequiredLandmarkChain_LeftToRight: + return true + default: + return false + } +} + +func findFirstCharOptimized(r *Runner) (handled bool, found bool) { + if r.code == nil || r.code.FindOptimizations == nil { + return false, false + } + + opts := r.code.FindOptimizations + switch opts.FindMode { + case syntax.NoSearch: + return false, false + case syntax.TrailingAnchor_FixedLength_LeftToRight_End: + return true, findTrailingFixedLengthEnd(r, opts.MinRequiredLength) + case syntax.LeadingString_LeftToRight: + return true, findLeadingStringLeftToRight(r, []rune(opts.LeadingPrefix), false) + case syntax.LeadingString_OrdinalIgnoreCase_LeftToRight: + return true, findLeadingStringLeftToRight(r, []rune(opts.LeadingPrefix), true) + case syntax.LeadingStrings_LeftToRight: + return true, findLeadingStringsLeftToRight(r, opts.LeadingPrefixesRunes, false) + case syntax.LeadingStrings_OrdinalIgnoreCase_LeftToRight: + return true, findLeadingStringsLeftToRight(r, opts.LeadingPrefixesRunes, true) + case syntax.FixedDistanceSets_LeftToRight: + return true, findFixedDistanceSetsLeftToRight(r, opts.FixedDistanceSets) + case syntax.FixedDistanceChar_LeftToRight: + return true, findFixedDistanceCharLeftToRight(r, opts.FixedDistanceLiteral.C, opts.FixedDistanceLiteral.Distance) + case syntax.FixedDistanceString_LeftToRight: + return true, findFixedDistanceStringLeftToRight(r, []rune(opts.FixedDistanceLiteral.S), opts.FixedDistanceLiteral.Distance) + case syntax.LiteralAfterLoop_LeftToRight: + return true, findLiteralAfterLoopLeftToRight(r, opts.LiteralAfterLoop) + case syntax.RequiredLandmarkChain_LeftToRight: + return true, findRequiredLandmarkChainLeftToRight(r, opts.LandmarkChain) + default: + return false, false + } +} + +func findTrailingFixedLengthEnd(r *Runner, fixedLength int) bool { + start := r.Runtextend - fixedLength + if start < r.Runtextpos || start < 0 { + r.Runtextpos = r.Runtextend + return false + } + r.Runtextpos = start + return true +} + +func findLeadingStringLeftToRight(r *Runner, prefix []rune, ignoreCase bool) bool { + if len(prefix) == 0 { + return true + } + + search := r.Runtext[r.Runtextpos:] + var offset int + if ignoreCase { + if isASCIIRunes(prefix) { + offset = helpers.IndexOfIgnoreCaseAscii(search, prefix) + } else { + offset = helpers.IndexOfIgnoreCase(search, prefix) + } + } else { + offset = helpers.IndexOf(search, prefix) + } + if offset < 0 { + r.Runtextpos = r.Runtextend + return false + } + + start := r.Runtextpos + offset + if !hasRequiredLengthAt(r, start) { + r.Runtextpos = r.Runtextend + return false + } + r.Runtextpos = start + return true +} + +func findLeadingStringsLeftToRight(r *Runner, prefixes [][]rune, ignoreCase bool) bool { + if len(prefixes) == 0 { + return false + } + + for start := r.Runtextpos; start <= latestPossibleStart(r); start++ { + for _, prefix := range prefixes { + if ignoreCase { + if helpers.StartsWithIgnoreCase(r.Runtext[start:], prefix) { + r.Runtextpos = start + return true + } + } else if helpers.StartsWith(r.Runtext[start:], prefix) { + r.Runtextpos = start + return true + } + } + } + + r.Runtextpos = r.Runtextend + return false +} + +func findFixedDistanceCharLeftToRight(r *Runner, ch rune, distance int) bool { + searchStart := r.Runtextpos + distance + for searchStart < r.Runtextend { + offset := helpers.IndexOfAny1(r.Runtext[searchStart:], ch) + if offset < 0 { + r.Runtextpos = r.Runtextend + return false + } + literalIndex := searchStart + offset + start := literalIndex - distance + if start >= r.Runtextpos && hasRequiredLengthAt(r, start) { + r.Runtextpos = start + return true + } + if start > latestPossibleStart(r) { + break + } + searchStart = literalIndex + 1 + } + + r.Runtextpos = r.Runtextend + return false +} + +func findFixedDistanceStringLeftToRight(r *Runner, literal []rune, distance int) bool { + if len(literal) == 0 { + return true + } + + searchStart := r.Runtextpos + distance + for searchStart <= r.Runtextend-len(literal) { + offset := helpers.IndexOf(r.Runtext[searchStart:], literal) + if offset < 0 { + r.Runtextpos = r.Runtextend + return false + } + literalIndex := searchStart + offset + start := literalIndex - distance + if start >= r.Runtextpos && hasRequiredLengthAt(r, start) { + r.Runtextpos = start + return true + } + if start > latestPossibleStart(r) { + break + } + searchStart = literalIndex + 1 + } + + r.Runtextpos = r.Runtextend + return false +} + +func findFixedDistanceSetsLeftToRight(r *Runner, sets []syntax.FixedDistanceSet) bool { + if len(sets) == 0 || sets[0].Set == nil { + return false + } + + primary := sets[0] + searchStart := r.Runtextpos + primary.Distance + for searchStart < r.Runtextend { + offset := indexOfSet(r.Runtext[searchStart:], primary) + if offset < 0 { + r.Runtextpos = r.Runtextend + return false + } + + charIndex := searchStart + offset + start := charIndex - primary.Distance + if start > latestPossibleStart(r) { + break + } + if start >= r.Runtextpos && hasRequiredLengthAt(r, start) && fixedDistanceSetsMatchAt(r, sets, start) { + r.Runtextpos = start + return true + } + searchStart = charIndex + 1 + } + + r.Runtextpos = r.Runtextend + return false +} + +func findLiteralAfterLoopLeftToRight(r *Runner, literal *syntax.LiteralAfterLoop) bool { + if literal == nil || literal.LoopNode == nil || literal.LoopNode.Set == nil { + return false + } + + searchStart := r.Runtextpos + for searchStart < r.Runtextend { + literalIndex := indexOfLiteralAfterLoop(r, literal, searchStart) + if literalIndex < 0 { + r.Runtextpos = r.Runtextend + return false + } + + start := literalIndex + for start > r.Runtextpos && literal.LoopNode.Set.CharIn(r.Runtext[start-1]) { + start-- + } + if hasRequiredLengthAt(r, start) { + r.Runtextpos = start + return true + } + searchStart = literalIndex + 1 + } + + r.Runtextpos = r.Runtextend + return false +} + +func findRequiredLandmarkChainLeftToRight(r *Runner, chain *syntax.RequiredLandmarkChain) bool { + if chain == nil || chain.LeadingLoopSet == nil || len(chain.Landmarks) == 0 { + return false + } + + for searchStart := r.Runtextpos; searchStart <= latestPossibleStart(r); { + first, ok := findNextRequiredLandmarkRunes(r.Runtext, searchStart, r.Runtextend, chain.Landmarks[0]) + if !ok { + r.Runtextpos = r.Runtextend + return false + } + + nextStart := first.End + for i := 1; i < len(chain.Landmarks); i++ { + landmark, ok := findNextRequiredLandmarkRunes(r.Runtext, nextStart, r.Runtextend, chain.Landmarks[i]) + if !ok { + r.Runtextpos = r.Runtextend + return false + } + nextStart = landmark.End + } + + candidate := first.Start + if candidate < r.Runtextpos { + candidate = r.Runtextpos + } + for candidate > r.Runtextpos && chain.LeadingLoopSet.CharIn(r.Runtext[candidate-1]) { + candidate-- + } + if hasRequiredLengthAt(r, candidate) { + r.Runtextpos = candidate + return true + } + + searchStart = first.CoreStart + 1 + } + + r.Runtextpos = r.Runtextend + return false +} + +type requiredLandmarkMatch struct { + Start int + CoreStart int + End int +} + +func findNextRequiredLandmarkRunes(input []rune, startAt, endAt int, landmark syntax.RequiredLandmark) (requiredLandmarkMatch, bool) { + for i := startAt; i < endAt; i++ { + for _, alt := range landmark.Alternatives { + if match, ok := requiredLandmarkAlternativeMatch(input, i, endAt, alt); ok { + return match, true + } + } + } + return requiredLandmarkMatch{}, false +} + +func requiredLandmarkAlternativeMatch(input []rune, start, endAt int, alt syntax.RequiredLandmarkAlternative) (requiredLandmarkMatch, bool) { + if alt.RequireWhitespaceBefore && + (start == 0 || alt.LeadingWhitespaceSet == nil || !alt.LeadingWhitespaceSet.CharIn(input[start-1])) { + return requiredLandmarkMatch{}, false + } + + var end int + if len(alt.Literal) > 0 { + if start+len(alt.Literal) > endAt || !helpers.StartsWith(input[start:], alt.Literal) { + return requiredLandmarkMatch{}, false + } + end = start + len(alt.Literal) + } else if alt.Set != nil && alt.MinRepeat > 0 { + end = start + maxRepeat := alt.MaxRepeat + if maxRepeat <= 0 { + maxRepeat = alt.MinRepeat + } + for end < endAt && end-start < maxRepeat && alt.Set.CharIn(input[end]) { + end++ + } + if end-start < alt.MinRepeat { + return requiredLandmarkMatch{}, false + } + } else { + return requiredLandmarkMatch{}, false + } + + if alt.RequireWhitespaceAfter && + (end >= endAt || alt.TrailingWhitespaceSet == nil || !alt.TrailingWhitespaceSet.CharIn(input[end])) { + return requiredLandmarkMatch{}, false + } + + matchStart := start + for matchStart > 0 && alt.LeadingWhitespaceSet != nil && alt.LeadingWhitespaceSet.CharIn(input[matchStart-1]) { + matchStart-- + } + return requiredLandmarkMatch{Start: matchStart, CoreStart: start, End: end}, true +} + +func indexOfLiteralAfterLoop(r *Runner, literal *syntax.LiteralAfterLoop, searchStart int) int { + switch { + case literal.String != "": + needle := []rune(literal.String) + if literal.StringIgnoreCase { + var offset int + if isASCIIString(literal.String) { + offset = helpers.IndexOfIgnoreCaseAscii(r.Runtext[searchStart:], needle) + } else { + offset = helpers.IndexOfIgnoreCase(r.Runtext[searchStart:], needle) + } + if offset >= 0 { + return searchStart + offset + } + } else if offset := helpers.IndexOf(r.Runtext[searchStart:], needle); offset >= 0 { + return searchStart + offset + } + case len(literal.Chars) > 0: + if offset := helpers.IndexOfAny(r.Runtext[searchStart:], literal.Chars); offset >= 0 { + return searchStart + offset + } + default: + if offset := helpers.IndexOfAny1(r.Runtext[searchStart:], literal.Char); offset >= 0 { + return searchStart + offset + } + } + return -1 +} + +func isASCIIRunes(in []rune) bool { + for _, ch := range in { + if ch > unicode.MaxASCII { + return false + } + } + return true +} + +func indexOfSet(chars []rune, set syntax.FixedDistanceSet) int { + if len(set.Chars) > 0 && !set.Negated { + return helpers.IndexOfAny(chars, set.Chars) + } + if len(set.Chars) > 0 && set.Negated { + return helpers.IndexOfAnyExcept(chars, set.Chars) + } + if set.Range != nil { + if set.Negated { + return helpers.IndexOfAnyExceptInRange(chars, set.Range.First, set.Range.Last) + } + return helpers.IndexOfAnyInRange(chars, set.Range.First, set.Range.Last) + } + return helpers.IndexFunc(chars, func(ch rune) bool { + return charInFixedDistanceSet(set, ch) + }) +} + +func fixedDistanceSetsMatchAt(r *Runner, sets []syntax.FixedDistanceSet, start int) bool { + for _, set := range sets { + index := start + set.Distance + if index < 0 || index >= r.Runtextend || !charInFixedDistanceSet(set, r.Runtext[index]) { + return false + } + } + return true +} + +func charInFixedDistanceSet(set syntax.FixedDistanceSet, ch rune) bool { + if len(set.Chars) > 0 { + found := slices.Contains(set.Chars, ch) + if set.Negated { + return !found + } + return found + } + if set.Range != nil { + found := ch >= set.Range.First && ch <= set.Range.Last + if set.Negated { + return !found + } + return found + } + return set.Set != nil && set.Set.CharIn(ch) +} + +func latestPossibleStart(r *Runner) int { + if r.code == nil || r.code.FindOptimizations == nil { + return r.Runtextend + } + minRequiredLength := r.code.FindOptimizations.MinRequiredLength + if minRequiredLength <= 0 { + return r.Runtextend + } + return r.Runtextend - minRequiredLength +} + +func hasRequiredLengthAt(r *Runner, start int) bool { + return start >= 0 && start <= latestPossibleStart(r) +} + +func (r *Runner) initMatch(textInfo *matchText) { + // Use a hashtable'ed Match object if the capture numbers are sparse + + if r.runmatch == nil { + if r.re.caps != nil { + r.runmatch = newMatchSparse(r.re, r.re.caps, r.re.capsize, textInfo, r.Runtextstart) + } else { + r.runmatch = newMatch(r.re, r.re.capsize, textInfo, r.Runtextstart) + } + } else { + r.runmatch.reset(textInfo, r.Runtextstart) + } + + // note we test runcrawl, because it is the last one to be allocated + // If there is an alloc failure in the middle of the three allocations, + // we may still return to reuse this instance, and we want to behave + // as if the allocations didn't occur. (we used to test _trackcount != 0) + + if r.runcrawl != nil { + r.Runtrackpos = len(r.runtrack) + r.Runstackpos = len(r.runstack) + r.runcrawlpos = len(r.runcrawl) + return + } + + r.initTrackCount() + + tracksize := r.runtrackcount * 8 + stacksize := r.runtrackcount * 8 + + if tracksize < 64 { + tracksize = 64 + } + if stacksize < 32 { + stacksize = 32 + } + + r.runtrack = make([]int, tracksize) + r.Runtrackpos = tracksize + + r.runstack = make([]int, stacksize) + r.Runstackpos = stacksize + + r.runcrawl = make([]int, 32) + r.runcrawlpos = 32 +} + +func (r *Runner) tidyMatch(quick bool) *Match { + if !quick { + match := r.runmatch + + r.runmatch = nil + + match.tidy(r.Runtextpos) + return match + } else { + // send back our match -- it's not leaving the package, so it's safe to not clean it up + // this reduces allocs for frequent calls to the "IsMatch" bool-only functions + m := r.runmatch + if m == nil { + return nil + } + m.textpos = r.Runtextpos + if m.matchcount[0] > 0 { + interval := m.matches[0] + // bytes indices aren't used so just use fast path + m.RuneIndex = interval[0] + m.RuneLength = interval[1] + } + return m + } +} + +// Capture captures a subexpression. Note that the +// capnum used here has already been mapped to a non-sparse +// index (by the code generator RegexWriter). +func (r *Runner) Capture(capnum, start, end int) { + if end < start { + T := end + end = start + start = T + } + + r.crawl(capnum) + r.runmatch.addMatch(capnum, start, end-start) +} + +// transferCapture captures a subexpression. Note that the +// capnum used here has already been mapped to a non-sparse +// index (by the code generator RegexWriter). +func (r *Runner) transferCapture(capnum, uncapnum, start, end int) { + var start2, end2 int + + // these are the two intervals that are cancelling each other + + if end < start { + T := end + end = start + start = T + } + + start2 = r.runmatch.matchIndex(uncapnum) + end2 = start2 + r.runmatch.matchLength(uncapnum) + + // The new capture gets the innermost defined interval + + if start >= end2 { + end = start + start = end2 + } else if end <= start2 { + start = start2 + } else { + if end > end2 { + end = end2 + } + if start2 > start { + start = start2 + } + } + + r.crawl(uncapnum) + r.runmatch.balanceMatch(uncapnum) + + if capnum != -1 { + r.crawl(capnum) + r.runmatch.addMatch(capnum, start, end-start) + } +} + +// revert the last capture +func (r *Runner) uncapture() { + capnum := r.popcrawl() + r.runmatch.removeMatch(capnum) +} + +//debug + +func (r *Runner) dumpState() { + back := "" + if r.operator&syntax.Back != 0 { + back = " Back" + } + if r.operator&syntax.Back2 != 0 { + back += " Back2" + } + fmt.Printf("Text: %v\nTrack: %v\nStack: %v\n %s%s\n\n", + r.textposDescription(), + r.stackDescription(r.runtrack, r.Runtrackpos), + r.stackDescription(r.runstack, r.Runstackpos), + r.code.OpcodeDescription(r.codepos), + back) +} + +func (r *Runner) stackDescription(a []int, index int) string { + buf := &bytes.Buffer{} + + fmt.Fprintf(buf, "%v/%v", len(a)-index, len(a)) + if buf.Len() < 8 { + buf.WriteString(strings.Repeat(" ", 8-buf.Len())) + } + + buf.WriteRune('(') + for i := index; i < len(a); i++ { + if i > index { + buf.WriteRune(' ') + } + + buf.WriteString(strconv.Itoa(a[i])) + } + + buf.WriteRune(')') + + return buf.String() +} + +func (r *Runner) textposDescription() string { + buf := &bytes.Buffer{} + + buf.WriteString(strconv.Itoa(r.Runtextpos)) + + if buf.Len() < 8 { + buf.WriteString(strings.Repeat(" ", 8-buf.Len())) + } + + if r.Runtextpos > 0 { + buf.WriteString(syntax.CharDescription(r.Runtext[r.Runtextpos-1])) + } else { + buf.WriteRune('^') + } + + buf.WriteRune('>') + + for i := r.Runtextpos; i < r.Runtextend; i++ { + buf.WriteString(syntax.CharDescription(r.Runtext[i])) + } + if buf.Len() >= 64 { + buf.Truncate(61) + buf.WriteString("...") + } else { + buf.WriteRune('$') + } + + return buf.String() +} + +// decide whether the pos +// at the specified index is a boundary or not. It's just not worth +// emitting inline code for this logic. +func (r *Runner) IsBoundary(index int) bool { + return (index > 0 && syntax.IsWordChar(r.Runtext[index-1])) != + (index < r.Runtextend && syntax.IsWordChar(r.Runtext[index])) +} + +func (r *Runner) IsECMABoundary(index int) bool { + return (index > 0 && syntax.IsECMAWordChar(r.Runtext[index-1])) != + (index < r.Runtextend && syntax.IsECMAWordChar(r.Runtext[index])) +} + +func (r *Runner) startTimeoutWatch() { + if r.ignoreTimeout { + return + } + r.deadline = makeDeadline(r.timeout) +} + +func (r *Runner) CheckTimeout() error { + if r.ignoreTimeout || !r.deadline.reached() { + return nil + } + + return fmt.Errorf("match timeout after %v on input `%v`", r.timeout, string(r.Runtext)) +} + +func (r *Runner) initTrackCount() { + if r.code != nil { + r.runtrackcount = r.code.TrackCount + } +} + +// decodeString converts s to []rune using a shared size-classed buffer pool when +// allowed by the regexp optimization settings. Pooled slices must be returned +// after the runner is done with them. +func (r *Runner) decodeString(s string) ([]rune, *[]rune) { + buf, pooled := pooledRuneBuffers.get(len(s), r.re.optimizations.MaxCachedRuneBufferLength) + n := 0 + for _, ch := range s { + buf[n] = ch + n++ + } + return buf[:n], pooled +} + +func (r *Runner) decodeStringWithStart(s string, startAt int) (runes []rune, runeStart int, pooled *[]rune) { + buf, pooled := pooledRuneBuffers.get(len(s), r.re.optimizations.MaxCachedRuneBufferLength) + n := 0 + runeStart = -1 + for strIdx, ch := range s { + if startAt >= 0 && strIdx == startAt { + runeStart = n + } + buf[n] = ch + n++ + } + if startAt >= 0 && startAt == len(s) { + runeStart = n + } + return buf[:n], runeStart, pooled +} + +// getRunner returns a runner to use for matching re. +func (re *Regexp) getRunner() *Runner { + if re.runnerPool == nil { + re.initCaches() + } + return re.runnerPool.Get().(*Runner) +} + +// putRunner returns a runner to the re's pool cache. +func (re *Regexp) putRunner(r *Runner) { + r.Runtext = nil + if r.runmatch != nil { + r.runmatch.text = nil + } + re.runnerPool.Put(r) +} + +func (r *Runner) LastIndexOfRune(startIndex int, endIndex int, find rune) int { + for i := endIndex - 1; i >= startIndex; i-- { + if r.Runtext[i] == find { + return i + } + } + return -1 +} + +// Undo captures until it reaches the specified capture position +func (r *Runner) UncaptureUntil(capturePos int) { + for r.Crawlpos() > capturePos { + r.uncapture() + } +} + +func (r *Runner) StackPop() int { + //get it + val := r.runstack[r.Runstackpos] + // pop it + r.Runstackpos++ + // return it + return val +} + +func (r *Runner) StackPush(val int) { + // check if we need to size up stack + r.ensureStack(1) + r.Runstackpos-- + r.runstack[r.Runstackpos] = val +} +func (r *Runner) StackPush2(val1, val2 int) { + // check if we need to size up stack + r.ensureStack(2) + r.Runstackpos-- + r.runstack[r.Runstackpos] = val1 + r.Runstackpos-- + r.runstack[r.Runstackpos] = val2 +} +func (r *Runner) StackPush3(val1, val2, val3 int) { + // check if we need to size up stack + r.ensureStack(3) + r.Runstackpos-- + r.runstack[r.Runstackpos] = val1 + r.Runstackpos-- + r.runstack[r.Runstackpos] = val2 + r.Runstackpos-- + r.runstack[r.Runstackpos] = val3 +} +func (r *Runner) StackPush4(val1, val2, val3, val4 int) { + // check if we need to size up stack + r.ensureStack(4) + r.Runstackpos-- + r.runstack[r.Runstackpos] = val1 + r.Runstackpos-- + r.runstack[r.Runstackpos] = val2 + r.Runstackpos-- + r.runstack[r.Runstackpos] = val3 + r.Runstackpos-- + r.runstack[r.Runstackpos] = val4 +} +func (r *Runner) StackPush5(val1, val2, val3, val4, val5 int) { + // check if we need to size up stack + r.ensureStack(5) + r.Runstackpos-- + r.runstack[r.Runstackpos] = val1 + r.Runstackpos-- + r.runstack[r.Runstackpos] = val2 + r.Runstackpos-- + r.runstack[r.Runstackpos] = val3 + r.Runstackpos-- + r.runstack[r.Runstackpos] = val4 + r.Runstackpos-- + r.runstack[r.Runstackpos] = val5 +} +func (r *Runner) StackPushN(vals ...int) { + // check if we need to size up stack + r.ensureStack(len(vals)) + for _, val := range vals { + r.Runstackpos-- + r.runstack[r.Runstackpos] = val + } +} +func (r *Runner) IsMatched(cap int) bool { + return r.runmatch.isMatched(cap) +} +func (r *Runner) MatchLength(cap int) int { + return r.runmatch.matchLength(cap) +} +func (r *Runner) MatchIndex(cap int) int { + return r.runmatch.matchIndex(cap) +} diff --git a/vendor/github.com/dlclark/regexp2/v2/split.go b/vendor/github.com/dlclark/regexp2/v2/split.go new file mode 100644 index 000000000..1dbe0dcd1 --- /dev/null +++ b/vendor/github.com/dlclark/regexp2/v2/split.go @@ -0,0 +1,67 @@ +package regexp2 + +import ( + "errors" + "math" +) + +// Split splits the given input string using the pattern and returns +// a slice of the parts. Count limits the number of matches to process. +// If Count is -1, then it will process the input fully. +// If Count is 0, returns nil. If Count is 1, returns the original input. +// The only expected error is a Timeout, if it's set. +// +// If capturing parentheses are used in the Regex expression, any captured +// text is included in the resulting string array +// For example, a pattern of "-" Split("a-b") will return ["a", "b"] +// but a pattern with "(-)" Split ("a-b") will return ["a", "-", "b"] +func (re *Regexp) Split(input string, count int) ([]string, error) { + if count < -1 { + return nil, errors.New("count too small") + } + if count == 0 { + return nil, nil + } + if count == 1 { + return []string{input}, nil + } + if count == -1 { + // no limit + count = math.MaxInt + } + + // iterate through the matches + priorIndex := 0 + var retVal []string + var txt []rune + + m, err := re.FindStringMatch(input) + + for ; m != nil && count > 0; m, err = re.FindNextMatch(m) { + txt = m.text.runes + // if we have an m, we don't have an err + // append our match + retVal = append(retVal, string(txt[priorIndex:m.RuneIndex])) + // append any capture groups, skipping group 0 + gs := m.Groups() + for i := 1; i < len(gs); i++ { + retVal = append(retVal, gs[i].String()) + } + priorIndex = m.RuneIndex + m.RuneLength + count-- + } + + if err != nil { + return nil, err + } + + if txt == nil { + // we never matched, return the original string + return []string{input}, nil + } + + // append our remainder + retVal = append(retVal, string(txt[priorIndex:])) + + return retVal, nil +} diff --git a/vendor/github.com/dlclark/regexp2/v2/stringprefixfilter.go b/vendor/github.com/dlclark/regexp2/v2/stringprefixfilter.go new file mode 100644 index 000000000..fe9cb6ad7 --- /dev/null +++ b/vendor/github.com/dlclark/regexp2/v2/stringprefixfilter.go @@ -0,0 +1,375 @@ +package regexp2 + +import ( + "errors" + "strings" + "unicode/utf8" + + "github.com/dlclark/regexp2/v2/helpers" + "github.com/dlclark/regexp2/v2/syntax" +) + +const maxStringFilterLiteralLen = 8 + +var ( + errStringStartAtTooLarge = errors.New("startAt must be less than the length of the input string") + errStringStartAtNotRuneBoundary = errors.New("startAt must align to the start of a valid rune in the input string") +) + +// StringPrefixFilter optionally searches string input before the engine decodes it +// to runes. It returns a byte index for a candidate match start, or ok=false if +// the regex cannot match. The filter must be conservative: false positives are +// allowed, false negatives are not. +type StringPrefixFilter func(input string, startAt int) (candidateByteIndex int, ok bool) + +func newStringPrefixFilter(code *syntax.Code) StringPrefixFilter { + if code == nil || code.RightToLeft || code.FindOptimizations == nil { + return nil + } + + opts := code.FindOptimizations + minRequiredLength := opts.MinRequiredLength + + switch opts.FindMode { + case syntax.LeadingString_LeftToRight: + return stringIndexPrefixFilter(opts.LeadingPrefix, false, minRequiredLength) + case syntax.LeadingString_OrdinalIgnoreCase_LeftToRight: + return stringIndexPrefixFilter(opts.LeadingPrefix, true, minRequiredLength) + case syntax.LeadingStrings_LeftToRight: + return stringIndexPrefixesFilter(opts.LeadingPrefixes, false, minRequiredLength) + case syntax.LeadingStrings_OrdinalIgnoreCase_LeftToRight: + return stringIndexPrefixesFilter(opts.LeadingPrefixes, true, minRequiredLength) + case syntax.FixedDistanceChar_LeftToRight: + return stringFixedDistanceCharFilter(opts.FixedDistanceLiteral.C, opts.FixedDistanceLiteral.Distance, minRequiredLength) + case syntax.FixedDistanceString_LeftToRight: + return stringFixedDistanceStringFilter(opts.FixedDistanceLiteral.S, opts.FixedDistanceLiteral.Distance, minRequiredLength) + case syntax.LiteralAfterLoop_LeftToRight: + return stringLiteralAfterLoopFilter(opts.LiteralAfterLoop, minRequiredLength) + default: + return nil + } +} + +func stringIndexPrefixFilter(prefix string, ignoreCase bool, minRequiredLength int) StringPrefixFilter { + if prefix == "" { + return nil + } + if ignoreCase && !isASCIIString(prefix) { + return nil + } + + return func(input string, startAt int) (candidateByteIndex int, ok bool) { + if !hasMinRequiredBytes(input, startAt, minRequiredLength) { + return 0, false + } + + var offset int + if ignoreCase { + offset = helpers.IndexStringIgnoreCaseASCII(input[startAt:], prefix) + } else { + offset = strings.Index(input[startAt:], prefix) + } + if offset < 0 { + return 0, false + } + return startAt + offset, true + } +} + +func stringIndexPrefixesFilter(prefixes []string, ignoreCase bool, minRequiredLength int) StringPrefixFilter { + if len(prefixes) == 0 { + return nil + } + if ignoreCase { + for _, prefix := range prefixes { + if !isASCIIString(prefix) { + return nil + } + } + } + + if filter, ok := compileASCIIStringSetPrefixFilter(prefixes, ignoreCase, minRequiredLength); ok { + return filter.index + } + + return func(input string, startAt int) (candidateByteIndex int, ok bool) { + return indexAnyPrefixFallback(input, startAt, prefixes, ignoreCase, minRequiredLength) + } +} + +func indexAnyPrefixFallback(input string, startAt int, prefixes []string, ignoreCase bool, minRequiredLength int) (candidateByteIndex int, ok bool) { + if !hasMinRequiredBytes(input, startAt, minRequiredLength) { + return 0, false + } + + best := -1 + remaining := input[startAt:] + for _, prefix := range prefixes { + var offset int + if ignoreCase { + offset = helpers.IndexStringIgnoreCaseASCII(remaining, prefix) + } else { + offset = strings.Index(remaining, prefix) + } + if offset >= 0 && (best < 0 || offset < best) { + best = offset + } + } + if best < 0 { + return 0, false + } + return startAt + best, true +} + +type asciiStringSetPrefixFilter struct { + firstChars string + prefixesByFirst [256][]string + minRequiredBytes int +} + +// compileASCIIStringSetPrefixFilter builds a byte-oriented multi-prefix scanner +// for the narrow shape where it beats running strings.Index once per prefix: +// case-sensitive ASCII prefixes with at least two prefixes sharing a first byte. +// It indexes possible first bytes with strings.IndexAny, then verifies only the +// bucket for the byte found. Other shapes fall back to the old implementation. +func compileASCIIStringSetPrefixFilter(prefixes []string, ignoreCase bool, minRequiredLength int) (*asciiStringSetPrefixFilter, bool) { + if ignoreCase { + return nil, false + } + + filter := &asciiStringSetPrefixFilter{ + minRequiredBytes: minRequiredLength, + } + var firstChars [256]bool + var hasSharedFirst bool + for _, prefix := range prefixes { + if prefix == "" || !isASCIIString(prefix) { + return nil, false + } + + first := prefix[0] + filter.prefixesByFirst[first] = append(filter.prefixesByFirst[first], prefix) + if len(filter.prefixesByFirst[first]) > 1 { + hasSharedFirst = true + } + firstChars[first] = true + } + + if !hasSharedFirst { + return nil, false + } + + firstBytes := make([]byte, 0, len(prefixes)*2) + for i, ok := range firstChars { + if ok { + firstBytes = append(firstBytes, byte(i)) + } + } + if len(firstBytes) == 0 { + return nil, false + } + filter.firstChars = string(firstBytes) + return filter, true +} + +func (f *asciiStringSetPrefixFilter) index(input string, startAt int) (candidateByteIndex int, ok bool) { + if !hasMinRequiredBytes(input, startAt, f.minRequiredBytes) { + return 0, false + } + + for searchAt := startAt; searchAt < len(input); { + offset := strings.IndexAny(input[searchAt:], f.firstChars) + if offset < 0 { + return 0, false + } + i := searchAt + offset + first := input[i] + for _, prefix := range f.prefixesByFirst[first] { + if len(input)-i >= len(prefix) && strings.HasPrefix(input[i:], prefix) { + return i, true + } + } + searchAt = i + 1 + } + return 0, false +} + +func stringFixedDistanceCharFilter(ch rune, distance, minRequiredLength int) StringPrefixFilter { + if distance < 0 { + return nil + } + + return func(input string, startAt int) (candidateByteIndex int, ok bool) { + if !hasMinRequiredBytes(input, startAt, minRequiredLength) { + return 0, false + } + + searchAt := startAt + for { + offset := strings.IndexRune(input[searchAt:], ch) + if offset < 0 { + return 0, false + } + byteIndex := searchAt + offset + candidateByteIndex, ok := stringFixedDistanceCandidateStart(input, startAt, byteIndex, distance) + if ok && hasMinRequiredBytes(input, candidateByteIndex, minRequiredLength) { + return candidateByteIndex, true + } + if ok { + return 0, false + } + _, size := utf8.DecodeRuneInString(input[byteIndex:]) + if size == 0 { + return 0, false + } + searchAt = byteIndex + size + } + } +} + +func stringFixedDistanceStringFilter(literal string, distance, minRequiredLength int) StringPrefixFilter { + if literal == "" || distance < 0 || len(literal) > maxStringFilterLiteralLen { + return nil + } + + return func(input string, startAt int) (candidateByteIndex int, ok bool) { + if !hasMinRequiredBytes(input, startAt, minRequiredLength) { + return 0, false + } + + searchAt := startAt + for searchAt <= len(input)-len(literal) { + offset := strings.Index(input[searchAt:], literal) + if offset < 0 { + return 0, false + } + literalIndex := searchAt + offset + candidateByteIndex, ok := stringFixedDistanceCandidateStart(input, startAt, literalIndex, distance) + if ok && hasMinRequiredBytes(input, candidateByteIndex, minRequiredLength) { + return candidateByteIndex, true + } + if ok { + return 0, false + } + searchAt = literalIndex + 1 + } + return 0, false + } +} + +func stringLiteralAfterLoopFilter(literal *syntax.LiteralAfterLoop, minRequiredLength int) StringPrefixFilter { + if literal == nil || literal.LoopNode == nil || literal.LoopNode.Set == nil { + return nil + } + if literal.StringIgnoreCase && (literal.String == "" || !isASCIIString(literal.String)) { + return nil + } + + return func(input string, startAt int) (candidateByteIndex int, ok bool) { + if !hasMinRequiredBytes(input, startAt, minRequiredLength) { + return 0, false + } + if !stringHasLiteralAfterLoop(input, startAt, literal) { + return 0, false + } + return startAt, true + } +} + +func stringHasLiteralAfterLoop(input string, searchAt int, literal *syntax.LiteralAfterLoop) bool { + switch { + case literal.String != "": + if literal.StringIgnoreCase { + return helpers.IndexStringIgnoreCaseASCII(input[searchAt:], literal.String) >= 0 + } + return strings.Contains(input[searchAt:], literal.String) + case len(literal.Chars) > 0: + needle := string(literal.Chars) + return strings.ContainsAny(input[searchAt:], needle) + default: + return strings.ContainsRune(input[searchAt:], literal.Char) + } +} + +func stringFixedDistanceCandidateStart(input string, startAt, byteIndex, distance int) (int, bool) { + candidateByteIndex := byteIndex + for i := 0; i < distance; i++ { + if candidateByteIndex <= startAt { + return 0, false + } + _, size := utf8.DecodeLastRuneInString(input[:candidateByteIndex]) + if size == 0 { + return 0, false + } + candidateByteIndex -= size + } + return candidateByteIndex, true +} + +func (re *Regexp) findStringPrefixCandidate(input string, startAt int) (candidateByteIndex int, ok bool) { + if re.stringPrefixFilter == nil || re.RightToLeft() { + return startAt, true + } + candidateByteIndex, ok = re.stringPrefixFilter(input, startAt) + if !ok { + return 0, false + } + if candidateByteIndex < startAt || candidateByteIndex > len(input) || !isStringRuneBoundary(input, candidateByteIndex) { + return startAt, true + } + return candidateByteIndex, true +} + +func (re *Regexp) findStringMatchStart(input string, startAt int) (candidateByteIndex int, ok bool, err error) { + if startAt > len(input) { + return 0, false, errStringStartAtTooLarge + } + if startAt >= 0 && !isStringRuneBoundary(input, startAt) { + return 0, false, errStringStartAtNotRuneBoundary + } + + if startAt < 0 { + if re.RightToLeft() { + startAt = len(input) + } else { + startAt = 0 + } + } + + candidateByteIndex, ok = re.findStringPrefixCandidate(input, startAt) + return candidateByteIndex, ok, nil +} + +func hasMinRequiredBytes(input string, startAt, minRequiredLength int) bool { + if startAt < 0 || startAt > len(input) { + return false + } + return minRequiredLength <= 0 || len(input)-startAt >= minRequiredLength +} + +func isStringRuneBoundary(s string, index int) bool { + if index == 0 || index == len(s) { + return true + } + if index < 0 || index > len(s) { + return false + } + for strIdx := range s { + if strIdx == index { + return true + } + if strIdx > index { + return false + } + } + return false +} + +func isASCIIString(s string) bool { + for i := 0; i < len(s); i++ { + if s[i] >= utf8.RuneSelf { + return false + } + } + return true +} diff --git a/vendor/github.com/dlclark/regexp2/v2/syntax/charclass.go b/vendor/github.com/dlclark/regexp2/v2/syntax/charclass.go new file mode 100644 index 000000000..b00fc9ad8 --- /dev/null +++ b/vendor/github.com/dlclark/regexp2/v2/syntax/charclass.go @@ -0,0 +1,1493 @@ +package syntax + +import ( + "bytes" + "encoding/binary" + "fmt" + "slices" + "sort" + "strings" + "unicode" + "unicode/utf8" +) + +// CharSet combines start-end rune ranges and unicode categories representing a set of characters +type CharSet struct { + ranges []SingleRange + categories []Category + sub *CharSet //optional subtractor + negate bool + anything bool + + ascii *asciiBitmap +} + +type asciiBitmap struct { + bits [2]uint64 +} + +type Category struct { + Negate bool + Cat string +} + +type SingleRange struct { + First rune + Last rune +} + +const ( + SpaceCategoryText = " " + WordCategoryText = "W" +) + +var ( + ecmaSpace = []rune{0x0009, 0x000e, 0x0020, 0x0021, 0x00a0, 0x00a1, 0x1680, 0x1681, 0x2000, 0x200b, 0x2028, 0x202a, 0x202f, 0x2030, 0x205f, 0x2060, 0x3000, 0x3001, 0xfeff, 0xff00} + ecmaWord = []rune{0x0030, 0x003a, 0x0041, 0x005b, 0x005f, 0x0060, 0x0061, 0x007b} + ecmaDigit = []rune{0x0030, 0x003a} + + re2Space = []rune{0x0009, 0x000b, 0x000c, 0x000e, 0x0020, 0x0021} +) + +var ( + AnyClass = getCharSetFromOldString([]rune{0}, false) + ECMAAnyClass = getCharSetFromOldString([]rune{0, 0x000a, 0x000b, 0x000d, 0x000e}, false) + NoneClass = getCharSetFromOldString(nil, false) + ECMAWordClass = getCharSetFromOldString(ecmaWord, false) + NotECMAWordClass = getCharSetFromOldString(ecmaWord, true) + ECMASpaceClass = getCharSetFromOldString(ecmaSpace, false) + NotECMASpaceClass = getCharSetFromOldString(ecmaSpace, true) + ECMADigitClass = getCharSetFromOldString(ecmaDigit, false) + NotECMADigitClass = getCharSetFromOldString(ecmaDigit, true) + + WordClass = getCharSetFromCategoryString(false, false, WordCategoryText) + NotWordClass = getCharSetFromCategoryString(true, false, WordCategoryText) + SpaceClass = getCharSetFromCategoryString(false, false, SpaceCategoryText) + NotSpaceClass = getCharSetFromCategoryString(true, false, SpaceCategoryText) + DigitClass = getCharSetFromCategoryString(false, false, "Nd") + NotDigitClass = getCharSetFromCategoryString(false, true, "Nd") + + RE2SpaceClass = getCharSetFromOldString(re2Space, false) + NotRE2SpaceClass = getCharSetFromOldString(re2Space, true) + + NotNewLineClass = getCharSetFromOldString([]rune{0x0a, 0x0b}, true) +) + +var unicodeCategories = func() map[string]*unicode.RangeTable { + retVal := make(map[string]*unicode.RangeTable) + for k, v := range unicode.Scripts { + retVal[k] = v + } + for k, v := range unicode.Categories { + retVal[k] = v + } + // aliases are just pointers to the original keys + for k, v := range unicode.CategoryAliases { + retVal[k] = unicode.Categories[v] + } + for k, v := range unicode.Properties { + retVal[k] = v + } + for k, v := range unicodeAliasCategories { + retVal[k] = v + } + return retVal +}() + +func getCharSetFromCategoryString(negateSet bool, negateCat bool, cats ...string) func() *CharSet { + if negateCat && negateSet { + panic("BUG! You should only negate the set OR the category in a constant setup, but not both") + } + + c := CharSet{negate: negateSet} + + c.categories = make([]Category, len(cats)) + for i, cat := range cats { + c.categories[i] = Category{Cat: cat, Negate: negateCat} + } + return func() *CharSet { + //make a copy each time + local := c + //return that address + return &local + } +} + +func getCharSetFromOldString(setText []rune, negate bool) func() *CharSet { + c := CharSet{} + if len(setText) > 0 { + fillFirst := false + l := len(setText) + if negate { + if setText[0] == 0 { + setText = setText[1:] + } else { + l++ + fillFirst = true + } + } + + if l%2 == 0 { + c.ranges = make([]SingleRange, l/2) + } else { + c.ranges = make([]SingleRange, l/2+1) + } + + first := true + if fillFirst { + c.ranges[0] = SingleRange{First: 0} + first = false + } + + i := 0 + for _, r := range setText { + if first { + // lower bound in a new range + c.ranges[i] = SingleRange{First: r} + first = false + } else { + c.ranges[i].Last = r - 1 + i++ + first = true + } + } + if !first { + c.ranges[i].Last = utf8.MaxRune + } + if len(c.ranges) == 1 && c.ranges[0].First == 0 && c.ranges[0].Last >= unicode.MaxRune { + // this is anything...or nothing + c.anything = !negate + } + } + + return func() *CharSet { + local := c + return &local + } +} + +// Copy makes a deep copy to prevent accidental mutation of a set +func (c CharSet) Copy() CharSet { + ret := CharSet{ + anything: c.anything, + negate: c.negate, + } + + ret.ranges = append(ret.ranges, c.ranges...) + ret.categories = append(ret.categories, c.categories...) + + if c.sub != nil { + sub := c.sub.Copy() + ret.sub = &sub + } + + return ret +} + +// gets a human-readable description for a set string +func (c CharSet) String() string { + buf := &bytes.Buffer{} + buf.WriteRune('[') + + if c.IsNegated() { + buf.WriteRune('^') + } + + for _, r := range c.ranges { + + buf.WriteString(CharDescription(r.First)) + if r.First != r.Last { + if r.Last-r.First != 1 { + //groups that are 1 char apart skip the dash + buf.WriteRune('-') + } + buf.WriteString(CharDescription(r.Last)) + } + } + + for _, c := range c.categories { + buf.WriteString(c.String()) + } + + if c.sub != nil { + buf.WriteRune('-') + buf.WriteString(c.sub.String()) + } + + buf.WriteRune(']') + + return buf.String() +} + +func b2i(b bool) byte { + if b { + return 1 + } + return 0 +} + +// mapHashFill converts a charset into a buffer for use in maps +func (c CharSet) mapHashFill(buf *bytes.Buffer) { + buf.WriteByte(b2i(c.negate) + b2i(c.anything)*2) + + _ = binary.Write(buf, binary.LittleEndian, int32(len(c.ranges))) + _ = binary.Write(buf, binary.LittleEndian, int32(len(c.categories))) + for _, r := range c.ranges { + buf.WriteRune(r.First) + buf.WriteRune(r.Last) + } + for _, ct := range c.categories { + // write the length of the cat and indicate if it's negated + if ct.Negate { + _ = binary.Write(buf, binary.LittleEndian, int8(-1*len(ct.Cat))) + } else { + _ = binary.Write(buf, binary.LittleEndian, int8(len(ct.Cat))) + } + buf.WriteString(ct.Cat) + } + + if c.sub != nil { + c.sub.mapHashFill(buf) + } +} + +func NewCharSetRuntime(buf string) CharSet { + retVal := CharSet{} + b := bytes.NewBufferString(buf) + val, _ := b.ReadByte() + //1s bit == negate, 2s bit == anything + retVal.negate = (val&0x1 == 0x1) + retVal.anything = (val&0x2 == 0x2) + var lenRanges, lenCats int32 + _ = binary.Read(b, binary.LittleEndian, &lenRanges) + _ = binary.Read(b, binary.LittleEndian, &lenCats) + + retVal.ranges = make([]SingleRange, lenRanges) + for i := 0; i < int(lenRanges); i++ { + r := SingleRange{} + r.First, _, _ = b.ReadRune() + r.Last, _, _ = b.ReadRune() + retVal.ranges[i] = r + } + + retVal.categories = make([]Category, lenCats) + for i := 0; i < int(lenCats); i++ { + var lenCat int8 + c := Category{} + _ = binary.Read(b, binary.LittleEndian, &lenCat) + if lenCat < 0 { + c.Negate = true + lenCat *= -1 + } + c.Cat = string(b.Next(int(lenCat))) + retVal.categories[i] = c + } + + //sub + if b.Len() > 0 { + sub := NewCharSetRuntime(b.String()) + retVal.sub = &sub + } + + return retVal +} + +// CharIn returns true if the rune is in our character set (either ranges or categories). +// It handles negations and subtracted sub-charsets. +func (c CharSet) CharIn(ch rune) bool { + if ch >= 0 && ch < 128 && c.ascii != nil { + return (c.ascii.bits[ch/64] & (1 << (uint(ch) % 64))) != 0 + } + return c.charInSlow(ch) +} + +func (c CharSet) charInSlow(ch rune) bool { + val := false + // in s && !s.subtracted + + //check ranges -- binary search for sets with many ranges, linear for small sets + n := len(c.ranges) + if n > 0 { + if n <= 4 { + for _, r := range c.ranges { + if ch < r.First { + break + } + if ch <= r.Last { + val = true + break + } + } + } else { + lo, hi := 0, n + for lo < hi { + mid := int(uint(lo+hi) >> 1) + if c.ranges[mid].First <= ch { + lo = mid + 1 + } else { + hi = mid + } + } + if lo > 0 && ch <= c.ranges[lo-1].Last { + val = true + } + } + } + + //check categories if we haven't already found a range + if !val && len(c.categories) > 0 { + val = c.charInCategories(ch) + } + + // negate the whole char set + if c.negate { + val = !val + } + + // get subtracted recurse + if val && c.sub != nil { + val = !c.sub.CharIn(ch) + } + + //log.Printf("Char '%v' in %v == %v", string(ch), c.String(), val) + return val +} + +func (c *CharSet) prepareASCIIBitmap() { + if c == nil || c.ascii != nil { + return + } + if c.sub != nil { + c.sub.prepareASCIIBitmap() + } + bm := &asciiBitmap{} + for i := range rune(128) { + if c.charInSlow(i) { + bm.bits[i/64] |= 1 << (uint(i) % 64) + } + } + c.ascii = bm +} + +func (c *CharSet) charInCategories(ch rune) bool { + for _, ct := range c.categories { + // special categories...then unicode + if ct.Cat == SpaceCategoryText { + if unicode.IsSpace(ch) { + // we found a space so we're done + // negate means this is a "bad" thing + return !ct.Negate + } else if ct.Negate { + return true + } + } else if ct.Cat == WordCategoryText { + if IsWordChar(ch) { + return !ct.Negate + } else if ct.Negate { + return true + } + } else if unicode.Is(unicodeCategories[ct.Cat], ch) { + // if we're in this unicode category then we're done + // if negate=true on this category then we "failed" our test + // otherwise we're good that we found it + return !ct.Negate + } else if ct.Negate { + return true + } + } + return false +} + +func (c Category) String() string { + switch c.Cat { + case SpaceCategoryText: + if c.Negate { + return "\\S" + } + return "\\s" + case WordCategoryText: + if c.Negate { + return "\\W" + } + return "\\w" + } + if _, ok := unicodeCategories[c.Cat]; ok { + + if c.Negate { + return "\\P{" + c.Cat + "}" + } + return "\\p{" + c.Cat + "}" + } + return "Unknown category: " + c.Cat +} + +// CharDescription Produces a human-readable description for a single character. +func CharDescription(ch rune) string { + /*if ch == '\\' { + return "\\\\" + } + + if ch > ' ' && ch <= '~' { + return string(ch) + } else if ch == '\n' { + return "\\n" + } else if ch == ' ' { + return "\\ " + }*/ + + b := &bytes.Buffer{} + escape(b, ch, false) //fmt.Sprintf("%U", ch) + return b.String() +} + +// According to UTS#18 Unicode Regular Expressions (http://www.unicode.org/reports/tr18/) +// RL 1.4 Simple Word Boundaries The class of includes all Alphabetic +// values from the Unicode character database, from UnicodeData.txt [UData], plus the U+200C +// ZERO WIDTH NON-JOINER and U+200D ZERO WIDTH JOINER. +func IsWordChar(r rune) bool { + //"L", "Mn", "Nd", "Pc" + return unicode.In(r, + unicode.Categories["L"], unicode.Categories["Mn"], + unicode.Categories["Nd"], unicode.Categories["Pc"]) || r == '\u200D' || r == '\u200C' + //return 'A' <= r && r <= 'Z' || 'a' <= r && r <= 'z' || '0' <= r && r <= '9' || r == '_' +} + +func IsECMAWordChar(r rune) bool { + return unicode.In(r, + unicode.Categories["L"], unicode.Categories["Mn"], + unicode.Categories["Nd"], unicode.Categories["Pc"]) + + //return 'A' <= r && r <= 'Z' || 'a' <= r && r <= 'z' || '0' <= r && r <= '9' || r == '_' +} + +func IsECMAIdentifierStartChar(r rune) bool { + return r == '$' || r == '_' || unicode.In(r, unicode.L, unicode.Nl, unicode.Other_ID_Start) +} + +func IsECMAIdentifierChar(r rune) bool { + return IsECMAIdentifierStartChar(r) || r == '\u200C' || r == '\u200D' || + unicode.In(r, unicode.Mn, unicode.Mc, unicode.Nd, unicode.Pc, unicode.Other_ID_Continue) +} + +// SingletonChar will return the char from the first range without validation. +// It assumes you have checked for IsSingleton or IsSingletonInverse and will panic given bad input +func (c CharSet) SingletonChar() rune { + return c.ranges[0].First +} + +func (c CharSet) IsSingleton() bool { + return !c.negate && //negated is multiple chars + len(c.categories) == 0 && len(c.ranges) == 1 && // multiple ranges and unicode classes represent multiple chars + c.sub == nil && // subtraction means we've got multiple chars + c.ranges[0].First == c.ranges[0].Last // first and last equal means we're just 1 char +} + +func (c CharSet) IsSingletonInverse() bool { + return c.negate && //same as above, but requires negated + len(c.categories) == 0 && len(c.ranges) == 1 && // multiple ranges and unicode classes represent multiple chars + c.sub == nil && // subtraction means we've got multiple chars + c.ranges[0].First == c.ranges[0].Last // first and last equal means we're just 1 char +} + +func (c CharSet) IsMergeable() bool { + return !c.IsNegated() && !c.HasSubtraction() +} + +func (c CharSet) IsNegated() bool { + return c.negate +} + +func (c CharSet) HasSubtraction() bool { + return c.sub != nil +} + +func (c CharSet) IsEmpty() bool { + return len(c.ranges) == 0 && len(c.categories) == 0 && c.sub == nil +} + +func (c CharSet) IsAnything() bool { + return c.anything +} + +func (c *CharSet) addDigit(ecma, negate bool) { + if ecma { + if negate { + c.addRanges(NotECMADigitClass().ranges) + } else { + c.addRanges(ECMADigitClass().ranges) + } + } else { + c.addCategories(Category{Cat: "Nd", Negate: negate}) + } +} + +func (c *CharSet) addChar(ch rune) { + c.addRange(ch, ch) +} + +func (c *CharSet) addSpace(ecma, re2, negate bool) { + if ecma { + if negate { + c.addRanges(NotECMASpaceClass().ranges) + } else { + c.addRanges(ECMASpaceClass().ranges) + } + } else if re2 { + if negate { + c.addRanges(NotRE2SpaceClass().ranges) + } else { + c.addRanges(RE2SpaceClass().ranges) + } + } else { + c.addCategories(Category{Cat: SpaceCategoryText, Negate: negate}) + } +} + +func (c *CharSet) addWord(ecma, negate bool) { + if ecma { + if negate { + c.addRanges(NotECMAWordClass().ranges) + } else { + c.addRanges(ECMAWordClass().ranges) + } + } else { + c.addCategories(Category{Cat: WordCategoryText, Negate: negate}) + } +} + +// Add set ranges and categories into ours -- no deduping or anything +func (c *CharSet) addSet(set CharSet) { + if c.anything { + return + } + if set.anything { + c.makeAnything() + return + } + // just append here to prevent double-canon + c.ranges = append(c.ranges, set.ranges...) + c.addCategories(set.categories...) + c.canonicalize() +} + +func (c *CharSet) makeAnything() { + c.anything = true + c.categories = []Category{} + c.ranges = []SingleRange{{First: 0, Last: unicode.MaxRune}} +} + +func (c *CharSet) addCategories(cats ...Category) { + // don't add dupes and remove positive+negative + if c.anything { + // if we've had a previous positive+negative group then + // just return, we're as broad as we can get + return + } + + for _, ct := range cats { + found := false + for _, ct2 := range c.categories { + if ct.Cat == ct2.Cat { + if ct.Negate != ct2.Negate { + // oposite negations...this mean we just + // take us as anything and move on + c.makeAnything() + return + } + found = true + break + } + } + + if !found { + c.categories = append(c.categories, ct) + } + } +} + +// Merges new ranges to our own +func (c *CharSet) addRanges(ranges []SingleRange) { + if c.anything { + return + } + c.ranges = append(c.ranges, ranges...) + c.canonicalize() +} + +// Merges everything but the new ranges into our own +func (c *CharSet) addNegativeRanges(ranges []SingleRange) { + if c.anything { + return + } + + var hi rune + + // convert incoming ranges into opposites, assume they are in order + for _, r := range ranges { + if hi < r.First { + c.ranges = append(c.ranges, SingleRange{hi, r.First - 1}) + } + hi = r.Last + 1 + } + + if hi < utf8.MaxRune { + c.ranges = append(c.ranges, SingleRange{hi, utf8.MaxRune}) + } + + c.canonicalize() +} + +func normalizeUnicodeCategoryAlias(catName string) string { + var b strings.Builder + b.Grow(len(catName)) + for _, ch := range catName { + switch ch { + case '_', '-', ' ': + continue + default: + b.WriteRune(unicode.ToLower(ch)) + } + } + return b.String() +} + +func canonicalUnicodeCatName(catName string) (string, bool) { + if _, ok := unicodeCategories[catName]; ok { + return catName, true + } + + normalized := normalizeUnicodeCategoryAlias(catName) + if canonical, ok := unicodeSupportedPropertyAliases[normalized]; ok { + return canonical, true + } + if canonical, ok := unicodeBarePropertyValueAliases[normalized]; ok { + return canonical, true + } + + if eq := strings.IndexRune(catName, '='); eq >= 0 { + propName := catName[:eq] + valueName := catName[eq+1:] + prop, ok := unicodeSupportedPropertyAliases[normalizeUnicodeCategoryAlias(propName)] + if !ok { + return "", false + } + values := unicodeSupportedPropertyValueAliases[prop] + if values == nil { + return "", false + } + value, ok := values[normalizeUnicodeCategoryAlias(valueName)] + if !ok { + return "", false + } + canonical := prop + "=" + value + if _, ok := unicodeCategories[canonical]; ok { + return canonical, true + } + } + + return "", false +} + +func (c *CharSet) addCategory(categoryName string, negate, caseInsensitive bool) { + var ok bool + categoryName, ok = canonicalUnicodeCatName(categoryName) + if !ok { + // unknown unicode category, script, or property "blah" + panic(fmt.Errorf("unknown unicode category, script, or property '%v'", categoryName)) + + } + + if caseInsensitive && (categoryName == "Ll" || categoryName == "Lu" || categoryName == "Lt") { + // when RegexOptions.IgnoreCase is specified then {Ll} {Lu} and {Lt} cases should all match + c.addCategories( + Category{Cat: "Ll", Negate: negate}, + Category{Cat: "Lu", Negate: negate}, + Category{Cat: "Lt", Negate: negate}) + } + c.addCategories(Category{Cat: categoryName, Negate: negate}) +} + +// Adds to the class any case-equivalence versions of characters already +// in the class. Used for case-insensitivity. +func (c *CharSet) addCaseEquivalences() { + // we already have all case equiv + if c.anything { + return + } + rangeCount := len(c.ranges) + for i := 0; i < rangeCount; i++ { + r := c.ranges[i] + // For a single range that's in the set, adds any additional ranges + // necessary to ensure that lowercase equivalents are also included. + for i := r.First; i <= r.Last; i++ { + equiv := tryFindCaseEquivalences(i) + for _, eq := range equiv { + c.ranges = append(c.ranges, SingleRange{First: eq, Last: eq}) + } + } + } + c.canonicalize() +} + +// Performs a fast lookup which determines if a character is involved in case conversion, as well as +// returns the OTHER characters that should be considered equivalent in case it does participate in case conversion. +func tryFindCaseEquivalences(ch rune) []rune { + newCh := unicode.SimpleFold(ch) + if newCh == ch { + // no case support + return nil + } + equiv := []rune{newCh} + for { + newCh = unicode.SimpleFold(newCh) + if newCh == ch { + return equiv + } + equiv = append(equiv, newCh) + } +} + +func (c *CharSet) addSubtraction(sub *CharSet) { + c.sub = sub +} + +func (c *CharSet) addRange(chMin, chMax rune) { + c.ranges = append(c.ranges, SingleRange{First: chMin, Last: chMax}) + c.canonicalize() +} + +func (c *CharSet) addNamedASCII(name string, negate bool) bool { + var rs []SingleRange + + switch name { + case "alnum": + rs = []SingleRange{{'0', '9'}, {'A', 'Z'}, {'a', 'z'}} + case "alpha": + rs = []SingleRange{{'A', 'Z'}, {'a', 'z'}} + case "ascii": + rs = []SingleRange{{0, 0x7f}} + case "blank": + rs = []SingleRange{{'\t', '\t'}, {' ', ' '}} + case "cntrl": + rs = []SingleRange{{0, 0x1f}, {0x7f, 0x7f}} + case "digit": + c.addDigit(false, negate) + case "graph": + rs = []SingleRange{{'!', '~'}} + case "lower": + rs = []SingleRange{{'a', 'z'}} + case "print": + rs = []SingleRange{{' ', '~'}} + case "punct": //[!-/:-@[-`{-~] + rs = []SingleRange{{'!', '/'}, {':', '@'}, {'[', '`'}, {'{', '~'}} + case "space": + c.addSpace(true, false, negate) + case "upper": + rs = []SingleRange{{'A', 'Z'}} + case "word": + c.addWord(true, negate) + case "xdigit": + rs = []SingleRange{{'0', '9'}, {'A', 'F'}, {'a', 'f'}} + default: + return false + } + + if len(rs) > 0 { + if negate { + c.addNegativeRanges(rs) + } else { + c.addRanges(rs) + } + } + + return true +} + +type singleRangeSorter []SingleRange + +func (p singleRangeSorter) Len() int { return len(p) } +func (p singleRangeSorter) Less(i, j int) bool { return p[i].First < p[j].First } +func (p singleRangeSorter) Swap(i, j int) { p[i], p[j] = p[j], p[i] } + +// Logic to reduce a character class to a unique, sorted form. +func (c *CharSet) canonicalize() { + var i, j int + var last rune + + if len(c.ranges) == 0 { + return + } + + // + // Find and eliminate overlapping or abutting ranges + // + + if len(c.ranges) > 1 { + sort.Sort(singleRangeSorter(c.ranges)) + + done := false + + for i, j = 1, 0; ; i++ { + for last = c.ranges[j].Last; ; i++ { + if i == len(c.ranges) || last >= unicode.MaxRune { + done = true + break + } + + CurrentRange := c.ranges[i] + if CurrentRange.First > last+1 { + break + } + + if last < CurrentRange.Last { + last = CurrentRange.Last + } + } + + c.ranges[j] = SingleRange{First: c.ranges[j].First, Last: last} + + j++ + + if done { + break + } + + if j < i { + c.ranges[j] = c.ranges[i] + } + } + + c.ranges = append(c.ranges[:j], c.ranges[len(c.ranges):]...) + } + + // If the class now represents a single negated range, but does so by including every + // other character, invert it to produce a normalized form with a single range. This + // is valuable for subsequent optimizations in most of the engines. + if !c.negate && c.sub == nil && len(c.categories) == 0 { + if len(c.ranges) == 2 { + // There are two ranges in the list. See if there's one missing range between them. + // Such a range might be as small as a single character. + if c.ranges[0].First == 0 && + c.ranges[1].Last >= unicode.MaxRune && + c.ranges[0].Last < c.ranges[1].First-1 { + c.ranges = []SingleRange{{c.ranges[0].Last + 1, c.ranges[1].First - 1}} + c.negate = true + } + } else if len(c.ranges) == 1 { + switch c.ranges[0].First { + case 0: + // There's only one range in the list. Does it include everything but the last char? + if c.ranges[0].Last == unicode.MaxRune-1 { + c.ranges[0] = SingleRange{unicode.MaxRune, unicode.MaxRune} + c.negate = true + } + case 1: + // Or everything but the first char? + if c.ranges[0].Last >= unicode.MaxRune { + c.ranges[0] = SingleRange{'\x00', '\x00'} + c.negate = true + } + } + } + } + + // If the class now has a range that includes everything, and if it doesn't have subtraction, + // we can remove all of its categories, as they're duplicative (the set already includes everything). + if !c.negate && + c.sub == nil && + len(c.ranges) == 1 && c.ranges[0].First == 0 && c.ranges[0].Last >= unicode.MaxRune { + + c.makeAnything() + } + + // If there's only a single character omitted from ranges, if there's no subtractor, and if there are categories, + // see if that character is in the categories. If it is, then we can replace whole thing with a complete "any" range. + // If it's not, then we can remove the categories, as they're only duplicating the rest of the range, turning the set + // into a "not one". This primarily helps in the case of a synthesized set from analysis that ends up combining '.' with + // categories, as we want to reduce that set down to either [^\n] or [\0-\uFFFF]. (This can be extrapolated to any number + // of missing characters; in fact, categories in general are superfluous and the entire set can be represented as ranges. + // But categories serve as a space optimization, and we strike a balance between testing many characters and the time/complexity + // it takes to do so. Thus, we limit this to the common case of a single missing character.) + if !c.negate && c.sub == nil && len(c.categories) > 0 && + len(c.ranges) == 2 && c.ranges[0].First == 0 && c.ranges[0].Last+2 == c.ranges[1].First && c.ranges[1].Last == unicode.MaxRune { + + if c.charInCategories(c.ranges[0].Last + 1) { + //c.ranges = []SingleRange{{'\x00', unicode.MaxRune}} + c.makeAnything() + } else { + c.negate = true + c.ranges = []SingleRange{{c.ranges[0].Last + 1, c.ranges[0].Last + 1}} + c.categories = []Category{} + } + } +} + +// Adds to the class any lowercase versions of characters already +// in the class. Used for case-insensitivity. +func (c *CharSet) addLowercase() { + if c.anything { + return + } + toAdd := []SingleRange{} + for i := 0; i < len(c.ranges); i++ { + r := c.ranges[i] + if r.First == r.Last { + lower := unicode.ToLower(r.First) + c.ranges[i] = SingleRange{First: lower, Last: lower} + } else { + toAdd = append(toAdd, r) + } + } + + for _, r := range toAdd { + c.addLowercaseRange(r.First, r.Last) + } + c.canonicalize() +} + +/************************************************************************** + Let U be the set of Unicode character values and let L be the lowercase + function, mapping from U to U. To perform case insensitive matching of + character sets, we need to be able to map an interval I in U, say + + I = [chMin, chMax] = { ch : chMin <= ch <= chMax } + + to a set A such that A contains L(I) and A is contained in the union of + I and L(I). + + The table below partitions U into intervals on which L is non-decreasing. + Thus, for any interval J = [a, b] contained in one of these intervals, + L(J) is contained in [L(a), L(b)]. + + It is also true that for any such J, [L(a), L(b)] is contained in the + union of J and L(J). This does not follow from L being non-decreasing on + these intervals. It follows from the nature of the L on each interval. + On each interval, L has one of the following forms: + + (1) L(ch) = constant (LowercaseSet) + (2) L(ch) = ch + offset (LowercaseAdd) + (3) L(ch) = ch | 1 (LowercaseBor) + (4) L(ch) = ch + (ch & 1) (LowercaseBad) + + It is easy to verify that for any of these forms [L(a), L(b)] is + contained in the union of [a, b] and L([a, b]). +***************************************************************************/ + +const ( + LowercaseSet = 0 // Set to arg. + LowercaseAdd = 1 // Add arg. + LowercaseBor = 2 // Bitwise or with 1. + LowercaseBad = 3 // Bitwise and with 1 and add original. +) + +type lcMap struct { + chMin, chMax rune + op, data int32 +} + +var lcTable = []lcMap{ + {'\u0041', '\u005A', LowercaseAdd, 32}, + {'\u00C0', '\u00DE', LowercaseAdd, 32}, + {'\u0100', '\u012E', LowercaseBor, 0}, + {'\u0130', '\u0130', LowercaseSet, 0x0069}, + {'\u0132', '\u0136', LowercaseBor, 0}, + {'\u0139', '\u0147', LowercaseBad, 0}, + {'\u014A', '\u0176', LowercaseBor, 0}, + {'\u0178', '\u0178', LowercaseSet, 0x00FF}, + {'\u0179', '\u017D', LowercaseBad, 0}, + {'\u0181', '\u0181', LowercaseSet, 0x0253}, + {'\u0182', '\u0184', LowercaseBor, 0}, + {'\u0186', '\u0186', LowercaseSet, 0x0254}, + {'\u0187', '\u0187', LowercaseSet, 0x0188}, + {'\u0189', '\u018A', LowercaseAdd, 205}, + {'\u018B', '\u018B', LowercaseSet, 0x018C}, + {'\u018E', '\u018E', LowercaseSet, 0x01DD}, + {'\u018F', '\u018F', LowercaseSet, 0x0259}, + {'\u0190', '\u0190', LowercaseSet, 0x025B}, + {'\u0191', '\u0191', LowercaseSet, 0x0192}, + {'\u0193', '\u0193', LowercaseSet, 0x0260}, + {'\u0194', '\u0194', LowercaseSet, 0x0263}, + {'\u0196', '\u0196', LowercaseSet, 0x0269}, + {'\u0197', '\u0197', LowercaseSet, 0x0268}, + {'\u0198', '\u0198', LowercaseSet, 0x0199}, + {'\u019C', '\u019C', LowercaseSet, 0x026F}, + {'\u019D', '\u019D', LowercaseSet, 0x0272}, + {'\u019F', '\u019F', LowercaseSet, 0x0275}, + {'\u01A0', '\u01A4', LowercaseBor, 0}, + {'\u01A7', '\u01A7', LowercaseSet, 0x01A8}, + {'\u01A9', '\u01A9', LowercaseSet, 0x0283}, + {'\u01AC', '\u01AC', LowercaseSet, 0x01AD}, + {'\u01AE', '\u01AE', LowercaseSet, 0x0288}, + {'\u01AF', '\u01AF', LowercaseSet, 0x01B0}, + {'\u01B1', '\u01B2', LowercaseAdd, 217}, + {'\u01B3', '\u01B5', LowercaseBad, 0}, + {'\u01B7', '\u01B7', LowercaseSet, 0x0292}, + {'\u01B8', '\u01B8', LowercaseSet, 0x01B9}, + {'\u01BC', '\u01BC', LowercaseSet, 0x01BD}, + {'\u01C4', '\u01C5', LowercaseSet, 0x01C6}, + {'\u01C7', '\u01C8', LowercaseSet, 0x01C9}, + {'\u01CA', '\u01CB', LowercaseSet, 0x01CC}, + {'\u01CD', '\u01DB', LowercaseBad, 0}, + {'\u01DE', '\u01EE', LowercaseBor, 0}, + {'\u01F1', '\u01F2', LowercaseSet, 0x01F3}, + {'\u01F4', '\u01F4', LowercaseSet, 0x01F5}, + {'\u01FA', '\u0216', LowercaseBor, 0}, + {'\u0386', '\u0386', LowercaseSet, 0x03AC}, + {'\u0388', '\u038A', LowercaseAdd, 37}, + {'\u038C', '\u038C', LowercaseSet, 0x03CC}, + {'\u038E', '\u038F', LowercaseAdd, 63}, + {'\u0391', '\u03AB', LowercaseAdd, 32}, + {'\u03E2', '\u03EE', LowercaseBor, 0}, + {'\u0401', '\u040F', LowercaseAdd, 80}, + {'\u0410', '\u042F', LowercaseAdd, 32}, + {'\u0460', '\u0480', LowercaseBor, 0}, + {'\u0490', '\u04BE', LowercaseBor, 0}, + {'\u04C1', '\u04C3', LowercaseBad, 0}, + {'\u04C7', '\u04C7', LowercaseSet, 0x04C8}, + {'\u04CB', '\u04CB', LowercaseSet, 0x04CC}, + {'\u04D0', '\u04EA', LowercaseBor, 0}, + {'\u04EE', '\u04F4', LowercaseBor, 0}, + {'\u04F8', '\u04F8', LowercaseSet, 0x04F9}, + {'\u0531', '\u0556', LowercaseAdd, 48}, + {'\u10A0', '\u10C5', LowercaseAdd, 48}, + {'\u1E00', '\u1EF8', LowercaseBor, 0}, + {'\u1F08', '\u1F0F', LowercaseAdd, -8}, + {'\u1F18', '\u1F1F', LowercaseAdd, -8}, + {'\u1F28', '\u1F2F', LowercaseAdd, -8}, + {'\u1F38', '\u1F3F', LowercaseAdd, -8}, + {'\u1F48', '\u1F4D', LowercaseAdd, -8}, + {'\u1F59', '\u1F59', LowercaseSet, 0x1F51}, + {'\u1F5B', '\u1F5B', LowercaseSet, 0x1F53}, + {'\u1F5D', '\u1F5D', LowercaseSet, 0x1F55}, + {'\u1F5F', '\u1F5F', LowercaseSet, 0x1F57}, + {'\u1F68', '\u1F6F', LowercaseAdd, -8}, + {'\u1F88', '\u1F8F', LowercaseAdd, -8}, + {'\u1F98', '\u1F9F', LowercaseAdd, -8}, + {'\u1FA8', '\u1FAF', LowercaseAdd, -8}, + {'\u1FB8', '\u1FB9', LowercaseAdd, -8}, + {'\u1FBA', '\u1FBB', LowercaseAdd, -74}, + {'\u1FBC', '\u1FBC', LowercaseSet, 0x1FB3}, + {'\u1FC8', '\u1FCB', LowercaseAdd, -86}, + {'\u1FCC', '\u1FCC', LowercaseSet, 0x1FC3}, + {'\u1FD8', '\u1FD9', LowercaseAdd, -8}, + {'\u1FDA', '\u1FDB', LowercaseAdd, -100}, + {'\u1FE8', '\u1FE9', LowercaseAdd, -8}, + {'\u1FEA', '\u1FEB', LowercaseAdd, -112}, + {'\u1FEC', '\u1FEC', LowercaseSet, 0x1FE5}, + {'\u1FF8', '\u1FF9', LowercaseAdd, -128}, + {'\u1FFA', '\u1FFB', LowercaseAdd, -126}, + {'\u1FFC', '\u1FFC', LowercaseSet, 0x1FF3}, + {'\u2160', '\u216F', LowercaseAdd, 16}, + {'\u24B6', '\u24D0', LowercaseAdd, 26}, + {'\uFF21', '\uFF3A', LowercaseAdd, 32}, +} + +func (c *CharSet) addLowercaseRange(chMin, chMax rune) { + var i, iMax, iMid int + var chMinT, chMaxT rune + var lc lcMap + + for i, iMax = 0, len(lcTable); i < iMax; { + iMid = (i + iMax) / 2 + if lcTable[iMid].chMax < chMin { + i = iMid + 1 + } else { + iMax = iMid + } + } + + for ; i < len(lcTable); i++ { + lc = lcTable[i] + if lc.chMin > chMax { + return + } + chMinT = lc.chMin + if chMinT < chMin { + chMinT = chMin + } + + chMaxT = lc.chMax + if chMaxT > chMax { + chMaxT = chMax + } + + switch lc.op { + case LowercaseSet: + chMinT = rune(lc.data) + chMaxT = rune(lc.data) + case LowercaseAdd: + chMinT += lc.data + chMaxT += lc.data + case LowercaseBor: + chMinT |= 1 + chMaxT |= 1 + case LowercaseBad: + chMinT += (chMinT & 1) + chMaxT += (chMaxT & 1) + } + + if chMinT < chMin || chMaxT > chMax { + c.ranges = append(c.ranges, SingleRange{First: chMinT, Last: chMaxT}) + } + } +} + +// Determines whether two sets could overlap. +func (set1 *CharSet) MayOverlap(set2 *CharSet) bool { + // If the sets are identical, there's obviously overlap. + if set1.Equals(set2) { + return true + } + + // If either set is all-inclusive, there's overlap by definition (unless + // the other set is empty, but that's so rare it's not worth checking.) + if set1.IsAnything() || set2.IsAnything() { + return true + } + + // If one set is negated and the other one isn't, we're in one of two situations: + // - The remainder of the sets are identical, in which case these are inverses of + // each other, and they don't overlap. + // - The remainder of the sets aren't identical, in which case there's very likely + // overlap, and it's not worth spending more time investigating. + set1Negated := set1.IsNegated() + set2Negated := set2.IsNegated() + if set1Negated != set2Negated { + + return !set1.equals(set2, true) + } + + // If the sets are negated, since they're not equal, there's almost certainly overlap. + if set1Negated { + return true + } + + // Special-case some known, common classes that don't overlap. + if knownDistinctSets(set1, set2) || knownDistinctSets(set2, set1) { + return false + } + + // If set2 can be easily enumerated (e.g. no unicode categories), then enumerate it and + // check if any of its members are in set1. Otherwise, the same for set1. + if !set2.HasSubtraction() && len(set2.categories) == 0 { + return mayOverlapByEnumeration(set1, set2) + } else if !set1.HasSubtraction() && len(set1.categories) == 0 { + return mayOverlapByEnumeration(set2, set1) + } + + // Assume that everything else might overlap. In the future if it proved impactful, we could be more accurate here, + // at the exense of more computation time. + return true +} + +func knownDistinctSets(set1, set2 *CharSet) bool { + + return (set1.Equals(SpaceClass()) || set1.Equals(ECMASpaceClass())) && + (set2.Equals(DigitClass()) || set2.Equals(WordClass()) || + set2.Equals(ECMADigitClass()) || set2.Equals(ECMAWordClass())) + +} + +func mayOverlapByEnumeration(set1, set2 *CharSet) bool { + for i := 0; i < len(set2.ranges); i++ { + for c := set2.ranges[i].First; c <= set2.ranges[i].Last; c++ { + if set1.CharIn(c) { + return true + } + } + } + + return false +} + +// Gets all of the characters in the specified set, storing them into the provided span. +// +// Only considers character classes that only contain sets (no categories), +// just simple sets containing starting/ending pairs (subtraction from those pairs +// is factored in, however).The returned characters may be negated: if IsNegated(set) +// is false, then the returned characters are the only ones that match; if it returns +// true, then the returned characters are the only ones that don't match. +func (c *CharSet) GetSetChars(maxChars int) []rune { + // don't support categories, just ranges + if len(c.categories) > 0 || len(c.ranges) > maxChars { + return nil + } + + // Negation with subtraction is too cumbersome to reason about efficiently. + if c.IsNegated() && c.HasSubtraction() { + return nil + } + + chars := make([]rune, 0, maxChars) + curWork := 0 + // Iterate through the pairs of ranges, storing each value in each range + // into the supplied span. If they all won't fit, we give up and return 0. + // Otherwise we return the number found. Note that we don't bother to handle + // the corner case where the last range's upper bound is LastChar (\uFFFF), + // based on it a) complicating things, and b) it being really unlikely to + // be part of a small set. + for _, r := range c.ranges { + // loop through each char in the range + for ch := r.First; ch <= r.Last; ch++ { + + // Keep track of how many characters we've checked. This could work + // just comparing count rather than evaluated, but we also want to + // limit how much work is done here, which we can do by constraining + // the number of checks to the size of the storage provided. + curWork++ + if curWork > maxChars { + return nil + } + + // If the set is all ranges but has a subtracted class, + // validate the char is actually in the set prior to storing it: + // it might be in the subtracted range. + if c.HasSubtraction() && !c.CharIn(ch) { + continue + } + chars = append(chars, ch) + } + } + return chars +} + +func (c *CharSet) Hash() []byte { + b := &bytes.Buffer{} + c.mapHashFill(b) + return b.Bytes() +} + +func (c *CharSet) Equals(c2 *CharSet) bool { + return c.equals(c2, false) +} + +func (c *CharSet) equals(c2 *CharSet, ignoreNegate bool) bool { + if c == nil && c2 == nil { + return true + } + if c == nil && c2 != nil || c2 == nil && c != nil { + return false + } + + if !ignoreNegate { + if c.negate != c2.negate { + return false + } + } + if c.anything != c2.anything { + return false + } + + if !slices.Equal(c.ranges, c2.ranges) { + return false + } + if !slices.Equal(c.categories, c2.categories) { + return false + } + + return c.sub.equals(c2.sub, false) +} + +var whitespaceChars = []rune{'\u0009', '\u000A', '\u000B', '\u000C', '\u000D', + '\u0020', '\u0085', '\u00A0', '\u1680', '\u2000', + '\u2001', '\u2002', '\u2003', '\u2004', '\u2005', + '\u2006', '\u2007', '\u2008', '\u2009', '\u200A', + '\u2028', '\u2029', '\u202F', '\u205F', '\u3000'} + +// Gets whether the specified set is a named set with a reasonably small count +// of Unicode characters. Designed to help the regexp code generator choose a better +// search algo for finding chars +// Description is a short name that can be used as part of a var name in code gen +func (c *CharSet) IsUnicodeCategoryOfSmallCharCount() (isSmall bool, chars []rune, negated bool, desc string) { + // figure out if we're SpaceClass, RE2SpaceClass, ECMASpaceClass or inverse + // "hash" ourselves -- this is actually fully serialized, not just hashed + if c.IsSingleton() { + return true, []rune{c.SingletonChar()}, false, "" + } + if c.IsSingletonInverse() { + return true, []rune{c.SingletonChar()}, true, "" + } + + if c.Equals(SpaceClass()) { + // we're SpaceClass + return true, whitespaceChars, false, "whitespace" + } + if c.Equals(NotSpaceClass()) { + // we're NotSpaceClass + return true, whitespaceChars, true, "whitespace" + } + + return false, nil, false, "" +} + +// Gets whether the set description string is for two ASCII letters that case +// to each other under IgnoreCase rules. +func (c *CharSet) containsAsciiIgnoreCaseCharacter() (bool, []rune) { + if c.IsNegated() { + return false, nil + } + // get up to 3 chars, just to be able to error on both "too many" and "too few" + twoChars := c.GetSetChars(3) + return len(twoChars) == 2 && twoChars[0] < unicode.MaxASCII && twoChars[1] < unicode.MaxASCII && + (twoChars[0]|0x20) == (twoChars[1]|0x20) && + unicode.IsLetter(twoChars[0]) && unicode.IsLetter(twoChars[1]), twoChars +} + +func anyParticipateInCaseConversion(chars []rune) bool { + for _, c := range chars { + if participatesInCaseConversion(c) { + return true + } + } + return false +} + +func participatesInCaseConversion(ch rune) bool { + /* + case UnicodeCategory.ClosePunctuation: + case UnicodeCategory.ConnectorPunctuation: + case UnicodeCategory.Control: + case UnicodeCategory.DashPunctuation: + case UnicodeCategory.DecimalDigitNumber: + case UnicodeCategory.FinalQuotePunctuation: + case UnicodeCategory.InitialQuotePunctuation: + case UnicodeCategory.LineSeparator: + case UnicodeCategory.OpenPunctuation: + case UnicodeCategory.OtherNumber: + case UnicodeCategory.OtherPunctuation: + case UnicodeCategory.ParagraphSeparator: + case UnicodeCategory.SpaceSeparator: + */ + return !unicode.In(ch, unicode.Pe, unicode.Pc, unicode.Cc, unicode.Pd, unicode.Nd, unicode.Pf, + unicode.Pi, unicode.Zl, unicode.Ps, unicode.No, unicode.Po, unicode.Zp, unicode.Zs) +} + +func anyParticipatesInCaseConversion(str string) bool { + for _, c := range str { + if participatesInCaseConversion(c) { + return true + } + } + return false +} + +func isAsciiRunes(in []rune) bool { + for i := 0; i < len(in); i++ { + if in[i] > unicode.MaxASCII { + return false + } + } + return true +} + +func (c CharSet) GetIfNRanges(n int) []SingleRange { + if len(c.categories) > 0 { + return nil + } + if c.sub != nil { + return nil + } + if len(c.ranges) == n { + return c.ranges[:n] + } + return nil +} + +func (c *CharSet) GetIfOnlyUnicodeCategories() (cats []Category, negate bool) { + if c.sub != nil { + return nil, false + } + if len(c.ranges) > 0 { + return nil, false + } + // all cats need to be rationalized to the same negation or not + if len(c.categories) == 0 { + return nil, false + } + + neg := c.categories[0].Negate + for _, cat := range c.categories { + if neg != cat.Negate || cat.Cat == SpaceCategoryText || cat.Cat == WordCategoryText { + // negate some and not others...a problem + // or one of our non-unicode categories + return nil, false + } + } + + // tell the caller to negate if either all the categories + // are negated or the set as a whole is negated, but not + // both + return c.categories, neg != c.negate +} + +type CharClassAnalysisResults struct { + // true if the set contains only ranges; false if it contains Unicode categories and/or subtraction. + OnlyRanges bool + // true if we know for sure that the set contains only ASCII values; otherwise, false. + // This can only be true if OnlyRanges is true. + ContainsOnlyAscii bool + // true if we know for sure that the set doesn't contain any ASCII values; otherwise, false. + // This can only be true if OnlyRanges is true. + ContainsNoAscii bool + // true if we know for sure that all ASCII values are in the set; otherwise, false. + // This can only be true if OnlyRanges is true. + AllAsciiContained bool + // true if we know for sure that all non-ASCII values are in the set; otherwise, false. + // This can only be true if OnlyRanges is true. + AllNonAsciiContained bool + // The inclusive lower bound. + // This is only valid if OnlyRanges is true. + LowerBoundInclusiveIfOnlyRanges rune + // The exclusive upper bound. + // This is only valid if OnlyRanges is true. + UpperBoundExclusiveIfOnlyRanges rune +} + +// Analyzes the set to determine some basic properties that can be used to optimize usage. +func (set *CharSet) Analyze() CharClassAnalysisResults { + // The analysis is performed based entirely on ranges contained within the set. + // Thus, we require that it can be "easily enumerated", meaning it contains only + // ranges (and more specifically those with both the lower inclusive and upper + // exclusive bounds specified). We also permit the set to contain a subtracted + // character class, as for non-negated sets, that can only narrow what's permitted, + // and the analysis can be performed on the overestimate of the set prior to subtraction. + // However, negation is performed before subtraction, which means we can't trust + // the ranges to inform AllNonAsciiContained and AllAsciiContained, as the subtraction + // could create holes in those. As such, while we can permit subtraction for non-negated + // sets, for negated sets, we need to bail. + if (set.IsNegated() && set.HasSubtraction()) || len(set.categories) > 0 || len(set.ranges) == 0 { + // We can't make any strong claims about the set. + return CharClassAnalysisResults{} + } + + firstValueInclusive := set.ranges[0].First + lastValueExclusive := set.ranges[len(set.ranges)-1].Last + 1 + + if set.IsNegated() { + // We're negated: if the upper bound of the range is ASCII, that means everything + // above it is actually included, meaning all non-ASCII are in the class. + // Similarly if the lower bound is non-ASCII, that means in a negated world + // everything ASCII is included. + return CharClassAnalysisResults{ + OnlyRanges: true, + AllNonAsciiContained: lastValueExclusive <= unicode.MaxASCII, + AllAsciiContained: firstValueInclusive >= unicode.MaxASCII, + ContainsNoAscii: firstValueInclusive == 0 && set.ranges[0].Last >= unicode.MaxASCII, + ContainsOnlyAscii: false, + LowerBoundInclusiveIfOnlyRanges: firstValueInclusive, + UpperBoundExclusiveIfOnlyRanges: lastValueExclusive, + } + } + + // If the upper bound is ASCII, that means everything included in the class is ASCII. + // Similarly if the lower bound is non-ASCII, that means no ASCII is in the class. + return CharClassAnalysisResults{ + OnlyRanges: true, + AllNonAsciiContained: false, + AllAsciiContained: firstValueInclusive == 0 && set.ranges[0].Last >= unicode.MaxASCII && !set.HasSubtraction(), + ContainsOnlyAscii: lastValueExclusive <= unicode.MaxASCII, + ContainsNoAscii: firstValueInclusive >= unicode.MaxASCII, + LowerBoundInclusiveIfOnlyRanges: firstValueInclusive, + UpperBoundExclusiveIfOnlyRanges: lastValueExclusive, + } +} diff --git a/vendor/github.com/dlclark/regexp2/v2/syntax/code.go b/vendor/github.com/dlclark/regexp2/v2/syntax/code.go new file mode 100644 index 000000000..1df4e45a9 --- /dev/null +++ b/vendor/github.com/dlclark/regexp2/v2/syntax/code.go @@ -0,0 +1,316 @@ +package syntax + +import ( + "bytes" + "fmt" + "math" +) + +// similar to prog.go in the go regex package...also with comment 'may not belong in this package' + +// File provides operator constants for use by the Builder and the Machine. + +// Implementation notes: +// +// Regexps are built into RegexCodes, which contain an operation array, +// a string table, and some constants. +// +// Each operation is one of the codes below, followed by the integer +// operands specified for each op. +// +// Strings and sets are indices into a string table. + +type InstOp int + +const ( + // lef/back operands description + + Onerep InstOp = 0 // lef,back char,min,max a {n} + Notonerep InstOp = 1 // lef,back char,min,max .{n} + Setrep InstOp = 2 // lef,back set,min,max [\d]{n} + + Oneloop InstOp = 3 // lef,back char,min,max a {,n} + Notoneloop InstOp = 4 // lef,back char,min,max .{,n} + Setloop InstOp = 5 // lef,back set,min,max [\d]{,n} + + Onelazy InstOp = 6 // lef,back char,min,max a {,n}? + Notonelazy InstOp = 7 // lef,back char,min,max .{,n}? + Setlazy InstOp = 8 // lef,back set,min,max [\d]{,n}? + + One InstOp = 9 // lef char a + Notone InstOp = 10 // lef char [^a] + Set InstOp = 11 // lef set [a-z\s] \w \s \d + + Multi InstOp = 12 // lef string abcd + Ref InstOp = 13 // lef group \# + + Bol InstOp = 14 // ^ + Eol InstOp = 15 // $ + Boundary InstOp = 16 // \b + Nonboundary InstOp = 17 // \B + Beginning InstOp = 18 // \A + Start InstOp = 19 // \G + EndZ InstOp = 20 // \Z + End InstOp = 21 // \Z + + Nothing InstOp = 22 // Reject! + + // Primitive control structures + + Lazybranch InstOp = 23 // back jump straight first + Branchmark InstOp = 24 // back jump branch first for loop + Lazybranchmark InstOp = 25 // back jump straight first for loop + Nullcount InstOp = 26 // back val set counter, null mark + Setcount InstOp = 27 // back val set counter, make mark + Branchcount InstOp = 28 // back jump,limit branch++ if zero<=c impl group slots + Capsize int // number of impl group slots + FcPrefix *Prefix // the set of candidate first characters (may be null) + BmPrefix *BmPrefix // the fixed prefix string as a Boyer-Moore machine (may be null) + Anchors AnchorLoc // the set of zero-length start anchors (RegexFCD.Bol, etc) + RightToLeft bool // true if right to left + FindOptimizations *FindOptimizations // analyzed candidate search strategy +} + +// PrepareCharSetASCIIBitmaps builds bounded ASCII lookup tables for compiled +// character classes before the regexp is shared across goroutines. +func (c *Code) PrepareCharSetASCIIBitmaps() { + if c == nil { + return + } + for _, set := range c.Sets { + set.prepareASCIIBitmap() + } + if c.FcPrefix != nil { + c.FcPrefix.PrefixSet.prepareASCIIBitmap() + } + if c.FindOptimizations != nil { + for _, set := range c.FindOptimizations.FixedDistanceSets { + set.Set.prepareASCIIBitmap() + } + if c.FindOptimizations.LiteralAfterLoop != nil && c.FindOptimizations.LiteralAfterLoop.LoopNode != nil { + c.FindOptimizations.LiteralAfterLoop.LoopNode.Set.prepareASCIIBitmap() + } + } +} + +func opcodeBacktracks(op InstOp) bool { + op &= Mask + + switch op { + case Oneloop, Notoneloop, Setloop, Onelazy, Notonelazy, Setlazy, Lazybranch, Branchmark, Lazybranchmark, + Nullcount, Setcount, Branchcount, Lazybranchcount, Setmark, Capturemark, Getmark, Setjump, Backjump, + Forejump, Goto: + return true + + default: + return false + } +} + +func opcodeSize(op InstOp) int { + op &= Mask + + switch op { + case Nothing, Bol, Eol, Boundary, Nonboundary, ECMABoundary, NonECMABoundary, Beginning, Start, EndZ, + End, Nullmark, Setmark, Getmark, Setjump, Backjump, Forejump, Stop, UpdateBumpalong: + return 1 + + case One, Notone, Multi, Ref, Testref, Goto, Nullcount, Setcount, Lazybranch, Branchmark, Lazybranchmark, + Prune, Set: + return 2 + + case Capturemark, Branchcount, Lazybranchcount, Onerep, Notonerep, Oneloop, Notoneloop, Onelazy, Notonelazy, + Setlazy, Setrep, Setloop, Oneloopatomic, Notoneloopatomic, Setloopatomic: + return 3 + + default: + panic(fmt.Errorf("unexpected op code: %v", op)) + } +} + +var codeStr = []string{ + "Onerep", "Notonerep", "Setrep", + "Oneloop", "Notoneloop", "Setloop", + "Onelazy", "Notonelazy", "Setlazy", + "One", "Notone", "Set", + "Multi", "Ref", + "Bol", "Eol", "Boundary", "Nonboundary", "Beginning", "Start", "EndZ", "End", + "Nothing", + "Lazybranch", "Branchmark", "Lazybranchmark", + "Nullcount", "Setcount", "Branchcount", "Lazybranchcount", + "Nullmark", "Setmark", "Capturemark", "Getmark", + "Setjump", "Backjump", "Forejump", "Testref", "Goto", + "Prune", "Stop", + "ECMABoundary", "NonECMABoundary", + "Oneloopatomic", "Notoneloopatomic", "Setloopatomic", + "Bumpalong", +} + +func operatorDescription(op InstOp) string { + desc := codeStr[op&Mask] + if (op & Ci) != 0 { + desc += "-Ci" + } + if (op & Rtl) != 0 { + desc += "-Rtl" + } + if (op & Back) != 0 { + desc += "-Back" + } + if (op & Back2) != 0 { + desc += "-Back2" + } + + return desc +} + +// OpcodeDescription is a humman readable string of the specific offset +func (c *Code) OpcodeDescription(offset int) string { + buf := &bytes.Buffer{} + + op := InstOp(c.Codes[offset]) + fmt.Fprintf(buf, "%06d ", offset) + + if opcodeBacktracks(op & Mask) { + buf.WriteString("*") + } else { + buf.WriteString(" ") + } + buf.WriteString(operatorDescription(op)) + buf.WriteString("(") + op &= Mask + + switch op { + case One, Notone, Onerep, Notonerep, Oneloop, Notoneloop, Onelazy, Notonelazy, + Oneloopatomic, Notoneloopatomic: + buf.WriteString("Ch = ") + buf.WriteString(CharDescription(rune(c.Codes[offset+1]))) + + case Set, Setrep, Setloop, Setlazy, Setloopatomic: + buf.WriteString("Set = ") + buf.WriteString(c.Sets[c.Codes[offset+1]].String()) + + case Multi: + fmt.Fprintf(buf, "String = %s", string(c.Strings[c.Codes[offset+1]])) + + case Ref, Testref: + fmt.Fprintf(buf, "Index = %d", c.Codes[offset+1]) + + case Capturemark: + fmt.Fprintf(buf, "Index = %d", c.Codes[offset+1]) + if c.Codes[offset+2] != -1 { + fmt.Fprintf(buf, ", Unindex = %d", c.Codes[offset+2]) + } + + case Nullcount, Setcount: + fmt.Fprintf(buf, "Value = %d", c.Codes[offset+1]) + + case Goto, Lazybranch, Branchmark, Lazybranchmark, Branchcount, Lazybranchcount: + fmt.Fprintf(buf, "Addr = %d", c.Codes[offset+1]) + } + + switch op { + case Onerep, Notonerep, Oneloop, Notoneloop, Onelazy, Notonelazy, Setrep, Setloop, Setlazy, + Oneloopatomic, Notoneloopatomic, Setloopatomic: + buf.WriteString(", Rep = ") + if c.Codes[offset+2] == math.MaxInt32 { + buf.WriteString("inf") + } else { + fmt.Fprintf(buf, "%d", c.Codes[offset+2]) + } + + case Branchcount, Lazybranchcount: + buf.WriteString(", Limit = ") + if c.Codes[offset+2] == math.MaxInt32 { + buf.WriteString("inf") + } else { + fmt.Fprintf(buf, "%d", c.Codes[offset+2]) + } + + } + + buf.WriteString(")") + + return buf.String() +} + +func (c *Code) Dump() string { + buf := &bytes.Buffer{} + + if c.RightToLeft { + fmt.Fprintln(buf, "Direction: right-to-left") + } else { + fmt.Fprintln(buf, "Direction: left-to-right") + } + if c.FcPrefix == nil { + fmt.Fprintln(buf, "Firstchars: n/a") + } else { + fmt.Fprintf(buf, "Firstchars: %v\n", c.FcPrefix.PrefixSet.String()) + } + + if c.BmPrefix == nil { + fmt.Fprintln(buf, "Prefix: n/a") + } else { + fmt.Fprintf(buf, "Prefix: %v\n", Escape(c.BmPrefix.String())) + } + + fmt.Fprintf(buf, "Anchors: %v\n", c.Anchors) + if c.FindOptimizations != nil { + fmt.Fprint(buf, c.FindOptimizations.Dump()) + } + fmt.Fprintln(buf) + + if c.BmPrefix != nil { + fmt.Fprintln(buf, "BoyerMoore:") + fmt.Fprintln(buf, c.BmPrefix.Dump(" ")) + } + for i := 0; i < len(c.Codes); i += opcodeSize(InstOp(c.Codes[i])) { + fmt.Fprintln(buf, c.OpcodeDescription(i)) + } + + return buf.String() +} diff --git a/vendor/github.com/dlclark/regexp2/syntax/escape.go b/vendor/github.com/dlclark/regexp2/v2/syntax/escape.go similarity index 97% rename from vendor/github.com/dlclark/regexp2/syntax/escape.go rename to vendor/github.com/dlclark/regexp2/v2/syntax/escape.go index 609df1073..40dea1781 100644 --- a/vendor/github.com/dlclark/regexp2/syntax/escape.go +++ b/vendor/github.com/dlclark/regexp2/v2/syntax/escape.go @@ -19,7 +19,7 @@ const meta = `\.+*?()|[]{}^$# ` func escape(b *bytes.Buffer, r rune, force bool) { if unicode.IsPrint(r) { - if strings.IndexRune(meta, r) >= 0 || force { + if strings.ContainsRune(meta, r) || force { b.WriteRune('\\') } b.WriteRune(r) diff --git a/vendor/github.com/dlclark/regexp2/syntax/fuzz.go b/vendor/github.com/dlclark/regexp2/v2/syntax/fuzz.go similarity index 80% rename from vendor/github.com/dlclark/regexp2/syntax/fuzz.go rename to vendor/github.com/dlclark/regexp2/v2/syntax/fuzz.go index ee863866d..41cf8852b 100644 --- a/vendor/github.com/dlclark/regexp2/syntax/fuzz.go +++ b/vendor/github.com/dlclark/regexp2/v2/syntax/fuzz.go @@ -1,3 +1,4 @@ +//go:build gofuzz // +build gofuzz package syntax @@ -5,7 +6,7 @@ package syntax // Fuzz is the input point for go-fuzz func Fuzz(data []byte) int { sdata := string(data) - tree, err := Parse(sdata, RegexOptions(0)) + tree, err := Parse(sdata, ParseOptions{}) if err != nil { return 0 } diff --git a/vendor/github.com/dlclark/regexp2/v2/syntax/optimizations.go b/vendor/github.com/dlclark/regexp2/v2/syntax/optimizations.go new file mode 100644 index 000000000..0186497a0 --- /dev/null +++ b/vendor/github.com/dlclark/regexp2/v2/syntax/optimizations.go @@ -0,0 +1,672 @@ +package syntax + +import ( + "bytes" + "cmp" + "fmt" + "slices" +) + +type FindOptimizations struct { + rightToLeft bool + asciiLookups [][]uint + + FindMode FindNextStartingPositionMode + LeadingAnchor NodeType + TrailingAnchor NodeType + MinRequiredLength int + MaxPossibleLength int + LeadingPrefix string + LeadingPrefixes []string + LeadingPrefixesRunes [][]rune + //LeadingStrings *helpers.StringSearchValues + + FixedDistanceLiteral FixedDistanceLiteral + FixedDistanceSets []FixedDistanceSet + LiteralAfterLoop *LiteralAfterLoop + LandmarkChain *RequiredLandmarkChain +} + +type LiteralAfterLoop struct { + String string + StringIgnoreCase bool + Char rune + Chars []rune + + LoopNode *RegexNode +} + +type FixedDistanceSet struct { + Set *CharSet + Chars []rune + Negated bool + Range *SingleRange + Distance int +} + +type FixedDistanceLiteral struct { + S string + C rune + Distance int +} + +type RequiredLandmarkChain struct { + // LeadingLoopSet is the unbounded leading set loop that precedes every + // landmark in the original concatenation. At run time, after the first + // landmark alternative is found, the scanner walks backward over this set + // to recover the earliest plausible regex start position. + LeadingLoopSet *CharSet + + // Landmarks must all be found, in slice order, for the chain prefilter to + // produce a candidate. Each landmark is satisfied by exactly one matching + // alternative; alternatives are tried independently by the runner. + Landmarks []RequiredLandmark +} + +type RequiredLandmark struct { + // Alternatives describes the mutually exclusive shapes that can satisfy + // this single required landmark. A landmark matches when any one alternative + // matches at a position in the input. + Alternatives []RequiredLandmarkAlternative +} + +type RequiredLandmarkAlternative struct { + // Literal is the core token for literal alternatives. When non-empty, it + // must match exactly at the candidate core position, and Set must be nil. + Literal []rune + + // Set is the core token for character-class alternatives. When non-nil, it + // must match between MinRepeat and MaxRepeat runes at the candidate core + // position, and Literal must be empty. The analyzer only builds set + // alternatives for non-negated sets that can be cheaply enumerated, but the + // runner uses Set for membership checks. + Set *CharSet + + // LeadingWhitespaceSet is the optional or required whitespace immediately + // before the core token. If RequireWhitespaceBefore is true, at least one + // rune from this set must precede the core. When this alternative is the + // first matched landmark, the runner may rewind over additional contiguous + // leading whitespace from this set before rewinding over LeadingLoopSet. + LeadingWhitespaceSet *CharSet + + // TrailingWhitespaceSet is the optional or required whitespace immediately + // after the core token. If RequireWhitespaceAfter is true, at least one rune + // from this set must follow the core. The runner validates the requirement, + // but does not consume optional trailing whitespace into the landmark end. + TrailingWhitespaceSet *CharSet + + // MinRepeat and MaxRepeat describe the core token width. Literal alternatives + // use 1..1 regardless of literal length because the literal is matched as one + // fixed core token; Set alternatives use the source set repetition. + MinRepeat int + MaxRepeat int + + RequireWhitespaceBefore bool + RequireWhitespaceAfter bool +} + +type FindNextStartingPositionMode int + +const ( + NoSearch FindNextStartingPositionMode = iota + // A "beginning" anchor at the beginning of the pattern. + LeadingAnchor_LeftToRight_Beginning + // A "start" anchor at the beginning of the pattern. + LeadingAnchor_LeftToRight_Start + // An "endz" anchor at the beginning of the pattern. This is rare. + LeadingAnchor_LeftToRight_EndZ + // An "end" anchor at the beginning of the pattern. This is rare. + LeadingAnchor_LeftToRight_End + // A "beginning" anchor at the beginning of the right-to-left pattern. + LeadingAnchor_RightToLeft_Beginning + // A "start" anchor at the beginning of the right-to-left pattern. + LeadingAnchor_RightToLeft_Start + // An "endz" anchor at the beginning of the right-to-left pattern. This is rare. + LeadingAnchor_RightToLeft_EndZ + // An "end" anchor at the beginning of the right-to-left pattern. This is rare. + LeadingAnchor_RightToLeft_End + // An "end" anchor at the end of the pattern, with the pattern always matching a fixed-length expression. + TrailingAnchor_FixedLength_LeftToRight_End + // An "endz" anchor at the end of the pattern, with the pattern always matching a fixed-length expression. + TrailingAnchor_FixedLength_LeftToRight_EndZ + // A multi-character substring at the beginning of the pattern. + LeadingString_LeftToRight + // A multi-character substring at the beginning of the right-to-left pattern. + LeadingString_RightToLeft + // A multi-character ordinal case-insensitive substring at the beginning of the pattern. + LeadingString_OrdinalIgnoreCase_LeftToRight + // Multiple leading prefix strings + LeadingStrings_LeftToRight + // Multiple leading ordinal case-insensitive prefix strings + LeadingStrings_OrdinalIgnoreCase_LeftToRight + + // A set starting the pattern. + LeadingSet_LeftToRight + // A set starting the right-to-left pattern. + LeadingSet_RightToLeft + + // A single character at the start of the right-to-left pattern. + LeadingChar_RightToLeft + + // A single character at a fixed distance from the start of the pattern. + FixedDistanceChar_LeftToRight + // A multi-character case-sensitive string at a fixed distance from the start of the pattern. + FixedDistanceString_LeftToRight + + // One or more sets at a fixed distance from the start of the pattern. + FixedDistanceSets_LeftToRight + + // A literal (single character, multi-char string, or set with small number of characters) after a non-overlapping set loop at the start of the pattern. + LiteralAfterLoop_LeftToRight + + // A sequence of required landmarks after a leading loop. + RequiredLandmarkChain_LeftToRight +) + +func (m FindNextStartingPositionMode) String() string { + switch m { + case NoSearch: + return "NoSearch" + case LeadingAnchor_LeftToRight_Beginning: + return "LeadingAnchor_LeftToRight_Beginning" + case LeadingAnchor_LeftToRight_Start: + return "LeadingAnchor_LeftToRight_Start" + case LeadingAnchor_LeftToRight_EndZ: + return "LeadingAnchor_LeftToRight_EndZ" + case LeadingAnchor_LeftToRight_End: + return "LeadingAnchor_LeftToRight_End" + case LeadingAnchor_RightToLeft_Beginning: + return "LeadingAnchor_RightToLeft_Beginning" + case LeadingAnchor_RightToLeft_Start: + return "LeadingAnchor_RightToLeft_Start" + case LeadingAnchor_RightToLeft_EndZ: + return "LeadingAnchor_RightToLeft_EndZ" + case LeadingAnchor_RightToLeft_End: + return "LeadingAnchor_RightToLeft_End" + case TrailingAnchor_FixedLength_LeftToRight_End: + return "TrailingAnchor_FixedLength_LeftToRight_End" + case TrailingAnchor_FixedLength_LeftToRight_EndZ: + return "TrailingAnchor_FixedLength_LeftToRight_EndZ" + case LeadingString_LeftToRight: + return "LeadingString_LeftToRight" + case LeadingString_RightToLeft: + return "LeadingString_RightToLeft" + case LeadingString_OrdinalIgnoreCase_LeftToRight: + return "LeadingString_OrdinalIgnoreCase_LeftToRight" + case LeadingStrings_LeftToRight: + return "LeadingStrings_LeftToRight" + case LeadingStrings_OrdinalIgnoreCase_LeftToRight: + return "LeadingStrings_OrdinalIgnoreCase_LeftToRight" + case LeadingSet_LeftToRight: + return "LeadingSet_LeftToRight" + case LeadingSet_RightToLeft: + return "LeadingSet_RightToLeft" + case LeadingChar_RightToLeft: + return "LeadingChar_RightToLeft" + case FixedDistanceChar_LeftToRight: + return "FixedDistanceChar_LeftToRight" + case FixedDistanceString_LeftToRight: + return "FixedDistanceString_LeftToRight" + case FixedDistanceSets_LeftToRight: + return "FixedDistanceSets_LeftToRight" + case LiteralAfterLoop_LeftToRight: + return "LiteralAfterLoop_LeftToRight" + case RequiredLandmarkChain_LeftToRight: + return "RequiredLandmarkChain_LeftToRight" + default: + return fmt.Sprintf("FindNextStartingPositionMode(%d)", int(m)) + } +} + +func (f *FindOptimizations) Dump() string { + buf := &bytes.Buffer{} + if f == nil { + fmt.Fprintln(buf, "Find mode: n/a") + return buf.String() + } + + fmt.Fprintf(buf, "Find mode: %s\n", f.FindMode) + fmt.Fprintf(buf, "Min length: %d\n", f.MinRequiredLength) + if f.MaxPossibleLength > 0 { + fmt.Fprintf(buf, "Max length: %d\n", f.MaxPossibleLength) + } + + switch f.FindMode { + case LeadingAnchor_LeftToRight_Beginning, LeadingAnchor_LeftToRight_Start, + LeadingAnchor_LeftToRight_EndZ, LeadingAnchor_LeftToRight_End, + LeadingAnchor_RightToLeft_Beginning, LeadingAnchor_RightToLeft_Start, + LeadingAnchor_RightToLeft_EndZ, LeadingAnchor_RightToLeft_End: + fmt.Fprintf(buf, "Anchor: %v\n", f.LeadingAnchor) + + case TrailingAnchor_FixedLength_LeftToRight_End, TrailingAnchor_FixedLength_LeftToRight_EndZ: + fmt.Fprintf(buf, "Anchor: %v\n", f.TrailingAnchor) + + case LeadingString_LeftToRight, LeadingString_RightToLeft, LeadingString_OrdinalIgnoreCase_LeftToRight: + fmt.Fprintf(buf, "Prefix: %q\n", f.LeadingPrefix) + + case LeadingStrings_LeftToRight, LeadingStrings_OrdinalIgnoreCase_LeftToRight: + fmt.Fprintf(buf, "Prefixes: %q\n", f.LeadingPrefixes) + + case FixedDistanceChar_LeftToRight: + fmt.Fprintf(buf, "Literal: %q at distance %d\n", f.FixedDistanceLiteral.C, f.FixedDistanceLiteral.Distance) + + case FixedDistanceString_LeftToRight: + fmt.Fprintf(buf, "Literal: %q at distance %d\n", f.FixedDistanceLiteral.S, f.FixedDistanceLiteral.Distance) + + case FixedDistanceSets_LeftToRight: + for i, set := range f.FixedDistanceSets { + fmt.Fprintf(buf, "Set[%d]: distance=%d %s\n", i, set.Distance, fixedDistanceSetDescription(set)) + } + + case LiteralAfterLoop_LeftToRight: + fmt.Fprintf(buf, "Literal: %s\n", literalAfterLoopDescription(f.LiteralAfterLoop)) + + case RequiredLandmarkChain_LeftToRight: + fmt.Fprintf(buf, "Landmarks: %s\n", landmarkChainDescription(f.LandmarkChain)) + } + + return buf.String() +} + +func fixedDistanceSetDescription(set FixedDistanceSet) string { + switch { + case len(set.Chars) > 0: + return fmt.Sprintf("chars=%q negated=%t", string(set.Chars), set.Negated) + case set.Range != nil: + return fmt.Sprintf("range=%q-%q negated=%t", set.Range.First, set.Range.Last, set.Negated) + case set.Set != nil: + return fmt.Sprintf("set=%s", set.Set.String()) + default: + return "set=" + } +} + +func literalAfterLoopDescription(literal *LiteralAfterLoop) string { + if literal == nil { + return "" + } + loopSet := "" + if literal.LoopNode != nil && literal.LoopNode.Set != nil { + loopSet = literal.LoopNode.Set.String() + } + switch { + case literal.String != "": + return fmt.Sprintf("string=%q ignoreCase=%t after loop set %s", literal.String, literal.StringIgnoreCase, loopSet) + case len(literal.Chars) > 0: + return fmt.Sprintf("chars=%q after loop set %s", string(literal.Chars), loopSet) + default: + return fmt.Sprintf("char=%q after loop set %s", literal.Char, loopSet) + } +} + +func landmarkChainDescription(chain *RequiredLandmarkChain) string { + if chain == nil { + return "" + } + loopSet := "" + if chain.LeadingLoopSet != nil { + loopSet = chain.LeadingLoopSet.String() + } + buf := &bytes.Buffer{} + fmt.Fprintf(buf, "leadingLoop=%s", loopSet) + for i, landmark := range chain.Landmarks { + fmt.Fprintf(buf, " landmark[%d]=", i) + for j, alt := range landmark.Alternatives { + if j > 0 { + buf.WriteString("|") + } + buf.WriteString(requiredLandmarkAlternativeDescription(alt)) + } + } + return buf.String() +} + +func requiredLandmarkAlternativeDescription(alt RequiredLandmarkAlternative) string { + core := "" + switch { + case len(alt.Literal) > 0: + core = fmt.Sprintf("literal=%q", string(alt.Literal)) + case alt.Set != nil: + core = fmt.Sprintf("set=%s repeat=%d..%d", alt.Set.String(), alt.MinRepeat, alt.MaxRepeat) + default: + core = "" + } + if alt.LeadingWhitespaceSet != nil { + core += fmt.Sprintf(" leadingWhitespace=%s required=%t", alt.LeadingWhitespaceSet.String(), alt.RequireWhitespaceBefore) + } + if alt.TrailingWhitespaceSet != nil { + core += fmt.Sprintf(" trailingWhitespace=%s required=%t", alt.TrailingWhitespaceSet.String(), alt.RequireWhitespaceAfter) + } + return core +} + +func newFindOptimizations(tree *RegexTree, opt ParseOptions) *FindOptimizations { + f := newFindOptimizationsForNode(tree.Root, opt, false) + + if !f.rightToLeft && !f.isUseful() { + if positiveLookahead, _ := findLeadingPositiveLookahead(tree.Root); positiveLookahead != nil { + positiveLookaheadOpts := newFindOptimizationsForNode(positiveLookahead.Children[0], opt, true) + + // Lookaheads don't currently factor into the whole-pattern length analysis, + // as they can overlap with the rest of the expression. Keep the whole-pattern + // minimum if it's larger, and preserve any max from the original expression. + positiveLookaheadOpts.MinRequiredLength = max(f.MinRequiredLength, positiveLookaheadOpts.MinRequiredLength) + positiveLookaheadOpts.MaxPossibleLength = f.MaxPossibleLength + f = positiveLookaheadOpts + } + } + + return f +} + +func newFindOptimizationsForNode(root *RegexNode, opt ParseOptions, isLeadingPartial bool) *FindOptimizations { + f := &FindOptimizations{ + rightToLeft: opt.RegexOptions&RightToLeft != 0, + MinRequiredLength: root.ComputeMinLength(), + LeadingAnchor: findLeadingOrTrailingAnchor(root, true), + MaxPossibleLength: -1, + } + + if f.rightToLeft && f.LeadingAnchor == NtBol { + // Filter out Bol for RightToLeft, as we don't currently optimize for it. + f.LeadingAnchor = NtUnknown + } + + f.FindMode = getFindMode(f.rightToLeft, f.LeadingAnchor) + if f.FindMode != NoSearch { + return f + } + + // Compute any anchor trailing the expression. If there is one, and we can also compute a fixed length + // for the whole expression, we can use that to quickly jump to the right location in the input. + if !f.rightToLeft && !isLeadingPartial { + f.TrailingAnchor = findLeadingOrTrailingAnchor(root, false) + if f.TrailingAnchor == NtEnd || f.TrailingAnchor == NtEndZ { + f.MaxPossibleLength = root.computeMaxLength() + if f.MinRequiredLength == f.MaxPossibleLength { + if f.TrailingAnchor == NtEnd { + f.FindMode = TrailingAnchor_FixedLength_LeftToRight_End + } else { + f.FindMode = TrailingAnchor_FixedLength_LeftToRight_EndZ + } + return f + } + } + } + + // If there's a leading substring, just use IndexOf and inherit all of its optimizations. + prefix := findPrefix(root) + if len(prefix) > 1 { + f.LeadingPrefix = prefix + if f.rightToLeft { + f.FindMode = LeadingString_RightToLeft + } else { + f.FindMode = LeadingString_LeftToRight + } + return f + } + + // At this point there are no fast-searchable anchors or case-sensitive prefixes. We can now analyze the + // pattern for sets and then use any found sets to determine what kind of search to perform. + + // If we're generating code, then the code generation process already handles sets that reduce to a single literal, + // so we can simplify and just always go for the sets. + dfa := false //(opt&NonBacktracking) != 0 + codeGen := opt.CodeGen && !dfa // for now, we never generate code for NonBacktracking, so treat it as non-codegen + interpreter := !codeGen && !dfa + //usesRfoTryFind := !codeGen + + // For interpreter, we want to employ optimizations, but we don't want to make construction significantly + // more expensive. regexp2cg can opt into more expensive analysis with OptionIsCodeGen. So for the + // interpreter we focus only on creating a set for the first character. Same for right-to-left, which + // is used very rarely and thus we don't need to invest in special-casing it. + if f.rightToLeft { + // Determine a set for anything that can possibly start the expression. + set := findFirstCharClass(root) + if set != nil { + var chars []rune + if !set.IsNegated() { + // See if the set is limited to holding only a few characters. + chars = set.GetSetChars(5) + } + + if !codeGen && len(chars) == 1 { + // The set contains one and only one character, meaning every match starts + // with the same literal value (potentially case-insensitive). Search for that. + f.FixedDistanceLiteral.C = chars[0] + f.FindMode = LeadingChar_RightToLeft + } else { + // The set may match multiple characters. Search for that. + f.FixedDistanceSets = []FixedDistanceSet{{ + Chars: chars, + Set: set, + Distance: 0, + }} + f.FindMode = LeadingSet_RightToLeft + f.asciiLookups = make([][]uint, 1) + } + } + return f + } + + // We're now left-to-right only. + + prefix = findPrefixOrdinalCaseInsensitive(root) + if len(prefix) > 1 { + f.LeadingPrefix = prefix + f.FindMode = LeadingString_OrdinalIgnoreCase_LeftToRight + return f + } + + // We're now left-to-right only and looking for multiple prefixes and/or sets. + + // If there are multiple leading strings, we can search for any of them. + // this works in the interpreter, but we avoid it due to additional cost during construction + + if !interpreter { + ciPrefixes := findPrefixes(root, true) + if len(ciPrefixes) > 1 { + f.LeadingPrefixes = ciPrefixes + f.LeadingPrefixesRunes = toRunePrefixes(ciPrefixes) + f.FindMode = LeadingStrings_OrdinalIgnoreCase_LeftToRight + /*SYSTEM_TEXT_REGULAREXPRESSIONS + if usesRfoTryFind { + f.LeadingStrings = helpers.NewSearchValues(f.LeadingPrefixes, true) + }*/ + return f + } + } + + // Build up a list of all of the sets that are a fixed distance from the start of the expression. + fixedDistanceSets := findFixedDistanceSets(root, !interpreter) + + // See if we can make a string of at least two characters long out of those sets. We should have already caught + // one at the beginning of the pattern, but there may be one hiding at a non-zero fixed distance into the pattern. + if len(fixedDistanceSets) > 0 { + bestFixedDistanceString := findFixedDistanceString(fixedDistanceSets) + if bestFixedDistanceString != nil { + f.FindMode = FixedDistanceString_LeftToRight + f.FixedDistanceLiteral = *bestFixedDistanceString + return f + } + } + + // A landmark chain is more selective than a single leading set for shapes like + // /name-separator host-separator domain/. Prefer it before falling back to + // one-position or one-literal candidate searches. + if landmarkChain := findRequiredLandmarkChain(root); landmarkChain != nil { + f.FindMode = RequiredLandmarkChain_LeftToRight + f.LandmarkChain = landmarkChain + return f + } + + // As a backup, see if we can find a literal after a leading atomic loop. That might be better than whatever sets we find, so + // we want to know whether we have one in our pocket before deciding whether to use a leading set (we'll prefer a leading + // set if it's something for which we can search efficiently). + literalAfterLoop := findLiteralFollowingLeadingLoop(root) + + // If we got such sets, we'll likely use them. However, if the best of them is something that doesn't support an efficient + // search and we did successfully find a literal after an atomic loop we could search instead, we prefer the efficient search. + // For example, if we have a negated set, we will still prefer the literal-after-an-atomic-loop because negated sets typically + // contain _many_ characters (e.g. [^a] is everything but 'a') and are thus more likely to very quickly match, which means any + // vectorization employed is less likely to kick in and be worth the startup overhead. + if len(fixedDistanceSets) > 0 { + // Sort the sets by "quality", such that whatever set is first is the one deemed most efficient to use. + // In some searches, we may use multiple sets, so we want the subsequent ones to also be the efficiency runners-up. + slices.SortFunc(fixedDistanceSets, compareFixedDistanceSetsByQuality) + + // If the best fixed-distance set is composed of high-frequency characters, IndexOfAny on + // those characters is likely to match too many positions. Prefer a case-sensitive + // multi-prefix search when one is available. + if !interpreter && !mayContainCaseInsensitiveMatching(root) && hasHighFrequencyChars(fixedDistanceSets[0]) { + caseSensitivePrefixes := findPrefixes(root, false) + if len(caseSensitivePrefixes) > 1 { + f.LeadingPrefixes = caseSensitivePrefixes + f.LeadingPrefixesRunes = toRunePrefixes(caseSensitivePrefixes) + f.FindMode = LeadingStrings_LeftToRight + return f + } + } + + // If there is no literal after the loop, use whatever set we got. + // If there is a literal after the loop, consider it to be better than a negated set and better than a set with many characters. + if literalAfterLoop == nil || (len(fixedDistanceSets[0].Chars) > 0 && !fixedDistanceSets[0].Negated) { + // Determine whether to do searching based on one or more sets or on a single literal. Code-generated engines + // don't need to special-case literals as they already do codegen to create the optimal lookup based on + // the set's characteristics. + if !codeGen && len(fixedDistanceSets) == 1 && len(fixedDistanceSets[0].Chars) == 1 && + !fixedDistanceSets[0].Negated { + f.FixedDistanceLiteral = FixedDistanceLiteral{ + C: fixedDistanceSets[0].Chars[0], + Distance: fixedDistanceSets[0].Distance, + } + f.FindMode = FixedDistanceChar_LeftToRight + } else { + // Limit how many sets we use to avoid doing lots of unnecessary work. The list was already + // sorted from best to worst, so just keep the first ones up to our limit. + const MaxSetsToUse = 3 // arbitrary tuned limit + if len(fixedDistanceSets) > MaxSetsToUse { + fixedDistanceSets = fixedDistanceSets[:MaxSetsToUse] + } + + // Store the sets, and compute which mode to use. + f.FixedDistanceSets = fixedDistanceSets + if len(fixedDistanceSets) == 1 && fixedDistanceSets[0].Distance == 0 { + f.FindMode = LeadingSet_LeftToRight + } else { + f.FindMode = FixedDistanceSets_LeftToRight + } + f.asciiLookups = make([][]uint, len(fixedDistanceSets)) + } + return f + } + } + + // If we found a literal we can search for after a leading set loop, use it. + if literalAfterLoop != nil { + f.FindMode = LiteralAfterLoop_LeftToRight + f.LiteralAfterLoop = literalAfterLoop + f.asciiLookups = make([][]uint, 1) + } + + return f +} + +func (f *FindOptimizations) isUseful() bool { + return f.FindMode != NoSearch || f.LeadingAnchor == NtBol +} + +func toRunePrefixes(prefixes []string) [][]rune { + if len(prefixes) == 0 { + return nil + } + runes := make([][]rune, len(prefixes)) + for i, prefix := range prefixes { + runes[i] = []rune(prefix) + } + return runes +} + +func getFindMode(rtl bool, t NodeType) FindNextStartingPositionMode { + if rtl { + switch t { + case NtBeginning: + return LeadingAnchor_RightToLeft_Beginning + case NtStart: + return LeadingAnchor_RightToLeft_Start + case NtEnd: + return LeadingAnchor_RightToLeft_End + case NtEndZ: + return LeadingAnchor_RightToLeft_EndZ + } + } else { + switch t { + case NtBeginning: + return LeadingAnchor_LeftToRight_Beginning + case NtStart: + return LeadingAnchor_LeftToRight_Start + case NtEnd: + return LeadingAnchor_LeftToRight_End + case NtEndZ: + return LeadingAnchor_LeftToRight_EndZ + } + } + + return NoSearch +} + +// Analyzes a list of fixed-distance sets to extract a case-sensitive string at a fixed distance. +func findFixedDistanceString(fixedDistanceSets []FixedDistanceSet) *FixedDistanceLiteral { + var best *FixedDistanceLiteral + + // A result string must be at least two characters in length; therefore we require at least that many sets. + if len(fixedDistanceSets) >= 2 { + // We're walking the sets from beginning to end, so we need them sorted by distance. + slices.SortFunc(fixedDistanceSets, func(s1, s2 FixedDistanceSet) int { + return cmp.Compare(s1.Distance, s2.Distance) + }) + + vsb := &bytes.Buffer{} + + // Looking for strings of length >= 2 + start := -1 + for i := 0; i < len(fixedDistanceSets)+1; i++ { + chars := []rune(nil) + if i < len(fixedDistanceSets) { + chars = fixedDistanceSets[i].Chars + } + invalidChars := len(chars) != 1 || fixedDistanceSets[i].Negated + + // If the current set ends a sequence (or we've walked off the end), see whether + // what we've gathered constitues a valid string, and if it's better than the + // best we've already seen, store it. Regardless, reset the sequence in order + // to continue analyzing. + if invalidChars || (i > 0 && fixedDistanceSets[i].Distance != fixedDistanceSets[i-1].Distance+1) { + bestLen := 2 + if best != nil { + bestLen = len(best.S) + } + if start != -1 && i-start >= bestLen { + best = &FixedDistanceLiteral{ + S: vsb.String(), + Distance: fixedDistanceSets[start].Distance, + } + } + + vsb.Reset() + start = -1 + if invalidChars { + continue + } + } + + if start == -1 { + start = i + } + + vsb.WriteRune(chars[0]) + } + } + + return best +} diff --git a/vendor/github.com/dlclark/regexp2/syntax/parser.go b/vendor/github.com/dlclark/regexp2/v2/syntax/parser.go similarity index 75% rename from vendor/github.com/dlclark/regexp2/syntax/parser.go rename to vendor/github.com/dlclark/regexp2/v2/syntax/parser.go index 4ff0aaa83..9e9029a8c 100644 --- a/vendor/github.com/dlclark/regexp2/syntax/parser.go +++ b/vendor/github.com/dlclark/regexp2/v2/syntax/parser.go @@ -3,9 +3,9 @@ package syntax import ( "fmt" "math" - "os" "sort" "strconv" + "strings" "unicode" ) @@ -13,16 +13,14 @@ type RegexOptions int32 const ( IgnoreCase RegexOptions = 0x0001 // "i" - Multiline = 0x0002 // "m" - ExplicitCapture = 0x0004 // "n" - Compiled = 0x0008 // "c" - Singleline = 0x0010 // "s" - IgnorePatternWhitespace = 0x0020 // "x" - RightToLeft = 0x0040 // "r" - Debug = 0x0080 // "d" - ECMAScript = 0x0100 // "e" - RE2 = 0x0200 // RE2 compat mode - Unicode = 0x0400 // "u" + Multiline RegexOptions = 0x0002 // "m" + ExplicitCapture RegexOptions = 0x0004 // "n" + Singleline RegexOptions = 0x0010 // "s" + IgnorePatternWhitespace RegexOptions = 0x0020 // "x" + RightToLeft RegexOptions = 0x0040 // "r" + ECMAScript RegexOptions = 0x0100 // "e" + RE2 RegexOptions = 0x0200 // RE2 compat mode + Unicode RegexOptions = 0x0400 // "u" ) func optionFromCode(ch rune) RegexOptions { @@ -40,8 +38,6 @@ func optionFromCode(ch rune) RegexOptions { return Singleline case 'x', 'X': return IgnorePatternWhitespace - case 'd', 'D': - return Debug case 'e', 'E': return ECMAScript case 'u', 'U': @@ -87,6 +83,8 @@ const ( ErrTooManyAlternates = "too many | in (?()|)" ErrUnrecognizedGrouping = "unrecognized grouping construct: (%v" ErrInvalidGroupName = "invalid group name: group names must begin with a word character and have a matching terminator" + ErrInvalidECMAGroupName = "invalid capture group name" + ErrDuplicateGroupName = "duplicate capture group name" ErrCapNumNotZero = "capture number cannot be zero" ErrUndefinedBackRef = "reference to undefined group number %v" ErrUndefinedNameRef = "reference to undefined group name %v" @@ -105,6 +103,7 @@ const ( ErrInvalidHex = "hex values may not be larger than 0x10FFFF" ErrMalformedNameRef = "malformed \\k<...> named back reference" ErrBadClassInCharRange = "cannot include class \\%v in character range" + ErrShorthandClassInCharRange = "cannot create range with shorthand escape sequence \\%v" ErrUnterminatedBracket = "unterminated [] set" ErrSubtractionMustBeLast = "a subtraction must be the last element in a character class" ErrReversedCharRange = "[%c-%c] range in reverse order" @@ -115,17 +114,16 @@ func (e ErrorCode) String() string { } type parser struct { - stack *regexNode - group *regexNode - alternation *regexNode - concatenation *regexNode - unit *regexNode + stack *RegexNode + group *RegexNode + alternation *RegexNode + concatenation *RegexNode + unit *RegexNode patternRaw string pattern []rune - currentPos int - specialCase *unicode.SpecialCase + currentPos int autocap int capcount int @@ -135,6 +133,8 @@ type parser struct { caps map[int]int capnames map[string]int + maintainCaptureOrder bool + capnumlist []int capnamelist []string @@ -143,16 +143,23 @@ type parser struct { ignoreNextParen bool } +type ParseOptions struct { + RegexOptions RegexOptions + MaintainCaptureOrder bool + CodeGen bool +} + const ( maxValueDiv10 int = math.MaxInt32 / 10 maxValueMod10 = math.MaxInt32 % 10 ) // Parse converts a regex string into a parse tree -func Parse(re string, op RegexOptions) (*RegexTree, error) { +func Parse(re string, op ParseOptions) (*RegexTree, error) { p := parser{ - options: op, - caps: make(map[int]int), + options: op.RegexOptions, + caps: make(map[int]int), + maintainCaptureOrder: op.MaintainCaptureOrder || (op.RegexOptions&ECMAScript) != 0, } p.setPattern(re) @@ -160,25 +167,22 @@ func Parse(re string, op RegexOptions) (*RegexTree, error) { return nil, err } - p.reset(op) + p.reset(op.RegexOptions) root, err := p.scanRegex() if err != nil { return nil, err } tree := &RegexTree{ - root: root, - caps: p.caps, - capnumlist: p.capnumlist, - captop: p.captop, + Root: root, + Caps: p.caps, + Capnumlist: p.capnumlist, + Captop: p.captop, Capnames: p.capnames, Caplist: p.capnamelist, - options: op, - } - - if tree.options&Debug > 0 { - os.Stdout.WriteString(tree.Dump()) + Options: op.RegexOptions, } + tree.FindOptimizations = newFindOptimizations(tree, op) return tree, nil } @@ -212,18 +216,32 @@ func (p *parser) noteCaptureSlot(i, pos int) { } } -func (p *parser) noteCaptureName(name string, pos int) { +func (p *parser) noteCaptureName(name string, pos int) error { if p.capnames == nil { p.capnames = make(map[string]int) } if _, ok := p.capnames[name]; !ok { - p.capnames[name] = pos + if p.maintainCaptureOrder { + slot := p.consumeAutocap() + p.capnames[name] = slot + p.noteCaptureSlot(slot, pos) + } else { + p.capnames[name] = pos + } p.capnamelist = append(p.capnamelist, name) + } else if p.useOptionE() { + return p.getErr(ErrDuplicateGroupName) } + return nil } func (p *parser) assignNameSlots() { + if p.maintainCaptureOrder { + p.assignOrderedNameSlots() + return + } + if p.capnames != nil { for _, name := range p.capnamelist { for p.isCaptureSlot(p.autocap) { @@ -293,12 +311,70 @@ func (p *parser) assignNameSlots() { } } +func (p *parser) assignOrderedNameSlots() { + if !p.useOptionE() && p.capnames == nil && p.capcount == p.captop { + return + } + + if p.capcount < p.captop { + p.capnumlist = make([]int, p.capcount) + i := 0 + for k := range p.caps { + p.capnumlist[i] = k + i++ + } + sort.Ints(p.capnumlist) + } + + names := p.capnamelist + p.capnamelist = make([]string, p.capcount) + if p.capnames == nil { + p.capnames = make(map[string]int, p.capcount) + } + + for _, name := range names { + slot := p.capnames[name] + index := slot + if p.capnumlist != nil { + for i, capnum := range p.capnumlist { + if capnum == slot { + index = i + break + } + } + } + p.capnamelist[index] = name + } + + for i := 0; i < p.capcount; i++ { + slot := i + if p.capnumlist != nil { + slot = p.capnumlist[i] + } + if p.useOptionE() { + continue + } + if p.capnamelist[i] == "" { + p.capnamelist[i] = strconv.Itoa(slot) + } + if _, ok := p.capnames[p.capnamelist[i]]; !ok { + p.capnames[p.capnamelist[i]] = slot + } + } +} + func (p *parser) consumeAutocap() int { r := p.autocap p.autocap++ return r } +func (p *parser) consumeCaptureSlot(capnum int) { + if p.maintainCaptureOrder && capnum == p.autocap { + p.consumeAutocap() + } +} + // CountCaptures is a prescanner for deducing the slots used for // captures by doing a partial tokenization of the pattern. func (p *parser) countCaptures() error { @@ -314,17 +390,17 @@ func (p *parser) countCaptures() error { switch ch { case '\\': if p.charsRight() > 0 { - p.scanBackslash(true) + _, _ = p.scanBackslash(true) } case '#': if p.useOptionX() { p.moveLeft() - p.scanBlank() + _ = p.scanBlank() } case '[': - p.scanCharSet(false, true) + _, _ = p.scanCharSet(false, true) case ')': if !p.emptyOptionsStack() { @@ -334,7 +410,7 @@ func (p *parser) countCaptures() error { case '(': if p.charsRight() >= 2 && p.rightChar(1) == '#' && p.rightChar(0) == '?' { p.moveLeft() - p.scanBlank() + _ = p.scanBlank() } else { p.pushOptions() if p.charsRight() > 0 && p.rightChar(0) == '?' { @@ -347,15 +423,27 @@ func (p *parser) countCaptures() error { p.moveRight(1) ch = p.rightChar(0) - if ch != '0' && IsWordChar(ch) { - if ch >= '1' && ch <= '9' { + if ch != '0' && p.isGroupNameStartChar(ch) { + if ch >= '1' && ch <= '9' && !p.useOptionE() { dec, err := p.scanDecimal() if err != nil { return err } - p.noteCaptureSlot(dec, pos) + if p.maintainCaptureOrder { + if err = p.noteCaptureName(strconv.Itoa(dec), pos); err != nil { + return err + } + } else { + p.noteCaptureSlot(dec, pos) + } } else { - p.noteCaptureName(p.scanCapname(), pos) + capname, err := p.scanCapname() + if err != nil { + return err + } + if err = p.noteCaptureName(capname, pos); err != nil { + return err + } } } } else if p.useRE2() && p.charsRight() > 2 && (p.rightChar(0) == 'P' && p.rightChar(1) == '<') { @@ -363,7 +451,13 @@ func (p *parser) countCaptures() error { p.moveRight(2) ch = p.rightChar(0) if IsWordChar(ch) { - p.noteCaptureName(p.scanCapname(), pos) + capname, err := p.scanCapname() + if err != nil { + return err + } + if err = p.noteCaptureName(capname, pos); err != nil { + return err + } } } else { @@ -416,11 +510,11 @@ func (p *parser) reset(topopts RegexOptions) { p.stack = nil } -func (p *parser) scanRegex() (*regexNode, error) { - ch := '@' // nonspecial ch, means at beginning +func (p *parser) scanRegex() (*RegexNode, error) { + var ch rune // nonspecial ch, means at beginning isQuant := false - p.startGroup(newRegexNodeMN(ntCapture, p.options, 0, -1)) + p.startGroup(newRegexNodeMN(NtCapture, p.options, 0, -1)) for p.charsRight() > 0 { wasPrevQuantifier := isQuant @@ -437,8 +531,7 @@ func (p *parser) scanRegex() (*regexNode, error) { if p.useOptionX() { for p.charsRight() > 0 { ch = p.rightChar(0) - //UGLY: clean up, this is ugly - if !(!isStopperX(ch) || (ch == '{' && !p.isTrueQuantifier())) { + if isStopperX(ch) && (ch != '{' || p.isTrueQuantifier()) { break } p.moveRight(1) @@ -446,7 +539,7 @@ func (p *parser) scanRegex() (*regexNode, error) { } else { for p.charsRight() > 0 { ch = p.rightChar(0) - if !(!isSpecial(ch) || ch == '{' && !p.isTrueQuantifier()) { + if isSpecial(ch) && (ch != '{' || p.isTrueQuantifier()) { break } p.moveRight(1) @@ -455,7 +548,9 @@ func (p *parser) scanRegex() (*regexNode, error) { endpos := p.textpos() - p.scanBlank() + if err := p.scanBlank(); err != nil { + return nil, err + } if p.charsRight() == 0 { ch = '!' // nonspecial, means at end @@ -497,6 +592,15 @@ func (p *parser) scanRegex() (*regexNode, error) { p.addUnitSet(cc) case '(': + if p.useRE2() && p.charsRight() >= 3 && p.rightChar(0) == '?' && p.rightChar(1) == 'P' && p.rightChar(2) == '=' { + n, err := p.scanPythonNamedBackref() + if err != nil { + return nil, err + } + p.addUnitNode(n) + break + } + p.pushOptions() if grouper, err := p.scanGroupOpen(); err != nil { @@ -540,16 +644,21 @@ func (p *parser) scanRegex() (*regexNode, error) { case '^': if p.useOptionM() { - p.addUnitType(ntBol) + p.addUnitType(NtBol) } else { - p.addUnitType(ntBeginning) + p.addUnitType(NtBeginning) } case '$': if p.useOptionM() { - p.addUnitType(ntEol) + p.addUnitType(NtEol) + } else if p.useRE2() || p.useOptionE() { + // RE2 and EcmaScript define $ as "asserts position at the end of the string" + // PCRE/.NET adds "or before the line terminator right at the end of the string (if any)" + // which is NtEnd, not NtEndZ + p.addUnitType(NtEnd) } else { - p.addUnitType(ntEndZ) + p.addUnitType(NtEndZ) } case '.': @@ -672,17 +781,17 @@ BreakOuterScan: return nil, err } - return p.unit, nil + return p.unit.finalOptimize(), nil } /* * Simple parsing for replacement patterns */ -func (p *parser) scanReplacement() (*regexNode, error) { +func (p *parser) scanReplacement() (*RegexNode, error) { var c, startpos int - p.concatenation = newRegexNode(ntConcatenate, p.options) + p.concatenation = newRegexNode(NtConcatenate, p.options) for { c = p.charsRight() @@ -717,9 +826,9 @@ func (p *parser) scanReplacement() (*regexNode, error) { /* * Scans $ patterns recognized within replacement patterns */ -func (p *parser) scanDollar() (*regexNode, error) { +func (p *parser) scanDollar() (*RegexNode, error) { if p.charsRight() == 0 { - return newRegexNodeCh(ntOne, p.options, '$'), nil + return newRegexNodeCh(NtOne, p.options, '$'), nil } ch := p.rightChar(0) @@ -767,7 +876,7 @@ func (p *parser) scanDollar() (*regexNode, error) { } p.textto(lastEndPos) if capnum >= 0 { - return newRegexNodeM(ntRef, p.options, capnum), nil + return newRegexNodeM(NtRef, p.options, capnum), nil } } else { capnum, err := p.scanDecimal() @@ -776,16 +885,19 @@ func (p *parser) scanDollar() (*regexNode, error) { } if !angled || p.charsRight() > 0 && p.moveRightGetChar() == '}' { if p.isCaptureSlot(capnum) { - return newRegexNodeM(ntRef, p.options, capnum), nil + return newRegexNodeM(NtRef, p.options, capnum), nil } } } - } else if angled && IsWordChar(ch) { - capname := p.scanCapname() + } else if angled && p.isGroupNameStartChar(ch) { + capname, err := p.scanCapname() + if err != nil { + return nil, err + } if p.charsRight() > 0 && p.moveRightGetChar() == '}' { if p.isCaptureName(capname) { - return newRegexNodeM(ntRef, p.options, p.captureSlotFromName(capname)), nil + return newRegexNodeM(NtRef, p.options, p.captureSlotFromName(capname)), nil } } } else if !angled { @@ -794,7 +906,7 @@ func (p *parser) scanDollar() (*regexNode, error) { switch ch { case '$': p.moveRight(1) - return newRegexNodeCh(ntOne, p.options, '$'), nil + return newRegexNodeCh(NtOne, p.options, '$'), nil case '&': capnum = 0 case '`': @@ -809,22 +921,56 @@ func (p *parser) scanDollar() (*regexNode, error) { if capnum != 1 { p.moveRight(1) - return newRegexNodeM(ntRef, p.options, capnum), nil + return newRegexNodeM(NtRef, p.options, capnum), nil } } // unrecognized $: literalize p.textto(backpos) - return newRegexNodeCh(ntOne, p.options, '$'), nil + return newRegexNodeCh(NtOne, p.options, '$'), nil +} + +func (p *parser) isGroupNameStartChar(ch rune) bool { + if p.useOptionE() { + return IsECMAIdentifierStartChar(ch) || ch == '\\' + } + return IsWordChar(ch) +} + +func (p *parser) scanPythonNamedBackref() (*RegexNode, error) { + p.moveRight(3) + if p.charsRight() == 0 { + return nil, p.getErr(ErrMalformedNameRef) + } + + ch := p.rightChar(0) + if !p.isGroupNameStartChar(ch) { + return nil, p.getErr(ErrInvalidGroupName) + } + + capname, err := p.scanCapname() + if err != nil { + return nil, err + } + + if capname == "" || p.charsRight() == 0 || p.moveRightGetChar() != ')' { + return nil, p.getErr(ErrMalformedNameRef) + } + + if !p.isCaptureName(capname) { + return nil, p.getErr(ErrUndefinedNameRef, capname) + } + + return newRegexNodeM(NtRef, p.options, p.captureSlotFromName(capname)), nil } // scanGroupOpen scans chars following a '(' (not counting the '('), and returns // a RegexNode for the type of group scanned, or nil if the group // simply changed options (?cimsx-cimsx) or was a comment (#...). -func (p *parser) scanGroupOpen() (*regexNode, error) { +func (p *parser) scanGroupOpen() (*RegexNode, error) { var ch rune - var nt nodeType + var nt NodeType var err error close := '>' start := p.textpos() @@ -836,32 +982,28 @@ func (p *parser) scanGroupOpen() (*regexNode, error) { if p.charsRight() == 0 || p.rightChar(0) != '?' || (p.rightChar(0) == '?' && (p.charsRight() > 1 && p.rightChar(1) == ')')) { if p.useOptionN() || p.ignoreNextParen { p.ignoreNextParen = false - return newRegexNode(ntGroup, p.options), nil + return newRegexNode(NtGroup, p.options), nil } - return newRegexNodeMN(ntCapture, p.options, p.consumeAutocap(), -1), nil + return newRegexNodeMN(NtCapture, p.options, p.consumeAutocap(), -1), nil } p.moveRight(1) - for { - if p.charsRight() == 0 { - break - } - + for p.charsRight() > 0 { switch ch = p.moveRightGetChar(); ch { case ':': - nt = ntGroup + nt = NtGroup case '=': p.options &= ^RightToLeft - nt = ntRequire + nt = NtPosLook case '!': p.options &= ^RightToLeft - nt = ntPrevent + nt = NtNegLook case '>': - nt = ntGreedy + nt = NtAtomic case '\'': close = '\'' @@ -879,7 +1021,7 @@ func (p *parser) scanGroupOpen() (*regexNode, error) { } p.options |= RightToLeft - nt = ntRequire + nt = NtPosLook case '!': if close == '\'' { @@ -887,7 +1029,7 @@ func (p *parser) scanGroupOpen() (*regexNode, error) { } p.options |= RightToLeft - nt = ntPrevent + nt = NtNegLook default: p.moveLeft() @@ -897,7 +1039,7 @@ func (p *parser) scanGroupOpen() (*regexNode, error) { // grab part before - - if ch >= '0' && ch <= '9' { + if ch >= '0' && ch <= '9' && !p.useOptionE() { if capnum, err = p.scanDecimal(); err != nil { return nil, err } @@ -907,33 +1049,42 @@ func (p *parser) scanGroupOpen() (*regexNode, error) { } // check if we have bogus characters after the number - if p.charsRight() > 0 && !(p.rightChar(0) == close || p.rightChar(0) == '-') { + if p.charsRight() > 0 && p.rightChar(0) != close && p.rightChar(0) != '-' { return nil, p.getErr(ErrInvalidGroupName) } if capnum == 0 { return nil, p.getErr(ErrCapNumNotZero) } - } else if IsWordChar(ch) { - capname := p.scanCapname() + } else if p.isGroupNameStartChar(ch) { + capname, err := p.scanCapname() + if err != nil { + return nil, err + } if p.isCaptureName(capname) { capnum = p.captureSlotFromName(capname) } // check if we have bogus character after the name - if p.charsRight() > 0 && !(p.rightChar(0) == close || p.rightChar(0) == '-') { + if p.charsRight() > 0 && p.rightChar(0) != close && p.rightChar(0) != '-' { + if p.useOptionE() { + return nil, p.getErr(ErrInvalidECMAGroupName) + } return nil, p.getErr(ErrInvalidGroupName) } } else if ch == '-' { proceed = true } else { // bad group name - starts with something other than a word character and isn't a number + if p.useOptionE() { + return nil, p.getErr(ErrInvalidECMAGroupName) + } return nil, p.getErr(ErrInvalidGroupName) } // grab part after - if any - if (capnum != -1 || proceed == true) && p.charsRight() > 0 && p.rightChar(0) == '-' { + if !p.useOptionE() && (capnum != -1 || proceed) && p.charsRight() > 0 && p.rightChar(0) == '-' { p.moveRight(1) //no more chars left, no closing char, etc @@ -956,7 +1107,10 @@ func (p *parser) scanGroupOpen() (*regexNode, error) { return nil, p.getErr(ErrInvalidGroupName) } } else if IsWordChar(ch) { - uncapname := p.scanCapname() + uncapname, err := p.scanCapname() + if err != nil { + return nil, err + } if !p.isCaptureName(uncapname) { return nil, p.getErr(ErrUndefinedNameRef, uncapname) @@ -976,7 +1130,8 @@ func (p *parser) scanGroupOpen() (*regexNode, error) { // actually make the node if (capnum != -1 || uncapnum != -1) && p.charsRight() > 0 && p.moveRightGetChar() == close { - return newRegexNodeMN(ntCapture, p.options, capnum, uncapnum), nil + p.consumeCaptureSlot(capnum) + return newRegexNodeMN(NtCapture, p.options, capnum, uncapnum), nil } goto BreakRecognize } @@ -996,7 +1151,7 @@ func (p *parser) scanGroupOpen() (*regexNode, error) { } if p.charsRight() > 0 && p.moveRightGetChar() == ')' { if p.isCaptureSlot(capnum) { - return newRegexNodeM(ntTestref, p.options, capnum), nil + return newRegexNodeM(NtBackRefCond, p.options, capnum), nil } return nil, p.getErr(ErrUndefinedReference, capnum) } @@ -1004,15 +1159,18 @@ func (p *parser) scanGroupOpen() (*regexNode, error) { return nil, p.getErr(ErrMalformedReference, capnum) } else if IsWordChar(ch) { - capname := p.scanCapname() + capname, err := p.scanCapname() + if err != nil { + return nil, err + } if p.isCaptureName(capname) && p.charsRight() > 0 && p.moveRightGetChar() == ')' { - return newRegexNodeM(ntTestref, p.options, p.captureSlotFromName(capname)), nil + return newRegexNodeM(NtBackRefCond, p.options, p.captureSlotFromName(capname)), nil } } } // not a backref - nt = ntTestgroup + nt = NtExprCond p.textto(parenPos - 1) // jump to the start of the parentheses p.ignoreNextParen = true // but make sure we don't try to capture the insides @@ -1051,7 +1209,10 @@ func (p *parser) scanGroupOpen() (*regexNode, error) { if IsWordChar(ch) { capnum := -1 - capname := p.scanCapname() + capname, err := p.scanCapname() + if err != nil { + return nil, err + } if p.isCaptureName(capname) { capnum = p.captureSlotFromName(capname) @@ -1065,7 +1226,8 @@ func (p *parser) scanGroupOpen() (*regexNode, error) { // actually make the node if capnum != -1 && p.charsRight() > 0 && p.moveRightGetChar() == '>' { - return newRegexNodeMN(ntCapture, p.options, capnum, -1), nil + p.consumeCaptureSlot(capnum) + return newRegexNodeMN(NtCapture, p.options, capnum, -1), nil } goto BreakRecognize @@ -1081,9 +1243,9 @@ func (p *parser) scanGroupOpen() (*regexNode, error) { default: p.moveLeft() - nt = ntGroup + nt = NtGroup // disallow options in the children of a testgroup node - if p.group.t != ntTestgroup { + if p.group.T != NtExprCond { p.scanOptions() } if p.charsRight() == 0 { @@ -1111,7 +1273,7 @@ BreakRecognize: } // scans backslash specials and basics -func (p *parser) scanBackslash(scanOnly bool) (*regexNode, error) { +func (p *parser) scanBackslash(scanOnly bool) (*RegexNode, error) { if p.charsRight() == 0 { return nil, p.getErr(ErrIllegalEndEscape) @@ -1125,62 +1287,67 @@ func (p *parser) scanBackslash(scanOnly bool) (*regexNode, error) { case 'w': p.moveRight(1) if p.useOptionE() || p.useRE2() { - return newRegexNodeSet(ntSet, p.options, ECMAWordClass()), nil + return newRegexNodeSet(NtSet, p.options, ECMAWordClass()), nil } - return newRegexNodeSet(ntSet, p.options, WordClass()), nil + return newRegexNodeSet(NtSet, p.options, WordClass()), nil case 'W': p.moveRight(1) if p.useOptionE() || p.useRE2() { - return newRegexNodeSet(ntSet, p.options, NotECMAWordClass()), nil + return newRegexNodeSet(NtSet, p.options, NotECMAWordClass()), nil } - return newRegexNodeSet(ntSet, p.options, NotWordClass()), nil + return newRegexNodeSet(NtSet, p.options, NotWordClass()), nil case 's': p.moveRight(1) if p.useOptionE() { - return newRegexNodeSet(ntSet, p.options, ECMASpaceClass()), nil + return newRegexNodeSet(NtSet, p.options, ECMASpaceClass()), nil } else if p.useRE2() { - return newRegexNodeSet(ntSet, p.options, RE2SpaceClass()), nil + return newRegexNodeSet(NtSet, p.options, RE2SpaceClass()), nil } - return newRegexNodeSet(ntSet, p.options, SpaceClass()), nil + return newRegexNodeSet(NtSet, p.options, SpaceClass()), nil case 'S': p.moveRight(1) if p.useOptionE() { - return newRegexNodeSet(ntSet, p.options, NotECMASpaceClass()), nil + return newRegexNodeSet(NtSet, p.options, NotECMASpaceClass()), nil } else if p.useRE2() { - return newRegexNodeSet(ntSet, p.options, NotRE2SpaceClass()), nil + return newRegexNodeSet(NtSet, p.options, NotRE2SpaceClass()), nil } - return newRegexNodeSet(ntSet, p.options, NotSpaceClass()), nil + return newRegexNodeSet(NtSet, p.options, NotSpaceClass()), nil case 'd': p.moveRight(1) if p.useOptionE() || p.useRE2() { - return newRegexNodeSet(ntSet, p.options, ECMADigitClass()), nil + return newRegexNodeSet(NtSet, p.options, ECMADigitClass()), nil } - return newRegexNodeSet(ntSet, p.options, DigitClass()), nil + return newRegexNodeSet(NtSet, p.options, DigitClass()), nil case 'D': p.moveRight(1) if p.useOptionE() || p.useRE2() { - return newRegexNodeSet(ntSet, p.options, NotECMADigitClass()), nil + return newRegexNodeSet(NtSet, p.options, NotECMADigitClass()), nil } - return newRegexNodeSet(ntSet, p.options, NotDigitClass()), nil + return newRegexNodeSet(NtSet, p.options, NotDigitClass()), nil case 'p', 'P': + // skip if we're in ECMAScript mode WITHOUT unicode flag + if p.useOptionE() && !p.useOptionU() { + return p.scanBasicBackslash(scanOnly) + } + p.moveRight(1) prop, err := p.parseProperty() if err != nil { return nil, err } cc := &CharSet{} - cc.addCategory(prop, (ch != 'p'), p.useOptionI(), p.patternRaw) + cc.addCategory(prop, (ch != 'p'), p.useOptionI()) if p.useOptionI() { cc.addLowercase() } - return newRegexNodeSet(ntSet, p.options, cc), nil + return newRegexNodeSet(NtSet, p.options, cc), nil default: return p.scanBasicBackslash(scanOnly) @@ -1188,7 +1355,7 @@ func (p *parser) scanBackslash(scanOnly bool) (*regexNode, error) { } // Scans \-style backreferences and character escapes -func (p *parser) scanBasicBackslash(scanOnly bool) (*regexNode, error) { +func (p *parser) scanBasicBackslash(scanOnly bool) (*RegexNode, error) { if p.charsRight() == 0 { return nil, p.getErr(ErrIllegalEndEscape) } @@ -1205,7 +1372,7 @@ func (p *parser) scanBasicBackslash(scanOnly bool) (*regexNode, error) { // there is at least one group name in the regexp. // See https://www.ecma-international.org/ecma-262/#sec-isvalidregularexpressionliteral, step 7. // Note, during the first (scanOnly) run we may not have all group names scanned, but that's ok. - if ch == 'k' && (!p.useOptionE() || len(p.capnames) > 0) { + if ch == 'k' && (!p.useOptionE() || p.useOptionU() || len(p.capnames) > 0) { if p.charsRight() >= 2 { p.moveRight(1) ch = p.moveRightGetChar() @@ -1249,7 +1416,7 @@ func (p *parser) scanBasicBackslash(scanOnly bool) (*regexNode, error) { if p.charsRight() > 0 && p.moveRightGetChar() == close { if p.isCaptureSlot(capnum) { - return newRegexNodeM(ntRef, p.options, capnum), nil + return newRegexNodeM(NtRef, p.options, capnum), nil } return nil, p.getErr(ErrUndefinedBackRef, capnum) } @@ -1264,14 +1431,17 @@ func (p *parser) scanBasicBackslash(scanOnly bool) (*regexNode, error) { } if p.isCaptureSlot(capnum) { - return newRegexNodeM(ntRef, p.options, capnum), nil + return newRegexNodeM(NtRef, p.options, capnum), nil } if capnum <= 9 && !p.useOptionE() { return nil, p.getErr(ErrUndefinedBackRef, capnum) } } else if angled { - capname := p.scanCapname() + capname, err := p.scanCapname() + if err != nil { + return nil, err + } if capname != "" && p.charsRight() > 0 && p.moveRightGetChar() == close { @@ -1280,7 +1450,7 @@ func (p *parser) scanBasicBackslash(scanOnly bool) (*regexNode, error) { } if p.isCaptureName(capname) { - return newRegexNodeM(ntRef, p.options, p.captureSlotFromName(capname)), nil + return newRegexNodeM(NtRef, p.options, p.captureSlotFromName(capname)), nil } return nil, p.getErr(ErrUndefinedNameRef, capname) } else { @@ -1306,20 +1476,21 @@ func (p *parser) scanBasicBackslash(scanOnly bool) (*regexNode, error) { ch = unicode.ToLower(ch) } - return newRegexNodeCh(ntOne, p.options, ch), nil + return newRegexNodeCh(NtOne, p.options, ch), nil } // Scans X for \p{X} or \P{X} func (p *parser) parseProperty() (string, error) { // RE2 and PCRE supports \pX syntax (no {} and only 1 letter unicode cats supported) // since this is purely additive syntax it's not behind a flag - if p.charsRight() >= 1 && p.rightChar(0) != '{' { + if p.charsRight() >= 1 && p.rightChar(0) != '{' && (!p.useOptionE() || !p.useOptionU()) { ch := string(p.moveRightGetChar()) // check if it's a valid cat - if !isValidUnicodeCat(ch) { + canonical, ok := canonicalUnicodeCatName(ch) + if !ok { return "", p.getErr(ErrUnknownSlashP, ch) } - return ch, nil + return canonical, nil } if p.charsRight() < 3 { @@ -1333,7 +1504,7 @@ func (p *parser) parseProperty() (string, error) { startpos := p.textpos() for p.charsRight() > 0 { ch = p.moveRightGetChar() - if !(IsWordChar(ch) || ch == '-') { + if !IsWordChar(ch) && ch != '-' && ch != '=' { p.moveLeft() break } @@ -1344,36 +1515,37 @@ func (p *parser) parseProperty() (string, error) { return "", p.getErr(ErrIncompleteSlashP) } - if !isValidUnicodeCat(capname) { + canonical, ok := canonicalUnicodeCatName(capname) + if !ok { return "", p.getErr(ErrUnknownSlashP, capname) } - return capname, nil + return canonical, nil } // Returns ReNode type for zero-length assertions with a \ code. -func (p *parser) typeFromCode(ch rune) nodeType { +func (p *parser) typeFromCode(ch rune) NodeType { switch ch { case 'b': if p.useOptionE() { - return ntECMABoundary + return NtECMABoundary } - return ntBoundary + return NtBoundary case 'B': if p.useOptionE() { - return ntNonECMABoundary + return NtNonECMABoundary } - return ntNonboundary + return NtNonboundary case 'A': - return ntBeginning + return NtBeginning case 'G': - return ntStart + return NtStart case 'Z': - return ntEndZ + return NtEndZ case 'z': - return ntEnd + return NtEnd default: - return ntNothing + return NtNothing } } @@ -1425,7 +1597,66 @@ func (p *parser) scanBlank() error { return nil } -func (p *parser) scanCapname() string { +func (p *parser) scanECMACapname() (string, error) { + startpos := p.textpos() + var sb strings.Builder + hasEscape := false + index := 0 + + for p.charsRight() > 0 { + savedpos := p.textpos() + ch := p.moveRightGetChar() + var err error + escaped := false + + if ch == '\\' { + if p.charsRight() == 0 || p.rightChar(0) != 'u' { + return "", p.getErr(ErrInvalidECMAGroupName) + } + escaped = true + p.moveRight(1) + if p.charsRight() > 0 && p.rightChar(0) == '{' { + if !p.useOptionU() { + return "", p.getErr(ErrInvalidECMAGroupName) + } + p.moveRight(1) + ch, err = p.scanHexUntilBrace() + } else { + ch, err = p.scanHex(4) + } + if err != nil { + return "", err + } + if !hasEscape { + sb.WriteString(string(p.pattern[startpos:savedpos])) + hasEscape = true + } + } + + valid := IsECMAIdentifierChar(ch) + if index == 0 { + valid = IsECMAIdentifierStartChar(ch) + } + if !valid { + if escaped { + return "", p.getErr(ErrInvalidECMAGroupName) + } + p.textto(savedpos) + break + } + if hasEscape { + sb.WriteRune(ch) + } + index++ + } + + if hasEscape { + return sb.String(), nil + } + return string(p.pattern[startpos:p.textpos()]), nil +} + +func (p *parser) scanWord() string { startpos := p.textpos() for p.charsRight() > 0 { @@ -1438,9 +1669,17 @@ func (p *parser) scanCapname() string { return string(p.pattern[startpos:p.textpos()]) } +func (p *parser) scanCapname() (string, error) { + if p.useOptionE() { + return p.scanECMACapname() + } + + return p.scanWord(), nil +} + // Scans contents of [] (not including []'s), and converts to a set. func (p *parser) scanCharSet(caseInsensitive, scanOnly bool) (*CharSet, error) { - ch := '\x00' + var ch rune chPrev := '\x00' inRange := false firstChar := true @@ -1478,16 +1717,26 @@ func (p *parser) scanCharSet(caseInsensitive, scanOnly bool) (*CharSet, error) { case 'D', 'd': if !scanOnly { if inRange { - return nil, p.getErr(ErrBadClassInCharRange, ch) + if !p.useOptionE() { + return nil, p.getErr(ErrBadClassInCharRange, ch) + } + cc.addChar(chPrev) + cc.addChar('-') + inRange = false } - cc.addDigit(p.useOptionE() || p.useRE2(), ch == 'D', p.patternRaw) + cc.addDigit(p.useOptionE() || p.useRE2(), ch == 'D') } continue case 'S', 's': if !scanOnly { if inRange { - return nil, p.getErr(ErrBadClassInCharRange, ch) + if !p.useOptionE() { + return nil, p.getErr(ErrBadClassInCharRange, ch) + } + cc.addChar(chPrev) + cc.addChar('-') + inRange = false } cc.addSpace(p.useOptionE(), p.useRE2(), ch == 'S') } @@ -1496,7 +1745,12 @@ func (p *parser) scanCharSet(caseInsensitive, scanOnly bool) (*CharSet, error) { case 'W', 'w': if !scanOnly { if inRange { - return nil, p.getErr(ErrBadClassInCharRange, ch) + if !p.useOptionE() { + return nil, p.getErr(ErrBadClassInCharRange, ch) + } + cc.addChar(chPrev) + cc.addChar('-') + inRange = false } cc.addWord(p.useOptionE() || p.useRE2(), ch == 'W') @@ -1504,17 +1758,44 @@ func (p *parser) scanCharSet(caseInsensitive, scanOnly bool) (*CharSet, error) { continue case 'p', 'P': - if !scanOnly { - if inRange { - return nil, p.getErr(ErrBadClassInCharRange, ch) + if p.useOptionE() && !p.useOptionU() && ch == 'P' && inRange { + return nil, p.getErr(ErrShorthandClassInCharRange, string(ch)) + } + if p.useOptionE() && !p.useOptionU() && ch == 'p' { + if !scanOnly { + if inRange { + if chPrev > ch { + return nil, p.getErr(ErrReversedCharRange, chPrev, ch) + } + cc.addRange(chPrev, ch) + inRange = false + } else if p.charsRight() >= 2 && p.rightChar(0) == '-' && p.rightChar(1) != ']' { + cc.addChar('-') + p.moveRight(1) + chLast := p.moveRightGetChar() + if ch > chLast { + return nil, p.getErr(ErrReversedCharRange, ch, chLast) + } + cc.addRange(ch, chLast) + } else { + cc.addChar(ch) + } } + continue + } + if !scanOnly { prop, err := p.parseProperty() if err != nil { return nil, err } - cc.addCategory(prop, (ch != 'p'), caseInsensitive, p.patternRaw) + if inRange { + return nil, p.getErr(ErrShorthandClassInCharRange, string(ch)) + } + cc.addCategory(prop, (ch != 'p'), caseInsensitive) } else { - p.parseProperty() + if _, err := p.parseProperty(); err != nil { + return nil, err + } } continue @@ -1533,7 +1814,6 @@ func (p *parser) scanCharSet(caseInsensitive, scanOnly bool) (*CharSet, error) { return nil, err } fTranslatedChar = true - break // this break will only break out of the switch } } else if ch == '[' { // This is code for Posix style properties - [:Ll:] or [:IsTibetan:]. @@ -1548,7 +1828,7 @@ func (p *parser) scanCharSet(caseInsensitive, scanOnly bool) (*CharSet, error) { p.moveRight(1) } - nm := p.scanCapname() // snag the name + nm := p.scanWord() // snag the name if !scanOnly && p.useRE2() { // look up the name since these are valid for RE2 // add the group based on the name @@ -1611,7 +1891,7 @@ func (p *parser) scanCharSet(caseInsensitive, scanOnly bool) (*CharSet, error) { } } else { p.moveRight(1) - p.scanCharSet(caseInsensitive, true) + _, _ = p.scanCharSet(caseInsensitive, true) } } else { if !scanOnly { @@ -1659,17 +1939,18 @@ func isOnlyTopOption(option RegexOptions) bool { return option == RightToLeft || option == ECMAScript || option == RE2 } -// Scans cimsx-cimsx option string, stops at the first unrecognized char. +// Scans imnsxu-imnsxu option string, stops at the first unrecognized char. func (p *parser) scanOptions() { for off := false; p.charsRight() > 0; p.moveRight(1) { ch := p.rightChar(0) - if ch == '-' { + switch ch { + case '-': off = true - } else if ch == '+' { + case '+': off = false - } else { + default: option := optionFromCode(ch) if option == 0 || isOnlyTopOption(option) { return @@ -2017,42 +2298,34 @@ func (p *parser) addConcatenate3(lazy bool, min, max int) { // Sets the current unit to a single char node func (p *parser) addUnitOne(ch rune) { - if p.useOptionI() { - ch = unicode.ToLower(ch) - } - - p.unit = newRegexNodeCh(ntOne, p.options, ch) + p.unit = newRegexNodeCh(NtOne, p.options, ch) } // Sets the current unit to a single inverse-char node func (p *parser) addUnitNotone(ch rune) { - if p.useOptionI() { - ch = unicode.ToLower(ch) - } - - p.unit = newRegexNodeCh(ntNotone, p.options, ch) + p.unit = newRegexNodeCh(NtNotone, p.options, ch) } // Sets the current unit to a single set node func (p *parser) addUnitSet(set *CharSet) { - p.unit = newRegexNodeSet(ntSet, p.options, set) + p.unit = newRegexNodeSet(NtSet, p.options, set) } // Sets the current unit to a subtree -func (p *parser) addUnitNode(node *regexNode) { +func (p *parser) addUnitNode(node *RegexNode) { p.unit = node } // Sets the current unit to an assertion of the specified type -func (p *parser) addUnitType(t nodeType) { +func (p *parser) addUnitType(t NodeType) { p.unit = newRegexNode(t, p.options) } // Finish the current group (in response to a ')' or end) func (p *parser) addGroup() error { - if p.group.t == ntTestgroup || p.group.t == ntTestref { + if p.group.T == NtExprCond || p.group.T == NtBackRefCond { p.group.addChild(p.concatenation.reverseLeft()) - if (p.group.t == ntTestref && len(p.group.children) > 2) || len(p.group.children) > 3 { + if (p.group.T == NtBackRefCond && len(p.group.Children) > 2) || len(p.group.Children) > 3 { return p.getErr(ErrTooManyAlternates) } } else { @@ -2085,57 +2358,51 @@ func (p *parser) pushOptions() { // Add a string to the last concatenate. func (p *parser) addToConcatenate(pos, cch int, isReplacement bool) { - var node *regexNode - if cch == 0 { return } + if cch == 1 { + var node *RegexNode - if cch > 1 { - str := make([]rune, cch) - copy(str, p.pattern[pos:pos+cch]) - - if p.useOptionI() && !isReplacement { - // We do the ToLower character by character for consistency. With surrogate chars, doing - // a ToLower on the entire string could actually change the surrogate pair. This is more correct - // linguistically, but since Regex doesn't support surrogates, it's more important to be - // consistent. - for i := 0; i < len(str); i++ { - str[i] = unicode.ToLower(str[i]) - } - } - - node = newRegexNodeStr(ntMulti, p.options, str) - } else { - ch := p.charAt(pos) - - if p.useOptionI() && !isReplacement { - ch = unicode.ToLower(ch) + if isReplacement { + node = newRegexNodeCh(NtOne, p.options&^IgnoreCase, p.pattern[pos]) + } else { + node = newRegexNodeCh(NtOne, p.options, p.pattern[pos]) } + p.concatenation.addChild(node) + return + } - node = newRegexNodeCh(ntOne, p.options, ch) + if cch > 1 && (!p.useOptionI() || isReplacement || !anyParticipateInCaseConversion(p.pattern[pos:pos+cch])) { + str := make([]rune, cch) + copy(str, p.pattern[pos:pos+cch]) + p.concatenation.addChild(newRegexNodeStr(NtMulti, p.options&^IgnoreCase, str)) + return } - p.concatenation.addChild(node) + // each letter gets an upper-lower range + for i := pos; i < pos+cch; i++ { + p.concatenation.addChild(newRegexNodeCh(NtOne, p.options, p.pattern[i])) + } } // Push the parser state (in response to an open paren) func (p *parser) pushGroup() { - p.group.next = p.stack - p.alternation.next = p.group - p.concatenation.next = p.alternation + p.group.Parent = p.stack + p.alternation.Parent = p.group + p.concatenation.Parent = p.alternation p.stack = p.concatenation } // Remember the pushed state (in response to a ')') func (p *parser) popGroup() error { p.concatenation = p.stack - p.alternation = p.concatenation.next - p.group = p.alternation.next - p.stack = p.group.next + p.alternation = p.concatenation.Parent + p.group = p.alternation.Parent + p.stack = p.group.Parent // The first () inside a Testgroup group goes directly to the group - if p.group.t == ntTestgroup && len(p.group.children) == 0 { + if p.group.T == NtExprCond && len(p.group.Children) == 0 { if p.unit == nil { return p.getErr(ErrConditionalExpression) } @@ -2152,33 +2419,33 @@ func (p *parser) emptyStack() bool { } // Start a new round for the parser state (in response to an open paren or string start) -func (p *parser) startGroup(openGroup *regexNode) { +func (p *parser) startGroup(openGroup *RegexNode) { p.group = openGroup - p.alternation = newRegexNode(ntAlternate, p.options) - p.concatenation = newRegexNode(ntConcatenate, p.options) + p.alternation = newRegexNode(NtAlternate, p.options) + p.concatenation = newRegexNode(NtConcatenate, p.options) } // Finish the current concatenation (in response to a |) func (p *parser) addAlternate() { // The | parts inside a Testgroup group go directly to the group - if p.group.t == ntTestgroup || p.group.t == ntTestref { + if p.group.T == NtExprCond || p.group.T == NtBackRefCond { p.group.addChild(p.concatenation.reverseLeft()) } else { p.alternation.addChild(p.concatenation.reverseLeft()) } - p.concatenation = newRegexNode(ntConcatenate, p.options) + p.concatenation = newRegexNode(NtConcatenate, p.options) } // For categorizing ascii characters. const ( Q byte = 5 // quantifier - S = 4 // ordinary stopper - Z = 3 // ScanBlank stopper - X = 2 // whitespace - E = 1 // should be escaped + S byte = 4 // ordinary stopper + Z byte = 3 // ScanBlank stopper + X byte = 2 // whitespace + E byte = 1 // should be escaped ) var _category = []byte{ diff --git a/vendor/github.com/dlclark/regexp2/syntax/prefix.go b/vendor/github.com/dlclark/regexp2/v2/syntax/prefix.go similarity index 73% rename from vendor/github.com/dlclark/regexp2/syntax/prefix.go rename to vendor/github.com/dlclark/regexp2/v2/syntax/prefix.go index f67168862..af5a8c06b 100644 --- a/vendor/github.com/dlclark/regexp2/syntax/prefix.go +++ b/vendor/github.com/dlclark/regexp2/v2/syntax/prefix.go @@ -45,19 +45,19 @@ type regexFcd struct { * and after each child of an interior node, and at each leaf. */ func (s *regexFcd) regexFCFromRegexTree(tree *RegexTree) *regexFc { - curNode := tree.root + curNode := tree.Root curChild := 0 for { - if len(curNode.children) == 0 { + if len(curNode.Children) == 0 { // This is a leaf node - s.calculateFC(curNode.t, curNode, 0) - } else if curChild < len(curNode.children) && !s.skipAllChildren { + s.calculateFC(curNode.T, curNode, 0) + } else if curChild < len(curNode.Children) && !s.skipAllChildren { // This is an interior node, and we have more children to analyze - s.calculateFC(curNode.t|beforeChild, curNode, curChild) + s.calculateFC(curNode.T|BeforeChild, curNode, curChild) if !s.skipchild { - curNode = curNode.children[curChild] + curNode = curNode.Children[curChild] // this stack is how we get a depth first walk of the tree. s.pushInt(curChild) curChild = 0 @@ -77,9 +77,9 @@ func (s *regexFcd) regexFCFromRegexTree(tree *RegexTree) *regexFc { } curChild = s.popInt() - curNode = curNode.next + curNode = curNode.Parent - s.calculateFC(curNode.t|afterChild, curNode, curChild) + s.calculateFC(curNode.T|AfterChild, curNode, curChild) if s.failed { return nil } @@ -153,35 +153,32 @@ func (s *regexFcd) skipChild() { } // FC computation and shortcut cases for each node type -func (s *regexFcd) calculateFC(nt nodeType, node *regexNode, CurIndex int) { +func (s *regexFcd) calculateFC(nt NodeType, node *RegexNode, CurIndex int) { //fmt.Printf("NodeType: %v, CurIndex: %v, Desc: %v\n", nt, CurIndex, node.description()) ci := false rtl := false - if nt <= ntRef { - if (node.options & IgnoreCase) != 0 { + if nt <= NtRef { + if (node.Options & IgnoreCase) != 0 { ci = true } - if (node.options & RightToLeft) != 0 { + if (node.Options & RightToLeft) != 0 { rtl = true } } switch nt { - case ntConcatenate | beforeChild, ntAlternate | beforeChild, ntTestref | beforeChild, ntLoop | beforeChild, ntLazyloop | beforeChild: - break + case NtConcatenate | BeforeChild, NtAlternate | BeforeChild, NtBackRefCond | BeforeChild, NtLoop | BeforeChild, NtLazyloop | BeforeChild: - case ntTestgroup | beforeChild: + case NtExprCond | BeforeChild: if CurIndex == 0 { s.skipChild() } - break - case ntEmpty: + case NtEmpty: s.pushFC(regexFc{nullable: true}) - break - case ntConcatenate | afterChild: + case NtConcatenate | AfterChild: if CurIndex != 0 { child := s.popFC() cumul := s.topFC() @@ -193,81 +190,66 @@ func (s *regexFcd) calculateFC(nt nodeType, node *regexNode, CurIndex int) { if !fc.nullable { s.skipAllChildren = true } - break - case ntTestgroup | afterChild: + case NtExprCond | AfterChild: if CurIndex > 1 { child := s.popFC() cumul := s.topFC() s.failed = !cumul.addFC(*child, false) } - break - case ntAlternate | afterChild, ntTestref | afterChild: + case NtAlternate | AfterChild, NtBackRefCond | AfterChild: if CurIndex != 0 { child := s.popFC() cumul := s.topFC() s.failed = !cumul.addFC(*child, false) } - break - case ntLoop | afterChild, ntLazyloop | afterChild: - if node.m == 0 { + case NtLoop | AfterChild, NtLazyloop | AfterChild: + if node.M == 0 { fc := s.topFC() fc.nullable = true } - break - case ntGroup | beforeChild, ntGroup | afterChild, ntCapture | beforeChild, ntCapture | afterChild, ntGreedy | beforeChild, ntGreedy | afterChild: - break + case NtGroup | BeforeChild, NtGroup | AfterChild, NtCapture | BeforeChild, NtCapture | AfterChild, NtAtomic | BeforeChild, NtAtomic | AfterChild: - case ntRequire | beforeChild, ntPrevent | beforeChild: + case NtPosLook | BeforeChild, NtNegLook | BeforeChild: s.skipChild() s.pushFC(regexFc{nullable: true}) - break - case ntRequire | afterChild, ntPrevent | afterChild: - break + case NtPosLook | AfterChild, NtNegLook | AfterChild: - case ntOne, ntNotone: - s.pushFC(newRegexFc(node.ch, nt == ntNotone, false, ci)) - break + case NtOne, NtNotone: + s.pushFC(newRegexFc(node.Ch, nt == NtNotone, false, ci)) - case ntOneloop, ntOnelazy: - s.pushFC(newRegexFc(node.ch, false, node.m == 0, ci)) - break + case NtOneloop, NtOnelazy, NtOneloopatomic: + s.pushFC(newRegexFc(node.Ch, false, node.M == 0, ci)) - case ntNotoneloop, ntNotonelazy: - s.pushFC(newRegexFc(node.ch, true, node.m == 0, ci)) - break + case NtNotoneloop, NtNotonelazy, NtNotoneloopatomic: + s.pushFC(newRegexFc(node.Ch, true, node.M == 0, ci)) - case ntMulti: - if len(node.str) == 0 { + case NtMulti: + if len(node.Str) == 0 { s.pushFC(regexFc{nullable: true}) } else if !rtl { - s.pushFC(newRegexFc(node.str[0], false, false, ci)) + s.pushFC(newRegexFc(node.Str[0], false, false, ci)) } else { - s.pushFC(newRegexFc(node.str[len(node.str)-1], false, false, ci)) + s.pushFC(newRegexFc(node.Str[len(node.Str)-1], false, false, ci)) } - break - case ntSet: - s.pushFC(regexFc{cc: node.set.Copy(), nullable: false, caseInsensitive: ci}) - break + case NtSet: + s.pushFC(regexFc{cc: node.Set.Copy(), nullable: false, caseInsensitive: ci}) - case ntSetloop, ntSetlazy: - s.pushFC(regexFc{cc: node.set.Copy(), nullable: node.m == 0, caseInsensitive: ci}) - break + case NtSetloop, NtSetlazy, NtSetloopatomic: + s.pushFC(regexFc{cc: node.Set.Copy(), nullable: node.M == 0, caseInsensitive: ci}) - case ntRef: + case NtRef: s.pushFC(regexFc{cc: *AnyClass(), nullable: true, caseInsensitive: false}) - break - case ntNothing, ntBol, ntEol, ntBoundary, ntNonboundary, ntECMABoundary, ntNonECMABoundary, ntBeginning, ntStart, ntEndZ, ntEnd: + case NtNothing, NtBol, NtEol, NtBoundary, NtNonboundary, NtECMABoundary, NtNonECMABoundary, NtBeginning, NtStart, NtEndZ, NtEnd, NtUpdateBumpalong: s.pushFC(regexFc{nullable: true}) - break default: panic(fmt.Sprintf("unexpected op code: %v", nt)) @@ -334,57 +316,57 @@ func (r *regexFc) addFC(fc regexFc, concatenate bool) bool { // This is a related computation: it takes a RegexTree and computes the // leading substring if it sees one. It's quite trivial and gives up easily. func getPrefix(tree *RegexTree) *Prefix { - var concatNode *regexNode + var concatNode *RegexNode nextChild := 0 - curNode := tree.root + curNode := tree.Root for { - switch curNode.t { - case ntConcatenate: - if len(curNode.children) > 0 { + switch curNode.T { + case NtConcatenate: + if len(curNode.Children) > 0 { concatNode = curNode nextChild = 0 } - case ntGreedy, ntCapture: - curNode = curNode.children[0] + case NtAtomic, NtCapture: + curNode = curNode.Children[0] concatNode = nil continue - case ntOneloop, ntOnelazy: - if curNode.m > 0 { + case NtOneloop, NtOnelazy: + if curNode.M > 0 { return &Prefix{ - PrefixStr: repeat(curNode.ch, curNode.m), - CaseInsensitive: (curNode.options & IgnoreCase) != 0, + PrefixStr: repeat(curNode.Ch, curNode.M), + CaseInsensitive: (curNode.Options & IgnoreCase) != 0, } } return nil - case ntOne: + case NtOne: return &Prefix{ - PrefixStr: []rune{curNode.ch}, - CaseInsensitive: (curNode.options & IgnoreCase) != 0, + PrefixStr: []rune{curNode.Ch}, + CaseInsensitive: (curNode.Options & IgnoreCase) != 0, } - case ntMulti: + case NtMulti: return &Prefix{ - PrefixStr: curNode.str, - CaseInsensitive: (curNode.options & IgnoreCase) != 0, + PrefixStr: curNode.Str, + CaseInsensitive: (curNode.Options & IgnoreCase) != 0, } - case ntBol, ntEol, ntBoundary, ntECMABoundary, ntBeginning, ntStart, - ntEndZ, ntEnd, ntEmpty, ntRequire, ntPrevent: + case NtBol, NtEol, NtBoundary, NtECMABoundary, NtBeginning, NtStart, + NtEndZ, NtEnd, NtEmpty, NtPosLook, NtNegLook: default: return nil } - if concatNode == nil || nextChild >= len(concatNode.children) { + if concatNode == nil || nextChild >= len(concatNode.Children) { return nil } - curNode = concatNode.children[nextChild] + curNode = concatNode.Children[nextChild] nextChild++ } } @@ -788,71 +770,71 @@ type AnchorLoc int16 // where the regex can be pegged const ( AnchorBeginning AnchorLoc = 0x0001 - AnchorBol = 0x0002 - AnchorStart = 0x0004 - AnchorEol = 0x0008 - AnchorEndZ = 0x0010 - AnchorEnd = 0x0020 - AnchorBoundary = 0x0040 - AnchorECMABoundary = 0x0080 + AnchorBol AnchorLoc = 0x0002 + AnchorStart AnchorLoc = 0x0004 + AnchorEol AnchorLoc = 0x0008 + AnchorEndZ AnchorLoc = 0x0010 + AnchorEnd AnchorLoc = 0x0020 + AnchorBoundary AnchorLoc = 0x0040 + AnchorECMABoundary AnchorLoc = 0x0080 ) func getAnchors(tree *RegexTree) AnchorLoc { - var concatNode *regexNode + var concatNode *RegexNode nextChild, result := 0, AnchorLoc(0) - curNode := tree.root + curNode := tree.Root for { - switch curNode.t { - case ntConcatenate: - if len(curNode.children) > 0 { + switch curNode.T { + case NtConcatenate: + if len(curNode.Children) > 0 { concatNode = curNode nextChild = 0 } - case ntGreedy, ntCapture: - curNode = curNode.children[0] + case NtAtomic, NtCapture: + curNode = curNode.Children[0] concatNode = nil continue - case ntBol, ntEol, ntBoundary, ntECMABoundary, ntBeginning, - ntStart, ntEndZ, ntEnd: - return result | anchorFromType(curNode.t) + case NtBol, NtEol, NtBoundary, NtECMABoundary, NtBeginning, + NtStart, NtEndZ, NtEnd: + return result | anchorFromType(curNode.T) - case ntEmpty, ntRequire, ntPrevent: + case NtEmpty, NtPosLook, NtNegLook: default: return result } - if concatNode == nil || nextChild >= len(concatNode.children) { + if concatNode == nil || nextChild >= len(concatNode.Children) { return result } - curNode = concatNode.children[nextChild] + curNode = concatNode.Children[nextChild] nextChild++ } } -func anchorFromType(t nodeType) AnchorLoc { +func anchorFromType(t NodeType) AnchorLoc { switch t { - case ntBol: + case NtBol: return AnchorBol - case ntEol: + case NtEol: return AnchorEol - case ntBoundary: + case NtBoundary: return AnchorBoundary - case ntECMABoundary: + case NtECMABoundary: return AnchorECMABoundary - case ntBeginning: + case NtBeginning: return AnchorBeginning - case ntStart: + case NtStart: return AnchorStart - case ntEndZ: + case NtEndZ: return AnchorEndZ - case ntEnd: + case NtEnd: return AnchorEnd default: return 0 @@ -863,28 +845,28 @@ func anchorFromType(t nodeType) AnchorLoc { func (anchors AnchorLoc) String() string { buf := &bytes.Buffer{} - if 0 != (anchors & AnchorBeginning) { + if (anchors & AnchorBeginning) != 0 { buf.WriteString(", Beginning") } - if 0 != (anchors & AnchorStart) { + if (anchors & AnchorStart) != 0 { buf.WriteString(", Start") } - if 0 != (anchors & AnchorBol) { + if (anchors & AnchorBol) != 0 { buf.WriteString(", Bol") } - if 0 != (anchors & AnchorBoundary) { + if (anchors & AnchorBoundary) != 0 { buf.WriteString(", Boundary") } - if 0 != (anchors & AnchorECMABoundary) { + if (anchors & AnchorECMABoundary) != 0 { buf.WriteString(", ECMABoundary") } - if 0 != (anchors & AnchorEol) { + if (anchors & AnchorEol) != 0 { buf.WriteString(", Eol") } - if 0 != (anchors & AnchorEnd) { + if (anchors & AnchorEnd) != 0 { buf.WriteString(", End") } - if 0 != (anchors & AnchorEndZ) { + if (anchors & AnchorEndZ) != 0 { buf.WriteString(", EndZ") } @@ -894,3 +876,68 @@ func (anchors AnchorLoc) String() string { } return "None" } + +func findLeadingOrTrailingAnchor(node *RegexNode, leading bool) NodeType { + for { + switch node.T { + case NtBol, NtEol, NtBeginning, NtStart, NtEndZ, NtEnd, NtBoundary, NtECMABoundary: + // anchor found + return node.T + case NtAtomic, NtCapture: + // For groups, continue exploring the sole child. + node = node.Children[0] + continue + case NtConcatenate: + // For concatenations, we expect primarily to explore its first (for leading) or last (for trailing) child, + // but we can also skip over certain kinds of nodes (e.g. Empty), and thus iterate through its children backward + // looking for the last we shouldn't skip. + var child *RegexNode + + if leading { + for i := 0; i < len(node.Children); i++ { + t := node.Children[i].T + if t != NtEmpty && t != NtPosLook && t != NtNegLook { + child = node.Children[i] + break + } + } + } else { + for i := len(node.Children) - 1; i >= 0; i-- { + t := node.Children[i].T + if t != NtEmpty && t != NtPosLook && t != NtNegLook { + child = node.Children[i] + break + } + } + } + if child != nil { + node = child + continue + } + + case NtAlternate: + // For alternations, every branch needs to lead or trail with the same anchor. + + // Get the leading/trailing anchor of the first branch. If there isn't one, bail. + anchor := findLeadingOrTrailingAnchor(node.Children[0], leading) + if anchor == NtUnknown { + return NtUnknown + } + + // Look at each subsequent branch and validate it has the same leading or trailing + // anchor. If any doesn't, bail. + for i := 1; i < len(node.Children); i++ { + if findLeadingOrTrailingAnchor(node.Children[i], leading) != anchor { + return NtUnknown + } + } + + // All branches have the same leading/trailing anchor. Return it. + return anchor + + } + + // no anchor + return NtUnknown + } +} diff --git a/vendor/github.com/dlclark/regexp2/v2/syntax/prefixanalyzer.go b/vendor/github.com/dlclark/regexp2/v2/syntax/prefixanalyzer.go new file mode 100644 index 000000000..0490585bd --- /dev/null +++ b/vendor/github.com/dlclark/regexp2/v2/syntax/prefixanalyzer.go @@ -0,0 +1,1491 @@ +package syntax + +import ( + "bytes" + "cmp" + "math" + "slices" + "strings" + "unicode" + "unicode/utf8" + "unsafe" +) + +// Computes a character class for the first character in tree. This uses a more robust algorithm +// than is used by TryFindFixedLiterals and thus can find starting sets it couldn't. For example, +// fixed literals won't find the starting set for a*b, as the a isn't guaranteed and the b is at a +// variable position, but this will find [ab] as it's instead looking for anything that under any +// circumstance could possibly start a match. +func findFirstCharClass(root *RegexNode) *CharSet { + // Explore the graph, adding found chars into a result set, which is lazily initialized so that + // we can initialize it to a parsed set if we discover one first (this is helpful not just for allocation + // but because it enables supporting starting negated sets, which wouldn't work if they had to be merged + // into a non-negated default set). If the operation returns true, we successfully explore all relevant nodes + // in the graph. If it returns false, we were unable to successfully explore all relevant nodes, typically + // due to conflicts when trying to add characters into the result set, e.g. we may have read a negated set + // and were then unable to merge into that a subsequent non-negated set. If it returns null, it means the + // whole pattern was nullable such that it could match an empty string, in which case we + // can't make any statements about what begins a match. + var cc *CharSet + if tryFindFirstCharClass(root, &cc) == 1 { + return cc + } + return nil +} + +// Walks the nodes of the expression looking for any node that could possibly match the first +// character of a match, e.g. in `a*b*c+d`, we'd find [abc], or in `(abc|d*e)?[fgh]`, we'd find +// [adefgh]. The function is called for each node, recurring into children where appropriate, +// and returns: +// - 1 if the child was successfully processed and represents a stopping point, e.g. a single +// char loop with a minimum bound greater than 0 such that nothing after that node in a +// concatenation could possibly match the first character. +// - 0 if the child failed to be processed but needed to be, such that the results can't +// be trusted. If any node returns false, the whole operation fails. +// - -1 if the child was successfully processed but doesn't represent a stopping point, i.e. +// it's zero-width (e.g. empty, a lookaround, an anchor, etc.) or it could be zero-width +// (e.g. a loop with a min bound of 0). A concatenation processing a child that returns +// -1 needs to keep processing the next child. +func tryFindFirstCharClass(node *RegexNode, ccIn **CharSet) int { + cc := *ccIn + + switch node.T { + // Base cases where we have results to add to the result set. Add the values into the result set, if possible. + // If this is a loop and it has a lower bound of 0, then it's zero-width, so return null. + case NtOne, NtOneloop, NtOnelazy, NtOneloopatomic: + if cc == nil { + cc = &CharSet{} + *ccIn = cc + } + if cc.IsMergeable() { + cc.addChar(node.Ch) + if node.T == NtOne || node.M > 0 { + return 1 + } + return -1 + } + return 0 + + case NtNotone, NtNotoneloop, NtNotonelazy, NtNotoneloopatomic: + if cc == nil { + cc = &CharSet{} + *ccIn = cc + } + if cc.IsMergeable() { + cc.addChar(node.Ch) + cc.negate = true + /*if node.Ch > 0 { + // Add the range before the excluded char. + cc.addRange(0, (node.Ch - 1)) + } + if node.Ch < unicode.MaxRune { + // Add the range after the excluded char. + cc.addRange(node.Ch+1, unicode.MaxRune) + }*/ + if node.T == NtNotone || node.M > 0 { + return 1 + } + return -1 + } + return 0 + + case NtSet, NtSetloop, NtSetlazy, NtSetloopatomic: + { + setSuccess := false + if cc == nil { + cp := node.Set.Copy() + *ccIn = &cp + setSuccess = true + } else if cc.IsMergeable() && node.Set.IsMergeable() { + cc.addSet(*node.Set) + setSuccess = true + } + if !setSuccess { + return 0 + } else if node.T == NtSet || node.M > 0 { + return 1 + } + return -1 + } + + case NtMulti: + if cc == nil { + cc = &CharSet{} + *ccIn = cc + } + if cc.IsMergeable() { + if node.Options&RightToLeft != 0 { + cc.addChar(node.Str[len(node.Str)-1]) + } else { + cc.addChar(node.Str[0]) + } + return 1 + } + return 0 + + // Zero-width elements. These don't contribute to the starting set, so return null to indicate a caller + // should keep looking past them. + case NtEmpty, NtNothing, NtBol, NtEol, NtBoundary, NtNonboundary, NtECMABoundary, NtNonECMABoundary, + NtBeginning, NtStart, NtEndZ, NtEnd, NtUpdateBumpalong, NtPosLook, NtNegLook: + return -1 + + // Groups. These don't contribute anything of their own, and are just pass-throughs to their children. + case NtAtomic, NtCapture: + return tryFindFirstCharClass(node.Children[0], ccIn) + + // Loops. Like groups, these are mostly pass-through: if the child fails, then the whole operation needs + // to fail, and if the child is nullable, then the loop is as well. However, if the child succeeds but + // the loop has a lower bound of 0, then the loop is still nullable. + case NtLoop, NtLazyloop: + val := tryFindFirstCharClass(node.Children[0], ccIn) + if val <= 0 || node.M != 0 { + return val + } + return -1 + + // Concatenation. Loop through the children as long as they're nullable. The moment a child returns true, + // we don't need or want to look further, as that child represents non-zero-width and nothing beyond it can + // contribute to the starting character set. The moment a child returns false, we need to fail the whole thing. + // If every child is nullable, then the concatenation is also nullable. + case NtConcatenate: + for i := 0; i < len(node.Children); i++ { + childResult := tryFindFirstCharClass(node.Children[i], ccIn) + if childResult != -1 { + return childResult + } + } + return -1 + + // Alternation. Every child is its own fork/branch and contributes to the starting set. As with concatenation, + // the moment any child fails, fail. And if any child is nullable, the alternation is also nullable (since that + // zero-width path could be taken). Otherwise, if every branch returns true, so too does the alternation. + case NtAlternate: + anyChildWasNull := false + for i := 0; i < len(node.Children); i++ { + childResult := tryFindFirstCharClass(node.Children[i], ccIn) + switch childResult { + case -1: + anyChildWasNull = true + case 0: + return 0 + } + } + if anyChildWasNull { + return -1 + } + return 1 + + // Conditionals. Just like alternation for their "yes"/"no" child branches. If either returns false, return false. + // If either is nullable, this is nullable. If both return true, return true. + case NtBackRefCond, NtExprCond: + branchStart := 1 + if node.T == NtBackRefCond { + branchStart = 0 + } + // conditional without all the branches + if branchStart+1 >= len(node.Children) { + return -1 + } + start := tryFindFirstCharClass(node.Children[branchStart], ccIn) + next := tryFindFirstCharClass(node.Children[branchStart+1], ccIn) + if start == -1 || next == -1 { + return -1 + } + if start == 0 || next == 0 { + return 0 + } + return 1 + + // Backreferences. We can't easily make any claims about what content they might match, so just give up. + case NtRef: + return 0 + } + + // Unknown node. + return 0 +} + +// Computes the leading ordinal case-insensitive substring in node +func findPrefixOrdinalCaseInsensitive(node *RegexNode) string { + for { + // Search down the left side of the tree looking for a concatenation. If we find one, + // ask it for any ordinal case-insensitive prefix it has. + switch node.T { + case NtLoop, NtLazyloop: + if node.M <= 0 { + return "" + } + fallthrough + case NtAtomic, NtCapture: + node = node.Children[0] + continue + + case NtConcatenate: + _, _, caseInsensitiveString := node.TryGetOrdinalCaseInsensitiveString(0, len(node.Children), true) + return caseInsensitiveString + + default: + return "" + } + } +} + +// Computes the leading substring in node may be empty. +func findPrefix(node *RegexNode) string { + vsb := &bytes.Buffer{} + tryFindPrefix(node, vsb) + return vsb.String() +} + +// Processes the node, adding any prefix text to the builder. +// Returns whether processing should continue with subsequent nodes. +func tryFindPrefix(node *RegexNode, vsb *bytes.Buffer) bool { + // We don't bother to handle reversed input, so process at most one node + // when handling RightToLeft. + rtl := (node.Options & RightToLeft) != 0 + + switch node.T { + // Concatenation + case NtConcatenate: + for i := 0; i < len(node.Children); i++ { + if !tryFindPrefix(node.Children[i], vsb) { + return false + } + } + return !rtl + // Alternation: find a string that's a shared prefix of all branches + case NtAlternate: + // for RTL we'd need to be matching the suffixes of the alternation cases + if rtl { + return false + } + + // Store the initial branch into the target builder, keeping track + // of how much was appended. Any of this contents that doesn't overlap + // will every other branch will be removed before returning. + initialLength := vsb.Len() + tryFindPrefix(node.Children[0], vsb) + addedLength := vsb.Len() - initialLength + + // Then explore the rest of the branches, finding the length + // of prefix they all share in common with the initial branch. + if addedLength != 0 { + alternateSb := &bytes.Buffer{} + vsbSlice := vsb.Bytes()[initialLength : initialLength+addedLength] + + // Process each branch. If we reach a point where we've proven there's + // no overlap, we can bail early. + for i := 1; i < len(node.Children) && addedLength != 0; i++ { + alternateSb.Reset() + + // Process the branch into a temporary builder. + tryFindPrefix(node.Children[i], alternateSb) + + // Find how much overlap there is between this branch's prefix + // and the smallest amount of prefix that overlapped with all + // the previously seen branches. + addedLength = commonPrefixLen(vsbSlice, alternateSb.Bytes()) + } + + // Then cull back on what was added based on the other branches. + vsb.Truncate(initialLength + addedLength) + } + + // Don't explore anything after the alternation. We could make this work if desirable, + // but it's currently not worth the extra complication. The entire contents of every + // branch would need to be identical other than zero-width anchors/assertions. + return false + + // One character + case NtOne: + vsb.WriteRune(node.Ch) + return !rtl + + // Multiple characters + case NtMulti: + vsb.WriteString(string(node.Str)) + return !rtl + + // Loop of one character + case NtOneloop /*NtOneloopatomic,*/, NtOnelazy: + if node.M <= 0 { + return false + } + // arbitrary cut-off to avoid creating super long strings unnecessarily + count := 32 + if node.M < count { + count = node.M + } + vsb.WriteString(strings.Repeat(string(node.Ch), count)) + return count == node.N && !rtl + + // Loop of a node + case NtLoop, NtLazyloop: + if node.M <= 0 { + return false + } + + // arbitrary cut-off to avoid creating super long strings unnecessarily + limit := 4 + if node.M < limit { + limit = node.M + } + for i := 0; i < limit; i++ { + if tryFindPrefix(node.Children[0], vsb) { + return false + } + } + return limit == node.N && !rtl + + // Grouping nodes for which we only care about their single child + case NtAtomic, NtCapture: + return tryFindPrefix(node.Children[0], vsb) + + // Zero-width anchors and assertions + case NtBol, NtEol, NtBoundary, NtECMABoundary, NtNonboundary, NtNonECMABoundary, NtBeginning, + NtStart, NtEndZ, NtEnd, NtEmpty, NtUpdateBumpalong, NtPosLook, NtNegLook: + return true + } + // Give up for anything else + return false +} + +// commonPrefixLen returns the length of the common prefix of two strings. +func commonPrefixLen(a, b []byte) int { + commonLen := min(len(a), len(b)) + i := 0 + // Optimization: load and compare word-sized chunks at a time. + // This is about 6x faster than the naive approach when len > 64. + // + // TODO(adonovan): further optimizations are possible, + // at the cost of portability, for example by: + // - better elimination of bounds checks; + // - use of uint64 instead of an array may result in better + // registerization, and allows computing the final portion + // from the bitmask: + // + // cmp := load64le(a, i) ^ load64le(b, i) + // if cmp != 0 { + // return i + bits.LeadingZeros64(cmp)/8 + // } + // + // - use of vector instructions in the manner of + // runtime.cmpstring, which is expected to achieve 3x + // further improvement when len > 32. + // + const wordsize = int(unsafe.Sizeof(uint(0))) + var aword, bword [wordsize]byte + for i+wordsize <= commonLen { + copy(aword[:], a[i:i+wordsize]) + copy(bword[:], b[i:i+wordsize]) + if aword != bword { + break + } + i += wordsize + } + // naive implementation + for i < commonLen { + if a[i] != b[i] { + return i + } + i++ + } + return i +} +func min(x, y int) int { + if x < y { + return x + } else { + return y + } +} +func max(x, y int) int { + if x > y { + return x + } else { + return y + } +} + +// Minimum string length for prefixes to be useful. If any prefix has length 1, +// then we're generally better off just using IndexOfAny with chars. +const minPrefixLength = 2 + +// Arbitrary string length limit (with some wiggle room) to avoid creating strings that are longer than is useful and consuming too much memory. +const maxPrefixLength = 8 + +// Arbitrary limit on the number of prefixes to find. If we find more than this, we're likely to be spending too much time finding prefixes that won't be useful. +const maxPrefixes = 16 + +// Finds an array of multiple prefixes that a node can begin with. +// If a fixed set of prefixes is found, such that a match for this node is guaranteed to begin +// with one of those prefixes, an array of those prefixes is returned. Otherwise, null. +func findPrefixes(node *RegexNode, ignoreCase bool) []string { + + // Analyze the node to find prefixes. + results := []*bytes.Buffer{{}} + findPrefixesCore(node, &results, ignoreCase) + + // If we found too many prefixes or if any found is too short, fail. + if len(results) > maxPrefixes || slices.ContainsFunc(results, func(sb *bytes.Buffer) bool { return sb.Len() < minPrefixLength }) { + return nil + } + + // Return the prefixes. + resultStrings := make([]string, len(results)) + for i := 0; i < len(results); i++ { + resultStrings[i] = results[i].String() + } + return resultStrings +} + +// Updates the results list with found prefixes. All existing strings in the list are treated as existing +// discovered prefixes prior to the node being processed. The method returns true if subsequent nodes after +// this one should be examined, or returns false if they shouldn't be because the node wasn't guaranteed +// to be fully processed. +func findPrefixesCore(node *RegexNode, res *[]*bytes.Buffer, ignoreCase bool) bool { + results := *res + // If we're too deep to analyze further, we can't trust what we've already computed, so stop iterating. + // Also bail if any of our results is already hitting the threshold, or if this node is RTL, which is + // not worth the complexity of handling. + // Or if we've already discovered more than the allowed number of prefixes. + + if slices.ContainsFunc(results, func(sb *bytes.Buffer) bool { return sb.Len() >= maxPrefixLength }) || + (node.Options&RightToLeft) != 0 || + len(results) > maxPrefixes { + return false + } + + // These limits are approximations. We'll stop trying to make strings longer once we exceed the max length, + // and if we exceed the max number of prefixes by a non-trivial amount, we'll fail the operation. + // limit how many chars we get from a set based on the max prefixes we care about + //setChars := make([]rune, 0, maxPrefixes) + + // Loop down the left side of the tree, looking for a starting node we can handle. We only loop through + // atomic and capture nodes, as the child is guaranteed to execute once, as well as loops with a positive + // minimum and thus at least one guaranteed iteration. + for { + switch node.T { + // These nodes are all guaranteed to execute at least once, so we can just + // skip through them to their child. + case NtAtomic, NtCapture: + node = node.Children[0] + continue + + // Zero-width anchors and assertions don't impact a prefix and may be skipped over. + case NtBol, NtEol, NtBoundary, NtECMABoundary, NtNonboundary, NtNonECMABoundary, + NtBeginning, NtStart, NtEndZ, NtEnd, NtEmpty, NtUpdateBumpalong, + NtPosLook, NtNegLook: + return true + + // If we hit a single character, we can just return that character. + // This is only relevant for case-sensitive searches, as for case-insensitive we'd have sets for anything + // that produces a different result when case-folded, or for strings composed entirely of characters that + // don't participate in case conversion. Single character loops are handled the same as single characters + // up to the min iteration limit. We can continue processing after them as well if they're repeaters such + // that their min and max are the same. + case NtOne, NtOneloop, NtOnelazy, NtOneloopatomic: + if !ignoreCase || !participatesInCaseConversion(node.Ch) { + reps := maxPrefixLength + if node.T == NtOne { + reps = 1 + } else if node.M < reps { + reps = node.M + } + if reps == 1 { + for _, sb := range results { + sb.WriteRune(node.Ch) + } + } else { + for _, sb := range results { + sb.WriteString(strings.Repeat(string(node.Ch), reps)) + } + } + return node.T == NtOne || reps == node.N + } + + // If we hit a string, we can just return that string. + // As with One above, this is only relevant for case-sensitive searches. + case NtMulti: + if !ignoreCase { + for _, sb := range results { + sb.WriteString(string(node.Str)) + } + } else { + // If we're ignoring case, then only append up through characters that don't participate in case conversion. + // If there are any beyond that, we can't go further and need to stop with what we have. + for _, c := range node.Str { + if participatesInCaseConversion(c) { + return false + } + + for _, sb := range results { + sb.WriteRune(c) + } + } + } + return true + + // For case-sensitive, try to extract the characters that comprise it, and if there are + // any and there aren't more than the max number of prefixes, we can return + // them each as a prefix. Effectively, this is an alternation of the characters + // that comprise the set. For case-insensitive, we need the set to be two ASCII letters that case fold to the same thing. + // As with One and loops, set loops are handled the same as sets up to the min iteration limit. + case NtSet, NtSetloop, NtSetlazy, NtSetloopatomic: + + setChars := node.Set.GetSetChars(maxPrefixes) + + if len(setChars) == 0 { + return false + } + + reps := maxPrefixLength + if node.T == NtSet { + reps = 1 + } else if node.M < reps { + reps = node.M + } + if !ignoreCase { + for rep := 0; rep < reps; rep++ { + existingCount := len(results) + if existingCount*len(setChars) > maxPrefixes { + return false + } + + // Duplicate all of the existing strings for all of the new suffixes, other than the first. + for _, suffix := range setChars[1:] { + for existing := 0; existing < existingCount; existing++ { + newSb := bytes.NewBuffer(slices.Clone(results[existing].Bytes())) + newSb.WriteRune(suffix) + results = append(results, newSb) + } + } + *res = results + + // Then append the first suffix to all of the existing strings. + for existing := 0; existing < existingCount; existing++ { + results[existing].WriteRune(setChars[0]) + } + } + } else { + // For ignore-case, we currently only handle the simple (but common) case of a single + // ASCII character that case folds to the same char. + ok, setChars := node.Set.containsAsciiIgnoreCaseCharacter() + if !ok { + return false + } + + // Append it to each. + for _, sb := range results { + sb.WriteString(strings.Repeat(string(setChars[1]), reps)) + } + } + + *res = results + return node.T == NtSet || reps == node.N + + case NtConcatenate: + for i := 0; i < len(node.Children); i++ { + if !findPrefixesCore(node.Children[i], res, ignoreCase) { + return false + } + } + + return true + + // We can append any guaranteed iterations as if they were a concatenation. + case NtLoop, NtLazyloop: + if node.M > 0 { + // MaxPrefixLength here is somewhat arbitrary, as a single loop iteration could yield multiple chars + limit := maxPrefixLength + if node.M < limit { + limit = node.M + } + for i := 0; i < limit; i++ { + if !findPrefixesCore(node.Children[0], res, ignoreCase) { + return false + } + } + return limit == node.N + } + + // For alternations, we need to find a prefix for every branch; if we can't compute a + // prefix for any one branch, we can't trust the results and need to give up, since we don't + // know if our set of prefixes is complete. + case NtAlternate: + + // If there are more children than our maximum, just give up immediately, as we + // won't be able to get a prefix for every branch and have it be within our max. + if len(node.Children) > maxPrefixes { + return false + } + + // Build up the list of all prefixes across all branches. + var allBranchResults []*bytes.Buffer + alternateBranchResults := []*bytes.Buffer{{}} + for i := 0; i < len(node.Children); i++ { + findPrefixesCore(node.Children[i], &alternateBranchResults, ignoreCase) + + // If we now have too many results, bail. + if len(allBranchResults)+len(alternateBranchResults) > maxPrefixes { + return false + } + + for _, sb := range alternateBranchResults { + // If a branch yields an empty prefix, then none of the other branches + // matter, e.g. if the pattern is abc(def|ghi|), then this would result + // in prefixes abcdef, abcghi, and abc, and since abc is a prefix of both + // abcdef and abcghi, the former two would never be used. + if sb.Len() == 0 { + return false + } + } + + if allBranchResults == nil { + allBranchResults = alternateBranchResults + alternateBranchResults = []*bytes.Buffer{{}} + } else { + allBranchResults = append(allBranchResults, alternateBranchResults...) + alternateBranchResults = []*bytes.Buffer{{}} + } + } + + // At this point, we know we can successfully incorporate the alternation's results + // into the main results. + + // If the results are currently empty (meaning a single empty StringBuilder), we can remove + // that builder and just replace the results with the alternation's results. We would otherwise + // be creating a dot product of every builder in the results with every branch's result, which + // is logically the same thing. + if len(results) == 1 && results[0].Len() == 0 { + results = allBranchResults + } else { + existingCount := len(results) + + // Duplicate all of the existing strings for all of the new suffixes, other than the first. + for i := 1; i < len(allBranchResults); i++ { + suffix := allBranchResults[i] + for existing := 0; existing < existingCount; existing++ { + newSb := &bytes.Buffer{} + newSb.Write(results[existing].Bytes()) + newSb.Write(suffix.Bytes()) + results = append(results, newSb) + } + } + + // Then append the first suffix to all of the existing strings. + for existing := 0; existing < existingCount; existing++ { + results[existing].Write(allBranchResults[0].Bytes()) + } + } + *res = results + + // We don't know that we fully processed every branch, so we can't iterate through what comes after this node. + // The results were successfully updated, but return false to indicate that nothing after this node should be examined. + } + return false + } +} + +const maxLoopExpansion = 20 // arbitrary cut-off to avoid loops adding significant overhead to processing +const maxFixedResults = 50 // arbitrary cut-off to avoid generating lots of sets unnecessarily + +// Finds sets at fixed-offsets from the beginning of the pattern/ +// set "thorough" to true to spend more time finding sets (e.g. through alternations); false to do a faster analysis that's potentially more incomplete. +// Returns the array of found sets, or null if there aren't any. +func findFixedDistanceSets(root *RegexNode, thorough bool) []FixedDistanceSet { + + // Find all fixed-distance sets. + results := []FixedDistanceSet{} + distance := 0 + tryFindRawFixedSets(root, &results, &distance, thorough) + + // Remove any sets that match everything; they're not helpful. (This check exists primarily to weed + // out use of . in Singleline mode, but also filters out explicit sets like [\s\S].) + results = slices.DeleteFunc(results, func(s FixedDistanceSet) bool { return s.Set.IsAnything() }) + + // If we don't have any results, try harder to compute one for the starting character. + // This is a more involved computation that can find things the fixed-distance investigation + // doesn't. + if len(results) == 0 { + // weed out match-all, same as above + c := findFirstCharClass(root) + if c == nil || c.IsAnything() { + return nil + } + + results = append(results, FixedDistanceSet{Set: c, Distance: 0}) + } + + // For every entry, try to get the chars that make up the set, if there are few enough. + // For any for which we couldn't get the small chars list, see if we can get other useful info. + //scratch := make([]rune, 0, 128) + for i := 0; i < len(results); i++ { + result := results[i] + result.Negated = result.Set.IsNegated() + + // prefer IndexOfAny for tiny sets of 1 or 2 elements + if r := result.Set.GetIfNRanges(1); len(r) == 1 && r[0].Last-r[0].First > 1 { + result.Range = &r[0] + } else { + scratch := result.Set.GetSetChars(128) + if len(scratch) > 0 { + result.Chars = scratch + } + } + + results[i] = result + } + + return results +} + +// Starting from the specified root node, populates results with any characters at a fixed distance +// from the node's starting position. The function returns true if the entire contents of the node +// is at a fixed distance, in which case distance will have been updated to include the full length +// of the node. If it returns false, the node isn't entirely fixed, in which case subsequent nodes +// shouldn't be examined and distance should no longer be trusted. However, regardless of whether it +// returns true or false, it may have populated results, and all populated results are valid. All +// FixedDistanceSet result will only have its Set string and Distance populated; the rest is left +// to be populated by FindFixedDistanceSets after this returns. +func tryFindRawFixedSets(node *RegexNode, res *[]FixedDistanceSet, distance *int, thorough bool) bool { + results := *res + if node.Options&RightToLeft != 0 { + return false + } + + switch node.T { + case NtOne: + if len(results) < maxFixedResults { + set := &CharSet{} + set.addChar(node.Ch) + results = append(results, FixedDistanceSet{Set: set, Distance: *distance}) + *res = results + *distance++ + return true + } + return false + + case NtOnelazy, NtOneloop, NtOneloopatomic: + if node.M > 0 { + set := &CharSet{} + set.addChar(node.Ch) + minIterations := maxLoopExpansion + if node.M < minIterations { + minIterations = node.M + } + i := 0 + for ; i < minIterations && len(results) < maxFixedResults; i++ { + results = append(results, FixedDistanceSet{Set: set, Distance: *distance}) + *distance++ + } + *res = results + return i == node.M && i == node.N + } + + case NtMulti: + i := 0 + for ; i < len(node.Str) && len(results) < maxFixedResults; i++ { + set := &CharSet{} + set.addChar(node.Str[i]) + results = append(results, FixedDistanceSet{Set: set, Distance: *distance}) + *distance++ + } + *res = results + return i == len(node.Str) + + case NtSet: + if len(results) < maxFixedResults { + results = append(results, FixedDistanceSet{Set: node.Set, Distance: *distance}) + *res = results + *distance++ + return true + } + return false + + case NtSetlazy, NtSetloop, NtSetloopatomic: + if node.M > 0 { + minIterations := maxLoopExpansion + if node.M < minIterations { + minIterations = node.M + } + i := 0 + for ; i < minIterations && len(results) < maxFixedResults; i++ { + results = append(results, FixedDistanceSet{Set: node.Set, Distance: *distance}) + *distance++ + } + *res = results + return i == node.M && i == node.N + } + + case NtNotone: + // We could create a set out of Notone, but it will be of little value in helping to improve + // the speed of finding the first place to match, as almost every character will match it. + *distance++ + return true + + case NtNotonelazy, NtNotoneloop, NtNotoneloopatomic: + if node.M == node.N { + *distance += node.M + return true + } + case NtBeginning, NtBol, NtBoundary, NtECMABoundary, NtEmpty, NtEnd, NtEndZ, NtEol, + NtNonboundary, NtNonECMABoundary, NtUpdateBumpalong, + NtStart, NtNegLook, NtPosLook: + // Zero-width anchors and assertions. In theory, for PositiveLookaround and NegativeLookaround we could also + // investigate them and use the learned knowledge to impact the generated sets, at least for lookaheads. + // For now, we don't bother. + return true + + case NtAtomic, NtGroup, NtCapture: + return tryFindRawFixedSets(node.Children[0], res, distance, thorough) + + case NtLazyloop, NtLoop: + if node.M > 0 { + // This effectively only iterates the loop once. If deemed valuable, + // it could be updated in the future to duplicate the found results + // (updated to incorporate distance from previous iterations) and + // summed distance for all node.M iterations. If node.M == node.N, + // this would then also allow continued evaluation of the rest of the + // expression after the loop. + tryFindRawFixedSets(node.Children[0], res, distance, thorough) + return false + } + + case NtConcatenate: + for i := 0; i < len(node.Children); i++ { + if !tryFindRawFixedSets(node.Children[i], res, distance, thorough) { + return false + } + } + return true + + case NtAlternate: + if thorough { + allSameSize := true + sameDistance := -1 + var combined = make(map[int]struct { + Set *CharSet + Count int + }) + var localResults []FixedDistanceSet + + for i := 0; i < len(node.Children); i++ { + localResults = []FixedDistanceSet{} + localDistance := 0 + allSameSize = allSameSize && tryFindRawFixedSets(node.Children[i], &localResults, &localDistance, thorough) + + if len(localResults) == 0 { + return false + } + + if allSameSize { + if sameDistance == -1 { + sameDistance = localDistance + } else if sameDistance != localDistance { + allSameSize = false + } + } + + for _, fixedSet := range localResults { + if v, ok := combined[fixedSet.Distance]; ok { + if v.Set.IsMergeable() && fixedSet.Set.IsMergeable() { + v.Set.addSet(*fixedSet.Set) + v.Count++ + combined[fixedSet.Distance] = v + } + } else { + combined[fixedSet.Distance] = struct { + Set *CharSet + Count int + }{Set: fixedSet.Set, Count: 1} + } + } + } + + for k, v := range combined { + if len(results) >= maxFixedResults { + allSameSize = false + break + } + + if v.Count == len(node.Children) { + results = append(results, FixedDistanceSet{Set: v.Set, Distance: k + *distance}) + } + } + *res = results + + if allSameSize { + *distance += sameDistance + return true + } + + return false + } + } + return false +} + +// CompareFunc for a set of fixed-distance set results from best to worst quality. +func compareFixedDistanceSetsByQuality(s1, s2 FixedDistanceSet) int { + // Finally, try to move the "best" results to be earlier. "best" here are ones we're able to search + // for the fastest and that have the best chance of matching as few false positives as possible. + s1RangeLength := getRangeLength(s1.Range, s1.Negated) + s2RangeLength := getRangeLength(s2.Range, s2.Negated) + + // If one set is negated and the other isn't, prefer the non-negated set. In general, negated + // sets are large and thus likely to match more frequently, making them slower to search for. + if s1.Negated != s2.Negated { + if s2.Negated { + return -1 + } + return 1 + } + + // If we extracted only a few chars and the sets are negated, they both represent very large + // sets that are difficult to compare for quality. + if !s1.Negated { + // If both have chars, prioritize the one with the smaller frequency for those chars. + if len(s1.Chars) > 0 && len(s2.Chars) > 0 { + // Prefer sets with less frequent values. The frequency is only an approximation, + // used as a tie-breaker when we'd otherwise effectively be picking randomly. + // True frequencies will vary widely based on the actual data being searched, the language of the data, etc. + s1Frequency := sumFrequencies(s1.Chars) + s2Frequency := sumFrequencies(s2.Chars) + + if s1Frequency != s2Frequency { + return cmp.Compare(s1Frequency, s2Frequency) + } + + if !isAsciiRunes(s1.Chars) && !isAsciiRunes(s2.Chars) { + // Prefer the set with fewer values. + return cmp.Compare(len(s1.Chars), len(s2.Chars)) + } + } + + // If one has chars and the other has a range, prefer the shorter set. + if (len(s1.Chars) > 0 && s2RangeLength > 0) || (s1RangeLength > 0 && len(s2.Chars) > 0) { + s1Len := s1RangeLength + if len(s1.Chars) > s1Len { + s1Len = len(s1.Chars) + } + s2Len := s2RangeLength + if len(s2.Chars) > s2Len { + s2Len = len(s2.Chars) + } + c := cmp.Compare(s1Len, s2Len) + if c != 0 { + return c + } + + // If lengths are the same, prefer the chars. + if len(s1.Chars) > 0 { + return -1 + } + return 1 + } + + // If one has chars and the other doesn't, prioritize the one with chars. + if (len(s1.Chars) > 0) != (len(s2.Chars) > 0) { + if len(s1.Chars) > 0 { + return -1 + } + return 1 + } + } + + // If one has a range and the other doesn't, prioritize the one with a range. + if (s1RangeLength > 0) != (s2RangeLength > 0) { + if s1RangeLength > 0 { + return -1 + } + return 1 + } + + // If both have ranges, prefer the one that includes fewer characters. + if s1RangeLength > 0 { + return cmp.Compare(s1RangeLength, s2RangeLength) + } + + // As a tiebreaker, prioritize the earlier one. + return cmp.Compare(s1.Distance, s2.Distance) +} + +func getRangeLength(r *SingleRange, negated bool) int { + if r == nil { + return 0 + } + if negated { + return int(unicode.MaxRune - (r.Last - r.First)) + } + return int(r.Last - r.First + 1) +} + +func sumFrequencies(chars []rune) float32 { + var sum float32 + for _, c := range chars { + // Lookup each character in the table. Values >= 128 are ignored + // and thus we'll get skew in the data. It's already a gross approximation, though, + // and it is primarily meant for disambiguation of ASCII letters. + if c < unicode.MaxASCII { + sum += frequency[c] + } + } + return sum +} + +func hasHighFrequencyChars(set FixedDistanceSet) bool { + if set.Negated { + return true + } + + // Sets without extracted chars can't be frequency-analyzed. + // Single-char sets use IndexOf, which is a strong filter regardless of frequency. + if len(set.Chars) <= 1 { + return false + } + + totalFrequency := sumFrequencies(set.Chars) + + // If the average frequency of the set's chars exceeds this threshold, the + // characters are common enough that a multi-string search may be a better filter. + const highFrequencyThreshold = 0.6 + return totalFrequency >= highFrequencyThreshold*float32(len(set.Chars)) +} + +func mayContainCaseInsensitiveMatching(node *RegexNode) bool { + if node.Options&IgnoreCase != 0 { + return true + } + + if node.Set != nil { + chars := node.Set.GetSetChars(maxPrefixes) + for _, ch := range chars { + if participatesInCaseConversion(ch) && + slices.Contains(chars, unicode.ToLower(ch)) && + slices.Contains(chars, unicode.ToUpper(ch)) { + return true + } + } + } + + for _, child := range node.Children { + if mayContainCaseInsensitiveMatching(child) { + return true + } + } + + return false +} + +// Percent occurrences in source text (100 * char count / total count) +var frequency = []float32{ + 0.000 /* '\x00' */, 0.000 /* '\x01' */, 0.000 /* '\x02' */, 0.000 /* '\x03' */, 0.000 /* '\x04' */, 0.000 /* '\x05' */, 0.000 /* '\x06' */, 0.000, /* '\x07' */ + 0.000 /* '\x08' */, 0.001 /* '\x09' */, 0.000 /* '\x0A' */, 0.000 /* '\x0B' */, 0.000 /* '\x0C' */, 0.000 /* '\x0D' */, 0.000 /* '\x0E' */, 0.000, /* '\x0F' */ + 0.000 /* '\x10' */, 0.000 /* '\x11' */, 0.000 /* '\x12' */, 0.000 /* '\x13' */, 0.003 /* '\x14' */, 0.000 /* '\x15' */, 0.000 /* '\x16' */, 0.000, /* '\x17' */ + 0.000 /* '\x18' */, 0.004 /* '\x19' */, 0.000 /* '\x1A' */, 0.000 /* '\x1B' */, 0.006 /* '\x1C' */, 0.006 /* '\x1D' */, 0.000 /* '\x1E' */, 0.000, /* '\x1F' */ + 8.952 /* ' ' */, 0.065 /* ' !' */, 0.420 /* ' "' */, 0.010 /* ' #' */, 0.011 /* ' $' */, 0.005 /* ' %' */, 0.070 /* ' &' */, 0.050, /* ' '' */ + 3.911 /* ' (' */, 3.910 /* ' )' */, 0.356 /* ' *' */, 2.775 /* ' +' */, 1.411 /* ' ,' */, 0.173 /* ' -' */, 2.054 /* ' .' */, 0.677, /* ' /' */ + 1.199 /* ' 0' */, 0.870 /* ' 1' */, 0.729 /* ' 2' */, 0.491 /* ' 3' */, 0.335 /* ' 4' */, 0.269 /* ' 5' */, 0.435 /* ' 6' */, 0.240, /* ' 7' */ + 0.234 /* ' 8' */, 0.196 /* ' 9' */, 0.144 /* ' :' */, 0.983 /* ' ;' */, 0.357 /* ' <' */, 0.661 /* ' =' */, 0.371 /* ' >' */, 0.088, /* ' ?' */ + 0.007 /* ' @' */, 0.763 /* ' A' */, 0.229 /* ' B' */, 0.551 /* ' C' */, 0.306 /* ' D' */, 0.449 /* ' E' */, 0.337 /* ' F' */, 0.162, /* ' G' */ + 0.131 /* ' H' */, 0.489 /* ' I' */, 0.031 /* ' J' */, 0.035 /* ' K' */, 0.301 /* ' L' */, 0.205 /* ' M' */, 0.253 /* ' N' */, 0.228, /* ' O' */ + 0.288 /* ' P' */, 0.034 /* ' Q' */, 0.380 /* ' R' */, 0.730 /* ' S' */, 0.675 /* ' T' */, 0.265 /* ' U' */, 0.309 /* ' V' */, 0.137, /* ' W' */ + 0.084 /* ' X' */, 0.023 /* ' Y' */, 0.023 /* ' Z' */, 0.591 /* ' [' */, 0.085 /* ' \' */, 0.590 /* ' ]' */, 0.013 /* ' ^' */, 0.797, /* ' _' */ + 0.001 /* ' `' */, 4.596 /* ' a' */, 1.296 /* ' b' */, 2.081 /* ' c' */, 2.005 /* ' d' */, 6.903 /* ' e' */, 1.494 /* ' f' */, 1.019, /* ' g' */ + 1.024 /* ' h' */, 3.750 /* ' i' */, 0.286 /* ' j' */, 0.439 /* ' k' */, 2.913 /* ' l' */, 1.459 /* ' m' */, 3.908 /* ' n' */, 3.230, /* ' o' */ + 1.444 /* ' p' */, 0.231 /* ' q' */, 4.220 /* ' r' */, 3.924 /* ' s' */, 5.312 /* ' t' */, 2.112 /* ' u' */, 0.737 /* ' v' */, 0.573, /* ' w' */ + 0.992 /* ' x' */, 1.067 /* ' y' */, 0.181 /* ' z' */, 0.391 /* ' {' */, 0.056 /* ' |' */, 0.391 /* ' }' */, 0.002 /* ' ~' */, 0.000, /* '\x7F' */ +} + +// The above table was generated programmatically with the following. This can be augmented to incorporate additional data sources, +// though it is only intended to be a rough approximation use when tie-breaking and we'd otherwise be picking randomly, so, it's something. +// The frequencies may be wildly inaccurate when used with data sources different in nature than the training set, in which case we shouldn't +// be much worse off than just picking randomly: +// +// using System.Runtime.InteropServices; +// +// var counts = new Dictionary(); +// +// (string, string)[] rootsAndExtensions = new[] +// { +// (@"d:\repos\runtime\src\", "*.cs"), // C# files in dotnet/runtime +// (@"d:\Top25GutenbergBooks", "*.txt"), // Top 25 most popular books on Project Gutenberg +// }; +// +// foreach ((string root, string ext) in rootsAndExtensions) +// foreach (string path in Directory.EnumerateFiles(root, ext, SearchOption.AllDirectories)) +// foreach (string line in File.ReadLines(path)) +// foreach (char c in line.AsSpan().Trim()) +// CollectionsMarshal.GetValueRefOrAddDefault(counts, (byte)c, out _)++; +// +// long total = counts.Sum(i => i.Value); +// +// Console.WriteLine("/// Percent occurrences in source text (100 * char count / total count)."); +// Console.WriteLine("private static ReadOnlySpan Frequency =>"); +// Console.WriteLine("["); +// int i = 0; +// for (int row = 0; row < 16; row++) +// { +// Console.Write(" "); +// for (int col = 0; col < 8; col++) +// { +// counts.TryGetValue((byte)i, out long charCount); +// float frequency = (float)(charCount / (double)total) * 100; +// Console.Write($" {frequency:N3}f /* '{(i >= 32 && i < 127 ? $" {(char)i}" : $"\\x{i:X2}")}' */,"); +// i++; +// } +// Console.WriteLine(); +// } +// Console.WriteLine("];"); + +// / +// / Analyzes the pattern for a leading set loop followed by a non-overlapping literal. If such a pattern is found, an implementation +// / can search for the literal and then walk backward through all matches for the loop until the beginning is found. +// / +func findLiteralFollowingLeadingLoop(node *RegexNode) *LiteralAfterLoop { + if (node.Options & RightToLeft) != 0 { + // As a simplification, ignore RightToLeft. + return nil + } + + // Find the first concatenation. We traverse through atomic and capture nodes as they don't effect flow control. (We don't + // want to explore loops, even if they have a guaranteed iteration, because we may use information about the node to then + // skip the node's execution in the matching algorithm, and we would need to special-case only skipping the first iteration.) + for node.T == NtAtomic || node.T == NtCapture { + node = node.Children[0] + } + if node.T != NtConcatenate { + return nil + } + + // Bail if the first node isn't a set loop. We treat any kind of set loop (Setloop, Setloopatomic, and Setlazy) + // the same because of two important constraints: the loop must not have an upper bound, and the literal we look + // for immediately following it must not overlap. With those constraints, all three of these kinds of loops will + // end up having the same semantics; in fact, if atomic optimizations are used, we will have converted Setloop + // into a Setloopatomic (but those optimizations are disabled for NonBacktracking in general). This + // could also be made to support Oneloopatomic and Notoneloopatomic, but the scenarios for that are rare. + firstChild := node.Children[0] + for firstChild.T == NtAtomic || firstChild.T == NtCapture { + firstChild = firstChild.Children[0] + } + if (firstChild.T != NtSetloop && firstChild.T != NtSetloopatomic && firstChild.T != NtSetlazy) || + firstChild.N != math.MaxInt32 { + return nil + } + + // Get the subsequent node. An UpdateBumpalong may have been added as an optimization, but it doesn't have an + // impact on semantics and we can skip it. + nextChild := node.Children[1] + if nextChild.T == NtUpdateBumpalong { + if len(node.Children) == 2 { + // If the UpdateBumpalong is the last node, nothing meaningful follows the set loop. + return nil + } + nextChild = node.Children[2] + } + nextChild = unwrapImmediateLiteralAfterLoopNode(nextChild) + if nextChild == nil { + return nil + } + + // Is the set loop followed by a case-sensitive string we can search for? + if prefix := findPrefix(nextChild); len(prefix) >= 1 { + // The literal can be searched for as either a single char or as a string. + // But we need to make sure that its starting character isn't part of the preceding + // set, as then we can't know for certain where the set loop ends. + if firstChild.Set.CharIn(rune(prefix[0])) { + return nil + } else if len(prefix) == 1 { + return &LiteralAfterLoop{ + LoopNode: firstChild, + Char: rune(prefix[0]), + } + } + return &LiteralAfterLoop{ + LoopNode: firstChild, + String: prefix, + } + } + + // Is the set loop followed by an ordinal case-insensitive string we can search for? We could + // search for a string with at least one char, but if it has only one, we're better off just + // searching as a set, so we look for strings with at least two chars. + if ordinalCaseInsensitivePrefix := findPrefixOrdinalCaseInsensitive(nextChild); len(ordinalCaseInsensitivePrefix) >= 2 { + // The literal can be searched for as a case-insensitive string. As with ordinal above, + // though, we need to make sure its starting character isn't part of the previous set. + // If that starting character participates in case conversion, then we need to test out + // both casings (FindPrefixOrdinalCaseInsensitive will only return strings composed of + // characters that either are ASCII or that don't participate in case conversion). + ch, _ := utf8.DecodeRuneInString(ordinalCaseInsensitivePrefix) + if participatesInCaseConversion(ch) { + if firstChild.Set.CharIn(ch|0x20) || + firstChild.Set.CharIn(ch&^0x20) { + return nil + } + } else if firstChild.Set.CharIn(ch) { + return nil + } + + return &LiteralAfterLoop{ + LoopNode: firstChild, + String: ordinalCaseInsensitivePrefix, + StringIgnoreCase: true, + } + } + + // If the resulting node is a set with at least one iteration, we can search for it. + if nextChild.IsSetFamily() && + !nextChild.Set.IsNegated() && + (nextChild.T == NtSet || nextChild.M >= 1) { + // maximum number of chars optimized by IndexOfAny + chars := nextChild.Set.GetSetChars(5) + if len(chars) > 0 { + for _, c := range chars { + if firstChild.Set.CharIn(c) { + return nil + } + } + + return &LiteralAfterLoop{ + LoopNode: firstChild, + Chars: chars, + } + } + } + + // Otherwise, we couldn't find the pattern of an atomic set loop followed by a literal. + return nil +} + +func unwrapImmediateLiteralAfterLoopNode(node *RegexNode) *RegexNode { + for { + node = unwrapTransparentNodes(node) + if node == nil { + return nil + } + if node.T != NtConcatenate { + return node + } + if len(node.Children) == 0 { + return nil + } + node = node.Children[0] + } +} + +func findRequiredLandmarkChain(node *RegexNode) *RequiredLandmarkChain { + if (node.Options & RightToLeft) != 0 { + return nil + } + + node = unwrapTransparentNodes(node) + if node.T != NtConcatenate || len(node.Children) < 4 { + return nil + } + + firstChild := unwrapTransparentNodes(node.Children[0]) + if !isUnboundedSetLoop(firstChild) { + return nil + } + + // Collect landmarks that must appear in order later in the match. This is a + // conservative prefilter: if any child cannot be described as a detectable + // landmark, we skip that child rather than making it part of the chain. + landmarks := make([]RequiredLandmark, 0, 2) + for _, child := range node.Children[1:] { + if landmark, ok := extractRequiredLandmark(child); ok { + landmarks = append(landmarks, landmark) + } else if len(landmarks) == 0 && !isZeroWidthLandmarkGap(child) { + return nil + } + } + if len(landmarks) < 2 { + return nil + } + + return &RequiredLandmarkChain{ + LeadingLoopSet: firstChild.Set, + Landmarks: landmarks, + } +} + +func isZeroWidthLandmarkGap(node *RegexNode) bool { + node = unwrapTransparentNodes(node) + if node == nil { + return true + } + switch node.T { + case NtEmpty, NtUpdateBumpalong, + NtBeginning, NtBol, NtStart, NtEndZ, NtEnd, NtEol, + NtBoundary, NtNonboundary, NtECMABoundary, NtNonECMABoundary: + return true + default: + return false + } +} + +func unwrapTransparentNodes(node *RegexNode) *RegexNode { + for node != nil && (node.T == NtAtomic || node.T == NtCapture || node.T == NtGroup) && len(node.Children) == 1 { + node = node.Children[0] + } + return node +} + +func isUnboundedSetLoop(node *RegexNode) bool { + return node != nil && + (node.T == NtSetloop || node.T == NtSetloopatomic || node.T == NtSetlazy) && + node.Set != nil && + node.N == math.MaxInt32 +} + +func extractRequiredLandmark(node *RegexNode) (RequiredLandmark, bool) { + node = unwrapTransparentNodes(node) + if node == nil { + return RequiredLandmark{}, false + } + + if node.T != NtAlternate { + alt, ok := extractRequiredLandmarkAlternative(node) + if !ok { + return RequiredLandmark{}, false + } + return RequiredLandmark{Alternatives: []RequiredLandmarkAlternative{alt}}, true + } + + landmark := RequiredLandmark{Alternatives: make([]RequiredLandmarkAlternative, 0, len(node.Children))} + for _, child := range node.Children { + alt, ok := extractRequiredLandmarkAlternative(child) + if !ok { + return RequiredLandmark{}, false + } + landmark.Alternatives = append(landmark.Alternatives, alt) + } + return landmark, len(landmark.Alternatives) > 0 +} + +func extractRequiredLandmarkAlternative(node *RegexNode) (RequiredLandmarkAlternative, bool) { + node = unwrapTransparentNodes(node) + if node == nil { + return RequiredLandmarkAlternative{}, false + } + + children := []*RegexNode{node} + if node.T == NtConcatenate { + children = node.Children + } + + alt := RequiredLandmarkAlternative{} + i := 0 + if i < len(children) { + if whitespaceSet, min, ok := whitespaceLoop(children[i]); ok { + alt.LeadingWhitespaceSet = whitespaceSet + alt.RequireWhitespaceBefore = min > 0 + i++ + } + } + if i >= len(children) { + return RequiredLandmarkAlternative{}, false + } + + // The core of a landmark must be a literal or a bounded, enumerable set + // repetition. The VM still validates the full regex after this prefilter + // returns a candidate. + core := unwrapTransparentNodes(children[i]) + switch core.T { + case NtOne: + alt.Literal = []rune{core.Ch} + alt.MinRepeat = 1 + alt.MaxRepeat = 1 + case NtMulti: + alt.Literal = core.Str + alt.MinRepeat = 1 + alt.MaxRepeat = 1 + case NtSet, NtSetloop, NtSetloopatomic, NtSetlazy: + if core.Set == nil { + return RequiredLandmarkAlternative{}, false + } + if core.T == NtSet { + alt.MinRepeat = 1 + alt.MaxRepeat = 1 + } else if core.M > 0 && core.N != math.MaxInt32 { + alt.MinRepeat = core.M + alt.MaxRepeat = core.N + } else { + return RequiredLandmarkAlternative{}, false + } + chars := core.Set.GetSetChars(8) + if len(chars) == 0 || core.Set.IsNegated() { + return RequiredLandmarkAlternative{}, false + } + alt.Set = core.Set + default: + return RequiredLandmarkAlternative{}, false + } + i++ + + if i < len(children) { + if whitespaceSet, min, ok := whitespaceLoop(children[i]); ok { + alt.TrailingWhitespaceSet = whitespaceSet + alt.RequireWhitespaceAfter = min > 0 + i++ + } + } + if i != len(children) { + return RequiredLandmarkAlternative{}, false + } + return alt, true +} + +func whitespaceLoop(node *RegexNode) (*CharSet, int, bool) { + node = unwrapTransparentNodes(node) + if node != nil && + (node.T == NtSetloop || node.T == NtSetloopatomic || node.T == NtSetlazy) && + node.Set != nil && + node.N == math.MaxInt32 && + (node.Set.Equals(SpaceClass()) || node.Set.Equals(ECMASpaceClass()) || node.Set.Equals(RE2SpaceClass())) { + return node.Set, node.M, true + } + return nil, 0, false +} + +// Returns a leading positive lookahead if found and whether to keep examining subsequent nodes in a concatenation. +func findLeadingPositiveLookahead(node *RegexNode) (*RegexNode, bool) { + for { + if node.Options&RightToLeft != 0 { + return nil, false + } + + switch node.T { + case NtPosLook: + return node, false + + case NtBol, NtEol, NtBeginning, NtStart, NtEndZ, NtEnd, + NtBoundary, NtECMABoundary, NtNegLook, NtEmpty: + return nil, true + + case NtAtomic, NtCapture: + node = node.Children[0] + continue + + case NtLoop, NtLazyloop: + if node.M < 1 { + return nil, false + } + lookahead, _ := findLeadingPositiveLookahead(node.Children[0]) + return lookahead, false + + case NtConcatenate: + for i := 0; i < len(node.Children); i++ { + lookahead, keepLooking := findLeadingPositiveLookahead(node.Children[i]) + if lookahead != nil || !keepLooking { + return lookahead, false + } + } + return nil, true + + default: + return nil, false + } + } +} diff --git a/vendor/github.com/dlclark/regexp2/syntax/replacerdata.go b/vendor/github.com/dlclark/regexp2/v2/syntax/replacerdata.go similarity index 80% rename from vendor/github.com/dlclark/regexp2/syntax/replacerdata.go rename to vendor/github.com/dlclark/regexp2/v2/syntax/replacerdata.go index bcf4d3f25..ea1b6ab3d 100644 --- a/vendor/github.com/dlclark/regexp2/syntax/replacerdata.go +++ b/vendor/github.com/dlclark/regexp2/v2/syntax/replacerdata.go @@ -19,8 +19,8 @@ const ( replaceWholeString = -4 ) -//ErrReplacementError is a general error during parsing the replacement text -var ErrReplacementError = errors.New("Replacement pattern error.") +// ErrReplacementError is a general error during parsing the replacement text +var ErrReplacementError = errors.New("replacement pattern error") // NewReplacerData will populate a reusable replacer data struct based on the given replacement string // and the capture group data from a regexp @@ -37,7 +37,7 @@ func NewReplacerData(rep string, caps map[int]int, capsize int, capnames map[str return nil, err } - if concat.t != ntConcatenate { + if concat.T != NtConcatenate { panic(ErrReplacementError) } @@ -47,21 +47,21 @@ func NewReplacerData(rep string, caps map[int]int, capsize int, capnames map[str rules []int ) - for _, child := range concat.children { - switch child.t { - case ntMulti: + for _, child := range concat.Children { + switch child.T { + case NtMulti: child.writeStrToBuf(sb) - case ntOne: - sb.WriteRune(child.ch) + case NtOne: + sb.WriteRune(child.Ch) - case ntRef: + case NtRef: if sb.Len() > 0 { rules = append(rules, len(strings)) strings = append(strings, sb.String()) sb.Reset() } - slot := child.m + slot := child.M if len(caps) > 0 && slot >= 0 { slot = caps[slot] diff --git a/vendor/github.com/dlclark/regexp2/v2/syntax/tree.go b/vendor/github.com/dlclark/regexp2/v2/syntax/tree.go new file mode 100644 index 000000000..f4b8b6a26 --- /dev/null +++ b/vendor/github.com/dlclark/regexp2/v2/syntax/tree.go @@ -0,0 +1,2362 @@ +package syntax + +import ( + "bytes" + "fmt" + "math" + "strconv" + "strings" + "unicode" + + "slices" +) + +// Arbitrary number of repetitions of the same character when we'd prefer to represent that as a repeater of that character rather than a string. +const MultiVsRepeaterLimit = 64 + +type RegexTree struct { + Root *RegexNode + Caps map[int]int + Capnumlist []int + Captop int + Capnames map[string]int + Caplist []string + Options RegexOptions + FindOptimizations *FindOptimizations +} + +// It is built into a parsed tree for a regular expression. + +// Implementation notes: +// +// Since the node tree is a temporary data structure only used +// during compilation of the regexp to integer codes, it's +// designed for clarity and convenience rather than +// space efficiency. +// +// RegexNodes are built into a tree, linked by the n.children list. +// Each node also has a n.parent and n.ichild member indicating +// its parent and which child # it is in its parent's list. +// +// RegexNodes come in as many types as there are constructs in +// a regular expression, for example, "concatenate", "alternate", +// "one", "rept", "group". There are also node types for basic +// peephole optimizations, e.g., "onerep", "notsetrep", etc. +// +// Because perl 5 allows "lookback" groups that scan backwards, +// each node also gets a "direction". Normally the value of +// boolean n.backward = false. +// +// On the parse stack, each tree has a "role" - basically, the +// nonterminal in the grammar that the parser has currently +// assigned to the tree. That code is stored in n.role. +// +// Finally, some of the different kinds of nodes have data. +// Two integers (for the looping constructs) are stored in +// n.operands, an an object (either a string or a set) +// is stored in n.data +type RegexNode struct { + T NodeType + Children []*RegexNode + Str []rune + Set *CharSet + Ch rune + M int + N int + Options RegexOptions + Parent *RegexNode +} + +type NodeType int32 + +const ( + // The following are leaves, and correspond to primitive operations + NtUnknown NodeType = -1 + //NtOnerep NodeType = 0 // lef,back char,min,max a {n} + //NtNotonerep NodeType = 1 // lef,back char,min,max .{n} + //NtSetrep NodeType = 2 // lef,back set,min,max [\d]{n} + NtOneloop NodeType = 3 // lef,back char,min,max a {,n} + NtNotoneloop NodeType = 4 // lef,back char,min,max .{,n} + NtSetloop NodeType = 5 // lef,back set,min,max [\d]{,n} + NtOnelazy NodeType = 6 // lef,back char,min,max a {,n}? + NtNotonelazy NodeType = 7 // lef,back char,min,max .{,n}? + NtSetlazy NodeType = 8 // lef,back set,min,max [\d]{,n}? + NtOne NodeType = 9 // lef char a + NtNotone NodeType = 10 // lef char [^a] + NtSet NodeType = 11 // lef set [a-z\s] \w \s \d + NtMulti NodeType = 12 // lef string abcd + NtRef NodeType = 13 // lef group \# + NtBol NodeType = 14 // ^ + NtEol NodeType = 15 // $ + NtBoundary NodeType = 16 // \b + NtNonboundary NodeType = 17 // \B + NtBeginning NodeType = 18 // \A + NtStart NodeType = 19 // \G + NtEndZ NodeType = 20 // \Z + NtEnd NodeType = 21 // \Z + + // Interior nodes do not correspond to primitive operations, but + // control structures compositing other operations + + // Concat and alternate take n children, and can run forward or backwards + + NtNothing NodeType = 22 // [] + NtEmpty NodeType = 23 // () + NtAlternate NodeType = 24 // a|b + NtConcatenate NodeType = 25 // ab + NtLoop NodeType = 26 // m,x * + ? {,} + NtLazyloop NodeType = 27 // m,x *? +? ?? {,}? + NtCapture NodeType = 28 // n () + NtGroup NodeType = 29 // (?:) + NtPosLook NodeType = 30 // (?=) (?<=) + NtNegLook NodeType = 31 // (?!) (?) (?<) + NtBackRefCond NodeType = 33 // (?(n) | ) + NtExprCond NodeType = 34 // (?(...) | ) + + NtECMABoundary NodeType = 41 // \b + NtNonECMABoundary NodeType = 42 // \B + + // Atomic loop of the specified character. + // Operand 0 is the character. Operand 1 is the max iteration count. + NtOneloopatomic NodeType = 43 + // Atomic loop of a single character other than the one specified. + // Operand 0 is the character. Operand 1 is the max iteration count. + NtNotoneloopatomic NodeType = 44 + // Atomic loop of a single character matching the specified set + // Operand 0 is index into the strings table of the character class description. Operand 1 is the repetition count. + NtSetloopatomic NodeType = 45 + // Updates the bumpalong position to the current position. + NtUpdateBumpalong NodeType = 46 +) + +func newRegexNode(t NodeType, opt RegexOptions) *RegexNode { + return &RegexNode{ + T: t, + Options: opt, + } +} + +func newRegexNodeCh(t NodeType, opt RegexOptions, ch rune) *RegexNode { + return nodeWithCaseConversion(&RegexNode{ + T: t, + Options: opt, + Ch: ch, + }) +} + +func newRegexNodeStr(t NodeType, opt RegexOptions, str []rune) *RegexNode { + return &RegexNode{ + T: t, + Options: opt, + Str: str, + } +} + +func newRegexNodeSet(t NodeType, opt RegexOptions, set *CharSet) *RegexNode { + return nodeWithCaseConversion(&RegexNode{ + T: t, + Options: opt, + Set: set, + }) +} + +func newRegexNodeM(t NodeType, opt RegexOptions, m int) *RegexNode { + return &RegexNode{ + T: t, + Options: opt, + M: m, + } +} +func newRegexNodeMN(t NodeType, opt RegexOptions, m, n int) *RegexNode { + return &RegexNode{ + T: t, + Options: opt, + M: m, + N: n, + } +} + +func nodeWithCaseConversion(n *RegexNode) *RegexNode { + // if opts are ignore case and our rune is impacted by casing + // then we need to switch our type to the set version + // NtOne = NtSet + if n.Options&IgnoreCase == 0 { + return n + } + + if n.Ch > 0 { + ch := n.Ch + if isLow, isUp := unicode.IsLower(ch), unicode.IsUpper(ch); isLow || isUp { + /*var upper, lower rune + // it's a capitalizable char + if isUp { + upper = ch + lower = unicode.ToLower(ch) + } else { + lower = ch + upper = unicode.ToUpper(ch) + }*/ + set := &CharSet{} + set.addChar(ch) + set.addCaseEquivalences() + t := NtSet + + switch n.T { + case NtOneloop, NtNotoneloop: + t = NtSetloop + case NtOnelazy, NtNotonelazy: + t = NtSetlazy + } + set.negate = n.IsNotoneFamily() + + return &RegexNode{ + T: t, + Options: n.Options & ^IgnoreCase, + Set: set, + } + } + } else if n.Set != nil { + // just to be safe we don't modify the original set pointer + // just in case it's used in a case-sensitive area + s := n.Set.Copy() + s.addCaseEquivalences() + n.Set = &s + n.Options &= ^IgnoreCase + } + + return n +} + +func (n *RegexNode) IsSetFamily() bool { + return n.T == NtSet || n.T == NtSetloop || n.T == NtSetlazy || n.T == NtSetloopatomic +} +func (n *RegexNode) IsOneFamily() bool { + return n.T == NtOne || n.T == NtOneloop || n.T == NtOnelazy || n.T == NtOneloopatomic +} +func (n *RegexNode) IsNotoneFamily() bool { + return n.T == NtNotone || n.T == NtNotoneloop || n.T == NtNotonelazy || n.T == NtNotoneloopatomic +} + +func (n *RegexNode) IsSetloopFamily() bool { + return n.T == NtSetloop || n.T == NtSetlazy || n.T == NtSetloopatomic +} +func (n *RegexNode) IsOneloopFamily() bool { + return n.T == NtOneloop || n.T == NtOnelazy || n.T == NtOneloopatomic +} +func (n *RegexNode) IsNotoneloopFamily() bool { + return n.T == NtNotoneloop || n.T == NtNotonelazy || n.T == NtNotoneloopatomic +} + +func (n *RegexNode) IsAtomicloopFamily() bool { + return n.T == NtOneloopatomic || n.T == NtNotoneloopatomic || n.T == NtSetloopatomic +} + +func (n *RegexNode) writeStrToBuf(buf *bytes.Buffer) { + for i := 0; i < len(n.Str); i++ { + buf.WriteRune(n.Str[i]) + } +} + +func (n *RegexNode) addChild(child *RegexNode) { + child.Parent = n + reduced := child.reduce() + reduced.Parent = n + n.Children = append(n.Children, reduced) + reduced.Parent = n +} + +func (n *RegexNode) insertChildren(afterIndex int, nodes []*RegexNode) { + for _, c := range nodes { + c.Parent = n + } + n.Children = slices.Insert(n.Children, afterIndex, nodes...) + //newChildren := make([]*RegexNode, 0, len(n.Children)+len(nodes)) + //n.Children = append(append(append(newChildren, n.Children[:afterIndex]...), nodes...), n.Children[afterIndex:]...) +} + +// removes children including the start but not the end index +func (n *RegexNode) removeChildren(startIndex, endIndex int) { + n.Children = append(n.Children[:startIndex], n.Children[endIndex:]...) +} + +func (n *RegexNode) ReplaceChild(index int, newChild *RegexNode) { + newChild.Parent = n // so that the child can see its parent while being reduced + newChild = newChild.reduce() + newChild.Parent = n // in case Reduce returns a different node that needs to be reparented + + n.Children[index] = newChild +} + +// Pass type as OneLazy or OneLoop +func (n *RegexNode) makeRep(t NodeType, min, max int) { + n.T += (t - NtOne) + n.M = min + n.N = max +} + +// Performs additional optimizations on an entire tree prior to being used. +// +// Some optimizations are performed by the parser while parsing, and others are performed +// as nodes are being added to the tree. The optimizations here expect the tree to be fully +// formed, as they inspect relationships between nodes that may not have been in place as +// individual nodes were being processed/added to the tree. +func (n *RegexNode) finalOptimize() *RegexNode { + rootNode := n + + // Only apply optimization when LTR to avoid needing additional code for the much rarer RTL case. + // Also only apply these optimizations when not using NonBacktracking, as these optimizations are + // all about avoiding things that are impactful for the backtracking engines but nops for non-backtracking. + if n.Options&RightToLeft == 0 { + // Optimization: eliminate backtracking for loops. + // For any single-character loop (Oneloop, Notoneloop, Setloop), see if we can automatically convert + // that into its atomic counterpart (Oneloopatomic, Notoneloopatomic, Setloopatomic) based on what + // comes after it in the expression tree. + rootNode.findAndMakeLoopsAtomic() + + // Optimization: backtracking removal at expression end. + // If we find backtracking construct at the end of the regex, we can instead make it non-backtracking, + // since nothing would ever backtrack into it anyway. Doing this then makes the construct available + // to implementations that don't support backtracking. + rootNode.eliminateEndingBacktracking() + + // Optimization: unnecessary re-processing of starting loops. + // If an expression is guaranteed to begin with a single-character unbounded loop that isn't part of an alternation (in which case it + // wouldn't be guaranteed to be at the beginning) or a capture (in which case a back reference could be influenced by its length), then we + // can update the tree with a temporary node to indicate that the implementation should use that node's ending position in the input text + // as the next starting position at which to start the next match. This avoids redoing matches we've already performed, e.g. matching + // "\w+@dot.net" against "is this a valid address@dot.net", the \w+ will initially match the "is" and then will fail to match the "@". + // Rather than bumping the scan loop by 1 and trying again to match at the "s", we can instead start at the " ". For functional correctness + // we can only consider unbounded loops, as to be able to start at the end of the loop we need the loop to have consumed all possible matches; + // otherwise, you could end up with a pattern like "a{1,3}b" matching against "aaaabc", which should match, but if we pre-emptively stop consuming + // after the first three a's and re-start from that position, we'll end up failing the match even though it should have succeeded. We can also + // apply this optimization to non-atomic loops: even though backtracking could be necessary, such backtracking would be handled within the processing + // of a single starting position. Lazy loops similarly benefit, as a failed match will result in exploring the exact same search space as with + // a greedy loop, just in the opposite order (and a successful match will overwrite the bumpalong position); we need to avoid atomic lazy loops, + // however, as they will only end up as a repeater for the minimum length and thus will effectively end up with a non-infinite upper bound, which + // we've already outlined is problematic. + node := rootNode.Children[0] // skip implicit root capture node + atomicByAncestry := true // the root is implicitly atomic because nothing comes after it (same for the implicit root capture) + for { + if node.T == NtAtomic { + node = node.Children[0] + continue + } else if node.T == NtConcatenate { + atomicByAncestry = false + node = node.Children[0] + continue + } else if node.N == math.MaxInt32 && + ((node.T == NtOneloop || node.T == NtOneloopatomic || node.T == NtNotoneloop || node.T == NtNotoneloopatomic || node.T == NtSetloop || node.T == NtSetloopatomic) || + ((node.T == NtOnelazy || node.T == NtNotonelazy || node.T == NtSetlazy) && !atomicByAncestry)) { + + if node.Parent != nil && node.Parent.T == NtConcatenate { + node.Parent.Children = slices.Insert(node.Parent.Children, 1, &RegexNode{T: NtUpdateBumpalong, Options: node.Options, Parent: node.Parent}) + } + } + + break + } + + } + + //debug helper + //rootNode.ValidateFinalTreeInvariants() + + // Done optimizing. Return the final tree. + return rootNode +} + +// Finds {one/notone/set}loop nodes in the concatenation that can be automatically upgraded +// to {one/notone/set}loopatomic nodes. Such changes avoid potential useless backtracking. +// e.g. A*B (where sets A and B don't overlap) => (?>A*)B. +func (n *RegexNode) findAndMakeLoopsAtomic() { + if n.Options&RightToLeft != 0 { + // RTL is so rare, we don't need to spend additional time/code optimizing for it. + return + } + + // For all node types that have children, recur into each of those children. + for i := 0; i < len(n.Children); i++ { + n.Children[i].findAndMakeLoopsAtomic() + } + + // If this isn't a concatenation, nothing more to do. + if n.T != NtConcatenate { + return + } + + // This is a concatenation. Iterate through each pair of nodes in the concatenation seeing whether we can + // make the first node (or its right-most child) atomic based on the second node (or its left-most child). + for i := 0; i < len(n.Children)-1; i++ { + n.Children[i].processNode(n.Children[i+1]) + } +} + +func (node *RegexNode) processNode(subsequent *RegexNode) { + // Skip down the node past irrelevant nodes. + for { + // We can always recur into captures and into the last node of concatenations. + if node.T == NtCapture || node.T == NtConcatenate { + node = node.Children[len(node.Children)-1] + continue + } + + // For loops with at least one guaranteed iteration, we can recur into them, but + // we need to be careful not to just always do so; the ending node of a loop can only + // be made atomic if what comes after the loop but also the beginning of the loop are + // compatible for the optimization. + if node.T == NtLoop { + loopDescendent := node.FindLastExpressionInLoopForAutoAtomic() + if loopDescendent != nil { + node = loopDescendent + continue + } + } + + // Can't skip any further. + break + } + + // If the node can be changed to atomic based on what comes after it, do so. + switch node.T { + case NtOneloop, NtNotoneloop, NtSetloop: + if node.canBeMadeAtomic(subsequent, true, false) { + // The greedy loop doesn't overlap with what comes after it, which means giving anything it matches back will not + // help the overall match to succeed, which means it can simply become atomic to match as much as possible. The call + // to CanBeMadeAtomic passes iterateNullableSubsequent=true because, in a pattern like a*b*c*, when analyzing a*, we + // want to examine the b* and the c* rather than just giving up after seeing that b* is nullable; in order to make + // the a* atomic, we need to know that anything that could possibly come after the loop doesn't overlap. + node.makeLoopAtomic() + } + + case NtOnelazy, NtNotonelazy, NtSetlazy: + if node.canBeMadeAtomic(subsequent, false, true) { + // The lazy loop doesn't overlap with what comes after it, which means it needs to match as much as its allowed + // to match in order for there to be a possibility that what comes next matches (if it doesn't match as much + // as it's allowed and there was still more it could match, then what comes next is guaranteed to not match, + // since it doesn't match any of the same things the loop matches). We don't want to just make the lazy loop + // atomic, as an atomic lazy loop matches as little as possible, not as much as possible. Instead, we want to + // make the lazy loop into an atomic greedy loop. Note that when we check CanBeMadeAtomic, we need to set + // "iterateNullableSubsequent" to false so that we only inspect non-nullable subsequent nodes. For example, + // given a pattern like a*?b, we want to upgrade that loop to being greedy atomic, e.g. (?>a*)b. But given a + // pattern like a*?b*, the subsequent node is nullable, which means it doesn't have to be part of a match, which + // means the a*? could match by itself, in which case as it's lazy it needs to match as few a's as possible, e.g. + // a+?b* against the input "aaaab" should match "a", not "aaaa" nor "aaaab". (Technically for lazy, we only need to prevent + // walking off the end of the pattern, but it's not currently worth complicating the implementation for that case.) + // allowLazy is set to true so that the implementation will analyze rather than ignore this node; generally lazy nodes + // are ignored due to making them atomic not generally being a sound change, but here we're explicitly choosing to + // given the circumstances. + node.T -= NtOnelazy - NtOneloop // lazy to greedy + node.makeLoopAtomic() + } + + case NtAlternate, NtBackRefCond, NtExprCond: + // In the case of alternation, we can't change the alternation node itself + // based on what comes after it (at least not with more complicated analysis + // that factors in all branches together), but we can look at each individual + // branch, and analyze ending loops in each branch individually to see if they + // can be made atomic. Then if we do end up backtracking into the alternation, + // we at least won't need to backtrack into that loop. The same is true for + // conditionals, though we don't want to process the condition expression + // itself, as it's already considered atomic and handled as part of ReduceExpressionConditional. + b := 0 + if node.T == NtExprCond { + b = 1 + } + for ; b < len(node.Children); b++ { + node.Children[b].processNode(subsequent) + } + + } +} + +func (n *RegexNode) reduce() *RegexNode { + // Remove IgnoreCase option from everything except a Backreference + if n.T != NtRef { + n.Options &= ^IgnoreCase + } + switch n.T { + case NtAlternate: + return n.reduceAlternation() + case NtAtomic: + return n.reduceAtomic() + case NtConcatenate: + return n.reduceConcatenation() + case NtGroup: + return n.reduceGroup() + case NtLoop, NtLazyloop: + return n.reduceRep() + case NtPosLook, NtNegLook: + return n.reduceLookaround() + case NtSet, NtSetloop, NtSetlazy, NtSetloopatomic: + return n.reduceSet() + case NtExprCond: + return n.reduceExpressionConditional() + case NtBackRefCond: + return n.reduceBackreferenceConditional() + default: + return n + } +} + +// / Optimizations for positive and negative lookaheads/behinds. +func (n *RegexNode) reduceLookaround() *RegexNode { + // A lookaround is a zero-width atomic assertion. + // As it's atomic, nothing will backtrack into it, and we can + // eliminate any ending backtracking from it. + n.eliminateEndingBacktracking() + + // A positive lookaround wrapped around an empty is a nop, and we can reduce it + // to simply Empty. A developer typically doesn't write this, but rather it evolves + // due to optimizations resulting in empty. + + // A negative lookaround wrapped around an empty child, i.e. (?!), is + // sometimes used as a way to insert a guaranteed no-match into the expression, + // often as part of a conditional. We can reduce it to simply Nothing. + + if n.Children[0].T == NtEmpty { + if n.T == NtPosLook { + n.T = NtEmpty + } else { + n.T = NtNothing + } + n.Children = nil + } + + return n +} + +// Optimizations for backreference conditionals. +func (n *RegexNode) reduceBackreferenceConditional() *RegexNode { + // This isn't so much an optimization as it is changing the tree for consistency. We want + // all engines to be able to trust that every backreference conditional will have two children, + // even though it's optional in the syntax. If it's missing a "not matched" branch, + // we add one that will match empty. + if len(n.Children) == 1 { + n.addChild(&RegexNode{T: NtEmpty, Options: n.Options}) + } + + return n +} + +// / Optimizations for expression conditionals. +func (n *RegexNode) reduceExpressionConditional() *RegexNode { + // This isn't so much an optimization as it is changing the tree for consistency. We want + // all engines to be able to trust that every expression conditional will have three children, + // even though it's optional in the syntax. If it's missing a "not matched" branch, + // we add one that will match empty. + if len(n.Children) == 2 { + n.addChild(&RegexNode{T: NtEmpty, Options: n.Options}) + } + + // It's common for the condition to be an explicit positive lookahead, as specifying + // that eliminates any ambiguity in syntax as to whether the expression is to be matched + // as an expression or to be a reference to a capture group. After parsing, however, + // there's no ambiguity, and we can remove an extra level of positive lookahead, as the + // engines need to treat the condition as a zero-width positive, atomic assertion regardless. + condition := n.Children[0] + if condition.T == NtPosLook && (condition.Options&RightToLeft) == 0 { + n.ReplaceChild(0, condition.Children[0]) + } + + // We can also eliminate any ending backtracking in the condition, as the condition + // is considered to be a positive lookahead, which is an atomic zero-width assertion. + condition = n.Children[0] + condition.eliminateEndingBacktracking() + + return n +} + +// Remove unnecessary atomic nodes, and make appropriate descendents of the atomic node themselves atomic. +// e.g. (?>(?>(?>a*))) => (?>a*) +// e.g. (?>(abc*)*) => (?>(abc(?>c*))*) +func (n *RegexNode) reduceAtomic() *RegexNode { + atomic := n + child := n.Children[0] + for child.T == NtAtomic { + atomic = child + child = atomic.Children[0] + } + + switch child.T { + // If the child is empty/nothing, there's nothing to be made atomic so the Atomic + // node can simply be removed. + case NtEmpty, NtNothing: + return child + + // If the child is already atomic, we can just remove the atomic node. + case NtOneloopatomic, NtNotoneloopatomic, NtSetloopatomic: + return child + + // If an atomic subexpression contains only a {one/notone/set}{loop/lazy}, + // change it to be an {one/notone/set}loopatomic and remove the atomic node. + case NtOneloop, NtNotoneloop, NtSetloop, NtOnelazy, NtNotonelazy, NtSetlazy: + child.makeLoopAtomic() + return child + + // Alternations have a variety of possible optimizations that can be applied + // iff they're atomic. + case NtAlternate: + if (n.Options & RightToLeft) == 0 { + branches := child.Children + + // If an alternation is atomic and its first branch is Empty, the whole thing + // is a nop, as Empty will match everything trivially, and no backtracking + // into the node will be performed, making the remaining branches irrelevant. + if branches[0].T == NtEmpty { + return &RegexNode{T: NtEmpty, Options: child.Options} + } + + // Similarly, we can trim off any branches after an Empty, as they'll never be used. + // An Empty will match anything, and thus branches after that would only be used + // if we backtracked into it and advanced passed the Empty after trying the Empty... + // but if the alternation is atomic, such backtracking won't happen. + for i := 1; i < len(branches)-1; i++ { + if branches[i].T == NtEmpty { + branches = slices.Delete(branches, i+1, len(branches)) + break + } + } + + // If an alternation is atomic, we won't ever backtrack back into it, which + // means order matters but not repetition. With backtracking, it would be incorrect + // to convert an expression like "hi|there|hello" into "hi|hello|there", as doing + // so could then change the order of results if we matched "hi" and then failed + // based on what came after it, and both "hello" and "there" could be successful + // with what came later. But without backtracking, we can reorder "hi|there|hello" + // to instead be "hi|hello|there", as "hello" and "there" can't match the same text, + // and once this atomic alternation has matched, we won't try another branch. This + // reordering is valuable as it then enables further optimizations, e.g. + // "hi|there|hello" => "hi|hello|there" => "h(?:i|ello)|there", which means we only + // need to check the 'h' once in case it's not an 'h', and it's easier to employ different + // code gen that, for example, switches on first character of the branches, enabling faster + // choice of branch without always having to walk through each. + reordered := false + for start := 0; start < len(branches); start++ { + // Get the node that may start our range. If it's a one, multi, or concat of those, proceed. + startNode := branches[start] + if startNode.findBranchOneOrMultiStart() == nil { + continue + } + + // Find the contiguous range of nodes from this point that are similarly one, multi, or concat of those. + endExclusive := start + 1 + for endExclusive < len(branches) && branches[endExclusive].findBranchOneOrMultiStart() != nil { + endExclusive++ + } + + // If there's at least 3, there may be something to reorder (we won't reorder anything + // before the starting position, and so only 2 items is considered ordered). + if endExclusive-start >= 3 { + compare := start + for compare < endExclusive { + // Get the starting character + c := branches[compare].findBranchOneOrMultiStart().FirstCharOfOneOrMulti() + + // Move compare to point to the last branch that has the same starting value. + for compare < endExclusive && branches[compare].findBranchOneOrMultiStart().FirstCharOfOneOrMulti() == c { + compare++ + } + + // Compare now points to the first node that doesn't match the starting node. + // If we've walked off our range, there's nothing left to reorder. + if compare < endExclusive { + // There may be something to reorder. See if there are any other nodes that begin with the same character. + for next := compare + 1; next < endExclusive; next++ { + nextChild := branches[next] + if nextChild.findBranchOneOrMultiStart().FirstCharOfOneOrMulti() == c { + branches = slices.Delete(branches, next, next+1) + branches = slices.Insert(branches, compare, nextChild) + compare++ + reordered = true + } + } + } + } + } + + // Move to the end of the range we've now explored. endExclusive is not a viable + // starting position either, and the start++ for the loop will thus take us to + // the next potential place to start a range. + start = endExclusive + } + child.Children = branches + // If anything was reordered, there may be new optimization opportunities inside + // of the alternation, so reduce it again. + if reordered { + atomic.ReplaceChild(0, child) + child = atomic.Children[0] + } + } + fallthrough + + // For everything else, try to reduce ending backtracking of the last contained expression. + default: + child.eliminateEndingBacktracking() + return atomic + } +} + +func (n *RegexNode) makeLoopAtomic() { + + switch n.T { + case NtOneloop, NtNotoneloop, NtSetloop: + // For loops, we simply change the Type to the atomic variant. + // Atomic greedy loops should consume as many values as they can. + n.T += NtOneloopatomic - NtOneloop + + case NtOnelazy, NtNotonelazy, NtSetlazy: + // For lazy, we not only change the Type, we also lower the max number of iterations + // to the minimum number of iterations, creating a repeater, as they should end up + // matching as little as possible. + n.T += NtOneloopatomic - NtOnelazy + n.N = n.M + if n.N == 0 { + // If moving the max to be the same as the min dropped it to 0, there's no + // work to be done for this node, and we can make it Empty. + n.T = NtEmpty + n.Str = nil + n.Ch = 0x0 + } else if n.T == NtOneloopatomic && n.N >= 2 && n.N <= MultiVsRepeaterLimit { + // If this is now a One repeater with a small enough length, + // make it a Multi instead, as they're better optimized down the line. + n.T = NtMulti + n.Str = []rune(strings.Repeat(string(n.Ch), n.N)) + n.Ch = 0x0 + n.M = 0 + n.N = 0 + } + } +} + +// Converts nodes at the end of the node tree to be atomic. +// The correctness of this optimization depends on nothing being able to backtrack into +// the provided node. That means it must be at the root of the overall expression, or +// it must be an Atomic node that nothing will backtrack into by the very nature of Atomic. +func (n *RegexNode) eliminateEndingBacktracking() { + // Walk the tree starting from the current node. + node := n + for { + switch node.T { + // {One/Notone/Set}loops can be upgraded to {One/Notone/Set}loopatomic nodes, e.g. [abc]* => (?>[abc]*). + // And {One/Notone/Set}lazys can similarly be upgraded to be atomic, which really makes them into repeaters + // or even empty nodes. + case NtOneloop, NtNotoneloop, NtSetloop, NtOnelazy, NtNotonelazy, NtSetlazy: + node.makeLoopAtomic() + + // Just because a particular node is atomic doesn't mean all its descendants are. + // Process them as well. Lookarounds are implicitly atomic. + case NtAtomic, NtPosLook, NtNegLook: + node = node.Children[0] + continue + + case NtCapture, NtConcatenate: + // For Capture and Concatenate, we just recur into their last child (only child in the case + // of Capture). However, if the child is an alternation or loop, we can also make the + // node itself atomic by wrapping it in an Atomic node. Since we later check to see whether a + // node is atomic based on its parent or grandparent, we don't bother wrapping such a node in + // an Atomic one if its grandparent is already Atomic. + // e.g. [xyz](?:abc|def) => [xyz](?>abc|def) + + // validate grandparent isn't atomic + existingChild := node.Children[len(node.Children)-1] + if (existingChild.T == NtAlternate || existingChild.T == NtBackRefCond || + existingChild.T == NtExprCond || existingChild.T == NtLoop || + existingChild.T == NtLazyloop) && + (node.Parent == nil || node.Parent.T != NtAtomic) { + + atomic := &RegexNode{T: NtAtomic, Options: existingChild.Options} + atomic.addChild(existingChild) + node.ReplaceChild(len(node.Children)-1, atomic) + } + node = existingChild + continue + + // For alternate, we can recur into each branch separately. We use this iteration for the first branch. + // Conditionals are just like alternations in this regard. + // e.g. abc*|def* => ab(?>c*)|de(?>f*) + case NtAlternate, NtBackRefCond, NtExprCond: + + branches := len(node.Children) + for i := 1; i < branches; i++ { + node.Children[i].eliminateEndingBacktracking() + } + + // ReduceExpressionConditional will have already applied ending backtracking removal + if node.T != NtExprCond { + node = node.Children[0] + continue + } + + // For {Lazy}Loop, we search to see if there's a viable last expression, and iff there + // is we recur into processing it. Also, as with the single-char lazy loops, LazyLoop + // can have its max iteration count dropped to its min iteration count, as there's no + // reason for it to match more than the minimal at the end; that in turn makes it a + // repeater, which results in better code generation. + // e.g. (?:abc*)* => (?:ab(?>c*))* + // e.g. (abc*?)+? => (ab){1} + case NtLazyloop: + node.N = node.M + fallthrough + case NtLoop: + if node.N == 1 { + // If the loop has a max iteration count of 1 (e.g. it's an optional node), + // there's no possibility for conflict between multiple iterations, so + // we can process it. + node = node.Children[0] + continue + } + + loopDescendent := node.FindLastExpressionInLoopForAutoAtomic() + if loopDescendent != nil { + node = loopDescendent + continue // loop around to process node + } + + } + + break + } +} + +// Recurs into the last expression of a loop node, looking to see if it can find a node +// that could be made atomic _assuming_ the conditions exist for it with the loop's ancestors. +// Returns The found node that should be explored further for auto-atomicity; null if it doesn't exist. +func (n *RegexNode) FindLastExpressionInLoopForAutoAtomic() *RegexNode { + node := n + + // Start by looking at the loop's sole child. + node = node.Children[0] + + // Skip past captures. + for node.T == NtCapture { + node = node.Children[0] + } + + // If the loop's body is a concatenate, we can skip to its last child iff that + // last child doesn't conflict with the first child, since this whole concatenation + // could be repeated, such that the first node ends up following the last. For + // example, in the expression (a+[def])*, the last child is [def] and the first is + // a+, which can't possibly overlap with [def]. In contrast, if we had (a+[ade])*, + // [ade] could potentially match the starting 'a'. + if node.T == NtConcatenate { + concatCount := len(node.Children) + lastConcatChild := node.Children[concatCount-1] + if lastConcatChild.canBeMadeAtomic(node.Children[0], false, false) { + return lastConcatChild + } + } + + // Otherwise, the loop has nothing that can participate in auto-atomicity. + return nil +} + +// Determines whether a node can be switched to an atomic loop. +// +// The node following is subsequent, used to determine whether it overlaps. +// iterateNullableSubsequent is whether to allow examining nodes beyond subsequent. +// allowLazy is whether lazy loops in addition to greedy loops should be considered for atomicity. +func (n *RegexNode) canBeMadeAtomic(subsequent *RegexNode, iterateNullableSubsequent, allowLazy bool) bool { + // In most case, we'll simply check the node against whatever subsequent is. However, in case + // subsequent ends up being a loop with a min bound of 0, we'll also need to evaluate the node + // against whatever comes after subsequent. In that case, we'll walk the tree to find the + // next subsequent, and we'll loop around against to perform the comparison again. + for { + // Skip the successor down to the closest node that's guaranteed to follow it. + childCount := len(subsequent.Children) + for ; childCount > 0; childCount = len(subsequent.Children) { + if subsequent.T == NtConcatenate || subsequent.T == NtCapture || + subsequent.T == NtAtomic || + (subsequent.T == NtPosLook && subsequent.Options&RightToLeft == 0) || + ((subsequent.T == NtLoop || subsequent.T == NtLazyloop) && subsequent.M > 0) { + subsequent = subsequent.Children[0] + continue + } + + break + } + + // If the current node's options don't match the subsequent node, then we cannot make it atomic. + // This applies to RightToLeft for lookbehinds, as well as patterns that enable/disable global flags in the middle of the pattern. + if n.Options != subsequent.Options { + return false + } + + // If the successor is an alternation, all of its children need to be evaluated, since any of them + // could come after this node. If any of them fail the optimization, then the whole node fails. + // This applies to expression conditionals as well, as long as they have both a yes and a no branch (if there's + // only a yes branch, we'd need to also check whatever comes after the conditional). It doesn't apply to + // backreference conditionals, as the condition itself is unknown statically and could overlap with the + // loop being considered for atomicity. + if subsequent.T == NtAlternate || (subsequent.T == NtExprCond && childCount == 3) { + // condition, yes, and no branch + for i := 0; i < childCount; i++ { + if !n.canBeMadeAtomic(subsequent.Children[i], iterateNullableSubsequent, false) { + return false + } + } + return true + } + + // If this node is a {one/notone/set}loop, see if it overlaps with its successor in the concatenation. + // If it doesn't, then we can upgrade it to being a {one/notone/set}loopatomic. + // Doing so avoids unnecessary backtracking. + if n.T == NtOneloop || (n.T == NtOnelazy && allowLazy) { + + if (subsequent.T == NtOne && n.Ch != subsequent.Ch) || + (subsequent.T == NtNotone && n.Ch == subsequent.Ch) || + (subsequent.T == NtSet && !subsequent.Set.CharIn(n.Ch)) || + (subsequent.IsOneFamily() && subsequent.M > 0 && n.Ch != subsequent.Ch) || + (subsequent.IsNotoneFamily() && subsequent.M > 0 && n.Ch == subsequent.Ch) || + (subsequent.IsSetFamily() && subsequent.M > 0 && !subsequent.Set.CharIn(n.Ch)) || + (subsequent.T == NtMulti && n.Ch != subsequent.Str[0]) || + (subsequent.T == NtEnd) || + (subsequent.T == NtEndZ && n.Ch != '\n') || + (subsequent.T == NtEol && n.Ch != '\n') { + return true + } + + // The loop can be made atomic based on this subsequent node, but we'll need to evaluate the next one as well. + if (subsequent.IsOneloopFamily() && subsequent.M == 0 && n.Ch != subsequent.Ch) || + (subsequent.IsNotoneloopFamily() && subsequent.M == 0 && n.Ch == subsequent.Ch) || + (subsequent.IsSetloopFamily() && subsequent.M == 0 && !subsequent.Set.CharIn(n.Ch)) || + (subsequent.T == NtBoundary && n.M > 0 && IsWordChar(n.Ch)) || + (subsequent.T == NtNonboundary && n.M > 0 && !IsWordChar(n.Ch)) || + (subsequent.T == NtECMABoundary && n.M > 0 && IsECMAWordChar(n.Ch)) || + (subsequent.T == NtNonECMABoundary && n.M > 0 && !IsECMAWordChar(n.Ch)) { + goto end + } + + return false + + } else if n.T == NtNotoneloop || (n.T == NtNotonelazy && allowLazy) { + if (subsequent.T == NtOne && n.Ch == subsequent.Ch) || + (subsequent.IsOneFamily() && subsequent.M > 0 && n.Ch == subsequent.Ch) || + (subsequent.T == NtMulti && n.Ch == subsequent.Str[0]) || + (subsequent.T == NtEnd) { + return true + } + + // The loop can be made atomic based on this subsequent node, but we'll need to evaluate the next one as well. + if subsequent.IsOneloopFamily() && subsequent.M == 0 && n.Ch == subsequent.Ch { + goto end + } + + return false + } else if n.T == NtSetloop || (n.T == NtSetlazy && allowLazy) { + if (subsequent.T == NtOne && !n.Set.CharIn(subsequent.Ch)) || + (subsequent.T == NtSet && !n.Set.MayOverlap(subsequent.Set)) || + (subsequent.IsOneloopFamily() && subsequent.M > 0 && !n.Set.CharIn(subsequent.Ch)) || + (subsequent.IsSetloopFamily() && subsequent.M > 0 && !n.Set.MayOverlap(subsequent.Set)) || + (subsequent.T == NtMulti && !n.Set.CharIn(subsequent.Str[0])) || + (subsequent.T == NtEnd) || + (subsequent.T == NtEndZ && !n.Set.CharIn('\n')) || + (subsequent.T == NtEol && !n.Set.CharIn('\n')) { + return true + } + + if (subsequent.IsOneloopFamily() && subsequent.M == 0 && !n.Set.CharIn(subsequent.Ch)) || + (subsequent.IsSetloopFamily() && subsequent.M == 0 && subsequent.Set.MayOverlap(n.Set)) || + (subsequent.T == NtBoundary && n.M > 0 && (n.Set.Equals(WordClass()) || n.Set.Equals(DigitClass()))) || + (subsequent.T == NtNonboundary && n.M > 0 && (n.Set.Equals(NotWordClass()) || n.Set.Equals(NotDigitClass()))) || + (subsequent.T == NtECMABoundary && n.M > 0 && (n.Set.Equals(ECMAWordClass()) || n.Set.Equals(ECMADigitClass()))) || + (subsequent.T == NtNonECMABoundary && n.M > 0 && (n.Set.Equals(NotECMAWordClass()) || n.Set.Equals(NotDigitClass()))) { + // The loop can be made atomic based on this subsequent node, but we'll need to evaluate the next one as well. + goto end + } + return false + } else { + return false + } + + end: + // We only get here if the node could be made atomic based on subsequent but subsequent has a lower bound of zero + // and thus we need to move subsequent to be the next node in sequence and loop around to try again. + if !iterateNullableSubsequent { + return false + } + + // To be conservative, we only walk up through a very limited set of constructs (even though we may have walked + // down through more, like loops), looking for the next concatenation that we're not at the end of, at + // which point subsequent becomes whatever node is next in that concatenation. + for { + parent := subsequent.Parent + if parent == nil { + // If we hit the root, we're at the end of the expression, at which point nothing could backtrack + // in and we can declare success. + return true + } + + switch parent.T { + case NtAtomic, NtAlternate, NtCapture: + subsequent = parent + continue + + case NtConcatenate: + peers := parent.Children + currentIndex := slices.Index(peers, subsequent) + + if currentIndex+1 == len(peers) { + subsequent = parent + continue + } else { + subsequent = peers[currentIndex+1] + } + + default: + // Anything else, we don't know what to do, so we have to assume it could conflict with the loop. + return false + } + + break + } + } +} + +// Basic optimization. Single-letter alternations can be replaced +// by faster set specifications, and nested alternations with no +// intervening operators can be flattened: +// +// a|b|c|def|g|h -> [a-c]|def|[gh] +// apple|(?:orange|pear)|grape -> apple|orange|pear|grape +func (n *RegexNode) reduceAlternation() *RegexNode { + if len(n.Children) == 0 { + return newRegexNode(NtNothing, n.Options) + } + if len(n.Children) == 1 { + return n.Children[0] + } + n.reduceSingleLetterAndNestedAlternations() + + node := n.replaceNodeIfUnnecessary() + if node.T == NtAlternate { + node = node.extractCommonPrefixText() + if node.T == NtAlternate { + node = node.extractCommonPrefixOneNotoneSet() + if node.T == NtAlternate { + node = node.removeRedundantEmptiesAndNothings() + } + } + } + return node +} + +// Analyzes all the branches of the alternation for text that's identical at the beginning +// of every branch. That text is then pulled out into its own one or multi node in a +// concatenation with the alternation (whose branches are updated to remove that prefix). +// This is valuable for a few reasons. One, it exposes potentially more text to the +// expression prefix analyzer used to influence FindFirstChar. Second, it exposes more +// potential alternation optimizations, e.g. if the same prefix is followed in two branches +// by sets that can be merged. Third, it reduces the amount of duplicated comparisons required +// if we end up backtracking into subsequent branches. +// e.g. abc|ade => a(?bc|de) +func (n *RegexNode) extractCommonPrefixText() *RegexNode { + // To keep things relatively simple, we currently only handle: + // - Left to right (e.g. we don't process alternations in lookbehinds) + // - Branches that are one or multi nodes, or that are concatenations beginning with one or multi nodes. + // - All branches having the same options. + + // Only extract left-to-right prefixes. + if (n.Options & RightToLeft) != 0 { + return n + } + + for startingIndex := 0; startingIndex < len(n.Children)-1; startingIndex++ { + // Process the first branch to get the maximum possible common string. + startingNode := n.Children[startingIndex].findBranchOneOrMultiStart() + if startingNode == nil { + return n + } + + startingNodeOptions := startingNode.Options + startingSpan := startingNode.Str + if startingNode.T == NtOne { + startingSpan = []rune{startingNode.Ch} + } + + // Now compare the rest of the branches against it. + endingIndex := startingIndex + 1 + for ; endingIndex < len(n.Children); endingIndex++ { + // Get the starting node of the next branch. + startingNode = n.Children[endingIndex].findBranchOneOrMultiStart() + if startingNode == nil || startingNode.Options != startingNodeOptions { + break + } + + // See if the new branch's prefix has a shared prefix with the current one. + // If it does, shorten to that; if it doesn't, bail. + if startingNode.T == NtOne { + if startingSpan[0] != startingNode.Ch { + break + } + + if len(startingSpan) != 1 { + startingSpan = startingSpan[0:1] + } + } else { + minLength := len(startingSpan) + if len(startingNode.Str) < minLength { + minLength = len(startingNode.Str) + } + c := 0 + for c < minLength && startingSpan[c] == startingNode.Str[c] { + c++ + } + + if c == 0 { + break + } + + startingSpan = startingSpan[0:c] + } + } + + // When we get here, we have a starting string prefix shared by all branches + // in the range [startingIndex, endingIndex). + if endingIndex-startingIndex <= 1 { + // There's nothing to consolidate for this starting node. + continue + } + + // We should be able to consolidate something for the nodes in the range [startingIndex, endingIndex). + + // Create a new node of the form: + // Concatenation(prefix, Alternation(each | node | with | prefix | removed)) + // that replaces all these branches in this alternation. + var prefix *RegexNode + if len(startingSpan) == 1 { + prefix = &RegexNode{T: NtOne, Options: startingNodeOptions, Ch: startingSpan[0]} + } else { + prefix = &RegexNode{T: NtMulti, Options: startingNodeOptions, Str: slices.Clone(startingSpan)} + } + + newAlternate := &RegexNode{T: NtAlternate, Options: startingNodeOptions} + for i := startingIndex; i < endingIndex; i++ { + branch := n.Children[i] + if branch.T == NtConcatenate { + branch.Children[0].processOneOrMulti(startingSpan) + } else { + branch.processOneOrMulti(startingSpan) + } + branch = branch.reduce() + newAlternate.addChild(branch) + } + + if n.Parent != nil && n.Parent.T == NtAtomic { + var atomic = &RegexNode{T: NtAtomic, Options: startingNodeOptions} + atomic.addChild(newAlternate) + newAlternate = atomic + } + + newConcat := &RegexNode{T: NtConcatenate, Options: startingNodeOptions} + newConcat.addChild(prefix) + newConcat.addChild(newAlternate) + n.ReplaceChild(startingIndex, newConcat) + n.Children = slices.Delete(n.Children, startingIndex+1, endingIndex) + } + + if len(n.Children) == 1 { + return n.Children[0] + } + + return n +} + +// This function optimizes out prefix nodes from alternation branches that are +// the same across multiple contiguous branches. +// e.g. \w12|\d34|\d56|\w78|\w90 => \w12|\d(?:34|56)|\w(?:78|90) +func (n *RegexNode) extractCommonPrefixOneNotoneSet() *RegexNode { + // Only process left-to-right prefixes. + if (n.Options & RightToLeft) != 0 { + return n + } + + // Only handle the case where each branch is a concatenation + for _, child := range n.Children { + if child.T != NtConcatenate || len(child.Children) < 2 { + return n + } + } + + for startingIndex := 0; startingIndex < len(n.Children)-1; startingIndex++ { + // Only handle the case where each branch begins with the same One, Notone, or Set (individual or loop). + // Note that while we can do this for individual characters, fixed length loops, and atomic loops, doing + // it for non-atomic variable length loops could change behavior as each branch could otherwise have a + // different number of characters consumed by the loop based on what's after it. + required := n.Children[startingIndex].Children[0] + + if (!required.IsOneFamily() && !required.IsNotoneFamily() && !required.IsSetFamily()) || + required.M != required.N { + // skip if it's not one of these scenarios + continue + } + + // Only handle the case where each branch begins with the exact same node value + endingIndex := startingIndex + 1 + for ; endingIndex < len(n.Children); endingIndex++ { + other := n.Children[endingIndex].Children[0] + if required.T != other.T || + required.Options != other.Options || + required.M != other.M || + required.N != other.N || + required.Ch != other.Ch || + !slices.Equal(required.Str, other.Str) || + !required.Set.Equals(other.Set) { + break + } + } + + if endingIndex-startingIndex <= 1 { + // Nothing to extract from this starting index. + continue + } + + // Remove the prefix node from every branch, adding it to a new alternation + newAlternate := &RegexNode{T: NtAlternate, Options: n.Options} + for i := startingIndex; i < endingIndex; i++ { + n.Children[i].Children = slices.Delete(n.Children[i].Children, 0, 1) + newAlternate.addChild(n.Children[i]) + } + + // If this alternation is wrapped as atomic, we need to do the same for the new alternation. + if n.Parent != nil && n.Parent.T == NtAtomic { + atomic := &RegexNode{T: NtAtomic, Options: n.Options} + atomic.addChild(newAlternate) + newAlternate = atomic + } + + // Now create a concatenation of the prefix node with the new alternation for the combined + // branches, and replace all of the branches in this alternation with that new concatenation. + newConcat := &RegexNode{T: NtConcatenate, Options: n.Options} + newConcat.addChild(required) + newConcat.addChild(newAlternate) + n.ReplaceChild(startingIndex, newConcat) + n.Children = slices.Delete(n.Children, startingIndex+1, endingIndex) + } + + return n.replaceNodeIfUnnecessary() +} + +// Removes unnecessary Empty and Nothing nodes from the alternation. A Nothing will never +// match, so it can be removed entirely, and an Empty can be removed if there's a previous +// Empty in the alternation: it's an extreme case of just having a repeated branch in an +// alternation, and while we don't check for all duplicates, checking for empty is easy. +func (n *RegexNode) removeRedundantEmptiesAndNothings() *RegexNode { + children := n.Children + + i, j := 0, 0 + seenEmpty := false + for i < len(children) { + child := children[i] + if child.T == NtNothing || (child.T == NtEmpty && seenEmpty) { + i++ + continue + } + if child.T == NtEmpty { + seenEmpty = true + } + children[j] = children[i] + i++ + j++ + } + + n.Children = slices.Delete(children, j, len(children)) + return n.replaceNodeIfUnnecessary() +} + +// Remove the starting text from the one or multi node. This may end up changing +// the type of the node to be Empty if the starting text matches the node's full value. +func (n *RegexNode) processOneOrMulti(startingSpan []rune) { + if n.T == NtOne { + n.T = NtEmpty + n.Ch = 0x0 + } else { + if len(n.Str) == len(startingSpan) { + n.T = NtEmpty + n.Str = nil + } else if len(n.Str)-1 == len(startingSpan) { + n.T = NtOne + n.Ch = n.Str[len(n.Str)-1] + n.Str = nil + } else { + n.Str = n.Str[len(startingSpan):] + } + } +} + +// Finds the starting one or multi of the branch, if it has one; otherwise, returns null. +// For simplicity, this only considers branches that are One or Multi, or a Concatenation +// beginning with a One or Multi. We don't traverse more than one level to avoid the +// complication of then having to later update that hierarchy when removing the prefix, +// but it could be done in the future if proven beneficial enough. +func (n *RegexNode) findBranchOneOrMultiStart() *RegexNode { + branch := n + if n.T == NtConcatenate { + branch = n.Children[0] + } + if branch.T == NtOne || branch.T == NtMulti { + return branch + } + return nil +} + +func (n *RegexNode) reduceSingleLetterAndNestedAlternations() { + + wasLastSet := false + lastNodeCannotMerge := false + var optionsLast RegexOptions + var i, j int + + for i, j = 0, 0; i < len(n.Children); i, j = i+1, j+1 { + at := n.Children[i] + + if j < i { + n.Children[j] = at + } + + for { + if at.T == NtAlternate { + n.insertChildren(i+1, at.Children) + j-- + } else if at.T == NtSet || at.T == NtOne { + // Cannot merge sets if L or I options differ, or if either are negated. + optionsAt := at.Options & (RightToLeft | IgnoreCase) + + if at.T == NtSet { + if !wasLastSet || optionsLast != optionsAt || lastNodeCannotMerge || !at.Set.IsMergeable() { + wasLastSet = true + lastNodeCannotMerge = !at.Set.IsMergeable() + optionsLast = optionsAt + break + } + } else if !wasLastSet || optionsLast != optionsAt || lastNodeCannotMerge { + wasLastSet = true + lastNodeCannotMerge = false + optionsLast = optionsAt + break + } + + // The last node was a Set or a One, we're a Set or One and our options are the same. + // Merge the two nodes. + j-- + prev := n.Children[j] + + var prevCharClass *CharSet + if prev.T == NtOne { + prevCharClass = &CharSet{} + prevCharClass.addChar(prev.Ch) + } else { + prevCharClass = prev.Set + } + + if at.T == NtOne { + prevCharClass.addChar(at.Ch) + } else { + prevCharClass.addSet(*at.Set) + } + + prev.T = NtSet + prev.Set = prevCharClass + if prev.Options&IgnoreCase != 0 { + prev.Options &= ^IgnoreCase + } + } else if at.T == NtNothing { + j-- + } else { + wasLastSet = false + lastNodeCannotMerge = false + } + break + } + } + + if j < i { + n.removeChildren(j, i) + } +} + +func (n *RegexNode) reduceConcatenation() *RegexNode { + // Eliminate empties and concat adjacent strings/chars + + if len(n.Children) == 0 { + return newRegexNode(NtEmpty, n.Options) + } + // remove concat + if len(n.Children) == 1 { + return n.Children[0] + } + + // If any node in the concatenation is a Nothing, the concatenation itself is a Nothing. + for i := 0; i < len(n.Children); i++ { + child := n.Children[i] + if child.T == NtNothing { + return child + } + } + + // Coalesce adjacent loops. This helps to minimize work done by the interpreter, minimize code gen, + // and also help to reduce catastrophic backtracking. + n.reduceConcatenationWithAdjacentLoops() + + // Coalesce adjacent characters/strings. This is done after the adjacent loop coalescing so that + // a One adjacent to both a Multi and a Loop prefers being folded into the Loop rather than into + // the Multi. Doing so helps with auto-atomicity when it's later applied. + n.reduceConcatenationWithAdjacentStrings() + + // If the concatenation is now empty, return an empty node, or if it's got a single child, return that child. + // Otherwise, return this. + return n.replaceNodeIfUnnecessary() +} + +func addMinLength(x, y int) int { + const maxMinLength = math.MaxInt32 - 1 + if x >= maxMinLength || y >= maxMinLength || x > maxMinLength-y { + return maxMinLength + } + return x + y +} + +func multiplyMinLength(x, y int) int { + const maxMinLength = math.MaxInt32 - 1 + if x == 0 || y == 0 { + return 0 + } + if x >= maxMinLength || y >= maxMinLength || x > maxMinLength/y { + return maxMinLength + } + return x * y +} + +func addMaxLength(x, y int) int { + if x < 0 || y < 0 || x >= math.MaxInt32 || y >= math.MaxInt32 || x > (math.MaxInt32-1)-y { + return -1 + } + return x + y +} + +func multiplyMaxLength(x, y int) int { + if x < 0 || y < 0 { + return -1 + } + if x == 0 || y == 0 { + return 0 + } + if x >= math.MaxInt32 || y >= math.MaxInt32 || x > (math.MaxInt32-1)/y { + return -1 + } + return x * y +} + +func maxLessThanTwiceMin(max, min int) bool { + if min <= math.MaxInt32/2 { + return max < min*2 + } + return max != math.MaxInt32 +} + +func canCombineCounts(nodeMin, nodeMax, nextMin, nextMax int) bool { + // We shouldn't have an infinite minimum; bail if we find one. Also check for the + // degenerate case where we'd make the min overflow or go infinite when it wasn't already. + if nodeMin == math.MaxInt32 || + nextMin == math.MaxInt32 || + addMaxLength(nodeMin, nextMin) < 0 { + return false + } + + // Similar overflow / go infinite check for max (which can be infinite). + if nodeMax != math.MaxInt32 && + nextMax != math.MaxInt32 && + addMaxLength(nodeMax, nextMax) < 0 { + return false + } + + return true +} + +// Combine adjacent loops. +// e.g. a*a*a* => a* +// e.g. a+ab => a{2,}b +func (n *RegexNode) reduceConcatenationWithAdjacentLoops() { + current, next, nextSave := 0, 1, 1 + + for next < len(n.Children) { + currentNode := n.Children[current] + nextNode := n.Children[next] + + if currentNode.Options == nextNode.Options { + // Coalescing a loop with its same type + if ((currentNode.IsOneloopFamily() || currentNode.IsNotoneloopFamily()) && nextNode.T == currentNode.T && currentNode.Ch == nextNode.Ch) || + (currentNode.IsSetloopFamily() && currentNode.T == nextNode.T && currentNode.Set.Equals(nextNode.Set)) { + if nextNode.M > 0 && currentNode.IsAtomicloopFamily() { + // Atomic loops can only be combined if the second loop has no lower bound, as if it has a lower bound, + // combining them changes behavior. Uncombined, the first loop can consume all matching items; + // the second loop might then not be able to meet its minimum and fail. But if they're combined, the combined + // minimum of the sole loop could now be met, introducing matches where there shouldn't have been any. + goto End + } + + if !canCombineCounts(currentNode.M, currentNode.N, nextNode.M, nextNode.N) { + goto End + } + currentNode.M += nextNode.M + if currentNode.N != math.MaxInt32 { + if nextNode.N == math.MaxInt32 { + currentNode.N = math.MaxInt32 + } else { + currentNode.N += nextNode.N + } + } + next++ + continue + + } else if ((currentNode.T == NtOneloop || currentNode.T == NtOnelazy) && nextNode.T == NtOne && currentNode.Ch == nextNode.Ch) || + ((currentNode.T == NtNotoneloop || currentNode.T == NtNotonelazy) && nextNode.T == NtNotone && currentNode.Ch == nextNode.Ch) || + ((currentNode.T == NtSetloop || currentNode.T == NtSetlazy) && nextNode.T == NtSet && currentNode.Set.Equals(nextNode.Set)) { + // Coalescing a loop with an additional item of the same type + if canCombineCounts(currentNode.M, currentNode.N, 1, 1) { + currentNode.M++ + if currentNode.N != math.MaxInt32 { + currentNode.N++ + } + next++ + continue + } + } else if (currentNode.T == NtOneloop || currentNode.T == NtOnelazy) && nextNode.T == NtMulti && currentNode.Ch == nextNode.Str[0] { + // Coalescing a loop with a subsequent string + // Determine how many of the multi's characters can be combined. + // We already checked for the first, so we know it's at least one. + matchingCharsInMulti := 1 + for matchingCharsInMulti < len(nextNode.Str) && currentNode.Ch == nextNode.Str[matchingCharsInMulti] { + matchingCharsInMulti++ + } + + if canCombineCounts(currentNode.M, currentNode.N, matchingCharsInMulti, matchingCharsInMulti) { + // Update the loop's bounds to include those characters from the multi + currentNode.M += matchingCharsInMulti + if currentNode.N != math.MaxInt32 { + currentNode.N += matchingCharsInMulti + } + + // If it was the full multi, skip/remove the multi and continue processing this loop. + if len(nextNode.Str) == matchingCharsInMulti { + next++ + continue + } + + // Otherwise, trim the characters from the multiple that were absorbed into the loop. + // If it now only has a single character, it becomes a One. + if len(nextNode.Str)-matchingCharsInMulti == 1 { + nextNode.T = NtOne + nextNode.Ch = nextNode.Str[len(nextNode.Str)-1] + nextNode.Str = nil + } else { + nextNode.Str = nextNode.Str[matchingCharsInMulti:] + } + } + + // NOTE: We could add support for coalescing a string with a subsequent loop, but the benefits of that + // are limited. Pulling a subsequent string's prefix back into the loop helps with making the loop atomic, + // but if the loop is after the string, pulling the suffix of the string forward into the loop may actually + // be a deoptimization as those characters could end up matching more slowly as part of loop matching. + + } else if (currentNode.T == NtOne && nextNode.IsOneloopFamily() && currentNode.Ch == nextNode.Ch) || + (currentNode.T == NtNotone && nextNode.IsNotoneloopFamily() && currentNode.Ch == nextNode.Ch) || + (currentNode.T == NtSet && nextNode.IsSetloopFamily() && currentNode.Set.Equals(nextNode.Set)) { + // Coalescing an individual item with a loop. + if canCombineCounts(1, 1, nextNode.M, nextNode.N) { + currentNode.T = nextNode.T + currentNode.M = nextNode.M + 1 + if nextNode.N == math.MaxInt32 { + currentNode.N = math.MaxInt32 + } else { + currentNode.N = nextNode.N + 1 + } + next++ + continue + } + } else if (currentNode.T == NtNotone && nextNode.T == NtNotone && currentNode.Ch == nextNode.Ch) || + (currentNode.T == NtSet && nextNode.T == NtSet && currentNode.Set.Equals(nextNode.Set)) { + // Coalescing an individual item with another individual item. + // We don't coalesce adjacent One nodes into a Oneloop as we'd rather they be joined into a Multi. + currentNode.makeRep(NtOneloop, 2, 2) + next++ + continue + } + + End: + } + + n.Children[nextSave] = n.Children[next] + nextSave++ + current = next + next++ + } + + if nextSave < len(n.Children) { + n.Children = slices.Delete(n.Children, nextSave, len(n.Children)) + } +} + +// Basic optimization. Adjacent strings can be concatenated. +// +// (?:abc)(?:def) -> abcdef +func (n *RegexNode) reduceConcatenationWithAdjacentStrings() { + var optionsLast RegexOptions + var optionsAt RegexOptions + var i, j int + + wasLastString := false + + for i, j = 0, 0; i < len(n.Children); i, j = i+1, j+1 { + var at, prev *RegexNode + + at = n.Children[i] + + if j < i { + n.Children[j] = at + } + + if at.T == NtConcatenate && + ((at.Options & RightToLeft) == (n.Options & RightToLeft)) { + for k := 0; k < len(at.Children); k++ { + at.Children[k].Parent = n + } + + //insert at.children at i+1 index in n.children + n.insertChildren(i+1, at.Children) + + j-- + } else if at.T == NtMulti || at.T == NtOne { + // Cannot merge strings if L or I options differ + optionsAt = at.Options & (RightToLeft | IgnoreCase) + + if !wasLastString || optionsLast != optionsAt { + wasLastString = true + optionsLast = optionsAt + continue + } + + j-- + prev = n.Children[j] + + if prev.T == NtOne { + prev.T = NtMulti + prev.Str = []rune{prev.Ch} + } + + if (optionsAt & RightToLeft) == 0 { + if at.T == NtOne { + prev.Str = append(prev.Str, at.Ch) + } else { + prev.Str = append(prev.Str, at.Str...) + } + } else { + if at.T == NtOne { + // insert at the front by expanding our slice, copying the data over, and then setting the value + prev.Str = append(prev.Str, 0) + copy(prev.Str[1:], prev.Str) + prev.Str[0] = at.Ch + } else { + //insert at the front...this one we'll make a new slice and copy both into it + merge := make([]rune, len(prev.Str)+len(at.Str)) + copy(merge, at.Str) + copy(merge[len(at.Str):], prev.Str) + prev.Str = merge + } + } + } else if at.T == NtEmpty { + j-- + } else { + wasLastString = false + } + } + + if j < i { + // remove indices j through i from the children + n.removeChildren(j, i) + } +} + +// Nested repeaters just get multiplied with each other if they're not +// too lumpy +func (n *RegexNode) reduceRep() *RegexNode { + + u := n + t := n.T + min := n.M + max := n.N + + for len(u.Children) > 0 { + child := u.Children[0] + + // multiply reps of the same type only + if child.T != t { + valid := false + if t == NtLoop { + switch child.T { + case NtOneloop, NtOneloopatomic, NtNotoneloop, + NtNotoneloopatomic, NtSetloop, NtSetloopatomic: + valid = true + } + } else { + switch child.T { + case NtOnelazy, NtNotonelazy, NtSetlazy: + valid = true + } + } + if !valid { + break + } + } + + // child can be too lumpy to blur, e.g., (a {100,105}) {3} or (a {2,})? + // [but things like (a {2,})+ are not too lumpy...] + if u.M == 0 && child.M > 1 || maxLessThanTwiceMin(child.N, child.M) { + break + } + + u = child + if u.M > 0 { + if (math.MaxInt32-1)/u.M < min { + u.M = math.MaxInt32 + } else { + u.M *= min + } + } + if u.N > 0 { + if (math.MaxInt32-1)/u.N < max { + u.N = math.MaxInt32 + } else { + u.N *= max + } + } + } + + if min == math.MaxInt32 { + return newRegexNode(NtNothing, n.Options) + } + + // If the Loop or Lazyloop now only has one child node and its a Set, One, or Notone, + // reduce to just Setloop/lazy, Oneloop/lazy, or Notoneloop/lazy. The parser will + // generally have only produced the latter, but other reductions could have exposed + // this. + if len(u.Children) == 1 { + child := u.Children[0] + switch child.T { + case NtOne, NtNotone, NtSet: + if u.T == NtLazyloop { + child.makeRep(NtOnelazy, u.M, u.N) + } else { + child.makeRep(NtOneloop, u.M, u.N) + } + u = child + } + } + + return u + +} + +// Simple optimization. If a concatenation or alternation has only +// one child strip out the intermediate node. If it has zero children, +// turn it into an empty. +func (n *RegexNode) replaceNodeIfUnnecessary() *RegexNode { + switch len(n.Children) { + case 0: + emptyType := NtEmpty + if n.T == NtAlternate { + emptyType = NtNothing + } + return newRegexNode(emptyType, n.Options) + case 1: + return n.Children[0] + default: + return n + } +} + +func (n *RegexNode) reduceGroup() *RegexNode { + u := n + + for u.T == NtGroup { + u = u.Children[0] + } + + return u +} + +// Simple optimization. If a set is a singleton, an inverse singleton, +// or empty, it's transformed accordingly. +func (n *RegexNode) reduceSet() *RegexNode { + // Extract empty-set, one and not-one case as special + + if n.Set == nil { + n.T = NtNothing + } else if n.Set.IsSingleton() { + n.Ch = n.Set.SingletonChar() + n.Set = nil + n.T += (NtOne - NtSet) + } else if n.Set.IsSingletonInverse() { + n.Ch = n.Set.SingletonChar() + n.Set = nil + n.T += (NtNotone - NtSet) + } + + return n +} + +func (n *RegexNode) reverseLeft() *RegexNode { + if n.Options&RightToLeft != 0 && n.T == NtConcatenate && len(n.Children) > 0 { + //reverse children order + for left, right := 0, len(n.Children)-1; left < right; left, right = left+1, right-1 { + n.Children[left], n.Children[right] = n.Children[right], n.Children[left] + } + } + + return n +} + +func (n *RegexNode) makeQuantifier(lazy bool, min, max int) *RegexNode { + // Certain cases of repeaters (min == max) can be handled specially + if min == 0 && max == 0 { + // The node is repeated 0 times, so it's actually empty. + return newRegexNode(NtEmpty, n.Options) + } + + if min == 1 && max == 1 { + // The node is repeated 1 time, so it's not actually a repeater. + return n + } + + if min == max && max <= MultiVsRepeaterLimit && n.T == NtOne { + // The same character is repeated a fixed number of times, so it's actually a multi. + // While this could remain a repeater, multis are more readily optimized later in + // processing. The counts used here in real-world expressions are invariably small (e.g. 4), + // but we set an upper bound just to avoid creating really large strings. + n.T = NtMulti + n.Str = []rune(strings.Repeat(string(n.Ch), max)) + n.Ch = 0 + return n + } + + switch n.T { + case NtOne, NtNotone, NtSet: + if lazy { + n.makeRep(NtOnelazy, min, max) + } else { + n.makeRep(NtOneloop, min, max) + } + return n + + default: + var t NodeType + if lazy { + t = NtLazyloop + } else { + t = NtLoop + } + result := newRegexNodeMN(t, n.Options, min, max) + result.addChild(n) + return result + } +} + +// Computes a min bound on the required length of any string that could possibly match. +// If the result is 0, there is no minimum we can enforce. +func (n *RegexNode) ComputeMinLength() int { + switch n.T { + case NtOne, NtNotone, NtSet: + // single char + return 1 + case NtMulti: + // Every character in the string needs to match. + return len(n.Str) + case NtNotonelazy, NtNotoneloop, NtNotoneloopatomic, + NtOnelazy, NtOneloop, NtOneloopatomic, NtSetlazy, NtSetloop, NtSetloopatomic: + // One character repeated at least M times. + return n.M + case NtLazyloop, NtLoop: + // A node graph repeated at least M times. + return multiplyMinLength(n.M, n.Children[0].ComputeMinLength()) + case NtAlternate: + // The minimum required length for any of the alternation's branches. + childCount := len(n.Children) + min := n.Children[0].ComputeMinLength() + for i := 1; i < childCount && min > 0; i++ { + newMin := n.Children[i].ComputeMinLength() + if newMin < min { + min = newMin + } + } + return min + case NtBackRefCond: + // Minimum of its yes and no branches. The backreference doesn't add to the length. + b1 := n.Children[0].ComputeMinLength() + if len(n.Children) == 1 { + return b1 + } + b2 := n.Children[1].ComputeMinLength() + if b1 < b2 { + return b1 + } + return b2 + case NtExprCond: + // Minimum of its yes and no branches. The condition is a zero-width assertion. + if len(n.Children) == 2 { + return n.Children[1].ComputeMinLength() + } + b1 := n.Children[1].ComputeMinLength() + b2 := n.Children[2].ComputeMinLength() + if b1 < b2 { + return b1 + } + return b2 + case NtConcatenate: + // The sum of all of the concatenation's children. + sum := 0 + for i := 0; i < len(n.Children); i++ { + sum = addMinLength(sum, n.Children[i].ComputeMinLength()) + } + return sum + case NtAtomic, NtCapture, NtGroup: + // For groups, we just delegate to the sole child. + return n.Children[0].ComputeMinLength() + case NtEmpty, NtNothing, + NtBeginning, NtBol, NtBoundary, NtECMABoundary, NtEnd, NtEndZ, NtEol, + NtNonboundary, NtNonECMABoundary, NtStart, NtNegLook, NtPosLook, NtRef: + // Nothing to match. In the future, we could potentially use Nothing to say that the min length + // is infinite, but that would require a different structure, as that would only apply if the + // Nothing match is required in all cases (rather than, say, as one branch of an alternation). + } + return 0 +} + +// Computes a maximum length of any string that could possibly match. +// or -1 if the length may not always be the same. +func (n *RegexNode) computeMaxLength() int { + switch n.T { + case NtOne, NtNotone, NtSet: + return 1 + case NtMulti: + return len(n.Str) + case NtNotonelazy, NtNotoneloop, NtNotoneloopatomic, + NtOnelazy, NtOneloop, NtOneloopatomic, + NtSetlazy, NtSetloop, NtSetloopatomic: + // Return the max number of iterations if there's an upper bound, or null if it's infinite + if n.N == math.MaxInt32 { + return -1 + } + return n.N + case NtLazyloop, NtLoop: + if n.N == math.MaxInt32 { + return -1 + } + // A node graph repeated a fixed number of times + if c := n.Children[0].computeMaxLength(); c >= 0 { + return multiplyMaxLength(n.N, c) + } + case NtAlternate: + // The maximum length of any child branch, as long as they all have one. + c := n.Children[0].computeMaxLength() + + if c < 0 { + return -1 + } + for i := 1; i < len(n.Children); i++ { + c2 := n.Children[i].computeMaxLength() + if c2 < 0 { + return -1 + } + + c = max(c, c2) + } + return c + case NtBackRefCond: + // The maximum length of either child branch, as long as they both have one. + b1 := n.Children[0].computeMaxLength() + if b1 < 0 { + return -1 + } + b2 := n.Children[1].computeMaxLength() + if b2 < 0 { + return -1 + } + return max(b1, b2) + + case NtExprCond: + // The condition for an expression conditional is a zero-width assertion. + b1 := n.Children[1].computeMaxLength() + if b1 < 0 { + return -1 + } + b2 := n.Children[2].computeMaxLength() + if b2 < 0 { + return -1 + } + return max(b1, b2) + + case NtConcatenate: + // The sum of all of the concatenation's children's max lengths, as long as they all have one. + sum := 0 + for i := 0; i < len(n.Children); i++ { + c := n.Children[i].computeMaxLength() + if c < 0 { + return -1 + } + sum = addMaxLength(sum, c) + if sum < 0 { + return -1 + } + } + return sum + + case NtAtomic, NtCapture: + // For groups, we just delegate to the sole child. + return n.Children[0].computeMaxLength() + case NtEmpty, NtNothing, NtUpdateBumpalong, + NtBeginning, NtBol, NtBoundary, NtECMABoundary, NtEnd, NtEndZ, NtEol, + NtNonboundary, NtNonECMABoundary, NtStart, NtNegLook, NtPosLook: + //zero-width + return 0 + + case NtRef: + // Requires matching data available only at run-time. In the future, we could choose to find + // and follow the capture group this aligns with, while being careful not to end up in an + // infinite cycle. + return -1 + } + + return -1 +} + +// debug functions + +var typeStr = []string{ + "Onerep", "Notonerep", "Setrep", + "Oneloop", "Notoneloop", "Setloop", + "Onelazy", "Notonelazy", "Setlazy", + "One", "Notone", "Set", + "Multi", "Ref", + "Bol", "Eol", "Boundary", "Nonboundary", + "Beginning", "Start", "EndZ", "End", + "Nothing", "Empty", + "Alternate", "Concatenate", + "Loop", "Lazyloop", + "Capture", "Group", "PosLook", "NegLook", "Atomic", + "BackRefCond", "ExprCond", + "Unknown", "Unknown", "Unknown", + "Unknown", "Unknown", "Unknown", + "ECMABoundary", "NonECMABoundary", + "OneloopAtomic", "NotoneloopAtomic", "SetloopAtomic", + "UpdateBumpalong", +} + +func (n *RegexNode) Description() string { + buf := &bytes.Buffer{} + + buf.WriteString(typeStr[n.T]) + + if (n.Options & ExplicitCapture) != 0 { + buf.WriteString("-C") + } + if (n.Options & IgnoreCase) != 0 { + buf.WriteString("-I") + } + if (n.Options & RightToLeft) != 0 { + buf.WriteString("-L") + } + if (n.Options & Multiline) != 0 { + buf.WriteString("-M") + } + if (n.Options & Singleline) != 0 { + buf.WriteString("-S") + } + if (n.Options & IgnorePatternWhitespace) != 0 { + buf.WriteString("-X") + } + if (n.Options & ECMAScript) != 0 { + buf.WriteString("-E") + } + + switch n.T { + case NtOneloop, NtOneloopatomic, NtNotoneloop, NtOnelazy, NtNotonelazy, NtOne, NtNotone, NtNotoneloopatomic: + buf.WriteString("(Ch = " + CharDescription(n.Ch) + ")") + case NtCapture: + buf.WriteString("(index = " + strconv.Itoa(n.M) + ", unindex = " + strconv.Itoa(n.N) + ")") + case NtRef, NtBackRefCond: + buf.WriteString("(index = " + strconv.Itoa(n.M) + ")") + case NtMulti: + fmt.Fprintf(buf, "(String = %#v)", string(n.Str)) + case NtSet, NtSetloop, NtSetlazy, NtSetloopatomic: + buf.WriteString("(Set = " + n.Set.String() + ")") + } + + switch n.T { + case NtOneloop, NtNotoneloop, NtOnelazy, NtNotonelazy, NtSetloop, NtSetlazy, NtLoop, NtLazyloop, + NtOneloopatomic, NtNotoneloopatomic, NtSetloopatomic: + + buf.WriteString("(Min = ") + buf.WriteString(strconv.Itoa(n.M)) + buf.WriteString(", Max = ") + if n.N == math.MaxInt32 { + buf.WriteString("inf") + } else { + buf.WriteString(strconv.Itoa(n.N)) + } + buf.WriteString(")") + } + + return buf.String() +} + +var padSpace = []byte(" ") + +func (t *RegexTree) Dump() string { + return t.Root.dump() +} + +func (n *RegexNode) dump() string { + var stack []int + CurNode := n + CurChild := 0 + + buf := bytes.NewBufferString(CurNode.Description()) + buf.WriteRune('\n') + + for { + if CurNode.Children != nil && CurChild < len(CurNode.Children) { + stack = append(stack, CurChild+1) + CurNode = CurNode.Children[CurChild] + CurChild = 0 + + Depth := len(stack) + if Depth > 32 { + Depth = 32 + } + buf.Write(padSpace[:Depth]) + buf.WriteString(CurNode.Description()) + buf.WriteRune('\n') + } else { + if len(stack) == 0 { + break + } + + CurChild = stack[len(stack)-1] + stack = stack[:len(stack)-1] + CurNode = CurNode.Parent + } + } + return buf.String() +} + +// Determines whether the specified child index of a concatenation begins a sequence whose values +// should be used to perform an ordinal case-insensitive comparison. +// +// When consumeZeroWidthNodes is false, the consumer needs the semantics of matching the produced string to fully represent +// the semantics of all the consumed nodes, which means nodes can be consumed iff they produce text that's represented +// by the resulting string. When true, the resulting string needs to fully represent all valid matches at that position, +// but it can have false positives, which means the resulting string doesn't need to fully represent all zero-width nodes +// consumed. true is only valid when used as part of a search to determine where to try a full match, not as part of +// actual matching logic. +// consumeZeroWidthNodes = false +func (n *RegexNode) TryGetOrdinalCaseInsensitiveString(childIndex int, exclusiveChildBound int, consumeZeroWidthNodes bool) (success bool, nodesConsumed int, caseInsensitiveString string) { + vsb := &strings.Builder{} + + // We're looking in particular for sets of ASCII characters, so we focus only on sets with two characters in them, e.g. [Aa]. + //twoChars := make([]rune, 0, 2) + + // Iterate from the child index to the exclusive upper bound. + var i int + for i = childIndex; i < exclusiveChildBound; i++ { + child := n.Children[i] + + if child.T == NtOne { + // We only want to include ASCII characters, and only if they don't participate in case conversion + // such that they only case to themselves and nothing other cases to them. Otherwise, including + // them would potentially cause us to match against things not allowed by the pattern. + if child.Ch >= unicode.MaxASCII || participatesInCaseConversion(child.Ch) { + break + } + + vsb.WriteRune(child.Ch) + } else if child.T == NtMulti { + // As with NtOne, the string needs to be composed solely of ASCII characters that + // don't participate in case conversion. + hasNonAscii := slices.ContainsFunc(child.Str, func(ch rune) bool { return ch > unicode.MaxASCII }) + if hasNonAscii || anyParticipatesInCaseConversion(string(child.Str)) { + break + } + + vsb.WriteString(string(child.Str)) + } else if child.T == NtSet || + ((child.T == NtSetloop || child.T == NtSetlazy || child.T == NtSetloopatomic) && child.M == child.N) { + // In particular we want to look for sets that contain only the upper and lowercase variant + // of the same ASCII letter. + ok, twoChars := child.Set.containsAsciiIgnoreCaseCharacter() + if !ok { + break + } + + count := child.M + if child.T == NtSet { + count = 1 + } + vsb.WriteString(strings.Repeat(string(twoChars[0]|0x20), count)) + } else if child.T == NtEmpty { + // Skip over empty nodes, as they're pure nops. They would ideally have been optimized away, + // but can still remain in some situations. + } else if consumeZeroWidthNodes && + // anchors + (child.T == NtBeginning || child.T == NtBol || child.T == NtStart || + // boundaries + child.T == NtBoundary || child.T == NtECMABoundary || child.T == NtNonboundary || child.T == NtNonECMABoundary || + // lookarounds + child.T == NtNegLook || child.T == NtPosLook || + // logic + child.T == NtUpdateBumpalong) { + // Skip over zero-width nodes that might be reasonable at the beginning of or within a substring. + // We can only do these if consumeZeroWidthNodes is true, as otherwise we'd be producing a string that + // may not fully represent the semantics of this portion of the pattern. + } else { + break + } + } + + // If we found at least two characters, consider it a sequence found. It's possible + // they all came from the same node, so this could be a sequence of just one node. + if vsb.Len() >= 2 { + return true, i - childIndex, vsb.String() + } + + // No sequence found. + return false, 0, "" +} + +func (child *RegexNode) canJoinLengthCheck() bool { + if child.T == NtOne || child.T == NtNotone || child.T == NtSet || child.T == NtMulti { + return true + } + if (child.IsSetloopFamily() || child.IsNotoneloopFamily() || child.IsOneloopFamily()) && + child.M == child.N { + return true + } + + return false +} + +// Determine whether the specified child node is the beginning of a sequence that can +// trivially have length checks combined in order to avoid bounds checks. +// requiredLength is The sum of all the fixed lengths for the nodes in the sequence. +// exclusiveEnd is The index of the node just after the last one in the sequence. +// returns true if more than one node can have their length checks combined; otherwise, false. +// +// There are additional node types for which we can prove a fixed length, e.g. examining all branches +// of an alternation and returning true if all their lengths are equal. However, the primary purpose +// of this method is to avoid bounds checks by consolidating length checks that guard accesses to +// strings/spans for which the JIT can see a fixed index within bounds, and alternations employ +// patterns that defeat that (e.g. reassigning the span in question). As such, the implementation +// remains focused on only a core subset of nodes that are a) likely to be used in concatenations and +// b) employ simple patterns of checks. +func (n *RegexNode) TryGetJoinableLengthCheckChildRange(childIndex int, requiredLength *int, exclusiveEnd *int) bool { + + child := n.Children[childIndex] + if child.canJoinLengthCheck() { + *requiredLength = child.ComputeMinLength() + + for *exclusiveEnd = childIndex + 1; *exclusiveEnd < len(n.Children); *exclusiveEnd++ { + child = n.Children[*exclusiveEnd] + if !child.canJoinLengthCheck() { + break + } + + *requiredLength += child.ComputeMinLength() + } + + if *exclusiveEnd-childIndex > 1 { + return true + } + } + + *requiredLength = 0 + *exclusiveEnd = 0 + return false +} + +type StartingLiteral struct { + Range SingleRange + String []rune + SetChars []rune + Negated bool +} + +func (n *RegexNode) FindStartingLiteral() *StartingLiteral { + node := n.FindStartingLiteralNode(true) + if node == nil { + return nil + } + + if node.IsOneFamily() { + return &StartingLiteral{Range: SingleRange{node.Ch, node.Ch}, Negated: false} + } + if node.IsNotoneFamily() { + return &StartingLiteral{Range: SingleRange{node.Ch, node.Ch}, Negated: true} + } + if node.IsSetFamily() { + ranges := node.Set.GetIfNRanges(1) + if len(ranges) == 1 && ranges[0].Last-ranges[0].First > 1 { + return &StartingLiteral{Range: ranges[0], Negated: node.Set.IsNegated()} + } + setChars := node.Set.GetSetChars(128) + if len(setChars) > 0 { + return &StartingLiteral{SetChars: setChars, Negated: node.Set.IsNegated()} + } + } + if node.T == NtMulti { + return &StartingLiteral{String: node.Str} + } + + return nil +} + +// Finds the guaranteed beginning literal(s) of the node, or null if none exists. +// allowZeroWidth = true +func (n *RegexNode) FindStartingLiteralNode(allowZeroWidth bool) *RegexNode { + node := n + for { + if node != nil && node.Options&RightToLeft == 0 { + switch node.T { + case NtOne, NtNotone, NtMulti, NtSet: + return node + + case NtOneloop, NtOneloopatomic, NtOnelazy, + NtNotoneloop, NtNotoneloopatomic, NtNotonelazy, + NtSetloop, NtSetloopatomic, NtSetlazy: + if node.M > 0 { + return node + } + + case NtAtomic, NtConcatenate, NtCapture, NtGroup: + node = node.Children[0] + continue + case NtLoop, NtLazyloop: + node = node.Children[0] + continue + case NtPosLook: + if allowZeroWidth { + node = node.Children[0] + continue + } + } + } + + return nil + } +} + +// Gets the character that begins a One or Multi. +func (n *RegexNode) FirstCharOfOneOrMulti() rune { + if n.IsOneFamily() { + return n.Ch + } + return n.Str[0] +} diff --git a/vendor/github.com/dlclark/regexp2/v2/syntax/unicode_alias_tables.go b/vendor/github.com/dlclark/regexp2/v2/syntax/unicode_alias_tables.go new file mode 100644 index 000000000..a165b57ea --- /dev/null +++ b/vendor/github.com/dlclark/regexp2/v2/syntax/unicode_alias_tables.go @@ -0,0 +1,6058 @@ +package syntax + +import "unicode" + +const unicodePropertyTableVersion = "17.0.0" +const goUnicodeTableVersion = unicode.Version + +// Unicode property alias tables generated from Unicode 17.0.0 data. +// +// At generation time, the Go standard library Unicode tables used for scripts, +// general categories, category aliases, and built-in properties are Unicode +// 15.0.0 in the supported Go toolchain. These package-local tables +// intentionally use Unicode 17.0.0 for commonly updated properties, especially Emoji and +// Extended_Pictographic. +// +// Sources: +// - PropertyAliases.txt +// - PropertyValueAliases.txt +// - DerivedCoreProperties.txt +// - emoji/emoji-data.txt +// - auxiliary/GraphemeBreakProperty.txt +// - auxiliary/WordBreakProperty.txt +// - auxiliary/SentenceBreakProperty.txt +var unicodeAliasCategories = map[string]*unicode.RangeTable{ + "Emoji": unicodeAliasEmoji, + "Emoji_Component": unicodeAliasEmoji_Component, + "Emoji_Modifier": unicodeAliasEmoji_Modifier, + "Emoji_Modifier_Base": unicodeAliasEmoji_Modifier_Base, + "Emoji_Presentation": unicodeAliasEmoji_Presentation, + "Extended_Pictographic": unicodeAliasExtended_Pictographic, + "Grapheme_Cluster_Break=CR": unicodeAliasGrapheme_Cluster_Break_CR, + "Grapheme_Cluster_Break=Control": unicodeAliasGrapheme_Cluster_Break_Control, + "Grapheme_Cluster_Break=Extend": unicodeAliasGrapheme_Cluster_Break_Extend, + "Grapheme_Cluster_Break=L": unicodeAliasGrapheme_Cluster_Break_L, + "Grapheme_Cluster_Break=LF": unicodeAliasGrapheme_Cluster_Break_LF, + "Grapheme_Cluster_Break=LV": unicodeAliasGrapheme_Cluster_Break_LV, + "Grapheme_Cluster_Break=LVT": unicodeAliasGrapheme_Cluster_Break_LVT, + "Grapheme_Cluster_Break=Prepend": unicodeAliasGrapheme_Cluster_Break_Prepend, + "Grapheme_Cluster_Break=Regional_Indicator": unicodeAliasGrapheme_Cluster_Break_Regional_Indicator, + "Grapheme_Cluster_Break=SpacingMark": unicodeAliasGrapheme_Cluster_Break_SpacingMark, + "Grapheme_Cluster_Break=T": unicodeAliasGrapheme_Cluster_Break_T, + "Grapheme_Cluster_Break=V": unicodeAliasGrapheme_Cluster_Break_V, + "Grapheme_Cluster_Break=ZWJ": unicodeAliasGrapheme_Cluster_Break_ZWJ, + "Math": unicodeAliasMath, + "Sentence_Break=ATerm": unicodeAliasSentence_Break_ATerm, + "Sentence_Break=CR": unicodeAliasSentence_Break_CR, + "Sentence_Break=Close": unicodeAliasSentence_Break_Close, + "Sentence_Break=Extend": unicodeAliasSentence_Break_Extend, + "Sentence_Break=Format": unicodeAliasSentence_Break_Format, + "Sentence_Break=LF": unicodeAliasSentence_Break_LF, + "Sentence_Break=Lower": unicodeAliasSentence_Break_Lower, + "Sentence_Break=Numeric": unicodeAliasSentence_Break_Numeric, + "Sentence_Break=OLetter": unicodeAliasSentence_Break_OLetter, + "Sentence_Break=SContinue": unicodeAliasSentence_Break_SContinue, + "Sentence_Break=STerm": unicodeAliasSentence_Break_STerm, + "Sentence_Break=Sep": unicodeAliasSentence_Break_Sep, + "Sentence_Break=Sp": unicodeAliasSentence_Break_Sp, + "Sentence_Break=Upper": unicodeAliasSentence_Break_Upper, + "Word_Break=ALetter": unicodeAliasWord_Break_ALetter, + "Word_Break=CR": unicodeAliasWord_Break_CR, + "Word_Break=Double_Quote": unicodeAliasWord_Break_Double_Quote, + "Word_Break=Extend": unicodeAliasWord_Break_Extend, + "Word_Break=ExtendNumLet": unicodeAliasWord_Break_ExtendNumLet, + "Word_Break=Format": unicodeAliasWord_Break_Format, + "Word_Break=Hebrew_Letter": unicodeAliasWord_Break_Hebrew_Letter, + "Word_Break=Katakana": unicodeAliasWord_Break_Katakana, + "Word_Break=LF": unicodeAliasWord_Break_LF, + "Word_Break=MidLetter": unicodeAliasWord_Break_MidLetter, + "Word_Break=MidNum": unicodeAliasWord_Break_MidNum, + "Word_Break=MidNumLet": unicodeAliasWord_Break_MidNumLet, + "Word_Break=Newline": unicodeAliasWord_Break_Newline, + "Word_Break=Numeric": unicodeAliasWord_Break_Numeric, + "Word_Break=Regional_Indicator": unicodeAliasWord_Break_Regional_Indicator, + "Word_Break=Single_Quote": unicodeAliasWord_Break_Single_Quote, + "Word_Break=WSegSpace": unicodeAliasWord_Break_WSegSpace, + "Word_Break=ZWJ": unicodeAliasWord_Break_ZWJ, +} + +var unicodeSupportedPropertyAliases = map[string]string{ + "ebase": "Emoji_Modifier_Base", + "ecomp": "Emoji_Component", + "emod": "Emoji_Modifier", + "emoji": "Emoji", + "emojicomponent": "Emoji_Component", + "emojimodifier": "Emoji_Modifier", + "emojimodifierbase": "Emoji_Modifier_Base", + "emojipresentation": "Emoji_Presentation", + "epres": "Emoji_Presentation", + "extendedpictographic": "Extended_Pictographic", + "extpict": "Extended_Pictographic", + "gcb": "Grapheme_Cluster_Break", + "graphemeclusterbreak": "Grapheme_Cluster_Break", + "math": "Math", + "sb": "Sentence_Break", + "sentencebreak": "Sentence_Break", + "wb": "Word_Break", + "wordbreak": "Word_Break", +} + +var unicodeSupportedPropertyValueAliases = map[string]map[string]string{ + "Grapheme_Cluster_Break": { + "cn": "Control", + "control": "Control", + "cr": "CR", + "ex": "Extend", + "extend": "Extend", + "l": "L", + "lf": "LF", + "lv": "LV", + "lvt": "LVT", + "pp": "Prepend", + "prepend": "Prepend", + "regionalindicator": "Regional_Indicator", + "ri": "Regional_Indicator", + "sm": "SpacingMark", + "spacingmark": "SpacingMark", + "t": "T", + "v": "V", + "zwj": "ZWJ", + }, + "Sentence_Break": { + "at": "ATerm", + "aterm": "ATerm", + "cl": "Close", + "close": "Close", + "cr": "CR", + "ex": "Extend", + "extend": "Extend", + "fo": "Format", + "format": "Format", + "le": "OLetter", + "lf": "LF", + "lo": "Lower", + "lower": "Lower", + "nu": "Numeric", + "numeric": "Numeric", + "oletter": "OLetter", + "sc": "SContinue", + "scontinue": "SContinue", + "se": "Sep", + "sep": "Sep", + "sp": "Sp", + "st": "STerm", + "sterm": "STerm", + "up": "Upper", + "upper": "Upper", + }, + "Word_Break": { + "aletter": "ALetter", + "cr": "CR", + "doublequote": "Double_Quote", + "dq": "Double_Quote", + "ex": "ExtendNumLet", + "extend": "Extend", + "extendnumlet": "ExtendNumLet", + "fo": "Format", + "format": "Format", + "hebrewletter": "Hebrew_Letter", + "hl": "Hebrew_Letter", + "ka": "Katakana", + "katakana": "Katakana", + "le": "ALetter", + "lf": "LF", + "mb": "MidNumLet", + "midletter": "MidLetter", + "midnum": "MidNum", + "midnumlet": "MidNumLet", + "ml": "MidLetter", + "mn": "MidNum", + "newline": "Newline", + "nl": "Newline", + "nu": "Numeric", + "numeric": "Numeric", + "regionalindicator": "Regional_Indicator", + "ri": "Regional_Indicator", + "singlequote": "Single_Quote", + "sq": "Single_Quote", + "wsegspace": "WSegSpace", + "zwj": "ZWJ", + }, +} + +var unicodeBarePropertyValueAliases = map[string]string{ + "extendnumlet": "Word_Break=ExtendNumLet", + "hebrewletter": "Word_Break=Hebrew_Letter", + "regionalindicator": "Grapheme_Cluster_Break=Regional_Indicator", + "ri": "Grapheme_Cluster_Break=Regional_Indicator", + "wsegspace": "Word_Break=WSegSpace", +} + +var unicodeAliasEmoji = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0x23, Hi: 0x23, Stride: 1}, + {Lo: 0x2A, Hi: 0x2A, Stride: 1}, + {Lo: 0x30, Hi: 0x39, Stride: 1}, + {Lo: 0xA9, Hi: 0xA9, Stride: 1}, + {Lo: 0xAE, Hi: 0xAE, Stride: 1}, + {Lo: 0x203C, Hi: 0x203C, Stride: 1}, + {Lo: 0x2049, Hi: 0x2049, Stride: 1}, + {Lo: 0x2122, Hi: 0x2122, Stride: 1}, + {Lo: 0x2139, Hi: 0x2139, Stride: 1}, + {Lo: 0x2194, Hi: 0x2199, Stride: 1}, + {Lo: 0x21A9, Hi: 0x21AA, Stride: 1}, + {Lo: 0x231A, Hi: 0x231B, Stride: 1}, + {Lo: 0x2328, Hi: 0x2328, Stride: 1}, + {Lo: 0x23CF, Hi: 0x23CF, Stride: 1}, + {Lo: 0x23E9, Hi: 0x23F3, Stride: 1}, + {Lo: 0x23F8, Hi: 0x23FA, Stride: 1}, + {Lo: 0x24C2, Hi: 0x24C2, Stride: 1}, + {Lo: 0x25AA, Hi: 0x25AB, Stride: 1}, + {Lo: 0x25B6, Hi: 0x25B6, Stride: 1}, + {Lo: 0x25C0, Hi: 0x25C0, Stride: 1}, + {Lo: 0x25FB, Hi: 0x25FE, Stride: 1}, + {Lo: 0x2600, Hi: 0x2604, Stride: 1}, + {Lo: 0x260E, Hi: 0x260E, Stride: 1}, + {Lo: 0x2611, Hi: 0x2611, Stride: 1}, + {Lo: 0x2614, Hi: 0x2615, Stride: 1}, + {Lo: 0x2618, Hi: 0x2618, Stride: 1}, + {Lo: 0x261D, Hi: 0x261D, Stride: 1}, + {Lo: 0x2620, Hi: 0x2620, Stride: 1}, + {Lo: 0x2622, Hi: 0x2623, Stride: 1}, + {Lo: 0x2626, Hi: 0x2626, Stride: 1}, + {Lo: 0x262A, Hi: 0x262A, Stride: 1}, + {Lo: 0x262E, Hi: 0x262F, Stride: 1}, + {Lo: 0x2638, Hi: 0x263A, Stride: 1}, + {Lo: 0x2640, Hi: 0x2640, Stride: 1}, + {Lo: 0x2642, Hi: 0x2642, Stride: 1}, + {Lo: 0x2648, Hi: 0x2653, Stride: 1}, + {Lo: 0x265F, Hi: 0x2660, Stride: 1}, + {Lo: 0x2663, Hi: 0x2663, Stride: 1}, + {Lo: 0x2665, Hi: 0x2666, Stride: 1}, + {Lo: 0x2668, Hi: 0x2668, Stride: 1}, + {Lo: 0x267B, Hi: 0x267B, Stride: 1}, + {Lo: 0x267E, Hi: 0x267F, Stride: 1}, + {Lo: 0x2692, Hi: 0x2697, Stride: 1}, + {Lo: 0x2699, Hi: 0x2699, Stride: 1}, + {Lo: 0x269B, Hi: 0x269C, Stride: 1}, + {Lo: 0x26A0, Hi: 0x26A1, Stride: 1}, + {Lo: 0x26A7, Hi: 0x26A7, Stride: 1}, + {Lo: 0x26AA, Hi: 0x26AB, Stride: 1}, + {Lo: 0x26B0, Hi: 0x26B1, Stride: 1}, + {Lo: 0x26BD, Hi: 0x26BE, Stride: 1}, + {Lo: 0x26C4, Hi: 0x26C5, Stride: 1}, + {Lo: 0x26C8, Hi: 0x26C8, Stride: 1}, + {Lo: 0x26CE, Hi: 0x26CF, Stride: 1}, + {Lo: 0x26D1, Hi: 0x26D1, Stride: 1}, + {Lo: 0x26D3, Hi: 0x26D4, Stride: 1}, + {Lo: 0x26E9, Hi: 0x26EA, Stride: 1}, + {Lo: 0x26F0, Hi: 0x26F5, Stride: 1}, + {Lo: 0x26F7, Hi: 0x26FA, Stride: 1}, + {Lo: 0x26FD, Hi: 0x26FD, Stride: 1}, + {Lo: 0x2702, Hi: 0x2702, Stride: 1}, + {Lo: 0x2705, Hi: 0x2705, Stride: 1}, + {Lo: 0x2708, Hi: 0x270D, Stride: 1}, + {Lo: 0x270F, Hi: 0x270F, Stride: 1}, + {Lo: 0x2712, Hi: 0x2712, Stride: 1}, + {Lo: 0x2714, Hi: 0x2714, Stride: 1}, + {Lo: 0x2716, Hi: 0x2716, Stride: 1}, + {Lo: 0x271D, Hi: 0x271D, Stride: 1}, + {Lo: 0x2721, Hi: 0x2721, Stride: 1}, + {Lo: 0x2728, Hi: 0x2728, Stride: 1}, + {Lo: 0x2733, Hi: 0x2734, Stride: 1}, + {Lo: 0x2744, Hi: 0x2744, Stride: 1}, + {Lo: 0x2747, Hi: 0x2747, Stride: 1}, + {Lo: 0x274C, Hi: 0x274C, Stride: 1}, + {Lo: 0x274E, Hi: 0x274E, Stride: 1}, + {Lo: 0x2753, Hi: 0x2755, Stride: 1}, + {Lo: 0x2757, Hi: 0x2757, Stride: 1}, + {Lo: 0x2763, Hi: 0x2764, Stride: 1}, + {Lo: 0x2795, Hi: 0x2797, Stride: 1}, + {Lo: 0x27A1, Hi: 0x27A1, Stride: 1}, + {Lo: 0x27B0, Hi: 0x27B0, Stride: 1}, + {Lo: 0x27BF, Hi: 0x27BF, Stride: 1}, + {Lo: 0x2934, Hi: 0x2935, Stride: 1}, + {Lo: 0x2B05, Hi: 0x2B07, Stride: 1}, + {Lo: 0x2B1B, Hi: 0x2B1C, Stride: 1}, + {Lo: 0x2B50, Hi: 0x2B50, Stride: 1}, + {Lo: 0x2B55, Hi: 0x2B55, Stride: 1}, + {Lo: 0x3030, Hi: 0x3030, Stride: 1}, + {Lo: 0x303D, Hi: 0x303D, Stride: 1}, + {Lo: 0x3297, Hi: 0x3297, Stride: 1}, + {Lo: 0x3299, Hi: 0x3299, Stride: 1}, + }, + R32: []unicode.Range32{ + {Lo: 0x1F004, Hi: 0x1F004, Stride: 1}, + {Lo: 0x1F0CF, Hi: 0x1F0CF, Stride: 1}, + {Lo: 0x1F170, Hi: 0x1F171, Stride: 1}, + {Lo: 0x1F17E, Hi: 0x1F17F, Stride: 1}, + {Lo: 0x1F18E, Hi: 0x1F18E, Stride: 1}, + {Lo: 0x1F191, Hi: 0x1F19A, Stride: 1}, + {Lo: 0x1F1E6, Hi: 0x1F1FF, Stride: 1}, + {Lo: 0x1F201, Hi: 0x1F202, Stride: 1}, + {Lo: 0x1F21A, Hi: 0x1F21A, Stride: 1}, + {Lo: 0x1F22F, Hi: 0x1F22F, Stride: 1}, + {Lo: 0x1F232, Hi: 0x1F23A, Stride: 1}, + {Lo: 0x1F250, Hi: 0x1F251, Stride: 1}, + {Lo: 0x1F300, Hi: 0x1F321, Stride: 1}, + {Lo: 0x1F324, Hi: 0x1F393, Stride: 1}, + {Lo: 0x1F396, Hi: 0x1F397, Stride: 1}, + {Lo: 0x1F399, Hi: 0x1F39B, Stride: 1}, + {Lo: 0x1F39E, Hi: 0x1F3F0, Stride: 1}, + {Lo: 0x1F3F3, Hi: 0x1F3F5, Stride: 1}, + {Lo: 0x1F3F7, Hi: 0x1F4FD, Stride: 1}, + {Lo: 0x1F4FF, Hi: 0x1F53D, Stride: 1}, + {Lo: 0x1F549, Hi: 0x1F54E, Stride: 1}, + {Lo: 0x1F550, Hi: 0x1F567, Stride: 1}, + {Lo: 0x1F56F, Hi: 0x1F570, Stride: 1}, + {Lo: 0x1F573, Hi: 0x1F57A, Stride: 1}, + {Lo: 0x1F587, Hi: 0x1F587, Stride: 1}, + {Lo: 0x1F58A, Hi: 0x1F58D, Stride: 1}, + {Lo: 0x1F590, Hi: 0x1F590, Stride: 1}, + {Lo: 0x1F595, Hi: 0x1F596, Stride: 1}, + {Lo: 0x1F5A4, Hi: 0x1F5A5, Stride: 1}, + {Lo: 0x1F5A8, Hi: 0x1F5A8, Stride: 1}, + {Lo: 0x1F5B1, Hi: 0x1F5B2, Stride: 1}, + {Lo: 0x1F5BC, Hi: 0x1F5BC, Stride: 1}, + {Lo: 0x1F5C2, Hi: 0x1F5C4, Stride: 1}, + {Lo: 0x1F5D1, Hi: 0x1F5D3, Stride: 1}, + {Lo: 0x1F5DC, Hi: 0x1F5DE, Stride: 1}, + {Lo: 0x1F5E1, Hi: 0x1F5E1, Stride: 1}, + {Lo: 0x1F5E3, Hi: 0x1F5E3, Stride: 1}, + {Lo: 0x1F5E8, Hi: 0x1F5E8, Stride: 1}, + {Lo: 0x1F5EF, Hi: 0x1F5EF, Stride: 1}, + {Lo: 0x1F5F3, Hi: 0x1F5F3, Stride: 1}, + {Lo: 0x1F5FA, Hi: 0x1F64F, Stride: 1}, + {Lo: 0x1F680, Hi: 0x1F6C5, Stride: 1}, + {Lo: 0x1F6CB, Hi: 0x1F6D2, Stride: 1}, + {Lo: 0x1F6D5, Hi: 0x1F6D8, Stride: 1}, + {Lo: 0x1F6DC, Hi: 0x1F6E5, Stride: 1}, + {Lo: 0x1F6E9, Hi: 0x1F6E9, Stride: 1}, + {Lo: 0x1F6EB, Hi: 0x1F6EC, Stride: 1}, + {Lo: 0x1F6F0, Hi: 0x1F6F0, Stride: 1}, + {Lo: 0x1F6F3, Hi: 0x1F6FC, Stride: 1}, + {Lo: 0x1F7E0, Hi: 0x1F7EB, Stride: 1}, + {Lo: 0x1F7F0, Hi: 0x1F7F0, Stride: 1}, + {Lo: 0x1F90C, Hi: 0x1F93A, Stride: 1}, + {Lo: 0x1F93C, Hi: 0x1F945, Stride: 1}, + {Lo: 0x1F947, Hi: 0x1F9FF, Stride: 1}, + {Lo: 0x1FA70, Hi: 0x1FA7C, Stride: 1}, + {Lo: 0x1FA80, Hi: 0x1FA8A, Stride: 1}, + {Lo: 0x1FA8E, Hi: 0x1FAC6, Stride: 1}, + {Lo: 0x1FAC8, Hi: 0x1FAC8, Stride: 1}, + {Lo: 0x1FACD, Hi: 0x1FADC, Stride: 1}, + {Lo: 0x1FADF, Hi: 0x1FAEA, Stride: 1}, + {Lo: 0x1FAEF, Hi: 0x1FAF8, Stride: 1}, + }, +} + +var unicodeAliasEmoji_Component = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0x23, Hi: 0x23, Stride: 1}, + {Lo: 0x2A, Hi: 0x2A, Stride: 1}, + {Lo: 0x30, Hi: 0x39, Stride: 1}, + {Lo: 0x200D, Hi: 0x200D, Stride: 1}, + {Lo: 0x20E3, Hi: 0x20E3, Stride: 1}, + {Lo: 0xFE0F, Hi: 0xFE0F, Stride: 1}, + }, + R32: []unicode.Range32{ + {Lo: 0x1F1E6, Hi: 0x1F1FF, Stride: 1}, + {Lo: 0x1F3FB, Hi: 0x1F3FF, Stride: 1}, + {Lo: 0x1F9B0, Hi: 0x1F9B3, Stride: 1}, + {Lo: 0xE0020, Hi: 0xE007F, Stride: 1}, + }, +} + +var unicodeAliasEmoji_Modifier = &unicode.RangeTable{ + R32: []unicode.Range32{ + {Lo: 0x1F3FB, Hi: 0x1F3FF, Stride: 1}, + }, +} + +var unicodeAliasEmoji_Modifier_Base = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0x261D, Hi: 0x261D, Stride: 1}, + {Lo: 0x26F9, Hi: 0x26F9, Stride: 1}, + {Lo: 0x270A, Hi: 0x270D, Stride: 1}, + }, + R32: []unicode.Range32{ + {Lo: 0x1F385, Hi: 0x1F385, Stride: 1}, + {Lo: 0x1F3C2, Hi: 0x1F3C4, Stride: 1}, + {Lo: 0x1F3C7, Hi: 0x1F3C7, Stride: 1}, + {Lo: 0x1F3CA, Hi: 0x1F3CC, Stride: 1}, + {Lo: 0x1F442, Hi: 0x1F443, Stride: 1}, + {Lo: 0x1F446, Hi: 0x1F450, Stride: 1}, + {Lo: 0x1F466, Hi: 0x1F478, Stride: 1}, + {Lo: 0x1F47C, Hi: 0x1F47C, Stride: 1}, + {Lo: 0x1F481, Hi: 0x1F483, Stride: 1}, + {Lo: 0x1F485, Hi: 0x1F487, Stride: 1}, + {Lo: 0x1F48F, Hi: 0x1F48F, Stride: 1}, + {Lo: 0x1F491, Hi: 0x1F491, Stride: 1}, + {Lo: 0x1F4AA, Hi: 0x1F4AA, Stride: 1}, + {Lo: 0x1F574, Hi: 0x1F575, Stride: 1}, + {Lo: 0x1F57A, Hi: 0x1F57A, Stride: 1}, + {Lo: 0x1F590, Hi: 0x1F590, Stride: 1}, + {Lo: 0x1F595, Hi: 0x1F596, Stride: 1}, + {Lo: 0x1F645, Hi: 0x1F647, Stride: 1}, + {Lo: 0x1F64B, Hi: 0x1F64F, Stride: 1}, + {Lo: 0x1F6A3, Hi: 0x1F6A3, Stride: 1}, + {Lo: 0x1F6B4, Hi: 0x1F6B6, Stride: 1}, + {Lo: 0x1F6C0, Hi: 0x1F6C0, Stride: 1}, + {Lo: 0x1F6CC, Hi: 0x1F6CC, Stride: 1}, + {Lo: 0x1F90C, Hi: 0x1F90C, Stride: 1}, + {Lo: 0x1F90F, Hi: 0x1F90F, Stride: 1}, + {Lo: 0x1F918, Hi: 0x1F91F, Stride: 1}, + {Lo: 0x1F926, Hi: 0x1F926, Stride: 1}, + {Lo: 0x1F930, Hi: 0x1F939, Stride: 1}, + {Lo: 0x1F93C, Hi: 0x1F93E, Stride: 1}, + {Lo: 0x1F977, Hi: 0x1F977, Stride: 1}, + {Lo: 0x1F9B5, Hi: 0x1F9B6, Stride: 1}, + {Lo: 0x1F9B8, Hi: 0x1F9B9, Stride: 1}, + {Lo: 0x1F9BB, Hi: 0x1F9BB, Stride: 1}, + {Lo: 0x1F9CD, Hi: 0x1F9CF, Stride: 1}, + {Lo: 0x1F9D1, Hi: 0x1F9DD, Stride: 1}, + {Lo: 0x1FAC3, Hi: 0x1FAC5, Stride: 1}, + {Lo: 0x1FAF0, Hi: 0x1FAF8, Stride: 1}, + }, +} + +var unicodeAliasEmoji_Presentation = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0x231A, Hi: 0x231B, Stride: 1}, + {Lo: 0x23E9, Hi: 0x23EC, Stride: 1}, + {Lo: 0x23F0, Hi: 0x23F0, Stride: 1}, + {Lo: 0x23F3, Hi: 0x23F3, Stride: 1}, + {Lo: 0x25FD, Hi: 0x25FE, Stride: 1}, + {Lo: 0x2614, Hi: 0x2615, Stride: 1}, + {Lo: 0x2648, Hi: 0x2653, Stride: 1}, + {Lo: 0x267F, Hi: 0x267F, Stride: 1}, + {Lo: 0x2693, Hi: 0x2693, Stride: 1}, + {Lo: 0x26A1, Hi: 0x26A1, Stride: 1}, + {Lo: 0x26AA, Hi: 0x26AB, Stride: 1}, + {Lo: 0x26BD, Hi: 0x26BE, Stride: 1}, + {Lo: 0x26C4, Hi: 0x26C5, Stride: 1}, + {Lo: 0x26CE, Hi: 0x26CE, Stride: 1}, + {Lo: 0x26D4, Hi: 0x26D4, Stride: 1}, + {Lo: 0x26EA, Hi: 0x26EA, Stride: 1}, + {Lo: 0x26F2, Hi: 0x26F3, Stride: 1}, + {Lo: 0x26F5, Hi: 0x26F5, Stride: 1}, + {Lo: 0x26FA, Hi: 0x26FA, Stride: 1}, + {Lo: 0x26FD, Hi: 0x26FD, Stride: 1}, + {Lo: 0x2705, Hi: 0x2705, Stride: 1}, + {Lo: 0x270A, Hi: 0x270B, Stride: 1}, + {Lo: 0x2728, Hi: 0x2728, Stride: 1}, + {Lo: 0x274C, Hi: 0x274C, Stride: 1}, + {Lo: 0x274E, Hi: 0x274E, Stride: 1}, + {Lo: 0x2753, Hi: 0x2755, Stride: 1}, + {Lo: 0x2757, Hi: 0x2757, Stride: 1}, + {Lo: 0x2795, Hi: 0x2797, Stride: 1}, + {Lo: 0x27B0, Hi: 0x27B0, Stride: 1}, + {Lo: 0x27BF, Hi: 0x27BF, Stride: 1}, + {Lo: 0x2B1B, Hi: 0x2B1C, Stride: 1}, + {Lo: 0x2B50, Hi: 0x2B50, Stride: 1}, + {Lo: 0x2B55, Hi: 0x2B55, Stride: 1}, + }, + R32: []unicode.Range32{ + {Lo: 0x1F004, Hi: 0x1F004, Stride: 1}, + {Lo: 0x1F0CF, Hi: 0x1F0CF, Stride: 1}, + {Lo: 0x1F18E, Hi: 0x1F18E, Stride: 1}, + {Lo: 0x1F191, Hi: 0x1F19A, Stride: 1}, + {Lo: 0x1F1E6, Hi: 0x1F1FF, Stride: 1}, + {Lo: 0x1F201, Hi: 0x1F201, Stride: 1}, + {Lo: 0x1F21A, Hi: 0x1F21A, Stride: 1}, + {Lo: 0x1F22F, Hi: 0x1F22F, Stride: 1}, + {Lo: 0x1F232, Hi: 0x1F236, Stride: 1}, + {Lo: 0x1F238, Hi: 0x1F23A, Stride: 1}, + {Lo: 0x1F250, Hi: 0x1F251, Stride: 1}, + {Lo: 0x1F300, Hi: 0x1F320, Stride: 1}, + {Lo: 0x1F32D, Hi: 0x1F335, Stride: 1}, + {Lo: 0x1F337, Hi: 0x1F37C, Stride: 1}, + {Lo: 0x1F37E, Hi: 0x1F393, Stride: 1}, + {Lo: 0x1F3A0, Hi: 0x1F3CA, Stride: 1}, + {Lo: 0x1F3CF, Hi: 0x1F3D3, Stride: 1}, + {Lo: 0x1F3E0, Hi: 0x1F3F0, Stride: 1}, + {Lo: 0x1F3F4, Hi: 0x1F3F4, Stride: 1}, + {Lo: 0x1F3F8, Hi: 0x1F43E, Stride: 1}, + {Lo: 0x1F440, Hi: 0x1F440, Stride: 1}, + {Lo: 0x1F442, Hi: 0x1F4FC, Stride: 1}, + {Lo: 0x1F4FF, Hi: 0x1F53D, Stride: 1}, + {Lo: 0x1F54B, Hi: 0x1F54E, Stride: 1}, + {Lo: 0x1F550, Hi: 0x1F567, Stride: 1}, + {Lo: 0x1F57A, Hi: 0x1F57A, Stride: 1}, + {Lo: 0x1F595, Hi: 0x1F596, Stride: 1}, + {Lo: 0x1F5A4, Hi: 0x1F5A4, Stride: 1}, + {Lo: 0x1F5FB, Hi: 0x1F64F, Stride: 1}, + {Lo: 0x1F680, Hi: 0x1F6C5, Stride: 1}, + {Lo: 0x1F6CC, Hi: 0x1F6CC, Stride: 1}, + {Lo: 0x1F6D0, Hi: 0x1F6D2, Stride: 1}, + {Lo: 0x1F6D5, Hi: 0x1F6D8, Stride: 1}, + {Lo: 0x1F6DC, Hi: 0x1F6DF, Stride: 1}, + {Lo: 0x1F6EB, Hi: 0x1F6EC, Stride: 1}, + {Lo: 0x1F6F4, Hi: 0x1F6FC, Stride: 1}, + {Lo: 0x1F7E0, Hi: 0x1F7EB, Stride: 1}, + {Lo: 0x1F7F0, Hi: 0x1F7F0, Stride: 1}, + {Lo: 0x1F90C, Hi: 0x1F93A, Stride: 1}, + {Lo: 0x1F93C, Hi: 0x1F945, Stride: 1}, + {Lo: 0x1F947, Hi: 0x1F9FF, Stride: 1}, + {Lo: 0x1FA70, Hi: 0x1FA7C, Stride: 1}, + {Lo: 0x1FA80, Hi: 0x1FA8A, Stride: 1}, + {Lo: 0x1FA8E, Hi: 0x1FAC6, Stride: 1}, + {Lo: 0x1FAC8, Hi: 0x1FAC8, Stride: 1}, + {Lo: 0x1FACD, Hi: 0x1FADC, Stride: 1}, + {Lo: 0x1FADF, Hi: 0x1FAEA, Stride: 1}, + {Lo: 0x1FAEF, Hi: 0x1FAF8, Stride: 1}, + }, +} + +var unicodeAliasExtended_Pictographic = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0xA9, Hi: 0xA9, Stride: 1}, + {Lo: 0xAE, Hi: 0xAE, Stride: 1}, + {Lo: 0x203C, Hi: 0x203C, Stride: 1}, + {Lo: 0x2049, Hi: 0x2049, Stride: 1}, + {Lo: 0x2122, Hi: 0x2122, Stride: 1}, + {Lo: 0x2139, Hi: 0x2139, Stride: 1}, + {Lo: 0x2194, Hi: 0x2199, Stride: 1}, + {Lo: 0x21A9, Hi: 0x21AA, Stride: 1}, + {Lo: 0x231A, Hi: 0x231B, Stride: 1}, + {Lo: 0x2328, Hi: 0x2328, Stride: 1}, + {Lo: 0x23CF, Hi: 0x23CF, Stride: 1}, + {Lo: 0x23E9, Hi: 0x23F3, Stride: 1}, + {Lo: 0x23F8, Hi: 0x23FA, Stride: 1}, + {Lo: 0x24C2, Hi: 0x24C2, Stride: 1}, + {Lo: 0x25AA, Hi: 0x25AB, Stride: 1}, + {Lo: 0x25B6, Hi: 0x25B6, Stride: 1}, + {Lo: 0x25C0, Hi: 0x25C0, Stride: 1}, + {Lo: 0x25FB, Hi: 0x25FE, Stride: 1}, + {Lo: 0x2600, Hi: 0x2604, Stride: 1}, + {Lo: 0x260E, Hi: 0x260E, Stride: 1}, + {Lo: 0x2611, Hi: 0x2611, Stride: 1}, + {Lo: 0x2614, Hi: 0x2615, Stride: 1}, + {Lo: 0x2618, Hi: 0x2618, Stride: 1}, + {Lo: 0x261D, Hi: 0x261D, Stride: 1}, + {Lo: 0x2620, Hi: 0x2620, Stride: 1}, + {Lo: 0x2622, Hi: 0x2623, Stride: 1}, + {Lo: 0x2626, Hi: 0x2626, Stride: 1}, + {Lo: 0x262A, Hi: 0x262A, Stride: 1}, + {Lo: 0x262E, Hi: 0x262F, Stride: 1}, + {Lo: 0x2638, Hi: 0x263A, Stride: 1}, + {Lo: 0x2640, Hi: 0x2640, Stride: 1}, + {Lo: 0x2642, Hi: 0x2642, Stride: 1}, + {Lo: 0x2648, Hi: 0x2653, Stride: 1}, + {Lo: 0x265F, Hi: 0x2660, Stride: 1}, + {Lo: 0x2663, Hi: 0x2663, Stride: 1}, + {Lo: 0x2665, Hi: 0x2666, Stride: 1}, + {Lo: 0x2668, Hi: 0x2668, Stride: 1}, + {Lo: 0x267B, Hi: 0x267B, Stride: 1}, + {Lo: 0x267E, Hi: 0x267F, Stride: 1}, + {Lo: 0x2692, Hi: 0x2697, Stride: 1}, + {Lo: 0x2699, Hi: 0x2699, Stride: 1}, + {Lo: 0x269B, Hi: 0x269C, Stride: 1}, + {Lo: 0x26A0, Hi: 0x26A1, Stride: 1}, + {Lo: 0x26A7, Hi: 0x26A7, Stride: 1}, + {Lo: 0x26AA, Hi: 0x26AB, Stride: 1}, + {Lo: 0x26B0, Hi: 0x26B1, Stride: 1}, + {Lo: 0x26BD, Hi: 0x26BE, Stride: 1}, + {Lo: 0x26C4, Hi: 0x26C5, Stride: 1}, + {Lo: 0x26C8, Hi: 0x26C8, Stride: 1}, + {Lo: 0x26CE, Hi: 0x26CF, Stride: 1}, + {Lo: 0x26D1, Hi: 0x26D1, Stride: 1}, + {Lo: 0x26D3, Hi: 0x26D4, Stride: 1}, + {Lo: 0x26E9, Hi: 0x26EA, Stride: 1}, + {Lo: 0x26F0, Hi: 0x26F5, Stride: 1}, + {Lo: 0x26F7, Hi: 0x26FA, Stride: 1}, + {Lo: 0x26FD, Hi: 0x26FD, Stride: 1}, + {Lo: 0x2702, Hi: 0x2702, Stride: 1}, + {Lo: 0x2705, Hi: 0x2705, Stride: 1}, + {Lo: 0x2708, Hi: 0x270D, Stride: 1}, + {Lo: 0x270F, Hi: 0x270F, Stride: 1}, + {Lo: 0x2712, Hi: 0x2712, Stride: 1}, + {Lo: 0x2714, Hi: 0x2714, Stride: 1}, + {Lo: 0x2716, Hi: 0x2716, Stride: 1}, + {Lo: 0x271D, Hi: 0x271D, Stride: 1}, + {Lo: 0x2721, Hi: 0x2721, Stride: 1}, + {Lo: 0x2728, Hi: 0x2728, Stride: 1}, + {Lo: 0x2733, Hi: 0x2734, Stride: 1}, + {Lo: 0x2744, Hi: 0x2744, Stride: 1}, + {Lo: 0x2747, Hi: 0x2747, Stride: 1}, + {Lo: 0x274C, Hi: 0x274C, Stride: 1}, + {Lo: 0x274E, Hi: 0x274E, Stride: 1}, + {Lo: 0x2753, Hi: 0x2755, Stride: 1}, + {Lo: 0x2757, Hi: 0x2757, Stride: 1}, + {Lo: 0x2763, Hi: 0x2764, Stride: 1}, + {Lo: 0x2795, Hi: 0x2797, Stride: 1}, + {Lo: 0x27A1, Hi: 0x27A1, Stride: 1}, + {Lo: 0x27B0, Hi: 0x27B0, Stride: 1}, + {Lo: 0x27BF, Hi: 0x27BF, Stride: 1}, + {Lo: 0x2934, Hi: 0x2935, Stride: 1}, + {Lo: 0x2B05, Hi: 0x2B07, Stride: 1}, + {Lo: 0x2B1B, Hi: 0x2B1C, Stride: 1}, + {Lo: 0x2B50, Hi: 0x2B50, Stride: 1}, + {Lo: 0x2B55, Hi: 0x2B55, Stride: 1}, + {Lo: 0x3030, Hi: 0x3030, Stride: 1}, + {Lo: 0x303D, Hi: 0x303D, Stride: 1}, + {Lo: 0x3297, Hi: 0x3297, Stride: 1}, + {Lo: 0x3299, Hi: 0x3299, Stride: 1}, + }, + R32: []unicode.Range32{ + {Lo: 0x1F004, Hi: 0x1F004, Stride: 1}, + {Lo: 0x1F02C, Hi: 0x1F02F, Stride: 1}, + {Lo: 0x1F094, Hi: 0x1F09F, Stride: 1}, + {Lo: 0x1F0AF, Hi: 0x1F0B0, Stride: 1}, + {Lo: 0x1F0C0, Hi: 0x1F0C0, Stride: 1}, + {Lo: 0x1F0CF, Hi: 0x1F0D0, Stride: 1}, + {Lo: 0x1F0F6, Hi: 0x1F0FF, Stride: 1}, + {Lo: 0x1F170, Hi: 0x1F171, Stride: 1}, + {Lo: 0x1F17E, Hi: 0x1F17F, Stride: 1}, + {Lo: 0x1F18E, Hi: 0x1F18E, Stride: 1}, + {Lo: 0x1F191, Hi: 0x1F19A, Stride: 1}, + {Lo: 0x1F1AE, Hi: 0x1F1E5, Stride: 1}, + {Lo: 0x1F201, Hi: 0x1F20F, Stride: 1}, + {Lo: 0x1F21A, Hi: 0x1F21A, Stride: 1}, + {Lo: 0x1F22F, Hi: 0x1F22F, Stride: 1}, + {Lo: 0x1F232, Hi: 0x1F23A, Stride: 1}, + {Lo: 0x1F23C, Hi: 0x1F23F, Stride: 1}, + {Lo: 0x1F249, Hi: 0x1F25F, Stride: 1}, + {Lo: 0x1F266, Hi: 0x1F321, Stride: 1}, + {Lo: 0x1F324, Hi: 0x1F393, Stride: 1}, + {Lo: 0x1F396, Hi: 0x1F397, Stride: 1}, + {Lo: 0x1F399, Hi: 0x1F39B, Stride: 1}, + {Lo: 0x1F39E, Hi: 0x1F3F0, Stride: 1}, + {Lo: 0x1F3F3, Hi: 0x1F3F5, Stride: 1}, + {Lo: 0x1F3F7, Hi: 0x1F3FA, Stride: 1}, + {Lo: 0x1F400, Hi: 0x1F4FD, Stride: 1}, + {Lo: 0x1F4FF, Hi: 0x1F53D, Stride: 1}, + {Lo: 0x1F549, Hi: 0x1F54E, Stride: 1}, + {Lo: 0x1F550, Hi: 0x1F567, Stride: 1}, + {Lo: 0x1F56F, Hi: 0x1F570, Stride: 1}, + {Lo: 0x1F573, Hi: 0x1F57A, Stride: 1}, + {Lo: 0x1F587, Hi: 0x1F587, Stride: 1}, + {Lo: 0x1F58A, Hi: 0x1F58D, Stride: 1}, + {Lo: 0x1F590, Hi: 0x1F590, Stride: 1}, + {Lo: 0x1F595, Hi: 0x1F596, Stride: 1}, + {Lo: 0x1F5A4, Hi: 0x1F5A5, Stride: 1}, + {Lo: 0x1F5A8, Hi: 0x1F5A8, Stride: 1}, + {Lo: 0x1F5B1, Hi: 0x1F5B2, Stride: 1}, + {Lo: 0x1F5BC, Hi: 0x1F5BC, Stride: 1}, + {Lo: 0x1F5C2, Hi: 0x1F5C4, Stride: 1}, + {Lo: 0x1F5D1, Hi: 0x1F5D3, Stride: 1}, + {Lo: 0x1F5DC, Hi: 0x1F5DE, Stride: 1}, + {Lo: 0x1F5E1, Hi: 0x1F5E1, Stride: 1}, + {Lo: 0x1F5E3, Hi: 0x1F5E3, Stride: 1}, + {Lo: 0x1F5E8, Hi: 0x1F5E8, Stride: 1}, + {Lo: 0x1F5EF, Hi: 0x1F5EF, Stride: 1}, + {Lo: 0x1F5F3, Hi: 0x1F5F3, Stride: 1}, + {Lo: 0x1F5FA, Hi: 0x1F64F, Stride: 1}, + {Lo: 0x1F680, Hi: 0x1F6C5, Stride: 1}, + {Lo: 0x1F6CB, Hi: 0x1F6D2, Stride: 1}, + {Lo: 0x1F6D5, Hi: 0x1F6E5, Stride: 1}, + {Lo: 0x1F6E9, Hi: 0x1F6E9, Stride: 1}, + {Lo: 0x1F6EB, Hi: 0x1F6F0, Stride: 1}, + {Lo: 0x1F6F3, Hi: 0x1F6FF, Stride: 1}, + {Lo: 0x1F7DA, Hi: 0x1F7FF, Stride: 1}, + {Lo: 0x1F80C, Hi: 0x1F80F, Stride: 1}, + {Lo: 0x1F848, Hi: 0x1F84F, Stride: 1}, + {Lo: 0x1F85A, Hi: 0x1F85F, Stride: 1}, + {Lo: 0x1F888, Hi: 0x1F88F, Stride: 1}, + {Lo: 0x1F8AE, Hi: 0x1F8AF, Stride: 1}, + {Lo: 0x1F8BC, Hi: 0x1F8BF, Stride: 1}, + {Lo: 0x1F8C2, Hi: 0x1F8CF, Stride: 1}, + {Lo: 0x1F8D9, Hi: 0x1F8FF, Stride: 1}, + {Lo: 0x1F90C, Hi: 0x1F93A, Stride: 1}, + {Lo: 0x1F93C, Hi: 0x1F945, Stride: 1}, + {Lo: 0x1F947, Hi: 0x1F9FF, Stride: 1}, + {Lo: 0x1FA58, Hi: 0x1FA5F, Stride: 1}, + {Lo: 0x1FA6E, Hi: 0x1FAFF, Stride: 1}, + {Lo: 0x1FC00, Hi: 0x1FFFD, Stride: 1}, + }, +} + +var unicodeAliasGrapheme_Cluster_Break_CR = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0xD, Hi: 0xD, Stride: 1}, + }, +} + +var unicodeAliasGrapheme_Cluster_Break_Control = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0x0, Hi: 0x9, Stride: 1}, + {Lo: 0xB, Hi: 0xC, Stride: 1}, + {Lo: 0xE, Hi: 0x1F, Stride: 1}, + {Lo: 0x7F, Hi: 0x9F, Stride: 1}, + {Lo: 0xAD, Hi: 0xAD, Stride: 1}, + {Lo: 0x61C, Hi: 0x61C, Stride: 1}, + {Lo: 0x180E, Hi: 0x180E, Stride: 1}, + {Lo: 0x200B, Hi: 0x200B, Stride: 1}, + {Lo: 0x200E, Hi: 0x200F, Stride: 1}, + {Lo: 0x2028, Hi: 0x202E, Stride: 1}, + {Lo: 0x2060, Hi: 0x206F, Stride: 1}, + {Lo: 0xFEFF, Hi: 0xFEFF, Stride: 1}, + {Lo: 0xFFF0, Hi: 0xFFFB, Stride: 1}, + }, + R32: []unicode.Range32{ + {Lo: 0x13430, Hi: 0x1343F, Stride: 1}, + {Lo: 0x1BCA0, Hi: 0x1BCA3, Stride: 1}, + {Lo: 0x1D173, Hi: 0x1D17A, Stride: 1}, + {Lo: 0xE0000, Hi: 0xE001F, Stride: 1}, + {Lo: 0xE0080, Hi: 0xE00FF, Stride: 1}, + {Lo: 0xE01F0, Hi: 0xE0FFF, Stride: 1}, + }, +} + +var unicodeAliasGrapheme_Cluster_Break_Extend = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0x300, Hi: 0x36F, Stride: 1}, + {Lo: 0x483, Hi: 0x489, Stride: 1}, + {Lo: 0x591, Hi: 0x5BD, Stride: 1}, + {Lo: 0x5BF, Hi: 0x5BF, Stride: 1}, + {Lo: 0x5C1, Hi: 0x5C2, Stride: 1}, + {Lo: 0x5C4, Hi: 0x5C5, Stride: 1}, + {Lo: 0x5C7, Hi: 0x5C7, Stride: 1}, + {Lo: 0x610, Hi: 0x61A, Stride: 1}, + {Lo: 0x64B, Hi: 0x65F, Stride: 1}, + {Lo: 0x670, Hi: 0x670, Stride: 1}, + {Lo: 0x6D6, Hi: 0x6DC, Stride: 1}, + {Lo: 0x6DF, Hi: 0x6E4, Stride: 1}, + {Lo: 0x6E7, Hi: 0x6E8, Stride: 1}, + {Lo: 0x6EA, Hi: 0x6ED, Stride: 1}, + {Lo: 0x711, Hi: 0x711, Stride: 1}, + {Lo: 0x730, Hi: 0x74A, Stride: 1}, + {Lo: 0x7A6, Hi: 0x7B0, Stride: 1}, + {Lo: 0x7EB, Hi: 0x7F3, Stride: 1}, + {Lo: 0x7FD, Hi: 0x7FD, Stride: 1}, + {Lo: 0x816, Hi: 0x819, Stride: 1}, + {Lo: 0x81B, Hi: 0x823, Stride: 1}, + {Lo: 0x825, Hi: 0x827, Stride: 1}, + {Lo: 0x829, Hi: 0x82D, Stride: 1}, + {Lo: 0x859, Hi: 0x85B, Stride: 1}, + {Lo: 0x897, Hi: 0x89F, Stride: 1}, + {Lo: 0x8CA, Hi: 0x8E1, Stride: 1}, + {Lo: 0x8E3, Hi: 0x902, Stride: 1}, + {Lo: 0x93A, Hi: 0x93A, Stride: 1}, + {Lo: 0x93C, Hi: 0x93C, Stride: 1}, + {Lo: 0x941, Hi: 0x948, Stride: 1}, + {Lo: 0x94D, Hi: 0x94D, Stride: 1}, + {Lo: 0x951, Hi: 0x957, Stride: 1}, + {Lo: 0x962, Hi: 0x963, Stride: 1}, + {Lo: 0x981, Hi: 0x981, Stride: 1}, + {Lo: 0x9BC, Hi: 0x9BC, Stride: 1}, + {Lo: 0x9BE, Hi: 0x9BE, Stride: 1}, + {Lo: 0x9C1, Hi: 0x9C4, Stride: 1}, + {Lo: 0x9CD, Hi: 0x9CD, Stride: 1}, + {Lo: 0x9D7, Hi: 0x9D7, Stride: 1}, + {Lo: 0x9E2, Hi: 0x9E3, Stride: 1}, + {Lo: 0x9FE, Hi: 0x9FE, Stride: 1}, + {Lo: 0xA01, Hi: 0xA02, Stride: 1}, + {Lo: 0xA3C, Hi: 0xA3C, Stride: 1}, + {Lo: 0xA41, Hi: 0xA42, Stride: 1}, + {Lo: 0xA47, Hi: 0xA48, Stride: 1}, + {Lo: 0xA4B, Hi: 0xA4D, Stride: 1}, + {Lo: 0xA51, Hi: 0xA51, Stride: 1}, + {Lo: 0xA70, Hi: 0xA71, Stride: 1}, + {Lo: 0xA75, Hi: 0xA75, Stride: 1}, + {Lo: 0xA81, Hi: 0xA82, Stride: 1}, + {Lo: 0xABC, Hi: 0xABC, Stride: 1}, + {Lo: 0xAC1, Hi: 0xAC5, Stride: 1}, + {Lo: 0xAC7, Hi: 0xAC8, Stride: 1}, + {Lo: 0xACD, Hi: 0xACD, Stride: 1}, + {Lo: 0xAE2, Hi: 0xAE3, Stride: 1}, + {Lo: 0xAFA, Hi: 0xAFF, Stride: 1}, + {Lo: 0xB01, Hi: 0xB01, Stride: 1}, + {Lo: 0xB3C, Hi: 0xB3C, Stride: 1}, + {Lo: 0xB3E, Hi: 0xB3F, Stride: 1}, + {Lo: 0xB41, Hi: 0xB44, Stride: 1}, + {Lo: 0xB4D, Hi: 0xB4D, Stride: 1}, + {Lo: 0xB55, Hi: 0xB57, Stride: 1}, + {Lo: 0xB62, Hi: 0xB63, Stride: 1}, + {Lo: 0xB82, Hi: 0xB82, Stride: 1}, + {Lo: 0xBBE, Hi: 0xBBE, Stride: 1}, + {Lo: 0xBC0, Hi: 0xBC0, Stride: 1}, + {Lo: 0xBCD, Hi: 0xBCD, Stride: 1}, + {Lo: 0xBD7, Hi: 0xBD7, Stride: 1}, + {Lo: 0xC00, Hi: 0xC00, Stride: 1}, + {Lo: 0xC04, Hi: 0xC04, Stride: 1}, + {Lo: 0xC3C, Hi: 0xC3C, Stride: 1}, + {Lo: 0xC3E, Hi: 0xC40, Stride: 1}, + {Lo: 0xC46, Hi: 0xC48, Stride: 1}, + {Lo: 0xC4A, Hi: 0xC4D, Stride: 1}, + {Lo: 0xC55, Hi: 0xC56, Stride: 1}, + {Lo: 0xC62, Hi: 0xC63, Stride: 1}, + {Lo: 0xC81, Hi: 0xC81, Stride: 1}, + {Lo: 0xCBC, Hi: 0xCBC, Stride: 1}, + {Lo: 0xCBF, Hi: 0xCC0, Stride: 1}, + {Lo: 0xCC2, Hi: 0xCC2, Stride: 1}, + {Lo: 0xCC6, Hi: 0xCC8, Stride: 1}, + {Lo: 0xCCA, Hi: 0xCCD, Stride: 1}, + {Lo: 0xCD5, Hi: 0xCD6, Stride: 1}, + {Lo: 0xCE2, Hi: 0xCE3, Stride: 1}, + {Lo: 0xD00, Hi: 0xD01, Stride: 1}, + {Lo: 0xD3B, Hi: 0xD3C, Stride: 1}, + {Lo: 0xD3E, Hi: 0xD3E, Stride: 1}, + {Lo: 0xD41, Hi: 0xD44, Stride: 1}, + {Lo: 0xD4D, Hi: 0xD4D, Stride: 1}, + {Lo: 0xD57, Hi: 0xD57, Stride: 1}, + {Lo: 0xD62, Hi: 0xD63, Stride: 1}, + {Lo: 0xD81, Hi: 0xD81, Stride: 1}, + {Lo: 0xDCA, Hi: 0xDCA, Stride: 1}, + {Lo: 0xDCF, Hi: 0xDCF, Stride: 1}, + {Lo: 0xDD2, Hi: 0xDD4, Stride: 1}, + {Lo: 0xDD6, Hi: 0xDD6, Stride: 1}, + {Lo: 0xDDF, Hi: 0xDDF, Stride: 1}, + {Lo: 0xE31, Hi: 0xE31, Stride: 1}, + {Lo: 0xE34, Hi: 0xE3A, Stride: 1}, + {Lo: 0xE47, Hi: 0xE4E, Stride: 1}, + {Lo: 0xEB1, Hi: 0xEB1, Stride: 1}, + {Lo: 0xEB4, Hi: 0xEBC, Stride: 1}, + {Lo: 0xEC8, Hi: 0xECE, Stride: 1}, + {Lo: 0xF18, Hi: 0xF19, Stride: 1}, + {Lo: 0xF35, Hi: 0xF35, Stride: 1}, + {Lo: 0xF37, Hi: 0xF37, Stride: 1}, + {Lo: 0xF39, Hi: 0xF39, Stride: 1}, + {Lo: 0xF71, Hi: 0xF7E, Stride: 1}, + {Lo: 0xF80, Hi: 0xF84, Stride: 1}, + {Lo: 0xF86, Hi: 0xF87, Stride: 1}, + {Lo: 0xF8D, Hi: 0xF97, Stride: 1}, + {Lo: 0xF99, Hi: 0xFBC, Stride: 1}, + {Lo: 0xFC6, Hi: 0xFC6, Stride: 1}, + {Lo: 0x102D, Hi: 0x1030, Stride: 1}, + {Lo: 0x1032, Hi: 0x1037, Stride: 1}, + {Lo: 0x1039, Hi: 0x103A, Stride: 1}, + {Lo: 0x103D, Hi: 0x103E, Stride: 1}, + {Lo: 0x1058, Hi: 0x1059, Stride: 1}, + {Lo: 0x105E, Hi: 0x1060, Stride: 1}, + {Lo: 0x1071, Hi: 0x1074, Stride: 1}, + {Lo: 0x1082, Hi: 0x1082, Stride: 1}, + {Lo: 0x1085, Hi: 0x1086, Stride: 1}, + {Lo: 0x108D, Hi: 0x108D, Stride: 1}, + {Lo: 0x109D, Hi: 0x109D, Stride: 1}, + {Lo: 0x135D, Hi: 0x135F, Stride: 1}, + {Lo: 0x1712, Hi: 0x1715, Stride: 1}, + {Lo: 0x1732, Hi: 0x1734, Stride: 1}, + {Lo: 0x1752, Hi: 0x1753, Stride: 1}, + {Lo: 0x1772, Hi: 0x1773, Stride: 1}, + {Lo: 0x17B4, Hi: 0x17B5, Stride: 1}, + {Lo: 0x17B7, Hi: 0x17BD, Stride: 1}, + {Lo: 0x17C6, Hi: 0x17C6, Stride: 1}, + {Lo: 0x17C9, Hi: 0x17D3, Stride: 1}, + {Lo: 0x17DD, Hi: 0x17DD, Stride: 1}, + {Lo: 0x180B, Hi: 0x180D, Stride: 1}, + {Lo: 0x180F, Hi: 0x180F, Stride: 1}, + {Lo: 0x1885, Hi: 0x1886, Stride: 1}, + {Lo: 0x18A9, Hi: 0x18A9, Stride: 1}, + {Lo: 0x1920, Hi: 0x1922, Stride: 1}, + {Lo: 0x1927, Hi: 0x1928, Stride: 1}, + {Lo: 0x1932, Hi: 0x1932, Stride: 1}, + {Lo: 0x1939, Hi: 0x193B, Stride: 1}, + {Lo: 0x1A17, Hi: 0x1A18, Stride: 1}, + {Lo: 0x1A1B, Hi: 0x1A1B, Stride: 1}, + {Lo: 0x1A56, Hi: 0x1A56, Stride: 1}, + {Lo: 0x1A58, Hi: 0x1A5E, Stride: 1}, + {Lo: 0x1A60, Hi: 0x1A60, Stride: 1}, + {Lo: 0x1A62, Hi: 0x1A62, Stride: 1}, + {Lo: 0x1A65, Hi: 0x1A6C, Stride: 1}, + {Lo: 0x1A73, Hi: 0x1A7C, Stride: 1}, + {Lo: 0x1A7F, Hi: 0x1A7F, Stride: 1}, + {Lo: 0x1AB0, Hi: 0x1ADD, Stride: 1}, + {Lo: 0x1AE0, Hi: 0x1AEB, Stride: 1}, + {Lo: 0x1B00, Hi: 0x1B03, Stride: 1}, + {Lo: 0x1B34, Hi: 0x1B3D, Stride: 1}, + {Lo: 0x1B42, Hi: 0x1B44, Stride: 1}, + {Lo: 0x1B6B, Hi: 0x1B73, Stride: 1}, + {Lo: 0x1B80, Hi: 0x1B81, Stride: 1}, + {Lo: 0x1BA2, Hi: 0x1BA5, Stride: 1}, + {Lo: 0x1BA8, Hi: 0x1BAD, Stride: 1}, + {Lo: 0x1BE6, Hi: 0x1BE6, Stride: 1}, + {Lo: 0x1BE8, Hi: 0x1BE9, Stride: 1}, + {Lo: 0x1BED, Hi: 0x1BED, Stride: 1}, + {Lo: 0x1BEF, Hi: 0x1BF3, Stride: 1}, + {Lo: 0x1C2C, Hi: 0x1C33, Stride: 1}, + {Lo: 0x1C36, Hi: 0x1C37, Stride: 1}, + {Lo: 0x1CD0, Hi: 0x1CD2, Stride: 1}, + {Lo: 0x1CD4, Hi: 0x1CE0, Stride: 1}, + {Lo: 0x1CE2, Hi: 0x1CE8, Stride: 1}, + {Lo: 0x1CED, Hi: 0x1CED, Stride: 1}, + {Lo: 0x1CF4, Hi: 0x1CF4, Stride: 1}, + {Lo: 0x1CF8, Hi: 0x1CF9, Stride: 1}, + {Lo: 0x1DC0, Hi: 0x1DFF, Stride: 1}, + {Lo: 0x200C, Hi: 0x200C, Stride: 1}, + {Lo: 0x20D0, Hi: 0x20F0, Stride: 1}, + {Lo: 0x2CEF, Hi: 0x2CF1, Stride: 1}, + {Lo: 0x2D7F, Hi: 0x2D7F, Stride: 1}, + {Lo: 0x2DE0, Hi: 0x2DFF, Stride: 1}, + {Lo: 0x302A, Hi: 0x302F, Stride: 1}, + {Lo: 0x3099, Hi: 0x309A, Stride: 1}, + {Lo: 0xA66F, Hi: 0xA672, Stride: 1}, + {Lo: 0xA674, Hi: 0xA67D, Stride: 1}, + {Lo: 0xA69E, Hi: 0xA69F, Stride: 1}, + {Lo: 0xA6F0, Hi: 0xA6F1, Stride: 1}, + {Lo: 0xA802, Hi: 0xA802, Stride: 1}, + {Lo: 0xA806, Hi: 0xA806, Stride: 1}, + {Lo: 0xA80B, Hi: 0xA80B, Stride: 1}, + {Lo: 0xA825, Hi: 0xA826, Stride: 1}, + {Lo: 0xA82C, Hi: 0xA82C, Stride: 1}, + {Lo: 0xA8C4, Hi: 0xA8C5, Stride: 1}, + {Lo: 0xA8E0, Hi: 0xA8F1, Stride: 1}, + {Lo: 0xA8FF, Hi: 0xA8FF, Stride: 1}, + {Lo: 0xA926, Hi: 0xA92D, Stride: 1}, + {Lo: 0xA947, Hi: 0xA951, Stride: 1}, + {Lo: 0xA953, Hi: 0xA953, Stride: 1}, + {Lo: 0xA980, Hi: 0xA982, Stride: 1}, + {Lo: 0xA9B3, Hi: 0xA9B3, Stride: 1}, + {Lo: 0xA9B6, Hi: 0xA9B9, Stride: 1}, + {Lo: 0xA9BC, Hi: 0xA9BD, Stride: 1}, + {Lo: 0xA9C0, Hi: 0xA9C0, Stride: 1}, + {Lo: 0xA9E5, Hi: 0xA9E5, Stride: 1}, + {Lo: 0xAA29, Hi: 0xAA2E, Stride: 1}, + {Lo: 0xAA31, Hi: 0xAA32, Stride: 1}, + {Lo: 0xAA35, Hi: 0xAA36, Stride: 1}, + {Lo: 0xAA43, Hi: 0xAA43, Stride: 1}, + {Lo: 0xAA4C, Hi: 0xAA4C, Stride: 1}, + {Lo: 0xAA7C, Hi: 0xAA7C, Stride: 1}, + {Lo: 0xAAB0, Hi: 0xAAB0, Stride: 1}, + {Lo: 0xAAB2, Hi: 0xAAB4, Stride: 1}, + {Lo: 0xAAB7, Hi: 0xAAB8, Stride: 1}, + {Lo: 0xAABE, Hi: 0xAABF, Stride: 1}, + {Lo: 0xAAC1, Hi: 0xAAC1, Stride: 1}, + {Lo: 0xAAEC, Hi: 0xAAED, Stride: 1}, + {Lo: 0xAAF6, Hi: 0xAAF6, Stride: 1}, + {Lo: 0xABE5, Hi: 0xABE5, Stride: 1}, + {Lo: 0xABE8, Hi: 0xABE8, Stride: 1}, + {Lo: 0xABED, Hi: 0xABED, Stride: 1}, + {Lo: 0xFB1E, Hi: 0xFB1E, Stride: 1}, + {Lo: 0xFE00, Hi: 0xFE0F, Stride: 1}, + {Lo: 0xFE20, Hi: 0xFE2F, Stride: 1}, + {Lo: 0xFF9E, Hi: 0xFF9F, Stride: 1}, + }, + R32: []unicode.Range32{ + {Lo: 0x101FD, Hi: 0x101FD, Stride: 1}, + {Lo: 0x102E0, Hi: 0x102E0, Stride: 1}, + {Lo: 0x10376, Hi: 0x1037A, Stride: 1}, + {Lo: 0x10A01, Hi: 0x10A03, Stride: 1}, + {Lo: 0x10A05, Hi: 0x10A06, Stride: 1}, + {Lo: 0x10A0C, Hi: 0x10A0F, Stride: 1}, + {Lo: 0x10A38, Hi: 0x10A3A, Stride: 1}, + {Lo: 0x10A3F, Hi: 0x10A3F, Stride: 1}, + {Lo: 0x10AE5, Hi: 0x10AE6, Stride: 1}, + {Lo: 0x10D24, Hi: 0x10D27, Stride: 1}, + {Lo: 0x10D69, Hi: 0x10D6D, Stride: 1}, + {Lo: 0x10EAB, Hi: 0x10EAC, Stride: 1}, + {Lo: 0x10EFA, Hi: 0x10EFF, Stride: 1}, + {Lo: 0x10F46, Hi: 0x10F50, Stride: 1}, + {Lo: 0x10F82, Hi: 0x10F85, Stride: 1}, + {Lo: 0x11001, Hi: 0x11001, Stride: 1}, + {Lo: 0x11038, Hi: 0x11046, Stride: 1}, + {Lo: 0x11070, Hi: 0x11070, Stride: 1}, + {Lo: 0x11073, Hi: 0x11074, Stride: 1}, + {Lo: 0x1107F, Hi: 0x11081, Stride: 1}, + {Lo: 0x110B3, Hi: 0x110B6, Stride: 1}, + {Lo: 0x110B9, Hi: 0x110BA, Stride: 1}, + {Lo: 0x110C2, Hi: 0x110C2, Stride: 1}, + {Lo: 0x11100, Hi: 0x11102, Stride: 1}, + {Lo: 0x11127, Hi: 0x1112B, Stride: 1}, + {Lo: 0x1112D, Hi: 0x11134, Stride: 1}, + {Lo: 0x11173, Hi: 0x11173, Stride: 1}, + {Lo: 0x11180, Hi: 0x11181, Stride: 1}, + {Lo: 0x111B6, Hi: 0x111BE, Stride: 1}, + {Lo: 0x111C0, Hi: 0x111C0, Stride: 1}, + {Lo: 0x111C9, Hi: 0x111CC, Stride: 1}, + {Lo: 0x111CF, Hi: 0x111CF, Stride: 1}, + {Lo: 0x1122F, Hi: 0x11231, Stride: 1}, + {Lo: 0x11234, Hi: 0x11237, Stride: 1}, + {Lo: 0x1123E, Hi: 0x1123E, Stride: 1}, + {Lo: 0x11241, Hi: 0x11241, Stride: 1}, + {Lo: 0x112DF, Hi: 0x112DF, Stride: 1}, + {Lo: 0x112E3, Hi: 0x112EA, Stride: 1}, + {Lo: 0x11300, Hi: 0x11301, Stride: 1}, + {Lo: 0x1133B, Hi: 0x1133C, Stride: 1}, + {Lo: 0x1133E, Hi: 0x1133E, Stride: 1}, + {Lo: 0x11340, Hi: 0x11340, Stride: 1}, + {Lo: 0x1134D, Hi: 0x1134D, Stride: 1}, + {Lo: 0x11357, Hi: 0x11357, Stride: 1}, + {Lo: 0x11366, Hi: 0x1136C, Stride: 1}, + {Lo: 0x11370, Hi: 0x11374, Stride: 1}, + {Lo: 0x113B8, Hi: 0x113B8, Stride: 1}, + {Lo: 0x113BB, Hi: 0x113C0, Stride: 1}, + {Lo: 0x113C2, Hi: 0x113C2, Stride: 1}, + {Lo: 0x113C5, Hi: 0x113C5, Stride: 1}, + {Lo: 0x113C7, Hi: 0x113C9, Stride: 1}, + {Lo: 0x113CE, Hi: 0x113D0, Stride: 1}, + {Lo: 0x113D2, Hi: 0x113D2, Stride: 1}, + {Lo: 0x113E1, Hi: 0x113E2, Stride: 1}, + {Lo: 0x11438, Hi: 0x1143F, Stride: 1}, + {Lo: 0x11442, Hi: 0x11444, Stride: 1}, + {Lo: 0x11446, Hi: 0x11446, Stride: 1}, + {Lo: 0x1145E, Hi: 0x1145E, Stride: 1}, + {Lo: 0x114B0, Hi: 0x114B0, Stride: 1}, + {Lo: 0x114B3, Hi: 0x114B8, Stride: 1}, + {Lo: 0x114BA, Hi: 0x114BA, Stride: 1}, + {Lo: 0x114BD, Hi: 0x114BD, Stride: 1}, + {Lo: 0x114BF, Hi: 0x114C0, Stride: 1}, + {Lo: 0x114C2, Hi: 0x114C3, Stride: 1}, + {Lo: 0x115AF, Hi: 0x115AF, Stride: 1}, + {Lo: 0x115B2, Hi: 0x115B5, Stride: 1}, + {Lo: 0x115BC, Hi: 0x115BD, Stride: 1}, + {Lo: 0x115BF, Hi: 0x115C0, Stride: 1}, + {Lo: 0x115DC, Hi: 0x115DD, Stride: 1}, + {Lo: 0x11633, Hi: 0x1163A, Stride: 1}, + {Lo: 0x1163D, Hi: 0x1163D, Stride: 1}, + {Lo: 0x1163F, Hi: 0x11640, Stride: 1}, + {Lo: 0x116AB, Hi: 0x116AB, Stride: 1}, + {Lo: 0x116AD, Hi: 0x116AD, Stride: 1}, + {Lo: 0x116B0, Hi: 0x116B7, Stride: 1}, + {Lo: 0x1171D, Hi: 0x1171D, Stride: 1}, + {Lo: 0x1171F, Hi: 0x1171F, Stride: 1}, + {Lo: 0x11722, Hi: 0x11725, Stride: 1}, + {Lo: 0x11727, Hi: 0x1172B, Stride: 1}, + {Lo: 0x1182F, Hi: 0x11837, Stride: 1}, + {Lo: 0x11839, Hi: 0x1183A, Stride: 1}, + {Lo: 0x11930, Hi: 0x11930, Stride: 1}, + {Lo: 0x1193B, Hi: 0x1193E, Stride: 1}, + {Lo: 0x11943, Hi: 0x11943, Stride: 1}, + {Lo: 0x119D4, Hi: 0x119D7, Stride: 1}, + {Lo: 0x119DA, Hi: 0x119DB, Stride: 1}, + {Lo: 0x119E0, Hi: 0x119E0, Stride: 1}, + {Lo: 0x11A01, Hi: 0x11A0A, Stride: 1}, + {Lo: 0x11A33, Hi: 0x11A38, Stride: 1}, + {Lo: 0x11A3B, Hi: 0x11A3E, Stride: 1}, + {Lo: 0x11A47, Hi: 0x11A47, Stride: 1}, + {Lo: 0x11A51, Hi: 0x11A56, Stride: 1}, + {Lo: 0x11A59, Hi: 0x11A5B, Stride: 1}, + {Lo: 0x11A8A, Hi: 0x11A96, Stride: 1}, + {Lo: 0x11A98, Hi: 0x11A99, Stride: 1}, + {Lo: 0x11B60, Hi: 0x11B60, Stride: 1}, + {Lo: 0x11B62, Hi: 0x11B64, Stride: 1}, + {Lo: 0x11B66, Hi: 0x11B66, Stride: 1}, + {Lo: 0x11C30, Hi: 0x11C36, Stride: 1}, + {Lo: 0x11C38, Hi: 0x11C3D, Stride: 1}, + {Lo: 0x11C3F, Hi: 0x11C3F, Stride: 1}, + {Lo: 0x11C92, Hi: 0x11CA7, Stride: 1}, + {Lo: 0x11CAA, Hi: 0x11CB0, Stride: 1}, + {Lo: 0x11CB2, Hi: 0x11CB3, Stride: 1}, + {Lo: 0x11CB5, Hi: 0x11CB6, Stride: 1}, + {Lo: 0x11D31, Hi: 0x11D36, Stride: 1}, + {Lo: 0x11D3A, Hi: 0x11D3A, Stride: 1}, + {Lo: 0x11D3C, Hi: 0x11D3D, Stride: 1}, + {Lo: 0x11D3F, Hi: 0x11D45, Stride: 1}, + {Lo: 0x11D47, Hi: 0x11D47, Stride: 1}, + {Lo: 0x11D90, Hi: 0x11D91, Stride: 1}, + {Lo: 0x11D95, Hi: 0x11D95, Stride: 1}, + {Lo: 0x11D97, Hi: 0x11D97, Stride: 1}, + {Lo: 0x11EF3, Hi: 0x11EF4, Stride: 1}, + {Lo: 0x11F00, Hi: 0x11F01, Stride: 1}, + {Lo: 0x11F36, Hi: 0x11F3A, Stride: 1}, + {Lo: 0x11F40, Hi: 0x11F42, Stride: 1}, + {Lo: 0x11F5A, Hi: 0x11F5A, Stride: 1}, + {Lo: 0x13440, Hi: 0x13440, Stride: 1}, + {Lo: 0x13447, Hi: 0x13455, Stride: 1}, + {Lo: 0x1611E, Hi: 0x16129, Stride: 1}, + {Lo: 0x1612D, Hi: 0x1612F, Stride: 1}, + {Lo: 0x16AF0, Hi: 0x16AF4, Stride: 1}, + {Lo: 0x16B30, Hi: 0x16B36, Stride: 1}, + {Lo: 0x16F4F, Hi: 0x16F4F, Stride: 1}, + {Lo: 0x16F8F, Hi: 0x16F92, Stride: 1}, + {Lo: 0x16FE4, Hi: 0x16FE4, Stride: 1}, + {Lo: 0x16FF0, Hi: 0x16FF1, Stride: 1}, + {Lo: 0x1BC9D, Hi: 0x1BC9E, Stride: 1}, + {Lo: 0x1CF00, Hi: 0x1CF2D, Stride: 1}, + {Lo: 0x1CF30, Hi: 0x1CF46, Stride: 1}, + {Lo: 0x1D165, Hi: 0x1D169, Stride: 1}, + {Lo: 0x1D16D, Hi: 0x1D172, Stride: 1}, + {Lo: 0x1D17B, Hi: 0x1D182, Stride: 1}, + {Lo: 0x1D185, Hi: 0x1D18B, Stride: 1}, + {Lo: 0x1D1AA, Hi: 0x1D1AD, Stride: 1}, + {Lo: 0x1D242, Hi: 0x1D244, Stride: 1}, + {Lo: 0x1DA00, Hi: 0x1DA36, Stride: 1}, + {Lo: 0x1DA3B, Hi: 0x1DA6C, Stride: 1}, + {Lo: 0x1DA75, Hi: 0x1DA75, Stride: 1}, + {Lo: 0x1DA84, Hi: 0x1DA84, Stride: 1}, + {Lo: 0x1DA9B, Hi: 0x1DA9F, Stride: 1}, + {Lo: 0x1DAA1, Hi: 0x1DAAF, Stride: 1}, + {Lo: 0x1E000, Hi: 0x1E006, Stride: 1}, + {Lo: 0x1E008, Hi: 0x1E018, Stride: 1}, + {Lo: 0x1E01B, Hi: 0x1E021, Stride: 1}, + {Lo: 0x1E023, Hi: 0x1E024, Stride: 1}, + {Lo: 0x1E026, Hi: 0x1E02A, Stride: 1}, + {Lo: 0x1E08F, Hi: 0x1E08F, Stride: 1}, + {Lo: 0x1E130, Hi: 0x1E136, Stride: 1}, + {Lo: 0x1E2AE, Hi: 0x1E2AE, Stride: 1}, + {Lo: 0x1E2EC, Hi: 0x1E2EF, Stride: 1}, + {Lo: 0x1E4EC, Hi: 0x1E4EF, Stride: 1}, + {Lo: 0x1E5EE, Hi: 0x1E5EF, Stride: 1}, + {Lo: 0x1E6E3, Hi: 0x1E6E3, Stride: 1}, + {Lo: 0x1E6E6, Hi: 0x1E6E6, Stride: 1}, + {Lo: 0x1E6EE, Hi: 0x1E6EF, Stride: 1}, + {Lo: 0x1E6F5, Hi: 0x1E6F5, Stride: 1}, + {Lo: 0x1E8D0, Hi: 0x1E8D6, Stride: 1}, + {Lo: 0x1E944, Hi: 0x1E94A, Stride: 1}, + {Lo: 0x1F3FB, Hi: 0x1F3FF, Stride: 1}, + {Lo: 0xE0020, Hi: 0xE007F, Stride: 1}, + {Lo: 0xE0100, Hi: 0xE01EF, Stride: 1}, + }, +} + +var unicodeAliasGrapheme_Cluster_Break_L = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0x1100, Hi: 0x115F, Stride: 1}, + {Lo: 0xA960, Hi: 0xA97C, Stride: 1}, + }, +} + +var unicodeAliasGrapheme_Cluster_Break_LF = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0xA, Hi: 0xA, Stride: 1}, + }, +} + +var unicodeAliasGrapheme_Cluster_Break_LV = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0xAC00, Hi: 0xAC00, Stride: 1}, + {Lo: 0xAC1C, Hi: 0xAC1C, Stride: 1}, + {Lo: 0xAC38, Hi: 0xAC38, Stride: 1}, + {Lo: 0xAC54, Hi: 0xAC54, Stride: 1}, + {Lo: 0xAC70, Hi: 0xAC70, Stride: 1}, + {Lo: 0xAC8C, Hi: 0xAC8C, Stride: 1}, + {Lo: 0xACA8, Hi: 0xACA8, Stride: 1}, + {Lo: 0xACC4, Hi: 0xACC4, Stride: 1}, + {Lo: 0xACE0, Hi: 0xACE0, Stride: 1}, + {Lo: 0xACFC, Hi: 0xACFC, Stride: 1}, + {Lo: 0xAD18, Hi: 0xAD18, Stride: 1}, + {Lo: 0xAD34, Hi: 0xAD34, Stride: 1}, + {Lo: 0xAD50, Hi: 0xAD50, Stride: 1}, + {Lo: 0xAD6C, Hi: 0xAD6C, Stride: 1}, + {Lo: 0xAD88, Hi: 0xAD88, Stride: 1}, + {Lo: 0xADA4, Hi: 0xADA4, Stride: 1}, + {Lo: 0xADC0, Hi: 0xADC0, Stride: 1}, + {Lo: 0xADDC, Hi: 0xADDC, Stride: 1}, + {Lo: 0xADF8, Hi: 0xADF8, Stride: 1}, + {Lo: 0xAE14, Hi: 0xAE14, Stride: 1}, + {Lo: 0xAE30, Hi: 0xAE30, Stride: 1}, + {Lo: 0xAE4C, Hi: 0xAE4C, Stride: 1}, + {Lo: 0xAE68, Hi: 0xAE68, Stride: 1}, + {Lo: 0xAE84, Hi: 0xAE84, Stride: 1}, + {Lo: 0xAEA0, Hi: 0xAEA0, Stride: 1}, + {Lo: 0xAEBC, Hi: 0xAEBC, Stride: 1}, + {Lo: 0xAED8, Hi: 0xAED8, Stride: 1}, + {Lo: 0xAEF4, Hi: 0xAEF4, Stride: 1}, + {Lo: 0xAF10, Hi: 0xAF10, Stride: 1}, + {Lo: 0xAF2C, Hi: 0xAF2C, Stride: 1}, + {Lo: 0xAF48, Hi: 0xAF48, Stride: 1}, + {Lo: 0xAF64, Hi: 0xAF64, Stride: 1}, + {Lo: 0xAF80, Hi: 0xAF80, Stride: 1}, + {Lo: 0xAF9C, Hi: 0xAF9C, Stride: 1}, + {Lo: 0xAFB8, Hi: 0xAFB8, Stride: 1}, + {Lo: 0xAFD4, Hi: 0xAFD4, Stride: 1}, + {Lo: 0xAFF0, Hi: 0xAFF0, Stride: 1}, + {Lo: 0xB00C, Hi: 0xB00C, Stride: 1}, + {Lo: 0xB028, Hi: 0xB028, Stride: 1}, + {Lo: 0xB044, Hi: 0xB044, Stride: 1}, + {Lo: 0xB060, Hi: 0xB060, Stride: 1}, + {Lo: 0xB07C, Hi: 0xB07C, Stride: 1}, + {Lo: 0xB098, Hi: 0xB098, Stride: 1}, + {Lo: 0xB0B4, Hi: 0xB0B4, Stride: 1}, + {Lo: 0xB0D0, Hi: 0xB0D0, Stride: 1}, + {Lo: 0xB0EC, Hi: 0xB0EC, Stride: 1}, + {Lo: 0xB108, Hi: 0xB108, Stride: 1}, + {Lo: 0xB124, Hi: 0xB124, Stride: 1}, + {Lo: 0xB140, Hi: 0xB140, Stride: 1}, + {Lo: 0xB15C, Hi: 0xB15C, Stride: 1}, + {Lo: 0xB178, Hi: 0xB178, Stride: 1}, + {Lo: 0xB194, Hi: 0xB194, Stride: 1}, + {Lo: 0xB1B0, Hi: 0xB1B0, Stride: 1}, + {Lo: 0xB1CC, Hi: 0xB1CC, Stride: 1}, + {Lo: 0xB1E8, Hi: 0xB1E8, Stride: 1}, + {Lo: 0xB204, Hi: 0xB204, Stride: 1}, + {Lo: 0xB220, Hi: 0xB220, Stride: 1}, + {Lo: 0xB23C, Hi: 0xB23C, Stride: 1}, + {Lo: 0xB258, Hi: 0xB258, Stride: 1}, + {Lo: 0xB274, Hi: 0xB274, Stride: 1}, + {Lo: 0xB290, Hi: 0xB290, Stride: 1}, + {Lo: 0xB2AC, Hi: 0xB2AC, Stride: 1}, + {Lo: 0xB2C8, Hi: 0xB2C8, Stride: 1}, + {Lo: 0xB2E4, Hi: 0xB2E4, Stride: 1}, + {Lo: 0xB300, Hi: 0xB300, Stride: 1}, + {Lo: 0xB31C, Hi: 0xB31C, Stride: 1}, + {Lo: 0xB338, Hi: 0xB338, Stride: 1}, + {Lo: 0xB354, Hi: 0xB354, Stride: 1}, + {Lo: 0xB370, Hi: 0xB370, Stride: 1}, + {Lo: 0xB38C, Hi: 0xB38C, Stride: 1}, + {Lo: 0xB3A8, Hi: 0xB3A8, Stride: 1}, + {Lo: 0xB3C4, Hi: 0xB3C4, Stride: 1}, + {Lo: 0xB3E0, Hi: 0xB3E0, Stride: 1}, + {Lo: 0xB3FC, Hi: 0xB3FC, Stride: 1}, + {Lo: 0xB418, Hi: 0xB418, Stride: 1}, + {Lo: 0xB434, Hi: 0xB434, Stride: 1}, + {Lo: 0xB450, Hi: 0xB450, Stride: 1}, + {Lo: 0xB46C, Hi: 0xB46C, Stride: 1}, + {Lo: 0xB488, Hi: 0xB488, Stride: 1}, + {Lo: 0xB4A4, Hi: 0xB4A4, Stride: 1}, + {Lo: 0xB4C0, Hi: 0xB4C0, Stride: 1}, + {Lo: 0xB4DC, Hi: 0xB4DC, Stride: 1}, + {Lo: 0xB4F8, Hi: 0xB4F8, Stride: 1}, + {Lo: 0xB514, Hi: 0xB514, Stride: 1}, + {Lo: 0xB530, Hi: 0xB530, Stride: 1}, + {Lo: 0xB54C, Hi: 0xB54C, Stride: 1}, + {Lo: 0xB568, Hi: 0xB568, Stride: 1}, + {Lo: 0xB584, Hi: 0xB584, Stride: 1}, + {Lo: 0xB5A0, Hi: 0xB5A0, Stride: 1}, + {Lo: 0xB5BC, Hi: 0xB5BC, Stride: 1}, + {Lo: 0xB5D8, Hi: 0xB5D8, Stride: 1}, + {Lo: 0xB5F4, Hi: 0xB5F4, Stride: 1}, + {Lo: 0xB610, Hi: 0xB610, Stride: 1}, + {Lo: 0xB62C, Hi: 0xB62C, Stride: 1}, + {Lo: 0xB648, Hi: 0xB648, Stride: 1}, + {Lo: 0xB664, Hi: 0xB664, Stride: 1}, + {Lo: 0xB680, Hi: 0xB680, Stride: 1}, + {Lo: 0xB69C, Hi: 0xB69C, Stride: 1}, + {Lo: 0xB6B8, Hi: 0xB6B8, Stride: 1}, + {Lo: 0xB6D4, Hi: 0xB6D4, Stride: 1}, + {Lo: 0xB6F0, Hi: 0xB6F0, Stride: 1}, + {Lo: 0xB70C, Hi: 0xB70C, Stride: 1}, + {Lo: 0xB728, Hi: 0xB728, Stride: 1}, + {Lo: 0xB744, Hi: 0xB744, Stride: 1}, + {Lo: 0xB760, Hi: 0xB760, Stride: 1}, + {Lo: 0xB77C, Hi: 0xB77C, Stride: 1}, + {Lo: 0xB798, Hi: 0xB798, Stride: 1}, + {Lo: 0xB7B4, Hi: 0xB7B4, Stride: 1}, + {Lo: 0xB7D0, Hi: 0xB7D0, Stride: 1}, + {Lo: 0xB7EC, Hi: 0xB7EC, Stride: 1}, + {Lo: 0xB808, Hi: 0xB808, Stride: 1}, + {Lo: 0xB824, Hi: 0xB824, Stride: 1}, + {Lo: 0xB840, Hi: 0xB840, Stride: 1}, + {Lo: 0xB85C, Hi: 0xB85C, Stride: 1}, + {Lo: 0xB878, Hi: 0xB878, Stride: 1}, + {Lo: 0xB894, Hi: 0xB894, Stride: 1}, + {Lo: 0xB8B0, Hi: 0xB8B0, Stride: 1}, + {Lo: 0xB8CC, Hi: 0xB8CC, Stride: 1}, + {Lo: 0xB8E8, Hi: 0xB8E8, Stride: 1}, + {Lo: 0xB904, Hi: 0xB904, Stride: 1}, + {Lo: 0xB920, Hi: 0xB920, Stride: 1}, + {Lo: 0xB93C, Hi: 0xB93C, Stride: 1}, + {Lo: 0xB958, Hi: 0xB958, Stride: 1}, + {Lo: 0xB974, Hi: 0xB974, Stride: 1}, + {Lo: 0xB990, Hi: 0xB990, Stride: 1}, + {Lo: 0xB9AC, Hi: 0xB9AC, Stride: 1}, + {Lo: 0xB9C8, Hi: 0xB9C8, Stride: 1}, + {Lo: 0xB9E4, Hi: 0xB9E4, Stride: 1}, + {Lo: 0xBA00, Hi: 0xBA00, Stride: 1}, + {Lo: 0xBA1C, Hi: 0xBA1C, Stride: 1}, + {Lo: 0xBA38, Hi: 0xBA38, Stride: 1}, + {Lo: 0xBA54, Hi: 0xBA54, Stride: 1}, + {Lo: 0xBA70, Hi: 0xBA70, Stride: 1}, + {Lo: 0xBA8C, Hi: 0xBA8C, Stride: 1}, + {Lo: 0xBAA8, Hi: 0xBAA8, Stride: 1}, + {Lo: 0xBAC4, Hi: 0xBAC4, Stride: 1}, + {Lo: 0xBAE0, Hi: 0xBAE0, Stride: 1}, + {Lo: 0xBAFC, Hi: 0xBAFC, Stride: 1}, + {Lo: 0xBB18, Hi: 0xBB18, Stride: 1}, + {Lo: 0xBB34, Hi: 0xBB34, Stride: 1}, + {Lo: 0xBB50, Hi: 0xBB50, Stride: 1}, + {Lo: 0xBB6C, Hi: 0xBB6C, Stride: 1}, + {Lo: 0xBB88, Hi: 0xBB88, Stride: 1}, + {Lo: 0xBBA4, Hi: 0xBBA4, Stride: 1}, + {Lo: 0xBBC0, Hi: 0xBBC0, Stride: 1}, + {Lo: 0xBBDC, Hi: 0xBBDC, Stride: 1}, + {Lo: 0xBBF8, Hi: 0xBBF8, Stride: 1}, + {Lo: 0xBC14, Hi: 0xBC14, Stride: 1}, + {Lo: 0xBC30, Hi: 0xBC30, Stride: 1}, + {Lo: 0xBC4C, Hi: 0xBC4C, Stride: 1}, + {Lo: 0xBC68, Hi: 0xBC68, Stride: 1}, + {Lo: 0xBC84, Hi: 0xBC84, Stride: 1}, + {Lo: 0xBCA0, Hi: 0xBCA0, Stride: 1}, + {Lo: 0xBCBC, Hi: 0xBCBC, Stride: 1}, + {Lo: 0xBCD8, Hi: 0xBCD8, Stride: 1}, + {Lo: 0xBCF4, Hi: 0xBCF4, Stride: 1}, + {Lo: 0xBD10, Hi: 0xBD10, Stride: 1}, + {Lo: 0xBD2C, Hi: 0xBD2C, Stride: 1}, + {Lo: 0xBD48, Hi: 0xBD48, Stride: 1}, + {Lo: 0xBD64, Hi: 0xBD64, Stride: 1}, + {Lo: 0xBD80, Hi: 0xBD80, Stride: 1}, + {Lo: 0xBD9C, Hi: 0xBD9C, Stride: 1}, + {Lo: 0xBDB8, Hi: 0xBDB8, Stride: 1}, + {Lo: 0xBDD4, Hi: 0xBDD4, Stride: 1}, + {Lo: 0xBDF0, Hi: 0xBDF0, Stride: 1}, + {Lo: 0xBE0C, Hi: 0xBE0C, Stride: 1}, + {Lo: 0xBE28, Hi: 0xBE28, Stride: 1}, + {Lo: 0xBE44, Hi: 0xBE44, Stride: 1}, + {Lo: 0xBE60, Hi: 0xBE60, Stride: 1}, + {Lo: 0xBE7C, Hi: 0xBE7C, Stride: 1}, + {Lo: 0xBE98, Hi: 0xBE98, Stride: 1}, + {Lo: 0xBEB4, Hi: 0xBEB4, Stride: 1}, + {Lo: 0xBED0, Hi: 0xBED0, Stride: 1}, + {Lo: 0xBEEC, Hi: 0xBEEC, Stride: 1}, + {Lo: 0xBF08, Hi: 0xBF08, Stride: 1}, + {Lo: 0xBF24, Hi: 0xBF24, Stride: 1}, + {Lo: 0xBF40, Hi: 0xBF40, Stride: 1}, + {Lo: 0xBF5C, Hi: 0xBF5C, Stride: 1}, + {Lo: 0xBF78, Hi: 0xBF78, Stride: 1}, + {Lo: 0xBF94, Hi: 0xBF94, Stride: 1}, + {Lo: 0xBFB0, Hi: 0xBFB0, Stride: 1}, + {Lo: 0xBFCC, Hi: 0xBFCC, Stride: 1}, + {Lo: 0xBFE8, Hi: 0xBFE8, Stride: 1}, + {Lo: 0xC004, Hi: 0xC004, Stride: 1}, + {Lo: 0xC020, Hi: 0xC020, Stride: 1}, + {Lo: 0xC03C, Hi: 0xC03C, Stride: 1}, + {Lo: 0xC058, Hi: 0xC058, Stride: 1}, + {Lo: 0xC074, Hi: 0xC074, Stride: 1}, + {Lo: 0xC090, Hi: 0xC090, Stride: 1}, + {Lo: 0xC0AC, Hi: 0xC0AC, Stride: 1}, + {Lo: 0xC0C8, Hi: 0xC0C8, Stride: 1}, + {Lo: 0xC0E4, Hi: 0xC0E4, Stride: 1}, + {Lo: 0xC100, Hi: 0xC100, Stride: 1}, + {Lo: 0xC11C, Hi: 0xC11C, Stride: 1}, + {Lo: 0xC138, Hi: 0xC138, Stride: 1}, + {Lo: 0xC154, Hi: 0xC154, Stride: 1}, + {Lo: 0xC170, Hi: 0xC170, Stride: 1}, + {Lo: 0xC18C, Hi: 0xC18C, Stride: 1}, + {Lo: 0xC1A8, Hi: 0xC1A8, Stride: 1}, + {Lo: 0xC1C4, Hi: 0xC1C4, Stride: 1}, + {Lo: 0xC1E0, Hi: 0xC1E0, Stride: 1}, + {Lo: 0xC1FC, Hi: 0xC1FC, Stride: 1}, + {Lo: 0xC218, Hi: 0xC218, Stride: 1}, + {Lo: 0xC234, Hi: 0xC234, Stride: 1}, + {Lo: 0xC250, Hi: 0xC250, Stride: 1}, + {Lo: 0xC26C, Hi: 0xC26C, Stride: 1}, + {Lo: 0xC288, Hi: 0xC288, Stride: 1}, + {Lo: 0xC2A4, Hi: 0xC2A4, Stride: 1}, + {Lo: 0xC2C0, Hi: 0xC2C0, Stride: 1}, + {Lo: 0xC2DC, Hi: 0xC2DC, Stride: 1}, + {Lo: 0xC2F8, Hi: 0xC2F8, Stride: 1}, + {Lo: 0xC314, Hi: 0xC314, Stride: 1}, + {Lo: 0xC330, Hi: 0xC330, Stride: 1}, + {Lo: 0xC34C, Hi: 0xC34C, Stride: 1}, + {Lo: 0xC368, Hi: 0xC368, Stride: 1}, + {Lo: 0xC384, Hi: 0xC384, Stride: 1}, + {Lo: 0xC3A0, Hi: 0xC3A0, Stride: 1}, + {Lo: 0xC3BC, Hi: 0xC3BC, Stride: 1}, + {Lo: 0xC3D8, Hi: 0xC3D8, Stride: 1}, + {Lo: 0xC3F4, Hi: 0xC3F4, Stride: 1}, + {Lo: 0xC410, Hi: 0xC410, Stride: 1}, + {Lo: 0xC42C, Hi: 0xC42C, Stride: 1}, + {Lo: 0xC448, Hi: 0xC448, Stride: 1}, + {Lo: 0xC464, Hi: 0xC464, Stride: 1}, + {Lo: 0xC480, Hi: 0xC480, Stride: 1}, + {Lo: 0xC49C, Hi: 0xC49C, Stride: 1}, + {Lo: 0xC4B8, Hi: 0xC4B8, Stride: 1}, + {Lo: 0xC4D4, Hi: 0xC4D4, Stride: 1}, + {Lo: 0xC4F0, Hi: 0xC4F0, Stride: 1}, + {Lo: 0xC50C, Hi: 0xC50C, Stride: 1}, + {Lo: 0xC528, Hi: 0xC528, Stride: 1}, + {Lo: 0xC544, Hi: 0xC544, Stride: 1}, + {Lo: 0xC560, Hi: 0xC560, Stride: 1}, + {Lo: 0xC57C, Hi: 0xC57C, Stride: 1}, + {Lo: 0xC598, Hi: 0xC598, Stride: 1}, + {Lo: 0xC5B4, Hi: 0xC5B4, Stride: 1}, + {Lo: 0xC5D0, Hi: 0xC5D0, Stride: 1}, + {Lo: 0xC5EC, Hi: 0xC5EC, Stride: 1}, + {Lo: 0xC608, Hi: 0xC608, Stride: 1}, + {Lo: 0xC624, Hi: 0xC624, Stride: 1}, + {Lo: 0xC640, Hi: 0xC640, Stride: 1}, + {Lo: 0xC65C, Hi: 0xC65C, Stride: 1}, + {Lo: 0xC678, Hi: 0xC678, Stride: 1}, + {Lo: 0xC694, Hi: 0xC694, Stride: 1}, + {Lo: 0xC6B0, Hi: 0xC6B0, Stride: 1}, + {Lo: 0xC6CC, Hi: 0xC6CC, Stride: 1}, + {Lo: 0xC6E8, Hi: 0xC6E8, Stride: 1}, + {Lo: 0xC704, Hi: 0xC704, Stride: 1}, + {Lo: 0xC720, Hi: 0xC720, Stride: 1}, + {Lo: 0xC73C, Hi: 0xC73C, Stride: 1}, + {Lo: 0xC758, Hi: 0xC758, Stride: 1}, + {Lo: 0xC774, Hi: 0xC774, Stride: 1}, + {Lo: 0xC790, Hi: 0xC790, Stride: 1}, + {Lo: 0xC7AC, Hi: 0xC7AC, Stride: 1}, + {Lo: 0xC7C8, Hi: 0xC7C8, Stride: 1}, + {Lo: 0xC7E4, Hi: 0xC7E4, Stride: 1}, + {Lo: 0xC800, Hi: 0xC800, Stride: 1}, + {Lo: 0xC81C, Hi: 0xC81C, Stride: 1}, + {Lo: 0xC838, Hi: 0xC838, Stride: 1}, + {Lo: 0xC854, Hi: 0xC854, Stride: 1}, + {Lo: 0xC870, Hi: 0xC870, Stride: 1}, + {Lo: 0xC88C, Hi: 0xC88C, Stride: 1}, + {Lo: 0xC8A8, Hi: 0xC8A8, Stride: 1}, + {Lo: 0xC8C4, Hi: 0xC8C4, Stride: 1}, + {Lo: 0xC8E0, Hi: 0xC8E0, Stride: 1}, + {Lo: 0xC8FC, Hi: 0xC8FC, Stride: 1}, + {Lo: 0xC918, Hi: 0xC918, Stride: 1}, + {Lo: 0xC934, Hi: 0xC934, Stride: 1}, + {Lo: 0xC950, Hi: 0xC950, Stride: 1}, + {Lo: 0xC96C, Hi: 0xC96C, Stride: 1}, + {Lo: 0xC988, Hi: 0xC988, Stride: 1}, + {Lo: 0xC9A4, Hi: 0xC9A4, Stride: 1}, + {Lo: 0xC9C0, Hi: 0xC9C0, Stride: 1}, + {Lo: 0xC9DC, Hi: 0xC9DC, Stride: 1}, + {Lo: 0xC9F8, Hi: 0xC9F8, Stride: 1}, + {Lo: 0xCA14, Hi: 0xCA14, Stride: 1}, + {Lo: 0xCA30, Hi: 0xCA30, Stride: 1}, + {Lo: 0xCA4C, Hi: 0xCA4C, Stride: 1}, + {Lo: 0xCA68, Hi: 0xCA68, Stride: 1}, + {Lo: 0xCA84, Hi: 0xCA84, Stride: 1}, + {Lo: 0xCAA0, Hi: 0xCAA0, Stride: 1}, + {Lo: 0xCABC, Hi: 0xCABC, Stride: 1}, + {Lo: 0xCAD8, Hi: 0xCAD8, Stride: 1}, + {Lo: 0xCAF4, Hi: 0xCAF4, Stride: 1}, + {Lo: 0xCB10, Hi: 0xCB10, Stride: 1}, + {Lo: 0xCB2C, Hi: 0xCB2C, Stride: 1}, + {Lo: 0xCB48, Hi: 0xCB48, Stride: 1}, + {Lo: 0xCB64, Hi: 0xCB64, Stride: 1}, + {Lo: 0xCB80, Hi: 0xCB80, Stride: 1}, + {Lo: 0xCB9C, Hi: 0xCB9C, Stride: 1}, + {Lo: 0xCBB8, Hi: 0xCBB8, Stride: 1}, + {Lo: 0xCBD4, Hi: 0xCBD4, Stride: 1}, + {Lo: 0xCBF0, Hi: 0xCBF0, Stride: 1}, + {Lo: 0xCC0C, Hi: 0xCC0C, Stride: 1}, + {Lo: 0xCC28, Hi: 0xCC28, Stride: 1}, + {Lo: 0xCC44, Hi: 0xCC44, Stride: 1}, + {Lo: 0xCC60, Hi: 0xCC60, Stride: 1}, + {Lo: 0xCC7C, Hi: 0xCC7C, Stride: 1}, + {Lo: 0xCC98, Hi: 0xCC98, Stride: 1}, + {Lo: 0xCCB4, Hi: 0xCCB4, Stride: 1}, + {Lo: 0xCCD0, Hi: 0xCCD0, Stride: 1}, + {Lo: 0xCCEC, Hi: 0xCCEC, Stride: 1}, + {Lo: 0xCD08, Hi: 0xCD08, Stride: 1}, + {Lo: 0xCD24, Hi: 0xCD24, Stride: 1}, + {Lo: 0xCD40, Hi: 0xCD40, Stride: 1}, + {Lo: 0xCD5C, Hi: 0xCD5C, Stride: 1}, + {Lo: 0xCD78, Hi: 0xCD78, Stride: 1}, + {Lo: 0xCD94, Hi: 0xCD94, Stride: 1}, + {Lo: 0xCDB0, Hi: 0xCDB0, Stride: 1}, + {Lo: 0xCDCC, Hi: 0xCDCC, Stride: 1}, + {Lo: 0xCDE8, Hi: 0xCDE8, Stride: 1}, + {Lo: 0xCE04, Hi: 0xCE04, Stride: 1}, + {Lo: 0xCE20, Hi: 0xCE20, Stride: 1}, + {Lo: 0xCE3C, Hi: 0xCE3C, Stride: 1}, + {Lo: 0xCE58, Hi: 0xCE58, Stride: 1}, + {Lo: 0xCE74, Hi: 0xCE74, Stride: 1}, + {Lo: 0xCE90, Hi: 0xCE90, Stride: 1}, + {Lo: 0xCEAC, Hi: 0xCEAC, Stride: 1}, + {Lo: 0xCEC8, Hi: 0xCEC8, Stride: 1}, + {Lo: 0xCEE4, Hi: 0xCEE4, Stride: 1}, + {Lo: 0xCF00, Hi: 0xCF00, Stride: 1}, + {Lo: 0xCF1C, Hi: 0xCF1C, Stride: 1}, + {Lo: 0xCF38, Hi: 0xCF38, Stride: 1}, + {Lo: 0xCF54, Hi: 0xCF54, Stride: 1}, + {Lo: 0xCF70, Hi: 0xCF70, Stride: 1}, + {Lo: 0xCF8C, Hi: 0xCF8C, Stride: 1}, + {Lo: 0xCFA8, Hi: 0xCFA8, Stride: 1}, + {Lo: 0xCFC4, Hi: 0xCFC4, Stride: 1}, + {Lo: 0xCFE0, Hi: 0xCFE0, Stride: 1}, + {Lo: 0xCFFC, Hi: 0xCFFC, Stride: 1}, + {Lo: 0xD018, Hi: 0xD018, Stride: 1}, + {Lo: 0xD034, Hi: 0xD034, Stride: 1}, + {Lo: 0xD050, Hi: 0xD050, Stride: 1}, + {Lo: 0xD06C, Hi: 0xD06C, Stride: 1}, + {Lo: 0xD088, Hi: 0xD088, Stride: 1}, + {Lo: 0xD0A4, Hi: 0xD0A4, Stride: 1}, + {Lo: 0xD0C0, Hi: 0xD0C0, Stride: 1}, + {Lo: 0xD0DC, Hi: 0xD0DC, Stride: 1}, + {Lo: 0xD0F8, Hi: 0xD0F8, Stride: 1}, + {Lo: 0xD114, Hi: 0xD114, Stride: 1}, + {Lo: 0xD130, Hi: 0xD130, Stride: 1}, + {Lo: 0xD14C, Hi: 0xD14C, Stride: 1}, + {Lo: 0xD168, Hi: 0xD168, Stride: 1}, + {Lo: 0xD184, Hi: 0xD184, Stride: 1}, + {Lo: 0xD1A0, Hi: 0xD1A0, Stride: 1}, + {Lo: 0xD1BC, Hi: 0xD1BC, Stride: 1}, + {Lo: 0xD1D8, Hi: 0xD1D8, Stride: 1}, + {Lo: 0xD1F4, Hi: 0xD1F4, Stride: 1}, + {Lo: 0xD210, Hi: 0xD210, Stride: 1}, + {Lo: 0xD22C, Hi: 0xD22C, Stride: 1}, + {Lo: 0xD248, Hi: 0xD248, Stride: 1}, + {Lo: 0xD264, Hi: 0xD264, Stride: 1}, + {Lo: 0xD280, Hi: 0xD280, Stride: 1}, + {Lo: 0xD29C, Hi: 0xD29C, Stride: 1}, + {Lo: 0xD2B8, Hi: 0xD2B8, Stride: 1}, + {Lo: 0xD2D4, Hi: 0xD2D4, Stride: 1}, + {Lo: 0xD2F0, Hi: 0xD2F0, Stride: 1}, + {Lo: 0xD30C, Hi: 0xD30C, Stride: 1}, + {Lo: 0xD328, Hi: 0xD328, Stride: 1}, + {Lo: 0xD344, Hi: 0xD344, Stride: 1}, + {Lo: 0xD360, Hi: 0xD360, Stride: 1}, + {Lo: 0xD37C, Hi: 0xD37C, Stride: 1}, + {Lo: 0xD398, Hi: 0xD398, Stride: 1}, + {Lo: 0xD3B4, Hi: 0xD3B4, Stride: 1}, + {Lo: 0xD3D0, Hi: 0xD3D0, Stride: 1}, + {Lo: 0xD3EC, Hi: 0xD3EC, Stride: 1}, + {Lo: 0xD408, Hi: 0xD408, Stride: 1}, + {Lo: 0xD424, Hi: 0xD424, Stride: 1}, + {Lo: 0xD440, Hi: 0xD440, Stride: 1}, + {Lo: 0xD45C, Hi: 0xD45C, Stride: 1}, + {Lo: 0xD478, Hi: 0xD478, Stride: 1}, + {Lo: 0xD494, Hi: 0xD494, Stride: 1}, + {Lo: 0xD4B0, Hi: 0xD4B0, Stride: 1}, + {Lo: 0xD4CC, Hi: 0xD4CC, Stride: 1}, + {Lo: 0xD4E8, Hi: 0xD4E8, Stride: 1}, + {Lo: 0xD504, Hi: 0xD504, Stride: 1}, + {Lo: 0xD520, Hi: 0xD520, Stride: 1}, + {Lo: 0xD53C, Hi: 0xD53C, Stride: 1}, + {Lo: 0xD558, Hi: 0xD558, Stride: 1}, + {Lo: 0xD574, Hi: 0xD574, Stride: 1}, + {Lo: 0xD590, Hi: 0xD590, Stride: 1}, + {Lo: 0xD5AC, Hi: 0xD5AC, Stride: 1}, + {Lo: 0xD5C8, Hi: 0xD5C8, Stride: 1}, + {Lo: 0xD5E4, Hi: 0xD5E4, Stride: 1}, + {Lo: 0xD600, Hi: 0xD600, Stride: 1}, + {Lo: 0xD61C, Hi: 0xD61C, Stride: 1}, + {Lo: 0xD638, Hi: 0xD638, Stride: 1}, + {Lo: 0xD654, Hi: 0xD654, Stride: 1}, + {Lo: 0xD670, Hi: 0xD670, Stride: 1}, + {Lo: 0xD68C, Hi: 0xD68C, Stride: 1}, + {Lo: 0xD6A8, Hi: 0xD6A8, Stride: 1}, + {Lo: 0xD6C4, Hi: 0xD6C4, Stride: 1}, + {Lo: 0xD6E0, Hi: 0xD6E0, Stride: 1}, + {Lo: 0xD6FC, Hi: 0xD6FC, Stride: 1}, + {Lo: 0xD718, Hi: 0xD718, Stride: 1}, + {Lo: 0xD734, Hi: 0xD734, Stride: 1}, + {Lo: 0xD750, Hi: 0xD750, Stride: 1}, + {Lo: 0xD76C, Hi: 0xD76C, Stride: 1}, + {Lo: 0xD788, Hi: 0xD788, Stride: 1}, + }, +} + +var unicodeAliasGrapheme_Cluster_Break_LVT = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0xAC01, Hi: 0xAC1B, Stride: 1}, + {Lo: 0xAC1D, Hi: 0xAC37, Stride: 1}, + {Lo: 0xAC39, Hi: 0xAC53, Stride: 1}, + {Lo: 0xAC55, Hi: 0xAC6F, Stride: 1}, + {Lo: 0xAC71, Hi: 0xAC8B, Stride: 1}, + {Lo: 0xAC8D, Hi: 0xACA7, Stride: 1}, + {Lo: 0xACA9, Hi: 0xACC3, Stride: 1}, + {Lo: 0xACC5, Hi: 0xACDF, Stride: 1}, + {Lo: 0xACE1, Hi: 0xACFB, Stride: 1}, + {Lo: 0xACFD, Hi: 0xAD17, Stride: 1}, + {Lo: 0xAD19, Hi: 0xAD33, Stride: 1}, + {Lo: 0xAD35, Hi: 0xAD4F, Stride: 1}, + {Lo: 0xAD51, Hi: 0xAD6B, Stride: 1}, + {Lo: 0xAD6D, Hi: 0xAD87, Stride: 1}, + {Lo: 0xAD89, Hi: 0xADA3, Stride: 1}, + {Lo: 0xADA5, Hi: 0xADBF, Stride: 1}, + {Lo: 0xADC1, Hi: 0xADDB, Stride: 1}, + {Lo: 0xADDD, Hi: 0xADF7, Stride: 1}, + {Lo: 0xADF9, Hi: 0xAE13, Stride: 1}, + {Lo: 0xAE15, Hi: 0xAE2F, Stride: 1}, + {Lo: 0xAE31, Hi: 0xAE4B, Stride: 1}, + {Lo: 0xAE4D, Hi: 0xAE67, Stride: 1}, + {Lo: 0xAE69, Hi: 0xAE83, Stride: 1}, + {Lo: 0xAE85, Hi: 0xAE9F, Stride: 1}, + {Lo: 0xAEA1, Hi: 0xAEBB, Stride: 1}, + {Lo: 0xAEBD, Hi: 0xAED7, Stride: 1}, + {Lo: 0xAED9, Hi: 0xAEF3, Stride: 1}, + {Lo: 0xAEF5, Hi: 0xAF0F, Stride: 1}, + {Lo: 0xAF11, Hi: 0xAF2B, Stride: 1}, + {Lo: 0xAF2D, Hi: 0xAF47, Stride: 1}, + {Lo: 0xAF49, Hi: 0xAF63, Stride: 1}, + {Lo: 0xAF65, Hi: 0xAF7F, Stride: 1}, + {Lo: 0xAF81, Hi: 0xAF9B, Stride: 1}, + {Lo: 0xAF9D, Hi: 0xAFB7, Stride: 1}, + {Lo: 0xAFB9, Hi: 0xAFD3, Stride: 1}, + {Lo: 0xAFD5, Hi: 0xAFEF, Stride: 1}, + {Lo: 0xAFF1, Hi: 0xB00B, Stride: 1}, + {Lo: 0xB00D, Hi: 0xB027, Stride: 1}, + {Lo: 0xB029, Hi: 0xB043, Stride: 1}, + {Lo: 0xB045, Hi: 0xB05F, Stride: 1}, + {Lo: 0xB061, Hi: 0xB07B, Stride: 1}, + {Lo: 0xB07D, Hi: 0xB097, Stride: 1}, + {Lo: 0xB099, Hi: 0xB0B3, Stride: 1}, + {Lo: 0xB0B5, Hi: 0xB0CF, Stride: 1}, + {Lo: 0xB0D1, Hi: 0xB0EB, Stride: 1}, + {Lo: 0xB0ED, Hi: 0xB107, Stride: 1}, + {Lo: 0xB109, Hi: 0xB123, Stride: 1}, + {Lo: 0xB125, Hi: 0xB13F, Stride: 1}, + {Lo: 0xB141, Hi: 0xB15B, Stride: 1}, + {Lo: 0xB15D, Hi: 0xB177, Stride: 1}, + {Lo: 0xB179, Hi: 0xB193, Stride: 1}, + {Lo: 0xB195, Hi: 0xB1AF, Stride: 1}, + {Lo: 0xB1B1, Hi: 0xB1CB, Stride: 1}, + {Lo: 0xB1CD, Hi: 0xB1E7, Stride: 1}, + {Lo: 0xB1E9, Hi: 0xB203, Stride: 1}, + {Lo: 0xB205, Hi: 0xB21F, Stride: 1}, + {Lo: 0xB221, Hi: 0xB23B, Stride: 1}, + {Lo: 0xB23D, Hi: 0xB257, Stride: 1}, + {Lo: 0xB259, Hi: 0xB273, Stride: 1}, + {Lo: 0xB275, Hi: 0xB28F, Stride: 1}, + {Lo: 0xB291, Hi: 0xB2AB, Stride: 1}, + {Lo: 0xB2AD, Hi: 0xB2C7, Stride: 1}, + {Lo: 0xB2C9, Hi: 0xB2E3, Stride: 1}, + {Lo: 0xB2E5, Hi: 0xB2FF, Stride: 1}, + {Lo: 0xB301, Hi: 0xB31B, Stride: 1}, + {Lo: 0xB31D, Hi: 0xB337, Stride: 1}, + {Lo: 0xB339, Hi: 0xB353, Stride: 1}, + {Lo: 0xB355, Hi: 0xB36F, Stride: 1}, + {Lo: 0xB371, Hi: 0xB38B, Stride: 1}, + {Lo: 0xB38D, Hi: 0xB3A7, Stride: 1}, + {Lo: 0xB3A9, Hi: 0xB3C3, Stride: 1}, + {Lo: 0xB3C5, Hi: 0xB3DF, Stride: 1}, + {Lo: 0xB3E1, Hi: 0xB3FB, Stride: 1}, + {Lo: 0xB3FD, Hi: 0xB417, Stride: 1}, + {Lo: 0xB419, Hi: 0xB433, Stride: 1}, + {Lo: 0xB435, Hi: 0xB44F, Stride: 1}, + {Lo: 0xB451, Hi: 0xB46B, Stride: 1}, + {Lo: 0xB46D, Hi: 0xB487, Stride: 1}, + {Lo: 0xB489, Hi: 0xB4A3, Stride: 1}, + {Lo: 0xB4A5, Hi: 0xB4BF, Stride: 1}, + {Lo: 0xB4C1, Hi: 0xB4DB, Stride: 1}, + {Lo: 0xB4DD, Hi: 0xB4F7, Stride: 1}, + {Lo: 0xB4F9, Hi: 0xB513, Stride: 1}, + {Lo: 0xB515, Hi: 0xB52F, Stride: 1}, + {Lo: 0xB531, Hi: 0xB54B, Stride: 1}, + {Lo: 0xB54D, Hi: 0xB567, Stride: 1}, + {Lo: 0xB569, Hi: 0xB583, Stride: 1}, + {Lo: 0xB585, Hi: 0xB59F, Stride: 1}, + {Lo: 0xB5A1, Hi: 0xB5BB, Stride: 1}, + {Lo: 0xB5BD, Hi: 0xB5D7, Stride: 1}, + {Lo: 0xB5D9, Hi: 0xB5F3, Stride: 1}, + {Lo: 0xB5F5, Hi: 0xB60F, Stride: 1}, + {Lo: 0xB611, Hi: 0xB62B, Stride: 1}, + {Lo: 0xB62D, Hi: 0xB647, Stride: 1}, + {Lo: 0xB649, Hi: 0xB663, Stride: 1}, + {Lo: 0xB665, Hi: 0xB67F, Stride: 1}, + {Lo: 0xB681, Hi: 0xB69B, Stride: 1}, + {Lo: 0xB69D, Hi: 0xB6B7, Stride: 1}, + {Lo: 0xB6B9, Hi: 0xB6D3, Stride: 1}, + {Lo: 0xB6D5, Hi: 0xB6EF, Stride: 1}, + {Lo: 0xB6F1, Hi: 0xB70B, Stride: 1}, + {Lo: 0xB70D, Hi: 0xB727, Stride: 1}, + {Lo: 0xB729, Hi: 0xB743, Stride: 1}, + {Lo: 0xB745, Hi: 0xB75F, Stride: 1}, + {Lo: 0xB761, Hi: 0xB77B, Stride: 1}, + {Lo: 0xB77D, Hi: 0xB797, Stride: 1}, + {Lo: 0xB799, Hi: 0xB7B3, Stride: 1}, + {Lo: 0xB7B5, Hi: 0xB7CF, Stride: 1}, + {Lo: 0xB7D1, Hi: 0xB7EB, Stride: 1}, + {Lo: 0xB7ED, Hi: 0xB807, Stride: 1}, + {Lo: 0xB809, Hi: 0xB823, Stride: 1}, + {Lo: 0xB825, Hi: 0xB83F, Stride: 1}, + {Lo: 0xB841, Hi: 0xB85B, Stride: 1}, + {Lo: 0xB85D, Hi: 0xB877, Stride: 1}, + {Lo: 0xB879, Hi: 0xB893, Stride: 1}, + {Lo: 0xB895, Hi: 0xB8AF, Stride: 1}, + {Lo: 0xB8B1, Hi: 0xB8CB, Stride: 1}, + {Lo: 0xB8CD, Hi: 0xB8E7, Stride: 1}, + {Lo: 0xB8E9, Hi: 0xB903, Stride: 1}, + {Lo: 0xB905, Hi: 0xB91F, Stride: 1}, + {Lo: 0xB921, Hi: 0xB93B, Stride: 1}, + {Lo: 0xB93D, Hi: 0xB957, Stride: 1}, + {Lo: 0xB959, Hi: 0xB973, Stride: 1}, + {Lo: 0xB975, Hi: 0xB98F, Stride: 1}, + {Lo: 0xB991, Hi: 0xB9AB, Stride: 1}, + {Lo: 0xB9AD, Hi: 0xB9C7, Stride: 1}, + {Lo: 0xB9C9, Hi: 0xB9E3, Stride: 1}, + {Lo: 0xB9E5, Hi: 0xB9FF, Stride: 1}, + {Lo: 0xBA01, Hi: 0xBA1B, Stride: 1}, + {Lo: 0xBA1D, Hi: 0xBA37, Stride: 1}, + {Lo: 0xBA39, Hi: 0xBA53, Stride: 1}, + {Lo: 0xBA55, Hi: 0xBA6F, Stride: 1}, + {Lo: 0xBA71, Hi: 0xBA8B, Stride: 1}, + {Lo: 0xBA8D, Hi: 0xBAA7, Stride: 1}, + {Lo: 0xBAA9, Hi: 0xBAC3, Stride: 1}, + {Lo: 0xBAC5, Hi: 0xBADF, Stride: 1}, + {Lo: 0xBAE1, Hi: 0xBAFB, Stride: 1}, + {Lo: 0xBAFD, Hi: 0xBB17, Stride: 1}, + {Lo: 0xBB19, Hi: 0xBB33, Stride: 1}, + {Lo: 0xBB35, Hi: 0xBB4F, Stride: 1}, + {Lo: 0xBB51, Hi: 0xBB6B, Stride: 1}, + {Lo: 0xBB6D, Hi: 0xBB87, Stride: 1}, + {Lo: 0xBB89, Hi: 0xBBA3, Stride: 1}, + {Lo: 0xBBA5, Hi: 0xBBBF, Stride: 1}, + {Lo: 0xBBC1, Hi: 0xBBDB, Stride: 1}, + {Lo: 0xBBDD, Hi: 0xBBF7, Stride: 1}, + {Lo: 0xBBF9, Hi: 0xBC13, Stride: 1}, + {Lo: 0xBC15, Hi: 0xBC2F, Stride: 1}, + {Lo: 0xBC31, Hi: 0xBC4B, Stride: 1}, + {Lo: 0xBC4D, Hi: 0xBC67, Stride: 1}, + {Lo: 0xBC69, Hi: 0xBC83, Stride: 1}, + {Lo: 0xBC85, Hi: 0xBC9F, Stride: 1}, + {Lo: 0xBCA1, Hi: 0xBCBB, Stride: 1}, + {Lo: 0xBCBD, Hi: 0xBCD7, Stride: 1}, + {Lo: 0xBCD9, Hi: 0xBCF3, Stride: 1}, + {Lo: 0xBCF5, Hi: 0xBD0F, Stride: 1}, + {Lo: 0xBD11, Hi: 0xBD2B, Stride: 1}, + {Lo: 0xBD2D, Hi: 0xBD47, Stride: 1}, + {Lo: 0xBD49, Hi: 0xBD63, Stride: 1}, + {Lo: 0xBD65, Hi: 0xBD7F, Stride: 1}, + {Lo: 0xBD81, Hi: 0xBD9B, Stride: 1}, + {Lo: 0xBD9D, Hi: 0xBDB7, Stride: 1}, + {Lo: 0xBDB9, Hi: 0xBDD3, Stride: 1}, + {Lo: 0xBDD5, Hi: 0xBDEF, Stride: 1}, + {Lo: 0xBDF1, Hi: 0xBE0B, Stride: 1}, + {Lo: 0xBE0D, Hi: 0xBE27, Stride: 1}, + {Lo: 0xBE29, Hi: 0xBE43, Stride: 1}, + {Lo: 0xBE45, Hi: 0xBE5F, Stride: 1}, + {Lo: 0xBE61, Hi: 0xBE7B, Stride: 1}, + {Lo: 0xBE7D, Hi: 0xBE97, Stride: 1}, + {Lo: 0xBE99, Hi: 0xBEB3, Stride: 1}, + {Lo: 0xBEB5, Hi: 0xBECF, Stride: 1}, + {Lo: 0xBED1, Hi: 0xBEEB, Stride: 1}, + {Lo: 0xBEED, Hi: 0xBF07, Stride: 1}, + {Lo: 0xBF09, Hi: 0xBF23, Stride: 1}, + {Lo: 0xBF25, Hi: 0xBF3F, Stride: 1}, + {Lo: 0xBF41, Hi: 0xBF5B, Stride: 1}, + {Lo: 0xBF5D, Hi: 0xBF77, Stride: 1}, + {Lo: 0xBF79, Hi: 0xBF93, Stride: 1}, + {Lo: 0xBF95, Hi: 0xBFAF, Stride: 1}, + {Lo: 0xBFB1, Hi: 0xBFCB, Stride: 1}, + {Lo: 0xBFCD, Hi: 0xBFE7, Stride: 1}, + {Lo: 0xBFE9, Hi: 0xC003, Stride: 1}, + {Lo: 0xC005, Hi: 0xC01F, Stride: 1}, + {Lo: 0xC021, Hi: 0xC03B, Stride: 1}, + {Lo: 0xC03D, Hi: 0xC057, Stride: 1}, + {Lo: 0xC059, Hi: 0xC073, Stride: 1}, + {Lo: 0xC075, Hi: 0xC08F, Stride: 1}, + {Lo: 0xC091, Hi: 0xC0AB, Stride: 1}, + {Lo: 0xC0AD, Hi: 0xC0C7, Stride: 1}, + {Lo: 0xC0C9, Hi: 0xC0E3, Stride: 1}, + {Lo: 0xC0E5, Hi: 0xC0FF, Stride: 1}, + {Lo: 0xC101, Hi: 0xC11B, Stride: 1}, + {Lo: 0xC11D, Hi: 0xC137, Stride: 1}, + {Lo: 0xC139, Hi: 0xC153, Stride: 1}, + {Lo: 0xC155, Hi: 0xC16F, Stride: 1}, + {Lo: 0xC171, Hi: 0xC18B, Stride: 1}, + {Lo: 0xC18D, Hi: 0xC1A7, Stride: 1}, + {Lo: 0xC1A9, Hi: 0xC1C3, Stride: 1}, + {Lo: 0xC1C5, Hi: 0xC1DF, Stride: 1}, + {Lo: 0xC1E1, Hi: 0xC1FB, Stride: 1}, + {Lo: 0xC1FD, Hi: 0xC217, Stride: 1}, + {Lo: 0xC219, Hi: 0xC233, Stride: 1}, + {Lo: 0xC235, Hi: 0xC24F, Stride: 1}, + {Lo: 0xC251, Hi: 0xC26B, Stride: 1}, + {Lo: 0xC26D, Hi: 0xC287, Stride: 1}, + {Lo: 0xC289, Hi: 0xC2A3, Stride: 1}, + {Lo: 0xC2A5, Hi: 0xC2BF, Stride: 1}, + {Lo: 0xC2C1, Hi: 0xC2DB, Stride: 1}, + {Lo: 0xC2DD, Hi: 0xC2F7, Stride: 1}, + {Lo: 0xC2F9, Hi: 0xC313, Stride: 1}, + {Lo: 0xC315, Hi: 0xC32F, Stride: 1}, + {Lo: 0xC331, Hi: 0xC34B, Stride: 1}, + {Lo: 0xC34D, Hi: 0xC367, Stride: 1}, + {Lo: 0xC369, Hi: 0xC383, Stride: 1}, + {Lo: 0xC385, Hi: 0xC39F, Stride: 1}, + {Lo: 0xC3A1, Hi: 0xC3BB, Stride: 1}, + {Lo: 0xC3BD, Hi: 0xC3D7, Stride: 1}, + {Lo: 0xC3D9, Hi: 0xC3F3, Stride: 1}, + {Lo: 0xC3F5, Hi: 0xC40F, Stride: 1}, + {Lo: 0xC411, Hi: 0xC42B, Stride: 1}, + {Lo: 0xC42D, Hi: 0xC447, Stride: 1}, + {Lo: 0xC449, Hi: 0xC463, Stride: 1}, + {Lo: 0xC465, Hi: 0xC47F, Stride: 1}, + {Lo: 0xC481, Hi: 0xC49B, Stride: 1}, + {Lo: 0xC49D, Hi: 0xC4B7, Stride: 1}, + {Lo: 0xC4B9, Hi: 0xC4D3, Stride: 1}, + {Lo: 0xC4D5, Hi: 0xC4EF, Stride: 1}, + {Lo: 0xC4F1, Hi: 0xC50B, Stride: 1}, + {Lo: 0xC50D, Hi: 0xC527, Stride: 1}, + {Lo: 0xC529, Hi: 0xC543, Stride: 1}, + {Lo: 0xC545, Hi: 0xC55F, Stride: 1}, + {Lo: 0xC561, Hi: 0xC57B, Stride: 1}, + {Lo: 0xC57D, Hi: 0xC597, Stride: 1}, + {Lo: 0xC599, Hi: 0xC5B3, Stride: 1}, + {Lo: 0xC5B5, Hi: 0xC5CF, Stride: 1}, + {Lo: 0xC5D1, Hi: 0xC5EB, Stride: 1}, + {Lo: 0xC5ED, Hi: 0xC607, Stride: 1}, + {Lo: 0xC609, Hi: 0xC623, Stride: 1}, + {Lo: 0xC625, Hi: 0xC63F, Stride: 1}, + {Lo: 0xC641, Hi: 0xC65B, Stride: 1}, + {Lo: 0xC65D, Hi: 0xC677, Stride: 1}, + {Lo: 0xC679, Hi: 0xC693, Stride: 1}, + {Lo: 0xC695, Hi: 0xC6AF, Stride: 1}, + {Lo: 0xC6B1, Hi: 0xC6CB, Stride: 1}, + {Lo: 0xC6CD, Hi: 0xC6E7, Stride: 1}, + {Lo: 0xC6E9, Hi: 0xC703, Stride: 1}, + {Lo: 0xC705, Hi: 0xC71F, Stride: 1}, + {Lo: 0xC721, Hi: 0xC73B, Stride: 1}, + {Lo: 0xC73D, Hi: 0xC757, Stride: 1}, + {Lo: 0xC759, Hi: 0xC773, Stride: 1}, + {Lo: 0xC775, Hi: 0xC78F, Stride: 1}, + {Lo: 0xC791, Hi: 0xC7AB, Stride: 1}, + {Lo: 0xC7AD, Hi: 0xC7C7, Stride: 1}, + {Lo: 0xC7C9, Hi: 0xC7E3, Stride: 1}, + {Lo: 0xC7E5, Hi: 0xC7FF, Stride: 1}, + {Lo: 0xC801, Hi: 0xC81B, Stride: 1}, + {Lo: 0xC81D, Hi: 0xC837, Stride: 1}, + {Lo: 0xC839, Hi: 0xC853, Stride: 1}, + {Lo: 0xC855, Hi: 0xC86F, Stride: 1}, + {Lo: 0xC871, Hi: 0xC88B, Stride: 1}, + {Lo: 0xC88D, Hi: 0xC8A7, Stride: 1}, + {Lo: 0xC8A9, Hi: 0xC8C3, Stride: 1}, + {Lo: 0xC8C5, Hi: 0xC8DF, Stride: 1}, + {Lo: 0xC8E1, Hi: 0xC8FB, Stride: 1}, + {Lo: 0xC8FD, Hi: 0xC917, Stride: 1}, + {Lo: 0xC919, Hi: 0xC933, Stride: 1}, + {Lo: 0xC935, Hi: 0xC94F, Stride: 1}, + {Lo: 0xC951, Hi: 0xC96B, Stride: 1}, + {Lo: 0xC96D, Hi: 0xC987, Stride: 1}, + {Lo: 0xC989, Hi: 0xC9A3, Stride: 1}, + {Lo: 0xC9A5, Hi: 0xC9BF, Stride: 1}, + {Lo: 0xC9C1, Hi: 0xC9DB, Stride: 1}, + {Lo: 0xC9DD, Hi: 0xC9F7, Stride: 1}, + {Lo: 0xC9F9, Hi: 0xCA13, Stride: 1}, + {Lo: 0xCA15, Hi: 0xCA2F, Stride: 1}, + {Lo: 0xCA31, Hi: 0xCA4B, Stride: 1}, + {Lo: 0xCA4D, Hi: 0xCA67, Stride: 1}, + {Lo: 0xCA69, Hi: 0xCA83, Stride: 1}, + {Lo: 0xCA85, Hi: 0xCA9F, Stride: 1}, + {Lo: 0xCAA1, Hi: 0xCABB, Stride: 1}, + {Lo: 0xCABD, Hi: 0xCAD7, Stride: 1}, + {Lo: 0xCAD9, Hi: 0xCAF3, Stride: 1}, + {Lo: 0xCAF5, Hi: 0xCB0F, Stride: 1}, + {Lo: 0xCB11, Hi: 0xCB2B, Stride: 1}, + {Lo: 0xCB2D, Hi: 0xCB47, Stride: 1}, + {Lo: 0xCB49, Hi: 0xCB63, Stride: 1}, + {Lo: 0xCB65, Hi: 0xCB7F, Stride: 1}, + {Lo: 0xCB81, Hi: 0xCB9B, Stride: 1}, + {Lo: 0xCB9D, Hi: 0xCBB7, Stride: 1}, + {Lo: 0xCBB9, Hi: 0xCBD3, Stride: 1}, + {Lo: 0xCBD5, Hi: 0xCBEF, Stride: 1}, + {Lo: 0xCBF1, Hi: 0xCC0B, Stride: 1}, + {Lo: 0xCC0D, Hi: 0xCC27, Stride: 1}, + {Lo: 0xCC29, Hi: 0xCC43, Stride: 1}, + {Lo: 0xCC45, Hi: 0xCC5F, Stride: 1}, + {Lo: 0xCC61, Hi: 0xCC7B, Stride: 1}, + {Lo: 0xCC7D, Hi: 0xCC97, Stride: 1}, + {Lo: 0xCC99, Hi: 0xCCB3, Stride: 1}, + {Lo: 0xCCB5, Hi: 0xCCCF, Stride: 1}, + {Lo: 0xCCD1, Hi: 0xCCEB, Stride: 1}, + {Lo: 0xCCED, Hi: 0xCD07, Stride: 1}, + {Lo: 0xCD09, Hi: 0xCD23, Stride: 1}, + {Lo: 0xCD25, Hi: 0xCD3F, Stride: 1}, + {Lo: 0xCD41, Hi: 0xCD5B, Stride: 1}, + {Lo: 0xCD5D, Hi: 0xCD77, Stride: 1}, + {Lo: 0xCD79, Hi: 0xCD93, Stride: 1}, + {Lo: 0xCD95, Hi: 0xCDAF, Stride: 1}, + {Lo: 0xCDB1, Hi: 0xCDCB, Stride: 1}, + {Lo: 0xCDCD, Hi: 0xCDE7, Stride: 1}, + {Lo: 0xCDE9, Hi: 0xCE03, Stride: 1}, + {Lo: 0xCE05, Hi: 0xCE1F, Stride: 1}, + {Lo: 0xCE21, Hi: 0xCE3B, Stride: 1}, + {Lo: 0xCE3D, Hi: 0xCE57, Stride: 1}, + {Lo: 0xCE59, Hi: 0xCE73, Stride: 1}, + {Lo: 0xCE75, Hi: 0xCE8F, Stride: 1}, + {Lo: 0xCE91, Hi: 0xCEAB, Stride: 1}, + {Lo: 0xCEAD, Hi: 0xCEC7, Stride: 1}, + {Lo: 0xCEC9, Hi: 0xCEE3, Stride: 1}, + {Lo: 0xCEE5, Hi: 0xCEFF, Stride: 1}, + {Lo: 0xCF01, Hi: 0xCF1B, Stride: 1}, + {Lo: 0xCF1D, Hi: 0xCF37, Stride: 1}, + {Lo: 0xCF39, Hi: 0xCF53, Stride: 1}, + {Lo: 0xCF55, Hi: 0xCF6F, Stride: 1}, + {Lo: 0xCF71, Hi: 0xCF8B, Stride: 1}, + {Lo: 0xCF8D, Hi: 0xCFA7, Stride: 1}, + {Lo: 0xCFA9, Hi: 0xCFC3, Stride: 1}, + {Lo: 0xCFC5, Hi: 0xCFDF, Stride: 1}, + {Lo: 0xCFE1, Hi: 0xCFFB, Stride: 1}, + {Lo: 0xCFFD, Hi: 0xD017, Stride: 1}, + {Lo: 0xD019, Hi: 0xD033, Stride: 1}, + {Lo: 0xD035, Hi: 0xD04F, Stride: 1}, + {Lo: 0xD051, Hi: 0xD06B, Stride: 1}, + {Lo: 0xD06D, Hi: 0xD087, Stride: 1}, + {Lo: 0xD089, Hi: 0xD0A3, Stride: 1}, + {Lo: 0xD0A5, Hi: 0xD0BF, Stride: 1}, + {Lo: 0xD0C1, Hi: 0xD0DB, Stride: 1}, + {Lo: 0xD0DD, Hi: 0xD0F7, Stride: 1}, + {Lo: 0xD0F9, Hi: 0xD113, Stride: 1}, + {Lo: 0xD115, Hi: 0xD12F, Stride: 1}, + {Lo: 0xD131, Hi: 0xD14B, Stride: 1}, + {Lo: 0xD14D, Hi: 0xD167, Stride: 1}, + {Lo: 0xD169, Hi: 0xD183, Stride: 1}, + {Lo: 0xD185, Hi: 0xD19F, Stride: 1}, + {Lo: 0xD1A1, Hi: 0xD1BB, Stride: 1}, + {Lo: 0xD1BD, Hi: 0xD1D7, Stride: 1}, + {Lo: 0xD1D9, Hi: 0xD1F3, Stride: 1}, + {Lo: 0xD1F5, Hi: 0xD20F, Stride: 1}, + {Lo: 0xD211, Hi: 0xD22B, Stride: 1}, + {Lo: 0xD22D, Hi: 0xD247, Stride: 1}, + {Lo: 0xD249, Hi: 0xD263, Stride: 1}, + {Lo: 0xD265, Hi: 0xD27F, Stride: 1}, + {Lo: 0xD281, Hi: 0xD29B, Stride: 1}, + {Lo: 0xD29D, Hi: 0xD2B7, Stride: 1}, + {Lo: 0xD2B9, Hi: 0xD2D3, Stride: 1}, + {Lo: 0xD2D5, Hi: 0xD2EF, Stride: 1}, + {Lo: 0xD2F1, Hi: 0xD30B, Stride: 1}, + {Lo: 0xD30D, Hi: 0xD327, Stride: 1}, + {Lo: 0xD329, Hi: 0xD343, Stride: 1}, + {Lo: 0xD345, Hi: 0xD35F, Stride: 1}, + {Lo: 0xD361, Hi: 0xD37B, Stride: 1}, + {Lo: 0xD37D, Hi: 0xD397, Stride: 1}, + {Lo: 0xD399, Hi: 0xD3B3, Stride: 1}, + {Lo: 0xD3B5, Hi: 0xD3CF, Stride: 1}, + {Lo: 0xD3D1, Hi: 0xD3EB, Stride: 1}, + {Lo: 0xD3ED, Hi: 0xD407, Stride: 1}, + {Lo: 0xD409, Hi: 0xD423, Stride: 1}, + {Lo: 0xD425, Hi: 0xD43F, Stride: 1}, + {Lo: 0xD441, Hi: 0xD45B, Stride: 1}, + {Lo: 0xD45D, Hi: 0xD477, Stride: 1}, + {Lo: 0xD479, Hi: 0xD493, Stride: 1}, + {Lo: 0xD495, Hi: 0xD4AF, Stride: 1}, + {Lo: 0xD4B1, Hi: 0xD4CB, Stride: 1}, + {Lo: 0xD4CD, Hi: 0xD4E7, Stride: 1}, + {Lo: 0xD4E9, Hi: 0xD503, Stride: 1}, + {Lo: 0xD505, Hi: 0xD51F, Stride: 1}, + {Lo: 0xD521, Hi: 0xD53B, Stride: 1}, + {Lo: 0xD53D, Hi: 0xD557, Stride: 1}, + {Lo: 0xD559, Hi: 0xD573, Stride: 1}, + {Lo: 0xD575, Hi: 0xD58F, Stride: 1}, + {Lo: 0xD591, Hi: 0xD5AB, Stride: 1}, + {Lo: 0xD5AD, Hi: 0xD5C7, Stride: 1}, + {Lo: 0xD5C9, Hi: 0xD5E3, Stride: 1}, + {Lo: 0xD5E5, Hi: 0xD5FF, Stride: 1}, + {Lo: 0xD601, Hi: 0xD61B, Stride: 1}, + {Lo: 0xD61D, Hi: 0xD637, Stride: 1}, + {Lo: 0xD639, Hi: 0xD653, Stride: 1}, + {Lo: 0xD655, Hi: 0xD66F, Stride: 1}, + {Lo: 0xD671, Hi: 0xD68B, Stride: 1}, + {Lo: 0xD68D, Hi: 0xD6A7, Stride: 1}, + {Lo: 0xD6A9, Hi: 0xD6C3, Stride: 1}, + {Lo: 0xD6C5, Hi: 0xD6DF, Stride: 1}, + {Lo: 0xD6E1, Hi: 0xD6FB, Stride: 1}, + {Lo: 0xD6FD, Hi: 0xD717, Stride: 1}, + {Lo: 0xD719, Hi: 0xD733, Stride: 1}, + {Lo: 0xD735, Hi: 0xD74F, Stride: 1}, + {Lo: 0xD751, Hi: 0xD76B, Stride: 1}, + {Lo: 0xD76D, Hi: 0xD787, Stride: 1}, + {Lo: 0xD789, Hi: 0xD7A3, Stride: 1}, + }, +} + +var unicodeAliasGrapheme_Cluster_Break_Prepend = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0x600, Hi: 0x605, Stride: 1}, + {Lo: 0x6DD, Hi: 0x6DD, Stride: 1}, + {Lo: 0x70F, Hi: 0x70F, Stride: 1}, + {Lo: 0x890, Hi: 0x891, Stride: 1}, + {Lo: 0x8E2, Hi: 0x8E2, Stride: 1}, + {Lo: 0xD4E, Hi: 0xD4E, Stride: 1}, + }, + R32: []unicode.Range32{ + {Lo: 0x110BD, Hi: 0x110BD, Stride: 1}, + {Lo: 0x110CD, Hi: 0x110CD, Stride: 1}, + {Lo: 0x111C2, Hi: 0x111C3, Stride: 1}, + {Lo: 0x113D1, Hi: 0x113D1, Stride: 1}, + {Lo: 0x1193F, Hi: 0x1193F, Stride: 1}, + {Lo: 0x11941, Hi: 0x11941, Stride: 1}, + {Lo: 0x11A84, Hi: 0x11A89, Stride: 1}, + {Lo: 0x11D46, Hi: 0x11D46, Stride: 1}, + {Lo: 0x11F02, Hi: 0x11F02, Stride: 1}, + }, +} + +var unicodeAliasGrapheme_Cluster_Break_Regional_Indicator = &unicode.RangeTable{ + R32: []unicode.Range32{ + {Lo: 0x1F1E6, Hi: 0x1F1FF, Stride: 1}, + }, +} + +var unicodeAliasGrapheme_Cluster_Break_SpacingMark = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0x903, Hi: 0x903, Stride: 1}, + {Lo: 0x93B, Hi: 0x93B, Stride: 1}, + {Lo: 0x93E, Hi: 0x940, Stride: 1}, + {Lo: 0x949, Hi: 0x94C, Stride: 1}, + {Lo: 0x94E, Hi: 0x94F, Stride: 1}, + {Lo: 0x982, Hi: 0x983, Stride: 1}, + {Lo: 0x9BF, Hi: 0x9C0, Stride: 1}, + {Lo: 0x9C7, Hi: 0x9C8, Stride: 1}, + {Lo: 0x9CB, Hi: 0x9CC, Stride: 1}, + {Lo: 0xA03, Hi: 0xA03, Stride: 1}, + {Lo: 0xA3E, Hi: 0xA40, Stride: 1}, + {Lo: 0xA83, Hi: 0xA83, Stride: 1}, + {Lo: 0xABE, Hi: 0xAC0, Stride: 1}, + {Lo: 0xAC9, Hi: 0xAC9, Stride: 1}, + {Lo: 0xACB, Hi: 0xACC, Stride: 1}, + {Lo: 0xB02, Hi: 0xB03, Stride: 1}, + {Lo: 0xB40, Hi: 0xB40, Stride: 1}, + {Lo: 0xB47, Hi: 0xB48, Stride: 1}, + {Lo: 0xB4B, Hi: 0xB4C, Stride: 1}, + {Lo: 0xBBF, Hi: 0xBBF, Stride: 1}, + {Lo: 0xBC1, Hi: 0xBC2, Stride: 1}, + {Lo: 0xBC6, Hi: 0xBC8, Stride: 1}, + {Lo: 0xBCA, Hi: 0xBCC, Stride: 1}, + {Lo: 0xC01, Hi: 0xC03, Stride: 1}, + {Lo: 0xC41, Hi: 0xC44, Stride: 1}, + {Lo: 0xC82, Hi: 0xC83, Stride: 1}, + {Lo: 0xCBE, Hi: 0xCBE, Stride: 1}, + {Lo: 0xCC1, Hi: 0xCC1, Stride: 1}, + {Lo: 0xCC3, Hi: 0xCC4, Stride: 1}, + {Lo: 0xCF3, Hi: 0xCF3, Stride: 1}, + {Lo: 0xD02, Hi: 0xD03, Stride: 1}, + {Lo: 0xD3F, Hi: 0xD40, Stride: 1}, + {Lo: 0xD46, Hi: 0xD48, Stride: 1}, + {Lo: 0xD4A, Hi: 0xD4C, Stride: 1}, + {Lo: 0xD82, Hi: 0xD83, Stride: 1}, + {Lo: 0xDD0, Hi: 0xDD1, Stride: 1}, + {Lo: 0xDD8, Hi: 0xDDE, Stride: 1}, + {Lo: 0xDF2, Hi: 0xDF3, Stride: 1}, + {Lo: 0xE33, Hi: 0xE33, Stride: 1}, + {Lo: 0xEB3, Hi: 0xEB3, Stride: 1}, + {Lo: 0xF3E, Hi: 0xF3F, Stride: 1}, + {Lo: 0xF7F, Hi: 0xF7F, Stride: 1}, + {Lo: 0x1031, Hi: 0x1031, Stride: 1}, + {Lo: 0x103B, Hi: 0x103C, Stride: 1}, + {Lo: 0x1056, Hi: 0x1057, Stride: 1}, + {Lo: 0x1084, Hi: 0x1084, Stride: 1}, + {Lo: 0x17B6, Hi: 0x17B6, Stride: 1}, + {Lo: 0x17BE, Hi: 0x17C5, Stride: 1}, + {Lo: 0x17C7, Hi: 0x17C8, Stride: 1}, + {Lo: 0x1923, Hi: 0x1926, Stride: 1}, + {Lo: 0x1929, Hi: 0x192B, Stride: 1}, + {Lo: 0x1930, Hi: 0x1931, Stride: 1}, + {Lo: 0x1933, Hi: 0x1938, Stride: 1}, + {Lo: 0x1A19, Hi: 0x1A1A, Stride: 1}, + {Lo: 0x1A55, Hi: 0x1A55, Stride: 1}, + {Lo: 0x1A57, Hi: 0x1A57, Stride: 1}, + {Lo: 0x1A6D, Hi: 0x1A72, Stride: 1}, + {Lo: 0x1B04, Hi: 0x1B04, Stride: 1}, + {Lo: 0x1B3E, Hi: 0x1B41, Stride: 1}, + {Lo: 0x1B82, Hi: 0x1B82, Stride: 1}, + {Lo: 0x1BA1, Hi: 0x1BA1, Stride: 1}, + {Lo: 0x1BA6, Hi: 0x1BA7, Stride: 1}, + {Lo: 0x1BE7, Hi: 0x1BE7, Stride: 1}, + {Lo: 0x1BEA, Hi: 0x1BEC, Stride: 1}, + {Lo: 0x1BEE, Hi: 0x1BEE, Stride: 1}, + {Lo: 0x1C24, Hi: 0x1C2B, Stride: 1}, + {Lo: 0x1C34, Hi: 0x1C35, Stride: 1}, + {Lo: 0x1CE1, Hi: 0x1CE1, Stride: 1}, + {Lo: 0x1CF7, Hi: 0x1CF7, Stride: 1}, + {Lo: 0xA823, Hi: 0xA824, Stride: 1}, + {Lo: 0xA827, Hi: 0xA827, Stride: 1}, + {Lo: 0xA880, Hi: 0xA881, Stride: 1}, + {Lo: 0xA8B4, Hi: 0xA8C3, Stride: 1}, + {Lo: 0xA952, Hi: 0xA952, Stride: 1}, + {Lo: 0xA983, Hi: 0xA983, Stride: 1}, + {Lo: 0xA9B4, Hi: 0xA9B5, Stride: 1}, + {Lo: 0xA9BA, Hi: 0xA9BB, Stride: 1}, + {Lo: 0xA9BE, Hi: 0xA9BF, Stride: 1}, + {Lo: 0xAA2F, Hi: 0xAA30, Stride: 1}, + {Lo: 0xAA33, Hi: 0xAA34, Stride: 1}, + {Lo: 0xAA4D, Hi: 0xAA4D, Stride: 1}, + {Lo: 0xAAEB, Hi: 0xAAEB, Stride: 1}, + {Lo: 0xAAEE, Hi: 0xAAEF, Stride: 1}, + {Lo: 0xAAF5, Hi: 0xAAF5, Stride: 1}, + {Lo: 0xABE3, Hi: 0xABE4, Stride: 1}, + {Lo: 0xABE6, Hi: 0xABE7, Stride: 1}, + {Lo: 0xABE9, Hi: 0xABEA, Stride: 1}, + {Lo: 0xABEC, Hi: 0xABEC, Stride: 1}, + }, + R32: []unicode.Range32{ + {Lo: 0x11000, Hi: 0x11000, Stride: 1}, + {Lo: 0x11002, Hi: 0x11002, Stride: 1}, + {Lo: 0x11082, Hi: 0x11082, Stride: 1}, + {Lo: 0x110B0, Hi: 0x110B2, Stride: 1}, + {Lo: 0x110B7, Hi: 0x110B8, Stride: 1}, + {Lo: 0x1112C, Hi: 0x1112C, Stride: 1}, + {Lo: 0x11145, Hi: 0x11146, Stride: 1}, + {Lo: 0x11182, Hi: 0x11182, Stride: 1}, + {Lo: 0x111B3, Hi: 0x111B5, Stride: 1}, + {Lo: 0x111BF, Hi: 0x111BF, Stride: 1}, + {Lo: 0x111CE, Hi: 0x111CE, Stride: 1}, + {Lo: 0x1122C, Hi: 0x1122E, Stride: 1}, + {Lo: 0x11232, Hi: 0x11233, Stride: 1}, + {Lo: 0x112E0, Hi: 0x112E2, Stride: 1}, + {Lo: 0x11302, Hi: 0x11303, Stride: 1}, + {Lo: 0x1133F, Hi: 0x1133F, Stride: 1}, + {Lo: 0x11341, Hi: 0x11344, Stride: 1}, + {Lo: 0x11347, Hi: 0x11348, Stride: 1}, + {Lo: 0x1134B, Hi: 0x1134C, Stride: 1}, + {Lo: 0x11362, Hi: 0x11363, Stride: 1}, + {Lo: 0x113B9, Hi: 0x113BA, Stride: 1}, + {Lo: 0x113CA, Hi: 0x113CA, Stride: 1}, + {Lo: 0x113CC, Hi: 0x113CD, Stride: 1}, + {Lo: 0x11435, Hi: 0x11437, Stride: 1}, + {Lo: 0x11440, Hi: 0x11441, Stride: 1}, + {Lo: 0x11445, Hi: 0x11445, Stride: 1}, + {Lo: 0x114B1, Hi: 0x114B2, Stride: 1}, + {Lo: 0x114B9, Hi: 0x114B9, Stride: 1}, + {Lo: 0x114BB, Hi: 0x114BC, Stride: 1}, + {Lo: 0x114BE, Hi: 0x114BE, Stride: 1}, + {Lo: 0x114C1, Hi: 0x114C1, Stride: 1}, + {Lo: 0x115B0, Hi: 0x115B1, Stride: 1}, + {Lo: 0x115B8, Hi: 0x115BB, Stride: 1}, + {Lo: 0x115BE, Hi: 0x115BE, Stride: 1}, + {Lo: 0x11630, Hi: 0x11632, Stride: 1}, + {Lo: 0x1163B, Hi: 0x1163C, Stride: 1}, + {Lo: 0x1163E, Hi: 0x1163E, Stride: 1}, + {Lo: 0x116AC, Hi: 0x116AC, Stride: 1}, + {Lo: 0x116AE, Hi: 0x116AF, Stride: 1}, + {Lo: 0x1171E, Hi: 0x1171E, Stride: 1}, + {Lo: 0x11726, Hi: 0x11726, Stride: 1}, + {Lo: 0x1182C, Hi: 0x1182E, Stride: 1}, + {Lo: 0x11838, Hi: 0x11838, Stride: 1}, + {Lo: 0x11931, Hi: 0x11935, Stride: 1}, + {Lo: 0x11937, Hi: 0x11938, Stride: 1}, + {Lo: 0x11940, Hi: 0x11940, Stride: 1}, + {Lo: 0x11942, Hi: 0x11942, Stride: 1}, + {Lo: 0x119D1, Hi: 0x119D3, Stride: 1}, + {Lo: 0x119DC, Hi: 0x119DF, Stride: 1}, + {Lo: 0x119E4, Hi: 0x119E4, Stride: 1}, + {Lo: 0x11A39, Hi: 0x11A39, Stride: 1}, + {Lo: 0x11A57, Hi: 0x11A58, Stride: 1}, + {Lo: 0x11A97, Hi: 0x11A97, Stride: 1}, + {Lo: 0x11B61, Hi: 0x11B61, Stride: 1}, + {Lo: 0x11B65, Hi: 0x11B65, Stride: 1}, + {Lo: 0x11B67, Hi: 0x11B67, Stride: 1}, + {Lo: 0x11C2F, Hi: 0x11C2F, Stride: 1}, + {Lo: 0x11C3E, Hi: 0x11C3E, Stride: 1}, + {Lo: 0x11CA9, Hi: 0x11CA9, Stride: 1}, + {Lo: 0x11CB1, Hi: 0x11CB1, Stride: 1}, + {Lo: 0x11CB4, Hi: 0x11CB4, Stride: 1}, + {Lo: 0x11D8A, Hi: 0x11D8E, Stride: 1}, + {Lo: 0x11D93, Hi: 0x11D94, Stride: 1}, + {Lo: 0x11D96, Hi: 0x11D96, Stride: 1}, + {Lo: 0x11EF5, Hi: 0x11EF6, Stride: 1}, + {Lo: 0x11F03, Hi: 0x11F03, Stride: 1}, + {Lo: 0x11F34, Hi: 0x11F35, Stride: 1}, + {Lo: 0x11F3E, Hi: 0x11F3F, Stride: 1}, + {Lo: 0x1612A, Hi: 0x1612C, Stride: 1}, + {Lo: 0x16F51, Hi: 0x16F87, Stride: 1}, + }, +} + +var unicodeAliasGrapheme_Cluster_Break_T = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0x11A8, Hi: 0x11FF, Stride: 1}, + {Lo: 0xD7CB, Hi: 0xD7FB, Stride: 1}, + }, +} + +var unicodeAliasGrapheme_Cluster_Break_V = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0x1160, Hi: 0x11A7, Stride: 1}, + {Lo: 0xD7B0, Hi: 0xD7C6, Stride: 1}, + }, + R32: []unicode.Range32{ + {Lo: 0x16D63, Hi: 0x16D63, Stride: 1}, + {Lo: 0x16D67, Hi: 0x16D6A, Stride: 1}, + }, +} + +var unicodeAliasGrapheme_Cluster_Break_ZWJ = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0x200D, Hi: 0x200D, Stride: 1}, + }, +} + +var unicodeAliasMath = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0x2B, Hi: 0x2B, Stride: 1}, + {Lo: 0x3C, Hi: 0x3E, Stride: 1}, + {Lo: 0x5E, Hi: 0x5E, Stride: 1}, + {Lo: 0x7C, Hi: 0x7C, Stride: 1}, + {Lo: 0x7E, Hi: 0x7E, Stride: 1}, + {Lo: 0xAC, Hi: 0xAC, Stride: 1}, + {Lo: 0xB1, Hi: 0xB1, Stride: 1}, + {Lo: 0xD7, Hi: 0xD7, Stride: 1}, + {Lo: 0xF7, Hi: 0xF7, Stride: 1}, + {Lo: 0x3D0, Hi: 0x3D2, Stride: 1}, + {Lo: 0x3D5, Hi: 0x3D5, Stride: 1}, + {Lo: 0x3F0, Hi: 0x3F1, Stride: 1}, + {Lo: 0x3F4, Hi: 0x3F6, Stride: 1}, + {Lo: 0x606, Hi: 0x608, Stride: 1}, + {Lo: 0x2016, Hi: 0x2016, Stride: 1}, + {Lo: 0x2032, Hi: 0x2034, Stride: 1}, + {Lo: 0x2040, Hi: 0x2040, Stride: 1}, + {Lo: 0x2044, Hi: 0x2044, Stride: 1}, + {Lo: 0x2052, Hi: 0x2052, Stride: 1}, + {Lo: 0x2061, Hi: 0x2064, Stride: 1}, + {Lo: 0x207A, Hi: 0x207E, Stride: 1}, + {Lo: 0x208A, Hi: 0x208E, Stride: 1}, + {Lo: 0x20D0, Hi: 0x20DC, Stride: 1}, + {Lo: 0x20E1, Hi: 0x20E1, Stride: 1}, + {Lo: 0x20E5, Hi: 0x20E6, Stride: 1}, + {Lo: 0x20EB, Hi: 0x20EF, Stride: 1}, + {Lo: 0x2102, Hi: 0x2102, Stride: 1}, + {Lo: 0x2107, Hi: 0x2107, Stride: 1}, + {Lo: 0x210A, Hi: 0x2113, Stride: 1}, + {Lo: 0x2115, Hi: 0x2115, Stride: 1}, + {Lo: 0x2118, Hi: 0x211D, Stride: 1}, + {Lo: 0x2124, Hi: 0x2124, Stride: 1}, + {Lo: 0x2128, Hi: 0x2129, Stride: 1}, + {Lo: 0x212C, Hi: 0x212D, Stride: 1}, + {Lo: 0x212F, Hi: 0x2131, Stride: 1}, + {Lo: 0x2133, Hi: 0x2138, Stride: 1}, + {Lo: 0x213C, Hi: 0x2149, Stride: 1}, + {Lo: 0x214B, Hi: 0x214B, Stride: 1}, + {Lo: 0x2190, Hi: 0x21A7, Stride: 1}, + {Lo: 0x21A9, Hi: 0x21AE, Stride: 1}, + {Lo: 0x21B0, Hi: 0x21B1, Stride: 1}, + {Lo: 0x21B6, Hi: 0x21B7, Stride: 1}, + {Lo: 0x21BC, Hi: 0x21DB, Stride: 1}, + {Lo: 0x21DD, Hi: 0x21DD, Stride: 1}, + {Lo: 0x21E4, Hi: 0x21E5, Stride: 1}, + {Lo: 0x21F4, Hi: 0x22FF, Stride: 1}, + {Lo: 0x2308, Hi: 0x230B, Stride: 1}, + {Lo: 0x2320, Hi: 0x2321, Stride: 1}, + {Lo: 0x237C, Hi: 0x237C, Stride: 1}, + {Lo: 0x239B, Hi: 0x23B5, Stride: 1}, + {Lo: 0x23B7, Hi: 0x23B7, Stride: 1}, + {Lo: 0x23D0, Hi: 0x23D0, Stride: 1}, + {Lo: 0x23DC, Hi: 0x23E2, Stride: 1}, + {Lo: 0x25A0, Hi: 0x25A1, Stride: 1}, + {Lo: 0x25AE, Hi: 0x25B7, Stride: 1}, + {Lo: 0x25BC, Hi: 0x25C1, Stride: 1}, + {Lo: 0x25C6, Hi: 0x25C7, Stride: 1}, + {Lo: 0x25CA, Hi: 0x25CB, Stride: 1}, + {Lo: 0x25CF, Hi: 0x25D3, Stride: 1}, + {Lo: 0x25E2, Hi: 0x25E2, Stride: 1}, + {Lo: 0x25E4, Hi: 0x25E4, Stride: 1}, + {Lo: 0x25E7, Hi: 0x25EC, Stride: 1}, + {Lo: 0x25F8, Hi: 0x25FF, Stride: 1}, + {Lo: 0x2605, Hi: 0x2606, Stride: 1}, + {Lo: 0x2640, Hi: 0x2640, Stride: 1}, + {Lo: 0x2642, Hi: 0x2642, Stride: 1}, + {Lo: 0x2660, Hi: 0x2663, Stride: 1}, + {Lo: 0x266D, Hi: 0x266F, Stride: 1}, + {Lo: 0x27C0, Hi: 0x27FF, Stride: 1}, + {Lo: 0x2900, Hi: 0x2AFF, Stride: 1}, + {Lo: 0x2B30, Hi: 0x2B44, Stride: 1}, + {Lo: 0x2B47, Hi: 0x2B4C, Stride: 1}, + {Lo: 0xFB29, Hi: 0xFB29, Stride: 1}, + {Lo: 0xFE61, Hi: 0xFE66, Stride: 1}, + {Lo: 0xFE68, Hi: 0xFE68, Stride: 1}, + {Lo: 0xFF0B, Hi: 0xFF0B, Stride: 1}, + {Lo: 0xFF1C, Hi: 0xFF1E, Stride: 1}, + {Lo: 0xFF3C, Hi: 0xFF3C, Stride: 1}, + {Lo: 0xFF3E, Hi: 0xFF3E, Stride: 1}, + {Lo: 0xFF5C, Hi: 0xFF5C, Stride: 1}, + {Lo: 0xFF5E, Hi: 0xFF5E, Stride: 1}, + {Lo: 0xFFE2, Hi: 0xFFE2, Stride: 1}, + {Lo: 0xFFE9, Hi: 0xFFEC, Stride: 1}, + }, + R32: []unicode.Range32{ + {Lo: 0x10D8E, Hi: 0x10D8F, Stride: 1}, + {Lo: 0x1CEF0, Hi: 0x1CEF0, Stride: 1}, + {Lo: 0x1D400, Hi: 0x1D454, Stride: 1}, + {Lo: 0x1D456, Hi: 0x1D49C, Stride: 1}, + {Lo: 0x1D49E, Hi: 0x1D49F, Stride: 1}, + {Lo: 0x1D4A2, Hi: 0x1D4A2, Stride: 1}, + {Lo: 0x1D4A5, Hi: 0x1D4A6, Stride: 1}, + {Lo: 0x1D4A9, Hi: 0x1D4AC, Stride: 1}, + {Lo: 0x1D4AE, Hi: 0x1D4B9, Stride: 1}, + {Lo: 0x1D4BB, Hi: 0x1D4BB, Stride: 1}, + {Lo: 0x1D4BD, Hi: 0x1D4C3, Stride: 1}, + {Lo: 0x1D4C5, Hi: 0x1D505, Stride: 1}, + {Lo: 0x1D507, Hi: 0x1D50A, Stride: 1}, + {Lo: 0x1D50D, Hi: 0x1D514, Stride: 1}, + {Lo: 0x1D516, Hi: 0x1D51C, Stride: 1}, + {Lo: 0x1D51E, Hi: 0x1D539, Stride: 1}, + {Lo: 0x1D53B, Hi: 0x1D53E, Stride: 1}, + {Lo: 0x1D540, Hi: 0x1D544, Stride: 1}, + {Lo: 0x1D546, Hi: 0x1D546, Stride: 1}, + {Lo: 0x1D54A, Hi: 0x1D550, Stride: 1}, + {Lo: 0x1D552, Hi: 0x1D6A5, Stride: 1}, + {Lo: 0x1D6A8, Hi: 0x1D7CB, Stride: 1}, + {Lo: 0x1D7CE, Hi: 0x1D7FF, Stride: 1}, + {Lo: 0x1EE00, Hi: 0x1EE03, Stride: 1}, + {Lo: 0x1EE05, Hi: 0x1EE1F, Stride: 1}, + {Lo: 0x1EE21, Hi: 0x1EE22, Stride: 1}, + {Lo: 0x1EE24, Hi: 0x1EE24, Stride: 1}, + {Lo: 0x1EE27, Hi: 0x1EE27, Stride: 1}, + {Lo: 0x1EE29, Hi: 0x1EE32, Stride: 1}, + {Lo: 0x1EE34, Hi: 0x1EE37, Stride: 1}, + {Lo: 0x1EE39, Hi: 0x1EE39, Stride: 1}, + {Lo: 0x1EE3B, Hi: 0x1EE3B, Stride: 1}, + {Lo: 0x1EE42, Hi: 0x1EE42, Stride: 1}, + {Lo: 0x1EE47, Hi: 0x1EE47, Stride: 1}, + {Lo: 0x1EE49, Hi: 0x1EE49, Stride: 1}, + {Lo: 0x1EE4B, Hi: 0x1EE4B, Stride: 1}, + {Lo: 0x1EE4D, Hi: 0x1EE4F, Stride: 1}, + {Lo: 0x1EE51, Hi: 0x1EE52, Stride: 1}, + {Lo: 0x1EE54, Hi: 0x1EE54, Stride: 1}, + {Lo: 0x1EE57, Hi: 0x1EE57, Stride: 1}, + {Lo: 0x1EE59, Hi: 0x1EE59, Stride: 1}, + {Lo: 0x1EE5B, Hi: 0x1EE5B, Stride: 1}, + {Lo: 0x1EE5D, Hi: 0x1EE5D, Stride: 1}, + {Lo: 0x1EE5F, Hi: 0x1EE5F, Stride: 1}, + {Lo: 0x1EE61, Hi: 0x1EE62, Stride: 1}, + {Lo: 0x1EE64, Hi: 0x1EE64, Stride: 1}, + {Lo: 0x1EE67, Hi: 0x1EE6A, Stride: 1}, + {Lo: 0x1EE6C, Hi: 0x1EE72, Stride: 1}, + {Lo: 0x1EE74, Hi: 0x1EE77, Stride: 1}, + {Lo: 0x1EE79, Hi: 0x1EE7C, Stride: 1}, + {Lo: 0x1EE7E, Hi: 0x1EE7E, Stride: 1}, + {Lo: 0x1EE80, Hi: 0x1EE89, Stride: 1}, + {Lo: 0x1EE8B, Hi: 0x1EE9B, Stride: 1}, + {Lo: 0x1EEA1, Hi: 0x1EEA3, Stride: 1}, + {Lo: 0x1EEA5, Hi: 0x1EEA9, Stride: 1}, + {Lo: 0x1EEAB, Hi: 0x1EEBB, Stride: 1}, + {Lo: 0x1EEF0, Hi: 0x1EEF1, Stride: 1}, + {Lo: 0x1F8D0, Hi: 0x1F8D8, Stride: 1}, + }, +} + +var unicodeAliasSentence_Break_ATerm = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0x2E, Hi: 0x2E, Stride: 1}, + {Lo: 0x2024, Hi: 0x2024, Stride: 1}, + {Lo: 0xFE52, Hi: 0xFE52, Stride: 1}, + {Lo: 0xFF0E, Hi: 0xFF0E, Stride: 1}, + }, +} + +var unicodeAliasSentence_Break_CR = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0xD, Hi: 0xD, Stride: 1}, + }, +} + +var unicodeAliasSentence_Break_Close = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0x22, Hi: 0x22, Stride: 1}, + {Lo: 0x27, Hi: 0x29, Stride: 1}, + {Lo: 0x5B, Hi: 0x5B, Stride: 1}, + {Lo: 0x5D, Hi: 0x5D, Stride: 1}, + {Lo: 0x7B, Hi: 0x7B, Stride: 1}, + {Lo: 0x7D, Hi: 0x7D, Stride: 1}, + {Lo: 0xAB, Hi: 0xAB, Stride: 1}, + {Lo: 0xBB, Hi: 0xBB, Stride: 1}, + {Lo: 0xF3A, Hi: 0xF3D, Stride: 1}, + {Lo: 0x169B, Hi: 0x169C, Stride: 1}, + {Lo: 0x2018, Hi: 0x201F, Stride: 1}, + {Lo: 0x2039, Hi: 0x203A, Stride: 1}, + {Lo: 0x2045, Hi: 0x2046, Stride: 1}, + {Lo: 0x207D, Hi: 0x207E, Stride: 1}, + {Lo: 0x208D, Hi: 0x208E, Stride: 1}, + {Lo: 0x2308, Hi: 0x230B, Stride: 1}, + {Lo: 0x2329, Hi: 0x232A, Stride: 1}, + {Lo: 0x275B, Hi: 0x2760, Stride: 1}, + {Lo: 0x2768, Hi: 0x2775, Stride: 1}, + {Lo: 0x27C5, Hi: 0x27C6, Stride: 1}, + {Lo: 0x27E6, Hi: 0x27EF, Stride: 1}, + {Lo: 0x2983, Hi: 0x2998, Stride: 1}, + {Lo: 0x29D8, Hi: 0x29DB, Stride: 1}, + {Lo: 0x29FC, Hi: 0x29FD, Stride: 1}, + {Lo: 0x2E00, Hi: 0x2E0D, Stride: 1}, + {Lo: 0x2E1C, Hi: 0x2E1D, Stride: 1}, + {Lo: 0x2E20, Hi: 0x2E29, Stride: 1}, + {Lo: 0x2E42, Hi: 0x2E42, Stride: 1}, + {Lo: 0x2E55, Hi: 0x2E5C, Stride: 1}, + {Lo: 0x3008, Hi: 0x3011, Stride: 1}, + {Lo: 0x3014, Hi: 0x301B, Stride: 1}, + {Lo: 0x301D, Hi: 0x301F, Stride: 1}, + {Lo: 0xFD3E, Hi: 0xFD3F, Stride: 1}, + {Lo: 0xFE17, Hi: 0xFE18, Stride: 1}, + {Lo: 0xFE35, Hi: 0xFE44, Stride: 1}, + {Lo: 0xFE47, Hi: 0xFE48, Stride: 1}, + {Lo: 0xFE59, Hi: 0xFE5E, Stride: 1}, + {Lo: 0xFF08, Hi: 0xFF09, Stride: 1}, + {Lo: 0xFF3B, Hi: 0xFF3B, Stride: 1}, + {Lo: 0xFF3D, Hi: 0xFF3D, Stride: 1}, + {Lo: 0xFF5B, Hi: 0xFF5B, Stride: 1}, + {Lo: 0xFF5D, Hi: 0xFF5D, Stride: 1}, + {Lo: 0xFF5F, Hi: 0xFF60, Stride: 1}, + {Lo: 0xFF62, Hi: 0xFF63, Stride: 1}, + }, + R32: []unicode.Range32{ + {Lo: 0x1F676, Hi: 0x1F678, Stride: 1}, + }, +} + +var unicodeAliasSentence_Break_Extend = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0x300, Hi: 0x36F, Stride: 1}, + {Lo: 0x483, Hi: 0x489, Stride: 1}, + {Lo: 0x591, Hi: 0x5BD, Stride: 1}, + {Lo: 0x5BF, Hi: 0x5BF, Stride: 1}, + {Lo: 0x5C1, Hi: 0x5C2, Stride: 1}, + {Lo: 0x5C4, Hi: 0x5C5, Stride: 1}, + {Lo: 0x5C7, Hi: 0x5C7, Stride: 1}, + {Lo: 0x610, Hi: 0x61A, Stride: 1}, + {Lo: 0x64B, Hi: 0x65F, Stride: 1}, + {Lo: 0x670, Hi: 0x670, Stride: 1}, + {Lo: 0x6D6, Hi: 0x6DC, Stride: 1}, + {Lo: 0x6DF, Hi: 0x6E4, Stride: 1}, + {Lo: 0x6E7, Hi: 0x6E8, Stride: 1}, + {Lo: 0x6EA, Hi: 0x6ED, Stride: 1}, + {Lo: 0x711, Hi: 0x711, Stride: 1}, + {Lo: 0x730, Hi: 0x74A, Stride: 1}, + {Lo: 0x7A6, Hi: 0x7B0, Stride: 1}, + {Lo: 0x7EB, Hi: 0x7F3, Stride: 1}, + {Lo: 0x7FD, Hi: 0x7FD, Stride: 1}, + {Lo: 0x816, Hi: 0x819, Stride: 1}, + {Lo: 0x81B, Hi: 0x823, Stride: 1}, + {Lo: 0x825, Hi: 0x827, Stride: 1}, + {Lo: 0x829, Hi: 0x82D, Stride: 1}, + {Lo: 0x859, Hi: 0x85B, Stride: 1}, + {Lo: 0x897, Hi: 0x89F, Stride: 1}, + {Lo: 0x8CA, Hi: 0x8E1, Stride: 1}, + {Lo: 0x8E3, Hi: 0x903, Stride: 1}, + {Lo: 0x93A, Hi: 0x93C, Stride: 1}, + {Lo: 0x93E, Hi: 0x94F, Stride: 1}, + {Lo: 0x951, Hi: 0x957, Stride: 1}, + {Lo: 0x962, Hi: 0x963, Stride: 1}, + {Lo: 0x981, Hi: 0x983, Stride: 1}, + {Lo: 0x9BC, Hi: 0x9BC, Stride: 1}, + {Lo: 0x9BE, Hi: 0x9C4, Stride: 1}, + {Lo: 0x9C7, Hi: 0x9C8, Stride: 1}, + {Lo: 0x9CB, Hi: 0x9CD, Stride: 1}, + {Lo: 0x9D7, Hi: 0x9D7, Stride: 1}, + {Lo: 0x9E2, Hi: 0x9E3, Stride: 1}, + {Lo: 0x9FE, Hi: 0x9FE, Stride: 1}, + {Lo: 0xA01, Hi: 0xA03, Stride: 1}, + {Lo: 0xA3C, Hi: 0xA3C, Stride: 1}, + {Lo: 0xA3E, Hi: 0xA42, Stride: 1}, + {Lo: 0xA47, Hi: 0xA48, Stride: 1}, + {Lo: 0xA4B, Hi: 0xA4D, Stride: 1}, + {Lo: 0xA51, Hi: 0xA51, Stride: 1}, + {Lo: 0xA70, Hi: 0xA71, Stride: 1}, + {Lo: 0xA75, Hi: 0xA75, Stride: 1}, + {Lo: 0xA81, Hi: 0xA83, Stride: 1}, + {Lo: 0xABC, Hi: 0xABC, Stride: 1}, + {Lo: 0xABE, Hi: 0xAC5, Stride: 1}, + {Lo: 0xAC7, Hi: 0xAC9, Stride: 1}, + {Lo: 0xACB, Hi: 0xACD, Stride: 1}, + {Lo: 0xAE2, Hi: 0xAE3, Stride: 1}, + {Lo: 0xAFA, Hi: 0xAFF, Stride: 1}, + {Lo: 0xB01, Hi: 0xB03, Stride: 1}, + {Lo: 0xB3C, Hi: 0xB3C, Stride: 1}, + {Lo: 0xB3E, Hi: 0xB44, Stride: 1}, + {Lo: 0xB47, Hi: 0xB48, Stride: 1}, + {Lo: 0xB4B, Hi: 0xB4D, Stride: 1}, + {Lo: 0xB55, Hi: 0xB57, Stride: 1}, + {Lo: 0xB62, Hi: 0xB63, Stride: 1}, + {Lo: 0xB82, Hi: 0xB82, Stride: 1}, + {Lo: 0xBBE, Hi: 0xBC2, Stride: 1}, + {Lo: 0xBC6, Hi: 0xBC8, Stride: 1}, + {Lo: 0xBCA, Hi: 0xBCD, Stride: 1}, + {Lo: 0xBD7, Hi: 0xBD7, Stride: 1}, + {Lo: 0xC00, Hi: 0xC04, Stride: 1}, + {Lo: 0xC3C, Hi: 0xC3C, Stride: 1}, + {Lo: 0xC3E, Hi: 0xC44, Stride: 1}, + {Lo: 0xC46, Hi: 0xC48, Stride: 1}, + {Lo: 0xC4A, Hi: 0xC4D, Stride: 1}, + {Lo: 0xC55, Hi: 0xC56, Stride: 1}, + {Lo: 0xC62, Hi: 0xC63, Stride: 1}, + {Lo: 0xC81, Hi: 0xC83, Stride: 1}, + {Lo: 0xCBC, Hi: 0xCBC, Stride: 1}, + {Lo: 0xCBE, Hi: 0xCC4, Stride: 1}, + {Lo: 0xCC6, Hi: 0xCC8, Stride: 1}, + {Lo: 0xCCA, Hi: 0xCCD, Stride: 1}, + {Lo: 0xCD5, Hi: 0xCD6, Stride: 1}, + {Lo: 0xCE2, Hi: 0xCE3, Stride: 1}, + {Lo: 0xCF3, Hi: 0xCF3, Stride: 1}, + {Lo: 0xD00, Hi: 0xD03, Stride: 1}, + {Lo: 0xD3B, Hi: 0xD3C, Stride: 1}, + {Lo: 0xD3E, Hi: 0xD44, Stride: 1}, + {Lo: 0xD46, Hi: 0xD48, Stride: 1}, + {Lo: 0xD4A, Hi: 0xD4D, Stride: 1}, + {Lo: 0xD57, Hi: 0xD57, Stride: 1}, + {Lo: 0xD62, Hi: 0xD63, Stride: 1}, + {Lo: 0xD81, Hi: 0xD83, Stride: 1}, + {Lo: 0xDCA, Hi: 0xDCA, Stride: 1}, + {Lo: 0xDCF, Hi: 0xDD4, Stride: 1}, + {Lo: 0xDD6, Hi: 0xDD6, Stride: 1}, + {Lo: 0xDD8, Hi: 0xDDF, Stride: 1}, + {Lo: 0xDF2, Hi: 0xDF3, Stride: 1}, + {Lo: 0xE31, Hi: 0xE31, Stride: 1}, + {Lo: 0xE34, Hi: 0xE3A, Stride: 1}, + {Lo: 0xE47, Hi: 0xE4E, Stride: 1}, + {Lo: 0xEB1, Hi: 0xEB1, Stride: 1}, + {Lo: 0xEB4, Hi: 0xEBC, Stride: 1}, + {Lo: 0xEC8, Hi: 0xECE, Stride: 1}, + {Lo: 0xF18, Hi: 0xF19, Stride: 1}, + {Lo: 0xF35, Hi: 0xF35, Stride: 1}, + {Lo: 0xF37, Hi: 0xF37, Stride: 1}, + {Lo: 0xF39, Hi: 0xF39, Stride: 1}, + {Lo: 0xF3E, Hi: 0xF3F, Stride: 1}, + {Lo: 0xF71, Hi: 0xF84, Stride: 1}, + {Lo: 0xF86, Hi: 0xF87, Stride: 1}, + {Lo: 0xF8D, Hi: 0xF97, Stride: 1}, + {Lo: 0xF99, Hi: 0xFBC, Stride: 1}, + {Lo: 0xFC6, Hi: 0xFC6, Stride: 1}, + {Lo: 0x102B, Hi: 0x103E, Stride: 1}, + {Lo: 0x1056, Hi: 0x1059, Stride: 1}, + {Lo: 0x105E, Hi: 0x1060, Stride: 1}, + {Lo: 0x1062, Hi: 0x1064, Stride: 1}, + {Lo: 0x1067, Hi: 0x106D, Stride: 1}, + {Lo: 0x1071, Hi: 0x1074, Stride: 1}, + {Lo: 0x1082, Hi: 0x108D, Stride: 1}, + {Lo: 0x108F, Hi: 0x108F, Stride: 1}, + {Lo: 0x109A, Hi: 0x109D, Stride: 1}, + {Lo: 0x135D, Hi: 0x135F, Stride: 1}, + {Lo: 0x1712, Hi: 0x1715, Stride: 1}, + {Lo: 0x1732, Hi: 0x1734, Stride: 1}, + {Lo: 0x1752, Hi: 0x1753, Stride: 1}, + {Lo: 0x1772, Hi: 0x1773, Stride: 1}, + {Lo: 0x17B4, Hi: 0x17D3, Stride: 1}, + {Lo: 0x17DD, Hi: 0x17DD, Stride: 1}, + {Lo: 0x180B, Hi: 0x180D, Stride: 1}, + {Lo: 0x180F, Hi: 0x180F, Stride: 1}, + {Lo: 0x1885, Hi: 0x1886, Stride: 1}, + {Lo: 0x18A9, Hi: 0x18A9, Stride: 1}, + {Lo: 0x1920, Hi: 0x192B, Stride: 1}, + {Lo: 0x1930, Hi: 0x193B, Stride: 1}, + {Lo: 0x1A17, Hi: 0x1A1B, Stride: 1}, + {Lo: 0x1A55, Hi: 0x1A5E, Stride: 1}, + {Lo: 0x1A60, Hi: 0x1A7C, Stride: 1}, + {Lo: 0x1A7F, Hi: 0x1A7F, Stride: 1}, + {Lo: 0x1AB0, Hi: 0x1ADD, Stride: 1}, + {Lo: 0x1AE0, Hi: 0x1AEB, Stride: 1}, + {Lo: 0x1B00, Hi: 0x1B04, Stride: 1}, + {Lo: 0x1B34, Hi: 0x1B44, Stride: 1}, + {Lo: 0x1B6B, Hi: 0x1B73, Stride: 1}, + {Lo: 0x1B80, Hi: 0x1B82, Stride: 1}, + {Lo: 0x1BA1, Hi: 0x1BAD, Stride: 1}, + {Lo: 0x1BE6, Hi: 0x1BF3, Stride: 1}, + {Lo: 0x1C24, Hi: 0x1C37, Stride: 1}, + {Lo: 0x1CD0, Hi: 0x1CD2, Stride: 1}, + {Lo: 0x1CD4, Hi: 0x1CE8, Stride: 1}, + {Lo: 0x1CED, Hi: 0x1CED, Stride: 1}, + {Lo: 0x1CF4, Hi: 0x1CF4, Stride: 1}, + {Lo: 0x1CF7, Hi: 0x1CF9, Stride: 1}, + {Lo: 0x1DC0, Hi: 0x1DFF, Stride: 1}, + {Lo: 0x200C, Hi: 0x200D, Stride: 1}, + {Lo: 0x20D0, Hi: 0x20F0, Stride: 1}, + {Lo: 0x2CEF, Hi: 0x2CF1, Stride: 1}, + {Lo: 0x2D7F, Hi: 0x2D7F, Stride: 1}, + {Lo: 0x2DE0, Hi: 0x2DFF, Stride: 1}, + {Lo: 0x302A, Hi: 0x302F, Stride: 1}, + {Lo: 0x3099, Hi: 0x309A, Stride: 1}, + {Lo: 0xA66F, Hi: 0xA672, Stride: 1}, + {Lo: 0xA674, Hi: 0xA67D, Stride: 1}, + {Lo: 0xA69E, Hi: 0xA69F, Stride: 1}, + {Lo: 0xA6F0, Hi: 0xA6F1, Stride: 1}, + {Lo: 0xA802, Hi: 0xA802, Stride: 1}, + {Lo: 0xA806, Hi: 0xA806, Stride: 1}, + {Lo: 0xA80B, Hi: 0xA80B, Stride: 1}, + {Lo: 0xA823, Hi: 0xA827, Stride: 1}, + {Lo: 0xA82C, Hi: 0xA82C, Stride: 1}, + {Lo: 0xA880, Hi: 0xA881, Stride: 1}, + {Lo: 0xA8B4, Hi: 0xA8C5, Stride: 1}, + {Lo: 0xA8E0, Hi: 0xA8F1, Stride: 1}, + {Lo: 0xA8FF, Hi: 0xA8FF, Stride: 1}, + {Lo: 0xA926, Hi: 0xA92D, Stride: 1}, + {Lo: 0xA947, Hi: 0xA953, Stride: 1}, + {Lo: 0xA980, Hi: 0xA983, Stride: 1}, + {Lo: 0xA9B3, Hi: 0xA9C0, Stride: 1}, + {Lo: 0xA9E5, Hi: 0xA9E5, Stride: 1}, + {Lo: 0xAA29, Hi: 0xAA36, Stride: 1}, + {Lo: 0xAA43, Hi: 0xAA43, Stride: 1}, + {Lo: 0xAA4C, Hi: 0xAA4D, Stride: 1}, + {Lo: 0xAA7B, Hi: 0xAA7D, Stride: 1}, + {Lo: 0xAAB0, Hi: 0xAAB0, Stride: 1}, + {Lo: 0xAAB2, Hi: 0xAAB4, Stride: 1}, + {Lo: 0xAAB7, Hi: 0xAAB8, Stride: 1}, + {Lo: 0xAABE, Hi: 0xAABF, Stride: 1}, + {Lo: 0xAAC1, Hi: 0xAAC1, Stride: 1}, + {Lo: 0xAAEB, Hi: 0xAAEF, Stride: 1}, + {Lo: 0xAAF5, Hi: 0xAAF6, Stride: 1}, + {Lo: 0xABE3, Hi: 0xABEA, Stride: 1}, + {Lo: 0xABEC, Hi: 0xABED, Stride: 1}, + {Lo: 0xFB1E, Hi: 0xFB1E, Stride: 1}, + {Lo: 0xFE00, Hi: 0xFE0F, Stride: 1}, + {Lo: 0xFE20, Hi: 0xFE2F, Stride: 1}, + {Lo: 0xFF9E, Hi: 0xFF9F, Stride: 1}, + }, + R32: []unicode.Range32{ + {Lo: 0x101FD, Hi: 0x101FD, Stride: 1}, + {Lo: 0x102E0, Hi: 0x102E0, Stride: 1}, + {Lo: 0x10376, Hi: 0x1037A, Stride: 1}, + {Lo: 0x10A01, Hi: 0x10A03, Stride: 1}, + {Lo: 0x10A05, Hi: 0x10A06, Stride: 1}, + {Lo: 0x10A0C, Hi: 0x10A0F, Stride: 1}, + {Lo: 0x10A38, Hi: 0x10A3A, Stride: 1}, + {Lo: 0x10A3F, Hi: 0x10A3F, Stride: 1}, + {Lo: 0x10AE5, Hi: 0x10AE6, Stride: 1}, + {Lo: 0x10D24, Hi: 0x10D27, Stride: 1}, + {Lo: 0x10D69, Hi: 0x10D6D, Stride: 1}, + {Lo: 0x10EAB, Hi: 0x10EAC, Stride: 1}, + {Lo: 0x10EFA, Hi: 0x10EFF, Stride: 1}, + {Lo: 0x10F46, Hi: 0x10F50, Stride: 1}, + {Lo: 0x10F82, Hi: 0x10F85, Stride: 1}, + {Lo: 0x11000, Hi: 0x11002, Stride: 1}, + {Lo: 0x11038, Hi: 0x11046, Stride: 1}, + {Lo: 0x11070, Hi: 0x11070, Stride: 1}, + {Lo: 0x11073, Hi: 0x11074, Stride: 1}, + {Lo: 0x1107F, Hi: 0x11082, Stride: 1}, + {Lo: 0x110B0, Hi: 0x110BA, Stride: 1}, + {Lo: 0x110C2, Hi: 0x110C2, Stride: 1}, + {Lo: 0x11100, Hi: 0x11102, Stride: 1}, + {Lo: 0x11127, Hi: 0x11134, Stride: 1}, + {Lo: 0x11145, Hi: 0x11146, Stride: 1}, + {Lo: 0x11173, Hi: 0x11173, Stride: 1}, + {Lo: 0x11180, Hi: 0x11182, Stride: 1}, + {Lo: 0x111B3, Hi: 0x111C0, Stride: 1}, + {Lo: 0x111C9, Hi: 0x111CC, Stride: 1}, + {Lo: 0x111CE, Hi: 0x111CF, Stride: 1}, + {Lo: 0x1122C, Hi: 0x11237, Stride: 1}, + {Lo: 0x1123E, Hi: 0x1123E, Stride: 1}, + {Lo: 0x11241, Hi: 0x11241, Stride: 1}, + {Lo: 0x112DF, Hi: 0x112EA, Stride: 1}, + {Lo: 0x11300, Hi: 0x11303, Stride: 1}, + {Lo: 0x1133B, Hi: 0x1133C, Stride: 1}, + {Lo: 0x1133E, Hi: 0x11344, Stride: 1}, + {Lo: 0x11347, Hi: 0x11348, Stride: 1}, + {Lo: 0x1134B, Hi: 0x1134D, Stride: 1}, + {Lo: 0x11357, Hi: 0x11357, Stride: 1}, + {Lo: 0x11362, Hi: 0x11363, Stride: 1}, + {Lo: 0x11366, Hi: 0x1136C, Stride: 1}, + {Lo: 0x11370, Hi: 0x11374, Stride: 1}, + {Lo: 0x113B8, Hi: 0x113C0, Stride: 1}, + {Lo: 0x113C2, Hi: 0x113C2, Stride: 1}, + {Lo: 0x113C5, Hi: 0x113C5, Stride: 1}, + {Lo: 0x113C7, Hi: 0x113CA, Stride: 1}, + {Lo: 0x113CC, Hi: 0x113D0, Stride: 1}, + {Lo: 0x113D2, Hi: 0x113D2, Stride: 1}, + {Lo: 0x113E1, Hi: 0x113E2, Stride: 1}, + {Lo: 0x11435, Hi: 0x11446, Stride: 1}, + {Lo: 0x1145E, Hi: 0x1145E, Stride: 1}, + {Lo: 0x114B0, Hi: 0x114C3, Stride: 1}, + {Lo: 0x115AF, Hi: 0x115B5, Stride: 1}, + {Lo: 0x115B8, Hi: 0x115C0, Stride: 1}, + {Lo: 0x115DC, Hi: 0x115DD, Stride: 1}, + {Lo: 0x11630, Hi: 0x11640, Stride: 1}, + {Lo: 0x116AB, Hi: 0x116B7, Stride: 1}, + {Lo: 0x1171D, Hi: 0x1172B, Stride: 1}, + {Lo: 0x1182C, Hi: 0x1183A, Stride: 1}, + {Lo: 0x11930, Hi: 0x11935, Stride: 1}, + {Lo: 0x11937, Hi: 0x11938, Stride: 1}, + {Lo: 0x1193B, Hi: 0x1193E, Stride: 1}, + {Lo: 0x11940, Hi: 0x11940, Stride: 1}, + {Lo: 0x11942, Hi: 0x11943, Stride: 1}, + {Lo: 0x119D1, Hi: 0x119D7, Stride: 1}, + {Lo: 0x119DA, Hi: 0x119E0, Stride: 1}, + {Lo: 0x119E4, Hi: 0x119E4, Stride: 1}, + {Lo: 0x11A01, Hi: 0x11A0A, Stride: 1}, + {Lo: 0x11A33, Hi: 0x11A39, Stride: 1}, + {Lo: 0x11A3B, Hi: 0x11A3E, Stride: 1}, + {Lo: 0x11A47, Hi: 0x11A47, Stride: 1}, + {Lo: 0x11A51, Hi: 0x11A5B, Stride: 1}, + {Lo: 0x11A8A, Hi: 0x11A99, Stride: 1}, + {Lo: 0x11B60, Hi: 0x11B67, Stride: 1}, + {Lo: 0x11C2F, Hi: 0x11C36, Stride: 1}, + {Lo: 0x11C38, Hi: 0x11C3F, Stride: 1}, + {Lo: 0x11C92, Hi: 0x11CA7, Stride: 1}, + {Lo: 0x11CA9, Hi: 0x11CB6, Stride: 1}, + {Lo: 0x11D31, Hi: 0x11D36, Stride: 1}, + {Lo: 0x11D3A, Hi: 0x11D3A, Stride: 1}, + {Lo: 0x11D3C, Hi: 0x11D3D, Stride: 1}, + {Lo: 0x11D3F, Hi: 0x11D45, Stride: 1}, + {Lo: 0x11D47, Hi: 0x11D47, Stride: 1}, + {Lo: 0x11D8A, Hi: 0x11D8E, Stride: 1}, + {Lo: 0x11D90, Hi: 0x11D91, Stride: 1}, + {Lo: 0x11D93, Hi: 0x11D97, Stride: 1}, + {Lo: 0x11EF3, Hi: 0x11EF6, Stride: 1}, + {Lo: 0x11F00, Hi: 0x11F01, Stride: 1}, + {Lo: 0x11F03, Hi: 0x11F03, Stride: 1}, + {Lo: 0x11F34, Hi: 0x11F3A, Stride: 1}, + {Lo: 0x11F3E, Hi: 0x11F42, Stride: 1}, + {Lo: 0x11F5A, Hi: 0x11F5A, Stride: 1}, + {Lo: 0x13440, Hi: 0x13440, Stride: 1}, + {Lo: 0x13447, Hi: 0x13455, Stride: 1}, + {Lo: 0x1611E, Hi: 0x1612F, Stride: 1}, + {Lo: 0x16AF0, Hi: 0x16AF4, Stride: 1}, + {Lo: 0x16B30, Hi: 0x16B36, Stride: 1}, + {Lo: 0x16F4F, Hi: 0x16F4F, Stride: 1}, + {Lo: 0x16F51, Hi: 0x16F87, Stride: 1}, + {Lo: 0x16F8F, Hi: 0x16F92, Stride: 1}, + {Lo: 0x16FE4, Hi: 0x16FE4, Stride: 1}, + {Lo: 0x16FF0, Hi: 0x16FF1, Stride: 1}, + {Lo: 0x1BC9D, Hi: 0x1BC9E, Stride: 1}, + {Lo: 0x1CF00, Hi: 0x1CF2D, Stride: 1}, + {Lo: 0x1CF30, Hi: 0x1CF46, Stride: 1}, + {Lo: 0x1D165, Hi: 0x1D169, Stride: 1}, + {Lo: 0x1D16D, Hi: 0x1D172, Stride: 1}, + {Lo: 0x1D17B, Hi: 0x1D182, Stride: 1}, + {Lo: 0x1D185, Hi: 0x1D18B, Stride: 1}, + {Lo: 0x1D1AA, Hi: 0x1D1AD, Stride: 1}, + {Lo: 0x1D242, Hi: 0x1D244, Stride: 1}, + {Lo: 0x1DA00, Hi: 0x1DA36, Stride: 1}, + {Lo: 0x1DA3B, Hi: 0x1DA6C, Stride: 1}, + {Lo: 0x1DA75, Hi: 0x1DA75, Stride: 1}, + {Lo: 0x1DA84, Hi: 0x1DA84, Stride: 1}, + {Lo: 0x1DA9B, Hi: 0x1DA9F, Stride: 1}, + {Lo: 0x1DAA1, Hi: 0x1DAAF, Stride: 1}, + {Lo: 0x1E000, Hi: 0x1E006, Stride: 1}, + {Lo: 0x1E008, Hi: 0x1E018, Stride: 1}, + {Lo: 0x1E01B, Hi: 0x1E021, Stride: 1}, + {Lo: 0x1E023, Hi: 0x1E024, Stride: 1}, + {Lo: 0x1E026, Hi: 0x1E02A, Stride: 1}, + {Lo: 0x1E08F, Hi: 0x1E08F, Stride: 1}, + {Lo: 0x1E130, Hi: 0x1E136, Stride: 1}, + {Lo: 0x1E2AE, Hi: 0x1E2AE, Stride: 1}, + {Lo: 0x1E2EC, Hi: 0x1E2EF, Stride: 1}, + {Lo: 0x1E4EC, Hi: 0x1E4EF, Stride: 1}, + {Lo: 0x1E5EE, Hi: 0x1E5EF, Stride: 1}, + {Lo: 0x1E6E3, Hi: 0x1E6E3, Stride: 1}, + {Lo: 0x1E6E6, Hi: 0x1E6E6, Stride: 1}, + {Lo: 0x1E6EE, Hi: 0x1E6EF, Stride: 1}, + {Lo: 0x1E6F5, Hi: 0x1E6F5, Stride: 1}, + {Lo: 0x1E8D0, Hi: 0x1E8D6, Stride: 1}, + {Lo: 0x1E944, Hi: 0x1E94A, Stride: 1}, + {Lo: 0xE0020, Hi: 0xE007F, Stride: 1}, + {Lo: 0xE0100, Hi: 0xE01EF, Stride: 1}, + }, +} + +var unicodeAliasSentence_Break_Format = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0xAD, Hi: 0xAD, Stride: 1}, + {Lo: 0x61C, Hi: 0x61C, Stride: 1}, + {Lo: 0x70F, Hi: 0x70F, Stride: 1}, + {Lo: 0x180E, Hi: 0x180E, Stride: 1}, + {Lo: 0x200B, Hi: 0x200B, Stride: 1}, + {Lo: 0x200E, Hi: 0x200F, Stride: 1}, + {Lo: 0x202A, Hi: 0x202E, Stride: 1}, + {Lo: 0x2060, Hi: 0x2064, Stride: 1}, + {Lo: 0x2066, Hi: 0x206F, Stride: 1}, + {Lo: 0xFEFF, Hi: 0xFEFF, Stride: 1}, + {Lo: 0xFFF9, Hi: 0xFFFB, Stride: 1}, + }, + R32: []unicode.Range32{ + {Lo: 0x13430, Hi: 0x1343F, Stride: 1}, + {Lo: 0x1BCA0, Hi: 0x1BCA3, Stride: 1}, + {Lo: 0x1D173, Hi: 0x1D17A, Stride: 1}, + {Lo: 0xE0001, Hi: 0xE0001, Stride: 1}, + }, +} + +var unicodeAliasSentence_Break_LF = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0xA, Hi: 0xA, Stride: 1}, + }, +} + +var unicodeAliasSentence_Break_Lower = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0x61, Hi: 0x7A, Stride: 1}, + {Lo: 0xAA, Hi: 0xAA, Stride: 1}, + {Lo: 0xB5, Hi: 0xB5, Stride: 1}, + {Lo: 0xBA, Hi: 0xBA, Stride: 1}, + {Lo: 0xDF, Hi: 0xF6, Stride: 1}, + {Lo: 0xF8, Hi: 0xFF, Stride: 1}, + {Lo: 0x101, Hi: 0x101, Stride: 1}, + {Lo: 0x103, Hi: 0x103, Stride: 1}, + {Lo: 0x105, Hi: 0x105, Stride: 1}, + {Lo: 0x107, Hi: 0x107, Stride: 1}, + {Lo: 0x109, Hi: 0x109, Stride: 1}, + {Lo: 0x10B, Hi: 0x10B, Stride: 1}, + {Lo: 0x10D, Hi: 0x10D, Stride: 1}, + {Lo: 0x10F, Hi: 0x10F, Stride: 1}, + {Lo: 0x111, Hi: 0x111, Stride: 1}, + {Lo: 0x113, Hi: 0x113, Stride: 1}, + {Lo: 0x115, Hi: 0x115, Stride: 1}, + {Lo: 0x117, Hi: 0x117, Stride: 1}, + {Lo: 0x119, Hi: 0x119, Stride: 1}, + {Lo: 0x11B, Hi: 0x11B, Stride: 1}, + {Lo: 0x11D, Hi: 0x11D, Stride: 1}, + {Lo: 0x11F, Hi: 0x11F, Stride: 1}, + {Lo: 0x121, Hi: 0x121, Stride: 1}, + {Lo: 0x123, Hi: 0x123, Stride: 1}, + {Lo: 0x125, Hi: 0x125, Stride: 1}, + {Lo: 0x127, Hi: 0x127, Stride: 1}, + {Lo: 0x129, Hi: 0x129, Stride: 1}, + {Lo: 0x12B, Hi: 0x12B, Stride: 1}, + {Lo: 0x12D, Hi: 0x12D, Stride: 1}, + {Lo: 0x12F, Hi: 0x12F, Stride: 1}, + {Lo: 0x131, Hi: 0x131, Stride: 1}, + {Lo: 0x133, Hi: 0x133, Stride: 1}, + {Lo: 0x135, Hi: 0x135, Stride: 1}, + {Lo: 0x137, Hi: 0x138, Stride: 1}, + {Lo: 0x13A, Hi: 0x13A, Stride: 1}, + {Lo: 0x13C, Hi: 0x13C, Stride: 1}, + {Lo: 0x13E, Hi: 0x13E, Stride: 1}, + {Lo: 0x140, Hi: 0x140, Stride: 1}, + {Lo: 0x142, Hi: 0x142, Stride: 1}, + {Lo: 0x144, Hi: 0x144, Stride: 1}, + {Lo: 0x146, Hi: 0x146, Stride: 1}, + {Lo: 0x148, Hi: 0x149, Stride: 1}, + {Lo: 0x14B, Hi: 0x14B, Stride: 1}, + {Lo: 0x14D, Hi: 0x14D, Stride: 1}, + {Lo: 0x14F, Hi: 0x14F, Stride: 1}, + {Lo: 0x151, Hi: 0x151, Stride: 1}, + {Lo: 0x153, Hi: 0x153, Stride: 1}, + {Lo: 0x155, Hi: 0x155, Stride: 1}, + {Lo: 0x157, Hi: 0x157, Stride: 1}, + {Lo: 0x159, Hi: 0x159, Stride: 1}, + {Lo: 0x15B, Hi: 0x15B, Stride: 1}, + {Lo: 0x15D, Hi: 0x15D, Stride: 1}, + {Lo: 0x15F, Hi: 0x15F, Stride: 1}, + {Lo: 0x161, Hi: 0x161, Stride: 1}, + {Lo: 0x163, Hi: 0x163, Stride: 1}, + {Lo: 0x165, Hi: 0x165, Stride: 1}, + {Lo: 0x167, Hi: 0x167, Stride: 1}, + {Lo: 0x169, Hi: 0x169, Stride: 1}, + {Lo: 0x16B, Hi: 0x16B, Stride: 1}, + {Lo: 0x16D, Hi: 0x16D, Stride: 1}, + {Lo: 0x16F, Hi: 0x16F, Stride: 1}, + {Lo: 0x171, Hi: 0x171, Stride: 1}, + {Lo: 0x173, Hi: 0x173, Stride: 1}, + {Lo: 0x175, Hi: 0x175, Stride: 1}, + {Lo: 0x177, Hi: 0x177, Stride: 1}, + {Lo: 0x17A, Hi: 0x17A, Stride: 1}, + {Lo: 0x17C, Hi: 0x17C, Stride: 1}, + {Lo: 0x17E, Hi: 0x180, Stride: 1}, + {Lo: 0x183, Hi: 0x183, Stride: 1}, + {Lo: 0x185, Hi: 0x185, Stride: 1}, + {Lo: 0x188, Hi: 0x188, Stride: 1}, + {Lo: 0x18C, Hi: 0x18D, Stride: 1}, + {Lo: 0x192, Hi: 0x192, Stride: 1}, + {Lo: 0x195, Hi: 0x195, Stride: 1}, + {Lo: 0x199, Hi: 0x19B, Stride: 1}, + {Lo: 0x19E, Hi: 0x19E, Stride: 1}, + {Lo: 0x1A1, Hi: 0x1A1, Stride: 1}, + {Lo: 0x1A3, Hi: 0x1A3, Stride: 1}, + {Lo: 0x1A5, Hi: 0x1A5, Stride: 1}, + {Lo: 0x1A8, Hi: 0x1A8, Stride: 1}, + {Lo: 0x1AA, Hi: 0x1AB, Stride: 1}, + {Lo: 0x1AD, Hi: 0x1AD, Stride: 1}, + {Lo: 0x1B0, Hi: 0x1B0, Stride: 1}, + {Lo: 0x1B4, Hi: 0x1B4, Stride: 1}, + {Lo: 0x1B6, Hi: 0x1B6, Stride: 1}, + {Lo: 0x1B9, Hi: 0x1BA, Stride: 1}, + {Lo: 0x1BD, Hi: 0x1BF, Stride: 1}, + {Lo: 0x1C6, Hi: 0x1C6, Stride: 1}, + {Lo: 0x1C9, Hi: 0x1C9, Stride: 1}, + {Lo: 0x1CC, Hi: 0x1CC, Stride: 1}, + {Lo: 0x1CE, Hi: 0x1CE, Stride: 1}, + {Lo: 0x1D0, Hi: 0x1D0, Stride: 1}, + {Lo: 0x1D2, Hi: 0x1D2, Stride: 1}, + {Lo: 0x1D4, Hi: 0x1D4, Stride: 1}, + {Lo: 0x1D6, Hi: 0x1D6, Stride: 1}, + {Lo: 0x1D8, Hi: 0x1D8, Stride: 1}, + {Lo: 0x1DA, Hi: 0x1DA, Stride: 1}, + {Lo: 0x1DC, Hi: 0x1DD, Stride: 1}, + {Lo: 0x1DF, Hi: 0x1DF, Stride: 1}, + {Lo: 0x1E1, Hi: 0x1E1, Stride: 1}, + {Lo: 0x1E3, Hi: 0x1E3, Stride: 1}, + {Lo: 0x1E5, Hi: 0x1E5, Stride: 1}, + {Lo: 0x1E7, Hi: 0x1E7, Stride: 1}, + {Lo: 0x1E9, Hi: 0x1E9, Stride: 1}, + {Lo: 0x1EB, Hi: 0x1EB, Stride: 1}, + {Lo: 0x1ED, Hi: 0x1ED, Stride: 1}, + {Lo: 0x1EF, Hi: 0x1F0, Stride: 1}, + {Lo: 0x1F3, Hi: 0x1F3, Stride: 1}, + {Lo: 0x1F5, Hi: 0x1F5, Stride: 1}, + {Lo: 0x1F9, Hi: 0x1F9, Stride: 1}, + {Lo: 0x1FB, Hi: 0x1FB, Stride: 1}, + {Lo: 0x1FD, Hi: 0x1FD, Stride: 1}, + {Lo: 0x1FF, Hi: 0x1FF, Stride: 1}, + {Lo: 0x201, Hi: 0x201, Stride: 1}, + {Lo: 0x203, Hi: 0x203, Stride: 1}, + {Lo: 0x205, Hi: 0x205, Stride: 1}, + {Lo: 0x207, Hi: 0x207, Stride: 1}, + {Lo: 0x209, Hi: 0x209, Stride: 1}, + {Lo: 0x20B, Hi: 0x20B, Stride: 1}, + {Lo: 0x20D, Hi: 0x20D, Stride: 1}, + {Lo: 0x20F, Hi: 0x20F, Stride: 1}, + {Lo: 0x211, Hi: 0x211, Stride: 1}, + {Lo: 0x213, Hi: 0x213, Stride: 1}, + {Lo: 0x215, Hi: 0x215, Stride: 1}, + {Lo: 0x217, Hi: 0x217, Stride: 1}, + {Lo: 0x219, Hi: 0x219, Stride: 1}, + {Lo: 0x21B, Hi: 0x21B, Stride: 1}, + {Lo: 0x21D, Hi: 0x21D, Stride: 1}, + {Lo: 0x21F, Hi: 0x21F, Stride: 1}, + {Lo: 0x221, Hi: 0x221, Stride: 1}, + {Lo: 0x223, Hi: 0x223, Stride: 1}, + {Lo: 0x225, Hi: 0x225, Stride: 1}, + {Lo: 0x227, Hi: 0x227, Stride: 1}, + {Lo: 0x229, Hi: 0x229, Stride: 1}, + {Lo: 0x22B, Hi: 0x22B, Stride: 1}, + {Lo: 0x22D, Hi: 0x22D, Stride: 1}, + {Lo: 0x22F, Hi: 0x22F, Stride: 1}, + {Lo: 0x231, Hi: 0x231, Stride: 1}, + {Lo: 0x233, Hi: 0x239, Stride: 1}, + {Lo: 0x23C, Hi: 0x23C, Stride: 1}, + {Lo: 0x23F, Hi: 0x240, Stride: 1}, + {Lo: 0x242, Hi: 0x242, Stride: 1}, + {Lo: 0x247, Hi: 0x247, Stride: 1}, + {Lo: 0x249, Hi: 0x249, Stride: 1}, + {Lo: 0x24B, Hi: 0x24B, Stride: 1}, + {Lo: 0x24D, Hi: 0x24D, Stride: 1}, + {Lo: 0x24F, Hi: 0x293, Stride: 1}, + {Lo: 0x296, Hi: 0x2B8, Stride: 1}, + {Lo: 0x2C0, Hi: 0x2C1, Stride: 1}, + {Lo: 0x2E0, Hi: 0x2E4, Stride: 1}, + {Lo: 0x371, Hi: 0x371, Stride: 1}, + {Lo: 0x373, Hi: 0x373, Stride: 1}, + {Lo: 0x377, Hi: 0x377, Stride: 1}, + {Lo: 0x37A, Hi: 0x37D, Stride: 1}, + {Lo: 0x390, Hi: 0x390, Stride: 1}, + {Lo: 0x3AC, Hi: 0x3CE, Stride: 1}, + {Lo: 0x3D0, Hi: 0x3D1, Stride: 1}, + {Lo: 0x3D5, Hi: 0x3D7, Stride: 1}, + {Lo: 0x3D9, Hi: 0x3D9, Stride: 1}, + {Lo: 0x3DB, Hi: 0x3DB, Stride: 1}, + {Lo: 0x3DD, Hi: 0x3DD, Stride: 1}, + {Lo: 0x3DF, Hi: 0x3DF, Stride: 1}, + {Lo: 0x3E1, Hi: 0x3E1, Stride: 1}, + {Lo: 0x3E3, Hi: 0x3E3, Stride: 1}, + {Lo: 0x3E5, Hi: 0x3E5, Stride: 1}, + {Lo: 0x3E7, Hi: 0x3E7, Stride: 1}, + {Lo: 0x3E9, Hi: 0x3E9, Stride: 1}, + {Lo: 0x3EB, Hi: 0x3EB, Stride: 1}, + {Lo: 0x3ED, Hi: 0x3ED, Stride: 1}, + {Lo: 0x3EF, Hi: 0x3F3, Stride: 1}, + {Lo: 0x3F5, Hi: 0x3F5, Stride: 1}, + {Lo: 0x3F8, Hi: 0x3F8, Stride: 1}, + {Lo: 0x3FB, Hi: 0x3FC, Stride: 1}, + {Lo: 0x430, Hi: 0x45F, Stride: 1}, + {Lo: 0x461, Hi: 0x461, Stride: 1}, + {Lo: 0x463, Hi: 0x463, Stride: 1}, + {Lo: 0x465, Hi: 0x465, Stride: 1}, + {Lo: 0x467, Hi: 0x467, Stride: 1}, + {Lo: 0x469, Hi: 0x469, Stride: 1}, + {Lo: 0x46B, Hi: 0x46B, Stride: 1}, + {Lo: 0x46D, Hi: 0x46D, Stride: 1}, + {Lo: 0x46F, Hi: 0x46F, Stride: 1}, + {Lo: 0x471, Hi: 0x471, Stride: 1}, + {Lo: 0x473, Hi: 0x473, Stride: 1}, + {Lo: 0x475, Hi: 0x475, Stride: 1}, + {Lo: 0x477, Hi: 0x477, Stride: 1}, + {Lo: 0x479, Hi: 0x479, Stride: 1}, + {Lo: 0x47B, Hi: 0x47B, Stride: 1}, + {Lo: 0x47D, Hi: 0x47D, Stride: 1}, + {Lo: 0x47F, Hi: 0x47F, Stride: 1}, + {Lo: 0x481, Hi: 0x481, Stride: 1}, + {Lo: 0x48B, Hi: 0x48B, Stride: 1}, + {Lo: 0x48D, Hi: 0x48D, Stride: 1}, + {Lo: 0x48F, Hi: 0x48F, Stride: 1}, + {Lo: 0x491, Hi: 0x491, Stride: 1}, + {Lo: 0x493, Hi: 0x493, Stride: 1}, + {Lo: 0x495, Hi: 0x495, Stride: 1}, + {Lo: 0x497, Hi: 0x497, Stride: 1}, + {Lo: 0x499, Hi: 0x499, Stride: 1}, + {Lo: 0x49B, Hi: 0x49B, Stride: 1}, + {Lo: 0x49D, Hi: 0x49D, Stride: 1}, + {Lo: 0x49F, Hi: 0x49F, Stride: 1}, + {Lo: 0x4A1, Hi: 0x4A1, Stride: 1}, + {Lo: 0x4A3, Hi: 0x4A3, Stride: 1}, + {Lo: 0x4A5, Hi: 0x4A5, Stride: 1}, + {Lo: 0x4A7, Hi: 0x4A7, Stride: 1}, + {Lo: 0x4A9, Hi: 0x4A9, Stride: 1}, + {Lo: 0x4AB, Hi: 0x4AB, Stride: 1}, + {Lo: 0x4AD, Hi: 0x4AD, Stride: 1}, + {Lo: 0x4AF, Hi: 0x4AF, Stride: 1}, + {Lo: 0x4B1, Hi: 0x4B1, Stride: 1}, + {Lo: 0x4B3, Hi: 0x4B3, Stride: 1}, + {Lo: 0x4B5, Hi: 0x4B5, Stride: 1}, + {Lo: 0x4B7, Hi: 0x4B7, Stride: 1}, + {Lo: 0x4B9, Hi: 0x4B9, Stride: 1}, + {Lo: 0x4BB, Hi: 0x4BB, Stride: 1}, + {Lo: 0x4BD, Hi: 0x4BD, Stride: 1}, + {Lo: 0x4BF, Hi: 0x4BF, Stride: 1}, + {Lo: 0x4C2, Hi: 0x4C2, Stride: 1}, + {Lo: 0x4C4, Hi: 0x4C4, Stride: 1}, + {Lo: 0x4C6, Hi: 0x4C6, Stride: 1}, + {Lo: 0x4C8, Hi: 0x4C8, Stride: 1}, + {Lo: 0x4CA, Hi: 0x4CA, Stride: 1}, + {Lo: 0x4CC, Hi: 0x4CC, Stride: 1}, + {Lo: 0x4CE, Hi: 0x4CF, Stride: 1}, + {Lo: 0x4D1, Hi: 0x4D1, Stride: 1}, + {Lo: 0x4D3, Hi: 0x4D3, Stride: 1}, + {Lo: 0x4D5, Hi: 0x4D5, Stride: 1}, + {Lo: 0x4D7, Hi: 0x4D7, Stride: 1}, + {Lo: 0x4D9, Hi: 0x4D9, Stride: 1}, + {Lo: 0x4DB, Hi: 0x4DB, Stride: 1}, + {Lo: 0x4DD, Hi: 0x4DD, Stride: 1}, + {Lo: 0x4DF, Hi: 0x4DF, Stride: 1}, + {Lo: 0x4E1, Hi: 0x4E1, Stride: 1}, + {Lo: 0x4E3, Hi: 0x4E3, Stride: 1}, + {Lo: 0x4E5, Hi: 0x4E5, Stride: 1}, + {Lo: 0x4E7, Hi: 0x4E7, Stride: 1}, + {Lo: 0x4E9, Hi: 0x4E9, Stride: 1}, + {Lo: 0x4EB, Hi: 0x4EB, Stride: 1}, + {Lo: 0x4ED, Hi: 0x4ED, Stride: 1}, + {Lo: 0x4EF, Hi: 0x4EF, Stride: 1}, + {Lo: 0x4F1, Hi: 0x4F1, Stride: 1}, + {Lo: 0x4F3, Hi: 0x4F3, Stride: 1}, + {Lo: 0x4F5, Hi: 0x4F5, Stride: 1}, + {Lo: 0x4F7, Hi: 0x4F7, Stride: 1}, + {Lo: 0x4F9, Hi: 0x4F9, Stride: 1}, + {Lo: 0x4FB, Hi: 0x4FB, Stride: 1}, + {Lo: 0x4FD, Hi: 0x4FD, Stride: 1}, + {Lo: 0x4FF, Hi: 0x4FF, Stride: 1}, + {Lo: 0x501, Hi: 0x501, Stride: 1}, + {Lo: 0x503, Hi: 0x503, Stride: 1}, + {Lo: 0x505, Hi: 0x505, Stride: 1}, + {Lo: 0x507, Hi: 0x507, Stride: 1}, + {Lo: 0x509, Hi: 0x509, Stride: 1}, + {Lo: 0x50B, Hi: 0x50B, Stride: 1}, + {Lo: 0x50D, Hi: 0x50D, Stride: 1}, + {Lo: 0x50F, Hi: 0x50F, Stride: 1}, + {Lo: 0x511, Hi: 0x511, Stride: 1}, + {Lo: 0x513, Hi: 0x513, Stride: 1}, + {Lo: 0x515, Hi: 0x515, Stride: 1}, + {Lo: 0x517, Hi: 0x517, Stride: 1}, + {Lo: 0x519, Hi: 0x519, Stride: 1}, + {Lo: 0x51B, Hi: 0x51B, Stride: 1}, + {Lo: 0x51D, Hi: 0x51D, Stride: 1}, + {Lo: 0x51F, Hi: 0x51F, Stride: 1}, + {Lo: 0x521, Hi: 0x521, Stride: 1}, + {Lo: 0x523, Hi: 0x523, Stride: 1}, + {Lo: 0x525, Hi: 0x525, Stride: 1}, + {Lo: 0x527, Hi: 0x527, Stride: 1}, + {Lo: 0x529, Hi: 0x529, Stride: 1}, + {Lo: 0x52B, Hi: 0x52B, Stride: 1}, + {Lo: 0x52D, Hi: 0x52D, Stride: 1}, + {Lo: 0x52F, Hi: 0x52F, Stride: 1}, + {Lo: 0x560, Hi: 0x588, Stride: 1}, + {Lo: 0x10FC, Hi: 0x10FC, Stride: 1}, + {Lo: 0x13F8, Hi: 0x13FD, Stride: 1}, + {Lo: 0x1C80, Hi: 0x1C88, Stride: 1}, + {Lo: 0x1C8A, Hi: 0x1C8A, Stride: 1}, + {Lo: 0x1D00, Hi: 0x1DBF, Stride: 1}, + {Lo: 0x1E01, Hi: 0x1E01, Stride: 1}, + {Lo: 0x1E03, Hi: 0x1E03, Stride: 1}, + {Lo: 0x1E05, Hi: 0x1E05, Stride: 1}, + {Lo: 0x1E07, Hi: 0x1E07, Stride: 1}, + {Lo: 0x1E09, Hi: 0x1E09, Stride: 1}, + {Lo: 0x1E0B, Hi: 0x1E0B, Stride: 1}, + {Lo: 0x1E0D, Hi: 0x1E0D, Stride: 1}, + {Lo: 0x1E0F, Hi: 0x1E0F, Stride: 1}, + {Lo: 0x1E11, Hi: 0x1E11, Stride: 1}, + {Lo: 0x1E13, Hi: 0x1E13, Stride: 1}, + {Lo: 0x1E15, Hi: 0x1E15, Stride: 1}, + {Lo: 0x1E17, Hi: 0x1E17, Stride: 1}, + {Lo: 0x1E19, Hi: 0x1E19, Stride: 1}, + {Lo: 0x1E1B, Hi: 0x1E1B, Stride: 1}, + {Lo: 0x1E1D, Hi: 0x1E1D, Stride: 1}, + {Lo: 0x1E1F, Hi: 0x1E1F, Stride: 1}, + {Lo: 0x1E21, Hi: 0x1E21, Stride: 1}, + {Lo: 0x1E23, Hi: 0x1E23, Stride: 1}, + {Lo: 0x1E25, Hi: 0x1E25, Stride: 1}, + {Lo: 0x1E27, Hi: 0x1E27, Stride: 1}, + {Lo: 0x1E29, Hi: 0x1E29, Stride: 1}, + {Lo: 0x1E2B, Hi: 0x1E2B, Stride: 1}, + {Lo: 0x1E2D, Hi: 0x1E2D, Stride: 1}, + {Lo: 0x1E2F, Hi: 0x1E2F, Stride: 1}, + {Lo: 0x1E31, Hi: 0x1E31, Stride: 1}, + {Lo: 0x1E33, Hi: 0x1E33, Stride: 1}, + {Lo: 0x1E35, Hi: 0x1E35, Stride: 1}, + {Lo: 0x1E37, Hi: 0x1E37, Stride: 1}, + {Lo: 0x1E39, Hi: 0x1E39, Stride: 1}, + {Lo: 0x1E3B, Hi: 0x1E3B, Stride: 1}, + {Lo: 0x1E3D, Hi: 0x1E3D, Stride: 1}, + {Lo: 0x1E3F, Hi: 0x1E3F, Stride: 1}, + {Lo: 0x1E41, Hi: 0x1E41, Stride: 1}, + {Lo: 0x1E43, Hi: 0x1E43, Stride: 1}, + {Lo: 0x1E45, Hi: 0x1E45, Stride: 1}, + {Lo: 0x1E47, Hi: 0x1E47, Stride: 1}, + {Lo: 0x1E49, Hi: 0x1E49, Stride: 1}, + {Lo: 0x1E4B, Hi: 0x1E4B, Stride: 1}, + {Lo: 0x1E4D, Hi: 0x1E4D, Stride: 1}, + {Lo: 0x1E4F, Hi: 0x1E4F, Stride: 1}, + {Lo: 0x1E51, Hi: 0x1E51, Stride: 1}, + {Lo: 0x1E53, Hi: 0x1E53, Stride: 1}, + {Lo: 0x1E55, Hi: 0x1E55, Stride: 1}, + {Lo: 0x1E57, Hi: 0x1E57, Stride: 1}, + {Lo: 0x1E59, Hi: 0x1E59, Stride: 1}, + {Lo: 0x1E5B, Hi: 0x1E5B, Stride: 1}, + {Lo: 0x1E5D, Hi: 0x1E5D, Stride: 1}, + {Lo: 0x1E5F, Hi: 0x1E5F, Stride: 1}, + {Lo: 0x1E61, Hi: 0x1E61, Stride: 1}, + {Lo: 0x1E63, Hi: 0x1E63, Stride: 1}, + {Lo: 0x1E65, Hi: 0x1E65, Stride: 1}, + {Lo: 0x1E67, Hi: 0x1E67, Stride: 1}, + {Lo: 0x1E69, Hi: 0x1E69, Stride: 1}, + {Lo: 0x1E6B, Hi: 0x1E6B, Stride: 1}, + {Lo: 0x1E6D, Hi: 0x1E6D, Stride: 1}, + {Lo: 0x1E6F, Hi: 0x1E6F, Stride: 1}, + {Lo: 0x1E71, Hi: 0x1E71, Stride: 1}, + {Lo: 0x1E73, Hi: 0x1E73, Stride: 1}, + {Lo: 0x1E75, Hi: 0x1E75, Stride: 1}, + {Lo: 0x1E77, Hi: 0x1E77, Stride: 1}, + {Lo: 0x1E79, Hi: 0x1E79, Stride: 1}, + {Lo: 0x1E7B, Hi: 0x1E7B, Stride: 1}, + {Lo: 0x1E7D, Hi: 0x1E7D, Stride: 1}, + {Lo: 0x1E7F, Hi: 0x1E7F, Stride: 1}, + {Lo: 0x1E81, Hi: 0x1E81, Stride: 1}, + {Lo: 0x1E83, Hi: 0x1E83, Stride: 1}, + {Lo: 0x1E85, Hi: 0x1E85, Stride: 1}, + {Lo: 0x1E87, Hi: 0x1E87, Stride: 1}, + {Lo: 0x1E89, Hi: 0x1E89, Stride: 1}, + {Lo: 0x1E8B, Hi: 0x1E8B, Stride: 1}, + {Lo: 0x1E8D, Hi: 0x1E8D, Stride: 1}, + {Lo: 0x1E8F, Hi: 0x1E8F, Stride: 1}, + {Lo: 0x1E91, Hi: 0x1E91, Stride: 1}, + {Lo: 0x1E93, Hi: 0x1E93, Stride: 1}, + {Lo: 0x1E95, Hi: 0x1E9D, Stride: 1}, + {Lo: 0x1E9F, Hi: 0x1E9F, Stride: 1}, + {Lo: 0x1EA1, Hi: 0x1EA1, Stride: 1}, + {Lo: 0x1EA3, Hi: 0x1EA3, Stride: 1}, + {Lo: 0x1EA5, Hi: 0x1EA5, Stride: 1}, + {Lo: 0x1EA7, Hi: 0x1EA7, Stride: 1}, + {Lo: 0x1EA9, Hi: 0x1EA9, Stride: 1}, + {Lo: 0x1EAB, Hi: 0x1EAB, Stride: 1}, + {Lo: 0x1EAD, Hi: 0x1EAD, Stride: 1}, + {Lo: 0x1EAF, Hi: 0x1EAF, Stride: 1}, + {Lo: 0x1EB1, Hi: 0x1EB1, Stride: 1}, + {Lo: 0x1EB3, Hi: 0x1EB3, Stride: 1}, + {Lo: 0x1EB5, Hi: 0x1EB5, Stride: 1}, + {Lo: 0x1EB7, Hi: 0x1EB7, Stride: 1}, + {Lo: 0x1EB9, Hi: 0x1EB9, Stride: 1}, + {Lo: 0x1EBB, Hi: 0x1EBB, Stride: 1}, + {Lo: 0x1EBD, Hi: 0x1EBD, Stride: 1}, + {Lo: 0x1EBF, Hi: 0x1EBF, Stride: 1}, + {Lo: 0x1EC1, Hi: 0x1EC1, Stride: 1}, + {Lo: 0x1EC3, Hi: 0x1EC3, Stride: 1}, + {Lo: 0x1EC5, Hi: 0x1EC5, Stride: 1}, + {Lo: 0x1EC7, Hi: 0x1EC7, Stride: 1}, + {Lo: 0x1EC9, Hi: 0x1EC9, Stride: 1}, + {Lo: 0x1ECB, Hi: 0x1ECB, Stride: 1}, + {Lo: 0x1ECD, Hi: 0x1ECD, Stride: 1}, + {Lo: 0x1ECF, Hi: 0x1ECF, Stride: 1}, + {Lo: 0x1ED1, Hi: 0x1ED1, Stride: 1}, + {Lo: 0x1ED3, Hi: 0x1ED3, Stride: 1}, + {Lo: 0x1ED5, Hi: 0x1ED5, Stride: 1}, + {Lo: 0x1ED7, Hi: 0x1ED7, Stride: 1}, + {Lo: 0x1ED9, Hi: 0x1ED9, Stride: 1}, + {Lo: 0x1EDB, Hi: 0x1EDB, Stride: 1}, + {Lo: 0x1EDD, Hi: 0x1EDD, Stride: 1}, + {Lo: 0x1EDF, Hi: 0x1EDF, Stride: 1}, + {Lo: 0x1EE1, Hi: 0x1EE1, Stride: 1}, + {Lo: 0x1EE3, Hi: 0x1EE3, Stride: 1}, + {Lo: 0x1EE5, Hi: 0x1EE5, Stride: 1}, + {Lo: 0x1EE7, Hi: 0x1EE7, Stride: 1}, + {Lo: 0x1EE9, Hi: 0x1EE9, Stride: 1}, + {Lo: 0x1EEB, Hi: 0x1EEB, Stride: 1}, + {Lo: 0x1EED, Hi: 0x1EED, Stride: 1}, + {Lo: 0x1EEF, Hi: 0x1EEF, Stride: 1}, + {Lo: 0x1EF1, Hi: 0x1EF1, Stride: 1}, + {Lo: 0x1EF3, Hi: 0x1EF3, Stride: 1}, + {Lo: 0x1EF5, Hi: 0x1EF5, Stride: 1}, + {Lo: 0x1EF7, Hi: 0x1EF7, Stride: 1}, + {Lo: 0x1EF9, Hi: 0x1EF9, Stride: 1}, + {Lo: 0x1EFB, Hi: 0x1EFB, Stride: 1}, + {Lo: 0x1EFD, Hi: 0x1EFD, Stride: 1}, + {Lo: 0x1EFF, Hi: 0x1F07, Stride: 1}, + {Lo: 0x1F10, Hi: 0x1F15, Stride: 1}, + {Lo: 0x1F20, Hi: 0x1F27, Stride: 1}, + {Lo: 0x1F30, Hi: 0x1F37, Stride: 1}, + {Lo: 0x1F40, Hi: 0x1F45, Stride: 1}, + {Lo: 0x1F50, Hi: 0x1F57, Stride: 1}, + {Lo: 0x1F60, Hi: 0x1F67, Stride: 1}, + {Lo: 0x1F70, Hi: 0x1F7D, Stride: 1}, + {Lo: 0x1F80, Hi: 0x1F87, Stride: 1}, + {Lo: 0x1F90, Hi: 0x1F97, Stride: 1}, + {Lo: 0x1FA0, Hi: 0x1FA7, Stride: 1}, + {Lo: 0x1FB0, Hi: 0x1FB4, Stride: 1}, + {Lo: 0x1FB6, Hi: 0x1FB7, Stride: 1}, + {Lo: 0x1FBE, Hi: 0x1FBE, Stride: 1}, + {Lo: 0x1FC2, Hi: 0x1FC4, Stride: 1}, + {Lo: 0x1FC6, Hi: 0x1FC7, Stride: 1}, + {Lo: 0x1FD0, Hi: 0x1FD3, Stride: 1}, + {Lo: 0x1FD6, Hi: 0x1FD7, Stride: 1}, + {Lo: 0x1FE0, Hi: 0x1FE7, Stride: 1}, + {Lo: 0x1FF2, Hi: 0x1FF4, Stride: 1}, + {Lo: 0x1FF6, Hi: 0x1FF7, Stride: 1}, + {Lo: 0x2071, Hi: 0x2071, Stride: 1}, + {Lo: 0x207F, Hi: 0x207F, Stride: 1}, + {Lo: 0x2090, Hi: 0x209C, Stride: 1}, + {Lo: 0x210A, Hi: 0x210A, Stride: 1}, + {Lo: 0x210E, Hi: 0x210F, Stride: 1}, + {Lo: 0x2113, Hi: 0x2113, Stride: 1}, + {Lo: 0x212F, Hi: 0x212F, Stride: 1}, + {Lo: 0x2134, Hi: 0x2134, Stride: 1}, + {Lo: 0x2139, Hi: 0x2139, Stride: 1}, + {Lo: 0x213C, Hi: 0x213D, Stride: 1}, + {Lo: 0x2146, Hi: 0x2149, Stride: 1}, + {Lo: 0x214E, Hi: 0x214E, Stride: 1}, + {Lo: 0x2170, Hi: 0x217F, Stride: 1}, + {Lo: 0x2184, Hi: 0x2184, Stride: 1}, + {Lo: 0x24D0, Hi: 0x24E9, Stride: 1}, + {Lo: 0x2C30, Hi: 0x2C5F, Stride: 1}, + {Lo: 0x2C61, Hi: 0x2C61, Stride: 1}, + {Lo: 0x2C65, Hi: 0x2C66, Stride: 1}, + {Lo: 0x2C68, Hi: 0x2C68, Stride: 1}, + {Lo: 0x2C6A, Hi: 0x2C6A, Stride: 1}, + {Lo: 0x2C6C, Hi: 0x2C6C, Stride: 1}, + {Lo: 0x2C71, Hi: 0x2C71, Stride: 1}, + {Lo: 0x2C73, Hi: 0x2C74, Stride: 1}, + {Lo: 0x2C76, Hi: 0x2C7D, Stride: 1}, + {Lo: 0x2C81, Hi: 0x2C81, Stride: 1}, + {Lo: 0x2C83, Hi: 0x2C83, Stride: 1}, + {Lo: 0x2C85, Hi: 0x2C85, Stride: 1}, + {Lo: 0x2C87, Hi: 0x2C87, Stride: 1}, + {Lo: 0x2C89, Hi: 0x2C89, Stride: 1}, + {Lo: 0x2C8B, Hi: 0x2C8B, Stride: 1}, + {Lo: 0x2C8D, Hi: 0x2C8D, Stride: 1}, + {Lo: 0x2C8F, Hi: 0x2C8F, Stride: 1}, + {Lo: 0x2C91, Hi: 0x2C91, Stride: 1}, + {Lo: 0x2C93, Hi: 0x2C93, Stride: 1}, + {Lo: 0x2C95, Hi: 0x2C95, Stride: 1}, + {Lo: 0x2C97, Hi: 0x2C97, Stride: 1}, + {Lo: 0x2C99, Hi: 0x2C99, Stride: 1}, + {Lo: 0x2C9B, Hi: 0x2C9B, Stride: 1}, + {Lo: 0x2C9D, Hi: 0x2C9D, Stride: 1}, + {Lo: 0x2C9F, Hi: 0x2C9F, Stride: 1}, + {Lo: 0x2CA1, Hi: 0x2CA1, Stride: 1}, + {Lo: 0x2CA3, Hi: 0x2CA3, Stride: 1}, + {Lo: 0x2CA5, Hi: 0x2CA5, Stride: 1}, + {Lo: 0x2CA7, Hi: 0x2CA7, Stride: 1}, + {Lo: 0x2CA9, Hi: 0x2CA9, Stride: 1}, + {Lo: 0x2CAB, Hi: 0x2CAB, Stride: 1}, + {Lo: 0x2CAD, Hi: 0x2CAD, Stride: 1}, + {Lo: 0x2CAF, Hi: 0x2CAF, Stride: 1}, + {Lo: 0x2CB1, Hi: 0x2CB1, Stride: 1}, + {Lo: 0x2CB3, Hi: 0x2CB3, Stride: 1}, + {Lo: 0x2CB5, Hi: 0x2CB5, Stride: 1}, + {Lo: 0x2CB7, Hi: 0x2CB7, Stride: 1}, + {Lo: 0x2CB9, Hi: 0x2CB9, Stride: 1}, + {Lo: 0x2CBB, Hi: 0x2CBB, Stride: 1}, + {Lo: 0x2CBD, Hi: 0x2CBD, Stride: 1}, + {Lo: 0x2CBF, Hi: 0x2CBF, Stride: 1}, + {Lo: 0x2CC1, Hi: 0x2CC1, Stride: 1}, + {Lo: 0x2CC3, Hi: 0x2CC3, Stride: 1}, + {Lo: 0x2CC5, Hi: 0x2CC5, Stride: 1}, + {Lo: 0x2CC7, Hi: 0x2CC7, Stride: 1}, + {Lo: 0x2CC9, Hi: 0x2CC9, Stride: 1}, + {Lo: 0x2CCB, Hi: 0x2CCB, Stride: 1}, + {Lo: 0x2CCD, Hi: 0x2CCD, Stride: 1}, + {Lo: 0x2CCF, Hi: 0x2CCF, Stride: 1}, + {Lo: 0x2CD1, Hi: 0x2CD1, Stride: 1}, + {Lo: 0x2CD3, Hi: 0x2CD3, Stride: 1}, + {Lo: 0x2CD5, Hi: 0x2CD5, Stride: 1}, + {Lo: 0x2CD7, Hi: 0x2CD7, Stride: 1}, + {Lo: 0x2CD9, Hi: 0x2CD9, Stride: 1}, + {Lo: 0x2CDB, Hi: 0x2CDB, Stride: 1}, + {Lo: 0x2CDD, Hi: 0x2CDD, Stride: 1}, + {Lo: 0x2CDF, Hi: 0x2CDF, Stride: 1}, + {Lo: 0x2CE1, Hi: 0x2CE1, Stride: 1}, + {Lo: 0x2CE3, Hi: 0x2CE4, Stride: 1}, + {Lo: 0x2CEC, Hi: 0x2CEC, Stride: 1}, + {Lo: 0x2CEE, Hi: 0x2CEE, Stride: 1}, + {Lo: 0x2CF3, Hi: 0x2CF3, Stride: 1}, + {Lo: 0x2D00, Hi: 0x2D25, Stride: 1}, + {Lo: 0x2D27, Hi: 0x2D27, Stride: 1}, + {Lo: 0x2D2D, Hi: 0x2D2D, Stride: 1}, + {Lo: 0xA641, Hi: 0xA641, Stride: 1}, + {Lo: 0xA643, Hi: 0xA643, Stride: 1}, + {Lo: 0xA645, Hi: 0xA645, Stride: 1}, + {Lo: 0xA647, Hi: 0xA647, Stride: 1}, + {Lo: 0xA649, Hi: 0xA649, Stride: 1}, + {Lo: 0xA64B, Hi: 0xA64B, Stride: 1}, + {Lo: 0xA64D, Hi: 0xA64D, Stride: 1}, + {Lo: 0xA64F, Hi: 0xA64F, Stride: 1}, + {Lo: 0xA651, Hi: 0xA651, Stride: 1}, + {Lo: 0xA653, Hi: 0xA653, Stride: 1}, + {Lo: 0xA655, Hi: 0xA655, Stride: 1}, + {Lo: 0xA657, Hi: 0xA657, Stride: 1}, + {Lo: 0xA659, Hi: 0xA659, Stride: 1}, + {Lo: 0xA65B, Hi: 0xA65B, Stride: 1}, + {Lo: 0xA65D, Hi: 0xA65D, Stride: 1}, + {Lo: 0xA65F, Hi: 0xA65F, Stride: 1}, + {Lo: 0xA661, Hi: 0xA661, Stride: 1}, + {Lo: 0xA663, Hi: 0xA663, Stride: 1}, + {Lo: 0xA665, Hi: 0xA665, Stride: 1}, + {Lo: 0xA667, Hi: 0xA667, Stride: 1}, + {Lo: 0xA669, Hi: 0xA669, Stride: 1}, + {Lo: 0xA66B, Hi: 0xA66B, Stride: 1}, + {Lo: 0xA66D, Hi: 0xA66D, Stride: 1}, + {Lo: 0xA681, Hi: 0xA681, Stride: 1}, + {Lo: 0xA683, Hi: 0xA683, Stride: 1}, + {Lo: 0xA685, Hi: 0xA685, Stride: 1}, + {Lo: 0xA687, Hi: 0xA687, Stride: 1}, + {Lo: 0xA689, Hi: 0xA689, Stride: 1}, + {Lo: 0xA68B, Hi: 0xA68B, Stride: 1}, + {Lo: 0xA68D, Hi: 0xA68D, Stride: 1}, + {Lo: 0xA68F, Hi: 0xA68F, Stride: 1}, + {Lo: 0xA691, Hi: 0xA691, Stride: 1}, + {Lo: 0xA693, Hi: 0xA693, Stride: 1}, + {Lo: 0xA695, Hi: 0xA695, Stride: 1}, + {Lo: 0xA697, Hi: 0xA697, Stride: 1}, + {Lo: 0xA699, Hi: 0xA699, Stride: 1}, + {Lo: 0xA69B, Hi: 0xA69D, Stride: 1}, + {Lo: 0xA723, Hi: 0xA723, Stride: 1}, + {Lo: 0xA725, Hi: 0xA725, Stride: 1}, + {Lo: 0xA727, Hi: 0xA727, Stride: 1}, + {Lo: 0xA729, Hi: 0xA729, Stride: 1}, + {Lo: 0xA72B, Hi: 0xA72B, Stride: 1}, + {Lo: 0xA72D, Hi: 0xA72D, Stride: 1}, + {Lo: 0xA72F, Hi: 0xA731, Stride: 1}, + {Lo: 0xA733, Hi: 0xA733, Stride: 1}, + {Lo: 0xA735, Hi: 0xA735, Stride: 1}, + {Lo: 0xA737, Hi: 0xA737, Stride: 1}, + {Lo: 0xA739, Hi: 0xA739, Stride: 1}, + {Lo: 0xA73B, Hi: 0xA73B, Stride: 1}, + {Lo: 0xA73D, Hi: 0xA73D, Stride: 1}, + {Lo: 0xA73F, Hi: 0xA73F, Stride: 1}, + {Lo: 0xA741, Hi: 0xA741, Stride: 1}, + {Lo: 0xA743, Hi: 0xA743, Stride: 1}, + {Lo: 0xA745, Hi: 0xA745, Stride: 1}, + {Lo: 0xA747, Hi: 0xA747, Stride: 1}, + {Lo: 0xA749, Hi: 0xA749, Stride: 1}, + {Lo: 0xA74B, Hi: 0xA74B, Stride: 1}, + {Lo: 0xA74D, Hi: 0xA74D, Stride: 1}, + {Lo: 0xA74F, Hi: 0xA74F, Stride: 1}, + {Lo: 0xA751, Hi: 0xA751, Stride: 1}, + {Lo: 0xA753, Hi: 0xA753, Stride: 1}, + {Lo: 0xA755, Hi: 0xA755, Stride: 1}, + {Lo: 0xA757, Hi: 0xA757, Stride: 1}, + {Lo: 0xA759, Hi: 0xA759, Stride: 1}, + {Lo: 0xA75B, Hi: 0xA75B, Stride: 1}, + {Lo: 0xA75D, Hi: 0xA75D, Stride: 1}, + {Lo: 0xA75F, Hi: 0xA75F, Stride: 1}, + {Lo: 0xA761, Hi: 0xA761, Stride: 1}, + {Lo: 0xA763, Hi: 0xA763, Stride: 1}, + {Lo: 0xA765, Hi: 0xA765, Stride: 1}, + {Lo: 0xA767, Hi: 0xA767, Stride: 1}, + {Lo: 0xA769, Hi: 0xA769, Stride: 1}, + {Lo: 0xA76B, Hi: 0xA76B, Stride: 1}, + {Lo: 0xA76D, Hi: 0xA76D, Stride: 1}, + {Lo: 0xA76F, Hi: 0xA778, Stride: 1}, + {Lo: 0xA77A, Hi: 0xA77A, Stride: 1}, + {Lo: 0xA77C, Hi: 0xA77C, Stride: 1}, + {Lo: 0xA77F, Hi: 0xA77F, Stride: 1}, + {Lo: 0xA781, Hi: 0xA781, Stride: 1}, + {Lo: 0xA783, Hi: 0xA783, Stride: 1}, + {Lo: 0xA785, Hi: 0xA785, Stride: 1}, + {Lo: 0xA787, Hi: 0xA787, Stride: 1}, + {Lo: 0xA78C, Hi: 0xA78C, Stride: 1}, + {Lo: 0xA78E, Hi: 0xA78E, Stride: 1}, + {Lo: 0xA791, Hi: 0xA791, Stride: 1}, + {Lo: 0xA793, Hi: 0xA795, Stride: 1}, + {Lo: 0xA797, Hi: 0xA797, Stride: 1}, + {Lo: 0xA799, Hi: 0xA799, Stride: 1}, + {Lo: 0xA79B, Hi: 0xA79B, Stride: 1}, + {Lo: 0xA79D, Hi: 0xA79D, Stride: 1}, + {Lo: 0xA79F, Hi: 0xA79F, Stride: 1}, + {Lo: 0xA7A1, Hi: 0xA7A1, Stride: 1}, + {Lo: 0xA7A3, Hi: 0xA7A3, Stride: 1}, + {Lo: 0xA7A5, Hi: 0xA7A5, Stride: 1}, + {Lo: 0xA7A7, Hi: 0xA7A7, Stride: 1}, + {Lo: 0xA7A9, Hi: 0xA7A9, Stride: 1}, + {Lo: 0xA7AF, Hi: 0xA7AF, Stride: 1}, + {Lo: 0xA7B5, Hi: 0xA7B5, Stride: 1}, + {Lo: 0xA7B7, Hi: 0xA7B7, Stride: 1}, + {Lo: 0xA7B9, Hi: 0xA7B9, Stride: 1}, + {Lo: 0xA7BB, Hi: 0xA7BB, Stride: 1}, + {Lo: 0xA7BD, Hi: 0xA7BD, Stride: 1}, + {Lo: 0xA7BF, Hi: 0xA7BF, Stride: 1}, + {Lo: 0xA7C1, Hi: 0xA7C1, Stride: 1}, + {Lo: 0xA7C3, Hi: 0xA7C3, Stride: 1}, + {Lo: 0xA7C8, Hi: 0xA7C8, Stride: 1}, + {Lo: 0xA7CA, Hi: 0xA7CA, Stride: 1}, + {Lo: 0xA7CD, Hi: 0xA7CD, Stride: 1}, + {Lo: 0xA7CF, Hi: 0xA7CF, Stride: 1}, + {Lo: 0xA7D1, Hi: 0xA7D1, Stride: 1}, + {Lo: 0xA7D3, Hi: 0xA7D3, Stride: 1}, + {Lo: 0xA7D5, Hi: 0xA7D5, Stride: 1}, + {Lo: 0xA7D7, Hi: 0xA7D7, Stride: 1}, + {Lo: 0xA7D9, Hi: 0xA7D9, Stride: 1}, + {Lo: 0xA7DB, Hi: 0xA7DB, Stride: 1}, + {Lo: 0xA7F1, Hi: 0xA7F4, Stride: 1}, + {Lo: 0xA7F6, Hi: 0xA7F6, Stride: 1}, + {Lo: 0xA7F8, Hi: 0xA7FA, Stride: 1}, + {Lo: 0xAB30, Hi: 0xAB5A, Stride: 1}, + {Lo: 0xAB5C, Hi: 0xAB69, Stride: 1}, + {Lo: 0xAB70, Hi: 0xABBF, Stride: 1}, + {Lo: 0xFB00, Hi: 0xFB06, Stride: 1}, + {Lo: 0xFB13, Hi: 0xFB17, Stride: 1}, + {Lo: 0xFF41, Hi: 0xFF5A, Stride: 1}, + }, + R32: []unicode.Range32{ + {Lo: 0x10428, Hi: 0x1044F, Stride: 1}, + {Lo: 0x104D8, Hi: 0x104FB, Stride: 1}, + {Lo: 0x10597, Hi: 0x105A1, Stride: 1}, + {Lo: 0x105A3, Hi: 0x105B1, Stride: 1}, + {Lo: 0x105B3, Hi: 0x105B9, Stride: 1}, + {Lo: 0x105BB, Hi: 0x105BC, Stride: 1}, + {Lo: 0x10780, Hi: 0x10780, Stride: 1}, + {Lo: 0x10783, Hi: 0x10785, Stride: 1}, + {Lo: 0x10787, Hi: 0x107B0, Stride: 1}, + {Lo: 0x107B2, Hi: 0x107BA, Stride: 1}, + {Lo: 0x10CC0, Hi: 0x10CF2, Stride: 1}, + {Lo: 0x10D70, Hi: 0x10D85, Stride: 1}, + {Lo: 0x118C0, Hi: 0x118DF, Stride: 1}, + {Lo: 0x16E60, Hi: 0x16E7F, Stride: 1}, + {Lo: 0x16EBB, Hi: 0x16ED3, Stride: 1}, + {Lo: 0x1D41A, Hi: 0x1D433, Stride: 1}, + {Lo: 0x1D44E, Hi: 0x1D454, Stride: 1}, + {Lo: 0x1D456, Hi: 0x1D467, Stride: 1}, + {Lo: 0x1D482, Hi: 0x1D49B, Stride: 1}, + {Lo: 0x1D4B6, Hi: 0x1D4B9, Stride: 1}, + {Lo: 0x1D4BB, Hi: 0x1D4BB, Stride: 1}, + {Lo: 0x1D4BD, Hi: 0x1D4C3, Stride: 1}, + {Lo: 0x1D4C5, Hi: 0x1D4CF, Stride: 1}, + {Lo: 0x1D4EA, Hi: 0x1D503, Stride: 1}, + {Lo: 0x1D51E, Hi: 0x1D537, Stride: 1}, + {Lo: 0x1D552, Hi: 0x1D56B, Stride: 1}, + {Lo: 0x1D586, Hi: 0x1D59F, Stride: 1}, + {Lo: 0x1D5BA, Hi: 0x1D5D3, Stride: 1}, + {Lo: 0x1D5EE, Hi: 0x1D607, Stride: 1}, + {Lo: 0x1D622, Hi: 0x1D63B, Stride: 1}, + {Lo: 0x1D656, Hi: 0x1D66F, Stride: 1}, + {Lo: 0x1D68A, Hi: 0x1D6A5, Stride: 1}, + {Lo: 0x1D6C2, Hi: 0x1D6DA, Stride: 1}, + {Lo: 0x1D6DC, Hi: 0x1D6E1, Stride: 1}, + {Lo: 0x1D6FC, Hi: 0x1D714, Stride: 1}, + {Lo: 0x1D716, Hi: 0x1D71B, Stride: 1}, + {Lo: 0x1D736, Hi: 0x1D74E, Stride: 1}, + {Lo: 0x1D750, Hi: 0x1D755, Stride: 1}, + {Lo: 0x1D770, Hi: 0x1D788, Stride: 1}, + {Lo: 0x1D78A, Hi: 0x1D78F, Stride: 1}, + {Lo: 0x1D7AA, Hi: 0x1D7C2, Stride: 1}, + {Lo: 0x1D7C4, Hi: 0x1D7C9, Stride: 1}, + {Lo: 0x1D7CB, Hi: 0x1D7CB, Stride: 1}, + {Lo: 0x1DF00, Hi: 0x1DF09, Stride: 1}, + {Lo: 0x1DF0B, Hi: 0x1DF1E, Stride: 1}, + {Lo: 0x1DF25, Hi: 0x1DF2A, Stride: 1}, + {Lo: 0x1E030, Hi: 0x1E06D, Stride: 1}, + {Lo: 0x1E922, Hi: 0x1E943, Stride: 1}, + }, +} + +var unicodeAliasSentence_Break_Numeric = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0x30, Hi: 0x39, Stride: 1}, + {Lo: 0x600, Hi: 0x605, Stride: 1}, + {Lo: 0x660, Hi: 0x669, Stride: 1}, + {Lo: 0x66B, Hi: 0x66C, Stride: 1}, + {Lo: 0x6DD, Hi: 0x6DD, Stride: 1}, + {Lo: 0x6F0, Hi: 0x6F9, Stride: 1}, + {Lo: 0x7C0, Hi: 0x7C9, Stride: 1}, + {Lo: 0x890, Hi: 0x891, Stride: 1}, + {Lo: 0x8E2, Hi: 0x8E2, Stride: 1}, + {Lo: 0x966, Hi: 0x96F, Stride: 1}, + {Lo: 0x9E6, Hi: 0x9EF, Stride: 1}, + {Lo: 0xA66, Hi: 0xA6F, Stride: 1}, + {Lo: 0xAE6, Hi: 0xAEF, Stride: 1}, + {Lo: 0xB66, Hi: 0xB6F, Stride: 1}, + {Lo: 0xBE6, Hi: 0xBEF, Stride: 1}, + {Lo: 0xC66, Hi: 0xC6F, Stride: 1}, + {Lo: 0xCE6, Hi: 0xCEF, Stride: 1}, + {Lo: 0xD66, Hi: 0xD6F, Stride: 1}, + {Lo: 0xDE6, Hi: 0xDEF, Stride: 1}, + {Lo: 0xE50, Hi: 0xE59, Stride: 1}, + {Lo: 0xED0, Hi: 0xED9, Stride: 1}, + {Lo: 0xF20, Hi: 0xF29, Stride: 1}, + {Lo: 0x1040, Hi: 0x1049, Stride: 1}, + {Lo: 0x1090, Hi: 0x1099, Stride: 1}, + {Lo: 0x17E0, Hi: 0x17E9, Stride: 1}, + {Lo: 0x1810, Hi: 0x1819, Stride: 1}, + {Lo: 0x1946, Hi: 0x194F, Stride: 1}, + {Lo: 0x19D0, Hi: 0x19DA, Stride: 1}, + {Lo: 0x1A80, Hi: 0x1A89, Stride: 1}, + {Lo: 0x1A90, Hi: 0x1A99, Stride: 1}, + {Lo: 0x1B50, Hi: 0x1B59, Stride: 1}, + {Lo: 0x1BB0, Hi: 0x1BB9, Stride: 1}, + {Lo: 0x1C40, Hi: 0x1C49, Stride: 1}, + {Lo: 0x1C50, Hi: 0x1C59, Stride: 1}, + {Lo: 0xA620, Hi: 0xA629, Stride: 1}, + {Lo: 0xA8D0, Hi: 0xA8D9, Stride: 1}, + {Lo: 0xA900, Hi: 0xA909, Stride: 1}, + {Lo: 0xA9D0, Hi: 0xA9D9, Stride: 1}, + {Lo: 0xA9F0, Hi: 0xA9F9, Stride: 1}, + {Lo: 0xAA50, Hi: 0xAA59, Stride: 1}, + {Lo: 0xABF0, Hi: 0xABF9, Stride: 1}, + {Lo: 0xFF10, Hi: 0xFF19, Stride: 1}, + }, + R32: []unicode.Range32{ + {Lo: 0x104A0, Hi: 0x104A9, Stride: 1}, + {Lo: 0x10D30, Hi: 0x10D39, Stride: 1}, + {Lo: 0x10D40, Hi: 0x10D49, Stride: 1}, + {Lo: 0x11066, Hi: 0x1106F, Stride: 1}, + {Lo: 0x110BD, Hi: 0x110BD, Stride: 1}, + {Lo: 0x110CD, Hi: 0x110CD, Stride: 1}, + {Lo: 0x110F0, Hi: 0x110F9, Stride: 1}, + {Lo: 0x11136, Hi: 0x1113F, Stride: 1}, + {Lo: 0x111D0, Hi: 0x111D9, Stride: 1}, + {Lo: 0x112F0, Hi: 0x112F9, Stride: 1}, + {Lo: 0x11450, Hi: 0x11459, Stride: 1}, + {Lo: 0x114D0, Hi: 0x114D9, Stride: 1}, + {Lo: 0x11650, Hi: 0x11659, Stride: 1}, + {Lo: 0x116C0, Hi: 0x116C9, Stride: 1}, + {Lo: 0x116D0, Hi: 0x116E3, Stride: 1}, + {Lo: 0x11730, Hi: 0x11739, Stride: 1}, + {Lo: 0x118E0, Hi: 0x118E9, Stride: 1}, + {Lo: 0x11950, Hi: 0x11959, Stride: 1}, + {Lo: 0x11BF0, Hi: 0x11BF9, Stride: 1}, + {Lo: 0x11C50, Hi: 0x11C59, Stride: 1}, + {Lo: 0x11D50, Hi: 0x11D59, Stride: 1}, + {Lo: 0x11DA0, Hi: 0x11DA9, Stride: 1}, + {Lo: 0x11DE0, Hi: 0x11DE9, Stride: 1}, + {Lo: 0x11F50, Hi: 0x11F59, Stride: 1}, + {Lo: 0x16130, Hi: 0x16139, Stride: 1}, + {Lo: 0x16A60, Hi: 0x16A69, Stride: 1}, + {Lo: 0x16AC0, Hi: 0x16AC9, Stride: 1}, + {Lo: 0x16B50, Hi: 0x16B59, Stride: 1}, + {Lo: 0x16D70, Hi: 0x16D79, Stride: 1}, + {Lo: 0x1CCF0, Hi: 0x1CCF9, Stride: 1}, + {Lo: 0x1D7CE, Hi: 0x1D7FF, Stride: 1}, + {Lo: 0x1E140, Hi: 0x1E149, Stride: 1}, + {Lo: 0x1E2F0, Hi: 0x1E2F9, Stride: 1}, + {Lo: 0x1E4F0, Hi: 0x1E4F9, Stride: 1}, + {Lo: 0x1E5F1, Hi: 0x1E5FA, Stride: 1}, + {Lo: 0x1E950, Hi: 0x1E959, Stride: 1}, + {Lo: 0x1FBF0, Hi: 0x1FBF9, Stride: 1}, + }, +} + +var unicodeAliasSentence_Break_OLetter = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0x1BB, Hi: 0x1BB, Stride: 1}, + {Lo: 0x1C0, Hi: 0x1C3, Stride: 1}, + {Lo: 0x294, Hi: 0x295, Stride: 1}, + {Lo: 0x2B9, Hi: 0x2BF, Stride: 1}, + {Lo: 0x2C6, Hi: 0x2D1, Stride: 1}, + {Lo: 0x2EC, Hi: 0x2EC, Stride: 1}, + {Lo: 0x2EE, Hi: 0x2EE, Stride: 1}, + {Lo: 0x374, Hi: 0x374, Stride: 1}, + {Lo: 0x559, Hi: 0x559, Stride: 1}, + {Lo: 0x5D0, Hi: 0x5EA, Stride: 1}, + {Lo: 0x5EF, Hi: 0x5F3, Stride: 1}, + {Lo: 0x620, Hi: 0x64A, Stride: 1}, + {Lo: 0x66E, Hi: 0x66F, Stride: 1}, + {Lo: 0x671, Hi: 0x6D3, Stride: 1}, + {Lo: 0x6D5, Hi: 0x6D5, Stride: 1}, + {Lo: 0x6E5, Hi: 0x6E6, Stride: 1}, + {Lo: 0x6EE, Hi: 0x6EF, Stride: 1}, + {Lo: 0x6FA, Hi: 0x6FC, Stride: 1}, + {Lo: 0x6FF, Hi: 0x6FF, Stride: 1}, + {Lo: 0x710, Hi: 0x710, Stride: 1}, + {Lo: 0x712, Hi: 0x72F, Stride: 1}, + {Lo: 0x74D, Hi: 0x7A5, Stride: 1}, + {Lo: 0x7B1, Hi: 0x7B1, Stride: 1}, + {Lo: 0x7CA, Hi: 0x7EA, Stride: 1}, + {Lo: 0x7F4, Hi: 0x7F5, Stride: 1}, + {Lo: 0x7FA, Hi: 0x7FA, Stride: 1}, + {Lo: 0x800, Hi: 0x815, Stride: 1}, + {Lo: 0x81A, Hi: 0x81A, Stride: 1}, + {Lo: 0x824, Hi: 0x824, Stride: 1}, + {Lo: 0x828, Hi: 0x828, Stride: 1}, + {Lo: 0x840, Hi: 0x858, Stride: 1}, + {Lo: 0x860, Hi: 0x86A, Stride: 1}, + {Lo: 0x870, Hi: 0x887, Stride: 1}, + {Lo: 0x889, Hi: 0x88F, Stride: 1}, + {Lo: 0x8A0, Hi: 0x8C9, Stride: 1}, + {Lo: 0x904, Hi: 0x939, Stride: 1}, + {Lo: 0x93D, Hi: 0x93D, Stride: 1}, + {Lo: 0x950, Hi: 0x950, Stride: 1}, + {Lo: 0x958, Hi: 0x961, Stride: 1}, + {Lo: 0x971, Hi: 0x980, Stride: 1}, + {Lo: 0x985, Hi: 0x98C, Stride: 1}, + {Lo: 0x98F, Hi: 0x990, Stride: 1}, + {Lo: 0x993, Hi: 0x9A8, Stride: 1}, + {Lo: 0x9AA, Hi: 0x9B0, Stride: 1}, + {Lo: 0x9B2, Hi: 0x9B2, Stride: 1}, + {Lo: 0x9B6, Hi: 0x9B9, Stride: 1}, + {Lo: 0x9BD, Hi: 0x9BD, Stride: 1}, + {Lo: 0x9CE, Hi: 0x9CE, Stride: 1}, + {Lo: 0x9DC, Hi: 0x9DD, Stride: 1}, + {Lo: 0x9DF, Hi: 0x9E1, Stride: 1}, + {Lo: 0x9F0, Hi: 0x9F1, Stride: 1}, + {Lo: 0x9FC, Hi: 0x9FC, Stride: 1}, + {Lo: 0xA05, Hi: 0xA0A, Stride: 1}, + {Lo: 0xA0F, Hi: 0xA10, Stride: 1}, + {Lo: 0xA13, Hi: 0xA28, Stride: 1}, + {Lo: 0xA2A, Hi: 0xA30, Stride: 1}, + {Lo: 0xA32, Hi: 0xA33, Stride: 1}, + {Lo: 0xA35, Hi: 0xA36, Stride: 1}, + {Lo: 0xA38, Hi: 0xA39, Stride: 1}, + {Lo: 0xA59, Hi: 0xA5C, Stride: 1}, + {Lo: 0xA5E, Hi: 0xA5E, Stride: 1}, + {Lo: 0xA72, Hi: 0xA74, Stride: 1}, + {Lo: 0xA85, Hi: 0xA8D, Stride: 1}, + {Lo: 0xA8F, Hi: 0xA91, Stride: 1}, + {Lo: 0xA93, Hi: 0xAA8, Stride: 1}, + {Lo: 0xAAA, Hi: 0xAB0, Stride: 1}, + {Lo: 0xAB2, Hi: 0xAB3, Stride: 1}, + {Lo: 0xAB5, Hi: 0xAB9, Stride: 1}, + {Lo: 0xABD, Hi: 0xABD, Stride: 1}, + {Lo: 0xAD0, Hi: 0xAD0, Stride: 1}, + {Lo: 0xAE0, Hi: 0xAE1, Stride: 1}, + {Lo: 0xAF9, Hi: 0xAF9, Stride: 1}, + {Lo: 0xB05, Hi: 0xB0C, Stride: 1}, + {Lo: 0xB0F, Hi: 0xB10, Stride: 1}, + {Lo: 0xB13, Hi: 0xB28, Stride: 1}, + {Lo: 0xB2A, Hi: 0xB30, Stride: 1}, + {Lo: 0xB32, Hi: 0xB33, Stride: 1}, + {Lo: 0xB35, Hi: 0xB39, Stride: 1}, + {Lo: 0xB3D, Hi: 0xB3D, Stride: 1}, + {Lo: 0xB5C, Hi: 0xB5D, Stride: 1}, + {Lo: 0xB5F, Hi: 0xB61, Stride: 1}, + {Lo: 0xB71, Hi: 0xB71, Stride: 1}, + {Lo: 0xB83, Hi: 0xB83, Stride: 1}, + {Lo: 0xB85, Hi: 0xB8A, Stride: 1}, + {Lo: 0xB8E, Hi: 0xB90, Stride: 1}, + {Lo: 0xB92, Hi: 0xB95, Stride: 1}, + {Lo: 0xB99, Hi: 0xB9A, Stride: 1}, + {Lo: 0xB9C, Hi: 0xB9C, Stride: 1}, + {Lo: 0xB9E, Hi: 0xB9F, Stride: 1}, + {Lo: 0xBA3, Hi: 0xBA4, Stride: 1}, + {Lo: 0xBA8, Hi: 0xBAA, Stride: 1}, + {Lo: 0xBAE, Hi: 0xBB9, Stride: 1}, + {Lo: 0xBD0, Hi: 0xBD0, Stride: 1}, + {Lo: 0xC05, Hi: 0xC0C, Stride: 1}, + {Lo: 0xC0E, Hi: 0xC10, Stride: 1}, + {Lo: 0xC12, Hi: 0xC28, Stride: 1}, + {Lo: 0xC2A, Hi: 0xC39, Stride: 1}, + {Lo: 0xC3D, Hi: 0xC3D, Stride: 1}, + {Lo: 0xC58, Hi: 0xC5A, Stride: 1}, + {Lo: 0xC5C, Hi: 0xC5D, Stride: 1}, + {Lo: 0xC60, Hi: 0xC61, Stride: 1}, + {Lo: 0xC80, Hi: 0xC80, Stride: 1}, + {Lo: 0xC85, Hi: 0xC8C, Stride: 1}, + {Lo: 0xC8E, Hi: 0xC90, Stride: 1}, + {Lo: 0xC92, Hi: 0xCA8, Stride: 1}, + {Lo: 0xCAA, Hi: 0xCB3, Stride: 1}, + {Lo: 0xCB5, Hi: 0xCB9, Stride: 1}, + {Lo: 0xCBD, Hi: 0xCBD, Stride: 1}, + {Lo: 0xCDC, Hi: 0xCDE, Stride: 1}, + {Lo: 0xCE0, Hi: 0xCE1, Stride: 1}, + {Lo: 0xCF1, Hi: 0xCF2, Stride: 1}, + {Lo: 0xD04, Hi: 0xD0C, Stride: 1}, + {Lo: 0xD0E, Hi: 0xD10, Stride: 1}, + {Lo: 0xD12, Hi: 0xD3A, Stride: 1}, + {Lo: 0xD3D, Hi: 0xD3D, Stride: 1}, + {Lo: 0xD4E, Hi: 0xD4E, Stride: 1}, + {Lo: 0xD54, Hi: 0xD56, Stride: 1}, + {Lo: 0xD5F, Hi: 0xD61, Stride: 1}, + {Lo: 0xD7A, Hi: 0xD7F, Stride: 1}, + {Lo: 0xD85, Hi: 0xD96, Stride: 1}, + {Lo: 0xD9A, Hi: 0xDB1, Stride: 1}, + {Lo: 0xDB3, Hi: 0xDBB, Stride: 1}, + {Lo: 0xDBD, Hi: 0xDBD, Stride: 1}, + {Lo: 0xDC0, Hi: 0xDC6, Stride: 1}, + {Lo: 0xE01, Hi: 0xE30, Stride: 1}, + {Lo: 0xE32, Hi: 0xE33, Stride: 1}, + {Lo: 0xE40, Hi: 0xE46, Stride: 1}, + {Lo: 0xE81, Hi: 0xE82, Stride: 1}, + {Lo: 0xE84, Hi: 0xE84, Stride: 1}, + {Lo: 0xE86, Hi: 0xE8A, Stride: 1}, + {Lo: 0xE8C, Hi: 0xEA3, Stride: 1}, + {Lo: 0xEA5, Hi: 0xEA5, Stride: 1}, + {Lo: 0xEA7, Hi: 0xEB0, Stride: 1}, + {Lo: 0xEB2, Hi: 0xEB3, Stride: 1}, + {Lo: 0xEBD, Hi: 0xEBD, Stride: 1}, + {Lo: 0xEC0, Hi: 0xEC4, Stride: 1}, + {Lo: 0xEC6, Hi: 0xEC6, Stride: 1}, + {Lo: 0xEDC, Hi: 0xEDF, Stride: 1}, + {Lo: 0xF00, Hi: 0xF00, Stride: 1}, + {Lo: 0xF40, Hi: 0xF47, Stride: 1}, + {Lo: 0xF49, Hi: 0xF6C, Stride: 1}, + {Lo: 0xF88, Hi: 0xF8C, Stride: 1}, + {Lo: 0x1000, Hi: 0x102A, Stride: 1}, + {Lo: 0x103F, Hi: 0x103F, Stride: 1}, + {Lo: 0x1050, Hi: 0x1055, Stride: 1}, + {Lo: 0x105A, Hi: 0x105D, Stride: 1}, + {Lo: 0x1061, Hi: 0x1061, Stride: 1}, + {Lo: 0x1065, Hi: 0x1066, Stride: 1}, + {Lo: 0x106E, Hi: 0x1070, Stride: 1}, + {Lo: 0x1075, Hi: 0x1081, Stride: 1}, + {Lo: 0x108E, Hi: 0x108E, Stride: 1}, + {Lo: 0x10D0, Hi: 0x10FA, Stride: 1}, + {Lo: 0x10FD, Hi: 0x1248, Stride: 1}, + {Lo: 0x124A, Hi: 0x124D, Stride: 1}, + {Lo: 0x1250, Hi: 0x1256, Stride: 1}, + {Lo: 0x1258, Hi: 0x1258, Stride: 1}, + {Lo: 0x125A, Hi: 0x125D, Stride: 1}, + {Lo: 0x1260, Hi: 0x1288, Stride: 1}, + {Lo: 0x128A, Hi: 0x128D, Stride: 1}, + {Lo: 0x1290, Hi: 0x12B0, Stride: 1}, + {Lo: 0x12B2, Hi: 0x12B5, Stride: 1}, + {Lo: 0x12B8, Hi: 0x12BE, Stride: 1}, + {Lo: 0x12C0, Hi: 0x12C0, Stride: 1}, + {Lo: 0x12C2, Hi: 0x12C5, Stride: 1}, + {Lo: 0x12C8, Hi: 0x12D6, Stride: 1}, + {Lo: 0x12D8, Hi: 0x1310, Stride: 1}, + {Lo: 0x1312, Hi: 0x1315, Stride: 1}, + {Lo: 0x1318, Hi: 0x135A, Stride: 1}, + {Lo: 0x1380, Hi: 0x138F, Stride: 1}, + {Lo: 0x1401, Hi: 0x166C, Stride: 1}, + {Lo: 0x166F, Hi: 0x167F, Stride: 1}, + {Lo: 0x1681, Hi: 0x169A, Stride: 1}, + {Lo: 0x16A0, Hi: 0x16EA, Stride: 1}, + {Lo: 0x16EE, Hi: 0x16F8, Stride: 1}, + {Lo: 0x1700, Hi: 0x1711, Stride: 1}, + {Lo: 0x171F, Hi: 0x1731, Stride: 1}, + {Lo: 0x1740, Hi: 0x1751, Stride: 1}, + {Lo: 0x1760, Hi: 0x176C, Stride: 1}, + {Lo: 0x176E, Hi: 0x1770, Stride: 1}, + {Lo: 0x1780, Hi: 0x17B3, Stride: 1}, + {Lo: 0x17D7, Hi: 0x17D7, Stride: 1}, + {Lo: 0x17DC, Hi: 0x17DC, Stride: 1}, + {Lo: 0x1820, Hi: 0x1878, Stride: 1}, + {Lo: 0x1880, Hi: 0x1884, Stride: 1}, + {Lo: 0x1887, Hi: 0x18A8, Stride: 1}, + {Lo: 0x18AA, Hi: 0x18AA, Stride: 1}, + {Lo: 0x18B0, Hi: 0x18F5, Stride: 1}, + {Lo: 0x1900, Hi: 0x191E, Stride: 1}, + {Lo: 0x1950, Hi: 0x196D, Stride: 1}, + {Lo: 0x1970, Hi: 0x1974, Stride: 1}, + {Lo: 0x1980, Hi: 0x19AB, Stride: 1}, + {Lo: 0x19B0, Hi: 0x19C9, Stride: 1}, + {Lo: 0x1A00, Hi: 0x1A16, Stride: 1}, + {Lo: 0x1A20, Hi: 0x1A54, Stride: 1}, + {Lo: 0x1AA7, Hi: 0x1AA7, Stride: 1}, + {Lo: 0x1B05, Hi: 0x1B33, Stride: 1}, + {Lo: 0x1B45, Hi: 0x1B4C, Stride: 1}, + {Lo: 0x1B83, Hi: 0x1BA0, Stride: 1}, + {Lo: 0x1BAE, Hi: 0x1BAF, Stride: 1}, + {Lo: 0x1BBA, Hi: 0x1BE5, Stride: 1}, + {Lo: 0x1C00, Hi: 0x1C23, Stride: 1}, + {Lo: 0x1C4D, Hi: 0x1C4F, Stride: 1}, + {Lo: 0x1C5A, Hi: 0x1C7D, Stride: 1}, + {Lo: 0x1C90, Hi: 0x1CBA, Stride: 1}, + {Lo: 0x1CBD, Hi: 0x1CBF, Stride: 1}, + {Lo: 0x1CE9, Hi: 0x1CEC, Stride: 1}, + {Lo: 0x1CEE, Hi: 0x1CF3, Stride: 1}, + {Lo: 0x1CF5, Hi: 0x1CF6, Stride: 1}, + {Lo: 0x1CFA, Hi: 0x1CFA, Stride: 1}, + {Lo: 0x2135, Hi: 0x2138, Stride: 1}, + {Lo: 0x2180, Hi: 0x2182, Stride: 1}, + {Lo: 0x2185, Hi: 0x2188, Stride: 1}, + {Lo: 0x2D30, Hi: 0x2D67, Stride: 1}, + {Lo: 0x2D6F, Hi: 0x2D6F, Stride: 1}, + {Lo: 0x2D80, Hi: 0x2D96, Stride: 1}, + {Lo: 0x2DA0, Hi: 0x2DA6, Stride: 1}, + {Lo: 0x2DA8, Hi: 0x2DAE, Stride: 1}, + {Lo: 0x2DB0, Hi: 0x2DB6, Stride: 1}, + {Lo: 0x2DB8, Hi: 0x2DBE, Stride: 1}, + {Lo: 0x2DC0, Hi: 0x2DC6, Stride: 1}, + {Lo: 0x2DC8, Hi: 0x2DCE, Stride: 1}, + {Lo: 0x2DD0, Hi: 0x2DD6, Stride: 1}, + {Lo: 0x2DD8, Hi: 0x2DDE, Stride: 1}, + {Lo: 0x2E2F, Hi: 0x2E2F, Stride: 1}, + {Lo: 0x3005, Hi: 0x3007, Stride: 1}, + {Lo: 0x3021, Hi: 0x3029, Stride: 1}, + {Lo: 0x3031, Hi: 0x3035, Stride: 1}, + {Lo: 0x3038, Hi: 0x303C, Stride: 1}, + {Lo: 0x3041, Hi: 0x3096, Stride: 1}, + {Lo: 0x309D, Hi: 0x309F, Stride: 1}, + {Lo: 0x30A1, Hi: 0x30FA, Stride: 1}, + {Lo: 0x30FC, Hi: 0x30FF, Stride: 1}, + {Lo: 0x3105, Hi: 0x312F, Stride: 1}, + {Lo: 0x3131, Hi: 0x318E, Stride: 1}, + {Lo: 0x31A0, Hi: 0x31BF, Stride: 1}, + {Lo: 0x31F0, Hi: 0x31FF, Stride: 1}, + {Lo: 0x3400, Hi: 0x4DBF, Stride: 1}, + {Lo: 0x4E00, Hi: 0xA48C, Stride: 1}, + {Lo: 0xA4D0, Hi: 0xA4FD, Stride: 1}, + {Lo: 0xA500, Hi: 0xA60C, Stride: 1}, + {Lo: 0xA610, Hi: 0xA61F, Stride: 1}, + {Lo: 0xA62A, Hi: 0xA62B, Stride: 1}, + {Lo: 0xA66E, Hi: 0xA66E, Stride: 1}, + {Lo: 0xA67F, Hi: 0xA67F, Stride: 1}, + {Lo: 0xA6A0, Hi: 0xA6EF, Stride: 1}, + {Lo: 0xA717, Hi: 0xA71F, Stride: 1}, + {Lo: 0xA788, Hi: 0xA788, Stride: 1}, + {Lo: 0xA78F, Hi: 0xA78F, Stride: 1}, + {Lo: 0xA7F7, Hi: 0xA7F7, Stride: 1}, + {Lo: 0xA7FB, Hi: 0xA801, Stride: 1}, + {Lo: 0xA803, Hi: 0xA805, Stride: 1}, + {Lo: 0xA807, Hi: 0xA80A, Stride: 1}, + {Lo: 0xA80C, Hi: 0xA822, Stride: 1}, + {Lo: 0xA840, Hi: 0xA873, Stride: 1}, + {Lo: 0xA882, Hi: 0xA8B3, Stride: 1}, + {Lo: 0xA8F2, Hi: 0xA8F7, Stride: 1}, + {Lo: 0xA8FB, Hi: 0xA8FB, Stride: 1}, + {Lo: 0xA8FD, Hi: 0xA8FE, Stride: 1}, + {Lo: 0xA90A, Hi: 0xA925, Stride: 1}, + {Lo: 0xA930, Hi: 0xA946, Stride: 1}, + {Lo: 0xA960, Hi: 0xA97C, Stride: 1}, + {Lo: 0xA984, Hi: 0xA9B2, Stride: 1}, + {Lo: 0xA9CF, Hi: 0xA9CF, Stride: 1}, + {Lo: 0xA9E0, Hi: 0xA9E4, Stride: 1}, + {Lo: 0xA9E6, Hi: 0xA9EF, Stride: 1}, + {Lo: 0xA9FA, Hi: 0xA9FE, Stride: 1}, + {Lo: 0xAA00, Hi: 0xAA28, Stride: 1}, + {Lo: 0xAA40, Hi: 0xAA42, Stride: 1}, + {Lo: 0xAA44, Hi: 0xAA4B, Stride: 1}, + {Lo: 0xAA60, Hi: 0xAA76, Stride: 1}, + {Lo: 0xAA7A, Hi: 0xAA7A, Stride: 1}, + {Lo: 0xAA7E, Hi: 0xAAAF, Stride: 1}, + {Lo: 0xAAB1, Hi: 0xAAB1, Stride: 1}, + {Lo: 0xAAB5, Hi: 0xAAB6, Stride: 1}, + {Lo: 0xAAB9, Hi: 0xAABD, Stride: 1}, + {Lo: 0xAAC0, Hi: 0xAAC0, Stride: 1}, + {Lo: 0xAAC2, Hi: 0xAAC2, Stride: 1}, + {Lo: 0xAADB, Hi: 0xAADD, Stride: 1}, + {Lo: 0xAAE0, Hi: 0xAAEA, Stride: 1}, + {Lo: 0xAAF2, Hi: 0xAAF4, Stride: 1}, + {Lo: 0xAB01, Hi: 0xAB06, Stride: 1}, + {Lo: 0xAB09, Hi: 0xAB0E, Stride: 1}, + {Lo: 0xAB11, Hi: 0xAB16, Stride: 1}, + {Lo: 0xAB20, Hi: 0xAB26, Stride: 1}, + {Lo: 0xAB28, Hi: 0xAB2E, Stride: 1}, + {Lo: 0xABC0, Hi: 0xABE2, Stride: 1}, + {Lo: 0xAC00, Hi: 0xD7A3, Stride: 1}, + {Lo: 0xD7B0, Hi: 0xD7C6, Stride: 1}, + {Lo: 0xD7CB, Hi: 0xD7FB, Stride: 1}, + {Lo: 0xF900, Hi: 0xFA6D, Stride: 1}, + {Lo: 0xFA70, Hi: 0xFAD9, Stride: 1}, + {Lo: 0xFB1D, Hi: 0xFB1D, Stride: 1}, + {Lo: 0xFB1F, Hi: 0xFB28, Stride: 1}, + {Lo: 0xFB2A, Hi: 0xFB36, Stride: 1}, + {Lo: 0xFB38, Hi: 0xFB3C, Stride: 1}, + {Lo: 0xFB3E, Hi: 0xFB3E, Stride: 1}, + {Lo: 0xFB40, Hi: 0xFB41, Stride: 1}, + {Lo: 0xFB43, Hi: 0xFB44, Stride: 1}, + {Lo: 0xFB46, Hi: 0xFBB1, Stride: 1}, + {Lo: 0xFBD3, Hi: 0xFD3D, Stride: 1}, + {Lo: 0xFD50, Hi: 0xFD8F, Stride: 1}, + {Lo: 0xFD92, Hi: 0xFDC7, Stride: 1}, + {Lo: 0xFDF0, Hi: 0xFDFB, Stride: 1}, + {Lo: 0xFE70, Hi: 0xFE74, Stride: 1}, + {Lo: 0xFE76, Hi: 0xFEFC, Stride: 1}, + {Lo: 0xFF66, Hi: 0xFF9D, Stride: 1}, + {Lo: 0xFFA0, Hi: 0xFFBE, Stride: 1}, + {Lo: 0xFFC2, Hi: 0xFFC7, Stride: 1}, + {Lo: 0xFFCA, Hi: 0xFFCF, Stride: 1}, + {Lo: 0xFFD2, Hi: 0xFFD7, Stride: 1}, + {Lo: 0xFFDA, Hi: 0xFFDC, Stride: 1}, + }, + R32: []unicode.Range32{ + {Lo: 0x10000, Hi: 0x1000B, Stride: 1}, + {Lo: 0x1000D, Hi: 0x10026, Stride: 1}, + {Lo: 0x10028, Hi: 0x1003A, Stride: 1}, + {Lo: 0x1003C, Hi: 0x1003D, Stride: 1}, + {Lo: 0x1003F, Hi: 0x1004D, Stride: 1}, + {Lo: 0x10050, Hi: 0x1005D, Stride: 1}, + {Lo: 0x10080, Hi: 0x100FA, Stride: 1}, + {Lo: 0x10140, Hi: 0x10174, Stride: 1}, + {Lo: 0x10280, Hi: 0x1029C, Stride: 1}, + {Lo: 0x102A0, Hi: 0x102D0, Stride: 1}, + {Lo: 0x10300, Hi: 0x1031F, Stride: 1}, + {Lo: 0x1032D, Hi: 0x1034A, Stride: 1}, + {Lo: 0x10350, Hi: 0x10375, Stride: 1}, + {Lo: 0x10380, Hi: 0x1039D, Stride: 1}, + {Lo: 0x103A0, Hi: 0x103C3, Stride: 1}, + {Lo: 0x103C8, Hi: 0x103CF, Stride: 1}, + {Lo: 0x103D1, Hi: 0x103D5, Stride: 1}, + {Lo: 0x10450, Hi: 0x1049D, Stride: 1}, + {Lo: 0x10500, Hi: 0x10527, Stride: 1}, + {Lo: 0x10530, Hi: 0x10563, Stride: 1}, + {Lo: 0x105C0, Hi: 0x105F3, Stride: 1}, + {Lo: 0x10600, Hi: 0x10736, Stride: 1}, + {Lo: 0x10740, Hi: 0x10755, Stride: 1}, + {Lo: 0x10760, Hi: 0x10767, Stride: 1}, + {Lo: 0x10781, Hi: 0x10782, Stride: 1}, + {Lo: 0x10800, Hi: 0x10805, Stride: 1}, + {Lo: 0x10808, Hi: 0x10808, Stride: 1}, + {Lo: 0x1080A, Hi: 0x10835, Stride: 1}, + {Lo: 0x10837, Hi: 0x10838, Stride: 1}, + {Lo: 0x1083C, Hi: 0x1083C, Stride: 1}, + {Lo: 0x1083F, Hi: 0x10855, Stride: 1}, + {Lo: 0x10860, Hi: 0x10876, Stride: 1}, + {Lo: 0x10880, Hi: 0x1089E, Stride: 1}, + {Lo: 0x108E0, Hi: 0x108F2, Stride: 1}, + {Lo: 0x108F4, Hi: 0x108F5, Stride: 1}, + {Lo: 0x10900, Hi: 0x10915, Stride: 1}, + {Lo: 0x10920, Hi: 0x10939, Stride: 1}, + {Lo: 0x10940, Hi: 0x10959, Stride: 1}, + {Lo: 0x10980, Hi: 0x109B7, Stride: 1}, + {Lo: 0x109BE, Hi: 0x109BF, Stride: 1}, + {Lo: 0x10A00, Hi: 0x10A00, Stride: 1}, + {Lo: 0x10A10, Hi: 0x10A13, Stride: 1}, + {Lo: 0x10A15, Hi: 0x10A17, Stride: 1}, + {Lo: 0x10A19, Hi: 0x10A35, Stride: 1}, + {Lo: 0x10A60, Hi: 0x10A7C, Stride: 1}, + {Lo: 0x10A80, Hi: 0x10A9C, Stride: 1}, + {Lo: 0x10AC0, Hi: 0x10AC7, Stride: 1}, + {Lo: 0x10AC9, Hi: 0x10AE4, Stride: 1}, + {Lo: 0x10B00, Hi: 0x10B35, Stride: 1}, + {Lo: 0x10B40, Hi: 0x10B55, Stride: 1}, + {Lo: 0x10B60, Hi: 0x10B72, Stride: 1}, + {Lo: 0x10B80, Hi: 0x10B91, Stride: 1}, + {Lo: 0x10C00, Hi: 0x10C48, Stride: 1}, + {Lo: 0x10D00, Hi: 0x10D23, Stride: 1}, + {Lo: 0x10D4A, Hi: 0x10D4F, Stride: 1}, + {Lo: 0x10D6F, Hi: 0x10D6F, Stride: 1}, + {Lo: 0x10E80, Hi: 0x10EA9, Stride: 1}, + {Lo: 0x10EB0, Hi: 0x10EB1, Stride: 1}, + {Lo: 0x10EC2, Hi: 0x10EC7, Stride: 1}, + {Lo: 0x10F00, Hi: 0x10F1C, Stride: 1}, + {Lo: 0x10F27, Hi: 0x10F27, Stride: 1}, + {Lo: 0x10F30, Hi: 0x10F45, Stride: 1}, + {Lo: 0x10F70, Hi: 0x10F81, Stride: 1}, + {Lo: 0x10FB0, Hi: 0x10FC4, Stride: 1}, + {Lo: 0x10FE0, Hi: 0x10FF6, Stride: 1}, + {Lo: 0x11003, Hi: 0x11037, Stride: 1}, + {Lo: 0x11071, Hi: 0x11072, Stride: 1}, + {Lo: 0x11075, Hi: 0x11075, Stride: 1}, + {Lo: 0x11083, Hi: 0x110AF, Stride: 1}, + {Lo: 0x110D0, Hi: 0x110E8, Stride: 1}, + {Lo: 0x11103, Hi: 0x11126, Stride: 1}, + {Lo: 0x11144, Hi: 0x11144, Stride: 1}, + {Lo: 0x11147, Hi: 0x11147, Stride: 1}, + {Lo: 0x11150, Hi: 0x11172, Stride: 1}, + {Lo: 0x11176, Hi: 0x11176, Stride: 1}, + {Lo: 0x11183, Hi: 0x111B2, Stride: 1}, + {Lo: 0x111C1, Hi: 0x111C4, Stride: 1}, + {Lo: 0x111DA, Hi: 0x111DA, Stride: 1}, + {Lo: 0x111DC, Hi: 0x111DC, Stride: 1}, + {Lo: 0x11200, Hi: 0x11211, Stride: 1}, + {Lo: 0x11213, Hi: 0x1122B, Stride: 1}, + {Lo: 0x1123F, Hi: 0x11240, Stride: 1}, + {Lo: 0x11280, Hi: 0x11286, Stride: 1}, + {Lo: 0x11288, Hi: 0x11288, Stride: 1}, + {Lo: 0x1128A, Hi: 0x1128D, Stride: 1}, + {Lo: 0x1128F, Hi: 0x1129D, Stride: 1}, + {Lo: 0x1129F, Hi: 0x112A8, Stride: 1}, + {Lo: 0x112B0, Hi: 0x112DE, Stride: 1}, + {Lo: 0x11305, Hi: 0x1130C, Stride: 1}, + {Lo: 0x1130F, Hi: 0x11310, Stride: 1}, + {Lo: 0x11313, Hi: 0x11328, Stride: 1}, + {Lo: 0x1132A, Hi: 0x11330, Stride: 1}, + {Lo: 0x11332, Hi: 0x11333, Stride: 1}, + {Lo: 0x11335, Hi: 0x11339, Stride: 1}, + {Lo: 0x1133D, Hi: 0x1133D, Stride: 1}, + {Lo: 0x11350, Hi: 0x11350, Stride: 1}, + {Lo: 0x1135D, Hi: 0x11361, Stride: 1}, + {Lo: 0x11380, Hi: 0x11389, Stride: 1}, + {Lo: 0x1138B, Hi: 0x1138B, Stride: 1}, + {Lo: 0x1138E, Hi: 0x1138E, Stride: 1}, + {Lo: 0x11390, Hi: 0x113B5, Stride: 1}, + {Lo: 0x113B7, Hi: 0x113B7, Stride: 1}, + {Lo: 0x113D1, Hi: 0x113D1, Stride: 1}, + {Lo: 0x113D3, Hi: 0x113D3, Stride: 1}, + {Lo: 0x11400, Hi: 0x11434, Stride: 1}, + {Lo: 0x11447, Hi: 0x1144A, Stride: 1}, + {Lo: 0x1145F, Hi: 0x11461, Stride: 1}, + {Lo: 0x11480, Hi: 0x114AF, Stride: 1}, + {Lo: 0x114C4, Hi: 0x114C5, Stride: 1}, + {Lo: 0x114C7, Hi: 0x114C7, Stride: 1}, + {Lo: 0x11580, Hi: 0x115AE, Stride: 1}, + {Lo: 0x115D8, Hi: 0x115DB, Stride: 1}, + {Lo: 0x11600, Hi: 0x1162F, Stride: 1}, + {Lo: 0x11644, Hi: 0x11644, Stride: 1}, + {Lo: 0x11680, Hi: 0x116AA, Stride: 1}, + {Lo: 0x116B8, Hi: 0x116B8, Stride: 1}, + {Lo: 0x11700, Hi: 0x1171A, Stride: 1}, + {Lo: 0x11740, Hi: 0x11746, Stride: 1}, + {Lo: 0x11800, Hi: 0x1182B, Stride: 1}, + {Lo: 0x118FF, Hi: 0x11906, Stride: 1}, + {Lo: 0x11909, Hi: 0x11909, Stride: 1}, + {Lo: 0x1190C, Hi: 0x11913, Stride: 1}, + {Lo: 0x11915, Hi: 0x11916, Stride: 1}, + {Lo: 0x11918, Hi: 0x1192F, Stride: 1}, + {Lo: 0x1193F, Hi: 0x1193F, Stride: 1}, + {Lo: 0x11941, Hi: 0x11941, Stride: 1}, + {Lo: 0x119A0, Hi: 0x119A7, Stride: 1}, + {Lo: 0x119AA, Hi: 0x119D0, Stride: 1}, + {Lo: 0x119E1, Hi: 0x119E1, Stride: 1}, + {Lo: 0x119E3, Hi: 0x119E3, Stride: 1}, + {Lo: 0x11A00, Hi: 0x11A00, Stride: 1}, + {Lo: 0x11A0B, Hi: 0x11A32, Stride: 1}, + {Lo: 0x11A3A, Hi: 0x11A3A, Stride: 1}, + {Lo: 0x11A50, Hi: 0x11A50, Stride: 1}, + {Lo: 0x11A5C, Hi: 0x11A89, Stride: 1}, + {Lo: 0x11A9D, Hi: 0x11A9D, Stride: 1}, + {Lo: 0x11AB0, Hi: 0x11AF8, Stride: 1}, + {Lo: 0x11BC0, Hi: 0x11BE0, Stride: 1}, + {Lo: 0x11C00, Hi: 0x11C08, Stride: 1}, + {Lo: 0x11C0A, Hi: 0x11C2E, Stride: 1}, + {Lo: 0x11C40, Hi: 0x11C40, Stride: 1}, + {Lo: 0x11C72, Hi: 0x11C8F, Stride: 1}, + {Lo: 0x11D00, Hi: 0x11D06, Stride: 1}, + {Lo: 0x11D08, Hi: 0x11D09, Stride: 1}, + {Lo: 0x11D0B, Hi: 0x11D30, Stride: 1}, + {Lo: 0x11D46, Hi: 0x11D46, Stride: 1}, + {Lo: 0x11D60, Hi: 0x11D65, Stride: 1}, + {Lo: 0x11D67, Hi: 0x11D68, Stride: 1}, + {Lo: 0x11D6A, Hi: 0x11D89, Stride: 1}, + {Lo: 0x11D98, Hi: 0x11D98, Stride: 1}, + {Lo: 0x11DB0, Hi: 0x11DDB, Stride: 1}, + {Lo: 0x11EE0, Hi: 0x11EF2, Stride: 1}, + {Lo: 0x11F02, Hi: 0x11F02, Stride: 1}, + {Lo: 0x11F04, Hi: 0x11F10, Stride: 1}, + {Lo: 0x11F12, Hi: 0x11F33, Stride: 1}, + {Lo: 0x11FB0, Hi: 0x11FB0, Stride: 1}, + {Lo: 0x12000, Hi: 0x12399, Stride: 1}, + {Lo: 0x12400, Hi: 0x1246E, Stride: 1}, + {Lo: 0x12480, Hi: 0x12543, Stride: 1}, + {Lo: 0x12F90, Hi: 0x12FF0, Stride: 1}, + {Lo: 0x13000, Hi: 0x1342F, Stride: 1}, + {Lo: 0x13441, Hi: 0x13446, Stride: 1}, + {Lo: 0x13460, Hi: 0x143FA, Stride: 1}, + {Lo: 0x14400, Hi: 0x14646, Stride: 1}, + {Lo: 0x16100, Hi: 0x1611D, Stride: 1}, + {Lo: 0x16800, Hi: 0x16A38, Stride: 1}, + {Lo: 0x16A40, Hi: 0x16A5E, Stride: 1}, + {Lo: 0x16A70, Hi: 0x16ABE, Stride: 1}, + {Lo: 0x16AD0, Hi: 0x16AED, Stride: 1}, + {Lo: 0x16B00, Hi: 0x16B2F, Stride: 1}, + {Lo: 0x16B40, Hi: 0x16B43, Stride: 1}, + {Lo: 0x16B63, Hi: 0x16B77, Stride: 1}, + {Lo: 0x16B7D, Hi: 0x16B8F, Stride: 1}, + {Lo: 0x16D40, Hi: 0x16D6C, Stride: 1}, + {Lo: 0x16F00, Hi: 0x16F4A, Stride: 1}, + {Lo: 0x16F50, Hi: 0x16F50, Stride: 1}, + {Lo: 0x16F93, Hi: 0x16F9F, Stride: 1}, + {Lo: 0x16FE0, Hi: 0x16FE1, Stride: 1}, + {Lo: 0x16FE3, Hi: 0x16FE3, Stride: 1}, + {Lo: 0x16FF2, Hi: 0x16FF6, Stride: 1}, + {Lo: 0x17000, Hi: 0x18CD5, Stride: 1}, + {Lo: 0x18CFF, Hi: 0x18D1E, Stride: 1}, + {Lo: 0x18D80, Hi: 0x18DF2, Stride: 1}, + {Lo: 0x1AFF0, Hi: 0x1AFF3, Stride: 1}, + {Lo: 0x1AFF5, Hi: 0x1AFFB, Stride: 1}, + {Lo: 0x1AFFD, Hi: 0x1AFFE, Stride: 1}, + {Lo: 0x1B000, Hi: 0x1B122, Stride: 1}, + {Lo: 0x1B132, Hi: 0x1B132, Stride: 1}, + {Lo: 0x1B150, Hi: 0x1B152, Stride: 1}, + {Lo: 0x1B155, Hi: 0x1B155, Stride: 1}, + {Lo: 0x1B164, Hi: 0x1B167, Stride: 1}, + {Lo: 0x1B170, Hi: 0x1B2FB, Stride: 1}, + {Lo: 0x1BC00, Hi: 0x1BC6A, Stride: 1}, + {Lo: 0x1BC70, Hi: 0x1BC7C, Stride: 1}, + {Lo: 0x1BC80, Hi: 0x1BC88, Stride: 1}, + {Lo: 0x1BC90, Hi: 0x1BC99, Stride: 1}, + {Lo: 0x1DF0A, Hi: 0x1DF0A, Stride: 1}, + {Lo: 0x1E100, Hi: 0x1E12C, Stride: 1}, + {Lo: 0x1E137, Hi: 0x1E13D, Stride: 1}, + {Lo: 0x1E14E, Hi: 0x1E14E, Stride: 1}, + {Lo: 0x1E290, Hi: 0x1E2AD, Stride: 1}, + {Lo: 0x1E2C0, Hi: 0x1E2EB, Stride: 1}, + {Lo: 0x1E4D0, Hi: 0x1E4EB, Stride: 1}, + {Lo: 0x1E5D0, Hi: 0x1E5ED, Stride: 1}, + {Lo: 0x1E5F0, Hi: 0x1E5F0, Stride: 1}, + {Lo: 0x1E6C0, Hi: 0x1E6DE, Stride: 1}, + {Lo: 0x1E6E0, Hi: 0x1E6E2, Stride: 1}, + {Lo: 0x1E6E4, Hi: 0x1E6E5, Stride: 1}, + {Lo: 0x1E6E7, Hi: 0x1E6ED, Stride: 1}, + {Lo: 0x1E6F0, Hi: 0x1E6F4, Stride: 1}, + {Lo: 0x1E6FE, Hi: 0x1E6FF, Stride: 1}, + {Lo: 0x1E7E0, Hi: 0x1E7E6, Stride: 1}, + {Lo: 0x1E7E8, Hi: 0x1E7EB, Stride: 1}, + {Lo: 0x1E7ED, Hi: 0x1E7EE, Stride: 1}, + {Lo: 0x1E7F0, Hi: 0x1E7FE, Stride: 1}, + {Lo: 0x1E800, Hi: 0x1E8C4, Stride: 1}, + {Lo: 0x1E94B, Hi: 0x1E94B, Stride: 1}, + {Lo: 0x1EE00, Hi: 0x1EE03, Stride: 1}, + {Lo: 0x1EE05, Hi: 0x1EE1F, Stride: 1}, + {Lo: 0x1EE21, Hi: 0x1EE22, Stride: 1}, + {Lo: 0x1EE24, Hi: 0x1EE24, Stride: 1}, + {Lo: 0x1EE27, Hi: 0x1EE27, Stride: 1}, + {Lo: 0x1EE29, Hi: 0x1EE32, Stride: 1}, + {Lo: 0x1EE34, Hi: 0x1EE37, Stride: 1}, + {Lo: 0x1EE39, Hi: 0x1EE39, Stride: 1}, + {Lo: 0x1EE3B, Hi: 0x1EE3B, Stride: 1}, + {Lo: 0x1EE42, Hi: 0x1EE42, Stride: 1}, + {Lo: 0x1EE47, Hi: 0x1EE47, Stride: 1}, + {Lo: 0x1EE49, Hi: 0x1EE49, Stride: 1}, + {Lo: 0x1EE4B, Hi: 0x1EE4B, Stride: 1}, + {Lo: 0x1EE4D, Hi: 0x1EE4F, Stride: 1}, + {Lo: 0x1EE51, Hi: 0x1EE52, Stride: 1}, + {Lo: 0x1EE54, Hi: 0x1EE54, Stride: 1}, + {Lo: 0x1EE57, Hi: 0x1EE57, Stride: 1}, + {Lo: 0x1EE59, Hi: 0x1EE59, Stride: 1}, + {Lo: 0x1EE5B, Hi: 0x1EE5B, Stride: 1}, + {Lo: 0x1EE5D, Hi: 0x1EE5D, Stride: 1}, + {Lo: 0x1EE5F, Hi: 0x1EE5F, Stride: 1}, + {Lo: 0x1EE61, Hi: 0x1EE62, Stride: 1}, + {Lo: 0x1EE64, Hi: 0x1EE64, Stride: 1}, + {Lo: 0x1EE67, Hi: 0x1EE6A, Stride: 1}, + {Lo: 0x1EE6C, Hi: 0x1EE72, Stride: 1}, + {Lo: 0x1EE74, Hi: 0x1EE77, Stride: 1}, + {Lo: 0x1EE79, Hi: 0x1EE7C, Stride: 1}, + {Lo: 0x1EE7E, Hi: 0x1EE7E, Stride: 1}, + {Lo: 0x1EE80, Hi: 0x1EE89, Stride: 1}, + {Lo: 0x1EE8B, Hi: 0x1EE9B, Stride: 1}, + {Lo: 0x1EEA1, Hi: 0x1EEA3, Stride: 1}, + {Lo: 0x1EEA5, Hi: 0x1EEA9, Stride: 1}, + {Lo: 0x1EEAB, Hi: 0x1EEBB, Stride: 1}, + {Lo: 0x20000, Hi: 0x2A6DF, Stride: 1}, + {Lo: 0x2A700, Hi: 0x2B81D, Stride: 1}, + {Lo: 0x2B820, Hi: 0x2CEAD, Stride: 1}, + {Lo: 0x2CEB0, Hi: 0x2EBE0, Stride: 1}, + {Lo: 0x2EBF0, Hi: 0x2EE5D, Stride: 1}, + {Lo: 0x2F800, Hi: 0x2FA1D, Stride: 1}, + {Lo: 0x30000, Hi: 0x3134A, Stride: 1}, + {Lo: 0x31350, Hi: 0x33479, Stride: 1}, + }, +} + +var unicodeAliasSentence_Break_SContinue = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0x2C, Hi: 0x2D, Stride: 1}, + {Lo: 0x3A, Hi: 0x3B, Stride: 1}, + {Lo: 0x37E, Hi: 0x37E, Stride: 1}, + {Lo: 0x55D, Hi: 0x55D, Stride: 1}, + {Lo: 0x60C, Hi: 0x60D, Stride: 1}, + {Lo: 0x7F8, Hi: 0x7F8, Stride: 1}, + {Lo: 0x1802, Hi: 0x1802, Stride: 1}, + {Lo: 0x1808, Hi: 0x1808, Stride: 1}, + {Lo: 0x2013, Hi: 0x2014, Stride: 1}, + {Lo: 0x3001, Hi: 0x3001, Stride: 1}, + {Lo: 0xFE10, Hi: 0xFE11, Stride: 1}, + {Lo: 0xFE13, Hi: 0xFE14, Stride: 1}, + {Lo: 0xFE31, Hi: 0xFE32, Stride: 1}, + {Lo: 0xFE50, Hi: 0xFE51, Stride: 1}, + {Lo: 0xFE54, Hi: 0xFE55, Stride: 1}, + {Lo: 0xFE58, Hi: 0xFE58, Stride: 1}, + {Lo: 0xFE63, Hi: 0xFE63, Stride: 1}, + {Lo: 0xFF0C, Hi: 0xFF0D, Stride: 1}, + {Lo: 0xFF1A, Hi: 0xFF1B, Stride: 1}, + {Lo: 0xFF64, Hi: 0xFF64, Stride: 1}, + }, +} + +var unicodeAliasSentence_Break_STerm = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0x21, Hi: 0x21, Stride: 1}, + {Lo: 0x3F, Hi: 0x3F, Stride: 1}, + {Lo: 0x589, Hi: 0x589, Stride: 1}, + {Lo: 0x61D, Hi: 0x61F, Stride: 1}, + {Lo: 0x6D4, Hi: 0x6D4, Stride: 1}, + {Lo: 0x700, Hi: 0x702, Stride: 1}, + {Lo: 0x7F9, Hi: 0x7F9, Stride: 1}, + {Lo: 0x837, Hi: 0x837, Stride: 1}, + {Lo: 0x839, Hi: 0x839, Stride: 1}, + {Lo: 0x83D, Hi: 0x83E, Stride: 1}, + {Lo: 0x964, Hi: 0x965, Stride: 1}, + {Lo: 0x104A, Hi: 0x104B, Stride: 1}, + {Lo: 0x1362, Hi: 0x1362, Stride: 1}, + {Lo: 0x1367, Hi: 0x1368, Stride: 1}, + {Lo: 0x166E, Hi: 0x166E, Stride: 1}, + {Lo: 0x1735, Hi: 0x1736, Stride: 1}, + {Lo: 0x17D4, Hi: 0x17D5, Stride: 1}, + {Lo: 0x1803, Hi: 0x1803, Stride: 1}, + {Lo: 0x1809, Hi: 0x1809, Stride: 1}, + {Lo: 0x1944, Hi: 0x1945, Stride: 1}, + {Lo: 0x1AA8, Hi: 0x1AAB, Stride: 1}, + {Lo: 0x1B4E, Hi: 0x1B4F, Stride: 1}, + {Lo: 0x1B5A, Hi: 0x1B5B, Stride: 1}, + {Lo: 0x1B5E, Hi: 0x1B5F, Stride: 1}, + {Lo: 0x1B7D, Hi: 0x1B7F, Stride: 1}, + {Lo: 0x1C3B, Hi: 0x1C3C, Stride: 1}, + {Lo: 0x1C7E, Hi: 0x1C7F, Stride: 1}, + {Lo: 0x203C, Hi: 0x203D, Stride: 1}, + {Lo: 0x2047, Hi: 0x2049, Stride: 1}, + {Lo: 0x2CF9, Hi: 0x2CFB, Stride: 1}, + {Lo: 0x2E2E, Hi: 0x2E2E, Stride: 1}, + {Lo: 0x2E3C, Hi: 0x2E3C, Stride: 1}, + {Lo: 0x2E53, Hi: 0x2E54, Stride: 1}, + {Lo: 0x3002, Hi: 0x3002, Stride: 1}, + {Lo: 0xA4FF, Hi: 0xA4FF, Stride: 1}, + {Lo: 0xA60E, Hi: 0xA60F, Stride: 1}, + {Lo: 0xA6F3, Hi: 0xA6F3, Stride: 1}, + {Lo: 0xA6F7, Hi: 0xA6F7, Stride: 1}, + {Lo: 0xA876, Hi: 0xA877, Stride: 1}, + {Lo: 0xA8CE, Hi: 0xA8CF, Stride: 1}, + {Lo: 0xA92F, Hi: 0xA92F, Stride: 1}, + {Lo: 0xA9C8, Hi: 0xA9C9, Stride: 1}, + {Lo: 0xAA5D, Hi: 0xAA5F, Stride: 1}, + {Lo: 0xAAF0, Hi: 0xAAF1, Stride: 1}, + {Lo: 0xABEB, Hi: 0xABEB, Stride: 1}, + {Lo: 0xFE12, Hi: 0xFE12, Stride: 1}, + {Lo: 0xFE15, Hi: 0xFE16, Stride: 1}, + {Lo: 0xFE56, Hi: 0xFE57, Stride: 1}, + {Lo: 0xFF01, Hi: 0xFF01, Stride: 1}, + {Lo: 0xFF1F, Hi: 0xFF1F, Stride: 1}, + {Lo: 0xFF61, Hi: 0xFF61, Stride: 1}, + }, + R32: []unicode.Range32{ + {Lo: 0x10A56, Hi: 0x10A57, Stride: 1}, + {Lo: 0x10F55, Hi: 0x10F59, Stride: 1}, + {Lo: 0x10F86, Hi: 0x10F89, Stride: 1}, + {Lo: 0x11047, Hi: 0x11048, Stride: 1}, + {Lo: 0x110BE, Hi: 0x110C1, Stride: 1}, + {Lo: 0x11141, Hi: 0x11143, Stride: 1}, + {Lo: 0x111C5, Hi: 0x111C6, Stride: 1}, + {Lo: 0x111CD, Hi: 0x111CD, Stride: 1}, + {Lo: 0x111DE, Hi: 0x111DF, Stride: 1}, + {Lo: 0x11238, Hi: 0x11239, Stride: 1}, + {Lo: 0x1123B, Hi: 0x1123C, Stride: 1}, + {Lo: 0x112A9, Hi: 0x112A9, Stride: 1}, + {Lo: 0x113D4, Hi: 0x113D5, Stride: 1}, + {Lo: 0x1144B, Hi: 0x1144C, Stride: 1}, + {Lo: 0x115C2, Hi: 0x115C3, Stride: 1}, + {Lo: 0x115C9, Hi: 0x115D7, Stride: 1}, + {Lo: 0x11641, Hi: 0x11642, Stride: 1}, + {Lo: 0x1173C, Hi: 0x1173E, Stride: 1}, + {Lo: 0x11944, Hi: 0x11944, Stride: 1}, + {Lo: 0x11946, Hi: 0x11946, Stride: 1}, + {Lo: 0x11A42, Hi: 0x11A43, Stride: 1}, + {Lo: 0x11A9B, Hi: 0x11A9C, Stride: 1}, + {Lo: 0x11C41, Hi: 0x11C42, Stride: 1}, + {Lo: 0x11EF7, Hi: 0x11EF8, Stride: 1}, + {Lo: 0x11F43, Hi: 0x11F44, Stride: 1}, + {Lo: 0x16A6E, Hi: 0x16A6F, Stride: 1}, + {Lo: 0x16AF5, Hi: 0x16AF5, Stride: 1}, + {Lo: 0x16B37, Hi: 0x16B38, Stride: 1}, + {Lo: 0x16B44, Hi: 0x16B44, Stride: 1}, + {Lo: 0x16D6E, Hi: 0x16D6F, Stride: 1}, + {Lo: 0x16E98, Hi: 0x16E98, Stride: 1}, + {Lo: 0x1BC9F, Hi: 0x1BC9F, Stride: 1}, + {Lo: 0x1DA88, Hi: 0x1DA88, Stride: 1}, + }, +} + +var unicodeAliasSentence_Break_Sep = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0x85, Hi: 0x85, Stride: 1}, + {Lo: 0x2028, Hi: 0x2029, Stride: 1}, + }, +} + +var unicodeAliasSentence_Break_Sp = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0x9, Hi: 0x9, Stride: 1}, + {Lo: 0xB, Hi: 0xC, Stride: 1}, + {Lo: 0x20, Hi: 0x20, Stride: 1}, + {Lo: 0xA0, Hi: 0xA0, Stride: 1}, + {Lo: 0x1680, Hi: 0x1680, Stride: 1}, + {Lo: 0x2000, Hi: 0x200A, Stride: 1}, + {Lo: 0x202F, Hi: 0x202F, Stride: 1}, + {Lo: 0x205F, Hi: 0x205F, Stride: 1}, + {Lo: 0x3000, Hi: 0x3000, Stride: 1}, + }, +} + +var unicodeAliasSentence_Break_Upper = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0x41, Hi: 0x5A, Stride: 1}, + {Lo: 0xC0, Hi: 0xD6, Stride: 1}, + {Lo: 0xD8, Hi: 0xDE, Stride: 1}, + {Lo: 0x100, Hi: 0x100, Stride: 1}, + {Lo: 0x102, Hi: 0x102, Stride: 1}, + {Lo: 0x104, Hi: 0x104, Stride: 1}, + {Lo: 0x106, Hi: 0x106, Stride: 1}, + {Lo: 0x108, Hi: 0x108, Stride: 1}, + {Lo: 0x10A, Hi: 0x10A, Stride: 1}, + {Lo: 0x10C, Hi: 0x10C, Stride: 1}, + {Lo: 0x10E, Hi: 0x10E, Stride: 1}, + {Lo: 0x110, Hi: 0x110, Stride: 1}, + {Lo: 0x112, Hi: 0x112, Stride: 1}, + {Lo: 0x114, Hi: 0x114, Stride: 1}, + {Lo: 0x116, Hi: 0x116, Stride: 1}, + {Lo: 0x118, Hi: 0x118, Stride: 1}, + {Lo: 0x11A, Hi: 0x11A, Stride: 1}, + {Lo: 0x11C, Hi: 0x11C, Stride: 1}, + {Lo: 0x11E, Hi: 0x11E, Stride: 1}, + {Lo: 0x120, Hi: 0x120, Stride: 1}, + {Lo: 0x122, Hi: 0x122, Stride: 1}, + {Lo: 0x124, Hi: 0x124, Stride: 1}, + {Lo: 0x126, Hi: 0x126, Stride: 1}, + {Lo: 0x128, Hi: 0x128, Stride: 1}, + {Lo: 0x12A, Hi: 0x12A, Stride: 1}, + {Lo: 0x12C, Hi: 0x12C, Stride: 1}, + {Lo: 0x12E, Hi: 0x12E, Stride: 1}, + {Lo: 0x130, Hi: 0x130, Stride: 1}, + {Lo: 0x132, Hi: 0x132, Stride: 1}, + {Lo: 0x134, Hi: 0x134, Stride: 1}, + {Lo: 0x136, Hi: 0x136, Stride: 1}, + {Lo: 0x139, Hi: 0x139, Stride: 1}, + {Lo: 0x13B, Hi: 0x13B, Stride: 1}, + {Lo: 0x13D, Hi: 0x13D, Stride: 1}, + {Lo: 0x13F, Hi: 0x13F, Stride: 1}, + {Lo: 0x141, Hi: 0x141, Stride: 1}, + {Lo: 0x143, Hi: 0x143, Stride: 1}, + {Lo: 0x145, Hi: 0x145, Stride: 1}, + {Lo: 0x147, Hi: 0x147, Stride: 1}, + {Lo: 0x14A, Hi: 0x14A, Stride: 1}, + {Lo: 0x14C, Hi: 0x14C, Stride: 1}, + {Lo: 0x14E, Hi: 0x14E, Stride: 1}, + {Lo: 0x150, Hi: 0x150, Stride: 1}, + {Lo: 0x152, Hi: 0x152, Stride: 1}, + {Lo: 0x154, Hi: 0x154, Stride: 1}, + {Lo: 0x156, Hi: 0x156, Stride: 1}, + {Lo: 0x158, Hi: 0x158, Stride: 1}, + {Lo: 0x15A, Hi: 0x15A, Stride: 1}, + {Lo: 0x15C, Hi: 0x15C, Stride: 1}, + {Lo: 0x15E, Hi: 0x15E, Stride: 1}, + {Lo: 0x160, Hi: 0x160, Stride: 1}, + {Lo: 0x162, Hi: 0x162, Stride: 1}, + {Lo: 0x164, Hi: 0x164, Stride: 1}, + {Lo: 0x166, Hi: 0x166, Stride: 1}, + {Lo: 0x168, Hi: 0x168, Stride: 1}, + {Lo: 0x16A, Hi: 0x16A, Stride: 1}, + {Lo: 0x16C, Hi: 0x16C, Stride: 1}, + {Lo: 0x16E, Hi: 0x16E, Stride: 1}, + {Lo: 0x170, Hi: 0x170, Stride: 1}, + {Lo: 0x172, Hi: 0x172, Stride: 1}, + {Lo: 0x174, Hi: 0x174, Stride: 1}, + {Lo: 0x176, Hi: 0x176, Stride: 1}, + {Lo: 0x178, Hi: 0x179, Stride: 1}, + {Lo: 0x17B, Hi: 0x17B, Stride: 1}, + {Lo: 0x17D, Hi: 0x17D, Stride: 1}, + {Lo: 0x181, Hi: 0x182, Stride: 1}, + {Lo: 0x184, Hi: 0x184, Stride: 1}, + {Lo: 0x186, Hi: 0x187, Stride: 1}, + {Lo: 0x189, Hi: 0x18B, Stride: 1}, + {Lo: 0x18E, Hi: 0x191, Stride: 1}, + {Lo: 0x193, Hi: 0x194, Stride: 1}, + {Lo: 0x196, Hi: 0x198, Stride: 1}, + {Lo: 0x19C, Hi: 0x19D, Stride: 1}, + {Lo: 0x19F, Hi: 0x1A0, Stride: 1}, + {Lo: 0x1A2, Hi: 0x1A2, Stride: 1}, + {Lo: 0x1A4, Hi: 0x1A4, Stride: 1}, + {Lo: 0x1A6, Hi: 0x1A7, Stride: 1}, + {Lo: 0x1A9, Hi: 0x1A9, Stride: 1}, + {Lo: 0x1AC, Hi: 0x1AC, Stride: 1}, + {Lo: 0x1AE, Hi: 0x1AF, Stride: 1}, + {Lo: 0x1B1, Hi: 0x1B3, Stride: 1}, + {Lo: 0x1B5, Hi: 0x1B5, Stride: 1}, + {Lo: 0x1B7, Hi: 0x1B8, Stride: 1}, + {Lo: 0x1BC, Hi: 0x1BC, Stride: 1}, + {Lo: 0x1C4, Hi: 0x1C5, Stride: 1}, + {Lo: 0x1C7, Hi: 0x1C8, Stride: 1}, + {Lo: 0x1CA, Hi: 0x1CB, Stride: 1}, + {Lo: 0x1CD, Hi: 0x1CD, Stride: 1}, + {Lo: 0x1CF, Hi: 0x1CF, Stride: 1}, + {Lo: 0x1D1, Hi: 0x1D1, Stride: 1}, + {Lo: 0x1D3, Hi: 0x1D3, Stride: 1}, + {Lo: 0x1D5, Hi: 0x1D5, Stride: 1}, + {Lo: 0x1D7, Hi: 0x1D7, Stride: 1}, + {Lo: 0x1D9, Hi: 0x1D9, Stride: 1}, + {Lo: 0x1DB, Hi: 0x1DB, Stride: 1}, + {Lo: 0x1DE, Hi: 0x1DE, Stride: 1}, + {Lo: 0x1E0, Hi: 0x1E0, Stride: 1}, + {Lo: 0x1E2, Hi: 0x1E2, Stride: 1}, + {Lo: 0x1E4, Hi: 0x1E4, Stride: 1}, + {Lo: 0x1E6, Hi: 0x1E6, Stride: 1}, + {Lo: 0x1E8, Hi: 0x1E8, Stride: 1}, + {Lo: 0x1EA, Hi: 0x1EA, Stride: 1}, + {Lo: 0x1EC, Hi: 0x1EC, Stride: 1}, + {Lo: 0x1EE, Hi: 0x1EE, Stride: 1}, + {Lo: 0x1F1, Hi: 0x1F2, Stride: 1}, + {Lo: 0x1F4, Hi: 0x1F4, Stride: 1}, + {Lo: 0x1F6, Hi: 0x1F8, Stride: 1}, + {Lo: 0x1FA, Hi: 0x1FA, Stride: 1}, + {Lo: 0x1FC, Hi: 0x1FC, Stride: 1}, + {Lo: 0x1FE, Hi: 0x1FE, Stride: 1}, + {Lo: 0x200, Hi: 0x200, Stride: 1}, + {Lo: 0x202, Hi: 0x202, Stride: 1}, + {Lo: 0x204, Hi: 0x204, Stride: 1}, + {Lo: 0x206, Hi: 0x206, Stride: 1}, + {Lo: 0x208, Hi: 0x208, Stride: 1}, + {Lo: 0x20A, Hi: 0x20A, Stride: 1}, + {Lo: 0x20C, Hi: 0x20C, Stride: 1}, + {Lo: 0x20E, Hi: 0x20E, Stride: 1}, + {Lo: 0x210, Hi: 0x210, Stride: 1}, + {Lo: 0x212, Hi: 0x212, Stride: 1}, + {Lo: 0x214, Hi: 0x214, Stride: 1}, + {Lo: 0x216, Hi: 0x216, Stride: 1}, + {Lo: 0x218, Hi: 0x218, Stride: 1}, + {Lo: 0x21A, Hi: 0x21A, Stride: 1}, + {Lo: 0x21C, Hi: 0x21C, Stride: 1}, + {Lo: 0x21E, Hi: 0x21E, Stride: 1}, + {Lo: 0x220, Hi: 0x220, Stride: 1}, + {Lo: 0x222, Hi: 0x222, Stride: 1}, + {Lo: 0x224, Hi: 0x224, Stride: 1}, + {Lo: 0x226, Hi: 0x226, Stride: 1}, + {Lo: 0x228, Hi: 0x228, Stride: 1}, + {Lo: 0x22A, Hi: 0x22A, Stride: 1}, + {Lo: 0x22C, Hi: 0x22C, Stride: 1}, + {Lo: 0x22E, Hi: 0x22E, Stride: 1}, + {Lo: 0x230, Hi: 0x230, Stride: 1}, + {Lo: 0x232, Hi: 0x232, Stride: 1}, + {Lo: 0x23A, Hi: 0x23B, Stride: 1}, + {Lo: 0x23D, Hi: 0x23E, Stride: 1}, + {Lo: 0x241, Hi: 0x241, Stride: 1}, + {Lo: 0x243, Hi: 0x246, Stride: 1}, + {Lo: 0x248, Hi: 0x248, Stride: 1}, + {Lo: 0x24A, Hi: 0x24A, Stride: 1}, + {Lo: 0x24C, Hi: 0x24C, Stride: 1}, + {Lo: 0x24E, Hi: 0x24E, Stride: 1}, + {Lo: 0x370, Hi: 0x370, Stride: 1}, + {Lo: 0x372, Hi: 0x372, Stride: 1}, + {Lo: 0x376, Hi: 0x376, Stride: 1}, + {Lo: 0x37F, Hi: 0x37F, Stride: 1}, + {Lo: 0x386, Hi: 0x386, Stride: 1}, + {Lo: 0x388, Hi: 0x38A, Stride: 1}, + {Lo: 0x38C, Hi: 0x38C, Stride: 1}, + {Lo: 0x38E, Hi: 0x38F, Stride: 1}, + {Lo: 0x391, Hi: 0x3A1, Stride: 1}, + {Lo: 0x3A3, Hi: 0x3AB, Stride: 1}, + {Lo: 0x3CF, Hi: 0x3CF, Stride: 1}, + {Lo: 0x3D2, Hi: 0x3D4, Stride: 1}, + {Lo: 0x3D8, Hi: 0x3D8, Stride: 1}, + {Lo: 0x3DA, Hi: 0x3DA, Stride: 1}, + {Lo: 0x3DC, Hi: 0x3DC, Stride: 1}, + {Lo: 0x3DE, Hi: 0x3DE, Stride: 1}, + {Lo: 0x3E0, Hi: 0x3E0, Stride: 1}, + {Lo: 0x3E2, Hi: 0x3E2, Stride: 1}, + {Lo: 0x3E4, Hi: 0x3E4, Stride: 1}, + {Lo: 0x3E6, Hi: 0x3E6, Stride: 1}, + {Lo: 0x3E8, Hi: 0x3E8, Stride: 1}, + {Lo: 0x3EA, Hi: 0x3EA, Stride: 1}, + {Lo: 0x3EC, Hi: 0x3EC, Stride: 1}, + {Lo: 0x3EE, Hi: 0x3EE, Stride: 1}, + {Lo: 0x3F4, Hi: 0x3F4, Stride: 1}, + {Lo: 0x3F7, Hi: 0x3F7, Stride: 1}, + {Lo: 0x3F9, Hi: 0x3FA, Stride: 1}, + {Lo: 0x3FD, Hi: 0x42F, Stride: 1}, + {Lo: 0x460, Hi: 0x460, Stride: 1}, + {Lo: 0x462, Hi: 0x462, Stride: 1}, + {Lo: 0x464, Hi: 0x464, Stride: 1}, + {Lo: 0x466, Hi: 0x466, Stride: 1}, + {Lo: 0x468, Hi: 0x468, Stride: 1}, + {Lo: 0x46A, Hi: 0x46A, Stride: 1}, + {Lo: 0x46C, Hi: 0x46C, Stride: 1}, + {Lo: 0x46E, Hi: 0x46E, Stride: 1}, + {Lo: 0x470, Hi: 0x470, Stride: 1}, + {Lo: 0x472, Hi: 0x472, Stride: 1}, + {Lo: 0x474, Hi: 0x474, Stride: 1}, + {Lo: 0x476, Hi: 0x476, Stride: 1}, + {Lo: 0x478, Hi: 0x478, Stride: 1}, + {Lo: 0x47A, Hi: 0x47A, Stride: 1}, + {Lo: 0x47C, Hi: 0x47C, Stride: 1}, + {Lo: 0x47E, Hi: 0x47E, Stride: 1}, + {Lo: 0x480, Hi: 0x480, Stride: 1}, + {Lo: 0x48A, Hi: 0x48A, Stride: 1}, + {Lo: 0x48C, Hi: 0x48C, Stride: 1}, + {Lo: 0x48E, Hi: 0x48E, Stride: 1}, + {Lo: 0x490, Hi: 0x490, Stride: 1}, + {Lo: 0x492, Hi: 0x492, Stride: 1}, + {Lo: 0x494, Hi: 0x494, Stride: 1}, + {Lo: 0x496, Hi: 0x496, Stride: 1}, + {Lo: 0x498, Hi: 0x498, Stride: 1}, + {Lo: 0x49A, Hi: 0x49A, Stride: 1}, + {Lo: 0x49C, Hi: 0x49C, Stride: 1}, + {Lo: 0x49E, Hi: 0x49E, Stride: 1}, + {Lo: 0x4A0, Hi: 0x4A0, Stride: 1}, + {Lo: 0x4A2, Hi: 0x4A2, Stride: 1}, + {Lo: 0x4A4, Hi: 0x4A4, Stride: 1}, + {Lo: 0x4A6, Hi: 0x4A6, Stride: 1}, + {Lo: 0x4A8, Hi: 0x4A8, Stride: 1}, + {Lo: 0x4AA, Hi: 0x4AA, Stride: 1}, + {Lo: 0x4AC, Hi: 0x4AC, Stride: 1}, + {Lo: 0x4AE, Hi: 0x4AE, Stride: 1}, + {Lo: 0x4B0, Hi: 0x4B0, Stride: 1}, + {Lo: 0x4B2, Hi: 0x4B2, Stride: 1}, + {Lo: 0x4B4, Hi: 0x4B4, Stride: 1}, + {Lo: 0x4B6, Hi: 0x4B6, Stride: 1}, + {Lo: 0x4B8, Hi: 0x4B8, Stride: 1}, + {Lo: 0x4BA, Hi: 0x4BA, Stride: 1}, + {Lo: 0x4BC, Hi: 0x4BC, Stride: 1}, + {Lo: 0x4BE, Hi: 0x4BE, Stride: 1}, + {Lo: 0x4C0, Hi: 0x4C1, Stride: 1}, + {Lo: 0x4C3, Hi: 0x4C3, Stride: 1}, + {Lo: 0x4C5, Hi: 0x4C5, Stride: 1}, + {Lo: 0x4C7, Hi: 0x4C7, Stride: 1}, + {Lo: 0x4C9, Hi: 0x4C9, Stride: 1}, + {Lo: 0x4CB, Hi: 0x4CB, Stride: 1}, + {Lo: 0x4CD, Hi: 0x4CD, Stride: 1}, + {Lo: 0x4D0, Hi: 0x4D0, Stride: 1}, + {Lo: 0x4D2, Hi: 0x4D2, Stride: 1}, + {Lo: 0x4D4, Hi: 0x4D4, Stride: 1}, + {Lo: 0x4D6, Hi: 0x4D6, Stride: 1}, + {Lo: 0x4D8, Hi: 0x4D8, Stride: 1}, + {Lo: 0x4DA, Hi: 0x4DA, Stride: 1}, + {Lo: 0x4DC, Hi: 0x4DC, Stride: 1}, + {Lo: 0x4DE, Hi: 0x4DE, Stride: 1}, + {Lo: 0x4E0, Hi: 0x4E0, Stride: 1}, + {Lo: 0x4E2, Hi: 0x4E2, Stride: 1}, + {Lo: 0x4E4, Hi: 0x4E4, Stride: 1}, + {Lo: 0x4E6, Hi: 0x4E6, Stride: 1}, + {Lo: 0x4E8, Hi: 0x4E8, Stride: 1}, + {Lo: 0x4EA, Hi: 0x4EA, Stride: 1}, + {Lo: 0x4EC, Hi: 0x4EC, Stride: 1}, + {Lo: 0x4EE, Hi: 0x4EE, Stride: 1}, + {Lo: 0x4F0, Hi: 0x4F0, Stride: 1}, + {Lo: 0x4F2, Hi: 0x4F2, Stride: 1}, + {Lo: 0x4F4, Hi: 0x4F4, Stride: 1}, + {Lo: 0x4F6, Hi: 0x4F6, Stride: 1}, + {Lo: 0x4F8, Hi: 0x4F8, Stride: 1}, + {Lo: 0x4FA, Hi: 0x4FA, Stride: 1}, + {Lo: 0x4FC, Hi: 0x4FC, Stride: 1}, + {Lo: 0x4FE, Hi: 0x4FE, Stride: 1}, + {Lo: 0x500, Hi: 0x500, Stride: 1}, + {Lo: 0x502, Hi: 0x502, Stride: 1}, + {Lo: 0x504, Hi: 0x504, Stride: 1}, + {Lo: 0x506, Hi: 0x506, Stride: 1}, + {Lo: 0x508, Hi: 0x508, Stride: 1}, + {Lo: 0x50A, Hi: 0x50A, Stride: 1}, + {Lo: 0x50C, Hi: 0x50C, Stride: 1}, + {Lo: 0x50E, Hi: 0x50E, Stride: 1}, + {Lo: 0x510, Hi: 0x510, Stride: 1}, + {Lo: 0x512, Hi: 0x512, Stride: 1}, + {Lo: 0x514, Hi: 0x514, Stride: 1}, + {Lo: 0x516, Hi: 0x516, Stride: 1}, + {Lo: 0x518, Hi: 0x518, Stride: 1}, + {Lo: 0x51A, Hi: 0x51A, Stride: 1}, + {Lo: 0x51C, Hi: 0x51C, Stride: 1}, + {Lo: 0x51E, Hi: 0x51E, Stride: 1}, + {Lo: 0x520, Hi: 0x520, Stride: 1}, + {Lo: 0x522, Hi: 0x522, Stride: 1}, + {Lo: 0x524, Hi: 0x524, Stride: 1}, + {Lo: 0x526, Hi: 0x526, Stride: 1}, + {Lo: 0x528, Hi: 0x528, Stride: 1}, + {Lo: 0x52A, Hi: 0x52A, Stride: 1}, + {Lo: 0x52C, Hi: 0x52C, Stride: 1}, + {Lo: 0x52E, Hi: 0x52E, Stride: 1}, + {Lo: 0x531, Hi: 0x556, Stride: 1}, + {Lo: 0x10A0, Hi: 0x10C5, Stride: 1}, + {Lo: 0x10C7, Hi: 0x10C7, Stride: 1}, + {Lo: 0x10CD, Hi: 0x10CD, Stride: 1}, + {Lo: 0x13A0, Hi: 0x13F5, Stride: 1}, + {Lo: 0x1C89, Hi: 0x1C89, Stride: 1}, + {Lo: 0x1E00, Hi: 0x1E00, Stride: 1}, + {Lo: 0x1E02, Hi: 0x1E02, Stride: 1}, + {Lo: 0x1E04, Hi: 0x1E04, Stride: 1}, + {Lo: 0x1E06, Hi: 0x1E06, Stride: 1}, + {Lo: 0x1E08, Hi: 0x1E08, Stride: 1}, + {Lo: 0x1E0A, Hi: 0x1E0A, Stride: 1}, + {Lo: 0x1E0C, Hi: 0x1E0C, Stride: 1}, + {Lo: 0x1E0E, Hi: 0x1E0E, Stride: 1}, + {Lo: 0x1E10, Hi: 0x1E10, Stride: 1}, + {Lo: 0x1E12, Hi: 0x1E12, Stride: 1}, + {Lo: 0x1E14, Hi: 0x1E14, Stride: 1}, + {Lo: 0x1E16, Hi: 0x1E16, Stride: 1}, + {Lo: 0x1E18, Hi: 0x1E18, Stride: 1}, + {Lo: 0x1E1A, Hi: 0x1E1A, Stride: 1}, + {Lo: 0x1E1C, Hi: 0x1E1C, Stride: 1}, + {Lo: 0x1E1E, Hi: 0x1E1E, Stride: 1}, + {Lo: 0x1E20, Hi: 0x1E20, Stride: 1}, + {Lo: 0x1E22, Hi: 0x1E22, Stride: 1}, + {Lo: 0x1E24, Hi: 0x1E24, Stride: 1}, + {Lo: 0x1E26, Hi: 0x1E26, Stride: 1}, + {Lo: 0x1E28, Hi: 0x1E28, Stride: 1}, + {Lo: 0x1E2A, Hi: 0x1E2A, Stride: 1}, + {Lo: 0x1E2C, Hi: 0x1E2C, Stride: 1}, + {Lo: 0x1E2E, Hi: 0x1E2E, Stride: 1}, + {Lo: 0x1E30, Hi: 0x1E30, Stride: 1}, + {Lo: 0x1E32, Hi: 0x1E32, Stride: 1}, + {Lo: 0x1E34, Hi: 0x1E34, Stride: 1}, + {Lo: 0x1E36, Hi: 0x1E36, Stride: 1}, + {Lo: 0x1E38, Hi: 0x1E38, Stride: 1}, + {Lo: 0x1E3A, Hi: 0x1E3A, Stride: 1}, + {Lo: 0x1E3C, Hi: 0x1E3C, Stride: 1}, + {Lo: 0x1E3E, Hi: 0x1E3E, Stride: 1}, + {Lo: 0x1E40, Hi: 0x1E40, Stride: 1}, + {Lo: 0x1E42, Hi: 0x1E42, Stride: 1}, + {Lo: 0x1E44, Hi: 0x1E44, Stride: 1}, + {Lo: 0x1E46, Hi: 0x1E46, Stride: 1}, + {Lo: 0x1E48, Hi: 0x1E48, Stride: 1}, + {Lo: 0x1E4A, Hi: 0x1E4A, Stride: 1}, + {Lo: 0x1E4C, Hi: 0x1E4C, Stride: 1}, + {Lo: 0x1E4E, Hi: 0x1E4E, Stride: 1}, + {Lo: 0x1E50, Hi: 0x1E50, Stride: 1}, + {Lo: 0x1E52, Hi: 0x1E52, Stride: 1}, + {Lo: 0x1E54, Hi: 0x1E54, Stride: 1}, + {Lo: 0x1E56, Hi: 0x1E56, Stride: 1}, + {Lo: 0x1E58, Hi: 0x1E58, Stride: 1}, + {Lo: 0x1E5A, Hi: 0x1E5A, Stride: 1}, + {Lo: 0x1E5C, Hi: 0x1E5C, Stride: 1}, + {Lo: 0x1E5E, Hi: 0x1E5E, Stride: 1}, + {Lo: 0x1E60, Hi: 0x1E60, Stride: 1}, + {Lo: 0x1E62, Hi: 0x1E62, Stride: 1}, + {Lo: 0x1E64, Hi: 0x1E64, Stride: 1}, + {Lo: 0x1E66, Hi: 0x1E66, Stride: 1}, + {Lo: 0x1E68, Hi: 0x1E68, Stride: 1}, + {Lo: 0x1E6A, Hi: 0x1E6A, Stride: 1}, + {Lo: 0x1E6C, Hi: 0x1E6C, Stride: 1}, + {Lo: 0x1E6E, Hi: 0x1E6E, Stride: 1}, + {Lo: 0x1E70, Hi: 0x1E70, Stride: 1}, + {Lo: 0x1E72, Hi: 0x1E72, Stride: 1}, + {Lo: 0x1E74, Hi: 0x1E74, Stride: 1}, + {Lo: 0x1E76, Hi: 0x1E76, Stride: 1}, + {Lo: 0x1E78, Hi: 0x1E78, Stride: 1}, + {Lo: 0x1E7A, Hi: 0x1E7A, Stride: 1}, + {Lo: 0x1E7C, Hi: 0x1E7C, Stride: 1}, + {Lo: 0x1E7E, Hi: 0x1E7E, Stride: 1}, + {Lo: 0x1E80, Hi: 0x1E80, Stride: 1}, + {Lo: 0x1E82, Hi: 0x1E82, Stride: 1}, + {Lo: 0x1E84, Hi: 0x1E84, Stride: 1}, + {Lo: 0x1E86, Hi: 0x1E86, Stride: 1}, + {Lo: 0x1E88, Hi: 0x1E88, Stride: 1}, + {Lo: 0x1E8A, Hi: 0x1E8A, Stride: 1}, + {Lo: 0x1E8C, Hi: 0x1E8C, Stride: 1}, + {Lo: 0x1E8E, Hi: 0x1E8E, Stride: 1}, + {Lo: 0x1E90, Hi: 0x1E90, Stride: 1}, + {Lo: 0x1E92, Hi: 0x1E92, Stride: 1}, + {Lo: 0x1E94, Hi: 0x1E94, Stride: 1}, + {Lo: 0x1E9E, Hi: 0x1E9E, Stride: 1}, + {Lo: 0x1EA0, Hi: 0x1EA0, Stride: 1}, + {Lo: 0x1EA2, Hi: 0x1EA2, Stride: 1}, + {Lo: 0x1EA4, Hi: 0x1EA4, Stride: 1}, + {Lo: 0x1EA6, Hi: 0x1EA6, Stride: 1}, + {Lo: 0x1EA8, Hi: 0x1EA8, Stride: 1}, + {Lo: 0x1EAA, Hi: 0x1EAA, Stride: 1}, + {Lo: 0x1EAC, Hi: 0x1EAC, Stride: 1}, + {Lo: 0x1EAE, Hi: 0x1EAE, Stride: 1}, + {Lo: 0x1EB0, Hi: 0x1EB0, Stride: 1}, + {Lo: 0x1EB2, Hi: 0x1EB2, Stride: 1}, + {Lo: 0x1EB4, Hi: 0x1EB4, Stride: 1}, + {Lo: 0x1EB6, Hi: 0x1EB6, Stride: 1}, + {Lo: 0x1EB8, Hi: 0x1EB8, Stride: 1}, + {Lo: 0x1EBA, Hi: 0x1EBA, Stride: 1}, + {Lo: 0x1EBC, Hi: 0x1EBC, Stride: 1}, + {Lo: 0x1EBE, Hi: 0x1EBE, Stride: 1}, + {Lo: 0x1EC0, Hi: 0x1EC0, Stride: 1}, + {Lo: 0x1EC2, Hi: 0x1EC2, Stride: 1}, + {Lo: 0x1EC4, Hi: 0x1EC4, Stride: 1}, + {Lo: 0x1EC6, Hi: 0x1EC6, Stride: 1}, + {Lo: 0x1EC8, Hi: 0x1EC8, Stride: 1}, + {Lo: 0x1ECA, Hi: 0x1ECA, Stride: 1}, + {Lo: 0x1ECC, Hi: 0x1ECC, Stride: 1}, + {Lo: 0x1ECE, Hi: 0x1ECE, Stride: 1}, + {Lo: 0x1ED0, Hi: 0x1ED0, Stride: 1}, + {Lo: 0x1ED2, Hi: 0x1ED2, Stride: 1}, + {Lo: 0x1ED4, Hi: 0x1ED4, Stride: 1}, + {Lo: 0x1ED6, Hi: 0x1ED6, Stride: 1}, + {Lo: 0x1ED8, Hi: 0x1ED8, Stride: 1}, + {Lo: 0x1EDA, Hi: 0x1EDA, Stride: 1}, + {Lo: 0x1EDC, Hi: 0x1EDC, Stride: 1}, + {Lo: 0x1EDE, Hi: 0x1EDE, Stride: 1}, + {Lo: 0x1EE0, Hi: 0x1EE0, Stride: 1}, + {Lo: 0x1EE2, Hi: 0x1EE2, Stride: 1}, + {Lo: 0x1EE4, Hi: 0x1EE4, Stride: 1}, + {Lo: 0x1EE6, Hi: 0x1EE6, Stride: 1}, + {Lo: 0x1EE8, Hi: 0x1EE8, Stride: 1}, + {Lo: 0x1EEA, Hi: 0x1EEA, Stride: 1}, + {Lo: 0x1EEC, Hi: 0x1EEC, Stride: 1}, + {Lo: 0x1EEE, Hi: 0x1EEE, Stride: 1}, + {Lo: 0x1EF0, Hi: 0x1EF0, Stride: 1}, + {Lo: 0x1EF2, Hi: 0x1EF2, Stride: 1}, + {Lo: 0x1EF4, Hi: 0x1EF4, Stride: 1}, + {Lo: 0x1EF6, Hi: 0x1EF6, Stride: 1}, + {Lo: 0x1EF8, Hi: 0x1EF8, Stride: 1}, + {Lo: 0x1EFA, Hi: 0x1EFA, Stride: 1}, + {Lo: 0x1EFC, Hi: 0x1EFC, Stride: 1}, + {Lo: 0x1EFE, Hi: 0x1EFE, Stride: 1}, + {Lo: 0x1F08, Hi: 0x1F0F, Stride: 1}, + {Lo: 0x1F18, Hi: 0x1F1D, Stride: 1}, + {Lo: 0x1F28, Hi: 0x1F2F, Stride: 1}, + {Lo: 0x1F38, Hi: 0x1F3F, Stride: 1}, + {Lo: 0x1F48, Hi: 0x1F4D, Stride: 1}, + {Lo: 0x1F59, Hi: 0x1F59, Stride: 1}, + {Lo: 0x1F5B, Hi: 0x1F5B, Stride: 1}, + {Lo: 0x1F5D, Hi: 0x1F5D, Stride: 1}, + {Lo: 0x1F5F, Hi: 0x1F5F, Stride: 1}, + {Lo: 0x1F68, Hi: 0x1F6F, Stride: 1}, + {Lo: 0x1F88, Hi: 0x1F8F, Stride: 1}, + {Lo: 0x1F98, Hi: 0x1F9F, Stride: 1}, + {Lo: 0x1FA8, Hi: 0x1FAF, Stride: 1}, + {Lo: 0x1FB8, Hi: 0x1FBC, Stride: 1}, + {Lo: 0x1FC8, Hi: 0x1FCC, Stride: 1}, + {Lo: 0x1FD8, Hi: 0x1FDB, Stride: 1}, + {Lo: 0x1FE8, Hi: 0x1FEC, Stride: 1}, + {Lo: 0x1FF8, Hi: 0x1FFC, Stride: 1}, + {Lo: 0x2102, Hi: 0x2102, Stride: 1}, + {Lo: 0x2107, Hi: 0x2107, Stride: 1}, + {Lo: 0x210B, Hi: 0x210D, Stride: 1}, + {Lo: 0x2110, Hi: 0x2112, Stride: 1}, + {Lo: 0x2115, Hi: 0x2115, Stride: 1}, + {Lo: 0x2119, Hi: 0x211D, Stride: 1}, + {Lo: 0x2124, Hi: 0x2124, Stride: 1}, + {Lo: 0x2126, Hi: 0x2126, Stride: 1}, + {Lo: 0x2128, Hi: 0x2128, Stride: 1}, + {Lo: 0x212A, Hi: 0x212D, Stride: 1}, + {Lo: 0x2130, Hi: 0x2133, Stride: 1}, + {Lo: 0x213E, Hi: 0x213F, Stride: 1}, + {Lo: 0x2145, Hi: 0x2145, Stride: 1}, + {Lo: 0x2160, Hi: 0x216F, Stride: 1}, + {Lo: 0x2183, Hi: 0x2183, Stride: 1}, + {Lo: 0x24B6, Hi: 0x24CF, Stride: 1}, + {Lo: 0x2C00, Hi: 0x2C2F, Stride: 1}, + {Lo: 0x2C60, Hi: 0x2C60, Stride: 1}, + {Lo: 0x2C62, Hi: 0x2C64, Stride: 1}, + {Lo: 0x2C67, Hi: 0x2C67, Stride: 1}, + {Lo: 0x2C69, Hi: 0x2C69, Stride: 1}, + {Lo: 0x2C6B, Hi: 0x2C6B, Stride: 1}, + {Lo: 0x2C6D, Hi: 0x2C70, Stride: 1}, + {Lo: 0x2C72, Hi: 0x2C72, Stride: 1}, + {Lo: 0x2C75, Hi: 0x2C75, Stride: 1}, + {Lo: 0x2C7E, Hi: 0x2C80, Stride: 1}, + {Lo: 0x2C82, Hi: 0x2C82, Stride: 1}, + {Lo: 0x2C84, Hi: 0x2C84, Stride: 1}, + {Lo: 0x2C86, Hi: 0x2C86, Stride: 1}, + {Lo: 0x2C88, Hi: 0x2C88, Stride: 1}, + {Lo: 0x2C8A, Hi: 0x2C8A, Stride: 1}, + {Lo: 0x2C8C, Hi: 0x2C8C, Stride: 1}, + {Lo: 0x2C8E, Hi: 0x2C8E, Stride: 1}, + {Lo: 0x2C90, Hi: 0x2C90, Stride: 1}, + {Lo: 0x2C92, Hi: 0x2C92, Stride: 1}, + {Lo: 0x2C94, Hi: 0x2C94, Stride: 1}, + {Lo: 0x2C96, Hi: 0x2C96, Stride: 1}, + {Lo: 0x2C98, Hi: 0x2C98, Stride: 1}, + {Lo: 0x2C9A, Hi: 0x2C9A, Stride: 1}, + {Lo: 0x2C9C, Hi: 0x2C9C, Stride: 1}, + {Lo: 0x2C9E, Hi: 0x2C9E, Stride: 1}, + {Lo: 0x2CA0, Hi: 0x2CA0, Stride: 1}, + {Lo: 0x2CA2, Hi: 0x2CA2, Stride: 1}, + {Lo: 0x2CA4, Hi: 0x2CA4, Stride: 1}, + {Lo: 0x2CA6, Hi: 0x2CA6, Stride: 1}, + {Lo: 0x2CA8, Hi: 0x2CA8, Stride: 1}, + {Lo: 0x2CAA, Hi: 0x2CAA, Stride: 1}, + {Lo: 0x2CAC, Hi: 0x2CAC, Stride: 1}, + {Lo: 0x2CAE, Hi: 0x2CAE, Stride: 1}, + {Lo: 0x2CB0, Hi: 0x2CB0, Stride: 1}, + {Lo: 0x2CB2, Hi: 0x2CB2, Stride: 1}, + {Lo: 0x2CB4, Hi: 0x2CB4, Stride: 1}, + {Lo: 0x2CB6, Hi: 0x2CB6, Stride: 1}, + {Lo: 0x2CB8, Hi: 0x2CB8, Stride: 1}, + {Lo: 0x2CBA, Hi: 0x2CBA, Stride: 1}, + {Lo: 0x2CBC, Hi: 0x2CBC, Stride: 1}, + {Lo: 0x2CBE, Hi: 0x2CBE, Stride: 1}, + {Lo: 0x2CC0, Hi: 0x2CC0, Stride: 1}, + {Lo: 0x2CC2, Hi: 0x2CC2, Stride: 1}, + {Lo: 0x2CC4, Hi: 0x2CC4, Stride: 1}, + {Lo: 0x2CC6, Hi: 0x2CC6, Stride: 1}, + {Lo: 0x2CC8, Hi: 0x2CC8, Stride: 1}, + {Lo: 0x2CCA, Hi: 0x2CCA, Stride: 1}, + {Lo: 0x2CCC, Hi: 0x2CCC, Stride: 1}, + {Lo: 0x2CCE, Hi: 0x2CCE, Stride: 1}, + {Lo: 0x2CD0, Hi: 0x2CD0, Stride: 1}, + {Lo: 0x2CD2, Hi: 0x2CD2, Stride: 1}, + {Lo: 0x2CD4, Hi: 0x2CD4, Stride: 1}, + {Lo: 0x2CD6, Hi: 0x2CD6, Stride: 1}, + {Lo: 0x2CD8, Hi: 0x2CD8, Stride: 1}, + {Lo: 0x2CDA, Hi: 0x2CDA, Stride: 1}, + {Lo: 0x2CDC, Hi: 0x2CDC, Stride: 1}, + {Lo: 0x2CDE, Hi: 0x2CDE, Stride: 1}, + {Lo: 0x2CE0, Hi: 0x2CE0, Stride: 1}, + {Lo: 0x2CE2, Hi: 0x2CE2, Stride: 1}, + {Lo: 0x2CEB, Hi: 0x2CEB, Stride: 1}, + {Lo: 0x2CED, Hi: 0x2CED, Stride: 1}, + {Lo: 0x2CF2, Hi: 0x2CF2, Stride: 1}, + {Lo: 0xA640, Hi: 0xA640, Stride: 1}, + {Lo: 0xA642, Hi: 0xA642, Stride: 1}, + {Lo: 0xA644, Hi: 0xA644, Stride: 1}, + {Lo: 0xA646, Hi: 0xA646, Stride: 1}, + {Lo: 0xA648, Hi: 0xA648, Stride: 1}, + {Lo: 0xA64A, Hi: 0xA64A, Stride: 1}, + {Lo: 0xA64C, Hi: 0xA64C, Stride: 1}, + {Lo: 0xA64E, Hi: 0xA64E, Stride: 1}, + {Lo: 0xA650, Hi: 0xA650, Stride: 1}, + {Lo: 0xA652, Hi: 0xA652, Stride: 1}, + {Lo: 0xA654, Hi: 0xA654, Stride: 1}, + {Lo: 0xA656, Hi: 0xA656, Stride: 1}, + {Lo: 0xA658, Hi: 0xA658, Stride: 1}, + {Lo: 0xA65A, Hi: 0xA65A, Stride: 1}, + {Lo: 0xA65C, Hi: 0xA65C, Stride: 1}, + {Lo: 0xA65E, Hi: 0xA65E, Stride: 1}, + {Lo: 0xA660, Hi: 0xA660, Stride: 1}, + {Lo: 0xA662, Hi: 0xA662, Stride: 1}, + {Lo: 0xA664, Hi: 0xA664, Stride: 1}, + {Lo: 0xA666, Hi: 0xA666, Stride: 1}, + {Lo: 0xA668, Hi: 0xA668, Stride: 1}, + {Lo: 0xA66A, Hi: 0xA66A, Stride: 1}, + {Lo: 0xA66C, Hi: 0xA66C, Stride: 1}, + {Lo: 0xA680, Hi: 0xA680, Stride: 1}, + {Lo: 0xA682, Hi: 0xA682, Stride: 1}, + {Lo: 0xA684, Hi: 0xA684, Stride: 1}, + {Lo: 0xA686, Hi: 0xA686, Stride: 1}, + {Lo: 0xA688, Hi: 0xA688, Stride: 1}, + {Lo: 0xA68A, Hi: 0xA68A, Stride: 1}, + {Lo: 0xA68C, Hi: 0xA68C, Stride: 1}, + {Lo: 0xA68E, Hi: 0xA68E, Stride: 1}, + {Lo: 0xA690, Hi: 0xA690, Stride: 1}, + {Lo: 0xA692, Hi: 0xA692, Stride: 1}, + {Lo: 0xA694, Hi: 0xA694, Stride: 1}, + {Lo: 0xA696, Hi: 0xA696, Stride: 1}, + {Lo: 0xA698, Hi: 0xA698, Stride: 1}, + {Lo: 0xA69A, Hi: 0xA69A, Stride: 1}, + {Lo: 0xA722, Hi: 0xA722, Stride: 1}, + {Lo: 0xA724, Hi: 0xA724, Stride: 1}, + {Lo: 0xA726, Hi: 0xA726, Stride: 1}, + {Lo: 0xA728, Hi: 0xA728, Stride: 1}, + {Lo: 0xA72A, Hi: 0xA72A, Stride: 1}, + {Lo: 0xA72C, Hi: 0xA72C, Stride: 1}, + {Lo: 0xA72E, Hi: 0xA72E, Stride: 1}, + {Lo: 0xA732, Hi: 0xA732, Stride: 1}, + {Lo: 0xA734, Hi: 0xA734, Stride: 1}, + {Lo: 0xA736, Hi: 0xA736, Stride: 1}, + {Lo: 0xA738, Hi: 0xA738, Stride: 1}, + {Lo: 0xA73A, Hi: 0xA73A, Stride: 1}, + {Lo: 0xA73C, Hi: 0xA73C, Stride: 1}, + {Lo: 0xA73E, Hi: 0xA73E, Stride: 1}, + {Lo: 0xA740, Hi: 0xA740, Stride: 1}, + {Lo: 0xA742, Hi: 0xA742, Stride: 1}, + {Lo: 0xA744, Hi: 0xA744, Stride: 1}, + {Lo: 0xA746, Hi: 0xA746, Stride: 1}, + {Lo: 0xA748, Hi: 0xA748, Stride: 1}, + {Lo: 0xA74A, Hi: 0xA74A, Stride: 1}, + {Lo: 0xA74C, Hi: 0xA74C, Stride: 1}, + {Lo: 0xA74E, Hi: 0xA74E, Stride: 1}, + {Lo: 0xA750, Hi: 0xA750, Stride: 1}, + {Lo: 0xA752, Hi: 0xA752, Stride: 1}, + {Lo: 0xA754, Hi: 0xA754, Stride: 1}, + {Lo: 0xA756, Hi: 0xA756, Stride: 1}, + {Lo: 0xA758, Hi: 0xA758, Stride: 1}, + {Lo: 0xA75A, Hi: 0xA75A, Stride: 1}, + {Lo: 0xA75C, Hi: 0xA75C, Stride: 1}, + {Lo: 0xA75E, Hi: 0xA75E, Stride: 1}, + {Lo: 0xA760, Hi: 0xA760, Stride: 1}, + {Lo: 0xA762, Hi: 0xA762, Stride: 1}, + {Lo: 0xA764, Hi: 0xA764, Stride: 1}, + {Lo: 0xA766, Hi: 0xA766, Stride: 1}, + {Lo: 0xA768, Hi: 0xA768, Stride: 1}, + {Lo: 0xA76A, Hi: 0xA76A, Stride: 1}, + {Lo: 0xA76C, Hi: 0xA76C, Stride: 1}, + {Lo: 0xA76E, Hi: 0xA76E, Stride: 1}, + {Lo: 0xA779, Hi: 0xA779, Stride: 1}, + {Lo: 0xA77B, Hi: 0xA77B, Stride: 1}, + {Lo: 0xA77D, Hi: 0xA77E, Stride: 1}, + {Lo: 0xA780, Hi: 0xA780, Stride: 1}, + {Lo: 0xA782, Hi: 0xA782, Stride: 1}, + {Lo: 0xA784, Hi: 0xA784, Stride: 1}, + {Lo: 0xA786, Hi: 0xA786, Stride: 1}, + {Lo: 0xA78B, Hi: 0xA78B, Stride: 1}, + {Lo: 0xA78D, Hi: 0xA78D, Stride: 1}, + {Lo: 0xA790, Hi: 0xA790, Stride: 1}, + {Lo: 0xA792, Hi: 0xA792, Stride: 1}, + {Lo: 0xA796, Hi: 0xA796, Stride: 1}, + {Lo: 0xA798, Hi: 0xA798, Stride: 1}, + {Lo: 0xA79A, Hi: 0xA79A, Stride: 1}, + {Lo: 0xA79C, Hi: 0xA79C, Stride: 1}, + {Lo: 0xA79E, Hi: 0xA79E, Stride: 1}, + {Lo: 0xA7A0, Hi: 0xA7A0, Stride: 1}, + {Lo: 0xA7A2, Hi: 0xA7A2, Stride: 1}, + {Lo: 0xA7A4, Hi: 0xA7A4, Stride: 1}, + {Lo: 0xA7A6, Hi: 0xA7A6, Stride: 1}, + {Lo: 0xA7A8, Hi: 0xA7A8, Stride: 1}, + {Lo: 0xA7AA, Hi: 0xA7AE, Stride: 1}, + {Lo: 0xA7B0, Hi: 0xA7B4, Stride: 1}, + {Lo: 0xA7B6, Hi: 0xA7B6, Stride: 1}, + {Lo: 0xA7B8, Hi: 0xA7B8, Stride: 1}, + {Lo: 0xA7BA, Hi: 0xA7BA, Stride: 1}, + {Lo: 0xA7BC, Hi: 0xA7BC, Stride: 1}, + {Lo: 0xA7BE, Hi: 0xA7BE, Stride: 1}, + {Lo: 0xA7C0, Hi: 0xA7C0, Stride: 1}, + {Lo: 0xA7C2, Hi: 0xA7C2, Stride: 1}, + {Lo: 0xA7C4, Hi: 0xA7C7, Stride: 1}, + {Lo: 0xA7C9, Hi: 0xA7C9, Stride: 1}, + {Lo: 0xA7CB, Hi: 0xA7CC, Stride: 1}, + {Lo: 0xA7CE, Hi: 0xA7CE, Stride: 1}, + {Lo: 0xA7D0, Hi: 0xA7D0, Stride: 1}, + {Lo: 0xA7D2, Hi: 0xA7D2, Stride: 1}, + {Lo: 0xA7D4, Hi: 0xA7D4, Stride: 1}, + {Lo: 0xA7D6, Hi: 0xA7D6, Stride: 1}, + {Lo: 0xA7D8, Hi: 0xA7D8, Stride: 1}, + {Lo: 0xA7DA, Hi: 0xA7DA, Stride: 1}, + {Lo: 0xA7DC, Hi: 0xA7DC, Stride: 1}, + {Lo: 0xA7F5, Hi: 0xA7F5, Stride: 1}, + {Lo: 0xFF21, Hi: 0xFF3A, Stride: 1}, + }, + R32: []unicode.Range32{ + {Lo: 0x10400, Hi: 0x10427, Stride: 1}, + {Lo: 0x104B0, Hi: 0x104D3, Stride: 1}, + {Lo: 0x10570, Hi: 0x1057A, Stride: 1}, + {Lo: 0x1057C, Hi: 0x1058A, Stride: 1}, + {Lo: 0x1058C, Hi: 0x10592, Stride: 1}, + {Lo: 0x10594, Hi: 0x10595, Stride: 1}, + {Lo: 0x10C80, Hi: 0x10CB2, Stride: 1}, + {Lo: 0x10D50, Hi: 0x10D65, Stride: 1}, + {Lo: 0x118A0, Hi: 0x118BF, Stride: 1}, + {Lo: 0x16E40, Hi: 0x16E5F, Stride: 1}, + {Lo: 0x16EA0, Hi: 0x16EB8, Stride: 1}, + {Lo: 0x1D400, Hi: 0x1D419, Stride: 1}, + {Lo: 0x1D434, Hi: 0x1D44D, Stride: 1}, + {Lo: 0x1D468, Hi: 0x1D481, Stride: 1}, + {Lo: 0x1D49C, Hi: 0x1D49C, Stride: 1}, + {Lo: 0x1D49E, Hi: 0x1D49F, Stride: 1}, + {Lo: 0x1D4A2, Hi: 0x1D4A2, Stride: 1}, + {Lo: 0x1D4A5, Hi: 0x1D4A6, Stride: 1}, + {Lo: 0x1D4A9, Hi: 0x1D4AC, Stride: 1}, + {Lo: 0x1D4AE, Hi: 0x1D4B5, Stride: 1}, + {Lo: 0x1D4D0, Hi: 0x1D4E9, Stride: 1}, + {Lo: 0x1D504, Hi: 0x1D505, Stride: 1}, + {Lo: 0x1D507, Hi: 0x1D50A, Stride: 1}, + {Lo: 0x1D50D, Hi: 0x1D514, Stride: 1}, + {Lo: 0x1D516, Hi: 0x1D51C, Stride: 1}, + {Lo: 0x1D538, Hi: 0x1D539, Stride: 1}, + {Lo: 0x1D53B, Hi: 0x1D53E, Stride: 1}, + {Lo: 0x1D540, Hi: 0x1D544, Stride: 1}, + {Lo: 0x1D546, Hi: 0x1D546, Stride: 1}, + {Lo: 0x1D54A, Hi: 0x1D550, Stride: 1}, + {Lo: 0x1D56C, Hi: 0x1D585, Stride: 1}, + {Lo: 0x1D5A0, Hi: 0x1D5B9, Stride: 1}, + {Lo: 0x1D5D4, Hi: 0x1D5ED, Stride: 1}, + {Lo: 0x1D608, Hi: 0x1D621, Stride: 1}, + {Lo: 0x1D63C, Hi: 0x1D655, Stride: 1}, + {Lo: 0x1D670, Hi: 0x1D689, Stride: 1}, + {Lo: 0x1D6A8, Hi: 0x1D6C0, Stride: 1}, + {Lo: 0x1D6E2, Hi: 0x1D6FA, Stride: 1}, + {Lo: 0x1D71C, Hi: 0x1D734, Stride: 1}, + {Lo: 0x1D756, Hi: 0x1D76E, Stride: 1}, + {Lo: 0x1D790, Hi: 0x1D7A8, Stride: 1}, + {Lo: 0x1D7CA, Hi: 0x1D7CA, Stride: 1}, + {Lo: 0x1E900, Hi: 0x1E921, Stride: 1}, + {Lo: 0x1F130, Hi: 0x1F149, Stride: 1}, + {Lo: 0x1F150, Hi: 0x1F169, Stride: 1}, + {Lo: 0x1F170, Hi: 0x1F189, Stride: 1}, + }, +} + +var unicodeAliasWord_Break_ALetter = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0x41, Hi: 0x5A, Stride: 1}, + {Lo: 0x61, Hi: 0x7A, Stride: 1}, + {Lo: 0xAA, Hi: 0xAA, Stride: 1}, + {Lo: 0xB5, Hi: 0xB5, Stride: 1}, + {Lo: 0xB8, Hi: 0xB8, Stride: 1}, + {Lo: 0xBA, Hi: 0xBA, Stride: 1}, + {Lo: 0xC0, Hi: 0xD6, Stride: 1}, + {Lo: 0xD8, Hi: 0xF6, Stride: 1}, + {Lo: 0xF8, Hi: 0x2D7, Stride: 1}, + {Lo: 0x2DE, Hi: 0x2FF, Stride: 1}, + {Lo: 0x370, Hi: 0x374, Stride: 1}, + {Lo: 0x376, Hi: 0x377, Stride: 1}, + {Lo: 0x37A, Hi: 0x37D, Stride: 1}, + {Lo: 0x37F, Hi: 0x37F, Stride: 1}, + {Lo: 0x386, Hi: 0x386, Stride: 1}, + {Lo: 0x388, Hi: 0x38A, Stride: 1}, + {Lo: 0x38C, Hi: 0x38C, Stride: 1}, + {Lo: 0x38E, Hi: 0x3A1, Stride: 1}, + {Lo: 0x3A3, Hi: 0x3F5, Stride: 1}, + {Lo: 0x3F7, Hi: 0x481, Stride: 1}, + {Lo: 0x48A, Hi: 0x52F, Stride: 1}, + {Lo: 0x531, Hi: 0x556, Stride: 1}, + {Lo: 0x559, Hi: 0x55C, Stride: 1}, + {Lo: 0x55E, Hi: 0x55E, Stride: 1}, + {Lo: 0x560, Hi: 0x588, Stride: 1}, + {Lo: 0x58A, Hi: 0x58A, Stride: 1}, + {Lo: 0x5F3, Hi: 0x5F3, Stride: 1}, + {Lo: 0x620, Hi: 0x64A, Stride: 1}, + {Lo: 0x66E, Hi: 0x66F, Stride: 1}, + {Lo: 0x671, Hi: 0x6D3, Stride: 1}, + {Lo: 0x6D5, Hi: 0x6D5, Stride: 1}, + {Lo: 0x6E5, Hi: 0x6E6, Stride: 1}, + {Lo: 0x6EE, Hi: 0x6EF, Stride: 1}, + {Lo: 0x6FA, Hi: 0x6FC, Stride: 1}, + {Lo: 0x6FF, Hi: 0x6FF, Stride: 1}, + {Lo: 0x70F, Hi: 0x710, Stride: 1}, + {Lo: 0x712, Hi: 0x72F, Stride: 1}, + {Lo: 0x74D, Hi: 0x7A5, Stride: 1}, + {Lo: 0x7B1, Hi: 0x7B1, Stride: 1}, + {Lo: 0x7CA, Hi: 0x7EA, Stride: 1}, + {Lo: 0x7F4, Hi: 0x7F5, Stride: 1}, + {Lo: 0x7FA, Hi: 0x7FA, Stride: 1}, + {Lo: 0x800, Hi: 0x815, Stride: 1}, + {Lo: 0x81A, Hi: 0x81A, Stride: 1}, + {Lo: 0x824, Hi: 0x824, Stride: 1}, + {Lo: 0x828, Hi: 0x828, Stride: 1}, + {Lo: 0x840, Hi: 0x858, Stride: 1}, + {Lo: 0x860, Hi: 0x86A, Stride: 1}, + {Lo: 0x870, Hi: 0x887, Stride: 1}, + {Lo: 0x889, Hi: 0x88F, Stride: 1}, + {Lo: 0x8A0, Hi: 0x8C9, Stride: 1}, + {Lo: 0x904, Hi: 0x939, Stride: 1}, + {Lo: 0x93D, Hi: 0x93D, Stride: 1}, + {Lo: 0x950, Hi: 0x950, Stride: 1}, + {Lo: 0x958, Hi: 0x961, Stride: 1}, + {Lo: 0x971, Hi: 0x980, Stride: 1}, + {Lo: 0x985, Hi: 0x98C, Stride: 1}, + {Lo: 0x98F, Hi: 0x990, Stride: 1}, + {Lo: 0x993, Hi: 0x9A8, Stride: 1}, + {Lo: 0x9AA, Hi: 0x9B0, Stride: 1}, + {Lo: 0x9B2, Hi: 0x9B2, Stride: 1}, + {Lo: 0x9B6, Hi: 0x9B9, Stride: 1}, + {Lo: 0x9BD, Hi: 0x9BD, Stride: 1}, + {Lo: 0x9CE, Hi: 0x9CE, Stride: 1}, + {Lo: 0x9DC, Hi: 0x9DD, Stride: 1}, + {Lo: 0x9DF, Hi: 0x9E1, Stride: 1}, + {Lo: 0x9F0, Hi: 0x9F1, Stride: 1}, + {Lo: 0x9FC, Hi: 0x9FC, Stride: 1}, + {Lo: 0xA05, Hi: 0xA0A, Stride: 1}, + {Lo: 0xA0F, Hi: 0xA10, Stride: 1}, + {Lo: 0xA13, Hi: 0xA28, Stride: 1}, + {Lo: 0xA2A, Hi: 0xA30, Stride: 1}, + {Lo: 0xA32, Hi: 0xA33, Stride: 1}, + {Lo: 0xA35, Hi: 0xA36, Stride: 1}, + {Lo: 0xA38, Hi: 0xA39, Stride: 1}, + {Lo: 0xA59, Hi: 0xA5C, Stride: 1}, + {Lo: 0xA5E, Hi: 0xA5E, Stride: 1}, + {Lo: 0xA72, Hi: 0xA74, Stride: 1}, + {Lo: 0xA85, Hi: 0xA8D, Stride: 1}, + {Lo: 0xA8F, Hi: 0xA91, Stride: 1}, + {Lo: 0xA93, Hi: 0xAA8, Stride: 1}, + {Lo: 0xAAA, Hi: 0xAB0, Stride: 1}, + {Lo: 0xAB2, Hi: 0xAB3, Stride: 1}, + {Lo: 0xAB5, Hi: 0xAB9, Stride: 1}, + {Lo: 0xABD, Hi: 0xABD, Stride: 1}, + {Lo: 0xAD0, Hi: 0xAD0, Stride: 1}, + {Lo: 0xAE0, Hi: 0xAE1, Stride: 1}, + {Lo: 0xAF9, Hi: 0xAF9, Stride: 1}, + {Lo: 0xB05, Hi: 0xB0C, Stride: 1}, + {Lo: 0xB0F, Hi: 0xB10, Stride: 1}, + {Lo: 0xB13, Hi: 0xB28, Stride: 1}, + {Lo: 0xB2A, Hi: 0xB30, Stride: 1}, + {Lo: 0xB32, Hi: 0xB33, Stride: 1}, + {Lo: 0xB35, Hi: 0xB39, Stride: 1}, + {Lo: 0xB3D, Hi: 0xB3D, Stride: 1}, + {Lo: 0xB5C, Hi: 0xB5D, Stride: 1}, + {Lo: 0xB5F, Hi: 0xB61, Stride: 1}, + {Lo: 0xB71, Hi: 0xB71, Stride: 1}, + {Lo: 0xB83, Hi: 0xB83, Stride: 1}, + {Lo: 0xB85, Hi: 0xB8A, Stride: 1}, + {Lo: 0xB8E, Hi: 0xB90, Stride: 1}, + {Lo: 0xB92, Hi: 0xB95, Stride: 1}, + {Lo: 0xB99, Hi: 0xB9A, Stride: 1}, + {Lo: 0xB9C, Hi: 0xB9C, Stride: 1}, + {Lo: 0xB9E, Hi: 0xB9F, Stride: 1}, + {Lo: 0xBA3, Hi: 0xBA4, Stride: 1}, + {Lo: 0xBA8, Hi: 0xBAA, Stride: 1}, + {Lo: 0xBAE, Hi: 0xBB9, Stride: 1}, + {Lo: 0xBD0, Hi: 0xBD0, Stride: 1}, + {Lo: 0xC05, Hi: 0xC0C, Stride: 1}, + {Lo: 0xC0E, Hi: 0xC10, Stride: 1}, + {Lo: 0xC12, Hi: 0xC28, Stride: 1}, + {Lo: 0xC2A, Hi: 0xC39, Stride: 1}, + {Lo: 0xC3D, Hi: 0xC3D, Stride: 1}, + {Lo: 0xC58, Hi: 0xC5A, Stride: 1}, + {Lo: 0xC5C, Hi: 0xC5D, Stride: 1}, + {Lo: 0xC60, Hi: 0xC61, Stride: 1}, + {Lo: 0xC80, Hi: 0xC80, Stride: 1}, + {Lo: 0xC85, Hi: 0xC8C, Stride: 1}, + {Lo: 0xC8E, Hi: 0xC90, Stride: 1}, + {Lo: 0xC92, Hi: 0xCA8, Stride: 1}, + {Lo: 0xCAA, Hi: 0xCB3, Stride: 1}, + {Lo: 0xCB5, Hi: 0xCB9, Stride: 1}, + {Lo: 0xCBD, Hi: 0xCBD, Stride: 1}, + {Lo: 0xCDC, Hi: 0xCDE, Stride: 1}, + {Lo: 0xCE0, Hi: 0xCE1, Stride: 1}, + {Lo: 0xCF1, Hi: 0xCF2, Stride: 1}, + {Lo: 0xD04, Hi: 0xD0C, Stride: 1}, + {Lo: 0xD0E, Hi: 0xD10, Stride: 1}, + {Lo: 0xD12, Hi: 0xD3A, Stride: 1}, + {Lo: 0xD3D, Hi: 0xD3D, Stride: 1}, + {Lo: 0xD4E, Hi: 0xD4E, Stride: 1}, + {Lo: 0xD54, Hi: 0xD56, Stride: 1}, + {Lo: 0xD5F, Hi: 0xD61, Stride: 1}, + {Lo: 0xD7A, Hi: 0xD7F, Stride: 1}, + {Lo: 0xD85, Hi: 0xD96, Stride: 1}, + {Lo: 0xD9A, Hi: 0xDB1, Stride: 1}, + {Lo: 0xDB3, Hi: 0xDBB, Stride: 1}, + {Lo: 0xDBD, Hi: 0xDBD, Stride: 1}, + {Lo: 0xDC0, Hi: 0xDC6, Stride: 1}, + {Lo: 0xF00, Hi: 0xF00, Stride: 1}, + {Lo: 0xF40, Hi: 0xF47, Stride: 1}, + {Lo: 0xF49, Hi: 0xF6C, Stride: 1}, + {Lo: 0xF88, Hi: 0xF8C, Stride: 1}, + {Lo: 0x10A0, Hi: 0x10C5, Stride: 1}, + {Lo: 0x10C7, Hi: 0x10C7, Stride: 1}, + {Lo: 0x10CD, Hi: 0x10CD, Stride: 1}, + {Lo: 0x10D0, Hi: 0x10FA, Stride: 1}, + {Lo: 0x10FC, Hi: 0x1248, Stride: 1}, + {Lo: 0x124A, Hi: 0x124D, Stride: 1}, + {Lo: 0x1250, Hi: 0x1256, Stride: 1}, + {Lo: 0x1258, Hi: 0x1258, Stride: 1}, + {Lo: 0x125A, Hi: 0x125D, Stride: 1}, + {Lo: 0x1260, Hi: 0x1288, Stride: 1}, + {Lo: 0x128A, Hi: 0x128D, Stride: 1}, + {Lo: 0x1290, Hi: 0x12B0, Stride: 1}, + {Lo: 0x12B2, Hi: 0x12B5, Stride: 1}, + {Lo: 0x12B8, Hi: 0x12BE, Stride: 1}, + {Lo: 0x12C0, Hi: 0x12C0, Stride: 1}, + {Lo: 0x12C2, Hi: 0x12C5, Stride: 1}, + {Lo: 0x12C8, Hi: 0x12D6, Stride: 1}, + {Lo: 0x12D8, Hi: 0x1310, Stride: 1}, + {Lo: 0x1312, Hi: 0x1315, Stride: 1}, + {Lo: 0x1318, Hi: 0x135A, Stride: 1}, + {Lo: 0x1380, Hi: 0x138F, Stride: 1}, + {Lo: 0x13A0, Hi: 0x13F5, Stride: 1}, + {Lo: 0x13F8, Hi: 0x13FD, Stride: 1}, + {Lo: 0x1401, Hi: 0x166C, Stride: 1}, + {Lo: 0x166F, Hi: 0x167F, Stride: 1}, + {Lo: 0x1681, Hi: 0x169A, Stride: 1}, + {Lo: 0x16A0, Hi: 0x16EA, Stride: 1}, + {Lo: 0x16EE, Hi: 0x16F8, Stride: 1}, + {Lo: 0x1700, Hi: 0x1711, Stride: 1}, + {Lo: 0x171F, Hi: 0x1731, Stride: 1}, + {Lo: 0x1740, Hi: 0x1751, Stride: 1}, + {Lo: 0x1760, Hi: 0x176C, Stride: 1}, + {Lo: 0x176E, Hi: 0x1770, Stride: 1}, + {Lo: 0x1820, Hi: 0x1878, Stride: 1}, + {Lo: 0x1880, Hi: 0x1884, Stride: 1}, + {Lo: 0x1887, Hi: 0x18A8, Stride: 1}, + {Lo: 0x18AA, Hi: 0x18AA, Stride: 1}, + {Lo: 0x18B0, Hi: 0x18F5, Stride: 1}, + {Lo: 0x1900, Hi: 0x191E, Stride: 1}, + {Lo: 0x1A00, Hi: 0x1A16, Stride: 1}, + {Lo: 0x1B05, Hi: 0x1B33, Stride: 1}, + {Lo: 0x1B45, Hi: 0x1B4C, Stride: 1}, + {Lo: 0x1B83, Hi: 0x1BA0, Stride: 1}, + {Lo: 0x1BAE, Hi: 0x1BAF, Stride: 1}, + {Lo: 0x1BBA, Hi: 0x1BE5, Stride: 1}, + {Lo: 0x1C00, Hi: 0x1C23, Stride: 1}, + {Lo: 0x1C4D, Hi: 0x1C4F, Stride: 1}, + {Lo: 0x1C5A, Hi: 0x1C7D, Stride: 1}, + {Lo: 0x1C80, Hi: 0x1C8A, Stride: 1}, + {Lo: 0x1C90, Hi: 0x1CBA, Stride: 1}, + {Lo: 0x1CBD, Hi: 0x1CBF, Stride: 1}, + {Lo: 0x1CE9, Hi: 0x1CEC, Stride: 1}, + {Lo: 0x1CEE, Hi: 0x1CF3, Stride: 1}, + {Lo: 0x1CF5, Hi: 0x1CF6, Stride: 1}, + {Lo: 0x1CFA, Hi: 0x1CFA, Stride: 1}, + {Lo: 0x1D00, Hi: 0x1DBF, Stride: 1}, + {Lo: 0x1E00, Hi: 0x1F15, Stride: 1}, + {Lo: 0x1F18, Hi: 0x1F1D, Stride: 1}, + {Lo: 0x1F20, Hi: 0x1F45, Stride: 1}, + {Lo: 0x1F48, Hi: 0x1F4D, Stride: 1}, + {Lo: 0x1F50, Hi: 0x1F57, Stride: 1}, + {Lo: 0x1F59, Hi: 0x1F59, Stride: 1}, + {Lo: 0x1F5B, Hi: 0x1F5B, Stride: 1}, + {Lo: 0x1F5D, Hi: 0x1F5D, Stride: 1}, + {Lo: 0x1F5F, Hi: 0x1F7D, Stride: 1}, + {Lo: 0x1F80, Hi: 0x1FB4, Stride: 1}, + {Lo: 0x1FB6, Hi: 0x1FBC, Stride: 1}, + {Lo: 0x1FBE, Hi: 0x1FBE, Stride: 1}, + {Lo: 0x1FC2, Hi: 0x1FC4, Stride: 1}, + {Lo: 0x1FC6, Hi: 0x1FCC, Stride: 1}, + {Lo: 0x1FD0, Hi: 0x1FD3, Stride: 1}, + {Lo: 0x1FD6, Hi: 0x1FDB, Stride: 1}, + {Lo: 0x1FE0, Hi: 0x1FEC, Stride: 1}, + {Lo: 0x1FF2, Hi: 0x1FF4, Stride: 1}, + {Lo: 0x1FF6, Hi: 0x1FFC, Stride: 1}, + {Lo: 0x2071, Hi: 0x2071, Stride: 1}, + {Lo: 0x207F, Hi: 0x207F, Stride: 1}, + {Lo: 0x2090, Hi: 0x209C, Stride: 1}, + {Lo: 0x2102, Hi: 0x2102, Stride: 1}, + {Lo: 0x2107, Hi: 0x2107, Stride: 1}, + {Lo: 0x210A, Hi: 0x2113, Stride: 1}, + {Lo: 0x2115, Hi: 0x2115, Stride: 1}, + {Lo: 0x2119, Hi: 0x211D, Stride: 1}, + {Lo: 0x2124, Hi: 0x2124, Stride: 1}, + {Lo: 0x2126, Hi: 0x2126, Stride: 1}, + {Lo: 0x2128, Hi: 0x2128, Stride: 1}, + {Lo: 0x212A, Hi: 0x212D, Stride: 1}, + {Lo: 0x212F, Hi: 0x2139, Stride: 1}, + {Lo: 0x213C, Hi: 0x213F, Stride: 1}, + {Lo: 0x2145, Hi: 0x2149, Stride: 1}, + {Lo: 0x214E, Hi: 0x214E, Stride: 1}, + {Lo: 0x2160, Hi: 0x2188, Stride: 1}, + {Lo: 0x24B6, Hi: 0x24E9, Stride: 1}, + {Lo: 0x2C00, Hi: 0x2CE4, Stride: 1}, + {Lo: 0x2CEB, Hi: 0x2CEE, Stride: 1}, + {Lo: 0x2CF2, Hi: 0x2CF3, Stride: 1}, + {Lo: 0x2D00, Hi: 0x2D25, Stride: 1}, + {Lo: 0x2D27, Hi: 0x2D27, Stride: 1}, + {Lo: 0x2D2D, Hi: 0x2D2D, Stride: 1}, + {Lo: 0x2D30, Hi: 0x2D67, Stride: 1}, + {Lo: 0x2D6F, Hi: 0x2D6F, Stride: 1}, + {Lo: 0x2D80, Hi: 0x2D96, Stride: 1}, + {Lo: 0x2DA0, Hi: 0x2DA6, Stride: 1}, + {Lo: 0x2DA8, Hi: 0x2DAE, Stride: 1}, + {Lo: 0x2DB0, Hi: 0x2DB6, Stride: 1}, + {Lo: 0x2DB8, Hi: 0x2DBE, Stride: 1}, + {Lo: 0x2DC0, Hi: 0x2DC6, Stride: 1}, + {Lo: 0x2DC8, Hi: 0x2DCE, Stride: 1}, + {Lo: 0x2DD0, Hi: 0x2DD6, Stride: 1}, + {Lo: 0x2DD8, Hi: 0x2DDE, Stride: 1}, + {Lo: 0x2E2F, Hi: 0x2E2F, Stride: 1}, + {Lo: 0x3005, Hi: 0x3005, Stride: 1}, + {Lo: 0x303B, Hi: 0x303C, Stride: 1}, + {Lo: 0x3105, Hi: 0x312F, Stride: 1}, + {Lo: 0x3131, Hi: 0x318E, Stride: 1}, + {Lo: 0x31A0, Hi: 0x31BF, Stride: 1}, + {Lo: 0xA000, Hi: 0xA48C, Stride: 1}, + {Lo: 0xA4D0, Hi: 0xA4FD, Stride: 1}, + {Lo: 0xA500, Hi: 0xA60C, Stride: 1}, + {Lo: 0xA610, Hi: 0xA61F, Stride: 1}, + {Lo: 0xA62A, Hi: 0xA62B, Stride: 1}, + {Lo: 0xA640, Hi: 0xA66E, Stride: 1}, + {Lo: 0xA67F, Hi: 0xA69D, Stride: 1}, + {Lo: 0xA6A0, Hi: 0xA6EF, Stride: 1}, + {Lo: 0xA708, Hi: 0xA7DC, Stride: 1}, + {Lo: 0xA7F1, Hi: 0xA801, Stride: 1}, + {Lo: 0xA803, Hi: 0xA805, Stride: 1}, + {Lo: 0xA807, Hi: 0xA80A, Stride: 1}, + {Lo: 0xA80C, Hi: 0xA822, Stride: 1}, + {Lo: 0xA840, Hi: 0xA873, Stride: 1}, + {Lo: 0xA882, Hi: 0xA8B3, Stride: 1}, + {Lo: 0xA8F2, Hi: 0xA8F7, Stride: 1}, + {Lo: 0xA8FB, Hi: 0xA8FB, Stride: 1}, + {Lo: 0xA8FD, Hi: 0xA8FE, Stride: 1}, + {Lo: 0xA90A, Hi: 0xA925, Stride: 1}, + {Lo: 0xA930, Hi: 0xA946, Stride: 1}, + {Lo: 0xA960, Hi: 0xA97C, Stride: 1}, + {Lo: 0xA984, Hi: 0xA9B2, Stride: 1}, + {Lo: 0xA9CF, Hi: 0xA9CF, Stride: 1}, + {Lo: 0xAA00, Hi: 0xAA28, Stride: 1}, + {Lo: 0xAA40, Hi: 0xAA42, Stride: 1}, + {Lo: 0xAA44, Hi: 0xAA4B, Stride: 1}, + {Lo: 0xAAE0, Hi: 0xAAEA, Stride: 1}, + {Lo: 0xAAF2, Hi: 0xAAF4, Stride: 1}, + {Lo: 0xAB01, Hi: 0xAB06, Stride: 1}, + {Lo: 0xAB09, Hi: 0xAB0E, Stride: 1}, + {Lo: 0xAB11, Hi: 0xAB16, Stride: 1}, + {Lo: 0xAB20, Hi: 0xAB26, Stride: 1}, + {Lo: 0xAB28, Hi: 0xAB2E, Stride: 1}, + {Lo: 0xAB30, Hi: 0xAB69, Stride: 1}, + {Lo: 0xAB70, Hi: 0xABE2, Stride: 1}, + {Lo: 0xAC00, Hi: 0xD7A3, Stride: 1}, + {Lo: 0xD7B0, Hi: 0xD7C6, Stride: 1}, + {Lo: 0xD7CB, Hi: 0xD7FB, Stride: 1}, + {Lo: 0xFB00, Hi: 0xFB06, Stride: 1}, + {Lo: 0xFB13, Hi: 0xFB17, Stride: 1}, + {Lo: 0xFB50, Hi: 0xFBB1, Stride: 1}, + {Lo: 0xFBD3, Hi: 0xFD3D, Stride: 1}, + {Lo: 0xFD50, Hi: 0xFD8F, Stride: 1}, + {Lo: 0xFD92, Hi: 0xFDC7, Stride: 1}, + {Lo: 0xFDF0, Hi: 0xFDFB, Stride: 1}, + {Lo: 0xFE70, Hi: 0xFE74, Stride: 1}, + {Lo: 0xFE76, Hi: 0xFEFC, Stride: 1}, + {Lo: 0xFF21, Hi: 0xFF3A, Stride: 1}, + {Lo: 0xFF41, Hi: 0xFF5A, Stride: 1}, + {Lo: 0xFFA0, Hi: 0xFFBE, Stride: 1}, + {Lo: 0xFFC2, Hi: 0xFFC7, Stride: 1}, + {Lo: 0xFFCA, Hi: 0xFFCF, Stride: 1}, + {Lo: 0xFFD2, Hi: 0xFFD7, Stride: 1}, + {Lo: 0xFFDA, Hi: 0xFFDC, Stride: 1}, + }, + R32: []unicode.Range32{ + {Lo: 0x10000, Hi: 0x1000B, Stride: 1}, + {Lo: 0x1000D, Hi: 0x10026, Stride: 1}, + {Lo: 0x10028, Hi: 0x1003A, Stride: 1}, + {Lo: 0x1003C, Hi: 0x1003D, Stride: 1}, + {Lo: 0x1003F, Hi: 0x1004D, Stride: 1}, + {Lo: 0x10050, Hi: 0x1005D, Stride: 1}, + {Lo: 0x10080, Hi: 0x100FA, Stride: 1}, + {Lo: 0x10140, Hi: 0x10174, Stride: 1}, + {Lo: 0x10280, Hi: 0x1029C, Stride: 1}, + {Lo: 0x102A0, Hi: 0x102D0, Stride: 1}, + {Lo: 0x10300, Hi: 0x1031F, Stride: 1}, + {Lo: 0x1032D, Hi: 0x1034A, Stride: 1}, + {Lo: 0x10350, Hi: 0x10375, Stride: 1}, + {Lo: 0x10380, Hi: 0x1039D, Stride: 1}, + {Lo: 0x103A0, Hi: 0x103C3, Stride: 1}, + {Lo: 0x103C8, Hi: 0x103CF, Stride: 1}, + {Lo: 0x103D1, Hi: 0x103D5, Stride: 1}, + {Lo: 0x10400, Hi: 0x1049D, Stride: 1}, + {Lo: 0x104B0, Hi: 0x104D3, Stride: 1}, + {Lo: 0x104D8, Hi: 0x104FB, Stride: 1}, + {Lo: 0x10500, Hi: 0x10527, Stride: 1}, + {Lo: 0x10530, Hi: 0x10563, Stride: 1}, + {Lo: 0x10570, Hi: 0x1057A, Stride: 1}, + {Lo: 0x1057C, Hi: 0x1058A, Stride: 1}, + {Lo: 0x1058C, Hi: 0x10592, Stride: 1}, + {Lo: 0x10594, Hi: 0x10595, Stride: 1}, + {Lo: 0x10597, Hi: 0x105A1, Stride: 1}, + {Lo: 0x105A3, Hi: 0x105B1, Stride: 1}, + {Lo: 0x105B3, Hi: 0x105B9, Stride: 1}, + {Lo: 0x105BB, Hi: 0x105BC, Stride: 1}, + {Lo: 0x105C0, Hi: 0x105F3, Stride: 1}, + {Lo: 0x10600, Hi: 0x10736, Stride: 1}, + {Lo: 0x10740, Hi: 0x10755, Stride: 1}, + {Lo: 0x10760, Hi: 0x10767, Stride: 1}, + {Lo: 0x10780, Hi: 0x10785, Stride: 1}, + {Lo: 0x10787, Hi: 0x107B0, Stride: 1}, + {Lo: 0x107B2, Hi: 0x107BA, Stride: 1}, + {Lo: 0x10800, Hi: 0x10805, Stride: 1}, + {Lo: 0x10808, Hi: 0x10808, Stride: 1}, + {Lo: 0x1080A, Hi: 0x10835, Stride: 1}, + {Lo: 0x10837, Hi: 0x10838, Stride: 1}, + {Lo: 0x1083C, Hi: 0x1083C, Stride: 1}, + {Lo: 0x1083F, Hi: 0x10855, Stride: 1}, + {Lo: 0x10860, Hi: 0x10876, Stride: 1}, + {Lo: 0x10880, Hi: 0x1089E, Stride: 1}, + {Lo: 0x108E0, Hi: 0x108F2, Stride: 1}, + {Lo: 0x108F4, Hi: 0x108F5, Stride: 1}, + {Lo: 0x10900, Hi: 0x10915, Stride: 1}, + {Lo: 0x10920, Hi: 0x10939, Stride: 1}, + {Lo: 0x10940, Hi: 0x10959, Stride: 1}, + {Lo: 0x10980, Hi: 0x109B7, Stride: 1}, + {Lo: 0x109BE, Hi: 0x109BF, Stride: 1}, + {Lo: 0x10A00, Hi: 0x10A00, Stride: 1}, + {Lo: 0x10A10, Hi: 0x10A13, Stride: 1}, + {Lo: 0x10A15, Hi: 0x10A17, Stride: 1}, + {Lo: 0x10A19, Hi: 0x10A35, Stride: 1}, + {Lo: 0x10A60, Hi: 0x10A7C, Stride: 1}, + {Lo: 0x10A80, Hi: 0x10A9C, Stride: 1}, + {Lo: 0x10AC0, Hi: 0x10AC7, Stride: 1}, + {Lo: 0x10AC9, Hi: 0x10AE4, Stride: 1}, + {Lo: 0x10B00, Hi: 0x10B35, Stride: 1}, + {Lo: 0x10B40, Hi: 0x10B55, Stride: 1}, + {Lo: 0x10B60, Hi: 0x10B72, Stride: 1}, + {Lo: 0x10B80, Hi: 0x10B91, Stride: 1}, + {Lo: 0x10C00, Hi: 0x10C48, Stride: 1}, + {Lo: 0x10C80, Hi: 0x10CB2, Stride: 1}, + {Lo: 0x10CC0, Hi: 0x10CF2, Stride: 1}, + {Lo: 0x10D00, Hi: 0x10D23, Stride: 1}, + {Lo: 0x10D4A, Hi: 0x10D65, Stride: 1}, + {Lo: 0x10D6F, Hi: 0x10D85, Stride: 1}, + {Lo: 0x10E80, Hi: 0x10EA9, Stride: 1}, + {Lo: 0x10EB0, Hi: 0x10EB1, Stride: 1}, + {Lo: 0x10EC2, Hi: 0x10EC7, Stride: 1}, + {Lo: 0x10F00, Hi: 0x10F1C, Stride: 1}, + {Lo: 0x10F27, Hi: 0x10F27, Stride: 1}, + {Lo: 0x10F30, Hi: 0x10F45, Stride: 1}, + {Lo: 0x10F70, Hi: 0x10F81, Stride: 1}, + {Lo: 0x10FB0, Hi: 0x10FC4, Stride: 1}, + {Lo: 0x10FE0, Hi: 0x10FF6, Stride: 1}, + {Lo: 0x11003, Hi: 0x11037, Stride: 1}, + {Lo: 0x11071, Hi: 0x11072, Stride: 1}, + {Lo: 0x11075, Hi: 0x11075, Stride: 1}, + {Lo: 0x11083, Hi: 0x110AF, Stride: 1}, + {Lo: 0x110D0, Hi: 0x110E8, Stride: 1}, + {Lo: 0x11103, Hi: 0x11126, Stride: 1}, + {Lo: 0x11144, Hi: 0x11144, Stride: 1}, + {Lo: 0x11147, Hi: 0x11147, Stride: 1}, + {Lo: 0x11150, Hi: 0x11172, Stride: 1}, + {Lo: 0x11176, Hi: 0x11176, Stride: 1}, + {Lo: 0x11183, Hi: 0x111B2, Stride: 1}, + {Lo: 0x111C1, Hi: 0x111C4, Stride: 1}, + {Lo: 0x111DA, Hi: 0x111DA, Stride: 1}, + {Lo: 0x111DC, Hi: 0x111DC, Stride: 1}, + {Lo: 0x11200, Hi: 0x11211, Stride: 1}, + {Lo: 0x11213, Hi: 0x1122B, Stride: 1}, + {Lo: 0x1123F, Hi: 0x11240, Stride: 1}, + {Lo: 0x11280, Hi: 0x11286, Stride: 1}, + {Lo: 0x11288, Hi: 0x11288, Stride: 1}, + {Lo: 0x1128A, Hi: 0x1128D, Stride: 1}, + {Lo: 0x1128F, Hi: 0x1129D, Stride: 1}, + {Lo: 0x1129F, Hi: 0x112A8, Stride: 1}, + {Lo: 0x112B0, Hi: 0x112DE, Stride: 1}, + {Lo: 0x11305, Hi: 0x1130C, Stride: 1}, + {Lo: 0x1130F, Hi: 0x11310, Stride: 1}, + {Lo: 0x11313, Hi: 0x11328, Stride: 1}, + {Lo: 0x1132A, Hi: 0x11330, Stride: 1}, + {Lo: 0x11332, Hi: 0x11333, Stride: 1}, + {Lo: 0x11335, Hi: 0x11339, Stride: 1}, + {Lo: 0x1133D, Hi: 0x1133D, Stride: 1}, + {Lo: 0x11350, Hi: 0x11350, Stride: 1}, + {Lo: 0x1135D, Hi: 0x11361, Stride: 1}, + {Lo: 0x11380, Hi: 0x11389, Stride: 1}, + {Lo: 0x1138B, Hi: 0x1138B, Stride: 1}, + {Lo: 0x1138E, Hi: 0x1138E, Stride: 1}, + {Lo: 0x11390, Hi: 0x113B5, Stride: 1}, + {Lo: 0x113B7, Hi: 0x113B7, Stride: 1}, + {Lo: 0x113D1, Hi: 0x113D1, Stride: 1}, + {Lo: 0x113D3, Hi: 0x113D3, Stride: 1}, + {Lo: 0x11400, Hi: 0x11434, Stride: 1}, + {Lo: 0x11447, Hi: 0x1144A, Stride: 1}, + {Lo: 0x1145F, Hi: 0x11461, Stride: 1}, + {Lo: 0x11480, Hi: 0x114AF, Stride: 1}, + {Lo: 0x114C4, Hi: 0x114C5, Stride: 1}, + {Lo: 0x114C7, Hi: 0x114C7, Stride: 1}, + {Lo: 0x11580, Hi: 0x115AE, Stride: 1}, + {Lo: 0x115D8, Hi: 0x115DB, Stride: 1}, + {Lo: 0x11600, Hi: 0x1162F, Stride: 1}, + {Lo: 0x11644, Hi: 0x11644, Stride: 1}, + {Lo: 0x11680, Hi: 0x116AA, Stride: 1}, + {Lo: 0x116B8, Hi: 0x116B8, Stride: 1}, + {Lo: 0x11800, Hi: 0x1182B, Stride: 1}, + {Lo: 0x118A0, Hi: 0x118DF, Stride: 1}, + {Lo: 0x118FF, Hi: 0x11906, Stride: 1}, + {Lo: 0x11909, Hi: 0x11909, Stride: 1}, + {Lo: 0x1190C, Hi: 0x11913, Stride: 1}, + {Lo: 0x11915, Hi: 0x11916, Stride: 1}, + {Lo: 0x11918, Hi: 0x1192F, Stride: 1}, + {Lo: 0x1193F, Hi: 0x1193F, Stride: 1}, + {Lo: 0x11941, Hi: 0x11941, Stride: 1}, + {Lo: 0x119A0, Hi: 0x119A7, Stride: 1}, + {Lo: 0x119AA, Hi: 0x119D0, Stride: 1}, + {Lo: 0x119E1, Hi: 0x119E1, Stride: 1}, + {Lo: 0x119E3, Hi: 0x119E3, Stride: 1}, + {Lo: 0x11A00, Hi: 0x11A00, Stride: 1}, + {Lo: 0x11A0B, Hi: 0x11A32, Stride: 1}, + {Lo: 0x11A3A, Hi: 0x11A3A, Stride: 1}, + {Lo: 0x11A50, Hi: 0x11A50, Stride: 1}, + {Lo: 0x11A5C, Hi: 0x11A89, Stride: 1}, + {Lo: 0x11A9D, Hi: 0x11A9D, Stride: 1}, + {Lo: 0x11AB0, Hi: 0x11AF8, Stride: 1}, + {Lo: 0x11BC0, Hi: 0x11BE0, Stride: 1}, + {Lo: 0x11C00, Hi: 0x11C08, Stride: 1}, + {Lo: 0x11C0A, Hi: 0x11C2E, Stride: 1}, + {Lo: 0x11C40, Hi: 0x11C40, Stride: 1}, + {Lo: 0x11C72, Hi: 0x11C8F, Stride: 1}, + {Lo: 0x11D00, Hi: 0x11D06, Stride: 1}, + {Lo: 0x11D08, Hi: 0x11D09, Stride: 1}, + {Lo: 0x11D0B, Hi: 0x11D30, Stride: 1}, + {Lo: 0x11D46, Hi: 0x11D46, Stride: 1}, + {Lo: 0x11D60, Hi: 0x11D65, Stride: 1}, + {Lo: 0x11D67, Hi: 0x11D68, Stride: 1}, + {Lo: 0x11D6A, Hi: 0x11D89, Stride: 1}, + {Lo: 0x11D98, Hi: 0x11D98, Stride: 1}, + {Lo: 0x11DB0, Hi: 0x11DDB, Stride: 1}, + {Lo: 0x11EE0, Hi: 0x11EF2, Stride: 1}, + {Lo: 0x11F02, Hi: 0x11F02, Stride: 1}, + {Lo: 0x11F04, Hi: 0x11F10, Stride: 1}, + {Lo: 0x11F12, Hi: 0x11F33, Stride: 1}, + {Lo: 0x11FB0, Hi: 0x11FB0, Stride: 1}, + {Lo: 0x12000, Hi: 0x12399, Stride: 1}, + {Lo: 0x12400, Hi: 0x1246E, Stride: 1}, + {Lo: 0x12480, Hi: 0x12543, Stride: 1}, + {Lo: 0x12F90, Hi: 0x12FF0, Stride: 1}, + {Lo: 0x13000, Hi: 0x1342F, Stride: 1}, + {Lo: 0x13441, Hi: 0x13446, Stride: 1}, + {Lo: 0x13460, Hi: 0x143FA, Stride: 1}, + {Lo: 0x14400, Hi: 0x14646, Stride: 1}, + {Lo: 0x16100, Hi: 0x1611D, Stride: 1}, + {Lo: 0x16800, Hi: 0x16A38, Stride: 1}, + {Lo: 0x16A40, Hi: 0x16A5E, Stride: 1}, + {Lo: 0x16A70, Hi: 0x16ABE, Stride: 1}, + {Lo: 0x16AD0, Hi: 0x16AED, Stride: 1}, + {Lo: 0x16B00, Hi: 0x16B2F, Stride: 1}, + {Lo: 0x16B40, Hi: 0x16B43, Stride: 1}, + {Lo: 0x16B63, Hi: 0x16B77, Stride: 1}, + {Lo: 0x16B7D, Hi: 0x16B8F, Stride: 1}, + {Lo: 0x16D40, Hi: 0x16D6C, Stride: 1}, + {Lo: 0x16E40, Hi: 0x16E7F, Stride: 1}, + {Lo: 0x16EA0, Hi: 0x16EB8, Stride: 1}, + {Lo: 0x16EBB, Hi: 0x16ED3, Stride: 1}, + {Lo: 0x16F00, Hi: 0x16F4A, Stride: 1}, + {Lo: 0x16F50, Hi: 0x16F50, Stride: 1}, + {Lo: 0x16F93, Hi: 0x16F9F, Stride: 1}, + {Lo: 0x16FE0, Hi: 0x16FE1, Stride: 1}, + {Lo: 0x16FE3, Hi: 0x16FE3, Stride: 1}, + {Lo: 0x1BC00, Hi: 0x1BC6A, Stride: 1}, + {Lo: 0x1BC70, Hi: 0x1BC7C, Stride: 1}, + {Lo: 0x1BC80, Hi: 0x1BC88, Stride: 1}, + {Lo: 0x1BC90, Hi: 0x1BC99, Stride: 1}, + {Lo: 0x1D400, Hi: 0x1D454, Stride: 1}, + {Lo: 0x1D456, Hi: 0x1D49C, Stride: 1}, + {Lo: 0x1D49E, Hi: 0x1D49F, Stride: 1}, + {Lo: 0x1D4A2, Hi: 0x1D4A2, Stride: 1}, + {Lo: 0x1D4A5, Hi: 0x1D4A6, Stride: 1}, + {Lo: 0x1D4A9, Hi: 0x1D4AC, Stride: 1}, + {Lo: 0x1D4AE, Hi: 0x1D4B9, Stride: 1}, + {Lo: 0x1D4BB, Hi: 0x1D4BB, Stride: 1}, + {Lo: 0x1D4BD, Hi: 0x1D4C3, Stride: 1}, + {Lo: 0x1D4C5, Hi: 0x1D505, Stride: 1}, + {Lo: 0x1D507, Hi: 0x1D50A, Stride: 1}, + {Lo: 0x1D50D, Hi: 0x1D514, Stride: 1}, + {Lo: 0x1D516, Hi: 0x1D51C, Stride: 1}, + {Lo: 0x1D51E, Hi: 0x1D539, Stride: 1}, + {Lo: 0x1D53B, Hi: 0x1D53E, Stride: 1}, + {Lo: 0x1D540, Hi: 0x1D544, Stride: 1}, + {Lo: 0x1D546, Hi: 0x1D546, Stride: 1}, + {Lo: 0x1D54A, Hi: 0x1D550, Stride: 1}, + {Lo: 0x1D552, Hi: 0x1D6A5, Stride: 1}, + {Lo: 0x1D6A8, Hi: 0x1D6C0, Stride: 1}, + {Lo: 0x1D6C2, Hi: 0x1D6DA, Stride: 1}, + {Lo: 0x1D6DC, Hi: 0x1D6FA, Stride: 1}, + {Lo: 0x1D6FC, Hi: 0x1D714, Stride: 1}, + {Lo: 0x1D716, Hi: 0x1D734, Stride: 1}, + {Lo: 0x1D736, Hi: 0x1D74E, Stride: 1}, + {Lo: 0x1D750, Hi: 0x1D76E, Stride: 1}, + {Lo: 0x1D770, Hi: 0x1D788, Stride: 1}, + {Lo: 0x1D78A, Hi: 0x1D7A8, Stride: 1}, + {Lo: 0x1D7AA, Hi: 0x1D7C2, Stride: 1}, + {Lo: 0x1D7C4, Hi: 0x1D7CB, Stride: 1}, + {Lo: 0x1DF00, Hi: 0x1DF1E, Stride: 1}, + {Lo: 0x1DF25, Hi: 0x1DF2A, Stride: 1}, + {Lo: 0x1E030, Hi: 0x1E06D, Stride: 1}, + {Lo: 0x1E100, Hi: 0x1E12C, Stride: 1}, + {Lo: 0x1E137, Hi: 0x1E13D, Stride: 1}, + {Lo: 0x1E14E, Hi: 0x1E14E, Stride: 1}, + {Lo: 0x1E290, Hi: 0x1E2AD, Stride: 1}, + {Lo: 0x1E2C0, Hi: 0x1E2EB, Stride: 1}, + {Lo: 0x1E4D0, Hi: 0x1E4EB, Stride: 1}, + {Lo: 0x1E5D0, Hi: 0x1E5ED, Stride: 1}, + {Lo: 0x1E5F0, Hi: 0x1E5F0, Stride: 1}, + {Lo: 0x1E6C0, Hi: 0x1E6DE, Stride: 1}, + {Lo: 0x1E6E0, Hi: 0x1E6E2, Stride: 1}, + {Lo: 0x1E6E4, Hi: 0x1E6E5, Stride: 1}, + {Lo: 0x1E6E7, Hi: 0x1E6ED, Stride: 1}, + {Lo: 0x1E6F0, Hi: 0x1E6F4, Stride: 1}, + {Lo: 0x1E6FE, Hi: 0x1E6FF, Stride: 1}, + {Lo: 0x1E7E0, Hi: 0x1E7E6, Stride: 1}, + {Lo: 0x1E7E8, Hi: 0x1E7EB, Stride: 1}, + {Lo: 0x1E7ED, Hi: 0x1E7EE, Stride: 1}, + {Lo: 0x1E7F0, Hi: 0x1E7FE, Stride: 1}, + {Lo: 0x1E800, Hi: 0x1E8C4, Stride: 1}, + {Lo: 0x1E900, Hi: 0x1E943, Stride: 1}, + {Lo: 0x1E94B, Hi: 0x1E94B, Stride: 1}, + {Lo: 0x1EE00, Hi: 0x1EE03, Stride: 1}, + {Lo: 0x1EE05, Hi: 0x1EE1F, Stride: 1}, + {Lo: 0x1EE21, Hi: 0x1EE22, Stride: 1}, + {Lo: 0x1EE24, Hi: 0x1EE24, Stride: 1}, + {Lo: 0x1EE27, Hi: 0x1EE27, Stride: 1}, + {Lo: 0x1EE29, Hi: 0x1EE32, Stride: 1}, + {Lo: 0x1EE34, Hi: 0x1EE37, Stride: 1}, + {Lo: 0x1EE39, Hi: 0x1EE39, Stride: 1}, + {Lo: 0x1EE3B, Hi: 0x1EE3B, Stride: 1}, + {Lo: 0x1EE42, Hi: 0x1EE42, Stride: 1}, + {Lo: 0x1EE47, Hi: 0x1EE47, Stride: 1}, + {Lo: 0x1EE49, Hi: 0x1EE49, Stride: 1}, + {Lo: 0x1EE4B, Hi: 0x1EE4B, Stride: 1}, + {Lo: 0x1EE4D, Hi: 0x1EE4F, Stride: 1}, + {Lo: 0x1EE51, Hi: 0x1EE52, Stride: 1}, + {Lo: 0x1EE54, Hi: 0x1EE54, Stride: 1}, + {Lo: 0x1EE57, Hi: 0x1EE57, Stride: 1}, + {Lo: 0x1EE59, Hi: 0x1EE59, Stride: 1}, + {Lo: 0x1EE5B, Hi: 0x1EE5B, Stride: 1}, + {Lo: 0x1EE5D, Hi: 0x1EE5D, Stride: 1}, + {Lo: 0x1EE5F, Hi: 0x1EE5F, Stride: 1}, + {Lo: 0x1EE61, Hi: 0x1EE62, Stride: 1}, + {Lo: 0x1EE64, Hi: 0x1EE64, Stride: 1}, + {Lo: 0x1EE67, Hi: 0x1EE6A, Stride: 1}, + {Lo: 0x1EE6C, Hi: 0x1EE72, Stride: 1}, + {Lo: 0x1EE74, Hi: 0x1EE77, Stride: 1}, + {Lo: 0x1EE79, Hi: 0x1EE7C, Stride: 1}, + {Lo: 0x1EE7E, Hi: 0x1EE7E, Stride: 1}, + {Lo: 0x1EE80, Hi: 0x1EE89, Stride: 1}, + {Lo: 0x1EE8B, Hi: 0x1EE9B, Stride: 1}, + {Lo: 0x1EEA1, Hi: 0x1EEA3, Stride: 1}, + {Lo: 0x1EEA5, Hi: 0x1EEA9, Stride: 1}, + {Lo: 0x1EEAB, Hi: 0x1EEBB, Stride: 1}, + {Lo: 0x1F130, Hi: 0x1F149, Stride: 1}, + {Lo: 0x1F150, Hi: 0x1F169, Stride: 1}, + {Lo: 0x1F170, Hi: 0x1F189, Stride: 1}, + }, +} + +var unicodeAliasWord_Break_CR = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0xD, Hi: 0xD, Stride: 1}, + }, +} + +var unicodeAliasWord_Break_Double_Quote = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0x22, Hi: 0x22, Stride: 1}, + }, +} + +var unicodeAliasWord_Break_Extend = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0x300, Hi: 0x36F, Stride: 1}, + {Lo: 0x483, Hi: 0x489, Stride: 1}, + {Lo: 0x591, Hi: 0x5BD, Stride: 1}, + {Lo: 0x5BF, Hi: 0x5BF, Stride: 1}, + {Lo: 0x5C1, Hi: 0x5C2, Stride: 1}, + {Lo: 0x5C4, Hi: 0x5C5, Stride: 1}, + {Lo: 0x5C7, Hi: 0x5C7, Stride: 1}, + {Lo: 0x610, Hi: 0x61A, Stride: 1}, + {Lo: 0x64B, Hi: 0x65F, Stride: 1}, + {Lo: 0x670, Hi: 0x670, Stride: 1}, + {Lo: 0x6D6, Hi: 0x6DC, Stride: 1}, + {Lo: 0x6DF, Hi: 0x6E4, Stride: 1}, + {Lo: 0x6E7, Hi: 0x6E8, Stride: 1}, + {Lo: 0x6EA, Hi: 0x6ED, Stride: 1}, + {Lo: 0x711, Hi: 0x711, Stride: 1}, + {Lo: 0x730, Hi: 0x74A, Stride: 1}, + {Lo: 0x7A6, Hi: 0x7B0, Stride: 1}, + {Lo: 0x7EB, Hi: 0x7F3, Stride: 1}, + {Lo: 0x7FD, Hi: 0x7FD, Stride: 1}, + {Lo: 0x816, Hi: 0x819, Stride: 1}, + {Lo: 0x81B, Hi: 0x823, Stride: 1}, + {Lo: 0x825, Hi: 0x827, Stride: 1}, + {Lo: 0x829, Hi: 0x82D, Stride: 1}, + {Lo: 0x859, Hi: 0x85B, Stride: 1}, + {Lo: 0x897, Hi: 0x89F, Stride: 1}, + {Lo: 0x8CA, Hi: 0x8E1, Stride: 1}, + {Lo: 0x8E3, Hi: 0x903, Stride: 1}, + {Lo: 0x93A, Hi: 0x93C, Stride: 1}, + {Lo: 0x93E, Hi: 0x94F, Stride: 1}, + {Lo: 0x951, Hi: 0x957, Stride: 1}, + {Lo: 0x962, Hi: 0x963, Stride: 1}, + {Lo: 0x981, Hi: 0x983, Stride: 1}, + {Lo: 0x9BC, Hi: 0x9BC, Stride: 1}, + {Lo: 0x9BE, Hi: 0x9C4, Stride: 1}, + {Lo: 0x9C7, Hi: 0x9C8, Stride: 1}, + {Lo: 0x9CB, Hi: 0x9CD, Stride: 1}, + {Lo: 0x9D7, Hi: 0x9D7, Stride: 1}, + {Lo: 0x9E2, Hi: 0x9E3, Stride: 1}, + {Lo: 0x9FE, Hi: 0x9FE, Stride: 1}, + {Lo: 0xA01, Hi: 0xA03, Stride: 1}, + {Lo: 0xA3C, Hi: 0xA3C, Stride: 1}, + {Lo: 0xA3E, Hi: 0xA42, Stride: 1}, + {Lo: 0xA47, Hi: 0xA48, Stride: 1}, + {Lo: 0xA4B, Hi: 0xA4D, Stride: 1}, + {Lo: 0xA51, Hi: 0xA51, Stride: 1}, + {Lo: 0xA70, Hi: 0xA71, Stride: 1}, + {Lo: 0xA75, Hi: 0xA75, Stride: 1}, + {Lo: 0xA81, Hi: 0xA83, Stride: 1}, + {Lo: 0xABC, Hi: 0xABC, Stride: 1}, + {Lo: 0xABE, Hi: 0xAC5, Stride: 1}, + {Lo: 0xAC7, Hi: 0xAC9, Stride: 1}, + {Lo: 0xACB, Hi: 0xACD, Stride: 1}, + {Lo: 0xAE2, Hi: 0xAE3, Stride: 1}, + {Lo: 0xAFA, Hi: 0xAFF, Stride: 1}, + {Lo: 0xB01, Hi: 0xB03, Stride: 1}, + {Lo: 0xB3C, Hi: 0xB3C, Stride: 1}, + {Lo: 0xB3E, Hi: 0xB44, Stride: 1}, + {Lo: 0xB47, Hi: 0xB48, Stride: 1}, + {Lo: 0xB4B, Hi: 0xB4D, Stride: 1}, + {Lo: 0xB55, Hi: 0xB57, Stride: 1}, + {Lo: 0xB62, Hi: 0xB63, Stride: 1}, + {Lo: 0xB82, Hi: 0xB82, Stride: 1}, + {Lo: 0xBBE, Hi: 0xBC2, Stride: 1}, + {Lo: 0xBC6, Hi: 0xBC8, Stride: 1}, + {Lo: 0xBCA, Hi: 0xBCD, Stride: 1}, + {Lo: 0xBD7, Hi: 0xBD7, Stride: 1}, + {Lo: 0xC00, Hi: 0xC04, Stride: 1}, + {Lo: 0xC3C, Hi: 0xC3C, Stride: 1}, + {Lo: 0xC3E, Hi: 0xC44, Stride: 1}, + {Lo: 0xC46, Hi: 0xC48, Stride: 1}, + {Lo: 0xC4A, Hi: 0xC4D, Stride: 1}, + {Lo: 0xC55, Hi: 0xC56, Stride: 1}, + {Lo: 0xC62, Hi: 0xC63, Stride: 1}, + {Lo: 0xC81, Hi: 0xC83, Stride: 1}, + {Lo: 0xCBC, Hi: 0xCBC, Stride: 1}, + {Lo: 0xCBE, Hi: 0xCC4, Stride: 1}, + {Lo: 0xCC6, Hi: 0xCC8, Stride: 1}, + {Lo: 0xCCA, Hi: 0xCCD, Stride: 1}, + {Lo: 0xCD5, Hi: 0xCD6, Stride: 1}, + {Lo: 0xCE2, Hi: 0xCE3, Stride: 1}, + {Lo: 0xCF3, Hi: 0xCF3, Stride: 1}, + {Lo: 0xD00, Hi: 0xD03, Stride: 1}, + {Lo: 0xD3B, Hi: 0xD3C, Stride: 1}, + {Lo: 0xD3E, Hi: 0xD44, Stride: 1}, + {Lo: 0xD46, Hi: 0xD48, Stride: 1}, + {Lo: 0xD4A, Hi: 0xD4D, Stride: 1}, + {Lo: 0xD57, Hi: 0xD57, Stride: 1}, + {Lo: 0xD62, Hi: 0xD63, Stride: 1}, + {Lo: 0xD81, Hi: 0xD83, Stride: 1}, + {Lo: 0xDCA, Hi: 0xDCA, Stride: 1}, + {Lo: 0xDCF, Hi: 0xDD4, Stride: 1}, + {Lo: 0xDD6, Hi: 0xDD6, Stride: 1}, + {Lo: 0xDD8, Hi: 0xDDF, Stride: 1}, + {Lo: 0xDF2, Hi: 0xDF3, Stride: 1}, + {Lo: 0xE31, Hi: 0xE31, Stride: 1}, + {Lo: 0xE34, Hi: 0xE3A, Stride: 1}, + {Lo: 0xE47, Hi: 0xE4E, Stride: 1}, + {Lo: 0xEB1, Hi: 0xEB1, Stride: 1}, + {Lo: 0xEB4, Hi: 0xEBC, Stride: 1}, + {Lo: 0xEC8, Hi: 0xECE, Stride: 1}, + {Lo: 0xF18, Hi: 0xF19, Stride: 1}, + {Lo: 0xF35, Hi: 0xF35, Stride: 1}, + {Lo: 0xF37, Hi: 0xF37, Stride: 1}, + {Lo: 0xF39, Hi: 0xF39, Stride: 1}, + {Lo: 0xF3E, Hi: 0xF3F, Stride: 1}, + {Lo: 0xF71, Hi: 0xF84, Stride: 1}, + {Lo: 0xF86, Hi: 0xF87, Stride: 1}, + {Lo: 0xF8D, Hi: 0xF97, Stride: 1}, + {Lo: 0xF99, Hi: 0xFBC, Stride: 1}, + {Lo: 0xFC6, Hi: 0xFC6, Stride: 1}, + {Lo: 0x102B, Hi: 0x103E, Stride: 1}, + {Lo: 0x1056, Hi: 0x1059, Stride: 1}, + {Lo: 0x105E, Hi: 0x1060, Stride: 1}, + {Lo: 0x1062, Hi: 0x1064, Stride: 1}, + {Lo: 0x1067, Hi: 0x106D, Stride: 1}, + {Lo: 0x1071, Hi: 0x1074, Stride: 1}, + {Lo: 0x1082, Hi: 0x108D, Stride: 1}, + {Lo: 0x108F, Hi: 0x108F, Stride: 1}, + {Lo: 0x109A, Hi: 0x109D, Stride: 1}, + {Lo: 0x135D, Hi: 0x135F, Stride: 1}, + {Lo: 0x1712, Hi: 0x1715, Stride: 1}, + {Lo: 0x1732, Hi: 0x1734, Stride: 1}, + {Lo: 0x1752, Hi: 0x1753, Stride: 1}, + {Lo: 0x1772, Hi: 0x1773, Stride: 1}, + {Lo: 0x17B4, Hi: 0x17D3, Stride: 1}, + {Lo: 0x17DD, Hi: 0x17DD, Stride: 1}, + {Lo: 0x180B, Hi: 0x180D, Stride: 1}, + {Lo: 0x180F, Hi: 0x180F, Stride: 1}, + {Lo: 0x1885, Hi: 0x1886, Stride: 1}, + {Lo: 0x18A9, Hi: 0x18A9, Stride: 1}, + {Lo: 0x1920, Hi: 0x192B, Stride: 1}, + {Lo: 0x1930, Hi: 0x193B, Stride: 1}, + {Lo: 0x1A17, Hi: 0x1A1B, Stride: 1}, + {Lo: 0x1A55, Hi: 0x1A5E, Stride: 1}, + {Lo: 0x1A60, Hi: 0x1A7C, Stride: 1}, + {Lo: 0x1A7F, Hi: 0x1A7F, Stride: 1}, + {Lo: 0x1AB0, Hi: 0x1ADD, Stride: 1}, + {Lo: 0x1AE0, Hi: 0x1AEB, Stride: 1}, + {Lo: 0x1B00, Hi: 0x1B04, Stride: 1}, + {Lo: 0x1B34, Hi: 0x1B44, Stride: 1}, + {Lo: 0x1B6B, Hi: 0x1B73, Stride: 1}, + {Lo: 0x1B80, Hi: 0x1B82, Stride: 1}, + {Lo: 0x1BA1, Hi: 0x1BAD, Stride: 1}, + {Lo: 0x1BE6, Hi: 0x1BF3, Stride: 1}, + {Lo: 0x1C24, Hi: 0x1C37, Stride: 1}, + {Lo: 0x1CD0, Hi: 0x1CD2, Stride: 1}, + {Lo: 0x1CD4, Hi: 0x1CE8, Stride: 1}, + {Lo: 0x1CED, Hi: 0x1CED, Stride: 1}, + {Lo: 0x1CF4, Hi: 0x1CF4, Stride: 1}, + {Lo: 0x1CF7, Hi: 0x1CF9, Stride: 1}, + {Lo: 0x1DC0, Hi: 0x1DFF, Stride: 1}, + {Lo: 0x200C, Hi: 0x200C, Stride: 1}, + {Lo: 0x20D0, Hi: 0x20F0, Stride: 1}, + {Lo: 0x2CEF, Hi: 0x2CF1, Stride: 1}, + {Lo: 0x2D7F, Hi: 0x2D7F, Stride: 1}, + {Lo: 0x2DE0, Hi: 0x2DFF, Stride: 1}, + {Lo: 0x302A, Hi: 0x302F, Stride: 1}, + {Lo: 0x3099, Hi: 0x309A, Stride: 1}, + {Lo: 0xA66F, Hi: 0xA672, Stride: 1}, + {Lo: 0xA674, Hi: 0xA67D, Stride: 1}, + {Lo: 0xA69E, Hi: 0xA69F, Stride: 1}, + {Lo: 0xA6F0, Hi: 0xA6F1, Stride: 1}, + {Lo: 0xA802, Hi: 0xA802, Stride: 1}, + {Lo: 0xA806, Hi: 0xA806, Stride: 1}, + {Lo: 0xA80B, Hi: 0xA80B, Stride: 1}, + {Lo: 0xA823, Hi: 0xA827, Stride: 1}, + {Lo: 0xA82C, Hi: 0xA82C, Stride: 1}, + {Lo: 0xA880, Hi: 0xA881, Stride: 1}, + {Lo: 0xA8B4, Hi: 0xA8C5, Stride: 1}, + {Lo: 0xA8E0, Hi: 0xA8F1, Stride: 1}, + {Lo: 0xA8FF, Hi: 0xA8FF, Stride: 1}, + {Lo: 0xA926, Hi: 0xA92D, Stride: 1}, + {Lo: 0xA947, Hi: 0xA953, Stride: 1}, + {Lo: 0xA980, Hi: 0xA983, Stride: 1}, + {Lo: 0xA9B3, Hi: 0xA9C0, Stride: 1}, + {Lo: 0xA9E5, Hi: 0xA9E5, Stride: 1}, + {Lo: 0xAA29, Hi: 0xAA36, Stride: 1}, + {Lo: 0xAA43, Hi: 0xAA43, Stride: 1}, + {Lo: 0xAA4C, Hi: 0xAA4D, Stride: 1}, + {Lo: 0xAA7B, Hi: 0xAA7D, Stride: 1}, + {Lo: 0xAAB0, Hi: 0xAAB0, Stride: 1}, + {Lo: 0xAAB2, Hi: 0xAAB4, Stride: 1}, + {Lo: 0xAAB7, Hi: 0xAAB8, Stride: 1}, + {Lo: 0xAABE, Hi: 0xAABF, Stride: 1}, + {Lo: 0xAAC1, Hi: 0xAAC1, Stride: 1}, + {Lo: 0xAAEB, Hi: 0xAAEF, Stride: 1}, + {Lo: 0xAAF5, Hi: 0xAAF6, Stride: 1}, + {Lo: 0xABE3, Hi: 0xABEA, Stride: 1}, + {Lo: 0xABEC, Hi: 0xABED, Stride: 1}, + {Lo: 0xFB1E, Hi: 0xFB1E, Stride: 1}, + {Lo: 0xFE00, Hi: 0xFE0F, Stride: 1}, + {Lo: 0xFE20, Hi: 0xFE2F, Stride: 1}, + {Lo: 0xFF9E, Hi: 0xFF9F, Stride: 1}, + }, + R32: []unicode.Range32{ + {Lo: 0x101FD, Hi: 0x101FD, Stride: 1}, + {Lo: 0x102E0, Hi: 0x102E0, Stride: 1}, + {Lo: 0x10376, Hi: 0x1037A, Stride: 1}, + {Lo: 0x10A01, Hi: 0x10A03, Stride: 1}, + {Lo: 0x10A05, Hi: 0x10A06, Stride: 1}, + {Lo: 0x10A0C, Hi: 0x10A0F, Stride: 1}, + {Lo: 0x10A38, Hi: 0x10A3A, Stride: 1}, + {Lo: 0x10A3F, Hi: 0x10A3F, Stride: 1}, + {Lo: 0x10AE5, Hi: 0x10AE6, Stride: 1}, + {Lo: 0x10D24, Hi: 0x10D27, Stride: 1}, + {Lo: 0x10D69, Hi: 0x10D6D, Stride: 1}, + {Lo: 0x10EAB, Hi: 0x10EAC, Stride: 1}, + {Lo: 0x10EFA, Hi: 0x10EFF, Stride: 1}, + {Lo: 0x10F46, Hi: 0x10F50, Stride: 1}, + {Lo: 0x10F82, Hi: 0x10F85, Stride: 1}, + {Lo: 0x11000, Hi: 0x11002, Stride: 1}, + {Lo: 0x11038, Hi: 0x11046, Stride: 1}, + {Lo: 0x11070, Hi: 0x11070, Stride: 1}, + {Lo: 0x11073, Hi: 0x11074, Stride: 1}, + {Lo: 0x1107F, Hi: 0x11082, Stride: 1}, + {Lo: 0x110B0, Hi: 0x110BA, Stride: 1}, + {Lo: 0x110C2, Hi: 0x110C2, Stride: 1}, + {Lo: 0x11100, Hi: 0x11102, Stride: 1}, + {Lo: 0x11127, Hi: 0x11134, Stride: 1}, + {Lo: 0x11145, Hi: 0x11146, Stride: 1}, + {Lo: 0x11173, Hi: 0x11173, Stride: 1}, + {Lo: 0x11180, Hi: 0x11182, Stride: 1}, + {Lo: 0x111B3, Hi: 0x111C0, Stride: 1}, + {Lo: 0x111C9, Hi: 0x111CC, Stride: 1}, + {Lo: 0x111CE, Hi: 0x111CF, Stride: 1}, + {Lo: 0x1122C, Hi: 0x11237, Stride: 1}, + {Lo: 0x1123E, Hi: 0x1123E, Stride: 1}, + {Lo: 0x11241, Hi: 0x11241, Stride: 1}, + {Lo: 0x112DF, Hi: 0x112EA, Stride: 1}, + {Lo: 0x11300, Hi: 0x11303, Stride: 1}, + {Lo: 0x1133B, Hi: 0x1133C, Stride: 1}, + {Lo: 0x1133E, Hi: 0x11344, Stride: 1}, + {Lo: 0x11347, Hi: 0x11348, Stride: 1}, + {Lo: 0x1134B, Hi: 0x1134D, Stride: 1}, + {Lo: 0x11357, Hi: 0x11357, Stride: 1}, + {Lo: 0x11362, Hi: 0x11363, Stride: 1}, + {Lo: 0x11366, Hi: 0x1136C, Stride: 1}, + {Lo: 0x11370, Hi: 0x11374, Stride: 1}, + {Lo: 0x113B8, Hi: 0x113C0, Stride: 1}, + {Lo: 0x113C2, Hi: 0x113C2, Stride: 1}, + {Lo: 0x113C5, Hi: 0x113C5, Stride: 1}, + {Lo: 0x113C7, Hi: 0x113CA, Stride: 1}, + {Lo: 0x113CC, Hi: 0x113D0, Stride: 1}, + {Lo: 0x113D2, Hi: 0x113D2, Stride: 1}, + {Lo: 0x113E1, Hi: 0x113E2, Stride: 1}, + {Lo: 0x11435, Hi: 0x11446, Stride: 1}, + {Lo: 0x1145E, Hi: 0x1145E, Stride: 1}, + {Lo: 0x114B0, Hi: 0x114C3, Stride: 1}, + {Lo: 0x115AF, Hi: 0x115B5, Stride: 1}, + {Lo: 0x115B8, Hi: 0x115C0, Stride: 1}, + {Lo: 0x115DC, Hi: 0x115DD, Stride: 1}, + {Lo: 0x11630, Hi: 0x11640, Stride: 1}, + {Lo: 0x116AB, Hi: 0x116B7, Stride: 1}, + {Lo: 0x1171D, Hi: 0x1172B, Stride: 1}, + {Lo: 0x1182C, Hi: 0x1183A, Stride: 1}, + {Lo: 0x11930, Hi: 0x11935, Stride: 1}, + {Lo: 0x11937, Hi: 0x11938, Stride: 1}, + {Lo: 0x1193B, Hi: 0x1193E, Stride: 1}, + {Lo: 0x11940, Hi: 0x11940, Stride: 1}, + {Lo: 0x11942, Hi: 0x11943, Stride: 1}, + {Lo: 0x119D1, Hi: 0x119D7, Stride: 1}, + {Lo: 0x119DA, Hi: 0x119E0, Stride: 1}, + {Lo: 0x119E4, Hi: 0x119E4, Stride: 1}, + {Lo: 0x11A01, Hi: 0x11A0A, Stride: 1}, + {Lo: 0x11A33, Hi: 0x11A39, Stride: 1}, + {Lo: 0x11A3B, Hi: 0x11A3E, Stride: 1}, + {Lo: 0x11A47, Hi: 0x11A47, Stride: 1}, + {Lo: 0x11A51, Hi: 0x11A5B, Stride: 1}, + {Lo: 0x11A8A, Hi: 0x11A99, Stride: 1}, + {Lo: 0x11B60, Hi: 0x11B67, Stride: 1}, + {Lo: 0x11C2F, Hi: 0x11C36, Stride: 1}, + {Lo: 0x11C38, Hi: 0x11C3F, Stride: 1}, + {Lo: 0x11C92, Hi: 0x11CA7, Stride: 1}, + {Lo: 0x11CA9, Hi: 0x11CB6, Stride: 1}, + {Lo: 0x11D31, Hi: 0x11D36, Stride: 1}, + {Lo: 0x11D3A, Hi: 0x11D3A, Stride: 1}, + {Lo: 0x11D3C, Hi: 0x11D3D, Stride: 1}, + {Lo: 0x11D3F, Hi: 0x11D45, Stride: 1}, + {Lo: 0x11D47, Hi: 0x11D47, Stride: 1}, + {Lo: 0x11D8A, Hi: 0x11D8E, Stride: 1}, + {Lo: 0x11D90, Hi: 0x11D91, Stride: 1}, + {Lo: 0x11D93, Hi: 0x11D97, Stride: 1}, + {Lo: 0x11EF3, Hi: 0x11EF6, Stride: 1}, + {Lo: 0x11F00, Hi: 0x11F01, Stride: 1}, + {Lo: 0x11F03, Hi: 0x11F03, Stride: 1}, + {Lo: 0x11F34, Hi: 0x11F3A, Stride: 1}, + {Lo: 0x11F3E, Hi: 0x11F42, Stride: 1}, + {Lo: 0x11F5A, Hi: 0x11F5A, Stride: 1}, + {Lo: 0x13440, Hi: 0x13440, Stride: 1}, + {Lo: 0x13447, Hi: 0x13455, Stride: 1}, + {Lo: 0x1611E, Hi: 0x1612F, Stride: 1}, + {Lo: 0x16AF0, Hi: 0x16AF4, Stride: 1}, + {Lo: 0x16B30, Hi: 0x16B36, Stride: 1}, + {Lo: 0x16F4F, Hi: 0x16F4F, Stride: 1}, + {Lo: 0x16F51, Hi: 0x16F87, Stride: 1}, + {Lo: 0x16F8F, Hi: 0x16F92, Stride: 1}, + {Lo: 0x16FE4, Hi: 0x16FE4, Stride: 1}, + {Lo: 0x16FF0, Hi: 0x16FF1, Stride: 1}, + {Lo: 0x1BC9D, Hi: 0x1BC9E, Stride: 1}, + {Lo: 0x1CF00, Hi: 0x1CF2D, Stride: 1}, + {Lo: 0x1CF30, Hi: 0x1CF46, Stride: 1}, + {Lo: 0x1D165, Hi: 0x1D169, Stride: 1}, + {Lo: 0x1D16D, Hi: 0x1D172, Stride: 1}, + {Lo: 0x1D17B, Hi: 0x1D182, Stride: 1}, + {Lo: 0x1D185, Hi: 0x1D18B, Stride: 1}, + {Lo: 0x1D1AA, Hi: 0x1D1AD, Stride: 1}, + {Lo: 0x1D242, Hi: 0x1D244, Stride: 1}, + {Lo: 0x1DA00, Hi: 0x1DA36, Stride: 1}, + {Lo: 0x1DA3B, Hi: 0x1DA6C, Stride: 1}, + {Lo: 0x1DA75, Hi: 0x1DA75, Stride: 1}, + {Lo: 0x1DA84, Hi: 0x1DA84, Stride: 1}, + {Lo: 0x1DA9B, Hi: 0x1DA9F, Stride: 1}, + {Lo: 0x1DAA1, Hi: 0x1DAAF, Stride: 1}, + {Lo: 0x1E000, Hi: 0x1E006, Stride: 1}, + {Lo: 0x1E008, Hi: 0x1E018, Stride: 1}, + {Lo: 0x1E01B, Hi: 0x1E021, Stride: 1}, + {Lo: 0x1E023, Hi: 0x1E024, Stride: 1}, + {Lo: 0x1E026, Hi: 0x1E02A, Stride: 1}, + {Lo: 0x1E08F, Hi: 0x1E08F, Stride: 1}, + {Lo: 0x1E130, Hi: 0x1E136, Stride: 1}, + {Lo: 0x1E2AE, Hi: 0x1E2AE, Stride: 1}, + {Lo: 0x1E2EC, Hi: 0x1E2EF, Stride: 1}, + {Lo: 0x1E4EC, Hi: 0x1E4EF, Stride: 1}, + {Lo: 0x1E5EE, Hi: 0x1E5EF, Stride: 1}, + {Lo: 0x1E6E3, Hi: 0x1E6E3, Stride: 1}, + {Lo: 0x1E6E6, Hi: 0x1E6E6, Stride: 1}, + {Lo: 0x1E6EE, Hi: 0x1E6EF, Stride: 1}, + {Lo: 0x1E6F5, Hi: 0x1E6F5, Stride: 1}, + {Lo: 0x1E8D0, Hi: 0x1E8D6, Stride: 1}, + {Lo: 0x1E944, Hi: 0x1E94A, Stride: 1}, + {Lo: 0x1F3FB, Hi: 0x1F3FF, Stride: 1}, + {Lo: 0xE0020, Hi: 0xE007F, Stride: 1}, + {Lo: 0xE0100, Hi: 0xE01EF, Stride: 1}, + }, +} + +var unicodeAliasWord_Break_ExtendNumLet = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0x5F, Hi: 0x5F, Stride: 1}, + {Lo: 0x202F, Hi: 0x202F, Stride: 1}, + {Lo: 0x203F, Hi: 0x2040, Stride: 1}, + {Lo: 0x2054, Hi: 0x2054, Stride: 1}, + {Lo: 0xFE33, Hi: 0xFE34, Stride: 1}, + {Lo: 0xFE4D, Hi: 0xFE4F, Stride: 1}, + {Lo: 0xFF3F, Hi: 0xFF3F, Stride: 1}, + }, +} + +var unicodeAliasWord_Break_Format = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0xAD, Hi: 0xAD, Stride: 1}, + {Lo: 0x61C, Hi: 0x61C, Stride: 1}, + {Lo: 0x180E, Hi: 0x180E, Stride: 1}, + {Lo: 0x200E, Hi: 0x200F, Stride: 1}, + {Lo: 0x202A, Hi: 0x202E, Stride: 1}, + {Lo: 0x2060, Hi: 0x2064, Stride: 1}, + {Lo: 0x2066, Hi: 0x206F, Stride: 1}, + {Lo: 0xFEFF, Hi: 0xFEFF, Stride: 1}, + {Lo: 0xFFF9, Hi: 0xFFFB, Stride: 1}, + }, + R32: []unicode.Range32{ + {Lo: 0x13430, Hi: 0x1343F, Stride: 1}, + {Lo: 0x1BCA0, Hi: 0x1BCA3, Stride: 1}, + {Lo: 0x1D173, Hi: 0x1D17A, Stride: 1}, + {Lo: 0xE0001, Hi: 0xE0001, Stride: 1}, + }, +} + +var unicodeAliasWord_Break_Hebrew_Letter = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0x5D0, Hi: 0x5EA, Stride: 1}, + {Lo: 0x5EF, Hi: 0x5F2, Stride: 1}, + {Lo: 0xFB1D, Hi: 0xFB1D, Stride: 1}, + {Lo: 0xFB1F, Hi: 0xFB28, Stride: 1}, + {Lo: 0xFB2A, Hi: 0xFB36, Stride: 1}, + {Lo: 0xFB38, Hi: 0xFB3C, Stride: 1}, + {Lo: 0xFB3E, Hi: 0xFB3E, Stride: 1}, + {Lo: 0xFB40, Hi: 0xFB41, Stride: 1}, + {Lo: 0xFB43, Hi: 0xFB44, Stride: 1}, + {Lo: 0xFB46, Hi: 0xFB4F, Stride: 1}, + }, +} + +var unicodeAliasWord_Break_Katakana = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0x3031, Hi: 0x3035, Stride: 1}, + {Lo: 0x309B, Hi: 0x309C, Stride: 1}, + {Lo: 0x30A0, Hi: 0x30FA, Stride: 1}, + {Lo: 0x30FC, Hi: 0x30FF, Stride: 1}, + {Lo: 0x31F0, Hi: 0x31FF, Stride: 1}, + {Lo: 0x32D0, Hi: 0x32FE, Stride: 1}, + {Lo: 0x3300, Hi: 0x3357, Stride: 1}, + {Lo: 0xFF66, Hi: 0xFF9D, Stride: 1}, + }, + R32: []unicode.Range32{ + {Lo: 0x1AFF0, Hi: 0x1AFF3, Stride: 1}, + {Lo: 0x1AFF5, Hi: 0x1AFFB, Stride: 1}, + {Lo: 0x1AFFD, Hi: 0x1AFFE, Stride: 1}, + {Lo: 0x1B000, Hi: 0x1B000, Stride: 1}, + {Lo: 0x1B120, Hi: 0x1B122, Stride: 1}, + {Lo: 0x1B155, Hi: 0x1B155, Stride: 1}, + {Lo: 0x1B164, Hi: 0x1B167, Stride: 1}, + }, +} + +var unicodeAliasWord_Break_LF = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0xA, Hi: 0xA, Stride: 1}, + }, +} + +var unicodeAliasWord_Break_MidLetter = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0x3A, Hi: 0x3A, Stride: 1}, + {Lo: 0xB7, Hi: 0xB7, Stride: 1}, + {Lo: 0x387, Hi: 0x387, Stride: 1}, + {Lo: 0x55F, Hi: 0x55F, Stride: 1}, + {Lo: 0x5F4, Hi: 0x5F4, Stride: 1}, + {Lo: 0x2027, Hi: 0x2027, Stride: 1}, + {Lo: 0xFE13, Hi: 0xFE13, Stride: 1}, + {Lo: 0xFE55, Hi: 0xFE55, Stride: 1}, + {Lo: 0xFF1A, Hi: 0xFF1A, Stride: 1}, + }, +} + +var unicodeAliasWord_Break_MidNum = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0x2C, Hi: 0x2C, Stride: 1}, + {Lo: 0x3B, Hi: 0x3B, Stride: 1}, + {Lo: 0x37E, Hi: 0x37E, Stride: 1}, + {Lo: 0x589, Hi: 0x589, Stride: 1}, + {Lo: 0x60C, Hi: 0x60D, Stride: 1}, + {Lo: 0x66C, Hi: 0x66C, Stride: 1}, + {Lo: 0x7F8, Hi: 0x7F8, Stride: 1}, + {Lo: 0x2044, Hi: 0x2044, Stride: 1}, + {Lo: 0xFE50, Hi: 0xFE50, Stride: 1}, + {Lo: 0xFE54, Hi: 0xFE54, Stride: 1}, + {Lo: 0xFF0C, Hi: 0xFF0C, Stride: 1}, + {Lo: 0xFF1B, Hi: 0xFF1B, Stride: 1}, + }, +} + +var unicodeAliasWord_Break_MidNumLet = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0x2E, Hi: 0x2E, Stride: 1}, + {Lo: 0x2018, Hi: 0x2019, Stride: 1}, + {Lo: 0x2024, Hi: 0x2024, Stride: 1}, + {Lo: 0xFE52, Hi: 0xFE52, Stride: 1}, + {Lo: 0xFF07, Hi: 0xFF07, Stride: 1}, + {Lo: 0xFF0E, Hi: 0xFF0E, Stride: 1}, + }, +} + +var unicodeAliasWord_Break_Newline = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0xB, Hi: 0xC, Stride: 1}, + {Lo: 0x85, Hi: 0x85, Stride: 1}, + {Lo: 0x2028, Hi: 0x2029, Stride: 1}, + }, +} + +var unicodeAliasWord_Break_Numeric = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0x30, Hi: 0x39, Stride: 1}, + {Lo: 0x600, Hi: 0x605, Stride: 1}, + {Lo: 0x660, Hi: 0x669, Stride: 1}, + {Lo: 0x66B, Hi: 0x66B, Stride: 1}, + {Lo: 0x6DD, Hi: 0x6DD, Stride: 1}, + {Lo: 0x6F0, Hi: 0x6F9, Stride: 1}, + {Lo: 0x7C0, Hi: 0x7C9, Stride: 1}, + {Lo: 0x890, Hi: 0x891, Stride: 1}, + {Lo: 0x8E2, Hi: 0x8E2, Stride: 1}, + {Lo: 0x966, Hi: 0x96F, Stride: 1}, + {Lo: 0x9E6, Hi: 0x9EF, Stride: 1}, + {Lo: 0xA66, Hi: 0xA6F, Stride: 1}, + {Lo: 0xAE6, Hi: 0xAEF, Stride: 1}, + {Lo: 0xB66, Hi: 0xB6F, Stride: 1}, + {Lo: 0xBE6, Hi: 0xBEF, Stride: 1}, + {Lo: 0xC66, Hi: 0xC6F, Stride: 1}, + {Lo: 0xCE6, Hi: 0xCEF, Stride: 1}, + {Lo: 0xD66, Hi: 0xD6F, Stride: 1}, + {Lo: 0xDE6, Hi: 0xDEF, Stride: 1}, + {Lo: 0xE50, Hi: 0xE59, Stride: 1}, + {Lo: 0xED0, Hi: 0xED9, Stride: 1}, + {Lo: 0xF20, Hi: 0xF29, Stride: 1}, + {Lo: 0x1040, Hi: 0x1049, Stride: 1}, + {Lo: 0x1090, Hi: 0x1099, Stride: 1}, + {Lo: 0x17E0, Hi: 0x17E9, Stride: 1}, + {Lo: 0x1810, Hi: 0x1819, Stride: 1}, + {Lo: 0x1946, Hi: 0x194F, Stride: 1}, + {Lo: 0x19D0, Hi: 0x19DA, Stride: 1}, + {Lo: 0x1A80, Hi: 0x1A89, Stride: 1}, + {Lo: 0x1A90, Hi: 0x1A99, Stride: 1}, + {Lo: 0x1B50, Hi: 0x1B59, Stride: 1}, + {Lo: 0x1BB0, Hi: 0x1BB9, Stride: 1}, + {Lo: 0x1C40, Hi: 0x1C49, Stride: 1}, + {Lo: 0x1C50, Hi: 0x1C59, Stride: 1}, + {Lo: 0xA620, Hi: 0xA629, Stride: 1}, + {Lo: 0xA8D0, Hi: 0xA8D9, Stride: 1}, + {Lo: 0xA900, Hi: 0xA909, Stride: 1}, + {Lo: 0xA9D0, Hi: 0xA9D9, Stride: 1}, + {Lo: 0xA9F0, Hi: 0xA9F9, Stride: 1}, + {Lo: 0xAA50, Hi: 0xAA59, Stride: 1}, + {Lo: 0xABF0, Hi: 0xABF9, Stride: 1}, + {Lo: 0xFF10, Hi: 0xFF19, Stride: 1}, + }, + R32: []unicode.Range32{ + {Lo: 0x104A0, Hi: 0x104A9, Stride: 1}, + {Lo: 0x10D30, Hi: 0x10D39, Stride: 1}, + {Lo: 0x10D40, Hi: 0x10D49, Stride: 1}, + {Lo: 0x11066, Hi: 0x1106F, Stride: 1}, + {Lo: 0x110BD, Hi: 0x110BD, Stride: 1}, + {Lo: 0x110CD, Hi: 0x110CD, Stride: 1}, + {Lo: 0x110F0, Hi: 0x110F9, Stride: 1}, + {Lo: 0x11136, Hi: 0x1113F, Stride: 1}, + {Lo: 0x111D0, Hi: 0x111D9, Stride: 1}, + {Lo: 0x112F0, Hi: 0x112F9, Stride: 1}, + {Lo: 0x11450, Hi: 0x11459, Stride: 1}, + {Lo: 0x114D0, Hi: 0x114D9, Stride: 1}, + {Lo: 0x11650, Hi: 0x11659, Stride: 1}, + {Lo: 0x116C0, Hi: 0x116C9, Stride: 1}, + {Lo: 0x116D0, Hi: 0x116E3, Stride: 1}, + {Lo: 0x11730, Hi: 0x11739, Stride: 1}, + {Lo: 0x118E0, Hi: 0x118E9, Stride: 1}, + {Lo: 0x11950, Hi: 0x11959, Stride: 1}, + {Lo: 0x11BF0, Hi: 0x11BF9, Stride: 1}, + {Lo: 0x11C50, Hi: 0x11C59, Stride: 1}, + {Lo: 0x11D50, Hi: 0x11D59, Stride: 1}, + {Lo: 0x11DA0, Hi: 0x11DA9, Stride: 1}, + {Lo: 0x11DE0, Hi: 0x11DE9, Stride: 1}, + {Lo: 0x11F50, Hi: 0x11F59, Stride: 1}, + {Lo: 0x16130, Hi: 0x16139, Stride: 1}, + {Lo: 0x16A60, Hi: 0x16A69, Stride: 1}, + {Lo: 0x16AC0, Hi: 0x16AC9, Stride: 1}, + {Lo: 0x16B50, Hi: 0x16B59, Stride: 1}, + {Lo: 0x16D70, Hi: 0x16D79, Stride: 1}, + {Lo: 0x1CCF0, Hi: 0x1CCF9, Stride: 1}, + {Lo: 0x1D7CE, Hi: 0x1D7FF, Stride: 1}, + {Lo: 0x1E140, Hi: 0x1E149, Stride: 1}, + {Lo: 0x1E2F0, Hi: 0x1E2F9, Stride: 1}, + {Lo: 0x1E4F0, Hi: 0x1E4F9, Stride: 1}, + {Lo: 0x1E5F1, Hi: 0x1E5FA, Stride: 1}, + {Lo: 0x1E950, Hi: 0x1E959, Stride: 1}, + {Lo: 0x1FBF0, Hi: 0x1FBF9, Stride: 1}, + }, +} + +var unicodeAliasWord_Break_Regional_Indicator = &unicode.RangeTable{ + R32: []unicode.Range32{ + {Lo: 0x1F1E6, Hi: 0x1F1FF, Stride: 1}, + }, +} + +var unicodeAliasWord_Break_Single_Quote = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0x27, Hi: 0x27, Stride: 1}, + }, +} + +var unicodeAliasWord_Break_WSegSpace = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0x20, Hi: 0x20, Stride: 1}, + {Lo: 0x1680, Hi: 0x1680, Stride: 1}, + {Lo: 0x2000, Hi: 0x2006, Stride: 1}, + {Lo: 0x2008, Hi: 0x200A, Stride: 1}, + {Lo: 0x205F, Hi: 0x205F, Stride: 1}, + {Lo: 0x3000, Hi: 0x3000, Stride: 1}, + }, +} + +var unicodeAliasWord_Break_ZWJ = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0x200D, Hi: 0x200D, Stride: 1}, + }, +} diff --git a/vendor/github.com/dlclark/regexp2/syntax/writer.go b/vendor/github.com/dlclark/regexp2/v2/syntax/writer.go similarity index 63% rename from vendor/github.com/dlclark/regexp2/syntax/writer.go rename to vendor/github.com/dlclark/regexp2/v2/syntax/writer.go index a5aa11ca0..818b4b56c 100644 --- a/vendor/github.com/dlclark/regexp2/syntax/writer.go +++ b/vendor/github.com/dlclark/regexp2/v2/syntax/writer.go @@ -4,7 +4,6 @@ import ( "bytes" "fmt" "math" - "os" ) func Write(tree *RegexTree) (*Code, error) { @@ -17,11 +16,6 @@ func Write(tree *RegexTree) (*Code, error) { code, err := w.codeFromTree(tree) - if tree.options&Debug > 0 && code != nil { - os.Stdout.WriteString(code.Dump()) - os.Stdout.WriteString("\n") - } - return code, err } @@ -41,8 +35,8 @@ type writer struct { } const ( - beforeChild nodeType = 64 - afterChild = 128 + BeforeChild NodeType = 64 + AfterChild NodeType = 128 //MaxPrefixSize is the largest number of runes we'll use for a BoyerMoyer prefix MaxPrefixSize = 50 ) @@ -58,20 +52,20 @@ const ( // to just generate the code and grow the array as we go. func (w *writer) codeFromTree(tree *RegexTree) (*Code, error) { var ( - curNode *regexNode + curNode *RegexNode curChild int capsize int ) // construct sparse capnum mapping if some numbers are unused - if tree.capnumlist == nil || tree.captop == len(tree.capnumlist) { - capsize = tree.captop + if tree.Capnumlist == nil || tree.Captop == len(tree.Capnumlist) { + capsize = tree.Captop w.caps = nil } else { - capsize = len(tree.capnumlist) - w.caps = tree.caps - for i := 0; i < len(tree.capnumlist); i++ { - w.caps[tree.capnumlist[i]] = i + capsize = len(tree.Capnumlist) + w.caps = tree.Caps + for i := 0; i < len(tree.Capnumlist); i++ { + w.caps[tree.Capnumlist[i]] = i } } @@ -82,18 +76,22 @@ func (w *writer) codeFromTree(tree *RegexTree) (*Code, error) { w.emitted = make([]int, w.count) } - curNode = tree.root + curNode = tree.Root curChild = 0 w.emit1(Lazybranch, 0) for { - if len(curNode.children) == 0 { - w.emitFragment(curNode.t, curNode, 0) - } else if curChild < len(curNode.children) { - w.emitFragment(curNode.t|beforeChild, curNode, curChild) + if len(curNode.Children) == 0 { + if err := w.emitFragment(curNode.T, curNode, 0); err != nil { + return nil, err + } + } else if curChild < len(curNode.Children) { + if err := w.emitFragment(curNode.T|BeforeChild, curNode, curChild); err != nil { + return nil, err + } - curNode = curNode.children[curChild] + curNode = curNode.Children[curChild] w.pushInt(curChild) curChild = 0 @@ -105,9 +103,11 @@ func (w *writer) codeFromTree(tree *RegexTree) (*Code, error) { } curChild = w.popInt() - curNode = curNode.next + curNode = curNode.Parent - w.emitFragment(curNode.t|afterChild, curNode, curChild) + if err := w.emitFragment(curNode.T|AfterChild, curNode, curChild); err != nil { + return nil, err + } curChild++ } @@ -123,7 +123,7 @@ func (w *writer) codeFromTree(tree *RegexTree) (*Code, error) { fcPrefix := getFirstCharsPrefix(tree) prefix := getPrefix(tree) - rtl := (tree.options & RightToLeft) != 0 + rtl := (tree.Options & RightToLeft) != 0 var bmPrefix *BmPrefix //TODO: benchmark string prefixes @@ -138,47 +138,46 @@ func (w *writer) codeFromTree(tree *RegexTree) (*Code, error) { } return &Code{ - Codes: w.emitted, - Strings: w.stringtable, - Sets: w.settable, - TrackCount: w.trackcount, - Caps: w.caps, - Capsize: capsize, - FcPrefix: fcPrefix, - BmPrefix: bmPrefix, - Anchors: getAnchors(tree), - RightToLeft: rtl, + Codes: w.emitted, + Strings: w.stringtable, + Sets: w.settable, + TrackCount: w.trackcount, + Caps: w.caps, + Capsize: capsize, + FcPrefix: fcPrefix, + BmPrefix: bmPrefix, + Anchors: getAnchors(tree), + RightToLeft: rtl, + FindOptimizations: tree.FindOptimizations, }, nil } // The main RegexCode generator. It does a depth-first walk // through the tree and calls EmitFragment to emits code before // and after each child of an interior node, and at each leaf. -func (w *writer) emitFragment(nodetype nodeType, node *regexNode, curIndex int) error { +func (w *writer) emitFragment(nodetype NodeType, node *RegexNode, curIndex int) error { bits := InstOp(0) - if nodetype <= ntRef { - if (node.options & RightToLeft) != 0 { - bits |= Rtl - } - if (node.options & IgnoreCase) != 0 { - bits |= Ci - } + if (node.Options & RightToLeft) != 0 { + bits |= Rtl + } + if (node.Options & IgnoreCase) != 0 { + bits |= Ci } - ntBits := nodeType(bits) + + ntBits := NodeType(bits) switch nodetype { - case ntConcatenate | beforeChild, ntConcatenate | afterChild, ntEmpty: - break + case NtConcatenate | BeforeChild, NtConcatenate | AfterChild, NtEmpty: - case ntAlternate | beforeChild: - if curIndex < len(node.children)-1 { + case NtAlternate | BeforeChild: + if curIndex < len(node.Children)-1 { w.pushInt(w.curPos()) w.emit1(Lazybranch, 0) } - case ntAlternate | afterChild: - if curIndex < len(node.children)-1 { + case NtAlternate | AfterChild: + if curIndex < len(node.Children)-1 { lbPos := w.popInt() w.pushInt(w.curPos()) w.emit1(Goto, 0) @@ -188,32 +187,32 @@ func (w *writer) emitFragment(nodetype nodeType, node *regexNode, curIndex int) w.patchJump(w.popInt(), w.curPos()) } } - break - case ntTestref | beforeChild: + case NtBackRefCond | BeforeChild: if curIndex == 0 { w.emit(Setjump) w.pushInt(w.curPos()) w.emit1(Lazybranch, 0) - w.emit1(Testref, w.mapCapnum(node.m)) + w.emit1(Testref, w.mapCapnum(node.M)) w.emit(Forejump) } - case ntTestref | afterChild: - if curIndex == 0 { + case NtBackRefCond | AfterChild: + switch curIndex { + case 0: branchpos := w.popInt() w.pushInt(w.curPos()) w.emit1(Goto, 0) w.patchJump(branchpos, w.curPos()) w.emit(Forejump) - if len(node.children) <= 1 { + if len(node.Children) <= 1 { w.patchJump(w.popInt(), w.curPos()) } - } else if curIndex == 1 { + case 1: w.patchJump(w.popInt(), w.curPos()) } - case ntTestgroup | beforeChild: + case NtExprCond | BeforeChild: if curIndex == 0 { w.emit(Setjump) w.emit(Setmark) @@ -221,143 +220,144 @@ func (w *writer) emitFragment(nodetype nodeType, node *regexNode, curIndex int) w.emit1(Lazybranch, 0) } - case ntTestgroup | afterChild: - if curIndex == 0 { + case NtExprCond | AfterChild: + switch curIndex { + case 0: w.emit(Getmark) w.emit(Forejump) - } else if curIndex == 1 { - Branchpos := w.popInt() + case 1: + branchpos := w.popInt() w.pushInt(w.curPos()) w.emit1(Goto, 0) - w.patchJump(Branchpos, w.curPos()) + w.patchJump(branchpos, w.curPos()) w.emit(Getmark) w.emit(Forejump) - if len(node.children) <= 2 { + if len(node.Children) <= 2 { w.patchJump(w.popInt(), w.curPos()) } - } else if curIndex == 2 { + case 2: w.patchJump(w.popInt(), w.curPos()) } - case ntLoop | beforeChild, ntLazyloop | beforeChild: + case NtLoop | BeforeChild, NtLazyloop | BeforeChild: - if node.n < math.MaxInt32 || node.m > 1 { - if node.m == 0 { + if node.N < math.MaxInt32 || node.M > 1 { + if node.M == 0 { w.emit1(Nullcount, 0) } else { - w.emit1(Setcount, 1-node.m) + w.emit1(Setcount, 1-node.M) } - } else if node.m == 0 { + } else if node.M == 0 { w.emit(Nullmark) } else { w.emit(Setmark) } - if node.m == 0 { + if node.M == 0 { w.pushInt(w.curPos()) w.emit1(Goto, 0) } w.pushInt(w.curPos()) - case ntLoop | afterChild, ntLazyloop | afterChild: + case NtLoop | AfterChild, NtLazyloop | AfterChild: startJumpPos := w.curPos() - lazy := (nodetype - (ntLoop | afterChild)) + lazy := InstOp(nodetype - (NtLoop | AfterChild)) - if node.n < math.MaxInt32 || node.m > 1 { - if node.n == math.MaxInt32 { - w.emit2(InstOp(Branchcount+lazy), w.popInt(), math.MaxInt32) + if node.N < math.MaxInt32 || node.M > 1 { + if node.N == math.MaxInt32 { + w.emit2(Branchcount+lazy, w.popInt(), math.MaxInt32) } else { - w.emit2(InstOp(Branchcount+lazy), w.popInt(), node.n-node.m) + w.emit2(Branchcount+lazy, w.popInt(), node.N-node.M) } } else { - w.emit1(InstOp(Branchmark+lazy), w.popInt()) + w.emit1(Branchmark+lazy, w.popInt()) } - if node.m == 0 { + if node.M == 0 { w.patchJump(w.popInt(), startJumpPos) } - case ntGroup | beforeChild, ntGroup | afterChild: + case NtGroup | BeforeChild, NtGroup | AfterChild: - case ntCapture | beforeChild: + case NtCapture | BeforeChild: w.emit(Setmark) - case ntCapture | afterChild: - w.emit2(Capturemark, w.mapCapnum(node.m), w.mapCapnum(node.n)) + case NtCapture | AfterChild: + w.emit2(Capturemark, w.mapCapnum(node.M), w.mapCapnum(node.N)) - case ntRequire | beforeChild: + case NtPosLook | BeforeChild: // NOTE: the following line causes lookahead/lookbehind to be // NON-BACKTRACKING. It can be commented out with (*) w.emit(Setjump) w.emit(Setmark) - case ntRequire | afterChild: + case NtPosLook | AfterChild: w.emit(Getmark) // NOTE: the following line causes lookahead/lookbehind to be // NON-BACKTRACKING. It can be commented out with (*) w.emit(Forejump) - case ntPrevent | beforeChild: + case NtNegLook | BeforeChild: w.emit(Setjump) w.pushInt(w.curPos()) w.emit1(Lazybranch, 0) - case ntPrevent | afterChild: + case NtNegLook | AfterChild: w.emit(Backjump) w.patchJump(w.popInt(), w.curPos()) w.emit(Forejump) - case ntGreedy | beforeChild: + case NtAtomic | BeforeChild: w.emit(Setjump) - case ntGreedy | afterChild: + case NtAtomic | AfterChild: w.emit(Forejump) - case ntOne, ntNotone: - w.emit1(InstOp(node.t|ntBits), int(node.ch)) + case NtOne, NtNotone: + w.emit1(InstOp(node.T|ntBits), int(node.Ch)) - case ntNotoneloop, ntNotonelazy, ntOneloop, ntOnelazy: - if node.m > 0 { - if node.t == ntOneloop || node.t == ntOnelazy { - w.emit2(Onerep|bits, int(node.ch), node.m) + case NtNotoneloop, NtNotoneloopatomic, NtNotonelazy, NtOneloop, NtOneloopatomic, NtOnelazy: + if node.M > 0 { + if node.T == NtOneloop || node.T == NtOnelazy || node.T == NtOneloopatomic { + w.emit2(Onerep|bits, int(node.Ch), node.M) } else { - w.emit2(Notonerep|bits, int(node.ch), node.m) + w.emit2(Notonerep|bits, int(node.Ch), node.M) } } - if node.n > node.m { - if node.n == math.MaxInt32 { - w.emit2(InstOp(node.t|ntBits), int(node.ch), math.MaxInt32) + if node.N > node.M { + if node.N == math.MaxInt32 { + w.emit2(InstOp(node.T|ntBits), int(node.Ch), math.MaxInt32) } else { - w.emit2(InstOp(node.t|ntBits), int(node.ch), node.n-node.m) + w.emit2(InstOp(node.T|ntBits), int(node.Ch), node.N-node.M) } } - case ntSetloop, ntSetlazy: - if node.m > 0 { - w.emit2(Setrep|bits, w.setCode(node.set), node.m) + case NtSetloop, NtSetlazy, NtSetloopatomic: + if node.M > 0 { + w.emit2(Setrep|bits, w.setCode(node.Set), node.M) } - if node.n > node.m { - if node.n == math.MaxInt32 { - w.emit2(InstOp(node.t|ntBits), w.setCode(node.set), math.MaxInt32) + if node.N > node.M { + if node.N == math.MaxInt32 { + w.emit2(InstOp(node.T|ntBits), w.setCode(node.Set), math.MaxInt32) } else { - w.emit2(InstOp(node.t|ntBits), w.setCode(node.set), node.n-node.m) + w.emit2(InstOp(node.T|ntBits), w.setCode(node.Set), node.N-node.M) } } - case ntMulti: - w.emit1(InstOp(node.t|ntBits), w.stringCode(node.str)) + case NtMulti: + w.emit1(InstOp(node.T|ntBits), w.stringCode(node.Str)) - case ntSet: - w.emit1(InstOp(node.t|ntBits), w.setCode(node.set)) + case NtSet: + w.emit1(InstOp(node.T|ntBits), w.setCode(node.Set)) - case ntRef: - w.emit1(InstOp(node.t|ntBits), w.mapCapnum(node.m)) + case NtRef: + w.emit1(InstOp(node.T|ntBits), w.mapCapnum(node.M)) - case ntNothing, ntBol, ntEol, ntBoundary, ntNonboundary, ntECMABoundary, ntNonECMABoundary, ntBeginning, ntStart, ntEndZ, ntEnd: - w.emit(InstOp(node.t)) + case NtNothing, NtBol, NtEol, NtBoundary, NtNonboundary, NtECMABoundary, NtNonECMABoundary, NtBeginning, NtStart, NtEndZ, NtEnd, NtUpdateBumpalong: + w.emit(InstOp(node.T)) default: return fmt.Errorf("unexpected opcode in regular expression generation: %v", nodetype) diff --git a/vendor/github.com/grafana/sobek/builtin_array.go b/vendor/github.com/grafana/sobek/builtin_array.go index ca66cc4fc..4e577f576 100644 --- a/vendor/github.com/grafana/sobek/builtin_array.go +++ b/vendor/github.com/grafana/sobek/builtin_array.go @@ -58,20 +58,6 @@ func arraySpeciesCreate(obj *Object, size int64) *Object { return obj.runtime.newArrayLength(size) } -func max(a, b int64) int64 { - if a > b { - return a - } - return b -} - -func min(a, b int64) int64 { - if a < b { - return a - } - return b -} - func relToIdx(rel, l int64) int64 { if rel >= 0 { return min(rel, l) @@ -979,7 +965,7 @@ func arrayproto_reverse_generic_step(o *Object, lower, upper int64) { } else if !lowerExists && upperExists { o.self.setOwnIdx(lowerP, upperValue, true) o.self.deleteIdx(upperP, true) - } else if lowerExists && !upperExists { + } else if lowerExists { o.self.deleteIdx(lowerP, true) o.self.setOwnIdx(upperP, lowerValue, true) } @@ -1276,7 +1262,7 @@ func (r *Runtime) arrayproto_with(call FunctionCall) Value { actualIndex = length + relativeIndex } if actualIndex >= length || actualIndex < 0 { - panic(r.newError(r.getRangeError(), "Invalid index %s", call.Argument(0).String())) + panic(r.newErrorf(r.getRangeError(), "Invalid index %s", call.Argument(0).String())) } if src := r.checkStdArrayObj(o); src != nil { diff --git a/vendor/github.com/grafana/sobek/builtin_json.go b/vendor/github.com/grafana/sobek/builtin_json.go index e3fbbd7b4..2b2b7d02f 100644 --- a/vendor/github.com/grafana/sobek/builtin_json.go +++ b/vendor/github.com/grafana/sobek/builtin_json.go @@ -22,14 +22,14 @@ func (r *Runtime) builtinJSON_parse(call FunctionCall) Value { value, err := r.builtinJSON_decodeValue(d) if errors.Is(err, io.EOF) { - panic(r.newError(r.getSyntaxError(), "Unexpected end of JSON input (%v)", err.Error())) + panic(r.newErrorf(r.getSyntaxError(), "Unexpected end of JSON input (%v)", err.Error())) } if err != nil { panic(r.newError(r.getSyntaxError(), err.Error())) } if tok, err := d.Token(); err != io.EOF { - panic(r.newError(r.getSyntaxError(), "Unexpected token at the end: %v", tok)) + panic(r.newErrorf(r.getSyntaxError(), "Unexpected token at the end: %v", tok)) } var reviver func(FunctionCall) Value diff --git a/vendor/github.com/grafana/sobek/builtin_regexp.go b/vendor/github.com/grafana/sobek/builtin_regexp.go index e8686de07..552038b2b 100644 --- a/vendor/github.com/grafana/sobek/builtin_regexp.go +++ b/vendor/github.com/grafana/sobek/builtin_regexp.go @@ -773,13 +773,13 @@ func (r *Runtime) regexpproto_stdMatcher(call FunctionCall) Value { } if rx.pattern.global { rx.setOwnStr("lastIndex", intToValue(0), true) - res := rx.pattern.findAllSubmatchIndex(s, 0, -1, rx.pattern.sticky) - if len(res) == 0 { + results := rx.pattern.findAllSubmatchIndex(s, 0, -1, rx.pattern.sticky) + if len(results) == 0 { return _null } - a := make([]Value, 0, len(res)) - for _, result := range res { - a = append(a, s.Substring(result[0], result[1])) + a := make([]Value, 0, len(results)) + for _, result := range results { + a = append(a, s.Substring(result.indexes[0], result.indexes[1])) } return r.newArrayValues(a) } else { @@ -905,7 +905,7 @@ func (r *Runtime) regexpproto_stdSearch(call FunctionCall) Value { if !match { return intToValue(-1) } - return intToValue(int64(result[0])) + return intToValue(int64(result.indexes[0])) } func (r *Runtime) regexpproto_stdSplitterGeneric(splitter *Object, s String, limit Value, unicodeMatching bool) Value { @@ -1039,43 +1039,43 @@ func (r *Runtime) regexpproto_stdSplitter(call FunctionCall) Value { lastIndex := 0 found := 0 - result := pattern.findAllSubmatchIndex(s, 0, -1, false) + results := pattern.findAllSubmatchIndex(s, 0, -1, false) if targetLength == 0 { - if result == nil { + if len(results) == 0 { valueArray = append(valueArray, s) } goto RETURN } - for _, match := range result { - if match[0] == match[1] { + for _, result := range results { + if result.indexes[0] == result.indexes[1] { // FIXME Ugh, this is a hack - if match[0] == 0 || match[0] == targetLength { + if result.indexes[0] == 0 || result.indexes[0] == targetLength { continue } } - if lastIndex != match[0] { - valueArray = append(valueArray, s.Substring(lastIndex, match[0])) + if lastIndex != result.indexes[0] { + valueArray = append(valueArray, s.Substring(lastIndex, result.indexes[0])) found++ - } else if lastIndex == match[0] { + } else if lastIndex == result.indexes[0] { if lastIndex != -1 { valueArray = append(valueArray, stringEmpty) found++ } } - lastIndex = match[1] + lastIndex = result.indexes[1] if found == limit { goto RETURN } - captureCount := len(match) / 2 + captureCount := len(result.indexes) / 2 for index := 1; index < captureCount; index++ { offset := index * 2 var value Value - if match[offset] != -1 { - value = s.Substring(match[offset], match[offset+1]) + if result.indexes[offset] != -1 { + value = s.Substring(result.indexes[offset], result.indexes[offset+1]) } else { value = _undefined } @@ -1139,6 +1139,9 @@ func (r *Runtime) regexpproto_stdReplacerGeneric(rxObj *Object, s, replaceStr St var replacement String if rcall != nil { captures = append(captures, intToValue(int64(position)), s) + if namedCaptures := nilSafe(obj.self.getStr("groups", nil)); namedCaptures != _undefined { + captures = append(captures, namedCaptures) + } replacement = rcall(FunctionCall{ This: _undefined, Arguments: captures, @@ -1149,6 +1152,10 @@ func (r *Runtime) regexpproto_stdReplacerGeneric(rxObj *Object, s, replaceStr St nextSourcePosition = position + matchLength } } else { + var namedCaptures *Object + if c := nilSafe(obj.self.getStr("groups", nil)); c != _undefined { + namedCaptures = c.ToObject(r) + } if position >= nextSourcePosition { resultBuf.WriteString(s.Substring(nextSourcePosition, position)) writeSubstitution(s, position, len(captures), func(idx int) String { @@ -1157,6 +1164,15 @@ func (r *Runtime) regexpproto_stdReplacerGeneric(rxObj *Object, s, replaceStr St return capture.toString() } return stringEmpty + }, func(ref String) String { + if namedCaptures != nil { + capture := nilSafe(namedCaptures.self.getStr(ref.string(), nil)) + if capture != _undefined { + return capture.toString() + } + return stringEmpty + } + return nil }, replaceStr, &resultBuf) nextSourcePosition = position + matchLength } @@ -1168,7 +1184,7 @@ func (r *Runtime) regexpproto_stdReplacerGeneric(rxObj *Object, s, replaceStr St return resultBuf.String() } -func writeSubstitution(s String, position int, numCaptures int, getCapture func(int) String, replaceStr String, buf *StringBuilder) { +func writeSubstitution(s String, position int, numCaptures int, getCapture func(int) String, getNamedCapture func(String) String, replaceStr String, buf *StringBuilder) { l := s.Length() rl := replaceStr.Length() matched := getCapture(0) @@ -1189,24 +1205,45 @@ func writeSubstitution(s String, position int, numCaptures int, getCapture func( } case '&': buf.WriteString(matched) + case '<': + var ref String + j := i + 2 + for ; j < rl; j++ { + ch := replaceStr.CharAt(j) + if ch == '>' { + ref = replaceStr.Substring(i+2, j) + break + } + } + if ref != nil { + capture := getNamedCapture(ref) + if capture != nil { + buf.WriteString(capture) + i = j + continue + } + } + buf.WriteRune('$') + buf.WriteRune('<') default: - matchNumber := 0 + index := 0 j := i + 1 - for j < rl { + lim := min(j+2, rl) + + for ; j < lim; j++ { ch := replaceStr.CharAt(j) if ch >= '0' && ch <= '9' { - m := matchNumber*10 + int(ch-'0') + m := index*10 + int(ch-'0') if m >= numCaptures { break } - matchNumber = m - j++ + index = m } else { break } } - if matchNumber > 0 { - buf.WriteString(getCapture(matchNumber)) + if index > 0 { + buf.WriteString(getCapture(index)) i = j - 1 continue } else { @@ -1242,12 +1279,11 @@ func (r *Runtime) regexpproto_stdReplacer(call FunctionCall) Value { if rx.pattern.global || rx.pattern.sticky { var newLastIndex int64 if !rx.pattern.global && len(found) > 0 { - newLastIndex = int64(found[len(found)-1][1]) + newLastIndex = int64(found[len(found)-1].indexes[1]) } rx.setOwnStr("lastIndex", intToValue(newLastIndex), true) } - - return stringReplace(s, found, replaceStr, rcall) + return r.stringReplace(s, found, replaceStr, rcall) } func (r *Runtime) regExpStringIteratorProto_next(call FunctionCall) Value { diff --git a/vendor/github.com/grafana/sobek/builtin_string.go b/vendor/github.com/grafana/sobek/builtin_string.go index 17f15cc38..604de4505 100644 --- a/vendor/github.com/grafana/sobek/builtin_string.go +++ b/vendor/github.com/grafana/sobek/builtin_string.go @@ -136,11 +136,11 @@ func (r *Runtime) string_fromcodepoint(call FunctionCall) Value { var c rune if numInt, ok := num.(valueInt); ok { if numInt < 0 || numInt > utf8.MaxRune { - panic(r.newError(r.getRangeError(), "Invalid code point %d", numInt)) + panic(r.newErrorf(r.getRangeError(), "Invalid code point %d", numInt)) } c = rune(numInt) } else { - panic(r.newError(r.getRangeError(), "Invalid code point %s", num)) + panic(r.newErrorf(r.getRangeError(), "Invalid code point %s", num)) } sb.WriteRune(c) } @@ -593,7 +593,7 @@ func getReplaceValue(replaceValue Value) (str String, rcall func(FunctionCall) V return } -func stringReplace(s String, found [][]int, newstring String, rcall func(FunctionCall) Value) Value { +func (r *Runtime) stringReplace(s String, found []regexpResult, newstring String, rcall func(FunctionCall) Value) Value { if len(found) == 0 { return s } @@ -606,48 +606,69 @@ func stringReplace(s String, found [][]int, newstring String, rcall func(Functio lengthS := s.Length() if rcall != nil { for _, item := range found { - if item[0] != lastIndex { - buf.WriteSubstring(s, lastIndex, item[0]) + if item.indexes[0] != lastIndex { + buf.WriteSubstring(s, lastIndex, item.indexes[0]) } - matchCount := len(item) / 2 - argumentList := make([]Value, matchCount+2) + matchCount := len(item.indexes) / 2 + argumentList := make([]Value, matchCount+2, matchCount+3) for index := 0; index < matchCount; index++ { offset := 2 * index - if item[offset] != -1 { + if item.indexes[offset] != -1 { if u == nil { - argumentList[index] = a[item[offset]:item[offset+1]] + argumentList[index] = a[item.indexes[offset]:item.indexes[offset+1]] } else { - argumentList[index] = u.Substring(item[offset], item[offset+1]) + argumentList[index] = u.Substring(item.indexes[offset], item.indexes[offset+1]) } } else { argumentList[index] = _undefined } } - argumentList[matchCount] = valueInt(item[0]) + argumentList[matchCount] = intToValue(int64(item.indexes[0])) argumentList[matchCount+1] = s + groups := r.createRegexpGroupsObj(argumentList[:matchCount], item.groups) + if groups != nil { + argumentList = append(argumentList, groups) + } replacement := rcall(FunctionCall{ This: _undefined, Arguments: argumentList, }).toString() buf.WriteString(replacement) - lastIndex = item[1] + lastIndex = item.indexes[1] } } else { for _, item := range found { - if item[0] != lastIndex { - buf.WriteString(s.Substring(lastIndex, item[0])) + if item.indexes[0] != lastIndex { + buf.WriteString(s.Substring(lastIndex, item.indexes[0])) } - matchCount := len(item) / 2 - writeSubstitution(s, item[0], matchCount, func(idx int) String { - if item[idx*2] != -1 { + matchCount := len(item.indexes) / 2 + var namedGroups map[unistring.String]int + writeSubstitution(s, item.indexes[0], matchCount, func(idx int) String { + if item.indexes[idx*2] != -1 { if u == nil { - return a[item[idx*2]:item[idx*2+1]] + return a[item.indexes[idx*2]:item.indexes[idx*2+1]] + } + return u.Substring(item.indexes[idx*2], item.indexes[idx*2+1]) + } + return stringEmpty + }, func(ref String) String { + if namedGroups == nil { + namedGroups = createRegexpGroupsMap(item) + } + if len(namedGroups) == 0 { + return nil + } + if idx, exists := namedGroups[ref.string()]; exists { + if item.indexes[idx] != -1 { + if u == nil { + return a[item.indexes[idx]:item.indexes[idx+1]] + } + return u.Substring(item.indexes[idx], item.indexes[idx+1]) } - return u.Substring(item[idx*2], item[idx*2+1]) } return stringEmpty }, newstring, &buf) - lastIndex = item[1] + lastIndex = item.indexes[1] } } @@ -672,15 +693,15 @@ func (r *Runtime) stringproto_replace(call FunctionCall) Value { } s := call.This.toString() - var found [][]int + var found []regexpResult searchStr := searchValue.toString() pos := s.index(searchStr, 0) if pos != -1 { - found = append(found, []int{pos, pos + searchStr.Length()}) + found = append(found, regexpResult{indexes: []int{pos, pos + searchStr.Length()}}) } str, rcall := getReplaceValue(replaceValue) - return stringReplace(s, found, str, rcall) + return r.stringReplace(s, found, str, rcall) } func (r *Runtime) stringproto_replaceAll(call FunctionCall) Value { @@ -704,19 +725,19 @@ func (r *Runtime) stringproto_replaceAll(call FunctionCall) Value { } s := call.This.toString() - var found [][]int + var found []regexpResult searchStr := searchValue.toString() searchLength := searchStr.Length() advanceBy := toIntStrict(max(1, int64(searchLength))) pos := s.index(searchStr, 0) for pos != -1 { - found = append(found, []int{pos, pos + searchLength}) + found = append(found, regexpResult{indexes: []int{pos, pos + searchLength}}) pos = s.index(searchStr, pos+advanceBy) } str, rcall := getReplaceValue(replaceValue) - return stringReplace(s, found, str, rcall) + return r.stringReplace(s, found, str, rcall) } func (r *Runtime) stringproto_search(call FunctionCall) Value { diff --git a/vendor/github.com/grafana/sobek/builtin_typedarrays.go b/vendor/github.com/grafana/sobek/builtin_typedarrays.go index 698616fd1..b323b6d01 100644 --- a/vendor/github.com/grafana/sobek/builtin_typedarrays.go +++ b/vendor/github.com/grafana/sobek/builtin_typedarrays.go @@ -174,13 +174,13 @@ func (r *Runtime) newDataView(args []Value, newTarget *Object) *Object { byteOffset = r.toIndex(offsetArg) buffer.ensureNotDetached(true) if byteOffset > len(buffer.data) { - panic(r.newError(r.getRangeError(), "Start offset %s is outside the bounds of the buffer", offsetArg.String())) + panic(r.newErrorf(r.getRangeError(), "Start offset %s is outside the bounds of the buffer", offsetArg.String())) } } if len(args) > 2 && args[2] != nil && args[2] != _undefined { byteLen = r.toIndex(args[2]) if byteOffset+byteLen > len(buffer.data) { - panic(r.newError(r.getRangeError(), "Invalid DataView length %d", byteLen)) + panic(r.newErrorf(r.getRangeError(), "Invalid DataView length %d", byteLen)) } } else { byteLen = len(buffer.data) - byteOffset @@ -188,10 +188,10 @@ func (r *Runtime) newDataView(args []Value, newTarget *Object) *Object { proto := r.getPrototypeFromCtor(newTarget, r.getDataView(), r.getDataViewPrototype()) buffer.ensureNotDetached(true) if byteOffset > len(buffer.data) { - panic(r.newError(r.getRangeError(), "Start offset %d is outside the bounds of the buffer", byteOffset)) + panic(r.newErrorf(r.getRangeError(), "Start offset %d is outside the bounds of the buffer", byteOffset)) } if byteOffset+byteLen > len(buffer.data) { - panic(r.newError(r.getRangeError(), "Invalid DataView length %d", byteLen)) + panic(r.newErrorf(r.getRangeError(), "Invalid DataView length %d", byteLen)) } o := &Object{runtime: r} b := &dataViewObject{ @@ -901,7 +901,7 @@ func (r *Runtime) typedArrayProto_map(call FunctionCall) Value { fc.Arguments[0] = _undefined } fc.Arguments[1] = intToValue(int64(i)) - dst.typedArray.set(i, callbackFn(fc)) + dst.typedArray.set(dst.offset+i, callbackFn(fc)) } return dst.val } @@ -1093,12 +1093,12 @@ func (r *Runtime) typedArrayProto_slice(call FunctionCall) Value { ta.viewedArrayBuf.ensureNotDetached(true) offset := ta.offset elemSize := ta.elemSize - copy(dst.viewedArrayBuf.data, ta.viewedArrayBuf.data[(offset+start)*elemSize:(offset+start+count)*elemSize]) + copy(dst.viewedArrayBuf.data[dst.offset:], ta.viewedArrayBuf.data[(offset+start)*elemSize:(offset+start+count)*elemSize]) } } else { for i := 0; i < count; i++ { ta.viewedArrayBuf.ensureNotDetached(true) - dst.typedArray.set(i, ta.typedArray.get(ta.offset+start+i)) + dst.typedArray.set(dst.offset+i, ta.typedArray.get(ta.offset+start+i)) } } return dst.val @@ -1241,7 +1241,7 @@ func (r *Runtime) typedArrayProto_with(call FunctionCall) Value { } else { fromValue = ta.typedArray.get(ta.offset + k) } - a.typedArray.set(ta.offset+k, fromValue) + a.typedArray.set(k, fromValue) } return a.val } @@ -1260,7 +1260,7 @@ func (r *Runtime) typedArrayProto_toReversed(call FunctionCall) Value { for k := 0; k < length; k++ { from := length - k - 1 fromValue := ta.typedArray.get(ta.offset + from) - a.typedArray.set(ta.offset+k, fromValue) + a.typedArray.set(k, fromValue) } return a.val @@ -1445,7 +1445,7 @@ func (r *Runtime) _newTypedArrayFromArrayBuffer(ab *arrayBufferObject, args []Va if len(args) > 1 && args[1] != nil && args[1] != _undefined { byteOffset = r.toIndex(args[1]) if byteOffset%ta.elemSize != 0 { - panic(r.newError(r.getRangeError(), "Start offset of %s should be a multiple of %d", newTarget.self.getStr("name", nil), ta.elemSize)) + panic(r.newErrorf(r.getRangeError(), "Start offset of %s should be a multiple of %d", newTarget.self.getStr("name", nil), ta.elemSize)) } } var length int @@ -1453,16 +1453,16 @@ func (r *Runtime) _newTypedArrayFromArrayBuffer(ab *arrayBufferObject, args []Va length = r.toIndex(args[2]) ab.ensureNotDetached(true) if byteOffset+length*ta.elemSize > len(ab.data) { - panic(r.newError(r.getRangeError(), "Invalid typed array length: %d", length)) + panic(r.newErrorf(r.getRangeError(), "Invalid typed array length: %d", length)) } } else { ab.ensureNotDetached(true) if len(ab.data)%ta.elemSize != 0 { - panic(r.newError(r.getRangeError(), "Byte length of %s should be a multiple of %d", newTarget.self.getStr("name", nil), ta.elemSize)) + panic(r.newErrorf(r.getRangeError(), "Byte length of %s should be a multiple of %d", newTarget.self.getStr("name", nil), ta.elemSize)) } length = (len(ab.data) - byteOffset) / ta.elemSize if length < 0 { - panic(r.newError(r.getRangeError(), "Start offset %d is outside the bounds of the buffer", byteOffset)) + panic(r.newErrorf(r.getRangeError(), "Start offset %d is outside the bounds of the buffer", byteOffset)) } } ta.offset = byteOffset / ta.elemSize diff --git a/vendor/github.com/grafana/sobek/compiler.go b/vendor/github.com/grafana/sobek/compiler.go index 187c9df27..cd9f3923e 100644 --- a/vendor/github.com/grafana/sobek/compiler.go +++ b/vendor/github.com/grafana/sobek/compiler.go @@ -571,7 +571,7 @@ func (s *scope) addBinding(offset int) *binding { func (s *scope) bindNameLexical(name unistring.String, unique bool, offset int) (*binding, bool) { if b := s.boundNames[name]; b != nil { if unique { - s.c.throwSyntaxError(offset, "Identifier '%s' has already been declared", name) + s.c.throwSyntaxErrorf(offset, "Identifier '%s' has already been declared", name) } return b, false } @@ -1077,7 +1077,7 @@ func (c *compiler) compileLocalExportEntry(entry exportEntry) { b, ok := c.scope.boundNames[name] if !ok { if entry.localName != "default" { - c.throwSyntaxError(entry.offset, "exporting unknown binding: %q", name) + c.throwSyntaxErrorf(entry.offset, "exporting unknown binding: %q", name) } b, _ = c.scope.bindName(name) } @@ -1367,7 +1367,7 @@ func (c *compiler) createBindings(target ast.Expression, createIdBinding func(na case *ast.PropertyKeyed: c.createBindings(prop.Value, createIdBinding) default: - c.throwSyntaxError(int(target.Idx0()-1), "unsupported property type in ObjectPattern: %T", prop) + c.throwSyntaxErrorf(int(target.Idx0()-1), "unsupported property type in ObjectPattern: %T", prop) } } if target.Rest != nil { @@ -1385,7 +1385,7 @@ func (c *compiler) createBindings(target ast.Expression, createIdBinding func(na case *ast.AssignExpression: c.createBindings(target.Left, createIdBinding) default: - c.throwSyntaxError(int(target.Idx0()-1), "unsupported binding target: %T", target) + c.throwSyntaxErrorf(int(target.Idx0()-1), "unsupported binding target: %T", target) } } @@ -1428,7 +1428,7 @@ func (c *compiler) createLexicalIdBindingFuncBody(name unistring.String, isConst parentBinding := paramScope.boundNames[name] if parentBinding != nil { if parentBinding != calleeBinding && (name != "arguments" || !paramScope.argsNeeded) { - c.throwSyntaxError(offset, "Identifier '%s' has already been declared", name) + c.throwSyntaxErrorf(offset, "Identifier '%s' has already been declared", name) } } b, _ := c.scope.bindNameLexical(name, true, offset) @@ -1541,7 +1541,17 @@ func (c *compiler) emit(instructions ...instruction) { c.p.code = append(c.p.code, instructions...) } -func (c *compiler) throwSyntaxError(offset int, format string, args ...interface{}) { +func (c *compiler) throwSyntaxError(offset int, msg string) { + panic(&CompilerSyntaxError{ + CompilerError: CompilerError{ + File: c.p.src, + Offset: offset, + Message: msg, + }, + }) +} + +func (c *compiler) throwSyntaxErrorf(offset int, format string, args ...interface{}) { panic(&CompilerSyntaxError{ CompilerError: CompilerError{ File: c.p.src, @@ -1623,7 +1633,7 @@ func (c *compiler) compileStatementDummy(statement ast.Statement) { func (c *compiler) assert(cond bool, offset int, msg string, args ...interface{}) { if !cond { - c.throwSyntaxError(offset, "Compiler bug: "+msg, args...) + c.throwSyntaxErrorf(offset, "Compiler bug: "+msg, args...) } } @@ -1690,7 +1700,7 @@ func (s *classScope) declarePrivateId(name unistring.String, kind ast.PropertyKi } } } - s.c.throwSyntaxError(offset, "Identifier '#%s' has already been declared", name) + s.c.throwSyntaxErrorf(offset, "Identifier '#%s' has already been declared", name) panic("unreachable") } var env *privateEnvRegistry @@ -1749,6 +1759,6 @@ func (c *compiler) resolvePrivateName(name unistring.String, offset int) (*resol } } } - c.throwSyntaxError(offset, "Private field '#%s' must be declared in an enclosing class", name) + c.throwSyntaxErrorf(offset, "Private field '#%s' must be declared in an enclosing class", name) panic("unreachable") } diff --git a/vendor/github.com/grafana/sobek/compiler_expr.go b/vendor/github.com/grafana/sobek/compiler_expr.go index ecd627ecf..894bb08ec 100644 --- a/vendor/github.com/grafana/sobek/compiler_expr.go +++ b/vendor/github.com/grafana/sobek/compiler_expr.go @@ -1387,7 +1387,7 @@ func (e *compiledFunctionLiteral) compile() (prg *Program, name unistring.String b.isArg = true hasPatterns = true default: - e.c.throwSyntaxError(int(item.Idx0())-1, "Unsupported BindingElement type: %T", item) + e.c.throwSyntaxErrorf(int(item.Idx0())-1, "Unsupported BindingElement type: %T", item) return } if item.Initializer != nil { @@ -1742,7 +1742,7 @@ func (e *compiledFunctionLiteral) emitGetter(putOnStack bool) { } } default: - e.c.throwSyntaxError(e.offset, "Unsupported func type: %v", e.typ) + e.c.throwSyntaxErrorf(e.offset, "Unsupported func type: %v", e.typ) } if !putOnStack { e.c.emit(pop) @@ -2272,7 +2272,7 @@ func (c *compiler) compileArrowFunctionLiteral(v *ast.ArrowFunctionLiteral) *com }, } default: - c.throwSyntaxError(int(b.Idx0())-1, "Unsupported ConciseBody type: %T", b) + c.throwSyntaxErrorf(int(b.Idx0())-1, "Unsupported ConciseBody type: %T", b) } r := &compiledFunctionLiteral{ parameterList: v.ParameterList, @@ -2395,7 +2395,7 @@ func (c *compiler) compileMetaProperty(v *ast.MetaProperty) compiledExpr { return r } - c.throwSyntaxError(int(v.Idx)-1, "Unsupported meta property: %s.%s", v.Meta.Name, v.Property.Name) + c.throwSyntaxErrorf(int(v.Idx)-1, "Unsupported meta property: %s.%s", v.Meta.Name, v.Property.Name) return nil } @@ -3398,7 +3398,7 @@ func (c *compiler) emitObjectPattern(pattern *ast.ObjectPattern, emitAssign func c.emit(getKey) }, initializer, prop.Idx0()), emitAssign) default: - c.throwSyntaxError(int(prop.Idx0()-1), "Unsupported AssignmentProperty type: %T", prop) + c.throwSyntaxErrorf(int(prop.Idx0()-1), "Unsupported AssignmentProperty type: %T", prop) } } if pattern.Rest != nil { diff --git a/vendor/github.com/grafana/sobek/compiler_stmt.go b/vendor/github.com/grafana/sobek/compiler_stmt.go index 990f40c6e..39e898648 100644 --- a/vendor/github.com/grafana/sobek/compiler_stmt.go +++ b/vendor/github.com/grafana/sobek/compiler_stmt.go @@ -68,7 +68,7 @@ func (c *compiler) compileLabeledStatement(v *ast.LabelledStatement, needResult } for b := c.block; b != nil; b = b.outer { if b.label == label { - c.throwSyntaxError(int(v.Label.Idx-1), "Label '%s' has already been declared", label) + c.throwSyntaxErrorf(int(v.Label.Idx-1), "Label '%s' has already been declared", label) } } switch s := v.Statement.(type) { @@ -372,7 +372,7 @@ func (c *compiler) compileForInto(into ast.ForInto, needResult bool) (enter *ent c.emit(enumGet) c.emitPattern(target, c.emitPatternVarAssign, false) default: - c.throwSyntaxError(int(target.Idx0()-1), "unsupported for-in var target: %T", target) + c.throwSyntaxErrorf(int(target.Idx0()-1), "unsupported for-in var target: %T", target) } case *ast.ForDeclaration: @@ -590,7 +590,7 @@ func (c *compiler) findBreakBlock(label *ast.Identifier, isBreak bool) (res *blo } } if !isBreak && found != nil && found.typ != blockLoop && found.typ != blockLoopEnum { - c.throwSyntaxError(int(label.Idx)-1, "Illegal continue statement: '%s' does not denote an iteration statement", label.Name) + c.throwSyntaxErrorf(int(label.Idx)-1, "Illegal continue statement: '%s' does not denote an iteration statement", label.Name) } if res == nil { res = found @@ -758,7 +758,7 @@ func (c *compiler) compileReturnStatement(v *ast.ReturnStatement) { func (c *compiler) checkVarConflict(name unistring.String, offset int) { for sc := c.scope; sc != nil; sc = sc.outer { if b, exists := sc.boundNames[name]; exists && !b.isVar && !(b.isArg && sc != c.scope) { - c.throwSyntaxError(offset, "Identifier '%s' has already been declared", name) + c.throwSyntaxErrorf(offset, "Identifier '%s' has already been declared", name) } if sc.isFunction() { break @@ -839,7 +839,7 @@ func (c *compiler) compileExportDeclaration(expr *ast.ExportDeclaration) { } localB, _ := c.scope.lookupName(n) if localB == nil { - c.throwSyntaxError(int(expr.Idx0()), "couldn't lookup %s", n) + c.throwSyntaxErrorf(int(expr.Idx0()), "couldn't lookup %s", n) } identifier := name.IdentifierName.String() localB.getIndirect = func(vm *vm) Value { @@ -898,7 +898,7 @@ func (c *compiler) compileImportDeclaration(expr *ast.ImportDeclaration) { c.checkIdentifierLName(n, int(expr.Idx)) localB, _ := c.scope.lookupName(n) if localB == nil { - c.throwSyntaxError(int(expr.Idx0()), "couldn't lookup %s", n) + c.throwSyntaxErrorf(int(expr.Idx0()), "couldn't lookup %s", n) } identifier := unistring.NewFromString(value.BindingName).String() localB.getIndirect = func(vm *vm) Value { @@ -920,7 +920,7 @@ func (c *compiler) compileImportDeclaration(expr *ast.ImportDeclaration) { localB, _ := c.scope.lookupName(def.Name) if localB == nil { - c.throwSyntaxError(int(expr.Idx0()), "couldn't lookup %s", def.Name) + c.throwSyntaxErrorf(int(expr.Idx0()), "couldn't lookup %s", def.Name) } if value.BindingName == "*namespace*" { idx := expr.Idx @@ -955,7 +955,7 @@ func (c *compiler) compileVarBinding(expr *ast.Binding) { c.compileExpression(expr.Initializer).emitGetter(true) c.emitPattern(target, c.emitPatternVarAssign, false) default: - c.throwSyntaxError(int(target.Idx0()-1), "unsupported variable binding target: %T", target) + c.throwSyntaxErrorf(int(target.Idx0()-1), "unsupported variable binding target: %T", target) } } @@ -1012,7 +1012,7 @@ func (c *compiler) compileLexicalBinding(expr *ast.Binding) { c.emitPatternLexicalAssign(target, init) }, false) default: - c.throwSyntaxError(int(target.Idx0()-1), "unsupported lexical binding target: %T", target) + c.throwSyntaxErrorf(int(target.Idx0()-1), "unsupported lexical binding target: %T", target) } } diff --git a/vendor/github.com/grafana/sobek/extract_passed_tests.sh b/vendor/github.com/grafana/sobek/extract_passed_tests.sh new file mode 100644 index 000000000..5f90c4c6c --- /dev/null +++ b/vendor/github.com/grafana/sobek/extract_passed_tests.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +# Usage: +# go test -v | ./extract_passed_tests.sh +# +# In order to count how many test files are passing: +# go test -v | ./extract_passed_tests.sh | wc -l +# +# Compare passed test files before & after certain change: +# go test -v | ./extract_passed_tests.sh > new.txt +# git checkout && go test -v | ./extract_passed_tests.sh > old.txt +# diff -u old.txt new.txt + +sed -En 's/^.*PASS: TestTC39\/tc39\/(test\/.*.js).*$/\1/p' | sort -u diff --git a/vendor/github.com/grafana/sobek/object_goreflect.go b/vendor/github.com/grafana/sobek/object_goreflect.go index 12611c28f..3e6fefe4f 100644 --- a/vendor/github.com/grafana/sobek/object_goreflect.go +++ b/vendor/github.com/grafana/sobek/object_goreflect.go @@ -154,7 +154,7 @@ func (o *objectGoReflect) init() { // Always use pointer type for non-interface values to be able to access both methods defined on // the literal type and on the pointer. if o.fieldsValue.Kind() != reflect.Interface { - methodsType = reflect.PtrTo(o.fieldsValue.Type()) + methodsType = reflect.PointerTo(o.fieldsValue.Type()) } else { methodsType = o.fieldsValue.Type() } diff --git a/vendor/github.com/grafana/sobek/parser/regexp.go b/vendor/github.com/grafana/sobek/parser/regexp.go index f455d0da2..775fcbdd6 100644 --- a/vendor/github.com/grafana/sobek/parser/regexp.go +++ b/vendor/github.com/grafana/sobek/parser/regexp.go @@ -175,8 +175,14 @@ func (self *_RegExp_parser) scanGroup() { self.error(false, "re2: Invalid (%s) ", self.str[self.chrOffset:self.chrOffset+2]) return case ch == '<': - self.error(false, "re2: Invalid (%s) ", self.str[self.chrOffset:self.chrOffset+2]) - return + if len(str) > 2 && (str[2] == '=' || str[2] == '!') { + self.error(false, "re2: Invalid (%s) ", self.str[self.chrOffset:self.chrOffset+2]) + return + } + self.pass() // ? + self.writeByte('P') // older Go versions compatibility + self.pass() // < + self.scanGroupName() case ch != ':': self.error(true, "Invalid group") return @@ -212,6 +218,24 @@ func (self *_RegExp_parser) scanGroup() { self.pass() } +func (self *_RegExp_parser) scanGroupName() { + supported := true + if !(self.chr >= 'a' && self.chr <= 'z' || self.chr >= 'A' && self.chr <= 'Z' && self.chr == '_') { + supported = false + } + for self.chr != -1 && self.chr != '>' { + if !(self.chr >= 'a' && self.chr <= 'z' || self.chr >= 'A' && self.chr <= 'Z' && self.chr == '_' || self.chr >= '0' && self.chr <= '9') { + supported = false + } + self.pass() + } + if !supported { + self.error(false, "Unsupported group name") + return + } + self.pass() +} + // [...] func (self *_RegExp_parser) scanBracket() { str := self.str[self.chrOffset:] @@ -367,6 +391,10 @@ func (self *_RegExp_parser) scanEscape(inClass bool) { } self.read() return + case 'k': + // The rules are too complicated to implement here, so we pass it on to regexp2 + self.error(false, "named group back-reference") + return default: // $ is an identifier character, so we have to have // a special case for it here diff --git a/vendor/github.com/grafana/sobek/regexp.go b/vendor/github.com/grafana/sobek/regexp.go index 98f6979aa..e83440fe3 100644 --- a/vendor/github.com/grafana/sobek/regexp.go +++ b/vendor/github.com/grafana/sobek/regexp.go @@ -8,7 +8,7 @@ import ( "strings" "unicode/utf16" - "github.com/dlclark/regexp2" + "github.com/dlclark/regexp2/v2" "github.com/grafana/sobek/unistring" ) @@ -69,8 +69,26 @@ type regexpPattern struct { regexp2Wrapper *regexp2Wrapper } +type regexpResult struct { + indexes []int + groups []string +} + +func (result *regexpResult) appendIndexesAndGroup(index1, index2 int, name string) { + result.indexes = append(result.indexes, index1, index2) + result.groups = append(result.groups, name) +} + +func submatchesToRegexpResults(submatches [][]int, groups []string) []regexpResult { + results := make([]regexpResult, 0, len(submatches)) + for _, val := range submatches { + results = append(results, regexpResult{indexes: val, groups: groups}) + } + return results +} + func compileRegexp2(src string, multiline, dotAll, ignoreCase, unicode bool) (*regexp2Wrapper, error) { - var opts regexp2.RegexOptions = regexp2.ECMAScript + var opts = regexp2.ECMAScript if multiline { opts |= regexp2.Multiline } @@ -125,7 +143,7 @@ func buildUTF8PosMap(s unicodeString) (positionMap, string) { return pm, sb.String() } -func (p *regexpPattern) findSubmatchIndex(s String, start int) []int { +func (p *regexpPattern) findSubmatchIndex(s String, start int) regexpResult { if p.regexpWrapper == nil { return p.regexp2Wrapper.findSubmatchIndex(s, start, p.unicode, p.global || p.sticky) } @@ -139,7 +157,7 @@ func (p *regexpPattern) findSubmatchIndex(s String, start int) []int { return p.regexpWrapper.findSubmatchIndex(s, p.unicode) } -func (p *regexpPattern) findAllSubmatchIndex(s String, start int, limit int, sticky bool) [][]int { +func (p *regexpPattern) findAllSubmatchIndex(s String, start int, limit int, sticky bool) []regexpResult { if p.regexpWrapper == nil { return p.regexp2Wrapper.findAllSubmatchIndex(s, start, limit, sticky, p.unicode) } @@ -150,10 +168,10 @@ func (p *regexpPattern) findAllSubmatchIndex(s String, start int, limit int, sti } if limit == 1 { result := p.regexpWrapper.findSubmatchIndexUnicode(u, p.unicode) - if result == nil { + if result.indexes == nil { return nil } - return [][]int{result} + return []regexpResult{result} } // Unfortunately Go's regexp library lacks FindAllReaderSubmatchIndex(), so we have to use a UTF-8 string as an // input. @@ -163,8 +181,8 @@ func (p *regexpPattern) findAllSubmatchIndex(s String, start int, limit int, sti if pm != nil { res := p.regexpWrapper.findAllSubmatchIndex(str, limit, sticky) for _, result := range res { - for i, idx := range result { - result[i] = pm.get(idx) + for i, idx := range result.indexes { + result.indexes[i] = pm.get(idx) } } return res @@ -204,7 +222,7 @@ type regexpObject struct { standard bool } -func (r *regexp2Wrapper) findSubmatchIndex(s String, start int, fullUnicode, doCache bool) (result []int) { +func (r *regexp2Wrapper) findSubmatchIndex(s String, start int, fullUnicode, doCache bool) regexpResult { if fullUnicode { return r.findSubmatchIndexUnicode(s, start, doCache) } @@ -237,26 +255,29 @@ func (r *regexp2Wrapper) findUTF16Cached(s String, start int, doCache bool) (mat return } -func (r *regexp2Wrapper) findSubmatchIndexUTF16(s String, start int, doCache bool) (result []int) { +func (r *regexp2Wrapper) findSubmatchIndexUTF16(s String, start int, doCache bool) regexpResult { match, _, err := r.findUTF16Cached(s, start, doCache) if err != nil { - return + return regexpResult{} } if match == nil { - return + return regexpResult{} } groups := match.Groups() - result = make([]int, 0, len(groups)<<1) + result := regexpResult{ + indexes: make([]int, 0, len(groups)<<1), + groups: make([]string, 0, len(groups)), + } for _, group := range groups { if len(group.Captures) > 0 { - result = append(result, group.Index, group.Index+group.Length) + result.appendIndexesAndGroup(group.RuneIndex, group.RuneIndex+group.RuneLength, group.Name) } else { - result = append(result, -1, 0) + result.appendIndexesAndGroup(-1, 0, group.Name) } } - return + return result } func (r *regexp2Wrapper) findUnicodeCached(s String, start int, doCache bool) (match *regexp2.Match, posMap []int, err error) { @@ -302,26 +323,29 @@ func (r *regexp2Wrapper) findUnicodeCached(s String, start int, doCache bool) (m return } -func (r *regexp2Wrapper) findSubmatchIndexUnicode(s String, start int, doCache bool) (result []int) { +func (r *regexp2Wrapper) findSubmatchIndexUnicode(s String, start int, doCache bool) regexpResult { match, posMap, err := r.findUnicodeCached(s, start, doCache) if match == nil || err != nil { - return + return regexpResult{} } groups := match.Groups() - result = make([]int, 0, len(groups)<<1) + result := regexpResult{ + indexes: make([]int, 0, len(groups)<<1), + groups: make([]string, 0, len(groups)), + } for _, group := range groups { if len(group.Captures) > 0 { - result = append(result, posMap[group.Index], posMap[group.Index+group.Length]) + result.appendIndexesAndGroup(posMap[group.RuneIndex], posMap[group.RuneIndex+group.RuneLength], group.Name) } else { - result = append(result, -1, 0) + result.appendIndexesAndGroup(-1, 0, group.Name) } } - return + return result } -func (r *regexp2Wrapper) findAllSubmatchIndexUTF16(s String, start, limit int, sticky bool) [][]int { +func (r *regexp2Wrapper) findAllSubmatchIndexUTF16(s String, start, limit int, sticky bool) []regexpResult { wrapped := r.rx match, runes, err := r.findUTF16Cached(s, start, false) if match == nil || err != nil { @@ -330,27 +354,30 @@ func (r *regexp2Wrapper) findAllSubmatchIndexUTF16(s String, start, limit int, s if limit < 0 { limit = len(runes) + 1 } - results := make([][]int, 0, limit) + results := make([]regexpResult, 0, limit) for match != nil { groups := match.Groups() - result := make([]int, 0, len(groups)<<1) + result := regexpResult{ + indexes: make([]int, 0, len(groups)<<1), + groups: make([]string, 0, len(groups)), + } for _, group := range groups { if len(group.Captures) > 0 { - startPos := group.Index - endPos := group.Index + group.Length - result = append(result, startPos, endPos) + startPos := group.RuneIndex + endPos := group.RuneIndex + group.RuneLength + result.appendIndexesAndGroup(startPos, endPos, group.Name) } else { - result = append(result, -1, 0) + result.appendIndexesAndGroup(-1, 0, group.Name) } } - if sticky && len(result) > 1 { - if result[0] != start { + if sticky && len(result.indexes) > 1 { + if result.indexes[0] != start { break } - start = result[1] + start = result.indexes[1] } results = append(results, result) @@ -404,12 +431,12 @@ func posMapReverseLookup(posMap []int, pos int) (int, bool) { return mapped, false } -func (r *regexp2Wrapper) findAllSubmatchIndexUnicode(s unicodeString, start, limit int, sticky bool) [][]int { +func (r *regexp2Wrapper) findAllSubmatchIndexUnicode(s unicodeString, start, limit int, sticky bool) []regexpResult { wrapped := r.rx if limit < 0 { limit = len(s) + 1 } - results := make([][]int, 0, limit) + results := make([]regexpResult, 0, limit) match, posMap, err := r.findUnicodeCached(s, start, false) if err != nil { return nil @@ -417,23 +444,26 @@ func (r *regexp2Wrapper) findAllSubmatchIndexUnicode(s unicodeString, start, lim for match != nil { groups := match.Groups() - result := make([]int, 0, len(groups)<<1) + result := regexpResult{ + indexes: make([]int, 0, len(groups)<<1), + groups: make([]string, 0, len(groups)), + } for _, group := range groups { if len(group.Captures) > 0 { - start := posMap[group.Index] - end := posMap[group.Index+group.Length] - result = append(result, start, end) + start := posMap[group.RuneIndex] + end := posMap[group.RuneIndex+group.RuneLength] + result.appendIndexesAndGroup(start, end, group.Name) } else { - result = append(result, -1, 0) + result.appendIndexesAndGroup(-1, 0, group.Name) } } - if sticky && len(result) > 1 { - if result[0] != start { + if sticky && len(result.indexes) > 1 { + if result.indexes[0] != start { break } - start = result[1] + start = result.indexes[1] } results = append(results, result) @@ -445,7 +475,7 @@ func (r *regexp2Wrapper) findAllSubmatchIndexUnicode(s unicodeString, start, lim return results } -func (r *regexp2Wrapper) findAllSubmatchIndex(s String, start, limit int, sticky, fullUnicode bool) [][]int { +func (r *regexp2Wrapper) findAllSubmatchIndex(s String, start, limit int, sticky, fullUnicode bool) []regexpResult { a, u := devirtualizeString(s) if u != nil { if fullUnicode { @@ -462,24 +492,24 @@ func (r *regexp2Wrapper) clone() *regexp2Wrapper { } } -func (r *regexpWrapper) findAllSubmatchIndex(s string, limit int, sticky bool) (results [][]int) { +func (r *regexpWrapper) findAllSubmatchIndex(s string, limit int, sticky bool) []regexpResult { wrapped := (*regexp.Regexp)(r) - results = wrapped.FindAllStringSubmatchIndex(s, limit) + results := submatchesToRegexpResults(wrapped.FindAllStringSubmatchIndex(s, limit), wrapped.SubexpNames()) pos := 0 if sticky { for i, result := range results { - if len(result) > 1 { - if result[0] != pos { + if len(result.indexes) > 1 { + if result.indexes[0] != pos { return results[:i] } - pos = result[1] + pos = result.indexes[1] } } } - return + return results } -func (r *regexpWrapper) findSubmatchIndex(s String, fullUnicode bool) []int { +func (r *regexpWrapper) findSubmatchIndex(s String, fullUnicode bool) regexpResult { a, u := devirtualizeString(s) if u != nil { return r.findSubmatchIndexUnicode(u, fullUnicode) @@ -487,41 +517,75 @@ func (r *regexpWrapper) findSubmatchIndex(s String, fullUnicode bool) []int { return r.findSubmatchIndexASCII(string(a)) } -func (r *regexpWrapper) findSubmatchIndexASCII(s string) []int { +func (r *regexpWrapper) findSubmatchIndexASCII(s string) regexpResult { wrapped := (*regexp.Regexp)(r) - return wrapped.FindStringSubmatchIndex(s) + return regexpResult{indexes: wrapped.FindStringSubmatchIndex(s), groups: wrapped.SubexpNames()} } -func (r *regexpWrapper) findSubmatchIndexUnicode(s unicodeString, fullUnicode bool) (result []int) { +func (r *regexpWrapper) findSubmatchIndexUnicode(s unicodeString, fullUnicode bool) regexpResult { wrapped := (*regexp.Regexp)(r) if fullUnicode { posMap, runes, _, _ := buildPosMap(&lenientUtf16Decoder{utf16Reader: s.utf16Reader()}, s.Length(), 0) - res := wrapped.FindReaderSubmatchIndex(&arrayRuneReader{runes: runes}) - for i, item := range res { + result := regexpResult{indexes: wrapped.FindReaderSubmatchIndex(&arrayRuneReader{runes: runes})} + for i, item := range result.indexes { if item >= 0 { - res[i] = posMap[item] + result.indexes[i] = posMap[item] } } - return res + return result } - return wrapped.FindReaderSubmatchIndex(s.utf16RuneReader()) + return regexpResult{indexes: wrapped.FindReaderSubmatchIndex(s.utf16RuneReader()), groups: wrapped.SubexpNames()} } func (r *regexpWrapper) clone() *regexpWrapper { return r } -func (r *regexpObject) execResultToArray(target String, result []int) Value { - captureCount := len(result) >> 1 +func (r *Runtime) createRegexpGroupsObj(valueArray []Value, groupNames []string) *Object { + var groups *baseObject + for index := 1; index < len(valueArray); index++ { + if index < len(groupNames) { + name := groupNames[index] + if name == "" { + continue + } else if groups == nil { + groups = r.newBaseObject(nil, classObject) + } + groups.setOwnStr(unistring.NewFromString(name), valueArray[index], false) + } + } + if groups != nil { + return groups.val + } + return nil +} + +func createRegexpGroupsMap(result regexpResult) (groups map[unistring.String]int) { + if len(result.groups) > 0 { + groups = make(map[unistring.String]int) + for i := 1; i < len(result.groups); i++ { + if group := result.groups[i]; group != "" { + idx := i * 2 + if idx < len(result.indexes)-1 { + groups[unistring.NewFromString(group)] = idx + } + } + } + } + return +} + +func (r *regexpObject) execResultToArray(target String, result regexpResult) Value { + captureCount := len(result.indexes) >> 1 valueArray := make([]Value, captureCount) - matchIndex := result[0] - valueArray[0] = target.Substring(result[0], result[1]) + matchIndex := result.indexes[0] + valueArray[0] = target.Substring(result.indexes[0], result.indexes[1]) lowerBound := 0 for index := 1; index < captureCount; index++ { offset := index << 1 - if result[offset] >= 0 && result[offset+1] >= lowerBound { - valueArray[index] = target.Substring(result[offset], result[offset+1]) - lowerBound = result[offset] + if result.indexes[offset] >= 0 && result.indexes[offset+1] >= lowerBound { + valueArray[index] = target.Substring(result.indexes[offset], result.indexes[offset+1]) + lowerBound = result.indexes[offset] } else { valueArray[index] = _undefined } @@ -529,6 +593,22 @@ func (r *regexpObject) execResultToArray(target String, result []int) Value { match := r.val.runtime.newArrayValues(valueArray) match.self.setOwnStr("input", target, false) match.self.setOwnStr("index", intToValue(int64(matchIndex)), false) + + groups := r.val.runtime.createRegexpGroupsObj(valueArray, result.groups) + + var groupsVal Value + if groups != nil { + groupsVal = groups + } else { + groupsVal = _undefined + } + match.self.defineOwnPropertyStr("groups", PropertyDescriptor{ + Value: groupsVal, + Writable: FLAG_TRUE, + Configurable: FLAG_TRUE, + Enumerable: FLAG_TRUE, + }, false) + return match } @@ -540,17 +620,17 @@ func (r *regexpObject) getLastIndex() int64 { return lastIndex } -func (r *regexpObject) execRegexp(target String) (match bool, result []int) { +func (r *regexpObject) execRegexp(target String) (match bool, result regexpResult) { index := r.getLastIndex() if index >= 0 && index <= int64(target.Length()) { result = r.pattern.findSubmatchIndex(target, int(index)) } - match = len(result) > 0 && (!r.pattern.sticky || int64(result[0]) == index) + match = len(result.indexes) > 0 && (!r.pattern.sticky || int64(result.indexes[0]) == index) if r.pattern.global || r.pattern.sticky { var newLastIndex int64 if match { - newLastIndex = int64(result[1]) + newLastIndex = int64(result.indexes[1]) } r.setOwnStr("lastIndex", intToValue(newLastIndex), true) } diff --git a/vendor/github.com/grafana/sobek/runtime.go b/vendor/github.com/grafana/sobek/runtime.go index c8fb6d7e4..cb8502a35 100644 --- a/vendor/github.com/grafana/sobek/runtime.go +++ b/vendor/github.com/grafana/sobek/runtime.go @@ -474,22 +474,20 @@ func (r *Runtime) typeErrorResult(throw bool, args ...interface{}) { } } -func (r *Runtime) newError(typ *Object, format string, args ...interface{}) Value { - var msg string - if len(args) > 0 { - msg = fmt.Sprintf(format, args...) - } else { - msg = format - } +func (r *Runtime) newError(typ *Object, msg string) Value { return r.builtin_new(typ, []Value{newStringValue(msg)}) } +func (r *Runtime) newErrorf(typ *Object, format string, args ...interface{}) Value { + return r.builtin_new(typ, []Value{newStringValue(fmt.Sprintf(format, args...))}) +} + func (r *Runtime) throwReferenceError(name unistring.String) { panic(r.newReferenceError(name)) } func (r *Runtime) newReferenceError(name unistring.String) Value { - return r.newError(r.getReferenceError(), "%s is not defined", name) + return r.newErrorf(r.getReferenceError(), "%s is not defined", name) } func (r *Runtime) newSyntaxError(msg string, offset int) Value { @@ -1289,11 +1287,11 @@ func (r *Runtime) toIndex(v Value) int { num := v.ToInteger() if num >= 0 && num < maxInt { if bits.UintSize == 32 && num >= math.MaxInt32 { - panic(r.newError(r.getRangeError(), "Index %s overflows int", v.String())) + panic(r.newErrorf(r.getRangeError(), "Index %s overflows int", v.String())) } return int(num) } - panic(r.newError(r.getRangeError(), "Invalid index %s", v.String())) + panic(r.newErrorf(r.getRangeError(), "Invalid index %s", v.String())) } func (r *Runtime) toBoolean(b bool) Value { @@ -2208,7 +2206,7 @@ func (r *Runtime) toReflectValue(v Value, dst reflect.Value, ctx *objectExportCt } case reflect.Struct: if o, ok := v.(*Object); ok { - t := reflect.PtrTo(typ) + t := reflect.PointerTo(typ) if v, exists := ctx.getTyped(o, t); exists { dst.Set(reflect.ValueOf(v).Elem()) return nil diff --git a/vendor/github.com/grafana/sobek/typedarrays.go b/vendor/github.com/grafana/sobek/typedarrays.go index ead7c2489..74a0abb1e 100644 --- a/vendor/github.com/grafana/sobek/typedarrays.go +++ b/vendor/github.com/grafana/sobek/typedarrays.go @@ -132,8 +132,8 @@ func (a *uint8Array) toRaw(v Value) uint64 { } func (a *uint8Array) ptr(idx int) *uint8 { - p := unsafe.Pointer((*reflect.SliceHeader)(unsafe.Pointer(a)).Data) - return (*uint8)(unsafe.Pointer(uintptr(p) + uintptr(idx))) + p := unsafe.SliceData(*a) + return (*uint8)(unsafe.Add(unsafe.Pointer(p), idx)) } func (a *uint8Array) get(idx int) Value { @@ -169,7 +169,7 @@ func (a *uint8Array) typeMatch(v Value) bool { } func (a *uint8Array) export(offset int, length int) interface{} { - return ([]uint8)(*a)[offset : offset+length : offset+length] + return unsafe.Slice(a.ptr(offset), length) } func (a *uint8Array) exportType() reflect.Type { @@ -181,8 +181,8 @@ func (a *uint8ClampedArray) toRaw(v Value) uint64 { } func (a *uint8ClampedArray) ptr(idx int) *uint8 { - p := unsafe.Pointer((*reflect.SliceHeader)(unsafe.Pointer(a)).Data) - return (*uint8)(unsafe.Pointer(uintptr(p) + uintptr(idx))) + p := unsafe.SliceData(*a) + return (*uint8)(unsafe.Add(unsafe.Pointer(p), idx)) } func (a *uint8ClampedArray) get(idx int) Value { @@ -218,7 +218,7 @@ func (a *uint8ClampedArray) typeMatch(v Value) bool { } func (a *uint8ClampedArray) export(offset int, length int) interface{} { - return ([]uint8)(*a)[offset : offset+length : offset+length] + return unsafe.Slice(a.ptr(offset), length) } func (a *uint8ClampedArray) exportType() reflect.Type { @@ -226,8 +226,8 @@ func (a *uint8ClampedArray) exportType() reflect.Type { } func (a *int8Array) ptr(idx int) *int8 { - p := unsafe.Pointer((*reflect.SliceHeader)(unsafe.Pointer(a)).Data) - return (*int8)(unsafe.Pointer(uintptr(p) + uintptr(idx))) + p := unsafe.SliceData(*a) + return (*int8)(unsafe.Add(unsafe.Pointer(p), idx)) } func (a *int8Array) get(idx int) Value { @@ -267,12 +267,7 @@ func (a *int8Array) typeMatch(v Value) bool { } func (a *int8Array) export(offset int, length int) interface{} { - var res []int8 - sliceHeader := (*reflect.SliceHeader)(unsafe.Pointer(&res)) - sliceHeader.Data = (*reflect.SliceHeader)(unsafe.Pointer(a)).Data + uintptr(offset) - sliceHeader.Len = length - sliceHeader.Cap = length - return res + return unsafe.Slice(a.ptr(offset), length) } var typeInt8Array = reflect.TypeOf(([]int8)(nil)) @@ -286,8 +281,8 @@ func (a *uint16Array) toRaw(v Value) uint64 { } func (a *uint16Array) ptr(idx int) *uint16 { - p := unsafe.Pointer((*reflect.SliceHeader)(unsafe.Pointer(a)).Data) - return (*uint16)(unsafe.Pointer(uintptr(p) + uintptr(idx)*2)) + p := unsafe.SliceData(*a) + return (*uint16)(unsafe.Add(unsafe.Pointer(p), idx*2)) } func (a *uint16Array) get(idx int) Value { @@ -325,12 +320,7 @@ func (a *uint16Array) typeMatch(v Value) bool { var typeUint16Array = reflect.TypeOf(([]uint16)(nil)) func (a *uint16Array) export(offset int, length int) interface{} { - var res []uint16 - sliceHeader := (*reflect.SliceHeader)(unsafe.Pointer(&res)) - sliceHeader.Data = (*reflect.SliceHeader)(unsafe.Pointer(a)).Data + uintptr(offset)*2 - sliceHeader.Len = length - sliceHeader.Cap = length - return res + return unsafe.Slice(a.ptr(offset), length) } func (a *uint16Array) exportType() reflect.Type { @@ -338,8 +328,8 @@ func (a *uint16Array) exportType() reflect.Type { } func (a *int16Array) ptr(idx int) *int16 { - p := unsafe.Pointer((*reflect.SliceHeader)(unsafe.Pointer(a)).Data) - return (*int16)(unsafe.Pointer(uintptr(p) + uintptr(idx)*2)) + p := unsafe.SliceData(*a) + return (*int16)(unsafe.Add(unsafe.Pointer(p), idx*2)) } func (a *int16Array) get(idx int) Value { @@ -379,12 +369,7 @@ func (a *int16Array) typeMatch(v Value) bool { } func (a *int16Array) export(offset int, length int) interface{} { - var res []int16 - sliceHeader := (*reflect.SliceHeader)(unsafe.Pointer(&res)) - sliceHeader.Data = (*reflect.SliceHeader)(unsafe.Pointer(a)).Data + uintptr(offset)*2 - sliceHeader.Len = length - sliceHeader.Cap = length - return res + return unsafe.Slice(a.ptr(offset), length) } var typeInt16Array = reflect.TypeOf(([]int16)(nil)) @@ -394,8 +379,8 @@ func (a *int16Array) exportType() reflect.Type { } func (a *uint32Array) ptr(idx int) *uint32 { - p := unsafe.Pointer((*reflect.SliceHeader)(unsafe.Pointer(a)).Data) - return (*uint32)(unsafe.Pointer(uintptr(p) + uintptr(idx)*4)) + p := unsafe.SliceData(*a) + return (*uint32)(unsafe.Add(unsafe.Pointer(p), idx*4)) } func (a *uint32Array) get(idx int) Value { @@ -435,12 +420,7 @@ func (a *uint32Array) typeMatch(v Value) bool { } func (a *uint32Array) export(offset int, length int) interface{} { - var res []uint32 - sliceHeader := (*reflect.SliceHeader)(unsafe.Pointer(&res)) - sliceHeader.Data = (*reflect.SliceHeader)(unsafe.Pointer(a)).Data + uintptr(offset)*4 - sliceHeader.Len = length - sliceHeader.Cap = length - return res + return unsafe.Slice(a.ptr(offset), length) } var typeUint32Array = reflect.TypeOf(([]uint32)(nil)) @@ -450,8 +430,8 @@ func (a *uint32Array) exportType() reflect.Type { } func (a *int32Array) ptr(idx int) *int32 { - p := unsafe.Pointer((*reflect.SliceHeader)(unsafe.Pointer(a)).Data) - return (*int32)(unsafe.Pointer(uintptr(p) + uintptr(idx)*4)) + p := unsafe.SliceData(*a) + return (*int32)(unsafe.Add(unsafe.Pointer(p), idx*4)) } func (a *int32Array) get(idx int) Value { @@ -491,12 +471,7 @@ func (a *int32Array) typeMatch(v Value) bool { } func (a *int32Array) export(offset int, length int) interface{} { - var res []int32 - sliceHeader := (*reflect.SliceHeader)(unsafe.Pointer(&res)) - sliceHeader.Data = (*reflect.SliceHeader)(unsafe.Pointer(a)).Data + uintptr(offset)*4 - sliceHeader.Len = length - sliceHeader.Cap = length - return res + return unsafe.Slice(a.ptr(offset), length) } var typeInt32Array = reflect.TypeOf(([]int32)(nil)) @@ -506,8 +481,8 @@ func (a *int32Array) exportType() reflect.Type { } func (a *float32Array) ptr(idx int) *float32 { - p := unsafe.Pointer((*reflect.SliceHeader)(unsafe.Pointer(a)).Data) - return (*float32)(unsafe.Pointer(uintptr(p) + uintptr(idx)*4)) + p := unsafe.SliceData(*a) + return (*float32)(unsafe.Add(unsafe.Pointer(p), idx*4)) } func (a *float32Array) get(idx int) Value { @@ -562,12 +537,7 @@ func (a *float32Array) typeMatch(v Value) bool { } func (a *float32Array) export(offset int, length int) interface{} { - var res []float32 - sliceHeader := (*reflect.SliceHeader)(unsafe.Pointer(&res)) - sliceHeader.Data = (*reflect.SliceHeader)(unsafe.Pointer(a)).Data + uintptr(offset)*4 - sliceHeader.Len = length - sliceHeader.Cap = length - return res + return unsafe.Slice(a.ptr(offset), length) } var typeFloat32Array = reflect.TypeOf(([]float32)(nil)) @@ -577,8 +547,8 @@ func (a *float32Array) exportType() reflect.Type { } func (a *float64Array) ptr(idx int) *float64 { - p := unsafe.Pointer((*reflect.SliceHeader)(unsafe.Pointer(a)).Data) - return (*float64)(unsafe.Pointer(uintptr(p) + uintptr(idx)*8)) + p := unsafe.SliceData(*a) + return (*float64)(unsafe.Add(unsafe.Pointer(p), idx*8)) } func (a *float64Array) get(idx int) Value { @@ -619,12 +589,7 @@ func (a *float64Array) typeMatch(v Value) bool { } func (a *float64Array) export(offset int, length int) interface{} { - var res []float64 - sliceHeader := (*reflect.SliceHeader)(unsafe.Pointer(&res)) - sliceHeader.Data = (*reflect.SliceHeader)(unsafe.Pointer(a)).Data + uintptr(offset)*8 - sliceHeader.Len = length - sliceHeader.Cap = length - return res + return unsafe.Slice(a.ptr(offset), length) } var typeFloat64Array = reflect.TypeOf(([]float64)(nil)) @@ -638,8 +603,8 @@ func (a *bigInt64Array) toRaw(value Value) uint64 { } func (a *bigInt64Array) ptr(idx int) *int64 { - p := unsafe.Pointer((*reflect.SliceHeader)(unsafe.Pointer(a)).Data) - return (*int64)(unsafe.Pointer(uintptr(p) + uintptr(idx)*8)) + p := unsafe.SliceData(*a) + return (*int64)(unsafe.Add(unsafe.Pointer(p), idx*8)) } func (a *bigInt64Array) get(idx int) Value { @@ -688,12 +653,7 @@ func (a *bigInt64Array) typeMatch(v Value) bool { } func (a *bigInt64Array) export(offset int, length int) interface{} { - var res []int64 - sliceHeader := (*reflect.SliceHeader)(unsafe.Pointer(&res)) - sliceHeader.Data = (*reflect.SliceHeader)(unsafe.Pointer(a)).Data + uintptr(offset)*8 - sliceHeader.Len = length - sliceHeader.Cap = length - return res + return unsafe.Slice(a.ptr(offset), length) } var typeBigInt64Array = reflect.TypeOf(([]int64)(nil)) @@ -707,8 +667,8 @@ func (a *bigUint64Array) toRaw(value Value) uint64 { } func (a *bigUint64Array) ptr(idx int) *uint64 { - p := unsafe.Pointer((*reflect.SliceHeader)(unsafe.Pointer(a)).Data) - return (*uint64)(unsafe.Pointer(uintptr(p) + uintptr(idx)*8)) + p := unsafe.SliceData(*a) + return (*uint64)(unsafe.Add(unsafe.Pointer(p), idx*8)) } func (a *bigUint64Array) get(idx int) Value { @@ -749,12 +709,7 @@ func (a *bigUint64Array) typeMatch(v Value) bool { } func (a *bigUint64Array) export(offset int, length int) interface{} { - var res []uint64 - sliceHeader := (*reflect.SliceHeader)(unsafe.Pointer(&res)) - sliceHeader.Data = (*reflect.SliceHeader)(unsafe.Pointer(a)).Data + uintptr(offset)*8 - sliceHeader.Len = length - sliceHeader.Cap = length - return res + return unsafe.Slice(a.ptr(offset), length) } var typeBigUint64Array = reflect.TypeOf(([]uint64)(nil)) @@ -1087,7 +1042,7 @@ func (r *Runtime) newBigUint64ArrayObject(buf *arrayBufferObject, offset, length func (o *dataViewObject) getIdxAndByteOrder(getIdx int, littleEndianVal Value, size int) (int, byteOrder) { o.viewedArrayBuf.ensureNotDetached(true) if getIdx+size > o.byteLen { - panic(o.val.runtime.newError(o.val.runtime.getRangeError(), "Index %d is out of bounds", getIdx)) + panic(o.val.runtime.newErrorf(o.val.runtime.getRangeError(), "Index %d is out of bounds", getIdx)) } getIdx += o.byteOffset var bo byteOrder diff --git a/vendor/github.com/grafana/sobek/unistring/string.go b/vendor/github.com/grafana/sobek/unistring/string.go index 462829953..06f95667a 100644 --- a/vendor/github.com/grafana/sobek/unistring/string.go +++ b/vendor/github.com/grafana/sobek/unistring/string.go @@ -9,7 +9,6 @@ package unistring import ( - "reflect" "unicode/utf16" "unicode/utf8" "unsafe" @@ -97,12 +96,7 @@ func NewFromRunes(s []rune) String { } func FromUtf16(b []uint16) String { - var str string - hdr := (*reflect.StringHeader)(unsafe.Pointer(&str)) - hdr.Data = uintptr(unsafe.Pointer(&b[0])) - hdr.Len = len(b) * 2 - - return String(str) + return String(unsafe.String((*byte)(unsafe.Pointer(&b[0])), len(b)*2)) } func (s String) String() string { @@ -118,16 +112,7 @@ func (s String) AsUtf16() []uint16 { return nil } - var a []uint16 - raw := string(s) - - sliceHeader := (*reflect.SliceHeader)(unsafe.Pointer(&a)) - sliceHeader.Data = (*reflect.StringHeader)(unsafe.Pointer(&raw)).Data - - l := len(raw) / 2 - - sliceHeader.Len = l - sliceHeader.Cap = l + a := unsafe.Slice((*uint16)(unsafe.Pointer(unsafe.StringData(string(s)))), len(s)/2) if a[0] == BOM { return a diff --git a/vendor/github.com/grafana/sobek/vm.go b/vendor/github.com/grafana/sobek/vm.go index 033cea291..3d392dffc 100644 --- a/vendor/github.com/grafana/sobek/vm.go +++ b/vendor/github.com/grafana/sobek/vm.go @@ -4238,7 +4238,7 @@ func (n *newAsyncArrowFunc) exec(vm *vm) { } func (vm *vm) alreadyDeclared(name unistring.String) Value { - return vm.r.newError(vm.r.getSyntaxError(), "Identifier '%s' has already been declared", name) + return vm.r.newErrorf(vm.r.getSyntaxError(), "Identifier '%s' has already been declared", name) } func (vm *vm) checkBindVarsGlobal(names []unistring.String) { diff --git a/vendor/modules.txt b/vendor/modules.txt index 3ad1977dd..e3b89cdf4 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -110,10 +110,11 @@ github.com/chromedp/sysutil # github.com/davecgh/go-spew v1.1.1 ## explicit github.com/davecgh/go-spew/spew -# github.com/dlclark/regexp2 v1.12.0 -## explicit; go 1.13 -github.com/dlclark/regexp2 -github.com/dlclark/regexp2/syntax +# github.com/dlclark/regexp2/v2 v2.2.2 +## explicit; go 1.25 +github.com/dlclark/regexp2/v2 +github.com/dlclark/regexp2/v2/helpers +github.com/dlclark/regexp2/v2/syntax # github.com/evanw/esbuild v0.28.1 ## explicit; go 1.13 github.com/evanw/esbuild/internal/api_helpers @@ -184,8 +185,8 @@ github.com/grafana/k6-cloud-openapi-client-go/k6 # github.com/grafana/k6provider v0.5.0 ## explicit; go 1.24.0 github.com/grafana/k6provider -# github.com/grafana/sobek v0.0.0-20260429085637-a66d4790012b -## explicit; go 1.20 +# github.com/grafana/sobek v0.0.0-20260708062710-267a0e055bb4 +## explicit; go 1.25 github.com/grafana/sobek github.com/grafana/sobek/ast github.com/grafana/sobek/file From c06f9a94538cc4cfb12a573b15fdcbaee1bd7657 Mon Sep 17 00:00:00 2001 From: hyuraku <32809703+hyuraku@users.noreply.github.com> Date: Tue, 21 Jul 2026 20:24:20 +0900 Subject: [PATCH 031/182] test: add mouse options unit tests (#6141) --- .../k6/browser/common/mouse_options_test.go | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 internal/js/modules/k6/browser/common/mouse_options_test.go diff --git a/internal/js/modules/k6/browser/common/mouse_options_test.go b/internal/js/modules/k6/browser/common/mouse_options_test.go new file mode 100644 index 000000000..72ca714e2 --- /dev/null +++ b/internal/js/modules/k6/browser/common/mouse_options_test.go @@ -0,0 +1,70 @@ +package common + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestNewMouseClickOptions(t *testing.T) { + t.Parallel() + + opts := NewMouseClickOptions() + + assert.Equal(t, "left", opts.Button) + assert.Equal(t, int64(1), opts.ClickCount) + assert.Equal(t, int64(0), opts.Delay) +} + +func TestNewMouseDblClickOptions(t *testing.T) { + t.Parallel() + + opts := NewMouseDblClickOptions() + + assert.Equal(t, "left", opts.Button) + assert.Equal(t, int64(0), opts.Delay) +} + +func TestNewMouseDownUpOptions(t *testing.T) { + t.Parallel() + + opts := NewMouseDownUpOptions() + + assert.Equal(t, "left", opts.Button) + assert.Equal(t, int64(1), opts.ClickCount) +} + +func TestNewMouseMoveOptions(t *testing.T) { + t.Parallel() + + opts := NewMouseMoveOptions() + + assert.Equal(t, int64(1), opts.Steps) +} + +func TestMouseClickOptionsToMouseDownUpOptions(t *testing.T) { + t.Parallel() + + src := &MouseClickOptions{Button: "right", ClickCount: 3, Delay: 50} + + got := src.ToMouseDownUpOptions() + + // Button and ClickCount are carried over. MouseDownUpOptions has no Delay + // field, so Delay is intentionally dropped. + assert.Equal(t, "right", got.Button) + assert.Equal(t, int64(3), got.ClickCount) +} + +func TestMouseDblClickOptionsToMouseClickOptions(t *testing.T) { + t.Parallel() + + src := &MouseDblClickOptions{Button: "right", Delay: 50} + + got := src.ToMouseClickOptions() + + // Button and Delay are copied, while ClickCount is always forced to 2 + // because this represents a double click. + assert.Equal(t, "right", got.Button) + assert.Equal(t, int64(50), got.Delay) + assert.Equal(t, int64(2), got.ClickCount) +} From 57b85335b1cf72fa5073bb9b7b4fe09e2f5880a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Crevon?= Date: Tue, 21 Jul 2026 16:22:28 +0200 Subject: [PATCH 032/182] Expose TextEncoder and TextDecoder globally (#6182) * feat(js): expose text encoding globals * test(js): cover text encoding globals * chore(deps): use sobek encoding v0.1.0 --- go.mod | 1 + go.sum | 2 + internal/js/bundle.go | 10 +- internal/js/bundle_test.go | 49 + js/modulestest/runtime.go | 2 + .../grafana/sobek-webapi-encoding/LICENSE | 201 ++ .../sobek-webapi-encoding/encoding/doc.go | 51 + .../sobek-webapi-encoding/encoding/error.go | 68 + .../sobek-webapi-encoding/encoding/sobek.go | 215 +++ .../encoding/text_decoder.go | 528 ++++++ .../encoding/text_encoder.go | 44 + .../sobek-webapi-encoding/encoding/types.go | 16 + .../grafana/sobek-webapi-encoding/register.go | 17 + vendor/golang.org/x/text/encoding/encoding.go | 335 ++++ .../internal/identifier/identifier.go | 81 + .../text/encoding/internal/identifier/mib.go | 1627 +++++++++++++++++ .../x/text/encoding/internal/internal.go | 75 + .../x/text/encoding/unicode/override.go | 82 + .../x/text/encoding/unicode/unicode.go | 512 ++++++ .../internal/utf8internal/utf8internal.go | 87 + vendor/golang.org/x/text/runes/cond.go | 187 ++ vendor/golang.org/x/text/runes/runes.go | 355 ++++ vendor/modules.txt | 10 + 23 files changed, 4553 insertions(+), 2 deletions(-) create mode 100644 vendor/github.com/grafana/sobek-webapi-encoding/LICENSE create mode 100644 vendor/github.com/grafana/sobek-webapi-encoding/encoding/doc.go create mode 100644 vendor/github.com/grafana/sobek-webapi-encoding/encoding/error.go create mode 100644 vendor/github.com/grafana/sobek-webapi-encoding/encoding/sobek.go create mode 100644 vendor/github.com/grafana/sobek-webapi-encoding/encoding/text_decoder.go create mode 100644 vendor/github.com/grafana/sobek-webapi-encoding/encoding/text_encoder.go create mode 100644 vendor/github.com/grafana/sobek-webapi-encoding/encoding/types.go create mode 100644 vendor/github.com/grafana/sobek-webapi-encoding/register.go create mode 100644 vendor/golang.org/x/text/encoding/encoding.go create mode 100644 vendor/golang.org/x/text/encoding/internal/identifier/identifier.go create mode 100644 vendor/golang.org/x/text/encoding/internal/identifier/mib.go create mode 100644 vendor/golang.org/x/text/encoding/internal/internal.go create mode 100644 vendor/golang.org/x/text/encoding/unicode/override.go create mode 100644 vendor/golang.org/x/text/encoding/unicode/unicode.go create mode 100644 vendor/golang.org/x/text/internal/utf8internal/utf8internal.go create mode 100644 vendor/golang.org/x/text/runes/cond.go create mode 100644 vendor/golang.org/x/text/runes/runes.go diff --git a/go.mod b/go.mod index 75ee40aeb..aaa51a07c 100644 --- a/go.mod +++ b/go.mod @@ -23,6 +23,7 @@ require ( github.com/grafana/k6-cloud-openapi-client-go v0.0.3-0.20260716094638-49089b6e624d github.com/grafana/k6provider v0.5.0 github.com/grafana/sobek v0.0.0-20260708062710-267a0e055bb4 + github.com/grafana/sobek-webapi-encoding v0.1.0 github.com/grafana/xk6-dashboard-assets v0.1.2 github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 github.com/influxdata/influxdb1-client v0.0.0-20190402204710-8ff2fc3824fc diff --git a/go.sum b/go.sum index 803a19760..742c954cc 100644 --- a/go.sum +++ b/go.sum @@ -98,6 +98,8 @@ github.com/grafana/k6provider v0.5.0 h1:SwItWPOMQHfRytezQBKpeXLxjNmcyD/x9PTA28pE github.com/grafana/k6provider v0.5.0/go.mod h1:R9WKthnwk96E47m6w/mnC13hhBYTn5iMdP5caFt/t5k= github.com/grafana/sobek v0.0.0-20260708062710-267a0e055bb4 h1:LJ2pEOxFbfUIhrkpROwZ6hLhuCn6e5GSX08v5GFwN/4= github.com/grafana/sobek v0.0.0-20260708062710-267a0e055bb4/go.mod h1:BL/2XROA/Wtlb+zGEhkSdSZiMFIgw+D2ZdDfrbccyVE= +github.com/grafana/sobek-webapi-encoding v0.1.0 h1:2qf2pUiI6j33vl2etSE0Id4mfSQ4Jfa0VVfUuSccAkI= +github.com/grafana/sobek-webapi-encoding v0.1.0/go.mod h1:IegnWm83cyZ8qTnfL6Rivmx7dpMVE+w3CblopwfL/go= github.com/grafana/xk6-dashboard-assets v0.1.2 h1:n2wqytPICn2ZYsKa9HE6GlvFXk+WjByMfT4eM+ms3gE= github.com/grafana/xk6-dashboard-assets v0.1.2/go.mod h1:SeoRjvmFF8UhLIFDfvjqqwBtE8MtaIPYIDWqVJZEHDo= github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 h1:UH//fgunKIs4JdUbpDl1VZCDaL56wXCB/5+wF6uHfaI= diff --git a/internal/js/bundle.go b/internal/js/bundle.go index eab3ff4fa..b1a2ab2b7 100644 --- a/internal/js/bundle.go +++ b/internal/js/bundle.go @@ -13,6 +13,7 @@ import ( "strings" "github.com/grafana/sobek" + sobekencoding "github.com/grafana/sobek-webapi-encoding" "github.com/sirupsen/logrus" "go.k6.io/k6/v2/errext" @@ -392,14 +393,19 @@ func (b *Bundle) instantiate(vuImpl *moduleVUImpl, vuID uint64) (*BundleInstance } // registerGlobals registers the globals for the runtime. -// e.g. timers and webcrypto. +// e.g. timers, webcrypto, and encoding. func registerGlobals(vuImpl *moduleVUImpl) error { err := timers.SetupGlobally(vuImpl) if err != nil { return err } - return webcrypto.SetupGlobally(vuImpl) + err = webcrypto.SetupGlobally(vuImpl) + if err != nil { + return err + } + + return sobekencoding.RegisterGlobally(vuImpl.runtime) } func (b *Bundle) setupJSRuntime(rt *sobek.Runtime, vuID uint64, logger logrus.FieldLogger) error { diff --git a/internal/js/bundle_test.go b/internal/js/bundle_test.go index 268e483cb..156cc8983 100644 --- a/internal/js/bundle_test.go +++ b/internal/js/bundle_test.go @@ -1033,6 +1033,55 @@ func TestGlobalTimers(t *testing.T) { } } +func TestGlobalTextEncoding(t *testing.T) { + t.Parallel() + data := ` + const text = "Hello, 世界 👋"; + const encoded = new TextEncoder().encode(text); + if (!(encoded instanceof Uint8Array)) { + throw new Error("TextEncoder.encode() did not return a Uint8Array"); + } + + const decoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }); + if (!decoder.fatal || !decoder.ignoreBOM) { + throw new Error("TextDecoder options were not applied"); + } + if (decoder.decode(encoded) !== text) { + throw new Error("text encoding round trip failed"); + } + + let threwTypeError = false; + try { + decoder.decode(new Uint8Array([0xff])); + } catch (error) { + threwTypeError = error instanceof TypeError; + } + if (!threwTypeError) { + throw new Error("fatal TextDecoder did not throw a TypeError"); + } + + export default function() {} + ` + + b1, err := getSimpleBundle(t, "/script.js", data) + require.NoError(t, err) + logger := testutils.NewLogger(t) + + b2, err := getSimpleBundleFromArchive(t, b1.makeArchive(), logger) + require.NoError(t, err) + + bundles := map[string]*Bundle{"Source": b1, "Archive": b2} + for name, b := range bundles { + t.Run(name, func(t *testing.T) { + t.Parallel() + for _, vuID := range []uint64{1, 2} { + _, err := b.Instantiate(context.Background(), vuID) + require.NoError(t, err) + } + }) + } +} + func TestTopLevelAwaitErrors(t *testing.T) { t.Parallel() data := ` diff --git a/js/modulestest/runtime.go b/js/modulestest/runtime.go index ebb88e1a6..12f8214ff 100644 --- a/js/modulestest/runtime.go +++ b/js/modulestest/runtime.go @@ -7,6 +7,7 @@ import ( "testing" "github.com/grafana/sobek" + sobekencoding "github.com/grafana/sobek-webapi-encoding" "github.com/stretchr/testify/require" "go.k6.io/k6/v2/internal/js/compiler" "go.k6.io/k6/v2/internal/js/eventloop" @@ -59,6 +60,7 @@ func NewRuntime(t testing.TB) *Runtime { } require.NoError(t, timers.SetupGlobally(vu)) require.NoError(t, webcrypto.SetupGlobally(vu)) + require.NoError(t, sobekencoding.RegisterGlobally(vu.RuntimeField)) // let's cancel again in case it has changed t.Cleanup(func() { result.CancelContext() }) return result diff --git a/vendor/github.com/grafana/sobek-webapi-encoding/LICENSE b/vendor/github.com/grafana/sobek-webapi-encoding/LICENSE new file mode 100644 index 000000000..43533e246 --- /dev/null +++ b/vendor/github.com/grafana/sobek-webapi-encoding/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2026 Grafana Labs + + 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. diff --git a/vendor/github.com/grafana/sobek-webapi-encoding/encoding/doc.go b/vendor/github.com/grafana/sobek-webapi-encoding/encoding/doc.go new file mode 100644 index 000000000..cc2526284 --- /dev/null +++ b/vendor/github.com/grafana/sobek-webapi-encoding/encoding/doc.go @@ -0,0 +1,51 @@ +// Package encoding implements the WHATWG Encoding Standard for Sobek runtimes. +// +// This package provides TextEncoder and TextDecoder implementations that can be +// registered with a Sobek runtime to provide Web-compatible text encoding/decoding +// capabilities in JavaScript. +// +// # Supported Encodings +// +// The package supports the following encodings: +// - UTF-8 (default) +// - UTF-16LE (little-endian) +// - UTF-16BE (big-endian) +// +// # Usage +// +// RegisterRuntime reads TextDecoder/TextDecoder.decode options (e.g. "fatal", +// "ignoreBOM", "stream") from JS objects by matching their spec names against +// this package's Go struct fields. Sobek only does that matching when a +// [sobek.FieldNameMapper] is configured on the runtime, and +// RegisterRuntime deliberately leaves that choice to the caller: it is a +// runtime-wide setting, and forcing one here would override a field name +// mapper the host application has already configured for its own use (for +// example a JS runtime embedding sobek for other purposes). Callers must set +// one themselves, such as [sobek.TagFieldNameMapper] configured for the "js" +// tag used by this package's option structs, before relying on any TextDecoder +// option. The option structs retain equivalent "json" tags for callers that +// already use a JSON-tag mapper. +// +// rt := sobek.New() +// rt.SetFieldNameMapper(sobek.TagFieldNameMapper("js", true)) +// if err := encoding.RegisterRuntime(rt); err != nil { +// log.Fatal(err) +// } +// +// Without a field name mapper, options such as {fatal: true} are silently +// ignored: ExportTo falls back to matching the exact exported Go field name +// (e.g. "Fatal"), which no spec-compliant JS caller will ever pass. +// +// After registration, TextEncoder and TextDecoder are available in JavaScript: +// +// const encoder = new TextEncoder(); +// const encoded = encoder.encode("Hello, World!"); +// +// const decoder = new TextDecoder("utf-8"); +// const decoded = decoder.decode(encoded); +// +// # Specification +// +// This implementation follows the WHATWG Encoding Standard: +// https://encoding.spec.whatwg.org/ +package encoding diff --git a/vendor/github.com/grafana/sobek-webapi-encoding/encoding/error.go b/vendor/github.com/grafana/sobek-webapi-encoding/encoding/error.go new file mode 100644 index 000000000..ce4cefe55 --- /dev/null +++ b/vendor/github.com/grafana/sobek-webapi-encoding/encoding/error.go @@ -0,0 +1,68 @@ +package encoding + +import ( + "fmt" + + "github.com/grafana/sobek" +) + +// ErrorName identifies the category of an encoding error. +type ErrorName string + +const ( + // RangeError is thrown if the value of label is unknown, or + // is one of the values leading to a 'replacement' decoding + // algorithm ("iso-2022-cn" or "iso-2022-cn-ext"). + RangeError ErrorName = "RangeError" + + // TypeError is thrown if the value if the Decoder fatal option + // is set and the input data cannot be decoded. + TypeError ErrorName = "TypeError" +) + +// Error represents an encoding error. +type Error struct { + // Name contains one of the strings associated with an error name. + Name ErrorName `json:"name"` + + // Message represents message or description associated with the given error name. + Message string `json:"message"` +} + +// JSError creates a JavaScript error object that can be thrown +func (e *Error) JSError(rt *sobek.Runtime) *sobek.Object { + var constructor *sobek.Object + + switch e.Name { + case TypeError: + constructor = rt.Get("TypeError").ToObject(rt) + case RangeError: + constructor = rt.Get("RangeError").ToObject(rt) + default: + constructor = rt.Get("Error").ToObject(rt) + } + + errorObj, err := rt.New(constructor, rt.ToValue(e.Message)) + if err != nil { + // Fallback to generic error + errorObj = rt.ToValue(fmt.Errorf("%s: %s", e.Name, e.Message)).ToObject(rt) + } + + return errorObj +} + +// Error implements the `error` interface. +func (e *Error) Error() string { + return fmt.Sprintf("%s: %s", e.Name, e.Message) +} + +// NewError returns a new Error instance. +func NewError(name ErrorName, message string) *Error { + return &Error{ + Name: name, + Message: message, + } +} + +// Ensure Error implements the error interface at compile time. +var _ error = (*Error)(nil) diff --git a/vendor/github.com/grafana/sobek-webapi-encoding/encoding/sobek.go b/vendor/github.com/grafana/sobek-webapi-encoding/encoding/sobek.go new file mode 100644 index 000000000..6aebaaef4 --- /dev/null +++ b/vendor/github.com/grafana/sobek-webapi-encoding/encoding/sobek.go @@ -0,0 +1,215 @@ +package encoding + +import ( + "errors" + "fmt" + + "github.com/grafana/sobek" +) + +// RegisterRuntime exports the TextDecoder and TextEncoder constructors into the provided sobek runtime. +// +// It does not configure rt's [sobek.FieldNameMapper]: doing so unconditionally +// would override a mapper the host application may have already set for its +// own purposes. Callers must set a mapper that resolves this package's "js" +// (or equivalent "json") tags for "fatal", "ignoreBOM", and "stream". For +// example, configure +// rt.SetFieldNameMapper(sobek.TagFieldNameMapper("js", true)) before +// registering, or TextDecoder/TextDecoder.decode options will be silently +// ignored. See the package documentation for details. +func RegisterRuntime(rt *sobek.Runtime) error { + if err := bindTextDecoder(rt); err != nil { + return err + } + + return bindTextEncoder(rt) +} + +func bindTextDecoder(rt *sobek.Runtime) error { + constructor := func(call sobek.ConstructorCall) *sobek.Object { + label := "utf-8" + if arg := call.Argument(0); arg != nil && !isNullish(arg) { + // Per the WebIDL USVString conversion rules, a Symbol cannot be + // coerced to a string and must throw a TypeError; unlike real + // string coercion, sobek's ExportTo would otherwise silently + // convert it to its description instead of erroring. + if _, isSymbol := arg.(*sobek.Symbol); isSymbol { + throwAsJSError(rt, NewError(TypeError, "the provided label value cannot be converted to a string")) + } + + if err := rt.ExportTo(arg, &label); err != nil { + throwAsJSError(rt, NewError(RangeError, "extracting label from the first argument: "+err.Error())) + } + } + + var options TextDecoderOptions + if arg := call.Argument(1); arg != nil && !isNullish(arg) { + if err := rt.ExportTo(arg, &options); err != nil { + panic(rt.NewGoError(err)) + } + } + + td, err := NewTextDecoder(label, options) + if err != nil { + throwAsJSError(rt, err) + } + + return newTextDecoderObject(rt, td) + } + + return rt.Set("TextDecoder", constructor) +} + +func bindTextEncoder(rt *sobek.Runtime) error { + constructor := func(_ sobek.ConstructorCall) *sobek.Object { + return newTextEncoderObject(rt, NewTextEncoder()) + } + + return rt.Set("TextEncoder", constructor) +} + +// newTextDecoderObject converts the given TextDecoder instance into a JS object. +// +// It is used by the TextDecoder constructor to convert the Go instance into a JS, +// and will also set the relevant properties as read-only as per the spec. +// +// In the event setting the properties on the object where to fail, the function +// will throw a JS exception. +func newTextDecoderObject(rt *sobek.Runtime, td *TextDecoder) *sobek.Object { + obj := rt.NewObject() + + // Wrap the Go TextDecoder.Decode method in a JS function + decodeMethod := func(call sobek.FunctionCall) sobek.Value { + // Handle variable arguments - buffer can be undefined/missing + var buffer sobek.Value + if len(call.Arguments) > 0 { + buffer = call.Arguments[0] + } + + // Handle options parameter + var options TextDecodeOptions + if len(call.Arguments) > 1 && !isNullish(call.Arguments[1]) { + if err := rt.ExportTo(call.Arguments[1], &options); err != nil { + panic(rt.NewGoError(err)) + } + } + + data, err := exportArrayBuffer(rt, buffer) + if err != nil { + panic(rt.NewGoError(err)) + } + + decoded, err := td.Decode(data, options) + if err != nil { + throwAsJSError(rt, err) + } + + return rt.ToValue(decoded) + } + + // Set the decode method to the wrapper function we just created + if err := setReadOnlyPropertyOf(obj, "decode", rt.ToValue(decodeMethod)); err != nil { + panic(rt.NewGoError(fmt.Errorf("defining decode read-only property on TextDecoder object: %w", err))) + } + + // Set the encoding property + if err := setReadOnlyPropertyOf(obj, "encoding", rt.ToValue(string(td.Encoding))); err != nil { + panic(rt.NewGoError(fmt.Errorf("defining encoding read-only property on TextDecoder object: %w", err))) + } + + // Set the fatal property + if err := setReadOnlyPropertyOf(obj, "fatal", rt.ToValue(td.Fatal)); err != nil { + panic(rt.NewGoError(fmt.Errorf("defining fatal read-only property on TextDecoder object: %w", err))) + } + + // Set the ignoreBOM property + if err := setReadOnlyPropertyOf(obj, "ignoreBOM", rt.ToValue(td.IgnoreBOM)); err != nil { + panic(rt.NewGoError(fmt.Errorf("defining ignoreBOM read-only property on TextDecoder object: %w", err))) + } + + return obj +} + +func newTextEncoderObject(rt *sobek.Runtime, te *TextEncoder) *sobek.Object { + obj := rt.NewObject() + + // Wrap the Go TextEncoder.Encode method in a JS function + encodeMethod := func(value sobek.Value) *sobek.Object { + // Handle undefined/null values by defaulting to empty string + var text string + if isNullish(value) { + text = "" + } else { + text = value.String() + } + + buffer, err := te.Encode(text) + if err != nil { + throwAsJSError(rt, err) + } + + // Create a new Uint8Array from the buffer + u, err := rt.New(rt.Get("Uint8Array"), rt.ToValue(rt.NewArrayBuffer(buffer))) + if err != nil { + panic(rt.NewGoError(err)) + } + + return u + } + + // Set the encode property by wrapping the Go function in a JS function + if err := setReadOnlyPropertyOf(obj, "encode", rt.ToValue(encodeMethod)); err != nil { + panic(rt.NewGoError(fmt.Errorf("defining encode read-only method on TextEncoder object: %w", err))) + } + + // Set the encoding property + if err := setReadOnlyPropertyOf(obj, "encoding", rt.ToValue(string(te.Encoding))); err != nil { + panic(rt.NewGoError(fmt.Errorf("defining encoding read-only property on TextEncoder object: %w", err))) + } + + return obj +} + +func throwAsJSError(rt *sobek.Runtime, err error) { + var encErr *Error + if errors.As(err, &encErr) { + panic(encErr.JSError(rt)) + } + + panic(rt.NewGoError(err)) +} + +// setReadOnlyPropertyOf sets a read-only property on the given [sobek.Object]. +func setReadOnlyPropertyOf(obj *sobek.Object, name string, value sobek.Value) error { + err := obj.DefineDataProperty(name, + value, + sobek.FLAG_FALSE, + sobek.FLAG_FALSE, + sobek.FLAG_TRUE, + ) + if err != nil { + return fmt.Errorf("defining %s read-only property: %w", name, err) + } + + return nil +} + +// exportArrayBuffer interprets the given value as an ArrayBuffer, TypedArray or DataView +// and returns the underlying byte slice, backed by the original data (no copy is +// performed, per [sobek.Runtime.ExportTo]'s documented behavior for these types). +func exportArrayBuffer(rt *sobek.Runtime, v sobek.Value) ([]byte, error) { + if isNullish(v) { + return []byte{}, nil + } + + var data []byte + if err := rt.ExportTo(v, &data); err != nil { + return nil, errors.New("data is not an ArrayBuffer, typed array, or DataView") + } + + return data, nil +} + +func isNullish(v sobek.Value) bool { + return v == nil || sobek.IsUndefined(v) || sobek.IsNull(v) +} diff --git a/vendor/github.com/grafana/sobek-webapi-encoding/encoding/text_decoder.go b/vendor/github.com/grafana/sobek-webapi-encoding/encoding/text_decoder.go new file mode 100644 index 000000000..49ee5ca89 --- /dev/null +++ b/vendor/github.com/grafana/sobek-webapi-encoding/encoding/text_decoder.go @@ -0,0 +1,528 @@ +package encoding + +import ( + "errors" + "fmt" + "strings" + + "golang.org/x/text/encoding" + "golang.org/x/text/encoding/unicode" + "golang.org/x/text/transform" +) + +// TextDecoder represents a decoder for a specific text encoding, such +// as UTF-8, UTF-16LE, or UTF-16BE. +// +// A decoder takes a stream of bytes as input and emits a stream of code points. +// +// See https://encoding.spec.whatwg.org/#textdecoder +type TextDecoder struct { + TextDecoderCommon + + decoder encoding.Encoding + transform transform.Transformer + + buffer []byte +} + +// TextDecoderOptions represents the options that can be passed to the +// TextDecoder constructor. +type TextDecoderOptions struct { + // Fatal holds a boolean value indicating if the TextDecoder.decode() + // method must throw a TypeError when decoding invalid data. + // + // It defaults to false, which means that the decoder will substitute + // malformed data with a replacement character (U+FFFD). + Fatal bool `json:"fatal" js:"fatal"` + + // IgnoreBOM holds a boolean value indicating whether the byte order + // mark (BOM) is ignored. + IgnoreBOM bool `json:"ignoreBOM" js:"ignoreBOM"` +} + +// TextDecoderCommon represents the common subset of the TextDecoder interface +// that is shared between the TextDecoder and TextDecoderStream interfaces. +// +// See https://encoding.spec.whatwg.org/#textdecodercommon +type TextDecoderCommon struct { + // Encoding holds the name of the decoder, which is a string describing + // the method the TextDecoder will use. + Encoding Name `json:"encoding"` + + // Fatal holds a boolean value indicating if the TextDecoder.decode() + // method must throw a TypeError when decoding invalid data. + // + // It defaults to false, which means that the decoder will substitute + // malformed data with a replacement character (U+FFFD). + Fatal bool `json:"fatal"` + + // IgnoreBOM holds a boolean value indicating whether the byte order + // mark (BOM) is ignored. + IgnoreBOM bool `json:"ignoreBOM"` +} + +// NewTextDecoder returns a new TextDecoder object instance that will +// generate a string from a byte stream with a specific encoding. +// +// Implementation follows the WHATWG Encoding spec: +// https://encoding.spec.whatwg.org/#dom-textdecoder +func NewTextDecoder(label string, options TextDecoderOptions) (*TextDecoder, error) { + // Pick the encoding BOM policy accordingly + bomPolicy := unicode.IgnoreBOM + if !options.IgnoreBOM { + bomPolicy = unicode.UseBOM + } + + // Step 1: Let encoding be the result of getting an encoding from label. + var enc Name + var decoder encoding.Encoding + // Trim ASCII whitespace only (TAB, LF, FF, CR, SPACE); it's narrower than + // Unicode whitespace, which get-an-encoding's label trimming step needs. + switch strings.Trim(strings.ToLower(label), "\t\n\f\r ") { + case "", + "unicode-1-1-utf-8", + "unicode11utf8", + "unicode20utf8", + "utf-8", + "utf8", + "x-unicode20utf8": + enc = UTF8EncodingFormat + decoder = unicode.UTF8 + case "csunicode", + "iso-10646-ucs-2", + "ucs-2", + "unicode", + "unicodefeff", + "utf-16", + "utf-16le": + enc = UTF16LEEncodingFormat + decoder = unicode.UTF16(unicode.LittleEndian, bomPolicy) + case "unicodefffe", "utf-16be": + enc = UTF16BEEncodingFormat + decoder = unicode.UTF16(unicode.BigEndian, bomPolicy) + default: + // Step 2: If encoding is failure or replacement, throw a RangeError. + return nil, NewError(RangeError, fmt.Sprintf("unsupported encoding: %s", label)) + } + + // Step 3: Set this's encoding to encoding. + td := &TextDecoder{} + td.Encoding = enc + td.decoder = decoder + + // Step 4: If options["fatal"] is true, set this's error mode to "fatal". + if options.Fatal { + td.Fatal = true + } + + // Step 5: Set this's ignore BOM to options["ignoreBOM"]. + td.IgnoreBOM = options.IgnoreBOM + + return td, nil +} + +// appendReplacementCharUTF8 appends the UTF-8 encoded form of U+FFFD. +func appendReplacementCharUTF8(dst []byte) []byte { + return append(dst, 0xEF, 0xBF, 0xBD) +} + +const ( + // utf8MaxBytesPerCodePoint is the max expansion factor for UTF-8 decoding. + utf8MaxBytesPerCodePoint = 4 + // minTransformBufferSize is the minimum buffer used for streaming transforms. + minTransformBufferSize = 64 +) + +// Decode takes a byte stream as input and returns a string. +func (td *TextDecoder) Decode(buffer []byte, options TextDecodeOptions) (string, error) { + if td.decoder == nil { + return "", errors.New("encoding not set") + } + + if td.Encoding == UTF8EncodingFormat { + return td.decodeUTF8(buffer, options) + } + + return td.decodeUTF16(buffer, options) +} + +func (td *TextDecoder) decodeUTF8(buffer []byte, options TextDecodeOptions) (string, error) { + stream := options.Stream + + if td.transform == nil { + decoder := td.decoder.NewDecoder() + if !td.IgnoreBOM { + td.transform = unicode.BOMOverride(decoder) + } else { + td.transform = decoder + } + } + + combined := append(append([]byte{}, td.buffer...), buffer...) + td.buffer = td.buffer[:0] + + processed, leftover, hadInvalid := sanitizeUTF8Bytes(combined, stream) + if len(leftover) > 0 { + td.buffer = append(td.buffer, leftover...) + } + + atEOF := !stream + if stream && len(td.buffer) == 0 { + atEOF = true + } + + decoded, _, err := td.applyTransform(processed, atEOF) + if err != nil && !errors.Is(err, transform.ErrShortDst) && !errors.Is(err, transform.ErrShortSrc) { + if td.Fatal { + td.resetState() + return "", NewError(TypeError, "decoding text: "+err.Error()) + } + return "", err + } + + if td.Fatal && hadInvalid { + td.resetState() + return "", NewError(TypeError, "decoding text: invalid byte sequence") + } + + if !stream { + td.resetState() + } + + return decoded, nil +} + +func (td *TextDecoder) decodeUTF16(buffer []byte, options TextDecodeOptions) (string, error) { + stream := options.Stream + + if td.transform == nil { + td.transform = td.decoder.NewDecoder() + } + + // Keep td.buffer as the canonical byte queue so sequences that span multiple + // calls (e.g., surrogate pairs) remain intact until the transformer consumes + // them. + td.buffer = append(td.buffer, buffer...) + + processLen := len(td.buffer) + var pending []byte + + if stream { + if processLen%2 == 1 { + processLen-- + } + } else if processLen%2 == 1 { + pending = append(pending, td.buffer[processLen-1]) + processLen-- + } + + var decoded string + var err error + var consumed int + var hadInvalid bool + + if processLen > 0 { + toDecode := td.buffer[:processLen] + decoded, consumed, err = td.applyTransform(toDecode, !stream) + if consumed > 0 { + hadInvalid = hasInvalidUTF16Surrogate(toDecode[:consumed], td.Encoding == UTF16BEEncodingFormat) + } + td.buffer = append(td.buffer[:0], td.buffer[consumed:]...) + } else { + decoded, _, err = td.applyTransform(nil, !stream) + } + if err != nil && !errors.Is(err, transform.ErrShortDst) && !errors.Is(err, transform.ErrShortSrc) { + if td.Fatal { + td.resetState() + return "", NewError(TypeError, "decoding text: "+err.Error()) + } + return "", err + } + + var builder strings.Builder + builder.WriteString(decoded) + + if len(pending) > 0 { + if td.Fatal { + td.resetState() + return "", NewError(TypeError, "decoding text: invalid byte sequence") + } + builder.WriteRune('\uFFFD') + } + + result := builder.String() + + if td.Fatal && hadInvalid { + td.resetState() + return "", NewError(TypeError, "decoding text: invalid byte sequence") + } + + if !stream { + td.resetState() + } + + return result, nil +} + +// hasInvalidUTF16Surrogate reports whether data (a sequence of 2-byte code +// units in the given endianness) contains a lone/unpaired UTF-16 surrogate. +// +// The x/text UTF-16 decoder substitutes such sequences with U+FFFD without +// surfacing an error, so this scans the source bytes directly rather than +// inferring invalidity from the decoded output (which cannot distinguish a +// substitution from a legitimately-encoded U+FFFD character). +func hasInvalidUTF16Surrogate(data []byte, bigEndian bool) bool { + for i := 0; i+1 < len(data); i += 2 { + unit := decodeUTF16CodeUnit(data[i], data[i+1], bigEndian) + + switch { + case isUTF16HighSurrogate(unit): + if i+3 >= len(data) { + return true + } + + next := decodeUTF16CodeUnit(data[i+2], data[i+3], bigEndian) + if !isUTF16LowSurrogate(next) { + return true + } + + i += 2 + case isUTF16LowSurrogate(unit): + return true + } + } + + return false +} + +func decodeUTF16CodeUnit(b0, b1 byte, bigEndian bool) uint16 { + if bigEndian { + return uint16(b0)<<8 | uint16(b1) + } + return uint16(b1)<<8 | uint16(b0) +} + +func isUTF16HighSurrogate(u uint16) bool { + return u >= 0xD800 && u <= 0xDBFF +} + +func isUTF16LowSurrogate(u uint16) bool { + return u >= 0xDC00 && u <= 0xDFFF +} + +// applyTransform applies the decoder's transformer to the input bytes and returns +// the decoded string along with the number of bytes consumed. +// +// The atEOF parameter indicates whether this is the final chunk of input. When true, +// the transformer will flush any pending state and report errors for incomplete sequences. +// The function handles transform.ErrShortDst by growing the destination buffer as needed. +func (td *TextDecoder) applyTransform(input []byte, atEOF bool) (string, int, error) { + if td.transform == nil { + return "", 0, errors.New("transformer not initialized") + } + + if len(input) == 0 { + if atEOF { + empty := make([]byte, 0) + if _, _, err := td.transform.Transform(empty, empty, true); err != nil && + !errors.Is(err, transform.ErrShortDst) && + !errors.Is(err, transform.ErrShortSrc) { + return "", 0, err + } + } + return "", 0, nil + } + + destSize := max(len(input)*utf8MaxBytesPerCodePoint+minTransformBufferSize, minTransformBufferSize) + dest := make([]byte, destSize) + + var ( + builder strings.Builder + src = input + consumed int + ) + + for len(src) > 0 { + nDst, nSrc, err := td.transform.Transform(dest, src, atEOF) + builder.Write(dest[:nDst]) + src = src[nSrc:] + consumed += nSrc + + if err == nil { + continue + } + + if errors.Is(err, transform.ErrShortDst) { + if nSrc == 0 { + dest = make([]byte, len(dest)*2) + } + continue + } + + if errors.Is(err, transform.ErrShortSrc) && !atEOF { + break + } + + if !errors.Is(err, transform.ErrShortSrc) && !errors.Is(err, transform.ErrShortDst) { + return "", consumed, err + } + } + + return builder.String(), consumed, nil +} + +func (td *TextDecoder) resetState() { + if td.transform != nil { + td.transform.Reset() + td.transform = nil + } + td.buffer = nil +} + +// sanitizeUTF8Bytes validates and processes UTF-8 byte sequences, handling +// incomplete and invalid sequences according to the WHATWG Encoding spec. +// +// It returns: +// - processed: valid UTF-8 bytes with invalid sequences replaced by U+FFFD +// - leftover: incomplete trailing bytes (only when stream=true) +// - hadInvalid: true if any invalid sequences were encountered +// +// When stream is true, incomplete multi-byte sequences at the end of the input +// are preserved in leftover for the next chunk. When stream is false (final chunk), +// incomplete sequences are replaced with U+FFFD. +// +// This function implements the "replacement" error mode behavior where malformed +// byte sequences are replaced with the Unicode replacement character (U+FFFD). +// +// This duplicates validation logic golang.org/x/text/encoding/unicode's own +// UTF-8 decoder already contains, but that decoder's Transform cannot be used +// here directly: when it is short on source bytes and atEOF is false, it +// always waits for more data via transform.ErrShortSrc, even if the bytes +// already available prove the sequence malformed (e.g. a lead byte followed +// by a byte outside the valid continuation range). It only resolves such a +// sequence once atEOF is true. The WHATWG spec instead requires detecting an +// invalid continuation byte as soon as it is seen, independent of whether the +// caller is still streaming (see TestTextDecoderUTF8StreamingStateMachine's +// IncompleteThenInvalidContinuation case). Hence this package needs its own +// incremental scan rather than delegating to the transform's error signal. +func sanitizeUTF8Bytes(data []byte, stream bool) (processed []byte, leftover []byte, hadInvalid bool) { + if len(data) == 0 { + return nil, nil, false + } + + processed = make([]byte, 0, len(data)) + + for i := 0; i < len(data); { + b := data[i] + + if b < 0x80 { + processed = append(processed, b) + i++ + continue + } + + var needed int + switch { + case b >= 0xC2 && b <= 0xDF: + needed = 2 + case b >= 0xE0 && b <= 0xEF: + needed = 3 + case b >= 0xF0 && b <= 0xF4: + needed = 4 + default: + hadInvalid = true + processed = appendReplacementCharUTF8(processed) + i++ + continue + } + + validCount := 0 + incomplete := false + invalidSeq := false + for j := 1; j < needed; j++ { + idx := i + j + if idx >= len(data) { + if stream { + leftover = append([]byte{}, data[i:]...) + return processed, leftover, hadInvalid + } + incomplete = true + break + } + + cb := data[idx] + if !isValidContinuationByte(cb) || !passesUTF8RangeChecks(b, j, cb) { + invalidSeq = true + break + } + validCount++ + } + + if invalidSeq { + hadInvalid = true + processed = appendReplacementCharUTF8(processed) + i += 1 + validCount + continue + } + + if incomplete { + hadInvalid = true + processed = appendReplacementCharUTF8(processed) + i += 1 + validCount + continue + } + + processed = append(processed, data[i:i+needed]...) + i += needed + continue + } + + return processed, leftover, hadInvalid +} + +// isValidContinuationByte checks if a byte is a valid UTF-8 continuation byte. +// Continuation bytes have the bit pattern 10xxxxxx (0x80-0xBF). +func isValidContinuationByte(b byte) bool { + return b&0xC0 == 0x80 +} + +// passesUTF8RangeChecks validates that continuation bytes fall within valid ranges +// for specific UTF-8 start bytes. This rejects overlong encodings and surrogate pairs. +// +// The checks are: +// - 0xE0: First continuation must be >= 0xA0 (rejects overlong 2-byte forms of U+0000-U+07FF) +// - 0xED: First continuation must be <= 0x9F (rejects surrogate pairs U+D800-U+DFFF) +// - 0xF0: First continuation must be >= 0x90 (rejects overlong 3-byte forms of U+0000-U+FFFF) +// - 0xF4: First continuation must be <= 0x8F (rejects code points > U+10FFFF) +func passesUTF8RangeChecks(start byte, position int, cont byte) bool { + switch start { + case 0xE0: + if position == 1 { + return cont >= 0xA0 && cont <= 0xBF + } + case 0xED: + if position == 1 { + return cont >= 0x80 && cont <= 0x9F + } + case 0xF0: + if position == 1 { + return cont >= 0x90 && cont <= 0xBF + } + case 0xF4: + if position == 1 { + return cont >= 0x80 && cont <= 0x8F + } + } + return true +} + +// TextDecodeOptions represents the options that can be passed to the +// TextDecoder.decode() method. +type TextDecodeOptions struct { + // A boolean flag indicating whether additional data + // will follow in subsequent calls to decode(). + // + // Set to true if processing the data in chunks, and + // false for the final chunk or if the data is not chunked. + Stream bool `json:"stream" js:"stream"` +} diff --git a/vendor/github.com/grafana/sobek-webapi-encoding/encoding/text_encoder.go b/vendor/github.com/grafana/sobek-webapi-encoding/encoding/text_encoder.go new file mode 100644 index 000000000..32487754c --- /dev/null +++ b/vendor/github.com/grafana/sobek-webapi-encoding/encoding/text_encoder.go @@ -0,0 +1,44 @@ +package encoding + +import ( + "errors" + + "golang.org/x/text/encoding" + "golang.org/x/text/encoding/unicode" +) + +// TextEncoder represents an encoder that will generate a byte stream +// with UTF-8 encoding. +// +// See https://encoding.spec.whatwg.org/#textencoder +type TextEncoder struct { + // Encoding holds the encoding format name, which is always "utf-8" + // as per the WHATWG Encoding spec. + Encoding Name + + encoder encoding.Encoding +} + +// NewTextEncoder returns a new TextEncoder object instance that will +// generate a byte stream with UTF-8 encoding. +func NewTextEncoder() *TextEncoder { + return &TextEncoder{ + encoder: unicode.UTF8, + Encoding: UTF8EncodingFormat, + } +} + +// Encode takes a string as input and returns an encoded byte stream. +func (te *TextEncoder) Encode(text string) ([]byte, error) { + if te.encoder == nil { + return nil, errors.New("encoding not set") + } + + enc := te.encoder.NewEncoder() + encoded, err := enc.String(text) + if err != nil { + return nil, NewError(TypeError, "encoding text: "+err.Error()) + } + + return []byte(encoded), nil +} diff --git a/vendor/github.com/grafana/sobek-webapi-encoding/encoding/types.go b/vendor/github.com/grafana/sobek-webapi-encoding/encoding/types.go new file mode 100644 index 000000000..fc12d81b6 --- /dev/null +++ b/vendor/github.com/grafana/sobek-webapi-encoding/encoding/types.go @@ -0,0 +1,16 @@ +package encoding + +// Name is the identifier of an encoding format as defined by the WHATWG Encoding spec. +// See https://encoding.spec.whatwg.org/#names-and-labels +type Name string + +const ( + // UTF8EncodingFormat is the encoding format for UTF-8. + UTF8EncodingFormat Name = "utf-8" + + // UTF16LEEncodingFormat is the encoding format for UTF-16LE (little-endian). + UTF16LEEncodingFormat Name = "utf-16le" + + // UTF16BEEncodingFormat is the encoding format for UTF-16BE (big-endian). + UTF16BEEncodingFormat Name = "utf-16be" +) diff --git a/vendor/github.com/grafana/sobek-webapi-encoding/register.go b/vendor/github.com/grafana/sobek-webapi-encoding/register.go new file mode 100644 index 000000000..3c3f2dfff --- /dev/null +++ b/vendor/github.com/grafana/sobek-webapi-encoding/register.go @@ -0,0 +1,17 @@ +// Package sobekencoding registers the encoding Web API with Sobek runtimes. +package sobekencoding + +import ( + "github.com/grafana/sobek" + + "github.com/grafana/sobek-webapi-encoding/encoding" +) + +// RegisterGlobally exposes the encoding TextDecoder/TextEncoder constructors in the provided sobek runtime. +// +// See [encoding.RegisterRuntime] for a required caveat about rt's field name +// mapper: without one configured to resolve the option structs' "js" or +// "json" tags, TextDecoder options such as "fatal" are silently ignored. +func RegisterGlobally(rt *sobek.Runtime) error { + return encoding.RegisterRuntime(rt) +} diff --git a/vendor/golang.org/x/text/encoding/encoding.go b/vendor/golang.org/x/text/encoding/encoding.go new file mode 100644 index 000000000..a0bd7cd4d --- /dev/null +++ b/vendor/golang.org/x/text/encoding/encoding.go @@ -0,0 +1,335 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package encoding defines an interface for character encodings, such as Shift +// JIS and Windows 1252, that can convert to and from UTF-8. +// +// Encoding implementations are provided in other packages, such as +// golang.org/x/text/encoding/charmap and +// golang.org/x/text/encoding/japanese. +package encoding // import "golang.org/x/text/encoding" + +import ( + "errors" + "io" + "strconv" + "unicode/utf8" + + "golang.org/x/text/encoding/internal/identifier" + "golang.org/x/text/transform" +) + +// TODO: +// - There seems to be some inconsistency in when decoders return errors +// and when not. Also documentation seems to suggest they shouldn't return +// errors at all (except for UTF-16). +// - Encoders seem to rely on or at least benefit from the input being in NFC +// normal form. Perhaps add an example how users could prepare their output. + +// Encoding is a character set encoding that can be transformed to and from +// UTF-8. +type Encoding interface { + // NewDecoder returns a Decoder. + NewDecoder() *Decoder + + // NewEncoder returns an Encoder. + NewEncoder() *Encoder +} + +// A Decoder converts bytes to UTF-8. It implements transform.Transformer. +// +// Transforming source bytes that are not of that encoding will not result in an +// error per se. Each byte that cannot be transcoded will be represented in the +// output by the UTF-8 encoding of '\uFFFD', the replacement rune. +type Decoder struct { + transform.Transformer + + // This forces external creators of Decoders to use names in struct + // initializers, allowing for future extendibility without having to break + // code. + _ struct{} +} + +// Bytes converts the given encoded bytes to UTF-8. It returns the converted +// bytes or nil, err if any error occurred. +func (d *Decoder) Bytes(b []byte) ([]byte, error) { + b, _, err := transform.Bytes(d, b) + if err != nil { + return nil, err + } + return b, nil +} + +// String converts the given encoded string to UTF-8. It returns the converted +// string or "", err if any error occurred. +func (d *Decoder) String(s string) (string, error) { + s, _, err := transform.String(d, s) + if err != nil { + return "", err + } + return s, nil +} + +// Reader wraps another Reader to decode its bytes. +// +// The Decoder may not be used for any other operation as long as the returned +// Reader is in use. +func (d *Decoder) Reader(r io.Reader) io.Reader { + return transform.NewReader(r, d) +} + +// An Encoder converts bytes from UTF-8. It implements transform.Transformer. +// +// Each rune that cannot be transcoded will result in an error. In this case, +// the transform will consume all source byte up to, not including the offending +// rune. Transforming source bytes that are not valid UTF-8 will be replaced by +// `\uFFFD`. To return early with an error instead, use transform.Chain to +// preprocess the data with a UTF8Validator. +type Encoder struct { + transform.Transformer + + // This forces external creators of Encoders to use names in struct + // initializers, allowing for future extendibility without having to break + // code. + _ struct{} +} + +// Bytes converts bytes from UTF-8. It returns the converted bytes or nil, err if +// any error occurred. +func (e *Encoder) Bytes(b []byte) ([]byte, error) { + b, _, err := transform.Bytes(e, b) + if err != nil { + return nil, err + } + return b, nil +} + +// String converts a string from UTF-8. It returns the converted string or +// "", err if any error occurred. +func (e *Encoder) String(s string) (string, error) { + s, _, err := transform.String(e, s) + if err != nil { + return "", err + } + return s, nil +} + +// Writer wraps another Writer to encode its UTF-8 output. +// +// The Encoder may not be used for any other operation as long as the returned +// Writer is in use. +func (e *Encoder) Writer(w io.Writer) io.Writer { + return transform.NewWriter(w, e) +} + +// ASCIISub is the ASCII substitute character, as recommended by +// https://unicode.org/reports/tr36/#Text_Comparison +const ASCIISub = '\x1a' + +// Nop is the nop encoding. Its transformed bytes are the same as the source +// bytes; it does not replace invalid UTF-8 sequences. +var Nop Encoding = nop{} + +type nop struct{} + +func (nop) NewDecoder() *Decoder { + return &Decoder{Transformer: transform.Nop} +} +func (nop) NewEncoder() *Encoder { + return &Encoder{Transformer: transform.Nop} +} + +// Replacement is the replacement encoding. Decoding from the replacement +// encoding yields a single '\uFFFD' replacement rune. Encoding from UTF-8 to +// the replacement encoding yields the same as the source bytes except that +// invalid UTF-8 is converted to '\uFFFD'. +// +// It is defined at http://encoding.spec.whatwg.org/#replacement +var Replacement Encoding = replacement{} + +type replacement struct{} + +func (replacement) NewDecoder() *Decoder { + return &Decoder{Transformer: replacementDecoder{}} +} + +func (replacement) NewEncoder() *Encoder { + return &Encoder{Transformer: replacementEncoder{}} +} + +func (replacement) ID() (mib identifier.MIB, other string) { + return identifier.Replacement, "" +} + +type replacementDecoder struct{ transform.NopResetter } + +func (replacementDecoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) { + if len(dst) < 3 { + return 0, 0, transform.ErrShortDst + } + if atEOF { + const fffd = "\ufffd" + dst[0] = fffd[0] + dst[1] = fffd[1] + dst[2] = fffd[2] + nDst = 3 + } + return nDst, len(src), nil +} + +type replacementEncoder struct{ transform.NopResetter } + +func (replacementEncoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) { + r, size := rune(0), 0 + + for ; nSrc < len(src); nSrc += size { + r = rune(src[nSrc]) + + // Decode a 1-byte rune. + if r < utf8.RuneSelf { + size = 1 + + } else { + // Decode a multi-byte rune. + r, size = utf8.DecodeRune(src[nSrc:]) + if size == 1 { + // All valid runes of size 1 (those below utf8.RuneSelf) were + // handled above. We have invalid UTF-8 or we haven't seen the + // full character yet. + if !atEOF && !utf8.FullRune(src[nSrc:]) { + err = transform.ErrShortSrc + break + } + r = '\ufffd' + } + } + + if nDst+utf8.RuneLen(r) > len(dst) { + err = transform.ErrShortDst + break + } + nDst += utf8.EncodeRune(dst[nDst:], r) + } + return nDst, nSrc, err +} + +// HTMLEscapeUnsupported wraps encoders to replace source runes outside the +// repertoire of the destination encoding with HTML escape sequences. +// +// This wrapper exists to comply to URL and HTML forms requiring a +// non-terminating legacy encoder. The produced sequences may lead to data +// loss as they are indistinguishable from legitimate input. To avoid this +// issue, use UTF-8 encodings whenever possible. +func HTMLEscapeUnsupported(e *Encoder) *Encoder { + return &Encoder{Transformer: &errorHandler{e, errorToHTML}} +} + +// ReplaceUnsupported wraps encoders to replace source runes outside the +// repertoire of the destination encoding with an encoding-specific +// replacement. +// +// This wrapper is only provided for backwards compatibility and legacy +// handling. Its use is strongly discouraged. Use UTF-8 whenever possible. +func ReplaceUnsupported(e *Encoder) *Encoder { + return &Encoder{Transformer: &errorHandler{e, errorToReplacement}} +} + +type errorHandler struct { + *Encoder + handler func(dst []byte, r rune, err repertoireError) (n int, ok bool) +} + +// TODO: consider making this error public in some form. +type repertoireError interface { + Replacement() byte +} + +func (h errorHandler) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) { + nDst, nSrc, err = h.Transformer.Transform(dst, src, atEOF) + for err != nil { + rerr, ok := err.(repertoireError) + if !ok { + return nDst, nSrc, err + } + r, sz := utf8.DecodeRune(src[nSrc:]) + n, ok := h.handler(dst[nDst:], r, rerr) + if !ok { + return nDst, nSrc, transform.ErrShortDst + } + err = nil + nDst += n + if nSrc += sz; nSrc < len(src) { + var dn, sn int + dn, sn, err = h.Transformer.Transform(dst[nDst:], src[nSrc:], atEOF) + nDst += dn + nSrc += sn + } + } + return nDst, nSrc, err +} + +func errorToHTML(dst []byte, r rune, err repertoireError) (n int, ok bool) { + buf := [8]byte{} + b := strconv.AppendUint(buf[:0], uint64(r), 10) + if n = len(b) + len("&#;"); n >= len(dst) { + return 0, false + } + dst[0] = '&' + dst[1] = '#' + dst[copy(dst[2:], b)+2] = ';' + return n, true +} + +func errorToReplacement(dst []byte, r rune, err repertoireError) (n int, ok bool) { + if len(dst) == 0 { + return 0, false + } + dst[0] = err.Replacement() + return 1, true +} + +// ErrInvalidUTF8 means that a transformer encountered invalid UTF-8. +var ErrInvalidUTF8 = errors.New("encoding: invalid UTF-8") + +// UTF8Validator is a transformer that returns ErrInvalidUTF8 on the first +// input byte that is not valid UTF-8. +var UTF8Validator transform.Transformer = utf8Validator{} + +type utf8Validator struct{ transform.NopResetter } + +func (utf8Validator) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) { + n := len(src) + if n > len(dst) { + n = len(dst) + } + for i := 0; i < n; { + if c := src[i]; c < utf8.RuneSelf { + dst[i] = c + i++ + continue + } + _, size := utf8.DecodeRune(src[i:]) + if size == 1 { + // All valid runes of size 1 (those below utf8.RuneSelf) were + // handled above. We have invalid UTF-8 or we haven't seen the + // full character yet. + err = ErrInvalidUTF8 + if !atEOF && !utf8.FullRune(src[i:]) { + err = transform.ErrShortSrc + } + return i, i, err + } + if i+size > len(dst) { + return i, i, transform.ErrShortDst + } + for ; size > 0; size-- { + dst[i] = src[i] + i++ + } + } + if len(src) > len(dst) { + err = transform.ErrShortDst + } + return n, n, err +} diff --git a/vendor/golang.org/x/text/encoding/internal/identifier/identifier.go b/vendor/golang.org/x/text/encoding/internal/identifier/identifier.go new file mode 100644 index 000000000..5c9b85c28 --- /dev/null +++ b/vendor/golang.org/x/text/encoding/internal/identifier/identifier.go @@ -0,0 +1,81 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:generate go run gen.go + +// Package identifier defines the contract between implementations of Encoding +// and Index by defining identifiers that uniquely identify standardized coded +// character sets (CCS) and character encoding schemes (CES), which we will +// together refer to as encodings, for which Encoding implementations provide +// converters to and from UTF-8. This package is typically only of concern to +// implementers of Indexes and Encodings. +// +// One part of the identifier is the MIB code, which is defined by IANA and +// uniquely identifies a CCS or CES. Each code is associated with data that +// references authorities, official documentation as well as aliases and MIME +// names. +// +// Not all CESs are covered by the IANA registry. The "other" string that is +// returned by ID can be used to identify other character sets or versions of +// existing ones. +// +// It is recommended that each package that provides a set of Encodings provide +// the All and Common variables to reference all supported encodings and +// commonly used subset. This allows Index implementations to include all +// available encodings without explicitly referencing or knowing about them. +package identifier + +// Note: this package is internal, but could be made public if there is a need +// for writing third-party Indexes and Encodings. + +// References: +// - http://source.icu-project.org/repos/icu/icu/trunk/source/data/mappings/convrtrs.txt +// - http://www.iana.org/assignments/character-sets/character-sets.xhtml +// - http://www.iana.org/assignments/ianacharset-mib/ianacharset-mib +// - http://www.ietf.org/rfc/rfc2978.txt +// - https://www.unicode.org/reports/tr22/ +// - http://www.w3.org/TR/encoding/ +// - https://encoding.spec.whatwg.org/ +// - https://encoding.spec.whatwg.org/encodings.json +// - https://tools.ietf.org/html/rfc6657#section-5 + +// Interface can be implemented by Encodings to define the CCS or CES for which +// it implements conversions. +type Interface interface { + // ID returns an encoding identifier. Exactly one of the mib and other + // values should be non-zero. + // + // In the usual case it is only necessary to indicate the MIB code. The + // other string can be used to specify encodings for which there is no MIB, + // such as "x-mac-dingbat". + // + // The other string may only contain the characters a-z, A-Z, 0-9, - and _. + ID() (mib MIB, other string) + + // NOTE: the restrictions on the encoding are to allow extending the syntax + // with additional information such as versions, vendors and other variants. +} + +// A MIB identifies an encoding. It is derived from the IANA MIB codes and adds +// some identifiers for some encodings that are not covered by the IANA +// standard. +// +// See http://www.iana.org/assignments/ianacharset-mib. +type MIB uint16 + +// These additional MIB types are not defined in IANA. They are added because +// they are common and defined within the text repo. +const ( + // Unofficial marks the start of encodings not registered by IANA. + Unofficial MIB = 10000 + iota + + // Replacement is the WhatWG replacement encoding. + Replacement + + // XUserDefined is the code for x-user-defined. + XUserDefined + + // MacintoshCyrillic is the code for x-mac-cyrillic. + MacintoshCyrillic +) diff --git a/vendor/golang.org/x/text/encoding/internal/identifier/mib.go b/vendor/golang.org/x/text/encoding/internal/identifier/mib.go new file mode 100644 index 000000000..351fb86e2 --- /dev/null +++ b/vendor/golang.org/x/text/encoding/internal/identifier/mib.go @@ -0,0 +1,1627 @@ +// Code generated by running "go generate" in golang.org/x/text. DO NOT EDIT. + +package identifier + +const ( + // ASCII is the MIB identifier with IANA name US-ASCII (MIME: US-ASCII). + // + // ANSI X3.4-1986 + // Reference: RFC2046 + ASCII MIB = 3 + + // ISOLatin1 is the MIB identifier with IANA name ISO_8859-1:1987 (MIME: ISO-8859-1). + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISOLatin1 MIB = 4 + + // ISOLatin2 is the MIB identifier with IANA name ISO_8859-2:1987 (MIME: ISO-8859-2). + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISOLatin2 MIB = 5 + + // ISOLatin3 is the MIB identifier with IANA name ISO_8859-3:1988 (MIME: ISO-8859-3). + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISOLatin3 MIB = 6 + + // ISOLatin4 is the MIB identifier with IANA name ISO_8859-4:1988 (MIME: ISO-8859-4). + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISOLatin4 MIB = 7 + + // ISOLatinCyrillic is the MIB identifier with IANA name ISO_8859-5:1988 (MIME: ISO-8859-5). + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISOLatinCyrillic MIB = 8 + + // ISOLatinArabic is the MIB identifier with IANA name ISO_8859-6:1987 (MIME: ISO-8859-6). + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISOLatinArabic MIB = 9 + + // ISOLatinGreek is the MIB identifier with IANA name ISO_8859-7:1987 (MIME: ISO-8859-7). + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1947 + // Reference: RFC1345 + ISOLatinGreek MIB = 10 + + // ISOLatinHebrew is the MIB identifier with IANA name ISO_8859-8:1988 (MIME: ISO-8859-8). + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISOLatinHebrew MIB = 11 + + // ISOLatin5 is the MIB identifier with IANA name ISO_8859-9:1989 (MIME: ISO-8859-9). + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISOLatin5 MIB = 12 + + // ISOLatin6 is the MIB identifier with IANA name ISO-8859-10 (MIME: ISO-8859-10). + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISOLatin6 MIB = 13 + + // ISOTextComm is the MIB identifier with IANA name ISO_6937-2-add. + // + // ISO-IR: International Register of Escape Sequences and ISO 6937-2:1983 + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISOTextComm MIB = 14 + + // HalfWidthKatakana is the MIB identifier with IANA name JIS_X0201. + // + // JIS X 0201-1976. One byte only, this is equivalent to + // JIS/Roman (similar to ASCII) plus eight-bit half-width + // Katakana + // Reference: RFC1345 + HalfWidthKatakana MIB = 15 + + // JISEncoding is the MIB identifier with IANA name JIS_Encoding. + // + // JIS X 0202-1991. Uses ISO 2022 escape sequences to + // shift code sets as documented in JIS X 0202-1991. + JISEncoding MIB = 16 + + // ShiftJIS is the MIB identifier with IANA name Shift_JIS (MIME: Shift_JIS). + // + // This charset is an extension of csHalfWidthKatakana by + // adding graphic characters in JIS X 0208. The CCS's are + // JIS X0201:1997 and JIS X0208:1997. The + // complete definition is shown in Appendix 1 of JIS + // X0208:1997. + // This charset can be used for the top-level media type "text". + ShiftJIS MIB = 17 + + // EUCPkdFmtJapanese is the MIB identifier with IANA name Extended_UNIX_Code_Packed_Format_for_Japanese (MIME: EUC-JP). + // + // Standardized by OSF, UNIX International, and UNIX Systems + // Laboratories Pacific. Uses ISO 2022 rules to select + // code set 0: US-ASCII (a single 7-bit byte set) + // code set 1: JIS X0208-1990 (a double 8-bit byte set) + // restricted to A0-FF in both bytes + // code set 2: Half Width Katakana (a single 7-bit byte set) + // requiring SS2 as the character prefix + // code set 3: JIS X0212-1990 (a double 7-bit byte set) + // restricted to A0-FF in both bytes + // requiring SS3 as the character prefix + EUCPkdFmtJapanese MIB = 18 + + // EUCFixWidJapanese is the MIB identifier with IANA name Extended_UNIX_Code_Fixed_Width_for_Japanese. + // + // Used in Japan. Each character is 2 octets. + // code set 0: US-ASCII (a single 7-bit byte set) + // 1st byte = 00 + // 2nd byte = 20-7E + // code set 1: JIS X0208-1990 (a double 7-bit byte set) + // restricted to A0-FF in both bytes + // code set 2: Half Width Katakana (a single 7-bit byte set) + // 1st byte = 00 + // 2nd byte = A0-FF + // code set 3: JIS X0212-1990 (a double 7-bit byte set) + // restricted to A0-FF in + // the first byte + // and 21-7E in the second byte + EUCFixWidJapanese MIB = 19 + + // ISO4UnitedKingdom is the MIB identifier with IANA name BS_4730. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO4UnitedKingdom MIB = 20 + + // ISO11SwedishForNames is the MIB identifier with IANA name SEN_850200_C. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO11SwedishForNames MIB = 21 + + // ISO15Italian is the MIB identifier with IANA name IT. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO15Italian MIB = 22 + + // ISO17Spanish is the MIB identifier with IANA name ES. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO17Spanish MIB = 23 + + // ISO21German is the MIB identifier with IANA name DIN_66003. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO21German MIB = 24 + + // ISO60Norwegian1 is the MIB identifier with IANA name NS_4551-1. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO60Norwegian1 MIB = 25 + + // ISO69French is the MIB identifier with IANA name NF_Z_62-010. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO69French MIB = 26 + + // ISO10646UTF1 is the MIB identifier with IANA name ISO-10646-UTF-1. + // + // Universal Transfer Format (1), this is the multibyte + // encoding, that subsets ASCII-7. It does not have byte + // ordering issues. + ISO10646UTF1 MIB = 27 + + // ISO646basic1983 is the MIB identifier with IANA name ISO_646.basic:1983. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO646basic1983 MIB = 28 + + // INVARIANT is the MIB identifier with IANA name INVARIANT. + // + // Reference: RFC1345 + INVARIANT MIB = 29 + + // ISO2IntlRefVersion is the MIB identifier with IANA name ISO_646.irv:1983. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO2IntlRefVersion MIB = 30 + + // NATSSEFI is the MIB identifier with IANA name NATS-SEFI. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + NATSSEFI MIB = 31 + + // NATSSEFIADD is the MIB identifier with IANA name NATS-SEFI-ADD. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + NATSSEFIADD MIB = 32 + + // NATSDANO is the MIB identifier with IANA name NATS-DANO. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + NATSDANO MIB = 33 + + // NATSDANOADD is the MIB identifier with IANA name NATS-DANO-ADD. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + NATSDANOADD MIB = 34 + + // ISO10Swedish is the MIB identifier with IANA name SEN_850200_B. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO10Swedish MIB = 35 + + // KSC56011987 is the MIB identifier with IANA name KS_C_5601-1987. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + KSC56011987 MIB = 36 + + // ISO2022KR is the MIB identifier with IANA name ISO-2022-KR (MIME: ISO-2022-KR). + // + // rfc1557 (see also KS_C_5601-1987) + // Reference: RFC1557 + ISO2022KR MIB = 37 + + // EUCKR is the MIB identifier with IANA name EUC-KR (MIME: EUC-KR). + // + // rfc1557 (see also KS_C_5861-1992) + // Reference: RFC1557 + EUCKR MIB = 38 + + // ISO2022JP is the MIB identifier with IANA name ISO-2022-JP (MIME: ISO-2022-JP). + // + // rfc1468 (see also rfc2237 ) + // Reference: RFC1468 + ISO2022JP MIB = 39 + + // ISO2022JP2 is the MIB identifier with IANA name ISO-2022-JP-2 (MIME: ISO-2022-JP-2). + // + // rfc1554 + // Reference: RFC1554 + ISO2022JP2 MIB = 40 + + // ISO13JISC6220jp is the MIB identifier with IANA name JIS_C6220-1969-jp. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO13JISC6220jp MIB = 41 + + // ISO14JISC6220ro is the MIB identifier with IANA name JIS_C6220-1969-ro. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO14JISC6220ro MIB = 42 + + // ISO16Portuguese is the MIB identifier with IANA name PT. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO16Portuguese MIB = 43 + + // ISO18Greek7Old is the MIB identifier with IANA name greek7-old. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO18Greek7Old MIB = 44 + + // ISO19LatinGreek is the MIB identifier with IANA name latin-greek. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO19LatinGreek MIB = 45 + + // ISO25French is the MIB identifier with IANA name NF_Z_62-010_(1973). + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO25French MIB = 46 + + // ISO27LatinGreek1 is the MIB identifier with IANA name Latin-greek-1. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO27LatinGreek1 MIB = 47 + + // ISO5427Cyrillic is the MIB identifier with IANA name ISO_5427. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO5427Cyrillic MIB = 48 + + // ISO42JISC62261978 is the MIB identifier with IANA name JIS_C6226-1978. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO42JISC62261978 MIB = 49 + + // ISO47BSViewdata is the MIB identifier with IANA name BS_viewdata. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO47BSViewdata MIB = 50 + + // ISO49INIS is the MIB identifier with IANA name INIS. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO49INIS MIB = 51 + + // ISO50INIS8 is the MIB identifier with IANA name INIS-8. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO50INIS8 MIB = 52 + + // ISO51INISCyrillic is the MIB identifier with IANA name INIS-cyrillic. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO51INISCyrillic MIB = 53 + + // ISO54271981 is the MIB identifier with IANA name ISO_5427:1981. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO54271981 MIB = 54 + + // ISO5428Greek is the MIB identifier with IANA name ISO_5428:1980. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO5428Greek MIB = 55 + + // ISO57GB1988 is the MIB identifier with IANA name GB_1988-80. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO57GB1988 MIB = 56 + + // ISO58GB231280 is the MIB identifier with IANA name GB_2312-80. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO58GB231280 MIB = 57 + + // ISO61Norwegian2 is the MIB identifier with IANA name NS_4551-2. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO61Norwegian2 MIB = 58 + + // ISO70VideotexSupp1 is the MIB identifier with IANA name videotex-suppl. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO70VideotexSupp1 MIB = 59 + + // ISO84Portuguese2 is the MIB identifier with IANA name PT2. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO84Portuguese2 MIB = 60 + + // ISO85Spanish2 is the MIB identifier with IANA name ES2. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO85Spanish2 MIB = 61 + + // ISO86Hungarian is the MIB identifier with IANA name MSZ_7795.3. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO86Hungarian MIB = 62 + + // ISO87JISX0208 is the MIB identifier with IANA name JIS_C6226-1983. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO87JISX0208 MIB = 63 + + // ISO88Greek7 is the MIB identifier with IANA name greek7. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO88Greek7 MIB = 64 + + // ISO89ASMO449 is the MIB identifier with IANA name ASMO_449. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO89ASMO449 MIB = 65 + + // ISO90 is the MIB identifier with IANA name iso-ir-90. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO90 MIB = 66 + + // ISO91JISC62291984a is the MIB identifier with IANA name JIS_C6229-1984-a. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO91JISC62291984a MIB = 67 + + // ISO92JISC62991984b is the MIB identifier with IANA name JIS_C6229-1984-b. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO92JISC62991984b MIB = 68 + + // ISO93JIS62291984badd is the MIB identifier with IANA name JIS_C6229-1984-b-add. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO93JIS62291984badd MIB = 69 + + // ISO94JIS62291984hand is the MIB identifier with IANA name JIS_C6229-1984-hand. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO94JIS62291984hand MIB = 70 + + // ISO95JIS62291984handadd is the MIB identifier with IANA name JIS_C6229-1984-hand-add. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO95JIS62291984handadd MIB = 71 + + // ISO96JISC62291984kana is the MIB identifier with IANA name JIS_C6229-1984-kana. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO96JISC62291984kana MIB = 72 + + // ISO2033 is the MIB identifier with IANA name ISO_2033-1983. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO2033 MIB = 73 + + // ISO99NAPLPS is the MIB identifier with IANA name ANSI_X3.110-1983. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO99NAPLPS MIB = 74 + + // ISO102T617bit is the MIB identifier with IANA name T.61-7bit. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO102T617bit MIB = 75 + + // ISO103T618bit is the MIB identifier with IANA name T.61-8bit. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO103T618bit MIB = 76 + + // ISO111ECMACyrillic is the MIB identifier with IANA name ECMA-cyrillic. + // + // ISO registry + ISO111ECMACyrillic MIB = 77 + + // ISO121Canadian1 is the MIB identifier with IANA name CSA_Z243.4-1985-1. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO121Canadian1 MIB = 78 + + // ISO122Canadian2 is the MIB identifier with IANA name CSA_Z243.4-1985-2. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO122Canadian2 MIB = 79 + + // ISO123CSAZ24341985gr is the MIB identifier with IANA name CSA_Z243.4-1985-gr. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO123CSAZ24341985gr MIB = 80 + + // ISO88596E is the MIB identifier with IANA name ISO_8859-6-E (MIME: ISO-8859-6-E). + // + // rfc1556 + // Reference: RFC1556 + ISO88596E MIB = 81 + + // ISO88596I is the MIB identifier with IANA name ISO_8859-6-I (MIME: ISO-8859-6-I). + // + // rfc1556 + // Reference: RFC1556 + ISO88596I MIB = 82 + + // ISO128T101G2 is the MIB identifier with IANA name T.101-G2. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO128T101G2 MIB = 83 + + // ISO88598E is the MIB identifier with IANA name ISO_8859-8-E (MIME: ISO-8859-8-E). + // + // rfc1556 + // Reference: RFC1556 + ISO88598E MIB = 84 + + // ISO88598I is the MIB identifier with IANA name ISO_8859-8-I (MIME: ISO-8859-8-I). + // + // rfc1556 + // Reference: RFC1556 + ISO88598I MIB = 85 + + // ISO139CSN369103 is the MIB identifier with IANA name CSN_369103. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO139CSN369103 MIB = 86 + + // ISO141JUSIB1002 is the MIB identifier with IANA name JUS_I.B1.002. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO141JUSIB1002 MIB = 87 + + // ISO143IECP271 is the MIB identifier with IANA name IEC_P27-1. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO143IECP271 MIB = 88 + + // ISO146Serbian is the MIB identifier with IANA name JUS_I.B1.003-serb. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO146Serbian MIB = 89 + + // ISO147Macedonian is the MIB identifier with IANA name JUS_I.B1.003-mac. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO147Macedonian MIB = 90 + + // ISO150GreekCCITT is the MIB identifier with IANA name greek-ccitt. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO150GreekCCITT MIB = 91 + + // ISO151Cuba is the MIB identifier with IANA name NC_NC00-10:81. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO151Cuba MIB = 92 + + // ISO6937Add is the MIB identifier with IANA name ISO_6937-2-25. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO6937Add MIB = 93 + + // ISO153GOST1976874 is the MIB identifier with IANA name GOST_19768-74. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO153GOST1976874 MIB = 94 + + // ISO8859Supp is the MIB identifier with IANA name ISO_8859-supp. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO8859Supp MIB = 95 + + // ISO10367Box is the MIB identifier with IANA name ISO_10367-box. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO10367Box MIB = 96 + + // ISO158Lap is the MIB identifier with IANA name latin-lap. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO158Lap MIB = 97 + + // ISO159JISX02121990 is the MIB identifier with IANA name JIS_X0212-1990. + // + // ISO-IR: International Register of Escape Sequences + // Note: The current registration authority is IPSJ/ITSCJ, Japan. + // Reference: RFC1345 + ISO159JISX02121990 MIB = 98 + + // ISO646Danish is the MIB identifier with IANA name DS_2089. + // + // Danish Standard, DS 2089, February 1974 + // Reference: RFC1345 + ISO646Danish MIB = 99 + + // USDK is the MIB identifier with IANA name us-dk. + // + // Reference: RFC1345 + USDK MIB = 100 + + // DKUS is the MIB identifier with IANA name dk-us. + // + // Reference: RFC1345 + DKUS MIB = 101 + + // KSC5636 is the MIB identifier with IANA name KSC5636. + // + // Reference: RFC1345 + KSC5636 MIB = 102 + + // Unicode11UTF7 is the MIB identifier with IANA name UNICODE-1-1-UTF-7. + // + // rfc1642 + // Reference: RFC1642 + Unicode11UTF7 MIB = 103 + + // ISO2022CN is the MIB identifier with IANA name ISO-2022-CN. + // + // rfc1922 + // Reference: RFC1922 + ISO2022CN MIB = 104 + + // ISO2022CNEXT is the MIB identifier with IANA name ISO-2022-CN-EXT. + // + // rfc1922 + // Reference: RFC1922 + ISO2022CNEXT MIB = 105 + + // UTF8 is the MIB identifier with IANA name UTF-8. + // + // rfc3629 + // Reference: RFC3629 + UTF8 MIB = 106 + + // ISO885913 is the MIB identifier with IANA name ISO-8859-13. + // + // ISO See https://www.iana.org/assignments/charset-reg/ISO-8859-13 https://www.iana.org/assignments/charset-reg/ISO-8859-13 + ISO885913 MIB = 109 + + // ISO885914 is the MIB identifier with IANA name ISO-8859-14. + // + // ISO See https://www.iana.org/assignments/charset-reg/ISO-8859-14 + ISO885914 MIB = 110 + + // ISO885915 is the MIB identifier with IANA name ISO-8859-15. + // + // ISO + // Please see: https://www.iana.org/assignments/charset-reg/ISO-8859-15 + ISO885915 MIB = 111 + + // ISO885916 is the MIB identifier with IANA name ISO-8859-16. + // + // ISO + ISO885916 MIB = 112 + + // GBK is the MIB identifier with IANA name GBK. + // + // Chinese IT Standardization Technical Committee + // Please see: https://www.iana.org/assignments/charset-reg/GBK + GBK MIB = 113 + + // GB18030 is the MIB identifier with IANA name GB18030. + // + // Chinese IT Standardization Technical Committee + // Please see: https://www.iana.org/assignments/charset-reg/GB18030 + GB18030 MIB = 114 + + // OSDEBCDICDF0415 is the MIB identifier with IANA name OSD_EBCDIC_DF04_15. + // + // Fujitsu-Siemens standard mainframe EBCDIC encoding + // Please see: https://www.iana.org/assignments/charset-reg/OSD-EBCDIC-DF04-15 + OSDEBCDICDF0415 MIB = 115 + + // OSDEBCDICDF03IRV is the MIB identifier with IANA name OSD_EBCDIC_DF03_IRV. + // + // Fujitsu-Siemens standard mainframe EBCDIC encoding + // Please see: https://www.iana.org/assignments/charset-reg/OSD-EBCDIC-DF03-IRV + OSDEBCDICDF03IRV MIB = 116 + + // OSDEBCDICDF041 is the MIB identifier with IANA name OSD_EBCDIC_DF04_1. + // + // Fujitsu-Siemens standard mainframe EBCDIC encoding + // Please see: https://www.iana.org/assignments/charset-reg/OSD-EBCDIC-DF04-1 + OSDEBCDICDF041 MIB = 117 + + // ISO115481 is the MIB identifier with IANA name ISO-11548-1. + // + // See https://www.iana.org/assignments/charset-reg/ISO-11548-1 + ISO115481 MIB = 118 + + // KZ1048 is the MIB identifier with IANA name KZ-1048. + // + // See https://www.iana.org/assignments/charset-reg/KZ-1048 + KZ1048 MIB = 119 + + // Unicode is the MIB identifier with IANA name ISO-10646-UCS-2. + // + // the 2-octet Basic Multilingual Plane, aka Unicode + // this needs to specify network byte order: the standard + // does not specify (it is a 16-bit integer space) + Unicode MIB = 1000 + + // UCS4 is the MIB identifier with IANA name ISO-10646-UCS-4. + // + // the full code space. (same comment about byte order, + // these are 31-bit numbers. + UCS4 MIB = 1001 + + // UnicodeASCII is the MIB identifier with IANA name ISO-10646-UCS-Basic. + // + // ASCII subset of Unicode. Basic Latin = collection 1 + // See ISO 10646, Appendix A + UnicodeASCII MIB = 1002 + + // UnicodeLatin1 is the MIB identifier with IANA name ISO-10646-Unicode-Latin1. + // + // ISO Latin-1 subset of Unicode. Basic Latin and Latin-1 + // Supplement = collections 1 and 2. See ISO 10646, + // Appendix A. See rfc1815 . + UnicodeLatin1 MIB = 1003 + + // UnicodeJapanese is the MIB identifier with IANA name ISO-10646-J-1. + // + // ISO 10646 Japanese, see rfc1815 . + UnicodeJapanese MIB = 1004 + + // UnicodeIBM1261 is the MIB identifier with IANA name ISO-Unicode-IBM-1261. + // + // IBM Latin-2, -3, -5, Extended Presentation Set, GCSGID: 1261 + UnicodeIBM1261 MIB = 1005 + + // UnicodeIBM1268 is the MIB identifier with IANA name ISO-Unicode-IBM-1268. + // + // IBM Latin-4 Extended Presentation Set, GCSGID: 1268 + UnicodeIBM1268 MIB = 1006 + + // UnicodeIBM1276 is the MIB identifier with IANA name ISO-Unicode-IBM-1276. + // + // IBM Cyrillic Greek Extended Presentation Set, GCSGID: 1276 + UnicodeIBM1276 MIB = 1007 + + // UnicodeIBM1264 is the MIB identifier with IANA name ISO-Unicode-IBM-1264. + // + // IBM Arabic Presentation Set, GCSGID: 1264 + UnicodeIBM1264 MIB = 1008 + + // UnicodeIBM1265 is the MIB identifier with IANA name ISO-Unicode-IBM-1265. + // + // IBM Hebrew Presentation Set, GCSGID: 1265 + UnicodeIBM1265 MIB = 1009 + + // Unicode11 is the MIB identifier with IANA name UNICODE-1-1. + // + // rfc1641 + // Reference: RFC1641 + Unicode11 MIB = 1010 + + // SCSU is the MIB identifier with IANA name SCSU. + // + // SCSU See https://www.iana.org/assignments/charset-reg/SCSU + SCSU MIB = 1011 + + // UTF7 is the MIB identifier with IANA name UTF-7. + // + // rfc2152 + // Reference: RFC2152 + UTF7 MIB = 1012 + + // UTF16BE is the MIB identifier with IANA name UTF-16BE. + // + // rfc2781 + // Reference: RFC2781 + UTF16BE MIB = 1013 + + // UTF16LE is the MIB identifier with IANA name UTF-16LE. + // + // rfc2781 + // Reference: RFC2781 + UTF16LE MIB = 1014 + + // UTF16 is the MIB identifier with IANA name UTF-16. + // + // rfc2781 + // Reference: RFC2781 + UTF16 MIB = 1015 + + // CESU8 is the MIB identifier with IANA name CESU-8. + // + // https://www.unicode.org/reports/tr26 + CESU8 MIB = 1016 + + // UTF32 is the MIB identifier with IANA name UTF-32. + // + // https://www.unicode.org/reports/tr19/ + UTF32 MIB = 1017 + + // UTF32BE is the MIB identifier with IANA name UTF-32BE. + // + // https://www.unicode.org/reports/tr19/ + UTF32BE MIB = 1018 + + // UTF32LE is the MIB identifier with IANA name UTF-32LE. + // + // https://www.unicode.org/reports/tr19/ + UTF32LE MIB = 1019 + + // BOCU1 is the MIB identifier with IANA name BOCU-1. + // + // https://www.unicode.org/notes/tn6/ + BOCU1 MIB = 1020 + + // UTF7IMAP is the MIB identifier with IANA name UTF-7-IMAP. + // + // Note: This charset is used to encode Unicode in IMAP mailbox names; + // see section 5.1.3 of rfc3501 . It should never be used + // outside this context. A name has been assigned so that charset processing + // implementations can refer to it in a consistent way. + UTF7IMAP MIB = 1021 + + // Windows30Latin1 is the MIB identifier with IANA name ISO-8859-1-Windows-3.0-Latin-1. + // + // Extended ISO 8859-1 Latin-1 for Windows 3.0. + // PCL Symbol Set id: 9U + Windows30Latin1 MIB = 2000 + + // Windows31Latin1 is the MIB identifier with IANA name ISO-8859-1-Windows-3.1-Latin-1. + // + // Extended ISO 8859-1 Latin-1 for Windows 3.1. + // PCL Symbol Set id: 19U + Windows31Latin1 MIB = 2001 + + // Windows31Latin2 is the MIB identifier with IANA name ISO-8859-2-Windows-Latin-2. + // + // Extended ISO 8859-2. Latin-2 for Windows 3.1. + // PCL Symbol Set id: 9E + Windows31Latin2 MIB = 2002 + + // Windows31Latin5 is the MIB identifier with IANA name ISO-8859-9-Windows-Latin-5. + // + // Extended ISO 8859-9. Latin-5 for Windows 3.1 + // PCL Symbol Set id: 5T + Windows31Latin5 MIB = 2003 + + // HPRoman8 is the MIB identifier with IANA name hp-roman8. + // + // LaserJet IIP Printer User's Manual, + // HP part no 33471-90901, Hewlet-Packard, June 1989. + // Reference: RFC1345 + HPRoman8 MIB = 2004 + + // AdobeStandardEncoding is the MIB identifier with IANA name Adobe-Standard-Encoding. + // + // PostScript Language Reference Manual + // PCL Symbol Set id: 10J + AdobeStandardEncoding MIB = 2005 + + // VenturaUS is the MIB identifier with IANA name Ventura-US. + // + // Ventura US. ASCII plus characters typically used in + // publishing, like pilcrow, copyright, registered, trade mark, + // section, dagger, and double dagger in the range A0 (hex) + // to FF (hex). + // PCL Symbol Set id: 14J + VenturaUS MIB = 2006 + + // VenturaInternational is the MIB identifier with IANA name Ventura-International. + // + // Ventura International. ASCII plus coded characters similar + // to Roman8. + // PCL Symbol Set id: 13J + VenturaInternational MIB = 2007 + + // DECMCS is the MIB identifier with IANA name DEC-MCS. + // + // VAX/VMS User's Manual, + // Order Number: AI-Y517A-TE, April 1986. + // Reference: RFC1345 + DECMCS MIB = 2008 + + // PC850Multilingual is the MIB identifier with IANA name IBM850. + // + // IBM NLS RM Vol2 SE09-8002-01, March 1990 + // Reference: RFC1345 + PC850Multilingual MIB = 2009 + + // PC8DanishNorwegian is the MIB identifier with IANA name PC8-Danish-Norwegian. + // + // PC Danish Norwegian + // 8-bit PC set for Danish Norwegian + // PCL Symbol Set id: 11U + PC8DanishNorwegian MIB = 2012 + + // PC862LatinHebrew is the MIB identifier with IANA name IBM862. + // + // IBM NLS RM Vol2 SE09-8002-01, March 1990 + // Reference: RFC1345 + PC862LatinHebrew MIB = 2013 + + // PC8Turkish is the MIB identifier with IANA name PC8-Turkish. + // + // PC Latin Turkish. PCL Symbol Set id: 9T + PC8Turkish MIB = 2014 + + // IBMSymbols is the MIB identifier with IANA name IBM-Symbols. + // + // Presentation Set, CPGID: 259 + IBMSymbols MIB = 2015 + + // IBMThai is the MIB identifier with IANA name IBM-Thai. + // + // Presentation Set, CPGID: 838 + IBMThai MIB = 2016 + + // HPLegal is the MIB identifier with IANA name HP-Legal. + // + // PCL 5 Comparison Guide, Hewlett-Packard, + // HP part number 5961-0510, October 1992 + // PCL Symbol Set id: 1U + HPLegal MIB = 2017 + + // HPPiFont is the MIB identifier with IANA name HP-Pi-font. + // + // PCL 5 Comparison Guide, Hewlett-Packard, + // HP part number 5961-0510, October 1992 + // PCL Symbol Set id: 15U + HPPiFont MIB = 2018 + + // HPMath8 is the MIB identifier with IANA name HP-Math8. + // + // PCL 5 Comparison Guide, Hewlett-Packard, + // HP part number 5961-0510, October 1992 + // PCL Symbol Set id: 8M + HPMath8 MIB = 2019 + + // HPPSMath is the MIB identifier with IANA name Adobe-Symbol-Encoding. + // + // PostScript Language Reference Manual + // PCL Symbol Set id: 5M + HPPSMath MIB = 2020 + + // HPDesktop is the MIB identifier with IANA name HP-DeskTop. + // + // PCL 5 Comparison Guide, Hewlett-Packard, + // HP part number 5961-0510, October 1992 + // PCL Symbol Set id: 7J + HPDesktop MIB = 2021 + + // VenturaMath is the MIB identifier with IANA name Ventura-Math. + // + // PCL 5 Comparison Guide, Hewlett-Packard, + // HP part number 5961-0510, October 1992 + // PCL Symbol Set id: 6M + VenturaMath MIB = 2022 + + // MicrosoftPublishing is the MIB identifier with IANA name Microsoft-Publishing. + // + // PCL 5 Comparison Guide, Hewlett-Packard, + // HP part number 5961-0510, October 1992 + // PCL Symbol Set id: 6J + MicrosoftPublishing MIB = 2023 + + // Windows31J is the MIB identifier with IANA name Windows-31J. + // + // Windows Japanese. A further extension of Shift_JIS + // to include NEC special characters (Row 13), NEC + // selection of IBM extensions (Rows 89 to 92), and IBM + // extensions (Rows 115 to 119). The CCS's are + // JIS X0201:1997, JIS X0208:1997, and these extensions. + // This charset can be used for the top-level media type "text", + // but it is of limited or specialized use (see rfc2278 ). + // PCL Symbol Set id: 19K + Windows31J MIB = 2024 + + // GB2312 is the MIB identifier with IANA name GB2312 (MIME: GB2312). + // + // Chinese for People's Republic of China (PRC) mixed one byte, + // two byte set: + // 20-7E = one byte ASCII + // A1-FE = two byte PRC Kanji + // See GB 2312-80 + // PCL Symbol Set Id: 18C + GB2312 MIB = 2025 + + // Big5 is the MIB identifier with IANA name Big5 (MIME: Big5). + // + // Chinese for Taiwan Multi-byte set. + // PCL Symbol Set Id: 18T + Big5 MIB = 2026 + + // Macintosh is the MIB identifier with IANA name macintosh. + // + // The Unicode Standard ver1.0, ISBN 0-201-56788-1, Oct 1991 + // Reference: RFC1345 + Macintosh MIB = 2027 + + // IBM037 is the MIB identifier with IANA name IBM037. + // + // IBM NLS RM Vol2 SE09-8002-01, March 1990 + // Reference: RFC1345 + IBM037 MIB = 2028 + + // IBM038 is the MIB identifier with IANA name IBM038. + // + // IBM 3174 Character Set Ref, GA27-3831-02, March 1990 + // Reference: RFC1345 + IBM038 MIB = 2029 + + // IBM273 is the MIB identifier with IANA name IBM273. + // + // IBM NLS RM Vol2 SE09-8002-01, March 1990 + // Reference: RFC1345 + IBM273 MIB = 2030 + + // IBM274 is the MIB identifier with IANA name IBM274. + // + // IBM 3174 Character Set Ref, GA27-3831-02, March 1990 + // Reference: RFC1345 + IBM274 MIB = 2031 + + // IBM275 is the MIB identifier with IANA name IBM275. + // + // IBM NLS RM Vol2 SE09-8002-01, March 1990 + // Reference: RFC1345 + IBM275 MIB = 2032 + + // IBM277 is the MIB identifier with IANA name IBM277. + // + // IBM NLS RM Vol2 SE09-8002-01, March 1990 + // Reference: RFC1345 + IBM277 MIB = 2033 + + // IBM278 is the MIB identifier with IANA name IBM278. + // + // IBM NLS RM Vol2 SE09-8002-01, March 1990 + // Reference: RFC1345 + IBM278 MIB = 2034 + + // IBM280 is the MIB identifier with IANA name IBM280. + // + // IBM NLS RM Vol2 SE09-8002-01, March 1990 + // Reference: RFC1345 + IBM280 MIB = 2035 + + // IBM281 is the MIB identifier with IANA name IBM281. + // + // IBM 3174 Character Set Ref, GA27-3831-02, March 1990 + // Reference: RFC1345 + IBM281 MIB = 2036 + + // IBM284 is the MIB identifier with IANA name IBM284. + // + // IBM NLS RM Vol2 SE09-8002-01, March 1990 + // Reference: RFC1345 + IBM284 MIB = 2037 + + // IBM285 is the MIB identifier with IANA name IBM285. + // + // IBM NLS RM Vol2 SE09-8002-01, March 1990 + // Reference: RFC1345 + IBM285 MIB = 2038 + + // IBM290 is the MIB identifier with IANA name IBM290. + // + // IBM 3174 Character Set Ref, GA27-3831-02, March 1990 + // Reference: RFC1345 + IBM290 MIB = 2039 + + // IBM297 is the MIB identifier with IANA name IBM297. + // + // IBM NLS RM Vol2 SE09-8002-01, March 1990 + // Reference: RFC1345 + IBM297 MIB = 2040 + + // IBM420 is the MIB identifier with IANA name IBM420. + // + // IBM NLS RM Vol2 SE09-8002-01, March 1990, + // IBM NLS RM p 11-11 + // Reference: RFC1345 + IBM420 MIB = 2041 + + // IBM423 is the MIB identifier with IANA name IBM423. + // + // IBM NLS RM Vol2 SE09-8002-01, March 1990 + // Reference: RFC1345 + IBM423 MIB = 2042 + + // IBM424 is the MIB identifier with IANA name IBM424. + // + // IBM NLS RM Vol2 SE09-8002-01, March 1990 + // Reference: RFC1345 + IBM424 MIB = 2043 + + // PC8CodePage437 is the MIB identifier with IANA name IBM437. + // + // IBM NLS RM Vol2 SE09-8002-01, March 1990 + // Reference: RFC1345 + PC8CodePage437 MIB = 2011 + + // IBM500 is the MIB identifier with IANA name IBM500. + // + // IBM NLS RM Vol2 SE09-8002-01, March 1990 + // Reference: RFC1345 + IBM500 MIB = 2044 + + // IBM851 is the MIB identifier with IANA name IBM851. + // + // IBM NLS RM Vol2 SE09-8002-01, March 1990 + // Reference: RFC1345 + IBM851 MIB = 2045 + + // PCp852 is the MIB identifier with IANA name IBM852. + // + // IBM NLS RM Vol2 SE09-8002-01, March 1990 + // Reference: RFC1345 + PCp852 MIB = 2010 + + // IBM855 is the MIB identifier with IANA name IBM855. + // + // IBM NLS RM Vol2 SE09-8002-01, March 1990 + // Reference: RFC1345 + IBM855 MIB = 2046 + + // IBM857 is the MIB identifier with IANA name IBM857. + // + // IBM NLS RM Vol2 SE09-8002-01, March 1990 + // Reference: RFC1345 + IBM857 MIB = 2047 + + // IBM860 is the MIB identifier with IANA name IBM860. + // + // IBM NLS RM Vol2 SE09-8002-01, March 1990 + // Reference: RFC1345 + IBM860 MIB = 2048 + + // IBM861 is the MIB identifier with IANA name IBM861. + // + // IBM NLS RM Vol2 SE09-8002-01, March 1990 + // Reference: RFC1345 + IBM861 MIB = 2049 + + // IBM863 is the MIB identifier with IANA name IBM863. + // + // IBM Keyboard layouts and code pages, PN 07G4586 June 1991 + // Reference: RFC1345 + IBM863 MIB = 2050 + + // IBM864 is the MIB identifier with IANA name IBM864. + // + // IBM Keyboard layouts and code pages, PN 07G4586 June 1991 + // Reference: RFC1345 + IBM864 MIB = 2051 + + // IBM865 is the MIB identifier with IANA name IBM865. + // + // IBM DOS 3.3 Ref (Abridged), 94X9575 (Feb 1987) + // Reference: RFC1345 + IBM865 MIB = 2052 + + // IBM868 is the MIB identifier with IANA name IBM868. + // + // IBM NLS RM Vol2 SE09-8002-01, March 1990 + // Reference: RFC1345 + IBM868 MIB = 2053 + + // IBM869 is the MIB identifier with IANA name IBM869. + // + // IBM Keyboard layouts and code pages, PN 07G4586 June 1991 + // Reference: RFC1345 + IBM869 MIB = 2054 + + // IBM870 is the MIB identifier with IANA name IBM870. + // + // IBM NLS RM Vol2 SE09-8002-01, March 1990 + // Reference: RFC1345 + IBM870 MIB = 2055 + + // IBM871 is the MIB identifier with IANA name IBM871. + // + // IBM NLS RM Vol2 SE09-8002-01, March 1990 + // Reference: RFC1345 + IBM871 MIB = 2056 + + // IBM880 is the MIB identifier with IANA name IBM880. + // + // IBM NLS RM Vol2 SE09-8002-01, March 1990 + // Reference: RFC1345 + IBM880 MIB = 2057 + + // IBM891 is the MIB identifier with IANA name IBM891. + // + // IBM NLS RM Vol2 SE09-8002-01, March 1990 + // Reference: RFC1345 + IBM891 MIB = 2058 + + // IBM903 is the MIB identifier with IANA name IBM903. + // + // IBM NLS RM Vol2 SE09-8002-01, March 1990 + // Reference: RFC1345 + IBM903 MIB = 2059 + + // IBBM904 is the MIB identifier with IANA name IBM904. + // + // IBM NLS RM Vol2 SE09-8002-01, March 1990 + // Reference: RFC1345 + IBBM904 MIB = 2060 + + // IBM905 is the MIB identifier with IANA name IBM905. + // + // IBM 3174 Character Set Ref, GA27-3831-02, March 1990 + // Reference: RFC1345 + IBM905 MIB = 2061 + + // IBM918 is the MIB identifier with IANA name IBM918. + // + // IBM NLS RM Vol2 SE09-8002-01, March 1990 + // Reference: RFC1345 + IBM918 MIB = 2062 + + // IBM1026 is the MIB identifier with IANA name IBM1026. + // + // IBM NLS RM Vol2 SE09-8002-01, March 1990 + // Reference: RFC1345 + IBM1026 MIB = 2063 + + // IBMEBCDICATDE is the MIB identifier with IANA name EBCDIC-AT-DE. + // + // IBM 3270 Char Set Ref Ch 10, GA27-2837-9, April 1987 + // Reference: RFC1345 + IBMEBCDICATDE MIB = 2064 + + // EBCDICATDEA is the MIB identifier with IANA name EBCDIC-AT-DE-A. + // + // IBM 3270 Char Set Ref Ch 10, GA27-2837-9, April 1987 + // Reference: RFC1345 + EBCDICATDEA MIB = 2065 + + // EBCDICCAFR is the MIB identifier with IANA name EBCDIC-CA-FR. + // + // IBM 3270 Char Set Ref Ch 10, GA27-2837-9, April 1987 + // Reference: RFC1345 + EBCDICCAFR MIB = 2066 + + // EBCDICDKNO is the MIB identifier with IANA name EBCDIC-DK-NO. + // + // IBM 3270 Char Set Ref Ch 10, GA27-2837-9, April 1987 + // Reference: RFC1345 + EBCDICDKNO MIB = 2067 + + // EBCDICDKNOA is the MIB identifier with IANA name EBCDIC-DK-NO-A. + // + // IBM 3270 Char Set Ref Ch 10, GA27-2837-9, April 1987 + // Reference: RFC1345 + EBCDICDKNOA MIB = 2068 + + // EBCDICFISE is the MIB identifier with IANA name EBCDIC-FI-SE. + // + // IBM 3270 Char Set Ref Ch 10, GA27-2837-9, April 1987 + // Reference: RFC1345 + EBCDICFISE MIB = 2069 + + // EBCDICFISEA is the MIB identifier with IANA name EBCDIC-FI-SE-A. + // + // IBM 3270 Char Set Ref Ch 10, GA27-2837-9, April 1987 + // Reference: RFC1345 + EBCDICFISEA MIB = 2070 + + // EBCDICFR is the MIB identifier with IANA name EBCDIC-FR. + // + // IBM 3270 Char Set Ref Ch 10, GA27-2837-9, April 1987 + // Reference: RFC1345 + EBCDICFR MIB = 2071 + + // EBCDICIT is the MIB identifier with IANA name EBCDIC-IT. + // + // IBM 3270 Char Set Ref Ch 10, GA27-2837-9, April 1987 + // Reference: RFC1345 + EBCDICIT MIB = 2072 + + // EBCDICPT is the MIB identifier with IANA name EBCDIC-PT. + // + // IBM 3270 Char Set Ref Ch 10, GA27-2837-9, April 1987 + // Reference: RFC1345 + EBCDICPT MIB = 2073 + + // EBCDICES is the MIB identifier with IANA name EBCDIC-ES. + // + // IBM 3270 Char Set Ref Ch 10, GA27-2837-9, April 1987 + // Reference: RFC1345 + EBCDICES MIB = 2074 + + // EBCDICESA is the MIB identifier with IANA name EBCDIC-ES-A. + // + // IBM 3270 Char Set Ref Ch 10, GA27-2837-9, April 1987 + // Reference: RFC1345 + EBCDICESA MIB = 2075 + + // EBCDICESS is the MIB identifier with IANA name EBCDIC-ES-S. + // + // IBM 3270 Char Set Ref Ch 10, GA27-2837-9, April 1987 + // Reference: RFC1345 + EBCDICESS MIB = 2076 + + // EBCDICUK is the MIB identifier with IANA name EBCDIC-UK. + // + // IBM 3270 Char Set Ref Ch 10, GA27-2837-9, April 1987 + // Reference: RFC1345 + EBCDICUK MIB = 2077 + + // EBCDICUS is the MIB identifier with IANA name EBCDIC-US. + // + // IBM 3270 Char Set Ref Ch 10, GA27-2837-9, April 1987 + // Reference: RFC1345 + EBCDICUS MIB = 2078 + + // Unknown8BiT is the MIB identifier with IANA name UNKNOWN-8BIT. + // + // Reference: RFC1428 + Unknown8BiT MIB = 2079 + + // Mnemonic is the MIB identifier with IANA name MNEMONIC. + // + // rfc1345 , also known as "mnemonic+ascii+38" + // Reference: RFC1345 + Mnemonic MIB = 2080 + + // Mnem is the MIB identifier with IANA name MNEM. + // + // rfc1345 , also known as "mnemonic+ascii+8200" + // Reference: RFC1345 + Mnem MIB = 2081 + + // VISCII is the MIB identifier with IANA name VISCII. + // + // rfc1456 + // Reference: RFC1456 + VISCII MIB = 2082 + + // VIQR is the MIB identifier with IANA name VIQR. + // + // rfc1456 + // Reference: RFC1456 + VIQR MIB = 2083 + + // KOI8R is the MIB identifier with IANA name KOI8-R (MIME: KOI8-R). + // + // rfc1489 , based on GOST-19768-74, ISO-6937/8, + // INIS-Cyrillic, ISO-5427. + // Reference: RFC1489 + KOI8R MIB = 2084 + + // HZGB2312 is the MIB identifier with IANA name HZ-GB-2312. + // + // rfc1842 , rfc1843 rfc1843 rfc1842 + HZGB2312 MIB = 2085 + + // IBM866 is the MIB identifier with IANA name IBM866. + // + // IBM NLDG Volume 2 (SE09-8002-03) August 1994 + IBM866 MIB = 2086 + + // PC775Baltic is the MIB identifier with IANA name IBM775. + // + // HP PCL 5 Comparison Guide (P/N 5021-0329) pp B-13, 1996 + PC775Baltic MIB = 2087 + + // KOI8U is the MIB identifier with IANA name KOI8-U. + // + // rfc2319 + // Reference: RFC2319 + KOI8U MIB = 2088 + + // IBM00858 is the MIB identifier with IANA name IBM00858. + // + // IBM See https://www.iana.org/assignments/charset-reg/IBM00858 + IBM00858 MIB = 2089 + + // IBM00924 is the MIB identifier with IANA name IBM00924. + // + // IBM See https://www.iana.org/assignments/charset-reg/IBM00924 + IBM00924 MIB = 2090 + + // IBM01140 is the MIB identifier with IANA name IBM01140. + // + // IBM See https://www.iana.org/assignments/charset-reg/IBM01140 + IBM01140 MIB = 2091 + + // IBM01141 is the MIB identifier with IANA name IBM01141. + // + // IBM See https://www.iana.org/assignments/charset-reg/IBM01141 + IBM01141 MIB = 2092 + + // IBM01142 is the MIB identifier with IANA name IBM01142. + // + // IBM See https://www.iana.org/assignments/charset-reg/IBM01142 + IBM01142 MIB = 2093 + + // IBM01143 is the MIB identifier with IANA name IBM01143. + // + // IBM See https://www.iana.org/assignments/charset-reg/IBM01143 + IBM01143 MIB = 2094 + + // IBM01144 is the MIB identifier with IANA name IBM01144. + // + // IBM See https://www.iana.org/assignments/charset-reg/IBM01144 + IBM01144 MIB = 2095 + + // IBM01145 is the MIB identifier with IANA name IBM01145. + // + // IBM See https://www.iana.org/assignments/charset-reg/IBM01145 + IBM01145 MIB = 2096 + + // IBM01146 is the MIB identifier with IANA name IBM01146. + // + // IBM See https://www.iana.org/assignments/charset-reg/IBM01146 + IBM01146 MIB = 2097 + + // IBM01147 is the MIB identifier with IANA name IBM01147. + // + // IBM See https://www.iana.org/assignments/charset-reg/IBM01147 + IBM01147 MIB = 2098 + + // IBM01148 is the MIB identifier with IANA name IBM01148. + // + // IBM See https://www.iana.org/assignments/charset-reg/IBM01148 + IBM01148 MIB = 2099 + + // IBM01149 is the MIB identifier with IANA name IBM01149. + // + // IBM See https://www.iana.org/assignments/charset-reg/IBM01149 + IBM01149 MIB = 2100 + + // Big5HKSCS is the MIB identifier with IANA name Big5-HKSCS. + // + // See https://www.iana.org/assignments/charset-reg/Big5-HKSCS + Big5HKSCS MIB = 2101 + + // IBM1047 is the MIB identifier with IANA name IBM1047. + // + // IBM1047 (EBCDIC Latin 1/Open Systems) https://www-1.ibm.com/servers/eserver/iseries/software/globalization/pdf/cp01047z.pdf + IBM1047 MIB = 2102 + + // PTCP154 is the MIB identifier with IANA name PTCP154. + // + // See https://www.iana.org/assignments/charset-reg/PTCP154 + PTCP154 MIB = 2103 + + // Amiga1251 is the MIB identifier with IANA name Amiga-1251. + // + // See https://www.amiga.ultranet.ru/Amiga-1251.html + Amiga1251 MIB = 2104 + + // KOI7switched is the MIB identifier with IANA name KOI7-switched. + // + // See https://www.iana.org/assignments/charset-reg/KOI7-switched + KOI7switched MIB = 2105 + + // BRF is the MIB identifier with IANA name BRF. + // + // See https://www.iana.org/assignments/charset-reg/BRF + BRF MIB = 2106 + + // TSCII is the MIB identifier with IANA name TSCII. + // + // See https://www.iana.org/assignments/charset-reg/TSCII + TSCII MIB = 2107 + + // CP51932 is the MIB identifier with IANA name CP51932. + // + // See https://www.iana.org/assignments/charset-reg/CP51932 + CP51932 MIB = 2108 + + // Windows874 is the MIB identifier with IANA name windows-874. + // + // See https://www.iana.org/assignments/charset-reg/windows-874 + Windows874 MIB = 2109 + + // Windows1250 is the MIB identifier with IANA name windows-1250. + // + // Microsoft https://www.iana.org/assignments/charset-reg/windows-1250 + Windows1250 MIB = 2250 + + // Windows1251 is the MIB identifier with IANA name windows-1251. + // + // Microsoft https://www.iana.org/assignments/charset-reg/windows-1251 + Windows1251 MIB = 2251 + + // Windows1252 is the MIB identifier with IANA name windows-1252. + // + // Microsoft https://www.iana.org/assignments/charset-reg/windows-1252 + Windows1252 MIB = 2252 + + // Windows1253 is the MIB identifier with IANA name windows-1253. + // + // Microsoft https://www.iana.org/assignments/charset-reg/windows-1253 + Windows1253 MIB = 2253 + + // Windows1254 is the MIB identifier with IANA name windows-1254. + // + // Microsoft https://www.iana.org/assignments/charset-reg/windows-1254 + Windows1254 MIB = 2254 + + // Windows1255 is the MIB identifier with IANA name windows-1255. + // + // Microsoft https://www.iana.org/assignments/charset-reg/windows-1255 + Windows1255 MIB = 2255 + + // Windows1256 is the MIB identifier with IANA name windows-1256. + // + // Microsoft https://www.iana.org/assignments/charset-reg/windows-1256 + Windows1256 MIB = 2256 + + // Windows1257 is the MIB identifier with IANA name windows-1257. + // + // Microsoft https://www.iana.org/assignments/charset-reg/windows-1257 + Windows1257 MIB = 2257 + + // Windows1258 is the MIB identifier with IANA name windows-1258. + // + // Microsoft https://www.iana.org/assignments/charset-reg/windows-1258 + Windows1258 MIB = 2258 + + // TIS620 is the MIB identifier with IANA name TIS-620. + // + // Thai Industrial Standards Institute (TISI) + TIS620 MIB = 2259 + + // CP50220 is the MIB identifier with IANA name CP50220. + // + // See https://www.iana.org/assignments/charset-reg/CP50220 + CP50220 MIB = 2260 +) diff --git a/vendor/golang.org/x/text/encoding/internal/internal.go b/vendor/golang.org/x/text/encoding/internal/internal.go new file mode 100644 index 000000000..413e6fc6d --- /dev/null +++ b/vendor/golang.org/x/text/encoding/internal/internal.go @@ -0,0 +1,75 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package internal contains code that is shared among encoding implementations. +package internal + +import ( + "golang.org/x/text/encoding" + "golang.org/x/text/encoding/internal/identifier" + "golang.org/x/text/transform" +) + +// Encoding is an implementation of the Encoding interface that adds the String +// and ID methods to an existing encoding. +type Encoding struct { + encoding.Encoding + Name string + MIB identifier.MIB +} + +// _ verifies that Encoding implements identifier.Interface. +var _ identifier.Interface = (*Encoding)(nil) + +func (e *Encoding) String() string { + return e.Name +} + +func (e *Encoding) ID() (mib identifier.MIB, other string) { + return e.MIB, "" +} + +// SimpleEncoding is an Encoding that combines two Transformers. +type SimpleEncoding struct { + Decoder transform.Transformer + Encoder transform.Transformer +} + +func (e *SimpleEncoding) NewDecoder() *encoding.Decoder { + return &encoding.Decoder{Transformer: e.Decoder} +} + +func (e *SimpleEncoding) NewEncoder() *encoding.Encoder { + return &encoding.Encoder{Transformer: e.Encoder} +} + +// FuncEncoding is an Encoding that combines two functions returning a new +// Transformer. +type FuncEncoding struct { + Decoder func() transform.Transformer + Encoder func() transform.Transformer +} + +func (e FuncEncoding) NewDecoder() *encoding.Decoder { + return &encoding.Decoder{Transformer: e.Decoder()} +} + +func (e FuncEncoding) NewEncoder() *encoding.Encoder { + return &encoding.Encoder{Transformer: e.Encoder()} +} + +// A RepertoireError indicates a rune is not in the repertoire of a destination +// encoding. It is associated with an encoding-specific suggested replacement +// byte. +type RepertoireError byte + +// Error implements the error interface. +func (r RepertoireError) Error() string { + return "encoding: rune not supported by encoding." +} + +// Replacement returns the replacement string associated with this error. +func (r RepertoireError) Replacement() byte { return byte(r) } + +var ErrASCIIReplacement = RepertoireError(encoding.ASCIISub) diff --git a/vendor/golang.org/x/text/encoding/unicode/override.go b/vendor/golang.org/x/text/encoding/unicode/override.go new file mode 100644 index 000000000..35d62fcc9 --- /dev/null +++ b/vendor/golang.org/x/text/encoding/unicode/override.go @@ -0,0 +1,82 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package unicode + +import ( + "golang.org/x/text/transform" +) + +// BOMOverride returns a new decoder transformer that is identical to fallback, +// except that the presence of a Byte Order Mark at the start of the input +// causes it to switch to the corresponding Unicode decoding. It will only +// consider BOMs for UTF-8, UTF-16BE, and UTF-16LE. +// +// This differs from using ExpectBOM by allowing a BOM to switch to UTF-8, not +// just UTF-16 variants, and allowing falling back to any encoding scheme. +// +// This technique is recommended by the W3C for use in HTML 5: "For +// compatibility with deployed content, the byte order mark (also known as BOM) +// is considered more authoritative than anything else." +// http://www.w3.org/TR/encoding/#specification-hooks +// +// Using BOMOverride is mostly intended for use cases where the first characters +// of a fallback encoding are known to not be a BOM, for example, for valid HTML +// and most encodings. +func BOMOverride(fallback transform.Transformer) transform.Transformer { + // TODO: possibly allow a variadic argument of unicode encodings to allow + // specifying details of which fallbacks are supported as well as + // specifying the details of the implementations. This would also allow for + // support for UTF-32, which should not be supported by default. + return &bomOverride{fallback: fallback} +} + +type bomOverride struct { + fallback transform.Transformer + current transform.Transformer +} + +func (d *bomOverride) Reset() { + d.current = nil + d.fallback.Reset() +} + +var ( + // TODO: we could use decode functions here, instead of allocating a new + // decoder on every NewDecoder as IgnoreBOM decoders can be stateless. + utf16le = UTF16(LittleEndian, IgnoreBOM) + utf16be = UTF16(BigEndian, IgnoreBOM) +) + +const utf8BOM = "\ufeff" + +func (d *bomOverride) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) { + if d.current != nil { + return d.current.Transform(dst, src, atEOF) + } + if len(src) < 3 && !atEOF { + return 0, 0, transform.ErrShortSrc + } + d.current = d.fallback + bomSize := 0 + if len(src) >= 2 { + if src[0] == 0xFF && src[1] == 0xFE { + d.current = utf16le.NewDecoder() + bomSize = 2 + } else if src[0] == 0xFE && src[1] == 0xFF { + d.current = utf16be.NewDecoder() + bomSize = 2 + } else if len(src) >= 3 && + src[0] == utf8BOM[0] && + src[1] == utf8BOM[1] && + src[2] == utf8BOM[2] { + d.current = transform.Nop + bomSize = 3 + } + } + if bomSize < len(src) { + nDst, nSrc, err = d.current.Transform(dst, src[bomSize:], atEOF) + } + return nDst, nSrc + bomSize, err +} diff --git a/vendor/golang.org/x/text/encoding/unicode/unicode.go b/vendor/golang.org/x/text/encoding/unicode/unicode.go new file mode 100644 index 000000000..ce28c9062 --- /dev/null +++ b/vendor/golang.org/x/text/encoding/unicode/unicode.go @@ -0,0 +1,512 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package unicode provides Unicode encodings such as UTF-16. +package unicode // import "golang.org/x/text/encoding/unicode" + +import ( + "bytes" + "errors" + "unicode/utf16" + "unicode/utf8" + + "golang.org/x/text/encoding" + "golang.org/x/text/encoding/internal" + "golang.org/x/text/encoding/internal/identifier" + "golang.org/x/text/internal/utf8internal" + "golang.org/x/text/runes" + "golang.org/x/text/transform" +) + +// TODO: I think the Transformers really should return errors on unmatched +// surrogate pairs and odd numbers of bytes. This is not required by RFC 2781, +// which leaves it open, but is suggested by WhatWG. It will allow for all error +// modes as defined by WhatWG: fatal, HTML and Replacement. This would require +// the introduction of some kind of error type for conveying the erroneous code +// point. + +// UTF8 is the UTF-8 encoding. It neither removes nor adds byte order marks. +var UTF8 encoding.Encoding = utf8enc + +// UTF8BOM is an UTF-8 encoding where the decoder strips a leading byte order +// mark while the encoder adds one. +// +// Some editors add a byte order mark as a signature to UTF-8 files. Although +// the byte order mark is not useful for detecting byte order in UTF-8, it is +// sometimes used as a convention to mark UTF-8-encoded files. This relies on +// the observation that the UTF-8 byte order mark is either an illegal or at +// least very unlikely sequence in any other character encoding. +var UTF8BOM encoding.Encoding = utf8bomEncoding{} + +type utf8bomEncoding struct{} + +func (utf8bomEncoding) String() string { + return "UTF-8-BOM" +} + +func (utf8bomEncoding) ID() (identifier.MIB, string) { + return identifier.Unofficial, "x-utf8bom" +} + +func (utf8bomEncoding) NewEncoder() *encoding.Encoder { + return &encoding.Encoder{ + Transformer: &utf8bomEncoder{t: runes.ReplaceIllFormed()}, + } +} + +func (utf8bomEncoding) NewDecoder() *encoding.Decoder { + return &encoding.Decoder{Transformer: &utf8bomDecoder{}} +} + +var utf8enc = &internal.Encoding{ + Encoding: &internal.SimpleEncoding{Decoder: utf8Decoder{}, Encoder: runes.ReplaceIllFormed()}, + Name: "UTF-8", + MIB: identifier.UTF8, +} + +type utf8bomDecoder struct { + checked bool +} + +func (t *utf8bomDecoder) Reset() { + t.checked = false +} + +func (t *utf8bomDecoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) { + if !t.checked { + if !atEOF && len(src) < len(utf8BOM) { + if len(src) == 0 { + return 0, 0, nil + } + return 0, 0, transform.ErrShortSrc + } + if bytes.HasPrefix(src, []byte(utf8BOM)) { + nSrc += len(utf8BOM) + src = src[len(utf8BOM):] + } + t.checked = true + } + nDst, n, err := utf8Decoder.Transform(utf8Decoder{}, dst[nDst:], src, atEOF) + nSrc += n + return nDst, nSrc, err +} + +type utf8bomEncoder struct { + written bool + t transform.Transformer +} + +func (t *utf8bomEncoder) Reset() { + t.written = false + t.t.Reset() +} + +func (t *utf8bomEncoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) { + if !t.written { + if len(dst) < len(utf8BOM) { + return nDst, 0, transform.ErrShortDst + } + nDst = copy(dst, utf8BOM) + t.written = true + } + n, nSrc, err := utf8Decoder.Transform(utf8Decoder{}, dst[nDst:], src, atEOF) + nDst += n + return nDst, nSrc, err +} + +type utf8Decoder struct{ transform.NopResetter } + +func (utf8Decoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) { + var pSrc int // point from which to start copy in src + var accept utf8internal.AcceptRange + + // The decoder can only make the input larger, not smaller. + n := len(src) + if len(dst) < n { + err = transform.ErrShortDst + n = len(dst) + atEOF = false + } + for nSrc < n { + c := src[nSrc] + if c < utf8.RuneSelf { + nSrc++ + continue + } + first := utf8internal.First[c] + size := int(first & utf8internal.SizeMask) + if first == utf8internal.FirstInvalid { + goto handleInvalid // invalid starter byte + } + accept = utf8internal.AcceptRanges[first>>utf8internal.AcceptShift] + if nSrc+size > n { + if !atEOF { + // We may stop earlier than necessary here if the short sequence + // has invalid bytes. Not checking for this simplifies the code + // and may avoid duplicate computations in certain conditions. + if err == nil { + err = transform.ErrShortSrc + } + break + } + // Determine the maximal subpart of an ill-formed subsequence. + switch { + case nSrc+1 >= n || src[nSrc+1] < accept.Lo || accept.Hi < src[nSrc+1]: + size = 1 + case nSrc+2 >= n || src[nSrc+2] < utf8internal.LoCB || utf8internal.HiCB < src[nSrc+2]: + size = 2 + default: + size = 3 // As we are short, the maximum is 3. + } + goto handleInvalid + } + if c = src[nSrc+1]; c < accept.Lo || accept.Hi < c { + size = 1 + goto handleInvalid // invalid continuation byte + } else if size == 2 { + } else if c = src[nSrc+2]; c < utf8internal.LoCB || utf8internal.HiCB < c { + size = 2 + goto handleInvalid // invalid continuation byte + } else if size == 3 { + } else if c = src[nSrc+3]; c < utf8internal.LoCB || utf8internal.HiCB < c { + size = 3 + goto handleInvalid // invalid continuation byte + } + nSrc += size + continue + + handleInvalid: + // Copy the scanned input so far. + nDst += copy(dst[nDst:], src[pSrc:nSrc]) + + // Append RuneError to the destination. + const runeError = "\ufffd" + if nDst+len(runeError) > len(dst) { + return nDst, nSrc, transform.ErrShortDst + } + nDst += copy(dst[nDst:], runeError) + + // Skip the maximal subpart of an ill-formed subsequence according to + // the W3C standard way instead of the Go way. This Transform is + // probably the only place in the text repo where it is warranted. + nSrc += size + pSrc = nSrc + + // Recompute the maximum source length. + if sz := len(dst) - nDst; sz < len(src)-nSrc { + err = transform.ErrShortDst + n = nSrc + sz + atEOF = false + } + } + return nDst + copy(dst[nDst:], src[pSrc:nSrc]), nSrc, err +} + +// UTF16 returns a UTF-16 Encoding for the given default endianness and byte +// order mark (BOM) policy. +// +// When decoding from UTF-16 to UTF-8, if the BOMPolicy is IgnoreBOM then +// neither BOMs U+FEFF nor noncharacters U+FFFE in the input stream will affect +// the endianness used for decoding, and will instead be output as their +// standard UTF-8 encodings: "\xef\xbb\xbf" and "\xef\xbf\xbe". If the BOMPolicy +// is UseBOM or ExpectBOM a staring BOM is not written to the UTF-8 output. +// Instead, it overrides the default endianness e for the remainder of the +// transformation. Any subsequent BOMs U+FEFF or noncharacters U+FFFE will not +// affect the endianness used, and will instead be output as their standard +// UTF-8 encodings. For UseBOM, if there is no starting BOM, it will proceed +// with the default Endianness. For ExpectBOM, in that case, the transformation +// will return early with an ErrMissingBOM error. +// +// When encoding from UTF-8 to UTF-16, a BOM will be inserted at the start of +// the output if the BOMPolicy is UseBOM or ExpectBOM. Otherwise, a BOM will not +// be inserted. The UTF-8 input does not need to contain a BOM. +// +// There is no concept of a 'native' endianness. If the UTF-16 data is produced +// and consumed in a greater context that implies a certain endianness, use +// IgnoreBOM. Otherwise, use ExpectBOM and always produce and consume a BOM. +// +// In the language of https://www.unicode.org/faq/utf_bom.html#bom10, IgnoreBOM +// corresponds to "Where the precise type of the data stream is known... the +// BOM should not be used" and ExpectBOM corresponds to "A particular +// protocol... may require use of the BOM". +func UTF16(e Endianness, b BOMPolicy) encoding.Encoding { + return utf16Encoding{config{e, b}, mibValue[e][b&bomMask]} +} + +// mibValue maps Endianness and BOMPolicy settings to MIB constants. Note that +// some configurations map to the same MIB identifier. RFC 2781 has requirements +// and recommendations. Some of the "configurations" are merely recommendations, +// so multiple configurations could match. +var mibValue = map[Endianness][numBOMValues]identifier.MIB{ + BigEndian: [numBOMValues]identifier.MIB{ + IgnoreBOM: identifier.UTF16BE, + UseBOM: identifier.UTF16, // BigEnding default is preferred by RFC 2781. + // TODO: acceptBOM | strictBOM would map to UTF16BE as well. + }, + LittleEndian: [numBOMValues]identifier.MIB{ + IgnoreBOM: identifier.UTF16LE, + UseBOM: identifier.UTF16, // LittleEndian default is allowed and preferred on Windows. + // TODO: acceptBOM | strictBOM would map to UTF16LE as well. + }, + // ExpectBOM is not widely used and has no valid MIB identifier. +} + +// All lists a configuration for each IANA-defined UTF-16 variant. +var All = []encoding.Encoding{ + UTF8, + UTF16(BigEndian, UseBOM), + UTF16(BigEndian, IgnoreBOM), + UTF16(LittleEndian, IgnoreBOM), +} + +// BOMPolicy is a UTF-16 encoding's byte order mark policy. +type BOMPolicy uint8 + +const ( + writeBOM BOMPolicy = 0x01 + acceptBOM BOMPolicy = 0x02 + requireBOM BOMPolicy = 0x04 + bomMask BOMPolicy = 0x07 + + // HACK: numBOMValues == 8 triggers a bug in the 1.4 compiler (cannot have a + // map of an array of length 8 of a type that is also used as a key or value + // in another map). See golang.org/issue/11354. + // TODO: consider changing this value back to 8 if the use of 1.4.* has + // been minimized. + numBOMValues = 8 + 1 + + // IgnoreBOM means to ignore any byte order marks. + IgnoreBOM BOMPolicy = 0 + // Common and RFC 2781-compliant interpretation for UTF-16BE/LE. + + // UseBOM means that the UTF-16 form may start with a byte order mark, which + // will be used to override the default encoding. + UseBOM BOMPolicy = writeBOM | acceptBOM + // Common and RFC 2781-compliant interpretation for UTF-16. + + // ExpectBOM means that the UTF-16 form must start with a byte order mark, + // which will be used to override the default encoding. + ExpectBOM BOMPolicy = writeBOM | acceptBOM | requireBOM + // Used in Java as Unicode (not to be confused with Java's UTF-16) and + // ICU's UTF-16,version=1. Not compliant with RFC 2781. + + // TODO (maybe): strictBOM: BOM must match Endianness. This would allow: + // - UTF-16(B|L)E,version=1: writeBOM | acceptBOM | requireBOM | strictBOM + // (UnicodeBig and UnicodeLittle in Java) + // - RFC 2781-compliant, but less common interpretation for UTF-16(B|L)E: + // acceptBOM | strictBOM (e.g. assigned to CheckBOM). + // This addition would be consistent with supporting ExpectBOM. +) + +// Endianness is a UTF-16 encoding's default endianness. +type Endianness bool + +const ( + // BigEndian is UTF-16BE. + BigEndian Endianness = false + // LittleEndian is UTF-16LE. + LittleEndian Endianness = true +) + +// ErrMissingBOM means that decoding UTF-16 input with ExpectBOM did not find a +// starting byte order mark. +var ErrMissingBOM = errors.New("encoding: missing byte order mark") + +type utf16Encoding struct { + config + mib identifier.MIB +} + +type config struct { + endianness Endianness + bomPolicy BOMPolicy +} + +func (u utf16Encoding) NewDecoder() *encoding.Decoder { + return &encoding.Decoder{Transformer: &utf16Decoder{ + initial: u.config, + current: u.config, + }} +} + +func (u utf16Encoding) NewEncoder() *encoding.Encoder { + return &encoding.Encoder{Transformer: &utf16Encoder{ + endianness: u.endianness, + initialBOMPolicy: u.bomPolicy, + currentBOMPolicy: u.bomPolicy, + }} +} + +func (u utf16Encoding) ID() (mib identifier.MIB, other string) { + return u.mib, "" +} + +func (u utf16Encoding) String() string { + e, b := "B", "" + if u.endianness == LittleEndian { + e = "L" + } + switch u.bomPolicy { + case ExpectBOM: + b = "Expect" + case UseBOM: + b = "Use" + case IgnoreBOM: + b = "Ignore" + } + return "UTF-16" + e + "E (" + b + " BOM)" +} + +type utf16Decoder struct { + initial config + current config +} + +func (u *utf16Decoder) Reset() { + u.current = u.initial +} + +func (u *utf16Decoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) { + if len(src) < 2 && atEOF && u.current.bomPolicy&requireBOM != 0 { + return 0, 0, ErrMissingBOM + } + if len(src) == 0 { + return 0, 0, nil + } + if len(src) >= 2 && u.current.bomPolicy&acceptBOM != 0 { + switch { + case src[0] == 0xfe && src[1] == 0xff: + u.current.endianness = BigEndian + nSrc = 2 + case src[0] == 0xff && src[1] == 0xfe: + u.current.endianness = LittleEndian + nSrc = 2 + default: + if u.current.bomPolicy&requireBOM != 0 { + return 0, 0, ErrMissingBOM + } + } + u.current.bomPolicy = IgnoreBOM + } + + var r rune + var dSize, sSize int + for nSrc < len(src) { + if nSrc+1 < len(src) { + x := uint16(src[nSrc+0])<<8 | uint16(src[nSrc+1]) + if u.current.endianness == LittleEndian { + x = x>>8 | x<<8 + } + r, sSize = rune(x), 2 + if utf16.IsSurrogate(r) { + if nSrc+3 < len(src) { + x = uint16(src[nSrc+2])<<8 | uint16(src[nSrc+3]) + if u.current.endianness == LittleEndian { + x = x>>8 | x<<8 + } + // Save for next iteration if it is not a high surrogate. + if isHighSurrogate(rune(x)) { + r, sSize = utf16.DecodeRune(r, rune(x)), 4 + } + } else if !atEOF { + err = transform.ErrShortSrc + break + } + } + if dSize = utf8.RuneLen(r); dSize < 0 { + r, dSize = utf8.RuneError, 3 + } + } else if atEOF { + // Single trailing byte. + r, dSize, sSize = utf8.RuneError, 3, 1 + } else { + err = transform.ErrShortSrc + break + } + if nDst+dSize > len(dst) { + err = transform.ErrShortDst + break + } + nDst += utf8.EncodeRune(dst[nDst:], r) + nSrc += sSize + } + return nDst, nSrc, err +} + +func isHighSurrogate(r rune) bool { + return 0xDC00 <= r && r <= 0xDFFF +} + +type utf16Encoder struct { + endianness Endianness + initialBOMPolicy BOMPolicy + currentBOMPolicy BOMPolicy +} + +func (u *utf16Encoder) Reset() { + u.currentBOMPolicy = u.initialBOMPolicy +} + +func (u *utf16Encoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) { + if u.currentBOMPolicy&writeBOM != 0 { + if len(dst) < 2 { + return 0, 0, transform.ErrShortDst + } + dst[0], dst[1] = 0xfe, 0xff + u.currentBOMPolicy = IgnoreBOM + nDst = 2 + } + + r, size := rune(0), 0 + for nSrc < len(src) { + r = rune(src[nSrc]) + + // Decode a 1-byte rune. + if r < utf8.RuneSelf { + size = 1 + + } else { + // Decode a multi-byte rune. + r, size = utf8.DecodeRune(src[nSrc:]) + if size == 1 { + // All valid runes of size 1 (those below utf8.RuneSelf) were + // handled above. We have invalid UTF-8 or we haven't seen the + // full character yet. + if !atEOF && !utf8.FullRune(src[nSrc:]) { + err = transform.ErrShortSrc + break + } + } + } + + if r <= 0xffff { + if nDst+2 > len(dst) { + err = transform.ErrShortDst + break + } + dst[nDst+0] = uint8(r >> 8) + dst[nDst+1] = uint8(r) + nDst += 2 + } else { + if nDst+4 > len(dst) { + err = transform.ErrShortDst + break + } + r1, r2 := utf16.EncodeRune(r) + dst[nDst+0] = uint8(r1 >> 8) + dst[nDst+1] = uint8(r1) + dst[nDst+2] = uint8(r2 >> 8) + dst[nDst+3] = uint8(r2) + nDst += 4 + } + nSrc += size + } + + if u.endianness == LittleEndian { + for i := 0; i < nDst; i += 2 { + dst[i], dst[i+1] = dst[i+1], dst[i] + } + } + return nDst, nSrc, err +} diff --git a/vendor/golang.org/x/text/internal/utf8internal/utf8internal.go b/vendor/golang.org/x/text/internal/utf8internal/utf8internal.go new file mode 100644 index 000000000..e5c53b1b3 --- /dev/null +++ b/vendor/golang.org/x/text/internal/utf8internal/utf8internal.go @@ -0,0 +1,87 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package utf8internal contains low-level utf8-related constants, tables, etc. +// that are used internally by the text package. +package utf8internal + +// The default lowest and highest continuation byte. +const ( + LoCB = 0x80 // 1000 0000 + HiCB = 0xBF // 1011 1111 +) + +// Constants related to getting information of first bytes of UTF-8 sequences. +const ( + // ASCII identifies a UTF-8 byte as ASCII. + ASCII = as + + // FirstInvalid indicates a byte is invalid as a first byte of a UTF-8 + // sequence. + FirstInvalid = xx + + // SizeMask is a mask for the size bits. Use use x&SizeMask to get the size. + SizeMask = 7 + + // AcceptShift is the right-shift count for the first byte info byte to get + // the index into the AcceptRanges table. See AcceptRanges. + AcceptShift = 4 + + // The names of these constants are chosen to give nice alignment in the + // table below. The first nibble is an index into acceptRanges or F for + // special one-byte cases. The second nibble is the Rune length or the + // Status for the special one-byte case. + xx = 0xF1 // invalid: size 1 + as = 0xF0 // ASCII: size 1 + s1 = 0x02 // accept 0, size 2 + s2 = 0x13 // accept 1, size 3 + s3 = 0x03 // accept 0, size 3 + s4 = 0x23 // accept 2, size 3 + s5 = 0x34 // accept 3, size 4 + s6 = 0x04 // accept 0, size 4 + s7 = 0x44 // accept 4, size 4 +) + +// First is information about the first byte in a UTF-8 sequence. +var First = [256]uint8{ + // 1 2 3 4 5 6 7 8 9 A B C D E F + as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, // 0x00-0x0F + as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, // 0x10-0x1F + as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, // 0x20-0x2F + as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, // 0x30-0x3F + as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, // 0x40-0x4F + as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, // 0x50-0x5F + as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, // 0x60-0x6F + as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, // 0x70-0x7F + // 1 2 3 4 5 6 7 8 9 A B C D E F + xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, // 0x80-0x8F + xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, // 0x90-0x9F + xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, // 0xA0-0xAF + xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, // 0xB0-0xBF + xx, xx, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, // 0xC0-0xCF + s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, // 0xD0-0xDF + s2, s3, s3, s3, s3, s3, s3, s3, s3, s3, s3, s3, s3, s4, s3, s3, // 0xE0-0xEF + s5, s6, s6, s6, s7, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, // 0xF0-0xFF +} + +// AcceptRange gives the range of valid values for the second byte in a UTF-8 +// sequence for any value for First that is not ASCII or FirstInvalid. +type AcceptRange struct { + Lo uint8 // lowest value for second byte. + Hi uint8 // highest value for second byte. +} + +// AcceptRanges is a slice of AcceptRange values. For a given byte sequence b +// +// AcceptRanges[First[b[0]]>>AcceptShift] +// +// will give the value of AcceptRange for the multi-byte UTF-8 sequence starting +// at b[0]. +var AcceptRanges = [...]AcceptRange{ + 0: {LoCB, HiCB}, + 1: {0xA0, HiCB}, + 2: {LoCB, 0x9F}, + 3: {0x90, HiCB}, + 4: {LoCB, 0x8F}, +} diff --git a/vendor/golang.org/x/text/runes/cond.go b/vendor/golang.org/x/text/runes/cond.go new file mode 100644 index 000000000..df7aa02db --- /dev/null +++ b/vendor/golang.org/x/text/runes/cond.go @@ -0,0 +1,187 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package runes + +import ( + "unicode/utf8" + + "golang.org/x/text/transform" +) + +// Note: below we pass invalid UTF-8 to the tIn and tNotIn transformers as is. +// This is done for various reasons: +// - To retain the semantics of the Nop transformer: if input is passed to a Nop +// one would expect it to be unchanged. +// - It would be very expensive to pass a converted RuneError to a transformer: +// a transformer might need more source bytes after RuneError, meaning that +// the only way to pass it safely is to create a new buffer and manage the +// intermingling of RuneErrors and normal input. +// - Many transformers leave ill-formed UTF-8 as is, so this is not +// inconsistent. Generally ill-formed UTF-8 is only replaced if it is a +// logical consequence of the operation (as for Map) or if it otherwise would +// pose security concerns (as for Remove). +// - An alternative would be to return an error on ill-formed UTF-8, but this +// would be inconsistent with other operations. + +// If returns a transformer that applies tIn to consecutive runes for which +// s.Contains(r) and tNotIn to consecutive runes for which !s.Contains(r). Reset +// is called on tIn and tNotIn at the start of each run. A Nop transformer will +// substitute a nil value passed to tIn or tNotIn. Invalid UTF-8 is translated +// to RuneError to determine which transformer to apply, but is passed as is to +// the respective transformer. +func If(s Set, tIn, tNotIn transform.Transformer) Transformer { + if tIn == nil && tNotIn == nil { + return Transformer{transform.Nop} + } + if tIn == nil { + tIn = transform.Nop + } + if tNotIn == nil { + tNotIn = transform.Nop + } + sIn, ok := tIn.(transform.SpanningTransformer) + if !ok { + sIn = dummySpan{tIn} + } + sNotIn, ok := tNotIn.(transform.SpanningTransformer) + if !ok { + sNotIn = dummySpan{tNotIn} + } + + a := &cond{ + tIn: sIn, + tNotIn: sNotIn, + f: s.Contains, + } + a.Reset() + return Transformer{a} +} + +type dummySpan struct{ transform.Transformer } + +func (d dummySpan) Span(src []byte, atEOF bool) (n int, err error) { + return 0, transform.ErrEndOfSpan +} + +type cond struct { + tIn, tNotIn transform.SpanningTransformer + f func(rune) bool + check func(rune) bool // current check to perform + t transform.SpanningTransformer // current transformer to use +} + +// Reset implements transform.Transformer. +func (t *cond) Reset() { + t.check = t.is + t.t = t.tIn + t.t.Reset() // notIn will be reset on first usage. +} + +func (t *cond) is(r rune) bool { + if t.f(r) { + return true + } + t.check = t.isNot + t.t = t.tNotIn + t.tNotIn.Reset() + return false +} + +func (t *cond) isNot(r rune) bool { + if !t.f(r) { + return true + } + t.check = t.is + t.t = t.tIn + t.tIn.Reset() + return false +} + +// This implementation of Span doesn't help all too much, but it needs to be +// there to satisfy this package's Transformer interface. +// TODO: there are certainly room for improvements, though. For example, if +// t.t == transform.Nop (which will a common occurrence) it will save a bundle +// to special-case that loop. +func (t *cond) Span(src []byte, atEOF bool) (n int, err error) { + p := 0 + for n < len(src) && err == nil { + // Don't process too much at a time as the Spanner that will be + // called on this block may terminate early. + const maxChunk = 4096 + max := len(src) + if v := n + maxChunk; v < max { + max = v + } + atEnd := false + size := 0 + current := t.t + for ; p < max; p += size { + r := rune(src[p]) + if r < utf8.RuneSelf { + size = 1 + } else if r, size = utf8.DecodeRune(src[p:]); size == 1 { + if !atEOF && !utf8.FullRune(src[p:]) { + err = transform.ErrShortSrc + break + } + } + if !t.check(r) { + // The next rune will be the start of a new run. + atEnd = true + break + } + } + n2, err2 := current.Span(src[n:p], atEnd || (atEOF && p == len(src))) + n += n2 + if err2 != nil { + return n, err2 + } + // At this point either err != nil or t.check will pass for the rune at p. + p = n + size + } + return n, err +} + +func (t *cond) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) { + p := 0 + for nSrc < len(src) && err == nil { + // Don't process too much at a time, as the work might be wasted if the + // destination buffer isn't large enough to hold the result or a + // transform returns an error early. + const maxChunk = 4096 + max := len(src) + if n := nSrc + maxChunk; n < len(src) { + max = n + } + atEnd := false + size := 0 + current := t.t + for ; p < max; p += size { + r := rune(src[p]) + if r < utf8.RuneSelf { + size = 1 + } else if r, size = utf8.DecodeRune(src[p:]); size == 1 { + if !atEOF && !utf8.FullRune(src[p:]) { + err = transform.ErrShortSrc + break + } + } + if !t.check(r) { + // The next rune will be the start of a new run. + atEnd = true + break + } + } + nDst2, nSrc2, err2 := current.Transform(dst[nDst:], src[nSrc:p], atEnd || (atEOF && p == len(src))) + nDst += nDst2 + nSrc += nSrc2 + if err2 != nil { + return nDst, nSrc, err2 + } + // At this point either err != nil or t.check will pass for the rune at p. + p = nSrc + size + } + return nDst, nSrc, err +} diff --git a/vendor/golang.org/x/text/runes/runes.go b/vendor/golang.org/x/text/runes/runes.go new file mode 100644 index 000000000..930e87fed --- /dev/null +++ b/vendor/golang.org/x/text/runes/runes.go @@ -0,0 +1,355 @@ +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package runes provide transforms for UTF-8 encoded text. +package runes // import "golang.org/x/text/runes" + +import ( + "unicode" + "unicode/utf8" + + "golang.org/x/text/transform" +) + +// A Set is a collection of runes. +type Set interface { + // Contains returns true if r is contained in the set. + Contains(r rune) bool +} + +type setFunc func(rune) bool + +func (s setFunc) Contains(r rune) bool { + return s(r) +} + +// Note: using funcs here instead of wrapping types result in cleaner +// documentation and a smaller API. + +// In creates a Set with a Contains method that returns true for all runes in +// the given RangeTable. +func In(rt *unicode.RangeTable) Set { + return setFunc(func(r rune) bool { return unicode.Is(rt, r) }) +} + +// NotIn creates a Set with a Contains method that returns true for all runes not +// in the given RangeTable. +func NotIn(rt *unicode.RangeTable) Set { + return setFunc(func(r rune) bool { return !unicode.Is(rt, r) }) +} + +// Predicate creates a Set with a Contains method that returns f(r). +func Predicate(f func(rune) bool) Set { + return setFunc(f) +} + +// Transformer implements the transform.Transformer interface. +type Transformer struct { + t transform.SpanningTransformer +} + +func (t Transformer) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) { + return t.t.Transform(dst, src, atEOF) +} + +func (t Transformer) Span(b []byte, atEOF bool) (n int, err error) { + return t.t.Span(b, atEOF) +} + +func (t Transformer) Reset() { t.t.Reset() } + +// Bytes returns a new byte slice with the result of converting b using t. It +// calls Reset on t. It returns nil if any error was found. This can only happen +// if an error-producing Transformer is passed to If. +func (t Transformer) Bytes(b []byte) []byte { + b, _, err := transform.Bytes(t, b) + if err != nil { + return nil + } + return b +} + +// String returns a string with the result of converting s using t. It calls +// Reset on t. It returns the empty string if any error was found. This can only +// happen if an error-producing Transformer is passed to If. +func (t Transformer) String(s string) string { + s, _, err := transform.String(t, s) + if err != nil { + return "" + } + return s +} + +// TODO: +// - Copy: copying strings and bytes in whole-rune units. +// - Validation (maybe) +// - Well-formed-ness (maybe) + +const runeErrorString = string(utf8.RuneError) + +// Remove returns a Transformer that removes runes r for which s.Contains(r). +// Illegal input bytes are replaced by RuneError before being passed to f. +func Remove(s Set) Transformer { + if f, ok := s.(setFunc); ok { + // This little trick cuts the running time of BenchmarkRemove for sets + // created by Predicate roughly in half. + // TODO: special-case RangeTables as well. + return Transformer{remove(f)} + } + return Transformer{remove(s.Contains)} +} + +// TODO: remove transform.RemoveFunc. + +type remove func(r rune) bool + +func (remove) Reset() {} + +// Span implements transform.Spanner. +func (t remove) Span(src []byte, atEOF bool) (n int, err error) { + for r, size := rune(0), 0; n < len(src); { + if r = rune(src[n]); r < utf8.RuneSelf { + size = 1 + } else if r, size = utf8.DecodeRune(src[n:]); size == 1 { + // Invalid rune. + if !atEOF && !utf8.FullRune(src[n:]) { + err = transform.ErrShortSrc + } else { + err = transform.ErrEndOfSpan + } + break + } + if t(r) { + err = transform.ErrEndOfSpan + break + } + n += size + } + return +} + +// Transform implements transform.Transformer. +func (t remove) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) { + for r, size := rune(0), 0; nSrc < len(src); { + if r = rune(src[nSrc]); r < utf8.RuneSelf { + size = 1 + } else if r, size = utf8.DecodeRune(src[nSrc:]); size == 1 { + // Invalid rune. + if !atEOF && !utf8.FullRune(src[nSrc:]) { + err = transform.ErrShortSrc + break + } + // We replace illegal bytes with RuneError. Not doing so might + // otherwise turn a sequence of invalid UTF-8 into valid UTF-8. + // The resulting byte sequence may subsequently contain runes + // for which t(r) is true that were passed unnoticed. + if !t(utf8.RuneError) { + if nDst+3 > len(dst) { + err = transform.ErrShortDst + break + } + dst[nDst+0] = runeErrorString[0] + dst[nDst+1] = runeErrorString[1] + dst[nDst+2] = runeErrorString[2] + nDst += 3 + } + nSrc++ + continue + } + if t(r) { + nSrc += size + continue + } + if nDst+size > len(dst) { + err = transform.ErrShortDst + break + } + for i := 0; i < size; i++ { + dst[nDst] = src[nSrc] + nDst++ + nSrc++ + } + } + return +} + +// Map returns a Transformer that maps the runes in the input using the given +// mapping. Illegal bytes in the input are converted to utf8.RuneError before +// being passed to the mapping func. +func Map(mapping func(rune) rune) Transformer { + return Transformer{mapper(mapping)} +} + +type mapper func(rune) rune + +func (mapper) Reset() {} + +// Span implements transform.Spanner. +func (t mapper) Span(src []byte, atEOF bool) (n int, err error) { + for r, size := rune(0), 0; n < len(src); n += size { + if r = rune(src[n]); r < utf8.RuneSelf { + size = 1 + } else if r, size = utf8.DecodeRune(src[n:]); size == 1 { + // Invalid rune. + if !atEOF && !utf8.FullRune(src[n:]) { + err = transform.ErrShortSrc + } else { + err = transform.ErrEndOfSpan + } + break + } + if t(r) != r { + err = transform.ErrEndOfSpan + break + } + } + return n, err +} + +// Transform implements transform.Transformer. +func (t mapper) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) { + var replacement rune + var b [utf8.UTFMax]byte + + for r, size := rune(0), 0; nSrc < len(src); { + if r = rune(src[nSrc]); r < utf8.RuneSelf { + if replacement = t(r); replacement < utf8.RuneSelf { + if nDst == len(dst) { + err = transform.ErrShortDst + break + } + dst[nDst] = byte(replacement) + nDst++ + nSrc++ + continue + } + size = 1 + } else if r, size = utf8.DecodeRune(src[nSrc:]); size == 1 { + // Invalid rune. + if !atEOF && !utf8.FullRune(src[nSrc:]) { + err = transform.ErrShortSrc + break + } + + if replacement = t(utf8.RuneError); replacement == utf8.RuneError { + if nDst+3 > len(dst) { + err = transform.ErrShortDst + break + } + dst[nDst+0] = runeErrorString[0] + dst[nDst+1] = runeErrorString[1] + dst[nDst+2] = runeErrorString[2] + nDst += 3 + nSrc++ + continue + } + } else if replacement = t(r); replacement == r { + if nDst+size > len(dst) { + err = transform.ErrShortDst + break + } + for i := 0; i < size; i++ { + dst[nDst] = src[nSrc] + nDst++ + nSrc++ + } + continue + } + + n := utf8.EncodeRune(b[:], replacement) + + if nDst+n > len(dst) { + err = transform.ErrShortDst + break + } + for i := 0; i < n; i++ { + dst[nDst] = b[i] + nDst++ + } + nSrc += size + } + return +} + +// ReplaceIllFormed returns a transformer that replaces all input bytes that are +// not part of a well-formed UTF-8 code sequence with utf8.RuneError. +func ReplaceIllFormed() Transformer { + return Transformer{&replaceIllFormed{}} +} + +type replaceIllFormed struct{ transform.NopResetter } + +func (t replaceIllFormed) Span(src []byte, atEOF bool) (n int, err error) { + for n < len(src) { + // ASCII fast path. + if src[n] < utf8.RuneSelf { + n++ + continue + } + + r, size := utf8.DecodeRune(src[n:]) + + // Look for a valid non-ASCII rune. + if r != utf8.RuneError || size != 1 { + n += size + continue + } + + // Look for short source data. + if !atEOF && !utf8.FullRune(src[n:]) { + err = transform.ErrShortSrc + break + } + + // We have an invalid rune. + err = transform.ErrEndOfSpan + break + } + return n, err +} + +func (t replaceIllFormed) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) { + for nSrc < len(src) { + // ASCII fast path. + if r := src[nSrc]; r < utf8.RuneSelf { + if nDst == len(dst) { + err = transform.ErrShortDst + break + } + dst[nDst] = r + nDst++ + nSrc++ + continue + } + + // Look for a valid non-ASCII rune. + if _, size := utf8.DecodeRune(src[nSrc:]); size != 1 { + if size != copy(dst[nDst:], src[nSrc:nSrc+size]) { + err = transform.ErrShortDst + break + } + nDst += size + nSrc += size + continue + } + + // Look for short source data. + if !atEOF && !utf8.FullRune(src[nSrc:]) { + err = transform.ErrShortSrc + break + } + + // We have an invalid rune. + if nDst+3 > len(dst) { + err = transform.ErrShortDst + break + } + dst[nDst+0] = runeErrorString[0] + dst[nDst+1] = runeErrorString[1] + dst[nDst+2] = runeErrorString[2] + nDst += 3 + nSrc++ + } + return nDst, nSrc, err +} diff --git a/vendor/modules.txt b/vendor/modules.txt index e3b89cdf4..6d4057b02 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -195,6 +195,10 @@ github.com/grafana/sobek/ftoa/internal/fast github.com/grafana/sobek/parser github.com/grafana/sobek/token github.com/grafana/sobek/unistring +# github.com/grafana/sobek-webapi-encoding v0.1.0 +## explicit; go 1.25.0 +github.com/grafana/sobek-webapi-encoding +github.com/grafana/sobek-webapi-encoding/encoding # github.com/grafana/xk6-dashboard-assets v0.1.2 ## explicit; go 1.24 github.com/grafana/xk6-dashboard-assets @@ -486,12 +490,18 @@ golang.org/x/term ## explicit; go 1.25.0 golang.org/x/text/cases golang.org/x/text/collate +golang.org/x/text/encoding +golang.org/x/text/encoding/internal +golang.org/x/text/encoding/internal/identifier +golang.org/x/text/encoding/unicode golang.org/x/text/internal golang.org/x/text/internal/colltab golang.org/x/text/internal/language golang.org/x/text/internal/language/compact golang.org/x/text/internal/tag +golang.org/x/text/internal/utf8internal golang.org/x/text/language +golang.org/x/text/runes golang.org/x/text/secure/bidirule golang.org/x/text/transform golang.org/x/text/unicode/bidi From 38a42d014367361d980198648a9e05696ef18f67 Mon Sep 17 00:00:00 2001 From: Ankur Date: Wed, 22 Jul 2026 14:44:35 +0100 Subject: [PATCH 033/182] Migrate k6 cloud run --local-execution to provisioning API (#6169) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add provisioning package skeleton New internal/cloudapi/provisioning package owns the local-execution flow's interactions with the v6 cloud API and the provisioning endpoints. This commit lays out the skeleton: Client construction, Config, error wrapping, and a reusable test server stub. API methods land in subsequent commits. Mirrors the existing internal/cloudapi/v6 conventions. * Add CreateOrFindLoadTest to v6.Client New public method that creates a load test by name only (no script) in a project, or returns the ID of an existing test on 409 conflict. Used by the upcoming provisioning flow, which uploads the archive out-of-band via a presigned S3 URL. Reuses the existing private findTestByName helper for the conflict fallback. * Add StartLocalExecution to provisioning Client POST .../start_local_execution returns the test run ID, the optional presigned archive upload URL, the runtime configuration (metrics push URL, scoped test_run_token, secrets endpoint and response_path), and the test run details page URL. Includes a K6-Idempotency-Key header for safe retries. * Add UploadArchive to provisioning.Client PUT pre-serialised archive bytes to the presigned S3 URL returned by StartLocalExecution. The URL is presigned (auth in query params), so no Authorization header is set. Retries on 5xx and transport errors; does not retry on 4xx. * Add WaitForTestRunReady polling helper Polls GET /cloud/v6/test_runs/{id} via the embedded v6.Client.FetchTest until the backend status becomes `initializing` (signalling that k6 can begin local execution). Returns an error if the test run reaches `aborted` or `completed` first. Cancellable via context. Logs status transitions at Info level once per change. * Add NotifyTestRunCompleted to provisioning Client POST /provisioning/v1/test_runs/{id}/notify reports the script_execution_completed event with an optional mapped error code. Uses the generated SDK method with a scoped test_run_token via ContextAccessToken. The mapping helper translates k6 abort reasons to canonical k6-cloud notify codes: AbortedByUser/ScriptAbort/ Threshold -> 8036, AbortedByScriptError -> 8035, AbortedByTimeout/Output -> 8034, AbortedByThresholdsAfterTestEnd -> nil (normal end). * Add ProvisionLocalExecution orchestrator Compose CreateOrFindLoadTest (v6) → StartLocalExecution → optional UploadArchive → WaitForTestRunReady into a single ProvisionLocalExecution method on provisioning.Client. Return the test run ID, the details page URL, and the full runtime configuration (metrics push URL, scoped test_run_token, secrets endpoint + response_path). Propagate SetStackID to the embedded v6 client so CreateOrFindLoadTest sends the correct X-Stack-Id header. NotifyTestRunCompleted is not called here — that runs at the end of the test from the cloud Output. * Add HTTPClient for provisioning metrics push provisioning.HTTPClient is a Bearer-authenticated HTTP layer used by the cloud Output's expv2 metrics push when in provisioning mode. It signs requests with the scoped test_run_token, retries on 5xx and transport errors, and decodes JSON responses into a caller-provided struct. * Rename metricsHTTPClient interface Mechanical rename of metricsHTTPClient to metricsHTTPClientWithBaseURL in the expv2 package. The renamed interface still requires both Do and BaseURL; behaviour is unchanged. The mock struct is also renamed for consistency. This frees up the metricsHTTPClient name for a smaller interface (Do-only) in the next commit, used by the provisioning-mode metrics pipeline. * Refactor metricsClient HTTP interface split Add a smaller metricsHTTPClient interface with only Do; have metricsHTTPClientWithBaseURL embed it. Narrow the metricsClient struct field type to the smaller interface — BaseURL is only used at construction time in the legacy constructor, not post-construction. No call-site changes; no behaviour change. This prepares for an explicit-URL constructor that only needs Do, required by provisioning-mode metrics push whose HTTP layer has no meaningful base URL. * Add explicit-URL constructor and Output setters Add newMetricsClientWithURL, a sibling to newMetricsClient that takes an explicit push URL and a smaller metricsHTTPClient (Do-only). Add SetMetricsHTTPClient and SetMetricsURL on expv2.Output; when both are set before Start, the explicit constructor is used instead of legacy URL derivation. Existing call sites that don't call the setters are unchanged. Used by the upcoming cloud Output provisioning-mode branch. * Add MetricsPushURL and TestRunToken to Config Two new fields on cloudapi.Config, JSON-tagged but not envconfig-tagged. Used by the upcoming `k6 cloud run --local-execution` provisioning flow to pass the metrics push URL and scoped token from cmd to the cloud Output via the existing Config-JSON round-trip pipeline. Internal-only; not exposed to users via env vars. When unset (the default for `--out cloud` and the PushRefID flow), behaviour is unchanged. The JSON round-trip test doubles as the security regression: the new fields live on cloudapi.Config (in-process JSON-Collectors blob only), never on lib.Options (which would be serialised into the archive). * Add expv2 provisioning-mode config in Start When cloudapi.Config.MetricsPushURL is set (signalling provisioning mode populated by cmd/outputs_cloud.go), the cloud Output's existing testRunID branch lazy- constructs a provisioning.HTTPClient with the scoped test_run_token and a *provisioning.Client, then configures the underlying expv2.Output via SetMetricsHTTPClient + SetMetricsURL before startVersionedOutput returns. PushRefID retains its existing precedence; --out cloud is unaffected when the new Config fields are unset. * Add notify branch in Output.testFinished When the cloud Output is in provisioning mode (Config has MetricsPushURL + TestRunToken), testFinished calls NotifyTestRunCompleted instead of the legacy TestFinished. PushRefID continues to short-circuit before either path. Path B (--out cloud) keeps using TestFinished unchanged. * Use provisioning API for local-execution Replace the v1 createTestRun path in createCloudTest with provisioning.Client.ProvisionLocalExecution, which orchestrates: CreateOrFindLoadTest -> StartLocalExecution -> UploadArchive (optional) -> WaitForTestRunReady Runtime config returned by the provisioning API is mapped to cloudapi.Config fields (push interval, push concurrency, aggregation periods, max samples per package). AggregationMinSamples is intentionally dropped because expv2 has no min-samples knob. Secrets config is registered from the provisioning response. The PushRefID short-circuit is unchanged. * Refactor provisioning-mode gate to explicit state testFinished and startVersionedOutput previously inferred provisioning mode from cloudapi.Config field presence (MetricsPushURL + TestRunToken). That made the gating asymmetric with Start()'s lazyInitProvisioning, which checks additional conditions (preset testRunID and !PushRefID). Introduce out.provisioningMode, set true only inside lazyInitProvisioning after both deps are constructed. Both read sites gate on it directly. The Config fields no longer participate in the runtime mode decision. The change is defensive — there is no current code path that populates the Config fields without lazyInitProvisioning also running. Keeping the decision encoded in explicit state removes the latent risk of a future divergence (e.g., a new config source) leaving stop-time logic with nil deps. * Remove unused provisioning Config The Config struct and its Apply method in the provisioning package were referenced only by their own test — NewClient takes discrete parameters (token, host, version, stackID, timeout), never a Config. They were a leftover from the package skeleton that mirrored cloudapi/v6's Config shape but was never wired up. * Update provisioning archive size handling Address review feedback on the provisioning archive path: - ArchiveSize is a plain int64 (0 means no archive) instead of a *int64. 0 is still sent as explicit JSON null, and a real archive is never empty, so the null contract is preserved without a pointer. - Warn instead of silently skipping when an archive is present but start_local_execution returns no upload URL. * Refactor expv2 metrics client construction Collapse the two metricsClient constructors into a single newMetricsClientWithURL. The host-derived URL is now built by a small, testable deriveMetricsURL helper, and Start sets both the HTTP client and URL together, returning an error if only one is set rather than silently falling back to the derived URL. * Use distinct error for nil provisioning response StartLocalExecution returned the generic errUnknown when the SDK response was nil despite passing status/error checks. The SDK getters return zero values on a nil receiver, so removing the guard would silently produce an empty result. Keep the guard but return a distinct error so the unexpected condition is reported clearly. * Use int64 for the provisioning stack ID provisioning.NewClient now takes the stack ID as int64 and treats it as required (checkCloudLogin already guarantees it). The int32 X-Stack-Id boundary is confined to v6.SetStackID, which validates the range; the provisioning endpoints carry it as a decimal-string header. Removes the toInt32 stack-id conversions that leaked into cmd/outputs_cloud.go and output/cloud/output.go, so those layers work purely in int64. Resource IDs were already int64. * Reformat signature and drop a comment Collapse the ProvisionLocalExecution signature onto one line, and remove the multi-line justification comment above WaitForTestRunReady (always waiting for the run to be ready is self-evident). * Use distinct error for nil load-test response Swap the generic errUnknown for a distinct error when the SDK returns a nil response from CreateOrFindLoadTest despite passing the status/error checks. The SDK getters return zero values on a nil receiver, so keeping the guard avoids a silent bogus 0 id. * Add metricsPusher assertion in provisioning test TestOutputStart_ProvisioningMode injected the metricsPusher mock but never verified it. Feed a sample and confirm the stop-time flush pushes through the injected pusher, so the interface earns its test keep. * Use httperr to classify provisioning 401/403 provisioning.CheckResponse returned a generic ResponseError for every non-2xx status, including 401/403. Classify those via the shared httperr package so auth failures are reported consistently with the v1 and v6 clients. The shared CheckResponse skeleton extraction across all three clients remains for the follow-up cleanup PR. * Refactor provisioning retry into shared helper Both Client.doWithRetry (archive upload) and HTTPClient.Do (metrics push / notify) ran near-identical manual retry loops. Extract a single package-level doWithRetry(httpClient, req) that both call: Client keeps a thin wrapper, and HTTPClient sets its headers, calls the helper, then keeps its CheckResponse + decode. Replace the retry-wait time.Sleep with a select on time.After and req.Context().Done() so a cancelled request stops waiting promptly instead of blocking for the full RetryInterval. Body reset via GetBody, 5xx+transport retry, and MaxRetries/RetryInterval behaviour are otherwise unchanged. Clarify the Client and HTTPClient doc comments so the reason both exist is explicit, and add a test covering the context-cancellation path. * Add shared k6cloud client config builder v6.NewClient and provisioning.NewClient built their k6cloud.Configuration almost identically: same User-Agent, single server, HTTP transport, and retry settings, differing only in the server description. Extract a shared clientcfg.New(host, version, description, timeout) and have both call it. The retry values (MaxRetries, RetryInterval) matched between the two packages, so they now live once in clientcfg as the single source of truth. The provisioning retry helper and its test reference clientcfg.MaxRetries / clientcfg.RetryInterval; behaviour is unchanged (User-Agent, servers, transport, retry settings). clientcfg is a neutral package under internal/cloudapi, mirroring internal/cloudapi/httperr, so both v6 and provisioning can import it without an import cycle (provisioning already imports v6). --- cloudapi/config.go | 22 +- cloudapi/config_test.go | 91 +++ internal/cloudapi/clientcfg/clientcfg.go | 42 ++ internal/cloudapi/provisioning/api.go | 292 ++++++++ internal/cloudapi/provisioning/api_test.go | 628 ++++++++++++++++++ internal/cloudapi/provisioning/client.go | 140 ++++ internal/cloudapi/provisioning/client_test.go | 38 ++ internal/cloudapi/provisioning/doc.go | 5 + internal/cloudapi/provisioning/errors.go | 51 ++ internal/cloudapi/provisioning/errors_test.go | 62 ++ internal/cloudapi/provisioning/http_client.go | 78 +++ .../cloudapi/provisioning/http_client_test.go | 191 ++++++ internal/cloudapi/provisioning/notify.go | 86 +++ internal/cloudapi/provisioning/notify_test.go | 56 ++ internal/cloudapi/provisioning/provision.go | 110 +++ .../cloudapi/provisioning/provision_test.go | 512 ++++++++++++++ internal/cloudapi/provisioning/test/server.go | 216 ++++++ internal/cloudapi/v6/api.go | 31 + internal/cloudapi/v6/api_test.go | 110 +++ internal/cloudapi/v6/client.go | 23 +- internal/cmd/outputs_cloud.go | 148 ++++- internal/cmd/outputs_cloud_test.go | 152 +++++ internal/cmd/tests/cmd_cloud_run_test.go | 321 ++++++--- internal/output/cloud/output.go | 117 ++++ internal/output/cloud/output_test.go | 303 ++++++++- output/cloud/expv2/metrics_client.go | 42 +- output/cloud/expv2/metrics_client_test.go | 51 +- output/cloud/expv2/output.go | 37 +- output/cloud/expv2/output_test.go | 30 + 29 files changed, 3798 insertions(+), 187 deletions(-) create mode 100644 internal/cloudapi/clientcfg/clientcfg.go create mode 100644 internal/cloudapi/provisioning/api.go create mode 100644 internal/cloudapi/provisioning/api_test.go create mode 100644 internal/cloudapi/provisioning/client.go create mode 100644 internal/cloudapi/provisioning/client_test.go create mode 100644 internal/cloudapi/provisioning/doc.go create mode 100644 internal/cloudapi/provisioning/errors.go create mode 100644 internal/cloudapi/provisioning/errors_test.go create mode 100644 internal/cloudapi/provisioning/http_client.go create mode 100644 internal/cloudapi/provisioning/http_client_test.go create mode 100644 internal/cloudapi/provisioning/notify.go create mode 100644 internal/cloudapi/provisioning/notify_test.go create mode 100644 internal/cloudapi/provisioning/provision.go create mode 100644 internal/cloudapi/provisioning/provision_test.go create mode 100644 internal/cloudapi/provisioning/test/server.go create mode 100644 internal/cmd/outputs_cloud_test.go diff --git a/cloudapi/config.go b/cloudapi/config.go index d2846c93f..7ff3dd626 100644 --- a/cloudapi/config.go +++ b/cloudapi/config.go @@ -34,6 +34,20 @@ type Config struct { StopOnError null.Bool `json:"stopOnError" envconfig:"K6_CLOUD_STOP_ON_ERROR"` APIVersion null.Int `json:"apiVersion" envconfig:"K6_CLOUD_API_VERSION"` + // MetricsPushURL is the explicit URL to push metrics to, returned by + // the provisioning API's start_local_execution endpoint. When set, the + // cloud Output uses this URL instead of deriving one from Host. Set + // programmatically by `cmd/outputs_cloud.go` for the + // `k6 cloud run --local-execution` provisioning flow; never set via + // env vars or user-facing config. + MetricsPushURL null.String `json:"metricsPushURL"` + + // TestRunToken is the scoped test-run token returned by the + // provisioning API's start_local_execution endpoint. When set, the + // cloud Output uses it as the Bearer token for metrics push and notify. + // Set programmatically; never set via env vars or user-facing config. + TestRunToken null.String `json:"testRunToken"` + // PushRefID is the identifier used by k6 Cloud to correlate all the things that // belong to the same test run/execution. Currently, it is equivalent to the test run id. // But, in the future, or in future solutions (e.g. Synthetic Monitoring), there might be @@ -104,7 +118,7 @@ func NewConfig() Config { // Apply saves config non-zero config values from the passed config in the receiver. // -//nolint:cyclop,gocognit +//nolint:cyclop,funlen,gocognit func (c Config) Apply(cfg Config) Config { if cfg.StackID.Valid { c.StackID = cfg.StackID @@ -133,6 +147,12 @@ func (c Config) Apply(cfg Config) Config { if cfg.LogsTailURL.Valid && cfg.LogsTailURL.String != "" { c.LogsTailURL = cfg.LogsTailURL } + if cfg.MetricsPushURL.Valid { + c.MetricsPushURL = cfg.MetricsPushURL + } + if cfg.TestRunToken.Valid { + c.TestRunToken = cfg.TestRunToken + } if cfg.PushRefID.Valid { c.PushRefID = cfg.PushRefID } diff --git a/cloudapi/config_test.go b/cloudapi/config_test.go index 08c85e153..c4a4168e2 100644 --- a/cloudapi/config_test.go +++ b/cloudapi/config_test.go @@ -32,6 +32,8 @@ func TestConfigApply(t *testing.T) { Hostv6: null.NewString("Hostv6", true), Timeout: types.NewNullDuration(5*time.Second, true), LogsTailURL: null.NewString("LogsTailURL", true), + MetricsPushURL: null.NewString("MetricsPushURL", true), + TestRunToken: null.NewString("TestRunToken", true), PushRefID: null.NewString("PushRefID", true), WebAppURL: null.NewString("foo", true), NoCompress: null.NewBool(true, true), @@ -55,6 +57,95 @@ func TestConfigApply(t *testing.T) { assert.Equal(t, full, defaults.Apply(full)) } +// TestConfig_NewFieldsRoundTripThroughJSON also serves as the security +// regression for "scoped tokens stay in-process": the fields live on +// cloudapi.Config (which round-trips only via derivedConfig.Collectors[cloud]) +// and NOT on lib.Options (which is serialised into the archive's +// metadata.json and pushed to the cloud). A new field accidentally added +// to lib.Options would be serialised into the archive — but the new +// fields here are on cloudapi.Config, so they cannot leak that way. +func TestConfig_NewFieldsRoundTripThroughJSON(t *testing.T) { + t.Parallel() + + original := Config{ + MetricsPushURL: null.StringFrom("https://ingest.example/metrics/abc"), + TestRunToken: null.StringFrom("scoped-token-xyz"), + } + + data, err := json.Marshal(original) + require.NoError(t, err) + + assert.Contains(t, string(data), `"metricsPushURL":"https://ingest.example/metrics/abc"`) + assert.Contains(t, string(data), `"testRunToken":"scoped-token-xyz"`) + + var roundTripped Config + require.NoError(t, json.Unmarshal(data, &roundTripped)) + + assert.Equal(t, original.MetricsPushURL, roundTripped.MetricsPushURL) + assert.Equal(t, original.TestRunToken, roundTripped.TestRunToken) +} + +func TestConfig_NewFieldsNotPickedUpByEnvconfig(t *testing.T) { + t.Parallel() + + // Set env vars with every plausible name a user might guess. + envVars := map[string]string{ + "K6_CLOUD_METRICS_PUSH_URL": "foo", + "K6_CLOUD_TEST_RUN_TOKEN": "bar", + "K6_CLOUD_METRICSPUSHURL": "foo", + "K6_CLOUD_TESTRUNTOKEN": "bar", + } + + config, _, err := GetConsolidatedConfig(nil, envVars, "", nil) + require.NoError(t, err) + + assert.Equal(t, null.String{}, config.MetricsPushURL) + assert.Equal(t, null.String{}, config.TestRunToken) +} + +func TestConfig_Apply_MergesNewFields(t *testing.T) { + t.Parallel() + + cases := []struct { + name string + base Config + applied Config + wantPushURL null.String + wantRunToken null.String + }{ + { + name: "applied populated, base unset → uses applied", + base: Config{}, + applied: Config{MetricsPushURL: null.StringFrom("https://push.example"), TestRunToken: null.StringFrom("tok-1")}, + wantPushURL: null.StringFrom("https://push.example"), + wantRunToken: null.StringFrom("tok-1"), + }, + { + name: "applied unset, base populated → keeps base", + base: Config{MetricsPushURL: null.StringFrom("https://base.example"), TestRunToken: null.StringFrom("tok-base")}, + applied: Config{}, + wantPushURL: null.StringFrom("https://base.example"), + wantRunToken: null.StringFrom("tok-base"), + }, + { + name: "both populated → applied wins", + base: Config{MetricsPushURL: null.StringFrom("https://base.example"), TestRunToken: null.StringFrom("tok-base")}, + applied: Config{MetricsPushURL: null.StringFrom("https://applied.example"), TestRunToken: null.StringFrom("tok-applied")}, + wantPushURL: null.StringFrom("https://applied.example"), + wantRunToken: null.StringFrom("tok-applied"), + }, + } + + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + got := tc.base.Apply(tc.applied) + assert.Equal(t, tc.wantPushURL, got.MetricsPushURL) + assert.Equal(t, tc.wantRunToken, got.TestRunToken) + }) + } +} + func TestGetConsolidatedConfig(t *testing.T) { t.Parallel() config, warn, err := GetConsolidatedConfig(json.RawMessage(`{"token":"jsonraw"}`), nil, "", nil) diff --git a/internal/cloudapi/clientcfg/clientcfg.go b/internal/cloudapi/clientcfg/clientcfg.go new file mode 100644 index 000000000..25957a2a5 --- /dev/null +++ b/internal/cloudapi/clientcfg/clientcfg.go @@ -0,0 +1,42 @@ +// Package clientcfg builds the k6cloud SDK client Configuration shared by +// k6's internal cloud API clients (internal/cloudapi/v6 and +// internal/cloudapi/provisioning). Both need the same User-Agent, +// single-server list, HTTP transport, and retry settings; only the server +// description differs between them, so it is passed in. +package clientcfg + +import ( + "net/http" + "time" + + k6cloud "github.com/grafana/k6-cloud-openapi-client-go/k6" +) + +const ( + // RetryInterval is the default cloud request retry interval. + RetryInterval = 500 * time.Millisecond + // MaxRetries specifies max retry attempts. + MaxRetries = 3 +) + +// New builds a k6cloud.Configuration for a single-server cloud API client. +// host is the server URL, version sets the k6cloud/ User-Agent, +// description labels the server entry, and timeout bounds each HTTP +// request. Retry settings use the shared MaxRetries/RetryInterval. +func New(host, version, description string, timeout time.Duration) *k6cloud.Configuration { + cfg := k6cloud.NewConfiguration() + cfg.UserAgent = "k6cloud/" + version + cfg.Servers = k6cloud.ServerConfigurations{ + { + URL: host, + Description: description, + }, + } + cfg.HTTPClient = &http.Client{ + Timeout: timeout, + Transport: http.DefaultTransport, + } + cfg.MaxRetries = MaxRetries + cfg.RetryInterval = RetryInterval + return cfg +} diff --git a/internal/cloudapi/provisioning/api.go b/internal/cloudapi/provisioning/api.go new file mode 100644 index 000000000..fe037ac2e --- /dev/null +++ b/internal/cloudapi/provisioning/api.go @@ -0,0 +1,292 @@ +package provisioning + +import ( + "bytes" + "context" + "crypto/rand" + "encoding/hex" + "encoding/json" + "errors" + "fmt" + "io" + "math" + "net/http" + "time" + + k6cloud "github.com/grafana/k6-cloud-openapi-client-go/k6" + + v6 "go.k6.io/k6/v2/internal/cloudapi/v6" +) + +// defaultWaitPollInterval is the default interval between status polls +// when waiting for a test run to become ready. +const defaultWaitPollInterval = 2 * time.Second + +// StartLocalExecutionRequest contains the parameters for starting a local +// execution test run via the provisioning API. +type StartLocalExecutionRequest struct { + // Options is the pre-marshalled lib.Options JSON produced by cmd. + // Kept as json.RawMessage to preserve typed precision (custom + // marshallers on lib.Options work correctly). + Options json.RawMessage + + // MaxVUs is the maximum number of virtual users during the test. + MaxVUs int64 + + // TotalDuration is the total test duration in seconds. + TotalDuration int64 + + // ArchiveSize is the archive file size in bytes, or 0 when there is + // no archive (--no-archive-upload); 0 is sent as explicit JSON null. + // A real archive is never empty, so 0 unambiguously means "no archive". + ArchiveSize int64 +} + +// StartLocalExecutionResponse holds the fields returned by the +// start_local_execution endpoint that downstream consumers need. +type StartLocalExecutionResponse struct { + TestRunID int64 + ArchiveUploadURL *string // nil when no archive upload expected + RuntimeConfig RuntimeConfig + TestRunDetailsPageURL string +} + +// RuntimeConfig carries the runtime configuration returned by the +// provisioning API for a local-execution test run. +type RuntimeConfig struct { + Metrics MetricsConfig + TestRunToken string + Secrets SecretsConfig +} + +// MetricsConfig holds the metrics push configuration from the +// provisioning API's runtime_config.metrics object. +type MetricsConfig struct { + PushURL string + PushInterval *string + PushConcurrency *int32 + AggregationPeriod *string + AggregationWaitPeriod *string + AggregationMinSamples *int32 + MaxSamplesPerPackage *int32 +} + +// SecretsConfig holds the secrets configuration from the +// provisioning API's runtime_config.secrets object. +type SecretsConfig struct { + Endpoint string + ResponsePath string +} + +// UploadArchive PUTs pre-serialised archive bytes to the given +// presigned S3 URL. The URL carries auth in query params, so no +// Authorization header is set. Retries on 5xx and transport errors. +func (c *Client) UploadArchive(ctx context.Context, uploadURL string, body []byte) error { + req, err := http.NewRequestWithContext(ctx, http.MethodPut, uploadURL, bytes.NewReader(body)) + if err != nil { + return fmt.Errorf("creating upload request: %w", err) + } + req.Header.Set("Content-Type", "application/x-tar") + req.ContentLength = int64(len(body)) + + resp, err := c.doWithRetry(req) + if err != nil { + return fmt.Errorf("uploading archive: %w", err) + } + defer func() { + _, _ = io.Copy(io.Discard, resp.Body) + _ = resp.Body.Close() + }() + + if resp.StatusCode < 200 || resp.StatusCode >= 300 { + respBody, readErr := io.ReadAll(resp.Body) + if readErr != nil || len(respBody) == 0 { + return fmt.Errorf("archive upload failed: %d %s", + resp.StatusCode, http.StatusText(resp.StatusCode)) + } + return fmt.Errorf("archive upload failed: %d %s: %s", + resp.StatusCode, http.StatusText(resp.StatusCode), respBody) + } + + return nil +} + +// WaitForTestRunReady polls GET /cloud/v6/test_runs/{id} until the +// backend status becomes "initializing" (signalling that k6 can begin +// local execution). Returns an error if the test run reaches "aborted" +// or "completed" first. Cancellable via context. Logs status transitions +// at Info level once per change. +// +// If pollInterval is <= 0 the defaultWaitPollInterval is used. +func (c *Client) WaitForTestRunReady(ctx context.Context, testRunID int64, pollInterval time.Duration) error { + if pollInterval <= 0 { + pollInterval = defaultWaitPollInterval + c.logger.WithField("interval", pollInterval).Info("using default poll interval") + } + + var lastStatus string + + for { + progress, err := c.v6Client.FetchTest(ctx, testRunID) + if err != nil { + return fmt.Errorf("fetching test status: %w", err) + } + + status := progress.Status.String() + + switch v6.Status(status) { + case v6.StatusInitializing: + return nil + + case v6.StatusAborted: + var abortMsg string + for _, e := range progress.StatusHistory { + if e.Status == v6.StatusAborted && e.Message != "" { + abortMsg = e.Message + break + } + } + if abortMsg != "" { + return fmt.Errorf("test run aborted before starting: %s", abortMsg) + } + return fmt.Errorf("test run aborted before starting") + + case v6.StatusCompleted: + return fmt.Errorf("test run completed before k6 could start") + + default: + // created, queued, or any unrecognised state — keep polling. + if status != lastStatus { + c.logger.WithField("status", progress.FormatStatus()).Info("test status") + lastStatus = status + } + } + + select { + case <-ctx.Done(): + return ctx.Err() + case <-time.After(pollInterval): + // continue polling + } + } +} + +// StartLocalExecution starts a local-execution test run via the +// provisioning API. It generates a K6-Idempotency-Key header for +// safe retries. The caller provides options as pre-marshalled JSON. +func (c *Client) StartLocalExecution( + ctx context.Context, loadTestID int64, req StartLocalExecutionRequest, +) (*StartLocalExecutionResponse, error) { + // Generate idempotency key: 8 random bytes hex-encoded (16 chars). + var key [8]byte + if _, err := rand.Read(key[:]); err != nil { + return nil, fmt.Errorf("generating idempotency key: %w", err) + } + + // SDK adapter: unmarshal json.RawMessage → map[string]any. + var opts map[string]any + if err := json.Unmarshal(req.Options, &opts); err != nil { + return nil, fmt.Errorf("unmarshalling options for SDK: %w", err) + } + + maxVUs, err := toInt32(req.MaxVUs) + if err != nil { + return nil, fmt.Errorf("max_vus: %w", err) + } + totalDuration, err := toInt32(req.TotalDuration) + if err != nil { + return nil, fmt.Errorf("total_duration: %w", err) + } + + sdkReq := k6cloud.NewStartLocalExecutionTestRequest(opts, maxVUs, totalDuration) + + if req.ArchiveSize > 0 { + v, err := toInt32(req.ArchiveSize) + if err != nil { + return nil, fmt.Errorf("archive_size: %w", err) + } + sdkReq.SetArchiveSize(v) + } else { + sdkReq.SetArchiveSizeNil() + } + + res, hr, err := c.apiClient.ProvisioningAPI. + StartLocalExecutionTest(c.authCtx(ctx), loadTestID). + K6IdempotencyKey(hex.EncodeToString(key[:])). + StartLocalExecutionTestRequest(sdkReq). + Execute() + defer closeResponse(hr, &err) + + if hr != nil { + if respErr := CheckResponse(hr); respErr != nil { + return nil, respErr + } + } + if err != nil { + return nil, err + } + if res == nil { + // Should not happen once the status/error checks above pass, but + // the SDK getters return zero values on a nil receiver, so guard + // against silently producing an empty result and report it clearly. + return nil, errors.New("unexpected nil response from start_local_execution") + } + + return mapStartLocalExecutionResponse(res), nil +} + +// mapStartLocalExecutionResponse converts the SDK response type into +// the package's domain type. +func mapStartLocalExecutionResponse(res *k6cloud.StartLocalExecutionTestResponse) *StartLocalExecutionResponse { + rc := res.GetRuntimeConfig() + m := rc.GetMetrics() + s := rc.GetSecrets() + + resp := &StartLocalExecutionResponse{ + TestRunID: res.GetTestRunId(), + TestRunDetailsPageURL: res.GetTestRunDetailsPageUrl(), + RuntimeConfig: RuntimeConfig{ + TestRunToken: rc.GetTestRunToken(), + Metrics: MetricsConfig{ + PushURL: m.GetPushUrl(), + PushInterval: m.PushInterval.Get(), + PushConcurrency: m.PushConcurrency.Get(), + AggregationPeriod: m.AggregationPeriod.Get(), + AggregationWaitPeriod: m.AggregationWaitPeriod.Get(), + AggregationMinSamples: m.AggregationMinSamples.Get(), + MaxSamplesPerPackage: m.MaxSamplesPerPackage.Get(), + }, + Secrets: SecretsConfig{ + Endpoint: s.GetEndpoint(), + ResponsePath: s.GetResponsePath(), + }, + }, + } + + if url := res.ArchiveUploadUrl.Get(); url != nil { + resp.ArchiveUploadURL = url + } + + return resp +} + +// toInt32 safely converts an int64 to int32, returning an error if +// the value overflows. +func toInt32(v int64) (int32, error) { + if v < math.MinInt32 || v > math.MaxInt32 { + return 0, fmt.Errorf("value %d overflows int32", v) + } + return int32(v), nil +} + +// closeResponse drains and closes an HTTP response body. It mirrors +// the v6 package's closeResponse helper. +func closeResponse(res *http.Response, rerr *error) { + if res == nil { + return + } + _, _ = io.Copy(io.Discard, res.Body) + if err := res.Body.Close(); err != nil && *rerr == nil { + *rerr = err + } +} diff --git a/internal/cloudapi/provisioning/api_test.go b/internal/cloudapi/provisioning/api_test.go new file mode 100644 index 000000000..d9a0b3be9 --- /dev/null +++ b/internal/cloudapi/provisioning/api_test.go @@ -0,0 +1,628 @@ +package provisioning + +import ( + "context" + "encoding/json" + "errors" + "io" + "net/http" + "sync/atomic" + "testing" + "time" + + "github.com/sirupsen/logrus" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "go.k6.io/k6/v2/errext" + provtest "go.k6.io/k6/v2/internal/cloudapi/provisioning/test" + v6 "go.k6.io/k6/v2/internal/cloudapi/v6" + "go.k6.io/k6/v2/internal/lib/testutils" +) + +func TestStartLocalExecution(t *testing.T) { + t.Parallel() + + var ( + method string + path string + body []byte + idempKey string + authHeader string + stackIDHdr string + userAgent string + ) + + srv := provtest.NewServer(t) + srv.HandleStartLocalExecution(provtest.DefaultLoadTestID, func(w http.ResponseWriter, r *http.Request) { + method = r.Method + path = r.URL.Path + idempKey = r.Header.Get("K6-Idempotency-Key") + authHeader = r.Header.Get("Authorization") + stackIDHdr = r.Header.Get("X-Stack-Id") + userAgent = r.Header.Get("User-Agent") + var err error + body, err = io.ReadAll(r.Body) + if err != nil { + http.Error(w, "read body", http.StatusInternalServerError) + return + } + + resp := provtest.DefaultStartLocalExecutionResponse() + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _ = json.NewEncoder(w).Encode(resp) + }) + + client, err := NewClient(testutils.NewLogger(t), "test-token", srv.URL, "0.42.0", 7, 5*time.Second) + require.NoError(t, err) + + opts := json.RawMessage(`{"vus":10,"duration":"30s"}`) + archiveSize := int64(1000) + req := StartLocalExecutionRequest{ + Options: opts, + MaxVUs: 50, + TotalDuration: 630, + ArchiveSize: archiveSize, + } + + got, err := client.StartLocalExecution(t.Context(), provtest.DefaultLoadTestID, req) + require.NoError(t, err) + + // --- Response assertions --- + assert.Equal(t, provtest.DefaultTestRunID, got.TestRunID) + require.NotNil(t, got.ArchiveUploadURL) + assert.Contains(t, *got.ArchiveUploadURL, "s3.amazonaws.com") + assert.Contains(t, got.TestRunDetailsPageURL, "/runs/") + assert.Equal(t, "https://ingest.k6.io/v1/metrics", got.RuntimeConfig.Metrics.PushURL) + assert.Equal(t, "test-run-token-abc", got.RuntimeConfig.TestRunToken) + assert.Equal(t, "https://api.k6.io/provisioning/v1/test_runs/123/decrypt_secret?name={key}", got.RuntimeConfig.Secrets.Endpoint) + assert.Equal(t, "plaintext", got.RuntimeConfig.Secrets.ResponsePath) + + // Metrics tuning fields. + require.NotNil(t, got.RuntimeConfig.Metrics.PushInterval) + assert.Equal(t, "2s", *got.RuntimeConfig.Metrics.PushInterval) + require.NotNil(t, got.RuntimeConfig.Metrics.PushConcurrency) + assert.Equal(t, int32(5), *got.RuntimeConfig.Metrics.PushConcurrency) + require.NotNil(t, got.RuntimeConfig.Metrics.AggregationPeriod) + assert.Equal(t, "3s", *got.RuntimeConfig.Metrics.AggregationPeriod) + require.NotNil(t, got.RuntimeConfig.Metrics.AggregationWaitPeriod) + assert.Equal(t, "1s", *got.RuntimeConfig.Metrics.AggregationWaitPeriod) + require.NotNil(t, got.RuntimeConfig.Metrics.MaxSamplesPerPackage) + assert.Equal(t, int32(2000), *got.RuntimeConfig.Metrics.MaxSamplesPerPackage) + + // --- Request assertions --- + assert.Equal(t, http.MethodPost, method) + assert.Equal(t, "/provisioning/v1/load_tests/456/start_local_execution", path) + assert.Equal(t, "Bearer test-token", authHeader) + assert.Equal(t, "7", stackIDHdr) + assert.Equal(t, "k6cloud/0.42.0", userAgent) + assert.Regexp(t, `^[0-9a-f]+$`, idempKey) + assert.GreaterOrEqual(t, len(idempKey), 1) + + // Request body shape. + var reqBody map[string]any + require.NoError(t, json.Unmarshal(body, &reqBody)) + assert.Equal(t, float64(50), reqBody["max_vus"]) + assert.Equal(t, float64(630), reqBody["total_duration"]) + assert.Equal(t, float64(1000), reqBody["archive_size"]) + + reqOpts, ok := reqBody["options"].(map[string]any) + require.True(t, ok, "options should be an object") + assert.Equal(t, float64(10), reqOpts["vus"]) + assert.Equal(t, "30s", reqOpts["duration"]) +} + +func TestStartLocalExecution_NoArchive_ArchiveSizeNull(t *testing.T) { + t.Parallel() + + var body []byte + + srv := provtest.NewServer(t) + srv.HandleStartLocalExecution(provtest.DefaultLoadTestID, func(w http.ResponseWriter, r *http.Request) { + var err error + body, err = io.ReadAll(r.Body) + if err != nil { + http.Error(w, "read body", http.StatusInternalServerError) + return + } + resp := provtest.DefaultStartLocalExecutionResponse() + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _ = json.NewEncoder(w).Encode(resp) + }) + + client, err := NewClient(testutils.NewLogger(t), "test-token", srv.URL, "0.42.0", 7, 5*time.Second) + require.NoError(t, err) + + req := StartLocalExecutionRequest{ + Options: json.RawMessage(`{"vus":1}`), + MaxVUs: 1, + TotalDuration: 60, + ArchiveSize: 0, // no archive + } + + _, err = client.StartLocalExecution(t.Context(), provtest.DefaultLoadTestID, req) + require.NoError(t, err) + + // Verify archive_size is explicit JSON null (not omitted, not zero). + var raw map[string]json.RawMessage + require.NoError(t, json.Unmarshal(body, &raw)) + + archiveRaw, exists := raw["archive_size"] + require.True(t, exists, "archive_size key must be present in request body") + assert.Equal(t, "null", string(archiveRaw), "archive_size must be JSON null") +} + +func TestStartLocalExecution_5xxRetried(t *testing.T) { + t.Parallel() + + var attempts atomic.Int32 + + srv := provtest.NewServer(t) + srv.HandleStartLocalExecution(provtest.DefaultLoadTestID, func(w http.ResponseWriter, _ *http.Request) { + if attempts.Add(1) == 1 { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusInternalServerError) + _, _ = w.Write([]byte(`{"error":{"code":"server_error","message":"temporary"}}`)) + return + } + resp := provtest.DefaultStartLocalExecutionResponse() + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _ = json.NewEncoder(w).Encode(resp) + }) + + client, err := NewClient(testutils.NewLogger(t), "test-token", srv.URL, "0.42.0", 7, 5*time.Second) + require.NoError(t, err) + + req := StartLocalExecutionRequest{ + Options: json.RawMessage(`{"vus":1}`), + MaxVUs: 1, + TotalDuration: 60, + ArchiveSize: 0, + } + + got, err := client.StartLocalExecution(t.Context(), provtest.DefaultLoadTestID, req) + require.NoError(t, err) + assert.Equal(t, provtest.DefaultTestRunID, got.TestRunID) + assert.Equal(t, int32(2), attempts.Load(), "expected exactly 2 attempts (1 failure + 1 success)") +} + +func TestUploadArchive(t *testing.T) { + t.Parallel() + + var ( + method string + reqPath string + contentType string + authHeader string + contentLength int64 + gotBody []byte + hitCount atomic.Int32 + ) + + srv := provtest.NewServer(t) + srv.HandlePresignedUpload(provtest.PresignedUploadPath, func(w http.ResponseWriter, r *http.Request) { + hitCount.Add(1) + method = r.Method + reqPath = r.URL.Path + contentType = r.Header.Get("Content-Type") + authHeader = r.Header.Get("Authorization") + contentLength = r.ContentLength + var err error + gotBody, err = io.ReadAll(r.Body) + if err != nil { + http.Error(w, "read body", http.StatusInternalServerError) + return + } + w.WriteHeader(http.StatusOK) + }) + + client, err := NewClient(testutils.NewLogger(t), "test-token", srv.URL, "0.42.0", 7, 5*time.Second) + require.NoError(t, err) + + archiveBody := []byte("fake-archive-tar-content-12345") + err = client.UploadArchive(t.Context(), srv.PresignedUploadURL(), archiveBody) + require.NoError(t, err) + + assert.Equal(t, http.MethodPut, method) + assert.Equal(t, provtest.PresignedUploadPath, reqPath) + assert.Equal(t, "application/x-tar", contentType) + assert.Empty(t, authHeader, "presigned URLs must not carry an Authorization header") + assert.Equal(t, archiveBody, gotBody) + assert.Equal(t, int64(len(archiveBody)), contentLength) + assert.Equal(t, int32(1), hitCount.Load(), "server should be hit exactly once") +} + +func TestUploadArchive_RetriesOn5xx(t *testing.T) { + t.Parallel() + + var ( + attempts atomic.Int32 + body1 []byte + body2 []byte + ) + + srv := provtest.NewServer(t) + srv.HandlePresignedUpload(provtest.PresignedUploadPath, func(w http.ResponseWriter, r *http.Request) { + b, _ := io.ReadAll(r.Body) + if attempts.Add(1) == 1 { + body1 = b + w.WriteHeader(http.StatusInternalServerError) + return + } + body2 = b + w.WriteHeader(http.StatusOK) + }) + + client, err := NewClient(testutils.NewLogger(t), "test-token", srv.URL, "0.42.0", 7, 5*time.Second) + require.NoError(t, err) + + archiveBody := []byte("archive-bytes-for-retry-test") + err = client.UploadArchive(t.Context(), srv.PresignedUploadURL(), archiveBody) + require.NoError(t, err) + + assert.Equal(t, int32(2), attempts.Load(), "expected exactly 2 attempts (1 failure + 1 success)") + assert.Equal(t, body1, body2, "body replay should produce identical bytes on retry") +} + +func TestUploadArchive_4xxNotRetried(t *testing.T) { + t.Parallel() + + var attempts atomic.Int32 + + srv := provtest.NewServer(t) + srv.HandlePresignedUpload(provtest.PresignedUploadPath, func(w http.ResponseWriter, _ *http.Request) { + attempts.Add(1) + w.WriteHeader(http.StatusForbidden) + _, _ = w.Write([]byte("Request has expired")) + }) + + client, err := NewClient(testutils.NewLogger(t), "test-token", srv.URL, "0.42.0", 7, 5*time.Second) + require.NoError(t, err) + + archiveBody := []byte("archive-bytes-for-4xx-test") + err = client.UploadArchive(t.Context(), srv.PresignedUploadURL(), archiveBody) + require.Error(t, err) + + assert.Contains(t, err.Error(), "403") + assert.Contains(t, err.Error(), "Request has expired") + assert.Equal(t, int32(1), attempts.Load(), "4xx must not be retried") +} + +func TestStartLocalExecution_4xxNotRetried(t *testing.T) { + t.Parallel() + + var attempts atomic.Int32 + + srv := provtest.NewServer(t) + srv.HandleStartLocalExecution(provtest.DefaultLoadTestID, func(w http.ResponseWriter, _ *http.Request) { + attempts.Add(1) + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusBadRequest) + _, _ = w.Write([]byte(`{"error":{"code":"validation_error","message":"invalid options"}}`)) + }) + + client, err := NewClient(testutils.NewLogger(t), "test-token", srv.URL, "0.42.0", 7, 5*time.Second) + require.NoError(t, err) + + req := StartLocalExecutionRequest{ + Options: json.RawMessage(`{"vus":1}`), + MaxVUs: 1, + TotalDuration: 60, + ArchiveSize: 0, + } + + _, err = client.StartLocalExecution(t.Context(), provtest.DefaultLoadTestID, req) + require.Error(t, err) + + var respErr *ResponseError + require.ErrorAs(t, err, &respErr) + assert.Equal(t, http.StatusBadRequest, respErr.StatusCode) + assert.Equal(t, int32(1), attempts.Load(), "4xx must not be retried") +} + +func TestWaitForTestRunReady(t *testing.T) { + t.Parallel() + + srv := provtest.NewServer(t) + srv.HandleFetchTestRun(provtest.DefaultTestRunID, []v6.TestProgress{ + {Status: v6.StatusInitializing}, + }) + + client, err := NewClient(testutils.NewLogger(t), "test-token", srv.URL, "0.42.0", 7, 5*time.Second) + require.NoError(t, err) + + err = client.WaitForTestRunReady(t.Context(), provtest.DefaultTestRunID, 1*time.Microsecond) + require.NoError(t, err) + + assert.Equal(t, int32(1), srv.FetchTestRunHitCount(), "server should be hit exactly once") +} + +func TestWaitForTestRunReady_PollsUntilInitializing(t *testing.T) { + t.Parallel() + + srv := provtest.NewServer(t) + srv.HandleFetchTestRun(provtest.DefaultTestRunID, []v6.TestProgress{ + {Status: v6.StatusCreated}, + {Status: v6.StatusQueued}, + {Status: v6.StatusInitializing}, + }) + + client, err := NewClient(testutils.NewLogger(t), "test-token", srv.URL, "0.42.0", 7, 5*time.Second) + require.NoError(t, err) + + err = client.WaitForTestRunReady(t.Context(), provtest.DefaultTestRunID, 1*time.Microsecond) + require.NoError(t, err) + + assert.Equal(t, int32(3), srv.FetchTestRunHitCount(), "server should be hit 3 times") +} + +func TestWaitForTestRunReady_AbortedReturnsErrorWithMessage(t *testing.T) { + t.Parallel() + + srv := provtest.NewServer(t) + srv.HandleFetchTestRun(provtest.DefaultTestRunID, []v6.TestProgress{ + { + Status: v6.StatusAborted, + StatusHistory: []v6.StatusEvent{ + {Status: v6.StatusAborted, Message: "quota exceeded"}, + }, + }, + }) + + client, err := NewClient(testutils.NewLogger(t), "test-token", srv.URL, "0.42.0", 7, 5*time.Second) + require.NoError(t, err) + + err = client.WaitForTestRunReady(t.Context(), provtest.DefaultTestRunID, 1*time.Microsecond) + require.Error(t, err) + assert.Contains(t, err.Error(), "quota exceeded") +} + +func TestWaitForTestRunReady_AbortedNoHistoryReturnsGenericError(t *testing.T) { + t.Parallel() + + srv := provtest.NewServer(t) + srv.HandleFetchTestRun(provtest.DefaultTestRunID, []v6.TestProgress{ + {Status: v6.StatusAborted}, + }) + + client, err := NewClient(testutils.NewLogger(t), "test-token", srv.URL, "0.42.0", 7, 5*time.Second) + require.NoError(t, err) + + err = client.WaitForTestRunReady(t.Context(), provtest.DefaultTestRunID, 1*time.Microsecond) + require.Error(t, err) + assert.Contains(t, err.Error(), "test run aborted before starting") +} + +func TestWaitForTestRunReady_CompletedReturnsError(t *testing.T) { + t.Parallel() + + srv := provtest.NewServer(t) + srv.HandleFetchTestRun(provtest.DefaultTestRunID, []v6.TestProgress{ + {Status: v6.StatusCompleted}, + }) + + client, err := NewClient(testutils.NewLogger(t), "test-token", srv.URL, "0.42.0", 7, 5*time.Second) + require.NoError(t, err) + + err = client.WaitForTestRunReady(t.Context(), provtest.DefaultTestRunID, 1*time.Microsecond) + require.Error(t, err) + assert.Contains(t, err.Error(), "completed") +} + +func TestWaitForTestRunReady_UnknownStatusKeepsPolling(t *testing.T) { + t.Parallel() + + srv := provtest.NewServer(t) + srv.HandleFetchTestRun(provtest.DefaultTestRunID, []v6.TestProgress{ + {Status: v6.Status("weird-state")}, + {Status: v6.StatusInitializing}, + }) + + client, err := NewClient(testutils.NewLogger(t), "test-token", srv.URL, "0.42.0", 7, 5*time.Second) + require.NoError(t, err) + + err = client.WaitForTestRunReady(t.Context(), provtest.DefaultTestRunID, 1*time.Microsecond) + require.NoError(t, err) + + assert.Equal(t, int32(2), srv.FetchTestRunHitCount(), "server should be hit twice") +} + +func TestWaitForTestRunReady_LogsTransitionsOnce(t *testing.T) { + t.Parallel() + + srv := provtest.NewServer(t) + srv.HandleFetchTestRun(provtest.DefaultTestRunID, []v6.TestProgress{ + {Status: v6.StatusCreated}, + {Status: v6.StatusCreated}, + {Status: v6.StatusQueued}, + {Status: v6.StatusQueued}, + {Status: v6.StatusInitializing}, + }) + + logger, hook := testutils.NewLoggerWithHook(t, logrus.InfoLevel) + client, err := NewClient(logger, "test-token", srv.URL, "0.42.0", 7, 5*time.Second) + require.NoError(t, err) + + err = client.WaitForTestRunReady(t.Context(), provtest.DefaultTestRunID, 1*time.Microsecond) + require.NoError(t, err) + + entries := hook.Drain() + // Filter to only info-level entries with a "status" field. + var statusEntries []logrus.Entry + for _, e := range entries { + if e.Level == logrus.InfoLevel { + if _, ok := e.Data["status"]; ok { + statusEntries = append(statusEntries, e) + } + } + } + + // Should have exactly 2 log entries: one for "created", one for "queued". + // "initializing" is a terminal success — no log for it. + require.Len(t, statusEntries, 2, + "expected exactly 2 status transition log entries (created, queued)") + assert.Equal(t, "Created", statusEntries[0].Data["status"]) + assert.Equal(t, "Queued", statusEntries[1].Data["status"]) +} + +func TestWaitForTestRunReady_ContextCancellation(t *testing.T) { + t.Parallel() + + srv := provtest.NewServer(t) + // Server always returns "created" — polling never terminates on its own. + srv.HandleFetchTestRun(provtest.DefaultTestRunID, []v6.TestProgress{ + {Status: v6.StatusCreated}, + }) + + client, err := NewClient(testutils.NewLogger(t), "test-token", srv.URL, "0.42.0", 7, 5*time.Second) + require.NoError(t, err) + + ctx, cancel := context.WithCancel(t.Context()) + + // Cancel after a small delay to let a few polls happen. + go func() { + time.Sleep(5 * time.Millisecond) + cancel() + }() + + err = client.WaitForTestRunReady(ctx, provtest.DefaultTestRunID, 1*time.Microsecond) + require.Error(t, err) + assert.ErrorIs(t, err, context.Canceled) +} + +func TestNotifyTestRunCompleted(t *testing.T) { + t.Parallel() + + var ( + method string + reqPath string + authHeader string + contentType string + userAgent string + body []byte + hitCount atomic.Int32 + ) + + srv := provtest.NewServer(t) + srv.HandleNotify(provtest.DefaultTestRunID, func(w http.ResponseWriter, r *http.Request) { + hitCount.Add(1) + method = r.Method + reqPath = r.URL.Path + authHeader = r.Header.Get("Authorization") + contentType = r.Header.Get("Content-Type") + userAgent = r.Header.Get("User-Agent") + var err error + body, err = io.ReadAll(r.Body) + if err != nil { + http.Error(w, "read body", http.StatusInternalServerError) + return + } + w.WriteHeader(http.StatusNoContent) + }) + + client, err := NewClient(testutils.NewLogger(t), "test-token", srv.URL, "0.42.0", 7, 5*time.Second) + require.NoError(t, err) + + err = client.NotifyTestRunCompleted(t.Context(), provtest.DefaultTestRunID, "scoped-token-xyz", nil) + require.NoError(t, err) + + // --- Request assertions --- + assert.Equal(t, http.MethodPost, method) + assert.Equal(t, "/provisioning/v1/test_runs/123/notify", reqPath) + assert.Equal(t, "Bearer scoped-token-xyz", authHeader) + assert.Equal(t, "application/json", contentType) + assert.Equal(t, "k6cloud/0.42.0", userAgent) + assert.Equal(t, int32(1), hitCount.Load(), "server should be hit exactly once") + + // Request body shape: event_type present, error null. + var reqBody map[string]any + require.NoError(t, json.Unmarshal(body, &reqBody)) + assert.Equal(t, "script_execution_completed", reqBody["event_type"]) + assert.Nil(t, reqBody["error"]) +} + +func TestNotifyTestRunCompleted_WithErrorInRequestBody(t *testing.T) { + t.Parallel() + + var body []byte + + srv := provtest.NewServer(t) + srv.HandleNotify(provtest.DefaultTestRunID, func(w http.ResponseWriter, r *http.Request) { + var err error + body, err = io.ReadAll(r.Body) + if err != nil { + http.Error(w, "read body", http.StatusInternalServerError) + return + } + w.WriteHeader(http.StatusNoContent) + }) + + client, err := NewClient(testutils.NewLogger(t), "test-token", srv.URL, "0.42.0", 7, 5*time.Second) + require.NoError(t, err) + + testErr := errext.WithAbortReasonIfNone(errors.New("TypeError: foo is not a function"), errext.AbortedByScriptError) + err = client.NotifyTestRunCompleted(t.Context(), provtest.DefaultTestRunID, "scoped-token-xyz", testErr) + require.NoError(t, err) + + // Request body should include the mapped error. + var reqBody struct { + EventType string `json:"event_type"` + Error *struct { + Code int `json:"code"` + Reason string `json:"reason"` + } `json:"error"` + } + require.NoError(t, json.Unmarshal(body, &reqBody)) + assert.Equal(t, "script_execution_completed", reqBody.EventType) + require.NotNil(t, reqBody.Error) + assert.Equal(t, 8035, reqBody.Error.Code) + assert.Contains(t, reqBody.Error.Reason, "TypeError") +} + +func TestNotifyTestRunCompleted_4xxResponseReturnsError(t *testing.T) { + t.Parallel() + + var hitCount atomic.Int32 + + srv := provtest.NewServer(t) + srv.HandleNotify(provtest.DefaultTestRunID, func(w http.ResponseWriter, _ *http.Request) { + hitCount.Add(1) + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusBadRequest) + _, _ = w.Write([]byte(`{"error":{"code":"validation_error","message":"bad event_type"}}`)) + }) + + client, err := NewClient(testutils.NewLogger(t), "test-token", srv.URL, "0.42.0", 7, 5*time.Second) + require.NoError(t, err) + + err = client.NotifyTestRunCompleted(t.Context(), provtest.DefaultTestRunID, "scoped-token-xyz", nil) + require.Error(t, err) + assert.Contains(t, err.Error(), "400") + assert.Contains(t, err.Error(), "bad event_type") + assert.Equal(t, int32(1), hitCount.Load(), "4xx must not be retried") +} + +func TestNotifyTestRunCompleted_5xxRetried(t *testing.T) { + t.Parallel() + + var hitCount atomic.Int32 + + srv := provtest.NewServer(t) + srv.HandleNotify(provtest.DefaultTestRunID, func(w http.ResponseWriter, _ *http.Request) { + if hitCount.Add(1) == 1 { + w.WriteHeader(http.StatusInternalServerError) + return + } + w.WriteHeader(http.StatusNoContent) + }) + + client, err := NewClient(testutils.NewLogger(t), "test-token", srv.URL, "0.42.0", 7, 5*time.Second) + require.NoError(t, err) + + err = client.NotifyTestRunCompleted(t.Context(), provtest.DefaultTestRunID, "scoped-token-xyz", nil) + require.NoError(t, err) + assert.Equal(t, int32(2), hitCount.Load(), "expected exactly 2 attempts (1 failure + 1 success)") +} diff --git a/internal/cloudapi/provisioning/client.go b/internal/cloudapi/provisioning/client.go new file mode 100644 index 000000000..a422ac7a9 --- /dev/null +++ b/internal/cloudapi/provisioning/client.go @@ -0,0 +1,140 @@ +package provisioning + +import ( + "context" + "fmt" + "io" + "net/http" + "strconv" + "time" + + k6cloud "github.com/grafana/k6-cloud-openapi-client-go/k6" + "github.com/sirupsen/logrus" + + "go.k6.io/k6/v2/internal/cloudapi/clientcfg" + v6 "go.k6.io/k6/v2/internal/cloudapi/v6" +) + +// Client orchestrates the provisioning and v6 cloud APIs for a +// local-execution test run: creating/finding the load test, starting the +// run, uploading the archive, polling for readiness, and posting the +// completion notification. It wraps a k6cloud.APIClient for the +// provisioning endpoints and an embedded v6.Client for test-run status +// queries. It is distinct from HTTPClient, which is the scoped-token +// Bearer HTTP layer injected into the expv2 metrics push. +type Client struct { + apiClient *k6cloud.APIClient + v6Client *v6.Client + token string + stackID int64 + host string + version string + + logger logrus.FieldLogger +} + +// NewClient returns a new provisioning Client. It internally constructs +// both a k6cloud.APIClient (for provisioning endpoints) and a v6.Client +// (for v6 operations like FetchTest). The stackID identifies the +// Grafana Cloud stack and is required for the stack-scoped requests. +func NewClient( + logger logrus.FieldLogger, + token, host, version string, + stackID int64, + timeout time.Duration, +) (*Client, error) { + if token == "" { + return nil, fmt.Errorf("token is required to create provisioning API client") + } + + cfg := clientcfg.New(host, version, "k6 Cloud API (provisioning).", timeout) + + v6c, err := v6.NewClient(logger, token, host, version, timeout) + if err != nil { + return nil, fmt.Errorf("creating v6 client: %w", err) + } + + c := &Client{ + apiClient: k6cloud.NewAPIClient(cfg), + v6Client: v6c, + token: token, + stackID: stackID, + host: host, + version: version, + logger: logger, + } + // Propagate the stack ID to the embedded v6 client. v6.SetStackID + // validates that it fits the int32 the SDK's X-Stack-Id requires — + // that is the single place the int32 boundary is enforced. + if err := c.v6Client.SetStackID(stackID); err != nil { + return nil, err + } + // The provisioning endpoints carry the stack ID as a decimal-string + // default header, so no int32 narrowing is needed here. + c.apiClient.GetConfig().DefaultHeader["X-Stack-Id"] = strconv.FormatInt(stackID, 10) + return c, nil +} + +// authCtx returns a context carrying the API access token. +func (c *Client) authCtx(ctx context.Context) context.Context { + return context.WithValue(ctx, k6cloud.ContextAccessToken, c.token) +} + +// doWithRetry executes the request via the provisioning Client's HTTP +// client. It is a thin wrapper around the package-level doWithRetry; see +// that function for the retry semantics. +func (c *Client) doWithRetry(req *http.Request) (*http.Response, error) { + return doWithRetry(c.apiClient.GetConfig().HTTPClient, req) +} + +// doWithRetry runs req through httpClient, retrying on 5xx responses and +// transport errors up to clientcfg.MaxRetries times, resetting the body +// from req.GetBody before each attempt so a retried request with a body is +// not sent empty. The retry wait honours req.Context() so a cancelled +// request stops waiting promptly. 4xx responses are NOT retried. +func doWithRetry(httpClient *http.Client, req *http.Request) (*http.Response, error) { + var ( + lastErr error + lastResp *http.Response + ) + + for attempt := 1; attempt <= clientcfg.MaxRetries; attempt++ { + // The vendored SDK resets the body on its own internal retries, + // but this direct Do loop must do it itself. + if req.GetBody != nil { + body, err := req.GetBody() + if err != nil { + return nil, err + } + req.Body = body + } + + lastResp, lastErr = httpClient.Do(req) //nolint:gosec + if lastErr != nil { + if attempt < clientcfg.MaxRetries { + select { + case <-time.After(clientcfg.RetryInterval): + case <-req.Context().Done(): + return lastResp, req.Context().Err() + } + continue + } + break + } + + if lastResp.StatusCode >= 500 && attempt < clientcfg.MaxRetries { + _, _ = io.Copy(io.Discard, lastResp.Body) + _ = lastResp.Body.Close() + select { + case <-time.After(clientcfg.RetryInterval): + case <-req.Context().Done(): + return lastResp, req.Context().Err() + } + continue + } + + break + } + + return lastResp, lastErr +} diff --git a/internal/cloudapi/provisioning/client_test.go b/internal/cloudapi/provisioning/client_test.go new file mode 100644 index 000000000..9725569b9 --- /dev/null +++ b/internal/cloudapi/provisioning/client_test.go @@ -0,0 +1,38 @@ +package provisioning + +import ( + "testing" + "time" + + "github.com/sirupsen/logrus" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestNewClient(t *testing.T) { + t.Parallel() + + logger := logrus.New() + token := "test-token" + host := "https://api.k6.io" + version := "0.1.0" + stackID := int64(123) + timeout := 30 * time.Second + + c, err := NewClient(logger, token, host, version, stackID, timeout) + require.NoError(t, err) + + assert.Equal(t, logger, c.logger) + assert.Equal(t, token, c.token) + assert.Equal(t, stackID, c.stackID) + + // The underlying k6cloud.APIClient should be configured correctly. + require.NotNil(t, c.apiClient) + cfg := c.apiClient.GetConfig() + require.Len(t, cfg.Servers, 1) + assert.Equal(t, host, cfg.Servers[0].URL) + assert.Equal(t, timeout, cfg.HTTPClient.Timeout) + + // The internal v6 client should be constructed with the same auth params. + assert.NotNil(t, c.v6Client) +} diff --git a/internal/cloudapi/provisioning/doc.go b/internal/cloudapi/provisioning/doc.go new file mode 100644 index 000000000..703e6f3c2 --- /dev/null +++ b/internal/cloudapi/provisioning/doc.go @@ -0,0 +1,5 @@ +// Package provisioning owns the local-execution flow's interactions with the +// provisioning API endpoints and the v6 cloud API. It provides a Client +// for orchestrating load-test provisioning (start, archive upload, polling, +// notification) and wraps the v6 client for test-run status queries. +package provisioning diff --git a/internal/cloudapi/provisioning/errors.go b/internal/cloudapi/provisioning/errors.go new file mode 100644 index 000000000..75ea27e37 --- /dev/null +++ b/internal/cloudapi/provisioning/errors.go @@ -0,0 +1,51 @@ +package provisioning + +import ( + "errors" + "fmt" + "io" + "net/http" + + "go.k6.io/k6/v2/internal/cloudapi/httperr" +) + +var errUnknown = errors.New("an error occurred communicating with the provisioning API") + +// ResponseError represents an error returned by the provisioning API. +type ResponseError struct { + StatusCode int + Body string +} + +func (e *ResponseError) Error() string { + return fmt.Sprintf("provisioning API error (%d): %s", e.StatusCode, e.Body) +} + +// CheckResponse checks an HTTP response from the provisioning API. +// It returns nil if the status code is in the 2xx range, otherwise it +// returns a *ResponseError with the status code and response body. +func CheckResponse(resp *http.Response) error { + if resp == nil { + return errUnknown + } + + if c := resp.StatusCode; c >= 200 && c <= 299 { + return nil + } + + // Classify 401/403 to the shared sentinels so provisioning reports + // auth failures consistently with the v1 and v6 clients. + if classified := httperr.ClassifyStatus(resp.StatusCode); classified != nil { + return classified + } + + data, err := io.ReadAll(resp.Body) + if err != nil { + return errUnknown + } + + return &ResponseError{ + StatusCode: resp.StatusCode, + Body: string(data), + } +} diff --git a/internal/cloudapi/provisioning/errors_test.go b/internal/cloudapi/provisioning/errors_test.go new file mode 100644 index 000000000..d166a2e6d --- /dev/null +++ b/internal/cloudapi/provisioning/errors_test.go @@ -0,0 +1,62 @@ +package provisioning + +import ( + "io" + "net/http" + "strings" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestCheckResponse(t *testing.T) { + t.Parallel() + + cases := []struct { + name string + statusCode int + body string + wantErr bool + wantStatus int + }{ + {"2xx returns nil", 200, "{}", false, 0}, + {"4xx wraps as ResponseError", 400, `{"error":"bad"}`, true, 400}, + {"5xx wraps as ResponseError", 500, `{"error":"oops"}`, true, 500}, + } + + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + + resp := &http.Response{ + StatusCode: tc.statusCode, + Body: io.NopCloser(strings.NewReader(tc.body)), + } + + err := CheckResponse(resp) + if !tc.wantErr { + assert.NoError(t, err) + return + } + + require.Error(t, err) + var respErr *ResponseError + require.ErrorAs(t, err, &respErr) + assert.Equal(t, tc.wantStatus, respErr.StatusCode) + }) + } +} + +func TestResponseError_Error_FormatsStatusAndBody(t *testing.T) { + t.Parallel() + + re := &ResponseError{ + StatusCode: 422, + Body: "validation failed", + } + + msg := re.Error() + assert.Contains(t, msg, "422") + assert.Contains(t, msg, "validation failed") +} diff --git a/internal/cloudapi/provisioning/http_client.go b/internal/cloudapi/provisioning/http_client.go new file mode 100644 index 000000000..0ce17edea --- /dev/null +++ b/internal/cloudapi/provisioning/http_client.go @@ -0,0 +1,78 @@ +package provisioning + +import ( + "bytes" + "encoding/json" + "errors" + "fmt" + "io" + "net/http" + + "github.com/sirupsen/logrus" +) + +// HTTPClient is the scoped-token Bearer HTTP layer injected into the +// cloud Output's expv2 metrics push (and the notify call) when running +// in provisioning mode. It signs requests with the scoped +// test_run_token, retries on 5xx and transport errors via the shared +// doWithRetry helper, and decodes JSON responses into a caller-provided +// struct. Unlike Client, it drives no provisioning/v6 orchestration and +// implements only Do — not BaseURL — because the metrics URL is set +// explicitly by the caller (no client-side derivation). +type HTTPClient struct { + httpClient *http.Client + token string // scoped test_run_token + version string // for User-Agent + logger logrus.FieldLogger +} + +// NewHTTPClient constructs an HTTPClient for metrics push and notify +// in provisioning mode. version is used for the User-Agent header, +// matching the v1/v6 client convention `k6cloud/`. +func NewHTTPClient(httpClient *http.Client, token, version string, logger logrus.FieldLogger) *HTTPClient { + return &HTTPClient{httpClient: httpClient, token: token, version: version, logger: logger} +} + +// Do executes the request with Bearer auth, retries on 5xx and +// transport errors, and decodes the response body into v if non-nil. +func (p *HTTPClient) Do(req *http.Request, v any) error { + // Ensure GetBody is set so the body can be replayed on retries. + if req.Body != nil && req.GetBody == nil { + body, err := io.ReadAll(req.Body) + if err != nil { + return fmt.Errorf("reading request body: %w", err) + } + _ = req.Body.Close() + + req.GetBody = func() (io.ReadCloser, error) { + return io.NopCloser(bytes.NewReader(body)), nil + } + req.Body, _ = req.GetBody() + req.ContentLength = int64(len(body)) + } + + req.Header.Set("Authorization", "Bearer "+p.token) + req.Header.Set("User-Agent", "k6cloud/"+p.version) + + resp, err := doWithRetry(p.httpClient, req) + if err != nil { + return err + } + + defer func() { + _, _ = io.Copy(io.Discard, resp.Body) + _ = resp.Body.Close() + }() + + if err := CheckResponse(resp); err != nil { + return err + } + + if v != nil { + if err := json.NewDecoder(resp.Body).Decode(v); err != nil && !errors.Is(err, io.EOF) { + return fmt.Errorf("decoding response: %w", err) + } + } + + return nil +} diff --git a/internal/cloudapi/provisioning/http_client_test.go b/internal/cloudapi/provisioning/http_client_test.go new file mode 100644 index 000000000..9e09428be --- /dev/null +++ b/internal/cloudapi/provisioning/http_client_test.go @@ -0,0 +1,191 @@ +package provisioning + +import ( + "bytes" + "context" + "encoding/json" + "io" + "net/http" + "net/http/httptest" + "sync/atomic" + "testing" + "time" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "go.k6.io/k6/v2/internal/cloudapi/clientcfg" + "go.k6.io/k6/v2/internal/lib/testutils" +) + +func TestHTTPClient(t *testing.T) { + t.Parallel() + + var ( + gotAuth string + gotUA string + hits atomic.Int32 + ) + + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + hits.Add(1) + gotAuth = r.Header.Get("Authorization") + gotUA = r.Header.Get("User-Agent") + w.Header().Set("Content-Type", "application/json") + _ = json.NewEncoder(w).Encode(map[string]string{"foo": "bar"}) + })) + defer srv.Close() + + c := NewHTTPClient(srv.Client(), "scoped-token", "v1.2.3", testutils.NewLogger(t)) + + req, err := http.NewRequestWithContext(t.Context(), http.MethodPost, srv.URL, nil) + require.NoError(t, err) + + var target struct { + Foo string `json:"foo"` + } + err = c.Do(req, &target) + require.NoError(t, err) + + assert.Equal(t, "bar", target.Foo) + assert.Equal(t, "Bearer scoped-token", gotAuth) + assert.Equal(t, "k6cloud/v1.2.3", gotUA) + assert.Equal(t, int32(1), hits.Load()) +} + +func TestHTTPClient_NilVDoesNotDecode(t *testing.T) { + t.Parallel() + + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusNoContent) + })) + defer srv.Close() + + c := NewHTTPClient(srv.Client(), "tok", "v0.1.0", testutils.NewLogger(t)) + + req, err := http.NewRequestWithContext(t.Context(), http.MethodPost, srv.URL, nil) + require.NoError(t, err) + + err = c.Do(req, nil) + assert.NoError(t, err) +} + +func TestHTTPClient_RetriesOn5xx(t *testing.T) { + t.Parallel() + + var hits atomic.Int32 + + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + if hits.Add(1) == 1 { + w.WriteHeader(http.StatusInternalServerError) + return + } + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(`{}`)) + })) + defer srv.Close() + + c := NewHTTPClient(srv.Client(), "tok", "v0.1.0", testutils.NewLogger(t)) + + req, err := http.NewRequestWithContext(t.Context(), http.MethodPost, srv.URL, nil) + require.NoError(t, err) + + err = c.Do(req, nil) + assert.NoError(t, err) + assert.Equal(t, int32(2), hits.Load()) +} + +func TestHTTPClient_NoRetryOn4xx(t *testing.T) { + t.Parallel() + + var hits atomic.Int32 + + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + hits.Add(1) + w.WriteHeader(http.StatusBadRequest) + _, _ = w.Write([]byte(`{"error":"bad input"}`)) + })) + defer srv.Close() + + c := NewHTTPClient(srv.Client(), "tok", "v0.1.0", testutils.NewLogger(t)) + + req, err := http.NewRequestWithContext(t.Context(), http.MethodPost, srv.URL, nil) + require.NoError(t, err) + + err = c.Do(req, nil) + require.Error(t, err) + assert.Contains(t, err.Error(), "400") + assert.Contains(t, err.Error(), "bad input") + assert.Equal(t, int32(1), hits.Load()) +} + +func TestHTTPClient_ContextCancelStopsRetryWait(t *testing.T) { + t.Parallel() + + // Server always fails with 5xx so the client enters the retry wait. + hit := make(chan struct{}, 10) + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + hit <- struct{}{} + w.WriteHeader(http.StatusInternalServerError) + })) + defer srv.Close() + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + c := NewHTTPClient(srv.Client(), "tok", "v0.1.0", testutils.NewLogger(t)) + + req, err := http.NewRequestWithContext(ctx, http.MethodPost, srv.URL, nil) + require.NoError(t, err) + + // Cancel as soon as the first attempt reaches the server, so the + // retry wait (RetryInterval) is interrupted by the cancellation. + go func() { + <-hit + cancel() + }() + + start := time.Now() + err = c.Do(req, nil) + elapsed := time.Since(start) + + require.Error(t, err) + assert.ErrorIs(t, err, context.Canceled) + assert.Less(t, elapsed, clientcfg.RetryInterval, + "cancellation should interrupt the retry wait instead of sleeping the full interval") +} + +func TestHTTPClient_RequestBodyReplayedOnRetry(t *testing.T) { + t.Parallel() + + var ( + hits atomic.Int32 + body1 []byte + body2 []byte + ) + + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + b, _ := io.ReadAll(r.Body) + if hits.Add(1) == 1 { + body1 = b + w.WriteHeader(http.StatusInternalServerError) + return + } + body2 = b + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(`{}`)) + })) + defer srv.Close() + + payload := []byte(`{"metrics":[1,2,3]}`) + c := NewHTTPClient(srv.Client(), "tok", "v0.1.0", testutils.NewLogger(t)) + + req, err := http.NewRequestWithContext(t.Context(), http.MethodPost, srv.URL, bytes.NewReader(payload)) + require.NoError(t, err) + + err = c.Do(req, nil) + require.NoError(t, err) + assert.Equal(t, int32(2), hits.Load()) + assert.Equal(t, body1, body2, "body replay should produce identical bytes on retry") +} diff --git a/internal/cloudapi/provisioning/notify.go b/internal/cloudapi/provisioning/notify.go new file mode 100644 index 000000000..f3d01873d --- /dev/null +++ b/internal/cloudapi/provisioning/notify.go @@ -0,0 +1,86 @@ +package provisioning + +import ( + "context" + "errors" + "fmt" + + k6cloud "github.com/grafana/k6-cloud-openapi-client-go/k6" + + "go.k6.io/k6/v2/errext" +) + +// notifyError represents a script execution error in the notify +// request body, mapping k6 abort reasons to canonical k6-cloud codes. +type notifyError struct { + Code int32 + Reason string +} + +// mapTestErrorToNotifyCode translates a k6 test error (with an +// optional errext.AbortReason) into the canonical k6-cloud notify +// error code. Returns nil when the test completed without error or +// when the abort reason indicates a normal completion +// (AbortedByThresholdsAfterTestEnd). +func mapTestErrorToNotifyCode(testErr error) *notifyError { + if testErr == nil { + return nil + } + + var hasAbortReason errext.HasAbortReason + if errors.As(testErr, &hasAbortReason) { + switch hasAbortReason.AbortReason() { + case errext.AbortedByUser, errext.AbortedByScriptAbort: + return ¬ifyError{Code: 8036, Reason: testErr.Error()} + case errext.AbortedByThreshold: + return ¬ifyError{Code: 8036, Reason: testErr.Error()} + case errext.AbortedByThresholdsAfterTestEnd: + return nil + case errext.AbortedByScriptError: + return ¬ifyError{Code: 8035, Reason: testErr.Error()} + case errext.AbortedByTimeout, errext.AbortedByOutput: + return ¬ifyError{Code: 8034, Reason: testErr.Error()} + } + } + + return ¬ifyError{Code: 0, Reason: testErr.Error()} +} + +// NotifyTestRunCompleted posts a script_execution_completed event to +// POST /provisioning/v1/test_runs/{id}/notify using the generated SDK +// method. The scoped testRunToken is passed via context (not the +// long-lived API token). testErr is mapped to an optional error code +// in the request body. Retries on 5xx via the SDK's built-in retry; +// does not retry on 4xx. +func (c *Client) NotifyTestRunCompleted( + ctx context.Context, testRunID int64, testRunToken string, testErr error, +) error { + // Use the scoped test-run token instead of the long-lived API token. + // The SDK reads ContextAccessToken from the context and sets + // Authorization: Bearer . + scopedCtx := context.WithValue(ctx, k6cloud.ContextAccessToken, testRunToken) + + model := k6cloud.NewScriptExecutionCompletedNotificationApiModel("script_execution_completed") + if ne := mapTestErrorToNotifyCode(testErr); ne != nil { + model.SetError(*k6cloud.NewScriptExecutionError(ne.Code, ne.Reason)) + } else { + model.SetErrorNil() + } + + hr, err := c.apiClient.ProvisioningAPI. + TestRunsNotify(scopedCtx, testRunID). + ScriptExecutionCompletedNotificationApiModel(model). + Execute() + defer closeResponse(hr, &err) + + if hr != nil { + if respErr := CheckResponse(hr); respErr != nil { + return fmt.Errorf("notify test run completed: %w", respErr) + } + } + if err != nil { + return fmt.Errorf("notify test run completed: %w", err) + } + + return nil +} diff --git a/internal/cloudapi/provisioning/notify_test.go b/internal/cloudapi/provisioning/notify_test.go new file mode 100644 index 000000000..d8624f519 --- /dev/null +++ b/internal/cloudapi/provisioning/notify_test.go @@ -0,0 +1,56 @@ +package provisioning + +import ( + "errors" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "go.k6.io/k6/v2/errext" +) + +// abortErr constructs an error with an attached AbortReason, +// matching the pattern used elsewhere in k6's test suite. +func abortErr(reason errext.AbortReason, msg string) error { + return errext.WithAbortReasonIfNone(errors.New(msg), reason) +} + +func TestMapTestErrorToNotifyCode(t *testing.T) { + t.Parallel() + + cases := []struct { + name string + err error + wantNil bool + wantCode int32 + wantReasonContains string + }{ + {"nil returns nil", nil, true, 0, ""}, + {"AbortedByUser → 8036", abortErr(errext.AbortedByUser, "user pressed Ctrl+C"), false, 8036, "user"}, + {"AbortedByScriptAbort → 8036", abortErr(errext.AbortedByScriptAbort, "abort()"), false, 8036, "abort"}, + {"AbortedByScriptError → 8035", abortErr(errext.AbortedByScriptError, "TypeError"), false, 8035, "TypeError"}, + {"AbortedByOutput → 8034", abortErr(errext.AbortedByOutput, "cloud push failed"), false, 8034, "cloud"}, + {"AbortedByTimeout → 8034", abortErr(errext.AbortedByTimeout, "timeout"), false, 8034, "timeout"}, + {"AbortedByThreshold → 8036", abortErr(errext.AbortedByThreshold, "threshold crossed"), false, 8036, "threshold"}, + {"AbortedByThresholdsAfterTestEnd → nil (test completed)", abortErr(errext.AbortedByThresholdsAfterTestEnd, "post-end"), true, 0, ""}, + {"generic error → 0 (Unknown)", errors.New("something else"), false, 0, "something else"}, + } + + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + + got := mapTestErrorToNotifyCode(tc.err) + + if tc.wantNil { + assert.Nil(t, got) + return + } + + require.NotNil(t, got, "expected non-nil notifyError") + assert.Equal(t, tc.wantCode, got.Code) + assert.Contains(t, got.Reason, tc.wantReasonContains) + }) + } +} diff --git a/internal/cloudapi/provisioning/provision.go b/internal/cloudapi/provisioning/provision.go new file mode 100644 index 000000000..bdcd4f8ed --- /dev/null +++ b/internal/cloudapi/provisioning/provision.go @@ -0,0 +1,110 @@ +package provisioning + +import ( + "bytes" + "context" + "encoding/json" + "fmt" + "time" + + "go.k6.io/k6/v2/lib" +) + +// ProvisionParams contains the parameters for provisioning a local +// execution test run. +type ProvisionParams struct { + // Name is the load test name. + Name string + + // ProjectID is the cloud project ID. + ProjectID int64 + + // MaxVUs is the maximum number of virtual users. + MaxVUs int64 + + // TotalDuration is the total test duration in seconds. + TotalDuration int64 + + // Options is the pre-marshalled lib.Options JSON from cmd. + Options json.RawMessage + + // Archive is the test archive. Nil when --no-archive-upload is set. + Archive *lib.Archive + + // PollInterval is the interval between test-run status polls. + // Zero or negative uses the default interval. + PollInterval time.Duration +} + +// ProvisionResult contains the result of a successful provisioning +// operation. +type ProvisionResult struct { + // TestRunID is the ID of the provisioned test run. + TestRunID int64 + + // TestRunDetailsPageURL is the URL of the test run details page. + TestRunDetailsPageURL string + + // RuntimeConfig carries the metrics, secrets, and token + // configuration returned by the provisioning API. + RuntimeConfig RuntimeConfig +} + +// ProvisionLocalExecution orchestrates the full local-execution +// provisioning flow: CreateOrFindLoadTest → StartLocalExecution → +// optional UploadArchive → WaitForTestRunReady. +func (c *Client) ProvisionLocalExecution(ctx context.Context, params ProvisionParams) (*ProvisionResult, error) { + loadTestID, err := c.v6Client.CreateOrFindLoadTest(ctx, params.ProjectID, params.Name) + if err != nil { + return nil, fmt.Errorf("create or find load test: %w", err) + } + + // Serialise archive once to get its byte-length for the + // start_local_execution body. The same buffer is reused for + // the S3 upload to avoid a second serialisation. + var ( + archiveSize int64 + archiveBytes []byte + ) + if params.Archive != nil { + var buf bytes.Buffer + if err := params.Archive.Write(&buf); err != nil { + return nil, fmt.Errorf("serialising archive: %w", err) + } + archiveSize = int64(buf.Len()) + archiveBytes = buf.Bytes() + } + + sleReq := StartLocalExecutionRequest{ + Options: params.Options, + MaxVUs: params.MaxVUs, + TotalDuration: params.TotalDuration, + ArchiveSize: archiveSize, + } + + sleResp, err := c.StartLocalExecution(ctx, loadTestID, sleReq) + if err != nil { + return nil, fmt.Errorf("start local execution: %w", err) + } + + switch { + case params.Archive != nil && sleResp.ArchiveUploadURL != nil: + if err := c.UploadArchive(ctx, *sleResp.ArchiveUploadURL, archiveBytes); err != nil { + return nil, fmt.Errorf("upload archive: %w", err) + } + case params.Archive != nil && sleResp.ArchiveUploadURL == nil: + // We had an archive to upload but the API returned no upload URL; + // proceed without uploading rather than failing the run. + c.logger.Warn("archive present but provisioning API returned no upload URL; skipping archive upload") + } + + if err := c.WaitForTestRunReady(ctx, sleResp.TestRunID, params.PollInterval); err != nil { + return nil, fmt.Errorf("wait for test run ready: %w", err) + } + + return &ProvisionResult{ + TestRunID: sleResp.TestRunID, + TestRunDetailsPageURL: sleResp.TestRunDetailsPageURL, + RuntimeConfig: sleResp.RuntimeConfig, + }, nil +} diff --git a/internal/cloudapi/provisioning/provision_test.go b/internal/cloudapi/provisioning/provision_test.go new file mode 100644 index 000000000..93346be7f --- /dev/null +++ b/internal/cloudapi/provisioning/provision_test.go @@ -0,0 +1,512 @@ +package provisioning + +import ( + "encoding/json" + "fmt" + "io" + "net/http" + "net/url" + "sync" + "sync/atomic" + "testing" + "time" + + k6cloud "github.com/grafana/k6-cloud-openapi-client-go/k6" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + provtest "go.k6.io/k6/v2/internal/cloudapi/provisioning/test" + v6 "go.k6.io/k6/v2/internal/cloudapi/v6" + "go.k6.io/k6/v2/internal/lib/testutils" + "go.k6.io/k6/v2/lib" + "go.k6.io/k6/v2/lib/fsext" +) + +const ( + testLoadTestID int64 = 42 + testTestRunID int64 = 100 + testProjectID int64 = 1 +) + +// callRecorder tracks the sequence of HTTP endpoint calls for test assertions. +type callRecorder struct { + mu sync.Mutex + calls []string +} + +func (cr *callRecorder) record(name string) { + cr.mu.Lock() + defer cr.mu.Unlock() + cr.calls = append(cr.calls, name) +} + +func (cr *callRecorder) order() []string { + cr.mu.Lock() + defer cr.mu.Unlock() + return append([]string{}, cr.calls...) +} + +func (cr *callRecorder) count(name string) int { + cr.mu.Lock() + defer cr.mu.Unlock() + n := 0 + for _, c := range cr.calls { + if c == name { + n++ + } + } + return n +} + +func newTestArchive(t *testing.T) *lib.Archive { + t.Helper() + fs := fsext.NewMemMapFs() + require.NoError(t, fsext.WriteFile(fs, "/a.js", []byte(`// test`), 0o644)) + return &lib.Archive{ + Type: "js", + K6Version: "0.42.0", + FilenameURL: &url.URL{Scheme: "file", Path: "/a.js"}, + PwdURL: &url.URL{Scheme: "file", Path: "/"}, + Data: []byte(`// test`), + Filesystems: map[string]fsext.Fs{"file": fs}, + } +} + +// writeCreateResponse writes a v6 create-load-test response using testLoadTestID. +func writeCreateResponse(w http.ResponseWriter) { + res := k6cloud.NewLoadTestApiModelWithDefaults() + res.SetId(testLoadTestID) + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + if err := json.NewEncoder(w).Encode(res); err != nil { + panic(fmt.Errorf("encoding create response: %w", err)) + } +} + +// writeSLEResponse writes a StartLocalExecution response using +// testTestRunID and the given archive upload URL. +func writeSLEResponse(w http.ResponseWriter, uploadURL string) { + resp := provtest.DefaultStartLocalExecutionResponse() + resp.SetTestRunId(testTestRunID) + u := uploadURL + resp.ArchiveUploadUrl = *k6cloud.NewNullableString(&u) + resp.SetTestRunDetailsPageUrl(fmt.Sprintf("https://app.k6.io/runs/%d", testTestRunID)) + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + if err := json.NewEncoder(w).Encode(resp); err != nil { + panic(fmt.Errorf("encoding SLE response: %w", err)) + } +} + +func TestProvisionLocalExecution_WithArchive(t *testing.T) { + t.Parallel() + + var rec callRecorder + + srv := provtest.NewServer(t) + + // 1. Create-or-find → load test ID 42. + srv.HandleCreateLoadTest(testProjectID, func(w http.ResponseWriter, _ *http.Request) { + rec.record("create") + writeCreateResponse(w) + }) + + // 2. Start local execution → test run ID 100. + srv.HandleStartLocalExecution(testLoadTestID, func(w http.ResponseWriter, _ *http.Request) { + rec.record("start") + writeSLEResponse(w, srv.PresignedUploadURL()) + }) + + // 3. S3 presigned upload → 200. + srv.HandlePresignedUpload(provtest.PresignedUploadPath, func(w http.ResponseWriter, _ *http.Request) { + rec.record("upload") + w.WriteHeader(http.StatusOK) + }) + + // 4. Test-run poll → "initializing" immediately. + srv.HandleFetchTestRun(testTestRunID, []v6.TestProgress{ + {Status: v6.StatusInitializing}, + }) + + client, err := NewClient(testutils.NewLogger(t), "test-token", srv.URL, "0.42.0", 7, 5*time.Second) + require.NoError(t, err) + + result, err := client.ProvisionLocalExecution(t.Context(), ProvisionParams{ + Name: "my-test", + ProjectID: testProjectID, + MaxVUs: 50, + TotalDuration: 630, + Options: json.RawMessage(`{"vus":10,"duration":"30s"}`), + Archive: newTestArchive(t), + PollInterval: time.Microsecond, + }) + require.NoError(t, err) + + // --- ProvisionResult assertions --- + assert.Equal(t, testTestRunID, result.TestRunID) + assert.Contains(t, result.TestRunDetailsPageURL, "/runs/100") + assert.Equal(t, "https://ingest.k6.io/v1/metrics", result.RuntimeConfig.Metrics.PushURL) + assert.Equal(t, "test-run-token-abc", result.RuntimeConfig.TestRunToken) + assert.Equal(t, + "https://api.k6.io/provisioning/v1/test_runs/123/decrypt_secret?name={key}", + result.RuntimeConfig.Secrets.Endpoint) + assert.Equal(t, "plaintext", result.RuntimeConfig.Secrets.ResponsePath) + + // --- Call counts --- + assert.Equal(t, 1, rec.count("create")) + assert.Equal(t, 1, rec.count("start")) + assert.Equal(t, 1, rec.count("upload")) + assert.GreaterOrEqual(t, srv.FetchTestRunHitCount(), int32(1)) + + // --- Call order (create → start → upload; poll follows implicitly) --- + calls := rec.order() + require.Len(t, calls, 3) + assert.Equal(t, []string{"create", "start", "upload"}, calls) +} + +func TestProvisionLocalExecution_NoArchive(t *testing.T) { + t.Parallel() + + var sleBody []byte + + srv := provtest.NewServer(t) + + srv.HandleCreateLoadTest(testProjectID, func(w http.ResponseWriter, _ *http.Request) { + writeCreateResponse(w) + }) + + srv.HandleStartLocalExecution(testLoadTestID, func(w http.ResponseWriter, r *http.Request) { + var err error + sleBody, err = io.ReadAll(r.Body) + if err != nil { + http.Error(w, "read body", http.StatusInternalServerError) + return + } + writeSLEResponse(w, srv.PresignedUploadURL()) + }) + + var uploadHits atomic.Int32 + srv.HandlePresignedUpload(provtest.PresignedUploadPath, func(w http.ResponseWriter, _ *http.Request) { + uploadHits.Add(1) + w.WriteHeader(http.StatusOK) + }) + + srv.HandleFetchTestRun(testTestRunID, []v6.TestProgress{ + {Status: v6.StatusInitializing}, + }) + + client, err := NewClient(testutils.NewLogger(t), "test-token", srv.URL, "0.42.0", 7, 5*time.Second) + require.NoError(t, err) + + result, err := client.ProvisionLocalExecution(t.Context(), ProvisionParams{ + Name: "my-test", + ProjectID: testProjectID, + MaxVUs: 10, + TotalDuration: 60, + Options: json.RawMessage(`{"vus":1}`), + Archive: nil, + PollInterval: time.Microsecond, + }) + require.NoError(t, err) + + // archive_size must be explicit JSON null in the SLE request body. + var raw map[string]json.RawMessage + require.NoError(t, json.Unmarshal(sleBody, &raw)) + archiveRaw, exists := raw["archive_size"] + require.True(t, exists, "archive_size key must be present") + assert.Equal(t, "null", string(archiveRaw)) + + // S3 stub must NOT be called. + assert.Equal(t, int32(0), uploadHits.Load(), "upload must not be called when archive is nil") + + // Polling must still happen (unconditional). + assert.GreaterOrEqual(t, srv.FetchTestRunHitCount(), int32(1)) + + // ProvisionResult populated. + assert.Equal(t, testTestRunID, result.TestRunID) + assert.NotEmpty(t, result.TestRunDetailsPageURL) + assert.NotEmpty(t, result.RuntimeConfig.TestRunToken) +} + +func TestProvisionLocalExecution_409ConflictPropagatesToFindByName(t *testing.T) { + t.Parallel() + + srv := provtest.NewServer(t) + + // Create: POST → 409; GET (findByName) → matching test with ID 42. + srv.HandleCreateLoadTest(testProjectID, func(w http.ResponseWriter, r *http.Request) { + switch r.Method { + case http.MethodPost: + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusConflict) + _ = json.NewEncoder(w).Encode(map[string]any{ + "error": map[string]string{"code": "conflict", "message": "already exists"}, + }) + case http.MethodGet: + lt := k6cloud.NewLoadTestApiModelWithDefaults() + lt.SetId(testLoadTestID) + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _ = json.NewEncoder(w).Encode(map[string]any{"value": []any{lt}}) + } + }) + + srv.HandleStartLocalExecution(testLoadTestID, func(w http.ResponseWriter, _ *http.Request) { + writeSLEResponse(w, srv.PresignedUploadURL()) + }) + + srv.HandlePresignedUpload(provtest.PresignedUploadPath, func(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusOK) + }) + + srv.HandleFetchTestRun(testTestRunID, []v6.TestProgress{ + {Status: v6.StatusInitializing}, + }) + + client, err := NewClient(testutils.NewLogger(t), "test-token", srv.URL, "0.42.0", 7, 5*time.Second) + require.NoError(t, err) + + result, err := client.ProvisionLocalExecution(t.Context(), ProvisionParams{ + Name: "my-test", + ProjectID: testProjectID, + MaxVUs: 50, + TotalDuration: 630, + Options: json.RawMessage(`{"vus":10}`), + Archive: newTestArchive(t), + PollInterval: time.Microsecond, + }) + require.NoError(t, err) + + assert.Equal(t, testTestRunID, result.TestRunID) + assert.Contains(t, result.TestRunDetailsPageURL, "/runs/100") + assert.Equal(t, "test-run-token-abc", result.RuntimeConfig.TestRunToken) +} + +func TestProvisionLocalExecution_ArchivePresentButNoUploadURL(t *testing.T) { + t.Parallel() + + srv := provtest.NewServer(t) + + srv.HandleCreateLoadTest(testProjectID, func(w http.ResponseWriter, _ *http.Request) { + writeCreateResponse(w) + }) + + // start_local_execution returns no archive upload URL (null). + srv.HandleStartLocalExecution(testLoadTestID, func(w http.ResponseWriter, _ *http.Request) { + resp := provtest.DefaultStartLocalExecutionResponse() + resp.SetTestRunId(testTestRunID) + resp.ArchiveUploadUrl = *k6cloud.NewNullableString(nil) + resp.SetTestRunDetailsPageUrl(fmt.Sprintf("https://app.k6.io/runs/%d", testTestRunID)) + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + require.NoError(t, json.NewEncoder(w).Encode(resp)) + }) + + // The upload endpoint must not be hit when no URL is returned. + srv.HandlePresignedUpload(provtest.PresignedUploadPath, func(w http.ResponseWriter, _ *http.Request) { + t.Error("archive upload must not be attempted when no upload URL is returned") + w.WriteHeader(http.StatusOK) + }) + + srv.HandleFetchTestRun(testTestRunID, []v6.TestProgress{ + {Status: v6.StatusInitializing}, + }) + + client, err := NewClient(testutils.NewLogger(t), "test-token", srv.URL, "0.42.0", 7, 5*time.Second) + require.NoError(t, err) + + // Archive provided but API returns no upload URL: provisioning should + // still succeed (a warning is logged) and skip the upload. + result, err := client.ProvisionLocalExecution(t.Context(), ProvisionParams{ + Name: "my-test", + ProjectID: testProjectID, + MaxVUs: 50, + TotalDuration: 630, + Options: json.RawMessage(`{"vus":10}`), + Archive: newTestArchive(t), + PollInterval: time.Microsecond, + }) + require.NoError(t, err) + assert.Equal(t, testTestRunID, result.TestRunID) +} + +func TestProvisionLocalExecution_ErrorAtCreate(t *testing.T) { + t.Parallel() + + var rec callRecorder + + srv := provtest.NewServer(t) + + srv.HandleCreateLoadTest(testProjectID, func(w http.ResponseWriter, _ *http.Request) { + rec.record("create") + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusInternalServerError) + _ = json.NewEncoder(w).Encode(map[string]any{ + "error": map[string]string{"code": "server_error", "message": "internal error"}, + }) + }) + + srv.HandleStartLocalExecution(testLoadTestID, func(w http.ResponseWriter, _ *http.Request) { + rec.record("start") + w.WriteHeader(http.StatusOK) + }) + + srv.HandlePresignedUpload(provtest.PresignedUploadPath, func(w http.ResponseWriter, _ *http.Request) { + rec.record("upload") + w.WriteHeader(http.StatusOK) + }) + + srv.HandleFetchTestRun(testTestRunID, []v6.TestProgress{ + {Status: v6.StatusInitializing}, + }) + + client, err := NewClient(testutils.NewLogger(t), "test-token", srv.URL, "0.42.0", 7, 5*time.Second) + require.NoError(t, err) + + _, err = client.ProvisionLocalExecution(t.Context(), ProvisionParams{ + Name: "my-test", + ProjectID: testProjectID, + MaxVUs: 10, + TotalDuration: 60, + Options: json.RawMessage(`{"vus":1}`), + PollInterval: time.Microsecond, + }) + require.Error(t, err) + assert.Contains(t, err.Error(), "create or find load test") + + // Subsequent endpoints must not be called. + assert.Equal(t, 0, rec.count("start")) + assert.Equal(t, 0, rec.count("upload")) + assert.Equal(t, int32(0), srv.FetchTestRunHitCount()) +} + +func TestProvisionLocalExecution_ErrorAtStart(t *testing.T) { + t.Parallel() + + var rec callRecorder + + srv := provtest.NewServer(t) + + srv.HandleCreateLoadTest(testProjectID, func(w http.ResponseWriter, _ *http.Request) { + rec.record("create") + writeCreateResponse(w) + }) + + srv.HandleStartLocalExecution(testLoadTestID, func(w http.ResponseWriter, _ *http.Request) { + rec.record("start") + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusInternalServerError) + _, _ = w.Write([]byte(`{"error":{"code":"server_error","message":"start failed"}}`)) + }) + + srv.HandlePresignedUpload(provtest.PresignedUploadPath, func(w http.ResponseWriter, _ *http.Request) { + rec.record("upload") + w.WriteHeader(http.StatusOK) + }) + + srv.HandleFetchTestRun(testTestRunID, []v6.TestProgress{ + {Status: v6.StatusInitializing}, + }) + + client, err := NewClient(testutils.NewLogger(t), "test-token", srv.URL, "0.42.0", 7, 5*time.Second) + require.NoError(t, err) + + _, err = client.ProvisionLocalExecution(t.Context(), ProvisionParams{ + Name: "my-test", + ProjectID: testProjectID, + MaxVUs: 10, + TotalDuration: 60, + Options: json.RawMessage(`{"vus":1}`), + PollInterval: time.Microsecond, + }) + require.Error(t, err) + assert.Contains(t, err.Error(), "start local execution") + + // S3 + poll must not be called. + assert.Equal(t, 0, rec.count("upload")) + assert.Equal(t, int32(0), srv.FetchTestRunHitCount()) +} + +func TestProvisionLocalExecution_ErrorAtUpload(t *testing.T) { + t.Parallel() + + srv := provtest.NewServer(t) + + srv.HandleCreateLoadTest(testProjectID, func(w http.ResponseWriter, _ *http.Request) { + writeCreateResponse(w) + }) + + srv.HandleStartLocalExecution(testLoadTestID, func(w http.ResponseWriter, _ *http.Request) { + writeSLEResponse(w, srv.PresignedUploadURL()) + }) + + srv.HandlePresignedUpload(provtest.PresignedUploadPath, func(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusForbidden) + _, _ = w.Write([]byte("Request has expired")) + }) + + srv.HandleFetchTestRun(testTestRunID, []v6.TestProgress{ + {Status: v6.StatusInitializing}, + }) + + client, err := NewClient(testutils.NewLogger(t), "test-token", srv.URL, "0.42.0", 7, 5*time.Second) + require.NoError(t, err) + + _, err = client.ProvisionLocalExecution(t.Context(), ProvisionParams{ + Name: "my-test", + ProjectID: testProjectID, + MaxVUs: 50, + TotalDuration: 630, + Options: json.RawMessage(`{"vus":10}`), + Archive: newTestArchive(t), + PollInterval: time.Microsecond, + }) + require.Error(t, err) + assert.Contains(t, err.Error(), "upload archive") + + // Poll must not be called. + assert.Equal(t, int32(0), srv.FetchTestRunHitCount()) +} + +func TestProvisionLocalExecution_ErrorAtPolling(t *testing.T) { + t.Parallel() + + srv := provtest.NewServer(t) + + srv.HandleCreateLoadTest(testProjectID, func(w http.ResponseWriter, _ *http.Request) { + writeCreateResponse(w) + }) + + srv.HandleStartLocalExecution(testLoadTestID, func(w http.ResponseWriter, _ *http.Request) { + writeSLEResponse(w, srv.PresignedUploadURL()) + }) + + srv.HandlePresignedUpload(provtest.PresignedUploadPath, func(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusOK) + }) + + srv.HandleFetchTestRun(testTestRunID, []v6.TestProgress{ + { + Status: v6.StatusAborted, + StatusHistory: []v6.StatusEvent{ + {Status: v6.StatusAborted, Message: "quota exceeded"}, + }, + }, + }) + + client, err := NewClient(testutils.NewLogger(t), "test-token", srv.URL, "0.42.0", 7, 5*time.Second) + require.NoError(t, err) + + _, err = client.ProvisionLocalExecution(t.Context(), ProvisionParams{ + Name: "my-test", + ProjectID: testProjectID, + MaxVUs: 50, + TotalDuration: 630, + Options: json.RawMessage(`{"vus":10}`), + Archive: newTestArchive(t), + PollInterval: time.Microsecond, + }) + require.Error(t, err) + assert.Contains(t, err.Error(), "wait for test run ready") + assert.Contains(t, err.Error(), "quota exceeded") +} diff --git a/internal/cloudapi/provisioning/test/server.go b/internal/cloudapi/provisioning/test/server.go new file mode 100644 index 000000000..968fd1baa --- /dev/null +++ b/internal/cloudapi/provisioning/test/server.go @@ -0,0 +1,216 @@ +// Package provtest provides an HTTP test server that simulates the +// provisioning API. Routes are registered by individual specs as they +// add API methods; this skeleton starts with an empty mux. +package provtest + +import ( + "encoding/json" + "fmt" + "net/http" + "net/http/httptest" + "sync/atomic" + "testing" + + k6cloud "github.com/grafana/k6-cloud-openapi-client-go/k6" + + cloudapi "go.k6.io/k6/v2/internal/cloudapi/v6" +) + +const ( + // DefaultLoadTestID is the load test ID used by default handlers. + DefaultLoadTestID int64 = 456 + // DefaultTestRunID is the test run ID returned by default handlers. + DefaultTestRunID int64 = 123 + // PresignedUploadPath is the default path used for the presigned archive upload stub. + PresignedUploadPath = "/upload/archive.tar" +) + +// Server is a test HTTP server for the provisioning API. +type Server struct { + *httptest.Server + Mux *http.ServeMux + + fetchTestRunHits *atomic.Int32 +} + +// NewServer creates and starts a test server with an empty route table. +// The server is automatically closed when the test finishes. +func NewServer(t *testing.T) *Server { + t.Helper() + + mux := http.NewServeMux() + srv := httptest.NewServer(mux) + t.Cleanup(srv.Close) + + return &Server{ + Server: srv, + Mux: mux, + } +} + +// HandleCreateLoadTest registers a handler for +// /cloud/v6/projects/{projectID}/load_tests, covering both the POST +// (create) and GET (find-by-name) operations of +// v6.Client.CreateOrFindLoadTest. The handler should inspect r.Method +// to distinguish between create (POST) and find-by-name (GET). +func (s *Server) HandleCreateLoadTest(projectID int64, handler http.HandlerFunc) { + s.Mux.HandleFunc( + fmt.Sprintf("/cloud/v6/projects/%d/load_tests", projectID), + handler, + ) +} + +// HandleStartLocalExecution registers a handler for +// POST /provisioning/v1/load_tests/{loadTestID}/start_local_execution. +// If handler is nil, a default handler returning a successful response is used. +func (s *Server) HandleStartLocalExecution(loadTestID int64, handler http.HandlerFunc) { + if handler == nil { + handler = func(w http.ResponseWriter, _ *http.Request) { + writeJSON(w, http.StatusOK, DefaultStartLocalExecutionResponse()) + } + } + s.Mux.HandleFunc( + fmt.Sprintf("POST /provisioning/v1/load_tests/%d/start_local_execution", loadTestID), + handler, + ) +} + +// DefaultStartLocalExecutionResponse returns a fully-populated +// StartLocalExecutionTestResponse suitable for test assertions. +func DefaultStartLocalExecutionResponse() *k6cloud.StartLocalExecutionTestResponse { + metrics := k6cloud.NewMetricsRuntimeConfig( + "https://ingest.k6.io/v1/metrics", + *k6cloud.NewNullableString(strPtr("2s")), + *k6cloud.NewNullableInt32(int32Ptr(5)), + *k6cloud.NewNullableString(strPtr("3s")), + *k6cloud.NewNullableString(strPtr("1s")), + *k6cloud.NewNullableInt32(int32Ptr(50)), + *k6cloud.NewNullableInt32(int32Ptr(2000)), + ) + + secrets := k6cloud.NewSecretsRuntimeConfig( + "https://api.k6.io/provisioning/v1/test_runs/123/decrypt_secret?name={key}", + "plaintext", + ) + + traces := k6cloud.NewTracesRuntimeConfig( + "https://traces.k6.io", + map[string]string{}, + "http", + ) + files := k6cloud.NewFilesRuntimeConfig( + "https://files.k6.io", + "/screenshots", + map[string]string{}, + "POST", + ) + logs := k6cloud.NewLogsRuntimeConfig( + "https://logs.k6.io", + "https://logs.k6.io/tail", + 900, + "3s", + "info", + 10000, + []string{"lz", "level"}, + ) + + rc := k6cloud.NewRuntimeConfig( + *metrics, + *traces, + *files, + *logs, + *secrets, + "test-run-token-abc", + ) + + uploadURL := "https://s3.amazonaws.com/bucket/archive.tar?presigned=1" + return k6cloud.NewStartLocalExecutionTestResponse( + DefaultTestRunID, + *rc, + *k6cloud.NewNullableString(&uploadURL), + fmt.Sprintf("https://app.k6.io/runs/%d", DefaultTestRunID), + ) +} + +func writeJSON(w http.ResponseWriter, status int, v any) { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(status) + if err := json.NewEncoder(w).Encode(v); err != nil { + panic(fmt.Errorf("provtest: encoding JSON: %w", err)) + } +} + +// HandlePresignedUpload registers a handler for PUT requests at the given path, +// simulating a presigned S3 upload endpoint. +func (s *Server) HandlePresignedUpload(path string, handler http.HandlerFunc) { + s.Mux.HandleFunc("PUT "+path, handler) +} + +// PresignedUploadURL returns the full URL for the presigned upload stub +// using the default PresignedUploadPath. +func (s *Server) PresignedUploadURL() string { + return s.URL + PresignedUploadPath +} + +// HandleFetchTestRun registers a handler for +// GET /cloud/v6/test_runs/{testRunID}. The handler returns successive +// TestProgress values from the provided sequence. Once the sequence is +// exhausted, the last element is repeated. +// +// It also tracks the number of times the handler was called; use +// FetchTestRunHitCount to query it. +func (s *Server) HandleFetchTestRun(testRunID int64, sequence []cloudapi.TestProgress) { + var idx atomic.Int32 + var hits atomic.Int32 + + s.fetchTestRunHits = &hits + + s.Mux.HandleFunc( + fmt.Sprintf("GET /cloud/v6/test_runs/%d", testRunID), + func(w http.ResponseWriter, _ *http.Request) { + hits.Add(1) + + i := int(idx.Load()) + if i < len(sequence)-1 { + idx.Add(1) + } + tp := sequence[i] + + res := k6cloud.NewTestRunApiModelWithDefaults() + res.SetStatus(tp.Status.String()) + res.SetResult(tp.Result.String()) + res.SetEstimatedDuration(tp.EstimatedDuration) + res.SetExecutionDuration(tp.ExecutionDuration) + res.SetStatusHistory(cloudapi.ToStatusModel(tp.StatusHistory)) + res.SetDistribution([]k6cloud.DistributionZoneApiModel{}) + res.SetResultDetails( + k6cloud.ResultDetailsApiModelAsTestRunApiModelResultDetails( + k6cloud.NewResultDetailsApiModel(""), + ), + ) + res.SetOptions(map[string]any{}) + writeJSON(w, http.StatusOK, res) + }, + ) +} + +// FetchTestRunHitCount returns the number of times the FetchTestRun +// handler was called. Returns 0 if HandleFetchTestRun was never called. +func (s *Server) FetchTestRunHitCount() int32 { + if s.fetchTestRunHits == nil { + return 0 + } + return s.fetchTestRunHits.Load() +} + +// HandleNotify registers a handler for +// POST /provisioning/v1/test_runs/{testRunID}/notify. +func (s *Server) HandleNotify(testRunID int64, handler http.HandlerFunc) { + s.Mux.HandleFunc( + fmt.Sprintf("POST /provisioning/v1/test_runs/%d/notify", testRunID), + handler, + ) +} + +func strPtr(s string) *string { return &s } +func int32Ptr(i int32) *int32 { return &i } diff --git a/internal/cloudapi/v6/api.go b/internal/cloudapi/v6/api.go index e59bf01b8..b384a1063 100644 --- a/internal/cloudapi/v6/api.go +++ b/internal/cloudapi/v6/api.go @@ -200,6 +200,37 @@ func (c *Client) ValidateOptions(ctx context.Context, projectID int64, opts lib. return nil } +// CreateOrFindLoadTest creates a load test by name in the given project without +// uploading a script. If the API returns 409 (conflict), it falls back to +// looking up the existing test by name and returns its ID. +func (c *Client) CreateOrFindLoadTest(ctx context.Context, projectID int64, name string) (_ int64, err error) { + res, hr, err := c.apiClient.LoadTestsAPI. + ProjectsLoadTestsCreate(c.authCtx(ctx), projectID). + XStackId(c.stackID). + Name(name). + Execute() + defer closeResponse(hr, &err) + + if err := CheckResponse(hr, err); err != nil { + var rerr ResponseError + if errors.As(err, &rerr) && rerr.Response != nil && rerr.Response.StatusCode == http.StatusConflict { + lt, err := c.findTestByName(ctx, projectID, name) + if err != nil { + return 0, err + } + return lt.GetId(), nil + } + return 0, err + } + if res == nil { + // The SDK getters return zero values on a nil receiver, so guard + // against silently producing a bogus 0 id and report it clearly. + return 0, errors.New("unexpected nil response from CreateOrFindLoadTest") + } + + return res.GetId(), nil +} + // UploadTest creates or updates a cloud load test's script. func (c *Client) UploadTest( ctx context.Context, name string, projectID int64, arc *lib.Archive, diff --git a/internal/cloudapi/v6/api_test.go b/internal/cloudapi/v6/api_test.go index c16ebf63f..0d8eb003c 100644 --- a/internal/cloudapi/v6/api_test.go +++ b/internal/cloudapi/v6/api_test.go @@ -3,6 +3,7 @@ package cloudapi import ( "bytes" "encoding/json" + "errors" "fmt" "io" "net/http" @@ -353,6 +354,115 @@ func TestUploadTest(t *testing.T) { }) } +func TestCreateOrFindLoadTest(t *testing.T) { + t.Parallel() + + var ( + method string + path string + stackID string + authHeader string + formName string + hasScript bool + ) + + client := newTestClient(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + method = r.Method + path = r.URL.Path + stackID = r.Header.Get("X-Stack-Id") + authHeader = r.Header.Get("Authorization") + + require.NoError(t, r.ParseMultipartForm(1<<20)) + formName = r.FormValue("name") + _, _, err := r.FormFile("script") + hasScript = err == nil + + res := k6cloud.NewLoadTestApiModelWithDefaults() + res.SetId(12345) + writeJSON(t, w, http.StatusOK, res) + })) + + id, err := client.CreateOrFindLoadTest(t.Context(), 99, "my-test") + require.NoError(t, err) + assert.Equal(t, int64(12345), id) + assert.Equal(t, http.MethodPost, method) + assert.Equal(t, "/cloud/v6/projects/99/load_tests", path) + assert.Equal(t, "my-test", formName) + assert.False(t, hasScript, "request must not include a script part") + assert.Equal(t, "1", stackID) + assert.Equal(t, "Bearer test-token", authHeader) +} + +func TestCreateOrFindLoadTest_ConflictFallsBackToFindByName(t *testing.T) { + t.Parallel() + + var ( + getHit bool + getName string + getTop string + ) + + client := newTestClient(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch r.Method { + case http.MethodPost: + writeError(t, w, http.StatusConflict, "conflict", "already exists") + case http.MethodGet: + getHit = true + getName = r.URL.Query().Get("name") + getTop = r.URL.Query().Get("$top") + lt := k6cloud.NewLoadTestApiModelWithDefaults() + lt.SetId(67890) + writeJSON(t, w, http.StatusOK, map[string]any{"value": []any{lt}}) + } + })) + + id, err := client.CreateOrFindLoadTest(t.Context(), 99, "my-test") + require.NoError(t, err) + assert.Equal(t, int64(67890), id) + assert.True(t, getHit, "GET fallback should have been called") + assert.Equal(t, "my-test", getName) + assert.Equal(t, "1", getTop) +} + +func TestCreateOrFindLoadTest_ConflictWithNoMatchReturnsError(t *testing.T) { + t.Parallel() + + client := newTestClient(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch r.Method { + case http.MethodPost: + writeError(t, w, http.StatusConflict, "conflict", "already exists") + case http.MethodGet: + writeJSON(t, w, http.StatusOK, map[string]any{"value": []any{}}) + } + })) + + _, err := client.CreateOrFindLoadTest(t.Context(), 99, "my-test") + assert.ErrorIs(t, err, errTestNotExists) +} + +func TestCreateOrFindLoadTest_NonConflictHTTPErrorReturned(t *testing.T) { + t.Parallel() + + var getHit bool + client := newTestClient(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch r.Method { + case http.MethodPost: + writeError(t, w, http.StatusInternalServerError, "server_error", "internal error") + case http.MethodGet: + getHit = true + w.WriteHeader(http.StatusOK) + } + })) + + _, err := client.CreateOrFindLoadTest(t.Context(), 99, "my-test") + require.Error(t, err) + + var rerr ResponseError + assert.True(t, errors.As(err, &rerr)) + assert.Equal(t, http.StatusInternalServerError, rerr.Response.StatusCode) + assert.False(t, getHit, "GET fallback should not be called on non-conflict error") +} + func TestStartTest(t *testing.T) { t.Parallel() diff --git a/internal/cloudapi/v6/client.go b/internal/cloudapi/v6/client.go index 2374d29c6..1c94141ab 100644 --- a/internal/cloudapi/v6/client.go +++ b/internal/cloudapi/v6/client.go @@ -11,16 +11,10 @@ import ( k6cloud "github.com/grafana/k6-cloud-openapi-client-go/k6" "github.com/sirupsen/logrus" + "go.k6.io/k6/v2/internal/cloudapi/clientcfg" "go.k6.io/k6/v2/internal/cloudapi/httperr" ) -const ( - // RetryInterval is the default cloud request retry interval - RetryInterval = 500 * time.Millisecond - // MaxRetries specifies max retry attempts - MaxRetries = 3 -) - // Client handles communication with the k6 Cloud API. type Client struct { apiClient *k6cloud.APIClient @@ -37,20 +31,7 @@ func NewClient(logger logrus.FieldLogger, token, host, version string, timeout t return nil, fmt.Errorf("token is required to create cloud API client") } - cfg := k6cloud.NewConfiguration() - cfg.UserAgent = "k6cloud/" + version - cfg.Servers = k6cloud.ServerConfigurations{ - { - URL: host, - Description: "Global k6 Cloud API.", - }, - } - cfg.HTTPClient = &http.Client{ - Timeout: timeout, - Transport: http.DefaultTransport, - } - cfg.MaxRetries = MaxRetries - cfg.RetryInterval = RetryInterval + cfg := clientcfg.New(host, version, "Global k6 Cloud API.", timeout) c := &Client{ apiClient: k6cloud.NewAPIClient(cfg), diff --git a/internal/cmd/outputs_cloud.go b/internal/cmd/outputs_cloud.go index 4fc7ae16a..eb16849a7 100644 --- a/internal/cmd/outputs_cloud.go +++ b/internal/cmd/outputs_cloud.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "path/filepath" + "strconv" "strings" "time" @@ -15,8 +16,10 @@ import ( "go.k6.io/k6/v2/cloudapi" "go.k6.io/k6/v2/cmd/state" "go.k6.io/k6/v2/internal/build" + "go.k6.io/k6/v2/internal/cloudapi/provisioning" cloudsecrets "go.k6.io/k6/v2/internal/secretsource/cloud" "go.k6.io/k6/v2/lib" + "go.k6.io/k6/v2/lib/types" "go.k6.io/k6/v2/metrics" ) @@ -104,64 +107,82 @@ func createCloudTest(gs *state.GlobalState, test *loadedAndConfiguredTest) error testArchive = test.makeArchive() } - testRun := &cloudapi.TestRun{ - Name: conf.Name.String, - ProjectID: conf.ProjectID.Int64, - VUsMax: int64(lib.GetMaxPossibleVUs(executionPlan)), //nolint:gosec - Thresholds: thresholds, - Duration: int64(duration / time.Second), - Archive: testArchive, - } - logger := gs.Logger.WithFields(logrus.Fields{"output": builtinOutputCloud.String()}) - apiClient := cloudapi.NewClient( - logger, conf.Token.String, conf.Host.String, build.Version, conf.Timeout.TimeDuration()) - if conf.StackID.Valid { - apiClient.SetStackID(conf.StackID.Int64) + // The stack ID is required (checkCloudLogin enforces it) and passed as + // int64; provisioning.NewClient handles the int32 boundary internally. + provClient, err := provisioning.NewClient( + logger, conf.Token.String, conf.Hostv6.String, build.Version, + conf.StackID.Int64, + conf.Timeout.TimeDuration(), + ) + if err != nil { + return err } - if testRun.ProjectID == 0 { + if conf.ProjectID.Int64 == 0 { projectID, err := resolveDefaultProjectID(gs, &conf) if err != nil { return err } if projectID > 0 { - testRun.ProjectID = projectID + conf.ProjectID = null.IntFrom(projectID) } } - response, err := apiClient.CreateTestRun(testRun) + // Marshal the resolved lib.Options as json.RawMessage for the request + // body's `options` field. No map[string]any round-trip — preserves + // typed precision from lib.Options custom marshalers. + optionsJSON, err := json.Marshal(test.derivedConfig.Options) + if err != nil { + return fmt.Errorf("marshalling options: %w", err) + } + + ctx := gs.Ctx + result, err := provClient.ProvisionLocalExecution(ctx, provisioning.ProvisionParams{ + Name: conf.Name.String, + ProjectID: conf.ProjectID.Int64, + MaxVUs: int64(lib.GetMaxPossibleVUs(executionPlan)), //nolint:gosec + TotalDuration: int64(duration / time.Second), + Options: json.RawMessage(optionsJSON), + Archive: testArchive, + }) if err != nil { return err } - // We store the test run id in the environment, so it can be used later. - test.preInitState.RuntimeOptions.Env[testRunIDKey] = response.ReferenceID + // Stash testRunID in env (existing pattern). + test.preInitState.RuntimeOptions.Env[testRunIDKey] = strconv.FormatInt(result.TestRunID, 10) - if response.SecretsConfig != nil && gs.CloudSecretSource != nil { + // Apply runtime_config metrics tuning to the Config. Malformed duration + // strings from the backend are logged as warnings, not failures. + conf = conf.Apply(buildConfigFromRuntimeConfig(logger, result.RuntimeConfig)) + + // Set the Config fields that the cloud Output reads for metrics push. + conf.MetricsPushURL = null.StringFrom(result.RuntimeConfig.Metrics.PushURL) + conf.TestRunToken = null.StringFrom(result.RuntimeConfig.TestRunToken) + + // Set the test run details page URL for the output banner. + conf.TestRunDetails = null.StringFrom(result.TestRunDetailsPageURL) + + // Register secrets config (always present in the provisioning response). + if gs.CloudSecretSource != nil { gs.CloudSecretSource.SetConfig(&cloudsecrets.Config{ - Token: response.TestRunToken, - Endpoint: response.SecretsConfig.Endpoint, - ResponsePath: response.SecretsConfig.ResponsePath, + Token: result.RuntimeConfig.TestRunToken, + Endpoint: result.RuntimeConfig.Secrets.Endpoint, + ResponsePath: result.RuntimeConfig.Secrets.ResponsePath, }) } - // If the Cloud API returned configuration overrides, we apply them to the current configuration. - // Then, we serialize the overridden configuration back, so it can be used by the Cloud output. - if response.ConfigOverride != nil { - logger.WithFields(logrus.Fields{"override": response.ConfigOverride}).Debug("overriding config options") - - raw, err := cloudConfToRawMessage(conf.Apply(*response.ConfigOverride)) - if err != nil { - return fmt.Errorf("could not serialize overridden cloud configuration: %w", err) - } - - if test.derivedConfig.Collectors == nil { - test.derivedConfig.Collectors = make(map[string]json.RawMessage) - } - test.derivedConfig.Collectors[builtinOutputCloud.String()] = raw + // Serialise overridden Config back into the collectors map (existing pattern). + raw, err := cloudConfToRawMessage(conf) + if err != nil { + return fmt.Errorf("could not serialize overridden cloud configuration: %w", err) + } + if test.derivedConfig.Collectors == nil { + test.derivedConfig.Collectors = make(map[string]json.RawMessage) } + test.derivedConfig.Collectors[builtinOutputCloud.String()] = raw return nil } @@ -213,3 +234,58 @@ func resolveCloudTestName(name null.String, scriptPath string) (null.String, err } return name, nil } + +// buildConfigFromRuntimeConfig maps provisioning RuntimeConfig fields +// to cloudapi.Config fields. +// +// If the backend returns an unparseable duration string, a warning is +// logged and the cloudapi.Config default is kept. Graceful degradation +// is preferable to blocking the user for a backend-side bug. +func buildConfigFromRuntimeConfig( + logger logrus.FieldLogger, rc provisioning.RuntimeConfig, +) cloudapi.Config { + cfg := cloudapi.Config{} + + // metrics.push_interval (string nullable) → MetricPushInterval (NullDuration) + if v := rc.Metrics.PushInterval; v != nil { + if d, err := time.ParseDuration(*v); err == nil { + cfg.MetricPushInterval = types.NewNullDuration(d, true) + } else { + logger.WithError(err).WithField("field", "push_interval"). + Warn("invalid duration in runtime_config; using default") + } + } + // metrics.push_concurrency (int32 nullable) → MetricPushConcurrency (null.Int) + if v := rc.Metrics.PushConcurrency; v != nil { + cfg.MetricPushConcurrency = null.IntFrom(int64(*v)) + } + // metrics.aggregation_period (string nullable) → AggregationPeriod (NullDuration) + if v := rc.Metrics.AggregationPeriod; v != nil { + if d, err := time.ParseDuration(*v); err == nil { + cfg.AggregationPeriod = types.NewNullDuration(d, true) + } else { + logger.WithError(err).WithField("field", "aggregation_period"). + Warn("invalid duration in runtime_config; using default") + } + } + // metrics.aggregation_wait_period (string nullable) → AggregationWaitPeriod + if v := rc.Metrics.AggregationWaitPeriod; v != nil { + if d, err := time.ParseDuration(*v); err == nil { + cfg.AggregationWaitPeriod = types.NewNullDuration(d, true) + } else { + logger.WithError(err).WithField("field", "aggregation_wait_period"). + Warn("invalid duration in runtime_config; using default") + } + } + // metrics.max_samples_per_package (int32 nullable) → MaxTimeSeriesInBatch + // (semantically the same field — per-batch series cap) + if v := rc.Metrics.MaxSamplesPerPackage; v != nil { + cfg.MaxTimeSeriesInBatch = null.IntFrom(int64(*v)) + } + + // rc.Metrics.AggregationMinSamples is intentionally not mapped. + // expv2 has no min-samples aggregation knob; adding one would + // require changes to output/cloud/expv2/{collect.go, flush.go}. + + return cfg +} diff --git a/internal/cmd/outputs_cloud_test.go b/internal/cmd/outputs_cloud_test.go new file mode 100644 index 000000000..fd7a641ac --- /dev/null +++ b/internal/cmd/outputs_cloud_test.go @@ -0,0 +1,152 @@ +package cmd + +import ( + "testing" + "time" + + "github.com/sirupsen/logrus" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "gopkg.in/guregu/null.v3" + + "go.k6.io/k6/v2/internal/cloudapi/provisioning" + "go.k6.io/k6/v2/internal/lib/testutils" + "go.k6.io/k6/v2/lib/types" +) + +func TestBuildConfigFromRuntimeConfig(t *testing.T) { + t.Parallel() + + pushInterval := "2s" + var pushConcurrency int32 = 5 + aggPeriod := "3s" + aggWaitPeriod := "1s" + var aggMinSamples int32 = 50 + var maxSamples int32 = 2000 + + rc := provisioning.RuntimeConfig{ + Metrics: provisioning.MetricsConfig{ + PushURL: "https://ingest.example.com/v1/metrics", + PushInterval: &pushInterval, + PushConcurrency: &pushConcurrency, + AggregationPeriod: &aggPeriod, + AggregationWaitPeriod: &aggWaitPeriod, + AggregationMinSamples: &aggMinSamples, + MaxSamplesPerPackage: &maxSamples, + }, + TestRunToken: "test-token", + Secrets: provisioning.SecretsConfig{ + Endpoint: "https://secrets.example.com", + ResponsePath: "plaintext", + }, + } + + logger := testutils.NewLogger(t) + cfg := buildConfigFromRuntimeConfig(logger, rc) + + // push_interval → MetricPushInterval + assert.True(t, cfg.MetricPushInterval.Valid) + assert.Equal(t, types.NewNullDuration(2*time.Second, true), cfg.MetricPushInterval) + + // push_concurrency → MetricPushConcurrency + assert.True(t, cfg.MetricPushConcurrency.Valid) + assert.Equal(t, null.IntFrom(5), cfg.MetricPushConcurrency) + + // aggregation_period → AggregationPeriod + assert.True(t, cfg.AggregationPeriod.Valid) + assert.Equal(t, types.NewNullDuration(3*time.Second, true), cfg.AggregationPeriod) + + // aggregation_wait_period → AggregationWaitPeriod + assert.True(t, cfg.AggregationWaitPeriod.Valid) + assert.Equal(t, types.NewNullDuration(1*time.Second, true), cfg.AggregationWaitPeriod) + + // max_samples_per_package → MaxTimeSeriesInBatch + assert.True(t, cfg.MaxTimeSeriesInBatch.Valid) + assert.Equal(t, null.IntFrom(2000), cfg.MaxTimeSeriesInBatch) +} + +func TestBuildConfigFromRuntimeConfig_InvalidDurationLogsWarning(t *testing.T) { + t.Parallel() + + badDuration := "not a duration" + rc := provisioning.RuntimeConfig{ + Metrics: provisioning.MetricsConfig{ + PushInterval: &badDuration, + }, + } + + logger := logrus.New() + logger.SetLevel(logrus.DebugLevel) + hook := testutils.NewLogHook() + logger.AddHook(hook) + + cfg := buildConfigFromRuntimeConfig(logger, rc) + + // MetricPushInterval should be left unset (invalid) when parse fails. + assert.False(t, cfg.MetricPushInterval.Valid, "expected MetricPushInterval to remain unset for unparseable duration") + + // A warning should have been logged. + entries := hook.Drain() + require.NotEmpty(t, entries, "expected at least one log entry for invalid duration") + + found := false + for _, e := range entries { + if e.Level == logrus.WarnLevel && e.Data["field"] == "push_interval" { + found = true + break + } + } + assert.True(t, found, "expected a warning log entry for field push_interval") +} + +func TestBuildConfigFromRuntimeConfig_NilFieldsLeftUnset(t *testing.T) { + t.Parallel() + + rc := provisioning.RuntimeConfig{ + Metrics: provisioning.MetricsConfig{ + PushURL: "https://ingest.example.com/v1/metrics", + // All nullable fields left nil. + }, + } + + logger := testutils.NewLogger(t) + cfg := buildConfigFromRuntimeConfig(logger, rc) + + assert.False(t, cfg.MetricPushInterval.Valid, "MetricPushInterval should be unset when input is nil") + assert.False(t, cfg.MetricPushConcurrency.Valid, "MetricPushConcurrency should be unset when input is nil") + assert.False(t, cfg.AggregationPeriod.Valid, "AggregationPeriod should be unset when input is nil") + assert.False(t, cfg.AggregationWaitPeriod.Valid, "AggregationWaitPeriod should be unset when input is nil") + assert.False(t, cfg.MaxTimeSeriesInBatch.Valid, "MaxTimeSeriesInBatch should be unset when input is nil") +} + +func TestBuildConfigFromRuntimeConfig_AggregationMinSamplesIgnored(t *testing.T) { + t.Parallel() + + var aggMinSamples int32 = 100 + rc := provisioning.RuntimeConfig{ + Metrics: provisioning.MetricsConfig{ + AggregationMinSamples: &aggMinSamples, + }, + } + + logger := logrus.New() + logger.SetLevel(logrus.DebugLevel) + hook := testutils.NewLogHook() + logger.AddHook(hook) + + cfg := buildConfigFromRuntimeConfig(logger, rc) + + // No Config field should have been set. + assert.False(t, cfg.MetricPushInterval.Valid) + assert.False(t, cfg.MetricPushConcurrency.Valid) + assert.False(t, cfg.AggregationPeriod.Valid) + assert.False(t, cfg.AggregationWaitPeriod.Valid) + assert.False(t, cfg.MaxTimeSeriesInBatch.Valid) + + // No warning or error should be logged (intentional drop, not an error). + entries := hook.Drain() + for _, e := range entries { + assert.NotEqual(t, logrus.WarnLevel, e.Level, "unexpected warning logged for intentionally dropped field") + assert.NotEqual(t, logrus.ErrorLevel, e.Level, "unexpected error logged for intentionally dropped field") + } +} diff --git a/internal/cmd/tests/cmd_cloud_run_test.go b/internal/cmd/tests/cmd_cloud_run_test.go index 81dfc17d7..d2b21df52 100644 --- a/internal/cmd/tests/cmd_cloud_run_test.go +++ b/internal/cmd/tests/cmd_cloud_run_test.go @@ -1,7 +1,6 @@ package tests import ( - "bytes" "encoding/json" "fmt" "io" @@ -9,13 +8,16 @@ import ( "os" "path/filepath" "strconv" + "sync/atomic" "testing" + k6cloud "github.com/grafana/k6-cloud-openapi-client-go/k6" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.k6.io/k6/v2/cloudapi" "go.k6.io/k6/v2/errext/exitcodes" + provtest "go.k6.io/k6/v2/internal/cloudapi/provisioning/test" + v6 "go.k6.io/k6/v2/internal/cloudapi/v6" "go.k6.io/k6/v2/internal/cloudapi/v6/v6test" "go.k6.io/k6/v2/internal/cmd" "go.k6.io/k6/v2/internal/lib/testutils" @@ -172,7 +174,7 @@ func TestCloudRunCommandIncompatibleFlags(t *testing.T) { func TestCloudRunLocalExecution(t *testing.T) { t.Parallel() - t.Run("should upload the test archive with a multipart request as a default", func(t *testing.T) { + t.Run("should upload the test archive via presigned S3 URL as a default", func(t *testing.T) { t.Parallel() script := ` @@ -187,42 +189,90 @@ export default function() {};` ts := makeTestState(t, script, []string{"--local-execution"}) - testServerHandlerFunc := http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) { - // When using the local execution mode, the test archive should be uploaded to the cloud - // as a multipart request. - formData, err := parseMultipartRequest(req) - require.NoError(t, err, "expected a correctly formed multipart request") - assert.Contains(t, formData, "name") - assert.Equal(t, "Hello k6 Cloud!", formData["name"]) - assert.Contains(t, formData, "project_id") - assert.Equal(t, "123456", formData["project_id"]) - assert.Contains(t, formData, "file") - assert.NotEmpty(t, formData["file"]) - - resp.WriteHeader(http.StatusOK) - _, err = fmt.Fprint(resp, `{ - "reference_id": "1337", - "test_run_token": "mock-test-run-token", - "secrets_config": { - "endpoint": "https://mock-secrets.example.com/{key}", - "response_path": "plaintext" - }, - "config": { - "testRunDetails": "https://some.other.url/foo/tests/org/1337?bar=baz" - } - }`) - assert.NoError(t, err) + srv := provtest.NewServer(t) + + // v6 CreateOrFindLoadTest: POST /cloud/v6/projects/{projectID}/load_tests + srv.HandleCreateLoadTest(123456, func(w http.ResponseWriter, r *http.Request) { + assert.Equal(t, http.MethodPost, r.Method) + res := k6cloud.NewLoadTestApiModelWithDefaults() + res.SetId(provtest.DefaultLoadTestID) + writeProvJSON(w, http.StatusCreated, res) + }) + + // start_local_execution: check request body and return response + var startCalled atomic.Bool + srv.HandleStartLocalExecution(provtest.DefaultLoadTestID, func(w http.ResponseWriter, r *http.Request) { + startCalled.Store(true) + + body, err := io.ReadAll(r.Body) + require.NoError(t, err) + + var payload map[string]any + require.NoError(t, json.Unmarshal(body, &payload)) + + // Verify options field is present and contains resolved lib.Options + assert.Contains(t, payload, "options") + + // Verify archive_size > 0 + assert.Contains(t, payload, "archive_size") + archiveSize, ok := payload["archive_size"].(float64) + assert.True(t, ok, "archive_size should be a number") + assert.Greater(t, archiveSize, float64(0), "archive_size should be > 0") + + resp := provtest.DefaultStartLocalExecutionResponse() + // Override URLs to point to the test server + uploadURL := srv.URL + provtest.PresignedUploadPath + resp.SetArchiveUploadUrl(uploadURL) + resp.SetTestRunDetailsPageUrl(fmt.Sprintf("%s/runs/%d", srv.URL, provtest.DefaultTestRunID)) + // Override metrics push URL to point to the test server + rc := resp.GetRuntimeConfig() + m := rc.GetMetrics() + m.SetPushUrl(srv.URL + "/v1/metrics") + rc.SetMetrics(m) + resp.SetRuntimeConfig(rc) + writeProvJSON(w, http.StatusOK, resp) + }) + + // presigned archive upload + var archiveUploaded atomic.Bool + srv.HandlePresignedUpload(provtest.PresignedUploadPath, func(w http.ResponseWriter, r *http.Request) { + archiveUploaded.Store(true) + body, err := io.ReadAll(r.Body) + require.NoError(t, err) + assert.Greater(t, len(body), 0, "archive upload body should not be empty") + assert.Equal(t, "application/x-tar", r.Header.Get("Content-Type")) + w.WriteHeader(http.StatusOK) + }) + + // v6 FetchTestRun: return "initializing" immediately + srv.HandleFetchTestRun(provtest.DefaultTestRunID, []v6.TestProgress{ + {Status: v6.StatusInitializing}, + }) + + // notify: verify it's called + var notifyCalled atomic.Bool + srv.HandleNotify(provtest.DefaultTestRunID, func(w http.ResponseWriter, _ *http.Request) { + notifyCalled.Store(true) + w.WriteHeader(http.StatusOK) + }) + + // catch-all for metrics pushes and other calls + srv.Mux.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusOK) }) - srv := getCloudTestEndChecker(t, 1337, testServerHandlerFunc, cloudapi.RunStatusFinished, cloudapi.ResultStatusPassed) ts.Env["K6_CLOUD_HOST"] = srv.URL + ts.Env["K6_CLOUD_HOST_V6"] = srv.URL cmd.ExecuteWithGlobalState(ts.GlobalState) stdout := ts.Stdout.String() t.Log(stdout) assert.Contains(t, stdout, "execution: local") - assert.Contains(t, stdout, "output: cloud (https://some.other.url/foo/tests/org/1337?bar=baz)") + assert.Contains(t, stdout, fmt.Sprintf("output: cloud (%s/runs/%d)", srv.URL, provtest.DefaultTestRunID)) + assert.True(t, startCalled.Load(), "start_local_execution should have been called") + assert.True(t, archiveUploaded.Load(), "archive should have been uploaded via presigned URL") + assert.True(t, notifyCalled.Load(), "notify should have been called at test end") }) t.Run("does not upload the archive when --no-archive-upload is provided", func(t *testing.T) { @@ -240,44 +290,67 @@ export default function() {};` ts := makeTestState(t, script, []string{"--local-execution", "--no-archive-upload"}) - testServerHandlerFunc := http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) { - body, err := io.ReadAll(req.Body) + srv := provtest.NewServer(t) + + srv.HandleCreateLoadTest(123456, func(w http.ResponseWriter, _ *http.Request) { + res := k6cloud.NewLoadTestApiModelWithDefaults() + res.SetId(provtest.DefaultLoadTestID) + writeProvJSON(w, http.StatusCreated, res) + }) + + // start_local_execution: verify archive_size is null + srv.HandleStartLocalExecution(provtest.DefaultLoadTestID, func(w http.ResponseWriter, r *http.Request) { + body, err := io.ReadAll(r.Body) require.NoError(t, err) var payload map[string]any - err = json.Unmarshal(body, &payload) - require.NoError(t, err) + require.NoError(t, json.Unmarshal(body, &payload)) + + // archive_size should be explicitly null (Go JSON unmarshals null as nil) + assert.Contains(t, payload, "archive_size") + assert.Nil(t, payload["archive_size"], "archive_size should be null when --no-archive-upload is provided") + + resp := provtest.DefaultStartLocalExecutionResponse() + // No upload URL when --no-archive-upload is set + resp.ArchiveUploadUrl.Unset() + resp.SetTestRunDetailsPageUrl(fmt.Sprintf("%s/runs/%d", srv.URL, provtest.DefaultTestRunID)) + rc := resp.GetRuntimeConfig() + m := rc.GetMetrics() + m.SetPushUrl(srv.URL + "/v1/metrics") + rc.SetMetrics(m) + resp.SetRuntimeConfig(rc) + writeProvJSON(w, http.StatusOK, resp) + }) + + // Archive upload should NOT be called + var archiveUploaded atomic.Bool + srv.HandlePresignedUpload(provtest.PresignedUploadPath, func(w http.ResponseWriter, _ *http.Request) { + archiveUploaded.Store(true) + w.WriteHeader(http.StatusOK) + }) + + srv.HandleFetchTestRun(provtest.DefaultTestRunID, []v6.TestProgress{ + {Status: v6.StatusInitializing}, + }) - assert.Contains(t, payload, "name") - assert.Equal(t, "Hello k6 Cloud!", payload["name"]) - assert.Contains(t, payload, "project_id") - assert.Equal(t, float64(123456), payload["project_id"]) - assert.NotContains(t, payload, "file") - - resp.WriteHeader(http.StatusOK) - _, err = fmt.Fprint(resp, `{ - "reference_id": "1337", - "test_run_token": "mock-test-run-token", - "secrets_config": { - "endpoint": "https://mock-secrets.example.com/{key}", - "response_path": "plaintext" - }, - "config": { - "testRunDetails": "https://some.other.url/foo/tests/org/1337?bar=baz" - } - }`) - assert.NoError(t, err) + srv.HandleNotify(provtest.DefaultTestRunID, func(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusOK) + }) + + srv.Mux.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusOK) }) - srv := getCloudTestEndChecker(t, 1337, testServerHandlerFunc, cloudapi.RunStatusFinished, cloudapi.ResultStatusPassed) ts.Env["K6_CLOUD_HOST"] = srv.URL + ts.Env["K6_CLOUD_HOST_V6"] = srv.URL cmd.ExecuteWithGlobalState(ts.GlobalState) stdout := ts.Stdout.String() t.Log(stdout) assert.Contains(t, stdout, "execution: local") - assert.Contains(t, stdout, "output: cloud (https://some.other.url/foo/tests/org/1337?bar=baz)") + assert.Contains(t, stdout, fmt.Sprintf("output: cloud (%s/runs/%d)", srv.URL, provtest.DefaultTestRunID)) + assert.False(t, archiveUploaded.Load(), "archive should NOT have been uploaded when --no-archive-upload is set") }) t.Run("the script can read the test run id to the environment", func(t *testing.T) { @@ -297,17 +370,53 @@ export default function() { ts := makeTestState(t, script, []string{"--local-execution", "--log-output=stdout"}) - const testRunID = 1337 - srv := getCloudTestEndChecker(t, testRunID, nil, cloudapi.RunStatusFinished, cloudapi.ResultStatusPassed) + srv := provtest.NewServer(t) + + srv.HandleCreateLoadTest(123456, func(w http.ResponseWriter, _ *http.Request) { + res := k6cloud.NewLoadTestApiModelWithDefaults() + res.SetId(provtest.DefaultLoadTestID) + writeProvJSON(w, http.StatusCreated, res) + }) + + srv.HandleStartLocalExecution(provtest.DefaultLoadTestID, func(w http.ResponseWriter, _ *http.Request) { + resp := provtest.DefaultStartLocalExecutionResponse() + uploadURL := srv.URL + provtest.PresignedUploadPath + resp.SetArchiveUploadUrl(uploadURL) + resp.SetTestRunDetailsPageUrl(fmt.Sprintf("%s/runs/%d", srv.URL, provtest.DefaultTestRunID)) + rc := resp.GetRuntimeConfig() + m := rc.GetMetrics() + m.SetPushUrl(srv.URL + "/v1/metrics") + rc.SetMetrics(m) + resp.SetRuntimeConfig(rc) + writeProvJSON(w, http.StatusOK, resp) + }) + + srv.HandlePresignedUpload(provtest.PresignedUploadPath, func(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusOK) + }) + + srv.HandleFetchTestRun(provtest.DefaultTestRunID, []v6.TestProgress{ + {Status: v6.StatusInitializing}, + }) + + srv.HandleNotify(provtest.DefaultTestRunID, func(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusOK) + }) + + srv.Mux.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusOK) + }) + ts.Env["K6_CLOUD_HOST"] = srv.URL + ts.Env["K6_CLOUD_HOST_V6"] = srv.URL cmd.ExecuteWithGlobalState(ts.GlobalState) stdout := ts.Stdout.String() t.Log(stdout) assert.Contains(t, stdout, "execution: local") - assert.Contains(t, stdout, "output: cloud (https://app.k6.io/runs/1337)") - assert.Contains(t, stdout, "The test run id is "+strconv.Itoa(testRunID)) + assert.Contains(t, stdout, fmt.Sprintf("output: cloud (%s/runs/%d)", srv.URL, provtest.DefaultTestRunID)) + assert.Contains(t, stdout, "The test run id is "+strconv.Itoa(int(provtest.DefaultTestRunID))) }) t.Run("reuses existing test run when K6_CLOUD_PUSH_REF_ID is set", func(t *testing.T) { @@ -334,9 +443,16 @@ export default function() { "POST ^/v1/tests$": http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { require.Fail(t, "CreateTestRun must not be called when K6_CLOUD_PUSH_REF_ID is set") }), + "POST ^/provisioning/v1/": http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { + require.Fail(t, "provisioning API must not be called when K6_CLOUD_PUSH_REF_ID is set") + }), + "POST ^/cloud/v6/projects/": http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { + require.Fail(t, "v6 load_tests API must not be called when K6_CLOUD_PUSH_REF_ID is set") + }), }) t.Cleanup(srv.Close) ts.Env["K6_CLOUD_HOST"] = srv.URL + ts.Env["K6_CLOUD_HOST_V6"] = srv.URL cmd.ExecuteWithGlobalState(ts.GlobalState) @@ -363,24 +479,45 @@ export default function() {};` ts := makeTestState(t, script, []string{"--local-execution", "--no-cloud-secrets"}) - testServerHandlerFunc := http.HandlerFunc(func(resp http.ResponseWriter, _ *http.Request) { - resp.WriteHeader(http.StatusOK) - _, err := fmt.Fprint(resp, `{ - "reference_id": "1337", - "test_run_token": "mock-test-run-token", - "secrets_config": { - "endpoint": "https://mock-secrets.example.com/{key}", - "response_path": "plaintext" - }, - "config": { - "testRunDetails": "https://some.other.url/foo/tests/org/1337?bar=baz" - } - }`) - assert.NoError(t, err) + srv := provtest.NewServer(t) + + srv.HandleCreateLoadTest(123456, func(w http.ResponseWriter, _ *http.Request) { + res := k6cloud.NewLoadTestApiModelWithDefaults() + res.SetId(provtest.DefaultLoadTestID) + writeProvJSON(w, http.StatusCreated, res) + }) + + srv.HandleStartLocalExecution(provtest.DefaultLoadTestID, func(w http.ResponseWriter, _ *http.Request) { + resp := provtest.DefaultStartLocalExecutionResponse() + uploadURL := srv.URL + provtest.PresignedUploadPath + resp.SetArchiveUploadUrl(uploadURL) + resp.SetTestRunDetailsPageUrl(fmt.Sprintf("%s/runs/%d", srv.URL, provtest.DefaultTestRunID)) + rc := resp.GetRuntimeConfig() + m := rc.GetMetrics() + m.SetPushUrl(srv.URL + "/v1/metrics") + rc.SetMetrics(m) + resp.SetRuntimeConfig(rc) + writeProvJSON(w, http.StatusOK, resp) + }) + + srv.HandlePresignedUpload(provtest.PresignedUploadPath, func(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusOK) + }) + + srv.HandleFetchTestRun(provtest.DefaultTestRunID, []v6.TestProgress{ + {Status: v6.StatusInitializing}, + }) + + srv.HandleNotify(provtest.DefaultTestRunID, func(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusOK) + }) + + srv.Mux.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusOK) }) - srv := getCloudTestEndChecker(t, 1337, testServerHandlerFunc, cloudapi.RunStatusFinished, cloudapi.ResultStatusPassed) ts.Env["K6_CLOUD_HOST"] = srv.URL + ts.Env["K6_CLOUD_HOST_V6"] = srv.URL cmd.ExecuteWithGlobalState(ts.GlobalState) @@ -402,36 +539,10 @@ func makeTestState(tb testing.TB, script string, cliFlags []string) *GlobalTestS return ts } -func parseMultipartRequest(r *http.Request) (map[string]string, error) { - // Parse the multipart form data - reader, err := r.MultipartReader() - if err != nil { - return nil, err +func writeProvJSON(w http.ResponseWriter, status int, v any) { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(status) + if err := json.NewEncoder(w).Encode(v); err != nil { + panic(fmt.Errorf("writeProvJSON: encoding JSON: %w", err)) } - - // Initialize a map to store the parsed form data - formData := make(map[string]string) - - // Iterate through the parts - for { - part, nextErr := reader.NextPart() - if nextErr == io.EOF { - break - } - if nextErr != nil { - return nil, err - } - - // Read the part content - buf := new(bytes.Buffer) - _, err = io.Copy(buf, part) - if err != nil { - return nil, err - } - - // Store the part content in the map - formData[part.FormName()] = buf.String() - } - - return formData, nil } diff --git a/internal/output/cloud/output.go b/internal/output/cloud/output.go index a1b4c2dd6..71807575b 100644 --- a/internal/output/cloud/output.go +++ b/internal/output/cloud/output.go @@ -2,9 +2,12 @@ package cloud import ( + "context" "errors" "fmt" + "net/http" "path/filepath" + "strconv" "strings" "time" @@ -14,6 +17,7 @@ import ( "go.k6.io/k6/v2/cloudapi" "go.k6.io/k6/v2/errext" "go.k6.io/k6/v2/internal/build" + "go.k6.io/k6/v2/internal/cloudapi/provisioning" "go.k6.io/k6/v2/internal/usage" "go.k6.io/k6/v2/lib" "go.k6.io/k6/v2/metrics" @@ -50,6 +54,21 @@ type cloudClient interface { TestFinished(referenceID string, thresholds cloudapi.ThresholdResult, tainted bool, runStatus cloudapi.RunStatus) error } +// metricsPusher is the metrics-push HTTP layer used in provisioning mode. +// Production implementation: *provisioning.HTTPClient. +// Tests inject mocks via field assignment. +type metricsPusher interface { + Do(req *http.Request, v any) error +} + +// provisioningNotifier is the orchestrator-level client used to call notify +// at end-of-test in provisioning mode. +// Production implementation: *provisioning.Client. +// Tests inject mocks via field assignment. +type provisioningNotifier interface { + NotifyTestRunCompleted(ctx context.Context, testRunID int64, token string, testErr error) error +} + type apiVersion int64 const ( @@ -81,6 +100,17 @@ type Output struct { client cloudClient testStopFunc func(error) + // Provisioning-mode dependencies. nil for --out cloud and PushRefID; + // lazy-constructed in Start when Config.MetricsPushURL.Valid. + // Tests inject mocks via field assignment. + metricsPusher metricsPusher + provisioningNotifier provisioningNotifier + + // provisioningMode gates the provisioning-mode runtime path. Set in + // lazyInitProvisioning after both deps are constructed; read by + // startVersionedOutput and testFinished. + provisioningMode bool + usage *usage.Usage } @@ -192,6 +222,17 @@ func (out *Output) Start() error { if out.testRunID != "" { out.logger.WithField("testRunId", out.testRunID).Debug("Directly pushing metrics without init") + + // Provisioning-mode setup. PushRefID flows don't set + // MetricsPushURL, so this block is normally skipped for them. + // The explicit !PushRefID.Valid guard is defensive against a + // future cmd-layer regression that populates both fields. + if out.config.MetricsPushURL.Valid && out.config.TestRunToken.Valid && !out.config.PushRefID.Valid { + if err := out.lazyInitProvisioning(); err != nil { + return err + } + } + return out.startVersionedOutput() } @@ -298,6 +339,23 @@ func (out *Output) testFinished(testErr error) error { return nil } + // Provisioning mode: notify instead of legacy TestFinished. Gate on + // the explicit flag set by lazyInitProvisioning, not on Config fields. + if out.provisioningMode { + // The provisioning API test-run IDs are int64; parse the full range. + testRunIDInt, err := strconv.ParseInt(out.testRunID, 10, 64) + if err != nil { + out.logger.WithError(err).Warn("could not parse testRunID for notify; skipping") + return nil + } + return out.provisioningNotifier.NotifyTestRunCompleted( + context.Background(), + testRunIDInt, + out.config.TestRunToken.String, + testErr, + ) + } + testTainted := false thresholdResults := make(cloudapi.ThresholdResult) for name, thresholds := range out.thresholds { @@ -392,6 +450,17 @@ func (out *Output) startVersionedOutput() error { err = errors.New("v1 is not supported anymore") case int64(apiVersion2): out.versionedOutput, err = cloudv2.New(out.logger, out.config, nil) + if err != nil { + break + } + + // Inject provisioning overrides if in provisioning mode. + if out.provisioningMode { + if v, ok := out.versionedOutput.(*cloudv2.Output); ok { + v.SetMetricsHTTPClient(out.metricsPusher) + v.SetMetricsURL(out.config.MetricsPushURL.String) + } + } default: err = fmt.Errorf("v%d is an unexpected version", out.config.APIVersion.Int64) } @@ -404,3 +473,51 @@ func (out *Output) startVersionedOutput() error { out.versionedOutput.SetTestRunStopCallback(out.testStopFunc) return out.versionedOutput.Start() } + +// lazyInitProvisioning constructs the provisioning-mode dependencies +// (metrics-push HTTP client and provisioning notifier) when they haven't +// been injected already. Tests inject mocks via field assignment before +// calling Start. +func (out *Output) lazyInitProvisioning() error { + // Lazy-construct the metrics-push HTTP client if not already injected + // (tests inject mocks via field assignment). + if out.metricsPusher == nil { + // Fresh *http.Client with the configured timeout (mirrors what + // cloudapi.Client constructs internally). Body-reset on retries + // is handled inside provisioning.HTTPClient.Do (via doWithRetry's + // explicit req.GetBody() between attempts), not at the transport + // layer — so a vanilla http.Client suffices. + httpClient := &http.Client{ + Timeout: out.config.Timeout.TimeDuration(), + } + out.metricsPusher = provisioning.NewHTTPClient( + httpClient, + out.config.TestRunToken.String, + build.Version, + out.logger, + ) + } + + // Lazy-construct the provisioning notifier (used at end-of-test). + if out.provisioningNotifier == nil { + // The stack ID is required and passed as int64; provisioning.NewClient + // enforces the int32 X-Stack-Id boundary internally. + c, err := provisioning.NewClient( + out.logger, + out.config.Token.String, // long-lived k6 token (NOT scoped) + out.config.Hostv6.String, + build.Version, + out.config.StackID.Int64, + out.config.Timeout.TimeDuration(), + ) + if err != nil { + return fmt.Errorf("provisioning client init: %w", err) + } + out.provisioningNotifier = c + } + + // Both deps constructed; arm the gate. + out.provisioningMode = true + + return nil +} diff --git a/internal/output/cloud/output_test.go b/internal/output/cloud/output_test.go index 149193dca..9f7f0f7fc 100644 --- a/internal/output/cloud/output_test.go +++ b/internal/output/cloud/output_test.go @@ -1,11 +1,14 @@ package cloud import ( + "context" + "encoding/json" "errors" "fmt" "net/http" "net/http/httptest" "net/url" + "sync/atomic" "testing" "testing/synctest" "time" @@ -275,8 +278,37 @@ func TestOutputStopWithTestError(t *testing.T) { }) } +// Locks in the symmetric-gating property: the stop-time decision must read +// out.provisioningMode (set by lazyInitProvisioning), never the Config fields +// directly. Otherwise a future divergence (Config fields populated without +// lazyInit running) would nil-deref out.provisioningNotifier. +func TestOutputStopWithTestError_ConfigFieldsAloneDoNotInferProvisioningMode(t *testing.T) { + t.Parallel() + synctest.Test(t, func(t *testing.T) { + mock := &cloudClientMock{} + out := &Output{ + logger: testutils.NewLogger(t), + testRunID: "1234", + client: mock, + // Config fields populated; lazyInit did not run; deps nil. + config: cloudapi.Config{ + MetricsPushURL: null.StringFrom("https://ingest.example/metrics/abc"), + TestRunToken: null.StringFrom("scoped-token"), + }, + } + out.versionedOutput = versionedOutputMock{callback: func(string) {}} + + require.NoError(t, out.StopWithTestError(nil)) + + require.True(t, mock.testFinishedCalled, + "legacy TestFinished must be called when provisioningMode is false") + }) +} + // cloudClientMock implements cloudClient for tests without starting a real HTTP server. type cloudClientMock struct { + createTestRunFn func(*cloudapi.TestRun) (*cloudapi.CreateTestRunResponse, error) + testFinishedCalled bool testFinishedRefID string testFinishedThresholds cloudapi.ThresholdResult @@ -284,7 +316,10 @@ type cloudClientMock struct { testFinishedRunStatus cloudapi.RunStatus } -func (m *cloudClientMock) CreateTestRun(_ *cloudapi.TestRun) (*cloudapi.CreateTestRunResponse, error) { +func (m *cloudClientMock) CreateTestRun(tr *cloudapi.TestRun) (*cloudapi.CreateTestRunResponse, error) { + if m.createTestRunFn != nil { + return m.createTestRunFn(tr) + } return &cloudapi.CreateTestRunResponse{}, nil } @@ -364,3 +399,269 @@ func (o versionedOutputMock) SetTestRunID(_ string) { func (o versionedOutputMock) AddMetricSamples(_ []metrics.SampleContainer) { o.callback("AddMetricSamples") } + +// metricsPusherMock implements metricsPusher for tests. +type metricsPusherMock struct { + doCalls atomic.Int32 +} + +func (m *metricsPusherMock) Do(_ *http.Request, _ any) error { + m.doCalls.Add(1) + return nil +} + +// provisioningNotifierMock implements provisioningNotifier for tests. +type provisioningNotifierMock struct { + called atomic.Bool + callCount atomic.Int32 + + // Captured arguments from the most recent call. + testRunID int64 + token string + testErr error +} + +func (m *provisioningNotifierMock) NotifyTestRunCompleted(_ context.Context, testRunID int64, token string, testErr error) error { + m.called.Store(true) + m.callCount.Add(1) + m.testRunID = testRunID + m.token = token + m.testErr = testErr + return nil +} + +func TestOutputStart_ProvisioningMode(t *testing.T) { + t.Parallel() + + // Build the JSON config containing MetricsPushURL and TestRunToken + // (the provisioning-mode fields on cloudapi.Config). + cfgJSON, err := json.Marshal(cloudapi.Config{ + Host: null.StringFrom("https://fake-cloud"), + Token: null.StringFrom("fake-long-lived-token"), + MetricsPushURL: null.StringFrom("https://metrics.example.com/v2/metrics/123"), + TestRunToken: null.StringFrom("scoped-test-run-token"), + APIVersion: null.IntFrom(2), + AggregationPeriod: types.NullDurationFrom(1 * time.Hour), + MetricPushInterval: types.NullDurationFrom(1 * time.Hour), + AggregationWaitPeriod: types.NullDurationFrom(1 * time.Second), + MaxTimeSeriesInBatch: null.IntFrom(1000), + MetricPushConcurrency: null.IntFrom(1), + }) + require.NoError(t, err) + + out, err := newOutput(output.Params{ + Logger: testutils.NewLogger(t), + JSONConfig: cfgJSON, + ScriptOptions: lib.Options{ + Duration: types.NullDurationFrom(1 * time.Second), + SystemTags: &metrics.DefaultSystemTagSet, + }, + ScriptPath: &url.URL{Path: "/script.js"}, + RuntimeOptions: lib.RuntimeOptions{ + Env: map[string]string{ + "K6_CLOUDRUN_TEST_RUN_ID": "12345", + }, + }, + Usage: usage.New(), + }) + require.NoError(t, err) + + // Inject a cloudClient mock whose CreateTestRun would fail the test + // if called — regression assertion that the provisioning path never + // falls through to the CreateTestRun legacy branch. + out.client = &cloudClientMock{ + createTestRunFn: func(_ *cloudapi.TestRun) (*cloudapi.CreateTestRunResponse, error) { + t.Fatal("CreateTestRun must not be called in provisioning mode") + return nil, errors.New("unreachable") + }, + } + + // Inject mocks for the provisioning-mode dependencies. + pusherMock := &metricsPusherMock{} + notifierMock := &provisioningNotifierMock{} + out.metricsPusher = pusherMock + out.provisioningNotifier = notifierMock + + // Start should succeed. + require.NoError(t, out.Start()) + + // The versionedOutput must be an *expv2.Output (api version 2). + expv2Out, ok := out.versionedOutput.(*cloudv2.Output) + require.True(t, ok, "expected versionedOutput to be *cloudv2.Output") + assert.NotNil(t, expv2Out) + + // Feed a sample so the stop-time flush exercises the metrics-push path, + // and confirm it goes through the injected metricsPusher rather than a + // real HTTP client. + r := metrics.NewRegistry() + m := r.MustNewMetric("test_metric", metrics.Counter) + out.AddMetricSamples([]metrics.SampleContainer{ + metrics.Sample{ + TimeSeries: metrics.TimeSeries{Metric: m, Tags: r.RootTagSet()}, + Time: time.Now(), + Value: 1.0, + }, + }) + + // Stop force-flushes the queued samples. + require.NoError(t, out.StopWithTestError(nil)) + + assert.Positive(t, pusherMock.doCalls.Load(), + "queued metrics should be pushed through the injected metricsPusher") +} + +// TestOutputStart_PushRefIDStillTakesPrecedence locks in cloud-Output +// behaviour even if cmd ever populated both PushRefID and MetricsPushURL. +// In practice, cmd/outputs_cloud.go:96-100 short-circuits on PushRefID +// before MetricsPushURL is ever set — so this combination shouldn't +// occur. This test is defensive against future cmd-layer regressions. +func TestOutputStart_PushRefIDStillTakesPrecedence(t *testing.T) { + t.Parallel() + + cfgJSON, err := json.Marshal(cloudapi.Config{ + Host: null.StringFrom("https://fake-cloud"), + Token: null.StringFrom("fake-token"), + PushRefID: null.StringFrom("99999"), + MetricsPushURL: null.StringFrom("https://metrics.example.com/v2/metrics/123"), + TestRunToken: null.StringFrom("scoped-test-run-token"), + APIVersion: null.IntFrom(2), + AggregationPeriod: types.NullDurationFrom(1 * time.Hour), + MetricPushInterval: types.NullDurationFrom(1 * time.Hour), + AggregationWaitPeriod: types.NullDurationFrom(1 * time.Second), + MaxTimeSeriesInBatch: null.IntFrom(1000), + MetricPushConcurrency: null.IntFrom(1), + }) + require.NoError(t, err) + + out, err := newOutput(output.Params{ + Logger: testutils.NewLogger(t), + JSONConfig: cfgJSON, + ScriptOptions: lib.Options{ + Duration: types.NullDurationFrom(1 * time.Second), + SystemTags: &metrics.DefaultSystemTagSet, + }, + ScriptPath: &url.URL{Path: "/script.js"}, + Usage: usage.New(), + }) + require.NoError(t, err) + + require.NoError(t, out.Start()) + + // PushRefID should win: testRunID should be set to the PushRefID value, + // not the testRunID from env. + assert.Equal(t, "99999", out.testRunID) + + // The metricsPusher field should remain nil — provisioning mode was NOT + // entered because PushRefID took precedence. + assert.Nil(t, out.metricsPusher, "metricsPusher should be nil when PushRefID takes precedence") + assert.Nil(t, out.provisioningNotifier, "provisioningNotifier should be nil when PushRefID takes precedence") + + require.NoError(t, out.StopWithTestError(nil)) +} + +func TestOutputStopWithTestError_ProvisioningMode_NoError(t *testing.T) { + t.Parallel() + synctest.Test(t, func(t *testing.T) { + notifierMock := &provisioningNotifierMock{} + clientMock := &cloudClientMock{} + + out := &Output{ + logger: testutils.NewLogger(t), + testRunID: "12345", + config: cloudapi.Config{ + MetricsPushURL: null.StringFrom("https://metrics.example.com/v2/metrics/123"), + TestRunToken: null.StringFrom("scoped-test-run-token"), + }, + client: clientMock, + provisioningNotifier: notifierMock, + provisioningMode: true, + } + + out.versionedOutput = versionedOutputMock{ + callback: func(_ string) {}, + } + + require.NoError(t, out.StopWithTestError(nil)) + + // Notify was called exactly once with the right arguments. + assert.True(t, notifierMock.called.Load()) + assert.Equal(t, int32(1), notifierMock.callCount.Load()) + assert.Equal(t, int64(12345), notifierMock.testRunID) + assert.Equal(t, "scoped-test-run-token", notifierMock.token) + assert.Nil(t, notifierMock.testErr) + + // TestFinished was NOT called (regression assertion). + assert.False(t, clientMock.testFinishedCalled) + }) +} + +func TestOutputStopWithTestError_ProvisioningMode_WithTestError(t *testing.T) { + t.Parallel() + synctest.Test(t, func(t *testing.T) { + notifierMock := &provisioningNotifierMock{} + clientMock := &cloudClientMock{} + + scriptErr := errext.WithAbortReasonIfNone( + errors.New("script error"), + errext.AbortedByScriptError, + ) + + out := &Output{ + logger: testutils.NewLogger(t), + testRunID: "12345", + config: cloudapi.Config{ + MetricsPushURL: null.StringFrom("https://metrics.example.com/v2/metrics/123"), + TestRunToken: null.StringFrom("scoped-test-run-token"), + }, + client: clientMock, + provisioningNotifier: notifierMock, + provisioningMode: true, + } + + out.versionedOutput = versionedOutputMock{ + callback: func(_ string) {}, + } + + require.NoError(t, out.StopWithTestError(scriptErr)) + + // Notify was called with the error verbatim (mapping to code 8035 + // happens inside the real notifier, which is mocked here). + assert.True(t, notifierMock.called.Load()) + assert.Equal(t, int64(12345), notifierMock.testRunID) + assert.Equal(t, "scoped-test-run-token", notifierMock.token) + assert.Equal(t, scriptErr, notifierMock.testErr) + + // TestFinished was NOT called. + assert.False(t, clientMock.testFinishedCalled) + }) +} + +func TestOutputStopWithTestError_PushRefID_NoNotifyNoTestFinished(t *testing.T) { + t.Parallel() + synctest.Test(t, func(t *testing.T) { + notifierMock := &provisioningNotifierMock{} + clientMock := &cloudClientMock{} + + out := &Output{ + logger: testutils.NewLogger(t), + testRunID: "12345", + config: cloudapi.Config{ + PushRefID: null.StringFrom("99999"), + MetricsPushURL: null.StringFrom("https://metrics.example.com/v2/metrics/123"), + TestRunToken: null.StringFrom("scoped-test-run-token"), + }, + client: clientMock, + provisioningNotifier: notifierMock, + } + + out.versionedOutput = versionedOutputMock{ + callback: func(_ string) {}, + } + + require.NoError(t, out.StopWithTestError(nil)) + + // PushRefID short-circuits: NEITHER notify NOR TestFinished called. + assert.False(t, notifierMock.called.Load()) + assert.False(t, clientMock.testFinishedCalled) + }) +} diff --git a/output/cloud/expv2/metrics_client.go b/output/cloud/expv2/metrics_client.go index bc0f64db4..f0131b2a3 100644 --- a/output/cloud/expv2/metrics_client.go +++ b/output/cloud/expv2/metrics_client.go @@ -15,11 +15,9 @@ import ( "go.k6.io/k6/v2/internal/output/cloud/expv2/pbcloud" ) -// metricsHTTPClient is the interface used by metricsClient to perform HTTP requests. -// It allows tests to inject a mock that returns immediately without using real HTTP. +// metricsHTTPClient is the HTTP transport contract used by metricsClient. type metricsHTTPClient interface { Do(req *http.Request, v any) error - BaseURL() string } // metricsClient is a Protobuf over HTTP client for sending @@ -30,25 +28,35 @@ type metricsClient struct { url string } -// newMetricsClient creates and initializes a new MetricsClient. -func newMetricsClient(c metricsHTTPClient, testRunID string) (*metricsClient, error) { - // The cloudapi.Client works across different versions of the API, the test - // lifecycle management is under /v1 instead the metrics ingestion is /v2. - // Unfortunately, the current client has v1 hard-coded so we need to trim the wrong path - // to be able to replace it with the correct one. - // A versioned client would be better but it would require a breaking change - // and considering that other services (e.g. k6-operator) depend on it, - // we want to stabilize the API before. - u := c.BaseURL() - if !strings.HasSuffix(u, "/v1") { - return nil, errors.New("a /v1 suffix is expected in the Cloud service's BaseURL path") +// deriveMetricsURL builds the v2 metrics-ingestion URL from the Cloud +// service base URL, used when no explicit push URL was provided. +// +// The cloudapi.Client works across different versions of the API: test +// lifecycle management is under /v1 while metrics ingestion is /v2. +// The client has /v1 hard-coded, so we trim it and replace with /v2. +// A versioned client would be better but it would require a breaking +// change, and other services (e.g. k6-operator) depend on it, so we want +// to stabilize the API first. +func deriveMetricsURL(baseURL, testRunID string) (string, error) { + if !strings.HasSuffix(baseURL, "/v1") { + return "", errors.New("a /v1 suffix is expected in the Cloud service's BaseURL path") } if testRunID == "" { - return nil, errors.New("TestRunID of the test is required") + return "", errors.New("TestRunID of the test is required") + } + return strings.TrimSuffix(baseURL, "/v1") + "/v2/metrics/" + testRunID, nil +} + +// newMetricsClientWithURL builds a metricsClient with an explicit push URL. +// It is the single metricsClient constructor: callers that need the +// host-derived URL compute it via deriveMetricsURL first. +func newMetricsClientWithURL(c metricsHTTPClient, url string) (*metricsClient, error) { + if url == "" { + return nil, errors.New("metrics push URL is required") } return &metricsClient{ httpClient: c, - url: strings.TrimSuffix(u, "/v1") + "/v2/metrics/" + testRunID, + url: url, }, nil } diff --git a/output/cloud/expv2/metrics_client_test.go b/output/cloud/expv2/metrics_client_test.go index bd7f32cda..02f199418 100644 --- a/output/cloud/expv2/metrics_client_test.go +++ b/output/cloud/expv2/metrics_client_test.go @@ -38,7 +38,9 @@ func TestMetricsClientPush(t *testing.T) { defer ts.Close() c := cloudapi.NewClient(nil, "fake-token", ts.URL, "k6cloud/v0.4", 1*time.Second) - mc, err := newMetricsClient(c, "test-ref-id") + url, err := deriveMetricsURL(c.BaseURL(), "test-ref-id") + require.NoError(t, err) + mc, err := newMetricsClientWithURL(c, url) require.NoError(t, err) mset := pbcloud.MetricSet{} @@ -54,14 +56,14 @@ func TestMetricsClientPushUnexpectedStatus(t *testing.T) { mock := &mockMetricsHTTPClient{ doErr: errors.New("500 Internal Server Error"), } - mc, err := newMetricsClient(mock, "test-ref-id") + mc, err := newMetricsClientWithURL(mock, "http://test/v2/metrics/test-ref-id") require.NoError(t, err) err = mc.push(t.Context(), nil) assert.ErrorContains(t, err, "500 Internal Server Error") } -// mockMetricsHTTPClient implements metricsHTTPClient for tests. +// mockMetricsHTTPClient implements the metricsHTTPClient interface for tests. // It returns immediately without making HTTP requests. type mockMetricsHTTPClient struct { doErr error @@ -71,6 +73,45 @@ func (m *mockMetricsHTTPClient) Do(_ *http.Request, _ any) error { return m.doErr } -func (m *mockMetricsHTTPClient) BaseURL() string { - return "http://test/v1" +func TestNewMetricsClientWithURL(t *testing.T) { + t.Parallel() + + stub := &mockMetricsHTTPClient{} + mc, err := newMetricsClientWithURL(stub, "https://ingest.example/metrics/abc") + require.NoError(t, err) + assert.Equal(t, "https://ingest.example/metrics/abc", mc.url) + assert.Equal(t, stub, mc.httpClient) +} + +func TestNewMetricsClientWithURL_EmptyURLReturnsError(t *testing.T) { + t.Parallel() + + stub := &mockMetricsHTTPClient{} + _, err := newMetricsClientWithURL(stub, "") + require.Error(t, err) + assert.Contains(t, err.Error(), "metrics push URL is required") +} + +func TestDeriveMetricsURL(t *testing.T) { + t.Parallel() + + url, err := deriveMetricsURL("https://ingest.example/v1", "12345") + require.NoError(t, err) + assert.Equal(t, "https://ingest.example/v2/metrics/12345", url) +} + +func TestDeriveMetricsURL_MissingV1Suffix(t *testing.T) { + t.Parallel() + + _, err := deriveMetricsURL("https://ingest.example", "12345") + require.Error(t, err) + assert.Contains(t, err.Error(), "/v1 suffix") +} + +func TestDeriveMetricsURL_EmptyTestRunID(t *testing.T) { + t.Parallel() + + _, err := deriveMetricsURL("https://ingest.example/v1", "") + require.Error(t, err) + assert.Contains(t, err.Error(), "TestRunID") } diff --git a/output/cloud/expv2/output.go b/output/cloud/expv2/output.go index 2770a8451..3701e135e 100644 --- a/output/cloud/expv2/output.go +++ b/output/cloud/expv2/output.go @@ -48,6 +48,9 @@ type Output struct { requestMetadatasCollector insightsOutput.RequestMetadatasCollector requestMetadatasFlusher insightsOutput.RequestMetadatasFlusher + metricsHTTPClient metricsHTTPClient // optional override + metricsURL string // optional override + // wg tracks background goroutines wg sync.WaitGroup @@ -85,6 +88,19 @@ func (o *Output) SetTestRunID(id string) { o.testRunID = id } +// SetMetricsHTTPClient injects a metricsHTTPClient for metric pushes. +// Used by the provisioning-mode flow to provide a Bearer-authenticated +// HTTP layer. +func (o *Output) SetMetricsHTTPClient(c metricsHTTPClient) { + o.metricsHTTPClient = c +} + +// SetMetricsURL injects an explicit metrics push URL. Used by the +// provisioning-mode flow where the URL comes from the API. +func (o *Output) SetMetricsURL(url string) { + o.metricsURL = url +} + // SetTestRunStopCallback receives the function that // that stops the engine when it is called. // It should be called on critical errors. @@ -106,7 +122,26 @@ func (o *Output) Start() error { return fmt.Errorf("failed to initialize the samples collector: %w", err) } - mc, err := newMetricsClient(o.cloudClient, o.testRunID) + // The metrics client always pushes to an explicit URL. In provisioning + // mode both the HTTP client and URL are injected via the setters; + // otherwise we derive the legacy /v2/metrics/ URL from the + // cloud client. The two must be set together — one without the other is + // a misconfiguration rather than a silent fallback. + switch { + case o.metricsHTTPClient != nil && o.metricsURL != "": + // Both injected (provisioning mode); use as-is. + case o.metricsHTTPClient == nil && o.metricsURL == "": + o.metricsURL, err = deriveMetricsURL(o.cloudClient.BaseURL(), o.testRunID) + if err != nil { + return fmt.Errorf("failed to derive the metrics push URL: %w", err) + } + o.metricsHTTPClient = o.cloudClient + default: + return errors.New("metrics push client misconfigured: " + + "metricsHTTPClient and metricsURL must be set together") + } + + mc, err := newMetricsClientWithURL(o.metricsHTTPClient, o.metricsURL) if err != nil { return fmt.Errorf("failed to initialize the http metrics flush client: %w", err) } diff --git a/output/cloud/expv2/output_test.go b/output/cloud/expv2/output_test.go index 0c90510f3..68b28d67e 100644 --- a/output/cloud/expv2/output_test.go +++ b/output/cloud/expv2/output_test.go @@ -563,6 +563,36 @@ func (ff requestMetadatasFlusherFunc) Flush(ctx context.Context) error { return nil } +func TestOutputSetters_OverrideMetricsClientAndURL(t *testing.T) { + t.Parallel() + + conf := cloudapi.Config{ + Host: null.StringFrom("host-not-used-for-override"), + Token: null.StringFrom("a-fake-token"), + AggregationWaitPeriod: types.NewNullDuration(5*time.Second, true), + AggregationPeriod: types.NewNullDuration(1*time.Hour, true), + MetricPushInterval: types.NewNullDuration(1*time.Hour, true), + } + logger := testutils.NewLogger(t) + o, err := New(logger, conf, nil) + require.NoError(t, err) + + stub := &mockMetricsHTTPClient{} + o.SetMetricsHTTPClient(stub) + o.SetMetricsURL("https://override.example/m/123") + o.SetTestRunID("run-42") + + require.NoError(t, o.Start()) + defer func() { require.NoError(t, o.StopWithTestError(nil)) }() + + mf, ok := o.flushing.(*metricsFlusher) + require.True(t, ok) + mc, ok := mf.client.(*metricsClient) + require.True(t, ok) + assert.Equal(t, "https://override.example/m/123", mc.url) + assert.Equal(t, stub, mc.httpClient) +} + func TestPrintableConfig(t *testing.T) { t.Parallel() From 82b9d626fabe9b98279c79d2c37166f23bcd0761 Mon Sep 17 00:00:00 2001 From: Ankur Date: Wed, 22 Jul 2026 14:44:55 +0100 Subject: [PATCH 034/182] Fix cloud secrets error when reusing a test run (#6096) When a test run is reused via K6_CLOUD_PUSH_REF_ID, k6 skips CreateTestRun (#5814) to avoid orphan runs. That response is the only place the cloud secret source is configured from the cloud API, so secrets.get() failed with a message telling the user to use 'k6 cloud run --local-execution' -- which they already were. The cloud secret source now reads K6_CLOUD_PUSH_REF_ID from its params and, when set, points users to K6_CLOUD_SECRETS_TOKEN and K6_CLOUD_SECRETS_ENDPOINT instead. The generic message is unchanged for all other cases. Resolves: https://github.com/grafana/k6/issues/6050 --- internal/secretsource/cloud/cloud.go | 20 ++++++++++++++--- internal/secretsource/cloud/cloud_test.go | 26 +++++++++++++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/internal/secretsource/cloud/cloud.go b/internal/secretsource/cloud/cloud.go index 796a466ed..ade390bbd 100644 --- a/internal/secretsource/cloud/cloud.go +++ b/internal/secretsource/cloud/cloud.go @@ -72,6 +72,22 @@ func (cs *SecretSource) Description() string { return "Grafana Cloud k6 secret source" } +// notConfiguredError explains why no secrets configuration is available. When a test run is +// reused via the K6_CLOUD_PUSH_REF_ID env var, CreateTestRun is skipped (see #5814) so the +// config can't come from its response and must instead be supplied via the K6_CLOUD_SECRETS_* +// env vars; otherwise the generic 'k6 cloud run --local-execution' guidance applies (#6050). +func (cs *SecretSource) notConfiguredError() error { + const prefix = "cloud secrets not configured: no secrets configuration available. " + if cs.params.Environment["K6_CLOUD_PUSH_REF_ID"] != "" { + return errors.New(prefix + + "When an existing test run is reused via K6_CLOUD_PUSH_REF_ID, set " + + "K6_CLOUD_SECRETS_TOKEN and K6_CLOUD_SECRETS_ENDPOINT to enable cloud secrets") + } + return errors.New(prefix + + "Make sure you're using 'k6 cloud run --local-execution' and the cloud API " + + "returned secrets configuration") +} + // ensureInitialized builds (or rebuilds) the URL source from configPtr. func (cs *SecretSource) ensureInitialized() (secretsource.Source, error) { cs.mu.Lock() @@ -90,9 +106,7 @@ func (cs *SecretSource) ensureInitialized() (secretsource.Source, error) { cs.initErr = nil if current == nil { - cs.initErr = errors.New("cloud secrets not configured: no secrets configuration available. " + - "Make sure you're using 'k6 cloud run --local-execution' and the cloud API " + - "returned secrets configuration") + cs.initErr = cs.notConfiguredError() return nil, cs.initErr } diff --git a/internal/secretsource/cloud/cloud_test.go b/internal/secretsource/cloud/cloud_test.go index 518347331..43b420f32 100644 --- a/internal/secretsource/cloud/cloud_test.go +++ b/internal/secretsource/cloud/cloud_test.go @@ -49,6 +49,32 @@ func TestCloudSecretsRequiresConfig(t *testing.T) { require.Contains(t, err.Error(), "cloud secrets not configured") } +// TestCloudSecretsNotConfiguredMessage verifies the "not configured" error adapts to context: +// the reuse-specific guidance appears only when K6_CLOUD_PUSH_REF_ID is set, otherwise the +// generic 'k6 cloud run --local-execution' message is used. +func TestCloudSecretsNotConfiguredMessage(t *testing.T) { + t.Parallel() + + // Without K6_CLOUD_PUSH_REF_ID: generic guidance. + generic, err := New(makeParams()) + require.NoError(t, err) + _, err = generic.Get("test-key") + require.Error(t, err) + require.Contains(t, err.Error(), "Make sure you're using 'k6 cloud run --local-execution'") + require.NotContains(t, err.Error(), "K6_CLOUD_PUSH_REF_ID") + + // With K6_CLOUD_PUSH_REF_ID: reuse-specific guidance. + params := makeParams() + params.Environment = map[string]string{"K6_CLOUD_PUSH_REF_ID": "12345"} + reused, err := New(params) + require.NoError(t, err) + _, err = reused.Get("test-key") + require.Error(t, err) + require.Contains(t, err.Error(), "K6_CLOUD_PUSH_REF_ID") + require.Contains(t, err.Error(), "K6_CLOUD_SECRETS_TOKEN") + require.NotContains(t, err.Error(), "Make sure you're using 'k6 cloud run --local-execution'") +} + // TestCloudSecretsDescription verifies the extension is registered with the expected description. func TestCloudSecretsDescription(t *testing.T) { t.Parallel() From 1e60453af2256fb8d5264c66580245ef31b5d6ca Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Wed, 22 Jul 2026 23:01:48 +0200 Subject: [PATCH 035/182] fix(deps): update module buf.build/gen/go/prometheus/prometheus/protocolbuffers/go to v1.36.11-20260707164124-2360da55afce.1 (#6175) | datasource | package | from | to | | ---------- | --------------------------------------------------------- | -------------------------------------- | -------------------------------------- | | go | buf.build/gen/go/prometheus/prometheus/protocolbuffers/go | v1.36.11-20260331160422-eae785f0a21d.1 | v1.36.11-20260707164124-2360da55afce.1 | Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 +-- .../prometheus/protocolbuffers/go/types.pb.go | 34 +++++++++++++------ .../go/types_protoopaque.pb.go | 34 +++++++++++++------ vendor/modules.txt | 2 +- 5 files changed, 50 insertions(+), 26 deletions(-) diff --git a/go.mod b/go.mod index aaa51a07c..c4200d8da 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.25.0 toolchain go1.25.12 require ( - buf.build/gen/go/prometheus/prometheus/protocolbuffers/go v1.36.11-20260331160422-eae785f0a21d.1 + buf.build/gen/go/prometheus/prometheus/protocolbuffers/go v1.36.11-20260707164124-2360da55afce.1 github.com/Azure/go-ntlmssp v0.1.1 github.com/Masterminds/semver/v3 v3.5.0 github.com/PuerkitoBio/goquery v1.12.0 diff --git a/go.sum b/go.sum index 742c954cc..cffb66d6d 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ buf.build/gen/go/gogo/protobuf/protocolbuffers/go v1.36.11-20240617172848-e1dbca2775a7.1 h1:FlXwksX9wjddXoyW88Jw3tz1DEGbXBSGZW6fg0frZ0M= buf.build/gen/go/gogo/protobuf/protocolbuffers/go v1.36.11-20240617172848-e1dbca2775a7.1/go.mod h1:mwDA6SccUlW4ebUkJTpKoHZzCrLFh/WI48oQRvUTGAA= -buf.build/gen/go/prometheus/prometheus/protocolbuffers/go v1.36.11-20260331160422-eae785f0a21d.1 h1:OyFGRpH4F78kDv9OdkRyzfrBnnJO97nYCP5dIfkOzDk= -buf.build/gen/go/prometheus/prometheus/protocolbuffers/go v1.36.11-20260331160422-eae785f0a21d.1/go.mod h1:6rM4oiNLtvSABJBFC+GReCtGUaWLYwhsadnb9FgJ/2k= +buf.build/gen/go/prometheus/prometheus/protocolbuffers/go v1.36.11-20260707164124-2360da55afce.1 h1:M4YtW8f34aXlYH7qlusABkaxVkhn3n6gOVjATbhqVfQ= +buf.build/gen/go/prometheus/prometheus/protocolbuffers/go v1.36.11-20260707164124-2360da55afce.1/go.mod h1:6rM4oiNLtvSABJBFC+GReCtGUaWLYwhsadnb9FgJ/2k= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/Azure/go-ntlmssp v0.1.1 h1:l+FM/EEMb0U9QZE7mKNEDw5Mu3mFiaa2GKOoTSsNDPw= github.com/Azure/go-ntlmssp v0.1.1/go.mod h1:NYqdhxd/8aAct/s4qSYZEerdPuH1liG2/X9DiVTbhpk= diff --git a/vendor/buf.build/gen/go/prometheus/prometheus/protocolbuffers/go/types.pb.go b/vendor/buf.build/gen/go/prometheus/prometheus/protocolbuffers/go/types.pb.go index e53762c2c..b43c11cc4 100644 --- a/vendor/buf.build/gen/go/prometheus/prometheus/protocolbuffers/go/types.pb.go +++ b/vendor/buf.build/gen/go/prometheus/prometheus/protocolbuffers/go/types.pb.go @@ -193,10 +193,13 @@ func (x LabelMatcher_Type) Number() protoreflect.EnumNumber { type Chunk_Encoding int32 const ( - Chunk_UNKNOWN Chunk_Encoding = 0 - Chunk_XOR Chunk_Encoding = 1 - Chunk_HISTOGRAM Chunk_Encoding = 2 - Chunk_FLOAT_HISTOGRAM Chunk_Encoding = 3 + Chunk_UNKNOWN Chunk_Encoding = 0 + Chunk_XOR Chunk_Encoding = 1 + Chunk_HISTOGRAM Chunk_Encoding = 2 + Chunk_FLOAT_HISTOGRAM Chunk_Encoding = 3 + Chunk_XOR2 Chunk_Encoding = 4 + Chunk_HISTOGRAM_ST Chunk_Encoding = 5 + Chunk_FLOAT_HISTOGRAM_ST Chunk_Encoding = 6 ) // Enum value maps for Chunk_Encoding. @@ -206,12 +209,18 @@ var ( 1: "XOR", 2: "HISTOGRAM", 3: "FLOAT_HISTOGRAM", + 4: "XOR2", + 5: "HISTOGRAM_ST", + 6: "FLOAT_HISTOGRAM_ST", } Chunk_Encoding_value = map[string]int32{ - "UNKNOWN": 0, - "XOR": 1, - "HISTOGRAM": 2, - "FLOAT_HISTOGRAM": 3, + "UNKNOWN": 0, + "XOR": 1, + "HISTOGRAM": 2, + "FLOAT_HISTOGRAM": 3, + "XOR2": 4, + "HISTOGRAM_ST": 5, + "FLOAT_HISTOGRAM_ST": 6, } ) @@ -1827,17 +1836,20 @@ const file_types_proto_rawDesc = "" + "\x06end_ms\x18\x04 \x01(\x03R\x05endMs\x12\x1a\n" + "\bgrouping\x18\x05 \x03(\tR\bgrouping\x12\x0e\n" + "\x02by\x18\x06 \x01(\bR\x02by\x12\x19\n" + - "\brange_ms\x18\a \x01(\x03R\arangeMs\"\xd1\x01\n" + + "\brange_ms\x18\a \x01(\x03R\arangeMs\"\x85\x02\n" + "\x05Chunk\x12\x1e\n" + "\vmin_time_ms\x18\x01 \x01(\x03R\tminTimeMs\x12\x1e\n" + "\vmax_time_ms\x18\x02 \x01(\x03R\tmaxTimeMs\x12.\n" + "\x04type\x18\x03 \x01(\x0e2\x1a.prometheus.Chunk.EncodingR\x04type\x12\x12\n" + - "\x04data\x18\x04 \x01(\fR\x04data\"D\n" + + "\x04data\x18\x04 \x01(\fR\x04data\"x\n" + "\bEncoding\x12\v\n" + "\aUNKNOWN\x10\x00\x12\a\n" + "\x03XOR\x10\x01\x12\r\n" + "\tHISTOGRAM\x10\x02\x12\x13\n" + - "\x0fFLOAT_HISTOGRAM\x10\x03\"q\n" + + "\x0fFLOAT_HISTOGRAM\x10\x03\x12\b\n" + + "\x04XOR2\x10\x04\x12\x10\n" + + "\fHISTOGRAM_ST\x10\x05\x12\x16\n" + + "\x12FLOAT_HISTOGRAM_ST\x10\x06\"q\n" + "\rChunkedSeries\x12/\n" + "\x06labels\x18\x01 \x03(\v2\x11.prometheus.LabelB\x04\xc8\xde\x1f\x00R\x06labels\x12/\n" + "\x06chunks\x18\x02 \x03(\v2\x11.prometheus.ChunkB\x04\xc8\xde\x1f\x00R\x06chunksB;Z9buf.build/gen/go/prometheus/prometheus/protocolbuffers/gob\x06proto3" diff --git a/vendor/buf.build/gen/go/prometheus/prometheus/protocolbuffers/go/types_protoopaque.pb.go b/vendor/buf.build/gen/go/prometheus/prometheus/protocolbuffers/go/types_protoopaque.pb.go index e06ffe2d1..3e365b588 100644 --- a/vendor/buf.build/gen/go/prometheus/prometheus/protocolbuffers/go/types_protoopaque.pb.go +++ b/vendor/buf.build/gen/go/prometheus/prometheus/protocolbuffers/go/types_protoopaque.pb.go @@ -193,10 +193,13 @@ func (x LabelMatcher_Type) Number() protoreflect.EnumNumber { type Chunk_Encoding int32 const ( - Chunk_UNKNOWN Chunk_Encoding = 0 - Chunk_XOR Chunk_Encoding = 1 - Chunk_HISTOGRAM Chunk_Encoding = 2 - Chunk_FLOAT_HISTOGRAM Chunk_Encoding = 3 + Chunk_UNKNOWN Chunk_Encoding = 0 + Chunk_XOR Chunk_Encoding = 1 + Chunk_HISTOGRAM Chunk_Encoding = 2 + Chunk_FLOAT_HISTOGRAM Chunk_Encoding = 3 + Chunk_XOR2 Chunk_Encoding = 4 + Chunk_HISTOGRAM_ST Chunk_Encoding = 5 + Chunk_FLOAT_HISTOGRAM_ST Chunk_Encoding = 6 ) // Enum value maps for Chunk_Encoding. @@ -206,12 +209,18 @@ var ( 1: "XOR", 2: "HISTOGRAM", 3: "FLOAT_HISTOGRAM", + 4: "XOR2", + 5: "HISTOGRAM_ST", + 6: "FLOAT_HISTOGRAM_ST", } Chunk_Encoding_value = map[string]int32{ - "UNKNOWN": 0, - "XOR": 1, - "HISTOGRAM": 2, - "FLOAT_HISTOGRAM": 3, + "UNKNOWN": 0, + "XOR": 1, + "HISTOGRAM": 2, + "FLOAT_HISTOGRAM": 3, + "XOR2": 4, + "HISTOGRAM_ST": 5, + "FLOAT_HISTOGRAM_ST": 6, } ) @@ -1795,17 +1804,20 @@ const file_types_proto_rawDesc = "" + "\x06end_ms\x18\x04 \x01(\x03R\x05endMs\x12\x1a\n" + "\bgrouping\x18\x05 \x03(\tR\bgrouping\x12\x0e\n" + "\x02by\x18\x06 \x01(\bR\x02by\x12\x19\n" + - "\brange_ms\x18\a \x01(\x03R\arangeMs\"\xd1\x01\n" + + "\brange_ms\x18\a \x01(\x03R\arangeMs\"\x85\x02\n" + "\x05Chunk\x12\x1e\n" + "\vmin_time_ms\x18\x01 \x01(\x03R\tminTimeMs\x12\x1e\n" + "\vmax_time_ms\x18\x02 \x01(\x03R\tmaxTimeMs\x12.\n" + "\x04type\x18\x03 \x01(\x0e2\x1a.prometheus.Chunk.EncodingR\x04type\x12\x12\n" + - "\x04data\x18\x04 \x01(\fR\x04data\"D\n" + + "\x04data\x18\x04 \x01(\fR\x04data\"x\n" + "\bEncoding\x12\v\n" + "\aUNKNOWN\x10\x00\x12\a\n" + "\x03XOR\x10\x01\x12\r\n" + "\tHISTOGRAM\x10\x02\x12\x13\n" + - "\x0fFLOAT_HISTOGRAM\x10\x03\"q\n" + + "\x0fFLOAT_HISTOGRAM\x10\x03\x12\b\n" + + "\x04XOR2\x10\x04\x12\x10\n" + + "\fHISTOGRAM_ST\x10\x05\x12\x16\n" + + "\x12FLOAT_HISTOGRAM_ST\x10\x06\"q\n" + "\rChunkedSeries\x12/\n" + "\x06labels\x18\x01 \x03(\v2\x11.prometheus.LabelB\x04\xc8\xde\x1f\x00R\x06labels\x12/\n" + "\x06chunks\x18\x02 \x03(\v2\x11.prometheus.ChunkB\x04\xc8\xde\x1f\x00R\x06chunksB;Z9buf.build/gen/go/prometheus/prometheus/protocolbuffers/gob\x06proto3" diff --git a/vendor/modules.txt b/vendor/modules.txt index 6d4057b02..c8b2b0fb0 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1,7 +1,7 @@ # buf.build/gen/go/gogo/protobuf/protocolbuffers/go v1.36.11-20240617172848-e1dbca2775a7.1 ## explicit; go 1.23 buf.build/gen/go/gogo/protobuf/protocolbuffers/go/gogoproto -# buf.build/gen/go/prometheus/prometheus/protocolbuffers/go v1.36.11-20260331160422-eae785f0a21d.1 +# buf.build/gen/go/prometheus/prometheus/protocolbuffers/go v1.36.11-20260707164124-2360da55afce.1 ## explicit; go 1.23 buf.build/gen/go/prometheus/prometheus/protocolbuffers/go # github.com/Azure/go-ntlmssp v0.1.1 From 8d59f80a37d694990d40c1d4e5e22aafa7d2c9c1 Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Wed, 22 Jul 2026 23:05:40 +0200 Subject: [PATCH 036/182] fix(security/unknown/examples/grpc_server): update module golang.org/x/net to v0.56.0 [security] (#6185) | datasource | package | from | to | | ---------- | ---------------- | ------- | ------- | | go | golang.org/x/net | v0.55.0 | v0.56.0 | Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> --- examples/grpc_server/go.mod | 6 +++--- examples/grpc_server/go.sum | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/grpc_server/go.mod b/examples/grpc_server/go.mod index f86a4e007..1d344782d 100644 --- a/examples/grpc_server/go.mod +++ b/examples/grpc_server/go.mod @@ -10,9 +10,9 @@ require ( ) require ( - golang.org/x/net v0.55.0 // indirect - golang.org/x/sys v0.45.0 // indirect - golang.org/x/text v0.37.0 // indirect + golang.org/x/net v0.56.0 // indirect + golang.org/x/sys v0.46.0 // indirect + golang.org/x/text v0.38.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20260401024825-9d38bb4040a9 // indirect google.golang.org/protobuf v1.36.11 // indirect ) diff --git a/examples/grpc_server/go.sum b/examples/grpc_server/go.sum index 410a7e13f..c190e28b2 100644 --- a/examples/grpc_server/go.sum +++ b/examples/grpc_server/go.sum @@ -24,12 +24,12 @@ go.opentelemetry.io/otel/sdk/metric v1.43.0 h1:S88dyqXjJkuBNLeMcVPRFXpRw2fuwdvfC go.opentelemetry.io/otel/sdk/metric v1.43.0/go.mod h1:C/RJtwSEJ5hzTiUz5pXF1kILHStzb9zFlIEe85bhj6A= go.opentelemetry.io/otel/trace v1.43.0 h1:BkNrHpup+4k4w+ZZ86CZoHHEkohws8AY+WTX09nk+3A= go.opentelemetry.io/otel/trace v1.43.0/go.mod h1:/QJhyVBUUswCphDVxq+8mld+AvhXZLhe+8WVFxiFff0= -golang.org/x/net v0.55.0 h1:bcvxaJn3e1U6InsFWt1JUq1aSjnRxLzT2rtD2KfkDF8= -golang.org/x/net v0.55.0/go.mod h1:L5U2KuzuOe1lY7Z+aWVIKK6qEeJXnXV9yzGA+WCHJww= -golang.org/x/sys v0.45.0 h1:dO4czNzziLiiXplLQgBCEpCvXQ3dnkn0SdaZSYdQ+FY= -golang.org/x/sys v0.45.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= -golang.org/x/text v0.37.0 h1:Cqjiwd9eSg8e0QAkyCaQTNHFIIzWtidPahFWR83rTrc= -golang.org/x/text v0.37.0/go.mod h1:a5sjxXGs9hsn/AJVwuElvCAo9v8QYLzvavO5z2PiM38= +golang.org/x/net v0.56.0 h1:Rw8j/hFzGvJUZwNBXnAtf5sVDVt+65SK2C7IxCxZt5o= +golang.org/x/net v0.56.0/go.mod h1:D3Ku6r+V6JROoZK144D2XfMHFcMq/0zSfLelVTCFKec= +golang.org/x/sys v0.46.0 h1:noSf2Fq6F8DBgS+LysIkx7rIExoNHJsxOAtPp4rthXw= +golang.org/x/sys v0.46.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= +golang.org/x/text v0.38.0 h1:sXmwo9DwP3OK9EZ7PqAdaooSGozfl/3a6/xJcbzPRhE= +golang.org/x/text v0.38.0/go.mod h1:YXZt3QhHUKYT53r2lLKFIVi6Ao1jdzrTR/KQ09qyxF4= gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4= gonum.org/v1/gonum v0.17.0/go.mod h1:El3tOrEuMpv2UdMrbNlKEh9vd86bmQ6vqIcDwxEOc1E= google.golang.org/genproto/googleapis/rpc v0.0.0-20260401024825-9d38bb4040a9 h1:m8qni9SQFH0tJc1X0vmnpw/0t+AImlSvp30sEupozUg= From c993cc76524d265c86a0b7c33f92d2c5dd220d03 Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Wed, 22 Jul 2026 23:23:11 +0200 Subject: [PATCH 037/182] fix(deps): update github.com/grafana/k6-cloud-openapi-client-go digest to 97c9614 (#6173) Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 +- .../k6-cloud-openapi-client-go/LICENSE | 862 ++++-------------- vendor/modules.txt | 2 +- 4 files changed, 205 insertions(+), 665 deletions(-) diff --git a/go.mod b/go.mod index c4200d8da..798b184aa 100644 --- a/go.mod +++ b/go.mod @@ -20,7 +20,7 @@ require ( github.com/golang/protobuf v1.5.4 github.com/google/uuid v1.6.0 github.com/gorilla/websocket v1.5.3 - github.com/grafana/k6-cloud-openapi-client-go v0.0.3-0.20260716094638-49089b6e624d + github.com/grafana/k6-cloud-openapi-client-go v0.0.3-0.20260716125012-97c96146fa7c github.com/grafana/k6provider v0.5.0 github.com/grafana/sobek v0.0.0-20260708062710-267a0e055bb4 github.com/grafana/sobek-webapi-encoding v0.1.0 diff --git a/go.sum b/go.sum index cffb66d6d..f3407b9c7 100644 --- a/go.sum +++ b/go.sum @@ -92,8 +92,8 @@ 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/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/grafana/k6-cloud-openapi-client-go v0.0.3-0.20260716094638-49089b6e624d h1:mGKcOe83IRY73ECb8S3PvhJCLVuev2aNGzZQID/f998= -github.com/grafana/k6-cloud-openapi-client-go v0.0.3-0.20260716094638-49089b6e624d/go.mod h1:RhZGBq6e90zSi0EME83c6S1qkOzD8pP0MNETqieWX0k= +github.com/grafana/k6-cloud-openapi-client-go v0.0.3-0.20260716125012-97c96146fa7c h1:a6t4uyt2GDUWUa3zML524CuKtuqPvGaYE3JfBO5Xww0= +github.com/grafana/k6-cloud-openapi-client-go v0.0.3-0.20260716125012-97c96146fa7c/go.mod h1:RhZGBq6e90zSi0EME83c6S1qkOzD8pP0MNETqieWX0k= github.com/grafana/k6provider v0.5.0 h1:SwItWPOMQHfRytezQBKpeXLxjNmcyD/x9PTA28pEbwg= github.com/grafana/k6provider v0.5.0/go.mod h1:R9WKthnwk96E47m6w/mnC13hhBYTn5iMdP5caFt/t5k= github.com/grafana/sobek v0.0.0-20260708062710-267a0e055bb4 h1:LJ2pEOxFbfUIhrkpROwZ6hLhuCn6e5GSX08v5GFwN/4= diff --git a/vendor/github.com/grafana/k6-cloud-openapi-client-go/LICENSE b/vendor/github.com/grafana/k6-cloud-openapi-client-go/LICENSE index bae94e189..f49a4e16e 100644 --- a/vendor/github.com/grafana/k6-cloud-openapi-client-go/LICENSE +++ b/vendor/github.com/grafana/k6-cloud-openapi-client-go/LICENSE @@ -1,661 +1,201 @@ - GNU AFFERO GENERAL PUBLIC LICENSE - Version 3, 19 November 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU Affero General Public License is a free, copyleft license for -software and other kinds of works, specifically designed to ensure -cooperation with the community in the case of network server software. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -our General Public Licenses are intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - Developers that use our General Public Licenses protect your rights -with two steps: (1) assert copyright on the software, and (2) offer -you this License which gives you legal permission to copy, distribute -and/or modify the software. - - A secondary benefit of defending all users' freedom is that -improvements made in alternate versions of the program, if they -receive widespread use, become available for other developers to -incorporate. Many developers of free software are heartened and -encouraged by the resulting cooperation. However, in the case of -software used on network servers, this result may fail to come about. -The GNU General Public License permits making a modified version and -letting the public access it on a server without ever releasing its -source code to the public. - - The GNU Affero General Public License is designed specifically to -ensure that, in such cases, the modified source code becomes available -to the community. It requires the operator of a network server to -provide the source code of the modified version running there to the -users of that server. Therefore, public use of a modified version, on -a publicly accessible server, gives the public access to the source -code of the modified version. - - An older license, called the Affero General Public License and -published by Affero, was designed to accomplish similar goals. This is -a different license, not a version of the Affero GPL, but Affero has -released a new version of the Affero GPL which permits relicensing under -this license. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU Affero General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Remote Network Interaction; Use with the GNU General Public License. - - Notwithstanding any other provision of this License, if you modify the -Program, your modified version must prominently offer all users -interacting with it remotely through a computer network (if your version -supports such interaction) an opportunity to receive the Corresponding -Source of your version by providing access to the Corresponding Source -from a network server at no charge, through some standard or customary -means of facilitating copying of software. This Corresponding Source -shall include the Corresponding Source for any work covered by version 3 -of the GNU General Public License that is incorporated pursuant to the -following paragraph. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the work with which it is combined will remain governed by version -3 of the GNU General Public License. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU Affero General Public License from time to time. Such new versions -will be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU Affero General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU Affero General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU Affero General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - - If your software can interact with users remotely through a computer -network, you should also make sure that it provides a way for users to -get its source. For example, if your program is a web application, its -interface could display a "Source" link that leads users to an archive -of the code. There are many ways you could offer source, and different -solutions will be better for different programs; see section 13 for the -specific requirements. - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU AGPL, see -. \ No newline at end of file + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. \ No newline at end of file diff --git a/vendor/modules.txt b/vendor/modules.txt index c8b2b0fb0..326f98370 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -179,7 +179,7 @@ github.com/google/uuid # github.com/gorilla/websocket v1.5.3 ## explicit; go 1.12 github.com/gorilla/websocket -# github.com/grafana/k6-cloud-openapi-client-go v0.0.3-0.20260716094638-49089b6e624d +# github.com/grafana/k6-cloud-openapi-client-go v0.0.3-0.20260716125012-97c96146fa7c ## explicit; go 1.23.4 github.com/grafana/k6-cloud-openapi-client-go/k6 # github.com/grafana/k6provider v0.5.0 From bb1eb70292a7506a876c6db324c9a263e03e4f98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20SZKIBA?= Date: Thu, 23 Jul 2026 10:08:02 +0000 Subject: [PATCH 038/182] fix(ci): resolve xk6 fork PR proxy race by adding fork to GOPRIVATE When a pull request comes from a fork, the test-xk6 workflow fails intermittently on Linux/macOS runners due to a race between CI runners and proxy.golang.org populating brand-new pseudo-versions. The issue affects the first run of each fork PR within 1-2 minutes of pushing. The root cause: go.mod resolution for fork commits routes through the public proxy (since GOPRIVATE only covered go.k6.io/k6) causing concurrent jobs to race on proxy population. Linux runners hit the proxy before it finished computing module hashes. Fix: Extend GOPRIVATE to include the fork's GitHub path when XK6_K6_REPO is set. This makes Go fetch the fork module directly from git, bypassing the proxy and checksum database entirely - eliminating the race. Tested: Re-running failed jobs hours after initial push confirms they pass with identical commit (proving code is not the issue). Fresh build reproduces and verifies the fix resolves the proxy population race. Fixes #6202 --- .github/workflows/xk6.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/xk6.yml b/.github/workflows/xk6.yml index 7e8bfd126..2d1491cc0 100644 --- a/.github/workflows/xk6.yml +++ b/.github/workflows/xk6.yml @@ -71,9 +71,11 @@ jobs: echo "COMMIT_ID=$COMMIT_ID" cd .github/workflows/xk6-tests go install go.k6.io/xk6/cmd/xk6@master + GOPRIVATE="go.k6.io/k6" if [ "${{ github.event_name }}" == "pull_request" -a \ "${PR_REPO}" != "${{ github.repository }}" ]; then export XK6_K6_REPO="github.com/${PR_REPO}" + GOPRIVATE="${GOPRIVATE},github.com/${PR_REPO}" fi # The following is a workaround for Windows, cause when using 'shell: bash', the PATH is expressed # with ':' as separator, but Go code, running on a Windows OS, expects ';' as separator. @@ -82,7 +84,7 @@ jobs: XPATH="$HOME/sdk/gotip/bin;$XPATH" fi PATH="$XPATH" \ - GOPRIVATE="go.k6.io/k6" xk6 build "$COMMIT_ID" \ + GOPRIVATE="${GOPRIVATE}" xk6 build "$COMMIT_ID" \ --output ./k6ext \ --with github.com/grafana/xk6-js-test="$(pwd)/xk6-js-test" \ --with github.com/grafana/xk6-output-test="$(pwd)/xk6-output-test" From 49592eeceade3f2a14c06f78114939a1860ea154 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Szkiba?= Date: Thu, 23 Jul 2026 12:26:15 +0200 Subject: [PATCH 039/182] Update .github/workflows/xk6.yml Co-authored-by: Mihail Stoykov <312246+mstoykov@users.noreply.github.com> --- .github/workflows/xk6.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/xk6.yml b/.github/workflows/xk6.yml index 2d1491cc0..6a272081c 100644 --- a/.github/workflows/xk6.yml +++ b/.github/workflows/xk6.yml @@ -75,7 +75,7 @@ jobs: if [ "${{ github.event_name }}" == "pull_request" -a \ "${PR_REPO}" != "${{ github.repository }}" ]; then export XK6_K6_REPO="github.com/${PR_REPO}" - GOPRIVATE="${GOPRIVATE},github.com/${PR_REPO}" + GOPRIVATE="${GOPRIVATE},${XK6_K6_REPO}" fi # The following is a workaround for Windows, cause when using 'shell: bash', the PATH is expressed # with ':' as separator, but Go code, running on a Windows OS, expects ';' as separator. From 8e24bb24836c8cc528cc4596e365c248cc25134b Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Thu, 23 Jul 2026 16:43:04 +0300 Subject: [PATCH 040/182] fix(security/high/examples/grpc_server): update module google.golang.org/grpc to v1.82.1 [security] (#6192) | datasource | package | from | to | | ---------- | ---------------------- | ------- | ------- | | go | google.golang.org/grpc | v1.80.0 | v1.82.1 | Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> --- examples/grpc_server/go.mod | 4 ++-- examples/grpc_server/go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/grpc_server/go.mod b/examples/grpc_server/go.mod index 1d344782d..4436a3915 100644 --- a/examples/grpc_server/go.mod +++ b/examples/grpc_server/go.mod @@ -6,13 +6,13 @@ replace go.k6.io/k6 => ../../ require ( go.k6.io/k6/v2 v2.0.0-rc1 - google.golang.org/grpc v1.80.0 + google.golang.org/grpc v1.82.1 ) require ( golang.org/x/net v0.56.0 // indirect golang.org/x/sys v0.46.0 // indirect golang.org/x/text v0.38.0 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20260401024825-9d38bb4040a9 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20260414002931-afd174a4e478 // indirect google.golang.org/protobuf v1.36.11 // indirect ) diff --git a/examples/grpc_server/go.sum b/examples/grpc_server/go.sum index c190e28b2..0bfa532f2 100644 --- a/examples/grpc_server/go.sum +++ b/examples/grpc_server/go.sum @@ -32,9 +32,9 @@ golang.org/x/text v0.38.0 h1:sXmwo9DwP3OK9EZ7PqAdaooSGozfl/3a6/xJcbzPRhE= golang.org/x/text v0.38.0/go.mod h1:YXZt3QhHUKYT53r2lLKFIVi6Ao1jdzrTR/KQ09qyxF4= gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4= gonum.org/v1/gonum v0.17.0/go.mod h1:El3tOrEuMpv2UdMrbNlKEh9vd86bmQ6vqIcDwxEOc1E= -google.golang.org/genproto/googleapis/rpc v0.0.0-20260401024825-9d38bb4040a9 h1:m8qni9SQFH0tJc1X0vmnpw/0t+AImlSvp30sEupozUg= -google.golang.org/genproto/googleapis/rpc v0.0.0-20260401024825-9d38bb4040a9/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8= -google.golang.org/grpc v1.80.0 h1:Xr6m2WmWZLETvUNvIUmeD5OAagMw3FiKmMlTdViWsHM= -google.golang.org/grpc v1.80.0/go.mod h1:ho/dLnxwi3EDJA4Zghp7k2Ec1+c2jqup0bFkw07bwF4= +google.golang.org/genproto/googleapis/rpc v0.0.0-20260414002931-afd174a4e478 h1:RmoJA1ujG+/lRGNfUnOMfhCy5EipVMyvUE+KNbPbTlw= +google.golang.org/genproto/googleapis/rpc v0.0.0-20260414002931-afd174a4e478/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8= +google.golang.org/grpc v1.82.1 h1:NnAxzGRA0677vCa4BUkOAnO5+FfQqVl9iUXeD0IqcGE= +google.golang.org/grpc v1.82.1/go.mod h1:yzTZ1TB1Z3SG+LIYaI+WiE8D5+PZ3ArnrSp8zF3+/ZA= google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE= google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= From 5cbc005a86c7337d82e865967e7d45039e5f89ce Mon Sep 17 00:00:00 2001 From: Sam Agarwal <44370096+samarth70@users.noreply.github.com> Date: Thu, 23 Jul 2026 10:25:54 -0400 Subject: [PATCH 041/182] Avoid division by zero for counter rate thresholds (#6200) Co-authored-by: Ankur --- metrics/thresholds.go | 6 +++++- metrics/thresholds_test.go | 12 ++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/metrics/thresholds.go b/metrics/thresholds.go index d0aad11a0..b043e6a7e 100644 --- a/metrics/thresholds.go +++ b/metrics/thresholds.go @@ -181,7 +181,11 @@ func (ts *Thresholds) Run(sink Sink, duration time.Duration) (bool, error) { switch sinkImpl := sink.(type) { case *CounterSink: ts.sinked["count"] = sinkImpl.Value - ts.sinked["rate"] = sinkImpl.Value / (float64(duration) / float64(time.Second)) + // Guard against a zero duration, matching CounterSink.Rate, so the rate + // does not become +Inf and make a "rate" threshold spuriously fail. + if duration > 0 { + ts.sinked["rate"] = sinkImpl.Value / (float64(duration) / float64(time.Second)) + } case *GaugeSink: ts.sinked["value"] = sinkImpl.Value case *TrendSink: diff --git a/metrics/thresholds_test.go b/metrics/thresholds_test.go index a499dbc41..f58c8ca03 100644 --- a/metrics/thresholds_test.go +++ b/metrics/thresholds_test.go @@ -686,6 +686,18 @@ func TestThresholdsRun(t *testing.T) { want: true, wantErr: false, }, + { + // A zero duration must not turn the counter's rate into +Inf. CounterSink.Rate + // guards against this, so a "rate" threshold has to behave the same way here. + name: "Running a counter rate threshold with zero duration does not divide by zero", + args: args{ + sink: &CounterSink{Value: 1234.5}, + thresholdExpressions: []string{"rate<100"}, + duration: 0, + }, + want: true, + wantErr: false, + }, { name: "Running threshold on trend sink with no values and passing med statement succeeds", args: args{ From 80fc08374e80fc0e1f44b04a58fa9198e4b250f4 Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Thu, 23 Jul 2026 18:10:06 +0300 Subject: [PATCH 042/182] fix(security/high/): update module google.golang.org/grpc to v1.82.1 [security] (#6191) | datasource | package | from | to | | ---------- | ---------------------- | ------- | ------- | | go | google.golang.org/grpc | v1.81.1 | v1.82.1 | Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 +- .../grpc/balancer/balancer.go | 4 +- .../grpc/balancer/pickfirst/pickfirst.go | 2 +- vendor/google.golang.org/grpc/dialoptions.go | 22 +- .../grpc/encoding/encoding.go | 3 + .../grpc/encoding/gzip/gzip.go | 14 +- .../balancer/weight/weight.go | 36 ++- .../health/grpc_health_v1/health_grpc.pb.go | 2 +- .../grpc/internal/envconfig/envconfig.go | 105 +++++++-- .../grpc/internal/envconfig/xds.go | 10 + .../grpc/internal/grpcutil/encode_duration.go | 1 - .../grpc/internal/resolver/config_selector.go | 24 +- .../grpc/internal/stats/labels.go | 60 +++-- .../grpc/internal/transport/client_stream.go | 36 ++- .../grpc/internal/transport/controlbuf.go | 215 ++++++++---------- .../grpc/internal/transport/flowcontrol.go | 10 +- .../grpc/internal/transport/handler_server.go | 4 +- .../grpc/internal/transport/http2_client.go | 58 ++++- .../grpc/internal/transport/http2_server.go | 29 ++- .../internal/internal.go} | 20 +- .../grpc/internal/transport/transport.go | 5 + .../grpc_reflection_v1/reflection_grpc.pb.go | 2 +- .../reflection_grpc.pb.go | 2 +- vendor/google.golang.org/grpc/rpc_util.go | 42 +++- vendor/google.golang.org/grpc/server.go | 52 +++-- vendor/google.golang.org/grpc/version.go | 2 +- vendor/modules.txt | 5 +- 28 files changed, 498 insertions(+), 273 deletions(-) rename vendor/google.golang.org/grpc/{internal => experimental}/balancer/weight/weight.go (71%) rename vendor/google.golang.org/grpc/internal/{grpcutil/regex.go => transport/internal/internal.go} (59%) diff --git a/go.mod b/go.mod index 798b184aa..e8e0ac47a 100644 --- a/go.mod +++ b/go.mod @@ -63,7 +63,7 @@ require ( golang.org/x/sync v0.22.0 golang.org/x/term v0.45.0 golang.org/x/time v0.15.0 - google.golang.org/grpc v1.81.1 + google.golang.org/grpc v1.82.1 google.golang.org/protobuf v1.36.11 gopkg.in/guregu/null.v3 v3.3.0 gopkg.in/yaml.v3 v3.0.1 diff --git a/go.sum b/go.sum index f3407b9c7..7bb67ee64 100644 --- a/go.sum +++ b/go.sum @@ -388,8 +388,8 @@ google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyac google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= -google.golang.org/grpc v1.81.1 h1:VnnIIZ88UzOOKLukQi+ImGz8O1Wdp8nAGGnvOfEIWQQ= -google.golang.org/grpc v1.81.1/go.mod h1:xGH9GfzOyMTGIOXBJmXt+BX/V0kcdQbdcuwQ/zNw42I= +google.golang.org/grpc v1.82.1 h1:NnAxzGRA0677vCa4BUkOAnO5+FfQqVl9iUXeD0IqcGE= +google.golang.org/grpc v1.82.1/go.mod h1:yzTZ1TB1Z3SG+LIYaI+WiE8D5+PZ3ArnrSp8zF3+/ZA= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= diff --git a/vendor/google.golang.org/grpc/balancer/balancer.go b/vendor/google.golang.org/grpc/balancer/balancer.go index 326888ae3..7e3dbaad2 100644 --- a/vendor/google.golang.org/grpc/balancer/balancer.go +++ b/vendor/google.golang.org/grpc/balancer/balancer.go @@ -60,7 +60,7 @@ func Register(b Builder) { if !envconfig.CaseSensitiveBalancerRegistries { name = strings.ToLower(name) if name != b.Name() { - logger.Warningf("Balancer registered with name %q. grpc-go will be switching to case sensitive balancer registries soon. After 2 releases, we will enable the env var by default.", b.Name()) + logger.Warningf("Balancer registered with name %q. grpc-go has switched to case sensitive balancer registries. GRPC_GO_EXPERIMENTAL_CASE_SENSITIVE_BALANCER_REGISTRIES env variable will be removed in release v1.82.0", b.Name()) } } m[name] = b @@ -85,7 +85,7 @@ func Get(name string) Builder { if !envconfig.CaseSensitiveBalancerRegistries { lowerName := strings.ToLower(name) if lowerName != name { - logger.Warningf("Balancer retrieved for name %q. grpc-go will be switching to case sensitive balancer registries soon. After 2 releases, we will enable the env var by default.", name) + logger.Warningf("Balancer retrieved for name %q. grpc-go has switched to case sensitive balancer registries. GRPC_GO_EXPERIMENTAL_CASE_SENSITIVE_BALANCER_REGISTRIES env variable will be removed in release v1.82.0", name) } name = lowerName } diff --git a/vendor/google.golang.org/grpc/balancer/pickfirst/pickfirst.go b/vendor/google.golang.org/grpc/balancer/pickfirst/pickfirst.go index 518a69d57..d48bc304c 100644 --- a/vendor/google.golang.org/grpc/balancer/pickfirst/pickfirst.go +++ b/vendor/google.golang.org/grpc/balancer/pickfirst/pickfirst.go @@ -35,9 +35,9 @@ import ( "google.golang.org/grpc/balancer" "google.golang.org/grpc/balancer/pickfirst/internal" "google.golang.org/grpc/connectivity" + "google.golang.org/grpc/experimental/balancer/weight" expstats "google.golang.org/grpc/experimental/stats" "google.golang.org/grpc/grpclog" - "google.golang.org/grpc/internal/balancer/weight" "google.golang.org/grpc/internal/envconfig" internalgrpclog "google.golang.org/grpc/internal/grpclog" "google.golang.org/grpc/internal/pretty" diff --git a/vendor/google.golang.org/grpc/dialoptions.go b/vendor/google.golang.org/grpc/dialoptions.go index 4ec5f9cd0..3af08e1ab 100644 --- a/vendor/google.golang.org/grpc/dialoptions.go +++ b/vendor/google.golang.org/grpc/dialoptions.go @@ -173,10 +173,8 @@ func newJoinDialOption(opts ...DialOption) DialOption { // If this option is set to true every connection will release the buffer after // flushing the data on the wire. // -// # Experimental -// -// Notice: This API is EXPERIMENTAL and may be changed or removed in a -// later release. +// Deprecated: shared write buffer is enabled by default. WithSharedWriteBuffer +// will be removed in a future release. func WithSharedWriteBuffer(val bool) DialOption { return newFuncDialOption(func(o *dialOptions) { o.copts.SharedWriteBuffer = val @@ -229,6 +227,14 @@ func WithInitialConnWindowSize(s int32) DialOption { // WithStaticStreamWindowSize returns a DialOption which sets the initial // stream window size to the value provided and disables dynamic flow control. +// +// Note that this also disables dynamic flow control for the connection, +// falling back to a default static connection-level window of 64KB. To +// use a larger connection-level window, you must also use the +// [WithStaticConnWindowSize] DialOption. +// +// Most users should not configure static flow control windows unless +// operating in a memory-constrained environment. func WithStaticStreamWindowSize(s int32) DialOption { return newFuncDialOption(func(o *dialOptions) { o.copts.InitialWindowSize = s @@ -239,6 +245,14 @@ func WithStaticStreamWindowSize(s int32) DialOption { // WithStaticConnWindowSize returns a DialOption which sets the initial // connection window size to the value provided and disables dynamic flow // control. +// +// Note that this also disables dynamic flow control for individual streams, +// falling back to a default static connection-level window of 64KB. To +// explicitly configure the stream-level window size, you must also use the +// [WithStaticStreamWindowSize] DialOption. +// +// Most users should not configure static flow control windows unless +// operating in a memory-constrained environment. func WithStaticConnWindowSize(s int32) DialOption { return newFuncDialOption(func(o *dialOptions) { o.copts.InitialConnWindowSize = s diff --git a/vendor/google.golang.org/grpc/encoding/encoding.go b/vendor/google.golang.org/grpc/encoding/encoding.go index 296f38c3a..bfa8b268f 100644 --- a/vendor/google.golang.org/grpc/encoding/encoding.go +++ b/vendor/google.golang.org/grpc/encoding/encoding.go @@ -66,6 +66,9 @@ type Compressor interface { // Decompress reads data from r, decompresses it, and provides the // uncompressed data via the returned io.Reader. If an error occurs while // initializing the decompressor, that error is returned instead. + // + // The returned io.Reader may optionally implement io.ReadCloser, and if it + // does, gRPC will call Close() exactly once. Decompress(r io.Reader) (io.Reader, error) // Name is the name of the compression codec and is used to set the content // coding header. The result must be static; the result cannot change diff --git a/vendor/google.golang.org/grpc/encoding/gzip/gzip.go b/vendor/google.golang.org/grpc/encoding/gzip/gzip.go index 153e4dbfb..65908d9a2 100644 --- a/vendor/google.golang.org/grpc/encoding/gzip/gzip.go +++ b/vendor/google.golang.org/grpc/encoding/gzip/gzip.go @@ -81,6 +81,8 @@ func (z *writer) Close() error { return z.Writer.Close() } +var _ io.Closer = &reader{} + type reader struct { *gzip.Reader pool *sync.Pool @@ -102,14 +104,16 @@ func (c *compressor) Decompress(r io.Reader) (io.Reader, error) { return z, nil } -func (z *reader) Read(p []byte) (n int, err error) { - n, err = z.Reader.Read(p) - if err == io.EOF { - z.pool.Put(z) - } +func (r *reader) Read(p []byte) (n int, err error) { + n, err = r.Reader.Read(p) return n, err } +func (r *reader) Close() error { + defer r.pool.Put(r) + return r.Reader.Close() +} + func (c *compressor) Name() string { return Name } diff --git a/vendor/google.golang.org/grpc/internal/balancer/weight/weight.go b/vendor/google.golang.org/grpc/experimental/balancer/weight/weight.go similarity index 71% rename from vendor/google.golang.org/grpc/internal/balancer/weight/weight.go rename to vendor/google.golang.org/grpc/experimental/balancer/weight/weight.go index 11beb07d1..beab9e07c 100644 --- a/vendor/google.golang.org/grpc/internal/balancer/weight/weight.go +++ b/vendor/google.golang.org/grpc/experimental/balancer/weight/weight.go @@ -16,23 +16,23 @@ * */ -// Package weight contains utilities to manage endpoint weights. Weights are -// used by LB policies such as ringhash to distribute load across multiple -// endpoints. +// Package weight contains utilities to manage endpoint weights. +// Weights may be used by LB policies to distribute load across +// multiple endpoints. +// +// # Experimental +// +// Notice: All APIs in this package are EXPERIMENTAL and may be changed +// or removed in a later release. package weight -import ( - "fmt" - - "google.golang.org/grpc/resolver" -) +import "google.golang.org/grpc/resolver" // attributeKey is the type used as the key to store EndpointInfo in the // Attributes field of resolver.Endpoint. type attributeKey struct{} -// EndpointInfo will be stored in the Attributes field of Endpoints in order to -// use the ringhash balancer. +// EndpointInfo will be stored in the Attributes field of Endpoints. type EndpointInfo struct { Weight uint32 } @@ -43,22 +43,16 @@ func (a EndpointInfo) Equal(o any) bool { return ok && oa.Weight == a.Weight } -// Set returns a copy of endpoint in which the Attributes field is updated with -// EndpointInfo. +// Set returns a copy of endpoint in which the Attributes field is +// updated with EndpointInfo. func Set(endpoint resolver.Endpoint, epInfo EndpointInfo) resolver.Endpoint { endpoint.Attributes = endpoint.Attributes.WithValue(attributeKey{}, epInfo) return endpoint } -// String returns a human-readable representation of EndpointInfo. -// This method is intended for logging, testing, and debugging purposes only. -// Do not rely on the output format, as it is not guaranteed to remain stable. -func (a EndpointInfo) String() string { - return fmt.Sprintf("Weight: %d", a.Weight) -} - -// FromEndpoint returns the EndpointInfo stored in the Attributes field of an -// endpoint. It returns an empty EndpointInfo if attribute is not found. +// FromEndpoint returns the EndpointInfo stored in the Attributes +// field of an endpoint. It returns an empty EndpointInfo if attribute +// is not found. func FromEndpoint(endpoint resolver.Endpoint) EndpointInfo { v := endpoint.Attributes.Value(attributeKey{}) ei, _ := v.(EndpointInfo) diff --git a/vendor/google.golang.org/grpc/health/grpc_health_v1/health_grpc.pb.go b/vendor/google.golang.org/grpc/health/grpc_health_v1/health_grpc.pb.go index 9e10fdd2e..537ba0571 100644 --- a/vendor/google.golang.org/grpc/health/grpc_health_v1/health_grpc.pb.go +++ b/vendor/google.golang.org/grpc/health/grpc_health_v1/health_grpc.pb.go @@ -17,7 +17,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: -// - protoc-gen-go-grpc v1.6.1 +// - protoc-gen-go-grpc v1.6.2 // - protoc v5.27.1 // source: grpc/health/v1/health.proto diff --git a/vendor/google.golang.org/grpc/internal/envconfig/envconfig.go b/vendor/google.golang.org/grpc/internal/envconfig/envconfig.go index 8ca87a57a..29d332e7b 100644 --- a/vendor/google.golang.org/grpc/internal/envconfig/envconfig.go +++ b/vendor/google.golang.org/grpc/internal/envconfig/envconfig.go @@ -59,6 +59,15 @@ var ( // unconditionally. XDSEndpointHashKeyBackwardCompat = boolFromEnv("GRPC_XDS_ENDPOINT_HASH_KEY_BACKWARD_COMPAT", false) + // LabelServerGoroutines controls setting [runtime/pprof.Labels] on the + // goroutines spawned by [grpc.Server] type. + // For now, this is limited to the goroutines spawned to handle incoming + // requests on the server. + // Set "GRPC_GO_SERVER_GOROUTINE_LABELS" to "grpc.method=true" to + // enable this grpc.method label, or "all" to enable all valid labels. + // This variable is a bit-field. + LabelServerGoroutines = goroutineLabelsFromEnv("GRPC_GO_SERVER_GOROUTINE_LABELS", 0) + // RingHashSetRequestHashKey is set if the ring hash balancer can get the // request hash header by setting the "requestHashHeader" field, according // to gRFC A76. It can be disabled by setting the environment variable @@ -78,12 +87,12 @@ var ( EnableDefaultPortForProxyTarget = boolFromEnv("GRPC_EXPERIMENTAL_ENABLE_DEFAULT_PORT_FOR_PROXY_TARGET", true) // CaseSensitiveBalancerRegistries is set if the balancer registry should be - // case-sensitive. This is disabled by default, but can be enabled by setting + // case-sensitive. This is enabled by default, but can be disabled by setting // the env variable "GRPC_GO_EXPERIMENTAL_CASE_SENSITIVE_BALANCER_REGISTRIES" - // to "true". + // to "false". // - // TODO: After 2 releases, we will enable the env var by default. - CaseSensitiveBalancerRegistries = boolFromEnv("GRPC_GO_EXPERIMENTAL_CASE_SENSITIVE_BALANCER_REGISTRIES", false) + // This env varible will be removed in release v1.82.0. + CaseSensitiveBalancerRegistries = boolFromEnv("GRPC_GO_EXPERIMENTAL_CASE_SENSITIVE_BALANCER_REGISTRIES", true) // XDSAuthorityRewrite indicates whether xDS authority rewriting is enabled. // This feature is defined in gRFC A81 and is enabled by setting the @@ -104,22 +113,6 @@ var ( // to "false". XDSRecoverPanicInResourceParsing = boolFromEnv("GRPC_GO_EXPERIMENTAL_XDS_RESOURCE_PANIC_RECOVERY", true) - // DisableStrictPathChecking indicates whether strict path checking is - // disabled. This feature can be disabled by setting the environment - // variable GRPC_GO_EXPERIMENTAL_DISABLE_STRICT_PATH_CHECKING to "true". - // - // When strict path checking is enabled, gRPC will reject requests with - // paths that do not conform to the gRPC over HTTP/2 specification found at - // https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md. - // - // When disabled, gRPC will allow paths that do not contain a leading slash. - // Enabling strict path checking is recommended for security reasons, as it - // prevents potential path traversal vulnerabilities. - // - // A future release will remove this environment variable, enabling strict - // path checking behavior unconditionally. - DisableStrictPathChecking = boolFromEnv("GRPC_GO_EXPERIMENTAL_DISABLE_STRICT_PATH_CHECKING", false) - // EnablePriorityLBChildPolicyCache controls whether the priority balancer // should cache child balancers that are removed from the LB policy config, // for a period of 15 minutes. This is disabled by default, but can be @@ -127,6 +120,18 @@ var ( // GRPC_EXPERIMENTAL_ENABLE_PRIORITY_LB_CHILD_POLICY_CACHE to true. EnablePriorityLBChildPolicyCache = boolFromEnv("GRPC_EXPERIMENTAL_ENABLE_PRIORITY_LB_CHILD_POLICY_CACHE", false) + // Enable8KBDefaultHeaderListSize indicates that default maximum header list + // size is restricted to 8KB. This is disabled by default, but can be enabled + // by setting the environment variable + // "GRPC_GO_EXPERIMENTAL_ENABLE_8KB_DEFAULT_HEADER_LIST_SIZE" to "true". + // When disabled, the default maximum header list size of 16MB is used. + // + // When enabled, RPCs with a total size of headers exceeding 8KB will fail + // unless explicitly configured otherwise by the user. + // + // TODO: In release v1.82.0, env var will be enabled by default. + Enable8KBDefaultHeaderListSize = boolFromEnv("GRPC_GO_EXPERIMENTAL_ENABLE_8KB_DEFAULT_HEADER_LIST_SIZE", false) + // EnableHTTPFramerReadBufferPooling enables the use of the // readyreader.Reader interface to perform non-memory-pinning reads, // provided the underlying net.Conn supports it. This reduces memory usage @@ -136,6 +141,17 @@ var ( // feature if unforeseen issues arise, and it will be removed in a future // release. EnableHTTPFramerReadBufferPooling = boolFromEnv("GRPC_GO_EXPERIMENTAL_HTTP_FRAMER_READ_BUFFER_POOLING", true) + + // ControlBufferThrottleLimit is the maximum number of control frames that can + // be queued in the control buffer before throttling is applied. The value + // must be between 1 and 10,000, and is set to 100 by default. + // + // This environment variable serves as an escape hatch to increase the + // throttling limit if unforeseen issues arise, and it will be removed in a + // future release. + // + // TODO: Remove this env var once v1.83.0 is release. + ControlBufferThrottleLimit = uint64FromEnv("GRPC_GO_EXPERIMENTAL_CONTROL_BUFFER_THROTTLE_LIMIT", 100, 1, 10000) ) func boolFromEnv(envVar string, def bool) bool { @@ -160,3 +176,52 @@ func uint64FromEnv(envVar string, def, min, max uint64) uint64 { } return v } + +// GoroutineLabels is a bitfield indicating which goroutine labels are enabled. +type GoroutineLabels uint16 + +func goroutineLabelsFromEnv(envVar string, def GoroutineLabels) GoroutineLabels { + val := def + v := os.Getenv(envVar) + if strings.EqualFold(v, "all") { + return AllGoroutineLabels + } else if strings.EqualFold(v, "none") { + return 0 + } + for s := range strings.SplitSeq(v, ",") { + s = strings.TrimSpace(s) + if len(s) == 0 { + continue + } + pre, post, ok := strings.Cut(s, "=") + if !ok { + // no equals sign + continue + } + post = strings.TrimSpace(post) + pre = strings.TrimSpace(pre) + bitDesignator := GoroutineLabels(0) + switch { + case strings.EqualFold(pre, "grpc.method"): + bitDesignator = GoroutineLabelServerMethod + default: + continue + } + if strings.EqualFold(post, "true") { + val |= bitDesignator + } else if strings.EqualFold(post, "false") { + val &^= bitDesignator + } + } + return val +} + +const ( + // GoroutineLabelServerMethod sets the grpc.method label on new + // server-side gRPC streams. + GoroutineLabelServerMethod GoroutineLabels = 1 << iota +) + +// AllGoroutineLabels is an or'd together bitfield of all valid GoroutineLabels +// constant values (above). +const AllGoroutineLabels = GoroutineLabelServerMethod diff --git a/vendor/google.golang.org/grpc/internal/envconfig/xds.go b/vendor/google.golang.org/grpc/internal/envconfig/xds.go index 333d8a0b0..a2312f8ea 100644 --- a/vendor/google.golang.org/grpc/internal/envconfig/xds.go +++ b/vendor/google.golang.org/grpc/internal/envconfig/xds.go @@ -89,4 +89,14 @@ var ( // filtered and prefix-propagated to the LRS server. For more details, see: // https://github.com/grpc/proposal/blob/master/A85-lrs-custom-metrics-changes.md XDSORCAToLRSPropEnabled = boolFromEnv("GRPC_EXPERIMENTAL_XDS_ORCA_LRS_PROPAGATION", false) + + // XDSClientExtProcEnabled indicates whether ExtProc filter is enabled on + // the client side. For more details, see: + // https://github.com/grpc/proposal/blob/master/A93-xds-ext-proc.md + XDSClientExtProcEnabled = boolFromEnv("GRPC_EXPERIMENTAL_XDS_EXT_PROC_ON_CLIENT", false) + + // GCPAuthenticationFilterEnabled enables the xDS GCP Authentication + // filter. For more details, see: + // https://github.com/grpc/proposal/blob/master/A83-xds-gcp-authn-filter.md + GCPAuthenticationFilterEnabled = boolFromEnv("GRPC_EXPERIMENTAL_XDS_GCP_AUTHENTICATION_FILTER", false) ) diff --git a/vendor/google.golang.org/grpc/internal/grpcutil/encode_duration.go b/vendor/google.golang.org/grpc/internal/grpcutil/encode_duration.go index b25b0baec..1cc43fc6b 100644 --- a/vendor/google.golang.org/grpc/internal/grpcutil/encode_duration.go +++ b/vendor/google.golang.org/grpc/internal/grpcutil/encode_duration.go @@ -39,7 +39,6 @@ func div(d, r time.Duration) int64 { // // https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#requests func EncodeDuration(t time.Duration) string { - // TODO: This is simplistic and not bandwidth efficient. Improve it. if t <= 0 { return "0n" } diff --git a/vendor/google.golang.org/grpc/internal/resolver/config_selector.go b/vendor/google.golang.org/grpc/internal/resolver/config_selector.go index 3db62ccad..6320e9b57 100644 --- a/vendor/google.golang.org/grpc/internal/resolver/config_selector.go +++ b/vendor/google.golang.org/grpc/internal/resolver/config_selector.go @@ -106,14 +106,24 @@ type ClientStream interface { // ClientInterceptor is an interceptor for gRPC client streams. type ClientInterceptor interface { - // NewStream produces a ClientStream for an RPC which may optionally use - // the provided function to produce a stream for delegation. Note: - // RPCInfo.Context should not be used (will be nil). + // NewStream creates a ClientStream for an RPC. // - // done is invoked when the RPC is finished using its connection, or could - // not be assigned a connection. RPC operations may still occur on - // ClientStream after done is called, since the interceptor is invoked by - // application-layer operations. done must never be nil when called. + // Implementations must delegate stream creation to the provided newStream + // function. To intercept or override stream behavior, implementations + // may wrap the ClientStream returned by the delegate. + // + // Note: RPCInfo.Context is currently unused and will be nil. + // + // The done function is invoked when the RPC has finished using its + // underlying connection or if a connection could not be assigned. Because + // interceptors operate at the application layer, RPC operations may + // continue on the ClientStream even after done has been called. The + // caller must ensure done is non-nil. + // + // To ensure RPC completion notifications propagate through the entire + // interceptor chain, implementations must ensure that the done function + // passed to the delegate newStream invokes the done function passed to + // NewStream. NewStream(ctx context.Context, ri RPCInfo, done func(), newStream func(ctx context.Context, done func()) (ClientStream, error)) (ClientStream, error) // Close closes the interceptor. Once called, no new calls to NewStream are // accepted. Ongoing calls to NewStream are allowed to complete. diff --git a/vendor/google.golang.org/grpc/internal/stats/labels.go b/vendor/google.golang.org/grpc/internal/stats/labels.go index fd33af51a..5ea898cb5 100644 --- a/vendor/google.golang.org/grpc/internal/stats/labels.go +++ b/vendor/google.golang.org/grpc/internal/stats/labels.go @@ -19,24 +19,56 @@ // Package stats provides internal stats related functionality. package stats -import "context" +import ( + "context" + "maps" +) -// Labels are the labels for metrics. -type Labels struct { - // TelemetryLabels are the telemetry labels to record. - TelemetryLabels map[string]string +// LabelCallback is a function that is executed when telemetry +// label keys are updated. +type LabelCallback func(map[string]string) +type telemetryLabelCallbackKey struct{} + +// UpdateLabels executes registered telemetry callbacks with the update labels. Labels +// are copied before being processed by any callbacks to ensure mutations are not +// shared among derived contexts. +// +// It is the responsibility of the registrant to handle conflicts or label resets. +func UpdateLabels(ctx context.Context, update map[string]string) { + executeTelemetryLabelCallbacks(ctx, update) } -type labelsKey struct{} +// RegisterTelemetryLabelCallback registers a callback function that is executed whenever +// telemetry labels are updated. +func RegisterTelemetryLabelCallback(ctx context.Context, callback LabelCallback) context.Context { + if callback == nil { + return ctx + } + + callbacks, ok := ctx.Value(telemetryLabelCallbackKey{}).([]LabelCallback) + if !ok { + return context.WithValue(ctx, telemetryLabelCallbackKey{}, []LabelCallback{callback}) + } + return context.WithValue(ctx, telemetryLabelCallbackKey{}, append(append([]LabelCallback(nil), callbacks...), callback)) -// GetLabels returns the Labels stored in the context, or nil if there is one. -func GetLabels(ctx context.Context) *Labels { - labels, _ := ctx.Value(labelsKey{}).(*Labels) - return labels } -// SetLabels sets the Labels in the context. -func SetLabels(ctx context.Context, labels *Labels) context.Context { - // could also append - return context.WithValue(ctx, labelsKey{}, labels) +// executeTelemetryLabelCallback runs the registered callbacks in the order they were +// registered on the context with the provided labels. If no callbacks are registered +// it does nothing. +// +// To ensure callbacks do not mutate the state of the provided label map it is copied +// before execution. +func executeTelemetryLabelCallbacks(ctx context.Context, labels map[string]string) { + callbacks, ok := ctx.Value(telemetryLabelCallbackKey{}).([]LabelCallback) + if !ok { + return + } + + labelsCopy := map[string]string{} + maps.Copy(labelsCopy, labels) + for _, callback := range callbacks { + callback(labelsCopy) + } + } diff --git a/vendor/google.golang.org/grpc/internal/transport/client_stream.go b/vendor/google.golang.org/grpc/internal/transport/client_stream.go index cd8152ef1..ad382b0fd 100644 --- a/vendor/google.golang.org/grpc/internal/transport/client_stream.go +++ b/vendor/google.golang.org/grpc/internal/transport/client_stream.go @@ -19,6 +19,7 @@ package transport import ( + "fmt" "sync/atomic" "golang.org/x/net/http2" @@ -28,6 +29,12 @@ import ( "google.golang.org/grpc/status" ) +// nonGRPCDataMaxLen is the maximum length of nonGRPCDataBuf. +// +// NOTE: If changed this value, you MUST update the corresponding test in: +// - /test/end2end_test.go:TestHTTPServerSendsNonGRPCHeaderSurfaceFurtherData +const nonGRPCDataMaxLen = 1024 + // ClientStream implements streaming functionality for a gRPC client. type ClientStream struct { Stream // Embed for common stream functionality. @@ -46,7 +53,11 @@ type ClientStream struct { // headerValid indicates whether a valid header was received. Only // meaningful after headerChan is closed (always call waitOnHeader() before // reading its value). - headerValid bool + headerValid bool + + nonGRPCStatus *status.Status // the initial status from the non-gRPC response header, finalized with collected data before closing. + nonGRPCDataBuf []byte // stores the data of a non-gRPC response. + noHeaders bool // set if the client never received headers (set only after the stream is done). headerChanClosed uint32 // set when headerChan is closed. Used to avoid closing headerChan multiple times. bytesReceived atomic.Bool // indicates whether any bytes have been received on this stream @@ -54,6 +65,29 @@ type ClientStream struct { statsHandler stats.Handler // nil for internal streams (e.g., health check, ORCA) where telemetry is not supported. } +func (s *ClientStream) startNonGRPCDataCollection(st *status.Status) { + s.nonGRPCStatus = st + s.nonGRPCDataBuf = make([]byte, 0, nonGRPCDataMaxLen) +} + +// finalizeNonGRPCStatus builds the terminal status by appending the collected +// response body to the original non-gRPC status message. +func (s *ClientStream) finalizeNonGRPCStatus() *status.Status { + msg := fmt.Sprintf("%s\ndata: %q", s.nonGRPCStatus.Message(), s.nonGRPCDataBuf) + return status.New(s.nonGRPCStatus.Code(), msg) +} + +// handleNonGRPCData collects non-gRPC body from the given data frame. +// It returns non-nil value when the stream should be closed with it. +func (s *ClientStream) handleNonGRPCData(f *parsedDataFrame) *status.Status { + n := min(f.data.Len(), nonGRPCDataMaxLen-len(s.nonGRPCDataBuf)) + s.nonGRPCDataBuf = append(s.nonGRPCDataBuf, f.data.ReadOnlyData()[0:n]...) + if len(s.nonGRPCDataBuf) >= nonGRPCDataMaxLen || f.StreamEnded() { + return s.finalizeNonGRPCStatus() + } + return nil +} + // Read reads an n byte message from the input stream. func (s *ClientStream) Read(n int) (mem.BufferSlice, error) { b, err := s.Stream.read(n) diff --git a/vendor/google.golang.org/grpc/internal/transport/controlbuf.go b/vendor/google.golang.org/grpc/internal/transport/controlbuf.go index 7efa52478..b9bae0249 100644 --- a/vendor/google.golang.org/grpc/internal/transport/controlbuf.go +++ b/vendor/google.golang.org/grpc/internal/transport/controlbuf.go @@ -29,6 +29,7 @@ import ( "golang.org/x/net/http2" "golang.org/x/net/http2/hpack" + "google.golang.org/grpc/internal/envconfig" "google.golang.org/grpc/internal/grpclog" "google.golang.org/grpc/mem" ) @@ -96,61 +97,70 @@ func (il *itemList) isEmpty() bool { return il.head == nil } -// The following defines various control items which could flow through -// the control buffer of transport. They represent different aspects of -// control tasks, e.g., flow control, settings, streaming resetting, etc. - -// maxQueuedTransportResponseFrames is the most queued "transport response" -// frames we will buffer before preventing new reads from occurring on the -// transport. These are control frames sent in response to client requests, -// such as RST_STREAM due to bad headers or settings acks. -const maxQueuedTransportResponseFrames = 50 +// maxQueuedControlBufferItems is the maximum number of frames (other than +// HEADERS and DATA) that we will buffer before preventing new reads from +// occurring on the transport. These are control frames sent in response to +// client requests, or frames that result in work being scheduled, such as +// RST_STREAM due to bad headers or settings acks. +var maxQueuedControlBufferItems = int(envconfig.ControlBufferThrottleLimit) type cbItem interface { - isTransportResponseFrame() bool + isThrottled() bool } +// throttledItem represents every item in the controlBuffer to which the overall +// throttling limit applies, other than outgoing HEADERS and DATA frames. +type throttledItem struct{} + +func (throttledItem) isThrottled() bool { return true } + +// The following defines various control items which could flow through +// the control buffer of transport. They represent different aspects of +// control tasks, e.g., flow control, settings, streaming resetting, etc. + // registerStream is used to register an incoming stream with loopy writer. type registerStream struct { + throttledItem streamID uint32 wq *writeQuota } -func (*registerStream) isTransportResponseFrame() bool { return false } - -// headerFrame is also used to register stream on the client-side. -type headerFrame struct { +type clientHeaders struct { streamID uint32 hf []hpack.HeaderField - endStream bool // Valid on server side. - initStream func(uint32) error // Used only on the client side. + initStream func(uint32) error onWrite func() - wq *writeQuota // write quota for the stream created. - cleanup *cleanupStream // Valid on the server side. - onOrphaned func(error) // Valid on client-side + wq *writeQuota + onOrphaned func(error) } -func (h *headerFrame) isTransportResponseFrame() bool { - return h.cleanup != nil && h.cleanup.rst // Results in a RST_STREAM +func (*clientHeaders) isThrottled() bool { return false } + +type serverHeaders struct { + streamID uint32 + hf []hpack.HeaderField + endStream bool + onWrite func() + cleanup *cleanupStream } +func (h *serverHeaders) isThrottled() bool { return false } + type cleanupStream struct { + throttledItem streamID uint32 rst bool rstCode http2.ErrCode onWrite func() } -func (c *cleanupStream) isTransportResponseFrame() bool { return c.rst } // Results in a RST_STREAM - type earlyAbortStream struct { + throttledItem streamID uint32 rst bool hf []hpack.HeaderField // Pre-built header fields } -func (*earlyAbortStream) isTransportResponseFrame() bool { return false } - type dataFrame struct { streamID uint32 endStream bool @@ -162,70 +172,60 @@ type dataFrame struct { onEachWrite func() } -func (*dataFrame) isTransportResponseFrame() bool { return false } +func (*dataFrame) isThrottled() bool { return false } type incomingWindowUpdate struct { + throttledItem streamID uint32 increment uint32 } -func (*incomingWindowUpdate) isTransportResponseFrame() bool { return false } - type outgoingWindowUpdate struct { + throttledItem streamID uint32 increment uint32 } -func (*outgoingWindowUpdate) isTransportResponseFrame() bool { - return false // window updates are throttled by thresholds -} - type incomingSettings struct { + throttledItem ss []http2.Setting } -func (*incomingSettings) isTransportResponseFrame() bool { return true } // Results in a settings ACK - type outgoingSettings struct { + throttledItem ss []http2.Setting } -func (*outgoingSettings) isTransportResponseFrame() bool { return false } - type incomingGoAway struct { + throttledItem } -func (*incomingGoAway) isTransportResponseFrame() bool { return false } - type goAway struct { + throttledItem code http2.ErrCode debugData []byte headsUp bool closeConn error // if set, loopyWriter will exit with this error } -func (*goAway) isTransportResponseFrame() bool { return false } - type ping struct { + throttledItem ack bool data [8]byte } -func (*ping) isTransportResponseFrame() bool { return true } - type outFlowControlSizeRequest struct { + throttledItem resp chan uint32 } -func (*outFlowControlSizeRequest) isTransportResponseFrame() bool { return false } - // closeConnection is an instruction to tell the loopy writer to flush the // framer and exit, which will cause the transport's connection to be closed // (by the client or server). The transport itself will close after the reader // encounters the EOF caused by the connection closure. -type closeConnection struct{} - -func (closeConnection) isTransportResponseFrame() bool { return false } +type closeConnection struct { + throttledItem +} type outStreamState int @@ -379,9 +379,9 @@ func (c *controlBuffer) executeAndPut(f func() bool, it cbItem) (bool, error) { c.consumerWaiting = false } c.list.enqueue(it) - if it.isTransportResponseFrame() { + if it.isThrottled() { c.transportResponseFrames++ - if c.transportResponseFrames == maxQueuedTransportResponseFrames { + if c.transportResponseFrames == maxQueuedControlBufferItems { // We are adding the frame that puts us over the threshold; create // a throttling channel. ch := make(chan struct{}) @@ -436,8 +436,8 @@ func (c *controlBuffer) getOnceLocked() (any, error) { return nil, nil } h := c.list.dequeue().(cbItem) - if h.isTransportResponseFrame() { - if c.transportResponseFrames == maxQueuedTransportResponseFrames { + if h.isThrottled() { + if c.transportResponseFrames == maxQueuedControlBufferItems { // We are removing the frame that put us over the // threshold; close and clear the throttling channel. ch := c.trfChan.Swap(nil) @@ -464,10 +464,8 @@ func (c *controlBuffer) finish() { // is still not aware of these yet. for head := c.list.dequeueAll(); head != nil; head = head.next { switch v := head.it.(type) { - case *headerFrame: - if v.onOrphaned != nil { // It will be nil on the server-side. - v.onOrphaned(ErrConnClosing) - } + case *clientHeaders: + v.onOrphaned(ErrConnClosing) case *dataFrame: if !v.processing { v.data.Free() @@ -680,42 +678,38 @@ func (l *loopyWriter) registerStreamHandler(h *registerStream) { l.estdStreams[h.streamID] = str } -func (l *loopyWriter) headerHandler(h *headerFrame) error { - if l.side == serverSide { - str, ok := l.estdStreams[h.streamID] - if !ok { - if l.logger.V(logLevel) { - l.logger.Infof("Unrecognized streamID %d in loopyWriter", h.streamID) - } - return nil - } - // Case 1.A: Server is responding back with headers. - if !h.endStream { - return l.writeHeader(h.streamID, h.endStream, h.hf, h.onWrite) +func (l *loopyWriter) serverHeaderHandler(hdr *serverHeaders) error { + str, ok := l.estdStreams[hdr.streamID] + if !ok { + if l.logger.V(logLevel) { + l.logger.Infof("Unrecognized streamID %d in loopyWriter", hdr.streamID) } - // else: Case 1.B: Server wants to close stream. + return nil + } - if str.state != empty { // either active or waiting on stream quota. - // add it str's list of items. - str.itl.enqueue(h) - return nil - } - if err := l.writeHeader(h.streamID, h.endStream, h.hf, h.onWrite); err != nil { - return err - } - return l.cleanupStreamHandler(h.cleanup) + // Case 1: Server is responding back with headers. + if !hdr.endStream { + return l.writeHeader(hdr.streamID, hdr.endStream, hdr.hf, hdr.onWrite) + } + + // Case 2: Server is closing the stream. + if str.state != empty { // either active or waiting on stream quota. + str.itl.enqueue(hdr) + return nil + } + if err := l.writeHeader(hdr.streamID, hdr.endStream, hdr.hf, hdr.onWrite); err != nil { + return err } - // Case 2: Client wants to originate stream. + return l.cleanupStreamHandler(hdr.cleanup) +} + +func (l *loopyWriter) clientHeaderHandler(hdr *clientHeaders) error { str := &outStream{ - id: h.streamID, + id: hdr.streamID, state: empty, itl: &itemList{}, - wq: h.wq, + wq: hdr.wq, } - return l.originateStream(str, h) -} - -func (l *loopyWriter) originateStream(str *outStream, hdr *headerFrame) error { // l.draining is set when handling GoAway. In which case, we want to avoid // creating new streams. if l.draining { @@ -726,7 +720,7 @@ func (l *loopyWriter) originateStream(str *outStream, hdr *headerFrame) error { if err := hdr.initStream(str.id); err != nil { return err } - if err := l.writeHeader(str.id, hdr.endStream, hdr.hf, hdr.onWrite); err != nil { + if err := l.writeHeader(str.id, false, hdr.hf, hdr.onWrite); err != nil { return err } l.estdStreams[str.id] = str @@ -882,8 +876,10 @@ func (l *loopyWriter) handle(i any) error { return l.incomingSettingsHandler(i) case *outgoingSettings: return l.outgoingSettingsHandler(i) - case *headerFrame: - return l.headerHandler(i) + case *clientHeaders: + return l.clientHeaderHandler(i) + case *serverHeaders: + return l.serverHeaderHandler(i) case *registerStream: l.registerStreamHandler(i) case *cleanupStream: @@ -956,39 +952,16 @@ func (l *loopyWriter) processData() (bool, error) { // from data is copied to h to make as big as the maximum possible HTTP2 frame // size. - if len(dataItem.h) == 0 && reader.Remaining() == 0 { // Empty data frame - // Client sends out empty data frame with endStream = true - if err := l.framer.writeData(dataItem.streamID, dataItem.endStream, nil); err != nil { - return false, err - } - str.itl.dequeue() // remove the empty data item from stream - reader.Close() - if str.itl.isEmpty() { - str.state = empty - } else if trailer, ok := str.itl.peek().(*headerFrame); ok { // the next item is trailers. - if err := l.writeHeader(trailer.streamID, trailer.endStream, trailer.hf, trailer.onWrite); err != nil { - return false, err - } - if err := l.cleanupStreamHandler(trailer.cleanup); err != nil { - return false, err - } - } else { - l.activeStreams.enqueue(str) - } - return false, nil - } - + isEmpty := len(dataItem.h) == 0 && reader.Remaining() == 0 // Figure out the maximum size we can send maxSize := http2MaxFrameLen - if strQuota := int(l.oiws) - str.bytesOutStanding; strQuota <= 0 { // stream-level flow control. + strQuota := int(l.oiws) - str.bytesOutStanding + if strQuota <= 0 && !isEmpty { // stream-level flow control. str.state = waitingOnStreamQuota return false, nil - } else if maxSize > strQuota { - maxSize = strQuota - } - if maxSize > int(l.sendQuota) { // connection-level flow control. - maxSize = int(l.sendQuota) } + maxSize = min(maxSize, max(strQuota, 0)) + maxSize = min(maxSize, int(l.sendQuota)) // connection-level flow control. // Compute how much of the header and data we can send within quota and max frame length hSize := min(maxSize, len(dataItem.h)) dSize := min(maxSize-hSize, reader.Remaining()) @@ -1039,19 +1012,23 @@ func (l *loopyWriter) processData() (bool, error) { reader.Close() str.itl.dequeue() } + return false, l.updateStreamAfterWrite(str) +} + +func (l *loopyWriter) updateStreamAfterWrite(str *outStream) error { if str.itl.isEmpty() { str.state = empty - } else if trailer, ok := str.itl.peek().(*headerFrame); ok { // The next item is trailers. + } else if trailer, ok := str.itl.peek().(*serverHeaders); ok { // the next item is trailers. if err := l.writeHeader(trailer.streamID, trailer.endStream, trailer.hf, trailer.onWrite); err != nil { - return false, err + return err } if err := l.cleanupStreamHandler(trailer.cleanup); err != nil { - return false, err + return err } } else if int(l.oiws)-str.bytesOutStanding <= 0 { // Ran out of stream quota. str.state = waitingOnStreamQuota } else { // Otherwise add it back to the list of active streams. l.activeStreams.enqueue(str) } - return false, nil + return nil } diff --git a/vendor/google.golang.org/grpc/internal/transport/flowcontrol.go b/vendor/google.golang.org/grpc/internal/transport/flowcontrol.go index 7cfbc9637..98cef9ec2 100644 --- a/vendor/google.golang.org/grpc/internal/transport/flowcontrol.go +++ b/vendor/google.golang.org/grpc/internal/transport/flowcontrol.go @@ -115,7 +115,6 @@ func (f *trInFlow) getSize() uint32 { return atomic.LoadUint32(&f.effectiveWindowSize) } -// TODO(mmukhi): Simplify this code. // inFlow deals with inbound flow control type inFlow struct { mu sync.Mutex @@ -174,14 +173,14 @@ func (f *inFlow) maybeAdjust(n uint32) uint32 { // onData is invoked when some data frame is received. It updates pendingData. func (f *inFlow) onData(n uint32) error { f.mu.Lock() + defer f.mu.Unlock() + f.pendingData += n if f.pendingData+f.pendingUpdate > f.limit+f.delta { limit := f.limit rcvd := f.pendingData + f.pendingUpdate - f.mu.Unlock() return fmt.Errorf("received %d-bytes data exceeding the limit %d bytes", rcvd, limit) } - f.mu.Unlock() return nil } @@ -189,8 +188,9 @@ func (f *inFlow) onData(n uint32) error { // to be sent to the peer. func (f *inFlow) onRead(n uint32) uint32 { f.mu.Lock() + defer f.mu.Unlock() + if f.pendingData == 0 { - f.mu.Unlock() return 0 } f.pendingData -= n @@ -205,9 +205,7 @@ func (f *inFlow) onRead(n uint32) uint32 { if f.pendingUpdate >= f.limit/4 { wu := f.pendingUpdate f.pendingUpdate = 0 - f.mu.Unlock() return wu } - f.mu.Unlock() return 0 } diff --git a/vendor/google.golang.org/grpc/internal/transport/handler_server.go b/vendor/google.golang.org/grpc/internal/transport/handler_server.go index 7ab3422b8..a8356c9ad 100644 --- a/vendor/google.golang.org/grpc/internal/transport/handler_server.go +++ b/vendor/google.golang.org/grpc/internal/transport/handler_server.go @@ -479,8 +479,8 @@ func (ht *serverHandlerTransport) runStream() { func (ht *serverHandlerTransport) incrMsgRecv() {} -func (ht *serverHandlerTransport) Drain(string) { - panic("Drain() is not implemented") +func (ht *serverHandlerTransport) Drain(s string) { + ht.Close(errors.New(s)) } // mapRecvMsgError returns the non-nil err into the appropriate diff --git a/vendor/google.golang.org/grpc/internal/transport/http2_client.go b/vendor/google.golang.org/grpc/internal/transport/http2_client.go index d6bc6a6cc..822c09ba6 100644 --- a/vendor/google.golang.org/grpc/internal/transport/http2_client.go +++ b/vendor/google.golang.org/grpc/internal/transport/http2_client.go @@ -39,6 +39,7 @@ import ( "google.golang.org/grpc/internal" "google.golang.org/grpc/internal/channelz" icredentials "google.golang.org/grpc/internal/credentials" + "google.golang.org/grpc/internal/envconfig" "google.golang.org/grpc/internal/grpclog" "google.golang.org/grpc/internal/grpcsync" "google.golang.org/grpc/internal/grpcutil" @@ -318,7 +319,13 @@ func NewHTTP2Client(connectCtx, ctx context.Context, addr resolver.Address, opts } writeBufSize := opts.WriteBufferSize readBufSize := opts.ReadBufferSize + // The default header list size is moving from 16MB to 8KB. The 8KB limit + // is only used if Enable8KBDefaultHeaderListSize is true; otherwise, the + // old 16MB default is used. User-specified options always take precedence. maxHeaderListSize := defaultClientMaxHeaderListSize + if envconfig.Enable8KBDefaultHeaderListSize { + maxHeaderListSize = upcomingDefaultHeaderListSize + } if opts.MaxHeaderListSize != nil { maxHeaderListSize = *opts.MaxHeaderListSize } @@ -799,9 +806,8 @@ func (t *http2Client) NewStream(ctx context.Context, callHdr *CallHdr, handler s close(s.headerChan) } } - hdr := &headerFrame{ - hf: headerFields, - endStream: false, + hdr := &clientHeaders{ + hf: headerFields, initStream: func(uint32) error { t.mu.Lock() // TODO: handle transport closure in loopy instead and remove this @@ -879,8 +885,8 @@ func (t *http2Client) NewStream(ctx context.Context, callHdr *CallHdr, handler s return false } } - if sz > int64(upcomingDefaultHeaderListSize) { - t.logger.Warningf("Header list size to send (%d bytes) is larger than the upcoming default limit (%d bytes). In a future release, this will be restricted to %d bytes.", sz, upcomingDefaultHeaderListSize, upcomingDefaultHeaderListSize) + if !envconfig.Enable8KBDefaultHeaderListSize && sz > int64(upcomingDefaultHeaderListSize) { + t.logger.Warningf("Header list size to send (%d bytes) is larger than the upcoming default limit (%d bytes). In release v1.82.0, GRPC_GO_EXPERIMENTAL_ENABLE_8KB_DEFAULT_HEADER_LIST_SIZE will be enabled by default, enforcing this limit.", sz, upcomingDefaultHeaderListSize) } return true } @@ -1224,10 +1230,30 @@ func (t *http2Client) handleData(f *parsedDataFrame) { t.closeStream(s, io.EOF, true, http2.ErrCodeFlowControl, status.New(codes.Internal, err.Error()), nil, false) return } + + if s.nonGRPCStatus != nil { + // The frame should be handled as a non-gRPC response body + st := s.handleNonGRPCData(f) + if st != nil { + t.closeStream(s, st.Err(), true, http2.ErrCodeProtocol, st, nil, true) + return + } + if w := s.fc.onRead(size); w > 0 { + t.controlBuf.put(&outgoingWindowUpdate{ + streamID: s.id, + increment: w, + }) + } + return + } + dataLen := f.data.Len() if f.Header().Flags.Has(http2.FlagDataPadded) { if w := s.fc.onRead(size - uint32(dataLen)); w > 0 { - t.controlBuf.put(&outgoingWindowUpdate{s.id, w}) + t.controlBuf.put(&outgoingWindowUpdate{ + streamID: s.id, + increment: w, + }) } } if dataLen > 0 { @@ -1468,6 +1494,17 @@ func (t *http2Client) operateHeaders(frame *http2.MetaHeadersFrame) { return } + // If we are collecting non-gRPC response data and receive a trailing + // HEADERS frame with END_STREAM, finalize the buffered data and close + // the stream. + if s.nonGRPCStatus != nil { + if endStream { + st := s.finalizeNonGRPCStatus() + t.closeStream(s, st.Err(), true, http2.ErrCodeProtocol, st, nil, true) + } + return + } + var ( // If a gRPC Response-Headers has already been received, then it means // that the peer is speaking gRPC and we are in gRPC mode. @@ -1568,7 +1605,12 @@ func (t *http2Client) operateHeaders(frame *http2.MetaHeadersFrame) { } se := status.New(grpcErrorCode, strings.Join(errs, "; ")) - t.closeStream(s, se.Err(), true, http2.ErrCodeProtocol, se, nil, endStream) + if endStream { + t.closeStream(s, se.Err(), true, http2.ErrCodeProtocol, se, nil, true) + return + } + + s.startNonGRPCDataCollection(se) return } @@ -1839,7 +1881,7 @@ func (t *http2Client) getOutFlowWindow() int64 { resp := make(chan uint32, 1) timer := time.NewTimer(time.Second) defer timer.Stop() - t.controlBuf.put(&outFlowControlSizeRequest{resp}) + t.controlBuf.put(&outFlowControlSizeRequest{resp: resp}) select { case sz := <-resp: return int64(sz) diff --git a/vendor/google.golang.org/grpc/internal/transport/http2_server.go b/vendor/google.golang.org/grpc/internal/transport/http2_server.go index 3a8c36e4f..be8ae9f9c 100644 --- a/vendor/google.golang.org/grpc/internal/transport/http2_server.go +++ b/vendor/google.golang.org/grpc/internal/transport/http2_server.go @@ -38,11 +38,13 @@ import ( "google.golang.org/protobuf/proto" "google.golang.org/grpc/internal" + "google.golang.org/grpc/internal/envconfig" "google.golang.org/grpc/internal/grpclog" "google.golang.org/grpc/internal/grpcutil" "google.golang.org/grpc/internal/pretty" istatus "google.golang.org/grpc/internal/status" "google.golang.org/grpc/internal/syscall" + transportinternal "google.golang.org/grpc/internal/transport/internal" "google.golang.org/grpc/mem" "google.golang.org/grpc/codes" @@ -165,7 +167,13 @@ func NewServerTransport(conn net.Conn, config *ServerConfig) (_ ServerTransport, } writeBufSize := config.WriteBufferSize readBufSize := config.ReadBufferSize + // The default header list size is moving from 16MB to 8KB. The 8KB limit + // is only used if Enable8KBDefaultHeaderListSize is true; otherwise, the + // old 16MB default is used. User-specified options always take precedence. maxHeaderListSize := defaultServerMaxHeaderListSize + if envconfig.Enable8KBDefaultHeaderListSize { + maxHeaderListSize = upcomingDefaultHeaderListSize + } if config.MaxHeaderListSize != nil { maxHeaderListSize = *config.MaxHeaderListSize } @@ -802,7 +810,10 @@ func (t *http2Server) handleData(f *parsedDataFrame) { dataLen := f.data.Len() if f.Header().Flags.Has(http2.FlagDataPadded) { if w := s.fc.onRead(size - uint32(dataLen)); w > 0 { - t.controlBuf.put(&outgoingWindowUpdate{s.id, w}) + t.controlBuf.put(&outgoingWindowUpdate{ + streamID: s.id, + increment: w, + }) } } if dataLen > 0 { @@ -948,8 +959,8 @@ func (t *http2Server) checkForHeaderListSize(hf []hpack.HeaderField) bool { return false } } - if sz > int64(upcomingDefaultHeaderListSize) { - t.logger.Warningf("Header list size to send (%d bytes) is larger than the upcoming default limit (%d bytes). In a future release, this will be restricted to %d bytes.", sz, upcomingDefaultHeaderListSize, upcomingDefaultHeaderListSize) + if !envconfig.Enable8KBDefaultHeaderListSize && sz > int64(upcomingDefaultHeaderListSize) { + t.logger.Warningf("Header list size to send (%d bytes) is larger than the upcoming default limit (%d bytes). In release v1.82.0, GRPC_GO_EXPERIMENTAL_ENABLE_8KB_DEFAULT_HEADER_LIST_SIZE will be enabled by default, enforcing this limit.", sz, upcomingDefaultHeaderListSize) } return true } @@ -1039,7 +1050,7 @@ func (t *http2Server) writeHeaderLocked(s *ServerStream) error { headerFields = append(headerFields, hpack.HeaderField{Name: "grpc-encoding", Value: s.sendCompress}) } headerFields = appendHeaderFieldsFromMD(headerFields, s.header) - hf := &headerFrame{ + hf := &serverHeaders{ streamID: s.id, hf: headerFields, endStream: false, @@ -1107,7 +1118,7 @@ func (t *http2Server) writeStatus(s *ServerStream, st *status.Status) error { // Attach the trailer metadata. headerFields = appendHeaderFieldsFromMD(headerFields, s.trailer) - trailingHeader := &headerFrame{ + trailingHeader := &serverHeaders{ streamID: s.id, hf: headerFields, endStream: true, @@ -1317,7 +1328,7 @@ func (t *http2Server) deleteStream(s *ServerStream, eosReceived bool) { } // finishStream closes the stream and puts the trailing headerFrame into controlbuf. -func (t *http2Server) finishStream(s *ServerStream, rst bool, rstCode http2.ErrCode, hdr *headerFrame, eosReceived bool) { +func (t *http2Server) finishStream(s *ServerStream, rst bool, rstCode http2.ErrCode, hdr *serverHeaders, eosReceived bool) { // In case stream sending and receiving are invoked in separate // goroutines (e.g., bi-directional streaming), cancel needs to be // called to interrupt the potential blocking on other goroutines. @@ -1441,14 +1452,14 @@ func (t *http2Server) socketMetrics() *channelz.EphemeralSocketMetrics { func (t *http2Server) incrMsgSent() { if channelz.IsOn() { t.channelz.SocketMetrics.MessagesSent.Add(1) - t.channelz.SocketMetrics.LastMessageSentTimestamp.Add(1) + t.channelz.SocketMetrics.LastMessageSentTimestamp.Store(transportinternal.TimeNowFunc()) } } func (t *http2Server) incrMsgRecv() { if channelz.IsOn() { t.channelz.SocketMetrics.MessagesReceived.Add(1) - t.channelz.SocketMetrics.LastMessageReceivedTimestamp.Add(1) + t.channelz.SocketMetrics.LastMessageReceivedTimestamp.Store(transportinternal.TimeNowFunc()) } } @@ -1456,7 +1467,7 @@ func (t *http2Server) getOutFlowWindow() int64 { resp := make(chan uint32, 1) timer := time.NewTimer(time.Second) defer timer.Stop() - t.controlBuf.put(&outFlowControlSizeRequest{resp}) + t.controlBuf.put(&outFlowControlSizeRequest{resp: resp}) select { case sz := <-resp: return int64(sz) diff --git a/vendor/google.golang.org/grpc/internal/grpcutil/regex.go b/vendor/google.golang.org/grpc/internal/transport/internal/internal.go similarity index 59% rename from vendor/google.golang.org/grpc/internal/grpcutil/regex.go rename to vendor/google.golang.org/grpc/internal/transport/internal/internal.go index 7a092b2b8..a7c7c7d5a 100644 --- a/vendor/google.golang.org/grpc/internal/grpcutil/regex.go +++ b/vendor/google.golang.org/grpc/internal/transport/internal/internal.go @@ -1,6 +1,6 @@ /* * - * Copyright 2021 gRPC authors. + * Copyright 2026 gRPC authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,16 +16,10 @@ * */ -package grpcutil +// Package internal contains functionality internal to the transport package. +package internal -import "regexp" - -// FullMatchWithRegex returns whether the full text matches the regex provided. -func FullMatchWithRegex(re *regexp.Regexp, text string) bool { - if len(text) == 0 { - return re.MatchString(text) - } - re.Longest() - rem := re.FindString(text) - return len(rem) == len(text) -} +// TimeNowFunc is a variable that can be set to override the default behavior of +// getting the current time in nanoseconds. It is used in transport code to set +// channelz timestamps, and is exposed here for testing purposes. +var TimeNowFunc func() int64 diff --git a/vendor/google.golang.org/grpc/internal/transport/transport.go b/vendor/google.golang.org/grpc/internal/transport/transport.go index 1e224576e..6dfae3984 100644 --- a/vendor/google.golang.org/grpc/internal/transport/transport.go +++ b/vendor/google.golang.org/grpc/internal/transport/transport.go @@ -35,6 +35,7 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/credentials" "google.golang.org/grpc/internal/channelz" + "google.golang.org/grpc/internal/transport/internal" "google.golang.org/grpc/keepalive" "google.golang.org/grpc/mem" "google.golang.org/grpc/metadata" @@ -46,6 +47,10 @@ import ( const logLevel = 2 +func init() { + internal.TimeNowFunc = func() int64 { return time.Now().UnixNano() } +} + // recvMsg represents the received msg from the transport. All transport // protocol specific info has been removed. type recvMsg struct { diff --git a/vendor/google.golang.org/grpc/reflection/grpc_reflection_v1/reflection_grpc.pb.go b/vendor/google.golang.org/grpc/reflection/grpc_reflection_v1/reflection_grpc.pb.go index 81ced2fbf..21142c64e 100644 --- a/vendor/google.golang.org/grpc/reflection/grpc_reflection_v1/reflection_grpc.pb.go +++ b/vendor/google.golang.org/grpc/reflection/grpc_reflection_v1/reflection_grpc.pb.go @@ -21,7 +21,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: -// - protoc-gen-go-grpc v1.6.1 +// - protoc-gen-go-grpc v1.6.2 // - protoc v5.27.1 // source: grpc/reflection/v1/reflection.proto diff --git a/vendor/google.golang.org/grpc/reflection/grpc_reflection_v1alpha/reflection_grpc.pb.go b/vendor/google.golang.org/grpc/reflection/grpc_reflection_v1alpha/reflection_grpc.pb.go index 18061e8ba..2a3f45d1b 100644 --- a/vendor/google.golang.org/grpc/reflection/grpc_reflection_v1alpha/reflection_grpc.pb.go +++ b/vendor/google.golang.org/grpc/reflection/grpc_reflection_v1alpha/reflection_grpc.pb.go @@ -18,7 +18,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: -// - protoc-gen-go-grpc v1.6.1 +// - protoc-gen-go-grpc v1.6.2 // - protoc v5.27.1 // grpc/reflection/v1alpha/reflection.proto is a deprecated file. diff --git a/vendor/google.golang.org/grpc/rpc_util.go b/vendor/google.golang.org/grpc/rpc_util.go index ee7f7dead..52f4ea513 100644 --- a/vendor/google.golang.org/grpc/rpc_util.go +++ b/vendor/google.golang.org/grpc/rpc_util.go @@ -128,6 +128,16 @@ func NewGZIPDecompressor() Decompressor { } func (d *gzipDecompressor) Do(r io.Reader) ([]byte, error) { + return d.doWithMaxSize(r, math.MaxInt64) +} + +// doWithMaxSize behaves like Do but caps the size of the decompressed +// payload at maxMessageSize+1 bytes. The Decompressor interface does not +// allow extra parameters, so callers inside the package type-assert to +// *gzipDecompressor to invoke this method directly. The +1 byte makes it +// possible for the caller to detect that the limit was exceeded and +// return ResourceExhausted instead of materializing an unbounded payload. +func (d *gzipDecompressor) doWithMaxSize(r io.Reader, maxMessageSize int64) ([]byte, error) { var z *gzip.Reader switch maybeZ := d.pool.Get().(type) { case nil: @@ -148,7 +158,11 @@ func (d *gzipDecompressor) Do(r io.Reader) ([]byte, error) { z.Close() d.pool.Put(z) }() - return io.ReadAll(z) + var src io.Reader = z + if maxMessageSize < math.MaxInt64 { + src = io.LimitReader(z, maxMessageSize+1) + } + return io.ReadAll(src) } func (d *gzipDecompressor) Type() string { @@ -830,15 +844,15 @@ func compress(in mem.BufferSlice, cp Compressor, compressor encoding.Compressor, if compressor != nil { z, err := compressor.Compress(w) if err != nil { - return nil, 0, wrapErr(err) + return nil, compressionNone, wrapErr(err) } for _, b := range in { if _, err := z.Write(b.ReadOnlyData()); err != nil { - return nil, 0, wrapErr(err) + return nil, compressionNone, wrapErr(err) } } if err := z.Close(); err != nil { - return nil, 0, wrapErr(err) + return nil, compressionNone, wrapErr(err) } } else { // This is obviously really inefficient since it fully materializes the data, but @@ -848,7 +862,7 @@ func compress(in mem.BufferSlice, cp Compressor, compressor encoding.Compressor, buf := in.MaterializeToBuffer(pool) defer buf.Free() if err := cp.Do(w, buf.ReadOnlyData()); err != nil { - return nil, 0, wrapErr(err) + return nil, compressionNone, wrapErr(err) } } return out, compressionMade, nil @@ -971,7 +985,20 @@ func recvAndDecompress(p *parser, s recvCompressor, dc Decompressor, maxReceiveM func decompress(compressor encoding.Compressor, d mem.BufferSlice, dc Decompressor, maxReceiveMessageSize int, pool mem.BufferPool) (mem.BufferSlice, error) { if dc != nil { r := d.Reader() - uncompressed, err := dc.Do(r) + // For the built-in gzip decompressor, bound the decompressed output + // at maxReceiveMessageSize+1 so that a small but highly compressed + // payload (a "zip bomb") cannot expand to gigabytes in memory before + // the post-decompression size check below has a chance to fire. The + // Decompressor interface does not accept an extra size parameter, + // so we type-assert to invoke a size-aware helper. Third-party + // Decompressor implementations keep the original Do behavior. + var uncompressed []byte + var err error + if gd, ok := dc.(*gzipDecompressor); ok { + uncompressed, err = gd.doWithMaxSize(r, int64(maxReceiveMessageSize)) + } else { + uncompressed, err = dc.Do(r) + } if err != nil { r.Close() // ensure buffers are reused return nil, status.Errorf(codes.Internal, "grpc: failed to decompress the received message: %v", err) @@ -989,6 +1016,9 @@ func decompress(compressor encoding.Compressor, d mem.BufferSlice, dc Decompress r.Close() // ensure buffers are reused return nil, status.Errorf(codes.Internal, "grpc: failed to decompress the message: %v", err) } + if closer, ok := dcReader.(io.Closer); ok { + defer closer.Close() + } // Read at most one byte more than the limit from the decompressor. // Unless the limit is MaxInt64, in which case, that's impossible, so diff --git a/vendor/google.golang.org/grpc/server.go b/vendor/google.golang.org/grpc/server.go index 5229adf71..cf0a20671 100644 --- a/vendor/google.golang.org/grpc/server.go +++ b/vendor/google.golang.org/grpc/server.go @@ -28,6 +28,7 @@ import ( "net/http" "reflect" "runtime" + "runtime/pprof" "strings" "sync" "sync/atomic" @@ -150,8 +151,6 @@ type Server struct { serverWorkerChannel chan func() serverWorkerChannelClose func() - - strictPathCheckingLogEmitted atomic.Bool } type serverOptions struct { @@ -250,10 +249,8 @@ func newJoinServerOption(opts ...ServerOption) ServerOption { // If this option is set to true every connection will release the buffer after // flushing the data on the wire. // -// # Experimental -// -// Notice: This API is EXPERIMENTAL and may be changed or removed in a -// later release. +// Deprecated: shared write buffer is enabled by default. SharedWriteBuffer +// will be removed in a future release. func SharedWriteBuffer(val bool) ServerOption { return newFuncServerOption(func(o *serverOptions) { o.sharedWriteBuffer = val @@ -302,6 +299,14 @@ func InitialConnWindowSize(s int32) ServerOption { // window size to the value provided and disables dynamic flow control. // The lower bound for window size is 64K and any value smaller than that // will be ignored. +// +// Note that this also disables dynamic flow control for the connection, +// falling back to a default static connection-level window of 64KB. To +// use a larger connection-level window, you must also use the +// [StaticConnWindowSize] ServerOption. +// +// Most users should not configure static flow control windows unless +// operating in a memory-constrained environment. func StaticStreamWindowSize(s int32) ServerOption { return newFuncServerOption(func(o *serverOptions) { o.initialWindowSize = s @@ -313,6 +318,14 @@ func StaticStreamWindowSize(s int32) ServerOption { // window size to the value provided and disables dynamic flow control. // The lower bound for window size is 64K and any value smaller than that // will be ignored. +// +// Note that this also disables dynamic flow control for individual streams, +// falling back to a default static connection-level window of 64KB. To +// explicitly configure the stream-level window size, you must also use the +// [StaticStreamWindowSize] ServerOption. +// +// Most users should not configure static flow control windows unless +// operating in a memory-constrained environment. func StaticConnWindowSize(s int32) ServerOption { return newFuncServerOption(func(o *serverOptions) { o.initialConnWindowSize = s @@ -1787,6 +1800,12 @@ func (s *Server) handleMalformedMethodName(stream *transport.ServerStream, ti *t func (s *Server) handleStream(t transport.ServerTransport, stream *transport.ServerStream) { ctx := stream.Context() ctx = contextWithServer(ctx, s) + if envconfig.LabelServerGoroutines&envconfig.GoroutineLabelServerMethod != 0 { + // This method always runs in its own goroutine, so we can set a + // goroutine label without needing to restore a previous context. + ctx = pprof.WithLabels(ctx, pprof.Labels("grpc.method", stream.Method())) + pprof.SetGoroutineLabels(ctx) + } var ti *traceInfo if EnableTracing { tr := newTrace("grpc.Recv."+methodFamily(stream.Method()), stream.Method()) @@ -1803,28 +1822,11 @@ func (s *Server) handleStream(t transport.ServerTransport, stream *transport.Ser } } - sm := stream.Method() - if sm == "" { + sm, found := strings.CutPrefix(stream.Method(), "/") + if !found { s.handleMalformedMethodName(stream, ti) return } - if sm[0] != '/' { - // TODO(easwars): Add a link to the CVE in the below log messages once - // published. - if envconfig.DisableStrictPathChecking { - if old := s.strictPathCheckingLogEmitted.Swap(true); !old { - channelz.Warningf(logger, s.channelz, "grpc: Server.handleStream received malformed method name %q. Allowing it because the environment variable GRPC_GO_EXPERIMENTAL_DISABLE_STRICT_PATH_CHECKING is set to true, but this option will be removed in a future release.", sm) - } - } else { - if old := s.strictPathCheckingLogEmitted.Swap(true); !old { - channelz.Warningf(logger, s.channelz, "grpc: Server.handleStream rejected malformed method name %q. To temporarily allow such requests, set the environment variable GRPC_GO_EXPERIMENTAL_DISABLE_STRICT_PATH_CHECKING to true. Note that this is not recommended as it may allow requests to bypass security policies.", sm) - } - s.handleMalformedMethodName(stream, ti) - return - } - } else { - sm = sm[1:] - } pos := strings.LastIndex(sm, "/") if pos == -1 { s.handleMalformedMethodName(stream, ti) diff --git a/vendor/google.golang.org/grpc/version.go b/vendor/google.golang.org/grpc/version.go index 3ccfe515f..53c737fee 100644 --- a/vendor/google.golang.org/grpc/version.go +++ b/vendor/google.golang.org/grpc/version.go @@ -19,4 +19,4 @@ package grpc // Version is the current grpc version. -const Version = "1.81.1" +const Version = "1.82.1" diff --git a/vendor/modules.txt b/vendor/modules.txt index 326f98370..e6028386d 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -517,7 +517,7 @@ google.golang.org/genproto/googleapis/api/httpbody ## explicit; go 1.25.0 google.golang.org/genproto/googleapis/rpc/errdetails google.golang.org/genproto/googleapis/rpc/status -# google.golang.org/grpc v1.81.1 +# google.golang.org/grpc v1.82.1 ## explicit; go 1.25.0 google.golang.org/grpc google.golang.org/grpc/attributes @@ -539,6 +539,7 @@ google.golang.org/grpc/encoding google.golang.org/grpc/encoding/gzip google.golang.org/grpc/encoding/internal google.golang.org/grpc/encoding/proto +google.golang.org/grpc/experimental/balancer/weight google.golang.org/grpc/experimental/stats google.golang.org/grpc/grpclog google.golang.org/grpc/grpclog/internal @@ -547,7 +548,6 @@ google.golang.org/grpc/health/grpc_health_v1 google.golang.org/grpc/internal google.golang.org/grpc/internal/backoff google.golang.org/grpc/internal/balancer/gracefulswitch -google.golang.org/grpc/internal/balancer/weight google.golang.org/grpc/internal/balancerload google.golang.org/grpc/internal/binarylog google.golang.org/grpc/internal/buffer @@ -573,6 +573,7 @@ google.golang.org/grpc/internal/stats google.golang.org/grpc/internal/status google.golang.org/grpc/internal/syscall google.golang.org/grpc/internal/transport +google.golang.org/grpc/internal/transport/internal google.golang.org/grpc/internal/transport/networktype google.golang.org/grpc/internal/transport/readyreader google.golang.org/grpc/keepalive From 8ae51bb0c0f64b609236ae1a555372a2606cbabc Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Thu, 23 Jul 2026 23:28:23 +0200 Subject: [PATCH 043/182] fix(deps): update module github.com/mccutchen/go-httpbin/v2 to v2.24.0 (#6177) | datasource | package | from | to | | ---------- | ---------------------------------- | ------- | ------- | | go | github.com/mccutchen/go-httpbin/v2 | v2.23.1 | v2.24.0 | Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 +-- .../go-httpbin/v2/httpbin/handlers.go | 35 +++++++++++-------- vendor/modules.txt | 2 +- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/go.mod b/go.mod index e8e0ac47a..f4dedbc32 100644 --- a/go.mod +++ b/go.mod @@ -31,7 +31,7 @@ require ( github.com/klauspost/compress v1.19.0 github.com/mattn/go-colorable v0.1.15 github.com/mattn/go-isatty v0.0.22 - github.com/mccutchen/go-httpbin/v2 v2.23.1 + github.com/mccutchen/go-httpbin/v2 v2.24.0 github.com/mstoykov/atlas v0.0.0-20220811071828-388f114305dd github.com/mstoykov/envconfig v1.5.0 github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c diff --git a/go.sum b/go.sum index 7bb67ee64..cc5e0877c 100644 --- a/go.sum +++ b/go.sum @@ -133,8 +133,8 @@ github.com/mattn/go-colorable v0.1.15 h1:+u9SLTRGnXv73cEsnsmoZBom+dMU88B2M0aDcWy github.com/mattn/go-colorable v0.1.15/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8= github.com/mattn/go-isatty v0.0.22 h1:j8l17JJ9i6VGPUFUYoTUKPSgKe/83EYU2zBC7YNKMw4= github.com/mattn/go-isatty v0.0.22/go.mod h1:ZXfXG4SQHsB/w3ZeOYbR0PrPwLy+n6xiMrJlRFqopa4= -github.com/mccutchen/go-httpbin/v2 v2.23.1 h1:F/05blJUzgTVTBd5bUW0cstUXnqnv5KIetb6uBciyG4= -github.com/mccutchen/go-httpbin/v2 v2.23.1/go.mod h1:8hkN5rHf0QvJYEovZ8u/Dudtqyj6Z5gxQaW7scQfT0Y= +github.com/mccutchen/go-httpbin/v2 v2.24.0 h1:MZ5QSGVeVpg/c7ZRbIg8UVZvefeBn/NhSVTc1fCQFEQ= +github.com/mccutchen/go-httpbin/v2 v2.24.0/go.mod h1:8hkN5rHf0QvJYEovZ8u/Dudtqyj6Z5gxQaW7scQfT0Y= github.com/mstoykov/atlas v0.0.0-20220811071828-388f114305dd h1:AC3N94irbx2kWGA8f/2Ks7EQl2LxKIRQYuT9IJDwgiI= github.com/mstoykov/atlas v0.0.0-20220811071828-388f114305dd/go.mod h1:9vRHVuLCjoFfE3GT06X0spdOAO+Zzo4AMjdIwUHBvAk= github.com/mstoykov/envconfig v1.5.0 h1:E2FgWf73BQt0ddgn7aoITkQHmgwAcHup1s//MsS5/f8= diff --git a/vendor/github.com/mccutchen/go-httpbin/v2/httpbin/handlers.go b/vendor/github.com/mccutchen/go-httpbin/v2/httpbin/handlers.go index 9673d9e4e..f7298a359 100644 --- a/vendor/github.com/mccutchen/go-httpbin/v2/httpbin/handlers.go +++ b/vendor/github.com/mccutchen/go-httpbin/v2/httpbin/handlers.go @@ -472,20 +472,11 @@ func (h *HTTPBin) RedirectTo(w http.ResponseWriter, r *http.Request) { return } - // If we're given a URL that includes a domain name and we have a list of - // allowed domains, ensure that the domain is allowed. - // - // Note: This checks the hostname directly rather than using the net.URL's - // IsAbs() method, because IsAbs() will return false for URLs that omit - // the scheme but include a domain name, like "//evil.com" and it's - // important that we validate the domain in these cases as well. - if u.Hostname() != "" && len(h.AllowedRedirectDomains) > 0 { - if _, ok := h.AllowedRedirectDomains[u.Hostname()]; !ok { - // for this error message we do not use our standard JSON response - // because we want it to be more obviously human readable. - writeResponse(w, http.StatusForbidden, "text/plain", []byte(h.forbiddenRedirectError)) - return - } + if !h.redirectAllowed(u) { + // for this error message we do not use our standard JSON response + // because we want it to be more obviously human readable. + writeResponse(w, http.StatusForbidden, "text/plain", []byte(h.forbiddenRedirectError)) + return } statusCode := http.StatusFound @@ -500,6 +491,22 @@ func (h *HTTPBin) RedirectTo(w http.ResponseWriter, r *http.Request) { h.doRedirect(w, u.String(), statusCode) } +// redirectAllowed checks whether the given redirect target is permitted. +// +// If a hostname allowlist is configured and the target is an absolute URL, +// its hostname must be in the allowlist. +// +// Otherwise, the target must be either an absolute or root-relative URL. +func (h *HTTPBin) redirectAllowed(target *url.URL) bool { + if len(h.AllowedRedirectDomains) > 0 { + if host := target.Hostname(); host != "" { + _, ok := h.AllowedRedirectDomains[host] + return ok + } + } + return target.IsAbs() || strings.HasPrefix(target.Path, "/") +} + // Cookies responds with the cookies in the incoming request func (h *HTTPBin) Cookies(w http.ResponseWriter, r *http.Request) { resp := cookiesResponse{Cookies: make(map[string]string)} diff --git a/vendor/modules.txt b/vendor/modules.txt index e6028386d..46b8ff868 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -256,7 +256,7 @@ github.com/mattn/go-colorable # github.com/mattn/go-isatty v0.0.22 ## explicit; go 1.21 github.com/mattn/go-isatty -# github.com/mccutchen/go-httpbin/v2 v2.23.1 +# github.com/mccutchen/go-httpbin/v2 v2.24.0 ## explicit; go 1.25.0 github.com/mccutchen/go-httpbin/v2/httpbin github.com/mccutchen/go-httpbin/v2/httpbin/digest From eac3e7e5310d57de7d6bcdbcf2c35e324a066ee1 Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Thu, 23 Jul 2026 23:33:35 +0200 Subject: [PATCH 044/182] fix(deps): update module github.com/andybalholm/brotli to v1.2.2 (#6174) | datasource | package | from | to | | ---------- | ----------------------------- | ------ | ------ | | go | github.com/andybalholm/brotli | v1.2.1 | v1.2.2 | Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 +- .../github.com/andybalholm/brotli/decode.go | 21 ++----- .../github.com/andybalholm/brotli/reader.go | 19 +++++- vendor/github.com/andybalholm/brotli/state.go | 63 ++++++++++++------- vendor/modules.txt | 2 +- 6 files changed, 67 insertions(+), 44 deletions(-) diff --git a/go.mod b/go.mod index f4dedbc32..b9a362087 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/Masterminds/semver/v3 v3.5.0 github.com/PuerkitoBio/goquery v1.12.0 github.com/Soontao/goHttpDigestClient v0.0.0-20170320082612-6d28bb1415c5 - github.com/andybalholm/brotli v1.2.1 + github.com/andybalholm/brotli v1.2.2 github.com/bufbuild/protocompile v0.14.1 github.com/chromedp/cdproto v0.0.0-20250803210736-d308e07a266d github.com/evanw/esbuild v0.28.1 diff --git a/go.sum b/go.sum index cc5e0877c..6d7f33df0 100644 --- a/go.sum +++ b/go.sum @@ -12,8 +12,8 @@ github.com/PuerkitoBio/goquery v1.12.0 h1:pAcL4g3WRXekcB9AU/y1mbKez2dbY2AajVhtkO github.com/PuerkitoBio/goquery v1.12.0/go.mod h1:802ej+gV2y7bbIhOIoPY5sT183ZW0YFofScC4q/hIpQ= github.com/Soontao/goHttpDigestClient v0.0.0-20170320082612-6d28bb1415c5 h1:k+1+doEm31k0rRjCjLnGG3YRkuO9ljaEyS2ajZd6GK8= github.com/Soontao/goHttpDigestClient v0.0.0-20170320082612-6d28bb1415c5/go.mod h1:5Q4+CyR7+Q3VMG8f78ou+QSX/BNUNUx5W48eFRat8DQ= -github.com/andybalholm/brotli v1.2.1 h1:R+f5xP285VArJDRgowrfb9DqL18yVK0gKAW/F+eTWro= -github.com/andybalholm/brotli v1.2.1/go.mod h1:rzTDkvFWvIrjDXZHkuS16NPggd91W3kUSvPlQ1pLaKY= +github.com/andybalholm/brotli v1.2.2 h1:HzTuoo2ErYQqf5qvcJInB8uvqSVxRttzkFexPWtnceM= +github.com/andybalholm/brotli v1.2.2/go.mod h1:rzTDkvFWvIrjDXZHkuS16NPggd91W3kUSvPlQ1pLaKY= github.com/andybalholm/cascadia v1.3.3 h1:AG2YHrzJIm4BZ19iwJ/DAua6Btl3IwJX+VI4kktS1LM= github.com/andybalholm/cascadia v1.3.3/go.mod h1:xNd9bqTn98Ln4DwST8/nG+H0yuB8Hmgu1YHNnWw0GeA= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= diff --git a/vendor/github.com/andybalholm/brotli/decode.go b/vendor/github.com/andybalholm/brotli/decode.go index 9d9513b7c..1a27c0a6b 100644 --- a/vendor/github.com/andybalholm/brotli/decode.go +++ b/vendor/github.com/andybalholm/brotli/decode.go @@ -2175,12 +2175,9 @@ func decoderDecompressStream(s *Reader, available_in *uint, next_in *[]byte, ava case stateInitialize: s.max_backward_distance = (1 << s.window_bits) - windowGap - /* Allocate memory for both block_type_trees and block_len_trees. */ - s.block_type_trees = make([]huffmanCode, (3 * (huffmanMaxSize258 + huffmanMaxSize26))) - if s.block_type_trees == nil { - result = decoderErrorAllocBlockTypeTrees - break + /* Allocate memory for both block_type_trees and block_len_trees. */ + s.block_type_trees = make([]huffmanCode, (3 * (huffmanMaxSize258 + huffmanMaxSize26))) } s.block_len_trees = s.block_type_trees[3*huffmanMaxSize258:] @@ -2368,17 +2365,9 @@ func decoderDecompressStream(s *Reader, available_in *uint, next_in *[]byte, ava break } - if !decoderHuffmanTreeGroupInit(s, &s.literal_hgroup, numLiteralSymbols, numLiteralSymbols, s.num_literal_htrees) { - allocation_success = false - } - - if !decoderHuffmanTreeGroupInit(s, &s.insert_copy_hgroup, numCommandSymbols, numCommandSymbols, s.num_block_types[1]) { - allocation_success = false - } - - if !decoderHuffmanTreeGroupInit(s, &s.distance_hgroup, num_distance_codes, max_distance_symbol, s.num_dist_htrees) { - allocation_success = false - } + decoderHuffmanTreeGroupInit(&s.literal_hgroup, numLiteralSymbols, numLiteralSymbols, s.num_literal_htrees) + decoderHuffmanTreeGroupInit(&s.insert_copy_hgroup, numCommandSymbols, numCommandSymbols, s.num_block_types[1]) + decoderHuffmanTreeGroupInit(&s.distance_hgroup, num_distance_codes, max_distance_symbol, s.num_dist_htrees) if !allocation_success { return saveErrorCode(s, decoderErrorAllocTreeGroups) diff --git a/vendor/github.com/andybalholm/brotli/reader.go b/vendor/github.com/andybalholm/brotli/reader.go index 3e2278935..d652f4a13 100644 --- a/vendor/github.com/andybalholm/brotli/reader.go +++ b/vendor/github.com/andybalholm/brotli/reader.go @@ -33,8 +33,23 @@ func NewReader(src io.Reader) *Reader { func (r *Reader) Reset(src io.Reader) error { if r.error_code < 0 { // There was an unrecoverable error, leaving the Reader's state - // undefined. Clear out everything but the buffer. - *r = Reader{buf: r.buf} + // undefined. Clear out everything but the buffers. + *r = Reader{ + buf: r.buf, + block_type_trees: r.block_type_trees, + literal_hgroup: huffmanTreeGroup{ + htrees: r.literal_hgroup.htrees, + codes: r.literal_hgroup.codes, + }, + distance_hgroup: huffmanTreeGroup{ + htrees: r.distance_hgroup.htrees, + codes: r.distance_hgroup.codes, + }, + insert_copy_hgroup: huffmanTreeGroup{ + htrees: r.insert_copy_hgroup.htrees, + codes: r.insert_copy_hgroup.codes, + }, + } } decoderStateInit(r) diff --git a/vendor/github.com/andybalholm/brotli/state.go b/vendor/github.com/andybalholm/brotli/state.go index 38d753ebe..da26da44f 100644 --- a/vendor/github.com/andybalholm/brotli/state.go +++ b/vendor/github.com/andybalholm/brotli/state.go @@ -198,7 +198,7 @@ func decoderStateInit(s *Reader) bool { s.rb_roundtrips = 0 s.partial_pos_out = 0 - s.block_type_trees = nil + clear(s.block_type_trees) s.block_len_trees = nil s.ringbuffer_size = 0 s.new_ringbuffer_size = 0 @@ -212,12 +212,8 @@ func decoderStateInit(s *Reader) bool { s.sub_loop_counter = 0 - s.literal_hgroup.codes = nil - s.literal_hgroup.htrees = nil - s.insert_copy_hgroup.codes = nil - s.insert_copy_hgroup.htrees = nil - s.distance_hgroup.codes = nil - s.distance_hgroup.htrees = nil + cleanupCodes(s) + cleanupHTrees(s) s.is_last_metablock = 0 s.is_uncompressed = 0 @@ -232,8 +228,6 @@ func decoderStateInit(s *Reader) bool { s.dist_rb[2] = 11 s.dist_rb[3] = 4 s.dist_rb_idx = 0 - s.block_type_trees = nil - s.block_len_trees = nil s.symbol_lists.storage = s.symbols_lists_array[:] s.symbol_lists.offset = huffmanMaxCodeLength + 1 @@ -266,29 +260,54 @@ func decoderStateMetablockBegin(s *Reader) { s.dist_context_map_slice = nil s.dist_htree_index = 0 s.context_lookup = nil - s.literal_hgroup.codes = nil - s.literal_hgroup.htrees = nil - s.insert_copy_hgroup.codes = nil - s.insert_copy_hgroup.htrees = nil - s.distance_hgroup.codes = nil - s.distance_hgroup.htrees = nil + + cleanupCodes(s) + cleanupHTrees(s) } func decoderStateCleanupAfterMetablock(s *Reader) { s.context_modes = nil s.context_map = nil s.dist_context_map = nil - s.literal_hgroup.htrees = nil - s.insert_copy_hgroup.htrees = nil - s.distance_hgroup.htrees = nil + cleanupHTrees(s) } -func decoderHuffmanTreeGroupInit(s *Reader, group *huffmanTreeGroup, alphabet_size uint32, max_symbol uint32, ntrees uint32) bool { +func decoderHuffmanTreeGroupInit(group *huffmanTreeGroup, alphabet_size uint32, max_symbol uint32, ntrees uint32) { var max_table_size uint = uint(kMaxHuffmanTableSize[(alphabet_size+31)>>5]) group.alphabet_size = uint16(alphabet_size) group.max_symbol = uint16(max_symbol) group.num_htrees = uint16(ntrees) - group.htrees = make([][]huffmanCode, ntrees) - group.codes = make([]huffmanCode, (uint(ntrees) * max_table_size)) - return !(group.codes == nil) + + makeCodesBuffer(group, uint(ntrees)*max_table_size) + makeTreesBuffer(group, ntrees) +} + +func makeTreesBuffer(group *huffmanTreeGroup, treesLen uint32) { + if cap(group.htrees) < int(treesLen) { + group.htrees = make([][]huffmanCode, treesLen) + return + } + + group.htrees = group.htrees[:treesLen] +} + +func makeCodesBuffer(group *huffmanTreeGroup, codesLen uint) { + if cap(group.codes) < int(codesLen) { + group.codes = make([]huffmanCode, codesLen) + return + } + + group.codes = group.codes[:codesLen] +} + +func cleanupCodes(s *Reader) { + clear(s.literal_hgroup.codes) + clear(s.insert_copy_hgroup.codes) + clear(s.distance_hgroup.codes) +} + +func cleanupHTrees(s *Reader) { + clear(s.literal_hgroup.htrees) + clear(s.insert_copy_hgroup.htrees) + clear(s.distance_hgroup.htrees) } diff --git a/vendor/modules.txt b/vendor/modules.txt index 46b8ff868..fbb8a92f2 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -17,7 +17,7 @@ github.com/PuerkitoBio/goquery # github.com/Soontao/goHttpDigestClient v0.0.0-20170320082612-6d28bb1415c5 ## explicit github.com/Soontao/goHttpDigestClient -# github.com/andybalholm/brotli v1.2.1 +# github.com/andybalholm/brotli v1.2.2 ## explicit; go 1.22 github.com/andybalholm/brotli github.com/andybalholm/brotli/flate From df2e967c86a671f7210f39197089fffc77882b22 Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Fri, 24 Jul 2026 12:49:49 +0300 Subject: [PATCH 045/182] fix(security/unknown/examples/grpc_server): update module golang.org/x/text to v0.39.0 [security] (#6186) | datasource | package | from | to | | ---------- | ----------------- | ------- | ------- | | go | golang.org/x/text | v0.38.0 | v0.39.0 | Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> --- examples/grpc_server/go.mod | 2 +- examples/grpc_server/go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/grpc_server/go.mod b/examples/grpc_server/go.mod index 4436a3915..1815ee0f6 100644 --- a/examples/grpc_server/go.mod +++ b/examples/grpc_server/go.mod @@ -12,7 +12,7 @@ require ( require ( golang.org/x/net v0.56.0 // indirect golang.org/x/sys v0.46.0 // indirect - golang.org/x/text v0.38.0 // indirect + golang.org/x/text v0.39.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20260414002931-afd174a4e478 // indirect google.golang.org/protobuf v1.36.11 // indirect ) diff --git a/examples/grpc_server/go.sum b/examples/grpc_server/go.sum index 0bfa532f2..58178e5c1 100644 --- a/examples/grpc_server/go.sum +++ b/examples/grpc_server/go.sum @@ -28,8 +28,8 @@ golang.org/x/net v0.56.0 h1:Rw8j/hFzGvJUZwNBXnAtf5sVDVt+65SK2C7IxCxZt5o= golang.org/x/net v0.56.0/go.mod h1:D3Ku6r+V6JROoZK144D2XfMHFcMq/0zSfLelVTCFKec= golang.org/x/sys v0.46.0 h1:noSf2Fq6F8DBgS+LysIkx7rIExoNHJsxOAtPp4rthXw= golang.org/x/sys v0.46.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= -golang.org/x/text v0.38.0 h1:sXmwo9DwP3OK9EZ7PqAdaooSGozfl/3a6/xJcbzPRhE= -golang.org/x/text v0.38.0/go.mod h1:YXZt3QhHUKYT53r2lLKFIVi6Ao1jdzrTR/KQ09qyxF4= +golang.org/x/text v0.39.0 h1:UbZz4pLOvn600D6Oh6GGEI6VAmndrEBLv8/6BEXzyus= +golang.org/x/text v0.39.0/go.mod h1:3UwRclnC2g0TU9x8PZiyfOajCd1zaUNHF9cvqcQZ+ZM= gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4= gonum.org/v1/gonum v0.17.0/go.mod h1:El3tOrEuMpv2UdMrbNlKEh9vd86bmQ6vqIcDwxEOc1E= google.golang.org/genproto/googleapis/rpc v0.0.0-20260414002931-afd174a4e478 h1:RmoJA1ujG+/lRGNfUnOMfhCy5EipVMyvUE+KNbPbTlw= From d51d095b953d2433e265ab45a7cb4904ee7e45ab Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Fri, 24 Jul 2026 17:35:28 +0300 Subject: [PATCH 046/182] fix(deps): update module github.com/mattn/go-isatty to v0.0.23 (#6176) | datasource | package | from | to | | ---------- | -------------------------- | ------- | ------- | | go | github.com/mattn/go-isatty | v0.0.22 | v0.0.23 | Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 ++-- vendor/github.com/mattn/go-isatty/isatty_others.go | 4 ++-- vendor/modules.txt | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index b9a362087..496136849 100644 --- a/go.mod +++ b/go.mod @@ -30,7 +30,7 @@ require ( github.com/jhump/protoreflect v1.18.0 github.com/klauspost/compress v1.19.0 github.com/mattn/go-colorable v0.1.15 - github.com/mattn/go-isatty v0.0.22 + github.com/mattn/go-isatty v0.0.23 github.com/mccutchen/go-httpbin/v2 v2.24.0 github.com/mstoykov/atlas v0.0.0-20220811071828-388f114305dd github.com/mstoykov/envconfig v1.5.0 diff --git a/go.sum b/go.sum index 6d7f33df0..86e7b5820 100644 --- a/go.sum +++ b/go.sum @@ -131,8 +131,8 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0 github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/mattn/go-colorable v0.1.15 h1:+u9SLTRGnXv73cEsnsmoZBom+dMU88B2M0aDcWy0/jY= github.com/mattn/go-colorable v0.1.15/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8= -github.com/mattn/go-isatty v0.0.22 h1:j8l17JJ9i6VGPUFUYoTUKPSgKe/83EYU2zBC7YNKMw4= -github.com/mattn/go-isatty v0.0.22/go.mod h1:ZXfXG4SQHsB/w3ZeOYbR0PrPwLy+n6xiMrJlRFqopa4= +github.com/mattn/go-isatty v0.0.23 h1:cYwCQTQf3HB6xUC+BtyCLZNr7IzbOmoZbmssVNzSyiQ= +github.com/mattn/go-isatty v0.0.23/go.mod h1:nMCL3Zebbrt45jsMDgnfIwz6ydEQApk5oEI3HqDio6A= github.com/mccutchen/go-httpbin/v2 v2.24.0 h1:MZ5QSGVeVpg/c7ZRbIg8UVZvefeBn/NhSVTc1fCQFEQ= github.com/mccutchen/go-httpbin/v2 v2.24.0/go.mod h1:8hkN5rHf0QvJYEovZ8u/Dudtqyj6Z5gxQaW7scQfT0Y= github.com/mstoykov/atlas v0.0.0-20220811071828-388f114305dd h1:AC3N94irbx2kWGA8f/2Ks7EQl2LxKIRQYuT9IJDwgiI= diff --git a/vendor/github.com/mattn/go-isatty/isatty_others.go b/vendor/github.com/mattn/go-isatty/isatty_others.go index b24a2fadc..569113eac 100644 --- a/vendor/github.com/mattn/go-isatty/isatty_others.go +++ b/vendor/github.com/mattn/go-isatty/isatty_others.go @@ -1,5 +1,5 @@ -//go:build (appengine || js || nacl || tinygo || wasm || wasip1 || wasip2) && !windows -// +build appengine js nacl tinygo wasm wasip1 wasip2 +//go:build (appengine || js || nacl || tinygo || wasm || wasip1 || wasip2 || haiku) && !windows +// +build appengine js nacl tinygo wasm wasip1 wasip2 haiku // +build !windows package isatty diff --git a/vendor/modules.txt b/vendor/modules.txt index fbb8a92f2..747aca584 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -253,8 +253,8 @@ github.com/klauspost/compress/zstd/internal/xxhash # github.com/mattn/go-colorable v0.1.15 ## explicit; go 1.18 github.com/mattn/go-colorable -# github.com/mattn/go-isatty v0.0.22 -## explicit; go 1.21 +# github.com/mattn/go-isatty v0.0.23 +## explicit; go 1.20 github.com/mattn/go-isatty # github.com/mccutchen/go-httpbin/v2 v2.24.0 ## explicit; go 1.25.0 From d48e41ec37f6f175c24b458f4f6b1826c05a1663 Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Fri, 24 Jul 2026 17:35:41 +0300 Subject: [PATCH 047/182] chore(deps): update actions/checkout action to v7 (#6158) | datasource | package | from | to | | ----------- | ---------------- | ------ | ------ | | github-tags | actions/checkout | v6.1.0 | v7.0.1 | Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> --- .github/workflows/browser_e2e.yml | 2 +- .github/workflows/build.yml | 12 ++++++------ .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/feature-briefs.yml | 2 +- .github/workflows/lint.yml | 4 ++-- .github/workflows/packager.yml | 2 +- .github/workflows/summary-code-generation.yml | 2 +- .github/workflows/tc39.yml | 2 +- .github/workflows/test-browser.yml | 8 ++++---- .github/workflows/test.yml | 8 ++++---- .github/workflows/wpt.yml | 2 +- .github/workflows/xk6.yml | 2 +- 12 files changed, 24 insertions(+), 24 deletions(-) diff --git a/.github/workflows/browser_e2e.yml b/.github/workflows/browser_e2e.yml index 7a763eab1..49b38442a 100644 --- a/.github/workflows/browser_e2e.yml +++ b/.github/workflows/browser_e2e.yml @@ -30,7 +30,7 @@ jobs: runs-on: ${{ matrix.platform }} steps: - name: Checkout code - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: persist-credentials: false - name: Install Go diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8ae3da9a7..94bf6dd24 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -45,7 +45,7 @@ jobs: is_latest_in_major: ${{ steps.classify_release.outputs.is_latest_in_major }} steps: - name: Checkout code - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: fetch-depth: 0 persist-credentials: false @@ -154,7 +154,7 @@ jobs: VERSION: ${{ needs.configure.outputs.k6_version }} steps: - name: Checkout code - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: fetch-depth: 0 persist-credentials: false @@ -220,7 +220,7 @@ jobs: VERSION: ${{ needs.configure.outputs.k6_version }} steps: - name: Checkout code - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: fetch-depth: 0 persist-credentials: false @@ -434,7 +434,7 @@ jobs: VERSION: ${{ needs.configure.outputs.k6_version }} steps: - name: Checkout code - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: persist-credentials: false - name: Install pandoc @@ -541,7 +541,7 @@ jobs: contents: write steps: - name: Checkout code - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: persist-credentials: false - name: Download binaries @@ -635,7 +635,7 @@ jobs: id-token: write # Required for Vault steps: - name: Checkout code - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: persist-credentials: false - name: Download binaries diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 859a56815..560e1a417 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -15,7 +15,7 @@ jobs: steps: - name: Checkout repo - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: persist-credentials: false diff --git a/.github/workflows/feature-briefs.yml b/.github/workflows/feature-briefs.yml index cf97adb94..fead9838a 100644 --- a/.github/workflows/feature-briefs.yml +++ b/.github/workflows/feature-briefs.yml @@ -17,7 +17,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: persist-credentials: false fetch-depth: 0 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 03ca1c660..48efd3d6a 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -19,7 +19,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: persist-credentials: false fetch-depth: 0 @@ -45,7 +45,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: persist-credentials: false fetch-depth: 0 diff --git a/.github/workflows/packager.yml b/.github/workflows/packager.yml index 9ba1c31b0..ae5c06682 100644 --- a/.github/workflows/packager.yml +++ b/.github/workflows/packager.yml @@ -23,7 +23,7 @@ jobs: packages: write steps: - name: Checkout code - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: persist-credentials: false - name: Build diff --git a/.github/workflows/summary-code-generation.yml b/.github/workflows/summary-code-generation.yml index 3c4bb3bcb..a487f1579 100644 --- a/.github/workflows/summary-code-generation.yml +++ b/.github/workflows/summary-code-generation.yml @@ -18,7 +18,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: persist-credentials: false diff --git a/.github/workflows/tc39.yml b/.github/workflows/tc39.yml index df9fa954c..4546da6a7 100644 --- a/.github/workflows/tc39.yml +++ b/.github/workflows/tc39.yml @@ -24,7 +24,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: persist-credentials: false - name: Resolve Go versions diff --git a/.github/workflows/test-browser.yml b/.github/workflows/test-browser.yml index c481f2e53..a72e9d23f 100644 --- a/.github/workflows/test-browser.yml +++ b/.github/workflows/test-browser.yml @@ -23,7 +23,7 @@ jobs: go_prev: ${{ steps.go_versions.outputs.prev }} steps: - name: Checkout code - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: persist-credentials: false - name: Resolve Go versions @@ -42,7 +42,7 @@ jobs: runs-on: ${{ matrix.platform }} steps: - name: Checkout code - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: fetch-depth: 0 persist-credentials: false @@ -74,7 +74,7 @@ jobs: continue-on-error: true steps: - name: Checkout code - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: persist-credentials: false - name: Run common test steps @@ -99,7 +99,7 @@ jobs: runs-on: ${{ matrix.platform }} steps: - name: Checkout code - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: persist-credentials: false - name: Run common test steps diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e0304a61c..c1a3adc43 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,7 +23,7 @@ jobs: go_prev: ${{ steps.go_versions.outputs.prev }} steps: - name: Checkout code - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: persist-credentials: false - name: Resolve Go versions @@ -41,7 +41,7 @@ jobs: runs-on: ${{ matrix.platform }} steps: - name: Checkout code - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: fetch-depth: 0 persist-credentials: false @@ -69,7 +69,7 @@ jobs: continue-on-error: true steps: - name: Checkout code - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: persist-credentials: false - name: Run common test steps @@ -94,7 +94,7 @@ jobs: runs-on: ${{ matrix.platform }} steps: - name: Checkout code - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: persist-credentials: false - name: Run common test steps diff --git a/.github/workflows/wpt.yml b/.github/workflows/wpt.yml index d8d6a18e3..24b357ada 100644 --- a/.github/workflows/wpt.yml +++ b/.github/workflows/wpt.yml @@ -18,7 +18,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: persist-credentials: false - name: Resolve Go versions diff --git a/.github/workflows/xk6.yml b/.github/workflows/xk6.yml index 6a272081c..40f5b7e7f 100644 --- a/.github/workflows/xk6.yml +++ b/.github/workflows/xk6.yml @@ -27,7 +27,7 @@ jobs: runs-on: ${{ matrix.platform }} steps: - name: Checkout code - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: persist-credentials: false - name: Resolve Go versions From 5dce05d2c1517cb8ef6384486797c219278cf2a5 Mon Sep 17 00:00:00 2001 From: lukdz <19475662+lukdz@users.noreply.github.com> Date: Fri, 24 Jul 2026 16:50:13 +0200 Subject: [PATCH 048/182] fix: prevent OpenTelemetry output panic with basic auth and no headers (#6145) getExporter declared the headers map with 'var headers map[string]string', leaving it nil unless K6_OTEL_HEADERS was set. When basic auth was configured via K6_OTEL_HTTP_EXPORTER_USERNAME/PASSWORD but no headers were provided, assigning the Authorization header panicked with 'assignment to entry in nil map'. Initialize the map so basic auth works independently of K6_OTEL_HEADERS. Adds a regression test covering basic auth with/without headers for both the HTTP and gRPC exporters. --- internal/output/opentelemetry/exporter.go | 2 +- .../output/opentelemetry/exporter_test.go | 82 +++++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 internal/output/opentelemetry/exporter_test.go diff --git a/internal/output/opentelemetry/exporter.go b/internal/output/opentelemetry/exporter.go index 0738208c7..b1fbcd14c 100644 --- a/internal/output/opentelemetry/exporter.go +++ b/internal/output/opentelemetry/exporter.go @@ -31,7 +31,7 @@ func getExporter(cfg Config) (metric.Exporter, error) { return nil, err } - var headers map[string]string + headers := make(map[string]string) if cfg.Headers.Valid { headers, err = parseHeaders(cfg.Headers.String) if err != nil { diff --git a/internal/output/opentelemetry/exporter_test.go b/internal/output/opentelemetry/exporter_test.go new file mode 100644 index 000000000..3e684383c --- /dev/null +++ b/internal/output/opentelemetry/exporter_test.go @@ -0,0 +1,82 @@ +package opentelemetry + +import ( + "testing" + + "github.com/stretchr/testify/require" + "gopkg.in/guregu/null.v3" +) + +// TestGetExporterBasicAuth verifies that configuring HTTP Basic Auth via +// K6_OTEL_HTTP_EXPORTER_USERNAME/PASSWORD does not panic when no headers are +// configured through K6_OTEL_HEADERS. Previously the headers map was nil and +// assigning the Authorization header caused a "assignment to entry in nil map" +// panic. +func TestGetExporterBasicAuth(t *testing.T) { + t.Parallel() + + httpBase := func() Config { + return Config{ + ExporterProtocol: null.StringFrom(httpExporterProtocol), + HTTPExporterEndpoint: null.StringFrom("localhost:4318"), + HTTPExporterURLPath: null.StringFrom("/v1/metrics"), + } + } + + grpcBase := func() Config { + return Config{ + ExporterProtocol: null.StringFrom(grpcExporterProtocol), + GRPCExporterEndpoint: null.StringFrom("localhost:4317"), + } + } + + testCases := map[string]struct { + cfg func() Config + }{ + "http basic auth without headers": { + cfg: func() Config { + cfg := httpBase() + cfg.HTTPUsername = null.StringFrom("user") + cfg.HTTPPassword = null.StringFrom("pass") + return cfg + }, + }, + "http basic auth with headers": { + cfg: func() Config { + cfg := httpBase() + cfg.HTTPUsername = null.StringFrom("user") + cfg.HTTPPassword = null.StringFrom("pass") + cfg.Headers = null.StringFrom("X-Scope-OrgID=test") + return cfg + }, + }, + "http headers only": { + cfg: func() Config { + cfg := httpBase() + cfg.Headers = null.StringFrom("X-Scope-OrgID=test") + return cfg + }, + }, + "http no auth no headers": { + cfg: httpBase, + }, + "grpc basic auth without headers": { + cfg: func() Config { + cfg := grpcBase() + cfg.HTTPUsername = null.StringFrom("user") + cfg.HTTPPassword = null.StringFrom("pass") + return cfg + }, + }, + } + + for name, tc := range testCases { + t.Run(name, func(t *testing.T) { + t.Parallel() + + exporter, err := getExporter(tc.cfg()) + require.NoError(t, err) + require.NotNil(t, exporter) + }) + } +} From 41e2e6136465aa2de70cc892cca193813d45ed8a Mon Sep 17 00:00:00 2001 From: Luis Baronceli Date: Mon, 27 Jul 2026 20:18:35 +1200 Subject: [PATCH 049/182] feat: make handleSummary timeout configurable (#5854) --- internal/cmd/config.go | 3 + internal/cmd/tests/cmd_run_test.go | 66 ++++++++++++++++++- .../js/modules/k6/execution/execution_test.go | 2 +- internal/js/runner.go | 6 +- internal/js/summary_test.go | 17 +++-- internal/js/timeout_error.go | 3 + lib/options.go | 12 ++-- lib/options_test.go | 6 ++ 8 files changed, 101 insertions(+), 14 deletions(-) diff --git a/internal/cmd/config.go b/internal/cmd/config.go index cb8500f3e..617cdec15 100644 --- a/internal/cmd/config.go +++ b/internal/cmd/config.go @@ -311,6 +311,9 @@ func applyDefault(conf Config) Config { if !conf.TeardownTimeout.Valid { conf.TeardownTimeout.Duration = types.Duration(60 * time.Second) } + if !conf.HandleSummaryTimeout.Valid { + conf.HandleSummaryTimeout.Duration = types.Duration(120 * time.Second) + } return conf } diff --git a/internal/cmd/tests/cmd_run_test.go b/internal/cmd/tests/cmd_run_test.go index d75b5cee7..a87bca006 100644 --- a/internal/cmd/tests/cmd_run_test.go +++ b/internal/cmd/tests/cmd_run_test.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" "io" + "maps" "net/http" "net/http/httptest" "os" @@ -521,7 +522,7 @@ func TestExecutionTestOptionsDefaultValues(t *testing.T) { loglines := ts.LoggerHook.Drain() require.Len(t, loglines, 1) - expected := `{"paused":null,"executionSegment":null,"executionSegmentSequence":null,"noSetup":null,"setupTimeout":null,"noTeardown":null,"teardownTimeout":null,"rps":null,"dns":{"ttl":null,"select":null,"policy":null},"maxRedirects":null,"userAgent":null,"batch":null,"batchPerHost":null,"httpDebug":null,"insecureSkipTLSVerify":null,"tlsCipherSuites":null,"tlsVersion":null,"tlsAuth":null,"throw":null,"thresholds":null,"blacklistIPs":null,"blockHostnames":null,"hosts":null,"noConnectionReuse":null,"noVUConnectionReuse":null,"minIterationDuration":null,"ext":null,"summaryTrendStats":["avg", "min", "med", "max", "p(90)", "p(95)"],"summaryTimeUnit":null,"systemTags":["check","error","error_code","expected_response","group","method","name","proto","scenario","service","status","subproto","tls_version","url"],"tags":null,"metricSamplesBufferSize":null,"noCookiesReset":null,"discardResponseBodies":null,"consoleOutput":null,"scenarios":{"default":{"vus":null,"iterations":1,"executor":"shared-iterations","maxDuration":null,"startTime":null,"env":null,"tags":null,"gracefulStop":null,"exec":null}},"localIPs":null,"features":null}` + expected := `{"paused":null,"executionSegment":null,"executionSegmentSequence":null,"noSetup":null,"setupTimeout":null,"noTeardown":null,"teardownTimeout":null,"rps":null,"dns":{"ttl":null,"select":null,"policy":null},"maxRedirects":null,"userAgent":null,"batch":null,"batchPerHost":null,"httpDebug":null,"insecureSkipTLSVerify":null,"tlsCipherSuites":null,"tlsVersion":null,"tlsAuth":null,"throw":null,"thresholds":null,"blacklistIPs":null,"blockHostnames":null,"hosts":null,"noConnectionReuse":null,"noVUConnectionReuse":null,"minIterationDuration":null,"ext":null,"summaryTrendStats":["avg", "min", "med", "max", "p(90)", "p(95)"],"summaryTimeUnit":null,"systemTags":["check","error","error_code","expected_response","group","method","name","proto","scenario","service","status","subproto","tls_version","url"],"tags":null,"metricSamplesBufferSize":null,"noCookiesReset":null,"discardResponseBodies":null,"consoleOutput":null,"scenarios":{"default":{"vus":null,"iterations":1,"executor":"shared-iterations","maxDuration":null,"startTime":null,"env":null,"tags":null,"gracefulStop":null,"exec":null}},"localIPs":null,"handleSummaryTimeout":null,"features":null}` assert.JSONEq(t, expected, loglines[0].Message) } @@ -2537,6 +2538,69 @@ func TestSetupTimeout(t *testing.T) { assert.Contains(t, stderr, "setup() execution timed out after 1 seconds") } +func TestHandleSummaryTimeout(t *testing.T) { + t.Parallel() + + for _, tc := range []struct { + name string + env map[string]string + script string + }{ + { + name: "script option", + script: ` + import { sleep } from 'k6'; + + export const options = { + handleSummaryTimeout: '1s', + }; + + export function handleSummary(data) { + sleep(100000); + } + + export default function() {} + `, + }, + { + name: "environment variable", + env: map[string]string{ + "K6_HANDLE_SUMMARY_TIMEOUT": "1s", + }, + script: ` + import { sleep } from 'k6'; + + export function handleSummary(data) { + sleep(100000); + } + + export default function() {} + `, + }, + } { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + ts := NewGlobalTestState(t) + ts.CmdArgs = []string{"k6", "run", "-"} + maps.Copy(ts.Env, tc.env) + ts.Stdin = bytes.NewBufferString(tc.script) + + start := time.Now() + cmd.ExecuteWithGlobalState(ts.GlobalState) + elapsed := time.Since(start) + assert.Greater(t, elapsed, 1*time.Second, "expected more time to have passed because of handleSummaryTimeout") + assert.Less( + t, elapsed, 5*time.Second, + "expected less time to have passed because of handleSummaryTimeout", + ) + + stderr := ts.Stderr.String() + t.Log(stderr) + assert.Contains(t, stderr, "handleSummary() execution timed out after 1 seconds") + }) + } +} + func TestTypeScriptSupport(t *testing.T) { t.Parallel() depScript := ` diff --git a/internal/js/modules/k6/execution/execution_test.go b/internal/js/modules/k6/execution/execution_test.go index e23a6abd9..deae97ca6 100644 --- a/internal/js/modules/k6/execution/execution_test.go +++ b/internal/js/modules/k6/execution/execution_test.go @@ -287,7 +287,7 @@ func TestFailTest(t *testing.T) { func TestOptionsTestFull(t *testing.T) { t.Parallel() - expected := `{"paused":true,"scenarios":{"const-vus":{"executor":"constant-vus","options":{"browser":{"someOption":true}},"startTime":"10s","gracefulStop":"30s","env":{"FOO":"bar"},"exec":"default","tags":{"tagkey":"tagvalue"},"vus":50,"duration":"10m0s"}},"executionSegment":"0:1/4","executionSegmentSequence":"0,1/4,1/2,1","noSetup":true,"setupTimeout":"1m0s","noTeardown":true,"teardownTimeout":"5m0s","rps":100,"dns":{"ttl":"1m","select":"roundRobin","policy":"any"},"maxRedirects":3,"userAgent":"k6-user-agent","batch":15,"batchPerHost":5,"httpDebug":"full","insecureSkipTLSVerify":true,"tlsCipherSuites":["TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"],"tlsVersion":{"min":"tls1.2","max":"tls1.3"},"tlsAuth":[{"domains":["example.com"],"cert":"mycert.pem","key":"mycert-key.pem","password":"mypwd"}],"throw":true,"thresholds":{"http_req_duration":[{"threshold":"rate>0.01","abortOnFail":true,"delayAbortEval":"10s"}]},"blacklistIPs":["192.0.2.0/24"],"blockHostnames":["test.k6.io","*.example.com"],"hosts":{"test.k6.io":"1.2.3.4:8443"},"noConnectionReuse":true,"noVUConnectionReuse":true,"minIterationDuration":"10s","ext":{"ext-one":{"rawkey":"rawvalue"}},"summaryTrendStats":["avg","min","max"],"summaryTimeUnit":"ms","systemTags":["iter","vu"],"tags":null,"metricSamplesBufferSize":8,"noCookiesReset":true,"discardResponseBodies":true,"consoleOutput":"loadtest.log","tags":{"runtag-key":"runtag-value"},"localIPs":"192.168.20.12-192.168.20.15,192.168.10.0/27","features":null}` + expected := `{"paused":true,"scenarios":{"const-vus":{"executor":"constant-vus","options":{"browser":{"someOption":true}},"startTime":"10s","gracefulStop":"30s","env":{"FOO":"bar"},"exec":"default","tags":{"tagkey":"tagvalue"},"vus":50,"duration":"10m0s"}},"executionSegment":"0:1/4","executionSegmentSequence":"0,1/4,1/2,1","noSetup":true,"setupTimeout":"1m0s","noTeardown":true,"teardownTimeout":"5m0s","rps":100,"dns":{"ttl":"1m","select":"roundRobin","policy":"any"},"maxRedirects":3,"userAgent":"k6-user-agent","batch":15,"batchPerHost":5,"httpDebug":"full","insecureSkipTLSVerify":true,"tlsCipherSuites":["TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"],"tlsVersion":{"min":"tls1.2","max":"tls1.3"},"tlsAuth":[{"domains":["example.com"],"cert":"mycert.pem","key":"mycert-key.pem","password":"mypwd"}],"throw":true,"thresholds":{"http_req_duration":[{"threshold":"rate>0.01","abortOnFail":true,"delayAbortEval":"10s"}]},"blacklistIPs":["192.0.2.0/24"],"blockHostnames":["test.k6.io","*.example.com"],"hosts":{"test.k6.io":"1.2.3.4:8443"},"noConnectionReuse":true,"noVUConnectionReuse":true,"minIterationDuration":"10s","ext":{"ext-one":{"rawkey":"rawvalue"}},"handleSummaryTimeout":null,"summaryTrendStats":["avg","min","max"],"summaryTimeUnit":"ms","systemTags":["iter","vu"],"tags":null,"metricSamplesBufferSize":8,"noCookiesReset":true,"discardResponseBodies":true,"consoleOutput":"loadtest.log","tags":{"runtag-key":"runtag-value"},"localIPs":"192.168.20.12-192.168.20.15,192.168.10.0/27","features":null}` var ( rt = sobek.New() diff --git a/internal/js/runner.go b/internal/js/runner.go index fd8a7c70e..a1c0bf1a1 100644 --- a/internal/js/runner.go +++ b/internal/js/runner.go @@ -396,6 +396,10 @@ func (r *Runner) HandleSummary( return nil, err } + if deadlineError := r.checkDeadline(summaryCtx, consts.HandleSummaryFn, nil, nil); deadlineError != nil { + return nil, deadlineError + } + wrapper := strings.Replace(summaryWrapperLambdaCode, "/*JSLIB_SUMMARY_CODE*/", summaryCode, 1) handleSummaryWrapperRaw, err := vu.Runtime.RunString(wrapper) if err != nil { @@ -692,7 +696,7 @@ func (r *Runner) getTimeoutFor(stage string) time.Duration { case consts.TeardownFn: return r.Bundle.Options.TeardownTimeout.TimeDuration() case consts.HandleSummaryFn: - return 2 * time.Minute // TODO: make configurable + return r.Bundle.Options.HandleSummaryTimeout.TimeDuration() } return d } diff --git a/internal/js/summary_test.go b/internal/js/summary_test.go index b8a7e138b..bad2718ea 100644 --- a/internal/js/summary_test.go +++ b/internal/js/summary_test.go @@ -54,7 +54,7 @@ func TestTextSummary(t *testing.T) { runner, err := getSimpleRunner( t, "/script.js", fmt.Sprintf(` - exports.options = {summaryTrendStats: %s}; + exports.options = {handleSummaryTimeout: "2m", summaryTrendStats: %s}; exports.default = function() {/* we don't run this, metrics are mocked */}; `, string(trendStats)), lib.RuntimeOptions{CompatibilityMode: null.NewString("base", true)}, @@ -110,7 +110,8 @@ func TestTextSummaryWithSubMetrics(t *testing.T) { runner, err := getSimpleRunner( t, "/script.js", - "exports.default = function() {/* we don't run this, metrics are mocked */};", + `exports.options = {handleSummaryTimeout: "2m"}; + exports.default = function() {/* we don't run this, metrics are mocked */};`, lib.RuntimeOptions{CompatibilityMode: null.NewString("base", true)}, ) require.NoError(t, err) @@ -294,7 +295,7 @@ func TestOldJSONExport(t *testing.T) { runner, err := getSimpleRunner( t, "/script.js", ` - exports.options = {summaryTrendStats: ["avg", "min", "med", "max", "p(90)", "p(95)", "p(99)", "count"]}; + exports.options = {handleSummaryTimeout: "2m", summaryTrendStats: ["avg", "min", "med", "max", "p(90)", "p(95)", "p(99)", "count"]}; exports.default = function() {/* we don't run this, metrics are mocked */}; `, lib.RuntimeOptions{ @@ -560,7 +561,7 @@ func TestRawHandleSummaryData(t *testing.T) { runner, err := getSimpleRunner( t, "/script.js", ` - exports.options = {summaryTrendStats: ["avg", "min", "med", "max", "p(90)", "p(95)", "p(99)", "count"]}; + exports.options = {handleSummaryTimeout: "2m", summaryTrendStats: ["avg", "min", "med", "max", "p(90)", "p(95)", "p(99)", "count"]}; exports.default = function() { /* we don't run this, metrics are mocked */ }; exports.handleSummary = function(data) { return {'rawdata.json': JSON.stringify(data)}; @@ -597,7 +598,7 @@ func TestRawHandleSummaryDataWithSetupData(t *testing.T) { runner, err := getSimpleRunner( t, "/script.js", ` - exports.options = {summaryTrendStats: ["avg", "min", "med", "max", "p(90)", "p(95)", "p(99)", "count"]}; + exports.options = {handleSummaryTimeout: "2m", summaryTrendStats: ["avg", "min", "med", "max", "p(90)", "p(95)", "p(99)", "count"]}; exports.default = function() { /* we don't run this, metrics are mocked */ }; exports.handleSummary = function(data) { if(data.setup_data != 5) { @@ -623,7 +624,7 @@ func TestRawHandleSummaryPromise(t *testing.T) { runner, err := getSimpleRunner( t, "/script.js", ` - exports.options = {summaryTrendStats: ["avg", "min", "med", "max", "p(90)", "p(95)", "p(99)", "count"]}; + exports.options = {handleSummaryTimeout: "2m", summaryTrendStats: ["avg", "min", "med", "max", "p(90)", "p(95)", "p(99)", "count"]}; exports.default = function() { /* we don't run this, metrics are mocked */ }; exports.handleSummary = async function(data) { return await Promise.resolve({'dataWithSetup.json': JSON.stringify(data)}); @@ -650,6 +651,7 @@ func TestWrongSummaryHandlerExportTypes(t *testing.T) { t.Parallel() runner, err := getSimpleRunner(t, "/script.js", fmt.Sprintf(` + exports.options = {handleSummaryTimeout: "2m"}; exports.default = function() { /* we don't run this, metrics are mocked */ }; exports.handleSummary = %s; `, tc), @@ -673,6 +675,7 @@ func TestExceptionInHandleSummaryFallsBackToTextSummary(t *testing.T) { logger.AddHook(logHook) runner, err := getSimpleRunner(t, "/script.js", ` + exports.options = {handleSummaryTimeout: "2m"}; exports.default = function() {/* we don't run this, metrics are mocked */}; exports.handleSummary = function(data) { throw new Error('intentional error'); @@ -696,6 +699,6 @@ func TestExceptionInHandleSummaryFallsBackToTextSummary(t *testing.T) { assert.Equal(t, 1, len(logErrors)) errMsg, err := logErrors[0].String() require.NoError(t, err) - assert.Contains(t, errMsg, "\"Error: intentional error\\n\\tat file:///script.js:4:11(3)\\n") + assert.Contains(t, errMsg, "\"Error: intentional error\\n\\tat file:///script.js:5:11(3)\\n") assert.Equal(t, logrus.Fields{"hint": "script exception", "source": "stacktrace"}, logErrors[0].Data) } diff --git a/internal/js/timeout_error.go b/internal/js/timeout_error.go index 0e2bac596..eb3178121 100644 --- a/internal/js/timeout_error.go +++ b/internal/js/timeout_error.go @@ -41,6 +41,9 @@ func (t timeoutError) Hint() string { hint = "You can increase the time limit via the setupTimeout option" case consts.TeardownFn: hint = "You can increase the time limit via the teardownTimeout option" + case consts.HandleSummaryFn: + hint = "You can increase the time limit via the handleSummaryTimeout option" + + " or the K6_HANDLE_SUMMARY_TIMEOUT environment variable" } return hint } diff --git a/lib/options.go b/lib/options.go index c03d4e379..2f33a9ec8 100644 --- a/lib/options.go +++ b/lib/options.go @@ -249,10 +249,11 @@ type Options struct { ExecutionSegmentSequence *ExecutionSegmentSequence `json:"executionSegmentSequence" ignored:"true"` // Timeouts for the setup() and teardown() functions - NoSetup null.Bool `json:"noSetup" envconfig:"K6_NO_SETUP"` - SetupTimeout types.NullDuration `json:"setupTimeout" envconfig:"K6_SETUP_TIMEOUT"` - NoTeardown null.Bool `json:"noTeardown" envconfig:"K6_NO_TEARDOWN"` - TeardownTimeout types.NullDuration `json:"teardownTimeout" envconfig:"K6_TEARDOWN_TIMEOUT"` + NoSetup null.Bool `json:"noSetup" envconfig:"K6_NO_SETUP"` + SetupTimeout types.NullDuration `json:"setupTimeout" envconfig:"K6_SETUP_TIMEOUT"` + NoTeardown null.Bool `json:"noTeardown" envconfig:"K6_NO_TEARDOWN"` + TeardownTimeout types.NullDuration `json:"teardownTimeout" envconfig:"K6_TEARDOWN_TIMEOUT"` + HandleSummaryTimeout types.NullDuration `json:"handleSummaryTimeout" envconfig:"K6_HANDLE_SUMMARY_TIMEOUT"` // Limit HTTP requests per second. RPS null.Int `json:"rps" envconfig:"K6_RPS"` @@ -421,6 +422,9 @@ func (o Options) Apply(opts Options) Options { if opts.TeardownTimeout.Valid { o.TeardownTimeout = opts.TeardownTimeout } + if opts.HandleSummaryTimeout.Valid { + o.HandleSummaryTimeout = opts.HandleSummaryTimeout + } if opts.RPS.Valid { o.RPS = opts.RPS } diff --git a/lib/options_test.go b/lib/options_test.go index d543db3a0..3d24e935f 100644 --- a/lib/options_test.go +++ b/lib/options_test.go @@ -659,6 +659,12 @@ func TestOptionsEnv(t *testing.T) { "true": null.BoolFrom(true), "false": null.BoolFrom(false), }, + {"HandleSummaryTimeout", "K6_HANDLE_SUMMARY_TIMEOUT"}: { + "": types.NullDuration{}, + "10s": types.NullDurationFrom(10 * time.Second), + "3m": types.NullDurationFrom(3 * time.Minute), + "300s": types.NullDurationFrom(300 * time.Second), + }, // Thresholds // External } From 131c99f57374018852a33a7752c26300d2a282f5 Mon Sep 17 00:00:00 2001 From: Solaris-star <67425364+Solaris-star@users.noreply.github.com> Date: Mon, 27 Jul 2026 16:40:53 +0800 Subject: [PATCH 050/182] Fix GaugeSink maximum for negative samples (#6195) Closes #6181 --- metrics/sink.go | 2 +- metrics/sink_test.go | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/metrics/sink.go b/metrics/sink.go index e39931040..8da906924 100644 --- a/metrics/sink.go +++ b/metrics/sink.go @@ -90,7 +90,7 @@ func (g *GaugeSink) IsEmpty() bool { return !g.minSet } // Add a single sample to the sink func (g *GaugeSink) Add(s Sample) { g.Value = s.Value - if s.Value > g.Max { + if s.Value > g.Max || !g.minSet { g.Max = s.Value } if s.Value < g.Min || !g.minSet { diff --git a/metrics/sink_test.go b/metrics/sink_test.go index 7183ea143..f3a934b0c 100644 --- a/metrics/sink_test.go +++ b/metrics/sink_test.go @@ -80,6 +80,16 @@ func TestGaugeSink(t *testing.T) { assert.Equal(t, true, sink.minSet) assert.Equal(t, 1.0, sink.Max) }) + t.Run("negative values", func(t *testing.T) { + t.Parallel() + sink := GaugeSink{} + for _, s := range []float64{-5.0, -3.0, -8.0} { + sink.Add(Sample{TimeSeries: TimeSeries{Metric: &Metric{}}, Value: s}) + } + assert.Equal(t, -8.0, sink.Value) + assert.Equal(t, -8.0, sink.Min) + assert.Equal(t, -3.0, sink.Max) + }) t.Run("values", func(t *testing.T) { t.Parallel() sink := GaugeSink{} From 0521027446d6f00d99724f3d05e37a0493ade491 Mon Sep 17 00:00:00 2001 From: Lohit Kolluri Date: Mon, 27 Jul 2026 14:18:31 +0530 Subject: [PATCH 051/182] fix: freeze __ENV to prevent modification from JS code (#6032) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: freeze __ENV to prevent modification from JS code Make __ENV a frozen, read-only object in user scripts. Extract shared helper used by bundle and runner setup. Signed-off-by: Lohit Kolluri * feat(features): gate __ENV freeze behind freeze-env flag Put the frozen __ENV behavior behind an experimental feature flag so it can land before v3.0.0 without breaking existing scripts. - Added FreezeEnv field to features.Flags (lifecycle: experimental) - setupEnvObject dispatches between frozen and mutable env based on the flag - Tests that expect frozen __ENV explicitly enable the flag Signed-off-by: Lohit Kolluri --------- Signed-off-by: Lohit Kolluri Co-authored-by: Théo Crevon --- internal/execution/scheduler_ext_test.go | 4 +-- internal/features/features.go | 1 + internal/js/bundle.go | 7 ++--- internal/js/bundle_test.go | 35 ++++++++++++---------- internal/js/env.go | 37 ++++++++++++++++++++++++ internal/js/runner.go | 8 +++-- 6 files changed, 68 insertions(+), 24 deletions(-) create mode 100644 internal/js/env.go diff --git a/internal/execution/scheduler_ext_test.go b/internal/execution/scheduler_ext_test.go index 0a9814222..d69caea48 100644 --- a/internal/execution/scheduler_ext_test.go +++ b/internal/execution/scheduler_ext_test.go @@ -579,8 +579,8 @@ func TestSchedulerRunCustomConfigNoCrossover(t *testing.T) { checkVar('TESTVAR3', undefined); checkVar('TESTGLOBALVAR', 'global'); - // Intentionally try to pollute the env - __ENV.TESTVAR2 = 'overridden'; + // Intentionally try to pollute the env (will be silently rejected since __ENV is frozen) + try { __ENV.TESTVAR2 = 'overridden'; } catch (e) { /* __ENV is frozen */ } http.get('HTTPBIN_IP_URL/', { tags: { reqtag: 'scenario1' }}); } diff --git a/internal/features/features.go b/internal/features/features.go index 74b8d6616..b609c4ba3 100644 --- a/internal/features/features.go +++ b/internal/features/features.go @@ -43,6 +43,7 @@ func (l Lifecycle) String() string { type Flags struct { NativeHistograms bool `lifecycle:"experimental" help:"Use native histograms for trend metrics"` MergeRunTags bool `lifecycle:"experimental" help:"Merge run tags across config layers instead of replacing"` + FreezeEnv bool `lifecycle:"experimental" help:"Freeze __ENV object to prevent modifications from JS code"` _ noCopy activated []string } diff --git a/internal/js/bundle.go b/internal/js/bundle.go index b1a2ab2b7..03f642078 100644 --- a/internal/js/bundle.go +++ b/internal/js/bundle.go @@ -412,12 +412,11 @@ func (b *Bundle) setupJSRuntime(rt *sobek.Runtime, vuID uint64, logger logrus.Fi rt.SetFieldNameMapper(common.FieldNameMapper{}) rt.SetRandSource(common.NewRandSource()) - env := make(map[string]string, len(b.preInitState.RuntimeOptions.Env)) - maps.Copy(env, b.preInitState.RuntimeOptions.Env) - err := rt.Set("__ENV", env) - if err != nil { + if err := setupEnvObject(rt, b.preInitState.RuntimeOptions.Env, b.preInitState.FeatureFlags); err != nil { return err } + + var err error err = rt.Set("__VU", vuID) if err != nil { return err diff --git a/internal/js/bundle_test.go b/internal/js/bundle_test.go index 156cc8983..ea8d8761b 100644 --- a/internal/js/bundle_test.go +++ b/internal/js/bundle_test.go @@ -20,6 +20,7 @@ import ( "gopkg.in/guregu/null.v3" "go.k6.io/k6/v2/internal/build" + "go.k6.io/k6/v2/internal/features" "go.k6.io/k6/v2/internal/lib/consts" "go.k6.io/k6/v2/internal/lib/testutils" "go.k6.io/k6/v2/internal/loader" @@ -55,6 +56,7 @@ func getSimpleBundle(tb testing.TB, filename, data string, opts ...any) (*Bundle fs := fsext.NewMemMapFs() var rtOpts *lib.RuntimeOptions var logger logrus.FieldLogger + var ff *features.Flags for _, o := range opts { switch opt := o.(type) { case fsext.Fs: @@ -63,11 +65,14 @@ func getSimpleBundle(tb testing.TB, filename, data string, opts ...any) (*Bundle rtOpts = &opt case logrus.FieldLogger: logger = opt + case *features.Flags: + ff = opt default: tb.Fatalf("unknown test option %q", opt) } } preInitState := getTestPreInitState(tb, logger, rtOpts) + preInitState.FeatureFlags = ff filenameURL := &url.URL{Path: filename, Scheme: "file"} @@ -88,17 +93,21 @@ func getSimpleBundleFromArchive(tb testing.TB, arc *lib.Archive, opts ...any) (* tb.Helper() var rtOpts *lib.RuntimeOptions var logger logrus.FieldLogger + var ff *features.Flags for _, o := range opts { switch opt := o.(type) { case lib.RuntimeOptions: rtOpts = &opt case logrus.FieldLogger: logger = opt + case *features.Flags: + ff = opt default: tb.Fatalf("unknown test option %q", opt) } } preInitState := getTestPreInitState(tb, logger, rtOpts) + preInitState.FeatureFlags = ff fss := arc.Filesystems moduleResolver := NewModuleResolver(arc.PwdURL, preInitState, fss) @@ -904,36 +913,32 @@ func TestBundleNotSharable(t *testing.T) { t.Parallel() data := ` export default function() { - if (__ITER == 0) { - if (typeof __ENV.something !== "undefined") { - throw new Error("invalid something: " + __ENV.something + " should be undefined"); - } - __ENV.something = __VU; - } else if (__ENV.something != __VU) { - throw new Error("invalid something: " + __ENV.something+ " should be "+ __VU); + if (typeof __ENV.something !== "undefined") { + throw new Error("invalid something: " + __ENV.something + " should be undefined"); + } + try { __ENV.something = __VU; throw new Error("should have frozen __ENV"); } catch (e) { + if (!(e instanceof TypeError)) { throw e; } } } ` - b1, err := getSimpleBundle(t, "/script.js", data) + ff := &features.Flags{FreezeEnv: true} + b1, err := getSimpleBundle(t, "/script.js", data, ff) require.NoError(t, err) logger := testutils.NewLogger(t) - b2, err := getSimpleBundleFromArchive(t, b1.makeArchive(), logger) + b2, err := getSimpleBundleFromArchive(t, b1.makeArchive(), logger, ff) require.NoError(t, err) bundles := map[string]*Bundle{"Source": b1, "Archive": b2} - var vus, iters uint64 = 10, 1000 + var vus uint64 = 10 for name, b := range bundles { t.Run(name, func(t *testing.T) { t.Parallel() for i := range vus { bi, err := b.Instantiate(context.Background(), i) require.NoError(t, err) - for j := range iters { - require.NoError(t, bi.Runtime.Set("__ITER", j)) - _, err := bi.getCallableExport(consts.DefaultFn)(sobek.Undefined()) - require.NoError(t, err) - } + _, err = bi.getCallableExport(consts.DefaultFn)(sobek.Undefined()) + require.NoError(t, err) } }) } diff --git a/internal/js/env.go b/internal/js/env.go new file mode 100644 index 000000000..cd9860ced --- /dev/null +++ b/internal/js/env.go @@ -0,0 +1,37 @@ +package js + +import ( + "fmt" + "maps" + + "github.com/grafana/sobek" + + "go.k6.io/k6/v2/internal/features" + "go.k6.io/k6/v2/js/common" +) + +// setupEnvObject configures the global __ENV object on the given runtime. +// When freeze is true, each property is defined as non-writable, non-configurable +// and the object is frozen so assignments like __ENV.foo = "bar" are rejected. +// When freeze is false, the old mutable map behavior is used (default). +func setupEnvObject(rt *sobek.Runtime, env map[string]string, flags *features.Flags) error { + if flags != nil && flags.FreezeEnv { + envObj := rt.NewObject() + for k, v := range env { + if err := envObj.DefineDataProperty( + k, rt.ToValue(v), sobek.FLAG_FALSE, sobek.FLAG_FALSE, sobek.FLAG_TRUE, + ); err != nil { + return fmt.Errorf("setting __ENV property %s: %w", k, err) + } + } + if err := common.FreezeObject(rt, envObj); err != nil { + return fmt.Errorf("freezing __ENV: %w", err) + } + return rt.Set("__ENV", envObj) + } + + // Old behavior: mutable map + envMap := make(map[string]string, len(env)) + maps.Copy(envMap, env) + return rt.Set("__ENV", envMap) +} diff --git a/internal/js/runner.go b/internal/js/runner.go index a1c0bf1a1..2dee13099 100644 --- a/internal/js/runner.go +++ b/internal/js/runner.go @@ -756,12 +756,14 @@ func (u *VU) Activate(params *lib.VUActivationParams) lib.ActiveVU { params.Exec = consts.DefaultFn } - // Override the preset global env with any custom env vars + // Override the preset global env with any custom env vars. + // __ENV is frozen when the freeze-env feature flag is active. env := make(map[string]string, len(u.env)+len(params.Env)) maps.Copy(env, u.env) maps.Copy(env, params.Env) - //nolint:errcheck,gosec // see https://github.com/grafana/k6/issues/1722#issuecomment-1761173634 - u.Runtime.Set("__ENV", env) + if err := setupEnvObject(u.Runtime, env, u.Runner.preInitState.FeatureFlags); err != nil { + panic(err) // should not happen with string values + } opts := u.Runner.Bundle.Options From 035fd73089ed5456f54a854cc97eb4ca9ac98507 Mon Sep 17 00:00:00 2001 From: Dean Chen <51218137+locker95@users.noreply.github.com> Date: Mon, 27 Jul 2026 14:07:34 +0500 Subject: [PATCH 052/182] examples/browser: add catch blocks for clearer error UX (#6196) Add try/catch/finally with fail() to browser examples so the original error is reported instead of being masked by cleanup in finally. Matches the pattern used by the k6 browser script template. Fixes #4389 Signed-off-by: Dean Chen <862469039@qq.com> --- examples/browser/colorscheme.js | 3 +++ examples/browser/cookies.js | 3 +++ examples/browser/device_emulation.js | 3 +++ examples/browser/dispatch.js | 3 +++ examples/browser/evaluate.js | 3 +++ examples/browser/fillform.js | 3 +++ examples/browser/framelocator.js | 4 +++- examples/browser/getattribute.js | 3 +++ examples/browser/grant_permission.js | 3 +++ examples/browser/hosts.js | 3 +++ examples/browser/locator.js | 3 +++ examples/browser/locator_pom.js | 3 +++ examples/browser/multiple-scenario.js | 5 +++++ examples/browser/page_waitForEvent.js | 3 +++ examples/browser/pageon-metric.js | 3 +++ examples/browser/pageon.js | 3 +++ examples/browser/querying.js | 3 +++ examples/browser/route.js | 4 +++- examples/browser/route_continue.js | 4 +++- examples/browser/screenshot.js | 3 +++ examples/browser/throttle.js | 7 +++++++ examples/browser/waitforfunction.js | 3 +++ 22 files changed, 72 insertions(+), 3 deletions(-) diff --git a/examples/browser/colorscheme.js b/examples/browser/colorscheme.js index 4141f0909..219310d62 100644 --- a/examples/browser/colorscheme.js +++ b/examples/browser/colorscheme.js @@ -1,4 +1,5 @@ import { browser } from 'k6/browser'; +import { fail } from 'k6'; import { check } from 'https://jslib.k6.io/k6-utils/1.5.0/index.js'; export const options = { @@ -33,6 +34,8 @@ export default async function() { 'isDarkColorScheme': p => p.evaluate(() => window.matchMedia('(prefers-color-scheme: dark)').matches) }); + } catch (error) { + fail(`Browser iteration failed: ${error.message}`); } finally { await page.close(); } diff --git a/examples/browser/cookies.js b/examples/browser/cookies.js index 48f588b60..3d4d01a83 100644 --- a/examples/browser/cookies.js +++ b/examples/browser/cookies.js @@ -1,4 +1,5 @@ import { browser } from 'k6/browser'; +import { fail } from 'k6'; import { check } from 'https://jslib.k6.io/k6-utils/1.5.0/index.js'; export const options = { @@ -120,6 +121,8 @@ export default async function () { await check(await context.cookies(), { 'number of cookies should be zero': c => c.length === 0, }); + } catch (error) { + fail(`Browser iteration failed: ${error.message}`); } finally { await page.close(); } diff --git a/examples/browser/device_emulation.js b/examples/browser/device_emulation.js index 7e62ab26a..ed4db21c0 100644 --- a/examples/browser/device_emulation.js +++ b/examples/browser/device_emulation.js @@ -1,4 +1,5 @@ import { browser, devices } from 'k6/browser'; +import { fail } from 'k6'; import { check } from 'https://jslib.k6.io/k6-utils/1.5.0/index.js'; export const options = { @@ -45,6 +46,8 @@ export default async function() { if (!__ENV.K6_BROWSER_HEADLESS) { await page.waitForTimeout(10000); } + } catch (error) { + fail(`Browser iteration failed: ${error.message}`); } finally { await page.close(); } diff --git a/examples/browser/dispatch.js b/examples/browser/dispatch.js index 5c12bc327..f77e59273 100644 --- a/examples/browser/dispatch.js +++ b/examples/browser/dispatch.js @@ -1,4 +1,5 @@ import { browser } from 'k6/browser'; +import { fail } from 'k6'; import { check } from 'https://jslib.k6.io/k6-utils/1.5.0/index.js'; export const options = { @@ -33,6 +34,8 @@ export default async function() { return text == 'Contact us'; } }); + } catch (error) { + fail(`Browser iteration failed: ${error.message}`); } finally { await page.close(); } diff --git a/examples/browser/evaluate.js b/examples/browser/evaluate.js index 6801adf83..7924204a3 100644 --- a/examples/browser/evaluate.js +++ b/examples/browser/evaluate.js @@ -1,4 +1,5 @@ import { browser } from 'k6/browser'; +import { fail } from 'k6'; import { check } from 'https://jslib.k6.io/k6-utils/1.5.0/index.js'; export const options = { @@ -39,6 +40,8 @@ export default async function() { return n == 25; } }); + } catch (error) { + fail(`Browser iteration failed: ${error.message}`); } finally { await page.close(); } diff --git a/examples/browser/fillform.js b/examples/browser/fillform.js index c3cf6cfb1..73f45b9eb 100644 --- a/examples/browser/fillform.js +++ b/examples/browser/fillform.js @@ -1,4 +1,5 @@ import { browser } from 'k6/browser'; +import { fail } from 'k6'; import { check } from 'https://jslib.k6.io/k6-utils/1.5.0/index.js'; export const options = { @@ -54,6 +55,8 @@ export default async function() { return cookies.find(c => c.name == 'AWSALB') !== undefined; } }); + } catch (error) { + fail(`Browser iteration failed: ${error.message}`); } finally { await page.close(); } diff --git a/examples/browser/framelocator.js b/examples/browser/framelocator.js index d12c4685a..2231a06e3 100644 --- a/examples/browser/framelocator.js +++ b/examples/browser/framelocator.js @@ -1,5 +1,5 @@ import { browser } from 'k6/browser'; -import { check } from 'k6'; +import { check, fail } from 'k6'; export const options = { scenarios: { @@ -65,6 +65,8 @@ export default async function () { 'found heading inside iframe': (text) => text === 'Inside iframe', }); + } catch (error) { + fail(`Browser iteration failed: ${error.message}`); } finally { await page.close(); } diff --git a/examples/browser/getattribute.js b/examples/browser/getattribute.js index 57dcbc1e3..80db83272 100644 --- a/examples/browser/getattribute.js +++ b/examples/browser/getattribute.js @@ -1,4 +1,5 @@ import { browser } from 'k6/browser'; +import { fail } from 'k6'; import { check } from 'https://jslib.k6.io/k6-utils/1.5.0/index.js'; export const options = { @@ -31,6 +32,8 @@ export default async function() { return await e.getAttribute('mode') === 'light'; } }); + } catch (error) { + fail(`Browser iteration failed: ${error.message}`); } finally { await page.close(); } diff --git a/examples/browser/grant_permission.js b/examples/browser/grant_permission.js index d306e226e..c2fdfbabd 100644 --- a/examples/browser/grant_permission.js +++ b/examples/browser/grant_permission.js @@ -1,4 +1,5 @@ import { browser } from 'k6/browser'; +import { fail } from 'k6'; export const options = { scenarios: { @@ -29,6 +30,8 @@ export default async function() { await page.goto('https://quickpizza.grafana.com/test.k6.io/'); await page.screenshot({ path: `example-chromium.png` }); await context.clearPermissions(); + } catch (error) { + fail(`Browser iteration failed: ${error.message}`); } finally { await page.close(); } diff --git a/examples/browser/hosts.js b/examples/browser/hosts.js index 4baf41477..48d22c39f 100644 --- a/examples/browser/hosts.js +++ b/examples/browser/hosts.js @@ -1,4 +1,5 @@ import { browser } from 'k6/browser'; +import { fail } from 'k6'; import { check } from 'https://jslib.k6.io/k6-utils/1.5.0/index.js'; export const options = { @@ -29,6 +30,8 @@ export default async function() { await check(res, { 'null response': r => r === null, }); + } catch (error) { + fail(`Browser iteration failed: ${error.message}`); } finally { await page.close(); } diff --git a/examples/browser/locator.js b/examples/browser/locator.js index b5d9c0860..424d7eee0 100644 --- a/examples/browser/locator.js +++ b/examples/browser/locator.js @@ -1,4 +1,5 @@ import { browser } from 'k6/browser'; +import { fail } from 'k6'; export const options = { scenarios: { @@ -68,6 +69,8 @@ export default async function() { tails.click(), ]); console.log(await currentBet.innerText()); + } catch (error) { + fail(`Browser iteration failed: ${error.message}`); } finally { await page.close(); } diff --git a/examples/browser/locator_pom.js b/examples/browser/locator_pom.js index 6be6e20c9..ccab2c69c 100644 --- a/examples/browser/locator_pom.js +++ b/examples/browser/locator_pom.js @@ -1,4 +1,5 @@ import { browser } from 'k6/browser'; +import { fail } from 'k6'; export const options = { scenarios: { @@ -71,6 +72,8 @@ export default async function() { console.log("Current bet:", await bet.current()); await bet.heads(); console.log("Current bet:", await bet.current()); + } catch (error) { + fail(`Browser iteration failed: ${error.message}`); } finally { await page.close(); } diff --git a/examples/browser/multiple-scenario.js b/examples/browser/multiple-scenario.js index d050e3203..bba8b9cfe 100644 --- a/examples/browser/multiple-scenario.js +++ b/examples/browser/multiple-scenario.js @@ -1,4 +1,5 @@ import { browser } from 'k6/browser'; +import { fail } from 'k6'; export const options = { scenarios: { @@ -37,6 +38,8 @@ export async function messages() { try { await page.goto('https://quickpizza.grafana.com/my_messages.php', { waitUntil: 'networkidle' }); + } catch (error) { + fail(`Browser iteration failed: ${error.message}`); } finally { await page.close(); } @@ -47,6 +50,8 @@ export async function news() { try { await page.goto('https://quickpizza.grafana.com/news.php', { waitUntil: 'networkidle' }); + } catch (error) { + fail(`Browser iteration failed: ${error.message}`); } finally { await page.close(); } diff --git a/examples/browser/page_waitForEvent.js b/examples/browser/page_waitForEvent.js index 2424328ee..73bc9ef6d 100644 --- a/examples/browser/page_waitForEvent.js +++ b/examples/browser/page_waitForEvent.js @@ -1,4 +1,5 @@ import { browser } from 'k6/browser'; +import { fail } from 'k6'; export const options = { scenarios: { @@ -40,6 +41,8 @@ export default async function() { const response = await responsePromise; console.log(`Response received: ${response.url()}`); + } catch (error) { + fail(`Browser iteration failed: ${error.message}`); } finally { await page.close(); } diff --git a/examples/browser/pageon-metric.js b/examples/browser/pageon-metric.js index e50d6326c..22eff4ab1 100644 --- a/examples/browser/pageon-metric.js +++ b/examples/browser/pageon-metric.js @@ -1,4 +1,5 @@ import { browser } from 'k6/browser'; +import { fail } from 'k6'; export const options = { scenarios: { @@ -28,6 +29,8 @@ export default async function() { try { await page.goto('https://quickpizza.grafana.com/test.k6.io/?q=abc123'); await page.goto('https://quickpizza.grafana.com/test.k6.io/?q=def456'); + } catch (error) { + fail(`Browser iteration failed: ${error.message}`); } finally { await page.close(); } diff --git a/examples/browser/pageon.js b/examples/browser/pageon.js index ae22fe317..19cccfff4 100644 --- a/examples/browser/pageon.js +++ b/examples/browser/pageon.js @@ -1,4 +1,5 @@ import { browser } from 'k6/browser'; +import { fail } from 'k6'; import { check } from 'https://jslib.k6.io/k6-utils/1.5.0/index.js'; export const options = { @@ -39,6 +40,8 @@ export default async function() { })); await page.evaluate(() => console.log('this is a console.log message', 42)); + } catch (error) { + fail(`Browser iteration failed: ${error.message}`); } finally { await page.close(); } diff --git a/examples/browser/querying.js b/examples/browser/querying.js index 1d0ef479d..7c24b4c35 100644 --- a/examples/browser/querying.js +++ b/examples/browser/querying.js @@ -1,4 +1,5 @@ import { browser } from 'k6/browser'; +import { fail } from 'k6'; import { check } from 'https://jslib.k6.io/k6-utils/1.5.0/index.js'; export const options = { @@ -34,6 +35,8 @@ export default async function() { return await e.textContent() === 'QuickPizza Legacy'; } }); + } catch (error) { + fail(`Browser iteration failed: ${error.message}`); } finally { await page.close(); } diff --git a/examples/browser/route.js b/examples/browser/route.js index ec50f69ab..e38bfd39d 100644 --- a/examples/browser/route.js +++ b/examples/browser/route.js @@ -1,5 +1,5 @@ import { browser } from 'k6/browser'; -import { check } from 'k6'; +import { check, fail } from 'k6'; export const options = { scenarios: { @@ -64,6 +64,8 @@ export default async function () { 'pizza API status is 200': (r) => r.status() === 200, 'pizza API URL is correct': (r) => r.url() === 'https://quickpizza.grafana.com/api/pizza', }); + } catch (error) { + fail(`Browser iteration failed: ${error.message}`); } finally { await page.close(); } diff --git a/examples/browser/route_continue.js b/examples/browser/route_continue.js index d76efa3ec..604bcdc71 100644 --- a/examples/browser/route_continue.js +++ b/examples/browser/route_continue.js @@ -1,4 +1,4 @@ -import { sleep } from 'k6'; +import { sleep, fail } from 'k6'; import { browser } from 'k6/browser'; import { check } from 'https://jslib.k6.io/k6-utils/1.5.0/index.js'; @@ -37,6 +37,8 @@ export default async function () { check(null, { pizzaName: await e.innerText() === 'Name: My Pizza', }); + } catch (error) { + fail(`Browser iteration failed: ${error.message}`); } finally { await page.close(); } diff --git a/examples/browser/screenshot.js b/examples/browser/screenshot.js index 315e3a4f7..0b28d37a6 100644 --- a/examples/browser/screenshot.js +++ b/examples/browser/screenshot.js @@ -1,4 +1,5 @@ import { browser } from 'k6/browser'; +import { fail } from 'k6'; export const options = { scenarios: { @@ -25,6 +26,8 @@ export default async function() { await page.screenshot({ path: 'screenshot.png' }); // TODO: Assert this somehow. Upload as CI artifact or just an external `ls`? // Maybe even do a fuzzy image comparison against a preset known good screenshot? + } catch (error) { + fail(`Browser iteration failed: ${error.message}`); } finally { await page.close(); } diff --git a/examples/browser/throttle.js b/examples/browser/throttle.js index 28a47590a..72ebd4da8 100644 --- a/examples/browser/throttle.js +++ b/examples/browser/throttle.js @@ -1,4 +1,5 @@ import { browser, networkProfiles } from 'k6/browser'; +import { fail } from 'k6'; export const options = { scenarios: { @@ -46,6 +47,8 @@ export async function normal() { try { await page.goto('https://quickpizza.grafana.com/test.k6.io/', { waitUntil: 'networkidle' }); + } catch (error) { + fail(`Browser iteration failed: ${error.message}`); } finally { await page.close(); } @@ -59,6 +62,8 @@ export async function networkThrottled() { await page.throttleNetwork(networkProfiles["Slow 3G"]); await page.goto('https://quickpizza.grafana.com/test.k6.io/', { waitUntil: 'networkidle' }); + } catch (error) { + fail(`Browser iteration failed: ${error.message}`); } finally { await page.close(); } @@ -72,6 +77,8 @@ export async function cpuThrottled() { await page.throttleCPU({ rate: 4 }); await page.goto('https://quickpizza.grafana.com/test.k6.io/', { waitUntil: 'networkidle' }); + } catch (error) { + fail(`Browser iteration failed: ${error.message}`); } finally { await page.close(); } diff --git a/examples/browser/waitforfunction.js b/examples/browser/waitforfunction.js index ea939b6d9..adea8f9a4 100644 --- a/examples/browser/waitforfunction.js +++ b/examples/browser/waitforfunction.js @@ -1,4 +1,5 @@ import { browser } from 'k6/browser'; +import { fail } from 'k6'; import { check } from 'https://jslib.k6.io/k6-utils/1.5.0/index.js'; export const options = { @@ -41,6 +42,8 @@ export default async function() { return await e.innerHTML() === 'Hello'; } }); + } catch (error) { + fail(`Browser iteration failed: ${error.message}`); } finally { await page.close(); } From c3c5b244aa44d1552187e7c8921166c6b5aa05aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gonz=C3=A1lez=20Lopes?= Date: Tue, 28 Jul 2026 10:43:24 +0200 Subject: [PATCH 053/182] [feat] Add `cloud load-zone list` command (#6142) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [feat] add `cloud load-zone list` command Add a new `k6 cloud load-zone list` subcommand that lists the load zones available in the configured Grafana Cloud k6 stack, mirroring the existing `cloud project list` command. Supports table and --json output. The table surfaces each zone's k6 load zone ID, name, whether it is a public (Grafana-managed) or private zone, and its availability. The `public` and `available` flags are not yet modeled by the cloud OpenAPI SDK, so they are read best-effort from the untyped response fields and default to false when absent. * [refactor] address review of cloud load-zone list - Name ListLoadZones' error return so a body-close error from closeResponse propagates instead of being silently dropped. - Extract the shared v6 client setup (config load, login check, client creation, stack ID wiring) into newCloudV6ClientFromConfig and a cloudStackName helper, used by both `cloud project list` and `cloud load-zone list` instead of duplicating ~35 lines. - Add a test covering the best-effort default: a load zone that omits the untyped public/available fields must default them to false. - Rename cloud_loadzone*.go to cloud_load_zone*.go to match the command spelling and the test file name. * [refactor] address Théo's PR review - Route cmdCloudTestList.run() through the shared newCloudV6ClientFromConfig helper too, so project, test, and load-zone list all use one setup path instead of each carrying its own config load / auth check / client construction / stack-ID wiring. - Expand the load-zone public/available comment into a TODO(#6142) tracking the k6-cloud-openapi-client-go bump that will replace the untyped AdditionalProperties reads with the SDK's typed fields, and note that both are required API fields so the false default only guards a contract violation. * Update internal/cmd/cloud_load_zone_list.go Co-authored-by: Joan López de la Franca Beltran <5459617+joanlopez@users.noreply.github.com> * Update internal/cmd/cloud_load_zone_list.go Co-authored-by: Joan López de la Franca Beltran <5459617+joanlopez@users.noreply.github.com> * Apply suggestion from @joanlopez --------- Co-authored-by: Joan López de la Franca Beltran <5459617+joanlopez@users.noreply.github.com> --- internal/cloudapi/v6/api.go | 43 +++++++ internal/cloudapi/v6/api_test.go | 35 ++++++ internal/cloudapi/v6/v6test/server.go | 17 +++ internal/cmd/cloud.go | 55 +++++++++ internal/cmd/cloud_load_zone.go | 42 +++++++ internal/cmd/cloud_load_zone_list.go | 101 ++++++++++++++++ internal/cmd/cloud_loadtest_list.go | 35 +----- internal/cmd/cloud_project_list.go | 41 +------ .../tests/cmd_cloud_load_zone_list_test.go | 111 ++++++++++++++++++ 9 files changed, 409 insertions(+), 71 deletions(-) create mode 100644 internal/cmd/cloud_load_zone.go create mode 100644 internal/cmd/cloud_load_zone_list.go create mode 100644 internal/cmd/tests/cmd_cloud_load_zone_list_test.go diff --git a/internal/cloudapi/v6/api.go b/internal/cloudapi/v6/api.go index b384a1063..908a0db32 100644 --- a/internal/cloudapi/v6/api.go +++ b/internal/cloudapi/v6/api.go @@ -33,6 +33,20 @@ type LoadTest struct { Updated time.Time `json:"updated"` } +// LoadZone is a Grafana Cloud k6 load zone. +type LoadZone struct { + ID int64 `json:"id"` + // K6LoadZoneID is the identifier used to reference the load zone from + // k6 scripts (e.g. "amazon:us:ashburn"). + K6LoadZoneID string `json:"k6_load_zone_id"` + Name string `json:"name"` + // Public reports whether the load zone is a public (Grafana-managed) + // zone as opposed to a private/custom one. + Public bool `json:"public"` + // Available reports whether the load zone is currently usable. + Available bool `json:"available"` +} + // ListProjects retrieves the list of projects for the configured stack. func (c *Client) ListProjects(ctx context.Context) ([]Project, error) { const pageSize int32 = 1000 @@ -141,6 +155,35 @@ func (c *Client) listLoadTestsPage( return res, nil } +// ListLoadZones retrieves the list of load zones available to the configured stack. +func (c *Client) ListLoadZones(ctx context.Context) (_ []LoadZone, err error) { + res, hr, err := c.apiClient.LoadZonesAPI. + LoadZonesList(c.authCtx(ctx)). + XStackId(c.stackID). + Execute() + defer closeResponse(hr, &err) + + if err := CheckResponse(hr, err); err != nil { + return nil, err + } + if res == nil { + return nil, errUnknown + } + + zones := make([]LoadZone, 0, len(res.Value)) + for _, zone := range res.Value { + zones = append(zones, LoadZone{ + ID: zone.Id, + K6LoadZoneID: zone.K6LoadZoneId, + Name: zone.Name, + Public: zone.Public, + Available: zone.Available, + }) + } + + return zones, nil +} + // ValidateToken validates the cloud authentication token. func (c *Client) ValidateToken(ctx context.Context, stackURL string) (_ *k6cloud.AuthenticationResponse, err error) { if stackURL == "" { diff --git a/internal/cloudapi/v6/api_test.go b/internal/cloudapi/v6/api_test.go index 0d8eb003c..68cb6add9 100644 --- a/internal/cloudapi/v6/api_test.go +++ b/internal/cloudapi/v6/api_test.go @@ -199,6 +199,41 @@ func TestListLoadTests(t *testing.T) { assert.Equal(t, int64(2), tests[1].ID) } +func TestListLoadZones(t *testing.T) { + t.Parallel() + + loadZone := func(id int64, k6LoadZoneID, name string, public, available bool) map[string]any { + return map[string]any{ + "id": id, + "k6_load_zone_id": k6LoadZoneID, + "name": name, + "public": public, + "available": available, + "custom_load_runner_image": nil, + } + } + + client := newTestClient(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + assert.Equal(t, "/cloud/v6/load_zones", r.URL.Path) + writeJSON(t, w, http.StatusOK, map[string]any{ + "value": []any{ + loadZone(1, "amazon:us:ashburn", "US East (Ashburn)", true, true), + loadZone(2, "my-cluster", "My private cluster", false, false), + }, + }) + })) + + zones, err := client.ListLoadZones(t.Context()) + require.NoError(t, err) + require.Len(t, zones, 2) + assert.Equal(t, + LoadZone{ID: 1, K6LoadZoneID: "amazon:us:ashburn", Name: "US East (Ashburn)", Public: true, Available: true}, + zones[0]) + assert.Equal(t, + LoadZone{ID: 2, K6LoadZoneID: "my-cluster", Name: "My private cluster", Public: false, Available: false}, + zones[1]) +} + func TestRetryWithConnectionClose(t *testing.T) { t.Parallel() diff --git a/internal/cloudapi/v6/v6test/server.go b/internal/cloudapi/v6/v6test/server.go index a542e58a8..a661f06d6 100644 --- a/internal/cloudapi/v6/v6test/server.go +++ b/internal/cloudapi/v6/v6test/server.go @@ -55,6 +55,9 @@ type Config struct { // LoadTests is the load test list returned by the load-tests endpoint. LoadTests []cloudapi.LoadTest + + // LoadZones is the load zone list returned by the load-zones endpoint. + LoadZones []cloudapi.LoadZone } // NewServer creates a test server that serves v6 API endpoints. @@ -70,6 +73,7 @@ func NewServer(t *testing.T, cfg Config) *Server { mux := http.NewServeMux() mux.HandleFunc("GET /cloud/v6/projects", s.handleListProjects) mux.HandleFunc("GET /cloud/v6/projects/{projectID}/load_tests", s.handleListLoadTests) + mux.HandleFunc("GET /cloud/v6/load_zones", s.handleListLoadZones) mux.HandleFunc("POST /cloud/v6/validate_options", s.handleValidateOptions) mux.HandleFunc("POST /cloud/v6/projects/{projectID}/load_tests", func(w http.ResponseWriter, r *http.Request) { if s.cfg.InspectArchive != nil { @@ -139,6 +143,19 @@ func (s *Server) handleListLoadTests(w http.ResponseWriter, r *http.Request) { writeJSON(w, http.StatusOK, res) } +func (s *Server) handleListLoadZones(w http.ResponseWriter, _ *http.Request) { + zones := make([]k6cloud.LoadZoneApiModel, len(s.cfg.LoadZones)) + for i, zone := range s.cfg.LoadZones { + m := k6cloud.NewLoadZoneApiModel( + zone.ID, zone.Name, zone.K6LoadZoneID, + zone.Available, *k6cloud.NewNullableString(nil), zone.Public, + ) + zones[i] = *m + } + res := k6cloud.NewLoadZonesListApiModel(zones) + writeJSON(w, http.StatusOK, res) +} + func (s *Server) handleValidateOptions(w http.ResponseWriter, _ *http.Request) { vuh, zero := float32(0.5), float32(0) res := k6cloud.NewValidateOptionsResponse( diff --git a/internal/cmd/cloud.go b/internal/cmd/cloud.go index 1133355fc..f8168387b 100644 --- a/internal/cmd/cloud.go +++ b/internal/cmd/cloud.go @@ -63,6 +63,58 @@ func checkCloudLoginFor(conf cloudapi.Config, prefix string) error { return nil } +// newCloudV6ClientFromConfig builds a v6 cloud API client from the on-disk and +// environment configuration. It verifies that a complete login is configured +// (using authPrefix in the error message) and wires the resolved stack ID into +// the client. It returns the client alongside the consolidated cloud config. +func newCloudV6ClientFromConfig( + gs *state.GlobalState, authPrefix string, +) (*cloudapiv6.Client, cloudapi.Config, error) { + currentDiskConf, err := readDiskConfig(gs) + if err != nil { + return nil, cloudapi.Config{}, err + } + + cloudConfig, warn, err := cloudapi.GetConsolidatedConfig( + currentDiskConf.Collectors["cloud"], gs.Env, "", nil) + if err != nil { + return nil, cloudapi.Config{}, err + } + if warn != "" { + gs.Logger.Warn(warn) + } + + if err := checkCloudLoginFor(cloudConfig, authPrefix); err != nil { + return nil, cloudapi.Config{}, err + } + + client, err := cloudapiv6.NewClient( + gs.Logger, + cloudConfig.Token.String, + cloudConfig.Hostv6.String, + build.Version, + cloudConfig.Timeout.TimeDuration(), + ) + if err != nil { + return nil, cloudapi.Config{}, err + } + + if err := client.SetStackID(cloudConfig.StackID.Int64); err != nil { + return nil, cloudapi.Config{}, err + } + + return client, cloudConfig, nil +} + +// cloudStackName returns a human-readable name for the configured stack, +// falling back to "stack-" when the stack URL is not available. +func cloudStackName(conf cloudapi.Config) string { + if conf.StackURL.Valid { + return conf.StackURL.String + } + return fmt.Sprintf("stack-%d", conf.StackID.Int64) +} + // cmdCloud handles the `k6 cloud` sub-command type cmdCloud struct { gs *state.GlobalState @@ -441,6 +493,9 @@ func getCmdCloud(gs *state.GlobalState) *cobra.Command { projectCmd := getCmdCloudProject(c) cloudCmd.AddCommand(projectCmd) + loadZoneCmd := getCmdCloudLoadZone(c) + cloudCmd.AddCommand(loadZoneCmd) + testCmd := getCmdCloudTest(c) cloudCmd.AddCommand(testCmd) diff --git a/internal/cmd/cloud_load_zone.go b/internal/cmd/cloud_load_zone.go new file mode 100644 index 000000000..90746ddaf --- /dev/null +++ b/internal/cmd/cloud_load_zone.go @@ -0,0 +1,42 @@ +package cmd + +import ( + "github.com/spf13/cobra" + "go.k6.io/k6/v2/cmd/state" +) + +type cmdCloudLoadZone struct { + globalState *state.GlobalState +} + +func getCmdCloudLoadZone(cloudCmd *cmdCloud) *cobra.Command { + c := &cmdCloudLoadZone{ + globalState: cloudCmd.gs, + } + + exampleText := getExampleText(cloudCmd.gs, ` + # List all load zones in the configured stack + $ {{.}} cloud load-zone list + + # List load zones in JSON format + $ {{.}} cloud load-zone list --json`[1:]) + + cloudLoadZoneCommand := &cobra.Command{ + Use: "load-zone", + Short: "Work with Grafana Cloud k6 load zones", + Long: `Work with Grafana Cloud k6 load zones.`, + + Example: exampleText, + } + + cloudUsageTemplate := getCloudUsageTemplate() + + listCmd := getCmdCloudLoadZoneList(c) + listCmd.SetUsageTemplate(cloudUsageTemplate) + listCmd.SetHelpTemplate(cloudUsageTemplate) + cloudLoadZoneCommand.AddCommand(listCmd) + + cloudLoadZoneCommand.SetUsageTemplate(cloudUsageTemplate) + + return cloudLoadZoneCommand +} diff --git a/internal/cmd/cloud_load_zone_list.go b/internal/cmd/cloud_load_zone_list.go new file mode 100644 index 000000000..1c10065b2 --- /dev/null +++ b/internal/cmd/cloud_load_zone_list.go @@ -0,0 +1,101 @@ +package cmd + +import ( + "bytes" + "encoding/json" + "fmt" + "strings" + "text/tabwriter" + + "github.com/spf13/cobra" + + "go.k6.io/k6/v2/cmd/state" + cloudapiv6 "go.k6.io/k6/v2/internal/cloudapi/v6" +) + +type cmdCloudLoadZoneList struct { + globalState *state.GlobalState + isJSON bool +} + +func getCmdCloudLoadZoneList(loadZoneCmd *cmdCloudLoadZone) *cobra.Command { + c := &cmdCloudLoadZoneList{ + globalState: loadZoneCmd.globalState, + } + + exampleText := getExampleText(loadZoneCmd.globalState, ` + # List all load zones in the configured stack + $ {{.}} cloud load-zone list`[1:]) + + listCmd := &cobra.Command{ + Use: "list", + Short: "List Grafana Cloud k6 load zones", + Long: `List all load zones in the configured Grafana Cloud k6 stack.`, + Example: exampleText, + Args: cobra.NoArgs, + RunE: c.run, + } + + listCmd.Flags().BoolVar(&c.isJSON, "json", false, "output load zone list in JSON format") + + return listCmd +} + +func (c *cmdCloudLoadZoneList) run(_ *cobra.Command, _ []string) error { + client, cloudConfig, err := newCloudV6ClientFromConfig( + c.globalState, "Listing cloud load zones requires auth settings") + if err != nil { + return err + } + + loadZones, err := client.ListLoadZones(c.globalState.Ctx) + if err != nil { + return err + } + + if c.isJSON { + return c.outputJSON(loadZones) + } + + stackHeader := fmt.Sprintf("Load zones for %s:\n\n", cloudStackName(cloudConfig)) + + if len(loadZones) == 0 { + printToStdout(c.globalState, stackHeader+"No load zones found.\n") + return nil + } + + printToStdout(c.globalState, stackHeader+formatLoadZoneTable(loadZones)) + return nil +} + +func (c *cmdCloudLoadZoneList) outputJSON(loadZones []cloudapiv6.LoadZone) error { + buf := &bytes.Buffer{} + enc := json.NewEncoder(buf) + enc.SetEscapeHTML(false) + enc.SetIndent("", " ") + if err := enc.Encode(loadZones); err != nil { + return fmt.Errorf("failed to encode load zone list: %w", err) + } + + printToStdout(c.globalState, buf.String()) + return nil +} + +func formatLoadZoneTable(loadZones []cloudapiv6.LoadZone) string { + var buf strings.Builder + w := tabwriter.NewWriter(&buf, 0, 0, 3, ' ', 0) + _, _ = fmt.Fprintln(w, "ID\tNAME\tTYPE\tAVAILABLE") + for _, z := range loadZones { + zoneType := "private" + if z.Public { + zoneType = "public" + } + available := "no" + if z.Available { + available = "yes" + } + _, _ = fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", z.K6LoadZoneID, z.Name, zoneType, available) + } + _ = w.Flush() + return buf.String() +} diff --git a/internal/cmd/cloud_loadtest_list.go b/internal/cmd/cloud_loadtest_list.go index 6034abd17..1dcdc0ad7 100644 --- a/internal/cmd/cloud_loadtest_list.go +++ b/internal/cmd/cloud_loadtest_list.go @@ -12,7 +12,6 @@ import ( "go.k6.io/k6/v2/cloudapi" "go.k6.io/k6/v2/cmd/state" - "go.k6.io/k6/v2/internal/build" v6cloudapi "go.k6.io/k6/v2/internal/cloudapi/v6" ) @@ -51,46 +50,16 @@ func getCmdCloudTestList(testCmd *cmdCloudTest) *cobra.Command { } func (c *cmdCloudTestList) run(cmd *cobra.Command, _ []string) error { - currentDiskConf, err := readDiskConfig(c.globalState) + client, cloudConfig, err := newCloudV6ClientFromConfig( + c.globalState, "Listing cloud tests requires auth settings") if err != nil { return err } - currentJSONConfigRaw := currentDiskConf.Collectors["cloud"] - - cloudConfig, warn, err := cloudapi.GetConsolidatedConfig( - currentJSONConfigRaw, c.globalState.Env, "", nil) - if err != nil { - return err - } - if warn != "" { - c.globalState.Logger.Warn(warn) - } - - if err := checkCloudLoginFor(cloudConfig, "Listing cloud tests requires auth settings"); err != nil { - return err - } - projectID, err := c.resolveProjectID(cloudConfig, cmd.Flags().Changed("project-id")) if err != nil { return err } - - client, err := v6cloudapi.NewClient( - c.globalState.Logger, - cloudConfig.Token.String, - cloudConfig.Hostv6.String, - build.Version, - cloudConfig.Timeout.TimeDuration(), - ) - if err != nil { - return err - } - - if err := client.SetStackID(cloudConfig.StackID.Int64); err != nil { - return err - } - tests, err := client.ListLoadTests(c.globalState.Ctx, projectID) if err != nil { return err diff --git a/internal/cmd/cloud_project_list.go b/internal/cmd/cloud_project_list.go index a13599c93..073a6b765 100644 --- a/internal/cmd/cloud_project_list.go +++ b/internal/cmd/cloud_project_list.go @@ -9,9 +9,7 @@ import ( "github.com/spf13/cobra" - "go.k6.io/k6/v2/cloudapi" "go.k6.io/k6/v2/cmd/state" - "go.k6.io/k6/v2/internal/build" cloudapiv6 "go.k6.io/k6/v2/internal/cloudapi/v6" ) @@ -44,41 +42,12 @@ func getCmdCloudProjectList(projectCmd *cmdCloudProject) *cobra.Command { } func (c *cmdCloudProjectList) run(_ *cobra.Command, _ []string) error { - currentDiskConf, err := readDiskConfig(c.globalState) + client, cloudConfig, err := newCloudV6ClientFromConfig( + c.globalState, "Listing cloud projects requires auth settings") if err != nil { return err } - currentJSONConfigRaw := currentDiskConf.Collectors["cloud"] - - cloudConfig, warn, err := cloudapi.GetConsolidatedConfig( - currentJSONConfigRaw, c.globalState.Env, "", nil) - if err != nil { - return err - } - if warn != "" { - c.globalState.Logger.Warn(warn) - } - - if err := checkCloudLoginFor(cloudConfig, "Listing cloud projects requires auth settings"); err != nil { - return err - } - - client, err := cloudapiv6.NewClient( - c.globalState.Logger, - cloudConfig.Token.String, - cloudConfig.Hostv6.String, - build.Version, - cloudConfig.Timeout.TimeDuration(), - ) - if err != nil { - return err - } - - if err := client.SetStackID(cloudConfig.StackID.Int64); err != nil { - return err - } - projects, err := client.ListProjects(c.globalState.Ctx) if err != nil { return err @@ -88,11 +57,7 @@ func (c *cmdCloudProjectList) run(_ *cobra.Command, _ []string) error { return c.outputJSON(projects) } - stackName := cloudConfig.StackURL.String - if !cloudConfig.StackURL.Valid { - stackName = fmt.Sprintf("stack-%d", cloudConfig.StackID.Int64) - } - stackHeader := fmt.Sprintf("Projects for %s:\n\n", stackName) + stackHeader := fmt.Sprintf("Projects for %s:\n\n", cloudStackName(cloudConfig)) if len(projects) == 0 { printToStdout(c.globalState, stackHeader+ diff --git a/internal/cmd/tests/cmd_cloud_load_zone_list_test.go b/internal/cmd/tests/cmd_cloud_load_zone_list_test.go new file mode 100644 index 000000000..9374a2f70 --- /dev/null +++ b/internal/cmd/tests/cmd_cloud_load_zone_list_test.go @@ -0,0 +1,111 @@ +package tests + +import ( + "encoding/json" + "fmt" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + cloudapiv6 "go.k6.io/k6/v2/internal/cloudapi/v6" + "go.k6.io/k6/v2/internal/cloudapi/v6/v6test" + "go.k6.io/k6/v2/internal/cmd" +) + +func TestCloudLoadZoneList(t *testing.T) { + t.Parallel() + + t.Run("lists load zones successfully", func(t *testing.T) { + t.Parallel() + + ts := newCloudLoadZoneListTestState(t, testLoadZones()) + + cmd.ExecuteWithGlobalState(ts.GlobalState) + + stdout := ts.Stdout.String() + assert.Contains(t, stdout, fmt.Sprintf("Load zones for stack-%d:", validStackID)) + assert.Contains(t, stdout, "ID NAME TYPE AVAILABLE") + assert.Contains(t, stdout, "amazon:us:ashburn US East (Ashburn) public yes") + assert.Contains(t, stdout, "my-cluster My private cluster private no") + }) + + t.Run("empty load zone list", func(t *testing.T) { + t.Parallel() + + ts := newCloudLoadZoneListTestState(t, nil) + + cmd.ExecuteWithGlobalState(ts.GlobalState) + + stdout := ts.Stdout.String() + assert.Contains(t, stdout, fmt.Sprintf("Load zones for stack-%d:", validStackID)) + assert.Contains(t, stdout, "No load zones found.") + }) + + t.Run("--help includes usage", func(t *testing.T) { + t.Parallel() + + ts := NewGlobalTestState(t) + ts.CmdArgs = []string{"k6", "cloud", "load-zone", "list", "--help"} + + cmd.ExecuteWithGlobalState(ts.GlobalState) + + stdout := ts.Stdout.String() + assert.Contains(t, stdout, "Usage:\n k6 cloud load-zone list [flags]") + assert.Contains(t, stdout, "--json") + assert.NotContains(t, stdout, "Global Flags:") + assert.NotContains(t, stdout, "--config") + assert.NotContains(t, stdout, "\n\n\nExamples:") + }) + + t.Run("--json outputs JSON", func(t *testing.T) { + t.Parallel() + + ts := newCloudLoadZoneListTestState(t, testLoadZones(), "--json") + + cmd.ExecuteWithGlobalState(ts.GlobalState) + + stdout := ts.Stdout.String() + + var loadZones []cloudapiv6.LoadZone + require.NoError(t, json.Unmarshal([]byte(stdout), &loadZones)) + assert.Equal(t, testLoadZones(), loadZones) + }) + + t.Run("--json with empty list outputs empty array", func(t *testing.T) { + t.Parallel() + + ts := newCloudLoadZoneListTestState(t, nil, "--json") + + cmd.ExecuteWithGlobalState(ts.GlobalState) + + stdout := ts.Stdout.String() + + var loadZones []cloudapiv6.LoadZone + require.NoError(t, json.Unmarshal([]byte(stdout), &loadZones)) + assert.Empty(t, loadZones) + }) +} + +func testLoadZones() []cloudapiv6.LoadZone { + return []cloudapiv6.LoadZone{ + {ID: 1, K6LoadZoneID: "amazon:us:ashburn", Name: "US East (Ashburn)", Public: true, Available: true}, + {ID: 2, K6LoadZoneID: "my-cluster", Name: "My private cluster", Public: false, Available: false}, + } +} + +func newCloudLoadZoneListTestState( + t *testing.T, loadZones []cloudapiv6.LoadZone, args ...string, +) *GlobalTestState { + t.Helper() + + srv := v6test.NewServer(t, v6test.Config{LoadZones: loadZones}) + + ts := NewGlobalTestState(t) + ts.CmdArgs = append([]string{"k6", "cloud", "load-zone", "list"}, args...) + ts.Env["K6_CLOUD_TOKEN"] = validToken + ts.Env["K6_CLOUD_STACK_ID"] = fmt.Sprintf("%d", validStackID) + ts.Env["K6_CLOUD_HOST_V6"] = srv.URL + + return ts +} From ab5bc092897ac12c50ee5bbbc9249bf940b50844 Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Tue, 28 Jul 2026 10:46:13 +0200 Subject: [PATCH 054/182] fix(deps): update module github.com/prometheus/client_golang to v1.24.1 (#6215) | datasource | package | from | to | | ---------- | ----------------------------------- | ------- | ------- | | go | github.com/prometheus/client_golang | v1.23.2 | v1.24.1 | Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> --- go.mod | 9 +- go.sum | 20 +- .../klauspost/compress/flate/inflate_gen.go | 116 +- .../klauspost/compress/s2/encode_all.go | 2 +- .../klauspost/compress/s2/reader.go | 19 +- .../compress/snappy/decode_strict.go | 130 + .../compress/zstd/fse_decoder_arm64.s | 13 +- .../klauspost/compress/zstd/seqdec_arm64.s | 8 +- .../klauspost/compress/zstd/snappy.go | 7 +- .../golang/gddo/httputil/header/header.go | 2 +- .../client_golang/prometheus/counter.go | 11 +- .../client_golang/prometheus/desc.go | 37 +- .../prometheus/expvar_collector.go | 8 +- .../client_golang/prometheus/gauge.go | 11 +- .../prometheus/go_collector_go116.go | 122 - .../prometheus/go_collector_latest.go | 20 +- .../client_golang/prometheus/histogram.go | 29 +- .../prometheus/internal/difflib.go | 4 +- .../client_golang/prometheus/labels.go | 3 +- .../client_golang/prometheus/metric.go | 3 + .../prometheus/process_collector_darwin.go | 13 +- .../prometheus/process_collector_windows.go | 19 +- .../client_golang/prometheus/promhttp/http.go | 197 +- .../prometheus/promhttp/instrument_client.go | 12 +- .../prometheus/promhttp/instrument_server.go | 88 +- .../prometheus/promhttp/option.go | 42 +- .../client_golang/prometheus/registry.go | 63 +- .../client_golang/prometheus/summary.go | 9 +- .../client_golang/prometheus/timer.go | 10 +- .../client_golang/prometheus/vec.go | 10 +- .../client_golang/prometheus/wrap.go | 5 +- .../prometheus/common/expfmt/decode.go | 14 +- .../prometheus/common/expfmt/expfmt.go | 5 +- .../prometheus/common/expfmt/fuzz.go | 1 - .../common/expfmt/openmetrics_create.go | 85 +- .../prometheus/common/expfmt/text_create.go | 62 +- .../prometheus/common/expfmt/text_parse.go | 112 +- .../prometheus/common/model/labels.go | 2 +- .../prometheus/common/model/labelset.go | 13 +- .../prometheus/common/model/metric.go | 14 +- .../prometheus/common/model/time.go | 44 +- .../prometheus/common/model/value.go | 8 +- .../prometheus/common/model/value_float.go | 2 +- .../common/model/value_histogram.go | 8 +- .../prometheus/procfs/Makefile.common | 200 +- .../github.com/prometheus/procfs/SECURITY.md | 2 +- vendor/github.com/prometheus/procfs/arp.go | 9 +- .../github.com/prometheus/procfs/buddyinfo.go | 10 +- .../github.com/prometheus/procfs/cmdline.go | 2 +- .../github.com/prometheus/procfs/cpuinfo.go | 5 +- .../prometheus/procfs/cpuinfo_armx.go | 4 +- .../prometheus/procfs/cpuinfo_loong64.go | 3 +- .../prometheus/procfs/cpuinfo_mipsx.go | 4 +- .../prometheus/procfs/cpuinfo_others.go | 3 +- .../prometheus/procfs/cpuinfo_ppcx.go | 4 +- .../prometheus/procfs/cpuinfo_riscvx.go | 4 +- .../prometheus/procfs/cpuinfo_s390x.go | 3 +- .../prometheus/procfs/cpuinfo_x86.go | 4 +- vendor/github.com/prometheus/procfs/crypto.go | 10 +- vendor/github.com/prometheus/procfs/doc.go | 2 +- vendor/github.com/prometheus/procfs/fs.go | 2 +- .../prometheus/procfs/fs_statfs_notype.go | 3 +- .../prometheus/procfs/fs_statfs_type.go | 3 +- .../github.com/prometheus/procfs/fscache.go | 9 +- .../prometheus/procfs/internal/fs/fs.go | 2 +- .../prometheus/procfs/internal/util/parse.go | 2 +- .../procfs/internal/util/readfile.go | 2 +- .../procfs/internal/util/sysreadfile.go | 4 +- .../internal/util/sysreadfile_compat.go | 3 +- .../procfs/internal/util/valueparser.go | 2 +- vendor/github.com/prometheus/procfs/ipvs.go | 2 +- .../prometheus/procfs/kernel_hung.go | 44 + .../prometheus/procfs/kernel_random.go | 3 +- .../github.com/prometheus/procfs/loadavg.go | 2 +- vendor/github.com/prometheus/procfs/mdstat.go | 121 +- .../github.com/prometheus/procfs/meminfo.go | 35 +- .../github.com/prometheus/procfs/mountinfo.go | 41 +- .../prometheus/procfs/mountstats.go | 4 +- .../prometheus/procfs/net_conntrackstat.go | 2 +- .../github.com/prometheus/procfs/net_dev.go | 2 +- .../prometheus/procfs/net_dev_snmp6.go | 7 +- .../prometheus/procfs/net_ip_socket.go | 2 +- .../prometheus/procfs/net_protocols.go | 4 +- .../github.com/prometheus/procfs/net_route.go | 2 +- .../prometheus/procfs/net_sockstat.go | 5 +- .../prometheus/procfs/net_softnet.go | 2 +- .../github.com/prometheus/procfs/net_tcp.go | 6 +- .../prometheus/procfs/net_tls_stat.go | 2 +- .../github.com/prometheus/procfs/net_udp.go | 2 +- .../github.com/prometheus/procfs/net_unix.go | 2 +- .../prometheus/procfs/net_wireless.go | 20 +- .../github.com/prometheus/procfs/net_xfrm.go | 2 +- .../github.com/prometheus/procfs/netstat.go | 2 +- .../prometheus/procfs/nfnetlink_queue.go | 85 + vendor/github.com/prometheus/procfs/proc.go | 4 +- .../prometheus/procfs/proc_cgroup.go | 4 +- .../prometheus/procfs/proc_cgroups.go | 8 +- .../prometheus/procfs/proc_environ.go | 2 +- .../prometheus/procfs/proc_fdinfo.go | 13 +- .../prometheus/procfs/proc_interrupts.go | 4 +- .../github.com/prometheus/procfs/proc_io.go | 2 +- .../prometheus/procfs/proc_limits.go | 7 +- .../github.com/prometheus/procfs/proc_maps.go | 4 +- .../prometheus/procfs/proc_netstat.go | 2 +- .../github.com/prometheus/procfs/proc_ns.go | 2 +- .../github.com/prometheus/procfs/proc_psi.go | 2 +- .../prometheus/procfs/proc_smaps.go | 3 +- .../github.com/prometheus/procfs/proc_snmp.go | 2 +- .../prometheus/procfs/proc_snmp6.go | 2 +- .../github.com/prometheus/procfs/proc_stat.go | 14 +- .../prometheus/procfs/proc_statm.go | 117 + .../prometheus/procfs/proc_status.go | 52 +- .../github.com/prometheus/procfs/proc_sys.go | 2 +- .../github.com/prometheus/procfs/schedstat.go | 2 +- vendor/github.com/prometheus/procfs/slab.go | 2 +- .../github.com/prometheus/procfs/softirqs.go | 2 +- vendor/github.com/prometheus/procfs/stat.go | 5 +- vendor/github.com/prometheus/procfs/swaps.go | 2 +- vendor/github.com/prometheus/procfs/thread.go | 2 +- vendor/github.com/prometheus/procfs/vm.go | 3 +- .../github.com/prometheus/procfs/zoneinfo.go | 9 +- vendor/go.yaml.in/yaml/v2/LICENSE | 201 -- vendor/go.yaml.in/yaml/v2/LICENSE.libyaml | 31 - vendor/go.yaml.in/yaml/v2/NOTICE | 13 - vendor/go.yaml.in/yaml/v2/apic.go | 744 ----- vendor/go.yaml.in/yaml/v2/decode.go | 815 ----- vendor/go.yaml.in/yaml/v2/emitterc.go | 1685 ---------- vendor/go.yaml.in/yaml/v2/encode.go | 390 --- vendor/go.yaml.in/yaml/v2/parserc.go | 1095 ------- vendor/go.yaml.in/yaml/v2/readerc.go | 412 --- vendor/go.yaml.in/yaml/v2/resolve.go | 258 -- vendor/go.yaml.in/yaml/v2/scannerc.go | 2711 ----------------- vendor/go.yaml.in/yaml/v2/sorter.go | 113 - vendor/go.yaml.in/yaml/v2/writerc.go | 26 - vendor/go.yaml.in/yaml/v2/yaml.go | 478 --- vendor/go.yaml.in/yaml/v2/yamlh.go | 739 ----- vendor/go.yaml.in/yaml/v2/yamlprivateh.go | 173 -- vendor/modules.txt | 17 +- 138 files changed, 1724 insertions(+), 10562 deletions(-) create mode 100644 vendor/github.com/klauspost/compress/snappy/decode_strict.go delete mode 100644 vendor/github.com/prometheus/client_golang/prometheus/go_collector_go116.go create mode 100644 vendor/github.com/prometheus/procfs/kernel_hung.go create mode 100644 vendor/github.com/prometheus/procfs/nfnetlink_queue.go create mode 100644 vendor/github.com/prometheus/procfs/proc_statm.go delete mode 100644 vendor/go.yaml.in/yaml/v2/LICENSE delete mode 100644 vendor/go.yaml.in/yaml/v2/LICENSE.libyaml delete mode 100644 vendor/go.yaml.in/yaml/v2/NOTICE delete mode 100644 vendor/go.yaml.in/yaml/v2/apic.go delete mode 100644 vendor/go.yaml.in/yaml/v2/decode.go delete mode 100644 vendor/go.yaml.in/yaml/v2/emitterc.go delete mode 100644 vendor/go.yaml.in/yaml/v2/encode.go delete mode 100644 vendor/go.yaml.in/yaml/v2/parserc.go delete mode 100644 vendor/go.yaml.in/yaml/v2/readerc.go delete mode 100644 vendor/go.yaml.in/yaml/v2/resolve.go delete mode 100644 vendor/go.yaml.in/yaml/v2/scannerc.go delete mode 100644 vendor/go.yaml.in/yaml/v2/sorter.go delete mode 100644 vendor/go.yaml.in/yaml/v2/writerc.go delete mode 100644 vendor/go.yaml.in/yaml/v2/yaml.go delete mode 100644 vendor/go.yaml.in/yaml/v2/yamlh.go delete mode 100644 vendor/go.yaml.in/yaml/v2/yamlprivateh.go diff --git a/go.mod b/go.mod index 496136849..1f67b8f0d 100644 --- a/go.mod +++ b/go.mod @@ -28,14 +28,14 @@ require ( github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 github.com/influxdata/influxdb1-client v0.0.0-20190402204710-8ff2fc3824fc github.com/jhump/protoreflect v1.18.0 - github.com/klauspost/compress v1.19.0 + github.com/klauspost/compress v1.19.1 github.com/mattn/go-colorable v0.1.15 github.com/mattn/go-isatty v0.0.23 github.com/mccutchen/go-httpbin/v2 v2.24.0 github.com/mstoykov/atlas v0.0.0-20220811071828-388f114305dd github.com/mstoykov/envconfig v1.5.0 github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c - github.com/prometheus/client_golang v1.23.2 + github.com/prometheus/client_golang v1.24.1 github.com/prometheus/client_model v0.6.2 github.com/r3labs/sse/v2 v2.10.0 github.com/serenize/snaker v0.0.0-20201027110005-a7ad2135616e @@ -90,12 +90,11 @@ require ( github.com/onsi/ginkgo v1.16.5 // indirect github.com/onsi/gomega v1.39.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/prometheus/common v0.66.1 // indirect - github.com/prometheus/procfs v0.16.1 // indirect + github.com/prometheus/common v0.70.1 // indirect + github.com/prometheus/procfs v0.21.1 // indirect github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/pretty v1.2.1 // indirect go.opentelemetry.io/auto/sdk v1.2.1 // indirect - go.yaml.in/yaml/v2 v2.4.2 // indirect golang.org/x/sys v0.47.0 // indirect golang.org/x/text v0.40.0 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20260526163538-3dc84a4a5aaa // indirect diff --git a/go.sum b/go.sum index 86e7b5820..aba56bdf5 100644 --- a/go.sum +++ b/go.sum @@ -117,8 +117,8 @@ github.com/jhump/protoreflect/v2 v2.0.0-beta.1 h1:Dw1rslK/VotaUGYsv53XVWITr+5RCP github.com/jhump/protoreflect/v2 v2.0.0-beta.1/go.mod h1:D9LBEowZyv8/iSu97FU2zmXG3JxVTmNw21mu63niFzU= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/klauspost/compress v1.19.0 h1:sXLILfc9jV2QYWkzFOPWStmcUVH2RHEB1JCdY2oVvCQ= -github.com/klauspost/compress v1.19.0/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ= +github.com/klauspost/compress v1.19.1 h1:VsB4HPswih7mmZ8WleSFQ75c/Ui1M4trX5oAsJnhSlk= +github.com/klauspost/compress v1.19.1/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= @@ -163,15 +163,15 @@ github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjL github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/prometheus/client_golang v1.23.2 h1:Je96obch5RDVy3FDMndoUsjAhG5Edi49h0RJWRi/o0o= -github.com/prometheus/client_golang v1.23.2/go.mod h1:Tb1a6LWHB3/SPIzCoaDXI4I8UHKeFTEQ1YCr+0Gyqmg= +github.com/prometheus/client_golang v1.24.1 h1:JnJkREXzWxUdCuPFpIWZiPispT9xVV59uiuyR2bPlnU= +github.com/prometheus/client_golang v1.24.1/go.mod h1:F+oSRECHg4sse5ucfYpYDeIv/hu68Zo0uoHKetWnzcE= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.6.2 h1:oBsgwpGs7iVziMvrGhE53c/GrLUsZdHnqNwqPLxwZyk= github.com/prometheus/client_model v0.6.2/go.mod h1:y3m2F6Gdpfy6Ut/GBsUqTWZqCUvMVzSfMLjcu6wAwpE= -github.com/prometheus/common v0.66.1 h1:h5E0h5/Y8niHc5DlaLlWLArTQI7tMrsfQjHV+d9ZoGs= -github.com/prometheus/common v0.66.1/go.mod h1:gcaUsgf3KfRSwHY4dIMXLPV0K/Wg1oZ8+SbZk/HH/dA= -github.com/prometheus/procfs v0.16.1 h1:hZ15bTNuirocR6u0JZ6BAHHmwS1p8B4P6MRqxtzMyRg= -github.com/prometheus/procfs v0.16.1/go.mod h1:teAbpZRB1iIAJYREa1LsoWUXykVXA1KlTmWl8x/U+Is= +github.com/prometheus/common v0.70.1 h1:1HvjP4D5oL3t8RsPlwxA9onvvStjtIHYE5XuuwOi/PY= +github.com/prometheus/common v0.70.1/go.mod h1:VdFUQDMZK3VLkurFUVhia6uys/0suUp86TJz5qbJRhc= +github.com/prometheus/procfs v0.21.1 h1:GljZCt+zSTS+NZq88cyQ1LjZ+RCHp3uVuabBWA5+OJI= +github.com/prometheus/procfs v0.21.1/go.mod h1:aB55Cww9pdSJVHk0hUf0inxWyyjPogFIjmHKYgMKmtY= github.com/r3labs/sse/v2 v2.10.0 h1:hFEkLLFY4LDifoHdiCN/LlGBAdVJYsANaLqNYa1l/v0= github.com/r3labs/sse/v2 v2.10.0/go.mod h1:Igau6Whc+F17QUgML1fYe1VPZzTV6EMCnYktEmkNJ7I= github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ= @@ -240,8 +240,8 @@ go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= go.uber.org/zap v1.18.1/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI= -go.yaml.in/yaml/v2 v2.4.2 h1:DzmwEr2rDGHl7lsFgAHxmNz/1NlQ7xLIrlN2h5d1eGI= -go.yaml.in/yaml/v2 v2.4.2/go.mod h1:081UH+NErpNdqlCXm3TtEran0rJZGxAYx9hb/ELlsPU= +go.yaml.in/yaml/v2 v2.4.4 h1:tuyd0P+2Ont/d6e2rl3be67goVK4R6deVxCUX5vyPaQ= +go.yaml.in/yaml/v2 v2.4.4/go.mod h1:gMZqIpDtDqOfM0uNfy0SkpRhvUryYH0Z6wdMYcacYXQ= go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc= go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= diff --git a/vendor/github.com/klauspost/compress/flate/inflate_gen.go b/vendor/github.com/klauspost/compress/flate/inflate_gen.go index 2b2f993f7..e80f19656 100644 --- a/vendor/github.com/klauspost/compress/flate/inflate_gen.go +++ b/vendor/github.com/klauspost/compress/flate/inflate_gen.go @@ -10,6 +10,15 @@ import ( "strings" ) +func peekBufio(fr *bufio.Reader) ([]byte, error) { + if fr.Buffered() == 0 { + if _, err := fr.Peek(1); err != nil && fr.Buffered() == 0 { + return nil, err + } + } + return fr.Peek(fr.Buffered()) +} + // Decode a single Huffman block from f. // hl and hd are the Huffman states for the lit/length values // and the distance values, respectively. If hd == nil, using the @@ -527,6 +536,8 @@ func (f *decompressor) huffmanBufioReader() { // but is smart enough to keep local variables in registers, so use nb and b, // inline call to moreBits and reassign b,nb back to f on return. fnb, fb, dict := f.nb, f.b, &f.dict + pbuf, _ := fr.Peek(fr.Buffered()) + pos := 0 switch f.stepState { case stateInit: @@ -548,12 +559,19 @@ readLiteral: n := uint(f.hl.maxRead) for { for fnb < n { - c, err := fr.ReadByte() - if err != nil { - f.b, f.nb = fb, fnb - f.err = noEOF(err) - return + if pos >= len(pbuf) { + fr.Discard(pos) + var err error + pbuf, err = peekBufio(fr) + pos = 0 + if len(pbuf) == 0 { + f.b, f.nb = fb, fnb + f.err = noEOF(err) + return + } } + c := pbuf[pos] + pos++ f.roffset++ fb |= uint32(c) << (fnb & regSizeMaskUint32) fnb += 8 @@ -566,6 +584,7 @@ readLiteral: } if n <= fnb { if n == 0 { + fr.Discard(pos) f.b, f.nb = fb, fnb if debugDecode { fmt.Println("huffsym: n==0") @@ -586,6 +605,7 @@ readLiteral: case v < 256: dict.writeByte(byte(v)) if dict.availWrite() == 0 { + fr.Discard(pos) f.toRead = dict.readFlush() f.step = huffmanBufioReader f.stepState = stateInit @@ -594,6 +614,7 @@ readLiteral: } goto readLiteral case v == 256: + fr.Discard(pos) f.b, f.nb = fb, fnb f.finishBlock() return @@ -605,15 +626,22 @@ readLiteral: length = int(val.length) + 3 n := uint(val.extra) for fnb < n { - c, err := fr.ReadByte() - if err != nil { - f.b, f.nb = fb, fnb - if debugDecode { - fmt.Println("morebits n>0:", err) + if pos >= len(pbuf) { + fr.Discard(pos) + var err error + pbuf, err = peekBufio(fr) + pos = 0 + if len(pbuf) == 0 { + f.b, f.nb = fb, fnb + if debugDecode { + fmt.Println("morebits n>0:", err) + } + f.err = err + return } - f.err = err - return } + c := pbuf[pos] + pos++ f.roffset++ fb |= uint32(c) << (fnb & regSizeMaskUint32) fnb += 8 @@ -622,6 +650,7 @@ readLiteral: fb >>= n & regSizeMaskUint32 fnb -= n default: + fr.Discard(pos) if debugDecode { fmt.Println(v, ">= maxNumLit") } @@ -633,15 +662,22 @@ readLiteral: var dist uint32 if f.hd == nil { for fnb < 5 { - c, err := fr.ReadByte() - if err != nil { - f.b, f.nb = fb, fnb - if debugDecode { - fmt.Println("morebits f.nb<5:", err) + if pos >= len(pbuf) { + fr.Discard(pos) + var err error + pbuf, err = peekBufio(fr) + pos = 0 + if len(pbuf) == 0 { + f.b, f.nb = fb, fnb + if debugDecode { + fmt.Println("morebits f.nb<5:", err) + } + f.err = err + return } - f.err = err - return } + c := pbuf[pos] + pos++ f.roffset++ fb |= uint32(c) << (fnb & regSizeMaskUint32) fnb += 8 @@ -660,12 +696,19 @@ readLiteral: // inline call to moreBits and reassign b,nb back to f on return. for { for fnb < n { - c, err := fr.ReadByte() - if err != nil { - f.b, f.nb = fb, fnb - f.err = noEOF(err) - return + if pos >= len(pbuf) { + fr.Discard(pos) + var err error + pbuf, err = peekBufio(fr) + pos = 0 + if len(pbuf) == 0 { + f.b, f.nb = fb, fnb + f.err = noEOF(err) + return + } } + c := pbuf[pos] + pos++ f.roffset++ fb |= uint32(c) << (fnb & regSizeMaskUint32) fnb += 8 @@ -678,6 +721,7 @@ readLiteral: } if n <= fnb { if n == 0 { + fr.Discard(pos) f.b, f.nb = fb, fnb if debugDecode { fmt.Println("huffsym: n==0") @@ -701,15 +745,22 @@ readLiteral: // have 1 bit in bottom of dist, need nb more. extra := (dist & 1) << (nb & regSizeMaskUint32) for fnb < nb { - c, err := fr.ReadByte() - if err != nil { - f.b, f.nb = fb, fnb - if debugDecode { - fmt.Println("morebits f.nb= len(pbuf) { + fr.Discard(pos) + var err error + pbuf, err = peekBufio(fr) + pos = 0 + if len(pbuf) == 0 { + f.b, f.nb = fb, fnb + if debugDecode { + fmt.Println("morebits f.nb uint32(dict.histSize()) { + fr.Discard(pos) f.b, f.nb = fb, fnb if debugDecode { fmt.Println("dist > dict.histSize():", dist, dict.histSize()) @@ -752,6 +805,7 @@ copyHistory: f.copyLen -= cnt if dict.availWrite() == 0 || f.copyLen > 0 { + fr.Discard(pos) f.toRead = dict.readFlush() f.step = huffmanBufioReader // We need to continue this work f.stepState = stateDict diff --git a/vendor/github.com/klauspost/compress/s2/encode_all.go b/vendor/github.com/klauspost/compress/s2/encode_all.go index 9d12c44f3..794ec8a68 100644 --- a/vendor/github.com/klauspost/compress/s2/encode_all.go +++ b/vendor/github.com/klauspost/compress/s2/encode_all.go @@ -981,7 +981,7 @@ searchDict: cv = load64(src, s) continue } - } else if uint32(cv>>(checkRep*8)) == load32(src, s-repeat+checkRep) { + } else if repeat > 0 && uint32(cv>>(checkRep*8)) == load32(src, s-repeat+checkRep) { base := s + checkRep // Extend back for i := base - repeat; base > nextEmit && i > 0 && src[i-1] == src[base-1]; { diff --git a/vendor/github.com/klauspost/compress/s2/reader.go b/vendor/github.com/klauspost/compress/s2/reader.go index 4d01c4190..17443e2c1 100644 --- a/vendor/github.com/klauspost/compress/s2/reader.go +++ b/vendor/github.com/klauspost/compress/s2/reader.go @@ -216,13 +216,18 @@ func (r *Reader) skippable(tmp []byte, n int, allowEOF bool, id uint8) (ok bool) return r.err == nil } if rs, ok := r.r.(io.ReadSeeker); ok { - _, err := rs.Seek(int64(n), io.SeekCurrent) - if err == nil { - return true - } - if err == io.ErrUnexpectedEOF || (r.err == io.EOF && !allowEOF) { - r.err = ErrCorrupt - return false + if cur, err := rs.Seek(0, io.SeekCurrent); err == nil { + if end, err := rs.Seek(0, io.SeekEnd); err == nil { + if cur+int64(n) <= end { + if _, err := rs.Seek(cur+int64(n), io.SeekStart); err == nil { + return true + } + } + if _, err := rs.Seek(cur, io.SeekStart); err != nil { + r.err = ErrCorrupt + return false + } + } } } for n > 0 { diff --git a/vendor/github.com/klauspost/compress/snappy/decode_strict.go b/vendor/github.com/klauspost/compress/snappy/decode_strict.go new file mode 100644 index 000000000..6c28bcbbb --- /dev/null +++ b/vendor/github.com/klauspost/compress/snappy/decode_strict.go @@ -0,0 +1,130 @@ +// Copyright 2011 The Snappy-Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package snappy + +import "encoding/binary" + +// DecodeStrict returns the decoded form of src, like Decode. +// +// Unlike Decode, which delegates to the s2 decoder and accepts the s2 +// "repeat last offset" extension (a copy whose encoded offset is 0), +// DecodeStrict uses a strict standard-Snappy block decoder. Offset 0 is not +// valid in the standard Snappy block format, so such a copy is rejected with +// ErrCorrupt. This makes DecodeStrict match github.com/golang/snappy and the +// C++ reference decoder, at the cost of being slower than Decode. +// +// The returned slice may be a sub-slice of dst if dst was large enough to +// hold the entire decoded block. Otherwise, a newly allocated slice will be +// returned. +// +// The dst and src must not overlap. It is valid to pass a nil dst. +// +// DecodeStrict handles the Snappy block format, not the Snappy stream format. +func DecodeStrict(dst, src []byte) ([]byte, error) { + v, n := binary.Uvarint(src) + if n <= 0 || n > 5 || v > 0xffffffff { + return nil, ErrCorrupt + } + const wordSize = 32 << (^uint(0) >> 32 & 1) + if wordSize == 32 && v > 0x7fffffff { + return nil, ErrTooLarge + } + dLen := int(v) + if dLen <= cap(dst) { + dst = dst[:dLen] + } else { + dst = make([]byte, dLen) + } + if decodeStrict(dst, src[n:]) != 0 { + return nil, ErrCorrupt + } + return dst, nil +} + +func decodeStrict(dst, src []byte) int { + var d, s, offset, length int + for s < len(src) { + switch src[s] & 0x03 { + case 0x00: + x := uint32(src[s] >> 2) + switch { + case x < 60: + s++ + case x == 60: + s += 2 + if uint(s) > uint(len(src)) { + return 1 + } + x = uint32(src[s-1]) + case x == 61: + s += 3 + if uint(s) > uint(len(src)) { + return 1 + } + x = uint32(src[s-2]) | uint32(src[s-1])<<8 + case x == 62: + s += 4 + if uint(s) > uint(len(src)) { + return 1 + } + x = uint32(src[s-3]) | uint32(src[s-2])<<8 | uint32(src[s-1])<<16 + case x == 63: + s += 5 + if uint(s) > uint(len(src)) { + return 1 + } + x = uint32(src[s-4]) | uint32(src[s-3])<<8 | uint32(src[s-2])<<16 | uint32(src[s-1])<<24 + } + length = int(x) + 1 + if length <= 0 || length > len(dst)-d || length > len(src)-s { + return 1 + } + copy(dst[d:], src[s:s+length]) + d += length + s += length + continue + case 0x01: + s += 2 + if uint(s) > uint(len(src)) { + return 1 + } + length = 4 + int(src[s-2])>>2&0x7 + offset = int(uint32(src[s-2])&0xe0<<3 | uint32(src[s-1])) + case 0x02: + s += 3 + if uint(s) > uint(len(src)) { + return 1 + } + length = 1 + int(src[s-3])>>2 + offset = int(uint32(src[s-2]) | uint32(src[s-1])<<8) + case 0x03: + s += 5 + if uint(s) > uint(len(src)) { + return 1 + } + length = 1 + int(src[s-5])>>2 + offset = int(uint32(src[s-4]) | uint32(src[s-3])<<8 | uint32(src[s-2])<<16 | uint32(src[s-1])<<24) + } + if offset <= 0 || d < offset || length > len(dst)-d { + return 1 + } + if offset >= length { + copy(dst[d:d+length], dst[d-offset:]) + d += length + continue + } + a := dst[d : d+length] + b := dst[d-offset:] + b = b[:len(a)] + for i := range a { + a[i] = b[i] + } + d += length + } + if d != len(dst) { + return 1 + } + return 0 +} diff --git a/vendor/github.com/klauspost/compress/zstd/fse_decoder_arm64.s b/vendor/github.com/klauspost/compress/zstd/fse_decoder_arm64.s index 661761fb2..77ee3913f 100644 --- a/vendor/github.com/klauspost/compress/zstd/fse_decoder_arm64.s +++ b/vendor/github.com/klauspost/compress/zstd/fse_decoder_arm64.s @@ -28,7 +28,10 @@ TEXT ·buildDtable_asm(SB), $0-24 init_main_loop: ADD R8<<1, R1, R15 MOVH (R15), R9 - CMN $1, R9 + AND $0xffff, R9, R15 + MOVD $-1, R16 + AND $0xffff, R16, R16 + CMP R16, R15 BNE do_not_update_high_threshold ADD R7<<3, R5, R15 MOVB R8, 1(R15) @@ -126,9 +129,13 @@ build_table_main_table: RET build_table_check1_ok: - TST R1, R1 + AND $0xff, R1, R15 + AND $0xff, R1, R16 + TST R16, R15 BNE build_table_check2_ok - CMP R6, R7 + AND $0xffff, R7, R15 + AND $0xffff, R6, R16 + CMP R16, R15 BNE build_table_check2_ok MOVD ctx+8(FP), R0 MOVD R7, 24(R0) diff --git a/vendor/github.com/klauspost/compress/zstd/seqdec_arm64.s b/vendor/github.com/klauspost/compress/zstd/seqdec_arm64.s index 75b19d732..a468e5fc2 100644 --- a/vendor/github.com/klauspost/compress/zstd/seqdec_arm64.s +++ b/vendor/github.com/klauspost/compress/zstd/seqdec_arm64.s @@ -670,9 +670,9 @@ error_overread: MOVD R16, ret+24(FP) RET -// skipped sequenceDecs_decode_bmi2 (BMI2 not available on arm64) +// skipped sequenceDecs_decode_bmi2 (generic twin preferred on arm64) -// skipped sequenceDecs_decode_56_bmi2 (BMI2 not available on arm64) +// skipped sequenceDecs_decode_56_bmi2 (generic twin preferred on arm64) // func sequenceDecs_executeSimple_amd64(ctx *executeAsmContext) bool // Requires: SSE @@ -1966,7 +1966,7 @@ error_not_enough_space: MOVD R16, ret+24(FP) RET -// skipped sequenceDecs_decodeSync_bmi2 (BMI2 not available on arm64) +// skipped sequenceDecs_decodeSync_bmi2 (generic twin preferred on arm64) // func sequenceDecs_decodeSync_safe_amd64(s *sequenceDecs, br *bitReader, ctx *decodeSyncAsmContext) int // Requires: CMOV, SSE @@ -2702,4 +2702,4 @@ error_not_enough_space: MOVD R16, ret+24(FP) RET -// skipped sequenceDecs_decodeSync_safe_bmi2 (BMI2 not available on arm64) +// skipped sequenceDecs_decodeSync_safe_bmi2 (generic twin preferred on arm64) diff --git a/vendor/github.com/klauspost/compress/zstd/snappy.go b/vendor/github.com/klauspost/compress/zstd/snappy.go index 336c28893..36c56f36d 100644 --- a/vendor/github.com/klauspost/compress/zstd/snappy.go +++ b/vendor/github.com/klauspost/compress/zstd/snappy.go @@ -334,9 +334,10 @@ func decodeSnappy(blk *blockEnc, src []byte) error { return errUnsupportedLiteralLength } - //if length > snappyMaxBlockSize-d || uint32(length) > len(src)-s { - // return ErrSnappyCorrupt - //} + if length > len(src)-s { + println("length > len(src)-s", length, len(src)-s) + return ErrSnappyCorrupt + } blk.literals = append(blk.literals, src[s:s+length]...) //println(length, "litLen") diff --git a/vendor/github.com/prometheus/client_golang/internal/github.com/golang/gddo/httputil/header/header.go b/vendor/github.com/prometheus/client_golang/internal/github.com/golang/gddo/httputil/header/header.go index 8547c8dfd..820bf436a 100644 --- a/vendor/github.com/prometheus/client_golang/internal/github.com/golang/gddo/httputil/header/header.go +++ b/vendor/github.com/prometheus/client_golang/internal/github.com/golang/gddo/httputil/header/header.go @@ -90,7 +90,7 @@ loop: s = skipSpace(s[1:]) } } - return + return specs } func skipSpace(s string) (rest string) { diff --git a/vendor/github.com/prometheus/client_golang/prometheus/counter.go b/vendor/github.com/prometheus/client_golang/prometheus/counter.go index 4ce84e7a8..7d963d3af 100644 --- a/vendor/github.com/prometheus/client_golang/prometheus/counter.go +++ b/vendor/github.com/prometheus/client_golang/prometheus/counter.go @@ -85,11 +85,12 @@ type CounterVecOpts struct { // Both internal tracking values are added up in the Write method. This has to // be taken into account when it comes to precision and overflow behavior. func NewCounter(opts CounterOpts) Counter { - desc := NewDesc( + desc := V2.NewDesc( BuildFQName(opts.Namespace, opts.Subsystem, opts.Name), opts.Help, - nil, + UnconstrainedLabels(nil), opts.ConstLabels, + WithUnit(opts.Unit), ) if opts.now == nil { opts.now = time.Now @@ -205,6 +206,7 @@ func (v2) NewCounterVec(opts CounterVecOpts) *CounterVec { opts.Help, opts.VariableLabels, opts.ConstLabels, + WithUnit(opts.Unit), ) if opts.now == nil { opts.now = time.Now @@ -349,10 +351,11 @@ type CounterFunc interface { // // Check out the ExampleGaugeFunc examples for the similar GaugeFunc. func NewCounterFunc(opts CounterOpts, function func() float64) CounterFunc { - return newValueFunc(NewDesc( + return newValueFunc(V2.NewDesc( BuildFQName(opts.Namespace, opts.Subsystem, opts.Name), opts.Help, - nil, + UnconstrainedLabels(nil), opts.ConstLabels, + WithUnit(opts.Unit), ), CounterValue, function) } diff --git a/vendor/github.com/prometheus/client_golang/prometheus/desc.go b/vendor/github.com/prometheus/client_golang/prometheus/desc.go index 2331b8b4f..a3c92e7a4 100644 --- a/vendor/github.com/prometheus/client_golang/prometheus/desc.go +++ b/vendor/github.com/prometheus/client_golang/prometheus/desc.go @@ -47,6 +47,8 @@ type Desc struct { fqName string // help provides some helpful information about this metric. help string + // unit provides the unit of this metric. + unit string // constLabelPairs contains precalculated DTO label pairs based on // the constant labels. constLabelPairs []*dto.LabelPair @@ -66,6 +68,16 @@ type Desc struct { err error } +// DescOpt allows setting optional fields for NewDesc. +type DescOpt func(*Desc) + +// WithUnit sets the unit for a Desc. +func WithUnit(unit string) DescOpt { + return func(d *Desc) { + d.unit = unit + } +} + // NewDesc allocates and initializes a new Desc. Errors are recorded in the Desc // and will be reported on registration time. variableLabels and constLabels can // be nil if no such labels should be set. fqName must not be empty. @@ -89,14 +101,17 @@ func NewDesc(fqName, help string, variableLabels []string, constLabels Labels) * // // For constLabels, the label values are constant. Therefore, they are fully // specified in the Desc. See the Collector example for a usage pattern. -func (v2) NewDesc(fqName, help string, variableLabels ConstrainableLabels, constLabels Labels) *Desc { +func (v2) NewDesc(fqName, help string, variableLabels ConstrainableLabels, constLabels Labels, opts ...DescOpt) *Desc { d := &Desc{ fqName: fqName, help: help, variableLabels: variableLabels.compile(), } - //nolint:staticcheck // TODO: Don't use deprecated model.NameValidationScheme. - if !model.NameValidationScheme.IsValidMetricName(fqName) { + + for _, opt := range opts { + opt(d) + } + if !model.UTF8Validation.IsValidMetricName(fqName) { d.err = fmt.Errorf("%q is not a valid metric name", fqName) return d } @@ -150,11 +165,13 @@ func (v2) NewDesc(fqName, help string, variableLabels ConstrainableLabels, const d.id = xxh.Sum64() // Sort labelNames so that order doesn't matter for the hash. sort.Strings(labelNames) - // Now hash together (in this order) the help string and the sorted + // Now hash together (in this order) the help string, the unit string and the sorted // label names. xxh.Reset() xxh.WriteString(help) xxh.Write(separatorByteSlice) + xxh.WriteString(d.unit) + xxh.Write(separatorByteSlice) for _, labelName := range labelNames { xxh.WriteString(labelName) xxh.Write(separatorByteSlice) @@ -182,6 +199,15 @@ func NewInvalidDesc(err error) *Desc { } } +// Err returns an error that occurred during construction, if any. +// +// Calling this method is optional. It can be used to detect construction +// errors early, before invoking other methods on the Desc. If an error is +// present, later operations may not behave as expected. +func (d *Desc) Err() error { + return d.err +} + func (d *Desc) String() string { lpStrings := make([]string, 0, len(d.constLabelPairs)) for _, lp := range d.constLabelPairs { @@ -202,9 +228,10 @@ func (d *Desc) String() string { } } return fmt.Sprintf( - "Desc{fqName: %q, help: %q, constLabels: {%s}, variableLabels: {%s}}", + "Desc{fqName: %q, help: %q, unit: %q, constLabels: {%s}, variableLabels: {%s}}", d.fqName, d.help, + d.unit, strings.Join(lpStrings, ","), strings.Join(vlStrings, ","), ) diff --git a/vendor/github.com/prometheus/client_golang/prometheus/expvar_collector.go b/vendor/github.com/prometheus/client_golang/prometheus/expvar_collector.go index de5a85629..327746f43 100644 --- a/vendor/github.com/prometheus/client_golang/prometheus/expvar_collector.go +++ b/vendor/github.com/prometheus/client_golang/prometheus/expvar_collector.go @@ -47,14 +47,14 @@ func (e *expvarCollector) Collect(ch chan<- Metric) { if expVar == nil { continue } - var v interface{} + var v any labels := make([]string, len(desc.variableLabels.names)) if err := json.Unmarshal([]byte(expVar.String()), &v); err != nil { ch <- NewInvalidMetric(desc, err) continue } - var processValue func(v interface{}, i int) - processValue = func(v interface{}, i int) { + var processValue func(v any, i int) + processValue = func(v any, i int) { if i >= len(labels) { copiedLabels := append(make([]string, 0, len(labels)), labels...) switch v := v.(type) { @@ -72,7 +72,7 @@ func (e *expvarCollector) Collect(ch chan<- Metric) { ch <- m return } - vm, ok := v.(map[string]interface{}) + vm, ok := v.(map[string]any) if !ok { return } diff --git a/vendor/github.com/prometheus/client_golang/prometheus/gauge.go b/vendor/github.com/prometheus/client_golang/prometheus/gauge.go index dd2eac940..41e54bf27 100644 --- a/vendor/github.com/prometheus/client_golang/prometheus/gauge.go +++ b/vendor/github.com/prometheus/client_golang/prometheus/gauge.go @@ -76,11 +76,12 @@ type GaugeVecOpts struct { // scenarios for Gauges and Counters, where the former tends to be Set-heavy and // the latter Inc-heavy. func NewGauge(opts GaugeOpts) Gauge { - desc := NewDesc( + desc := V2.NewDesc( BuildFQName(opts.Namespace, opts.Subsystem, opts.Name), opts.Help, - nil, + UnconstrainedLabels(nil), opts.ConstLabels, + WithUnit(opts.Unit), ) result := &gauge{desc: desc, labelPairs: desc.constLabelPairs} result.init(result) // Init self-collection. @@ -163,6 +164,7 @@ func (v2) NewGaugeVec(opts GaugeVecOpts) *GaugeVec { opts.Help, opts.VariableLabels, opts.ConstLabels, + WithUnit(opts.Unit), ) return &GaugeVec{ MetricVec: NewMetricVec(desc, func(lvs ...string) Metric { @@ -302,10 +304,11 @@ type GaugeFunc interface { // value of 1. Example: // https://github.com/prometheus/common/blob/8558a5b7db3c84fa38b4766966059a7bd5bfa2ee/version/info.go#L36-L56 func NewGaugeFunc(opts GaugeOpts, function func() float64) GaugeFunc { - return newValueFunc(NewDesc( + return newValueFunc(V2.NewDesc( BuildFQName(opts.Namespace, opts.Subsystem, opts.Name), opts.Help, - nil, + UnconstrainedLabels(nil), opts.ConstLabels, + WithUnit(opts.Unit), ), GaugeValue, function) } diff --git a/vendor/github.com/prometheus/client_golang/prometheus/go_collector_go116.go b/vendor/github.com/prometheus/client_golang/prometheus/go_collector_go116.go deleted file mode 100644 index 897a6e906..000000000 --- a/vendor/github.com/prometheus/client_golang/prometheus/go_collector_go116.go +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright 2021 The Prometheus 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. - -//go:build !go1.17 -// +build !go1.17 - -package prometheus - -import ( - "runtime" - "sync" - "time" -) - -type goCollector struct { - base baseGoCollector - - // ms... are memstats related. - msLast *runtime.MemStats // Previously collected memstats. - msLastTimestamp time.Time - msMtx sync.Mutex // Protects msLast and msLastTimestamp. - msMetrics memStatsMetrics - msRead func(*runtime.MemStats) // For mocking in tests. - msMaxWait time.Duration // Wait time for fresh memstats. - msMaxAge time.Duration // Maximum allowed age of old memstats. -} - -// NewGoCollector is the obsolete version of collectors.NewGoCollector. -// See there for documentation. -// -// Deprecated: Use collectors.NewGoCollector instead. -func NewGoCollector() Collector { - msMetrics := goRuntimeMemStats() - msMetrics = append(msMetrics, struct { - desc *Desc - eval func(*runtime.MemStats) float64 - valType ValueType - }{ - // This metric is omitted in Go1.17+, see https://github.com/prometheus/client_golang/issues/842#issuecomment-861812034 - desc: NewDesc( - memstatNamespace("gc_cpu_fraction"), - "The fraction of this program's available CPU time used by the GC since the program started.", - nil, nil, - ), - eval: func(ms *runtime.MemStats) float64 { return ms.GCCPUFraction }, - valType: GaugeValue, - }) - return &goCollector{ - base: newBaseGoCollector(), - msLast: &runtime.MemStats{}, - msRead: runtime.ReadMemStats, - msMaxWait: time.Second, - msMaxAge: 5 * time.Minute, - msMetrics: msMetrics, - } -} - -// Describe returns all descriptions of the collector. -func (c *goCollector) Describe(ch chan<- *Desc) { - c.base.Describe(ch) - for _, i := range c.msMetrics { - ch <- i.desc - } -} - -// Collect returns the current state of all metrics of the collector. -func (c *goCollector) Collect(ch chan<- Metric) { - var ( - ms = &runtime.MemStats{} - done = make(chan struct{}) - ) - // Start reading memstats first as it might take a while. - go func() { - c.msRead(ms) - c.msMtx.Lock() - c.msLast = ms - c.msLastTimestamp = time.Now() - c.msMtx.Unlock() - close(done) - }() - - // Collect base non-memory metrics. - c.base.Collect(ch) - - timer := time.NewTimer(c.msMaxWait) - select { - case <-done: // Our own ReadMemStats succeeded in time. Use it. - timer.Stop() // Important for high collection frequencies to not pile up timers. - c.msCollect(ch, ms) - return - case <-timer.C: // Time out, use last memstats if possible. Continue below. - } - c.msMtx.Lock() - if time.Since(c.msLastTimestamp) < c.msMaxAge { - // Last memstats are recent enough. Collect from them under the lock. - c.msCollect(ch, c.msLast) - c.msMtx.Unlock() - return - } - // If we are here, the last memstats are too old or don't exist. We have - // to wait until our own ReadMemStats finally completes. For that to - // happen, we have to release the lock. - c.msMtx.Unlock() - <-done - c.msCollect(ch, ms) -} - -func (c *goCollector) msCollect(ch chan<- Metric, ms *runtime.MemStats) { - for _, i := range c.msMetrics { - ch <- MustNewConstMetric(i.desc, i.valType, i.eval(ms)) - } -} diff --git a/vendor/github.com/prometheus/client_golang/prometheus/go_collector_latest.go b/vendor/github.com/prometheus/client_golang/prometheus/go_collector_latest.go index 6b8684731..1db1c4be0 100644 --- a/vendor/github.com/prometheus/client_golang/prometheus/go_collector_latest.go +++ b/vendor/github.com/prometheus/client_golang/prometheus/go_collector_latest.go @@ -98,7 +98,7 @@ type goCollector struct { // snapshot is always produced by Collect. mu sync.Mutex - // Contains all samples that has to retrieved from runtime/metrics (not all of them will be exposed). + // Contains all samples that have to be retrieved from runtime/metrics (not all of them will be exposed). sampleBuf []metrics.Sample // sampleMap allows lookup for MemStats metrics and runtime/metrics histograms for exact sums. sampleMap map[string]*metrics.Sample @@ -210,16 +210,26 @@ func NewGoCollector(opts ...func(o *internal.GoCollectorOptions)) Collector { sampleBuf = append(sampleBuf, metrics.Sample{Name: d.Name}) sampleMap[d.Name] = &sampleBuf[len(sampleBuf)-1] + // Extract unit from the runtime/metrics name (e.g., "/gc/heap/allocs:bytes" -> "bytes") + // and sanitize to match Prometheus naming conventions (e.g., "cpu-seconds" -> "cpu_seconds") + var unit string + if idx := strings.IndexRune(d.Name, ':'); idx >= 0 { + unit = d.Name[idx+1:] + unit = strings.ReplaceAll(unit, "-", "_") + unit = strings.ReplaceAll(unit, "*", "_") + unit = strings.ReplaceAll(unit, "/", "_per_") + } + var m collectorMetric if d.Kind == metrics.KindFloat64Histogram { _, hasSum := opt.RuntimeMetricSumForHist[d.Name] - unit := d.Name[strings.IndexRune(d.Name, ':')+1:] m = newBatchHistogram( - NewDesc( + V2.NewDesc( BuildFQName(namespace, subsystem, name), help, + UnconstrainedLabels(nil), nil, - nil, + WithUnit(unit), ), internal.RuntimeMetricsBucketsForUnit(bucketsMap[d.Name], unit), hasSum, @@ -230,6 +240,7 @@ func NewGoCollector(opts ...func(o *internal.GoCollectorOptions)) Collector { Subsystem: subsystem, Name: name, Help: help, + Unit: unit, }, ) } else { @@ -238,6 +249,7 @@ func NewGoCollector(opts ...func(o *internal.GoCollectorOptions)) Collector { Subsystem: subsystem, Name: name, Help: help, + Unit: unit, }) } metricSet = append(metricSet, m) diff --git a/vendor/github.com/prometheus/client_golang/prometheus/histogram.go b/vendor/github.com/prometheus/client_golang/prometheus/histogram.go index c453b754a..88bae3b32 100644 --- a/vendor/github.com/prometheus/client_golang/prometheus/histogram.go +++ b/vendor/github.com/prometheus/client_golang/prometheus/histogram.go @@ -378,6 +378,9 @@ type HistogramOpts struct { // string. Help string + // Unit provides the unit of this Histogram. + Unit string + // ConstLabels are used to attach fixed labels to this metric. Metrics // with the same fully-qualified name must have the same label names in // their ConstLabels. @@ -522,11 +525,12 @@ type HistogramVecOpts struct { // for each bucket. func NewHistogram(opts HistogramOpts) Histogram { return newHistogram( - NewDesc( + V2.NewDesc( BuildFQName(opts.Namespace, opts.Subsystem, opts.Name), opts.Help, - nil, + UnconstrainedLabels(nil), opts.ConstLabels, + WithUnit(opts.Unit), ), opts, ) @@ -966,7 +970,7 @@ func (h *histogram) maybeReset( // We are using the possibly mocked h.now() rather than // time.Since(h.lastResetTime) to enable testing. if h.nativeHistogramMinResetDuration == 0 || // No reset configured. - h.resetScheduled || // Do not interefere if a reset is already scheduled. + h.resetScheduled || // Do not interfere if a reset is already scheduled. h.now().Sub(h.lastResetTime) < h.nativeHistogramMinResetDuration { return false } @@ -1053,8 +1057,8 @@ func (h *histogram) maybeWidenZeroBucket(hot, cold *histogramCounts) bool { atomic.StoreUint64(&cold.nativeHistogramZeroThresholdBits, math.Float64bits(newZeroThreshold)) // ...and then merge the newly deleted buckets into the wider zero // bucket. - mergeAndDeleteOrAddAndReset := func(hotBuckets, coldBuckets *sync.Map) func(k, v interface{}) bool { - return func(k, v interface{}) bool { + mergeAndDeleteOrAddAndReset := func(hotBuckets, coldBuckets *sync.Map) func(k, v any) bool { + return func(k, v any) bool { key := k.(int) bucket := v.(*int64) if key == smallestKey { @@ -1107,8 +1111,8 @@ func (h *histogram) doubleBucketWidth(hot, cold *histogramCounts) { // ...adjust the schema in the cold counts, too... atomic.StoreInt32(&cold.nativeHistogramSchema, coldSchema) // ...and then merge the cold buckets into the wider hot buckets. - merge := func(hotBuckets *sync.Map) func(k, v interface{}) bool { - return func(k, v interface{}) bool { + merge := func(hotBuckets *sync.Map) func(k, v any) bool { + return func(k, v any) bool { key := k.(int) bucket := v.(*int64) // Adjust key to match the bucket to merge into. @@ -1190,6 +1194,7 @@ func (v2) NewHistogramVec(opts HistogramVecOpts) *HistogramVec { opts.Help, opts.VariableLabels, opts.ConstLabels, + WithUnit(opts.Unit), ) return &HistogramVec{ MetricVec: NewMetricVec(desc, func(lvs ...string) Metric { @@ -1476,7 +1481,7 @@ func pickSchema(bucketFactor float64) int32 { func makeBuckets(buckets *sync.Map) ([]*dto.BucketSpan, []int64) { var ii []int - buckets.Range(func(k, v interface{}) bool { + buckets.Range(func(k, v any) bool { ii = append(ii, k.(int)) return true }) @@ -1553,8 +1558,8 @@ func addToBucket(buckets *sync.Map, key int, increment int64) bool { // according to the buckets ranged through. It then resets all buckets ranged // through to 0 (but leaves them in place so that they don't need to get // recreated on the next scrape). -func addAndReset(hotBuckets *sync.Map, bucketNumber *uint32) func(k, v interface{}) bool { - return func(k, v interface{}) bool { +func addAndReset(hotBuckets *sync.Map, bucketNumber *uint32) func(k, v any) bool { + return func(k, v any) bool { bucket := v.(*int64) if addToBucket(hotBuckets, k.(int), atomic.LoadInt64(bucket)) { atomic.AddUint32(bucketNumber, 1) @@ -1565,7 +1570,7 @@ func addAndReset(hotBuckets *sync.Map, bucketNumber *uint32) func(k, v interface } func deleteSyncMap(m *sync.Map) { - m.Range(func(k, v interface{}) bool { + m.Range(func(k, v any) bool { m.Delete(k) return true }) @@ -1573,7 +1578,7 @@ func deleteSyncMap(m *sync.Map) { func findSmallestKey(m *sync.Map) int { result := math.MaxInt32 - m.Range(func(k, v interface{}) bool { + m.Range(func(k, v any) bool { key := k.(int) if key < result { result = key diff --git a/vendor/github.com/prometheus/client_golang/prometheus/internal/difflib.go b/vendor/github.com/prometheus/client_golang/prometheus/internal/difflib.go index 7bac0da33..2db270f21 100644 --- a/vendor/github.com/prometheus/client_golang/prometheus/internal/difflib.go +++ b/vendor/github.com/prometheus/client_golang/prometheus/internal/difflib.go @@ -78,7 +78,7 @@ type OpCode struct { // notion, pairing up elements that appear uniquely in each sequence. // That, and the method here, appear to yield more intuitive difference // reports than does diff. This method appears to be the least vulnerable -// to synching up on blocks of "junk lines", though (like blank lines in +// to syncing up on blocks of "junk lines", though (like blank lines in // ordinary text files, or maybe "

" lines in HTML files). That may be // because this is the only method of the 3 that has a *concept* of // "junk" . @@ -567,7 +567,7 @@ type UnifiedDiff struct { func WriteUnifiedDiff(writer io.Writer, diff UnifiedDiff) error { buf := bufio.NewWriter(writer) defer buf.Flush() - wf := func(format string, args ...interface{}) error { + wf := func(format string, args ...any) error { _, err := fmt.Fprintf(buf, format, args...) return err } diff --git a/vendor/github.com/prometheus/client_golang/prometheus/labels.go b/vendor/github.com/prometheus/client_golang/prometheus/labels.go index 5fe8d3b4d..a0285489a 100644 --- a/vendor/github.com/prometheus/client_golang/prometheus/labels.go +++ b/vendor/github.com/prometheus/client_golang/prometheus/labels.go @@ -184,6 +184,5 @@ func validateLabelValues(vals []string, expectedNumberOfValues int) error { } func checkLabelName(l string) bool { - //nolint:staticcheck // TODO: Don't use deprecated model.NameValidationScheme. - return model.NameValidationScheme.IsValidLabelName(l) && !strings.HasPrefix(l, reservedLabelPrefix) + return model.UTF8Validation.IsValidLabelName(l) && !strings.HasPrefix(l, reservedLabelPrefix) } diff --git a/vendor/github.com/prometheus/client_golang/prometheus/metric.go b/vendor/github.com/prometheus/client_golang/prometheus/metric.go index 76e59f128..c5cb90adf 100644 --- a/vendor/github.com/prometheus/client_golang/prometheus/metric.go +++ b/vendor/github.com/prometheus/client_golang/prometheus/metric.go @@ -81,6 +81,9 @@ type Opts struct { // string. Help string + // Unit provides the unit of this metric as per https://prometheus.io/docs/specs/om + Unit string + // ConstLabels are used to attach fixed labels to this metric. Metrics // with the same fully-qualified name must have the same label names in // their ConstLabels. diff --git a/vendor/github.com/prometheus/client_golang/prometheus/process_collector_darwin.go b/vendor/github.com/prometheus/client_golang/prometheus/process_collector_darwin.go index b32c95fa3..2b16298f4 100644 --- a/vendor/github.com/prometheus/client_golang/prometheus/process_collector_darwin.go +++ b/vendor/github.com/prometheus/client_golang/prometheus/process_collector_darwin.go @@ -72,7 +72,13 @@ func getOpenFileCount() (float64, error) { } func (c *processCollector) processCollect(ch chan<- Metric) { - if procs, err := unix.SysctlKinfoProcSlice("kern.proc.pid", os.Getpid()); err == nil { + pid, err := c.pidFn() + if err != nil { + c.reportError(ch, nil, err) + return + } + + if procs, err := unix.SysctlKinfoProcSlice("kern.proc.pid", pid); err == nil { if len(procs) == 1 { startTime := float64(procs[0].Proc.P_starttime.Nano() / 1e9) ch <- MustNewConstMetric(c.startTime, GaugeValue, startTime) @@ -84,6 +90,11 @@ func (c *processCollector) processCollect(ch chan<- Metric) { c.reportError(ch, c.startTime, err) } + if pid != os.Getpid() { + c.reportError(ch, nil, fmt.Errorf("collecting metrics for pid %d is not supported on darwin: process metrics collection is limited to the current process (pid %d)", pid, os.Getpid())) + return + } + // The proc structure returned by kern.proc.pid above has an Rusage member, // but it is not filled in, so it needs to be fetched by getrusage(2). For // that call, the UTime, STime, and Maxrss members are filled out, but not diff --git a/vendor/github.com/prometheus/client_golang/prometheus/process_collector_windows.go b/vendor/github.com/prometheus/client_golang/prometheus/process_collector_windows.go index fa474289e..c08dd05f0 100644 --- a/vendor/github.com/prometheus/client_golang/prometheus/process_collector_windows.go +++ b/vendor/github.com/prometheus/client_golang/prometheus/process_collector_windows.go @@ -30,6 +30,10 @@ var ( procGetProcessMemoryInfo = modpsapi.NewProc("GetProcessMemoryInfo") procGetProcessHandleCount = modkernel32.NewProc("GetProcessHandleCount") + + openProcess = windows.OpenProcess + closeHandle = windows.CloseHandle + getProcessTimes = windows.GetProcessTimes ) type processMemoryCounters struct { @@ -79,10 +83,21 @@ func getProcessHandleCount(handle windows.Handle) (uint32, error) { } func (c *processCollector) processCollect(ch chan<- Metric) { - h := windows.CurrentProcess() + pid, err := c.pidFn() + if err != nil { + c.reportError(ch, nil, err) + return + } + + h, err := openProcess(windows.PROCESS_QUERY_INFORMATION|windows.PROCESS_VM_READ, false, uint32(pid)) + if err != nil { + c.reportError(ch, nil, err) + return + } + defer closeHandle(h) var startTime, exitTime, kernelTime, userTime windows.Filetime - err := windows.GetProcessTimes(h, &startTime, &exitTime, &kernelTime, &userTime) + err = getProcessTimes(h, &startTime, &exitTime, &kernelTime, &userTime) if err != nil { c.reportError(ch, nil, err) return diff --git a/vendor/github.com/prometheus/client_golang/prometheus/promhttp/http.go b/vendor/github.com/prometheus/client_golang/prometheus/promhttp/http.go index 763d99e36..c28af5ce2 100644 --- a/vendor/github.com/prometheus/client_golang/prometheus/promhttp/http.go +++ b/vendor/github.com/prometheus/client_golang/prometheus/promhttp/http.go @@ -37,10 +37,12 @@ import ( "fmt" "io" "net/http" + "slices" "strconv" "sync" "time" + dto "github.com/prometheus/client_model/go" "github.com/prometheus/common/expfmt" "github.com/prometheus/client_golang/internal/github.com/golang/gddo/httputil" @@ -74,11 +76,118 @@ func defaultCompressionFormats() []Compression { } var gzipPool = sync.Pool{ - New: func() interface{} { + New: func() any { return gzip.NewWriter(nil) }, } +// coalescingGatherer wraps a TransactionalGatherer to deduplicate concurrent +// Gather calls. When a Gather is already in flight, new callers join the +// existing cycle and receive the same result once it completes. The underlying +// done function is called exactly once, when the last joined caller releases. +// +// This prevents goroutine pile-up when the scrape rate is faster than the +// time collectors need to produce metrics. +type coalescingGatherer struct { + g prometheus.TransactionalGatherer + mu sync.Mutex + cycle *gatherCycle +} + +// gatherCycle tracks a single in-flight Gather and all HTTP handlers sharing it. +type gatherCycle struct { + ready chan struct{} // closed when Gather completes; happens-before reads of mfs/err/done + mfs []*dto.MetricFamily // canonical result, set before ready is closed; callers get a slices.Clone, the element values stay shared and must not be mutated + err error // set before ready is closed + done func() // underlying done callback; set before ready is closed + refs int // number of handlers using this cycle; protected by coalescingGatherer.mu +} + +var _ prometheus.TransactionalGatherer = (*coalescingGatherer)(nil) // compile-time interface check + +// errGatherPanicked is returned to callers that joined an in-flight coalesced +// Gather whose underlying gatherer panicked. See the panic guard in Gather for +// why joiners receive this error instead of the panic itself. +var errGatherPanicked = errors.New("coalesced gather panicked") + +func (c *coalescingGatherer) Gather() ([]*dto.MetricFamily, func(), error) { + c.mu.Lock() + if cy := c.cycle; cy != nil { + // c.cycle is non-nil while Gather runs or handlers are still consuming its results. + cy.refs++ + c.mu.Unlock() + <-cy.ready + // Each caller gets its own slice header so it can filter or reorder + // without racing other callers sharing this cycle. The *dto.MetricFamily + // values remain shared and must not be mutated in place. + return slices.Clone(cy.mfs), c.releaseFunc(cy), cy.err + } + cy := &gatherCycle{ + ready: make(chan struct{}), + done: func() {}, + refs: 1, + } + c.cycle = cy + c.mu.Unlock() + + // Guard against a panic in c.g.Gather. The common case, a panicking + // Collector, never reaches here: Registry.Gather recovers Collector panics + // and returns them as an error. This guard only covers the rare case where + // the wrapped gatherer itself panics. + // + // We deliberately do not recover: the leader's panic propagates and is + // handled by net/http exactly as it would be without coalescing. We only + // set cy.err before closing cy.ready so joiners waiting on <-cy.ready fail + // with that error instead of silently returning an empty, successful + // response, and we clear c.cycle so the next Gather starts a fresh cycle. + // + // The leader never runs its own releaseFunc on this path, so its ref is + // not decremented; that is harmless because the cycle is detached (c.cycle + // = nil) and cy.done is still the no-op set at construction (c.g.Gather + // panicked before assigning a real done). If cy.done is ever made non-nil + // before c.g.Gather runs, this path would need to release it. + panicked := true + defer func() { + if panicked { + c.mu.Lock() + if c.cycle == cy { + c.cycle = nil + } + c.mu.Unlock() + cy.err = errGatherPanicked // set before close: happens-before joiners' reads + close(cy.ready) + } + }() + cy.mfs, cy.done, cy.err = c.g.Gather() + panicked = false + close(cy.ready) // happens-before joiners' reads of cy.mfs/err/done + + // Clone here too so cy.mfs stays the write-once canonical slice: joiners + // read it concurrently via slices.Clone, so the leader must not hand out + // (and potentially reorder) the same backing array. + return slices.Clone(cy.mfs), c.releaseFunc(cy), cy.err +} + +// releaseFunc returns the done callback for one caller sharing cy. +// When the last caller releases, the underlying done is invoked and the +// cycle is cleared so the next Gather starts fresh. +func (c *coalescingGatherer) releaseFunc(cy *gatherCycle) func() { + return func() { + c.mu.Lock() + cy.refs-- + if cy.refs > 0 { + c.mu.Unlock() + return + } + // Last caller. + if c.cycle == cy { + c.cycle = nil + } + c.mu.Unlock() + cy.done() // called outside the lock to avoid holding it during done + } +} + // Handler returns an http.Handler for the prometheus.DefaultGatherer, using // default HandlerOpts, i.e. it reports the first error as an HTTP error, it has // no error logging, and it applies compression if requested by the client. @@ -89,6 +198,10 @@ var gzipPool = sync.Pool{ // metrics used for instrumentation will be shared between them, providing // global scrape counts. // +// The handler supports filtering metrics by name using the `name[]` query parameter. +// Multiple metric names can be specified by providing the parameter multiple times. +// When no name[] parameters are provided, all metrics are returned. +// // This function is meant to cover the bulk of basic use cases. If you are doing // anything that requires more customization (including using a non-default // Gatherer, different instrumentation, and non-default HandlerOpts), use the @@ -105,6 +218,10 @@ func Handler() http.Handler { // Gatherers, with non-default HandlerOpts, and/or with custom (or no) // instrumentation. Use the InstrumentMetricHandler function to apply the same // kind of instrumentation as it is used by the Handler function. +// +// The handler supports filtering metrics by name using the `name[]` query parameter. +// Multiple metric names can be specified by providing the parameter multiple times. +// When no name[] parameters are provided, all metrics are returned. func HandlerFor(reg prometheus.Gatherer, opts HandlerOpts) http.Handler { return HandlerForTransactional(prometheus.ToTransactionalGatherer(reg), opts) } @@ -112,7 +229,15 @@ func HandlerFor(reg prometheus.Gatherer, opts HandlerOpts) http.Handler { // HandlerForTransactional is like HandlerFor, but it uses transactional gather, which // can safely change in-place returned *dto.MetricFamily before call to `Gather` and after // call to `done` of that `Gather`. +// +// The handler supports filtering metrics by name using the `name[]` query parameter. +// Multiple metric names can be specified by providing the parameter multiple times. +// When no name[] parameters are provided, all metrics are returned. func HandlerForTransactional(reg prometheus.TransactionalGatherer, opts HandlerOpts) http.Handler { + if opts.CoalesceGather { + reg = &coalescingGatherer{g: reg} + } + var ( inFlightSem chan struct{} errCnt = prometheus.NewCounterVec( @@ -214,12 +339,14 @@ func HandlerForTransactional(reg prometheus.TransactionalGatherer, opts HandlerO rsp.Header().Set(contentEncodingHeader, encodingHeader) } - var enc expfmt.Encoder + var ( + enc expfmt.Encoder + encOpts []expfmt.EncoderOption + ) if opts.EnableOpenMetricsTextCreatedSamples { - enc = expfmt.NewEncoder(w, contentType, expfmt.WithCreatedLines()) - } else { - enc = expfmt.NewEncoder(w, contentType) + encOpts = append(encOpts, expfmt.WithCreatedLines()) } + enc = expfmt.NewEncoder(w, contentType, encOpts...) // handleError handles the error according to opts.ErrorHandling // and returns true if we have to abort after the handling. @@ -245,7 +372,24 @@ func HandlerForTransactional(reg prometheus.TransactionalGatherer, opts HandlerO return false } + // Build metric name filter set from query params (if any). The URL + // can be nil on hand-constructed requests. + var metricFilter map[string]struct{} + if req.URL != nil { + if metricNames := req.URL.Query()["name[]"]; len(metricNames) > 0 { + metricFilter = make(map[string]struct{}, len(metricNames)) + for _, name := range metricNames { + metricFilter[name] = struct{}{} + } + } + } + for _, mf := range mfs { + if metricFilter != nil { + if _, ok := metricFilter[mf.GetName()]; !ok { + continue + } + } if handleError(enc.Encode(mf)) { return } @@ -353,7 +497,7 @@ const ( // log.Logger from the standard library implements this interface, and it is // easy to implement by custom loggers, if they don't do so already anyway. type Logger interface { - Println(v ...interface{}) + Println(v ...any) } // HandlerOpts specifies options how to serve metrics via an http.Handler. The @@ -400,6 +544,40 @@ type HandlerOpts struct { // Service Unavailable and a suitable message in the body. If // MaxRequestsInFlight is 0 or negative, no limit is applied. MaxRequestsInFlight int + // CoalesceGather, if true, deduplicates concurrent Gather calls so that + // only one collection runs at a time. Additional requests that arrive + // while a Gather is in flight will receive the same result once it + // completes. This prevents goroutine pile-up when the scrape rate is + // faster than the time collectors need to produce metrics. + // + // When enabled, concurrent scrapers share a single metric snapshot per + // collection cycle. Each request receives its own copy of the returned + // slice, so filtering or reordering it (for example via name[] query + // parameters) is safe. The pointed-to MetricFamily values are still + // shared: the built-in handler only reads them, so this is safe in + // practice, but a custom TransactionalGatherer that mutates the returned + // families in place after Gather returns must not use this option. + // + // Because the snapshot is shared, a request that arrives while a cycle is + // in flight receives that cycle's result even though collection began + // before the request; two scrapers joined to one cycle observe the same + // timestamps rather than independently gathered data. + // + // Consider using CoalesceGather together with Timeout. Timeout bounds the + // client-facing response time and keeps at most one collection running at + // a time, but it does not cancel the underlying Gather: a joined request + // that times out still holds a MaxRequestsInFlight slot until the shared + // collection completes. + // + // Panic handling: a panicking Collector is already turned into an error by + // the registry, so joiners receive that error like any other. In the rare + // case where the wrapped gatherer itself panics, the panicking request's + // panic propagates as usual (handled by net/http), while requests that + // joined the same cycle receive an error rather than an empty response. + // + // NOTE: This option is experimental and may change or be removed in a + // future release. + CoalesceGather bool // If handling a request takes longer than Timeout, it is responded to // with 503 ServiceUnavailable and a suitable Message. No timeout is // applied if Timeout is 0 or negative. Note that with the current @@ -407,8 +585,9 @@ type HandlerOpts struct { // described above (and even that only if sending of the body hasn't // started yet), while the bulk work of gathering all the metrics keeps // running in the background (with the eventual result to be thrown - // away). Until the implementation is improved, it is recommended to - // implement a separate timeout in potentially slow Collectors. + // away). When CoalesceGather is enabled, only one such background Gather + // can be in flight at a time. It is also recommended to implement a + // separate timeout in potentially slow Collectors. Timeout time.Duration // If true, the experimental OpenMetrics encoding is added to the // possible options during content negotiation. Note that Prometheus @@ -460,7 +639,7 @@ func httpError(rsp http.ResponseWriter, err error) { // negotiateEncodingWriter reads the Accept-Encoding header from a request and // selects the right compression based on an allow-list of supported -// compressions. It returns a writer implementing the compression and an the +// compressions. It returns a writer implementing the compression and the // correct value that the caller can set in the response header. func negotiateEncodingWriter(r *http.Request, rw io.Writer, compressions []string) (_ io.Writer, encodingHeaderValue string, closeWriter func(), _ error) { if len(compressions) == 0 { diff --git a/vendor/github.com/prometheus/client_golang/prometheus/promhttp/instrument_client.go b/vendor/github.com/prometheus/client_golang/prometheus/promhttp/instrument_client.go index d3482c40c..024857974 100644 --- a/vendor/github.com/prometheus/client_golang/prometheus/promhttp/instrument_client.go +++ b/vendor/github.com/prometheus/client_golang/prometheus/promhttp/instrument_client.go @@ -75,10 +75,10 @@ func InstrumentRoundTripperCounter(counter *prometheus.CounterVec, next http.Rou resp, err := next.RoundTrip(r) if err == nil { l := labels(code, method, r.Method, resp.StatusCode, rtOpts.extraMethods...) - for label, resolve := range rtOpts.extraLabelsFromCtx { - l[label] = resolve(resp.Request.Context()) + for label, resolve := range rtOpts.extraLabelsFromRequest { + l[label] = resolve(resp.Request) } - addWithExemplar(counter.With(l), 1, rtOpts.getExemplarFn(r.Context())) + addWithExemplar(counter.With(l), 1, rtOpts.getExemplarFn(r)) } return resp, err } @@ -119,10 +119,10 @@ func InstrumentRoundTripperDuration(obs prometheus.ObserverVec, next http.RoundT resp, err := next.RoundTrip(r) if err == nil { l := labels(code, method, r.Method, resp.StatusCode, rtOpts.extraMethods...) - for label, resolve := range rtOpts.extraLabelsFromCtx { - l[label] = resolve(resp.Request.Context()) + for label, resolve := range rtOpts.extraLabelsFromRequest { + l[label] = resolve(resp.Request) } - observeWithExemplar(obs.With(l), time.Since(start).Seconds(), rtOpts.getExemplarFn(r.Context())) + observeWithExemplar(obs.With(l), time.Since(start).Seconds(), rtOpts.getExemplarFn(r)) } return resp, err } diff --git a/vendor/github.com/prometheus/client_golang/prometheus/promhttp/instrument_server.go b/vendor/github.com/prometheus/client_golang/prometheus/promhttp/instrument_server.go index 9332b0249..9dec091ac 100644 --- a/vendor/github.com/prometheus/client_golang/prometheus/promhttp/instrument_server.go +++ b/vendor/github.com/prometheus/client_golang/prometheus/promhttp/instrument_server.go @@ -28,24 +28,36 @@ import ( // magicString is used for the hacky label test in checkLabels. Remove once fixed. const magicString = "zZgWfBxLqvG8kc8IMv3POi2Bb0tZI3vAnBx+gBaFi9FyPzB/CzKUer1yufDa" -// observeWithExemplar is a wrapper for [prometheus.ExemplarAdder.ExemplarObserver], -// which falls back to [prometheus.Observer.Observe] if no labels are provided. +// observeWithExemplar records val on obs. If labels is non-nil and obs +// implements [prometheus.ExemplarObserver], the exemplar is attached via +// ObserveWithExemplar; otherwise the exemplar is dropped and the value is +// recorded with a plain [prometheus.Observer.Observe]. This mirrors the +// safe-cast pattern in [prometheus.Timer.ObserveDurationWithExemplar] and +// ensures we never panic when callers pass an ObserverVec backed by a +// summary, which cannot carry exemplars in the Prometheus exposition format. func observeWithExemplar(obs prometheus.Observer, val float64, labels map[string]string) { - if labels == nil { - obs.Observe(val) - return + if labels != nil { + if eo, ok := obs.(prometheus.ExemplarObserver); ok { + eo.ObserveWithExemplar(val, labels) + return + } } - obs.(prometheus.ExemplarObserver).ObserveWithExemplar(val, labels) + obs.Observe(val) } -// addWithExemplar is a wrapper for [prometheus.ExemplarAdder.AddWithExemplar], -// which falls back to [prometheus.Counter.Add] if no labels are provided. -func addWithExemplar(obs prometheus.Counter, val float64, labels map[string]string) { - if labels == nil { - obs.Add(val) - return +// addWithExemplar records val on c. If labels is non-nil and c implements +// [prometheus.ExemplarAdder], the exemplar is attached via AddWithExemplar; +// otherwise the exemplar is dropped and the value is recorded with a plain +// [prometheus.Counter.Add]. The safe-cast keeps the helper robust against +// custom Counter implementations that do not advertise exemplar support. +func addWithExemplar(c prometheus.Counter, val float64, labels map[string]string) { + if labels != nil { + if ea, ok := c.(prometheus.ExemplarAdder); ok { + ea.AddWithExemplar(val, labels) + return + } } - obs.(prometheus.ExemplarAdder).AddWithExemplar(val, labels) + c.Add(val) } // InstrumentHandlerInFlight is a middleware that wraps the provided @@ -97,10 +109,10 @@ func InstrumentHandlerDuration(obs prometheus.ObserverVec, next http.Handler, op next.ServeHTTP(d, r) l := labels(code, method, r.Method, d.Status(), hOpts.extraMethods...) - for label, resolve := range hOpts.extraLabelsFromCtx { - l[label] = resolve(r.Context()) + for label, resolve := range hOpts.extraLabelsFromRequest { + l[label] = resolve(r) } - observeWithExemplar(obs.With(l), time.Since(now).Seconds(), hOpts.getExemplarFn(r.Context())) + observeWithExemplar(obs.With(l), time.Since(now).Seconds(), hOpts.getExemplarFn(r)) } } @@ -108,10 +120,10 @@ func InstrumentHandlerDuration(obs prometheus.ObserverVec, next http.Handler, op now := time.Now() next.ServeHTTP(w, r) l := labels(code, method, r.Method, 0, hOpts.extraMethods...) - for label, resolve := range hOpts.extraLabelsFromCtx { - l[label] = resolve(r.Context()) + for label, resolve := range hOpts.extraLabelsFromRequest { + l[label] = resolve(r) } - observeWithExemplar(obs.With(l), time.Since(now).Seconds(), hOpts.getExemplarFn(r.Context())) + observeWithExemplar(obs.With(l), time.Since(now).Seconds(), hOpts.getExemplarFn(r)) } } @@ -147,10 +159,10 @@ func InstrumentHandlerCounter(counter *prometheus.CounterVec, next http.Handler, next.ServeHTTP(d, r) l := labels(code, method, r.Method, d.Status(), hOpts.extraMethods...) - for label, resolve := range hOpts.extraLabelsFromCtx { - l[label] = resolve(r.Context()) + for label, resolve := range hOpts.extraLabelsFromRequest { + l[label] = resolve(r) } - addWithExemplar(counter.With(l), 1, hOpts.getExemplarFn(r.Context())) + addWithExemplar(counter.With(l), 1, hOpts.getExemplarFn(r)) } } @@ -158,10 +170,10 @@ func InstrumentHandlerCounter(counter *prometheus.CounterVec, next http.Handler, next.ServeHTTP(w, r) l := labels(code, method, r.Method, 0, hOpts.extraMethods...) - for label, resolve := range hOpts.extraLabelsFromCtx { - l[label] = resolve(r.Context()) + for label, resolve := range hOpts.extraLabelsFromRequest { + l[label] = resolve(r) } - addWithExemplar(counter.With(l), 1, hOpts.getExemplarFn(r.Context())) + addWithExemplar(counter.With(l), 1, hOpts.getExemplarFn(r)) } } @@ -200,10 +212,10 @@ func InstrumentHandlerTimeToWriteHeader(obs prometheus.ObserverVec, next http.Ha now := time.Now() d := newDelegator(w, func(status int) { l := labels(code, method, r.Method, status, hOpts.extraMethods...) - for label, resolve := range hOpts.extraLabelsFromCtx { - l[label] = resolve(r.Context()) + for label, resolve := range hOpts.extraLabelsFromRequest { + l[label] = resolve(r) } - observeWithExemplar(obs.With(l), time.Since(now).Seconds(), hOpts.getExemplarFn(r.Context())) + observeWithExemplar(obs.With(l), time.Since(now).Seconds(), hOpts.getExemplarFn(r)) }) next.ServeHTTP(d, r) } @@ -244,10 +256,10 @@ func InstrumentHandlerRequestSize(obs prometheus.ObserverVec, next http.Handler, size := computeApproximateRequestSize(r) l := labels(code, method, r.Method, d.Status(), hOpts.extraMethods...) - for label, resolve := range hOpts.extraLabelsFromCtx { - l[label] = resolve(r.Context()) + for label, resolve := range hOpts.extraLabelsFromRequest { + l[label] = resolve(r) } - observeWithExemplar(obs.With(l), float64(size), hOpts.getExemplarFn(r.Context())) + observeWithExemplar(obs.With(l), float64(size), hOpts.getExemplarFn(r)) } } @@ -256,10 +268,10 @@ func InstrumentHandlerRequestSize(obs prometheus.ObserverVec, next http.Handler, size := computeApproximateRequestSize(r) l := labels(code, method, r.Method, 0, hOpts.extraMethods...) - for label, resolve := range hOpts.extraLabelsFromCtx { - l[label] = resolve(r.Context()) + for label, resolve := range hOpts.extraLabelsFromRequest { + l[label] = resolve(r) } - observeWithExemplar(obs.With(l), float64(size), hOpts.getExemplarFn(r.Context())) + observeWithExemplar(obs.With(l), float64(size), hOpts.getExemplarFn(r)) } } @@ -296,10 +308,10 @@ func InstrumentHandlerResponseSize(obs prometheus.ObserverVec, next http.Handler next.ServeHTTP(d, r) l := labels(code, method, r.Method, d.Status(), hOpts.extraMethods...) - for label, resolve := range hOpts.extraLabelsFromCtx { - l[label] = resolve(r.Context()) + for label, resolve := range hOpts.extraLabelsFromRequest { + l[label] = resolve(r) } - observeWithExemplar(obs.With(l), float64(d.Written()), hOpts.getExemplarFn(r.Context())) + observeWithExemplar(obs.With(l), float64(d.Written()), hOpts.getExemplarFn(r)) }) } @@ -366,7 +378,7 @@ func checkLabels(c prometheus.Collector) (code, method bool) { panic("metric partitioned with non-supported labels") } } - return + return code, method } func isLabelCurried(c prometheus.Collector, label string) bool { diff --git a/vendor/github.com/prometheus/client_golang/prometheus/promhttp/option.go b/vendor/github.com/prometheus/client_golang/prometheus/promhttp/option.go index 5d4383aa1..d4c0954f3 100644 --- a/vendor/github.com/prometheus/client_golang/prometheus/promhttp/option.go +++ b/vendor/github.com/prometheus/client_golang/prometheus/promhttp/option.go @@ -15,6 +15,7 @@ package promhttp import ( "context" + "net/http" "github.com/prometheus/client_golang/prometheus" ) @@ -24,28 +25,31 @@ type Option interface { apply(*options) } +// LabelValueFromRequest is used to compute the label value from request. +type LabelValueFromRequest func(request *http.Request) string + // LabelValueFromCtx are used to compute the label value from request context. // Context can be filled with values from request through middleware. type LabelValueFromCtx func(ctx context.Context) string // options store options for both a handler or round tripper. type options struct { - extraMethods []string - getExemplarFn func(requestCtx context.Context) prometheus.Labels - extraLabelsFromCtx map[string]LabelValueFromCtx + extraMethods []string + getExemplarFn func(req *http.Request) prometheus.Labels + extraLabelsFromRequest map[string]LabelValueFromRequest } func defaultOptions() *options { return &options{ - getExemplarFn: func(ctx context.Context) prometheus.Labels { return nil }, - extraLabelsFromCtx: map[string]LabelValueFromCtx{}, + getExemplarFn: func(req *http.Request) prometheus.Labels { return nil }, + extraLabelsFromRequest: map[string]LabelValueFromRequest{}, } } func (o *options) emptyDynamicLabels() prometheus.Labels { labels := prometheus.Labels{} - for label := range o.extraLabelsFromCtx { + for label := range o.extraLabelsFromRequest { labels[label] = "" } @@ -66,19 +70,39 @@ func WithExtraMethods(methods ...string) Option { }) } -// WithExemplarFromContext allows to inject function that will get exemplar from context that will be put to counter and histogram metrics. +// WithExemplarFromRequest allows you to inject a function that will get exemplar from request that will be put to counter and histogram metrics. // If the function returns nil labels or the metric does not support exemplars, no exemplar will be added (noop), but // metric will continue to observe/increment. -func WithExemplarFromContext(getExemplarFn func(requestCtx context.Context) prometheus.Labels) Option { +func WithExemplarFromRequest(getExemplarFn func(req *http.Request) prometheus.Labels) Option { return optionApplyFunc(func(o *options) { o.getExemplarFn = getExemplarFn }) } +// WithExemplarFromContext allows you to inject a function that will get exemplar from context that will be put to counter and histogram metrics. +// If the function returns nil labels or the metric does not support exemplars, no exemplar will be added (noop), but +// metric will continue to observe/increment. +func WithExemplarFromContext(getExemplarFn func(requestCtx context.Context) prometheus.Labels) Option { + return optionApplyFunc(func(o *options) { + o.getExemplarFn = func(req *http.Request) prometheus.Labels { + return getExemplarFn(req.Context()) + } + }) +} + +// WithLabelFromRequest registers a label for dynamic resolution with access to the request. +func WithLabelFromRequest(name string, valueFn LabelValueFromRequest) Option { + return optionApplyFunc(func(o *options) { + o.extraLabelsFromRequest[name] = valueFn + }) +} + // WithLabelFromCtx registers a label for dynamic resolution with access to context. // See the example for ExampleInstrumentHandlerWithLabelResolver for example usage func WithLabelFromCtx(name string, valueFn LabelValueFromCtx) Option { return optionApplyFunc(func(o *options) { - o.extraLabelsFromCtx[name] = valueFn + o.extraLabelsFromRequest[name] = func(req *http.Request) string { + return valueFn(req.Context()) + } }) } diff --git a/vendor/github.com/prometheus/client_golang/prometheus/registry.go b/vendor/github.com/prometheus/client_golang/prometheus/registry.go index c6fd2f58b..ed0681c8b 100644 --- a/vendor/github.com/prometheus/client_golang/prometheus/registry.go +++ b/vendor/github.com/prometheus/client_golang/prometheus/registry.go @@ -214,6 +214,19 @@ func (err AlreadyRegisteredError) Error() string { // by a Gatherer to report multiple errors during MetricFamily gathering. type MultiError []error +// SafeMultiError is a thread-safe wrapper around MultiError using a mutex. +type SafeMultiError struct { + mu sync.Mutex + errs MultiError +} + +// Appends the provided error to the contained MultiError in a thread-safe way. +func (s *SafeMultiError) Append(err error) { + s.mu.Lock() + s.errs.Append(err) + s.mu.Unlock() +} + // Error formats the contained errors as a bullet point list, preceded by the // total number of errors. Note that this results in a multi-line string. func (errs MultiError) Error() string { @@ -408,6 +421,16 @@ func (r *Registry) MustRegister(cs ...Collector) { } } +// MustGather implements Gatherer. +// Wraps around Gather and panics if Gather fails for any reason. +func (r *Registry) MustGather() []*dto.MetricFamily { + mfs, err := r.Gather() + if err != nil { + panic(err) + } + return mfs +} + // Gather implements Gatherer. func (r *Registry) Gather() ([]*dto.MetricFamily, error) { r.mtx.RLock() @@ -423,7 +446,7 @@ func (r *Registry) Gather() ([]*dto.MetricFamily, error) { uncheckedMetricChan = make(chan Metric, capMetricChan) metricHashes = map[uint64]struct{}{} wg sync.WaitGroup - errs MultiError // The collected errors to return in the end. + safeErrs = &SafeMultiError{} // To collect errors in a threadsafe way registeredDescIDs map[uint64]struct{} // Only used for pedantic checks ) @@ -453,9 +476,9 @@ func (r *Registry) Gather() ([]*dto.MetricFamily, error) { for { select { case collector := <-checkedCollectors: - collector.Collect(checkedMetricChan) + safeErrs.Append((safeCollect(collector, checkedMetricChan))) case collector := <-uncheckedCollectors: - collector.Collect(uncheckedMetricChan) + safeErrs.Append(safeCollect(collector, uncheckedMetricChan)) default: return } @@ -499,7 +522,7 @@ func (r *Registry) Gather() ([]*dto.MetricFamily, error) { cmc = nil break } - errs.Append(processMetric( + safeErrs.Append(processMetric( metric, metricFamiliesByName, metricHashes, registeredDescIDs, @@ -509,7 +532,7 @@ func (r *Registry) Gather() ([]*dto.MetricFamily, error) { umc = nil break } - errs.Append(processMetric( + safeErrs.Append(processMetric( metric, metricFamiliesByName, metricHashes, nil, @@ -526,7 +549,7 @@ func (r *Registry) Gather() ([]*dto.MetricFamily, error) { cmc = nil break } - errs.Append(processMetric( + safeErrs.Append(processMetric( metric, metricFamiliesByName, metricHashes, registeredDescIDs, @@ -536,7 +559,7 @@ func (r *Registry) Gather() ([]*dto.MetricFamily, error) { umc = nil break } - errs.Append(processMetric( + safeErrs.Append(processMetric( metric, metricFamiliesByName, metricHashes, nil, @@ -556,7 +579,8 @@ func (r *Registry) Gather() ([]*dto.MetricFamily, error) { break } } - return internal.NormalizeMetricFamilies(metricFamiliesByName), errs.MaybeUnwrap() + + return internal.NormalizeMetricFamilies(metricFamiliesByName), safeErrs.errs.MaybeUnwrap() } // Describe implements Collector. @@ -571,6 +595,24 @@ func (r *Registry) Describe(ch chan<- *Desc) { } } +// Helper wrapper around Collector.Collect. +// It tries to collect from the channel, recovers on panic and +// if it has recovered from a panic, then it sends an InvalidMetric into +// the channel with an InvalidDesc, and an error that includes a stack trace. +func safeCollect(c Collector, ch chan<- Metric) (err error) { + defer func() { + if r := recover(); r != nil { + buf := make([]byte, 64<<10) // 64 KB + n := runtime.Stack(buf, false) + err = fmt.Errorf("prometheus collector panic recovered: type=%T: error=%v\nstack trace=%s", c, r, buf[:n]) + ch <- NewInvalidMetric(NewInvalidDesc(err), err) + } + }() + c.Collect(ch) + + return err +} + // Collect implements Collector. func (r *Registry) Collect(ch chan<- Metric) { r.mtx.RLock() @@ -599,10 +641,12 @@ func WriteToTextfile(filename string, g Gatherer) error { mfs, err := g.Gather() if err != nil { + tmp.Close() return err } for _, mf := range mfs { if _, err := expfmt.MetricFamilyToText(tmp, mf); err != nil { + tmp.Close() return err } } @@ -685,6 +729,9 @@ func processMetric( metricFamily = &dto.MetricFamily{} metricFamily.Name = proto.String(desc.fqName) metricFamily.Help = proto.String(desc.help) + if desc.unit != "" { + metricFamily.Unit = proto.String(desc.unit) + } // TODO(beorn7): Simplify switch once Desc has type. switch { case dtoMetric.Gauge != nil: diff --git a/vendor/github.com/prometheus/client_golang/prometheus/summary.go b/vendor/github.com/prometheus/client_golang/prometheus/summary.go index ac5203c6f..c12b8d13d 100644 --- a/vendor/github.com/prometheus/client_golang/prometheus/summary.go +++ b/vendor/github.com/prometheus/client_golang/prometheus/summary.go @@ -101,6 +101,9 @@ type SummaryOpts struct { // string. Help string + // Unit provides the unit of this Summary. + Unit string + // ConstLabels are used to attach fixed labels to this metric. Metrics // with the same fully-qualified name must have the same label names in // their ConstLabels. @@ -181,11 +184,12 @@ type SummaryVecOpts struct { // NewSummary creates a new Summary based on the provided SummaryOpts. func NewSummary(opts SummaryOpts) Summary { return newSummary( - NewDesc( + V2.NewDesc( BuildFQName(opts.Namespace, opts.Subsystem, opts.Name), opts.Help, - nil, + UnconstrainedLabels(nil), opts.ConstLabels, + WithUnit(opts.Unit), ), opts, ) @@ -578,6 +582,7 @@ func (v2) NewSummaryVec(opts SummaryVecOpts) *SummaryVec { opts.Help, opts.VariableLabels, opts.ConstLabels, + WithUnit(opts.Unit), ) return &SummaryVec{ MetricVec: NewMetricVec(desc, func(lvs ...string) Metric { diff --git a/vendor/github.com/prometheus/client_golang/prometheus/timer.go b/vendor/github.com/prometheus/client_golang/prometheus/timer.go index 52344fef5..c1318ffb5 100644 --- a/vendor/github.com/prometheus/client_golang/prometheus/timer.go +++ b/vendor/github.com/prometheus/client_golang/prometheus/timer.go @@ -37,10 +37,10 @@ type Timer struct { // or // // func TimeMeWithExemplar() { -// timer := NewTimer(myHistogram) -// defer timer.ObserveDurationWithExemplar(exemplar) -// // Do actual work. -// } +// timer := NewTimer(myHistogram) +// defer timer.ObserveDurationWithExemplar(exemplar) +// // Do actual work. +// } func NewTimer(o Observer) *Timer { return &Timer{ begin: time.Now(), @@ -66,7 +66,7 @@ func (t *Timer) ObserveDuration() time.Duration { // ObserveDurationWithExemplar is like ObserveDuration, but it will also // observe exemplar with the duration unless exemplar is nil or provided Observer can't -// be casted to ExemplarObserver. +// be cast to ExemplarObserver. func (t *Timer) ObserveDurationWithExemplar(exemplar Labels) time.Duration { d := time.Since(t.begin) eo, ok := t.observer.(ExemplarObserver) diff --git a/vendor/github.com/prometheus/client_golang/prometheus/vec.go b/vendor/github.com/prometheus/client_golang/prometheus/vec.go index 487b46656..121d2a963 100644 --- a/vendor/github.com/prometheus/client_golang/prometheus/vec.go +++ b/vendor/github.com/prometheus/client_golang/prometheus/vec.go @@ -193,9 +193,11 @@ func (m *MetricVec) CurryWith(labels Labels) (*MetricVec, error) { // // Keeping the Metric for later use is possible (and should be considered if // performance is critical), but keep in mind that Reset, DeleteLabelValues and -// Delete can be used to delete the Metric from the MetricVec. In that case, the -// Metric will still exist, but it will not be exported anymore, even if a -// Metric with the same label values is created later. +// Delete can be used to delete the Metric from the MetricVec. In that case, if +// you have previously kept a reference to that Metric, the Metric object still +// exists and can be used, but it will not be exported anymore. If a Metric with +// the same label values is created later, updates to the old Metric reference +// will not be exported. // // An error is returned if the number of label values is not the same as the // number of variable labels in Desc (minus any curried labels). @@ -657,7 +659,7 @@ func inlineLabelValues(lvs []string, curry []curriedLabelValue) []string { } var labelsPool = &sync.Pool{ - New: func() interface{} { + New: func() any { return make(Labels) }, } diff --git a/vendor/github.com/prometheus/client_golang/prometheus/wrap.go b/vendor/github.com/prometheus/client_golang/prometheus/wrap.go index 2ed128506..697f55558 100644 --- a/vendor/github.com/prometheus/client_golang/prometheus/wrap.go +++ b/vendor/github.com/prometheus/client_golang/prometheus/wrap.go @@ -230,6 +230,7 @@ func wrapDesc(desc *Desc, prefix string, labels Labels) *Desc { return &Desc{ fqName: desc.fqName, help: desc.help, + unit: desc.unit, variableLabels: desc.variableLabels, constLabelPairs: desc.constLabelPairs, err: fmt.Errorf("attempted wrapping with already existing label name %q", ln), @@ -238,8 +239,8 @@ func wrapDesc(desc *Desc, prefix string, labels Labels) *Desc { constLabels[ln] = lv } // NewDesc will do remaining validations. - newDesc := V2.NewDesc(prefix+desc.fqName, desc.help, desc.variableLabels, constLabels) - // Propagate errors if there was any. This will override any errer + newDesc := V2.NewDesc(prefix+desc.fqName, desc.help, desc.variableLabels, constLabels, WithUnit(desc.unit)) + // Propagate errors if there was any. This will override any error // created by NewDesc above, i.e. earlier errors get precedence. if desc.err != nil { newDesc.err = desc.err diff --git a/vendor/github.com/prometheus/common/expfmt/decode.go b/vendor/github.com/prometheus/common/expfmt/decode.go index 7b762370e..8f8dc65d3 100644 --- a/vendor/github.com/prometheus/common/expfmt/decode.go +++ b/vendor/github.com/prometheus/common/expfmt/decode.go @@ -220,7 +220,7 @@ func extractSamples(f *dto.MetricFamily, o *DecodeOptions) (model.Vector, error) return extractSummary(o, f), nil case dto.MetricType_UNTYPED: return extractUntyped(o, f), nil - case dto.MetricType_HISTOGRAM: + case dto.MetricType_HISTOGRAM, dto.MetricType_GAUGE_HISTOGRAM: return extractHistogram(o, f), nil } return nil, fmt.Errorf("expfmt.extractSamples: unknown metric family type %v", f.GetType()) @@ -403,9 +403,13 @@ func extractHistogram(o *DecodeOptions, f *dto.MetricFamily) model.Vector { infSeen = true } + v := q.GetCumulativeCountFloat() + if v <= 0 { + v = float64(q.GetCumulativeCount()) + } samples = append(samples, &model.Sample{ Metric: model.Metric(lset), - Value: model.SampleValue(q.GetCumulativeCount()), + Value: model.SampleValue(v), Timestamp: timestamp, }) } @@ -428,9 +432,13 @@ func extractHistogram(o *DecodeOptions, f *dto.MetricFamily) model.Vector { } lset[model.MetricNameLabel] = model.LabelValue(f.GetName() + "_count") + v := m.Histogram.GetSampleCountFloat() + if v <= 0 { + v = float64(m.Histogram.GetSampleCount()) + } count := &model.Sample{ Metric: model.Metric(lset), - Value: model.SampleValue(m.Histogram.GetSampleCount()), + Value: model.SampleValue(v), Timestamp: timestamp, } samples = append(samples, count) diff --git a/vendor/github.com/prometheus/common/expfmt/expfmt.go b/vendor/github.com/prometheus/common/expfmt/expfmt.go index c34c7de43..10bf35708 100644 --- a/vendor/github.com/prometheus/common/expfmt/expfmt.go +++ b/vendor/github.com/prometheus/common/expfmt/expfmt.go @@ -45,6 +45,7 @@ const ( // The Content-Type values for the different wire protocols. Do not do direct // comparisons to these constants, instead use the comparison functions. + // // Deprecated: Use expfmt.NewFormat(expfmt.TypeUnknown) instead. FmtUnknown Format = `` // Deprecated: Use expfmt.NewFormat(expfmt.TypeTextPlain) instead. @@ -121,7 +122,7 @@ func NewOpenMetricsFormat(version string) (Format, error) { // removed. func (f Format) WithEscapingScheme(s model.EscapingScheme) Format { var terms []string - for _, p := range strings.Split(string(f), ";") { + for p := range strings.SplitSeq(string(f), ";") { toks := strings.Split(p, "=") if len(toks) != 2 { trimmed := strings.TrimSpace(p) @@ -193,7 +194,7 @@ func (f Format) FormatType() FormatType { // "escaping" term exists, that will be used. Otherwise, the global default will // be returned. func (f Format) ToEscapingScheme() model.EscapingScheme { - for _, p := range strings.Split(string(f), ";") { + for p := range strings.SplitSeq(string(f), ";") { toks := strings.Split(p, "=") if len(toks) != 2 { continue diff --git a/vendor/github.com/prometheus/common/expfmt/fuzz.go b/vendor/github.com/prometheus/common/expfmt/fuzz.go index 0290f6abc..872c0c15b 100644 --- a/vendor/github.com/prometheus/common/expfmt/fuzz.go +++ b/vendor/github.com/prometheus/common/expfmt/fuzz.go @@ -13,7 +13,6 @@ // Build only when actually fuzzing //go:build gofuzz -// +build gofuzz package expfmt diff --git a/vendor/github.com/prometheus/common/expfmt/openmetrics_create.go b/vendor/github.com/prometheus/common/expfmt/openmetrics_create.go index 8dbf6d04e..0480e7af5 100644 --- a/vendor/github.com/prometheus/common/expfmt/openmetrics_create.go +++ b/vendor/github.com/prometheus/common/expfmt/openmetrics_create.go @@ -30,7 +30,6 @@ import ( type encoderOption struct { withCreatedLines bool - withUnit bool } type EncoderOption func(*encoderOption) @@ -51,17 +50,6 @@ func WithCreatedLines() EncoderOption { } } -// WithUnit is an EncoderOption enabling a set unit to be written to the output -// and to be added to the metric name, if it's not there already, as a suffix. -// Without opting in this way, the unit will not be added to the metric name and, -// on top of that, the unit will not be passed onto the output, even if it -// were declared in the *dto.MetricFamily struct, i.e. even if in.Unit !=nil. -func WithUnit() EncoderOption { - return func(t *encoderOption) { - t.withUnit = true - } -} - // MetricFamilyToOpenMetrics converts a MetricFamily proto message into the // OpenMetrics text format and writes the resulting lines to 'out'. It returns // the number of bytes written and any error encountered. The output will have @@ -99,15 +87,6 @@ func WithUnit() EncoderOption { // its type will be set to `unknown` in that case to avoid invalid OpenMetrics // output. // -// - According to the OM specs, the `# UNIT` line is optional, but if populated, -// the unit has to be present in the metric name as its suffix: -// (see https://github.com/prometheus/OpenMetrics/blob/v1.0.0/specification/OpenMetrics.md#unit). -// However, in order to accommodate any potential scenario where such a change in the -// metric name is not desirable, the users are here given the choice of either explicitly -// opt in, in case they wish for the unit to be included in the output AND in the metric name -// as a suffix (see the description of the WithUnit function above), -// or not to opt in, in case they don't want for any of that to happen. -// // - No support for the following (optional) features: info type, // stateset type, gaugehistogram type. // @@ -151,47 +130,44 @@ func MetricFamilyToOpenMetrics(out io.Writer, in *dto.MetricFamily, options ...E if metricType == dto.MetricType_COUNTER && strings.HasSuffix(compliantName, "_total") { compliantName = name[:len(name)-6] } - if toOM.withUnit && in.Unit != nil && !strings.HasSuffix(compliantName, "_"+*in.Unit) { - compliantName = compliantName + "_" + *in.Unit - } // Comments, first HELP, then TYPE. if in.Help != nil { n, err = w.WriteString("# HELP ") written += n if err != nil { - return + return written, err } n, err = writeName(w, compliantName) written += n if err != nil { - return + return written, err } err = w.WriteByte(' ') written++ if err != nil { - return + return written, err } n, err = writeEscapedString(w, *in.Help, true) written += n if err != nil { - return + return written, err } err = w.WriteByte('\n') written++ if err != nil { - return + return written, err } } n, err = w.WriteString("# TYPE ") written += n if err != nil { - return + return written, err } n, err = writeName(w, compliantName) written += n if err != nil { - return + return written, err } switch metricType { case dto.MetricType_COUNTER: @@ -208,39 +184,41 @@ func MetricFamilyToOpenMetrics(out io.Writer, in *dto.MetricFamily, options ...E n, err = w.WriteString(" unknown\n") case dto.MetricType_HISTOGRAM: n, err = w.WriteString(" histogram\n") + case dto.MetricType_GAUGE_HISTOGRAM: + n, err = w.WriteString(" gaugehistogram\n") default: return written, fmt.Errorf("unknown metric type %s", metricType.String()) } written += n if err != nil { - return + return written, err } - if toOM.withUnit && in.Unit != nil { + if in.Unit != nil { n, err = w.WriteString("# UNIT ") written += n if err != nil { - return + return written, err } n, err = writeName(w, compliantName) written += n if err != nil { - return + return written, err } err = w.WriteByte(' ') written++ if err != nil { - return + return written, err } n, err = writeEscapedString(w, *in.Unit, true) written += n if err != nil { - return + return written, err } err = w.WriteByte('\n') written++ if err != nil { - return + return written, err } } @@ -304,7 +282,7 @@ func MetricFamilyToOpenMetrics(out io.Writer, in *dto.MetricFamily, options ...E ) written += n if err != nil { - return + return written, err } } n, err = writeOpenMetricsSample( @@ -314,7 +292,7 @@ func MetricFamilyToOpenMetrics(out io.Writer, in *dto.MetricFamily, options ...E ) written += n if err != nil { - return + return written, err } n, err = writeOpenMetricsSample( w, compliantName, "_count", metric, "", 0, @@ -325,7 +303,7 @@ func MetricFamilyToOpenMetrics(out io.Writer, in *dto.MetricFamily, options ...E createdTsBytesWritten, err = writeOpenMetricsCreated(w, compliantName, "", metric, "", 0, metric.Summary.GetCreatedTimestamp()) n += createdTsBytesWritten } - case dto.MetricType_HISTOGRAM: + case dto.MetricType_HISTOGRAM, dto.MetricType_GAUGE_HISTOGRAM: if metric.Histogram == nil { return written, fmt.Errorf( "expected histogram in metric %s %s", compliantName, metric, @@ -333,6 +311,12 @@ func MetricFamilyToOpenMetrics(out io.Writer, in *dto.MetricFamily, options ...E } infSeen := false for _, b := range metric.Histogram.Bucket { + if b.GetCumulativeCountFloat() > 0 { + return written, fmt.Errorf( + "OpenMetrics v1.0 does not support float histogram %s %s", + compliantName, metric, + ) + } n, err = writeOpenMetricsSample( w, compliantName, "_bucket", metric, model.BucketLabel, b.GetUpperBound(), @@ -341,7 +325,7 @@ func MetricFamilyToOpenMetrics(out io.Writer, in *dto.MetricFamily, options ...E ) written += n if err != nil { - return + return written, err } if math.IsInf(b.GetUpperBound(), +1) { infSeen = true @@ -354,9 +338,12 @@ func MetricFamilyToOpenMetrics(out io.Writer, in *dto.MetricFamily, options ...E 0, metric.Histogram.GetSampleCount(), true, nil, ) + // We do not check for a float sample count here + // because we will check for it below (and error + // out if needed). written += n if err != nil { - return + return written, err } } n, err = writeOpenMetricsSample( @@ -366,7 +353,13 @@ func MetricFamilyToOpenMetrics(out io.Writer, in *dto.MetricFamily, options ...E ) written += n if err != nil { - return + return written, err + } + if metric.Histogram.GetSampleCountFloat() > 0 { + return written, fmt.Errorf( + "OpenMetrics v1.0 does not support float histogram %s %s", + compliantName, metric, + ) } n, err = writeOpenMetricsSample( w, compliantName, "_count", metric, "", 0, @@ -384,10 +377,10 @@ func MetricFamilyToOpenMetrics(out io.Writer, in *dto.MetricFamily, options ...E } written += n if err != nil { - return + return written, err } } - return + return written, err } // FinalizeOpenMetrics writes the final `# EOF\n` line required by OpenMetrics. diff --git a/vendor/github.com/prometheus/common/expfmt/text_create.go b/vendor/github.com/prometheus/common/expfmt/text_create.go index c4e9c1bbc..f4074ae9a 100644 --- a/vendor/github.com/prometheus/common/expfmt/text_create.go +++ b/vendor/github.com/prometheus/common/expfmt/text_create.go @@ -42,12 +42,12 @@ const ( var ( bufPool = sync.Pool{ - New: func() interface{} { + New: func() any { return bufio.NewWriter(io.Discard) }, } numBufPool = sync.Pool{ - New: func() interface{} { + New: func() any { b := make([]byte, 0, initialNumBufSize) return &b }, @@ -108,38 +108,38 @@ func MetricFamilyToText(out io.Writer, in *dto.MetricFamily) (written int, err e n, err = w.WriteString("# HELP ") written += n if err != nil { - return + return written, err } n, err = writeName(w, name) written += n if err != nil { - return + return written, err } err = w.WriteByte(' ') written++ if err != nil { - return + return written, err } n, err = writeEscapedString(w, *in.Help, false) written += n if err != nil { - return + return written, err } err = w.WriteByte('\n') written++ if err != nil { - return + return written, err } } n, err = w.WriteString("# TYPE ") written += n if err != nil { - return + return written, err } n, err = writeName(w, name) written += n if err != nil { - return + return written, err } metricType := in.GetType() switch metricType { @@ -151,14 +151,17 @@ func MetricFamilyToText(out io.Writer, in *dto.MetricFamily) (written int, err e n, err = w.WriteString(" summary\n") case dto.MetricType_UNTYPED: n, err = w.WriteString(" untyped\n") - case dto.MetricType_HISTOGRAM: + case dto.MetricType_HISTOGRAM, dto.MetricType_GAUGE_HISTOGRAM: + // The classic Prometheus text format has no notion of a gauge + // histogram. We render a gauge histogram in the same way as a + // regular histogram. n, err = w.WriteString(" histogram\n") default: return written, fmt.Errorf("unknown metric type %s", metricType.String()) } written += n if err != nil { - return + return written, err } // Finally the samples, one line for each. @@ -208,7 +211,7 @@ func MetricFamilyToText(out io.Writer, in *dto.MetricFamily) (written int, err e ) written += n if err != nil { - return + return written, err } } n, err = writeSample( @@ -217,13 +220,13 @@ func MetricFamilyToText(out io.Writer, in *dto.MetricFamily) (written int, err e ) written += n if err != nil { - return + return written, err } n, err = writeSample( w, name, "_count", metric, "", 0, float64(metric.Summary.GetSampleCount()), ) - case dto.MetricType_HISTOGRAM: + case dto.MetricType_HISTOGRAM, dto.MetricType_GAUGE_HISTOGRAM: if metric.Histogram == nil { return written, fmt.Errorf( "expected histogram in metric %s %s", name, metric, @@ -231,28 +234,36 @@ func MetricFamilyToText(out io.Writer, in *dto.MetricFamily) (written int, err e } infSeen := false for _, b := range metric.Histogram.Bucket { + v := b.GetCumulativeCountFloat() + if v == 0 { + v = float64(b.GetCumulativeCount()) + } n, err = writeSample( w, name, "_bucket", metric, model.BucketLabel, b.GetUpperBound(), - float64(b.GetCumulativeCount()), + v, ) written += n if err != nil { - return + return written, err } if math.IsInf(b.GetUpperBound(), +1) { infSeen = true } } if !infSeen { + v := metric.Histogram.GetSampleCountFloat() + if v == 0 { + v = float64(metric.Histogram.GetSampleCount()) + } n, err = writeSample( w, name, "_bucket", metric, model.BucketLabel, math.Inf(+1), - float64(metric.Histogram.GetSampleCount()), + v, ) written += n if err != nil { - return + return written, err } } n, err = writeSample( @@ -261,12 +272,13 @@ func MetricFamilyToText(out io.Writer, in *dto.MetricFamily) (written int, err e ) written += n if err != nil { - return + return written, err } - n, err = writeSample( - w, name, "_count", metric, "", 0, - float64(metric.Histogram.GetSampleCount()), - ) + v := metric.Histogram.GetSampleCountFloat() + if v == 0 { + v = float64(metric.Histogram.GetSampleCount()) + } + n, err = writeSample(w, name, "_count", metric, "", 0, v) default: return written, fmt.Errorf( "unexpected type in metric %s %s", name, metric, @@ -274,10 +286,10 @@ func MetricFamilyToText(out io.Writer, in *dto.MetricFamily) (written int, err e } written += n if err != nil { - return + return written, err } } - return + return written, err } // writeSample writes a single sample in text format to w, given the metric diff --git a/vendor/github.com/prometheus/common/expfmt/text_parse.go b/vendor/github.com/prometheus/common/expfmt/text_parse.go index 8f2edde32..4ce1f40b8 100644 --- a/vendor/github.com/prometheus/common/expfmt/text_parse.go +++ b/vendor/github.com/prometheus/common/expfmt/text_parse.go @@ -48,8 +48,10 @@ func (e ParseError) Error() string { return fmt.Sprintf("text format parsing error in line %d: %s", e.Line, e.Msg) } -// TextParser is used to parse the simple and flat text-based exchange format. Its -// zero value is ready to use. +// TextParser is used to parse the simple and flat text-based exchange format. +// +// TextParser instances must be created with NewTextParser, the zero value of +// TextParser is invalid. type TextParser struct { metricFamiliesByName map[string]*dto.MetricFamily buf *bufio.Reader // Where the parsed input is read through. @@ -129,9 +131,44 @@ func (p *TextParser) TextToMetricFamilies(in io.Reader) (map[string]*dto.MetricF if p.err != nil && errors.Is(p.err, io.EOF) { p.parseError("unexpected end of input stream") } + for _, histogramMetric := range p.histograms { + normalizeHistogram(histogramMetric.GetHistogram()) + } return p.metricFamiliesByName, p.err } +// normalizeHistogram makes sure that all the buckets and the count in each +// histogram is either completely float or completely integer. +func normalizeHistogram(histogram *dto.Histogram) { + if histogram == nil { + return + } + anyFloats := false + if histogram.GetSampleCountFloat() != 0 { + anyFloats = true + } else { + for _, b := range histogram.GetBucket() { + if b.GetCumulativeCountFloat() != 0 { + anyFloats = true + break + } + } + } + if !anyFloats { + return + } + if histogram.GetSampleCountFloat() == 0 { + histogram.SampleCountFloat = proto.Float64(float64(histogram.GetSampleCount())) + histogram.SampleCount = nil + } + for _, b := range histogram.GetBucket() { + if b.GetCumulativeCountFloat() == 0 { + b.CumulativeCountFloat = proto.Float64(float64(b.GetCumulativeCount())) + b.CumulativeCount = nil + } + } +} + func (p *TextParser) reset(in io.Reader) { p.metricFamiliesByName = map[string]*dto.MetricFamily{} p.currentLabelPairs = nil @@ -281,7 +318,9 @@ func (p *TextParser) readingLabels() stateFn { // Summaries/histograms are special. We have to reset the // currentLabels map, currentQuantile and currentBucket before starting to // read labels. - if p.currentMF.GetType() == dto.MetricType_SUMMARY || p.currentMF.GetType() == dto.MetricType_HISTOGRAM { + if p.currentMF.GetType() == dto.MetricType_SUMMARY || + p.currentMF.GetType() == dto.MetricType_HISTOGRAM || + p.currentMF.GetType() == dto.MetricType_GAUGE_HISTOGRAM { p.currentLabels = map[string]string{} p.currentLabels[string(model.MetricNameLabel)] = p.currentMF.GetName() p.currentQuantile = math.NaN() @@ -300,6 +339,16 @@ func (p *TextParser) startLabelName() stateFn { return nil // Unexpected end of input. } if p.currentByte == '}' { + if p.currentMF == nil { + // The closing brace was reached before any metric name was read, + // e.g. for the input "{}". There is no metric to attach labels to, + // so this is a malformed exposition. This mirrors the guard in + // startLabelValue. currentMF (not currentMetric) is checked because + // reset only clears currentMF between parses. + p.parseError("invalid metric name") + p.currentLabelPairs = nil + return nil + } p.currentMetric.Label = append(p.currentMetric.Label, p.currentLabelPairs...) p.currentLabelPairs = nil if p.skipBlankTab(); p.err != nil { @@ -374,7 +423,9 @@ func (p *TextParser) startLabelName() stateFn { // Special summary/histogram treatment. Don't add 'quantile' and 'le' // labels to 'real' labels. if (p.currentMF.GetType() != dto.MetricType_SUMMARY || p.currentLabelPair.GetName() != model.QuantileLabel) && - (p.currentMF.GetType() != dto.MetricType_HISTOGRAM || p.currentLabelPair.GetName() != model.BucketLabel) { + ((p.currentMF.GetType() != dto.MetricType_HISTOGRAM && + p.currentMF.GetType() != dto.MetricType_GAUGE_HISTOGRAM) || + p.currentLabelPair.GetName() != model.BucketLabel) { p.currentLabelPairs = append(p.currentLabelPairs, p.currentLabelPair) } // Check for duplicate label names. @@ -425,7 +476,7 @@ func (p *TextParser) startLabelValue() stateFn { } } // Similar special treatment of histograms. - if p.currentMF.GetType() == dto.MetricType_HISTOGRAM { + if p.currentMF.GetType() == dto.MetricType_HISTOGRAM || p.currentMF.GetType() == dto.MetricType_GAUGE_HISTOGRAM { if p.currentLabelPair.GetName() == model.BucketLabel { if p.currentBucket, p.err = parseFloat(p.currentLabelPair.GetValue()); p.err != nil { // Create a more helpful error message. @@ -476,7 +527,7 @@ func (p *TextParser) readingValue() stateFn { p.summaries[signature] = p.currentMetric p.currentMF.Metric = append(p.currentMF.Metric, p.currentMetric) } - case dto.MetricType_HISTOGRAM: + case dto.MetricType_HISTOGRAM, dto.MetricType_GAUGE_HISTOGRAM: signature := model.LabelsToSignature(p.currentLabels) if histogram := p.histograms[signature]; histogram != nil { p.currentMetric = histogram @@ -522,24 +573,38 @@ func (p *TextParser) readingValue() stateFn { }, ) } - case dto.MetricType_HISTOGRAM: + case dto.MetricType_HISTOGRAM, dto.MetricType_GAUGE_HISTOGRAM: // *sigh* if p.currentMetric.Histogram == nil { p.currentMetric.Histogram = &dto.Histogram{} } switch { case p.currentIsHistogramCount: - p.currentMetric.Histogram.SampleCount = proto.Uint64(uint64(value)) + if uintValue := uint64(value); value == float64(uintValue) { + p.currentMetric.Histogram.SampleCount = proto.Uint64(uintValue) + } else { + if value < 0 { + p.parseError(fmt.Sprintf("negative count for histogram %q", p.currentMF.GetName())) + return nil + } + p.currentMetric.Histogram.SampleCountFloat = proto.Float64(value) + } case p.currentIsHistogramSum: p.currentMetric.Histogram.SampleSum = proto.Float64(value) case !math.IsNaN(p.currentBucket): - p.currentMetric.Histogram.Bucket = append( - p.currentMetric.Histogram.Bucket, - &dto.Bucket{ - UpperBound: proto.Float64(p.currentBucket), - CumulativeCount: proto.Uint64(uint64(value)), - }, - ) + b := &dto.Bucket{ + UpperBound: proto.Float64(p.currentBucket), + } + if uintValue := uint64(value); value == float64(uintValue) { + b.CumulativeCount = proto.Uint64(uintValue) + } else { + if value < 0 { + p.parseError(fmt.Sprintf("negative bucket population for histogram %q", p.currentMF.GetName())) + return nil + } + b.CumulativeCountFloat = proto.Float64(value) + } + p.currentMetric.Histogram.Bucket = append(p.currentMetric.Histogram.Bucket, b) } default: p.err = fmt.Errorf("unexpected type for metric name %q", p.currentMF.GetName()) @@ -602,10 +667,18 @@ func (p *TextParser) readingType() stateFn { if p.readTokenUntilNewline(false); p.err != nil { return nil // Unexpected end of input. } - metricType, ok := dto.MetricType_value[strings.ToUpper(p.currentToken.String())] + typ := strings.ToUpper(p.currentToken.String()) // Tolerate any combination of upper and lower case. + metricType, ok := dto.MetricType_value[typ] // Tolerate "gauge_histogram" (not originally part of the text format). if !ok { - p.parseError(fmt.Sprintf("unknown metric type %q", p.currentToken.String())) - return nil + // We also want to tolerate "gaugehistogram" to mark a gauge + // histogram, because that string is used in OpenMetrics. Note, + // however, that gauge histograms do not officially exist in the + // classic text format. + if typ != "GAUGEHISTOGRAM" { + p.parseError(fmt.Sprintf("unknown metric type %q", p.currentToken.String())) + return nil + } + metricType = int32(dto.MetricType_GAUGE_HISTOGRAM) } p.currentMF.Type = dto.MetricType(metricType).Enum() return p.startOfLine @@ -855,7 +928,8 @@ func (p *TextParser) setOrCreateCurrentMF() { } histogramName := histogramMetricName(name) if p.currentMF = p.metricFamiliesByName[histogramName]; p.currentMF != nil { - if p.currentMF.GetType() == dto.MetricType_HISTOGRAM { + if p.currentMF.GetType() == dto.MetricType_HISTOGRAM || + p.currentMF.GetType() == dto.MetricType_GAUGE_HISTOGRAM { if isCount(name) { p.currentIsHistogramCount = true } diff --git a/vendor/github.com/prometheus/common/model/labels.go b/vendor/github.com/prometheus/common/model/labels.go index dfeb34be5..29688a13c 100644 --- a/vendor/github.com/prometheus/common/model/labels.go +++ b/vendor/github.com/prometheus/common/model/labels.go @@ -124,7 +124,7 @@ func (ln LabelName) IsValidLegacy() bool { } // UnmarshalYAML implements the yaml.Unmarshaler interface. -func (ln *LabelName) UnmarshalYAML(unmarshal func(interface{}) error) error { +func (ln *LabelName) UnmarshalYAML(unmarshal func(any) error) error { var s string if err := unmarshal(&s); err != nil { return err diff --git a/vendor/github.com/prometheus/common/model/labelset.go b/vendor/github.com/prometheus/common/model/labelset.go index 9de47b256..6010b26a8 100644 --- a/vendor/github.com/prometheus/common/model/labelset.go +++ b/vendor/github.com/prometheus/common/model/labelset.go @@ -16,6 +16,7 @@ package model import ( "encoding/json" "fmt" + "maps" "sort" ) @@ -107,9 +108,7 @@ func (ls LabelSet) Before(o LabelSet) bool { // Clone returns a copy of the label set. func (ls LabelSet) Clone() LabelSet { lsn := make(LabelSet, len(ls)) - for ln, lv := range ls { - lsn[ln] = lv - } + maps.Copy(lsn, ls) return lsn } @@ -117,13 +116,9 @@ func (ls LabelSet) Clone() LabelSet { func (ls LabelSet) Merge(other LabelSet) LabelSet { result := make(LabelSet, len(ls)) - for k, v := range ls { - result[k] = v - } + maps.Copy(result, ls) - for k, v := range other { - result[k] = v - } + maps.Copy(result, other) return result } diff --git a/vendor/github.com/prometheus/common/model/metric.go b/vendor/github.com/prometheus/common/model/metric.go index 3feebf328..2fe461511 100644 --- a/vendor/github.com/prometheus/common/model/metric.go +++ b/vendor/github.com/prometheus/common/model/metric.go @@ -17,6 +17,7 @@ import ( "encoding/json" "errors" "fmt" + "maps" "regexp" "sort" "strconv" @@ -24,7 +25,6 @@ import ( "unicode/utf8" dto "github.com/prometheus/client_model/go" - "go.yaml.in/yaml/v2" "google.golang.org/protobuf/proto" ) @@ -78,14 +78,6 @@ const ( UTF8Validation ) -var _ interface { - yaml.Marshaler - yaml.Unmarshaler - json.Marshaler - json.Unmarshaler - fmt.Stringer -} = new(ValidationScheme) - // String returns the string representation of s. func (s ValidationScheme) String() string { switch s { @@ -267,9 +259,7 @@ func (m Metric) Before(o Metric) bool { // Clone returns a copy of the Metric. func (m Metric) Clone() Metric { clone := make(Metric, len(m)) - for k, v := range m { - clone[k] = v - } + maps.Copy(clone, m) return clone } diff --git a/vendor/github.com/prometheus/common/model/time.go b/vendor/github.com/prometheus/common/model/time.go index 1730b0fdc..0854753f4 100644 --- a/vendor/github.com/prometheus/common/model/time.go +++ b/vendor/github.com/prometheus/common/model/time.go @@ -123,44 +123,38 @@ func (t Time) MarshalJSON() ([]byte, error) { // UnmarshalJSON implements the json.Unmarshaler interface. func (t *Time) UnmarshalJSON(b []byte) error { - p := strings.Split(string(b), ".") - switch len(p) { - case 1: - v, err := strconv.ParseInt(p[0], 10, 64) + base, frac, found := strings.Cut(string(b), ".") + if !found { + v, err := strconv.ParseInt(base, 10, 64) if err != nil { return err } *t = Time(v * second) - - case 2: - v, err := strconv.ParseInt(p[0], 10, 64) + } else { + v, err := strconv.ParseInt(base, 10, 64) if err != nil { return err } - v *= second - prec := dotPrecision - len(p[1]) + prec := dotPrecision - len(frac) if prec < 0 { - p[1] = p[1][:dotPrecision] - } else if prec > 0 { - p[1] += strings.Repeat("0", prec) + frac = frac[:dotPrecision] } - - va, err := strconv.ParseInt(p[1], 10, 32) + va, err := strconv.ParseInt(frac, 10, 32) if err != nil { return err } - - // If the value was something like -0.1 the negative is lost in the - // parsing because of the leading zero, this ensures that we capture it. - if len(p[0]) > 0 && p[0][0] == '-' && v+va > 0 { - *t = Time(v+va) * -1 - } else { - *t = Time(v + va) + switch prec { + case 1: + va *= 10 + case 2: + va *= 100 } - default: - return fmt.Errorf("invalid time %q", string(b)) + if len(base) > 0 && base[0] == '-' { + va = -va + } + *t = Time(v*second + va) } return nil } @@ -340,12 +334,12 @@ func (d *Duration) UnmarshalText(text []byte) error { } // MarshalYAML implements the yaml.Marshaler interface. -func (d Duration) MarshalYAML() (interface{}, error) { +func (d Duration) MarshalYAML() (any, error) { return d.String(), nil } // UnmarshalYAML implements the yaml.Unmarshaler interface. -func (d *Duration) UnmarshalYAML(unmarshal func(interface{}) error) error { +func (d *Duration) UnmarshalYAML(unmarshal func(any) error) error { var s string if err := unmarshal(&s); err != nil { return err diff --git a/vendor/github.com/prometheus/common/model/value.go b/vendor/github.com/prometheus/common/model/value.go index a9995a37e..8dffd9c4a 100644 --- a/vendor/github.com/prometheus/common/model/value.go +++ b/vendor/github.com/prometheus/common/model/value.go @@ -259,13 +259,13 @@ func (s Scalar) String() string { // MarshalJSON implements json.Marshaler. func (s Scalar) MarshalJSON() ([]byte, error) { v := strconv.FormatFloat(float64(s.Value), 'f', -1, 64) - return json.Marshal([...]interface{}{s.Timestamp, v}) + return json.Marshal([...]any{s.Timestamp, v}) } // UnmarshalJSON implements json.Unmarshaler. func (s *Scalar) UnmarshalJSON(b []byte) error { var f string - v := [...]interface{}{&s.Timestamp, &f} + v := [...]any{&s.Timestamp, &f} if err := json.Unmarshal(b, &v); err != nil { return err @@ -291,12 +291,12 @@ func (s *String) String() string { // MarshalJSON implements json.Marshaler. func (s String) MarshalJSON() ([]byte, error) { - return json.Marshal([]interface{}{s.Timestamp, s.Value}) + return json.Marshal([]any{s.Timestamp, s.Value}) } // UnmarshalJSON implements json.Unmarshaler. func (s *String) UnmarshalJSON(b []byte) error { - v := [...]interface{}{&s.Timestamp, &s.Value} + v := [...]any{&s.Timestamp, &s.Value} return json.Unmarshal(b, &v) } diff --git a/vendor/github.com/prometheus/common/model/value_float.go b/vendor/github.com/prometheus/common/model/value_float.go index 6bfc757d1..b7d93615e 100644 --- a/vendor/github.com/prometheus/common/model/value_float.go +++ b/vendor/github.com/prometheus/common/model/value_float.go @@ -79,7 +79,7 @@ func (s SamplePair) MarshalJSON() ([]byte, error) { if err != nil { return nil, err } - return []byte(fmt.Sprintf("[%s,%s]", t, v)), nil + return fmt.Appendf(nil, "[%s,%s]", t, v), nil } // UnmarshalJSON implements json.Unmarshaler. diff --git a/vendor/github.com/prometheus/common/model/value_histogram.go b/vendor/github.com/prometheus/common/model/value_histogram.go index 91ce5b7a4..f27856ccc 100644 --- a/vendor/github.com/prometheus/common/model/value_histogram.go +++ b/vendor/github.com/prometheus/common/model/value_histogram.go @@ -67,11 +67,11 @@ func (s HistogramBucket) MarshalJSON() ([]byte, error) { if err != nil { return nil, err } - return []byte(fmt.Sprintf("[%s,%s,%s,%s]", b, l, u, c)), nil + return fmt.Appendf(nil, "[%s,%s,%s,%s]", b, l, u, c), nil } func (s *HistogramBucket) UnmarshalJSON(buf []byte) error { - tmp := []interface{}{&s.Boundaries, &s.Lower, &s.Upper, &s.Count} + tmp := []any{&s.Boundaries, &s.Lower, &s.Upper, &s.Count} wantLen := len(tmp) if err := json.Unmarshal(buf, &tmp); err != nil { return err @@ -152,11 +152,11 @@ func (s SampleHistogramPair) MarshalJSON() ([]byte, error) { if err != nil { return nil, err } - return []byte(fmt.Sprintf("[%s,%s]", t, v)), nil + return fmt.Appendf(nil, "[%s,%s]", t, v), nil } func (s *SampleHistogramPair) UnmarshalJSON(buf []byte) error { - tmp := []interface{}{&s.Timestamp, &s.Histogram} + tmp := []any{&s.Timestamp, &s.Histogram} wantLen := len(tmp) if err := json.Unmarshal(buf, &tmp); err != nil { return err diff --git a/vendor/github.com/prometheus/procfs/Makefile.common b/vendor/github.com/prometheus/procfs/Makefile.common index 0ed55c2ba..a7c5f553e 100644 --- a/vendor/github.com/prometheus/procfs/Makefile.common +++ b/vendor/github.com/prometheus/procfs/Makefile.common @@ -1,4 +1,4 @@ -# Copyright 2018 The Prometheus Authors +# Copyright The Prometheus 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 @@ -33,7 +33,7 @@ GOHOSTOS ?= $(shell $(GO) env GOHOSTOS) GOHOSTARCH ?= $(shell $(GO) env GOHOSTARCH) GO_VERSION ?= $(shell $(GO) version) -GO_VERSION_NUMBER ?= $(word 3, $(GO_VERSION))Error Parsing File +GO_VERSION_NUMBER ?= $(word 3, $(GO_VERSION)) PRE_GO_111 ?= $(shell echo $(GO_VERSION_NUMBER) | grep -E 'go1\.(10|[0-9])\.') PROMU := $(FIRST_GOPATH)/bin/promu @@ -55,13 +55,14 @@ ifneq ($(shell command -v gotestsum 2> /dev/null),) endif endif -PROMU_VERSION ?= 0.17.0 +PROMU_VERSION ?= 0.20.0 PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_VERSION)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM).tar.gz SKIP_GOLANGCI_LINT := GOLANGCI_LINT := GOLANGCI_LINT_OPTS ?= -GOLANGCI_LINT_VERSION ?= v2.0.2 +GOLANGCI_LINT_VERSION ?= v2.11.4 +GOLANGCI_FMT_OPTS ?= # golangci-lint only supports linux, darwin and windows platforms on i386/amd64/arm64. # windows isn't included here because of the path separator being different. ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin)) @@ -81,11 +82,32 @@ endif PREFIX ?= $(shell pwd) BIN_DIR ?= $(shell pwd) DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD)) -DOCKERFILE_PATH ?= ./Dockerfile DOCKERBUILD_CONTEXT ?= ./ DOCKER_REPO ?= prom -DOCKER_ARCHS ?= amd64 +# Check if deprecated DOCKERFILE_PATH is set +ifdef DOCKERFILE_PATH +$(error DOCKERFILE_PATH is deprecated. Use DOCKERFILE_VARIANTS ?= $(DOCKERFILE_PATH) in the Makefile) +endif + +DOCKER_ARCHS ?= amd64 arm64 armv7 ppc64le riscv64 s390x +DOCKERFILE_VARIANTS ?= $(wildcard Dockerfile Dockerfile.*) + +# Function to extract variant from Dockerfile label. +# Returns the variant name from io.prometheus.image.variant label, or "default" if not found. +define dockerfile_variant +$(strip $(or $(shell sed -n 's/.*io\.prometheus\.image\.variant="\([^"]*\)".*/\1/p' $(1)),default)) +endef + +# Check for duplicate variant names (including default for Dockerfiles without labels). +DOCKERFILE_VARIANT_NAMES := $(foreach df,$(DOCKERFILE_VARIANTS),$(call dockerfile_variant,$(df))) +DOCKERFILE_VARIANT_NAMES_SORTED := $(sort $(DOCKERFILE_VARIANT_NAMES)) +ifneq ($(words $(DOCKERFILE_VARIANT_NAMES)),$(words $(DOCKERFILE_VARIANT_NAMES_SORTED))) +$(error Duplicate variant names found. Each Dockerfile must have a unique io.prometheus.image.variant label, and only one can be without a label (default)) +endif + +# Build variant:dockerfile pairs for shell iteration. +DOCKERFILE_VARIANTS_WITH_NAMES := $(foreach df,$(DOCKERFILE_VARIANTS),$(call dockerfile_variant,$(df)):$(df)) BUILD_DOCKER_ARCHS = $(addprefix common-docker-,$(DOCKER_ARCHS)) PUBLISH_DOCKER_ARCHS = $(addprefix common-docker-publish-,$(DOCKER_ARCHS)) @@ -111,7 +133,7 @@ common-all: precheck style check_license lint yamllint unused build test .PHONY: common-style common-style: @echo ">> checking code style" - @fmtRes=$$($(GOFMT) -d $$(find . -path ./vendor -prune -o -name '*.go' -print)); \ + @fmtRes=$$($(GOFMT) -d $$(git ls-files '*.go' ':!:vendor/*' || find . -path ./vendor -prune -o -name '*.go' -print)); \ if [ -n "$${fmtRes}" ]; then \ echo "gofmt checking failed!"; echo "$${fmtRes}"; echo; \ echo "Please ensure you are using $$($(GO) version) for formatting code."; \ @@ -121,13 +143,19 @@ common-style: .PHONY: common-check_license common-check_license: @echo ">> checking license header" - @licRes=$$(for file in $$(find . -type f -iname '*.go' ! -path './vendor/*') ; do \ + @licRes=$$(for file in $$(git ls-files '*.go' ':!:vendor/*' || find . -path ./vendor -prune -o -type f -iname '*.go' -print) ; do \ awk 'NR<=3' $$file | grep -Eq "(Copyright|generated|GENERATED)" || echo $$file; \ done); \ if [ -n "$${licRes}" ]; then \ echo "license header checking failed:"; echo "$${licRes}"; \ exit 1; \ fi + @echo ">> checking for copyright years 2026 or later" + @futureYearRes=$$(git grep -E 'Copyright (202[6-9]|20[3-9][0-9])' -- '*.go' ':!:vendor/*' || true); \ + if [ -n "$${futureYearRes}" ]; then \ + echo "Files with copyright year 2026 or later found (should use 'Copyright The Prometheus Authors'):"; echo "$${futureYearRes}"; \ + exit 1; \ + fi .PHONY: common-deps common-deps: @@ -138,7 +166,7 @@ common-deps: update-go-deps: @echo ">> updating Go dependencies" @for m in $$($(GO) list -mod=readonly -m -f '{{ if and (not .Indirect) (not .Main)}}{{.Path}}{{end}}' all); do \ - $(GO) get -d $$m; \ + $(GO) get $$m; \ done $(GO) mod tidy @@ -156,9 +184,13 @@ $(GOTEST_DIR): @mkdir -p $@ .PHONY: common-format -common-format: +common-format: $(GOLANGCI_LINT) @echo ">> formatting code" $(GO) fmt $(pkgs) +ifdef GOLANGCI_LINT + @echo ">> formatting code with golangci-lint" + $(GOLANGCI_LINT) fmt $(GOLANGCI_FMT_OPTS) +endif .PHONY: common-vet common-vet: @@ -215,28 +247,142 @@ common-docker-repo-name: .PHONY: common-docker $(BUILD_DOCKER_ARCHS) common-docker: $(BUILD_DOCKER_ARCHS) $(BUILD_DOCKER_ARCHS): common-docker-%: - docker build -t "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(SANITIZED_DOCKER_IMAGE_TAG)" \ - -f $(DOCKERFILE_PATH) \ - --build-arg ARCH="$*" \ - --build-arg OS="linux" \ - $(DOCKERBUILD_CONTEXT) + @for variant in $(DOCKERFILE_VARIANTS_WITH_NAMES); do \ + dockerfile=$${variant#*:}; \ + variant_name=$${variant%%:*}; \ + distroless_arch="$*"; \ + if [ "$*" = "armv7" ]; then \ + distroless_arch="arm"; \ + fi; \ + if [ "$$dockerfile" = "Dockerfile" ]; then \ + echo "Building default variant ($$variant_name) for linux-$* using $$dockerfile"; \ + docker build -t "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(SANITIZED_DOCKER_IMAGE_TAG)" \ + -f $$dockerfile \ + --build-arg ARCH="$*" \ + --build-arg OS="linux" \ + --build-arg DISTROLESS_ARCH="$$distroless_arch" \ + $(DOCKERBUILD_CONTEXT); \ + if [ "$$variant_name" != "default" ]; then \ + echo "Tagging default variant with $$variant_name suffix"; \ + docker tag "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(SANITIZED_DOCKER_IMAGE_TAG)" \ + "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(SANITIZED_DOCKER_IMAGE_TAG)-$$variant_name"; \ + fi; \ + else \ + echo "Building $$variant_name variant for linux-$* using $$dockerfile"; \ + docker build -t "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(SANITIZED_DOCKER_IMAGE_TAG)-$$variant_name" \ + -f $$dockerfile \ + --build-arg ARCH="$*" \ + --build-arg OS="linux" \ + --build-arg DISTROLESS_ARCH="$$distroless_arch" \ + $(DOCKERBUILD_CONTEXT); \ + fi; \ + done .PHONY: common-docker-publish $(PUBLISH_DOCKER_ARCHS) common-docker-publish: $(PUBLISH_DOCKER_ARCHS) $(PUBLISH_DOCKER_ARCHS): common-docker-publish-%: - docker push "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(SANITIZED_DOCKER_IMAGE_TAG)" + @for variant in $(DOCKERFILE_VARIANTS_WITH_NAMES); do \ + dockerfile=$${variant#*:}; \ + variant_name=$${variant%%:*}; \ + if [ "$$dockerfile" != "Dockerfile" ] || [ "$$variant_name" != "default" ]; then \ + echo "Pushing $$variant_name variant for linux-$*"; \ + docker push "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(SANITIZED_DOCKER_IMAGE_TAG)-$$variant_name"; \ + fi; \ + if [ "$$dockerfile" = "Dockerfile" ]; then \ + echo "Pushing default variant ($$variant_name) for linux-$*"; \ + docker push "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(SANITIZED_DOCKER_IMAGE_TAG)"; \ + fi; \ + if [ "$(DOCKER_IMAGE_TAG)" = "latest" ]; then \ + if [ "$$dockerfile" != "Dockerfile" ] || [ "$$variant_name" != "default" ]; then \ + echo "Pushing $$variant_name variant version tags for linux-$*"; \ + docker push "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:v$(DOCKER_MAJOR_VERSION_TAG)-$$variant_name"; \ + fi; \ + if [ "$$dockerfile" = "Dockerfile" ]; then \ + echo "Pushing default variant version tag for linux-$*"; \ + docker push "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:v$(DOCKER_MAJOR_VERSION_TAG)"; \ + fi; \ + fi; \ + done DOCKER_MAJOR_VERSION_TAG = $(firstword $(subst ., ,$(shell cat VERSION))) .PHONY: common-docker-tag-latest $(TAG_DOCKER_ARCHS) common-docker-tag-latest: $(TAG_DOCKER_ARCHS) $(TAG_DOCKER_ARCHS): common-docker-tag-latest-%: - docker tag "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(SANITIZED_DOCKER_IMAGE_TAG)" "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:latest" - docker tag "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(SANITIZED_DOCKER_IMAGE_TAG)" "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:v$(DOCKER_MAJOR_VERSION_TAG)" + @for variant in $(DOCKERFILE_VARIANTS_WITH_NAMES); do \ + dockerfile=$${variant#*:}; \ + variant_name=$${variant%%:*}; \ + if [ "$$dockerfile" != "Dockerfile" ] || [ "$$variant_name" != "default" ]; then \ + echo "Tagging $$variant_name variant for linux-$* as latest"; \ + docker tag "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(SANITIZED_DOCKER_IMAGE_TAG)-$$variant_name" "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:latest-$$variant_name"; \ + docker tag "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(SANITIZED_DOCKER_IMAGE_TAG)-$$variant_name" "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:v$(DOCKER_MAJOR_VERSION_TAG)-$$variant_name"; \ + fi; \ + if [ "$$dockerfile" = "Dockerfile" ]; then \ + echo "Tagging default variant ($$variant_name) for linux-$* as latest"; \ + docker tag "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(SANITIZED_DOCKER_IMAGE_TAG)" "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:latest"; \ + docker tag "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(SANITIZED_DOCKER_IMAGE_TAG)" "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:v$(DOCKER_MAJOR_VERSION_TAG)"; \ + fi; \ + done .PHONY: common-docker-manifest common-docker-manifest: - DOCKER_CLI_EXPERIMENTAL=enabled docker manifest create -a "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):$(SANITIZED_DOCKER_IMAGE_TAG)" $(foreach ARCH,$(DOCKER_ARCHS),$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$(ARCH):$(SANITIZED_DOCKER_IMAGE_TAG)) - DOCKER_CLI_EXPERIMENTAL=enabled docker manifest push "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):$(SANITIZED_DOCKER_IMAGE_TAG)" + @for variant in $(DOCKERFILE_VARIANTS_WITH_NAMES); do \ + dockerfile=$${variant#*:}; \ + variant_name=$${variant%%:*}; \ + if [ "$$dockerfile" != "Dockerfile" ] || [ "$$variant_name" != "default" ]; then \ + echo "Creating manifest for $$variant_name variant"; \ + refs=""; \ + for arch in $(DOCKER_ARCHS); do \ + refs="$$refs $(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$$arch:$(SANITIZED_DOCKER_IMAGE_TAG)-$$variant_name"; \ + done; \ + if [ -z "$$refs" ]; then \ + echo "Skipping manifest for $$variant_name variant (no supported architectures)"; \ + continue; \ + fi; \ + DOCKER_CLI_EXPERIMENTAL=enabled docker manifest create -a "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):$(SANITIZED_DOCKER_IMAGE_TAG)-$$variant_name" $$refs; \ + DOCKER_CLI_EXPERIMENTAL=enabled docker manifest push "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):$(SANITIZED_DOCKER_IMAGE_TAG)-$$variant_name"; \ + fi; \ + if [ "$$dockerfile" = "Dockerfile" ]; then \ + echo "Creating default variant ($$variant_name) manifest"; \ + refs=""; \ + for arch in $(DOCKER_ARCHS); do \ + refs="$$refs $(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$$arch:$(SANITIZED_DOCKER_IMAGE_TAG)"; \ + done; \ + if [ -z "$$refs" ]; then \ + echo "Skipping default variant manifest (no supported architectures)"; \ + continue; \ + fi; \ + DOCKER_CLI_EXPERIMENTAL=enabled docker manifest create -a "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):$(SANITIZED_DOCKER_IMAGE_TAG)" $$refs; \ + DOCKER_CLI_EXPERIMENTAL=enabled docker manifest push "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):$(SANITIZED_DOCKER_IMAGE_TAG)"; \ + fi; \ + if [ "$(DOCKER_IMAGE_TAG)" = "latest" ]; then \ + if [ "$$dockerfile" != "Dockerfile" ] || [ "$$variant_name" != "default" ]; then \ + echo "Creating manifest for $$variant_name variant version tag"; \ + refs=""; \ + for arch in $(DOCKER_ARCHS); do \ + refs="$$refs $(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$$arch:v$(DOCKER_MAJOR_VERSION_TAG)-$$variant_name"; \ + done; \ + if [ -z "$$refs" ]; then \ + echo "Skipping version-tag manifest for $$variant_name variant (no supported architectures)"; \ + continue; \ + fi; \ + DOCKER_CLI_EXPERIMENTAL=enabled docker manifest create -a "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):v$(DOCKER_MAJOR_VERSION_TAG)-$$variant_name" $$refs; \ + DOCKER_CLI_EXPERIMENTAL=enabled docker manifest push "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):v$(DOCKER_MAJOR_VERSION_TAG)-$$variant_name"; \ + fi; \ + if [ "$$dockerfile" = "Dockerfile" ]; then \ + echo "Creating default variant version tag manifest"; \ + refs=""; \ + for arch in $(DOCKER_ARCHS); do \ + refs="$$refs $(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$$arch:v$(DOCKER_MAJOR_VERSION_TAG)"; \ + done; \ + if [ -z "$$refs" ]; then \ + echo "Skipping default variant version-tag manifest (no supported architectures)"; \ + continue; \ + fi; \ + DOCKER_CLI_EXPERIMENTAL=enabled docker manifest create -a "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):v$(DOCKER_MAJOR_VERSION_TAG)" $$refs; \ + DOCKER_CLI_EXPERIMENTAL=enabled docker manifest push "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):v$(DOCKER_MAJOR_VERSION_TAG)"; \ + fi; \ + fi; \ + done .PHONY: promu promu: $(PROMU) @@ -248,8 +394,8 @@ $(PROMU): cp $(PROMU_TMP)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM)/promu $(FIRST_GOPATH)/bin/promu rm -r $(PROMU_TMP) -.PHONY: proto -proto: +.PHONY: common-proto +common-proto: @echo ">> generating code from proto files" @./scripts/genproto.sh @@ -261,6 +407,10 @@ $(GOLANGCI_LINT): | sh -s -- -b $(FIRST_GOPATH)/bin $(GOLANGCI_LINT_VERSION) endif +.PHONY: common-print-golangci-lint-version +common-print-golangci-lint-version: + @echo $(GOLANGCI_LINT_VERSION) + .PHONY: precheck precheck:: @@ -275,9 +425,3 @@ $(1)_precheck: exit 1; \ fi endef - -govulncheck: install-govulncheck - govulncheck ./... - -install-govulncheck: - command -v govulncheck > /dev/null || go install golang.org/x/vuln/cmd/govulncheck@latest diff --git a/vendor/github.com/prometheus/procfs/SECURITY.md b/vendor/github.com/prometheus/procfs/SECURITY.md index fed02d85c..5e6f976db 100644 --- a/vendor/github.com/prometheus/procfs/SECURITY.md +++ b/vendor/github.com/prometheus/procfs/SECURITY.md @@ -3,4 +3,4 @@ The Prometheus security policy, including how to report vulnerabilities, can be found here: - +[https://prometheus.io/docs/operating/security/](https://prometheus.io/docs/operating/security/) diff --git a/vendor/github.com/prometheus/procfs/arp.go b/vendor/github.com/prometheus/procfs/arp.go index 2e5334415..716bdef10 100644 --- a/vendor/github.com/prometheus/procfs/arp.go +++ b/vendor/github.com/prometheus/procfs/arp.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Prometheus Authors +// Copyright The Prometheus 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 @@ -73,15 +73,16 @@ func parseARPEntries(data []byte) ([]ARPEntry, error) { columns := strings.Fields(line) width := len(columns) - if width == expectedHeaderWidth || width == 0 { + switch width { + case expectedHeaderWidth, 0: continue - } else if width == expectedDataWidth { + case expectedDataWidth: entry, err := parseARPEntry(columns) if err != nil { return []ARPEntry{}, fmt.Errorf("%w: Failed to parse ARP entry: %v: %w", ErrFileParse, entry, err) } entries = append(entries, entry) - } else { + default: return []ARPEntry{}, fmt.Errorf("%w: %d columns found, but expected %d: %w", ErrFileParse, width, expectedDataWidth, err) } diff --git a/vendor/github.com/prometheus/procfs/buddyinfo.go b/vendor/github.com/prometheus/procfs/buddyinfo.go index 838075009..53243e687 100644 --- a/vendor/github.com/prometheus/procfs/buddyinfo.go +++ b/vendor/github.com/prometheus/procfs/buddyinfo.go @@ -1,4 +1,4 @@ -// Copyright 2017 The Prometheus Authors +// Copyright The Prometheus 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 @@ -64,14 +64,12 @@ func parseBuddyInfo(r io.Reader) ([]BuddyInfo, error) { if bucketCount == -1 { bucketCount = arraySize - } else { - if bucketCount != arraySize { - return nil, fmt.Errorf("%w: mismatch in number of buddyinfo buckets, previous count %d, new count %d", ErrFileParse, bucketCount, arraySize) - } + } else if bucketCount != arraySize { + return nil, fmt.Errorf("%w: mismatch in number of buddyinfo buckets, previous count %d, new count %d", ErrFileParse, bucketCount, arraySize) } sizes := make([]float64, arraySize) - for i := 0; i < arraySize; i++ { + for i := range arraySize { sizes[i], err = strconv.ParseFloat(parts[i+4], 64) if err != nil { return nil, fmt.Errorf("%w: Invalid valid in buddyinfo: %f: %w", ErrFileParse, sizes[i], err) diff --git a/vendor/github.com/prometheus/procfs/cmdline.go b/vendor/github.com/prometheus/procfs/cmdline.go index bf4f3b48c..4f1cac1f0 100644 --- a/vendor/github.com/prometheus/procfs/cmdline.go +++ b/vendor/github.com/prometheus/procfs/cmdline.go @@ -1,4 +1,4 @@ -// Copyright 2021 The Prometheus Authors +// Copyright The Prometheus 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 diff --git a/vendor/github.com/prometheus/procfs/cpuinfo.go b/vendor/github.com/prometheus/procfs/cpuinfo.go index f0950bb49..4b23d8d6b 100644 --- a/vendor/github.com/prometheus/procfs/cpuinfo.go +++ b/vendor/github.com/prometheus/procfs/cpuinfo.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Prometheus Authors +// Copyright The Prometheus 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 @@ -12,7 +12,6 @@ // limitations under the License. //go:build linux -// +build linux package procfs @@ -502,7 +501,7 @@ func parseCPUInfoRISCV(info []byte) ([]CPUInfo, error) { return cpuinfo, nil } -func parseCPUInfoDummy(_ []byte) ([]CPUInfo, error) { // nolint:unused,deadcode +func parseCPUInfoDummy(_ []byte) ([]CPUInfo, error) { //nolint:unused return nil, errors.New("not implemented") } diff --git a/vendor/github.com/prometheus/procfs/cpuinfo_armx.go b/vendor/github.com/prometheus/procfs/cpuinfo_armx.go index 64cfd534c..b09035ff3 100644 --- a/vendor/github.com/prometheus/procfs/cpuinfo_armx.go +++ b/vendor/github.com/prometheus/procfs/cpuinfo_armx.go @@ -1,4 +1,4 @@ -// Copyright 2020 The Prometheus Authors +// Copyright The Prometheus 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 @@ -12,8 +12,6 @@ // limitations under the License. //go:build linux && (arm || arm64) -// +build linux -// +build arm arm64 package procfs diff --git a/vendor/github.com/prometheus/procfs/cpuinfo_loong64.go b/vendor/github.com/prometheus/procfs/cpuinfo_loong64.go index d88442f0e..7bb20211f 100644 --- a/vendor/github.com/prometheus/procfs/cpuinfo_loong64.go +++ b/vendor/github.com/prometheus/procfs/cpuinfo_loong64.go @@ -1,4 +1,4 @@ -// Copyright 2022 The Prometheus Authors +// Copyright The Prometheus 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 @@ -12,7 +12,6 @@ // limitations under the License. //go:build linux -// +build linux package procfs diff --git a/vendor/github.com/prometheus/procfs/cpuinfo_mipsx.go b/vendor/github.com/prometheus/procfs/cpuinfo_mipsx.go index c11207f3a..fd75d0f79 100644 --- a/vendor/github.com/prometheus/procfs/cpuinfo_mipsx.go +++ b/vendor/github.com/prometheus/procfs/cpuinfo_mipsx.go @@ -1,4 +1,4 @@ -// Copyright 2020 The Prometheus Authors +// Copyright The Prometheus 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 @@ -12,8 +12,6 @@ // limitations under the License. //go:build linux && (mips || mipsle || mips64 || mips64le) -// +build linux -// +build mips mipsle mips64 mips64le package procfs diff --git a/vendor/github.com/prometheus/procfs/cpuinfo_others.go b/vendor/github.com/prometheus/procfs/cpuinfo_others.go index a6b2b3127..3d36ba0e6 100644 --- a/vendor/github.com/prometheus/procfs/cpuinfo_others.go +++ b/vendor/github.com/prometheus/procfs/cpuinfo_others.go @@ -1,4 +1,4 @@ -// Copyright 2020 The Prometheus Authors +// Copyright The Prometheus 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 @@ -12,7 +12,6 @@ // limitations under the License. //go:build linux && !386 && !amd64 && !arm && !arm64 && !loong64 && !mips && !mips64 && !mips64le && !mipsle && !ppc64 && !ppc64le && !riscv64 && !s390x -// +build linux,!386,!amd64,!arm,!arm64,!loong64,!mips,!mips64,!mips64le,!mipsle,!ppc64,!ppc64le,!riscv64,!s390x package procfs diff --git a/vendor/github.com/prometheus/procfs/cpuinfo_ppcx.go b/vendor/github.com/prometheus/procfs/cpuinfo_ppcx.go index 003bc2ad4..b3425051e 100644 --- a/vendor/github.com/prometheus/procfs/cpuinfo_ppcx.go +++ b/vendor/github.com/prometheus/procfs/cpuinfo_ppcx.go @@ -1,4 +1,4 @@ -// Copyright 2020 The Prometheus Authors +// Copyright The Prometheus 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 @@ -12,8 +12,6 @@ // limitations under the License. //go:build linux && (ppc64 || ppc64le) -// +build linux -// +build ppc64 ppc64le package procfs diff --git a/vendor/github.com/prometheus/procfs/cpuinfo_riscvx.go b/vendor/github.com/prometheus/procfs/cpuinfo_riscvx.go index 1c9b7313b..72598230c 100644 --- a/vendor/github.com/prometheus/procfs/cpuinfo_riscvx.go +++ b/vendor/github.com/prometheus/procfs/cpuinfo_riscvx.go @@ -1,4 +1,4 @@ -// Copyright 2020 The Prometheus Authors +// Copyright The Prometheus 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 @@ -12,8 +12,6 @@ // limitations under the License. //go:build linux && (riscv || riscv64) -// +build linux -// +build riscv riscv64 package procfs diff --git a/vendor/github.com/prometheus/procfs/cpuinfo_s390x.go b/vendor/github.com/prometheus/procfs/cpuinfo_s390x.go index fa3686bc0..50a8239cb 100644 --- a/vendor/github.com/prometheus/procfs/cpuinfo_s390x.go +++ b/vendor/github.com/prometheus/procfs/cpuinfo_s390x.go @@ -1,4 +1,4 @@ -// Copyright 2020 The Prometheus Authors +// Copyright The Prometheus 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 @@ -12,7 +12,6 @@ // limitations under the License. //go:build linux -// +build linux package procfs diff --git a/vendor/github.com/prometheus/procfs/cpuinfo_x86.go b/vendor/github.com/prometheus/procfs/cpuinfo_x86.go index a0ef55562..00edb30a5 100644 --- a/vendor/github.com/prometheus/procfs/cpuinfo_x86.go +++ b/vendor/github.com/prometheus/procfs/cpuinfo_x86.go @@ -1,4 +1,4 @@ -// Copyright 2020 The Prometheus Authors +// Copyright The Prometheus 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 @@ -12,8 +12,6 @@ // limitations under the License. //go:build linux && (386 || amd64) -// +build linux -// +build 386 amd64 package procfs diff --git a/vendor/github.com/prometheus/procfs/crypto.go b/vendor/github.com/prometheus/procfs/crypto.go index 5f2a37a78..d93b712e0 100644 --- a/vendor/github.com/prometheus/procfs/crypto.go +++ b/vendor/github.com/prometheus/procfs/crypto.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Prometheus Authors +// Copyright The Prometheus 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 @@ -48,11 +48,13 @@ type Crypto struct { Walksize *uint64 } +var cryptoFile = "crypto" + // Crypto parses an crypto-file (/proc/crypto) and returns a slice of // structs containing the relevant info. More information available here: // https://kernel.readthedocs.io/en/sphinx-samples/crypto-API.html func (fs FS) Crypto() ([]Crypto, error) { - path := fs.proc.Path("crypto") + path := fs.proc.Path(cryptoFile) b, err := util.ReadFileNoStat(path) if err != nil { return nil, fmt.Errorf("%w: Cannot read file %v: %w", ErrFileRead, b, err) @@ -82,6 +84,10 @@ func parseCrypto(r io.Reader) ([]Crypto, error) { continue } + if len(out) == 0 { + return nil, fmt.Errorf("%w: parsed invalid line before name parsed: %q", ErrFileParse, text) + } + kv := strings.Split(text, ":") if len(kv) != 2 { return nil, fmt.Errorf("%w: Cannot parse line: %q", ErrFileParse, text) diff --git a/vendor/github.com/prometheus/procfs/doc.go b/vendor/github.com/prometheus/procfs/doc.go index f9d961e44..26bfea071 100644 --- a/vendor/github.com/prometheus/procfs/doc.go +++ b/vendor/github.com/prometheus/procfs/doc.go @@ -1,4 +1,4 @@ -// Copyright 2014 Prometheus Team +// Copyright The Prometheus 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 diff --git a/vendor/github.com/prometheus/procfs/fs.go b/vendor/github.com/prometheus/procfs/fs.go index 9bdaccc7c..8f27912a1 100644 --- a/vendor/github.com/prometheus/procfs/fs.go +++ b/vendor/github.com/prometheus/procfs/fs.go @@ -1,4 +1,4 @@ -// Copyright 2018 The Prometheus Authors +// Copyright The Prometheus 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 diff --git a/vendor/github.com/prometheus/procfs/fs_statfs_notype.go b/vendor/github.com/prometheus/procfs/fs_statfs_notype.go index 1b5bdbdf8..0bef25bdd 100644 --- a/vendor/github.com/prometheus/procfs/fs_statfs_notype.go +++ b/vendor/github.com/prometheus/procfs/fs_statfs_notype.go @@ -1,4 +1,4 @@ -// Copyright 2018 The Prometheus Authors +// Copyright The Prometheus 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 @@ -12,7 +12,6 @@ // limitations under the License. //go:build !freebsd && !linux -// +build !freebsd,!linux package procfs diff --git a/vendor/github.com/prometheus/procfs/fs_statfs_type.go b/vendor/github.com/prometheus/procfs/fs_statfs_type.go index 80df79c31..d18333039 100644 --- a/vendor/github.com/prometheus/procfs/fs_statfs_type.go +++ b/vendor/github.com/prometheus/procfs/fs_statfs_type.go @@ -1,4 +1,4 @@ -// Copyright 2018 The Prometheus Authors +// Copyright The Prometheus 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 @@ -12,7 +12,6 @@ // limitations under the License. //go:build freebsd || linux -// +build freebsd linux package procfs diff --git a/vendor/github.com/prometheus/procfs/fscache.go b/vendor/github.com/prometheus/procfs/fscache.go index 7db863307..9dde85707 100644 --- a/vendor/github.com/prometheus/procfs/fscache.go +++ b/vendor/github.com/prometheus/procfs/fscache.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Prometheus Authors +// Copyright The Prometheus 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 @@ -388,20 +388,21 @@ func parseFscacheinfo(r io.Reader) (*Fscacheinfo, error) { } } case "CacheOp:": - if strings.Split(fields[1], "=")[0] == "alo" { + switch strings.Split(fields[1], "=")[0] { + case "alo": err := setFSCacheFields(fields[1:], &m.CacheopAllocationsinProgress, &m.CacheopLookupObjectInProgress, &m.CacheopLookupCompleteInPorgress, &m.CacheopGrabObjectInProgress) if err != nil { return &m, err } - } else if strings.Split(fields[1], "=")[0] == "inv" { + case "inv": err := setFSCacheFields(fields[1:], &m.CacheopInvalidations, &m.CacheopUpdateObjectInProgress, &m.CacheopDropObjectInProgress, &m.CacheopPutObjectInProgress, &m.CacheopAttributeChangeInProgress, &m.CacheopSyncCacheInProgress) if err != nil { return &m, err } - } else { + default: err := setFSCacheFields(fields[1:], &m.CacheopReadOrAllocPageInProgress, &m.CacheopReadOrAllocPagesInProgress, &m.CacheopAllocatePageInProgress, &m.CacheopAllocatePagesInProgress, &m.CacheopWritePagesInProgress, &m.CacheopUncachePagesInProgress, &m.CacheopDissociatePagesInProgress) diff --git a/vendor/github.com/prometheus/procfs/internal/fs/fs.go b/vendor/github.com/prometheus/procfs/internal/fs/fs.go index 3a43e8391..e7ccad66b 100644 --- a/vendor/github.com/prometheus/procfs/internal/fs/fs.go +++ b/vendor/github.com/prometheus/procfs/internal/fs/fs.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Prometheus Authors +// Copyright The Prometheus 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 diff --git a/vendor/github.com/prometheus/procfs/internal/util/parse.go b/vendor/github.com/prometheus/procfs/internal/util/parse.go index 5a7d2df06..30c587201 100644 --- a/vendor/github.com/prometheus/procfs/internal/util/parse.go +++ b/vendor/github.com/prometheus/procfs/internal/util/parse.go @@ -1,4 +1,4 @@ -// Copyright 2018 The Prometheus Authors +// Copyright The Prometheus 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 diff --git a/vendor/github.com/prometheus/procfs/internal/util/readfile.go b/vendor/github.com/prometheus/procfs/internal/util/readfile.go index 71b7a70eb..0e41f71af 100644 --- a/vendor/github.com/prometheus/procfs/internal/util/readfile.go +++ b/vendor/github.com/prometheus/procfs/internal/util/readfile.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Prometheus Authors +// Copyright The Prometheus 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 diff --git a/vendor/github.com/prometheus/procfs/internal/util/sysreadfile.go b/vendor/github.com/prometheus/procfs/internal/util/sysreadfile.go index d5404a6d7..f6a4a4de6 100644 --- a/vendor/github.com/prometheus/procfs/internal/util/sysreadfile.go +++ b/vendor/github.com/prometheus/procfs/internal/util/sysreadfile.go @@ -1,4 +1,4 @@ -// Copyright 2018 The Prometheus Authors +// Copyright The Prometheus 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 @@ -12,8 +12,6 @@ // limitations under the License. //go:build (linux || darwin) && !appengine -// +build linux darwin -// +build !appengine package util diff --git a/vendor/github.com/prometheus/procfs/internal/util/sysreadfile_compat.go b/vendor/github.com/prometheus/procfs/internal/util/sysreadfile_compat.go index 1d86f5e63..c80e082cb 100644 --- a/vendor/github.com/prometheus/procfs/internal/util/sysreadfile_compat.go +++ b/vendor/github.com/prometheus/procfs/internal/util/sysreadfile_compat.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Prometheus Authors +// Copyright The Prometheus 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 @@ -12,7 +12,6 @@ // limitations under the License. //go:build (linux && appengine) || (!linux && !darwin) -// +build linux,appengine !linux,!darwin package util diff --git a/vendor/github.com/prometheus/procfs/internal/util/valueparser.go b/vendor/github.com/prometheus/procfs/internal/util/valueparser.go index fe2355d3c..e0ed671ea 100644 --- a/vendor/github.com/prometheus/procfs/internal/util/valueparser.go +++ b/vendor/github.com/prometheus/procfs/internal/util/valueparser.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Prometheus Authors +// Copyright The Prometheus 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 diff --git a/vendor/github.com/prometheus/procfs/ipvs.go b/vendor/github.com/prometheus/procfs/ipvs.go index bc3a20c93..5374da9fa 100644 --- a/vendor/github.com/prometheus/procfs/ipvs.go +++ b/vendor/github.com/prometheus/procfs/ipvs.go @@ -1,4 +1,4 @@ -// Copyright 2018 The Prometheus Authors +// Copyright The Prometheus 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 diff --git a/vendor/github.com/prometheus/procfs/kernel_hung.go b/vendor/github.com/prometheus/procfs/kernel_hung.go new file mode 100644 index 000000000..0c7a69f99 --- /dev/null +++ b/vendor/github.com/prometheus/procfs/kernel_hung.go @@ -0,0 +1,44 @@ +// Copyright The Prometheus 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. + +//go:build !windows + +package procfs + +import ( + "os" + "strconv" + "strings" +) + +// KernelHung contains information about to the kernel's hung_task_detect_count number. +type KernelHung struct { + // Indicates the total number of tasks that have been detected as hung since the system boot. + // This file shows up if `CONFIG_DETECT_HUNG_TASK` is enabled. + HungTaskDetectCount *uint64 +} + +// KernelHung returns values from /proc/sys/kernel/hung_task_detect_count. +func (fs FS) KernelHung() (KernelHung, error) { + data, err := os.ReadFile(fs.proc.Path("sys", "kernel", "hung_task_detect_count")) + if err != nil { + return KernelHung{}, err + } + val, err := strconv.ParseUint(strings.TrimSpace(string(data)), 10, 64) + if err != nil { + return KernelHung{}, err + } + return KernelHung{ + HungTaskDetectCount: &val, + }, nil +} diff --git a/vendor/github.com/prometheus/procfs/kernel_random.go b/vendor/github.com/prometheus/procfs/kernel_random.go index db88566bd..e7c5b8cf2 100644 --- a/vendor/github.com/prometheus/procfs/kernel_random.go +++ b/vendor/github.com/prometheus/procfs/kernel_random.go @@ -1,4 +1,4 @@ -// Copyright 2020 The Prometheus Authors +// Copyright The Prometheus 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 @@ -12,7 +12,6 @@ // limitations under the License. //go:build !windows -// +build !windows package procfs diff --git a/vendor/github.com/prometheus/procfs/loadavg.go b/vendor/github.com/prometheus/procfs/loadavg.go index 332e76c17..c8c78a65e 100644 --- a/vendor/github.com/prometheus/procfs/loadavg.go +++ b/vendor/github.com/prometheus/procfs/loadavg.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Prometheus Authors +// Copyright The Prometheus 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 diff --git a/vendor/github.com/prometheus/procfs/mdstat.go b/vendor/github.com/prometheus/procfs/mdstat.go index 67a9d2b44..d66eeda82 100644 --- a/vendor/github.com/prometheus/procfs/mdstat.go +++ b/vendor/github.com/prometheus/procfs/mdstat.go @@ -1,4 +1,4 @@ -// Copyright 2018 The Prometheus Authors +// Copyright The Prometheus 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 @@ -27,13 +27,34 @@ var ( recoveryLinePctRE = regexp.MustCompile(`= (.+)%`) recoveryLineFinishRE = regexp.MustCompile(`finish=(.+)min`) recoveryLineSpeedRE = regexp.MustCompile(`speed=(.+)[A-Z]`) - componentDeviceRE = regexp.MustCompile(`(.*)\[\d+\]`) + componentDeviceRE = regexp.MustCompile(`(.*)\[(\d+)\](\([SF]+\))?`) + personalitiesPrefix = "Personalities : " ) +type MDStatComponent struct { + // Name of the component device. + Name string + // DescriptorIndex number of component device, e.g. the order in the superblock. + DescriptorIndex int32 + // Flags per Linux drivers/md/md.[ch] as of v6.12-rc1 + // Subset that are exposed in mdstat + WriteMostly bool + Journal bool + Faulty bool // "Faulty" is what kernel source uses for "(F)" + Spare bool + Replacement bool + // Some additional flags that are NOT exposed in procfs today; they may + // be available via sysfs. + // In_sync, Bitmap_sync, Blocked, WriteErrorSeen, FaultRecorded, + // BlockedBadBlocks, WantReplacement, Candidate, ... +} + // MDStat holds info parsed from /proc/mdstat. type MDStat struct { // Name of the device. Name string + // raid type of the device. + Type string // activity-state of the device. ActivityState string // Number of active disks. @@ -58,8 +79,8 @@ type MDStat struct { BlocksSyncedFinishTime float64 // current sync speed (in Kilobytes/sec) BlocksSyncedSpeed float64 - // Name of md component devices - Devices []string + // component devices + Devices []MDStatComponent } // MDStat parses an mdstat-file (/proc/mdstat) and returns a slice of @@ -80,28 +101,52 @@ func (fs FS) MDStat() ([]MDStat, error) { // parseMDStat parses data from mdstat file (/proc/mdstat) and returns a slice of // structs containing the relevant info. func parseMDStat(mdStatData []byte) ([]MDStat, error) { + // TODO: + // - parse global hotspares from the "unused devices" line. mdStats := []MDStat{} lines := strings.Split(string(mdStatData), "\n") + knownRaidTypes := make(map[string]bool) for i, line := range lines { if strings.TrimSpace(line) == "" || line[0] == ' ' || - strings.HasPrefix(line, "Personalities") || strings.HasPrefix(line, "unused") { continue } + // Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10] + if len(knownRaidTypes) == 0 && strings.HasPrefix(line, personalitiesPrefix) { + personalities := strings.Fields(line[len(personalitiesPrefix):]) + for _, word := range personalities { + word := word[1 : len(word)-1] + knownRaidTypes[word] = true + } + continue + } deviceFields := strings.Fields(line) if len(deviceFields) < 3 { return nil, fmt.Errorf("%w: Expected 3+ lines, got %q", ErrFileParse, line) } mdName := deviceFields[0] // mdx - state := deviceFields[2] // active or inactive + state := deviceFields[2] // active, inactive, broken + + mdType := "unknown" // raid1, raid5, etc. + var deviceStartIndex int + if len(deviceFields) > 3 { // mdType may be in the 3rd or 4th field + if isRaidType(deviceFields[3], knownRaidTypes) { + mdType = deviceFields[3] + deviceStartIndex = 4 + } else if len(deviceFields) > 4 && isRaidType(deviceFields[4], knownRaidTypes) { + // if the 3rd field is (...), the 4th field is the mdType + mdType = deviceFields[4] + deviceStartIndex = 5 + } + } if len(lines) <= i+3 { return nil, fmt.Errorf("%w: Too few lines for md device: %q", ErrFileParse, mdName) } - // Failed disks have the suffix (F) & Spare disks have the suffix (S). + // Failed (Faulty) disks have the suffix (F) & Spare disks have the suffix (S). fail := int64(strings.Count(line, "(F)")) spare := int64(strings.Count(line, "(S)")) active, total, down, size, err := evalStatusLine(lines[i], lines[i+1]) @@ -123,16 +168,20 @@ func parseMDStat(mdStatData []byte) ([]MDStat, error) { finish := float64(0) pct := float64(0) recovering := strings.Contains(lines[syncLineIdx], "recovery") + reshaping := strings.Contains(lines[syncLineIdx], "reshape") resyncing := strings.Contains(lines[syncLineIdx], "resync") checking := strings.Contains(lines[syncLineIdx], "check") // Append recovery and resyncing state info. - if recovering || resyncing || checking { - if recovering { + if recovering || resyncing || checking || reshaping { + switch { + case recovering: state = "recovering" - } else if checking { + case reshaping: + state = "reshaping" + case checking: state = "checking" - } else { + default: state = "resyncing" } @@ -148,8 +197,14 @@ func parseMDStat(mdStatData []byte) ([]MDStat, error) { } } + devices, err := evalComponentDevices(deviceFields[deviceStartIndex:]) + if err != nil { + return nil, fmt.Errorf("error parsing components in md device %q: %w", mdName, err) + } + mdStats = append(mdStats, MDStat{ Name: mdName, + Type: mdType, ActivityState: state, DisksActive: active, DisksFailed: fail, @@ -162,14 +217,24 @@ func parseMDStat(mdStatData []byte) ([]MDStat, error) { BlocksSyncedPct: pct, BlocksSyncedFinishTime: finish, BlocksSyncedSpeed: speed, - Devices: evalComponentDevices(deviceFields), + Devices: devices, }) } return mdStats, nil } +// check if a string's format is like the mdType +// Rule 1: mdType should not be like (...) +// Rule 2: mdType should not be like sda[0] +// . +func isRaidType(mdType string, knownRaidTypes map[string]bool) bool { + _, ok := knownRaidTypes[mdType] + return !strings.ContainsAny(mdType, "([") && ok +} + func evalStatusLine(deviceLine, statusLine string) (active, total, down, size int64, err error) { + // e.g. 523968 blocks super 1.2 [4/4] [UUUU] statusFields := strings.Fields(statusLine) if len(statusFields) < 1 { return 0, 0, 0, 0, fmt.Errorf("%w: Unexpected statusline %q: %w", ErrFileParse, statusLine, err) @@ -260,17 +325,29 @@ func evalRecoveryLine(recoveryLine string) (blocksSynced int64, blocksToBeSynced return blocksSynced, blocksToBeSynced, pct, finish, speed, nil } -func evalComponentDevices(deviceFields []string) []string { - mdComponentDevices := make([]string, 0) - if len(deviceFields) > 3 { - for _, field := range deviceFields[4:] { - match := componentDeviceRE.FindStringSubmatch(field) - if match == nil { - continue - } - mdComponentDevices = append(mdComponentDevices, match[1]) +func evalComponentDevices(deviceFields []string) ([]MDStatComponent, error) { + mdComponentDevices := make([]MDStatComponent, 0) + for _, field := range deviceFields { + match := componentDeviceRE.FindStringSubmatch(field) + if match == nil { + continue + } + descriptorIndex, err := strconv.ParseInt(match[2], 10, 32) + if err != nil { + return mdComponentDevices, fmt.Errorf("error parsing int from device %q: %w", match[2], err) } + mdComponentDevices = append(mdComponentDevices, MDStatComponent{ + Name: match[1], + DescriptorIndex: int32(descriptorIndex), + // match may contain one or more of these + // https://github.com/torvalds/linux/blob/7ec462100ef9142344ddbf86f2c3008b97acddbe/drivers/md/md.c#L8376-L8392 + Faulty: strings.Contains(match[3], "(F)"), + Spare: strings.Contains(match[3], "(S)"), + Journal: strings.Contains(match[3], "(J)"), + Replacement: strings.Contains(match[3], "(R)"), + WriteMostly: strings.Contains(match[3], "(W)"), + }) } - return mdComponentDevices + return mdComponentDevices, nil } diff --git a/vendor/github.com/prometheus/procfs/meminfo.go b/vendor/github.com/prometheus/procfs/meminfo.go index 4b2c4050a..342038318 100644 --- a/vendor/github.com/prometheus/procfs/meminfo.go +++ b/vendor/github.com/prometheus/procfs/meminfo.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Prometheus Authors +// Copyright The Prometheus 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 @@ -66,6 +66,10 @@ type Meminfo struct { // Memory which has been evicted from RAM, and is temporarily // on the disk SwapFree *uint64 + // Memory consumed by the zswap backend (compressed size) + Zswap *uint64 + // Amount of anonymous memory stored in zswap (original size) + Zswapped *uint64 // Memory which is waiting to get written back to the disk Dirty *uint64 // Memory which is actively being written back to the disk @@ -85,6 +89,8 @@ type Meminfo struct { // amount of memory dedicated to the lowest level of page // tables. PageTables *uint64 + // secondary page tables. + SecPageTables *uint64 // NFS pages sent to the server, but not yet committed to // stable storage NFSUnstable *uint64 @@ -129,15 +135,18 @@ type Meminfo struct { Percpu *uint64 HardwareCorrupted *uint64 AnonHugePages *uint64 + FileHugePages *uint64 ShmemHugePages *uint64 ShmemPmdMapped *uint64 CmaTotal *uint64 CmaFree *uint64 + Unaccepted *uint64 HugePagesTotal *uint64 HugePagesFree *uint64 HugePagesRsvd *uint64 HugePagesSurp *uint64 Hugepagesize *uint64 + Hugetlb *uint64 DirectMap4k *uint64 DirectMap2M *uint64 DirectMap1G *uint64 @@ -161,6 +170,8 @@ type Meminfo struct { MlockedBytes *uint64 SwapTotalBytes *uint64 SwapFreeBytes *uint64 + ZswapBytes *uint64 + ZswappedBytes *uint64 DirtyBytes *uint64 WritebackBytes *uint64 AnonPagesBytes *uint64 @@ -171,6 +182,7 @@ type Meminfo struct { SUnreclaimBytes *uint64 KernelStackBytes *uint64 PageTablesBytes *uint64 + SecPageTablesBytes *uint64 NFSUnstableBytes *uint64 BounceBytes *uint64 WritebackTmpBytes *uint64 @@ -182,11 +194,14 @@ type Meminfo struct { PercpuBytes *uint64 HardwareCorruptedBytes *uint64 AnonHugePagesBytes *uint64 + FileHugePagesBytes *uint64 ShmemHugePagesBytes *uint64 ShmemPmdMappedBytes *uint64 CmaTotalBytes *uint64 CmaFreeBytes *uint64 + UnacceptedBytes *uint64 HugepagesizeBytes *uint64 + HugetlbBytes *uint64 DirectMap4kBytes *uint64 DirectMap2MBytes *uint64 DirectMap1GBytes *uint64 @@ -287,6 +302,12 @@ func parseMemInfo(r io.Reader) (*Meminfo, error) { case "SwapFree:": m.SwapFree = &val m.SwapFreeBytes = &valBytes + case "Zswap:": + m.Zswap = &val + m.ZswapBytes = &valBytes + case "Zswapped:": + m.Zswapped = &val + m.ZswappedBytes = &valBytes case "Dirty:": m.Dirty = &val m.DirtyBytes = &valBytes @@ -317,6 +338,9 @@ func parseMemInfo(r io.Reader) (*Meminfo, error) { case "PageTables:": m.PageTables = &val m.PageTablesBytes = &valBytes + case "SecPageTables:": + m.SecPageTables = &val + m.SecPageTablesBytes = &valBytes case "NFS_Unstable:": m.NFSUnstable = &val m.NFSUnstableBytes = &valBytes @@ -350,6 +374,9 @@ func parseMemInfo(r io.Reader) (*Meminfo, error) { case "AnonHugePages:": m.AnonHugePages = &val m.AnonHugePagesBytes = &valBytes + case "FileHugePages:": + m.FileHugePages = &val + m.FileHugePagesBytes = &valBytes case "ShmemHugePages:": m.ShmemHugePages = &val m.ShmemHugePagesBytes = &valBytes @@ -362,6 +389,9 @@ func parseMemInfo(r io.Reader) (*Meminfo, error) { case "CmaFree:": m.CmaFree = &val m.CmaFreeBytes = &valBytes + case "Unaccepted:": + m.Unaccepted = &val + m.UnacceptedBytes = &valBytes case "HugePages_Total:": m.HugePagesTotal = &val case "HugePages_Free:": @@ -373,6 +403,9 @@ func parseMemInfo(r io.Reader) (*Meminfo, error) { case "Hugepagesize:": m.Hugepagesize = &val m.HugepagesizeBytes = &valBytes + case "Hugetlb:": + m.Hugetlb = &val + m.HugetlbBytes = &valBytes case "DirectMap4k:": m.DirectMap4k = &val m.DirectMap4kBytes = &valBytes diff --git a/vendor/github.com/prometheus/procfs/mountinfo.go b/vendor/github.com/prometheus/procfs/mountinfo.go index a704c5e73..8594ae7f1 100644 --- a/vendor/github.com/prometheus/procfs/mountinfo.go +++ b/vendor/github.com/prometheus/procfs/mountinfo.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Prometheus Authors +// Copyright The Prometheus 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 @@ -17,10 +17,10 @@ import ( "bufio" "bytes" "fmt" + "io" + "os" "strconv" "strings" - - "github.com/prometheus/procfs/internal/util" ) // A MountInfo is a type that describes the details, options @@ -147,8 +147,7 @@ func mountOptionsParseOptionalFields(o []string) (map[string]string, error) { // mountOptionsParser parses the mount options, superblock options. func mountOptionsParser(mountOptions string) map[string]string { opts := make(map[string]string) - options := strings.Split(mountOptions, ",") - for _, opt := range options { + for opt := range strings.SplitSeq(mountOptions, ",") { splitOption := strings.Split(opt, "=") if len(splitOption) < 2 { key := splitOption[0] @@ -161,9 +160,19 @@ func mountOptionsParser(mountOptions string) map[string]string { return opts } +// readMountInfo reads a full mountinfo file (no 1 MiB cap, unlike util.ReadFileNoStat). +func readMountInfo(path string) ([]byte, error) { + f, err := os.Open(path) + if err != nil { + return nil, err + } + defer f.Close() + return io.ReadAll(f) +} + // GetMounts retrieves mountinfo information from `/proc/self/mountinfo`. func GetMounts() ([]*MountInfo, error) { - data, err := util.ReadFileNoStat("/proc/self/mountinfo") + data, err := readMountInfo("/proc/self/mountinfo") if err != nil { return nil, err } @@ -172,7 +181,25 @@ func GetMounts() ([]*MountInfo, error) { // GetProcMounts retrieves mountinfo information from a processes' `/proc//mountinfo`. func GetProcMounts(pid int) ([]*MountInfo, error) { - data, err := util.ReadFileNoStat(fmt.Sprintf("/proc/%d/mountinfo", pid)) + data, err := readMountInfo(fmt.Sprintf("/proc/%d/mountinfo", pid)) + if err != nil { + return nil, err + } + return parseMountInfo(data) +} + +// GetMounts retrieves mountinfo information from `/proc/self/mountinfo`. +func (fs FS) GetMounts() ([]*MountInfo, error) { + data, err := readMountInfo(fs.proc.Path("self/mountinfo")) + if err != nil { + return nil, err + } + return parseMountInfo(data) +} + +// GetProcMounts retrieves mountinfo information from a processes' `/proc//mountinfo`. +func (fs FS) GetProcMounts(pid int) ([]*MountInfo, error) { + data, err := readMountInfo(fs.proc.Path(fmt.Sprintf("%d/mountinfo", pid))) if err != nil { return nil, err } diff --git a/vendor/github.com/prometheus/procfs/mountstats.go b/vendor/github.com/prometheus/procfs/mountstats.go index 50caa7327..e503cb3a6 100644 --- a/vendor/github.com/prometheus/procfs/mountstats.go +++ b/vendor/github.com/prometheus/procfs/mountstats.go @@ -1,4 +1,4 @@ -// Copyright 2018 The Prometheus Authors +// Copyright The Prometheus 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 @@ -383,7 +383,7 @@ func parseMountStatsNFS(s *bufio.Scanner, statVersion string) (*MountStatsNFS, e if stats.Opts == nil { stats.Opts = map[string]string{} } - for _, opt := range strings.Split(ss[1], ",") { + for opt := range strings.SplitSeq(ss[1], ",") { split := strings.Split(opt, "=") if len(split) == 2 { stats.Opts[split[0]] = split[1] diff --git a/vendor/github.com/prometheus/procfs/net_conntrackstat.go b/vendor/github.com/prometheus/procfs/net_conntrackstat.go index 316df5fbb..e9ca35707 100644 --- a/vendor/github.com/prometheus/procfs/net_conntrackstat.go +++ b/vendor/github.com/prometheus/procfs/net_conntrackstat.go @@ -1,4 +1,4 @@ -// Copyright 2020 The Prometheus Authors +// Copyright The Prometheus 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 diff --git a/vendor/github.com/prometheus/procfs/net_dev.go b/vendor/github.com/prometheus/procfs/net_dev.go index e66208aa0..7b3e1d61c 100644 --- a/vendor/github.com/prometheus/procfs/net_dev.go +++ b/vendor/github.com/prometheus/procfs/net_dev.go @@ -1,4 +1,4 @@ -// Copyright 2018 The Prometheus Authors +// Copyright The Prometheus 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 diff --git a/vendor/github.com/prometheus/procfs/net_dev_snmp6.go b/vendor/github.com/prometheus/procfs/net_dev_snmp6.go index f50b38e35..2a0f60f29 100644 --- a/vendor/github.com/prometheus/procfs/net_dev_snmp6.go +++ b/vendor/github.com/prometheus/procfs/net_dev_snmp6.go @@ -1,4 +1,4 @@ -// Copyright 2018 The Prometheus Authors +// Copyright The Prometheus 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 @@ -18,6 +18,7 @@ import ( "errors" "io" "os" + "path/filepath" "strconv" "strings" ) @@ -56,7 +57,9 @@ func newNetDevSNMP6(dir string) (NetDevSNMP6, error) { } for _, iFaceFile := range ifaceFiles { - f, err := os.Open(dir + "/" + iFaceFile.Name()) + filePath := filepath.Join(dir, iFaceFile.Name()) + + f, err := os.Open(filePath) if err != nil { return netDevSNMP6, err } diff --git a/vendor/github.com/prometheus/procfs/net_ip_socket.go b/vendor/github.com/prometheus/procfs/net_ip_socket.go index 19e3378f7..9291f8cd4 100644 --- a/vendor/github.com/prometheus/procfs/net_ip_socket.go +++ b/vendor/github.com/prometheus/procfs/net_ip_socket.go @@ -1,4 +1,4 @@ -// Copyright 2020 The Prometheus Authors +// Copyright The Prometheus 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 diff --git a/vendor/github.com/prometheus/procfs/net_protocols.go b/vendor/github.com/prometheus/procfs/net_protocols.go index 8d4b1ac05..eaa996cbc 100644 --- a/vendor/github.com/prometheus/procfs/net_protocols.go +++ b/vendor/github.com/prometheus/procfs/net_protocols.go @@ -1,4 +1,4 @@ -// Copyright 2020 The Prometheus Authors +// Copyright The Prometheus 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 @@ -169,7 +169,7 @@ func (pc *NetProtocolCapabilities) parseCapabilities(capabilities []string) erro &pc.EnterMemoryPressure, } - for i := 0; i < len(capabilities); i++ { + for i := range capabilities { switch capabilities[i] { case "y": *capabilityFields[i] = true diff --git a/vendor/github.com/prometheus/procfs/net_route.go b/vendor/github.com/prometheus/procfs/net_route.go index deb7029fe..fa3812d9d 100644 --- a/vendor/github.com/prometheus/procfs/net_route.go +++ b/vendor/github.com/prometheus/procfs/net_route.go @@ -1,4 +1,4 @@ -// Copyright 2023 The Prometheus Authors +// Copyright The Prometheus 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 diff --git a/vendor/github.com/prometheus/procfs/net_sockstat.go b/vendor/github.com/prometheus/procfs/net_sockstat.go index fae62b13d..8b221ebff 100644 --- a/vendor/github.com/prometheus/procfs/net_sockstat.go +++ b/vendor/github.com/prometheus/procfs/net_sockstat.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Prometheus Authors +// Copyright The Prometheus 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 @@ -139,9 +139,6 @@ func parseSockstatKVs(kvs []string) (map[string]int, error) { func parseSockstatProtocol(kvs map[string]int) NetSockstatProtocol { var nsp NetSockstatProtocol for k, v := range kvs { - // Capture the range variable to ensure we get unique pointers for - // each of the optional fields. - v := v switch k { case "inuse": nsp.InUse = v diff --git a/vendor/github.com/prometheus/procfs/net_softnet.go b/vendor/github.com/prometheus/procfs/net_softnet.go index 71c8059f4..4a2dfa18f 100644 --- a/vendor/github.com/prometheus/procfs/net_softnet.go +++ b/vendor/github.com/prometheus/procfs/net_softnet.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Prometheus Authors +// Copyright The Prometheus 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 diff --git a/vendor/github.com/prometheus/procfs/net_tcp.go b/vendor/github.com/prometheus/procfs/net_tcp.go index 0396d7201..2c7f9bc7c 100644 --- a/vendor/github.com/prometheus/procfs/net_tcp.go +++ b/vendor/github.com/prometheus/procfs/net_tcp.go @@ -1,4 +1,4 @@ -// Copyright 2020 The Prometheus Authors +// Copyright The Prometheus 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 @@ -25,6 +25,7 @@ type ( // NetTCP returns the IPv4 kernel/networking statistics for TCP datagrams // read from /proc/net/tcp. +// // Deprecated: Use github.com/mdlayher/netlink#Conn (with syscall.AF_INET) instead. func (fs FS) NetTCP() (NetTCP, error) { return newNetTCP(fs.proc.Path("net/tcp")) @@ -32,6 +33,7 @@ func (fs FS) NetTCP() (NetTCP, error) { // NetTCP6 returns the IPv6 kernel/networking statistics for TCP datagrams // read from /proc/net/tcp6. +// // Deprecated: Use github.com/mdlayher/netlink#Conn (with syscall.AF_INET6) instead. func (fs FS) NetTCP6() (NetTCP, error) { return newNetTCP(fs.proc.Path("net/tcp6")) @@ -39,6 +41,7 @@ func (fs FS) NetTCP6() (NetTCP, error) { // NetTCPSummary returns already computed statistics like the total queue lengths // for TCP datagrams read from /proc/net/tcp. +// // Deprecated: Use github.com/mdlayher/netlink#Conn (with syscall.AF_INET) instead. func (fs FS) NetTCPSummary() (*NetTCPSummary, error) { return newNetTCPSummary(fs.proc.Path("net/tcp")) @@ -46,6 +49,7 @@ func (fs FS) NetTCPSummary() (*NetTCPSummary, error) { // NetTCP6Summary returns already computed statistics like the total queue lengths // for TCP datagrams read from /proc/net/tcp6. +// // Deprecated: Use github.com/mdlayher/netlink#Conn (with syscall.AF_INET6) instead. func (fs FS) NetTCP6Summary() (*NetTCPSummary, error) { return newNetTCPSummary(fs.proc.Path("net/tcp6")) diff --git a/vendor/github.com/prometheus/procfs/net_tls_stat.go b/vendor/github.com/prometheus/procfs/net_tls_stat.go index 13994c178..b1b3f6a6a 100644 --- a/vendor/github.com/prometheus/procfs/net_tls_stat.go +++ b/vendor/github.com/prometheus/procfs/net_tls_stat.go @@ -1,4 +1,4 @@ -// Copyright 2023 Prometheus Team +// Copyright The Prometheus 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 diff --git a/vendor/github.com/prometheus/procfs/net_udp.go b/vendor/github.com/prometheus/procfs/net_udp.go index 9ac3daf2d..8a3277910 100644 --- a/vendor/github.com/prometheus/procfs/net_udp.go +++ b/vendor/github.com/prometheus/procfs/net_udp.go @@ -1,4 +1,4 @@ -// Copyright 2020 The Prometheus Authors +// Copyright The Prometheus 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 diff --git a/vendor/github.com/prometheus/procfs/net_unix.go b/vendor/github.com/prometheus/procfs/net_unix.go index d7e0cacb4..e4d635923 100644 --- a/vendor/github.com/prometheus/procfs/net_unix.go +++ b/vendor/github.com/prometheus/procfs/net_unix.go @@ -1,4 +1,4 @@ -// Copyright 2018 The Prometheus Authors +// Copyright The Prometheus 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 diff --git a/vendor/github.com/prometheus/procfs/net_wireless.go b/vendor/github.com/prometheus/procfs/net_wireless.go index 7c597bc87..f74dd3bed 100644 --- a/vendor/github.com/prometheus/procfs/net_wireless.go +++ b/vendor/github.com/prometheus/procfs/net_wireless.go @@ -1,4 +1,4 @@ -// Copyright 2023 The Prometheus Authors +// Copyright The Prometheus 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 @@ -114,47 +114,47 @@ func parseWireless(r io.Reader) ([]*Wireless, error) { qlink, err := strconv.Atoi(strings.TrimSuffix(stats[1], ".")) if err != nil { - return nil, fmt.Errorf("%w: parse Quality:link as integer %q: %w", ErrFileParse, qlink, err) + return nil, fmt.Errorf("%w: parse Quality:link as integer %q: %w", ErrFileParse, stats[1], err) } qlevel, err := strconv.Atoi(strings.TrimSuffix(stats[2], ".")) if err != nil { - return nil, fmt.Errorf("%w: Quality:level as integer %q: %w", ErrFileParse, qlevel, err) + return nil, fmt.Errorf("%w: Quality:level as integer %q: %w", ErrFileParse, stats[2], err) } qnoise, err := strconv.Atoi(strings.TrimSuffix(stats[3], ".")) if err != nil { - return nil, fmt.Errorf("%w: Quality:noise as integer %q: %w", ErrFileParse, qnoise, err) + return nil, fmt.Errorf("%w: Quality:noise as integer %q: %w", ErrFileParse, stats[3], err) } dnwid, err := strconv.Atoi(stats[4]) if err != nil { - return nil, fmt.Errorf("%w: Discarded:nwid as integer %q: %w", ErrFileParse, dnwid, err) + return nil, fmt.Errorf("%w: Discarded:nwid as integer %q: %w", ErrFileParse, stats[4], err) } dcrypt, err := strconv.Atoi(stats[5]) if err != nil { - return nil, fmt.Errorf("%w: Discarded:crypt as integer %q: %w", ErrFileParse, dcrypt, err) + return nil, fmt.Errorf("%w: Discarded:crypt as integer %q: %w", ErrFileParse, stats[5], err) } dfrag, err := strconv.Atoi(stats[6]) if err != nil { - return nil, fmt.Errorf("%w: Discarded:frag as integer %q: %w", ErrFileParse, dfrag, err) + return nil, fmt.Errorf("%w: Discarded:frag as integer %q: %w", ErrFileParse, stats[6], err) } dretry, err := strconv.Atoi(stats[7]) if err != nil { - return nil, fmt.Errorf("%w: Discarded:retry as integer %q: %w", ErrFileParse, dretry, err) + return nil, fmt.Errorf("%w: Discarded:retry as integer %q: %w", ErrFileParse, stats[7], err) } dmisc, err := strconv.Atoi(stats[8]) if err != nil { - return nil, fmt.Errorf("%w: Discarded:misc as integer %q: %w", ErrFileParse, dmisc, err) + return nil, fmt.Errorf("%w: Discarded:misc as integer %q: %w", ErrFileParse, stats[8], err) } mbeacon, err := strconv.Atoi(stats[9]) if err != nil { - return nil, fmt.Errorf("%w: Missed:beacon as integer %q: %w", ErrFileParse, mbeacon, err) + return nil, fmt.Errorf("%w: Missed:beacon as integer %q: %w", ErrFileParse, stats[9], err) } w := &Wireless{ diff --git a/vendor/github.com/prometheus/procfs/net_xfrm.go b/vendor/github.com/prometheus/procfs/net_xfrm.go index 932ef2046..5a9f497d1 100644 --- a/vendor/github.com/prometheus/procfs/net_xfrm.go +++ b/vendor/github.com/prometheus/procfs/net_xfrm.go @@ -1,4 +1,4 @@ -// Copyright 2017 Prometheus Team +// Copyright The Prometheus 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 diff --git a/vendor/github.com/prometheus/procfs/netstat.go b/vendor/github.com/prometheus/procfs/netstat.go index 742dff453..dbdae4739 100644 --- a/vendor/github.com/prometheus/procfs/netstat.go +++ b/vendor/github.com/prometheus/procfs/netstat.go @@ -1,4 +1,4 @@ -// Copyright 2020 The Prometheus Authors +// Copyright The Prometheus 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 diff --git a/vendor/github.com/prometheus/procfs/nfnetlink_queue.go b/vendor/github.com/prometheus/procfs/nfnetlink_queue.go new file mode 100644 index 000000000..b0a73b11e --- /dev/null +++ b/vendor/github.com/prometheus/procfs/nfnetlink_queue.go @@ -0,0 +1,85 @@ +// Copyright The Prometheus 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. + +package procfs + +import ( + "bufio" + "bytes" + "fmt" + + "github.com/prometheus/procfs/internal/util" +) + +const nfNetLinkQueueFormat = "%d %d %d %d %d %d %d %d %d" + +// NFNetLinkQueue contains general information about netfilter queues found in /proc/net/netfilter/nfnetlink_queue. +type NFNetLinkQueue struct { + // id of the queue + QueueID uint + // pid of process handling the queue + PeerPID uint + // number of packets waiting for a decision + QueueTotal uint + // indicate how userspace receive packets + CopyMode uint + // size of copy + CopyRange uint + // number of items dropped by the kernel because too many packets were waiting a decision. + // It queue_total is superior to queue_max_len (1024 per default) the packets are dropped. + QueueDropped uint + // number of packets dropped by userspace (due to kernel send failure on the netlink socket) + QueueUserDropped uint + // sequence number of packets queued. It gives a correct approximation of the number of queued packets. + SequenceID uint + // internal value (number of entity using the queue) + Use uint +} + +// NFNetLinkQueue returns information about current state of netfilter queues. +func (fs FS) NFNetLinkQueue() ([]NFNetLinkQueue, error) { + data, err := util.ReadFileNoStat(fs.proc.Path("net/netfilter/nfnetlink_queue")) + if err != nil { + return nil, err + } + + queue := []NFNetLinkQueue{} + if len(data) == 0 { + return queue, nil + } + + scanner := bufio.NewScanner(bytes.NewReader(data)) + for scanner.Scan() { + line := scanner.Text() + nFNetLinkQueue, err := parseNFNetLinkQueueLine(line) + if err != nil { + return nil, err + } + queue = append(queue, *nFNetLinkQueue) + } + return queue, nil +} + +// parseNFNetLinkQueueLine parses each line of the /proc/net/netfilter/nfnetlink_queue file. +func parseNFNetLinkQueueLine(line string) (*NFNetLinkQueue, error) { + nFNetLinkQueue := NFNetLinkQueue{} + _, err := fmt.Sscanf( + line, nfNetLinkQueueFormat, + &nFNetLinkQueue.QueueID, &nFNetLinkQueue.PeerPID, &nFNetLinkQueue.QueueTotal, &nFNetLinkQueue.CopyMode, + &nFNetLinkQueue.CopyRange, &nFNetLinkQueue.QueueDropped, &nFNetLinkQueue.QueueUserDropped, &nFNetLinkQueue.SequenceID, &nFNetLinkQueue.Use, + ) + if err != nil { + return nil, err + } + return &nFNetLinkQueue, nil +} diff --git a/vendor/github.com/prometheus/procfs/proc.go b/vendor/github.com/prometheus/procfs/proc.go index 368187fa8..39c14aa55 100644 --- a/vendor/github.com/prometheus/procfs/proc.go +++ b/vendor/github.com/prometheus/procfs/proc.go @@ -1,4 +1,4 @@ -// Copyright 2018 The Prometheus Authors +// Copyright The Prometheus 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 @@ -49,7 +49,7 @@ func (p Procs) Less(i, j int) bool { return p[i].PID < p[j].PID } // Self returns a process for the current process read via /proc/self. func Self() (Proc, error) { fs, err := NewFS(DefaultMountPoint) - if err != nil || errors.Unwrap(err) == ErrMountPoint { + if err != nil || errors.Is(err, ErrMountPoint) { return Proc{}, err } return fs.Self() diff --git a/vendor/github.com/prometheus/procfs/proc_cgroup.go b/vendor/github.com/prometheus/procfs/proc_cgroup.go index 4a64347c0..7e8a12297 100644 --- a/vendor/github.com/prometheus/procfs/proc_cgroup.go +++ b/vendor/github.com/prometheus/procfs/proc_cgroup.go @@ -1,4 +1,4 @@ -// Copyright 2020 The Prometheus Authors +// Copyright The Prometheus 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 @@ -60,7 +60,7 @@ func parseCgroupString(cgroupStr string) (*Cgroup, error) { } cgroup.HierarchyID, err = strconv.Atoi(fields[0]) if err != nil { - return nil, fmt.Errorf("%w: hierarchy ID: %q", ErrFileParse, cgroup.HierarchyID) + return nil, fmt.Errorf("%w: hierarchy ID: %q", ErrFileParse, fields[0]) } if fields[1] != "" { ssNames := strings.Split(fields[1], ",") diff --git a/vendor/github.com/prometheus/procfs/proc_cgroups.go b/vendor/github.com/prometheus/procfs/proc_cgroups.go index 5dd493899..0b275c3b1 100644 --- a/vendor/github.com/prometheus/procfs/proc_cgroups.go +++ b/vendor/github.com/prometheus/procfs/proc_cgroups.go @@ -1,4 +1,4 @@ -// Copyright 2021 The Prometheus Authors +// Copyright The Prometheus 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 @@ -40,13 +40,13 @@ type CgroupSummary struct { // parseCgroupSummary parses each line of the /proc/cgroup file // Line format is `subsys_name hierarchy num_cgroups enabled`. -func parseCgroupSummaryString(CgroupSummaryStr string) (*CgroupSummary, error) { +func parseCgroupSummaryString(cgroupSummaryStr string) (*CgroupSummary, error) { var err error - fields := strings.Fields(CgroupSummaryStr) + fields := strings.Fields(cgroupSummaryStr) // require at least 4 fields if len(fields) < 4 { - return nil, fmt.Errorf("%w: 4+ fields required, found %d fields in cgroup info string: %s", ErrFileParse, len(fields), CgroupSummaryStr) + return nil, fmt.Errorf("%w: 4+ fields required, found %d fields in cgroup info string: %s", ErrFileParse, len(fields), cgroupSummaryStr) } CgroupSummary := &CgroupSummary{ diff --git a/vendor/github.com/prometheus/procfs/proc_environ.go b/vendor/github.com/prometheus/procfs/proc_environ.go index 57a89895d..5b941de04 100644 --- a/vendor/github.com/prometheus/procfs/proc_environ.go +++ b/vendor/github.com/prometheus/procfs/proc_environ.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Prometheus Authors +// Copyright The Prometheus 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 diff --git a/vendor/github.com/prometheus/procfs/proc_fdinfo.go b/vendor/github.com/prometheus/procfs/proc_fdinfo.go index fa761b352..fa57761db 100644 --- a/vendor/github.com/prometheus/procfs/proc_fdinfo.go +++ b/vendor/github.com/prometheus/procfs/proc_fdinfo.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Prometheus Authors +// Copyright The Prometheus 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 @@ -60,15 +60,16 @@ func (p Proc) FDInfo(fd string) (*ProcFDInfo, error) { scanner := bufio.NewScanner(bytes.NewReader(data)) for scanner.Scan() { text = scanner.Text() - if rPos.MatchString(text) { + switch { + case rPos.MatchString(text): pos = rPos.FindStringSubmatch(text)[1] - } else if rFlags.MatchString(text) { + case rFlags.MatchString(text): flags = rFlags.FindStringSubmatch(text)[1] - } else if rMntID.MatchString(text) { + case rMntID.MatchString(text): mntid = rMntID.FindStringSubmatch(text)[1] - } else if rIno.MatchString(text) { + case rIno.MatchString(text): ino = rIno.FindStringSubmatch(text)[1] - } else if rInotify.MatchString(text) { + case rInotify.MatchString(text): newInotify, err := parseInotifyInfo(text) if err != nil { return nil, err diff --git a/vendor/github.com/prometheus/procfs/proc_interrupts.go b/vendor/github.com/prometheus/procfs/proc_interrupts.go index 86b4b4524..643b500d5 100644 --- a/vendor/github.com/prometheus/procfs/proc_interrupts.go +++ b/vendor/github.com/prometheus/procfs/proc_interrupts.go @@ -1,4 +1,4 @@ -// Copyright 2022 The Prometheus Authors +// Copyright The Prometheus 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 @@ -42,7 +42,7 @@ type Interrupts map[string]Interrupt // Interrupts creates a new instance from a given Proc instance. func (p Proc) Interrupts() (Interrupts, error) { - data, err := util.ReadFileNoStat(p.path("interrupts")) + data, err := util.ReadFileNoStat(p.fs.proc.Path("interrupts")) if err != nil { return nil, err } diff --git a/vendor/github.com/prometheus/procfs/proc_io.go b/vendor/github.com/prometheus/procfs/proc_io.go index d15b66ddb..dd8086ba2 100644 --- a/vendor/github.com/prometheus/procfs/proc_io.go +++ b/vendor/github.com/prometheus/procfs/proc_io.go @@ -1,4 +1,4 @@ -// Copyright 2018 The Prometheus Authors +// Copyright The Prometheus 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 diff --git a/vendor/github.com/prometheus/procfs/proc_limits.go b/vendor/github.com/prometheus/procfs/proc_limits.go index 9530b14bc..4b7d33784 100644 --- a/vendor/github.com/prometheus/procfs/proc_limits.go +++ b/vendor/github.com/prometheus/procfs/proc_limits.go @@ -1,4 +1,4 @@ -// Copyright 2018 The Prometheus Authors +// Copyright The Prometheus 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 @@ -19,6 +19,7 @@ import ( "os" "regexp" "strconv" + "strings" ) // ProcLimits represents the soft limits for each of the process's resource @@ -74,7 +75,7 @@ const ( ) var ( - limitsMatch = regexp.MustCompile(`(Max \w+\s{0,1}?\w*\s{0,1}\w*)\s{2,}(\w+)\s+(\w+)`) + limitsMatch = regexp.MustCompile(`(Max \w+\s??\w*\s?\w*)\s{2,}(\w+)\s+(\w+)`) ) // NewLimits returns the current soft limits of the process. @@ -106,7 +107,7 @@ func (p Proc) Limits() (ProcLimits, error) { return ProcLimits{}, fmt.Errorf("%w: couldn't parse %q line %q", ErrFileParse, f.Name(), s.Text()) } - switch fields[1] { + switch strings.TrimSpace(fields[1]) { case "Max cpu time": l.CPUTime, err = parseUint(fields[2]) case "Max file size": diff --git a/vendor/github.com/prometheus/procfs/proc_maps.go b/vendor/github.com/prometheus/procfs/proc_maps.go index 7e75c286b..08b89a6eb 100644 --- a/vendor/github.com/prometheus/procfs/proc_maps.go +++ b/vendor/github.com/prometheus/procfs/proc_maps.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Prometheus Authors +// Copyright The Prometheus 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 @@ -12,8 +12,6 @@ // limitations under the License. //go:build (aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris) && !js -// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris -// +build !js package procfs diff --git a/vendor/github.com/prometheus/procfs/proc_netstat.go b/vendor/github.com/prometheus/procfs/proc_netstat.go index 4248c1716..7f94cc891 100644 --- a/vendor/github.com/prometheus/procfs/proc_netstat.go +++ b/vendor/github.com/prometheus/procfs/proc_netstat.go @@ -1,4 +1,4 @@ -// Copyright 2022 The Prometheus Authors +// Copyright The Prometheus 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 diff --git a/vendor/github.com/prometheus/procfs/proc_ns.go b/vendor/github.com/prometheus/procfs/proc_ns.go index 0f8f847f9..5fc0eb9e2 100644 --- a/vendor/github.com/prometheus/procfs/proc_ns.go +++ b/vendor/github.com/prometheus/procfs/proc_ns.go @@ -1,4 +1,4 @@ -// Copyright 2018 The Prometheus Authors +// Copyright The Prometheus 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 diff --git a/vendor/github.com/prometheus/procfs/proc_psi.go b/vendor/github.com/prometheus/procfs/proc_psi.go index ccd35f153..cc2c5de87 100644 --- a/vendor/github.com/prometheus/procfs/proc_psi.go +++ b/vendor/github.com/prometheus/procfs/proc_psi.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Prometheus Authors +// Copyright The Prometheus 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 diff --git a/vendor/github.com/prometheus/procfs/proc_smaps.go b/vendor/github.com/prometheus/procfs/proc_smaps.go index 9a297afcf..f637309b3 100644 --- a/vendor/github.com/prometheus/procfs/proc_smaps.go +++ b/vendor/github.com/prometheus/procfs/proc_smaps.go @@ -1,4 +1,4 @@ -// Copyright 2020 The Prometheus Authors +// Copyright The Prometheus 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 @@ -12,7 +12,6 @@ // limitations under the License. //go:build !windows -// +build !windows package procfs diff --git a/vendor/github.com/prometheus/procfs/proc_snmp.go b/vendor/github.com/prometheus/procfs/proc_snmp.go index 4bdc90b07..8d9a9bcd6 100644 --- a/vendor/github.com/prometheus/procfs/proc_snmp.go +++ b/vendor/github.com/prometheus/procfs/proc_snmp.go @@ -1,4 +1,4 @@ -// Copyright 2022 The Prometheus Authors +// Copyright The Prometheus 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 diff --git a/vendor/github.com/prometheus/procfs/proc_snmp6.go b/vendor/github.com/prometheus/procfs/proc_snmp6.go index fb7fd3995..841fef464 100644 --- a/vendor/github.com/prometheus/procfs/proc_snmp6.go +++ b/vendor/github.com/prometheus/procfs/proc_snmp6.go @@ -1,4 +1,4 @@ -// Copyright 2022 The Prometheus Authors +// Copyright The Prometheus 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 diff --git a/vendor/github.com/prometheus/procfs/proc_stat.go b/vendor/github.com/prometheus/procfs/proc_stat.go index 06a8d931c..02e3f9e31 100644 --- a/vendor/github.com/prometheus/procfs/proc_stat.go +++ b/vendor/github.com/prometheus/procfs/proc_stat.go @@ -1,4 +1,4 @@ -// Copyright 2018 The Prometheus Authors +// Copyright The Prometheus 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 @@ -101,6 +101,12 @@ type ProcStat struct { RSS int // Soft limit in bytes on the rss of the process. RSSLimit uint64 + // The address above which program text can run. + StartCode uint64 + // The address below which program text can run. + EndCode uint64 + // The address of the start (i.e., bottom) of the stack. + StartStack uint64 // CPU number last executed on. Processor uint // Real-time scheduling priority, a number in the range 1 to 99 for processes @@ -177,9 +183,9 @@ func (p Proc) Stat() (ProcStat, error) { &s.VSize, &s.RSS, &s.RSSLimit, - &ignoreUint64, - &ignoreUint64, - &ignoreUint64, + &s.StartCode, + &s.EndCode, + &s.StartStack, &ignoreUint64, &ignoreUint64, &ignoreUint64, diff --git a/vendor/github.com/prometheus/procfs/proc_statm.go b/vendor/github.com/prometheus/procfs/proc_statm.go new file mode 100644 index 000000000..6bcc97ec9 --- /dev/null +++ b/vendor/github.com/prometheus/procfs/proc_statm.go @@ -0,0 +1,117 @@ +// Copyright The Prometheus 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. + +package procfs + +import ( + "os" + "strconv" + "strings" + + "github.com/prometheus/procfs/internal/util" +) + +// - https://man7.org/linux/man-pages/man5/proc_pid_statm.5.html + +// ProcStatm Provides memory usage information for a process, measured in memory pages. +// Read from /proc/[pid]/statm. +type ProcStatm struct { + // The process ID. + PID int + // total program size (same as VmSize in status) + Size uint64 + // resident set size (same as VmRSS in status) + Resident uint64 + // number of resident shared pages (i.e., backed by a file) + Shared uint64 + // text (code) + Text uint64 + // library (unused since Linux 2.6; always 0) + Lib uint64 + // data + stack + Data uint64 + // dirty pages (unused since Linux 2.6; always 0) + Dt uint64 +} + +// NewStatm returns the current status information of the process. +// +// Deprecated: Use p.Statm() instead. +func (p Proc) NewStatm() (ProcStatm, error) { + return p.Statm() +} + +// Statm returns the current memory usage information of the process. +func (p Proc) Statm() (ProcStatm, error) { + data, err := util.ReadFileNoStat(p.path("statm")) + if err != nil { + return ProcStatm{}, err + } + + statmSlice, err := parseStatm(data) + if err != nil { + return ProcStatm{}, err + } + + procStatm := ProcStatm{ + PID: p.PID, + Size: statmSlice[0], + Resident: statmSlice[1], + Shared: statmSlice[2], + Text: statmSlice[3], + Lib: statmSlice[4], + Data: statmSlice[5], + Dt: statmSlice[6], + } + + return procStatm, nil +} + +// parseStatm return /proc/[pid]/statm data to uint64 slice. +func parseStatm(data []byte) ([]uint64, error) { + var statmSlice []uint64 + statmItems := strings.Fields(string(data)) + for i := range statmItems { + statmItem, err := strconv.ParseUint(statmItems[i], 10, 64) + if err != nil { + return nil, err + } + statmSlice = append(statmSlice, statmItem) + } + return statmSlice, nil +} + +// SizeBytes returns the process of total program size in bytes. +func (s ProcStatm) SizeBytes() uint64 { + return s.Size * uint64(os.Getpagesize()) +} + +// ResidentBytes returns the process of resident set size in bytes. +func (s ProcStatm) ResidentBytes() uint64 { + return s.Resident * uint64(os.Getpagesize()) +} + +// SHRBytes returns the process of share memory size in bytes. +func (s ProcStatm) SHRBytes() uint64 { + return s.Shared * uint64(os.Getpagesize()) +} + +// TextBytes returns the process of text (code) size in bytes. +func (s ProcStatm) TextBytes() uint64 { + return s.Text * uint64(os.Getpagesize()) +} + +// DataBytes returns the process of data + stack size in bytes. +func (s ProcStatm) DataBytes() uint64 { + return s.Data * uint64(os.Getpagesize()) +} diff --git a/vendor/github.com/prometheus/procfs/proc_status.go b/vendor/github.com/prometheus/procfs/proc_status.go index dd8aa5688..12d65581c 100644 --- a/vendor/github.com/prometheus/procfs/proc_status.go +++ b/vendor/github.com/prometheus/procfs/proc_status.go @@ -1,4 +1,4 @@ -// Copyright 2018 The Prometheus Authors +// Copyright The Prometheus 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 @@ -16,7 +16,7 @@ package procfs import ( "bytes" "math/bits" - "sort" + "slices" "strconv" "strings" @@ -83,6 +83,19 @@ type ProcStatus struct { // CpusAllowedList: List of cpu cores processes are allowed to run on. CpusAllowedList []uint64 + + // CapInh is the bitmap of inheritable capabilities + // + // See: https://www.kernel.org/doc/man-pages/online/pages/man7/capabilities.7.html + CapInh uint64 + // CapPrm is the bitmap of permitted capabilities + CapPrm uint64 + // CapEff is the bitmap of effective capabilities + CapEff uint64 + // CapBnd is the bitmap of bounding capabilities + CapBnd uint64 + // CapAmb is the bitmap of ambient capabilities + CapAmb uint64 } // NewStatus returns the current status information of the process. @@ -94,8 +107,7 @@ func (p Proc) NewStatus() (ProcStatus, error) { s := ProcStatus{PID: p.PID} - lines := strings.Split(string(data), "\n") - for _, line := range lines { + for line := range strings.SplitSeq(string(data), "\n") { if !bytes.Contains([]byte(line), []byte(":")) { continue } @@ -191,6 +203,36 @@ func (s *ProcStatus) fillStatus(k string, vString string, vUint uint64, vUintByt s.NonVoluntaryCtxtSwitches = vUint case "Cpus_allowed_list": s.CpusAllowedList = calcCpusAllowedList(vString) + case "CapInh": + var err error + s.CapInh, err = strconv.ParseUint(vString, 16, 64) + if err != nil { + return err + } + case "CapPrm": + var err error + s.CapPrm, err = strconv.ParseUint(vString, 16, 64) + if err != nil { + return err + } + case "CapEff": + var err error + s.CapEff, err = strconv.ParseUint(vString, 16, 64) + if err != nil { + return err + } + case "CapBnd": + var err error + s.CapBnd, err = strconv.ParseUint(vString, 16, 64) + if err != nil { + return err + } + case "CapAmb": + var err error + s.CapAmb, err = strconv.ParseUint(vString, 16, 64) + if err != nil { + return err + } } return nil @@ -222,7 +264,7 @@ func calcCpusAllowedList(cpuString string) []uint64 { } - sort.Slice(g, func(i, j int) bool { return g[i] < g[j] }) + slices.Sort(g) return g } diff --git a/vendor/github.com/prometheus/procfs/proc_sys.go b/vendor/github.com/prometheus/procfs/proc_sys.go index 3810d1ac9..52658a4d5 100644 --- a/vendor/github.com/prometheus/procfs/proc_sys.go +++ b/vendor/github.com/prometheus/procfs/proc_sys.go @@ -1,4 +1,4 @@ -// Copyright 2022 The Prometheus Authors +// Copyright The Prometheus 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 diff --git a/vendor/github.com/prometheus/procfs/schedstat.go b/vendor/github.com/prometheus/procfs/schedstat.go index 5f7f32dc8..fafd8dff7 100644 --- a/vendor/github.com/prometheus/procfs/schedstat.go +++ b/vendor/github.com/prometheus/procfs/schedstat.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Prometheus Authors +// Copyright The Prometheus 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 diff --git a/vendor/github.com/prometheus/procfs/slab.go b/vendor/github.com/prometheus/procfs/slab.go index 8611c9017..32a04678a 100644 --- a/vendor/github.com/prometheus/procfs/slab.go +++ b/vendor/github.com/prometheus/procfs/slab.go @@ -1,4 +1,4 @@ -// Copyright 2020 The Prometheus Authors +// Copyright The Prometheus 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 diff --git a/vendor/github.com/prometheus/procfs/softirqs.go b/vendor/github.com/prometheus/procfs/softirqs.go index 403e6ae70..47b73a729 100644 --- a/vendor/github.com/prometheus/procfs/softirqs.go +++ b/vendor/github.com/prometheus/procfs/softirqs.go @@ -1,4 +1,4 @@ -// Copyright 2022 The Prometheus Authors +// Copyright The Prometheus 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 diff --git a/vendor/github.com/prometheus/procfs/stat.go b/vendor/github.com/prometheus/procfs/stat.go index e36b41c18..593ad0f62 100644 --- a/vendor/github.com/prometheus/procfs/stat.go +++ b/vendor/github.com/prometheus/procfs/stat.go @@ -1,4 +1,4 @@ -// Copyright 2018 The Prometheus Authors +// Copyright The Prometheus 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 @@ -16,6 +16,7 @@ package procfs import ( "bufio" "bytes" + "errors" "fmt" "io" "strconv" @@ -92,7 +93,7 @@ func parseCPUStat(line string) (CPUStat, int64, error) { &cpuStat.Iowait, &cpuStat.IRQ, &cpuStat.SoftIRQ, &cpuStat.Steal, &cpuStat.Guest, &cpuStat.GuestNice) - if err != nil && err != io.EOF { + if err != nil && !errors.Is(err, io.EOF) { return CPUStat{}, -1, fmt.Errorf("%w: couldn't parse %q (cpu): %w", ErrFileParse, line, err) } if count == 0 { diff --git a/vendor/github.com/prometheus/procfs/swaps.go b/vendor/github.com/prometheus/procfs/swaps.go index 65fec834b..ee17bf488 100644 --- a/vendor/github.com/prometheus/procfs/swaps.go +++ b/vendor/github.com/prometheus/procfs/swaps.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Prometheus Authors +// Copyright The Prometheus 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 diff --git a/vendor/github.com/prometheus/procfs/thread.go b/vendor/github.com/prometheus/procfs/thread.go index 80e0e947b..0cfbb5418 100644 --- a/vendor/github.com/prometheus/procfs/thread.go +++ b/vendor/github.com/prometheus/procfs/thread.go @@ -1,4 +1,4 @@ -// Copyright 2022 The Prometheus Authors +// Copyright The Prometheus 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 diff --git a/vendor/github.com/prometheus/procfs/vm.go b/vendor/github.com/prometheus/procfs/vm.go index 51c49d89e..52180c03e 100644 --- a/vendor/github.com/prometheus/procfs/vm.go +++ b/vendor/github.com/prometheus/procfs/vm.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Prometheus Authors +// Copyright The Prometheus 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 @@ -12,7 +12,6 @@ // limitations under the License. //go:build !windows -// +build !windows package procfs diff --git a/vendor/github.com/prometheus/procfs/zoneinfo.go b/vendor/github.com/prometheus/procfs/zoneinfo.go index e54d94b09..63d1898bc 100644 --- a/vendor/github.com/prometheus/procfs/zoneinfo.go +++ b/vendor/github.com/prometheus/procfs/zoneinfo.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Prometheus Authors +// Copyright The Prometheus 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 @@ -12,7 +12,6 @@ // limitations under the License. //go:build !windows -// +build !windows package procfs @@ -88,11 +87,9 @@ func parseZoneinfo(zoneinfoData []byte) ([]Zoneinfo, error) { zoneinfo := []Zoneinfo{} - zoneinfoBlocks := bytes.Split(zoneinfoData, []byte("\nNode")) - for _, block := range zoneinfoBlocks { + for block := range bytes.SplitSeq(zoneinfoData, []byte("\nNode")) { var zoneinfoElement Zoneinfo - lines := strings.Split(string(block), "\n") - for _, line := range lines { + for line := range strings.SplitSeq(string(block), "\n") { if nodeZone := nodeZoneRE.FindStringSubmatch(line); nodeZone != nil { zoneinfoElement.Node = nodeZone[1] diff --git a/vendor/go.yaml.in/yaml/v2/LICENSE b/vendor/go.yaml.in/yaml/v2/LICENSE deleted file mode 100644 index 8dada3eda..000000000 --- a/vendor/go.yaml.in/yaml/v2/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "{}" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright {yyyy} {name of copyright owner} - - 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. diff --git a/vendor/go.yaml.in/yaml/v2/LICENSE.libyaml b/vendor/go.yaml.in/yaml/v2/LICENSE.libyaml deleted file mode 100644 index 8da58fbf6..000000000 --- a/vendor/go.yaml.in/yaml/v2/LICENSE.libyaml +++ /dev/null @@ -1,31 +0,0 @@ -The following files were ported to Go from C files of libyaml, and thus -are still covered by their original copyright and license: - - apic.go - emitterc.go - parserc.go - readerc.go - scannerc.go - writerc.go - yamlh.go - yamlprivateh.go - -Copyright (c) 2006 Kirill Simonov - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/vendor/go.yaml.in/yaml/v2/NOTICE b/vendor/go.yaml.in/yaml/v2/NOTICE deleted file mode 100644 index 866d74a7a..000000000 --- a/vendor/go.yaml.in/yaml/v2/NOTICE +++ /dev/null @@ -1,13 +0,0 @@ -Copyright 2011-2016 Canonical Ltd. - -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. diff --git a/vendor/go.yaml.in/yaml/v2/apic.go b/vendor/go.yaml.in/yaml/v2/apic.go deleted file mode 100644 index acf71402c..000000000 --- a/vendor/go.yaml.in/yaml/v2/apic.go +++ /dev/null @@ -1,744 +0,0 @@ -package yaml - -import ( - "io" -) - -func yaml_insert_token(parser *yaml_parser_t, pos int, token *yaml_token_t) { - //fmt.Println("yaml_insert_token", "pos:", pos, "typ:", token.typ, "head:", parser.tokens_head, "len:", len(parser.tokens)) - - // Check if we can move the queue at the beginning of the buffer. - if parser.tokens_head > 0 && len(parser.tokens) == cap(parser.tokens) { - if parser.tokens_head != len(parser.tokens) { - copy(parser.tokens, parser.tokens[parser.tokens_head:]) - } - parser.tokens = parser.tokens[:len(parser.tokens)-parser.tokens_head] - parser.tokens_head = 0 - } - parser.tokens = append(parser.tokens, *token) - if pos < 0 { - return - } - copy(parser.tokens[parser.tokens_head+pos+1:], parser.tokens[parser.tokens_head+pos:]) - parser.tokens[parser.tokens_head+pos] = *token -} - -// Create a new parser object. -func yaml_parser_initialize(parser *yaml_parser_t) bool { - *parser = yaml_parser_t{ - raw_buffer: make([]byte, 0, input_raw_buffer_size), - buffer: make([]byte, 0, input_buffer_size), - } - return true -} - -// Destroy a parser object. -func yaml_parser_delete(parser *yaml_parser_t) { - *parser = yaml_parser_t{} -} - -// String read handler. -func yaml_string_read_handler(parser *yaml_parser_t, buffer []byte) (n int, err error) { - if parser.input_pos == len(parser.input) { - return 0, io.EOF - } - n = copy(buffer, parser.input[parser.input_pos:]) - parser.input_pos += n - return n, nil -} - -// Reader read handler. -func yaml_reader_read_handler(parser *yaml_parser_t, buffer []byte) (n int, err error) { - return parser.input_reader.Read(buffer) -} - -// Set a string input. -func yaml_parser_set_input_string(parser *yaml_parser_t, input []byte) { - if parser.read_handler != nil { - panic("must set the input source only once") - } - parser.read_handler = yaml_string_read_handler - parser.input = input - parser.input_pos = 0 -} - -// Set a file input. -func yaml_parser_set_input_reader(parser *yaml_parser_t, r io.Reader) { - if parser.read_handler != nil { - panic("must set the input source only once") - } - parser.read_handler = yaml_reader_read_handler - parser.input_reader = r -} - -// Set the source encoding. -func yaml_parser_set_encoding(parser *yaml_parser_t, encoding yaml_encoding_t) { - if parser.encoding != yaml_ANY_ENCODING { - panic("must set the encoding only once") - } - parser.encoding = encoding -} - -var disableLineWrapping = false - -// Create a new emitter object. -func yaml_emitter_initialize(emitter *yaml_emitter_t) { - *emitter = yaml_emitter_t{ - buffer: make([]byte, output_buffer_size), - raw_buffer: make([]byte, 0, output_raw_buffer_size), - states: make([]yaml_emitter_state_t, 0, initial_stack_size), - events: make([]yaml_event_t, 0, initial_queue_size), - } - if disableLineWrapping { - emitter.best_width = -1 - } -} - -// Destroy an emitter object. -func yaml_emitter_delete(emitter *yaml_emitter_t) { - *emitter = yaml_emitter_t{} -} - -// String write handler. -func yaml_string_write_handler(emitter *yaml_emitter_t, buffer []byte) error { - *emitter.output_buffer = append(*emitter.output_buffer, buffer...) - return nil -} - -// yaml_writer_write_handler uses emitter.output_writer to write the -// emitted text. -func yaml_writer_write_handler(emitter *yaml_emitter_t, buffer []byte) error { - _, err := emitter.output_writer.Write(buffer) - return err -} - -// Set a string output. -func yaml_emitter_set_output_string(emitter *yaml_emitter_t, output_buffer *[]byte) { - if emitter.write_handler != nil { - panic("must set the output target only once") - } - emitter.write_handler = yaml_string_write_handler - emitter.output_buffer = output_buffer -} - -// Set a file output. -func yaml_emitter_set_output_writer(emitter *yaml_emitter_t, w io.Writer) { - if emitter.write_handler != nil { - panic("must set the output target only once") - } - emitter.write_handler = yaml_writer_write_handler - emitter.output_writer = w -} - -// Set the output encoding. -func yaml_emitter_set_encoding(emitter *yaml_emitter_t, encoding yaml_encoding_t) { - if emitter.encoding != yaml_ANY_ENCODING { - panic("must set the output encoding only once") - } - emitter.encoding = encoding -} - -// Set the canonical output style. -func yaml_emitter_set_canonical(emitter *yaml_emitter_t, canonical bool) { - emitter.canonical = canonical -} - -//// Set the indentation increment. -func yaml_emitter_set_indent(emitter *yaml_emitter_t, indent int) { - if indent < 2 || indent > 9 { - indent = 2 - } - emitter.best_indent = indent -} - -// Set the preferred line width. -func yaml_emitter_set_width(emitter *yaml_emitter_t, width int) { - if width < 0 { - width = -1 - } - emitter.best_width = width -} - -// Set if unescaped non-ASCII characters are allowed. -func yaml_emitter_set_unicode(emitter *yaml_emitter_t, unicode bool) { - emitter.unicode = unicode -} - -// Set the preferred line break character. -func yaml_emitter_set_break(emitter *yaml_emitter_t, line_break yaml_break_t) { - emitter.line_break = line_break -} - -///* -// * Destroy a token object. -// */ -// -//YAML_DECLARE(void) -//yaml_token_delete(yaml_token_t *token) -//{ -// assert(token); // Non-NULL token object expected. -// -// switch (token.type) -// { -// case YAML_TAG_DIRECTIVE_TOKEN: -// yaml_free(token.data.tag_directive.handle); -// yaml_free(token.data.tag_directive.prefix); -// break; -// -// case YAML_ALIAS_TOKEN: -// yaml_free(token.data.alias.value); -// break; -// -// case YAML_ANCHOR_TOKEN: -// yaml_free(token.data.anchor.value); -// break; -// -// case YAML_TAG_TOKEN: -// yaml_free(token.data.tag.handle); -// yaml_free(token.data.tag.suffix); -// break; -// -// case YAML_SCALAR_TOKEN: -// yaml_free(token.data.scalar.value); -// break; -// -// default: -// break; -// } -// -// memset(token, 0, sizeof(yaml_token_t)); -//} -// -///* -// * Check if a string is a valid UTF-8 sequence. -// * -// * Check 'reader.c' for more details on UTF-8 encoding. -// */ -// -//static int -//yaml_check_utf8(yaml_char_t *start, size_t length) -//{ -// yaml_char_t *end = start+length; -// yaml_char_t *pointer = start; -// -// while (pointer < end) { -// unsigned char octet; -// unsigned int width; -// unsigned int value; -// size_t k; -// -// octet = pointer[0]; -// width = (octet & 0x80) == 0x00 ? 1 : -// (octet & 0xE0) == 0xC0 ? 2 : -// (octet & 0xF0) == 0xE0 ? 3 : -// (octet & 0xF8) == 0xF0 ? 4 : 0; -// value = (octet & 0x80) == 0x00 ? octet & 0x7F : -// (octet & 0xE0) == 0xC0 ? octet & 0x1F : -// (octet & 0xF0) == 0xE0 ? octet & 0x0F : -// (octet & 0xF8) == 0xF0 ? octet & 0x07 : 0; -// if (!width) return 0; -// if (pointer+width > end) return 0; -// for (k = 1; k < width; k ++) { -// octet = pointer[k]; -// if ((octet & 0xC0) != 0x80) return 0; -// value = (value << 6) + (octet & 0x3F); -// } -// if (!((width == 1) || -// (width == 2 && value >= 0x80) || -// (width == 3 && value >= 0x800) || -// (width == 4 && value >= 0x10000))) return 0; -// -// pointer += width; -// } -// -// return 1; -//} -// - -// Create STREAM-START. -func yaml_stream_start_event_initialize(event *yaml_event_t, encoding yaml_encoding_t) { - *event = yaml_event_t{ - typ: yaml_STREAM_START_EVENT, - encoding: encoding, - } -} - -// Create STREAM-END. -func yaml_stream_end_event_initialize(event *yaml_event_t) { - *event = yaml_event_t{ - typ: yaml_STREAM_END_EVENT, - } -} - -// Create DOCUMENT-START. -func yaml_document_start_event_initialize( - event *yaml_event_t, - version_directive *yaml_version_directive_t, - tag_directives []yaml_tag_directive_t, - implicit bool, -) { - *event = yaml_event_t{ - typ: yaml_DOCUMENT_START_EVENT, - version_directive: version_directive, - tag_directives: tag_directives, - implicit: implicit, - } -} - -// Create DOCUMENT-END. -func yaml_document_end_event_initialize(event *yaml_event_t, implicit bool) { - *event = yaml_event_t{ - typ: yaml_DOCUMENT_END_EVENT, - implicit: implicit, - } -} - -///* -// * Create ALIAS. -// */ -// -//YAML_DECLARE(int) -//yaml_alias_event_initialize(event *yaml_event_t, anchor *yaml_char_t) -//{ -// mark yaml_mark_t = { 0, 0, 0 } -// anchor_copy *yaml_char_t = NULL -// -// assert(event) // Non-NULL event object is expected. -// assert(anchor) // Non-NULL anchor is expected. -// -// if (!yaml_check_utf8(anchor, strlen((char *)anchor))) return 0 -// -// anchor_copy = yaml_strdup(anchor) -// if (!anchor_copy) -// return 0 -// -// ALIAS_EVENT_INIT(*event, anchor_copy, mark, mark) -// -// return 1 -//} - -// Create SCALAR. -func yaml_scalar_event_initialize(event *yaml_event_t, anchor, tag, value []byte, plain_implicit, quoted_implicit bool, style yaml_scalar_style_t) bool { - *event = yaml_event_t{ - typ: yaml_SCALAR_EVENT, - anchor: anchor, - tag: tag, - value: value, - implicit: plain_implicit, - quoted_implicit: quoted_implicit, - style: yaml_style_t(style), - } - return true -} - -// Create SEQUENCE-START. -func yaml_sequence_start_event_initialize(event *yaml_event_t, anchor, tag []byte, implicit bool, style yaml_sequence_style_t) bool { - *event = yaml_event_t{ - typ: yaml_SEQUENCE_START_EVENT, - anchor: anchor, - tag: tag, - implicit: implicit, - style: yaml_style_t(style), - } - return true -} - -// Create SEQUENCE-END. -func yaml_sequence_end_event_initialize(event *yaml_event_t) bool { - *event = yaml_event_t{ - typ: yaml_SEQUENCE_END_EVENT, - } - return true -} - -// Create MAPPING-START. -func yaml_mapping_start_event_initialize(event *yaml_event_t, anchor, tag []byte, implicit bool, style yaml_mapping_style_t) { - *event = yaml_event_t{ - typ: yaml_MAPPING_START_EVENT, - anchor: anchor, - tag: tag, - implicit: implicit, - style: yaml_style_t(style), - } -} - -// Create MAPPING-END. -func yaml_mapping_end_event_initialize(event *yaml_event_t) { - *event = yaml_event_t{ - typ: yaml_MAPPING_END_EVENT, - } -} - -// Destroy an event object. -func yaml_event_delete(event *yaml_event_t) { - *event = yaml_event_t{} -} - -///* -// * Create a document object. -// */ -// -//YAML_DECLARE(int) -//yaml_document_initialize(document *yaml_document_t, -// version_directive *yaml_version_directive_t, -// tag_directives_start *yaml_tag_directive_t, -// tag_directives_end *yaml_tag_directive_t, -// start_implicit int, end_implicit int) -//{ -// struct { -// error yaml_error_type_t -// } context -// struct { -// start *yaml_node_t -// end *yaml_node_t -// top *yaml_node_t -// } nodes = { NULL, NULL, NULL } -// version_directive_copy *yaml_version_directive_t = NULL -// struct { -// start *yaml_tag_directive_t -// end *yaml_tag_directive_t -// top *yaml_tag_directive_t -// } tag_directives_copy = { NULL, NULL, NULL } -// value yaml_tag_directive_t = { NULL, NULL } -// mark yaml_mark_t = { 0, 0, 0 } -// -// assert(document) // Non-NULL document object is expected. -// assert((tag_directives_start && tag_directives_end) || -// (tag_directives_start == tag_directives_end)) -// // Valid tag directives are expected. -// -// if (!STACK_INIT(&context, nodes, INITIAL_STACK_SIZE)) goto error -// -// if (version_directive) { -// version_directive_copy = yaml_malloc(sizeof(yaml_version_directive_t)) -// if (!version_directive_copy) goto error -// version_directive_copy.major = version_directive.major -// version_directive_copy.minor = version_directive.minor -// } -// -// if (tag_directives_start != tag_directives_end) { -// tag_directive *yaml_tag_directive_t -// if (!STACK_INIT(&context, tag_directives_copy, INITIAL_STACK_SIZE)) -// goto error -// for (tag_directive = tag_directives_start -// tag_directive != tag_directives_end; tag_directive ++) { -// assert(tag_directive.handle) -// assert(tag_directive.prefix) -// if (!yaml_check_utf8(tag_directive.handle, -// strlen((char *)tag_directive.handle))) -// goto error -// if (!yaml_check_utf8(tag_directive.prefix, -// strlen((char *)tag_directive.prefix))) -// goto error -// value.handle = yaml_strdup(tag_directive.handle) -// value.prefix = yaml_strdup(tag_directive.prefix) -// if (!value.handle || !value.prefix) goto error -// if (!PUSH(&context, tag_directives_copy, value)) -// goto error -// value.handle = NULL -// value.prefix = NULL -// } -// } -// -// DOCUMENT_INIT(*document, nodes.start, nodes.end, version_directive_copy, -// tag_directives_copy.start, tag_directives_copy.top, -// start_implicit, end_implicit, mark, mark) -// -// return 1 -// -//error: -// STACK_DEL(&context, nodes) -// yaml_free(version_directive_copy) -// while (!STACK_EMPTY(&context, tag_directives_copy)) { -// value yaml_tag_directive_t = POP(&context, tag_directives_copy) -// yaml_free(value.handle) -// yaml_free(value.prefix) -// } -// STACK_DEL(&context, tag_directives_copy) -// yaml_free(value.handle) -// yaml_free(value.prefix) -// -// return 0 -//} -// -///* -// * Destroy a document object. -// */ -// -//YAML_DECLARE(void) -//yaml_document_delete(document *yaml_document_t) -//{ -// struct { -// error yaml_error_type_t -// } context -// tag_directive *yaml_tag_directive_t -// -// context.error = YAML_NO_ERROR // Eliminate a compiler warning. -// -// assert(document) // Non-NULL document object is expected. -// -// while (!STACK_EMPTY(&context, document.nodes)) { -// node yaml_node_t = POP(&context, document.nodes) -// yaml_free(node.tag) -// switch (node.type) { -// case YAML_SCALAR_NODE: -// yaml_free(node.data.scalar.value) -// break -// case YAML_SEQUENCE_NODE: -// STACK_DEL(&context, node.data.sequence.items) -// break -// case YAML_MAPPING_NODE: -// STACK_DEL(&context, node.data.mapping.pairs) -// break -// default: -// assert(0) // Should not happen. -// } -// } -// STACK_DEL(&context, document.nodes) -// -// yaml_free(document.version_directive) -// for (tag_directive = document.tag_directives.start -// tag_directive != document.tag_directives.end -// tag_directive++) { -// yaml_free(tag_directive.handle) -// yaml_free(tag_directive.prefix) -// } -// yaml_free(document.tag_directives.start) -// -// memset(document, 0, sizeof(yaml_document_t)) -//} -// -///** -// * Get a document node. -// */ -// -//YAML_DECLARE(yaml_node_t *) -//yaml_document_get_node(document *yaml_document_t, index int) -//{ -// assert(document) // Non-NULL document object is expected. -// -// if (index > 0 && document.nodes.start + index <= document.nodes.top) { -// return document.nodes.start + index - 1 -// } -// return NULL -//} -// -///** -// * Get the root object. -// */ -// -//YAML_DECLARE(yaml_node_t *) -//yaml_document_get_root_node(document *yaml_document_t) -//{ -// assert(document) // Non-NULL document object is expected. -// -// if (document.nodes.top != document.nodes.start) { -// return document.nodes.start -// } -// return NULL -//} -// -///* -// * Add a scalar node to a document. -// */ -// -//YAML_DECLARE(int) -//yaml_document_add_scalar(document *yaml_document_t, -// tag *yaml_char_t, value *yaml_char_t, length int, -// style yaml_scalar_style_t) -//{ -// struct { -// error yaml_error_type_t -// } context -// mark yaml_mark_t = { 0, 0, 0 } -// tag_copy *yaml_char_t = NULL -// value_copy *yaml_char_t = NULL -// node yaml_node_t -// -// assert(document) // Non-NULL document object is expected. -// assert(value) // Non-NULL value is expected. -// -// if (!tag) { -// tag = (yaml_char_t *)YAML_DEFAULT_SCALAR_TAG -// } -// -// if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error -// tag_copy = yaml_strdup(tag) -// if (!tag_copy) goto error -// -// if (length < 0) { -// length = strlen((char *)value) -// } -// -// if (!yaml_check_utf8(value, length)) goto error -// value_copy = yaml_malloc(length+1) -// if (!value_copy) goto error -// memcpy(value_copy, value, length) -// value_copy[length] = '\0' -// -// SCALAR_NODE_INIT(node, tag_copy, value_copy, length, style, mark, mark) -// if (!PUSH(&context, document.nodes, node)) goto error -// -// return document.nodes.top - document.nodes.start -// -//error: -// yaml_free(tag_copy) -// yaml_free(value_copy) -// -// return 0 -//} -// -///* -// * Add a sequence node to a document. -// */ -// -//YAML_DECLARE(int) -//yaml_document_add_sequence(document *yaml_document_t, -// tag *yaml_char_t, style yaml_sequence_style_t) -//{ -// struct { -// error yaml_error_type_t -// } context -// mark yaml_mark_t = { 0, 0, 0 } -// tag_copy *yaml_char_t = NULL -// struct { -// start *yaml_node_item_t -// end *yaml_node_item_t -// top *yaml_node_item_t -// } items = { NULL, NULL, NULL } -// node yaml_node_t -// -// assert(document) // Non-NULL document object is expected. -// -// if (!tag) { -// tag = (yaml_char_t *)YAML_DEFAULT_SEQUENCE_TAG -// } -// -// if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error -// tag_copy = yaml_strdup(tag) -// if (!tag_copy) goto error -// -// if (!STACK_INIT(&context, items, INITIAL_STACK_SIZE)) goto error -// -// SEQUENCE_NODE_INIT(node, tag_copy, items.start, items.end, -// style, mark, mark) -// if (!PUSH(&context, document.nodes, node)) goto error -// -// return document.nodes.top - document.nodes.start -// -//error: -// STACK_DEL(&context, items) -// yaml_free(tag_copy) -// -// return 0 -//} -// -///* -// * Add a mapping node to a document. -// */ -// -//YAML_DECLARE(int) -//yaml_document_add_mapping(document *yaml_document_t, -// tag *yaml_char_t, style yaml_mapping_style_t) -//{ -// struct { -// error yaml_error_type_t -// } context -// mark yaml_mark_t = { 0, 0, 0 } -// tag_copy *yaml_char_t = NULL -// struct { -// start *yaml_node_pair_t -// end *yaml_node_pair_t -// top *yaml_node_pair_t -// } pairs = { NULL, NULL, NULL } -// node yaml_node_t -// -// assert(document) // Non-NULL document object is expected. -// -// if (!tag) { -// tag = (yaml_char_t *)YAML_DEFAULT_MAPPING_TAG -// } -// -// if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error -// tag_copy = yaml_strdup(tag) -// if (!tag_copy) goto error -// -// if (!STACK_INIT(&context, pairs, INITIAL_STACK_SIZE)) goto error -// -// MAPPING_NODE_INIT(node, tag_copy, pairs.start, pairs.end, -// style, mark, mark) -// if (!PUSH(&context, document.nodes, node)) goto error -// -// return document.nodes.top - document.nodes.start -// -//error: -// STACK_DEL(&context, pairs) -// yaml_free(tag_copy) -// -// return 0 -//} -// -///* -// * Append an item to a sequence node. -// */ -// -//YAML_DECLARE(int) -//yaml_document_append_sequence_item(document *yaml_document_t, -// sequence int, item int) -//{ -// struct { -// error yaml_error_type_t -// } context -// -// assert(document) // Non-NULL document is required. -// assert(sequence > 0 -// && document.nodes.start + sequence <= document.nodes.top) -// // Valid sequence id is required. -// assert(document.nodes.start[sequence-1].type == YAML_SEQUENCE_NODE) -// // A sequence node is required. -// assert(item > 0 && document.nodes.start + item <= document.nodes.top) -// // Valid item id is required. -// -// if (!PUSH(&context, -// document.nodes.start[sequence-1].data.sequence.items, item)) -// return 0 -// -// return 1 -//} -// -///* -// * Append a pair of a key and a value to a mapping node. -// */ -// -//YAML_DECLARE(int) -//yaml_document_append_mapping_pair(document *yaml_document_t, -// mapping int, key int, value int) -//{ -// struct { -// error yaml_error_type_t -// } context -// -// pair yaml_node_pair_t -// -// assert(document) // Non-NULL document is required. -// assert(mapping > 0 -// && document.nodes.start + mapping <= document.nodes.top) -// // Valid mapping id is required. -// assert(document.nodes.start[mapping-1].type == YAML_MAPPING_NODE) -// // A mapping node is required. -// assert(key > 0 && document.nodes.start + key <= document.nodes.top) -// // Valid key id is required. -// assert(value > 0 && document.nodes.start + value <= document.nodes.top) -// // Valid value id is required. -// -// pair.key = key -// pair.value = value -// -// if (!PUSH(&context, -// document.nodes.start[mapping-1].data.mapping.pairs, pair)) -// return 0 -// -// return 1 -//} -// -// diff --git a/vendor/go.yaml.in/yaml/v2/decode.go b/vendor/go.yaml.in/yaml/v2/decode.go deleted file mode 100644 index 129bc2a97..000000000 --- a/vendor/go.yaml.in/yaml/v2/decode.go +++ /dev/null @@ -1,815 +0,0 @@ -package yaml - -import ( - "encoding" - "encoding/base64" - "fmt" - "io" - "math" - "reflect" - "strconv" - "time" -) - -const ( - documentNode = 1 << iota - mappingNode - sequenceNode - scalarNode - aliasNode -) - -type node struct { - kind int - line, column int - tag string - // For an alias node, alias holds the resolved alias. - alias *node - value string - implicit bool - children []*node - anchors map[string]*node -} - -// ---------------------------------------------------------------------------- -// Parser, produces a node tree out of a libyaml event stream. - -type parser struct { - parser yaml_parser_t - event yaml_event_t - doc *node - doneInit bool -} - -func newParser(b []byte) *parser { - p := parser{} - if !yaml_parser_initialize(&p.parser) { - panic("failed to initialize YAML emitter") - } - if len(b) == 0 { - b = []byte{'\n'} - } - yaml_parser_set_input_string(&p.parser, b) - return &p -} - -func newParserFromReader(r io.Reader) *parser { - p := parser{} - if !yaml_parser_initialize(&p.parser) { - panic("failed to initialize YAML emitter") - } - yaml_parser_set_input_reader(&p.parser, r) - return &p -} - -func (p *parser) init() { - if p.doneInit { - return - } - p.expect(yaml_STREAM_START_EVENT) - p.doneInit = true -} - -func (p *parser) destroy() { - if p.event.typ != yaml_NO_EVENT { - yaml_event_delete(&p.event) - } - yaml_parser_delete(&p.parser) -} - -// expect consumes an event from the event stream and -// checks that it's of the expected type. -func (p *parser) expect(e yaml_event_type_t) { - if p.event.typ == yaml_NO_EVENT { - if !yaml_parser_parse(&p.parser, &p.event) { - p.fail() - } - } - if p.event.typ == yaml_STREAM_END_EVENT { - failf("attempted to go past the end of stream; corrupted value?") - } - if p.event.typ != e { - p.parser.problem = fmt.Sprintf("expected %s event but got %s", e, p.event.typ) - p.fail() - } - yaml_event_delete(&p.event) - p.event.typ = yaml_NO_EVENT -} - -// peek peeks at the next event in the event stream, -// puts the results into p.event and returns the event type. -func (p *parser) peek() yaml_event_type_t { - if p.event.typ != yaml_NO_EVENT { - return p.event.typ - } - if !yaml_parser_parse(&p.parser, &p.event) { - p.fail() - } - return p.event.typ -} - -func (p *parser) fail() { - var where string - var line int - if p.parser.problem_mark.line != 0 { - line = p.parser.problem_mark.line - // Scanner errors don't iterate line before returning error - if p.parser.error == yaml_SCANNER_ERROR { - line++ - } - } else if p.parser.context_mark.line != 0 { - line = p.parser.context_mark.line - } - if line != 0 { - where = "line " + strconv.Itoa(line) + ": " - } - var msg string - if len(p.parser.problem) > 0 { - msg = p.parser.problem - } else { - msg = "unknown problem parsing YAML content" - } - failf("%s%s", where, msg) -} - -func (p *parser) anchor(n *node, anchor []byte) { - if anchor != nil { - p.doc.anchors[string(anchor)] = n - } -} - -func (p *parser) parse() *node { - p.init() - switch p.peek() { - case yaml_SCALAR_EVENT: - return p.scalar() - case yaml_ALIAS_EVENT: - return p.alias() - case yaml_MAPPING_START_EVENT: - return p.mapping() - case yaml_SEQUENCE_START_EVENT: - return p.sequence() - case yaml_DOCUMENT_START_EVENT: - return p.document() - case yaml_STREAM_END_EVENT: - // Happens when attempting to decode an empty buffer. - return nil - default: - panic("attempted to parse unknown event: " + p.event.typ.String()) - } -} - -func (p *parser) node(kind int) *node { - return &node{ - kind: kind, - line: p.event.start_mark.line, - column: p.event.start_mark.column, - } -} - -func (p *parser) document() *node { - n := p.node(documentNode) - n.anchors = make(map[string]*node) - p.doc = n - p.expect(yaml_DOCUMENT_START_EVENT) - n.children = append(n.children, p.parse()) - p.expect(yaml_DOCUMENT_END_EVENT) - return n -} - -func (p *parser) alias() *node { - n := p.node(aliasNode) - n.value = string(p.event.anchor) - n.alias = p.doc.anchors[n.value] - if n.alias == nil { - failf("unknown anchor '%s' referenced", n.value) - } - p.expect(yaml_ALIAS_EVENT) - return n -} - -func (p *parser) scalar() *node { - n := p.node(scalarNode) - n.value = string(p.event.value) - n.tag = string(p.event.tag) - n.implicit = p.event.implicit - p.anchor(n, p.event.anchor) - p.expect(yaml_SCALAR_EVENT) - return n -} - -func (p *parser) sequence() *node { - n := p.node(sequenceNode) - p.anchor(n, p.event.anchor) - p.expect(yaml_SEQUENCE_START_EVENT) - for p.peek() != yaml_SEQUENCE_END_EVENT { - n.children = append(n.children, p.parse()) - } - p.expect(yaml_SEQUENCE_END_EVENT) - return n -} - -func (p *parser) mapping() *node { - n := p.node(mappingNode) - p.anchor(n, p.event.anchor) - p.expect(yaml_MAPPING_START_EVENT) - for p.peek() != yaml_MAPPING_END_EVENT { - n.children = append(n.children, p.parse(), p.parse()) - } - p.expect(yaml_MAPPING_END_EVENT) - return n -} - -// ---------------------------------------------------------------------------- -// Decoder, unmarshals a node into a provided value. - -type decoder struct { - doc *node - aliases map[*node]bool - mapType reflect.Type - terrors []string - strict bool - - decodeCount int - aliasCount int - aliasDepth int -} - -var ( - mapItemType = reflect.TypeOf(MapItem{}) - durationType = reflect.TypeOf(time.Duration(0)) - defaultMapType = reflect.TypeOf(map[interface{}]interface{}{}) - ifaceType = defaultMapType.Elem() - timeType = reflect.TypeOf(time.Time{}) - ptrTimeType = reflect.TypeOf(&time.Time{}) -) - -func newDecoder(strict bool) *decoder { - d := &decoder{mapType: defaultMapType, strict: strict} - d.aliases = make(map[*node]bool) - return d -} - -func (d *decoder) terror(n *node, tag string, out reflect.Value) { - if n.tag != "" { - tag = n.tag - } - value := n.value - if tag != yaml_SEQ_TAG && tag != yaml_MAP_TAG { - if len(value) > 10 { - value = " `" + value[:7] + "...`" - } else { - value = " `" + value + "`" - } - } - d.terrors = append(d.terrors, fmt.Sprintf("line %d: cannot unmarshal %s%s into %s", n.line+1, shortTag(tag), value, out.Type())) -} - -func (d *decoder) callUnmarshaler(n *node, u Unmarshaler) (good bool) { - terrlen := len(d.terrors) - err := u.UnmarshalYAML(func(v interface{}) (err error) { - defer handleErr(&err) - d.unmarshal(n, reflect.ValueOf(v)) - if len(d.terrors) > terrlen { - issues := d.terrors[terrlen:] - d.terrors = d.terrors[:terrlen] - return &TypeError{issues} - } - return nil - }) - if e, ok := err.(*TypeError); ok { - d.terrors = append(d.terrors, e.Errors...) - return false - } - if err != nil { - fail(err) - } - return true -} - -// d.prepare initializes and dereferences pointers and calls UnmarshalYAML -// if a value is found to implement it. -// It returns the initialized and dereferenced out value, whether -// unmarshalling was already done by UnmarshalYAML, and if so whether -// its types unmarshalled appropriately. -// -// If n holds a null value, prepare returns before doing anything. -func (d *decoder) prepare(n *node, out reflect.Value) (newout reflect.Value, unmarshaled, good bool) { - if n.tag == yaml_NULL_TAG || n.kind == scalarNode && n.tag == "" && (n.value == "null" || n.value == "~" || n.value == "" && n.implicit) { - return out, false, false - } - again := true - for again { - again = false - if out.Kind() == reflect.Ptr { - if out.IsNil() { - out.Set(reflect.New(out.Type().Elem())) - } - out = out.Elem() - again = true - } - if out.CanAddr() { - if u, ok := out.Addr().Interface().(Unmarshaler); ok { - good = d.callUnmarshaler(n, u) - return out, true, good - } - } - } - return out, false, false -} - -const ( - // 400,000 decode operations is ~500kb of dense object declarations, or - // ~5kb of dense object declarations with 10000% alias expansion - alias_ratio_range_low = 400000 - - // 4,000,000 decode operations is ~5MB of dense object declarations, or - // ~4.5MB of dense object declarations with 10% alias expansion - alias_ratio_range_high = 4000000 - - // alias_ratio_range is the range over which we scale allowed alias ratios - alias_ratio_range = float64(alias_ratio_range_high - alias_ratio_range_low) -) - -func allowedAliasRatio(decodeCount int) float64 { - switch { - case decodeCount <= alias_ratio_range_low: - // allow 99% to come from alias expansion for small-to-medium documents - return 0.99 - case decodeCount >= alias_ratio_range_high: - // allow 10% to come from alias expansion for very large documents - return 0.10 - default: - // scale smoothly from 99% down to 10% over the range. - // this maps to 396,000 - 400,000 allowed alias-driven decodes over the range. - // 400,000 decode operations is ~100MB of allocations in worst-case scenarios (single-item maps). - return 0.99 - 0.89*(float64(decodeCount-alias_ratio_range_low)/alias_ratio_range) - } -} - -func (d *decoder) unmarshal(n *node, out reflect.Value) (good bool) { - d.decodeCount++ - if d.aliasDepth > 0 { - d.aliasCount++ - } - if d.aliasCount > 100 && d.decodeCount > 1000 && float64(d.aliasCount)/float64(d.decodeCount) > allowedAliasRatio(d.decodeCount) { - failf("document contains excessive aliasing") - } - switch n.kind { - case documentNode: - return d.document(n, out) - case aliasNode: - return d.alias(n, out) - } - out, unmarshaled, good := d.prepare(n, out) - if unmarshaled { - return good - } - switch n.kind { - case scalarNode: - good = d.scalar(n, out) - case mappingNode: - good = d.mapping(n, out) - case sequenceNode: - good = d.sequence(n, out) - default: - panic("internal error: unknown node kind: " + strconv.Itoa(n.kind)) - } - return good -} - -func (d *decoder) document(n *node, out reflect.Value) (good bool) { - if len(n.children) == 1 { - d.doc = n - d.unmarshal(n.children[0], out) - return true - } - return false -} - -func (d *decoder) alias(n *node, out reflect.Value) (good bool) { - if d.aliases[n] { - // TODO this could actually be allowed in some circumstances. - failf("anchor '%s' value contains itself", n.value) - } - d.aliases[n] = true - d.aliasDepth++ - good = d.unmarshal(n.alias, out) - d.aliasDepth-- - delete(d.aliases, n) - return good -} - -var zeroValue reflect.Value - -func resetMap(out reflect.Value) { - for _, k := range out.MapKeys() { - out.SetMapIndex(k, zeroValue) - } -} - -func (d *decoder) scalar(n *node, out reflect.Value) bool { - var tag string - var resolved interface{} - if n.tag == "" && !n.implicit { - tag = yaml_STR_TAG - resolved = n.value - } else { - tag, resolved = resolve(n.tag, n.value) - if tag == yaml_BINARY_TAG { - data, err := base64.StdEncoding.DecodeString(resolved.(string)) - if err != nil { - failf("!!binary value contains invalid base64 data") - } - resolved = string(data) - } - } - if resolved == nil { - if out.Kind() == reflect.Map && !out.CanAddr() { - resetMap(out) - } else { - out.Set(reflect.Zero(out.Type())) - } - return true - } - if resolvedv := reflect.ValueOf(resolved); out.Type() == resolvedv.Type() { - // We've resolved to exactly the type we want, so use that. - out.Set(resolvedv) - return true - } - // Perhaps we can use the value as a TextUnmarshaler to - // set its value. - if out.CanAddr() { - u, ok := out.Addr().Interface().(encoding.TextUnmarshaler) - if ok { - var text []byte - if tag == yaml_BINARY_TAG { - text = []byte(resolved.(string)) - } else { - // We let any value be unmarshaled into TextUnmarshaler. - // That might be more lax than we'd like, but the - // TextUnmarshaler itself should bowl out any dubious values. - text = []byte(n.value) - } - err := u.UnmarshalText(text) - if err != nil { - fail(err) - } - return true - } - } - switch out.Kind() { - case reflect.String: - if tag == yaml_BINARY_TAG { - out.SetString(resolved.(string)) - return true - } - if resolved != nil { - out.SetString(n.value) - return true - } - case reflect.Interface: - if resolved == nil { - out.Set(reflect.Zero(out.Type())) - } else if tag == yaml_TIMESTAMP_TAG { - // It looks like a timestamp but for backward compatibility - // reasons we set it as a string, so that code that unmarshals - // timestamp-like values into interface{} will continue to - // see a string and not a time.Time. - // TODO(v3) Drop this. - out.Set(reflect.ValueOf(n.value)) - } else { - out.Set(reflect.ValueOf(resolved)) - } - return true - case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - switch resolved := resolved.(type) { - case int: - if !out.OverflowInt(int64(resolved)) { - out.SetInt(int64(resolved)) - return true - } - case int64: - if !out.OverflowInt(resolved) { - out.SetInt(resolved) - return true - } - case uint64: - if resolved <= math.MaxInt64 && !out.OverflowInt(int64(resolved)) { - out.SetInt(int64(resolved)) - return true - } - case float64: - if resolved <= math.MaxInt64 && !out.OverflowInt(int64(resolved)) { - out.SetInt(int64(resolved)) - return true - } - case string: - if out.Type() == durationType { - d, err := time.ParseDuration(resolved) - if err == nil { - out.SetInt(int64(d)) - return true - } - } - } - case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: - switch resolved := resolved.(type) { - case int: - if resolved >= 0 && !out.OverflowUint(uint64(resolved)) { - out.SetUint(uint64(resolved)) - return true - } - case int64: - if resolved >= 0 && !out.OverflowUint(uint64(resolved)) { - out.SetUint(uint64(resolved)) - return true - } - case uint64: - if !out.OverflowUint(uint64(resolved)) { - out.SetUint(uint64(resolved)) - return true - } - case float64: - if resolved <= math.MaxUint64 && !out.OverflowUint(uint64(resolved)) { - out.SetUint(uint64(resolved)) - return true - } - } - case reflect.Bool: - switch resolved := resolved.(type) { - case bool: - out.SetBool(resolved) - return true - } - case reflect.Float32, reflect.Float64: - switch resolved := resolved.(type) { - case int: - out.SetFloat(float64(resolved)) - return true - case int64: - out.SetFloat(float64(resolved)) - return true - case uint64: - out.SetFloat(float64(resolved)) - return true - case float64: - out.SetFloat(resolved) - return true - } - case reflect.Struct: - if resolvedv := reflect.ValueOf(resolved); out.Type() == resolvedv.Type() { - out.Set(resolvedv) - return true - } - case reflect.Ptr: - if out.Type().Elem() == reflect.TypeOf(resolved) { - // TODO DOes this make sense? When is out a Ptr except when decoding a nil value? - elem := reflect.New(out.Type().Elem()) - elem.Elem().Set(reflect.ValueOf(resolved)) - out.Set(elem) - return true - } - } - d.terror(n, tag, out) - return false -} - -func settableValueOf(i interface{}) reflect.Value { - v := reflect.ValueOf(i) - sv := reflect.New(v.Type()).Elem() - sv.Set(v) - return sv -} - -func (d *decoder) sequence(n *node, out reflect.Value) (good bool) { - l := len(n.children) - - var iface reflect.Value - switch out.Kind() { - case reflect.Slice: - out.Set(reflect.MakeSlice(out.Type(), l, l)) - case reflect.Array: - if l != out.Len() { - failf("invalid array: want %d elements but got %d", out.Len(), l) - } - case reflect.Interface: - // No type hints. Will have to use a generic sequence. - iface = out - out = settableValueOf(make([]interface{}, l)) - default: - d.terror(n, yaml_SEQ_TAG, out) - return false - } - et := out.Type().Elem() - - j := 0 - for i := 0; i < l; i++ { - e := reflect.New(et).Elem() - if ok := d.unmarshal(n.children[i], e); ok { - out.Index(j).Set(e) - j++ - } - } - if out.Kind() != reflect.Array { - out.Set(out.Slice(0, j)) - } - if iface.IsValid() { - iface.Set(out) - } - return true -} - -func (d *decoder) mapping(n *node, out reflect.Value) (good bool) { - switch out.Kind() { - case reflect.Struct: - return d.mappingStruct(n, out) - case reflect.Slice: - return d.mappingSlice(n, out) - case reflect.Map: - // okay - case reflect.Interface: - if d.mapType.Kind() == reflect.Map { - iface := out - out = reflect.MakeMap(d.mapType) - iface.Set(out) - } else { - slicev := reflect.New(d.mapType).Elem() - if !d.mappingSlice(n, slicev) { - return false - } - out.Set(slicev) - return true - } - default: - d.terror(n, yaml_MAP_TAG, out) - return false - } - outt := out.Type() - kt := outt.Key() - et := outt.Elem() - - mapType := d.mapType - if outt.Key() == ifaceType && outt.Elem() == ifaceType { - d.mapType = outt - } - - if out.IsNil() { - out.Set(reflect.MakeMap(outt)) - } - l := len(n.children) - for i := 0; i < l; i += 2 { - if isMerge(n.children[i]) { - d.merge(n.children[i+1], out) - continue - } - k := reflect.New(kt).Elem() - if d.unmarshal(n.children[i], k) { - kkind := k.Kind() - if kkind == reflect.Interface { - kkind = k.Elem().Kind() - } - if kkind == reflect.Map || kkind == reflect.Slice { - failf("invalid map key: %#v", k.Interface()) - } - e := reflect.New(et).Elem() - if d.unmarshal(n.children[i+1], e) { - d.setMapIndex(n.children[i+1], out, k, e) - } - } - } - d.mapType = mapType - return true -} - -func (d *decoder) setMapIndex(n *node, out, k, v reflect.Value) { - if d.strict && out.MapIndex(k) != zeroValue { - d.terrors = append(d.terrors, fmt.Sprintf("line %d: key %#v already set in map", n.line+1, k.Interface())) - return - } - out.SetMapIndex(k, v) -} - -func (d *decoder) mappingSlice(n *node, out reflect.Value) (good bool) { - outt := out.Type() - if outt.Elem() != mapItemType { - d.terror(n, yaml_MAP_TAG, out) - return false - } - - mapType := d.mapType - d.mapType = outt - - var slice []MapItem - var l = len(n.children) - for i := 0; i < l; i += 2 { - if isMerge(n.children[i]) { - d.merge(n.children[i+1], out) - continue - } - item := MapItem{} - k := reflect.ValueOf(&item.Key).Elem() - if d.unmarshal(n.children[i], k) { - v := reflect.ValueOf(&item.Value).Elem() - if d.unmarshal(n.children[i+1], v) { - slice = append(slice, item) - } - } - } - out.Set(reflect.ValueOf(slice)) - d.mapType = mapType - return true -} - -func (d *decoder) mappingStruct(n *node, out reflect.Value) (good bool) { - sinfo, err := getStructInfo(out.Type()) - if err != nil { - panic(err) - } - name := settableValueOf("") - l := len(n.children) - - var inlineMap reflect.Value - var elemType reflect.Type - if sinfo.InlineMap != -1 { - inlineMap = out.Field(sinfo.InlineMap) - inlineMap.Set(reflect.New(inlineMap.Type()).Elem()) - elemType = inlineMap.Type().Elem() - } - - var doneFields []bool - if d.strict { - doneFields = make([]bool, len(sinfo.FieldsList)) - } - for i := 0; i < l; i += 2 { - ni := n.children[i] - if isMerge(ni) { - d.merge(n.children[i+1], out) - continue - } - if !d.unmarshal(ni, name) { - continue - } - if info, ok := sinfo.FieldsMap[name.String()]; ok { - if d.strict { - if doneFields[info.Id] { - d.terrors = append(d.terrors, fmt.Sprintf("line %d: field %s already set in type %s", ni.line+1, name.String(), out.Type())) - continue - } - doneFields[info.Id] = true - } - var field reflect.Value - if info.Inline == nil { - field = out.Field(info.Num) - } else { - field = out.FieldByIndex(info.Inline) - } - d.unmarshal(n.children[i+1], field) - } else if sinfo.InlineMap != -1 { - if inlineMap.IsNil() { - inlineMap.Set(reflect.MakeMap(inlineMap.Type())) - } - value := reflect.New(elemType).Elem() - d.unmarshal(n.children[i+1], value) - d.setMapIndex(n.children[i+1], inlineMap, name, value) - } else if d.strict { - d.terrors = append(d.terrors, fmt.Sprintf("line %d: field %s not found in type %s", ni.line+1, name.String(), out.Type())) - } - } - return true -} - -func failWantMap() { - failf("map merge requires map or sequence of maps as the value") -} - -func (d *decoder) merge(n *node, out reflect.Value) { - switch n.kind { - case mappingNode: - d.unmarshal(n, out) - case aliasNode: - if n.alias != nil && n.alias.kind != mappingNode { - failWantMap() - } - d.unmarshal(n, out) - case sequenceNode: - // Step backwards as earlier nodes take precedence. - for i := len(n.children) - 1; i >= 0; i-- { - ni := n.children[i] - if ni.kind == aliasNode { - if ni.alias != nil && ni.alias.kind != mappingNode { - failWantMap() - } - } else if ni.kind != mappingNode { - failWantMap() - } - d.unmarshal(ni, out) - } - default: - failWantMap() - } -} - -func isMerge(n *node) bool { - return n.kind == scalarNode && n.value == "<<" && (n.implicit == true || n.tag == yaml_MERGE_TAG) -} diff --git a/vendor/go.yaml.in/yaml/v2/emitterc.go b/vendor/go.yaml.in/yaml/v2/emitterc.go deleted file mode 100644 index a1c2cc526..000000000 --- a/vendor/go.yaml.in/yaml/v2/emitterc.go +++ /dev/null @@ -1,1685 +0,0 @@ -package yaml - -import ( - "bytes" - "fmt" -) - -// Flush the buffer if needed. -func flush(emitter *yaml_emitter_t) bool { - if emitter.buffer_pos+5 >= len(emitter.buffer) { - return yaml_emitter_flush(emitter) - } - return true -} - -// Put a character to the output buffer. -func put(emitter *yaml_emitter_t, value byte) bool { - if emitter.buffer_pos+5 >= len(emitter.buffer) && !yaml_emitter_flush(emitter) { - return false - } - emitter.buffer[emitter.buffer_pos] = value - emitter.buffer_pos++ - emitter.column++ - return true -} - -// Put a line break to the output buffer. -func put_break(emitter *yaml_emitter_t) bool { - if emitter.buffer_pos+5 >= len(emitter.buffer) && !yaml_emitter_flush(emitter) { - return false - } - switch emitter.line_break { - case yaml_CR_BREAK: - emitter.buffer[emitter.buffer_pos] = '\r' - emitter.buffer_pos += 1 - case yaml_LN_BREAK: - emitter.buffer[emitter.buffer_pos] = '\n' - emitter.buffer_pos += 1 - case yaml_CRLN_BREAK: - emitter.buffer[emitter.buffer_pos+0] = '\r' - emitter.buffer[emitter.buffer_pos+1] = '\n' - emitter.buffer_pos += 2 - default: - panic("unknown line break setting") - } - emitter.column = 0 - emitter.line++ - return true -} - -// Copy a character from a string into buffer. -func write(emitter *yaml_emitter_t, s []byte, i *int) bool { - if emitter.buffer_pos+5 >= len(emitter.buffer) && !yaml_emitter_flush(emitter) { - return false - } - p := emitter.buffer_pos - w := width(s[*i]) - switch w { - case 4: - emitter.buffer[p+3] = s[*i+3] - fallthrough - case 3: - emitter.buffer[p+2] = s[*i+2] - fallthrough - case 2: - emitter.buffer[p+1] = s[*i+1] - fallthrough - case 1: - emitter.buffer[p+0] = s[*i+0] - default: - panic("unknown character width") - } - emitter.column++ - emitter.buffer_pos += w - *i += w - return true -} - -// Write a whole string into buffer. -func write_all(emitter *yaml_emitter_t, s []byte) bool { - for i := 0; i < len(s); { - if !write(emitter, s, &i) { - return false - } - } - return true -} - -// Copy a line break character from a string into buffer. -func write_break(emitter *yaml_emitter_t, s []byte, i *int) bool { - if s[*i] == '\n' { - if !put_break(emitter) { - return false - } - *i++ - } else { - if !write(emitter, s, i) { - return false - } - emitter.column = 0 - emitter.line++ - } - return true -} - -// Set an emitter error and return false. -func yaml_emitter_set_emitter_error(emitter *yaml_emitter_t, problem string) bool { - emitter.error = yaml_EMITTER_ERROR - emitter.problem = problem - return false -} - -// Emit an event. -func yaml_emitter_emit(emitter *yaml_emitter_t, event *yaml_event_t) bool { - emitter.events = append(emitter.events, *event) - for !yaml_emitter_need_more_events(emitter) { - event := &emitter.events[emitter.events_head] - if !yaml_emitter_analyze_event(emitter, event) { - return false - } - if !yaml_emitter_state_machine(emitter, event) { - return false - } - yaml_event_delete(event) - emitter.events_head++ - } - return true -} - -// Check if we need to accumulate more events before emitting. -// -// We accumulate extra -// - 1 event for DOCUMENT-START -// - 2 events for SEQUENCE-START -// - 3 events for MAPPING-START -// -func yaml_emitter_need_more_events(emitter *yaml_emitter_t) bool { - if emitter.events_head == len(emitter.events) { - return true - } - var accumulate int - switch emitter.events[emitter.events_head].typ { - case yaml_DOCUMENT_START_EVENT: - accumulate = 1 - break - case yaml_SEQUENCE_START_EVENT: - accumulate = 2 - break - case yaml_MAPPING_START_EVENT: - accumulate = 3 - break - default: - return false - } - if len(emitter.events)-emitter.events_head > accumulate { - return false - } - var level int - for i := emitter.events_head; i < len(emitter.events); i++ { - switch emitter.events[i].typ { - case yaml_STREAM_START_EVENT, yaml_DOCUMENT_START_EVENT, yaml_SEQUENCE_START_EVENT, yaml_MAPPING_START_EVENT: - level++ - case yaml_STREAM_END_EVENT, yaml_DOCUMENT_END_EVENT, yaml_SEQUENCE_END_EVENT, yaml_MAPPING_END_EVENT: - level-- - } - if level == 0 { - return false - } - } - return true -} - -// Append a directive to the directives stack. -func yaml_emitter_append_tag_directive(emitter *yaml_emitter_t, value *yaml_tag_directive_t, allow_duplicates bool) bool { - for i := 0; i < len(emitter.tag_directives); i++ { - if bytes.Equal(value.handle, emitter.tag_directives[i].handle) { - if allow_duplicates { - return true - } - return yaml_emitter_set_emitter_error(emitter, "duplicate %TAG directive") - } - } - - // [Go] Do we actually need to copy this given garbage collection - // and the lack of deallocating destructors? - tag_copy := yaml_tag_directive_t{ - handle: make([]byte, len(value.handle)), - prefix: make([]byte, len(value.prefix)), - } - copy(tag_copy.handle, value.handle) - copy(tag_copy.prefix, value.prefix) - emitter.tag_directives = append(emitter.tag_directives, tag_copy) - return true -} - -// Increase the indentation level. -func yaml_emitter_increase_indent(emitter *yaml_emitter_t, flow, indentless bool) bool { - emitter.indents = append(emitter.indents, emitter.indent) - if emitter.indent < 0 { - if flow { - emitter.indent = emitter.best_indent - } else { - emitter.indent = 0 - } - } else if !indentless { - emitter.indent += emitter.best_indent - } - return true -} - -// State dispatcher. -func yaml_emitter_state_machine(emitter *yaml_emitter_t, event *yaml_event_t) bool { - switch emitter.state { - default: - case yaml_EMIT_STREAM_START_STATE: - return yaml_emitter_emit_stream_start(emitter, event) - - case yaml_EMIT_FIRST_DOCUMENT_START_STATE: - return yaml_emitter_emit_document_start(emitter, event, true) - - case yaml_EMIT_DOCUMENT_START_STATE: - return yaml_emitter_emit_document_start(emitter, event, false) - - case yaml_EMIT_DOCUMENT_CONTENT_STATE: - return yaml_emitter_emit_document_content(emitter, event) - - case yaml_EMIT_DOCUMENT_END_STATE: - return yaml_emitter_emit_document_end(emitter, event) - - case yaml_EMIT_FLOW_SEQUENCE_FIRST_ITEM_STATE: - return yaml_emitter_emit_flow_sequence_item(emitter, event, true) - - case yaml_EMIT_FLOW_SEQUENCE_ITEM_STATE: - return yaml_emitter_emit_flow_sequence_item(emitter, event, false) - - case yaml_EMIT_FLOW_MAPPING_FIRST_KEY_STATE: - return yaml_emitter_emit_flow_mapping_key(emitter, event, true) - - case yaml_EMIT_FLOW_MAPPING_KEY_STATE: - return yaml_emitter_emit_flow_mapping_key(emitter, event, false) - - case yaml_EMIT_FLOW_MAPPING_SIMPLE_VALUE_STATE: - return yaml_emitter_emit_flow_mapping_value(emitter, event, true) - - case yaml_EMIT_FLOW_MAPPING_VALUE_STATE: - return yaml_emitter_emit_flow_mapping_value(emitter, event, false) - - case yaml_EMIT_BLOCK_SEQUENCE_FIRST_ITEM_STATE: - return yaml_emitter_emit_block_sequence_item(emitter, event, true) - - case yaml_EMIT_BLOCK_SEQUENCE_ITEM_STATE: - return yaml_emitter_emit_block_sequence_item(emitter, event, false) - - case yaml_EMIT_BLOCK_MAPPING_FIRST_KEY_STATE: - return yaml_emitter_emit_block_mapping_key(emitter, event, true) - - case yaml_EMIT_BLOCK_MAPPING_KEY_STATE: - return yaml_emitter_emit_block_mapping_key(emitter, event, false) - - case yaml_EMIT_BLOCK_MAPPING_SIMPLE_VALUE_STATE: - return yaml_emitter_emit_block_mapping_value(emitter, event, true) - - case yaml_EMIT_BLOCK_MAPPING_VALUE_STATE: - return yaml_emitter_emit_block_mapping_value(emitter, event, false) - - case yaml_EMIT_END_STATE: - return yaml_emitter_set_emitter_error(emitter, "expected nothing after STREAM-END") - } - panic("invalid emitter state") -} - -// Expect STREAM-START. -func yaml_emitter_emit_stream_start(emitter *yaml_emitter_t, event *yaml_event_t) bool { - if event.typ != yaml_STREAM_START_EVENT { - return yaml_emitter_set_emitter_error(emitter, "expected STREAM-START") - } - if emitter.encoding == yaml_ANY_ENCODING { - emitter.encoding = event.encoding - if emitter.encoding == yaml_ANY_ENCODING { - emitter.encoding = yaml_UTF8_ENCODING - } - } - if emitter.best_indent < 2 || emitter.best_indent > 9 { - emitter.best_indent = 2 - } - if emitter.best_width >= 0 && emitter.best_width <= emitter.best_indent*2 { - emitter.best_width = 80 - } - if emitter.best_width < 0 { - emitter.best_width = 1<<31 - 1 - } - if emitter.line_break == yaml_ANY_BREAK { - emitter.line_break = yaml_LN_BREAK - } - - emitter.indent = -1 - emitter.line = 0 - emitter.column = 0 - emitter.whitespace = true - emitter.indention = true - - if emitter.encoding != yaml_UTF8_ENCODING { - if !yaml_emitter_write_bom(emitter) { - return false - } - } - emitter.state = yaml_EMIT_FIRST_DOCUMENT_START_STATE - return true -} - -// Expect DOCUMENT-START or STREAM-END. -func yaml_emitter_emit_document_start(emitter *yaml_emitter_t, event *yaml_event_t, first bool) bool { - - if event.typ == yaml_DOCUMENT_START_EVENT { - - if event.version_directive != nil { - if !yaml_emitter_analyze_version_directive(emitter, event.version_directive) { - return false - } - } - - for i := 0; i < len(event.tag_directives); i++ { - tag_directive := &event.tag_directives[i] - if !yaml_emitter_analyze_tag_directive(emitter, tag_directive) { - return false - } - if !yaml_emitter_append_tag_directive(emitter, tag_directive, false) { - return false - } - } - - for i := 0; i < len(default_tag_directives); i++ { - tag_directive := &default_tag_directives[i] - if !yaml_emitter_append_tag_directive(emitter, tag_directive, true) { - return false - } - } - - implicit := event.implicit - if !first || emitter.canonical { - implicit = false - } - - if emitter.open_ended && (event.version_directive != nil || len(event.tag_directives) > 0) { - if !yaml_emitter_write_indicator(emitter, []byte("..."), true, false, false) { - return false - } - if !yaml_emitter_write_indent(emitter) { - return false - } - } - - if event.version_directive != nil { - implicit = false - if !yaml_emitter_write_indicator(emitter, []byte("%YAML"), true, false, false) { - return false - } - if !yaml_emitter_write_indicator(emitter, []byte("1.1"), true, false, false) { - return false - } - if !yaml_emitter_write_indent(emitter) { - return false - } - } - - if len(event.tag_directives) > 0 { - implicit = false - for i := 0; i < len(event.tag_directives); i++ { - tag_directive := &event.tag_directives[i] - if !yaml_emitter_write_indicator(emitter, []byte("%TAG"), true, false, false) { - return false - } - if !yaml_emitter_write_tag_handle(emitter, tag_directive.handle) { - return false - } - if !yaml_emitter_write_tag_content(emitter, tag_directive.prefix, true) { - return false - } - if !yaml_emitter_write_indent(emitter) { - return false - } - } - } - - if yaml_emitter_check_empty_document(emitter) { - implicit = false - } - if !implicit { - if !yaml_emitter_write_indent(emitter) { - return false - } - if !yaml_emitter_write_indicator(emitter, []byte("---"), true, false, false) { - return false - } - if emitter.canonical { - if !yaml_emitter_write_indent(emitter) { - return false - } - } - } - - emitter.state = yaml_EMIT_DOCUMENT_CONTENT_STATE - return true - } - - if event.typ == yaml_STREAM_END_EVENT { - if emitter.open_ended { - if !yaml_emitter_write_indicator(emitter, []byte("..."), true, false, false) { - return false - } - if !yaml_emitter_write_indent(emitter) { - return false - } - } - if !yaml_emitter_flush(emitter) { - return false - } - emitter.state = yaml_EMIT_END_STATE - return true - } - - return yaml_emitter_set_emitter_error(emitter, "expected DOCUMENT-START or STREAM-END") -} - -// Expect the root node. -func yaml_emitter_emit_document_content(emitter *yaml_emitter_t, event *yaml_event_t) bool { - emitter.states = append(emitter.states, yaml_EMIT_DOCUMENT_END_STATE) - return yaml_emitter_emit_node(emitter, event, true, false, false, false) -} - -// Expect DOCUMENT-END. -func yaml_emitter_emit_document_end(emitter *yaml_emitter_t, event *yaml_event_t) bool { - if event.typ != yaml_DOCUMENT_END_EVENT { - return yaml_emitter_set_emitter_error(emitter, "expected DOCUMENT-END") - } - if !yaml_emitter_write_indent(emitter) { - return false - } - if !event.implicit { - // [Go] Allocate the slice elsewhere. - if !yaml_emitter_write_indicator(emitter, []byte("..."), true, false, false) { - return false - } - if !yaml_emitter_write_indent(emitter) { - return false - } - } - if !yaml_emitter_flush(emitter) { - return false - } - emitter.state = yaml_EMIT_DOCUMENT_START_STATE - emitter.tag_directives = emitter.tag_directives[:0] - return true -} - -// Expect a flow item node. -func yaml_emitter_emit_flow_sequence_item(emitter *yaml_emitter_t, event *yaml_event_t, first bool) bool { - if first { - if !yaml_emitter_write_indicator(emitter, []byte{'['}, true, true, false) { - return false - } - if !yaml_emitter_increase_indent(emitter, true, false) { - return false - } - emitter.flow_level++ - } - - if event.typ == yaml_SEQUENCE_END_EVENT { - emitter.flow_level-- - emitter.indent = emitter.indents[len(emitter.indents)-1] - emitter.indents = emitter.indents[:len(emitter.indents)-1] - if emitter.canonical && !first { - if !yaml_emitter_write_indicator(emitter, []byte{','}, false, false, false) { - return false - } - if !yaml_emitter_write_indent(emitter) { - return false - } - } - if !yaml_emitter_write_indicator(emitter, []byte{']'}, false, false, false) { - return false - } - emitter.state = emitter.states[len(emitter.states)-1] - emitter.states = emitter.states[:len(emitter.states)-1] - - return true - } - - if !first { - if !yaml_emitter_write_indicator(emitter, []byte{','}, false, false, false) { - return false - } - } - - if emitter.canonical || emitter.column > emitter.best_width { - if !yaml_emitter_write_indent(emitter) { - return false - } - } - emitter.states = append(emitter.states, yaml_EMIT_FLOW_SEQUENCE_ITEM_STATE) - return yaml_emitter_emit_node(emitter, event, false, true, false, false) -} - -// Expect a flow key node. -func yaml_emitter_emit_flow_mapping_key(emitter *yaml_emitter_t, event *yaml_event_t, first bool) bool { - if first { - if !yaml_emitter_write_indicator(emitter, []byte{'{'}, true, true, false) { - return false - } - if !yaml_emitter_increase_indent(emitter, true, false) { - return false - } - emitter.flow_level++ - } - - if event.typ == yaml_MAPPING_END_EVENT { - emitter.flow_level-- - emitter.indent = emitter.indents[len(emitter.indents)-1] - emitter.indents = emitter.indents[:len(emitter.indents)-1] - if emitter.canonical && !first { - if !yaml_emitter_write_indicator(emitter, []byte{','}, false, false, false) { - return false - } - if !yaml_emitter_write_indent(emitter) { - return false - } - } - if !yaml_emitter_write_indicator(emitter, []byte{'}'}, false, false, false) { - return false - } - emitter.state = emitter.states[len(emitter.states)-1] - emitter.states = emitter.states[:len(emitter.states)-1] - return true - } - - if !first { - if !yaml_emitter_write_indicator(emitter, []byte{','}, false, false, false) { - return false - } - } - if emitter.canonical || emitter.column > emitter.best_width { - if !yaml_emitter_write_indent(emitter) { - return false - } - } - - if !emitter.canonical && yaml_emitter_check_simple_key(emitter) { - emitter.states = append(emitter.states, yaml_EMIT_FLOW_MAPPING_SIMPLE_VALUE_STATE) - return yaml_emitter_emit_node(emitter, event, false, false, true, true) - } - if !yaml_emitter_write_indicator(emitter, []byte{'?'}, true, false, false) { - return false - } - emitter.states = append(emitter.states, yaml_EMIT_FLOW_MAPPING_VALUE_STATE) - return yaml_emitter_emit_node(emitter, event, false, false, true, false) -} - -// Expect a flow value node. -func yaml_emitter_emit_flow_mapping_value(emitter *yaml_emitter_t, event *yaml_event_t, simple bool) bool { - if simple { - if !yaml_emitter_write_indicator(emitter, []byte{':'}, false, false, false) { - return false - } - } else { - if emitter.canonical || emitter.column > emitter.best_width { - if !yaml_emitter_write_indent(emitter) { - return false - } - } - if !yaml_emitter_write_indicator(emitter, []byte{':'}, true, false, false) { - return false - } - } - emitter.states = append(emitter.states, yaml_EMIT_FLOW_MAPPING_KEY_STATE) - return yaml_emitter_emit_node(emitter, event, false, false, true, false) -} - -// Expect a block item node. -func yaml_emitter_emit_block_sequence_item(emitter *yaml_emitter_t, event *yaml_event_t, first bool) bool { - if first { - if !yaml_emitter_increase_indent(emitter, false, emitter.mapping_context && !emitter.indention) { - return false - } - } - if event.typ == yaml_SEQUENCE_END_EVENT { - emitter.indent = emitter.indents[len(emitter.indents)-1] - emitter.indents = emitter.indents[:len(emitter.indents)-1] - emitter.state = emitter.states[len(emitter.states)-1] - emitter.states = emitter.states[:len(emitter.states)-1] - return true - } - if !yaml_emitter_write_indent(emitter) { - return false - } - if !yaml_emitter_write_indicator(emitter, []byte{'-'}, true, false, true) { - return false - } - emitter.states = append(emitter.states, yaml_EMIT_BLOCK_SEQUENCE_ITEM_STATE) - return yaml_emitter_emit_node(emitter, event, false, true, false, false) -} - -// Expect a block key node. -func yaml_emitter_emit_block_mapping_key(emitter *yaml_emitter_t, event *yaml_event_t, first bool) bool { - if first { - if !yaml_emitter_increase_indent(emitter, false, false) { - return false - } - } - if event.typ == yaml_MAPPING_END_EVENT { - emitter.indent = emitter.indents[len(emitter.indents)-1] - emitter.indents = emitter.indents[:len(emitter.indents)-1] - emitter.state = emitter.states[len(emitter.states)-1] - emitter.states = emitter.states[:len(emitter.states)-1] - return true - } - if !yaml_emitter_write_indent(emitter) { - return false - } - if yaml_emitter_check_simple_key(emitter) { - emitter.states = append(emitter.states, yaml_EMIT_BLOCK_MAPPING_SIMPLE_VALUE_STATE) - return yaml_emitter_emit_node(emitter, event, false, false, true, true) - } - if !yaml_emitter_write_indicator(emitter, []byte{'?'}, true, false, true) { - return false - } - emitter.states = append(emitter.states, yaml_EMIT_BLOCK_MAPPING_VALUE_STATE) - return yaml_emitter_emit_node(emitter, event, false, false, true, false) -} - -// Expect a block value node. -func yaml_emitter_emit_block_mapping_value(emitter *yaml_emitter_t, event *yaml_event_t, simple bool) bool { - if simple { - if !yaml_emitter_write_indicator(emitter, []byte{':'}, false, false, false) { - return false - } - } else { - if !yaml_emitter_write_indent(emitter) { - return false - } - if !yaml_emitter_write_indicator(emitter, []byte{':'}, true, false, true) { - return false - } - } - emitter.states = append(emitter.states, yaml_EMIT_BLOCK_MAPPING_KEY_STATE) - return yaml_emitter_emit_node(emitter, event, false, false, true, false) -} - -// Expect a node. -func yaml_emitter_emit_node(emitter *yaml_emitter_t, event *yaml_event_t, - root bool, sequence bool, mapping bool, simple_key bool) bool { - - emitter.root_context = root - emitter.sequence_context = sequence - emitter.mapping_context = mapping - emitter.simple_key_context = simple_key - - switch event.typ { - case yaml_ALIAS_EVENT: - return yaml_emitter_emit_alias(emitter, event) - case yaml_SCALAR_EVENT: - return yaml_emitter_emit_scalar(emitter, event) - case yaml_SEQUENCE_START_EVENT: - return yaml_emitter_emit_sequence_start(emitter, event) - case yaml_MAPPING_START_EVENT: - return yaml_emitter_emit_mapping_start(emitter, event) - default: - return yaml_emitter_set_emitter_error(emitter, - fmt.Sprintf("expected SCALAR, SEQUENCE-START, MAPPING-START, or ALIAS, but got %v", event.typ)) - } -} - -// Expect ALIAS. -func yaml_emitter_emit_alias(emitter *yaml_emitter_t, event *yaml_event_t) bool { - if !yaml_emitter_process_anchor(emitter) { - return false - } - emitter.state = emitter.states[len(emitter.states)-1] - emitter.states = emitter.states[:len(emitter.states)-1] - return true -} - -// Expect SCALAR. -func yaml_emitter_emit_scalar(emitter *yaml_emitter_t, event *yaml_event_t) bool { - if !yaml_emitter_select_scalar_style(emitter, event) { - return false - } - if !yaml_emitter_process_anchor(emitter) { - return false - } - if !yaml_emitter_process_tag(emitter) { - return false - } - if !yaml_emitter_increase_indent(emitter, true, false) { - return false - } - if !yaml_emitter_process_scalar(emitter) { - return false - } - emitter.indent = emitter.indents[len(emitter.indents)-1] - emitter.indents = emitter.indents[:len(emitter.indents)-1] - emitter.state = emitter.states[len(emitter.states)-1] - emitter.states = emitter.states[:len(emitter.states)-1] - return true -} - -// Expect SEQUENCE-START. -func yaml_emitter_emit_sequence_start(emitter *yaml_emitter_t, event *yaml_event_t) bool { - if !yaml_emitter_process_anchor(emitter) { - return false - } - if !yaml_emitter_process_tag(emitter) { - return false - } - if emitter.flow_level > 0 || emitter.canonical || event.sequence_style() == yaml_FLOW_SEQUENCE_STYLE || - yaml_emitter_check_empty_sequence(emitter) { - emitter.state = yaml_EMIT_FLOW_SEQUENCE_FIRST_ITEM_STATE - } else { - emitter.state = yaml_EMIT_BLOCK_SEQUENCE_FIRST_ITEM_STATE - } - return true -} - -// Expect MAPPING-START. -func yaml_emitter_emit_mapping_start(emitter *yaml_emitter_t, event *yaml_event_t) bool { - if !yaml_emitter_process_anchor(emitter) { - return false - } - if !yaml_emitter_process_tag(emitter) { - return false - } - if emitter.flow_level > 0 || emitter.canonical || event.mapping_style() == yaml_FLOW_MAPPING_STYLE || - yaml_emitter_check_empty_mapping(emitter) { - emitter.state = yaml_EMIT_FLOW_MAPPING_FIRST_KEY_STATE - } else { - emitter.state = yaml_EMIT_BLOCK_MAPPING_FIRST_KEY_STATE - } - return true -} - -// Check if the document content is an empty scalar. -func yaml_emitter_check_empty_document(emitter *yaml_emitter_t) bool { - return false // [Go] Huh? -} - -// Check if the next events represent an empty sequence. -func yaml_emitter_check_empty_sequence(emitter *yaml_emitter_t) bool { - if len(emitter.events)-emitter.events_head < 2 { - return false - } - return emitter.events[emitter.events_head].typ == yaml_SEQUENCE_START_EVENT && - emitter.events[emitter.events_head+1].typ == yaml_SEQUENCE_END_EVENT -} - -// Check if the next events represent an empty mapping. -func yaml_emitter_check_empty_mapping(emitter *yaml_emitter_t) bool { - if len(emitter.events)-emitter.events_head < 2 { - return false - } - return emitter.events[emitter.events_head].typ == yaml_MAPPING_START_EVENT && - emitter.events[emitter.events_head+1].typ == yaml_MAPPING_END_EVENT -} - -// Check if the next node can be expressed as a simple key. -func yaml_emitter_check_simple_key(emitter *yaml_emitter_t) bool { - length := 0 - switch emitter.events[emitter.events_head].typ { - case yaml_ALIAS_EVENT: - length += len(emitter.anchor_data.anchor) - case yaml_SCALAR_EVENT: - if emitter.scalar_data.multiline { - return false - } - length += len(emitter.anchor_data.anchor) + - len(emitter.tag_data.handle) + - len(emitter.tag_data.suffix) + - len(emitter.scalar_data.value) - case yaml_SEQUENCE_START_EVENT: - if !yaml_emitter_check_empty_sequence(emitter) { - return false - } - length += len(emitter.anchor_data.anchor) + - len(emitter.tag_data.handle) + - len(emitter.tag_data.suffix) - case yaml_MAPPING_START_EVENT: - if !yaml_emitter_check_empty_mapping(emitter) { - return false - } - length += len(emitter.anchor_data.anchor) + - len(emitter.tag_data.handle) + - len(emitter.tag_data.suffix) - default: - return false - } - return length <= 128 -} - -// Determine an acceptable scalar style. -func yaml_emitter_select_scalar_style(emitter *yaml_emitter_t, event *yaml_event_t) bool { - - no_tag := len(emitter.tag_data.handle) == 0 && len(emitter.tag_data.suffix) == 0 - if no_tag && !event.implicit && !event.quoted_implicit { - return yaml_emitter_set_emitter_error(emitter, "neither tag nor implicit flags are specified") - } - - style := event.scalar_style() - if style == yaml_ANY_SCALAR_STYLE { - style = yaml_PLAIN_SCALAR_STYLE - } - if emitter.canonical { - style = yaml_DOUBLE_QUOTED_SCALAR_STYLE - } - if emitter.simple_key_context && emitter.scalar_data.multiline { - style = yaml_DOUBLE_QUOTED_SCALAR_STYLE - } - - if style == yaml_PLAIN_SCALAR_STYLE { - if emitter.flow_level > 0 && !emitter.scalar_data.flow_plain_allowed || - emitter.flow_level == 0 && !emitter.scalar_data.block_plain_allowed { - style = yaml_SINGLE_QUOTED_SCALAR_STYLE - } - if len(emitter.scalar_data.value) == 0 && (emitter.flow_level > 0 || emitter.simple_key_context) { - style = yaml_SINGLE_QUOTED_SCALAR_STYLE - } - if no_tag && !event.implicit { - style = yaml_SINGLE_QUOTED_SCALAR_STYLE - } - } - if style == yaml_SINGLE_QUOTED_SCALAR_STYLE { - if !emitter.scalar_data.single_quoted_allowed { - style = yaml_DOUBLE_QUOTED_SCALAR_STYLE - } - } - if style == yaml_LITERAL_SCALAR_STYLE || style == yaml_FOLDED_SCALAR_STYLE { - if !emitter.scalar_data.block_allowed || emitter.flow_level > 0 || emitter.simple_key_context { - style = yaml_DOUBLE_QUOTED_SCALAR_STYLE - } - } - - if no_tag && !event.quoted_implicit && style != yaml_PLAIN_SCALAR_STYLE { - emitter.tag_data.handle = []byte{'!'} - } - emitter.scalar_data.style = style - return true -} - -// Write an anchor. -func yaml_emitter_process_anchor(emitter *yaml_emitter_t) bool { - if emitter.anchor_data.anchor == nil { - return true - } - c := []byte{'&'} - if emitter.anchor_data.alias { - c[0] = '*' - } - if !yaml_emitter_write_indicator(emitter, c, true, false, false) { - return false - } - return yaml_emitter_write_anchor(emitter, emitter.anchor_data.anchor) -} - -// Write a tag. -func yaml_emitter_process_tag(emitter *yaml_emitter_t) bool { - if len(emitter.tag_data.handle) == 0 && len(emitter.tag_data.suffix) == 0 { - return true - } - if len(emitter.tag_data.handle) > 0 { - if !yaml_emitter_write_tag_handle(emitter, emitter.tag_data.handle) { - return false - } - if len(emitter.tag_data.suffix) > 0 { - if !yaml_emitter_write_tag_content(emitter, emitter.tag_data.suffix, false) { - return false - } - } - } else { - // [Go] Allocate these slices elsewhere. - if !yaml_emitter_write_indicator(emitter, []byte("!<"), true, false, false) { - return false - } - if !yaml_emitter_write_tag_content(emitter, emitter.tag_data.suffix, false) { - return false - } - if !yaml_emitter_write_indicator(emitter, []byte{'>'}, false, false, false) { - return false - } - } - return true -} - -// Write a scalar. -func yaml_emitter_process_scalar(emitter *yaml_emitter_t) bool { - switch emitter.scalar_data.style { - case yaml_PLAIN_SCALAR_STYLE: - return yaml_emitter_write_plain_scalar(emitter, emitter.scalar_data.value, !emitter.simple_key_context) - - case yaml_SINGLE_QUOTED_SCALAR_STYLE: - return yaml_emitter_write_single_quoted_scalar(emitter, emitter.scalar_data.value, !emitter.simple_key_context) - - case yaml_DOUBLE_QUOTED_SCALAR_STYLE: - return yaml_emitter_write_double_quoted_scalar(emitter, emitter.scalar_data.value, !emitter.simple_key_context) - - case yaml_LITERAL_SCALAR_STYLE: - return yaml_emitter_write_literal_scalar(emitter, emitter.scalar_data.value) - - case yaml_FOLDED_SCALAR_STYLE: - return yaml_emitter_write_folded_scalar(emitter, emitter.scalar_data.value) - } - panic("unknown scalar style") -} - -// Check if a %YAML directive is valid. -func yaml_emitter_analyze_version_directive(emitter *yaml_emitter_t, version_directive *yaml_version_directive_t) bool { - if version_directive.major != 1 || version_directive.minor != 1 { - return yaml_emitter_set_emitter_error(emitter, "incompatible %YAML directive") - } - return true -} - -// Check if a %TAG directive is valid. -func yaml_emitter_analyze_tag_directive(emitter *yaml_emitter_t, tag_directive *yaml_tag_directive_t) bool { - handle := tag_directive.handle - prefix := tag_directive.prefix - if len(handle) == 0 { - return yaml_emitter_set_emitter_error(emitter, "tag handle must not be empty") - } - if handle[0] != '!' { - return yaml_emitter_set_emitter_error(emitter, "tag handle must start with '!'") - } - if handle[len(handle)-1] != '!' { - return yaml_emitter_set_emitter_error(emitter, "tag handle must end with '!'") - } - for i := 1; i < len(handle)-1; i += width(handle[i]) { - if !is_alpha(handle, i) { - return yaml_emitter_set_emitter_error(emitter, "tag handle must contain alphanumerical characters only") - } - } - if len(prefix) == 0 { - return yaml_emitter_set_emitter_error(emitter, "tag prefix must not be empty") - } - return true -} - -// Check if an anchor is valid. -func yaml_emitter_analyze_anchor(emitter *yaml_emitter_t, anchor []byte, alias bool) bool { - if len(anchor) == 0 { - problem := "anchor value must not be empty" - if alias { - problem = "alias value must not be empty" - } - return yaml_emitter_set_emitter_error(emitter, problem) - } - for i := 0; i < len(anchor); i += width(anchor[i]) { - if !is_alpha(anchor, i) { - problem := "anchor value must contain alphanumerical characters only" - if alias { - problem = "alias value must contain alphanumerical characters only" - } - return yaml_emitter_set_emitter_error(emitter, problem) - } - } - emitter.anchor_data.anchor = anchor - emitter.anchor_data.alias = alias - return true -} - -// Check if a tag is valid. -func yaml_emitter_analyze_tag(emitter *yaml_emitter_t, tag []byte) bool { - if len(tag) == 0 { - return yaml_emitter_set_emitter_error(emitter, "tag value must not be empty") - } - for i := 0; i < len(emitter.tag_directives); i++ { - tag_directive := &emitter.tag_directives[i] - if bytes.HasPrefix(tag, tag_directive.prefix) { - emitter.tag_data.handle = tag_directive.handle - emitter.tag_data.suffix = tag[len(tag_directive.prefix):] - return true - } - } - emitter.tag_data.suffix = tag - return true -} - -// Check if a scalar is valid. -func yaml_emitter_analyze_scalar(emitter *yaml_emitter_t, value []byte) bool { - var ( - block_indicators = false - flow_indicators = false - line_breaks = false - special_characters = false - - leading_space = false - leading_break = false - trailing_space = false - trailing_break = false - break_space = false - space_break = false - - preceded_by_whitespace = false - followed_by_whitespace = false - previous_space = false - previous_break = false - ) - - emitter.scalar_data.value = value - - if len(value) == 0 { - emitter.scalar_data.multiline = false - emitter.scalar_data.flow_plain_allowed = false - emitter.scalar_data.block_plain_allowed = true - emitter.scalar_data.single_quoted_allowed = true - emitter.scalar_data.block_allowed = false - return true - } - - if len(value) >= 3 && ((value[0] == '-' && value[1] == '-' && value[2] == '-') || (value[0] == '.' && value[1] == '.' && value[2] == '.')) { - block_indicators = true - flow_indicators = true - } - - preceded_by_whitespace = true - for i, w := 0, 0; i < len(value); i += w { - w = width(value[i]) - followed_by_whitespace = i+w >= len(value) || is_blank(value, i+w) - - if i == 0 { - switch value[i] { - case '#', ',', '[', ']', '{', '}', '&', '*', '!', '|', '>', '\'', '"', '%', '@', '`': - flow_indicators = true - block_indicators = true - case '?', ':': - flow_indicators = true - if followed_by_whitespace { - block_indicators = true - } - case '-': - if followed_by_whitespace { - flow_indicators = true - block_indicators = true - } - } - } else { - switch value[i] { - case ',', '?', '[', ']', '{', '}': - flow_indicators = true - case ':': - flow_indicators = true - if followed_by_whitespace { - block_indicators = true - } - case '#': - if preceded_by_whitespace { - flow_indicators = true - block_indicators = true - } - } - } - - if !is_printable(value, i) || !is_ascii(value, i) && !emitter.unicode { - special_characters = true - } - if is_space(value, i) { - if i == 0 { - leading_space = true - } - if i+width(value[i]) == len(value) { - trailing_space = true - } - if previous_break { - break_space = true - } - previous_space = true - previous_break = false - } else if is_break(value, i) { - line_breaks = true - if i == 0 { - leading_break = true - } - if i+width(value[i]) == len(value) { - trailing_break = true - } - if previous_space { - space_break = true - } - previous_space = false - previous_break = true - } else { - previous_space = false - previous_break = false - } - - // [Go]: Why 'z'? Couldn't be the end of the string as that's the loop condition. - preceded_by_whitespace = is_blankz(value, i) - } - - emitter.scalar_data.multiline = line_breaks - emitter.scalar_data.flow_plain_allowed = true - emitter.scalar_data.block_plain_allowed = true - emitter.scalar_data.single_quoted_allowed = true - emitter.scalar_data.block_allowed = true - - if leading_space || leading_break || trailing_space || trailing_break { - emitter.scalar_data.flow_plain_allowed = false - emitter.scalar_data.block_plain_allowed = false - } - if trailing_space { - emitter.scalar_data.block_allowed = false - } - if break_space { - emitter.scalar_data.flow_plain_allowed = false - emitter.scalar_data.block_plain_allowed = false - emitter.scalar_data.single_quoted_allowed = false - } - if space_break || special_characters { - emitter.scalar_data.flow_plain_allowed = false - emitter.scalar_data.block_plain_allowed = false - emitter.scalar_data.single_quoted_allowed = false - emitter.scalar_data.block_allowed = false - } - if line_breaks { - emitter.scalar_data.flow_plain_allowed = false - emitter.scalar_data.block_plain_allowed = false - } - if flow_indicators { - emitter.scalar_data.flow_plain_allowed = false - } - if block_indicators { - emitter.scalar_data.block_plain_allowed = false - } - return true -} - -// Check if the event data is valid. -func yaml_emitter_analyze_event(emitter *yaml_emitter_t, event *yaml_event_t) bool { - - emitter.anchor_data.anchor = nil - emitter.tag_data.handle = nil - emitter.tag_data.suffix = nil - emitter.scalar_data.value = nil - - switch event.typ { - case yaml_ALIAS_EVENT: - if !yaml_emitter_analyze_anchor(emitter, event.anchor, true) { - return false - } - - case yaml_SCALAR_EVENT: - if len(event.anchor) > 0 { - if !yaml_emitter_analyze_anchor(emitter, event.anchor, false) { - return false - } - } - if len(event.tag) > 0 && (emitter.canonical || (!event.implicit && !event.quoted_implicit)) { - if !yaml_emitter_analyze_tag(emitter, event.tag) { - return false - } - } - if !yaml_emitter_analyze_scalar(emitter, event.value) { - return false - } - - case yaml_SEQUENCE_START_EVENT: - if len(event.anchor) > 0 { - if !yaml_emitter_analyze_anchor(emitter, event.anchor, false) { - return false - } - } - if len(event.tag) > 0 && (emitter.canonical || !event.implicit) { - if !yaml_emitter_analyze_tag(emitter, event.tag) { - return false - } - } - - case yaml_MAPPING_START_EVENT: - if len(event.anchor) > 0 { - if !yaml_emitter_analyze_anchor(emitter, event.anchor, false) { - return false - } - } - if len(event.tag) > 0 && (emitter.canonical || !event.implicit) { - if !yaml_emitter_analyze_tag(emitter, event.tag) { - return false - } - } - } - return true -} - -// Write the BOM character. -func yaml_emitter_write_bom(emitter *yaml_emitter_t) bool { - if !flush(emitter) { - return false - } - pos := emitter.buffer_pos - emitter.buffer[pos+0] = '\xEF' - emitter.buffer[pos+1] = '\xBB' - emitter.buffer[pos+2] = '\xBF' - emitter.buffer_pos += 3 - return true -} - -func yaml_emitter_write_indent(emitter *yaml_emitter_t) bool { - indent := emitter.indent - if indent < 0 { - indent = 0 - } - if !emitter.indention || emitter.column > indent || (emitter.column == indent && !emitter.whitespace) { - if !put_break(emitter) { - return false - } - } - for emitter.column < indent { - if !put(emitter, ' ') { - return false - } - } - emitter.whitespace = true - emitter.indention = true - return true -} - -func yaml_emitter_write_indicator(emitter *yaml_emitter_t, indicator []byte, need_whitespace, is_whitespace, is_indention bool) bool { - if need_whitespace && !emitter.whitespace { - if !put(emitter, ' ') { - return false - } - } - if !write_all(emitter, indicator) { - return false - } - emitter.whitespace = is_whitespace - emitter.indention = (emitter.indention && is_indention) - emitter.open_ended = false - return true -} - -func yaml_emitter_write_anchor(emitter *yaml_emitter_t, value []byte) bool { - if !write_all(emitter, value) { - return false - } - emitter.whitespace = false - emitter.indention = false - return true -} - -func yaml_emitter_write_tag_handle(emitter *yaml_emitter_t, value []byte) bool { - if !emitter.whitespace { - if !put(emitter, ' ') { - return false - } - } - if !write_all(emitter, value) { - return false - } - emitter.whitespace = false - emitter.indention = false - return true -} - -func yaml_emitter_write_tag_content(emitter *yaml_emitter_t, value []byte, need_whitespace bool) bool { - if need_whitespace && !emitter.whitespace { - if !put(emitter, ' ') { - return false - } - } - for i := 0; i < len(value); { - var must_write bool - switch value[i] { - case ';', '/', '?', ':', '@', '&', '=', '+', '$', ',', '_', '.', '~', '*', '\'', '(', ')', '[', ']': - must_write = true - default: - must_write = is_alpha(value, i) - } - if must_write { - if !write(emitter, value, &i) { - return false - } - } else { - w := width(value[i]) - for k := 0; k < w; k++ { - octet := value[i] - i++ - if !put(emitter, '%') { - return false - } - - c := octet >> 4 - if c < 10 { - c += '0' - } else { - c += 'A' - 10 - } - if !put(emitter, c) { - return false - } - - c = octet & 0x0f - if c < 10 { - c += '0' - } else { - c += 'A' - 10 - } - if !put(emitter, c) { - return false - } - } - } - } - emitter.whitespace = false - emitter.indention = false - return true -} - -func yaml_emitter_write_plain_scalar(emitter *yaml_emitter_t, value []byte, allow_breaks bool) bool { - if !emitter.whitespace { - if !put(emitter, ' ') { - return false - } - } - - spaces := false - breaks := false - for i := 0; i < len(value); { - if is_space(value, i) { - if allow_breaks && !spaces && emitter.column > emitter.best_width && !is_space(value, i+1) { - if !yaml_emitter_write_indent(emitter) { - return false - } - i += width(value[i]) - } else { - if !write(emitter, value, &i) { - return false - } - } - spaces = true - } else if is_break(value, i) { - if !breaks && value[i] == '\n' { - if !put_break(emitter) { - return false - } - } - if !write_break(emitter, value, &i) { - return false - } - emitter.indention = true - breaks = true - } else { - if breaks { - if !yaml_emitter_write_indent(emitter) { - return false - } - } - if !write(emitter, value, &i) { - return false - } - emitter.indention = false - spaces = false - breaks = false - } - } - - emitter.whitespace = false - emitter.indention = false - if emitter.root_context { - emitter.open_ended = true - } - - return true -} - -func yaml_emitter_write_single_quoted_scalar(emitter *yaml_emitter_t, value []byte, allow_breaks bool) bool { - - if !yaml_emitter_write_indicator(emitter, []byte{'\''}, true, false, false) { - return false - } - - spaces := false - breaks := false - for i := 0; i < len(value); { - if is_space(value, i) { - if allow_breaks && !spaces && emitter.column > emitter.best_width && i > 0 && i < len(value)-1 && !is_space(value, i+1) { - if !yaml_emitter_write_indent(emitter) { - return false - } - i += width(value[i]) - } else { - if !write(emitter, value, &i) { - return false - } - } - spaces = true - } else if is_break(value, i) { - if !breaks && value[i] == '\n' { - if !put_break(emitter) { - return false - } - } - if !write_break(emitter, value, &i) { - return false - } - emitter.indention = true - breaks = true - } else { - if breaks { - if !yaml_emitter_write_indent(emitter) { - return false - } - } - if value[i] == '\'' { - if !put(emitter, '\'') { - return false - } - } - if !write(emitter, value, &i) { - return false - } - emitter.indention = false - spaces = false - breaks = false - } - } - if !yaml_emitter_write_indicator(emitter, []byte{'\''}, false, false, false) { - return false - } - emitter.whitespace = false - emitter.indention = false - return true -} - -func yaml_emitter_write_double_quoted_scalar(emitter *yaml_emitter_t, value []byte, allow_breaks bool) bool { - spaces := false - if !yaml_emitter_write_indicator(emitter, []byte{'"'}, true, false, false) { - return false - } - - for i := 0; i < len(value); { - if !is_printable(value, i) || (!emitter.unicode && !is_ascii(value, i)) || - is_bom(value, i) || is_break(value, i) || - value[i] == '"' || value[i] == '\\' { - - octet := value[i] - - var w int - var v rune - switch { - case octet&0x80 == 0x00: - w, v = 1, rune(octet&0x7F) - case octet&0xE0 == 0xC0: - w, v = 2, rune(octet&0x1F) - case octet&0xF0 == 0xE0: - w, v = 3, rune(octet&0x0F) - case octet&0xF8 == 0xF0: - w, v = 4, rune(octet&0x07) - } - for k := 1; k < w; k++ { - octet = value[i+k] - v = (v << 6) + (rune(octet) & 0x3F) - } - i += w - - if !put(emitter, '\\') { - return false - } - - var ok bool - switch v { - case 0x00: - ok = put(emitter, '0') - case 0x07: - ok = put(emitter, 'a') - case 0x08: - ok = put(emitter, 'b') - case 0x09: - ok = put(emitter, 't') - case 0x0A: - ok = put(emitter, 'n') - case 0x0b: - ok = put(emitter, 'v') - case 0x0c: - ok = put(emitter, 'f') - case 0x0d: - ok = put(emitter, 'r') - case 0x1b: - ok = put(emitter, 'e') - case 0x22: - ok = put(emitter, '"') - case 0x5c: - ok = put(emitter, '\\') - case 0x85: - ok = put(emitter, 'N') - case 0xA0: - ok = put(emitter, '_') - case 0x2028: - ok = put(emitter, 'L') - case 0x2029: - ok = put(emitter, 'P') - default: - if v <= 0xFF { - ok = put(emitter, 'x') - w = 2 - } else if v <= 0xFFFF { - ok = put(emitter, 'u') - w = 4 - } else { - ok = put(emitter, 'U') - w = 8 - } - for k := (w - 1) * 4; ok && k >= 0; k -= 4 { - digit := byte((v >> uint(k)) & 0x0F) - if digit < 10 { - ok = put(emitter, digit+'0') - } else { - ok = put(emitter, digit+'A'-10) - } - } - } - if !ok { - return false - } - spaces = false - } else if is_space(value, i) { - if allow_breaks && !spaces && emitter.column > emitter.best_width && i > 0 && i < len(value)-1 { - if !yaml_emitter_write_indent(emitter) { - return false - } - if is_space(value, i+1) { - if !put(emitter, '\\') { - return false - } - } - i += width(value[i]) - } else if !write(emitter, value, &i) { - return false - } - spaces = true - } else { - if !write(emitter, value, &i) { - return false - } - spaces = false - } - } - if !yaml_emitter_write_indicator(emitter, []byte{'"'}, false, false, false) { - return false - } - emitter.whitespace = false - emitter.indention = false - return true -} - -func yaml_emitter_write_block_scalar_hints(emitter *yaml_emitter_t, value []byte) bool { - if is_space(value, 0) || is_break(value, 0) { - indent_hint := []byte{'0' + byte(emitter.best_indent)} - if !yaml_emitter_write_indicator(emitter, indent_hint, false, false, false) { - return false - } - } - - emitter.open_ended = false - - var chomp_hint [1]byte - if len(value) == 0 { - chomp_hint[0] = '-' - } else { - i := len(value) - 1 - for value[i]&0xC0 == 0x80 { - i-- - } - if !is_break(value, i) { - chomp_hint[0] = '-' - } else if i == 0 { - chomp_hint[0] = '+' - emitter.open_ended = true - } else { - i-- - for value[i]&0xC0 == 0x80 { - i-- - } - if is_break(value, i) { - chomp_hint[0] = '+' - emitter.open_ended = true - } - } - } - if chomp_hint[0] != 0 { - if !yaml_emitter_write_indicator(emitter, chomp_hint[:], false, false, false) { - return false - } - } - return true -} - -func yaml_emitter_write_literal_scalar(emitter *yaml_emitter_t, value []byte) bool { - if !yaml_emitter_write_indicator(emitter, []byte{'|'}, true, false, false) { - return false - } - if !yaml_emitter_write_block_scalar_hints(emitter, value) { - return false - } - if !put_break(emitter) { - return false - } - emitter.indention = true - emitter.whitespace = true - breaks := true - for i := 0; i < len(value); { - if is_break(value, i) { - if !write_break(emitter, value, &i) { - return false - } - emitter.indention = true - breaks = true - } else { - if breaks { - if !yaml_emitter_write_indent(emitter) { - return false - } - } - if !write(emitter, value, &i) { - return false - } - emitter.indention = false - breaks = false - } - } - - return true -} - -func yaml_emitter_write_folded_scalar(emitter *yaml_emitter_t, value []byte) bool { - if !yaml_emitter_write_indicator(emitter, []byte{'>'}, true, false, false) { - return false - } - if !yaml_emitter_write_block_scalar_hints(emitter, value) { - return false - } - - if !put_break(emitter) { - return false - } - emitter.indention = true - emitter.whitespace = true - - breaks := true - leading_spaces := true - for i := 0; i < len(value); { - if is_break(value, i) { - if !breaks && !leading_spaces && value[i] == '\n' { - k := 0 - for is_break(value, k) { - k += width(value[k]) - } - if !is_blankz(value, k) { - if !put_break(emitter) { - return false - } - } - } - if !write_break(emitter, value, &i) { - return false - } - emitter.indention = true - breaks = true - } else { - if breaks { - if !yaml_emitter_write_indent(emitter) { - return false - } - leading_spaces = is_blank(value, i) - } - if !breaks && is_space(value, i) && !is_space(value, i+1) && emitter.column > emitter.best_width { - if !yaml_emitter_write_indent(emitter) { - return false - } - i += width(value[i]) - } else { - if !write(emitter, value, &i) { - return false - } - } - emitter.indention = false - breaks = false - } - } - return true -} diff --git a/vendor/go.yaml.in/yaml/v2/encode.go b/vendor/go.yaml.in/yaml/v2/encode.go deleted file mode 100644 index 0ee738e11..000000000 --- a/vendor/go.yaml.in/yaml/v2/encode.go +++ /dev/null @@ -1,390 +0,0 @@ -package yaml - -import ( - "encoding" - "fmt" - "io" - "reflect" - "regexp" - "sort" - "strconv" - "strings" - "time" - "unicode/utf8" -) - -// jsonNumber is the interface of the encoding/json.Number datatype. -// Repeating the interface here avoids a dependency on encoding/json, and also -// supports other libraries like jsoniter, which use a similar datatype with -// the same interface. Detecting this interface is useful when dealing with -// structures containing json.Number, which is a string under the hood. The -// encoder should prefer the use of Int64(), Float64() and string(), in that -// order, when encoding this type. -type jsonNumber interface { - Float64() (float64, error) - Int64() (int64, error) - String() string -} - -type encoder struct { - emitter yaml_emitter_t - event yaml_event_t - out []byte - flow bool - // doneInit holds whether the initial stream_start_event has been - // emitted. - doneInit bool -} - -func newEncoder() *encoder { - e := &encoder{} - yaml_emitter_initialize(&e.emitter) - yaml_emitter_set_output_string(&e.emitter, &e.out) - yaml_emitter_set_unicode(&e.emitter, true) - return e -} - -func newEncoderWithWriter(w io.Writer) *encoder { - e := &encoder{} - yaml_emitter_initialize(&e.emitter) - yaml_emitter_set_output_writer(&e.emitter, w) - yaml_emitter_set_unicode(&e.emitter, true) - return e -} - -func (e *encoder) init() { - if e.doneInit { - return - } - yaml_stream_start_event_initialize(&e.event, yaml_UTF8_ENCODING) - e.emit() - e.doneInit = true -} - -func (e *encoder) finish() { - e.emitter.open_ended = false - yaml_stream_end_event_initialize(&e.event) - e.emit() -} - -func (e *encoder) destroy() { - yaml_emitter_delete(&e.emitter) -} - -func (e *encoder) emit() { - // This will internally delete the e.event value. - e.must(yaml_emitter_emit(&e.emitter, &e.event)) -} - -func (e *encoder) must(ok bool) { - if !ok { - msg := e.emitter.problem - if msg == "" { - msg = "unknown problem generating YAML content" - } - failf("%s", msg) - } -} - -func (e *encoder) marshalDoc(tag string, in reflect.Value) { - e.init() - yaml_document_start_event_initialize(&e.event, nil, nil, true) - e.emit() - e.marshal(tag, in) - yaml_document_end_event_initialize(&e.event, true) - e.emit() -} - -func (e *encoder) marshal(tag string, in reflect.Value) { - if !in.IsValid() || in.Kind() == reflect.Ptr && in.IsNil() { - e.nilv() - return - } - iface := in.Interface() - switch m := iface.(type) { - case jsonNumber: - integer, err := m.Int64() - if err == nil { - // In this case the json.Number is a valid int64 - in = reflect.ValueOf(integer) - break - } - float, err := m.Float64() - if err == nil { - // In this case the json.Number is a valid float64 - in = reflect.ValueOf(float) - break - } - // fallback case - no number could be obtained - in = reflect.ValueOf(m.String()) - case time.Time, *time.Time: - // Although time.Time implements TextMarshaler, - // we don't want to treat it as a string for YAML - // purposes because YAML has special support for - // timestamps. - case Marshaler: - v, err := m.MarshalYAML() - if err != nil { - fail(err) - } - if v == nil { - e.nilv() - return - } - in = reflect.ValueOf(v) - case encoding.TextMarshaler: - text, err := m.MarshalText() - if err != nil { - fail(err) - } - in = reflect.ValueOf(string(text)) - case nil: - e.nilv() - return - } - switch in.Kind() { - case reflect.Interface: - e.marshal(tag, in.Elem()) - case reflect.Map: - e.mapv(tag, in) - case reflect.Ptr: - if in.Type() == ptrTimeType { - e.timev(tag, in.Elem()) - } else { - e.marshal(tag, in.Elem()) - } - case reflect.Struct: - if in.Type() == timeType { - e.timev(tag, in) - } else { - e.structv(tag, in) - } - case reflect.Slice, reflect.Array: - if in.Type().Elem() == mapItemType { - e.itemsv(tag, in) - } else { - e.slicev(tag, in) - } - case reflect.String: - e.stringv(tag, in) - case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - if in.Type() == durationType { - e.stringv(tag, reflect.ValueOf(iface.(time.Duration).String())) - } else { - e.intv(tag, in) - } - case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: - e.uintv(tag, in) - case reflect.Float32, reflect.Float64: - e.floatv(tag, in) - case reflect.Bool: - e.boolv(tag, in) - default: - panic("cannot marshal type: " + in.Type().String()) - } -} - -func (e *encoder) mapv(tag string, in reflect.Value) { - e.mappingv(tag, func() { - keys := keyList(in.MapKeys()) - sort.Sort(keys) - for _, k := range keys { - e.marshal("", k) - e.marshal("", in.MapIndex(k)) - } - }) -} - -func (e *encoder) itemsv(tag string, in reflect.Value) { - e.mappingv(tag, func() { - slice := in.Convert(reflect.TypeOf([]MapItem{})).Interface().([]MapItem) - for _, item := range slice { - e.marshal("", reflect.ValueOf(item.Key)) - e.marshal("", reflect.ValueOf(item.Value)) - } - }) -} - -func (e *encoder) structv(tag string, in reflect.Value) { - sinfo, err := getStructInfo(in.Type()) - if err != nil { - panic(err) - } - e.mappingv(tag, func() { - for _, info := range sinfo.FieldsList { - var value reflect.Value - if info.Inline == nil { - value = in.Field(info.Num) - } else { - value = in.FieldByIndex(info.Inline) - } - if info.OmitEmpty && isZero(value) { - continue - } - e.marshal("", reflect.ValueOf(info.Key)) - e.flow = info.Flow - e.marshal("", value) - } - if sinfo.InlineMap >= 0 { - m := in.Field(sinfo.InlineMap) - if m.Len() > 0 { - e.flow = false - keys := keyList(m.MapKeys()) - sort.Sort(keys) - for _, k := range keys { - if _, found := sinfo.FieldsMap[k.String()]; found { - panic(fmt.Sprintf("Can't have key %q in inlined map; conflicts with struct field", k.String())) - } - e.marshal("", k) - e.flow = false - e.marshal("", m.MapIndex(k)) - } - } - } - }) -} - -func (e *encoder) mappingv(tag string, f func()) { - implicit := tag == "" - style := yaml_BLOCK_MAPPING_STYLE - if e.flow { - e.flow = false - style = yaml_FLOW_MAPPING_STYLE - } - yaml_mapping_start_event_initialize(&e.event, nil, []byte(tag), implicit, style) - e.emit() - f() - yaml_mapping_end_event_initialize(&e.event) - e.emit() -} - -func (e *encoder) slicev(tag string, in reflect.Value) { - implicit := tag == "" - style := yaml_BLOCK_SEQUENCE_STYLE - if e.flow { - e.flow = false - style = yaml_FLOW_SEQUENCE_STYLE - } - e.must(yaml_sequence_start_event_initialize(&e.event, nil, []byte(tag), implicit, style)) - e.emit() - n := in.Len() - for i := 0; i < n; i++ { - e.marshal("", in.Index(i)) - } - e.must(yaml_sequence_end_event_initialize(&e.event)) - e.emit() -} - -// isBase60 returns whether s is in base 60 notation as defined in YAML 1.1. -// -// The base 60 float notation in YAML 1.1 is a terrible idea and is unsupported -// in YAML 1.2 and by this package, but these should be marshalled quoted for -// the time being for compatibility with other parsers. -func isBase60Float(s string) (result bool) { - // Fast path. - if s == "" { - return false - } - c := s[0] - if !(c == '+' || c == '-' || c >= '0' && c <= '9') || strings.IndexByte(s, ':') < 0 { - return false - } - // Do the full match. - return base60float.MatchString(s) -} - -// From http://yaml.org/type/float.html, except the regular expression there -// is bogus. In practice parsers do not enforce the "\.[0-9_]*" suffix. -var base60float = regexp.MustCompile(`^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+(?:\.[0-9_]*)?$`) - -func (e *encoder) stringv(tag string, in reflect.Value) { - var style yaml_scalar_style_t - s := in.String() - canUsePlain := true - switch { - case !utf8.ValidString(s): - if tag == yaml_BINARY_TAG { - failf("explicitly tagged !!binary data must be base64-encoded") - } - if tag != "" { - failf("cannot marshal invalid UTF-8 data as %s", shortTag(tag)) - } - // It can't be encoded directly as YAML so use a binary tag - // and encode it as base64. - tag = yaml_BINARY_TAG - s = encodeBase64(s) - case tag == "": - // Check to see if it would resolve to a specific - // tag when encoded unquoted. If it doesn't, - // there's no need to quote it. - rtag, _ := resolve("", s) - canUsePlain = rtag == yaml_STR_TAG && !isBase60Float(s) - } - // Note: it's possible for user code to emit invalid YAML - // if they explicitly specify a tag and a string containing - // text that's incompatible with that tag. - switch { - case strings.Contains(s, "\n"): - style = yaml_LITERAL_SCALAR_STYLE - case canUsePlain: - style = yaml_PLAIN_SCALAR_STYLE - default: - style = yaml_DOUBLE_QUOTED_SCALAR_STYLE - } - e.emitScalar(s, "", tag, style) -} - -func (e *encoder) boolv(tag string, in reflect.Value) { - var s string - if in.Bool() { - s = "true" - } else { - s = "false" - } - e.emitScalar(s, "", tag, yaml_PLAIN_SCALAR_STYLE) -} - -func (e *encoder) intv(tag string, in reflect.Value) { - s := strconv.FormatInt(in.Int(), 10) - e.emitScalar(s, "", tag, yaml_PLAIN_SCALAR_STYLE) -} - -func (e *encoder) uintv(tag string, in reflect.Value) { - s := strconv.FormatUint(in.Uint(), 10) - e.emitScalar(s, "", tag, yaml_PLAIN_SCALAR_STYLE) -} - -func (e *encoder) timev(tag string, in reflect.Value) { - t := in.Interface().(time.Time) - s := t.Format(time.RFC3339Nano) - e.emitScalar(s, "", tag, yaml_PLAIN_SCALAR_STYLE) -} - -func (e *encoder) floatv(tag string, in reflect.Value) { - // Issue #352: When formatting, use the precision of the underlying value - precision := 64 - if in.Kind() == reflect.Float32 { - precision = 32 - } - - s := strconv.FormatFloat(in.Float(), 'g', -1, precision) - switch s { - case "+Inf": - s = ".inf" - case "-Inf": - s = "-.inf" - case "NaN": - s = ".nan" - } - e.emitScalar(s, "", tag, yaml_PLAIN_SCALAR_STYLE) -} - -func (e *encoder) nilv() { - e.emitScalar("null", "", "", yaml_PLAIN_SCALAR_STYLE) -} - -func (e *encoder) emitScalar(value, anchor, tag string, style yaml_scalar_style_t) { - implicit := tag == "" - e.must(yaml_scalar_event_initialize(&e.event, []byte(anchor), []byte(tag), []byte(value), implicit, implicit, style)) - e.emit() -} diff --git a/vendor/go.yaml.in/yaml/v2/parserc.go b/vendor/go.yaml.in/yaml/v2/parserc.go deleted file mode 100644 index 81d05dfe5..000000000 --- a/vendor/go.yaml.in/yaml/v2/parserc.go +++ /dev/null @@ -1,1095 +0,0 @@ -package yaml - -import ( - "bytes" -) - -// The parser implements the following grammar: -// -// stream ::= STREAM-START implicit_document? explicit_document* STREAM-END -// implicit_document ::= block_node DOCUMENT-END* -// explicit_document ::= DIRECTIVE* DOCUMENT-START block_node? DOCUMENT-END* -// block_node_or_indentless_sequence ::= -// ALIAS -// | properties (block_content | indentless_block_sequence)? -// | block_content -// | indentless_block_sequence -// block_node ::= ALIAS -// | properties block_content? -// | block_content -// flow_node ::= ALIAS -// | properties flow_content? -// | flow_content -// properties ::= TAG ANCHOR? | ANCHOR TAG? -// block_content ::= block_collection | flow_collection | SCALAR -// flow_content ::= flow_collection | SCALAR -// block_collection ::= block_sequence | block_mapping -// flow_collection ::= flow_sequence | flow_mapping -// block_sequence ::= BLOCK-SEQUENCE-START (BLOCK-ENTRY block_node?)* BLOCK-END -// indentless_sequence ::= (BLOCK-ENTRY block_node?)+ -// block_mapping ::= BLOCK-MAPPING_START -// ((KEY block_node_or_indentless_sequence?)? -// (VALUE block_node_or_indentless_sequence?)?)* -// BLOCK-END -// flow_sequence ::= FLOW-SEQUENCE-START -// (flow_sequence_entry FLOW-ENTRY)* -// flow_sequence_entry? -// FLOW-SEQUENCE-END -// flow_sequence_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)? -// flow_mapping ::= FLOW-MAPPING-START -// (flow_mapping_entry FLOW-ENTRY)* -// flow_mapping_entry? -// FLOW-MAPPING-END -// flow_mapping_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)? - -// Peek the next token in the token queue. -func peek_token(parser *yaml_parser_t) *yaml_token_t { - if parser.token_available || yaml_parser_fetch_more_tokens(parser) { - return &parser.tokens[parser.tokens_head] - } - return nil -} - -// Remove the next token from the queue (must be called after peek_token). -func skip_token(parser *yaml_parser_t) { - parser.token_available = false - parser.tokens_parsed++ - parser.stream_end_produced = parser.tokens[parser.tokens_head].typ == yaml_STREAM_END_TOKEN - parser.tokens_head++ -} - -// Get the next event. -func yaml_parser_parse(parser *yaml_parser_t, event *yaml_event_t) bool { - // Erase the event object. - *event = yaml_event_t{} - - // No events after the end of the stream or error. - if parser.stream_end_produced || parser.error != yaml_NO_ERROR || parser.state == yaml_PARSE_END_STATE { - return true - } - - // Generate the next event. - return yaml_parser_state_machine(parser, event) -} - -// Set parser error. -func yaml_parser_set_parser_error(parser *yaml_parser_t, problem string, problem_mark yaml_mark_t) bool { - parser.error = yaml_PARSER_ERROR - parser.problem = problem - parser.problem_mark = problem_mark - return false -} - -func yaml_parser_set_parser_error_context(parser *yaml_parser_t, context string, context_mark yaml_mark_t, problem string, problem_mark yaml_mark_t) bool { - parser.error = yaml_PARSER_ERROR - parser.context = context - parser.context_mark = context_mark - parser.problem = problem - parser.problem_mark = problem_mark - return false -} - -// State dispatcher. -func yaml_parser_state_machine(parser *yaml_parser_t, event *yaml_event_t) bool { - //trace("yaml_parser_state_machine", "state:", parser.state.String()) - - switch parser.state { - case yaml_PARSE_STREAM_START_STATE: - return yaml_parser_parse_stream_start(parser, event) - - case yaml_PARSE_IMPLICIT_DOCUMENT_START_STATE: - return yaml_parser_parse_document_start(parser, event, true) - - case yaml_PARSE_DOCUMENT_START_STATE: - return yaml_parser_parse_document_start(parser, event, false) - - case yaml_PARSE_DOCUMENT_CONTENT_STATE: - return yaml_parser_parse_document_content(parser, event) - - case yaml_PARSE_DOCUMENT_END_STATE: - return yaml_parser_parse_document_end(parser, event) - - case yaml_PARSE_BLOCK_NODE_STATE: - return yaml_parser_parse_node(parser, event, true, false) - - case yaml_PARSE_BLOCK_NODE_OR_INDENTLESS_SEQUENCE_STATE: - return yaml_parser_parse_node(parser, event, true, true) - - case yaml_PARSE_FLOW_NODE_STATE: - return yaml_parser_parse_node(parser, event, false, false) - - case yaml_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE: - return yaml_parser_parse_block_sequence_entry(parser, event, true) - - case yaml_PARSE_BLOCK_SEQUENCE_ENTRY_STATE: - return yaml_parser_parse_block_sequence_entry(parser, event, false) - - case yaml_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE: - return yaml_parser_parse_indentless_sequence_entry(parser, event) - - case yaml_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE: - return yaml_parser_parse_block_mapping_key(parser, event, true) - - case yaml_PARSE_BLOCK_MAPPING_KEY_STATE: - return yaml_parser_parse_block_mapping_key(parser, event, false) - - case yaml_PARSE_BLOCK_MAPPING_VALUE_STATE: - return yaml_parser_parse_block_mapping_value(parser, event) - - case yaml_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE: - return yaml_parser_parse_flow_sequence_entry(parser, event, true) - - case yaml_PARSE_FLOW_SEQUENCE_ENTRY_STATE: - return yaml_parser_parse_flow_sequence_entry(parser, event, false) - - case yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE: - return yaml_parser_parse_flow_sequence_entry_mapping_key(parser, event) - - case yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE: - return yaml_parser_parse_flow_sequence_entry_mapping_value(parser, event) - - case yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE: - return yaml_parser_parse_flow_sequence_entry_mapping_end(parser, event) - - case yaml_PARSE_FLOW_MAPPING_FIRST_KEY_STATE: - return yaml_parser_parse_flow_mapping_key(parser, event, true) - - case yaml_PARSE_FLOW_MAPPING_KEY_STATE: - return yaml_parser_parse_flow_mapping_key(parser, event, false) - - case yaml_PARSE_FLOW_MAPPING_VALUE_STATE: - return yaml_parser_parse_flow_mapping_value(parser, event, false) - - case yaml_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE: - return yaml_parser_parse_flow_mapping_value(parser, event, true) - - default: - panic("invalid parser state") - } -} - -// Parse the production: -// stream ::= STREAM-START implicit_document? explicit_document* STREAM-END -// ************ -func yaml_parser_parse_stream_start(parser *yaml_parser_t, event *yaml_event_t) bool { - token := peek_token(parser) - if token == nil { - return false - } - if token.typ != yaml_STREAM_START_TOKEN { - return yaml_parser_set_parser_error(parser, "did not find expected ", token.start_mark) - } - parser.state = yaml_PARSE_IMPLICIT_DOCUMENT_START_STATE - *event = yaml_event_t{ - typ: yaml_STREAM_START_EVENT, - start_mark: token.start_mark, - end_mark: token.end_mark, - encoding: token.encoding, - } - skip_token(parser) - return true -} - -// Parse the productions: -// implicit_document ::= block_node DOCUMENT-END* -// * -// explicit_document ::= DIRECTIVE* DOCUMENT-START block_node? DOCUMENT-END* -// ************************* -func yaml_parser_parse_document_start(parser *yaml_parser_t, event *yaml_event_t, implicit bool) bool { - - token := peek_token(parser) - if token == nil { - return false - } - - // Parse extra document end indicators. - if !implicit { - for token.typ == yaml_DOCUMENT_END_TOKEN { - skip_token(parser) - token = peek_token(parser) - if token == nil { - return false - } - } - } - - if implicit && token.typ != yaml_VERSION_DIRECTIVE_TOKEN && - token.typ != yaml_TAG_DIRECTIVE_TOKEN && - token.typ != yaml_DOCUMENT_START_TOKEN && - token.typ != yaml_STREAM_END_TOKEN { - // Parse an implicit document. - if !yaml_parser_process_directives(parser, nil, nil) { - return false - } - parser.states = append(parser.states, yaml_PARSE_DOCUMENT_END_STATE) - parser.state = yaml_PARSE_BLOCK_NODE_STATE - - *event = yaml_event_t{ - typ: yaml_DOCUMENT_START_EVENT, - start_mark: token.start_mark, - end_mark: token.end_mark, - } - - } else if token.typ != yaml_STREAM_END_TOKEN { - // Parse an explicit document. - var version_directive *yaml_version_directive_t - var tag_directives []yaml_tag_directive_t - start_mark := token.start_mark - if !yaml_parser_process_directives(parser, &version_directive, &tag_directives) { - return false - } - token = peek_token(parser) - if token == nil { - return false - } - if token.typ != yaml_DOCUMENT_START_TOKEN { - yaml_parser_set_parser_error(parser, - "did not find expected ", token.start_mark) - return false - } - parser.states = append(parser.states, yaml_PARSE_DOCUMENT_END_STATE) - parser.state = yaml_PARSE_DOCUMENT_CONTENT_STATE - end_mark := token.end_mark - - *event = yaml_event_t{ - typ: yaml_DOCUMENT_START_EVENT, - start_mark: start_mark, - end_mark: end_mark, - version_directive: version_directive, - tag_directives: tag_directives, - implicit: false, - } - skip_token(parser) - - } else { - // Parse the stream end. - parser.state = yaml_PARSE_END_STATE - *event = yaml_event_t{ - typ: yaml_STREAM_END_EVENT, - start_mark: token.start_mark, - end_mark: token.end_mark, - } - skip_token(parser) - } - - return true -} - -// Parse the productions: -// explicit_document ::= DIRECTIVE* DOCUMENT-START block_node? DOCUMENT-END* -// *********** -// -func yaml_parser_parse_document_content(parser *yaml_parser_t, event *yaml_event_t) bool { - token := peek_token(parser) - if token == nil { - return false - } - if token.typ == yaml_VERSION_DIRECTIVE_TOKEN || - token.typ == yaml_TAG_DIRECTIVE_TOKEN || - token.typ == yaml_DOCUMENT_START_TOKEN || - token.typ == yaml_DOCUMENT_END_TOKEN || - token.typ == yaml_STREAM_END_TOKEN { - parser.state = parser.states[len(parser.states)-1] - parser.states = parser.states[:len(parser.states)-1] - return yaml_parser_process_empty_scalar(parser, event, - token.start_mark) - } - return yaml_parser_parse_node(parser, event, true, false) -} - -// Parse the productions: -// implicit_document ::= block_node DOCUMENT-END* -// ************* -// explicit_document ::= DIRECTIVE* DOCUMENT-START block_node? DOCUMENT-END* -// -func yaml_parser_parse_document_end(parser *yaml_parser_t, event *yaml_event_t) bool { - token := peek_token(parser) - if token == nil { - return false - } - - start_mark := token.start_mark - end_mark := token.start_mark - - implicit := true - if token.typ == yaml_DOCUMENT_END_TOKEN { - end_mark = token.end_mark - skip_token(parser) - implicit = false - } - - parser.tag_directives = parser.tag_directives[:0] - - parser.state = yaml_PARSE_DOCUMENT_START_STATE - *event = yaml_event_t{ - typ: yaml_DOCUMENT_END_EVENT, - start_mark: start_mark, - end_mark: end_mark, - implicit: implicit, - } - return true -} - -// Parse the productions: -// block_node_or_indentless_sequence ::= -// ALIAS -// ***** -// | properties (block_content | indentless_block_sequence)? -// ********** * -// | block_content | indentless_block_sequence -// * -// block_node ::= ALIAS -// ***** -// | properties block_content? -// ********** * -// | block_content -// * -// flow_node ::= ALIAS -// ***** -// | properties flow_content? -// ********** * -// | flow_content -// * -// properties ::= TAG ANCHOR? | ANCHOR TAG? -// ************************* -// block_content ::= block_collection | flow_collection | SCALAR -// ****** -// flow_content ::= flow_collection | SCALAR -// ****** -func yaml_parser_parse_node(parser *yaml_parser_t, event *yaml_event_t, block, indentless_sequence bool) bool { - //defer trace("yaml_parser_parse_node", "block:", block, "indentless_sequence:", indentless_sequence)() - - token := peek_token(parser) - if token == nil { - return false - } - - if token.typ == yaml_ALIAS_TOKEN { - parser.state = parser.states[len(parser.states)-1] - parser.states = parser.states[:len(parser.states)-1] - *event = yaml_event_t{ - typ: yaml_ALIAS_EVENT, - start_mark: token.start_mark, - end_mark: token.end_mark, - anchor: token.value, - } - skip_token(parser) - return true - } - - start_mark := token.start_mark - end_mark := token.start_mark - - var tag_token bool - var tag_handle, tag_suffix, anchor []byte - var tag_mark yaml_mark_t - if token.typ == yaml_ANCHOR_TOKEN { - anchor = token.value - start_mark = token.start_mark - end_mark = token.end_mark - skip_token(parser) - token = peek_token(parser) - if token == nil { - return false - } - if token.typ == yaml_TAG_TOKEN { - tag_token = true - tag_handle = token.value - tag_suffix = token.suffix - tag_mark = token.start_mark - end_mark = token.end_mark - skip_token(parser) - token = peek_token(parser) - if token == nil { - return false - } - } - } else if token.typ == yaml_TAG_TOKEN { - tag_token = true - tag_handle = token.value - tag_suffix = token.suffix - start_mark = token.start_mark - tag_mark = token.start_mark - end_mark = token.end_mark - skip_token(parser) - token = peek_token(parser) - if token == nil { - return false - } - if token.typ == yaml_ANCHOR_TOKEN { - anchor = token.value - end_mark = token.end_mark - skip_token(parser) - token = peek_token(parser) - if token == nil { - return false - } - } - } - - var tag []byte - if tag_token { - if len(tag_handle) == 0 { - tag = tag_suffix - tag_suffix = nil - } else { - for i := range parser.tag_directives { - if bytes.Equal(parser.tag_directives[i].handle, tag_handle) { - tag = append([]byte(nil), parser.tag_directives[i].prefix...) - tag = append(tag, tag_suffix...) - break - } - } - if len(tag) == 0 { - yaml_parser_set_parser_error_context(parser, - "while parsing a node", start_mark, - "found undefined tag handle", tag_mark) - return false - } - } - } - - implicit := len(tag) == 0 - if indentless_sequence && token.typ == yaml_BLOCK_ENTRY_TOKEN { - end_mark = token.end_mark - parser.state = yaml_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE - *event = yaml_event_t{ - typ: yaml_SEQUENCE_START_EVENT, - start_mark: start_mark, - end_mark: end_mark, - anchor: anchor, - tag: tag, - implicit: implicit, - style: yaml_style_t(yaml_BLOCK_SEQUENCE_STYLE), - } - return true - } - if token.typ == yaml_SCALAR_TOKEN { - var plain_implicit, quoted_implicit bool - end_mark = token.end_mark - if (len(tag) == 0 && token.style == yaml_PLAIN_SCALAR_STYLE) || (len(tag) == 1 && tag[0] == '!') { - plain_implicit = true - } else if len(tag) == 0 { - quoted_implicit = true - } - parser.state = parser.states[len(parser.states)-1] - parser.states = parser.states[:len(parser.states)-1] - - *event = yaml_event_t{ - typ: yaml_SCALAR_EVENT, - start_mark: start_mark, - end_mark: end_mark, - anchor: anchor, - tag: tag, - value: token.value, - implicit: plain_implicit, - quoted_implicit: quoted_implicit, - style: yaml_style_t(token.style), - } - skip_token(parser) - return true - } - if token.typ == yaml_FLOW_SEQUENCE_START_TOKEN { - // [Go] Some of the events below can be merged as they differ only on style. - end_mark = token.end_mark - parser.state = yaml_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE - *event = yaml_event_t{ - typ: yaml_SEQUENCE_START_EVENT, - start_mark: start_mark, - end_mark: end_mark, - anchor: anchor, - tag: tag, - implicit: implicit, - style: yaml_style_t(yaml_FLOW_SEQUENCE_STYLE), - } - return true - } - if token.typ == yaml_FLOW_MAPPING_START_TOKEN { - end_mark = token.end_mark - parser.state = yaml_PARSE_FLOW_MAPPING_FIRST_KEY_STATE - *event = yaml_event_t{ - typ: yaml_MAPPING_START_EVENT, - start_mark: start_mark, - end_mark: end_mark, - anchor: anchor, - tag: tag, - implicit: implicit, - style: yaml_style_t(yaml_FLOW_MAPPING_STYLE), - } - return true - } - if block && token.typ == yaml_BLOCK_SEQUENCE_START_TOKEN { - end_mark = token.end_mark - parser.state = yaml_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE - *event = yaml_event_t{ - typ: yaml_SEQUENCE_START_EVENT, - start_mark: start_mark, - end_mark: end_mark, - anchor: anchor, - tag: tag, - implicit: implicit, - style: yaml_style_t(yaml_BLOCK_SEQUENCE_STYLE), - } - return true - } - if block && token.typ == yaml_BLOCK_MAPPING_START_TOKEN { - end_mark = token.end_mark - parser.state = yaml_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE - *event = yaml_event_t{ - typ: yaml_MAPPING_START_EVENT, - start_mark: start_mark, - end_mark: end_mark, - anchor: anchor, - tag: tag, - implicit: implicit, - style: yaml_style_t(yaml_BLOCK_MAPPING_STYLE), - } - return true - } - if len(anchor) > 0 || len(tag) > 0 { - parser.state = parser.states[len(parser.states)-1] - parser.states = parser.states[:len(parser.states)-1] - - *event = yaml_event_t{ - typ: yaml_SCALAR_EVENT, - start_mark: start_mark, - end_mark: end_mark, - anchor: anchor, - tag: tag, - implicit: implicit, - quoted_implicit: false, - style: yaml_style_t(yaml_PLAIN_SCALAR_STYLE), - } - return true - } - - context := "while parsing a flow node" - if block { - context = "while parsing a block node" - } - yaml_parser_set_parser_error_context(parser, context, start_mark, - "did not find expected node content", token.start_mark) - return false -} - -// Parse the productions: -// block_sequence ::= BLOCK-SEQUENCE-START (BLOCK-ENTRY block_node?)* BLOCK-END -// ******************** *********** * ********* -// -func yaml_parser_parse_block_sequence_entry(parser *yaml_parser_t, event *yaml_event_t, first bool) bool { - if first { - token := peek_token(parser) - parser.marks = append(parser.marks, token.start_mark) - skip_token(parser) - } - - token := peek_token(parser) - if token == nil { - return false - } - - if token.typ == yaml_BLOCK_ENTRY_TOKEN { - mark := token.end_mark - skip_token(parser) - token = peek_token(parser) - if token == nil { - return false - } - if token.typ != yaml_BLOCK_ENTRY_TOKEN && token.typ != yaml_BLOCK_END_TOKEN { - parser.states = append(parser.states, yaml_PARSE_BLOCK_SEQUENCE_ENTRY_STATE) - return yaml_parser_parse_node(parser, event, true, false) - } else { - parser.state = yaml_PARSE_BLOCK_SEQUENCE_ENTRY_STATE - return yaml_parser_process_empty_scalar(parser, event, mark) - } - } - if token.typ == yaml_BLOCK_END_TOKEN { - parser.state = parser.states[len(parser.states)-1] - parser.states = parser.states[:len(parser.states)-1] - parser.marks = parser.marks[:len(parser.marks)-1] - - *event = yaml_event_t{ - typ: yaml_SEQUENCE_END_EVENT, - start_mark: token.start_mark, - end_mark: token.end_mark, - } - - skip_token(parser) - return true - } - - context_mark := parser.marks[len(parser.marks)-1] - parser.marks = parser.marks[:len(parser.marks)-1] - return yaml_parser_set_parser_error_context(parser, - "while parsing a block collection", context_mark, - "did not find expected '-' indicator", token.start_mark) -} - -// Parse the productions: -// indentless_sequence ::= (BLOCK-ENTRY block_node?)+ -// *********** * -func yaml_parser_parse_indentless_sequence_entry(parser *yaml_parser_t, event *yaml_event_t) bool { - token := peek_token(parser) - if token == nil { - return false - } - - if token.typ == yaml_BLOCK_ENTRY_TOKEN { - mark := token.end_mark - skip_token(parser) - token = peek_token(parser) - if token == nil { - return false - } - if token.typ != yaml_BLOCK_ENTRY_TOKEN && - token.typ != yaml_KEY_TOKEN && - token.typ != yaml_VALUE_TOKEN && - token.typ != yaml_BLOCK_END_TOKEN { - parser.states = append(parser.states, yaml_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE) - return yaml_parser_parse_node(parser, event, true, false) - } - parser.state = yaml_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE - return yaml_parser_process_empty_scalar(parser, event, mark) - } - parser.state = parser.states[len(parser.states)-1] - parser.states = parser.states[:len(parser.states)-1] - - *event = yaml_event_t{ - typ: yaml_SEQUENCE_END_EVENT, - start_mark: token.start_mark, - end_mark: token.start_mark, // [Go] Shouldn't this be token.end_mark? - } - return true -} - -// Parse the productions: -// block_mapping ::= BLOCK-MAPPING_START -// ******************* -// ((KEY block_node_or_indentless_sequence?)? -// *** * -// (VALUE block_node_or_indentless_sequence?)?)* -// -// BLOCK-END -// ********* -// -func yaml_parser_parse_block_mapping_key(parser *yaml_parser_t, event *yaml_event_t, first bool) bool { - if first { - token := peek_token(parser) - parser.marks = append(parser.marks, token.start_mark) - skip_token(parser) - } - - token := peek_token(parser) - if token == nil { - return false - } - - if token.typ == yaml_KEY_TOKEN { - mark := token.end_mark - skip_token(parser) - token = peek_token(parser) - if token == nil { - return false - } - if token.typ != yaml_KEY_TOKEN && - token.typ != yaml_VALUE_TOKEN && - token.typ != yaml_BLOCK_END_TOKEN { - parser.states = append(parser.states, yaml_PARSE_BLOCK_MAPPING_VALUE_STATE) - return yaml_parser_parse_node(parser, event, true, true) - } else { - parser.state = yaml_PARSE_BLOCK_MAPPING_VALUE_STATE - return yaml_parser_process_empty_scalar(parser, event, mark) - } - } else if token.typ == yaml_BLOCK_END_TOKEN { - parser.state = parser.states[len(parser.states)-1] - parser.states = parser.states[:len(parser.states)-1] - parser.marks = parser.marks[:len(parser.marks)-1] - *event = yaml_event_t{ - typ: yaml_MAPPING_END_EVENT, - start_mark: token.start_mark, - end_mark: token.end_mark, - } - skip_token(parser) - return true - } - - context_mark := parser.marks[len(parser.marks)-1] - parser.marks = parser.marks[:len(parser.marks)-1] - return yaml_parser_set_parser_error_context(parser, - "while parsing a block mapping", context_mark, - "did not find expected key", token.start_mark) -} - -// Parse the productions: -// block_mapping ::= BLOCK-MAPPING_START -// -// ((KEY block_node_or_indentless_sequence?)? -// -// (VALUE block_node_or_indentless_sequence?)?)* -// ***** * -// BLOCK-END -// -// -func yaml_parser_parse_block_mapping_value(parser *yaml_parser_t, event *yaml_event_t) bool { - token := peek_token(parser) - if token == nil { - return false - } - if token.typ == yaml_VALUE_TOKEN { - mark := token.end_mark - skip_token(parser) - token = peek_token(parser) - if token == nil { - return false - } - if token.typ != yaml_KEY_TOKEN && - token.typ != yaml_VALUE_TOKEN && - token.typ != yaml_BLOCK_END_TOKEN { - parser.states = append(parser.states, yaml_PARSE_BLOCK_MAPPING_KEY_STATE) - return yaml_parser_parse_node(parser, event, true, true) - } - parser.state = yaml_PARSE_BLOCK_MAPPING_KEY_STATE - return yaml_parser_process_empty_scalar(parser, event, mark) - } - parser.state = yaml_PARSE_BLOCK_MAPPING_KEY_STATE - return yaml_parser_process_empty_scalar(parser, event, token.start_mark) -} - -// Parse the productions: -// flow_sequence ::= FLOW-SEQUENCE-START -// ******************* -// (flow_sequence_entry FLOW-ENTRY)* -// * ********** -// flow_sequence_entry? -// * -// FLOW-SEQUENCE-END -// ***************** -// flow_sequence_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)? -// * -// -func yaml_parser_parse_flow_sequence_entry(parser *yaml_parser_t, event *yaml_event_t, first bool) bool { - if first { - token := peek_token(parser) - parser.marks = append(parser.marks, token.start_mark) - skip_token(parser) - } - token := peek_token(parser) - if token == nil { - return false - } - if token.typ != yaml_FLOW_SEQUENCE_END_TOKEN { - if !first { - if token.typ == yaml_FLOW_ENTRY_TOKEN { - skip_token(parser) - token = peek_token(parser) - if token == nil { - return false - } - } else { - context_mark := parser.marks[len(parser.marks)-1] - parser.marks = parser.marks[:len(parser.marks)-1] - return yaml_parser_set_parser_error_context(parser, - "while parsing a flow sequence", context_mark, - "did not find expected ',' or ']'", token.start_mark) - } - } - - if token.typ == yaml_KEY_TOKEN { - parser.state = yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE - *event = yaml_event_t{ - typ: yaml_MAPPING_START_EVENT, - start_mark: token.start_mark, - end_mark: token.end_mark, - implicit: true, - style: yaml_style_t(yaml_FLOW_MAPPING_STYLE), - } - skip_token(parser) - return true - } else if token.typ != yaml_FLOW_SEQUENCE_END_TOKEN { - parser.states = append(parser.states, yaml_PARSE_FLOW_SEQUENCE_ENTRY_STATE) - return yaml_parser_parse_node(parser, event, false, false) - } - } - - parser.state = parser.states[len(parser.states)-1] - parser.states = parser.states[:len(parser.states)-1] - parser.marks = parser.marks[:len(parser.marks)-1] - - *event = yaml_event_t{ - typ: yaml_SEQUENCE_END_EVENT, - start_mark: token.start_mark, - end_mark: token.end_mark, - } - - skip_token(parser) - return true -} - -// -// Parse the productions: -// flow_sequence_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)? -// *** * -// -func yaml_parser_parse_flow_sequence_entry_mapping_key(parser *yaml_parser_t, event *yaml_event_t) bool { - token := peek_token(parser) - if token == nil { - return false - } - if token.typ != yaml_VALUE_TOKEN && - token.typ != yaml_FLOW_ENTRY_TOKEN && - token.typ != yaml_FLOW_SEQUENCE_END_TOKEN { - parser.states = append(parser.states, yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE) - return yaml_parser_parse_node(parser, event, false, false) - } - mark := token.end_mark - skip_token(parser) - parser.state = yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE - return yaml_parser_process_empty_scalar(parser, event, mark) -} - -// Parse the productions: -// flow_sequence_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)? -// ***** * -// -func yaml_parser_parse_flow_sequence_entry_mapping_value(parser *yaml_parser_t, event *yaml_event_t) bool { - token := peek_token(parser) - if token == nil { - return false - } - if token.typ == yaml_VALUE_TOKEN { - skip_token(parser) - token := peek_token(parser) - if token == nil { - return false - } - if token.typ != yaml_FLOW_ENTRY_TOKEN && token.typ != yaml_FLOW_SEQUENCE_END_TOKEN { - parser.states = append(parser.states, yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE) - return yaml_parser_parse_node(parser, event, false, false) - } - } - parser.state = yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE - return yaml_parser_process_empty_scalar(parser, event, token.start_mark) -} - -// Parse the productions: -// flow_sequence_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)? -// * -// -func yaml_parser_parse_flow_sequence_entry_mapping_end(parser *yaml_parser_t, event *yaml_event_t) bool { - token := peek_token(parser) - if token == nil { - return false - } - parser.state = yaml_PARSE_FLOW_SEQUENCE_ENTRY_STATE - *event = yaml_event_t{ - typ: yaml_MAPPING_END_EVENT, - start_mark: token.start_mark, - end_mark: token.start_mark, // [Go] Shouldn't this be end_mark? - } - return true -} - -// Parse the productions: -// flow_mapping ::= FLOW-MAPPING-START -// ****************** -// (flow_mapping_entry FLOW-ENTRY)* -// * ********** -// flow_mapping_entry? -// ****************** -// FLOW-MAPPING-END -// **************** -// flow_mapping_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)? -// * *** * -// -func yaml_parser_parse_flow_mapping_key(parser *yaml_parser_t, event *yaml_event_t, first bool) bool { - if first { - token := peek_token(parser) - parser.marks = append(parser.marks, token.start_mark) - skip_token(parser) - } - - token := peek_token(parser) - if token == nil { - return false - } - - if token.typ != yaml_FLOW_MAPPING_END_TOKEN { - if !first { - if token.typ == yaml_FLOW_ENTRY_TOKEN { - skip_token(parser) - token = peek_token(parser) - if token == nil { - return false - } - } else { - context_mark := parser.marks[len(parser.marks)-1] - parser.marks = parser.marks[:len(parser.marks)-1] - return yaml_parser_set_parser_error_context(parser, - "while parsing a flow mapping", context_mark, - "did not find expected ',' or '}'", token.start_mark) - } - } - - if token.typ == yaml_KEY_TOKEN { - skip_token(parser) - token = peek_token(parser) - if token == nil { - return false - } - if token.typ != yaml_VALUE_TOKEN && - token.typ != yaml_FLOW_ENTRY_TOKEN && - token.typ != yaml_FLOW_MAPPING_END_TOKEN { - parser.states = append(parser.states, yaml_PARSE_FLOW_MAPPING_VALUE_STATE) - return yaml_parser_parse_node(parser, event, false, false) - } else { - parser.state = yaml_PARSE_FLOW_MAPPING_VALUE_STATE - return yaml_parser_process_empty_scalar(parser, event, token.start_mark) - } - } else if token.typ != yaml_FLOW_MAPPING_END_TOKEN { - parser.states = append(parser.states, yaml_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE) - return yaml_parser_parse_node(parser, event, false, false) - } - } - - parser.state = parser.states[len(parser.states)-1] - parser.states = parser.states[:len(parser.states)-1] - parser.marks = parser.marks[:len(parser.marks)-1] - *event = yaml_event_t{ - typ: yaml_MAPPING_END_EVENT, - start_mark: token.start_mark, - end_mark: token.end_mark, - } - skip_token(parser) - return true -} - -// Parse the productions: -// flow_mapping_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)? -// * ***** * -// -func yaml_parser_parse_flow_mapping_value(parser *yaml_parser_t, event *yaml_event_t, empty bool) bool { - token := peek_token(parser) - if token == nil { - return false - } - if empty { - parser.state = yaml_PARSE_FLOW_MAPPING_KEY_STATE - return yaml_parser_process_empty_scalar(parser, event, token.start_mark) - } - if token.typ == yaml_VALUE_TOKEN { - skip_token(parser) - token = peek_token(parser) - if token == nil { - return false - } - if token.typ != yaml_FLOW_ENTRY_TOKEN && token.typ != yaml_FLOW_MAPPING_END_TOKEN { - parser.states = append(parser.states, yaml_PARSE_FLOW_MAPPING_KEY_STATE) - return yaml_parser_parse_node(parser, event, false, false) - } - } - parser.state = yaml_PARSE_FLOW_MAPPING_KEY_STATE - return yaml_parser_process_empty_scalar(parser, event, token.start_mark) -} - -// Generate an empty scalar event. -func yaml_parser_process_empty_scalar(parser *yaml_parser_t, event *yaml_event_t, mark yaml_mark_t) bool { - *event = yaml_event_t{ - typ: yaml_SCALAR_EVENT, - start_mark: mark, - end_mark: mark, - value: nil, // Empty - implicit: true, - style: yaml_style_t(yaml_PLAIN_SCALAR_STYLE), - } - return true -} - -var default_tag_directives = []yaml_tag_directive_t{ - {[]byte("!"), []byte("!")}, - {[]byte("!!"), []byte("tag:yaml.org,2002:")}, -} - -// Parse directives. -func yaml_parser_process_directives(parser *yaml_parser_t, - version_directive_ref **yaml_version_directive_t, - tag_directives_ref *[]yaml_tag_directive_t) bool { - - var version_directive *yaml_version_directive_t - var tag_directives []yaml_tag_directive_t - - token := peek_token(parser) - if token == nil { - return false - } - - for token.typ == yaml_VERSION_DIRECTIVE_TOKEN || token.typ == yaml_TAG_DIRECTIVE_TOKEN { - if token.typ == yaml_VERSION_DIRECTIVE_TOKEN { - if version_directive != nil { - yaml_parser_set_parser_error(parser, - "found duplicate %YAML directive", token.start_mark) - return false - } - if token.major != 1 || token.minor != 1 { - yaml_parser_set_parser_error(parser, - "found incompatible YAML document", token.start_mark) - return false - } - version_directive = &yaml_version_directive_t{ - major: token.major, - minor: token.minor, - } - } else if token.typ == yaml_TAG_DIRECTIVE_TOKEN { - value := yaml_tag_directive_t{ - handle: token.value, - prefix: token.prefix, - } - if !yaml_parser_append_tag_directive(parser, value, false, token.start_mark) { - return false - } - tag_directives = append(tag_directives, value) - } - - skip_token(parser) - token = peek_token(parser) - if token == nil { - return false - } - } - - for i := range default_tag_directives { - if !yaml_parser_append_tag_directive(parser, default_tag_directives[i], true, token.start_mark) { - return false - } - } - - if version_directive_ref != nil { - *version_directive_ref = version_directive - } - if tag_directives_ref != nil { - *tag_directives_ref = tag_directives - } - return true -} - -// Append a tag directive to the directives stack. -func yaml_parser_append_tag_directive(parser *yaml_parser_t, value yaml_tag_directive_t, allow_duplicates bool, mark yaml_mark_t) bool { - for i := range parser.tag_directives { - if bytes.Equal(value.handle, parser.tag_directives[i].handle) { - if allow_duplicates { - return true - } - return yaml_parser_set_parser_error(parser, "found duplicate %TAG directive", mark) - } - } - - // [Go] I suspect the copy is unnecessary. This was likely done - // because there was no way to track ownership of the data. - value_copy := yaml_tag_directive_t{ - handle: make([]byte, len(value.handle)), - prefix: make([]byte, len(value.prefix)), - } - copy(value_copy.handle, value.handle) - copy(value_copy.prefix, value.prefix) - parser.tag_directives = append(parser.tag_directives, value_copy) - return true -} diff --git a/vendor/go.yaml.in/yaml/v2/readerc.go b/vendor/go.yaml.in/yaml/v2/readerc.go deleted file mode 100644 index 7c1f5fac3..000000000 --- a/vendor/go.yaml.in/yaml/v2/readerc.go +++ /dev/null @@ -1,412 +0,0 @@ -package yaml - -import ( - "io" -) - -// Set the reader error and return 0. -func yaml_parser_set_reader_error(parser *yaml_parser_t, problem string, offset int, value int) bool { - parser.error = yaml_READER_ERROR - parser.problem = problem - parser.problem_offset = offset - parser.problem_value = value - return false -} - -// Byte order marks. -const ( - bom_UTF8 = "\xef\xbb\xbf" - bom_UTF16LE = "\xff\xfe" - bom_UTF16BE = "\xfe\xff" -) - -// Determine the input stream encoding by checking the BOM symbol. If no BOM is -// found, the UTF-8 encoding is assumed. Return 1 on success, 0 on failure. -func yaml_parser_determine_encoding(parser *yaml_parser_t) bool { - // Ensure that we had enough bytes in the raw buffer. - for !parser.eof && len(parser.raw_buffer)-parser.raw_buffer_pos < 3 { - if !yaml_parser_update_raw_buffer(parser) { - return false - } - } - - // Determine the encoding. - buf := parser.raw_buffer - pos := parser.raw_buffer_pos - avail := len(buf) - pos - if avail >= 2 && buf[pos] == bom_UTF16LE[0] && buf[pos+1] == bom_UTF16LE[1] { - parser.encoding = yaml_UTF16LE_ENCODING - parser.raw_buffer_pos += 2 - parser.offset += 2 - } else if avail >= 2 && buf[pos] == bom_UTF16BE[0] && buf[pos+1] == bom_UTF16BE[1] { - parser.encoding = yaml_UTF16BE_ENCODING - parser.raw_buffer_pos += 2 - parser.offset += 2 - } else if avail >= 3 && buf[pos] == bom_UTF8[0] && buf[pos+1] == bom_UTF8[1] && buf[pos+2] == bom_UTF8[2] { - parser.encoding = yaml_UTF8_ENCODING - parser.raw_buffer_pos += 3 - parser.offset += 3 - } else { - parser.encoding = yaml_UTF8_ENCODING - } - return true -} - -// Update the raw buffer. -func yaml_parser_update_raw_buffer(parser *yaml_parser_t) bool { - size_read := 0 - - // Return if the raw buffer is full. - if parser.raw_buffer_pos == 0 && len(parser.raw_buffer) == cap(parser.raw_buffer) { - return true - } - - // Return on EOF. - if parser.eof { - return true - } - - // Move the remaining bytes in the raw buffer to the beginning. - if parser.raw_buffer_pos > 0 && parser.raw_buffer_pos < len(parser.raw_buffer) { - copy(parser.raw_buffer, parser.raw_buffer[parser.raw_buffer_pos:]) - } - parser.raw_buffer = parser.raw_buffer[:len(parser.raw_buffer)-parser.raw_buffer_pos] - parser.raw_buffer_pos = 0 - - // Call the read handler to fill the buffer. - size_read, err := parser.read_handler(parser, parser.raw_buffer[len(parser.raw_buffer):cap(parser.raw_buffer)]) - parser.raw_buffer = parser.raw_buffer[:len(parser.raw_buffer)+size_read] - if err == io.EOF { - parser.eof = true - } else if err != nil { - return yaml_parser_set_reader_error(parser, "input error: "+err.Error(), parser.offset, -1) - } - return true -} - -// Ensure that the buffer contains at least `length` characters. -// Return true on success, false on failure. -// -// The length is supposed to be significantly less that the buffer size. -func yaml_parser_update_buffer(parser *yaml_parser_t, length int) bool { - if parser.read_handler == nil { - panic("read handler must be set") - } - - // [Go] This function was changed to guarantee the requested length size at EOF. - // The fact we need to do this is pretty awful, but the description above implies - // for that to be the case, and there are tests - - // If the EOF flag is set and the raw buffer is empty, do nothing. - if parser.eof && parser.raw_buffer_pos == len(parser.raw_buffer) { - // [Go] ACTUALLY! Read the documentation of this function above. - // This is just broken. To return true, we need to have the - // given length in the buffer. Not doing that means every single - // check that calls this function to make sure the buffer has a - // given length is Go) panicking; or C) accessing invalid memory. - //return true - } - - // Return if the buffer contains enough characters. - if parser.unread >= length { - return true - } - - // Determine the input encoding if it is not known yet. - if parser.encoding == yaml_ANY_ENCODING { - if !yaml_parser_determine_encoding(parser) { - return false - } - } - - // Move the unread characters to the beginning of the buffer. - buffer_len := len(parser.buffer) - if parser.buffer_pos > 0 && parser.buffer_pos < buffer_len { - copy(parser.buffer, parser.buffer[parser.buffer_pos:]) - buffer_len -= parser.buffer_pos - parser.buffer_pos = 0 - } else if parser.buffer_pos == buffer_len { - buffer_len = 0 - parser.buffer_pos = 0 - } - - // Open the whole buffer for writing, and cut it before returning. - parser.buffer = parser.buffer[:cap(parser.buffer)] - - // Fill the buffer until it has enough characters. - first := true - for parser.unread < length { - - // Fill the raw buffer if necessary. - if !first || parser.raw_buffer_pos == len(parser.raw_buffer) { - if !yaml_parser_update_raw_buffer(parser) { - parser.buffer = parser.buffer[:buffer_len] - return false - } - } - first = false - - // Decode the raw buffer. - inner: - for parser.raw_buffer_pos != len(parser.raw_buffer) { - var value rune - var width int - - raw_unread := len(parser.raw_buffer) - parser.raw_buffer_pos - - // Decode the next character. - switch parser.encoding { - case yaml_UTF8_ENCODING: - // Decode a UTF-8 character. Check RFC 3629 - // (http://www.ietf.org/rfc/rfc3629.txt) for more details. - // - // The following table (taken from the RFC) is used for - // decoding. - // - // Char. number range | UTF-8 octet sequence - // (hexadecimal) | (binary) - // --------------------+------------------------------------ - // 0000 0000-0000 007F | 0xxxxxxx - // 0000 0080-0000 07FF | 110xxxxx 10xxxxxx - // 0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx - // 0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx - // - // Additionally, the characters in the range 0xD800-0xDFFF - // are prohibited as they are reserved for use with UTF-16 - // surrogate pairs. - - // Determine the length of the UTF-8 sequence. - octet := parser.raw_buffer[parser.raw_buffer_pos] - switch { - case octet&0x80 == 0x00: - width = 1 - case octet&0xE0 == 0xC0: - width = 2 - case octet&0xF0 == 0xE0: - width = 3 - case octet&0xF8 == 0xF0: - width = 4 - default: - // The leading octet is invalid. - return yaml_parser_set_reader_error(parser, - "invalid leading UTF-8 octet", - parser.offset, int(octet)) - } - - // Check if the raw buffer contains an incomplete character. - if width > raw_unread { - if parser.eof { - return yaml_parser_set_reader_error(parser, - "incomplete UTF-8 octet sequence", - parser.offset, -1) - } - break inner - } - - // Decode the leading octet. - switch { - case octet&0x80 == 0x00: - value = rune(octet & 0x7F) - case octet&0xE0 == 0xC0: - value = rune(octet & 0x1F) - case octet&0xF0 == 0xE0: - value = rune(octet & 0x0F) - case octet&0xF8 == 0xF0: - value = rune(octet & 0x07) - default: - value = 0 - } - - // Check and decode the trailing octets. - for k := 1; k < width; k++ { - octet = parser.raw_buffer[parser.raw_buffer_pos+k] - - // Check if the octet is valid. - if (octet & 0xC0) != 0x80 { - return yaml_parser_set_reader_error(parser, - "invalid trailing UTF-8 octet", - parser.offset+k, int(octet)) - } - - // Decode the octet. - value = (value << 6) + rune(octet&0x3F) - } - - // Check the length of the sequence against the value. - switch { - case width == 1: - case width == 2 && value >= 0x80: - case width == 3 && value >= 0x800: - case width == 4 && value >= 0x10000: - default: - return yaml_parser_set_reader_error(parser, - "invalid length of a UTF-8 sequence", - parser.offset, -1) - } - - // Check the range of the value. - if value >= 0xD800 && value <= 0xDFFF || value > 0x10FFFF { - return yaml_parser_set_reader_error(parser, - "invalid Unicode character", - parser.offset, int(value)) - } - - case yaml_UTF16LE_ENCODING, yaml_UTF16BE_ENCODING: - var low, high int - if parser.encoding == yaml_UTF16LE_ENCODING { - low, high = 0, 1 - } else { - low, high = 1, 0 - } - - // The UTF-16 encoding is not as simple as one might - // naively think. Check RFC 2781 - // (http://www.ietf.org/rfc/rfc2781.txt). - // - // Normally, two subsequent bytes describe a Unicode - // character. However a special technique (called a - // surrogate pair) is used for specifying character - // values larger than 0xFFFF. - // - // A surrogate pair consists of two pseudo-characters: - // high surrogate area (0xD800-0xDBFF) - // low surrogate area (0xDC00-0xDFFF) - // - // The following formulas are used for decoding - // and encoding characters using surrogate pairs: - // - // U = U' + 0x10000 (0x01 00 00 <= U <= 0x10 FF FF) - // U' = yyyyyyyyyyxxxxxxxxxx (0 <= U' <= 0x0F FF FF) - // W1 = 110110yyyyyyyyyy - // W2 = 110111xxxxxxxxxx - // - // where U is the character value, W1 is the high surrogate - // area, W2 is the low surrogate area. - - // Check for incomplete UTF-16 character. - if raw_unread < 2 { - if parser.eof { - return yaml_parser_set_reader_error(parser, - "incomplete UTF-16 character", - parser.offset, -1) - } - break inner - } - - // Get the character. - value = rune(parser.raw_buffer[parser.raw_buffer_pos+low]) + - (rune(parser.raw_buffer[parser.raw_buffer_pos+high]) << 8) - - // Check for unexpected low surrogate area. - if value&0xFC00 == 0xDC00 { - return yaml_parser_set_reader_error(parser, - "unexpected low surrogate area", - parser.offset, int(value)) - } - - // Check for a high surrogate area. - if value&0xFC00 == 0xD800 { - width = 4 - - // Check for incomplete surrogate pair. - if raw_unread < 4 { - if parser.eof { - return yaml_parser_set_reader_error(parser, - "incomplete UTF-16 surrogate pair", - parser.offset, -1) - } - break inner - } - - // Get the next character. - value2 := rune(parser.raw_buffer[parser.raw_buffer_pos+low+2]) + - (rune(parser.raw_buffer[parser.raw_buffer_pos+high+2]) << 8) - - // Check for a low surrogate area. - if value2&0xFC00 != 0xDC00 { - return yaml_parser_set_reader_error(parser, - "expected low surrogate area", - parser.offset+2, int(value2)) - } - - // Generate the value of the surrogate pair. - value = 0x10000 + ((value & 0x3FF) << 10) + (value2 & 0x3FF) - } else { - width = 2 - } - - default: - panic("impossible") - } - - // Check if the character is in the allowed range: - // #x9 | #xA | #xD | [#x20-#x7E] (8 bit) - // | #x85 | [#xA0-#xD7FF] | [#xE000-#xFFFD] (16 bit) - // | [#x10000-#x10FFFF] (32 bit) - switch { - case value == 0x09: - case value == 0x0A: - case value == 0x0D: - case value >= 0x20 && value <= 0x7E: - case value == 0x85: - case value >= 0xA0 && value <= 0xD7FF: - case value >= 0xE000 && value <= 0xFFFD: - case value >= 0x10000 && value <= 0x10FFFF: - default: - return yaml_parser_set_reader_error(parser, - "control characters are not allowed", - parser.offset, int(value)) - } - - // Move the raw pointers. - parser.raw_buffer_pos += width - parser.offset += width - - // Finally put the character into the buffer. - if value <= 0x7F { - // 0000 0000-0000 007F . 0xxxxxxx - parser.buffer[buffer_len+0] = byte(value) - buffer_len += 1 - } else if value <= 0x7FF { - // 0000 0080-0000 07FF . 110xxxxx 10xxxxxx - parser.buffer[buffer_len+0] = byte(0xC0 + (value >> 6)) - parser.buffer[buffer_len+1] = byte(0x80 + (value & 0x3F)) - buffer_len += 2 - } else if value <= 0xFFFF { - // 0000 0800-0000 FFFF . 1110xxxx 10xxxxxx 10xxxxxx - parser.buffer[buffer_len+0] = byte(0xE0 + (value >> 12)) - parser.buffer[buffer_len+1] = byte(0x80 + ((value >> 6) & 0x3F)) - parser.buffer[buffer_len+2] = byte(0x80 + (value & 0x3F)) - buffer_len += 3 - } else { - // 0001 0000-0010 FFFF . 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx - parser.buffer[buffer_len+0] = byte(0xF0 + (value >> 18)) - parser.buffer[buffer_len+1] = byte(0x80 + ((value >> 12) & 0x3F)) - parser.buffer[buffer_len+2] = byte(0x80 + ((value >> 6) & 0x3F)) - parser.buffer[buffer_len+3] = byte(0x80 + (value & 0x3F)) - buffer_len += 4 - } - - parser.unread++ - } - - // On EOF, put NUL into the buffer and return. - if parser.eof { - parser.buffer[buffer_len] = 0 - buffer_len++ - parser.unread++ - break - } - } - // [Go] Read the documentation of this function above. To return true, - // we need to have the given length in the buffer. Not doing that means - // every single check that calls this function to make sure the buffer - // has a given length is Go) panicking; or C) accessing invalid memory. - // This happens here due to the EOF above breaking early. - for buffer_len < length { - parser.buffer[buffer_len] = 0 - buffer_len++ - } - parser.buffer = parser.buffer[:buffer_len] - return true -} diff --git a/vendor/go.yaml.in/yaml/v2/resolve.go b/vendor/go.yaml.in/yaml/v2/resolve.go deleted file mode 100644 index 4120e0c91..000000000 --- a/vendor/go.yaml.in/yaml/v2/resolve.go +++ /dev/null @@ -1,258 +0,0 @@ -package yaml - -import ( - "encoding/base64" - "math" - "regexp" - "strconv" - "strings" - "time" -) - -type resolveMapItem struct { - value interface{} - tag string -} - -var resolveTable = make([]byte, 256) -var resolveMap = make(map[string]resolveMapItem) - -func init() { - t := resolveTable - t[int('+')] = 'S' // Sign - t[int('-')] = 'S' - for _, c := range "0123456789" { - t[int(c)] = 'D' // Digit - } - for _, c := range "yYnNtTfFoO~" { - t[int(c)] = 'M' // In map - } - t[int('.')] = '.' // Float (potentially in map) - - var resolveMapList = []struct { - v interface{} - tag string - l []string - }{ - {true, yaml_BOOL_TAG, []string{"y", "Y", "yes", "Yes", "YES"}}, - {true, yaml_BOOL_TAG, []string{"true", "True", "TRUE"}}, - {true, yaml_BOOL_TAG, []string{"on", "On", "ON"}}, - {false, yaml_BOOL_TAG, []string{"n", "N", "no", "No", "NO"}}, - {false, yaml_BOOL_TAG, []string{"false", "False", "FALSE"}}, - {false, yaml_BOOL_TAG, []string{"off", "Off", "OFF"}}, - {nil, yaml_NULL_TAG, []string{"", "~", "null", "Null", "NULL"}}, - {math.NaN(), yaml_FLOAT_TAG, []string{".nan", ".NaN", ".NAN"}}, - {math.Inf(+1), yaml_FLOAT_TAG, []string{".inf", ".Inf", ".INF"}}, - {math.Inf(+1), yaml_FLOAT_TAG, []string{"+.inf", "+.Inf", "+.INF"}}, - {math.Inf(-1), yaml_FLOAT_TAG, []string{"-.inf", "-.Inf", "-.INF"}}, - {"<<", yaml_MERGE_TAG, []string{"<<"}}, - } - - m := resolveMap - for _, item := range resolveMapList { - for _, s := range item.l { - m[s] = resolveMapItem{item.v, item.tag} - } - } -} - -const longTagPrefix = "tag:yaml.org,2002:" - -func shortTag(tag string) string { - // TODO This can easily be made faster and produce less garbage. - if strings.HasPrefix(tag, longTagPrefix) { - return "!!" + tag[len(longTagPrefix):] - } - return tag -} - -func longTag(tag string) string { - if strings.HasPrefix(tag, "!!") { - return longTagPrefix + tag[2:] - } - return tag -} - -func resolvableTag(tag string) bool { - switch tag { - case "", yaml_STR_TAG, yaml_BOOL_TAG, yaml_INT_TAG, yaml_FLOAT_TAG, yaml_NULL_TAG, yaml_TIMESTAMP_TAG: - return true - } - return false -} - -var yamlStyleFloat = regexp.MustCompile(`^[-+]?(\.[0-9]+|[0-9]+(\.[0-9]*)?)([eE][-+]?[0-9]+)?$`) - -func resolve(tag string, in string) (rtag string, out interface{}) { - if !resolvableTag(tag) { - return tag, in - } - - defer func() { - switch tag { - case "", rtag, yaml_STR_TAG, yaml_BINARY_TAG: - return - case yaml_FLOAT_TAG: - if rtag == yaml_INT_TAG { - switch v := out.(type) { - case int64: - rtag = yaml_FLOAT_TAG - out = float64(v) - return - case int: - rtag = yaml_FLOAT_TAG - out = float64(v) - return - } - } - } - failf("cannot decode %s `%s` as a %s", shortTag(rtag), in, shortTag(tag)) - }() - - // Any data is accepted as a !!str or !!binary. - // Otherwise, the prefix is enough of a hint about what it might be. - hint := byte('N') - if in != "" { - hint = resolveTable[in[0]] - } - if hint != 0 && tag != yaml_STR_TAG && tag != yaml_BINARY_TAG { - // Handle things we can lookup in a map. - if item, ok := resolveMap[in]; ok { - return item.tag, item.value - } - - // Base 60 floats are a bad idea, were dropped in YAML 1.2, and - // are purposefully unsupported here. They're still quoted on - // the way out for compatibility with other parser, though. - - switch hint { - case 'M': - // We've already checked the map above. - - case '.': - // Not in the map, so maybe a normal float. - floatv, err := strconv.ParseFloat(in, 64) - if err == nil { - return yaml_FLOAT_TAG, floatv - } - - case 'D', 'S': - // Int, float, or timestamp. - // Only try values as a timestamp if the value is unquoted or there's an explicit - // !!timestamp tag. - if tag == "" || tag == yaml_TIMESTAMP_TAG { - t, ok := parseTimestamp(in) - if ok { - return yaml_TIMESTAMP_TAG, t - } - } - - plain := strings.Replace(in, "_", "", -1) - intv, err := strconv.ParseInt(plain, 0, 64) - if err == nil { - if intv == int64(int(intv)) { - return yaml_INT_TAG, int(intv) - } else { - return yaml_INT_TAG, intv - } - } - uintv, err := strconv.ParseUint(plain, 0, 64) - if err == nil { - return yaml_INT_TAG, uintv - } - if yamlStyleFloat.MatchString(plain) { - floatv, err := strconv.ParseFloat(plain, 64) - if err == nil { - return yaml_FLOAT_TAG, floatv - } - } - if strings.HasPrefix(plain, "0b") { - intv, err := strconv.ParseInt(plain[2:], 2, 64) - if err == nil { - if intv == int64(int(intv)) { - return yaml_INT_TAG, int(intv) - } else { - return yaml_INT_TAG, intv - } - } - uintv, err := strconv.ParseUint(plain[2:], 2, 64) - if err == nil { - return yaml_INT_TAG, uintv - } - } else if strings.HasPrefix(plain, "-0b") { - intv, err := strconv.ParseInt("-" + plain[3:], 2, 64) - if err == nil { - if true || intv == int64(int(intv)) { - return yaml_INT_TAG, int(intv) - } else { - return yaml_INT_TAG, intv - } - } - } - default: - panic("resolveTable item not yet handled: " + string(rune(hint)) + " (with " + in + ")") - } - } - return yaml_STR_TAG, in -} - -// encodeBase64 encodes s as base64 that is broken up into multiple lines -// as appropriate for the resulting length. -func encodeBase64(s string) string { - const lineLen = 70 - encLen := base64.StdEncoding.EncodedLen(len(s)) - lines := encLen/lineLen + 1 - buf := make([]byte, encLen*2+lines) - in := buf[0:encLen] - out := buf[encLen:] - base64.StdEncoding.Encode(in, []byte(s)) - k := 0 - for i := 0; i < len(in); i += lineLen { - j := i + lineLen - if j > len(in) { - j = len(in) - } - k += copy(out[k:], in[i:j]) - if lines > 1 { - out[k] = '\n' - k++ - } - } - return string(out[:k]) -} - -// This is a subset of the formats allowed by the regular expression -// defined at http://yaml.org/type/timestamp.html. -var allowedTimestampFormats = []string{ - "2006-1-2T15:4:5.999999999Z07:00", // RCF3339Nano with short date fields. - "2006-1-2t15:4:5.999999999Z07:00", // RFC3339Nano with short date fields and lower-case "t". - "2006-1-2 15:4:5.999999999", // space separated with no time zone - "2006-1-2", // date only - // Notable exception: time.Parse cannot handle: "2001-12-14 21:59:43.10 -5" - // from the set of examples. -} - -// parseTimestamp parses s as a timestamp string and -// returns the timestamp and reports whether it succeeded. -// Timestamp formats are defined at http://yaml.org/type/timestamp.html -func parseTimestamp(s string) (time.Time, bool) { - // TODO write code to check all the formats supported by - // http://yaml.org/type/timestamp.html instead of using time.Parse. - - // Quick check: all date formats start with YYYY-. - i := 0 - for ; i < len(s); i++ { - if c := s[i]; c < '0' || c > '9' { - break - } - } - if i != 4 || i == len(s) || s[i] != '-' { - return time.Time{}, false - } - for _, format := range allowedTimestampFormats { - if t, err := time.Parse(format, s); err == nil { - return t, true - } - } - return time.Time{}, false -} diff --git a/vendor/go.yaml.in/yaml/v2/scannerc.go b/vendor/go.yaml.in/yaml/v2/scannerc.go deleted file mode 100644 index 0b9bb6030..000000000 --- a/vendor/go.yaml.in/yaml/v2/scannerc.go +++ /dev/null @@ -1,2711 +0,0 @@ -package yaml - -import ( - "bytes" - "fmt" -) - -// Introduction -// ************ -// -// The following notes assume that you are familiar with the YAML specification -// (http://yaml.org/spec/1.2/spec.html). We mostly follow it, although in -// some cases we are less restrictive that it requires. -// -// The process of transforming a YAML stream into a sequence of events is -// divided on two steps: Scanning and Parsing. -// -// The Scanner transforms the input stream into a sequence of tokens, while the -// parser transform the sequence of tokens produced by the Scanner into a -// sequence of parsing events. -// -// The Scanner is rather clever and complicated. The Parser, on the contrary, -// is a straightforward implementation of a recursive-descendant parser (or, -// LL(1) parser, as it is usually called). -// -// Actually there are two issues of Scanning that might be called "clever", the -// rest is quite straightforward. The issues are "block collection start" and -// "simple keys". Both issues are explained below in details. -// -// Here the Scanning step is explained and implemented. We start with the list -// of all the tokens produced by the Scanner together with short descriptions. -// -// Now, tokens: -// -// STREAM-START(encoding) # The stream start. -// STREAM-END # The stream end. -// VERSION-DIRECTIVE(major,minor) # The '%YAML' directive. -// TAG-DIRECTIVE(handle,prefix) # The '%TAG' directive. -// DOCUMENT-START # '---' -// DOCUMENT-END # '...' -// BLOCK-SEQUENCE-START # Indentation increase denoting a block -// BLOCK-MAPPING-START # sequence or a block mapping. -// BLOCK-END # Indentation decrease. -// FLOW-SEQUENCE-START # '[' -// FLOW-SEQUENCE-END # ']' -// BLOCK-SEQUENCE-START # '{' -// BLOCK-SEQUENCE-END # '}' -// BLOCK-ENTRY # '-' -// FLOW-ENTRY # ',' -// KEY # '?' or nothing (simple keys). -// VALUE # ':' -// ALIAS(anchor) # '*anchor' -// ANCHOR(anchor) # '&anchor' -// TAG(handle,suffix) # '!handle!suffix' -// SCALAR(value,style) # A scalar. -// -// The following two tokens are "virtual" tokens denoting the beginning and the -// end of the stream: -// -// STREAM-START(encoding) -// STREAM-END -// -// We pass the information about the input stream encoding with the -// STREAM-START token. -// -// The next two tokens are responsible for tags: -// -// VERSION-DIRECTIVE(major,minor) -// TAG-DIRECTIVE(handle,prefix) -// -// Example: -// -// %YAML 1.1 -// %TAG ! !foo -// %TAG !yaml! tag:yaml.org,2002: -// --- -// -// The correspoding sequence of tokens: -// -// STREAM-START(utf-8) -// VERSION-DIRECTIVE(1,1) -// TAG-DIRECTIVE("!","!foo") -// TAG-DIRECTIVE("!yaml","tag:yaml.org,2002:") -// DOCUMENT-START -// STREAM-END -// -// Note that the VERSION-DIRECTIVE and TAG-DIRECTIVE tokens occupy a whole -// line. -// -// The document start and end indicators are represented by: -// -// DOCUMENT-START -// DOCUMENT-END -// -// Note that if a YAML stream contains an implicit document (without '---' -// and '...' indicators), no DOCUMENT-START and DOCUMENT-END tokens will be -// produced. -// -// In the following examples, we present whole documents together with the -// produced tokens. -// -// 1. An implicit document: -// -// 'a scalar' -// -// Tokens: -// -// STREAM-START(utf-8) -// SCALAR("a scalar",single-quoted) -// STREAM-END -// -// 2. An explicit document: -// -// --- -// 'a scalar' -// ... -// -// Tokens: -// -// STREAM-START(utf-8) -// DOCUMENT-START -// SCALAR("a scalar",single-quoted) -// DOCUMENT-END -// STREAM-END -// -// 3. Several documents in a stream: -// -// 'a scalar' -// --- -// 'another scalar' -// --- -// 'yet another scalar' -// -// Tokens: -// -// STREAM-START(utf-8) -// SCALAR("a scalar",single-quoted) -// DOCUMENT-START -// SCALAR("another scalar",single-quoted) -// DOCUMENT-START -// SCALAR("yet another scalar",single-quoted) -// STREAM-END -// -// We have already introduced the SCALAR token above. The following tokens are -// used to describe aliases, anchors, tag, and scalars: -// -// ALIAS(anchor) -// ANCHOR(anchor) -// TAG(handle,suffix) -// SCALAR(value,style) -// -// The following series of examples illustrate the usage of these tokens: -// -// 1. A recursive sequence: -// -// &A [ *A ] -// -// Tokens: -// -// STREAM-START(utf-8) -// ANCHOR("A") -// FLOW-SEQUENCE-START -// ALIAS("A") -// FLOW-SEQUENCE-END -// STREAM-END -// -// 2. A tagged scalar: -// -// !!float "3.14" # A good approximation. -// -// Tokens: -// -// STREAM-START(utf-8) -// TAG("!!","float") -// SCALAR("3.14",double-quoted) -// STREAM-END -// -// 3. Various scalar styles: -// -// --- # Implicit empty plain scalars do not produce tokens. -// --- a plain scalar -// --- 'a single-quoted scalar' -// --- "a double-quoted scalar" -// --- |- -// a literal scalar -// --- >- -// a folded -// scalar -// -// Tokens: -// -// STREAM-START(utf-8) -// DOCUMENT-START -// DOCUMENT-START -// SCALAR("a plain scalar",plain) -// DOCUMENT-START -// SCALAR("a single-quoted scalar",single-quoted) -// DOCUMENT-START -// SCALAR("a double-quoted scalar",double-quoted) -// DOCUMENT-START -// SCALAR("a literal scalar",literal) -// DOCUMENT-START -// SCALAR("a folded scalar",folded) -// STREAM-END -// -// Now it's time to review collection-related tokens. We will start with -// flow collections: -// -// FLOW-SEQUENCE-START -// FLOW-SEQUENCE-END -// FLOW-MAPPING-START -// FLOW-MAPPING-END -// FLOW-ENTRY -// KEY -// VALUE -// -// The tokens FLOW-SEQUENCE-START, FLOW-SEQUENCE-END, FLOW-MAPPING-START, and -// FLOW-MAPPING-END represent the indicators '[', ']', '{', and '}' -// correspondingly. FLOW-ENTRY represent the ',' indicator. Finally the -// indicators '?' and ':', which are used for denoting mapping keys and values, -// are represented by the KEY and VALUE tokens. -// -// The following examples show flow collections: -// -// 1. A flow sequence: -// -// [item 1, item 2, item 3] -// -// Tokens: -// -// STREAM-START(utf-8) -// FLOW-SEQUENCE-START -// SCALAR("item 1",plain) -// FLOW-ENTRY -// SCALAR("item 2",plain) -// FLOW-ENTRY -// SCALAR("item 3",plain) -// FLOW-SEQUENCE-END -// STREAM-END -// -// 2. A flow mapping: -// -// { -// a simple key: a value, # Note that the KEY token is produced. -// ? a complex key: another value, -// } -// -// Tokens: -// -// STREAM-START(utf-8) -// FLOW-MAPPING-START -// KEY -// SCALAR("a simple key",plain) -// VALUE -// SCALAR("a value",plain) -// FLOW-ENTRY -// KEY -// SCALAR("a complex key",plain) -// VALUE -// SCALAR("another value",plain) -// FLOW-ENTRY -// FLOW-MAPPING-END -// STREAM-END -// -// A simple key is a key which is not denoted by the '?' indicator. Note that -// the Scanner still produce the KEY token whenever it encounters a simple key. -// -// For scanning block collections, the following tokens are used (note that we -// repeat KEY and VALUE here): -// -// BLOCK-SEQUENCE-START -// BLOCK-MAPPING-START -// BLOCK-END -// BLOCK-ENTRY -// KEY -// VALUE -// -// The tokens BLOCK-SEQUENCE-START and BLOCK-MAPPING-START denote indentation -// increase that precedes a block collection (cf. the INDENT token in Python). -// The token BLOCK-END denote indentation decrease that ends a block collection -// (cf. the DEDENT token in Python). However YAML has some syntax pecularities -// that makes detections of these tokens more complex. -// -// The tokens BLOCK-ENTRY, KEY, and VALUE are used to represent the indicators -// '-', '?', and ':' correspondingly. -// -// The following examples show how the tokens BLOCK-SEQUENCE-START, -// BLOCK-MAPPING-START, and BLOCK-END are emitted by the Scanner: -// -// 1. Block sequences: -// -// - item 1 -// - item 2 -// - -// - item 3.1 -// - item 3.2 -// - -// key 1: value 1 -// key 2: value 2 -// -// Tokens: -// -// STREAM-START(utf-8) -// BLOCK-SEQUENCE-START -// BLOCK-ENTRY -// SCALAR("item 1",plain) -// BLOCK-ENTRY -// SCALAR("item 2",plain) -// BLOCK-ENTRY -// BLOCK-SEQUENCE-START -// BLOCK-ENTRY -// SCALAR("item 3.1",plain) -// BLOCK-ENTRY -// SCALAR("item 3.2",plain) -// BLOCK-END -// BLOCK-ENTRY -// BLOCK-MAPPING-START -// KEY -// SCALAR("key 1",plain) -// VALUE -// SCALAR("value 1",plain) -// KEY -// SCALAR("key 2",plain) -// VALUE -// SCALAR("value 2",plain) -// BLOCK-END -// BLOCK-END -// STREAM-END -// -// 2. Block mappings: -// -// a simple key: a value # The KEY token is produced here. -// ? a complex key -// : another value -// a mapping: -// key 1: value 1 -// key 2: value 2 -// a sequence: -// - item 1 -// - item 2 -// -// Tokens: -// -// STREAM-START(utf-8) -// BLOCK-MAPPING-START -// KEY -// SCALAR("a simple key",plain) -// VALUE -// SCALAR("a value",plain) -// KEY -// SCALAR("a complex key",plain) -// VALUE -// SCALAR("another value",plain) -// KEY -// SCALAR("a mapping",plain) -// BLOCK-MAPPING-START -// KEY -// SCALAR("key 1",plain) -// VALUE -// SCALAR("value 1",plain) -// KEY -// SCALAR("key 2",plain) -// VALUE -// SCALAR("value 2",plain) -// BLOCK-END -// KEY -// SCALAR("a sequence",plain) -// VALUE -// BLOCK-SEQUENCE-START -// BLOCK-ENTRY -// SCALAR("item 1",plain) -// BLOCK-ENTRY -// SCALAR("item 2",plain) -// BLOCK-END -// BLOCK-END -// STREAM-END -// -// YAML does not always require to start a new block collection from a new -// line. If the current line contains only '-', '?', and ':' indicators, a new -// block collection may start at the current line. The following examples -// illustrate this case: -// -// 1. Collections in a sequence: -// -// - - item 1 -// - item 2 -// - key 1: value 1 -// key 2: value 2 -// - ? complex key -// : complex value -// -// Tokens: -// -// STREAM-START(utf-8) -// BLOCK-SEQUENCE-START -// BLOCK-ENTRY -// BLOCK-SEQUENCE-START -// BLOCK-ENTRY -// SCALAR("item 1",plain) -// BLOCK-ENTRY -// SCALAR("item 2",plain) -// BLOCK-END -// BLOCK-ENTRY -// BLOCK-MAPPING-START -// KEY -// SCALAR("key 1",plain) -// VALUE -// SCALAR("value 1",plain) -// KEY -// SCALAR("key 2",plain) -// VALUE -// SCALAR("value 2",plain) -// BLOCK-END -// BLOCK-ENTRY -// BLOCK-MAPPING-START -// KEY -// SCALAR("complex key") -// VALUE -// SCALAR("complex value") -// BLOCK-END -// BLOCK-END -// STREAM-END -// -// 2. Collections in a mapping: -// -// ? a sequence -// : - item 1 -// - item 2 -// ? a mapping -// : key 1: value 1 -// key 2: value 2 -// -// Tokens: -// -// STREAM-START(utf-8) -// BLOCK-MAPPING-START -// KEY -// SCALAR("a sequence",plain) -// VALUE -// BLOCK-SEQUENCE-START -// BLOCK-ENTRY -// SCALAR("item 1",plain) -// BLOCK-ENTRY -// SCALAR("item 2",plain) -// BLOCK-END -// KEY -// SCALAR("a mapping",plain) -// VALUE -// BLOCK-MAPPING-START -// KEY -// SCALAR("key 1",plain) -// VALUE -// SCALAR("value 1",plain) -// KEY -// SCALAR("key 2",plain) -// VALUE -// SCALAR("value 2",plain) -// BLOCK-END -// BLOCK-END -// STREAM-END -// -// YAML also permits non-indented sequences if they are included into a block -// mapping. In this case, the token BLOCK-SEQUENCE-START is not produced: -// -// key: -// - item 1 # BLOCK-SEQUENCE-START is NOT produced here. -// - item 2 -// -// Tokens: -// -// STREAM-START(utf-8) -// BLOCK-MAPPING-START -// KEY -// SCALAR("key",plain) -// VALUE -// BLOCK-ENTRY -// SCALAR("item 1",plain) -// BLOCK-ENTRY -// SCALAR("item 2",plain) -// BLOCK-END -// - -// Ensure that the buffer contains the required number of characters. -// Return true on success, false on failure (reader error or memory error). -func cache(parser *yaml_parser_t, length int) bool { - // [Go] This was inlined: !cache(A, B) -> unread < B && !update(A, B) - return parser.unread >= length || yaml_parser_update_buffer(parser, length) -} - -// Advance the buffer pointer. -func skip(parser *yaml_parser_t) { - parser.mark.index++ - parser.mark.column++ - parser.unread-- - parser.buffer_pos += width(parser.buffer[parser.buffer_pos]) -} - -func skip_line(parser *yaml_parser_t) { - if is_crlf(parser.buffer, parser.buffer_pos) { - parser.mark.index += 2 - parser.mark.column = 0 - parser.mark.line++ - parser.unread -= 2 - parser.buffer_pos += 2 - } else if is_break(parser.buffer, parser.buffer_pos) { - parser.mark.index++ - parser.mark.column = 0 - parser.mark.line++ - parser.unread-- - parser.buffer_pos += width(parser.buffer[parser.buffer_pos]) - } -} - -// Copy a character to a string buffer and advance pointers. -func read(parser *yaml_parser_t, s []byte) []byte { - w := width(parser.buffer[parser.buffer_pos]) - if w == 0 { - panic("invalid character sequence") - } - if len(s) == 0 { - s = make([]byte, 0, 32) - } - if w == 1 && len(s)+w <= cap(s) { - s = s[:len(s)+1] - s[len(s)-1] = parser.buffer[parser.buffer_pos] - parser.buffer_pos++ - } else { - s = append(s, parser.buffer[parser.buffer_pos:parser.buffer_pos+w]...) - parser.buffer_pos += w - } - parser.mark.index++ - parser.mark.column++ - parser.unread-- - return s -} - -// Copy a line break character to a string buffer and advance pointers. -func read_line(parser *yaml_parser_t, s []byte) []byte { - buf := parser.buffer - pos := parser.buffer_pos - switch { - case buf[pos] == '\r' && buf[pos+1] == '\n': - // CR LF . LF - s = append(s, '\n') - parser.buffer_pos += 2 - parser.mark.index++ - parser.unread-- - case buf[pos] == '\r' || buf[pos] == '\n': - // CR|LF . LF - s = append(s, '\n') - parser.buffer_pos += 1 - case buf[pos] == '\xC2' && buf[pos+1] == '\x85': - // NEL . LF - s = append(s, '\n') - parser.buffer_pos += 2 - case buf[pos] == '\xE2' && buf[pos+1] == '\x80' && (buf[pos+2] == '\xA8' || buf[pos+2] == '\xA9'): - // LS|PS . LS|PS - s = append(s, buf[parser.buffer_pos:pos+3]...) - parser.buffer_pos += 3 - default: - return s - } - parser.mark.index++ - parser.mark.column = 0 - parser.mark.line++ - parser.unread-- - return s -} - -// Get the next token. -func yaml_parser_scan(parser *yaml_parser_t, token *yaml_token_t) bool { - // Erase the token object. - *token = yaml_token_t{} // [Go] Is this necessary? - - // No tokens after STREAM-END or error. - if parser.stream_end_produced || parser.error != yaml_NO_ERROR { - return true - } - - // Ensure that the tokens queue contains enough tokens. - if !parser.token_available { - if !yaml_parser_fetch_more_tokens(parser) { - return false - } - } - - // Fetch the next token from the queue. - *token = parser.tokens[parser.tokens_head] - parser.tokens_head++ - parser.tokens_parsed++ - parser.token_available = false - - if token.typ == yaml_STREAM_END_TOKEN { - parser.stream_end_produced = true - } - return true -} - -// Set the scanner error and return false. -func yaml_parser_set_scanner_error(parser *yaml_parser_t, context string, context_mark yaml_mark_t, problem string) bool { - parser.error = yaml_SCANNER_ERROR - parser.context = context - parser.context_mark = context_mark - parser.problem = problem - parser.problem_mark = parser.mark - return false -} - -func yaml_parser_set_scanner_tag_error(parser *yaml_parser_t, directive bool, context_mark yaml_mark_t, problem string) bool { - context := "while parsing a tag" - if directive { - context = "while parsing a %TAG directive" - } - return yaml_parser_set_scanner_error(parser, context, context_mark, problem) -} - -func trace(args ...interface{}) func() { - pargs := append([]interface{}{"+++"}, args...) - fmt.Println(pargs...) - pargs = append([]interface{}{"---"}, args...) - return func() { fmt.Println(pargs...) } -} - -// Ensure that the tokens queue contains at least one token which can be -// returned to the Parser. -func yaml_parser_fetch_more_tokens(parser *yaml_parser_t) bool { - // While we need more tokens to fetch, do it. - for { - if parser.tokens_head != len(parser.tokens) { - // If queue is non-empty, check if any potential simple key may - // occupy the head position. - head_tok_idx, ok := parser.simple_keys_by_tok[parser.tokens_parsed] - if !ok { - break - } else if valid, ok := yaml_simple_key_is_valid(parser, &parser.simple_keys[head_tok_idx]); !ok { - return false - } else if !valid { - break - } - } - // Fetch the next token. - if !yaml_parser_fetch_next_token(parser) { - return false - } - } - - parser.token_available = true - return true -} - -// The dispatcher for token fetchers. -func yaml_parser_fetch_next_token(parser *yaml_parser_t) bool { - // Ensure that the buffer is initialized. - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - - // Check if we just started scanning. Fetch STREAM-START then. - if !parser.stream_start_produced { - return yaml_parser_fetch_stream_start(parser) - } - - // Eat whitespaces and comments until we reach the next token. - if !yaml_parser_scan_to_next_token(parser) { - return false - } - - // Check the indentation level against the current column. - if !yaml_parser_unroll_indent(parser, parser.mark.column) { - return false - } - - // Ensure that the buffer contains at least 4 characters. 4 is the length - // of the longest indicators ('--- ' and '... '). - if parser.unread < 4 && !yaml_parser_update_buffer(parser, 4) { - return false - } - - // Is it the end of the stream? - if is_z(parser.buffer, parser.buffer_pos) { - return yaml_parser_fetch_stream_end(parser) - } - - // Is it a directive? - if parser.mark.column == 0 && parser.buffer[parser.buffer_pos] == '%' { - return yaml_parser_fetch_directive(parser) - } - - buf := parser.buffer - pos := parser.buffer_pos - - // Is it the document start indicator? - if parser.mark.column == 0 && buf[pos] == '-' && buf[pos+1] == '-' && buf[pos+2] == '-' && is_blankz(buf, pos+3) { - return yaml_parser_fetch_document_indicator(parser, yaml_DOCUMENT_START_TOKEN) - } - - // Is it the document end indicator? - if parser.mark.column == 0 && buf[pos] == '.' && buf[pos+1] == '.' && buf[pos+2] == '.' && is_blankz(buf, pos+3) { - return yaml_parser_fetch_document_indicator(parser, yaml_DOCUMENT_END_TOKEN) - } - - // Is it the flow sequence start indicator? - if buf[pos] == '[' { - return yaml_parser_fetch_flow_collection_start(parser, yaml_FLOW_SEQUENCE_START_TOKEN) - } - - // Is it the flow mapping start indicator? - if parser.buffer[parser.buffer_pos] == '{' { - return yaml_parser_fetch_flow_collection_start(parser, yaml_FLOW_MAPPING_START_TOKEN) - } - - // Is it the flow sequence end indicator? - if parser.buffer[parser.buffer_pos] == ']' { - return yaml_parser_fetch_flow_collection_end(parser, - yaml_FLOW_SEQUENCE_END_TOKEN) - } - - // Is it the flow mapping end indicator? - if parser.buffer[parser.buffer_pos] == '}' { - return yaml_parser_fetch_flow_collection_end(parser, - yaml_FLOW_MAPPING_END_TOKEN) - } - - // Is it the flow entry indicator? - if parser.buffer[parser.buffer_pos] == ',' { - return yaml_parser_fetch_flow_entry(parser) - } - - // Is it the block entry indicator? - if parser.buffer[parser.buffer_pos] == '-' && is_blankz(parser.buffer, parser.buffer_pos+1) { - return yaml_parser_fetch_block_entry(parser) - } - - // Is it the key indicator? - if parser.buffer[parser.buffer_pos] == '?' && (parser.flow_level > 0 || is_blankz(parser.buffer, parser.buffer_pos+1)) { - return yaml_parser_fetch_key(parser) - } - - // Is it the value indicator? - if parser.buffer[parser.buffer_pos] == ':' && (parser.flow_level > 0 || is_blankz(parser.buffer, parser.buffer_pos+1)) { - return yaml_parser_fetch_value(parser) - } - - // Is it an alias? - if parser.buffer[parser.buffer_pos] == '*' { - return yaml_parser_fetch_anchor(parser, yaml_ALIAS_TOKEN) - } - - // Is it an anchor? - if parser.buffer[parser.buffer_pos] == '&' { - return yaml_parser_fetch_anchor(parser, yaml_ANCHOR_TOKEN) - } - - // Is it a tag? - if parser.buffer[parser.buffer_pos] == '!' { - return yaml_parser_fetch_tag(parser) - } - - // Is it a literal scalar? - if parser.buffer[parser.buffer_pos] == '|' && parser.flow_level == 0 { - return yaml_parser_fetch_block_scalar(parser, true) - } - - // Is it a folded scalar? - if parser.buffer[parser.buffer_pos] == '>' && parser.flow_level == 0 { - return yaml_parser_fetch_block_scalar(parser, false) - } - - // Is it a single-quoted scalar? - if parser.buffer[parser.buffer_pos] == '\'' { - return yaml_parser_fetch_flow_scalar(parser, true) - } - - // Is it a double-quoted scalar? - if parser.buffer[parser.buffer_pos] == '"' { - return yaml_parser_fetch_flow_scalar(parser, false) - } - - // Is it a plain scalar? - // - // A plain scalar may start with any non-blank characters except - // - // '-', '?', ':', ',', '[', ']', '{', '}', - // '#', '&', '*', '!', '|', '>', '\'', '\"', - // '%', '@', '`'. - // - // In the block context (and, for the '-' indicator, in the flow context - // too), it may also start with the characters - // - // '-', '?', ':' - // - // if it is followed by a non-space character. - // - // The last rule is more restrictive than the specification requires. - // [Go] Make this logic more reasonable. - //switch parser.buffer[parser.buffer_pos] { - //case '-', '?', ':', ',', '?', '-', ',', ':', ']', '[', '}', '{', '&', '#', '!', '*', '>', '|', '"', '\'', '@', '%', '-', '`': - //} - if !(is_blankz(parser.buffer, parser.buffer_pos) || parser.buffer[parser.buffer_pos] == '-' || - parser.buffer[parser.buffer_pos] == '?' || parser.buffer[parser.buffer_pos] == ':' || - parser.buffer[parser.buffer_pos] == ',' || parser.buffer[parser.buffer_pos] == '[' || - parser.buffer[parser.buffer_pos] == ']' || parser.buffer[parser.buffer_pos] == '{' || - parser.buffer[parser.buffer_pos] == '}' || parser.buffer[parser.buffer_pos] == '#' || - parser.buffer[parser.buffer_pos] == '&' || parser.buffer[parser.buffer_pos] == '*' || - parser.buffer[parser.buffer_pos] == '!' || parser.buffer[parser.buffer_pos] == '|' || - parser.buffer[parser.buffer_pos] == '>' || parser.buffer[parser.buffer_pos] == '\'' || - parser.buffer[parser.buffer_pos] == '"' || parser.buffer[parser.buffer_pos] == '%' || - parser.buffer[parser.buffer_pos] == '@' || parser.buffer[parser.buffer_pos] == '`') || - (parser.buffer[parser.buffer_pos] == '-' && !is_blank(parser.buffer, parser.buffer_pos+1)) || - (parser.flow_level == 0 && - (parser.buffer[parser.buffer_pos] == '?' || parser.buffer[parser.buffer_pos] == ':') && - !is_blankz(parser.buffer, parser.buffer_pos+1)) { - return yaml_parser_fetch_plain_scalar(parser) - } - - // If we don't determine the token type so far, it is an error. - return yaml_parser_set_scanner_error(parser, - "while scanning for the next token", parser.mark, - "found character that cannot start any token") -} - -func yaml_simple_key_is_valid(parser *yaml_parser_t, simple_key *yaml_simple_key_t) (valid, ok bool) { - if !simple_key.possible { - return false, true - } - - // The 1.2 specification says: - // - // "If the ? indicator is omitted, parsing needs to see past the - // implicit key to recognize it as such. To limit the amount of - // lookahead required, the “:” indicator must appear at most 1024 - // Unicode characters beyond the start of the key. In addition, the key - // is restricted to a single line." - // - if simple_key.mark.line < parser.mark.line || simple_key.mark.index+1024 < parser.mark.index { - // Check if the potential simple key to be removed is required. - if simple_key.required { - return false, yaml_parser_set_scanner_error(parser, - "while scanning a simple key", simple_key.mark, - "could not find expected ':'") - } - simple_key.possible = false - return false, true - } - return true, true -} - -// Check if a simple key may start at the current position and add it if -// needed. -func yaml_parser_save_simple_key(parser *yaml_parser_t) bool { - // A simple key is required at the current position if the scanner is in - // the block context and the current column coincides with the indentation - // level. - - required := parser.flow_level == 0 && parser.indent == parser.mark.column - - // - // If the current position may start a simple key, save it. - // - if parser.simple_key_allowed { - simple_key := yaml_simple_key_t{ - possible: true, - required: required, - token_number: parser.tokens_parsed + (len(parser.tokens) - parser.tokens_head), - mark: parser.mark, - } - - if !yaml_parser_remove_simple_key(parser) { - return false - } - parser.simple_keys[len(parser.simple_keys)-1] = simple_key - parser.simple_keys_by_tok[simple_key.token_number] = len(parser.simple_keys) - 1 - } - return true -} - -// Remove a potential simple key at the current flow level. -func yaml_parser_remove_simple_key(parser *yaml_parser_t) bool { - i := len(parser.simple_keys) - 1 - if parser.simple_keys[i].possible { - // If the key is required, it is an error. - if parser.simple_keys[i].required { - return yaml_parser_set_scanner_error(parser, - "while scanning a simple key", parser.simple_keys[i].mark, - "could not find expected ':'") - } - // Remove the key from the stack. - parser.simple_keys[i].possible = false - delete(parser.simple_keys_by_tok, parser.simple_keys[i].token_number) - } - return true -} - -// max_flow_level limits the flow_level -const max_flow_level = 10000 - -// Increase the flow level and resize the simple key list if needed. -func yaml_parser_increase_flow_level(parser *yaml_parser_t) bool { - // Reset the simple key on the next level. - parser.simple_keys = append(parser.simple_keys, yaml_simple_key_t{ - possible: false, - required: false, - token_number: parser.tokens_parsed + (len(parser.tokens) - parser.tokens_head), - mark: parser.mark, - }) - - // Increase the flow level. - parser.flow_level++ - if parser.flow_level > max_flow_level { - return yaml_parser_set_scanner_error(parser, - "while increasing flow level", parser.simple_keys[len(parser.simple_keys)-1].mark, - fmt.Sprintf("exceeded max depth of %d", max_flow_level)) - } - return true -} - -// Decrease the flow level. -func yaml_parser_decrease_flow_level(parser *yaml_parser_t) bool { - if parser.flow_level > 0 { - parser.flow_level-- - last := len(parser.simple_keys) - 1 - delete(parser.simple_keys_by_tok, parser.simple_keys[last].token_number) - parser.simple_keys = parser.simple_keys[:last] - } - return true -} - -// max_indents limits the indents stack size -const max_indents = 10000 - -// Push the current indentation level to the stack and set the new level -// the current column is greater than the indentation level. In this case, -// append or insert the specified token into the token queue. -func yaml_parser_roll_indent(parser *yaml_parser_t, column, number int, typ yaml_token_type_t, mark yaml_mark_t) bool { - // In the flow context, do nothing. - if parser.flow_level > 0 { - return true - } - - if parser.indent < column { - // Push the current indentation level to the stack and set the new - // indentation level. - parser.indents = append(parser.indents, parser.indent) - parser.indent = column - if len(parser.indents) > max_indents { - return yaml_parser_set_scanner_error(parser, - "while increasing indent level", parser.simple_keys[len(parser.simple_keys)-1].mark, - fmt.Sprintf("exceeded max depth of %d", max_indents)) - } - - // Create a token and insert it into the queue. - token := yaml_token_t{ - typ: typ, - start_mark: mark, - end_mark: mark, - } - if number > -1 { - number -= parser.tokens_parsed - } - yaml_insert_token(parser, number, &token) - } - return true -} - -// Pop indentation levels from the indents stack until the current level -// becomes less or equal to the column. For each indentation level, append -// the BLOCK-END token. -func yaml_parser_unroll_indent(parser *yaml_parser_t, column int) bool { - // In the flow context, do nothing. - if parser.flow_level > 0 { - return true - } - - // Loop through the indentation levels in the stack. - for parser.indent > column { - // Create a token and append it to the queue. - token := yaml_token_t{ - typ: yaml_BLOCK_END_TOKEN, - start_mark: parser.mark, - end_mark: parser.mark, - } - yaml_insert_token(parser, -1, &token) - - // Pop the indentation level. - parser.indent = parser.indents[len(parser.indents)-1] - parser.indents = parser.indents[:len(parser.indents)-1] - } - return true -} - -// Initialize the scanner and produce the STREAM-START token. -func yaml_parser_fetch_stream_start(parser *yaml_parser_t) bool { - - // Set the initial indentation. - parser.indent = -1 - - // Initialize the simple key stack. - parser.simple_keys = append(parser.simple_keys, yaml_simple_key_t{}) - - parser.simple_keys_by_tok = make(map[int]int) - - // A simple key is allowed at the beginning of the stream. - parser.simple_key_allowed = true - - // We have started. - parser.stream_start_produced = true - - // Create the STREAM-START token and append it to the queue. - token := yaml_token_t{ - typ: yaml_STREAM_START_TOKEN, - start_mark: parser.mark, - end_mark: parser.mark, - encoding: parser.encoding, - } - yaml_insert_token(parser, -1, &token) - return true -} - -// Produce the STREAM-END token and shut down the scanner. -func yaml_parser_fetch_stream_end(parser *yaml_parser_t) bool { - - // Force new line. - if parser.mark.column != 0 { - parser.mark.column = 0 - parser.mark.line++ - } - - // Reset the indentation level. - if !yaml_parser_unroll_indent(parser, -1) { - return false - } - - // Reset simple keys. - if !yaml_parser_remove_simple_key(parser) { - return false - } - - parser.simple_key_allowed = false - - // Create the STREAM-END token and append it to the queue. - token := yaml_token_t{ - typ: yaml_STREAM_END_TOKEN, - start_mark: parser.mark, - end_mark: parser.mark, - } - yaml_insert_token(parser, -1, &token) - return true -} - -// Produce a VERSION-DIRECTIVE or TAG-DIRECTIVE token. -func yaml_parser_fetch_directive(parser *yaml_parser_t) bool { - // Reset the indentation level. - if !yaml_parser_unroll_indent(parser, -1) { - return false - } - - // Reset simple keys. - if !yaml_parser_remove_simple_key(parser) { - return false - } - - parser.simple_key_allowed = false - - // Create the YAML-DIRECTIVE or TAG-DIRECTIVE token. - token := yaml_token_t{} - if !yaml_parser_scan_directive(parser, &token) { - return false - } - // Append the token to the queue. - yaml_insert_token(parser, -1, &token) - return true -} - -// Produce the DOCUMENT-START or DOCUMENT-END token. -func yaml_parser_fetch_document_indicator(parser *yaml_parser_t, typ yaml_token_type_t) bool { - // Reset the indentation level. - if !yaml_parser_unroll_indent(parser, -1) { - return false - } - - // Reset simple keys. - if !yaml_parser_remove_simple_key(parser) { - return false - } - - parser.simple_key_allowed = false - - // Consume the token. - start_mark := parser.mark - - skip(parser) - skip(parser) - skip(parser) - - end_mark := parser.mark - - // Create the DOCUMENT-START or DOCUMENT-END token. - token := yaml_token_t{ - typ: typ, - start_mark: start_mark, - end_mark: end_mark, - } - // Append the token to the queue. - yaml_insert_token(parser, -1, &token) - return true -} - -// Produce the FLOW-SEQUENCE-START or FLOW-MAPPING-START token. -func yaml_parser_fetch_flow_collection_start(parser *yaml_parser_t, typ yaml_token_type_t) bool { - // The indicators '[' and '{' may start a simple key. - if !yaml_parser_save_simple_key(parser) { - return false - } - - // Increase the flow level. - if !yaml_parser_increase_flow_level(parser) { - return false - } - - // A simple key may follow the indicators '[' and '{'. - parser.simple_key_allowed = true - - // Consume the token. - start_mark := parser.mark - skip(parser) - end_mark := parser.mark - - // Create the FLOW-SEQUENCE-START of FLOW-MAPPING-START token. - token := yaml_token_t{ - typ: typ, - start_mark: start_mark, - end_mark: end_mark, - } - // Append the token to the queue. - yaml_insert_token(parser, -1, &token) - return true -} - -// Produce the FLOW-SEQUENCE-END or FLOW-MAPPING-END token. -func yaml_parser_fetch_flow_collection_end(parser *yaml_parser_t, typ yaml_token_type_t) bool { - // Reset any potential simple key on the current flow level. - if !yaml_parser_remove_simple_key(parser) { - return false - } - - // Decrease the flow level. - if !yaml_parser_decrease_flow_level(parser) { - return false - } - - // No simple keys after the indicators ']' and '}'. - parser.simple_key_allowed = false - - // Consume the token. - - start_mark := parser.mark - skip(parser) - end_mark := parser.mark - - // Create the FLOW-SEQUENCE-END of FLOW-MAPPING-END token. - token := yaml_token_t{ - typ: typ, - start_mark: start_mark, - end_mark: end_mark, - } - // Append the token to the queue. - yaml_insert_token(parser, -1, &token) - return true -} - -// Produce the FLOW-ENTRY token. -func yaml_parser_fetch_flow_entry(parser *yaml_parser_t) bool { - // Reset any potential simple keys on the current flow level. - if !yaml_parser_remove_simple_key(parser) { - return false - } - - // Simple keys are allowed after ','. - parser.simple_key_allowed = true - - // Consume the token. - start_mark := parser.mark - skip(parser) - end_mark := parser.mark - - // Create the FLOW-ENTRY token and append it to the queue. - token := yaml_token_t{ - typ: yaml_FLOW_ENTRY_TOKEN, - start_mark: start_mark, - end_mark: end_mark, - } - yaml_insert_token(parser, -1, &token) - return true -} - -// Produce the BLOCK-ENTRY token. -func yaml_parser_fetch_block_entry(parser *yaml_parser_t) bool { - // Check if the scanner is in the block context. - if parser.flow_level == 0 { - // Check if we are allowed to start a new entry. - if !parser.simple_key_allowed { - return yaml_parser_set_scanner_error(parser, "", parser.mark, - "block sequence entries are not allowed in this context") - } - // Add the BLOCK-SEQUENCE-START token if needed. - if !yaml_parser_roll_indent(parser, parser.mark.column, -1, yaml_BLOCK_SEQUENCE_START_TOKEN, parser.mark) { - return false - } - } else { - // It is an error for the '-' indicator to occur in the flow context, - // but we let the Parser detect and report about it because the Parser - // is able to point to the context. - } - - // Reset any potential simple keys on the current flow level. - if !yaml_parser_remove_simple_key(parser) { - return false - } - - // Simple keys are allowed after '-'. - parser.simple_key_allowed = true - - // Consume the token. - start_mark := parser.mark - skip(parser) - end_mark := parser.mark - - // Create the BLOCK-ENTRY token and append it to the queue. - token := yaml_token_t{ - typ: yaml_BLOCK_ENTRY_TOKEN, - start_mark: start_mark, - end_mark: end_mark, - } - yaml_insert_token(parser, -1, &token) - return true -} - -// Produce the KEY token. -func yaml_parser_fetch_key(parser *yaml_parser_t) bool { - - // In the block context, additional checks are required. - if parser.flow_level == 0 { - // Check if we are allowed to start a new key (not nessesary simple). - if !parser.simple_key_allowed { - return yaml_parser_set_scanner_error(parser, "", parser.mark, - "mapping keys are not allowed in this context") - } - // Add the BLOCK-MAPPING-START token if needed. - if !yaml_parser_roll_indent(parser, parser.mark.column, -1, yaml_BLOCK_MAPPING_START_TOKEN, parser.mark) { - return false - } - } - - // Reset any potential simple keys on the current flow level. - if !yaml_parser_remove_simple_key(parser) { - return false - } - - // Simple keys are allowed after '?' in the block context. - parser.simple_key_allowed = parser.flow_level == 0 - - // Consume the token. - start_mark := parser.mark - skip(parser) - end_mark := parser.mark - - // Create the KEY token and append it to the queue. - token := yaml_token_t{ - typ: yaml_KEY_TOKEN, - start_mark: start_mark, - end_mark: end_mark, - } - yaml_insert_token(parser, -1, &token) - return true -} - -// Produce the VALUE token. -func yaml_parser_fetch_value(parser *yaml_parser_t) bool { - - simple_key := &parser.simple_keys[len(parser.simple_keys)-1] - - // Have we found a simple key? - if valid, ok := yaml_simple_key_is_valid(parser, simple_key); !ok { - return false - - } else if valid { - - // Create the KEY token and insert it into the queue. - token := yaml_token_t{ - typ: yaml_KEY_TOKEN, - start_mark: simple_key.mark, - end_mark: simple_key.mark, - } - yaml_insert_token(parser, simple_key.token_number-parser.tokens_parsed, &token) - - // In the block context, we may need to add the BLOCK-MAPPING-START token. - if !yaml_parser_roll_indent(parser, simple_key.mark.column, - simple_key.token_number, - yaml_BLOCK_MAPPING_START_TOKEN, simple_key.mark) { - return false - } - - // Remove the simple key. - simple_key.possible = false - delete(parser.simple_keys_by_tok, simple_key.token_number) - - // A simple key cannot follow another simple key. - parser.simple_key_allowed = false - - } else { - // The ':' indicator follows a complex key. - - // In the block context, extra checks are required. - if parser.flow_level == 0 { - - // Check if we are allowed to start a complex value. - if !parser.simple_key_allowed { - return yaml_parser_set_scanner_error(parser, "", parser.mark, - "mapping values are not allowed in this context") - } - - // Add the BLOCK-MAPPING-START token if needed. - if !yaml_parser_roll_indent(parser, parser.mark.column, -1, yaml_BLOCK_MAPPING_START_TOKEN, parser.mark) { - return false - } - } - - // Simple keys after ':' are allowed in the block context. - parser.simple_key_allowed = parser.flow_level == 0 - } - - // Consume the token. - start_mark := parser.mark - skip(parser) - end_mark := parser.mark - - // Create the VALUE token and append it to the queue. - token := yaml_token_t{ - typ: yaml_VALUE_TOKEN, - start_mark: start_mark, - end_mark: end_mark, - } - yaml_insert_token(parser, -1, &token) - return true -} - -// Produce the ALIAS or ANCHOR token. -func yaml_parser_fetch_anchor(parser *yaml_parser_t, typ yaml_token_type_t) bool { - // An anchor or an alias could be a simple key. - if !yaml_parser_save_simple_key(parser) { - return false - } - - // A simple key cannot follow an anchor or an alias. - parser.simple_key_allowed = false - - // Create the ALIAS or ANCHOR token and append it to the queue. - var token yaml_token_t - if !yaml_parser_scan_anchor(parser, &token, typ) { - return false - } - yaml_insert_token(parser, -1, &token) - return true -} - -// Produce the TAG token. -func yaml_parser_fetch_tag(parser *yaml_parser_t) bool { - // A tag could be a simple key. - if !yaml_parser_save_simple_key(parser) { - return false - } - - // A simple key cannot follow a tag. - parser.simple_key_allowed = false - - // Create the TAG token and append it to the queue. - var token yaml_token_t - if !yaml_parser_scan_tag(parser, &token) { - return false - } - yaml_insert_token(parser, -1, &token) - return true -} - -// Produce the SCALAR(...,literal) or SCALAR(...,folded) tokens. -func yaml_parser_fetch_block_scalar(parser *yaml_parser_t, literal bool) bool { - // Remove any potential simple keys. - if !yaml_parser_remove_simple_key(parser) { - return false - } - - // A simple key may follow a block scalar. - parser.simple_key_allowed = true - - // Create the SCALAR token and append it to the queue. - var token yaml_token_t - if !yaml_parser_scan_block_scalar(parser, &token, literal) { - return false - } - yaml_insert_token(parser, -1, &token) - return true -} - -// Produce the SCALAR(...,single-quoted) or SCALAR(...,double-quoted) tokens. -func yaml_parser_fetch_flow_scalar(parser *yaml_parser_t, single bool) bool { - // A plain scalar could be a simple key. - if !yaml_parser_save_simple_key(parser) { - return false - } - - // A simple key cannot follow a flow scalar. - parser.simple_key_allowed = false - - // Create the SCALAR token and append it to the queue. - var token yaml_token_t - if !yaml_parser_scan_flow_scalar(parser, &token, single) { - return false - } - yaml_insert_token(parser, -1, &token) - return true -} - -// Produce the SCALAR(...,plain) token. -func yaml_parser_fetch_plain_scalar(parser *yaml_parser_t) bool { - // A plain scalar could be a simple key. - if !yaml_parser_save_simple_key(parser) { - return false - } - - // A simple key cannot follow a flow scalar. - parser.simple_key_allowed = false - - // Create the SCALAR token and append it to the queue. - var token yaml_token_t - if !yaml_parser_scan_plain_scalar(parser, &token) { - return false - } - yaml_insert_token(parser, -1, &token) - return true -} - -// Eat whitespaces and comments until the next token is found. -func yaml_parser_scan_to_next_token(parser *yaml_parser_t) bool { - - // Until the next token is not found. - for { - // Allow the BOM mark to start a line. - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - if parser.mark.column == 0 && is_bom(parser.buffer, parser.buffer_pos) { - skip(parser) - } - - // Eat whitespaces. - // Tabs are allowed: - // - in the flow context - // - in the block context, but not at the beginning of the line or - // after '-', '?', or ':' (complex value). - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - - for parser.buffer[parser.buffer_pos] == ' ' || ((parser.flow_level > 0 || !parser.simple_key_allowed) && parser.buffer[parser.buffer_pos] == '\t') { - skip(parser) - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - } - - // Eat a comment until a line break. - if parser.buffer[parser.buffer_pos] == '#' { - for !is_breakz(parser.buffer, parser.buffer_pos) { - skip(parser) - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - } - } - - // If it is a line break, eat it. - if is_break(parser.buffer, parser.buffer_pos) { - if parser.unread < 2 && !yaml_parser_update_buffer(parser, 2) { - return false - } - skip_line(parser) - - // In the block context, a new line may start a simple key. - if parser.flow_level == 0 { - parser.simple_key_allowed = true - } - } else { - break // We have found a token. - } - } - - return true -} - -// Scan a YAML-DIRECTIVE or TAG-DIRECTIVE token. -// -// Scope: -// %YAML 1.1 # a comment \n -// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -// %TAG !yaml! tag:yaml.org,2002: \n -// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -// -func yaml_parser_scan_directive(parser *yaml_parser_t, token *yaml_token_t) bool { - // Eat '%'. - start_mark := parser.mark - skip(parser) - - // Scan the directive name. - var name []byte - if !yaml_parser_scan_directive_name(parser, start_mark, &name) { - return false - } - - // Is it a YAML directive? - if bytes.Equal(name, []byte("YAML")) { - // Scan the VERSION directive value. - var major, minor int8 - if !yaml_parser_scan_version_directive_value(parser, start_mark, &major, &minor) { - return false - } - end_mark := parser.mark - - // Create a VERSION-DIRECTIVE token. - *token = yaml_token_t{ - typ: yaml_VERSION_DIRECTIVE_TOKEN, - start_mark: start_mark, - end_mark: end_mark, - major: major, - minor: minor, - } - - // Is it a TAG directive? - } else if bytes.Equal(name, []byte("TAG")) { - // Scan the TAG directive value. - var handle, prefix []byte - if !yaml_parser_scan_tag_directive_value(parser, start_mark, &handle, &prefix) { - return false - } - end_mark := parser.mark - - // Create a TAG-DIRECTIVE token. - *token = yaml_token_t{ - typ: yaml_TAG_DIRECTIVE_TOKEN, - start_mark: start_mark, - end_mark: end_mark, - value: handle, - prefix: prefix, - } - - // Unknown directive. - } else { - yaml_parser_set_scanner_error(parser, "while scanning a directive", - start_mark, "found unknown directive name") - return false - } - - // Eat the rest of the line including any comments. - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - - for is_blank(parser.buffer, parser.buffer_pos) { - skip(parser) - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - } - - if parser.buffer[parser.buffer_pos] == '#' { - for !is_breakz(parser.buffer, parser.buffer_pos) { - skip(parser) - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - } - } - - // Check if we are at the end of the line. - if !is_breakz(parser.buffer, parser.buffer_pos) { - yaml_parser_set_scanner_error(parser, "while scanning a directive", - start_mark, "did not find expected comment or line break") - return false - } - - // Eat a line break. - if is_break(parser.buffer, parser.buffer_pos) { - if parser.unread < 2 && !yaml_parser_update_buffer(parser, 2) { - return false - } - skip_line(parser) - } - - return true -} - -// Scan the directive name. -// -// Scope: -// %YAML 1.1 # a comment \n -// ^^^^ -// %TAG !yaml! tag:yaml.org,2002: \n -// ^^^ -// -func yaml_parser_scan_directive_name(parser *yaml_parser_t, start_mark yaml_mark_t, name *[]byte) bool { - // Consume the directive name. - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - - var s []byte - for is_alpha(parser.buffer, parser.buffer_pos) { - s = read(parser, s) - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - } - - // Check if the name is empty. - if len(s) == 0 { - yaml_parser_set_scanner_error(parser, "while scanning a directive", - start_mark, "could not find expected directive name") - return false - } - - // Check for an blank character after the name. - if !is_blankz(parser.buffer, parser.buffer_pos) { - yaml_parser_set_scanner_error(parser, "while scanning a directive", - start_mark, "found unexpected non-alphabetical character") - return false - } - *name = s - return true -} - -// Scan the value of VERSION-DIRECTIVE. -// -// Scope: -// %YAML 1.1 # a comment \n -// ^^^^^^ -func yaml_parser_scan_version_directive_value(parser *yaml_parser_t, start_mark yaml_mark_t, major, minor *int8) bool { - // Eat whitespaces. - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - for is_blank(parser.buffer, parser.buffer_pos) { - skip(parser) - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - } - - // Consume the major version number. - if !yaml_parser_scan_version_directive_number(parser, start_mark, major) { - return false - } - - // Eat '.'. - if parser.buffer[parser.buffer_pos] != '.' { - return yaml_parser_set_scanner_error(parser, "while scanning a %YAML directive", - start_mark, "did not find expected digit or '.' character") - } - - skip(parser) - - // Consume the minor version number. - if !yaml_parser_scan_version_directive_number(parser, start_mark, minor) { - return false - } - return true -} - -const max_number_length = 2 - -// Scan the version number of VERSION-DIRECTIVE. -// -// Scope: -// %YAML 1.1 # a comment \n -// ^ -// %YAML 1.1 # a comment \n -// ^ -func yaml_parser_scan_version_directive_number(parser *yaml_parser_t, start_mark yaml_mark_t, number *int8) bool { - - // Repeat while the next character is digit. - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - var value, length int8 - for is_digit(parser.buffer, parser.buffer_pos) { - // Check if the number is too long. - length++ - if length > max_number_length { - return yaml_parser_set_scanner_error(parser, "while scanning a %YAML directive", - start_mark, "found extremely long version number") - } - value = value*10 + int8(as_digit(parser.buffer, parser.buffer_pos)) - skip(parser) - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - } - - // Check if the number was present. - if length == 0 { - return yaml_parser_set_scanner_error(parser, "while scanning a %YAML directive", - start_mark, "did not find expected version number") - } - *number = value - return true -} - -// Scan the value of a TAG-DIRECTIVE token. -// -// Scope: -// %TAG !yaml! tag:yaml.org,2002: \n -// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -// -func yaml_parser_scan_tag_directive_value(parser *yaml_parser_t, start_mark yaml_mark_t, handle, prefix *[]byte) bool { - var handle_value, prefix_value []byte - - // Eat whitespaces. - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - - for is_blank(parser.buffer, parser.buffer_pos) { - skip(parser) - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - } - - // Scan a handle. - if !yaml_parser_scan_tag_handle(parser, true, start_mark, &handle_value) { - return false - } - - // Expect a whitespace. - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - if !is_blank(parser.buffer, parser.buffer_pos) { - yaml_parser_set_scanner_error(parser, "while scanning a %TAG directive", - start_mark, "did not find expected whitespace") - return false - } - - // Eat whitespaces. - for is_blank(parser.buffer, parser.buffer_pos) { - skip(parser) - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - } - - // Scan a prefix. - if !yaml_parser_scan_tag_uri(parser, true, nil, start_mark, &prefix_value) { - return false - } - - // Expect a whitespace or line break. - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - if !is_blankz(parser.buffer, parser.buffer_pos) { - yaml_parser_set_scanner_error(parser, "while scanning a %TAG directive", - start_mark, "did not find expected whitespace or line break") - return false - } - - *handle = handle_value - *prefix = prefix_value - return true -} - -func yaml_parser_scan_anchor(parser *yaml_parser_t, token *yaml_token_t, typ yaml_token_type_t) bool { - var s []byte - - // Eat the indicator character. - start_mark := parser.mark - skip(parser) - - // Consume the value. - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - - for is_alpha(parser.buffer, parser.buffer_pos) { - s = read(parser, s) - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - } - - end_mark := parser.mark - - /* - * Check if length of the anchor is greater than 0 and it is followed by - * a whitespace character or one of the indicators: - * - * '?', ':', ',', ']', '}', '%', '@', '`'. - */ - - if len(s) == 0 || - !(is_blankz(parser.buffer, parser.buffer_pos) || parser.buffer[parser.buffer_pos] == '?' || - parser.buffer[parser.buffer_pos] == ':' || parser.buffer[parser.buffer_pos] == ',' || - parser.buffer[parser.buffer_pos] == ']' || parser.buffer[parser.buffer_pos] == '}' || - parser.buffer[parser.buffer_pos] == '%' || parser.buffer[parser.buffer_pos] == '@' || - parser.buffer[parser.buffer_pos] == '`') { - context := "while scanning an alias" - if typ == yaml_ANCHOR_TOKEN { - context = "while scanning an anchor" - } - yaml_parser_set_scanner_error(parser, context, start_mark, - "did not find expected alphabetic or numeric character") - return false - } - - // Create a token. - *token = yaml_token_t{ - typ: typ, - start_mark: start_mark, - end_mark: end_mark, - value: s, - } - - return true -} - -/* - * Scan a TAG token. - */ - -func yaml_parser_scan_tag(parser *yaml_parser_t, token *yaml_token_t) bool { - var handle, suffix []byte - - start_mark := parser.mark - - // Check if the tag is in the canonical form. - if parser.unread < 2 && !yaml_parser_update_buffer(parser, 2) { - return false - } - - if parser.buffer[parser.buffer_pos+1] == '<' { - // Keep the handle as '' - - // Eat '!<' - skip(parser) - skip(parser) - - // Consume the tag value. - if !yaml_parser_scan_tag_uri(parser, false, nil, start_mark, &suffix) { - return false - } - - // Check for '>' and eat it. - if parser.buffer[parser.buffer_pos] != '>' { - yaml_parser_set_scanner_error(parser, "while scanning a tag", - start_mark, "did not find the expected '>'") - return false - } - - skip(parser) - } else { - // The tag has either the '!suffix' or the '!handle!suffix' form. - - // First, try to scan a handle. - if !yaml_parser_scan_tag_handle(parser, false, start_mark, &handle) { - return false - } - - // Check if it is, indeed, handle. - if handle[0] == '!' && len(handle) > 1 && handle[len(handle)-1] == '!' { - // Scan the suffix now. - if !yaml_parser_scan_tag_uri(parser, false, nil, start_mark, &suffix) { - return false - } - } else { - // It wasn't a handle after all. Scan the rest of the tag. - if !yaml_parser_scan_tag_uri(parser, false, handle, start_mark, &suffix) { - return false - } - - // Set the handle to '!'. - handle = []byte{'!'} - - // A special case: the '!' tag. Set the handle to '' and the - // suffix to '!'. - if len(suffix) == 0 { - handle, suffix = suffix, handle - } - } - } - - // Check the character which ends the tag. - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - if !is_blankz(parser.buffer, parser.buffer_pos) { - yaml_parser_set_scanner_error(parser, "while scanning a tag", - start_mark, "did not find expected whitespace or line break") - return false - } - - end_mark := parser.mark - - // Create a token. - *token = yaml_token_t{ - typ: yaml_TAG_TOKEN, - start_mark: start_mark, - end_mark: end_mark, - value: handle, - suffix: suffix, - } - return true -} - -// Scan a tag handle. -func yaml_parser_scan_tag_handle(parser *yaml_parser_t, directive bool, start_mark yaml_mark_t, handle *[]byte) bool { - // Check the initial '!' character. - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - if parser.buffer[parser.buffer_pos] != '!' { - yaml_parser_set_scanner_tag_error(parser, directive, - start_mark, "did not find expected '!'") - return false - } - - var s []byte - - // Copy the '!' character. - s = read(parser, s) - - // Copy all subsequent alphabetical and numerical characters. - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - for is_alpha(parser.buffer, parser.buffer_pos) { - s = read(parser, s) - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - } - - // Check if the trailing character is '!' and copy it. - if parser.buffer[parser.buffer_pos] == '!' { - s = read(parser, s) - } else { - // It's either the '!' tag or not really a tag handle. If it's a %TAG - // directive, it's an error. If it's a tag token, it must be a part of URI. - if directive && string(s) != "!" { - yaml_parser_set_scanner_tag_error(parser, directive, - start_mark, "did not find expected '!'") - return false - } - } - - *handle = s - return true -} - -// Scan a tag. -func yaml_parser_scan_tag_uri(parser *yaml_parser_t, directive bool, head []byte, start_mark yaml_mark_t, uri *[]byte) bool { - //size_t length = head ? strlen((char *)head) : 0 - var s []byte - hasTag := len(head) > 0 - - // Copy the head if needed. - // - // Note that we don't copy the leading '!' character. - if len(head) > 1 { - s = append(s, head[1:]...) - } - - // Scan the tag. - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - - // The set of characters that may appear in URI is as follows: - // - // '0'-'9', 'A'-'Z', 'a'-'z', '_', '-', ';', '/', '?', ':', '@', '&', - // '=', '+', '$', ',', '.', '!', '~', '*', '\'', '(', ')', '[', ']', - // '%'. - // [Go] Convert this into more reasonable logic. - for is_alpha(parser.buffer, parser.buffer_pos) || parser.buffer[parser.buffer_pos] == ';' || - parser.buffer[parser.buffer_pos] == '/' || parser.buffer[parser.buffer_pos] == '?' || - parser.buffer[parser.buffer_pos] == ':' || parser.buffer[parser.buffer_pos] == '@' || - parser.buffer[parser.buffer_pos] == '&' || parser.buffer[parser.buffer_pos] == '=' || - parser.buffer[parser.buffer_pos] == '+' || parser.buffer[parser.buffer_pos] == '$' || - parser.buffer[parser.buffer_pos] == ',' || parser.buffer[parser.buffer_pos] == '.' || - parser.buffer[parser.buffer_pos] == '!' || parser.buffer[parser.buffer_pos] == '~' || - parser.buffer[parser.buffer_pos] == '*' || parser.buffer[parser.buffer_pos] == '\'' || - parser.buffer[parser.buffer_pos] == '(' || parser.buffer[parser.buffer_pos] == ')' || - parser.buffer[parser.buffer_pos] == '[' || parser.buffer[parser.buffer_pos] == ']' || - parser.buffer[parser.buffer_pos] == '%' { - // Check if it is a URI-escape sequence. - if parser.buffer[parser.buffer_pos] == '%' { - if !yaml_parser_scan_uri_escapes(parser, directive, start_mark, &s) { - return false - } - } else { - s = read(parser, s) - } - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - hasTag = true - } - - if !hasTag { - yaml_parser_set_scanner_tag_error(parser, directive, - start_mark, "did not find expected tag URI") - return false - } - *uri = s - return true -} - -// Decode an URI-escape sequence corresponding to a single UTF-8 character. -func yaml_parser_scan_uri_escapes(parser *yaml_parser_t, directive bool, start_mark yaml_mark_t, s *[]byte) bool { - - // Decode the required number of characters. - w := 1024 - for w > 0 { - // Check for a URI-escaped octet. - if parser.unread < 3 && !yaml_parser_update_buffer(parser, 3) { - return false - } - - if !(parser.buffer[parser.buffer_pos] == '%' && - is_hex(parser.buffer, parser.buffer_pos+1) && - is_hex(parser.buffer, parser.buffer_pos+2)) { - return yaml_parser_set_scanner_tag_error(parser, directive, - start_mark, "did not find URI escaped octet") - } - - // Get the octet. - octet := byte((as_hex(parser.buffer, parser.buffer_pos+1) << 4) + as_hex(parser.buffer, parser.buffer_pos+2)) - - // If it is the leading octet, determine the length of the UTF-8 sequence. - if w == 1024 { - w = width(octet) - if w == 0 { - return yaml_parser_set_scanner_tag_error(parser, directive, - start_mark, "found an incorrect leading UTF-8 octet") - } - } else { - // Check if the trailing octet is correct. - if octet&0xC0 != 0x80 { - return yaml_parser_set_scanner_tag_error(parser, directive, - start_mark, "found an incorrect trailing UTF-8 octet") - } - } - - // Copy the octet and move the pointers. - *s = append(*s, octet) - skip(parser) - skip(parser) - skip(parser) - w-- - } - return true -} - -// Scan a block scalar. -func yaml_parser_scan_block_scalar(parser *yaml_parser_t, token *yaml_token_t, literal bool) bool { - // Eat the indicator '|' or '>'. - start_mark := parser.mark - skip(parser) - - // Scan the additional block scalar indicators. - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - - // Check for a chomping indicator. - var chomping, increment int - if parser.buffer[parser.buffer_pos] == '+' || parser.buffer[parser.buffer_pos] == '-' { - // Set the chomping method and eat the indicator. - if parser.buffer[parser.buffer_pos] == '+' { - chomping = +1 - } else { - chomping = -1 - } - skip(parser) - - // Check for an indentation indicator. - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - if is_digit(parser.buffer, parser.buffer_pos) { - // Check that the indentation is greater than 0. - if parser.buffer[parser.buffer_pos] == '0' { - yaml_parser_set_scanner_error(parser, "while scanning a block scalar", - start_mark, "found an indentation indicator equal to 0") - return false - } - - // Get the indentation level and eat the indicator. - increment = as_digit(parser.buffer, parser.buffer_pos) - skip(parser) - } - - } else if is_digit(parser.buffer, parser.buffer_pos) { - // Do the same as above, but in the opposite order. - - if parser.buffer[parser.buffer_pos] == '0' { - yaml_parser_set_scanner_error(parser, "while scanning a block scalar", - start_mark, "found an indentation indicator equal to 0") - return false - } - increment = as_digit(parser.buffer, parser.buffer_pos) - skip(parser) - - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - if parser.buffer[parser.buffer_pos] == '+' || parser.buffer[parser.buffer_pos] == '-' { - if parser.buffer[parser.buffer_pos] == '+' { - chomping = +1 - } else { - chomping = -1 - } - skip(parser) - } - } - - // Eat whitespaces and comments to the end of the line. - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - for is_blank(parser.buffer, parser.buffer_pos) { - skip(parser) - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - } - if parser.buffer[parser.buffer_pos] == '#' { - for !is_breakz(parser.buffer, parser.buffer_pos) { - skip(parser) - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - } - } - - // Check if we are at the end of the line. - if !is_breakz(parser.buffer, parser.buffer_pos) { - yaml_parser_set_scanner_error(parser, "while scanning a block scalar", - start_mark, "did not find expected comment or line break") - return false - } - - // Eat a line break. - if is_break(parser.buffer, parser.buffer_pos) { - if parser.unread < 2 && !yaml_parser_update_buffer(parser, 2) { - return false - } - skip_line(parser) - } - - end_mark := parser.mark - - // Set the indentation level if it was specified. - var indent int - if increment > 0 { - if parser.indent >= 0 { - indent = parser.indent + increment - } else { - indent = increment - } - } - - // Scan the leading line breaks and determine the indentation level if needed. - var s, leading_break, trailing_breaks []byte - if !yaml_parser_scan_block_scalar_breaks(parser, &indent, &trailing_breaks, start_mark, &end_mark) { - return false - } - - // Scan the block scalar content. - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - var leading_blank, trailing_blank bool - for parser.mark.column == indent && !is_z(parser.buffer, parser.buffer_pos) { - // We are at the beginning of a non-empty line. - - // Is it a trailing whitespace? - trailing_blank = is_blank(parser.buffer, parser.buffer_pos) - - // Check if we need to fold the leading line break. - if !literal && !leading_blank && !trailing_blank && len(leading_break) > 0 && leading_break[0] == '\n' { - // Do we need to join the lines by space? - if len(trailing_breaks) == 0 { - s = append(s, ' ') - } - } else { - s = append(s, leading_break...) - } - leading_break = leading_break[:0] - - // Append the remaining line breaks. - s = append(s, trailing_breaks...) - trailing_breaks = trailing_breaks[:0] - - // Is it a leading whitespace? - leading_blank = is_blank(parser.buffer, parser.buffer_pos) - - // Consume the current line. - for !is_breakz(parser.buffer, parser.buffer_pos) { - s = read(parser, s) - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - } - - // Consume the line break. - if parser.unread < 2 && !yaml_parser_update_buffer(parser, 2) { - return false - } - - leading_break = read_line(parser, leading_break) - - // Eat the following indentation spaces and line breaks. - if !yaml_parser_scan_block_scalar_breaks(parser, &indent, &trailing_breaks, start_mark, &end_mark) { - return false - } - } - - // Chomp the tail. - if chomping != -1 { - s = append(s, leading_break...) - } - if chomping == 1 { - s = append(s, trailing_breaks...) - } - - // Create a token. - *token = yaml_token_t{ - typ: yaml_SCALAR_TOKEN, - start_mark: start_mark, - end_mark: end_mark, - value: s, - style: yaml_LITERAL_SCALAR_STYLE, - } - if !literal { - token.style = yaml_FOLDED_SCALAR_STYLE - } - return true -} - -// Scan indentation spaces and line breaks for a block scalar. Determine the -// indentation level if needed. -func yaml_parser_scan_block_scalar_breaks(parser *yaml_parser_t, indent *int, breaks *[]byte, start_mark yaml_mark_t, end_mark *yaml_mark_t) bool { - *end_mark = parser.mark - - // Eat the indentation spaces and line breaks. - max_indent := 0 - for { - // Eat the indentation spaces. - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - for (*indent == 0 || parser.mark.column < *indent) && is_space(parser.buffer, parser.buffer_pos) { - skip(parser) - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - } - if parser.mark.column > max_indent { - max_indent = parser.mark.column - } - - // Check for a tab character messing the indentation. - if (*indent == 0 || parser.mark.column < *indent) && is_tab(parser.buffer, parser.buffer_pos) { - return yaml_parser_set_scanner_error(parser, "while scanning a block scalar", - start_mark, "found a tab character where an indentation space is expected") - } - - // Have we found a non-empty line? - if !is_break(parser.buffer, parser.buffer_pos) { - break - } - - // Consume the line break. - if parser.unread < 2 && !yaml_parser_update_buffer(parser, 2) { - return false - } - // [Go] Should really be returning breaks instead. - *breaks = read_line(parser, *breaks) - *end_mark = parser.mark - } - - // Determine the indentation level if needed. - if *indent == 0 { - *indent = max_indent - if *indent < parser.indent+1 { - *indent = parser.indent + 1 - } - if *indent < 1 { - *indent = 1 - } - } - return true -} - -// Scan a quoted scalar. -func yaml_parser_scan_flow_scalar(parser *yaml_parser_t, token *yaml_token_t, single bool) bool { - // Eat the left quote. - start_mark := parser.mark - skip(parser) - - // Consume the content of the quoted scalar. - var s, leading_break, trailing_breaks, whitespaces []byte - for { - // Check that there are no document indicators at the beginning of the line. - if parser.unread < 4 && !yaml_parser_update_buffer(parser, 4) { - return false - } - - if parser.mark.column == 0 && - ((parser.buffer[parser.buffer_pos+0] == '-' && - parser.buffer[parser.buffer_pos+1] == '-' && - parser.buffer[parser.buffer_pos+2] == '-') || - (parser.buffer[parser.buffer_pos+0] == '.' && - parser.buffer[parser.buffer_pos+1] == '.' && - parser.buffer[parser.buffer_pos+2] == '.')) && - is_blankz(parser.buffer, parser.buffer_pos+3) { - yaml_parser_set_scanner_error(parser, "while scanning a quoted scalar", - start_mark, "found unexpected document indicator") - return false - } - - // Check for EOF. - if is_z(parser.buffer, parser.buffer_pos) { - yaml_parser_set_scanner_error(parser, "while scanning a quoted scalar", - start_mark, "found unexpected end of stream") - return false - } - - // Consume non-blank characters. - leading_blanks := false - for !is_blankz(parser.buffer, parser.buffer_pos) { - if single && parser.buffer[parser.buffer_pos] == '\'' && parser.buffer[parser.buffer_pos+1] == '\'' { - // Is is an escaped single quote. - s = append(s, '\'') - skip(parser) - skip(parser) - - } else if single && parser.buffer[parser.buffer_pos] == '\'' { - // It is a right single quote. - break - } else if !single && parser.buffer[parser.buffer_pos] == '"' { - // It is a right double quote. - break - - } else if !single && parser.buffer[parser.buffer_pos] == '\\' && is_break(parser.buffer, parser.buffer_pos+1) { - // It is an escaped line break. - if parser.unread < 3 && !yaml_parser_update_buffer(parser, 3) { - return false - } - skip(parser) - skip_line(parser) - leading_blanks = true - break - - } else if !single && parser.buffer[parser.buffer_pos] == '\\' { - // It is an escape sequence. - code_length := 0 - - // Check the escape character. - switch parser.buffer[parser.buffer_pos+1] { - case '0': - s = append(s, 0) - case 'a': - s = append(s, '\x07') - case 'b': - s = append(s, '\x08') - case 't', '\t': - s = append(s, '\x09') - case 'n': - s = append(s, '\x0A') - case 'v': - s = append(s, '\x0B') - case 'f': - s = append(s, '\x0C') - case 'r': - s = append(s, '\x0D') - case 'e': - s = append(s, '\x1B') - case ' ': - s = append(s, '\x20') - case '"': - s = append(s, '"') - case '\'': - s = append(s, '\'') - case '\\': - s = append(s, '\\') - case 'N': // NEL (#x85) - s = append(s, '\xC2') - s = append(s, '\x85') - case '_': // #xA0 - s = append(s, '\xC2') - s = append(s, '\xA0') - case 'L': // LS (#x2028) - s = append(s, '\xE2') - s = append(s, '\x80') - s = append(s, '\xA8') - case 'P': // PS (#x2029) - s = append(s, '\xE2') - s = append(s, '\x80') - s = append(s, '\xA9') - case 'x': - code_length = 2 - case 'u': - code_length = 4 - case 'U': - code_length = 8 - default: - yaml_parser_set_scanner_error(parser, "while parsing a quoted scalar", - start_mark, "found unknown escape character") - return false - } - - skip(parser) - skip(parser) - - // Consume an arbitrary escape code. - if code_length > 0 { - var value int - - // Scan the character value. - if parser.unread < code_length && !yaml_parser_update_buffer(parser, code_length) { - return false - } - for k := 0; k < code_length; k++ { - if !is_hex(parser.buffer, parser.buffer_pos+k) { - yaml_parser_set_scanner_error(parser, "while parsing a quoted scalar", - start_mark, "did not find expected hexdecimal number") - return false - } - value = (value << 4) + as_hex(parser.buffer, parser.buffer_pos+k) - } - - // Check the value and write the character. - if (value >= 0xD800 && value <= 0xDFFF) || value > 0x10FFFF { - yaml_parser_set_scanner_error(parser, "while parsing a quoted scalar", - start_mark, "found invalid Unicode character escape code") - return false - } - if value <= 0x7F { - s = append(s, byte(value)) - } else if value <= 0x7FF { - s = append(s, byte(0xC0+(value>>6))) - s = append(s, byte(0x80+(value&0x3F))) - } else if value <= 0xFFFF { - s = append(s, byte(0xE0+(value>>12))) - s = append(s, byte(0x80+((value>>6)&0x3F))) - s = append(s, byte(0x80+(value&0x3F))) - } else { - s = append(s, byte(0xF0+(value>>18))) - s = append(s, byte(0x80+((value>>12)&0x3F))) - s = append(s, byte(0x80+((value>>6)&0x3F))) - s = append(s, byte(0x80+(value&0x3F))) - } - - // Advance the pointer. - for k := 0; k < code_length; k++ { - skip(parser) - } - } - } else { - // It is a non-escaped non-blank character. - s = read(parser, s) - } - if parser.unread < 2 && !yaml_parser_update_buffer(parser, 2) { - return false - } - } - - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - - // Check if we are at the end of the scalar. - if single { - if parser.buffer[parser.buffer_pos] == '\'' { - break - } - } else { - if parser.buffer[parser.buffer_pos] == '"' { - break - } - } - - // Consume blank characters. - for is_blank(parser.buffer, parser.buffer_pos) || is_break(parser.buffer, parser.buffer_pos) { - if is_blank(parser.buffer, parser.buffer_pos) { - // Consume a space or a tab character. - if !leading_blanks { - whitespaces = read(parser, whitespaces) - } else { - skip(parser) - } - } else { - if parser.unread < 2 && !yaml_parser_update_buffer(parser, 2) { - return false - } - - // Check if it is a first line break. - if !leading_blanks { - whitespaces = whitespaces[:0] - leading_break = read_line(parser, leading_break) - leading_blanks = true - } else { - trailing_breaks = read_line(parser, trailing_breaks) - } - } - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - } - - // Join the whitespaces or fold line breaks. - if leading_blanks { - // Do we need to fold line breaks? - if len(leading_break) > 0 && leading_break[0] == '\n' { - if len(trailing_breaks) == 0 { - s = append(s, ' ') - } else { - s = append(s, trailing_breaks...) - } - } else { - s = append(s, leading_break...) - s = append(s, trailing_breaks...) - } - trailing_breaks = trailing_breaks[:0] - leading_break = leading_break[:0] - } else { - s = append(s, whitespaces...) - whitespaces = whitespaces[:0] - } - } - - // Eat the right quote. - skip(parser) - end_mark := parser.mark - - // Create a token. - *token = yaml_token_t{ - typ: yaml_SCALAR_TOKEN, - start_mark: start_mark, - end_mark: end_mark, - value: s, - style: yaml_SINGLE_QUOTED_SCALAR_STYLE, - } - if !single { - token.style = yaml_DOUBLE_QUOTED_SCALAR_STYLE - } - return true -} - -// Scan a plain scalar. -func yaml_parser_scan_plain_scalar(parser *yaml_parser_t, token *yaml_token_t) bool { - - var s, leading_break, trailing_breaks, whitespaces []byte - var leading_blanks bool - var indent = parser.indent + 1 - - start_mark := parser.mark - end_mark := parser.mark - - // Consume the content of the plain scalar. - for { - // Check for a document indicator. - if parser.unread < 4 && !yaml_parser_update_buffer(parser, 4) { - return false - } - if parser.mark.column == 0 && - ((parser.buffer[parser.buffer_pos+0] == '-' && - parser.buffer[parser.buffer_pos+1] == '-' && - parser.buffer[parser.buffer_pos+2] == '-') || - (parser.buffer[parser.buffer_pos+0] == '.' && - parser.buffer[parser.buffer_pos+1] == '.' && - parser.buffer[parser.buffer_pos+2] == '.')) && - is_blankz(parser.buffer, parser.buffer_pos+3) { - break - } - - // Check for a comment. - if parser.buffer[parser.buffer_pos] == '#' { - break - } - - // Consume non-blank characters. - for !is_blankz(parser.buffer, parser.buffer_pos) { - - // Check for indicators that may end a plain scalar. - if (parser.buffer[parser.buffer_pos] == ':' && is_blankz(parser.buffer, parser.buffer_pos+1)) || - (parser.flow_level > 0 && - (parser.buffer[parser.buffer_pos] == ',' || - parser.buffer[parser.buffer_pos] == '?' || parser.buffer[parser.buffer_pos] == '[' || - parser.buffer[parser.buffer_pos] == ']' || parser.buffer[parser.buffer_pos] == '{' || - parser.buffer[parser.buffer_pos] == '}')) { - break - } - - // Check if we need to join whitespaces and breaks. - if leading_blanks || len(whitespaces) > 0 { - if leading_blanks { - // Do we need to fold line breaks? - if leading_break[0] == '\n' { - if len(trailing_breaks) == 0 { - s = append(s, ' ') - } else { - s = append(s, trailing_breaks...) - } - } else { - s = append(s, leading_break...) - s = append(s, trailing_breaks...) - } - trailing_breaks = trailing_breaks[:0] - leading_break = leading_break[:0] - leading_blanks = false - } else { - s = append(s, whitespaces...) - whitespaces = whitespaces[:0] - } - } - - // Copy the character. - s = read(parser, s) - - end_mark = parser.mark - if parser.unread < 2 && !yaml_parser_update_buffer(parser, 2) { - return false - } - } - - // Is it the end? - if !(is_blank(parser.buffer, parser.buffer_pos) || is_break(parser.buffer, parser.buffer_pos)) { - break - } - - // Consume blank characters. - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - - for is_blank(parser.buffer, parser.buffer_pos) || is_break(parser.buffer, parser.buffer_pos) { - if is_blank(parser.buffer, parser.buffer_pos) { - - // Check for tab characters that abuse indentation. - if leading_blanks && parser.mark.column < indent && is_tab(parser.buffer, parser.buffer_pos) { - yaml_parser_set_scanner_error(parser, "while scanning a plain scalar", - start_mark, "found a tab character that violates indentation") - return false - } - - // Consume a space or a tab character. - if !leading_blanks { - whitespaces = read(parser, whitespaces) - } else { - skip(parser) - } - } else { - if parser.unread < 2 && !yaml_parser_update_buffer(parser, 2) { - return false - } - - // Check if it is a first line break. - if !leading_blanks { - whitespaces = whitespaces[:0] - leading_break = read_line(parser, leading_break) - leading_blanks = true - } else { - trailing_breaks = read_line(parser, trailing_breaks) - } - } - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - } - - // Check indentation level. - if parser.flow_level == 0 && parser.mark.column < indent { - break - } - } - - // Create a token. - *token = yaml_token_t{ - typ: yaml_SCALAR_TOKEN, - start_mark: start_mark, - end_mark: end_mark, - value: s, - style: yaml_PLAIN_SCALAR_STYLE, - } - - // Note that we change the 'simple_key_allowed' flag. - if leading_blanks { - parser.simple_key_allowed = true - } - return true -} diff --git a/vendor/go.yaml.in/yaml/v2/sorter.go b/vendor/go.yaml.in/yaml/v2/sorter.go deleted file mode 100644 index 4c45e660a..000000000 --- a/vendor/go.yaml.in/yaml/v2/sorter.go +++ /dev/null @@ -1,113 +0,0 @@ -package yaml - -import ( - "reflect" - "unicode" -) - -type keyList []reflect.Value - -func (l keyList) Len() int { return len(l) } -func (l keyList) Swap(i, j int) { l[i], l[j] = l[j], l[i] } -func (l keyList) Less(i, j int) bool { - a := l[i] - b := l[j] - ak := a.Kind() - bk := b.Kind() - for (ak == reflect.Interface || ak == reflect.Ptr) && !a.IsNil() { - a = a.Elem() - ak = a.Kind() - } - for (bk == reflect.Interface || bk == reflect.Ptr) && !b.IsNil() { - b = b.Elem() - bk = b.Kind() - } - af, aok := keyFloat(a) - bf, bok := keyFloat(b) - if aok && bok { - if af != bf { - return af < bf - } - if ak != bk { - return ak < bk - } - return numLess(a, b) - } - if ak != reflect.String || bk != reflect.String { - return ak < bk - } - ar, br := []rune(a.String()), []rune(b.String()) - for i := 0; i < len(ar) && i < len(br); i++ { - if ar[i] == br[i] { - continue - } - al := unicode.IsLetter(ar[i]) - bl := unicode.IsLetter(br[i]) - if al && bl { - return ar[i] < br[i] - } - if al || bl { - return bl - } - var ai, bi int - var an, bn int64 - if ar[i] == '0' || br[i] == '0' { - for j := i-1; j >= 0 && unicode.IsDigit(ar[j]); j-- { - if ar[j] != '0' { - an = 1 - bn = 1 - break - } - } - } - for ai = i; ai < len(ar) && unicode.IsDigit(ar[ai]); ai++ { - an = an*10 + int64(ar[ai]-'0') - } - for bi = i; bi < len(br) && unicode.IsDigit(br[bi]); bi++ { - bn = bn*10 + int64(br[bi]-'0') - } - if an != bn { - return an < bn - } - if ai != bi { - return ai < bi - } - return ar[i] < br[i] - } - return len(ar) < len(br) -} - -// keyFloat returns a float value for v if it is a number/bool -// and whether it is a number/bool or not. -func keyFloat(v reflect.Value) (f float64, ok bool) { - switch v.Kind() { - case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - return float64(v.Int()), true - case reflect.Float32, reflect.Float64: - return v.Float(), true - case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: - return float64(v.Uint()), true - case reflect.Bool: - if v.Bool() { - return 1, true - } - return 0, true - } - return 0, false -} - -// numLess returns whether a < b. -// a and b must necessarily have the same kind. -func numLess(a, b reflect.Value) bool { - switch a.Kind() { - case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - return a.Int() < b.Int() - case reflect.Float32, reflect.Float64: - return a.Float() < b.Float() - case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: - return a.Uint() < b.Uint() - case reflect.Bool: - return !a.Bool() && b.Bool() - } - panic("not a number") -} diff --git a/vendor/go.yaml.in/yaml/v2/writerc.go b/vendor/go.yaml.in/yaml/v2/writerc.go deleted file mode 100644 index a2dde608c..000000000 --- a/vendor/go.yaml.in/yaml/v2/writerc.go +++ /dev/null @@ -1,26 +0,0 @@ -package yaml - -// Set the writer error and return false. -func yaml_emitter_set_writer_error(emitter *yaml_emitter_t, problem string) bool { - emitter.error = yaml_WRITER_ERROR - emitter.problem = problem - return false -} - -// Flush the output buffer. -func yaml_emitter_flush(emitter *yaml_emitter_t) bool { - if emitter.write_handler == nil { - panic("write handler not set") - } - - // Check if the buffer is empty. - if emitter.buffer_pos == 0 { - return true - } - - if err := emitter.write_handler(emitter, emitter.buffer[:emitter.buffer_pos]); err != nil { - return yaml_emitter_set_writer_error(emitter, "write error: "+err.Error()) - } - emitter.buffer_pos = 0 - return true -} diff --git a/vendor/go.yaml.in/yaml/v2/yaml.go b/vendor/go.yaml.in/yaml/v2/yaml.go deleted file mode 100644 index 5248e1263..000000000 --- a/vendor/go.yaml.in/yaml/v2/yaml.go +++ /dev/null @@ -1,478 +0,0 @@ -// Package yaml implements YAML support for the Go language. -// -// Source code and other details for the project are available at GitHub: -// -// https://github.com/yaml/go-yaml -// -package yaml - -import ( - "errors" - "fmt" - "io" - "reflect" - "strings" - "sync" -) - -// MapSlice encodes and decodes as a YAML map. -// The order of keys is preserved when encoding and decoding. -type MapSlice []MapItem - -// MapItem is an item in a MapSlice. -type MapItem struct { - Key, Value interface{} -} - -// The Unmarshaler interface may be implemented by types to customize their -// behavior when being unmarshaled from a YAML document. The UnmarshalYAML -// method receives a function that may be called to unmarshal the original -// YAML value into a field or variable. It is safe to call the unmarshal -// function parameter more than once if necessary. -type Unmarshaler interface { - UnmarshalYAML(unmarshal func(interface{}) error) error -} - -// The Marshaler interface may be implemented by types to customize their -// behavior when being marshaled into a YAML document. The returned value -// is marshaled in place of the original value implementing Marshaler. -// -// If an error is returned by MarshalYAML, the marshaling procedure stops -// and returns with the provided error. -type Marshaler interface { - MarshalYAML() (interface{}, error) -} - -// Unmarshal decodes the first document found within the in byte slice -// and assigns decoded values into the out value. -// -// Maps and pointers (to a struct, string, int, etc) are accepted as out -// values. If an internal pointer within a struct is not initialized, -// the yaml package will initialize it if necessary for unmarshalling -// the provided data. The out parameter must not be nil. -// -// The type of the decoded values should be compatible with the respective -// values in out. If one or more values cannot be decoded due to a type -// mismatches, decoding continues partially until the end of the YAML -// content, and a *yaml.TypeError is returned with details for all -// missed values. -// -// Struct fields are only unmarshalled if they are exported (have an -// upper case first letter), and are unmarshalled using the field name -// lowercased as the default key. Custom keys may be defined via the -// "yaml" name in the field tag: the content preceding the first comma -// is used as the key, and the following comma-separated options are -// used to tweak the marshalling process (see Marshal). -// Conflicting names result in a runtime error. -// -// For example: -// -// type T struct { -// F int `yaml:"a,omitempty"` -// B int -// } -// var t T -// yaml.Unmarshal([]byte("a: 1\nb: 2"), &t) -// -// See the documentation of Marshal for the format of tags and a list of -// supported tag options. -// -func Unmarshal(in []byte, out interface{}) (err error) { - return unmarshal(in, out, false) -} - -// UnmarshalStrict is like Unmarshal except that any fields that are found -// in the data that do not have corresponding struct members, or mapping -// keys that are duplicates, will result in -// an error. -func UnmarshalStrict(in []byte, out interface{}) (err error) { - return unmarshal(in, out, true) -} - -// A Decoder reads and decodes YAML values from an input stream. -type Decoder struct { - strict bool - parser *parser -} - -// NewDecoder returns a new decoder that reads from r. -// -// The decoder introduces its own buffering and may read -// data from r beyond the YAML values requested. -func NewDecoder(r io.Reader) *Decoder { - return &Decoder{ - parser: newParserFromReader(r), - } -} - -// SetStrict sets whether strict decoding behaviour is enabled when -// decoding items in the data (see UnmarshalStrict). By default, decoding is not strict. -func (dec *Decoder) SetStrict(strict bool) { - dec.strict = strict -} - -// Decode reads the next YAML-encoded value from its input -// and stores it in the value pointed to by v. -// -// See the documentation for Unmarshal for details about the -// conversion of YAML into a Go value. -func (dec *Decoder) Decode(v interface{}) (err error) { - d := newDecoder(dec.strict) - defer handleErr(&err) - node := dec.parser.parse() - if node == nil { - return io.EOF - } - out := reflect.ValueOf(v) - if out.Kind() == reflect.Ptr && !out.IsNil() { - out = out.Elem() - } - d.unmarshal(node, out) - if len(d.terrors) > 0 { - return &TypeError{d.terrors} - } - return nil -} - -func unmarshal(in []byte, out interface{}, strict bool) (err error) { - defer handleErr(&err) - d := newDecoder(strict) - p := newParser(in) - defer p.destroy() - node := p.parse() - if node != nil { - v := reflect.ValueOf(out) - if v.Kind() == reflect.Ptr && !v.IsNil() { - v = v.Elem() - } - d.unmarshal(node, v) - } - if len(d.terrors) > 0 { - return &TypeError{d.terrors} - } - return nil -} - -// Marshal serializes the value provided into a YAML document. The structure -// of the generated document will reflect the structure of the value itself. -// Maps and pointers (to struct, string, int, etc) are accepted as the in value. -// -// Struct fields are only marshalled if they are exported (have an upper case -// first letter), and are marshalled using the field name lowercased as the -// default key. Custom keys may be defined via the "yaml" name in the field -// tag: the content preceding the first comma is used as the key, and the -// following comma-separated options are used to tweak the marshalling process. -// Conflicting names result in a runtime error. -// -// The field tag format accepted is: -// -// `(...) yaml:"[][,[,]]" (...)` -// -// The following flags are currently supported: -// -// omitempty Only include the field if it's not set to the zero -// value for the type or to empty slices or maps. -// Zero valued structs will be omitted if all their public -// fields are zero, unless they implement an IsZero -// method (see the IsZeroer interface type), in which -// case the field will be excluded if IsZero returns true. -// -// flow Marshal using a flow style (useful for structs, -// sequences and maps). -// -// inline Inline the field, which must be a struct or a map, -// causing all of its fields or keys to be processed as if -// they were part of the outer struct. For maps, keys must -// not conflict with the yaml keys of other struct fields. -// -// In addition, if the key is "-", the field is ignored. -// -// For example: -// -// type T struct { -// F int `yaml:"a,omitempty"` -// B int -// } -// yaml.Marshal(&T{B: 2}) // Returns "b: 2\n" -// yaml.Marshal(&T{F: 1}} // Returns "a: 1\nb: 0\n" -// -func Marshal(in interface{}) (out []byte, err error) { - defer handleErr(&err) - e := newEncoder() - defer e.destroy() - e.marshalDoc("", reflect.ValueOf(in)) - e.finish() - out = e.out - return -} - -// An Encoder writes YAML values to an output stream. -type Encoder struct { - encoder *encoder -} - -// NewEncoder returns a new encoder that writes to w. -// The Encoder should be closed after use to flush all data -// to w. -func NewEncoder(w io.Writer) *Encoder { - return &Encoder{ - encoder: newEncoderWithWriter(w), - } -} - -// Encode writes the YAML encoding of v to the stream. -// If multiple items are encoded to the stream, the -// second and subsequent document will be preceded -// with a "---" document separator, but the first will not. -// -// See the documentation for Marshal for details about the conversion of Go -// values to YAML. -func (e *Encoder) Encode(v interface{}) (err error) { - defer handleErr(&err) - e.encoder.marshalDoc("", reflect.ValueOf(v)) - return nil -} - -// Close closes the encoder by writing any remaining data. -// It does not write a stream terminating string "...". -func (e *Encoder) Close() (err error) { - defer handleErr(&err) - e.encoder.finish() - return nil -} - -func handleErr(err *error) { - if v := recover(); v != nil { - if e, ok := v.(yamlError); ok { - *err = e.err - } else { - panic(v) - } - } -} - -type yamlError struct { - err error -} - -func fail(err error) { - panic(yamlError{err}) -} - -func failf(format string, args ...interface{}) { - panic(yamlError{fmt.Errorf("yaml: "+format, args...)}) -} - -// A TypeError is returned by Unmarshal when one or more fields in -// the YAML document cannot be properly decoded into the requested -// types. When this error is returned, the value is still -// unmarshaled partially. -type TypeError struct { - Errors []string -} - -func (e *TypeError) Error() string { - return fmt.Sprintf("yaml: unmarshal errors:\n %s", strings.Join(e.Errors, "\n ")) -} - -// -------------------------------------------------------------------------- -// Maintain a mapping of keys to structure field indexes - -// The code in this section was copied from mgo/bson. - -// structInfo holds details for the serialization of fields of -// a given struct. -type structInfo struct { - FieldsMap map[string]fieldInfo - FieldsList []fieldInfo - - // InlineMap is the number of the field in the struct that - // contains an ,inline map, or -1 if there's none. - InlineMap int -} - -type fieldInfo struct { - Key string - Num int - OmitEmpty bool - Flow bool - // Id holds the unique field identifier, so we can cheaply - // check for field duplicates without maintaining an extra map. - Id int - - // Inline holds the field index if the field is part of an inlined struct. - Inline []int -} - -var structMap = make(map[reflect.Type]*structInfo) -var fieldMapMutex sync.RWMutex - -func getStructInfo(st reflect.Type) (*structInfo, error) { - fieldMapMutex.RLock() - sinfo, found := structMap[st] - fieldMapMutex.RUnlock() - if found { - return sinfo, nil - } - - n := st.NumField() - fieldsMap := make(map[string]fieldInfo) - fieldsList := make([]fieldInfo, 0, n) - inlineMap := -1 - for i := 0; i != n; i++ { - field := st.Field(i) - if field.PkgPath != "" && !field.Anonymous { - continue // Private field - } - - info := fieldInfo{Num: i} - - tag := field.Tag.Get("yaml") - if tag == "" && strings.Index(string(field.Tag), ":") < 0 { - tag = string(field.Tag) - } - if tag == "-" { - continue - } - - inline := false - fields := strings.Split(tag, ",") - if len(fields) > 1 { - for _, flag := range fields[1:] { - switch flag { - case "omitempty": - info.OmitEmpty = true - case "flow": - info.Flow = true - case "inline": - inline = true - default: - return nil, errors.New(fmt.Sprintf("Unsupported flag %q in tag %q of type %s", flag, tag, st)) - } - } - tag = fields[0] - } - - if inline { - switch field.Type.Kind() { - case reflect.Map: - if inlineMap >= 0 { - return nil, errors.New("Multiple ,inline maps in struct " + st.String()) - } - if field.Type.Key() != reflect.TypeOf("") { - return nil, errors.New("Option ,inline needs a map with string keys in struct " + st.String()) - } - inlineMap = info.Num - case reflect.Struct: - sinfo, err := getStructInfo(field.Type) - if err != nil { - return nil, err - } - for _, finfo := range sinfo.FieldsList { - if _, found := fieldsMap[finfo.Key]; found { - msg := "Duplicated key '" + finfo.Key + "' in struct " + st.String() - return nil, errors.New(msg) - } - if finfo.Inline == nil { - finfo.Inline = []int{i, finfo.Num} - } else { - finfo.Inline = append([]int{i}, finfo.Inline...) - } - finfo.Id = len(fieldsList) - fieldsMap[finfo.Key] = finfo - fieldsList = append(fieldsList, finfo) - } - default: - //return nil, errors.New("Option ,inline needs a struct value or map field") - return nil, errors.New("Option ,inline needs a struct value field") - } - continue - } - - if tag != "" { - info.Key = tag - } else { - info.Key = strings.ToLower(field.Name) - } - - if _, found = fieldsMap[info.Key]; found { - msg := "Duplicated key '" + info.Key + "' in struct " + st.String() - return nil, errors.New(msg) - } - - info.Id = len(fieldsList) - fieldsList = append(fieldsList, info) - fieldsMap[info.Key] = info - } - - sinfo = &structInfo{ - FieldsMap: fieldsMap, - FieldsList: fieldsList, - InlineMap: inlineMap, - } - - fieldMapMutex.Lock() - structMap[st] = sinfo - fieldMapMutex.Unlock() - return sinfo, nil -} - -// IsZeroer is used to check whether an object is zero to -// determine whether it should be omitted when marshaling -// with the omitempty flag. One notable implementation -// is time.Time. -type IsZeroer interface { - IsZero() bool -} - -func isZero(v reflect.Value) bool { - kind := v.Kind() - if z, ok := v.Interface().(IsZeroer); ok { - if (kind == reflect.Ptr || kind == reflect.Interface) && v.IsNil() { - return true - } - return z.IsZero() - } - switch kind { - case reflect.String: - return len(v.String()) == 0 - case reflect.Interface, reflect.Ptr: - return v.IsNil() - case reflect.Slice: - return v.Len() == 0 - case reflect.Map: - return v.Len() == 0 - case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - return v.Int() == 0 - case reflect.Float32, reflect.Float64: - return v.Float() == 0 - case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: - return v.Uint() == 0 - case reflect.Bool: - return !v.Bool() - case reflect.Struct: - vt := v.Type() - for i := v.NumField() - 1; i >= 0; i-- { - if vt.Field(i).PkgPath != "" { - continue // Private field - } - if !isZero(v.Field(i)) { - return false - } - } - return true - } - return false -} - -// FutureLineWrap globally disables line wrapping when encoding long strings. -// This is a temporary and thus deprecated method introduced to faciliate -// migration towards v3, which offers more control of line lengths on -// individual encodings, and has a default matching the behavior introduced -// by this function. -// -// The default formatting of v2 was erroneously changed in v2.3.0 and reverted -// in v2.4.0, at which point this function was introduced to help migration. -func FutureLineWrap() { - disableLineWrapping = true -} diff --git a/vendor/go.yaml.in/yaml/v2/yamlh.go b/vendor/go.yaml.in/yaml/v2/yamlh.go deleted file mode 100644 index f6a9c8e34..000000000 --- a/vendor/go.yaml.in/yaml/v2/yamlh.go +++ /dev/null @@ -1,739 +0,0 @@ -package yaml - -import ( - "fmt" - "io" -) - -// The version directive data. -type yaml_version_directive_t struct { - major int8 // The major version number. - minor int8 // The minor version number. -} - -// The tag directive data. -type yaml_tag_directive_t struct { - handle []byte // The tag handle. - prefix []byte // The tag prefix. -} - -type yaml_encoding_t int - -// The stream encoding. -const ( - // Let the parser choose the encoding. - yaml_ANY_ENCODING yaml_encoding_t = iota - - yaml_UTF8_ENCODING // The default UTF-8 encoding. - yaml_UTF16LE_ENCODING // The UTF-16-LE encoding with BOM. - yaml_UTF16BE_ENCODING // The UTF-16-BE encoding with BOM. -) - -type yaml_break_t int - -// Line break types. -const ( - // Let the parser choose the break type. - yaml_ANY_BREAK yaml_break_t = iota - - yaml_CR_BREAK // Use CR for line breaks (Mac style). - yaml_LN_BREAK // Use LN for line breaks (Unix style). - yaml_CRLN_BREAK // Use CR LN for line breaks (DOS style). -) - -type yaml_error_type_t int - -// Many bad things could happen with the parser and emitter. -const ( - // No error is produced. - yaml_NO_ERROR yaml_error_type_t = iota - - yaml_MEMORY_ERROR // Cannot allocate or reallocate a block of memory. - yaml_READER_ERROR // Cannot read or decode the input stream. - yaml_SCANNER_ERROR // Cannot scan the input stream. - yaml_PARSER_ERROR // Cannot parse the input stream. - yaml_COMPOSER_ERROR // Cannot compose a YAML document. - yaml_WRITER_ERROR // Cannot write to the output stream. - yaml_EMITTER_ERROR // Cannot emit a YAML stream. -) - -// The pointer position. -type yaml_mark_t struct { - index int // The position index. - line int // The position line. - column int // The position column. -} - -// Node Styles - -type yaml_style_t int8 - -type yaml_scalar_style_t yaml_style_t - -// Scalar styles. -const ( - // Let the emitter choose the style. - yaml_ANY_SCALAR_STYLE yaml_scalar_style_t = iota - - yaml_PLAIN_SCALAR_STYLE // The plain scalar style. - yaml_SINGLE_QUOTED_SCALAR_STYLE // The single-quoted scalar style. - yaml_DOUBLE_QUOTED_SCALAR_STYLE // The double-quoted scalar style. - yaml_LITERAL_SCALAR_STYLE // The literal scalar style. - yaml_FOLDED_SCALAR_STYLE // The folded scalar style. -) - -type yaml_sequence_style_t yaml_style_t - -// Sequence styles. -const ( - // Let the emitter choose the style. - yaml_ANY_SEQUENCE_STYLE yaml_sequence_style_t = iota - - yaml_BLOCK_SEQUENCE_STYLE // The block sequence style. - yaml_FLOW_SEQUENCE_STYLE // The flow sequence style. -) - -type yaml_mapping_style_t yaml_style_t - -// Mapping styles. -const ( - // Let the emitter choose the style. - yaml_ANY_MAPPING_STYLE yaml_mapping_style_t = iota - - yaml_BLOCK_MAPPING_STYLE // The block mapping style. - yaml_FLOW_MAPPING_STYLE // The flow mapping style. -) - -// Tokens - -type yaml_token_type_t int - -// Token types. -const ( - // An empty token. - yaml_NO_TOKEN yaml_token_type_t = iota - - yaml_STREAM_START_TOKEN // A STREAM-START token. - yaml_STREAM_END_TOKEN // A STREAM-END token. - - yaml_VERSION_DIRECTIVE_TOKEN // A VERSION-DIRECTIVE token. - yaml_TAG_DIRECTIVE_TOKEN // A TAG-DIRECTIVE token. - yaml_DOCUMENT_START_TOKEN // A DOCUMENT-START token. - yaml_DOCUMENT_END_TOKEN // A DOCUMENT-END token. - - yaml_BLOCK_SEQUENCE_START_TOKEN // A BLOCK-SEQUENCE-START token. - yaml_BLOCK_MAPPING_START_TOKEN // A BLOCK-SEQUENCE-END token. - yaml_BLOCK_END_TOKEN // A BLOCK-END token. - - yaml_FLOW_SEQUENCE_START_TOKEN // A FLOW-SEQUENCE-START token. - yaml_FLOW_SEQUENCE_END_TOKEN // A FLOW-SEQUENCE-END token. - yaml_FLOW_MAPPING_START_TOKEN // A FLOW-MAPPING-START token. - yaml_FLOW_MAPPING_END_TOKEN // A FLOW-MAPPING-END token. - - yaml_BLOCK_ENTRY_TOKEN // A BLOCK-ENTRY token. - yaml_FLOW_ENTRY_TOKEN // A FLOW-ENTRY token. - yaml_KEY_TOKEN // A KEY token. - yaml_VALUE_TOKEN // A VALUE token. - - yaml_ALIAS_TOKEN // An ALIAS token. - yaml_ANCHOR_TOKEN // An ANCHOR token. - yaml_TAG_TOKEN // A TAG token. - yaml_SCALAR_TOKEN // A SCALAR token. -) - -func (tt yaml_token_type_t) String() string { - switch tt { - case yaml_NO_TOKEN: - return "yaml_NO_TOKEN" - case yaml_STREAM_START_TOKEN: - return "yaml_STREAM_START_TOKEN" - case yaml_STREAM_END_TOKEN: - return "yaml_STREAM_END_TOKEN" - case yaml_VERSION_DIRECTIVE_TOKEN: - return "yaml_VERSION_DIRECTIVE_TOKEN" - case yaml_TAG_DIRECTIVE_TOKEN: - return "yaml_TAG_DIRECTIVE_TOKEN" - case yaml_DOCUMENT_START_TOKEN: - return "yaml_DOCUMENT_START_TOKEN" - case yaml_DOCUMENT_END_TOKEN: - return "yaml_DOCUMENT_END_TOKEN" - case yaml_BLOCK_SEQUENCE_START_TOKEN: - return "yaml_BLOCK_SEQUENCE_START_TOKEN" - case yaml_BLOCK_MAPPING_START_TOKEN: - return "yaml_BLOCK_MAPPING_START_TOKEN" - case yaml_BLOCK_END_TOKEN: - return "yaml_BLOCK_END_TOKEN" - case yaml_FLOW_SEQUENCE_START_TOKEN: - return "yaml_FLOW_SEQUENCE_START_TOKEN" - case yaml_FLOW_SEQUENCE_END_TOKEN: - return "yaml_FLOW_SEQUENCE_END_TOKEN" - case yaml_FLOW_MAPPING_START_TOKEN: - return "yaml_FLOW_MAPPING_START_TOKEN" - case yaml_FLOW_MAPPING_END_TOKEN: - return "yaml_FLOW_MAPPING_END_TOKEN" - case yaml_BLOCK_ENTRY_TOKEN: - return "yaml_BLOCK_ENTRY_TOKEN" - case yaml_FLOW_ENTRY_TOKEN: - return "yaml_FLOW_ENTRY_TOKEN" - case yaml_KEY_TOKEN: - return "yaml_KEY_TOKEN" - case yaml_VALUE_TOKEN: - return "yaml_VALUE_TOKEN" - case yaml_ALIAS_TOKEN: - return "yaml_ALIAS_TOKEN" - case yaml_ANCHOR_TOKEN: - return "yaml_ANCHOR_TOKEN" - case yaml_TAG_TOKEN: - return "yaml_TAG_TOKEN" - case yaml_SCALAR_TOKEN: - return "yaml_SCALAR_TOKEN" - } - return "" -} - -// The token structure. -type yaml_token_t struct { - // The token type. - typ yaml_token_type_t - - // The start/end of the token. - start_mark, end_mark yaml_mark_t - - // The stream encoding (for yaml_STREAM_START_TOKEN). - encoding yaml_encoding_t - - // The alias/anchor/scalar value or tag/tag directive handle - // (for yaml_ALIAS_TOKEN, yaml_ANCHOR_TOKEN, yaml_SCALAR_TOKEN, yaml_TAG_TOKEN, yaml_TAG_DIRECTIVE_TOKEN). - value []byte - - // The tag suffix (for yaml_TAG_TOKEN). - suffix []byte - - // The tag directive prefix (for yaml_TAG_DIRECTIVE_TOKEN). - prefix []byte - - // The scalar style (for yaml_SCALAR_TOKEN). - style yaml_scalar_style_t - - // The version directive major/minor (for yaml_VERSION_DIRECTIVE_TOKEN). - major, minor int8 -} - -// Events - -type yaml_event_type_t int8 - -// Event types. -const ( - // An empty event. - yaml_NO_EVENT yaml_event_type_t = iota - - yaml_STREAM_START_EVENT // A STREAM-START event. - yaml_STREAM_END_EVENT // A STREAM-END event. - yaml_DOCUMENT_START_EVENT // A DOCUMENT-START event. - yaml_DOCUMENT_END_EVENT // A DOCUMENT-END event. - yaml_ALIAS_EVENT // An ALIAS event. - yaml_SCALAR_EVENT // A SCALAR event. - yaml_SEQUENCE_START_EVENT // A SEQUENCE-START event. - yaml_SEQUENCE_END_EVENT // A SEQUENCE-END event. - yaml_MAPPING_START_EVENT // A MAPPING-START event. - yaml_MAPPING_END_EVENT // A MAPPING-END event. -) - -var eventStrings = []string{ - yaml_NO_EVENT: "none", - yaml_STREAM_START_EVENT: "stream start", - yaml_STREAM_END_EVENT: "stream end", - yaml_DOCUMENT_START_EVENT: "document start", - yaml_DOCUMENT_END_EVENT: "document end", - yaml_ALIAS_EVENT: "alias", - yaml_SCALAR_EVENT: "scalar", - yaml_SEQUENCE_START_EVENT: "sequence start", - yaml_SEQUENCE_END_EVENT: "sequence end", - yaml_MAPPING_START_EVENT: "mapping start", - yaml_MAPPING_END_EVENT: "mapping end", -} - -func (e yaml_event_type_t) String() string { - if e < 0 || int(e) >= len(eventStrings) { - return fmt.Sprintf("unknown event %d", e) - } - return eventStrings[e] -} - -// The event structure. -type yaml_event_t struct { - - // The event type. - typ yaml_event_type_t - - // The start and end of the event. - start_mark, end_mark yaml_mark_t - - // The document encoding (for yaml_STREAM_START_EVENT). - encoding yaml_encoding_t - - // The version directive (for yaml_DOCUMENT_START_EVENT). - version_directive *yaml_version_directive_t - - // The list of tag directives (for yaml_DOCUMENT_START_EVENT). - tag_directives []yaml_tag_directive_t - - // The anchor (for yaml_SCALAR_EVENT, yaml_SEQUENCE_START_EVENT, yaml_MAPPING_START_EVENT, yaml_ALIAS_EVENT). - anchor []byte - - // The tag (for yaml_SCALAR_EVENT, yaml_SEQUENCE_START_EVENT, yaml_MAPPING_START_EVENT). - tag []byte - - // The scalar value (for yaml_SCALAR_EVENT). - value []byte - - // Is the document start/end indicator implicit, or the tag optional? - // (for yaml_DOCUMENT_START_EVENT, yaml_DOCUMENT_END_EVENT, yaml_SEQUENCE_START_EVENT, yaml_MAPPING_START_EVENT, yaml_SCALAR_EVENT). - implicit bool - - // Is the tag optional for any non-plain style? (for yaml_SCALAR_EVENT). - quoted_implicit bool - - // The style (for yaml_SCALAR_EVENT, yaml_SEQUENCE_START_EVENT, yaml_MAPPING_START_EVENT). - style yaml_style_t -} - -func (e *yaml_event_t) scalar_style() yaml_scalar_style_t { return yaml_scalar_style_t(e.style) } -func (e *yaml_event_t) sequence_style() yaml_sequence_style_t { return yaml_sequence_style_t(e.style) } -func (e *yaml_event_t) mapping_style() yaml_mapping_style_t { return yaml_mapping_style_t(e.style) } - -// Nodes - -const ( - yaml_NULL_TAG = "tag:yaml.org,2002:null" // The tag !!null with the only possible value: null. - yaml_BOOL_TAG = "tag:yaml.org,2002:bool" // The tag !!bool with the values: true and false. - yaml_STR_TAG = "tag:yaml.org,2002:str" // The tag !!str for string values. - yaml_INT_TAG = "tag:yaml.org,2002:int" // The tag !!int for integer values. - yaml_FLOAT_TAG = "tag:yaml.org,2002:float" // The tag !!float for float values. - yaml_TIMESTAMP_TAG = "tag:yaml.org,2002:timestamp" // The tag !!timestamp for date and time values. - - yaml_SEQ_TAG = "tag:yaml.org,2002:seq" // The tag !!seq is used to denote sequences. - yaml_MAP_TAG = "tag:yaml.org,2002:map" // The tag !!map is used to denote mapping. - - // Not in original libyaml. - yaml_BINARY_TAG = "tag:yaml.org,2002:binary" - yaml_MERGE_TAG = "tag:yaml.org,2002:merge" - - yaml_DEFAULT_SCALAR_TAG = yaml_STR_TAG // The default scalar tag is !!str. - yaml_DEFAULT_SEQUENCE_TAG = yaml_SEQ_TAG // The default sequence tag is !!seq. - yaml_DEFAULT_MAPPING_TAG = yaml_MAP_TAG // The default mapping tag is !!map. -) - -type yaml_node_type_t int - -// Node types. -const ( - // An empty node. - yaml_NO_NODE yaml_node_type_t = iota - - yaml_SCALAR_NODE // A scalar node. - yaml_SEQUENCE_NODE // A sequence node. - yaml_MAPPING_NODE // A mapping node. -) - -// An element of a sequence node. -type yaml_node_item_t int - -// An element of a mapping node. -type yaml_node_pair_t struct { - key int // The key of the element. - value int // The value of the element. -} - -// The node structure. -type yaml_node_t struct { - typ yaml_node_type_t // The node type. - tag []byte // The node tag. - - // The node data. - - // The scalar parameters (for yaml_SCALAR_NODE). - scalar struct { - value []byte // The scalar value. - length int // The length of the scalar value. - style yaml_scalar_style_t // The scalar style. - } - - // The sequence parameters (for YAML_SEQUENCE_NODE). - sequence struct { - items_data []yaml_node_item_t // The stack of sequence items. - style yaml_sequence_style_t // The sequence style. - } - - // The mapping parameters (for yaml_MAPPING_NODE). - mapping struct { - pairs_data []yaml_node_pair_t // The stack of mapping pairs (key, value). - pairs_start *yaml_node_pair_t // The beginning of the stack. - pairs_end *yaml_node_pair_t // The end of the stack. - pairs_top *yaml_node_pair_t // The top of the stack. - style yaml_mapping_style_t // The mapping style. - } - - start_mark yaml_mark_t // The beginning of the node. - end_mark yaml_mark_t // The end of the node. - -} - -// The document structure. -type yaml_document_t struct { - - // The document nodes. - nodes []yaml_node_t - - // The version directive. - version_directive *yaml_version_directive_t - - // The list of tag directives. - tag_directives_data []yaml_tag_directive_t - tag_directives_start int // The beginning of the tag directives list. - tag_directives_end int // The end of the tag directives list. - - start_implicit int // Is the document start indicator implicit? - end_implicit int // Is the document end indicator implicit? - - // The start/end of the document. - start_mark, end_mark yaml_mark_t -} - -// The prototype of a read handler. -// -// The read handler is called when the parser needs to read more bytes from the -// source. The handler should write not more than size bytes to the buffer. -// The number of written bytes should be set to the size_read variable. -// -// [in,out] data A pointer to an application data specified by -// yaml_parser_set_input(). -// [out] buffer The buffer to write the data from the source. -// [in] size The size of the buffer. -// [out] size_read The actual number of bytes read from the source. -// -// On success, the handler should return 1. If the handler failed, -// the returned value should be 0. On EOF, the handler should set the -// size_read to 0 and return 1. -type yaml_read_handler_t func(parser *yaml_parser_t, buffer []byte) (n int, err error) - -// This structure holds information about a potential simple key. -type yaml_simple_key_t struct { - possible bool // Is a simple key possible? - required bool // Is a simple key required? - token_number int // The number of the token. - mark yaml_mark_t // The position mark. -} - -// The states of the parser. -type yaml_parser_state_t int - -const ( - yaml_PARSE_STREAM_START_STATE yaml_parser_state_t = iota - - yaml_PARSE_IMPLICIT_DOCUMENT_START_STATE // Expect the beginning of an implicit document. - yaml_PARSE_DOCUMENT_START_STATE // Expect DOCUMENT-START. - yaml_PARSE_DOCUMENT_CONTENT_STATE // Expect the content of a document. - yaml_PARSE_DOCUMENT_END_STATE // Expect DOCUMENT-END. - yaml_PARSE_BLOCK_NODE_STATE // Expect a block node. - yaml_PARSE_BLOCK_NODE_OR_INDENTLESS_SEQUENCE_STATE // Expect a block node or indentless sequence. - yaml_PARSE_FLOW_NODE_STATE // Expect a flow node. - yaml_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE // Expect the first entry of a block sequence. - yaml_PARSE_BLOCK_SEQUENCE_ENTRY_STATE // Expect an entry of a block sequence. - yaml_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE // Expect an entry of an indentless sequence. - yaml_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE // Expect the first key of a block mapping. - yaml_PARSE_BLOCK_MAPPING_KEY_STATE // Expect a block mapping key. - yaml_PARSE_BLOCK_MAPPING_VALUE_STATE // Expect a block mapping value. - yaml_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE // Expect the first entry of a flow sequence. - yaml_PARSE_FLOW_SEQUENCE_ENTRY_STATE // Expect an entry of a flow sequence. - yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE // Expect a key of an ordered mapping. - yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE // Expect a value of an ordered mapping. - yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE // Expect the and of an ordered mapping entry. - yaml_PARSE_FLOW_MAPPING_FIRST_KEY_STATE // Expect the first key of a flow mapping. - yaml_PARSE_FLOW_MAPPING_KEY_STATE // Expect a key of a flow mapping. - yaml_PARSE_FLOW_MAPPING_VALUE_STATE // Expect a value of a flow mapping. - yaml_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE // Expect an empty value of a flow mapping. - yaml_PARSE_END_STATE // Expect nothing. -) - -func (ps yaml_parser_state_t) String() string { - switch ps { - case yaml_PARSE_STREAM_START_STATE: - return "yaml_PARSE_STREAM_START_STATE" - case yaml_PARSE_IMPLICIT_DOCUMENT_START_STATE: - return "yaml_PARSE_IMPLICIT_DOCUMENT_START_STATE" - case yaml_PARSE_DOCUMENT_START_STATE: - return "yaml_PARSE_DOCUMENT_START_STATE" - case yaml_PARSE_DOCUMENT_CONTENT_STATE: - return "yaml_PARSE_DOCUMENT_CONTENT_STATE" - case yaml_PARSE_DOCUMENT_END_STATE: - return "yaml_PARSE_DOCUMENT_END_STATE" - case yaml_PARSE_BLOCK_NODE_STATE: - return "yaml_PARSE_BLOCK_NODE_STATE" - case yaml_PARSE_BLOCK_NODE_OR_INDENTLESS_SEQUENCE_STATE: - return "yaml_PARSE_BLOCK_NODE_OR_INDENTLESS_SEQUENCE_STATE" - case yaml_PARSE_FLOW_NODE_STATE: - return "yaml_PARSE_FLOW_NODE_STATE" - case yaml_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE: - return "yaml_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE" - case yaml_PARSE_BLOCK_SEQUENCE_ENTRY_STATE: - return "yaml_PARSE_BLOCK_SEQUENCE_ENTRY_STATE" - case yaml_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE: - return "yaml_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE" - case yaml_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE: - return "yaml_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE" - case yaml_PARSE_BLOCK_MAPPING_KEY_STATE: - return "yaml_PARSE_BLOCK_MAPPING_KEY_STATE" - case yaml_PARSE_BLOCK_MAPPING_VALUE_STATE: - return "yaml_PARSE_BLOCK_MAPPING_VALUE_STATE" - case yaml_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE: - return "yaml_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE" - case yaml_PARSE_FLOW_SEQUENCE_ENTRY_STATE: - return "yaml_PARSE_FLOW_SEQUENCE_ENTRY_STATE" - case yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE: - return "yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE" - case yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE: - return "yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE" - case yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE: - return "yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE" - case yaml_PARSE_FLOW_MAPPING_FIRST_KEY_STATE: - return "yaml_PARSE_FLOW_MAPPING_FIRST_KEY_STATE" - case yaml_PARSE_FLOW_MAPPING_KEY_STATE: - return "yaml_PARSE_FLOW_MAPPING_KEY_STATE" - case yaml_PARSE_FLOW_MAPPING_VALUE_STATE: - return "yaml_PARSE_FLOW_MAPPING_VALUE_STATE" - case yaml_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE: - return "yaml_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE" - case yaml_PARSE_END_STATE: - return "yaml_PARSE_END_STATE" - } - return "" -} - -// This structure holds aliases data. -type yaml_alias_data_t struct { - anchor []byte // The anchor. - index int // The node id. - mark yaml_mark_t // The anchor mark. -} - -// The parser structure. -// -// All members are internal. Manage the structure using the -// yaml_parser_ family of functions. -type yaml_parser_t struct { - - // Error handling - - error yaml_error_type_t // Error type. - - problem string // Error description. - - // The byte about which the problem occurred. - problem_offset int - problem_value int - problem_mark yaml_mark_t - - // The error context. - context string - context_mark yaml_mark_t - - // Reader stuff - - read_handler yaml_read_handler_t // Read handler. - - input_reader io.Reader // File input data. - input []byte // String input data. - input_pos int - - eof bool // EOF flag - - buffer []byte // The working buffer. - buffer_pos int // The current position of the buffer. - - unread int // The number of unread characters in the buffer. - - raw_buffer []byte // The raw buffer. - raw_buffer_pos int // The current position of the buffer. - - encoding yaml_encoding_t // The input encoding. - - offset int // The offset of the current position (in bytes). - mark yaml_mark_t // The mark of the current position. - - // Scanner stuff - - stream_start_produced bool // Have we started to scan the input stream? - stream_end_produced bool // Have we reached the end of the input stream? - - flow_level int // The number of unclosed '[' and '{' indicators. - - tokens []yaml_token_t // The tokens queue. - tokens_head int // The head of the tokens queue. - tokens_parsed int // The number of tokens fetched from the queue. - token_available bool // Does the tokens queue contain a token ready for dequeueing. - - indent int // The current indentation level. - indents []int // The indentation levels stack. - - simple_key_allowed bool // May a simple key occur at the current position? - simple_keys []yaml_simple_key_t // The stack of simple keys. - simple_keys_by_tok map[int]int // possible simple_key indexes indexed by token_number - - // Parser stuff - - state yaml_parser_state_t // The current parser state. - states []yaml_parser_state_t // The parser states stack. - marks []yaml_mark_t // The stack of marks. - tag_directives []yaml_tag_directive_t // The list of TAG directives. - - // Dumper stuff - - aliases []yaml_alias_data_t // The alias data. - - document *yaml_document_t // The currently parsed document. -} - -// Emitter Definitions - -// The prototype of a write handler. -// -// The write handler is called when the emitter needs to flush the accumulated -// characters to the output. The handler should write @a size bytes of the -// @a buffer to the output. -// -// @param[in,out] data A pointer to an application data specified by -// yaml_emitter_set_output(). -// @param[in] buffer The buffer with bytes to be written. -// @param[in] size The size of the buffer. -// -// @returns On success, the handler should return @c 1. If the handler failed, -// the returned value should be @c 0. -// -type yaml_write_handler_t func(emitter *yaml_emitter_t, buffer []byte) error - -type yaml_emitter_state_t int - -// The emitter states. -const ( - // Expect STREAM-START. - yaml_EMIT_STREAM_START_STATE yaml_emitter_state_t = iota - - yaml_EMIT_FIRST_DOCUMENT_START_STATE // Expect the first DOCUMENT-START or STREAM-END. - yaml_EMIT_DOCUMENT_START_STATE // Expect DOCUMENT-START or STREAM-END. - yaml_EMIT_DOCUMENT_CONTENT_STATE // Expect the content of a document. - yaml_EMIT_DOCUMENT_END_STATE // Expect DOCUMENT-END. - yaml_EMIT_FLOW_SEQUENCE_FIRST_ITEM_STATE // Expect the first item of a flow sequence. - yaml_EMIT_FLOW_SEQUENCE_ITEM_STATE // Expect an item of a flow sequence. - yaml_EMIT_FLOW_MAPPING_FIRST_KEY_STATE // Expect the first key of a flow mapping. - yaml_EMIT_FLOW_MAPPING_KEY_STATE // Expect a key of a flow mapping. - yaml_EMIT_FLOW_MAPPING_SIMPLE_VALUE_STATE // Expect a value for a simple key of a flow mapping. - yaml_EMIT_FLOW_MAPPING_VALUE_STATE // Expect a value of a flow mapping. - yaml_EMIT_BLOCK_SEQUENCE_FIRST_ITEM_STATE // Expect the first item of a block sequence. - yaml_EMIT_BLOCK_SEQUENCE_ITEM_STATE // Expect an item of a block sequence. - yaml_EMIT_BLOCK_MAPPING_FIRST_KEY_STATE // Expect the first key of a block mapping. - yaml_EMIT_BLOCK_MAPPING_KEY_STATE // Expect the key of a block mapping. - yaml_EMIT_BLOCK_MAPPING_SIMPLE_VALUE_STATE // Expect a value for a simple key of a block mapping. - yaml_EMIT_BLOCK_MAPPING_VALUE_STATE // Expect a value of a block mapping. - yaml_EMIT_END_STATE // Expect nothing. -) - -// The emitter structure. -// -// All members are internal. Manage the structure using the @c yaml_emitter_ -// family of functions. -type yaml_emitter_t struct { - - // Error handling - - error yaml_error_type_t // Error type. - problem string // Error description. - - // Writer stuff - - write_handler yaml_write_handler_t // Write handler. - - output_buffer *[]byte // String output data. - output_writer io.Writer // File output data. - - buffer []byte // The working buffer. - buffer_pos int // The current position of the buffer. - - raw_buffer []byte // The raw buffer. - raw_buffer_pos int // The current position of the buffer. - - encoding yaml_encoding_t // The stream encoding. - - // Emitter stuff - - canonical bool // If the output is in the canonical style? - best_indent int // The number of indentation spaces. - best_width int // The preferred width of the output lines. - unicode bool // Allow unescaped non-ASCII characters? - line_break yaml_break_t // The preferred line break. - - state yaml_emitter_state_t // The current emitter state. - states []yaml_emitter_state_t // The stack of states. - - events []yaml_event_t // The event queue. - events_head int // The head of the event queue. - - indents []int // The stack of indentation levels. - - tag_directives []yaml_tag_directive_t // The list of tag directives. - - indent int // The current indentation level. - - flow_level int // The current flow level. - - root_context bool // Is it the document root context? - sequence_context bool // Is it a sequence context? - mapping_context bool // Is it a mapping context? - simple_key_context bool // Is it a simple mapping key context? - - line int // The current line. - column int // The current column. - whitespace bool // If the last character was a whitespace? - indention bool // If the last character was an indentation character (' ', '-', '?', ':')? - open_ended bool // If an explicit document end is required? - - // Anchor analysis. - anchor_data struct { - anchor []byte // The anchor value. - alias bool // Is it an alias? - } - - // Tag analysis. - tag_data struct { - handle []byte // The tag handle. - suffix []byte // The tag suffix. - } - - // Scalar analysis. - scalar_data struct { - value []byte // The scalar value. - multiline bool // Does the scalar contain line breaks? - flow_plain_allowed bool // Can the scalar be expessed in the flow plain style? - block_plain_allowed bool // Can the scalar be expressed in the block plain style? - single_quoted_allowed bool // Can the scalar be expressed in the single quoted style? - block_allowed bool // Can the scalar be expressed in the literal or folded styles? - style yaml_scalar_style_t // The output style. - } - - // Dumper stuff - - opened bool // If the stream was already opened? - closed bool // If the stream was already closed? - - // The information associated with the document nodes. - anchors *struct { - references int // The number of references. - anchor int // The anchor id. - serialized bool // If the node has been emitted? - } - - last_anchor_id int // The last assigned anchor id. - - document *yaml_document_t // The currently emitted document. -} diff --git a/vendor/go.yaml.in/yaml/v2/yamlprivateh.go b/vendor/go.yaml.in/yaml/v2/yamlprivateh.go deleted file mode 100644 index 8110ce3c3..000000000 --- a/vendor/go.yaml.in/yaml/v2/yamlprivateh.go +++ /dev/null @@ -1,173 +0,0 @@ -package yaml - -const ( - // The size of the input raw buffer. - input_raw_buffer_size = 512 - - // The size of the input buffer. - // It should be possible to decode the whole raw buffer. - input_buffer_size = input_raw_buffer_size * 3 - - // The size of the output buffer. - output_buffer_size = 128 - - // The size of the output raw buffer. - // It should be possible to encode the whole output buffer. - output_raw_buffer_size = (output_buffer_size*2 + 2) - - // The size of other stacks and queues. - initial_stack_size = 16 - initial_queue_size = 16 - initial_string_size = 16 -) - -// Check if the character at the specified position is an alphabetical -// character, a digit, '_', or '-'. -func is_alpha(b []byte, i int) bool { - return b[i] >= '0' && b[i] <= '9' || b[i] >= 'A' && b[i] <= 'Z' || b[i] >= 'a' && b[i] <= 'z' || b[i] == '_' || b[i] == '-' -} - -// Check if the character at the specified position is a digit. -func is_digit(b []byte, i int) bool { - return b[i] >= '0' && b[i] <= '9' -} - -// Get the value of a digit. -func as_digit(b []byte, i int) int { - return int(b[i]) - '0' -} - -// Check if the character at the specified position is a hex-digit. -func is_hex(b []byte, i int) bool { - return b[i] >= '0' && b[i] <= '9' || b[i] >= 'A' && b[i] <= 'F' || b[i] >= 'a' && b[i] <= 'f' -} - -// Get the value of a hex-digit. -func as_hex(b []byte, i int) int { - bi := b[i] - if bi >= 'A' && bi <= 'F' { - return int(bi) - 'A' + 10 - } - if bi >= 'a' && bi <= 'f' { - return int(bi) - 'a' + 10 - } - return int(bi) - '0' -} - -// Check if the character is ASCII. -func is_ascii(b []byte, i int) bool { - return b[i] <= 0x7F -} - -// Check if the character at the start of the buffer can be printed unescaped. -func is_printable(b []byte, i int) bool { - return ((b[i] == 0x0A) || // . == #x0A - (b[i] >= 0x20 && b[i] <= 0x7E) || // #x20 <= . <= #x7E - (b[i] == 0xC2 && b[i+1] >= 0xA0) || // #0xA0 <= . <= #xD7FF - (b[i] > 0xC2 && b[i] < 0xED) || - (b[i] == 0xED && b[i+1] < 0xA0) || - (b[i] == 0xEE) || - (b[i] == 0xEF && // #xE000 <= . <= #xFFFD - !(b[i+1] == 0xBB && b[i+2] == 0xBF) && // && . != #xFEFF - !(b[i+1] == 0xBF && (b[i+2] == 0xBE || b[i+2] == 0xBF)))) -} - -// Check if the character at the specified position is NUL. -func is_z(b []byte, i int) bool { - return b[i] == 0x00 -} - -// Check if the beginning of the buffer is a BOM. -func is_bom(b []byte, i int) bool { - return b[0] == 0xEF && b[1] == 0xBB && b[2] == 0xBF -} - -// Check if the character at the specified position is space. -func is_space(b []byte, i int) bool { - return b[i] == ' ' -} - -// Check if the character at the specified position is tab. -func is_tab(b []byte, i int) bool { - return b[i] == '\t' -} - -// Check if the character at the specified position is blank (space or tab). -func is_blank(b []byte, i int) bool { - //return is_space(b, i) || is_tab(b, i) - return b[i] == ' ' || b[i] == '\t' -} - -// Check if the character at the specified position is a line break. -func is_break(b []byte, i int) bool { - return (b[i] == '\r' || // CR (#xD) - b[i] == '\n' || // LF (#xA) - b[i] == 0xC2 && b[i+1] == 0x85 || // NEL (#x85) - b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA8 || // LS (#x2028) - b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA9) // PS (#x2029) -} - -func is_crlf(b []byte, i int) bool { - return b[i] == '\r' && b[i+1] == '\n' -} - -// Check if the character is a line break or NUL. -func is_breakz(b []byte, i int) bool { - //return is_break(b, i) || is_z(b, i) - return ( // is_break: - b[i] == '\r' || // CR (#xD) - b[i] == '\n' || // LF (#xA) - b[i] == 0xC2 && b[i+1] == 0x85 || // NEL (#x85) - b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA8 || // LS (#x2028) - b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA9 || // PS (#x2029) - // is_z: - b[i] == 0) -} - -// Check if the character is a line break, space, or NUL. -func is_spacez(b []byte, i int) bool { - //return is_space(b, i) || is_breakz(b, i) - return ( // is_space: - b[i] == ' ' || - // is_breakz: - b[i] == '\r' || // CR (#xD) - b[i] == '\n' || // LF (#xA) - b[i] == 0xC2 && b[i+1] == 0x85 || // NEL (#x85) - b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA8 || // LS (#x2028) - b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA9 || // PS (#x2029) - b[i] == 0) -} - -// Check if the character is a line break, space, tab, or NUL. -func is_blankz(b []byte, i int) bool { - //return is_blank(b, i) || is_breakz(b, i) - return ( // is_blank: - b[i] == ' ' || b[i] == '\t' || - // is_breakz: - b[i] == '\r' || // CR (#xD) - b[i] == '\n' || // LF (#xA) - b[i] == 0xC2 && b[i+1] == 0x85 || // NEL (#x85) - b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA8 || // LS (#x2028) - b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA9 || // PS (#x2029) - b[i] == 0) -} - -// Determine the width of the character. -func width(b byte) int { - // Don't replace these by a switch without first - // confirming that it is being inlined. - if b&0x80 == 0x00 { - return 1 - } - if b&0xE0 == 0xC0 { - return 2 - } - if b&0xF0 == 0xE0 { - return 3 - } - if b&0xF8 == 0xF0 { - return 4 - } - return 0 - -} diff --git a/vendor/modules.txt b/vendor/modules.txt index 747aca584..7714c3a4a 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -235,7 +235,7 @@ github.com/jhump/protoreflect/v2/internal/reparse github.com/jhump/protoreflect/v2/internal/sort github.com/jhump/protoreflect/v2/protoresolve github.com/jhump/protoreflect/v2/sourceinfo -# github.com/klauspost/compress v1.19.0 +# github.com/klauspost/compress v1.19.1 ## explicit; go 1.24 github.com/klauspost/compress github.com/klauspost/compress/flate @@ -285,8 +285,8 @@ github.com/pkg/browser # github.com/pmezard/go-difflib v1.0.0 ## explicit github.com/pmezard/go-difflib/difflib -# github.com/prometheus/client_golang v1.23.2 -## explicit; go 1.23.0 +# github.com/prometheus/client_golang v1.24.1 +## explicit; go 1.25.0 github.com/prometheus/client_golang/internal/github.com/golang/gddo/httputil github.com/prometheus/client_golang/internal/github.com/golang/gddo/httputil/header github.com/prometheus/client_golang/prometheus @@ -296,12 +296,12 @@ github.com/prometheus/client_golang/prometheus/promhttp/internal # github.com/prometheus/client_model v0.6.2 ## explicit; go 1.22.0 github.com/prometheus/client_model/go -# github.com/prometheus/common v0.66.1 -## explicit; go 1.23.0 +# github.com/prometheus/common v0.70.1 +## explicit; go 1.25.0 github.com/prometheus/common/expfmt github.com/prometheus/common/model -# github.com/prometheus/procfs v0.16.1 -## explicit; go 1.23.0 +# github.com/prometheus/procfs v0.21.1 +## explicit; go 1.25.0 github.com/prometheus/procfs github.com/prometheus/procfs/internal/fs github.com/prometheus/procfs/internal/util @@ -448,9 +448,6 @@ go.opentelemetry.io/proto/otlp/trace/v1 ## explicit; go 1.20 go.uber.org/goleak go.uber.org/goleak/internal/stack -# go.yaml.in/yaml/v2 v2.4.2 -## explicit; go 1.15 -go.yaml.in/yaml/v2 # golang.org/x/crypto v0.54.0 ## explicit; go 1.25.0 golang.org/x/crypto/md4 From 796c81905c6038207dc8ece143bd0fe0c12114d7 Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Tue, 28 Jul 2026 10:47:12 +0200 Subject: [PATCH 055/182] fix(deps): update module go.opentelemetry.io/proto/otlp to v1.11.0 (#6216) | datasource | package | from | to | | ---------- | ------------------------------ | ------- | ------- | | go | go.opentelemetry.io/proto/otlp | v1.10.0 | v1.11.0 | Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> --- go.mod | 6 +++--- go.sum | 12 ++++++------ .../proto/otlp/common/v1/common.pb.go | 6 +++--- .../proto/otlp/metrics/v1/metrics.pb.go | 2 +- vendor/modules.txt | 8 ++++---- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/go.mod b/go.mod index 1f67b8f0d..c77404296 100644 --- a/go.mod +++ b/go.mod @@ -55,7 +55,7 @@ require ( go.opentelemetry.io/otel/sdk v1.44.0 go.opentelemetry.io/otel/sdk/metric v1.44.0 go.opentelemetry.io/otel/trace v1.44.0 - go.opentelemetry.io/proto/otlp v1.10.0 + go.opentelemetry.io/proto/otlp v1.11.0 go.uber.org/goleak v1.3.0 golang.org/x/crypto v0.54.0 golang.org/x/crypto/x509roots/fallback v0.0.0-20260609182332-5f2de1a9f1e2 @@ -97,8 +97,8 @@ require ( go.opentelemetry.io/auto/sdk v1.2.1 // indirect golang.org/x/sys v0.47.0 // indirect golang.org/x/text v0.40.0 // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20260526163538-3dc84a4a5aaa // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20260526163538-3dc84a4a5aaa // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20260720211330-0afa2a65878a // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20260720211330-0afa2a65878a // indirect gopkg.in/cenkalti/backoff.v1 v1.1.0 // indirect gopkg.in/validator.v2 v2.0.1 // indirect ) diff --git a/go.sum b/go.sum index aba56bdf5..9e2f3b61f 100644 --- a/go.sum +++ b/go.sum @@ -232,8 +232,8 @@ go.opentelemetry.io/otel/sdk/metric v1.44.0 h1:3LlKgI+VjbVsjNRFZJZAJ30WjXC5VkNRk go.opentelemetry.io/otel/sdk/metric v1.44.0/go.mod h1:5B5pMARnXxKhltooO4xUuCBorl65a4EpnTalObqOigA= go.opentelemetry.io/otel/trace v1.44.0 h1:jxF5CsGYCe74MCRx2X4g7WsY/VBKRqqpNvXlX/6gtIk= go.opentelemetry.io/otel/trace v1.44.0/go.mod h1:oLl1jrMQAVo6v3GAggN+1VH9VIz9iUSvW53sW1Q8PIE= -go.opentelemetry.io/proto/otlp v1.10.0 h1:IQRWgT5srOCYfiWnpqUYz9CVmbO8bFmKcwYxpuCSL2g= -go.opentelemetry.io/proto/otlp v1.10.0/go.mod h1:/CV4QoCR/S9yaPj8utp3lvQPoqMtxXdzn7ozvvozVqk= +go.opentelemetry.io/proto/otlp v1.11.0 h1:5rrYs0Ykyj50sdU/JU0x8etU+LubXWb+gED6TbEdMIk= +go.opentelemetry.io/proto/otlp v1.11.0/go.mod h1:SmVizdCOAm3XBtG1g1NnOdhW6jtddT72hLMhv8VwA8E= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= @@ -379,10 +379,10 @@ google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7 google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20200423170343-7949de9c1215/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto/googleapis/api v0.0.0-20260526163538-3dc84a4a5aaa h1:Kjn0N0tCrDgiAFW+lGO4JZ3ck44CehvJQMAwj9QF0G8= -google.golang.org/genproto/googleapis/api v0.0.0-20260526163538-3dc84a4a5aaa/go.mod h1:q4lMZS6kskjT5HvCPrnnypcDPVJqT/f4nfxmkE7gryY= -google.golang.org/genproto/googleapis/rpc v0.0.0-20260526163538-3dc84a4a5aaa h1:mZHHdPZl0dbGHCflZgAq/Q468DWVFcU2whhB2KAo8fk= -google.golang.org/genproto/googleapis/rpc v0.0.0-20260526163538-3dc84a4a5aaa/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8= +google.golang.org/genproto/googleapis/api v0.0.0-20260720211330-0afa2a65878a h1:97PfJ4tCxY5C7NzzgGqQEMZmXbISdvSArNNEOoUGKBg= +google.golang.org/genproto/googleapis/api v0.0.0-20260720211330-0afa2a65878a/go.mod h1:1brfde68Npq6+WA75c1EHWPijZEG1kMus61ygPZfn4A= +google.golang.org/genproto/googleapis/rpc v0.0.0-20260720211330-0afa2a65878a h1:qI/YMH1ep2qQtqcp00gMQyoU7mjvbhg88GJKCvfoLj0= +google.golang.org/genproto/googleapis/rpc v0.0.0-20260720211330-0afa2a65878a/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= diff --git a/vendor/go.opentelemetry.io/proto/otlp/common/v1/common.pb.go b/vendor/go.opentelemetry.io/proto/otlp/common/v1/common.pb.go index 304f64763..cef358000 100644 --- a/vendor/go.opentelemetry.io/proto/otlp/common/v1/common.pb.go +++ b/vendor/go.opentelemetry.io/proto/otlp/common/v1/common.pb.go @@ -194,7 +194,7 @@ type AnyValue_StringValueStrindex struct { // Profiling signal and process the data as if this value were absent or // empty, ignoring its semantic content for the non-Profiling signal. // - // Status: [Development] + // Status: [Alpha] StringValueStrindex int32 `protobuf:"varint,8,opt,name=string_value_strindex,json=stringValueStrindex,proto3,oneof"` } @@ -330,7 +330,7 @@ type KeyValue struct { unknownFields protoimpl.UnknownFields // The key name of the pair. - // key_ref MUST NOT be set if key is used. + // key_strindex MUST NOT be set if key is used. Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` // The value of the pair. Value *AnyValue `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` @@ -344,7 +344,7 @@ type KeyValue struct { // Profiling signal and process the data as if this value were absent or // empty, ignoring its semantic content for the non-Profiling signal. // - // Status: [Development] + // Status: [Alpha] KeyStrindex int32 `protobuf:"varint,3,opt,name=key_strindex,json=keyStrindex,proto3" json:"key_strindex,omitempty"` } diff --git a/vendor/go.opentelemetry.io/proto/otlp/metrics/v1/metrics.pb.go b/vendor/go.opentelemetry.io/proto/otlp/metrics/v1/metrics.pb.go index 748c9fb1c..e148ddd13 100644 --- a/vendor/go.opentelemetry.io/proto/otlp/metrics/v1/metrics.pb.go +++ b/vendor/go.opentelemetry.io/proto/otlp/metrics/v1/metrics.pb.go @@ -527,7 +527,7 @@ type Metric struct { // A description of the metric, which can be used in documentation. Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` // The unit in which the metric value is reported. Follows the format - // described by https://unitsofmeasure.org/ucum.html. + // described by https://ucum.org/ucum and https://units-of-measurement.org/ Unit string `protobuf:"bytes,3,opt,name=unit,proto3" json:"unit,omitempty"` // Data determines the aggregation type (if any) of the metric, what is the // reported value type for the data points, as well as the relatationship to diff --git a/vendor/modules.txt b/vendor/modules.txt index 7714c3a4a..c8335b974 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -436,8 +436,8 @@ go.opentelemetry.io/otel/trace go.opentelemetry.io/otel/trace/embedded go.opentelemetry.io/otel/trace/internal/telemetry go.opentelemetry.io/otel/trace/noop -# go.opentelemetry.io/proto/otlp v1.10.0 -## explicit; go 1.24.0 +# go.opentelemetry.io/proto/otlp v1.11.0 +## explicit; go 1.25.0 go.opentelemetry.io/proto/otlp/collector/metrics/v1 go.opentelemetry.io/proto/otlp/collector/trace/v1 go.opentelemetry.io/proto/otlp/common/v1 @@ -507,10 +507,10 @@ golang.org/x/text/unicode/rangetable # golang.org/x/time v0.15.0 ## explicit; go 1.25.0 golang.org/x/time/rate -# google.golang.org/genproto/googleapis/api v0.0.0-20260526163538-3dc84a4a5aaa +# google.golang.org/genproto/googleapis/api v0.0.0-20260720211330-0afa2a65878a ## explicit; go 1.25.0 google.golang.org/genproto/googleapis/api/httpbody -# google.golang.org/genproto/googleapis/rpc v0.0.0-20260526163538-3dc84a4a5aaa +# google.golang.org/genproto/googleapis/rpc v0.0.0-20260720211330-0afa2a65878a ## explicit; go 1.25.0 google.golang.org/genproto/googleapis/rpc/errdetails google.golang.org/genproto/googleapis/rpc/status From ec14ca2520e18c7e0d03e8527e45ab446a29529b Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Tue, 28 Jul 2026 10:48:04 +0200 Subject: [PATCH 056/182] fix(deps): update module github.com/mattn/go-isatty to v0.0.24 (#6214) | datasource | package | from | to | | ---------- | -------------------------- | ------- | ------- | | go | github.com/mattn/go-isatty | v0.0.23 | v0.0.24 | Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 ++-- .../go-isatty/{isatty_tcgets.go => isatty_tiocgwinsz.go} | 6 +++++- vendor/modules.txt | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) rename vendor/github.com/mattn/go-isatty/{isatty_tcgets.go => isatty_tiocgwinsz.go} (62%) diff --git a/go.mod b/go.mod index c77404296..900858307 100644 --- a/go.mod +++ b/go.mod @@ -30,7 +30,7 @@ require ( github.com/jhump/protoreflect v1.18.0 github.com/klauspost/compress v1.19.1 github.com/mattn/go-colorable v0.1.15 - github.com/mattn/go-isatty v0.0.23 + github.com/mattn/go-isatty v0.0.24 github.com/mccutchen/go-httpbin/v2 v2.24.0 github.com/mstoykov/atlas v0.0.0-20220811071828-388f114305dd github.com/mstoykov/envconfig v1.5.0 diff --git a/go.sum b/go.sum index 9e2f3b61f..523ee9417 100644 --- a/go.sum +++ b/go.sum @@ -131,8 +131,8 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0 github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/mattn/go-colorable v0.1.15 h1:+u9SLTRGnXv73cEsnsmoZBom+dMU88B2M0aDcWy0/jY= github.com/mattn/go-colorable v0.1.15/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8= -github.com/mattn/go-isatty v0.0.23 h1:cYwCQTQf3HB6xUC+BtyCLZNr7IzbOmoZbmssVNzSyiQ= -github.com/mattn/go-isatty v0.0.23/go.mod h1:nMCL3Zebbrt45jsMDgnfIwz6ydEQApk5oEI3HqDio6A= +github.com/mattn/go-isatty v0.0.24 h1:tGZZoVgT/KiqK1c8ocVLeDS8BSWMRd47J3Lbz7vsReI= +github.com/mattn/go-isatty v0.0.24/go.mod h1:nMCL3Zebbrt45jsMDgnfIwz6ydEQApk5oEI3HqDio6A= github.com/mccutchen/go-httpbin/v2 v2.24.0 h1:MZ5QSGVeVpg/c7ZRbIg8UVZvefeBn/NhSVTc1fCQFEQ= github.com/mccutchen/go-httpbin/v2 v2.24.0/go.mod h1:8hkN5rHf0QvJYEovZ8u/Dudtqyj6Z5gxQaW7scQfT0Y= github.com/mstoykov/atlas v0.0.0-20220811071828-388f114305dd h1:AC3N94irbx2kWGA8f/2Ks7EQl2LxKIRQYuT9IJDwgiI= diff --git a/vendor/github.com/mattn/go-isatty/isatty_tcgets.go b/vendor/github.com/mattn/go-isatty/isatty_tiocgwinsz.go similarity index 62% rename from vendor/github.com/mattn/go-isatty/isatty_tcgets.go rename to vendor/github.com/mattn/go-isatty/isatty_tiocgwinsz.go index 0337d8cf6..6aecf8704 100644 --- a/vendor/github.com/mattn/go-isatty/isatty_tcgets.go +++ b/vendor/github.com/mattn/go-isatty/isatty_tiocgwinsz.go @@ -8,8 +8,12 @@ package isatty import "golang.org/x/sys/unix" // IsTerminal return true if the file descriptor is terminal. +// TIOCGWINSZ is used instead of TCGETS because TCGETS shares its ioctl +// number with SNDCTL_TMR_TIMEBASE of the OSS sound API, so it may succeed +// (and even change the device mode) on non-tty devices. musl's isatty does +// the same. func IsTerminal(fd uintptr) bool { - _, err := unix.IoctlGetTermios(int(fd), unix.TCGETS) + _, err := unix.IoctlGetWinsize(int(fd), unix.TIOCGWINSZ) return err == nil } diff --git a/vendor/modules.txt b/vendor/modules.txt index c8335b974..a099f88a7 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -253,7 +253,7 @@ github.com/klauspost/compress/zstd/internal/xxhash # github.com/mattn/go-colorable v0.1.15 ## explicit; go 1.18 github.com/mattn/go-colorable -# github.com/mattn/go-isatty v0.0.23 +# github.com/mattn/go-isatty v0.0.24 ## explicit; go 1.20 github.com/mattn/go-isatty # github.com/mccutchen/go-httpbin/v2 v2.24.0 From b79cb32d10c05cd33b1d38d3f03b22aa445b1d95 Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Tue, 28 Jul 2026 10:48:52 +0200 Subject: [PATCH 057/182] fix(deps): update module github.com/klauspost/compress to v1.19.1 (#6213) | datasource | package | from | to | | ---------- | ----------------------------- | ------- | ------- | | go | github.com/klauspost/compress | v1.19.0 | v1.19.1 | Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> From cca3e5297f9b65d55288b939a41634b112150610 Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Tue, 28 Jul 2026 10:49:40 +0200 Subject: [PATCH 058/182] fix(deps): update golang.org/x/crypto/x509roots/fallback digest to d701c51 (#6212) | datasource | package | from | to | | ---------- | -------------------------------------- | ---------------------------------- | ---------------------------------- | | go | golang.org/x/crypto/x509roots/fallback | v0.0.0-20260609182332-5f2de1a9f1e2 | v0.0.0-20260723152544-d701c51f7e4e | Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 +- .../x509roots/fallback/bundle/bundle.der | Bin 128416 -> 128016 bytes .../x509roots/fallback/bundle/bundle.go | 268 +++++++++--------- vendor/modules.txt | 2 +- 5 files changed, 137 insertions(+), 139 deletions(-) diff --git a/go.mod b/go.mod index 900858307..43d62e6dc 100644 --- a/go.mod +++ b/go.mod @@ -58,7 +58,7 @@ require ( go.opentelemetry.io/proto/otlp v1.11.0 go.uber.org/goleak v1.3.0 golang.org/x/crypto v0.54.0 - golang.org/x/crypto/x509roots/fallback v0.0.0-20260609182332-5f2de1a9f1e2 + golang.org/x/crypto/x509roots/fallback v0.0.0-20260723152544-d701c51f7e4e golang.org/x/net v0.57.0 golang.org/x/sync v0.22.0 golang.org/x/term v0.45.0 diff --git a/go.sum b/go.sum index 523ee9417..3ab37b9ef 100644 --- a/go.sum +++ b/go.sum @@ -254,8 +254,8 @@ golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= golang.org/x/crypto v0.54.0 h1:YLIA59K4fiNzHzjnZt2tUJQjQtUWfWbeHBqKtk3eScw= golang.org/x/crypto v0.54.0/go.mod h1:KWL8ny2AZdGR2cWmzeHrp2azQPGogOv+HeQaVEXC2dk= -golang.org/x/crypto/x509roots/fallback v0.0.0-20260609182332-5f2de1a9f1e2 h1:nQAdbnDzK0eYA4IKMp9xUaZq2UOkAYU5kBWQOSqwjP8= -golang.org/x/crypto/x509roots/fallback v0.0.0-20260609182332-5f2de1a9f1e2/go.mod h1:+UoQFNBq2p2wO+Q6ddVtYc25GZ6VNdOMyyrd4nrqrKs= +golang.org/x/crypto/x509roots/fallback v0.0.0-20260723152544-d701c51f7e4e h1:9TjMDOuGaMMTP5f7GXeHeA0JvFqGmv4DYRIWkzoePGI= +golang.org/x/crypto/x509roots/fallback v0.0.0-20260723152544-d701c51f7e4e/go.mod h1:+UoQFNBq2p2wO+Q6ddVtYc25GZ6VNdOMyyrd4nrqrKs= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= diff --git a/vendor/golang.org/x/crypto/x509roots/fallback/bundle/bundle.der b/vendor/golang.org/x/crypto/x509roots/fallback/bundle/bundle.der index c913aa88ef5d7e4e0bd8a55ce55f12f25065380b..0e9b381f3e33bc7ef37d1ae28461b7c90c64963e 100644 GIT binary patch delta 3708 zcmb`Jc{J3G8pmftM41euK^RL}n_(t{tYZrkV~j0CNTTdXWROIrkQiHJ$x?*D*dmmz zguzQC5sf8;v`Ch#y7%1P_r3R=d(Q3m-}C!E=RD_kKIeHpzuR*h2{Rn!dcu_tMddG7 zh8G9KpE5;70-3kLARq|D35d8LzZfrZK@Y{nzC$+Js7C_=2BYlIJ5ikMU^0ZA4`ghP zmPSc_FSz(bNcwm)f|#XWpnrfEDcC>2?To(|-dj;#%rwAN5iNld|K11YL;UEYnHvLP zr!c5}a2_QL3ayMrVX;ce7&|x*MiqrdWBytG&S^kQ(i@T>W&Ty0(nw{o->* zl3Dak#p73ff()x)o{VJ@N2^ZRq^LHW#qh=vZ)PXu!vRNw+0pQd04^h00gFf4jLj8FmaUK z)GAWDPyC?Nh03l!P@>;+35Xy{ApCC~-y3L&Fd&jv-wouWj81rWObjInR)Hs#WOP{X zDWY@1I~vi4A7;9z^AR#`aH(l$ANvOXq+QnD*2dPH2SNkx0WBA_ci4r{O_epjcn|6e zvdT0Toa4-5kA1COhOyCU-C*Av4$UVi`M~8GbIu`DBwIQv5*+z2?(btUeNV&3=_np{ zP8uo$D5&;-fKD|1D`+$ti~R-kkMehc{yuFRH1MoAG)=Yo}=&NM(G0FacUN6e}!E#Y06M>vqh|tqBI`kNtZ-Z)zP$oqy ze@mE3`IfPD1Z+7%?a5lMuq5JUN_1Zbg+Ad_v=Ymi8mWEatd<92sB$js%L>JdDrUog zHjQq%%p8YkRuKW>o0^kn)*Qtb zc@9neX(9hp!}o>6Qute+vg)L>J?6hwk(iq>5(mbYPl8+9VOYv1IW9CSBJ*m_w0g9& zTD(Y_a_enn+x;U*Vl%npc=zD37cKJIL;h4nzSgTj2BIWRm@KAH^S6<1|Wtnm~>$*@8-md42>i+8=*{}a`Q03FHN5G~H{-dEf ztIr3f@|({>FJEDn6^7eMr`;lMfZmGlo*n8-UParkKQAluBWvE$0E7t=5iW#IbbPoE zZ^>G0b?7Tk9ZJZ>o~xoLK7FrR?|kN#blXsXn{wz-&#-4n%b~iKqELB}P<{;0$a=3x zY#GFOXM>cOyBQfnKg9~iB>E|kV|P+J7{>Dca&f}uA?t&YjUVF!dAvg4V17BCig3Fy zR|fFKi&-76cdg|52~I;|D?_CZPe1?E1fKR4|CmdZLVO%10Bp^5^Uf^JrKaJAg3|o7x)H++6r`bB|N^*c=hxYc~PV?-j=)NGKH5kEye%#zJ4)8(Ji!849 zyKU$KgrjiFvq!VL!e}8@&UlK;J{8eyKny;Gl}v&4%!i4Xe$q4|6H(>j-?+Kl z)-oVpV!MNDmT|xxk~Q8=KuIhGq_pkJnxA)bH!!XrY3V|M#Cfp{Mf{!rGt$S4S(=i>EWEt~#PB*|=ahdq zQyIN|Hc`&FZEGI-eoJwvZGEEAsO`rN^&5x%P-aVK3O`<1yI!UCu1 z8)Ft`EgnOf9s&mCl7!0PNfX{sKaKR8A^LR+4Z-7=?leJQv?J5vRn3L$ZnXGigq3YF zs~t<#xRRsthK;A$wAdON+24$nijJmy9;*4KPAEN4lPr}Lzw4TWjlS!SWJLwCheIQZA6)B* zv)NW=ne0PNcUSk-aZi@cN($iU*_2y@4dqyjeZX_r{yhR7!;*0X#sA;4XU@#A&4NizIWd$)`3>NtDzol}eR8L18Z!M486iB+)&ZIo&-loxy~As>g{ zo~6MytCYcF%}fI&iPy2(XD!2$;j8@Xb$M?!E*4ClpxAy=L^2wpl3Um){gX*GOM!2=|k0 zr!@yeg-Upq5Cbwp#Z5Bgim2d^P$y(FKcw3eA)4})<6vq^wnf4oN|U*q>?ecg7Pz>) z2}MkVnOQwNhgXpy8@!SL|I&idA6Yv;h}XMmRW4fbt=ZYw2PG*XQU;1U z=b-bPFu7z9X>;WZSpajNKjO6W&ps%#y zYaPSzcexNkCs= z1?@YM@(~9LsIIuymutQ+8XRAkI;ampBg;1A-#>p61 z=CTYr8<0|c{%{A_CxA?VoM`2maHj{QIw}$FVNMgDus>2i2oFGRq;;5&bRHQlO927w zn*^F3*xg-24A=u#ohaFrSxi%B+|ecWs66BPUar?L(jct(DtEWIaDRK>uKRh<-f3;= z$fSJQ;`9rWi;MYu6;^CjVc9oKNa(aZ56TThn^p2A3$SWI=PTc<xeZPp%qE ztrXM8RZw|vD-b&L%AU?r2?Dv(y6^aRhYv5mn}c?6zY5tAuL21=^SG=gF&XG-SyR3U HTw?nNm^=)d delta 3810 zcmcImXHb)C7UmKSMCMxC9MG+~Az=rG2th=*2v$Hch^ZhyR`OcYl-t#=?dD4~{ZmluY>kAn`E`u?& zj<+DR04*(}z2Z|BS;s~Nkd2-RonV--%LV`}bTptQMg$b1hgd=(tlT=JfQtx1aL7dx z(ak&{fP_#0F&RZdNG%Ko#DZ9ilCr8IXv@o{2x1fzsh_f%vYPFG(?NuC!V^G{v*I-< z0cZ_*jgj&#Y2~gFzG__6x<9J`R zZdrmw-A;tk$>JlMgxXxB-KB4#=Zjd93PO<$pX4@KiXV+-^ND^Upu*8N7-%5?4R9wC zi~xnHZ!Qdj@<6#N%IF(p%bA=uUQkv7YdbXfeW#I>SsWlD|L-y&-*F)V3J2M#qhyhx z2cST`90Upg84YicWB{O%xU4jtX_$c4DU`+0r#bz8qnd^AK(sC5C4<_+H(bPht+OAB zPj*taeC$7N9B7xnE6FHfPN@Efcpe6HhVJrDh+&kVKzTcNUZ3QfiF54F_*{>2*)@a(?X#v?c#S7@ekD!4>(_Rg*j1b7$Zl`MN6M$y^6Ya<`WfFI zEKZHRwl!e=z4cKu*T*LK5sbTedwY7IbIrEm(*;zeCXq0}eYZ2AXgD_8Gdw8z+APcL zDqPT$@tIfAdXY|%zJf&fTq1Lj*4lz?>F9L-@W5Lqa@*E9{hJ@rt$er&{z;a|2CR;5 zeY=zJ=R+oVJ>93oh>F5ST_O2+GBh2GfrR~lKh(g-jPNt`>8Q|;uE(%|Ovl)#=cKi? z!0>=v#{n}Zn}I*+m<6&3BY#(Uj2ehNK4;+sFJHbaPyCUS_a~Bm(KE9^cwIzz`MU-L z2L=Q?Q+b1M2}1-E-HE|iqQ5Hiv9hZ;+zPG zkVSaeKotx|0jmHiC@LvXNvH7lQ299gKi{3G^1t65M{db#(bN4l;D-({e3yAf&5CZL zFAT2Zsq$g{Fb_yAQI-0>%W>LW-c&@OLE!Abi=M2j^-qp4*A*ett+5d}M4ZEi`xm4t z_TIN?2Vwi4;$alDXAdgNg?k!5x&2(`D8}ST4esrk>9i=bQ%p&5H0vO<7T@sx0oo?- zWEQWi0l7%jUoXs$)jsFYu%iDY-rnKBe@Uci$J5|NLag2Gq~wNq>8L~TpsO`q9jVpk z*(O!zlNUHK{L5!ei>Ip_y~jG#2th;P;pDWLNa3i-=!Z5EkKl)k8FRZ)3&edTEKE8o z(6ml9LB5D=RaeAYyC(Eh3hCG)G_iCWiu(F;if!WQ51L2UgV8mVXjTA4KAy2K2UHA1 zMX?`);HSw(QxE=mwxY*BpM>&(JW*VpX$u~u&GDo^z*N-%jv9ih)PHPp@`tK zuNtPGXYUhi`DIxdckg$^-z_BjX_z;nr7w}>Spsz zPW?ikQ2NP1`0B?3Pge5tXq-5Y$bnZJ;ig7{jojuDPY6@pg;{kzc@sq|n+tl$b8vn2 z?z+xc-HYbes~%QJk8HaMF`K^VsH!eTKR+Uqry^GyK7iuAaZ^g8cA>Es)(cenBs6I||>3H?A;?`cz?WoGI@}m#b;6^M1I=bp+6BFNl4U>ZGw{i)w0$sGVX- zQw{kTE$lwJYZa){*!^9qE=WAyj`L82Y}=&S=wEUvwRKb#pc6wvf~mr3`(tx(xqlt( zty_O|zUhMnWpOd4Pev$>Cu8cQ5apW-U?8dhQkhDfs1m3ODl4iesZg1!^pB9T<^m8h z(o<37cC}t?xTk>(SJT=8=bBZ>Nz+s@IiBU(lqZp;RvPF_;)=1ps|rb(`DZn=7Y@#M z=RV1}(*3oj;=Z8_gOKF*nU25{mrLUb%?D}W3wIXITSJC9!ooIuGDO`{eBAEc;hYaT zjJ#JcBWZzctm1oQBe8BLI=V>w?PEsggta|O4|$##pgA~XGk@ssSRLDS@T>S)w6w-+ zmV3Mkp{299%+p;i{`qfD-)-PoiueD*sBHkhRYcH_+nrGPW7`b>Mi$K9=-JL5J!DE4 zq_?R(SDOOQiP&N>uX2&7LcU88R}7=@7$tAx#_+{hjFDn6ohfUJ<&90N)TG20HU01t zYP7d%GT_D1Hw{?1tdzD$BT$nu@x@K;7TGhCax2sv;yM=@_i&n*XY?}{fRI&5A<=6+zq&!R_pyZ4>w`#TZrq89fCJ3z4 zH0eZ_p8Mu~{c7VS#$dFOcHhgs_-i>FWrYF!tq(`SiI&sYHO-`81&TJ*{MVcSluhCef^=?nK#x^=(0{>v<>$sXcL@X&MiPSHm0$;$asJX6v8r`Y|2PRdvp zpMckGwdhHK?R(_M^K%|7g;Vbo*4A9Wiy&7|m9Ly1 zAmreF+)2dS*FB)nI4sbQb`<^#he3x7#wkS@8kG7=s92FiGZUk~gammkBuW?sDnySh z8}`_}{T%+sN>Pe-A0SGe6=&Z_p1!IW;xSw!8mWHPukhtBTwAWBrvTC$yBcT4U?O41 zr00t)@_sx9*>>_uef9~pAiA{cjl#6ba({k*NaL+{lt>(C7U-=w&P5y6Q>UH@Hkr@r=rCR=da;o zvkR^w-OwBZLojrwi{y!P515 zU)woywHKEsi{Z7&Hr>Ih_f>qcN4YP4h1oFQ^V;pX4>brU(A0KW>@+XU?rGk^j8+~Z z&E5LTJwAmn&}VW*TMkGr0I9sa-a+GCCi|Jzkyqe~4Z6E7zI?Aom^^W0-yM-umzpxy zX{HKMl&+3QKyDIl{Oc+0@UZ$a;O1zd79)2V2O!s|aOo~Ni>)y{Z=Zo96do{}I@r!G zE78s2cK@Q4xcO5xvv0F$`NlMimk;Kh(?{^!!P9L|AuQJU-9flwdOGu~d`4d`j2&HpqG`T%1rk5CQ;4 zpc*~Y1I<7K#elznanoo{ zZ@JI}$3M_b^|Mr`28p4TGd0Fq*Z{aJqqfcH_OF)^Cz~amNUywel^lF&EGCOTmp6zp z=zF6F%2Gm4EaNAw1v$|UVfn?(XpeI7Q}kXJF7_q48}3U-TaoC83Rb0-RXrqRHpiMz z5i|BweoaYE)-F)h~rp zoY|El@@v(+SX`X65h|&5`zjl9jK;zby7TS#R?7r$T`Zs2^M9`hb@Z%~O#Cp}n^y3l zbKaY*T<7}k9^Yj9;)?OASrWT*hRB>8{~Va9eDhaW3qu`$R4P90yotQ&O#Iv^vpF+w z-gkj|Gul6aJFZyd8U5e$&*#En7Ypc93Gx+E4*F_|7v!*=@%ovwtR}JreK+HkoS(8k z$T!wAKU7kWe6S+@=2GQjaE~h}YCuHAkc849+b6~>^95bkxu(B##oF%fgJjN?3g15b zhem-ym)hi*)y$$98;-u3nK{#W%-G=i^5^=)n<6~S0^cXM_9R=LbO|^4x}}l7Ec|Xa zj;+;&&6ElR{C1Vl&*MKE?kT^g-py93c}*j<;;d^d6v^n3{5i(xx!pm-Fnes=D;y$z a7iO#_Q*eN0W-?uk-h&sk3U2^gbbkYg8cl=% diff --git a/vendor/golang.org/x/crypto/x509roots/fallback/bundle/bundle.go b/vendor/golang.org/x/crypto/x509roots/fallback/bundle/bundle.go index 10f20dcd9..3d250b40b 100644 --- a/vendor/golang.org/x/crypto/x509roots/fallback/bundle/bundle.go +++ b/vendor/golang.org/x/crypto/x509roots/fallback/bundle/bundle.go @@ -45,684 +45,682 @@ var unparsedCertificates = []unparsedCertificate{ certStartOff: 6732, certLength: 502, }, - { - cn: "CN=Atos TrustedRoot 2011,O=Atos,C=DE", - sha256Hash: "f356bea244b7a91eb35d53ca9ad7864ace018e2d35d5f8f96ddf68a6f41aa474", - certStartOff: 7234, - certLength: 891, - }, { cn: "CN=Atos TrustedRoot Root CA ECC TLS 2021,O=Atos,C=DE", sha256Hash: "b2fae53e14ccd7ab9212064701ae279c1d8988facb775fa8a008914e663988a8", - certStartOff: 8125, + certStartOff: 7234, certLength: 537, }, { cn: "CN=Atos TrustedRoot Root CA RSA TLS 2021,O=Atos,C=DE", sha256Hash: "81a9088ea59fb364c548a6f85559099b6f0405efbf18e5324ec9f457ba00112f", - certStartOff: 8662, + certStartOff: 7771, certLength: 1384, }, { cn: "CN=Autoridad de Certificacion Firmaprofesional CIF A62634068,C=ES", sha256Hash: "57de0583efd2b26e0361da99da9df4648def7ee8441c3b728afa9bcde0f9b26a", - certStartOff: 10046, + certStartOff: 9155, certLength: 1560, }, { cn: "CN=BJCA Global Root CA1,O=BEIJING CERTIFICATE AUTHORITY,C=CN", sha256Hash: "f3896f88fe7c0a882766a7fa6ad2749fb57a7f3e98fb769c1fa7b09c2c44d5ae", - certStartOff: 11606, + certStartOff: 10715, certLength: 1400, }, { cn: "CN=BJCA Global Root CA2,O=BEIJING CERTIFICATE AUTHORITY,C=CN", sha256Hash: "574df6931e278039667b720afdc1600fc27eb66dd3092979fb73856487212882", - certStartOff: 13006, + certStartOff: 12115, certLength: 553, }, { cn: "CN=Buypass Class 2 Root CA,O=Buypass AS-983163327,C=NO", sha256Hash: "9a114025197c5bb95d94e63d55cd43790847b646b23cdf11ada4a00eff15fb48", - certStartOff: 13559, + certStartOff: 12668, certLength: 1373, }, { cn: "CN=Buypass Class 3 Root CA,O=Buypass AS-983163327,C=NO", sha256Hash: "edf7ebbca27a2a384d387b7d4010c666e2edb4843e4c29b4ae1d5b9332e6b24d", - certStartOff: 14932, + certStartOff: 14041, certLength: 1373, }, { cn: "CN=CA Disig Root R2,O=Disig a.s.,L=Bratislava,C=SK", sha256Hash: "e23d4a036d7b70e9f595b1422079d2b91edfbb1fb651a0633eaa8a9dc5f80703", - certStartOff: 16305, + certStartOff: 15414, certLength: 1389, }, { cn: "CN=CFCA EV ROOT,O=China Financial Certification Authority,C=CN", sha256Hash: "5cc3d78e4e1d5e45547a04e6873e64f90cf9536d1ccc2ef800f355c4c5fd70fd", - certStartOff: 17694, + certStartOff: 16803, certLength: 1425, }, { cn: "CN=COMODO ECC Certification Authority,O=COMODO CA Limited,L=Salford,ST=Greater Manchester,C=GB", sha256Hash: "1793927a0614549789adce2f8f34f7f0b66d0f3ae3a3b84d21ec15dbba4fadc7", - certStartOff: 19119, + certStartOff: 18228, certLength: 653, }, { cn: "CN=COMODO RSA Certification Authority,O=COMODO CA Limited,L=Salford,ST=Greater Manchester,C=GB", sha256Hash: "52f0e1c4e58ec629291b60317f074671b85d7ea80d5b07273463534b32b40234", - certStartOff: 19772, + certStartOff: 18881, certLength: 1500, }, { cn: "CN=Certainly Root E1,O=Certainly,C=US", sha256Hash: "b4585f22e4ac756a4e8612a1361c5d9d031a93fd84febb778fa3068b0fc42dc2", - certStartOff: 21272, + certStartOff: 20381, certLength: 507, }, { cn: "CN=Certainly Root R1,O=Certainly,C=US", sha256Hash: "77b82cd8644c4305f7acc5cb156b45675004033d51c60c6202a8e0c33467d3a0", - certStartOff: 21779, + certStartOff: 20888, certLength: 1355, }, { cn: "CN=Certigna Root CA,OU=0002 48146308100036,O=Dhimyotis,C=FR", sha256Hash: "d48d3d23eedb50a459e55197601c27774b9d7b18c94d5a059511a10250b93168", - certStartOff: 23134, + certStartOff: 22243, certLength: 1631, }, { cn: "CN=Certum EC-384 CA,OU=Certum Certification Authority,O=Asseco Data Systems S.A.,C=PL", sha256Hash: "6b328085625318aa50d173c98d8bda09d57e27413d114cf787a0f5d06c030cf6", - certStartOff: 24765, + certStartOff: 23874, certLength: 617, }, { cn: "CN=Certum Trusted Network CA 2,OU=Certum Certification Authority,O=Unizeto Technologies S.A.,C=PL", sha256Hash: "b676f2eddae8775cd36cb0f63cd1d4603961f49e6265ba013a2f0307b6d0b804", - certStartOff: 25382, + certStartOff: 24491, certLength: 1494, }, { cn: "CN=Certum Trusted Network CA,OU=Certum Certification Authority,O=Unizeto Technologies S.A.,C=PL", sha256Hash: "5c58468d55f58e497e743982d2b50010b6d165374acf83a7d4a32db768c4408e", - certStartOff: 26876, + certStartOff: 25985, certLength: 959, }, { cn: "CN=Certum Trusted Root CA,OU=Certum Certification Authority,O=Asseco Data Systems S.A.,C=PL", sha256Hash: "fe7696573855773e37a95e7ad4d9cc96c30157c15d31765ba9b15704e1ae78fd", - certStartOff: 27835, + certStartOff: 26944, certLength: 1476, }, { cn: "CN=D-TRUST BR Root CA 1 2020,O=D-Trust GmbH,C=DE", sha256Hash: "e59aaa816009c22bff5b25bad37df306f049797c1f81d85ab089e657bd8f0044", - certStartOff: 29311, + certStartOff: 28420, certLength: 735, }, { cn: "CN=D-TRUST BR Root CA 2 2023,O=D-Trust GmbH,C=DE", sha256Hash: "0552e6f83fdf65e8fa9670e666df28a4e21340b510cbe52566f97c4fb94b2bd1", - certStartOff: 30046, + certStartOff: 29155, certLength: 1453, }, { cn: "CN=D-TRUST EV Root CA 1 2020,O=D-Trust GmbH,C=DE", sha256Hash: "08170d1aa36453901a2f959245e347db0c8d37abaabc56b81aa100dc958970db", - certStartOff: 31499, + certStartOff: 30608, certLength: 735, }, { cn: "CN=D-TRUST EV Root CA 2 2023,O=D-Trust GmbH,C=DE", sha256Hash: "8e8221b2e7d4007836a1672f0dcc299c33bc07d316f132fa1a206d587150f1ce", - certStartOff: 32234, + certStartOff: 31343, certLength: 1453, }, { cn: "CN=D-TRUST Root Class 3 CA 2 2009,O=D-Trust GmbH,C=DE", sha256Hash: "49e7a442acf0ea6287050054b52564b650e4f49e42e348d6aa38e039e957b1c1", - certStartOff: 33687, + certStartOff: 32796, certLength: 1079, }, { cn: "CN=D-TRUST Root Class 3 CA 2 EV 2009,O=D-Trust GmbH,C=DE", sha256Hash: "eec5496b988ce98625b934092eec2908bed0b0f316c2d4730c84eaf1f3d34881", - certStartOff: 34766, + certStartOff: 33875, certLength: 1095, }, { cn: "CN=DigiCert Assured ID Root G2,OU=www.digicert.com,O=DigiCert Inc,C=US", sha256Hash: "7d05ebb682339f8c9451ee094eebfefa7953a114edb2f44949452fab7d2fc185", - certStartOff: 35861, + certStartOff: 34970, certLength: 922, }, { cn: "CN=DigiCert Assured ID Root G3,OU=www.digicert.com,O=DigiCert Inc,C=US", sha256Hash: "7e37cb8b4c47090cab36551ba6f45db840680fba166a952db100717f43053fc2", - certStartOff: 36783, + certStartOff: 35892, certLength: 586, }, { cn: "CN=DigiCert Global Root G2,OU=www.digicert.com,O=DigiCert Inc,C=US", sha256Hash: "cb3ccbb76031e5e0138f8dd39a23f9de47ffc35e43c1144cea27d46a5ab1cb5f", - certStartOff: 37369, + certStartOff: 36478, certLength: 914, }, { cn: "CN=DigiCert Global Root G3,OU=www.digicert.com,O=DigiCert Inc,C=US", sha256Hash: "31ad6648f8104138c738f39ea4320133393e3a18cc02296ef97c2ac9ef6731d0", - certStartOff: 38283, + certStartOff: 37392, certLength: 579, }, { cn: "CN=DigiCert TLS ECC P384 Root G5,O=DigiCert\\, Inc.,C=US", sha256Hash: "018e13f0772532cf809bd1b17281867283fc48c6e13be9c69812854a490c1b05", - certStartOff: 38862, + certStartOff: 37971, certLength: 541, }, { cn: "CN=DigiCert TLS RSA4096 Root G5,O=DigiCert\\, Inc.,C=US", sha256Hash: "371a00dc0533b3721a7eeb40e8419e70799d2b0a0f2c1d80693165f7cec4ad75", - certStartOff: 39403, + certStartOff: 38512, certLength: 1386, }, { cn: "CN=DigiCert Trusted Root G4,OU=www.digicert.com,O=DigiCert Inc,C=US", sha256Hash: "552f7bdcf1a7af9e6ce672017f4f12abf77240c78e761ac203d1d9d20ac89988", - certStartOff: 40789, + certStartOff: 39898, certLength: 1428, }, - { - cn: "CN=Entrust Root Certification Authority,OU=www.entrust.net/CPS is incorporated by reference+OU=(c) 2006 Entrust\\, Inc.,O=Entrust\\, Inc.,C=US", - sha256Hash: "73c176434f1bc6d5adf45b0e76e727287c8de57616c1e6e6141a2b2cbc7d8e4c", - certStartOff: 42217, - certLength: 1173, - distrustAfter: "2024-11-30T23:59:59Z", - }, { cn: "CN=GDCA TrustAUTH R5 ROOT,O=GUANG DONG CERTIFICATE AUTHORITY CO.\\,LTD.,C=CN", sha256Hash: "bfff8fd04433487d6a8aa60c1a29767a9fc2bbb05e420f713a13b992891d3893", - certStartOff: 43390, + certStartOff: 41326, certLength: 1420, }, { cn: "CN=GTS Root R1,O=Google Trust Services LLC,C=US", sha256Hash: "d947432abde7b7fa90fc2e6b59101b1280e0e1c7e4e40fa3c6887fff57a7f4cf", - certStartOff: 44810, + certStartOff: 42746, certLength: 1371, }, { cn: "CN=GTS Root R3,O=Google Trust Services LLC,C=US", sha256Hash: "34d8a73ee208d9bcdb0d956520934b4e40e69482596e8b6f73c8426b010a6f48", - certStartOff: 46181, + certStartOff: 44117, certLength: 525, }, { cn: "CN=GTS Root R4,O=Google Trust Services LLC,C=US", sha256Hash: "349dfa4058c5e263123b398ae795573c4e1313c83fe68f93556cd5e8031b3c7d", - certStartOff: 46706, + certStartOff: 44642, certLength: 525, }, { cn: "CN=GlobalSign Root E46,O=GlobalSign nv-sa,C=BE", sha256Hash: "cbb9c44d84b8043e1050ea31a69f514955d7bfd2e2c6b49301019ad61d9f5058", - certStartOff: 47231, + certStartOff: 45167, certLength: 527, }, { cn: "CN=GlobalSign Root R46,O=GlobalSign nv-sa,C=BE", sha256Hash: "4fa3126d8d3a11d1c4855a4f807cbad6cf919d3a5a88b03bea2c6372d93c40c9", - certStartOff: 47758, + certStartOff: 45694, certLength: 1374, }, { cn: "CN=GlobalSign,OU=GlobalSign ECC Root CA - R4,O=GlobalSign", sha256Hash: "b085d70b964f191a73e4af0d54ae7a0e07aafdaf9b71dd0862138ab7325a24a2", - certStartOff: 49132, + certStartOff: 47068, certLength: 480, }, { cn: "CN=GlobalSign,OU=GlobalSign ECC Root CA - R5,O=GlobalSign", sha256Hash: "179fbc148a3dd00fd24ea13458cc43bfa7f59c8182d783a513f6ebec100c8924", - certStartOff: 49612, + certStartOff: 47548, certLength: 546, }, { cn: "CN=GlobalSign,OU=GlobalSign Root CA - R3,O=GlobalSign", sha256Hash: "cbb522d7b7f127ad6a0113865bdf1cd4102e7d0759af635a7cf4720dc963c53b", - certStartOff: 50158, + certStartOff: 48094, certLength: 867, }, { cn: "CN=GlobalSign,OU=GlobalSign Root CA - R6,O=GlobalSign", sha256Hash: "2cabeafe37d06ca22aba7391c0033d25982952c453647349763a3ab5ad6ccf69", - certStartOff: 51025, + certStartOff: 48961, certLength: 1415, }, { cn: "CN=Go Daddy Root Certificate Authority - G2,O=GoDaddy.com\\, Inc.,L=Scottsdale,ST=Arizona,C=US", sha256Hash: "45140b3247eb9cc8c5b4f0d7b53091f73292089e6e5a63e2749dd3aca9198eda", - certStartOff: 52440, + certStartOff: 50376, certLength: 969, }, { cn: "CN=HARICA TLS ECC Root CA 2021,O=Hellenic Academic and Research Institutions CA,C=GR", sha256Hash: "3f99cc474acfce4dfed58794665e478d1547739f2e780f1bb4ca9b133097d401", - certStartOff: 53409, + certStartOff: 51345, certLength: 600, }, { cn: "CN=HARICA TLS RSA Root CA 2021,O=Hellenic Academic and Research Institutions CA,C=GR", sha256Hash: "d95d0e8eda79525bf9beb11b14d2100d3294985f0c62d9fabd9cd999eccb7b1d", - certStartOff: 54009, + certStartOff: 51945, certLength: 1448, }, { cn: "CN=Hellenic Academic and Research Institutions ECC RootCA 2015,O=Hellenic Academic and Research Institutions Cert. Authority,L=Athens,C=GR", sha256Hash: "44b545aa8a25e65a73ca15dc27fc36d24c1cb9953a066539b11582dc487b4833", - certStartOff: 55457, + certStartOff: 53393, certLength: 711, }, { cn: "CN=Hellenic Academic and Research Institutions RootCA 2015,O=Hellenic Academic and Research Institutions Cert. Authority,L=Athens,C=GR", sha256Hash: "a040929a02ce53b4acf4f2ffc6981ce4496f755e6d45fe0b2a692bcd52523f36", - certStartOff: 56168, + certStartOff: 54104, certLength: 1551, }, { cn: "CN=HiPKI Root CA - G1,O=Chunghwa Telecom Co.\\, Ltd.,C=TW", sha256Hash: "f015ce3cc239bfef064be9f1d2c417e1a0264a0a94be1f0c8d121864eb6949cc", - certStartOff: 57719, + certStartOff: 55655, certLength: 1390, }, { cn: "CN=Hongkong Post Root CA 3,O=Hongkong Post,L=Hong Kong,ST=Hong Kong,C=HK", sha256Hash: "5a2fc03f0c83b090bbfa40604b0988446c7636183df9846e17101a447fb8efd6", - certStartOff: 59109, + certStartOff: 57045, certLength: 1491, }, { cn: "CN=ISRG Root X1,O=Internet Security Research Group,C=US", sha256Hash: "96bcec06264976f37460779acf28c5a7cfe8a3c0aae11a8ffcee05c0bddf08c6", - certStartOff: 60600, + certStartOff: 58536, certLength: 1391, }, { cn: "CN=ISRG Root X2,O=Internet Security Research Group,C=US", sha256Hash: "69729b8e15a86efc177a57afb7171dfc64add28c2fca8cf1507e34453ccb1470", - certStartOff: 61991, + certStartOff: 59927, certLength: 543, }, { cn: "CN=IdenTrust Commercial Root CA 1,O=IdenTrust,C=US", sha256Hash: "5d56499be4d2e08bcfcad08a3e38723d50503bde706948e42f55603019e528ae", - certStartOff: 62534, + certStartOff: 60470, certLength: 1380, }, { cn: "CN=IdenTrust Public Sector Root CA 1,O=IdenTrust,C=US", sha256Hash: "30d0895a9a448a262091635522d1f52010b5867acae12c78ef958fd4f4389f2f", - certStartOff: 63914, + certStartOff: 61850, certLength: 1386, }, { cn: "CN=Izenpe.com,O=IZENPE S.A.,C=ES", sha256Hash: "2530cc8e98321502bad96f9b1fba1b099e2d299e0f4548bb914f363bc0d4531f", - certStartOff: 65300, + certStartOff: 63236, certLength: 1525, }, { cn: "CN=Microsec e-Szigno Root CA 2009,O=Microsec Ltd.,L=Budapest,C=HU,1.2.840.113549.1.9.1=#0c10696e666f40652d737a69676e6f2e6875", sha256Hash: "3c5f81fea5fab82c64bfa2eaecafcde8e077fc8620a7cae537163df36edbf378", - certStartOff: 66825, + certStartOff: 64761, certLength: 1038, }, { cn: "CN=Microsoft ECC Root Certificate Authority 2017,O=Microsoft Corporation,C=US", sha256Hash: "358df39d764af9e1b766e9c972df352ee15cfac227af6ad1d70e8e4a6edcba02", - certStartOff: 67863, + certStartOff: 65799, certLength: 605, }, { cn: "CN=Microsoft RSA Root Certificate Authority 2017,O=Microsoft Corporation,C=US", sha256Hash: "c741f70f4b2a8d88bf2e71c14122ef53ef10eba0cfa5e64cfa20f418853073e0", - certStartOff: 68468, + certStartOff: 66404, certLength: 1452, }, { cn: "CN=NAVER Global Root Certification Authority,O=NAVER BUSINESS PLATFORM Corp.,C=KR", sha256Hash: "88f438dcf8ffd1fa8f429115ffe5f82ae1e06e0c70c375faad717b34a49e7265", - certStartOff: 69920, + certStartOff: 67856, certLength: 1446, }, { cn: "CN=NetLock Arany (Class Gold) Főtanúsítvány,OU=Tanúsítványkiadók (Certification Services),O=NetLock Kft.,L=Budapest,C=HU", sha256Hash: "6c61dac3a2def031506be036d2a6fe401994fbd13df9c8d466599274c446ec98", - certStartOff: 71366, + certStartOff: 69302, certLength: 1049, }, { cn: "CN=OISTE Server Root ECC G1,O=OISTE Foundation,C=CH", sha256Hash: "eec997c0c30f216f7e3b8b307d2bae42412d753fc8219dafd1520b2572850f49", - certStartOff: 72415, + certStartOff: 70351, certLength: 569, }, { cn: "CN=OISTE Server Root RSA G1,O=OISTE Foundation,C=CH", sha256Hash: "9ae36232a5189ffddb353dfd26520c015395d22777dac59db57b98c089a651e6", - certStartOff: 72984, + certStartOff: 70920, certLength: 1415, }, { cn: "CN=OISTE WISeKey Global Root GB CA,OU=OISTE Foundation Endorsed,O=WISeKey,C=CH", sha256Hash: "6b9c08e86eb0f767cfad65cd98b62149e5494a67f5845e7bd1ed019f27b86bd6", - certStartOff: 74399, + certStartOff: 72335, certLength: 953, }, { cn: "CN=OISTE WISeKey Global Root GC CA,OU=OISTE Foundation Endorsed,O=WISeKey,C=CH", sha256Hash: "8560f91c3624daba9570b5fea0dbe36ff11a8323be9486854fb3f34a5571198d", - certStartOff: 75352, + certStartOff: 73288, certLength: 621, }, { cn: "CN=QuoVadis Root CA 1 G3,O=QuoVadis Limited,C=BM", sha256Hash: "8a866fd1b276b57e578e921c65828a2bed58e9f2f288054134b7f1f4bfc9cc74", - certStartOff: 75973, + certStartOff: 73909, certLength: 1380, }, { cn: "CN=QuoVadis Root CA 2 G3,O=QuoVadis Limited,C=BM", sha256Hash: "8fe4fb0af93a4d0d67db0bebb23e37c71bf325dcbcdd240ea04daf58b47e1840", - certStartOff: 77353, + certStartOff: 75289, certLength: 1380, }, { cn: "CN=QuoVadis Root CA 3 G3,O=QuoVadis Limited,C=BM", sha256Hash: "88ef81de202eb018452e43f864725cea5fbd1fc2d9d205730709c5d8b8690f46", - certStartOff: 78733, + certStartOff: 76669, certLength: 1380, }, + { + cn: "CN=SECOM TLS ECC Root CA 2024,O=SECOM Trust Systems Co.\\, Ltd.,C=JP", + sha256Hash: "6ab2ab75f51cb4f4f0156203fbf6f646232f514be059f62833308b82b4d72db1", + certStartOff: 78049, + certLength: 592, + }, + { + cn: "CN=SECOM TLS RSA Root CA 2024,O=SECOM Trust Systems Co.\\, Ltd.,C=JP", + sha256Hash: "1435f225c5d252d7a21948cc3ce62aecfa88001e3dd72d1cc3555100eb372f93", + certStartOff: 78641, + certLength: 1438, + }, { cn: "CN=SSL.com EV Root Certification Authority ECC,O=SSL Corporation,L=Houston,ST=Texas,C=US", sha256Hash: "22a2c1f7bded704cc1e701b5f408c310880fe956b5de2a4a44f99c873a25a7c8", - certStartOff: 80113, + certStartOff: 80079, certLength: 664, }, { cn: "CN=SSL.com EV Root Certification Authority RSA R2,O=SSL Corporation,L=Houston,ST=Texas,C=US", sha256Hash: "2e7bf16cc22485a7bbe2aa8696750761b0ae39be3b2fe9d0cc6d4ef73491425c", - certStartOff: 80777, + certStartOff: 80743, certLength: 1519, }, { cn: "CN=SSL.com Root Certification Authority ECC,O=SSL Corporation,L=Houston,ST=Texas,C=US", sha256Hash: "3417bb06cc6007da1b961c920b8ab4ce3fad820e4aa30b9acbc4a74ebdcebc65", - certStartOff: 82296, + certStartOff: 82262, certLength: 657, }, { cn: "CN=SSL.com Root Certification Authority RSA,O=SSL Corporation,L=Houston,ST=Texas,C=US", sha256Hash: "85666a562ee0be5ce925c1d8890a6f76a87ec16d4d7d5f29ea7419cf20123b69", - certStartOff: 82953, + certStartOff: 82919, certLength: 1505, }, { cn: "CN=SSL.com TLS ECC Root CA 2022,O=SSL Corporation,C=US", sha256Hash: "c32ffd9f46f936d16c3673990959434b9ad60aafbb9e7cf33654f144cc1ba143", - certStartOff: 84458, + certStartOff: 84424, certLength: 574, }, { cn: "CN=SSL.com TLS RSA Root CA 2022,O=SSL Corporation,C=US", sha256Hash: "8faf7d2e2cb4709bb8e0b33666bf75a5dd45b5de480f8ea8d4bfe6bebc17f2ed", - certStartOff: 85032, + certStartOff: 84998, certLength: 1421, }, { cn: "CN=SZAFIR ROOT CA2,O=Krajowa Izba Rozliczeniowa S.A.,C=PL", sha256Hash: "a1339d33281a0b56e557d3d32b1ce7f9367eb094bd5fa72a7e5004c8ded7cafe", - certStartOff: 86453, + certStartOff: 86419, certLength: 886, }, { cn: "CN=Sectigo Public Server Authentication Root E46,O=Sectigo Limited,C=GB", sha256Hash: "c90f26f0fb1b4018b22227519b5ca2b53e2ca5b3be5cf18efe1bef47380c5383", - certStartOff: 87339, + certStartOff: 87305, certLength: 574, }, { cn: "CN=Sectigo Public Server Authentication Root R46,O=Sectigo Limited,C=GB", sha256Hash: "7bb647a62aeeac88bf257aa522d01ffea395e0ab45c73f93f65654ec38f25a06", - certStartOff: 87913, + certStartOff: 87879, certLength: 1422, }, - { - cn: "CN=SecureSign Root CA12,O=Cybertrust Japan Co.\\, Ltd.,C=JP", - sha256Hash: "3f034bb5704d44b2d08545a02057de93ebf3905fce721acbc730c06ddaee904e", - certStartOff: 89335, - certLength: 886, - }, { cn: "CN=SecureSign Root CA14,O=Cybertrust Japan Co.\\, Ltd.,C=JP", sha256Hash: "4b009c1034494f9ab56bba3ba1d62731fc4d20d8955adcec10a925607261e338", - certStartOff: 90221, + certStartOff: 89301, certLength: 1398, }, { cn: "CN=SecureSign Root CA15,O=Cybertrust Japan Co.\\, Ltd.,C=JP", sha256Hash: "e778f0f095fe843729cd1a0082179e5314a9c291442805e1fb1d8fb6b8886c3a", - certStartOff: 91619, + certStartOff: 90699, certLength: 551, }, { cn: "CN=Security Communication ECC RootCA1,O=SECOM Trust Systems CO.\\,LTD.,C=JP", sha256Hash: "e74fbda55bd564c473a36b441aa799c8a68e077440e8288b9fa1e50e4bbaca11", - certStartOff: 92170, + certStartOff: 91250, certLength: 572, }, { cn: "CN=Starfield Root Certificate Authority - G2,O=Starfield Technologies\\, Inc.,L=Scottsdale,ST=Arizona,C=US", sha256Hash: "2ce1cb0bf9d2f9e102993fbe215152c3b2dd0cabde1c68e5319b839154dbb7f5", - certStartOff: 92742, + certStartOff: 91822, certLength: 993, }, { cn: "CN=Starfield Services Root Certificate Authority - G2,O=Starfield Technologies\\, Inc.,L=Scottsdale,ST=Arizona,C=US", sha256Hash: "568d6905a2c88708a4b3025190edcfedb1974a606a13c6e5290fcb2ae63edab5", - certStartOff: 93735, + certStartOff: 92815, certLength: 1011, }, { cn: "CN=SwissSign RSA TLS Root CA 2022 - 1,O=SwissSign AG,C=CH", sha256Hash: "193144f431e0fddb740717d4de926a571133884b4360d30e272913cbe660ce41", - certStartOff: 94746, + certStartOff: 93826, certLength: 1431, }, { cn: "CN=T-TeleSec GlobalRoot Class 2,OU=T-Systems Trust Center,O=T-Systems Enterprise Services GmbH,C=DE", sha256Hash: "91e2f5788d5810eba7ba58737de1548a8ecacd014598bc0b143e041b17052552", - certStartOff: 96177, + certStartOff: 95257, certLength: 967, }, { cn: "CN=T-TeleSec GlobalRoot Class 3,OU=T-Systems Trust Center,O=T-Systems Enterprise Services GmbH,C=DE", sha256Hash: "fd73dad31c644ff1b43bef0ccdda96710b9cd9875eca7e31707af3e96d522bbd", - certStartOff: 97144, + certStartOff: 96224, certLength: 967, }, { cn: "CN=TWCA CYBER Root CA,OU=Root CA,O=TAIWAN-CA,C=TW", sha256Hash: "3f63bb2814be174ec8b6439cf08d6d56f0b7c405883a5648a334424d6b3ec558", - certStartOff: 98111, + certStartOff: 97191, certLength: 1425, }, { cn: "CN=TWCA Global Root CA,OU=Root CA,O=TAIWAN-CA,C=TW", sha256Hash: "59769007f7685d0fcd50872f9f95d5755a5b2b457d81f3692b610a98672f0e1b", - certStartOff: 99536, + certStartOff: 98616, certLength: 1349, }, { cn: "CN=TWCA Root Certification Authority,OU=Root CA,O=TAIWAN-CA,C=TW", sha256Hash: "bfd88fe1101c41ae3e801bf8be56350ee9bad1a6b9bd515edc5c6d5b8711ac44", - certStartOff: 100885, + certStartOff: 99965, certLength: 895, }, { cn: "CN=Telekom Security TLS ECC Root 2020,O=Deutsche Telekom Security GmbH,C=DE", sha256Hash: "578af4ded0853f4e5998db4aeaf9cbea8d945f60b620a38d1a3c13b2bc7ba8e1", - certStartOff: 101780, + certStartOff: 100860, certLength: 582, }, { cn: "CN=Telekom Security TLS RSA Root 2023,O=Deutsche Telekom Security GmbH,C=DE", sha256Hash: "efc65cadbb59adb6efe84da22311b35624b71b3b1ea0da8b6655174ec8978646", - certStartOff: 102362, + certStartOff: 101442, certLength: 1463, }, + { + cn: "CN=Telia EC TLS Root CA v3,O=Telia Company AB,C=SE", + sha256Hash: "098e08a91dbbf77478b96cceb89b1413a5da37b7c862606a955deb07179f4326", + certStartOff: 102905, + certLength: 566, + }, + { + cn: "CN=Telia RSA TLS Root CA v3,O=Telia Company AB,C=SE", + sha256Hash: "d13db1294c45ebc6fc86c6bbf69fa29bdfe692dff7c713c243c7a956c6a2284c", + certStartOff: 103471, + certLength: 1414, + }, { cn: "CN=Telia Root CA v2,O=Telia Finland Oyj,C=FI", sha256Hash: "242b69742fcb1e5b2abf98898b94572187544e5b4d9911786573621f6a74b82c", - certStartOff: 103825, + certStartOff: 104885, certLength: 1400, }, { cn: "CN=TrustAsia Global Root CA G3,O=TrustAsia Technologies\\, Inc.,C=CN", sha256Hash: "e0d3226aeb1163c2e48ff9be3b50b4c6431be7bb1eacc5c36b5d5ec509039a08", - certStartOff: 105225, + certStartOff: 106285, certLength: 1449, }, { cn: "CN=TrustAsia Global Root CA G4,O=TrustAsia Technologies\\, Inc.,C=CN", sha256Hash: "be4b56cb5056c0136a526df444508daa36a0b54f42e4ac38f72af470e479654c", - certStartOff: 106674, + certStartOff: 107734, certLength: 601, }, { cn: "CN=TrustAsia TLS ECC Root CA,O=TrustAsia Technologies\\, Inc.,C=CN", sha256Hash: "c0076b9ef0531fb1a656d67c4ebe97cd5dbaa41ef44598acc2489878c92d8711", - certStartOff: 107275, + certStartOff: 108335, certLength: 565, }, { cn: "CN=TrustAsia TLS RSA Root CA,O=TrustAsia Technologies\\, Inc.,C=CN", sha256Hash: "06c08d7dafd876971eb1124fe67f847ec0c7a158d3ea53cbe940e2ea9791f4c3", - certStartOff: 107840, + certStartOff: 108900, certLength: 1412, }, { cn: "CN=TunTrust Root CA,O=Agence Nationale de Certification Electronique,C=TN", sha256Hash: "2e44102ab58cb85419451c8e19d9acf3662cafbc614b6a53960a30f7d0e2eb41", - certStartOff: 109252, + certStartOff: 110312, certLength: 1463, }, { cn: "CN=UCA Extended Validation Root,O=UniTrust,C=CN", sha256Hash: "d43af9b35473755c9684fc06d7d8cb70ee5c28e773fb294eb41ee71722924d24", - certStartOff: 110715, + certStartOff: 111775, certLength: 1374, }, { cn: "CN=UCA Global G2 Root,O=UniTrust,C=CN", sha256Hash: "9bea11c976fe014764c1be56a6f914b5a560317abd9988393382e5161aa0493c", - certStartOff: 112089, + certStartOff: 113149, certLength: 1354, }, { cn: "CN=USERTrust ECC Certification Authority,O=The USERTRUST Network,L=Jersey City,ST=New Jersey,C=US", sha256Hash: "4ff460d54b9c86dabfbcfc5712e0400d2bed3fbc4d4fbdaa86e06adcd2a9ad7a", - certStartOff: 113443, + certStartOff: 114503, certLength: 659, }, { cn: "CN=USERTrust RSA Certification Authority,O=The USERTRUST Network,L=Jersey City,ST=New Jersey,C=US", sha256Hash: "e793c9b02fd8aa13e21c31228accb08119643b749c898964b1746d46c3d4cbd2", - certStartOff: 114102, + certStartOff: 115162, certLength: 1506, }, { cn: "CN=e-Szigno Root CA 2017,O=Microsec Ltd.,L=Budapest,C=HU,2.5.4.97=#130e56415448552d3233353834343937", sha256Hash: "beb00b30839b9bc32c32e4447905950641f26421b15ed089198b518ae2ea1b99", - certStartOff: 115608, + certStartOff: 116668, certLength: 580, }, { cn: "CN=e-Szigno TLS Root CA 2023,O=Microsec Ltd.,L=Budapest,C=HU,2.5.4.97=#130e56415448552d3233353834343937", sha256Hash: "b49141502d00663d740f2e7ec340c52800962666121a36d09cf7dd2b90384fb4", - certStartOff: 116188, + certStartOff: 117248, certLength: 723, }, { cn: "CN=emSign ECC Root CA - C3,OU=emSign PKI,O=eMudhra Inc,C=US", sha256Hash: "bc4d809b15189d78db3e1d8cf4f9726a795da1643ca5f1358e1ddb0edc0d7eb3", - certStartOff: 116911, + certStartOff: 117971, certLength: 559, }, { cn: "CN=emSign ECC Root CA - G3,OU=emSign PKI,O=eMudhra Technologies Limited,C=IN", sha256Hash: "86a1ecba089c4a8d3bbe2734c612ba341d813e043cf9e8a862cd5c57a36bbe6b", - certStartOff: 117470, + certStartOff: 118530, certLength: 594, }, { cn: "CN=emSign Root CA - C1,OU=emSign PKI,O=eMudhra Inc,C=US", sha256Hash: "125609aa301da0a249b97a8239cb6a34216f44dcac9f3954b14292f2e8c8608f", - certStartOff: 118064, + certStartOff: 119124, certLength: 887, }, { cn: "CN=emSign Root CA - G1,OU=emSign PKI,O=eMudhra Technologies Limited,C=IN", sha256Hash: "40f6af0346a99aa1cd1d555a4e9cce62c7f9634603ee406615833dc8c8d00367", - certStartOff: 118951, + certStartOff: 120011, certLength: 920, }, { cn: "CN=vTrus ECC Root CA,O=iTrusChina Co.\\,Ltd.,C=CN", sha256Hash: "30fbba2c32238e2a98547af97931e550428b9b3f1c8eeb6633dcfa86c5b27dd3", - certStartOff: 119871, + certStartOff: 120931, certLength: 531, }, { cn: "CN=vTrus Root CA,O=iTrusChina Co.\\,Ltd.,C=CN", sha256Hash: "8a71de6559336f426c26e53880d00d88a18da4c6a91f0dcb6194e206c5c96387", - certStartOff: 120402, + certStartOff: 121462, certLength: 1370, }, { cn: "OU=AC RAIZ FNMT-RCM,O=FNMT-RCM,C=ES", sha256Hash: "ebc5570c29018c4d67b1aa127baf12f703b4611ebc17b7dab5573894179b93fa", - certStartOff: 121772, + certStartOff: 122832, certLength: 1415, }, { cn: "OU=Security Communication RootCA2,O=SECOM Trust Systems CO.\\,LTD.,C=JP", sha256Hash: "513b2cecb810d4cde5dd85391adfc6c2dd60d87bb736d2b521484aa47a0ebef6", - certStartOff: 123187, + certStartOff: 124247, certLength: 891, }, { cn: "OU=certSIGN ROOT CA G2,O=CERTSIGN SA,C=RO", sha256Hash: "657cfe2fa73faa38462571f332a2363a46fce7020951710702cdfbb6eeda3305", - certStartOff: 124078, + certStartOff: 125138, certLength: 1355, }, - { - cn: "OU=ePKI Root Certification Authority,O=Chunghwa Telecom Co.\\, Ltd.,C=TW", - sha256Hash: "c0a6f4dc63a24bfdcf54ef2a6a082a0a72de35803e2ff5ff527ae5d87206dfd5", - certStartOff: 125433, - certLength: 1460, - distrustAfter: "2025-04-15T23:59:59Z", - }, { cn: "SERIALNUMBER=G63287510,CN=ANF Secure Server Root CA,OU=ANF CA Raiz,O=ANF Autoridad de Certificacion,C=ES", sha256Hash: "fb8fec759169b9106b1e511644c618c51304373f6c0643088d8beffd1b997599", - certStartOff: 126893, + certStartOff: 126493, certLength: 1523, }, } diff --git a/vendor/modules.txt b/vendor/modules.txt index a099f88a7..b09fe1c21 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -453,7 +453,7 @@ go.uber.org/goleak/internal/stack golang.org/x/crypto/md4 golang.org/x/crypto/ocsp golang.org/x/crypto/ripemd160 -# golang.org/x/crypto/x509roots/fallback v0.0.0-20260609182332-5f2de1a9f1e2 +# golang.org/x/crypto/x509roots/fallback v0.0.0-20260723152544-d701c51f7e4e ## explicit; go 1.25.0 golang.org/x/crypto/x509roots/fallback golang.org/x/crypto/x509roots/fallback/bundle From 29ac39cf0ee5553eaaa1be8696f00e72a9958083 Mon Sep 17 00:00:00 2001 From: Mihail Stoykov <312246+mstoykov@users.noreply.github.com> Date: Tue, 28 Jul 2026 13:18:14 +0300 Subject: [PATCH 059/182] Update sobek and regexp2 (#6218) sobek: 267a0e055bb4 -> 7781506a890f regexp2/v2: v2.2.2 -> v2.5.2 (indirect) sobek: - WeakMap/WeakSet entries are now actually collectable. Instead of storing values in a map hanging off each key *Object (which kept them alive as long as the key was reachable), weak maps hold their own mutex-guarded map keyed by object identity and use runtime.AddCleanup to drop entries when the key is collected. - Object and Symbol shrank: both derive identity from their own address, so Object.id, Object.weakRefs, Symbol.h and Runtime.genId are gone. - String.prototype.split no longer round-trips through UTF-8, with dedicated ASCII and UTF-16 paths; indexOf/lastIndexOf on unicode strings use bytes.Index/LastIndex above a 32-unit crossover instead of a naive scan. CompareTo compares UTF-16 code units, fixing ordering around surrogates. - Several typed array fixes: filter, toSorted and with ignored the view's offset when writing to the destination; slice mishandled forward-overlapping buffers; with validated the index before coercing its argument, so a detaching valueOf was missed; out-of-bounds foreign sets no longer fall through to the generic path. - baseObject.setForeignIdx passed its arguments in the wrong order, sending the property name as the value. regexp2: - Backtracking is now bounded. MaxBacktrackingStackSize (default 100000, negative to disable) and OptionMaxBacktrackingStackSize cap the track stack, and a match that exceeds it fails with ErrBacktrackingStackLimit rather than growing until it runs out of memory. This complements MatchTimeout for catastrophic patterns. - Bool-only matching APIs run a second compiled program with capture marks removed for slots the pattern never observes. - The "advance past an empty match" logic moved into scan(), replacing four copies in FindNextMatch, findAllRunesIndex and both replace runners, and keeps Runtextstart put so \G behaves. - Leading single-set patterns get a prefix-scan fast path, and alternations precompute their distinct first runes. - Fixes a CharSet aliased and mutated during fixed-set analysis, and collapses a repeat of an empty expression that otherwise cost a backtracking frame per iteration. Co-Authored-By: Claude Opus 5 (1M context) --- go.mod | 4 +- go.sum | 8 +- ...breaking_test_errors-stripTypes=false.json | 15 -- .../breaking_test_errors-stripTypes=true.json | 15 -- .../github.com/dlclark/regexp2/v2/options.go | 15 +- .../github.com/dlclark/regexp2/v2/regexp.go | 81 +++---- .../dlclark/regexp2/v2/regexp_codegen.go | 18 +- .../github.com/dlclark/regexp2/v2/replace.go | 24 +- .../github.com/dlclark/regexp2/v2/runner.go | 206 ++++++++++++++---- .../dlclark/regexp2/v2/stringprefixfilter.go | 90 ++++++++ .../dlclark/regexp2/v2/syntax/code.go | 34 +++ .../regexp2/v2/syntax/optimizations.go | 29 ++- .../regexp2/v2/syntax/prefixanalyzer.go | 3 +- .../dlclark/regexp2/v2/syntax/tree.go | 6 + .../dlclark/regexp2/v2/syntax/writer.go | 74 +++++-- .../grafana/sobek/builtin_string.go | 96 ++++++-- .../grafana/sobek/builtin_typedarrays.go | 36 +-- .../grafana/sobek/builtin_weakmap.go | 78 +++++-- .../grafana/sobek/builtin_weakset.go | 4 +- vendor/github.com/grafana/sobek/object.go | 182 +++++++--------- vendor/github.com/grafana/sobek/runtime.go | 18 +- .../github.com/grafana/sobek/string_ascii.go | 21 +- .../grafana/sobek/string_imported.go | 6 +- .../grafana/sobek/string_unicode.go | 200 +++++++++++++---- .../github.com/grafana/sobek/typedarrays.go | 12 + vendor/github.com/grafana/sobek/value.go | 17 +- vendor/modules.txt | 6 +- 27 files changed, 888 insertions(+), 410 deletions(-) diff --git a/go.mod b/go.mod index 43d62e6dc..9dd163b88 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/gorilla/websocket v1.5.3 github.com/grafana/k6-cloud-openapi-client-go v0.0.3-0.20260716125012-97c96146fa7c github.com/grafana/k6provider v0.5.0 - github.com/grafana/sobek v0.0.0-20260708062710-267a0e055bb4 + github.com/grafana/sobek v0.0.0-20260727154728-7781506a890f github.com/grafana/sobek-webapi-encoding v0.1.0 github.com/grafana/xk6-dashboard-assets v0.1.2 github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 @@ -77,7 +77,7 @@ require ( github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/chromedp/sysutil v1.1.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/dlclark/regexp2/v2 v2.2.2 // indirect + github.com/dlclark/regexp2/v2 v2.5.2 // indirect github.com/go-logr/logr v1.4.3 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/google/pprof v0.0.0-20260115054156-294ebfa9ad83 // indirect diff --git a/go.sum b/go.sum index 3ab37b9ef..b7a4121e9 100644 --- a/go.sum +++ b/go.sum @@ -36,8 +36,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dlclark/regexp2/v2 v2.2.2 h1:MYWvNYw8okuqNhwTYO587EZMiDruVa2vhV6fsGpfya0= -github.com/dlclark/regexp2/v2 v2.2.2/go.mod h1:avUrQvPaLz2DrFNHJF0taWAFFX2C1GMSSoeiqFjcBmU= +github.com/dlclark/regexp2/v2 v2.5.2 h1:HAsucWRhsqcDzl6Ua9aR8JwYOTzrZyPrF0/FNxJVAI0= +github.com/dlclark/regexp2/v2 v2.5.2/go.mod h1:avUrQvPaLz2DrFNHJF0taWAFFX2C1GMSSoeiqFjcBmU= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= @@ -96,8 +96,8 @@ github.com/grafana/k6-cloud-openapi-client-go v0.0.3-0.20260716125012-97c96146fa github.com/grafana/k6-cloud-openapi-client-go v0.0.3-0.20260716125012-97c96146fa7c/go.mod h1:RhZGBq6e90zSi0EME83c6S1qkOzD8pP0MNETqieWX0k= github.com/grafana/k6provider v0.5.0 h1:SwItWPOMQHfRytezQBKpeXLxjNmcyD/x9PTA28pEbwg= github.com/grafana/k6provider v0.5.0/go.mod h1:R9WKthnwk96E47m6w/mnC13hhBYTn5iMdP5caFt/t5k= -github.com/grafana/sobek v0.0.0-20260708062710-267a0e055bb4 h1:LJ2pEOxFbfUIhrkpROwZ6hLhuCn6e5GSX08v5GFwN/4= -github.com/grafana/sobek v0.0.0-20260708062710-267a0e055bb4/go.mod h1:BL/2XROA/Wtlb+zGEhkSdSZiMFIgw+D2ZdDfrbccyVE= +github.com/grafana/sobek v0.0.0-20260727154728-7781506a890f h1:YNPYRCa0yVIPtLYrzNzsfObrRZJQDupuGL3zW3SWn0M= +github.com/grafana/sobek v0.0.0-20260727154728-7781506a890f/go.mod h1:Sza3zAy+gfXCTtzbPuijuT5odA6N3lQxMTVpCP8sC/4= github.com/grafana/sobek-webapi-encoding v0.1.0 h1:2qf2pUiI6j33vl2etSE0Id4mfSQ4Jfa0VVfUuSccAkI= github.com/grafana/sobek-webapi-encoding v0.1.0/go.mod h1:IegnWm83cyZ8qTnfL6Rivmx7dpMVE+w3CblopwfL/go= github.com/grafana/xk6-dashboard-assets v0.1.2 h1:n2wqytPICn2ZYsKa9HE6GlvFXk+WjByMfT4eM+ms3gE= diff --git a/internal/js/tc39/breaking_test_errors-stripTypes=false.json b/internal/js/tc39/breaking_test_errors-stripTypes=false.json index 186f638c2..f0d8bf770 100644 --- a/internal/js/tc39/breaking_test_errors-stripTypes=false.json +++ b/internal/js/tc39/breaking_test_errors-stripTypes=false.json @@ -221,16 +221,6 @@ "test/built-ins/RegExp/unicode_restricted_incomplete_quantifier.js-strict:true": "test/built-ins/RegExp/unicode_restricted_incomplete_quantifier.js: Test262Error: RegExp(\"a{\", \"u\"): Expected a SyntaxError to be thrown but no exception was thrown at all ", "test/built-ins/RegExp/unicode_restricted_octal_escape.js-strict:true": "test/built-ins/RegExp/unicode_restricted_octal_escape.js: Test262Error: RegExp(\"\\1\", \"u\"): Expected a SyntaxError to be thrown but no exception was thrown at all ", "test/built-ins/RegExp/unicode_restricted_quantifiable_assertion.js-strict:true": "test/built-ins/RegExp/unicode_restricted_quantifiable_assertion.js: Test262Error: RegExp(\"(?=.)*\", \"u\"): Expected a SyntaxError to be thrown but no exception was thrown at all ", - "test/built-ins/TypedArray/prototype/slice/speciesctor-return-same-buffer-with-offset.js-strict:true": "test/built-ins/TypedArray/prototype/slice/speciesctor-return-same-buffer-with-offset.js: Test262Error: Actual [8.1254e-320, 40.0000000001169, 50, 60] and expected [20, 20, 20, 60] should have the same contents. (Testing with Float64Array and makePassthrough.) ", - "test/built-ins/TypedArray/prototype/with/value-throw-completion.js-strict:true": "test/built-ins/TypedArray/prototype/with/value-throw-completion.js: Test262Error: Positive too large index Expected a MyError but got a RangeError (Testing with Float64Array and makePassthrough.) ", - "test/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-canonical-invalid-index-prototype-chain-set.js-strict:true": "test/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-canonical-invalid-index-prototype-chain-set.js: Test262Error: 1 setter should be unreachable! (Testing with BigInt64Array and makePassthrough.) ", - "test/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-canonical-invalid-index-reflect-set.js-strict:true": "test/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-canonical-invalid-index-reflect-set.js: Test262Error: 1 setter should be unreachable! (Testing with BigInt64Array and makePassthrough.) ", - "test/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-valid-index-reflect-set.js-strict:true": "test/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-valid-index-reflect-set.js: Test262Error: Reflect.set should fail (receiver: another typed array of shorter length) (Testing with BigInt64Array and makePassthrough.) ", - "test/built-ins/TypedArrayConstructors/internals/Set/key-is-canonical-invalid-index-prototype-chain-set.js-strict:true": "test/built-ins/TypedArrayConstructors/internals/Set/key-is-canonical-invalid-index-prototype-chain-set.js: Test262Error: 1 setter should be unreachable! (Testing with Float64Array and makePassthrough.) ", - "test/built-ins/TypedArrayConstructors/internals/Set/key-is-canonical-invalid-index-reflect-set.js-strict:true": "test/built-ins/TypedArrayConstructors/internals/Set/key-is-canonical-invalid-index-reflect-set.js: Test262Error: 1 setter should be unreachable! (Testing with Float64Array and makePassthrough.) ", - "test/built-ins/TypedArrayConstructors/internals/Set/key-is-out-of-bounds-receiver-is-not-object.js-strict:true": "test/built-ins/TypedArrayConstructors/internals/Set/key-is-out-of-bounds-receiver-is-not-object.js: Test262Error: [[Set]] succeeeds ", - "test/built-ins/TypedArrayConstructors/internals/Set/key-is-out-of-bounds-receiver-is-proto.js-strict:true": "test/built-ins/TypedArrayConstructors/internals/Set/key-is-out-of-bounds-receiver-is-proto.js: Test262Error: valueOf is called exactly once Expected SameValue(«0», «1») to be true ", - "test/built-ins/TypedArrayConstructors/internals/Set/key-is-valid-index-reflect-set.js-strict:true": "test/built-ins/TypedArrayConstructors/internals/Set/key-is-valid-index-reflect-set.js: Test262Error: Reflect.set should fail (receiver: another typed array of shorter length) (Testing with Float64Array and makePassthrough.) ", "test/built-ins/WeakMap/prototype/getOrInsert/adds-object-element.js-strict:true": "test/built-ins/WeakMap/prototype/getOrInsert/adds-object-element.js: TypeError: Object has no member 'getOrInsert' ", "test/built-ins/WeakMap/prototype/getOrInsert/getOrInsert.js-strict:true": "test/built-ins/WeakMap/prototype/getOrInsert/getOrInsert.js: Test262Error: typeof WeakMap.prototype.getOrInsert is \"function\" Expected SameValue(«\"undefined\"», «\"function\"») to be true ", "test/built-ins/WeakMap/prototype/getOrInsert/length.js-strict:true": "test/built-ins/WeakMap/prototype/getOrInsert/length.js: TypeError: Cannot convert undefined or null to object ", @@ -256,14 +246,10 @@ "test/language/expressions/class/class-name-ident-await-module.js-strict:true": "test/language/expressions/class/class-name-ident-await-module.js: error is not an object (Test262: This statement should not be evaluated.)", "test/language/expressions/class/elements/private-getter-is-not-a-own-property.js-strict:true": "test/language/expressions/class/elements/private-getter-is-not-a-own-property.js: TypeError: Object has no member '__lookupGetter__' ", "test/language/expressions/class/elements/private-setter-is-not-a-own-property.js-strict:true": "test/language/expressions/class/elements/private-setter-is-not-a-own-property.js: TypeError: Object has no member '__lookupSetter__' ", - "test/language/expressions/greater-than-or-equal/S11.8.4_A4.12_T1.js-strict:true": "test/language/expressions/greater-than-or-equal/S11.8.4_A4.12_T1.js: Test262Error: #10: (\"\\u{10000}\" >= \"\\uFFFF\") === false ", - "test/language/expressions/greater-than/S11.8.2_A4.12_T1.js-strict:true": "test/language/expressions/greater-than/S11.8.2_A4.12_T1.js: Test262Error: #9: (\"\\uDC00\" > \"\\uD800\") === true ", "test/language/expressions/import.meta/import-meta-is-an-ordinary-object.js-strict:true": "test/language/expressions/import.meta/import-meta-is-an-ordinary-object.js: file:///TestTC39/test262/test/language/expressions/import.meta/import-meta-is-an-ordinary-object.js: Line 28:25 import not supported in script (and 19 more errors)", "test/language/expressions/import.meta/same-object-returned.js-strict:true": "test/language/expressions/import.meta/same-object-returned.js: file:///TestTC39/test262/test/language/expressions/import.meta/same-object-returned.js: Line 28:9 import not supported in script (and 3 more errors)", "test/language/expressions/import.meta/syntax/goal-module-nested-function.js-strict:true": "test/language/expressions/import.meta/syntax/goal-module-nested-function.js: file:///TestTC39/test262/test/language/expressions/import.meta/syntax/goal-module-nested-function.js: Line 16:3 import not supported in script (and 4 more errors)", "test/language/expressions/import.meta/syntax/goal-module.js-strict:true": "test/language/expressions/import.meta/syntax/goal-module.js: file:///TestTC39/test262/test/language/expressions/import.meta/syntax/goal-module.js: Line 15:1 import not supported in script (and 3 more errors)", - "test/language/expressions/less-than-or-equal/S11.8.3_A4.12_T1.js-strict:true": "test/language/expressions/less-than-or-equal/S11.8.3_A4.12_T1.js: Test262Error: #10: (\"\\u{10000}\" <= \"\\uFFFF\") === true ", - "test/language/expressions/less-than/S11.8.1_A4.12_T1.js-strict:true": "test/language/expressions/less-than/S11.8.1_A4.12_T1.js: Test262Error: #9: (\"\\uD800\" < \"\\uDC00\") === true ", "test/language/expressions/optional-chaining/iteration-statement-for-await-of.js-strict:true": "test/language/expressions/optional-chaining/iteration-statement-for-await-of.js: test/language/expressions/optional-chaining/iteration-statement-for-await-of.js: Line 32:7 Unexpected token await (and 9 more errors)", "test/language/expressions/optional-chaining/member-expression.js-strict:true": "test/language/expressions/optional-chaining/member-expression.js: SyntaxError: Async generators are not supported yet ", "test/language/identifiers/part-unicode-15.1.0-class-escaped.js-strict:true": "test/language/identifiers/part-unicode-15.1.0-class-escaped.js: test/language/identifiers/part-unicode-15.1.0-class-escaped.js: Line 20:22 Unexpected token ILLEGAL (and 1 more errors)", @@ -425,7 +411,6 @@ "test/language/statements/with/get-binding-value-call-with-proxy-env.js-strict:false": "test/language/statements/with/get-binding-value-call-with-proxy-env.js: Test262Error: Actual [has:Object, get:Symbol(Symbol.unscopables), get:Object] and expected [has:Object, get:Symbol(Symbol.unscopables), has:Object, get:Object] should have the same contents. ", "test/language/statements/with/get-binding-value-idref-with-proxy-env.js-strict:false": "test/language/statements/with/get-binding-value-idref-with-proxy-env.js: Test262Error: Actual [has:Object, get:Symbol(Symbol.unscopables), get:Object] and expected [has:Object, get:Symbol(Symbol.unscopables), has:Object, get:Object] should have the same contents. ", "test/language/statements/with/get-mutable-binding-binding-deleted-in-get-unscopables-strict-mode.js-strict:false": "test/language/statements/with/get-mutable-binding-binding-deleted-in-get-unscopables-strict-mode.js: Test262Error: Expected a ReferenceError to be thrown but no exception was thrown at all ", - "test/language/statements/with/set-mutable-binding-binding-deleted-with-typed-array-in-proto-chain.js-strict:false": "test/language/statements/with/set-mutable-binding-binding-deleted-with-typed-array-in-proto-chain.js: Test262Error: Expected SameValue(«[object Object]», «undefined») to be true ", "test/language/statements/with/set-mutable-binding-idref-compound-assign-with-proxy-env.js-strict:false": "test/language/statements/with/set-mutable-binding-idref-compound-assign-with-proxy-env.js: Test262Error: Actual [has:p, get:Symbol(Symbol.unscopables), get:p, set:p, getOwnPropertyDescriptor:p, defineProperty:p] and expected [has:p, get:Symbol(Symbol.unscopables), has:p, get:p, has:p, set:p, getOwnPropertyDescriptor:p, defineProperty:p] should have the same contents. ", "test/language/statements/with/set-mutable-binding-idref-with-proxy-env.js-strict:false": "test/language/statements/with/set-mutable-binding-idref-with-proxy-env.js: Test262Error: Actual [has:p, get:Symbol(Symbol.unscopables), set:p, getOwnPropertyDescriptor:p, defineProperty:p] and expected [has:p, get:Symbol(Symbol.unscopables), has:p, set:p, getOwnPropertyDescriptor:p, defineProperty:p] should have the same contents. " } diff --git a/internal/js/tc39/breaking_test_errors-stripTypes=true.json b/internal/js/tc39/breaking_test_errors-stripTypes=true.json index b2ae30af4..e9e133ec7 100644 --- a/internal/js/tc39/breaking_test_errors-stripTypes=true.json +++ b/internal/js/tc39/breaking_test_errors-stripTypes=true.json @@ -221,16 +221,6 @@ "test/built-ins/RegExp/unicode_restricted_incomplete_quantifier.js-strict:true": "test/built-ins/RegExp/unicode_restricted_incomplete_quantifier.js: Test262Error: RegExp(\"a{\", \"u\"): Expected a SyntaxError to be thrown but no exception was thrown at all ", "test/built-ins/RegExp/unicode_restricted_octal_escape.js-strict:true": "test/built-ins/RegExp/unicode_restricted_octal_escape.js: Test262Error: RegExp(\"\\1\", \"u\"): Expected a SyntaxError to be thrown but no exception was thrown at all ", "test/built-ins/RegExp/unicode_restricted_quantifiable_assertion.js-strict:true": "test/built-ins/RegExp/unicode_restricted_quantifiable_assertion.js: Test262Error: RegExp(\"(?=.)*\", \"u\"): Expected a SyntaxError to be thrown but no exception was thrown at all ", - "test/built-ins/TypedArray/prototype/slice/speciesctor-return-same-buffer-with-offset.js-strict:true": "test/built-ins/TypedArray/prototype/slice/speciesctor-return-same-buffer-with-offset.js: Test262Error: Actual [8.1254e-320, 40.0000000001169, 50, 60] and expected [20, 20, 20, 60] should have the same contents. (Testing with Float64Array and makePassthrough.) ", - "test/built-ins/TypedArray/prototype/with/value-throw-completion.js-strict:true": "test/built-ins/TypedArray/prototype/with/value-throw-completion.js: Test262Error: Positive too large index Expected a MyError but got a RangeError (Testing with Float64Array and makePassthrough.) ", - "test/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-canonical-invalid-index-prototype-chain-set.js-strict:true": "test/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-canonical-invalid-index-prototype-chain-set.js: Test262Error: 1 setter should be unreachable! (Testing with BigInt64Array and makePassthrough.) ", - "test/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-canonical-invalid-index-reflect-set.js-strict:true": "test/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-canonical-invalid-index-reflect-set.js: Test262Error: 1 setter should be unreachable! (Testing with BigInt64Array and makePassthrough.) ", - "test/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-valid-index-reflect-set.js-strict:true": "test/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-valid-index-reflect-set.js: Test262Error: Reflect.set should fail (receiver: another typed array of shorter length) (Testing with BigInt64Array and makePassthrough.) ", - "test/built-ins/TypedArrayConstructors/internals/Set/key-is-canonical-invalid-index-prototype-chain-set.js-strict:true": "test/built-ins/TypedArrayConstructors/internals/Set/key-is-canonical-invalid-index-prototype-chain-set.js: Test262Error: 1 setter should be unreachable! (Testing with Float64Array and makePassthrough.) ", - "test/built-ins/TypedArrayConstructors/internals/Set/key-is-canonical-invalid-index-reflect-set.js-strict:true": "test/built-ins/TypedArrayConstructors/internals/Set/key-is-canonical-invalid-index-reflect-set.js: Test262Error: 1 setter should be unreachable! (Testing with Float64Array and makePassthrough.) ", - "test/built-ins/TypedArrayConstructors/internals/Set/key-is-out-of-bounds-receiver-is-not-object.js-strict:true": "test/built-ins/TypedArrayConstructors/internals/Set/key-is-out-of-bounds-receiver-is-not-object.js: Test262Error: [[Set]] succeeeds ", - "test/built-ins/TypedArrayConstructors/internals/Set/key-is-out-of-bounds-receiver-is-proto.js-strict:true": "test/built-ins/TypedArrayConstructors/internals/Set/key-is-out-of-bounds-receiver-is-proto.js: Test262Error: valueOf is called exactly once Expected SameValue(«0», «1») to be true ", - "test/built-ins/TypedArrayConstructors/internals/Set/key-is-valid-index-reflect-set.js-strict:true": "test/built-ins/TypedArrayConstructors/internals/Set/key-is-valid-index-reflect-set.js: Test262Error: Reflect.set should fail (receiver: another typed array of shorter length) (Testing with Float64Array and makePassthrough.) ", "test/built-ins/WeakMap/prototype/getOrInsert/adds-object-element.js-strict:true": "test/built-ins/WeakMap/prototype/getOrInsert/adds-object-element.js: TypeError: Object has no member 'getOrInsert' ", "test/built-ins/WeakMap/prototype/getOrInsert/getOrInsert.js-strict:true": "test/built-ins/WeakMap/prototype/getOrInsert/getOrInsert.js: Test262Error: typeof WeakMap.prototype.getOrInsert is \"function\" Expected SameValue(«\"undefined\"», «\"function\"») to be true ", "test/built-ins/WeakMap/prototype/getOrInsert/length.js-strict:true": "test/built-ins/WeakMap/prototype/getOrInsert/length.js: TypeError: Cannot convert undefined or null to object ", @@ -256,14 +246,10 @@ "test/language/expressions/class/class-name-ident-await-module.js-strict:true": "test/language/expressions/class/class-name-ident-await-module.js: error is not an object (Test262: This statement should not be evaluated.)", "test/language/expressions/class/elements/private-getter-is-not-a-own-property.js-strict:true": "test/language/expressions/class/elements/private-getter-is-not-a-own-property.js: TypeError: Object has no member '__lookupGetter__' ", "test/language/expressions/class/elements/private-setter-is-not-a-own-property.js-strict:true": "test/language/expressions/class/elements/private-setter-is-not-a-own-property.js: TypeError: Object has no member '__lookupSetter__' ", - "test/language/expressions/greater-than-or-equal/S11.8.4_A4.12_T1.js-strict:true": "test/language/expressions/greater-than-or-equal/S11.8.4_A4.12_T1.js: Test262Error: #10: (\"\\u{10000}\" >= \"\\uFFFF\") === false ", - "test/language/expressions/greater-than/S11.8.2_A4.12_T1.js-strict:true": "test/language/expressions/greater-than/S11.8.2_A4.12_T1.js: Test262Error: #9: (\"\\uDC00\" > \"\\uD800\") === true ", "test/language/expressions/import.meta/import-meta-is-an-ordinary-object.js-strict:true": "test/language/expressions/import.meta/import-meta-is-an-ordinary-object.js: file:///TestTC39/test262/test/language/expressions/import.meta/import-meta-is-an-ordinary-object.js: Line 28:25 import not supported in script (and 19 more errors)", "test/language/expressions/import.meta/same-object-returned.js-strict:true": "test/language/expressions/import.meta/same-object-returned.js: file:///TestTC39/test262/test/language/expressions/import.meta/same-object-returned.js: Line 28:9 import not supported in script (and 3 more errors)", "test/language/expressions/import.meta/syntax/goal-module-nested-function.js-strict:true": "test/language/expressions/import.meta/syntax/goal-module-nested-function.js: file:///TestTC39/test262/test/language/expressions/import.meta/syntax/goal-module-nested-function.js: Line 16:3 import not supported in script (and 4 more errors)", "test/language/expressions/import.meta/syntax/goal-module.js-strict:true": "test/language/expressions/import.meta/syntax/goal-module.js: file:///TestTC39/test262/test/language/expressions/import.meta/syntax/goal-module.js: Line 15:1 import not supported in script (and 3 more errors)", - "test/language/expressions/less-than-or-equal/S11.8.3_A4.12_T1.js-strict:true": "test/language/expressions/less-than-or-equal/S11.8.3_A4.12_T1.js: Test262Error: #10: (\"\\u{10000}\" <= \"\\uFFFF\") === true ", - "test/language/expressions/less-than/S11.8.1_A4.12_T1.js-strict:true": "test/language/expressions/less-than/S11.8.1_A4.12_T1.js: Test262Error: #9: (\"\\uD800\" < \"\\uDC00\") === true ", "test/language/expressions/optional-chaining/iteration-statement-for-await-of.js-strict:true": "test/language/expressions/optional-chaining/iteration-statement-for-await-of.js: test/language/expressions/optional-chaining/iteration-statement-for-await-of.js: Line 32:7 Unexpected token await (and 9 more errors)", "test/language/expressions/optional-chaining/member-expression.js-strict:true": "test/language/expressions/optional-chaining/member-expression.js: SyntaxError: Async generators are not supported yet ", "test/language/identifiers/part-unicode-15.1.0-class-escaped.js-strict:true": "test/language/identifiers/part-unicode-15.1.0-class-escaped.js: test/language/identifiers/part-unicode-15.1.0-class-escaped.js: Line 20:22 Unexpected token ILLEGAL (and 1 more errors)", @@ -425,7 +411,6 @@ "test/language/statements/with/get-binding-value-call-with-proxy-env.js-strict:false": "test/language/statements/with/get-binding-value-call-with-proxy-env.js: Test262Error: Actual [has:Object, get:Symbol(Symbol.unscopables), get:Object] and expected [has:Object, get:Symbol(Symbol.unscopables), has:Object, get:Object] should have the same contents. ", "test/language/statements/with/get-binding-value-idref-with-proxy-env.js-strict:false": "test/language/statements/with/get-binding-value-idref-with-proxy-env.js: Test262Error: Actual [has:Object, get:Symbol(Symbol.unscopables), get:Object] and expected [has:Object, get:Symbol(Symbol.unscopables), has:Object, get:Object] should have the same contents. ", "test/language/statements/with/get-mutable-binding-binding-deleted-in-get-unscopables-strict-mode.js-strict:false": "test/language/statements/with/get-mutable-binding-binding-deleted-in-get-unscopables-strict-mode.js: Test262Error: Expected a ReferenceError to be thrown but no exception was thrown at all ", - "test/language/statements/with/set-mutable-binding-binding-deleted-with-typed-array-in-proto-chain.js-strict:false": "test/language/statements/with/set-mutable-binding-binding-deleted-with-typed-array-in-proto-chain.js: Test262Error: Expected SameValue(«[object Object]», «undefined») to be true ", "test/language/statements/with/set-mutable-binding-idref-compound-assign-with-proxy-env.js-strict:false": "test/language/statements/with/set-mutable-binding-idref-compound-assign-with-proxy-env.js: Test262Error: Actual [has:p, get:Symbol(Symbol.unscopables), get:p, set:p, getOwnPropertyDescriptor:p, defineProperty:p] and expected [has:p, get:Symbol(Symbol.unscopables), has:p, get:p, has:p, set:p, getOwnPropertyDescriptor:p, defineProperty:p] should have the same contents. ", "test/language/statements/with/set-mutable-binding-idref-with-proxy-env.js-strict:false": "test/language/statements/with/set-mutable-binding-idref-with-proxy-env.js: Test262Error: Actual [has:p, get:Symbol(Symbol.unscopables), set:p, getOwnPropertyDescriptor:p, defineProperty:p] and expected [has:p, get:Symbol(Symbol.unscopables), has:p, set:p, getOwnPropertyDescriptor:p, defineProperty:p] should have the same contents. " } diff --git a/vendor/github.com/dlclark/regexp2/v2/options.go b/vendor/github.com/dlclark/regexp2/v2/options.go index c0e49fff5..e54fa782b 100644 --- a/vendor/github.com/dlclark/regexp2/v2/options.go +++ b/vendor/github.com/dlclark/regexp2/v2/options.go @@ -5,6 +5,7 @@ var ( DefaultUnmarshalOptions = None // DefaultOptimizationOptions controls the default memory/performance trade-offs used by Compile. DefaultOptimizationOptions = OptimizationOptions{ + MaxBacktrackingStackSize: 100000, MaxCachedRuneBufferLength: 256 << 10, MaxCachedReplaceBufferLength: 256 << 10, MaxCachedReplacerDataEntries: 16, @@ -36,13 +37,17 @@ const ( Unicode RegexOptions = 0x0400 // "u" ) -// OptimizationOptions controls optional runtime caches and compile-time fast paths. +// OptimizationOptions controls runtime limits, optional caches, and compile-time fast paths. // +// For MaxBacktrackingStackSize, negative values allow unbounded growth. // For replacement data cache size fields, 0 disables persistent retention and // -1 means unbounded. For pooled buffer cache size fields, 0 disables pooling // and -1 allows all built-in size classes. // Defaults are intentionally bounded so Compile is safe for mixed-cardinality inputs. type OptimizationOptions struct { + // MaxBacktrackingStackSize limits the number of integer slots used by a match's backtracking stack. + // Negative values disable the limit. + MaxBacktrackingStackSize int // MaxCachedRuneBufferLength limits retained string-to-rune buffers in the shared size-classed pool. MaxCachedRuneBufferLength int // MaxCachedReplaceBufferLength limits retained replacement output buffers in the shared size-classed pool. @@ -100,6 +105,14 @@ func newCompileConfig(options []CompileOption) compileConfig { return c } +// OptionMaxBacktrackingStackSize limits the number of integer slots used by a match's backtracking stack. +// Negative values disable the limit. A match that exceeds the limit returns ErrBacktrackingStackLimit. +func OptionMaxBacktrackingStackSize(n int) CompileOption { + return compileOptionFunc(func(c *compileConfig) { + c.optimizations.MaxBacktrackingStackSize = n + }) +} + // OptionMaxCachedRuneBufferLength limits retained string-to-rune buffers in the shared size-classed pool. func OptionMaxCachedRuneBufferLength(n int) CompileOption { return compileOptionFunc(func(c *compileConfig) { diff --git a/vendor/github.com/dlclark/regexp2/v2/regexp.go b/vendor/github.com/dlclark/regexp2/v2/regexp.go index 0a5d140a3..c3f2adb32 100644 --- a/vendor/github.com/dlclark/regexp2/v2/regexp.go +++ b/vendor/github.com/dlclark/regexp2/v2/regexp.go @@ -25,6 +25,8 @@ import ( var ( // DefaultMatchTimeout used when running regexp matches -- "forever" DefaultMatchTimeout = time.Duration(math.MaxInt64) + // ErrBacktrackingStackLimit is returned when a match exceeds its configured backtracking stack size. + ErrBacktrackingStackLimit = errors.New("regexp2: maximum backtracking stack size exceeded") ) // Regexp is the representation of a compiled regular expression. @@ -59,7 +61,9 @@ type Regexp struct { // hook points to override runner functions findFirstChar func(r *Runner) bool execute func(r *Runner) error + executeQuick func(r *Runner) error stringPrefixFilter StringPrefixFilter + quickCode *syntax.Code // bool-only program with unobservable captures removed } // Compile parses a regular expression and returns, if successful, @@ -107,6 +111,7 @@ func compile(expr string, c compileConfig) (*Regexp, error) { capslist: tree.Caplist, capsize: code.Capsize, code: code, + quickCode: makeQuickCode(code), MatchTimeout: DefaultMatchTimeout, optimizations: c.optimizations, } @@ -115,6 +120,16 @@ func compile(expr string, c compileConfig) (*Regexp, error) { return re, nil } +func makeQuickCode(code *syntax.Code) *syntax.Code { + if code == nil || len(code.QuickCodes) == 0 { + return nil + } + quick := *code + quick.Codes = code.QuickCodes + quick.QuickCodes = nil + return &quick +} + // MustCompile is like Compile but panics if the expression cannot be parsed. // It simplifies safe initialization of global variables holding compiled regular // expressions. @@ -230,12 +245,12 @@ func (re *Regexp) FindStringMatch(s string) (*Match, error) { if runeStart < 0 { runeStart = 0 } - return re.run(false, runeStart, r, newStringMatchText(s, r)) + return re.run(false, runeStart, -1, r, newStringMatchText(s, r)) } // FindRunesMatch searches the input rune slice for a Regexp match func (re *Regexp) FindRunesMatch(r []rune) (*Match, error) { - return re.run(false, -1, r, newMatchText(r)) + return re.run(false, -1, -1, r, newMatchText(r)) } // FindStringMatchStartingAt searches the input string for a Regexp match starting at the startAt index @@ -254,12 +269,12 @@ func (re *Regexp) FindStringMatchStartingAt(s string, startAt int) (*Match, erro return nil, errors.New("startAt must align to the start of a valid rune in the input string") } - return re.run(false, startAt, r, newStringMatchText(s, r)) + return re.run(false, startAt, -1, r, newStringMatchText(s, r)) } // FindRunesMatchStartingAt searches the input rune slice for a Regexp match starting at the startAt index func (re *Regexp) FindRunesMatchStartingAt(r []rune, startAt int) (*Match, error) { - return re.run(false, startAt, r, newMatchText(r)) + return re.run(false, startAt, -1, r, newMatchText(r)) } // FindAllStringIndex returns a slice of byte index pairs identifying all @@ -299,6 +314,9 @@ func (re *Regexp) FindAllStringIndex(s string, n int) ([][]int, error) { } byteOffsets := newStringByteMapper(s) + if re.quickCode != nil { + runner.code = re.quickCode + } return re.findAllRunesIndex(runner, input, runeStart, n, func(runeIndex, runeLength int) (int, int) { if byteOffsets == nil { return runeIndex, runeIndex + runeLength @@ -321,6 +339,9 @@ func (re *Regexp) FindAllRunesIndex(r []rune, n int) ([][]int, error) { if re.RightToLeft() { startAt = len(r) } + if re.quickCode != nil { + runner.code = re.quickCode + } return re.findAllRunesIndex(runner, r, startAt, n, func(runeIndex, runeLength int) (int, int) { return runeIndex, runeIndex + runeLength }) @@ -335,8 +356,9 @@ func (re *Regexp) findAllRunesIndex(runner *Runner, input []rune, startAt, n int } prevEnd := -1 + previousMatchLength := -1 for n != 0 { - m, err := runner.scan(input, nil, startAt, true, re.MatchTimeout) + m, err := runner.scan(input, nil, startAt, previousMatchLength, true, re.MatchTimeout) if err != nil { return nil, err } @@ -355,23 +377,7 @@ func (re *Regexp) findAllRunesIndex(runner *Runner, input []rune, startAt, n int } startAt = m.textpos - if m.RuneLength == 0 { - if re.RightToLeft() { - if m.textpos == 0 { - break - } - if startAt == m.textstart { - startAt-- - } - } else { - if m.textpos == len(input) { - break - } - if startAt == m.textstart { - startAt++ - } - } - } + previousMatchLength = m.RuneLength } return out, nil } @@ -420,29 +426,7 @@ func (re *Regexp) FindNextMatch(m *Match) (*Match, error) { return nil, nil } - // If previous match was empty, advance by one before matching to prevent - // infinite loop - startAt := m.textpos - if m.RuneLength == 0 { - if re.RightToLeft() { - if m.textpos == 0 { - return nil, nil - } - if startAt == m.textstart { - startAt-- - } - } else { - if m.textpos == len(m.text.runes) { - return nil, nil - } - - if startAt == m.textstart { - startAt++ - } - - } - } - return re.run(false, startAt, m.text.runes, m.text) + return re.run(false, m.textpos, m.RuneLength, m.text.runes, m.text) } // MatchString return true if the string matches the regex @@ -486,8 +470,11 @@ func (re *Regexp) matchStringAt(s string, startAt int) (bool, error) { pooledRuneBuffers.put(pooledInput) } }() + if re.quickCode != nil { + runner.code = re.quickCode + } - m, err := runner.scan(input, nil, runeStart, true, re.MatchTimeout) + m, err := runner.scan(input, nil, runeStart, -1, true, re.MatchTimeout) if err != nil { return false, err } @@ -525,7 +512,7 @@ func getRunes(s string) []rune { // MatchRunes return true if the runes matches the regex // error will be set if a timeout occurs func (re *Regexp) MatchRunes(r []rune) (bool, error) { - m, err := re.run(true, -1, r, nil) + m, err := re.run(true, -1, -1, r, nil) if err != nil { return false, err } diff --git a/vendor/github.com/dlclark/regexp2/v2/regexp_codegen.go b/vendor/github.com/dlclark/regexp2/v2/regexp_codegen.go index 41c1aef35..cfef08781 100644 --- a/vendor/github.com/dlclark/regexp2/v2/regexp_codegen.go +++ b/vendor/github.com/dlclark/regexp2/v2/regexp_codegen.go @@ -11,13 +11,15 @@ type RuntimeEngineData struct { CapSize int // size of the capture array FindFirstChar func(*Runner) bool // generated candidate search Execute func(*Runner) error - StringPrefixFilter StringPrefixFilter // optional pre-decode candidate search for string input + ExecuteQuick func(*Runner) error // optional bool-only execution with unobservable captures removed + StringPrefixFilter StringPrefixFilter // optional pre-decode candidate search for string input } type cacheKey struct { - pattern string - opt RegexOptions - maintainCaptureOrder bool + pattern string + opt RegexOptions + maintainCaptureOrder bool + maxBacktrackingStackSize int } func RegisterEngine(pattern string, engine RuntimeEngineData, options ...CompileOption) { @@ -40,6 +42,7 @@ func newEngineRegexp(pattern string, c compileConfig, engine RuntimeEngineData) optimizations: c.optimizations, findFirstChar: engine.FindFirstChar, execute: engine.Execute, + executeQuick: engine.ExecuteQuick, stringPrefixFilter: engine.StringPrefixFilter, } re.initCaches() @@ -58,9 +61,10 @@ func getEngineRegexp(pattern string, c compileConfig) *Regexp { func cacheKeyFromConfig(pattern string, c compileConfig) cacheKey { return cacheKey{ - pattern: pattern, - opt: c.regexOptions, - maintainCaptureOrder: c.maintainCaptureOrder, + pattern: pattern, + opt: c.regexOptions, + maintainCaptureOrder: c.maintainCaptureOrder, + maxBacktrackingStackSize: c.optimizations.MaxBacktrackingStackSize, } } diff --git a/vendor/github.com/dlclark/regexp2/v2/replace.go b/vendor/github.com/dlclark/regexp2/v2/replace.go index 240b40f4a..9b965caf4 100644 --- a/vendor/github.com/dlclark/regexp2/v2/replace.go +++ b/vendor/github.com/dlclark/regexp2/v2/replace.go @@ -165,7 +165,7 @@ func replaceRunnerLTR(regex *Regexp, data *syntax.ReplacerData, input string, st runeStart = 0 } - m, err := runner.scan(text, textInfo, runeStart, true, regex.MatchTimeout) + m, err := runner.scan(text, textInfo, runeStart, -1, true, regex.MatchTimeout) if err != nil { return "", err } @@ -195,15 +195,7 @@ func replaceRunnerLTR(regex *Regexp, data *syntax.ReplacerData, input string, st break } - scanStart := m.textpos - if m.RuneLength == 0 { - if scanStart >= len(text) { - break - } - scanStart++ - } - - m, err = runner.scan(text, textInfo, scanStart, true, regex.MatchTimeout) + m, err = runner.scan(text, textInfo, m.textpos, m.RuneLength, true, regex.MatchTimeout) if err != nil { return "", err } @@ -236,7 +228,7 @@ func replaceRunnerRTL(regex *Regexp, data *syntax.ReplacerData, input string, st runeStart = len(text) } - m, err := runner.scan(text, textInfo, runeStart, true, regex.MatchTimeout) + m, err := runner.scan(text, textInfo, runeStart, -1, true, regex.MatchTimeout) if err != nil { return "", err } @@ -268,15 +260,7 @@ func replaceRunnerRTL(regex *Regexp, data *syntax.ReplacerData, input string, st break } - scanStart := m.textpos - if m.RuneLength == 0 { - if scanStart <= 0 { - break - } - scanStart-- - } - - m, err = runner.scan(text, textInfo, scanStart, true, regex.MatchTimeout) + m, err = runner.scan(text, textInfo, m.textpos, m.RuneLength, true, regex.MatchTimeout) if err != nil { return "", err } diff --git a/vendor/github.com/dlclark/regexp2/v2/runner.go b/vendor/github.com/dlclark/regexp2/v2/runner.go index ce09df07d..b70980fc1 100644 --- a/vendor/github.com/dlclark/regexp2/v2/runner.go +++ b/vendor/github.com/dlclark/regexp2/v2/runner.go @@ -74,8 +74,10 @@ type Runner struct { // // quick is usually false, but can be true to not return matches, just put it in caches. // textstart is -1 to start at the "beginning" (depending on Right-To-Left), otherwise an index in input. +// previousMatchLength is -1 for an initial scan. A zero value advances the current scan position while +// preserving textstart for anchors such as \G. // textInfo is nil for quick scans that do not need returned capture text metadata. -func (re *Regexp) run(quick bool, textstart int, input []rune, textInfo *matchText) (*Match, error) { +func (re *Regexp) run(quick bool, textstart, previousMatchLength int, input []rune, textInfo *matchText) (*Match, error) { // get a cached runner runner := re.getRunner() @@ -88,8 +90,11 @@ func (re *Regexp) run(quick bool, textstart int, input []rune, textInfo *matchTe textstart = 0 } } + if quick && textInfo == nil && re.quickCode != nil { + runner.code = re.quickCode + } - return runner.scan(input, textInfo, textstart, quick, re.MatchTimeout) + return runner.scan(input, textInfo, textstart, previousMatchLength, quick, re.MatchTimeout) } // Scans the string to find the first match. Uses the Match object @@ -108,13 +113,16 @@ func (re *Regexp) run(quick bool, textstart int, input []rune, textInfo *matchTe // used as a boolean result and capture text is intentionally unavailable. If // we collapsed down to just textInfo it would "escape" and hit the GC for fast // scans without captures. -func (r *Runner) scan(rt []rune, textInfo *matchText, textstart int, quick bool, timeout time.Duration) (*Match, error) { +func (r *Runner) scan(rt []rune, textInfo *matchText, textstart, previousMatchLength int, quick bool, timeout time.Duration) (*Match, error) { r.timeout = timeout r.ignoreTimeout = (time.Duration(math.MaxInt64) == timeout) r.debug = r.re.Debug() r.Runtextstart = textstart r.Runtext = rt r.Runtextend = len(rt) + // Some internal callers use quick match tidying while still consuming + // capture data (notably replacement). Capture elision is only safe when no + // match text metadata was requested. stoppos := r.Runtextend bump := 1 @@ -130,6 +138,9 @@ func (r *Runner) scan(rt []rune, textInfo *matchText, textstart int, quick bool, // setup our scanner functions findFirstChar := r.re.findFirstChar execute := r.re.execute + if quick && textInfo == nil && r.re.executeQuick != nil { + execute = r.re.executeQuick + } if findFirstChar == nil { findFirstChar = findFirstCharDefault } @@ -144,6 +155,16 @@ func (r *Runner) scan(rt []rune, textInfo *matchText, textstart int, quick bool, r.initMatch(textInfo) + // An empty previous match must not be returned again. Keep Runtextstart at + // the previous match position for \G, but move the candidate scan position. + if previousMatchLength == 0 { + if r.Runtextpos == stoppos { + r.tidyMatch(true) + return nil, nil + } + r.Runtextpos += bump + } + r.startTimeoutWatch() for { if minRequiredLength > 0 { @@ -208,7 +229,9 @@ func (r *Runner) scan(rt []rune, textInfo *matchText, textstart int, quick bool, func executeDefault(r *Runner) error { - r.goTo(0) + if err := r.goTo(0); err != nil { + return err + } for { @@ -230,7 +253,9 @@ func executeDefault(r *Runner) error { //noop case syntax.Goto: - r.goTo(r.operand(0)) + if err := r.goTo(r.operand(0)); err != nil { + return err + } continue case syntax.Testref: @@ -248,7 +273,9 @@ func executeDefault(r *Runner) error { case syntax.Lazybranch | syntax.Back: r.trackPop() r.textto(r.trackPeek()) - r.goTo(r.operand(0)) + if err := r.goTo(r.operand(0)); err != nil { + return err + } continue case syntax.Setmark: @@ -307,9 +334,11 @@ func executeDefault(r *Runner) error { matched := r.textPos() - r.stackPeek() if matched != 0 { // Nonempty match -> loop now - r.trackPush2(r.stackPeek(), r.textPos()) // Save old mark, textpos - r.stackPush(r.textPos()) // Make new mark - r.goTo(r.operand(0)) // Loop + r.trackPush2(r.stackPeek(), r.textPos()) // Save old mark, textpos + r.stackPush(r.textPos()) // Make new mark + if err := r.goTo(r.operand(0)); err != nil { // Loop + return err + } } else { // Empty match -> straight now r.trackPushNeg1(r.stackPeek()) // Save old mark r.advance(1) // Straight @@ -364,10 +393,12 @@ func executeDefault(r *Runner) error { r.trackPopN(2) pos := r.trackPeekN(1) - r.trackPushNeg2(r.trackPeek(), 1) // Save old mark, note that we pushed a new mark - r.stackPush(pos) // Make new mark - r.textto(pos) // Recall position - r.goTo(r.operand(0)) // Loop + r.trackPushNeg2(r.trackPeek(), 1) // Save old mark, note that we pushed a new mark + r.stackPush(pos) // Make new mark + r.textto(pos) // Recall position + if err := r.goTo(r.operand(0)); err != nil { // Loop + return err + } continue case syntax.Lazybranchmark | syntax.Back2: @@ -413,9 +444,11 @@ func executeDefault(r *Runner) error { r.trackPushNeg2(mark, count) // Save old mark, count r.advance(2) // Straight } else { // Nonempty match -> count+loop now - r.trackPush1(mark) // remember mark - r.stackPush2(r.textPos(), count+1) // Make new mark, incr count - r.goTo(r.operand(0)) // Loop + r.trackPush1(mark) // remember mark + r.stackPush2(r.textPos(), count+1) // Make new mark, incr count + if err := r.goTo(r.operand(0)); err != nil { // Loop + return err + } } continue @@ -452,9 +485,11 @@ func executeDefault(r *Runner) error { count := r.stackPeekN(1) if count < 0 { // Negative count -> loop now - r.trackPushNeg1(mark) // Save old mark - r.stackPush2(r.textPos(), count+1) // Make new mark, incr count - r.goTo(r.operand(0)) // Loop + r.trackPushNeg1(mark) // Save old mark + r.stackPush2(r.textPos(), count+1) // Make new mark, incr count + if err := r.goTo(r.operand(0)); err != nil { // Loop + return err + } } else { // Nonneg count -> straight now r.trackPush3(mark, count, r.textPos()) // Save mark, count, position r.advance(2) // Straight @@ -472,10 +507,12 @@ func executeDefault(r *Runner) error { textpos := r.trackPeekN(2) if r.trackPeekN(1) < r.operand(1) && textpos != mark { // Under limit and not empty match -> loop - r.textto(textpos) // Recall position - r.stackPush2(textpos, r.trackPeekN(1)+1) // Make new mark, incr count - r.trackPushNeg1(mark) // Save old mark - r.goTo(r.operand(0)) // Loop + r.textto(textpos) // Recall position + r.stackPush2(textpos, r.trackPeekN(1)+1) // Make new mark, incr count + r.trackPushNeg1(mark) // Save old mark + if err := r.goTo(r.operand(0)); err != nil { // Loop + return err + } continue } else { // Max loops or empty match -> backtrack r.stackPush2(r.trackPeek(), r.trackPeekN(1)) // Recall old mark, count @@ -935,18 +972,21 @@ func executeDefault(r *Runner) error { ; // "break Backward" comes here: - r.backtrack() + if err := r.backtrack(); err != nil { + return err + } } } // increase the size of stack and track storage -func (r *Runner) ensureStorage() { +func (r *Runner) ensureStorage() error { if r.Runstackpos < r.runtrackcount*4 { doubleIntSlice(&r.runstack, &r.Runstackpos) } - if r.Runtrackpos < r.runtrackcount*4 { - doubleIntSlice(&r.runtrack, &r.Runtrackpos) + if r.Runtrackpos < r.runtrackcount*4 && !r.growTrack() { + return ErrBacktrackingStackLimit } + return nil } func (r *Runner) ensureStack(plus int) { @@ -990,14 +1030,17 @@ func (r *Runner) advance(i int) { r.setOperator(r.code.Codes[r.codepos]) } -func (r *Runner) goTo(newpos int) { +func (r *Runner) goTo(newpos int) error { // when branching backward or in place, ensure storage if newpos <= r.codepos { - r.ensureStorage() + if err := r.ensureStorage(); err != nil { + return err + } } r.setOperator(r.code.Codes[newpos]) r.codepos = newpos + return nil } func (r *Runner) textto(newpos int) { @@ -1021,6 +1064,26 @@ func (r *Runner) trackpos() int { return len(r.runtrack) - r.Runtrackpos } +func (r *Runner) growTrack() bool { + oldLen := len(r.runtrack) + newLen := oldLen * 2 + if newLen == 0 { + newLen = 1 + } + if limit := r.re.optimizations.MaxBacktrackingStackSize; limit >= 0 && newLen > limit { + newLen = limit + } + if newLen <= oldLen { + return false + } + + newTrack := make([]int, newLen) + copy(newTrack[newLen-oldLen:], r.runtrack) + r.Runtrackpos += newLen - oldLen + r.runtrack = newTrack + return true +} + func (r *Runner) trackPush() { r.Runtrackpos-- r.runtrack[r.Runtrackpos] = r.codepos @@ -1069,7 +1132,7 @@ func (r *Runner) trackPushNeg2(I1, I2 int) { r.runtrack[r.Runtrackpos] = -r.codepos } -func (r *Runner) backtrack() { +func (r *Runner) backtrack() error { newpos := r.runtrack[r.Runtrackpos] r.Runtrackpos++ @@ -1090,10 +1153,13 @@ func (r *Runner) backtrack() { // When branching backward, ensure storage if newpos < r.codepos { - r.ensureStorage() + if err := r.ensureStorage(); err != nil { + return err + } } r.codepos = newpos + return nil } func (r *Runner) setOperator(op int) { @@ -1397,7 +1463,8 @@ func shouldUseFindFirstCharOptimized(r *Runner) bool { return false } - switch r.code.FindOptimizations.FindMode { + opts := r.code.FindOptimizations + switch opts.FindMode { case syntax.TrailingAnchor_FixedLength_LeftToRight_End, syntax.LeadingString_OrdinalIgnoreCase_LeftToRight, syntax.LeadingStrings_LeftToRight, @@ -1408,6 +1475,13 @@ func shouldUseFindFirstCharOptimized(r *Runner) bool { syntax.LiteralAfterLoop_LeftToRight, syntax.RequiredLandmarkChain_LeftToRight: return true + case syntax.LeadingSet_LeftToRight: + // General Unicode sets already have a direct fallback loop below. + // Large enumerated sets are also faster through the set's ASCII bitmap + // than through the linear IndexOfAny helper. + return len(opts.FixedDistanceSets) > 0 && + ((len(opts.FixedDistanceSets[0].Chars) > 0 && len(opts.FixedDistanceSets[0].Chars) <= 5) || + opts.FixedDistanceSets[0].Range != nil) default: return false } @@ -1429,10 +1503,10 @@ func findFirstCharOptimized(r *Runner) (handled bool, found bool) { case syntax.LeadingString_OrdinalIgnoreCase_LeftToRight: return true, findLeadingStringLeftToRight(r, []rune(opts.LeadingPrefix), true) case syntax.LeadingStrings_LeftToRight: - return true, findLeadingStringsLeftToRight(r, opts.LeadingPrefixesRunes, false) + return true, findLeadingStringsLeftToRight(r, opts.LeadingPrefixesRunes, opts.LeadingPrefixFirstRunes, false) case syntax.LeadingStrings_OrdinalIgnoreCase_LeftToRight: - return true, findLeadingStringsLeftToRight(r, opts.LeadingPrefixesRunes, true) - case syntax.FixedDistanceSets_LeftToRight: + return true, findLeadingStringsLeftToRight(r, opts.LeadingPrefixesRunes, opts.LeadingPrefixFirstRunes, true) + case syntax.LeadingSet_LeftToRight, syntax.FixedDistanceSets_LeftToRight: return true, findFixedDistanceSetsLeftToRight(r, opts.FixedDistanceSets) case syntax.FixedDistanceChar_LeftToRight: return true, findFixedDistanceCharLeftToRight(r, opts.FixedDistanceLiteral.C, opts.FixedDistanceLiteral.Distance) @@ -1487,29 +1561,69 @@ func findLeadingStringLeftToRight(r *Runner, prefix []rune, ignoreCase bool) boo return true } -func findLeadingStringsLeftToRight(r *Runner, prefixes [][]rune, ignoreCase bool) bool { +func findLeadingStringsLeftToRight(r *Runner, prefixes [][]rune, firstRunes []rune, ignoreCase bool) bool { if len(prefixes) == 0 { return false } - for start := r.Runtextpos; start <= latestPossibleStart(r); start++ { - for _, prefix := range prefixes { - if ignoreCase { - if helpers.StartsWithIgnoreCase(r.Runtext[start:], prefix) { + // Unicode ordinal-ignore-case matching has more possible first-rune folds + // than a small precomputed set can safely represent. Keep its conservative + // position-by-position scan; the common case-sensitive path skips directly + // between possible first runes. + if ignoreCase || len(firstRunes) == 0 { + for start := r.Runtextpos; start <= latestPossibleStart(r); start++ { + for _, prefix := range prefixes { + if ignoreCase { + if helpers.StartsWithIgnoreCase(r.Runtext[start:], prefix) { + r.Runtextpos = start + return true + } + } else if helpers.StartsWith(r.Runtext[start:], prefix) { r.Runtextpos = start return true } - } else if helpers.StartsWith(r.Runtext[start:], prefix) { + } + } + r.Runtextpos = r.Runtextend + return false + } + + latest := min(latestPossibleStart(r), r.Runtextend-1) + for searchAt := r.Runtextpos; searchAt <= latest; { + offset := indexOfAnyRunes(r.Runtext[searchAt:latest+1], firstRunes) + if offset < 0 { + break + } + start := searchAt + offset + first := r.Runtext[start] + for _, prefix := range prefixes { + if len(prefix) > 0 && prefix[0] == first && helpers.StartsWith(r.Runtext[start:], prefix) { r.Runtextpos = start return true } } + searchAt = start + 1 } r.Runtextpos = r.Runtextend return false } +func indexOfAnyRunes(input, find []rune) int { + switch len(find) { + case 0: + return -1 + case 1: + return helpers.IndexOfAny1(input, find[0]) + case 2: + return helpers.IndexOfAny2(input, find[0], find[1]) + case 3: + return helpers.IndexOfAny3(input, find[0], find[1], find[2]) + default: + return helpers.IndexOfAny(input, find) + } +} + func findFixedDistanceCharLeftToRight(r *Runner, ch rune, distance int) bool { searchStart := r.Runtextpos + distance for searchStart < r.Runtextend { @@ -1850,6 +1964,9 @@ func (r *Runner) initMatch(textInfo *matchText) { if tracksize < 64 { tracksize = 64 } + if limit := r.re.optimizations.MaxBacktrackingStackSize; limit >= 0 && tracksize > limit { + tracksize = limit + } if stacksize < 32 { stacksize = 32 } @@ -2097,6 +2214,7 @@ func (re *Regexp) getRunner() *Runner { // putRunner returns a runner to the re's pool cache. func (re *Regexp) putRunner(r *Runner) { r.Runtext = nil + r.code = re.code if r.runmatch != nil { r.runmatch.text = nil } @@ -2128,6 +2246,12 @@ func (r *Runner) StackPop() int { return val } +// StackDepth returns the number of integer slots currently used by the +// generated engine's backtracking stack. +func (r *Runner) StackDepth() int { + return len(r.runstack) - r.Runstackpos +} + func (r *Runner) StackPush(val int) { // check if we need to size up stack r.ensureStack(1) diff --git a/vendor/github.com/dlclark/regexp2/v2/stringprefixfilter.go b/vendor/github.com/dlclark/regexp2/v2/stringprefixfilter.go index fe9cb6ad7..080b8c290 100644 --- a/vendor/github.com/dlclark/regexp2/v2/stringprefixfilter.go +++ b/vendor/github.com/dlclark/regexp2/v2/stringprefixfilter.go @@ -39,6 +39,15 @@ func newStringPrefixFilter(code *syntax.Code) StringPrefixFilter { return stringIndexPrefixesFilter(opts.LeadingPrefixes, false, minRequiredLength) case syntax.LeadingStrings_OrdinalIgnoreCase_LeftToRight: return stringIndexPrefixesFilter(opts.LeadingPrefixes, true, minRequiredLength) + case syntax.LeadingSet_LeftToRight: + if len(opts.FixedDistanceSets) == 0 { + return nil + } + set := opts.FixedDistanceSets[0] + if set.Range == nil && (len(set.Chars) == 0 || len(set.Chars) > 5) { + return nil + } + return stringFixedDistanceSetFilter(set, minRequiredLength) case syntax.FixedDistanceChar_LeftToRight: return stringFixedDistanceCharFilter(opts.FixedDistanceLiteral.C, opts.FixedDistanceLiteral.Distance, minRequiredLength) case syntax.FixedDistanceString_LeftToRight: @@ -50,6 +59,87 @@ func newStringPrefixFilter(code *syntax.Code) StringPrefixFilter { } } +type asciiSetStringScanner struct { + chars string + first byte + last byte + useRange bool + distance int +} + +func newASCIISetStringScanner(set syntax.FixedDistanceSet) (asciiSetStringScanner, bool) { + if set.Negated || set.Distance < 0 { + return asciiSetStringScanner{}, false + } + if set.Range != nil { + if set.Range.First < 0 || set.Range.Last > utf8.RuneSelf-1 { + return asciiSetStringScanner{}, false + } + return asciiSetStringScanner{ + first: byte(set.Range.First), + last: byte(set.Range.Last), + useRange: true, + distance: set.Distance, + }, true + } + if len(set.Chars) == 0 { + return asciiSetStringScanner{}, false + } + chars := make([]byte, len(set.Chars)) + for i, ch := range set.Chars { + if ch < 0 || ch > utf8.RuneSelf-1 { + return asciiSetStringScanner{}, false + } + chars[i] = byte(ch) + } + return asciiSetStringScanner{chars: string(chars), distance: set.Distance}, true +} + +func stringFixedDistanceSetFilter(set syntax.FixedDistanceSet, minRequiredLength int) StringPrefixFilter { + scanner, ok := newASCIISetStringScanner(set) + if !ok { + return nil + } + + return func(input string, startAt int) (candidateByteIndex int, ok bool) { + if !hasMinRequiredBytes(input, startAt, minRequiredLength) { + return 0, false + } + + for searchAt := startAt; searchAt < len(input); { + offset := scanner.index(input[searchAt:]) + if offset < 0 { + return 0, false + } + setByteIndex := searchAt + offset + candidateByteIndex, valid := stringFixedDistanceCandidateStart(input, startAt, setByteIndex, scanner.distance) + if valid && hasMinRequiredBytes(input, candidateByteIndex, minRequiredLength) { + return candidateByteIndex, true + } + if valid { + return 0, false + } + searchAt = setByteIndex + 1 + } + return 0, false + } +} + +func (s asciiSetStringScanner) index(input string) int { + if !s.useRange { + if len(s.chars) == 1 { + return strings.IndexByte(input, s.chars[0]) + } + return strings.IndexAny(input, s.chars) + } + for i := 0; i < len(input); i++ { + if input[i] >= s.first && input[i] <= s.last { + return i + } + } + return -1 +} + func stringIndexPrefixFilter(prefix string, ignoreCase bool, minRequiredLength int) StringPrefixFilter { if prefix == "" { return nil diff --git a/vendor/github.com/dlclark/regexp2/v2/syntax/code.go b/vendor/github.com/dlclark/regexp2/v2/syntax/code.go index 1df4e45a9..405cd6c22 100644 --- a/vendor/github.com/dlclark/regexp2/v2/syntax/code.go +++ b/vendor/github.com/dlclark/regexp2/v2/syntax/code.go @@ -113,6 +113,40 @@ type Code struct { Anchors AnchorLoc // the set of zero-length start anchors (RegexFCD.Bol, etc) RightToLeft bool // true if right to left FindOptimizations *FindOptimizations // analyzed candidate search strategy + QuickCodes []int // bool-only code with unobservable captures removed + CaptureSlotInUse []bool // capture slots observable by the pattern itself during quick matches +} + +// captureSlotsInUse returns the capture slots whose values can affect matching. +// Group 0 is always retained as the success marker. Ordinary captures that are +// never referenced by the pattern may be omitted by bool-only matching APIs. +func captureSlotsInUse(codes []int, capsize int) []bool { + inUse := make([]bool, capsize) + if capsize > 0 { + inUse[0] = true + } + for pos := 0; pos < len(codes); { + op := InstOp(codes[pos]) & Mask + switch op { + case Ref, Testref: + capnum := codes[pos+1] + if capnum >= 0 && capnum < len(inUse) { + inUse[capnum] = true + } + case Capturemark: + // Balancing groups both observe and mutate capture state. Keep both + // sides live even if no later backreference refers to them. + if codes[pos+2] != -1 { + for _, capnum := range codes[pos+1 : pos+3] { + if capnum >= 0 && capnum < len(inUse) { + inUse[capnum] = true + } + } + } + } + pos += opcodeSize(op) + } + return inUse } // PrepareCharSetASCIIBitmaps builds bounded ASCII lookup tables for compiled diff --git a/vendor/github.com/dlclark/regexp2/v2/syntax/optimizations.go b/vendor/github.com/dlclark/regexp2/v2/syntax/optimizations.go index 0186497a0..8b726891e 100644 --- a/vendor/github.com/dlclark/regexp2/v2/syntax/optimizations.go +++ b/vendor/github.com/dlclark/regexp2/v2/syntax/optimizations.go @@ -11,20 +11,21 @@ type FindOptimizations struct { rightToLeft bool asciiLookups [][]uint - FindMode FindNextStartingPositionMode - LeadingAnchor NodeType - TrailingAnchor NodeType - MinRequiredLength int - MaxPossibleLength int - LeadingPrefix string - LeadingPrefixes []string - LeadingPrefixesRunes [][]rune + FindMode FindNextStartingPositionMode + LeadingAnchor NodeType + TrailingAnchor NodeType + MinRequiredLength int + MaxPossibleLength int + LeadingPrefix string + LeadingPrefixes []string + LeadingPrefixesRunes [][]rune //LeadingStrings *helpers.StringSearchValues FixedDistanceLiteral FixedDistanceLiteral FixedDistanceSets []FixedDistanceSet LiteralAfterLoop *LiteralAfterLoop LandmarkChain *RequiredLandmarkChain + LeadingPrefixFirstRunes []rune } type LiteralAfterLoop struct { @@ -468,6 +469,7 @@ func newFindOptimizationsForNode(root *RegexNode, opt ParseOptions, isLeadingPar if len(ciPrefixes) > 1 { f.LeadingPrefixes = ciPrefixes f.LeadingPrefixesRunes = toRunePrefixes(ciPrefixes) + f.LeadingPrefixFirstRunes = leadingPrefixFirstRunes(f.LeadingPrefixesRunes) f.FindMode = LeadingStrings_OrdinalIgnoreCase_LeftToRight /*SYSTEM_TEXT_REGULAREXPRESSIONS if usesRfoTryFind { @@ -523,6 +525,7 @@ func newFindOptimizationsForNode(root *RegexNode, opt ParseOptions, isLeadingPar if len(caseSensitivePrefixes) > 1 { f.LeadingPrefixes = caseSensitivePrefixes f.LeadingPrefixesRunes = toRunePrefixes(caseSensitivePrefixes) + f.LeadingPrefixFirstRunes = leadingPrefixFirstRunes(f.LeadingPrefixesRunes) f.FindMode = LeadingStrings_LeftToRight return f } @@ -587,6 +590,16 @@ func toRunePrefixes(prefixes []string) [][]rune { return runes } +func leadingPrefixFirstRunes(prefixes [][]rune) []rune { + first := make([]rune, 0, len(prefixes)) + for _, prefix := range prefixes { + if len(prefix) > 0 && !slices.Contains(first, prefix[0]) { + first = append(first, prefix[0]) + } + } + return first +} + func getFindMode(rtl bool, t NodeType) FindNextStartingPositionMode { if rtl { switch t { diff --git a/vendor/github.com/dlclark/regexp2/v2/syntax/prefixanalyzer.go b/vendor/github.com/dlclark/regexp2/v2/syntax/prefixanalyzer.go index 0490585bd..ac030de14 100644 --- a/vendor/github.com/dlclark/regexp2/v2/syntax/prefixanalyzer.go +++ b/vendor/github.com/dlclark/regexp2/v2/syntax/prefixanalyzer.go @@ -895,10 +895,11 @@ func tryFindRawFixedSets(node *RegexNode, res *[]FixedDistanceSet, distance *int combined[fixedSet.Distance] = v } } else { + setCopy := fixedSet.Set.Copy() combined[fixedSet.Distance] = struct { Set *CharSet Count int - }{Set: fixedSet.Set, Count: 1} + }{Set: &setCopy, Count: 1} } } } diff --git a/vendor/github.com/dlclark/regexp2/v2/syntax/tree.go b/vendor/github.com/dlclark/regexp2/v2/syntax/tree.go index f4b8b6a26..960f1a191 100644 --- a/vendor/github.com/dlclark/regexp2/v2/syntax/tree.go +++ b/vendor/github.com/dlclark/regexp2/v2/syntax/tree.go @@ -1680,6 +1680,12 @@ func (n *RegexNode) reduceConcatenationWithAdjacentStrings() { // Nested repeaters just get multiplied with each other if they're not // too lumpy func (n *RegexNode) reduceRep() *RegexNode { + // Repeating a literal empty expression has no observable effect. In addition to + // being unnecessary, retaining the loop would require one backtracking frame per + // mandatory iteration even though no input is consumed. + if len(n.Children) == 1 && n.Children[0].T == NtEmpty { + return n.Children[0] + } u := n t := n.T diff --git a/vendor/github.com/dlclark/regexp2/v2/syntax/writer.go b/vendor/github.com/dlclark/regexp2/v2/syntax/writer.go index 818b4b56c..ab7f7feac 100644 --- a/vendor/github.com/dlclark/regexp2/v2/syntax/writer.go +++ b/vendor/github.com/dlclark/regexp2/v2/syntax/writer.go @@ -4,34 +4,51 @@ import ( "bytes" "fmt" "math" + "slices" ) func Write(tree *RegexTree) (*Code, error) { - w := writer{ - intStack: make([]int, 0, 32), - emitted: make([]int, 2), - stringhash: make(map[string]int), - sethash: make(map[string]int), + w := newWriter(nil) + code, err := w.codeFromTree(tree) + if err != nil { + return nil, err } - code, err := w.codeFromTree(tree) + if slices.Contains(code.CaptureSlotInUse, false) { + quickWriter := newWriter(code.CaptureSlotInUse) + quickCode, err := quickWriter.codeFromTree(tree) + if err != nil { + return nil, err + } + code.QuickCodes = quickCode.Codes + } + return code, nil +} - return code, err +func newWriter(quickCaptureSlots []bool) writer { + return writer{ + intStack: make([]int, 0, 32), + emitted: make([]int, 2), + stringhash: make(map[string]int), + sethash: make(map[string]int), + quickCaptureSlots: quickCaptureSlots, + } } type writer struct { emitted []int - intStack []int - curpos int - stringhash map[string]int - stringtable [][]rune - sethash map[string]int - settable []*CharSet - counting bool - count int - trackcount int - caps map[int]int + intStack []int + curpos int + stringhash map[string]int + stringtable [][]rune + sethash map[string]int + settable []*CharSet + counting bool + count int + trackcount int + caps map[int]int + quickCaptureSlots []bool } const ( @@ -120,6 +137,9 @@ func (w *writer) codeFromTree(tree *RegexTree) (*Code, error) { w.counting = false } + if w.quickCaptureSlots != nil { + return &Code{Codes: w.emitted, TrackCount: w.trackcount}, nil + } fcPrefix := getFirstCharsPrefix(tree) prefix := getPrefix(tree) @@ -144,6 +164,7 @@ func (w *writer) codeFromTree(tree *RegexTree) (*Code, error) { TrackCount: w.trackcount, Caps: w.caps, Capsize: capsize, + CaptureSlotInUse: captureSlotsInUse(w.emitted, capsize), FcPrefix: fcPrefix, BmPrefix: bmPrefix, Anchors: getAnchors(tree), @@ -281,10 +302,14 @@ func (w *writer) emitFragment(nodetype NodeType, node *RegexNode, curIndex int) case NtGroup | BeforeChild, NtGroup | AfterChild: case NtCapture | BeforeChild: - w.emit(Setmark) + if w.emitCapture(node) { + w.emit(Setmark) + } case NtCapture | AfterChild: - w.emit2(Capturemark, w.mapCapnum(node.M), w.mapCapnum(node.N)) + if w.emitCapture(node) { + w.emit2(Capturemark, w.mapCapnum(node.M), w.mapCapnum(node.N)) + } case NtPosLook | BeforeChild: // NOTE: the following line causes lookahead/lookbehind to be @@ -366,6 +391,17 @@ func (w *writer) emitFragment(nodetype NodeType, node *RegexNode, curIndex int) return nil } +func (w *writer) emitCapture(node *RegexNode) bool { + if w.quickCaptureSlots == nil { + return true + } + capnum, uncapnum := w.mapCapnum(node.M), w.mapCapnum(node.N) + if uncapnum != -1 { + return true + } + return capnum >= 0 && (capnum >= len(w.quickCaptureSlots) || w.quickCaptureSlots[capnum]) +} + // To avoid recursion, we use a simple integer stack. // This is the push. func (w *writer) pushInt(i int) { diff --git a/vendor/github.com/grafana/sobek/builtin_string.go b/vendor/github.com/grafana/sobek/builtin_string.go index 604de4505..6005426e9 100644 --- a/vendor/github.com/grafana/sobek/builtin_string.go +++ b/vendor/github.com/grafana/sobek/builtin_string.go @@ -841,24 +841,88 @@ func (r *Runtime) stringproto_split(call FunctionCall) Value { return r.newArrayValues([]Value{s}) } - separator := separatorValue.String() - - str := s.String() - splitLimit := limit - if limit > 0 { - splitLimit = limit + 1 - } - - // TODO handle invalid UTF-16 - split := strings.SplitN(str, separator, splitLimit) + var valueArray []Value + sa, su := devirtualizeString(s) + sepa, sepu := devirtualizeString(separatorValue.toString()) + if su == nil { // ASCII string + if sepu == nil { + // Both are ASCII + splitLimit := limit + if limit > 0 { + splitLimit = limit + 1 + } - if limit > 0 && len(split) > limit { - split = split[:limit] - } + split := strings.SplitN(string(sa), string(sepa), splitLimit) - valueArray := make([]Value, len(split)) - for index, value := range split { - valueArray[index] = newStringValue(value) + if limit > 0 && len(split) > limit { + split = split[:limit] + } + valueArray = make([]Value, len(split)) + for index, value := range split { + valueArray[index] = asciiString(value) + } + } else { + // Unicode separator will never match an ASCII string + return r.newArrayValues([]Value{s}) + } + } else { + var ss []uint16 + if sepu != nil { + ss = sepu[1:] + } else { + ss = sepa.utf16() + } + su = su[1:] + if len(ss) > 0 { + idx := utf16Index(su, ss) + if idx == -1 { + // Shortcut to avoid creating a copy of s + return r.newArrayValues([]Value{s}) + } + if limit < 0 { + limit = min(math.MaxInt, math.MaxUint32) + } + for ; limit > 0; limit-- { + var sb strings.Builder + for i := range idx { + if su[i] >= utf8.RuneSelf { + chunk := make(unicodeString, idx+1) + chunk[0] = unistring.BOM + copy(chunk[1:], su[:idx]) + valueArray = append(valueArray, chunk) + goto next + } + } + sb.Grow(idx) + for i := range idx { + sb.WriteByte((byte)(su[i])) + } + valueArray = append(valueArray, asciiString(sb.String())) + next: + if idx == len(su) { + break + } + su = su[idx+len(ss):] + idx = utf16Index(su, ss) + if idx == -1 { + idx = len(su) + } + } + } else { + if limit > 0 && len(su) > limit { + su = su[:limit] + } + for len(su) > 0 { + c := su[0] + if c >= utf8.RuneSelf { + chunk := unicodeString{unistring.BOM, c} + valueArray = append(valueArray, chunk) + } else { + valueArray = append(valueArray, asciiString(rune(c))) + } + su = su[1:] + } + } } return r.newArrayValues(valueArray) diff --git a/vendor/github.com/grafana/sobek/builtin_typedarrays.go b/vendor/github.com/grafana/sobek/builtin_typedarrays.go index b323b6d01..6ca87d7b5 100644 --- a/vendor/github.com/grafana/sobek/builtin_typedarrays.go +++ b/vendor/github.com/grafana/sobek/builtin_typedarrays.go @@ -571,7 +571,7 @@ func (r *Runtime) typedArrayProto_filter(call FunctionCall) Value { ret := r.typedArrayCreate(c, intToValue(int64(captured))) keptTa := kept.self.(*typedArrayObject) for i := 0; i < captured; i++ { - ret.typedArray.set(i, keptTa.typedArray.get(keptTa.offset+i)) + ret.typedArray.set(ret.offset+i, keptTa.typedArray.get(keptTa.offset+i)) } return ret.val } @@ -1093,7 +1093,19 @@ func (r *Runtime) typedArrayProto_slice(call FunctionCall) Value { ta.viewedArrayBuf.ensureNotDetached(true) offset := ta.offset elemSize := ta.elemSize - copy(dst.viewedArrayBuf.data[dst.offset:], ta.viewedArrayBuf.data[(offset+start)*elemSize:(offset+start+count)*elemSize]) + byteCount := count * elemSize + dstBuf := dst.viewedArrayBuf.data[dst.offset*dst.elemSize : dst.offset*dst.elemSize+byteCount] + srcBuf := ta.viewedArrayBuf.data[(offset+start)*elemSize : (offset+start)*elemSize+byteCount] + dstStart := uintptr(unsafe.Pointer(&dstBuf[0])) + srcStart := uintptr(unsafe.Pointer(&srcBuf[0])) + if dstStart <= srcStart || dstStart >= srcStart+uintptr(byteCount) { + copy(dstBuf, srcBuf) + } else { + // Slices overlap forward, cannot just use copy() here because it's too smart + for i := 0; i < byteCount; i++ { + dstBuf[i] = srcBuf[i] + } + } } } else { for i := 0; i < count; i++ { @@ -1221,9 +1233,6 @@ func (r *Runtime) typedArrayProto_with(call FunctionCall) Value { } else { actualIndex = toIntStrict(int64(length) + relativeIndex) } - if !ta.isValidIntegerIndex(actualIndex) { - panic(r.newError(r.getRangeError(), "Invalid typed array index")) - } var numericValue Value switch ta.typedArray.(type) { @@ -1233,16 +1242,13 @@ func (r *Runtime) typedArrayProto_with(call FunctionCall) Value { numericValue = call.Argument(1).ToNumber() } - a := r.typedArrayCreate(ta.defaultCtor, intToValue(int64(length))) - for k := 0; k < length; k++ { - var fromValue Value - if k == actualIndex { - fromValue = numericValue - } else { - fromValue = ta.typedArray.get(ta.offset + k) - } - a.typedArray.set(k, fromValue) + if !ta.isValidIntegerIndex(actualIndex) { + panic(r.newError(r.getRangeError(), "Invalid typed array index")) } + + a := r.typedArrayCreate(ta.defaultCtor, intToValue(int64(length))) + copy(a.viewedArrayBuf.data, ta.viewedArrayBuf.data[ta.offset*ta.elemSize:]) + a.typedArray.set(actualIndex, numericValue) return a.val } @@ -1288,7 +1294,7 @@ func (r *Runtime) typedArrayProto_toSorted(call FunctionCall) Value { length := ta.length a := r.typedArrayCreate(ta.defaultCtor, intToValue(int64(length))) - copy(a.viewedArrayBuf.data, ta.viewedArrayBuf.data) + copy(a.viewedArrayBuf.data, ta.viewedArrayBuf.data[ta.offset*ta.elemSize:]) ctx := typedArraySortCtx{ ta: a, diff --git a/vendor/github.com/grafana/sobek/builtin_weakmap.go b/vendor/github.com/grafana/sobek/builtin_weakmap.go index 24bfdd2a4..14294acfc 100644 --- a/vendor/github.com/grafana/sobek/builtin_weakmap.go +++ b/vendor/github.com/grafana/sobek/builtin_weakmap.go @@ -1,36 +1,72 @@ package sobek -type weakMap uint64 - -type weakMapObject struct { - baseObject - m weakMap +import ( + "runtime" + "sync" + "weak" +) + +type weakMap struct { + m map[uint64]Value + sync.Mutex +} + +func (wm *weakMap) set(key *Object, value Value) { + id := key.getId() + wm.Lock() + _, exists := wm.m[id] + wm.m[id] = value + wm.Unlock() + if !exists { + wmPtr := weak.Make(wm) // do not hold strong reference to wm so that it could be collected by GC + runtime.AddCleanup(key, func(id uint64) { + wm := wmPtr.Value() + if wm == nil { + return + } + wm.Lock() + delete(wm.m, id) + wm.Unlock() + }, id) + } } -func (wmo *weakMapObject) init() { - wmo.baseObject.init() - wmo.m = weakMap(wmo.val.runtime.genId()) +func (wm *weakMap) get(key *Object) (res Value) { + id := key.getId() + wm.Lock() + res = wm.m[id] + wm.Unlock() + return } -func (wm weakMap) set(key *Object, value Value) { - key.getWeakRefs()[wm] = value +func (wm *weakMap) remove(key *Object) (removed bool) { + id := key.getId() + wm.Lock() + if _, removed = wm.m[id]; removed { + delete(wm.m, id) + } + wm.Unlock() + return } -func (wm weakMap) get(key *Object) Value { - return key.weakRefs[wm] +func (wm *weakMap) has(key *Object) bool { + id := key.getId() + wm.Lock() + _, exists := wm.m[id] + wm.Unlock() + return exists } -func (wm weakMap) remove(key *Object) bool { - if _, exists := key.weakRefs[wm]; exists { - delete(key.weakRefs, wm) - return true - } - return false +type weakMapObject struct { + baseObject + m weakMap } -func (wm weakMap) has(key *Object) bool { - _, exists := key.weakRefs[wm] - return exists +func (wmo *weakMapObject) init() { + wmo.baseObject.init() + wmo.m = weakMap{ + m: make(map[uint64]Value), + } } func (r *Runtime) weakMapProto_delete(call FunctionCall) Value { diff --git a/vendor/github.com/grafana/sobek/builtin_weakset.go b/vendor/github.com/grafana/sobek/builtin_weakset.go index e1f842ef0..9109c2c6d 100644 --- a/vendor/github.com/grafana/sobek/builtin_weakset.go +++ b/vendor/github.com/grafana/sobek/builtin_weakset.go @@ -7,7 +7,9 @@ type weakSetObject struct { func (ws *weakSetObject) init() { ws.baseObject.init() - ws.s = weakMap(ws.val.runtime.genId()) + ws.s = weakMap{ + m: make(map[uint64]Value), + } } func (r *Runtime) weakSetProto_add(call FunctionCall) Value { diff --git a/vendor/github.com/grafana/sobek/object.go b/vendor/github.com/grafana/sobek/object.go index 06ee2a3c0..acac475b0 100644 --- a/vendor/github.com/grafana/sobek/object.go +++ b/vendor/github.com/grafana/sobek/object.go @@ -5,6 +5,7 @@ import ( "math" "reflect" "sort" + "unsafe" "github.com/grafana/sobek/unistring" ) @@ -46,11 +47,8 @@ var ( ) type Object struct { - id uint64 - runtime *Runtime self objectImpl - - weakRefs map[weakMap]Value + runtime *Runtime } type iterNextFunc func() (propIterItem, iterNextFunc) @@ -601,7 +599,7 @@ func (o *baseObject) setForeignIdx(name valueInt, val, receiver Value, throw boo if idx := toIdx(name); idx != math.MaxUint32 { o.ensurePropOrder() if o.idxPropCount == 0 { - return o._setForeignIdx(name, name, nil, receiver, throw) + return o._setForeignIdx(name, nil, val, receiver, throw) } } return o.setForeignStr(name.string(), val, receiver, throw) @@ -1470,36 +1468,36 @@ func (o *Object) hasProperty(p Value) bool { func (o *Object) setStr(name unistring.String, val, receiver Value, throw bool) bool { if receiver == o { return o.self.setOwnStr(name, val, throw) - } else { - if res, ok := o.self.setForeignStr(name, val, receiver, throw); !ok { - if robj, ok := receiver.(*Object); ok { - if prop := robj.self.getOwnPropStr(name); prop != nil { - if desc, ok := prop.(*valueProperty); ok { - if desc.accessor { - o.runtime.typeErrorResult(throw, "Receiver property %s is an accessor", name) - return false - } - if !desc.writable { - o.runtime.typeErrorResult(throw, "Cannot assign to read only property '%s'", name) - return false - } + } + + if res, ok := o.self.setForeignStr(name, val, receiver, throw); !ok { + if robj, ok := receiver.(*Object); ok { + if prop := robj.self.getOwnPropStr(name); prop != nil { + if desc, ok := prop.(*valueProperty); ok { + if desc.accessor { + o.runtime.typeErrorResult(throw, "Receiver property %s is an accessor", name) + return false + } + if !desc.writable { + o.runtime.typeErrorResult(throw, "Cannot assign to read only property '%s'", name) + return false } - return robj.self.defineOwnPropertyStr(name, PropertyDescriptor{Value: val}, throw) - } else { - return robj.self.defineOwnPropertyStr(name, PropertyDescriptor{ - Value: val, - Writable: FLAG_TRUE, - Configurable: FLAG_TRUE, - Enumerable: FLAG_TRUE, - }, throw) } - } else { - o.runtime.typeErrorResult(throw, "Receiver is not an object: %v", receiver) - return false + return robj.self.defineOwnPropertyStr(name, PropertyDescriptor{Value: val}, throw) } - } else { - return res + + return robj.self.defineOwnPropertyStr(name, PropertyDescriptor{ + Value: val, + Writable: FLAG_TRUE, + Configurable: FLAG_TRUE, + Enumerable: FLAG_TRUE, + }, throw) } + + o.runtime.typeErrorResult(throw, "Receiver is not an object: %v", receiver) + return false + } else { + return res } } @@ -1528,75 +1526,73 @@ func (o *Object) setOwn(name Value, val Value, throw bool) bool { func (o *Object) setIdx(name valueInt, val, receiver Value, throw bool) bool { if receiver == o { return o.self.setOwnIdx(name, val, throw) - } else { - if res, ok := o.self.setForeignIdx(name, val, receiver, throw); !ok { - if robj, ok := receiver.(*Object); ok { - if prop := robj.self.getOwnPropIdx(name); prop != nil { - if desc, ok := prop.(*valueProperty); ok { - if desc.accessor { - o.runtime.typeErrorResult(throw, "Receiver property %s is an accessor", name) - return false - } - if !desc.writable { - o.runtime.typeErrorResult(throw, "Cannot assign to read only property '%s'", name) - return false - } + } + + if res, ok := o.self.setForeignIdx(name, val, receiver, throw); !ok { + if robj, ok := receiver.(*Object); ok { + if prop := robj.self.getOwnPropIdx(name); prop != nil { + if desc, ok := prop.(*valueProperty); ok { + if desc.accessor { + o.runtime.typeErrorResult(throw, "Receiver property %s is an accessor", name) + return false + } + if !desc.writable { + o.runtime.typeErrorResult(throw, "Cannot assign to read only property '%s'", name) + return false } - robj.self.defineOwnPropertyIdx(name, PropertyDescriptor{Value: val}, throw) - } else { - robj.self.defineOwnPropertyIdx(name, PropertyDescriptor{ - Value: val, - Writable: FLAG_TRUE, - Configurable: FLAG_TRUE, - Enumerable: FLAG_TRUE, - }, throw) } - } else { - o.runtime.typeErrorResult(throw, "Receiver is not an object: %v", receiver) - return false + return robj.self.defineOwnPropertyIdx(name, PropertyDescriptor{Value: val}, throw) } - } else { - return res + + return robj.self.defineOwnPropertyIdx(name, PropertyDescriptor{ + Value: val, + Writable: FLAG_TRUE, + Configurable: FLAG_TRUE, + Enumerable: FLAG_TRUE, + }, throw) } + + o.runtime.typeErrorResult(throw, "Receiver is not an object: %v", receiver) + return false + } else { + return res } - return true } func (o *Object) setSym(name *Symbol, val, receiver Value, throw bool) bool { if receiver == o { return o.self.setOwnSym(name, val, throw) - } else { - if res, ok := o.self.setForeignSym(name, val, receiver, throw); !ok { - if robj, ok := receiver.(*Object); ok { - if prop := robj.self.getOwnPropSym(name); prop != nil { - if desc, ok := prop.(*valueProperty); ok { - if desc.accessor { - o.runtime.typeErrorResult(throw, "Receiver property %s is an accessor", name) - return false - } - if !desc.writable { - o.runtime.typeErrorResult(throw, "Cannot assign to read only property '%s'", name) - return false - } + } + + if res, ok := o.self.setForeignSym(name, val, receiver, throw); !ok { + if robj, ok := receiver.(*Object); ok { + if prop := robj.self.getOwnPropSym(name); prop != nil { + if desc, ok := prop.(*valueProperty); ok { + if desc.accessor { + o.runtime.typeErrorResult(throw, "Receiver property %s is an accessor", name) + return false + } + if !desc.writable { + o.runtime.typeErrorResult(throw, "Cannot assign to read only property '%s'", name) + return false } - robj.self.defineOwnPropertySym(name, PropertyDescriptor{Value: val}, throw) - } else { - robj.self.defineOwnPropertySym(name, PropertyDescriptor{ - Value: val, - Writable: FLAG_TRUE, - Configurable: FLAG_TRUE, - Enumerable: FLAG_TRUE, - }, throw) } - } else { - o.runtime.typeErrorResult(throw, "Receiver is not an object: %v", receiver) - return false + return robj.self.defineOwnPropertySym(name, PropertyDescriptor{Value: val}, throw) } - } else { - return res + + return robj.self.defineOwnPropertySym(name, PropertyDescriptor{ + Value: val, + Writable: FLAG_TRUE, + Configurable: FLAG_TRUE, + Enumerable: FLAG_TRUE, + }, throw) } + + o.runtime.typeErrorResult(throw, "Receiver is not an object: %v", receiver) + return false + } else { + return res } - return true } func (o *Object) delete(n Value, throw bool) bool { @@ -1621,22 +1617,8 @@ func (o *Object) defineOwnProperty(n Value, desc PropertyDescriptor, throw bool) } } -func (o *Object) getWeakRefs() map[weakMap]Value { - refs := o.weakRefs - if refs == nil { - refs = make(map[weakMap]Value) - o.weakRefs = refs - } - return refs -} - func (o *Object) getId() uint64 { - id := o.id - if id == 0 { - id = o.runtime.genId() - o.id = id - } - return id + return uint64(uintptr(unsafe.Pointer(o))) } func (o *guardedObject) guard(props ...unistring.String) { diff --git a/vendor/github.com/grafana/sobek/runtime.go b/vendor/github.com/grafana/sobek/runtime.go index cb8502a35..bb95249f5 100644 --- a/vendor/github.com/grafana/sobek/runtime.go +++ b/vendor/github.com/grafana/sobek/runtime.go @@ -193,9 +193,8 @@ type Runtime struct { fieldNameMapper FieldNameMapper - vm *vm - hash *maphash.Hash - idSeq uint64 + vm *vm + hash *maphash.Hash modules map[ModuleRecord]ModuleInstance moduleNamespaces map[ModuleRecord]*namespaceObject @@ -2938,19 +2937,6 @@ func growCap(newSize, oldSize, oldCap int) int { } } -func (r *Runtime) genId() (ret uint64) { - if r.hash == nil { - h := r.getHash() - r.idSeq = h.Sum64() - } - if r.idSeq == 0 { - r.idSeq = 1 - } - ret = r.idSeq - r.idSeq++ - return -} - func (r *Runtime) setGlobal(name unistring.String, v Value, strict bool) { if ref := r.global.stash.getRefByName(name, strict); ref != nil { ref.set(v) diff --git a/vendor/github.com/grafana/sobek/string_ascii.go b/vendor/github.com/grafana/sobek/string_ascii.go index 63c92ada0..7faffd78e 100644 --- a/vendor/github.com/grafana/sobek/string_ascii.go +++ b/vendor/github.com/grafana/sobek/string_ascii.go @@ -82,6 +82,14 @@ func (s asciiString) utf16Runes() []rune { return runes } +func (s asciiString) utf16() []uint16 { + u := make([]uint16, len(s)) + for i := 0; i < len(s); i++ { + u[i] = uint16(s[i]) + } + return u +} + // ss must be trimmed func stringToInt(ss string) (int64, error) { if ss == "" { @@ -335,16 +343,11 @@ func (s asciiString) Substring(start, end int) String { } func (s asciiString) CompareTo(other String) int { - switch other := other.(type) { - case asciiString: - return strings.Compare(string(s), string(other)) - case unicodeString: - return strings.Compare(string(s), other.String()) - case *importedString: - return strings.Compare(string(s), other.s) - default: - panic(newTypeError("Internal bug: unknown string type: %T", other)) + a, u := devirtualizeString(other) + if u != nil { + return -u.compareToAscii(s) } + return strings.Compare(string(s), string(a)) } func (s asciiString) index(substr String, start int) int { diff --git a/vendor/github.com/grafana/sobek/string_imported.go b/vendor/github.com/grafana/sobek/string_imported.go index e61cb77c4..2e97a2fa7 100644 --- a/vendor/github.com/grafana/sobek/string_imported.go +++ b/vendor/github.com/grafana/sobek/string_imported.go @@ -188,7 +188,11 @@ func (i *importedString) Substring(start, end int) String { } func (i *importedString) CompareTo(v String) int { - return strings.Compare(i.s, v.String()) + i.ensureScanned() + if i.u != nil { + return i.u.CompareTo(v) + } + return asciiString(i.s).CompareTo(v) } func (i *importedString) Reader() io.RuneReader { diff --git a/vendor/github.com/grafana/sobek/string_unicode.go b/vendor/github.com/grafana/sobek/string_unicode.go index b0afeef11..721bb380b 100644 --- a/vendor/github.com/grafana/sobek/string_unicode.go +++ b/vendor/github.com/grafana/sobek/string_unicode.go @@ -1,14 +1,17 @@ package sobek import ( + "bytes" "errors" "hash/maphash" "io" "math" "reflect" + "slices" "strings" "unicode/utf16" "unicode/utf8" + "unsafe" "github.com/grafana/sobek/parser" "github.com/grafana/sobek/unistring" @@ -16,6 +19,8 @@ import ( "golang.org/x/text/language" ) +const utf16IndexNaiveCrossover = 32 + type unicodeString []uint16 type unicodeRuneReader struct { @@ -495,9 +500,100 @@ func (s unicodeString) String() string { return string(utf16.Decode(s[1:])) } +func (s unicodeString) compareToAscii(s2 asciiString) int { + s1 := s[1:] + for i := range s1 { + if i >= len(s2) { + return 1 + } + c1 := s1[i] + c2 := uint16(s2[i]) + if c1 < c2 { + return -1 + } + if c1 > c2 { + return 1 + } + } + // This condition will never be true as long as unicodeString contains at least one + // Unicode character, but is left here for completeness. + if len(s2) > len(s1) { + return -1 + } + return 0 +} + func (s unicodeString) CompareTo(other String) int { - // TODO handle invalid UTF-16 - return strings.Compare(s.String(), other.String()) + oa, ou := devirtualizeString(other) + if ou != nil { + return slices.Compare(s[1:], ou[1:]) + } + return s.compareToAscii(oa) +} + +func utf16Index(s, substr []uint16) int { + if len(s) < utf16IndexNaiveCrossover { + return utf16IndexNaive(s, substr) + } + return utf16IndexBytes(s, substr) +} + +func utf16IndexNaive(s, sep []uint16) int { + n := len(sep) + if n == 0 { + return 0 + } + if n > len(s) { + return -1 + } + for i := 0; i+n <= len(s); i++ { + if s[i] == sep[0] { + match := true + for j := 1; j < n; j++ { + if s[i+j] != sep[j] { + match = false + break + } + } + if match { + return i + } + } + } + return -1 +} + +func uint16AsBytes(s []uint16) []byte { + if len(s) == 0 { + return nil + } + return unsafe.Slice((*byte)(unsafe.Pointer(&s[0])), len(s)*2) +} + +func utf16IndexBytes(s, sep []uint16) int { + if len(sep) == 0 { + return 0 + } + if len(sep) > len(s) { + return -1 + } + + sb := uint16AsBytes(s) + sepb := uint16AsBytes(sep) + + offset := 0 + for { + i := bytes.Index(sb[offset:], sepb) + if i < 0 { + return -1 + } + pos := offset + i + if pos%2 == 0 { + return pos / 2 + } + // False match, not aligned, continue + offset = pos + 1 + } } func (s unicodeString) index(substr String, start int) int { @@ -506,24 +602,72 @@ func (s unicodeString) index(substr String, start int) int { if u != nil { ss = u[1:] } else { - ss = make([]uint16, len(a)) - for i := 0; i < len(a); i++ { - ss[i] = uint16(a[i]) - } + ss = a.utf16() } - s1 := s[1:] - // TODO: optimise - end := len(s1) - len(ss) - for start <= end { - for i := 0; i < len(ss); i++ { - if s1[start+i] != ss[i] { - goto nomatch + idx := utf16Index(s[min(1+start, len(s)):], ss) + if idx != -1 { + return idx + start + } + return -1 +} + +func utf16LastIndex(s, sep []uint16) int { + if len(s) < utf16IndexNaiveCrossover { + return utf16LastIndexNaive(s, sep) + } + return utf16LastIndexBytes(s, sep) +} + +func utf16LastIndexNaive(s, sep []uint16) int { + n := len(sep) + if n == 0 { + return len(s) + } + if n > len(s) { + return -1 + } + for i := len(s) - n; i >= 0; i-- { + if s[i] == sep[0] { + match := true + for j := 1; j < n; j++ { + if s[i+j] != sep[j] { + match = false + break + } + } + if match { + return i } } + } + return -1 +} - return start - nomatch: - start++ +func utf16LastIndexBytes(s, sep []uint16) int { + if len(sep) == 0 { + return len(s) + } + if len(sep) > len(s) { + return -1 + } + + sb := uint16AsBytes(s) + sepb := uint16AsBytes(sep) + + end := len(sb) + for end >= len(sepb) { + i := bytes.LastIndex(sb[:end], sepb) + if i < 0 { + return -1 + } + if i%2 == 0 { + return i / 2 + } + // False match starting at odd byte offset i. Shrink the window so + // the next search can still find a match starting at i-1 (i.e. + // end must be >= (i-1)+len(sepb)) while excluding this same match + // (end must be < i+len(sepb)). end = i+len(sepb)-1 satisfies both. + end = i + len(sepb) - 1 } return -1 } @@ -534,29 +678,9 @@ func (s unicodeString) lastIndex(substr String, start int) int { if u != nil { ss = u[1:] } else { - ss = make([]uint16, len(a)) - for i := 0; i < len(a); i++ { - ss[i] = uint16(a[i]) - } - } - - s1 := s[1:] - if maxStart := len(s1) - len(ss); start > maxStart { - start = maxStart - } - // TODO: optimise - for start >= 0 { - for i := 0; i < len(ss); i++ { - if s1[start+i] != ss[i] { - goto nomatch - } - } - - return start - nomatch: - start-- + ss = a.utf16() } - return -1 + return utf16LastIndex(s[1:min(start+1+len(ss), len(s))], ss) } func unicodeStringFromRunes(r []rune) unicodeString { diff --git a/vendor/github.com/grafana/sobek/typedarrays.go b/vendor/github.com/grafana/sobek/typedarrays.go index 74a0abb1e..da5abf296 100644 --- a/vendor/github.com/grafana/sobek/typedarrays.go +++ b/vendor/github.com/grafana/sobek/typedarrays.go @@ -820,10 +820,22 @@ func (a *typedArrayObject) setOwnIdx(p valueInt, v Value, throw bool) bool { } func (a *typedArrayObject) setForeignStr(p unistring.String, v, receiver Value, throw bool) (res bool, handled bool) { + idx, ok := strToIntNum(p) + if ok { + if !a.isValidIntegerIndex(idx) { + return true, true + } + } else if idx == 0 { + return true, true + } + return a._setForeignStr(p, a.getOwnPropStr(p), v, receiver, throw) } func (a *typedArrayObject) setForeignIdx(p valueInt, v, receiver Value, throw bool) (res bool, handled bool) { + if !a.isValidIntegerIndex(toIntClamp(int64(p))) { + return true, true + } return a._setForeignIdx(p, trueValIfPresent(a.hasOwnPropertyIdx(p)), v, receiver, throw) } diff --git a/vendor/github.com/grafana/sobek/value.go b/vendor/github.com/grafana/sobek/value.go index 18e16e3b5..18f5b5ded 100644 --- a/vendor/github.com/grafana/sobek/value.go +++ b/vendor/github.com/grafana/sobek/value.go @@ -112,12 +112,11 @@ type valueUndefined struct { valueNull } -// *Symbol is a Value containing ECMAScript Symbol primitive. Symbols must only be created +// Symbol is a Value containing ECMAScript Symbol primitive. Symbols must only be created // using NewSymbol(). Zero values and copying of values (i.e. *s1 = *s2) are not permitted. // Well-known Symbols can be accessed using Sym* package variables (SymIterator, etc...) // Symbols can be shared by multiple Runtimes. type Symbol struct { - h uintptr desc String } @@ -1127,7 +1126,11 @@ func (s *Symbol) baseObject(r *Runtime) *Object { } func (s *Symbol) hash(*maphash.Hash) uint64 { - return uint64(s.h) + // This may need to be reconsidered in the future. + // Depending on changes in Go's allocation policy and/or introduction of a compacting GC + // this may no longer provide sufficient dispersion. The alternative, however, is a globally + // synchronised random generator/hasher/sequencer and I don't want to go down that route just yet. + return uint64(uintptr(unsafe.Pointer(s))) } func exportValue(v Value, ctx *objectExportCtx) interface{} { @@ -1138,15 +1141,9 @@ func exportValue(v Value, ctx *objectExportCtx) interface{} { } func newSymbol(s String) *Symbol { - r := &Symbol{ + return &Symbol{ desc: s, } - // This may need to be reconsidered in the future. - // Depending on changes in Go's allocation policy and/or introduction of a compacting GC - // this may no longer provide sufficient dispersion. The alternative, however, is a globally - // synchronised random generator/hasher/sequencer and I don't want to go down that route just yet. - r.h = uintptr(unsafe.Pointer(r)) - return r } func NewSymbol(s string) *Symbol { diff --git a/vendor/modules.txt b/vendor/modules.txt index b09fe1c21..1d02401f0 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -110,7 +110,7 @@ github.com/chromedp/sysutil # github.com/davecgh/go-spew v1.1.1 ## explicit github.com/davecgh/go-spew/spew -# github.com/dlclark/regexp2/v2 v2.2.2 +# github.com/dlclark/regexp2/v2 v2.5.2 ## explicit; go 1.25 github.com/dlclark/regexp2/v2 github.com/dlclark/regexp2/v2/helpers @@ -185,8 +185,8 @@ github.com/grafana/k6-cloud-openapi-client-go/k6 # github.com/grafana/k6provider v0.5.0 ## explicit; go 1.24.0 github.com/grafana/k6provider -# github.com/grafana/sobek v0.0.0-20260708062710-267a0e055bb4 -## explicit; go 1.25 +# github.com/grafana/sobek v0.0.0-20260727154728-7781506a890f +## explicit; go 1.25.0 github.com/grafana/sobek github.com/grafana/sobek/ast github.com/grafana/sobek/file From 68d8dd54e44436db86e1f80c8cefa7d9ef712b7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 3 Jul 2026 13:36:12 -0400 Subject: [PATCH 060/182] Make usage report endpoint overridable The usage report endpoint was a hardcoded const posting to stats.grafana.org, so no test could observe the anonymous usage report. Reading the endpoint from K6_USAGE_REPORT_URL (defaulting to the production endpoint) lets integration tests point it at a local server and assert the report is sent. --- cmd/state/state.go | 5 +++ internal/cmd/report.go | 10 ++++- internal/cmd/tests/cmd_run_report_test.go | 49 +++++++++++++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 internal/cmd/tests/cmd_run_report_test.go diff --git a/cmd/state/state.go b/cmd/state/state.go index ae5e7163a..fe5b03ba0 100644 --- a/cmd/state/state.go +++ b/cmd/state/state.go @@ -44,6 +44,11 @@ const ( // to keep the command tree construction off the real network. ProvisionCatalogURL = "K6_PROVISION_CATALOG_URL" + // UsageReportURL overrides the endpoint the anonymous usage report is sent + // to. It defaults to the production endpoint and lets tests point it at an + // httptest server to observe the report. + UsageReportURL = "K6_USAGE_REPORT_URL" + // defaultBuildServiceURL defines the URL to the default (grafana hosted) build service defaultBuildServiceURL = "https://ingest.k6.io/builder/api/v1" diff --git a/internal/cmd/report.go b/internal/cmd/report.go index 58062ca53..d0c12af3f 100644 --- a/internal/cmd/report.go +++ b/internal/cmd/report.go @@ -8,6 +8,7 @@ import ( "runtime" "strconv" + "go.k6.io/k6/v2/cmd/state" "go.k6.io/k6/v2/internal/build" "go.k6.io/k6/v2/internal/execution" "go.k6.io/k6/v2/internal/usage" @@ -33,6 +34,10 @@ func createReport(u *usage.Usage, execScheduler *execution.Scheduler) map[string return m } +// defaultUsageReportURL is the production endpoint the anonymous usage report +// is sent to when K6_USAGE_REPORT_URL is not set. +const defaultUsageReportURL = "https://stats.grafana.org/k6-usage-report" + func reportUsage(ctx context.Context, execScheduler *execution.Scheduler, test *loadedAndConfiguredTest) error { m := createReport(test.preInitState.Usage, execScheduler) body, err := json.Marshal(m) @@ -40,7 +45,10 @@ func reportUsage(ctx context.Context, execScheduler *execution.Scheduler, test * return err } - const usageStatsURL = "https://stats.grafana.org/k6-usage-report" + usageStatsURL := defaultUsageReportURL + if url, ok := test.preInitState.LookupEnv(state.UsageReportURL); ok && url != "" { + usageStatsURL = url + } req, err := http.NewRequestWithContext(ctx, http.MethodPost, usageStatsURL, bytes.NewBuffer(body)) if err != nil { return err diff --git a/internal/cmd/tests/cmd_run_report_test.go b/internal/cmd/tests/cmd_run_report_test.go new file mode 100644 index 000000000..98d92e99a --- /dev/null +++ b/internal/cmd/tests/cmd_run_report_test.go @@ -0,0 +1,49 @@ +package tests + +import ( + "bytes" + "net/http" + "net/http/httptest" + "sync/atomic" + "testing" + + "github.com/stretchr/testify/require" + + "go.k6.io/k6/v2/cmd/state" + "go.k6.io/k6/v2/internal/cmd" +) + +func TestRunReportsExtensions(t *testing.T) { + t.Parallel() + + tt := []struct { + name string + }{ + {name: "sends the usage report to the configured endpoint"}, + } + + for _, tc := range tt { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + + var reported atomic.Bool + reportServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method == http.MethodPost { + reported.Store(true) + } + w.WriteHeader(http.StatusOK) + })) + t.Cleanup(reportServer.Close) + + ts := NewGlobalTestState(t) + ts.Env["K6_NO_USAGE_REPORT"] = "false" + ts.Env[state.UsageReportURL] = reportServer.URL + ts.CmdArgs = []string{"k6", "run", "-"} + ts.Stdin = bytes.NewBufferString(`export default function() {};`) + + cmd.ExecuteWithGlobalState(ts.GlobalState) + + require.True(t, reported.Load(), "expected the usage report to reach the configured endpoint") + }) + } +} From f9e9f5a25692f0f3a1364b3200ad4d4a524c4102 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 3 Jul 2026 13:41:54 -0400 Subject: [PATCH 061/182] Report imported catalog extensions in usage report The usage report tracked only built-in modules and dropped every k6/x/ import, so extension adoption was invisible. Resolved Go extensions are now recorded in a dedicated extensions bucket at the cached resolution site, identified by registry membership rather than the k6/x/ name, and reported with their Go module path, version, and kind, de-duplicated per module and kind. Only extensions whose module path appears in the public registry catalog are reported, so private or unlisted extensions never leak. The catalog is read through the same cache file, TTL, and K6_PROVISION_CATALOG_URL override the k6 x subcommand path uses, fetched inside the bounded report send off the run's hot path, and an unreachable catalog fail-closed reports nothing. When nothing catalogued was used, the extensions key is omitted rather than sent as an empty array, consistent with how modules behaves. --- internal/cmd/report.go | 66 ++++++++++- internal/cmd/report_test.go | 9 +- internal/cmd/run.go | 2 +- internal/cmd/subcommand.go | 3 +- internal/cmd/tests/cmd_run_report_test.go | 103 ++++++++++++++++- internal/cmd/tests/testimport2/testimport2.go | 21 ++++ internal/cmd/x_registry.go | 107 +++++++++++++++--- internal/usage/usage.go | 24 ++++ js/modules/resolution.go | 16 ++- 9 files changed, 314 insertions(+), 37 deletions(-) create mode 100644 internal/cmd/tests/testimport2/testimport2.go diff --git a/internal/cmd/report.go b/internal/cmd/report.go index d0c12af3f..983e497db 100644 --- a/internal/cmd/report.go +++ b/internal/cmd/report.go @@ -9,12 +9,30 @@ import ( "strconv" "go.k6.io/k6/v2/cmd/state" + "go.k6.io/k6/v2/ext" "go.k6.io/k6/v2/internal/build" "go.k6.io/k6/v2/internal/execution" "go.k6.io/k6/v2/internal/usage" ) -func createReport(u *usage.Usage, execScheduler *execution.Scheduler) map[string]any { +// extensionEntry identifies a used extension in the usage report by its Go +// module path, along with its version and kind. +type extensionEntry struct { + Module string `json:"module"` + Version string `json:"version"` + Kind string `json:"kind"` +} + +// newExtensionEntry builds the usage-report entry for a registered extension. +func newExtensionEntry(e *ext.Extension) extensionEntry { + return extensionEntry{ + Module: e.Path, + Version: e.Version, + Kind: e.Type.String(), + } +} + +func createReport(u *usage.Usage, execScheduler *execution.Scheduler, catalog map[string]struct{}) map[string]any { execState := execScheduler.GetState() m := u.Map() @@ -31,15 +49,57 @@ func createReport(u *usage.Usage, execScheduler *execution.Scheduler) map[string m["executors"] = executors m["is_ci"] = isCI(execState.Test.LookupEnv) + resolveExtensions(m, catalog) + return m } +// resolveExtensions replaces the used extensions recorded under "extensions" in +// usage with report entries, keeping only those advertised in the public +// catalog. Fail closed: dropping the raw list first means an empty catalog +// reports no extensions rather than leaking it, and the key stays omitted when +// nothing survives instead of sending []. +func resolveExtensions(m map[string]any, catalog map[string]struct{}) { + used, ok := m["extensions"].([]any) + if !ok { + return + } + delete(m, "extensions") + if entries := filterExtensions(used, catalog); len(entries) > 0 { + m["extensions"] = entries + } +} + +// filterExtensions turns the recorded used extensions into report entries, +// keeping only those whose module path is advertised in the public catalog and +// de-duplicating per (module, kind). +func filterExtensions(used []any, public map[string]struct{}) []extensionEntry { + seen := make(map[[2]string]struct{}, len(used)) + entries := make([]extensionEntry, 0, len(used)) + for _, v := range used { + e, ok := v.(*ext.Extension) + if !ok { + continue + } + if _, ok := public[e.Path]; !ok { + continue + } + key := [2]string{e.Path, e.Type.String()} + if _, dup := seen[key]; dup { + continue + } + seen[key] = struct{}{} + entries = append(entries, newExtensionEntry(e)) + } + return entries +} + // defaultUsageReportURL is the production endpoint the anonymous usage report // is sent to when K6_USAGE_REPORT_URL is not set. const defaultUsageReportURL = "https://stats.grafana.org/k6-usage-report" -func reportUsage(ctx context.Context, execScheduler *execution.Scheduler, test *loadedAndConfiguredTest) error { - m := createReport(test.preInitState.Usage, execScheduler) +func reportUsage(ctx context.Context, gs *state.GlobalState, execScheduler *execution.Scheduler, test *loadedAndConfiguredTest) error { + m := createReport(test.preInitState.Usage, execScheduler, catalogModulePaths(ctx, gs)) body, err := json.Marshal(m) if err != nil { return err diff --git a/internal/cmd/report_test.go b/internal/cmd/report_test.go index b93dabe72..34de346d5 100644 --- a/internal/cmd/report_test.go +++ b/internal/cmd/report_test.go @@ -50,8 +50,7 @@ func TestCreateReport(t *testing.T) { time.Sleep(10 * time.Millisecond) s.GetState().MarkEnded() - m := createReport(usage.New(), s) - require.NoError(t, err) + m := createReport(usage.New(), s, nil) assert.Equal(t, build.Version, m["k6_version"]) assert.EqualValues(t, map[string]int{"shared-iterations": 1}, m["executors"]) @@ -72,8 +71,7 @@ func TestCreateReport(t *testing.T) { }) require.NoError(t, err) - m := createReport(usage.New(), s) - require.NoError(t, err) + m := createReport(usage.New(), s, nil) assert.Equal(t, build.Version, m["k6_version"]) assert.EqualValues(t, map[string]int{"shared-iterations": 1}, m["executors"]) @@ -94,8 +92,7 @@ func TestCreateReport(t *testing.T) { }) require.NoError(t, err) - m := createReport(usage.New(), s) - require.NoError(t, err) + m := createReport(usage.New(), s, nil) assert.Equal(t, build.Version, m["k6_version"]) assert.EqualValues(t, map[string]int{"shared-iterations": 1}, m["executors"]) diff --git a/internal/cmd/run.go b/internal/cmd/run.go index 17e0f96c9..95058cddd 100644 --- a/internal/cmd/run.go +++ b/internal/cmd/run.go @@ -464,7 +464,7 @@ func (c *cmdRun) run(cmd *cobra.Command, args []string) (err error) { defer reportCancel() logger.Debug("Sending usage report...") - if rerr := reportUsage(reportCtx, execScheduler, test); rerr != nil { + if rerr := reportUsage(reportCtx, c.gs, execScheduler, test); rerr != nil { logger.WithError(rerr).Debug("Error sending usage report") } else { logger.Debug("Usage report sent successfully") diff --git a/internal/cmd/subcommand.go b/internal/cmd/subcommand.go index 1127a1b76..4bcc13cd7 100644 --- a/internal/cmd/subcommand.go +++ b/internal/cmd/subcommand.go @@ -1,7 +1,6 @@ package cmd import ( - "cmp" "fmt" "slices" "strings" @@ -107,7 +106,7 @@ func registryStubs(gs *state.GlobalState, baked []*cobra.Command) []*cobra.Comma gs.Logger.WithError(err).Debug("k6 extension catalog") } if subs == nil && first == 0 { // first == 0: not TAB completion, network allowed - url := cmp.Or(gs.Env[state.ProvisionCatalogURL], defaultCatalogURL()) + url := catalogURL(gs) _, _ = fmt.Fprint(gs.Stderr, "Loading the subcommand list...") tail := "\n\n" if gs.Stderr.IsTTY { diff --git a/internal/cmd/tests/cmd_run_report_test.go b/internal/cmd/tests/cmd_run_report_test.go index 98d92e99a..64604ed37 100644 --- a/internal/cmd/tests/cmd_run_report_test.go +++ b/internal/cmd/tests/cmd_run_report_test.go @@ -2,24 +2,98 @@ package tests import ( "bytes" + "encoding/json" + "io" "net/http" "net/http/httptest" + "sync" "sync/atomic" "testing" "github.com/stretchr/testify/require" "go.k6.io/k6/v2/cmd/state" + "go.k6.io/k6/v2/ext" "go.k6.io/k6/v2/internal/cmd" + "go.k6.io/k6/v2/internal/cmd/tests/testimport2" + "go.k6.io/k6/v2/js/modules" ) +// testImportModule is the resolved module path of the in-tree k6/x/testimport +// extension registered by registerRunReportTestExtensions. It is whatever +// ext.Get(ext.JSExtension)["k6/x/testimport"].Path returns for an in-tree +// registration, i.e. this test package's own Go package path. +const testImportModule = "go.k6.io/k6/v2/internal/cmd/tests" + +// testImportModule2 is the resolved module path of the in-tree k6/x/testimport2 +// extension. Its module type lives in its own Go package, so it resolves to a +// distinct path from testImportModule. +const testImportModule2 = "go.k6.io/k6/v2/internal/cmd/tests/testimport2" + +type runReportTestModule struct{} + +func (*runReportTestModule) NewModuleInstance(_ modules.VU) modules.Instance { + return &runReportTestModuleInstance{} +} + +type runReportTestModuleInstance struct{} + +func (*runReportTestModuleInstance) Exports() modules.Exports { + return modules.Exports{Named: map[string]any{}} +} + +// registerRunReportTestExtensionsOnce guards process-global ext.Register, which +// panics on a duplicate name/type. +var registerRunReportTestExtensionsOnce sync.Once //nolint:gochecknoglobals + +func registerRunReportTestExtensions(t *testing.T) { + t.Helper() + + registerRunReportTestExtensionsOnce.Do(func() { + modules.Register("k6/x/testimport", &runReportTestModule{}) + modules.Register("k6/x/testimport2", &testimport2.Module{}) + }) +} + func TestRunReportsExtensions(t *testing.T) { t.Parallel() + registerRunReportTestExtensions(t) + tt := []struct { - name string + name string + script string + catalog string + wantExtensions []map[string]any }{ - {name: "sends the usage report to the configured endpoint"}, + { + name: "sends the usage report to the configured endpoint", + script: `export default function() {};`, + }, + { + name: "used public import is reported", + script: `import "k6/x/testimport"; export default function() {};`, + catalog: `{"k6/x/testimport": {"module":"` + testImportModule + `"}}`, + wantExtensions: []map[string]any{ + { + "module": testImportModule, + "version": ext.Get(ext.JSExtension)["k6/x/testimport"].Version, + "kind": "js", + }, + }, + }, + { + name: "extension not in the catalog is filtered out", + script: `import "k6/x/testimport"; import "k6/x/testimport2"; export default function() {};`, + catalog: `{"k6/x/testimport2": {"module":"` + testImportModule2 + `"}}`, + wantExtensions: []map[string]any{ + { + "module": testImportModule2, + "version": ext.Get(ext.JSExtension)["k6/x/testimport2"].Version, + "kind": "js", + }, + }, + }, } for _, tc := range tt { @@ -27,8 +101,11 @@ func TestRunReportsExtensions(t *testing.T) { t.Parallel() var reported atomic.Bool + var gotBody atomic.Value reportServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.Method == http.MethodPost { + body, _ := io.ReadAll(r.Body) + gotBody.Store(body) reported.Store(true) } w.WriteHeader(http.StatusOK) @@ -38,12 +115,32 @@ func TestRunReportsExtensions(t *testing.T) { ts := NewGlobalTestState(t) ts.Env["K6_NO_USAGE_REPORT"] = "false" ts.Env[state.UsageReportURL] = reportServer.URL + if tc.catalog != "" { + catalogServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + w.Header().Set("Content-Type", "application/json") + _, _ = w.Write([]byte(tc.catalog)) + })) + t.Cleanup(catalogServer.Close) + ts.Env[state.ProvisionCatalogURL] = catalogServer.URL + } ts.CmdArgs = []string{"k6", "run", "-"} - ts.Stdin = bytes.NewBufferString(`export default function() {};`) + ts.Stdin = bytes.NewBufferString(tc.script) cmd.ExecuteWithGlobalState(ts.GlobalState) require.True(t, reported.Load(), "expected the usage report to reach the configured endpoint") + + if tc.wantExtensions == nil { + return + } + + raw, ok := gotBody.Load().([]byte) + require.True(t, ok, "expected a report body") + var report struct { + Extensions []map[string]any `json:"extensions"` + } + require.NoError(t, json.Unmarshal(raw, &report)) + require.ElementsMatch(t, tc.wantExtensions, report.Extensions) }) } } diff --git a/internal/cmd/tests/testimport2/testimport2.go b/internal/cmd/tests/testimport2/testimport2.go new file mode 100644 index 000000000..702f8bea3 --- /dev/null +++ b/internal/cmd/tests/testimport2/testimport2.go @@ -0,0 +1,21 @@ +// Package testimport2 hosts a second in-tree JS module type in its own Go +// package so it resolves to a distinct module path from the k6/x/testimport +// extension. Two module types in the same package would share one path and get +// de-duplicated, which would hide slot-overwrite or over-dedup bugs. +package testimport2 + +import "go.k6.io/k6/v2/js/modules" + +// Module is a no-op JS module used only to register a second distinct extension. +type Module struct{} + +// NewModuleInstance implements modules.Module. +func (*Module) NewModuleInstance(_ modules.VU) modules.Instance { + return &instance{} +} + +type instance struct{} + +func (*instance) Exports() modules.Exports { + return modules.Exports{Named: map[string]any{}} +} diff --git a/internal/cmd/x_registry.go b/internal/cmd/x_registry.go index 6c47ca4f3..2f754613f 100644 --- a/internal/cmd/x_registry.go +++ b/internal/cmd/x_registry.go @@ -1,6 +1,7 @@ package cmd import ( + "cmp" "context" "encoding/json" "errors" @@ -69,6 +70,12 @@ func catalogMajorVersion() string { return v } +// catalogURL returns the extension registry catalog URL, honouring the +// K6_PROVISION_CATALOG_URL override. +func catalogURL(gs *state.GlobalState) string { + return cmp.Or(gs.Env[state.ProvisionCatalogURL], defaultCatalogURL()) +} + // catalogCachePath returns the on-disk location of the k6 extension registry // catalog cache, alongside the build cache so both share the user cache dir. func catalogCachePath(gs *state.GlobalState) string { @@ -79,23 +86,9 @@ func catalogCachePath(gs *state.GlobalState) string { // cache. A missing or stale cache returns (nil, nil); real I/O or parse // failures return an error so the caller can surface them at debug. func readCachedCatalog(gs *state.GlobalState, cachePath string) (registrySubcommands, error) { - maxAge := 24 * time.Hour - if d, err := time.ParseDuration(gs.Env[state.ProvisionCatalogTTL]); err == nil { - maxAge = d - } - info, err := gs.FS.Stat(cachePath) - if errors.Is(err, fs.ErrNotExist) { - return nil, nil - } - if err != nil { - return nil, fmt.Errorf("checking extensions cache: %w", err) - } - if time.Since(info.ModTime()) > maxAge { - return nil, nil - } - raw, err := fsext.ReadFile(gs.FS, cachePath) - if err != nil { - return nil, fmt.Errorf("reading extensions cache: %w", err) + raw, err := readCachedCatalogBytes(gs, cachePath) + if raw == nil || err != nil { + return nil, err } var subs registrySubcommands if err := json.Unmarshal(raw, &subs); err != nil { @@ -136,6 +129,86 @@ func fetchCatalog(ctx context.Context, url string) (registrySubcommands, []byte, return subs, raw, nil } +// catalogModulePaths returns the set of Go module paths advertised in the k6 +// extension registry catalog. It shares the same cache file, TTL, and +// K6_PROVISION_CATALOG_URL override as `k6 x`: it reads the on-disk cache and, +// on a miss, fetches the catalog and writes the fresh bytes back. The caller +// bounds ctx so the fetch stays non-fatal and off the run's hot path; any +// failure yields an empty set. +func catalogModulePaths(ctx context.Context, gs *state.GlobalState) map[string]struct{} { + cachePath := catalogCachePath(gs) + raw, err := readCachedCatalogBytes(gs, cachePath) + if err != nil { + gs.Logger.WithError(err).Debug("k6 extension catalog") + } + if raw == nil { + raw, err = fetchCatalogBytes(ctx, gs, cachePath) + if err != nil { + gs.Logger.WithError(err).Debug("k6 extension catalog") + return nil + } + } + return parseCatalogModulePaths(raw) +} + +// readCachedCatalogBytes returns the raw catalog cache bytes when the cache +// exists and is fresh, honouring the K6_PROVISION_CATALOG_TTL override. A miss +// (absent or stale cache) returns (nil, nil); real I/O failures return an +// error so the caller can surface them at debug. +func readCachedCatalogBytes(gs *state.GlobalState, cachePath string) ([]byte, error) { + maxAge := 24 * time.Hour + if d, err := time.ParseDuration(gs.Env[state.ProvisionCatalogTTL]); err == nil { + maxAge = d + } + info, err := gs.FS.Stat(cachePath) + if errors.Is(err, fs.ErrNotExist) { + return nil, nil + } + if err != nil { + return nil, fmt.Errorf("checking extensions cache: %w", err) + } + if time.Since(info.ModTime()) > maxAge { + return nil, nil + } + raw, err := fsext.ReadFile(gs.FS, cachePath) + if err != nil { + return nil, fmt.Errorf("reading extensions cache: %w", err) + } + return raw, nil +} + +// fetchCatalogBytes downloads the catalog exactly as `k6 x` does, honouring the +// K6_PROVISION_CATALOG_URL override, and writes the fresh bytes to the cache. +func fetchCatalogBytes(ctx context.Context, gs *state.GlobalState, cachePath string) ([]byte, error) { + _, raw, err := fetchCatalog(ctx, catalogURL(gs)) + if err != nil { + return nil, err + } + if err := writeCachedCatalog(gs, cachePath, raw); err != nil { + gs.Logger.WithError(err).Debug("k6 extension catalog") + } + return raw, nil +} + +// parseCatalogModulePaths reads the per-entry "module" field the +// registrySubcommands decoder drops, collecting each catalog entry's Go module +// path into a set. Entries without a module path are skipped. +func parseCatalogModulePaths(raw []byte) map[string]struct{} { + var catalog map[string]struct { + Module string `json:"module"` + } + if err := json.Unmarshal(raw, &catalog); err != nil { + return nil + } + paths := make(map[string]struct{}, len(catalog)) + for _, e := range catalog { + if e.Module != "" { + paths[e.Module] = struct{}{} + } + } + return paths +} + // writeCachedCatalog persists raw catalog bytes under cachePath, creating any // missing parent directories. func writeCachedCatalog(gs *state.GlobalState, cachePath string, raw []byte) error { diff --git a/internal/usage/usage.go b/internal/usage/usage.go index 78d2539b3..fb14d3e94 100644 --- a/internal/usage/usage.go +++ b/internal/usage/usage.go @@ -45,6 +45,30 @@ func (u *Usage) Strings(originalKey, value string) error { return nil } +// Values appends the provided value to a slice of values that is the value, +// like Strings but for arbitrary values, so callers can record structured usage +// without Usage knowing their types. It also works out level of keys. +func (u *Usage) Values(originalKey string, value any) error { + u.l.Lock() + defer u.l.Unlock() + m, newKey, err := u.createLevel(originalKey) + if err != nil { + return err + } + oldV, ok := m[newKey] + if !ok { + m[newKey] = []any{value} + return nil + } + switch oldValue := oldV.(type) { + case []any: + m[newKey] = append(oldValue, value) + default: + return fmt.Errorf("value of key %s is not []any as expected but %T", originalKey, oldValue) + } + return nil +} + // Uint64 adds the provided value to a given key. Creating the key if needed and working out levels of keys func (u *Usage) Uint64(originalKey string, value uint64) error { u.l.Lock() diff --git a/js/modules/resolution.go b/js/modules/resolution.go index aa54e87f5..5b9488f5e 100644 --- a/js/modules/resolution.go +++ b/js/modules/resolution.go @@ -11,6 +11,7 @@ import ( "github.com/grafana/sobek/ast" "github.com/sirupsen/logrus" + "go.k6.io/k6/v2/ext" "go.k6.io/k6/v2/internal/js/compiler" "go.k6.io/k6/v2/internal/loader" "go.k6.io/k6/v2/internal/usage" @@ -78,12 +79,17 @@ func (mr *ModuleResolver) initializeGoModule(name string) (sobek.ModuleRecord, e mr.unknownModules = append(mr.unknownModules, name) return &unknownModule{name: name, requested: make(map[string]struct{})}, nil } - // we don't want to report extensions and we would have hit cache if this isn't the first time - if !strings.HasPrefix(name, "k6/x/") { - err := mr.usage.Strings("modules", name) - if err != nil { - mr.logger.WithError(err).Warnf("Error while reporting usage of module %q", name) + // We would have hit the cache if this isn't the first time, so each distinct + // module is recorded once. An extension is identified by membership in the + // extension registry, not by its k6/x/ name: its resolved registry entry is + // recorded under "extensions" so the report needs no re-resolution, while + // built-in modules stay in the "modules" bucket. + if e, ok := ext.Get(ext.JSExtension)[name]; ok { + if err := mr.usage.Values("extensions", e); err != nil { + mr.logger.WithError(err).Warnf("Error while reporting usage of extension %q", name) } + } else if err := mr.usage.Strings("modules", name); err != nil { + mr.logger.WithError(err).Warnf("Error while reporting usage of module %q", name) } k6m, ok := mod.(Module) if !ok { From cdb4adce958d1f523c18474159c859a02af8fe32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 3 Jul 2026 13:42:53 -0400 Subject: [PATCH 062/182] Cover imported extension reported once per module The usage report must not list the same extension multiple times when many VUs import it. This adds a --vus 5 --iterations 5 acceptance row asserting a module imported across VUs yields exactly one js entry, locking in the per-(module,kind) de-duplication done at report assembly. --- internal/cmd/tests/cmd_run_report_test.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/internal/cmd/tests/cmd_run_report_test.go b/internal/cmd/tests/cmd_run_report_test.go index 64604ed37..e9e9234e7 100644 --- a/internal/cmd/tests/cmd_run_report_test.go +++ b/internal/cmd/tests/cmd_run_report_test.go @@ -62,6 +62,7 @@ func TestRunReportsExtensions(t *testing.T) { tt := []struct { name string + args []string script string catalog string wantExtensions []map[string]any @@ -82,6 +83,19 @@ func TestRunReportsExtensions(t *testing.T) { }, }, }, + { + name: "module imported by many VUs is reported once", + args: []string{"--vus", "5", "--iterations", "5"}, + script: `import "k6/x/testimport"; export default function() {};`, + catalog: `{"k6/x/testimport": {"module":"` + testImportModule + `"}}`, + wantExtensions: []map[string]any{ + { + "module": testImportModule, + "version": ext.Get(ext.JSExtension)["k6/x/testimport"].Version, + "kind": "js", + }, + }, + }, { name: "extension not in the catalog is filtered out", script: `import "k6/x/testimport"; import "k6/x/testimport2"; export default function() {};`, @@ -123,7 +137,8 @@ func TestRunReportsExtensions(t *testing.T) { t.Cleanup(catalogServer.Close) ts.Env[state.ProvisionCatalogURL] = catalogServer.URL } - ts.CmdArgs = []string{"k6", "run", "-"} + ts.CmdArgs = append([]string{"k6", "run"}, tc.args...) + ts.CmdArgs = append(ts.CmdArgs, "-") ts.Stdin = bytes.NewBufferString(tc.script) cmd.ExecuteWithGlobalState(ts.GlobalState) From c945958d9eef4bd3dd8c272d4b1b44980b2848ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 3 Jul 2026 13:43:45 -0400 Subject: [PATCH 063/182] Guard each imported extension reported distinctly The usage report must list every imported extension, not collapse distinct modules into one slot. This guards run's reporting so that two extensions in separate Go packages, which resolve to distinct module paths, each surface as their own js entry and survive de-duplication. --- internal/cmd/tests/cmd_run_report_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/internal/cmd/tests/cmd_run_report_test.go b/internal/cmd/tests/cmd_run_report_test.go index e9e9234e7..c54e0bc52 100644 --- a/internal/cmd/tests/cmd_run_report_test.go +++ b/internal/cmd/tests/cmd_run_report_test.go @@ -96,6 +96,23 @@ func TestRunReportsExtensions(t *testing.T) { }, }, }, + { + name: "distinct imported extensions are each reported", + script: `import "k6/x/testimport"; import "k6/x/testimport2"; export default function() {};`, + catalog: `{"k6/x/testimport": {"module":"` + testImportModule + `"},"k6/x/testimport2": {"module":"` + testImportModule2 + `"}}`, + wantExtensions: []map[string]any{ + { + "module": testImportModule, + "version": ext.Get(ext.JSExtension)["k6/x/testimport"].Version, + "kind": "js", + }, + { + "module": testImportModule2, + "version": ext.Get(ext.JSExtension)["k6/x/testimport2"].Version, + "kind": "js", + }, + }, + }, { name: "extension not in the catalog is filtered out", script: `import "k6/x/testimport"; import "k6/x/testimport2"; export default function() {};`, From c59e36ea71327217cfa6271ecf90aca245e33e62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 3 Jul 2026 13:44:28 -0400 Subject: [PATCH 064/182] Cover extensions key omitted when none are used An empty or fully filtered extensions result omits the key entirely, consistent with how modules behaves, so key presence always means at least one catalogued extension was used. Nothing pinned that. This adds a row asserting a run that uses no extension produces no extensions key rather than an empty array. --- internal/cmd/tests/cmd_run_report_test.go | 27 ++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/internal/cmd/tests/cmd_run_report_test.go b/internal/cmd/tests/cmd_run_report_test.go index c54e0bc52..5d6ba5766 100644 --- a/internal/cmd/tests/cmd_run_report_test.go +++ b/internal/cmd/tests/cmd_run_report_test.go @@ -61,16 +61,23 @@ func TestRunReportsExtensions(t *testing.T) { registerRunReportTestExtensions(t) tt := []struct { - name string - args []string - script string - catalog string - wantExtensions []map[string]any + name string + args []string + script string + catalog string + wantExtensions []map[string]any + wantNoExtensionsKey bool }{ { name: "sends the usage report to the configured endpoint", script: `export default function() {};`, }, + { + name: "compiled but unused extension omits the extensions key", + script: `export default function() {};`, + catalog: `{"k6/x/testimport": {"module":"` + testImportModule + `"}}`, + wantNoExtensionsKey: true, + }, { name: "used public import is reported", script: `import "k6/x/testimport"; export default function() {};`, @@ -162,6 +169,16 @@ func TestRunReportsExtensions(t *testing.T) { require.True(t, reported.Load(), "expected the usage report to reach the configured endpoint") + if tc.wantNoExtensionsKey { + raw, ok := gotBody.Load().([]byte) + require.True(t, ok, "expected a report body") + var report map[string]json.RawMessage + require.NoError(t, json.Unmarshal(raw, &report)) + _, present := report["extensions"] + require.False(t, present, "expected no extensions key when nothing catalogued was used") + return + } + if tc.wantExtensions == nil { return } From e481f3aa61ef369ff9e1280936e9ffc81a28cec6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 3 Jul 2026 13:45:09 -0400 Subject: [PATCH 065/182] Guard extension match against import-name reuse The report filter keys on Go module path, but nothing pinned that a private fork reusing a public import name resolves to its own path and is dropped. A guard row now imports an in-tree fork registered under a catalogued import name while the catalog advertises only the real extension's path; the fork's distinct module path keeps it out of the report, so the row fails if matching ever regresses to import names. --- internal/cmd/tests/cmd_run_report_test.go | 11 +++++++++++ internal/cmd/tests/testfork/testfork.go | 23 +++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 internal/cmd/tests/testfork/testfork.go diff --git a/internal/cmd/tests/cmd_run_report_test.go b/internal/cmd/tests/cmd_run_report_test.go index 5d6ba5766..bf568863f 100644 --- a/internal/cmd/tests/cmd_run_report_test.go +++ b/internal/cmd/tests/cmd_run_report_test.go @@ -15,6 +15,7 @@ import ( "go.k6.io/k6/v2/cmd/state" "go.k6.io/k6/v2/ext" "go.k6.io/k6/v2/internal/cmd" + "go.k6.io/k6/v2/internal/cmd/tests/testfork" "go.k6.io/k6/v2/internal/cmd/tests/testimport2" "go.k6.io/k6/v2/js/modules" ) @@ -52,6 +53,7 @@ func registerRunReportTestExtensions(t *testing.T) { registerRunReportTestExtensionsOnce.Do(func() { modules.Register("k6/x/testimport", &runReportTestModule{}) modules.Register("k6/x/testimport2", &testimport2.Module{}) + modules.Register("k6/x/testfork", &testfork.Module{}) }) } @@ -132,6 +134,15 @@ func TestRunReportsExtensions(t *testing.T) { }, }, }, + { + // The catalog lists the real extension's module path for this import + // name, but the imported fork resolves to its own path, so matching + // by module path drops it. + name: "private fork reusing a public import name is dropped", + script: `import "k6/x/testfork"; export default function() {};`, + catalog: `{"k6/x/testfork": {"module":"` + testImportModule + `"}}`, + wantNoExtensionsKey: true, + }, } for _, tc := range tt { diff --git a/internal/cmd/tests/testfork/testfork.go b/internal/cmd/tests/testfork/testfork.go new file mode 100644 index 000000000..70840efe1 --- /dev/null +++ b/internal/cmd/tests/testfork/testfork.go @@ -0,0 +1,23 @@ +// Package testfork hosts an in-tree JS module type in its own Go package so it +// resolves to a distinct module path from the k6/x/testimport extension. It +// stands in for a private fork registered under a public import name: the +// catalog advertises the real extension's module path for that name, while this +// fork resolves to its own path, so matching by module path drops it. +package testfork + +import "go.k6.io/k6/v2/js/modules" + +// Module is a no-op JS module used only to register a fork extension whose +// module path differs from the catalogued one. +type Module struct{} + +// NewModuleInstance implements modules.Module. +func (*Module) NewModuleInstance(_ modules.VU) modules.Instance { + return &instance{} +} + +type instance struct{} + +func (*instance) Exports() modules.Exports { + return modules.Exports{Named: map[string]any{}} +} From 47b8211b99b4567b69ee4c4b09b552611c7a3993 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 3 Jul 2026 13:45:41 -0400 Subject: [PATCH 066/182] Cover fail-closed report on catalog outage catalogModulePaths returns nothing when the catalog cannot be fetched and resolveExtensions drops the raw bucket before consulting it, so an unreachable catalog with no cache reports no extensions instead of leaking the unfiltered list. Nothing pinned that. This adds a row importing a used extension against an unreachable catalog, asserting the report carries no extensions and the run still exits 0. --- internal/cmd/tests/cmd_run_report_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/internal/cmd/tests/cmd_run_report_test.go b/internal/cmd/tests/cmd_run_report_test.go index bf568863f..c7c88209b 100644 --- a/internal/cmd/tests/cmd_run_report_test.go +++ b/internal/cmd/tests/cmd_run_report_test.go @@ -67,6 +67,7 @@ func TestRunReportsExtensions(t *testing.T) { args []string script string catalog string + unreachableCatalog bool wantExtensions []map[string]any wantNoExtensionsKey bool }{ @@ -143,6 +144,15 @@ func TestRunReportsExtensions(t *testing.T) { catalog: `{"k6/x/testfork": {"module":"` + testImportModule + `"}}`, wantNoExtensionsKey: true, }, + { + // An unreachable catalog with no cache must fail closed: report no + // extensions rather than leak the unfiltered import, and never fail + // the run. + name: "unreachable catalog reports nothing", + script: `import "k6/x/testimport"; export default function() {};`, + unreachableCatalog: true, + wantNoExtensionsKey: true, + }, } for _, tc := range tt { @@ -172,6 +182,12 @@ func TestRunReportsExtensions(t *testing.T) { t.Cleanup(catalogServer.Close) ts.Env[state.ProvisionCatalogURL] = catalogServer.URL } + if tc.unreachableCatalog { + // Close the server immediately so its URL refuses connections. + catalogServer := httptest.NewServer(http.HandlerFunc(func(http.ResponseWriter, *http.Request) {})) + catalogServer.Close() + ts.Env[state.ProvisionCatalogURL] = catalogServer.URL + } ts.CmdArgs = append([]string{"k6", "run"}, tc.args...) ts.CmdArgs = append(ts.CmdArgs, "-") ts.Stdin = bytes.NewBufferString(tc.script) From 67dbf0366c69fe7b244f72dfcbc7304452e6dafd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 3 Jul 2026 13:46:09 -0400 Subject: [PATCH 067/182] Cover run opt-out suppressing extension data The usage report gained a catalog fetch and extension enrichment. This guards that the existing K6_NO_USAGE_REPORT opt-out still gates all of it: with the opt-out set, neither the report endpoint nor the catalog server is contacted, so no new opt-out is needed and none of the added work runs ahead of the gate. --- internal/cmd/tests/cmd_run_report_test.go | 24 ++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/internal/cmd/tests/cmd_run_report_test.go b/internal/cmd/tests/cmd_run_report_test.go index c7c88209b..42130512f 100644 --- a/internal/cmd/tests/cmd_run_report_test.go +++ b/internal/cmd/tests/cmd_run_report_test.go @@ -68,6 +68,7 @@ func TestRunReportsExtensions(t *testing.T) { script string catalog string unreachableCatalog bool + optOut bool wantExtensions []map[string]any wantNoExtensionsKey bool }{ @@ -153,6 +154,14 @@ func TestRunReportsExtensions(t *testing.T) { unreachableCatalog: true, wantNoExtensionsKey: true, }, + { + // The existing opt-out gates the whole report, so neither the report + // endpoint nor the catalog is consulted. + name: "opt-out suppresses the report and catalog fetch", + script: `import "k6/x/testimport"; export default function() {};`, + catalog: `{"k6/x/testimport": {"module":"` + testImportModule + `"}}`, + optOut: true, + }, } for _, tc := range tt { @@ -171,11 +180,18 @@ func TestRunReportsExtensions(t *testing.T) { })) t.Cleanup(reportServer.Close) + var catalogHit atomic.Bool + ts := NewGlobalTestState(t) - ts.Env["K6_NO_USAGE_REPORT"] = "false" + if tc.optOut { + ts.Env["K6_NO_USAGE_REPORT"] = "true" + } else { + ts.Env["K6_NO_USAGE_REPORT"] = "false" + } ts.Env[state.UsageReportURL] = reportServer.URL if tc.catalog != "" { catalogServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + catalogHit.Store(true) w.Header().Set("Content-Type", "application/json") _, _ = w.Write([]byte(tc.catalog)) })) @@ -194,6 +210,12 @@ func TestRunReportsExtensions(t *testing.T) { cmd.ExecuteWithGlobalState(ts.GlobalState) + if tc.optOut { + require.False(t, reported.Load(), "expected the opt-out to suppress the usage report") + require.False(t, catalogHit.Load(), "expected the opt-out to suppress the catalog fetch") + return + } + require.True(t, reported.Load(), "expected the usage report to reach the configured endpoint") if tc.wantNoExtensionsKey { From 0c4fa206bb1eab4626e0851f61d458a0419ef5ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 3 Jul 2026 13:46:45 -0400 Subject: [PATCH 068/182] Report selected output extensions Output extensions chosen via --out were tracked only in the built-in outputs list, so catalogued xk6 output extensions never appeared in the usage report. A selected output that is a member of the output registry is now recorded as a resolved registry entry in the shared extensions bucket, so the report filters it by module path like every other surface. Built-in outputs stay out of the bucket. --- internal/cmd/outputs.go | 9 +++++++ internal/cmd/tests/cmd_run_report_test.go | 30 +++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/internal/cmd/outputs.go b/internal/cmd/outputs.go index 9a25a40f1..2645101ed 100644 --- a/internal/cmd/outputs.go +++ b/internal/cmd/outputs.go @@ -152,6 +152,15 @@ func createOutputs( } } + // An output is an extension by membership in the output registry, not by + // its name, so built-in outputs stay out of the "extensions" bucket that + // the usage report filters against the catalog. + if e, isExt := ext.Get(ext.OutputExtension)[outputType]; isExt { + if err := test.preInitState.Usage.Values("extensions", e); err != nil { + gs.Logger.WithError(err).Warnf("Couldn't report usage for output extension %q", outputType) + } + } + params := baseParams params.OutputType = outputType params.ConfigArgument = outputArg diff --git a/internal/cmd/tests/cmd_run_report_test.go b/internal/cmd/tests/cmd_run_report_test.go index 42130512f..be96eee97 100644 --- a/internal/cmd/tests/cmd_run_report_test.go +++ b/internal/cmd/tests/cmd_run_report_test.go @@ -18,6 +18,8 @@ import ( "go.k6.io/k6/v2/internal/cmd/tests/testfork" "go.k6.io/k6/v2/internal/cmd/tests/testimport2" "go.k6.io/k6/v2/js/modules" + "go.k6.io/k6/v2/metrics" + "go.k6.io/k6/v2/output" ) // testImportModule is the resolved module path of the in-tree k6/x/testimport @@ -31,6 +33,20 @@ const testImportModule = "go.k6.io/k6/v2/internal/cmd/tests" // distinct path from testImportModule. const testImportModule2 = "go.k6.io/k6/v2/internal/cmd/tests/testimport2" +// newReportTestOutput is the output extension constructor registered under the +// "testoutput" name. Its resolved module path is the runtime name of this +// function, read back via ext.Get(ext.OutputExtension)["testoutput"].Path. +func newReportTestOutput(output.Params) (output.Output, error) { + return reportTestOutput{}, nil +} + +type reportTestOutput struct{} + +func (reportTestOutput) Description() string { return "testoutput" } +func (reportTestOutput) Start() error { return nil } +func (reportTestOutput) AddMetricSamples([]metrics.SampleContainer) {} +func (reportTestOutput) Stop() error { return nil } + type runReportTestModule struct{} func (*runReportTestModule) NewModuleInstance(_ modules.VU) modules.Instance { @@ -54,6 +70,7 @@ func registerRunReportTestExtensions(t *testing.T) { modules.Register("k6/x/testimport", &runReportTestModule{}) modules.Register("k6/x/testimport2", &testimport2.Module{}) modules.Register("k6/x/testfork", &testfork.Module{}) + output.RegisterExtension("testoutput", newReportTestOutput) }) } @@ -124,6 +141,19 @@ func TestRunReportsExtensions(t *testing.T) { }, }, }, + { + name: "selected output extension is reported", + args: []string{"--out", "testoutput"}, + script: `export default function() {};`, + catalog: `{"testoutput": {"module":"` + ext.Get(ext.OutputExtension)["testoutput"].Path + `"}}`, + wantExtensions: []map[string]any{ + { + "module": ext.Get(ext.OutputExtension)["testoutput"].Path, + "version": ext.Get(ext.OutputExtension)["testoutput"].Version, + "kind": "output", + }, + }, + }, { name: "extension not in the catalog is filtered out", script: `import "k6/x/testimport"; import "k6/x/testimport2"; export default function() {};`, From 05a167298e1cb99764d05f9d23dfc6fbd6f97f96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 3 Jul 2026 13:47:24 -0400 Subject: [PATCH 069/182] Guard outputs flow through the catalog filter The output extension bucket shared the same catalog filter as JS imports, but nothing pinned that behavior. This adds a test row proving a used output extension absent from the catalog is dropped from the usage report, so a future change that routes outputs around the filter fails loudly. --- internal/cmd/tests/cmd_run_report_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/internal/cmd/tests/cmd_run_report_test.go b/internal/cmd/tests/cmd_run_report_test.go index be96eee97..0817d3773 100644 --- a/internal/cmd/tests/cmd_run_report_test.go +++ b/internal/cmd/tests/cmd_run_report_test.go @@ -154,6 +154,15 @@ func TestRunReportsExtensions(t *testing.T) { }, }, }, + { + // The output extension is used but its module path is absent from the + // catalog, so the shared filter must drop it just like a JS import. + name: "output extension not in the catalog is dropped", + args: []string{"--out", "testoutput"}, + script: `export default function() {};`, + catalog: `{"k6/x/testimport": {"module":"` + testImportModule + `"}}`, + wantNoExtensionsKey: true, + }, { name: "extension not in the catalog is filtered out", script: `import "k6/x/testimport"; import "k6/x/testimport2"; export default function() {};`, From f9cf33bc8639d30c28f9308ceedbb526bb83a10d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 3 Jul 2026 13:47:58 -0400 Subject: [PATCH 070/182] Guard built-in outputs stay out of extensions Extension usage recording keys the extensions bucket on output-registry membership, so built-in outputs like json were never reported as extensions. Without a test, a future change could broaden recording to all outputs and start leaking built-ins. This guards that json stays listed under outputs and never produces an output-kind extension entry. --- internal/cmd/tests/cmd_run_report_test.go | 25 +++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/internal/cmd/tests/cmd_run_report_test.go b/internal/cmd/tests/cmd_run_report_test.go index 0817d3773..a9dbb72de 100644 --- a/internal/cmd/tests/cmd_run_report_test.go +++ b/internal/cmd/tests/cmd_run_report_test.go @@ -88,6 +88,7 @@ func TestRunReportsExtensions(t *testing.T) { optOut bool wantExtensions []map[string]any wantNoExtensionsKey bool + wantOutputs []any }{ { name: "sends the usage report to the configured endpoint", @@ -154,6 +155,16 @@ func TestRunReportsExtensions(t *testing.T) { }, }, }, + { + // A built-in output is classified by the built-in output enum and never + // enters the extensions bucket, so it is absent from "extensions" yet + // still listed under "outputs". + name: "built-in output is not an extension", + args: []string{"--out", "json"}, + script: `export default function() {};`, + wantNoExtensionsKey: true, + wantOutputs: []any{"json"}, + }, { // The output extension is used but its module path is absent from the // catalog, so the shared filter must drop it just like a JS import. @@ -257,6 +268,20 @@ func TestRunReportsExtensions(t *testing.T) { require.True(t, reported.Load(), "expected the usage report to reach the configured endpoint") + if tc.wantOutputs != nil { + raw, ok := gotBody.Load().([]byte) + require.True(t, ok, "expected a report body") + var report struct { + Outputs []any `json:"outputs"` + Extensions []map[string]any `json:"extensions"` + } + require.NoError(t, json.Unmarshal(raw, &report)) + require.Equal(t, tc.wantOutputs, report.Outputs, "expected the built-in output to stay listed under outputs") + for _, e := range report.Extensions { + require.NotEqual(t, "output", e["kind"], "expected no output-kind extension entry for a built-in output") + } + } + if tc.wantNoExtensionsKey { raw, ok := gotBody.Load().([]byte) require.True(t, ok, "expected a report body") From 2bb26bc3d2af94faebd039612204b8065e1eef3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 3 Jul 2026 13:49:00 -0400 Subject: [PATCH 071/182] Report subcommand extension usage Baked-in subcommands invoked via `k6 x` sent no usage telemetry, so the extension registry had no signal about their use. The root execute seam now reports once after the command runs, using cobra's ExecuteC to recover the command that ran and its error, so a registered subcommand extension is reported whether it succeeds or fails, through the shared usage-report transport. It carries only the run-independent identifying fields and the catalogued extension entry, bounded and non-fatal so it never fails or delays the command, and the command's own hook is left untouched. --- internal/cmd/report.go | 62 ++++++++-- internal/cmd/root.go | 6 +- internal/cmd/run.go | 12 +- internal/cmd/subcommand.go | 22 ++++ .../cmd/tests/cmd_subcommand_report_test.go | 110 ++++++++++++++++++ 5 files changed, 195 insertions(+), 17 deletions(-) create mode 100644 internal/cmd/tests/cmd_subcommand_report_test.go diff --git a/internal/cmd/report.go b/internal/cmd/report.go index 983e497db..1afec2b91 100644 --- a/internal/cmd/report.go +++ b/internal/cmd/report.go @@ -7,6 +7,7 @@ import ( "net/http" "runtime" "strconv" + "time" "go.k6.io/k6/v2/cmd/state" "go.k6.io/k6/v2/ext" @@ -32,14 +33,35 @@ func newExtensionEntry(e *ext.Extension) extensionEntry { } } +// envLookup adapts an environment map to the lookup-function shape the report +// helpers share with the run path's LookupEnv. +func envLookup(env map[string]string) func(string) (string, bool) { + return func(key string) (string, bool) { + val, ok := env[key] + return val, ok + } +} + +// addEnvironmentInfo stamps the fields identifying this k6 binary and where it +// runs. Both the run report and the subcommand report carry them. +func addEnvironmentInfo(m map[string]any, lookupEnv func(string) (string, bool)) { + m["k6_version"] = build.Version + m["goos"] = runtime.GOOS + m["goarch"] = runtime.GOARCH + m["is_ci"] = isCI(lookupEnv) +} + +// createReport assembles the anonymous usage report for a run from its +// scheduler and recorded usage, keeping only the used extensions advertised in +// the public catalog. It is the run report k6 has always sent, with the +// extensions field added. func createReport(u *usage.Usage, execScheduler *execution.Scheduler, catalog map[string]struct{}) map[string]any { execState := execScheduler.GetState() m := u.Map() - m["k6_version"] = build.Version + addEnvironmentInfo(m, execState.Test.LookupEnv) + m["duration"] = execState.GetCurrentTestRunDuration().String() - m["goos"] = runtime.GOOS - m["goarch"] = runtime.GOARCH m["vus_max"] = uint64(execState.GetInitializedVUsCount()) //nolint:gosec m["iterations"] = execState.GetFullIterationCount() executors := make(map[string]int) @@ -47,13 +69,25 @@ func createReport(u *usage.Usage, execScheduler *execution.Scheduler, catalog ma executors[ec.GetType()]++ } m["executors"] = executors - m["is_ci"] = isCI(execState.Test.LookupEnv) resolveExtensions(m, catalog) return m } +// createSubcommandReport builds the usage report for an invoked subcommand +// extension. A subcommand is not a load test, so it reports the identity fields +// and the used extension without the run summary that createReport derives from +// a scheduler. +func createSubcommandReport(ctx context.Context, gs *state.GlobalState, extension *ext.Extension) map[string]any { + m := make(map[string]any) + addEnvironmentInfo(m, envLookup(gs.Env)) + m["extensions"] = []any{extension} + resolveExtensions(m, catalogModulePaths(ctx, gs)) + + return m +} + // resolveExtensions replaces the used extensions recorded under "extensions" in // usage with report entries, keeping only those advertised in the public // catalog. Fail closed: dropping the raw list first means an empty catalog @@ -94,19 +128,33 @@ func filterExtensions(used []any, public map[string]struct{}) []extensionEntry { return entries } +// reportUsage sends the report built by create, logging the attempt and outcome +// at debug, all bounded by a timeout. Both k6 run and k6 x call it; whether to +// run it in the background is the caller's concern, not the pipeline's. +func reportUsage(ctx context.Context, gs *state.GlobalState, create func(ctx context.Context) map[string]any) { + reportCtx, cancel := context.WithTimeout(ctx, 3*time.Second) + defer cancel() + + gs.Logger.Debug("Sending usage report...") + if err := postUsageReport(reportCtx, envLookup(gs.Env), create(reportCtx)); err != nil { + gs.Logger.WithError(err).Debug("Error sending usage report") + } else { + gs.Logger.Debug("Usage report sent successfully") + } +} + // defaultUsageReportURL is the production endpoint the anonymous usage report // is sent to when K6_USAGE_REPORT_URL is not set. const defaultUsageReportURL = "https://stats.grafana.org/k6-usage-report" -func reportUsage(ctx context.Context, gs *state.GlobalState, execScheduler *execution.Scheduler, test *loadedAndConfiguredTest) error { - m := createReport(test.preInitState.Usage, execScheduler, catalogModulePaths(ctx, gs)) +func postUsageReport(ctx context.Context, lookupEnv func(string) (string, bool), m map[string]any) error { body, err := json.Marshal(m) if err != nil { return err } usageStatsURL := defaultUsageReportURL - if url, ok := test.preInitState.LookupEnv(state.UsageReportURL); ok && url != "" { + if url, ok := lookupEnv(state.UsageReportURL); ok && url != "" { usageStatsURL = url } req, err := http.NewRequestWithContext(ctx, http.MethodPost, usageStatsURL, bytes.NewBuffer(body)) diff --git a/internal/cmd/root.go b/internal/cmd/root.go index 380cef6cf..359c5ed91 100644 --- a/internal/cmd/root.go +++ b/internal/cmd/root.go @@ -197,7 +197,11 @@ func (c *rootCommand) execute() { if ext, ok := detectExtensionCompletion(c.cmd, c.globalState); ok { err = completeExtension(c.globalState, ext, newCacheProvisioner(c.globalState)) } else { - err = c.cmd.Execute() + var executed *cobra.Command + executed, err = c.cmd.ExecuteC() + // Report subcommand usage after the command runs, regardless of its exit + // error, so a failed subcommand is still counted. + reportSubcommandUsage(c.globalState, executed) } if err == nil { exitCode = 0 diff --git a/internal/cmd/run.go b/internal/cmd/run.go index 95058cddd..27ee82d41 100644 --- a/internal/cmd/run.go +++ b/internal/cmd/run.go @@ -460,15 +460,9 @@ func (c *cmdRun) run(cmd *cobra.Command, args []string) (err error) { // usage report after the context is done. if !conf.NoUsageReport.Bool { backgroundProcesses.Go(func() { - reportCtx, reportCancel := context.WithTimeout(globalCtx, 3*time.Second) - defer reportCancel() - logger.Debug("Sending usage report...") - - if rerr := reportUsage(reportCtx, c.gs, execScheduler, test); rerr != nil { - logger.WithError(rerr).Debug("Error sending usage report") - } else { - logger.Debug("Usage report sent successfully") - } + reportUsage(globalCtx, c.gs, func(ctx context.Context) map[string]any { + return createReport(test.preInitState.Usage, execScheduler, catalogModulePaths(ctx, c.gs)) + }) }) } diff --git a/internal/cmd/subcommand.go b/internal/cmd/subcommand.go index 4bcc13cd7..d3738b7cd 100644 --- a/internal/cmd/subcommand.go +++ b/internal/cmd/subcommand.go @@ -1,6 +1,7 @@ package cmd import ( + "context" "fmt" "slices" "strings" @@ -82,6 +83,27 @@ Run "k6 x explore" to see the full list of official and community-provided subco return cmd } +// reportSubcommandUsage reports usage for a subcommand extension after it runs. +// It is called with the command cobra actually executed, whether that command +// succeeded or failed, so a subcommand that exits non-zero is still counted. It +// reports only for a name backed by a registered subcommand extension, so the +// catch-all `x` help, `k6 run`, completions, and provisioning stubs are ignored. +func reportSubcommandUsage(gs *state.GlobalState, executed *cobra.Command) { + if executed == nil { + return + } + extension, ok := ext.Get(ext.SubcommandExtension)[executed.Name()] + if !ok { + return + } + if conf, err := readEnvConfig(gs.Env); err != nil || conf.NoUsageReport.Bool { + return + } + reportUsage(gs.Ctx, gs, func(ctx context.Context) map[string]any { + return createSubcommandReport(ctx, gs, extension) + }) +} + // registryStubs returns cobra stubs for registry-advertised subcommands not // already provided by baked-in extensions. The stubs only exist so `k6 x` // help can advertise the wider catalog; invoking one drops into the regular diff --git a/internal/cmd/tests/cmd_subcommand_report_test.go b/internal/cmd/tests/cmd_subcommand_report_test.go new file mode 100644 index 000000000..d359320e1 --- /dev/null +++ b/internal/cmd/tests/cmd_subcommand_report_test.go @@ -0,0 +1,110 @@ +package tests + +import ( + "encoding/json" + "io" + "net/http" + "net/http/httptest" + "sync" + "sync/atomic" + "testing" + + "github.com/spf13/cobra" + "github.com/stretchr/testify/require" + + "go.k6.io/k6/v2/cmd/state" + "go.k6.io/k6/v2/ext" + "go.k6.io/k6/v2/internal/cmd" + "go.k6.io/k6/v2/subcommand" +) + +// registerReportTestSubcommandOnce guards process-global ext.Register, which +// panics on a duplicate name/type. +var registerReportTestSubcommandOnce sync.Once //nolint:gochecknoglobals + +func registerReportTestSubcommand(t *testing.T) { + t.Helper() + + registerReportTestSubcommandOnce.Do(func() { + subcommand.RegisterExtension("testsub", func(*state.GlobalState) *cobra.Command { + return &cobra.Command{ + Use: "testsub", + Run: func(*cobra.Command, []string) {}, + } + }) + }) +} + +func TestSubcommandReportsUsage(t *testing.T) { + t.Parallel() + + registerReportTestSubcommand(t) + + // The subcommand constructor is an in-tree func, so its resolved module path + // is the constructor's runtime name in this test package. + testSubModule := ext.Get(ext.SubcommandExtension)["testsub"].Path + + tt := []struct { + name string + args []string + catalog string + wantExtensions []map[string]any + }{ + { + name: "catalogued subcommand run is reported", + args: []string{"x", "testsub"}, + catalog: `{"testsub": {"subcommands":["testsub"],"module":"` + testSubModule + `"}}`, + wantExtensions: []map[string]any{ + { + "module": testSubModule, + "version": ext.Get(ext.SubcommandExtension)["testsub"].Version, + "kind": "subcommand", + }, + }, + }, + } + + for _, tc := range tt { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + + var reportCount atomic.Int32 + var gotBody atomic.Value + reportServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method == http.MethodPost { + body, _ := io.ReadAll(r.Body) + gotBody.Store(body) + reportCount.Add(1) + } + w.WriteHeader(http.StatusOK) + })) + t.Cleanup(reportServer.Close) + + ts := NewGlobalTestState(t) + ts.Env["K6_NO_USAGE_REPORT"] = "false" + ts.Env[state.UsageReportURL] = reportServer.URL + if tc.catalog != "" { + catalogServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + w.Header().Set("Content-Type", "application/json") + _, _ = w.Write([]byte(tc.catalog)) + })) + t.Cleanup(catalogServer.Close) + ts.Env[state.ProvisionCatalogURL] = catalogServer.URL + } + ts.CmdArgs = append([]string{"k6"}, tc.args...) + ts.ReparseFlags() + + cmd.ExecuteWithGlobalState(ts.GlobalState) + + require.Equal(t, int32(1), reportCount.Load(), "expected exactly one usage report") + + raw, ok := gotBody.Load().([]byte) + require.True(t, ok, "expected a report body") + var report struct { + Extensions []map[string]any `json:"extensions"` + } + require.NoError(t, json.Unmarshal(raw, &report)) + require.ElementsMatch(t, tc.wantExtensions, report.Extensions) + }) + } +} From 32edebf553dc9b29b74dad4d60ab190286be998d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 3 Jul 2026 13:49:51 -0400 Subject: [PATCH 072/182] Cover private subcommands dropped from the report createSubcommandReport keeps a subcommand's entry only when its module path appears in the public catalog, matching the run path's filter. Nothing pinned that. This adds a row running a baked-in subcommand whose module path the catalog omits, asserting the report carries no entry for it. --- internal/cmd/tests/cmd_subcommand_report_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/cmd/tests/cmd_subcommand_report_test.go b/internal/cmd/tests/cmd_subcommand_report_test.go index d359320e1..67b1ef1a7 100644 --- a/internal/cmd/tests/cmd_subcommand_report_test.go +++ b/internal/cmd/tests/cmd_subcommand_report_test.go @@ -62,6 +62,12 @@ func TestSubcommandReportsUsage(t *testing.T) { }, }, }, + { + name: "subcommand absent from catalog is dropped", + args: []string{"x", "testsub"}, + catalog: `{"other": {"subcommands":["other"],"module":"example.com/x-other"}}`, + wantExtensions: nil, + }, } for _, tc := range tt { From d65de325028024c70eac90d146de08c2730ebb18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 3 Jul 2026 13:50:29 -0400 Subject: [PATCH 073/182] Guard unknown subcommands are never reported Before, nothing guarded against a usage report firing for a subcommand name the binary does not provide. This adds a guard: running k6 x with an unregistered name against an unreachable catalog builds no command and sends no report, so an early or stray report call would now be caught. --- .../cmd/tests/cmd_subcommand_report_test.go | 42 +++++++++++++++++-- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/internal/cmd/tests/cmd_subcommand_report_test.go b/internal/cmd/tests/cmd_subcommand_report_test.go index 67b1ef1a7..b3a32626a 100644 --- a/internal/cmd/tests/cmd_subcommand_report_test.go +++ b/internal/cmd/tests/cmd_subcommand_report_test.go @@ -13,6 +13,7 @@ import ( "github.com/stretchr/testify/require" "go.k6.io/k6/v2/cmd/state" + "go.k6.io/k6/v2/errext/exitcodes" "go.k6.io/k6/v2/ext" "go.k6.io/k6/v2/internal/cmd" "go.k6.io/k6/v2/subcommand" @@ -45,10 +46,13 @@ func TestSubcommandReportsUsage(t *testing.T) { testSubModule := ext.Get(ext.SubcommandExtension)["testsub"].Path tt := []struct { - name string - args []string - catalog string - wantExtensions []map[string]any + name string + args []string + catalog string + unreachableCatalog bool + wantNoReport bool + wantExitCode int + wantExtensions []map[string]any }{ { name: "catalogued subcommand run is reported", @@ -68,6 +72,16 @@ func TestSubcommandReportsUsage(t *testing.T) { catalog: `{"other": {"subcommands":["other"],"module":"example.com/x-other"}}`, wantExtensions: nil, }, + { + // An unregistered name cannot be provisioned from an unreachable + // catalog, so the host builds no command for it and the wrapped hook + // never runs. Neither the report endpoint nor the catalog is consulted. + name: "unknown subcommand is not reported", + args: []string{"x", "not-a-catalog-name"}, + unreachableCatalog: true, + wantNoReport: true, + wantExitCode: int(exitcodes.ScriptException), + }, } for _, tc := range tt { @@ -86,22 +100,42 @@ func TestSubcommandReportsUsage(t *testing.T) { })) t.Cleanup(reportServer.Close) + var catalogHit atomic.Bool + ts := NewGlobalTestState(t) ts.Env["K6_NO_USAGE_REPORT"] = "false" ts.Env[state.UsageReportURL] = reportServer.URL if tc.catalog != "" { catalogServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + catalogHit.Store(true) w.Header().Set("Content-Type", "application/json") _, _ = w.Write([]byte(tc.catalog)) })) t.Cleanup(catalogServer.Close) ts.Env[state.ProvisionCatalogURL] = catalogServer.URL } + if tc.unreachableCatalog { + // Close the server immediately so its URL refuses connections. + catalogServer := httptest.NewServer(http.HandlerFunc(func(http.ResponseWriter, *http.Request) { + catalogHit.Store(true) + })) + catalogServer.Close() + ts.Env[state.ProvisionCatalogURL] = catalogServer.URL + // Keep the provisioning attempt off the real build service. + ts.Env["K6_BUILD_SERVICE_URL"] = "http://127.0.0.1:1/unreachable" + } + ts.ExpectedExitCode = tc.wantExitCode ts.CmdArgs = append([]string{"k6"}, tc.args...) ts.ReparseFlags() cmd.ExecuteWithGlobalState(ts.GlobalState) + if tc.wantNoReport { + require.Equal(t, int32(0), reportCount.Load(), "expected no usage report for an unknown subcommand") + require.False(t, catalogHit.Load(), "expected no catalog request for an unknown subcommand") + return + } + require.Equal(t, int32(1), reportCount.Load(), "expected exactly one usage report") raw, ok := gotBody.Load().([]byte) From c13a7858ff5d72d753e94c350219f5f2bce47fbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 3 Jul 2026 13:51:08 -0400 Subject: [PATCH 074/182] Cover the bounded send on a slow endpoint The subcommand report rides the shared bounded, non-fatal send, so a slow or unreachable endpoint cannot stall or fail k6 x. Nothing pinned that. This adds a row proving the send is abandoned within the bounded run-report timeout, the command still exits 0 with no surfaced error, and the failure surfaces only as a debug-level log. --- .../cmd/tests/cmd_subcommand_report_test.go | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/internal/cmd/tests/cmd_subcommand_report_test.go b/internal/cmd/tests/cmd_subcommand_report_test.go index b3a32626a..92734fff1 100644 --- a/internal/cmd/tests/cmd_subcommand_report_test.go +++ b/internal/cmd/tests/cmd_subcommand_report_test.go @@ -8,7 +8,9 @@ import ( "sync" "sync/atomic" "testing" + "time" + "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/stretchr/testify/require" @@ -16,6 +18,7 @@ import ( "go.k6.io/k6/v2/errext/exitcodes" "go.k6.io/k6/v2/ext" "go.k6.io/k6/v2/internal/cmd" + "go.k6.io/k6/v2/internal/lib/testutils" "go.k6.io/k6/v2/subcommand" ) @@ -50,6 +53,7 @@ func TestSubcommandReportsUsage(t *testing.T) { args []string catalog string unreachableCatalog bool + slowReport bool wantNoReport bool wantExitCode int wantExtensions []map[string]any @@ -82,6 +86,15 @@ func TestSubcommandReportsUsage(t *testing.T) { wantNoReport: true, wantExitCode: int(exitcodes.ScriptException), }, + { + // A slow report endpoint must not delay or fail the command: the send + // is abandoned within the bounded timeout, the command still exits 0, + // and only a debug-level log records the failure. + name: "slow endpoint does not delay or fail the command", + args: []string{"x", "testsub", "-v"}, + catalog: `{"testsub": {"subcommands":["testsub"],"module":"` + testSubModule + `"}}`, + slowReport: true, + }, } for _, tc := range tt { @@ -90,7 +103,17 @@ func TestSubcommandReportsUsage(t *testing.T) { var reportCount atomic.Int32 var gotBody atomic.Value + released := make(chan struct{}) reportServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if tc.slowReport { + // Hang past the bounded timeout so the client abandons the send; + // release only at cleanup to avoid leaking the handler goroutine. + select { + case <-r.Context().Done(): + case <-released: + } + return + } if r.Method == http.MethodPost { body, _ := io.ReadAll(r.Body) gotBody.Store(body) @@ -98,7 +121,9 @@ func TestSubcommandReportsUsage(t *testing.T) { } w.WriteHeader(http.StatusOK) })) + // Release the hung handler before Close waits on it (cleanups run LIFO). t.Cleanup(reportServer.Close) + t.Cleanup(func() { close(released) }) var catalogHit atomic.Bool @@ -128,7 +153,30 @@ func TestSubcommandReportsUsage(t *testing.T) { ts.CmdArgs = append([]string{"k6"}, tc.args...) ts.ReparseFlags() + start := time.Now() cmd.ExecuteWithGlobalState(ts.GlobalState) + elapsed := time.Since(start) + + if tc.slowReport { + // Exit 0 (default, asserted by the harness) with the send abandoned + // within the bounded run-report timeout, surfacing the failure only + // at debug level. + require.Equal(t, int32(0), reportCount.Load(), "expected the slow send to be abandoned") + require.Less(t, elapsed, 10*time.Second, "expected the slow send to be abandoned within the bounded timeout") + + entries := ts.LoggerHook.Drain() + require.True(t, + testutils.LogContains(entries, logrus.DebugLevel, "Error sending usage report"), + "expected a debug-level log for the failed usage report", + ) + for _, e := range entries { + if e.Level < logrus.DebugLevel { + require.NotContains(t, e.Message, "usage report", + "expected the report failure to surface only at debug level") + } + } + return + } if tc.wantNoReport { require.Equal(t, int32(0), reportCount.Load(), "expected no usage report for an unknown subcommand") From b23fe9f25df470ae2a429f54b2756393b9d649f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 3 Jul 2026 13:51:47 -0400 Subject: [PATCH 075/182] Cover subcommand report opt-out with a test Nothing exercised the K6_NO_USAGE_REPORT gate on the k6 x report path, so a regression could re-enable telemetry unnoticed. This adds a table row that runs k6 x under the opt-out and asserts neither the report endpoint nor the catalog is consulted. --- .../cmd/tests/cmd_subcommand_report_test.go | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/internal/cmd/tests/cmd_subcommand_report_test.go b/internal/cmd/tests/cmd_subcommand_report_test.go index 92734fff1..f61bb1c88 100644 --- a/internal/cmd/tests/cmd_subcommand_report_test.go +++ b/internal/cmd/tests/cmd_subcommand_report_test.go @@ -54,6 +54,8 @@ func TestSubcommandReportsUsage(t *testing.T) { catalog string unreachableCatalog bool slowReport bool + optOut bool + autoOff bool wantNoReport bool wantExitCode int wantExtensions []map[string]any @@ -95,6 +97,18 @@ func TestSubcommandReportsUsage(t *testing.T) { catalog: `{"testsub": {"subcommands":["testsub"],"module":"` + testSubModule + `"}}`, slowReport: true, }, + { + // The existing opt-out gates the subcommand report too, so neither the + // report endpoint nor the catalog is consulted by the telemetry path + // even though the wrapped subcommand body still runs. Auto-resolution is + // off so the unrelated `k6 x` stub listing never touches the catalog, + // leaving the report as the only possible catalog consumer. + name: "opt-out suppresses the subcommand report", + args: []string{"x", "testsub"}, + catalog: `{"testsub": {"subcommands":["testsub"],"module":"` + testSubModule + `"}}`, + optOut: true, + autoOff: true, + }, } for _, tc := range tt { @@ -128,7 +142,14 @@ func TestSubcommandReportsUsage(t *testing.T) { var catalogHit atomic.Bool ts := NewGlobalTestState(t) - ts.Env["K6_NO_USAGE_REPORT"] = "false" + if tc.optOut { + ts.Env["K6_NO_USAGE_REPORT"] = "true" + } else { + ts.Env["K6_NO_USAGE_REPORT"] = "false" + } + if tc.autoOff { + ts.Env[state.AutoExtensionResolution] = "false" + } ts.Env[state.UsageReportURL] = reportServer.URL if tc.catalog != "" { catalogServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { @@ -178,6 +199,12 @@ func TestSubcommandReportsUsage(t *testing.T) { return } + if tc.optOut { + require.Equal(t, int32(0), reportCount.Load(), "expected the opt-out to suppress the usage report") + require.False(t, catalogHit.Load(), "expected the opt-out to suppress the catalog fetch") + return + } + if tc.wantNoReport { require.Equal(t, int32(0), reportCount.Load(), "expected no usage report for an unknown subcommand") require.False(t, catalogHit.Load(), "expected no catalog request for an unknown subcommand") From 6c0a92801a39fcc72cfd12917c30363678d7fb40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 Jul 2026 12:12:54 -0400 Subject: [PATCH 076/182] Skip catalog fetch when a run used no extensions Every reported run consulted the extension catalog, fetching it on a cold or stale cache even when the script used no extensions, which is most runs. The fetch also spent part of the bounded report window with nothing to filter. The report step now resolves the catalog lazily, only after finding recorded extension usage, so an extension-less run sends its report without touching the registry. --- internal/cmd/report.go | 17 ++++++++++------- internal/cmd/run.go | 4 +++- internal/cmd/tests/cmd_run_report_test.go | 8 ++++++++ 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/internal/cmd/report.go b/internal/cmd/report.go index 1afec2b91..39f4dad24 100644 --- a/internal/cmd/report.go +++ b/internal/cmd/report.go @@ -55,7 +55,9 @@ func addEnvironmentInfo(m map[string]any, lookupEnv func(string) (string, bool)) // scheduler and recorded usage, keeping only the used extensions advertised in // the public catalog. It is the run report k6 has always sent, with the // extensions field added. -func createReport(u *usage.Usage, execScheduler *execution.Scheduler, catalog map[string]struct{}) map[string]any { +func createReport( + u *usage.Usage, execScheduler *execution.Scheduler, catalog func() map[string]struct{}, +) map[string]any { execState := execScheduler.GetState() m := u.Map() @@ -83,23 +85,24 @@ func createSubcommandReport(ctx context.Context, gs *state.GlobalState, extensio m := make(map[string]any) addEnvironmentInfo(m, envLookup(gs.Env)) m["extensions"] = []any{extension} - resolveExtensions(m, catalogModulePaths(ctx, gs)) + resolveExtensions(m, func() map[string]struct{} { return catalogModulePaths(ctx, gs) }) return m } // resolveExtensions replaces the used extensions recorded under "extensions" in // usage with report entries, keeping only those advertised in the public -// catalog. Fail closed: dropping the raw list first means an empty catalog -// reports no extensions rather than leaking it, and the key stays omitted when -// nothing survives instead of sending []. -func resolveExtensions(m map[string]any, catalog map[string]struct{}) { +// catalog. The catalog func runs only when extensions were recorded, so a run +// that used none never fetches the catalog. Fail closed: dropping the raw list +// first means an empty catalog reports no extensions rather than leaking it, +// and the key stays omitted when nothing survives instead of sending []. +func resolveExtensions(m map[string]any, catalog func() map[string]struct{}) { used, ok := m["extensions"].([]any) if !ok { return } delete(m, "extensions") - if entries := filterExtensions(used, catalog); len(entries) > 0 { + if entries := filterExtensions(used, catalog()); len(entries) > 0 { m["extensions"] = entries } } diff --git a/internal/cmd/run.go b/internal/cmd/run.go index 27ee82d41..b4a095dbb 100644 --- a/internal/cmd/run.go +++ b/internal/cmd/run.go @@ -461,7 +461,9 @@ func (c *cmdRun) run(cmd *cobra.Command, args []string) (err error) { if !conf.NoUsageReport.Bool { backgroundProcesses.Go(func() { reportUsage(globalCtx, c.gs, func(ctx context.Context) map[string]any { - return createReport(test.preInitState.Usage, execScheduler, catalogModulePaths(ctx, c.gs)) + return createReport(test.preInitState.Usage, execScheduler, func() map[string]struct{} { + return catalogModulePaths(ctx, c.gs) + }) }) }) } diff --git a/internal/cmd/tests/cmd_run_report_test.go b/internal/cmd/tests/cmd_run_report_test.go index a9dbb72de..b90d43aea 100644 --- a/internal/cmd/tests/cmd_run_report_test.go +++ b/internal/cmd/tests/cmd_run_report_test.go @@ -88,6 +88,7 @@ func TestRunReportsExtensions(t *testing.T) { optOut bool wantExtensions []map[string]any wantNoExtensionsKey bool + wantNoCatalogFetch bool wantOutputs []any }{ { @@ -95,10 +96,13 @@ func TestRunReportsExtensions(t *testing.T) { script: `export default function() {};`, }, { + // A run that used no extensions has nothing to filter, so the + // catalog must not be consulted at all. name: "compiled but unused extension omits the extensions key", script: `export default function() {};`, catalog: `{"k6/x/testimport": {"module":"` + testImportModule + `"}}`, wantNoExtensionsKey: true, + wantNoCatalogFetch: true, }, { name: "used public import is reported", @@ -268,6 +272,10 @@ func TestRunReportsExtensions(t *testing.T) { require.True(t, reported.Load(), "expected the usage report to reach the configured endpoint") + if tc.wantNoCatalogFetch { + require.False(t, catalogHit.Load(), "expected no catalog fetch when the run used no extensions") + } + if tc.wantOutputs != nil { raw, ok := gotBody.Load().([]byte) require.True(t, ok, "expected a report body") From cfd7b8a064e87d891dec3f55f64923633cb9dc58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 Jul 2026 12:32:22 -0400 Subject: [PATCH 077/182] Report subcommand usage for nested invocations The subcommand report matched the executed command's bare name against the extension registry. cobra returns the deepest command it ran, so an extension invoked through a nested subcommand (k6 x docs search) was never reported, while a builtin sharing a registered extension's name (k6 version) was reported without the extension running. Two of the four catalogued subcommand extensions already nest, so their real usage went uncounted. The report now resolves the extension from the direct child of the root-level x command on the executed command's parent chain: nested invocations count toward their extension, builtins stay unreported, and the catch-all x help and provisioning stubs stay excluded. --- internal/cmd/subcommand.go | 30 +++- .../cmd_subcommand_nested_report_test.go | 162 ++++++++++++++++++ 2 files changed, 186 insertions(+), 6 deletions(-) create mode 100644 internal/cmd/tests/cmd_subcommand_nested_report_test.go diff --git a/internal/cmd/subcommand.go b/internal/cmd/subcommand.go index d3738b7cd..c60be212f 100644 --- a/internal/cmd/subcommand.go +++ b/internal/cmd/subcommand.go @@ -86,13 +86,12 @@ Run "k6 x explore" to see the full list of official and community-provided subco // reportSubcommandUsage reports usage for a subcommand extension after it runs. // It is called with the command cobra actually executed, whether that command // succeeded or failed, so a subcommand that exits non-zero is still counted. It -// reports only for a name backed by a registered subcommand extension, so the -// catch-all `x` help, `k6 run`, completions, and provisioning stubs are ignored. +// reports only for a command backed by a registered subcommand extension, so +// the catch-all `x` help, `k6 run`, builtins sharing an extension's name, +// completions, and provisioning stubs are ignored. A nested invocation +// (`k6 x `) counts toward the extension that owns the child. func reportSubcommandUsage(gs *state.GlobalState, executed *cobra.Command) { - if executed == nil { - return - } - extension, ok := ext.Get(ext.SubcommandExtension)[executed.Name()] + extension, ok := subcommandExtension(executed) if !ok { return } @@ -104,6 +103,25 @@ func reportSubcommandUsage(gs *state.GlobalState, executed *cobra.Command) { }) } +// subcommandExtension resolves the executed command to the registered +// subcommand extension it belongs to: the direct child of the root-level `x` +// command on the executed command's parent chain. Matching by position rather +// than by the executed command's bare name keeps a builtin sharing an +// extension's name unreported and lets a nested invocation count toward its +// extension. cobra returns the deepest command it ran, so the walk climbs from +// there. +func subcommandExtension(executed *cobra.Command) (*ext.Extension, bool) { + for cmd := executed; cmd != nil && cmd.HasParent(); cmd = cmd.Parent() { + parent := cmd.Parent() + if parent.Name() != "x" || parent.Parent() == nil || parent.Parent().HasParent() { + continue + } + extension, ok := ext.Get(ext.SubcommandExtension)[cmd.Name()] + return extension, ok + } + return nil, false +} + // registryStubs returns cobra stubs for registry-advertised subcommands not // already provided by baked-in extensions. The stubs only exist so `k6 x` // help can advertise the wider catalog; invoking one drops into the regular diff --git a/internal/cmd/tests/cmd_subcommand_nested_report_test.go b/internal/cmd/tests/cmd_subcommand_nested_report_test.go new file mode 100644 index 000000000..61fb62cc7 --- /dev/null +++ b/internal/cmd/tests/cmd_subcommand_nested_report_test.go @@ -0,0 +1,162 @@ +package tests + +import ( + "encoding/json" + "io" + "net/http" + "net/http/httptest" + "sync" + "sync/atomic" + "testing" + + "github.com/spf13/cobra" + "github.com/stretchr/testify/require" + + "go.k6.io/k6/v2/cmd/state" + "go.k6.io/k6/v2/ext" + "go.k6.io/k6/v2/internal/cmd" + "go.k6.io/k6/v2/subcommand" +) + +// registerNestedTestSubcommandOnce guards process-global ext.Register, which +// panics on a duplicate name/type. +var registerNestedTestSubcommandOnce sync.Once //nolint:gochecknoglobals + +func registerNestedTestSubcommand(t *testing.T) { + t.Helper() + + registerNestedTestSubcommandOnce.Do(func() { + subcommand.RegisterExtension("testnest", func(*state.GlobalState) *cobra.Command { + root := &cobra.Command{ + Use: "testnest", + Run: func(*cobra.Command, []string) {}, + } + root.AddCommand(&cobra.Command{ + Use: "child", + Run: func(*cobra.Command, []string) {}, + }) + return root + }) + }) +} + +// registerBuiltinNamedTestSubcommandOnce guards process-global ext.Register, +// which panics on a duplicate name/type. +var registerBuiltinNamedTestSubcommandOnce sync.Once //nolint:gochecknoglobals + +func registerBuiltinNamedTestSubcommand(t *testing.T) { + t.Helper() + + registerBuiltinNamedTestSubcommandOnce.Do(func() { + subcommand.RegisterExtension("version", func(*state.GlobalState) *cobra.Command { + return &cobra.Command{ + Use: "version", + Run: func(*cobra.Command, []string) {}, + } + }) + }) +} + +// TestBuiltinNamedSubcommandExtensionIsNotReported covers a subcommand +// extension sharing a builtin command's name: running the builtin must not +// report the extension, even when the catalog lists it. +func TestBuiltinNamedSubcommandExtensionIsNotReported(t *testing.T) { + t.Parallel() + + registerBuiltinNamedTestSubcommand(t) + + versionModule := ext.Get(ext.SubcommandExtension)["version"].Path + + var reportCount atomic.Int32 + reportServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method == http.MethodPost { + reportCount.Add(1) + } + w.WriteHeader(http.StatusOK) + })) + t.Cleanup(reportServer.Close) + + catalogServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + w.Header().Set("Content-Type", "application/json") + _, _ = w.Write([]byte(`{"version": {"subcommands":["version"],"module":"` + versionModule + `"}}`)) + })) + t.Cleanup(catalogServer.Close) + + ts := NewGlobalTestState(t) + ts.Env["K6_NO_USAGE_REPORT"] = "false" + ts.Env[state.UsageReportURL] = reportServer.URL + ts.Env[state.ProvisionCatalogURL] = catalogServer.URL + ts.CmdArgs = []string{"k6", "version"} + ts.ReparseFlags() + + cmd.ExecuteWithGlobalState(ts.GlobalState) + + require.Equal(t, int32(0), reportCount.Load(), + "expected the builtin run to send no report despite an extension sharing its name") +} + +func TestNestedSubcommandReportsUsage(t *testing.T) { + t.Parallel() + + registerNestedTestSubcommand(t) + + testNestModule := ext.Get(ext.SubcommandExtension)["testnest"].Path + wantExtensions := []map[string]any{ + { + "module": testNestModule, + "version": ext.Get(ext.SubcommandExtension)["testnest"].Version, + "kind": "subcommand", + }, + } + + tt := []struct { + name string + args []string + }{ + {name: "root invocation is reported", args: []string{"x", "testnest"}}, + {name: "child invocation is reported under the extension", args: []string{"x", "testnest", "child"}}, + } + + for _, tc := range tt { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + + var reportCount atomic.Int32 + var gotBody atomic.Value + reportServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method == http.MethodPost { + body, _ := io.ReadAll(r.Body) + gotBody.Store(body) + reportCount.Add(1) + } + w.WriteHeader(http.StatusOK) + })) + t.Cleanup(reportServer.Close) + + catalogServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + w.Header().Set("Content-Type", "application/json") + _, _ = w.Write([]byte(`{"testnest": {"subcommands":["testnest"],"module":"` + testNestModule + `"}}`)) + })) + t.Cleanup(catalogServer.Close) + + ts := NewGlobalTestState(t) + ts.Env["K6_NO_USAGE_REPORT"] = "false" + ts.Env[state.UsageReportURL] = reportServer.URL + ts.Env[state.ProvisionCatalogURL] = catalogServer.URL + ts.CmdArgs = append([]string{"k6"}, tc.args...) + ts.ReparseFlags() + + cmd.ExecuteWithGlobalState(ts.GlobalState) + + require.Equal(t, int32(1), reportCount.Load(), "expected exactly one usage report") + + raw, ok := gotBody.Load().([]byte) + require.True(t, ok, "expected a report body") + var report struct { + Extensions []map[string]any `json:"extensions"` + } + require.NoError(t, json.Unmarshal(raw, &report)) + require.ElementsMatch(t, wantExtensions, report.Extensions) + }) + } +} From e136ec092e9e101ba6dce3a9499f9a8c436aac53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 Jul 2026 12:51:02 -0400 Subject: [PATCH 078/182] Honor config-file opt-out for subcommand reports The subcommand report checked only K6_NO_USAGE_REPORT, while the run report also honors the config file's noUsageReport option. The public usage-collection docs list the config file as a supported opt-out, so a user who disabled reporting there still sent a report on every k6 x extension run. The subcommand gate now reads the config file too, with the env var winning like on the run path, and fails closed by skipping the send when either source is unreadable, logging the skip at debug. Ordinary commands never pay for the file read: the extension match returns first. --- internal/cmd/subcommand.go | 15 +++- .../cmd/tests/cmd_optout_config_file_test.go | 85 +++++++++++++++++++ 2 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 internal/cmd/tests/cmd_optout_config_file_test.go diff --git a/internal/cmd/subcommand.go b/internal/cmd/subcommand.go index c60be212f..9ad328d33 100644 --- a/internal/cmd/subcommand.go +++ b/internal/cmd/subcommand.go @@ -95,7 +95,20 @@ func reportSubcommandUsage(gs *state.GlobalState, executed *cobra.Command) { if !ok { return } - if conf, err := readEnvConfig(gs.Env); err != nil || conf.NoUsageReport.Bool { + // The opt-out honors both sources that reach this path, the config file + // and the env var, with the env winning like on the run path. An + // unreadable source fails closed by skipping the send. + fileConf, err := readDiskConfig(gs) + if err != nil { + gs.Logger.WithError(err).Debug("Skipping the usage report") + return + } + envConf, err := readEnvConfig(gs.Env) + if err != nil { + gs.Logger.WithError(err).Debug("Skipping the usage report") + return + } + if fileConf.Apply(envConf).NoUsageReport.Bool { return } reportUsage(gs.Ctx, gs, func(ctx context.Context) map[string]any { diff --git a/internal/cmd/tests/cmd_optout_config_file_test.go b/internal/cmd/tests/cmd_optout_config_file_test.go new file mode 100644 index 000000000..5164ed7ee --- /dev/null +++ b/internal/cmd/tests/cmd_optout_config_file_test.go @@ -0,0 +1,85 @@ +package tests + +import ( + "bytes" + "net/http" + "net/http/httptest" + "path/filepath" + "sync/atomic" + "testing" + + "github.com/stretchr/testify/require" + + "go.k6.io/k6/v2/cmd/state" + "go.k6.io/k6/v2/internal/cmd" + "go.k6.io/k6/v2/lib/fsext" +) + +// TestConfigFileOptOutSuppressesReports covers the config-file opt-out +// (noUsageReport: true) with K6_NO_USAGE_REPORT unset: it must suppress the +// usage report on every reporting path, matching the documented opt-out. +func TestConfigFileOptOutSuppressesReports(t *testing.T) { + t.Parallel() + + registerReportTestSubcommand(t) + + testSubModule := "go.k6.io/k6/v2/internal/cmd/tests" + + tt := []struct { + name string + args []string + stdin string + }{ + { + name: "config file opt-out suppresses the run report", + args: []string{"run", "-"}, + stdin: `export default function() {};`, + }, + { + name: "config file opt-out suppresses the subcommand report", + args: []string{"x", "testsub"}, + }, + } + + for _, tc := range tt { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + + var reportCount atomic.Int32 + reportServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method == http.MethodPost { + reportCount.Add(1) + } + w.WriteHeader(http.StatusOK) + })) + t.Cleanup(reportServer.Close) + + catalogServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + w.Header().Set("Content-Type", "application/json") + _, _ = w.Write([]byte(`{"testsub": {"subcommands":["testsub"],"module":"` + testSubModule + `"}}`)) + })) + t.Cleanup(catalogServer.Close) + + ts := NewGlobalTestState(t) + // The env opt-out must stay unset so the config file is the only gate. + delete(ts.Env, "K6_NO_USAGE_REPORT") + ts.Env[state.UsageReportURL] = reportServer.URL + ts.Env[state.ProvisionCatalogURL] = catalogServer.URL + + require.NoError(t, ts.FS.MkdirAll(filepath.Dir(ts.Flags.ConfigFilePath), 0o755)) + require.NoError(t, fsext.WriteFile(ts.FS, ts.Flags.ConfigFilePath, + []byte(`{"noUsageReport": true}`), 0o600)) + + ts.CmdArgs = append([]string{"k6"}, tc.args...) + if tc.stdin != "" { + ts.Stdin = bytes.NewBufferString(tc.stdin) + } + ts.ReparseFlags() + + cmd.ExecuteWithGlobalState(ts.GlobalState) + + require.Equal(t, int32(0), reportCount.Load(), + "expected the config-file opt-out to suppress the usage report") + }) + } +} From b66dce4fa51904711b0f7018aa5cd552e58bae19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 Jul 2026 17:54:29 -0400 Subject: [PATCH 079/182] Keep report tests fail-closed on a nil catalog createReport's catalog parameter became a func, and the unit tests passed a bare nil. That was safe only because no case records an extension: the old nil map filtered everything out when consulted, but calling a nil func panics. The tests now pass a func returning a nil catalog, so a future case that records an extension filters against an empty catalog instead of panicking. --- internal/cmd/report_test.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/internal/cmd/report_test.go b/internal/cmd/report_test.go index 34de346d5..692be4583 100644 --- a/internal/cmd/report_test.go +++ b/internal/cmd/report_test.go @@ -36,6 +36,11 @@ func TestCreateReport(t *testing.T) { }, local.NewController()) } + // A nil func would also work while no case records an extension, but this + // stays fail-closed if one ever does: filtering against a nil catalog + // drops the extensions instead of panicking. + noCatalog := func() map[string]struct{} { return nil } + t.Run("default (no env)", func(t *testing.T) { t.Parallel() @@ -50,7 +55,7 @@ func TestCreateReport(t *testing.T) { time.Sleep(10 * time.Millisecond) s.GetState().MarkEnded() - m := createReport(usage.New(), s, nil) + m := createReport(usage.New(), s, noCatalog) assert.Equal(t, build.Version, m["k6_version"]) assert.EqualValues(t, map[string]int{"shared-iterations": 1}, m["executors"]) @@ -71,7 +76,7 @@ func TestCreateReport(t *testing.T) { }) require.NoError(t, err) - m := createReport(usage.New(), s, nil) + m := createReport(usage.New(), s, noCatalog) assert.Equal(t, build.Version, m["k6_version"]) assert.EqualValues(t, map[string]int{"shared-iterations": 1}, m["executors"]) @@ -92,7 +97,7 @@ func TestCreateReport(t *testing.T) { }) require.NoError(t, err) - m := createReport(usage.New(), s, nil) + m := createReport(usage.New(), s, noCatalog) assert.Equal(t, build.Version, m["k6_version"]) assert.EqualValues(t, map[string]int{"shared-iterations": 1}, m["executors"]) From 71415ddc035bcfe94f5408b3b802c12be5265f39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 Jul 2026 17:55:22 -0400 Subject: [PATCH 080/182] Pin env-over-file opt-out precedence with a test K6_NO_USAGE_REPORT is documented to win over the config file's noUsageReport, but no test set both sources at once, so inverting the Apply order in reportSubcommandUsage passed the whole telemetry suite. The config-file opt-out test now tables the env variant: with K6_NO_USAGE_REPORT=false against the file's noUsageReport: true, one report must go out on both the run and subcommand paths. The inverted-precedence mutant now fails it. --- .../cmd/tests/cmd_optout_config_file_test.go | 38 ++++++++++++++----- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/internal/cmd/tests/cmd_optout_config_file_test.go b/internal/cmd/tests/cmd_optout_config_file_test.go index 5164ed7ee..9532a3c35 100644 --- a/internal/cmd/tests/cmd_optout_config_file_test.go +++ b/internal/cmd/tests/cmd_optout_config_file_test.go @@ -15,10 +15,10 @@ import ( "go.k6.io/k6/v2/lib/fsext" ) -// TestConfigFileOptOutSuppressesReports covers the config-file opt-out -// (noUsageReport: true) with K6_NO_USAGE_REPORT unset: it must suppress the -// usage report on every reporting path, matching the documented opt-out. -func TestConfigFileOptOutSuppressesReports(t *testing.T) { +// TestConfigFileOptOut covers the config-file opt-out (noUsageReport: true) +// on every reporting path: alone it must suppress the usage report, and +// K6_NO_USAGE_REPORT=false must win over it and re-enable reporting. +func TestConfigFileOptOut(t *testing.T) { t.Parallel() registerReportTestSubcommand(t) @@ -26,9 +26,11 @@ func TestConfigFileOptOutSuppressesReports(t *testing.T) { testSubModule := "go.k6.io/k6/v2/internal/cmd/tests" tt := []struct { - name string - args []string - stdin string + name string + args []string + stdin string + envOptOut string // K6_NO_USAGE_REPORT; empty leaves it unset + wantReports int32 }{ { name: "config file opt-out suppresses the run report", @@ -39,6 +41,19 @@ func TestConfigFileOptOutSuppressesReports(t *testing.T) { name: "config file opt-out suppresses the subcommand report", args: []string{"x", "testsub"}, }, + { + name: "env re-enables the run report over the config file", + args: []string{"run", "-"}, + stdin: `export default function() {};`, + envOptOut: "false", + wantReports: 1, + }, + { + name: "env re-enables the subcommand report over the config file", + args: []string{"x", "testsub"}, + envOptOut: "false", + wantReports: 1, + }, } for _, tc := range tt { @@ -61,8 +76,11 @@ func TestConfigFileOptOutSuppressesReports(t *testing.T) { t.Cleanup(catalogServer.Close) ts := NewGlobalTestState(t) - // The env opt-out must stay unset so the config file is the only gate. + // The default env opt-out would mask the config file gate. delete(ts.Env, "K6_NO_USAGE_REPORT") + if tc.envOptOut != "" { + ts.Env["K6_NO_USAGE_REPORT"] = tc.envOptOut + } ts.Env[state.UsageReportURL] = reportServer.URL ts.Env[state.ProvisionCatalogURL] = catalogServer.URL @@ -78,8 +96,8 @@ func TestConfigFileOptOutSuppressesReports(t *testing.T) { cmd.ExecuteWithGlobalState(ts.GlobalState) - require.Equal(t, int32(0), reportCount.Load(), - "expected the config-file opt-out to suppress the usage report") + require.Equal(t, tc.wantReports, reportCount.Load(), + "unexpected usage report count with noUsageReport set in the config file") }) } } From 4a2b124bd776fb82eba2b471e5c6a83c34529dac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 Jul 2026 19:24:58 -0400 Subject: [PATCH 081/182] Pin deep and x-named nested subcommand reporting The walk's root-level check in subcommandExtension had no covering test: simplifying its condition to a bare name match passed the whole suite while an invocation under an extension's own x-named subcommand went unreported. Rows for a grandchild and an x-named nested subcommand now pin the attribution; the weakened guard fails them. --- .../cmd_subcommand_nested_report_test.go | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/internal/cmd/tests/cmd_subcommand_nested_report_test.go b/internal/cmd/tests/cmd_subcommand_nested_report_test.go index 61fb62cc7..6bc6f6fad 100644 --- a/internal/cmd/tests/cmd_subcommand_nested_report_test.go +++ b/internal/cmd/tests/cmd_subcommand_nested_report_test.go @@ -31,10 +31,26 @@ func registerNestedTestSubcommand(t *testing.T) { Use: "testnest", Run: func(*cobra.Command, []string) {}, } - root.AddCommand(&cobra.Command{ + child := &cobra.Command{ Use: "child", Run: func(*cobra.Command, []string) {}, + } + child.AddCommand(&cobra.Command{ + Use: "grandchild", + Run: func(*cobra.Command, []string) {}, + }) + // An x-named nested subcommand exercises the walk's root-level + // check: the walk must climb past it to the extension under the + // real x. + nestedX := &cobra.Command{ + Use: "x", + Run: func(*cobra.Command, []string) {}, + } + nestedX.AddCommand(&cobra.Command{ + Use: "leaf", + Run: func(*cobra.Command, []string) {}, }) + root.AddCommand(child, nestedX) return root }) }) @@ -115,6 +131,9 @@ func TestNestedSubcommandReportsUsage(t *testing.T) { }{ {name: "root invocation is reported", args: []string{"x", "testnest"}}, {name: "child invocation is reported under the extension", args: []string{"x", "testnest", "child"}}, + {name: "grandchild invocation is reported under the extension", args: []string{"x", "testnest", "child", "grandchild"}}, + {name: "x-named nested invocation is reported under the extension", args: []string{"x", "testnest", "x"}}, + {name: "invocation under an x-named nested subcommand is reported", args: []string{"x", "testnest", "x", "leaf"}}, } for _, tc := range tt { From 13c9caa2a929078f22deb7a68a390669d927f211 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 Jul 2026 19:25:37 -0400 Subject: [PATCH 082/182] Pin reporting a builtin-named extension under x Only the negative half of the builtin-name collision was pinned: running the builtin sends nothing. A walk that additionally blacklisted builtin names would have passed the suite while a builtin-named extension invoked under x silently went unreported. The positive case pins that k6 x version reports the extension. --- .../cmd_subcommand_nested_report_test.go | 75 +++++++++++-------- 1 file changed, 45 insertions(+), 30 deletions(-) diff --git a/internal/cmd/tests/cmd_subcommand_nested_report_test.go b/internal/cmd/tests/cmd_subcommand_nested_report_test.go index 6bc6f6fad..8e585717c 100644 --- a/internal/cmd/tests/cmd_subcommand_nested_report_test.go +++ b/internal/cmd/tests/cmd_subcommand_nested_report_test.go @@ -73,42 +73,57 @@ func registerBuiltinNamedTestSubcommand(t *testing.T) { }) } -// TestBuiltinNamedSubcommandExtensionIsNotReported covers a subcommand -// extension sharing a builtin command's name: running the builtin must not -// report the extension, even when the catalog lists it. -func TestBuiltinNamedSubcommandExtensionIsNotReported(t *testing.T) { +// TestBuiltinNamedSubcommandExtension covers a subcommand extension sharing a +// builtin command's name: running the builtin must not report the extension, +// even when the catalog lists it, while running the extension under x must. +func TestBuiltinNamedSubcommandExtension(t *testing.T) { t.Parallel() registerBuiltinNamedTestSubcommand(t) versionModule := ext.Get(ext.SubcommandExtension)["version"].Path - var reportCount atomic.Int32 - reportServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if r.Method == http.MethodPost { - reportCount.Add(1) - } - w.WriteHeader(http.StatusOK) - })) - t.Cleanup(reportServer.Close) - - catalogServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { - w.Header().Set("Content-Type", "application/json") - _, _ = w.Write([]byte(`{"version": {"subcommands":["version"],"module":"` + versionModule + `"}}`)) - })) - t.Cleanup(catalogServer.Close) - - ts := NewGlobalTestState(t) - ts.Env["K6_NO_USAGE_REPORT"] = "false" - ts.Env[state.UsageReportURL] = reportServer.URL - ts.Env[state.ProvisionCatalogURL] = catalogServer.URL - ts.CmdArgs = []string{"k6", "version"} - ts.ReparseFlags() - - cmd.ExecuteWithGlobalState(ts.GlobalState) - - require.Equal(t, int32(0), reportCount.Load(), - "expected the builtin run to send no report despite an extension sharing its name") + tt := []struct { + name string + args []string + wantReports int32 + }{ + {name: "the builtin does not report the extension", args: []string{"version"}}, + {name: "the extension under x is reported", args: []string{"x", "version"}, wantReports: 1}, + } + + for _, tc := range tt { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + + var reportCount atomic.Int32 + reportServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method == http.MethodPost { + reportCount.Add(1) + } + w.WriteHeader(http.StatusOK) + })) + t.Cleanup(reportServer.Close) + + catalogServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + w.Header().Set("Content-Type", "application/json") + _, _ = w.Write([]byte(`{"version": {"subcommands":["version"],"module":"` + versionModule + `"}}`)) + })) + t.Cleanup(catalogServer.Close) + + ts := NewGlobalTestState(t) + ts.Env["K6_NO_USAGE_REPORT"] = "false" + ts.Env[state.UsageReportURL] = reportServer.URL + ts.Env[state.ProvisionCatalogURL] = catalogServer.URL + ts.CmdArgs = append([]string{"k6"}, tc.args...) + ts.ReparseFlags() + + cmd.ExecuteWithGlobalState(ts.GlobalState) + + require.Equal(t, tc.wantReports, reportCount.Load(), + "unexpected usage report count for a builtin-named extension") + }) + } } func TestNestedSubcommandReportsUsage(t *testing.T) { From 233e1bb4ff3db850739863aa0d904fa83d7dbe90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 Jul 2026 19:26:19 -0400 Subject: [PATCH 083/182] Pin the fail-closed skip on an unreadable config reportSubcommandUsage skips the send when the config file is unreadable, but no test covered that branch: swallowing the read error and reporting anyway would have passed the suite. The new case pins that a malformed config file suppresses the report even when the env re-enables it, while the subcommand still runs. --- .../cmd/tests/cmd_optout_config_file_test.go | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/internal/cmd/tests/cmd_optout_config_file_test.go b/internal/cmd/tests/cmd_optout_config_file_test.go index 9532a3c35..5a4f6419c 100644 --- a/internal/cmd/tests/cmd_optout_config_file_test.go +++ b/internal/cmd/tests/cmd_optout_config_file_test.go @@ -16,8 +16,9 @@ import ( ) // TestConfigFileOptOut covers the config-file opt-out (noUsageReport: true) -// on every reporting path: alone it must suppress the usage report, and -// K6_NO_USAGE_REPORT=false must win over it and re-enable reporting. +// on every reporting path: alone it must suppress the usage report, +// K6_NO_USAGE_REPORT=false must win over it and re-enable reporting, and an +// unreadable config file must fail closed by skipping the report. func TestConfigFileOptOut(t *testing.T) { t.Parallel() @@ -29,6 +30,7 @@ func TestConfigFileOptOut(t *testing.T) { name string args []string stdin string + config string // config file content; empty means {"noUsageReport": true} envOptOut string // K6_NO_USAGE_REPORT; empty leaves it unset wantReports int32 }{ @@ -54,6 +56,15 @@ func TestConfigFileOptOut(t *testing.T) { envOptOut: "false", wantReports: 1, }, + { + // An unreadable config file must fail closed: no report, while + // the subcommand still runs (the zero exit code is asserted by + // the test state). + name: "unreadable config file skips the subcommand report", + args: []string{"x", "testsub"}, + config: `{not json`, + envOptOut: "false", + }, } for _, tc := range tt { @@ -84,9 +95,12 @@ func TestConfigFileOptOut(t *testing.T) { ts.Env[state.UsageReportURL] = reportServer.URL ts.Env[state.ProvisionCatalogURL] = catalogServer.URL + config := tc.config + if config == "" { + config = `{"noUsageReport": true}` + } require.NoError(t, ts.FS.MkdirAll(filepath.Dir(ts.Flags.ConfigFilePath), 0o755)) - require.NoError(t, fsext.WriteFile(ts.FS, ts.Flags.ConfigFilePath, - []byte(`{"noUsageReport": true}`), 0o600)) + require.NoError(t, fsext.WriteFile(ts.FS, ts.Flags.ConfigFilePath, []byte(config), 0o600)) ts.CmdArgs = append([]string{"k6"}, tc.args...) if tc.stdin != "" { From 2b1399ee4d38e107feb32c776812e9ae19a44f95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 Jul 2026 19:26:41 -0400 Subject: [PATCH 084/182] Derive the opt-out test catalog from the registry The hardcoded module path never matched the registered extension: a func module resolves to its constructor's symbol name, so the catalog fixture filtered every extension out and the count-only assertions hid it. Deriving the path via ext.Get keeps the fixture real, like the sibling report tests. --- internal/cmd/tests/cmd_optout_config_file_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/cmd/tests/cmd_optout_config_file_test.go b/internal/cmd/tests/cmd_optout_config_file_test.go index 5a4f6419c..b55cde0c9 100644 --- a/internal/cmd/tests/cmd_optout_config_file_test.go +++ b/internal/cmd/tests/cmd_optout_config_file_test.go @@ -11,6 +11,7 @@ import ( "github.com/stretchr/testify/require" "go.k6.io/k6/v2/cmd/state" + "go.k6.io/k6/v2/ext" "go.k6.io/k6/v2/internal/cmd" "go.k6.io/k6/v2/lib/fsext" ) @@ -24,7 +25,7 @@ func TestConfigFileOptOut(t *testing.T) { registerReportTestSubcommand(t) - testSubModule := "go.k6.io/k6/v2/internal/cmd/tests" + testSubModule := ext.Get(ext.SubcommandExtension)["testsub"].Path tt := []struct { name string From 3374facb2307e505471e725aa2329e3b741c3345 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 Jul 2026 21:14:10 -0400 Subject: [PATCH 085/182] Count k6 help x as extension usage k6 x --help reported the extension, but k6 help x , which displays the same help, did not, undercounting extension usage. Resolve the root help command to the command whose help it displayed before matching it to an extension, so both help forms count. k6 help x and k6 x help describe the x namespace rather than an extension and stay unreported. --- internal/cmd/subcommand.go | 21 ++++- .../tests/cmd_subcommand_help_report_test.go | 93 +++++++++++++++++++ 2 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 internal/cmd/tests/cmd_subcommand_help_report_test.go diff --git a/internal/cmd/subcommand.go b/internal/cmd/subcommand.go index 9ad328d33..930582da5 100644 --- a/internal/cmd/subcommand.go +++ b/internal/cmd/subcommand.go @@ -90,8 +90,10 @@ Run "k6 x explore" to see the full list of official and community-provided subco // the catch-all `x` help, `k6 run`, builtins sharing an extension's name, // completions, and provisioning stubs are ignored. A nested invocation // (`k6 x `) counts toward the extension that owns the child. +// Displaying an extension's help counts too, whether requested with the flag +// (`k6 x --help`) or the help command (`k6 help x `). func reportSubcommandUsage(gs *state.GlobalState, executed *cobra.Command) { - extension, ok := subcommandExtension(executed) + extension, ok := subcommandExtension(helpTarget(executed)) if !ok { return } @@ -116,6 +118,23 @@ func reportSubcommandUsage(gs *state.GlobalState, executed *cobra.Command) { }) } +// helpTarget resolves the root help command to the command whose help it +// displayed, so `k6 help x ` counts toward the extension like +// `k6 x --help` does. Any other command passes through unchanged. The +// lookup repeats the one cobra's help command ran on its positional args, +// which its flag set still holds after execution. +func helpTarget(executed *cobra.Command) *cobra.Command { + if executed == nil || executed.Name() != "help" || + !executed.HasParent() || executed.Parent().HasParent() { + return executed + } + target, _, err := executed.Root().Find(executed.Flags().Args()) + if err != nil { + return executed + } + return target +} + // subcommandExtension resolves the executed command to the registered // subcommand extension it belongs to: the direct child of the root-level `x` // command on the executed command's parent chain. Matching by position rather diff --git a/internal/cmd/tests/cmd_subcommand_help_report_test.go b/internal/cmd/tests/cmd_subcommand_help_report_test.go new file mode 100644 index 000000000..39936faf5 --- /dev/null +++ b/internal/cmd/tests/cmd_subcommand_help_report_test.go @@ -0,0 +1,93 @@ +package tests + +import ( + "encoding/json" + "io" + "net/http" + "net/http/httptest" + "sync/atomic" + "testing" + + "github.com/stretchr/testify/require" + + "go.k6.io/k6/v2/cmd/state" + "go.k6.io/k6/v2/ext" + "go.k6.io/k6/v2/internal/cmd" +) + +// TestHelpInvocationReportsUsage covers help invocations of a subcommand +// extension: both `k6 x --help` and `k6 help x ` display the +// extension's help, so both count as usage. `k6 help x` describes the x +// namespace itself, and `k6 x help ` also falls back to the namespace +// help, so neither reports. +func TestHelpInvocationReportsUsage(t *testing.T) { + t.Parallel() + + registerReportTestSubcommand(t) + + testSubModule := ext.Get(ext.SubcommandExtension)["testsub"].Path + wantExtensions := []map[string]any{ + { + "module": testSubModule, + "version": ext.Get(ext.SubcommandExtension)["testsub"].Version, + "kind": "subcommand", + }, + } + + tt := []struct { + name string + args []string + wantReports int32 + }{ + {name: "flag help on the extension is reported", args: []string{"x", "testsub", "--help"}, wantReports: 1}, + {name: "help command on the extension is reported", args: []string{"help", "x", "testsub"}, wantReports: 1}, + {name: "help of the x namespace is not reported", args: []string{"help", "x"}}, + {name: "namespace help under x is not reported", args: []string{"x", "help", "testsub"}}, + } + + for _, tc := range tt { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + + var reportCount atomic.Int32 + var gotBody atomic.Value + reportServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method == http.MethodPost { + body, _ := io.ReadAll(r.Body) + gotBody.Store(body) + reportCount.Add(1) + } + w.WriteHeader(http.StatusOK) + })) + t.Cleanup(reportServer.Close) + + catalogServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + w.Header().Set("Content-Type", "application/json") + _, _ = w.Write([]byte(`{"testsub": {"subcommands":["testsub"],"module":"` + testSubModule + `"}}`)) + })) + t.Cleanup(catalogServer.Close) + + ts := NewGlobalTestState(t) + ts.Env["K6_NO_USAGE_REPORT"] = "false" + ts.Env[state.UsageReportURL] = reportServer.URL + ts.Env[state.ProvisionCatalogURL] = catalogServer.URL + ts.CmdArgs = append([]string{"k6"}, tc.args...) + ts.ReparseFlags() + + cmd.ExecuteWithGlobalState(ts.GlobalState) + + require.Equal(t, tc.wantReports, reportCount.Load(), "unexpected usage report count for a help invocation") + + if tc.wantReports == 0 { + return + } + raw, ok := gotBody.Load().([]byte) + require.True(t, ok, "expected a report body") + var report struct { + Extensions []map[string]any `json:"extensions"` + } + require.NoError(t, json.Unmarshal(raw, &report)) + require.ElementsMatch(t, wantExtensions, report.Extensions) + }) + } +} From fd1baf79dc53d508e7857d9c0773666dee29e1cb Mon Sep 17 00:00:00 2001 From: Mihail Stoykov <312246+mstoykov@users.noreply.github.com> Date: Wed, 29 Jul 2026 10:26:33 +0300 Subject: [PATCH 086/182] fsext: serialize first-fill in CacheOnReadFs to fix concurrent-open race (#6125) afero.CacheOnReadFs.Open on a cacheMiss runs base.Stat + copyToLayer + layer.Open. A second goroutine entering Open during copyToLayer classifies the mid-copy layer file as cacheHit and returns layer.Open(name) on a partially written file, reading zero or truncated bytes. The wrapper now serializes the cacheMiss -> copyToLayer -> layer.Open sequence per path via a fill mutex, and remembers paths whose first open has completed so subsequent opens take a fast path with no extra locking. OpenFile shares the same path since it has the same shape in afero. Queued waiters that wake after the first filler finished release the fill mutex before running openFn so they can fan out through afero's cacheHit branch in parallel. First observed as a flake in TestRunCSVParseConcurrentFromMultipleModules where three top-level-await modules each call fs.open("data.csv") + csv.parse(file) and one ends up reading 0 bytes. The test passes -race -count=500 cleanly after this change; before it produced multiple failures at the same count. --- lib/fsext/cacheonread.go | 84 ++++++++++++++++++++++++++++++++++- lib/fsext/cacheonread_test.go | 82 ++++++++++++++++++++++++++++++++++ 2 files changed, 165 insertions(+), 1 deletion(-) create mode 100644 lib/fsext/cacheonread_test.go diff --git a/lib/fsext/cacheonread.go b/lib/fsext/cacheonread.go index 0a4eaeb2e..55391938e 100644 --- a/lib/fsext/cacheonread.go +++ b/lib/fsext/cacheonread.go @@ -21,6 +21,21 @@ type CacheOnReadFs struct { lock *sync.Mutex cachedOnly bool cached map[string]bool + + // populated marks paths whose first copyToLayer has finished; subsequent + // Opens can then run concurrently through afero's cacheHit branch. + // + // Entries are never invalidated. k6 uses this wrapper read-only (see + // internal/loader/filesystems.go), so Remove/RemoveAll/Rename/Chtimes/ + // Chmod - anything that triggers a fresh copyToLayer - would need to + // clear the marker to avoid re-exposing the copyToLayer race. + populated map[string]bool + + // fills holds a per-path mutex serializing the first + // cacheMiss -> copyToLayer -> layer.Open in afero. Without it a second + // reader can be classified as cacheHit on the still-being-copied layer + // file and read empty/partial bytes. + fills map[string]*sync.Mutex } // OnlyCachedEnabler enables the mode of FS that allows to open @@ -43,6 +58,8 @@ func NewCacheOnReadFs(base, layer afero.Fs, cacheTime time.Duration) afero.Fs { lock: &sync.Mutex{}, cachedOnly: false, cached: make(map[string]bool), + populated: make(map[string]bool), + fills: make(map[string]*sync.Mutex), } } @@ -66,13 +83,78 @@ func (c *CacheOnReadFs) Open(name string) (afero.File, error) { return nil, err } - return c.Fs.Open(name) + return c.openSerialized(name, func() (afero.File, error) { + return c.Fs.Open(name) + }) +} + +// OpenFile shares openSerialized with Open so a first cacheMiss can't race +// with a concurrent reader. Read-only flags only: a write/truncate flag +// mutates the layer while populated stays true, letting concurrent fast-path +// Opens read torn or empty data (see the populated field comment). +func (c *CacheOnReadFs) OpenFile(name string, flag int, perm fs.FileMode) (afero.File, error) { + if err := c.checkOrRemember(name); err != nil { + return nil, err + } + + return c.openSerialized(name, func() (afero.File, error) { + return c.Fs.OpenFile(name, flag, perm) + }) +} + +// openSerialized invokes openFn while ensuring that, for a given name, the +// first successful open completes before any other goroutine is allowed into +// the same open path. Once a name is marked populated, openFn is invoked with +// no extra locking. +func (c *CacheOnReadFs) openSerialized(name string, openFn func() (afero.File, error)) (afero.File, error) { + c.lock.Lock() + if c.populated[name] { + c.lock.Unlock() + return openFn() + } + fl, ok := c.fills[name] + if !ok { + fl = &sync.Mutex{} + c.fills[name] = fl + } + c.lock.Unlock() + + fl.Lock() + + // Filler already finished: drop fl so queued waiters fan out in parallel + // through afero's cacheHit branch, and skip the redundant bookkeeping. + c.lock.Lock() + alreadyPopulated := c.populated[name] + c.lock.Unlock() + if alreadyPopulated { + fl.Unlock() + return openFn() + } + + defer fl.Unlock() + + f, err := openFn() + if err != nil { + return nil, err + } + + c.lock.Lock() + c.populated[name] = true + delete(c.fills, name) + c.lock.Unlock() + + return f, nil } // Stat returns a FileInfo describing the named file, or an error, if any // happens. // if CacheOnReadFs is in the opened only mode it should return // an error if path wasn't open before +// +// Not routed through openSerialized: a concurrent Stat during another +// goroutine's first Open can see the layer file mid copyToLayer and report +// Size=0. Safe today because k6's Stat callers only read presence/IsDir. +// Route through openSerialized if a caller starts consuming Size/ModTime/Mode. func (c *CacheOnReadFs) Stat(path string) (fs.FileInfo, error) { if err := c.checkOrRemember(path); err != nil { return nil, err diff --git a/lib/fsext/cacheonread_test.go b/lib/fsext/cacheonread_test.go new file mode 100644 index 000000000..9be974fc9 --- /dev/null +++ b/lib/fsext/cacheonread_test.go @@ -0,0 +1,82 @@ +package fsext + +import ( + "io" + "sync" + "syscall" + "testing" + + "github.com/spf13/afero" + "github.com/stretchr/testify/require" +) + +// TestCacheOnReadFsConcurrentFirstOpen exercises the race where two goroutines +// open the same not-yet-cached file at the same time. Without per-path +// serialization in CacheOnReadFs the underlying afero CacheOnReadFs can be +// caught mid copyToLayer by a second reader, which then opens the layer file +// while it is still being filled and reads zero or partial bytes. +func TestCacheOnReadFsConcurrentFirstOpen(t *testing.T) { + t.Parallel() + assertConcurrentFirstOpenReadsFullContent(t, func(fs afero.Fs, path string) (afero.File, error) { + return fs.Open(path) + }) +} + +// TestCacheOnReadFsConcurrentFirstOpenFile mirrors the plain Open test but +// exercises the OpenFile entry point, which shares openSerialized. Guards +// against a future refactor reintroducing the race on that path. +func TestCacheOnReadFsConcurrentFirstOpenFile(t *testing.T) { + t.Parallel() + assertConcurrentFirstOpenReadsFullContent(t, func(fs afero.Fs, path string) (afero.File, error) { + return fs.OpenFile(path, syscall.O_RDONLY, 0) + }) +} + +// assertConcurrentFirstOpenReadsFullContent releases N goroutines simultaneously +// at the first-open of a not-yet-cached path and asserts every goroutine reads +// the full file content. The opener parameter picks the entry point under test +// (Open vs OpenFile). +func assertConcurrentFirstOpenReadsFullContent(t *testing.T, opener func(afero.Fs, string) (afero.File, error)) { + t.Helper() + + const ( + path = "/data.csv" + concurrency = 32 + ) + content := []byte("col1,col2\na,b\nc,d\n") + + base := NewMemMapFs() + require.NoError(t, WriteFile(base, path, content, 0o644)) + + fs := NewCacheOnReadFs(base, NewMemMapFs(), 0) + + var ( + wg sync.WaitGroup + start = make(chan struct{}) + ) + results := make([][]byte, concurrency) + errs := make([]error, concurrency) + + for i := range concurrency { + wg.Add(1) + go func(idx int) { + defer wg.Done() + <-start + f, err := opener(fs, path) + if err != nil { + errs[idx] = err + return + } + defer f.Close() //nolint:errcheck + results[idx], errs[idx] = io.ReadAll(f) + }(i) + } + + close(start) + wg.Wait() + + for i, got := range results { + require.NoError(t, errs[i], "goroutine %d", i) + require.Equal(t, content, got, "goroutine %d read truncated data", i) + } +} From 7a2f1de42a3a0aefc190a7eeeb2a8dd6cf3ee240 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20L=C3=B3pez=20de=20la=20Franca=20Beltran?= <5459617+joanlopez@users.noreply.github.com> Date: Thu, 30 Jul 2026 10:51:19 +0200 Subject: [PATCH 087/182] feat(browser): Support to connectOverCDP to an existing browser (#6165) * feat(browser): Support to connectOverCDP to an existing browser * Skip the processDone wait when isRemoteBrowser * Also parse browser opts from env in ConnectOverCDP * Fix context().browser() on user-managed (connectOverCDP) browsers * Hard-code browser type for chromium specific connectOverCDP * Use a custom env var remote.js example, as convenience * Make IsConnected() reflect close synchronously * Drain remote close via detach events * Cover connectOverCDP option parsing without a scenario * Clear error when using a connectOverCDP browser after close * Stamp VU and scenario on connectOverCDP iteration spans * Make test proxy tolerant of WS connection shutdown * Minor improvements suggested during code review * Reject host-less ws endpoints in connectOverCDP validation * Apply feedback from code review --- examples/browser/remote.js | 41 ++++ .../browser/browser_context_mapping.go | 5 +- .../k6/browser/browser/browser_mapping.go | 60 ++++- .../k6/browser/browser/chromium_mapping.go | 40 ++++ .../js/modules/k6/browser/browser/mapping.go | 9 +- .../k6/browser/browser/mapping_test.go | 3 +- .../js/modules/k6/browser/browser/module.go | 33 +-- .../modules/k6/browser/browser/module_test.go | 1 + .../js/modules/k6/browser/browser/registry.go | 133 +++++++++-- .../k6/browser/browser/registry_test.go | 62 +++++ .../k6/browser/chromium/browser_type.go | 91 +++++++- .../k6/browser/chromium/browser_type_test.go | 52 +++++ .../js/modules/k6/browser/common/browser.go | 60 ++++- .../k6/browser/k6ext/k6test/span_recorder.go | 105 +++++++++ .../k6/browser/tests/browser_context_test.go | 126 ++++++++++ .../k6/browser/tests/browser_type_test.go | 221 ++++++++++++++++++ .../k6/browser/tests/test_browser_proxy.go | 24 +- 17 files changed, 998 insertions(+), 68 deletions(-) create mode 100644 examples/browser/remote.js create mode 100644 internal/js/modules/k6/browser/browser/chromium_mapping.go create mode 100644 internal/js/modules/k6/browser/k6ext/k6test/span_recorder.go diff --git a/examples/browser/remote.js b/examples/browser/remote.js new file mode 100644 index 000000000..5cedb44fd --- /dev/null +++ b/examples/browser/remote.js @@ -0,0 +1,41 @@ +import { chromium } from 'k6/browser'; + +// Connect to an external CDP browser with a URL computed at runtime. +// +// For instance, you could fetch that URL from your browser provider's API, +// in setup(), and pass it to the iterations: +// +// import http from 'k6/http'; +// +// export function setup() { +// const res = http.post('https://provider.example/v1/sessions', /* ... */); +// return { wsURL: res.json().connectUrl }; +// } +// +// export default async function (data) { +// const browser = await chromium.connectOverCDP(data.wsURL); +// // ... +// } +// +// For a quick local run, start Chrome with --remote-debugging-port=9222 and pass +// its ws URL via an env var — e.g., CDP_WS_URL, simulating a URL computed at runtime: +// CDP_WS_URL=ws://localhost:9222/devtools/browser/ k6 run examples/browser/remote.js +// +// Note this is different from K6_BROWSER_WS_URL, which covers a different path where +// k6 users can provide the ws URL via an env var, not computed at runtime. + +export default async function () { + const browser = await chromium.connectOverCDP(__ENV.CDP_WS_URL); + const page = await browser.newPage(); + + try { + await page.goto('https://quickpizza.grafana.com/', { waitUntil: 'networkidle' }); + console.log(`title: ${await page.title()}`); + } finally { + await page.close(); + // For user-managed browsers (those created via chromium.connectOverCDP), + // close() is exposed so you can release the connection early. + // It's optional, k6 auto-closes it at iteration end, just like k6-managed browsers. + await browser.close(); + } +} diff --git a/internal/js/modules/k6/browser/browser/browser_context_mapping.go b/internal/js/modules/k6/browser/browser/browser_context_mapping.go index 456cf2c52..fb495182d 100644 --- a/internal/js/modules/k6/browser/browser/browser_context_mapping.go +++ b/internal/js/modules/k6/browser/browser/browser_context_mapping.go @@ -56,8 +56,9 @@ func mapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //nolin }) }, "browser": func() mapping { - // the browser is grabbed from VU. - return mapBrowser(vu) + return mapBrowser(vu, func() (*common.Browser, error) { + return bc.Browser(), nil + }) }, "clearCookies": func() *sobek.Promise { return promise(vu, func() (any, error) { diff --git a/internal/js/modules/k6/browser/browser/browser_mapping.go b/internal/js/modules/k6/browser/browser/browser_mapping.go index be408278f..7d1d0ce4b 100644 --- a/internal/js/modules/k6/browser/browser/browser_mapping.go +++ b/internal/js/modules/k6/browser/browser/browser_mapping.go @@ -8,13 +8,18 @@ import ( "go.k6.io/k6/v2/internal/js/modules/k6/browser/common" ) -// mapBrowser to the JS module. +// browserProvider is a function that provides a browser instance. +type browserProvider func() (*common.Browser, error) + +// mapBrowser to the JS module API using the provider to get the browser instance. +// This lets the same mapping serve both the managed browser and a browser +// obtained via chromium.connectOverCDP, since they share the same API. // -//nolint:gocognit -func mapBrowser(vu moduleVU) mapping { - return mapping{ +//nolint:gocognit,funlen +func mapBrowser(vu moduleVU, browser browserProvider) mapping { + m := mapping{ "context": func() (mapping, error) { - b, err := vu.browser() + b, err := browser() if err != nil { return nil, err } @@ -22,7 +27,7 @@ func mapBrowser(vu moduleVU) mapping { }, "closeContext": func() *sobek.Promise { return promise(vu, func() (any, error) { - b, err := vu.browser() + b, err := browser() if err != nil { return nil, err } @@ -30,7 +35,7 @@ func mapBrowser(vu moduleVU) mapping { }) }, "isConnected": func() (bool, error) { - b, err := vu.browser() + b, err := browser() if err != nil { return false, err } @@ -42,7 +47,7 @@ func mapBrowser(vu moduleVU) mapping { return nil, fmt.Errorf("parsing browser.newContext options: %w", err) } return promise(vu, func() (any, error) { - b, err := vu.browser() + b, err := browser() if err != nil { return nil, err } @@ -58,14 +63,14 @@ func mapBrowser(vu moduleVU) mapping { }), nil }, "userAgent": func() (string, error) { - b, err := vu.browser() + b, err := browser() if err != nil { return "", err } return b.UserAgent(), nil }, "version": func() (string, error) { - b, err := vu.browser() + b, err := browser() if err != nil { return "", err } @@ -77,7 +82,7 @@ func mapBrowser(vu moduleVU) mapping { return nil, fmt.Errorf("parsing browser.newPage options: %w", err) } return promise(vu, func() (any, error) { - b, err := vu.browser() + b, err := browser() if err != nil { return nil, err } @@ -93,6 +98,39 @@ func mapBrowser(vu moduleVU) mapping { }), nil }, } + + addUserManagedClose(vu, m, browser) + + return m +} + +// addUserManagedClose adds a close() method to the browser mapping when the +// browser is user-managed (created via chromium.connectOverCDP). close() +// untracks the browser from the registry (so the IterEnd/Exit sweep does not +// double-close) and closes it. Managed browsers don't get a close(): the +// registry owns their lifecycle. +func addUserManagedClose(vu moduleVU, m mapping, browser browserProvider) { + // In the init context (e.g. the module-level browser export) there's no + // state and no iteration browser to resolve; the managed browser never + // exposes close() anyway. + if vu.State() == nil { + return + } + b, err := browser() + if err != nil { + return + } + iter, ok := vu.userManagedIter(b) + if !ok { + return + } + m["close"] = func() *sobek.Promise { + return promise(vu, func() (any, error) { + vu.untrackUserManagedBrowser(iter, b) + b.Close() + return nil, nil + }) + } } func initBrowserContext(bctx *common.BrowserContext, testRunID string) error { diff --git a/internal/js/modules/k6/browser/browser/chromium_mapping.go b/internal/js/modules/k6/browser/browser/chromium_mapping.go new file mode 100644 index 000000000..b5f21b272 --- /dev/null +++ b/internal/js/modules/k6/browser/browser/chromium_mapping.go @@ -0,0 +1,40 @@ +package browser + +import ( + "fmt" + + "github.com/grafana/sobek" + + "go.k6.io/k6/v2/internal/js/modules/k6/browser/chromium" + "go.k6.io/k6/v2/internal/js/modules/k6/browser/common" +) + +// mapChromium maps the Chromium browser type API to the JS module. +func mapChromium(vu moduleVU, bt *chromium.BrowserType) mapping { + return mapping{ + "connectOverCDP": func(wsEndpoint string) *sobek.Promise { + return promise(vu, func() (any, error) { + iter := vu.State().Iteration + + // Clone the BrowserType for this call so concurrent + // connectOverCDP calls in the same iteration (e.g., via + // Promise.all) don't race on its mutable state. + connBT := bt.Clone() + + // Link the connection to the iteration trace and connect. + tracedCtx := vu.startConnectTrace(vu.Context(), iter) + b, err := connBT.ConnectOverCDP(tracedCtx, wsEndpoint) + if err != nil { + return nil, fmt.Errorf("connecting to Chromium over CDP: %w", err) + } + + // Register for guaranteed cleanup at IterEnd / Exit. + vu.trackUserManagedBrowser(iter, b) + + return mapBrowser(vu, func() (*common.Browser, error) { + return b, nil + }), nil + }) + }, + } +} diff --git a/internal/js/modules/k6/browser/browser/mapping.go b/internal/js/modules/k6/browser/browser/mapping.go index a9890ea46..d9f83a8ae 100644 --- a/internal/js/modules/k6/browser/browser/mapping.go +++ b/internal/js/modules/k6/browser/browser/mapping.go @@ -19,18 +19,17 @@ import ( // and customization over our API. type mapping = map[string]any -// mapBrowserToSobek maps the browser API to the JS module. +// mapToSobek maps a browser-module mapping to a Sobek object. // The motivation of this mapping was to support $ and $$ wildcard // methods. // See issue #661 for more details. -func mapBrowserToSobek(vu moduleVU) *sobek.Object { +func mapToSobek(vu moduleVU, m mapping) *sobek.Object { var ( rt = vu.Runtime() obj = rt.NewObject() ) - for k, v := range mapBrowser(vu) { - err := obj.Set(k, rt.ToValue(v)) - if err != nil { + for k, v := range m { + if err := obj.Set(k, rt.ToValue(v)); err != nil { k6common.Throw(rt, k6ext.BrowserError(fmt.Errorf("mapping: %w", err))) } } diff --git a/internal/js/modules/k6/browser/browser/mapping_test.go b/internal/js/modules/k6/browser/browser/mapping_test.go index 01e865dcd..97aa2803e 100644 --- a/internal/js/modules/k6/browser/browser/mapping_test.go +++ b/internal/js/modules/k6/browser/browser/mapping_test.go @@ -126,7 +126,8 @@ func TestMappings(t *testing.T) { "browser": { apiInterface: (*browserAPI)(nil), mapp: func() mapping { - return mapBrowser(moduleVU{VU: vu}) + mvu := moduleVU{VU: vu} + return mapBrowser(mvu, mvu.browser) }, }, "browserContext": { diff --git a/internal/js/modules/k6/browser/browser/module.go b/internal/js/modules/k6/browser/browser/module.go index 022b16733..6daf2f88f 100644 --- a/internal/js/modules/k6/browser/browser/module.go +++ b/internal/js/modules/k6/browser/browser/module.go @@ -13,6 +13,7 @@ import ( "github.com/grafana/sobek" + "go.k6.io/k6/v2/internal/js/modules/k6/browser/chromium" "go.k6.io/k6/v2/internal/js/modules/k6/browser/common" "go.k6.io/k6/v2/internal/js/modules/k6/browser/env" "go.k6.io/k6/v2/internal/js/modules/k6/browser/k6ext" @@ -41,6 +42,7 @@ type ( // JSModule exposes the properties available to the JS script. JSModule struct { Browser *sobek.Object + Chromium *sobek.Object Devices map[string]common.Device NetworkProfiles map[string]common.NetworkProfile `js:"networkProfiles"` } @@ -76,22 +78,25 @@ func (m *RootModule) NewModuleInstance(vu k6modules.VU) k6modules.Instance { m.initialize(vu) }) + mvu := moduleVU{ + VU: vu, + pidRegistry: m.PidRegistry, + browserRegistry: newBrowserRegistry( + context.Background(), + vu, + m.remoteRegistry, + m.PidRegistry, + m.tracesMetadata, + ), + taskQueueRegistry: newTaskQueueRegistry(vu), + filePersister: m.filePersister, + testRunID: m.testRunID, + } + return &ModuleInstance{ mod: &JSModule{ - Browser: mapBrowserToSobek(moduleVU{ - VU: vu, - pidRegistry: m.PidRegistry, - browserRegistry: newBrowserRegistry( - context.Background(), - vu, - m.remoteRegistry, - m.PidRegistry, - m.tracesMetadata, - ), - taskQueueRegistry: newTaskQueueRegistry(vu), - filePersister: m.filePersister, - testRunID: m.testRunID, - }), + Browser: mapToSobek(mvu, mapBrowser(mvu, mvu.browser)), + Chromium: mapToSobek(mvu, mapChromium(mvu, chromium.NewBrowserType(vu))), Devices: common.GetDevices(), NetworkProfiles: common.GetNetworkProfiles(), }, diff --git a/internal/js/modules/k6/browser/browser/module_test.go b/internal/js/modules/k6/browser/browser/module_test.go index b23f8d523..d658f9184 100644 --- a/internal/js/modules/k6/browser/browser/module_test.go +++ b/internal/js/modules/k6/browser/browser/module_test.go @@ -21,4 +21,5 @@ func TestModuleNew(t *testing.T) { require.NotNil(t, m.mod.Browser, "Browser should be set") require.NotNil(t, m.mod.Devices, "Devices should be set") require.NotNil(t, m.mod.NetworkProfiles, "Profiles should be set") + require.NotNil(t, m.mod.Chromium, "Chromium should be set") } diff --git a/internal/js/modules/k6/browser/browser/registry.go b/internal/js/modules/k6/browser/browser/registry.go index d6f5befdd..1ddc54f2e 100644 --- a/internal/js/modules/k6/browser/browser/registry.go +++ b/internal/js/modules/k6/browser/browser/registry.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "math/big" + "slices" "strconv" "strings" "sync" @@ -178,6 +179,12 @@ type browserRegistry struct { mu sync.RWMutex m map[int64]*common.Browser + // userManaged holds browsers created via chromium.connectOverCDP, keyed by + // iteration. Unlike m (browsers k6 launches/connects from scenario options), + // these are connected by the script at runtime. k6 still sweeps them on + // IterEnd and Exit. A slice (not a single slot) so a repeat connect in the + // same iteration does not clobber the first. + userManaged map[int64][]*common.Browser buildFn browserBuildFunc } @@ -229,6 +236,7 @@ func newBrowserRegistry( vu: vu, tracesMetadata: tracesMetadata, m: make(map[int64]*common.Browser), + userManaged: make(map[int64][]*common.Browser), buildFn: builder, } @@ -259,19 +267,20 @@ func (r *browserRegistry) handleIterEvents( ) for e := range eventsCh { - // If browser module is imported in the test, NewModuleInstance will be called for - // every VU. Because on VU init stage we can not distinguish to which scenario it - // belongs or access its options (because state is nil), we have to always subscribe - // to each VU iter events, including VUs that do not make use of the browser in their - // iterations. - // Therefore, if we get an event that does not correspond to a browser iteration, then - // skip this iteration. We can't just unsubscribe as the VU might be reused in a later - // scenario that does have browser setup. - // TODO try to maybe do this only once per scenario - if !isBrowserIter(r.vu) { - e.Done() - continue - } + // If the browser module is imported, NewModuleInstance runs for every VU, so + // this registry subscribes to iteration events for every VU. At VU init we + // cannot tell which scenario a VU belongs to (state is nil), so we cannot + // subscribe selectively; we also cannot unsubscribe later, since a VU may be + // reused by a later scenario that does use the browser. + // + // This handler used to skip non-browser iterations entirely (an early + // `continue` when !isBrowserIter), because only managed browser scenarios had + // anything to clean up. That is no longer safe: chromium.connectOverCDP lets a + // script create a browser in any iteration, without options.browser. So we now + // process every iteration event and gate only the managed-browser work + // (buildFn on IterStart, deleteBrowser on IterEnd) behind isBrowserIter below; + // the user-managed-browser sweep (closeUserManaged) and endIterationTrace run + // unconditionally on IterEnd. // The context in the VU is not thread safe. It can // be safely accessed during an iteration but not @@ -288,8 +297,17 @@ func (r *browserRegistry) handleIterEvents( continue } + browserIter := isBrowserIter(r.vu) + switch e.Type { case k6event.IterStart: + // Managed browsers are only built for browser scenarios. Connected + // (connectOverCDP) browsers are built lazily at connection time, so + // there is nothing to do at IterStart for them. + if !browserIter { + break + } + // Because VU.State is nil when browser registry is initialized, // we have to initialize traces registry on the first VU iteration // so we can get access to the k6 TracerProvider. @@ -314,8 +332,16 @@ func (r *browserRegistry) handleIterEvents( } r.setBrowser(data.Iteration, b) case k6event.IterEnd: - r.deleteBrowser(data.Iteration) - r.tr.endIterationTrace(data.Iteration) + // Always sweep user-managed browsers and end any iteration trace, + // even for non-browser iterations (connectOverCDP runs in + // iterations without options.browser). + if browserIter { + r.deleteBrowser(data.Iteration) + } + r.closeUserManaged(data.Iteration) + if r.tr != nil { + r.tr.endIterationTrace(data.Iteration) + } default: r.vu.State().Logger.Warnf("received unexpected event type: %v", e.Type) } @@ -397,6 +423,63 @@ func (r *browserRegistry) clear() { b.Close() delete(r.m, id) } + for iter, browsers := range r.userManaged { + for _, b := range browsers { + b.Close() + } + delete(r.userManaged, iter) + } +} + +func (r *browserRegistry) trackUserManagedBrowser(iter int64, b *common.Browser) { + r.mu.Lock() + defer r.mu.Unlock() + + r.userManaged[iter] = append(r.userManaged[iter], b) +} + +func (r *browserRegistry) untrackUserManagedBrowser(iter int64, b *common.Browser) { + r.mu.Lock() + defer r.mu.Unlock() + + s := r.userManaged[iter] + for i, x := range s { + if x == b { + r.userManaged[iter] = append(s[:i], s[i+1:]...) + break + } + } + if len(r.userManaged[iter]) == 0 { + delete(r.userManaged, iter) + } +} + +// userManagedIter returns the iteration a user-managed browser is tracked under +// and whether it is tracked at all. It's used to decide whether a browser +// mapping should expose close() (only user-managed browsers do). +func (r *browserRegistry) userManagedIter(b *common.Browser) (int64, bool) { + r.mu.RLock() + defer r.mu.RUnlock() + + for iter, browsers := range r.userManaged { + if slices.Contains(browsers, b) { + return iter, true + } + } + return 0, false +} + +// closeUserManaged gracefully closes and removes all user-managed browsers for iter. +// Close is done outside the lock because it performs CDP round-trips. +func (r *browserRegistry) closeUserManaged(iter int64) { + r.mu.Lock() + browsers := r.userManaged[iter] + delete(r.userManaged, iter) + r.mu.Unlock() + + for _, b := range browsers { + b.Close() + } } // initTracesRegistry must only be called within an iteration execution, @@ -412,6 +495,26 @@ func (r *browserRegistry) initTracesRegistry() { }) } +// startConnectTrace ensures the per-VU traces registry exists and reuses or +// starts the iteration root span for iter, mirroring the IterStart path used by +// managed browsers. It returns a context carrying both the tracer and the span, +// so browser API calls made over a connectOverCDP browser parent under the +// iteration trace. +func (r *browserRegistry) startConnectTrace(vuCtx context.Context, iter int64) context.Context { + r.initTracesRegistry() + + tracerCtx := common.WithTracer(vuCtx, r.tr.tracer) + // startIterationTrace already reuses an existing span for the same + // iteration, so a repeat connect does not create a second root span. + // Fill in the VU and scenario so connect-only iteration spans carry the + // same test.vu/test.scenario attributes as the managed IterStart path. + return r.tr.startIterationTrace(tracerCtx, k6event.IterData{ + Iteration: iter, + VUID: r.vu.State().VUID, + ScenarioName: k6ext.GetScenarioName(vuCtx), + }) +} + func (r *browserRegistry) stopTracesRegistry() { // Because traces registry is initialized on iterStart event, it is not // initialized for the initial NewModuleInstance call, whose VU does not diff --git a/internal/js/modules/k6/browser/browser/registry_test.go b/internal/js/modules/k6/browser/browser/registry_test.go index 537d4c16d..b04c7d7fd 100644 --- a/internal/js/modules/k6/browser/browser/registry_test.go +++ b/internal/js/modules/k6/browser/browser/registry_test.go @@ -9,7 +9,9 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + sdktrace "go.opentelemetry.io/otel/sdk/trace" + "go.k6.io/k6/v2/internal/js/modules/k6/browser/common" "go.k6.io/k6/v2/internal/js/modules/k6/browser/env" "go.k6.io/k6/v2/internal/js/modules/k6/browser/k6ext/k6test" @@ -317,6 +319,66 @@ func TestBrowserRegistry(t *testing.T) { // Verify there are no browsers left assert.Equal(t, 0, browserRegistry.browserCount()) }) + + // IterEnd must be a no-op for a non-browser iteration that never called + // chromium.connectOverCDP: nothing was built (IterStart is skipped), nothing + // is tracked in userManaged, and the traces registry was never initialized. + // This locks in the `if r.tr != nil` guard and the unconditional + // closeUserManaged sweep on IterEnd — without them, IterEnd would panic here. + t.Run("iterend_noop_on_bare_non_browser_iter", func(t *testing.T) { + t.Parallel() + + var ( + vu = k6test.NewVU(t) + browserRegistry = newBrowserRegistry(context.Background(), vu, remoteRegistry, &pidRegistry{}, nil) + ) + + vu.ActivateVU() + + // Unset the browser type option so this represents a non-browser VU. + delete(vu.StateField.Options.Scenarios["default"].GetScenarioOptions().Browser, "type") + + vu.StartIteration(t, k6test.WithIteration(0)) + + // Nothing built and no traces registry: IterStart is skipped entirely for + // a non-browser iter, and connectOverCDP (which would init the registry) + // was never called. + require.Equal(t, 0, browserRegistry.browserCount()) + require.Nil(t, browserRegistry.tr, "traces registry must not be initialized for a bare non-browser iter") + + // The regression under test: IterEnd reaches closeUserManaged (nothing + // tracked) and the trace guard (r.tr is nil). Neither may panic. + require.NotPanics(t, func() { + vu.EndIteration(t, k6test.WithIteration(0)) + }) + + require.Equal(t, 0, browserRegistry.browserCount()) + require.Nil(t, browserRegistry.tr, "traces registry must remain uninitialized after IterEnd") + }) +} + +func TestStartConnectTraceAttributes(t *testing.T) { + t.Parallel() + + rec := k6test.NewSpanRecorder() + tp := sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(rec)) + + vu := k6test.NewVU(t, k6test.WithTracerProvider(tp)) + vu.ActivateVU() + vu.StartIteration(t) + vu.State().VUID = 42 // non-zero so the test.vu assertion is meaningful + + r := &browserRegistry{ + vu: vu, + m: make(map[int64]*common.Browser), + userManaged: make(map[int64][]*common.Browser), + } + r.startConnectTrace(vu.Context(), vu.State().Iteration) + + span, ok := rec.Find("iteration") + require.True(t, ok, "expected an 'iteration' root span") + require.Equal(t, int64(42), span.AttrInt64(t, "test.vu")) + require.Equal(t, "default", span.AttrString(t, "test.scenario")) } func TestParseTracesMetadata(t *testing.T) { diff --git a/internal/js/modules/k6/browser/chromium/browser_type.go b/internal/js/modules/k6/browser/chromium/browser_type.go index cf900290f..b6d421e02 100644 --- a/internal/js/modules/k6/browser/chromium/browser_type.go +++ b/internal/js/modules/k6/browser/chromium/browser_type.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "math/rand" // nosemgrep: math-random-used // This is used to generate id for easier debugging + "net/url" "os/exec" "path/filepath" "sort" @@ -51,8 +52,28 @@ func NewBrowserType(vu k6modules.VU) *BrowserType { } } +// Clone returns a new BrowserType that reuses the receiver's already +// initialized, thread-safe fields (vu, hooks, k6Metrics, envLookupper) but +// gets its own randSrc and Ctx. +// +// This exists, so callers that need a fresh BrowserType per operation (e.g., +// concurrent ConnectOverCDP calls in the same iteration) don't have to go +// through NewBrowserType, which calls vu.InitEnv() and therefore only works +// during the script init scope, not during an iteration. +// Sharing a single BrowserType across concurrent operations instead would race +// on randSrc (used in initContext) and on the Ctx field (written in Connect). +func (b *BrowserType) Clone() *BrowserType { + return &BrowserType{ + vu: b.vu, + hooks: b.hooks, + k6Metrics: b.k6Metrics, + randSrc: rand.New(rand.NewSource(time.Now().UnixNano())), //nolint: gosec + envLookupper: b.envLookupper, + } +} + func (b *BrowserType) init( - ctx context.Context, isRemoteBrowser bool, + ctx context.Context, isRemoteBrowser bool, scenarioOpts map[string]any, ) (context.Context, *common.BrowserOptions, *log.Logger, error) { ctx = b.initContext(ctx) @@ -68,8 +89,7 @@ func (b *BrowserType) init( browserOpts = common.NewLocalBrowserOptions() } - opts := k6ext.GetScenarioOpts(b.vu.Context(), b.vu) - if err = browserOpts.Parse(ctx, logger, opts, b.envLookupper); err != nil { + if err = browserOpts.Parse(ctx, logger, scenarioOpts, b.envLookupper); err != nil { return nil, nil, nil, fmt.Errorf("error parsing browser options: %w", err) } ctx = common.WithBrowserOptions(ctx, browserOpts) @@ -92,6 +112,67 @@ func (b *BrowserType) initContext(ctx context.Context) context.Context { return ctx } +// ConnectOverCDP attaches the k6 browser to an existing, user-managed browser +// over CDP, without requiring scenario browser options. +// +// The passed context must be the context the caller wants to control both the +// connection and the browser lifetime; when it is canceled (iteration ends), +// the connection is torn down. +func (b *BrowserType) ConnectOverCDP(ctx context.Context, wsEndpoint string) (*common.Browser, error) { + // Validate wsEndpoint up front so an empty or malformed value + // fails fast with a clear error, instead of a confusing lower-level + // connection error. + if err := validateWSEndpoint(wsEndpoint); err != nil { + return nil, err + } + + // Parse browser options from the environment (K6_BROWSER_TIMEOUT, + // K6_BROWSER_DEBUG, the log category filter, ...) like Connect does. Pass a + // fixed chromium type instead of scenario options: connectOverCDP works + // without a browser scenario, and Parse requires the type to be set. + ctx, browserOpts, logger, err := b.init(ctx, true, map[string]any{"type": "chromium"}) + if err != nil { + return nil, fmt.Errorf("initializing browser type: %w", err) + } + + bp, err := b.connect(ctx, ctx, wsEndpoint, browserOpts, logger) + if err != nil { + err = &k6ext.UserFriendlyError{ + Err: err, + Timeout: browserOpts.Timeout, + } + return nil, fmt.Errorf("%w", err) + } + + return bp, nil +} + +// validateWSEndpoint returns an error if wsEndpoint is not a usable CDP +// WebSocket URL, catching common mistakes (an empty value, a non-ws scheme, +// a missing host, etc.) before we attempt to connect. +func validateWSEndpoint(wsEndpoint string) error { + if strings.TrimSpace(wsEndpoint) == "" { + return errors.New("WebSocket endpoint cannot be empty") + } + + u, err := url.Parse(wsEndpoint) + if err != nil { + return fmt.Errorf("invalid WebSocket endpoint %q: %w", wsEndpoint, err) + } + + if u.Scheme != "ws" && u.Scheme != "wss" { + return fmt.Errorf( + "invalid WebSocket endpoint %q: scheme must be ws or wss, got %q", wsEndpoint, u.Scheme, + ) + } + + if u.Hostname() == "" { + return fmt.Errorf("invalid WebSocket endpoint %q: host is missing", wsEndpoint) + } + + return nil +} + // Connect attaches k6 browser to an existing browser instance. // // vuCtx is the context coming from the VU itself. The k6 vu/iteration controls @@ -104,7 +185,7 @@ func (b *BrowserType) initContext(ctx context.Context) context.Context { // the iteration to end (e.g. during a SIGTERM) and unblocks k6 to then fire off // the events which allows the connection to close. func (b *BrowserType) Connect(ctx, vuCtx context.Context, wsEndpoint string) (*common.Browser, error) { - vuCtx, browserOpts, logger, err := b.init(vuCtx, true) + vuCtx, browserOpts, logger, err := b.init(vuCtx, true, k6ext.GetScenarioOpts(b.vu.Context(), b.vu)) if err != nil { return nil, fmt.Errorf("initializing browser type: %w", err) } @@ -170,7 +251,7 @@ func (b *BrowserType) link( // the iteration to end (e.g. during a SIGTERM) and unblocks k6 to then fire off // the events which allows the chromium subprocess to shutdown. func (b *BrowserType) Launch(ctx, vuCtx context.Context) (_ *common.Browser, browserProcessID int, _ error) { - vuCtx, browserOpts, logger, err := b.init(vuCtx, false) + vuCtx, browserOpts, logger, err := b.init(vuCtx, false, k6ext.GetScenarioOpts(b.vu.Context(), b.vu)) if err != nil { return nil, 0, fmt.Errorf("initializing browser type: %w", err) } diff --git a/internal/js/modules/k6/browser/chromium/browser_type_test.go b/internal/js/modules/k6/browser/chromium/browser_type_test.go index a014bbfde..af1836d1c 100644 --- a/internal/js/modules/k6/browser/chromium/browser_type_test.go +++ b/internal/js/modules/k6/browser/chromium/browser_type_test.go @@ -1,6 +1,7 @@ package chromium import ( + "context" "io/fs" "net" "path/filepath" @@ -9,6 +10,7 @@ import ( "go.k6.io/k6/v2/internal/js/modules/k6/browser/common" "go.k6.io/k6/v2/internal/js/modules/k6/browser/env" + "go.k6.io/k6/v2/internal/js/modules/k6/browser/k6ext/k6test" k6lib "go.k6.io/k6/v2/lib" k6types "go.k6.io/k6/v2/lib/types" @@ -17,6 +19,56 @@ import ( "github.com/stretchr/testify/require" ) +// TestBrowserTypeInitParsesEnvWithoutScenario locks in the connectOverCDP use +// case: a plain script has no options.browser, so init must parse browser +// options from the environment using only the fixed chromium type that +// ConnectOverCDP passes, without requiring scenario options. +func TestBrowserTypeInitParsesEnvWithoutScenario(t *testing.T) { + t.Parallel() + + vu := k6test.NewVU(t) + bt := NewBrowserType(vu) + vu.ActivateVU() + + _, opts, _, err := bt.init(context.Background(), true, map[string]any{"type": "chromium"}) + require.NoError(t, err) + require.NotNil(t, opts) +} + +// TestValidateWSEndpoint pins the fast-fail validation for connectOverCDP +// endpoints. +func TestValidateWSEndpoint(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + endpoint string + wantErr string // substring; empty means the endpoint must be accepted + }{ + {"valid ws", "ws://localhost:9222", ""}, + {"valid wss with path", "wss://example.com/devtools/browser/abc", ""}, + {"empty", "", "cannot be empty"}, + {"blank", " ", "cannot be empty"}, + {"wrong scheme", "http://localhost:9222", "scheme must be ws or wss"}, + {"missing scheme", "localhost:9222", "scheme must be ws or wss"}, + {"no host with path", "ws:///devtools/browser/id", "host is missing"}, + {"opaque no host", "ws:localhost:9222", "host is missing"}, + {"port only no host", "ws://:9222", "host is missing"}, + } + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + + err := validateWSEndpoint(tc.endpoint) + if tc.wantErr == "" { + require.NoError(t, err) + return + } + require.ErrorContains(t, err, tc.wantErr) + }) + } +} + func TestBrowserTypePrepareFlags(t *testing.T) { t.Parallel() diff --git a/internal/js/modules/k6/browser/common/browser.go b/internal/js/modules/k6/browser/common/browser.go index ea1480144..9f6ac0efe 100644 --- a/internal/js/modules/k6/browser/common/browser.go +++ b/internal/js/modules/k6/browser/common/browser.go @@ -624,15 +624,26 @@ func (b *Browser) Close() { b.logger.Errorf("Browser:Close", "closing the browser: %v", err) } } - // Wait for all outstanding events (e.g. Target.detachedFromTarget) to be - // processed, and for the process to exit gracefully. Otherwise kill it - // forcefully after the timeout. + + // Wait for outstanding teardown to drain before closing the connection, so + // in-flight CDP messages (e.g. Target.detachedFromTarget) are delivered + // rather than dropped by an early WebSocket close. timeout := time.Second - select { - case <-b.browserProc.processDone: - case <-time.After(timeout): - b.logger.Debugf("Browser:Close", "killing browser process with PID %d after %s", b.browserProc.Pid(), timeout) - b.browserProc.Terminate() + if b.browserOpts.isRemoteBrowser { + // A remote browser has no local process to wait on, so waiting on + // processDone would always hit the full timeout. Instead, wait, up to the + // timeout, for our targets' detach events to be delivered — observed as + // the pages draining to zero — then close. + b.waitForPagesToDetach(timeout) + } else { + // Wait for the process to exit gracefully; otherwise kill it forcefully + // after the timeout. + select { + case <-b.browserProc.processDone: + case <-time.After(timeout): + b.logger.Debugf("Browser:Close", "killing browser process with PID %d after %s", b.browserProc.Pid(), timeout) + b.browserProc.Terminate() + } } // This is unintuitive, since the process exited, so the connection would've // been closed as well. The reason we still call conn.Close() here is to @@ -645,6 +656,34 @@ func (b *Browser) Close() { b.conn.Close() } +// waitForPagesToDetach waits, up to timeout, for the browser's own pages to +// drain to zero. Closing pages triggers Target.detachedFromTarget events; a +// page leaves b.pages only once its event has been received and processed. +// +// This is a barrier on our own targets' teardown, NOT on the connection going +// quiet: a remote browser we don't own keeps emitting unsolicited events right +// up to conn.Close(), and those may still be dropped. That's harmless for us +// (we've decided we're done), but the guarantee is only "our page detaches are +// processed", not "all in-flight messages are delivered". It's a bounded, +// event-driven alternative to waiting on a process exit, which a remote browser +// doesn't have. +func (b *Browser) waitForPagesToDetach(timeout time.Duration) { + ticker := time.NewTicker(20 * time.Millisecond) + defer ticker.Stop() + + deadline := time.After(timeout) + for len(b.getPages()) > 0 { + select { + case <-deadline: + b.logger.Debugf("Browser:Close", + "timed out after %s waiting for %d page(s) to detach; closing anyway", + timeout, len(b.getPages())) + return + case <-ticker.C: + } + } +} + // CloseContext is a short-cut function to close the current browser's context. // If there is no active browser context, it returns an error. func (b *Browser) CloseContext() error { @@ -662,7 +701,7 @@ func (b *Browser) Context() *BrowserContext { // IsConnected returns whether the WebSocket connection to the browser process // is active or not. func (b *Browser) IsConnected() bool { - return b.browserProc.isConnected() + return !b.closing.Load() && b.browserProc.isConnected() } // NewContext creates a new incognito-like browser context. @@ -670,6 +709,9 @@ func (b *Browser) NewContext(opts *BrowserContextOptions) (*BrowserContext, erro _, span := TraceAPICall(b.vuCtx, "", "browser.newContext") defer span.End() + if b.closing.Load() { + return nil, spanRecordErrorf(span, "browser has been closed") + } if b.context != nil { return nil, spanRecordErrorf(span, "existing browser context must be closed before creating a new one") } diff --git a/internal/js/modules/k6/browser/k6ext/k6test/span_recorder.go b/internal/js/modules/k6/browser/k6ext/k6test/span_recorder.go new file mode 100644 index 000000000..08449852d --- /dev/null +++ b/internal/js/modules/k6/browser/k6ext/k6test/span_recorder.go @@ -0,0 +1,105 @@ +package k6test + +import ( + "context" + "sync" + "testing" + + "go.opentelemetry.io/otel/attribute" + sdktrace "go.opentelemetry.io/otel/sdk/trace" + oteltrace "go.opentelemetry.io/otel/trace" +) + +// RecordedSpan is a snapshot of a span captured by a SpanRecorder, exposing just +// enough for tests to assert on span names, parentage, attributes and end state. +type RecordedSpan struct { + Name string + TraceID oteltrace.TraceID + SpanID oteltrace.SpanID + ParentID oteltrace.SpanID + Attrs []attribute.KeyValue +} + +// AttrInt64 returns the int64 value of the named attribute on the span, failing +// the test if it is absent. +func (s RecordedSpan) AttrInt64(tb testing.TB, key string) int64 { + tb.Helper() + for _, kv := range s.Attrs { + if string(kv.Key) == key { + return kv.Value.AsInt64() + } + } + tb.Fatalf("attribute %q not found on span %q", key, s.Name) + return 0 +} + +// AttrString returns the string value of the named attribute on the span, +// failing the test if it is absent. +func (s RecordedSpan) AttrString(tb testing.TB, key string) string { + tb.Helper() + for _, kv := range s.Attrs { + if string(kv.Key) == key { + return kv.Value.AsString() + } + } + tb.Fatalf("attribute %q not found on span %q", key, s.Name) + return "" +} + +// SpanRecorder is a minimal sdktrace.SpanProcessor that records started spans +// (for name/parent/attribute inspection) and which span ids have ended. +type SpanRecorder struct { + mu sync.Mutex + started []RecordedSpan + ended map[oteltrace.SpanID]bool +} + +// NewSpanRecorder returns a ready-to-use SpanRecorder. +func NewSpanRecorder() *SpanRecorder { + return &SpanRecorder{ended: make(map[oteltrace.SpanID]bool)} +} + +// OnStart implements sdktrace.SpanProcessor. +func (r *SpanRecorder) OnStart(_ context.Context, s sdktrace.ReadWriteSpan) { + r.mu.Lock() + defer r.mu.Unlock() + r.started = append(r.started, RecordedSpan{ + Name: s.Name(), + TraceID: s.SpanContext().TraceID(), + SpanID: s.SpanContext().SpanID(), + ParentID: s.Parent().SpanID(), + Attrs: s.Attributes(), + }) +} + +// OnEnd implements sdktrace.SpanProcessor. +func (r *SpanRecorder) OnEnd(s sdktrace.ReadOnlySpan) { + r.mu.Lock() + defer r.mu.Unlock() + r.ended[s.SpanContext().SpanID()] = true +} + +// Shutdown implements sdktrace.SpanProcessor. +func (r *SpanRecorder) Shutdown(context.Context) error { return nil } + +// ForceFlush implements sdktrace.SpanProcessor. +func (r *SpanRecorder) ForceFlush(context.Context) error { return nil } + +// Find returns the first recorded span with the given name. +func (r *SpanRecorder) Find(name string) (RecordedSpan, bool) { + r.mu.Lock() + defer r.mu.Unlock() + for _, s := range r.started { + if s.Name == name { + return s, true + } + } + return RecordedSpan{}, false +} + +// IsEnded reports whether the span with the given id has ended. +func (r *SpanRecorder) IsEnded(id oteltrace.SpanID) bool { + r.mu.Lock() + defer r.mu.Unlock() + return r.ended[id] +} diff --git a/internal/js/modules/k6/browser/tests/browser_context_test.go b/internal/js/modules/k6/browser/tests/browser_context_test.go index c1afe617f..8f5c56295 100644 --- a/internal/js/modules/k6/browser/tests/browser_context_test.go +++ b/internal/js/modules/k6/browser/tests/browser_context_test.go @@ -11,8 +11,10 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.k6.io/k6/v2/internal/js/modules/k6/browser/browser" "go.k6.io/k6/v2/internal/js/modules/k6/browser/common" "go.k6.io/k6/v2/internal/js/modules/k6/browser/env" + "go.k6.io/k6/v2/internal/js/modules/k6/browser/k6ext/k6test" ) func TestBrowserContextAddCookies(t *testing.T) { @@ -992,3 +994,127 @@ func TestBrowserContextMappingBehavior(t *testing.T) { require.NoError(t, err) require.True(t, value.ToBoolean()) } + +// TestChromiumConnectOverCDPContextBrowserPlain covers a connectOverCDP script +// with no managed browser in the registry: the owning browser must be reachable +// via context().browser(). +func TestChromiumConnectOverCDPContextBrowserPlain(t *testing.T) { + t.Parallel() + + tb := newTestBrowser(t) + + // No StartIteration, so the managed-browser registry stays empty (as in a + // script with no options.browser). + vu := k6test.NewVU(t) + mod := browser.New().NewModuleInstance(vu) + jsMod, ok := mod.Exports().Default.(*browser.JSModule) + require.Truef(t, ok, "unexpected default mod export type %T", mod.Exports().Default) + vu.ActivateVU() + vu.SetVar(t, "chromium", jsMod.Chromium) + + _, err := vu.RunAsync(t, ` + const b = await chromium.connectOverCDP("%s"); + const p = await b.newPage(); + p.context().browser().version(); + await b.close(); + `, tb.wsURL) + require.NoError(t, err) +} + +// TestChromiumConnectOverCDPContextBrowserOwner covers the silent wrong-browser +// case: with a managed browser also present, context().browser() must return the +// connectOverCDP browser that owns the context, not the managed one. Closing the +// connectOverCDP browser must therefore disconnect the browser reached via +// context().browser(). +func TestChromiumConnectOverCDPContextBrowserOwner(t *testing.T) { + t.Parallel() + + tb := newTestBrowser(t) + vu := setupChromiumVU(t) // StartIteration also builds a managed browser + + // context().browser() must be the connectOverCDP browser that owns the + // context, so closing that browser disconnects the one reached via + // context().browser() (isConnected() flips synchronously on close). + _, err := vu.RunAsync(t, ` + const b = await chromium.connectOverCDP("%s"); + const p = await b.newPage(); + const owner = p.context().browser(); + await b.close(); + if (owner.isConnected()) { + throw new Error("context().browser() should be the connectOverCDP browser, disconnected after close"); + } + `, tb.wsURL) + require.NoError(t, err) +} + +// TestChromiumConnectOverCDPContextBrowserExposesClose verifies that a +// connectOverCDP browser reached via context().browser() exposes a working +// close(). +func TestChromiumConnectOverCDPContextBrowserExposesClose(t *testing.T) { + t.Parallel() + + tb := newTestBrowser(t) + vu := setupChromiumVU(t) + + _, err := vu.RunAsync(t, ` + const b = await chromium.connectOverCDP("%s"); + const p = await b.newPage(); + const owner = p.context().browser(); + if (typeof owner.close !== "function") { + throw new Error("expected close() on connectOverCDP browser via context().browser()"); + } + await owner.close(); // close via context().browser() + if (owner.isConnected()) { + throw new Error("close() via context().browser() should disconnect the browser"); + } + `, tb.wsURL) + require.NoError(t, err) +} + +// TestBrowserContextBrowserNoCloseForManaged verifies that a managed browser +// reached via context().browser() does NOT expose close(): the registry owns its +// lifecycle. Only user-managed (connectOverCDP) browsers get close(). +func TestBrowserContextBrowserNoCloseForManaged(t *testing.T) { + t.Parallel() + + vu := k6test.NewVU(t) + mod := browser.New().NewModuleInstance(vu) + jsMod, ok := mod.Exports().Default.(*browser.JSModule) + require.Truef(t, ok, "unexpected default mod export type %T", mod.Exports().Default) + vu.ActivateVU() + vu.StartIteration(t) // builds the managed browser + vu.SetVar(t, "browser", jsMod.Browser) + + _, err := vu.RunAsync(t, ` + const p = await browser.newPage(); + if (typeof p.context().browser().close !== "undefined") { + throw new Error("managed browser via context().browser() must not expose close()"); + } + await p.close(); + `) + require.NoError(t, err) +} + +// TestChromiumConnectOverCDPUseAfterClose verifies that using a connectOverCDP +// browser after close() gives a clear "browser has been closed" error. +func TestChromiumConnectOverCDPUseAfterClose(t *testing.T) { + t.Parallel() + + tb := newTestBrowser(t) + vu := setupChromiumVU(t) + + _, err := vu.RunAsync(t, ` + const b = await chromium.connectOverCDP("%s"); + await b.close(); + let msg = ""; + try { + await b.newPage(); + } catch (e) { + msg = String(e); + } + if (!msg.includes("browser has been closed")) { + throw new Error("expected 'browser has been closed', got: " + msg); + } + `, tb.wsURL) + require.NoError(t, err) +} diff --git a/internal/js/modules/k6/browser/tests/browser_type_test.go b/internal/js/modules/k6/browser/tests/browser_type_test.go index 5b72dbc16..f127c80bc 100644 --- a/internal/js/modules/k6/browser/tests/browser_type_test.go +++ b/internal/js/modules/k6/browser/tests/browser_type_test.go @@ -5,7 +5,9 @@ import ( "testing" "github.com/stretchr/testify/require" + sdktrace "go.opentelemetry.io/otel/sdk/trace" + k6event "go.k6.io/k6/v2/internal/event" "go.k6.io/k6/v2/internal/js/modules/k6/browser/browser" "go.k6.io/k6/v2/internal/js/modules/k6/browser/chromium" "go.k6.io/k6/v2/internal/js/modules/k6/browser/env" @@ -29,6 +31,225 @@ func TestBrowserTypeConnect(t *testing.T) { require.NoError(t, err) } +func TestBrowserTypeConnectOverCDP(t *testing.T) { + t.Parallel() + + // Start a test browser so we can get its WS URL + // and connect through BrowserType.ConnectOverCDP. + tb := newTestBrowser(t) + vu := k6test.NewVU(t) + bt := chromium.NewBrowserType(vu) + vu.ActivateVU() + + b, err := bt.ConnectOverCDP(context.Background(), tb.wsURL) + require.NoError(t, err) + t.Cleanup(b.Close) + + _, err = b.NewPage(nil) + require.NoError(t, err) +} + +func TestBrowserTypeConnectOverCDPValidation(t *testing.T) { + t.Parallel() + + // Invalid endpoints must fail immediately, before any connection attempt, + // so no test browser is needed. + vu := k6test.NewVU(t) + bt := chromium.NewBrowserType(vu) + vu.ActivateVU() + + for _, wsEndpoint := range []string{ + "", // empty (e.g. an undefined value or failed lookup) + " ", // blank + "http://localhost:9222", // wrong scheme + "localhost:9222", // missing ws/wss scheme + } { + _, err := bt.ConnectOverCDP(context.Background(), wsEndpoint) + require.Errorf(t, err, "endpoint %q should be rejected", wsEndpoint) + } +} + +// TestChromiumConnectOverCDPAppliesBrowserTimeout verifies that ConnectOverCDP +// parses browser options from the environment. E.g., with K6_BROWSER_TIMEOUT=1ms +// a browser operation (e.g., NewPage) must time out. +func TestChromiumConnectOverCDPAppliesBrowserTimeout(t *testing.T) { + t.Parallel() + + tb := newTestBrowser(t) + vu := k6test.NewVU(t, env.ConstLookup(env.BrowserGlobalTimeout, "1ms")) + bt := chromium.NewBrowserType(vu) + vu.ActivateVU() + + b, err := bt.ConnectOverCDP(context.Background(), tb.wsURL) + require.NoError(t, err) + t.Cleanup(b.Close) + + _, err = b.NewPage(nil) + require.Error(t, err, "NewPage should time out with K6_BROWSER_TIMEOUT=1ms") +} + +// setupChromiumVU builds a VU with the browser module's chromium object bound +// to the "chromium" global and an iteration started, ready to run +// connectOverCDP scripts via RunAsync. +func setupChromiumVU(t *testing.T, opts ...any) *k6test.VU { + t.Helper() + + vu := k6test.NewVU(t, opts...) + mod := browser.New().NewModuleInstance(vu) + jsMod, ok := mod.Exports().Default.(*browser.JSModule) + require.Truef(t, ok, "unexpected default mod export type %T", mod.Exports().Default) + + vu.ActivateVU() + vu.StartIteration(t) + vu.SetVar(t, "chromium", jsMod.Chromium) + + return vu +} + +// TestChromiumConnectOverCDPConcurrent is a regression test for a data race +// where two concurrent chromium.connectOverCDP calls in the same iteration +// used to race. +func TestChromiumConnectOverCDPConcurrent(t *testing.T) { + t.Parallel() + + tb := newTestBrowser(t) + vu := setupChromiumVU(t) + _, err := vu.RunAsync(t, ` + await Promise.all([ + chromium.connectOverCDP("%s"), + chromium.connectOverCDP("%s"), + ].map(async (p) => { + const b = await p; + const pg = await b.newPage(); + await pg.close(); + await b.close(); + })); + `, tb.wsURL, tb.wsURL) + require.NoError(t, err) +} + +func TestChromiumConnectOverCDPAutoClose(t *testing.T) { + t.Parallel() + + tb := newTestBrowser(t) + vu := setupChromiumVU(t) + _, err := vu.RunAsync(t, ` + const b = await chromium.connectOverCDP("%s"); + const p = await b.newPage(); + await p.close(); + if (!b.isConnected()) { + throw new Error("expected browser to be connected before iteration end"); + } + // Stash the browser so we can check its state after the iteration + // ends, once the registry sweep has had a chance to run. + globalThis.__cdpBrowser = b; + // Intentionally NOT calling b.close(). + `, tb.wsURL) + require.NoError(t, err) + + // End the iteration; the registry sweep must close the connected browser. + vu.EndIteration(t) + + // Verify the sweep actually closed the browser, instead of just trusting + // that EndIteration didn't error out. + got := vu.RunPromise(t, "return globalThis.__cdpBrowser.isConnected();") + require.False(t, got.Result().ToBoolean(), "expected browser to be disconnected after iteration end") +} + +func TestChromiumConnectOverCDPExplicitClose(t *testing.T) { + t.Parallel() + + tb := newTestBrowser(t) + vu := setupChromiumVU(t) + _, err := vu.RunAsync(t, ` + const b = await chromium.connectOverCDP("%s"); + const p = await b.newPage(); + await p.close(); + await b.close(); + `, tb.wsURL) + require.NoError(t, err) + + // Ending the iteration after an explicit close must not panic or + // double-close (untrack removed it from the sweep set). + vu.EndIteration(t) +} + +// TestChromiumConnectOverCDPExitSweep verifies that a connected browser left +// open when the test exits (e.g., SIGTERM mid-iteration) is closed by the +// registry's Exit sweep (clear), not only by the per-iteration IterEnd sweep. +func TestChromiumConnectOverCDPExitSweep(t *testing.T) { + t.Parallel() + + tb := newTestBrowser(t) + vu := setupChromiumVU(t) + _, err := vu.RunAsync(t, ` + const b = await chromium.connectOverCDP("%s"); + const p = await b.newPage(); + await p.close(); + // Stash the browser so we can check its state after the Exit sweep, + // and intentionally do NOT close it or end the iteration. + globalThis.__cdpBrowser = b; + `, tb.wsURL) + require.NoError(t, err) + + // Fire the global Exit event, as k6 does on process exit / SIGTERM. The + // registry's clear() must close any still-connected browsers. + events, ok := vu.EventsField.Global.(*k6event.System) + require.True(t, ok, "want *k6event.System; got %T", events) + waitDone := events.Emit(&k6event.Event{Type: k6event.Exit}) + require.NoError(t, waitDone(context.Background()), "error waiting on Exit done") + + // Verify the Exit sweep actually closed the connected browser. + got := vu.RunPromise(t, "return globalThis.__cdpBrowser.isConnected();") + require.False(t, got.Result().ToBoolean(), "expected browser to be disconnected after Exit sweep") +} + +// TestChromiumConnectOverCDPTraceLinkage verifies that a call made over a +// connectOverCDP browser produces a span parented under an iteration root +// span keyed by the real iteration number, and that root span is +// ended at IterEnd. +// It uses a recording tracer provider to inspect the span tree. +func TestChromiumConnectOverCDPTraceLinkage(t *testing.T) { + t.Parallel() + + rec := k6test.NewSpanRecorder() + tp := sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(rec)) + + tb := newTestBrowser(t) + vu := setupChromiumVU(t, k6test.WithTracerProvider(tp)) + wantIter := vu.State().Iteration + + _, err := vu.RunAsync(t, ` + const b = await chromium.connectOverCDP("%s"); + const p = await b.newPage(); + await p.close(); + await b.close(); + `, tb.wsURL) + require.NoError(t, err) + + // End the iteration so the iteration root span is closed. + vu.EndIteration(t) + + iterSpan, ok := rec.Find("iteration") + require.True(t, ok, "expected an 'iteration' root span") + newPageSpan, ok := rec.Find("browser.newPage") + require.True(t, ok, "expected a 'browser.newPage' span") + + // The browser API span must be parented under the iteration trace that + // connectOverCDP established. If startConnectTrace did not wire the tracer + // into the browser's context, browser.newPage would be a noop/orphaned span + // and these assertions would fail. + require.Equal(t, iterSpan.TraceID, newPageSpan.TraceID, + "browser.newPage span should be in the same trace as the iteration span") + require.Equal(t, iterSpan.SpanID, newPageSpan.ParentID, + "browser.newPage span should be parented under the iteration span") + + // The iteration span must be keyed by the real iteration number and ended + // when the iteration ends. + require.Equal(t, wantIter, iterSpan.AttrInt64(t, "test.iteration.number")) + require.True(t, rec.IsEnded(iterSpan.SpanID), "iteration span should be ended at IterEnd") +} + func TestBrowserTypeLaunchToConnect(t *testing.T) { t.Parallel() diff --git a/internal/js/modules/k6/browser/tests/test_browser_proxy.go b/internal/js/modules/k6/browser/tests/test_browser_proxy.go index 1e170e845..6df4f7b7e 100644 --- a/internal/js/modules/k6/browser/tests/test_browser_proxy.go +++ b/internal/js/modules/k6/browser/tests/test_browser_proxy.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "net" "net/http" "net/http/httptest" "net/url" @@ -102,9 +103,8 @@ LOOP: default: mt, message, err := in.ReadMessage() if err != nil { - var cerr *websocket.CloseError - if errors.As(err, &cerr) { - // If WS conn is closed, just return + if isConnShuttingDown(err) { + // If either WS conn is closing, just return. return } p.t.Fatalf("error reading message: %v", err) @@ -112,9 +112,8 @@ LOOP: err = out.WriteMessage(mt, message) if err != nil { - var cerr *websocket.CloseError - if errors.As(err, &cerr) { - // If WS conn is closed, just return + if isConnShuttingDown(err) { + // If either WS conn is closing, just return. return } p.t.Fatalf("error writing message: %v", err) @@ -122,3 +121,16 @@ LOOP: } } } + +// isConnShuttingDown reports whether err indicates one of the proxied WS +// connections is closing, so forwarding should stop cleanly instead of failing +// the test. This covers the peer sending a close frame (*websocket.CloseError), +// this side having already sent its own close frame (websocket.ErrCloseSent, +// e.g. when a client closes its connection while the browser is still emitting +// unsolicited events), and the underlying socket being closed (net.ErrClosed). +func isConnShuttingDown(err error) bool { + var cerr *websocket.CloseError + return errors.As(err, &cerr) || + errors.Is(err, websocket.ErrCloseSent) || + errors.Is(err, net.ErrClosed) +} From 2bd43af70ae7405c68ee8dc927cf69b6abd12fde Mon Sep 17 00:00:00 2001 From: Dhia Abbassi <95589303+d14c@users.noreply.github.com> Date: Thu, 30 Jul 2026 11:02:52 +0200 Subject: [PATCH 088/182] fix: stop sending invalid Sec-WebSocket-Protocol for cloud log tail (#6205) Signed-off-by: Dhia Abbassi --- cloudapi/logs.go | 1 - cloudapi/logs_test.go | 6 +++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cloudapi/logs.go b/cloudapi/logs.go index 0c30d2347..806bc2519 100644 --- a/cloudapi/logs.go +++ b/cloudapi/logs.go @@ -94,7 +94,6 @@ func (c *Config) logtailConn(ctx context.Context, referenceID string, since time u.RawQuery = fmt.Sprintf(`query={test_run_id="%s"}&start=%d`, referenceID, since.UnixNano()) headers := make(http.Header) - headers.Add("Sec-WebSocket-Protocol", "token="+c.Token.String) headers.Add("Authorization", "token "+c.Token.String) headers.Add("X-K6testrun-Id", referenceID) diff --git a/cloudapi/logs_test.go b/cloudapi/logs_test.go index d373429a7..38bf6d4b3 100644 --- a/cloudapi/logs_test.go +++ b/cloudapi/logs_test.go @@ -214,6 +214,7 @@ func TestStreamLogsToLogger(t *testing.T) { wsurl := strings.TrimPrefix(tb.ServerHTTP.URL, "http://") return Config{ LogsTailURL: null.NewString(fmt.Sprintf("ws://%s/api/v1/tail", wsurl), false), + Token: null.NewString("fake-token", true), } } @@ -236,7 +237,10 @@ func TestStreamLogsToLogger(t *testing.T) { defer cancel() tb := httpmultibin.NewHTTPMultiBin(t) - logtailHandleFunc(tb, func(conn *websocket.Conn, _ *http.Request) { + logtailHandleFunc(tb, func(conn *websocket.Conn, req *http.Request) { + assert.Equal(t, "token fake-token", req.Header.Get("Authorization")) + assert.Equal(t, "ref_id", req.Header.Get("X-K6testrun-Id")) + rawmsg := json.RawMessage(generateLogline("stream1", 1598282752000000000, "logline1")) err := conn.WriteJSON(rawmsg) require.NoError(t, err) From 8e3e3bfe8cc56c8710dcafcf3eae6c6035bdd2ed Mon Sep 17 00:00:00 2001 From: Ankur Date: Thu, 30 Jul 2026 10:11:24 +0100 Subject: [PATCH 089/182] Support externally-provisioned runs in cloud run --local-execution (#6170) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add env bindings for provisioning push creds Give cloudapi.Config.MetricsPushURL and TestRunToken envconfig tags (K6_CLOUD_METRICS_PUSH_URL, K6_CLOUD_TEST_RUN_TOKEN) so an external service that provisioned a run can hand the scoped push URL + test-run token to a local `k6 cloud run --local-execution`. Self-provision and `--out cloud` are unaffected (nothing sets these env vars in those flows). The long-lived org token remains the sensitive credential and is unchanged. * Use provisioning push for external runs Push to the provisioning URL with the scoped token whenever MetricsPushURL + TestRunToken are set, even when PushRefID is present (an external service provisioned the run and owns its lifecycle). Skip the notifier in that case — testFinished already suppresses notify on PushRefID, so it would be unused. Reject a half-set credential pair instead of silently using legacy push. * Fix env override of scoped push creds The scoped push creds (MetricsPushURL, TestRunToken) were bound to K6_CLOUD_METRICS_PUSH_URL / K6_CLOUD_TEST_RUN_TOKEN via envconfig so an externally-provisioned run could receive them. But the cloud Output re-consolidates its config with env applied last, so a stray env var (or a stale config-file value) overrode the run-scoped values k6 gets from start_local_execution, breaking the self-provisioned push. Drop the two envconfig tags; the fields are now programmatic-only. Instead read the two env vars explicitly in the PushRefID branch of createCloudTest, validate both-or-neither, and bake them into the serialized cloud config the Output reads. The self-provisioned path is now immune to stray env/config values, and the externally-provisioned path keeps working. Add TestExtProvMatrix: an end-to-end matrix over the self-provisioned, externally-provisioned, PushRefID-relay and legacy --out cloud paths. --- cloudapi/config.go | 25 +- internal/cmd/outputs_cloud.go | 39 ++ .../cmd_cloud_run_push_credentials_test.go | 353 ++++++++++++++++++ internal/output/cloud/output.go | 29 +- internal/output/cloud/output_test.go | 129 ++++++- 5 files changed, 546 insertions(+), 29 deletions(-) create mode 100644 internal/cmd/tests/cmd_cloud_run_push_credentials_test.go diff --git a/cloudapi/config.go b/cloudapi/config.go index 7ff3dd626..151883ea6 100644 --- a/cloudapi/config.go +++ b/cloudapi/config.go @@ -34,18 +34,23 @@ type Config struct { StopOnError null.Bool `json:"stopOnError" envconfig:"K6_CLOUD_STOP_ON_ERROR"` APIVersion null.Int `json:"apiVersion" envconfig:"K6_CLOUD_API_VERSION"` - // MetricsPushURL is the explicit URL to push metrics to, returned by - // the provisioning API's start_local_execution endpoint. When set, the - // cloud Output uses this URL instead of deriving one from Host. Set - // programmatically by `cmd/outputs_cloud.go` for the - // `k6 cloud run --local-execution` provisioning flow; never set via - // env vars or user-facing config. + // MetricsPushURL is the URL to push metrics to. It is set only + // programmatically: from the provisioning API's start_local_execution + // response in the self-provision flow, or from K6_CLOUD_METRICS_PUSH_URL + // read explicitly by the cmd layer (internal/cmd/outputs_cloud.go) in the + // externally-provisioned flow. It is deliberately NOT env-bound (no + // envconfig tag): binding it would let a stray K6_CLOUD_METRICS_PUSH_URL + // in the environment override the value obtained from provisioning and + // corrupt the self-provisioned push. When set, the cloud Output pushes + // here instead of deriving a URL from Host. MetricsPushURL null.String `json:"metricsPushURL"` - // TestRunToken is the scoped test-run token returned by the - // provisioning API's start_local_execution endpoint. When set, the - // cloud Output uses it as the Bearer token for metrics push and notify. - // Set programmatically; never set via env vars or user-facing config. + // TestRunToken is the scoped test-run token used as the Bearer token for + // metrics push (and notify, in the self-provision flow). Like + // MetricsPushURL it is set only programmatically — from the provisioning + // response, or from K6_CLOUD_TEST_RUN_TOKEN read explicitly by the cmd + // layer for an externally-provisioned run — and is deliberately NOT + // env-bound, so a stray env var cannot hijack the self-provisioned push. TestRunToken null.String `json:"testRunToken"` // PushRefID is the identifier used by k6 Cloud to correlate all the things that diff --git a/internal/cmd/outputs_cloud.go b/internal/cmd/outputs_cloud.go index eb16849a7..df9b160c7 100644 --- a/internal/cmd/outputs_cloud.go +++ b/internal/cmd/outputs_cloud.go @@ -97,6 +97,9 @@ func createCloudTest(gs *state.GlobalState, test *loadedAndConfiguredTest) error } if conf.PushRefID.Valid && conf.PushRefID.String != "" { + if err := applyExternalProvisioningCreds(gs, test, &conf); err != nil { + return err + } test.preInitState.RuntimeOptions.Env[testRunIDKey] = conf.PushRefID.String gs.Logger.Debug("using PushRefID, skipping CreateTestRun") return nil @@ -187,6 +190,42 @@ func createCloudTest(gs *state.GlobalState, test *loadedAndConfiguredTest) error return nil } +// applyExternalProvisioningCreds handles the externally-provisioned +// `--local-execution` flow, signalled by K6_CLOUD_PUSH_REF_ID: an external +// service created and started the run and hands its scoped push credentials +// to this local k6 via env. It reads K6_CLOUD_METRICS_PUSH_URL and +// K6_CLOUD_TEST_RUN_TOKEN explicitly here — they are deliberately NOT +// env-bound on cloudapi.Config, so a stray env var can never override the +// values the self-provision flow obtains from the provisioning response. +// It requires both-or-neither and, when both are present, sets them on conf +// (so downstream consumers such as the log pusher see them) and bakes them +// into the serialized cloud config that the Output reads. +func applyExternalProvisioningCreds( + gs *state.GlobalState, test *loadedAndConfiguredTest, conf *cloudapi.Config, +) error { + pushURL := gs.Env["K6_CLOUD_METRICS_PUSH_URL"] + token := gs.Env["K6_CLOUD_TEST_RUN_TOKEN"] + if (pushURL == "") != (token == "") { + return errors.New("both K6_CLOUD_METRICS_PUSH_URL and " + + "K6_CLOUD_TEST_RUN_TOKEN must be set together") + } + if pushURL == "" { + return nil + } + + conf.MetricsPushURL = null.StringFrom(pushURL) + conf.TestRunToken = null.StringFrom(token) + raw, err := cloudConfToRawMessage(*conf) + if err != nil { + return fmt.Errorf("could not serialize cloud configuration: %w", err) + } + if test.derivedConfig.Collectors == nil { + test.derivedConfig.Collectors = make(map[string]json.RawMessage) + } + test.derivedConfig.Collectors[builtinOutputCloud.String()] = raw + return nil +} + // validateRequiredSystemTags checks if all required tags are present. func validateRequiredSystemTags(scriptTags *metrics.SystemTagSet) error { var missingRequiredTags []string diff --git a/internal/cmd/tests/cmd_cloud_run_push_credentials_test.go b/internal/cmd/tests/cmd_cloud_run_push_credentials_test.go new file mode 100644 index 000000000..fcb74f4dc --- /dev/null +++ b/internal/cmd/tests/cmd_cloud_run_push_credentials_test.go @@ -0,0 +1,353 @@ +package tests + +import ( + "fmt" + "io" + "net/http" + "path/filepath" + "strings" + "sync" + "sync/atomic" + "testing" + + k6cloud "github.com/grafana/k6-cloud-openapi-client-go/k6" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + provtest "go.k6.io/k6/v2/internal/cloudapi/provisioning/test" + v6 "go.k6.io/k6/v2/internal/cloudapi/v6" + "go.k6.io/k6/v2/internal/cmd" + "go.k6.io/k6/v2/lib/fsext" +) + +// Sentinel credentials. Each has a single, distinct source so a test can +// tell exactly which one k6 used to push metrics. +const ( + orgToken = "org-longlived-token" // K6_CLOUD_TOKEN: legacy / relay push + scopedToken = "test-run-token-abc" // from the provisioning response + bogusToken = "bogus-env-token" // a stray value in the environment + extToken = "ext-scoped-token" // an externally-supplied scoped token + staleConfigToken = "stale-config-token" // a stale value in a k6 config file +) + +const pushCredScript = ` +export const options = { cloud: { name: 'push creds', projectID: 123456 } }; +export default function () {};` + +// cloudRequestRecorder captures the bearer token of every request the mock +// cloud sees, so a test can assert which token k6 pushed metrics with. +type cloudRequestRecorder struct { + mu sync.Mutex + requests []recordedRequest +} + +type recordedRequest struct{ path, token string } + +func (r *cloudRequestRecorder) handler(w http.ResponseWriter, req *http.Request) { + _, _ = io.Copy(io.Discard, req.Body) + r.mu.Lock() + r.requests = append(r.requests, recordedRequest{req.URL.Path, bearerToken(req)}) + r.mu.Unlock() + w.WriteHeader(http.StatusOK) +} + +func (r *cloudRequestRecorder) tokensForPath(sub string) []string { + r.mu.Lock() + defer r.mu.Unlock() + var out []string + for _, req := range r.requests { + if strings.Contains(req.path, sub) { + out = append(out, req.token) + } + } + return out +} + +func (r *cloudRequestRecorder) allTokens() []string { + r.mu.Lock() + defer r.mu.Unlock() + out := make([]string, 0, len(r.requests)) + for _, req := range r.requests { + out = append(out, req.token) + } + return out +} + +// bearerToken extracts the credential from the Authorization header, +// tolerating both schemes k6 uses: "Bearer " for the provisioning/v6 +// push and "Token " for the legacy v1 push. +func bearerToken(req *http.Request) string { + auth := req.Header.Get("Authorization") + auth = strings.TrimPrefix(auth, "Bearer ") + auth = strings.TrimPrefix(auth, "Token ") + return auth +} + +func failHandler(t *testing.T, msg string) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + assert.Fail(t, msg) + w.WriteHeader(http.StatusInternalServerError) + }) +} + +// assertPushedWith asserts that at least one request hit a path containing +// sub, and that every such request carried the expected bearer token. +func assertPushedWith(t *testing.T, rec *cloudRequestRecorder, sub, token string) { + t.Helper() + tokens := rec.tokensForPath(sub) + require.NotEmptyf(t, tokens, "expected a metrics push to a path containing %q", sub) + for _, tk := range tokens { + assert.Equalf(t, token, tk, "push to %q used an unexpected bearer token", sub) + } +} + +func assertTokenNeverUsed(t *testing.T, rec *cloudRequestRecorder, token string) { + t.Helper() + assert.NotContainsf(t, rec.allTokens(), token, "token %q must never be sent", token) +} + +func assertPathNeverHit(t *testing.T, rec *cloudRequestRecorder, sub string) { + t.Helper() + assert.Emptyf(t, rec.tokensForPath(sub), "no request should hit a path containing %q", sub) +} + +// setupSelfProvisionedRun wires a self-provisioned `k6 cloud run +// --local-execution` against a provisioning mock whose start_local_execution +// returns the scoped token and a push URL that points back at the mock +// (/v1/metrics). +func setupSelfProvisionedRun( + t *testing.T, +) (*GlobalTestState, *provtest.Server, *cloudRequestRecorder, *atomic.Bool) { + t.Helper() + + ts := makeTestState(t, pushCredScript, []string{"--local-execution"}) + ts.Env["K6_CLOUD_TOKEN"] = orgToken + + srv := provtest.NewServer(t) + rec := &cloudRequestRecorder{} + var notified atomic.Bool + + srv.HandleCreateLoadTest(123456, func(w http.ResponseWriter, _ *http.Request) { + res := k6cloud.NewLoadTestApiModelWithDefaults() + res.SetId(provtest.DefaultLoadTestID) + writeProvJSON(w, http.StatusCreated, res) + }) + srv.HandleStartLocalExecution(provtest.DefaultLoadTestID, func(w http.ResponseWriter, _ *http.Request) { + resp := provtest.DefaultStartLocalExecutionResponse() + resp.SetArchiveUploadUrl(srv.PresignedUploadURL()) + resp.SetTestRunDetailsPageUrl(fmt.Sprintf("%s/runs/%d", srv.URL, provtest.DefaultTestRunID)) + rc := resp.GetRuntimeConfig() + m := rc.GetMetrics() + m.SetPushUrl(srv.URL + "/v1/metrics") + rc.SetMetrics(m) + resp.SetRuntimeConfig(rc) + writeProvJSON(w, http.StatusOK, resp) + }) + srv.HandlePresignedUpload(provtest.PresignedUploadPath, func(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusOK) + }) + srv.HandleFetchTestRun(provtest.DefaultTestRunID, []v6.TestProgress{{Status: v6.StatusInitializing}}) + srv.HandleNotify(provtest.DefaultTestRunID, func(w http.ResponseWriter, _ *http.Request) { + notified.Store(true) + w.WriteHeader(http.StatusOK) + }) + + // Record the provisioning-mode push (/v1/metrics) and any stray push + // (e.g. an overridden URL landing on the catch-all). + srv.Mux.HandleFunc("/v1/metrics", rec.handler) + srv.Mux.HandleFunc("/", rec.handler) + + ts.Env["K6_CLOUD_HOST"] = srv.URL + ts.Env["K6_CLOUD_HOST_V6"] = srv.URL + return ts, srv, rec, ¬ified +} + +// TestCloudMetricsPushCredentials specifies how the cloud output resolves +// the endpoint and bearer token it pushes metrics with, across the three +// ways a run can be provisioned: +// +// - Self-provisioned (k6 cloud run --local-execution): the push URL and +// scoped token come from the provisioning API's start_local_execution +// response. They are set programmatically and are never overridden by +// the environment or a config file. +// - Externally-provisioned (--local-execution + K6_CLOUD_PUSH_REF_ID): an +// orchestrator that already created the run supplies the scoped push URL +// and token via K6_CLOUD_METRICS_PUSH_URL and K6_CLOUD_TEST_RUN_TOKEN, +// which are required together. +// - Legacy (k6 run --out cloud, or a PushRefID relay without scoped +// creds): metrics go to the endpoint derived from the host using the +// long-lived org token. +// +// Each case runs the real command against an in-process mock cloud +// (httptest, no network) and asserts which bearer token k6 pushes with, +// using distinct sentinel tokens so the source is unambiguous. +func TestCloudMetricsPushCredentials(t *testing.T) { + t.Parallel() + + // Self-provisioned: creds come from the provisioning response and must + // not be overridden by stray env vars or config-file values. + + t.Run("self-provisioned run pushes with the scoped token from provisioning", func(t *testing.T) { + t.Parallel() + ts, _, rec, notified := setupSelfProvisionedRun(t) + cmd.ExecuteWithGlobalState(ts.GlobalState) + assertPushedWith(t, rec, "/v1/metrics", scopedToken) + assert.True(t, notified.Load(), "a self-provisioned run notifies at the end") + }) + + t.Run("self-provisioned run ignores a stray token env var", func(t *testing.T) { + t.Parallel() + ts, _, rec, notified := setupSelfProvisionedRun(t) + ts.Env["K6_CLOUD_TEST_RUN_TOKEN"] = bogusToken + cmd.ExecuteWithGlobalState(ts.GlobalState) + assertPushedWith(t, rec, "/v1/metrics", scopedToken) + assertTokenNeverUsed(t, rec, bogusToken) + assert.True(t, notified.Load()) + }) + + t.Run("self-provisioned run ignores a stray metrics-push-URL env var", func(t *testing.T) { + t.Parallel() + ts, srv, rec, _ := setupSelfProvisionedRun(t) + ts.Env["K6_CLOUD_METRICS_PUSH_URL"] = srv.URL + "/overridden-metrics" + cmd.ExecuteWithGlobalState(ts.GlobalState) + assertPushedWith(t, rec, "/v1/metrics", scopedToken) + assertPathNeverHit(t, rec, "/overridden-metrics") + }) + + t.Run("self-provisioned run ignores stray scoped-cred env vars", func(t *testing.T) { + t.Parallel() + ts, srv, rec, _ := setupSelfProvisionedRun(t) + ts.Env["K6_CLOUD_TEST_RUN_TOKEN"] = bogusToken + ts.Env["K6_CLOUD_METRICS_PUSH_URL"] = srv.URL + "/overridden-metrics" + cmd.ExecuteWithGlobalState(ts.GlobalState) + assertPushedWith(t, rec, "/v1/metrics", scopedToken) + assertTokenNeverUsed(t, rec, bogusToken) + assertPathNeverHit(t, rec, "/overridden-metrics") + }) + + t.Run("self-provisioned run ignores a stale token in the config file", func(t *testing.T) { + t.Parallel() + ts, _, rec, _ := setupSelfProvisionedRun(t) + cfg := []byte(`{"collectors":{"cloud":{"testRunToken":"` + staleConfigToken + `"}}}`) + require.NoError(t, ts.FS.MkdirAll(filepath.Dir(ts.Flags.ConfigFilePath), 0o755)) + require.NoError(t, fsext.WriteFile(ts.FS, ts.Flags.ConfigFilePath, cfg, 0o644)) + cmd.ExecuteWithGlobalState(ts.GlobalState) + assertPushedWith(t, rec, "/v1/metrics", scopedToken) + assertTokenNeverUsed(t, rec, staleConfigToken) + }) + + // Legacy: `k6 run --out cloud` and PushRefID relays push to the + // host-derived endpoint with the long-lived org token, unaffected by the + // scoped-cred env vars. + + t.Run("k6 run --out cloud ignores a stray token env var", func(t *testing.T) { + t.Parallel() + ts := getSingleFileTestState(t, pushCredScript, []string{"-v", "--log-output=stdout", "--out=cloud"}, 0) + ts.Env["K6_CLOUD_TOKEN"] = orgToken + ts.Env["K6_CLOUD_TEST_RUN_TOKEN"] = bogusToken + + rec := &cloudRequestRecorder{} + const refID = 1337 + srv := getTestServer(t, map[string]http.Handler{ + "POST ^/v1/tests$": http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusOK) + _, _ = fmt.Fprintf(w, `{"reference_id": "%d", "config": {}}`, refID) + }), + fmt.Sprintf("POST ^/v1/tests/%d$", refID): http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusOK) + }), + "POST ^/v2/metrics/": http.HandlerFunc(rec.handler), + }) + t.Cleanup(srv.Close) + ts.Env["K6_CLOUD_HOST"] = srv.URL + + cmd.ExecuteWithGlobalState(ts.GlobalState) + assertPushedWith(t, rec, "/v2/metrics/", orgToken) + assertTokenNeverUsed(t, rec, bogusToken) + }) + + t.Run("a PushRefID relay without scoped creds pushes with the org token", func(t *testing.T) { + t.Parallel() + ts := makeTestState(t, pushCredScript, []string{"--local-execution"}) + ts.Env["K6_CLOUD_TOKEN"] = orgToken + ts.Env["K6_CLOUD_PUSH_REF_ID"] = "99999" + + rec := &cloudRequestRecorder{} + srv := getTestServer(t, map[string]http.Handler{ + "POST ^/v1/tests$": failHandler(t, "CreateTestRun must not be called with PushRefID"), + "POST ^/provisioning/v1/": failHandler(t, "provisioning API must not be called with PushRefID"), + "POST ^/cloud/v6/": failHandler(t, "v6 API must not be called with PushRefID"), + "POST ^/v2/metrics/": http.HandlerFunc(rec.handler), + }) + t.Cleanup(srv.Close) + ts.Env["K6_CLOUD_HOST"] = srv.URL + ts.Env["K6_CLOUD_HOST_V6"] = srv.URL + + cmd.ExecuteWithGlobalState(ts.GlobalState) + assertPushedWith(t, rec, "/v2/metrics/", orgToken) + }) + + t.Run("k6 run --out cloud with PushRefID ignores a lone scoped-cred env var", func(t *testing.T) { + t.Parallel() + ts := getSingleFileTestState(t, pushCredScript, []string{"-v", "--log-output=stdout", "--out=cloud"}, 0) + ts.Env["K6_CLOUD_TOKEN"] = orgToken + ts.Env["K6_CLOUD_PUSH_REF_ID"] = "1337" + ts.Env["K6_CLOUD_TEST_RUN_TOKEN"] = extToken // lone scoped cred, no push URL + + rec := &cloudRequestRecorder{} + srv := getTestServer(t, map[string]http.Handler{ + "POST ^/v1/tests$": failHandler(t, "CreateTestRun must not be called with PushRefID"), + "POST ^/v2/metrics/": http.HandlerFunc(rec.handler), + }) + t.Cleanup(srv.Close) + ts.Env["K6_CLOUD_HOST"] = srv.URL + + cmd.ExecuteWithGlobalState(ts.GlobalState) + assertPushedWith(t, rec, "/v2/metrics/", orgToken) + }) + + // Externally-provisioned: an orchestrator supplies the scoped creds via + // env; both are required together. + + t.Run("externally-provisioned run pushes with the scoped creds from env", func(t *testing.T) { + t.Parallel() + ts := makeTestState(t, pushCredScript, []string{"--local-execution"}) + ts.Env["K6_CLOUD_TOKEN"] = orgToken + ts.Env["K6_CLOUD_PUSH_REF_ID"] = "99999" + + rec := &cloudRequestRecorder{} + srv := getTestServer(t, map[string]http.Handler{ + "POST ^/provisioning/v1/": failHandler(t, "provisioning API must not be called with PushRefID"), + "POST ^/cloud/v6/": failHandler(t, "v6 API must not be called with PushRefID"), + "POST ^/v1/metrics": http.HandlerFunc(rec.handler), + "POST ^/v2/metrics/": http.HandlerFunc(rec.handler), + }) + t.Cleanup(srv.Close) + ts.Env["K6_CLOUD_HOST"] = srv.URL + ts.Env["K6_CLOUD_HOST_V6"] = srv.URL + ts.Env["K6_CLOUD_METRICS_PUSH_URL"] = srv.URL + "/v1/metrics" + ts.Env["K6_CLOUD_TEST_RUN_TOKEN"] = extToken + + cmd.ExecuteWithGlobalState(ts.GlobalState) + assertPushedWith(t, rec, "/v1/metrics", extToken) + }) + + t.Run("externally-provisioned run requires both scoped creds", func(t *testing.T) { + t.Parallel() + ts := makeTestState(t, pushCredScript, []string{"--local-execution", "--log-output=stdout"}) + ts.Env["K6_CLOUD_TOKEN"] = orgToken + ts.Env["K6_CLOUD_PUSH_REF_ID"] = "99999" + ts.Env["K6_CLOUD_TEST_RUN_TOKEN"] = extToken // only one of the pair + ts.ExpectedExitCode = -1 + + srv := getTestServer(t, map[string]http.Handler{}) + t.Cleanup(srv.Close) + ts.Env["K6_CLOUD_HOST"] = srv.URL + ts.Env["K6_CLOUD_HOST_V6"] = srv.URL + + cmd.ExecuteWithGlobalState(ts.GlobalState) + out := ts.Stdout.String() + ts.Stderr.String() + assert.Contains(t, out, "must be set together", + "a partial scoped-cred pair must fail with a clear error") + }) +} diff --git a/internal/output/cloud/output.go b/internal/output/cloud/output.go index 71807575b..d97bc2e22 100644 --- a/internal/output/cloud/output.go +++ b/internal/output/cloud/output.go @@ -223,11 +223,22 @@ func (out *Output) Start() error { if out.testRunID != "" { out.logger.WithField("testRunId", out.testRunID).Debug("Directly pushing metrics without init") - // Provisioning-mode setup. PushRefID flows don't set - // MetricsPushURL, so this block is normally skipped for them. - // The explicit !PushRefID.Valid guard is defensive against a - // future cmd-layer regression that populates both fields. - if out.config.MetricsPushURL.Valid && out.config.TestRunToken.Valid && !out.config.PushRefID.Valid { + // Exactly one of the scoped push creds set is a misconfiguration. + // The cmd layer already validates this for the externally-provisioned + // env case (internal/cmd/outputs_cloud.go); this is the defensive + // backstop for any other source (e.g. a hand-written cloud config). + if out.config.MetricsPushURL.Valid != out.config.TestRunToken.Valid { + return fmt.Errorf( + "both K6_CLOUD_METRICS_PUSH_URL and K6_CLOUD_TEST_RUN_TOKEN " + + "must be set together") + } + + // Provisioning-mode push. Armed whenever the scoped push credentials + // are present: either k6 self-provisioned (no PushRefID) or an external + // service provisioned the run and its creds were injected into the + // cloud config by the cmd layer (PushRefID set; that service owns + // create/start/notify). + if out.config.MetricsPushURL.Valid && out.config.TestRunToken.Valid { if err := out.lazyInitProvisioning(); err != nil { return err } @@ -498,8 +509,12 @@ func (out *Output) lazyInitProvisioning() error { ) } - // Lazy-construct the provisioning notifier (used at end-of-test). - if out.provisioningNotifier == nil { + // Lazy-construct the provisioning notifier (end-of-test notify). + // Skipped when PushRefID is set: an external service owns the run + // lifecycle, so k6 never notifies (testFinished returns early on + // PushRefID) and the notifier would be unused. Invariant: a nil + // notifier with provisioningMode true implies PushRefID is set. + if out.provisioningNotifier == nil && !out.config.PushRefID.Valid { // The stack ID is required and passed as int64; provisioning.NewClient // enforces the int32 X-Stack-Id boundary internally. c, err := provisioning.NewClient( diff --git a/internal/output/cloud/output_test.go b/internal/output/cloud/output_test.go index 9f7f0f7fc..a9c8e399f 100644 --- a/internal/output/cloud/output_test.go +++ b/internal/output/cloud/output_test.go @@ -510,12 +510,13 @@ func TestOutputStart_ProvisioningMode(t *testing.T) { "queued metrics should be pushed through the injected metricsPusher") } -// TestOutputStart_PushRefIDStillTakesPrecedence locks in cloud-Output -// behaviour even if cmd ever populated both PushRefID and MetricsPushURL. -// In practice, cmd/outputs_cloud.go:96-100 short-circuits on PushRefID -// before MetricsPushURL is ever set — so this combination shouldn't -// occur. This test is defensive against future cmd-layer regressions. -func TestOutputStart_PushRefIDStillTakesPrecedence(t *testing.T) { +// TestOutputStart_ExternallyProvisioned covers the flow where an +// external service provisioned the run and passes the scoped push +// creds (MetricsPushURL + TestRunToken) plus PushRefID via env. k6 +// must push to the provisioning URL with the scoped token but must +// NOT build a notifier — the external service owns create/start/ +// notify (see testFinished, which returns early on PushRefID). +func TestOutputStart_ExternallyProvisioned(t *testing.T) { t.Parallel() cfgJSON, err := json.Marshal(cloudapi.Config{ @@ -545,20 +546,124 @@ func TestOutputStart_PushRefIDStillTakesPrecedence(t *testing.T) { }) require.NoError(t, err) + // Inject a metrics-pusher mock so Start arms the provisioning push + // without constructing a real HTTP client (mirrors + // TestOutputStart_ProvisioningMode). provisioningNotifier is left nil + // to prove lazyInitProvisioning skips it when PushRefID is set. + out.metricsPusher = &metricsPusherMock{} + require.NoError(t, out.Start()) - // PushRefID should win: testRunID should be set to the PushRefID value, - // not the testRunID from env. + // PushRefID still supplies the test run id. assert.Equal(t, "99999", out.testRunID) - // The metricsPusher field should remain nil — provisioning mode was NOT - // entered because PushRefID took precedence. - assert.Nil(t, out.metricsPusher, "metricsPusher should be nil when PushRefID takes precedence") - assert.Nil(t, out.provisioningNotifier, "provisioningNotifier should be nil when PushRefID takes precedence") + // Provisioning push is armed on scoped-cred presence, even with PushRefID. + assert.True(t, out.provisioningMode) + assert.NotNil(t, out.metricsPusher) + + // No notifier: the external service owns the run lifecycle. + assert.Nil(t, out.provisioningNotifier) require.NoError(t, out.StopWithTestError(nil)) } +// TestOutputStart_ExternalProvisioned_RequiresBothCreds locks the +// "no silent legacy fallback on partial config" behaviour: if only one +// of the scoped push creds is set, Start errors (naming both env vars) +// instead of quietly falling back to the legacy push endpoint. +func TestOutputStart_ExternalProvisioned_RequiresBothCreds(t *testing.T) { + t.Parallel() + + cases := []struct { + name string + metricsPushURL null.String + testRunToken null.String + }{ + { + name: "only MetricsPushURL set", + metricsPushURL: null.StringFrom("https://metrics.example.com/v2/metrics/123"), + }, + { + name: "only TestRunToken set", + testRunToken: null.StringFrom("scoped-test-run-token"), + }, + } + + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + + cfgJSON, err := json.Marshal(cloudapi.Config{ + Host: null.StringFrom("https://fake-cloud"), + Token: null.StringFrom("fake-token"), + PushRefID: null.StringFrom("99999"), + MetricsPushURL: tc.metricsPushURL, + TestRunToken: tc.testRunToken, + APIVersion: null.IntFrom(2), + AggregationPeriod: types.NullDurationFrom(1 * time.Hour), + MetricPushInterval: types.NullDurationFrom(1 * time.Hour), + AggregationWaitPeriod: types.NullDurationFrom(1 * time.Second), + MaxTimeSeriesInBatch: null.IntFrom(1000), + MetricPushConcurrency: null.IntFrom(1), + }) + require.NoError(t, err) + + out, err := newOutput(output.Params{ + Logger: testutils.NewLogger(t), + JSONConfig: cfgJSON, + ScriptOptions: lib.Options{ + Duration: types.NullDurationFrom(1 * time.Second), + SystemTags: &metrics.DefaultSystemTagSet, + }, + ScriptPath: &url.URL{Path: "/script.js"}, + Usage: usage.New(), + }) + require.NoError(t, err) + + err = out.Start() + require.Error(t, err) + assert.Contains(t, err.Error(), "K6_CLOUD_METRICS_PUSH_URL") + assert.Contains(t, err.Error(), "K6_CLOUD_TEST_RUN_TOKEN") + }) + } +} + +// TestOutputStopWithTestError_ExternalProvisioned_NoNotifier locks the +// invariant "notifier nil ⇒ PushRefID set ⇒ testFinished returns early": +// with provisioningMode true and a nil notifier, Stop must not panic and +// must neither notify nor call the legacy TestFinished. +func TestOutputStopWithTestError_ExternalProvisioned_NoNotifier(t *testing.T) { + t.Parallel() + synctest.Test(t, func(t *testing.T) { + clientMock := &cloudClientMock{} + + out := &Output{ + logger: testutils.NewLogger(t), + testRunID: "12345", + config: cloudapi.Config{ + PushRefID: null.StringFrom("99999"), + MetricsPushURL: null.StringFrom("https://metrics.example.com/v2/metrics/123"), + TestRunToken: null.StringFrom("scoped-test-run-token"), + }, + client: clientMock, + provisioningNotifier: nil, + provisioningMode: true, + } + + out.versionedOutput = versionedOutputMock{ + callback: func(_ string) {}, + } + + // Must not panic even though provisioningNotifier is nil while + // provisioningMode is true — testFinished returns early on PushRefID + // (so the nil notifier is never dereferenced, and notify never fires). + require.NoError(t, out.StopWithTestError(nil)) + + // Legacy TestFinished is not called either (PushRefID short-circuit). + assert.False(t, clientMock.testFinishedCalled) + }) +} + func TestOutputStopWithTestError_ProvisioningMode_NoError(t *testing.T) { t.Parallel() synctest.Test(t, func(t *testing.T) { From 267b7490def806e5c91ecf3ac01bcd683f84ece0 Mon Sep 17 00:00:00 2001 From: Marton Vegh Date: Thu, 30 Jul 2026 12:36:55 +0200 Subject: [PATCH 090/182] Fix documentation typos (#6129) --- docs/design/020-distributed-execution-and-test-suites.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/design/020-distributed-execution-and-test-suites.md b/docs/design/020-distributed-execution-and-test-suites.md index b56ad8f29..0694ee150 100644 --- a/docs/design/020-distributed-execution-and-test-suites.md +++ b/docs/design/020-distributed-execution-and-test-suites.md @@ -298,9 +298,9 @@ Let's get back to my actual proposal of a `execution.Controller` API + new `k6 c To show that the proposed solution is a viable one, I'll go through the 9 items from the list in the "Missing Parts in the Current State" section and show how the proposal can be used to easily implement them: 1. `k6 coordinator` assembles the script and its dependencies into a [.tar archive bundle](https://k6.io/docs/misc/archive-command/) and distributes it to all `k6 agent` nodes automatically once they connect to it (either pull-based or push-based). -2. I showed how `setup()` can be cooperatively execuded only on a single instance and how its result can be distributed to the rest of the instances with the `GetOrCreateData()` pseudo-API described in the "Instance Synchronization API" section. +2. I showed how `setup()` can be cooperatively executed only on a single instance and how its result can be distributed to the rest of the instances with the `GetOrCreateData()` pseudo-API described in the "Instance Synchronization API" section. 3. Similarly, in the "Instance Synchronization API" section I showed how the `SignalAndWait()` pseudo-API can be used to ensure that all instances have finished initializing their VUs and executed `setup()` before they start the actual test execution simultaneously -4. Most failures will be handled by the coordinator and propaged to waiting instances. For the best UX, instances might subscribe to a special error channel so they can be interupted even during the test execution. +4. Most failures will be handled by the coordinator and propagated to waiting instances. For the best UX, instances might subscribe to a special error channel so they can be interrupted even during the test execution. 5. Metric collection was described in the "Metrics Handling" section, and the coordinator will be able to stop the test if a threshold is crossed. 6. We can probably handle `test.abort()` calls from an instance with a `GetOrCreateData()` call that uses a special `dataID` watched by the coordinator, but it might be simpler to just add a custom API for that... :thinking: 7. Detecting when the test has finished is trivial with `SignalAndWait()`. From ec8cd877c6eef4ef90464562556dd5ed555e0543 Mon Sep 17 00:00:00 2001 From: Hardik Borse <174507577+the-onewho-knocks@users.noreply.github.com> Date: Thu, 30 Jul 2026 16:40:51 +0530 Subject: [PATCH 091/182] fix: retain regDurationCtx cancel in getDurationContexts (#6144) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: the-onewho-knocks Co-authored-by: Iván Szkiba --- lib/executor/constant_arrival_rate.go | 3 ++- lib/executor/constant_vus.go | 3 ++- lib/executor/helpers.go | 10 ++++++---- lib/executor/per_vu_iterations.go | 3 ++- lib/executor/ramping_arrival_rate.go | 3 ++- lib/executor/ramping_vus.go | 3 ++- lib/executor/shared_iterations.go | 3 ++- 7 files changed, 18 insertions(+), 10 deletions(-) diff --git a/lib/executor/constant_arrival_rate.go b/lib/executor/constant_arrival_rate.go index 384c3db7b..9ce041c9f 100644 --- a/lib/executor/constant_arrival_rate.go +++ b/lib/executor/constant_arrival_rate.go @@ -212,9 +212,10 @@ func (car ConstantArrivalRate) Run(parentCtx context.Context, out chan<- metrics returnedVUs := make(chan struct{}) waitOnProgressChannel := make(chan struct{}) - startTime, maxDurationCtx, regDurationCtx, cancel := getDurationContexts(parentCtx, duration, gracefulStop) + startTime, maxDurationCtx, regDurationCtx, cancel, regCancel := getDurationContexts(parentCtx, duration, gracefulStop) defer func() { cancel() + regCancel() <-waitOnProgressChannel }() diff --git a/lib/executor/constant_vus.go b/lib/executor/constant_vus.go index a1f85f22d..3d1d40ae4 100644 --- a/lib/executor/constant_vus.go +++ b/lib/executor/constant_vus.go @@ -128,9 +128,10 @@ func (clv ConstantVUs) Run(parentCtx context.Context, _ chan<- metrics.SampleCon gracefulStop := clv.config.GetGracefulStop() waitOnProgressChannel := make(chan struct{}) - startTime, maxDurationCtx, regDurationCtx, cancel := getDurationContexts(parentCtx, duration, gracefulStop) + startTime, maxDurationCtx, regDurationCtx, cancel, regCancel := getDurationContexts(parentCtx, duration, gracefulStop) defer func() { cancel() + regCancel() <-waitOnProgressChannel }() diff --git a/lib/executor/helpers.go b/lib/executor/helpers.go index dc9549360..310c6768a 100644 --- a/lib/executor/helpers.go +++ b/lib/executor/helpers.go @@ -134,17 +134,19 @@ func getIterationRunner( // that will also cancel these contexts, thus the "general abort" case is // handled transparently. func getDurationContexts(parentCtx context.Context, regularDuration, gracefulStop time.Duration) ( - startTime time.Time, maxDurationCtx, regDurationCtx context.Context, maxDurationCancel func(), + startTime time.Time, + maxDurationCtx, regDurationCtx context.Context, + maxDurationCancel func(), regDurationCancel func(), ) { startTime = time.Now() maxEndTime := startTime.Add(regularDuration + gracefulStop) maxDurationCtx, maxDurationCancel = context.WithDeadline(parentCtx, maxEndTime) if gracefulStop == 0 { - return startTime, maxDurationCtx, maxDurationCtx, maxDurationCancel + return startTime, maxDurationCtx, maxDurationCtx, maxDurationCancel, maxDurationCancel } - regDurationCtx, _ = context.WithDeadline(maxDurationCtx, startTime.Add(regularDuration)) //nolint:govet - return startTime, maxDurationCtx, regDurationCtx, maxDurationCancel + regDurationCtx, regDurationCancel = context.WithDeadline(maxDurationCtx, startTime.Add(regularDuration)) + return startTime, maxDurationCtx, regDurationCtx, maxDurationCancel, regDurationCancel } // trackProgress is a helper function that monitors certain end-events in an diff --git a/lib/executor/per_vu_iterations.go b/lib/executor/per_vu_iterations.go index 7586361e6..4cdb77f46 100644 --- a/lib/executor/per_vu_iterations.go +++ b/lib/executor/per_vu_iterations.go @@ -139,9 +139,10 @@ func (pvi PerVUIterations) Run(parentCtx context.Context, out chan<- metrics.Sam gracefulStop := pvi.config.GetGracefulStop() waitOnProgressChannel := make(chan struct{}) - startTime, maxDurationCtx, regDurationCtx, cancel := getDurationContexts(parentCtx, duration, gracefulStop) + startTime, maxDurationCtx, regDurationCtx, cancel, regCancel := getDurationContexts(parentCtx, duration, gracefulStop) defer func() { cancel() + regCancel() <-waitOnProgressChannel }() diff --git a/lib/executor/ramping_arrival_rate.go b/lib/executor/ramping_arrival_rate.go index 779c6580f..35d8d5f89 100644 --- a/lib/executor/ramping_arrival_rate.go +++ b/lib/executor/ramping_arrival_rate.go @@ -335,7 +335,7 @@ func (varr RampingArrivalRate) Run(parentCtx context.Context, out chan<- metrics returnedVUs := make(chan struct{}) waitOnProgressChannel := make(chan struct{}) - startTime, maxDurationCtx, regDurationCtx, cancel := getDurationContexts(parentCtx, duration, gracefulStop) + startTime, maxDurationCtx, regDurationCtx, cancel, regCancel := getDurationContexts(parentCtx, duration, gracefulStop) vusPool := newActiveVUPool(varr.executionState) @@ -346,6 +346,7 @@ func (varr RampingArrivalRate) Run(parentCtx context.Context, out chan<- metrics // first close the vusPool so we wait for the gracefulShutdown vusPool.Close() cancel() + regCancel() activeVUsWg.Wait() <-waitOnProgressChannel }() diff --git a/lib/executor/ramping_vus.go b/lib/executor/ramping_vus.go index d235c30d3..f0a3ea87d 100644 --- a/lib/executor/ramping_vus.go +++ b/lib/executor/ramping_vus.go @@ -501,11 +501,12 @@ func (vlv *RampingVUs) Run(ctx context.Context, _ chan<- metrics.SampleContainer return fmt.Errorf("%s expected graceful end offset at %s to be final", vlv.config.GetName(), maxDuration) } waitOnProgressChannel := make(chan struct{}) - startTime, maxDurationCtx, regularDurationCtx, cancel := getDurationContexts( + startTime, maxDurationCtx, regularDurationCtx, cancel, regCancel := getDurationContexts( ctx, regularDuration, maxDuration-regularDuration, ) defer func() { cancel() + regCancel() <-waitOnProgressChannel }() diff --git a/lib/executor/shared_iterations.go b/lib/executor/shared_iterations.go index 5afa6739e..e0acdf1af 100644 --- a/lib/executor/shared_iterations.go +++ b/lib/executor/shared_iterations.go @@ -171,9 +171,10 @@ func (si SharedIterations) Run(parentCtx context.Context, out chan<- metrics.Sam gracefulStop := si.config.GetGracefulStop() waitOnProgressChannel := make(chan struct{}) - startTime, maxDurationCtx, regDurationCtx, cancel := getDurationContexts(parentCtx, duration, gracefulStop) + startTime, maxDurationCtx, regDurationCtx, cancel, regCancel := getDurationContexts(parentCtx, duration, gracefulStop) defer func() { cancel() + regCancel() <-waitOnProgressChannel }() From 7dbe86e3ea08373e41f75748d772dd594066cb90 Mon Sep 17 00:00:00 2001 From: Rohan Patnaik Date: Thu, 30 Jul 2026 19:26:17 +0530 Subject: [PATCH 092/182] fix: periodically flush file logs (#6070) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: periodically flush file logs * fix: use structured file hook errors --------- Co-authored-by: Théo Crevon Co-authored-by: Joan López de la Franca Beltran <5459617+joanlopez@users.noreply.github.com> --- internal/log/file.go | 18 +++++++++++---- internal/log/file_test.go | 47 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 4 deletions(-) diff --git a/internal/log/file.go b/internal/log/file.go index 9129a4b2d..bfe2a3159 100644 --- a/internal/log/file.go +++ b/internal/log/file.go @@ -10,6 +10,7 @@ import ( "path/filepath" "strings" "syscall" + "time" "github.com/sirupsen/logrus" "go.k6.io/k6/v2/internal/lib/strvals" @@ -19,6 +20,8 @@ import ( // fileHookBufferSize is a default size for the fileHook's loglines channel. const fileHookBufferSize = 100 +const fileHookFlushInterval = time.Second + // fileHook is a hook to handle writing to local files. type fileHook struct { fs fsext.Fs @@ -109,11 +112,18 @@ func (h *fileHook) openFile(getCwd func() (string, error)) error { // Listen waits for log lines to flush. func (h *fileHook) Listen(ctx context.Context) { + ticker := time.NewTicker(fileHookFlushInterval) + defer ticker.Stop() + for { select { case entry := <-h.loglines: if _, err := h.bw.Write(entry); err != nil { - h.fallbackLogger.Errorf("failed to write a log message to a logfile: %w", err) + h.fallbackLogger.WithError(err).Error("failed to write a log message to a logfile") + } + case <-ticker.C: + if err := h.bw.Flush(); err != nil { + h.fallbackLogger.WithError(err).Error("failed to flush logfile buffer") } case <-ctx.Done(): // This context is cancelled after the command finishes executing, so it is guaranteed that no more lines @@ -124,7 +134,7 @@ func (h *fileHook) Listen(ctx context.Context) { select { case entry := <-h.loglines: if _, err := h.bw.Write(entry); err != nil { - h.fallbackLogger.Errorf("failed to write a log message to a logfile: %w", err) + h.fallbackLogger.WithError(err).Error("failed to write a log message to a logfile") } default: break drainloop @@ -132,11 +142,11 @@ func (h *fileHook) Listen(ctx context.Context) { } if err := h.bw.Flush(); err != nil { - h.fallbackLogger.Errorf("failed to flush buffer: %w", err) + h.fallbackLogger.WithError(err).Error("failed to flush buffer") } if err := h.w.Close(); err != nil { - h.fallbackLogger.Errorf("failed to close logfile: %w", err) + h.fallbackLogger.WithError(err).Error("failed to close logfile") } return diff --git a/internal/log/file_test.go b/internal/log/file_test.go index 492ffeea5..9c4d23e07 100644 --- a/internal/log/file_test.go +++ b/internal/log/file_test.go @@ -24,6 +24,18 @@ func (nc *nopCloser) Close() error { return nil } +type signalWriter struct { + wrote chan struct{} +} + +func (sw signalWriter) Write(p []byte) (int, error) { + select { + case sw.wrote <- struct{}{}: + default: + } + return len(p), nil +} + func TestFileHookFromConfigLine(t *testing.T) { t.Parallel() @@ -145,3 +157,38 @@ func TestFileHookFire(t *testing.T) { assert.Contains(t, buffer.String(), "example log line") } + +func TestFileHookPeriodicallyFlushes(t *testing.T) { + t.Parallel() + + wrote := make(chan struct{}, 1) + nc := &nopCloser{ + Writer: signalWriter{wrote: wrote}, + closed: make(chan struct{}), + } + + hook := &fileHook{ + loglines: make(chan []byte, fileHookBufferSize), + w: nc, + bw: bufio.NewWriter(nc), + levels: logrus.AllLevels, + } + + ctx, cancel := context.WithCancel(context.Background()) + defer func() { + cancel() + <-nc.closed + }() + + go hook.Listen(ctx) + hook.loglines <- []byte("example log line\n") + + require.Eventually(t, func() bool { + select { + case <-wrote: + return true + default: + return false + } + }, 2*fileHookFlushInterval, 10*time.Millisecond) +} From 1db22efcd9992bea9f4020ec6c2946236cafa088 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gonz=C3=A1lez=20Lopes?= Date: Thu, 30 Jul 2026 16:24:12 +0200 Subject: [PATCH 093/182] cloud: drop the run flags from `k6 cloud` help (#6208) * cloud: drop the run flags from `k6 cloud` help `k6 cloud` is a command group whose RunE only prints help, but it also registered the full test execution flag set (`optionFlagSet` plus `runtimeOptionFlagSet`, `--exit-on-running` and `--show-logs`). Those ~40 flags were parsed and discarded, so `k6 cloud --vus 50 script.js` silently printed help instead of running anything, and `k6 cloud --help` was 90 lines of flags that do nothing. They belong to `k6 cloud run`, which builds its own flag set. The registration is a leftover from when `k6 cloud script.js` was the way to run a cloud test. `k6 cloud --help` is now 29 lines, and an execution flag on the group is rejected with "unknown flag" rather than being ignored. TestConfigConsolidation exercised its cases against `k6 cloud`, relying on those flags being present; it now uses `k6 cloud run`, the command that actually owns them. * cloud: assert run flags stay out of `k6 cloud` help Pins the new behavior so re-adding the run flag set to the parent `cloud` command is caught by tests. --- internal/cmd/cloud.go | 3 --- internal/cmd/config_consolidation_test.go | 6 ++++-- internal/cmd/tests/cmd_cloud_test.go | 1 + 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/cmd/cloud.go b/internal/cmd/cloud.go index f8168387b..6b5597477 100644 --- a/internal/cmd/cloud.go +++ b/internal/cmd/cloud.go @@ -499,9 +499,6 @@ func getCmdCloud(gs *state.GlobalState) *cobra.Command { testCmd := getCmdCloudTest(c) cloudCmd.AddCommand(testCmd) - cloudCmd.Flags().SortFlags = false - cloudCmd.Flags().AddFlagSet(c.flagSet()) - // Use custom template similar to root - hardcode flags to avoid showing global flags cloudTemplate := getCloudUsageTemplate() cloudCmd.SetUsageTemplate(cloudTemplate) diff --git a/internal/cmd/config_consolidation_test.go b/internal/cmd/config_consolidation_test.go index 40116ded9..71274f372 100644 --- a/internal/cmd/config_consolidation_test.go +++ b/internal/cmd/config_consolidation_test.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "strings" "testing" "time" @@ -569,7 +570,8 @@ func runTestCase(t *testing.T, testCase configConsolidationTestCase, subCmd stri t.Logf("Test for `k6 %s` with opts=%#v and exp=%#v\n", subCmd, testCase.options, testCase.expected) ts := tests.NewGlobalTestState(t) - ts.CmdArgs = append([]string{"k6", subCmd}, testCase.options.cli...) + // subCmd may name a nested command, e.g. "cloud run". + ts.CmdArgs = append(append([]string{"k6"}, strings.Fields(subCmd)...), testCase.options.cli...) ts.Env = state.BuildEnvMap(testCase.options.env) if testCase.options.fs != nil { ts.FS = testCase.options.fs @@ -645,7 +647,7 @@ func TestConfigConsolidation(t *testing.T) { for tcNum, testCase := range getConfigConsolidationTestCases() { subCommands := testCase.options.cmds if subCommands == nil { // handle the most common case - subCommands = []string{"run", "archive", "cloud"} + subCommands = []string{"run", "archive", "cloud run"} } for fsNum, subCmd := range subCommands { t.Run( diff --git a/internal/cmd/tests/cmd_cloud_test.go b/internal/cmd/tests/cmd_cloud_test.go index 929933ddb..5bd73f081 100644 --- a/internal/cmd/tests/cmd_cloud_test.go +++ b/internal/cmd/tests/cmd_cloud_test.go @@ -26,6 +26,7 @@ func TestCloudNoArgsShowsHelp(t *testing.T) { stdout := ts.Stdout.String() t.Log(stdout) assert.Contains(t, stdout, "Run and manage Grafana Cloud tests", "expected help text to be shown") + assert.NotContains(t, stdout, "--vus", "run flags belong to `k6 cloud run`, not to `k6 cloud`") } type setupCommandFunc func(cliFlags []string) []string From b9bd46d40ce1934bf148fcf0ef971563884bb939 Mon Sep 17 00:00:00 2001 From: Inanc Gumus Date: Thu, 30 Jul 2026 11:13:18 -0400 Subject: [PATCH 094/182] Merge pull request #6229 from grafana/rename/ext-telemetry-kind-to-type Extension telemetry: Rename extension kind to type --- internal/cmd/report.go | 8 ++++---- internal/cmd/tests/cmd_run_report_test.go | 14 +++++++------- .../cmd/tests/cmd_subcommand_help_report_test.go | 2 +- .../cmd/tests/cmd_subcommand_nested_report_test.go | 2 +- internal/cmd/tests/cmd_subcommand_report_test.go | 2 +- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/internal/cmd/report.go b/internal/cmd/report.go index 39f4dad24..fa4bbf759 100644 --- a/internal/cmd/report.go +++ b/internal/cmd/report.go @@ -17,11 +17,11 @@ import ( ) // extensionEntry identifies a used extension in the usage report by its Go -// module path, along with its version and kind. +// module path, along with its version and type. type extensionEntry struct { Module string `json:"module"` Version string `json:"version"` - Kind string `json:"kind"` + Type string `json:"type"` } // newExtensionEntry builds the usage-report entry for a registered extension. @@ -29,7 +29,7 @@ func newExtensionEntry(e *ext.Extension) extensionEntry { return extensionEntry{ Module: e.Path, Version: e.Version, - Kind: e.Type.String(), + Type: e.Type.String(), } } @@ -109,7 +109,7 @@ func resolveExtensions(m map[string]any, catalog func() map[string]struct{}) { // filterExtensions turns the recorded used extensions into report entries, // keeping only those whose module path is advertised in the public catalog and -// de-duplicating per (module, kind). +// de-duplicating per (module, type). func filterExtensions(used []any, public map[string]struct{}) []extensionEntry { seen := make(map[[2]string]struct{}, len(used)) entries := make([]extensionEntry, 0, len(used)) diff --git a/internal/cmd/tests/cmd_run_report_test.go b/internal/cmd/tests/cmd_run_report_test.go index b90d43aea..470ceca2a 100644 --- a/internal/cmd/tests/cmd_run_report_test.go +++ b/internal/cmd/tests/cmd_run_report_test.go @@ -112,7 +112,7 @@ func TestRunReportsExtensions(t *testing.T) { { "module": testImportModule, "version": ext.Get(ext.JSExtension)["k6/x/testimport"].Version, - "kind": "js", + "type": "js", }, }, }, @@ -125,7 +125,7 @@ func TestRunReportsExtensions(t *testing.T) { { "module": testImportModule, "version": ext.Get(ext.JSExtension)["k6/x/testimport"].Version, - "kind": "js", + "type": "js", }, }, }, @@ -137,12 +137,12 @@ func TestRunReportsExtensions(t *testing.T) { { "module": testImportModule, "version": ext.Get(ext.JSExtension)["k6/x/testimport"].Version, - "kind": "js", + "type": "js", }, { "module": testImportModule2, "version": ext.Get(ext.JSExtension)["k6/x/testimport2"].Version, - "kind": "js", + "type": "js", }, }, }, @@ -155,7 +155,7 @@ func TestRunReportsExtensions(t *testing.T) { { "module": ext.Get(ext.OutputExtension)["testoutput"].Path, "version": ext.Get(ext.OutputExtension)["testoutput"].Version, - "kind": "output", + "type": "output", }, }, }, @@ -186,7 +186,7 @@ func TestRunReportsExtensions(t *testing.T) { { "module": testImportModule2, "version": ext.Get(ext.JSExtension)["k6/x/testimport2"].Version, - "kind": "js", + "type": "js", }, }, }, @@ -286,7 +286,7 @@ func TestRunReportsExtensions(t *testing.T) { require.NoError(t, json.Unmarshal(raw, &report)) require.Equal(t, tc.wantOutputs, report.Outputs, "expected the built-in output to stay listed under outputs") for _, e := range report.Extensions { - require.NotEqual(t, "output", e["kind"], "expected no output-kind extension entry for a built-in output") + require.NotEqual(t, "output", e["type"], "expected no output-type extension entry for a built-in output") } } diff --git a/internal/cmd/tests/cmd_subcommand_help_report_test.go b/internal/cmd/tests/cmd_subcommand_help_report_test.go index 39936faf5..56a8bb32f 100644 --- a/internal/cmd/tests/cmd_subcommand_help_report_test.go +++ b/internal/cmd/tests/cmd_subcommand_help_report_test.go @@ -30,7 +30,7 @@ func TestHelpInvocationReportsUsage(t *testing.T) { { "module": testSubModule, "version": ext.Get(ext.SubcommandExtension)["testsub"].Version, - "kind": "subcommand", + "type": "subcommand", }, } diff --git a/internal/cmd/tests/cmd_subcommand_nested_report_test.go b/internal/cmd/tests/cmd_subcommand_nested_report_test.go index 8e585717c..3b00692b5 100644 --- a/internal/cmd/tests/cmd_subcommand_nested_report_test.go +++ b/internal/cmd/tests/cmd_subcommand_nested_report_test.go @@ -136,7 +136,7 @@ func TestNestedSubcommandReportsUsage(t *testing.T) { { "module": testNestModule, "version": ext.Get(ext.SubcommandExtension)["testnest"].Version, - "kind": "subcommand", + "type": "subcommand", }, } diff --git a/internal/cmd/tests/cmd_subcommand_report_test.go b/internal/cmd/tests/cmd_subcommand_report_test.go index f61bb1c88..06121a198 100644 --- a/internal/cmd/tests/cmd_subcommand_report_test.go +++ b/internal/cmd/tests/cmd_subcommand_report_test.go @@ -68,7 +68,7 @@ func TestSubcommandReportsUsage(t *testing.T) { { "module": testSubModule, "version": ext.Get(ext.SubcommandExtension)["testsub"].Version, - "kind": "subcommand", + "type": "subcommand", }, }, }, From 60afa8a9f335cf8c8a391f25bf28a4937218419a Mon Sep 17 00:00:00 2001 From: Ankur Date: Fri, 31 Jul 2026 16:54:00 +0100 Subject: [PATCH 095/182] Address cloud provisioning review nits (#6230) * Use errors.New for the scoped push cred error The both-or-neither error string has no format arguments, so errors.New is more appropriate than fmt.Errorf. Addresses a review nit on #6170. * Update cloud poll logging to reduce noise WaitForTestRunReady logged the poll interval at Info when the default was used, and logged every status transition at Info. Neither matches the rest of the cloud subsystem: no output logs its poll interval (they are silent constants), "using default X" is only ever a Warn about bad input, and routine status is shown via a progress bar or logged at Debug (final status) / Trace (periodic flushes). Remove the poll-interval log and drop status-transition logging from Info to Debug. Addresses a review nit on #6169. --- internal/cloudapi/provisioning/api.go | 5 ++--- internal/cloudapi/provisioning/api_test.go | 6 +++--- internal/output/cloud/output.go | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/internal/cloudapi/provisioning/api.go b/internal/cloudapi/provisioning/api.go index fe037ac2e..70a2f8a81 100644 --- a/internal/cloudapi/provisioning/api.go +++ b/internal/cloudapi/provisioning/api.go @@ -115,13 +115,12 @@ func (c *Client) UploadArchive(ctx context.Context, uploadURL string, body []byt // backend status becomes "initializing" (signalling that k6 can begin // local execution). Returns an error if the test run reaches "aborted" // or "completed" first. Cancellable via context. Logs status transitions -// at Info level once per change. +// at Debug level once per change. // // If pollInterval is <= 0 the defaultWaitPollInterval is used. func (c *Client) WaitForTestRunReady(ctx context.Context, testRunID int64, pollInterval time.Duration) error { if pollInterval <= 0 { pollInterval = defaultWaitPollInterval - c.logger.WithField("interval", pollInterval).Info("using default poll interval") } var lastStatus string @@ -157,7 +156,7 @@ func (c *Client) WaitForTestRunReady(ctx context.Context, testRunID int64, pollI default: // created, queued, or any unrecognised state — keep polling. if status != lastStatus { - c.logger.WithField("status", progress.FormatStatus()).Info("test status") + c.logger.WithField("status", progress.FormatStatus()).Debug("test status") lastStatus = status } } diff --git a/internal/cloudapi/provisioning/api_test.go b/internal/cloudapi/provisioning/api_test.go index d9a0b3be9..9af55cac9 100644 --- a/internal/cloudapi/provisioning/api_test.go +++ b/internal/cloudapi/provisioning/api_test.go @@ -442,7 +442,7 @@ func TestWaitForTestRunReady_LogsTransitionsOnce(t *testing.T) { {Status: v6.StatusInitializing}, }) - logger, hook := testutils.NewLoggerWithHook(t, logrus.InfoLevel) + logger, hook := testutils.NewLoggerWithHook(t, logrus.DebugLevel) client, err := NewClient(logger, "test-token", srv.URL, "0.42.0", 7, 5*time.Second) require.NoError(t, err) @@ -450,10 +450,10 @@ func TestWaitForTestRunReady_LogsTransitionsOnce(t *testing.T) { require.NoError(t, err) entries := hook.Drain() - // Filter to only info-level entries with a "status" field. + // Filter to only debug-level entries with a "status" field. var statusEntries []logrus.Entry for _, e := range entries { - if e.Level == logrus.InfoLevel { + if e.Level == logrus.DebugLevel { if _, ok := e.Data["status"]; ok { statusEntries = append(statusEntries, e) } diff --git a/internal/output/cloud/output.go b/internal/output/cloud/output.go index d97bc2e22..4023f7f45 100644 --- a/internal/output/cloud/output.go +++ b/internal/output/cloud/output.go @@ -228,7 +228,7 @@ func (out *Output) Start() error { // env case (internal/cmd/outputs_cloud.go); this is the defensive // backstop for any other source (e.g. a hand-written cloud config). if out.config.MetricsPushURL.Valid != out.config.TestRunToken.Valid { - return fmt.Errorf( + return errors.New( "both K6_CLOUD_METRICS_PUSH_URL and K6_CLOUD_TEST_RUN_TOKEN " + "must be set together") } From 5880ca9c8d0e72213c8f3cefd8f193a5cf4b8c32 Mon Sep 17 00:00:00 2001 From: Ankur Date: Fri, 31 Jul 2026 17:23:52 +0100 Subject: [PATCH 096/182] Stream --local-execution logs to Grafana Cloud (#6171) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add logs runtime config to provisioning response start_local_execution returns runtime_config.logs (push URL, level, limit, push period, message max size, allowed labels). The SDK decodes it but the mapper dropped it. Add a LogsConfig domain type and a Logs field on RuntimeConfig, and populate it alongside the existing metrics and secrets config, so downstream code can push local-execution logs to the cloud. * Add programmatic constructor for the loki hook Extract NewLokiHook(fallbackLogger, LokiHookOptions) from LokiFromConfigLine so the hook can be built from structured config, not only a --log-output config line. LokiFromConfigLine now parses the line into options and delegates. No behaviour change; existing config-line parsing and validation are preserved. * Add cloud log-push component Add internal/log/cloud.Pusher, a logrus AsyncHook that buffers log entries until SetConfig supplies the push URL and scoped token (available only after provisioning), then pushes them to the cloud via a loki hook, labelling streams with test_run_id. Mirrors the cloud secret source's pre-register + SetConfig + lazy-init pattern. Not yet wired into the run; registration follows. * Add log-push config fields to cloudapi.Config Add env-bound (K6_CLOUD_LOGS_*) fields for the local-execution log push: URL, level, limit, push period, message max size, allowed labels. Env-only (json:"-"), mirroring LogsTailURL. An external orchestrator supplies them directly; the self-provisioned flow fills them from the provisioning response. Consumed by cmd to configure the cloud log pusher. Unset unless --local-execution enables the pusher. * Add cloud log pusher and --no-cloud-logs Auto-register the cloud log pusher on the logger for k6 cloud run --local-execution (mirroring the cloud secret source auto-registration) and start its Listen goroutine under the logger goroutine group. Add --no-cloud-logs to opt out (valid only with --local-execution). The pusher buffers until it is configured; wiring its config from the provisioning response or env follows. * Use cloud log push for local-execution Configure the registered log pusher from createCloudTest: the self-provisioned flow maps the provisioning response's logs config into cloudapi.Config; the externally-provisioned flow reads it from env. Both translate to the pusher's config and call SetConfig, labelling streams with test_run_id. k6 cloud run --local-execution now streams its logs to the cloud unless --no-cloud-logs is set. * Fix cloud log loss by draining before notify The log pusher flushed at logger shutdown, after the cloud Output notified the run complete, so the backend rejected the final log batch with 403 and it was lost. Add Pusher.Drain and call it from the cloud Output immediately before notify, so in-run logs are pushed while the run is still open. Best-effort: entries in flight inside the loki hook at flush time may not be sent; the shared loki hook is unchanged. * Use the configured level for cloud log push The pusher forwarded entries straight to the loki hook, bypassing the logrus level dispatch, so the backend-provided log level was never enforced and --verbose leaked debug logs to the cloud. Filter by the configured level in the pusher's forward path so the backend level is authoritative for cloud logs; local log output is unaffected. * Add e2e tests for cloud log-push creds Mirror TestCloudMetricsPushCredentials for the cloud log push: the tests assert which bearer token, URL and test_run_id k6 streams logs with across the self-provisioned, externally-provisioned and legacy paths. They guard the stray-env and stale-config-file token overrides on the log path, the partial-scoped-creds error, the no-pusher cases for --out=cloud and PushRefID relay runs, and that lines below the backend-configured level are filtered before push. * Fix cloud log push on an invalid backend level An unparseable logs.level from the provisioning response made NewLokiHook fail, which disabled the whole cloud log push instead of the intended fallback (the fallback warn was dead code). The level is also filtered by the pusher itself, so passing it to the hook was redundant. Stop handing Level to NewLokiHook and interpret it in the pusher: a valid level applies, an invalid one falls back to info (the backend's default) with a warning, and an unset one keeps all levels. Add TestPusher_InvalidLevelDefaultsToInfo. * Fix loki hook panic on non-positive options Negative Limit, PushPeriod or MsgMaxSize reached NewLokiHook programmatically (via K6_CLOUD_LOGS_* or a backend logs config, which bypass the config-line validation) and panicked in Listen at make([]tmpMsg, limit) / time.NewTicker(pushPeriod), or on push in the message-size slicing. The panic ran in a goroutine with no recover, taking down the whole run. Clamp non-positive values to the built-in defaults and warn, so a bad backend value degrades gracefully. The config-line path is unchanged (parseArgs still rejects them up front). Add TestNewLokiHookClampsNonPositiveOptions. * Fix cloud tests hitting the real logs host setupSelfProvisionedRun mocked the metrics push URL but left the logs push URL as DefaultStartLocalExecutionResponse's real host. Once the log pusher is active for --local-execution, the five self-provisioned subtests of TestCloudMetricsPushCredentials pushed logs to https://logs.k6.io, reaching production on a networked CI. Point the logs push URL at the in-process mock, like the metrics URL, so nothing egresses. * Add no-push assertion to the --no-cloud-logs test The --no-cloud-logs subtest only checked that the pusher was not registered. Also assert the mock received no log push, so the opt-out is guaranteed end to end rather than just at registration. * Refactor local-execution setup into one guard The cloud secret source and the cloud log-push decision were two adjacent if isCloudRunWithLocalExecution(cmd) blocks. Fold the log-push decision into the secrets block: same guard, both run before setupLoggers, and they're independent. No behaviour change. * Fix cloud logs silently skipped without a token In the externally-provisioned flow, a K6_CLOUD_LOGS_PUSH_URL set without the scoped token left the log pusher unconfigured and it streamed nothing, with only a debug line — while the metrics pair errors "must be set together". The token authenticates both, so reject a logs URL supplied without it, in applyExternalProvisioningCreds alongside the metrics check. * Fix stray env override of log-push config The Logs* config fields were env-bound (K6_CLOUD_LOGS_*), so a stray env value survived Apply and configured the pusher whenever the provisioning response omitted a logs field — the same footgun the metrics creds fix removed. Drop the envconfig tags (Logs* are programmatic-only now): the self-provisioned flow sets them from the provisioning response, and the externally-provisioned flow reads K6_CLOUD_LOGS_* explicitly in applyExternalProvisioningCreds. Cover the Logs fields in the "not picked up by envconfig" and "nil fields left unset" tests, and add TestApplyExternalLogsConfig. * Add drain test for the PushRefID path The cloud log drain runs before notify, but the only test that exercised it used the self-provisioned path, where notify also runs. Add a test that the drain runs on the external (PushRefID) path too, where notify is skipped, so a future change tying the drain to notify can't silently drop the final batch. * Use the loki client's timeout for the log drain The log drain wrapped the flush in context.WithTimeout using conf.Timeout — the cloud API request timeout, which the log path doesn't otherwise use and which every other client applies via http.Client{Timeout} (where 0 means "no timeout"). As a context deadline, K6_CLOUD_TIMEOUT=0 expired immediately, so the drain was skipped and notify raced the flush. The push is already bounded by the loki hook's own HTTP client timeout, so drain on a plain fresh context and let that govern. Add a test that the drain isn't handed an already-expired context. * Add a note on the omitted logs tail_url tail_url is for tailing logs from the cloud (the live stream in a normal k6 cloud run); --local-execution only pushes logs, so it is deliberately not mapped into LogsConfig. Note it on the type so it doesn't read as an oversight. * Add e2e test for cloud-log secret redaction The cloud log pusher observes entries only after the secrets-redaction hook, so a logged secret should reach the backend only in redacted form. Nothing tested it — a regression that let secrets through to cloud logs would pass CI. Add an e2e: a VU logs a secret from a mock source, and the pushed body must carry ***SECRET_REDACTED***, never the raw value. * Fix test_run_id loss on an empty allow-list An explicitly empty K6_CLOUD_LOGS_ALLOWED_LABELS decodes to a non-nil empty slice. The loki hook treats nil as "keep all labels" but a non-nil empty slice as "keep none", which stripped the required test_run_id label and got the cloud log push rejected with 401. Normalise an empty allow-list to nil so the keep-all path is taken and test_run_id always survives. Covered by a new unit test and an end-to-end case that sets K6_CLOUD_LOGS_ALLOWED_LABELS="". * Add a test for the rejected empty loki addr --log-output=loki= (an empty URL) is rejected up front by the config parser rather than silently falling back to the default endpoint, so no empty address ever reaches the constructor. Bare loki still uses the default. This is unchanged from before the loki hook constructor extraction, since parseArgs still runs strvals.Parse first. Add a test documenting both cases. --- cloudapi/config.go | 32 ++ cloudapi/config_test.go | 82 ++- cmd/state/state.go | 2 + internal/cloudapi/provisioning/api.go | 22 + internal/cloudapi/provisioning/api_test.go | 8 + internal/cmd/cloud_run.go | 16 + internal/cmd/outputs.go | 12 + internal/cmd/outputs_cloud.go | 115 +++- internal/cmd/outputs_cloud_test.go | 125 +++++ internal/cmd/root.go | 54 +- .../cmd_cloud_run_push_credentials_test.go | 6 + internal/cmd/tests/cmd_cloud_run_test.go | 493 +++++++++++++++++ internal/log/cloud/cloud.go | 257 +++++++++ internal/log/cloud/cloud_test.go | 519 ++++++++++++++++++ internal/log/loki.go | 118 +++- internal/log/loki_test.go | 153 ++++++ internal/output/cloud/output.go | 28 + internal/output/cloud/output_test.go | 158 ++++++ 18 files changed, 2156 insertions(+), 44 deletions(-) create mode 100644 internal/log/cloud/cloud.go create mode 100644 internal/log/cloud/cloud_test.go diff --git a/cloudapi/config.go b/cloudapi/config.go index 151883ea6..d7fde24db 100644 --- a/cloudapi/config.go +++ b/cloudapi/config.go @@ -59,6 +59,20 @@ type Config struct { // no test run id, and we may still need an identifier to correlate all the things. PushRefID null.String `json:"pushRefID" envconfig:"K6_CLOUD_PUSH_REF_ID"` + // Log-push configuration for `k6 cloud run --local-execution`. Like the + // scoped push creds above, these are programmatic-only (no envconfig tag): + // the self-provisioned flow sets them from the provisioning API's + // runtime_config.logs, while the externally-provisioned flow reads the + // K6_CLOUD_LOGS_* env vars explicitly in cmd (applyExternalLogsConfig), so + // a stray env value can't override the run-scoped values. Consumed by cmd + // to configure the cloud log pusher; never serialised. + LogsPushURL null.String `json:"-"` + LogsLevel null.String `json:"-"` + LogsLimit null.Int `json:"-"` + LogsPushPeriod types.NullDuration `json:"-"` + LogsMessageMaxSize null.Int `json:"-"` + LogsAllowedLabels []string `json:"-"` + // Defines the max allowed number of time series in a single batch. MaxTimeSeriesInBatch null.Int `json:"maxTimeSeriesInBatch" envconfig:"K6_CLOUD_MAX_TIME_SERIES_IN_BATCH"` @@ -161,6 +175,24 @@ func (c Config) Apply(cfg Config) Config { if cfg.PushRefID.Valid { c.PushRefID = cfg.PushRefID } + if cfg.LogsPushURL.Valid { + c.LogsPushURL = cfg.LogsPushURL + } + if cfg.LogsLevel.Valid { + c.LogsLevel = cfg.LogsLevel + } + if cfg.LogsLimit.Valid { + c.LogsLimit = cfg.LogsLimit + } + if cfg.LogsPushPeriod.Valid { + c.LogsPushPeriod = cfg.LogsPushPeriod + } + if cfg.LogsMessageMaxSize.Valid { + c.LogsMessageMaxSize = cfg.LogsMessageMaxSize + } + if len(cfg.LogsAllowedLabels) > 0 { + c.LogsAllowedLabels = cfg.LogsAllowedLabels + } if cfg.WebAppURL.Valid { c.WebAppURL = cfg.WebAppURL } diff --git a/cloudapi/config_test.go b/cloudapi/config_test.go index c4a4168e2..c054a4bdf 100644 --- a/cloudapi/config_test.go +++ b/cloudapi/config_test.go @@ -90,17 +90,31 @@ func TestConfig_NewFieldsNotPickedUpByEnvconfig(t *testing.T) { // Set env vars with every plausible name a user might guess. envVars := map[string]string{ - "K6_CLOUD_METRICS_PUSH_URL": "foo", - "K6_CLOUD_TEST_RUN_TOKEN": "bar", - "K6_CLOUD_METRICSPUSHURL": "foo", - "K6_CLOUD_TESTRUNTOKEN": "bar", + "K6_CLOUD_METRICS_PUSH_URL": "foo", + "K6_CLOUD_TEST_RUN_TOKEN": "bar", + "K6_CLOUD_METRICSPUSHURL": "foo", + "K6_CLOUD_TESTRUNTOKEN": "bar", + "K6_CLOUD_LOGS_PUSH_URL": "https://stray.example/logs", + "K6_CLOUD_LOGS_LEVEL": "debug", + "K6_CLOUD_LOGS_LIMIT": "5", + "K6_CLOUD_LOGS_PUSH_PERIOD": "9s", + "K6_CLOUD_LOGS_MESSAGE_MAX_SIZE": "42", + "K6_CLOUD_LOGS_ALLOWED_LABELS": "stray", } config, _, err := GetConsolidatedConfig(nil, envVars, "", nil) require.NoError(t, err) + // The scoped push creds and the log-push config are all programmatic-only, + // so none of these env vars are picked up by envconfig. assert.Equal(t, null.String{}, config.MetricsPushURL) assert.Equal(t, null.String{}, config.TestRunToken) + assert.Equal(t, null.String{}, config.LogsPushURL) + assert.Equal(t, null.String{}, config.LogsLevel) + assert.Equal(t, null.Int{}, config.LogsLimit) + assert.Equal(t, types.NullDuration{}, config.LogsPushPeriod) + assert.Equal(t, null.Int{}, config.LogsMessageMaxSize) + assert.Empty(t, config.LogsAllowedLabels) } func TestConfig_Apply_MergesNewFields(t *testing.T) { @@ -146,6 +160,66 @@ func TestConfig_Apply_MergesNewFields(t *testing.T) { } } +func TestConfig_Apply_MergesLogsFields(t *testing.T) { + t.Parallel() + + baseCfg := Config{ + LogsPushURL: null.StringFrom("https://base.example/logs"), + LogsLevel: null.StringFrom("warn"), + LogsLimit: null.IntFrom(100), + LogsPushPeriod: types.NewNullDuration(1*time.Second, true), + LogsMessageMaxSize: null.IntFrom(1024), + LogsAllowedLabels: []string{"level"}, + } + appliedCfg := Config{ + LogsPushURL: null.StringFrom("https://applied.example/logs"), + LogsLevel: null.StringFrom("info"), + LogsLimit: null.IntFrom(900), + LogsPushPeriod: types.NewNullDuration(3*time.Second, true), + LogsMessageMaxSize: null.IntFrom(10000), + LogsAllowedLabels: []string{"lz", "test_run_id"}, + } + + cases := []struct { + name string + base Config + applied Config + want Config + }{ + { + name: "applied populated, base unset → uses applied", + base: Config{}, + applied: appliedCfg, + want: appliedCfg, + }, + { + name: "applied unset, base populated → keeps base", + base: baseCfg, + applied: Config{}, + want: baseCfg, + }, + { + name: "both populated → applied wins", + base: baseCfg, + applied: appliedCfg, + want: appliedCfg, + }, + } + + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + got := tc.base.Apply(tc.applied) + assert.Equal(t, tc.want.LogsPushURL, got.LogsPushURL) + assert.Equal(t, tc.want.LogsLevel, got.LogsLevel) + assert.Equal(t, tc.want.LogsLimit, got.LogsLimit) + assert.Equal(t, tc.want.LogsPushPeriod, got.LogsPushPeriod) + assert.Equal(t, tc.want.LogsMessageMaxSize, got.LogsMessageMaxSize) + assert.Equal(t, tc.want.LogsAllowedLabels, got.LogsAllowedLabels) + }) + } +} + func TestGetConsolidatedConfig(t *testing.T) { t.Parallel() config, warn, err := GetConsolidatedConfig(json.RawMessage(`{"token":"jsonraw"}`), nil, "", nil) diff --git a/cmd/state/state.go b/cmd/state/state.go index fe5b03ba0..8f9ccdf6c 100644 --- a/cmd/state/state.go +++ b/cmd/state/state.go @@ -17,6 +17,7 @@ import ( "github.com/sirupsen/logrus" "go.k6.io/k6/v2/internal/event" + cloudlog "go.k6.io/k6/v2/internal/log/cloud" cloudsecrets "go.k6.io/k6/v2/internal/secretsource/cloud" "go.k6.io/k6/v2/internal/ui/console" "go.k6.io/k6/v2/internal/usage" @@ -95,6 +96,7 @@ type GlobalState struct { SecretsManager *secretsource.Manager CloudSecretSource *cloudsecrets.SecretSource + CloudLogPusher *cloudlog.Pusher Usage *usage.Usage TestStatus *lib.TestStatus } diff --git a/internal/cloudapi/provisioning/api.go b/internal/cloudapi/provisioning/api.go index 70a2f8a81..f49c581de 100644 --- a/internal/cloudapi/provisioning/api.go +++ b/internal/cloudapi/provisioning/api.go @@ -57,6 +57,7 @@ type RuntimeConfig struct { Metrics MetricsConfig TestRunToken string Secrets SecretsConfig + Logs LogsConfig } // MetricsConfig holds the metrics push configuration from the @@ -78,6 +79,18 @@ type SecretsConfig struct { ResponsePath string } +// LogsConfig holds the log-push configuration from the provisioning +// API's runtime_config.logs object. tail_url is intentionally omitted: +// --local-execution pushes logs, it doesn't tail them. +type LogsConfig struct { + PushURL string + Level string + Limit int32 + PushPeriodSeconds string + MessageMaxSize int32 + AllowedLabels []string +} + // UploadArchive PUTs pre-serialised archive bytes to the given // presigned S3 URL. The URL carries auth in query params, so no // Authorization header is set. Retries on 5xx and transport errors. @@ -240,6 +253,7 @@ func mapStartLocalExecutionResponse(res *k6cloud.StartLocalExecutionTestResponse rc := res.GetRuntimeConfig() m := rc.GetMetrics() s := rc.GetSecrets() + l := rc.GetLogs() resp := &StartLocalExecutionResponse{ TestRunID: res.GetTestRunId(), @@ -259,6 +273,14 @@ func mapStartLocalExecutionResponse(res *k6cloud.StartLocalExecutionTestResponse Endpoint: s.GetEndpoint(), ResponsePath: s.GetResponsePath(), }, + Logs: LogsConfig{ + PushURL: l.GetPushUrl(), + Level: l.GetLevel(), + Limit: l.GetLimit(), + PushPeriodSeconds: l.GetPushPeriodSeconds(), + MessageMaxSize: l.GetMessageMaxSize(), + AllowedLabels: l.GetAllowedLabels(), + }, }, } diff --git a/internal/cloudapi/provisioning/api_test.go b/internal/cloudapi/provisioning/api_test.go index 9af55cac9..fd7f21c47 100644 --- a/internal/cloudapi/provisioning/api_test.go +++ b/internal/cloudapi/provisioning/api_test.go @@ -91,6 +91,14 @@ func TestStartLocalExecution(t *testing.T) { require.NotNil(t, got.RuntimeConfig.Metrics.MaxSamplesPerPackage) assert.Equal(t, int32(2000), *got.RuntimeConfig.Metrics.MaxSamplesPerPackage) + // Logs config. + assert.Equal(t, "https://logs.k6.io", got.RuntimeConfig.Logs.PushURL) + assert.Equal(t, "info", got.RuntimeConfig.Logs.Level) + assert.Equal(t, int32(900), got.RuntimeConfig.Logs.Limit) + assert.Equal(t, "3s", got.RuntimeConfig.Logs.PushPeriodSeconds) + assert.Equal(t, int32(10000), got.RuntimeConfig.Logs.MessageMaxSize) + assert.Equal(t, []string{"lz", "level"}, got.RuntimeConfig.Logs.AllowedLabels) + // --- Request assertions --- assert.Equal(t, http.MethodPost, method) assert.Equal(t, "/provisioning/v1/load_tests/456/start_local_execution", path) diff --git a/internal/cmd/cloud_run.go b/internal/cmd/cloud_run.go index 944f655f1..20289483a 100644 --- a/internal/cmd/cloud_run.go +++ b/internal/cmd/cloud_run.go @@ -34,6 +34,9 @@ type cmdCloudRun struct { // noCloudSecrets stores the state of the --no-cloud-secrets flag. noCloudSecrets bool + // noCloudLogs stores the state of the --no-cloud-logs flag. + noCloudLogs bool + // runCmd holds an instance of the k6 run command that we store // in order to be able to call its run method to support // the --local-execution flag mode. @@ -132,6 +135,13 @@ func (c *cmdCloudRun) preRun(cmd *cobra.Command, args []string) error { ) } + if c.noCloudLogs { + return errext.WithExitCodeIfNone( + fmt.Errorf("the --no-cloud-logs flag can only be used in conjunction with the --local-execution flag"), + exitcodes.InvalidConfig, + ) + } + return c.deprecatedCloudCmd.preRun(cmd, args) } @@ -192,6 +202,12 @@ func (c *cmdCloudRun) flagSet() *pflag.FlagSet { c.noCloudSecrets, "only when using the local-execution mode, don't automatically configure the cloud secret source", ) + flags.BoolVar( + &c.noCloudLogs, + "no-cloud-logs", + c.noCloudLogs, + "only when using the local-execution mode, don't push logs to the cloud", + ) flags.StringArray("features", nil, "enable feature flags (comma-separated)") return flags diff --git a/internal/cmd/outputs.go b/internal/cmd/outputs.go index 2645101ed..abd87742c 100644 --- a/internal/cmd/outputs.go +++ b/internal/cmd/outputs.go @@ -187,8 +187,20 @@ func createOutputs( } } + attachCloudLogDrainer(out, gs) + result = append(result, out) } return result, nil } + +// attachCloudLogDrainer gives the cloud output the local-execution log pusher +// so it flushes buffered logs before the run is notified complete. The +// concrete-nil guard avoids handing the output a typed-nil drainer once it is +// wrapped in an interface. +func attachCloudLogDrainer(out output.Output, gs *state.GlobalState) { + if co, ok := out.(*cloud.Output); ok && gs.CloudLogPusher != nil { + co.SetLogDrainer(gs.CloudLogPusher) + } +} diff --git a/internal/cmd/outputs_cloud.go b/internal/cmd/outputs_cloud.go index df9b160c7..70d018365 100644 --- a/internal/cmd/outputs_cloud.go +++ b/internal/cmd/outputs_cloud.go @@ -10,6 +10,7 @@ import ( "strings" "time" + "github.com/mstoykov/envconfig" "github.com/sirupsen/logrus" "gopkg.in/guregu/null.v3" @@ -17,6 +18,7 @@ import ( "go.k6.io/k6/v2/cmd/state" "go.k6.io/k6/v2/internal/build" "go.k6.io/k6/v2/internal/cloudapi/provisioning" + cloudlog "go.k6.io/k6/v2/internal/log/cloud" cloudsecrets "go.k6.io/k6/v2/internal/secretsource/cloud" "go.k6.io/k6/v2/lib" "go.k6.io/k6/v2/lib/types" @@ -102,6 +104,8 @@ func createCloudTest(gs *state.GlobalState, test *loadedAndConfiguredTest) error } test.preInitState.RuntimeOptions.Env[testRunIDKey] = conf.PushRefID.String gs.Logger.Debug("using PushRefID, skipping CreateTestRun") + // Externally-provisioned run: the run id is the PushRefID. + configureCloudLogPusher(gs, conf, conf.PushRefID.String) return nil } @@ -177,6 +181,10 @@ func createCloudTest(gs *state.GlobalState, test *loadedAndConfiguredTest) error }) } + // Configure the log pusher for the self-provisioned run. The run id is + // the provisioning result's TestRunID. + configureCloudLogPusher(gs, conf, strconv.FormatInt(result.TestRunID, 10)) + // Serialise overridden Config back into the collectors map (existing pattern). raw, err := cloudConfToRawMessage(conf) if err != nil { @@ -199,16 +207,29 @@ func createCloudTest(gs *state.GlobalState, test *loadedAndConfiguredTest) error // values the self-provision flow obtains from the provisioning response. // It requires both-or-neither and, when both are present, sets them on conf // (so downstream consumers such as the log pusher see them) and bakes them -// into the serialized cloud config that the Output reads. +// into the serialized cloud config that the Output reads. It also reads the +// K6_CLOUD_LOGS_* log-push config, which the external flow supplies the same +// way. func applyExternalProvisioningCreds( gs *state.GlobalState, test *loadedAndConfiguredTest, conf *cloudapi.Config, ) error { + // The log-push config is env-supplied for an external run and likewise not + // env-bound on the Config, so read it explicitly here (before the checks + // below, which require the token when a logs URL is set). + if err := applyExternalLogsConfig(gs, conf); err != nil { + return err + } pushURL := gs.Env["K6_CLOUD_METRICS_PUSH_URL"] token := gs.Env["K6_CLOUD_TEST_RUN_TOKEN"] if (pushURL == "") != (token == "") { return errors.New("both K6_CLOUD_METRICS_PUSH_URL and " + "K6_CLOUD_TEST_RUN_TOKEN must be set together") } + // A logs push URL is authenticated with the same scoped token, so reject a + // logs URL supplied without it rather than silently streaming nothing. + if token == "" && conf.LogsPushURL.Valid && conf.LogsPushURL.String != "" { + return errors.New("K6_CLOUD_LOGS_PUSH_URL requires K6_CLOUD_TEST_RUN_TOKEN") + } if pushURL == "" { return nil } @@ -226,6 +247,41 @@ func applyExternalProvisioningCreds( return nil } +// externalLogsConfig mirrors the K6_CLOUD_LOGS_* env vars an external +// orchestrator uses to hand the log-push settings to a local k6. These are +// read explicitly (the Logs* fields are not env-bound on cloudapi.Config) so a +// stray env value can't override the run-scoped logs config in the +// self-provisioned flow. +type externalLogsConfig struct { + PushURL null.String `envconfig:"K6_CLOUD_LOGS_PUSH_URL"` + Level null.String `envconfig:"K6_CLOUD_LOGS_LEVEL"` + Limit null.Int `envconfig:"K6_CLOUD_LOGS_LIMIT"` + PushPeriod types.NullDuration `envconfig:"K6_CLOUD_LOGS_PUSH_PERIOD"` + MsgMaxSize null.Int `envconfig:"K6_CLOUD_LOGS_MESSAGE_MAX_SIZE"` + AllowedLabels []string `envconfig:"K6_CLOUD_LOGS_ALLOWED_LABELS"` +} + +// applyExternalLogsConfig reads the K6_CLOUD_LOGS_* env vars into conf for the +// externally-provisioned flow, where there is no provisioning response to +// supply them. It uses the same envconfig parsing as GetConsolidatedConfig, so +// malformed values fail the same way. +func applyExternalLogsConfig(gs *state.GlobalState, conf *cloudapi.Config) error { + var elc externalLogsConfig + if err := envconfig.Process("", &elc, func(key string) (string, bool) { + v, ok := gs.Env[key] + return v, ok + }); err != nil { + return err + } + conf.LogsPushURL = elc.PushURL + conf.LogsLevel = elc.Level + conf.LogsLimit = elc.Limit + conf.LogsPushPeriod = elc.PushPeriod + conf.LogsMessageMaxSize = elc.MsgMaxSize + conf.LogsAllowedLabels = elc.AllowedLabels + return nil +} + // validateRequiredSystemTags checks if all required tags are present. func validateRequiredSystemTags(scriptTags *metrics.SystemTagSet) error { var missingRequiredTags []string @@ -326,5 +382,62 @@ func buildConfigFromRuntimeConfig( // expv2 has no min-samples aggregation knob; adding one would // require changes to output/cloud/expv2/{collect.go, flush.go}. + // logs.push_url (string) → LogsPushURL + if v := rc.Logs.PushURL; v != "" { + cfg.LogsPushURL = null.StringFrom(v) + } + // logs.level (string) → LogsLevel + if v := rc.Logs.Level; v != "" { + cfg.LogsLevel = null.StringFrom(v) + } + // logs.limit (int32) → LogsLimit + if v := rc.Logs.Limit; v != 0 { + cfg.LogsLimit = null.IntFrom(int64(v)) + } + // logs.push_period_seconds (string) → LogsPushPeriod (NullDuration) + if v := rc.Logs.PushPeriodSeconds; v != "" { + if d, err := time.ParseDuration(v); err == nil { + cfg.LogsPushPeriod = types.NewNullDuration(d, true) + } else { + logger.WithError(err).WithField("field", "push_period_seconds"). + Warn("invalid duration in runtime_config; using default") + } + } + // logs.message_max_size (int32) → LogsMessageMaxSize + if v := rc.Logs.MessageMaxSize; v != 0 { + cfg.LogsMessageMaxSize = null.IntFrom(int64(v)) + } + // logs.allowed_labels ([]string) → LogsAllowedLabels + if v := rc.Logs.AllowedLabels; len(v) > 0 { + cfg.LogsAllowedLabels = v + } + return cfg } + +// configureCloudLogPusher points the registered cloud log pusher at the +// run. It is a no-op unless the pusher was registered (i.e. +// --local-execution without --no-cloud-logs). +func configureCloudLogPusher(gs *state.GlobalState, conf cloudapi.Config, testRunID string) { + if gs.CloudLogPusher == nil { + return + } + gs.CloudLogPusher.SetConfig(logPusherConfig(conf, testRunID)) +} + +// logPusherConfig translates the resolved cloudapi.Config log-push fields +// into the cloud log pusher's config. testRunID is the run identifier used +// as the required test_run_id stream label: result.TestRunID in the +// self-provisioned flow, PushRefID in the externally-provisioned flow. +func logPusherConfig(conf cloudapi.Config, testRunID string) cloudlog.Config { + return cloudlog.Config{ + PushURL: conf.LogsPushURL.String, + Token: conf.TestRunToken.String, + TestRunID: testRunID, + Level: conf.LogsLevel.String, + Limit: int(conf.LogsLimit.Int64), + PushPeriod: conf.LogsPushPeriod.TimeDuration(), + MsgMaxSize: int(conf.LogsMessageMaxSize.Int64), + AllowedLabels: conf.LogsAllowedLabels, + } +} diff --git a/internal/cmd/outputs_cloud_test.go b/internal/cmd/outputs_cloud_test.go index fd7a641ac..20bc39fcf 100644 --- a/internal/cmd/outputs_cloud_test.go +++ b/internal/cmd/outputs_cloud_test.go @@ -9,8 +9,11 @@ import ( "github.com/stretchr/testify/require" "gopkg.in/guregu/null.v3" + "go.k6.io/k6/v2/cloudapi" + "go.k6.io/k6/v2/cmd/state" "go.k6.io/k6/v2/internal/cloudapi/provisioning" "go.k6.io/k6/v2/internal/lib/testutils" + cloudlog "go.k6.io/k6/v2/internal/log/cloud" "go.k6.io/k6/v2/lib/types" ) @@ -39,6 +42,14 @@ func TestBuildConfigFromRuntimeConfig(t *testing.T) { Endpoint: "https://secrets.example.com", ResponsePath: "plaintext", }, + Logs: provisioning.LogsConfig{ + PushURL: "https://logs.example.com/push", + Level: "info", + Limit: 900, + PushPeriodSeconds: "3s", + MessageMaxSize: 10000, + AllowedLabels: []string{"lz", "level", "test_run_id"}, + }, } logger := testutils.NewLogger(t) @@ -63,6 +74,24 @@ func TestBuildConfigFromRuntimeConfig(t *testing.T) { // max_samples_per_package → MaxTimeSeriesInBatch assert.True(t, cfg.MaxTimeSeriesInBatch.Valid) assert.Equal(t, null.IntFrom(2000), cfg.MaxTimeSeriesInBatch) + + // logs.push_url → LogsPushURL + assert.Equal(t, null.StringFrom("https://logs.example.com/push"), cfg.LogsPushURL) + + // logs.level → LogsLevel + assert.Equal(t, null.StringFrom("info"), cfg.LogsLevel) + + // logs.limit → LogsLimit + assert.Equal(t, null.IntFrom(900), cfg.LogsLimit) + + // logs.push_period_seconds → LogsPushPeriod (parsed from "3s") + assert.Equal(t, types.NewNullDuration(3*time.Second, true), cfg.LogsPushPeriod) + + // logs.message_max_size → LogsMessageMaxSize + assert.Equal(t, null.IntFrom(10000), cfg.LogsMessageMaxSize) + + // logs.allowed_labels → LogsAllowedLabels + assert.Equal(t, []string{"lz", "level", "test_run_id"}, cfg.LogsAllowedLabels) } func TestBuildConfigFromRuntimeConfig_InvalidDurationLogsWarning(t *testing.T) { @@ -99,6 +128,66 @@ func TestBuildConfigFromRuntimeConfig_InvalidDurationLogsWarning(t *testing.T) { assert.True(t, found, "expected a warning log entry for field push_interval") } +func TestBuildConfigFromRuntimeConfig_InvalidLogsPushPeriodLogsWarning(t *testing.T) { + t.Parallel() + + rc := provisioning.RuntimeConfig{ + Logs: provisioning.LogsConfig{ + PushPeriodSeconds: "not a duration", + }, + } + + logger := logrus.New() + logger.SetLevel(logrus.DebugLevel) + hook := testutils.NewLogHook() + logger.AddHook(hook) + + cfg := buildConfigFromRuntimeConfig(logger, rc) + + // LogsPushPeriod should be left unset (invalid) when parse fails. + assert.False(t, cfg.LogsPushPeriod.Valid, "expected LogsPushPeriod to remain unset for unparseable duration") + + // A warning should have been logged (not an error). + entries := hook.Drain() + require.NotEmpty(t, entries, "expected at least one log entry for invalid duration") + + found := false + for _, e := range entries { + assert.NotEqual(t, logrus.ErrorLevel, e.Level, "invalid duration must warn, not error") + if e.Level == logrus.WarnLevel && e.Data["field"] == "push_period_seconds" { + found = true + } + } + assert.True(t, found, "expected a warning log entry for field push_period_seconds") +} + +func TestLogPusherConfig(t *testing.T) { + t.Parallel() + + conf := cloudapi.Config{ + LogsPushURL: null.StringFrom("https://logs.example.com/push"), + TestRunToken: null.StringFrom("scoped-token"), + LogsLevel: null.StringFrom("warn"), + LogsLimit: null.IntFrom(500), + LogsPushPeriod: types.NewNullDuration(2*time.Second, true), + LogsMessageMaxSize: null.IntFrom(2048), + LogsAllowedLabels: []string{"lz", "test_run_id"}, + } + + got := logPusherConfig(conf, "42") + + assert.Equal(t, cloudlog.Config{ + PushURL: "https://logs.example.com/push", + Token: "scoped-token", + TestRunID: "42", + Level: "warn", + Limit: 500, + PushPeriod: 2 * time.Second, + MsgMaxSize: 2048, + AllowedLabels: []string{"lz", "test_run_id"}, + }, got) +} + func TestBuildConfigFromRuntimeConfig_NilFieldsLeftUnset(t *testing.T) { t.Parallel() @@ -117,6 +206,16 @@ func TestBuildConfigFromRuntimeConfig_NilFieldsLeftUnset(t *testing.T) { assert.False(t, cfg.AggregationPeriod.Valid, "AggregationPeriod should be unset when input is nil") assert.False(t, cfg.AggregationWaitPeriod.Valid, "AggregationWaitPeriod should be unset when input is nil") assert.False(t, cfg.MaxTimeSeriesInBatch.Valid, "MaxTimeSeriesInBatch should be unset when input is nil") + + // The logs fields must also stay unset when provisioning omits them, so a + // stray K6_CLOUD_LOGS_* env value cannot survive Apply in the + // self-provisioned flow (the fields are programmatic-only). + assert.False(t, cfg.LogsPushURL.Valid, "LogsPushURL should be unset when input is nil") + assert.False(t, cfg.LogsLevel.Valid, "LogsLevel should be unset when input is nil") + assert.False(t, cfg.LogsLimit.Valid, "LogsLimit should be unset when input is nil") + assert.False(t, cfg.LogsPushPeriod.Valid, "LogsPushPeriod should be unset when input is nil") + assert.False(t, cfg.LogsMessageMaxSize.Valid, "LogsMessageMaxSize should be unset when input is nil") + assert.Empty(t, cfg.LogsAllowedLabels, "LogsAllowedLabels should be unset when input is nil") } func TestBuildConfigFromRuntimeConfig_AggregationMinSamplesIgnored(t *testing.T) { @@ -150,3 +249,29 @@ func TestBuildConfigFromRuntimeConfig_AggregationMinSamplesIgnored(t *testing.T) assert.NotEqual(t, logrus.ErrorLevel, e.Level, "unexpected error logged for intentionally dropped field") } } + +// TestApplyExternalLogsConfig verifies the externally-provisioned flow reads +// the log-push knobs from the K6_CLOUD_LOGS_* env vars into the config (the +// fields are not env-bound on cloudapi.Config, so cmd reads them explicitly). +func TestApplyExternalLogsConfig(t *testing.T) { + t.Parallel() + + gs := &state.GlobalState{Env: map[string]string{ + "K6_CLOUD_LOGS_PUSH_URL": "https://api.k6.io/logs/v1/test_runs/42", + "K6_CLOUD_LOGS_LEVEL": "info", + "K6_CLOUD_LOGS_LIMIT": "900", + "K6_CLOUD_LOGS_PUSH_PERIOD": "3s", + "K6_CLOUD_LOGS_MESSAGE_MAX_SIZE": "10000", + "K6_CLOUD_LOGS_ALLOWED_LABELS": "lz,level,test_run_id", + }} + + var conf cloudapi.Config + require.NoError(t, applyExternalLogsConfig(gs, &conf)) + + assert.Equal(t, null.StringFrom("https://api.k6.io/logs/v1/test_runs/42"), conf.LogsPushURL) + assert.Equal(t, null.StringFrom("info"), conf.LogsLevel) + assert.Equal(t, null.IntFrom(900), conf.LogsLimit) + assert.Equal(t, types.NewNullDuration(3*time.Second, true), conf.LogsPushPeriod) + assert.Equal(t, null.IntFrom(10000), conf.LogsMessageMaxSize) + assert.Equal(t, []string{"lz", "level", "test_run_id"}, conf.LogsAllowedLabels) +} diff --git a/internal/cmd/root.go b/internal/cmd/root.go index 359c5ed91..1acb71587 100644 --- a/internal/cmd/root.go +++ b/internal/cmd/root.go @@ -21,6 +21,7 @@ import ( "go.k6.io/k6/v2/errext/exitcodes" "go.k6.io/k6/v2/ext" "go.k6.io/k6/v2/internal/log" + cloudlog "go.k6.io/k6/v2/internal/log/cloud" "go.k6.io/k6/v2/secretsource" _ "go.k6.io/k6/v2/internal/secretsource" // import it to register internal secret sources @@ -84,10 +85,11 @@ func ExecuteWithGlobalState(gs *state.GlobalState) { type rootCommand struct { globalState *state.GlobalState - cmd *cobra.Command - stopLoggersCh chan struct{} - loggersWg sync.WaitGroup - loggerIsRemote bool + cmd *cobra.Command + stopLoggersCh chan struct{} + loggersWg sync.WaitGroup + loggerIsRemote bool + enableCloudLogPush bool } // newRootCommand creates a root command with a default launcher @@ -148,14 +150,20 @@ func (c *rootCommand) persistentPreRunE(cmd *cobra.Command, _ []string) error { return errext.WithExitCodeIfNone(errAlreadyReported, exitcodes.InvalidConfig) } - // For 'k6 cloud run --local-execution', automatically register the cloud secret source - // so scripts can call secrets.get() without any extra flags. - // This must happen before setupLoggers, which calls createSecretSources internally. + // For 'k6 cloud run --local-execution', wire up the cloud secret source and + // the cloud log push. Both must happen before setupLoggers, which calls + // createSecretSources and registers the log pusher on the logger. if isCloudRunWithLocalExecution(cmd) { - f := cmd.Flag("no-cloud-secrets") - if f == nil || f.Value.String() != "true" { + // Register the cloud secret source so scripts can call secrets.get() + // without any extra flags. + if f := cmd.Flag("no-cloud-secrets"); f == nil || f.Value.String() != "true" { c.globalState.Flags.SecretSource = append(c.globalState.Flags.SecretSource, "cloud") } + + // Push k6's own logs to the cloud unless --no-cloud-logs is set; the + // decision is applied in setupLoggers. + f := cmd.Flag("no-cloud-logs") + c.enableCloudLogPush = f == nil || f.Value.String() != "true" } err := c.setupLoggers(c.stopLoggersCh) @@ -417,6 +425,10 @@ func (c *rootCommand) setupLoggers(stop <-chan struct{}) error { c.setLoggerHook(ctx, hook) } + // Attach the cloud log pusher after the secrets-redaction hook so it only + // ever observes redacted entries (see setupCloudLogPusher). + c.setupCloudLogPusher(stop) + // Sometimes the Go runtime uses the standard log output to // log some messages directly. // It does when an invalid char is found in a Cookie. @@ -439,6 +451,30 @@ func (c *rootCommand) setLoggerHook(ctx context.Context, h log.AsyncHook) { c.globalState.Logger.SetOutput(io.Discard) // don't output to anywhere else } +// setupCloudLogPusher registers the cloud log pusher on the logger and starts +// its Listen goroutine under the logger goroutine group. It does nothing unless +// cloud log push is enabled. It must be called after the secrets-redaction hook +// is registered: logrus fires hooks in registration order and each hook mutates +// the same entry in place, so a hook added later only observes redacted entries. +// Unlike setLoggerHook, the hook is added directly and the primary log output is +// left intact; the pusher only mirrors entries to the cloud. The pusher buffers +// until it is configured and drains on shutdown when stop fires and its context +// is cancelled. +func (c *rootCommand) setupCloudLogPusher(stop <-chan struct{}) { + if !c.enableCloudLogPush { + return + } + p := cloudlog.New(c.globalState.FallbackLogger) + c.globalState.CloudLogPusher = p + c.globalState.Logger.AddHook(p) + pctx, pcancel := context.WithCancel(context.Background()) + c.loggersWg.Go(func() { p.Listen(pctx) }) + c.loggersWg.Go(func() { + <-stop + pcancel() + }) +} + //nolint:gocognit func createSecretSources(gs *state.GlobalState) (map[string]secretsource.Source, error) { baseParams := secretsource.Params{ diff --git a/internal/cmd/tests/cmd_cloud_run_push_credentials_test.go b/internal/cmd/tests/cmd_cloud_run_push_credentials_test.go index fcb74f4dc..8ec84ca92 100644 --- a/internal/cmd/tests/cmd_cloud_run_push_credentials_test.go +++ b/internal/cmd/tests/cmd_cloud_run_push_credentials_test.go @@ -140,6 +140,12 @@ func setupSelfProvisionedRun( m := rc.GetMetrics() m.SetPushUrl(srv.URL + "/v1/metrics") rc.SetMetrics(m) + // Point the logs push URL at the mock too: --local-execution activates + // the cloud log pusher, which would otherwise egress to the real logs + // host baked into DefaultStartLocalExecutionResponse. + l := rc.GetLogs() + l.SetPushUrl(srv.URL + logsPushPath) + rc.SetLogs(l) resp.SetRuntimeConfig(rc) writeProvJSON(w, http.StatusOK, resp) }) diff --git a/internal/cmd/tests/cmd_cloud_run_test.go b/internal/cmd/tests/cmd_cloud_run_test.go index d2b21df52..a2b93ea8d 100644 --- a/internal/cmd/tests/cmd_cloud_run_test.go +++ b/internal/cmd/tests/cmd_cloud_run_test.go @@ -8,6 +8,8 @@ import ( "os" "path/filepath" "strconv" + "strings" + "sync" "sync/atomic" "testing" @@ -155,6 +157,11 @@ func TestCloudRunCommandIncompatibleFlags(t *testing.T) { cliArgs: []string{"--no-cloud-secrets"}, wantStderrContains: "the --no-cloud-secrets flag can only be used in conjunction with the --local-execution flag", }, + { + name: "using --no-cloud-logs without --local-execution should fail", + cliArgs: []string{"--no-cloud-logs"}, + wantStderrContains: "the --no-cloud-logs flag can only be used in conjunction with the --local-execution flag", + }, } for _, tc := range testCases { @@ -229,6 +236,11 @@ export default function() {};` m := rc.GetMetrics() m.SetPushUrl(srv.URL + "/v1/metrics") rc.SetMetrics(m) + // Point the logs push_url at the test server too, so the + // configured pusher never contacts the real logs host. + l := rc.GetLogs() + l.SetPushUrl(srv.URL + logsPushPath) + rc.SetLogs(l) resp.SetRuntimeConfig(rc) writeProvJSON(w, http.StatusOK, resp) }) @@ -318,6 +330,11 @@ export default function() {};` m := rc.GetMetrics() m.SetPushUrl(srv.URL + "/v1/metrics") rc.SetMetrics(m) + // Point the logs push_url at the test server too, so the + // configured pusher never contacts the real logs host. + l := rc.GetLogs() + l.SetPushUrl(srv.URL + logsPushPath) + rc.SetLogs(l) resp.SetRuntimeConfig(rc) writeProvJSON(w, http.StatusOK, resp) }) @@ -387,6 +404,11 @@ export default function() { m := rc.GetMetrics() m.SetPushUrl(srv.URL + "/v1/metrics") rc.SetMetrics(m) + // Point the logs push_url at the test server too, so the + // configured pusher never contacts the real logs host. + l := rc.GetLogs() + l.SetPushUrl(srv.URL + logsPushPath) + rc.SetLogs(l) resp.SetRuntimeConfig(rc) writeProvJSON(w, http.StatusOK, resp) }) @@ -496,6 +518,11 @@ export default function() {};` m := rc.GetMetrics() m.SetPushUrl(srv.URL + "/v1/metrics") rc.SetMetrics(m) + // Point the logs push_url at the test server too, so the + // configured pusher never contacts the real logs host. + l := rc.GetLogs() + l.SetPushUrl(srv.URL + logsPushPath) + rc.SetLogs(l) resp.SetRuntimeConfig(rc) writeProvJSON(w, http.StatusOK, resp) }) @@ -525,6 +552,472 @@ export default function() {};` assert.Nil(t, ts.CloudSecretSource, "cloud secret source should not be registered when --no-cloud-secrets is set") } +func TestCloudRunLocalExecutionCloudLogPusher(t *testing.T) { + t.Parallel() + + // The VU logs one line so the pusher has a deterministic entry to push; + // console.log routes through the same logger the pusher hooks. + script := ` +export const options = { + cloud: { + name: 'Test cloud logs', + projectID: 123456, + }, +}; +export default function() { console.log('hello from the vu'); };` + + t.Run("registers the pusher for --local-execution", func(t *testing.T) { + t.Parallel() + + ts := makeTestState(t, script, []string{"--local-execution"}) + rec := setupLocalExecutionProvMock(t, ts) + + cmd.ExecuteWithGlobalState(ts.GlobalState) + + assert.NotNil(t, ts.CloudLogPusher, + "cloud log pusher should be registered for k6 cloud run --local-execution") + + // The self-provisioned flow must configure the pusher from the + // provisioning response: streams are pushed with the scoped token + // and the result's TestRunID as the test_run_id label. + auths, bodies := rec.snapshot() + require.NotEmpty(t, bodies, "expected at least one cloud log push") + assert.Equal(t, "Bearer test-run-token-abc", auths[0]) + assert.Contains(t, bodies[0], + fmt.Sprintf(`"test_run_id":"%d"`, provtest.DefaultTestRunID)) + }) + + t.Run("configures the pusher from env for an externally-provisioned run", func(t *testing.T) { + t.Parallel() + + rec := &logPushRecorder{} + const pushRefID = "99999" + + srv := getTestServer(t, map[string]http.Handler{ + "POST ^" + logsPushPath + "$": http.HandlerFunc(rec.handler), + "POST ^/v1/tests$": http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { + require.Fail(t, "CreateTestRun must not be called when K6_CLOUD_PUSH_REF_ID is set") + }), + "POST ^/provisioning/v1/": http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { + require.Fail(t, "provisioning API must not be called when K6_CLOUD_PUSH_REF_ID is set") + }), + }) + t.Cleanup(srv.Close) + + ts := makeTestState(t, script, []string{"--local-execution"}) + ts.Env["K6_CLOUD_HOST"] = srv.URL + ts.Env["K6_CLOUD_HOST_V6"] = srv.URL + ts.Env["K6_CLOUD_PUSH_REF_ID"] = pushRefID + ts.Env["K6_CLOUD_LOGS_PUSH_URL"] = srv.URL + logsPushPath + // An external orchestrator supplies the scoped metrics push creds + // (PR #6133); they must be set together, and the same token is used + // as the Bearer for the logs push. + ts.Env["K6_CLOUD_METRICS_PUSH_URL"] = srv.URL + "/v1/metrics" + ts.Env["K6_CLOUD_TEST_RUN_TOKEN"] = "ext-token" + + cmd.ExecuteWithGlobalState(ts.GlobalState) + + require.NotNil(t, ts.CloudLogPusher, + "cloud log pusher should be registered for an externally-provisioned --local-execution run") + + // The externally-provisioned flow reads the logs config and token + // from env; the run id is the PushRefID. + auths, bodies := rec.snapshot() + require.NotEmpty(t, bodies, "expected at least one cloud log push") + assert.Equal(t, "Bearer ext-token", auths[0]) + assert.Contains(t, bodies[0], `"test_run_id":"`+pushRefID+`"`) + }) + + t.Run("externally-provisioned run keeps test_run_id with empty allowed labels", func(t *testing.T) { + t.Parallel() + + rec := &logPushRecorder{} + const pushRefID = "99999" + + srv := getTestServer(t, map[string]http.Handler{ + "POST ^" + logsPushPath + "$": http.HandlerFunc(rec.handler), + }) + t.Cleanup(srv.Close) + + ts := makeTestState(t, script, []string{"--local-execution"}) + ts.Env["K6_CLOUD_HOST"] = srv.URL + ts.Env["K6_CLOUD_HOST_V6"] = srv.URL + ts.Env["K6_CLOUD_PUSH_REF_ID"] = pushRefID + ts.Env["K6_CLOUD_LOGS_PUSH_URL"] = srv.URL + logsPushPath + ts.Env["K6_CLOUD_METRICS_PUSH_URL"] = srv.URL + "/v1/metrics" + ts.Env["K6_CLOUD_TEST_RUN_TOKEN"] = "ext-token" + // An explicitly empty allow-list decodes to []string{}; the required + // test_run_id label must still survive rather than be stripped. + ts.Env["K6_CLOUD_LOGS_ALLOWED_LABELS"] = "" + + cmd.ExecuteWithGlobalState(ts.GlobalState) + + _, bodies := rec.snapshot() + require.NotEmpty(t, bodies, "expected at least one cloud log push") + assert.Contains(t, bodies[0], `"test_run_id":"`+pushRefID+`"`, + "test_run_id must survive an empty K6_CLOUD_LOGS_ALLOWED_LABELS") + }) + + t.Run("does not register the pusher with --no-cloud-logs", func(t *testing.T) { + t.Parallel() + + ts := makeTestState(t, script, []string{"--local-execution", "--no-cloud-logs"}) + rec := setupLocalExecutionProvMock(t, ts) + + cmd.ExecuteWithGlobalState(ts.GlobalState) + + assert.Nil(t, ts.CloudLogPusher, + "cloud log pusher should not be registered when --no-cloud-logs is set") + _, bodies := rec.snapshot() + assert.Empty(t, bodies, "no logs should be pushed when --no-cloud-logs is set") + }) + + t.Run("does not register the pusher for non-local-execution", func(t *testing.T) { + t.Parallel() + + ts := NewGlobalTestState(t) + require.NoError(t, fsext.WriteFile(ts.FS, filepath.Join(ts.Cwd, "test.js"), []byte(script), 0o644)) + ts.CmdArgs = []string{"k6", "run", "test.js"} + + cmd.ExecuteWithGlobalState(ts.GlobalState) + + assert.Nil(t, ts.CloudLogPusher, + "cloud log pusher should not be registered for a non-local-execution run") + }) + + // The subtests below mirror TestCloudMetricsPushCredentials (which pins the metrics + // push-credential resolution) for the cloud *log* push: the observable + // is which bearer token / URL k6 streams logs with across the + // self-provisioned, externally-provisioned and legacy paths. The + // sentinel token consts (scopedToken, bogusToken, extToken, + // staleConfigToken, orgToken) are shared with + // cmd_cloud_run_push_credentials_test.go. + + // A2 (log): a stray K6_CLOUD_TEST_RUN_TOKEN in the env must NOT override + // the run-scoped token the self-provisioned flow gets from provisioning. + // The token is programmatic-only (no envconfig), so the stray is inert. + t.Run("self-provisioned log push ignores a stray token env var", func(t *testing.T) { + t.Parallel() + + ts := makeTestState(t, script, []string{"--local-execution"}) + rec := setupLocalExecutionProvMock(t, ts) + ts.Env["K6_CLOUD_TEST_RUN_TOKEN"] = bogusToken + + cmd.ExecuteWithGlobalState(ts.GlobalState) + + auths, bodies := rec.snapshot() + require.NotEmpty(t, bodies, "expected at least one cloud log push") + for _, a := range auths { + assert.Equalf(t, "Bearer "+scopedToken, a, + "log push must use the run-scoped token, not the stray env token %q", bogusToken) + } + }) + + // A3 (log): a stray K6_CLOUD_LOGS_PUSH_URL must NOT override the + // provisioning-supplied logs URL. conf.Apply(runtime_config) overwrites + // the env value. If it leaked, the push would go to the unroutable host + // and the provisioning logs endpoint (rec) would record nothing. + t.Run("self-provisioned log push ignores a stray logs-push-URL env var", func(t *testing.T) { + t.Parallel() + + ts := makeTestState(t, script, []string{"--local-execution"}) + rec := setupLocalExecutionProvMock(t, ts) + ts.Env["K6_CLOUD_LOGS_PUSH_URL"] = "http://stray.invalid/logs/push" + + cmd.ExecuteWithGlobalState(ts.GlobalState) + + auths, bodies := rec.snapshot() + require.NotEmpty(t, bodies, + "log push must hit the provisioning logs URL, not the stray env URL") + for _, a := range auths { + assert.Equal(t, "Bearer "+scopedToken, a) + } + }) + + // A4 (log): both stray env vars at once — scoped token + provisioning URL + // must still win. + t.Run("self-provisioned log push ignores both stray env vars", func(t *testing.T) { + t.Parallel() + + ts := makeTestState(t, script, []string{"--local-execution"}) + rec := setupLocalExecutionProvMock(t, ts) + ts.Env["K6_CLOUD_TEST_RUN_TOKEN"] = bogusToken + ts.Env["K6_CLOUD_LOGS_PUSH_URL"] = "http://stray.invalid/logs/push" + + cmd.ExecuteWithGlobalState(ts.GlobalState) + + auths, bodies := rec.snapshot() + require.NotEmpty(t, bodies, + "log push must hit the provisioning logs URL with the scoped token") + for _, a := range auths { + assert.Equal(t, "Bearer "+scopedToken, a) + } + }) + + // A8 (log): a stale testRunToken living in the k6 config file must NOT + // override the run-scoped token in the self-provisioned flow. + t.Run("self-provisioned log push ignores a stale config-file token", func(t *testing.T) { + t.Parallel() + + ts := makeTestState(t, script, []string{"--local-execution"}) + rec := setupLocalExecutionProvMock(t, ts) + cfg := []byte(`{"collectors":{"cloud":{"testRunToken":"` + staleConfigToken + `"}}}`) + require.NoError(t, ts.FS.MkdirAll(filepath.Dir(ts.Flags.ConfigFilePath), 0o755)) + require.NoError(t, fsext.WriteFile(ts.FS, ts.Flags.ConfigFilePath, cfg, 0o644)) + + cmd.ExecuteWithGlobalState(ts.GlobalState) + + auths, bodies := rec.snapshot() + require.NotEmpty(t, bodies, "expected at least one cloud log push") + for _, a := range auths { + assert.Equalf(t, "Bearer "+scopedToken, a, + "log push must use the run-scoped token, not the stale config token %q", staleConfigToken) + } + }) + + // B2 (log): partial scoped creds (only the token) must error before any + // log push happens. + t.Run("errors on partial scoped creds and pushes no logs", func(t *testing.T) { + t.Parallel() + + ts := makeTestState(t, script, []string{"--local-execution", "--log-output=stdout"}) + ts.Env["K6_CLOUD_PUSH_REF_ID"] = "99999" + ts.Env["K6_CLOUD_TEST_RUN_TOKEN"] = extToken // only one of the required pair + ts.ExpectedExitCode = -1 + + rec := &logPushRecorder{} + srv := getTestServer(t, map[string]http.Handler{ + "POST ^" + logsPushPath + "$": http.HandlerFunc(rec.handler), + }) + t.Cleanup(srv.Close) + ts.Env["K6_CLOUD_HOST"] = srv.URL + ts.Env["K6_CLOUD_HOST_V6"] = srv.URL + + cmd.ExecuteWithGlobalState(ts.GlobalState) + + out := ts.Stdout.String() + ts.Stderr.String() + assert.Contains(t, out, "must be set together", + "expected a clear both-or-neither error for partial scoped creds") + _, bodies := rec.snapshot() + assert.Empty(t, bodies, "no cloud log push should happen when the run errors out") + }) + + // A logs push URL in the externally-provisioned flow is useless without the + // scoped token; it must error rather than silently stream nothing. + t.Run("errors when a logs push URL is set without a token", func(t *testing.T) { + t.Parallel() + + ts := makeTestState(t, script, []string{"--local-execution", "--log-output=stdout"}) + ts.Env["K6_CLOUD_PUSH_REF_ID"] = "99999" + ts.Env["K6_CLOUD_LOGS_PUSH_URL"] = "http://logs.invalid/push" + // No K6_CLOUD_TEST_RUN_TOKEN (nor the K6_CLOUD_METRICS_PUSH_URL it + // pairs with), so there is no token to authenticate the logs push. + ts.ExpectedExitCode = -1 + + srv := getTestServer(t, map[string]http.Handler{}) + t.Cleanup(srv.Close) + ts.Env["K6_CLOUD_HOST"] = srv.URL + ts.Env["K6_CLOUD_HOST_V6"] = srv.URL + + cmd.ExecuteWithGlobalState(ts.GlobalState) + + out := ts.Stdout.String() + ts.Stderr.String() + assert.Contains(t, out, "K6_CLOUD_LOGS_PUSH_URL requires K6_CLOUD_TEST_RUN_TOKEN") + }) + + // A5/A6 (log): the legacy `k6 run --out=cloud` path must not register a + // cloud log pusher at all (log streaming is a --local-execution feature). + t.Run("does not register the pusher for k6 run --out=cloud", func(t *testing.T) { + t.Parallel() + + ts := getSingleFileTestState(t, script, []string{"-v", "--log-output=stdout", "--out=cloud"}, 0) + ts.Env["K6_CLOUD_TOKEN"] = orgToken + const refID = 1337 + srv := getTestServer(t, map[string]http.Handler{ + "POST ^/v1/tests$": http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusOK) + _, _ = fmt.Fprintf(w, `{"reference_id": "%d", "config": {}}`, refID) + }), + }) + t.Cleanup(srv.Close) + ts.Env["K6_CLOUD_HOST"] = srv.URL + + cmd.ExecuteWithGlobalState(ts.GlobalState) + + assert.Nil(t, ts.CloudLogPusher, + "cloud log streaming is only for cloud run --local-execution, not --out=cloud") + }) + + // A6 (log): a PushRefID relay run with no scoped creds and no logs push + // URL must not push logs anywhere (the pusher stays unconfigured). + t.Run("relay run without a logs push URL pushes no logs", func(t *testing.T) { + t.Parallel() + + ts := makeTestState(t, script, []string{"--local-execution"}) + ts.Env["K6_CLOUD_PUSH_REF_ID"] = "99999" + + rec := &logPushRecorder{} + srv := getTestServer(t, map[string]http.Handler{ + "POST ^/v1/tests$": failHandler(t, "CreateTestRun must not be called with PushRefID"), + "POST ^/provisioning/v1/": failHandler(t, "provisioning API must not be called with PushRefID"), + "POST ^" + logsPushPath + "$": http.HandlerFunc(rec.handler), + }) + t.Cleanup(srv.Close) + ts.Env["K6_CLOUD_HOST"] = srv.URL + ts.Env["K6_CLOUD_HOST_V6"] = srv.URL + + cmd.ExecuteWithGlobalState(ts.GlobalState) + + _, bodies := rec.snapshot() + assert.Empty(t, bodies, + "a relay run with no logs push URL must not push logs anywhere") + }) + + // "and more" (beyond the metrics matrix): the pusher must honour the + // backend-configured log level. The logger runs at debug (-v) so + // console.debug reaches the pusher hook; the provisioning logs config + // (level=info) must then drop it before pushing, while info survives. + t.Run("self-provisioned log push filters lines below the configured level", func(t *testing.T) { + t.Parallel() + + lvlScript := ` +export const options = { cloud: { name: 'Test cloud logs', projectID: 123456 } }; +export default function() { + console.debug('debug-line-must-be-filtered'); + console.log('info-line-must-be-pushed'); +};` + ts := makeTestState(t, lvlScript, []string{"--local-execution", "-v", "--log-output=stdout"}) + rec := setupLocalExecutionProvMock(t, ts) + + cmd.ExecuteWithGlobalState(ts.GlobalState) + + _, bodies := rec.snapshot() + require.NotEmpty(t, bodies, "expected at least one cloud log push") + all := strings.Join(bodies, "\n") + assert.Contains(t, all, "info-line-must-be-pushed", + "info-level lines should be pushed") + assert.NotContains(t, all, "debug-line-must-be-filtered", + "debug-level lines must be filtered out by the configured level (info)") + }) + + // A logged secret must reach the cloud only in redacted form: the + // secrets-redaction hook runs before the pusher observes an entry + // (root.go), so the push never carries the raw value. Guards that + // property end to end. + t.Run("redacts secrets before pushing logs", func(t *testing.T) { + t.Parallel() + + const secret = "super-secret-value" + secretScript := ` +import secrets from "k6/secrets"; +export const options = { cloud: { name: 'Test cloud logs', projectID: 123456 } }; +export default async function() { + const s = await secrets.get("mykey"); + console.log("the secret is " + s); +};` + ts := makeTestState(t, secretScript, []string{ + "--local-execution", "--no-cloud-secrets", + "--secret-source=mock=mykey=" + secret, + }) + rec := setupLocalExecutionProvMock(t, ts) + + cmd.ExecuteWithGlobalState(ts.GlobalState) + + _, bodies := rec.snapshot() + require.NotEmpty(t, bodies, "expected at least one cloud log push") + all := strings.Join(bodies, "\n") + assert.Contains(t, all, "***SECRET_REDACTED***", + "the log line should reach the cloud only in redacted form") + assert.NotContains(t, all, secret, + "the raw secret must never reach the cloud log push") + }) +} + +// logsPushPath is the path the local-execution mocks use for the cloud +// logs push endpoint, overriding the real host baked into +// DefaultStartLocalExecutionResponse so tests never contact it. +const logsPushPath = "/logs/v1/push" + +// logPushRecorder captures cloud log pushes received by the mock server so +// tests can assert on the pusher wiring (auth header + test_run_id label). +type logPushRecorder struct { + mu sync.Mutex + auths []string + bodies []string +} + +func (r *logPushRecorder) handler(w http.ResponseWriter, req *http.Request) { + body, _ := io.ReadAll(req.Body) + r.mu.Lock() + r.auths = append(r.auths, req.Header.Get("Authorization")) + r.bodies = append(r.bodies, string(body)) + r.mu.Unlock() + w.WriteHeader(http.StatusNoContent) +} + +func (r *logPushRecorder) snapshot() (auths, bodies []string) { + r.mu.Lock() + defer r.mu.Unlock() + return append([]string(nil), r.auths...), append([]string(nil), r.bodies...) +} + +// setupLocalExecutionProvMock wires a provisioning mock server for a +// k6 cloud run --local-execution flow and points ts at it. It mirrors the +// handlers used by TestCloudRunLocalExecutionNoCloudSecrets. The returned +// recorder captures any cloud log pushes; the logs push_url is overridden +// onto the mock server so the real logs host is never contacted. +func setupLocalExecutionProvMock(t *testing.T, ts *GlobalTestState) *logPushRecorder { + t.Helper() + + rec := &logPushRecorder{} + srv := provtest.NewServer(t) + + srv.HandleCreateLoadTest(123456, func(w http.ResponseWriter, _ *http.Request) { + res := k6cloud.NewLoadTestApiModelWithDefaults() + res.SetId(provtest.DefaultLoadTestID) + writeProvJSON(w, http.StatusCreated, res) + }) + + srv.HandleStartLocalExecution(provtest.DefaultLoadTestID, func(w http.ResponseWriter, _ *http.Request) { + resp := provtest.DefaultStartLocalExecutionResponse() + uploadURL := srv.URL + provtest.PresignedUploadPath + resp.SetArchiveUploadUrl(uploadURL) + resp.SetTestRunDetailsPageUrl(fmt.Sprintf("%s/runs/%d", srv.URL, provtest.DefaultTestRunID)) + rc := resp.GetRuntimeConfig() + m := rc.GetMetrics() + m.SetPushUrl(srv.URL + "/v1/metrics") + rc.SetMetrics(m) + l := rc.GetLogs() + l.SetPushUrl(srv.URL + logsPushPath) + rc.SetLogs(l) + resp.SetRuntimeConfig(rc) + writeProvJSON(w, http.StatusOK, resp) + }) + + srv.HandlePresignedUpload(provtest.PresignedUploadPath, func(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusOK) + }) + + srv.HandleFetchTestRun(provtest.DefaultTestRunID, []v6.TestProgress{ + {Status: v6.StatusInitializing}, + }) + + srv.HandleNotify(provtest.DefaultTestRunID, func(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusOK) + }) + + srv.Mux.HandleFunc("POST "+logsPushPath, rec.handler) + + srv.Mux.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusOK) + }) + + ts.Env["K6_CLOUD_HOST"] = srv.URL + ts.Env["K6_CLOUD_HOST_V6"] = srv.URL + + return rec +} + func makeTestState(tb testing.TB, script string, cliFlags []string) *GlobalTestState { if cliFlags == nil { cliFlags = []string{"-v", "--log-output=stdout"} diff --git a/internal/log/cloud/cloud.go b/internal/log/cloud/cloud.go new file mode 100644 index 000000000..6fdad6ae2 --- /dev/null +++ b/internal/log/cloud/cloud.go @@ -0,0 +1,257 @@ +// Package cloudlog implements a logrus hook that pushes k6's own logs to the +// Grafana Cloud k6 logs backend for 'k6 cloud run --local-execution'. +// +// The package lives in directory internal/log/cloud but is named cloudlog +// (not cloud) so that call sites which also import internal/secretsource/cloud +// do not have a package-name collision. +// +// It takes a plain Config struct and does not import cloudapi or +// internal/cloudapi/provisioning (avoiding an import cycle); the cmd layer +// translates the provisioning response or environment into Config. +package cloudlog + +import ( + "context" + "slices" + "sync" + "sync/atomic" + "time" + + "github.com/sirupsen/logrus" + + "go.k6.io/k6/v2/internal/log" +) + +// bufferCap bounds the pre-configuration entry buffer. It matches the loki +// hook's own channel capacity so Fire stays non-blocking under the same load. +const bufferCap = 1000 + +// testRunIDLabel is the stream label the backend requires on every push: a +// push whose stream lacks it, or carries a value not matching the token's run, +// is rejected with 401. +const testRunIDLabel = "test_run_id" + +// Config is the log-push configuration, translated by the cmd layer from the +// provisioning response or the environment. It intentionally depends on no +// cloudapi or provisioning types. +type Config struct { + PushURL string // loki push endpoint (empty => unconfigured) + Token string // scoped test-run token, sent as Authorization: Bearer + TestRunID string // added as the required test_run_id stream label + Level string // minimum level; "" => all levels + Limit int // max entries per push period + PushPeriod time.Duration // how often batches are flushed + MsgMaxSize int // per-message truncation size + AllowedLabels []string // stream labels to keep; empty => keep all +} + +// Pusher is a logrus AsyncHook that buffers log entries until SetConfig +// supplies the push URL and scoped token (available only after provisioning), +// then forwards buffered and subsequent entries to the cloud through an +// internal/log loki hook. It mirrors the cloud secret source's pre-register + +// SetConfig + lazy-init pattern. +type Pusher struct { + fallbackLogger logrus.FieldLogger + cfg atomic.Pointer[Config] + ready chan struct{} // closed once by SetConfig when configured + readyOnce sync.Once + buf chan *logrus.Entry + dropped atomic.Int64 + drainCh chan struct{} // closed once by Drain to request a final flush + drainOnce sync.Once + doneCh chan struct{} // closed by Listen on return, signalling Drain +} + +// Compile-time check that Pusher is usable as a logrus async hook. +var _ log.AsyncHook = (*Pusher)(nil) + +// New creates a Pusher that buffers entries until SetConfig configures it. +func New(fallbackLogger logrus.FieldLogger) *Pusher { + return &Pusher{ + fallbackLogger: fallbackLogger, + ready: make(chan struct{}), + buf: make(chan *logrus.Entry, bufferCap), + drainCh: make(chan struct{}), + doneCh: make(chan struct{}), + } +} + +// SetConfig stores the push configuration and signals readiness once. It is +// safe to call before or after Listen starts. An empty PushURL, TestRunID, or +// Token leaves the Pusher unconfigured (it keeps buffering and never pushes), +// since the backend requires all three. +func (p *Pusher) SetConfig(c Config) { + if c.PushURL == "" || c.TestRunID == "" || c.Token == "" { + if p.fallbackLogger != nil { + p.fallbackLogger.Debug("cloud log push not configured: missing push URL, test run ID, or token") + } + return + } + p.cfg.Store(&c) + p.readyOnce.Do(func() { close(p.ready) }) +} + +// Levels reports all levels; the underlying loki hook re-filters by its own +// configured level. +func (p *Pusher) Levels() []logrus.Level { + return logrus.AllLevels +} + +// Fire buffers the entry without blocking. If the buffer is full the entry is +// dropped and counted, so the logging path is never blocked. +func (p *Pusher) Fire(entry *logrus.Entry) error { + select { + case p.buf <- entry: + default: + p.dropped.Add(1) + } + return nil +} + +// Drain flushes buffered logs to the backend and returns once the flush has +// completed (or ctx is done). It is safe to call when unconfigured (a no-op) +// and idempotent. Best-effort: entries still in flight inside the loki hook's +// channel at flush time may not be sent (see the package notes). +func (p *Pusher) Drain(ctx context.Context) error { + select { + case <-p.ready: + default: + return nil // never configured => nothing to flush + } + p.drainOnce.Do(func() { close(p.drainCh) }) + select { + case <-p.doneCh: + return nil + case <-ctx.Done(): + return ctx.Err() + } +} + +// Listen blocks until SetConfig has configured the Pusher or ctx is done. If +// ctx fires first (e.g. --no-cloud-logs or an early exit) it returns without +// pushing. Once configured it builds the loki hook and forwards buffered and +// subsequent entries to it. A Drain request or a ctx cancel both forward the +// buffered entries and trigger the loki hook's synchronous final flush; Listen +// returns only after that flush has completed. It always closes doneCh on +// return, so a concurrent Drain never blocks. +// +// The loki hook deliberately runs on its own background-derived context (not +// ctx) so its final flush is triggered only after buffered entries have been +// forwarded; hence the contextcheck exception. +func (p *Pusher) Listen(ctx context.Context) { //nolint:contextcheck + defer close(p.doneCh) + + select { + case <-p.ready: + case <-ctx.Done(): + return + } + + c := p.cfg.Load() + + // Level is intentionally omitted here: cloudlog filters by level itself in + // forward (below), so the hook's own Levels() dispatch is unused. Handing an + // invalid backend level to NewLokiHook would make it fail and disable the + // whole push, so we parse the level ourselves and fall back gracefully. + lokiHook, err := log.NewLokiHook(p.fallbackLogger, log.LokiHookOptions{ + Addr: c.PushURL, + Limit: c.Limit, + PushPeriod: c.PushPeriod, + MsgMaxSize: c.MsgMaxSize, + AllowedLabels: allowedLabelsWithTestRunID(c.AllowedLabels), + Labels: [][2]string{{testRunIDLabel, c.TestRunID}}, + Headers: [][2]string{{"Authorization", "Bearer " + c.Token}}, + }) + if err != nil { + if p.fallbackLogger != nil { + p.fallbackLogger.WithError(err).Error("cloud log push disabled: could not build the loki hook") + } + return + } + + // The loki hook's Fire enqueues unconditionally (its Levels() dispatch is + // bypassed on the forward path), so filter by the configured level here, + // where the level is known. logrus orders levels by severity (lower = + // more severe), so an entry passes iff it is at least as severe as the + // configured level: e.Level <= minLevel. An unset level keeps all. + minLevel := logrus.TraceLevel // "" => keep all levels (defer to the logger) + if c.Level != "" { + if lvl, err := logrus.ParseLevel(c.Level); err == nil { + minLevel = lvl + } else { + // The level comes from the backend, not the user, so a bad value + // falls back to info (the backend's own default) rather than + // pushing everything or disabling the push entirely. + minLevel = logrus.InfoLevel + if p.fallbackLogger != nil { + p.fallbackLogger.WithField("level", c.Level). + Warn("invalid cloud log level; defaulting to info") + } + } + } + + forward := func(e *logrus.Entry) { + if e.Level <= minLevel { + _ = lokiHook.Fire(e) + } + } + + // The loki hook runs on its own context so the final flush is triggered + // only after buffered entries have been forwarded (see finish), not + // concurrently with the forwarding. + lokiCtx, lokiCancel := context.WithCancel(context.Background()) + lokiDone := make(chan struct{}) + go func() { + lokiHook.Listen(lokiCtx) + close(lokiDone) + }() + + // finish forwards everything currently buffered, then cancels the loki + // hook so it runs its synchronous final flush, and waits for that to + // complete. lokiHook.Fire is a blocking send, so forwarding must happen + // while the loki hook is still draining its channel (before lokiCancel). + finish := func() { + for { + select { + case e := <-p.buf: + forward(e) + default: + lokiCancel() + <-lokiDone + return + } + } + } + + // Single consumer of buf, forwarding to the loki hook (the single producer + // stays Fire). A drain request or ctx cancel both run finish, then return; + // after a drain the later logger-shutdown ctx cancel is a no-op. + for { + select { + case e := <-p.buf: + forward(e) + case <-p.drainCh: + finish() + return + case <-ctx.Done(): + finish() + return + } + } +} + +// allowedLabelsWithTestRunID ensures the required test_run_id label survives +// the loki hook's label filtering, which drops any label not in the allow-list +// when that list is non-empty. An empty list must normalise to nil: the loki +// hook treats nil as "keep all labels", whereas a non-nil empty slice (which +// an explicitly empty K6_CLOUD_LOGS_ALLOWED_LABELS decodes to) means "keep +// none" and would strip test_run_id from the stream, getting the push 401'd. +func allowedLabelsWithTestRunID(allowed []string) []string { + if len(allowed) == 0 { + return nil + } + if slices.Contains(allowed, testRunIDLabel) { + return allowed + } + return append(slices.Clone(allowed), testRunIDLabel) +} diff --git a/internal/log/cloud/cloud_test.go b/internal/log/cloud/cloud_test.go new file mode 100644 index 000000000..85d72ce89 --- /dev/null +++ b/internal/log/cloud/cloud_test.go @@ -0,0 +1,519 @@ +package cloudlog + +import ( + "context" + "io" + "net/http" + "net/http/httptest" + "strings" + "sync" + "testing" + "time" + + "github.com/sirupsen/logrus" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "go.k6.io/k6/v2/internal/lib/testutils" +) + +// TestPusher is the canonical case: entries fired before and after SetConfig +// are buffered and then pushed to the configured endpoint, carrying the +// bearer token and the required test_run_id label. +func TestPusher(t *testing.T) { + t.Parallel() + + type received struct { + body string + auth string + } + recvCh := make(chan received, 1) + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { + b, _ := io.ReadAll(req.Body) + select { + case recvCh <- received{body: string(b), auth: req.Header.Get("Authorization")}: + default: + } + w.WriteHeader(http.StatusNoContent) + })) + defer srv.Close() + + p := New(testutils.NewLogger(t)) + + // Fired BEFORE SetConfig: must be buffered until the pusher is configured. + require.NoError(t, p.Fire(&logrus.Entry{Time: time.Now(), Level: logrus.InfoLevel, Message: "before-config"})) + + p.SetConfig(Config{ + PushURL: srv.URL, + Token: "test-token", + TestRunID: "run-123", + PushPeriod: 20 * time.Millisecond, + }) + + // Fired AFTER SetConfig: still buffered until Listen drains. + require.NoError(t, p.Fire(&logrus.Entry{Time: time.Now(), Level: logrus.InfoLevel, Message: "after-config"})) + + ctx, cancel := context.WithCancel(context.Background()) + listenDone := make(chan struct{}) + go func() { + p.Listen(ctx) + close(listenDone) + }() + + var got received + select { + case got = <-recvCh: + case <-time.After(2 * time.Second): + t.Fatal("no push received from the pusher") + } + + assert.Equal(t, "Bearer test-token", got.auth) + assert.Contains(t, got.body, "before-config") + assert.Contains(t, got.body, "after-config") + assert.Contains(t, got.body, `"test_run_id":"run-123"`) + + cancel() + select { + case <-listenDone: + case <-time.After(2 * time.Second): + t.Fatal("Listen did not return after ctx was cancelled") + } +} + +// TestPusher_UnconfiguredDrainsOnCtxDone covers the --no-cloud-logs / early +// exit path: without SetConfig, Listen returns promptly on ctx.Done and never +// pushes. +func TestPusher_UnconfiguredDrainsOnCtxDone(t *testing.T) { + t.Parallel() + + srv := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { + t.Errorf("pusher made an HTTP request while unconfigured") + })) + defer srv.Close() + + p := New(testutils.NewLogger(t)) + require.NoError(t, p.Fire(&logrus.Entry{Time: time.Now(), Level: logrus.InfoLevel, Message: "buffered"})) + + ctx, cancel := context.WithCancel(context.Background()) + listenDone := make(chan struct{}) + go func() { + p.Listen(ctx) + close(listenDone) + }() + + cancel() + select { + case <-listenDone: + case <-time.After(2 * time.Second): + t.Fatal("Listen did not return promptly on ctx.Done while unconfigured") + } +} + +// TestPusher_FireNeverBlocks keeps the logging path non-blocking: with no +// Listen draining, Fire returns immediately even past the buffer capacity and +// over-cap entries are counted as dropped. +func TestPusher_FireNeverBlocks(t *testing.T) { + t.Parallel() + + p := New(testutils.NewLogger(t)) + + const overflow = 10 + total := bufferCap + overflow + + fired := make(chan struct{}) + go func() { + for range total { + _ = p.Fire(&logrus.Entry{Time: time.Now(), Level: logrus.InfoLevel, Message: "x"}) + } + close(fired) + }() + + select { + case <-fired: + case <-time.After(2 * time.Second): + t.Fatal("Fire blocked when the buffer was full") + } + + assert.Equal(t, int64(overflow), p.dropped.Load()) +} + +// TestPusher_TestRunIDLabelKept locks the backend's hard requirement: even +// when AllowedLabels omits test_run_id, the pushed stream still carries it as +// a label (the backend 401s a push whose stream lacks it). +func TestPusher_TestRunIDLabelKept(t *testing.T) { + t.Parallel() + + recvCh := make(chan string, 1) + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { + b, _ := io.ReadAll(req.Body) + select { + case recvCh <- string(b): + default: + } + w.WriteHeader(http.StatusNoContent) + })) + defer srv.Close() + + p := New(testutils.NewLogger(t)) + p.SetConfig(Config{ + PushURL: srv.URL, + Token: "tok", + TestRunID: "run-xyz", + PushPeriod: 20 * time.Millisecond, + AllowedLabels: []string{"level"}, // deliberately omits test_run_id + }) + require.NoError(t, p.Fire(&logrus.Entry{Time: time.Now(), Level: logrus.InfoLevel, Message: "hello"})) + + ctx, cancel := context.WithCancel(context.Background()) + listenDone := make(chan struct{}) + go func() { + p.Listen(ctx) + close(listenDone) + }() + + select { + case body := <-recvCh: + assert.Contains(t, body, `"test_run_id":"run-xyz"`) + case <-time.After(2 * time.Second): + t.Fatal("no push received from the pusher") + } + + cancel() + <-listenDone +} + +// TestPusher_EmptyAllowedLabelsKeepsTestRunID guards the empty-slice edge: an +// explicitly empty K6_CLOUD_LOGS_ALLOWED_LABELS decodes to a non-nil []string{}, +// which must still keep the required test_run_id label rather than strip every +// label from the stream. +func TestPusher_EmptyAllowedLabelsKeepsTestRunID(t *testing.T) { + t.Parallel() + + recvCh := make(chan string, 1) + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { + b, _ := io.ReadAll(req.Body) + select { + case recvCh <- string(b): + default: + } + w.WriteHeader(http.StatusNoContent) + })) + defer srv.Close() + + p := New(testutils.NewLogger(t)) + p.SetConfig(Config{ + PushURL: srv.URL, + Token: "tok", + TestRunID: "run-empty-labels", + PushPeriod: 20 * time.Millisecond, + AllowedLabels: []string{}, // non-nil empty, as envconfig decodes "" + }) + require.NoError(t, p.Fire(&logrus.Entry{Time: time.Now(), Level: logrus.InfoLevel, Message: "hello"})) + + ctx, cancel := context.WithCancel(context.Background()) + listenDone := make(chan struct{}) + go func() { + p.Listen(ctx) + close(listenDone) + }() + + select { + case body := <-recvCh: + assert.Contains(t, body, `"test_run_id":"run-empty-labels"`) + case <-time.After(2 * time.Second): + t.Fatal("no push received from the pusher") + } + + cancel() + <-listenDone +} + +// TestPusher_Drain covers the pre-notify drain: after entries are pushed while +// the run is open, Drain returns without hanging, drives Listen to return even +// though ctx was never cancelled, and is idempotent on a second call. +func TestPusher_Drain(t *testing.T) { + t.Parallel() + + type received struct { + body string + auth string + } + recvCh := make(chan received, 8) + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { + b, _ := io.ReadAll(req.Body) + select { + case recvCh <- received{body: string(b), auth: req.Header.Get("Authorization")}: + default: + } + w.WriteHeader(http.StatusNoContent) + })) + defer srv.Close() + + p := New(testutils.NewLogger(t)) + p.SetConfig(Config{ + PushURL: srv.URL, + Token: "drain-token", + TestRunID: "run-drain", + PushPeriod: 20 * time.Millisecond, + }) + + for _, msg := range []string{"entry-a", "entry-b", "entry-c"} { + require.NoError(t, p.Fire(&logrus.Entry{Time: time.Now(), Level: logrus.InfoLevel, Message: msg})) + } + + // ctx stays alive for the whole test: shutdown must be driven by Drain, + // not by a ctx cancel. + ctx := t.Context() + listenDone := make(chan struct{}) + go func() { + p.Listen(ctx) + close(listenDone) + }() + + // Entries reach the backend via the periodic push while the run is open, + // carrying the bearer token and the required test_run_id label. + var got received + select { + case got = <-recvCh: + case <-time.After(2 * time.Second): + t.Fatal("no push received from the pusher") + } + assert.Equal(t, "Bearer drain-token", got.auth) + assert.Contains(t, got.body, `"test_run_id":"run-drain"`) + + // Drain returns once the flush has completed; it must not hang. + require.NoError(t, p.Drain(context.Background())) + + // Drain drove Listen to return, even though ctx was never cancelled. + select { + case <-listenDone: + case <-time.After(2 * time.Second): + t.Fatal("Listen did not return after Drain") + } + + // Idempotent: a second Drain returns nil immediately. + require.NoError(t, p.Drain(context.Background())) +} + +// TestPusher_DrainUnconfigured covers the --out cloud / --no-cloud-logs case: +// without SetConfig, Drain is a no-op that returns nil immediately and makes +// no HTTP request. +func TestPusher_DrainUnconfigured(t *testing.T) { + t.Parallel() + + p := New(testutils.NewLogger(t)) + require.NoError(t, p.Fire(&logrus.Entry{Time: time.Now(), Level: logrus.InfoLevel, Message: "buffered"})) + + require.NoError(t, p.Drain(context.Background())) +} + +// TestPusher_DrainContextTimeout locks Drain's ctx contract: when the flush +// cannot complete (here Listen is never started, so doneCh never closes), a +// done ctx unblocks Drain with the ctx error rather than blocking forever. +func TestPusher_DrainContextTimeout(t *testing.T) { + t.Parallel() + + p := New(testutils.NewLogger(t)) + p.SetConfig(Config{ + PushURL: "http://127.0.0.1:0", + Token: "tok", + TestRunID: "run", + }) + + ctx, cancel := context.WithCancel(context.Background()) + cancel() + + require.ErrorIs(t, p.Drain(ctx), context.Canceled) +} + +// TestPusher_FiltersBelowConfiguredLevel locks the backend-level directive: +// with Level "info" the pusher pushes info/warn/error entries but filters out +// the less-severe debug entry, even though the loki hook's Fire enqueues +// unconditionally. Entries reach the backend via the periodic push. +func TestPusher_FiltersBelowConfiguredLevel(t *testing.T) { + t.Parallel() + + var ( + mu sync.Mutex + body strings.Builder + ) + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { + b, _ := io.ReadAll(req.Body) + mu.Lock() + body.Write(b) + mu.Unlock() + w.WriteHeader(http.StatusNoContent) + })) + defer srv.Close() + + p := New(testutils.NewLogger(t)) + p.SetConfig(Config{ + PushURL: srv.URL, + Token: "tok", + TestRunID: "run-lvl", + Level: "info", + PushPeriod: 20 * time.Millisecond, + }) + + // Fired debug-first, so by the time the others are pushed the debug entry + // has already been through the forward path (and been filtered). + for _, e := range []*logrus.Entry{ + {Time: time.Now(), Level: logrus.DebugLevel, Message: "msg-debug"}, + {Time: time.Now(), Level: logrus.InfoLevel, Message: "msg-info"}, + {Time: time.Now(), Level: logrus.WarnLevel, Message: "msg-warn"}, + {Time: time.Now(), Level: logrus.ErrorLevel, Message: "msg-error"}, + } { + require.NoError(t, p.Fire(e)) + } + + ctx, cancel := context.WithCancel(context.Background()) + listenDone := make(chan struct{}) + go func() { + p.Listen(ctx) + close(listenDone) + }() + + got := func() string { + mu.Lock() + defer mu.Unlock() + return body.String() + } + + // The info/warn/error entries (at or above the configured level) are pushed. + require.Eventually(t, func() bool { + b := got() + return strings.Contains(b, "msg-info") && + strings.Contains(b, "msg-warn") && + strings.Contains(b, "msg-error") + }, 2*time.Second, 10*time.Millisecond, "info/warn/error entries were not pushed") + + // The debug entry is below the configured level, so it is never pushed. + assert.NotContains(t, got(), "msg-debug") + + cancel() + select { + case <-listenDone: + case <-time.After(2 * time.Second): + t.Fatal("Listen did not return after ctx was cancelled") + } +} + +// TestPusher_EmptyLevelKeepsAll is the variant: an unset Level keeps all +// levels, so even a debug entry is pushed. +func TestPusher_EmptyLevelKeepsAll(t *testing.T) { + t.Parallel() + + var ( + mu sync.Mutex + body strings.Builder + ) + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { + b, _ := io.ReadAll(req.Body) + mu.Lock() + body.Write(b) + mu.Unlock() + w.WriteHeader(http.StatusNoContent) + })) + defer srv.Close() + + p := New(testutils.NewLogger(t)) + p.SetConfig(Config{ + PushURL: srv.URL, + Token: "tok", + TestRunID: "run-empty", + Level: "", // unset => keep all levels + PushPeriod: 20 * time.Millisecond, + }) + + require.NoError(t, p.Fire(&logrus.Entry{Time: time.Now(), Level: logrus.DebugLevel, Message: "msg-debug"})) + + ctx, cancel := context.WithCancel(context.Background()) + listenDone := make(chan struct{}) + go func() { + p.Listen(ctx) + close(listenDone) + }() + + require.Eventually(t, func() bool { + mu.Lock() + defer mu.Unlock() + return strings.Contains(body.String(), "msg-debug") + }, 2*time.Second, 10*time.Millisecond, "debug entry was not pushed with empty level") + + cancel() + select { + case <-listenDone: + case <-time.After(2 * time.Second): + t.Fatal("Listen did not return after ctx was cancelled") + } +} + +// TestPusher_InvalidLevelDefaultsToInfo verifies that an unparseable Level +// (which can only come from the backend) neither disables the push nor keeps +// all levels: it falls back to info, so debug is dropped while info and above +// are still pushed. +func TestPusher_InvalidLevelDefaultsToInfo(t *testing.T) { + t.Parallel() + + var ( + mu sync.Mutex + body strings.Builder + ) + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { + b, _ := io.ReadAll(req.Body) + mu.Lock() + body.Write(b) + mu.Unlock() + w.WriteHeader(http.StatusNoContent) + })) + defer srv.Close() + + p := New(testutils.NewLogger(t)) + p.SetConfig(Config{ + PushURL: srv.URL, + Token: "tok", + TestRunID: "run-badlvl", + Level: "bogus", // invalid => fall back to info + PushPeriod: 20 * time.Millisecond, + }) + + // Debug fired first, so if it were going to be pushed it would land no + // later than the info/error entries. + for _, e := range []*logrus.Entry{ + {Time: time.Now(), Level: logrus.DebugLevel, Message: "msg-debug"}, + {Time: time.Now(), Level: logrus.InfoLevel, Message: "msg-info"}, + {Time: time.Now(), Level: logrus.ErrorLevel, Message: "msg-error"}, + } { + require.NoError(t, p.Fire(e)) + } + + ctx, cancel := context.WithCancel(context.Background()) + listenDone := make(chan struct{}) + go func() { + p.Listen(ctx) + close(listenDone) + }() + + got := func() string { + mu.Lock() + defer mu.Unlock() + return body.String() + } + + // info/error (at or above the info fallback) are pushed despite the + // invalid level, proving the push is not disabled. + require.Eventually(t, func() bool { + b := got() + return strings.Contains(b, "msg-info") && strings.Contains(b, "msg-error") + }, 2*time.Second, 10*time.Millisecond, "info/error not pushed with an invalid level") + + // debug (below info) is dropped, proving the fallback is info, not all. + assert.NotContains(t, got(), "msg-debug") + + cancel() + select { + case <-listenDone: + case <-time.After(2 * time.Second): + t.Fatal("Listen did not return after ctx was cancelled") + } +} diff --git a/internal/log/loki.go b/internal/log/loki.go index aa25f034a..261f6935b 100644 --- a/internal/log/loki.go +++ b/internal/log/loki.go @@ -47,24 +47,66 @@ func getDefaultLoki() *lokiHook { } } -// LokiFromConfigLine returns a new logrus.Hook -// that pushes logrus.Entrys to loki and is configured -// through the provided line. -func LokiFromConfigLine(fallbackLogger logrus.FieldLogger, line string) (AsyncHook, error) { +// LokiHookOptions configures a loki push hook built by NewLokiHook. +// Zero-valued fields take the built-in defaults. +type LokiHookOptions struct { + Addr string // default http://127.0.0.1:3100/loki/api/v1/push + PushPeriod time.Duration // default 1s + Limit int // default 100 + MsgMaxSize int // default 1MB + Level string // "" => all levels; else parseLevels + AllowedLabels []string + Labels [][2]string // static labels (e.g. test_run_id) + Headers [][2]string // e.g. Authorization: Bearer + Profile bool +} + +// NewLokiHook returns a new AsyncHook that pushes logrus.Entrys to loki, +// configured from opts. Zero-valued opts fields take the built-in defaults. +func NewLokiHook(fallbackLogger logrus.FieldLogger, opts LokiHookOptions) (AsyncHook, error) { h := getDefaultLoki() h.fallbackLogger = fallbackLogger - if line != "loki" { - logOutput, _, _ := strings.Cut(line, "=") - if logOutput != "loki" { - return nil, fmt.Errorf("loki configuration should be in the form `loki=url-to-push` but is `%s`", line) - } - - err := h.parseArgs(line) + if opts.Addr != "" { + h.addr = opts.Addr + } + // Limit, PushPeriod and MsgMaxSize fall back to their defaults on a + // non-positive value. Negatives can only arrive programmatically + // (K6_CLOUD_LOGS_* / a backend logs config bypass the config-line + // validation) and would otherwise panic in Listen — make([]tmpMsg, limit) + // and time.NewTicker(pushPeriod) — or on push (msgMaxSize slicing); warn so + // a bad value is visible. + if opts.PushPeriod > 0 { + h.pushPeriod = opts.PushPeriod + } else if opts.PushPeriod < 0 && fallbackLogger != nil { + fallbackLogger.WithField("pushPeriod", opts.PushPeriod). + Warn("negative loki push period; using default") + } + if opts.Limit > 0 { + h.limit = opts.Limit + } else if opts.Limit < 0 && fallbackLogger != nil { + fallbackLogger.WithField("limit", opts.Limit). + Warn("negative loki limit; using default") + } + if opts.MsgMaxSize > 0 { + h.msgMaxSize = opts.MsgMaxSize + } else if opts.MsgMaxSize < 0 && fallbackLogger != nil { + fallbackLogger.WithField("msgMaxSize", opts.MsgMaxSize). + Warn("negative loki message size; using default") + } + if opts.Level != "" { + levels, err := parseLevels(opts.Level) if err != nil { return nil, err } + h.levels = levels + } + if opts.AllowedLabels != nil { + h.allowedLabels = opts.AllowedLabels } + h.labels = append(h.labels, opts.Labels...) + h.headers = append(h.headers, opts.Headers...) + h.profile = opts.Profile h.droppedLabels = make(map[string]string, 2+len(h.labels)) h.droppedLabels["level"] = logrus.WarnLevel.String() @@ -74,10 +116,31 @@ func LokiFromConfigLine(fallbackLogger logrus.FieldLogger, line string) (AsyncHo h.droppedMsg = h.filterLabels(h.droppedLabels, h.droppedMsg) h.client = &http.Client{Timeout: h.pushPeriod} + return h, nil } -func (h *lokiHook) parseArgs(line string) error { +// LokiFromConfigLine returns a new logrus.Hook +// that pushes logrus.Entrys to loki and is configured +// through the provided line. +func LokiFromConfigLine(fallbackLogger logrus.FieldLogger, line string) (AsyncHook, error) { + var opts LokiHookOptions + + if line != "loki" { + logOutput, _, _ := strings.Cut(line, "=") + if logOutput != "loki" { + return nil, fmt.Errorf("loki configuration should be in the form `loki=url-to-push` but is `%s`", line) + } + + if err := opts.parseArgs(line); err != nil { + return nil, err + } + } + + return NewLokiHook(fallbackLogger, opts) +} + +func (opts *LokiHookOptions) parseArgs(line string) error { tokens, err := strvals.Parse(line) if err != nil { return fmt.Errorf("error while parsing loki configuration %w", err) @@ -90,46 +153,41 @@ func (h *lokiHook) parseArgs(line string) error { var err error switch key { case "loki": - h.addr = value + opts.Addr = value case "pushPeriod": - h.pushPeriod, err = time.ParseDuration(value) + opts.PushPeriod, err = time.ParseDuration(value) if err != nil { return fmt.Errorf("couldn't parse the loki pushPeriod %w", err) } case "profile": - h.profile = true + opts.Profile = true case "limit": - h.limit, err = strconv.Atoi(value) + opts.Limit, err = strconv.Atoi(value) if err != nil { return fmt.Errorf("couldn't parse the loki limit as a number %w", err) } - if h.limit < 1 { - return fmt.Errorf("loki limit needs to be a positive number, is %d", h.limit) + if opts.Limit < 1 { + return fmt.Errorf("loki limit needs to be a positive number, is %d", opts.Limit) } case "msgMaxSize": - h.msgMaxSize, err = strconv.Atoi(value) + opts.MsgMaxSize, err = strconv.Atoi(value) if err != nil { return fmt.Errorf("couldn't parse the loki msgMaxSize as a number %w", err) } - if h.msgMaxSize < 1 { - return fmt.Errorf("loki msgMaxSize needs to be a positive number, is %d", h.msgMaxSize) + if opts.MsgMaxSize < 1 { + return fmt.Errorf("loki msgMaxSize needs to be a positive number, is %d", opts.MsgMaxSize) } case "level": - h.levels, err = parseLevels(value) - if err != nil { - return err - } + opts.Level = value case "allowedLabels": - h.allowedLabels = strings.Split(value, ",") + opts.AllowedLabels = strings.Split(value, ",") default: if after, ok := strings.CutPrefix(key, "label."); ok { - labelKey := after - h.labels = append(h.labels, [2]string{labelKey, value}) + opts.Labels = append(opts.Labels, [2]string{after, value}) continue } else if after, ok := strings.CutPrefix(key, "header."); ok { - headerKey := after - h.headers = append(h.headers, [2]string{headerKey, value}) + opts.Headers = append(opts.Headers, [2]string{after, value}) continue } diff --git a/internal/log/loki_test.go b/internal/log/loki_test.go index 3762e5975..5889e1d96 100644 --- a/internal/log/loki_test.go +++ b/internal/log/loki_test.go @@ -14,6 +14,8 @@ import ( "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "go.k6.io/k6/v2/internal/lib/testutils" ) func TestSyslogFromConfigLine(t *testing.T) { @@ -93,6 +95,74 @@ func TestSyslogFromConfigLine(t *testing.T) { } } +func TestNewLokiHook(t *testing.T) { + t.Parallel() + + opts := LokiHookOptions{ + Addr: "somewhere:1233", + PushPeriod: time.Minute*5 + time.Second*32, + Limit: 32, + MsgMaxSize: 1231, + Level: "info", + AllowedLabels: []string{"something"}, + Labels: [][2]string{{"something", "else"}, {"foo", "bar"}}, + Headers: [][2]string{{"x-test", "123"}, {"authorization", "token foobar"}}, + Profile: true, + } + + res, err := NewLokiHook(nil, opts) + require.NoError(t, err) + hook, ok := res.(*lokiHook) + require.True(t, ok) + + assert.Equal(t, "somewhere:1233", hook.addr) + assert.Equal(t, time.Minute*5+time.Second*32, hook.pushPeriod) + assert.Equal(t, 32, hook.limit) + assert.Equal(t, 1231, hook.msgMaxSize) + assert.Equal(t, logrus.AllLevels[:5], hook.levels) + assert.Equal(t, []string{"something"}, hook.allowedLabels) + assert.Equal(t, [][2]string{{"something", "else"}, {"foo", "bar"}}, hook.labels) + assert.Equal(t, [][2]string{{"x-test", "123"}, {"authorization", "token foobar"}}, hook.headers) + assert.True(t, hook.profile) + + // The tail-end setup (droppedLabels/droppedMsg/client) must have run: + // non-allowed labels are folded into droppedMsg and dropped from droppedLabels. + assert.Equal(t, map[string]string{"something": "else"}, hook.droppedLabels) + assert.Equal(t, + "k6 dropped %d log messages because they were above the limit of %d messages / %s foo=bar level=warning", + hook.droppedMsg) + require.NotNil(t, hook.client) + assert.Equal(t, time.Minute*5+time.Second*32, hook.client.Timeout) +} + +func TestNewLokiHook_Defaults(t *testing.T) { + t.Parallel() + + res, err := NewLokiHook(nil, LokiHookOptions{}) + require.NoError(t, err) + hook, ok := res.(*lokiHook) + require.True(t, ok) + + assert.Equal(t, "http://127.0.0.1:3100/loki/api/v1/push", hook.addr) + assert.Equal(t, time.Second*1, hook.pushPeriod) + assert.Equal(t, 100, hook.limit) + assert.Equal(t, 1024*1024, hook.msgMaxSize) + assert.Equal(t, logrus.AllLevels, hook.levels) + assert.Nil(t, hook.allowedLabels) + assert.Nil(t, hook.labels) + assert.Nil(t, hook.headers) + assert.False(t, hook.profile) + + // The tail-end setup runs even with defaults: only the level label is seeded, + // and with no allowedLabels the droppedMsg is left untouched. + assert.Equal(t, map[string]string{"level": "warning"}, hook.droppedLabels) + assert.Equal(t, + "k6 dropped %d log messages because they were above the limit of %d messages / %s", + hook.droppedMsg) + require.NotNil(t, hook.client) + assert.Equal(t, time.Second*1, hook.client.Timeout) +} + func TestLogEntryMarshal(t *testing.T) { t.Parallel() entry := logEntry{ @@ -220,3 +290,86 @@ func TestLokiHeaders(t *testing.T) { t.Fatal("No logs were received from loki before hook has finished") } } + +// TestNewLokiHookClampsNonPositiveOptions verifies that non-positive Limit, +// PushPeriod and MsgMaxSize fall back to the built-in defaults (with a warning) +// instead of panicking. These values can only arrive programmatically — e.g. +// via K6_CLOUD_LOGS_* or a backend logs config — which bypass the config-line +// validation that otherwise rejects them. +func TestNewLokiHookClampsNonPositiveOptions(t *testing.T) { + t.Parallel() + + logger, hook := testutils.NewLoggerWithHook(t, logrus.WarnLevel) + + receivedData := make(chan string, 1) + srv := httptest.NewServer( + http.HandlerFunc(func(_ http.ResponseWriter, req *http.Request) { + b, err := io.ReadAll(req.Body) + if err != nil { + t.Error(err) + return + } + select { + case receivedData <- string(b): + default: + } + }), + ) + defer srv.Close() + + // Without the clamp these panic in Listen — make([]tmpMsg, limit) and + // time.NewTicker(pushPeriod) — and on push (msgMaxSize slicing). + h, err := NewLokiHook(logger, LokiHookOptions{ + Addr: srv.URL, + Limit: -5, + PushPeriod: -1 * time.Second, + MsgMaxSize: -10, + }) + require.NoError(t, err) + + // Each bad value is warned about (and falls back to its default). + entries := hook.Drain() + assert.True(t, testutils.LogContains(entries, logrus.WarnLevel, "limit"), + "expected a warning about the negative limit") + assert.True(t, testutils.LogContains(entries, logrus.WarnLevel, "push period"), + "expected a warning about the negative push period") + assert.True(t, testutils.LogContains(entries, logrus.WarnLevel, "message size"), + "expected a warning about the negative message size") + + // Listen must not panic, and the entry is pushed using the defaults. + ctx, cancel := context.WithCancel(context.Background()) + wg := new(sync.WaitGroup) + now := time.Now() + wg.Go(func() { + require.NoError(t, h.Fire(&logrus.Entry{Time: now, Level: logrus.InfoLevel, Message: "clamp message"})) + time.Sleep(10 * time.Millisecond) + cancel() + }) + h.Listen(ctx) + wg.Wait() + + select { + case data := <-receivedData: + require.Contains(t, data, "clamp message") + default: + t.Fatal("no logs received; hook did not push with clamped defaults") + } +} + +// TestLokiFromConfigLineEmptyAddr documents that `--log-output=loki=` (an empty +// URL) is rejected up front by the config parser rather than silently falling +// back to the default endpoint — so there is no empty-address case reaching the +// constructor. Bare `loki` still uses the default. This is unchanged from +// before the NewLokiHook extraction, since parseArgs still runs strvals.Parse +// first. +func TestLokiFromConfigLineEmptyAddr(t *testing.T) { + t.Parallel() + + _, err := LokiFromConfigLine(nil, "loki=") + require.Error(t, err, "an empty loki address must be rejected, not defaulted") + assert.Contains(t, err.Error(), "no value") + + bare, err := LokiFromConfigLine(nil, "loki") + require.NoError(t, err) + assert.NotEmpty(t, bare.(*lokiHook).addr, "bare loki uses the default endpoint") +} diff --git a/internal/output/cloud/output.go b/internal/output/cloud/output.go index 4023f7f45..ba43541c4 100644 --- a/internal/output/cloud/output.go +++ b/internal/output/cloud/output.go @@ -69,6 +69,14 @@ type provisioningNotifier interface { NotifyTestRunCompleted(ctx context.Context, testRunID int64, token string, testErr error) error } +// logDrainer flushes buffered cloud logs so they reach the backend before the +// run is notified complete (afterwards the backend rejects late pushes). Kept +// structural (no import of internal/log/cloud) to avoid coupling the output to +// that package. Production implementation: *cloudlog.Pusher. +type logDrainer interface { + Drain(context.Context) error +} + type apiVersion int64 const ( @@ -111,6 +119,10 @@ type Output struct { // startVersionedOutput and testFinished. provisioningMode bool + // logDrainer, when set, is flushed before notify so in-run logs land while + // the run is still open. nil for --out cloud / --no-cloud-logs. + logDrainer logDrainer + usage *usage.Usage } @@ -315,6 +327,11 @@ func (out *Output) SetArchive(archive *lib.Archive) { out.testArchive = archive } +// SetLogDrainer sets the cloud-log drainer flushed before end-of-test notify. +func (out *Output) SetLogDrainer(d logDrainer) { + out.logDrainer = d +} + var _ output.WithArchive = &Output{} // Stop gracefully stops all metric emission from the output: when all metric @@ -335,6 +352,17 @@ func (out *Output) StopWithTestError(testErr error) error { // to notify the cloud backend we have no return here } + // Flush buffered cloud logs before notify: once the run is notified + // complete the backend rejects late log pushes, so the final batch would + // be lost. The push is already bounded by the loki hook's own HTTP client + // timeout, so the drain just waits for it on a fresh context — fresh + // because the run's context is already cancelled at shutdown. + if out.logDrainer != nil { + if err := out.logDrainer.Drain(context.Background()); err != nil { + out.logger.WithError(err).Warn("could not drain cloud logs before notify") + } + } + out.logger.Debug("Metric emission stopped, calling cloud API...") err = out.testFinished(testErr) if err != nil { diff --git a/internal/output/cloud/output_test.go b/internal/output/cloud/output_test.go index a9c8e399f..2af0a85b9 100644 --- a/internal/output/cloud/output_test.go +++ b/internal/output/cloud/output_test.go @@ -430,6 +430,25 @@ func (m *provisioningNotifierMock) NotifyTestRunCompleted(_ context.Context, tes return nil } +// logDrainerMock implements the output's logDrainer for tests. onDrain, when +// set, runs inside Drain so a test can observe ordering relative to notify. +// ctxErr records ctx.Err() at call time so a test can assert the drain wasn't +// handed an already-expired context. +type logDrainerMock struct { + called atomic.Bool + ctxErr error + onDrain func() +} + +func (m *logDrainerMock) Drain(ctx context.Context) error { + m.called.Store(true) + m.ctxErr = ctx.Err() + if m.onDrain != nil { + m.onDrain() + } + return nil +} + func TestOutputStart_ProvisioningMode(t *testing.T) { t.Parallel() @@ -770,3 +789,142 @@ func TestOutputStopWithTestError_PushRefID_NoNotifyNoTestFinished(t *testing.T) assert.False(t, clientMock.testFinishedCalled) }) } + +// TestOutputStopWithTestError_DrainsLogsBeforeNotify locks the ordering fix: +// the cloud log drainer is flushed before the run is notified complete, so +// in-run logs land while the run is still open (afterwards the backend +// rejects late pushes). +func TestOutputStopWithTestError_DrainsLogsBeforeNotify(t *testing.T) { + t.Parallel() + synctest.Test(t, func(t *testing.T) { + notifierMock := &provisioningNotifierMock{} + clientMock := &cloudClientMock{} + drainerMock := &logDrainerMock{ + onDrain: func() { + // Drain must run before notify: the notifier has not been + // called yet at drain time. + assert.Equal(t, int32(0), notifierMock.callCount.Load(), + "Drain must be called before NotifyTestRunCompleted") + }, + } + + out := &Output{ + logger: testutils.NewLogger(t), + testRunID: "12345", + config: cloudapi.Config{ + MetricsPushURL: null.StringFrom("https://metrics.example.com/v2/metrics/123"), + TestRunToken: null.StringFrom("scoped-test-run-token"), + Timeout: types.NullDurationFrom(60 * time.Second), + }, + client: clientMock, + provisioningNotifier: notifierMock, + provisioningMode: true, + logDrainer: drainerMock, + } + out.versionedOutput = versionedOutputMock{callback: func(string) {}} + + require.NoError(t, out.StopWithTestError(nil)) + + assert.True(t, drainerMock.called.Load(), "Drain must be called") + assert.True(t, notifierMock.called.Load(), "notify must still happen after drain") + }) +} + +// TestOutputStopWithTestError_PushRefID_DrainsLogs guards that the cloud log +// drain runs even on the externally-provisioned (PushRefID) path, where notify +// is skipped. If a future change tied the drain to notify, this flow would +// silently lose its final log batch and no other test would catch it. +func TestOutputStopWithTestError_PushRefID_DrainsLogs(t *testing.T) { + t.Parallel() + synctest.Test(t, func(t *testing.T) { + notifierMock := &provisioningNotifierMock{} + clientMock := &cloudClientMock{} + drainerMock := &logDrainerMock{} + + out := &Output{ + logger: testutils.NewLogger(t), + testRunID: "12345", + config: cloudapi.Config{ + PushRefID: null.StringFrom("99999"), + MetricsPushURL: null.StringFrom("https://metrics.example.com/v2/metrics/123"), + TestRunToken: null.StringFrom("scoped-test-run-token"), + Timeout: types.NullDurationFrom(60 * time.Second), + }, + client: clientMock, + provisioningNotifier: notifierMock, + provisioningMode: true, + logDrainer: drainerMock, + } + out.versionedOutput = versionedOutputMock{callback: func(string) {}} + + require.NoError(t, out.StopWithTestError(nil)) + + // Drain runs even though the PushRefID path skips notify/TestFinished. + assert.True(t, drainerMock.called.Load(), "Drain must run on the PushRefID path too") + assert.False(t, notifierMock.called.Load(), "PushRefID path must not notify") + assert.False(t, clientMock.testFinishedCalled, "PushRefID path must not call TestFinished") + }) +} + +// TestOutputStopWithTestError_ZeroTimeoutDrainsWithoutDeadline guards that +// K6_CLOUD_TIMEOUT=0 ("no timeout", as the other cloud clients treat it) does +// not hand the drain an already-expired context, which would skip the flush +// and let notify race it. +func TestOutputStopWithTestError_ZeroTimeoutDrainsWithoutDeadline(t *testing.T) { + t.Parallel() + synctest.Test(t, func(t *testing.T) { + notifierMock := &provisioningNotifierMock{} + clientMock := &cloudClientMock{} + drainerMock := &logDrainerMock{} + + out := &Output{ + logger: testutils.NewLogger(t), + testRunID: "12345", + config: cloudapi.Config{ + MetricsPushURL: null.StringFrom("https://metrics.example.com/v2/metrics/123"), + TestRunToken: null.StringFrom("scoped-test-run-token"), + Timeout: types.NewNullDuration(0, true), // K6_CLOUD_TIMEOUT=0 + }, + client: clientMock, + provisioningNotifier: notifierMock, + provisioningMode: true, + logDrainer: drainerMock, + } + out.versionedOutput = versionedOutputMock{callback: func(string) {}} + + require.NoError(t, out.StopWithTestError(nil)) + + assert.True(t, drainerMock.called.Load(), "Drain must be called") + assert.NoError(t, drainerMock.ctxErr, + "drain context must not be already expired when the timeout is 0 (no timeout)") + }) +} + +// TestOutputStopWithTestError_NilLogDrainerStillNotifies covers the +// --out cloud / --no-cloud-logs case: with no drainer set, Stop neither +// panics nor skips notify. +func TestOutputStopWithTestError_NilLogDrainerStillNotifies(t *testing.T) { + t.Parallel() + synctest.Test(t, func(t *testing.T) { + notifierMock := &provisioningNotifierMock{} + clientMock := &cloudClientMock{} + + out := &Output{ + logger: testutils.NewLogger(t), + testRunID: "12345", + config: cloudapi.Config{ + MetricsPushURL: null.StringFrom("https://metrics.example.com/v2/metrics/123"), + TestRunToken: null.StringFrom("scoped-test-run-token"), + Timeout: types.NullDurationFrom(60 * time.Second), + }, + client: clientMock, + provisioningNotifier: notifierMock, + provisioningMode: true, + logDrainer: nil, + } + out.versionedOutput = versionedOutputMock{callback: func(string) {}} + + require.NoError(t, out.StopWithTestError(nil)) + assert.True(t, notifierMock.called.Load()) + }) +} From 36961eef9d80d6956e8623e7754faf4db783f64b Mon Sep 17 00:00:00 2001 From: Ankur Date: Sat, 1 Aug 2026 07:13:34 +0100 Subject: [PATCH 097/182] Fix loki shutdown log loss and surface dropped cloud logs (#6232) * Refactor loki entry buffering into a helper Extract the per-entry buffering in lokiHook.Listen (the limit check, label building and appending to msgs) into a local appendEntry closure, so the shutdown path can reuse the same logic. Pure refactor with no behavior change: the existing loki tests still pass unchanged. * Fix log loss on loki hook shutdown lokiHook.Listen's shutdown branch pushed only the entries already consumed into its buffer, never draining what was still queued in the channel, so a ctx-cancel could lose a tail of logs. This is shared with --out loki and was made observable by the cloud log pusher's Drain path. Drain the channel before the final push. The gocognit nolint is extended because the drain adds one branch to an already-exempt function. * Add a notice for dropped cloud logs Fire counted entries dropped when the buffer was full, but nothing ever read that counter, so a full buffer lost logs silently. Surface the count as a synthetic warning, mirroring how --out loki reports its own limit drops. The notice is pushed through the loki hook's NoticePusher capability, which sends it immediately and exempt from the per-batch limit, so a full final batch (many buffered entries at shutdown, exactly when drops are likely) cannot swallow the notice itself. It is pushed after the final flush so it is the newest entry in the warning stream it shares with the hook's own limit-drop message, avoiding an out-of-order write that Loki with unordered_writes=false would reject. --- internal/log/cloud/cloud.go | 32 +++++++++ internal/log/cloud/cloud_test.go | 102 +++++++++++++++++++++++++++ internal/log/log.go | 8 +++ internal/log/loki.go | 114 ++++++++++++++++++++++--------- internal/log/loki_test.go | 57 ++++++++++++++++ 5 files changed, 282 insertions(+), 31 deletions(-) diff --git a/internal/log/cloud/cloud.go b/internal/log/cloud/cloud.go index 6fdad6ae2..6b328c374 100644 --- a/internal/log/cloud/cloud.go +++ b/internal/log/cloud/cloud.go @@ -12,6 +12,7 @@ package cloudlog import ( "context" + "fmt" "slices" "sync" "sync/atomic" @@ -210,6 +211,11 @@ func (p *Pusher) Listen(ctx context.Context) { //nolint:contextcheck // hook so it runs its synchronous final flush, and waits for that to // complete. lokiHook.Fire is a blocking send, so forwarding must happen // while the loki hook is still draining its channel (before lokiCancel). + // + // reportDropped runs last, after the final flush has been pushed: its + // notice shares the "warning" stream with the loki hook's own limit-drop + // message, so it must carry the newest timestamp and be pushed after it — + // otherwise Loki with unordered_writes=false rejects the older flush write. finish := func() { for { select { @@ -218,6 +224,7 @@ func (p *Pusher) Listen(ctx context.Context) { //nolint:contextcheck default: lokiCancel() <-lokiDone + p.reportDropped(lokiHook) return } } @@ -240,6 +247,31 @@ func (p *Pusher) Listen(ctx context.Context) { //nolint:contextcheck } } +// reportDropped surfaces the entries Fire dropped when the buffer was full, so +// the loss is visible rather than silent. The count is read once as a shutdown +// summary; drops after this point are not reported. +// +// It uses the loki hook's NoticePusher capability, which pushes the notice +// immediately and exempt from the hook's per-batch limit — otherwise a full +// final batch (many buffered entries at shutdown, exactly when drops are +// likely) would swallow the notice itself. +func (p *Pusher) reportDropped(h log.AsyncHook) { + n := p.dropped.Load() + if n == 0 { + return + } + + np, ok := h.(log.NoticePusher) + if !ok { + return + } + + msg := fmt.Sprintf("k6 dropped %d log messages because the cloud log buffer was full", n) + if err := np.PushNotice(msg); err != nil && p.fallbackLogger != nil { + p.fallbackLogger.WithError(err).Warn("could not push the dropped-cloud-logs notice") + } +} + // allowedLabelsWithTestRunID ensures the required test_run_id label survives // the loki hook's label filtering, which drops any label not in the allow-list // when that list is non-empty. An empty list must normalise to nil: the loki diff --git a/internal/log/cloud/cloud_test.go b/internal/log/cloud/cloud_test.go index 85d72ce89..e616a6272 100644 --- a/internal/log/cloud/cloud_test.go +++ b/internal/log/cloud/cloud_test.go @@ -2,9 +2,11 @@ package cloudlog import ( "context" + "encoding/json" "io" "net/http" "net/http/httptest" + "strconv" "strings" "sync" "testing" @@ -137,6 +139,106 @@ func TestPusher_FireNeverBlocks(t *testing.T) { assert.Equal(t, int64(overflow), p.dropped.Load()) } +// TestPusher_ReportsDroppedLogs proves the front-buffer drop counter is +// surfaced rather than silently discarded, even when the loki hook's own +// per-batch limit is already exhausted: the notice must bypass that limit. The +// limit is set well below the number of forwarded entries so a naive push +// (subject to the limit) would drop the notice itself. +// +// It also asserts push ordering: the notice shares the "warning" stream with +// the loki hook's own limit-drop message, so across pushes that stream's +// timestamps must be non-decreasing, otherwise Loki with unordered_writes=false +// rejects the older write. +func TestPusher_ReportsDroppedLogs(t *testing.T) { + t.Parallel() + + var ( + mu sync.Mutex + requests []string // request bodies, in the order the server received them + ) + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { + b, _ := io.ReadAll(req.Body) + mu.Lock() + requests = append(requests, string(b)) + mu.Unlock() + w.WriteHeader(http.StatusNoContent) + })) + defer srv.Close() + + const overflow = 7 + + p := New(testutils.NewLogger(t)) + p.SetConfig(Config{ + PushURL: srv.URL, + Token: "tok", + TestRunID: "run-dropped", + // Deliberately far below bufferCap: forwarding the buffered entries + // exhausts the loki per-batch limit, so the notice must bypass it. + Limit: 10, + PushPeriod: time.Hour, // only the shutdown push + }) + + // Overflow the buffer before Listen consumes anything, so exactly `overflow` + // entries are dropped by Fire. + for range bufferCap + overflow { + require.NoError(t, p.Fire(&logrus.Entry{Time: time.Now(), Level: logrus.InfoLevel, Message: "x"})) + } + require.Equal(t, int64(overflow), p.dropped.Load()) + + ctx := t.Context() + listenDone := make(chan struct{}) + go func() { + p.Listen(ctx) + close(listenDone) + }() + + require.NoError(t, p.Drain(context.Background())) + select { + case <-listenDone: + case <-time.After(2 * time.Second): + t.Fatal("Listen did not return after Drain") + } + + mu.Lock() + defer mu.Unlock() + + assert.Contains(t, strings.Join(requests, ""), + "dropped 7 log messages because the cloud log buffer was full", + "the front-buffer drop count must survive the loki per-batch limit") + + // Collect the "warning" stream timestamps in the order they were pushed and + // assert they never go backwards across requests. + type lokiPush struct { + Streams []struct { + Stream map[string]string `json:"stream"` + Values [][]string `json:"values"` + } `json:"streams"` + } + var warnTS []int64 + for _, body := range requests { + var lp lokiPush + require.NoError(t, json.Unmarshal([]byte(body), &lp)) + for _, s := range lp.Streams { + if s.Stream["level"] != logrus.WarnLevel.String() { + continue + } + for _, v := range s.Values { + require.GreaterOrEqual(t, len(v), 1) + ts, err := strconv.ParseInt(v[0], 10, 64) + require.NoError(t, err) + warnTS = append(warnTS, ts) + } + } + } + require.GreaterOrEqual(t, len(warnTS), 2, + "expected both the loki limit-drop warning and the cloud-buffer notice") + for i := 1; i < len(warnTS); i++ { + assert.GreaterOrEqual(t, warnTS[i], warnTS[i-1], + "warning-stream timestamps must not go backwards across pushes "+ + "(an out-of-order write is rejected by Loki with unordered_writes=false)") + } +} + // TestPusher_TestRunIDLabelKept locks the backend's hard requirement: even // when AllowedLabels omits test_run_id, the pushed stream still carries it as // a label (the backend 401s a push whose stream lacks it). diff --git a/internal/log/log.go b/internal/log/log.go index 3f0cfa4fc..1ef148767 100644 --- a/internal/log/log.go +++ b/internal/log/log.go @@ -16,3 +16,11 @@ type AsyncHook interface { // It stops when the context is canceled. Listen(ctx context.Context) } + +// NoticePusher is an optional capability of an AsyncHook: it pushes a single +// diagnostic line immediately, exempt from any per-batch limit the hook +// normally enforces. Callers type-assert an AsyncHook to it to surface events +// (such as an upstream buffer overflow) that must not be lost to that limit. +type NoticePusher interface { + PushNotice(message string) error +} diff --git a/internal/log/loki.go b/internal/log/loki.go index 261f6935b..173fa3caf 100644 --- a/internal/log/loki.go +++ b/internal/log/loki.go @@ -204,7 +204,7 @@ func (opts *LokiHookOptions) parseArgs(line string) error { // // TODO benchmark this // -//nolint:funlen +//nolint:funlen,gocognit func (h *lokiHook) Listen(ctx context.Context) { var ( msgs = make([]tmpMsg, h.limit) @@ -274,45 +274,75 @@ func (h *lokiHook) Listen(ctx context.Context) { } }() - for { - select { - case entry := <-h.ch: - if count == h.limit { - dropped++ + // appendEntry buffers one entry into msgs, or counts it as dropped once the + // per-push-period limit is reached. It mutates the count, dropped and msgs + // loop state, so it must run only on the main goroutine — never while the + // push goroutine is swapping msgs and resetting the counters. + appendEntry := func(entry *logrus.Entry) { + if count == h.limit { + dropped++ - continue - } + return + } - // Arguably we can directly generate the final marshalled version of the labels right here - // through sorting the entry.Data, removing additionalparams from it and then dumping it - // as the final marshal and appending level and h.labels after it. - // If we reuse some kind of big enough `[]byte` buffer we can also possibly skip on some - // of allocation. Combined with the cutoff part and directly pushing in the final data - // type this can be really a lot faster and to use a lot less memory - labels := make(map[string]string, len(entry.Data)+1) - for k, v := range entry.Data { - labels[k] = fmt.Sprint(v) // TODO optimize ? - } - for _, params := range h.labels { - labels[params[0]] = params[1] - } - labels["level"] = entry.Level.String() - msg := h.filterLabels(labels, entry.Message) // TODO we can do this while constructing - // have the cutoff here ? - // if we cutoff here we can cut somewhat on the backbuffers and optimize the inserting - // in/creating of the final Streams that we push - msgs[count] = tmpMsg{ - labels: labels, - msg: msg, - t: entry.Time.UnixNano(), + // Arguably we can directly generate the final marshalled version of the labels right here + // through sorting the entry.Data, removing additionalparams from it and then dumping it + // as the final marshal and appending level and h.labels after it. + // If we reuse some kind of big enough `[]byte` buffer we can also possibly skip on some + // of allocation. Combined with the cutoff part and directly pushing in the final data + // type this can be really a lot faster and to use a lot less memory + labels := make(map[string]string, len(entry.Data)+1) + for k, v := range entry.Data { + labels[k] = fmt.Sprint(v) // TODO optimize ? + } + for _, params := range h.labels { + labels[params[0]] = params[1] + } + labels["level"] = entry.Level.String() + msg := h.filterLabels(labels, entry.Message) // TODO we can do this while constructing + // have the cutoff here ? + // if we cutoff here we can cut somewhat on the backbuffers and optimize the inserting + // in/creating of the final Streams that we push + msgs[count] = tmpMsg{ + labels: labels, + msg: msg, + t: entry.Time.UnixNano(), + } + count++ + } + + // drainQueued flushes entries still buffered in h.ch into msgs without + // blocking. Called on shutdown so the final push includes everything Fire + // already accepted; best-effort, it does not wait for entries still being + // Fired concurrently with the shutdown. + drainQueued := func() { + for { + select { + case entry, ok := <-h.ch: + if !ok { + // h.ch is never closed today; this guards a future close + // from spinning on nil receives. + return + } + appendEntry(entry) + default: + return } - count++ + } + } + + for { + select { + case entry := <-h.ch: + appendEntry(entry) case t := <-ticker.C: ch := make(chan int64) pushCh <- ch ch <- t.Add(-(h.pushPeriod / 2)).UnixNano() <-ch case <-ctx.Done(): + drainQueued() + ch := make(chan int64) pushCh <- ch ch <- time.Now().Add(time.Second).UnixNano() @@ -388,6 +418,28 @@ func (h *lokiHook) createPushMessage(msgs []tmpMsg, cutOffIndex, dropped int) *l return pushMsg } +// PushNotice synchronously pushes a single warning line to loki, exempt from +// the per-batch limit the main push loop enforces. It surfaces out-of-band +// drops (for example an upstream buffer overflow) that must not be lost to that +// limit. The line carries the hook's configured labels, so it is not rejected +// for a missing test_run_id. +func (h *lokiHook) PushNotice(message string) error { + pushMsg := new(lokiPushMessage) + pushMsg.maxSize = h.msgMaxSize + pushMsg.add(tmpMsg{ + labels: h.droppedLabels, + msg: message, + t: time.Now().UnixNano(), + }) + + var b bytes.Buffer + if _, err := pushMsg.WriteTo(&b); err != nil { + return err + } + + return h.push(b) +} + func (h *lokiHook) push(b bytes.Buffer) error { body := b.Bytes() diff --git a/internal/log/loki_test.go b/internal/log/loki_test.go index 5889e1d96..52383861d 100644 --- a/internal/log/loki_test.go +++ b/internal/log/loki_test.go @@ -373,3 +373,60 @@ func TestLokiFromConfigLineEmptyAddr(t *testing.T) { require.NoError(t, err) assert.NotEmpty(t, bare.(*lokiHook).addr, "bare loki uses the default endpoint") } + +// TestLokiHookDrainsQueuedEntriesOnShutdown pins that a ctx-cancel shutdown +// flushes every entry already queued in the hook's channel, not just the ones +// the run loop happened to consume before the cancel was selected. The entries +// are pre-loaded and the context is already cancelled, so Listen takes its +// shutdown branch with the whole batch still queued; without draining the +// channel it would lose a suffix of them. +func TestLokiHookDrainsQueuedEntriesOnShutdown(t *testing.T) { + t.Parallel() + + const n = 100 + + var ( + mu sync.Mutex + got string + ) + srv := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, req *http.Request) { + b, err := io.ReadAll(req.Body) + if err != nil { + t.Error(err) + return + } + mu.Lock() + got += string(b) + mu.Unlock() + })) + defer srv.Close() + + // Limit well above n so nothing is limit-dropped, and a long push period so + // the shutdown push is the only one. + h, err := NewLokiHook(testutils.NewLogger(t), LokiHookOptions{ + Addr: srv.URL, + Limit: 2 * n, + PushPeriod: time.Hour, + }) + require.NoError(t, err) + + // Queue every entry before Listen starts (white-box: this test is in + // package log), so the shutdown branch must drain the channel to send them. + for i := range n { + h.(*lokiHook).ch <- &logrus.Entry{ + Time: time.Now(), + Level: logrus.InfoLevel, + Message: fmt.Sprintf("msg-%d", i), + } + } + + ctx, cancel := context.WithCancel(context.Background()) + cancel() + h.Listen(ctx) + + mu.Lock() + defer mu.Unlock() + for i := range n { + assert.Contains(t, got, fmt.Sprintf("msg-%d", i), "entry %d was lost on shutdown", i) + } +} From f069f135ce80267b08613ce73c5b0773372bcaf7 Mon Sep 17 00:00:00 2001 From: Mihail Stoykov <312246+mstoykov@users.noreply.github.com> Date: Mon, 3 Aug 2026 11:39:21 +0300 Subject: [PATCH 098/182] fix(httpext): classify HTTP/2 errors and negotiate h2 correctly under Go 1.27 (#6234) Since Go 1.27, golang.org/x/net/http2 compiles a "wrapping implementation" that delegates to net/http. HTTP/2 errors then originate from the unexported net/http/internal/http2 types, which the http2.{ConnectionError,GoAwayError} cases in errorCodeForError cannot match. Unlike StreamError, those two types have no errors.As bridge to the x/net types, so they previously collapsed to the generic default error code. Add a fallback to the default branch of errorCodeForError: * StreamError is recovered via errors.As (the standard-library type implements an As bridge to x/net's StreamError). * ConnectionError and GoAwayError are matched by their Error() text, which is identical between the x/net and standard-library implementations; the spec-defined error code is parsed back out so the existing, code-specific k6 error codes and messages are preserved. Verified against real Go 1.27 (gotip) errors: connection/goaway/stream errors now map to the same k6 error codes as on Go <= 1.26. Adds TestHTTP2MessageFallback, which feeds the exact error strings and so runs on every Go version. Co-Authored-By: Claude Opus 4.8 (1M context) --- .github/actions/test/action.yml | 11 --- internal/js/runner.go | 7 +- .../testutils/httpmultibin/httpmultibin.go | 17 +++- lib/netext/httpext/error_codes.go | 87 ++++++++++++++-- lib/netext/httpext/error_codes_test.go | 99 ++++++++++++++++++- 5 files changed, 191 insertions(+), 30 deletions(-) diff --git a/.github/actions/test/action.yml b/.github/actions/test/action.yml index 7a9f22a10..ec95d6122 100644 --- a/.github/actions/test/action.yml +++ b/.github/actions/test/action.yml @@ -39,15 +39,4 @@ runs: unset args[2] fi fi - if [[ ${USE_GOTIP} == 'true' ]]; then - # Under Go 1.27+, golang.org/x/net/http2 switches to a "wrapping - # implementation" that delegates to net/http. With it, ConfigureTransport - # no longer forces HTTP/2 over custom dialers, and HTTP/2 errors surface as - # unexported net/http/internal/http2 types that lib/netext/httpext can no - # longer classify (only StreamError has an upstream errors.As bridge; - # ConnectionError and GoAwayError do not). Force the legacy x/net - # implementation until k6 adapts. See Dependencies.md / the http2 error - # handling in lib/netext/httpext/error_codes.go. - args+=("-tags" "http2legacy") - fi go test "${args[@]}" -timeout 1600s `go list ./... | grep -v browser/tests` diff --git a/internal/js/runner.go b/internal/js/runner.go index 2dee13099..4da79dbf6 100644 --- a/internal/js/runner.go +++ b/internal/js/runner.go @@ -19,7 +19,6 @@ import ( "github.com/grafana/sobek" "github.com/sirupsen/logrus" - "golang.org/x/net/http2" "golang.org/x/time/rate" "go.k6.io/k6/v2/errext" @@ -206,9 +205,11 @@ func (r *Runner) newVU( } if r.forceHTTP1() { - transport.TLSNextProto = make(map[string]func(string, *tls.Conn) http.RoundTripper) // send over h1 protocol + transport.TLSNextProto = make(map[string]func(string, *tls.Conn) http.RoundTripper) } else { - _ = http2.ConfigureTransport(transport) // send over h2 protocol + // net/http negotiates HTTP/2 over a Transport with a custom DialContext or + // TLSClientConfig only when ForceAttemptHTTP2 is set (see Go issue #14275). + transport.ForceAttemptHTTP2 = true } cookieJar, err := cookiejar.New(nil) diff --git a/internal/lib/testutils/httpmultibin/httpmultibin.go b/internal/lib/testutils/httpmultibin/httpmultibin.go index 437644f0f..09063b917 100644 --- a/internal/lib/testutils/httpmultibin/httpmultibin.go +++ b/internal/lib/testutils/httpmultibin/httpmultibin.go @@ -359,12 +359,21 @@ func NewHTTPMultiBin(t testing.TB) *HTTPMultiBin { }) require.NoError(t, err) - // Pre-configure the HTTP client transport with the dialer and TLS config (incl. HTTP2 support) + // Pre-configure the HTTP client transport with the dialer and TLS config. + // + // Advertise both h2 and http/1.1 so the client can reach both the HTTP/2 server and the + // http/1.1-only HTTPS server. ForceAttemptHTTP2 tells net/http to negotiate HTTP/2 even + // when a custom DialContext/TLSClientConfig is set (see Go issue #14275). + // + // Clone the shared TLS config before widening NextProtos so the client-only protocol list + // does not leak into other users of the config. + clientTLSConfig := tlsConfig.Clone() + clientTLSConfig.NextProtos = []string{http2.NextProtoTLS, "http/1.1"} transport := &http.Transport{ - DialContext: dialer.DialContext, - TLSClientConfig: tlsConfig, + DialContext: dialer.DialContext, + TLSClientConfig: clientTLSConfig, + ForceAttemptHTTP2: true, } - require.NoError(t, http2.ConfigureTransport(transport)) ctx, ctxCancel := context.WithCancel(context.Background()) diff --git a/lib/netext/httpext/error_codes.go b/lib/netext/httpext/error_codes.go index 4c4eb7e07..2e4251c4a 100644 --- a/lib/netext/httpext/error_codes.go +++ b/lib/netext/httpext/error_codes.go @@ -9,6 +9,8 @@ import ( "net/url" "os" "runtime" + "strconv" + "strings" "syscall" "golang.org/x/net/http2" @@ -92,6 +94,75 @@ func http2ErrCodeOffset(code http2.ErrCode) errCode { return 1 + errCode(code) } +// http2ErrCodeByName maps the textual form produced by http2.ErrCode.String() +// (e.g. "PROTOCOL_ERROR") back to its code. Unknown numeric codes are also +// recognized so they remain in the appropriate unknown HTTP/2 error bucket. +func http2ErrCodeByName(name string) (http2.ErrCode, bool) { + for code := http2.ErrCodeNo; code <= http2.ErrCodeHTTP11Required; code++ { + if code.String() == name { + return code, true + } + } + const unknownCodePrefix = "unknown error code 0x" + if after, ok := strings.CutPrefix(name, unknownCodePrefix); ok { + if value, err := strconv.ParseUint(after, 16, 32); err == nil { + return http2.ErrCode(value), true + } + } + return 0, false +} + +// errorCodeForHTTP2Message classifies an HTTP/2 error by the text of its +// Error() method. All HTTP/2 error types from both golang.org/x/net/http2 and +// Go's stdlib net/http/internal/http2 produce the same Error() strings, so +// this single path handles every Go version uniformly. Spec-defined codes are +// mapped to specific buckets, and unknown numeric codes retain their unknown +// HTTP/2 error bucket. +func errorCodeForHTTP2Message(msg string) (errCode, string, bool) { + switch { + case strings.HasPrefix(msg, "stream error: "): + // Format: "stream error: stream ID N; ERRCODE[; cause]" + // Cause is omitted when StreamError.Cause == nil, so the trailing "; cause" + // segment may be absent. Skip "stream error: stream ID N; " then take the + // ERRCODE up to the next ";" (with cause) or end of string (without cause). + if _, rest, ok := strings.Cut(msg, "; "); ok { + name, _, _ := strings.Cut(rest, ";") + if code, ok := http2ErrCodeByName(strings.TrimSpace(name)); ok { + return unknownHTTP2StreamErrorCode + http2ErrCodeOffset(code), + fmt.Sprintf(http2StreamErrorCodeMsg, code), true + } + } + case strings.HasPrefix(msg, "connection error: "): + name := strings.TrimPrefix(msg, "connection error: ") + if code, ok := http2ErrCodeByName(name); ok { + return unknownHTTP2ConnectionErrorCode + http2ErrCodeOffset(code), + fmt.Sprintf(http2ConnectionErrorCodeMsg, code), true + } + case strings.HasPrefix(msg, "http2: server sent GOAWAY"): + if name, ok := stringBetween(msg, "ErrCode=", ","); ok { + if code, ok := http2ErrCodeByName(name); ok { + return unknownHTTP2GoAwayErrorCode + http2ErrCodeOffset(code), + fmt.Sprintf(http2GoAwayErrorCodeMsg, code), true + } + } + } + return 0, "", false +} + +// stringBetween returns the substring of s found between the first occurrence +// of prefix and the next occurrence of sep that follows it. +func stringBetween(s, prefix, sep string) (string, bool) { + _, after, found := strings.Cut(s, prefix) + if !found { + return "", false + } + mid, _, found := strings.Cut(after, sep) + if !found { + return "", false + } + return mid, true +} + //nolint:errorlint func errorCodeForNetOpError(err *net.OpError) (errCode, string) { // TODO: refactor this further - a big switch would be more readable, maybe @@ -173,15 +244,6 @@ func errorCodeForError(err error) (errCode, string) { return blackListedIPErrorCode, blackListedIPErrorCodeMsg case netext.BlockedHostError: return blockedHostnameErrorCode, blockedHostnameErrorMsg - case http2.GoAwayError: - return unknownHTTP2GoAwayErrorCode + http2ErrCodeOffset(e.ErrCode), - fmt.Sprintf(http2GoAwayErrorCodeMsg, e.ErrCode) - case http2.StreamError: - return unknownHTTP2StreamErrorCode + http2ErrCodeOffset(e.Code), - fmt.Sprintf(http2StreamErrorCodeMsg, e.Code) - case http2.ConnectionError: - return unknownHTTP2ConnectionErrorCode + http2ErrCodeOffset(http2.ErrCode(e)), - fmt.Sprintf(http2ConnectionErrorCodeMsg, http2.ErrCode(e)) case *net.OpError: return errorCodeForNetOpError(e) case x509.UnknownAuthorityError: @@ -193,9 +255,16 @@ func errorCodeForError(err error) (errCode, string) { case *url.Error: return errorCodeForError(e.Err) default: + // Unwrap first: a wrapped error may have a concrete inner type that one of + // the cases above can match. String matching runs only on errors that have + // no unwrappable inner type, reducing the chance of a false positive from + // a non-HTTP/2 error whose message happens to start with an HTTP/2 prefix. if wrappedErr := errors.Unwrap(err); wrappedErr != nil { return errorCodeForError(wrappedErr) } + if code, msg, ok := errorCodeForHTTP2Message(err.Error()); ok { + return code, msg + } return defaultErrorCode, err.Error() } diff --git a/lib/netext/httpext/error_codes_test.go b/lib/netext/httpext/error_codes_test.go index b771132bb..7ec224868 100644 --- a/lib/netext/httpext/error_codes_test.go +++ b/lib/netext/httpext/error_codes_test.go @@ -338,6 +338,99 @@ func TestHTTP2GoAwayError(t *testing.T) { assert.Equal(t, fmt.Sprintf(http2GoAwayErrorCodeMsg, http2.ErrCodeInadequateSecurity), msg) } +// TestHTTP2MessageFallback covers message-based classification of HTTP/2 errors. +// Both golang.org/x/net/http2 and Go's stdlib net/http/internal/http2 produce +// identical Error() strings, so a single message-based path handles every Go +// version uniformly. This feeds exact error strings directly, so it runs on +// every Go version without a live server. +func TestHTTP2MessageFallback(t *testing.T) { + t.Parallel() + + streamErr := fmt.Errorf("stream error: stream ID 1; %v; EOF", http2.ErrCodeInternal) + streamErrNoCause := fmt.Errorf("stream error: stream ID 1; %v", http2.ErrCodeInternal) + connErr := errors.New("connection error: " + http2.ErrCodeProtocol.String()) + goAwayErr := fmt.Errorf( + "http2: server sent GOAWAY and closed the connection; LastStreamID=4, ErrCode=%v, debug=%q", + http2.ErrCodeInadequateSecurity, "whatever") + + testCases := []struct { + name string + err error + wantCode errCode + wantMsg string + }{ + { + name: "stream error", + err: streamErr, + wantCode: unknownHTTP2StreamErrorCode + http2ErrCodeOffset(http2.ErrCodeInternal), + wantMsg: fmt.Sprintf(http2StreamErrorCodeMsg, http2.ErrCodeInternal), + }, + { + name: "stream error wrapped", + err: fmt.Errorf("read: %w", streamErr), + wantCode: unknownHTTP2StreamErrorCode + http2ErrCodeOffset(http2.ErrCodeInternal), + wantMsg: fmt.Sprintf(http2StreamErrorCodeMsg, http2.ErrCodeInternal), + }, + { + name: "stream error no cause", + err: streamErrNoCause, + wantCode: unknownHTTP2StreamErrorCode + http2ErrCodeOffset(http2.ErrCodeInternal), + wantMsg: fmt.Sprintf(http2StreamErrorCodeMsg, http2.ErrCodeInternal), + }, + { + name: "connection error", + err: connErr, + wantCode: unknownHTTP2ConnectionErrorCode + http2ErrCodeOffset(http2.ErrCodeProtocol), + wantMsg: fmt.Sprintf(http2ConnectionErrorCodeMsg, http2.ErrCodeProtocol), + }, + { + name: "connection error wrapped in url.Error", + err: &url.Error{Op: "Get", URL: "https://example.com", Err: connErr}, + wantCode: unknownHTTP2ConnectionErrorCode + http2ErrCodeOffset(http2.ErrCodeProtocol), + wantMsg: fmt.Sprintf(http2ConnectionErrorCodeMsg, http2.ErrCodeProtocol), + }, + { + name: "goaway error", + err: goAwayErr, + wantCode: unknownHTTP2GoAwayErrorCode + http2ErrCodeOffset(http2.ErrCodeInadequateSecurity), + wantMsg: fmt.Sprintf(http2GoAwayErrorCodeMsg, http2.ErrCodeInadequateSecurity), + }, + { + name: "goaway error wrapped", + err: fmt.Errorf("read tcp: %w", goAwayErr), + wantCode: unknownHTTP2GoAwayErrorCode + http2ErrCodeOffset(http2.ErrCodeInadequateSecurity), + wantMsg: fmt.Sprintf(http2GoAwayErrorCodeMsg, http2.ErrCodeInadequateSecurity), + }, + { + name: "unknown connection error", + err: errors.New("connection error: unknown error code 0xe"), + wantCode: unknownHTTP2ConnectionErrorCode, + wantMsg: "http2: connection error with http2 ErrCode unknown error code 0xe", + }, + { + name: "unknown stream error", + err: errors.New("stream error: stream ID 1; unknown error code 0xe; received from peer"), + wantCode: unknownHTTP2StreamErrorCode, + wantMsg: "http2: stream error with http2 ErrCode unknown error code 0xe", + }, + { + name: "unknown goaway error", + err: errors.New( + "http2: server sent GOAWAY and closed the connection; LastStreamID=4, ErrCode=unknown error code 0xe, debug=\"whatever\""), + wantCode: unknownHTTP2GoAwayErrorCode, + wantMsg: "http2: received GoAway with http2 ErrCode unknown error code 0xe", + }, + } + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + code, msg := errorCodeForError(tc.err) + assert.Equal(t, tc.wantCode, code) + assert.Equal(t, tc.wantMsg, msg) + }) + } +} + type connKeyT int32 const connKey connKeyT = 2 @@ -372,10 +465,10 @@ func getHTTP2ServerWithCustomConnContext(t *testing.T) *httpmultibin.HTTPMultiBi require.NoError(t, err) transport := &http.Transport{ - DialContext: dialer.DialContext, - TLSClientConfig: tlsConfig, + DialContext: dialer.DialContext, + TLSClientConfig: tlsConfig, + ForceAttemptHTTP2: true, } - require.NoError(t, http2.ConfigureTransport(transport)) return &httpmultibin.HTTPMultiBin{ Mux: mux, ServerHTTP2: http2Srv, From d7cfa7599ddc13530c659d2a4f4fed862a550fdd Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Mon, 3 Aug 2026 11:48:38 +0100 Subject: [PATCH 099/182] fix(deps): update module google.golang.org/grpc to v1.83.0 (#6240) | datasource | package | from | to | | ---------- | ---------------------- | ------- | ------- | | go | google.golang.org/grpc | v1.82.1 | v1.83.0 | Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 +- vendor/google.golang.org/grpc/clientconn.go | 23 +----- .../clientconn_disconnect_reason_noplan9.go | 48 ++++++++++++ .../clientconn_disconnect_reason_plan9.go | 39 ++++++++++ .../grpc/internal/envconfig/xds.go | 7 +- .../internal/grpcsync/callback_serializer.go | 26 +++++++ .../grpc/internal/resolver/config_selector.go | 78 +------------------ .../grpc/internal/transport/client_stream.go | 5 +- .../grpc/internal/transport/http2_client.go | 4 - .../grpc/internal/transport/transport.go | 2 - vendor/google.golang.org/grpc/stream.go | 35 ++++++--- vendor/google.golang.org/grpc/version.go | 2 +- vendor/modules.txt | 2 +- 14 files changed, 153 insertions(+), 124 deletions(-) create mode 100644 vendor/google.golang.org/grpc/clientconn_disconnect_reason_noplan9.go create mode 100644 vendor/google.golang.org/grpc/clientconn_disconnect_reason_plan9.go diff --git a/go.mod b/go.mod index 9dd163b88..a0a0188c7 100644 --- a/go.mod +++ b/go.mod @@ -63,7 +63,7 @@ require ( golang.org/x/sync v0.22.0 golang.org/x/term v0.45.0 golang.org/x/time v0.15.0 - google.golang.org/grpc v1.82.1 + google.golang.org/grpc v1.83.0 google.golang.org/protobuf v1.36.11 gopkg.in/guregu/null.v3 v3.3.0 gopkg.in/yaml.v3 v3.0.1 diff --git a/go.sum b/go.sum index b7a4121e9..03f8158fc 100644 --- a/go.sum +++ b/go.sum @@ -388,8 +388,8 @@ google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyac google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= -google.golang.org/grpc v1.82.1 h1:NnAxzGRA0677vCa4BUkOAnO5+FfQqVl9iUXeD0IqcGE= -google.golang.org/grpc v1.82.1/go.mod h1:yzTZ1TB1Z3SG+LIYaI+WiE8D5+PZ3ArnrSp8zF3+/ZA= +google.golang.org/grpc v1.83.0 h1:JeNZEKJFbQxArAMl+hiytHauacDNqJUllNfmIMmpqnQ= +google.golang.org/grpc v1.83.0/go.mod h1:kDyl6SKsiHKt0uylY5gtn5cEjkrIOhQOGDgIc4JGwzQ= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= diff --git a/vendor/google.golang.org/grpc/clientconn.go b/vendor/google.golang.org/grpc/clientconn.go index c4bca5203..b27c7e84a 100644 --- a/vendor/google.golang.org/grpc/clientconn.go +++ b/vendor/google.golang.org/grpc/clientconn.go @@ -24,12 +24,10 @@ import ( "fmt" "math" "net/url" - "os" "slices" "strings" "sync" "sync/atomic" - "syscall" "time" "google.golang.org/grpc/balancer" @@ -1573,26 +1571,13 @@ func (ac *addrConn) createTransport(ctx context.Context, addr resolver.Address, // to the provided transport.GoAwayInfo, as specified by gRFC A94: // https://github.com/grpc/proposal/blob/master/A94-grpc-subchannel-disconnections-metrics.md func disconnectErrorString(info transport.GoAwayInfo) string { - err := info.Err - var sysErr syscall.Errno - switch { - case info.Reason != transport.GoAwayInvalid: + if info.Reason != transport.GoAwayInvalid { return fmt.Sprintf("GOAWAY %s", info.GoAwayCode.String()) - case err == nil: - return "unknown" - case errors.Is(err, context.Canceled): - return "subchannel shutdown" - case errors.Is(err, syscall.ECONNRESET): - return "connection reset" - case errors.Is(err, syscall.ETIMEDOUT), errors.Is(err, context.DeadlineExceeded), errors.Is(err, os.ErrDeadlineExceeded): - return "connection timed out" - case errors.Is(err, syscall.ECONNABORTED): - return "connection aborted" - case errors.As(err, &sysErr): - return "socket error" - default: + } + if info.Err == nil { return "unknown" } + return disconnectErrorLabel(info.Err) } // startHealthCheck starts the health checking stream (RPC) to watch the health diff --git a/vendor/google.golang.org/grpc/clientconn_disconnect_reason_noplan9.go b/vendor/google.golang.org/grpc/clientconn_disconnect_reason_noplan9.go new file mode 100644 index 000000000..f0fcd8842 --- /dev/null +++ b/vendor/google.golang.org/grpc/clientconn_disconnect_reason_noplan9.go @@ -0,0 +1,48 @@ +//go:build !plan9 + +/* + * + * Copyright 2026 gRPC 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. + * + */ + +package grpc + +import ( + "context" + "errors" + "os" + "syscall" +) + +// disconnectErrorLabel returns the grpc.disconnect_error metric label for a +// transport error, as specified by gRFC A94. +func disconnectErrorLabel(err error) string { + var sysErr syscall.Errno + switch { + case errors.Is(err, context.Canceled): + return "subchannel shutdown" + case errors.Is(err, syscall.ECONNRESET): + return "connection reset" + case errors.Is(err, syscall.ETIMEDOUT), errors.Is(err, context.DeadlineExceeded), errors.Is(err, os.ErrDeadlineExceeded): + return "connection timed out" + case errors.Is(err, syscall.ECONNABORTED): + return "connection aborted" + case errors.As(err, &sysErr): + return "socket error" + default: + return "unknown" + } +} diff --git a/vendor/google.golang.org/grpc/clientconn_disconnect_reason_plan9.go b/vendor/google.golang.org/grpc/clientconn_disconnect_reason_plan9.go new file mode 100644 index 000000000..930b12664 --- /dev/null +++ b/vendor/google.golang.org/grpc/clientconn_disconnect_reason_plan9.go @@ -0,0 +1,39 @@ +/* + * + * Copyright 2026 gRPC 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. + * + */ + +package grpc + +import ( + "context" + "errors" + "os" +) + +// disconnectErrorLabel returns the grpc.disconnect_error metric label for a +// transport error, as specified by gRFC A94. syscall.Errno does not exist on +// plan9, so only the portable classifications are available. +func disconnectErrorLabel(err error) string { + switch { + case errors.Is(err, context.Canceled): + return "subchannel shutdown" + case errors.Is(err, context.DeadlineExceeded), errors.Is(err, os.ErrDeadlineExceeded): + return "connection timed out" + default: + return "unknown" + } +} diff --git a/vendor/google.golang.org/grpc/internal/envconfig/xds.go b/vendor/google.golang.org/grpc/internal/envconfig/xds.go index a2312f8ea..e4b691913 100644 --- a/vendor/google.golang.org/grpc/internal/envconfig/xds.go +++ b/vendor/google.golang.org/grpc/internal/envconfig/xds.go @@ -69,9 +69,8 @@ var ( // https://github.com/grpc/proposal/blob/master/A87-mtls-spiffe-support.md XDSSPIFFEEnabled = boolFromEnv("GRPC_EXPERIMENTAL_XDS_MTLS_SPIFFE", false) - // XDSHTTPConnectEnabled is true if gRPC should parse custom Metadata - // configuring use of an HTTP CONNECT proxy via xDS from cluster resources. - // For more details, see: + // XDSHTTPConnectEnabled controls support for dynamic HTTP CONNECT proxying + // configured via the xDS control plane. For more details, see: // https://github.com/grpc/proposal/blob/master/A86-xds-http-connect.md XDSHTTPConnectEnabled = boolFromEnv("GRPC_EXPERIMENTAL_XDS_HTTP_CONNECT", false) @@ -88,7 +87,7 @@ var ( // XDSORCAToLRSPropEnabled controls whether ORCA metrics are explicitly // filtered and prefix-propagated to the LRS server. For more details, see: // https://github.com/grpc/proposal/blob/master/A85-lrs-custom-metrics-changes.md - XDSORCAToLRSPropEnabled = boolFromEnv("GRPC_EXPERIMENTAL_XDS_ORCA_LRS_PROPAGATION", false) + XDSORCAToLRSPropEnabled = boolFromEnv("GRPC_EXPERIMENTAL_XDS_ORCA_LRS_PROPAGATION", true) // XDSClientExtProcEnabled indicates whether ExtProc filter is enabled on // the client side. For more details, see: diff --git a/vendor/google.golang.org/grpc/internal/grpcsync/callback_serializer.go b/vendor/google.golang.org/grpc/internal/grpcsync/callback_serializer.go index 9b6d8a1fa..d4999fcca 100644 --- a/vendor/google.golang.org/grpc/internal/grpcsync/callback_serializer.go +++ b/vendor/google.golang.org/grpc/internal/grpcsync/callback_serializer.go @@ -20,10 +20,15 @@ package grpcsync import ( "context" + "errors" "google.golang.org/grpc/internal/buffer" ) +// ErrSerializerClosed is returned by ScheduleAndWait if the CallbackSerializer +// was closed before the callback could be scheduled. +var ErrSerializerClosed = errors.New("callback serializer is closed") + // CallbackSerializer provides a mechanism to schedule callbacks in a // synchronized manner. It provides a FIFO guarantee on the order of execution // of scheduled callbacks. New callbacks can be scheduled by invoking the @@ -77,6 +82,27 @@ func (cs *CallbackSerializer) ScheduleOr(f func(ctx context.Context), onFailure } } +// ScheduleAndWait schedules the provided callback function f to be executed in +// the order it was added and blocks until f has run. If the context passed to +// NewCallbackSerializer was canceled before this method is called, f is not run +// and ScheduleAndWait returns ErrSerializerClosed. +// +// Callbacks are expected to honor the context when performing any blocking +// operations, and should return early when the context is canceled. +func (cs *CallbackSerializer) ScheduleAndWait(f func(ctx context.Context)) error { + done := make(chan struct{}) + var err error + cs.ScheduleOr(func(ctx context.Context) { + f(ctx) + close(done) + }, func() { + err = ErrSerializerClosed + close(done) + }) + <-done + return err +} + func (cs *CallbackSerializer) run(ctx context.Context) { defer close(cs.done) diff --git a/vendor/google.golang.org/grpc/internal/resolver/config_selector.go b/vendor/google.golang.org/grpc/internal/resolver/config_selector.go index 6320e9b57..238950bbb 100644 --- a/vendor/google.golang.org/grpc/internal/resolver/config_selector.go +++ b/vendor/google.golang.org/grpc/internal/resolver/config_selector.go @@ -24,7 +24,6 @@ import ( "sync" "google.golang.org/grpc/internal/serviceconfig" - "google.golang.org/grpc/metadata" "google.golang.org/grpc/resolver" ) @@ -52,82 +51,7 @@ type RPCConfig struct { Context context.Context MethodConfig serviceconfig.MethodConfig // configuration to use for this RPC OnCommitted func() // Called when the RPC has been committed (retries no longer possible) - Interceptor ClientInterceptor -} - -// ClientStream is the same as grpc.ClientStream, but defined here for circular -// dependency reasons. -type ClientStream interface { - // Header returns the header metadata received from the server if there - // is any. It blocks if the metadata is not ready to read. - Header() (metadata.MD, error) - // Trailer returns the trailer metadata from the server, if there is any. - // It must only be called after stream.CloseAndRecv has returned, or - // stream.Recv has returned a non-nil error (including io.EOF). - Trailer() metadata.MD - // CloseSend closes the send direction of the stream. It closes the stream - // when non-nil error is met. It is also not safe to call CloseSend - // concurrently with SendMsg. - CloseSend() error - // Context returns the context for this stream. - // - // It should not be called until after Header or RecvMsg has returned. Once - // called, subsequent client-side retries are disabled. - Context() context.Context - // SendMsg is generally called by generated code. On error, SendMsg aborts - // the stream. If the error was generated by the client, the status is - // returned directly; otherwise, io.EOF is returned and the status of - // the stream may be discovered using RecvMsg. - // - // SendMsg blocks until: - // - There is sufficient flow control to schedule m with the transport, or - // - The stream is done, or - // - The stream breaks. - // - // SendMsg does not wait until the message is received by the server. An - // untimely stream closure may result in lost messages. To ensure delivery, - // users should ensure the RPC completed successfully using RecvMsg. - // - // It is safe to have a goroutine calling SendMsg and another goroutine - // calling RecvMsg on the same stream at the same time, but it is not safe - // to call SendMsg on the same stream in different goroutines. It is also - // not safe to call CloseSend concurrently with SendMsg. - SendMsg(m any) error - // RecvMsg blocks until it receives a message into m or the stream is - // done. It returns io.EOF when the stream completes successfully. On - // any other error, the stream is aborted and the error contains the RPC - // status. - // - // It is safe to have a goroutine calling SendMsg and another goroutine - // calling RecvMsg on the same stream at the same time, but it is not - // safe to call RecvMsg on the same stream in different goroutines. - RecvMsg(m any) error -} - -// ClientInterceptor is an interceptor for gRPC client streams. -type ClientInterceptor interface { - // NewStream creates a ClientStream for an RPC. - // - // Implementations must delegate stream creation to the provided newStream - // function. To intercept or override stream behavior, implementations - // may wrap the ClientStream returned by the delegate. - // - // Note: RPCInfo.Context is currently unused and will be nil. - // - // The done function is invoked when the RPC has finished using its - // underlying connection or if a connection could not be assigned. Because - // interceptors operate at the application layer, RPC operations may - // continue on the ClientStream even after done has been called. The - // caller must ensure done is non-nil. - // - // To ensure RPC completion notifications propagate through the entire - // interceptor chain, implementations must ensure that the done function - // passed to the delegate newStream invokes the done function passed to - // NewStream. - NewStream(ctx context.Context, ri RPCInfo, done func(), newStream func(ctx context.Context, done func()) (ClientStream, error)) (ClientStream, error) - // Close closes the interceptor. Once called, no new calls to NewStream are - // accepted. Ongoing calls to NewStream are allowed to complete. - Close() + Interceptor any } // ServerInterceptor is an interceptor for incoming RPC's on gRPC server side. diff --git a/vendor/google.golang.org/grpc/internal/transport/client_stream.go b/vendor/google.golang.org/grpc/internal/transport/client_stream.go index ad382b0fd..046f0a555 100644 --- a/vendor/google.golang.org/grpc/internal/transport/client_stream.go +++ b/vendor/google.golang.org/grpc/internal/transport/client_stream.go @@ -39,9 +39,8 @@ const nonGRPCDataMaxLen = 1024 type ClientStream struct { Stream // Embed for common stream functionality. - ct *http2Client - done chan struct{} // closed at the end of stream to unblock writers. - doneFunc func() // invoked at the end of stream. + ct *http2Client + done chan struct{} // closed at the end of stream to unblock writers. headerChan chan struct{} // closed to indicate the end of header metadata. header metadata.MD // the received header metadata diff --git a/vendor/google.golang.org/grpc/internal/transport/http2_client.go b/vendor/google.golang.org/grpc/internal/transport/http2_client.go index 822c09ba6..c19b45080 100644 --- a/vendor/google.golang.org/grpc/internal/transport/http2_client.go +++ b/vendor/google.golang.org/grpc/internal/transport/http2_client.go @@ -498,7 +498,6 @@ func (t *http2Client) newStream(ctx context.Context, callHdr *CallHdr, handler s ct: t, done: make(chan struct{}), headerChan: make(chan struct{}), - doneFunc: callHdr.DoneFunc, statsHandler: handler, } s.Stream.buf.init() @@ -998,9 +997,6 @@ func (t *http2Client) closeStream(s *ClientStream, err error, rst bool, rstCode t.controlBuf.executeAndPut(addBackStreamQuota, cleanup) // This will unblock write. close(s.done) - if s.doneFunc != nil { - s.doneFunc() - } } // Close kicks off the shutdown process of the transport. This should be called diff --git a/vendor/google.golang.org/grpc/internal/transport/transport.go b/vendor/google.golang.org/grpc/internal/transport/transport.go index 6dfae3984..d2e49538f 100644 --- a/vendor/google.golang.org/grpc/internal/transport/transport.go +++ b/vendor/google.golang.org/grpc/internal/transport/transport.go @@ -594,8 +594,6 @@ type CallHdr struct { PreviousAttempts int // value of grpc-previous-rpc-attempts header to set - DoneFunc func() // called when the stream is finished - // Authority is used to explicitly override the `:authority` header. // // This value comes from one of two sources: diff --git a/vendor/google.golang.org/grpc/stream.go b/vendor/google.golang.org/grpc/stream.go index 4aac644a8..51aff85df 100644 --- a/vendor/google.golang.org/grpc/stream.go +++ b/vendor/google.golang.org/grpc/stream.go @@ -201,6 +201,15 @@ func endOfClientStream(cc *ClientConn, err error, opts ...CallOption) { } } +// clientInterceptor is structurally identical to the ClientInterceptor defined +// in internal/xds/httpfilter/httpfilter.go. It is defined locally here so that +// we can type-assert the generic Interceptor field in iresolver.RPCConfig +// without introducing a dependency on xDS packages. +type clientInterceptor interface { + NewStream(ctx context.Context, ri iresolver.RPCInfo, newStream func(ctx context.Context, opts ...CallOption) (ClientStream, error), opts ...CallOption) (ClientStream, error) + Close() +} + func newClientStream(ctx context.Context, desc *StreamDesc, cc *ClientConn, method string, opts ...CallOption) (_ ClientStream, err error) { if channelz.IsOn() { cc.incrCallsStarted() @@ -244,8 +253,11 @@ func newClientStream(ctx context.Context, desc *StreamDesc, cc *ClientConn, meth mc := &emptyMethodConfig var onCommit func() - newStream := func(ctx context.Context, done func()) (iresolver.ClientStream, error) { - return newClientStreamWithParams(ctx, desc, cc, method, mc, onCommit, done, nameResolutionDelayed, opts...) + newStream := func(ctx context.Context, filterOpts ...CallOption) (ClientStream, error) { + if filterOpts != nil { + opts = combine(opts, filterOpts) + } + return newClientStreamWithParams(ctx, desc, cc, method, mc, onCommit, nameResolutionDelayed, opts...) } rpcInfo := iresolver.RPCInfo{Context: ctx, Method: method} @@ -270,20 +282,24 @@ func newClientStream(ctx context.Context, desc *StreamDesc, cc *ClientConn, meth if rpcConfig.Interceptor != nil { rpcInfo.Context = nil ns := newStream - newStream = func(ctx context.Context, done func()) (iresolver.ClientStream, error) { - cs, err := rpcConfig.Interceptor.NewStream(ctx, rpcInfo, done, ns) - if err != nil { - return nil, toRPCErr(err) + if interceptor, ok := rpcConfig.Interceptor.(clientInterceptor); ok { + newStream = func(ctx context.Context, filterOpts ...CallOption) (ClientStream, error) { + cs, err := interceptor.NewStream(ctx, rpcInfo, ns, filterOpts...) + if err != nil { + return nil, toRPCErr(err) + } + return cs, nil } - return cs, nil + } else { + return nil, status.Errorf(codes.Internal, "invalid client interceptor type %T", rpcConfig.Interceptor) } } } - return newStream(ctx, func() {}) + return newStream(ctx) } -func newClientStreamWithParams(ctx context.Context, desc *StreamDesc, cc *ClientConn, method string, mc *serviceconfig.MethodConfig, onCommit, doneFunc func(), nameResolutionDelayed bool, opts ...CallOption) (_ iresolver.ClientStream, err error) { +func newClientStreamWithParams(ctx context.Context, desc *StreamDesc, cc *ClientConn, method string, mc *serviceconfig.MethodConfig, onCommit func(), nameResolutionDelayed bool, opts ...CallOption) (_ ClientStream, err error) { callInfo := defaultCallInfo() if mc.WaitForReady != nil { callInfo.failFast = !*mc.WaitForReady @@ -321,7 +337,6 @@ func newClientStreamWithParams(ctx context.Context, desc *StreamDesc, cc *Client Host: cc.authority, Method: method, ContentSubtype: callInfo.contentSubtype, - DoneFunc: doneFunc, Authority: callInfo.authority, } if allowed := callInfo.acceptedResponseCompressors; len(allowed) > 0 { diff --git a/vendor/google.golang.org/grpc/version.go b/vendor/google.golang.org/grpc/version.go index 53c737fee..4083c0390 100644 --- a/vendor/google.golang.org/grpc/version.go +++ b/vendor/google.golang.org/grpc/version.go @@ -19,4 +19,4 @@ package grpc // Version is the current grpc version. -const Version = "1.82.1" +const Version = "1.83.0" diff --git a/vendor/modules.txt b/vendor/modules.txt index 1d02401f0..634f7b6c0 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -514,7 +514,7 @@ google.golang.org/genproto/googleapis/api/httpbody ## explicit; go 1.25.0 google.golang.org/genproto/googleapis/rpc/errdetails google.golang.org/genproto/googleapis/rpc/status -# google.golang.org/grpc v1.82.1 +# google.golang.org/grpc v1.83.0 ## explicit; go 1.25.0 google.golang.org/grpc google.golang.org/grpc/attributes From 53b5727d893d30a5c73e5b1a9891283786e0ec44 Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Mon, 3 Aug 2026 11:49:12 +0100 Subject: [PATCH 100/182] fix(deps): update module github.com/mccutchen/go-httpbin/v2 to v2.25.0 (#6239) | datasource | package | from | to | | ---------- | ---------------------------------- | ------- | ------- | | go | github.com/mccutchen/go-httpbin/v2 | v2.24.0 | v2.25.0 | Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 +- .../go-httpbin/v2/httpbin/middleware.go | 41 +++++++++++++------ vendor/modules.txt | 2 +- 4 files changed, 32 insertions(+), 17 deletions(-) diff --git a/go.mod b/go.mod index a0a0188c7..389c595a1 100644 --- a/go.mod +++ b/go.mod @@ -31,7 +31,7 @@ require ( github.com/klauspost/compress v1.19.1 github.com/mattn/go-colorable v0.1.15 github.com/mattn/go-isatty v0.0.24 - github.com/mccutchen/go-httpbin/v2 v2.24.0 + github.com/mccutchen/go-httpbin/v2 v2.25.0 github.com/mstoykov/atlas v0.0.0-20220811071828-388f114305dd github.com/mstoykov/envconfig v1.5.0 github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c diff --git a/go.sum b/go.sum index 03f8158fc..0059fb9c5 100644 --- a/go.sum +++ b/go.sum @@ -133,8 +133,8 @@ github.com/mattn/go-colorable v0.1.15 h1:+u9SLTRGnXv73cEsnsmoZBom+dMU88B2M0aDcWy github.com/mattn/go-colorable v0.1.15/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8= github.com/mattn/go-isatty v0.0.24 h1:tGZZoVgT/KiqK1c8ocVLeDS8BSWMRd47J3Lbz7vsReI= github.com/mattn/go-isatty v0.0.24/go.mod h1:nMCL3Zebbrt45jsMDgnfIwz6ydEQApk5oEI3HqDio6A= -github.com/mccutchen/go-httpbin/v2 v2.24.0 h1:MZ5QSGVeVpg/c7ZRbIg8UVZvefeBn/NhSVTc1fCQFEQ= -github.com/mccutchen/go-httpbin/v2 v2.24.0/go.mod h1:8hkN5rHf0QvJYEovZ8u/Dudtqyj6Z5gxQaW7scQfT0Y= +github.com/mccutchen/go-httpbin/v2 v2.25.0 h1:YpPBoAIKYIyyPEwXZkEqBVIKwon02TK7CELwAkt1mLU= +github.com/mccutchen/go-httpbin/v2 v2.25.0/go.mod h1:8hkN5rHf0QvJYEovZ8u/Dudtqyj6Z5gxQaW7scQfT0Y= github.com/mstoykov/atlas v0.0.0-20220811071828-388f114305dd h1:AC3N94irbx2kWGA8f/2Ks7EQl2LxKIRQYuT9IJDwgiI= github.com/mstoykov/atlas v0.0.0-20220811071828-388f114305dd/go.mod h1:9vRHVuLCjoFfE3GT06X0spdOAO+Zzo4AMjdIwUHBvAk= github.com/mstoykov/envconfig v1.5.0 h1:E2FgWf73BQt0ddgn7aoITkQHmgwAcHup1s//MsS5/f8= diff --git a/vendor/github.com/mccutchen/go-httpbin/v2/httpbin/middleware.go b/vendor/github.com/mccutchen/go-httpbin/v2/httpbin/middleware.go index b8ad5611e..01fda3452 100644 --- a/vendor/github.com/mccutchen/go-httpbin/v2/httpbin/middleware.go +++ b/vendor/github.com/mccutchen/go-httpbin/v2/httpbin/middleware.go @@ -117,37 +117,50 @@ func observe(o Observer, h http.Handler) http.Handler { mw := &metaResponseWriter{w: w} t := time.Now() h.ServeHTTP(mw, r) - o(Result{ - Status: mw.Status(), - Method: r.Method, - URI: r.URL.RequestURI(), - Size: mw.Size(), - Duration: time.Since(t), - UserAgent: r.Header.Get("User-Agent"), - ClientIP: getClientIP(r), + o(r.Context(), Result{ + Status: mw.Status(), + Method: r.Method, + URI: r.URL.RequestURI(), + Route: r.Pattern, + Size: mw.Size(), + Duration: time.Since(t), + UserAgent: r.Header.Get("User-Agent"), + ClientIP: getClientIP(r), + RequestSize: r.ContentLength, }) }) } -// Result is the result of handling a request, used for instrumentation +// Result records the details of an incoming request and the resulting +// response, for instrumentation via an [Observer]. type Result struct { Status int Method string URI string - Size int64 Duration time.Duration UserAgent string ClientIP string + + // Response size in bytes written. TODO: consider rename to ResponseSize + // for clarity/consistency with RequestSize. + Size int64 + + // Matched net/http handler route pattern, via [Request.Pattern]: + // https://pkg.go.dev/net/http#Request + Route string + + // Request size via, incoming Content-Length header. + RequestSize int64 } // Observer is a function that will be called with the details of a handled // request, which can be used for logging, instrumentation, etc -type Observer func(result Result) +type Observer func(ctx context.Context, result Result) // StdLogObserver creates an Observer that will log each request in structured // format using the given stdlib logger func StdLogObserver(l *slog.Logger) Observer { - return func(result Result) { + return func(ctx context.Context, result Result) { logLevel := slog.LevelInfo if result.Status >= 500 { logLevel = slog.LevelError @@ -155,16 +168,18 @@ func StdLogObserver(l *slog.Logger) Observer { logLevel = slog.LevelWarn } l.LogAttrs( - context.Background(), + ctx, logLevel, fmt.Sprintf("%d %s %s %.1fms", result.Status, result.Method, result.URI, result.Duration.Seconds()*1e3), slog.Int("status", result.Status), slog.String("method", result.Method), slog.String("uri", result.URI), + slog.String("route", result.Route), slog.Int64("size_bytes", result.Size), slog.Float64("duration_ms", result.Duration.Seconds()*1e3), slog.String("user_agent", result.UserAgent), slog.String("client_ip", result.ClientIP), + slog.Int64("request_size_bytes", result.RequestSize), ) } } diff --git a/vendor/modules.txt b/vendor/modules.txt index 634f7b6c0..27b753c93 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -256,7 +256,7 @@ github.com/mattn/go-colorable # github.com/mattn/go-isatty v0.0.24 ## explicit; go 1.20 github.com/mattn/go-isatty -# github.com/mccutchen/go-httpbin/v2 v2.24.0 +# github.com/mccutchen/go-httpbin/v2 v2.25.0 ## explicit; go 1.25.0 github.com/mccutchen/go-httpbin/v2/httpbin github.com/mccutchen/go-httpbin/v2/httpbin/digest From e74f35804d630c52bc12721aaab8933506993258 Mon Sep 17 00:00:00 2001 From: jgaalen Date: Sun, 9 Aug 2026 13:11:40 +0200 Subject: [PATCH 101/182] ci: disable unnecessary scheduled workflows --- .github/workflows/browser_e2e.yml | 3 --- .github/workflows/packager.yml | 43 ------------------------------- 2 files changed, 46 deletions(-) delete mode 100644 .github/workflows/packager.yml diff --git a/.github/workflows/browser_e2e.yml b/.github/workflows/browser_e2e.yml index 3804deaa0..907f93f26 100644 --- a/.github/workflows/browser_e2e.yml +++ b/.github/workflows/browser_e2e.yml @@ -6,9 +6,6 @@ on: branches: - master pull_request: - schedule: - # At 06:00 AM UTC from Monday through Friday - - cron: '0 6 * * 1-5' defaults: run: diff --git a/.github/workflows/packager.yml b/.github/workflows/packager.yml deleted file mode 100644 index 6edec1d30..000000000 --- a/.github/workflows/packager.yml +++ /dev/null @@ -1,43 +0,0 @@ -name: k6packager -on: - # Enable manually triggering this workflow via the API or web UI - workflow_dispatch: - schedule: - - cron: '0 0 * * 0' # weekly (Sundays at 00:00) - -defaults: - run: - shell: bash - -jobs: - publish-packager: - runs-on: ubuntu-latest - env: - VERSION: 0.0.4 - DOCKER_IMAGE_ID: ghcr.io/grafana/k6packager - GITHUB_ACTOR: ${{ github.actor }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - permissions: - contents: read - id-token: write - packages: write - steps: - - name: Checkout code - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 - with: - persist-credentials: false - - name: Build - run: | - cd packaging - docker compose build packager - - name: Login to GitHub Container Registry - uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 - with: - registry: ghcr.io - username: ${{ env.GITHUB_ACTOR }} - password: ${{ env.GITHUB_TOKEN }} - - name: Publish - run: | - docker push "${DOCKER_IMAGE_ID}:latest" - docker tag "${DOCKER_IMAGE_ID}" "${DOCKER_IMAGE_ID}:${VERSION}" - docker push "${DOCKER_IMAGE_ID}:${VERSION}" From 77f1637442bedaa718b3ae72c30c2cb6c721291e Mon Sep 17 00:00:00 2001 From: Ankur Date: Mon, 10 Aug 2026 14:48:23 +0100 Subject: [PATCH 102/182] Update k6 version to 2.2.0 (#6243) --- internal/build/version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/build/version.go b/internal/build/version.go index 24427c399..0f884d142 100644 --- a/internal/build/version.go +++ b/internal/build/version.go @@ -3,4 +3,4 @@ package build // Version contains the current version of k6 // represented using Semantic Versioning expression. -const Version = "2.1.0" +const Version = "2.2.0" From 00a9a1b7f552d6bb4337278b10ae25aac0f4e666 Mon Sep 17 00:00:00 2001 From: Ankur Date: Mon, 10 Aug 2026 14:48:50 +0100 Subject: [PATCH 103/182] Release notes v2.2.0 (#6242) * Add v2.2.0 release notes * Add initial changes for release v2.2.0 * Apply suggestions from code review Co-authored-by: Ankur * Update v2.2.0 release notes Replace the template with the drafted notes covering all 73 PRs merged between v2.1.0 and the release branch tip. * Update v2.2.0 release notes Move the feature-flag PR links onto their bullets and recategorize #5631 as an enhancement, covering the headerValues() and browser traffic metric changes. * Apply suggestions from code review Co-authored-by: Ankur * Update v2.2.0 release notes Group the renovate dependency bumps into Go, Docker, and GitHub Actions lines, and squash the cloud API cleanup and provisioning follow-up entries. * Update v2.2.0 release notes Cover the newly merged dependency bumps: grpc lands on v1.83.0 and go-httpbin joins the grouped Go deps line. --- release notes/v2.2.0.md | 154 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 release notes/v2.2.0.md diff --git a/release notes/v2.2.0.md b/release notes/v2.2.0.md new file mode 100644 index 000000000..27d1d15a1 --- /dev/null +++ b/release notes/v2.2.0.md @@ -0,0 +1,154 @@ +k6 `v2.2.0` is here 🎉! This release includes: + +- `k6 cloud run --local-execution` now streams k6's logs to Grafana Cloud, so the test run's log view works for local execution too. +- `chromium.connectOverCDP()`, which connects browser tests to an already-running Chromium instance. +- `TextEncoder` and `TextDecoder` available as globals, and `WritableStream` support in `k6/experimental/streams`. +- A `k6 cloud load-zone list` command. +- Two new experimental feature flags: `merge-run-tags` and `freeze-env`. + +## Breaking changes + +There are no breaking changes in this release. + +## New features + +### `k6 cloud run --local-execution` streams logs to Grafana Cloud [#6171](https://github.com/grafana/k6/pull/6171) + +When a cloud test runs locally with `k6 cloud run --local-execution`, k6's logs now stream to the Grafana Cloud test run, so the run's log view is populated the same way it is for cloud execution. Previously, local-execution logs stayed on the machine running k6 and never reached the cloud. Work with Grafana's secrets management to safely work with secrets and redact them if they're accidentally leaked into logs are pushed. Use the new `--no-cloud-logs` flag opts out to opt out of streaming of logs when working with `--local-execution`: + +```shell +k6 cloud run --local-execution script.js +k6 cloud run --local-execution --no-cloud-logs script.js +``` + +### Connect to a running browser with `chromium.connectOverCDP()` [#6165](https://github.com/grafana/k6/pull/6165) + +The browser module can now attach to an existing Chromium-based browser over the Chrome DevTools Protocol, mirroring Playwright's `browserType.connectOverCDP()`. Pass the browser's WebSocket endpoint and k6 manages the returned browser's connection — it's auto-closed at the end of the iteration, though you can call `close()` earlier to release the connection on demand. + +```js +import { chromium } from 'k6/browser'; + +export default async function () { + const browser = await chromium.connectOverCDP('ws://localhost:9222/devtools/browser/'); + const page = await browser.newPage(); + + try { + await page.goto('https://quickpizza.grafana.com/'); + } finally { + await page.close(); + await browser.close(); + } +} +``` + +Unlike the `K6_BROWSER_WS_URL` environment variable, the endpoint is a runtime value — you can, for example, request a fresh session URL from a browser provider's API in `setup()` and connect to it from the iterations. + +### `TextEncoder` and `TextDecoder` globals [#6182](https://github.com/grafana/k6/pull/6182) + +`TextEncoder` and `TextDecoder` are now available as standard globals in both the init and VU contexts, no import required — matching how they are exposed in browsers and other JavaScript runtimes. + +```js +const encoded = new TextEncoder().encode('Hello, world!'); +const decoded = new TextDecoder().decode(encoded); +``` + +### `WritableStream` in `k6/experimental/streams` [#6132](https://github.com/grafana/k6/pull/6132) + +The experimental streams module now implements `WritableStream` and `WritableStreamDefaultWriter` following the WHATWG Streams specification, complementing the existing `ReadableStream` and paving the way for a future `TransformStream` implementation. + +```js +import { WritableStream } from 'k6/experimental/streams'; + +export default async function () { + const stream = new WritableStream({ + write(chunk) { + console.log(`wrote ${chunk}`); + }, + }); + + const writer = stream.getWriter(); + await writer.write('hello'); + await writer.close(); +} +``` + +### `k6 cloud load-zone list` command [#6142](https://github.com/grafana/k6/pull/6142) + +A new `k6 cloud load-zone list` subcommand lists the load zones — public and private — available in the configured Grafana Cloud k6 stack, mirroring the existing `k6 cloud project list` command. Output defaults to a human-readable table; pass `--json` to emit a JSON array instead. + +```console +$ k6 cloud load-zone list +Load zones for https://example.grafana.net: + +ID NAME TYPE AVAILABLE +amazon:us:ashburn Ashburn, US (Amazon) public yes +amazon:sa:cape town Cape Town, SA (Amazon) public yes +``` + +### Configurable `handleSummary()` timeout [#5854](https://github.com/grafana/k6/pull/5854) + +The time budget for the `handleSummary()` callback — previously hardcoded to 120 seconds — is now configurable through the `handleSummaryTimeout` option or the `K6_HANDLE_SUMMARY_TIMEOUT` environment variable, so long-running tests with heavy summaries no longer fail with `handleSummary() execution timed out`. Thanks, @LBaronceli! + +```js +export const options = { + handleSummaryTimeout: '5m', +}; +``` + +### New experimental feature flags: `merge-run-tags` and `freeze-env` + +Two new experimental flags join the feature-flag system introduced in v2.1.0: + +- [#5714](https://github.com/grafana/k6/pull/5714) `merge-run-tags` merges run tags per key across config layers, so `options.tags` in a script is no longer silently discarded when `--tag` or `K6_TAGS` is also used — higher-priority layers win on conflicting keys instead of replacing the whole map. Thanks, @yordis! +- [#6032](https://github.com/grafana/k6/pull/6032) `freeze-env` freezes the `__ENV` object, so modifications from script code throw a `TypeError` (in strict mode) instead of silently persisting across iterations and scenarios. Thanks, @lohitkolluri! + +```shell +k6 run --features merge-run-tags,freeze-env script.js +``` + +## UX improvements and enhancements + +- [#5631](https://github.com/grafana/k6/pull/5631) Makes the browser module's header accessors — `response.allHeaders()`, `headerValue()`, `headerValues()`, and `headersArray()` — return the raw wire headers (including `Set-Cookie` and security-related headers), correctly paired with each hop of a redirect chain instead of Chrome's provisional headers. As part of this, `headerValues()` now matches header names case-insensitively and splits repeated values on newlines rather than commas, and the `browser_data_sent`/`browser_data_received` metrics now include the raw header bytes and no longer vary run-to-run with CDP event ordering. +- [#6208](https://github.com/grafana/k6/pull/6208) Makes `k6 cloud` reject the run flags (for example, `--vus`) with an `unknown flag` error and a non-zero exit code. Previously `k6 cloud --vus 10 script.js` accepted the flags, printed the help text, and exited 0 — running tests with `k6 cloud` directly was deprecated in v2.0.0 in favor of `k6 cloud run`. +- [#6096](https://github.com/grafana/k6/pull/6096) Points the cloud secrets error at `K6_CLOUD_SECRETS_TOKEN` and `K6_CLOUD_SECRETS_ENDPOINT` when a test run is reused via `K6_CLOUD_PUSH_REF_ID` under `--local-execution`, instead of suggesting the `--local-execution` flag the user is already using. +- [#6196](https://github.com/grafana/k6/pull/6196) Adds `catch` blocks to the browser examples so a failing iteration reports the original error instead of a subsequent `page.close()` failure. Thanks, @locker95! + +## Bug fixes + +- [#6234](https://github.com/grafana/k6/pull/6234) Classifies HTTP/2 errors by message so the `error_code` metric tag stays correct when k6 is built with Go 1.27 (whose `x/net/http2` delegates to the standard library), and explicitly enables HTTP/2 negotiation on VU transports. +- [#6232](https://github.com/grafana/k6/pull/6232) Drains queued log entries in the Loki hook at shutdown so `--out loki` and cloud log streaming no longer lose the final batch, and emits a `k6 dropped N log messages` warning when the cloud log buffer overflows instead of dropping logs silently. +- [#6125](https://github.com/grafana/k6/pull/6125) Serializes the first concurrent open of a file in the caching filesystem so parallel `fs.open()` calls on the same file no longer read zero or truncated bytes. +- [#6147](https://github.com/grafana/k6/pull/6147) Fixes a data race and inconsistent request-interception state when browser routes are added or removed concurrently. Thanks, @somak2kai! +- [#6070](https://github.com/grafana/k6/pull/6070) Flushes buffered file log output once per second so recent logs aren't lost when k6 is killed before shutdown. Thanks, @rohan-patnaik! +- [#6205](https://github.com/grafana/k6/pull/6205) Stops sending an invalid `Sec-WebSocket-Protocol` header when tailing Grafana Cloud logs; spec-strict servers rejected the handshake with `websocket: bad handshake`. +- [#6200](https://github.com/grafana/k6/pull/6200) Leaves a counter's `rate` unset when the observed duration is zero, instead of computing `+Inf` and spuriously failing `rate` thresholds. Thanks, @samarth70! +- [#6195](https://github.com/grafana/k6/pull/6195) Initializes a gauge's maximum from the first sample so all-negative gauge series no longer report `max=0`. Thanks, @Solaris-star! +- [#6145](https://github.com/grafana/k6/pull/6145) Prevents the OpenTelemetry output from panicking at startup when basic auth is configured without `K6_OTEL_HEADERS`. Thanks, @lukdz! +- [#6140](https://github.com/grafana/k6/pull/6140) Stops `SharedArray` deep-freezing JS primitives, which needlessly wrapped large strings in `String` objects — cutting memory usage in the reported reproduction from roughly 1 GB to 100 MB. + +## Maintenance and internal improvements + +- [#6126](https://github.com/grafana/k6/pull/6126), [#6224](https://github.com/grafana/k6/pull/6224), [#6229](https://github.com/grafana/k6/pull/6229) Adds anonymous extension usage to the k6 usage report: a run reports the Go module path, version, and type of registry-cataloged extensions it actually uses (imported `k6/x/` modules, output extensions selected with `--out`, and `k6 x` subcommands). Private and unlisted extensions are never reported, and the existing `--no-usage-report` opt-out covers it. +- [#6183](https://github.com/grafana/k6/pull/6183), [#6218](https://github.com/grafana/k6/pull/6218) Updates Sobek and regexp2, making `WeakMap`/`WeakSet` entries garbage-collectable, improving string and typed-array correctness and performance, and bounding regular-expression backtracking memory. +- [#6169](https://github.com/grafana/k6/pull/6169), [#6230](https://github.com/grafana/k6/pull/6230) Migrates `k6 cloud run --local-execution` from the legacy v1 cloud API to the v6 and provisioning APIs, and quietens its status polling logs. User-facing behavior is unchanged, and `k6 run --out cloud` stays on the legacy API. +- [#6170](https://github.com/grafana/k6/pull/6170) Lets an orchestration service that provisioned a test run itself supply the scoped push credentials to `k6 cloud run --local-execution` via the `K6_CLOUD_METRICS_PUSH_URL` and `K6_CLOUD_TEST_RUN_TOKEN` environment variables. +- [#6151](https://github.com/grafana/k6/pull/6151), [#6152](https://github.com/grafana/k6/pull/6152), [#6173](https://github.com/grafana/k6/pull/6173) Updates `github.com/grafana/k6-cloud-openapi-client-go`, consuming the upstream retry body-reset fix (dropping the k6-side workaround) and the int64 resource-ID widening. +- [#6149](https://github.com/grafana/k6/pull/6149), [#6159](https://github.com/grafana/k6/pull/6159) Cleans up the internal cloud API clients, removing the dead v6 config file and sharing the 401/403 error classification between the v1 and v6 clients. +- [#6144](https://github.com/grafana/k6/pull/6144) Retains and calls the regular-duration context cancel function in executors instead of discarding it. Thanks, @the-onewho-knocks! +- [#6141](https://github.com/grafana/k6/pull/6141) Adds unit tests for the browser mouse options. Thanks, @hyuraku! +- [#6129](https://github.com/grafana/k6/pull/6129) Fixes documentation typos. Thanks, @Martonveghcode! +- [#6203](https://github.com/grafana/k6/pull/6203) Fixes the xk6 CI job for fork PRs after the `go.k6.io/k6/v2` module move. +- [#6112](https://github.com/grafana/k6/pull/6112) Centralizes the CI Go versions into `.github/go-versions.env`. +- [#6104](https://github.com/grafana/k6/pull/6104) Skips the code CI jobs for docs-only and release-notes-only PRs. +- [#6103](https://github.com/grafana/k6/pull/6103) Adds the feature brief process to the contributing docs. +- [#6075](https://github.com/grafana/k6/pull/6075) Prepares the workflows for `get-vault-secrets` v2. +- [#6134](https://github.com/grafana/k6/pull/6134) Updates the Go toolchain directive to 1.25.12 [security]. +- [#6191](https://github.com/grafana/k6/pull/6191), [#6192](https://github.com/grafana/k6/pull/6192), [#6240](https://github.com/grafana/k6/pull/6240) Updates `google.golang.org/grpc` to `v1.83.0` [security]. +- [#6185](https://github.com/grafana/k6/pull/6185), [#6186](https://github.com/grafana/k6/pull/6186) Updates `golang.org/x/net` to `v0.56.0` and `golang.org/x/text` to `v0.39.0` in the gRPC server example [security]. +- [#6097](https://github.com/grafana/k6/pull/6097), [#6212](https://github.com/grafana/k6/pull/6212), [#6156](https://github.com/grafana/k6/pull/6156), [#6213](https://github.com/grafana/k6/pull/6213), [#6176](https://github.com/grafana/k6/pull/6176), [#6214](https://github.com/grafana/k6/pull/6214), [#6083](https://github.com/grafana/k6/pull/6083), [#6177](https://github.com/grafana/k6/pull/6177), [#6239](https://github.com/grafana/k6/pull/6239), [#6216](https://github.com/grafana/k6/pull/6216), [#6215](https://github.com/grafana/k6/pull/6215), [#6175](https://github.com/grafana/k6/pull/6175), [#6174](https://github.com/grafana/k6/pull/6174), [#6082](https://github.com/grafana/k6/pull/6082) Updates Go dependencies, including the `golang.org/x` packages, `klauspost/compress`, `mattn/go-isatty`, `mccutchen/go-httpbin`, the OpenTelemetry and Prometheus protobufs, `andybalholm/brotli`, and `evanw/esbuild`. +- [#6155](https://github.com/grafana/k6/pull/6155), [#6080](https://github.com/grafana/k6/pull/6080), [#6098](https://github.com/grafana/k6/pull/6098), [#6114](https://github.com/grafana/k6/pull/6114) Updates the Docker base images (Go to `1.26.5`, Alpine to `3.24.1`, Debian to `trixie-20260623`). +- [#6158](https://github.com/grafana/k6/pull/6158), [#6119](https://github.com/grafana/k6/pull/6119), [#6120](https://github.com/grafana/k6/pull/6120), [#6121](https://github.com/grafana/k6/pull/6121), [#6122](https://github.com/grafana/k6/pull/6122), [#6076](https://github.com/grafana/k6/pull/6076), [#6123](https://github.com/grafana/k6/pull/6123), [#6124](https://github.com/grafana/k6/pull/6124) Updates the GitHub Actions dependencies, including `actions/checkout` to `v7`, `golangci/golangci-lint-action` to `v9.3.0`, and the `grafana/shared-workflows` actions. + +## External contributors + +A huge thank you to the external contributors who helped during this release: @LBaronceli, @yordis, @lohitkolluri, @locker95, @rohan-patnaik, @somak2kai, @samarth70, @Solaris-star, @lukdz, @the-onewho-knocks, @hyuraku, and @Martonveghcode! 🙏 From fe07b955036144efd56a43594f5cca017c38766a Mon Sep 17 00:00:00 2001 From: Ankur Date: Mon, 10 Aug 2026 15:36:03 +0100 Subject: [PATCH 104/182] Add bzip2 to the k6packager image (#6270) debian:13 (trixie) dropped bzip2 from its base image, so create-deb-repo.sh failed with "bzip2: command not found", breaking the publish-packages job of the v2.2.0 release. --- packaging/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/Dockerfile b/packaging/Dockerfile index 88e8a3ce8..90a8cfd0d 100644 --- a/packaging/Dockerfile +++ b/packaging/Dockerfile @@ -5,7 +5,7 @@ LABEL maintainer="k6 Developers " ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update -y && \ - apt-get install -y apt-utils createrepo-c curl git gnupg2 s3cmd unzip rpm + apt-get install -y apt-utils bzip2 createrepo-c curl git gnupg2 s3cmd unzip rpm # Download awscli, check GPG signature and install. COPY ./awscli-key.gpg . From 35df11a2413e698341a60e7e34ef2e0fbdb1907f Mon Sep 17 00:00:00 2001 From: Inanc Gumus Date: Mon, 10 Aug 2026 12:41:46 -0400 Subject: [PATCH 105/182] Enable Renovate auto-merge (#6246) --- .github/workflows/auto-approve-renovate.yml | 14 ++++++++++++++ renovate.json | 3 ++- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/auto-approve-renovate.yml diff --git a/.github/workflows/auto-approve-renovate.yml b/.github/workflows/auto-approve-renovate.yml new file mode 100644 index 000000000..ef02e15f5 --- /dev/null +++ b/.github/workflows/auto-approve-renovate.yml @@ -0,0 +1,14 @@ +name: Auto-approve Renovate +on: + schedule: + - cron: '1 * * * *' + workflow_dispatch: +permissions: + contents: read + pull-requests: read + checks: read + statuses: read + id-token: write +jobs: + approve: + uses: grafana/k6-ci/.github/workflows/auto-approve-renovate.yml@9477260e6838640d56c28aa95bcbf9a884ab21f3 # k6-ci#44 merge commit diff --git a/renovate.json b/renovate.json index cd45ead1a..f393c000a 100644 --- a/renovate.json +++ b/renovate.json @@ -2,7 +2,8 @@ "$schema": "https://docs.renovatebot.com/renovate-schema.json", "extends": [ "github>grafana/grafana-renovate-config//presets/k6/k6-engine-base.json", - "schedule:weekly" + "schedule:weekly", + "github>grafana/grafana-renovate-config//presets/k6/k6-engine-automerge.json" ], "ignorePaths": [ "**/vendor/**", From 55f774633628acda4a3df307189d617b82f66210 Mon Sep 17 00:00:00 2001 From: Andrey Slotin Date: Mon, 10 Aug 2026 19:50:09 +0200 Subject: [PATCH 106/182] Update external contributors section for release notes (#6256) Add @janHildebrandt98 to the external contributors filter query. --- .github/ISSUE_TEMPLATE/release.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/release.md b/.github/ISSUE_TEMPLATE/release.md index 50836768f..7383abf8a 100644 --- a/.github/ISSUE_TEMPLATE/release.md +++ b/.github/ISSUE_TEMPLATE/release.md @@ -34,7 +34,7 @@ labels: ["release"] - [ ] Ensure all PRs in the `k6` repository, part of the current [milestone](https://github.com/grafana/k6/milestones), have been merged. - [ ] Open a PR with the release notes for the new version - [ ] Ask teams that might have contributed to the release to contribute their notes and review the existing ones. - - [ ] Remember to mention and thank [external contributors](https://github.com/search?q=user%3Agrafana+repo%3Ak6+milestone%3A%22v2.1.0%22+-author%3Amstoykov+-author%3Aoleiade+-author%3Acodebien+-author%3Aandrewslotin+-author%3Ajoanlopez+-author%3Aankur22+-author%3Ainancgumus+-author%3Aszkiba+-author%3AAgnesToulet+-author%3Adependabot%5Bbot%5D+-author%3Arenovate-sh-app%5Bbot%5D&type=pullrequests). (**<- Update the query with the correct milestone version**). + - [ ] Remember to mention and thank [external contributors](https://github.com/search?q=user%3Agrafana+repo%3Ak6+milestone%3A%22v2.3.0%22+-author%3Amstoykov+-author%3Aoleiade+-author%3Acodebien+-author%3Aandrewslotin+-author%3Ajoanlopez+-author%3Aankur22+-author%3Ainancgumus+-author%3Aszkiba+-author%3AAgnesToulet+-author%3Adependabot%5Bbot%5D+-author%3Arenovate-sh-app%5Bbot%5D+-author%3AjanHildebrandt98&type=pullrequests). (**<- Update the query with the correct milestone version**). - [ ] Share the release notes PR with the k6 open-source teams. Request contributions from all affected teams and any other stakeholders involved in the new release. - [ ] Open a separate PR for bumping [the k6 Go project's version](https://github.com/grafana/k6/blob/master/internal/build/version.go#L6). - [ ] Open a PR in the `DefinitelyTyped/DefinitelyTyped` repository using the release branch created in the grafana/k6-DefinitelyTyped fork to update the k6 type definitions for the new release. From 12c1d759c84bacb4074cdeb1044b83ffcc8c4fc5 Mon Sep 17 00:00:00 2001 From: Mihail Stoykov <312246+mstoykov@users.noreply.github.com> Date: Tue, 11 Aug 2026 12:58:21 +0300 Subject: [PATCH 107/182] chore: run CI on v1.x (#6245) --- .github/workflows/browser_e2e.yml | 1 + .github/workflows/build.yml | 1 + .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/summary-code-generation.yml | 1 + .github/workflows/tc39.yml | 1 + .github/workflows/test-browser.yml | 1 + .github/workflows/test.yml | 1 + .github/workflows/xk6.yml | 1 + 8 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/browser_e2e.yml b/.github/workflows/browser_e2e.yml index 49b38442a..e6f176e8c 100644 --- a/.github/workflows/browser_e2e.yml +++ b/.github/workflows/browser_e2e.yml @@ -5,6 +5,7 @@ on: push: branches: - master + - v1.x pull_request: paths-ignore: - 'docs/**' diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 94bf6dd24..ead766941 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,6 +12,7 @@ on: push: branches: - master + - v1.x tags: - v* pull_request: diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 560e1a417..69f8eb20c 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -2,7 +2,7 @@ name: "CodeQL" on: push: - branches: [ master ] + branches: [ master, v1.x ] permissions: contents: read diff --git a/.github/workflows/summary-code-generation.yml b/.github/workflows/summary-code-generation.yml index a487f1579..4bbd7fe29 100644 --- a/.github/workflows/summary-code-generation.yml +++ b/.github/workflows/summary-code-generation.yml @@ -4,6 +4,7 @@ on: push: branches: - master + - v1.x pull_request: defaults: diff --git a/.github/workflows/tc39.yml b/.github/workflows/tc39.yml index 4546da6a7..90505d7df 100644 --- a/.github/workflows/tc39.yml +++ b/.github/workflows/tc39.yml @@ -4,6 +4,7 @@ on: push: branches: - master + - v1.x pull_request: paths: - 'js/**' diff --git a/.github/workflows/test-browser.yml b/.github/workflows/test-browser.yml index a72e9d23f..1d5fda7ca 100644 --- a/.github/workflows/test-browser.yml +++ b/.github/workflows/test-browser.yml @@ -3,6 +3,7 @@ on: push: branches: - master + - v.x pull_request: paths-ignore: - 'docs/**' diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c1a3adc43..00030166e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,6 +3,7 @@ on: push: branches: - master + - v1.x pull_request: paths-ignore: - 'docs/**' diff --git a/.github/workflows/xk6.yml b/.github/workflows/xk6.yml index 40f5b7e7f..61c9534dc 100644 --- a/.github/workflows/xk6.yml +++ b/.github/workflows/xk6.yml @@ -5,6 +5,7 @@ on: push: branches: - master + - v1.x pull_request: paths-ignore: - 'docs/**' From ddc5f32e9c7c4f0dd979dbbfc94e3064bf375d57 Mon Sep 17 00:00:00 2001 From: adarshsm Date: Wed, 12 Aug 2026 17:08:06 +0530 Subject: [PATCH 108/182] fix(browser): use filepath.ToSlash for URL paths in file persister (#6235) filepath.Join produces backslashes on Windows. When those paths end up in a JSON template string via fmt.Sprintf, sequences like \s and \p are invalid JSON escape sequences and cause assert.JSONEq to fail. Wrap filepath.Join with filepath.ToSlash to normalize separators to / before marshaling. Re-enables TestRemoteFilePersister on Windows. Closes #902 --- internal/js/modules/k6/browser/storage/file_persister.go | 2 +- .../js/modules/k6/browser/storage/file_persister_test.go | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/internal/js/modules/k6/browser/storage/file_persister.go b/internal/js/modules/k6/browser/storage/file_persister.go index aad36d5da..9c668e351 100644 --- a/internal/js/modules/k6/browser/storage/file_persister.go +++ b/internal/js/modules/k6/browser/storage/file_persister.go @@ -169,7 +169,7 @@ func buildPresignedRequestBody(basePath, path string) ([]byte, error) { Name string `json:"name"` }{ { - Name: filepath.Join(basePath, path), + Name: filepath.ToSlash(filepath.Join(basePath, path)), }, }, } diff --git a/internal/js/modules/k6/browser/storage/file_persister_test.go b/internal/js/modules/k6/browser/storage/file_persister_test.go index cfee00518..53ea54d92 100644 --- a/internal/js/modules/k6/browser/storage/file_persister_test.go +++ b/internal/js/modules/k6/browser/storage/file_persister_test.go @@ -7,8 +7,8 @@ import ( "net/http" "net/http/httptest" "os" + "path" "path/filepath" - "runtime" "strings" "testing" @@ -82,11 +82,6 @@ func TestLocalFilePersister(t *testing.T) { func TestRemoteFilePersister(t *testing.T) { t.Parallel() - if runtime.GOOS == "windows" { - t.Skip("not supported on windows for now") - // actual problem is that the paths used are with reverse slash even when they get to be inside JSON - // which leads to them being parsed as escepe codes when they shouldn't - } const ( basePath = "screenshots" @@ -239,7 +234,7 @@ func TestRemoteFilePersister(t *testing.T) { // Does the response match the expected format? wantPresignedURLBody := fmt.Sprintf( tt.wantPresignedURLBody, - filepath.Join(basePath, tt.path), + path.Join(basePath, tt.path), ) assert.JSONEq(t, wantPresignedURLBody, string(bb)) From 93accf6570dcd306ca5e99cc44c393ee3797761b Mon Sep 17 00:00:00 2001 From: djedi-knight Date: Thu, 13 Aug 2026 09:18:15 -0400 Subject: [PATCH 109/182] Fix urlencoded form bodies encoding null as and objects as map[...] (#6238) When a JS object is passed as an HTTP request body, k6 auto-encodes it as application/x-www-form-urlencoded. The encoder formatted every value with fmt.Sprintf("%v", ...), so a JavaScript null/undefined became the literal string "" and a nested object/array became "map[...]"/"[...]". formatFormVal now encodes null and undefined as an empty value (e.g. "key="), matching Node's querystring and jQuery.param, and logs a warning for nested objects/arrays (which cannot be represented in a flat urlencoded body) instead of emitting Go's map[...] representation. Behavior stays backward-compatible: requests still succeed. Adds tests covering null, undefined, nested objects, and arrays. Closes #1185 --- js/modules/k6/http/request.go | 31 +++++++++++++- js/modules/k6/http/request_test.go | 66 ++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+), 2 deletions(-) diff --git a/js/modules/k6/http/request.go b/js/modules/k6/http/request.go index a7947bda3..454281b47 100644 --- a/js/modules/k6/http/request.go +++ b/js/modules/k6/http/request.go @@ -178,9 +178,36 @@ func (c *Client) parseRequest( result.ResponseType = httpext.ResponseTypeText } + // formatFormVal converts a single value from a JS object body into its + // application/x-www-form-urlencoded string representation. + // + // JavaScript null and undefined are both exported to a nil Go value; they + // are encoded as an empty value (e.g. "key=") instead of Go's default + // "" string. This matches how Node's querystring and jQuery.param + // serialize null/undefined. See https://github.com/grafana/k6/issues/1185. + // + // Nested objects and arrays-of-objects cannot be represented in a flat + // urlencoded form body. Rather than emitting Go's "map[...]"/"[...]" + // representation, they are encoded as an empty value and a warning is + // logged. Users who need to send structured data should serialize it + // explicitly, e.g. with JSON.stringify(). + // See https://github.com/grafana/k6/issues/2369. formatFormVal := func(v any) string { - // TODO: handle/warn about unsupported/nested values - return fmt.Sprintf("%v", v) + switch val := v.(type) { + case nil: + return "" + case string: + return val + case map[string]any, []any: + state.Logger.Warnf( + "cannot urlencode a nested %T value in a request form body; encoding it "+ + "as an empty value, use JSON.stringify() to send structured data", + val, + ) + return "" + default: + return fmt.Sprintf("%v", val) + } } handleObjectBody := func(data map[string]any) error { diff --git a/js/modules/k6/http/request_test.go b/js/modules/k6/http/request_test.go index d282a05e5..3f03e284c 100644 --- a/js/modules/k6/http/request_test.go +++ b/js/modules/k6/http/request_test.go @@ -1314,6 +1314,72 @@ func TestRequest(t *testing.T) { }) } +// TestRequestFormBodyEncoding verifies how JS object bodies that get +// auto-encoded as application/x-www-form-urlencoded handle null/undefined and +// nested values. See https://github.com/grafana/k6/issues/1185. +func TestRequestFormBodyEncoding(t *testing.T) { + t.Parallel() + ts := newTestCase(t) + tb := ts.tb + rt := ts.runtime.VU.Runtime() + sr := tb.Replacer.Replace + + // url.Values.Encode sorts keys alphabetically and preserves slice order + // within a key, so the encoded body is deterministic and can be asserted + // on directly. + t.Run("null and undefined are encoded as empty values", func(t *testing.T) { + ts.hook.Reset() + _, err := rt.RunString(sr(` + var res = http.post("HTTPBIN_URL/post", {data: "something", another: null, missing: undefined}); + if (res.status != 200) { throw new Error("wrong status: " + res.status); } + if (res.request.body !== "another=&data=something&missing=") { + throw new Error("wrong body: " + res.request.body); + } + `)) + require.NoError(t, err) + assert.Nil(t, ts.hook.LastEntry()) + }) + + t.Run("null inside an array is encoded as empty", func(t *testing.T) { + ts.hook.Reset() + _, err := rt.RunString(sr(` + var res = http.post("HTTPBIN_URL/post", {c: ["one", null]}); + if (res.status != 200) { throw new Error("wrong status: " + res.status); } + if (res.request.body !== "c=one&c=") { throw new Error("wrong body: " + res.request.body); } + `)) + require.NoError(t, err) + assert.Nil(t, ts.hook.LastEntry()) + }) + + t.Run("nested objects are not encoded as map[...] and log a warning", func(t *testing.T) { + ts.hook.Reset() + _, err := rt.RunString(sr(` + var res = http.post("HTTPBIN_URL/post", {a: "x", nested: {inner: 1}}); + if (res.status != 200) { throw new Error("wrong status: " + res.status); } + if (res.request.body !== "a=x&nested=") { throw new Error("wrong body: " + res.request.body); } + `)) + require.NoError(t, err) + logEntry := ts.hook.LastEntry() + require.NotNil(t, logEntry) + assert.Equal(t, logrus.WarnLevel, logEntry.Level) + assert.Contains(t, logEntry.Message, "cannot urlencode a nested") + }) + + t.Run("arrays of objects are not encoded as map[...] and log a warning", func(t *testing.T) { + ts.hook.Reset() + _, err := rt.RunString(sr(` + var res = http.post("HTTPBIN_URL/post", {items: [{x: 1}, {y: 2}]}); + if (res.status != 200) { throw new Error("wrong status: " + res.status); } + if (res.request.body !== "items=&items=") { throw new Error("wrong body: " + res.request.body); } + `)) + require.NoError(t, err) + logEntry := ts.hook.LastEntry() + require.NotNil(t, logEntry) + assert.Equal(t, logrus.WarnLevel, logEntry.Level) + assert.Contains(t, logEntry.Message, "cannot urlencode a nested") + }) +} + func TestRequestCancellation(t *testing.T) { t.Parallel() ts := newTestCase(t) From 3d8bf3e10747f9994a33a8c070f2231390eb09e8 Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Mon, 17 Aug 2026 09:02:35 +0000 Subject: [PATCH 110/182] fix(deps): update golangx (#6265) | datasource | package | from | to | | ---------- | -------------------------------------- | ---------------------------------- | ---------------------------------- | | go | golang.org/x/crypto | v0.54.0 | v0.55.0 | | go | golang.org/x/crypto/x509roots/fallback | v0.0.0-20260723152544-d701c51f7e4e | v0.0.0-20260811175631-f44d03d253a1 | | go | golang.org/x/net | v0.57.0 | v0.58.0 | Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> --- go.mod | 8 +-- go.sum | 16 +++--- vendor/golang.org/x/crypto/ocsp/ocsp.go | 17 +++++-- vendor/golang.org/x/net/http2/hpack/encode.go | 1 - vendor/golang.org/x/net/http2/hpack/hpack.go | 1 - vendor/golang.org/x/net/http2/hpack/tables.go | 51 ++++++++++++++----- .../golang.org/x/net/http2/transport_wrap.go | 49 +++++++++++------- vendor/modules.txt | 8 +-- 8 files changed, 96 insertions(+), 55 deletions(-) diff --git a/go.mod b/go.mod index 389c595a1..bbdaea863 100644 --- a/go.mod +++ b/go.mod @@ -57,9 +57,9 @@ require ( go.opentelemetry.io/otel/trace v1.44.0 go.opentelemetry.io/proto/otlp v1.11.0 go.uber.org/goleak v1.3.0 - golang.org/x/crypto v0.54.0 - golang.org/x/crypto/x509roots/fallback v0.0.0-20260723152544-d701c51f7e4e - golang.org/x/net v0.57.0 + golang.org/x/crypto v0.55.0 + golang.org/x/crypto/x509roots/fallback v0.0.0-20260811175631-f44d03d253a1 + golang.org/x/net v0.58.0 golang.org/x/sync v0.22.0 golang.org/x/term v0.45.0 golang.org/x/time v0.15.0 @@ -96,7 +96,7 @@ require ( github.com/tidwall/pretty v1.2.1 // indirect go.opentelemetry.io/auto/sdk v1.2.1 // indirect golang.org/x/sys v0.47.0 // indirect - golang.org/x/text v0.40.0 // indirect + golang.org/x/text v0.41.0 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20260720211330-0afa2a65878a // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20260720211330-0afa2a65878a // indirect gopkg.in/cenkalti/backoff.v1 v1.1.0 // indirect diff --git a/go.sum b/go.sum index 0059fb9c5..23ad7dbf0 100644 --- a/go.sum +++ b/go.sum @@ -252,10 +252,10 @@ golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliY golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= -golang.org/x/crypto v0.54.0 h1:YLIA59K4fiNzHzjnZt2tUJQjQtUWfWbeHBqKtk3eScw= -golang.org/x/crypto v0.54.0/go.mod h1:KWL8ny2AZdGR2cWmzeHrp2azQPGogOv+HeQaVEXC2dk= -golang.org/x/crypto/x509roots/fallback v0.0.0-20260723152544-d701c51f7e4e h1:9TjMDOuGaMMTP5f7GXeHeA0JvFqGmv4DYRIWkzoePGI= -golang.org/x/crypto/x509roots/fallback v0.0.0-20260723152544-d701c51f7e4e/go.mod h1:+UoQFNBq2p2wO+Q6ddVtYc25GZ6VNdOMyyrd4nrqrKs= +golang.org/x/crypto v0.55.0 h1:+KWHjbgOaAQ66dh/YlkZKHlz9ZUlq61AFirAR9ntP8M= +golang.org/x/crypto v0.55.0/go.mod h1:uq0V9dE/fzQuJtbnL+2EhWOE63vo164FY8xqEnV9xis= +golang.org/x/crypto/x509roots/fallback v0.0.0-20260811175631-f44d03d253a1 h1:0LcVce0NOnpZF3lueZ6uAorLcATPGDmPolJYvQBE0ic= +golang.org/x/crypto/x509roots/fallback v0.0.0-20260811175631-f44d03d253a1/go.mod h1:+UoQFNBq2p2wO+Q6ddVtYc25GZ6VNdOMyyrd4nrqrKs= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= @@ -287,8 +287,8 @@ golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4= -golang.org/x/net v0.57.0 h1:K5+3DljvIuDG9/Jv9rvyMywYNFCQ9RSUY6OOTTkT+tE= -golang.org/x/net v0.57.0/go.mod h1:KpXc8iv+r3XplLAG/f7Jsf9RPszJzdR0f58q9vGOuEU= +golang.org/x/net v0.58.0 h1:ynWG7rqYi4ccpTEuPZ2QGWHktVEM9DMCj9yzDE0Q7To= +golang.org/x/net v0.58.0/go.mod h1:YwCddHnFlT7eLQqVprV19OnhLGtc5xOKgE0RyqgfWAU= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -350,8 +350,8 @@ golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= -golang.org/x/text v0.40.0 h1:Ub2Z6/xjgF1WrYQz2nuITOEegKFtiIy+rieRJ5lHZKs= -golang.org/x/text v0.40.0/go.mod h1:hpnzDAfGV753zIKo+wk3u1bVKCGPbrnF7+7LBF/UHVY= +golang.org/x/text v0.41.0 h1:vz/seA0lnX87Othu2f/0L24RcgrXD9/YFTSuGjj3rH8= +golang.org/x/text v0.41.0/go.mod h1:jvf1O8ajNzZqhSrQBPbutR/EB83Cc0CFrezNQIwbb5M= golang.org/x/time v0.15.0 h1:bbrp8t3bGUeFOx08pvsMYRTCVSMk89u4tKbNOZbp88U= golang.org/x/time v0.15.0/go.mod h1:Y4YMaQmXwGQZoFaVFk4YpCt4FLQMYKZe9oeV/f4MSno= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/vendor/golang.org/x/crypto/ocsp/ocsp.go b/vendor/golang.org/x/crypto/ocsp/ocsp.go index e6c645e7c..23c39e737 100644 --- a/vendor/golang.org/x/crypto/ocsp/ocsp.go +++ b/vendor/golang.org/x/crypto/ocsp/ocsp.go @@ -85,7 +85,8 @@ type certID struct { // https://tools.ietf.org/html/rfc2560#section-4.1.1 type ocspRequest struct { - TBSRequest tbsRequest + TBSRequest tbsRequest + OptionalSignature asn1.RawValue `asn1:"explicit,tag:0,optional"` } type tbsRequest struct { @@ -321,10 +322,10 @@ type Request struct { func (req *Request) Marshal() ([]byte, error) { hashAlg := getOIDFromHashAlgorithm(req.HashAlgorithm) if hashAlg == nil { - return nil, errors.New("Unknown hash algorithm") + return nil, errors.New("unknown hash algorithm") } return asn1.Marshal(ocspRequest{ - tbsRequest{ + TBSRequest: tbsRequest{ Version: 0, RequestList: []request{ { @@ -418,8 +419,10 @@ func (p ParseError) Error() string { } // ParseRequest parses an OCSP request in DER form. It only supports -// requests for a single certificate. Signed requests are not supported. -// If a request includes a signature, it will result in a ParseError. +// requests for a single certificate identifier. If a request includes +// multiple certificate identifiers, only the first will be included in +// the parsed Request. Signed requests are not supported. If a request +// includes a signature, it will result in a ParseError. func ParseRequest(bytes []byte) (*Request, error) { var req ocspRequest rest, err := asn1.Unmarshal(bytes, &req) @@ -430,6 +433,10 @@ func ParseRequest(bytes []byte) (*Request, error) { return nil, ParseError("trailing data in OCSP request") } + if len(req.OptionalSignature.FullBytes) > 0 { + return nil, ParseError("signed OCSP requests are not supported") + } + if len(req.TBSRequest.RequestList) == 0 { return nil, ParseError("OCSP request contains no request body") } diff --git a/vendor/golang.org/x/net/http2/hpack/encode.go b/vendor/golang.org/x/net/http2/hpack/encode.go index 46219da2b..e6d0c265a 100644 --- a/vendor/golang.org/x/net/http2/hpack/encode.go +++ b/vendor/golang.org/x/net/http2/hpack/encode.go @@ -39,7 +39,6 @@ func NewEncoder(w io.Writer) *Encoder { tableSizeUpdate: false, w: w, } - e.dynTab.table.init() e.dynTab.setMaxSize(initialHeaderTableSize) return e } diff --git a/vendor/golang.org/x/net/http2/hpack/hpack.go b/vendor/golang.org/x/net/http2/hpack/hpack.go index 7a1d97669..ecd3eeca9 100644 --- a/vendor/golang.org/x/net/http2/hpack/hpack.go +++ b/vendor/golang.org/x/net/http2/hpack/hpack.go @@ -105,7 +105,6 @@ func NewDecoder(maxDynamicTableSize uint32, emitFunc func(f HeaderField)) *Decod emitEnabled: true, firstField: true, } - d.dynTab.table.init() d.dynTab.allowedMaxSize = maxDynamicTableSize d.dynTab.setMaxSize(maxDynamicTableSize) return d diff --git a/vendor/golang.org/x/net/http2/hpack/tables.go b/vendor/golang.org/x/net/http2/hpack/tables.go index 8cbdf3f01..3bd7eb753 100644 --- a/vendor/golang.org/x/net/http2/hpack/tables.go +++ b/vendor/golang.org/x/net/http2/hpack/tables.go @@ -31,10 +31,18 @@ type headerFieldTable struct { // byName maps a HeaderField name to the unique id of the newest entry with // the same name. See above for a definition of "unique id". + // + // byName and byNameValue are used only by search, which is only called + // for tables used by encoders. For tables used only by decoders, the + // maps are never built, as a memory optimization for servers with many + // mostly-idle connections, each pinning a dynamic table. The maps are + // built lazily by the first search call and are nil until then. The two + // maps are always both nil or both non-nil. byName map[string]uint64 // byNameValue maps a HeaderField name/value pair to the unique id of the newest // entry with the same name and value. See above for a definition of "unique id". + // See byName for when this map is non-nil. byNameValue map[pairNameValue]uint64 } @@ -42,9 +50,17 @@ type pairNameValue struct { name, value string } -func (t *headerFieldTable) init() { - t.byName = make(map[string]uint64) - t.byNameValue = make(map[pairNameValue]uint64) +// buildMaps initializes byName and byNameValue from ents. +func (t *headerFieldTable) buildMaps() { + t.byName = make(map[string]uint64, len(t.ents)) + t.byNameValue = make(map[pairNameValue]uint64, len(t.ents)) + for k, f := range t.ents { + // Map to the newest matching entry: later (newer) entries + // overwrite earlier ones, matching addEntry's behavior. + id := t.evictCount + uint64(k) + 1 + t.byName[f.Name] = id + t.byNameValue[pairNameValue{f.Name, f.Value}] = id + } } // len reports the number of entries in the table. @@ -54,9 +70,11 @@ func (t *headerFieldTable) len() int { // addEntry adds a new entry. func (t *headerFieldTable) addEntry(f HeaderField) { - id := uint64(t.len()) + t.evictCount + 1 - t.byName[f.Name] = id - t.byNameValue[pairNameValue{f.Name, f.Value}] = id + if t.byName != nil { + id := uint64(t.len()) + t.evictCount + 1 + t.byName[f.Name] = id + t.byNameValue[pairNameValue{f.Name, f.Value}] = id + } t.ents = append(t.ents, f) } @@ -65,14 +83,16 @@ func (t *headerFieldTable) evictOldest(n int) { if n > t.len() { panic(fmt.Sprintf("evictOldest(%v) on table with %v entries", n, t.len())) } - for k := 0; k < n; k++ { - f := t.ents[k] - id := t.evictCount + uint64(k) + 1 - if t.byName[f.Name] == id { - delete(t.byName, f.Name) - } - if p := (pairNameValue{f.Name, f.Value}); t.byNameValue[p] == id { - delete(t.byNameValue, p) + if t.byName != nil { + for k := 0; k < n; k++ { + f := t.ents[k] + id := t.evictCount + uint64(k) + 1 + if t.byName[f.Name] == id { + delete(t.byName, f.Name) + } + if p := (pairNameValue{f.Name, f.Value}); t.byNameValue[p] == id { + delete(t.byNameValue, p) + } } } copy(t.ents, t.ents[n:]) @@ -100,6 +120,9 @@ func (t *headerFieldTable) evictOldest(n int) { // // See Section 2.3.3. func (t *headerFieldTable) search(f HeaderField) (i uint64, nameValueMatch bool) { + if t.byName == nil { + t.buildMaps() + } if !f.Sensitive { if id := t.byNameValue[pairNameValue{f.Name, f.Value}]; id != 0 { return t.idToIndex(id), true diff --git a/vendor/golang.org/x/net/http2/transport_wrap.go b/vendor/golang.org/x/net/http2/transport_wrap.go index 534e77ab9..741fb9706 100644 --- a/vendor/golang.org/x/net/http2/transport_wrap.go +++ b/vendor/golang.org/x/net/http2/transport_wrap.go @@ -237,32 +237,40 @@ type ClientConn struct { } func (cc *ClientConn) roundTrip(req *http.Request) (*http.Response, error) { - err := func() error { + haveReservation, err := func() (bool, error) { cc.mu.Lock() defer cc.mu.Unlock() if cc.doNotReuse { - return errClientConnUnusable - } - cc.roundTrips++ - if cc.reserved > 0 { - // We've already reserved a concurrency slot for this request. - cc.reserved-- - } else if cc.cc.Reserve() != nil { - // We don't seem to have an available concurrency slot, - // so bump the pending count (requests waiting for a slot). - cc.pending++ + return false, errClientConnUnusable } + // ClientConn.Shutdown will not shut down the conn while // cc.starting > 0 or cc.cc.InFlight() > 0. // // The starting state covers the gap between us deciding to // start sending the request, and actually sending it. cc.starting++ - return nil + + cc.roundTrips++ + if cc.reserved == 0 { + // We do not have a concurrency slot reserved for this request. + return false, nil + } + cc.reserved-- + return true, nil }() if err != nil { return nil, err } + // If we have no reservation, try to acquire one. + // (This must be done without cc.mu held, since Reserve may call back to the state hook.) + if !haveReservation && cc.cc.Reserve() != nil { + // We could not acquire a concurrency slot, so bump the pending count + // (requests waiting for a slot). + cc.mu.Lock() + cc.pending++ + cc.mu.Unlock() + } resp, err := cc.cc.RoundTrip(req) cc.mu.Lock() cc.starting-- @@ -293,16 +301,21 @@ func (cc *ClientConn) ping(ctx context.Context) error { } func (cc *ClientConn) reserveNewRequest() bool { + if err := cc.cc.Reserve(); err != nil { + return false + } + reserved := true cc.mu.Lock() - defer cc.mu.Unlock() if cc.doNotReuse { - return false + reserved = false + } else { + cc.reserved++ } - if err := cc.cc.Reserve(); err != nil { - return false + cc.mu.Unlock() + if !reserved { + cc.cc.Release() } - cc.reserved++ - return true + return reserved } func (cc *ClientConn) setDoNotReuse() { diff --git a/vendor/modules.txt b/vendor/modules.txt index 27b753c93..8a18f281a 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -448,16 +448,16 @@ go.opentelemetry.io/proto/otlp/trace/v1 ## explicit; go 1.20 go.uber.org/goleak go.uber.org/goleak/internal/stack -# golang.org/x/crypto v0.54.0 +# golang.org/x/crypto v0.55.0 ## explicit; go 1.25.0 golang.org/x/crypto/md4 golang.org/x/crypto/ocsp golang.org/x/crypto/ripemd160 -# golang.org/x/crypto/x509roots/fallback v0.0.0-20260723152544-d701c51f7e4e +# golang.org/x/crypto/x509roots/fallback v0.0.0-20260811175631-f44d03d253a1 ## explicit; go 1.25.0 golang.org/x/crypto/x509roots/fallback golang.org/x/crypto/x509roots/fallback/bundle -# golang.org/x/net v0.57.0 +# golang.org/x/net v0.58.0 ## explicit; go 1.25.0 golang.org/x/net/context golang.org/x/net/html @@ -483,7 +483,7 @@ golang.org/x/sys/windows/registry # golang.org/x/term v0.45.0 ## explicit; go 1.25.0 golang.org/x/term -# golang.org/x/text v0.40.0 +# golang.org/x/text v0.41.0 ## explicit; go 1.25.0 golang.org/x/text/cases golang.org/x/text/collate From 01ffac6f245854c1b8adc6a69857c76a15f90022 Mon Sep 17 00:00:00 2001 From: Ankur Date: Mon, 17 Aug 2026 17:57:35 +0100 Subject: [PATCH 111/182] Update the release issue template (#6271) * Update the release issue template Refresh stale versions and links for the v2.3.0 cycle, and fix the version bump link that still pointed at the removed lib/consts/consts.go. Drop the dependency-updates and experimental-modules steps, both of which now happen throughout the cycle. Document the k6-DefinitelyTyped flow: branch off the fork's master and merge upstream/master, since repository rules block "Sync fork" and cannot be amended. Add the missing push of the long-lived v{major}.{minor}.x branch, which the release-day one-liner never did. * Update .github/ISSUE_TEMPLATE/release.md Co-authored-by: Mihail Stoykov <312246+mstoykov@users.noreply.github.com> * Update .github/ISSUE_TEMPLATE/release.md Co-authored-by: Mihail Stoykov <312246+mstoykov@users.noreply.github.com> * Fix contradictions in the release template The k6-DefinitelyTyped prose still described branching off the fork's master and merging upstream, while the commands branch straight from upstream/master. Align the prose with the commands and drop the now-unused git fetch origin. Restore the push of the long-lived release branch in the checklist item, so it no longer disagrees with the one-liner below it. * Add docs release notes porting instructions Only the highest version tree in k6-docs is published as latest, so a release notes file left in its own version folder is never published. This is what happened to v1.8.x and v2.0.0. Require the file to land in next and the highest version folder, and to carry the front matter it needs to appear in the release notes index. * Reformat the docs release notes instructions --------- Co-authored-by: Mihail Stoykov <312246+mstoykov@users.noreply.github.com> --- .github/ISSUE_TEMPLATE/release.md | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/release.md b/.github/ISSUE_TEMPLATE/release.md index 7383abf8a..111e3c4b9 100644 --- a/.github/ISSUE_TEMPLATE/release.md +++ b/.github/ISSUE_TEMPLATE/release.md @@ -7,7 +7,7 @@ labels: ["release"] **Release Date**: -22nd June 2026 **<- WRITE HERE THE UPDATED RELEASE DATE** +21st September 2026 **<- WRITE HERE THE UPDATED RELEASE DATE** ## Release Activities @@ -15,8 +15,15 @@ labels: ["release"] - [ ] Create a new `release-v{major}.{minor}.0` branch. - [ ] Add a new release notes file using the available [template](https://github.com/grafana/k6/blob/master/release%20notes/template.md) to the [repository's `release notes` folder](https://github.com/grafana/k6/blob/master/release%20notes). - - [ ] Go through the potential [dependencies updates](https://github.com/grafana/k6/blob/master/Dependencies.md) and create a dedicated PR if any of them is relevant to this release. - [ ] Create a new `release-v{major}.{minor}.0` branch on the [grafana/k6-DefinitelyTyped](https://github.com/grafana/k6-DefinitelyTyped) fork repository. + - Branch directly off `upstream/master`, so the branch starts from the latest upstream state. Do **not** use GitHub's "Sync fork" button: repository rules on the fork block it and they cannot be amended. + + ``` + git remote add upstream https://github.com/DefinitelyTyped/DefinitelyTyped.git # only once + git fetch upstream + git checkout -b release-v2.3.0 upstream/master + git push -u origin release-v2.3.0 + ``` - [ ] Bump the version in [types/k6/package.json](https://github.com/grafana/k6-DefinitelyTyped/blob/master/types/k6/package.json#L4) to the next one. - [ ] [Lock the conversation](https://docs.github.com/en/communities/moderating-comments-and-conversations/locking-conversations) of the current issue to prevent any abuse or misuse of the issue. Note, it still allow the maintainers to edit the issue's description and to add comments. @@ -25,7 +32,6 @@ labels: ["release"] #### ~ 2 weeks before the release date - [ ] Ensure that all PRs from a release milestone are merged. -- [ ] Ensure experimental modules (if needed) have been updated to their latest version. #### ~ 1 week before the release date @@ -38,7 +44,7 @@ labels: ["release"] - [ ] Share the release notes PR with the k6 open-source teams. Request contributions from all affected teams and any other stakeholders involved in the new release. - [ ] Open a separate PR for bumping [the k6 Go project's version](https://github.com/grafana/k6/blob/master/internal/build/version.go#L6). - [ ] Open a PR in the `DefinitelyTyped/DefinitelyTyped` repository using the release branch created in the grafana/k6-DefinitelyTyped fork to update the k6 type definitions for the new release. -- [ ] Open a PR to add the new k6 version to the extensions registry (similar to [this one](https://github.com/grafana/k6-extension-registry/pull/104) for v2.1.0). +- [ ] Open a PR to add the new k6 version to the extensions registry (similar to [this one](https://github.com/grafana/k6-extension-registry/pull/261) for v2.2.0). #### ~ 1 day before the release date @@ -50,12 +56,14 @@ labels: ["release"] - [ ] Open and merge a PR from `main` in the `k6-docs` repository: - [ ] Creating a new `v{major}.{minor}.0` file in the [next release notes folder](https://github.com/grafana/k6-docs/tree/main/docs/sources/k6/next/release-notes) and copy/paste the main sections of the release notes (new features, deprecations and roadmap). - - [ ] Copying the current k6's `next` (including the newly created release note file) to a folder named with the k6 version (e.g., `v2.1.x`). + - Include the front matter (`title`, `menuTitle`, `description`, `weight`), or the page won't appear in the release notes index. + - [ ] Copying the current k6's `next` (including the newly created release note file) to a folder named with the k6 version (e.g., `v2.2.x`). + - [ ] Ensure the file is in `next` and the highest version folder, not only its own. Only the highest tree is published as `latest`, so notes left in an older folder are lost (see [k6-docs#2299](https://github.com/grafana/k6-docs/pull/2299)). Applies to patch releases from maintenance branches too. - [ ] Ensure the `k6` repository release notes PR contains the correct links to the docs. #### In k6 repository -- [ ] Merge the PR bumping [the k6 Go project's version](https://github.com/grafana/k6/blob/master/lib/consts/consts.go#L11-L12). +- [ ] Merge the PR bumping [the k6 Go project's version](https://github.com/grafana/k6/blob/master/internal/build/version.go#L6). - [ ] Merge the release notes PR. - [ ] Pull locally the previously merged changes. - [ ] Create a new long-lived `v{major}.{minor}.x` release branch from the `master` branch. @@ -64,7 +72,7 @@ labels: ["release"] !!! Update the below when making the issue ``` -git checkout master && git pull && git checkout -b v2.1.x && git tag v2.1.0 -m "v2.1.0" && git push origin v2.1.0 +git checkout master && git pull && git checkout -b v2.3.x && git push -u origin v2.3.x && git tag v2.3.0 -m "v2.3.0" && git push origin v2.3.0 ``` #### In k6-extension-registry @@ -80,5 +88,4 @@ git checkout master && git pull && git checkout -b v2.1.x && git tag v2.1.0 -m " ## Wrapping Release - [ ] Ensure the `DefinitelyTyped/DefinitelyTyped` PR(s) are merged. -- [ ] Ensure to sync `grafana/k6-DefinitelyTyped` fork with the latest changes from the `DefinitelyTyped/DefinitelyTyped` repository. - [ ] Update the k6 repository's `.github/ISSUE_TEMPLATE/release.md` in the event steps from this checklist were incorrect or missing. From 0608c0173bbc81851753f7c4fd9a57e2c2217c44 Mon Sep 17 00:00:00 2001 From: Jan Hildebrandt <32014057+janHildebrandt98@users.noreply.github.com> Date: Tue, 18 Aug 2026 11:15:49 +0200 Subject: [PATCH 112/182] Introduce a smoke test of the browser image in build workflow (#6236) * Introduce a smoke test of the browser image in build workflow fix docker run call * Move newPage() call into try/catch --- .github/workflows/build.yml | 22 ++++++++++++++++------ examples/browser/framelocator.js | 18 ++++++++++++++---- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ead766941..ac05e7eb9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -237,13 +237,23 @@ jobs: -t $DOCKER_IMAGE_ID . - name: Check run: | - docker buildx build --load -t $DOCKER_IMAGE_ID . + set -x + CHECK_IMAGE_TAG="k6:check" + docker buildx build --target with-browser --load -t $CHECK_IMAGE_TAG . # Assert that simple cases works for the new built image - docker run $DOCKER_IMAGE_ID version - docker run $DOCKER_IMAGE_ID --help - docker run $DOCKER_IMAGE_ID help - docker run $DOCKER_IMAGE_ID run --help - docker run $DOCKER_IMAGE_ID inspect --help + docker run --rm --pull never $CHECK_IMAGE_TAG version + docker run --rm --pull never $CHECK_IMAGE_TAG --help + docker run --rm --pull never $CHECK_IMAGE_TAG help + docker run --rm --pull never $CHECK_IMAGE_TAG run --help + docker run --rm --pull never $CHECK_IMAGE_TAG inspect --help + + # Run a browser script to smoke test the browser image + # Using framelocator.js because it does not depend on an external website + docker run --rm \ + --pull never \ + --env K6_NO_USAGE_REPORT=true \ + -v "$PWD/examples/browser:/tests:ro" \ + $CHECK_IMAGE_TAG run -q "/tests/framelocator.js" - name: Login to GAR (Docker Hub mirror) if: ${{ github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v') }} uses: grafana/shared-workflows/actions/login-to-gar@c7ad5f57693ac858c698d95783685a9cbfd91223 # login-to-gar/v1.0.1 diff --git a/examples/browser/framelocator.js b/examples/browser/framelocator.js index 2231a06e3..98ded9821 100644 --- a/examples/browser/framelocator.js +++ b/examples/browser/framelocator.js @@ -1,5 +1,6 @@ import { browser } from 'k6/browser'; -import { check, fail } from 'k6'; +import { check } from 'k6'; +import exec from 'k6/execution'; export const options = { scenarios: { @@ -18,9 +19,11 @@ export const options = { } export default async function () { - const page = await browser.newPage(); + let page; try { + page = await browser.newPage(); + // create a page with an iframe await page.setContent(` @@ -66,8 +69,15 @@ export default async function () { }); } catch (error) { - fail(`Browser iteration failed: ${error.message}`); + // This script is run as a smoke test in the build workflow to verify the + // browser Docker image. exec.test.fail() is used here (instead of fail()) + // to produce a non-zero exit code on exception, failing that CI check. + // error.message is empty for rejected promises, so fall back to error.toString() + const message = error.message || error.toString(); + exec.test.fail(`Browser iteration failed: ${message}`); } finally { - await page.close(); + if (page) { + await page.close(); + } } } From 761c619966606003c10c5a1408d277e152ffae90 Mon Sep 17 00:00:00 2001 From: Marcelo Magallon Date: Tue, 18 Aug 2026 08:21:38 -0600 Subject: [PATCH 113/182] Shut down TracerProvider after the Exit event is handled (#6298) TracerProvider.Shutdown ran in a defer registered after the Exit event's emit-and-wait defer, so LIFO ordering made it execute first. This meant the browser module's Exit handler, which ends any open spans in reaction to event.Exit, was ending them after the tracer's exporter had already been torn down, silently dropping those spans. Move the tracer provider shutdown into its own nil-safe hook that is deferred right after globalCancel, so it runs after the Exit event has been emitted and awaited (and after ExitData.Error has been finalized by threshold handling), but before globalCtx is cancelled. Drop the now-unnecessary WaitGroup used to run the traces and outputs flush concurrently, since only outputs flushing remains there. --- internal/cmd/run.go | 34 ++++++++++++++---------------- internal/cmd/tests/cmd_run_test.go | 12 +++++------ 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/internal/cmd/run.go b/internal/cmd/run.go index b4a095dbb..6e4a8865d 100644 --- a/internal/cmd/run.go +++ b/internal/cmd/run.go @@ -73,6 +73,18 @@ func (c *cmdRun) run(cmd *cobra.Command, args []string) (err error) { globalCtx, globalCancel := context.WithCancel(c.gs.Ctx) defer globalCancel() + // shutdownTracerProvider is set once the tracer provider is created below. + // It must run after the Exit event has been emitted and handled (e.g. by + // the browser module ending any open spans), but before globalCtx is + // cancelled by globalCancel above, since it derives its own timeout from + // globalCtx. + var shutdownTracerProvider func() + defer func() { + if shutdownTracerProvider != nil { + shutdownTracerProvider() + } + }() + // lingerCtx is cancelled by Ctrl+C, and is used to wait for that event when // k6 was started with the --linger option. lingerCtx, lingerCancel := context.WithCancel(globalCtx) @@ -119,7 +131,7 @@ func (c *cmdRun) run(cmd *cobra.Command, args []string) (err error) { if err = c.setupTracerProvider(globalCtx, test); err != nil { return err } - waitTracesFlushed := func() { + shutdownTracerProvider = func() { ctx, cancel := context.WithTimeout(globalCtx, waitForTracerProviderStopTimeout) defer cancel() if tpErr := test.preInitState.TracerProvider.Shutdown(ctx); tpErr != nil { @@ -377,24 +389,10 @@ func (c *cmdRun) run(cmd *cobra.Command, args []string) (err error) { } defer func() { - logger.Debug("Waiting for metrics and traces processing to finish...") + logger.Debug("Waiting for metrics processing to finish...") close(samples) - - ww := [...]func(){ - waitOutputsFlushed, - waitTracesFlushed, - } - var wg sync.WaitGroup - wg.Add(len(ww)) - for _, w := range ww { - go func() { - w() - wg.Done() - }() - } - wg.Wait() - - logger.Debug("Metrics and traces processing finished!") + waitOutputsFlushed() + logger.Debug("Metrics processing finished!") }() printExecutionDescription( diff --git a/internal/cmd/tests/cmd_run_test.go b/internal/cmd/tests/cmd_run_test.go index a87bca006..8fdefe069 100644 --- a/internal/cmd/tests/cmd_run_test.go +++ b/internal/cmd/tests/cmd_run_test.go @@ -713,7 +713,7 @@ func TestSetupTeardownThresholds(t *testing.T) { assert.True(t, testutils.LogContains(logMsgs, logrus.DebugLevel, "Running thresholds on 4 metrics...")) assert.True(t, testutils.LogContains(logMsgs, logrus.DebugLevel, "Finalizing thresholds...")) assert.True(t, testutils.LogContains(logMsgs, logrus.DebugLevel, "Metrics emission of VUs and VUsMax metrics stopped")) - assert.True(t, testutils.LogContains(logMsgs, logrus.DebugLevel, "Metrics and traces processing finished!")) + assert.True(t, testutils.LogContains(logMsgs, logrus.DebugLevel, "Metrics processing finished!")) } func TestThresholdsFailed(t *testing.T) { @@ -797,7 +797,7 @@ func TestAbortedByThreshold(t *testing.T) { assert.Contains(t, stdOut, "iterations\n ✗ 'count == 1'") assert.Contains(t, stdOut, `teardown() called`) assert.Contains(t, stdOut, `level=debug msg="Metrics emission of VUs and VUsMax metrics stopped"`) - assert.Contains(t, stdOut, `level=debug msg="Metrics and traces processing finished!"`) + assert.Contains(t, stdOut, `level=debug msg="Metrics processing finished!"`) assert.Contains(t, stdOut, `level=debug msg="Sending test finished" output=cloud ref=111 run_status=8 tainted=true`) } @@ -859,7 +859,7 @@ func TestAbortedByUserWithGoodThresholds(t *testing.T) { ✓ 'count == 1' count=1`) assert.Contains(t, stdout, `Stopping k6 in response to signal`) assert.Contains(t, stdout, `level=debug msg="Metrics emission of VUs and VUsMax metrics stopped"`) - assert.Contains(t, stdout, `level=debug msg="Metrics and traces processing finished!"`) + assert.Contains(t, stdout, `level=debug msg="Metrics processing finished!"`) assert.Contains(t, stdout, `level=debug msg="Sending test finished" output=cloud ref=111 run_status=5 tainted=false`) } @@ -983,7 +983,7 @@ func TestAbortedByUserWithRestAPI(t *testing.T) { assert.Contains(t, stdout, `PATCH /v1/status`) assert.Contains(t, stdout, `level=error msg="test run stopped from REST API`) assert.Contains(t, stdout, `level=debug msg="Metrics emission of VUs and VUsMax metrics stopped"`) - assert.Contains(t, stdout, `level=debug msg="Metrics and traces processing finished!"`) + assert.Contains(t, stdout, `level=debug msg="Metrics processing finished!"`) assert.Contains(t, stdout, `level=debug msg="Sending test finished" output=cloud ref=111 run_status=5 tainted=false`) assert.NotContains(t, stdout, `Running thresholds`) assert.NotContains(t, stdout, `Finalizing thresholds`) @@ -1273,7 +1273,7 @@ func testAbortedByScriptError(t *testing.T, script string, runTest func(*testing stdout := ts.Stdout.String() t.Log(stdout) assert.Contains(t, stdout, `level=debug msg="Metrics emission of VUs and VUsMax metrics stopped"`) - assert.Contains(t, stdout, `level=debug msg="Metrics and traces processing finished!"`) + assert.Contains(t, stdout, `level=debug msg="Metrics processing finished!"`) assert.Contains(t, stdout, `level=debug msg="Everything has finished, exiting k6 with an error!"`) assert.Contains(t, stdout, `level=debug msg="Sending test finished" output=cloud ref=111 run_status=7 tainted=false`) return ts @@ -1418,7 +1418,7 @@ func testAbortedByScriptTestAbort(t *testing.T, script string, runTest func(*tes assert.Contains(t, stdout, "test aborted: foo") assert.Contains(t, stdout, `level=debug msg="Sending test finished" output=cloud ref=111 run_status=5 tainted=false`) assert.Contains(t, stdout, `level=debug msg="Metrics emission of VUs and VUsMax metrics stopped"`) - assert.Contains(t, stdout, `level=debug msg="Metrics and traces processing finished!"`) + assert.Contains(t, stdout, `level=debug msg="Metrics processing finished!"`) assert.Contains(t, stdout, "bogus summary") } From fce5185886242af55a0ac0b7071d904dfa5b7d00 Mon Sep 17 00:00:00 2001 From: Shun Takahashi Date: Fri, 21 Aug 2026 02:00:26 +0900 Subject: [PATCH 114/182] refactor(cmd): decouple cloud subcommands from the parent cmdCloud (#6209) * refactor(cmd): decouple cloud subcommands from the parent cmdCloud The `k6 cloud` command no longer executes a test directly - it is a pure coordinator that prints help and delegates to `cloud run` / `cloud upload` / `cloud project` / `cloud test`. Despite that, the subcommands still reached into a shared `cmdCloud` instance to borrow its `run`, `preRun` and `flagSet` methods, which meant the parent carried per-run flag state (`showCloudLogs`, `exitOnRunning`, `uploadOnly`) on behalf of its children, and `cloud upload` mutated that shared state before invoking the parent's run method. Replace the struct with package-level functions that take their inputs explicitly: cmdCloud.preRun -> applyCloudEnvOverrides(gs, cmd, showCloudLogs, exitOnRunning) cmdCloud.run -> runCloudTest(gs, cmd, args, showCloudLogs, exitOnRunning, uploadOnly) cmdCloud.printTestStatus -> printCloudTestStatus(gs, status) cmdCloud.flagSet -> cloudCmdFlagSet(showCloudLogs, exitOnRunning) Each subcommand constructor now takes a *state.GlobalState instead of a *cmdCloud, and `cloud run` owns the flag values it binds. `cloud upload` calls runCloudTest with uploadOnly=true rather than flipping a field on a shared object. The parent `k6 cloud` keeps advertising --show-logs and --exit-on-running in its usage output, bound to throwaway values, so the help text is unchanged. No user-visible behaviour change. * refactor(cmd): split cloud env var parsing from flag application Review feedback on #6209: cloud upload's preRun only needs the K6_SHOW_CLOUD_LOGS / K6_EXIT_ON_RUNNING validation half of applyCloudEnvOverrides, since the command defines neither flag, so it had to supply throwaway bool variables just to give the overrides somewhere to land. Extract parseCloudEnvOverrides, which parses and validates the two env variables and reports each value as a nil-able pointer. applyCloudEnvOverrides becomes a thin wrapper that applies the parsed values unless the corresponding CLI flag was explicitly set, and cloud upload calls the parse function directly, dropping the placeholders. Behaviour is unchanged: same error messages, same flag-over-env precedence, and upload keeps rejecting invalid values as before. * refactor(cmd): group runCloudTest's flag values into an options struct Review feedback on #6209: three positional bools in a row are easy to mix up, and a call like runCloudTest(gs, cmd, args, false, false, true) doesn't tell the reader which value is which. Introduce cloudTestRunOptions so call sites name what they set: cloud run passes {showCloudLogs, exitOnRunning} and cloud upload passes {uploadOnly: true}. * docs(cmd): correct which commands use cloudCmdFlagSet The comment claimed the flag set was shared by cloud run/upload, but cloud upload builds its own flag set without --exit-on-running and --show-logs. Since #6208 the parent cloud command no longer registers it either, leaving cloud run as the only user. * test(cmd): cover cloud env var overrides and flag precedence Review feedback on #6209: the refactoring moved the K6_SHOW_CLOUD_LOGS / K6_EXIT_ON_RUNNING handling, but no test set K6_EXIT_ON_RUNNING, and none set an env variable together with its flag, so the cmd.Flags().Changed precedence was uncovered too. Add subtests for cloud run: the env variable alone triggers exit-on-running, an explicitly set flag wins over the env value, and an invalid value fails the command. Also cover cloud upload, which defines neither flag but still validates the variables. --- internal/cmd/cloud.go | 156 +++++++++++--------- internal/cmd/cloud_load_zone.go | 6 +- internal/cmd/cloud_loadtest.go | 6 +- internal/cmd/cloud_project.go | 6 +- internal/cmd/cloud_run.go | 37 +++-- internal/cmd/cloud_upload.go | 22 ++- internal/cmd/tests/cmd_cloud_test.go | 48 ++++++ internal/cmd/tests/cmd_cloud_upload_test.go | 15 ++ 8 files changed, 193 insertions(+), 103 deletions(-) diff --git a/internal/cmd/cloud.go b/internal/cmd/cloud.go index 6b5597477..c750eeb23 100644 --- a/internal/cmd/cloud.go +++ b/internal/cmd/cloud.go @@ -115,48 +115,74 @@ func cloudStackName(conf cloudapi.Config) string { return fmt.Sprintf("stack-%d", conf.StackID.Int64) } -// cmdCloud handles the `k6 cloud` sub-command -type cmdCloud struct { - gs *state.GlobalState - - showCloudLogs bool - exitOnRunning bool - uploadOnly bool -} - -func (c *cmdCloud) preRun(cmd *cobra.Command, _ []string) error { - // TODO: refactor (https://github.com/grafana/k6/issues/883) - // - // We deliberately parse the env variables, to validate for wrong - // values, even if we don't subsequently use them (if the respective - // CLI flag was specified, since it has a higher priority). - if showCloudLogsEnv, ok := c.gs.Env["K6_SHOW_CLOUD_LOGS"]; ok { +// parseCloudEnvOverrides parses and validates the K6_SHOW_CLOUD_LOGS and +// K6_EXIT_ON_RUNNING environment variables. A nil result means the +// corresponding variable is not set. +// +// It is also used on its own to validate the variables for wrong values by +// commands that don't subsequently use them. +func parseCloudEnvOverrides(env map[string]string) (showCloudLogs, exitOnRunning *bool, err error) { + if showCloudLogsEnv, ok := env["K6_SHOW_CLOUD_LOGS"]; ok { showCloudLogsValue, err := strconv.ParseBool(showCloudLogsEnv) if err != nil { - return fmt.Errorf("parsing K6_SHOW_CLOUD_LOGS returned an error: %w", err) - } - if !cmd.Flags().Changed("show-logs") { - c.showCloudLogs = showCloudLogsValue + return nil, nil, fmt.Errorf("parsing K6_SHOW_CLOUD_LOGS returned an error: %w", err) } + showCloudLogs = &showCloudLogsValue } - if exitOnRunningEnv, ok := c.gs.Env["K6_EXIT_ON_RUNNING"]; ok { + if exitOnRunningEnv, ok := env["K6_EXIT_ON_RUNNING"]; ok { exitOnRunningValue, err := strconv.ParseBool(exitOnRunningEnv) if err != nil { - return fmt.Errorf("parsing K6_EXIT_ON_RUNNING returned an error: %w", err) - } - if !cmd.Flags().Changed("exit-on-running") { - c.exitOnRunning = exitOnRunningValue + return nil, nil, fmt.Errorf("parsing K6_EXIT_ON_RUNNING returned an error: %w", err) } + exitOnRunning = &exitOnRunningValue + } + return showCloudLogs, exitOnRunning, nil +} + +// applyCloudEnvOverrides applies the K6_SHOW_CLOUD_LOGS and K6_EXIT_ON_RUNNING +// environment variables onto the provided flag values, unless the corresponding +// CLI flag was explicitly set (in which case it takes precedence). +// +// TODO: refactor (https://github.com/grafana/k6/issues/883) +func applyCloudEnvOverrides(gs *state.GlobalState, cmd *cobra.Command, showCloudLogs, exitOnRunning *bool) error { + envShowCloudLogs, envExitOnRunning, err := parseCloudEnvOverrides(gs.Env) + if err != nil { + return err + } + + if envShowCloudLogs != nil && !cmd.Flags().Changed("show-logs") { + *showCloudLogs = *envShowCloudLogs + } + if envExitOnRunning != nil && !cmd.Flags().Changed("exit-on-running") { + *exitOnRunning = *envExitOnRunning } return nil } +// cloudTestRunOptions holds the flag values that control how runCloudTest +// behaves. +type cloudTestRunOptions struct { + // showCloudLogs streams the cloud logs to the terminal while the test runs. + showCloudLogs bool + + // exitOnRunning makes the command return as soon as the test reaches the + // running status, instead of waiting for it to finish. + exitOnRunning bool + + // uploadOnly stops after uploading the test archive, without starting a + // test run. + uploadOnly bool +} + +// runCloudTest builds the test archive, uploads it to Grafana Cloud, and (unless +// opts.uploadOnly is set) starts the run and tracks its progress until completion. +// // TODO: split apart some more // //nolint:funlen,gocognit,cyclop -func (c *cmdCloud) run(cmd *cobra.Command, args []string) error { - test, err := loadAndConfigureLocalTest(c.gs, cmd, args, getPartialConfig) +func runCloudTest(gs *state.GlobalState, cmd *cobra.Command, args []string, opts cloudTestRunOptions) error { + test, err := loadAndConfigureLocalTest(gs, cmd, args, getPartialConfig) if err != nil { return err } @@ -173,15 +199,15 @@ func (c *cmdCloud) run(cmd *cobra.Command, args []string) error { // TODO: validate for usage of execution segment // TODO: validate for externally controlled executor (i.e. executors that aren't distributable) // TODO: move those validations to a separate function and reuse validateConfig()? - printBanner(c.gs) + printBanner(gs) progressBar := pb.New( pb.WithConstLeft("Init"), pb.WithConstProgress(0, "Loading test script..."), ) - printBar(c.gs, progressBar) + printBar(gs, progressBar) - modifyAndPrintBar(c.gs, progressBar, pb.WithConstProgress(0, "Building the archive...")) + modifyAndPrintBar(gs, progressBar, pb.WithConstProgress(0, "Building the archive...")) arc := test.makeArchive() tmpCloudConfig, err := cloudapi.GetTemporaryCloudConfig(arc.Options.Cloud) @@ -191,7 +217,7 @@ func (c *cmdCloud) run(cmd *cobra.Command, args []string) error { // Cloud config cloudConfig, warn, err := cloudapi.GetConsolidatedConfig( - test.derivedConfig.Collectors["cloud"], c.gs.Env, "", arc.Options.Cloud) + test.derivedConfig.Collectors["cloud"], gs.Env, "", arc.Options.Cloud) if err != nil { return err } @@ -201,7 +227,7 @@ func (c *cmdCloud) run(cmd *cobra.Command, args []string) error { // Display config warning if needed if warn != "" { - modifyAndPrintBar(c.gs, progressBar, pb.WithConstProgress(0, "Warning: "+warn)) + modifyAndPrintBar(gs, progressBar, pb.WithConstProgress(0, "Warning: "+warn)) } if cloudConfig.Token.Valid { @@ -230,31 +256,31 @@ func (c *cmdCloud) run(cmd *cobra.Command, args []string) error { name = filepath.Base(test.sourceRootPath) } - globalCtx, globalCancel := context.WithCancel(c.gs.Ctx) + globalCtx, globalCancel := context.WithCancel(gs.Ctx) defer globalCancel() - logger := c.gs.Logger + logger := gs.Logger // Start cloud test run - modifyAndPrintBar(c.gs, progressBar, pb.WithConstProgress(0, "Validating script options")) + modifyAndPrintBar(gs, progressBar, pb.WithConstProgress(0, "Validating script options")) client, err := cloudapiv6.NewClient( logger, cloudConfig.Token.String, cloudConfig.Hostv6.String, build.Version, cloudConfig.Timeout.TimeDuration()) if err != nil { return err } - projectID, err := prepCloudTestRun(globalCtx, c.gs, client, &cloudConfig, tmpCloudConfig, arc) + projectID, err := prepCloudTestRun(globalCtx, gs, client, &cloudConfig, tmpCloudConfig, arc) if err != nil { return err } - modifyAndPrintBar(c.gs, progressBar, pb.WithConstProgress(0, "Uploading archive")) + modifyAndPrintBar(gs, progressBar, pb.WithConstProgress(0, "Uploading archive")) loadTest, err := client.UploadTest(globalCtx, name, projectID, arc) if err != nil { return fmt.Errorf("uploading test: %w", err) } - if c.uploadOnly { + if opts.uploadOnly { et, err := lib.NewExecutionTuple(test.derivedConfig.ExecutionSegment, test.derivedConfig.ExecutionSegmentSequence) if err != nil { return err @@ -265,10 +291,10 @@ func (c *cmdCloud) run(cmd *cobra.Command, args []string) error { return err } printExecutionDescription( - c.gs, "cloud", test.sourceRootPath, testURL, test.derivedConfig, et, executionPlan, nil, + gs, "cloud", test.sourceRootPath, testURL, test.derivedConfig, et, executionPlan, nil, ) - modifyAndPrintBar(c.gs, progressBar, pb.WithConstLeft("Run "), pb.WithConstProgress(1.0, "Archived")) - c.printTestStatus("Archived") + modifyAndPrintBar(gs, progressBar, pb.WithConstLeft("Run "), pb.WithConstProgress(1.0, "Archived")) + printCloudTestStatus(gs, "Archived") return nil } @@ -296,7 +322,7 @@ func (c *cmdCloud) run(cmd *cobra.Command, args []string) error { onHardStop := func(sig os.Signal) { logger.WithField("sig", sig).Error("Aborting k6 in response to signal, we won't wait for the test to end.") } - stopSignalHandling := handleTestAbortSignals(c.gs, gracefulStop, onHardStop) + stopSignalHandling := handleTestAbortSignals(gs, gracefulStop, onHardStop) defer stopSignalHandling() et, err := lib.NewExecutionTuple(test.derivedConfig.ExecutionSegment, test.derivedConfig.ExecutionSegmentSequence) @@ -306,11 +332,11 @@ func (c *cmdCloud) run(cmd *cobra.Command, args []string) error { testURL := run.GetTestRunDetailsPageUrl() executionPlan := test.derivedConfig.Scenarios.GetFullExecutionRequirements(et) printExecutionDescription( - c.gs, "cloud", test.sourceRootPath, testURL, test.derivedConfig, et, executionPlan, nil, + gs, "cloud", test.sourceRootPath, testURL, test.derivedConfig, et, executionPlan, nil, ) modifyAndPrintBar( - c.gs, progressBar, + gs, progressBar, pb.WithConstLeft("Run "), pb.WithConstProgress(0, "Initializing the cloud test"), ) @@ -320,7 +346,7 @@ func (c *cmdCloud) run(cmd *cobra.Command, args []string) error { defer progressBarWG.Wait() defer progressCancel() go func() { - showProgress(progressCtx, c.gs, []*pb.ProgressBar{progressBar}, logger) + showProgress(progressCtx, gs, []*pb.ProgressBar{progressBar}, logger) progressBarWG.Done() }() @@ -345,7 +371,7 @@ func (c *cmdCloud) run(cmd *cobra.Command, args []string) error { ) ticker := time.NewTicker(time.Millisecond * 2000) - if c.showCloudLogs { + if opts.showCloudLogs { refID := strconv.FormatInt(testRunID, 10) go func() { logger.Debug("Connecting to cloud logs server...") @@ -367,7 +393,7 @@ func (c *cmdCloud) run(cmd *cobra.Command, args []string) error { testProgressLock.Unlock() if newTestProgress.IsFinished() || - (c.exitOnRunning && newTestProgress.IsRunning()) { + (opts.exitOnRunning && newTestProgress.IsRunning()) { globalCancel() break } @@ -382,7 +408,7 @@ func (c *cmdCloud) run(cmd *cobra.Command, args []string) error { return errext.WithExitCodeIfNone(errors.New("Test progress error"), exitcodes.CloudFailedToGetProgress) } - c.printTestStatus(testProgress.FormatStatus()) + printCloudTestStatus(gs, testProgress.FormatStatus()) if testProgress.ThresholdsFailed() { //nolint:staticcheck @@ -396,27 +422,29 @@ func (c *cmdCloud) run(cmd *cobra.Command, args []string) error { return nil } -func (c *cmdCloud) printTestStatus(status string) { - if !c.gs.Flags.Quiet { - valueColor := getColor(c.gs.Flags.NoColor || !c.gs.Stdout.IsTTY, color.FgCyan) - printToStdout(c.gs, fmt.Sprintf( +func printCloudTestStatus(gs *state.GlobalState, status string) { + if !gs.Flags.Quiet { + valueColor := getColor(gs.Flags.NoColor || !gs.Stdout.IsTTY, color.FgCyan) + printToStdout(gs, fmt.Sprintf( " test status: %s\n", valueColor.Sprint(status), )) } else { - c.gs.Logger.WithField("run_status", status).Debug("Test finished") + gs.Logger.WithField("run_status", status).Debug("Test finished") } } -func (c *cmdCloud) flagSet() *pflag.FlagSet { +// cloudCmdFlagSet returns the flag set used by the cloud run command, +// binding the --exit-on-running and --show-logs flags to the provided values. +func cloudCmdFlagSet(showCloudLogs, exitOnRunning *bool) *pflag.FlagSet { flags := pflag.NewFlagSet("", pflag.ContinueOnError) flags.SortFlags = false flags.AddFlagSet(optionFlagSet()) flags.AddFlagSet(runtimeOptionFlagSet(false)) // TODO: Figure out a better way to handle the CLI flags - flags.BoolVar(&c.exitOnRunning, "exit-on-running", c.exitOnRunning, + flags.BoolVar(exitOnRunning, "exit-on-running", *exitOnRunning, "exits when test reaches the running status") - flags.BoolVar(&c.showCloudLogs, "show-logs", c.showCloudLogs, + flags.BoolVar(showCloudLogs, "show-logs", *showCloudLogs, "enable showing of logs when a test is executed in the cloud") return flags } @@ -442,12 +470,6 @@ Use "{{.CommandPath}} [command] --help" for more information about a command.{{e } func getCmdCloud(gs *state.GlobalState) *cobra.Command { - c := &cmdCloud{ - gs: gs, - showCloudLogs: true, - exitOnRunning: false, - } - exampleText := getExampleText(gs, ` # Authenticate with Grafana Cloud $ {{.}} cloud login @@ -475,7 +497,7 @@ func getCmdCloud(gs *state.GlobalState) *cobra.Command { defaultUsageTemplate := (&cobra.Command{}).UsageTemplate() defaultUsageTemplate = strings.ReplaceAll(defaultUsageTemplate, "FlagUsages", "FlagUsagesWrapped 120") - runCmd := getCmdCloudRun(c) + runCmd := getCmdCloudRun(gs) runCmd.SetUsageTemplate(defaultUsageTemplate) runCmd.SetHelpTemplate((&cobra.Command{}).HelpTemplate()) cloudCmd.AddCommand(runCmd) @@ -485,18 +507,18 @@ func getCmdCloud(gs *state.GlobalState) *cobra.Command { loginCmd.SetHelpTemplate((&cobra.Command{}).HelpTemplate()) cloudCmd.AddCommand(loginCmd) - uploadCmd := getCmdCloudUpload(c) + uploadCmd := getCmdCloudUpload(gs) uploadCmd.SetUsageTemplate(defaultUsageTemplate) uploadCmd.SetHelpTemplate((&cobra.Command{}).HelpTemplate()) cloudCmd.AddCommand(uploadCmd) - projectCmd := getCmdCloudProject(c) + projectCmd := getCmdCloudProject(gs) cloudCmd.AddCommand(projectCmd) - loadZoneCmd := getCmdCloudLoadZone(c) + loadZoneCmd := getCmdCloudLoadZone(gs) cloudCmd.AddCommand(loadZoneCmd) - testCmd := getCmdCloudTest(c) + testCmd := getCmdCloudTest(gs) cloudCmd.AddCommand(testCmd) // Use custom template similar to root - hardcode flags to avoid showing global flags diff --git a/internal/cmd/cloud_load_zone.go b/internal/cmd/cloud_load_zone.go index 90746ddaf..23c389fdb 100644 --- a/internal/cmd/cloud_load_zone.go +++ b/internal/cmd/cloud_load_zone.go @@ -9,12 +9,12 @@ type cmdCloudLoadZone struct { globalState *state.GlobalState } -func getCmdCloudLoadZone(cloudCmd *cmdCloud) *cobra.Command { +func getCmdCloudLoadZone(gs *state.GlobalState) *cobra.Command { c := &cmdCloudLoadZone{ - globalState: cloudCmd.gs, + globalState: gs, } - exampleText := getExampleText(cloudCmd.gs, ` + exampleText := getExampleText(gs, ` # List all load zones in the configured stack $ {{.}} cloud load-zone list diff --git a/internal/cmd/cloud_loadtest.go b/internal/cmd/cloud_loadtest.go index ffdde0204..1cd0882e8 100644 --- a/internal/cmd/cloud_loadtest.go +++ b/internal/cmd/cloud_loadtest.go @@ -9,12 +9,12 @@ type cmdCloudTest struct { globalState *state.GlobalState } -func getCmdCloudTest(cloudCmd *cmdCloud) *cobra.Command { +func getCmdCloudTest(gs *state.GlobalState) *cobra.Command { c := &cmdCloudTest{ - globalState: cloudCmd.gs, + globalState: gs, } - exampleText := getExampleText(cloudCmd.gs, ` + exampleText := getExampleText(gs, ` # List tests in the default project $ {{.}} cloud test list diff --git a/internal/cmd/cloud_project.go b/internal/cmd/cloud_project.go index 732408789..57bc0315e 100644 --- a/internal/cmd/cloud_project.go +++ b/internal/cmd/cloud_project.go @@ -9,12 +9,12 @@ type cmdCloudProject struct { globalState *state.GlobalState } -func getCmdCloudProject(cloudCmd *cmdCloud) *cobra.Command { +func getCmdCloudProject(gs *state.GlobalState) *cobra.Command { c := &cmdCloudProject{ - globalState: cloudCmd.gs, + globalState: gs, } - exampleText := getExampleText(cloudCmd.gs, ` + exampleText := getExampleText(gs, ` # List all projects in the configured stack $ {{.}} cloud project list diff --git a/internal/cmd/cloud_run.go b/internal/cmd/cloud_run.go index 20289483a..add1188f4 100644 --- a/internal/cmd/cloud_run.go +++ b/internal/cmd/cloud_run.go @@ -7,6 +7,7 @@ import ( "github.com/spf13/cobra" "github.com/spf13/pflag" + "go.k6.io/k6/v2/cmd/state" "go.k6.io/k6/v2/errext" "go.k6.io/k6/v2/errext/exitcodes" "go.k6.io/k6/v2/internal/execution" @@ -42,17 +43,21 @@ type cmdCloudRun struct { // the --local-execution flag mode. runCmd *cmdRun - // deprecatedCloudCmd holds an instance of the k6 cloud command that we store - // in order to be able to call its run method to support the cloud execution - // feature, and to have access to its flagSet if necessary. - deprecatedCloudCmd *cmdCloud + // gs holds the global state, used to run the test in the cloud. + gs *state.GlobalState + + // showCloudLogs stores the state of the --show-logs flag. + showCloudLogs bool + + // exitOnRunning stores the state of the --exit-on-running flag. + exitOnRunning bool } -func getCmdCloudRun(cloudCmd *cmdCloud) *cobra.Command { +func getCmdCloudRun(gs *state.GlobalState) *cobra.Command { // We instantiate the run command here to be able to call its run method // when the --local-execution flag is set. runCmd := &cmdRun{ - gs: cloudCmd.gs, + gs: gs, // We override the loadConfiguredTest func to use the local execution // configuration which enforces the use of the cloud output among other @@ -62,17 +67,18 @@ func getCmdCloudRun(cloudCmd *cmdCloud) *cobra.Command { execution.Controller, error, ) { - test, err := loadAndConfigureLocalTest(cloudCmd.gs, cmd, args, getCloudRunLocalExecutionConfig) + test, err := loadAndConfigureLocalTest(gs, cmd, args, getCloudRunLocalExecutionConfig) return test, local.NewController(), err }, } cloudRunCmd := &cmdCloudRun{ - deprecatedCloudCmd: cloudCmd, - runCmd: runCmd, + gs: gs, + runCmd: runCmd, + showCloudLogs: true, } - exampleText := getExampleText(cloudCmd.gs, ` + exampleText := getExampleText(gs, ` # Run a test script in Grafana Cloud $ {{.}} cloud run script.js @@ -97,12 +103,12 @@ func getCmdCloudRun(cloudCmd *cmdCloud) *cobra.Command { thisCmd.Flags().SortFlags = false thisCmd.Flags().AddFlagSet(cloudRunCmd.flagSet()) - thisCmd.Flags().AddFlagSet(cloudCmd.flagSet()) + thisCmd.Flags().AddFlagSet(cloudCmdFlagSet(&cloudRunCmd.showCloudLogs, &cloudRunCmd.exitOnRunning)) return thisCmd } -func (c *cmdCloudRun) preRun(cmd *cobra.Command, args []string) error { +func (c *cmdCloudRun) preRun(cmd *cobra.Command, _ []string) error { if c.localExecution { if cmd.Flags().Changed("exit-on-running") { return errext.WithExitCodeIfNone( @@ -142,7 +148,7 @@ func (c *cmdCloudRun) preRun(cmd *cobra.Command, args []string) error { ) } - return c.deprecatedCloudCmd.preRun(cmd, args) + return applyCloudEnvOverrides(c.gs, cmd, &c.showCloudLogs, &c.exitOnRunning) } func (c *cmdCloudRun) run(cmd *cobra.Command, args []string) error { @@ -168,7 +174,10 @@ func (c *cmdCloudRun) run(cmd *cobra.Command, args []string) error { // When running the `k6 cloud run` command explicitly disable the usage report. c.noUsageReport = true - return c.deprecatedCloudCmd.run(cmd, args) + return runCloudTest(c.gs, cmd, args, cloudTestRunOptions{ + showCloudLogs: c.showCloudLogs, + exitOnRunning: c.exitOnRunning, + }) } func (c *cmdCloudRun) flagSet() *pflag.FlagSet { diff --git a/internal/cmd/cloud_upload.go b/internal/cmd/cloud_upload.go index 9cb82f49b..cd3b709d7 100644 --- a/internal/cmd/cloud_upload.go +++ b/internal/cmd/cloud_upload.go @@ -11,21 +11,15 @@ const cloudUploadCommandName = "upload" type cmdCloudUpload struct { globalState *state.GlobalState - - // deprecatedCloudCmd holds an instance of the k6 cloud command that we store - // in order to be able to call its run method to support the cloud upload - // feature - deprecatedCloudCmd *cmdCloud } -func getCmdCloudUpload(cloudCmd *cmdCloud) *cobra.Command { +func getCmdCloudUpload(gs *state.GlobalState) *cobra.Command { c := &cmdCloudUpload{ - globalState: cloudCmd.gs, - deprecatedCloudCmd: cloudCmd, + globalState: gs, } // uploadCloudCommand represents the 'cloud upload' command - exampleText := getExampleText(cloudCmd.gs, ` + exampleText := getExampleText(gs, ` # Upload a test to Grafana Cloud without running it $ {{.}} cloud upload script.js`[1:]) @@ -44,14 +38,16 @@ func getCmdCloudUpload(cloudCmd *cmdCloud) *cobra.Command { return uploadCloudCommand } -func (c *cmdCloudUpload) preRun(cmd *cobra.Command, args []string) error { - return c.deprecatedCloudCmd.preRun(cmd, args) +func (c *cmdCloudUpload) preRun(_ *cobra.Command, _ []string) error { + // The upload command doesn't expose the --show-logs/--exit-on-running flags, + // but we still validate the corresponding env variables for wrong values. + _, _, err := parseCloudEnvOverrides(c.globalState.Env) + return err } // run is the code that runs when the user executes `k6 cloud upload` func (c *cmdCloudUpload) run(cmd *cobra.Command, args []string) error { - c.deprecatedCloudCmd.uploadOnly = true - return c.deprecatedCloudCmd.run(cmd, args) + return runCloudTest(c.globalState, cmd, args, cloudTestRunOptions{uploadOnly: true}) } func (c *cmdCloudUpload) flagSet() *pflag.FlagSet { diff --git a/internal/cmd/tests/cmd_cloud_test.go b/internal/cmd/tests/cmd_cloud_test.go index 5bd73f081..c691e0717 100644 --- a/internal/cmd/tests/cmd_cloud_test.go +++ b/internal/cmd/tests/cmd_cloud_test.go @@ -112,6 +112,54 @@ func runCloudTests(t *testing.T, setupCmd setupCommandFunc) { assert.Contains(t, stdout, `test status: Running`) }) + t.Run("TestCloudExitOnRunningEnv", func(t *testing.T) { + t.Parallel() + + // Same as TestCloudExitOnRunning, but driven by the environment + // variable instead of the CLI flag. Without the override taking + // effect, the command would keep polling the mock server forever, + // since its progress is always "Running". + ts := getSimpleCloudTestState(t, nil, setupCmd, []string{"--log-output=stdout"}, + v6test.Progress(cloudapiv6.StatusRunning, v6test.ResultNone)) + ts.Env["K6_EXIT_ON_RUNNING"] = "true" + cmd.ExecuteWithGlobalState(ts.GlobalState) + + stdout := ts.Stdout.String() + t.Log(stdout) + assert.Contains(t, stdout, `execution: cloud`) + assert.Contains(t, stdout, `output: https://stack.grafana.com/a/k6-app/runs/123`) + assert.Contains(t, stdout, `test status: Running`) + }) + + t.Run("TestCloudExitOnRunningFlagOverridesEnv", func(t *testing.T) { + t.Parallel() + + // An explicitly set CLI flag takes precedence over the environment + // variable. If the "false" from the environment won instead, the + // command would poll the always-"Running" mock server forever. + ts := getSimpleCloudTestState(t, nil, setupCmd, []string{"--exit-on-running", "--log-output=stdout"}, + v6test.Progress(cloudapiv6.StatusRunning, v6test.ResultNone)) + ts.Env["K6_EXIT_ON_RUNNING"] = "false" + cmd.ExecuteWithGlobalState(ts.GlobalState) + + stdout := ts.Stdout.String() + t.Log(stdout) + assert.Contains(t, stdout, `test status: Running`) + }) + + t.Run("TestCloudExitOnRunningInvalidEnv", func(t *testing.T) { + t.Parallel() + + ts := getSimpleCloudTestState(t, nil, setupCmd, nil, nil) + ts.Env["K6_EXIT_ON_RUNNING"] = "invalid" + ts.ExpectedExitCode = -1 + cmd.ExecuteWithGlobalState(ts.GlobalState) + + stdout := ts.Stdout.String() + t.Log(stdout) + assert.Contains(t, stdout, `parsing K6_EXIT_ON_RUNNING returned an error`) + }) + t.Run("TestCloudURLFromStartResponse", func(t *testing.T) { t.Parallel() diff --git a/internal/cmd/tests/cmd_cloud_upload_test.go b/internal/cmd/tests/cmd_cloud_upload_test.go index 4022f9909..5289f16f3 100644 --- a/internal/cmd/tests/cmd_cloud_upload_test.go +++ b/internal/cmd/tests/cmd_cloud_upload_test.go @@ -33,6 +33,21 @@ func TestK6CloudUpload(t *testing.T) { assert.Contains(t, stdout, `access token not configured`) }) + t.Run("TestCloudUploadInvalidEnv", func(t *testing.T) { + t.Parallel() + + // The upload command doesn't define the --exit-on-running flag, but it + // still validates the corresponding env variable for wrong values. + ts := getSimpleCloudTestState(t, nil, setupK6CloudUploadCmd, nil, nil) + ts.Env["K6_EXIT_ON_RUNNING"] = "invalid" + ts.ExpectedExitCode = -1 + cmd.ExecuteWithGlobalState(ts.GlobalState) + + stdout := ts.Stdout.String() + t.Log(stdout) + assert.Contains(t, stdout, `parsing K6_EXIT_ON_RUNNING returned an error`) + }) + t.Run("TestCloudUploadWithScript", func(t *testing.T) { t.Parallel() From 94169daab29df52c1ed2ee0549657a577666b855 Mon Sep 17 00:00:00 2001 From: Ankur Date: Fri, 21 Aug 2026 09:34:12 +0100 Subject: [PATCH 115/182] Fix frozen pages on shared browser connections (#6279) * Fix defaultContext publication race The connection's recvLoop goroutine starts before connect() assigns b.defaultContext, so an attach event could observe the field while it is being written. Publish the assignment under contextMu so the connection's attach filter can read it safely. * Fix rejected browser targets staying paused Each connection auto-attaches to every new target in the browser with waitForDebuggerOnStart, so the browser keeps a new target paused until every attached client releases it. When the attach filter rejected a target, the connection sent Runtime.runIfWaitingForDebugger but stayed attached, so the browser kept waiting on this client for future events. Detach from rejected targets instead. Detaching should be enough to release the hold, but the browser has a bug where a detached target can stay paused, so resume the target first and await the resume response before sending the detach: the ordering must be guaranteed by the response, not by wire order, or the browser may still process the detach before the resume. This is the same workaround Playwright applies in CRSession.detach (crConnection.ts). The wait is bounded because an unresponsive target must still be detached from, or this client would keep holding it. Awaiting the response requires a registered session, because the connection drops responses addressed to unknown sessions, so the reject path now creates a session for the target before releasing it. This also matches Playwright, where a session object exists for every attached target. The session is cleaned up by the existing handling of the Target.detachedFromTarget event the browser sends back. * Fix connection filter claiming foreign targets Each connection auto-attaches to every new target in the browser with waitForDebuggerOnStart, so the browser keeps a new page paused until every attached client releases it. The attach filter accepted any target while the connection had no browser context yet, so a connection that was still setting up claimed pages belonging to other connections sharing the browser and never released them. Those pages stayed frozen until the claiming connection closed: with multiple VUs on a shared browser instance, roughly one page per browser made progress at a time. Only accept targets from the connection's own browser context or the browser's default context. Foreign targets now take the reject path, which resumes them, detaches from them, and releases the hold. * Release targets the browser ignores onAttachedToTarget could ignore an attached target after isAttachedPageValid rejected it, without releasing it: the target stayed paused, held by this client, until the connection closed. Resume and detach from every target the browser ignores, the same sequenced release the connection uses for filtered targets. * Release rejected pages regardless of closing isPageAttachmentErrorIgnorable can also return true when only this VU's own context ended, not just when the browser is closing, but the rejected target's session was only released in the closing case. On a shared browser instance, the connection and its other VUs can outlive this VU's context, so the target was left held for anyone still using that browser. Release the target unconditionally: detachSession is a no-op if the connection or session is already gone, so this is safe when the browser genuinely is closing too. * Fix recvLoop stalling on a closed session getSession only holds the sessions lock for the map lookup, so a session obtained this way can already be closed by the time recvLoop tries to deliver a message to it: closeSession is callable from any goroutine, not just recvLoop, and detachSession's goroutine calls it after releasing a rejected target. With no reader left on the session's readCh once its readLoop has exited, delivering to it blocked forever, since neither the connection's closeCh nor done fire just because one session closed. That stalled recvLoop - the single goroutine reading every message for the whole connection - along with every other session sharing it. Extract recvLoop's dispatch into deliverToSession and add a <-session.done case, so delivering to an already-closed session returns immediately instead of blocking. Also add a concurrency test proving closeSession is safe to call more than once for the same session, the same shape as detachSession's own close racing the browser's Target.detachedFromTarget event. * Fix detachSession leaking on a failed detach send detachSession left a rejected target's session registered until the browser's own Target.detachedFromTarget event arrived, but that event is not guaranteed: the detach command itself can error against a real browser. When it does, the session's goroutine and its entry in the connection's sessions map are never reclaimed until the whole connection closes. Close the session locally right after the resume-and-detach attempt, regardless of whether it succeeded. Safe now that a concurrent recvLoop dispatch to the same session can no longer block. --- .../js/modules/k6/browser/common/browser.go | 55 +-- .../modules/k6/browser/common/browser_test.go | 97 ++++++ .../modules/k6/browser/common/connection.go | 127 ++++--- .../k6/browser/common/connection_test.go | 312 ++++++++++++++++++ .../k6/browser/common/frame_session.go | 16 +- .../modules/k6/browser/tests/browser_test.go | 29 ++ 6 files changed, 552 insertions(+), 84 deletions(-) diff --git a/internal/js/modules/k6/browser/common/browser.go b/internal/js/modules/k6/browser/common/browser.go index 9f6ac0efe..b513ccd7a 100644 --- a/internal/js/modules/k6/browser/common/browser.go +++ b/internal/js/modules/k6/browser/common/browser.go @@ -160,12 +160,16 @@ func (b *Browser) connect() error { return fmt.Errorf("connecting to browser DevTools URL: %w", err) } - // We don't need to lock this because `connect()` is called only in NewBrowser - b.defaultContext, err = NewBrowserContext(b.vuCtx, b, "", DefaultBrowserContextOptions(), b.logger) + defaultContext, err := NewBrowserContext(b.vuCtx, b, "", DefaultBrowserContextOptions(), b.logger) if err != nil { return fmt.Errorf("browser connect: %w", err) } - b.runOnClose = append(b.runOnClose, b.defaultContext.cleanup) + // The connection's recvLoop reads defaultContext through + // connectionOnAttachedToTarget, so publish it under contextMu. + b.contextMu.Lock() + b.defaultContext = defaultContext + b.contextMu.Unlock() + b.runOnClose = append(b.runOnClose, defaultContext.cleanup) return b.initEvents() } @@ -266,23 +270,16 @@ func (b *Browser) initEvents() error { } // connectionOnAttachedToTarget is called when Connection receives an attachedToTarget -// event. Returning false will stop the event from being processed by the connection. +// event. Returning false makes the connection release the target instead of +// adopting it. Targets from the connection's own browser context and from +// the default browser context are accepted. func (b *Browser) connectionOnAttachedToTarget(eva *target.EventAttachedToTarget) bool { - // This allows to attach targets to the same browser context as the current - // one, and to the default browser context. - // - // We don't want to hold the lock for the entire function - // (connectionOnAttachedToTarget) run duration, because we want to avoid - // possible lock contention issues with the browser context being closed while - // we're waiting for it. So, we do the lock management in a function with its - // own defer. - isAllowedBrowserContext := func() bool { - b.contextMu.RLock() - defer b.contextMu.RUnlock() - return b.context == nil || b.context.id == eva.TargetInfo.BrowserContextID - } - - return isAllowedBrowserContext() + b.contextMu.RLock() + defer b.contextMu.RUnlock() + if b.context != nil && b.context.id == eva.TargetInfo.BrowserContextID { + return true + } + return b.defaultContext.id == eva.TargetInfo.BrowserContextID } // onAttachedToTarget is called when a new page is attached to the browser. @@ -295,9 +292,6 @@ func (b *Browser) onAttachedToTarget(ev *target.EventAttachedToTarget) error { browserCtx = b.getDefaultBrowserContextOrMatchedID(targetPage.BrowserContextID) ) - if !b.isAttachedPageValid(ev, browserCtx) { - return nil // Ignore this page. - } session := b.conn.getSession(ev.SessionID) if session == nil { b.logger.Debugf("Browser:onAttachedToTarget", @@ -305,6 +299,13 @@ func (b *Browser) onAttachedToTarget(ev *target.EventAttachedToTarget) error { ev.SessionID, targetPage.TargetID) return nil // ignore } + if !b.isAttachedPageValid(ev, browserCtx) { + // Never ignore an attached target without detaching from it: the + // browser keeps the target paused until every attached client + // releases it, and detaching drops this client's hold. + detachSession(session) + return nil // Ignore this page. + } var ( isPage = targetPage.Type == "page" @@ -320,10 +321,10 @@ func (b *Browser) onAttachedToTarget(ev *target.EventAttachedToTarget) error { } p, err := NewPage(b.vuCtx, session, browserCtx, targetPage.TargetID, opener, isPage, b.logger) if err != nil && b.isPageAttachmentErrorIgnorable(ev, session, err) { - if b.closing.Load() { - b.logger.Debugf("Browser:onAttachedToTarget", "new page failed; browser is closing: sid:%v", ev.SessionID) - detachSession(b.browserCtx, session) - } + // Always release: isPageAttachmentErrorIgnorable can also return + // true when only this VU's context ended, while the browser + // instance stays alive and shared with other VUs. + detachSession(session) return nil // Ignore this page. } if err != nil { @@ -349,7 +350,7 @@ func (b *Browser) onAttachedToTarget(ev *target.EventAttachedToTarget) error { ) } - detachSession(b.browserCtx, session) + detachSession(session) return nil } diff --git a/internal/js/modules/k6/browser/common/browser_test.go b/internal/js/modules/k6/browser/common/browser_test.go index d1af513ce..9607c84ef 100644 --- a/internal/js/modules/k6/browser/common/browser_test.go +++ b/internal/js/modules/k6/browser/common/browser_test.go @@ -6,6 +6,7 @@ import ( "testing" "time" + "github.com/chromedp/cdproto" "github.com/chromedp/cdproto/cdp" "github.com/chromedp/cdproto/target" "github.com/stretchr/testify/require" @@ -189,6 +190,102 @@ func TestBrowserNewPageInContext(t *testing.T) { }) } +func TestConnectionOnAttachedToTarget(t *testing.T) { + t.Parallel() + + const ( + ownContextID cdp.BrowserContextID = "own" + foreignContextID cdp.BrowserContextID = "foreign" + ) + + newTestBrowser := func(t *testing.T, withOwnContext bool) *Browser { + t.Helper() + + ctx, cancel := context.WithCancel(context.Background()) + t.Cleanup(cancel) + b := newBrowser(context.Background(), ctx, cancel, nil, NewLocalBrowserOptions(), log.NewNullLogger()) + + var err error + b.defaultContext, err = NewBrowserContext(k6ext.WithVU(ctx, k6test.NewVU(t)), b, "", nil, nil) + require.NoError(t, err) + if withOwnContext { + b.context, err = NewBrowserContext(k6ext.WithVU(ctx, k6test.NewVU(t)), b, ownContextID, nil, nil) + require.NoError(t, err) + } + + return b + } + + tests := []struct { + name string + withOwnContext bool + targetContextID cdp.BrowserContextID + want bool + }{ + {"own_context_target", true, ownContextID, true}, + {"foreign_target", true, foreignContextID, false}, + {"foreign_target_without_own_context", false, foreignContextID, false}, + {"default_context_target", false, "", true}, + {"default_context_target_with_own_context", true, "", true}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + b := newTestBrowser(t, tt.withOwnContext) + ev := &target.EventAttachedToTarget{ + TargetInfo: &target.Info{BrowserContextID: tt.targetContextID}, + } + require.Equal(t, tt.want, b.connectionOnAttachedToTarget(ev)) + }) + } +} + +// TestBrowserRejectedTarget ensures a target the connection accepts but the +// browser rejects (isAttachedPageValid) is resumed and then detached from, +// like the connection-level rejection in TestConnectionRejectedTarget. +func TestBrowserRejectedTarget(t *testing.T) { + t.Parallel() + + const rejectedSessionID = target.SessionID("session_id_0123456789") + + wsURL, received := newAttachedToTargetServer(t, + attachedToTargetEvent(rejectedSessionID, "service_worker", ""), + 300*time.Millisecond) + + vuCtx, vuCancel := context.WithCancel(context.Background()) + t.Cleanup(vuCancel) + b := newBrowser(context.Background(), vuCtx, vuCancel, nil, NewLocalBrowserOptions(), log.NewNullLogger()) + var err error + b.defaultContext, err = NewBrowserContext(k6ext.WithVU(vuCtx, k6test.NewVU(t)), b, "", nil, nil) + require.NoError(t, err) + + conn, err := NewConnection( + b.browserCtx, wsURL, log.NewNullLogger(), b.connectionOnAttachedToTarget, + ) + require.NoError(t, err) + t.Cleanup(conn.Close) + b.conn = conn + + evCh := make(chan Event) + conn.on(b.browserCtx, []string{cdproto.EventTargetAttachedToTarget}, evCh) + + action := target.SetDiscoverTargets(true) + require.NoError(t, action.Do(cdp.WithExecutor(b.browserCtx, conn))) + + select { + case event := <-evCh: + ev, ok := event.data.(*target.EventAttachedToTarget) + require.True(t, ok) + require.NoError(t, b.onAttachedToTarget(ev)) + case <-time.After(5 * time.Second): + t.Fatal("timed out waiting for the attached target event") + } + + requireResumeThenDetach(t, received, rejectedSessionID) +} + type fakeConn struct { connection execute func(context.Context, string, any, any) error diff --git a/internal/js/modules/k6/browser/common/connection.go b/internal/js/modules/k6/browser/common/connection.go index 5217c614f..72509f440 100644 --- a/internal/js/modules/k6/browser/common/connection.go +++ b/internal/js/modules/k6/browser/common/connection.go @@ -134,9 +134,12 @@ type Connection struct { sessionsMu sync.RWMutex sessions map[target.SessionID]*Session - // onTargetAttachedToTarget is called when a new target is attached to the browser. - // Returning false will prevent the session from being created. - // If onTargetAttachedToTarget is nil, the session will be created. + // onTargetAttachedToTarget is called when a new target is attached to + // the browser. The target's session is registered before the call, so + // that the response to the release below can be routed back to it. + // Returning false releases the target: it is resumed and detached from + // instead of being adopted. If onTargetAttachedToTarget is nil, every + // target is adopted. onTargetAttachedToTarget func(*target.EventAttachedToTarget) bool } @@ -329,7 +332,36 @@ func (c *Connection) findTargetIDForLog(id target.SessionID) target.ID { return s.targetID } -//nolint:funlen,gocognit,cyclop +// deliverToSession routes msg to session's readCh. It reports whether +// recvLoop should stop reading from the connection entirely. +// +// getSession only holds the sessions lock for the lookup, so by the time +// this runs, session may already be closed (e.g. by closeSession, which +// can be called concurrently from any goroutine, not just recvLoop): its +// readLoop may have already exited on its own done channel, leaving no +// receiver on readCh. Without the <-session.done case, an unbuffered send +// there would then block forever, since neither c.closeCh nor c.done fire +// just because one session closed - stalling recvLoop, and with it every +// other session on the connection. +func (c *Connection) deliverToSession(session *Session, msg *cdproto.Message) (stop bool) { + select { + case session.readCh <- msg: + case <-session.done: + c.logger.Debugf("Connection:deliverToSession:<-session.done", "sid:%v tid:%v wsURL:%q", + session.id, session.targetID, c.wsURL) + case code := <-c.closeCh: + c.logger.Debugf("Connection:deliverToSession:<-c.closeCh", "sid:%v tid:%v wsURL:%v crashed:%t", + session.id, session.targetID, c.wsURL, session.crashed) + _ = c.close(code) + case <-c.done: + c.logger.Debugf("Connection:deliverToSession:<-c.done", "sid:%v tid:%v wsURL:%v crashed:%t", + session.id, session.targetID, c.wsURL, session.crashed) + return true + } + return false +} + +//nolint:funlen,gocognit func (c *Connection) recvLoop() { c.logger.Debugf("Connection:recvLoop", "wsURL:%q", c.wsURL) for { @@ -363,21 +395,21 @@ func (c *Connection) recvLoop() { eva := ev.(*target.EventAttachedToTarget) //nolint:forcetypeassert sid, tid := eva.SessionID, eva.TargetInfo.TargetID + c.sessionsMu.Lock() + session := NewSession(c.ctx, c, sid, tid, c.logger, c.msgIDGen) + c.logger.Debugf("Connection:recvLoop:EventAttachedToTarget", "sid:%v tid:%v wsURL:%q", sid, tid, c.wsURL) + c.sessions[sid] = session + c.sessionsMu.Unlock() + if c.onTargetAttachedToTarget != nil { - // If onTargetAttachedToTarget is set, it will be called to determine - // if a session should be created for the target. + // If onTargetAttachedToTarget is set, it will be called to + // determine if the target should be adopted or released. ok := c.onTargetAttachedToTarget(eva) if !ok { - c.stopWaitingForDebugger(sid) + detachSession(session) continue } } - - c.sessionsMu.Lock() - session := NewSession(c.ctx, c, sid, tid, c.logger, c.msgIDGen) - c.logger.Debugf("Connection:recvLoop:EventAttachedToTarget", "sid:%v tid:%v wsURL:%q", sid, tid, c.wsURL) - c.sessions[sid] = session - c.sessionsMu.Unlock() } else if msg.Method == cdproto.EventTargetDetachedFromTarget { ev, err := cdproto.UnmarshalMessage(&msg) if err != nil { @@ -401,7 +433,6 @@ func (c *Connection) recvLoop() { switch { case msg.SessionID != "" && (msg.Method != "" || msg.ID != 0): - // TODO: possible data race - session can get removed after getting it here session := c.getSession(msg.SessionID) if session == nil { continue @@ -413,15 +444,7 @@ func (c *Connection) recvLoop() { continue } - select { - case session.readCh <- &msg: - case code := <-c.closeCh: - c.logger.Debugf("Connection:recvLoop:<-c.closeCh", "sid:%v tid:%v wsURL:%v crashed:%t", - session.id, session.targetID, c.wsURL, session.crashed) - _ = c.close(code) - case <-c.done: - c.logger.Debugf("Connection:recvLoop:<-c.done", "sid:%v tid:%v wsURL:%v crashed:%t", - session.id, session.targetID, c.wsURL, session.crashed) + if c.deliverToSession(session, &msg) { return } @@ -445,29 +468,43 @@ func (c *Connection) recvLoop() { } } -// stopWaitingForDebugger tells the browser to stop waiting for the -// debugger to attach to the page's session. -// -// Whether we're not sharing pages among browser contexts, Chromium -// still does so (since we're auto-attaching all browser targets). -// This means that if we don't stop waiting for the debugger, the -// browser will wait for the debugger to attach to the new page -// indefinitely, even if the page is not part of the browser context -// we're using. +// detachSession resumes a rejected target's session, awaits the response, +// then detaches from it. Detaching alone should release the target, but the +// browser has a bug where a detached target can stay paused, so the resume +// must land first — the same workaround as Playwright's CRSession.detach +// (crConnection.ts). The wait is bounded so an unresponsive target is still +// detached from. Best-effort: errors are not returned. Target.detachFromTarget +// is browser-level: the session goes in the params, not the message's +// session ID. // -// We don't return an error because the browser might have already -// closed the connection. In that case, handling the error would -// be redundant. This operation is best-effort. -func (c *Connection) stopWaitingForDebugger(sid target.SessionID) { - msg := &cdproto.Message{ - ID: c.msgIDGen.newID(), - SessionID: sid, - Method: cdproto.MethodType(cdpruntime.CommandRunIfWaitingForDebugger), - } - err := c.send(c.ctx, msg, nil, nil) - if err != nil { - c.logger.Errorf("Connection:stopWaitingForDebugger", "sid:%v wsURL:%q, err:%v", sid, c.wsURL, err) - } +// The session is also closed locally here, rather than left for the +// browser's own Target.detachedFromTarget event to reap: that event isn't +// guaranteed to arrive (e.g. if the detach command itself errors), and +// waiting for it would leak the session's goroutine and its entry in the +// connection's sessions map until the whole connection closes. +func detachSession(session *Session) { + go func() { + c := session.conn + defer c.closeSession(session.id, session.targetID) + + ctx, cancel := context.WithTimeout(c.ctx, DefaultTimeout) + defer cancel() + _ = session.Execute(ctx, cdpruntime.CommandRunIfWaitingForDebugger, nil, nil) + + buf, err := jsonv2.Marshal(&target.DetachFromTargetParams{SessionID: session.id}, defaultJSONV2Options) + if err != nil { + c.logger.Errorf("Connection:detachSession", "sid:%v wsURL:%q, err:%v", session.id, c.wsURL, err) + return + } + msg := &cdproto.Message{ + ID: c.msgIDGen.newID(), + Method: cdproto.MethodType(target.CommandDetachFromTarget), + Params: buf, + } + if err := c.send(c.ctx, msg, nil, nil); err != nil { + c.logger.Errorf("Connection:detachSession", "sid:%v wsURL:%q, err:%v", session.id, c.wsURL, err) + } + }() } func (c *Connection) send( diff --git a/internal/js/modules/k6/browser/common/connection_test.go b/internal/js/modules/k6/browser/common/connection_test.go index 6fd6db437..d61505e18 100644 --- a/internal/js/modules/k6/browser/common/connection_test.go +++ b/internal/js/modules/k6/browser/common/connection_test.go @@ -4,14 +4,18 @@ import ( "context" "fmt" "net/url" + "sync" "testing" + "time" "go.k6.io/k6/v2/internal/js/modules/k6/browser/log" "go.k6.io/k6/v2/internal/js/modules/k6/browser/tests/ws" "github.com/chromedp/cdproto" "github.com/chromedp/cdproto/cdp" + cdpruntime "github.com/chromedp/cdproto/runtime" "github.com/chromedp/cdproto/target" + jsonv2 "github.com/go-json-experiment/json" "github.com/go-json-experiment/json/jsontext" "github.com/gorilla/websocket" "github.com/stretchr/testify/assert" @@ -78,6 +82,314 @@ func TestConnectionSendRecv(t *testing.T) { }) } +// attachedToTargetEvent returns a Target.attachedToTarget event payload for +// a paused target, as the browser sends when auto-attaching a new target. +func attachedToTargetEvent(sessionID target.SessionID, targetType, browserContextID string) string { + return fmt.Sprintf(` + { + "sessionId": %q, + "targetInfo": { + "targetId": "target_id_0123456789", + "type": %q, + "title": "", + "url": "about:blank", + "attached": true, + "browserContextId": %q + }, + "waitingForDebugger": true + }`, sessionID, targetType, browserContextID) +} + +// resumeRespondedSentinel marks, in the received stream, the moment the +// server wrote its response to Runtime.runIfWaitingForDebugger. Anything +// the client sends after seeing that response arrives later in the stream. +const resumeRespondedSentinel = cdproto.MethodType("test:resume-responded") + +// newAttachedToTargetServer starts a fake CDP websocket server that records +// every command it receives and emits the given Target.attachedToTarget +// event when the client sends Target.setDiscoverTargets. The response to +// Runtime.runIfWaitingForDebugger is delayed by resumeDelay, and a +// resumeRespondedSentinel is recorded when it is written. +func newAttachedToTargetServer( + t *testing.T, attachedEvent string, resumeDelay time.Duration, +) (string, chan cdproto.Message) { + t.Helper() + + received := make(chan cdproto.Message, 16) + handler := func(conn *websocket.Conn, msg *cdproto.Message, writeCh chan cdproto.Message, done chan struct{}) { + if msg.Method == "" { + return + } + received <- *msg + switch msg.Method { + case cdproto.MethodType(cdproto.CommandTargetSetDiscoverTargets): + writeCh <- cdproto.Message{ + Method: cdproto.EventTargetAttachedToTarget, + Params: jsontext.Value(attachedEvent), + } + writeCh <- cdproto.Message{ + ID: msg.ID, + Result: jsontext.Value([]byte("{}")), + } + case cdproto.MethodType(cdpruntime.CommandRunIfWaitingForDebugger): + response := cdproto.Message{ + ID: msg.ID, + SessionID: msg.SessionID, + Result: jsontext.Value([]byte("{}")), + } + // Respond asynchronously so a delayed response does not also + // delay reading the messages the client sends in the meantime. + go func() { + select { + case <-time.After(resumeDelay): + case <-done: + return + } + received <- cdproto.Message{Method: resumeRespondedSentinel} + select { + case writeCh <- response: + case <-done: + } + }() + } + } + + server := ws.NewServer(t, ws.WithCDPHandler("/cdp", handler, nil)) + u, err := url.Parse(server.ServerHTTP.URL) + require.NoError(t, err) + + return fmt.Sprintf("ws://%s/cdp", u.Host), received +} + +// requireResumeThenDetach consumes the server-received messages until the +// rejected target's session is detached from, asserting the client resumed +// the target, awaited the server's response, and only then detached, with +// both commands correctly addressed. +func requireResumeThenDetach(t *testing.T, received <-chan cdproto.Message, sid target.SessionID) { + t.Helper() + + timeout := time.After(5 * time.Second) + var sawResume, sawResponse bool + for { + select { + case msg := <-received: + switch msg.Method { + case cdproto.MethodType(cdpruntime.CommandRunIfWaitingForDebugger): + // The resume targets the paused session directly. + require.Equal(t, sid, msg.SessionID) + sawResume = true + case resumeRespondedSentinel: + sawResponse = true + case cdproto.MethodType(target.CommandDetachFromTarget): + // Target.detachFromTarget is a browser-level command: the + // session goes in the params, not in the message session ID. + require.Empty(t, msg.SessionID) + var params target.DetachFromTargetParams + require.NoError(t, jsonv2.Unmarshal(msg.Params, ¶ms, defaultJSONV2Options)) + require.Equal(t, sid, params.SessionID) + require.True(t, sawResume, "expected Runtime.runIfWaitingForDebugger before the detach") + require.True(t, sawResponse, + "expected the detach to be sent only after the resume response was written") + return + } + case <-timeout: + t.Fatal("timed out waiting for the rejected target to be released") + } + } +} + +// TestConnectionRejectedTarget ensures a target rejected by the attach filter +// is resumed and then detached from. The browser keeps a new target paused +// until every client attached with waitForDebuggerOnStart releases it. +// Detaching should be enough to release the hold, but the browser has a bug +// where a detached target can stay paused, so the resume must come first — +// the same workaround Playwright uses (crConnection.ts, CRSession.detach). +// Wire order is not enough: only awaiting the response guarantees the +// browser processed the resume before the detach, so the server delays the +// resume response to catch a client that does not wait for it. +func TestConnectionRejectedTarget(t *testing.T) { + t.Parallel() + + const rejectedSessionID = target.SessionID("session_id_0123456789") + + wsURL, received := newAttachedToTargetServer(t, + attachedToTargetEvent(rejectedSessionID, "page", "browser_context_id_0123456789"), + 300*time.Millisecond) + + ctx := context.Background() + rejectAll := func(*target.EventAttachedToTarget) bool { return false } + conn, err := NewConnection(ctx, wsURL, log.NewNullLogger(), rejectAll) + require.NoError(t, err) + t.Cleanup(conn.Close) + + action := target.SetDiscoverTargets(true) + require.NoError(t, action.Do(cdp.WithExecutor(ctx, conn))) + + requireResumeThenDetach(t, received, rejectedSessionID) +} + +// TestConnectionRejectedTargetClosedLocallyOnDetachError ensures a rejected +// target's session is closed locally even when the outgoing detach command +// itself errors (as it can against a real browser). Waiting for the +// browser's own Target.detachedFromTarget event to reap the session would +// leak it whenever that event never arrives. +func TestConnectionRejectedTargetClosedLocallyOnDetachError(t *testing.T) { + t.Parallel() + + const rejectedSessionID = target.SessionID("session_id_0123456789") + + received := make(chan cdproto.Message, 16) + handler := func(_ *websocket.Conn, msg *cdproto.Message, writeCh chan cdproto.Message, _ chan struct{}) { + if msg.Method == "" { + return + } + received <- *msg + switch msg.Method { + case cdproto.MethodType(cdproto.CommandTargetSetDiscoverTargets): + writeCh <- cdproto.Message{ + Method: cdproto.EventTargetAttachedToTarget, + Params: jsontext.Value(attachedToTargetEvent(rejectedSessionID, "page", "browser_context_id_0123456789")), + } + writeCh <- cdproto.Message{ID: msg.ID, Result: jsontext.Value([]byte("{}"))} + case cdproto.MethodType(cdpruntime.CommandRunIfWaitingForDebugger): + writeCh <- cdproto.Message{ID: msg.ID, SessionID: msg.SessionID, Result: jsontext.Value([]byte("{}"))} + case cdproto.MethodType(target.CommandDetachFromTarget): + // Simulate the browser rejecting the detach itself. + writeCh <- cdproto.Message{ID: msg.ID, Error: &cdproto.Error{Message: "No session with given id"}} + } + } + + server := ws.NewServer(t, ws.WithCDPHandler("/cdp", handler, nil)) + u, err := url.Parse(server.ServerHTTP.URL) + require.NoError(t, err) + wsURL := fmt.Sprintf("ws://%s/cdp", u.Host) + + ctx := context.Background() + rejectAll := func(*target.EventAttachedToTarget) bool { return false } + conn, err := NewConnection(ctx, wsURL, log.NewNullLogger(), rejectAll) + require.NoError(t, err) + t.Cleanup(conn.Close) + + action := target.SetDiscoverTargets(true) + require.NoError(t, action.Do(cdp.WithExecutor(ctx, conn))) + + require.Eventually(t, func() bool { + return conn.getSession(rejectedSessionID) == nil + }, 5*time.Second, 10*time.Millisecond, + "session should be closed locally even though the detach command errored") +} + +// newTestConnection dials a minimal fake CDP server that acknowledges +// every command with an empty success reply. +func newTestConnection(t *testing.T) *Connection { + t.Helper() + + handler := func(_ *websocket.Conn, msg *cdproto.Message, writeCh chan cdproto.Message, _ chan struct{}) { + writeCh <- cdproto.Message{ID: msg.ID, SessionID: msg.SessionID, Result: jsontext.Value([]byte("{}"))} + } + server := ws.NewServer(t, ws.WithCDPHandler("/cdp", handler, nil)) + u, err := url.Parse(server.ServerHTTP.URL) + require.NoError(t, err) + + conn, err := NewConnection(context.Background(), fmt.Sprintf("ws://%s/cdp", u.Host), log.NewNullLogger(), nil) + require.NoError(t, err) + t.Cleanup(conn.Close) + + return conn +} + +// TestConnectionDeliverToSessionAfterClose is a deterministic regression +// test for a race in recvLoop's dispatch to a session's readCh: getSession +// only holds the sessions lock for the map lookup, so a session obtained +// this way can already be closed - by closeSession, callable from any +// goroutine, not just recvLoop - by the time the dispatch actually runs. +// Without the <-session.done case, delivering to an already-closed +// session's readCh blocks forever: its readLoop has already exited, so +// there is no reader left, and neither c.closeCh nor c.done fire just +// because one session closed. That would stall recvLoop - the single +// goroutine reading every message for the whole connection - along with +// every other session sharing it. +// +// The session's readLoop is deliberately never started (done is closed by +// hand instead of via NewSession + closeSession), so there is provably no +// reader on readCh, ever - this removes any dependency on readLoop's own +// exit timing and drives the exact interleaving deterministically, rather +// than hoping to catch it. +func TestConnectionDeliverToSessionAfterClose(t *testing.T) { + t.Parallel() + + const sid = target.SessionID("session_id_0123456789") + const tid = target.ID("target_id_0123456789") + + conn := newTestConnection(t) + + session := &Session{ + BaseEventEmitter: NewBaseEventEmitter(context.Background()), + conn: conn, + id: sid, + targetID: tid, + readCh: make(chan *cdproto.Message), + done: make(chan struct{}), + msgIDGen: conn.msgIDGen, + logger: log.NewNullLogger(), + } + close(session.done) // no readLoop was ever started to close it itself + + done := make(chan bool, 1) + go func() { + done <- conn.deliverToSession(session, &cdproto.Message{Method: "Test.event", SessionID: sid}) + }() + + select { + case stop := <-done: + require.False(t, stop, "delivering to a closed session must not signal a connection-level stop") + case <-time.After(2 * time.Second): + t.Fatal("deliverToSession blocked forever delivering to an already-closed session") + } +} + +// TestConnectionCloseSessionConcurrent proves closeSession is safe to call +// concurrently, and repeatedly, for the same session - the exact shape of +// detachSession's own closeSession call racing the browser's genuine +// Target.detachedFromTarget event arriving and being handled by recvLoop's +// own closeSession call, or any other pair of callers. Under -race, a +// data race here would fail the test; closeSession's own locking must +// also make it safe to call twice - only the first caller may release the +// session, every other caller must see it already gone. +func TestConnectionCloseSessionConcurrent(t *testing.T) { + t.Parallel() + + const sid = target.SessionID("session_id_0123456789") + const tid = target.ID("target_id_0123456789") + const callers = 50 + + conn := newTestConnection(t) + + conn.sessionsMu.Lock() + conn.sessions[sid] = NewSession(context.Background(), conn, sid, tid, log.NewNullLogger(), conn.msgIDGen) + conn.sessionsMu.Unlock() + + var wg sync.WaitGroup + results := make([]bool, callers) + for i := range callers { + wg.Add(1) + go func(i int) { + defer wg.Done() + results[i] = conn.closeSession(sid, tid) + }(i) + } + wg.Wait() + + var released int + for _, ok := range results { + if ok { + released++ + } + } + require.Equal(t, 1, released, "exactly one concurrent closeSession call should release the session") + require.Nil(t, conn.getSession(sid), "the session must be gone from the connection after closing") +} + func TestConnectionCreateSession(t *testing.T) { t.Parallel() diff --git a/internal/js/modules/k6/browser/common/frame_session.go b/internal/js/modules/k6/browser/common/frame_session.go index 3edf039b2..1441aed8f 100644 --- a/internal/js/modules/k6/browser/common/frame_session.go +++ b/internal/js/modules/k6/browser/common/frame_session.go @@ -969,7 +969,7 @@ func (fs *FrameSession) onAttachedToTarget(event *target.EventAttachedToTarget) default: fs.logger.Debugf("FrameSession:onAttachedToTarget", "unsupported target type %q sid:%v", ti.Type, session.ID()) - detachSession(fs.teardownCtx, session) + detachSession(session) } if err == nil { return @@ -1020,7 +1020,7 @@ func (fs *FrameSession) attachIFrameToTarget(ti *target.Info, session *Session) if fs.page.isClosing() { fs.logger.Debugf("FrameSession:attachIFrameToTarget", "rejected frame; page is closing: tid=%v", ti.TargetID) - detachSession(fs.teardownCtx, session) + detachSession(session) return nil } @@ -1059,7 +1059,7 @@ func (fs *FrameSession) attachIFrameToTarget(ti *target.Info, session *Session) if errors.Is(err, errPageClosing) { fs.logger.Debugf("FrameSession:attachIFrameToTarget", "rejected frame; page is closing: tid=%v", ti.TargetID) - detachSession(fs.teardownCtx, session) + detachSession(session) return nil } return err @@ -1073,7 +1073,7 @@ func (fs *FrameSession) attachWorkerToTarget(ti *target.Info, session *Session) if fs.page.isClosing() { fs.logger.Debugf("FrameSession:attachWorkerToTarget", "rejected worker; page is closing: tid=%v", ti.TargetID) - detachSession(fs.teardownCtx, session) + detachSession(session) return nil } @@ -1288,11 +1288,3 @@ func (fs *FrameSession) executionContextForID( return nil, fmt.Errorf("no execution context found for id: %v", executionContextID) } - -// detachSession unblocks a target waiting for debugger and detaches from it. -// Prevents the browser from hanging on rejected targets during close -func detachSession(ctx context.Context, session *Session) { - _ = session.ExecuteWithoutExpectationOnReply(ctx, cdpruntime.CommandRunIfWaitingForDebugger, nil, nil) - _ = session.ExecuteWithoutExpectationOnReply(ctx, target.CommandDetachFromTarget, - &target.DetachFromTargetParams{SessionID: session.id}, nil) -} diff --git a/internal/js/modules/k6/browser/tests/browser_test.go b/internal/js/modules/k6/browser/tests/browser_test.go index aee9edced..e558e155b 100644 --- a/internal/js/modules/k6/browser/tests/browser_test.go +++ b/internal/js/modules/k6/browser/tests/browser_test.go @@ -351,6 +351,35 @@ func TestMultiConnectToSingleBrowser(t *testing.T) { require.NoError(t, err, "failed to close page #2") } +// TestContextlessConnectionDoesNotStallNavigation guards against connections +// freezing each other's pages when they share a browser instance. Every new +// page starts paused until all auto-attached connections resume it. A +// connection that hadn't created its browser context yet used to claim other +// connections' pages without ever releasing them, stalling their navigations +// until it disconnected. The second connection here never creates a context, +// which reproduces that state deterministically. +func TestContextlessConnectionDoesNotStallNavigation(t *testing.T) { + t.Parallel() + + tb := newTestBrowser(t) + + b2, err := tb.browserType.Connect(context.Background(), tb.context(), tb.wsURL) + require.NoError(t, err) + t.Cleanup(b2.Close) + + bctx, err := tb.NewContext(nil) + require.NoError(t, err) + p, err := bctx.NewPage() + require.NoError(t, err) + + err = tb.awaitWithTimeout(10*time.Second, func() error { + opts := &common.FrameGotoOptions{Timeout: 10 * time.Second} + _, err := p.Goto("data:text/html,hello", opts) + return err + }) + require.NoError(t, err) +} + func TestCloseContext(t *testing.T) { t.Parallel() From 6dbacc2f5788c1585ad2a3e2f6731c599c05169d Mon Sep 17 00:00:00 2001 From: Daigo Yamashita Date: Fri, 21 Aug 2026 20:55:17 +0900 Subject: [PATCH 116/182] fix(output/influxdb): support URL path prefixes in --out influxdb= (#5949) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ParseURL now treats the last segment of the URL path as the database name and preserves any remaining path as part of the address. This allows InfluxDB to be hosted behind a reverse proxy that routes on a path prefix (e.g. https://host/influxdbA/dbname → Addr=https://host/influxdbA, DB=dbname). A trailing slash signals that the whole path is the prefix and no DB is specified in the URL. The path-splitting logic is extracted into splitPathPrefixAndDB to keep ParseURL's complexity within the project's lint thresholds. Closes #425 --- internal/output/influxdb/config.go | 25 ++++++++++++-- internal/output/influxdb/config_test.go | 9 +++++ internal/output/influxdb/output_test.go | 44 +++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 3 deletions(-) diff --git a/internal/output/influxdb/config.go b/internal/output/influxdb/config.go index dfd124d17..6306680ff 100644 --- a/internal/output/influxdb/config.go +++ b/internal/output/influxdb/config.go @@ -107,6 +107,22 @@ func ParseJSON(data json.RawMessage) (Config, error) { return conf, err } +// splitPathPrefixAndDB splits a URL path into the address prefix kept as part +// of Addr and a database name. The last segment is treated as the DB name, +// allowing InfluxDB to be hosted behind a reverse proxy that routes on a path +// prefix (e.g. https://host/influxdbA/dbname -> prefix=/influxdbA, db=dbname). +// A trailing slash means the whole path is the prefix and no DB is specified. +func splitPathPrefixAndDB(path string) (prefix, db string) { + if path == "" { + return "", "" + } + if rest, ok := strings.CutSuffix(path, "/"); ok { + return rest, "" + } + idx := strings.LastIndex(path, "/") + return path[:idx], path[idx+1:] +} + // ParseURL parses the supplied URL into a Config. func ParseURL(text string) (Config, error) { c := Config{} @@ -115,9 +131,12 @@ func ParseURL(text string) (Config, error) { return c, err } if u.Host != "" { - c.Addr = null.StringFrom(u.Scheme + "://" + u.Host) - } - if db := strings.TrimPrefix(u.Path, "/"); db != "" { + prefix, db := splitPathPrefixAndDB(u.Path) + c.Addr = null.StringFrom(u.Scheme + "://" + u.Host + prefix) + if db != "" { + c.DB = null.StringFrom(db) + } + } else if db := strings.TrimPrefix(u.Path, "/"); db != "" { c.DB = null.StringFrom(db) } if u.User != nil { diff --git a/internal/output/influxdb/config_test.go b/internal/output/influxdb/config_test.go index 2c709df98..c1f0eaa4b 100644 --- a/internal/output/influxdb/config_test.go +++ b/internal/output/influxdb/config_test.go @@ -15,6 +15,15 @@ func TestParseURL(t *testing.T) { "/dbname": {DB: null.StringFrom("dbname")}, "http://localhost:8086": {Addr: null.StringFrom("http://localhost:8086")}, "http://localhost:8086/dbname": {Addr: null.StringFrom("http://localhost:8086"), DB: null.StringFrom("dbname")}, + "http://my.site.io/influxdbA/k6db": { + Addr: null.StringFrom("http://my.site.io/influxdbA"), + DB: null.StringFrom("k6db"), + }, + "http://my.site.io/a/b/c/dbname": { + Addr: null.StringFrom("http://my.site.io/a/b/c"), + DB: null.StringFrom("dbname"), + }, + "http://my.site.io/prefix/": {Addr: null.StringFrom("http://my.site.io/prefix")}, } queries := map[string]struct { Config Config diff --git a/internal/output/influxdb/output_test.go b/internal/output/influxdb/output_test.go index d70f4f377..debb7c36f 100644 --- a/internal/output/influxdb/output_test.go +++ b/internal/output/influxdb/output_test.go @@ -133,6 +133,50 @@ func TestOutput(t *testing.T) { }) } +func TestOutputWritesToURLPathPrefix(t *testing.T) { + t.Parallel() + + var ( + mu sync.Mutex + gotPath string + ) + ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { + if r.URL.Path != "/ping" { + mu.Lock() + gotPath = r.URL.Path + mu.Unlock() + } + rw.WriteHeader(http.StatusNoContent) + })) + defer ts.Close() + + registry := metrics.NewRegistry() + metric, err := registry.NewMetric("test_gauge", metrics.Gauge) + require.NoError(t, err) + + o, err := newOutput(output.Params{ + Logger: testutils.NewLogger(t), + ConfigArgument: ts.URL + "/influxdbA/k6db", + }) + require.NoError(t, err) + require.Equal(t, "k6db", o.Config.DB.String) + require.Equal(t, ts.URL+"/influxdbA", o.Config.Addr.String) + + require.NoError(t, o.Start()) + o.AddMetricSamples([]metrics.SampleContainer{metrics.Samples{ + metrics.Sample{ + TimeSeries: metrics.TimeSeries{Metric: metric, Tags: registry.RootTagSet()}, + Time: time.Now(), + Value: 1.0, + }, + }}) + require.NoError(t, o.Stop()) + + mu.Lock() + defer mu.Unlock() + assert.Equal(t, "/influxdbA/write", gotPath) +} + func TestOutputFlushMetricsConcurrency(t *testing.T) { t.Parallel() From 87883075ccd5e3d3fb961a860b3d6e422bbc353b Mon Sep 17 00:00:00 2001 From: Inanc Gumus Date: Fri, 21 Aug 2026 09:43:41 -0400 Subject: [PATCH 117/182] Automate the second approval for Renovate PRs (#6277) Renovate PRs need two approvals. k6-core-bot supplies one only after its gates pass (trusted update, green CI, no conflicts), and a human still had to supply the other, so vetted dependency updates sat waiting for reviews. Reacting to the bot's approval reuses those gates and lets Renovate merge vetted updates on its own; everything the bot does not approve still needs two humans. --- .github/workflows/second-approve-renovate.yml | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/workflows/second-approve-renovate.yml diff --git a/.github/workflows/second-approve-renovate.yml b/.github/workflows/second-approve-renovate.yml new file mode 100644 index 000000000..cbb0dffef --- /dev/null +++ b/.github/workflows/second-approve-renovate.yml @@ -0,0 +1,22 @@ +name: Second approval for Renovate +on: + pull_request_review: + types: [submitted] + +permissions: {} + +jobs: + approve: + if: > + github.event.review.state == 'approved' && + github.event.review.user.login == 'k6-core-bot[bot]' && + github.event.pull_request.user.login == 'renovate-sh-app[bot]' + runs-on: ubuntu-latest + permissions: + pull-requests: write + steps: + - name: Approve + env: + GH_TOKEN: ${{ github.token }} + PR: ${{ github.event.pull_request.number }} + run: gh pr review "$PR" --repo "$GITHUB_REPOSITORY" --approve From 0e3693411ede178d33a18df189ac03a62df2bd4d Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Tue, 25 Aug 2026 09:54:40 +0100 Subject: [PATCH 118/182] fix(deps): update module github.com/stretchr/testify to v1.12.1 (#6332) | datasource | package | from | to | | ---------- | --------------------------- | ------- | ------- | | go | github.com/stretchr/testify | v1.11.1 | v1.12.1 | Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> --- go.mod | 5 +- go.sum | 10 +- .../testify/assert/assertion_format.go | 28 +- .../testify/assert/assertion_forward.go | 52 +- .../testify/assert/assertion_order.go | 14 +- .../stretchr/testify/assert/assertions.go | 147 +- .../github.com/stretchr/testify/assert/doc.go | 4 +- .../testify/assert/yaml/yaml_custom.go | 2 +- .../testify/assert/yaml/yaml_default.go | 6 +- .../stretchr/testify/assert/yaml/yaml_fail.go | 2 +- .../testify/internal/difflib}/LICENSE | 2 +- .../testify/internal}/difflib/difflib.go | 206 +- .../testify/internal/spew}/LICENSE | 0 .../testify/internal}/spew/bypass.go | 1 + .../testify/internal}/spew/bypasssafe.go | 1 + .../testify/internal}/spew/common.go | 0 .../testify/internal}/spew/config.go | 30 +- .../testify/internal}/spew/doc.go | 146 +- .../testify/internal}/spew/dump.go | 18 +- .../testify/internal}/spew/format.go | 0 .../testify/internal}/spew/spew.go | 0 .../stretchr/testify/require/doc.go | 6 +- .../stretchr/testify/require/require.go | 102 +- .../testify/require/require_forward.go | 100 +- .../stretchr/testify/require/requirements.go | 8 +- vendor/go.yaml.in/yaml/v3/LICENSE | 50 + vendor/go.yaml.in/yaml/v3/NOTICE | 13 + vendor/go.yaml.in/yaml/v3/apic.go | 747 ++++ vendor/go.yaml.in/yaml/v3/decode.go | 1018 ++++++ vendor/go.yaml.in/yaml/v3/emitterc.go | 2054 +++++++++++ vendor/go.yaml.in/yaml/v3/encode.go | 577 ++++ vendor/go.yaml.in/yaml/v3/parserc.go | 1260 +++++++ vendor/go.yaml.in/yaml/v3/readerc.go | 434 +++ vendor/go.yaml.in/yaml/v3/resolve.go | 326 ++ vendor/go.yaml.in/yaml/v3/scannerc.go | 3040 +++++++++++++++++ vendor/go.yaml.in/yaml/v3/sorter.go | 134 + vendor/go.yaml.in/yaml/v3/writerc.go | 48 + vendor/go.yaml.in/yaml/v3/yaml.go | 703 ++++ vendor/go.yaml.in/yaml/v3/yamlh.go | 807 +++++ vendor/go.yaml.in/yaml/v3/yamlprivateh.go | 198 ++ vendor/modules.txt | 13 +- 41 files changed, 11802 insertions(+), 510 deletions(-) rename vendor/github.com/{pmezard/go-difflib => stretchr/testify/internal/difflib}/LICENSE (95%) rename vendor/github.com/{pmezard/go-difflib => stretchr/testify/internal}/difflib/difflib.go (77%) rename vendor/github.com/{davecgh/go-spew => stretchr/testify/internal/spew}/LICENSE (100%) rename vendor/github.com/{davecgh/go-spew => stretchr/testify/internal}/spew/bypass.go (98%) rename vendor/github.com/{davecgh/go-spew => stretchr/testify/internal}/spew/bypasssafe.go (96%) rename vendor/github.com/{davecgh/go-spew => stretchr/testify/internal}/spew/common.go (100%) rename vendor/github.com/{davecgh/go-spew => stretchr/testify/internal}/spew/config.go (95%) rename vendor/github.com/{davecgh/go-spew => stretchr/testify/internal}/spew/doc.go (65%) rename vendor/github.com/{davecgh/go-spew => stretchr/testify/internal}/spew/dump.go (96%) rename vendor/github.com/{davecgh/go-spew => stretchr/testify/internal}/spew/format.go (100%) rename vendor/github.com/{davecgh/go-spew => stretchr/testify/internal}/spew/spew.go (100%) create mode 100644 vendor/go.yaml.in/yaml/v3/LICENSE create mode 100644 vendor/go.yaml.in/yaml/v3/NOTICE create mode 100644 vendor/go.yaml.in/yaml/v3/apic.go create mode 100644 vendor/go.yaml.in/yaml/v3/decode.go create mode 100644 vendor/go.yaml.in/yaml/v3/emitterc.go create mode 100644 vendor/go.yaml.in/yaml/v3/encode.go create mode 100644 vendor/go.yaml.in/yaml/v3/parserc.go create mode 100644 vendor/go.yaml.in/yaml/v3/readerc.go create mode 100644 vendor/go.yaml.in/yaml/v3/resolve.go create mode 100644 vendor/go.yaml.in/yaml/v3/scannerc.go create mode 100644 vendor/go.yaml.in/yaml/v3/sorter.go create mode 100644 vendor/go.yaml.in/yaml/v3/writerc.go create mode 100644 vendor/go.yaml.in/yaml/v3/yaml.go create mode 100644 vendor/go.yaml.in/yaml/v3/yamlh.go create mode 100644 vendor/go.yaml.in/yaml/v3/yamlprivateh.go diff --git a/go.mod b/go.mod index bbdaea863..323aec9cb 100644 --- a/go.mod +++ b/go.mod @@ -43,7 +43,7 @@ require ( github.com/spf13/afero v1.1.2 github.com/spf13/cobra v1.4.0 github.com/spf13/pflag v1.0.5 - github.com/stretchr/testify v1.11.1 + github.com/stretchr/testify v1.12.1 github.com/tidwall/gjson v1.19.0 go.opentelemetry.io/otel v1.44.0 go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.44.0 @@ -76,7 +76,6 @@ require ( github.com/cenkalti/backoff/v5 v5.0.3 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/chromedp/sysutil v1.1.0 // indirect - github.com/davecgh/go-spew v1.1.1 // indirect github.com/dlclark/regexp2/v2 v2.5.2 // indirect github.com/go-logr/logr v1.4.3 // indirect github.com/go-logr/stdr v1.2.2 // indirect @@ -89,12 +88,12 @@ require ( github.com/nxadm/tail v1.4.11 // indirect github.com/onsi/ginkgo v1.16.5 // indirect github.com/onsi/gomega v1.39.1 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/common v0.70.1 // indirect github.com/prometheus/procfs v0.21.1 // indirect github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/pretty v1.2.1 // indirect go.opentelemetry.io/auto/sdk v1.2.1 // indirect + go.yaml.in/yaml/v3 v3.0.5 // indirect golang.org/x/sys v0.47.0 // indirect golang.org/x/text v0.41.0 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20260720211330-0afa2a65878a // indirect diff --git a/go.sum b/go.sum index 23ad7dbf0..976a6d7fa 100644 --- a/go.sum +++ b/go.sum @@ -34,7 +34,6 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dlclark/regexp2/v2 v2.5.2 h1:HAsucWRhsqcDzl6Ua9aR8JwYOTzrZyPrF0/FNxJVAI0= github.com/dlclark/regexp2/v2 v2.5.2/go.mod h1:avUrQvPaLz2DrFNHJF0taWAFFX2C1GMSSoeiqFjcBmU= @@ -161,7 +160,6 @@ github.com/petermattis/goid v0.0.0-20260113132338-7c7de50cc741/go.mod h1:pxMtw7c github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ= github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v1.24.1 h1:JnJkREXzWxUdCuPFpIWZiPispT9xVV59uiuyR2bPlnU= github.com/prometheus/client_golang v1.24.1/go.mod h1:F+oSRECHg4sse5ucfYpYDeIv/hu68Zo0uoHKetWnzcE= @@ -195,8 +193,8 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= -github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= +github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWDWE= +github.com/stretchr/testify v1.12.1/go.mod h1:MDEgiDPPsNp5cuIrHPPCyornHKgEVbtFUmoNlxoYthg= github.com/tidwall/gjson v1.19.0 h1:xwxm7n691Uf3u5OFjzngavjGTh55KX5q/9w9xHW88JU= github.com/tidwall/gjson v1.19.0/go.mod h1:V37/opeE/JbLUOfH0QTXiNez2l0RUjYUhpT4szFQAfc= github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= @@ -242,8 +240,8 @@ go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9i go.uber.org/zap v1.18.1/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI= go.yaml.in/yaml/v2 v2.4.4 h1:tuyd0P+2Ont/d6e2rl3be67goVK4R6deVxCUX5vyPaQ= go.yaml.in/yaml/v2 v2.4.4/go.mod h1:gMZqIpDtDqOfM0uNfy0SkpRhvUryYH0Z6wdMYcacYXQ= -go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc= -go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= +go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw= +go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= diff --git a/vendor/github.com/stretchr/testify/assert/assertion_format.go b/vendor/github.com/stretchr/testify/assert/assertion_format.go index c592f6ad5..a19a89279 100644 --- a/vendor/github.com/stretchr/testify/assert/assertion_format.go +++ b/vendor/github.com/stretchr/testify/assert/assertion_format.go @@ -84,7 +84,7 @@ func Equalf(t TestingT, expected interface{}, actual interface{}, msg string, ar return Equal(t, expected, actual, append([]interface{}{msg}, args...)...) } -// EqualErrorf asserts that a function returned an error (i.e. not `nil`) +// EqualErrorf asserts that a function returned a non-nil error (i.e. an error) // and that it is equal to the provided error. // // actualObj, err := SomeFunction() @@ -124,7 +124,7 @@ func EqualValuesf(t TestingT, expected interface{}, actual interface{}, msg stri return EqualValues(t, expected, actual, append([]interface{}{msg}, args...)...) } -// Errorf asserts that a function returned an error (i.e. not `nil`). +// Errorf asserts that a function returned a non-nil error (ie. an error). // // actualObj, err := SomeFunction() // assert.Errorf(t, err, "error message %s", "formatted") @@ -144,8 +144,8 @@ func ErrorAsf(t TestingT, err error, target interface{}, msg string, args ...int return ErrorAs(t, err, target, append([]interface{}{msg}, args...)...) } -// ErrorContainsf asserts that a function returned an error (i.e. not `nil`) -// and that the error contains the specified substring. +// ErrorContainsf asserts that a function returned a non-nil error (i.e. an +// error) and that the error contains the specified substring. // // actualObj, err := SomeFunction() // assert.ErrorContainsf(t, err, expectedErrorSubString, "error message %s", "formatted") @@ -190,10 +190,10 @@ func Eventuallyf(t TestingT, condition func() bool, waitFor time.Duration, tick // time.Sleep(8*time.Second) // externalValue = true // }() -// assert.EventuallyWithTf(t, func(c *assert.CollectT, "error message %s", "formatted") { +// assert.EventuallyWithTf(t, func(c *assert.CollectT) { // // add assertions as needed; any assertion failure will fail the current tick // assert.True(c, externalValue, "expected 'externalValue' to be true") -// }, 10*time.Second, 1*time.Second, "external state has not changed to 'true'; still false") +// }, 10*time.Second, 1*time.Second, "error message %s", "formatted") func EventuallyWithTf(t TestingT, condition func(collect *CollectT), waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) bool { if h, ok := t.(tHelper); ok { h.Helper() @@ -552,7 +552,7 @@ func NoDirExistsf(t TestingT, path string, msg string, args ...interface{}) bool return NoDirExists(t, path, append([]interface{}{msg}, args...)...) } -// NoErrorf asserts that a function returned no error (i.e. `nil`). +// NoErrorf asserts that a function returned a nil error (ie. no error). // // actualObj, err := SomeFunction() // if assert.NoErrorf(t, err, "error message %s", "formatted") { @@ -849,7 +849,19 @@ func WithinRangef(t TestingT, actual time.Time, start time.Time, end time.Time, return WithinRange(t, actual, start, end, append([]interface{}{msg}, args...)...) } -// YAMLEqf asserts that two YAML strings are equivalent. +// YAMLEqf asserts that the first documents in the two YAML strings are equivalent. +// +// expected := `--- +// key: value +// --- +// key: this is a second document, it is not evaluated +// ` +// actual := `--- +// key: value +// --- +// key: this is a subsequent document, it is not evaluated +// ` +// assert.YAMLEqf(t, expected, actual, "error message %s", "formatted") func YAMLEqf(t TestingT, expected string, actual string, msg string, args ...interface{}) bool { if h, ok := t.(tHelper); ok { h.Helper() diff --git a/vendor/github.com/stretchr/testify/assert/assertion_forward.go b/vendor/github.com/stretchr/testify/assert/assertion_forward.go index 58db92845..cd2a86061 100644 --- a/vendor/github.com/stretchr/testify/assert/assertion_forward.go +++ b/vendor/github.com/stretchr/testify/assert/assertion_forward.go @@ -146,7 +146,7 @@ func (a *Assertions) Equal(expected interface{}, actual interface{}, msgAndArgs return Equal(a.t, expected, actual, msgAndArgs...) } -// EqualError asserts that a function returned an error (i.e. not `nil`) +// EqualError asserts that a function returned a non-nil error (i.e. an error) // and that it is equal to the provided error. // // actualObj, err := SomeFunction() @@ -158,7 +158,7 @@ func (a *Assertions) EqualError(theError error, errString string, msgAndArgs ... return EqualError(a.t, theError, errString, msgAndArgs...) } -// EqualErrorf asserts that a function returned an error (i.e. not `nil`) +// EqualErrorf asserts that a function returned a non-nil error (i.e. an error) // and that it is equal to the provided error. // // actualObj, err := SomeFunction() @@ -240,7 +240,7 @@ func (a *Assertions) Equalf(expected interface{}, actual interface{}, msg string return Equalf(a.t, expected, actual, msg, args...) } -// Error asserts that a function returned an error (i.e. not `nil`). +// Error asserts that a function returned a non-nil error (ie. an error). // // actualObj, err := SomeFunction() // a.Error(err) @@ -269,8 +269,8 @@ func (a *Assertions) ErrorAsf(err error, target interface{}, msg string, args .. return ErrorAsf(a.t, err, target, msg, args...) } -// ErrorContains asserts that a function returned an error (i.e. not `nil`) -// and that the error contains the specified substring. +// ErrorContains asserts that a function returned a non-nil error (i.e. an +// error) and that the error contains the specified substring. // // actualObj, err := SomeFunction() // a.ErrorContains(err, expectedErrorSubString) @@ -281,8 +281,8 @@ func (a *Assertions) ErrorContains(theError error, contains string, msgAndArgs . return ErrorContains(a.t, theError, contains, msgAndArgs...) } -// ErrorContainsf asserts that a function returned an error (i.e. not `nil`) -// and that the error contains the specified substring. +// ErrorContainsf asserts that a function returned a non-nil error (i.e. an +// error) and that the error contains the specified substring. // // actualObj, err := SomeFunction() // a.ErrorContainsf(err, expectedErrorSubString, "error message %s", "formatted") @@ -311,7 +311,7 @@ func (a *Assertions) ErrorIsf(err error, target error, msg string, args ...inter return ErrorIsf(a.t, err, target, msg, args...) } -// Errorf asserts that a function returned an error (i.e. not `nil`). +// Errorf asserts that a function returned a non-nil error (ie. an error). // // actualObj, err := SomeFunction() // a.Errorf(err, "error message %s", "formatted") @@ -372,10 +372,10 @@ func (a *Assertions) EventuallyWithT(condition func(collect *CollectT), waitFor // time.Sleep(8*time.Second) // externalValue = true // }() -// a.EventuallyWithTf(func(c *assert.CollectT, "error message %s", "formatted") { +// a.EventuallyWithTf(func(c *assert.CollectT) { // // add assertions as needed; any assertion failure will fail the current tick // assert.True(c, externalValue, "expected 'externalValue' to be true") -// }, 10*time.Second, 1*time.Second, "external state has not changed to 'true'; still false") +// }, 10*time.Second, 1*time.Second, "error message %s", "formatted") func (a *Assertions) EventuallyWithTf(condition func(collect *CollectT), waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) bool { if h, ok := a.t.(tHelper); ok { h.Helper() @@ -1096,7 +1096,7 @@ func (a *Assertions) NoDirExistsf(path string, msg string, args ...interface{}) return NoDirExistsf(a.t, path, msg, args...) } -// NoError asserts that a function returned no error (i.e. `nil`). +// NoError asserts that a function returned a nil error (ie. no error). // // actualObj, err := SomeFunction() // if a.NoError(err) { @@ -1109,7 +1109,7 @@ func (a *Assertions) NoError(err error, msgAndArgs ...interface{}) bool { return NoError(a.t, err, msgAndArgs...) } -// NoErrorf asserts that a function returned no error (i.e. `nil`). +// NoErrorf asserts that a function returned a nil error (ie. no error). // // actualObj, err := SomeFunction() // if a.NoErrorf(err, "error message %s", "formatted") { @@ -1690,7 +1690,19 @@ func (a *Assertions) WithinRangef(actual time.Time, start time.Time, end time.Ti return WithinRangef(a.t, actual, start, end, msg, args...) } -// YAMLEq asserts that two YAML strings are equivalent. +// YAMLEq asserts that the first documents in the two YAML strings are equivalent. +// +// expected := `--- +// key: value +// --- +// key: this is a second document, it is not evaluated +// ` +// actual := `--- +// key: value +// --- +// key: this is a subsequent document, it is not evaluated +// ` +// a.YAMLEq(expected, actual) func (a *Assertions) YAMLEq(expected string, actual string, msgAndArgs ...interface{}) bool { if h, ok := a.t.(tHelper); ok { h.Helper() @@ -1698,7 +1710,19 @@ func (a *Assertions) YAMLEq(expected string, actual string, msgAndArgs ...interf return YAMLEq(a.t, expected, actual, msgAndArgs...) } -// YAMLEqf asserts that two YAML strings are equivalent. +// YAMLEqf asserts that the first documents in the two YAML strings are equivalent. +// +// expected := `--- +// key: value +// --- +// key: this is a second document, it is not evaluated +// ` +// actual := `--- +// key: value +// --- +// key: this is a subsequent document, it is not evaluated +// ` +// a.YAMLEqf(expected, actual, "error message %s", "formatted") func (a *Assertions) YAMLEqf(expected string, actual string, msg string, args ...interface{}) bool { if h, ok := a.t.(tHelper); ok { h.Helper() diff --git a/vendor/github.com/stretchr/testify/assert/assertion_order.go b/vendor/github.com/stretchr/testify/assert/assertion_order.go index 2fdf80fdd..a44b40ed3 100644 --- a/vendor/github.com/stretchr/testify/assert/assertion_order.go +++ b/vendor/github.com/stretchr/testify/assert/assertion_order.go @@ -9,7 +9,7 @@ import ( func isOrdered(t TestingT, object interface{}, allowedComparesResults []compareResult, failMessage string, msgAndArgs ...interface{}) bool { objKind := reflect.TypeOf(object).Kind() if objKind != reflect.Slice && objKind != reflect.Array { - return false + return Fail(t, fmt.Sprintf("object %T is not an ordered collection", object), msgAndArgs...) } objValue := reflect.ValueOf(object) @@ -50,6 +50,9 @@ func isOrdered(t TestingT, object interface{}, allowedComparesResults []compareR // assert.IsIncreasing(t, []float{1, 2}) // assert.IsIncreasing(t, []string{"a", "b"}) func IsIncreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) bool { + if h, ok := t.(tHelper); ok { + h.Helper() + } return isOrdered(t, object, []compareResult{compareLess}, "\"%v\" is not less than \"%v\"", msgAndArgs...) } @@ -59,6 +62,9 @@ func IsIncreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) boo // assert.IsNonIncreasing(t, []float{2, 1}) // assert.IsNonIncreasing(t, []string{"b", "a"}) func IsNonIncreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) bool { + if h, ok := t.(tHelper); ok { + h.Helper() + } return isOrdered(t, object, []compareResult{compareEqual, compareGreater}, "\"%v\" is not greater than or equal to \"%v\"", msgAndArgs...) } @@ -68,6 +74,9 @@ func IsNonIncreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) // assert.IsDecreasing(t, []float{2, 1}) // assert.IsDecreasing(t, []string{"b", "a"}) func IsDecreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) bool { + if h, ok := t.(tHelper); ok { + h.Helper() + } return isOrdered(t, object, []compareResult{compareGreater}, "\"%v\" is not greater than \"%v\"", msgAndArgs...) } @@ -77,5 +86,8 @@ func IsDecreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) boo // assert.IsNonDecreasing(t, []float{1, 2}) // assert.IsNonDecreasing(t, []string{"a", "b"}) func IsNonDecreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) bool { + if h, ok := t.(tHelper); ok { + h.Helper() + } return isOrdered(t, object, []compareResult{compareLess, compareEqual}, "\"%v\" is not less than or equal to \"%v\"", msgAndArgs...) } diff --git a/vendor/github.com/stretchr/testify/assert/assertions.go b/vendor/github.com/stretchr/testify/assert/assertions.go index de8de0cb6..166f63726 100644 --- a/vendor/github.com/stretchr/testify/assert/assertions.go +++ b/vendor/github.com/stretchr/testify/assert/assertions.go @@ -17,11 +17,10 @@ import ( "unicode" "unicode/utf8" - "github.com/davecgh/go-spew/spew" - "github.com/pmezard/go-difflib/difflib" - - // Wrapper around gopkg.in/yaml.v3 + // Wrapper around go.yaml.in/yaml/v3 "github.com/stretchr/testify/assert/yaml" + "github.com/stretchr/testify/internal/difflib" + "github.com/stretchr/testify/internal/spew" ) //go:generate sh -c "cd ../_codegen && go build && cd - && ../_codegen/_codegen -output-package=assert -template=assertion_format.go.tmpl" @@ -33,19 +32,19 @@ type TestingT interface { // ComparisonAssertionFunc is a common function prototype when comparing two values. Can be useful // for table driven tests. -type ComparisonAssertionFunc func(TestingT, interface{}, interface{}, ...interface{}) bool +type ComparisonAssertionFunc = func(TestingT, interface{}, interface{}, ...interface{}) bool // ValueAssertionFunc is a common function prototype when validating a single value. Can be useful // for table driven tests. -type ValueAssertionFunc func(TestingT, interface{}, ...interface{}) bool +type ValueAssertionFunc = func(TestingT, interface{}, ...interface{}) bool // BoolAssertionFunc is a common function prototype when validating a bool value. Can be useful // for table driven tests. -type BoolAssertionFunc func(TestingT, bool, ...interface{}) bool +type BoolAssertionFunc = func(TestingT, bool, ...interface{}) bool // ErrorAssertionFunc is a common function prototype when validating an error value. Can be useful // for table driven tests. -type ErrorAssertionFunc func(TestingT, error, ...interface{}) bool +type ErrorAssertionFunc = func(TestingT, error, ...interface{}) bool // PanicAssertionFunc is a common function prototype when validating a panic value. Can be useful // for table driven tests. @@ -325,13 +324,15 @@ func messageFromMsgAndArgs(msgAndArgs ...interface{}) string { func indentMessageLines(message string, longestLabelLen int) string { outBuf := new(bytes.Buffer) - for i, scanner := 0, bufio.NewScanner(strings.NewReader(message)); scanner.Scan(); i++ { - // no need to align first line because it starts at the correct location (after the label) - if i != 0 { - // append alignLen+1 spaces to align with "{{longestLabel}}:" before adding tab - outBuf.WriteString("\n\t" + strings.Repeat(" ", longestLabelLen+1) + "\t") + scanner := bufio.NewScanner(strings.NewReader(message)) + for firstLine := true; scanner.Scan(); firstLine = false { + if !firstLine { + fmt.Fprint(outBuf, "\n\t"+strings.Repeat(" ", longestLabelLen+1)+"\t") } - outBuf.WriteString(scanner.Text()) + fmt.Fprint(outBuf, scanner.Text()) + } + if err := scanner.Err(); err != nil { + return fmt.Sprintf("cannot display message: %s", err) } return outBuf.String() @@ -544,9 +545,8 @@ func Same(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) b if !same { // both are pointers but not the same type & pointing to the same address return Fail(t, fmt.Sprintf("Not same: \n"+ - "expected: %p %#[1]v\n"+ - "actual : %p %#[2]v", - expected, actual), msgAndArgs...) + "expected: %[2]s (%[1]T)(%[1]p)\n"+ + "actual : %[4]s (%[3]T)(%[3]p)", expected, truncatingFormat("%#v", expected), actual, truncatingFormat("%#v", actual)), msgAndArgs...) } return true @@ -571,8 +571,8 @@ func NotSame(t TestingT, expected, actual interface{}, msgAndArgs ...interface{} if same { return Fail(t, fmt.Sprintf( - "Expected and actual point to the same object: %p %#[1]v", - expected), msgAndArgs...) + "Expected and actual point to the same object: %p %s", + expected, truncatingFormat("%#v", expected)), msgAndArgs...) } return true } @@ -604,25 +604,26 @@ func samePointers(first, second interface{}) (same bool, ok bool) { // to a type conversion in the Go grammar. func formatUnequalValues(expected, actual interface{}) (e string, a string) { if reflect.TypeOf(expected) != reflect.TypeOf(actual) { - return fmt.Sprintf("%T(%s)", expected, truncatingFormat(expected)), - fmt.Sprintf("%T(%s)", actual, truncatingFormat(actual)) + return fmt.Sprintf("%T(%s)", expected, truncatingFormat("%#v", expected)), + fmt.Sprintf("%T(%s)", actual, truncatingFormat("%#v", actual)) } switch expected.(type) { case time.Duration: return fmt.Sprintf("%v", expected), fmt.Sprintf("%v", actual) } - return truncatingFormat(expected), truncatingFormat(actual) + return truncatingFormat("%#v", expected), truncatingFormat("%#v", actual) } // truncatingFormat formats the data and truncates it if it's too long. // // This helps keep formatted error messages lines from exceeding the // bufio.MaxScanTokenSize max line length that the go testing framework imposes. -func truncatingFormat(data interface{}) string { - value := fmt.Sprintf("%#v", data) - max := bufio.MaxScanTokenSize - 100 // Give us some space the type info too if needed. - if len(value) > max { - value = value[0:max] + "<... truncated>" +func truncatingFormat(format string, data interface{}) string { + value := fmt.Sprintf(format, data) + // Give us space for two truncated objects and the surrounding sentence. + maxMessageSize := bufio.MaxScanTokenSize/2 - 100 + if len(value) > maxMessageSize { + value = value[0:maxMessageSize] + "<... truncated>" } return value } @@ -743,7 +744,7 @@ func Nil(t TestingT, object interface{}, msgAndArgs ...interface{}) bool { if h, ok := t.(tHelper); ok { h.Helper() } - return Fail(t, fmt.Sprintf("Expected nil, but got: %#v", object), msgAndArgs...) + return Fail(t, fmt.Sprintf("Expected nil, but got: %s", truncatingFormat("%#v", object)), msgAndArgs...) } // isEmpty gets whether the specified object is considered empty or not. @@ -793,7 +794,7 @@ func Empty(t TestingT, object interface{}, msgAndArgs ...interface{}) bool { if h, ok := t.(tHelper); ok { h.Helper() } - Fail(t, fmt.Sprintf("Should be empty, but was %v", object), msgAndArgs...) + Fail(t, fmt.Sprintf("Should be empty, but was %s", truncatingFormat("%v", object)), msgAndArgs...) } return pass @@ -836,11 +837,11 @@ func Len(t TestingT, object interface{}, length int, msgAndArgs ...interface{}) } l, ok := getLen(object) if !ok { - return Fail(t, fmt.Sprintf("\"%v\" could not be applied builtin len()", object), msgAndArgs...) + return Fail(t, fmt.Sprintf("%q could not be applied builtin len()", truncatingFormat("%v", object)), msgAndArgs...) } if l != length { - return Fail(t, fmt.Sprintf("\"%v\" should have %d item(s), but has %d", object, length, l), msgAndArgs...) + return Fail(t, fmt.Sprintf("%q should have %d item(s), but has %d", truncatingFormat("%v", object), length, l), msgAndArgs...) } return true } @@ -889,7 +890,7 @@ func NotEqual(t TestingT, expected, actual interface{}, msgAndArgs ...interface{ } if ObjectsAreEqual(expected, actual) { - return Fail(t, fmt.Sprintf("Should not be: %#v\n", actual), msgAndArgs...) + return Fail(t, fmt.Sprintf("Should not be: %s\n", truncatingFormat("%#v", actual)), msgAndArgs...) } return true @@ -904,7 +905,7 @@ func NotEqualValues(t TestingT, expected, actual interface{}, msgAndArgs ...inte } if ObjectsAreEqualValues(expected, actual) { - return Fail(t, fmt.Sprintf("Should not be: %#v\n", actual), msgAndArgs...) + return Fail(t, fmt.Sprintf("Should not be: %s\n", truncatingFormat("%#v", actual)), msgAndArgs...) } return true @@ -964,10 +965,10 @@ func Contains(t TestingT, s, contains interface{}, msgAndArgs ...interface{}) bo ok, found := containsElement(s, contains) if !ok { - return Fail(t, fmt.Sprintf("%#v could not be applied builtin len()", s), msgAndArgs...) + return Fail(t, fmt.Sprintf("%s could not be applied builtin len()", truncatingFormat("%#v", s)), msgAndArgs...) } if !found { - return Fail(t, fmt.Sprintf("%#v does not contain %#v", s, contains), msgAndArgs...) + return Fail(t, fmt.Sprintf("%s does not contain %#v", truncatingFormat("%#v", s), contains), msgAndArgs...) } return true @@ -986,10 +987,10 @@ func NotContains(t TestingT, s, contains interface{}, msgAndArgs ...interface{}) ok, found := containsElement(s, contains) if !ok { - return Fail(t, fmt.Sprintf("%#v could not be applied builtin len()", s), msgAndArgs...) + return Fail(t, fmt.Sprintf("%s could not be applied builtin len()", truncatingFormat("%#v", s)), msgAndArgs...) } if found { - return Fail(t, fmt.Sprintf("%#v should not contain %#v", s, contains), msgAndArgs...) + return Fail(t, fmt.Sprintf("%s should not contain %#v", truncatingFormat("%#v", s), contains), msgAndArgs...) } return true @@ -1031,10 +1032,10 @@ func Subset(t TestingT, list, subset interface{}, msgAndArgs ...interface{}) (ok av := actualMap.MapIndex(k) if !av.IsValid() { - return Fail(t, fmt.Sprintf("%#v does not contain %#v", list, subset), msgAndArgs...) + return Fail(t, fmt.Sprintf("%s does not contain %s", truncatingFormat("%#v", list), truncatingFormat("%#v", subset)), msgAndArgs...) } if !ObjectsAreEqual(ev.Interface(), av.Interface()) { - return Fail(t, fmt.Sprintf("%#v does not contain %#v", list, subset), msgAndArgs...) + return Fail(t, fmt.Sprintf("%s does not contain %s", truncatingFormat("%#v", list), truncatingFormat("%#v", subset)), msgAndArgs...) } } @@ -1056,7 +1057,7 @@ func Subset(t TestingT, list, subset interface{}, msgAndArgs ...interface{}) (ok return Fail(t, fmt.Sprintf("%#v could not be applied builtin len()", list), msgAndArgs...) } if !found { - return Fail(t, fmt.Sprintf("%#v does not contain %#v", list, element), msgAndArgs...) + return Fail(t, fmt.Sprintf("%s does not contain %#v", truncatingFormat("%#v", list), element), msgAndArgs...) } } @@ -1082,12 +1083,12 @@ func NotSubset(t TestingT, list, subset interface{}, msgAndArgs ...interface{}) listKind := reflect.TypeOf(list).Kind() if listKind != reflect.Array && listKind != reflect.Slice && listKind != reflect.Map { - return Fail(t, fmt.Sprintf("%q has an unsupported type %s", list, listKind), msgAndArgs...) + return Fail(t, fmt.Sprintf("%#v has an unsupported type %s", list, listKind), msgAndArgs...) } subsetKind := reflect.TypeOf(subset).Kind() if subsetKind != reflect.Array && subsetKind != reflect.Slice && subsetKind != reflect.Map { - return Fail(t, fmt.Sprintf("%q has an unsupported type %s", subset, subsetKind), msgAndArgs...) + return Fail(t, fmt.Sprintf("%#v has an unsupported type %s", subset, subsetKind), msgAndArgs...) } if subsetKind == reflect.Map && listKind == reflect.Map { @@ -1106,7 +1107,7 @@ func NotSubset(t TestingT, list, subset interface{}, msgAndArgs ...interface{}) } } - return Fail(t, fmt.Sprintf("%q is a subset of %q", subset, list), msgAndArgs...) + return Fail(t, fmt.Sprintf("%s is a subset of %s", truncatingFormat("%#v", subset), truncatingFormat("%#v", list)), msgAndArgs...) } subsetList := reflect.ValueOf(subset) @@ -1121,14 +1122,14 @@ func NotSubset(t TestingT, list, subset interface{}, msgAndArgs ...interface{}) element := subsetList.Index(i).Interface() ok, found := containsElement(list, element) if !ok { - return Fail(t, fmt.Sprintf("%q could not be applied builtin len()", list), msgAndArgs...) + return Fail(t, fmt.Sprintf("%#v could not be applied builtin len()", list), msgAndArgs...) } if !found { return true } } - return Fail(t, fmt.Sprintf("%q is a subset of %q", subset, list), msgAndArgs...) + return Fail(t, fmt.Sprintf("%s is a subset of %s", truncatingFormat("%#v", subset), truncatingFormat("%#v", list)), msgAndArgs...) } // ElementsMatch asserts that the specified listA(array, slice...) is equal to specified @@ -1343,9 +1344,15 @@ func PanicsWithError(t TestingT, errString string, f PanicTestFunc, msgAndArgs . if !funcDidPanic { return Fail(t, fmt.Sprintf("func %#v should panic\n\tPanic value:\t%#v", f, panicValue), msgAndArgs...) } - panicErr, ok := panicValue.(error) - if !ok || panicErr.Error() != errString { - return Fail(t, fmt.Sprintf("func %#v should panic with error message:\t%#v\n\tPanic value:\t%#v\n\tPanic stack:\t%s", f, errString, panicValue, panickedStack), msgAndArgs...) + panicErr, isError := panicValue.(error) + if !isError || panicErr.Error() != errString { + msg := fmt.Sprintf("func %#v should panic with error message:\t%#v\n", f, errString) + if isError { + msg += fmt.Sprintf("\tError message:\t%#v\n", panicErr.Error()) + } + msg += fmt.Sprintf("\tPanic value:\t%#v\n", panicValue) + msg += fmt.Sprintf("\tPanic stack:\t%s\n", panickedStack) + return Fail(t, msg, msgAndArgs...) } return true @@ -1624,7 +1631,7 @@ func InEpsilonSlice(t TestingT, expected, actual interface{}, epsilon float64, m Errors */ -// NoError asserts that a function returned no error (i.e. `nil`). +// NoError asserts that a function returned a nil error (ie. no error). // // actualObj, err := SomeFunction() // if assert.NoError(t, err) { @@ -1635,13 +1642,13 @@ func NoError(t TestingT, err error, msgAndArgs ...interface{}) bool { if h, ok := t.(tHelper); ok { h.Helper() } - return Fail(t, fmt.Sprintf("Received unexpected error:\n%+v", err), msgAndArgs...) + return Fail(t, fmt.Sprintf("Received unexpected error:\n%s", truncatingFormat("%+v", err)), msgAndArgs...) } return true } -// Error asserts that a function returned an error (i.e. not `nil`). +// Error asserts that a function returned a non-nil error (ie. an error). // // actualObj, err := SomeFunction() // assert.Error(t, err) @@ -1656,7 +1663,7 @@ func Error(t TestingT, err error, msgAndArgs ...interface{}) bool { return true } -// EqualError asserts that a function returned an error (i.e. not `nil`) +// EqualError asserts that a function returned a non-nil error (i.e. an error) // and that it is equal to the provided error. // // actualObj, err := SomeFunction() @@ -1674,13 +1681,13 @@ func EqualError(t TestingT, theError error, errString string, msgAndArgs ...inte if expected != actual { return Fail(t, fmt.Sprintf("Error message not equal:\n"+ "expected: %q\n"+ - "actual : %q", expected, actual), msgAndArgs...) + "actual : %s", expected, truncatingFormat("%q", actual)), msgAndArgs...) } return true } -// ErrorContains asserts that a function returned an error (i.e. not `nil`) -// and that the error contains the specified substring. +// ErrorContains asserts that a function returned a non-nil error (i.e. an +// error) and that the error contains the specified substring. // // actualObj, err := SomeFunction() // assert.ErrorContains(t, err, expectedErrorSubString) @@ -1694,7 +1701,7 @@ func ErrorContains(t TestingT, theError error, contains string, msgAndArgs ...in actual := theError.Error() if !strings.Contains(actual, contains) { - return Fail(t, fmt.Sprintf("Error %#v does not contain %#v", actual, contains), msgAndArgs...) + return Fail(t, fmt.Sprintf("Error %s does not contain %#v", truncatingFormat("%#v", actual), contains), msgAndArgs...) } return true @@ -1760,7 +1767,7 @@ func Zero(t TestingT, i interface{}, msgAndArgs ...interface{}) bool { h.Helper() } if i != nil && !reflect.DeepEqual(i, reflect.Zero(reflect.TypeOf(i)).Interface()) { - return Fail(t, fmt.Sprintf("Should be zero, but was %v", i), msgAndArgs...) + return Fail(t, fmt.Sprintf("Should be zero, but was %s", truncatingFormat("%v", i)), msgAndArgs...) } return true } @@ -1874,7 +1881,19 @@ func JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{ return Equal(t, expectedJSONAsInterface, actualJSONAsInterface, msgAndArgs...) } -// YAMLEq asserts that two YAML strings are equivalent. +// YAMLEq asserts that the first documents in the two YAML strings are equivalent. +// +// expected := `--- +// key: value +// --- +// key: this is a second document, it is not evaluated +// ` +// actual := `--- +// key: value +// --- +// key: this is a subsequent document, it is not evaluated +// ` +// assert.YAMLEq(t, expected, actual) func YAMLEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) bool { if h, ok := t.(tHelper); ok { h.Helper() @@ -2188,8 +2207,8 @@ func ErrorIs(t TestingT, err, target error, msgAndArgs ...interface{}) bool { chain := buildErrorChainString(err, false) return Fail(t, fmt.Sprintf("Target error should be in err chain:\n"+ - "expected: %q\n"+ - "in chain: %s", expectedText, chain, + "expected: %s\n"+ + "in chain: %s", truncatingFormat("%q", expectedText), truncatingFormat("%s", chain), ), msgAndArgs...) } @@ -2211,8 +2230,8 @@ func NotErrorIs(t TestingT, err, target error, msgAndArgs ...interface{}) bool { chain := buildErrorChainString(err, false) return Fail(t, fmt.Sprintf("Target error should not be in err chain:\n"+ - "found: %q\n"+ - "in chain: %s", expectedText, chain, + "found: %s\n"+ + "in chain: %s", truncatingFormat("%q", expectedText), truncatingFormat("%s", chain), ), msgAndArgs...) } @@ -2236,7 +2255,7 @@ func ErrorAs(t TestingT, err error, target interface{}, msgAndArgs ...interface{ return Fail(t, fmt.Sprintf("Should be in error chain:\n"+ "expected: %s\n"+ - "in chain: %s", expectedType, chain, + "in chain: %s", expectedType, truncatingFormat("%s", chain), ), msgAndArgs...) } @@ -2254,7 +2273,7 @@ func NotErrorAs(t TestingT, err error, target interface{}, msgAndArgs ...interfa return Fail(t, fmt.Sprintf("Target error should not be in err chain:\n"+ "found: %s\n"+ - "in chain: %s", reflect.TypeOf(target).Elem().String(), chain, + "in chain: %s", reflect.TypeOf(target).Elem().String(), truncatingFormat("%s", chain), ), msgAndArgs...) } diff --git a/vendor/github.com/stretchr/testify/assert/doc.go b/vendor/github.com/stretchr/testify/assert/doc.go index a0b953aa5..c111589c7 100644 --- a/vendor/github.com/stretchr/testify/assert/doc.go +++ b/vendor/github.com/stretchr/testify/assert/doc.go @@ -40,8 +40,8 @@ // // # Assertions // -// Assertions allow you to easily write test code, and are global funcs in the `assert` package. -// All assertion functions take, as the first argument, the `*testing.T` object provided by the +// Assertions allow you to easily write test code, and are global funcs in the assert package. +// All assertion functions take, as the first argument, the [*testing.T] object provided by the // testing framework. This allows the assertion funcs to write the failings and other details to // the correct place. // diff --git a/vendor/github.com/stretchr/testify/assert/yaml/yaml_custom.go b/vendor/github.com/stretchr/testify/assert/yaml/yaml_custom.go index 5a74c4f4d..956227ca2 100644 --- a/vendor/github.com/stretchr/testify/assert/yaml/yaml_custom.go +++ b/vendor/github.com/stretchr/testify/assert/yaml/yaml_custom.go @@ -7,7 +7,7 @@ // go test -tags testify_yaml_custom // // This implementation can be used at build time to replace the default implementation -// to avoid linking with [gopkg.in/yaml.v3]. +// to avoid linking with [go.yaml.in/yaml/v3]. // // In your test package: // diff --git a/vendor/github.com/stretchr/testify/assert/yaml/yaml_default.go b/vendor/github.com/stretchr/testify/assert/yaml/yaml_default.go index 0bae80e34..dd89ac03a 100644 --- a/vendor/github.com/stretchr/testify/assert/yaml/yaml_default.go +++ b/vendor/github.com/stretchr/testify/assert/yaml/yaml_default.go @@ -6,7 +6,7 @@ // indirection with an alternative implementation of this package that uses // another implementation of YAML deserialization. This allows to not either not // use YAML deserialization at all, or to use another implementation than -// [gopkg.in/yaml.v3] (for example for license compatibility reasons, see [PR #1120]). +// [go.yaml.in/yaml/v3] (for example for license compatibility reasons, see [PR #1120]). // // Alternative implementations are selected using build tags: // @@ -28,9 +28,9 @@ // [PR #1120]: https://github.com/stretchr/testify/pull/1120 package yaml -import goyaml "gopkg.in/yaml.v3" +import goyaml "go.yaml.in/yaml/v3" -// Unmarshal is just a wrapper of [gopkg.in/yaml.v3.Unmarshal]. +// Unmarshal is just a wrapper of [go.yaml.in/yaml/v3.Unmarshal]. func Unmarshal(in []byte, out interface{}) error { return goyaml.Unmarshal(in, out) } diff --git a/vendor/github.com/stretchr/testify/assert/yaml/yaml_fail.go b/vendor/github.com/stretchr/testify/assert/yaml/yaml_fail.go index 8041803fd..a51d27925 100644 --- a/vendor/github.com/stretchr/testify/assert/yaml/yaml_fail.go +++ b/vendor/github.com/stretchr/testify/assert/yaml/yaml_fail.go @@ -3,7 +3,7 @@ // Package yaml is an implementation of YAML functions that always fail. // // This implementation can be used at build time to replace the default implementation -// to avoid linking with [gopkg.in/yaml.v3]: +// to avoid linking with [go.yaml.in/yaml/v3]: // // go test -tags testify_yaml_fail package yaml diff --git a/vendor/github.com/pmezard/go-difflib/LICENSE b/vendor/github.com/stretchr/testify/internal/difflib/LICENSE similarity index 95% rename from vendor/github.com/pmezard/go-difflib/LICENSE rename to vendor/github.com/stretchr/testify/internal/difflib/LICENSE index c67dad612..485be13c6 100644 --- a/vendor/github.com/pmezard/go-difflib/LICENSE +++ b/vendor/github.com/stretchr/testify/internal/difflib/LICENSE @@ -24,4 +24,4 @@ TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/vendor/github.com/pmezard/go-difflib/difflib/difflib.go b/vendor/github.com/stretchr/testify/internal/difflib/difflib.go similarity index 77% rename from vendor/github.com/pmezard/go-difflib/difflib/difflib.go rename to vendor/github.com/stretchr/testify/internal/difflib/difflib.go index 003e99fad..9984599b4 100644 --- a/vendor/github.com/pmezard/go-difflib/difflib/difflib.go +++ b/vendor/github.com/stretchr/testify/internal/difflib/difflib.go @@ -8,11 +8,14 @@ // // - unified_diff // -// - context_diff -// // Getting unified diffs was the main goal of the port. Keep in mind this code // is mostly suitable to output text differences in a human friendly way, there // are no guarantees generated diffs are consumable by patch(1). +// +// This package was adopted from [github.com/pmezard/go-difflib] which +// is no longer maintained. +// +// [github.com/pmezard/go-difflib]: https://github.com/pmezard/go-difflib package difflib import ( @@ -37,13 +40,6 @@ func max(a, b int) int { return b } -func calculateRatio(matches, length int) float64 { - if length > 0 { - return 2.0 * float64(matches) / float64(length) - } - return 1.0 -} - type Match struct { A int B int @@ -103,14 +99,6 @@ func NewMatcher(a, b []string) *SequenceMatcher { return &m } -func NewMatcherWithJunk(a, b []string, autoJunk bool, - isJunk func(string) bool) *SequenceMatcher { - - m := SequenceMatcher{IsJunk: isJunk, autoJunk: autoJunk} - m.SetSeqs(a, b) - return &m -} - // Set two sequences to be compared. func (m *SequenceMatcher) SetSeqs(a, b []string) { m.SetSeq1(a) @@ -199,12 +187,15 @@ func (m *SequenceMatcher) isBJunk(s string) bool { // If IsJunk is not defined: // // Return (i,j,k) such that a[i:i+k] is equal to b[j:j+k], where -// alo <= i <= i+k <= ahi -// blo <= j <= j+k <= bhi +// +// alo <= i <= i+k <= ahi +// blo <= j <= j+k <= bhi +// // and for all (i',j',k') meeting those conditions, -// k >= k' -// i <= i' -// and if i == i', j <= j' +// +// k >= k' +// i <= i' +// and if i == i', j <= j' // // In other words, of all maximal matching blocks, return one that // starts earliest in a, and of all those maximal matching blocks that @@ -451,66 +442,6 @@ func (m *SequenceMatcher) GetGroupedOpCodes(n int) [][]OpCode { return groups } -// Return a measure of the sequences' similarity (float in [0,1]). -// -// Where T is the total number of elements in both sequences, and -// M is the number of matches, this is 2.0*M / T. -// Note that this is 1 if the sequences are identical, and 0 if -// they have nothing in common. -// -// .Ratio() is expensive to compute if you haven't already computed -// .GetMatchingBlocks() or .GetOpCodes(), in which case you may -// want to try .QuickRatio() or .RealQuickRation() first to get an -// upper bound. -func (m *SequenceMatcher) Ratio() float64 { - matches := 0 - for _, m := range m.GetMatchingBlocks() { - matches += m.Size - } - return calculateRatio(matches, len(m.a)+len(m.b)) -} - -// Return an upper bound on ratio() relatively quickly. -// -// This isn't defined beyond that it is an upper bound on .Ratio(), and -// is faster to compute. -func (m *SequenceMatcher) QuickRatio() float64 { - // viewing a and b as multisets, set matches to the cardinality - // of their intersection; this counts the number of matches - // without regard to order, so is clearly an upper bound - if m.fullBCount == nil { - m.fullBCount = map[string]int{} - for _, s := range m.b { - m.fullBCount[s] = m.fullBCount[s] + 1 - } - } - - // avail[x] is the number of times x appears in 'b' less the - // number of times we've seen it in 'a' so far ... kinda - avail := map[string]int{} - matches := 0 - for _, s := range m.a { - n, ok := avail[s] - if !ok { - n = m.fullBCount[s] - } - avail[s] = n - 1 - if n > 0 { - matches += 1 - } - } - return calculateRatio(matches, len(m.a)+len(m.b)) -} - -// Return an upper bound on ratio() very quickly. -// -// This isn't defined beyond that it is an upper bound on .Ratio(), and -// is faster to compute than either .Ratio() or .QuickRatio(). -func (m *SequenceMatcher) RealQuickRatio() float64 { - la, lb := len(m.a), len(m.b) - return calculateRatio(min(la, lb), la+lb) -} - // Convert range to the "ed" format func formatRangeUnified(start, stop int) string { // Per the diff spec at http://www.unix.org/single_unix_specification/ @@ -652,117 +583,6 @@ func formatRangeContext(start, stop int) string { return fmt.Sprintf("%d,%d", beginning, beginning+length-1) } -type ContextDiff UnifiedDiff - -// Compare two sequences of lines; generate the delta as a context diff. -// -// Context diffs are a compact way of showing line changes and a few -// lines of context. The number of context lines is set by diff.Context -// which defaults to three. -// -// By default, the diff control lines (those with *** or ---) are -// created with a trailing newline. -// -// For inputs that do not have trailing newlines, set the diff.Eol -// argument to "" so that the output will be uniformly newline free. -// -// The context diff format normally has a header for filenames and -// modification times. Any or all of these may be specified using -// strings for diff.FromFile, diff.ToFile, diff.FromDate, diff.ToDate. -// The modification times are normally expressed in the ISO 8601 format. -// If not specified, the strings default to blanks. -func WriteContextDiff(writer io.Writer, diff ContextDiff) error { - buf := bufio.NewWriter(writer) - defer buf.Flush() - var diffErr error - wf := func(format string, args ...interface{}) { - _, err := buf.WriteString(fmt.Sprintf(format, args...)) - if diffErr == nil && err != nil { - diffErr = err - } - } - ws := func(s string) { - _, err := buf.WriteString(s) - if diffErr == nil && err != nil { - diffErr = err - } - } - - if len(diff.Eol) == 0 { - diff.Eol = "\n" - } - - prefix := map[byte]string{ - 'i': "+ ", - 'd': "- ", - 'r': "! ", - 'e': " ", - } - - started := false - m := NewMatcher(diff.A, diff.B) - for _, g := range m.GetGroupedOpCodes(diff.Context) { - if !started { - started = true - fromDate := "" - if len(diff.FromDate) > 0 { - fromDate = "\t" + diff.FromDate - } - toDate := "" - if len(diff.ToDate) > 0 { - toDate = "\t" + diff.ToDate - } - if diff.FromFile != "" || diff.ToFile != "" { - wf("*** %s%s%s", diff.FromFile, fromDate, diff.Eol) - wf("--- %s%s%s", diff.ToFile, toDate, diff.Eol) - } - } - - first, last := g[0], g[len(g)-1] - ws("***************" + diff.Eol) - - range1 := formatRangeContext(first.I1, last.I2) - wf("*** %s ****%s", range1, diff.Eol) - for _, c := range g { - if c.Tag == 'r' || c.Tag == 'd' { - for _, cc := range g { - if cc.Tag == 'i' { - continue - } - for _, line := range diff.A[cc.I1:cc.I2] { - ws(prefix[cc.Tag] + line) - } - } - break - } - } - - range2 := formatRangeContext(first.J1, last.J2) - wf("--- %s ----%s", range2, diff.Eol) - for _, c := range g { - if c.Tag == 'r' || c.Tag == 'i' { - for _, cc := range g { - if cc.Tag == 'd' { - continue - } - for _, line := range diff.B[cc.J1:cc.J2] { - ws(prefix[cc.Tag] + line) - } - } - break - } - } - } - return diffErr -} - -// Like WriteContextDiff but returns the diff a string. -func GetContextDiffString(diff ContextDiff) (string, error) { - w := &bytes.Buffer{} - err := WriteContextDiff(w, diff) - return string(w.Bytes()), err -} - // Split a string on "\n" while preserving them. The output can be used // as input for UnifiedDiff and ContextDiff structures. func SplitLines(s string) []string { diff --git a/vendor/github.com/davecgh/go-spew/LICENSE b/vendor/github.com/stretchr/testify/internal/spew/LICENSE similarity index 100% rename from vendor/github.com/davecgh/go-spew/LICENSE rename to vendor/github.com/stretchr/testify/internal/spew/LICENSE diff --git a/vendor/github.com/davecgh/go-spew/spew/bypass.go b/vendor/github.com/stretchr/testify/internal/spew/bypass.go similarity index 98% rename from vendor/github.com/davecgh/go-spew/spew/bypass.go rename to vendor/github.com/stretchr/testify/internal/spew/bypass.go index 792994785..70ddeaad3 100644 --- a/vendor/github.com/davecgh/go-spew/spew/bypass.go +++ b/vendor/github.com/stretchr/testify/internal/spew/bypass.go @@ -18,6 +18,7 @@ // tag is deprecated and thus should not be used. // Go versions prior to 1.4 are disabled because they use a different layout // for interfaces which make the implementation of unsafeReflectValue more complex. +//go:build !js && !appengine && !safe && !disableunsafe && go1.4 // +build !js,!appengine,!safe,!disableunsafe,go1.4 package spew diff --git a/vendor/github.com/davecgh/go-spew/spew/bypasssafe.go b/vendor/github.com/stretchr/testify/internal/spew/bypasssafe.go similarity index 96% rename from vendor/github.com/davecgh/go-spew/spew/bypasssafe.go rename to vendor/github.com/stretchr/testify/internal/spew/bypasssafe.go index 205c28d68..5e2d890d6 100644 --- a/vendor/github.com/davecgh/go-spew/spew/bypasssafe.go +++ b/vendor/github.com/stretchr/testify/internal/spew/bypasssafe.go @@ -16,6 +16,7 @@ // when the code is running on Google App Engine, compiled by GopherJS, or // "-tags safe" is added to the go build command line. The "disableunsafe" // tag is deprecated and thus should not be used. +//go:build js || appengine || safe || disableunsafe || !go1.4 // +build js appengine safe disableunsafe !go1.4 package spew diff --git a/vendor/github.com/davecgh/go-spew/spew/common.go b/vendor/github.com/stretchr/testify/internal/spew/common.go similarity index 100% rename from vendor/github.com/davecgh/go-spew/spew/common.go rename to vendor/github.com/stretchr/testify/internal/spew/common.go diff --git a/vendor/github.com/davecgh/go-spew/spew/config.go b/vendor/github.com/stretchr/testify/internal/spew/config.go similarity index 95% rename from vendor/github.com/davecgh/go-spew/spew/config.go rename to vendor/github.com/stretchr/testify/internal/spew/config.go index 2e3d22f31..161895fc6 100644 --- a/vendor/github.com/davecgh/go-spew/spew/config.go +++ b/vendor/github.com/stretchr/testify/internal/spew/config.go @@ -254,15 +254,15 @@ pointer addresses used to indirect to the final value. It provides the following features over the built-in printing facilities provided by the fmt package: - * Pointers are dereferenced and followed - * Circular data structures are detected and handled properly - * Custom Stringer/error interfaces are optionally invoked, including - on unexported types - * Custom types which only implement the Stringer/error interfaces via - a pointer receiver are optionally invoked when passing non-pointer - variables - * Byte arrays and slices are dumped like the hexdump -C command which - includes offsets, byte values in hex, and ASCII output + - Pointers are dereferenced and followed + - Circular data structures are detected and handled properly + - Custom Stringer/error interfaces are optionally invoked, including + on unexported types + - Custom types which only implement the Stringer/error interfaces via + a pointer receiver are optionally invoked when passing non-pointer + variables + - Byte arrays and slices are dumped like the hexdump -C command which + includes offsets, byte values in hex, and ASCII output The configuration options are controlled by modifying the public members of c. See ConfigState for options documentation. @@ -295,12 +295,12 @@ func (c *ConfigState) convertArgs(args []interface{}) (formatters []interface{}) // NewDefaultConfig returns a ConfigState with the following default settings. // -// Indent: " " -// MaxDepth: 0 -// DisableMethods: false -// DisablePointerMethods: false -// ContinueOnMethod: false -// SortKeys: false +// Indent: " " +// MaxDepth: 0 +// DisableMethods: false +// DisablePointerMethods: false +// ContinueOnMethod: false +// SortKeys: false func NewDefaultConfig() *ConfigState { return &ConfigState{Indent: " "} } diff --git a/vendor/github.com/davecgh/go-spew/spew/doc.go b/vendor/github.com/stretchr/testify/internal/spew/doc.go similarity index 65% rename from vendor/github.com/davecgh/go-spew/spew/doc.go rename to vendor/github.com/stretchr/testify/internal/spew/doc.go index aacaac6f1..722e9aa79 100644 --- a/vendor/github.com/davecgh/go-spew/spew/doc.go +++ b/vendor/github.com/stretchr/testify/internal/spew/doc.go @@ -21,35 +21,36 @@ debugging. A quick overview of the additional features spew provides over the built-in printing facilities for Go data types are as follows: - * Pointers are dereferenced and followed - * Circular data structures are detected and handled properly - * Custom Stringer/error interfaces are optionally invoked, including - on unexported types - * Custom types which only implement the Stringer/error interfaces via - a pointer receiver are optionally invoked when passing non-pointer - variables - * Byte arrays and slices are dumped like the hexdump -C command which - includes offsets, byte values in hex, and ASCII output (only when using - Dump style) + - Pointers are dereferenced and followed + - Circular data structures are detected and handled properly + - Custom Stringer/error interfaces are optionally invoked, including + on unexported types + - Custom types which only implement the Stringer/error interfaces via + a pointer receiver are optionally invoked when passing non-pointer + variables + - Byte arrays and slices are dumped like the hexdump -C command which + includes offsets, byte values in hex, and ASCII output (only when using + Dump style) There are two different approaches spew allows for dumping Go data structures: - * Dump style which prints with newlines, customizable indentation, - and additional debug information such as types and all pointer addresses - used to indirect to the final value - * A custom Formatter interface that integrates cleanly with the standard fmt - package and replaces %v, %+v, %#v, and %#+v to provide inline printing - similar to the default %v while providing the additional functionality - outlined above and passing unsupported format verbs such as %x and %q - along to fmt + - Dump style which prints with newlines, customizable indentation, + and additional debug information such as types and all pointer addresses + used to indirect to the final value + - A custom Formatter interface that integrates cleanly with the standard fmt + package and replaces %v, %+v, %#v, and %#+v to provide inline printing + similar to the default %v while providing the additional functionality + outlined above and passing unsupported format verbs such as %x and %q + along to fmt -Quick Start +# Quick Start This section demonstrates how to quickly get started with spew. See the sections below for further details on formatting and configuration options. To dump a variable with full newlines, indentation, type, and pointer information use Dump, Fdump, or Sdump: + spew.Dump(myVar1, myVar2, ...) spew.Fdump(someWriter, myVar1, myVar2, ...) str := spew.Sdump(myVar1, myVar2, ...) @@ -58,12 +59,13 @@ Alternatively, if you would prefer to use format strings with a compacted inline printing style, use the convenience wrappers Printf, Fprintf, etc with %v (most compact), %+v (adds pointer addresses), %#v (adds types), or %#+v (adds types and pointer addresses): + spew.Printf("myVar1: %v -- myVar2: %+v", myVar1, myVar2) spew.Printf("myVar3: %#v -- myVar4: %#+v", myVar3, myVar4) spew.Fprintf(someWriter, "myVar1: %v -- myVar2: %+v", myVar1, myVar2) spew.Fprintf(someWriter, "myVar3: %#v -- myVar4: %#+v", myVar3, myVar4) -Configuration Options +# Configuration Options Configuration of spew is handled by fields in the ConfigState type. For convenience, all of the top-level functions use a global state available @@ -74,51 +76,52 @@ equivalent to the top-level functions. This allows concurrent configuration options. See the ConfigState documentation for more details. The following configuration options are available: - * Indent - String to use for each indentation level for Dump functions. - It is a single space by default. A popular alternative is "\t". - - * MaxDepth - Maximum number of levels to descend into nested data structures. - There is no limit by default. - - * DisableMethods - Disables invocation of error and Stringer interface methods. - Method invocation is enabled by default. - - * DisablePointerMethods - Disables invocation of error and Stringer interface methods on types - which only accept pointer receivers from non-pointer variables. - Pointer method invocation is enabled by default. - - * DisablePointerAddresses - DisablePointerAddresses specifies whether to disable the printing of - pointer addresses. This is useful when diffing data structures in tests. - - * DisableCapacities - DisableCapacities specifies whether to disable the printing of - capacities for arrays, slices, maps and channels. This is useful when - diffing data structures in tests. - - * ContinueOnMethod - Enables recursion into types after invoking error and Stringer interface - methods. Recursion after method invocation is disabled by default. - - * SortKeys - Specifies map keys should be sorted before being printed. Use - this to have a more deterministic, diffable output. Note that - only native types (bool, int, uint, floats, uintptr and string) - and types which implement error or Stringer interfaces are - supported with other types sorted according to the - reflect.Value.String() output which guarantees display - stability. Natural map order is used by default. - - * SpewKeys - Specifies that, as a last resort attempt, map keys should be - spewed to strings and sorted by those strings. This is only - considered if SortKeys is true. - -Dump Usage + + - Indent + String to use for each indentation level for Dump functions. + It is a single space by default. A popular alternative is "\t". + + - MaxDepth + Maximum number of levels to descend into nested data structures. + There is no limit by default. + + - DisableMethods + Disables invocation of error and Stringer interface methods. + Method invocation is enabled by default. + + - DisablePointerMethods + Disables invocation of error and Stringer interface methods on types + which only accept pointer receivers from non-pointer variables. + Pointer method invocation is enabled by default. + + - DisablePointerAddresses + DisablePointerAddresses specifies whether to disable the printing of + pointer addresses. This is useful when diffing data structures in tests. + + - DisableCapacities + DisableCapacities specifies whether to disable the printing of + capacities for arrays, slices, maps and channels. This is useful when + diffing data structures in tests. + + - ContinueOnMethod + Enables recursion into types after invoking error and Stringer interface + methods. Recursion after method invocation is disabled by default. + + - SortKeys + Specifies map keys should be sorted before being printed. Use + this to have a more deterministic, diffable output. Note that + only native types (bool, int, uint, floats, uintptr and string) + and types which implement error or Stringer interfaces are + supported with other types sorted according to the + reflect.Value.String() output which guarantees display + stability. Natural map order is used by default. + + - SpewKeys + Specifies that, as a last resort attempt, map keys should be + spewed to strings and sorted by those strings. This is only + considered if SortKeys is true. + +# Dump Usage Simply call spew.Dump with a list of variables you want to dump: @@ -133,7 +136,7 @@ A third option is to call spew.Sdump to get the formatted output as a string: str := spew.Sdump(myVar1, myVar2, ...) -Sample Dump Output +# Sample Dump Output See the Dump example for details on the setup of the types and variables being shown here. @@ -150,13 +153,14 @@ shown here. Byte (and uint8) arrays and slices are displayed uniquely like the hexdump -C command as shown. + ([]uint8) (len=32 cap=32) { 00000000 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 |............... | 00000010 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 |!"#$%&'()*+,-./0| 00000020 31 32 |12| } -Custom Formatter +# Custom Formatter Spew provides a custom formatter that implements the fmt.Formatter interface so that it integrates cleanly with standard fmt package printing functions. The @@ -170,7 +174,7 @@ standard fmt package for formatting. In addition, the custom formatter ignores the width and precision arguments (however they will still work on the format specifiers not handled by the custom formatter). -Custom Formatter Usage +# Custom Formatter Usage The simplest way to make use of the spew custom formatter is to call one of the convenience functions such as spew.Printf, spew.Println, or spew.Printf. The @@ -184,15 +188,17 @@ functions have syntax you are most likely already familiar with: See the Index for the full list convenience functions. -Sample Formatter Output +# Sample Formatter Output Double pointer to a uint8: + %v: <**>5 %+v: <**>(0xf8400420d0->0xf8400420c8)5 %#v: (**uint8)5 %#+v: (**uint8)(0xf8400420d0->0xf8400420c8)5 Pointer to circular struct with a uint8 field and a pointer to itself: + %v: <*>{1 <*>} %+v: <*>(0xf84003e260){ui8:1 c:<*>(0xf84003e260)} %#v: (*main.circular){ui8:(uint8)1 c:(*main.circular)} @@ -201,7 +207,7 @@ Pointer to circular struct with a uint8 field and a pointer to itself: See the Printf example for details on the setup of variables being shown here. -Errors +# Errors Since it is possible for custom Stringer/error interfaces to panic, spew detects them and handles them internally by printing the panic information diff --git a/vendor/github.com/davecgh/go-spew/spew/dump.go b/vendor/github.com/stretchr/testify/internal/spew/dump.go similarity index 96% rename from vendor/github.com/davecgh/go-spew/spew/dump.go rename to vendor/github.com/stretchr/testify/internal/spew/dump.go index f78d89fc1..8323041a4 100644 --- a/vendor/github.com/davecgh/go-spew/spew/dump.go +++ b/vendor/github.com/stretchr/testify/internal/spew/dump.go @@ -488,15 +488,15 @@ pointer addresses used to indirect to the final value. It provides the following features over the built-in printing facilities provided by the fmt package: - * Pointers are dereferenced and followed - * Circular data structures are detected and handled properly - * Custom Stringer/error interfaces are optionally invoked, including - on unexported types - * Custom types which only implement the Stringer/error interfaces via - a pointer receiver are optionally invoked when passing non-pointer - variables - * Byte arrays and slices are dumped like the hexdump -C command which - includes offsets, byte values in hex, and ASCII output + - Pointers are dereferenced and followed + - Circular data structures are detected and handled properly + - Custom Stringer/error interfaces are optionally invoked, including + on unexported types + - Custom types which only implement the Stringer/error interfaces via + a pointer receiver are optionally invoked when passing non-pointer + variables + - Byte arrays and slices are dumped like the hexdump -C command which + includes offsets, byte values in hex, and ASCII output The configuration options are controlled by an exported package global, spew.Config. See ConfigState for options documentation. diff --git a/vendor/github.com/davecgh/go-spew/spew/format.go b/vendor/github.com/stretchr/testify/internal/spew/format.go similarity index 100% rename from vendor/github.com/davecgh/go-spew/spew/format.go rename to vendor/github.com/stretchr/testify/internal/spew/format.go diff --git a/vendor/github.com/davecgh/go-spew/spew/spew.go b/vendor/github.com/stretchr/testify/internal/spew/spew.go similarity index 100% rename from vendor/github.com/davecgh/go-spew/spew/spew.go rename to vendor/github.com/stretchr/testify/internal/spew/spew.go diff --git a/vendor/github.com/stretchr/testify/require/doc.go b/vendor/github.com/stretchr/testify/require/doc.go index c8e3f94a8..ee84cc479 100644 --- a/vendor/github.com/stretchr/testify/require/doc.go +++ b/vendor/github.com/stretchr/testify/require/doc.go @@ -1,4 +1,4 @@ -// Package require implements the same assertions as the `assert` package but +// Package require implements the same assertions as the assert package but // stops test execution when a test fails. // // # Example Usage @@ -21,8 +21,8 @@ // // # Assertions // -// The `require` package have same global functions as in the `assert` package, -// but instead of returning a boolean result they call `t.FailNow()`. +// The require package have same global functions as in the assert package, +// but instead of returning a boolean result they call [testing.T.FailNow]. // A consequence of this is that it must be called from the goroutine running // the test function, not from other goroutines created during the test. // diff --git a/vendor/github.com/stretchr/testify/require/require.go b/vendor/github.com/stretchr/testify/require/require.go index 2d02f9bce..652871f2e 100644 --- a/vendor/github.com/stretchr/testify/require/require.go +++ b/vendor/github.com/stretchr/testify/require/require.go @@ -180,7 +180,7 @@ func Equal(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...i t.FailNow() } -// EqualError asserts that a function returned an error (i.e. not `nil`) +// EqualError asserts that a function returned a non-nil error (i.e. an error) // and that it is equal to the provided error. // // actualObj, err := SomeFunction() @@ -195,7 +195,7 @@ func EqualError(t TestingT, theError error, errString string, msgAndArgs ...inte t.FailNow() } -// EqualErrorf asserts that a function returned an error (i.e. not `nil`) +// EqualErrorf asserts that a function returned a non-nil error (i.e. an error) // and that it is equal to the provided error. // // actualObj, err := SomeFunction() @@ -295,7 +295,7 @@ func Equalf(t TestingT, expected interface{}, actual interface{}, msg string, ar t.FailNow() } -// Error asserts that a function returned an error (i.e. not `nil`). +// Error asserts that a function returned a non-nil error (ie. an error). // // actualObj, err := SomeFunction() // require.Error(t, err) @@ -333,8 +333,8 @@ func ErrorAsf(t TestingT, err error, target interface{}, msg string, args ...int t.FailNow() } -// ErrorContains asserts that a function returned an error (i.e. not `nil`) -// and that the error contains the specified substring. +// ErrorContains asserts that a function returned a non-nil error (i.e. an +// error) and that the error contains the specified substring. // // actualObj, err := SomeFunction() // require.ErrorContains(t, err, expectedErrorSubString) @@ -348,8 +348,8 @@ func ErrorContains(t TestingT, theError error, contains string, msgAndArgs ...in t.FailNow() } -// ErrorContainsf asserts that a function returned an error (i.e. not `nil`) -// and that the error contains the specified substring. +// ErrorContainsf asserts that a function returned a non-nil error (i.e. an +// error) and that the error contains the specified substring. // // actualObj, err := SomeFunction() // require.ErrorContainsf(t, err, expectedErrorSubString, "error message %s", "formatted") @@ -387,7 +387,7 @@ func ErrorIsf(t TestingT, err error, target error, msg string, args ...interface t.FailNow() } -// Errorf asserts that a function returned an error (i.e. not `nil`). +// Errorf asserts that a function returned a non-nil error (ie. an error). // // actualObj, err := SomeFunction() // require.Errorf(t, err, "error message %s", "formatted") @@ -429,7 +429,7 @@ func Eventually(t TestingT, condition func() bool, waitFor time.Duration, tick t // time.Sleep(8*time.Second) // externalValue = true // }() -// require.EventuallyWithT(t, func(c *require.CollectT) { +// require.EventuallyWithT(t, func(c *assert.CollectT) { // // add assertions as needed; any assertion failure will fail the current tick // require.True(c, externalValue, "expected 'externalValue' to be true") // }, 10*time.Second, 1*time.Second, "external state has not changed to 'true'; still false") @@ -457,10 +457,10 @@ func EventuallyWithT(t TestingT, condition func(collect *assert.CollectT), waitF // time.Sleep(8*time.Second) // externalValue = true // }() -// require.EventuallyWithTf(t, func(c *require.CollectT, "error message %s", "formatted") { +// require.EventuallyWithTf(t, func(c *assert.CollectT) { // // add assertions as needed; any assertion failure will fail the current tick // require.True(c, externalValue, "expected 'externalValue' to be true") -// }, 10*time.Second, 1*time.Second, "external state has not changed to 'true'; still false") +// }, 10*time.Second, 1*time.Second, "error message %s", "formatted") func EventuallyWithTf(t TestingT, condition func(collect *assert.CollectT), waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -671,8 +671,6 @@ func Greaterf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...in // body that contains a string. // // require.HTTPBodyContains(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky") -// -// Returns whether the assertion was successful (true) or not (false). func HTTPBodyContains(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -687,8 +685,6 @@ func HTTPBodyContains(t TestingT, handler http.HandlerFunc, method string, url s // body that contains a string. // // require.HTTPBodyContainsf(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted") -// -// Returns whether the assertion was successful (true) or not (false). func HTTPBodyContainsf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -703,8 +699,6 @@ func HTTPBodyContainsf(t TestingT, handler http.HandlerFunc, method string, url // body that does not contain a string. // // require.HTTPBodyNotContains(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky") -// -// Returns whether the assertion was successful (true) or not (false). func HTTPBodyNotContains(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -719,8 +713,6 @@ func HTTPBodyNotContains(t TestingT, handler http.HandlerFunc, method string, ur // body that does not contain a string. // // require.HTTPBodyNotContainsf(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted") -// -// Returns whether the assertion was successful (true) or not (false). func HTTPBodyNotContainsf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -734,8 +726,6 @@ func HTTPBodyNotContainsf(t TestingT, handler http.HandlerFunc, method string, u // HTTPError asserts that a specified handler returns an error status code. // // require.HTTPError(t, myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}} -// -// Returns whether the assertion was successful (true) or not (false). func HTTPError(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -749,8 +739,6 @@ func HTTPError(t TestingT, handler http.HandlerFunc, method string, url string, // HTTPErrorf asserts that a specified handler returns an error status code. // // require.HTTPErrorf(t, myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}} -// -// Returns whether the assertion was successful (true) or not (false). func HTTPErrorf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -764,8 +752,6 @@ func HTTPErrorf(t TestingT, handler http.HandlerFunc, method string, url string, // HTTPRedirect asserts that a specified handler returns a redirect status code. // // require.HTTPRedirect(t, myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}} -// -// Returns whether the assertion was successful (true) or not (false). func HTTPRedirect(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -779,8 +765,6 @@ func HTTPRedirect(t TestingT, handler http.HandlerFunc, method string, url strin // HTTPRedirectf asserts that a specified handler returns a redirect status code. // // require.HTTPRedirectf(t, myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}} -// -// Returns whether the assertion was successful (true) or not (false). func HTTPRedirectf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -794,8 +778,6 @@ func HTTPRedirectf(t TestingT, handler http.HandlerFunc, method string, url stri // HTTPStatusCode asserts that a specified handler returns a specified status code. // // require.HTTPStatusCode(t, myHandler, "GET", "/notImplemented", nil, 501) -// -// Returns whether the assertion was successful (true) or not (false). func HTTPStatusCode(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, statuscode int, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -809,8 +791,6 @@ func HTTPStatusCode(t TestingT, handler http.HandlerFunc, method string, url str // HTTPStatusCodef asserts that a specified handler returns a specified status code. // // require.HTTPStatusCodef(t, myHandler, "GET", "/notImplemented", nil, 501, "error message %s", "formatted") -// -// Returns whether the assertion was successful (true) or not (false). func HTTPStatusCodef(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, statuscode int, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -824,8 +804,6 @@ func HTTPStatusCodef(t TestingT, handler http.HandlerFunc, method string, url st // HTTPSuccess asserts that a specified handler returns a success status code. // // require.HTTPSuccess(t, myHandler, "POST", "http://www.google.com", nil) -// -// Returns whether the assertion was successful (true) or not (false). func HTTPSuccess(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -839,8 +817,6 @@ func HTTPSuccess(t TestingT, handler http.HandlerFunc, method string, url string // HTTPSuccessf asserts that a specified handler returns a success status code. // // require.HTTPSuccessf(t, myHandler, "POST", "http://www.google.com", nil, "error message %s", "formatted") -// -// Returns whether the assertion was successful (true) or not (false). func HTTPSuccessf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1385,12 +1361,11 @@ func NoDirExistsf(t TestingT, path string, msg string, args ...interface{}) { t.FailNow() } -// NoError asserts that a function returned no error (i.e. `nil`). +// NoError asserts that a function returned a nil error (ie. no error). // -// actualObj, err := SomeFunction() -// if require.NoError(t, err) { -// require.Equal(t, expectedObj, actualObj) -// } +// actualObj, err := SomeFunction() +// require.NoError(t, err) +// require.Equal(t, expectedObj, actualObj) func NoError(t TestingT, err error, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1401,12 +1376,11 @@ func NoError(t TestingT, err error, msgAndArgs ...interface{}) { t.FailNow() } -// NoErrorf asserts that a function returned no error (i.e. `nil`). +// NoErrorf asserts that a function returned a nil error (ie. no error). // -// actualObj, err := SomeFunction() -// if require.NoErrorf(t, err, "error message %s", "formatted") { -// require.Equal(t, expectedObj, actualObj) -// } +// actualObj, err := SomeFunction() +// require.NoErrorf(t, err, "error message %s", "formatted") +// require.Equal(t, expectedObj, actualObj) func NoErrorf(t TestingT, err error, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1515,9 +1489,8 @@ func NotElementsMatchf(t TestingT, listA interface{}, listB interface{}, msg str // NotEmpty asserts that the specified object is NOT [Empty]. // -// if require.NotEmpty(t, obj) { -// require.Equal(t, "two", obj[1]) -// } +// require.NotEmpty(t, obj) +// require.Equal(t, "two", obj[1]) func NotEmpty(t TestingT, object interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -1530,9 +1503,8 @@ func NotEmpty(t TestingT, object interface{}, msgAndArgs ...interface{}) { // NotEmptyf asserts that the specified object is NOT [Empty]. // -// if require.NotEmptyf(t, obj, "error message %s", "formatted") { -// require.Equal(t, "two", obj[1]) -// } +// require.NotEmptyf(t, obj, "error message %s", "formatted") +// require.Equal(t, "two", obj[1]) func NotEmptyf(t TestingT, object interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2135,7 +2107,19 @@ func WithinRangef(t TestingT, actual time.Time, start time.Time, end time.Time, t.FailNow() } -// YAMLEq asserts that two YAML strings are equivalent. +// YAMLEq asserts that the first documents in the two YAML strings are equivalent. +// +// expected := `--- +// key: value +// --- +// key: this is a second document, it is not evaluated +// ` +// actual := `--- +// key: value +// --- +// key: this is a subsequent document, it is not evaluated +// ` +// require.YAMLEq(t, expected, actual) func YAMLEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() @@ -2146,7 +2130,19 @@ func YAMLEq(t TestingT, expected string, actual string, msgAndArgs ...interface{ t.FailNow() } -// YAMLEqf asserts that two YAML strings are equivalent. +// YAMLEqf asserts that the first documents in the two YAML strings are equivalent. +// +// expected := `--- +// key: value +// --- +// key: this is a second document, it is not evaluated +// ` +// actual := `--- +// key: value +// --- +// key: this is a subsequent document, it is not evaluated +// ` +// require.YAMLEqf(t, expected, actual, "error message %s", "formatted") func YAMLEqf(t TestingT, expected string, actual string, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() diff --git a/vendor/github.com/stretchr/testify/require/require_forward.go b/vendor/github.com/stretchr/testify/require/require_forward.go index e6f7e9446..edac147ef 100644 --- a/vendor/github.com/stretchr/testify/require/require_forward.go +++ b/vendor/github.com/stretchr/testify/require/require_forward.go @@ -147,7 +147,7 @@ func (a *Assertions) Equal(expected interface{}, actual interface{}, msgAndArgs Equal(a.t, expected, actual, msgAndArgs...) } -// EqualError asserts that a function returned an error (i.e. not `nil`) +// EqualError asserts that a function returned a non-nil error (i.e. an error) // and that it is equal to the provided error. // // actualObj, err := SomeFunction() @@ -159,7 +159,7 @@ func (a *Assertions) EqualError(theError error, errString string, msgAndArgs ... EqualError(a.t, theError, errString, msgAndArgs...) } -// EqualErrorf asserts that a function returned an error (i.e. not `nil`) +// EqualErrorf asserts that a function returned a non-nil error (i.e. an error) // and that it is equal to the provided error. // // actualObj, err := SomeFunction() @@ -241,7 +241,7 @@ func (a *Assertions) Equalf(expected interface{}, actual interface{}, msg string Equalf(a.t, expected, actual, msg, args...) } -// Error asserts that a function returned an error (i.e. not `nil`). +// Error asserts that a function returned a non-nil error (ie. an error). // // actualObj, err := SomeFunction() // a.Error(err) @@ -270,8 +270,8 @@ func (a *Assertions) ErrorAsf(err error, target interface{}, msg string, args .. ErrorAsf(a.t, err, target, msg, args...) } -// ErrorContains asserts that a function returned an error (i.e. not `nil`) -// and that the error contains the specified substring. +// ErrorContains asserts that a function returned a non-nil error (i.e. an +// error) and that the error contains the specified substring. // // actualObj, err := SomeFunction() // a.ErrorContains(err, expectedErrorSubString) @@ -282,8 +282,8 @@ func (a *Assertions) ErrorContains(theError error, contains string, msgAndArgs . ErrorContains(a.t, theError, contains, msgAndArgs...) } -// ErrorContainsf asserts that a function returned an error (i.e. not `nil`) -// and that the error contains the specified substring. +// ErrorContainsf asserts that a function returned a non-nil error (i.e. an +// error) and that the error contains the specified substring. // // actualObj, err := SomeFunction() // a.ErrorContainsf(err, expectedErrorSubString, "error message %s", "formatted") @@ -312,7 +312,7 @@ func (a *Assertions) ErrorIsf(err error, target error, msg string, args ...inter ErrorIsf(a.t, err, target, msg, args...) } -// Errorf asserts that a function returned an error (i.e. not `nil`). +// Errorf asserts that a function returned a non-nil error (ie. an error). // // actualObj, err := SomeFunction() // a.Errorf(err, "error message %s", "formatted") @@ -373,10 +373,10 @@ func (a *Assertions) EventuallyWithT(condition func(collect *assert.CollectT), w // time.Sleep(8*time.Second) // externalValue = true // }() -// a.EventuallyWithTf(func(c *assert.CollectT, "error message %s", "formatted") { +// a.EventuallyWithTf(func(c *assert.CollectT) { // // add assertions as needed; any assertion failure will fail the current tick // assert.True(c, externalValue, "expected 'externalValue' to be true") -// }, 10*time.Second, 1*time.Second, "external state has not changed to 'true'; still false") +// }, 10*time.Second, 1*time.Second, "error message %s", "formatted") func (a *Assertions) EventuallyWithTf(condition func(collect *assert.CollectT), waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) { if h, ok := a.t.(tHelper); ok { h.Helper() @@ -539,8 +539,6 @@ func (a *Assertions) Greaterf(e1 interface{}, e2 interface{}, msg string, args . // body that contains a string. // // a.HTTPBodyContains(myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky") -// -// Returns whether the assertion was successful (true) or not (false). func (a *Assertions) HTTPBodyContains(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) { if h, ok := a.t.(tHelper); ok { h.Helper() @@ -552,8 +550,6 @@ func (a *Assertions) HTTPBodyContains(handler http.HandlerFunc, method string, u // body that contains a string. // // a.HTTPBodyContainsf(myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted") -// -// Returns whether the assertion was successful (true) or not (false). func (a *Assertions) HTTPBodyContainsf(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) { if h, ok := a.t.(tHelper); ok { h.Helper() @@ -565,8 +561,6 @@ func (a *Assertions) HTTPBodyContainsf(handler http.HandlerFunc, method string, // body that does not contain a string. // // a.HTTPBodyNotContains(myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky") -// -// Returns whether the assertion was successful (true) or not (false). func (a *Assertions) HTTPBodyNotContains(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) { if h, ok := a.t.(tHelper); ok { h.Helper() @@ -578,8 +572,6 @@ func (a *Assertions) HTTPBodyNotContains(handler http.HandlerFunc, method string // body that does not contain a string. // // a.HTTPBodyNotContainsf(myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted") -// -// Returns whether the assertion was successful (true) or not (false). func (a *Assertions) HTTPBodyNotContainsf(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) { if h, ok := a.t.(tHelper); ok { h.Helper() @@ -590,8 +582,6 @@ func (a *Assertions) HTTPBodyNotContainsf(handler http.HandlerFunc, method strin // HTTPError asserts that a specified handler returns an error status code. // // a.HTTPError(myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}} -// -// Returns whether the assertion was successful (true) or not (false). func (a *Assertions) HTTPError(handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) { if h, ok := a.t.(tHelper); ok { h.Helper() @@ -602,8 +592,6 @@ func (a *Assertions) HTTPError(handler http.HandlerFunc, method string, url stri // HTTPErrorf asserts that a specified handler returns an error status code. // // a.HTTPErrorf(myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}} -// -// Returns whether the assertion was successful (true) or not (false). func (a *Assertions) HTTPErrorf(handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) { if h, ok := a.t.(tHelper); ok { h.Helper() @@ -614,8 +602,6 @@ func (a *Assertions) HTTPErrorf(handler http.HandlerFunc, method string, url str // HTTPRedirect asserts that a specified handler returns a redirect status code. // // a.HTTPRedirect(myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}} -// -// Returns whether the assertion was successful (true) or not (false). func (a *Assertions) HTTPRedirect(handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) { if h, ok := a.t.(tHelper); ok { h.Helper() @@ -626,8 +612,6 @@ func (a *Assertions) HTTPRedirect(handler http.HandlerFunc, method string, url s // HTTPRedirectf asserts that a specified handler returns a redirect status code. // // a.HTTPRedirectf(myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}} -// -// Returns whether the assertion was successful (true) or not (false). func (a *Assertions) HTTPRedirectf(handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) { if h, ok := a.t.(tHelper); ok { h.Helper() @@ -638,8 +622,6 @@ func (a *Assertions) HTTPRedirectf(handler http.HandlerFunc, method string, url // HTTPStatusCode asserts that a specified handler returns a specified status code. // // a.HTTPStatusCode(myHandler, "GET", "/notImplemented", nil, 501) -// -// Returns whether the assertion was successful (true) or not (false). func (a *Assertions) HTTPStatusCode(handler http.HandlerFunc, method string, url string, values url.Values, statuscode int, msgAndArgs ...interface{}) { if h, ok := a.t.(tHelper); ok { h.Helper() @@ -650,8 +632,6 @@ func (a *Assertions) HTTPStatusCode(handler http.HandlerFunc, method string, url // HTTPStatusCodef asserts that a specified handler returns a specified status code. // // a.HTTPStatusCodef(myHandler, "GET", "/notImplemented", nil, 501, "error message %s", "formatted") -// -// Returns whether the assertion was successful (true) or not (false). func (a *Assertions) HTTPStatusCodef(handler http.HandlerFunc, method string, url string, values url.Values, statuscode int, msg string, args ...interface{}) { if h, ok := a.t.(tHelper); ok { h.Helper() @@ -662,8 +642,6 @@ func (a *Assertions) HTTPStatusCodef(handler http.HandlerFunc, method string, ur // HTTPSuccess asserts that a specified handler returns a success status code. // // a.HTTPSuccess(myHandler, "POST", "http://www.google.com", nil) -// -// Returns whether the assertion was successful (true) or not (false). func (a *Assertions) HTTPSuccess(handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) { if h, ok := a.t.(tHelper); ok { h.Helper() @@ -674,8 +652,6 @@ func (a *Assertions) HTTPSuccess(handler http.HandlerFunc, method string, url st // HTTPSuccessf asserts that a specified handler returns a success status code. // // a.HTTPSuccessf(myHandler, "POST", "http://www.google.com", nil, "error message %s", "formatted") -// -// Returns whether the assertion was successful (true) or not (false). func (a *Assertions) HTTPSuccessf(handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) { if h, ok := a.t.(tHelper); ok { h.Helper() @@ -1097,12 +1073,11 @@ func (a *Assertions) NoDirExistsf(path string, msg string, args ...interface{}) NoDirExistsf(a.t, path, msg, args...) } -// NoError asserts that a function returned no error (i.e. `nil`). +// NoError asserts that a function returned a nil error (ie. no error). // -// actualObj, err := SomeFunction() -// if a.NoError(err) { -// assert.Equal(t, expectedObj, actualObj) -// } +// actualObj, err := SomeFunction() +// a.NoError(err) +// a.Equal(expectedObj, actualObj) func (a *Assertions) NoError(err error, msgAndArgs ...interface{}) { if h, ok := a.t.(tHelper); ok { h.Helper() @@ -1110,12 +1085,11 @@ func (a *Assertions) NoError(err error, msgAndArgs ...interface{}) { NoError(a.t, err, msgAndArgs...) } -// NoErrorf asserts that a function returned no error (i.e. `nil`). +// NoErrorf asserts that a function returned a nil error (ie. no error). // -// actualObj, err := SomeFunction() -// if a.NoErrorf(err, "error message %s", "formatted") { -// assert.Equal(t, expectedObj, actualObj) -// } +// actualObj, err := SomeFunction() +// a.NoErrorf(err, "error message %s", "formatted") +// a.Equal(expectedObj, actualObj) func (a *Assertions) NoErrorf(err error, msg string, args ...interface{}) { if h, ok := a.t.(tHelper); ok { h.Helper() @@ -1203,9 +1177,8 @@ func (a *Assertions) NotElementsMatchf(listA interface{}, listB interface{}, msg // NotEmpty asserts that the specified object is NOT [Empty]. // -// if a.NotEmpty(obj) { -// assert.Equal(t, "two", obj[1]) -// } +// a.NotEmpty(obj) +// a.Equal("two", obj[1]) func (a *Assertions) NotEmpty(object interface{}, msgAndArgs ...interface{}) { if h, ok := a.t.(tHelper); ok { h.Helper() @@ -1215,9 +1188,8 @@ func (a *Assertions) NotEmpty(object interface{}, msgAndArgs ...interface{}) { // NotEmptyf asserts that the specified object is NOT [Empty]. // -// if a.NotEmptyf(obj, "error message %s", "formatted") { -// assert.Equal(t, "two", obj[1]) -// } +// a.NotEmptyf(obj, "error message %s", "formatted") +// a.Equal("two", obj[1]) func (a *Assertions) NotEmptyf(object interface{}, msg string, args ...interface{}) { if h, ok := a.t.(tHelper); ok { h.Helper() @@ -1691,7 +1663,19 @@ func (a *Assertions) WithinRangef(actual time.Time, start time.Time, end time.Ti WithinRangef(a.t, actual, start, end, msg, args...) } -// YAMLEq asserts that two YAML strings are equivalent. +// YAMLEq asserts that the first documents in the two YAML strings are equivalent. +// +// expected := `--- +// key: value +// --- +// key: this is a second document, it is not evaluated +// ` +// actual := `--- +// key: value +// --- +// key: this is a subsequent document, it is not evaluated +// ` +// a.YAMLEq(expected, actual) func (a *Assertions) YAMLEq(expected string, actual string, msgAndArgs ...interface{}) { if h, ok := a.t.(tHelper); ok { h.Helper() @@ -1699,7 +1683,19 @@ func (a *Assertions) YAMLEq(expected string, actual string, msgAndArgs ...interf YAMLEq(a.t, expected, actual, msgAndArgs...) } -// YAMLEqf asserts that two YAML strings are equivalent. +// YAMLEqf asserts that the first documents in the two YAML strings are equivalent. +// +// expected := `--- +// key: value +// --- +// key: this is a second document, it is not evaluated +// ` +// actual := `--- +// key: value +// --- +// key: this is a subsequent document, it is not evaluated +// ` +// a.YAMLEqf(expected, actual, "error message %s", "formatted") func (a *Assertions) YAMLEqf(expected string, actual string, msg string, args ...interface{}) { if h, ok := a.t.(tHelper); ok { h.Helper() diff --git a/vendor/github.com/stretchr/testify/require/requirements.go b/vendor/github.com/stretchr/testify/require/requirements.go index 6b7ce929e..375adb0a6 100644 --- a/vendor/github.com/stretchr/testify/require/requirements.go +++ b/vendor/github.com/stretchr/testify/require/requirements.go @@ -12,18 +12,18 @@ type tHelper = interface { // ComparisonAssertionFunc is a common function prototype when comparing two values. Can be useful // for table driven tests. -type ComparisonAssertionFunc func(TestingT, interface{}, interface{}, ...interface{}) +type ComparisonAssertionFunc = func(TestingT, interface{}, interface{}, ...interface{}) // ValueAssertionFunc is a common function prototype when validating a single value. Can be useful // for table driven tests. -type ValueAssertionFunc func(TestingT, interface{}, ...interface{}) +type ValueAssertionFunc = func(TestingT, interface{}, ...interface{}) // BoolAssertionFunc is a common function prototype when validating a bool value. Can be useful // for table driven tests. -type BoolAssertionFunc func(TestingT, bool, ...interface{}) +type BoolAssertionFunc = func(TestingT, bool, ...interface{}) // ErrorAssertionFunc is a common function prototype when validating an error value. Can be useful // for table driven tests. -type ErrorAssertionFunc func(TestingT, error, ...interface{}) +type ErrorAssertionFunc = func(TestingT, error, ...interface{}) //go:generate sh -c "cd ../_codegen && go build && cd - && ../_codegen/_codegen -output-package=require -template=require.go.tmpl -include-format-funcs" diff --git a/vendor/go.yaml.in/yaml/v3/LICENSE b/vendor/go.yaml.in/yaml/v3/LICENSE new file mode 100644 index 000000000..2683e4bb1 --- /dev/null +++ b/vendor/go.yaml.in/yaml/v3/LICENSE @@ -0,0 +1,50 @@ + +This project is covered by two different licenses: MIT and Apache. + +#### MIT License #### + +The following files were ported to Go from C files of libyaml, and thus +are still covered by their original MIT license, with the additional +copyright staring in 2011 when the project was ported over: + + apic.go emitterc.go parserc.go readerc.go scannerc.go + writerc.go yamlh.go yamlprivateh.go + +Copyright (c) 2006-2010 Kirill Simonov +Copyright (c) 2006-2011 Kirill Simonov + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +### Apache License ### + +All the remaining project files are covered by the Apache license: + +Copyright (c) 2011-2019 Canonical Ltd + +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. diff --git a/vendor/go.yaml.in/yaml/v3/NOTICE b/vendor/go.yaml.in/yaml/v3/NOTICE new file mode 100644 index 000000000..866d74a7a --- /dev/null +++ b/vendor/go.yaml.in/yaml/v3/NOTICE @@ -0,0 +1,13 @@ +Copyright 2011-2016 Canonical Ltd. + +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. diff --git a/vendor/go.yaml.in/yaml/v3/apic.go b/vendor/go.yaml.in/yaml/v3/apic.go new file mode 100644 index 000000000..05fd305da --- /dev/null +++ b/vendor/go.yaml.in/yaml/v3/apic.go @@ -0,0 +1,747 @@ +// +// Copyright (c) 2011-2019 Canonical Ltd +// Copyright (c) 2006-2010 Kirill Simonov +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of +// this software and associated documentation files (the "Software"), to deal in +// the Software without restriction, including without limitation the rights to +// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +// of the Software, and to permit persons to whom the Software is furnished to do +// so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +package yaml + +import ( + "io" +) + +func yaml_insert_token(parser *yaml_parser_t, pos int, token *yaml_token_t) { + //fmt.Println("yaml_insert_token", "pos:", pos, "typ:", token.typ, "head:", parser.tokens_head, "len:", len(parser.tokens)) + + // Check if we can move the queue at the beginning of the buffer. + if parser.tokens_head > 0 && len(parser.tokens) == cap(parser.tokens) { + if parser.tokens_head != len(parser.tokens) { + copy(parser.tokens, parser.tokens[parser.tokens_head:]) + } + parser.tokens = parser.tokens[:len(parser.tokens)-parser.tokens_head] + parser.tokens_head = 0 + } + parser.tokens = append(parser.tokens, *token) + if pos < 0 { + return + } + copy(parser.tokens[parser.tokens_head+pos+1:], parser.tokens[parser.tokens_head+pos:]) + parser.tokens[parser.tokens_head+pos] = *token +} + +// Create a new parser object. +func yaml_parser_initialize(parser *yaml_parser_t) bool { + *parser = yaml_parser_t{ + raw_buffer: make([]byte, 0, input_raw_buffer_size), + buffer: make([]byte, 0, input_buffer_size), + } + return true +} + +// Destroy a parser object. +func yaml_parser_delete(parser *yaml_parser_t) { + *parser = yaml_parser_t{} +} + +// String read handler. +func yaml_string_read_handler(parser *yaml_parser_t, buffer []byte) (n int, err error) { + if parser.input_pos == len(parser.input) { + return 0, io.EOF + } + n = copy(buffer, parser.input[parser.input_pos:]) + parser.input_pos += n + return n, nil +} + +// Reader read handler. +func yaml_reader_read_handler(parser *yaml_parser_t, buffer []byte) (n int, err error) { + return parser.input_reader.Read(buffer) +} + +// Set a string input. +func yaml_parser_set_input_string(parser *yaml_parser_t, input []byte) { + if parser.read_handler != nil { + panic("must set the input source only once") + } + parser.read_handler = yaml_string_read_handler + parser.input = input + parser.input_pos = 0 +} + +// Set a file input. +func yaml_parser_set_input_reader(parser *yaml_parser_t, r io.Reader) { + if parser.read_handler != nil { + panic("must set the input source only once") + } + parser.read_handler = yaml_reader_read_handler + parser.input_reader = r +} + +// Set the source encoding. +func yaml_parser_set_encoding(parser *yaml_parser_t, encoding yaml_encoding_t) { + if parser.encoding != yaml_ANY_ENCODING { + panic("must set the encoding only once") + } + parser.encoding = encoding +} + +// Create a new emitter object. +func yaml_emitter_initialize(emitter *yaml_emitter_t) { + *emitter = yaml_emitter_t{ + buffer: make([]byte, output_buffer_size), + raw_buffer: make([]byte, 0, output_raw_buffer_size), + states: make([]yaml_emitter_state_t, 0, initial_stack_size), + events: make([]yaml_event_t, 0, initial_queue_size), + best_width: -1, + } +} + +// Destroy an emitter object. +func yaml_emitter_delete(emitter *yaml_emitter_t) { + *emitter = yaml_emitter_t{} +} + +// String write handler. +func yaml_string_write_handler(emitter *yaml_emitter_t, buffer []byte) error { + *emitter.output_buffer = append(*emitter.output_buffer, buffer...) + return nil +} + +// yaml_writer_write_handler uses emitter.output_writer to write the +// emitted text. +func yaml_writer_write_handler(emitter *yaml_emitter_t, buffer []byte) error { + _, err := emitter.output_writer.Write(buffer) + return err +} + +// Set a string output. +func yaml_emitter_set_output_string(emitter *yaml_emitter_t, output_buffer *[]byte) { + if emitter.write_handler != nil { + panic("must set the output target only once") + } + emitter.write_handler = yaml_string_write_handler + emitter.output_buffer = output_buffer +} + +// Set a file output. +func yaml_emitter_set_output_writer(emitter *yaml_emitter_t, w io.Writer) { + if emitter.write_handler != nil { + panic("must set the output target only once") + } + emitter.write_handler = yaml_writer_write_handler + emitter.output_writer = w +} + +// Set the output encoding. +func yaml_emitter_set_encoding(emitter *yaml_emitter_t, encoding yaml_encoding_t) { + if emitter.encoding != yaml_ANY_ENCODING { + panic("must set the output encoding only once") + } + emitter.encoding = encoding +} + +// Set the canonical output style. +func yaml_emitter_set_canonical(emitter *yaml_emitter_t, canonical bool) { + emitter.canonical = canonical +} + +// Set the indentation increment. +func yaml_emitter_set_indent(emitter *yaml_emitter_t, indent int) { + if indent < 2 || indent > 9 { + indent = 2 + } + emitter.best_indent = indent +} + +// Set the preferred line width. +func yaml_emitter_set_width(emitter *yaml_emitter_t, width int) { + if width < 0 { + width = -1 + } + emitter.best_width = width +} + +// Set if unescaped non-ASCII characters are allowed. +func yaml_emitter_set_unicode(emitter *yaml_emitter_t, unicode bool) { + emitter.unicode = unicode +} + +// Set the preferred line break character. +func yaml_emitter_set_break(emitter *yaml_emitter_t, line_break yaml_break_t) { + emitter.line_break = line_break +} + +///* +// * Destroy a token object. +// */ +// +//YAML_DECLARE(void) +//yaml_token_delete(yaml_token_t *token) +//{ +// assert(token); // Non-NULL token object expected. +// +// switch (token.type) +// { +// case YAML_TAG_DIRECTIVE_TOKEN: +// yaml_free(token.data.tag_directive.handle); +// yaml_free(token.data.tag_directive.prefix); +// break; +// +// case YAML_ALIAS_TOKEN: +// yaml_free(token.data.alias.value); +// break; +// +// case YAML_ANCHOR_TOKEN: +// yaml_free(token.data.anchor.value); +// break; +// +// case YAML_TAG_TOKEN: +// yaml_free(token.data.tag.handle); +// yaml_free(token.data.tag.suffix); +// break; +// +// case YAML_SCALAR_TOKEN: +// yaml_free(token.data.scalar.value); +// break; +// +// default: +// break; +// } +// +// memset(token, 0, sizeof(yaml_token_t)); +//} +// +///* +// * Check if a string is a valid UTF-8 sequence. +// * +// * Check 'reader.c' for more details on UTF-8 encoding. +// */ +// +//static int +//yaml_check_utf8(yaml_char_t *start, size_t length) +//{ +// yaml_char_t *end = start+length; +// yaml_char_t *pointer = start; +// +// while (pointer < end) { +// unsigned char octet; +// unsigned int width; +// unsigned int value; +// size_t k; +// +// octet = pointer[0]; +// width = (octet & 0x80) == 0x00 ? 1 : +// (octet & 0xE0) == 0xC0 ? 2 : +// (octet & 0xF0) == 0xE0 ? 3 : +// (octet & 0xF8) == 0xF0 ? 4 : 0; +// value = (octet & 0x80) == 0x00 ? octet & 0x7F : +// (octet & 0xE0) == 0xC0 ? octet & 0x1F : +// (octet & 0xF0) == 0xE0 ? octet & 0x0F : +// (octet & 0xF8) == 0xF0 ? octet & 0x07 : 0; +// if (!width) return 0; +// if (pointer+width > end) return 0; +// for (k = 1; k < width; k ++) { +// octet = pointer[k]; +// if ((octet & 0xC0) != 0x80) return 0; +// value = (value << 6) + (octet & 0x3F); +// } +// if (!((width == 1) || +// (width == 2 && value >= 0x80) || +// (width == 3 && value >= 0x800) || +// (width == 4 && value >= 0x10000))) return 0; +// +// pointer += width; +// } +// +// return 1; +//} +// + +// Create STREAM-START. +func yaml_stream_start_event_initialize(event *yaml_event_t, encoding yaml_encoding_t) { + *event = yaml_event_t{ + typ: yaml_STREAM_START_EVENT, + encoding: encoding, + } +} + +// Create STREAM-END. +func yaml_stream_end_event_initialize(event *yaml_event_t) { + *event = yaml_event_t{ + typ: yaml_STREAM_END_EVENT, + } +} + +// Create DOCUMENT-START. +func yaml_document_start_event_initialize( + event *yaml_event_t, + version_directive *yaml_version_directive_t, + tag_directives []yaml_tag_directive_t, + implicit bool, +) { + *event = yaml_event_t{ + typ: yaml_DOCUMENT_START_EVENT, + version_directive: version_directive, + tag_directives: tag_directives, + implicit: implicit, + } +} + +// Create DOCUMENT-END. +func yaml_document_end_event_initialize(event *yaml_event_t, implicit bool) { + *event = yaml_event_t{ + typ: yaml_DOCUMENT_END_EVENT, + implicit: implicit, + } +} + +// Create ALIAS. +func yaml_alias_event_initialize(event *yaml_event_t, anchor []byte) bool { + *event = yaml_event_t{ + typ: yaml_ALIAS_EVENT, + anchor: anchor, + } + return true +} + +// Create SCALAR. +func yaml_scalar_event_initialize(event *yaml_event_t, anchor, tag, value []byte, plain_implicit, quoted_implicit bool, style yaml_scalar_style_t) bool { + *event = yaml_event_t{ + typ: yaml_SCALAR_EVENT, + anchor: anchor, + tag: tag, + value: value, + implicit: plain_implicit, + quoted_implicit: quoted_implicit, + style: yaml_style_t(style), + } + return true +} + +// Create SEQUENCE-START. +func yaml_sequence_start_event_initialize(event *yaml_event_t, anchor, tag []byte, implicit bool, style yaml_sequence_style_t) bool { + *event = yaml_event_t{ + typ: yaml_SEQUENCE_START_EVENT, + anchor: anchor, + tag: tag, + implicit: implicit, + style: yaml_style_t(style), + } + return true +} + +// Create SEQUENCE-END. +func yaml_sequence_end_event_initialize(event *yaml_event_t) bool { + *event = yaml_event_t{ + typ: yaml_SEQUENCE_END_EVENT, + } + return true +} + +// Create MAPPING-START. +func yaml_mapping_start_event_initialize(event *yaml_event_t, anchor, tag []byte, implicit bool, style yaml_mapping_style_t) { + *event = yaml_event_t{ + typ: yaml_MAPPING_START_EVENT, + anchor: anchor, + tag: tag, + implicit: implicit, + style: yaml_style_t(style), + } +} + +// Create MAPPING-END. +func yaml_mapping_end_event_initialize(event *yaml_event_t) { + *event = yaml_event_t{ + typ: yaml_MAPPING_END_EVENT, + } +} + +// Destroy an event object. +func yaml_event_delete(event *yaml_event_t) { + *event = yaml_event_t{} +} + +///* +// * Create a document object. +// */ +// +//YAML_DECLARE(int) +//yaml_document_initialize(document *yaml_document_t, +// version_directive *yaml_version_directive_t, +// tag_directives_start *yaml_tag_directive_t, +// tag_directives_end *yaml_tag_directive_t, +// start_implicit int, end_implicit int) +//{ +// struct { +// error yaml_error_type_t +// } context +// struct { +// start *yaml_node_t +// end *yaml_node_t +// top *yaml_node_t +// } nodes = { NULL, NULL, NULL } +// version_directive_copy *yaml_version_directive_t = NULL +// struct { +// start *yaml_tag_directive_t +// end *yaml_tag_directive_t +// top *yaml_tag_directive_t +// } tag_directives_copy = { NULL, NULL, NULL } +// value yaml_tag_directive_t = { NULL, NULL } +// mark yaml_mark_t = { 0, 0, 0 } +// +// assert(document) // Non-NULL document object is expected. +// assert((tag_directives_start && tag_directives_end) || +// (tag_directives_start == tag_directives_end)) +// // Valid tag directives are expected. +// +// if (!STACK_INIT(&context, nodes, INITIAL_STACK_SIZE)) goto error +// +// if (version_directive) { +// version_directive_copy = yaml_malloc(sizeof(yaml_version_directive_t)) +// if (!version_directive_copy) goto error +// version_directive_copy.major = version_directive.major +// version_directive_copy.minor = version_directive.minor +// } +// +// if (tag_directives_start != tag_directives_end) { +// tag_directive *yaml_tag_directive_t +// if (!STACK_INIT(&context, tag_directives_copy, INITIAL_STACK_SIZE)) +// goto error +// for (tag_directive = tag_directives_start +// tag_directive != tag_directives_end; tag_directive ++) { +// assert(tag_directive.handle) +// assert(tag_directive.prefix) +// if (!yaml_check_utf8(tag_directive.handle, +// strlen((char *)tag_directive.handle))) +// goto error +// if (!yaml_check_utf8(tag_directive.prefix, +// strlen((char *)tag_directive.prefix))) +// goto error +// value.handle = yaml_strdup(tag_directive.handle) +// value.prefix = yaml_strdup(tag_directive.prefix) +// if (!value.handle || !value.prefix) goto error +// if (!PUSH(&context, tag_directives_copy, value)) +// goto error +// value.handle = NULL +// value.prefix = NULL +// } +// } +// +// DOCUMENT_INIT(*document, nodes.start, nodes.end, version_directive_copy, +// tag_directives_copy.start, tag_directives_copy.top, +// start_implicit, end_implicit, mark, mark) +// +// return 1 +// +//error: +// STACK_DEL(&context, nodes) +// yaml_free(version_directive_copy) +// while (!STACK_EMPTY(&context, tag_directives_copy)) { +// value yaml_tag_directive_t = POP(&context, tag_directives_copy) +// yaml_free(value.handle) +// yaml_free(value.prefix) +// } +// STACK_DEL(&context, tag_directives_copy) +// yaml_free(value.handle) +// yaml_free(value.prefix) +// +// return 0 +//} +// +///* +// * Destroy a document object. +// */ +// +//YAML_DECLARE(void) +//yaml_document_delete(document *yaml_document_t) +//{ +// struct { +// error yaml_error_type_t +// } context +// tag_directive *yaml_tag_directive_t +// +// context.error = YAML_NO_ERROR // Eliminate a compiler warning. +// +// assert(document) // Non-NULL document object is expected. +// +// while (!STACK_EMPTY(&context, document.nodes)) { +// node yaml_node_t = POP(&context, document.nodes) +// yaml_free(node.tag) +// switch (node.type) { +// case YAML_SCALAR_NODE: +// yaml_free(node.data.scalar.value) +// break +// case YAML_SEQUENCE_NODE: +// STACK_DEL(&context, node.data.sequence.items) +// break +// case YAML_MAPPING_NODE: +// STACK_DEL(&context, node.data.mapping.pairs) +// break +// default: +// assert(0) // Should not happen. +// } +// } +// STACK_DEL(&context, document.nodes) +// +// yaml_free(document.version_directive) +// for (tag_directive = document.tag_directives.start +// tag_directive != document.tag_directives.end +// tag_directive++) { +// yaml_free(tag_directive.handle) +// yaml_free(tag_directive.prefix) +// } +// yaml_free(document.tag_directives.start) +// +// memset(document, 0, sizeof(yaml_document_t)) +//} +// +///** +// * Get a document node. +// */ +// +//YAML_DECLARE(yaml_node_t *) +//yaml_document_get_node(document *yaml_document_t, index int) +//{ +// assert(document) // Non-NULL document object is expected. +// +// if (index > 0 && document.nodes.start + index <= document.nodes.top) { +// return document.nodes.start + index - 1 +// } +// return NULL +//} +// +///** +// * Get the root object. +// */ +// +//YAML_DECLARE(yaml_node_t *) +//yaml_document_get_root_node(document *yaml_document_t) +//{ +// assert(document) // Non-NULL document object is expected. +// +// if (document.nodes.top != document.nodes.start) { +// return document.nodes.start +// } +// return NULL +//} +// +///* +// * Add a scalar node to a document. +// */ +// +//YAML_DECLARE(int) +//yaml_document_add_scalar(document *yaml_document_t, +// tag *yaml_char_t, value *yaml_char_t, length int, +// style yaml_scalar_style_t) +//{ +// struct { +// error yaml_error_type_t +// } context +// mark yaml_mark_t = { 0, 0, 0 } +// tag_copy *yaml_char_t = NULL +// value_copy *yaml_char_t = NULL +// node yaml_node_t +// +// assert(document) // Non-NULL document object is expected. +// assert(value) // Non-NULL value is expected. +// +// if (!tag) { +// tag = (yaml_char_t *)YAML_DEFAULT_SCALAR_TAG +// } +// +// if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error +// tag_copy = yaml_strdup(tag) +// if (!tag_copy) goto error +// +// if (length < 0) { +// length = strlen((char *)value) +// } +// +// if (!yaml_check_utf8(value, length)) goto error +// value_copy = yaml_malloc(length+1) +// if (!value_copy) goto error +// memcpy(value_copy, value, length) +// value_copy[length] = '\0' +// +// SCALAR_NODE_INIT(node, tag_copy, value_copy, length, style, mark, mark) +// if (!PUSH(&context, document.nodes, node)) goto error +// +// return document.nodes.top - document.nodes.start +// +//error: +// yaml_free(tag_copy) +// yaml_free(value_copy) +// +// return 0 +//} +// +///* +// * Add a sequence node to a document. +// */ +// +//YAML_DECLARE(int) +//yaml_document_add_sequence(document *yaml_document_t, +// tag *yaml_char_t, style yaml_sequence_style_t) +//{ +// struct { +// error yaml_error_type_t +// } context +// mark yaml_mark_t = { 0, 0, 0 } +// tag_copy *yaml_char_t = NULL +// struct { +// start *yaml_node_item_t +// end *yaml_node_item_t +// top *yaml_node_item_t +// } items = { NULL, NULL, NULL } +// node yaml_node_t +// +// assert(document) // Non-NULL document object is expected. +// +// if (!tag) { +// tag = (yaml_char_t *)YAML_DEFAULT_SEQUENCE_TAG +// } +// +// if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error +// tag_copy = yaml_strdup(tag) +// if (!tag_copy) goto error +// +// if (!STACK_INIT(&context, items, INITIAL_STACK_SIZE)) goto error +// +// SEQUENCE_NODE_INIT(node, tag_copy, items.start, items.end, +// style, mark, mark) +// if (!PUSH(&context, document.nodes, node)) goto error +// +// return document.nodes.top - document.nodes.start +// +//error: +// STACK_DEL(&context, items) +// yaml_free(tag_copy) +// +// return 0 +//} +// +///* +// * Add a mapping node to a document. +// */ +// +//YAML_DECLARE(int) +//yaml_document_add_mapping(document *yaml_document_t, +// tag *yaml_char_t, style yaml_mapping_style_t) +//{ +// struct { +// error yaml_error_type_t +// } context +// mark yaml_mark_t = { 0, 0, 0 } +// tag_copy *yaml_char_t = NULL +// struct { +// start *yaml_node_pair_t +// end *yaml_node_pair_t +// top *yaml_node_pair_t +// } pairs = { NULL, NULL, NULL } +// node yaml_node_t +// +// assert(document) // Non-NULL document object is expected. +// +// if (!tag) { +// tag = (yaml_char_t *)YAML_DEFAULT_MAPPING_TAG +// } +// +// if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error +// tag_copy = yaml_strdup(tag) +// if (!tag_copy) goto error +// +// if (!STACK_INIT(&context, pairs, INITIAL_STACK_SIZE)) goto error +// +// MAPPING_NODE_INIT(node, tag_copy, pairs.start, pairs.end, +// style, mark, mark) +// if (!PUSH(&context, document.nodes, node)) goto error +// +// return document.nodes.top - document.nodes.start +// +//error: +// STACK_DEL(&context, pairs) +// yaml_free(tag_copy) +// +// return 0 +//} +// +///* +// * Append an item to a sequence node. +// */ +// +//YAML_DECLARE(int) +//yaml_document_append_sequence_item(document *yaml_document_t, +// sequence int, item int) +//{ +// struct { +// error yaml_error_type_t +// } context +// +// assert(document) // Non-NULL document is required. +// assert(sequence > 0 +// && document.nodes.start + sequence <= document.nodes.top) +// // Valid sequence id is required. +// assert(document.nodes.start[sequence-1].type == YAML_SEQUENCE_NODE) +// // A sequence node is required. +// assert(item > 0 && document.nodes.start + item <= document.nodes.top) +// // Valid item id is required. +// +// if (!PUSH(&context, +// document.nodes.start[sequence-1].data.sequence.items, item)) +// return 0 +// +// return 1 +//} +// +///* +// * Append a pair of a key and a value to a mapping node. +// */ +// +//YAML_DECLARE(int) +//yaml_document_append_mapping_pair(document *yaml_document_t, +// mapping int, key int, value int) +//{ +// struct { +// error yaml_error_type_t +// } context +// +// pair yaml_node_pair_t +// +// assert(document) // Non-NULL document is required. +// assert(mapping > 0 +// && document.nodes.start + mapping <= document.nodes.top) +// // Valid mapping id is required. +// assert(document.nodes.start[mapping-1].type == YAML_MAPPING_NODE) +// // A mapping node is required. +// assert(key > 0 && document.nodes.start + key <= document.nodes.top) +// // Valid key id is required. +// assert(value > 0 && document.nodes.start + value <= document.nodes.top) +// // Valid value id is required. +// +// pair.key = key +// pair.value = value +// +// if (!PUSH(&context, +// document.nodes.start[mapping-1].data.mapping.pairs, pair)) +// return 0 +// +// return 1 +//} +// +// diff --git a/vendor/go.yaml.in/yaml/v3/decode.go b/vendor/go.yaml.in/yaml/v3/decode.go new file mode 100644 index 000000000..02e2b17bf --- /dev/null +++ b/vendor/go.yaml.in/yaml/v3/decode.go @@ -0,0 +1,1018 @@ +// +// Copyright (c) 2011-2019 Canonical Ltd +// +// 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. + +package yaml + +import ( + "encoding" + "encoding/base64" + "fmt" + "io" + "math" + "reflect" + "strconv" + "time" +) + +// ---------------------------------------------------------------------------- +// Parser, produces a node tree out of a libyaml event stream. + +type parser struct { + parser yaml_parser_t + event yaml_event_t + doc *Node + anchors map[string]*Node + doneInit bool + textless bool +} + +func newParser(b []byte) *parser { + p := parser{} + if !yaml_parser_initialize(&p.parser) { + panic("failed to initialize YAML emitter") + } + if len(b) == 0 { + b = []byte{'\n'} + } + yaml_parser_set_input_string(&p.parser, b) + return &p +} + +func newParserFromReader(r io.Reader) *parser { + p := parser{} + if !yaml_parser_initialize(&p.parser) { + panic("failed to initialize YAML emitter") + } + yaml_parser_set_input_reader(&p.parser, r) + return &p +} + +func (p *parser) init() { + if p.doneInit { + return + } + p.anchors = make(map[string]*Node) + p.expect(yaml_STREAM_START_EVENT) + p.doneInit = true +} + +func (p *parser) destroy() { + if p.event.typ != yaml_NO_EVENT { + yaml_event_delete(&p.event) + } + yaml_parser_delete(&p.parser) +} + +// expect consumes an event from the event stream and +// checks that it's of the expected type. +func (p *parser) expect(e yaml_event_type_t) { + if p.event.typ == yaml_NO_EVENT { + if !yaml_parser_parse(&p.parser, &p.event) { + p.fail() + } + } + if p.event.typ == yaml_STREAM_END_EVENT { + failf("attempted to go past the end of stream; corrupted value?") + } + if p.event.typ != e { + p.parser.problem = fmt.Sprintf("expected %s event but got %s", e, p.event.typ) + p.fail() + } + yaml_event_delete(&p.event) + p.event.typ = yaml_NO_EVENT +} + +// peek peeks at the next event in the event stream, +// puts the results into p.event and returns the event type. +func (p *parser) peek() yaml_event_type_t { + if p.event.typ != yaml_NO_EVENT { + return p.event.typ + } + // It's curious choice from the underlying API to generally return a + // positive result on success, but on this case return true in an error + // scenario. This was the source of bugs in the past (issue #666). + if !yaml_parser_parse(&p.parser, &p.event) || p.parser.error != yaml_NO_ERROR { + p.fail() + } + return p.event.typ +} + +func (p *parser) fail() { + var where string + var line int + if p.parser.context_mark.line != 0 { + line = p.parser.context_mark.line + // Scanner errors don't iterate line before returning error + if p.parser.error == yaml_SCANNER_ERROR { + line++ + } + } else if p.parser.problem_mark.line != 0 { + line = p.parser.problem_mark.line + // Scanner errors don't iterate line before returning error + if p.parser.error == yaml_SCANNER_ERROR { + line++ + } + } + if line != 0 { + where = "line " + strconv.Itoa(line) + ": " + } + var msg string + if len(p.parser.problem) > 0 { + msg = p.parser.problem + } else { + msg = "unknown problem parsing YAML content" + } + failf("%s%s", where, msg) +} + +func (p *parser) anchor(n *Node, anchor []byte) { + if anchor != nil { + n.Anchor = string(anchor) + p.anchors[n.Anchor] = n + } +} + +func (p *parser) parse() *Node { + p.init() + switch p.peek() { + case yaml_SCALAR_EVENT: + return p.scalar() + case yaml_ALIAS_EVENT: + return p.alias() + case yaml_MAPPING_START_EVENT: + return p.mapping() + case yaml_SEQUENCE_START_EVENT: + return p.sequence() + case yaml_DOCUMENT_START_EVENT: + return p.document() + case yaml_STREAM_END_EVENT: + // Happens when attempting to decode an empty buffer. + return nil + case yaml_TAIL_COMMENT_EVENT: + panic("internal error: unexpected tail comment event (please report)") + default: + panic("internal error: attempted to parse unknown event (please report): " + p.event.typ.String()) + } +} + +func (p *parser) node(kind Kind, defaultTag, tag, value string) *Node { + var style Style + if tag != "" && tag != "!" { + tag = shortTag(tag) + style = TaggedStyle + } else if defaultTag != "" { + tag = defaultTag + } else if kind == ScalarNode { + tag, _ = resolve("", value) + } + n := &Node{ + Kind: kind, + Tag: tag, + Value: value, + Style: style, + } + if !p.textless { + n.Line = p.event.start_mark.line + 1 + n.Column = p.event.start_mark.column + 1 + n.HeadComment = string(p.event.head_comment) + n.LineComment = string(p.event.line_comment) + n.FootComment = string(p.event.foot_comment) + } + return n +} + +func (p *parser) parseChild(parent *Node) *Node { + child := p.parse() + parent.Content = append(parent.Content, child) + return child +} + +func (p *parser) document() *Node { + n := p.node(DocumentNode, "", "", "") + p.doc = n + p.expect(yaml_DOCUMENT_START_EVENT) + p.parseChild(n) + if p.peek() == yaml_DOCUMENT_END_EVENT { + n.FootComment = string(p.event.foot_comment) + } + p.expect(yaml_DOCUMENT_END_EVENT) + return n +} + +func (p *parser) alias() *Node { + n := p.node(AliasNode, "", "", string(p.event.anchor)) + n.Alias = p.anchors[n.Value] + if n.Alias == nil { + failf("unknown anchor '%s' referenced", n.Value) + } + p.expect(yaml_ALIAS_EVENT) + return n +} + +func (p *parser) scalar() *Node { + var parsedStyle = p.event.scalar_style() + var nodeStyle Style + switch { + case parsedStyle&yaml_DOUBLE_QUOTED_SCALAR_STYLE != 0: + nodeStyle = DoubleQuotedStyle + case parsedStyle&yaml_SINGLE_QUOTED_SCALAR_STYLE != 0: + nodeStyle = SingleQuotedStyle + case parsedStyle&yaml_LITERAL_SCALAR_STYLE != 0: + nodeStyle = LiteralStyle + case parsedStyle&yaml_FOLDED_SCALAR_STYLE != 0: + nodeStyle = FoldedStyle + } + var nodeValue = string(p.event.value) + var nodeTag = string(p.event.tag) + var defaultTag string + if nodeStyle == 0 { + if nodeValue == "<<" { + defaultTag = mergeTag + } + } else { + defaultTag = strTag + } + n := p.node(ScalarNode, defaultTag, nodeTag, nodeValue) + n.Style |= nodeStyle + p.anchor(n, p.event.anchor) + p.expect(yaml_SCALAR_EVENT) + return n +} + +func (p *parser) sequence() *Node { + n := p.node(SequenceNode, seqTag, string(p.event.tag), "") + if p.event.sequence_style()&yaml_FLOW_SEQUENCE_STYLE != 0 { + n.Style |= FlowStyle + } + p.anchor(n, p.event.anchor) + p.expect(yaml_SEQUENCE_START_EVENT) + for p.peek() != yaml_SEQUENCE_END_EVENT { + p.parseChild(n) + } + n.LineComment = string(p.event.line_comment) + n.FootComment = string(p.event.foot_comment) + p.expect(yaml_SEQUENCE_END_EVENT) + return n +} + +func (p *parser) mapping() *Node { + n := p.node(MappingNode, mapTag, string(p.event.tag), "") + block := true + if p.event.mapping_style()&yaml_FLOW_MAPPING_STYLE != 0 { + block = false + n.Style |= FlowStyle + } + p.anchor(n, p.event.anchor) + p.expect(yaml_MAPPING_START_EVENT) + for p.peek() != yaml_MAPPING_END_EVENT { + k := p.parseChild(n) + if block && k.FootComment != "" { + // Must be a foot comment for the prior value when being dedented. + if len(n.Content) > 2 { + n.Content[len(n.Content)-3].FootComment = k.FootComment + k.FootComment = "" + } + } + v := p.parseChild(n) + if k.FootComment == "" && v.FootComment != "" { + k.FootComment = v.FootComment + v.FootComment = "" + } + if p.peek() == yaml_TAIL_COMMENT_EVENT { + if k.FootComment == "" { + k.FootComment = string(p.event.foot_comment) + } + p.expect(yaml_TAIL_COMMENT_EVENT) + } + } + n.LineComment = string(p.event.line_comment) + n.FootComment = string(p.event.foot_comment) + if n.Style&FlowStyle == 0 && n.FootComment != "" && len(n.Content) > 1 { + n.Content[len(n.Content)-2].FootComment = n.FootComment + n.FootComment = "" + } + p.expect(yaml_MAPPING_END_EVENT) + return n +} + +// ---------------------------------------------------------------------------- +// Decoder, unmarshals a node into a provided value. + +type decoder struct { + doc *Node + aliases map[*Node]bool + terrors []string + + stringMapType reflect.Type + generalMapType reflect.Type + + knownFields bool + uniqueKeys bool + decodeCount int + aliasCount int + aliasDepth int + + mergedFields map[interface{}]bool +} + +var ( + nodeType = reflect.TypeOf(Node{}) + durationType = reflect.TypeOf(time.Duration(0)) + stringMapType = reflect.TypeOf(map[string]interface{}{}) + generalMapType = reflect.TypeOf(map[interface{}]interface{}{}) + ifaceType = generalMapType.Elem() + timeType = reflect.TypeOf(time.Time{}) + ptrTimeType = reflect.TypeOf(&time.Time{}) +) + +func newDecoder() *decoder { + d := &decoder{ + stringMapType: stringMapType, + generalMapType: generalMapType, + uniqueKeys: true, + } + d.aliases = make(map[*Node]bool) + return d +} + +func (d *decoder) terror(n *Node, tag string, out reflect.Value) { + if n.Tag != "" { + tag = n.Tag + } + value := n.Value + if tag != seqTag && tag != mapTag { + if len(value) > 10 { + value = " `" + value[:7] + "...`" + } else { + value = " `" + value + "`" + } + } + d.terrors = append(d.terrors, fmt.Sprintf("line %d: cannot unmarshal %s%s into %s", n.Line, shortTag(tag), value, out.Type())) +} + +func (d *decoder) callUnmarshaler(n *Node, u Unmarshaler) (good bool) { + err := u.UnmarshalYAML(n) + if e, ok := err.(*TypeError); ok { + d.terrors = append(d.terrors, e.Errors...) + return false + } + if err != nil { + fail(err) + } + return true +} + +func (d *decoder) callObsoleteUnmarshaler(n *Node, u obsoleteUnmarshaler) (good bool) { + terrlen := len(d.terrors) + err := u.UnmarshalYAML(func(v interface{}) (err error) { + defer handleErr(&err) + d.unmarshal(n, reflect.ValueOf(v)) + if len(d.terrors) > terrlen { + issues := d.terrors[terrlen:] + d.terrors = d.terrors[:terrlen] + return &TypeError{issues} + } + return nil + }) + if e, ok := err.(*TypeError); ok { + d.terrors = append(d.terrors, e.Errors...) + return false + } + if err != nil { + fail(err) + } + return true +} + +// d.prepare initializes and dereferences pointers and calls UnmarshalYAML +// if a value is found to implement it. +// It returns the initialized and dereferenced out value, whether +// unmarshalling was already done by UnmarshalYAML, and if so whether +// its types unmarshalled appropriately. +// +// If n holds a null value, prepare returns before doing anything. +func (d *decoder) prepare(n *Node, out reflect.Value) (newout reflect.Value, unmarshaled, good bool) { + if n.ShortTag() == nullTag { + return out, false, false + } + again := true + for again { + again = false + if out.Kind() == reflect.Ptr { + if out.IsNil() { + out.Set(reflect.New(out.Type().Elem())) + } + out = out.Elem() + again = true + } + if out.CanAddr() { + outi := out.Addr().Interface() + if u, ok := outi.(Unmarshaler); ok { + good = d.callUnmarshaler(n, u) + return out, true, good + } + if u, ok := outi.(obsoleteUnmarshaler); ok { + good = d.callObsoleteUnmarshaler(n, u) + return out, true, good + } + } + } + return out, false, false +} + +func (d *decoder) fieldByIndex(n *Node, v reflect.Value, index []int) (field reflect.Value) { + if n.ShortTag() == nullTag { + return reflect.Value{} + } + for _, num := range index { + for { + if v.Kind() == reflect.Ptr { + if v.IsNil() { + v.Set(reflect.New(v.Type().Elem())) + } + v = v.Elem() + continue + } + break + } + v = v.Field(num) + } + return v +} + +const ( + // 400,000 decode operations is ~500kb of dense object declarations, or + // ~5kb of dense object declarations with 10000% alias expansion + alias_ratio_range_low = 400000 + + // 4,000,000 decode operations is ~5MB of dense object declarations, or + // ~4.5MB of dense object declarations with 10% alias expansion + alias_ratio_range_high = 4000000 + + // alias_ratio_range is the range over which we scale allowed alias ratios + alias_ratio_range = float64(alias_ratio_range_high - alias_ratio_range_low) +) + +func allowedAliasRatio(decodeCount int) float64 { + switch { + case decodeCount <= alias_ratio_range_low: + // allow 99% to come from alias expansion for small-to-medium documents + return 0.99 + case decodeCount >= alias_ratio_range_high: + // allow 10% to come from alias expansion for very large documents + return 0.10 + default: + // scale smoothly from 99% down to 10% over the range. + // this maps to 396,000 - 400,000 allowed alias-driven decodes over the range. + // 400,000 decode operations is ~100MB of allocations in worst-case scenarios (single-item maps). + return 0.99 - 0.89*(float64(decodeCount-alias_ratio_range_low)/alias_ratio_range) + } +} + +func (d *decoder) unmarshal(n *Node, out reflect.Value) (good bool) { + d.decodeCount++ + if d.aliasDepth > 0 { + d.aliasCount++ + } + if d.aliasCount > 100 && d.decodeCount > 1000 && float64(d.aliasCount)/float64(d.decodeCount) > allowedAliasRatio(d.decodeCount) { + failf("document contains excessive aliasing") + } + if out.Type() == nodeType { + out.Set(reflect.ValueOf(n).Elem()) + return true + } + switch n.Kind { + case DocumentNode: + return d.document(n, out) + case AliasNode: + return d.alias(n, out) + } + out, unmarshaled, good := d.prepare(n, out) + if unmarshaled { + return good + } + switch n.Kind { + case ScalarNode: + good = d.scalar(n, out) + case MappingNode: + good = d.mapping(n, out) + case SequenceNode: + good = d.sequence(n, out) + case 0: + if n.IsZero() { + return d.null(out) + } + fallthrough + default: + failf("cannot decode node with unknown kind %d", n.Kind) + } + return good +} + +func (d *decoder) document(n *Node, out reflect.Value) (good bool) { + if len(n.Content) == 1 { + d.doc = n + d.unmarshal(n.Content[0], out) + return true + } + return false +} + +func (d *decoder) alias(n *Node, out reflect.Value) (good bool) { + if d.aliases[n] { + // TODO this could actually be allowed in some circumstances. + failf("anchor '%s' value contains itself", n.Value) + } + d.aliases[n] = true + d.aliasDepth++ + good = d.unmarshal(n.Alias, out) + d.aliasDepth-- + delete(d.aliases, n) + return good +} + +var zeroValue reflect.Value + +func resetMap(out reflect.Value) { + for _, k := range out.MapKeys() { + out.SetMapIndex(k, zeroValue) + } +} + +func (d *decoder) null(out reflect.Value) bool { + if out.CanAddr() { + switch out.Kind() { + case reflect.Interface, reflect.Ptr, reflect.Map, reflect.Slice: + out.Set(reflect.Zero(out.Type())) + return true + } + } + return false +} + +func (d *decoder) scalar(n *Node, out reflect.Value) bool { + var tag string + var resolved interface{} + if n.indicatedString() { + tag = strTag + resolved = n.Value + } else { + tag, resolved = resolve(n.Tag, n.Value) + if tag == binaryTag { + data, err := base64.StdEncoding.DecodeString(resolved.(string)) + if err != nil { + failf("!!binary value contains invalid base64 data") + } + resolved = string(data) + } + } + if resolved == nil { + return d.null(out) + } + if resolvedv := reflect.ValueOf(resolved); out.Type() == resolvedv.Type() { + // We've resolved to exactly the type we want, so use that. + out.Set(resolvedv) + return true + } + // Perhaps we can use the value as a TextUnmarshaler to + // set its value. + if out.CanAddr() { + u, ok := out.Addr().Interface().(encoding.TextUnmarshaler) + if ok { + var text []byte + if tag == binaryTag { + text = []byte(resolved.(string)) + } else { + // We let any value be unmarshaled into TextUnmarshaler. + // That might be more lax than we'd like, but the + // TextUnmarshaler itself should bowl out any dubious values. + text = []byte(n.Value) + } + err := u.UnmarshalText(text) + if err != nil { + fail(err) + } + return true + } + } + switch out.Kind() { + case reflect.String: + if tag == binaryTag { + out.SetString(resolved.(string)) + return true + } + out.SetString(n.Value) + return true + case reflect.Interface: + out.Set(reflect.ValueOf(resolved)) + return true + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + // This used to work in v2, but it's very unfriendly. + isDuration := out.Type() == durationType + + switch resolved := resolved.(type) { + case int: + if !isDuration && !out.OverflowInt(int64(resolved)) { + out.SetInt(int64(resolved)) + return true + } + case int64: + if !isDuration && !out.OverflowInt(resolved) { + out.SetInt(resolved) + return true + } + case uint64: + if !isDuration && resolved <= math.MaxInt64 && !out.OverflowInt(int64(resolved)) { + out.SetInt(int64(resolved)) + return true + } + case float64: + if !isDuration && resolved <= math.MaxInt64 && !out.OverflowInt(int64(resolved)) { + out.SetInt(int64(resolved)) + return true + } + case string: + if out.Type() == durationType { + d, err := time.ParseDuration(resolved) + if err == nil { + out.SetInt(int64(d)) + return true + } + } + } + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: + switch resolved := resolved.(type) { + case int: + if resolved >= 0 && !out.OverflowUint(uint64(resolved)) { + out.SetUint(uint64(resolved)) + return true + } + case int64: + if resolved >= 0 && !out.OverflowUint(uint64(resolved)) { + out.SetUint(uint64(resolved)) + return true + } + case uint64: + if !out.OverflowUint(uint64(resolved)) { + out.SetUint(uint64(resolved)) + return true + } + case float64: + if resolved <= math.MaxUint64 && !out.OverflowUint(uint64(resolved)) { + out.SetUint(uint64(resolved)) + return true + } + } + case reflect.Bool: + switch resolved := resolved.(type) { + case bool: + out.SetBool(resolved) + return true + case string: + // This offers some compatibility with the 1.1 spec (https://yaml.org/type/bool.html). + // It only works if explicitly attempting to unmarshal into a typed bool value. + switch resolved { + case "y", "Y", "yes", "Yes", "YES", "on", "On", "ON": + out.SetBool(true) + return true + case "n", "N", "no", "No", "NO", "off", "Off", "OFF": + out.SetBool(false) + return true + } + } + case reflect.Float32, reflect.Float64: + switch resolved := resolved.(type) { + case int: + out.SetFloat(float64(resolved)) + return true + case int64: + out.SetFloat(float64(resolved)) + return true + case uint64: + out.SetFloat(float64(resolved)) + return true + case float64: + out.SetFloat(resolved) + return true + } + case reflect.Struct: + if resolvedv := reflect.ValueOf(resolved); out.Type() == resolvedv.Type() { + out.Set(resolvedv) + return true + } + case reflect.Ptr: + panic("yaml internal error: please report the issue") + } + d.terror(n, tag, out) + return false +} + +func settableValueOf(i interface{}) reflect.Value { + v := reflect.ValueOf(i) + sv := reflect.New(v.Type()).Elem() + sv.Set(v) + return sv +} + +func (d *decoder) sequence(n *Node, out reflect.Value) (good bool) { + l := len(n.Content) + + var iface reflect.Value + switch out.Kind() { + case reflect.Slice: + out.Set(reflect.MakeSlice(out.Type(), l, l)) + case reflect.Array: + if l != out.Len() { + failf("invalid array: want %d elements but got %d", out.Len(), l) + } + case reflect.Interface: + // No type hints. Will have to use a generic sequence. + iface = out + out = settableValueOf(make([]interface{}, l)) + default: + d.terror(n, seqTag, out) + return false + } + et := out.Type().Elem() + + j := 0 + for i := 0; i < l; i++ { + e := reflect.New(et).Elem() + if ok := d.unmarshal(n.Content[i], e); ok { + out.Index(j).Set(e) + j++ + } + } + if out.Kind() != reflect.Array { + out.Set(out.Slice(0, j)) + } + if iface.IsValid() { + iface.Set(out) + } + return true +} + +func (d *decoder) mapping(n *Node, out reflect.Value) (good bool) { + l := len(n.Content) + if d.uniqueKeys { + nerrs := len(d.terrors) + for i := 0; i < l; i += 2 { + ni := n.Content[i] + for j := i + 2; j < l; j += 2 { + nj := n.Content[j] + if ni.Kind == nj.Kind && ni.Value == nj.Value { + d.terrors = append(d.terrors, fmt.Sprintf("line %d: mapping key %#v already defined at line %d", nj.Line, nj.Value, ni.Line)) + } + } + } + if len(d.terrors) > nerrs { + return false + } + } + switch out.Kind() { + case reflect.Struct: + return d.mappingStruct(n, out) + case reflect.Map: + // okay + case reflect.Interface: + iface := out + if isStringMap(n) { + out = reflect.MakeMap(d.stringMapType) + } else { + out = reflect.MakeMap(d.generalMapType) + } + iface.Set(out) + default: + d.terror(n, mapTag, out) + return false + } + + outt := out.Type() + kt := outt.Key() + et := outt.Elem() + + stringMapType := d.stringMapType + generalMapType := d.generalMapType + if outt.Elem() == ifaceType { + if outt.Key().Kind() == reflect.String { + d.stringMapType = outt + } else if outt.Key() == ifaceType { + d.generalMapType = outt + } + } + + mergedFields := d.mergedFields + d.mergedFields = nil + + var mergeNode *Node + + mapIsNew := false + if out.IsNil() { + out.Set(reflect.MakeMap(outt)) + mapIsNew = true + } + for i := 0; i < l; i += 2 { + if isMerge(n.Content[i]) { + mergeNode = n.Content[i+1] + continue + } + k := reflect.New(kt).Elem() + if d.unmarshal(n.Content[i], k) { + if mergedFields != nil { + ki := k.Interface() + if d.getPossiblyUnhashableKey(mergedFields, ki) { + continue + } + d.setPossiblyUnhashableKey(mergedFields, ki, true) + } + kkind := k.Kind() + if kkind == reflect.Interface { + kkind = k.Elem().Kind() + } + if kkind == reflect.Map || kkind == reflect.Slice { + failf("invalid map key: %#v", k.Interface()) + } + e := reflect.New(et).Elem() + if d.unmarshal(n.Content[i+1], e) || n.Content[i+1].ShortTag() == nullTag && (mapIsNew || !out.MapIndex(k).IsValid()) { + out.SetMapIndex(k, e) + } + } + } + + d.mergedFields = mergedFields + if mergeNode != nil { + d.merge(n, mergeNode, out) + } + + d.stringMapType = stringMapType + d.generalMapType = generalMapType + return true +} + +func isStringMap(n *Node) bool { + if n.Kind != MappingNode { + return false + } + l := len(n.Content) + for i := 0; i < l; i += 2 { + shortTag := n.Content[i].ShortTag() + if shortTag != strTag && shortTag != mergeTag { + return false + } + } + return true +} + +func (d *decoder) mappingStruct(n *Node, out reflect.Value) (good bool) { + sinfo, err := getStructInfo(out.Type()) + if err != nil { + panic(err) + } + + var inlineMap reflect.Value + var elemType reflect.Type + if sinfo.InlineMap != -1 { + inlineMap = out.Field(sinfo.InlineMap) + elemType = inlineMap.Type().Elem() + } + + for _, index := range sinfo.InlineUnmarshalers { + field := d.fieldByIndex(n, out, index) + d.prepare(n, field) + } + + mergedFields := d.mergedFields + d.mergedFields = nil + var mergeNode *Node + var doneFields []bool + if d.uniqueKeys { + doneFields = make([]bool, len(sinfo.FieldsList)) + } + name := settableValueOf("") + l := len(n.Content) + for i := 0; i < l; i += 2 { + ni := n.Content[i] + if isMerge(ni) { + mergeNode = n.Content[i+1] + continue + } + if !d.unmarshal(ni, name) { + continue + } + sname := name.String() + if mergedFields != nil { + if mergedFields[sname] { + continue + } + mergedFields[sname] = true + } + if info, ok := sinfo.FieldsMap[sname]; ok { + if d.uniqueKeys { + if doneFields[info.Id] { + d.terrors = append(d.terrors, fmt.Sprintf("line %d: field %s already set in type %s", ni.Line, name.String(), out.Type())) + continue + } + doneFields[info.Id] = true + } + var field reflect.Value + if info.Inline == nil { + field = out.Field(info.Num) + } else { + field = d.fieldByIndex(n, out, info.Inline) + } + d.unmarshal(n.Content[i+1], field) + } else if sinfo.InlineMap != -1 { + if inlineMap.IsNil() { + inlineMap.Set(reflect.MakeMap(inlineMap.Type())) + } + value := reflect.New(elemType).Elem() + d.unmarshal(n.Content[i+1], value) + inlineMap.SetMapIndex(name, value) + } else if d.knownFields { + d.terrors = append(d.terrors, fmt.Sprintf("line %d: field %s not found in type %s", ni.Line, name.String(), out.Type())) + } + } + + d.mergedFields = mergedFields + if mergeNode != nil { + d.merge(n, mergeNode, out) + } + return true +} + +func failWantMap() { + failf("map merge requires map or sequence of maps as the value") +} + +func (d *decoder) setPossiblyUnhashableKey(m map[interface{}]bool, key interface{}, value bool) { + defer func() { + if err := recover(); err != nil { + failf("%v", err) + } + }() + m[key] = value +} + +func (d *decoder) getPossiblyUnhashableKey(m map[interface{}]bool, key interface{}) bool { + defer func() { + if err := recover(); err != nil { + failf("%v", err) + } + }() + return m[key] +} + +func (d *decoder) merge(parent *Node, merge *Node, out reflect.Value) { + mergedFields := d.mergedFields + if mergedFields == nil { + d.mergedFields = make(map[interface{}]bool) + for i := 0; i < len(parent.Content); i += 2 { + k := reflect.New(ifaceType).Elem() + if d.unmarshal(parent.Content[i], k) { + d.setPossiblyUnhashableKey(d.mergedFields, k.Interface(), true) + } + } + } + + switch merge.Kind { + case MappingNode: + d.unmarshal(merge, out) + case AliasNode: + if merge.Alias != nil && merge.Alias.Kind != MappingNode { + failWantMap() + } + d.unmarshal(merge, out) + case SequenceNode: + for i := 0; i < len(merge.Content); i++ { + ni := merge.Content[i] + if ni.Kind == AliasNode { + if ni.Alias != nil && ni.Alias.Kind != MappingNode { + failWantMap() + } + } else if ni.Kind != MappingNode { + failWantMap() + } + d.unmarshal(ni, out) + } + default: + failWantMap() + } + + d.mergedFields = mergedFields +} + +func isMerge(n *Node) bool { + return n.Kind == ScalarNode && n.Value == "<<" && (n.Tag == "" || n.Tag == "!" || shortTag(n.Tag) == mergeTag) +} diff --git a/vendor/go.yaml.in/yaml/v3/emitterc.go b/vendor/go.yaml.in/yaml/v3/emitterc.go new file mode 100644 index 000000000..ab4e03ba7 --- /dev/null +++ b/vendor/go.yaml.in/yaml/v3/emitterc.go @@ -0,0 +1,2054 @@ +// +// Copyright (c) 2011-2019 Canonical Ltd +// Copyright (c) 2006-2010 Kirill Simonov +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of +// this software and associated documentation files (the "Software"), to deal in +// the Software without restriction, including without limitation the rights to +// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +// of the Software, and to permit persons to whom the Software is furnished to do +// so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +package yaml + +import ( + "bytes" + "fmt" +) + +// Flush the buffer if needed. +func flush(emitter *yaml_emitter_t) bool { + if emitter.buffer_pos+5 >= len(emitter.buffer) { + return yaml_emitter_flush(emitter) + } + return true +} + +// Put a character to the output buffer. +func put(emitter *yaml_emitter_t, value byte) bool { + if emitter.buffer_pos+5 >= len(emitter.buffer) && !yaml_emitter_flush(emitter) { + return false + } + emitter.buffer[emitter.buffer_pos] = value + emitter.buffer_pos++ + emitter.column++ + return true +} + +// Put a line break to the output buffer. +func put_break(emitter *yaml_emitter_t) bool { + if emitter.buffer_pos+5 >= len(emitter.buffer) && !yaml_emitter_flush(emitter) { + return false + } + switch emitter.line_break { + case yaml_CR_BREAK: + emitter.buffer[emitter.buffer_pos] = '\r' + emitter.buffer_pos += 1 + case yaml_LN_BREAK: + emitter.buffer[emitter.buffer_pos] = '\n' + emitter.buffer_pos += 1 + case yaml_CRLN_BREAK: + emitter.buffer[emitter.buffer_pos+0] = '\r' + emitter.buffer[emitter.buffer_pos+1] = '\n' + emitter.buffer_pos += 2 + default: + panic("unknown line break setting") + } + if emitter.column == 0 { + emitter.space_above = true + } + emitter.column = 0 + emitter.line++ + // [Go] Do this here and below and drop from everywhere else (see commented lines). + emitter.indention = true + return true +} + +// Copy a character from a string into buffer. +func write(emitter *yaml_emitter_t, s []byte, i *int) bool { + if emitter.buffer_pos+5 >= len(emitter.buffer) && !yaml_emitter_flush(emitter) { + return false + } + p := emitter.buffer_pos + w := width(s[*i]) + switch w { + case 4: + emitter.buffer[p+3] = s[*i+3] + fallthrough + case 3: + emitter.buffer[p+2] = s[*i+2] + fallthrough + case 2: + emitter.buffer[p+1] = s[*i+1] + fallthrough + case 1: + emitter.buffer[p+0] = s[*i+0] + default: + panic("unknown character width") + } + emitter.column++ + emitter.buffer_pos += w + *i += w + return true +} + +// Write a whole string into buffer. +func write_all(emitter *yaml_emitter_t, s []byte) bool { + for i := 0; i < len(s); { + if !write(emitter, s, &i) { + return false + } + } + return true +} + +// Copy a line break character from a string into buffer. +func write_break(emitter *yaml_emitter_t, s []byte, i *int) bool { + if s[*i] == '\n' { + if !put_break(emitter) { + return false + } + *i++ + } else { + if !write(emitter, s, i) { + return false + } + if emitter.column == 0 { + emitter.space_above = true + } + emitter.column = 0 + emitter.line++ + // [Go] Do this here and above and drop from everywhere else (see commented lines). + emitter.indention = true + } + return true +} + +// Set an emitter error and return false. +func yaml_emitter_set_emitter_error(emitter *yaml_emitter_t, problem string) bool { + emitter.error = yaml_EMITTER_ERROR + emitter.problem = problem + return false +} + +// Emit an event. +func yaml_emitter_emit(emitter *yaml_emitter_t, event *yaml_event_t) bool { + emitter.events = append(emitter.events, *event) + for !yaml_emitter_need_more_events(emitter) { + event := &emitter.events[emitter.events_head] + if !yaml_emitter_analyze_event(emitter, event) { + return false + } + if !yaml_emitter_state_machine(emitter, event) { + return false + } + yaml_event_delete(event) + emitter.events_head++ + } + return true +} + +// Check if we need to accumulate more events before emitting. +// +// We accumulate extra +// - 1 event for DOCUMENT-START +// - 2 events for SEQUENCE-START +// - 3 events for MAPPING-START +func yaml_emitter_need_more_events(emitter *yaml_emitter_t) bool { + if emitter.events_head == len(emitter.events) { + return true + } + var accumulate int + switch emitter.events[emitter.events_head].typ { + case yaml_DOCUMENT_START_EVENT: + accumulate = 1 + break + case yaml_SEQUENCE_START_EVENT: + accumulate = 2 + break + case yaml_MAPPING_START_EVENT: + accumulate = 3 + break + default: + return false + } + if len(emitter.events)-emitter.events_head > accumulate { + return false + } + var level int + for i := emitter.events_head; i < len(emitter.events); i++ { + switch emitter.events[i].typ { + case yaml_STREAM_START_EVENT, yaml_DOCUMENT_START_EVENT, yaml_SEQUENCE_START_EVENT, yaml_MAPPING_START_EVENT: + level++ + case yaml_STREAM_END_EVENT, yaml_DOCUMENT_END_EVENT, yaml_SEQUENCE_END_EVENT, yaml_MAPPING_END_EVENT: + level-- + } + if level == 0 { + return false + } + } + return true +} + +// Append a directive to the directives stack. +func yaml_emitter_append_tag_directive(emitter *yaml_emitter_t, value *yaml_tag_directive_t, allow_duplicates bool) bool { + for i := 0; i < len(emitter.tag_directives); i++ { + if bytes.Equal(value.handle, emitter.tag_directives[i].handle) { + if allow_duplicates { + return true + } + return yaml_emitter_set_emitter_error(emitter, "duplicate %TAG directive") + } + } + + // [Go] Do we actually need to copy this given garbage collection + // and the lack of deallocating destructors? + tag_copy := yaml_tag_directive_t{ + handle: make([]byte, len(value.handle)), + prefix: make([]byte, len(value.prefix)), + } + copy(tag_copy.handle, value.handle) + copy(tag_copy.prefix, value.prefix) + emitter.tag_directives = append(emitter.tag_directives, tag_copy) + return true +} + +// Increase the indentation level. +func yaml_emitter_increase_indent_compact(emitter *yaml_emitter_t, flow, indentless bool, compact_seq bool) bool { + emitter.indents = append(emitter.indents, emitter.indent) + if emitter.indent < 0 { + if flow { + emitter.indent = emitter.best_indent + } else { + emitter.indent = 0 + } + } else if !indentless { + // [Go] This was changed so that indentations are more regular. + if emitter.states[len(emitter.states)-1] == yaml_EMIT_BLOCK_SEQUENCE_ITEM_STATE { + // The first indent inside a sequence will just skip the "- " indicator. + emitter.indent += 2 + } else { + // Everything else aligns to the chosen indentation. + emitter.indent = emitter.best_indent * ((emitter.indent + emitter.best_indent) / emitter.best_indent) + if compact_seq { + // The value compact_seq passed in is almost always set to `false` when this function is called, + // except when we are dealing with sequence nodes. So this gets triggered to subtract 2 only when we + // are increasing the indent to account for sequence nodes, which will be correct because we need to + // subtract 2 to account for the - at the beginning of the sequence node. + emitter.indent = emitter.indent - 2 + } + } + } + return true +} + +// State dispatcher. +func yaml_emitter_state_machine(emitter *yaml_emitter_t, event *yaml_event_t) bool { + switch emitter.state { + default: + case yaml_EMIT_STREAM_START_STATE: + return yaml_emitter_emit_stream_start(emitter, event) + + case yaml_EMIT_FIRST_DOCUMENT_START_STATE: + return yaml_emitter_emit_document_start(emitter, event, true) + + case yaml_EMIT_DOCUMENT_START_STATE: + return yaml_emitter_emit_document_start(emitter, event, false) + + case yaml_EMIT_DOCUMENT_CONTENT_STATE: + return yaml_emitter_emit_document_content(emitter, event) + + case yaml_EMIT_DOCUMENT_END_STATE: + return yaml_emitter_emit_document_end(emitter, event) + + case yaml_EMIT_FLOW_SEQUENCE_FIRST_ITEM_STATE: + return yaml_emitter_emit_flow_sequence_item(emitter, event, true, false) + + case yaml_EMIT_FLOW_SEQUENCE_TRAIL_ITEM_STATE: + return yaml_emitter_emit_flow_sequence_item(emitter, event, false, true) + + case yaml_EMIT_FLOW_SEQUENCE_ITEM_STATE: + return yaml_emitter_emit_flow_sequence_item(emitter, event, false, false) + + case yaml_EMIT_FLOW_MAPPING_FIRST_KEY_STATE: + return yaml_emitter_emit_flow_mapping_key(emitter, event, true, false) + + case yaml_EMIT_FLOW_MAPPING_TRAIL_KEY_STATE: + return yaml_emitter_emit_flow_mapping_key(emitter, event, false, true) + + case yaml_EMIT_FLOW_MAPPING_KEY_STATE: + return yaml_emitter_emit_flow_mapping_key(emitter, event, false, false) + + case yaml_EMIT_FLOW_MAPPING_SIMPLE_VALUE_STATE: + return yaml_emitter_emit_flow_mapping_value(emitter, event, true) + + case yaml_EMIT_FLOW_MAPPING_VALUE_STATE: + return yaml_emitter_emit_flow_mapping_value(emitter, event, false) + + case yaml_EMIT_BLOCK_SEQUENCE_FIRST_ITEM_STATE: + return yaml_emitter_emit_block_sequence_item(emitter, event, true) + + case yaml_EMIT_BLOCK_SEQUENCE_ITEM_STATE: + return yaml_emitter_emit_block_sequence_item(emitter, event, false) + + case yaml_EMIT_BLOCK_MAPPING_FIRST_KEY_STATE: + return yaml_emitter_emit_block_mapping_key(emitter, event, true) + + case yaml_EMIT_BLOCK_MAPPING_KEY_STATE: + return yaml_emitter_emit_block_mapping_key(emitter, event, false) + + case yaml_EMIT_BLOCK_MAPPING_SIMPLE_VALUE_STATE: + return yaml_emitter_emit_block_mapping_value(emitter, event, true) + + case yaml_EMIT_BLOCK_MAPPING_VALUE_STATE: + return yaml_emitter_emit_block_mapping_value(emitter, event, false) + + case yaml_EMIT_END_STATE: + return yaml_emitter_set_emitter_error(emitter, "expected nothing after STREAM-END") + } + panic("invalid emitter state") +} + +// Expect STREAM-START. +func yaml_emitter_emit_stream_start(emitter *yaml_emitter_t, event *yaml_event_t) bool { + if event.typ != yaml_STREAM_START_EVENT { + return yaml_emitter_set_emitter_error(emitter, "expected STREAM-START") + } + if emitter.encoding == yaml_ANY_ENCODING { + emitter.encoding = event.encoding + if emitter.encoding == yaml_ANY_ENCODING { + emitter.encoding = yaml_UTF8_ENCODING + } + } + if emitter.best_indent < 2 || emitter.best_indent > 9 { + emitter.best_indent = 2 + } + if emitter.best_width >= 0 && emitter.best_width <= emitter.best_indent*2 { + emitter.best_width = 80 + } + if emitter.best_width < 0 { + emitter.best_width = 1<<31 - 1 + } + if emitter.line_break == yaml_ANY_BREAK { + emitter.line_break = yaml_LN_BREAK + } + + emitter.indent = -1 + emitter.line = 0 + emitter.column = 0 + emitter.whitespace = true + emitter.indention = true + emitter.space_above = true + emitter.foot_indent = -1 + + if emitter.encoding != yaml_UTF8_ENCODING { + if !yaml_emitter_write_bom(emitter) { + return false + } + } + emitter.state = yaml_EMIT_FIRST_DOCUMENT_START_STATE + return true +} + +// Expect DOCUMENT-START or STREAM-END. +func yaml_emitter_emit_document_start(emitter *yaml_emitter_t, event *yaml_event_t, first bool) bool { + + if event.typ == yaml_DOCUMENT_START_EVENT { + + if event.version_directive != nil { + if !yaml_emitter_analyze_version_directive(emitter, event.version_directive) { + return false + } + } + + for i := 0; i < len(event.tag_directives); i++ { + tag_directive := &event.tag_directives[i] + if !yaml_emitter_analyze_tag_directive(emitter, tag_directive) { + return false + } + if !yaml_emitter_append_tag_directive(emitter, tag_directive, false) { + return false + } + } + + for i := 0; i < len(default_tag_directives); i++ { + tag_directive := &default_tag_directives[i] + if !yaml_emitter_append_tag_directive(emitter, tag_directive, true) { + return false + } + } + + implicit := event.implicit + if !first || emitter.canonical { + implicit = false + } + + if emitter.open_ended && (event.version_directive != nil || len(event.tag_directives) > 0) { + if !yaml_emitter_write_indicator(emitter, []byte("..."), true, false, false) { + return false + } + if !yaml_emitter_write_indent(emitter) { + return false + } + } + + if event.version_directive != nil { + implicit = false + if !yaml_emitter_write_indicator(emitter, []byte("%YAML"), true, false, false) { + return false + } + if !yaml_emitter_write_indicator(emitter, []byte("1.1"), true, false, false) { + return false + } + if !yaml_emitter_write_indent(emitter) { + return false + } + } + + if len(event.tag_directives) > 0 { + implicit = false + for i := 0; i < len(event.tag_directives); i++ { + tag_directive := &event.tag_directives[i] + if !yaml_emitter_write_indicator(emitter, []byte("%TAG"), true, false, false) { + return false + } + if !yaml_emitter_write_tag_handle(emitter, tag_directive.handle) { + return false + } + if !yaml_emitter_write_tag_content(emitter, tag_directive.prefix, true) { + return false + } + if !yaml_emitter_write_indent(emitter) { + return false + } + } + } + + if yaml_emitter_check_empty_document(emitter) { + implicit = false + } + if !implicit { + if !yaml_emitter_write_indent(emitter) { + return false + } + if !yaml_emitter_write_indicator(emitter, []byte("---"), true, false, false) { + return false + } + if emitter.canonical || true { + if !yaml_emitter_write_indent(emitter) { + return false + } + } + } + + if len(emitter.head_comment) > 0 { + if !yaml_emitter_process_head_comment(emitter) { + return false + } + if !put_break(emitter) { + return false + } + } + + emitter.state = yaml_EMIT_DOCUMENT_CONTENT_STATE + return true + } + + if event.typ == yaml_STREAM_END_EVENT { + if emitter.open_ended { + if !yaml_emitter_write_indicator(emitter, []byte("..."), true, false, false) { + return false + } + if !yaml_emitter_write_indent(emitter) { + return false + } + } + if !yaml_emitter_flush(emitter) { + return false + } + emitter.state = yaml_EMIT_END_STATE + return true + } + + return yaml_emitter_set_emitter_error(emitter, "expected DOCUMENT-START or STREAM-END") +} + +// yaml_emitter_increase_indent preserves the original signature and delegates to +// yaml_emitter_increase_indent_compact without compact-sequence indentation +func yaml_emitter_increase_indent(emitter *yaml_emitter_t, flow, indentless bool) bool { + return yaml_emitter_increase_indent_compact(emitter, flow, indentless, false) +} + +// yaml_emitter_process_line_comment preserves the original signature and delegates to +// yaml_emitter_process_line_comment_linebreak passing false for linebreak +func yaml_emitter_process_line_comment(emitter *yaml_emitter_t) bool { + return yaml_emitter_process_line_comment_linebreak(emitter, false) +} + +// Expect the root node. +func yaml_emitter_emit_document_content(emitter *yaml_emitter_t, event *yaml_event_t) bool { + emitter.states = append(emitter.states, yaml_EMIT_DOCUMENT_END_STATE) + + if !yaml_emitter_process_head_comment(emitter) { + return false + } + if !yaml_emitter_emit_node(emitter, event, true, false, false, false) { + return false + } + if !yaml_emitter_process_line_comment(emitter) { + return false + } + if !yaml_emitter_process_foot_comment(emitter) { + return false + } + return true +} + +// Expect DOCUMENT-END. +func yaml_emitter_emit_document_end(emitter *yaml_emitter_t, event *yaml_event_t) bool { + if event.typ != yaml_DOCUMENT_END_EVENT { + return yaml_emitter_set_emitter_error(emitter, "expected DOCUMENT-END") + } + // [Go] Force document foot separation. + emitter.foot_indent = 0 + if !yaml_emitter_process_foot_comment(emitter) { + return false + } + emitter.foot_indent = -1 + if !yaml_emitter_write_indent(emitter) { + return false + } + if !event.implicit { + // [Go] Allocate the slice elsewhere. + if !yaml_emitter_write_indicator(emitter, []byte("..."), true, false, false) { + return false + } + if !yaml_emitter_write_indent(emitter) { + return false + } + } + if !yaml_emitter_flush(emitter) { + return false + } + emitter.state = yaml_EMIT_DOCUMENT_START_STATE + emitter.tag_directives = emitter.tag_directives[:0] + return true +} + +// Expect a flow item node. +func yaml_emitter_emit_flow_sequence_item(emitter *yaml_emitter_t, event *yaml_event_t, first, trail bool) bool { + if first { + if !yaml_emitter_write_indicator(emitter, []byte{'['}, true, true, false) { + return false + } + if !yaml_emitter_increase_indent(emitter, true, false) { + return false + } + emitter.flow_level++ + } + + if event.typ == yaml_SEQUENCE_END_EVENT { + if emitter.canonical && !first && !trail { + if !yaml_emitter_write_indicator(emitter, []byte{','}, false, false, false) { + return false + } + } + emitter.flow_level-- + emitter.indent = emitter.indents[len(emitter.indents)-1] + emitter.indents = emitter.indents[:len(emitter.indents)-1] + if emitter.column == 0 || emitter.canonical && !first { + if !yaml_emitter_write_indent(emitter) { + return false + } + } + if !yaml_emitter_write_indicator(emitter, []byte{']'}, false, false, false) { + return false + } + if !yaml_emitter_process_line_comment(emitter) { + return false + } + if !yaml_emitter_process_foot_comment(emitter) { + return false + } + emitter.state = emitter.states[len(emitter.states)-1] + emitter.states = emitter.states[:len(emitter.states)-1] + + return true + } + + if !first && !trail { + if !yaml_emitter_write_indicator(emitter, []byte{','}, false, false, false) { + return false + } + } + + if !yaml_emitter_process_head_comment(emitter) { + return false + } + if emitter.column == 0 { + if !yaml_emitter_write_indent(emitter) { + return false + } + } + + if emitter.canonical || emitter.column > emitter.best_width { + if !yaml_emitter_write_indent(emitter) { + return false + } + } + if len(emitter.line_comment)+len(emitter.foot_comment)+len(emitter.tail_comment) > 0 { + emitter.states = append(emitter.states, yaml_EMIT_FLOW_SEQUENCE_TRAIL_ITEM_STATE) + } else { + emitter.states = append(emitter.states, yaml_EMIT_FLOW_SEQUENCE_ITEM_STATE) + } + if !yaml_emitter_emit_node(emitter, event, false, true, false, false) { + return false + } + if len(emitter.line_comment)+len(emitter.foot_comment)+len(emitter.tail_comment) > 0 { + if !yaml_emitter_write_indicator(emitter, []byte{','}, false, false, false) { + return false + } + } + if !yaml_emitter_process_line_comment(emitter) { + return false + } + if !yaml_emitter_process_foot_comment(emitter) { + return false + } + return true +} + +// Expect a flow key node. +func yaml_emitter_emit_flow_mapping_key(emitter *yaml_emitter_t, event *yaml_event_t, first, trail bool) bool { + if first { + if !yaml_emitter_write_indicator(emitter, []byte{'{'}, true, true, false) { + return false + } + if !yaml_emitter_increase_indent(emitter, true, false) { + return false + } + emitter.flow_level++ + } + + if event.typ == yaml_MAPPING_END_EVENT { + if (emitter.canonical || len(emitter.head_comment)+len(emitter.foot_comment)+len(emitter.tail_comment) > 0) && !first && !trail { + if !yaml_emitter_write_indicator(emitter, []byte{','}, false, false, false) { + return false + } + } + if !yaml_emitter_process_head_comment(emitter) { + return false + } + emitter.flow_level-- + emitter.indent = emitter.indents[len(emitter.indents)-1] + emitter.indents = emitter.indents[:len(emitter.indents)-1] + if emitter.canonical && !first { + if !yaml_emitter_write_indent(emitter) { + return false + } + } + if !yaml_emitter_write_indicator(emitter, []byte{'}'}, false, false, false) { + return false + } + if !yaml_emitter_process_line_comment(emitter) { + return false + } + if !yaml_emitter_process_foot_comment(emitter) { + return false + } + emitter.state = emitter.states[len(emitter.states)-1] + emitter.states = emitter.states[:len(emitter.states)-1] + return true + } + + if !first && !trail { + if !yaml_emitter_write_indicator(emitter, []byte{','}, false, false, false) { + return false + } + } + + if !yaml_emitter_process_head_comment(emitter) { + return false + } + + if emitter.column == 0 { + if !yaml_emitter_write_indent(emitter) { + return false + } + } + + if emitter.canonical || emitter.column > emitter.best_width { + if !yaml_emitter_write_indent(emitter) { + return false + } + } + + if !emitter.canonical && yaml_emitter_check_simple_key(emitter) { + emitter.states = append(emitter.states, yaml_EMIT_FLOW_MAPPING_SIMPLE_VALUE_STATE) + return yaml_emitter_emit_node(emitter, event, false, false, true, true) + } + if !yaml_emitter_write_indicator(emitter, []byte{'?'}, true, false, false) { + return false + } + emitter.states = append(emitter.states, yaml_EMIT_FLOW_MAPPING_VALUE_STATE) + return yaml_emitter_emit_node(emitter, event, false, false, true, false) +} + +// Expect a flow value node. +func yaml_emitter_emit_flow_mapping_value(emitter *yaml_emitter_t, event *yaml_event_t, simple bool) bool { + if simple { + if !yaml_emitter_write_indicator(emitter, []byte{':'}, false, false, false) { + return false + } + } else { + if emitter.canonical || emitter.column > emitter.best_width { + if !yaml_emitter_write_indent(emitter) { + return false + } + } + if !yaml_emitter_write_indicator(emitter, []byte{':'}, true, false, false) { + return false + } + } + if len(emitter.line_comment)+len(emitter.foot_comment)+len(emitter.tail_comment) > 0 { + emitter.states = append(emitter.states, yaml_EMIT_FLOW_MAPPING_TRAIL_KEY_STATE) + } else { + emitter.states = append(emitter.states, yaml_EMIT_FLOW_MAPPING_KEY_STATE) + } + if !yaml_emitter_emit_node(emitter, event, false, false, true, false) { + return false + } + if len(emitter.line_comment)+len(emitter.foot_comment)+len(emitter.tail_comment) > 0 { + if !yaml_emitter_write_indicator(emitter, []byte{','}, false, false, false) { + return false + } + } + if !yaml_emitter_process_line_comment(emitter) { + return false + } + if !yaml_emitter_process_foot_comment(emitter) { + return false + } + return true +} + +// Expect a block item node. +func yaml_emitter_emit_block_sequence_item(emitter *yaml_emitter_t, event *yaml_event_t, first bool) bool { + if first { + // emitter.mapping context tells us if we are currently in a mapping context. + // emiiter.column tells us which column we are in in the yaml output. 0 is the first char of the column. + // emitter.indentation tells us if the last character was an indentation character. + // emitter.compact_sequence_indent tells us if '- ' is considered part of the indentation for sequence elements. + // So, `seq` means that we are in a mapping context, and we are either at the first char of the column or + // the last character was not an indentation character, and we consider '- ' part of the indentation + // for sequence elements. + seq := emitter.mapping_context && (emitter.column == 0 || !emitter.indention) && + emitter.compact_sequence_indent + if !yaml_emitter_increase_indent_compact(emitter, false, false, seq) { + return false + } + } + if event.typ == yaml_SEQUENCE_END_EVENT { + emitter.indent = emitter.indents[len(emitter.indents)-1] + emitter.indents = emitter.indents[:len(emitter.indents)-1] + emitter.state = emitter.states[len(emitter.states)-1] + emitter.states = emitter.states[:len(emitter.states)-1] + return true + } + if !yaml_emitter_process_head_comment(emitter) { + return false + } + if !yaml_emitter_write_indent(emitter) { + return false + } + if !yaml_emitter_write_indicator(emitter, []byte{'-'}, true, false, true) { + return false + } + emitter.states = append(emitter.states, yaml_EMIT_BLOCK_SEQUENCE_ITEM_STATE) + if !yaml_emitter_emit_node(emitter, event, false, true, false, false) { + return false + } + if !yaml_emitter_process_line_comment(emitter) { + return false + } + if !yaml_emitter_process_foot_comment(emitter) { + return false + } + return true +} + +// Expect a block key node. +func yaml_emitter_emit_block_mapping_key(emitter *yaml_emitter_t, event *yaml_event_t, first bool) bool { + if first { + if !yaml_emitter_increase_indent(emitter, false, false) { + return false + } + } + if !yaml_emitter_process_head_comment(emitter) { + return false + } + if event.typ == yaml_MAPPING_END_EVENT { + emitter.indent = emitter.indents[len(emitter.indents)-1] + emitter.indents = emitter.indents[:len(emitter.indents)-1] + emitter.state = emitter.states[len(emitter.states)-1] + emitter.states = emitter.states[:len(emitter.states)-1] + return true + } + if !yaml_emitter_write_indent(emitter) { + return false + } + if len(emitter.line_comment) > 0 { + // [Go] A line comment was provided for the key. That's unusual as the + // scanner associates line comments with the value. Either way, + // save the line comment and render it appropriately later. + emitter.key_line_comment = emitter.line_comment + emitter.line_comment = nil + } + if yaml_emitter_check_simple_key(emitter) { + emitter.states = append(emitter.states, yaml_EMIT_BLOCK_MAPPING_SIMPLE_VALUE_STATE) + return yaml_emitter_emit_node(emitter, event, false, false, true, true) + } + if !yaml_emitter_write_indicator(emitter, []byte{'?'}, true, false, true) { + return false + } + emitter.states = append(emitter.states, yaml_EMIT_BLOCK_MAPPING_VALUE_STATE) + return yaml_emitter_emit_node(emitter, event, false, false, true, false) +} + +// Expect a block value node. +func yaml_emitter_emit_block_mapping_value(emitter *yaml_emitter_t, event *yaml_event_t, simple bool) bool { + if simple { + if !yaml_emitter_write_indicator(emitter, []byte{':'}, false, false, false) { + return false + } + } else { + if !yaml_emitter_write_indent(emitter) { + return false + } + if !yaml_emitter_write_indicator(emitter, []byte{':'}, true, false, true) { + return false + } + } + if len(emitter.key_line_comment) > 0 { + // [Go] Line comments are generally associated with the value, but when there's + // no value on the same line as a mapping key they end up attached to the + // key itself. + if event.typ == yaml_SCALAR_EVENT { + if len(emitter.line_comment) == 0 { + // A scalar is coming and it has no line comments by itself yet, + // so just let it handle the line comment as usual. If it has a + // line comment, we can't have both so the one from the key is lost. + emitter.line_comment = emitter.key_line_comment + emitter.key_line_comment = nil + } + } else if event.sequence_style() != yaml_FLOW_SEQUENCE_STYLE && (event.typ == yaml_MAPPING_START_EVENT || event.typ == yaml_SEQUENCE_START_EVENT) { + // An indented block follows, so write the comment right now. + emitter.line_comment, emitter.key_line_comment = emitter.key_line_comment, emitter.line_comment + if !yaml_emitter_process_line_comment(emitter) { + return false + } + emitter.line_comment, emitter.key_line_comment = emitter.key_line_comment, emitter.line_comment + } + } + emitter.states = append(emitter.states, yaml_EMIT_BLOCK_MAPPING_KEY_STATE) + if !yaml_emitter_emit_node(emitter, event, false, false, true, false) { + return false + } + if !yaml_emitter_process_line_comment(emitter) { + return false + } + if !yaml_emitter_process_foot_comment(emitter) { + return false + } + return true +} + +func yaml_emitter_silent_nil_event(emitter *yaml_emitter_t, event *yaml_event_t) bool { + return event.typ == yaml_SCALAR_EVENT && event.implicit && !emitter.canonical && len(emitter.scalar_data.value) == 0 +} + +// Expect a node. +func yaml_emitter_emit_node(emitter *yaml_emitter_t, event *yaml_event_t, + root bool, sequence bool, mapping bool, simple_key bool) bool { + + emitter.root_context = root + emitter.sequence_context = sequence + emitter.mapping_context = mapping + emitter.simple_key_context = simple_key + + switch event.typ { + case yaml_ALIAS_EVENT: + return yaml_emitter_emit_alias(emitter, event) + case yaml_SCALAR_EVENT: + return yaml_emitter_emit_scalar(emitter, event) + case yaml_SEQUENCE_START_EVENT: + return yaml_emitter_emit_sequence_start(emitter, event) + case yaml_MAPPING_START_EVENT: + return yaml_emitter_emit_mapping_start(emitter, event) + default: + return yaml_emitter_set_emitter_error(emitter, + fmt.Sprintf("expected SCALAR, SEQUENCE-START, MAPPING-START, or ALIAS, but got %v", event.typ)) + } +} + +// Expect ALIAS. +func yaml_emitter_emit_alias(emitter *yaml_emitter_t, event *yaml_event_t) bool { + if !yaml_emitter_process_anchor(emitter) { + return false + } + emitter.state = emitter.states[len(emitter.states)-1] + emitter.states = emitter.states[:len(emitter.states)-1] + return true +} + +// Expect SCALAR. +func yaml_emitter_emit_scalar(emitter *yaml_emitter_t, event *yaml_event_t) bool { + if !yaml_emitter_select_scalar_style(emitter, event) { + return false + } + if !yaml_emitter_process_anchor(emitter) { + return false + } + if !yaml_emitter_process_tag(emitter) { + return false + } + if !yaml_emitter_increase_indent(emitter, true, false) { + return false + } + if !yaml_emitter_process_scalar(emitter) { + return false + } + emitter.indent = emitter.indents[len(emitter.indents)-1] + emitter.indents = emitter.indents[:len(emitter.indents)-1] + emitter.state = emitter.states[len(emitter.states)-1] + emitter.states = emitter.states[:len(emitter.states)-1] + return true +} + +// Expect SEQUENCE-START. +func yaml_emitter_emit_sequence_start(emitter *yaml_emitter_t, event *yaml_event_t) bool { + if !yaml_emitter_process_anchor(emitter) { + return false + } + if !yaml_emitter_process_tag(emitter) { + return false + } + if emitter.flow_level > 0 || emitter.canonical || event.sequence_style() == yaml_FLOW_SEQUENCE_STYLE || + yaml_emitter_check_empty_sequence(emitter) { + emitter.state = yaml_EMIT_FLOW_SEQUENCE_FIRST_ITEM_STATE + } else { + emitter.state = yaml_EMIT_BLOCK_SEQUENCE_FIRST_ITEM_STATE + } + return true +} + +// Expect MAPPING-START. +func yaml_emitter_emit_mapping_start(emitter *yaml_emitter_t, event *yaml_event_t) bool { + if !yaml_emitter_process_anchor(emitter) { + return false + } + if !yaml_emitter_process_tag(emitter) { + return false + } + if emitter.flow_level > 0 || emitter.canonical || event.mapping_style() == yaml_FLOW_MAPPING_STYLE || + yaml_emitter_check_empty_mapping(emitter) { + emitter.state = yaml_EMIT_FLOW_MAPPING_FIRST_KEY_STATE + } else { + emitter.state = yaml_EMIT_BLOCK_MAPPING_FIRST_KEY_STATE + } + return true +} + +// Check if the document content is an empty scalar. +func yaml_emitter_check_empty_document(emitter *yaml_emitter_t) bool { + return false // [Go] Huh? +} + +// Check if the next events represent an empty sequence. +func yaml_emitter_check_empty_sequence(emitter *yaml_emitter_t) bool { + if len(emitter.events)-emitter.events_head < 2 { + return false + } + return emitter.events[emitter.events_head].typ == yaml_SEQUENCE_START_EVENT && + emitter.events[emitter.events_head+1].typ == yaml_SEQUENCE_END_EVENT +} + +// Check if the next events represent an empty mapping. +func yaml_emitter_check_empty_mapping(emitter *yaml_emitter_t) bool { + if len(emitter.events)-emitter.events_head < 2 { + return false + } + return emitter.events[emitter.events_head].typ == yaml_MAPPING_START_EVENT && + emitter.events[emitter.events_head+1].typ == yaml_MAPPING_END_EVENT +} + +// Check if the next node can be expressed as a simple key. +func yaml_emitter_check_simple_key(emitter *yaml_emitter_t) bool { + length := 0 + switch emitter.events[emitter.events_head].typ { + case yaml_ALIAS_EVENT: + length += len(emitter.anchor_data.anchor) + case yaml_SCALAR_EVENT: + if emitter.scalar_data.multiline { + return false + } + length += len(emitter.anchor_data.anchor) + + len(emitter.tag_data.handle) + + len(emitter.tag_data.suffix) + + len(emitter.scalar_data.value) + case yaml_SEQUENCE_START_EVENT: + if !yaml_emitter_check_empty_sequence(emitter) { + return false + } + length += len(emitter.anchor_data.anchor) + + len(emitter.tag_data.handle) + + len(emitter.tag_data.suffix) + case yaml_MAPPING_START_EVENT: + if !yaml_emitter_check_empty_mapping(emitter) { + return false + } + length += len(emitter.anchor_data.anchor) + + len(emitter.tag_data.handle) + + len(emitter.tag_data.suffix) + default: + return false + } + return length <= 128 +} + +// Determine an acceptable scalar style. +func yaml_emitter_select_scalar_style(emitter *yaml_emitter_t, event *yaml_event_t) bool { + + no_tag := len(emitter.tag_data.handle) == 0 && len(emitter.tag_data.suffix) == 0 + if no_tag && !event.implicit && !event.quoted_implicit { + return yaml_emitter_set_emitter_error(emitter, "neither tag nor implicit flags are specified") + } + + style := event.scalar_style() + if style == yaml_ANY_SCALAR_STYLE { + style = yaml_PLAIN_SCALAR_STYLE + } + if emitter.canonical { + style = yaml_DOUBLE_QUOTED_SCALAR_STYLE + } + if emitter.simple_key_context && emitter.scalar_data.multiline { + style = yaml_DOUBLE_QUOTED_SCALAR_STYLE + } + + if style == yaml_PLAIN_SCALAR_STYLE { + if emitter.flow_level > 0 && !emitter.scalar_data.flow_plain_allowed || + emitter.flow_level == 0 && !emitter.scalar_data.block_plain_allowed { + style = yaml_SINGLE_QUOTED_SCALAR_STYLE + } + if len(emitter.scalar_data.value) == 0 && (emitter.flow_level > 0 || emitter.simple_key_context) { + style = yaml_SINGLE_QUOTED_SCALAR_STYLE + } + if no_tag && !event.implicit { + style = yaml_SINGLE_QUOTED_SCALAR_STYLE + } + } + if style == yaml_SINGLE_QUOTED_SCALAR_STYLE { + if !emitter.scalar_data.single_quoted_allowed { + style = yaml_DOUBLE_QUOTED_SCALAR_STYLE + } + } + if style == yaml_LITERAL_SCALAR_STYLE || style == yaml_FOLDED_SCALAR_STYLE { + if !emitter.scalar_data.block_allowed || emitter.flow_level > 0 || emitter.simple_key_context { + style = yaml_DOUBLE_QUOTED_SCALAR_STYLE + } + } + + if no_tag && !event.quoted_implicit && style != yaml_PLAIN_SCALAR_STYLE { + emitter.tag_data.handle = []byte{'!'} + } + emitter.scalar_data.style = style + return true +} + +// Write an anchor. +func yaml_emitter_process_anchor(emitter *yaml_emitter_t) bool { + if emitter.anchor_data.anchor == nil { + return true + } + c := []byte{'&'} + if emitter.anchor_data.alias { + c[0] = '*' + } + if !yaml_emitter_write_indicator(emitter, c, true, false, false) { + return false + } + return yaml_emitter_write_anchor(emitter, emitter.anchor_data.anchor) +} + +// Write a tag. +func yaml_emitter_process_tag(emitter *yaml_emitter_t) bool { + if len(emitter.tag_data.handle) == 0 && len(emitter.tag_data.suffix) == 0 { + return true + } + if len(emitter.tag_data.handle) > 0 { + if !yaml_emitter_write_tag_handle(emitter, emitter.tag_data.handle) { + return false + } + if len(emitter.tag_data.suffix) > 0 { + if !yaml_emitter_write_tag_content(emitter, emitter.tag_data.suffix, false) { + return false + } + } + } else { + // [Go] Allocate these slices elsewhere. + if !yaml_emitter_write_indicator(emitter, []byte("!<"), true, false, false) { + return false + } + if !yaml_emitter_write_tag_content(emitter, emitter.tag_data.suffix, false) { + return false + } + if !yaml_emitter_write_indicator(emitter, []byte{'>'}, false, false, false) { + return false + } + } + return true +} + +// Write a scalar. +func yaml_emitter_process_scalar(emitter *yaml_emitter_t) bool { + switch emitter.scalar_data.style { + case yaml_PLAIN_SCALAR_STYLE: + return yaml_emitter_write_plain_scalar(emitter, emitter.scalar_data.value, !emitter.simple_key_context) + + case yaml_SINGLE_QUOTED_SCALAR_STYLE: + return yaml_emitter_write_single_quoted_scalar(emitter, emitter.scalar_data.value, !emitter.simple_key_context) + + case yaml_DOUBLE_QUOTED_SCALAR_STYLE: + return yaml_emitter_write_double_quoted_scalar(emitter, emitter.scalar_data.value, !emitter.simple_key_context) + + case yaml_LITERAL_SCALAR_STYLE: + return yaml_emitter_write_literal_scalar(emitter, emitter.scalar_data.value) + + case yaml_FOLDED_SCALAR_STYLE: + return yaml_emitter_write_folded_scalar(emitter, emitter.scalar_data.value) + } + panic("unknown scalar style") +} + +// Write a head comment. +func yaml_emitter_process_head_comment(emitter *yaml_emitter_t) bool { + if len(emitter.tail_comment) > 0 { + if !yaml_emitter_write_indent(emitter) { + return false + } + if !yaml_emitter_write_comment(emitter, emitter.tail_comment) { + return false + } + emitter.tail_comment = emitter.tail_comment[:0] + emitter.foot_indent = emitter.indent + if emitter.foot_indent < 0 { + emitter.foot_indent = 0 + } + } + + if len(emitter.head_comment) == 0 { + return true + } + if !yaml_emitter_write_indent(emitter) { + return false + } + if !yaml_emitter_write_comment(emitter, emitter.head_comment) { + return false + } + emitter.head_comment = emitter.head_comment[:0] + return true +} + +// Write an line comment. +func yaml_emitter_process_line_comment_linebreak(emitter *yaml_emitter_t, linebreak bool) bool { + if len(emitter.line_comment) == 0 { + // The next 3 lines are needed to resolve an issue with leading newlines + // See https://github.com/go-yaml/yaml/issues/755 + // When linebreak is set to true, put_break will be called and will add + // the needed newline. + if linebreak && !put_break(emitter) { + return false + } + return true + } + if !emitter.whitespace { + if !put(emitter, ' ') { + return false + } + } + if !yaml_emitter_write_comment(emitter, emitter.line_comment) { + return false + } + emitter.line_comment = emitter.line_comment[:0] + return true +} + +// Write a foot comment. +func yaml_emitter_process_foot_comment(emitter *yaml_emitter_t) bool { + if len(emitter.foot_comment) == 0 { + return true + } + if !yaml_emitter_write_indent(emitter) { + return false + } + if !yaml_emitter_write_comment(emitter, emitter.foot_comment) { + return false + } + emitter.foot_comment = emitter.foot_comment[:0] + emitter.foot_indent = emitter.indent + if emitter.foot_indent < 0 { + emitter.foot_indent = 0 + } + return true +} + +// Check if a %YAML directive is valid. +func yaml_emitter_analyze_version_directive(emitter *yaml_emitter_t, version_directive *yaml_version_directive_t) bool { + if version_directive.major != 1 || version_directive.minor != 1 { + return yaml_emitter_set_emitter_error(emitter, "incompatible %YAML directive") + } + return true +} + +// Check if a %TAG directive is valid. +func yaml_emitter_analyze_tag_directive(emitter *yaml_emitter_t, tag_directive *yaml_tag_directive_t) bool { + handle := tag_directive.handle + prefix := tag_directive.prefix + if len(handle) == 0 { + return yaml_emitter_set_emitter_error(emitter, "tag handle must not be empty") + } + if handle[0] != '!' { + return yaml_emitter_set_emitter_error(emitter, "tag handle must start with '!'") + } + if handle[len(handle)-1] != '!' { + return yaml_emitter_set_emitter_error(emitter, "tag handle must end with '!'") + } + for i := 1; i < len(handle)-1; i += width(handle[i]) { + if !is_alpha(handle, i) { + return yaml_emitter_set_emitter_error(emitter, "tag handle must contain alphanumerical characters only") + } + } + if len(prefix) == 0 { + return yaml_emitter_set_emitter_error(emitter, "tag prefix must not be empty") + } + return true +} + +// Check if an anchor is valid. +func yaml_emitter_analyze_anchor(emitter *yaml_emitter_t, anchor []byte, alias bool) bool { + if len(anchor) == 0 { + problem := "anchor value must not be empty" + if alias { + problem = "alias value must not be empty" + } + return yaml_emitter_set_emitter_error(emitter, problem) + } + for i := 0; i < len(anchor); i += width(anchor[i]) { + if !is_alpha(anchor, i) { + problem := "anchor value must contain alphanumerical characters only" + if alias { + problem = "alias value must contain alphanumerical characters only" + } + return yaml_emitter_set_emitter_error(emitter, problem) + } + } + emitter.anchor_data.anchor = anchor + emitter.anchor_data.alias = alias + return true +} + +// Check if a tag is valid. +func yaml_emitter_analyze_tag(emitter *yaml_emitter_t, tag []byte) bool { + if len(tag) == 0 { + return yaml_emitter_set_emitter_error(emitter, "tag value must not be empty") + } + for i := 0; i < len(emitter.tag_directives); i++ { + tag_directive := &emitter.tag_directives[i] + if bytes.HasPrefix(tag, tag_directive.prefix) { + emitter.tag_data.handle = tag_directive.handle + emitter.tag_data.suffix = tag[len(tag_directive.prefix):] + return true + } + } + emitter.tag_data.suffix = tag + return true +} + +// Check if a scalar is valid. +func yaml_emitter_analyze_scalar(emitter *yaml_emitter_t, value []byte) bool { + var ( + block_indicators = false + flow_indicators = false + line_breaks = false + special_characters = false + tab_characters = false + + leading_space = false + leading_break = false + trailing_space = false + trailing_break = false + break_space = false + space_break = false + + preceded_by_whitespace = false + followed_by_whitespace = false + previous_space = false + previous_break = false + ) + + emitter.scalar_data.value = value + + if len(value) == 0 { + emitter.scalar_data.multiline = false + emitter.scalar_data.flow_plain_allowed = false + emitter.scalar_data.block_plain_allowed = true + emitter.scalar_data.single_quoted_allowed = true + emitter.scalar_data.block_allowed = false + return true + } + + if len(value) >= 3 && ((value[0] == '-' && value[1] == '-' && value[2] == '-') || (value[0] == '.' && value[1] == '.' && value[2] == '.')) { + block_indicators = true + flow_indicators = true + } + + preceded_by_whitespace = true + for i, w := 0, 0; i < len(value); i += w { + w = width(value[i]) + followed_by_whitespace = i+w >= len(value) || is_blank(value, i+w) + + if i == 0 { + switch value[i] { + case '#', ',', '[', ']', '{', '}', '&', '*', '!', '|', '>', '\'', '"', '%', '@', '`': + flow_indicators = true + block_indicators = true + case '?', ':': + flow_indicators = true + if followed_by_whitespace { + block_indicators = true + } + case '-': + if followed_by_whitespace { + flow_indicators = true + block_indicators = true + } + } + } else { + switch value[i] { + case ',', '?', '[', ']', '{', '}': + flow_indicators = true + case ':': + flow_indicators = true + if followed_by_whitespace { + block_indicators = true + } + case '#': + if preceded_by_whitespace { + flow_indicators = true + block_indicators = true + } + } + } + + if value[i] == '\t' { + tab_characters = true + } else if !is_printable(value, i) || !is_ascii(value, i) && !emitter.unicode { + special_characters = true + } + if is_space(value, i) { + if i == 0 { + leading_space = true + } + if i+width(value[i]) == len(value) { + trailing_space = true + } + if previous_break { + break_space = true + } + previous_space = true + previous_break = false + } else if is_break(value, i) { + line_breaks = true + if i == 0 { + leading_break = true + } + if i+width(value[i]) == len(value) { + trailing_break = true + } + if previous_space { + space_break = true + } + previous_space = false + previous_break = true + } else { + previous_space = false + previous_break = false + } + + // [Go]: Why 'z'? Couldn't be the end of the string as that's the loop condition. + preceded_by_whitespace = is_blankz(value, i) + } + + emitter.scalar_data.multiline = line_breaks + emitter.scalar_data.flow_plain_allowed = true + emitter.scalar_data.block_plain_allowed = true + emitter.scalar_data.single_quoted_allowed = true + emitter.scalar_data.block_allowed = true + + if leading_space || leading_break || trailing_space || trailing_break { + emitter.scalar_data.flow_plain_allowed = false + emitter.scalar_data.block_plain_allowed = false + } + if trailing_space { + emitter.scalar_data.block_allowed = false + } + if break_space { + emitter.scalar_data.flow_plain_allowed = false + emitter.scalar_data.block_plain_allowed = false + emitter.scalar_data.single_quoted_allowed = false + } + if space_break || tab_characters || special_characters { + emitter.scalar_data.flow_plain_allowed = false + emitter.scalar_data.block_plain_allowed = false + emitter.scalar_data.single_quoted_allowed = false + } + if space_break || special_characters { + emitter.scalar_data.block_allowed = false + } + if line_breaks { + emitter.scalar_data.flow_plain_allowed = false + emitter.scalar_data.block_plain_allowed = false + } + if flow_indicators { + emitter.scalar_data.flow_plain_allowed = false + } + if block_indicators { + emitter.scalar_data.block_plain_allowed = false + } + return true +} + +// Check if the event data is valid. +func yaml_emitter_analyze_event(emitter *yaml_emitter_t, event *yaml_event_t) bool { + + emitter.anchor_data.anchor = nil + emitter.tag_data.handle = nil + emitter.tag_data.suffix = nil + emitter.scalar_data.value = nil + + if len(event.head_comment) > 0 { + emitter.head_comment = event.head_comment + } + if len(event.line_comment) > 0 { + emitter.line_comment = event.line_comment + } + if len(event.foot_comment) > 0 { + emitter.foot_comment = event.foot_comment + } + if len(event.tail_comment) > 0 { + emitter.tail_comment = event.tail_comment + } + + switch event.typ { + case yaml_ALIAS_EVENT: + if !yaml_emitter_analyze_anchor(emitter, event.anchor, true) { + return false + } + + case yaml_SCALAR_EVENT: + if len(event.anchor) > 0 { + if !yaml_emitter_analyze_anchor(emitter, event.anchor, false) { + return false + } + } + if len(event.tag) > 0 && (emitter.canonical || (!event.implicit && !event.quoted_implicit)) { + if !yaml_emitter_analyze_tag(emitter, event.tag) { + return false + } + } + if !yaml_emitter_analyze_scalar(emitter, event.value) { + return false + } + + case yaml_SEQUENCE_START_EVENT: + if len(event.anchor) > 0 { + if !yaml_emitter_analyze_anchor(emitter, event.anchor, false) { + return false + } + } + if len(event.tag) > 0 && (emitter.canonical || !event.implicit) { + if !yaml_emitter_analyze_tag(emitter, event.tag) { + return false + } + } + + case yaml_MAPPING_START_EVENT: + if len(event.anchor) > 0 { + if !yaml_emitter_analyze_anchor(emitter, event.anchor, false) { + return false + } + } + if len(event.tag) > 0 && (emitter.canonical || !event.implicit) { + if !yaml_emitter_analyze_tag(emitter, event.tag) { + return false + } + } + } + return true +} + +// Write the BOM character. +func yaml_emitter_write_bom(emitter *yaml_emitter_t) bool { + if !flush(emitter) { + return false + } + pos := emitter.buffer_pos + emitter.buffer[pos+0] = '\xEF' + emitter.buffer[pos+1] = '\xBB' + emitter.buffer[pos+2] = '\xBF' + emitter.buffer_pos += 3 + return true +} + +func yaml_emitter_write_indent(emitter *yaml_emitter_t) bool { + indent := emitter.indent + if indent < 0 { + indent = 0 + } + if !emitter.indention || emitter.column > indent || (emitter.column == indent && !emitter.whitespace) { + if !put_break(emitter) { + return false + } + } + if emitter.foot_indent == indent { + if !put_break(emitter) { + return false + } + } + for emitter.column < indent { + if !put(emitter, ' ') { + return false + } + } + emitter.whitespace = true + //emitter.indention = true + emitter.space_above = false + emitter.foot_indent = -1 + return true +} + +func yaml_emitter_write_indicator(emitter *yaml_emitter_t, indicator []byte, need_whitespace, is_whitespace, is_indention bool) bool { + if need_whitespace && !emitter.whitespace { + if !put(emitter, ' ') { + return false + } + } + if !write_all(emitter, indicator) { + return false + } + emitter.whitespace = is_whitespace + emitter.indention = (emitter.indention && is_indention) + emitter.open_ended = false + return true +} + +func yaml_emitter_write_anchor(emitter *yaml_emitter_t, value []byte) bool { + if !write_all(emitter, value) { + return false + } + emitter.whitespace = false + emitter.indention = false + return true +} + +func yaml_emitter_write_tag_handle(emitter *yaml_emitter_t, value []byte) bool { + if !emitter.whitespace { + if !put(emitter, ' ') { + return false + } + } + if !write_all(emitter, value) { + return false + } + emitter.whitespace = false + emitter.indention = false + return true +} + +func yaml_emitter_write_tag_content(emitter *yaml_emitter_t, value []byte, need_whitespace bool) bool { + if need_whitespace && !emitter.whitespace { + if !put(emitter, ' ') { + return false + } + } + for i := 0; i < len(value); { + var must_write bool + switch value[i] { + case ';', '/', '?', ':', '@', '&', '=', '+', '$', ',', '_', '.', '~', '*', '\'', '(', ')', '[', ']': + must_write = true + default: + must_write = is_alpha(value, i) + } + if must_write { + if !write(emitter, value, &i) { + return false + } + } else { + w := width(value[i]) + for k := 0; k < w; k++ { + octet := value[i] + i++ + if !put(emitter, '%') { + return false + } + + c := octet >> 4 + if c < 10 { + c += '0' + } else { + c += 'A' - 10 + } + if !put(emitter, c) { + return false + } + + c = octet & 0x0f + if c < 10 { + c += '0' + } else { + c += 'A' - 10 + } + if !put(emitter, c) { + return false + } + } + } + } + emitter.whitespace = false + emitter.indention = false + return true +} + +func yaml_emitter_write_plain_scalar(emitter *yaml_emitter_t, value []byte, allow_breaks bool) bool { + if len(value) > 0 && !emitter.whitespace { + if !put(emitter, ' ') { + return false + } + } + + spaces := false + breaks := false + for i := 0; i < len(value); { + if is_space(value, i) { + if allow_breaks && !spaces && emitter.column > emitter.best_width && !is_space(value, i+1) { + if !yaml_emitter_write_indent(emitter) { + return false + } + i += width(value[i]) + } else { + if !write(emitter, value, &i) { + return false + } + } + spaces = true + } else if is_break(value, i) { + if !breaks && value[i] == '\n' { + if !put_break(emitter) { + return false + } + } + if !write_break(emitter, value, &i) { + return false + } + //emitter.indention = true + breaks = true + } else { + if breaks { + if !yaml_emitter_write_indent(emitter) { + return false + } + } + if !write(emitter, value, &i) { + return false + } + emitter.indention = false + spaces = false + breaks = false + } + } + + if len(value) > 0 { + emitter.whitespace = false + } + emitter.indention = false + if emitter.root_context { + emitter.open_ended = true + } + + return true +} + +func yaml_emitter_write_single_quoted_scalar(emitter *yaml_emitter_t, value []byte, allow_breaks bool) bool { + + if !yaml_emitter_write_indicator(emitter, []byte{'\''}, true, false, false) { + return false + } + + spaces := false + breaks := false + for i := 0; i < len(value); { + if is_space(value, i) { + if allow_breaks && !spaces && emitter.column > emitter.best_width && i > 0 && i < len(value)-1 && !is_space(value, i+1) { + if !yaml_emitter_write_indent(emitter) { + return false + } + i += width(value[i]) + } else { + if !write(emitter, value, &i) { + return false + } + } + spaces = true + } else if is_break(value, i) { + if !breaks && value[i] == '\n' { + if !put_break(emitter) { + return false + } + } + if !write_break(emitter, value, &i) { + return false + } + //emitter.indention = true + breaks = true + } else { + if breaks { + if !yaml_emitter_write_indent(emitter) { + return false + } + } + if value[i] == '\'' { + if !put(emitter, '\'') { + return false + } + } + if !write(emitter, value, &i) { + return false + } + emitter.indention = false + spaces = false + breaks = false + } + } + if !yaml_emitter_write_indicator(emitter, []byte{'\''}, false, false, false) { + return false + } + emitter.whitespace = false + emitter.indention = false + return true +} + +func yaml_emitter_write_double_quoted_scalar(emitter *yaml_emitter_t, value []byte, allow_breaks bool) bool { + spaces := false + if !yaml_emitter_write_indicator(emitter, []byte{'"'}, true, false, false) { + return false + } + + for i := 0; i < len(value); { + if !is_printable(value, i) || (!emitter.unicode && !is_ascii(value, i)) || + is_bom(value, i) || is_break(value, i) || + value[i] == '"' || value[i] == '\\' { + + octet := value[i] + + var w int + var v rune + switch { + case octet&0x80 == 0x00: + w, v = 1, rune(octet&0x7F) + case octet&0xE0 == 0xC0: + w, v = 2, rune(octet&0x1F) + case octet&0xF0 == 0xE0: + w, v = 3, rune(octet&0x0F) + case octet&0xF8 == 0xF0: + w, v = 4, rune(octet&0x07) + } + for k := 1; k < w; k++ { + octet = value[i+k] + v = (v << 6) + (rune(octet) & 0x3F) + } + i += w + + if !put(emitter, '\\') { + return false + } + + var ok bool + switch v { + case 0x00: + ok = put(emitter, '0') + case 0x07: + ok = put(emitter, 'a') + case 0x08: + ok = put(emitter, 'b') + case 0x09: + ok = put(emitter, 't') + case 0x0A: + ok = put(emitter, 'n') + case 0x0b: + ok = put(emitter, 'v') + case 0x0c: + ok = put(emitter, 'f') + case 0x0d: + ok = put(emitter, 'r') + case 0x1b: + ok = put(emitter, 'e') + case 0x22: + ok = put(emitter, '"') + case 0x5c: + ok = put(emitter, '\\') + case 0x85: + ok = put(emitter, 'N') + case 0xA0: + ok = put(emitter, '_') + case 0x2028: + ok = put(emitter, 'L') + case 0x2029: + ok = put(emitter, 'P') + default: + if v <= 0xFF { + ok = put(emitter, 'x') + w = 2 + } else if v <= 0xFFFF { + ok = put(emitter, 'u') + w = 4 + } else { + ok = put(emitter, 'U') + w = 8 + } + for k := (w - 1) * 4; ok && k >= 0; k -= 4 { + digit := byte((v >> uint(k)) & 0x0F) + if digit < 10 { + ok = put(emitter, digit+'0') + } else { + ok = put(emitter, digit+'A'-10) + } + } + } + if !ok { + return false + } + spaces = false + } else if is_space(value, i) { + if allow_breaks && !spaces && emitter.column > emitter.best_width && i > 0 && i < len(value)-1 { + if !yaml_emitter_write_indent(emitter) { + return false + } + if is_space(value, i+1) { + if !put(emitter, '\\') { + return false + } + } + i += width(value[i]) + } else if !write(emitter, value, &i) { + return false + } + spaces = true + } else { + if !write(emitter, value, &i) { + return false + } + spaces = false + } + } + if !yaml_emitter_write_indicator(emitter, []byte{'"'}, false, false, false) { + return false + } + emitter.whitespace = false + emitter.indention = false + return true +} + +func yaml_emitter_write_block_scalar_hints(emitter *yaml_emitter_t, value []byte) bool { + if is_space(value, 0) || is_break(value, 0) { + indent_hint := []byte{'0' + byte(emitter.best_indent)} + if !yaml_emitter_write_indicator(emitter, indent_hint, false, false, false) { + return false + } + } + + emitter.open_ended = false + + var chomp_hint [1]byte + if len(value) == 0 { + chomp_hint[0] = '-' + } else { + i := len(value) - 1 + for value[i]&0xC0 == 0x80 { + i-- + } + if !is_break(value, i) { + chomp_hint[0] = '-' + } else if i == 0 { + chomp_hint[0] = '+' + emitter.open_ended = true + } else { + i-- + for value[i]&0xC0 == 0x80 { + i-- + } + if is_break(value, i) { + chomp_hint[0] = '+' + emitter.open_ended = true + } + } + } + if chomp_hint[0] != 0 { + if !yaml_emitter_write_indicator(emitter, chomp_hint[:], false, false, false) { + return false + } + } + return true +} + +func yaml_emitter_write_literal_scalar(emitter *yaml_emitter_t, value []byte) bool { + if !yaml_emitter_write_indicator(emitter, []byte{'|'}, true, false, false) { + return false + } + if !yaml_emitter_write_block_scalar_hints(emitter, value) { + return false + } + if !yaml_emitter_process_line_comment_linebreak(emitter, true) { + return false + } + //emitter.indention = true + emitter.whitespace = true + breaks := true + for i := 0; i < len(value); { + if is_break(value, i) { + if !write_break(emitter, value, &i) { + return false + } + //emitter.indention = true + breaks = true + } else { + if breaks { + if !yaml_emitter_write_indent(emitter) { + return false + } + } + if !write(emitter, value, &i) { + return false + } + emitter.indention = false + breaks = false + } + } + + return true +} + +func yaml_emitter_write_folded_scalar(emitter *yaml_emitter_t, value []byte) bool { + if !yaml_emitter_write_indicator(emitter, []byte{'>'}, true, false, false) { + return false + } + if !yaml_emitter_write_block_scalar_hints(emitter, value) { + return false + } + if !yaml_emitter_process_line_comment_linebreak(emitter, true) { + return false + } + + //emitter.indention = true + emitter.whitespace = true + + breaks := true + leading_spaces := true + for i := 0; i < len(value); { + if is_break(value, i) { + if !breaks && !leading_spaces && value[i] == '\n' { + k := 0 + for is_break(value, k) { + k += width(value[k]) + } + if !is_blankz(value, k) { + if !put_break(emitter) { + return false + } + } + } + if !write_break(emitter, value, &i) { + return false + } + //emitter.indention = true + breaks = true + } else { + if breaks { + if !yaml_emitter_write_indent(emitter) { + return false + } + leading_spaces = is_blank(value, i) + } + if !breaks && is_space(value, i) && !is_space(value, i+1) && emitter.column > emitter.best_width { + if !yaml_emitter_write_indent(emitter) { + return false + } + i += width(value[i]) + } else { + if !write(emitter, value, &i) { + return false + } + } + emitter.indention = false + breaks = false + } + } + return true +} + +func yaml_emitter_write_comment(emitter *yaml_emitter_t, comment []byte) bool { + breaks := false + pound := false + for i := 0; i < len(comment); { + if is_break(comment, i) { + if !write_break(emitter, comment, &i) { + return false + } + //emitter.indention = true + breaks = true + pound = false + } else { + if breaks && !yaml_emitter_write_indent(emitter) { + return false + } + if !pound { + if comment[i] != '#' && (!put(emitter, '#') || !put(emitter, ' ')) { + return false + } + pound = true + } + if !write(emitter, comment, &i) { + return false + } + emitter.indention = false + breaks = false + } + } + if !breaks && !put_break(emitter) { + return false + } + + emitter.whitespace = true + //emitter.indention = true + return true +} diff --git a/vendor/go.yaml.in/yaml/v3/encode.go b/vendor/go.yaml.in/yaml/v3/encode.go new file mode 100644 index 000000000..de9e72a3e --- /dev/null +++ b/vendor/go.yaml.in/yaml/v3/encode.go @@ -0,0 +1,577 @@ +// +// Copyright (c) 2011-2019 Canonical Ltd +// +// 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. + +package yaml + +import ( + "encoding" + "fmt" + "io" + "reflect" + "regexp" + "sort" + "strconv" + "strings" + "time" + "unicode/utf8" +) + +type encoder struct { + emitter yaml_emitter_t + event yaml_event_t + out []byte + flow bool + indent int + doneInit bool +} + +func newEncoder() *encoder { + e := &encoder{} + yaml_emitter_initialize(&e.emitter) + yaml_emitter_set_output_string(&e.emitter, &e.out) + yaml_emitter_set_unicode(&e.emitter, true) + return e +} + +func newEncoderWithWriter(w io.Writer) *encoder { + e := &encoder{} + yaml_emitter_initialize(&e.emitter) + yaml_emitter_set_output_writer(&e.emitter, w) + yaml_emitter_set_unicode(&e.emitter, true) + return e +} + +func (e *encoder) init() { + if e.doneInit { + return + } + if e.indent == 0 { + e.indent = 4 + } + e.emitter.best_indent = e.indent + yaml_stream_start_event_initialize(&e.event, yaml_UTF8_ENCODING) + e.emit() + e.doneInit = true +} + +func (e *encoder) finish() { + e.emitter.open_ended = false + yaml_stream_end_event_initialize(&e.event) + e.emit() +} + +func (e *encoder) destroy() { + yaml_emitter_delete(&e.emitter) +} + +func (e *encoder) emit() { + // This will internally delete the e.event value. + e.must(yaml_emitter_emit(&e.emitter, &e.event)) +} + +func (e *encoder) must(ok bool) { + if !ok { + msg := e.emitter.problem + if msg == "" { + msg = "unknown problem generating YAML content" + } + failf("%s", msg) + } +} + +func (e *encoder) marshalDoc(tag string, in reflect.Value) { + e.init() + var node *Node + if in.IsValid() { + node, _ = in.Interface().(*Node) + } + if node != nil && node.Kind == DocumentNode { + e.nodev(in) + } else { + yaml_document_start_event_initialize(&e.event, nil, nil, true) + e.emit() + e.marshal(tag, in) + yaml_document_end_event_initialize(&e.event, true) + e.emit() + } +} + +func (e *encoder) marshal(tag string, in reflect.Value) { + tag = shortTag(tag) + if !in.IsValid() || in.Kind() == reflect.Ptr && in.IsNil() { + e.nilv() + return + } + iface := in.Interface() + switch value := iface.(type) { + case *Node: + e.nodev(in) + return + case Node: + if !in.CanAddr() { + var n = reflect.New(in.Type()).Elem() + n.Set(in) + in = n + } + e.nodev(in.Addr()) + return + case time.Time: + e.timev(tag, in) + return + case *time.Time: + e.timev(tag, in.Elem()) + return + case time.Duration: + e.stringv(tag, reflect.ValueOf(value.String())) + return + case Marshaler: + v, err := value.MarshalYAML() + if err != nil { + fail(err) + } + if v == nil { + e.nilv() + return + } + e.marshal(tag, reflect.ValueOf(v)) + return + case encoding.TextMarshaler: + text, err := value.MarshalText() + if err != nil { + fail(err) + } + in = reflect.ValueOf(string(text)) + case nil: + e.nilv() + return + } + switch in.Kind() { + case reflect.Interface: + e.marshal(tag, in.Elem()) + case reflect.Map: + e.mapv(tag, in) + case reflect.Ptr: + e.marshal(tag, in.Elem()) + case reflect.Struct: + e.structv(tag, in) + case reflect.Slice, reflect.Array: + e.slicev(tag, in) + case reflect.String: + e.stringv(tag, in) + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + e.intv(tag, in) + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: + e.uintv(tag, in) + case reflect.Float32, reflect.Float64: + e.floatv(tag, in) + case reflect.Bool: + e.boolv(tag, in) + default: + panic("cannot marshal type: " + in.Type().String()) + } +} + +func (e *encoder) mapv(tag string, in reflect.Value) { + e.mappingv(tag, func() { + keys := keyList(in.MapKeys()) + sort.Sort(keys) + for _, k := range keys { + e.marshal("", k) + e.marshal("", in.MapIndex(k)) + } + }) +} + +func (e *encoder) fieldByIndex(v reflect.Value, index []int) (field reflect.Value) { + for _, num := range index { + for { + if v.Kind() == reflect.Ptr { + if v.IsNil() { + return reflect.Value{} + } + v = v.Elem() + continue + } + break + } + v = v.Field(num) + } + return v +} + +func (e *encoder) structv(tag string, in reflect.Value) { + sinfo, err := getStructInfo(in.Type()) + if err != nil { + panic(err) + } + e.mappingv(tag, func() { + for _, info := range sinfo.FieldsList { + var value reflect.Value + if info.Inline == nil { + value = in.Field(info.Num) + } else { + value = e.fieldByIndex(in, info.Inline) + if !value.IsValid() { + continue + } + } + if info.OmitEmpty && isZero(value) { + continue + } + e.marshal("", reflect.ValueOf(info.Key)) + e.flow = info.Flow + e.marshal("", value) + } + if sinfo.InlineMap >= 0 { + m := in.Field(sinfo.InlineMap) + if m.Len() > 0 { + e.flow = false + keys := keyList(m.MapKeys()) + sort.Sort(keys) + for _, k := range keys { + if _, found := sinfo.FieldsMap[k.String()]; found { + panic(fmt.Sprintf("cannot have key %q in inlined map: conflicts with struct field", k.String())) + } + e.marshal("", k) + e.flow = false + e.marshal("", m.MapIndex(k)) + } + } + } + }) +} + +func (e *encoder) mappingv(tag string, f func()) { + implicit := tag == "" + style := yaml_BLOCK_MAPPING_STYLE + if e.flow { + e.flow = false + style = yaml_FLOW_MAPPING_STYLE + } + yaml_mapping_start_event_initialize(&e.event, nil, []byte(tag), implicit, style) + e.emit() + f() + yaml_mapping_end_event_initialize(&e.event) + e.emit() +} + +func (e *encoder) slicev(tag string, in reflect.Value) { + implicit := tag == "" + style := yaml_BLOCK_SEQUENCE_STYLE + if e.flow { + e.flow = false + style = yaml_FLOW_SEQUENCE_STYLE + } + e.must(yaml_sequence_start_event_initialize(&e.event, nil, []byte(tag), implicit, style)) + e.emit() + n := in.Len() + for i := 0; i < n; i++ { + e.marshal("", in.Index(i)) + } + e.must(yaml_sequence_end_event_initialize(&e.event)) + e.emit() +} + +// isBase60 returns whether s is in base 60 notation as defined in YAML 1.1. +// +// The base 60 float notation in YAML 1.1 is a terrible idea and is unsupported +// in YAML 1.2 and by this package, but these should be marshalled quoted for +// the time being for compatibility with other parsers. +func isBase60Float(s string) (result bool) { + // Fast path. + if s == "" { + return false + } + c := s[0] + if !(c == '+' || c == '-' || c >= '0' && c <= '9') || strings.IndexByte(s, ':') < 0 { + return false + } + // Do the full match. + return base60float.MatchString(s) +} + +// From http://yaml.org/type/float.html, except the regular expression there +// is bogus. In practice parsers do not enforce the "\.[0-9_]*" suffix. +var base60float = regexp.MustCompile(`^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+(?:\.[0-9_]*)?$`) + +// isOldBool returns whether s is bool notation as defined in YAML 1.1. +// +// We continue to force strings that YAML 1.1 would interpret as booleans to be +// rendered as quotes strings so that the marshalled output valid for YAML 1.1 +// parsing. +func isOldBool(s string) (result bool) { + switch s { + case "y", "Y", "yes", "Yes", "YES", "on", "On", "ON", + "n", "N", "no", "No", "NO", "off", "Off", "OFF": + return true + default: + return false + } +} + +func (e *encoder) stringv(tag string, in reflect.Value) { + var style yaml_scalar_style_t + s := in.String() + canUsePlain := true + switch { + case !utf8.ValidString(s): + if tag == binaryTag { + failf("explicitly tagged !!binary data must be base64-encoded") + } + if tag != "" { + failf("cannot marshal invalid UTF-8 data as %s", shortTag(tag)) + } + // It can't be encoded directly as YAML so use a binary tag + // and encode it as base64. + tag = binaryTag + s = encodeBase64(s) + case tag == "": + // Check to see if it would resolve to a specific + // tag when encoded unquoted. If it doesn't, + // there's no need to quote it. + rtag, _ := resolve("", s) + canUsePlain = rtag == strTag && !(isBase60Float(s) || isOldBool(s)) + } + // Note: it's possible for user code to emit invalid YAML + // if they explicitly specify a tag and a string containing + // text that's incompatible with that tag. + switch { + case strings.Contains(s, "\n"): + if e.flow { + style = yaml_DOUBLE_QUOTED_SCALAR_STYLE + } else { + style = yaml_LITERAL_SCALAR_STYLE + } + case canUsePlain: + style = yaml_PLAIN_SCALAR_STYLE + default: + style = yaml_DOUBLE_QUOTED_SCALAR_STYLE + } + e.emitScalar(s, "", tag, style, nil, nil, nil, nil) +} + +func (e *encoder) boolv(tag string, in reflect.Value) { + var s string + if in.Bool() { + s = "true" + } else { + s = "false" + } + e.emitScalar(s, "", tag, yaml_PLAIN_SCALAR_STYLE, nil, nil, nil, nil) +} + +func (e *encoder) intv(tag string, in reflect.Value) { + s := strconv.FormatInt(in.Int(), 10) + e.emitScalar(s, "", tag, yaml_PLAIN_SCALAR_STYLE, nil, nil, nil, nil) +} + +func (e *encoder) uintv(tag string, in reflect.Value) { + s := strconv.FormatUint(in.Uint(), 10) + e.emitScalar(s, "", tag, yaml_PLAIN_SCALAR_STYLE, nil, nil, nil, nil) +} + +func (e *encoder) timev(tag string, in reflect.Value) { + t := in.Interface().(time.Time) + s := t.Format(time.RFC3339Nano) + e.emitScalar(s, "", tag, yaml_PLAIN_SCALAR_STYLE, nil, nil, nil, nil) +} + +func (e *encoder) floatv(tag string, in reflect.Value) { + // Issue #352: When formatting, use the precision of the underlying value + precision := 64 + if in.Kind() == reflect.Float32 { + precision = 32 + } + + s := strconv.FormatFloat(in.Float(), 'g', -1, precision) + switch s { + case "+Inf": + s = ".inf" + case "-Inf": + s = "-.inf" + case "NaN": + s = ".nan" + } + e.emitScalar(s, "", tag, yaml_PLAIN_SCALAR_STYLE, nil, nil, nil, nil) +} + +func (e *encoder) nilv() { + e.emitScalar("null", "", "", yaml_PLAIN_SCALAR_STYLE, nil, nil, nil, nil) +} + +func (e *encoder) emitScalar(value, anchor, tag string, style yaml_scalar_style_t, head, line, foot, tail []byte) { + // TODO Kill this function. Replace all initialize calls by their underlining Go literals. + implicit := tag == "" + if !implicit { + tag = longTag(tag) + } + e.must(yaml_scalar_event_initialize(&e.event, []byte(anchor), []byte(tag), []byte(value), implicit, implicit, style)) + e.event.head_comment = head + e.event.line_comment = line + e.event.foot_comment = foot + e.event.tail_comment = tail + e.emit() +} + +func (e *encoder) nodev(in reflect.Value) { + e.node(in.Interface().(*Node), "") +} + +func (e *encoder) node(node *Node, tail string) { + // Zero nodes behave as nil. + if node.Kind == 0 && node.IsZero() { + e.nilv() + return + } + + // If the tag was not explicitly requested, and dropping it won't change the + // implicit tag of the value, don't include it in the presentation. + var tag = node.Tag + var stag = shortTag(tag) + var forceQuoting bool + if tag != "" && node.Style&TaggedStyle == 0 { + if node.Kind == ScalarNode { + if stag == strTag && node.Style&(SingleQuotedStyle|DoubleQuotedStyle|LiteralStyle|FoldedStyle) != 0 { + tag = "" + } else { + rtag, _ := resolve("", node.Value) + if rtag == stag { + tag = "" + } else if stag == strTag { + tag = "" + forceQuoting = true + } + } + } else { + var rtag string + switch node.Kind { + case MappingNode: + rtag = mapTag + case SequenceNode: + rtag = seqTag + } + if rtag == stag { + tag = "" + } + } + } + + switch node.Kind { + case DocumentNode: + yaml_document_start_event_initialize(&e.event, nil, nil, true) + e.event.head_comment = []byte(node.HeadComment) + e.emit() + for _, node := range node.Content { + e.node(node, "") + } + yaml_document_end_event_initialize(&e.event, true) + e.event.foot_comment = []byte(node.FootComment) + e.emit() + + case SequenceNode: + style := yaml_BLOCK_SEQUENCE_STYLE + if node.Style&FlowStyle != 0 { + style = yaml_FLOW_SEQUENCE_STYLE + } + e.must(yaml_sequence_start_event_initialize(&e.event, []byte(node.Anchor), []byte(longTag(tag)), tag == "", style)) + e.event.head_comment = []byte(node.HeadComment) + e.emit() + for _, node := range node.Content { + e.node(node, "") + } + e.must(yaml_sequence_end_event_initialize(&e.event)) + e.event.line_comment = []byte(node.LineComment) + e.event.foot_comment = []byte(node.FootComment) + e.emit() + + case MappingNode: + style := yaml_BLOCK_MAPPING_STYLE + if node.Style&FlowStyle != 0 { + style = yaml_FLOW_MAPPING_STYLE + } + yaml_mapping_start_event_initialize(&e.event, []byte(node.Anchor), []byte(longTag(tag)), tag == "", style) + e.event.tail_comment = []byte(tail) + e.event.head_comment = []byte(node.HeadComment) + e.emit() + + // The tail logic below moves the foot comment of prior keys to the following key, + // since the value for each key may be a nested structure and the foot needs to be + // processed only the entirety of the value is streamed. The last tail is processed + // with the mapping end event. + var tail string + for i := 0; i+1 < len(node.Content); i += 2 { + k := node.Content[i] + foot := k.FootComment + if foot != "" { + kopy := *k + kopy.FootComment = "" + k = &kopy + } + e.node(k, tail) + tail = foot + + v := node.Content[i+1] + e.node(v, "") + } + + yaml_mapping_end_event_initialize(&e.event) + e.event.tail_comment = []byte(tail) + e.event.line_comment = []byte(node.LineComment) + e.event.foot_comment = []byte(node.FootComment) + e.emit() + + case AliasNode: + yaml_alias_event_initialize(&e.event, []byte(node.Value)) + e.event.head_comment = []byte(node.HeadComment) + e.event.line_comment = []byte(node.LineComment) + e.event.foot_comment = []byte(node.FootComment) + e.emit() + + case ScalarNode: + value := node.Value + if !utf8.ValidString(value) { + if stag == binaryTag { + failf("explicitly tagged !!binary data must be base64-encoded") + } + if stag != "" { + failf("cannot marshal invalid UTF-8 data as %s", stag) + } + // It can't be encoded directly as YAML so use a binary tag + // and encode it as base64. + tag = binaryTag + value = encodeBase64(value) + } + + style := yaml_PLAIN_SCALAR_STYLE + switch { + case node.Style&DoubleQuotedStyle != 0: + style = yaml_DOUBLE_QUOTED_SCALAR_STYLE + case node.Style&SingleQuotedStyle != 0: + style = yaml_SINGLE_QUOTED_SCALAR_STYLE + case node.Style&LiteralStyle != 0: + style = yaml_LITERAL_SCALAR_STYLE + case node.Style&FoldedStyle != 0: + style = yaml_FOLDED_SCALAR_STYLE + case strings.Contains(value, "\n"): + style = yaml_LITERAL_SCALAR_STYLE + case forceQuoting: + style = yaml_DOUBLE_QUOTED_SCALAR_STYLE + } + + e.emitScalar(value, node.Anchor, tag, style, []byte(node.HeadComment), []byte(node.LineComment), []byte(node.FootComment), []byte(tail)) + default: + failf("cannot encode node with unknown kind %d", node.Kind) + } +} diff --git a/vendor/go.yaml.in/yaml/v3/parserc.go b/vendor/go.yaml.in/yaml/v3/parserc.go new file mode 100644 index 000000000..f35829db4 --- /dev/null +++ b/vendor/go.yaml.in/yaml/v3/parserc.go @@ -0,0 +1,1260 @@ +// +// Copyright (c) 2011-2019 Canonical Ltd +// Copyright (c) 2006-2010 Kirill Simonov +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of +// this software and associated documentation files (the "Software"), to deal in +// the Software without restriction, including without limitation the rights to +// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +// of the Software, and to permit persons to whom the Software is furnished to do +// so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +package yaml + +import ( + "bytes" +) + +// The parser implements the following grammar: +// +// stream ::= STREAM-START implicit_document? explicit_document* STREAM-END +// implicit_document ::= block_node DOCUMENT-END* +// explicit_document ::= DIRECTIVE* DOCUMENT-START block_node? DOCUMENT-END* +// block_node_or_indentless_sequence ::= +// ALIAS +// | properties (block_content | indentless_block_sequence)? +// | block_content +// | indentless_block_sequence +// block_node ::= ALIAS +// | properties block_content? +// | block_content +// flow_node ::= ALIAS +// | properties flow_content? +// | flow_content +// properties ::= TAG ANCHOR? | ANCHOR TAG? +// block_content ::= block_collection | flow_collection | SCALAR +// flow_content ::= flow_collection | SCALAR +// block_collection ::= block_sequence | block_mapping +// flow_collection ::= flow_sequence | flow_mapping +// block_sequence ::= BLOCK-SEQUENCE-START (BLOCK-ENTRY block_node?)* BLOCK-END +// indentless_sequence ::= (BLOCK-ENTRY block_node?)+ +// block_mapping ::= BLOCK-MAPPING_START +// ((KEY block_node_or_indentless_sequence?)? +// (VALUE block_node_or_indentless_sequence?)?)* +// BLOCK-END +// flow_sequence ::= FLOW-SEQUENCE-START +// (flow_sequence_entry FLOW-ENTRY)* +// flow_sequence_entry? +// FLOW-SEQUENCE-END +// flow_sequence_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)? +// flow_mapping ::= FLOW-MAPPING-START +// (flow_mapping_entry FLOW-ENTRY)* +// flow_mapping_entry? +// FLOW-MAPPING-END +// flow_mapping_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)? + +// Peek the next token in the token queue. +func peek_token(parser *yaml_parser_t) *yaml_token_t { + if parser.token_available || yaml_parser_fetch_more_tokens(parser) { + token := &parser.tokens[parser.tokens_head] + yaml_parser_unfold_comments(parser, token) + return token + } + return nil +} + +// yaml_parser_unfold_comments walks through the comments queue and joins all +// comments behind the position of the provided token into the respective +// top-level comment slices in the parser. +func yaml_parser_unfold_comments(parser *yaml_parser_t, token *yaml_token_t) { + for parser.comments_head < len(parser.comments) && token.start_mark.index >= parser.comments[parser.comments_head].token_mark.index { + comment := &parser.comments[parser.comments_head] + if len(comment.head) > 0 { + if token.typ == yaml_BLOCK_END_TOKEN { + // No heads on ends, so keep comment.head for a follow up token. + break + } + if len(parser.head_comment) > 0 { + parser.head_comment = append(parser.head_comment, '\n') + } + parser.head_comment = append(parser.head_comment, comment.head...) + } + if len(comment.foot) > 0 { + if len(parser.foot_comment) > 0 { + parser.foot_comment = append(parser.foot_comment, '\n') + } + parser.foot_comment = append(parser.foot_comment, comment.foot...) + } + if len(comment.line) > 0 { + if len(parser.line_comment) > 0 { + parser.line_comment = append(parser.line_comment, '\n') + } + parser.line_comment = append(parser.line_comment, comment.line...) + } + *comment = yaml_comment_t{} + parser.comments_head++ + } +} + +// Remove the next token from the queue (must be called after peek_token). +func skip_token(parser *yaml_parser_t) { + parser.token_available = false + parser.tokens_parsed++ + parser.stream_end_produced = parser.tokens[parser.tokens_head].typ == yaml_STREAM_END_TOKEN + parser.tokens_head++ +} + +// Get the next event. +func yaml_parser_parse(parser *yaml_parser_t, event *yaml_event_t) bool { + // Erase the event object. + *event = yaml_event_t{} + + // No events after the end of the stream or error. + if parser.stream_end_produced || parser.error != yaml_NO_ERROR || parser.state == yaml_PARSE_END_STATE { + return true + } + + // Generate the next event. + return yaml_parser_state_machine(parser, event) +} + +// Set parser error. +func yaml_parser_set_parser_error(parser *yaml_parser_t, problem string, problem_mark yaml_mark_t) bool { + parser.error = yaml_PARSER_ERROR + parser.problem = problem + parser.problem_mark = problem_mark + return false +} + +func yaml_parser_set_parser_error_context(parser *yaml_parser_t, context string, context_mark yaml_mark_t, problem string, problem_mark yaml_mark_t) bool { + parser.error = yaml_PARSER_ERROR + parser.context = context + parser.context_mark = context_mark + parser.problem = problem + parser.problem_mark = problem_mark + return false +} + +// State dispatcher. +func yaml_parser_state_machine(parser *yaml_parser_t, event *yaml_event_t) bool { + //trace("yaml_parser_state_machine", "state:", parser.state.String()) + + switch parser.state { + case yaml_PARSE_STREAM_START_STATE: + return yaml_parser_parse_stream_start(parser, event) + + case yaml_PARSE_IMPLICIT_DOCUMENT_START_STATE: + return yaml_parser_parse_document_start(parser, event, true) + + case yaml_PARSE_DOCUMENT_START_STATE: + return yaml_parser_parse_document_start(parser, event, false) + + case yaml_PARSE_DOCUMENT_CONTENT_STATE: + return yaml_parser_parse_document_content(parser, event) + + case yaml_PARSE_DOCUMENT_END_STATE: + return yaml_parser_parse_document_end(parser, event) + + case yaml_PARSE_BLOCK_NODE_STATE: + return yaml_parser_parse_node(parser, event, true, false) + + case yaml_PARSE_BLOCK_NODE_OR_INDENTLESS_SEQUENCE_STATE: + return yaml_parser_parse_node(parser, event, true, true) + + case yaml_PARSE_FLOW_NODE_STATE: + return yaml_parser_parse_node(parser, event, false, false) + + case yaml_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE: + return yaml_parser_parse_block_sequence_entry(parser, event, true) + + case yaml_PARSE_BLOCK_SEQUENCE_ENTRY_STATE: + return yaml_parser_parse_block_sequence_entry(parser, event, false) + + case yaml_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE: + return yaml_parser_parse_indentless_sequence_entry(parser, event) + + case yaml_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE: + return yaml_parser_parse_block_mapping_key(parser, event, true) + + case yaml_PARSE_BLOCK_MAPPING_KEY_STATE: + return yaml_parser_parse_block_mapping_key(parser, event, false) + + case yaml_PARSE_BLOCK_MAPPING_VALUE_STATE: + return yaml_parser_parse_block_mapping_value(parser, event) + + case yaml_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE: + return yaml_parser_parse_flow_sequence_entry(parser, event, true) + + case yaml_PARSE_FLOW_SEQUENCE_ENTRY_STATE: + return yaml_parser_parse_flow_sequence_entry(parser, event, false) + + case yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE: + return yaml_parser_parse_flow_sequence_entry_mapping_key(parser, event) + + case yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE: + return yaml_parser_parse_flow_sequence_entry_mapping_value(parser, event) + + case yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE: + return yaml_parser_parse_flow_sequence_entry_mapping_end(parser, event) + + case yaml_PARSE_FLOW_MAPPING_FIRST_KEY_STATE: + return yaml_parser_parse_flow_mapping_key(parser, event, true) + + case yaml_PARSE_FLOW_MAPPING_KEY_STATE: + return yaml_parser_parse_flow_mapping_key(parser, event, false) + + case yaml_PARSE_FLOW_MAPPING_VALUE_STATE: + return yaml_parser_parse_flow_mapping_value(parser, event, false) + + case yaml_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE: + return yaml_parser_parse_flow_mapping_value(parser, event, true) + + default: + panic("invalid parser state") + } +} + +// Parse the production: +// +// stream ::= STREAM-START implicit_document? explicit_document* STREAM-END +// ************ +func yaml_parser_parse_stream_start(parser *yaml_parser_t, event *yaml_event_t) bool { + token := peek_token(parser) + if token == nil { + return false + } + if token.typ != yaml_STREAM_START_TOKEN { + return yaml_parser_set_parser_error(parser, "did not find expected ", token.start_mark) + } + parser.state = yaml_PARSE_IMPLICIT_DOCUMENT_START_STATE + *event = yaml_event_t{ + typ: yaml_STREAM_START_EVENT, + start_mark: token.start_mark, + end_mark: token.end_mark, + encoding: token.encoding, + } + skip_token(parser) + return true +} + +// Parse the productions: +// +// implicit_document ::= block_node DOCUMENT-END* +// * +// explicit_document ::= DIRECTIVE* DOCUMENT-START block_node? DOCUMENT-END* +// ************************* +func yaml_parser_parse_document_start(parser *yaml_parser_t, event *yaml_event_t, implicit bool) bool { + + token := peek_token(parser) + if token == nil { + return false + } + + // Parse extra document end indicators. + if !implicit { + for token.typ == yaml_DOCUMENT_END_TOKEN { + skip_token(parser) + token = peek_token(parser) + if token == nil { + return false + } + } + } + + if implicit && token.typ != yaml_VERSION_DIRECTIVE_TOKEN && + token.typ != yaml_TAG_DIRECTIVE_TOKEN && + token.typ != yaml_DOCUMENT_START_TOKEN && + token.typ != yaml_STREAM_END_TOKEN { + // Parse an implicit document. + if !yaml_parser_process_directives(parser, nil, nil) { + return false + } + parser.states = append(parser.states, yaml_PARSE_DOCUMENT_END_STATE) + parser.state = yaml_PARSE_BLOCK_NODE_STATE + + var head_comment []byte + if len(parser.head_comment) > 0 { + // [Go] Scan the header comment backwards, and if an empty line is found, break + // the header so the part before the last empty line goes into the + // document header, while the bottom of it goes into a follow up event. + for i := len(parser.head_comment) - 1; i > 0; i-- { + if parser.head_comment[i] == '\n' { + if i == len(parser.head_comment)-1 { + head_comment = parser.head_comment[:i] + parser.head_comment = parser.head_comment[i+1:] + break + } else if parser.head_comment[i-1] == '\n' { + head_comment = parser.head_comment[:i-1] + parser.head_comment = parser.head_comment[i+1:] + break + } + } + } + } + + *event = yaml_event_t{ + typ: yaml_DOCUMENT_START_EVENT, + start_mark: token.start_mark, + end_mark: token.end_mark, + + head_comment: head_comment, + } + + } else if token.typ != yaml_STREAM_END_TOKEN { + // Parse an explicit document. + var version_directive *yaml_version_directive_t + var tag_directives []yaml_tag_directive_t + start_mark := token.start_mark + if !yaml_parser_process_directives(parser, &version_directive, &tag_directives) { + return false + } + token = peek_token(parser) + if token == nil { + return false + } + if token.typ != yaml_DOCUMENT_START_TOKEN { + yaml_parser_set_parser_error(parser, + "did not find expected ", token.start_mark) + return false + } + parser.states = append(parser.states, yaml_PARSE_DOCUMENT_END_STATE) + parser.state = yaml_PARSE_DOCUMENT_CONTENT_STATE + end_mark := token.end_mark + + *event = yaml_event_t{ + typ: yaml_DOCUMENT_START_EVENT, + start_mark: start_mark, + end_mark: end_mark, + version_directive: version_directive, + tag_directives: tag_directives, + implicit: false, + } + skip_token(parser) + + } else { + // Parse the stream end. + parser.state = yaml_PARSE_END_STATE + *event = yaml_event_t{ + typ: yaml_STREAM_END_EVENT, + start_mark: token.start_mark, + end_mark: token.end_mark, + } + skip_token(parser) + } + + return true +} + +// Parse the productions: +// +// explicit_document ::= DIRECTIVE* DOCUMENT-START block_node? DOCUMENT-END* +// *********** +func yaml_parser_parse_document_content(parser *yaml_parser_t, event *yaml_event_t) bool { + token := peek_token(parser) + if token == nil { + return false + } + + if token.typ == yaml_VERSION_DIRECTIVE_TOKEN || + token.typ == yaml_TAG_DIRECTIVE_TOKEN || + token.typ == yaml_DOCUMENT_START_TOKEN || + token.typ == yaml_DOCUMENT_END_TOKEN || + token.typ == yaml_STREAM_END_TOKEN { + parser.state = parser.states[len(parser.states)-1] + parser.states = parser.states[:len(parser.states)-1] + return yaml_parser_process_empty_scalar(parser, event, + token.start_mark) + } + return yaml_parser_parse_node(parser, event, true, false) +} + +// Parse the productions: +// +// implicit_document ::= block_node DOCUMENT-END* +// ************* +// explicit_document ::= DIRECTIVE* DOCUMENT-START block_node? DOCUMENT-END* +func yaml_parser_parse_document_end(parser *yaml_parser_t, event *yaml_event_t) bool { + token := peek_token(parser) + if token == nil { + return false + } + + start_mark := token.start_mark + end_mark := token.start_mark + + implicit := true + if token.typ == yaml_DOCUMENT_END_TOKEN { + end_mark = token.end_mark + skip_token(parser) + implicit = false + } + + parser.tag_directives = parser.tag_directives[:0] + + parser.state = yaml_PARSE_DOCUMENT_START_STATE + *event = yaml_event_t{ + typ: yaml_DOCUMENT_END_EVENT, + start_mark: start_mark, + end_mark: end_mark, + implicit: implicit, + } + yaml_parser_set_event_comments(parser, event) + if len(event.head_comment) > 0 && len(event.foot_comment) == 0 { + event.foot_comment = event.head_comment + event.head_comment = nil + } + return true +} + +func yaml_parser_set_event_comments(parser *yaml_parser_t, event *yaml_event_t) { + event.head_comment = parser.head_comment + event.line_comment = parser.line_comment + event.foot_comment = parser.foot_comment + parser.head_comment = nil + parser.line_comment = nil + parser.foot_comment = nil + parser.tail_comment = nil + parser.stem_comment = nil +} + +// Parse the productions: +// +// block_node_or_indentless_sequence ::= +// ALIAS +// ***** +// | properties (block_content | indentless_block_sequence)? +// ********** * +// | block_content | indentless_block_sequence +// * +// block_node ::= ALIAS +// ***** +// | properties block_content? +// ********** * +// | block_content +// * +// flow_node ::= ALIAS +// ***** +// | properties flow_content? +// ********** * +// | flow_content +// * +// properties ::= TAG ANCHOR? | ANCHOR TAG? +// ************************* +// block_content ::= block_collection | flow_collection | SCALAR +// ****** +// flow_content ::= flow_collection | SCALAR +// ****** +func yaml_parser_parse_node(parser *yaml_parser_t, event *yaml_event_t, block, indentless_sequence bool) bool { + //defer trace("yaml_parser_parse_node", "block:", block, "indentless_sequence:", indentless_sequence)() + + token := peek_token(parser) + if token == nil { + return false + } + + if token.typ == yaml_ALIAS_TOKEN { + parser.state = parser.states[len(parser.states)-1] + parser.states = parser.states[:len(parser.states)-1] + *event = yaml_event_t{ + typ: yaml_ALIAS_EVENT, + start_mark: token.start_mark, + end_mark: token.end_mark, + anchor: token.value, + } + yaml_parser_set_event_comments(parser, event) + skip_token(parser) + return true + } + + start_mark := token.start_mark + end_mark := token.start_mark + + var tag_token bool + var tag_handle, tag_suffix, anchor []byte + var tag_mark yaml_mark_t + if token.typ == yaml_ANCHOR_TOKEN { + anchor = token.value + start_mark = token.start_mark + end_mark = token.end_mark + skip_token(parser) + token = peek_token(parser) + if token == nil { + return false + } + if token.typ == yaml_TAG_TOKEN { + tag_token = true + tag_handle = token.value + tag_suffix = token.suffix + tag_mark = token.start_mark + end_mark = token.end_mark + skip_token(parser) + token = peek_token(parser) + if token == nil { + return false + } + } + } else if token.typ == yaml_TAG_TOKEN { + tag_token = true + tag_handle = token.value + tag_suffix = token.suffix + start_mark = token.start_mark + tag_mark = token.start_mark + end_mark = token.end_mark + skip_token(parser) + token = peek_token(parser) + if token == nil { + return false + } + if token.typ == yaml_ANCHOR_TOKEN { + anchor = token.value + end_mark = token.end_mark + skip_token(parser) + token = peek_token(parser) + if token == nil { + return false + } + } + } + + var tag []byte + if tag_token { + if len(tag_handle) == 0 { + tag = tag_suffix + tag_suffix = nil + } else { + for i := range parser.tag_directives { + if bytes.Equal(parser.tag_directives[i].handle, tag_handle) { + tag = append([]byte(nil), parser.tag_directives[i].prefix...) + tag = append(tag, tag_suffix...) + break + } + } + if len(tag) == 0 { + yaml_parser_set_parser_error_context(parser, + "while parsing a node", start_mark, + "found undefined tag handle", tag_mark) + return false + } + } + } + + implicit := len(tag) == 0 + if indentless_sequence && token.typ == yaml_BLOCK_ENTRY_TOKEN { + end_mark = token.end_mark + parser.state = yaml_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE + *event = yaml_event_t{ + typ: yaml_SEQUENCE_START_EVENT, + start_mark: start_mark, + end_mark: end_mark, + anchor: anchor, + tag: tag, + implicit: implicit, + style: yaml_style_t(yaml_BLOCK_SEQUENCE_STYLE), + } + return true + } + if token.typ == yaml_SCALAR_TOKEN { + var plain_implicit, quoted_implicit bool + end_mark = token.end_mark + if (len(tag) == 0 && token.style == yaml_PLAIN_SCALAR_STYLE) || (len(tag) == 1 && tag[0] == '!') { + plain_implicit = true + } else if len(tag) == 0 { + quoted_implicit = true + } + parser.state = parser.states[len(parser.states)-1] + parser.states = parser.states[:len(parser.states)-1] + + *event = yaml_event_t{ + typ: yaml_SCALAR_EVENT, + start_mark: start_mark, + end_mark: end_mark, + anchor: anchor, + tag: tag, + value: token.value, + implicit: plain_implicit, + quoted_implicit: quoted_implicit, + style: yaml_style_t(token.style), + } + yaml_parser_set_event_comments(parser, event) + skip_token(parser) + return true + } + if token.typ == yaml_FLOW_SEQUENCE_START_TOKEN { + // [Go] Some of the events below can be merged as they differ only on style. + end_mark = token.end_mark + parser.state = yaml_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE + *event = yaml_event_t{ + typ: yaml_SEQUENCE_START_EVENT, + start_mark: start_mark, + end_mark: end_mark, + anchor: anchor, + tag: tag, + implicit: implicit, + style: yaml_style_t(yaml_FLOW_SEQUENCE_STYLE), + } + yaml_parser_set_event_comments(parser, event) + return true + } + if token.typ == yaml_FLOW_MAPPING_START_TOKEN { + end_mark = token.end_mark + parser.state = yaml_PARSE_FLOW_MAPPING_FIRST_KEY_STATE + *event = yaml_event_t{ + typ: yaml_MAPPING_START_EVENT, + start_mark: start_mark, + end_mark: end_mark, + anchor: anchor, + tag: tag, + implicit: implicit, + style: yaml_style_t(yaml_FLOW_MAPPING_STYLE), + } + yaml_parser_set_event_comments(parser, event) + return true + } + if block && token.typ == yaml_BLOCK_SEQUENCE_START_TOKEN { + end_mark = token.end_mark + parser.state = yaml_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE + *event = yaml_event_t{ + typ: yaml_SEQUENCE_START_EVENT, + start_mark: start_mark, + end_mark: end_mark, + anchor: anchor, + tag: tag, + implicit: implicit, + style: yaml_style_t(yaml_BLOCK_SEQUENCE_STYLE), + } + if parser.stem_comment != nil { + event.head_comment = parser.stem_comment + parser.stem_comment = nil + } + return true + } + if block && token.typ == yaml_BLOCK_MAPPING_START_TOKEN { + end_mark = token.end_mark + parser.state = yaml_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE + *event = yaml_event_t{ + typ: yaml_MAPPING_START_EVENT, + start_mark: start_mark, + end_mark: end_mark, + anchor: anchor, + tag: tag, + implicit: implicit, + style: yaml_style_t(yaml_BLOCK_MAPPING_STYLE), + } + if parser.stem_comment != nil { + event.head_comment = parser.stem_comment + parser.stem_comment = nil + } + return true + } + if len(anchor) > 0 || len(tag) > 0 { + parser.state = parser.states[len(parser.states)-1] + parser.states = parser.states[:len(parser.states)-1] + + *event = yaml_event_t{ + typ: yaml_SCALAR_EVENT, + start_mark: start_mark, + end_mark: end_mark, + anchor: anchor, + tag: tag, + implicit: implicit, + quoted_implicit: false, + style: yaml_style_t(yaml_PLAIN_SCALAR_STYLE), + } + return true + } + + context := "while parsing a flow node" + if block { + context = "while parsing a block node" + } + yaml_parser_set_parser_error_context(parser, context, start_mark, + "did not find expected node content", token.start_mark) + return false +} + +// Parse the productions: +// +// block_sequence ::= BLOCK-SEQUENCE-START (BLOCK-ENTRY block_node?)* BLOCK-END +// ******************** *********** * ********* +func yaml_parser_parse_block_sequence_entry(parser *yaml_parser_t, event *yaml_event_t, first bool) bool { + if first { + token := peek_token(parser) + if token == nil { + return false + } + parser.marks = append(parser.marks, token.start_mark) + skip_token(parser) + } + + token := peek_token(parser) + if token == nil { + return false + } + + if token.typ == yaml_BLOCK_ENTRY_TOKEN { + mark := token.end_mark + prior_head_len := len(parser.head_comment) + skip_token(parser) + yaml_parser_split_stem_comment(parser, prior_head_len) + token = peek_token(parser) + if token == nil { + return false + } + if token.typ != yaml_BLOCK_ENTRY_TOKEN && token.typ != yaml_BLOCK_END_TOKEN { + parser.states = append(parser.states, yaml_PARSE_BLOCK_SEQUENCE_ENTRY_STATE) + return yaml_parser_parse_node(parser, event, true, false) + } else { + parser.state = yaml_PARSE_BLOCK_SEQUENCE_ENTRY_STATE + return yaml_parser_process_empty_scalar(parser, event, mark) + } + } + if token.typ == yaml_BLOCK_END_TOKEN { + parser.state = parser.states[len(parser.states)-1] + parser.states = parser.states[:len(parser.states)-1] + parser.marks = parser.marks[:len(parser.marks)-1] + + *event = yaml_event_t{ + typ: yaml_SEQUENCE_END_EVENT, + start_mark: token.start_mark, + end_mark: token.end_mark, + } + + skip_token(parser) + return true + } + + context_mark := parser.marks[len(parser.marks)-1] + parser.marks = parser.marks[:len(parser.marks)-1] + return yaml_parser_set_parser_error_context(parser, + "while parsing a block collection", context_mark, + "did not find expected '-' indicator", token.start_mark) +} + +// Parse the productions: +// +// indentless_sequence ::= (BLOCK-ENTRY block_node?)+ +// *********** * +func yaml_parser_parse_indentless_sequence_entry(parser *yaml_parser_t, event *yaml_event_t) bool { + token := peek_token(parser) + if token == nil { + return false + } + + if token.typ == yaml_BLOCK_ENTRY_TOKEN { + mark := token.end_mark + prior_head_len := len(parser.head_comment) + skip_token(parser) + yaml_parser_split_stem_comment(parser, prior_head_len) + token = peek_token(parser) + if token == nil { + return false + } + if token.typ != yaml_BLOCK_ENTRY_TOKEN && + token.typ != yaml_KEY_TOKEN && + token.typ != yaml_VALUE_TOKEN && + token.typ != yaml_BLOCK_END_TOKEN { + parser.states = append(parser.states, yaml_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE) + return yaml_parser_parse_node(parser, event, true, false) + } + parser.state = yaml_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE + return yaml_parser_process_empty_scalar(parser, event, mark) + } + parser.state = parser.states[len(parser.states)-1] + parser.states = parser.states[:len(parser.states)-1] + + *event = yaml_event_t{ + typ: yaml_SEQUENCE_END_EVENT, + start_mark: token.start_mark, + end_mark: token.start_mark, // [Go] Shouldn't this be token.end_mark? + } + return true +} + +// Split stem comment from head comment. +// +// When a sequence or map is found under a sequence entry, the former head comment +// is assigned to the underlying sequence or map as a whole, not the individual +// sequence or map entry as would be expected otherwise. To handle this case the +// previous head comment is moved aside as the stem comment. +func yaml_parser_split_stem_comment(parser *yaml_parser_t, stem_len int) { + if stem_len == 0 { + return + } + + token := peek_token(parser) + if token == nil || token.typ != yaml_BLOCK_SEQUENCE_START_TOKEN && token.typ != yaml_BLOCK_MAPPING_START_TOKEN { + return + } + + parser.stem_comment = parser.head_comment[:stem_len] + if len(parser.head_comment) == stem_len { + parser.head_comment = nil + } else { + // Copy suffix to prevent very strange bugs if someone ever appends + // further bytes to the prefix in the stem_comment slice above. + parser.head_comment = append([]byte(nil), parser.head_comment[stem_len+1:]...) + } +} + +// Parse the productions: +// +// block_mapping ::= BLOCK-MAPPING_START +// ******************* +// ((KEY block_node_or_indentless_sequence?)? +// *** * +// (VALUE block_node_or_indentless_sequence?)?)* +// +// BLOCK-END +// ********* +func yaml_parser_parse_block_mapping_key(parser *yaml_parser_t, event *yaml_event_t, first bool) bool { + if first { + token := peek_token(parser) + if token == nil { + return false + } + parser.marks = append(parser.marks, token.start_mark) + skip_token(parser) + } + + token := peek_token(parser) + if token == nil { + return false + } + + // [Go] A tail comment was left from the prior mapping value processed. Emit an event + // as it needs to be processed with that value and not the following key. + if len(parser.tail_comment) > 0 { + *event = yaml_event_t{ + typ: yaml_TAIL_COMMENT_EVENT, + start_mark: token.start_mark, + end_mark: token.end_mark, + foot_comment: parser.tail_comment, + } + parser.tail_comment = nil + return true + } + + if token.typ == yaml_KEY_TOKEN { + mark := token.end_mark + skip_token(parser) + token = peek_token(parser) + if token == nil { + return false + } + if token.typ != yaml_KEY_TOKEN && + token.typ != yaml_VALUE_TOKEN && + token.typ != yaml_BLOCK_END_TOKEN { + parser.states = append(parser.states, yaml_PARSE_BLOCK_MAPPING_VALUE_STATE) + return yaml_parser_parse_node(parser, event, true, true) + } else { + parser.state = yaml_PARSE_BLOCK_MAPPING_VALUE_STATE + return yaml_parser_process_empty_scalar(parser, event, mark) + } + } else if token.typ == yaml_BLOCK_END_TOKEN { + parser.state = parser.states[len(parser.states)-1] + parser.states = parser.states[:len(parser.states)-1] + parser.marks = parser.marks[:len(parser.marks)-1] + *event = yaml_event_t{ + typ: yaml_MAPPING_END_EVENT, + start_mark: token.start_mark, + end_mark: token.end_mark, + } + yaml_parser_set_event_comments(parser, event) + skip_token(parser) + return true + } + + context_mark := parser.marks[len(parser.marks)-1] + parser.marks = parser.marks[:len(parser.marks)-1] + return yaml_parser_set_parser_error_context(parser, + "while parsing a block mapping", context_mark, + "did not find expected key", token.start_mark) +} + +// Parse the productions: +// +// block_mapping ::= BLOCK-MAPPING_START +// +// ((KEY block_node_or_indentless_sequence?)? +// +// (VALUE block_node_or_indentless_sequence?)?)* +// ***** * +// BLOCK-END +func yaml_parser_parse_block_mapping_value(parser *yaml_parser_t, event *yaml_event_t) bool { + token := peek_token(parser) + if token == nil { + return false + } + if token.typ == yaml_VALUE_TOKEN { + mark := token.end_mark + skip_token(parser) + token = peek_token(parser) + if token == nil { + return false + } + if token.typ != yaml_KEY_TOKEN && + token.typ != yaml_VALUE_TOKEN && + token.typ != yaml_BLOCK_END_TOKEN { + parser.states = append(parser.states, yaml_PARSE_BLOCK_MAPPING_KEY_STATE) + return yaml_parser_parse_node(parser, event, true, true) + } + parser.state = yaml_PARSE_BLOCK_MAPPING_KEY_STATE + return yaml_parser_process_empty_scalar(parser, event, mark) + } + parser.state = yaml_PARSE_BLOCK_MAPPING_KEY_STATE + return yaml_parser_process_empty_scalar(parser, event, token.start_mark) +} + +// Parse the productions: +// +// flow_sequence ::= FLOW-SEQUENCE-START +// ******************* +// (flow_sequence_entry FLOW-ENTRY)* +// * ********** +// flow_sequence_entry? +// * +// FLOW-SEQUENCE-END +// ***************** +// flow_sequence_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)? +// * +func yaml_parser_parse_flow_sequence_entry(parser *yaml_parser_t, event *yaml_event_t, first bool) bool { + if first { + token := peek_token(parser) + if token == nil { + return false + } + parser.marks = append(parser.marks, token.start_mark) + skip_token(parser) + } + token := peek_token(parser) + if token == nil { + return false + } + if token.typ != yaml_FLOW_SEQUENCE_END_TOKEN { + if !first { + if token.typ == yaml_FLOW_ENTRY_TOKEN { + skip_token(parser) + token = peek_token(parser) + if token == nil { + return false + } + } else { + context_mark := parser.marks[len(parser.marks)-1] + parser.marks = parser.marks[:len(parser.marks)-1] + return yaml_parser_set_parser_error_context(parser, + "while parsing a flow sequence", context_mark, + "did not find expected ',' or ']'", token.start_mark) + } + } + + if token.typ == yaml_KEY_TOKEN { + parser.state = yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE + *event = yaml_event_t{ + typ: yaml_MAPPING_START_EVENT, + start_mark: token.start_mark, + end_mark: token.end_mark, + implicit: true, + style: yaml_style_t(yaml_FLOW_MAPPING_STYLE), + } + skip_token(parser) + return true + } else if token.typ != yaml_FLOW_SEQUENCE_END_TOKEN { + parser.states = append(parser.states, yaml_PARSE_FLOW_SEQUENCE_ENTRY_STATE) + return yaml_parser_parse_node(parser, event, false, false) + } + } + + parser.state = parser.states[len(parser.states)-1] + parser.states = parser.states[:len(parser.states)-1] + parser.marks = parser.marks[:len(parser.marks)-1] + + *event = yaml_event_t{ + typ: yaml_SEQUENCE_END_EVENT, + start_mark: token.start_mark, + end_mark: token.end_mark, + } + yaml_parser_set_event_comments(parser, event) + + skip_token(parser) + return true +} + +// Parse the productions: +// +// flow_sequence_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)? +// *** * +func yaml_parser_parse_flow_sequence_entry_mapping_key(parser *yaml_parser_t, event *yaml_event_t) bool { + token := peek_token(parser) + if token == nil { + return false + } + if token.typ != yaml_VALUE_TOKEN && + token.typ != yaml_FLOW_ENTRY_TOKEN && + token.typ != yaml_FLOW_SEQUENCE_END_TOKEN { + parser.states = append(parser.states, yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE) + return yaml_parser_parse_node(parser, event, false, false) + } + mark := token.end_mark + skip_token(parser) + parser.state = yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE + return yaml_parser_process_empty_scalar(parser, event, mark) +} + +// Parse the productions: +// +// flow_sequence_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)? +// ***** * +func yaml_parser_parse_flow_sequence_entry_mapping_value(parser *yaml_parser_t, event *yaml_event_t) bool { + token := peek_token(parser) + if token == nil { + return false + } + if token.typ == yaml_VALUE_TOKEN { + skip_token(parser) + token := peek_token(parser) + if token == nil { + return false + } + if token.typ != yaml_FLOW_ENTRY_TOKEN && token.typ != yaml_FLOW_SEQUENCE_END_TOKEN { + parser.states = append(parser.states, yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE) + return yaml_parser_parse_node(parser, event, false, false) + } + } + parser.state = yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE + return yaml_parser_process_empty_scalar(parser, event, token.start_mark) +} + +// Parse the productions: +// +// flow_sequence_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)? +// * +func yaml_parser_parse_flow_sequence_entry_mapping_end(parser *yaml_parser_t, event *yaml_event_t) bool { + token := peek_token(parser) + if token == nil { + return false + } + parser.state = yaml_PARSE_FLOW_SEQUENCE_ENTRY_STATE + *event = yaml_event_t{ + typ: yaml_MAPPING_END_EVENT, + start_mark: token.start_mark, + end_mark: token.start_mark, // [Go] Shouldn't this be end_mark? + } + return true +} + +// Parse the productions: +// +// flow_mapping ::= FLOW-MAPPING-START +// ****************** +// (flow_mapping_entry FLOW-ENTRY)* +// * ********** +// flow_mapping_entry? +// ****************** +// FLOW-MAPPING-END +// **************** +// flow_mapping_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)? +// * *** * +func yaml_parser_parse_flow_mapping_key(parser *yaml_parser_t, event *yaml_event_t, first bool) bool { + if first { + token := peek_token(parser) + parser.marks = append(parser.marks, token.start_mark) + skip_token(parser) + } + + token := peek_token(parser) + if token == nil { + return false + } + + if token.typ != yaml_FLOW_MAPPING_END_TOKEN { + if !first { + if token.typ == yaml_FLOW_ENTRY_TOKEN { + skip_token(parser) + token = peek_token(parser) + if token == nil { + return false + } + } else { + context_mark := parser.marks[len(parser.marks)-1] + parser.marks = parser.marks[:len(parser.marks)-1] + return yaml_parser_set_parser_error_context(parser, + "while parsing a flow mapping", context_mark, + "did not find expected ',' or '}'", token.start_mark) + } + } + + if token.typ == yaml_KEY_TOKEN { + skip_token(parser) + token = peek_token(parser) + if token == nil { + return false + } + if token.typ != yaml_VALUE_TOKEN && + token.typ != yaml_FLOW_ENTRY_TOKEN && + token.typ != yaml_FLOW_MAPPING_END_TOKEN { + parser.states = append(parser.states, yaml_PARSE_FLOW_MAPPING_VALUE_STATE) + return yaml_parser_parse_node(parser, event, false, false) + } else { + parser.state = yaml_PARSE_FLOW_MAPPING_VALUE_STATE + return yaml_parser_process_empty_scalar(parser, event, token.start_mark) + } + } else if token.typ != yaml_FLOW_MAPPING_END_TOKEN { + parser.states = append(parser.states, yaml_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE) + return yaml_parser_parse_node(parser, event, false, false) + } + } + + parser.state = parser.states[len(parser.states)-1] + parser.states = parser.states[:len(parser.states)-1] + parser.marks = parser.marks[:len(parser.marks)-1] + *event = yaml_event_t{ + typ: yaml_MAPPING_END_EVENT, + start_mark: token.start_mark, + end_mark: token.end_mark, + } + yaml_parser_set_event_comments(parser, event) + skip_token(parser) + return true +} + +// Parse the productions: +// +// flow_mapping_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)? +// * ***** * +func yaml_parser_parse_flow_mapping_value(parser *yaml_parser_t, event *yaml_event_t, empty bool) bool { + token := peek_token(parser) + if token == nil { + return false + } + if empty { + parser.state = yaml_PARSE_FLOW_MAPPING_KEY_STATE + return yaml_parser_process_empty_scalar(parser, event, token.start_mark) + } + if token.typ == yaml_VALUE_TOKEN { + skip_token(parser) + token = peek_token(parser) + if token == nil { + return false + } + if token.typ != yaml_FLOW_ENTRY_TOKEN && token.typ != yaml_FLOW_MAPPING_END_TOKEN { + parser.states = append(parser.states, yaml_PARSE_FLOW_MAPPING_KEY_STATE) + return yaml_parser_parse_node(parser, event, false, false) + } + } + parser.state = yaml_PARSE_FLOW_MAPPING_KEY_STATE + return yaml_parser_process_empty_scalar(parser, event, token.start_mark) +} + +// Generate an empty scalar event. +func yaml_parser_process_empty_scalar(parser *yaml_parser_t, event *yaml_event_t, mark yaml_mark_t) bool { + *event = yaml_event_t{ + typ: yaml_SCALAR_EVENT, + start_mark: mark, + end_mark: mark, + value: nil, // Empty + implicit: true, + style: yaml_style_t(yaml_PLAIN_SCALAR_STYLE), + } + return true +} + +var default_tag_directives = []yaml_tag_directive_t{ + {[]byte("!"), []byte("!")}, + {[]byte("!!"), []byte("tag:yaml.org,2002:")}, +} + +// Parse directives. +func yaml_parser_process_directives(parser *yaml_parser_t, + version_directive_ref **yaml_version_directive_t, + tag_directives_ref *[]yaml_tag_directive_t) bool { + + var version_directive *yaml_version_directive_t + var tag_directives []yaml_tag_directive_t + + token := peek_token(parser) + if token == nil { + return false + } + + for token.typ == yaml_VERSION_DIRECTIVE_TOKEN || token.typ == yaml_TAG_DIRECTIVE_TOKEN { + if token.typ == yaml_VERSION_DIRECTIVE_TOKEN { + if version_directive != nil { + yaml_parser_set_parser_error(parser, + "found duplicate %YAML directive", token.start_mark) + return false + } + if token.major != 1 || token.minor != 1 { + yaml_parser_set_parser_error(parser, + "found incompatible YAML document", token.start_mark) + return false + } + version_directive = &yaml_version_directive_t{ + major: token.major, + minor: token.minor, + } + } else if token.typ == yaml_TAG_DIRECTIVE_TOKEN { + value := yaml_tag_directive_t{ + handle: token.value, + prefix: token.prefix, + } + if !yaml_parser_append_tag_directive(parser, value, false, token.start_mark) { + return false + } + tag_directives = append(tag_directives, value) + } + + skip_token(parser) + token = peek_token(parser) + if token == nil { + return false + } + } + + for i := range default_tag_directives { + if !yaml_parser_append_tag_directive(parser, default_tag_directives[i], true, token.start_mark) { + return false + } + } + + if version_directive_ref != nil { + *version_directive_ref = version_directive + } + if tag_directives_ref != nil { + *tag_directives_ref = tag_directives + } + return true +} + +// Append a tag directive to the directives stack. +func yaml_parser_append_tag_directive(parser *yaml_parser_t, value yaml_tag_directive_t, allow_duplicates bool, mark yaml_mark_t) bool { + for i := range parser.tag_directives { + if bytes.Equal(value.handle, parser.tag_directives[i].handle) { + if allow_duplicates { + return true + } + return yaml_parser_set_parser_error(parser, "found duplicate %TAG directive", mark) + } + } + + // [Go] I suspect the copy is unnecessary. This was likely done + // because there was no way to track ownership of the data. + value_copy := yaml_tag_directive_t{ + handle: make([]byte, len(value.handle)), + prefix: make([]byte, len(value.prefix)), + } + copy(value_copy.handle, value.handle) + copy(value_copy.prefix, value.prefix) + parser.tag_directives = append(parser.tag_directives, value_copy) + return true +} diff --git a/vendor/go.yaml.in/yaml/v3/readerc.go b/vendor/go.yaml.in/yaml/v3/readerc.go new file mode 100644 index 000000000..56af24536 --- /dev/null +++ b/vendor/go.yaml.in/yaml/v3/readerc.go @@ -0,0 +1,434 @@ +// +// Copyright (c) 2011-2019 Canonical Ltd +// Copyright (c) 2006-2010 Kirill Simonov +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of +// this software and associated documentation files (the "Software"), to deal in +// the Software without restriction, including without limitation the rights to +// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +// of the Software, and to permit persons to whom the Software is furnished to do +// so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +package yaml + +import ( + "io" +) + +// Set the reader error and return 0. +func yaml_parser_set_reader_error(parser *yaml_parser_t, problem string, offset int, value int) bool { + parser.error = yaml_READER_ERROR + parser.problem = problem + parser.problem_offset = offset + parser.problem_value = value + return false +} + +// Byte order marks. +const ( + bom_UTF8 = "\xef\xbb\xbf" + bom_UTF16LE = "\xff\xfe" + bom_UTF16BE = "\xfe\xff" +) + +// Determine the input stream encoding by checking the BOM symbol. If no BOM is +// found, the UTF-8 encoding is assumed. Return 1 on success, 0 on failure. +func yaml_parser_determine_encoding(parser *yaml_parser_t) bool { + // Ensure that we had enough bytes in the raw buffer. + for !parser.eof && len(parser.raw_buffer)-parser.raw_buffer_pos < 3 { + if !yaml_parser_update_raw_buffer(parser) { + return false + } + } + + // Determine the encoding. + buf := parser.raw_buffer + pos := parser.raw_buffer_pos + avail := len(buf) - pos + if avail >= 2 && buf[pos] == bom_UTF16LE[0] && buf[pos+1] == bom_UTF16LE[1] { + parser.encoding = yaml_UTF16LE_ENCODING + parser.raw_buffer_pos += 2 + parser.offset += 2 + } else if avail >= 2 && buf[pos] == bom_UTF16BE[0] && buf[pos+1] == bom_UTF16BE[1] { + parser.encoding = yaml_UTF16BE_ENCODING + parser.raw_buffer_pos += 2 + parser.offset += 2 + } else if avail >= 3 && buf[pos] == bom_UTF8[0] && buf[pos+1] == bom_UTF8[1] && buf[pos+2] == bom_UTF8[2] { + parser.encoding = yaml_UTF8_ENCODING + parser.raw_buffer_pos += 3 + parser.offset += 3 + } else { + parser.encoding = yaml_UTF8_ENCODING + } + return true +} + +// Update the raw buffer. +func yaml_parser_update_raw_buffer(parser *yaml_parser_t) bool { + size_read := 0 + + // Return if the raw buffer is full. + if parser.raw_buffer_pos == 0 && len(parser.raw_buffer) == cap(parser.raw_buffer) { + return true + } + + // Return on EOF. + if parser.eof { + return true + } + + // Move the remaining bytes in the raw buffer to the beginning. + if parser.raw_buffer_pos > 0 && parser.raw_buffer_pos < len(parser.raw_buffer) { + copy(parser.raw_buffer, parser.raw_buffer[parser.raw_buffer_pos:]) + } + parser.raw_buffer = parser.raw_buffer[:len(parser.raw_buffer)-parser.raw_buffer_pos] + parser.raw_buffer_pos = 0 + + // Call the read handler to fill the buffer. + size_read, err := parser.read_handler(parser, parser.raw_buffer[len(parser.raw_buffer):cap(parser.raw_buffer)]) + parser.raw_buffer = parser.raw_buffer[:len(parser.raw_buffer)+size_read] + if err == io.EOF { + parser.eof = true + } else if err != nil { + return yaml_parser_set_reader_error(parser, "input error: "+err.Error(), parser.offset, -1) + } + return true +} + +// Ensure that the buffer contains at least `length` characters. +// Return true on success, false on failure. +// +// The length is supposed to be significantly less that the buffer size. +func yaml_parser_update_buffer(parser *yaml_parser_t, length int) bool { + if parser.read_handler == nil { + panic("read handler must be set") + } + + // [Go] This function was changed to guarantee the requested length size at EOF. + // The fact we need to do this is pretty awful, but the description above implies + // for that to be the case, and there are tests + + // If the EOF flag is set and the raw buffer is empty, do nothing. + if parser.eof && parser.raw_buffer_pos == len(parser.raw_buffer) { + // [Go] ACTUALLY! Read the documentation of this function above. + // This is just broken. To return true, we need to have the + // given length in the buffer. Not doing that means every single + // check that calls this function to make sure the buffer has a + // given length is Go) panicking; or C) accessing invalid memory. + //return true + } + + // Return if the buffer contains enough characters. + if parser.unread >= length { + return true + } + + // Determine the input encoding if it is not known yet. + if parser.encoding == yaml_ANY_ENCODING { + if !yaml_parser_determine_encoding(parser) { + return false + } + } + + // Move the unread characters to the beginning of the buffer. + buffer_len := len(parser.buffer) + if parser.buffer_pos > 0 && parser.buffer_pos < buffer_len { + copy(parser.buffer, parser.buffer[parser.buffer_pos:]) + buffer_len -= parser.buffer_pos + parser.buffer_pos = 0 + } else if parser.buffer_pos == buffer_len { + buffer_len = 0 + parser.buffer_pos = 0 + } + + // Open the whole buffer for writing, and cut it before returning. + parser.buffer = parser.buffer[:cap(parser.buffer)] + + // Fill the buffer until it has enough characters. + first := true + for parser.unread < length { + + // Fill the raw buffer if necessary. + if !first || parser.raw_buffer_pos == len(parser.raw_buffer) { + if !yaml_parser_update_raw_buffer(parser) { + parser.buffer = parser.buffer[:buffer_len] + return false + } + } + first = false + + // Decode the raw buffer. + inner: + for parser.raw_buffer_pos != len(parser.raw_buffer) { + var value rune + var width int + + raw_unread := len(parser.raw_buffer) - parser.raw_buffer_pos + + // Decode the next character. + switch parser.encoding { + case yaml_UTF8_ENCODING: + // Decode a UTF-8 character. Check RFC 3629 + // (http://www.ietf.org/rfc/rfc3629.txt) for more details. + // + // The following table (taken from the RFC) is used for + // decoding. + // + // Char. number range | UTF-8 octet sequence + // (hexadecimal) | (binary) + // --------------------+------------------------------------ + // 0000 0000-0000 007F | 0xxxxxxx + // 0000 0080-0000 07FF | 110xxxxx 10xxxxxx + // 0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx + // 0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx + // + // Additionally, the characters in the range 0xD800-0xDFFF + // are prohibited as they are reserved for use with UTF-16 + // surrogate pairs. + + // Determine the length of the UTF-8 sequence. + octet := parser.raw_buffer[parser.raw_buffer_pos] + switch { + case octet&0x80 == 0x00: + width = 1 + case octet&0xE0 == 0xC0: + width = 2 + case octet&0xF0 == 0xE0: + width = 3 + case octet&0xF8 == 0xF0: + width = 4 + default: + // The leading octet is invalid. + return yaml_parser_set_reader_error(parser, + "invalid leading UTF-8 octet", + parser.offset, int(octet)) + } + + // Check if the raw buffer contains an incomplete character. + if width > raw_unread { + if parser.eof { + return yaml_parser_set_reader_error(parser, + "incomplete UTF-8 octet sequence", + parser.offset, -1) + } + break inner + } + + // Decode the leading octet. + switch { + case octet&0x80 == 0x00: + value = rune(octet & 0x7F) + case octet&0xE0 == 0xC0: + value = rune(octet & 0x1F) + case octet&0xF0 == 0xE0: + value = rune(octet & 0x0F) + case octet&0xF8 == 0xF0: + value = rune(octet & 0x07) + default: + value = 0 + } + + // Check and decode the trailing octets. + for k := 1; k < width; k++ { + octet = parser.raw_buffer[parser.raw_buffer_pos+k] + + // Check if the octet is valid. + if (octet & 0xC0) != 0x80 { + return yaml_parser_set_reader_error(parser, + "invalid trailing UTF-8 octet", + parser.offset+k, int(octet)) + } + + // Decode the octet. + value = (value << 6) + rune(octet&0x3F) + } + + // Check the length of the sequence against the value. + switch { + case width == 1: + case width == 2 && value >= 0x80: + case width == 3 && value >= 0x800: + case width == 4 && value >= 0x10000: + default: + return yaml_parser_set_reader_error(parser, + "invalid length of a UTF-8 sequence", + parser.offset, -1) + } + + // Check the range of the value. + if value >= 0xD800 && value <= 0xDFFF || value > 0x10FFFF { + return yaml_parser_set_reader_error(parser, + "invalid Unicode character", + parser.offset, int(value)) + } + + case yaml_UTF16LE_ENCODING, yaml_UTF16BE_ENCODING: + var low, high int + if parser.encoding == yaml_UTF16LE_ENCODING { + low, high = 0, 1 + } else { + low, high = 1, 0 + } + + // The UTF-16 encoding is not as simple as one might + // naively think. Check RFC 2781 + // (http://www.ietf.org/rfc/rfc2781.txt). + // + // Normally, two subsequent bytes describe a Unicode + // character. However a special technique (called a + // surrogate pair) is used for specifying character + // values larger than 0xFFFF. + // + // A surrogate pair consists of two pseudo-characters: + // high surrogate area (0xD800-0xDBFF) + // low surrogate area (0xDC00-0xDFFF) + // + // The following formulas are used for decoding + // and encoding characters using surrogate pairs: + // + // U = U' + 0x10000 (0x01 00 00 <= U <= 0x10 FF FF) + // U' = yyyyyyyyyyxxxxxxxxxx (0 <= U' <= 0x0F FF FF) + // W1 = 110110yyyyyyyyyy + // W2 = 110111xxxxxxxxxx + // + // where U is the character value, W1 is the high surrogate + // area, W2 is the low surrogate area. + + // Check for incomplete UTF-16 character. + if raw_unread < 2 { + if parser.eof { + return yaml_parser_set_reader_error(parser, + "incomplete UTF-16 character", + parser.offset, -1) + } + break inner + } + + // Get the character. + value = rune(parser.raw_buffer[parser.raw_buffer_pos+low]) + + (rune(parser.raw_buffer[parser.raw_buffer_pos+high]) << 8) + + // Check for unexpected low surrogate area. + if value&0xFC00 == 0xDC00 { + return yaml_parser_set_reader_error(parser, + "unexpected low surrogate area", + parser.offset, int(value)) + } + + // Check for a high surrogate area. + if value&0xFC00 == 0xD800 { + width = 4 + + // Check for incomplete surrogate pair. + if raw_unread < 4 { + if parser.eof { + return yaml_parser_set_reader_error(parser, + "incomplete UTF-16 surrogate pair", + parser.offset, -1) + } + break inner + } + + // Get the next character. + value2 := rune(parser.raw_buffer[parser.raw_buffer_pos+low+2]) + + (rune(parser.raw_buffer[parser.raw_buffer_pos+high+2]) << 8) + + // Check for a low surrogate area. + if value2&0xFC00 != 0xDC00 { + return yaml_parser_set_reader_error(parser, + "expected low surrogate area", + parser.offset+2, int(value2)) + } + + // Generate the value of the surrogate pair. + value = 0x10000 + ((value & 0x3FF) << 10) + (value2 & 0x3FF) + } else { + width = 2 + } + + default: + panic("impossible") + } + + // Check if the character is in the allowed range: + // #x9 | #xA | #xD | [#x20-#x7E] (8 bit) + // | #x85 | [#xA0-#xD7FF] | [#xE000-#xFFFD] (16 bit) + // | [#x10000-#x10FFFF] (32 bit) + switch { + case value == 0x09: + case value == 0x0A: + case value == 0x0D: + case value >= 0x20 && value <= 0x7E: + case value == 0x85: + case value >= 0xA0 && value <= 0xD7FF: + case value >= 0xE000 && value <= 0xFFFD: + case value >= 0x10000 && value <= 0x10FFFF: + default: + return yaml_parser_set_reader_error(parser, + "control characters are not allowed", + parser.offset, int(value)) + } + + // Move the raw pointers. + parser.raw_buffer_pos += width + parser.offset += width + + // Finally put the character into the buffer. + if value <= 0x7F { + // 0000 0000-0000 007F . 0xxxxxxx + parser.buffer[buffer_len+0] = byte(value) + buffer_len += 1 + } else if value <= 0x7FF { + // 0000 0080-0000 07FF . 110xxxxx 10xxxxxx + parser.buffer[buffer_len+0] = byte(0xC0 + (value >> 6)) + parser.buffer[buffer_len+1] = byte(0x80 + (value & 0x3F)) + buffer_len += 2 + } else if value <= 0xFFFF { + // 0000 0800-0000 FFFF . 1110xxxx 10xxxxxx 10xxxxxx + parser.buffer[buffer_len+0] = byte(0xE0 + (value >> 12)) + parser.buffer[buffer_len+1] = byte(0x80 + ((value >> 6) & 0x3F)) + parser.buffer[buffer_len+2] = byte(0x80 + (value & 0x3F)) + buffer_len += 3 + } else { + // 0001 0000-0010 FFFF . 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx + parser.buffer[buffer_len+0] = byte(0xF0 + (value >> 18)) + parser.buffer[buffer_len+1] = byte(0x80 + ((value >> 12) & 0x3F)) + parser.buffer[buffer_len+2] = byte(0x80 + ((value >> 6) & 0x3F)) + parser.buffer[buffer_len+3] = byte(0x80 + (value & 0x3F)) + buffer_len += 4 + } + + parser.unread++ + } + + // On EOF, put NUL into the buffer and return. + if parser.eof { + parser.buffer[buffer_len] = 0 + buffer_len++ + parser.unread++ + break + } + } + // [Go] Read the documentation of this function above. To return true, + // we need to have the given length in the buffer. Not doing that means + // every single check that calls this function to make sure the buffer + // has a given length is Go) panicking; or C) accessing invalid memory. + // This happens here due to the EOF above breaking early. + for buffer_len < length { + parser.buffer[buffer_len] = 0 + buffer_len++ + } + parser.buffer = parser.buffer[:buffer_len] + return true +} diff --git a/vendor/go.yaml.in/yaml/v3/resolve.go b/vendor/go.yaml.in/yaml/v3/resolve.go new file mode 100644 index 000000000..64ae88805 --- /dev/null +++ b/vendor/go.yaml.in/yaml/v3/resolve.go @@ -0,0 +1,326 @@ +// +// Copyright (c) 2011-2019 Canonical Ltd +// +// 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. + +package yaml + +import ( + "encoding/base64" + "math" + "regexp" + "strconv" + "strings" + "time" +) + +type resolveMapItem struct { + value interface{} + tag string +} + +var resolveTable = make([]byte, 256) +var resolveMap = make(map[string]resolveMapItem) + +func init() { + t := resolveTable + t[int('+')] = 'S' // Sign + t[int('-')] = 'S' + for _, c := range "0123456789" { + t[int(c)] = 'D' // Digit + } + for _, c := range "yYnNtTfFoO~" { + t[int(c)] = 'M' // In map + } + t[int('.')] = '.' // Float (potentially in map) + + var resolveMapList = []struct { + v interface{} + tag string + l []string + }{ + {true, boolTag, []string{"true", "True", "TRUE"}}, + {false, boolTag, []string{"false", "False", "FALSE"}}, + {nil, nullTag, []string{"", "~", "null", "Null", "NULL"}}, + {math.NaN(), floatTag, []string{".nan", ".NaN", ".NAN"}}, + {math.Inf(+1), floatTag, []string{".inf", ".Inf", ".INF"}}, + {math.Inf(+1), floatTag, []string{"+.inf", "+.Inf", "+.INF"}}, + {math.Inf(-1), floatTag, []string{"-.inf", "-.Inf", "-.INF"}}, + {"<<", mergeTag, []string{"<<"}}, + } + + m := resolveMap + for _, item := range resolveMapList { + for _, s := range item.l { + m[s] = resolveMapItem{item.v, item.tag} + } + } +} + +const ( + nullTag = "!!null" + boolTag = "!!bool" + strTag = "!!str" + intTag = "!!int" + floatTag = "!!float" + timestampTag = "!!timestamp" + seqTag = "!!seq" + mapTag = "!!map" + binaryTag = "!!binary" + mergeTag = "!!merge" +) + +var longTags = make(map[string]string) +var shortTags = make(map[string]string) + +func init() { + for _, stag := range []string{nullTag, boolTag, strTag, intTag, floatTag, timestampTag, seqTag, mapTag, binaryTag, mergeTag} { + ltag := longTag(stag) + longTags[stag] = ltag + shortTags[ltag] = stag + } +} + +const longTagPrefix = "tag:yaml.org,2002:" + +func shortTag(tag string) string { + if strings.HasPrefix(tag, longTagPrefix) { + if stag, ok := shortTags[tag]; ok { + return stag + } + return "!!" + tag[len(longTagPrefix):] + } + return tag +} + +func longTag(tag string) string { + if strings.HasPrefix(tag, "!!") { + if ltag, ok := longTags[tag]; ok { + return ltag + } + return longTagPrefix + tag[2:] + } + return tag +} + +func resolvableTag(tag string) bool { + switch tag { + case "", strTag, boolTag, intTag, floatTag, nullTag, timestampTag: + return true + } + return false +} + +var yamlStyleFloat = regexp.MustCompile(`^[-+]?(\.[0-9]+|[0-9]+(\.[0-9]*)?)([eE][-+]?[0-9]+)?$`) + +func resolve(tag string, in string) (rtag string, out interface{}) { + tag = shortTag(tag) + if !resolvableTag(tag) { + return tag, in + } + + defer func() { + switch tag { + case "", rtag, strTag, binaryTag: + return + case floatTag: + if rtag == intTag { + switch v := out.(type) { + case int64: + rtag = floatTag + out = float64(v) + return + case int: + rtag = floatTag + out = float64(v) + return + } + } + } + failf("cannot decode %s `%s` as a %s", shortTag(rtag), in, shortTag(tag)) + }() + + // Any data is accepted as a !!str or !!binary. + // Otherwise, the prefix is enough of a hint about what it might be. + hint := byte('N') + if in != "" { + hint = resolveTable[in[0]] + } + if hint != 0 && tag != strTag && tag != binaryTag { + // Handle things we can lookup in a map. + if item, ok := resolveMap[in]; ok { + return item.tag, item.value + } + + // Base 60 floats are a bad idea, were dropped in YAML 1.2, and + // are purposefully unsupported here. They're still quoted on + // the way out for compatibility with other parser, though. + + switch hint { + case 'M': + // We've already checked the map above. + + case '.': + // Not in the map, so maybe a normal float. + floatv, err := strconv.ParseFloat(in, 64) + if err == nil { + return floatTag, floatv + } + + case 'D', 'S': + // Int, float, or timestamp. + // Only try values as a timestamp if the value is unquoted or there's an explicit + // !!timestamp tag. + if tag == "" || tag == timestampTag { + t, ok := parseTimestamp(in) + if ok { + return timestampTag, t + } + } + + plain := strings.Replace(in, "_", "", -1) + intv, err := strconv.ParseInt(plain, 0, 64) + if err == nil { + if intv == int64(int(intv)) { + return intTag, int(intv) + } else { + return intTag, intv + } + } + uintv, err := strconv.ParseUint(plain, 0, 64) + if err == nil { + return intTag, uintv + } + if yamlStyleFloat.MatchString(plain) { + floatv, err := strconv.ParseFloat(plain, 64) + if err == nil { + return floatTag, floatv + } + } + if strings.HasPrefix(plain, "0b") { + intv, err := strconv.ParseInt(plain[2:], 2, 64) + if err == nil { + if intv == int64(int(intv)) { + return intTag, int(intv) + } else { + return intTag, intv + } + } + uintv, err := strconv.ParseUint(plain[2:], 2, 64) + if err == nil { + return intTag, uintv + } + } else if strings.HasPrefix(plain, "-0b") { + intv, err := strconv.ParseInt("-"+plain[3:], 2, 64) + if err == nil { + if true || intv == int64(int(intv)) { + return intTag, int(intv) + } else { + return intTag, intv + } + } + } + // Octals as introduced in version 1.2 of the spec. + // Octals from the 1.1 spec, spelled as 0777, are still + // decoded by default in v3 as well for compatibility. + // May be dropped in v4 depending on how usage evolves. + if strings.HasPrefix(plain, "0o") { + intv, err := strconv.ParseInt(plain[2:], 8, 64) + if err == nil { + if intv == int64(int(intv)) { + return intTag, int(intv) + } else { + return intTag, intv + } + } + uintv, err := strconv.ParseUint(plain[2:], 8, 64) + if err == nil { + return intTag, uintv + } + } else if strings.HasPrefix(plain, "-0o") { + intv, err := strconv.ParseInt("-"+plain[3:], 8, 64) + if err == nil { + if true || intv == int64(int(intv)) { + return intTag, int(intv) + } else { + return intTag, intv + } + } + } + default: + panic("internal error: missing handler for resolver table: " + string(rune(hint)) + " (with " + in + ")") + } + } + return strTag, in +} + +// encodeBase64 encodes s as base64 that is broken up into multiple lines +// as appropriate for the resulting length. +func encodeBase64(s string) string { + const lineLen = 70 + encLen := base64.StdEncoding.EncodedLen(len(s)) + lines := encLen/lineLen + 1 + buf := make([]byte, encLen*2+lines) + in := buf[0:encLen] + out := buf[encLen:] + base64.StdEncoding.Encode(in, []byte(s)) + k := 0 + for i := 0; i < len(in); i += lineLen { + j := i + lineLen + if j > len(in) { + j = len(in) + } + k += copy(out[k:], in[i:j]) + if lines > 1 { + out[k] = '\n' + k++ + } + } + return string(out[:k]) +} + +// This is a subset of the formats allowed by the regular expression +// defined at http://yaml.org/type/timestamp.html. +var allowedTimestampFormats = []string{ + "2006-1-2T15:4:5.999999999Z07:00", // RCF3339Nano with short date fields. + "2006-1-2t15:4:5.999999999Z07:00", // RFC3339Nano with short date fields and lower-case "t". + "2006-1-2 15:4:5.999999999", // space separated with no time zone + "2006-1-2", // date only + // Notable exception: time.Parse cannot handle: "2001-12-14 21:59:43.10 -5" + // from the set of examples. +} + +// parseTimestamp parses s as a timestamp string and +// returns the timestamp and reports whether it succeeded. +// Timestamp formats are defined at http://yaml.org/type/timestamp.html +func parseTimestamp(s string) (time.Time, bool) { + // TODO write code to check all the formats supported by + // http://yaml.org/type/timestamp.html instead of using time.Parse. + + // Quick check: all date formats start with YYYY-. + i := 0 + for ; i < len(s); i++ { + if c := s[i]; c < '0' || c > '9' { + break + } + } + if i != 4 || i == len(s) || s[i] != '-' { + return time.Time{}, false + } + for _, format := range allowedTimestampFormats { + if t, err := time.Parse(format, s); err == nil { + return t, true + } + } + return time.Time{}, false +} diff --git a/vendor/go.yaml.in/yaml/v3/scannerc.go b/vendor/go.yaml.in/yaml/v3/scannerc.go new file mode 100644 index 000000000..30b1f0892 --- /dev/null +++ b/vendor/go.yaml.in/yaml/v3/scannerc.go @@ -0,0 +1,3040 @@ +// +// Copyright (c) 2011-2019 Canonical Ltd +// Copyright (c) 2006-2010 Kirill Simonov +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of +// this software and associated documentation files (the "Software"), to deal in +// the Software without restriction, including without limitation the rights to +// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +// of the Software, and to permit persons to whom the Software is furnished to do +// so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +package yaml + +import ( + "bytes" + "fmt" +) + +// Introduction +// ************ +// +// The following notes assume that you are familiar with the YAML specification +// (http://yaml.org/spec/1.2/spec.html). We mostly follow it, although in +// some cases we are less restrictive that it requires. +// +// The process of transforming a YAML stream into a sequence of events is +// divided on two steps: Scanning and Parsing. +// +// The Scanner transforms the input stream into a sequence of tokens, while the +// parser transform the sequence of tokens produced by the Scanner into a +// sequence of parsing events. +// +// The Scanner is rather clever and complicated. The Parser, on the contrary, +// is a straightforward implementation of a recursive-descendant parser (or, +// LL(1) parser, as it is usually called). +// +// Actually there are two issues of Scanning that might be called "clever", the +// rest is quite straightforward. The issues are "block collection start" and +// "simple keys". Both issues are explained below in details. +// +// Here the Scanning step is explained and implemented. We start with the list +// of all the tokens produced by the Scanner together with short descriptions. +// +// Now, tokens: +// +// STREAM-START(encoding) # The stream start. +// STREAM-END # The stream end. +// VERSION-DIRECTIVE(major,minor) # The '%YAML' directive. +// TAG-DIRECTIVE(handle,prefix) # The '%TAG' directive. +// DOCUMENT-START # '---' +// DOCUMENT-END # '...' +// BLOCK-SEQUENCE-START # Indentation increase denoting a block +// BLOCK-MAPPING-START # sequence or a block mapping. +// BLOCK-END # Indentation decrease. +// FLOW-SEQUENCE-START # '[' +// FLOW-SEQUENCE-END # ']' +// BLOCK-SEQUENCE-START # '{' +// BLOCK-SEQUENCE-END # '}' +// BLOCK-ENTRY # '-' +// FLOW-ENTRY # ',' +// KEY # '?' or nothing (simple keys). +// VALUE # ':' +// ALIAS(anchor) # '*anchor' +// ANCHOR(anchor) # '&anchor' +// TAG(handle,suffix) # '!handle!suffix' +// SCALAR(value,style) # A scalar. +// +// The following two tokens are "virtual" tokens denoting the beginning and the +// end of the stream: +// +// STREAM-START(encoding) +// STREAM-END +// +// We pass the information about the input stream encoding with the +// STREAM-START token. +// +// The next two tokens are responsible for tags: +// +// VERSION-DIRECTIVE(major,minor) +// TAG-DIRECTIVE(handle,prefix) +// +// Example: +// +// %YAML 1.1 +// %TAG ! !foo +// %TAG !yaml! tag:yaml.org,2002: +// --- +// +// The correspoding sequence of tokens: +// +// STREAM-START(utf-8) +// VERSION-DIRECTIVE(1,1) +// TAG-DIRECTIVE("!","!foo") +// TAG-DIRECTIVE("!yaml","tag:yaml.org,2002:") +// DOCUMENT-START +// STREAM-END +// +// Note that the VERSION-DIRECTIVE and TAG-DIRECTIVE tokens occupy a whole +// line. +// +// The document start and end indicators are represented by: +// +// DOCUMENT-START +// DOCUMENT-END +// +// Note that if a YAML stream contains an implicit document (without '---' +// and '...' indicators), no DOCUMENT-START and DOCUMENT-END tokens will be +// produced. +// +// In the following examples, we present whole documents together with the +// produced tokens. +// +// 1. An implicit document: +// +// 'a scalar' +// +// Tokens: +// +// STREAM-START(utf-8) +// SCALAR("a scalar",single-quoted) +// STREAM-END +// +// 2. An explicit document: +// +// --- +// 'a scalar' +// ... +// +// Tokens: +// +// STREAM-START(utf-8) +// DOCUMENT-START +// SCALAR("a scalar",single-quoted) +// DOCUMENT-END +// STREAM-END +// +// 3. Several documents in a stream: +// +// 'a scalar' +// --- +// 'another scalar' +// --- +// 'yet another scalar' +// +// Tokens: +// +// STREAM-START(utf-8) +// SCALAR("a scalar",single-quoted) +// DOCUMENT-START +// SCALAR("another scalar",single-quoted) +// DOCUMENT-START +// SCALAR("yet another scalar",single-quoted) +// STREAM-END +// +// We have already introduced the SCALAR token above. The following tokens are +// used to describe aliases, anchors, tag, and scalars: +// +// ALIAS(anchor) +// ANCHOR(anchor) +// TAG(handle,suffix) +// SCALAR(value,style) +// +// The following series of examples illustrate the usage of these tokens: +// +// 1. A recursive sequence: +// +// &A [ *A ] +// +// Tokens: +// +// STREAM-START(utf-8) +// ANCHOR("A") +// FLOW-SEQUENCE-START +// ALIAS("A") +// FLOW-SEQUENCE-END +// STREAM-END +// +// 2. A tagged scalar: +// +// !!float "3.14" # A good approximation. +// +// Tokens: +// +// STREAM-START(utf-8) +// TAG("!!","float") +// SCALAR("3.14",double-quoted) +// STREAM-END +// +// 3. Various scalar styles: +// +// --- # Implicit empty plain scalars do not produce tokens. +// --- a plain scalar +// --- 'a single-quoted scalar' +// --- "a double-quoted scalar" +// --- |- +// a literal scalar +// --- >- +// a folded +// scalar +// +// Tokens: +// +// STREAM-START(utf-8) +// DOCUMENT-START +// DOCUMENT-START +// SCALAR("a plain scalar",plain) +// DOCUMENT-START +// SCALAR("a single-quoted scalar",single-quoted) +// DOCUMENT-START +// SCALAR("a double-quoted scalar",double-quoted) +// DOCUMENT-START +// SCALAR("a literal scalar",literal) +// DOCUMENT-START +// SCALAR("a folded scalar",folded) +// STREAM-END +// +// Now it's time to review collection-related tokens. We will start with +// flow collections: +// +// FLOW-SEQUENCE-START +// FLOW-SEQUENCE-END +// FLOW-MAPPING-START +// FLOW-MAPPING-END +// FLOW-ENTRY +// KEY +// VALUE +// +// The tokens FLOW-SEQUENCE-START, FLOW-SEQUENCE-END, FLOW-MAPPING-START, and +// FLOW-MAPPING-END represent the indicators '[', ']', '{', and '}' +// correspondingly. FLOW-ENTRY represent the ',' indicator. Finally the +// indicators '?' and ':', which are used for denoting mapping keys and values, +// are represented by the KEY and VALUE tokens. +// +// The following examples show flow collections: +// +// 1. A flow sequence: +// +// [item 1, item 2, item 3] +// +// Tokens: +// +// STREAM-START(utf-8) +// FLOW-SEQUENCE-START +// SCALAR("item 1",plain) +// FLOW-ENTRY +// SCALAR("item 2",plain) +// FLOW-ENTRY +// SCALAR("item 3",plain) +// FLOW-SEQUENCE-END +// STREAM-END +// +// 2. A flow mapping: +// +// { +// a simple key: a value, # Note that the KEY token is produced. +// ? a complex key: another value, +// } +// +// Tokens: +// +// STREAM-START(utf-8) +// FLOW-MAPPING-START +// KEY +// SCALAR("a simple key",plain) +// VALUE +// SCALAR("a value",plain) +// FLOW-ENTRY +// KEY +// SCALAR("a complex key",plain) +// VALUE +// SCALAR("another value",plain) +// FLOW-ENTRY +// FLOW-MAPPING-END +// STREAM-END +// +// A simple key is a key which is not denoted by the '?' indicator. Note that +// the Scanner still produce the KEY token whenever it encounters a simple key. +// +// For scanning block collections, the following tokens are used (note that we +// repeat KEY and VALUE here): +// +// BLOCK-SEQUENCE-START +// BLOCK-MAPPING-START +// BLOCK-END +// BLOCK-ENTRY +// KEY +// VALUE +// +// The tokens BLOCK-SEQUENCE-START and BLOCK-MAPPING-START denote indentation +// increase that precedes a block collection (cf. the INDENT token in Python). +// The token BLOCK-END denote indentation decrease that ends a block collection +// (cf. the DEDENT token in Python). However YAML has some syntax pecularities +// that makes detections of these tokens more complex. +// +// The tokens BLOCK-ENTRY, KEY, and VALUE are used to represent the indicators +// '-', '?', and ':' correspondingly. +// +// The following examples show how the tokens BLOCK-SEQUENCE-START, +// BLOCK-MAPPING-START, and BLOCK-END are emitted by the Scanner: +// +// 1. Block sequences: +// +// - item 1 +// - item 2 +// - +// - item 3.1 +// - item 3.2 +// - +// key 1: value 1 +// key 2: value 2 +// +// Tokens: +// +// STREAM-START(utf-8) +// BLOCK-SEQUENCE-START +// BLOCK-ENTRY +// SCALAR("item 1",plain) +// BLOCK-ENTRY +// SCALAR("item 2",plain) +// BLOCK-ENTRY +// BLOCK-SEQUENCE-START +// BLOCK-ENTRY +// SCALAR("item 3.1",plain) +// BLOCK-ENTRY +// SCALAR("item 3.2",plain) +// BLOCK-END +// BLOCK-ENTRY +// BLOCK-MAPPING-START +// KEY +// SCALAR("key 1",plain) +// VALUE +// SCALAR("value 1",plain) +// KEY +// SCALAR("key 2",plain) +// VALUE +// SCALAR("value 2",plain) +// BLOCK-END +// BLOCK-END +// STREAM-END +// +// 2. Block mappings: +// +// a simple key: a value # The KEY token is produced here. +// ? a complex key +// : another value +// a mapping: +// key 1: value 1 +// key 2: value 2 +// a sequence: +// - item 1 +// - item 2 +// +// Tokens: +// +// STREAM-START(utf-8) +// BLOCK-MAPPING-START +// KEY +// SCALAR("a simple key",plain) +// VALUE +// SCALAR("a value",plain) +// KEY +// SCALAR("a complex key",plain) +// VALUE +// SCALAR("another value",plain) +// KEY +// SCALAR("a mapping",plain) +// BLOCK-MAPPING-START +// KEY +// SCALAR("key 1",plain) +// VALUE +// SCALAR("value 1",plain) +// KEY +// SCALAR("key 2",plain) +// VALUE +// SCALAR("value 2",plain) +// BLOCK-END +// KEY +// SCALAR("a sequence",plain) +// VALUE +// BLOCK-SEQUENCE-START +// BLOCK-ENTRY +// SCALAR("item 1",plain) +// BLOCK-ENTRY +// SCALAR("item 2",plain) +// BLOCK-END +// BLOCK-END +// STREAM-END +// +// YAML does not always require to start a new block collection from a new +// line. If the current line contains only '-', '?', and ':' indicators, a new +// block collection may start at the current line. The following examples +// illustrate this case: +// +// 1. Collections in a sequence: +// +// - - item 1 +// - item 2 +// - key 1: value 1 +// key 2: value 2 +// - ? complex key +// : complex value +// +// Tokens: +// +// STREAM-START(utf-8) +// BLOCK-SEQUENCE-START +// BLOCK-ENTRY +// BLOCK-SEQUENCE-START +// BLOCK-ENTRY +// SCALAR("item 1",plain) +// BLOCK-ENTRY +// SCALAR("item 2",plain) +// BLOCK-END +// BLOCK-ENTRY +// BLOCK-MAPPING-START +// KEY +// SCALAR("key 1",plain) +// VALUE +// SCALAR("value 1",plain) +// KEY +// SCALAR("key 2",plain) +// VALUE +// SCALAR("value 2",plain) +// BLOCK-END +// BLOCK-ENTRY +// BLOCK-MAPPING-START +// KEY +// SCALAR("complex key") +// VALUE +// SCALAR("complex value") +// BLOCK-END +// BLOCK-END +// STREAM-END +// +// 2. Collections in a mapping: +// +// ? a sequence +// : - item 1 +// - item 2 +// ? a mapping +// : key 1: value 1 +// key 2: value 2 +// +// Tokens: +// +// STREAM-START(utf-8) +// BLOCK-MAPPING-START +// KEY +// SCALAR("a sequence",plain) +// VALUE +// BLOCK-SEQUENCE-START +// BLOCK-ENTRY +// SCALAR("item 1",plain) +// BLOCK-ENTRY +// SCALAR("item 2",plain) +// BLOCK-END +// KEY +// SCALAR("a mapping",plain) +// VALUE +// BLOCK-MAPPING-START +// KEY +// SCALAR("key 1",plain) +// VALUE +// SCALAR("value 1",plain) +// KEY +// SCALAR("key 2",plain) +// VALUE +// SCALAR("value 2",plain) +// BLOCK-END +// BLOCK-END +// STREAM-END +// +// YAML also permits non-indented sequences if they are included into a block +// mapping. In this case, the token BLOCK-SEQUENCE-START is not produced: +// +// key: +// - item 1 # BLOCK-SEQUENCE-START is NOT produced here. +// - item 2 +// +// Tokens: +// +// STREAM-START(utf-8) +// BLOCK-MAPPING-START +// KEY +// SCALAR("key",plain) +// VALUE +// BLOCK-ENTRY +// SCALAR("item 1",plain) +// BLOCK-ENTRY +// SCALAR("item 2",plain) +// BLOCK-END +// + +// Ensure that the buffer contains the required number of characters. +// Return true on success, false on failure (reader error or memory error). +func cache(parser *yaml_parser_t, length int) bool { + // [Go] This was inlined: !cache(A, B) -> unread < B && !update(A, B) + return parser.unread >= length || yaml_parser_update_buffer(parser, length) +} + +// Advance the buffer pointer. +func skip(parser *yaml_parser_t) { + if !is_blank(parser.buffer, parser.buffer_pos) { + parser.newlines = 0 + } + parser.mark.index++ + parser.mark.column++ + parser.unread-- + parser.buffer_pos += width(parser.buffer[parser.buffer_pos]) +} + +func skip_line(parser *yaml_parser_t) { + if is_crlf(parser.buffer, parser.buffer_pos) { + parser.mark.index += 2 + parser.mark.column = 0 + parser.mark.line++ + parser.unread -= 2 + parser.buffer_pos += 2 + parser.newlines++ + } else if is_break(parser.buffer, parser.buffer_pos) { + parser.mark.index++ + parser.mark.column = 0 + parser.mark.line++ + parser.unread-- + parser.buffer_pos += width(parser.buffer[parser.buffer_pos]) + parser.newlines++ + } +} + +// Copy a character to a string buffer and advance pointers. +func read(parser *yaml_parser_t, s []byte) []byte { + if !is_blank(parser.buffer, parser.buffer_pos) { + parser.newlines = 0 + } + w := width(parser.buffer[parser.buffer_pos]) + if w == 0 { + panic("invalid character sequence") + } + if len(s) == 0 { + s = make([]byte, 0, 32) + } + if w == 1 && len(s)+w <= cap(s) { + s = s[:len(s)+1] + s[len(s)-1] = parser.buffer[parser.buffer_pos] + parser.buffer_pos++ + } else { + s = append(s, parser.buffer[parser.buffer_pos:parser.buffer_pos+w]...) + parser.buffer_pos += w + } + parser.mark.index++ + parser.mark.column++ + parser.unread-- + return s +} + +// Copy a line break character to a string buffer and advance pointers. +func read_line(parser *yaml_parser_t, s []byte) []byte { + buf := parser.buffer + pos := parser.buffer_pos + switch { + case buf[pos] == '\r' && buf[pos+1] == '\n': + // CR LF . LF + s = append(s, '\n') + parser.buffer_pos += 2 + parser.mark.index++ + parser.unread-- + case buf[pos] == '\r' || buf[pos] == '\n': + // CR|LF . LF + s = append(s, '\n') + parser.buffer_pos += 1 + case buf[pos] == '\xC2' && buf[pos+1] == '\x85': + // NEL . LF + s = append(s, '\n') + parser.buffer_pos += 2 + case buf[pos] == '\xE2' && buf[pos+1] == '\x80' && (buf[pos+2] == '\xA8' || buf[pos+2] == '\xA9'): + // LS|PS . LS|PS + s = append(s, buf[parser.buffer_pos:pos+3]...) + parser.buffer_pos += 3 + default: + return s + } + parser.mark.index++ + parser.mark.column = 0 + parser.mark.line++ + parser.unread-- + parser.newlines++ + return s +} + +// Get the next token. +func yaml_parser_scan(parser *yaml_parser_t, token *yaml_token_t) bool { + // Erase the token object. + *token = yaml_token_t{} // [Go] Is this necessary? + + // No tokens after STREAM-END or error. + if parser.stream_end_produced || parser.error != yaml_NO_ERROR { + return true + } + + // Ensure that the tokens queue contains enough tokens. + if !parser.token_available { + if !yaml_parser_fetch_more_tokens(parser) { + return false + } + } + + // Fetch the next token from the queue. + *token = parser.tokens[parser.tokens_head] + parser.tokens_head++ + parser.tokens_parsed++ + parser.token_available = false + + if token.typ == yaml_STREAM_END_TOKEN { + parser.stream_end_produced = true + } + return true +} + +// Set the scanner error and return false. +func yaml_parser_set_scanner_error(parser *yaml_parser_t, context string, context_mark yaml_mark_t, problem string) bool { + parser.error = yaml_SCANNER_ERROR + parser.context = context + parser.context_mark = context_mark + parser.problem = problem + parser.problem_mark = parser.mark + return false +} + +func yaml_parser_set_scanner_tag_error(parser *yaml_parser_t, directive bool, context_mark yaml_mark_t, problem string) bool { + context := "while parsing a tag" + if directive { + context = "while parsing a %TAG directive" + } + return yaml_parser_set_scanner_error(parser, context, context_mark, problem) +} + +func trace(args ...interface{}) func() { + pargs := append([]interface{}{"+++"}, args...) + fmt.Println(pargs...) + pargs = append([]interface{}{"---"}, args...) + return func() { fmt.Println(pargs...) } +} + +// Ensure that the tokens queue contains at least one token which can be +// returned to the Parser. +func yaml_parser_fetch_more_tokens(parser *yaml_parser_t) bool { + // While we need more tokens to fetch, do it. + for { + // [Go] The comment parsing logic requires a lookahead of two tokens + // so that foot comments may be parsed in time of associating them + // with the tokens that are parsed before them, and also for line + // comments to be transformed into head comments in some edge cases. + if parser.tokens_head < len(parser.tokens)-2 { + // If a potential simple key is at the head position, we need to fetch + // the next token to disambiguate it. + head_tok_idx, ok := parser.simple_keys_by_tok[parser.tokens_parsed] + if !ok { + break + } else if valid, ok := yaml_simple_key_is_valid(parser, &parser.simple_keys[head_tok_idx]); !ok { + return false + } else if !valid { + break + } + } + // Fetch the next token. + if !yaml_parser_fetch_next_token(parser) { + return false + } + } + + parser.token_available = true + return true +} + +// The dispatcher for token fetchers. +func yaml_parser_fetch_next_token(parser *yaml_parser_t) (ok bool) { + // Ensure that the buffer is initialized. + if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { + return false + } + + // Check if we just started scanning. Fetch STREAM-START then. + if !parser.stream_start_produced { + return yaml_parser_fetch_stream_start(parser) + } + + scan_mark := parser.mark + + // Eat whitespaces and comments until we reach the next token. + if !yaml_parser_scan_to_next_token(parser) { + return false + } + + // [Go] While unrolling indents, transform the head comments of prior + // indentation levels observed after scan_start into foot comments at + // the respective indexes. + + // Check the indentation level against the current column. + if !yaml_parser_unroll_indent(parser, parser.mark.column, scan_mark) { + return false + } + + // Ensure that the buffer contains at least 4 characters. 4 is the length + // of the longest indicators ('--- ' and '... '). + if parser.unread < 4 && !yaml_parser_update_buffer(parser, 4) { + return false + } + + // Is it the end of the stream? + if is_z(parser.buffer, parser.buffer_pos) { + return yaml_parser_fetch_stream_end(parser) + } + + // Is it a directive? + if parser.mark.column == 0 && parser.buffer[parser.buffer_pos] == '%' { + return yaml_parser_fetch_directive(parser) + } + + buf := parser.buffer + pos := parser.buffer_pos + + // Is it the document start indicator? + if parser.mark.column == 0 && buf[pos] == '-' && buf[pos+1] == '-' && buf[pos+2] == '-' && is_blankz(buf, pos+3) { + return yaml_parser_fetch_document_indicator(parser, yaml_DOCUMENT_START_TOKEN) + } + + // Is it the document end indicator? + if parser.mark.column == 0 && buf[pos] == '.' && buf[pos+1] == '.' && buf[pos+2] == '.' && is_blankz(buf, pos+3) { + return yaml_parser_fetch_document_indicator(parser, yaml_DOCUMENT_END_TOKEN) + } + + comment_mark := parser.mark + if len(parser.tokens) > 0 && (parser.flow_level == 0 && buf[pos] == ':' || parser.flow_level > 0 && buf[pos] == ',') { + // Associate any following comments with the prior token. + comment_mark = parser.tokens[len(parser.tokens)-1].start_mark + } + defer func() { + if !ok { + return + } + if len(parser.tokens) > 0 && parser.tokens[len(parser.tokens)-1].typ == yaml_BLOCK_ENTRY_TOKEN { + // Sequence indicators alone have no line comments. It becomes + // a head comment for whatever follows. + return + } + if !yaml_parser_scan_line_comment(parser, comment_mark) { + ok = false + return + } + }() + + // Is it the flow sequence start indicator? + if buf[pos] == '[' { + return yaml_parser_fetch_flow_collection_start(parser, yaml_FLOW_SEQUENCE_START_TOKEN) + } + + // Is it the flow mapping start indicator? + if parser.buffer[parser.buffer_pos] == '{' { + return yaml_parser_fetch_flow_collection_start(parser, yaml_FLOW_MAPPING_START_TOKEN) + } + + // Is it the flow sequence end indicator? + if parser.buffer[parser.buffer_pos] == ']' { + return yaml_parser_fetch_flow_collection_end(parser, + yaml_FLOW_SEQUENCE_END_TOKEN) + } + + // Is it the flow mapping end indicator? + if parser.buffer[parser.buffer_pos] == '}' { + return yaml_parser_fetch_flow_collection_end(parser, + yaml_FLOW_MAPPING_END_TOKEN) + } + + // Is it the flow entry indicator? + if parser.buffer[parser.buffer_pos] == ',' { + return yaml_parser_fetch_flow_entry(parser) + } + + // Is it the block entry indicator? + if parser.buffer[parser.buffer_pos] == '-' && is_blankz(parser.buffer, parser.buffer_pos+1) { + return yaml_parser_fetch_block_entry(parser) + } + + // Is it the key indicator? + if parser.buffer[parser.buffer_pos] == '?' && (parser.flow_level > 0 || is_blankz(parser.buffer, parser.buffer_pos+1)) { + return yaml_parser_fetch_key(parser) + } + + // Is it the value indicator? + if parser.buffer[parser.buffer_pos] == ':' && (parser.flow_level > 0 || is_blankz(parser.buffer, parser.buffer_pos+1)) { + return yaml_parser_fetch_value(parser) + } + + // Is it an alias? + if parser.buffer[parser.buffer_pos] == '*' { + return yaml_parser_fetch_anchor(parser, yaml_ALIAS_TOKEN) + } + + // Is it an anchor? + if parser.buffer[parser.buffer_pos] == '&' { + return yaml_parser_fetch_anchor(parser, yaml_ANCHOR_TOKEN) + } + + // Is it a tag? + if parser.buffer[parser.buffer_pos] == '!' { + return yaml_parser_fetch_tag(parser) + } + + // Is it a literal scalar? + if parser.buffer[parser.buffer_pos] == '|' && parser.flow_level == 0 { + return yaml_parser_fetch_block_scalar(parser, true) + } + + // Is it a folded scalar? + if parser.buffer[parser.buffer_pos] == '>' && parser.flow_level == 0 { + return yaml_parser_fetch_block_scalar(parser, false) + } + + // Is it a single-quoted scalar? + if parser.buffer[parser.buffer_pos] == '\'' { + return yaml_parser_fetch_flow_scalar(parser, true) + } + + // Is it a double-quoted scalar? + if parser.buffer[parser.buffer_pos] == '"' { + return yaml_parser_fetch_flow_scalar(parser, false) + } + + // Is it a plain scalar? + // + // A plain scalar may start with any non-blank characters except + // + // '-', '?', ':', ',', '[', ']', '{', '}', + // '#', '&', '*', '!', '|', '>', '\'', '\"', + // '%', '@', '`'. + // + // In the block context (and, for the '-' indicator, in the flow context + // too), it may also start with the characters + // + // '-', '?', ':' + // + // if it is followed by a non-space character. + // + // The last rule is more restrictive than the specification requires. + // [Go] TODO Make this logic more reasonable. + //switch parser.buffer[parser.buffer_pos] { + //case '-', '?', ':', ',', '?', '-', ',', ':', ']', '[', '}', '{', '&', '#', '!', '*', '>', '|', '"', '\'', '@', '%', '-', '`': + //} + if !(is_blankz(parser.buffer, parser.buffer_pos) || parser.buffer[parser.buffer_pos] == '-' || + parser.buffer[parser.buffer_pos] == '?' || parser.buffer[parser.buffer_pos] == ':' || + parser.buffer[parser.buffer_pos] == ',' || parser.buffer[parser.buffer_pos] == '[' || + parser.buffer[parser.buffer_pos] == ']' || parser.buffer[parser.buffer_pos] == '{' || + parser.buffer[parser.buffer_pos] == '}' || parser.buffer[parser.buffer_pos] == '#' || + parser.buffer[parser.buffer_pos] == '&' || parser.buffer[parser.buffer_pos] == '*' || + parser.buffer[parser.buffer_pos] == '!' || parser.buffer[parser.buffer_pos] == '|' || + parser.buffer[parser.buffer_pos] == '>' || parser.buffer[parser.buffer_pos] == '\'' || + parser.buffer[parser.buffer_pos] == '"' || parser.buffer[parser.buffer_pos] == '%' || + parser.buffer[parser.buffer_pos] == '@' || parser.buffer[parser.buffer_pos] == '`') || + (parser.buffer[parser.buffer_pos] == '-' && !is_blank(parser.buffer, parser.buffer_pos+1)) || + (parser.flow_level == 0 && + (parser.buffer[parser.buffer_pos] == '?' || parser.buffer[parser.buffer_pos] == ':') && + !is_blankz(parser.buffer, parser.buffer_pos+1)) { + return yaml_parser_fetch_plain_scalar(parser) + } + + // If we don't determine the token type so far, it is an error. + return yaml_parser_set_scanner_error(parser, + "while scanning for the next token", parser.mark, + "found character that cannot start any token") +} + +func yaml_simple_key_is_valid(parser *yaml_parser_t, simple_key *yaml_simple_key_t) (valid, ok bool) { + if !simple_key.possible { + return false, true + } + + // The 1.2 specification says: + // + // "If the ? indicator is omitted, parsing needs to see past the + // implicit key to recognize it as such. To limit the amount of + // lookahead required, the “:” indicator must appear at most 1024 + // Unicode characters beyond the start of the key. In addition, the key + // is restricted to a single line." + // + if simple_key.mark.line < parser.mark.line || simple_key.mark.index+1024 < parser.mark.index { + // Check if the potential simple key to be removed is required. + if simple_key.required { + return false, yaml_parser_set_scanner_error(parser, + "while scanning a simple key", simple_key.mark, + "could not find expected ':'") + } + simple_key.possible = false + return false, true + } + return true, true +} + +// Check if a simple key may start at the current position and add it if +// needed. +func yaml_parser_save_simple_key(parser *yaml_parser_t) bool { + // A simple key is required at the current position if the scanner is in + // the block context and the current column coincides with the indentation + // level. + + required := parser.flow_level == 0 && parser.indent == parser.mark.column + + // + // If the current position may start a simple key, save it. + // + if parser.simple_key_allowed { + simple_key := yaml_simple_key_t{ + possible: true, + required: required, + token_number: parser.tokens_parsed + (len(parser.tokens) - parser.tokens_head), + mark: parser.mark, + } + + if !yaml_parser_remove_simple_key(parser) { + return false + } + parser.simple_keys[len(parser.simple_keys)-1] = simple_key + parser.simple_keys_by_tok[simple_key.token_number] = len(parser.simple_keys) - 1 + } + return true +} + +// Remove a potential simple key at the current flow level. +func yaml_parser_remove_simple_key(parser *yaml_parser_t) bool { + i := len(parser.simple_keys) - 1 + if parser.simple_keys[i].possible { + // If the key is required, it is an error. + if parser.simple_keys[i].required { + return yaml_parser_set_scanner_error(parser, + "while scanning a simple key", parser.simple_keys[i].mark, + "could not find expected ':'") + } + // Remove the key from the stack. + parser.simple_keys[i].possible = false + delete(parser.simple_keys_by_tok, parser.simple_keys[i].token_number) + } + return true +} + +// max_flow_level limits the flow_level +const max_flow_level = 10000 + +// Increase the flow level and resize the simple key list if needed. +func yaml_parser_increase_flow_level(parser *yaml_parser_t) bool { + // Reset the simple key on the next level. + parser.simple_keys = append(parser.simple_keys, yaml_simple_key_t{ + possible: false, + required: false, + token_number: parser.tokens_parsed + (len(parser.tokens) - parser.tokens_head), + mark: parser.mark, + }) + + // Increase the flow level. + parser.flow_level++ + if parser.flow_level > max_flow_level { + return yaml_parser_set_scanner_error(parser, + "while increasing flow level", parser.simple_keys[len(parser.simple_keys)-1].mark, + fmt.Sprintf("exceeded max depth of %d", max_flow_level)) + } + return true +} + +// Decrease the flow level. +func yaml_parser_decrease_flow_level(parser *yaml_parser_t) bool { + if parser.flow_level > 0 { + parser.flow_level-- + last := len(parser.simple_keys) - 1 + delete(parser.simple_keys_by_tok, parser.simple_keys[last].token_number) + parser.simple_keys = parser.simple_keys[:last] + } + return true +} + +// max_indents limits the indents stack size +const max_indents = 10000 + +// Push the current indentation level to the stack and set the new level +// the current column is greater than the indentation level. In this case, +// append or insert the specified token into the token queue. +func yaml_parser_roll_indent(parser *yaml_parser_t, column, number int, typ yaml_token_type_t, mark yaml_mark_t) bool { + // In the flow context, do nothing. + if parser.flow_level > 0 { + return true + } + + if parser.indent < column { + // Push the current indentation level to the stack and set the new + // indentation level. + parser.indents = append(parser.indents, parser.indent) + parser.indent = column + if len(parser.indents) > max_indents { + return yaml_parser_set_scanner_error(parser, + "while increasing indent level", parser.simple_keys[len(parser.simple_keys)-1].mark, + fmt.Sprintf("exceeded max depth of %d", max_indents)) + } + + // Create a token and insert it into the queue. + token := yaml_token_t{ + typ: typ, + start_mark: mark, + end_mark: mark, + } + if number > -1 { + number -= parser.tokens_parsed + } + yaml_insert_token(parser, number, &token) + } + return true +} + +// Pop indentation levels from the indents stack until the current level +// becomes less or equal to the column. For each indentation level, append +// the BLOCK-END token. +func yaml_parser_unroll_indent(parser *yaml_parser_t, column int, scan_mark yaml_mark_t) bool { + // In the flow context, do nothing. + if parser.flow_level > 0 { + return true + } + + block_mark := scan_mark + block_mark.index-- + + // Loop through the indentation levels in the stack. + for parser.indent > column { + + // [Go] Reposition the end token before potential following + // foot comments of parent blocks. For that, search + // backwards for recent comments that were at the same + // indent as the block that is ending now. + stop_index := block_mark.index + for i := len(parser.comments) - 1; i >= 0; i-- { + comment := &parser.comments[i] + + if comment.end_mark.index < stop_index { + // Don't go back beyond the start of the comment/whitespace scan, unless column < 0. + // If requested indent column is < 0, then the document is over and everything else + // is a foot anyway. + break + } + if comment.start_mark.column == parser.indent+1 { + // This is a good match. But maybe there's a former comment + // at that same indent level, so keep searching. + block_mark = comment.start_mark + } + + // While the end of the former comment matches with + // the start of the following one, we know there's + // nothing in between and scanning is still safe. + stop_index = comment.scan_mark.index + } + + // Create a token and append it to the queue. + token := yaml_token_t{ + typ: yaml_BLOCK_END_TOKEN, + start_mark: block_mark, + end_mark: block_mark, + } + yaml_insert_token(parser, -1, &token) + + // Pop the indentation level. + parser.indent = parser.indents[len(parser.indents)-1] + parser.indents = parser.indents[:len(parser.indents)-1] + } + return true +} + +// Initialize the scanner and produce the STREAM-START token. +func yaml_parser_fetch_stream_start(parser *yaml_parser_t) bool { + + // Set the initial indentation. + parser.indent = -1 + + // Initialize the simple key stack. + parser.simple_keys = append(parser.simple_keys, yaml_simple_key_t{}) + + parser.simple_keys_by_tok = make(map[int]int) + + // A simple key is allowed at the beginning of the stream. + parser.simple_key_allowed = true + + // We have started. + parser.stream_start_produced = true + + // Create the STREAM-START token and append it to the queue. + token := yaml_token_t{ + typ: yaml_STREAM_START_TOKEN, + start_mark: parser.mark, + end_mark: parser.mark, + encoding: parser.encoding, + } + yaml_insert_token(parser, -1, &token) + return true +} + +// Produce the STREAM-END token and shut down the scanner. +func yaml_parser_fetch_stream_end(parser *yaml_parser_t) bool { + + // Force new line. + if parser.mark.column != 0 { + parser.mark.column = 0 + parser.mark.line++ + } + + // Reset the indentation level. + if !yaml_parser_unroll_indent(parser, -1, parser.mark) { + return false + } + + // Reset simple keys. + if !yaml_parser_remove_simple_key(parser) { + return false + } + + parser.simple_key_allowed = false + + // Create the STREAM-END token and append it to the queue. + token := yaml_token_t{ + typ: yaml_STREAM_END_TOKEN, + start_mark: parser.mark, + end_mark: parser.mark, + } + yaml_insert_token(parser, -1, &token) + return true +} + +// Produce a VERSION-DIRECTIVE or TAG-DIRECTIVE token. +func yaml_parser_fetch_directive(parser *yaml_parser_t) bool { + // Reset the indentation level. + if !yaml_parser_unroll_indent(parser, -1, parser.mark) { + return false + } + + // Reset simple keys. + if !yaml_parser_remove_simple_key(parser) { + return false + } + + parser.simple_key_allowed = false + + // Create the YAML-DIRECTIVE or TAG-DIRECTIVE token. + token := yaml_token_t{} + if !yaml_parser_scan_directive(parser, &token) { + return false + } + // Append the token to the queue. + yaml_insert_token(parser, -1, &token) + return true +} + +// Produce the DOCUMENT-START or DOCUMENT-END token. +func yaml_parser_fetch_document_indicator(parser *yaml_parser_t, typ yaml_token_type_t) bool { + // Reset the indentation level. + if !yaml_parser_unroll_indent(parser, -1, parser.mark) { + return false + } + + // Reset simple keys. + if !yaml_parser_remove_simple_key(parser) { + return false + } + + parser.simple_key_allowed = false + + // Consume the token. + start_mark := parser.mark + + skip(parser) + skip(parser) + skip(parser) + + end_mark := parser.mark + + // Create the DOCUMENT-START or DOCUMENT-END token. + token := yaml_token_t{ + typ: typ, + start_mark: start_mark, + end_mark: end_mark, + } + // Append the token to the queue. + yaml_insert_token(parser, -1, &token) + return true +} + +// Produce the FLOW-SEQUENCE-START or FLOW-MAPPING-START token. +func yaml_parser_fetch_flow_collection_start(parser *yaml_parser_t, typ yaml_token_type_t) bool { + + // The indicators '[' and '{' may start a simple key. + if !yaml_parser_save_simple_key(parser) { + return false + } + + // Increase the flow level. + if !yaml_parser_increase_flow_level(parser) { + return false + } + + // A simple key may follow the indicators '[' and '{'. + parser.simple_key_allowed = true + + // Consume the token. + start_mark := parser.mark + skip(parser) + end_mark := parser.mark + + // Create the FLOW-SEQUENCE-START of FLOW-MAPPING-START token. + token := yaml_token_t{ + typ: typ, + start_mark: start_mark, + end_mark: end_mark, + } + // Append the token to the queue. + yaml_insert_token(parser, -1, &token) + return true +} + +// Produce the FLOW-SEQUENCE-END or FLOW-MAPPING-END token. +func yaml_parser_fetch_flow_collection_end(parser *yaml_parser_t, typ yaml_token_type_t) bool { + // Reset any potential simple key on the current flow level. + if !yaml_parser_remove_simple_key(parser) { + return false + } + + // Decrease the flow level. + if !yaml_parser_decrease_flow_level(parser) { + return false + } + + // No simple keys after the indicators ']' and '}'. + parser.simple_key_allowed = false + + // Consume the token. + + start_mark := parser.mark + skip(parser) + end_mark := parser.mark + + // Create the FLOW-SEQUENCE-END of FLOW-MAPPING-END token. + token := yaml_token_t{ + typ: typ, + start_mark: start_mark, + end_mark: end_mark, + } + // Append the token to the queue. + yaml_insert_token(parser, -1, &token) + return true +} + +// Produce the FLOW-ENTRY token. +func yaml_parser_fetch_flow_entry(parser *yaml_parser_t) bool { + // Reset any potential simple keys on the current flow level. + if !yaml_parser_remove_simple_key(parser) { + return false + } + + // Simple keys are allowed after ','. + parser.simple_key_allowed = true + + // Consume the token. + start_mark := parser.mark + skip(parser) + end_mark := parser.mark + + // Create the FLOW-ENTRY token and append it to the queue. + token := yaml_token_t{ + typ: yaml_FLOW_ENTRY_TOKEN, + start_mark: start_mark, + end_mark: end_mark, + } + yaml_insert_token(parser, -1, &token) + return true +} + +// Produce the BLOCK-ENTRY token. +func yaml_parser_fetch_block_entry(parser *yaml_parser_t) bool { + // Check if the scanner is in the block context. + if parser.flow_level == 0 { + // Check if we are allowed to start a new entry. + if !parser.simple_key_allowed { + return yaml_parser_set_scanner_error(parser, "", parser.mark, + "block sequence entries are not allowed in this context") + } + // Add the BLOCK-SEQUENCE-START token if needed. + if !yaml_parser_roll_indent(parser, parser.mark.column, -1, yaml_BLOCK_SEQUENCE_START_TOKEN, parser.mark) { + return false + } + } else { + // It is an error for the '-' indicator to occur in the flow context, + // but we let the Parser detect and report about it because the Parser + // is able to point to the context. + } + + // Reset any potential simple keys on the current flow level. + if !yaml_parser_remove_simple_key(parser) { + return false + } + + // Simple keys are allowed after '-'. + parser.simple_key_allowed = true + + // Consume the token. + start_mark := parser.mark + skip(parser) + end_mark := parser.mark + + // Create the BLOCK-ENTRY token and append it to the queue. + token := yaml_token_t{ + typ: yaml_BLOCK_ENTRY_TOKEN, + start_mark: start_mark, + end_mark: end_mark, + } + yaml_insert_token(parser, -1, &token) + return true +} + +// Produce the KEY token. +func yaml_parser_fetch_key(parser *yaml_parser_t) bool { + + // In the block context, additional checks are required. + if parser.flow_level == 0 { + // Check if we are allowed to start a new key (not nessesary simple). + if !parser.simple_key_allowed { + return yaml_parser_set_scanner_error(parser, "", parser.mark, + "mapping keys are not allowed in this context") + } + // Add the BLOCK-MAPPING-START token if needed. + if !yaml_parser_roll_indent(parser, parser.mark.column, -1, yaml_BLOCK_MAPPING_START_TOKEN, parser.mark) { + return false + } + } + + // Reset any potential simple keys on the current flow level. + if !yaml_parser_remove_simple_key(parser) { + return false + } + + // Simple keys are allowed after '?' in the block context. + parser.simple_key_allowed = parser.flow_level == 0 + + // Consume the token. + start_mark := parser.mark + skip(parser) + end_mark := parser.mark + + // Create the KEY token and append it to the queue. + token := yaml_token_t{ + typ: yaml_KEY_TOKEN, + start_mark: start_mark, + end_mark: end_mark, + } + yaml_insert_token(parser, -1, &token) + return true +} + +// Produce the VALUE token. +func yaml_parser_fetch_value(parser *yaml_parser_t) bool { + + simple_key := &parser.simple_keys[len(parser.simple_keys)-1] + + // Have we found a simple key? + if valid, ok := yaml_simple_key_is_valid(parser, simple_key); !ok { + return false + + } else if valid { + + // Create the KEY token and insert it into the queue. + token := yaml_token_t{ + typ: yaml_KEY_TOKEN, + start_mark: simple_key.mark, + end_mark: simple_key.mark, + } + yaml_insert_token(parser, simple_key.token_number-parser.tokens_parsed, &token) + + // In the block context, we may need to add the BLOCK-MAPPING-START token. + if !yaml_parser_roll_indent(parser, simple_key.mark.column, + simple_key.token_number, + yaml_BLOCK_MAPPING_START_TOKEN, simple_key.mark) { + return false + } + + // Remove the simple key. + simple_key.possible = false + delete(parser.simple_keys_by_tok, simple_key.token_number) + + // A simple key cannot follow another simple key. + parser.simple_key_allowed = false + + } else { + // The ':' indicator follows a complex key. + + // In the block context, extra checks are required. + if parser.flow_level == 0 { + + // Check if we are allowed to start a complex value. + if !parser.simple_key_allowed { + return yaml_parser_set_scanner_error(parser, "", parser.mark, + "mapping values are not allowed in this context") + } + + // Add the BLOCK-MAPPING-START token if needed. + if !yaml_parser_roll_indent(parser, parser.mark.column, -1, yaml_BLOCK_MAPPING_START_TOKEN, parser.mark) { + return false + } + } + + // Simple keys after ':' are allowed in the block context. + parser.simple_key_allowed = parser.flow_level == 0 + } + + // Consume the token. + start_mark := parser.mark + skip(parser) + end_mark := parser.mark + + // Create the VALUE token and append it to the queue. + token := yaml_token_t{ + typ: yaml_VALUE_TOKEN, + start_mark: start_mark, + end_mark: end_mark, + } + yaml_insert_token(parser, -1, &token) + return true +} + +// Produce the ALIAS or ANCHOR token. +func yaml_parser_fetch_anchor(parser *yaml_parser_t, typ yaml_token_type_t) bool { + // An anchor or an alias could be a simple key. + if !yaml_parser_save_simple_key(parser) { + return false + } + + // A simple key cannot follow an anchor or an alias. + parser.simple_key_allowed = false + + // Create the ALIAS or ANCHOR token and append it to the queue. + var token yaml_token_t + if !yaml_parser_scan_anchor(parser, &token, typ) { + return false + } + yaml_insert_token(parser, -1, &token) + return true +} + +// Produce the TAG token. +func yaml_parser_fetch_tag(parser *yaml_parser_t) bool { + // A tag could be a simple key. + if !yaml_parser_save_simple_key(parser) { + return false + } + + // A simple key cannot follow a tag. + parser.simple_key_allowed = false + + // Create the TAG token and append it to the queue. + var token yaml_token_t + if !yaml_parser_scan_tag(parser, &token) { + return false + } + yaml_insert_token(parser, -1, &token) + return true +} + +// Produce the SCALAR(...,literal) or SCALAR(...,folded) tokens. +func yaml_parser_fetch_block_scalar(parser *yaml_parser_t, literal bool) bool { + // Remove any potential simple keys. + if !yaml_parser_remove_simple_key(parser) { + return false + } + + // A simple key may follow a block scalar. + parser.simple_key_allowed = true + + // Create the SCALAR token and append it to the queue. + var token yaml_token_t + if !yaml_parser_scan_block_scalar(parser, &token, literal) { + return false + } + yaml_insert_token(parser, -1, &token) + return true +} + +// Produce the SCALAR(...,single-quoted) or SCALAR(...,double-quoted) tokens. +func yaml_parser_fetch_flow_scalar(parser *yaml_parser_t, single bool) bool { + // A plain scalar could be a simple key. + if !yaml_parser_save_simple_key(parser) { + return false + } + + // A simple key cannot follow a flow scalar. + parser.simple_key_allowed = false + + // Create the SCALAR token and append it to the queue. + var token yaml_token_t + if !yaml_parser_scan_flow_scalar(parser, &token, single) { + return false + } + yaml_insert_token(parser, -1, &token) + return true +} + +// Produce the SCALAR(...,plain) token. +func yaml_parser_fetch_plain_scalar(parser *yaml_parser_t) bool { + // A plain scalar could be a simple key. + if !yaml_parser_save_simple_key(parser) { + return false + } + + // A simple key cannot follow a flow scalar. + parser.simple_key_allowed = false + + // Create the SCALAR token and append it to the queue. + var token yaml_token_t + if !yaml_parser_scan_plain_scalar(parser, &token) { + return false + } + yaml_insert_token(parser, -1, &token) + return true +} + +// Eat whitespaces and comments until the next token is found. +func yaml_parser_scan_to_next_token(parser *yaml_parser_t) bool { + + scan_mark := parser.mark + + // Until the next token is not found. + for { + // Allow the BOM mark to start a line. + if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { + return false + } + if parser.mark.column == 0 && is_bom(parser.buffer, parser.buffer_pos) { + skip(parser) + } + + // Eat whitespaces. + // Tabs are allowed: + // - in the flow context + // - in the block context, but not at the beginning of the line or + // after '-', '?', or ':' (complex value). + if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { + return false + } + + for parser.buffer[parser.buffer_pos] == ' ' || ((parser.flow_level > 0 || !parser.simple_key_allowed) && parser.buffer[parser.buffer_pos] == '\t') { + skip(parser) + if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { + return false + } + } + + // Check if we just had a line comment under a sequence entry that + // looks more like a header to the following content. Similar to this: + // + // - # The comment + // - Some data + // + // If so, transform the line comment to a head comment and reposition. + if len(parser.comments) > 0 && len(parser.tokens) > 1 { + tokenA := parser.tokens[len(parser.tokens)-2] + tokenB := parser.tokens[len(parser.tokens)-1] + comment := &parser.comments[len(parser.comments)-1] + if tokenA.typ == yaml_BLOCK_SEQUENCE_START_TOKEN && tokenB.typ == yaml_BLOCK_ENTRY_TOKEN && len(comment.line) > 0 && !is_break(parser.buffer, parser.buffer_pos) { + // If it was in the prior line, reposition so it becomes a + // header of the follow up token. Otherwise, keep it in place + // so it becomes a header of the former. + comment.head = comment.line + comment.line = nil + if comment.start_mark.line == parser.mark.line-1 { + comment.token_mark = parser.mark + } + } + } + + // Eat a comment until a line break. + if parser.buffer[parser.buffer_pos] == '#' { + if !yaml_parser_scan_comments(parser, scan_mark) { + return false + } + } + + // If it is a line break, eat it. + if is_break(parser.buffer, parser.buffer_pos) { + if parser.unread < 2 && !yaml_parser_update_buffer(parser, 2) { + return false + } + skip_line(parser) + + // In the block context, a new line may start a simple key. + if parser.flow_level == 0 { + parser.simple_key_allowed = true + } + } else { + break // We have found a token. + } + } + + return true +} + +// Scan a YAML-DIRECTIVE or TAG-DIRECTIVE token. +// +// Scope: +// +// %YAML 1.1 # a comment \n +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +// %TAG !yaml! tag:yaml.org,2002: \n +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +func yaml_parser_scan_directive(parser *yaml_parser_t, token *yaml_token_t) bool { + // Eat '%'. + start_mark := parser.mark + skip(parser) + + // Scan the directive name. + var name []byte + if !yaml_parser_scan_directive_name(parser, start_mark, &name) { + return false + } + + // Is it a YAML directive? + if bytes.Equal(name, []byte("YAML")) { + // Scan the VERSION directive value. + var major, minor int8 + if !yaml_parser_scan_version_directive_value(parser, start_mark, &major, &minor) { + return false + } + end_mark := parser.mark + + // Create a VERSION-DIRECTIVE token. + *token = yaml_token_t{ + typ: yaml_VERSION_DIRECTIVE_TOKEN, + start_mark: start_mark, + end_mark: end_mark, + major: major, + minor: minor, + } + + // Is it a TAG directive? + } else if bytes.Equal(name, []byte("TAG")) { + // Scan the TAG directive value. + var handle, prefix []byte + if !yaml_parser_scan_tag_directive_value(parser, start_mark, &handle, &prefix) { + return false + } + end_mark := parser.mark + + // Create a TAG-DIRECTIVE token. + *token = yaml_token_t{ + typ: yaml_TAG_DIRECTIVE_TOKEN, + start_mark: start_mark, + end_mark: end_mark, + value: handle, + prefix: prefix, + } + + // Unknown directive. + } else { + yaml_parser_set_scanner_error(parser, "while scanning a directive", + start_mark, "found unknown directive name") + return false + } + + // Eat the rest of the line including any comments. + if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { + return false + } + + for is_blank(parser.buffer, parser.buffer_pos) { + skip(parser) + if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { + return false + } + } + + if parser.buffer[parser.buffer_pos] == '#' { + // [Go] Discard this inline comment for the time being. + //if !yaml_parser_scan_line_comment(parser, start_mark) { + // return false + //} + for !is_breakz(parser.buffer, parser.buffer_pos) { + skip(parser) + if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { + return false + } + } + } + + // Check if we are at the end of the line. + if !is_breakz(parser.buffer, parser.buffer_pos) { + yaml_parser_set_scanner_error(parser, "while scanning a directive", + start_mark, "did not find expected comment or line break") + return false + } + + // Eat a line break. + if is_break(parser.buffer, parser.buffer_pos) { + if parser.unread < 2 && !yaml_parser_update_buffer(parser, 2) { + return false + } + skip_line(parser) + } + + return true +} + +// Scan the directive name. +// +// Scope: +// +// %YAML 1.1 # a comment \n +// ^^^^ +// %TAG !yaml! tag:yaml.org,2002: \n +// ^^^ +func yaml_parser_scan_directive_name(parser *yaml_parser_t, start_mark yaml_mark_t, name *[]byte) bool { + // Consume the directive name. + if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { + return false + } + + var s []byte + for is_alpha(parser.buffer, parser.buffer_pos) { + s = read(parser, s) + if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { + return false + } + } + + // Check if the name is empty. + if len(s) == 0 { + yaml_parser_set_scanner_error(parser, "while scanning a directive", + start_mark, "could not find expected directive name") + return false + } + + // Check for an blank character after the name. + if !is_blankz(parser.buffer, parser.buffer_pos) { + yaml_parser_set_scanner_error(parser, "while scanning a directive", + start_mark, "found unexpected non-alphabetical character") + return false + } + *name = s + return true +} + +// Scan the value of VERSION-DIRECTIVE. +// +// Scope: +// +// %YAML 1.1 # a comment \n +// ^^^^^^ +func yaml_parser_scan_version_directive_value(parser *yaml_parser_t, start_mark yaml_mark_t, major, minor *int8) bool { + // Eat whitespaces. + if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { + return false + } + for is_blank(parser.buffer, parser.buffer_pos) { + skip(parser) + if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { + return false + } + } + + // Consume the major version number. + if !yaml_parser_scan_version_directive_number(parser, start_mark, major) { + return false + } + + // Eat '.'. + if parser.buffer[parser.buffer_pos] != '.' { + return yaml_parser_set_scanner_error(parser, "while scanning a %YAML directive", + start_mark, "did not find expected digit or '.' character") + } + + skip(parser) + + // Consume the minor version number. + if !yaml_parser_scan_version_directive_number(parser, start_mark, minor) { + return false + } + return true +} + +const max_number_length = 2 + +// Scan the version number of VERSION-DIRECTIVE. +// +// Scope: +// +// %YAML 1.1 # a comment \n +// ^ +// %YAML 1.1 # a comment \n +// ^ +func yaml_parser_scan_version_directive_number(parser *yaml_parser_t, start_mark yaml_mark_t, number *int8) bool { + + // Repeat while the next character is digit. + if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { + return false + } + var value, length int8 + for is_digit(parser.buffer, parser.buffer_pos) { + // Check if the number is too long. + length++ + if length > max_number_length { + return yaml_parser_set_scanner_error(parser, "while scanning a %YAML directive", + start_mark, "found extremely long version number") + } + value = value*10 + int8(as_digit(parser.buffer, parser.buffer_pos)) + skip(parser) + if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { + return false + } + } + + // Check if the number was present. + if length == 0 { + return yaml_parser_set_scanner_error(parser, "while scanning a %YAML directive", + start_mark, "did not find expected version number") + } + *number = value + return true +} + +// Scan the value of a TAG-DIRECTIVE token. +// +// Scope: +// +// %TAG !yaml! tag:yaml.org,2002: \n +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +func yaml_parser_scan_tag_directive_value(parser *yaml_parser_t, start_mark yaml_mark_t, handle, prefix *[]byte) bool { + var handle_value, prefix_value []byte + + // Eat whitespaces. + if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { + return false + } + + for is_blank(parser.buffer, parser.buffer_pos) { + skip(parser) + if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { + return false + } + } + + // Scan a handle. + if !yaml_parser_scan_tag_handle(parser, true, start_mark, &handle_value) { + return false + } + + // Expect a whitespace. + if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { + return false + } + if !is_blank(parser.buffer, parser.buffer_pos) { + yaml_parser_set_scanner_error(parser, "while scanning a %TAG directive", + start_mark, "did not find expected whitespace") + return false + } + + // Eat whitespaces. + for is_blank(parser.buffer, parser.buffer_pos) { + skip(parser) + if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { + return false + } + } + + // Scan a prefix. + if !yaml_parser_scan_tag_uri(parser, true, nil, start_mark, &prefix_value) { + return false + } + + // Expect a whitespace or line break. + if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { + return false + } + if !is_blankz(parser.buffer, parser.buffer_pos) { + yaml_parser_set_scanner_error(parser, "while scanning a %TAG directive", + start_mark, "did not find expected whitespace or line break") + return false + } + + *handle = handle_value + *prefix = prefix_value + return true +} + +func yaml_parser_scan_anchor(parser *yaml_parser_t, token *yaml_token_t, typ yaml_token_type_t) bool { + var s []byte + + // Eat the indicator character. + start_mark := parser.mark + skip(parser) + + // Consume the value. + if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { + return false + } + + for is_alpha(parser.buffer, parser.buffer_pos) { + s = read(parser, s) + if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { + return false + } + } + + end_mark := parser.mark + + /* + * Check if length of the anchor is greater than 0 and it is followed by + * a whitespace character or one of the indicators: + * + * '?', ':', ',', ']', '}', '%', '@', '`'. + */ + + if len(s) == 0 || + !(is_blankz(parser.buffer, parser.buffer_pos) || parser.buffer[parser.buffer_pos] == '?' || + parser.buffer[parser.buffer_pos] == ':' || parser.buffer[parser.buffer_pos] == ',' || + parser.buffer[parser.buffer_pos] == ']' || parser.buffer[parser.buffer_pos] == '}' || + parser.buffer[parser.buffer_pos] == '%' || parser.buffer[parser.buffer_pos] == '@' || + parser.buffer[parser.buffer_pos] == '`') { + context := "while scanning an alias" + if typ == yaml_ANCHOR_TOKEN { + context = "while scanning an anchor" + } + yaml_parser_set_scanner_error(parser, context, start_mark, + "did not find expected alphabetic or numeric character") + return false + } + + // Create a token. + *token = yaml_token_t{ + typ: typ, + start_mark: start_mark, + end_mark: end_mark, + value: s, + } + + return true +} + +/* + * Scan a TAG token. + */ + +func yaml_parser_scan_tag(parser *yaml_parser_t, token *yaml_token_t) bool { + var handle, suffix []byte + + start_mark := parser.mark + + // Check if the tag is in the canonical form. + if parser.unread < 2 && !yaml_parser_update_buffer(parser, 2) { + return false + } + + if parser.buffer[parser.buffer_pos+1] == '<' { + // Keep the handle as '' + + // Eat '!<' + skip(parser) + skip(parser) + + // Consume the tag value. + if !yaml_parser_scan_tag_uri(parser, false, nil, start_mark, &suffix) { + return false + } + + // Check for '>' and eat it. + if parser.buffer[parser.buffer_pos] != '>' { + yaml_parser_set_scanner_error(parser, "while scanning a tag", + start_mark, "did not find the expected '>'") + return false + } + + skip(parser) + } else { + // The tag has either the '!suffix' or the '!handle!suffix' form. + + // First, try to scan a handle. + if !yaml_parser_scan_tag_handle(parser, false, start_mark, &handle) { + return false + } + + // Check if it is, indeed, handle. + if handle[0] == '!' && len(handle) > 1 && handle[len(handle)-1] == '!' { + // Scan the suffix now. + if !yaml_parser_scan_tag_uri(parser, false, nil, start_mark, &suffix) { + return false + } + } else { + // It wasn't a handle after all. Scan the rest of the tag. + if !yaml_parser_scan_tag_uri(parser, false, handle, start_mark, &suffix) { + return false + } + + // Set the handle to '!'. + handle = []byte{'!'} + + // A special case: the '!' tag. Set the handle to '' and the + // suffix to '!'. + if len(suffix) == 0 { + handle, suffix = suffix, handle + } + } + } + + // Check the character which ends the tag. + if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { + return false + } + if !is_blankz(parser.buffer, parser.buffer_pos) { + yaml_parser_set_scanner_error(parser, "while scanning a tag", + start_mark, "did not find expected whitespace or line break") + return false + } + + end_mark := parser.mark + + // Create a token. + *token = yaml_token_t{ + typ: yaml_TAG_TOKEN, + start_mark: start_mark, + end_mark: end_mark, + value: handle, + suffix: suffix, + } + return true +} + +// Scan a tag handle. +func yaml_parser_scan_tag_handle(parser *yaml_parser_t, directive bool, start_mark yaml_mark_t, handle *[]byte) bool { + // Check the initial '!' character. + if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { + return false + } + if parser.buffer[parser.buffer_pos] != '!' { + yaml_parser_set_scanner_tag_error(parser, directive, + start_mark, "did not find expected '!'") + return false + } + + var s []byte + + // Copy the '!' character. + s = read(parser, s) + + // Copy all subsequent alphabetical and numerical characters. + if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { + return false + } + for is_alpha(parser.buffer, parser.buffer_pos) { + s = read(parser, s) + if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { + return false + } + } + + // Check if the trailing character is '!' and copy it. + if parser.buffer[parser.buffer_pos] == '!' { + s = read(parser, s) + } else { + // It's either the '!' tag or not really a tag handle. If it's a %TAG + // directive, it's an error. If it's a tag token, it must be a part of URI. + if directive && string(s) != "!" { + yaml_parser_set_scanner_tag_error(parser, directive, + start_mark, "did not find expected '!'") + return false + } + } + + *handle = s + return true +} + +// Scan a tag. +func yaml_parser_scan_tag_uri(parser *yaml_parser_t, directive bool, head []byte, start_mark yaml_mark_t, uri *[]byte) bool { + //size_t length = head ? strlen((char *)head) : 0 + var s []byte + hasTag := len(head) > 0 + + // Copy the head if needed. + // + // Note that we don't copy the leading '!' character. + if len(head) > 1 { + s = append(s, head[1:]...) + } + + // Scan the tag. + if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { + return false + } + + // The set of characters that may appear in URI is as follows: + // + // '0'-'9', 'A'-'Z', 'a'-'z', '_', '-', ';', '/', '?', ':', '@', '&', + // '=', '+', '$', ',', '.', '!', '~', '*', '\'', '(', ')', '[', ']', + // '%'. + // [Go] TODO Convert this into more reasonable logic. + for is_alpha(parser.buffer, parser.buffer_pos) || parser.buffer[parser.buffer_pos] == ';' || + parser.buffer[parser.buffer_pos] == '/' || parser.buffer[parser.buffer_pos] == '?' || + parser.buffer[parser.buffer_pos] == ':' || parser.buffer[parser.buffer_pos] == '@' || + parser.buffer[parser.buffer_pos] == '&' || parser.buffer[parser.buffer_pos] == '=' || + parser.buffer[parser.buffer_pos] == '+' || parser.buffer[parser.buffer_pos] == '$' || + parser.buffer[parser.buffer_pos] == ',' || parser.buffer[parser.buffer_pos] == '.' || + parser.buffer[parser.buffer_pos] == '!' || parser.buffer[parser.buffer_pos] == '~' || + parser.buffer[parser.buffer_pos] == '*' || parser.buffer[parser.buffer_pos] == '\'' || + parser.buffer[parser.buffer_pos] == '(' || parser.buffer[parser.buffer_pos] == ')' || + parser.buffer[parser.buffer_pos] == '[' || parser.buffer[parser.buffer_pos] == ']' || + parser.buffer[parser.buffer_pos] == '%' { + // Check if it is a URI-escape sequence. + if parser.buffer[parser.buffer_pos] == '%' { + if !yaml_parser_scan_uri_escapes(parser, directive, start_mark, &s) { + return false + } + } else { + s = read(parser, s) + } + if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { + return false + } + hasTag = true + } + + if !hasTag { + yaml_parser_set_scanner_tag_error(parser, directive, + start_mark, "did not find expected tag URI") + return false + } + *uri = s + return true +} + +// Decode an URI-escape sequence corresponding to a single UTF-8 character. +func yaml_parser_scan_uri_escapes(parser *yaml_parser_t, directive bool, start_mark yaml_mark_t, s *[]byte) bool { + + // Decode the required number of characters. + w := 1024 + for w > 0 { + // Check for a URI-escaped octet. + if parser.unread < 3 && !yaml_parser_update_buffer(parser, 3) { + return false + } + + if !(parser.buffer[parser.buffer_pos] == '%' && + is_hex(parser.buffer, parser.buffer_pos+1) && + is_hex(parser.buffer, parser.buffer_pos+2)) { + return yaml_parser_set_scanner_tag_error(parser, directive, + start_mark, "did not find URI escaped octet") + } + + // Get the octet. + octet := byte((as_hex(parser.buffer, parser.buffer_pos+1) << 4) + as_hex(parser.buffer, parser.buffer_pos+2)) + + // If it is the leading octet, determine the length of the UTF-8 sequence. + if w == 1024 { + w = width(octet) + if w == 0 { + return yaml_parser_set_scanner_tag_error(parser, directive, + start_mark, "found an incorrect leading UTF-8 octet") + } + } else { + // Check if the trailing octet is correct. + if octet&0xC0 != 0x80 { + return yaml_parser_set_scanner_tag_error(parser, directive, + start_mark, "found an incorrect trailing UTF-8 octet") + } + } + + // Copy the octet and move the pointers. + *s = append(*s, octet) + skip(parser) + skip(parser) + skip(parser) + w-- + } + return true +} + +// Scan a block scalar. +func yaml_parser_scan_block_scalar(parser *yaml_parser_t, token *yaml_token_t, literal bool) bool { + // Eat the indicator '|' or '>'. + start_mark := parser.mark + skip(parser) + + // Scan the additional block scalar indicators. + if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { + return false + } + + // Check for a chomping indicator. + var chomping, increment int + if parser.buffer[parser.buffer_pos] == '+' || parser.buffer[parser.buffer_pos] == '-' { + // Set the chomping method and eat the indicator. + if parser.buffer[parser.buffer_pos] == '+' { + chomping = +1 + } else { + chomping = -1 + } + skip(parser) + + // Check for an indentation indicator. + if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { + return false + } + if is_digit(parser.buffer, parser.buffer_pos) { + // Check that the indentation is greater than 0. + if parser.buffer[parser.buffer_pos] == '0' { + yaml_parser_set_scanner_error(parser, "while scanning a block scalar", + start_mark, "found an indentation indicator equal to 0") + return false + } + + // Get the indentation level and eat the indicator. + increment = as_digit(parser.buffer, parser.buffer_pos) + skip(parser) + } + + } else if is_digit(parser.buffer, parser.buffer_pos) { + // Do the same as above, but in the opposite order. + + if parser.buffer[parser.buffer_pos] == '0' { + yaml_parser_set_scanner_error(parser, "while scanning a block scalar", + start_mark, "found an indentation indicator equal to 0") + return false + } + increment = as_digit(parser.buffer, parser.buffer_pos) + skip(parser) + + if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { + return false + } + if parser.buffer[parser.buffer_pos] == '+' || parser.buffer[parser.buffer_pos] == '-' { + if parser.buffer[parser.buffer_pos] == '+' { + chomping = +1 + } else { + chomping = -1 + } + skip(parser) + } + } + + // Eat whitespaces and comments to the end of the line. + if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { + return false + } + for is_blank(parser.buffer, parser.buffer_pos) { + skip(parser) + if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { + return false + } + } + if parser.buffer[parser.buffer_pos] == '#' { + if !yaml_parser_scan_line_comment(parser, start_mark) { + return false + } + for !is_breakz(parser.buffer, parser.buffer_pos) { + skip(parser) + if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { + return false + } + } + } + + // Check if we are at the end of the line. + if !is_breakz(parser.buffer, parser.buffer_pos) { + yaml_parser_set_scanner_error(parser, "while scanning a block scalar", + start_mark, "did not find expected comment or line break") + return false + } + + // Eat a line break. + if is_break(parser.buffer, parser.buffer_pos) { + if parser.unread < 2 && !yaml_parser_update_buffer(parser, 2) { + return false + } + skip_line(parser) + } + + end_mark := parser.mark + + // Set the indentation level if it was specified. + var indent int + if increment > 0 { + if parser.indent >= 0 { + indent = parser.indent + increment + } else { + indent = increment + } + } + + // Scan the leading line breaks and determine the indentation level if needed. + var s, leading_break, trailing_breaks []byte + if !yaml_parser_scan_block_scalar_breaks(parser, &indent, &trailing_breaks, start_mark, &end_mark) { + return false + } + + // Scan the block scalar content. + if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { + return false + } + var leading_blank, trailing_blank bool + for parser.mark.column == indent && !is_z(parser.buffer, parser.buffer_pos) { + // We are at the beginning of a non-empty line. + + // Is it a trailing whitespace? + trailing_blank = is_blank(parser.buffer, parser.buffer_pos) + + // Check if we need to fold the leading line break. + if !literal && !leading_blank && !trailing_blank && len(leading_break) > 0 && leading_break[0] == '\n' { + // Do we need to join the lines by space? + if len(trailing_breaks) == 0 { + s = append(s, ' ') + } + } else { + s = append(s, leading_break...) + } + leading_break = leading_break[:0] + + // Append the remaining line breaks. + s = append(s, trailing_breaks...) + trailing_breaks = trailing_breaks[:0] + + // Is it a leading whitespace? + leading_blank = is_blank(parser.buffer, parser.buffer_pos) + + // Consume the current line. + for !is_breakz(parser.buffer, parser.buffer_pos) { + s = read(parser, s) + if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { + return false + } + } + + // Consume the line break. + if parser.unread < 2 && !yaml_parser_update_buffer(parser, 2) { + return false + } + + leading_break = read_line(parser, leading_break) + + // Eat the following indentation spaces and line breaks. + if !yaml_parser_scan_block_scalar_breaks(parser, &indent, &trailing_breaks, start_mark, &end_mark) { + return false + } + } + + // Chomp the tail. + if chomping != -1 { + s = append(s, leading_break...) + } + if chomping == 1 { + s = append(s, trailing_breaks...) + } + + // Create a token. + *token = yaml_token_t{ + typ: yaml_SCALAR_TOKEN, + start_mark: start_mark, + end_mark: end_mark, + value: s, + style: yaml_LITERAL_SCALAR_STYLE, + } + if !literal { + token.style = yaml_FOLDED_SCALAR_STYLE + } + return true +} + +// Scan indentation spaces and line breaks for a block scalar. Determine the +// indentation level if needed. +func yaml_parser_scan_block_scalar_breaks(parser *yaml_parser_t, indent *int, breaks *[]byte, start_mark yaml_mark_t, end_mark *yaml_mark_t) bool { + *end_mark = parser.mark + + // Eat the indentation spaces and line breaks. + max_indent := 0 + for { + // Eat the indentation spaces. + if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { + return false + } + for (*indent == 0 || parser.mark.column < *indent) && is_space(parser.buffer, parser.buffer_pos) { + skip(parser) + if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { + return false + } + } + if parser.mark.column > max_indent { + max_indent = parser.mark.column + } + + // Check for a tab character messing the indentation. + if (*indent == 0 || parser.mark.column < *indent) && is_tab(parser.buffer, parser.buffer_pos) { + return yaml_parser_set_scanner_error(parser, "while scanning a block scalar", + start_mark, "found a tab character where an indentation space is expected") + } + + // Have we found a non-empty line? + if !is_break(parser.buffer, parser.buffer_pos) { + break + } + + // Consume the line break. + if parser.unread < 2 && !yaml_parser_update_buffer(parser, 2) { + return false + } + // [Go] Should really be returning breaks instead. + *breaks = read_line(parser, *breaks) + *end_mark = parser.mark + } + + // Determine the indentation level if needed. + if *indent == 0 { + *indent = max_indent + if *indent < parser.indent+1 { + *indent = parser.indent + 1 + } + if *indent < 1 { + *indent = 1 + } + } + return true +} + +// Scan a quoted scalar. +func yaml_parser_scan_flow_scalar(parser *yaml_parser_t, token *yaml_token_t, single bool) bool { + // Eat the left quote. + start_mark := parser.mark + skip(parser) + + // Consume the content of the quoted scalar. + var s, leading_break, trailing_breaks, whitespaces []byte + for { + // Check that there are no document indicators at the beginning of the line. + if parser.unread < 4 && !yaml_parser_update_buffer(parser, 4) { + return false + } + + if parser.mark.column == 0 && + ((parser.buffer[parser.buffer_pos+0] == '-' && + parser.buffer[parser.buffer_pos+1] == '-' && + parser.buffer[parser.buffer_pos+2] == '-') || + (parser.buffer[parser.buffer_pos+0] == '.' && + parser.buffer[parser.buffer_pos+1] == '.' && + parser.buffer[parser.buffer_pos+2] == '.')) && + is_blankz(parser.buffer, parser.buffer_pos+3) { + yaml_parser_set_scanner_error(parser, "while scanning a quoted scalar", + start_mark, "found unexpected document indicator") + return false + } + + // Check for EOF. + if is_z(parser.buffer, parser.buffer_pos) { + yaml_parser_set_scanner_error(parser, "while scanning a quoted scalar", + start_mark, "found unexpected end of stream") + return false + } + + // Consume non-blank characters. + leading_blanks := false + for !is_blankz(parser.buffer, parser.buffer_pos) { + if single && parser.buffer[parser.buffer_pos] == '\'' && parser.buffer[parser.buffer_pos+1] == '\'' { + // Is is an escaped single quote. + s = append(s, '\'') + skip(parser) + skip(parser) + + } else if single && parser.buffer[parser.buffer_pos] == '\'' { + // It is a right single quote. + break + } else if !single && parser.buffer[parser.buffer_pos] == '"' { + // It is a right double quote. + break + + } else if !single && parser.buffer[parser.buffer_pos] == '\\' && is_break(parser.buffer, parser.buffer_pos+1) { + // It is an escaped line break. + if parser.unread < 3 && !yaml_parser_update_buffer(parser, 3) { + return false + } + skip(parser) + skip_line(parser) + leading_blanks = true + break + + } else if !single && parser.buffer[parser.buffer_pos] == '\\' { + // It is an escape sequence. + code_length := 0 + + // Check the escape character. + switch parser.buffer[parser.buffer_pos+1] { + case '0': + s = append(s, 0) + case 'a': + s = append(s, '\x07') + case 'b': + s = append(s, '\x08') + case 't', '\t': + s = append(s, '\x09') + case 'n': + s = append(s, '\x0A') + case 'v': + s = append(s, '\x0B') + case 'f': + s = append(s, '\x0C') + case 'r': + s = append(s, '\x0D') + case 'e': + s = append(s, '\x1B') + case ' ': + s = append(s, '\x20') + case '"': + s = append(s, '"') + case '\'': + s = append(s, '\'') + case '\\': + s = append(s, '\\') + case 'N': // NEL (#x85) + s = append(s, '\xC2') + s = append(s, '\x85') + case '_': // #xA0 + s = append(s, '\xC2') + s = append(s, '\xA0') + case 'L': // LS (#x2028) + s = append(s, '\xE2') + s = append(s, '\x80') + s = append(s, '\xA8') + case 'P': // PS (#x2029) + s = append(s, '\xE2') + s = append(s, '\x80') + s = append(s, '\xA9') + case 'x': + code_length = 2 + case 'u': + code_length = 4 + case 'U': + code_length = 8 + default: + yaml_parser_set_scanner_error(parser, "while parsing a quoted scalar", + start_mark, "found unknown escape character") + return false + } + + skip(parser) + skip(parser) + + // Consume an arbitrary escape code. + if code_length > 0 { + var value int + + // Scan the character value. + if parser.unread < code_length && !yaml_parser_update_buffer(parser, code_length) { + return false + } + for k := 0; k < code_length; k++ { + if !is_hex(parser.buffer, parser.buffer_pos+k) { + yaml_parser_set_scanner_error(parser, "while parsing a quoted scalar", + start_mark, "did not find expected hexdecimal number") + return false + } + value = (value << 4) + as_hex(parser.buffer, parser.buffer_pos+k) + } + + // Check the value and write the character. + if (value >= 0xD800 && value <= 0xDFFF) || value > 0x10FFFF { + yaml_parser_set_scanner_error(parser, "while parsing a quoted scalar", + start_mark, "found invalid Unicode character escape code") + return false + } + if value <= 0x7F { + s = append(s, byte(value)) + } else if value <= 0x7FF { + s = append(s, byte(0xC0+(value>>6))) + s = append(s, byte(0x80+(value&0x3F))) + } else if value <= 0xFFFF { + s = append(s, byte(0xE0+(value>>12))) + s = append(s, byte(0x80+((value>>6)&0x3F))) + s = append(s, byte(0x80+(value&0x3F))) + } else { + s = append(s, byte(0xF0+(value>>18))) + s = append(s, byte(0x80+((value>>12)&0x3F))) + s = append(s, byte(0x80+((value>>6)&0x3F))) + s = append(s, byte(0x80+(value&0x3F))) + } + + // Advance the pointer. + for k := 0; k < code_length; k++ { + skip(parser) + } + } + } else { + // It is a non-escaped non-blank character. + s = read(parser, s) + } + if parser.unread < 2 && !yaml_parser_update_buffer(parser, 2) { + return false + } + } + + if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { + return false + } + + // Check if we are at the end of the scalar. + if single { + if parser.buffer[parser.buffer_pos] == '\'' { + break + } + } else { + if parser.buffer[parser.buffer_pos] == '"' { + break + } + } + + // Consume blank characters. + for is_blank(parser.buffer, parser.buffer_pos) || is_break(parser.buffer, parser.buffer_pos) { + if is_blank(parser.buffer, parser.buffer_pos) { + // Consume a space or a tab character. + if !leading_blanks { + whitespaces = read(parser, whitespaces) + } else { + skip(parser) + } + } else { + if parser.unread < 2 && !yaml_parser_update_buffer(parser, 2) { + return false + } + + // Check if it is a first line break. + if !leading_blanks { + whitespaces = whitespaces[:0] + leading_break = read_line(parser, leading_break) + leading_blanks = true + } else { + trailing_breaks = read_line(parser, trailing_breaks) + } + } + if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { + return false + } + } + + // Join the whitespaces or fold line breaks. + if leading_blanks { + // Do we need to fold line breaks? + if len(leading_break) > 0 && leading_break[0] == '\n' { + if len(trailing_breaks) == 0 { + s = append(s, ' ') + } else { + s = append(s, trailing_breaks...) + } + } else { + s = append(s, leading_break...) + s = append(s, trailing_breaks...) + } + trailing_breaks = trailing_breaks[:0] + leading_break = leading_break[:0] + } else { + s = append(s, whitespaces...) + whitespaces = whitespaces[:0] + } + } + + // Eat the right quote. + skip(parser) + end_mark := parser.mark + + // Create a token. + *token = yaml_token_t{ + typ: yaml_SCALAR_TOKEN, + start_mark: start_mark, + end_mark: end_mark, + value: s, + style: yaml_SINGLE_QUOTED_SCALAR_STYLE, + } + if !single { + token.style = yaml_DOUBLE_QUOTED_SCALAR_STYLE + } + return true +} + +// Scan a plain scalar. +func yaml_parser_scan_plain_scalar(parser *yaml_parser_t, token *yaml_token_t) bool { + + var s, leading_break, trailing_breaks, whitespaces []byte + var leading_blanks bool + var indent = parser.indent + 1 + + start_mark := parser.mark + end_mark := parser.mark + + // Consume the content of the plain scalar. + for { + // Check for a document indicator. + if parser.unread < 4 && !yaml_parser_update_buffer(parser, 4) { + return false + } + if parser.mark.column == 0 && + ((parser.buffer[parser.buffer_pos+0] == '-' && + parser.buffer[parser.buffer_pos+1] == '-' && + parser.buffer[parser.buffer_pos+2] == '-') || + (parser.buffer[parser.buffer_pos+0] == '.' && + parser.buffer[parser.buffer_pos+1] == '.' && + parser.buffer[parser.buffer_pos+2] == '.')) && + is_blankz(parser.buffer, parser.buffer_pos+3) { + break + } + + // Check for a comment. + if parser.buffer[parser.buffer_pos] == '#' { + break + } + + // Consume non-blank characters. + for !is_blankz(parser.buffer, parser.buffer_pos) { + + // Check for indicators that may end a plain scalar. + if (parser.buffer[parser.buffer_pos] == ':' && is_blankz(parser.buffer, parser.buffer_pos+1)) || + (parser.flow_level > 0 && + (parser.buffer[parser.buffer_pos] == ',' || + parser.buffer[parser.buffer_pos] == '?' || parser.buffer[parser.buffer_pos] == '[' || + parser.buffer[parser.buffer_pos] == ']' || parser.buffer[parser.buffer_pos] == '{' || + parser.buffer[parser.buffer_pos] == '}')) { + break + } + + // Check if we need to join whitespaces and breaks. + if leading_blanks || len(whitespaces) > 0 { + if leading_blanks { + // Do we need to fold line breaks? + if leading_break[0] == '\n' { + if len(trailing_breaks) == 0 { + s = append(s, ' ') + } else { + s = append(s, trailing_breaks...) + } + } else { + s = append(s, leading_break...) + s = append(s, trailing_breaks...) + } + trailing_breaks = trailing_breaks[:0] + leading_break = leading_break[:0] + leading_blanks = false + } else { + s = append(s, whitespaces...) + whitespaces = whitespaces[:0] + } + } + + // Copy the character. + s = read(parser, s) + + end_mark = parser.mark + if parser.unread < 2 && !yaml_parser_update_buffer(parser, 2) { + return false + } + } + + // Is it the end? + if !(is_blank(parser.buffer, parser.buffer_pos) || is_break(parser.buffer, parser.buffer_pos)) { + break + } + + // Consume blank characters. + if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { + return false + } + + for is_blank(parser.buffer, parser.buffer_pos) || is_break(parser.buffer, parser.buffer_pos) { + if is_blank(parser.buffer, parser.buffer_pos) { + + // Check for tab characters that abuse indentation. + if leading_blanks && parser.mark.column < indent && is_tab(parser.buffer, parser.buffer_pos) { + yaml_parser_set_scanner_error(parser, "while scanning a plain scalar", + start_mark, "found a tab character that violates indentation") + return false + } + + // Consume a space or a tab character. + if !leading_blanks { + whitespaces = read(parser, whitespaces) + } else { + skip(parser) + } + } else { + if parser.unread < 2 && !yaml_parser_update_buffer(parser, 2) { + return false + } + + // Check if it is a first line break. + if !leading_blanks { + whitespaces = whitespaces[:0] + leading_break = read_line(parser, leading_break) + leading_blanks = true + } else { + trailing_breaks = read_line(parser, trailing_breaks) + } + } + if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { + return false + } + } + + // Check indentation level. + if parser.flow_level == 0 && parser.mark.column < indent { + break + } + } + + // Create a token. + *token = yaml_token_t{ + typ: yaml_SCALAR_TOKEN, + start_mark: start_mark, + end_mark: end_mark, + value: s, + style: yaml_PLAIN_SCALAR_STYLE, + } + + // Note that we change the 'simple_key_allowed' flag. + if leading_blanks { + parser.simple_key_allowed = true + } + return true +} + +func yaml_parser_scan_line_comment(parser *yaml_parser_t, token_mark yaml_mark_t) bool { + if parser.newlines > 0 { + return true + } + + var start_mark yaml_mark_t + var text []byte + + for peek := 0; peek < 512; peek++ { + if parser.unread < peek+1 && !yaml_parser_update_buffer(parser, peek+1) { + break + } + if is_blank(parser.buffer, parser.buffer_pos+peek) { + continue + } + if parser.buffer[parser.buffer_pos+peek] == '#' { + seen := parser.mark.index + peek + for { + if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { + return false + } + if is_breakz(parser.buffer, parser.buffer_pos) { + if parser.mark.index >= seen { + break + } + if parser.unread < 2 && !yaml_parser_update_buffer(parser, 2) { + return false + } + skip_line(parser) + } else if parser.mark.index >= seen { + if len(text) == 0 { + start_mark = parser.mark + } + text = read(parser, text) + } else { + skip(parser) + } + } + } + break + } + if len(text) > 0 { + parser.comments = append(parser.comments, yaml_comment_t{ + token_mark: token_mark, + start_mark: start_mark, + line: text, + }) + } + return true +} + +func yaml_parser_scan_comments(parser *yaml_parser_t, scan_mark yaml_mark_t) bool { + token := parser.tokens[len(parser.tokens)-1] + + if token.typ == yaml_FLOW_ENTRY_TOKEN && len(parser.tokens) > 1 { + token = parser.tokens[len(parser.tokens)-2] + } + + var token_mark = token.start_mark + var start_mark yaml_mark_t + var next_indent = parser.indent + if next_indent < 0 { + next_indent = 0 + } + + var recent_empty = false + var first_empty = parser.newlines <= 1 + + var line = parser.mark.line + var column = parser.mark.column + + var text []byte + + // The foot line is the place where a comment must start to + // still be considered as a foot of the prior content. + // If there's some content in the currently parsed line, then + // the foot is the line below it. + var foot_line = -1 + if scan_mark.line > 0 { + foot_line = parser.mark.line - parser.newlines + 1 + if parser.newlines == 0 && parser.mark.column > 1 { + foot_line++ + } + } + + var peek = 0 + for ; peek < 512; peek++ { + if parser.unread < peek+1 && !yaml_parser_update_buffer(parser, peek+1) { + break + } + column++ + if is_blank(parser.buffer, parser.buffer_pos+peek) { + continue + } + c := parser.buffer[parser.buffer_pos+peek] + var close_flow = parser.flow_level > 0 && (c == ']' || c == '}') + if close_flow || is_breakz(parser.buffer, parser.buffer_pos+peek) { + // Got line break or terminator. + if close_flow || !recent_empty { + if close_flow || first_empty && (start_mark.line == foot_line && token.typ != yaml_VALUE_TOKEN || start_mark.column-1 < next_indent) { + // This is the first empty line and there were no empty lines before, + // so this initial part of the comment is a foot of the prior token + // instead of being a head for the following one. Split it up. + // Alternatively, this might also be the last comment inside a flow + // scope, so it must be a footer. + if len(text) > 0 { + if start_mark.column-1 < next_indent { + // If dedented it's unrelated to the prior token. + token_mark = start_mark + } + parser.comments = append(parser.comments, yaml_comment_t{ + scan_mark: scan_mark, + token_mark: token_mark, + start_mark: start_mark, + end_mark: yaml_mark_t{parser.mark.index + peek, line, column}, + foot: text, + }) + scan_mark = yaml_mark_t{parser.mark.index + peek, line, column} + token_mark = scan_mark + text = nil + } + } else { + if len(text) > 0 && parser.buffer[parser.buffer_pos+peek] != 0 { + text = append(text, '\n') + } + } + } + if !is_break(parser.buffer, parser.buffer_pos+peek) { + break + } + first_empty = false + recent_empty = true + column = 0 + line++ + continue + } + + if len(text) > 0 && (close_flow || column-1 < next_indent && column != start_mark.column) { + // The comment at the different indentation is a foot of the + // preceding data rather than a head of the upcoming one. + parser.comments = append(parser.comments, yaml_comment_t{ + scan_mark: scan_mark, + token_mark: token_mark, + start_mark: start_mark, + end_mark: yaml_mark_t{parser.mark.index + peek, line, column}, + foot: text, + }) + scan_mark = yaml_mark_t{parser.mark.index + peek, line, column} + token_mark = scan_mark + text = nil + } + + if parser.buffer[parser.buffer_pos+peek] != '#' { + break + } + + if len(text) == 0 { + start_mark = yaml_mark_t{parser.mark.index + peek, line, column} + } else { + text = append(text, '\n') + } + + recent_empty = false + + // Consume until after the consumed comment line. + seen := parser.mark.index + peek + for { + if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { + return false + } + if is_breakz(parser.buffer, parser.buffer_pos) { + if parser.mark.index >= seen { + break + } + if parser.unread < 2 && !yaml_parser_update_buffer(parser, 2) { + return false + } + skip_line(parser) + } else if parser.mark.index >= seen { + text = read(parser, text) + } else { + skip(parser) + } + } + + peek = 0 + column = 0 + line = parser.mark.line + next_indent = parser.indent + if next_indent < 0 { + next_indent = 0 + } + } + + if len(text) > 0 { + parser.comments = append(parser.comments, yaml_comment_t{ + scan_mark: scan_mark, + token_mark: start_mark, + start_mark: start_mark, + end_mark: yaml_mark_t{parser.mark.index + peek - 1, line, column}, + head: text, + }) + } + return true +} diff --git a/vendor/go.yaml.in/yaml/v3/sorter.go b/vendor/go.yaml.in/yaml/v3/sorter.go new file mode 100644 index 000000000..9210ece7e --- /dev/null +++ b/vendor/go.yaml.in/yaml/v3/sorter.go @@ -0,0 +1,134 @@ +// +// Copyright (c) 2011-2019 Canonical Ltd +// +// 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. + +package yaml + +import ( + "reflect" + "unicode" +) + +type keyList []reflect.Value + +func (l keyList) Len() int { return len(l) } +func (l keyList) Swap(i, j int) { l[i], l[j] = l[j], l[i] } +func (l keyList) Less(i, j int) bool { + a := l[i] + b := l[j] + ak := a.Kind() + bk := b.Kind() + for (ak == reflect.Interface || ak == reflect.Ptr) && !a.IsNil() { + a = a.Elem() + ak = a.Kind() + } + for (bk == reflect.Interface || bk == reflect.Ptr) && !b.IsNil() { + b = b.Elem() + bk = b.Kind() + } + af, aok := keyFloat(a) + bf, bok := keyFloat(b) + if aok && bok { + if af != bf { + return af < bf + } + if ak != bk { + return ak < bk + } + return numLess(a, b) + } + if ak != reflect.String || bk != reflect.String { + return ak < bk + } + ar, br := []rune(a.String()), []rune(b.String()) + digits := false + for i := 0; i < len(ar) && i < len(br); i++ { + if ar[i] == br[i] { + digits = unicode.IsDigit(ar[i]) + continue + } + al := unicode.IsLetter(ar[i]) + bl := unicode.IsLetter(br[i]) + if al && bl { + return ar[i] < br[i] + } + if al || bl { + if digits { + return al + } else { + return bl + } + } + var ai, bi int + var an, bn int64 + if ar[i] == '0' || br[i] == '0' { + for j := i - 1; j >= 0 && unicode.IsDigit(ar[j]); j-- { + if ar[j] != '0' { + an = 1 + bn = 1 + break + } + } + } + for ai = i; ai < len(ar) && unicode.IsDigit(ar[ai]); ai++ { + an = an*10 + int64(ar[ai]-'0') + } + for bi = i; bi < len(br) && unicode.IsDigit(br[bi]); bi++ { + bn = bn*10 + int64(br[bi]-'0') + } + if an != bn { + return an < bn + } + if ai != bi { + return ai < bi + } + return ar[i] < br[i] + } + return len(ar) < len(br) +} + +// keyFloat returns a float value for v if it is a number/bool +// and whether it is a number/bool or not. +func keyFloat(v reflect.Value) (f float64, ok bool) { + switch v.Kind() { + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + return float64(v.Int()), true + case reflect.Float32, reflect.Float64: + return v.Float(), true + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: + return float64(v.Uint()), true + case reflect.Bool: + if v.Bool() { + return 1, true + } + return 0, true + } + return 0, false +} + +// numLess returns whether a < b. +// a and b must necessarily have the same kind. +func numLess(a, b reflect.Value) bool { + switch a.Kind() { + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + return a.Int() < b.Int() + case reflect.Float32, reflect.Float64: + return a.Float() < b.Float() + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: + return a.Uint() < b.Uint() + case reflect.Bool: + return !a.Bool() && b.Bool() + } + panic("not a number") +} diff --git a/vendor/go.yaml.in/yaml/v3/writerc.go b/vendor/go.yaml.in/yaml/v3/writerc.go new file mode 100644 index 000000000..266d0b092 --- /dev/null +++ b/vendor/go.yaml.in/yaml/v3/writerc.go @@ -0,0 +1,48 @@ +// +// Copyright (c) 2011-2019 Canonical Ltd +// Copyright (c) 2006-2010 Kirill Simonov +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of +// this software and associated documentation files (the "Software"), to deal in +// the Software without restriction, including without limitation the rights to +// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +// of the Software, and to permit persons to whom the Software is furnished to do +// so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +package yaml + +// Set the writer error and return false. +func yaml_emitter_set_writer_error(emitter *yaml_emitter_t, problem string) bool { + emitter.error = yaml_WRITER_ERROR + emitter.problem = problem + return false +} + +// Flush the output buffer. +func yaml_emitter_flush(emitter *yaml_emitter_t) bool { + if emitter.write_handler == nil { + panic("write handler not set") + } + + // Check if the buffer is empty. + if emitter.buffer_pos == 0 { + return true + } + + if err := emitter.write_handler(emitter, emitter.buffer[:emitter.buffer_pos]); err != nil { + return yaml_emitter_set_writer_error(emitter, "write error: "+err.Error()) + } + emitter.buffer_pos = 0 + return true +} diff --git a/vendor/go.yaml.in/yaml/v3/yaml.go b/vendor/go.yaml.in/yaml/v3/yaml.go new file mode 100644 index 000000000..0b101cd20 --- /dev/null +++ b/vendor/go.yaml.in/yaml/v3/yaml.go @@ -0,0 +1,703 @@ +// +// Copyright (c) 2011-2019 Canonical Ltd +// +// 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. + +// Package yaml implements YAML support for the Go language. +// +// Source code and other details for the project are available at GitHub: +// +// https://github.com/yaml/go-yaml +package yaml + +import ( + "errors" + "fmt" + "io" + "reflect" + "strings" + "sync" + "unicode/utf8" +) + +// The Unmarshaler interface may be implemented by types to customize their +// behavior when being unmarshaled from a YAML document. +type Unmarshaler interface { + UnmarshalYAML(value *Node) error +} + +type obsoleteUnmarshaler interface { + UnmarshalYAML(unmarshal func(interface{}) error) error +} + +// The Marshaler interface may be implemented by types to customize their +// behavior when being marshaled into a YAML document. The returned value +// is marshaled in place of the original value implementing Marshaler. +// +// If an error is returned by MarshalYAML, the marshaling procedure stops +// and returns with the provided error. +type Marshaler interface { + MarshalYAML() (interface{}, error) +} + +// Unmarshal decodes the first document found within the in byte slice +// and assigns decoded values into the out value. +// +// Maps and pointers (to a struct, string, int, etc) are accepted as out +// values. If an internal pointer within a struct is not initialized, +// the yaml package will initialize it if necessary for unmarshalling +// the provided data. The out parameter must not be nil. +// +// The type of the decoded values should be compatible with the respective +// values in out. If one or more values cannot be decoded due to a type +// mismatches, decoding continues partially until the end of the YAML +// content, and a *yaml.TypeError is returned with details for all +// missed values. +// +// Struct fields are only unmarshalled if they are exported (have an +// upper case first letter), and are unmarshalled using the field name +// lowercased as the default key. Custom keys may be defined via the +// "yaml" name in the field tag: the content preceding the first comma +// is used as the key, and the following comma-separated options are +// used to tweak the marshalling process (see Marshal). +// Conflicting names result in a runtime error. +// +// For example: +// +// type T struct { +// F int `yaml:"a,omitempty"` +// B int +// } +// var t T +// yaml.Unmarshal([]byte("a: 1\nb: 2"), &t) +// +// See the documentation of Marshal for the format of tags and a list of +// supported tag options. +func Unmarshal(in []byte, out interface{}) (err error) { + return unmarshal(in, out, false) +} + +// A Decoder reads and decodes YAML values from an input stream. +type Decoder struct { + parser *parser + knownFields bool +} + +// NewDecoder returns a new decoder that reads from r. +// +// The decoder introduces its own buffering and may read +// data from r beyond the YAML values requested. +func NewDecoder(r io.Reader) *Decoder { + return &Decoder{ + parser: newParserFromReader(r), + } +} + +// KnownFields ensures that the keys in decoded mappings to +// exist as fields in the struct being decoded into. +func (dec *Decoder) KnownFields(enable bool) { + dec.knownFields = enable +} + +// Decode reads the next YAML-encoded value from its input +// and stores it in the value pointed to by v. +// +// See the documentation for Unmarshal for details about the +// conversion of YAML into a Go value. +func (dec *Decoder) Decode(v interface{}) (err error) { + d := newDecoder() + d.knownFields = dec.knownFields + defer handleErr(&err) + node := dec.parser.parse() + if node == nil { + return io.EOF + } + out := reflect.ValueOf(v) + if out.Kind() == reflect.Ptr && !out.IsNil() { + out = out.Elem() + } + d.unmarshal(node, out) + if len(d.terrors) > 0 { + return &TypeError{d.terrors} + } + return nil +} + +// Decode decodes the node and stores its data into the value pointed to by v. +// +// See the documentation for Unmarshal for details about the +// conversion of YAML into a Go value. +func (n *Node) Decode(v interface{}) (err error) { + d := newDecoder() + defer handleErr(&err) + out := reflect.ValueOf(v) + if out.Kind() == reflect.Ptr && !out.IsNil() { + out = out.Elem() + } + d.unmarshal(n, out) + if len(d.terrors) > 0 { + return &TypeError{d.terrors} + } + return nil +} + +func unmarshal(in []byte, out interface{}, strict bool) (err error) { + defer handleErr(&err) + d := newDecoder() + p := newParser(in) + defer p.destroy() + node := p.parse() + if node != nil { + v := reflect.ValueOf(out) + if v.Kind() == reflect.Ptr && !v.IsNil() { + v = v.Elem() + } + d.unmarshal(node, v) + } + if len(d.terrors) > 0 { + return &TypeError{d.terrors} + } + return nil +} + +// Marshal serializes the value provided into a YAML document. The structure +// of the generated document will reflect the structure of the value itself. +// Maps and pointers (to struct, string, int, etc) are accepted as the in value. +// +// Struct fields are only marshalled if they are exported (have an upper case +// first letter), and are marshalled using the field name lowercased as the +// default key. Custom keys may be defined via the "yaml" name in the field +// tag: the content preceding the first comma is used as the key, and the +// following comma-separated options are used to tweak the marshalling process. +// Conflicting names result in a runtime error. +// +// The field tag format accepted is: +// +// `(...) yaml:"[][,[,]]" (...)` +// +// The following flags are currently supported: +// +// omitempty Only include the field if it's not set to the zero +// value for the type or to empty slices or maps. +// Zero valued structs will be omitted if all their public +// fields are zero, unless they implement an IsZero +// method (see the IsZeroer interface type), in which +// case the field will be excluded if IsZero returns true. +// +// flow Marshal using a flow style (useful for structs, +// sequences and maps). +// +// inline Inline the field, which must be a struct or a map, +// causing all of its fields or keys to be processed as if +// they were part of the outer struct. For maps, keys must +// not conflict with the yaml keys of other struct fields. +// +// In addition, if the key is "-", the field is ignored. +// +// For example: +// +// type T struct { +// F int `yaml:"a,omitempty"` +// B int +// } +// yaml.Marshal(&T{B: 2}) // Returns "b: 2\n" +// yaml.Marshal(&T{F: 1}} // Returns "a: 1\nb: 0\n" +func Marshal(in interface{}) (out []byte, err error) { + defer handleErr(&err) + e := newEncoder() + defer e.destroy() + e.marshalDoc("", reflect.ValueOf(in)) + e.finish() + out = e.out + return +} + +// An Encoder writes YAML values to an output stream. +type Encoder struct { + encoder *encoder +} + +// NewEncoder returns a new encoder that writes to w. +// The Encoder should be closed after use to flush all data +// to w. +func NewEncoder(w io.Writer) *Encoder { + return &Encoder{ + encoder: newEncoderWithWriter(w), + } +} + +// Encode writes the YAML encoding of v to the stream. +// If multiple items are encoded to the stream, the +// second and subsequent document will be preceded +// with a "---" document separator, but the first will not. +// +// See the documentation for Marshal for details about the conversion of Go +// values to YAML. +func (e *Encoder) Encode(v interface{}) (err error) { + defer handleErr(&err) + e.encoder.marshalDoc("", reflect.ValueOf(v)) + return nil +} + +// Encode encodes value v and stores its representation in n. +// +// See the documentation for Marshal for details about the +// conversion of Go values into YAML. +func (n *Node) Encode(v interface{}) (err error) { + defer handleErr(&err) + e := newEncoder() + defer e.destroy() + e.marshalDoc("", reflect.ValueOf(v)) + e.finish() + p := newParser(e.out) + p.textless = true + defer p.destroy() + doc := p.parse() + *n = *doc.Content[0] + return nil +} + +// SetIndent changes the used indentation used when encoding. +func (e *Encoder) SetIndent(spaces int) { + if spaces < 0 { + panic("yaml: cannot indent to a negative number of spaces") + } + e.encoder.indent = spaces +} + +// CompactSeqIndent makes it so that '- ' is considered part of the indentation. +func (e *Encoder) CompactSeqIndent() { + e.encoder.emitter.compact_sequence_indent = true +} + +// DefaultSeqIndent makes it so that '- ' is not considered part of the indentation. +func (e *Encoder) DefaultSeqIndent() { + e.encoder.emitter.compact_sequence_indent = false +} + +// Close closes the encoder by writing any remaining data. +// It does not write a stream terminating string "...". +func (e *Encoder) Close() (err error) { + defer handleErr(&err) + e.encoder.finish() + return nil +} + +func handleErr(err *error) { + if v := recover(); v != nil { + if e, ok := v.(yamlError); ok { + *err = e.err + } else { + panic(v) + } + } +} + +type yamlError struct { + err error +} + +func fail(err error) { + panic(yamlError{err}) +} + +func failf(format string, args ...interface{}) { + panic(yamlError{fmt.Errorf("yaml: "+format, args...)}) +} + +// A TypeError is returned by Unmarshal when one or more fields in +// the YAML document cannot be properly decoded into the requested +// types. When this error is returned, the value is still +// unmarshaled partially. +type TypeError struct { + Errors []string +} + +func (e *TypeError) Error() string { + return fmt.Sprintf("yaml: unmarshal errors:\n %s", strings.Join(e.Errors, "\n ")) +} + +type Kind uint32 + +const ( + DocumentNode Kind = 1 << iota + SequenceNode + MappingNode + ScalarNode + AliasNode +) + +type Style uint32 + +const ( + TaggedStyle Style = 1 << iota + DoubleQuotedStyle + SingleQuotedStyle + LiteralStyle + FoldedStyle + FlowStyle +) + +// Node represents an element in the YAML document hierarchy. While documents +// are typically encoded and decoded into higher level types, such as structs +// and maps, Node is an intermediate representation that allows detailed +// control over the content being decoded or encoded. +// +// It's worth noting that although Node offers access into details such as +// line numbers, colums, and comments, the content when re-encoded will not +// have its original textual representation preserved. An effort is made to +// render the data plesantly, and to preserve comments near the data they +// describe, though. +// +// Values that make use of the Node type interact with the yaml package in the +// same way any other type would do, by encoding and decoding yaml data +// directly or indirectly into them. +// +// For example: +// +// var person struct { +// Name string +// Address yaml.Node +// } +// err := yaml.Unmarshal(data, &person) +// +// Or by itself: +// +// var person Node +// err := yaml.Unmarshal(data, &person) +type Node struct { + // Kind defines whether the node is a document, a mapping, a sequence, + // a scalar value, or an alias to another node. The specific data type of + // scalar nodes may be obtained via the ShortTag and LongTag methods. + Kind Kind + + // Style allows customizing the apperance of the node in the tree. + Style Style + + // Tag holds the YAML tag defining the data type for the value. + // When decoding, this field will always be set to the resolved tag, + // even when it wasn't explicitly provided in the YAML content. + // When encoding, if this field is unset the value type will be + // implied from the node properties, and if it is set, it will only + // be serialized into the representation if TaggedStyle is used or + // the implicit tag diverges from the provided one. + Tag string + + // Value holds the unescaped and unquoted represenation of the value. + Value string + + // Anchor holds the anchor name for this node, which allows aliases to point to it. + Anchor string + + // Alias holds the node that this alias points to. Only valid when Kind is AliasNode. + Alias *Node + + // Content holds contained nodes for documents, mappings, and sequences. + Content []*Node + + // HeadComment holds any comments in the lines preceding the node and + // not separated by an empty line. + HeadComment string + + // LineComment holds any comments at the end of the line where the node is in. + LineComment string + + // FootComment holds any comments following the node and before empty lines. + FootComment string + + // Line and Column hold the node position in the decoded YAML text. + // These fields are not respected when encoding the node. + Line int + Column int +} + +// IsZero returns whether the node has all of its fields unset. +func (n *Node) IsZero() bool { + return n.Kind == 0 && n.Style == 0 && n.Tag == "" && n.Value == "" && n.Anchor == "" && n.Alias == nil && n.Content == nil && + n.HeadComment == "" && n.LineComment == "" && n.FootComment == "" && n.Line == 0 && n.Column == 0 +} + +// LongTag returns the long form of the tag that indicates the data type for +// the node. If the Tag field isn't explicitly defined, one will be computed +// based on the node properties. +func (n *Node) LongTag() string { + return longTag(n.ShortTag()) +} + +// ShortTag returns the short form of the YAML tag that indicates data type for +// the node. If the Tag field isn't explicitly defined, one will be computed +// based on the node properties. +func (n *Node) ShortTag() string { + if n.indicatedString() { + return strTag + } + if n.Tag == "" || n.Tag == "!" { + switch n.Kind { + case MappingNode: + return mapTag + case SequenceNode: + return seqTag + case AliasNode: + if n.Alias != nil { + return n.Alias.ShortTag() + } + case ScalarNode: + tag, _ := resolve("", n.Value) + return tag + case 0: + // Special case to make the zero value convenient. + if n.IsZero() { + return nullTag + } + } + return "" + } + return shortTag(n.Tag) +} + +func (n *Node) indicatedString() bool { + return n.Kind == ScalarNode && + (shortTag(n.Tag) == strTag || + (n.Tag == "" || n.Tag == "!") && n.Style&(SingleQuotedStyle|DoubleQuotedStyle|LiteralStyle|FoldedStyle) != 0) +} + +// SetString is a convenience function that sets the node to a string value +// and defines its style in a pleasant way depending on its content. +func (n *Node) SetString(s string) { + n.Kind = ScalarNode + if utf8.ValidString(s) { + n.Value = s + n.Tag = strTag + } else { + n.Value = encodeBase64(s) + n.Tag = binaryTag + } + if strings.Contains(n.Value, "\n") { + n.Style = LiteralStyle + } +} + +// -------------------------------------------------------------------------- +// Maintain a mapping of keys to structure field indexes + +// The code in this section was copied from mgo/bson. + +// structInfo holds details for the serialization of fields of +// a given struct. +type structInfo struct { + FieldsMap map[string]fieldInfo + FieldsList []fieldInfo + + // InlineMap is the number of the field in the struct that + // contains an ,inline map, or -1 if there's none. + InlineMap int + + // InlineUnmarshalers holds indexes to inlined fields that + // contain unmarshaler values. + InlineUnmarshalers [][]int +} + +type fieldInfo struct { + Key string + Num int + OmitEmpty bool + Flow bool + // Id holds the unique field identifier, so we can cheaply + // check for field duplicates without maintaining an extra map. + Id int + + // Inline holds the field index if the field is part of an inlined struct. + Inline []int +} + +var structMap = make(map[reflect.Type]*structInfo) +var fieldMapMutex sync.RWMutex +var unmarshalerType reflect.Type + +func init() { + var v Unmarshaler + unmarshalerType = reflect.ValueOf(&v).Elem().Type() +} + +func getStructInfo(st reflect.Type) (*structInfo, error) { + fieldMapMutex.RLock() + sinfo, found := structMap[st] + fieldMapMutex.RUnlock() + if found { + return sinfo, nil + } + + n := st.NumField() + fieldsMap := make(map[string]fieldInfo) + fieldsList := make([]fieldInfo, 0, n) + inlineMap := -1 + inlineUnmarshalers := [][]int(nil) + for i := 0; i != n; i++ { + field := st.Field(i) + if field.PkgPath != "" && !field.Anonymous { + continue // Private field + } + + info := fieldInfo{Num: i} + + tag := field.Tag.Get("yaml") + if tag == "" && strings.Index(string(field.Tag), ":") < 0 { + tag = string(field.Tag) + } + if tag == "-" { + continue + } + + inline := false + fields := strings.Split(tag, ",") + if len(fields) > 1 { + for _, flag := range fields[1:] { + switch flag { + case "omitempty": + info.OmitEmpty = true + case "flow": + info.Flow = true + case "inline": + inline = true + default: + return nil, errors.New(fmt.Sprintf("unsupported flag %q in tag %q of type %s", flag, tag, st)) + } + } + tag = fields[0] + } + + if inline { + switch field.Type.Kind() { + case reflect.Map: + if inlineMap >= 0 { + return nil, errors.New("multiple ,inline maps in struct " + st.String()) + } + if field.Type.Key() != reflect.TypeOf("") { + return nil, errors.New("option ,inline needs a map with string keys in struct " + st.String()) + } + inlineMap = info.Num + case reflect.Struct, reflect.Ptr: + ftype := field.Type + for ftype.Kind() == reflect.Ptr { + ftype = ftype.Elem() + } + if ftype.Kind() != reflect.Struct { + return nil, errors.New("option ,inline may only be used on a struct or map field") + } + if reflect.PtrTo(ftype).Implements(unmarshalerType) { + inlineUnmarshalers = append(inlineUnmarshalers, []int{i}) + } else { + sinfo, err := getStructInfo(ftype) + if err != nil { + return nil, err + } + for _, index := range sinfo.InlineUnmarshalers { + inlineUnmarshalers = append(inlineUnmarshalers, append([]int{i}, index...)) + } + for _, finfo := range sinfo.FieldsList { + if _, found := fieldsMap[finfo.Key]; found { + msg := "duplicated key '" + finfo.Key + "' in struct " + st.String() + return nil, errors.New(msg) + } + if finfo.Inline == nil { + finfo.Inline = []int{i, finfo.Num} + } else { + finfo.Inline = append([]int{i}, finfo.Inline...) + } + finfo.Id = len(fieldsList) + fieldsMap[finfo.Key] = finfo + fieldsList = append(fieldsList, finfo) + } + } + default: + return nil, errors.New("option ,inline may only be used on a struct or map field") + } + continue + } + + if tag != "" { + info.Key = tag + } else { + info.Key = strings.ToLower(field.Name) + } + + if _, found = fieldsMap[info.Key]; found { + msg := "duplicated key '" + info.Key + "' in struct " + st.String() + return nil, errors.New(msg) + } + + info.Id = len(fieldsList) + fieldsList = append(fieldsList, info) + fieldsMap[info.Key] = info + } + + sinfo = &structInfo{ + FieldsMap: fieldsMap, + FieldsList: fieldsList, + InlineMap: inlineMap, + InlineUnmarshalers: inlineUnmarshalers, + } + + fieldMapMutex.Lock() + structMap[st] = sinfo + fieldMapMutex.Unlock() + return sinfo, nil +} + +// IsZeroer is used to check whether an object is zero to +// determine whether it should be omitted when marshaling +// with the omitempty flag. One notable implementation +// is time.Time. +type IsZeroer interface { + IsZero() bool +} + +func isZero(v reflect.Value) bool { + kind := v.Kind() + if z, ok := v.Interface().(IsZeroer); ok { + if (kind == reflect.Ptr || kind == reflect.Interface) && v.IsNil() { + return true + } + return z.IsZero() + } + switch kind { + case reflect.String: + return len(v.String()) == 0 + case reflect.Interface, reflect.Ptr: + return v.IsNil() + case reflect.Slice: + return v.Len() == 0 + case reflect.Map: + return v.Len() == 0 + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + return v.Int() == 0 + case reflect.Float32, reflect.Float64: + return v.Float() == 0 + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: + return v.Uint() == 0 + case reflect.Bool: + return !v.Bool() + case reflect.Struct: + vt := v.Type() + for i := v.NumField() - 1; i >= 0; i-- { + if vt.Field(i).PkgPath != "" { + continue // Private field + } + if !isZero(v.Field(i)) { + return false + } + } + return true + } + return false +} diff --git a/vendor/go.yaml.in/yaml/v3/yamlh.go b/vendor/go.yaml.in/yaml/v3/yamlh.go new file mode 100644 index 000000000..07c442361 --- /dev/null +++ b/vendor/go.yaml.in/yaml/v3/yamlh.go @@ -0,0 +1,807 @@ +// +// Copyright (c) 2011-2019 Canonical Ltd +// Copyright (c) 2006-2010 Kirill Simonov +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of +// this software and associated documentation files (the "Software"), to deal in +// the Software without restriction, including without limitation the rights to +// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +// of the Software, and to permit persons to whom the Software is furnished to do +// so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +package yaml + +import ( + "fmt" + "io" +) + +// The version directive data. +type yaml_version_directive_t struct { + major int8 // The major version number. + minor int8 // The minor version number. +} + +// The tag directive data. +type yaml_tag_directive_t struct { + handle []byte // The tag handle. + prefix []byte // The tag prefix. +} + +type yaml_encoding_t int + +// The stream encoding. +const ( + // Let the parser choose the encoding. + yaml_ANY_ENCODING yaml_encoding_t = iota + + yaml_UTF8_ENCODING // The default UTF-8 encoding. + yaml_UTF16LE_ENCODING // The UTF-16-LE encoding with BOM. + yaml_UTF16BE_ENCODING // The UTF-16-BE encoding with BOM. +) + +type yaml_break_t int + +// Line break types. +const ( + // Let the parser choose the break type. + yaml_ANY_BREAK yaml_break_t = iota + + yaml_CR_BREAK // Use CR for line breaks (Mac style). + yaml_LN_BREAK // Use LN for line breaks (Unix style). + yaml_CRLN_BREAK // Use CR LN for line breaks (DOS style). +) + +type yaml_error_type_t int + +// Many bad things could happen with the parser and emitter. +const ( + // No error is produced. + yaml_NO_ERROR yaml_error_type_t = iota + + yaml_MEMORY_ERROR // Cannot allocate or reallocate a block of memory. + yaml_READER_ERROR // Cannot read or decode the input stream. + yaml_SCANNER_ERROR // Cannot scan the input stream. + yaml_PARSER_ERROR // Cannot parse the input stream. + yaml_COMPOSER_ERROR // Cannot compose a YAML document. + yaml_WRITER_ERROR // Cannot write to the output stream. + yaml_EMITTER_ERROR // Cannot emit a YAML stream. +) + +// The pointer position. +type yaml_mark_t struct { + index int // The position index. + line int // The position line. + column int // The position column. +} + +// Node Styles + +type yaml_style_t int8 + +type yaml_scalar_style_t yaml_style_t + +// Scalar styles. +const ( + // Let the emitter choose the style. + yaml_ANY_SCALAR_STYLE yaml_scalar_style_t = 0 + + yaml_PLAIN_SCALAR_STYLE yaml_scalar_style_t = 1 << iota // The plain scalar style. + yaml_SINGLE_QUOTED_SCALAR_STYLE // The single-quoted scalar style. + yaml_DOUBLE_QUOTED_SCALAR_STYLE // The double-quoted scalar style. + yaml_LITERAL_SCALAR_STYLE // The literal scalar style. + yaml_FOLDED_SCALAR_STYLE // The folded scalar style. +) + +type yaml_sequence_style_t yaml_style_t + +// Sequence styles. +const ( + // Let the emitter choose the style. + yaml_ANY_SEQUENCE_STYLE yaml_sequence_style_t = iota + + yaml_BLOCK_SEQUENCE_STYLE // The block sequence style. + yaml_FLOW_SEQUENCE_STYLE // The flow sequence style. +) + +type yaml_mapping_style_t yaml_style_t + +// Mapping styles. +const ( + // Let the emitter choose the style. + yaml_ANY_MAPPING_STYLE yaml_mapping_style_t = iota + + yaml_BLOCK_MAPPING_STYLE // The block mapping style. + yaml_FLOW_MAPPING_STYLE // The flow mapping style. +) + +// Tokens + +type yaml_token_type_t int + +// Token types. +const ( + // An empty token. + yaml_NO_TOKEN yaml_token_type_t = iota + + yaml_STREAM_START_TOKEN // A STREAM-START token. + yaml_STREAM_END_TOKEN // A STREAM-END token. + + yaml_VERSION_DIRECTIVE_TOKEN // A VERSION-DIRECTIVE token. + yaml_TAG_DIRECTIVE_TOKEN // A TAG-DIRECTIVE token. + yaml_DOCUMENT_START_TOKEN // A DOCUMENT-START token. + yaml_DOCUMENT_END_TOKEN // A DOCUMENT-END token. + + yaml_BLOCK_SEQUENCE_START_TOKEN // A BLOCK-SEQUENCE-START token. + yaml_BLOCK_MAPPING_START_TOKEN // A BLOCK-SEQUENCE-END token. + yaml_BLOCK_END_TOKEN // A BLOCK-END token. + + yaml_FLOW_SEQUENCE_START_TOKEN // A FLOW-SEQUENCE-START token. + yaml_FLOW_SEQUENCE_END_TOKEN // A FLOW-SEQUENCE-END token. + yaml_FLOW_MAPPING_START_TOKEN // A FLOW-MAPPING-START token. + yaml_FLOW_MAPPING_END_TOKEN // A FLOW-MAPPING-END token. + + yaml_BLOCK_ENTRY_TOKEN // A BLOCK-ENTRY token. + yaml_FLOW_ENTRY_TOKEN // A FLOW-ENTRY token. + yaml_KEY_TOKEN // A KEY token. + yaml_VALUE_TOKEN // A VALUE token. + + yaml_ALIAS_TOKEN // An ALIAS token. + yaml_ANCHOR_TOKEN // An ANCHOR token. + yaml_TAG_TOKEN // A TAG token. + yaml_SCALAR_TOKEN // A SCALAR token. +) + +func (tt yaml_token_type_t) String() string { + switch tt { + case yaml_NO_TOKEN: + return "yaml_NO_TOKEN" + case yaml_STREAM_START_TOKEN: + return "yaml_STREAM_START_TOKEN" + case yaml_STREAM_END_TOKEN: + return "yaml_STREAM_END_TOKEN" + case yaml_VERSION_DIRECTIVE_TOKEN: + return "yaml_VERSION_DIRECTIVE_TOKEN" + case yaml_TAG_DIRECTIVE_TOKEN: + return "yaml_TAG_DIRECTIVE_TOKEN" + case yaml_DOCUMENT_START_TOKEN: + return "yaml_DOCUMENT_START_TOKEN" + case yaml_DOCUMENT_END_TOKEN: + return "yaml_DOCUMENT_END_TOKEN" + case yaml_BLOCK_SEQUENCE_START_TOKEN: + return "yaml_BLOCK_SEQUENCE_START_TOKEN" + case yaml_BLOCK_MAPPING_START_TOKEN: + return "yaml_BLOCK_MAPPING_START_TOKEN" + case yaml_BLOCK_END_TOKEN: + return "yaml_BLOCK_END_TOKEN" + case yaml_FLOW_SEQUENCE_START_TOKEN: + return "yaml_FLOW_SEQUENCE_START_TOKEN" + case yaml_FLOW_SEQUENCE_END_TOKEN: + return "yaml_FLOW_SEQUENCE_END_TOKEN" + case yaml_FLOW_MAPPING_START_TOKEN: + return "yaml_FLOW_MAPPING_START_TOKEN" + case yaml_FLOW_MAPPING_END_TOKEN: + return "yaml_FLOW_MAPPING_END_TOKEN" + case yaml_BLOCK_ENTRY_TOKEN: + return "yaml_BLOCK_ENTRY_TOKEN" + case yaml_FLOW_ENTRY_TOKEN: + return "yaml_FLOW_ENTRY_TOKEN" + case yaml_KEY_TOKEN: + return "yaml_KEY_TOKEN" + case yaml_VALUE_TOKEN: + return "yaml_VALUE_TOKEN" + case yaml_ALIAS_TOKEN: + return "yaml_ALIAS_TOKEN" + case yaml_ANCHOR_TOKEN: + return "yaml_ANCHOR_TOKEN" + case yaml_TAG_TOKEN: + return "yaml_TAG_TOKEN" + case yaml_SCALAR_TOKEN: + return "yaml_SCALAR_TOKEN" + } + return "" +} + +// The token structure. +type yaml_token_t struct { + // The token type. + typ yaml_token_type_t + + // The start/end of the token. + start_mark, end_mark yaml_mark_t + + // The stream encoding (for yaml_STREAM_START_TOKEN). + encoding yaml_encoding_t + + // The alias/anchor/scalar value or tag/tag directive handle + // (for yaml_ALIAS_TOKEN, yaml_ANCHOR_TOKEN, yaml_SCALAR_TOKEN, yaml_TAG_TOKEN, yaml_TAG_DIRECTIVE_TOKEN). + value []byte + + // The tag suffix (for yaml_TAG_TOKEN). + suffix []byte + + // The tag directive prefix (for yaml_TAG_DIRECTIVE_TOKEN). + prefix []byte + + // The scalar style (for yaml_SCALAR_TOKEN). + style yaml_scalar_style_t + + // The version directive major/minor (for yaml_VERSION_DIRECTIVE_TOKEN). + major, minor int8 +} + +// Events + +type yaml_event_type_t int8 + +// Event types. +const ( + // An empty event. + yaml_NO_EVENT yaml_event_type_t = iota + + yaml_STREAM_START_EVENT // A STREAM-START event. + yaml_STREAM_END_EVENT // A STREAM-END event. + yaml_DOCUMENT_START_EVENT // A DOCUMENT-START event. + yaml_DOCUMENT_END_EVENT // A DOCUMENT-END event. + yaml_ALIAS_EVENT // An ALIAS event. + yaml_SCALAR_EVENT // A SCALAR event. + yaml_SEQUENCE_START_EVENT // A SEQUENCE-START event. + yaml_SEQUENCE_END_EVENT // A SEQUENCE-END event. + yaml_MAPPING_START_EVENT // A MAPPING-START event. + yaml_MAPPING_END_EVENT // A MAPPING-END event. + yaml_TAIL_COMMENT_EVENT +) + +var eventStrings = []string{ + yaml_NO_EVENT: "none", + yaml_STREAM_START_EVENT: "stream start", + yaml_STREAM_END_EVENT: "stream end", + yaml_DOCUMENT_START_EVENT: "document start", + yaml_DOCUMENT_END_EVENT: "document end", + yaml_ALIAS_EVENT: "alias", + yaml_SCALAR_EVENT: "scalar", + yaml_SEQUENCE_START_EVENT: "sequence start", + yaml_SEQUENCE_END_EVENT: "sequence end", + yaml_MAPPING_START_EVENT: "mapping start", + yaml_MAPPING_END_EVENT: "mapping end", + yaml_TAIL_COMMENT_EVENT: "tail comment", +} + +func (e yaml_event_type_t) String() string { + if e < 0 || int(e) >= len(eventStrings) { + return fmt.Sprintf("unknown event %d", e) + } + return eventStrings[e] +} + +// The event structure. +type yaml_event_t struct { + + // The event type. + typ yaml_event_type_t + + // The start and end of the event. + start_mark, end_mark yaml_mark_t + + // The document encoding (for yaml_STREAM_START_EVENT). + encoding yaml_encoding_t + + // The version directive (for yaml_DOCUMENT_START_EVENT). + version_directive *yaml_version_directive_t + + // The list of tag directives (for yaml_DOCUMENT_START_EVENT). + tag_directives []yaml_tag_directive_t + + // The comments + head_comment []byte + line_comment []byte + foot_comment []byte + tail_comment []byte + + // The anchor (for yaml_SCALAR_EVENT, yaml_SEQUENCE_START_EVENT, yaml_MAPPING_START_EVENT, yaml_ALIAS_EVENT). + anchor []byte + + // The tag (for yaml_SCALAR_EVENT, yaml_SEQUENCE_START_EVENT, yaml_MAPPING_START_EVENT). + tag []byte + + // The scalar value (for yaml_SCALAR_EVENT). + value []byte + + // Is the document start/end indicator implicit, or the tag optional? + // (for yaml_DOCUMENT_START_EVENT, yaml_DOCUMENT_END_EVENT, yaml_SEQUENCE_START_EVENT, yaml_MAPPING_START_EVENT, yaml_SCALAR_EVENT). + implicit bool + + // Is the tag optional for any non-plain style? (for yaml_SCALAR_EVENT). + quoted_implicit bool + + // The style (for yaml_SCALAR_EVENT, yaml_SEQUENCE_START_EVENT, yaml_MAPPING_START_EVENT). + style yaml_style_t +} + +func (e *yaml_event_t) scalar_style() yaml_scalar_style_t { return yaml_scalar_style_t(e.style) } +func (e *yaml_event_t) sequence_style() yaml_sequence_style_t { return yaml_sequence_style_t(e.style) } +func (e *yaml_event_t) mapping_style() yaml_mapping_style_t { return yaml_mapping_style_t(e.style) } + +// Nodes + +const ( + yaml_NULL_TAG = "tag:yaml.org,2002:null" // The tag !!null with the only possible value: null. + yaml_BOOL_TAG = "tag:yaml.org,2002:bool" // The tag !!bool with the values: true and false. + yaml_STR_TAG = "tag:yaml.org,2002:str" // The tag !!str for string values. + yaml_INT_TAG = "tag:yaml.org,2002:int" // The tag !!int for integer values. + yaml_FLOAT_TAG = "tag:yaml.org,2002:float" // The tag !!float for float values. + yaml_TIMESTAMP_TAG = "tag:yaml.org,2002:timestamp" // The tag !!timestamp for date and time values. + + yaml_SEQ_TAG = "tag:yaml.org,2002:seq" // The tag !!seq is used to denote sequences. + yaml_MAP_TAG = "tag:yaml.org,2002:map" // The tag !!map is used to denote mapping. + + // Not in original libyaml. + yaml_BINARY_TAG = "tag:yaml.org,2002:binary" + yaml_MERGE_TAG = "tag:yaml.org,2002:merge" + + yaml_DEFAULT_SCALAR_TAG = yaml_STR_TAG // The default scalar tag is !!str. + yaml_DEFAULT_SEQUENCE_TAG = yaml_SEQ_TAG // The default sequence tag is !!seq. + yaml_DEFAULT_MAPPING_TAG = yaml_MAP_TAG // The default mapping tag is !!map. +) + +type yaml_node_type_t int + +// Node types. +const ( + // An empty node. + yaml_NO_NODE yaml_node_type_t = iota + + yaml_SCALAR_NODE // A scalar node. + yaml_SEQUENCE_NODE // A sequence node. + yaml_MAPPING_NODE // A mapping node. +) + +// An element of a sequence node. +type yaml_node_item_t int + +// An element of a mapping node. +type yaml_node_pair_t struct { + key int // The key of the element. + value int // The value of the element. +} + +// The node structure. +type yaml_node_t struct { + typ yaml_node_type_t // The node type. + tag []byte // The node tag. + + // The node data. + + // The scalar parameters (for yaml_SCALAR_NODE). + scalar struct { + value []byte // The scalar value. + length int // The length of the scalar value. + style yaml_scalar_style_t // The scalar style. + } + + // The sequence parameters (for YAML_SEQUENCE_NODE). + sequence struct { + items_data []yaml_node_item_t // The stack of sequence items. + style yaml_sequence_style_t // The sequence style. + } + + // The mapping parameters (for yaml_MAPPING_NODE). + mapping struct { + pairs_data []yaml_node_pair_t // The stack of mapping pairs (key, value). + pairs_start *yaml_node_pair_t // The beginning of the stack. + pairs_end *yaml_node_pair_t // The end of the stack. + pairs_top *yaml_node_pair_t // The top of the stack. + style yaml_mapping_style_t // The mapping style. + } + + start_mark yaml_mark_t // The beginning of the node. + end_mark yaml_mark_t // The end of the node. + +} + +// The document structure. +type yaml_document_t struct { + + // The document nodes. + nodes []yaml_node_t + + // The version directive. + version_directive *yaml_version_directive_t + + // The list of tag directives. + tag_directives_data []yaml_tag_directive_t + tag_directives_start int // The beginning of the tag directives list. + tag_directives_end int // The end of the tag directives list. + + start_implicit int // Is the document start indicator implicit? + end_implicit int // Is the document end indicator implicit? + + // The start/end of the document. + start_mark, end_mark yaml_mark_t +} + +// The prototype of a read handler. +// +// The read handler is called when the parser needs to read more bytes from the +// source. The handler should write not more than size bytes to the buffer. +// The number of written bytes should be set to the size_read variable. +// +// [in,out] data A pointer to an application data specified by +// yaml_parser_set_input(). +// [out] buffer The buffer to write the data from the source. +// [in] size The size of the buffer. +// [out] size_read The actual number of bytes read from the source. +// +// On success, the handler should return 1. If the handler failed, +// the returned value should be 0. On EOF, the handler should set the +// size_read to 0 and return 1. +type yaml_read_handler_t func(parser *yaml_parser_t, buffer []byte) (n int, err error) + +// This structure holds information about a potential simple key. +type yaml_simple_key_t struct { + possible bool // Is a simple key possible? + required bool // Is a simple key required? + token_number int // The number of the token. + mark yaml_mark_t // The position mark. +} + +// The states of the parser. +type yaml_parser_state_t int + +const ( + yaml_PARSE_STREAM_START_STATE yaml_parser_state_t = iota + + yaml_PARSE_IMPLICIT_DOCUMENT_START_STATE // Expect the beginning of an implicit document. + yaml_PARSE_DOCUMENT_START_STATE // Expect DOCUMENT-START. + yaml_PARSE_DOCUMENT_CONTENT_STATE // Expect the content of a document. + yaml_PARSE_DOCUMENT_END_STATE // Expect DOCUMENT-END. + yaml_PARSE_BLOCK_NODE_STATE // Expect a block node. + yaml_PARSE_BLOCK_NODE_OR_INDENTLESS_SEQUENCE_STATE // Expect a block node or indentless sequence. + yaml_PARSE_FLOW_NODE_STATE // Expect a flow node. + yaml_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE // Expect the first entry of a block sequence. + yaml_PARSE_BLOCK_SEQUENCE_ENTRY_STATE // Expect an entry of a block sequence. + yaml_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE // Expect an entry of an indentless sequence. + yaml_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE // Expect the first key of a block mapping. + yaml_PARSE_BLOCK_MAPPING_KEY_STATE // Expect a block mapping key. + yaml_PARSE_BLOCK_MAPPING_VALUE_STATE // Expect a block mapping value. + yaml_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE // Expect the first entry of a flow sequence. + yaml_PARSE_FLOW_SEQUENCE_ENTRY_STATE // Expect an entry of a flow sequence. + yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE // Expect a key of an ordered mapping. + yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE // Expect a value of an ordered mapping. + yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE // Expect the and of an ordered mapping entry. + yaml_PARSE_FLOW_MAPPING_FIRST_KEY_STATE // Expect the first key of a flow mapping. + yaml_PARSE_FLOW_MAPPING_KEY_STATE // Expect a key of a flow mapping. + yaml_PARSE_FLOW_MAPPING_VALUE_STATE // Expect a value of a flow mapping. + yaml_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE // Expect an empty value of a flow mapping. + yaml_PARSE_END_STATE // Expect nothing. +) + +func (ps yaml_parser_state_t) String() string { + switch ps { + case yaml_PARSE_STREAM_START_STATE: + return "yaml_PARSE_STREAM_START_STATE" + case yaml_PARSE_IMPLICIT_DOCUMENT_START_STATE: + return "yaml_PARSE_IMPLICIT_DOCUMENT_START_STATE" + case yaml_PARSE_DOCUMENT_START_STATE: + return "yaml_PARSE_DOCUMENT_START_STATE" + case yaml_PARSE_DOCUMENT_CONTENT_STATE: + return "yaml_PARSE_DOCUMENT_CONTENT_STATE" + case yaml_PARSE_DOCUMENT_END_STATE: + return "yaml_PARSE_DOCUMENT_END_STATE" + case yaml_PARSE_BLOCK_NODE_STATE: + return "yaml_PARSE_BLOCK_NODE_STATE" + case yaml_PARSE_BLOCK_NODE_OR_INDENTLESS_SEQUENCE_STATE: + return "yaml_PARSE_BLOCK_NODE_OR_INDENTLESS_SEQUENCE_STATE" + case yaml_PARSE_FLOW_NODE_STATE: + return "yaml_PARSE_FLOW_NODE_STATE" + case yaml_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE: + return "yaml_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE" + case yaml_PARSE_BLOCK_SEQUENCE_ENTRY_STATE: + return "yaml_PARSE_BLOCK_SEQUENCE_ENTRY_STATE" + case yaml_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE: + return "yaml_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE" + case yaml_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE: + return "yaml_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE" + case yaml_PARSE_BLOCK_MAPPING_KEY_STATE: + return "yaml_PARSE_BLOCK_MAPPING_KEY_STATE" + case yaml_PARSE_BLOCK_MAPPING_VALUE_STATE: + return "yaml_PARSE_BLOCK_MAPPING_VALUE_STATE" + case yaml_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE: + return "yaml_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE" + case yaml_PARSE_FLOW_SEQUENCE_ENTRY_STATE: + return "yaml_PARSE_FLOW_SEQUENCE_ENTRY_STATE" + case yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE: + return "yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE" + case yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE: + return "yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE" + case yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE: + return "yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE" + case yaml_PARSE_FLOW_MAPPING_FIRST_KEY_STATE: + return "yaml_PARSE_FLOW_MAPPING_FIRST_KEY_STATE" + case yaml_PARSE_FLOW_MAPPING_KEY_STATE: + return "yaml_PARSE_FLOW_MAPPING_KEY_STATE" + case yaml_PARSE_FLOW_MAPPING_VALUE_STATE: + return "yaml_PARSE_FLOW_MAPPING_VALUE_STATE" + case yaml_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE: + return "yaml_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE" + case yaml_PARSE_END_STATE: + return "yaml_PARSE_END_STATE" + } + return "" +} + +// This structure holds aliases data. +type yaml_alias_data_t struct { + anchor []byte // The anchor. + index int // The node id. + mark yaml_mark_t // The anchor mark. +} + +// The parser structure. +// +// All members are internal. Manage the structure using the +// yaml_parser_ family of functions. +type yaml_parser_t struct { + + // Error handling + + error yaml_error_type_t // Error type. + + problem string // Error description. + + // The byte about which the problem occurred. + problem_offset int + problem_value int + problem_mark yaml_mark_t + + // The error context. + context string + context_mark yaml_mark_t + + // Reader stuff + + read_handler yaml_read_handler_t // Read handler. + + input_reader io.Reader // File input data. + input []byte // String input data. + input_pos int + + eof bool // EOF flag + + buffer []byte // The working buffer. + buffer_pos int // The current position of the buffer. + + unread int // The number of unread characters in the buffer. + + newlines int // The number of line breaks since last non-break/non-blank character + + raw_buffer []byte // The raw buffer. + raw_buffer_pos int // The current position of the buffer. + + encoding yaml_encoding_t // The input encoding. + + offset int // The offset of the current position (in bytes). + mark yaml_mark_t // The mark of the current position. + + // Comments + + head_comment []byte // The current head comments + line_comment []byte // The current line comments + foot_comment []byte // The current foot comments + tail_comment []byte // Foot comment that happens at the end of a block. + stem_comment []byte // Comment in item preceding a nested structure (list inside list item, etc) + + comments []yaml_comment_t // The folded comments for all parsed tokens + comments_head int + + // Scanner stuff + + stream_start_produced bool // Have we started to scan the input stream? + stream_end_produced bool // Have we reached the end of the input stream? + + flow_level int // The number of unclosed '[' and '{' indicators. + + tokens []yaml_token_t // The tokens queue. + tokens_head int // The head of the tokens queue. + tokens_parsed int // The number of tokens fetched from the queue. + token_available bool // Does the tokens queue contain a token ready for dequeueing. + + indent int // The current indentation level. + indents []int // The indentation levels stack. + + simple_key_allowed bool // May a simple key occur at the current position? + simple_keys []yaml_simple_key_t // The stack of simple keys. + simple_keys_by_tok map[int]int // possible simple_key indexes indexed by token_number + + // Parser stuff + + state yaml_parser_state_t // The current parser state. + states []yaml_parser_state_t // The parser states stack. + marks []yaml_mark_t // The stack of marks. + tag_directives []yaml_tag_directive_t // The list of TAG directives. + + // Dumper stuff + + aliases []yaml_alias_data_t // The alias data. + + document *yaml_document_t // The currently parsed document. +} + +type yaml_comment_t struct { + scan_mark yaml_mark_t // Position where scanning for comments started + token_mark yaml_mark_t // Position after which tokens will be associated with this comment + start_mark yaml_mark_t // Position of '#' comment mark + end_mark yaml_mark_t // Position where comment terminated + + head []byte + line []byte + foot []byte +} + +// Emitter Definitions + +// The prototype of a write handler. +// +// The write handler is called when the emitter needs to flush the accumulated +// characters to the output. The handler should write @a size bytes of the +// @a buffer to the output. +// +// @param[in,out] data A pointer to an application data specified by +// yaml_emitter_set_output(). +// @param[in] buffer The buffer with bytes to be written. +// @param[in] size The size of the buffer. +// +// @returns On success, the handler should return @c 1. If the handler failed, +// the returned value should be @c 0. +type yaml_write_handler_t func(emitter *yaml_emitter_t, buffer []byte) error + +type yaml_emitter_state_t int + +// The emitter states. +const ( + // Expect STREAM-START. + yaml_EMIT_STREAM_START_STATE yaml_emitter_state_t = iota + + yaml_EMIT_FIRST_DOCUMENT_START_STATE // Expect the first DOCUMENT-START or STREAM-END. + yaml_EMIT_DOCUMENT_START_STATE // Expect DOCUMENT-START or STREAM-END. + yaml_EMIT_DOCUMENT_CONTENT_STATE // Expect the content of a document. + yaml_EMIT_DOCUMENT_END_STATE // Expect DOCUMENT-END. + yaml_EMIT_FLOW_SEQUENCE_FIRST_ITEM_STATE // Expect the first item of a flow sequence. + yaml_EMIT_FLOW_SEQUENCE_TRAIL_ITEM_STATE // Expect the next item of a flow sequence, with the comma already written out + yaml_EMIT_FLOW_SEQUENCE_ITEM_STATE // Expect an item of a flow sequence. + yaml_EMIT_FLOW_MAPPING_FIRST_KEY_STATE // Expect the first key of a flow mapping. + yaml_EMIT_FLOW_MAPPING_TRAIL_KEY_STATE // Expect the next key of a flow mapping, with the comma already written out + yaml_EMIT_FLOW_MAPPING_KEY_STATE // Expect a key of a flow mapping. + yaml_EMIT_FLOW_MAPPING_SIMPLE_VALUE_STATE // Expect a value for a simple key of a flow mapping. + yaml_EMIT_FLOW_MAPPING_VALUE_STATE // Expect a value of a flow mapping. + yaml_EMIT_BLOCK_SEQUENCE_FIRST_ITEM_STATE // Expect the first item of a block sequence. + yaml_EMIT_BLOCK_SEQUENCE_ITEM_STATE // Expect an item of a block sequence. + yaml_EMIT_BLOCK_MAPPING_FIRST_KEY_STATE // Expect the first key of a block mapping. + yaml_EMIT_BLOCK_MAPPING_KEY_STATE // Expect the key of a block mapping. + yaml_EMIT_BLOCK_MAPPING_SIMPLE_VALUE_STATE // Expect a value for a simple key of a block mapping. + yaml_EMIT_BLOCK_MAPPING_VALUE_STATE // Expect a value of a block mapping. + yaml_EMIT_END_STATE // Expect nothing. +) + +// The emitter structure. +// +// All members are internal. Manage the structure using the @c yaml_emitter_ +// family of functions. +type yaml_emitter_t struct { + + // Error handling + + error yaml_error_type_t // Error type. + problem string // Error description. + + // Writer stuff + + write_handler yaml_write_handler_t // Write handler. + + output_buffer *[]byte // String output data. + output_writer io.Writer // File output data. + + buffer []byte // The working buffer. + buffer_pos int // The current position of the buffer. + + raw_buffer []byte // The raw buffer. + raw_buffer_pos int // The current position of the buffer. + + encoding yaml_encoding_t // The stream encoding. + + // Emitter stuff + + canonical bool // If the output is in the canonical style? + best_indent int // The number of indentation spaces. + best_width int // The preferred width of the output lines. + unicode bool // Allow unescaped non-ASCII characters? + line_break yaml_break_t // The preferred line break. + + state yaml_emitter_state_t // The current emitter state. + states []yaml_emitter_state_t // The stack of states. + + events []yaml_event_t // The event queue. + events_head int // The head of the event queue. + + indents []int // The stack of indentation levels. + + tag_directives []yaml_tag_directive_t // The list of tag directives. + + indent int // The current indentation level. + + compact_sequence_indent bool // Is '- ' is considered part of the indentation for sequence elements? + + flow_level int // The current flow level. + + root_context bool // Is it the document root context? + sequence_context bool // Is it a sequence context? + mapping_context bool // Is it a mapping context? + simple_key_context bool // Is it a simple mapping key context? + + line int // The current line. + column int // The current column. + whitespace bool // If the last character was a whitespace? + indention bool // If the last character was an indentation character (' ', '-', '?', ':')? + open_ended bool // If an explicit document end is required? + + space_above bool // Is there's an empty line above? + foot_indent int // The indent used to write the foot comment above, or -1 if none. + + // Anchor analysis. + anchor_data struct { + anchor []byte // The anchor value. + alias bool // Is it an alias? + } + + // Tag analysis. + tag_data struct { + handle []byte // The tag handle. + suffix []byte // The tag suffix. + } + + // Scalar analysis. + scalar_data struct { + value []byte // The scalar value. + multiline bool // Does the scalar contain line breaks? + flow_plain_allowed bool // Can the scalar be expessed in the flow plain style? + block_plain_allowed bool // Can the scalar be expressed in the block plain style? + single_quoted_allowed bool // Can the scalar be expressed in the single quoted style? + block_allowed bool // Can the scalar be expressed in the literal or folded styles? + style yaml_scalar_style_t // The output style. + } + + // Comments + head_comment []byte + line_comment []byte + foot_comment []byte + tail_comment []byte + + key_line_comment []byte + + // Dumper stuff + + opened bool // If the stream was already opened? + closed bool // If the stream was already closed? + + // The information associated with the document nodes. + anchors *struct { + references int // The number of references. + anchor int // The anchor id. + serialized bool // If the node has been emitted? + } + + last_anchor_id int // The last assigned anchor id. + + document *yaml_document_t // The currently emitted document. +} diff --git a/vendor/go.yaml.in/yaml/v3/yamlprivateh.go b/vendor/go.yaml.in/yaml/v3/yamlprivateh.go new file mode 100644 index 000000000..dea1ba961 --- /dev/null +++ b/vendor/go.yaml.in/yaml/v3/yamlprivateh.go @@ -0,0 +1,198 @@ +// +// Copyright (c) 2011-2019 Canonical Ltd +// Copyright (c) 2006-2010 Kirill Simonov +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of +// this software and associated documentation files (the "Software"), to deal in +// the Software without restriction, including without limitation the rights to +// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +// of the Software, and to permit persons to whom the Software is furnished to do +// so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +package yaml + +const ( + // The size of the input raw buffer. + input_raw_buffer_size = 512 + + // The size of the input buffer. + // It should be possible to decode the whole raw buffer. + input_buffer_size = input_raw_buffer_size * 3 + + // The size of the output buffer. + output_buffer_size = 128 + + // The size of the output raw buffer. + // It should be possible to encode the whole output buffer. + output_raw_buffer_size = (output_buffer_size*2 + 2) + + // The size of other stacks and queues. + initial_stack_size = 16 + initial_queue_size = 16 + initial_string_size = 16 +) + +// Check if the character at the specified position is an alphabetical +// character, a digit, '_', or '-'. +func is_alpha(b []byte, i int) bool { + return b[i] >= '0' && b[i] <= '9' || b[i] >= 'A' && b[i] <= 'Z' || b[i] >= 'a' && b[i] <= 'z' || b[i] == '_' || b[i] == '-' +} + +// Check if the character at the specified position is a digit. +func is_digit(b []byte, i int) bool { + return b[i] >= '0' && b[i] <= '9' +} + +// Get the value of a digit. +func as_digit(b []byte, i int) int { + return int(b[i]) - '0' +} + +// Check if the character at the specified position is a hex-digit. +func is_hex(b []byte, i int) bool { + return b[i] >= '0' && b[i] <= '9' || b[i] >= 'A' && b[i] <= 'F' || b[i] >= 'a' && b[i] <= 'f' +} + +// Get the value of a hex-digit. +func as_hex(b []byte, i int) int { + bi := b[i] + if bi >= 'A' && bi <= 'F' { + return int(bi) - 'A' + 10 + } + if bi >= 'a' && bi <= 'f' { + return int(bi) - 'a' + 10 + } + return int(bi) - '0' +} + +// Check if the character is ASCII. +func is_ascii(b []byte, i int) bool { + return b[i] <= 0x7F +} + +// Check if the character at the start of the buffer can be printed unescaped. +func is_printable(b []byte, i int) bool { + return ((b[i] == 0x0A) || // . == #x0A + (b[i] >= 0x20 && b[i] <= 0x7E) || // #x20 <= . <= #x7E + (b[i] == 0xC2 && b[i+1] >= 0xA0) || // #0xA0 <= . <= #xD7FF + (b[i] > 0xC2 && b[i] < 0xED) || + (b[i] == 0xED && b[i+1] < 0xA0) || + (b[i] == 0xEE) || + (b[i] == 0xEF && // #xE000 <= . <= #xFFFD + !(b[i+1] == 0xBB && b[i+2] == 0xBF) && // && . != #xFEFF + !(b[i+1] == 0xBF && (b[i+2] == 0xBE || b[i+2] == 0xBF)))) +} + +// Check if the character at the specified position is NUL. +func is_z(b []byte, i int) bool { + return b[i] == 0x00 +} + +// Check if the beginning of the buffer is a BOM. +func is_bom(b []byte, i int) bool { + return b[0] == 0xEF && b[1] == 0xBB && b[2] == 0xBF +} + +// Check if the character at the specified position is space. +func is_space(b []byte, i int) bool { + return b[i] == ' ' +} + +// Check if the character at the specified position is tab. +func is_tab(b []byte, i int) bool { + return b[i] == '\t' +} + +// Check if the character at the specified position is blank (space or tab). +func is_blank(b []byte, i int) bool { + //return is_space(b, i) || is_tab(b, i) + return b[i] == ' ' || b[i] == '\t' +} + +// Check if the character at the specified position is a line break. +func is_break(b []byte, i int) bool { + return (b[i] == '\r' || // CR (#xD) + b[i] == '\n' || // LF (#xA) + b[i] == 0xC2 && b[i+1] == 0x85 || // NEL (#x85) + b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA8 || // LS (#x2028) + b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA9) // PS (#x2029) +} + +func is_crlf(b []byte, i int) bool { + return b[i] == '\r' && b[i+1] == '\n' +} + +// Check if the character is a line break or NUL. +func is_breakz(b []byte, i int) bool { + //return is_break(b, i) || is_z(b, i) + return ( + // is_break: + b[i] == '\r' || // CR (#xD) + b[i] == '\n' || // LF (#xA) + b[i] == 0xC2 && b[i+1] == 0x85 || // NEL (#x85) + b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA8 || // LS (#x2028) + b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA9 || // PS (#x2029) + // is_z: + b[i] == 0) +} + +// Check if the character is a line break, space, or NUL. +func is_spacez(b []byte, i int) bool { + //return is_space(b, i) || is_breakz(b, i) + return ( + // is_space: + b[i] == ' ' || + // is_breakz: + b[i] == '\r' || // CR (#xD) + b[i] == '\n' || // LF (#xA) + b[i] == 0xC2 && b[i+1] == 0x85 || // NEL (#x85) + b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA8 || // LS (#x2028) + b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA9 || // PS (#x2029) + b[i] == 0) +} + +// Check if the character is a line break, space, tab, or NUL. +func is_blankz(b []byte, i int) bool { + //return is_blank(b, i) || is_breakz(b, i) + return ( + // is_blank: + b[i] == ' ' || b[i] == '\t' || + // is_breakz: + b[i] == '\r' || // CR (#xD) + b[i] == '\n' || // LF (#xA) + b[i] == 0xC2 && b[i+1] == 0x85 || // NEL (#x85) + b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA8 || // LS (#x2028) + b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA9 || // PS (#x2029) + b[i] == 0) +} + +// Determine the width of the character. +func width(b byte) int { + // Don't replace these by a switch without first + // confirming that it is being inlined. + if b&0x80 == 0x00 { + return 1 + } + if b&0xE0 == 0xC0 { + return 2 + } + if b&0xF0 == 0xE0 { + return 3 + } + if b&0xF8 == 0xF0 { + return 4 + } + return 0 + +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 8a18f281a..9082adf9e 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -107,9 +107,6 @@ github.com/chromedp/cdproto/webauthn # github.com/chromedp/sysutil v1.1.0 ## explicit; go 1.23 github.com/chromedp/sysutil -# github.com/davecgh/go-spew v1.1.1 -## explicit -github.com/davecgh/go-spew/spew # github.com/dlclark/regexp2/v2 v2.5.2 ## explicit; go 1.25 github.com/dlclark/regexp2/v2 @@ -282,9 +279,6 @@ github.com/nu7hatch/gouuid # github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c ## explicit; go 1.14 github.com/pkg/browser -# github.com/pmezard/go-difflib v1.0.0 -## explicit -github.com/pmezard/go-difflib/difflib # github.com/prometheus/client_golang v1.24.1 ## explicit; go 1.25.0 github.com/prometheus/client_golang/internal/github.com/golang/gddo/httputil @@ -325,10 +319,12 @@ github.com/spf13/cobra # github.com/spf13/pflag v1.0.5 ## explicit; go 1.12 github.com/spf13/pflag -# github.com/stretchr/testify v1.11.1 +# github.com/stretchr/testify v1.12.1 ## explicit; go 1.17 github.com/stretchr/testify/assert github.com/stretchr/testify/assert/yaml +github.com/stretchr/testify/internal/difflib +github.com/stretchr/testify/internal/spew github.com/stretchr/testify/require # github.com/tidwall/gjson v1.19.0 ## explicit; go 1.23 @@ -448,6 +444,9 @@ go.opentelemetry.io/proto/otlp/trace/v1 ## explicit; go 1.20 go.uber.org/goleak go.uber.org/goleak/internal/stack +# go.yaml.in/yaml/v3 v3.0.5 +## explicit; go 1.16 +go.yaml.in/yaml/v3 # golang.org/x/crypto v0.55.0 ## explicit; go 1.25.0 golang.org/x/crypto/md4 From ccac68fd62ccecdcd6a21ae8a6c10a5bf2a1b075 Mon Sep 17 00:00:00 2001 From: Mihail Stoykov <312246+mstoykov@users.noreply.github.com> Date: Tue, 25 Aug 2026 12:26:09 +0300 Subject: [PATCH 119/182] chore(ci): update k6-ci to v0.4.0 (#6312) --- .github/workflows/auto-approve-renovate.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/auto-approve-renovate.yml b/.github/workflows/auto-approve-renovate.yml index ef02e15f5..d47d20322 100644 --- a/.github/workflows/auto-approve-renovate.yml +++ b/.github/workflows/auto-approve-renovate.yml @@ -11,4 +11,4 @@ permissions: id-token: write jobs: approve: - uses: grafana/k6-ci/.github/workflows/auto-approve-renovate.yml@9477260e6838640d56c28aa95bcbf9a884ab21f3 # k6-ci#44 merge commit + uses: grafana/k6-ci/.github/workflows/auto-approve-renovate.yml@777962b022a831166517639e542630d8b7d1455f # v0.4.0 From 57ff6f9a994007fc3d42f9d1f20d85d7e3cb8784 Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Tue, 25 Aug 2026 12:26:59 +0300 Subject: [PATCH 120/182] fix(deps): update googles (#6304) | datasource | package | from | to | | ---------- | -------------------------- | -------- | -------- | | go | google.golang.org/grpc | v1.83.0 | v1.83.1 | | go | google.golang.org/protobuf | v1.36.11 | v1.36.12 | Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> --- go.mod | 4 +- go.sum | 8 +- .../grpc/internal/envconfig/envconfig.go | 12 +- .../grpc/internal/mem/buffer_pool.go | 14 + .../grpc/internal/transport/handler_server.go | 2 +- .../grpc/internal/transport/http2_client.go | 2 +- .../grpc/internal/transport/http2_server.go | 2 +- .../grpc/internal/transport/transport.go | 110 ++++++- .../google.golang.org/grpc/mem/buffer_pool.go | 4 - vendor/google.golang.org/grpc/mem/buffers.go | 6 +- vendor/google.golang.org/grpc/version.go | 2 +- .../encoding/protodelim/protodelim.go | 9 +- .../protobuf/encoding/protojson/decode.go | 12 + .../encoding/protojson/well_known_types.go | 5 +- .../protobuf/encoding/prototext/decode.go | 18 ++ .../protobuf/internal/descfmt/stringer.go | 269 +++++++++--------- .../editiondefaults/editions_defaults.binpb | Bin 154 -> 191 bytes .../internal/encoding/defval/default.go | 8 +- .../protobuf/internal/genid/descriptor_gen.go | 5 + .../protobuf/internal/version/version.go | 2 +- .../protobuf/reflect/protodesc/desc_init.go | 1 + .../reflect/protoreflect/source_gen.go | 2 + .../types/descriptorpb/descriptor.pb.go | 101 ++++--- .../protobuf/types/known/anypb/any.pb.go | 160 ++++------- .../types/known/fieldmaskpb/field_mask.pb.go | 34 ++- .../types/known/structpb/struct.pb.go | 55 ++-- .../types/known/timestamppb/timestamp.pb.go | 6 +- vendor/modules.txt | 4 +- 28 files changed, 485 insertions(+), 372 deletions(-) diff --git a/go.mod b/go.mod index 323aec9cb..792db4ca6 100644 --- a/go.mod +++ b/go.mod @@ -63,8 +63,8 @@ require ( golang.org/x/sync v0.22.0 golang.org/x/term v0.45.0 golang.org/x/time v0.15.0 - google.golang.org/grpc v1.83.0 - google.golang.org/protobuf v1.36.11 + google.golang.org/grpc v1.83.1 + google.golang.org/protobuf v1.36.12 gopkg.in/guregu/null.v3 v3.3.0 gopkg.in/yaml.v3 v3.0.1 ) diff --git a/go.sum b/go.sum index 976a6d7fa..c1ab2582a 100644 --- a/go.sum +++ b/go.sum @@ -386,16 +386,16 @@ google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyac google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= -google.golang.org/grpc v1.83.0 h1:JeNZEKJFbQxArAMl+hiytHauacDNqJUllNfmIMmpqnQ= -google.golang.org/grpc v1.83.0/go.mod h1:kDyl6SKsiHKt0uylY5gtn5cEjkrIOhQOGDgIc4JGwzQ= +google.golang.org/grpc v1.83.1 h1:HIO0+BEtBP6soyqvqC8sNUjZ7bTs+0hFQuFF+RAy++Y= +google.golang.org/grpc v1.83.1/go.mod h1:kDyl6SKsiHKt0uylY5gtn5cEjkrIOhQOGDgIc4JGwzQ= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE= -google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= +google.golang.org/protobuf v1.36.12 h1:pJOKDDOyeXErUroCihFAd5LQuwXBSpVnKGrj5o/fwxc= +google.golang.org/protobuf v1.36.12/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= gopkg.in/cenkalti/backoff.v1 v1.1.0 h1:Arh75ttbsvlpVA7WtVpH4u9h6Zl46xuptxqLxPiSo4Y= gopkg.in/cenkalti/backoff.v1 v1.1.0/go.mod h1:J6Vskwqd+OMVJl8C33mmtxTBs2gyzfv7UDAkHu8BrjI= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/vendor/google.golang.org/grpc/internal/envconfig/envconfig.go b/vendor/google.golang.org/grpc/internal/envconfig/envconfig.go index 29d332e7b..333448127 100644 --- a/vendor/google.golang.org/grpc/internal/envconfig/envconfig.go +++ b/vendor/google.golang.org/grpc/internal/envconfig/envconfig.go @@ -150,8 +150,18 @@ var ( // throttling limit if unforeseen issues arise, and it will be removed in a // future release. // - // TODO: Remove this env var once v1.83.0 is release. + // TODO: Remove this env var once v1.83.0 is released. ControlBufferThrottleLimit = uint64FromEnv("GRPC_GO_EXPERIMENTAL_CONTROL_BUFFER_THROTTLE_LIMIT", 100, 1, 10000) + + // EnableReceiveBufferCompaction enables the compaction of data buffers + // to reduce the number of buffers in the receive buffer. + // + // This environment variable serves as an escape hatch to disable the + // feature if unforeseen issues arise, and it will be removed in a future + // release. + // + // TODO: Remove this env var once v1.85.0 is released. + EnableReceiveBufferCompaction = boolFromEnv("GRPC_GO_EXPERIMENTAL_ENABLE_RECEIVE_BUFFER_COMPACTION", true) ) func boolFromEnv(envVar string, def bool) bool { diff --git a/vendor/google.golang.org/grpc/internal/mem/buffer_pool.go b/vendor/google.golang.org/grpc/internal/mem/buffer_pool.go index 2d83b2ece..00aeca419 100644 --- a/vendor/google.golang.org/grpc/internal/mem/buffer_pool.go +++ b/vendor/google.golang.org/grpc/internal/mem/buffer_pool.go @@ -26,12 +26,26 @@ import ( "slices" "sort" "sync" + + "google.golang.org/grpc/internal" ) const ( goPageSize = 4 * 1024 // 4KiB. N.B. this must be a power of 2. ) +var ( + // BufferPoolingThreshold is the minimum size of a buffer that can be pooled. + // This is used to determine whether to pool buffers or allocate them directly. + BufferPoolingThreshold = 1 << 10 +) + +func init() { + internal.SetBufferPoolingThresholdForTesting = func(threshold int) { + BufferPoolingThreshold = threshold + } +} + var uintSize = bits.UintSize // use a variable for mocking during tests. // bufferPool is a copy of the public bufferPool interface used to avoid diff --git a/vendor/google.golang.org/grpc/internal/transport/handler_server.go b/vendor/google.golang.org/grpc/internal/transport/handler_server.go index a8356c9ad..9cd8d28d3 100644 --- a/vendor/google.golang.org/grpc/internal/transport/handler_server.go +++ b/vendor/google.golang.org/grpc/internal/transport/handler_server.go @@ -424,7 +424,7 @@ func (ht *serverHandlerTransport) HandleStreams(ctx context.Context, startStream st: ht, headerWireLength: 0, // won't have access to header wire length until golang/go#18997. } - s.Stream.buf.init() + s.Stream.buf.init(ht.bufferPool) s.readRequester = s s.trReader = transportReader{ reader: recvBufferReader{ctx: s.ctx, ctxDone: s.ctx.Done(), recv: &s.buf}, diff --git a/vendor/google.golang.org/grpc/internal/transport/http2_client.go b/vendor/google.golang.org/grpc/internal/transport/http2_client.go index c19b45080..10d197741 100644 --- a/vendor/google.golang.org/grpc/internal/transport/http2_client.go +++ b/vendor/google.golang.org/grpc/internal/transport/http2_client.go @@ -500,7 +500,7 @@ func (t *http2Client) newStream(ctx context.Context, callHdr *CallHdr, handler s headerChan: make(chan struct{}), statsHandler: handler, } - s.Stream.buf.init() + s.Stream.buf.init(t.bufferPool) s.Stream.wq.init(defaultWriteQuota, s.done) s.readRequester = s // The client side stream context should have exactly the same life cycle with the user provided context. diff --git a/vendor/google.golang.org/grpc/internal/transport/http2_server.go b/vendor/google.golang.org/grpc/internal/transport/http2_server.go index be8ae9f9c..63c6539a3 100644 --- a/vendor/google.golang.org/grpc/internal/transport/http2_server.go +++ b/vendor/google.golang.org/grpc/internal/transport/http2_server.go @@ -407,7 +407,7 @@ func (t *http2Server) operateHeaders(ctx context.Context, frame *http2.MetaHeade st: t, headerWireLength: int(frame.Header().Length), } - s.Stream.buf.init() + s.Stream.buf.init(t.bufferPool) var ( // if false, content-type was missing or invalid isGRPC = false diff --git a/vendor/google.golang.org/grpc/internal/transport/transport.go b/vendor/google.golang.org/grpc/internal/transport/transport.go index d2e49538f..5fc901e5c 100644 --- a/vendor/google.golang.org/grpc/internal/transport/transport.go +++ b/vendor/google.golang.org/grpc/internal/transport/transport.go @@ -30,11 +30,14 @@ import ( "sync" "sync/atomic" "time" + "unsafe" "golang.org/x/net/http2" "google.golang.org/grpc/codes" "google.golang.org/grpc/credentials" "google.golang.org/grpc/internal/channelz" + "google.golang.org/grpc/internal/envconfig" + imem "google.golang.org/grpc/internal/mem" "google.golang.org/grpc/internal/transport/internal" "google.golang.org/grpc/keepalive" "google.golang.org/grpc/mem" @@ -45,7 +48,30 @@ import ( "google.golang.org/grpc/tap" ) -const logLevel = 2 +const ( + logLevel = 2 + // recvMsgSize estimates the memory overhead of a recvMsg in the backlog. + // It accounts for the recvMsg struct itself and the slice header of the + // underlying buffer's data. + recvMsgSize = int(unsafe.Sizeof(recvMsg{}) + unsafe.Sizeof([]byte{})) + + // utilizationFactor controls when we consider memory utilization acceptable. + // When backlogHeapSize / payloadSize <= utilizationFactor (meaning at least + // 50% of the heap memory is actual payload data), compaction is skipped. + utilizationFactor = 2 +) + +var ( + // compactionThreshold is approx 57KB (on 64-bit systems). It allows + // accumulating up to 1024 1-byte payloads before triggering compaction. + // + // Because individual payloads <= 1024 bytes are allocated on the heap + // outside mem.BufferPool, waiting for at least 1024 bytes to accumulate + // ensures that compaction coalesces those small heap allocations into a + // single large buffer from mem.BufferPool, enabling buffer reuse while + // avoiding frequent copying for small bursts of frames. + compactionThreshold = imem.BufferPoolingThreshold * (recvMsgSize + 1) +) func init() { internal.TimeNowFunc = func() int64 { return time.Now().UnixNano() } @@ -71,23 +97,31 @@ type recvBuffer struct { c chan recvMsg mu sync.Mutex backlog []recvMsg - err error + // uncompactedSuffixLen tracks the number of consecutive data messages at + // the tail of backlog that have not been compacted. + uncompactedSuffixLen int + // uncompactedBytes tracks the total payload bytes across the trailing + // uncompactedSuffixLen messages. + uncompactedBytes int + err error + bufPool mem.BufferPool } // init allows a recvBuffer to be initialized in-place, which is useful // for resetting a buffer or for avoiding a heap allocation when the buffer // is embedded in another struct. -func (b *recvBuffer) init() { +func (b *recvBuffer) init(pool mem.BufferPool) { b.c = make(chan recvMsg, 1) + b.bufPool = pool } func (b *recvBuffer) put(r recvMsg) { b.mu.Lock() + defer b.mu.Unlock() if b.err != nil { // drop the buffer on the floor. Since b.err is not nil, any subsequent reads // will always return an error, making this buffer inaccessible. r.buffer.Free() - b.mu.Unlock() // An error had occurred earlier, don't accept more // data or errors. return @@ -96,13 +130,70 @@ func (b *recvBuffer) put(r recvMsg) { if len(b.backlog) == 0 { select { case b.c <- r: - b.mu.Unlock() return default: } } b.backlog = append(b.backlog, r) - b.mu.Unlock() + b.compactBacklogLocked(r) +} + +func (b *recvBuffer) compactBacklogLocked(r recvMsg) { + if !envconfig.EnableReceiveBufferCompaction { + return + } + if r.buffer == nil { + b.uncompactedBytes = 0 + b.uncompactedSuffixLen = 0 + return + } + + b.uncompactedSuffixLen++ + b.uncompactedBytes += r.buffer.Len() + backlogHeapSize := b.uncompactedSuffixLen*recvMsgSize + b.uncompactedBytes + + // If the memory overhead is less than 50% of the heap usage (e.g., because + // a large DATA frame arrived), the average message size in the suffix is + // large enough that memory bloat is not a concern. Reset suffix tracking. + if backlogHeapSize <= utilizationFactor*b.uncompactedBytes { + b.uncompactedBytes = 0 + b.uncompactedSuffixLen = 0 + return + } + // Avoid compacting too frequently for short bursts of small frames. + // Wait until we have accumulated at least ~1024 small messages (~57 KB). + if backlogHeapSize <= compactionThreshold { + // Still can accumulate more payloads. + return + } + + // Since the memory utilization is less than 50%, the average payload size + // of each recvMsg must be less than recvMsgSize (approx 56 bytes). + // In the worst case for bytes copied (where the average payload is just + // below recvMsgSize), compaction will occur once every: + // compactionThreshold / (recvMsgSize + avg_payload) = ~520 messages, + // copying ~29KB of data. + + start := 0 + newBuf := b.bufPool.Get(b.uncompactedBytes) + startIdx := len(b.backlog) - b.uncompactedSuffixLen + + for i := startIdx; i < len(b.backlog); i++ { + m := b.backlog[i] + b.backlog[i] = recvMsg{} + start += copy((*newBuf)[start:], m.buffer.ReadOnlyData()) + m.buffer.Free() + } + b.backlog[startIdx] = recvMsg{ + buffer: mem.NewBuffer(newBuf, b.bufPool), + } + b.backlog = b.backlog[:startIdx+1] + // After compaction, the suffix is replaced with a single message containing + // the combined payload. The new utilization is close to 1.0 (overhead of + // one recvMsg relative to the large compacted payload), which is well + // below the utilization factor of 2. + b.uncompactedBytes = 0 + b.uncompactedSuffixLen = 0 } func (b *recvBuffer) load() { @@ -110,6 +201,13 @@ func (b *recvBuffer) load() { if len(b.backlog) > 0 { select { case b.c <- b.backlog[0]: + // backlog[0] is only part of the tracked uncompacted suffix if the + // entire backlog currently consists of the suffix. If an earlier + // compaction or reset occurred, backlog[0] is already compacted. + if envconfig.EnableReceiveBufferCompaction && b.uncompactedSuffixLen == len(b.backlog) { + b.uncompactedSuffixLen-- + b.uncompactedBytes -= b.backlog[0].buffer.Len() + } b.backlog[0] = recvMsg{} b.backlog = b.backlog[1:] default: diff --git a/vendor/google.golang.org/grpc/mem/buffer_pool.go b/vendor/google.golang.org/grpc/mem/buffer_pool.go index 3b02b9091..aa121379f 100644 --- a/vendor/google.golang.org/grpc/mem/buffer_pool.go +++ b/vendor/google.golang.org/grpc/mem/buffer_pool.go @@ -59,10 +59,6 @@ func init() { internal.SetDefaultBufferPool = func(pool BufferPool) { defaultBufferPool = pool } - - internal.SetBufferPoolingThresholdForTesting = func(threshold int) { - bufferPoolingThreshold = threshold - } } // DefaultBufferPool returns the current default buffer pool. It is a BufferPool diff --git a/vendor/google.golang.org/grpc/mem/buffers.go b/vendor/google.golang.org/grpc/mem/buffers.go index 2b410b16e..9b355d446 100644 --- a/vendor/google.golang.org/grpc/mem/buffers.go +++ b/vendor/google.golang.org/grpc/mem/buffers.go @@ -29,6 +29,8 @@ import ( "fmt" "sync" "sync/atomic" + + "google.golang.org/grpc/internal/mem" ) // A Buffer represents a reference counted piece of data (in bytes) that can be @@ -63,8 +65,6 @@ type Buffer interface { } var ( - bufferPoolingThreshold = 1 << 10 - bufferObjectPool = sync.Pool{New: func() any { return new(buffer) }} ) @@ -72,7 +72,7 @@ var ( // equal to the threshold for buffer pooling. This is used to determine whether // to pool buffers or allocate them directly. func IsBelowBufferPoolingThreshold(size int) bool { - return size <= bufferPoolingThreshold + return size <= mem.BufferPoolingThreshold } type buffer struct { diff --git a/vendor/google.golang.org/grpc/version.go b/vendor/google.golang.org/grpc/version.go index 4083c0390..64ec3b3cf 100644 --- a/vendor/google.golang.org/grpc/version.go +++ b/vendor/google.golang.org/grpc/version.go @@ -19,4 +19,4 @@ package grpc // Version is the current grpc version. -const Version = "1.83.0" +const Version = "1.83.1" diff --git a/vendor/google.golang.org/protobuf/encoding/protodelim/protodelim.go b/vendor/google.golang.org/protobuf/encoding/protodelim/protodelim.go index 2ef36bbcf..ec63689e7 100644 --- a/vendor/google.golang.org/protobuf/encoding/protodelim/protodelim.go +++ b/vendor/google.golang.org/protobuf/encoding/protodelim/protodelim.go @@ -10,6 +10,7 @@ import ( "encoding/binary" "fmt" "io" + "math" "google.golang.org/protobuf/encoding/protowire" "google.golang.org/protobuf/internal/errors" @@ -117,7 +118,13 @@ func (o UnmarshalOptions) UnmarshalFrom(r Reader, m proto.Message) error { if maxSize == 0 { maxSize = defaultMaxSize } - if maxSize != -1 && size > uint64(maxSize) { + if maxSize == -1 { + // No limit specified: Just check that size fits into an integer, + // otherwise the make([]byte, size) call below will panic. + if size > math.MaxInt { + return errors.Wrap(&SizeTooLargeError{Size: size, MaxSize: math.MaxInt}, "") + } + } else if size > uint64(maxSize) { return errors.Wrap(&SizeTooLargeError{Size: size, MaxSize: uint64(maxSize)}, "") } diff --git a/vendor/google.golang.org/protobuf/encoding/protojson/decode.go b/vendor/google.golang.org/protobuf/encoding/protojson/decode.go index 737d6876d..1d6608dc7 100644 --- a/vendor/google.golang.org/protobuf/encoding/protojson/decode.go +++ b/vendor/google.golang.org/protobuf/encoding/protojson/decode.go @@ -365,6 +365,10 @@ func unmarshalInt(tok json.Token, bitSize int) (protoreflect.Value, bool) { if err != nil { return protoreflect.Value{}, false } + // Ensure there is no non-number content in this string. + if next, err := dec.Read(); err != nil || next.Kind() != json.EOF { + return protoreflect.Value{}, false + } return getInt(tok, bitSize) } return protoreflect.Value{}, false @@ -397,6 +401,10 @@ func unmarshalUint(tok json.Token, bitSize int) (protoreflect.Value, bool) { if err != nil { return protoreflect.Value{}, false } + // Ensure there is no non-number content in this string. + if next, err := dec.Read(); err != nil || next.Kind() != json.EOF { + return protoreflect.Value{}, false + } return getUint(tok, bitSize) } return protoreflect.Value{}, false @@ -447,6 +455,10 @@ func unmarshalFloat(tok json.Token, bitSize int) (protoreflect.Value, bool) { if err != nil { return protoreflect.Value{}, false } + // Ensure there is no non-number content in this string. + if next, err := dec.Read(); err != nil || next.Kind() != json.EOF { + return protoreflect.Value{}, false + } return getFloat(tok, bitSize) } return protoreflect.Value{}, false diff --git a/vendor/google.golang.org/protobuf/encoding/protojson/well_known_types.go b/vendor/google.golang.org/protobuf/encoding/protojson/well_known_types.go index e9fe10394..d2eab4694 100644 --- a/vendor/google.golang.org/protobuf/encoding/protojson/well_known_types.go +++ b/vendor/google.golang.org/protobuf/encoding/protojson/well_known_types.go @@ -52,7 +52,10 @@ func wellKnownTypeMarshaler(name protoreflect.FullName) marshalFunc { case genid.FieldMask_message_name: return encoder.marshalFieldMask case genid.Empty_message_name: - return encoder.marshalEmpty + // The spec explicitly specifies that the Empty message + // is not considered to have any special JSON mapping: + // https://protobuf.dev/programming-guides/json/#any + return nil } } return nil diff --git a/vendor/google.golang.org/protobuf/encoding/prototext/decode.go b/vendor/google.golang.org/protobuf/encoding/prototext/decode.go index b53805056..20ec09e19 100644 --- a/vendor/google.golang.org/protobuf/encoding/prototext/decode.go +++ b/vendor/google.golang.org/protobuf/encoding/prototext/decode.go @@ -8,6 +8,7 @@ import ( "fmt" "unicode/utf8" + "google.golang.org/protobuf/encoding/protowire" "google.golang.org/protobuf/internal/encoding/messageset" "google.golang.org/protobuf/internal/encoding/text" "google.golang.org/protobuf/internal/errors" @@ -49,12 +50,19 @@ type UnmarshalOptions struct { protoregistry.MessageTypeResolver protoregistry.ExtensionTypeResolver } + + // RecursionLimit limits how deeply messages may be nested. + // If zero, a default limit is applied. + RecursionLimit int } // Unmarshal reads the given []byte and populates the given [proto.Message] // using options in the UnmarshalOptions object. // The provided message must be mutable (e.g., a non-nil pointer to a message). func (o UnmarshalOptions) Unmarshal(b []byte, m proto.Message) error { + if o.RecursionLimit == 0 { + o.RecursionLimit = protowire.DefaultRecursionLimit + } return o.unmarshal(b, m) } @@ -102,8 +110,14 @@ func (d decoder) syntaxError(pos int, f string, x ...any) error { return errors.New(head+f, x...) } +var errRecursionDepth = errors.New("exceeded maximum recursion depth") + // unmarshalMessage unmarshals into the given protoreflect.Message. func (d decoder) unmarshalMessage(m protoreflect.Message, checkDelims bool) error { + if d.opts.RecursionLimit--; d.opts.RecursionLimit < 0 { + return errRecursionDepth + } + messageDesc := m.Descriptor() if !flags.ProtoLegacy && messageset.IsMessageSet(messageDesc) { return errors.New("no support for proto1 MessageSets") @@ -437,6 +451,10 @@ func (d decoder) unmarshalList(fd protoreflect.FieldDescriptor, list protoreflec // unmarshalMap unmarshals into given protoreflect.Map. A map value is a // textproto message containing {key: , value: }. func (d decoder) unmarshalMap(fd protoreflect.FieldDescriptor, mmap protoreflect.Map) error { + if d.opts.RecursionLimit--; d.opts.RecursionLimit < 0 { + return errRecursionDepth + } + // Determine ahead whether map entry is a scalar type or a message type in // order to call the appropriate unmarshalMapValue func inside // unmarshalMapEntry. diff --git a/vendor/google.golang.org/protobuf/internal/descfmt/stringer.go b/vendor/google.golang.org/protobuf/internal/descfmt/stringer.go index 87e46bd4d..0b0dfacbe 100644 --- a/vendor/google.golang.org/protobuf/internal/descfmt/stringer.go +++ b/vendor/google.golang.org/protobuf/internal/descfmt/stringer.go @@ -83,12 +83,13 @@ func formatListOpt(vs list, isRoot, allowMulti bool) string { case protoreflect.FileImports: for i := 0; i < vs.Len(); i++ { var rs records - rv := reflect.ValueOf(vs.Get(i)) - rs.Append(rv, []methodAndName{ - {rv.MethodByName("Path"), "Path"}, - {rv.MethodByName("Package"), "Package"}, - {rv.MethodByName("IsPublic"), "IsPublic"}, - {rv.MethodByName("IsWeak"), "IsWeak"}, + fi := vs.Get(i) + rv := reflect.ValueOf(fi) + rs.Append(rv, []attrAndName{ + {fi.Path(), "Path"}, + {fi.Package(), "Package"}, + {fi.IsPublic, "IsPublic"}, + {fi.IsWeak, "IsWeak"}, }...) ss = append(ss, "{"+rs.Join()+"}") } @@ -104,9 +105,9 @@ func formatListOpt(vs list, isRoot, allowMulti bool) string { } } -type methodAndName struct { - method reflect.Value - name string +type attrAndName struct { + attr any + name string } func FormatDesc(s fmt.State, r rune, t protoreflect.Descriptor) { @@ -126,58 +127,58 @@ func formatDescOpt(t protoreflect.Descriptor, isRoot, allowMulti bool, record fu start = rt.Name() + "{" } - _, isFile := t.(protoreflect.FileDescriptor) + fd, isFile := t.(protoreflect.FileDescriptor) rs := records{ allowMulti: allowMulti, record: record, } if t.IsPlaceholder() { if isFile { - rs.Append(rv, []methodAndName{ - {rv.MethodByName("Path"), "Path"}, - {rv.MethodByName("Package"), "Package"}, - {rv.MethodByName("IsPlaceholder"), "IsPlaceholder"}, + rs.Append(rv, []attrAndName{ + {fd.Path(), "Path"}, + {fd.Package(), "Package"}, + {fd.IsPlaceholder(), "IsPlaceholder"}, }...) } else { - rs.Append(rv, []methodAndName{ - {rv.MethodByName("FullName"), "FullName"}, - {rv.MethodByName("IsPlaceholder"), "IsPlaceholder"}, + rs.Append(rv, []attrAndName{ + {t.FullName(), "FullName"}, + {t.IsPlaceholder(), "IsPlaceholder"}, }...) } } else { switch { case isFile: - rs.Append(rv, methodAndName{rv.MethodByName("Syntax"), "Syntax"}) + rs.Append(rv, attrAndName{fd.Syntax(), "Syntax"}) case isRoot: - rs.Append(rv, []methodAndName{ - {rv.MethodByName("Syntax"), "Syntax"}, - {rv.MethodByName("FullName"), "FullName"}, + rs.Append(rv, []attrAndName{ + {t.Syntax(), "Syntax"}, + {t.FullName(), "FullName"}, }...) default: - rs.Append(rv, methodAndName{rv.MethodByName("Name"), "Name"}) + rs.Append(rv, attrAndName{t.Name(), "Name"}) } switch t := t.(type) { case protoreflect.FieldDescriptor: - accessors := []methodAndName{ - {rv.MethodByName("Number"), "Number"}, - {rv.MethodByName("Cardinality"), "Cardinality"}, - {rv.MethodByName("Kind"), "Kind"}, - {rv.MethodByName("HasJSONName"), "HasJSONName"}, - {rv.MethodByName("JSONName"), "JSONName"}, - {rv.MethodByName("HasPresence"), "HasPresence"}, - {rv.MethodByName("IsExtension"), "IsExtension"}, - {rv.MethodByName("IsPacked"), "IsPacked"}, - {rv.MethodByName("IsWeak"), "IsWeak"}, - {rv.MethodByName("IsList"), "IsList"}, - {rv.MethodByName("IsMap"), "IsMap"}, - {rv.MethodByName("MapKey"), "MapKey"}, - {rv.MethodByName("MapValue"), "MapValue"}, - {rv.MethodByName("HasDefault"), "HasDefault"}, - {rv.MethodByName("Default"), "Default"}, - {rv.MethodByName("ContainingOneof"), "ContainingOneof"}, - {rv.MethodByName("ContainingMessage"), "ContainingMessage"}, - {rv.MethodByName("Message"), "Message"}, - {rv.MethodByName("Enum"), "Enum"}, + accessors := []attrAndName{ + {t.Number(), "Number"}, + {t.Cardinality(), "Cardinality"}, + {t.Kind(), "Kind"}, + {t.HasJSONName(), "HasJSONName"}, + {t.JSONName(), "JSONName"}, + {t.HasPresence(), "HasPresence"}, + {t.IsExtension(), "IsExtension"}, + {t.IsPacked(), "IsPacked"}, + {t.IsWeak(), "IsWeak"}, + {t.IsList(), "IsList"}, + {t.IsMap(), "IsMap"}, + {t.MapKey(), "MapKey"}, + {t.MapValue(), "MapValue"}, + {t.HasDefault(), "HasDefault"}, + {t.Default(), "Default"}, + {t.ContainingOneof(), "ContainingOneof"}, + {t.ContainingMessage(), "ContainingMessage"}, + {t.Message(), "Message"}, + {t.Enum(), "Enum"}, } for _, s := range accessors { switch s.name { @@ -223,58 +224,54 @@ func formatDescOpt(t protoreflect.Descriptor, isRoot, allowMulti bool, record fu } case protoreflect.FileDescriptor: - rs.Append(rv, []methodAndName{ - {rv.MethodByName("Path"), "Path"}, - {rv.MethodByName("Package"), "Package"}, - {rv.MethodByName("Imports"), "Imports"}, - {rv.MethodByName("Messages"), "Messages"}, - {rv.MethodByName("Enums"), "Enums"}, - {rv.MethodByName("Extensions"), "Extensions"}, - {rv.MethodByName("Services"), "Services"}, + rs.Append(rv, []attrAndName{ + {t.Path(), "Path"}, + {t.Package(), "Package"}, + {t.Imports(), "Imports"}, + {t.Messages(), "Messages"}, + {t.Enums(), "Enums"}, + {t.Extensions(), "Extensions"}, + {t.Services(), "Services"}, }...) case protoreflect.MessageDescriptor: - rs.Append(rv, []methodAndName{ - {rv.MethodByName("IsMapEntry"), "IsMapEntry"}, - {rv.MethodByName("Fields"), "Fields"}, - {rv.MethodByName("Oneofs"), "Oneofs"}, - {rv.MethodByName("ReservedNames"), "ReservedNames"}, - {rv.MethodByName("ReservedRanges"), "ReservedRanges"}, - {rv.MethodByName("RequiredNumbers"), "RequiredNumbers"}, - {rv.MethodByName("ExtensionRanges"), "ExtensionRanges"}, - {rv.MethodByName("Messages"), "Messages"}, - {rv.MethodByName("Enums"), "Enums"}, - {rv.MethodByName("Extensions"), "Extensions"}, + rs.Append(rv, []attrAndName{ + {t.IsMapEntry(), "IsMapEntry"}, + {t.Fields(), "Fields"}, + {t.Oneofs(), "Oneofs"}, + {t.ReservedNames(), "ReservedNames"}, + {t.ReservedRanges(), "ReservedRanges"}, + {t.RequiredNumbers(), "RequiredNumbers"}, + {t.ExtensionRanges(), "ExtensionRanges"}, + {t.Messages(), "Messages"}, + {t.Enums(), "Enums"}, + {t.Extensions(), "Extensions"}, }...) case protoreflect.EnumDescriptor: - rs.Append(rv, []methodAndName{ - {rv.MethodByName("Values"), "Values"}, - {rv.MethodByName("ReservedNames"), "ReservedNames"}, - {rv.MethodByName("ReservedRanges"), "ReservedRanges"}, - {rv.MethodByName("IsClosed"), "IsClosed"}, + rs.Append(rv, []attrAndName{ + {t.Values(), "Values"}, + {t.ReservedNames(), "ReservedNames"}, + {t.ReservedRanges(), "ReservedRanges"}, + {t.IsClosed(), "IsClosed"}, }...) case protoreflect.EnumValueDescriptor: - rs.Append(rv, []methodAndName{ - {rv.MethodByName("Number"), "Number"}, - }...) + rs.Append(rv, attrAndName{t.Number(), "Number"}) case protoreflect.ServiceDescriptor: - rs.Append(rv, []methodAndName{ - {rv.MethodByName("Methods"), "Methods"}, - }...) + rs.Append(rv, attrAndName{t.Methods(), "Methods"}) case protoreflect.MethodDescriptor: - rs.Append(rv, []methodAndName{ - {rv.MethodByName("Input"), "Input"}, - {rv.MethodByName("Output"), "Output"}, - {rv.MethodByName("IsStreamingClient"), "IsStreamingClient"}, - {rv.MethodByName("IsStreamingServer"), "IsStreamingServer"}, + rs.Append(rv, []attrAndName{ + {t.Input(), "Input"}, + {t.Output(), "Output"}, + {t.IsStreamingClient(), "IsStreamingClient"}, + {t.IsStreamingServer(), "IsStreamingServer"}, }...) } - if m := rv.MethodByName("GoType"); m.IsValid() { - rs.Append(rv, methodAndName{m, "GoType"}) + if m, ok := t.(interface{ GoType() reflect.Type }); ok { + rs.Append(rv, attrAndName{m.GoType(), "GoType"}) } } return start + rs.Join() + end @@ -297,68 +294,66 @@ func (rs *records) AppendRecs(fieldName string, newRecs [2]string) { rs.recs = append(rs.recs, newRecs) } -func (rs *records) Append(v reflect.Value, accessors ...methodAndName) { - for _, a := range accessors { - if rs.record != nil { - rs.record(a.name) - } - var rv reflect.Value - if a.method.IsValid() { - rv = a.method.Call(nil)[0] - } - if v.Kind() == reflect.Struct && !rv.IsValid() { - rv = v.FieldByName(a.name) - } - if !rv.IsValid() { - panic(fmt.Sprintf("unknown accessor: %v.%s", v.Type(), a.name)) - } - if _, ok := rv.Interface().(protoreflect.Value); ok { - rv = rv.MethodByName("Interface").Call(nil)[0] - if !rv.IsNil() { - rv = rv.Elem() - } - } +func (rs *records) Append(v reflect.Value, results ...attrAndName) { + for _, r := range results { + rs.appendAttribute(v, r.name, r.attr) + } +} - // Ignore zero values. - var isZero bool - switch rv.Kind() { - case reflect.Interface, reflect.Slice: - isZero = rv.IsNil() - case reflect.Bool: - isZero = rv.Bool() == false - case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - isZero = rv.Int() == 0 - case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: - isZero = rv.Uint() == 0 - case reflect.String: - isZero = rv.String() == "" - } - if n, ok := rv.Interface().(list); ok { - isZero = n.Len() == 0 - } - if isZero { - continue +func (rs *records) appendAttribute(val reflect.Value, name string, attrVal any) { + if rs.record != nil { + rs.record(name) + } + if attrVal == nil { + return + } + rv := reflect.ValueOf(attrVal) + if _, ok := rv.Interface().(protoreflect.Value); ok { + rv = rv.MethodByName("Interface").Call(nil)[0] + if !rv.IsNil() { + rv = rv.Elem() } + } - // Format the value. - var s string - v := rv.Interface() - switch v := v.(type) { - case list: - s = formatListOpt(v, false, rs.allowMulti) - case protoreflect.FieldDescriptor, protoreflect.OneofDescriptor, protoreflect.EnumValueDescriptor, protoreflect.MethodDescriptor: - s = string(v.(protoreflect.Descriptor).Name()) - case protoreflect.Descriptor: - s = string(v.FullName()) - case string: - s = strconv.Quote(v) - case []byte: - s = fmt.Sprintf("%q", v) - default: - s = fmt.Sprint(v) - } - rs.recs = append(rs.recs, [2]string{a.name, s}) + // Ignore zero values. + var isZero bool + switch rv.Kind() { + case reflect.Interface, reflect.Slice: + isZero = rv.IsNil() + case reflect.Bool: + isZero = rv.Bool() == false + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + isZero = rv.Int() == 0 + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: + isZero = rv.Uint() == 0 + case reflect.String: + isZero = rv.String() == "" + } + if n, ok := rv.Interface().(list); ok { + isZero = n.Len() == 0 + } + if isZero { + return + } + + // Format the value. + var s string + v := rv.Interface() + switch v := v.(type) { + case list: + s = formatListOpt(v, false, rs.allowMulti) + case protoreflect.FieldDescriptor, protoreflect.OneofDescriptor, protoreflect.EnumValueDescriptor, protoreflect.MethodDescriptor: + s = string(v.(protoreflect.Descriptor).Name()) + case protoreflect.Descriptor: + s = string(v.FullName()) + case string: + s = strconv.Quote(v) + case []byte: + s = fmt.Sprintf("%q", v) + default: + s = fmt.Sprint(v) } + rs.recs = append(rs.recs, [2]string{name, s}) } func (rs *records) Join() string { diff --git a/vendor/google.golang.org/protobuf/internal/editiondefaults/editions_defaults.binpb b/vendor/google.golang.org/protobuf/internal/editiondefaults/editions_defaults.binpb index 04696351eeeef14cbbd69fd1f4250530b1fbfd56..ad35ea4c449a6b23a78974a905b3fcba120223c6 100644 GIT binary patch delta 50 zcmbQmxSw&t6m2eLiGDvNNe)H>4lG0U`MWs{jB1 diff --git a/vendor/google.golang.org/protobuf/internal/encoding/defval/default.go b/vendor/google.golang.org/protobuf/internal/encoding/defval/default.go index 328dc733b..079a53dd1 100644 --- a/vendor/google.golang.org/protobuf/internal/encoding/defval/default.go +++ b/vendor/google.golang.org/protobuf/internal/encoding/defval/default.go @@ -69,19 +69,19 @@ func Unmarshal(s string, k protoreflect.Kind, evs protoreflect.EnumValueDescript } } case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind: - if v, err := strconv.ParseInt(s, 10, 32); err == nil { + if v, err := strconv.ParseInt(s, 0, 32); err == nil { return protoreflect.ValueOfInt32(int32(v)), nil, nil } case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: - if v, err := strconv.ParseInt(s, 10, 64); err == nil { + if v, err := strconv.ParseInt(s, 0, 64); err == nil { return protoreflect.ValueOfInt64(int64(v)), nil, nil } case protoreflect.Uint32Kind, protoreflect.Fixed32Kind: - if v, err := strconv.ParseUint(s, 10, 32); err == nil { + if v, err := strconv.ParseUint(s, 0, 32); err == nil { return protoreflect.ValueOfUint32(uint32(v)), nil, nil } case protoreflect.Uint64Kind, protoreflect.Fixed64Kind: - if v, err := strconv.ParseUint(s, 10, 64); err == nil { + if v, err := strconv.ParseUint(s, 0, 64); err == nil { return protoreflect.ValueOfUint64(uint64(v)), nil, nil } case protoreflect.FloatKind, protoreflect.DoubleKind: diff --git a/vendor/google.golang.org/protobuf/internal/genid/descriptor_gen.go b/vendor/google.golang.org/protobuf/internal/genid/descriptor_gen.go index 65aaf4d21..58aeff845 100644 --- a/vendor/google.golang.org/protobuf/internal/genid/descriptor_gen.go +++ b/vendor/google.golang.org/protobuf/internal/genid/descriptor_gen.go @@ -26,6 +26,7 @@ const ( Edition_EDITION_PROTO3_enum_value = 999 Edition_EDITION_2023_enum_value = 1000 Edition_EDITION_2024_enum_value = 1001 + Edition_EDITION_2026_enum_value = 1002 Edition_EDITION_UNSTABLE_enum_value = 9999 Edition_EDITION_1_TEST_ONLY_enum_value = 1 Edition_EDITION_2_TEST_ONLY_enum_value = 2 @@ -806,11 +807,13 @@ const ( FieldOptions_FeatureSupport_EditionDeprecated_field_name protoreflect.Name = "edition_deprecated" FieldOptions_FeatureSupport_DeprecationWarning_field_name protoreflect.Name = "deprecation_warning" FieldOptions_FeatureSupport_EditionRemoved_field_name protoreflect.Name = "edition_removed" + FieldOptions_FeatureSupport_RemovalError_field_name protoreflect.Name = "removal_error" FieldOptions_FeatureSupport_EditionIntroduced_field_fullname protoreflect.FullName = "google.protobuf.FieldOptions.FeatureSupport.edition_introduced" FieldOptions_FeatureSupport_EditionDeprecated_field_fullname protoreflect.FullName = "google.protobuf.FieldOptions.FeatureSupport.edition_deprecated" FieldOptions_FeatureSupport_DeprecationWarning_field_fullname protoreflect.FullName = "google.protobuf.FieldOptions.FeatureSupport.deprecation_warning" FieldOptions_FeatureSupport_EditionRemoved_field_fullname protoreflect.FullName = "google.protobuf.FieldOptions.FeatureSupport.edition_removed" + FieldOptions_FeatureSupport_RemovalError_field_fullname protoreflect.FullName = "google.protobuf.FieldOptions.FeatureSupport.removal_error" ) // Field numbers for google.protobuf.FieldOptions.FeatureSupport. @@ -819,6 +822,7 @@ const ( FieldOptions_FeatureSupport_EditionDeprecated_field_number protoreflect.FieldNumber = 2 FieldOptions_FeatureSupport_DeprecationWarning_field_number protoreflect.FieldNumber = 3 FieldOptions_FeatureSupport_EditionRemoved_field_number protoreflect.FieldNumber = 4 + FieldOptions_FeatureSupport_RemovalError_field_number protoreflect.FieldNumber = 5 ) // Names for google.protobuf.OneofOptions. @@ -1152,6 +1156,7 @@ const ( FeatureSet_ENFORCE_NAMING_STYLE_UNKNOWN_enum_value = 0 FeatureSet_STYLE2024_enum_value = 1 FeatureSet_STYLE_LEGACY_enum_value = 2 + FeatureSet_STYLE2026_enum_value = 3 ) // Names for google.protobuf.FeatureSet.VisibilityFeature. diff --git a/vendor/google.golang.org/protobuf/internal/version/version.go b/vendor/google.golang.org/protobuf/internal/version/version.go index 763fd8284..58ff0e246 100644 --- a/vendor/google.golang.org/protobuf/internal/version/version.go +++ b/vendor/google.golang.org/protobuf/internal/version/version.go @@ -52,7 +52,7 @@ import ( const ( Major = 1 Minor = 36 - Patch = 11 + Patch = 12 PreRelease = "" ) diff --git a/vendor/google.golang.org/protobuf/reflect/protodesc/desc_init.go b/vendor/google.golang.org/protobuf/reflect/protodesc/desc_init.go index c826ad043..84a3228ed 100644 --- a/vendor/google.golang.org/protobuf/reflect/protodesc/desc_init.go +++ b/vendor/google.golang.org/protobuf/reflect/protodesc/desc_init.go @@ -201,6 +201,7 @@ func (r descsByName) initExtensionDeclarations(xds []*descriptorpb.FieldDescript return nil, err } x.L1.EditionFeatures = mergeEditionFeatures(parent, xd.GetOptions().GetFeatures()) + x.L2.IsProto3Optional = xd.GetProto3Optional() if opts := xd.GetOptions(); opts != nil { opts = proto.Clone(opts).(*descriptorpb.FieldOptions) x.L2.Options = func() protoreflect.ProtoMessage { return opts } diff --git a/vendor/google.golang.org/protobuf/reflect/protoreflect/source_gen.go b/vendor/google.golang.org/protobuf/reflect/protoreflect/source_gen.go index 730331e66..86f0d0926 100644 --- a/vendor/google.golang.org/protobuf/reflect/protoreflect/source_gen.go +++ b/vendor/google.golang.org/protobuf/reflect/protoreflect/source_gen.go @@ -546,6 +546,8 @@ func (p *SourcePath) appendFieldOptions_FeatureSupport(b []byte) []byte { b = p.appendSingularField(b, "deprecation_warning", nil) case 4: b = p.appendSingularField(b, "edition_removed", nil) + case 5: + b = p.appendSingularField(b, "removal_error", nil) } return b } diff --git a/vendor/google.golang.org/protobuf/types/descriptorpb/descriptor.pb.go b/vendor/google.golang.org/protobuf/types/descriptorpb/descriptor.pb.go index 0b23faa95..a51cb1e54 100644 --- a/vendor/google.golang.org/protobuf/types/descriptorpb/descriptor.pb.go +++ b/vendor/google.golang.org/protobuf/types/descriptorpb/descriptor.pb.go @@ -1,32 +1,9 @@ // Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ +// Copyright 2008 Google LLC. All rights reserved. // -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd // Author: kenton@google.com (Kenton Varda) // Based on original Protocol Buffers design by @@ -69,6 +46,7 @@ const ( // comparison. Edition_EDITION_2023 Edition = 1000 Edition_EDITION_2024 Edition = 1001 + Edition_EDITION_2026 Edition = 1002 // A placeholder edition for developing and testing unscheduled features. Edition_EDITION_UNSTABLE Edition = 9999 // Placeholder editions for testing feature resolution. These should not be @@ -93,6 +71,7 @@ var ( 999: "EDITION_PROTO3", 1000: "EDITION_2023", 1001: "EDITION_2024", + 1002: "EDITION_2026", 9999: "EDITION_UNSTABLE", 1: "EDITION_1_TEST_ONLY", 2: "EDITION_2_TEST_ONLY", @@ -108,6 +87,7 @@ var ( "EDITION_PROTO3": 999, "EDITION_2023": 1000, "EDITION_2024": 1001, + "EDITION_2026": 1002, "EDITION_UNSTABLE": 9999, "EDITION_1_TEST_ONLY": 1, "EDITION_2_TEST_ONLY": 2, @@ -1213,6 +1193,7 @@ const ( FeatureSet_ENFORCE_NAMING_STYLE_UNKNOWN FeatureSet_EnforceNamingStyle = 0 FeatureSet_STYLE2024 FeatureSet_EnforceNamingStyle = 1 FeatureSet_STYLE_LEGACY FeatureSet_EnforceNamingStyle = 2 + FeatureSet_STYLE2026 FeatureSet_EnforceNamingStyle = 3 ) // Enum value maps for FeatureSet_EnforceNamingStyle. @@ -1221,11 +1202,13 @@ var ( 0: "ENFORCE_NAMING_STYLE_UNKNOWN", 1: "STYLE2024", 2: "STYLE_LEGACY", + 3: "STYLE2026", } FeatureSet_EnforceNamingStyle_value = map[string]int32{ "ENFORCE_NAMING_STYLE_UNKNOWN": 0, "STYLE2024": 1, "STYLE_LEGACY": 2, + "STYLE2026": 3, } ) @@ -4204,8 +4187,11 @@ type FieldOptions_FeatureSupport struct { // this one, the last default assigned will be used, and proto files will // not be able to override it. EditionRemoved *Edition `protobuf:"varint,4,opt,name=edition_removed,json=editionRemoved,enum=google.protobuf.Edition" json:"edition_removed,omitempty"` - unknownFields protoimpl.UnknownFields - sizeCache protoimpl.SizeCache + // The removal error text if this feature is used after the edition it was + // removed in. + RemovalError *string `protobuf:"bytes,5,opt,name=removal_error,json=removalError" json:"removal_error,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } func (x *FieldOptions_FeatureSupport) Reset() { @@ -4266,6 +4252,13 @@ func (x *FieldOptions_FeatureSupport) GetEditionRemoved() Edition { return Edition_EDITION_UNKNOWN } +func (x *FieldOptions_FeatureSupport) GetRemovalError() string { + if x != nil && x.RemovalError != nil { + return *x.RemovalError + } + return "" +} + // The name of the uninterpreted option. Each string represents a segment in // a dot-separated name. is_extension is true iff a segment represents an // extension (denoted with parentheses in options specs in .proto files). @@ -4719,7 +4712,7 @@ const file_google_protobuf_descriptor_proto_rawDesc = "" + "\aoptions\x18\x03 \x01(\v2&.google.protobuf.ExtensionRangeOptionsR\aoptions\x1a7\n" + "\rReservedRange\x12\x14\n" + "\x05start\x18\x01 \x01(\x05R\x05start\x12\x10\n" + - "\x03end\x18\x02 \x01(\x05R\x03end\"\xcc\x04\n" + + "\x03end\x18\x02 \x01(\x05R\x03end\"\xd4\x04\n" + "\x15ExtensionRangeOptions\x12X\n" + "\x14uninterpreted_option\x18\xe7\a \x03(\v2$.google.protobuf.UninterpretedOptionR\x13uninterpretedOption\x12Y\n" + "\vdeclaration\x18\x02 \x03(\v22.google.protobuf.ExtensionRangeOptions.DeclarationB\x03\x88\x01\x02R\vdeclaration\x127\n" + @@ -4735,7 +4728,7 @@ const file_google_protobuf_descriptor_proto_rawDesc = "" + "\x11VerificationState\x12\x0f\n" + "\vDECLARATION\x10\x00\x12\x0e\n" + "\n" + - "UNVERIFIED\x10\x01*\t\b\xe8\a\x10\x80\x80\x80\x80\x02\"\xc1\x06\n" + + "UNVERIFIED\x10\x01*\x06\b\xde\a\x10\xe7\a*\t\b\xe8\a\x10\x80\x80\x80\x80\x02\"\xc1\x06\n" + "\x14FieldDescriptorProto\x12\x12\n" + "\x04name\x18\x01 \x01(\tR\x04name\x12\x16\n" + "\x06number\x18\x03 \x01(\x05R\x06number\x12A\n" + @@ -4810,12 +4803,13 @@ const file_google_protobuf_descriptor_proto_rawDesc = "" + "outputType\x128\n" + "\aoptions\x18\x04 \x01(\v2\x1e.google.protobuf.MethodOptionsR\aoptions\x120\n" + "\x10client_streaming\x18\x05 \x01(\b:\x05falseR\x0fclientStreaming\x120\n" + - "\x10server_streaming\x18\x06 \x01(\b:\x05falseR\x0fserverStreaming\"\xad\t\n" + + "\x10server_streaming\x18\x06 \x01(\b:\x05falseR\x0fserverStreaming\"\xfa\n" + + "\n" + "\vFileOptions\x12!\n" + "\fjava_package\x18\x01 \x01(\tR\vjavaPackage\x120\n" + - "\x14java_outer_classname\x18\b \x01(\tR\x12javaOuterClassname\x125\n" + + "\x14java_outer_classname\x18\b \x01(\tR\x12javaOuterClassname\x12\xf9\x01\n" + "\x13java_multiple_files\x18\n" + - " \x01(\b:\x05falseR\x11javaMultipleFiles\x12D\n" + + " \x01(\b:\x05falseB\xc1\x01\xb2\x01\xbd\x01\b\xe6\a \xe9\a*\xb4\x01This behavior is enabled by default in editions 2024 and above. To disable it, you can set `features.(pb.java).nest_in_file_class = YES` on individual messages, enums, or services.R\x11javaMultipleFiles\x12D\n" + "\x1djava_generate_equals_and_hash\x18\x14 \x01(\bB\x02\x18\x01R\x19javaGenerateEqualsAndHash\x12:\n" + "\x16java_string_check_utf8\x18\x1b \x01(\b:\x05falseR\x13javaStringCheckUtf8\x12S\n" + "\foptimize_for\x18\t \x01(\x0e2).google.protobuf.FileOptions.OptimizeMode:\x05SPEEDR\voptimizeFor\x12\x1d\n" + @@ -4840,7 +4834,7 @@ const file_google_protobuf_descriptor_proto_rawDesc = "" + "\fOptimizeMode\x12\t\n" + "\x05SPEED\x10\x01\x12\r\n" + "\tCODE_SIZE\x10\x02\x12\x10\n" + - "\fLITE_RUNTIME\x10\x03*\t\b\xe8\a\x10\x80\x80\x80\x80\x02J\x04\b*\x10+J\x04\b&\x10'R\x14php_generic_services\"\xf4\x03\n" + + "\fLITE_RUNTIME\x10\x03*\x06\b\xde\a\x10\xe7\a*\t\b\xe8\a\x10\x80\x80\x80\x80\x02J\x04\b*\x10+J\x04\b&\x10'R\x14php_generic_services\"\xfc\x03\n" + "\x0eMessageOptions\x12<\n" + "\x17message_set_wire_format\x18\x01 \x01(\b:\x05falseR\x14messageSetWireFormat\x12L\n" + "\x1fno_standard_descriptor_accessor\x18\x02 \x01(\b:\x05falseR\x1cnoStandardDescriptorAccessor\x12%\n" + @@ -4850,8 +4844,8 @@ const file_google_protobuf_descriptor_proto_rawDesc = "" + "\tmap_entry\x18\a \x01(\bR\bmapEntry\x12V\n" + "&deprecated_legacy_json_field_conflicts\x18\v \x01(\bB\x02\x18\x01R\"deprecatedLegacyJsonFieldConflicts\x127\n" + "\bfeatures\x18\f \x01(\v2\x1b.google.protobuf.FeatureSetR\bfeatures\x12X\n" + - "\x14uninterpreted_option\x18\xe7\a \x03(\v2$.google.protobuf.UninterpretedOptionR\x13uninterpretedOption*\t\b\xe8\a\x10\x80\x80\x80\x80\x02J\x04\b\x04\x10\x05J\x04\b\x05\x10\x06J\x04\b\x06\x10\aJ\x04\b\b\x10\tJ\x04\b\t\x10\n" + - "\"\xa1\r\n" + + "\x14uninterpreted_option\x18\xe7\a \x03(\v2$.google.protobuf.UninterpretedOptionR\x13uninterpretedOption*\x06\b\xde\a\x10\xe7\a*\t\b\xe8\a\x10\x80\x80\x80\x80\x02J\x04\b\x04\x10\x05J\x04\b\x05\x10\x06J\x04\b\x06\x10\aJ\x04\b\b\x10\tJ\x04\b\t\x10\n" + + "\"\xce\r\n" + "\fFieldOptions\x12A\n" + "\x05ctype\x18\x01 \x01(\x0e2#.google.protobuf.FieldOptions.CType:\x06STRINGR\x05ctype\x12\x16\n" + "\x06packed\x18\x02 \x01(\bR\x06packed\x12G\n" + @@ -4872,12 +4866,13 @@ const file_google_protobuf_descriptor_proto_rawDesc = "" + "\x14uninterpreted_option\x18\xe7\a \x03(\v2$.google.protobuf.UninterpretedOptionR\x13uninterpretedOption\x1aZ\n" + "\x0eEditionDefault\x122\n" + "\aedition\x18\x03 \x01(\x0e2\x18.google.protobuf.EditionR\aedition\x12\x14\n" + - "\x05value\x18\x02 \x01(\tR\x05value\x1a\x96\x02\n" + + "\x05value\x18\x02 \x01(\tR\x05value\x1a\xbb\x02\n" + "\x0eFeatureSupport\x12G\n" + "\x12edition_introduced\x18\x01 \x01(\x0e2\x18.google.protobuf.EditionR\x11editionIntroduced\x12G\n" + "\x12edition_deprecated\x18\x02 \x01(\x0e2\x18.google.protobuf.EditionR\x11editionDeprecated\x12/\n" + "\x13deprecation_warning\x18\x03 \x01(\tR\x12deprecationWarning\x12A\n" + - "\x0fedition_removed\x18\x04 \x01(\x0e2\x18.google.protobuf.EditionR\x0eeditionRemoved\"/\n" + + "\x0fedition_removed\x18\x04 \x01(\x0e2\x18.google.protobuf.EditionR\x0eeditionRemoved\x12#\n" + + "\rremoval_error\x18\x05 \x01(\tR\fremovalError\"/\n" + "\x05CType\x12\n" + "\n" + "\x06STRING\x10\x00\x12\b\n" + @@ -4901,10 +4896,10 @@ const file_google_protobuf_descriptor_proto_rawDesc = "" + "\x10TARGET_TYPE_ENUM\x10\x06\x12\x1a\n" + "\x16TARGET_TYPE_ENUM_ENTRY\x10\a\x12\x17\n" + "\x13TARGET_TYPE_SERVICE\x10\b\x12\x16\n" + - "\x12TARGET_TYPE_METHOD\x10\t*\t\b\xe8\a\x10\x80\x80\x80\x80\x02J\x04\b\x04\x10\x05J\x04\b\x12\x10\x13\"\xac\x01\n" + + "\x12TARGET_TYPE_METHOD\x10\t*\x06\b\xde\a\x10\xe7\a*\t\b\xe8\a\x10\x80\x80\x80\x80\x02J\x04\b\x04\x10\x05J\x04\b\x12\x10\x13\"\xb4\x01\n" + "\fOneofOptions\x127\n" + "\bfeatures\x18\x01 \x01(\v2\x1b.google.protobuf.FeatureSetR\bfeatures\x12X\n" + - "\x14uninterpreted_option\x18\xe7\a \x03(\v2$.google.protobuf.UninterpretedOptionR\x13uninterpretedOption*\t\b\xe8\a\x10\x80\x80\x80\x80\x02\"\xd1\x02\n" + + "\x14uninterpreted_option\x18\xe7\a \x03(\v2$.google.protobuf.UninterpretedOptionR\x13uninterpretedOption*\x06\b\xde\a\x10\xe7\a*\t\b\xe8\a\x10\x80\x80\x80\x80\x02\"\xd9\x02\n" + "\vEnumOptions\x12\x1f\n" + "\vallow_alias\x18\x02 \x01(\bR\n" + "allowAlias\x12%\n" + @@ -4913,7 +4908,7 @@ const file_google_protobuf_descriptor_proto_rawDesc = "" + "deprecated\x12V\n" + "&deprecated_legacy_json_field_conflicts\x18\x06 \x01(\bB\x02\x18\x01R\"deprecatedLegacyJsonFieldConflicts\x127\n" + "\bfeatures\x18\a \x01(\v2\x1b.google.protobuf.FeatureSetR\bfeatures\x12X\n" + - "\x14uninterpreted_option\x18\xe7\a \x03(\v2$.google.protobuf.UninterpretedOptionR\x13uninterpretedOption*\t\b\xe8\a\x10\x80\x80\x80\x80\x02J\x04\b\x05\x10\x06\"\xd8\x02\n" + + "\x14uninterpreted_option\x18\xe7\a \x03(\v2$.google.protobuf.UninterpretedOptionR\x13uninterpretedOption*\x06\b\xde\a\x10\xe7\a*\t\b\xe8\a\x10\x80\x80\x80\x80\x02J\x04\b\x05\x10\x06\"\xe0\x02\n" + "\x10EnumValueOptions\x12%\n" + "\n" + "deprecated\x18\x01 \x01(\b:\x05falseR\n" + @@ -4921,13 +4916,13 @@ const file_google_protobuf_descriptor_proto_rawDesc = "" + "\bfeatures\x18\x02 \x01(\v2\x1b.google.protobuf.FeatureSetR\bfeatures\x12(\n" + "\fdebug_redact\x18\x03 \x01(\b:\x05falseR\vdebugRedact\x12U\n" + "\x0ffeature_support\x18\x04 \x01(\v2,.google.protobuf.FieldOptions.FeatureSupportR\x0efeatureSupport\x12X\n" + - "\x14uninterpreted_option\x18\xe7\a \x03(\v2$.google.protobuf.UninterpretedOptionR\x13uninterpretedOption*\t\b\xe8\a\x10\x80\x80\x80\x80\x02\"\xd5\x01\n" + + "\x14uninterpreted_option\x18\xe7\a \x03(\v2$.google.protobuf.UninterpretedOptionR\x13uninterpretedOption*\x06\b\xde\a\x10\xe7\a*\t\b\xe8\a\x10\x80\x80\x80\x80\x02\"\xdd\x01\n" + "\x0eServiceOptions\x127\n" + "\bfeatures\x18\" \x01(\v2\x1b.google.protobuf.FeatureSetR\bfeatures\x12%\n" + "\n" + "deprecated\x18! \x01(\b:\x05falseR\n" + "deprecated\x12X\n" + - "\x14uninterpreted_option\x18\xe7\a \x03(\v2$.google.protobuf.UninterpretedOptionR\x13uninterpretedOption*\t\b\xe8\a\x10\x80\x80\x80\x80\x02\"\x99\x03\n" + + "\x14uninterpreted_option\x18\xe7\a \x03(\v2$.google.protobuf.UninterpretedOptionR\x13uninterpretedOption*\x06\b\xde\a\x10\xe7\a*\t\b\xe8\a\x10\x80\x80\x80\x80\x02\"\xa1\x03\n" + "\rMethodOptions\x12%\n" + "\n" + "deprecated\x18! \x01(\b:\x05falseR\n" + @@ -4939,7 +4934,7 @@ const file_google_protobuf_descriptor_proto_rawDesc = "" + "\x13IDEMPOTENCY_UNKNOWN\x10\x00\x12\x13\n" + "\x0fNO_SIDE_EFFECTS\x10\x01\x12\x0e\n" + "\n" + - "IDEMPOTENT\x10\x02*\t\b\xe8\a\x10\x80\x80\x80\x80\x02\"\x9a\x03\n" + + "IDEMPOTENT\x10\x02*\x06\b\xde\a\x10\xe7\a*\t\b\xe8\a\x10\x80\x80\x80\x80\x02\"\x9a\x03\n" + "\x13UninterpretedOption\x12A\n" + "\x04name\x18\x02 \x03(\v2-.google.protobuf.UninterpretedOption.NamePartR\x04name\x12)\n" + "\x10identifier_value\x18\x03 \x01(\tR\x0fidentifierValue\x12,\n" + @@ -4950,7 +4945,7 @@ const file_google_protobuf_descriptor_proto_rawDesc = "" + "\x0faggregate_value\x18\b \x01(\tR\x0eaggregateValue\x1aJ\n" + "\bNamePart\x12\x1b\n" + "\tname_part\x18\x01 \x02(\tR\bnamePart\x12!\n" + - "\fis_extension\x18\x02 \x02(\bR\visExtension\"\x8e\x0f\n" + + "\fis_extension\x18\x02 \x02(\bR\visExtension\"\xae\x0f\n" + "\n" + "FeatureSet\x12\x91\x01\n" + "\x0efield_presence\x18\x01 \x01(\x0e2).google.protobuf.FeatureSet.FieldPresenceB?\x88\x01\x01\x98\x01\x04\x98\x01\x01\xa2\x01\r\x12\bEXPLICIT\x18\x84\a\xa2\x01\r\x12\bIMPLICIT\x18\xe7\a\xa2\x01\r\x12\bEXPLICIT\x18\xe8\a\xb2\x01\x03\b\xe8\aR\rfieldPresence\x12l\n" + @@ -4960,8 +4955,8 @@ const file_google_protobuf_descriptor_proto_rawDesc = "" + "\x10message_encoding\x18\x05 \x01(\x0e2+.google.protobuf.FeatureSet.MessageEncodingB&\x88\x01\x01\x98\x01\x04\x98\x01\x01\xa2\x01\x14\x12\x0fLENGTH_PREFIXED\x18\x84\a\xb2\x01\x03\b\xe8\aR\x0fmessageEncoding\x12\x82\x01\n" + "\vjson_format\x18\x06 \x01(\x0e2&.google.protobuf.FeatureSet.JsonFormatB9\x88\x01\x01\x98\x01\x03\x98\x01\x06\x98\x01\x01\xa2\x01\x17\x12\x12LEGACY_BEST_EFFORT\x18\x84\a\xa2\x01\n" + "\x12\x05ALLOW\x18\xe7\a\xb2\x01\x03\b\xe8\aR\n" + - "jsonFormat\x12\xab\x01\n" + - "\x14enforce_naming_style\x18\a \x01(\x0e2..google.protobuf.FeatureSet.EnforceNamingStyleBI\x88\x01\x02\x98\x01\x01\x98\x01\x02\x98\x01\x03\x98\x01\x04\x98\x01\x05\x98\x01\x06\x98\x01\a\x98\x01\b\x98\x01\t\xa2\x01\x11\x12\fSTYLE_LEGACY\x18\x84\a\xa2\x01\x0e\x12\tSTYLE2024\x18\xe9\a\xb2\x01\x03\b\xe9\aR\x12enforceNamingStyle\x12\xb9\x01\n" + + "jsonFormat\x12\xbc\x01\n" + + "\x14enforce_naming_style\x18\a \x01(\x0e2..google.protobuf.FeatureSet.EnforceNamingStyleBZ\x88\x01\x02\x98\x01\x01\x98\x01\x02\x98\x01\x03\x98\x01\x04\x98\x01\x05\x98\x01\x06\x98\x01\a\x98\x01\b\x98\x01\t\xa2\x01\x11\x12\fSTYLE_LEGACY\x18\x84\a\xa2\x01\x0e\x12\tSTYLE2024\x18\xe9\a\xa2\x01\x0e\x12\tSTYLE2026\x18\x8fN\xb2\x01\x03\b\xe9\aR\x12enforceNamingStyle\x12\xb9\x01\n" + "\x19default_symbol_visibility\x18\b \x01(\x0e2E.google.protobuf.FeatureSet.VisibilityFeature.DefaultSymbolVisibilityB6\x88\x01\x02\x98\x01\x01\xa2\x01\x0f\x12\n" + "EXPORT_ALL\x18\x84\a\xa2\x01\x15\x12\x10EXPORT_TOP_LEVEL\x18\xe9\a\xb2\x01\x03\b\xe9\aR\x17defaultSymbolVisibility\x1a\xa1\x01\n" + "\x11VisibilityFeature\"\x81\x01\n" + @@ -5001,11 +4996,12 @@ const file_google_protobuf_descriptor_proto_rawDesc = "" + "JsonFormat\x12\x17\n" + "\x13JSON_FORMAT_UNKNOWN\x10\x00\x12\t\n" + "\x05ALLOW\x10\x01\x12\x16\n" + - "\x12LEGACY_BEST_EFFORT\x10\x02\"W\n" + + "\x12LEGACY_BEST_EFFORT\x10\x02\"f\n" + "\x12EnforceNamingStyle\x12 \n" + "\x1cENFORCE_NAMING_STYLE_UNKNOWN\x10\x00\x12\r\n" + "\tSTYLE2024\x10\x01\x12\x10\n" + - "\fSTYLE_LEGACY\x10\x02*\x06\b\xe8\a\x10\x8bN*\x06\b\x8bN\x10\x90N*\x06\b\x90N\x10\x91NJ\x06\b\xe7\a\x10\xe8\a\"\xef\x03\n" + + "\fSTYLE_LEGACY\x10\x02\x12\r\n" + + "\tSTYLE2026\x10\x03*\x06\b\xe8\a\x10\x8bN*\x06\b\x8bN\x10\x90N*\x06\b\x90N\x10\x91NJ\x06\b\xe7\a\x10\xe8\a\"\xef\x03\n" + "\x12FeatureSetDefaults\x12X\n" + "\bdefaults\x18\x01 \x03(\v2<.google.protobuf.FeatureSetDefaults.FeatureSetEditionDefaultR\bdefaults\x12A\n" + "\x0fminimum_edition\x18\x04 \x01(\x0e2\x18.google.protobuf.EditionR\x0eminimumEdition\x12A\n" + @@ -5037,14 +5033,15 @@ const file_google_protobuf_descriptor_proto_rawDesc = "" + "\bSemantic\x12\b\n" + "\x04NONE\x10\x00\x12\a\n" + "\x03SET\x10\x01\x12\t\n" + - "\x05ALIAS\x10\x02*\xbe\x02\n" + + "\x05ALIAS\x10\x02*\xd1\x02\n" + "\aEdition\x12\x13\n" + "\x0fEDITION_UNKNOWN\x10\x00\x12\x13\n" + "\x0eEDITION_LEGACY\x10\x84\a\x12\x13\n" + "\x0eEDITION_PROTO2\x10\xe6\a\x12\x13\n" + "\x0eEDITION_PROTO3\x10\xe7\a\x12\x11\n" + "\fEDITION_2023\x10\xe8\a\x12\x11\n" + - "\fEDITION_2024\x10\xe9\a\x12\x15\n" + + "\fEDITION_2024\x10\xe9\a\x12\x11\n" + + "\fEDITION_2026\x10\xea\a\x12\x15\n" + "\x10EDITION_UNSTABLE\x10\x8fN\x12\x17\n" + "\x13EDITION_1_TEST_ONLY\x10\x01\x12\x17\n" + "\x13EDITION_2_TEST_ONLY\x10\x02\x12\x1d\n" + diff --git a/vendor/google.golang.org/protobuf/types/known/anypb/any.pb.go b/vendor/google.golang.org/protobuf/types/known/anypb/any.pb.go index 1ff0d1494..510894f2b 100644 --- a/vendor/google.golang.org/protobuf/types/known/anypb/any.pb.go +++ b/vendor/google.golang.org/protobuf/types/known/anypb/any.pb.go @@ -128,120 +128,66 @@ import ( // `Any` contains an arbitrary serialized protocol buffer message along with a // URL that describes the type of the serialized message. // -// Protobuf library provides support to pack/unpack Any values in the form -// of utility functions or additional generated methods of the Any type. -// -// Example 1: Pack and unpack a message in C++. -// -// Foo foo = ...; -// Any any; -// any.PackFrom(foo); -// ... -// if (any.UnpackTo(&foo)) { -// ... -// } -// -// Example 2: Pack and unpack a message in Java. -// -// Foo foo = ...; -// Any any = Any.pack(foo); -// ... -// if (any.is(Foo.class)) { -// foo = any.unpack(Foo.class); -// } -// // or ... -// if (any.isSameTypeAs(Foo.getDefaultInstance())) { -// foo = any.unpack(Foo.getDefaultInstance()); -// } -// -// Example 3: Pack and unpack a message in Python. -// -// foo = Foo(...) -// any = Any() -// any.Pack(foo) -// ... -// if any.Is(Foo.DESCRIPTOR): -// any.Unpack(foo) -// ... -// -// Example 4: Pack and unpack a message in Go -// -// foo := &pb.Foo{...} -// any, err := anypb.New(foo) -// if err != nil { -// ... -// } -// ... -// foo := &pb.Foo{} -// if err := any.UnmarshalTo(foo); err != nil { -// ... -// } -// -// The pack methods provided by protobuf library will by default use -// 'type.googleapis.com/full.type.name' as the type URL and the unpack -// methods only use the fully qualified type name after the last '/' -// in the type URL, for example "foo.bar.com/x/y.z" will yield type -// name "y.z". -// -// JSON -// ==== -// The JSON representation of an `Any` value uses the regular -// representation of the deserialized, embedded message, with an -// additional field `@type` which contains the type URL. Example: -// -// package google.profile; -// message Person { -// string first_name = 1; -// string last_name = 2; -// } -// -// { -// "@type": "type.googleapis.com/google.profile.Person", -// "firstName": , -// "lastName": -// } -// -// If the embedded message type is well-known and has a custom JSON -// representation, that representation will be embedded adding a field -// `value` which holds the custom JSON in addition to the `@type` -// field. Example (for message [google.protobuf.Duration][]): -// -// { -// "@type": "type.googleapis.com/google.protobuf.Duration", -// "value": "1.212s" -// } +// In its binary encoding, an `Any` is an ordinary message; but in other wire +// forms like JSON, it has a special encoding. The format of the type URL is +// described on the `type_url` field. +// +// Protobuf APIs provide utilities to interact with `Any` values: +// +// - A 'pack' operation accepts a message and constructs a generic `Any` wrapper +// around it. +// - An 'unpack' operation reads the content of an `Any` message, either into an +// existing message or a new one. Unpack operations must check the type of the +// value they unpack against the declared `type_url`. +// - An 'is' operation decides whether an `Any` contains a message of the given +// type, i.e. whether it can 'unpack' that type. +// +// The JSON format representation of an `Any` follows one of these cases: +// +// - For types without special-cased JSON encodings, the JSON format +// representation of the `Any` is the same as that of the message, with an +// additional `@type` field which contains the type URL. +// - For types with special-cased JSON encodings (typically called 'well-known' +// types, listed in https://protobuf.dev/programming-guides/json/#any), the +// JSON format representation has a key `@type` which contains the type URL +// and a key `value` which contains the JSON-serialized value. +// +// The text format representation of an `Any` is like a message with one field +// whose name is the type URL in brackets. For example, an `Any` containing a +// `foo.Bar` message may be written `[type.googleapis.com/foo.Bar] { a: 2 }`. type Any struct { state protoimpl.MessageState `protogen:"open.v1"` - // A URL/resource name that uniquely identifies the type of the serialized - // protocol buffer message. This string must contain at least - // one "/" character. The last segment of the URL's path must represent - // the fully qualified name of the type (as in - // `path/google.protobuf.Duration`). The name should be in a canonical form - // (e.g., leading "." is not accepted). + // Identifies the type of the serialized Protobuf message with a URI reference + // consisting of a prefix ending in a slash and the fully-qualified type name. + // + // Example: type.googleapis.com/google.protobuf.StringValue // - // In practice, teams usually precompile into the binary all types that they - // expect it to use in the context of Any. However, for URLs which use the - // scheme `http`, `https`, or no scheme, one can optionally set up a type - // server that maps type URLs to message definitions as follows: + // This string must contain at least one `/` character, and the content after + // the last `/` must be the fully-qualified name of the type in canonical + // form, without a leading dot. Do not write a scheme on these URI references + // so that clients do not attempt to contact them. // - // - If no scheme is provided, `https` is assumed. - // - An HTTP GET on the URL must yield a [google.protobuf.Type][] - // value in binary format, or produce an error. - // - Applications are allowed to cache lookup results based on the - // URL, or have them precompiled into a binary to avoid any - // lookup. Therefore, binary compatibility needs to be preserved - // on changes to types. (Use versioned type names to manage - // breaking changes.) + // The prefix is arbitrary and Protobuf implementations are expected to + // simply strip off everything up to and including the last `/` to identify + // the type. `type.googleapis.com/` is a common default prefix that some + // legacy implementations require. This prefix does not indicate the origin of + // the type, and URIs containing it are not expected to respond to any + // requests. // - // Note: this functionality is not currently available in the official - // protobuf release, and it is not used for type URLs beginning with - // type.googleapis.com. As of May 2023, there are no widely used type server - // implementations and no plans to implement one. + // All type URL strings must be legal URI references with the additional + // restriction (for the text format) that the content of the reference + // must consist only of alphanumeric characters, percent-encoded escapes, and + // characters in the following set (not including the outer backticks): + // `/-.~_!$&()*+,;=`. Despite our allowing percent encodings, implementations + // should not unescape them to prevent confusion with existing parsers. For + // example, `type.googleapis.com%2FFoo` should be rejected. // - // Schemes other than `http`, `https` (or the empty scheme) might be - // used with implementation specific semantics. + // In the original design of `Any`, the possibility of launching a type + // resolution service at these type URLs was considered but Protobuf never + // implemented one and considers contacting these URLs to be problematic and + // a potential security issue. Do not attempt to contact type URLs. TypeUrl string `protobuf:"bytes,1,opt,name=type_url,json=typeUrl,proto3" json:"type_url,omitempty"` - // Must be a valid serialized protocol buffer of the above specified type. + // Holds a Protobuf serialization of the type described by type_url. Value []byte `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache diff --git a/vendor/google.golang.org/protobuf/types/known/fieldmaskpb/field_mask.pb.go b/vendor/google.golang.org/protobuf/types/known/fieldmaskpb/field_mask.pb.go index 91ee89a5c..4a0437911 100644 --- a/vendor/google.golang.org/protobuf/types/known/fieldmaskpb/field_mask.pb.go +++ b/vendor/google.golang.org/protobuf/types/known/fieldmaskpb/field_mask.pb.go @@ -197,24 +197,22 @@ import ( // An implementation may provide options to override this default behavior for // repeated and message fields. // -// In order to reset a field's value to the default, the field must -// be in the mask and set to the default value in the provided resource. -// Hence, in order to reset all fields of a resource, provide a default -// instance of the resource and set all fields in the mask, or do -// not provide a mask as described below. -// -// If a field mask is not present on update, the operation applies to -// all fields (as if a field mask of all fields has been specified). -// Note that in the presence of schema evolution, this may mean that -// fields the client does not know and has therefore not filled into -// the request will be reset to their default. If this is unwanted -// behavior, a specific service may require a client to always specify -// a field mask, producing an error if not. -// -// As with get operations, the location of the resource which -// describes the updated values in the request message depends on the -// operation kind. In any case, the effect of the field mask is -// required to be honored by the API. +// Note that libraries which implement FieldMask resolution have various +// different behaviors in the face of empty masks or the special "*" mask. +// When implementing a service you should confirm these cases have the +// appropriate behavior in the underlying FieldMask library that you desire, +// and you may need to special case those cases in your application code if +// the underlying field mask library behavior differs from your intended +// service semantics. +// +// Update methods implementing https://google.aip.dev/134 +// - MUST support the special value * meaning "full replace" +// - MUST treat an omitted field mask as "replace fields which are present". +// +// Other methods implementing https://google.aip.dev/157 +// - SHOULD support the special value "*" to mean "get all". +// - MUST treat an omitted field mask to mean "get all", unless otherwise +// documented. // // ## Considerations for HTTP REST // diff --git a/vendor/google.golang.org/protobuf/types/known/structpb/struct.pb.go b/vendor/google.golang.org/protobuf/types/known/structpb/struct.pb.go index 30411b728..8325a5048 100644 --- a/vendor/google.golang.org/protobuf/types/known/structpb/struct.pb.go +++ b/vendor/google.golang.org/protobuf/types/known/structpb/struct.pb.go @@ -131,10 +131,15 @@ import ( unsafe "unsafe" ) -// `NullValue` is a singleton enumeration to represent the null value for the -// `Value` type union. +// Represents a JSON `null`. // -// The JSON representation for `NullValue` is JSON `null`. +// `NullValue` is a sentinel, using an enum with only one value to represent +// the null value for the `Value` type union. +// +// A field of type `NullValue` with any value other than `0` is considered +// invalid. Most ProtoJSON serializers will emit a Value with a `null_value` set +// as a JSON `null` regardless of the integer value, and so will round trip to +// a `0` value. type NullValue int32 const ( @@ -179,14 +184,19 @@ func (NullValue) EnumDescriptor() ([]byte, []int) { return file_google_protobuf_struct_proto_rawDescGZIP(), []int{0} } -// `Struct` represents a structured data value, consisting of fields -// which map to dynamically typed values. In some languages, `Struct` -// might be supported by a native representation. For example, in -// scripting languages like JS a struct is represented as an -// object. The details of that representation are described together -// with the proto support for the language. +// Represents a JSON object. +// +// An unordered key-value map, intending to perfectly capture the semantics of a +// JSON object. This enables parsing any arbitrary JSON payload as a message +// field in ProtoJSON format. +// +// This follows RFC 8259 guidelines for interoperable JSON: notably this type +// cannot represent large Int64 values or `NaN`/`Infinity` numbers, +// since the JSON format generally does not support those values in its number +// type. // -// The JSON representation for `Struct` is JSON object. +// If you do not intend to parse arbitrary JSON into your message, a custom +// typed message should be preferred instead of using this type. type Struct struct { state protoimpl.MessageState `protogen:"open.v1"` // Unordered map of dynamically typed values. @@ -269,12 +279,12 @@ func (x *Struct) GetFields() map[string]*Value { return nil } +// Represents a JSON value. +// // `Value` represents a dynamically typed value which can be either // null, a number, a string, a boolean, a recursive struct value, or a // list of values. A producer of value is expected to set one of these -// variants. Absence of any variant indicates an error. -// -// The JSON representation for `Value` is JSON value. +// variants. Absence of any variant is an invalid state. type Value struct { state protoimpl.MessageState `protogen:"open.v1"` // The kind of value. @@ -548,32 +558,35 @@ type isValue_Kind interface { } type Value_NullValue struct { - // Represents a null value. + // Represents a JSON `null`. NullValue NullValue `protobuf:"varint,1,opt,name=null_value,json=nullValue,proto3,enum=google.protobuf.NullValue,oneof"` } type Value_NumberValue struct { - // Represents a double value. + // Represents a JSON number. Must not be `NaN`, `Infinity` or + // `-Infinity`, since those are not supported in JSON. This also cannot + // represent large Int64 values, since JSON format generally does not + // support them in its number type. NumberValue float64 `protobuf:"fixed64,2,opt,name=number_value,json=numberValue,proto3,oneof"` } type Value_StringValue struct { - // Represents a string value. + // Represents a JSON string. StringValue string `protobuf:"bytes,3,opt,name=string_value,json=stringValue,proto3,oneof"` } type Value_BoolValue struct { - // Represents a boolean value. + // Represents a JSON boolean (`true` or `false` literal in JSON). BoolValue bool `protobuf:"varint,4,opt,name=bool_value,json=boolValue,proto3,oneof"` } type Value_StructValue struct { - // Represents a structured value. + // Represents a JSON object. StructValue *Struct `protobuf:"bytes,5,opt,name=struct_value,json=structValue,proto3,oneof"` } type Value_ListValue struct { - // Represents a repeated `Value`. + // Represents a JSON array. ListValue *ListValue `protobuf:"bytes,6,opt,name=list_value,json=listValue,proto3,oneof"` } @@ -589,9 +602,7 @@ func (*Value_StructValue) isValue_Kind() {} func (*Value_ListValue) isValue_Kind() {} -// `ListValue` is a wrapper around a repeated field of values. -// -// The JSON representation for `ListValue` is JSON array. +// Represents a JSON array. type ListValue struct { state protoimpl.MessageState `protogen:"open.v1"` // Repeated field of dynamically typed values. diff --git a/vendor/google.golang.org/protobuf/types/known/timestamppb/timestamp.pb.go b/vendor/google.golang.org/protobuf/types/known/timestamppb/timestamp.pb.go index 484c21fd5..2cd60946c 100644 --- a/vendor/google.golang.org/protobuf/types/known/timestamppb/timestamp.pb.go +++ b/vendor/google.golang.org/protobuf/types/known/timestamppb/timestamp.pb.go @@ -153,8 +153,8 @@ import ( // {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional // seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution), // are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone -// is required. A proto3 JSON serializer should always use UTC (as indicated by -// "Z") when printing the Timestamp type and a proto3 JSON parser should be +// is required. A ProtoJSON serializer should always use UTC (as indicated by +// "Z") when printing the Timestamp type and a ProtoJSON parser should be // able to accept both UTC and other timezones (as indicated by an offset). // // For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past @@ -173,7 +173,7 @@ import ( type Timestamp struct { state protoimpl.MessageState `protogen:"open.v1"` // Represents seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z. Must - // be between -315576000000 and 315576000000 inclusive (which corresponds to + // be between -62135596800 and 253402300799 inclusive (which corresponds to // 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z). Seconds int64 `protobuf:"varint,1,opt,name=seconds,proto3" json:"seconds,omitempty"` // Non-negative fractions of a second at nanosecond resolution. This field is diff --git a/vendor/modules.txt b/vendor/modules.txt index 9082adf9e..5d94c54aa 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -513,7 +513,7 @@ google.golang.org/genproto/googleapis/api/httpbody ## explicit; go 1.25.0 google.golang.org/genproto/googleapis/rpc/errdetails google.golang.org/genproto/googleapis/rpc/status -# google.golang.org/grpc v1.83.0 +# google.golang.org/grpc v1.83.1 ## explicit; go 1.25.0 google.golang.org/grpc google.golang.org/grpc/attributes @@ -587,7 +587,7 @@ google.golang.org/grpc/stats google.golang.org/grpc/status google.golang.org/grpc/tap google.golang.org/grpc/test/bufconn -# google.golang.org/protobuf v1.36.11 +# google.golang.org/protobuf v1.36.12 ## explicit; go 1.23 google.golang.org/protobuf/encoding/protodelim google.golang.org/protobuf/encoding/protojson From 8b46dce39512ad65daa413ecc340934390111efe Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Tue, 25 Aug 2026 12:02:35 +0000 Subject: [PATCH 121/182] chore(deps): update golang docker tag to v1.27.0 (#6331) | datasource | package | from | to | | ---------- | ------- | ------ | ------ | | docker | golang | 1.26.5 | 1.27.0 | Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 823b16760..9b65861bc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM --platform=$BUILDPLATFORM golang:1.26.5-alpine@sha256:0178a641fbb4858c5f1b48e34bdaabe0350a330a1b1149aabd498d0699ff5fb2 as builder +FROM --platform=$BUILDPLATFORM golang:1.27.0-alpine@sha256:4c9fe60190a2a3350ddc51de80d0224b8a6698d12bdfc999fee45ea9d6c46dbc as builder WORKDIR $GOPATH/src/go.k6.io/k6 COPY . . ARG TARGETOS TARGETARCH From 6b9cbaaa65bce5eadad0a1c5592fe8a1c2b91217 Mon Sep 17 00:00:00 2001 From: Jan Hildebrandt <32014057+janHildebrandt98@users.noreply.github.com> Date: Tue, 25 Aug 2026 14:33:05 +0200 Subject: [PATCH 122/182] Export constants for ReadyState in websockets module * Add static and per-object constants to replace ReadyState enum * Fix lint findings * adjust tests --- .../js/modules/k6/websockets/websockets.go | 39 +++++++++++++++---- .../modules/k6/websockets/websockets_test.go | 8 ++-- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/internal/js/modules/k6/websockets/websockets.go b/internal/js/modules/k6/websockets/websockets.go index 836562351..66076b216 100644 --- a/internal/js/modules/k6/websockets/websockets.go +++ b/internal/js/modules/k6/websockets/websockets.go @@ -29,8 +29,9 @@ type RootModule struct{} // WebSocketsAPI is the k6 extension implementing the websocket API as defined in https://websockets.spec.whatwg.org type WebSocketsAPI struct { //nolint:revive - vu modules.VU - blobConstructor sobek.Value + vu modules.VU + blobConstructor sobek.Value + webSocketConstructor sobek.Value } var _ modules.Module = &RootModule{} @@ -42,17 +43,27 @@ func New() *RootModule { // NewModuleInstance returns a new instance of the module func (r *RootModule) NewModuleInstance(vu modules.VU) modules.Instance { - return &WebSocketsAPI{ - vu: vu, + api := &WebSocketsAPI{vu: vu} + + rt := vu.Runtime() + api.blobConstructor = rt.ToValue(api.blob) + + wsConstructor, ok := rt.ToValue(api.websocket).(*sobek.Object) + if !ok { + common.Throw(rt, errors.New("websocket constructor is not a sobek.Object")) } + + defineReadyStateProperties(rt, wsConstructor) + api.webSocketConstructor = wsConstructor + + return api } // Exports implements the modules.Instance interface's Exports func (r *WebSocketsAPI) Exports() modules.Exports { - r.blobConstructor = r.vu.Runtime().ToValue(r.blob) return modules.Exports{ Named: map[string]any{ - "WebSocket": r.websocket, + "WebSocket": r.webSocketConstructor, "Blob": r.blobConstructor, }, } @@ -256,6 +267,20 @@ func defineWebsocket(rt *sobek.Runtime, w *webSocket) { setOn("onclose", w.eventListeners.getType(events.CLOSE)) setOn("onping", w.eventListeners.getType(events.PING)) setOn("onpong", w.eventListeners.getType(events.PONG)) + + defineReadyStateProperties(rt, w.obj) +} + +// the spec defines constants for the ready state on both the constructor and actual instances +func defineReadyStateProperties(rt *sobek.Runtime, target *sobek.Object) { + must(rt, target.DefineDataProperty( + "OPEN", rt.ToValue(uint(OPEN)), sobek.FLAG_FALSE, sobek.FLAG_FALSE, sobek.FLAG_TRUE)) + must(rt, target.DefineDataProperty( + "CLOSED", rt.ToValue(uint(CLOSED)), sobek.FLAG_FALSE, sobek.FLAG_FALSE, sobek.FLAG_TRUE)) + must(rt, target.DefineDataProperty( + "CLOSING", rt.ToValue(uint(CLOSING)), sobek.FLAG_FALSE, sobek.FLAG_FALSE, sobek.FLAG_TRUE)) + must(rt, target.DefineDataProperty( + "CONNECTING", rt.ToValue(uint(CONNECTING)), sobek.FLAG_FALSE, sobek.FLAG_FALSE, sobek.FLAG_TRUE)) } type message struct { @@ -834,7 +859,7 @@ func (w *webSocket) connectionClosedWithError(err error) error { return w.callEventListeners(events.CLOSE) } -// newEvent return an event implementing "implements" https://dom.spec.whatwg.org/#event +// newEvent returns an event implementing "implements" https://dom.spec.whatwg.org/#event // needs to be called on the event loop // TODO: move to events func (w *webSocket) newEvent(eventType string, t time.Time, funcOptions ...func(*sobek.Object)) *sobek.Object { diff --git a/internal/js/modules/k6/websockets/websockets_test.go b/internal/js/modules/k6/websockets/websockets_test.go index 766f3e9f3..f8fc690e2 100644 --- a/internal/js/modules/k6/websockets/websockets_test.go +++ b/internal/js/modules/k6/websockets/websockets_test.go @@ -276,11 +276,11 @@ func TestReadyState(t *testing.T) { _, err := ts.runtime.RunOnEventLoop(ts.tb.Replacer.Replace(` var ws = new WebSocket("WSBIN_URL/ws-echo") ws.addEventListener("open", () => { - if (ws.readyState != 1){ + if (ws.readyState != WebSocket.OPEN){ throw new Error("Expected ready state 1 got "+ ws.readyState) } ws.addEventListener("close", () => { - if (ws.readyState != 3){ + if (ws.readyState != WebSocket.CLOSED){ throw new Error("Expected ready state 3 got "+ ws.readyState) } @@ -288,7 +288,7 @@ func TestReadyState(t *testing.T) { ws.send("something") ws.close() }) - if (ws.readyState != 0){ + if (ws.readyState != WebSocket.CONNECTING){ throw new Error("Expected ready state 0 got "+ ws.readyState) } `)) @@ -1590,7 +1590,7 @@ func TestReadyStateSwitch(t *testing.T) { var ws = new WebSocket("WSBIN_URL/ws-echo") try { switch (ws.readyState) { - case 0: + case WebSocket.CONNECTING: break; default: throw "ws.readyState doesn't get correct value in switch" From 939db29bcb42eb538f232b3419786071a7ca245e Mon Sep 17 00:00:00 2001 From: Kazuya Umeki <108924738+umekikazuya@users.noreply.github.com> Date: Wed, 26 Aug 2026 19:07:58 +0900 Subject: [PATCH 123/182] Fix stale tc39 package path in docs (#6301) The tc39 tests moved to internal/js/tc39 in 7129195a, but Dependencies.md and the package README still referred to js/tc39. As a result the link in Dependencies.md pointed to a file that no longer exists. --- Dependencies.md | 2 +- internal/js/tc39/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dependencies.md b/Dependencies.md index d7e689b02..bd04f49df 100644 --- a/Dependencies.md +++ b/Dependencies.md @@ -94,4 +94,4 @@ It's preferable to make multiple PRs - in most cases you can split them in three Further splitting is recommended if PRs become too big. -When updating Sobek it's recommended to run the tc39 tests in `js/tc39`. And if needed, update the breaking ones as explained in an [Introduction to a k6's TC39 testing](./js/tc39/README.md). +When updating Sobek it's recommended to run the tc39 tests in `internal/js/tc39`. And if needed, update the breaking ones as explained in an [Introduction to a k6's TC39 testing](./internal/js/tc39/README.md). diff --git a/internal/js/tc39/README.md b/internal/js/tc39/README.md index 9919d3951..e65cd2544 100644 --- a/internal/js/tc39/README.md +++ b/internal/js/tc39/README.md @@ -1,6 +1,6 @@ # Introduction to a k6's TC39 testing -`js/tc39` package tests k6 [Sobek](https://github.com/grafana/sobek) and the k6 Sobek+esbuild combo against the tc39 test suite. +`internal/js/tc39` package tests k6 [Sobek](https://github.com/grafana/sobek) and the k6 Sobek+esbuild combo against the tc39 test suite. Ways to use it: 1. run ./checkout.sh to checkout the last commit sha of [test262](https://github.com/tc39/test262) From 165bb3c1a492b7a4823907fe1e93a30645794737 Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Wed, 26 Aug 2026 12:09:04 +0200 Subject: [PATCH 124/182] fix(deps): update module github.com/evanw/esbuild to v0.28.2 (#6303) | datasource | package | from | to | | ---------- | ------------------------ | ------- | ------- | | go | github.com/evanw/esbuild | v0.28.1 | v0.28.2 | Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 +- .../evanw/esbuild/internal/bundler/bundler.go | 79 ++- .../evanw/esbuild/internal/compat/compat.go | 86 ++++ .../internal/css_parser/css_color_spaces.go | 2 +- .../esbuild/internal/css_parser/css_parser.go | 45 +- .../css_parser/css_parser_selector.go | 35 +- .../evanw/esbuild/internal/helpers/mime.go | 3 + .../evanw/esbuild/internal/js_ast/js_ast.go | 7 +- .../esbuild/internal/js_parser/js_parser.go | 201 +++++--- .../internal/js_parser/js_parser_lower.go | 26 +- .../evanw/esbuild/internal/logger/logger.go | 463 +----------------- .../evanw/esbuild/internal/logger/msg_ids.go | 127 ++--- .../esbuild/internal/logger/style_default.go | 460 +++++++++++++++++ .../internal/logger/style_visualstudio.go | 107 ++++ .../github.com/evanw/esbuild/pkg/api/api.go | 10 + .../evanw/esbuild/pkg/api/api_impl.go | 70 ++- .../evanw/esbuild/pkg/api/serve_other.go | 51 +- vendor/modules.txt | 2 +- 19 files changed, 1127 insertions(+), 653 deletions(-) create mode 100644 vendor/github.com/evanw/esbuild/internal/logger/style_default.go create mode 100644 vendor/github.com/evanw/esbuild/internal/logger/style_visualstudio.go diff --git a/go.mod b/go.mod index 792db4ca6..f2ec9d5c5 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/andybalholm/brotli v1.2.2 github.com/bufbuild/protocompile v0.14.1 github.com/chromedp/cdproto v0.0.0-20250803210736-d308e07a266d - github.com/evanw/esbuild v0.28.1 + github.com/evanw/esbuild v0.28.2 github.com/fatih/color v1.19.0 github.com/go-json-experiment/json v0.0.0-20250211171154-1ae217ad3535 github.com/go-sourcemap/sourcemap v2.1.4+incompatible diff --git a/go.sum b/go.sum index c1ab2582a..398e777ce 100644 --- a/go.sum +++ b/go.sum @@ -41,8 +41,8 @@ github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymF github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= -github.com/evanw/esbuild v0.28.1 h1:ds+yuRyUaZGx++GR56CrCeuXh8PVhVM4xq8v7PNELFc= -github.com/evanw/esbuild v0.28.1/go.mod h1:D2vIQZqV/vIf/VRHtViaUtViZmG7o+kKmlBfVQuRi48= +github.com/evanw/esbuild v0.28.2 h1:A2uETn4jrQTcXaT/shwTDTYBxDjl7fV7nXmUrJxfA2w= +github.com/evanw/esbuild v0.28.2/go.mod h1:D2vIQZqV/vIf/VRHtViaUtViZmG7o+kKmlBfVQuRi48= github.com/fatih/color v1.19.0 h1:Zp3PiM21/9Ld6FzSKyL5c/BULoe/ONr9KlbYVOfG8+w= github.com/fatih/color v1.19.0/go.mod h1:zNk67I0ZUT1bEGsSGyCZYZNrHuTkJJB+r6Q9VuMi0LE= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= diff --git a/vendor/github.com/evanw/esbuild/internal/bundler/bundler.go b/vendor/github.com/evanw/esbuild/internal/bundler/bundler.go index ad74dfcb0..982c9e47b 100644 --- a/vendor/github.com/evanw/esbuild/internal/bundler/bundler.go +++ b/vendor/github.com/evanw/esbuild/internal/bundler/bundler.go @@ -116,7 +116,8 @@ type globResolveResult struct { type tlaCheck struct { parent ast.Index32 - depth uint32 + depth ast.Index32 + pass uint32 importRecordIndex uint32 } @@ -2810,13 +2811,17 @@ func (s *scanner) processScannedFiles(entryPointMeta []graph.EntryPoint) []scann s.results[sourceIndex] = result } + // Traverse the graph to check top-level await + if s.iterativelyValidateTLA() { + s.reportInvalidTLA() + } + // The linker operates on an array of files, so construct that now. This // can't be constructed earlier because we generate new parse results for // JavaScript stub files for CSS imports above. files := make([]scannerFile, len(s.results)) for sourceIndex := range s.results { if result := &s.results[sourceIndex]; result.ok { - s.validateTLA(uint32(sourceIndex)) files[sourceIndex] = result.file } } @@ -2824,33 +2829,69 @@ func (s *scanner) processScannedFiles(entryPointMeta []graph.EntryPoint) []scann return files } -func (s *scanner) validateTLA(sourceIndex uint32) tlaCheck { +func (s *scanner) iterativelyValidateTLA() bool { + pass := uint32(1) + hasTLA := false + + // Iterate until a fixed point has been reached to handle graph cycles + for { + didChange := false + for sourceIndex := range s.results { + s.recursivelyValidateTLA(uint32(sourceIndex), pass, &didChange) + } + if !didChange { + return hasTLA + } + pass++ + hasTLA = true + } +} + +func (s *scanner) recursivelyValidateTLA(sourceIndex uint32, pass uint32, didChange *bool) tlaCheck { result := &s.results[sourceIndex] - if result.ok && result.tlaCheck.depth == 0 { + // Use a "pass" integer instead of a separate "visited" set + if result.ok && result.tlaCheck.pass != pass { + result.tlaCheck.pass = pass + if repr, ok := result.file.inputFile.Repr.(*graph.JSRepr); ok { - result.tlaCheck.depth = 1 - if repr.AST.LiveTopLevelAwaitKeyword.Len > 0 { + // If this module contains top-level await, set its parent to itself + if repr.AST.LiveTopLevelAwaitKeyword.Len > 0 && result.tlaCheck.parent.GetIndex() != sourceIndex { result.tlaCheck.parent = ast.MakeIndex32(sourceIndex) + result.tlaCheck.depth = ast.MakeIndex32(1) + *didChange = true } + // Check all import statements and require calls (only import statements are valid) for importRecordIndex, record := range repr.AST.ImportRecords { if record.SourceIndex.IsValid() && (record.Kind == ast.ImportRequire || record.Kind == ast.ImportStmt) { - parent := s.validateTLA(record.SourceIndex.GetIndex()) - if !parent.parent.IsValid() { - continue - } + parent := s.recursivelyValidateTLA(record.SourceIndex.GetIndex(), pass, didChange) - // Follow any import chains - if record.Kind == ast.ImportStmt && (!result.tlaCheck.parent.IsValid() || parent.depth < result.tlaCheck.depth) { - result.tlaCheck.depth = parent.depth + 1 + // Track the shallowest top-level await parent (used to report invalid import chains later on) + if record.Kind == ast.ImportStmt && parent.depth.GetIndex() < result.tlaCheck.depth.GetIndex()-1 { result.tlaCheck.parent = record.SourceIndex + result.tlaCheck.depth = ast.MakeIndex32(parent.depth.GetIndex() + 1) result.tlaCheck.importRecordIndex = uint32(importRecordIndex) + *didChange = true continue } + } + } + } + } + + return result.tlaCheck +} +func (s *scanner) reportInvalidTLA() { + for sourceIndex := range s.results { + result := &s.results[sourceIndex] + + if result.ok && result.tlaCheck.parent.IsValid() { + if repr, ok := result.file.inputFile.Repr.(*graph.JSRepr); ok { + for _, record := range repr.AST.ImportRecords { // Require of a top-level await chain is forbidden - if record.Kind == ast.ImportRequire { + if record.Kind == ast.ImportRequire && record.SourceIndex.IsValid() && s.results[record.SourceIndex.GetIndex()].tlaCheck.parent.IsValid() { var notes []logger.MsgData var tlaPrettyPaths logger.PrettyPaths otherSourceIndex := record.SourceIndex.GetIndex() @@ -2899,18 +2940,14 @@ func (s *scanner) validateTLA(sourceIndex uint32) tlaCheck { s.log.AddErrorWithNotes(&tracker, record.Range, text, notes) } } - } - // Make sure that if we wrap this module in a closure, the closure is also - // async. This happens when you call "import()" on this module and code - // splitting is off. - if result.tlaCheck.parent.IsValid() { + // Make sure that if we wrap this module in a closure, the closure is also + // async. This happens when you call "import()" on this module and code + // splitting is off. repr.Meta.IsAsyncOrHasAsyncDependency = true } } } - - return result.tlaCheck } func DefaultExtensionToLoaderMap() map[string]config.Loader { diff --git a/vendor/github.com/evanw/esbuild/internal/compat/compat.go b/vendor/github.com/evanw/esbuild/internal/compat/compat.go index bd2d0ffd1..af069c20d 100644 --- a/vendor/github.com/evanw/esbuild/internal/compat/compat.go +++ b/vendor/github.com/evanw/esbuild/internal/compat/compat.go @@ -57,6 +57,92 @@ func compareVersions(a v, b Semver) int { return diff } +func CompareSemver(a Semver, b Semver) int { + an := len(a.Parts) + bn := len(b.Parts) + + n := an + if bn > n { + n = bn + } + + for i := 0; i < n; i++ { + ai := 0 + bi := 0 + if i < an { + ai = a.Parts[i] + } + if i < bn { + bi = b.Parts[i] + } + if ai != bi { + return ai - bi + } + } + + if (a.PreRelease != "") != (b.PreRelease != "") { + return len(b.PreRelease) - len(a.PreRelease) + } + + a_tail := strings.TrimPrefix(a.PreRelease, "-") + b_tail := strings.TrimPrefix(b.PreRelease, "-") + + for a_tail != "" && b_tail != "" { + var a_head, b_head string + a_head, a_tail = splitOffNextPreReleasePart(a_tail) + b_head, b_tail = splitOffNextPreReleasePart(b_tail) + if a_head == b_head { + continue + } + + // Check for numbers + a_num, a_isnum := preReleasePartToNumber(a_head) + b_num, b_isnum := preReleasePartToNumber(b_head) + if !a_isnum && !b_isnum { + // Lexicographic comparison for non-numbers + if a_head < b_head { + return -1 + } else { + return 1 + } + } else if a_isnum && b_isnum { + // Numeric comparison for numbers + if a_num != b_num { + return a_num - b_num + } else { + // Compare lengths for different text but equal numbers (e.g. "0" vs. "00") + return len(a_head) - len(b_head) + } + } else { + // One is a number and the other isn't + if a_isnum { + return -1 + } else { + return 1 + } + } + } + + return len(a_tail) - len(b_tail) +} + +func splitOffNextPreReleasePart(text string) (head string, tail string) { + if i := strings.IndexByte(text, '.'); i != -1 { + return text[:i], text[i+1:] + } + return text, "" +} + +func preReleasePartToNumber(text string) (int, bool) { + for _, c := range text { + if c < '0' || c > '9' { + return 0, false + } + } + n, err := strconv.Atoi(text) + return n, err == nil +} + // The start is inclusive and the end is exclusive type versionRange struct { start v diff --git a/vendor/github.com/evanw/esbuild/internal/css_parser/css_color_spaces.go b/vendor/github.com/evanw/esbuild/internal/css_parser/css_color_spaces.go index 721ecd33c..03c5efbc8 100644 --- a/vendor/github.com/evanw/esbuild/internal/css_parser/css_color_spaces.go +++ b/vendor/github.com/evanw/esbuild/internal/css_parser/css_color_spaces.go @@ -437,7 +437,7 @@ func gamut_mapping_xyz_to_srgb(x F64, y F64, z F64) (F64, F64, F64) { } clipped_r, clipped_g, clipped_b := clip(r), clip(g), clip(b) - L1, a1, b1 := srgb_to_oklab(clipped_r, clipped_b, clipped_g) + L1, a1, b1 := srgb_to_oklab(clipped_r, clipped_g, clipped_b) L2, a2, b2 := srgb_to_oklab(r, g, b) E := delta_eok(L1, a1, b1, L2, a2, b2) if E.Value() < JND { diff --git a/vendor/github.com/evanw/esbuild/internal/css_parser/css_parser.go b/vendor/github.com/evanw/esbuild/internal/css_parser/css_parser.go index f8e15f436..17d894b12 100644 --- a/vendor/github.com/evanw/esbuild/internal/css_parser/css_parser.go +++ b/vendor/github.com/evanw/esbuild/internal/css_parser/css_parser.go @@ -2309,7 +2309,50 @@ func (p *parser) scanForEndOfRule() (endOfRuleScan, int) { var initialStack [4]css_lexer.T stack := initialStack[:0] + // Small state machine to recognize "--foo:" + const ( + customPropIdent = iota + customPropColon + customPropAccept + customPropReject + ) + customProp := customPropIdent + for i, t := range p.tokens[p.index:] { + // People sometimes use CSS custom properties to store JSON. This is + // problematic because the "{...}" braces look like a CSS block unless + // this edge case is special-cased. See the (quite long) discussion on + // https://github.com/w3c/csswg-drafts/issues/7961 for more information. + // + // I couldn't find any actual specification for how this is supposed to + // work. Just a lot of discussion on GitHub. I did find this text, from + // https://drafts.csswg.org/css-syntax/#consume-a-declaration: + // + // Otherwise, if decl’s value contains a top-level simple block with + // an associated token of <{-token>, and also contains any other non- + // value, return nothing. (That is, a top-level {}- + // block is only allowed as the entire value of a non-custom property.) + // + // However, current browsers appear to accept custom properties with a + // {}-block contained anywhere inside them, not just as the entire value. + // So that's what I'm attempting to do here. + if customProp < customPropAccept { + switch customProp { + case customPropIdent: + if t.Kind == css_lexer.TIdent && strings.HasPrefix(p.source.Contents[t.Range.Loc.Start:], "--") { + customProp = customPropColon + } else if t.Kind != css_lexer.TWhitespace { + customProp = customPropReject + } + case customPropColon: + if t.Kind == css_lexer.TColon { + customProp = customPropAccept + } else if t.Kind != css_lexer.TWhitespace { + customProp = customPropReject + } + } + } + switch t.Kind { case css_lexer.TSemicolon: if len(stack) == 0 { @@ -2323,7 +2366,7 @@ func (p *parser) scanForEndOfRule() (endOfRuleScan, int) { stack = append(stack, css_lexer.TCloseBracket) case css_lexer.TOpenBrace: - if len(stack) == 0 { + if len(stack) == 0 && customProp != customPropAccept { return endOfRuleOpenBrace, p.index + i } stack = append(stack, css_lexer.TCloseBrace) diff --git a/vendor/github.com/evanw/esbuild/internal/css_parser/css_parser_selector.go b/vendor/github.com/evanw/esbuild/internal/css_parser/css_parser_selector.go index 78fec66e4..79c4c4f60 100644 --- a/vendor/github.com/evanw/esbuild/internal/css_parser/css_parser_selector.go +++ b/vendor/github.com/evanw/esbuild/internal/css_parser/css_parser_selector.go @@ -252,8 +252,17 @@ const ( func analyzeLeadingAmpersand(sel css_ast.ComplexSelector, isDeclarationContext bool) leadingAmpersand { if len(sel.Selectors) > 1 { if first := sel.Selectors[0]; first.IsSingleAmpersand() { - if second := sel.Selectors[1]; second.Combinator.Byte == 0 && len(second.NestingSelectorLocs) > 0 { + second := sel.Selectors[1] + rest := css_ast.ComplexSelector{Selectors: sel.Selectors[1:]} + if second.Combinator.Byte == 0 && rest.ContainsNestingCombinator() { // ".foo { & &.bar {} }" => ".foo { & &.bar {} }" + // ".foo { & .bar:not(& .baz) {} }" => ".foo { & .bar:not(& .baz) {} }" + + // The specification says: "If a selector in the + // does not start with a combinator but does contain the nesting selector, + // it is interpreted as a non-relative selector." So we don't want to + // remove the leading "&" here as that would change the meaning to a + // non-relative selector. See: https://www.w3.org/TR/css-nesting-1/ } else if second.Combinator.Byte != 0 || second.TypeSelector == nil || !isDeclarationContext { // "& + div {}" => "+ div {}" // "& div {}" => "div {}" @@ -264,6 +273,30 @@ func analyzeLeadingAmpersand(sel css_ast.ComplexSelector, isDeclarationContext b } else { // ".foo { & div {} }" // ".foo { .bar, & div {} }" => ".foo { .bar, div {} }" + + // The first iteration of CSS nesting didn't support an implicit "&" if + // the selector started with an identifier. This was done to avoid + // confusion with declarations in the parser, as the parser would + // otherwise need unbounded lookahead to distinguish between the two. + // Consider the following: + // + // span { + // color:blue; + // div:hover span {} + // } + // + // The "color:blue" is a declaration while "div:hover" is actually a + // relative selector in a nested style rule. The parser would need to + // scan to the ";" or "{" to distinguish between the two cases. + // Generally you want to avoid parsers with unbounded lookahead. + // + // However, this edge case is commonly encountered and it's confusing + // that it doesn't work. So the CSS working group later added unbounded + // lookahead to fix it: https://github.com/w3c/csswg-drafts/issues/7961. + // + // We deliberately don't take advantage of that newest syntax addition + // here so that our output still works in browsers before that newest + // syntax addition. We still keep a leading "&" before identifiers. return canRemoveLeadingAmpersandIfNotFirst } } diff --git a/vendor/github.com/evanw/esbuild/internal/helpers/mime.go b/vendor/github.com/evanw/esbuild/internal/helpers/mime.go index f928a8478..3a2f5a4ab 100644 --- a/vendor/github.com/evanw/esbuild/internal/helpers/mime.go +++ b/vendor/github.com/evanw/esbuild/internal/helpers/mime.go @@ -24,6 +24,9 @@ var builtinTypesLower = map[string]string{ ".svg": "image/svg+xml", ".webp": "image/webp", + // Audio + ".mp3": "audio/mpeg", + // Fonts ".eot": "application/vnd.ms-fontobject", ".otf": "font/otf", diff --git a/vendor/github.com/evanw/esbuild/internal/js_ast/js_ast.go b/vendor/github.com/evanw/esbuild/internal/js_ast/js_ast.go index 506fbdf0e..aa94f245b 100644 --- a/vendor/github.com/evanw/esbuild/internal/js_ast/js_ast.go +++ b/vendor/github.com/evanw/esbuild/internal/js_ast/js_ast.go @@ -540,9 +540,10 @@ type EUnary struct { } type EBinary struct { - Left Expr - Right Expr - Op OpCode + Left Expr + Right Expr + Op OpCode + IsParenthesized bool } type EBoolean struct{ Value bool } diff --git a/vendor/github.com/evanw/esbuild/internal/js_parser/js_parser.go b/vendor/github.com/evanw/esbuild/internal/js_parser/js_parser.go index a28386673..5bfa4555b 100644 --- a/vendor/github.com/evanw/esbuild/internal/js_parser/js_parser.go +++ b/vendor/github.com/evanw/esbuild/internal/js_parser/js_parser.go @@ -42,7 +42,7 @@ type parser struct { fnOnlyDataVisit fnOnlyDataVisit allocatedNames []string currentScope *js_ast.Scope - scopesForCurrentPart []*js_ast.Scope + currentPart *js_ast.Part symbols []ast.Symbol astHelpers js_ast.HelperContext tsUseCounts []uint32 @@ -53,10 +53,6 @@ type parser struct { exprComments map[logger.Loc][]string mangledProps map[string]ast.Ref reservedProps map[string]bool - symbolUses map[ast.Ref]js_ast.SymbolUse - importSymbolPropertyUses map[ast.Ref]map[string]js_ast.SymbolUse - symbolCallUses map[ast.Ref]js_ast.SymbolCallUse - declaredSymbols []js_ast.DeclaredSymbol globPatternImports []globPatternImport runtimeImports map[string]ast.LocRef duplicateCaseChecker duplicateCaseChecker @@ -115,9 +111,8 @@ type parser struct { enclosingNamespaceArgRef *ast.Ref // Imports (both ES6 and CommonJS) are tracked at the top level - importRecords []ast.ImportRecord - importRecordsForCurrentPart []uint32 - exportStarImportRecords []uint32 + importRecords []ast.ImportRecord + exportStarImportRecords []uint32 // These are for handling ES6 imports and exports importItemsForNamespace map[ast.Ref]namespaceImportItems @@ -1735,9 +1730,11 @@ func (p *parser) recordUsage(ref ast.Ref) { // code regions since those will be culled. if !p.isControlFlowDead { p.symbols[ref.InnerIndex].UseCountEstimate++ - use := p.symbolUses[ref] - use.CountEstimate++ - p.symbolUses[ref] = use + if part := p.currentPart; part != nil { + use := part.SymbolUses[ref] + use.CountEstimate++ + part.SymbolUses[ref] = use + } } // The correctness of TypeScript-to-JavaScript conversion relies on accurate @@ -1752,12 +1749,16 @@ func (p *parser) ignoreUsage(ref ast.Ref) { // Roll back the use count increment in recordUsage() if !p.isControlFlowDead { p.symbols[ref.InnerIndex].UseCountEstimate-- - use := p.symbolUses[ref] - use.CountEstimate-- - if use.CountEstimate == 0 { - delete(p.symbolUses, ref) - } else { - p.symbolUses[ref] = use + + // Only remove this usage if we're currently processing a part + if part := p.currentPart; part != nil { + use := part.SymbolUses[ref] + use.CountEstimate-- + if use.CountEstimate == 0 { + delete(part.SymbolUses, ref) + } else { + part.SymbolUses[ref] = use + } } } @@ -4262,6 +4263,7 @@ func (p *parser) parseExprCommon(level js_ast.L, errors *deferredErrors, flags e func (p *parser) parseSuffix(left js_ast.Expr, level js_ast.L, errors *deferredErrors, flags exprFlag) js_ast.Expr { optionalChain := js_ast.OptionalChainNone + afterAsLoc := logger.Loc{Start: -1} for { if p.lexer.Loc() == p.afterArrowBodyLoc { @@ -4281,9 +4283,11 @@ func (p *parser) parseSuffix(left js_ast.Expr, level js_ast.L, errors *deferredE } // Stop now if this token is forbidden to follow a TypeScript "as" cast - if p.lexer.Loc() == p.forbidSuffixAfterAsLoc { + operatorRange := p.lexer.Range() + if operatorRange.Loc == p.forbidSuffixAfterAsLoc { return left } + isAfterAs := operatorRange.Loc == afterAsLoc // Reset the optional chain flag by default. That way we won't accidentally // treat "c.d" as OptionalChainContinue in "a?.b + c.d". @@ -4976,11 +4980,39 @@ func (p *parser) parseSuffix(left js_ast.Expr, level js_ast.L, errors *deferredE p.forbidSuffixAfterAsLoc = p.lexer.Loc() return left } + afterAsLoc = p.lexer.Loc() continue } return left } + + // See: https://github.com/microsoft/TypeScript/issues/63527 + if isAfterAs { + if binary, ok := left.Data.(*js_ast.EBinary); ok { + if binaryLeft, ok := binary.Left.Data.(*js_ast.EBinary); ok && !binaryLeft.IsParenthesized { + rightLevel := js_ast.OpTable[binary.Op].Level + if binary.Op.IsRightAssociative() { + rightLevel++ + } + if rightLevel > js_ast.OpTable[binaryLeft.Op].Level { + start := binary.Left.Loc + end := p.source.LocBeforeWhitespace(operatorRange.Loc) + wrapRange := logger.Range{Loc: start, Len: end.Start - start.Start} + note := logger.MsgData{Text: "This is a syntax error in newer versions of TypeScript because the type cast has unintuitive precedence in this case."} + if text := p.source.TextForRange(wrapRange); !strings.ContainsRune(text, '\n') { + note = p.tracker.MsgData(wrapRange, note.Text+" Surround the inner expression in parentheses to silence this warning:") + note.Location.Suggestion = textForParenthesesSuggestion(text) + } + p.log.AddIDWithNotes(logger.MsgID_JS_ConfusingTypeScriptCast, logger.Warning, &p.tracker, operatorRange, + fmt.Sprintf("Operator %q should not directly follow a TypeScript type cast after the %q operator", + js_ast.OpTable[binary.Op].Text, js_ast.OpTable[binaryLeft.Op].Text), + []logger.MsgData{note}, + ) + } + } + } + } } } @@ -7019,7 +7051,7 @@ loop: var notes []logger.MsgData if text := p.source.TextForRange(wrapRange); !strings.ContainsRune(text, '\n') { note := p.tracker.MsgData(wrapRange, "Wrap this decorator in parentheses to allow arbitrary expressions:") - note.Location.Suggestion = fmt.Sprintf("(%s)", text) + note.Location.Suggestion = textForParenthesesSuggestion(text) notes = []logger.MsgData{note} } p.log.AddMsg(logger.Msg{ @@ -7032,6 +7064,14 @@ loop: return memberExpr } +func textForParenthesesSuggestion(text string) string { + count := utf8.RuneCountInString(text) - 2 + if count < 1 { + count = 1 + } + return fmt.Sprintf("(%s)", strings.Repeat(" ", count)) +} + type lexicalDecl uint8 const ( @@ -8627,7 +8667,10 @@ func (p *parser) pushScopeForVisitPass(kind js_ast.ScopeKind, loc logger.Loc) { p.scopesInOrder = p.scopesInOrder[1:] p.currentScope = order.scope - p.scopesForCurrentPart = append(p.scopesForCurrentPart, order.scope) + + if part := p.currentPart; part != nil { + part.Scopes = append(part.Scopes, order.scope) + } } type findSymbolResult struct { @@ -10027,7 +10070,7 @@ func (p *parser) recordDeclaredSymbol(ref ast.Ref) { } } - p.declaredSymbols = append(p.declaredSymbols, js_ast.DeclaredSymbol{ + p.currentPart.DeclaredSymbols = append(p.currentPart.DeclaredSymbols, js_ast.DeclaredSymbol{ Ref: ref, IsTopLevel: isTopLevel, }) @@ -11867,6 +11910,8 @@ func (p *parser) markExprAsParenthesized(value js_ast.Expr, openParenLoc logger. e.IsParenthesized = true case *js_ast.EArrow: e.IsParenthesized = true + case *js_ast.EBinary: + e.IsParenthesized = true } } @@ -13084,22 +13129,25 @@ func (p *parser) maybeRewritePropertyAccess( if p.options.mode == config.ModeBundle && !p.isControlFlowDead { if id, ok := target.Data.(*js_ast.EImportIdentifier); ok { // Remove the normal symbol use - use := p.symbolUses[id.Ref] + symbolUses := p.currentPart.SymbolUses + use := symbolUses[id.Ref] use.CountEstimate-- if use.CountEstimate == 0 { - delete(p.symbolUses, id.Ref) + delete(symbolUses, id.Ref) } else { - p.symbolUses[id.Ref] = use + symbolUses[id.Ref] = use } // Add a special symbol use instead - if p.importSymbolPropertyUses == nil { - p.importSymbolPropertyUses = make(map[ast.Ref]map[string]js_ast.SymbolUse) + importSymbolPropertyUses := p.currentPart.ImportSymbolPropertyUses + if importSymbolPropertyUses == nil { + importSymbolPropertyUses = make(map[ast.Ref]map[string]js_ast.SymbolUse) + p.currentPart.ImportSymbolPropertyUses = importSymbolPropertyUses } - properties := p.importSymbolPropertyUses[id.Ref] + properties := importSymbolPropertyUses[id.Ref] if properties == nil { properties = make(map[string]js_ast.SymbolUse) - p.importSymbolPropertyUses[id.Ref] = properties + importSymbolPropertyUses[id.Ref] = properties } use = properties[name] use.CountEstimate++ @@ -15122,7 +15170,7 @@ func (p *parser) visitExprInOut(expr js_ast.Expr, in exprIn) (js_ast.Expr, exprO record.Flags |= ast.HandlesImportErrors record.ErrorHandlerLoc = p.thenCatchChain.catchLoc } - p.importRecordsForCurrentPart = append(p.importRecordsForCurrentPart, importRecordIndex) + p.currentPart.ImportRecordIndices = append(p.currentPart.ImportRecordIndices, importRecordIndex) return js_ast.Expr{Loc: expr.Loc, Data: &js_ast.EImportString{ ImportRecordIndex: importRecordIndex, CloseParenLoc: e.CloseParenLoc, @@ -15492,7 +15540,7 @@ func (p *parser) visitExprInOut(expr js_ast.Expr, in exprIn) (js_ast.Expr, exprO record.Flags |= ast.HandlesImportErrors record.ErrorHandlerLoc = p.fnOrArrowDataVisit.tryCatchLoc } - p.importRecordsForCurrentPart = append(p.importRecordsForCurrentPart, importRecordIndex) + p.currentPart.ImportRecordIndices = append(p.currentPart.ImportRecordIndices, importRecordIndex) // Create a new expression to represent the operation return js_ast.Expr{Loc: expr.Loc, Data: &js_ast.ERequireResolveString{ @@ -15710,7 +15758,7 @@ func (p *parser) visitExprInOut(expr js_ast.Expr, in exprIn) (js_ast.Expr, exprO record.Flags |= ast.HandlesImportErrors record.ErrorHandlerLoc = p.fnOrArrowDataVisit.tryCatchLoc } - p.importRecordsForCurrentPart = append(p.importRecordsForCurrentPart, importRecordIndex) + p.currentPart.ImportRecordIndices = append(p.currentPart.ImportRecordIndices, importRecordIndex) // Currently "require" is not converted into "import" for ESM if p.options.mode != config.ModeBundle && p.options.outputFormat == config.FormatESModule && !omitWarnings { @@ -16785,24 +16833,27 @@ func (p *parser) globPatternFromExpr(expr js_ast.Expr) ([]globPart, logger.Range func (p *parser) convertSymbolUseToCall(ref ast.Ref, isSingleNonSpreadArgCall bool) { // Remove the normal symbol use - use := p.symbolUses[ref] + symbolUses := p.currentPart.SymbolUses + use := symbolUses[ref] use.CountEstimate-- if use.CountEstimate == 0 { - delete(p.symbolUses, ref) + delete(symbolUses, ref) } else { - p.symbolUses[ref] = use + symbolUses[ref] = use } // Add a special symbol use instead - if p.symbolCallUses == nil { - p.symbolCallUses = make(map[ast.Ref]js_ast.SymbolCallUse) + symbolCallUses := p.currentPart.SymbolCallUses + if symbolCallUses == nil { + symbolCallUses = make(map[ast.Ref]js_ast.SymbolCallUse) + p.currentPart.SymbolCallUses = symbolCallUses } - callUse := p.symbolCallUses[ref] + callUse := symbolCallUses[ref] callUse.CallCountEstimate++ if isSingleNonSpreadArgCall { callUse.SingleArgNonSpreadCallCountEstimate++ } - p.symbolCallUses[ref] = callUse + symbolCallUses[ref] = callUse } func (p *parser) warnAboutImportNamespaceCall(target js_ast.Expr, kind importNamespaceCallKind) { @@ -17468,7 +17519,7 @@ func (p *parser) scanForImportsAndExports(stmts []js_ast.Stmt) (result importsEx } // Also record these automatically-generated top-level namespace alias symbols - p.declaredSymbols = append(p.declaredSymbols, js_ast.DeclaredSymbol{ + p.currentPart.DeclaredSymbols = append(p.currentPart.DeclaredSymbols, js_ast.DeclaredSymbol{ Ref: name.Ref, IsTopLevel: true, }) @@ -17506,7 +17557,7 @@ func (p *parser) scanForImportsAndExports(stmts []js_ast.Stmt) (result importsEx } } - p.importRecordsForCurrentPart = append(p.importRecordsForCurrentPart, s.ImportRecordIndex) + p.currentPart.ImportRecordIndices = append(p.currentPart.ImportRecordIndices, s.ImportRecordIndex) if s.StarNameLoc != nil { record.Flags |= ast.ContainsImportStar @@ -17557,7 +17608,7 @@ func (p *parser) scanForImportsAndExports(stmts []js_ast.Stmt) (result importsEx case *js_ast.SExportStar: record := &p.importRecords[s.ImportRecordIndex] - p.importRecordsForCurrentPart = append(p.importRecordsForCurrentPart, s.ImportRecordIndex) + p.currentPart.ImportRecordIndices = append(p.currentPart.ImportRecordIndices, s.ImportRecordIndex) if s.Alias != nil { // "export * as ns from 'path'" @@ -17578,7 +17629,7 @@ func (p *parser) scanForImportsAndExports(stmts []js_ast.Stmt) (result importsEx case *js_ast.SExportFrom: record := &p.importRecords[s.ImportRecordIndex] - p.importRecordsForCurrentPart = append(p.importRecordsForCurrentPart, s.ImportRecordIndex) + p.currentPart.ImportRecordIndices = append(p.currentPart.ImportRecordIndices, s.ImportRecordIndex) for _, item := range s.Items { // Note that the imported alias is not item.Alias, which is the @@ -17629,17 +17680,11 @@ func (p *parser) scanForImportsAndExports(stmts []js_ast.Stmt) (result importsEx } func (p *parser) appendPart(parts []js_ast.Part, stmts []js_ast.Stmt) []js_ast.Part { - p.symbolUses = make(map[ast.Ref]js_ast.SymbolUse) - p.importSymbolPropertyUses = nil - p.symbolCallUses = nil - p.declaredSymbols = nil - p.importRecordsForCurrentPart = nil - p.scopesForCurrentPart = nil - part := js_ast.Part{ - Stmts: p.visitStmtsAndPrependTempRefs(stmts, prependTempRefsOpts{}), - SymbolUses: p.symbolUses, + SymbolUses: make(map[ast.Ref]js_ast.SymbolUse), } + p.currentPart = &part + part.Stmts = p.visitStmtsAndPrependTempRefs(stmts, prependTempRefsOpts{}) // Sanity check if p.currentScope != p.moduleScope { @@ -17681,13 +17726,11 @@ func (p *parser) appendPart(parts []js_ast.Part, stmts []js_ast.Stmt) []js_ast.P flags |= js_ast.KeepExportClauses } part.CanBeRemovedIfUnused = p.astHelpers.StmtsCanBeRemovedIfUnused(part.Stmts, flags) - part.DeclaredSymbols = p.declaredSymbols - part.ImportRecordIndices = p.importRecordsForCurrentPart - part.ImportSymbolPropertyUses = p.importSymbolPropertyUses - part.SymbolCallUses = p.symbolCallUses - part.Scopes = p.scopesForCurrentPart parts = append(parts, part) } + + // Reset the state for this part so we don't accidentally mutate it + p.currentPart = nil return parts } @@ -18098,9 +18141,14 @@ func LazyExportAST(log logger.Log, source logger.Source, options Options, expr j p := newParser(log, source, js_lexer.Lexer{}, &options) p.prepareForVisitPass() + // Defer the actual code generation until linking + part := js_ast.Part{ + SymbolUses: make(map[ast.Ref]js_ast.SymbolUse), + } + // Optionally call a runtime API function to transform the expression if helperCall != nil { - p.symbolUses = make(map[ast.Ref]js_ast.SymbolUse) + p.currentPart = &part if len(helperCall.Global) > 0 { ref := p.newSymbol(ast.SymbolUnbound, helperCall.Global[0]) p.recordUsage(ref) @@ -18114,7 +18162,9 @@ func LazyExportAST(log logger.Log, source logger.Source, options Options, expr j } else { expr = p.callRuntime(expr.Loc, helperCall.Runtime, []js_ast.Expr{expr}) } + p.currentPart = nil } + part.Stmts = []js_ast.Stmt{{Loc: expr.Loc, Data: &js_ast.SLazyExport{Value: expr}}} // Add an empty part for the namespace export that we can fill in later nsExportPart := js_ast.Part{ @@ -18122,13 +18172,6 @@ func LazyExportAST(log logger.Log, source logger.Source, options Options, expr j CanBeRemovedIfUnused: true, } - // Defer the actual code generation until linking - part := js_ast.Part{ - Stmts: []js_ast.Stmt{{Loc: expr.Loc, Data: &js_ast.SLazyExport{Value: expr}}}, - SymbolUses: p.symbolUses, - } - p.symbolUses = nil - ast := p.toAST([]js_ast.Part{nsExportPart}, []js_ast.Part{part}, nil, "", nil) ast.HasLazyExport = true return ast @@ -18157,22 +18200,22 @@ func GlobResolveAST(log logger.Log, source logger.Source, importRecords []ast.Im importRecordIndices = append(importRecordIndices, uint32(importRecordIndex)) } - p.symbolUses = make(map[ast.Ref]js_ast.SymbolUse) ref := p.newSymbol(ast.SymbolOther, name) p.moduleScope.Generated = append(p.moduleScope.Generated, ref) - part := js_ast.Part{ - Stmts: []js_ast.Stmt{{Data: &js_ast.SLocal{ - IsExport: true, - Decls: []js_ast.Decl{{ - Binding: js_ast.Binding{Data: &js_ast.BIdentifier{Ref: ref}}, - ValueOrNil: p.callRuntime(logger.Loc{}, "__glob", []js_ast.Expr{{Data: object}}), - }}, - }}}, ImportRecordIndices: importRecordIndices, - SymbolUses: p.symbolUses, + SymbolUses: make(map[ast.Ref]js_ast.SymbolUse), } - p.symbolUses = nil + + p.currentPart = &part + part.Stmts = []js_ast.Stmt{{Data: &js_ast.SLocal{ + IsExport: true, + Decls: []js_ast.Decl{{ + Binding: js_ast.Binding{Data: &js_ast.BIdentifier{Ref: ref}}, + ValueOrNil: p.callRuntime(logger.Loc{}, "__glob", []js_ast.Expr{{Data: object}}), + }}, + }}} + p.currentPart = nil p.esmExportKeyword.Len = 1 return p.toAST([]js_ast.Part{nsExportPart}, []js_ast.Part{part}, nil, "", nil) @@ -18628,17 +18671,13 @@ func (p *parser) toAST(before, parts, after []js_ast.Part, hashbang string, dire removedImportEquals := false partsEnd := 0 for partIndex, part := range parts { - p.importRecordsForCurrentPart = nil - p.declaredSymbols = nil - + p.currentPart = &part result := p.scanForImportsAndExports(part.Stmts) + p.currentPart = nil part.Stmts = result.stmts keptImportEquals = keptImportEquals || result.keptImportEquals removedImportEquals = removedImportEquals || result.removedImportEquals - part.ImportRecordIndices = append(part.ImportRecordIndices, p.importRecordsForCurrentPart...) - part.DeclaredSymbols = append(part.DeclaredSymbols, p.declaredSymbols...) - if len(part.Stmts) > 0 || uint32(partIndex) == js_ast.NSExportPartIndex { if p.moduleScope.ContainsDirectEval && len(part.DeclaredSymbols) > 0 { // If this file contains a direct call to "eval()", all parts that diff --git a/vendor/github.com/evanw/esbuild/internal/js_parser/js_parser_lower.go b/vendor/github.com/evanw/esbuild/internal/js_parser/js_parser_lower.go index 5def4cbb5..ca7a82898 100644 --- a/vendor/github.com/evanw/esbuild/internal/js_parser/js_parser_lower.go +++ b/vendor/github.com/evanw/esbuild/internal/js_parser/js_parser_lower.go @@ -382,7 +382,7 @@ func (p *parser) lowerFunction( // Forward the arguments to the wrapper function usesArgumentsRef := !isArrow && p.fnOnlyDataVisit.argumentsRef != nil && - p.symbolUses[*p.fnOnlyDataVisit.argumentsRef].CountEstimate > 0 + p.currentPart.SymbolUses[*p.fnOnlyDataVisit.argumentsRef].CountEstimate > 0 var forwardedArgs js_ast.Expr if !couldThrowErrors && !usesArgumentsRef { // Simple case: the arguments can stay on the outer function. It's @@ -849,6 +849,26 @@ func (p *parser) lowerAssignmentOperator(value js_ast.Expr, callback func(js_ast } case *js_ast.EIdentifier: + // Make sure we record this usage in the usage count so that duplicating + // a single-use reference means it's no longer considered a single-use + // reference. Otherwise the single-use reference inlining code may + // incorrectly inline the initializer into the first reference, leaving + // the second reference without a definition. For example: + // + // let x; + // x ||= {}; + // + // We're changing that to this: + // + // let x; + // x || (x = {}); + // + // And we don't want to believe that "x" still has a single reference, as + // then we may incorrectly inline the undefined value like this: + // + // void 0 || (x = {}); + // + p.recordUsage(left.Ref) return callback( js_ast.Expr{Loc: value.Loc, Data: &js_ast.EIdentifier{Ref: left.Ref}}, value, @@ -2011,7 +2031,7 @@ func (ctx *lowerUsingDeclarationContext) finalize(p *parser, stmts []js_ast.Stmt } isTopLevel := scope == p.moduleScope scope.Generated = append(scope.Generated, ctx.stackRef, caughtRef, errorRef, hasErrorRef) - p.declaredSymbols = append(p.declaredSymbols, + p.currentPart.DeclaredSymbols = append(p.currentPart.DeclaredSymbols, js_ast.DeclaredSymbol{IsTopLevel: isTopLevel, Ref: ctx.stackRef}, js_ast.DeclaredSymbol{IsTopLevel: isTopLevel, Ref: caughtRef}, js_ast.DeclaredSymbol{IsTopLevel: isTopLevel, Ref: errorRef}, @@ -2034,7 +2054,7 @@ func (ctx *lowerUsingDeclarationContext) finalize(p *parser, stmts []js_ast.Stmt if ctx.hasAwaitUsing { promiseRef := p.generateTempRef(tempRefNoDeclare, "_promise") scope.Generated = append(scope.Generated, promiseRef) - p.declaredSymbols = append(p.declaredSymbols, js_ast.DeclaredSymbol{IsTopLevel: isTopLevel, Ref: promiseRef}) + p.currentPart.DeclaredSymbols = append(p.currentPart.DeclaredSymbols, js_ast.DeclaredSymbol{IsTopLevel: isTopLevel, Ref: promiseRef}) // "await" expressions turn into "yield" expressions when lowering p.recordUsage(promiseRef) diff --git a/vendor/github.com/evanw/esbuild/internal/logger/logger.go b/vendor/github.com/evanw/esbuild/internal/logger/logger.go index eb47d2bf0..6fbbf6b80 100644 --- a/vendor/github.com/evanw/esbuild/internal/logger/logger.go +++ b/vendor/github.com/evanw/esbuild/internal/logger/logger.go @@ -47,6 +47,13 @@ const ( LevelSilent ) +type LogStyle int8 + +const ( + StyleDefault LogStyle = iota + StyleVisualStudio +) + type MsgKind uint8 const ( @@ -839,6 +846,7 @@ func OutputOptionsForArgs(osArgs []string) OutputOptions { options.Color = ColorNever case "--color=true", "--color": options.Color = ColorAlways + case "--log-level=info": options.LogLevel = LevelInfo case "--log-level=warning": @@ -847,6 +855,11 @@ func OutputOptionsForArgs(osArgs []string) OutputOptions { options.LogLevel = LevelError case "--log-level=silent": options.LogLevel = LevelSilent + + case "--log-style=default": + options.LogStyle = StyleDefault + case "--log-level=visualstudio": + options.LogStyle = StyleVisualStudio } } @@ -1202,275 +1215,24 @@ type OutputOptions struct { IncludeSource bool Color UseColor LogLevel LogLevel + LogStyle LogStyle PathStyle PathStyle Overrides map[MsgID]LogLevel } func (msg Msg) String(options OutputOptions, terminalInfo TerminalInfo) string { - // Format the message - var text strings.Builder - text.WriteString(msgString(options.IncludeSource, options.PathStyle, terminalInfo, msg.ID, msg.Kind, msg.Data, msg.PluginName)) - - // Format the notes - var oldData MsgData - for i, note := range msg.Notes { - if options.IncludeSource && (i == 0 || strings.IndexByte(oldData.Text, '\n') >= 0 || oldData.Location != nil) { - text.WriteString("\n") - } - text.WriteString(msgString(options.IncludeSource, options.PathStyle, terminalInfo, MsgID_None, Note, note, "")) - oldData = note - } + switch options.LogStyle { + case StyleVisualStudio: + return msgToStringVisualStudio(msg, options, terminalInfo) - // Add extra spacing between messages if source code is present - if options.IncludeSource { - text.WriteString("\n") + default: + return msgToStringDefault(msg, options, terminalInfo) } - return text.String() } // The number of margin characters in addition to the line number const extraMarginChars = 9 -func marginWithLineText(maxMargin int, line int) string { - number := fmt.Sprintf("%d", line) - return fmt.Sprintf(" %s%s │ ", strings.Repeat(" ", maxMargin-len(number)), number) -} - -func emptyMarginText(maxMargin int, isLast bool) string { - space := strings.Repeat(" ", maxMargin) - if isLast { - return fmt.Sprintf(" %s ╵ ", space) - } - return fmt.Sprintf(" %s │ ", space) -} - -func msgString(includeSource bool, pathStyle PathStyle, terminalInfo TerminalInfo, id MsgID, kind MsgKind, data MsgData, pluginName string) string { - if !includeSource { - if loc := data.Location; loc != nil { - return fmt.Sprintf("%s: %s: %s\n", loc.File.Select(pathStyle), kind.String(), data.Text) - } - return fmt.Sprintf("%s: %s\n", kind.String(), data.Text) - } - - var colors Colors - if terminalInfo.UseColorEscapes { - colors = TerminalColors - } - - var iconColor string - var kindColorBrackets string - var kindColorText string - - location := "" - - if data.Location != nil { - maxMargin := len(fmt.Sprintf("%d", data.Location.Line)) - d := detailStruct(data, pathStyle, terminalInfo, maxMargin) - - if d.Suggestion != "" { - location = fmt.Sprintf("\n %s:%d:%d:\n%s%s%s%s%s%s\n%s%s%s%s%s\n%s%s%s%s%s\n%s", - d.Path, d.Line, d.Column, - colors.Dim, d.SourceBefore, colors.Green, d.SourceMarked, colors.Dim, d.SourceAfter, - emptyMarginText(maxMargin, false), d.Indent, colors.Green, d.Marker, colors.Dim, - emptyMarginText(maxMargin, true), d.Indent, colors.Green, d.Suggestion, colors.Reset, - d.ContentAfter, - ) - } else { - location = fmt.Sprintf("\n %s:%d:%d:\n%s%s%s%s%s%s\n%s%s%s%s%s\n%s", - d.Path, d.Line, d.Column, - colors.Dim, d.SourceBefore, colors.Green, d.SourceMarked, colors.Dim, d.SourceAfter, - emptyMarginText(maxMargin, true), d.Indent, colors.Green, d.Marker, colors.Reset, - d.ContentAfter, - ) - } - } - - switch kind { - case Verbose: - iconColor = colors.Cyan - kindColorBrackets = colors.CyanBgCyan - kindColorText = colors.CyanBgBlack - - case Debug: - iconColor = colors.Green - kindColorBrackets = colors.GreenBgGreen - kindColorText = colors.GreenBgWhite - - case Info: - iconColor = colors.Blue - kindColorBrackets = colors.BlueBgBlue - kindColorText = colors.BlueBgWhite - - case Error: - iconColor = colors.Red - kindColorBrackets = colors.RedBgRed - kindColorText = colors.RedBgWhite - - case Warning: - iconColor = colors.Yellow - kindColorBrackets = colors.YellowBgYellow - kindColorText = colors.YellowBgBlack - - case Note: - sb := strings.Builder{} - - for _, line := range strings.Split(data.Text, "\n") { - // Special-case word wrapping - if wrapWidth := terminalInfo.Width; wrapWidth > 2 { - if !data.DisableMaximumWidth && wrapWidth > 100 { - wrapWidth = 100 // Enforce a maximum paragraph width for readability - } - for _, run := range wrapWordsInString(line, wrapWidth-2) { - sb.WriteString(" ") - sb.WriteString(linkifyText(run, colors.Underline, colors.Reset)) - sb.WriteByte('\n') - } - continue - } - - // Otherwise, just write an indented line - sb.WriteString(" ") - sb.WriteString(linkifyText(line, colors.Underline, colors.Reset)) - sb.WriteByte('\n') - } - - sb.WriteString(location) - return sb.String() - } - - if pluginName != "" { - pluginName = fmt.Sprintf(" %s%s[plugin %s]%s", colors.Bold, colors.Magenta, pluginName, colors.Reset) - } - - msgID := MsgIDToString(id) - if msgID != "" { - msgID = fmt.Sprintf(" [%s]", msgID) - } - - return fmt.Sprintf("%s%s %s[%s%s%s]%s %s%s%s%s%s\n%s", - iconColor, kind.Icon(), - kindColorBrackets, kindColorText, kind.String(), kindColorBrackets, colors.Reset, - colors.Bold, data.Text, colors.Reset, pluginName, msgID, - location, - ) -} - -func linkifyText(text string, underline string, reset string) string { - if underline == "" { - return text - } - - https := strings.Index(text, "https://") - if https == -1 { - return text - } - - sb := strings.Builder{} - for { - https := strings.Index(text, "https://") - if https == -1 { - break - } - - end := strings.IndexByte(text[https:], ' ') - if end == -1 { - end = len(text) - } else { - end += https - } - - // Remove trailing punctuation - if end > https { - switch text[end-1] { - case '.', ',', '?', '!', ')', ']', '}': - end-- - } - } - - sb.WriteString(text[:https]) - sb.WriteString(underline) - sb.WriteString(text[https:end]) - sb.WriteString(reset) - text = text[end:] - } - - sb.WriteString(text) - return sb.String() -} - -func wrapWordsInString(text string, width int) []string { - runs := []string{} - -outer: - for text != "" { - i := 0 - x := 0 - wordEndI := 0 - - // Skip over any leading spaces - for i < len(text) && text[i] == ' ' { - i++ - x++ - } - - // Find out how many words will fit in this run - for i < len(text) { - oldWordEndI := wordEndI - wordStartI := i - - // Find the end of the word - for i < len(text) { - c, width := utf8.DecodeRuneInString(text[i:]) - if c == ' ' { - break - } - i += width - x += 1 // Naively assume that each unicode code point is a single column - } - wordEndI = i - - // Split into a new run if this isn't the first word in the run and the end is past the width - if wordStartI > 0 && x > width { - runs = append(runs, text[:oldWordEndI]) - text = text[wordStartI:] - continue outer - } - - // Skip over any spaces after the word - for i < len(text) && text[i] == ' ' { - i++ - x++ - } - } - - // If we get here, this is the last run (i.e. everything fits) - break - } - - // Remove any trailing spaces on the last run - for len(text) > 0 && text[len(text)-1] == ' ' { - text = text[:len(text)-1] - } - runs = append(runs, text) - return runs -} - -type MsgDetail struct { - SourceBefore string - SourceMarked string - SourceAfter string - - Indent string - Marker string - Suggestion string - - ContentAfter string - - Path string - Line int - Column int -} - // It's not common for large files to have many warnings. But when it happens, // we want to make sure that it's not too slow. Source code locations are // represented as byte offsets for compactness but transforming these to @@ -1639,193 +1401,6 @@ func (tracker *LineColumnTracker) MsgLocationOrNil(r Range) *MsgLocation { } } -func detailStruct(data MsgData, pathStyle PathStyle, terminalInfo TerminalInfo, maxMargin int) MsgDetail { - // Only highlight the first line of the line text - loc := *data.Location - endOfFirstLine := len(loc.LineText) - - // Note: This uses "IndexByte" because Go implements this with SIMD, which - // can matter a lot for really long lines. Some people pass huge >100mb - // minified files as line text for the log message. - if i := strings.IndexByte(loc.LineText, '\n'); i >= 0 { - endOfFirstLine = i - } - - firstLine := loc.LineText[:endOfFirstLine] - afterFirstLine := loc.LineText[endOfFirstLine:] - if afterFirstLine != "" && !strings.HasSuffix(afterFirstLine, "\n") { - afterFirstLine += "\n" - } - - // Clamp values in range - if loc.Line < 0 { - loc.Line = 0 - } - if loc.Column < 0 { - loc.Column = 0 - } - if loc.Length < 0 { - loc.Length = 0 - } - if loc.Column > endOfFirstLine { - loc.Column = endOfFirstLine - } - if loc.Length > endOfFirstLine-loc.Column { - loc.Length = endOfFirstLine - loc.Column - } - - spacesPerTab := 2 - lineText := renderTabStops(firstLine, spacesPerTab) - textUpToLoc := renderTabStops(firstLine[:loc.Column], spacesPerTab) - markerStart := len(textUpToLoc) - markerEnd := markerStart - indent := strings.Repeat(" ", estimateWidthInTerminal(textUpToLoc)) - marker := "^" - - // Extend markers to cover the full range of the error - if loc.Length > 0 { - markerEnd = len(renderTabStops(firstLine[:loc.Column+loc.Length], spacesPerTab)) - } - - // Clip the marker to the bounds of the line - if markerStart > len(lineText) { - markerStart = len(lineText) - } - if markerEnd > len(lineText) { - markerEnd = len(lineText) - } - if markerEnd < markerStart { - markerEnd = markerStart - } - - // Trim the line to fit the terminal width - width := terminalInfo.Width - if width < 1 { - width = defaultTerminalWidth - } - width -= maxMargin + extraMarginChars - if width < 1 { - width = 1 - } - if loc.Column == endOfFirstLine { - // If the marker is at the very end of the line, the marker will be a "^" - // character that extends one column past the end of the line. In this case - // we should reserve a column at the end so the marker doesn't wrap. - width -= 1 - } - if len(lineText) > width { - // Try to center the error - sliceStart := (markerStart + markerEnd - width) / 2 - if sliceStart > markerStart-width/5 { - sliceStart = markerStart - width/5 - } - if sliceStart < 0 { - sliceStart = 0 - } - if sliceStart > len(lineText)-width { - sliceStart = len(lineText) - width - } - sliceEnd := sliceStart + width - - // Slice the line - slicedLine := lineText[sliceStart:sliceEnd] - markerStart -= sliceStart - markerEnd -= sliceStart - if markerStart < 0 { - markerStart = 0 - } - if markerEnd > len(slicedLine) { - markerEnd = len(slicedLine) - } - - // Truncate the ends with "..." - if len(slicedLine) > 3 && sliceStart > 0 { - slicedLine = "..." + slicedLine[3:] - if markerStart < 3 { - markerStart = 3 - } - } - if len(slicedLine) > 3 && sliceEnd < len(lineText) { - slicedLine = slicedLine[:len(slicedLine)-3] + "..." - if markerEnd > len(slicedLine)-3 { - markerEnd = len(slicedLine) - 3 - } - if markerEnd < markerStart { - markerEnd = markerStart - } - } - - // Now we can compute the indent - lineText = slicedLine - indent = strings.Repeat(" ", estimateWidthInTerminal(lineText[:markerStart])) - } - - // If marker is still multi-character after clipping, make the marker wider - if markerEnd-markerStart > 1 { - marker = strings.Repeat("~", estimateWidthInTerminal(lineText[markerStart:markerEnd])) - } - - // Put a margin before the marker indent - margin := marginWithLineText(maxMargin, loc.Line) - - return MsgDetail{ - Path: loc.File.Select(pathStyle), - Line: loc.Line, - Column: loc.Column, - - SourceBefore: margin + lineText[:markerStart], - SourceMarked: lineText[markerStart:markerEnd], - SourceAfter: lineText[markerEnd:], - - Indent: indent, - Marker: marker, - Suggestion: loc.Suggestion, - - ContentAfter: afterFirstLine, - } -} - -// Estimate the number of columns this string will take when printed -func estimateWidthInTerminal(text string) int { - // For now just assume each code point is one column. This is wrong but is - // less wrong than assuming each code unit is one column. - width := 0 - for text != "" { - c, size := utf8.DecodeRuneInString(text) - text = text[size:] - - // Ignore the Zero Width No-Break Space character (UTF-8 BOM) - if c != 0xFEFF { - width++ - } - } - return width -} - -func renderTabStops(withTabs string, spacesPerTab int) string { - if !strings.ContainsRune(withTabs, '\t') { - return withTabs - } - - withoutTabs := strings.Builder{} - count := 0 - - for _, c := range withTabs { - if c == '\t' { - spaces := spacesPerTab - count%spacesPerTab - for i := 0; i < spaces; i++ { - withoutTabs.WriteRune(' ') - count++ - } - } else { - withoutTabs.WriteRune(c) - count++ - } - } - - return withoutTabs.String() -} - func (log Log) AddError(tracker *LineColumnTracker, r Range, text string) { log.AddMsg(Msg{ Kind: Error, diff --git a/vendor/github.com/evanw/esbuild/internal/logger/msg_ids.go b/vendor/github.com/evanw/esbuild/internal/logger/msg_ids.go index b9a56ed01..3a1829c2e 100644 --- a/vendor/github.com/evanw/esbuild/internal/logger/msg_ids.go +++ b/vendor/github.com/evanw/esbuild/internal/logger/msg_ids.go @@ -21,6 +21,7 @@ const ( MsgID_JS_CallImportNamespace MsgID_JS_ClassNameWillThrow MsgID_JS_CommonJSVariableInESM + MsgID_JS_ConfusingTypeScriptCast MsgID_JS_DeleteSuperProperty MsgID_JS_DirectEval MsgID_JS_DuplicateCase @@ -116,6 +117,8 @@ func StringToMsgIDs(str string, logLevel LogLevel, overrides map[MsgID]LogLevel) overrides[MsgID_JS_ClassNameWillThrow] = logLevel case "commonjs-variable-in-esm": overrides[MsgID_JS_CommonJSVariableInESM] = logLevel + case "confusing-typescript-cast": + overrides[MsgID_JS_ConfusingTypeScriptCast] = logLevel case "delete-super-property": overrides[MsgID_JS_DeleteSuperProperty] = logLevel case "direct-eval": @@ -227,132 +230,144 @@ func StringToMsgIDs(str string, logLevel LogLevel, overrides map[MsgID]LogLevel) } } +// These are stored together to make it less accident-prone to edit them +type msgIDInfo struct { + name string + vsID vsID +} + func MsgIDToString(id MsgID) string { + return msgIDToInfo(id).name +} + +func msgIDToInfo(id MsgID) msgIDInfo { switch id { // JS case MsgID_JS_AssertToWith: - return "assert-to-with" + return msgIDInfo{name: "assert-to-with", vsID: vsID_JS_AssertToWith} case MsgID_JS_AssertTypeJSON: - return "assert-type-json" + return msgIDInfo{name: "assert-type-json", vsID: vsID_JS_AssertTypeJSON} case MsgID_JS_AssignToConstant: - return "assign-to-constant" + return msgIDInfo{name: "assign-to-constant", vsID: vsID_JS_AssignToConstant} case MsgID_JS_AssignToDefine: - return "assign-to-define" + return msgIDInfo{name: "assign-to-define", vsID: vsID_JS_AssignToDefine} case MsgID_JS_AssignToImport: - return "assign-to-import" + return msgIDInfo{name: "assign-to-import", vsID: vsID_JS_AssignToImport} case MsgID_JS_BigInt: - return "bigint" + return msgIDInfo{name: "bigint", vsID: vsID_JS_BigInt} case MsgID_JS_CallImportNamespace: - return "call-import-namespace" + return msgIDInfo{name: "call-import-namespace", vsID: vsID_JS_CallImportNamespace} case MsgID_JS_ClassNameWillThrow: - return "class-name-will-throw" + return msgIDInfo{name: "class-name-will-throw", vsID: vsID_JS_ClassNameWillThrow} case MsgID_JS_CommonJSVariableInESM: - return "commonjs-variable-in-esm" + return msgIDInfo{name: "commonjs-variable-in-esm", vsID: vsID_JS_CommonJSVariableInESM} + case MsgID_JS_ConfusingTypeScriptCast: + return msgIDInfo{name: "confusing-typescript-cast", vsID: vsID_JS_ConfusingTypeScriptCast} case MsgID_JS_DeleteSuperProperty: - return "delete-super-property" + return msgIDInfo{name: "delete-super-property", vsID: vsID_JS_DeleteSuperProperty} case MsgID_JS_DirectEval: - return "direct-eval" + return msgIDInfo{name: "direct-eval", vsID: vsID_JS_DirectEval} case MsgID_JS_DuplicateCase: - return "duplicate-case" + return msgIDInfo{name: "duplicate-case", vsID: vsID_JS_DuplicateCase} case MsgID_JS_DuplicateClassMember: - return "duplicate-class-member" + return msgIDInfo{name: "duplicate-class-member", vsID: vsID_JS_DuplicateClassMember} case MsgID_JS_DuplicateObjectKey: - return "duplicate-object-key" + return msgIDInfo{name: "duplicate-object-key", vsID: vsID_JS_DuplicateObjectKey} case MsgID_JS_EmptyImportMeta: - return "empty-import-meta" + return msgIDInfo{name: "empty-import-meta", vsID: vsID_JS_EmptyImportMeta} case MsgID_JS_EqualsNaN: - return "equals-nan" + return msgIDInfo{name: "equals-nan", vsID: vsID_JS_EqualsNaN} case MsgID_JS_EqualsNegativeZero: - return "equals-negative-zero" + return msgIDInfo{name: "equals-negative-zero", vsID: vsID_JS_EqualsNegativeZero} case MsgID_JS_EqualsNewObject: - return "equals-new-object" + return msgIDInfo{name: "equals-new-object", vsID: vsID_JS_EqualsNewObject} case MsgID_JS_HTMLCommentInJS: - return "html-comment-in-js" + return msgIDInfo{name: "html-comment-in-js", vsID: vsID_JS_HTMLCommentInJS} case MsgID_JS_ImpossibleTypeof: - return "impossible-typeof" + return msgIDInfo{name: "impossible-typeof", vsID: vsID_JS_ImpossibleTypeof} case MsgID_JS_IndirectRequire: - return "indirect-require" + return msgIDInfo{name: "indirect-require", vsID: vsID_JS_IndirectRequire} case MsgID_JS_PrivateNameWillThrow: - return "private-name-will-throw" + return msgIDInfo{name: "private-name-will-throw", vsID: vsID_JS_PrivateNameWillThrow} case MsgID_JS_SemicolonAfterReturn: - return "semicolon-after-return" + return msgIDInfo{name: "semicolon-after-return", vsID: vsID_JS_SemicolonAfterReturn} case MsgID_JS_SuspiciousBooleanNot: - return "suspicious-boolean-not" + return msgIDInfo{name: "suspicious-boolean-not", vsID: vsID_JS_SuspiciousBooleanNot} case MsgID_JS_SuspiciousDefine: - return "suspicious-define" + return msgIDInfo{name: "suspicious-define", vsID: vsID_JS_SuspiciousDefine} case MsgID_JS_SuspiciousLogicalOperator: - return "suspicious-logical-operator" + return msgIDInfo{name: "suspicious-logical-operator", vsID: vsID_JS_SuspiciousLogicalOperator} case MsgID_JS_SuspiciousNullishCoalescing: - return "suspicious-nullish-coalescing" + return msgIDInfo{name: "suspicious-nullish-coalescing", vsID: vsID_JS_SuspiciousNullishCoalescing} case MsgID_JS_ThisIsUndefinedInESM: - return "this-is-undefined-in-esm" + return msgIDInfo{name: "this-is-undefined-in-esm", vsID: vsID_JS_ThisIsUndefinedInESM} case MsgID_JS_UnsupportedDynamicImport: - return "unsupported-dynamic-import" + return msgIDInfo{name: "unsupported-dynamic-import", vsID: vsID_JS_UnsupportedDynamicImport} case MsgID_JS_UnsupportedJSXComment: - return "unsupported-jsx-comment" + return msgIDInfo{name: "unsupported-jsx-comment", vsID: vsID_JS_UnsupportedJSXComment} case MsgID_JS_UnsupportedRegExp: - return "unsupported-regexp" + return msgIDInfo{name: "unsupported-regexp", vsID: vsID_JS_UnsupportedRegExp} case MsgID_JS_UnsupportedRequireCall: - return "unsupported-require-call" + return msgIDInfo{name: "unsupported-require-call", vsID: vsID_JS_UnsupportedRequireCall} // CSS case MsgID_CSS_CSSSyntaxError: - return "css-syntax-error" + return msgIDInfo{name: "css-syntax-error", vsID: vsID_CSS_CSSSyntaxError} case MsgID_CSS_InvalidAtCharset: - return "invalid-@charset" + return msgIDInfo{name: "invalid-@charset", vsID: vsID_CSS_InvalidAtCharset} case MsgID_CSS_InvalidAtImport: - return "invalid-@import" + return msgIDInfo{name: "invalid-@import", vsID: vsID_CSS_InvalidAtImport} case MsgID_CSS_InvalidAtLayer: - return "invalid-@layer" + return msgIDInfo{name: "invalid-@layer", vsID: vsID_CSS_InvalidAtLayer} case MsgID_CSS_InvalidCalc: - return "invalid-calc" + return msgIDInfo{name: "invalid-calc", vsID: vsID_CSS_InvalidCalc} case MsgID_CSS_JSCommentInCSS: - return "js-comment-in-css" + return msgIDInfo{name: "js-comment-in-css", vsID: vsID_CSS_JSCommentInCSS} case MsgID_CSS_UndefinedComposesFrom: - return "undefined-composes-from" + return msgIDInfo{name: "undefined-composes-from", vsID: vsID_CSS_UndefinedComposesFrom} case MsgID_CSS_UnsupportedAtCharset: - return "unsupported-@charset" + return msgIDInfo{name: "unsupported-@charset", vsID: vsID_CSS_UnsupportedAtCharset} case MsgID_CSS_UnsupportedAtNamespace: - return "unsupported-@namespace" + return msgIDInfo{name: "unsupported-@namespace", vsID: vsID_CSS_UnsupportedAtNamespace} case MsgID_CSS_UnsupportedCSSProperty: - return "unsupported-css-property" + return msgIDInfo{name: "unsupported-css-property", vsID: vsID_CSS_UnsupportedCSSProperty} case MsgID_CSS_UnsupportedCSSNesting: - return "unsupported-css-nesting" + return msgIDInfo{name: "unsupported-css-nesting", vsID: vsID_CSS_UnsupportedCSSNesting} // Bundler case MsgID_Bundler_AmbiguousReexport: - return "ambiguous-reexport" + return msgIDInfo{name: "ambiguous-reexport", vsID: vsID_Bundler_AmbiguousReexport} case MsgID_Bundler_DifferentPathCase: - return "different-path-case" + return msgIDInfo{name: "different-path-case", vsID: vsID_Bundler_DifferentPathCase} case MsgID_Bundler_EmptyGlob: - return "empty-glob" + return msgIDInfo{name: "empty-glob", vsID: vsID_Bundler_EmptyGlob} case MsgID_Bundler_IgnoredBareImport: - return "ignored-bare-import" + return msgIDInfo{name: "ignored-bare-import", vsID: vsID_Bundler_IgnoredBareImport} case MsgID_Bundler_IgnoredDynamicImport: - return "ignored-dynamic-import" + return msgIDInfo{name: "ignored-dynamic-import", vsID: vsID_Bundler_IgnoredDynamicImport} case MsgID_Bundler_ImportIsUndefined: - return "import-is-undefined" + return msgIDInfo{name: "import-is-undefined", vsID: vsID_Bundler_ImportIsUndefined} case MsgID_Bundler_RequireResolveNotExternal: - return "require-resolve-not-external" + return msgIDInfo{name: "require-resolve-not-external", vsID: vsID_Bundler_RequireResolveNotExternal} // Source maps case MsgID_SourceMap_InvalidSourceMappings: - return "invalid-source-mappings" + return msgIDInfo{name: "invalid-source-mappings", vsID: vsID_SourceMap_InvalidSourceMappings} case MsgID_SourceMap_MissingSourceMap: - return "missing-source-map" + return msgIDInfo{name: "missing-source-map", vsID: vsID_SourceMap_MissingSourceMap} case MsgID_SourceMap_UnsupportedSourceMapComment: - return "unsupported-source-map-comment" + return msgIDInfo{name: "unsupported-source-map-comment", vsID: vsID_SourceMap_UnsupportedSourceMapComment} default: if id >= MsgID_PackageJSON_FIRST && id <= MsgID_PackageJSON_LAST { - return "package.json" + return msgIDInfo{name: "package.json", vsID: vsID_PackageJSON} } if id >= MsgID_TSConfigJSON_FIRST && id <= MsgID_TSConfigJSON_LAST { - return "tsconfig.json" + return msgIDInfo{name: "tsconfig.json", vsID: vsID_TSConfigJSON} } } - return "" + return msgIDInfo{} } // Some message IDs are more diverse internally than externally (in case we diff --git a/vendor/github.com/evanw/esbuild/internal/logger/style_default.go b/vendor/github.com/evanw/esbuild/internal/logger/style_default.go new file mode 100644 index 000000000..f2560a268 --- /dev/null +++ b/vendor/github.com/evanw/esbuild/internal/logger/style_default.go @@ -0,0 +1,460 @@ +package logger + +import ( + "fmt" + "strings" + "unicode/utf8" +) + +func msgToStringDefault(msg Msg, options OutputOptions, terminalInfo TerminalInfo) string { + // Format the message + var text strings.Builder + text.WriteString(msgString(options.IncludeSource, options.PathStyle, terminalInfo, msg.ID, msg.Kind, msg.Data, msg.PluginName)) + + // Format the notes + var oldData MsgData + for i, note := range msg.Notes { + if options.IncludeSource && (i == 0 || strings.IndexByte(oldData.Text, '\n') >= 0 || oldData.Location != nil) { + text.WriteString("\n") + } + text.WriteString(msgString(options.IncludeSource, options.PathStyle, terminalInfo, MsgID_None, Note, note, "")) + oldData = note + } + + // Add extra spacing between messages if source code is present + if options.IncludeSource { + text.WriteString("\n") + } + return text.String() +} + +func marginWithLineText(maxMargin int, line int) string { + number := fmt.Sprintf("%d", line) + return fmt.Sprintf(" %s%s │ ", strings.Repeat(" ", maxMargin-len(number)), number) +} + +func emptyMarginText(maxMargin int, isLast bool) string { + space := strings.Repeat(" ", maxMargin) + if isLast { + return fmt.Sprintf(" %s ╵ ", space) + } + return fmt.Sprintf(" %s │ ", space) +} + +func msgString(includeSource bool, pathStyle PathStyle, terminalInfo TerminalInfo, id MsgID, kind MsgKind, data MsgData, pluginName string) string { + if !includeSource { + if loc := data.Location; loc != nil { + return fmt.Sprintf("%s: %s: %s\n", loc.File.Select(pathStyle), kind.String(), data.Text) + } + return fmt.Sprintf("%s: %s\n", kind.String(), data.Text) + } + + var colors Colors + if terminalInfo.UseColorEscapes { + colors = TerminalColors + } + + var iconColor string + var kindColorBrackets string + var kindColorText string + + location := "" + + if data.Location != nil { + maxMargin := len(fmt.Sprintf("%d", data.Location.Line)) + d := detailStruct(data, pathStyle, terminalInfo, maxMargin) + + if d.Suggestion != "" { + location = fmt.Sprintf("\n %s:%d:%d:\n%s%s%s%s%s%s\n%s%s%s%s%s\n%s%s%s%s%s\n%s", + d.Path, d.Line, d.Column, + colors.Dim, d.SourceBefore, colors.Green, d.SourceMarked, colors.Dim, d.SourceAfter, + emptyMarginText(maxMargin, false), d.Indent, colors.Green, d.Marker, colors.Dim, + emptyMarginText(maxMargin, true), d.Indent, colors.Green, d.Suggestion, colors.Reset, + d.ContentAfter, + ) + } else { + location = fmt.Sprintf("\n %s:%d:%d:\n%s%s%s%s%s%s\n%s%s%s%s%s\n%s", + d.Path, d.Line, d.Column, + colors.Dim, d.SourceBefore, colors.Green, d.SourceMarked, colors.Dim, d.SourceAfter, + emptyMarginText(maxMargin, true), d.Indent, colors.Green, d.Marker, colors.Reset, + d.ContentAfter, + ) + } + } + + switch kind { + case Verbose: + iconColor = colors.Cyan + kindColorBrackets = colors.CyanBgCyan + kindColorText = colors.CyanBgBlack + + case Debug: + iconColor = colors.Green + kindColorBrackets = colors.GreenBgGreen + kindColorText = colors.GreenBgWhite + + case Info: + iconColor = colors.Blue + kindColorBrackets = colors.BlueBgBlue + kindColorText = colors.BlueBgWhite + + case Error: + iconColor = colors.Red + kindColorBrackets = colors.RedBgRed + kindColorText = colors.RedBgWhite + + case Warning: + iconColor = colors.Yellow + kindColorBrackets = colors.YellowBgYellow + kindColorText = colors.YellowBgBlack + + case Note: + sb := strings.Builder{} + + for _, line := range strings.Split(data.Text, "\n") { + // Special-case word wrapping + if wrapWidth := terminalInfo.Width; wrapWidth > 2 { + if !data.DisableMaximumWidth && wrapWidth > 100 { + wrapWidth = 100 // Enforce a maximum paragraph width for readability + } + for _, run := range wrapWordsInString(line, wrapWidth-2) { + sb.WriteString(" ") + sb.WriteString(linkifyText(run, colors.Underline, colors.Reset)) + sb.WriteByte('\n') + } + continue + } + + // Otherwise, just write an indented line + sb.WriteString(" ") + sb.WriteString(linkifyText(line, colors.Underline, colors.Reset)) + sb.WriteByte('\n') + } + + sb.WriteString(location) + return sb.String() + } + + if pluginName != "" { + pluginName = fmt.Sprintf(" %s%s[plugin %s]%s", colors.Bold, colors.Magenta, pluginName, colors.Reset) + } + + msgID := MsgIDToString(id) + if msgID != "" { + msgID = fmt.Sprintf(" [%s]", msgID) + } + + return fmt.Sprintf("%s%s %s[%s%s%s]%s %s%s%s%s%s\n%s", + iconColor, kind.Icon(), + kindColorBrackets, kindColorText, kind.String(), kindColorBrackets, colors.Reset, + colors.Bold, data.Text, colors.Reset, pluginName, msgID, + location, + ) +} + +func linkifyText(text string, underline string, reset string) string { + if underline == "" { + return text + } + + https := strings.Index(text, "https://") + if https == -1 { + return text + } + + sb := strings.Builder{} + for { + https := strings.Index(text, "https://") + if https == -1 { + break + } + + end := strings.IndexByte(text[https:], ' ') + if end == -1 { + end = len(text) + } else { + end += https + } + + // Remove trailing punctuation + if end > https { + switch text[end-1] { + case '.', ',', '?', '!', ')', ']', '}': + end-- + } + } + + sb.WriteString(text[:https]) + sb.WriteString(underline) + sb.WriteString(text[https:end]) + sb.WriteString(reset) + text = text[end:] + } + + sb.WriteString(text) + return sb.String() +} + +func wrapWordsInString(text string, width int) []string { + runs := []string{} + +outer: + for text != "" { + i := 0 + x := 0 + wordEndI := 0 + + // Skip over any leading spaces + for i < len(text) && text[i] == ' ' { + i++ + x++ + } + + // Find out how many words will fit in this run + for i < len(text) { + oldWordEndI := wordEndI + wordStartI := i + + // Find the end of the word + for i < len(text) { + c, width := utf8.DecodeRuneInString(text[i:]) + if c == ' ' { + break + } + i += width + x += 1 // Naively assume that each unicode code point is a single column + } + wordEndI = i + + // Split into a new run if this isn't the first word in the run and the end is past the width + if wordStartI > 0 && x > width { + runs = append(runs, text[:oldWordEndI]) + text = text[wordStartI:] + continue outer + } + + // Skip over any spaces after the word + for i < len(text) && text[i] == ' ' { + i++ + x++ + } + } + + // If we get here, this is the last run (i.e. everything fits) + break + } + + // Remove any trailing spaces on the last run + for len(text) > 0 && text[len(text)-1] == ' ' { + text = text[:len(text)-1] + } + runs = append(runs, text) + return runs +} + +type msgDetail struct { + SourceBefore string + SourceMarked string + SourceAfter string + + Indent string + Marker string + Suggestion string + + ContentAfter string + + Path string + Line int + Column int +} + +func detailStruct(data MsgData, pathStyle PathStyle, terminalInfo TerminalInfo, maxMargin int) msgDetail { + // Only highlight the first line of the line text + loc := *data.Location + endOfFirstLine := len(loc.LineText) + + // Note: This uses "IndexByte" because Go implements this with SIMD, which + // can matter a lot for really long lines. Some people pass huge >100mb + // minified files as line text for the log message. + if i := strings.IndexByte(loc.LineText, '\n'); i >= 0 { + endOfFirstLine = i + } + + firstLine := loc.LineText[:endOfFirstLine] + afterFirstLine := loc.LineText[endOfFirstLine:] + if afterFirstLine != "" && !strings.HasSuffix(afterFirstLine, "\n") { + afterFirstLine += "\n" + } + + // Clamp values in range + if loc.Line < 0 { + loc.Line = 0 + } + if loc.Column < 0 { + loc.Column = 0 + } + if loc.Length < 0 { + loc.Length = 0 + } + if loc.Column > endOfFirstLine { + loc.Column = endOfFirstLine + } + if loc.Length > endOfFirstLine-loc.Column { + loc.Length = endOfFirstLine - loc.Column + } + + spacesPerTab := 2 + lineText := renderTabStops(firstLine, spacesPerTab) + textUpToLoc := renderTabStops(firstLine[:loc.Column], spacesPerTab) + markerStart := len(textUpToLoc) + markerEnd := markerStart + indent := strings.Repeat(" ", estimateWidthInTerminal(textUpToLoc)) + marker := "^" + + // Extend markers to cover the full range of the error + if loc.Length > 0 { + markerEnd = len(renderTabStops(firstLine[:loc.Column+loc.Length], spacesPerTab)) + } + + // Clip the marker to the bounds of the line + if markerStart > len(lineText) { + markerStart = len(lineText) + } + if markerEnd > len(lineText) { + markerEnd = len(lineText) + } + if markerEnd < markerStart { + markerEnd = markerStart + } + + // Trim the line to fit the terminal width + width := terminalInfo.Width + if width < 1 { + width = defaultTerminalWidth + } + width -= maxMargin + extraMarginChars + if width < 1 { + width = 1 + } + if loc.Column == endOfFirstLine { + // If the marker is at the very end of the line, the marker will be a "^" + // character that extends one column past the end of the line. In this case + // we should reserve a column at the end so the marker doesn't wrap. + width -= 1 + } + if len(lineText) > width { + // Try to center the error + sliceStart := (markerStart + markerEnd - width) / 2 + if sliceStart > markerStart-width/5 { + sliceStart = markerStart - width/5 + } + if sliceStart < 0 { + sliceStart = 0 + } + if sliceStart > len(lineText)-width { + sliceStart = len(lineText) - width + } + sliceEnd := sliceStart + width + + // Slice the line + slicedLine := lineText[sliceStart:sliceEnd] + markerStart -= sliceStart + markerEnd -= sliceStart + if markerStart < 0 { + markerStart = 0 + } + if markerEnd > len(slicedLine) { + markerEnd = len(slicedLine) + } + + // Truncate the ends with "..." + if len(slicedLine) > 3 && sliceStart > 0 { + slicedLine = "..." + slicedLine[3:] + if markerStart < 3 { + markerStart = 3 + } + } + if len(slicedLine) > 3 && sliceEnd < len(lineText) { + slicedLine = slicedLine[:len(slicedLine)-3] + "..." + if markerEnd > len(slicedLine)-3 { + markerEnd = len(slicedLine) - 3 + } + if markerEnd < markerStart { + markerEnd = markerStart + } + } + + // Now we can compute the indent + lineText = slicedLine + indent = strings.Repeat(" ", estimateWidthInTerminal(lineText[:markerStart])) + } + + // If marker is still multi-character after clipping, make the marker wider + if markerEnd-markerStart > 1 { + marker = strings.Repeat("~", estimateWidthInTerminal(lineText[markerStart:markerEnd])) + } + + // Put a margin before the marker indent + margin := marginWithLineText(maxMargin, loc.Line) + + return msgDetail{ + Path: loc.File.Select(pathStyle), + + // Note: We want to deliberately print the unclamped line and column, as it + // may come from another tool that either didn't set "LineText" at all or + // at least didn't calculate the column number correctly. + Line: data.Location.Line, + Column: data.Location.Column, + + SourceBefore: margin + lineText[:markerStart], + SourceMarked: lineText[markerStart:markerEnd], + SourceAfter: lineText[markerEnd:], + + Indent: indent, + Marker: marker, + Suggestion: loc.Suggestion, + + ContentAfter: afterFirstLine, + } +} + +// Estimate the number of columns this string will take when printed +func estimateWidthInTerminal(text string) int { + // For now just assume each code point is one column. This is wrong but is + // less wrong than assuming each code unit is one column. + width := 0 + for text != "" { + c, size := utf8.DecodeRuneInString(text) + text = text[size:] + + // Ignore the Zero Width No-Break Space character (UTF-8 BOM) + if c != 0xFEFF { + width++ + } + } + return width +} + +func renderTabStops(withTabs string, spacesPerTab int) string { + if !strings.ContainsRune(withTabs, '\t') { + return withTabs + } + + withoutTabs := strings.Builder{} + count := 0 + + for _, c := range withTabs { + if c == '\t' { + spaces := spacesPerTab - count%spacesPerTab + for i := 0; i < spaces; i++ { + withoutTabs.WriteRune(' ') + count++ + } + } else { + withoutTabs.WriteRune(c) + count++ + } + } + + return withoutTabs.String() +} diff --git a/vendor/github.com/evanw/esbuild/internal/logger/style_visualstudio.go b/vendor/github.com/evanw/esbuild/internal/logger/style_visualstudio.go new file mode 100644 index 000000000..cea861ec3 --- /dev/null +++ b/vendor/github.com/evanw/esbuild/internal/logger/style_visualstudio.go @@ -0,0 +1,107 @@ +package logger + +import ( + "fmt" + "strings" +) + +// This log style is intended to help integrate esbuild with Visual Studio's +// built-in problem matcher. More information: +// +// - https://learn.microsoft.com/en-us/cpp/build/formatting-the-output-of-a-custom-build-step-or-build-event +// - https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild-diagnostic-format-for-tasks +func msgToStringVisualStudio(msg Msg, options OutputOptions, terminalInfo TerminalInfo) string { + var text strings.Builder + + // Write the origin + if loc := msg.Data.Location; loc != nil { + // Potentially this needs to always be an absolute path? + text.WriteString(loc.File.Abs) + + // Note: Need to adjust the column from 0-based to 1-based + if loc.Line > 0 { + text.WriteString(fmt.Sprintf("(%d,%d)", loc.Line, loc.Column+1)) + } + text.WriteString(": ") + } else { + // If there is no file, then we must write a tool name + text.WriteString("esbuild: ") + } + + // The code appears to be required, so make something up + code := fmt.Sprintf("ES%04d", msgIDToInfo(msg.ID).vsID) + + // The only valid options for the category seem to be "error" and "warning" + if msg.Kind == Error { + text.WriteString(fmt.Sprintf("error %s: ", code)) + } else { + text.WriteString(fmt.Sprintf("warning %s: ", code)) + } + + text.WriteString(msg.Data.Text) + text.WriteByte('\n') + return text.String() +} + +type vsID = uint8 + +// These are separate from "MsgID" because they are external and "MsgID" is +// internal. Don't ever delete or reorder one of these. Only append to them. +const ( + vsID_JS_AssertToWith = 1 + vsID_JS_AssertTypeJSON = 2 + vsID_JS_AssignToConstant = 3 + vsID_JS_AssignToDefine = 4 + vsID_JS_AssignToImport = 5 + vsID_JS_BigInt = 6 + vsID_JS_CallImportNamespace = 7 + vsID_JS_ClassNameWillThrow = 8 + vsID_JS_CommonJSVariableInESM = 9 + vsID_JS_ConfusingTypeScriptCast = 10 + vsID_JS_DeleteSuperProperty = 11 + vsID_JS_DirectEval = 12 + vsID_JS_DuplicateCase = 13 + vsID_JS_DuplicateClassMember = 14 + vsID_JS_DuplicateObjectKey = 15 + vsID_JS_EmptyImportMeta = 16 + vsID_JS_EqualsNaN = 17 + vsID_JS_EqualsNegativeZero = 18 + vsID_JS_EqualsNewObject = 19 + vsID_JS_HTMLCommentInJS = 20 + vsID_JS_ImpossibleTypeof = 21 + vsID_JS_IndirectRequire = 22 + vsID_JS_PrivateNameWillThrow = 23 + vsID_JS_SemicolonAfterReturn = 24 + vsID_JS_SuspiciousBooleanNot = 25 + vsID_JS_SuspiciousDefine = 26 + vsID_JS_SuspiciousLogicalOperator = 27 + vsID_JS_SuspiciousNullishCoalescing = 28 + vsID_JS_ThisIsUndefinedInESM = 29 + vsID_JS_UnsupportedDynamicImport = 30 + vsID_JS_UnsupportedJSXComment = 31 + vsID_JS_UnsupportedRegExp = 32 + vsID_JS_UnsupportedRequireCall = 33 + vsID_CSS_CSSSyntaxError = 34 + vsID_CSS_InvalidAtCharset = 35 + vsID_CSS_InvalidAtImport = 36 + vsID_CSS_InvalidAtLayer = 37 + vsID_CSS_InvalidCalc = 38 + vsID_CSS_JSCommentInCSS = 39 + vsID_CSS_UndefinedComposesFrom = 40 + vsID_CSS_UnsupportedAtCharset = 41 + vsID_CSS_UnsupportedAtNamespace = 42 + vsID_CSS_UnsupportedCSSProperty = 43 + vsID_CSS_UnsupportedCSSNesting = 44 + vsID_Bundler_AmbiguousReexport = 45 + vsID_Bundler_DifferentPathCase = 46 + vsID_Bundler_EmptyGlob = 47 + vsID_Bundler_IgnoredBareImport = 48 + vsID_Bundler_IgnoredDynamicImport = 49 + vsID_Bundler_ImportIsUndefined = 50 + vsID_Bundler_RequireResolveNotExternal = 51 + vsID_SourceMap_InvalidSourceMappings = 52 + vsID_SourceMap_MissingSourceMap = 53 + vsID_SourceMap_UnsupportedSourceMapComment = 54 + vsID_PackageJSON = 55 + vsID_TSConfigJSON = 56 +) diff --git a/vendor/github.com/evanw/esbuild/pkg/api/api.go b/vendor/github.com/evanw/esbuild/pkg/api/api.go index 9d507c79a..b98381128 100644 --- a/vendor/github.com/evanw/esbuild/pkg/api/api.go +++ b/vendor/github.com/evanw/esbuild/pkg/api/api.go @@ -236,6 +236,13 @@ const ( LogLevelError ) +type LogStyle uint8 + +const ( + LogStyleDefault LogStyle = iota + LogStyleVisualStudio +) + type Charset uint8 const ( @@ -280,6 +287,7 @@ const ( type BuildOptions struct { Color StderrColor // Documentation: https://esbuild.github.io/api/#color LogLevel LogLevel // Documentation: https://esbuild.github.io/api/#log-level + LogStyle LogStyle // Documentation: https://esbuild.github.io/api/#log-style LogLimit int // Documentation: https://esbuild.github.io/api/#log-limit LogOverride map[string]LogLevel // Documentation: https://esbuild.github.io/api/#log-override AbsPaths AbsPaths // Documentation: https://esbuild.github.io/api/#abs-path @@ -412,6 +420,7 @@ func Build(options BuildOptions) BuildResult { type TransformOptions struct { Color StderrColor // Documentation: https://esbuild.github.io/api/#color LogLevel LogLevel // Documentation: https://esbuild.github.io/api/#log-level + LogStyle LogStyle // Documentation: https://esbuild.github.io/api/#log-style LogLimit int // Documentation: https://esbuild.github.io/api/#log-limit LogOverride map[string]LogLevel // Documentation: https://esbuild.github.io/api/#log-override AbsPaths AbsPaths // Documentation: https://esbuild.github.io/api/#abs-path @@ -717,6 +726,7 @@ type FormatMessagesOptions struct { TerminalWidth int Kind MessageKind Color bool + LogStyle LogStyle } func FormatMessages(msgs []Message, opts FormatMessagesOptions) []string { diff --git a/vendor/github.com/evanw/esbuild/pkg/api/api_impl.go b/vendor/github.com/evanw/esbuild/pkg/api/api_impl.go index c30c92156..00ce29a5d 100644 --- a/vendor/github.com/evanw/esbuild/pkg/api/api_impl.go +++ b/vendor/github.com/evanw/esbuild/pkg/api/api_impl.go @@ -205,6 +205,17 @@ func validateLogLevel(value LogLevel) logger.LogLevel { } } +func validateLogStyle(value LogStyle) logger.LogStyle { + switch value { + case LogStyleDefault: + return logger.StyleDefault + case LogStyleVisualStudio: + return logger.StyleVisualStudio + default: + panic("Invalid log style") + } +} + func validateASCIIOnly(value Charset) bool { switch value { case CharsetDefault, CharsetASCII: @@ -345,10 +356,15 @@ func validateFeatures(log logger.Log, target Target, engines []Engine) (compat.J parts = append(parts, patch) } } - constraints[convertEngineName(engine.Name)] = compat.Semver{ + name := convertEngineName(engine.Name) + new := compat.Semver{ Parts: parts, PreRelease: match[4], } + if old, ok := constraints[name]; ok && compat.CompareSemver(old, new) < 0 { + continue + } + constraints[name] = new continue } } @@ -884,6 +900,7 @@ func contextImpl(buildOpts BuildOptions) (*internalContext, []Message) { MessageLimit: buildOpts.LogLimit, Color: validateColor(buildOpts.Color), LogLevel: validateLogLevel(buildOpts.LogLevel), + LogStyle: validateLogStyle(buildOpts.LogStyle), PathStyle: extractPathStyle(buildOpts.AbsPaths, LogAbsPath), Overrides: validateLogOverrides(buildOpts.LogOverride), } @@ -1494,10 +1511,7 @@ func rebuildImpl(args rebuildArgs, oldHashes map[string]string) (rebuildState, m // Scan over the bundle bundle := bundler.ScanBundle(config.BuildCall, log, realFS, args.caches, args.entryPoints, args.options, timer) watchData = realFS.WatchData() - - // The new build summary remains the same as the old one when there are - // errors. A failed build shouldn't erase the previous successful build. - newHashes := oldHashes + newHashes := make(map[string]string) // Stop now if there were errors var results []graph.OutputFile @@ -1515,27 +1529,26 @@ func rebuildImpl(args rebuildArgs, oldHashes map[string]string) (rebuildState, m // Stop now if there were errors if !log.HasErrors() { result.Metafile = metafile - } - } - // Populate the results to return - var hashBytes [8]byte - result.OutputFiles = make([]OutputFile, len(results)) - newHashes = make(map[string]string) - for i, item := range results { - if args.options.WriteToStdout { - item.AbsPath = "" - } - hasher := xxhash.New() - hasher.Write(item.Contents) - binary.LittleEndian.PutUint64(hashBytes[:], hasher.Sum64()) - hash := base64.RawStdEncoding.EncodeToString(hashBytes[:]) - result.OutputFiles[i] = OutputFile{ - Path: item.AbsPath, - Contents: item.Contents, - Hash: hash, + // Populate the results to return + var hashBytes [8]byte + result.OutputFiles = make([]OutputFile, len(results)) + for i, item := range results { + if args.options.WriteToStdout { + item.AbsPath = "" + } + hasher := xxhash.New() + hasher.Write(item.Contents) + binary.LittleEndian.PutUint64(hashBytes[:], hasher.Sum64()) + hash := base64.RawStdEncoding.EncodeToString(hashBytes[:]) + result.OutputFiles[i] = OutputFile{ + Path: item.AbsPath, + Contents: item.Contents, + Hash: hash, + } + newHashes[item.AbsPath] = hash + } } - newHashes[item.AbsPath] = hash } // Write output files before "OnEnd" callbacks run so they can expect @@ -1563,12 +1576,19 @@ func rebuildImpl(args rebuildArgs, oldHashes map[string]string) (rebuildState, m } } + // Only write output files if there were no errors. See this issue + // for why: https://github.com/evanw/esbuild/issues/3643 + shouldWriteFiles := !log.HasErrors() + // Process all file operations in parallel waitGroup := sync.WaitGroup{} waitGroup.Add(len(results) + len(toDelete)) for _, result := range results { go func(result graph.OutputFile) { defer waitGroup.Done() + if !shouldWriteFiles { + return + } fs.BeforeFileOpen() defer fs.AfterFileClose() if oldHash, ok := oldHashes[result.AbsPath]; ok && oldHash == newHashes[result.AbsPath] { @@ -1690,6 +1710,7 @@ func transformImpl(input string, transformOpts TransformOptions) TransformResult MessageLimit: transformOpts.LogLimit, Color: validateColor(transformOpts.Color), LogLevel: validateLogLevel(transformOpts.LogLevel), + LogStyle: validateLogStyle(transformOpts.LogStyle), PathStyle: extractPathStyle(transformOpts.AbsPaths, LogAbsPath), Overrides: validateLogOverrides(transformOpts.LogOverride), }) @@ -2199,6 +2220,7 @@ func formatMsgsImpl(msgs []Message, opts FormatMessagesOptions) []string { strings[i] = msg.String( logger.OutputOptions{ IncludeSource: true, + LogStyle: validateLogStyle(opts.LogStyle), }, logger.TerminalInfo{ UseColorEscapes: opts.Color, diff --git a/vendor/github.com/evanw/esbuild/pkg/api/serve_other.go b/vendor/github.com/evanw/esbuild/pkg/api/serve_other.go index b8aefe536..3a1f66c54 100644 --- a/vendor/github.com/evanw/esbuild/pkg/api/serve_other.go +++ b/vendor/github.com/evanw/esbuild/pkg/api/serve_other.go @@ -227,18 +227,19 @@ func (h *apiHandler) ServeHTTP(res http.ResponseWriter, req *http.Request) { // Check for a file in the "servedir" directory if h.servedir != "" && kind != fs.FileEntry { absPath := h.fs.Join(h.servedir, queryPath) + if symlink, ok := h.fs.EvalSymlinks(absPath); ok { + absPath = symlink + } if absDir := h.fs.Dir(absPath); absDir != absPath { if entries, err, _ := h.fs.ReadDirectory(absDir); err == nil { if entry, _ := entries.Get(h.fs.Base(absPath)); entry != nil && entry.Kind(h.fs) == fs.FileEntry { - if h.keyfileToLower != "" || h.certfileToLower != "" { - if toLower := strings.ToLower(absPath); toLower == h.keyfileToLower || toLower == h.certfileToLower { - // Don't serve the HTTPS key or certificate. This uses a case- - // insensitive check because some file systems are case-sensitive. - go h.notifyRequest(time.Since(start), req, http.StatusForbidden) - res.WriteHeader(http.StatusForbidden) - maybeWriteResponseBody([]byte("403 - Forbidden")) - return - } + if strings.EqualFold(absPath, h.keyfileToLower) || strings.EqualFold(absPath, h.certfileToLower) { + // Don't serve the HTTPS key or certificate. This uses a case- + // insensitive check because some file systems are case-sensitive. + go h.notifyRequest(time.Since(start), req, http.StatusForbidden) + res.WriteHeader(http.StatusForbidden) + maybeWriteResponseBody([]byte("403 - Forbidden")) + return } if contents, err, _ := h.fs.OpenFile(absPath); err == nil { defer contents.Close() @@ -346,12 +347,28 @@ func (h *apiHandler) ServeHTTP(res http.ResponseWriter, req *http.Request) { return } - // If we get here, the request was successful - if contentType := helpers.MimeTypeByExtension(h.fs.Ext(file.absPath)); contentType != "" { - res.Header().Set("Content-Type", contentType) - } else { - res.Header().Set("Content-Type", "application/octet-stream") + // Try to detect the MIME type + contentType := helpers.MimeTypeByExtension(h.fs.Ext(file.absPath)) + if contentType == "" { + if begin == 0 { + contentType = http.DetectContentType(fileBytes) + } else { + // Read the file header for MIME type detection of HTTP range requests + limit := 512 + if limit > fileContentsLen { + limit = fileContentsLen + } + if headerBytes, err := file.contents.Read(0, limit); err == nil { + contentType = http.DetectContentType(headerBytes) + } + } + } + if contentType == "" { + contentType = "application/octet-stream" } + + // If we get here, the request was successful + res.Header().Set("Content-Type", contentType) if isRange { res.Header().Set("Content-Range", fmt.Sprintf("bytes %d-%d/%d", begin, end-1, fileContentsLen)) } @@ -888,6 +905,12 @@ func (ctx *internalContext) Serve(serveOptions ServeOptions) (ServeResult, error if isHTTPS { serveOptions.Keyfile, _ = ctx.realFS.Abs(serveOptions.Keyfile) serveOptions.Certfile, _ = ctx.realFS.Abs(serveOptions.Certfile) + if symlink, ok := ctx.realFS.EvalSymlinks(serveOptions.Keyfile); ok { + serveOptions.Keyfile = symlink + } + if symlink, ok := ctx.realFS.EvalSymlinks(serveOptions.Certfile); ok { + serveOptions.Certfile = symlink + } } var shouldStop int32 diff --git a/vendor/modules.txt b/vendor/modules.txt index 5d94c54aa..fbee5a0bc 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -112,7 +112,7 @@ github.com/chromedp/sysutil github.com/dlclark/regexp2/v2 github.com/dlclark/regexp2/v2/helpers github.com/dlclark/regexp2/v2/syntax -# github.com/evanw/esbuild v0.28.1 +# github.com/evanw/esbuild v0.28.2 ## explicit; go 1.13 github.com/evanw/esbuild/internal/api_helpers github.com/evanw/esbuild/internal/ast From b1c90cf357676edeb5a909a0182fd0b85dff1586 Mon Sep 17 00:00:00 2001 From: Jan Hildebrandt <32014057+janHildebrandt98@users.noreply.github.com> Date: Thu, 27 Aug 2026 15:43:40 +0200 Subject: [PATCH 125/182] Opt-in nanosecond log timestamps (--log-ns-timestamps) * Adjust json log format to use nanosecond precision for timestamps * Introduce cli flag and env var to control behavior * add test for report caller * return error when formatter is of unexpected type * revert changes to ReportCaller() * revert changes to fallback logger --- cmd/state/state.go | 22 +++++---- internal/cmd/root.go | 40 ++++++++++------ internal/cmd/tests/cmd_run_test.go | 75 ++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+), 22 deletions(-) diff --git a/cmd/state/state.go b/cmd/state/state.go index 8f9ccdf6c..101827b00 100644 --- a/cmd/state/state.go +++ b/cmd/state/state.go @@ -192,15 +192,16 @@ func NewGlobalState(ctx context.Context) *GlobalState { // GlobalFlags contains global config values that apply for all k6 sub-commands. type GlobalFlags struct { - ConfigFilePath string - Quiet bool - NoColor bool - Address string - ProfilingEnabled bool - LogOutput string - SecretSource []string - LogFormat string - Verbose bool + ConfigFilePath string + Quiet bool + NoColor bool + Address string + ProfilingEnabled bool + LogOutput string + SecretSource []string + LogFormat string + LogNanosecondTimestamps bool + Verbose bool AutoExtensionResolution bool BuildServiceURL string @@ -247,6 +248,9 @@ func getFlags(defaultFlags GlobalFlags, env map[string]string, args []string) Gl if _, ok := env["NO_COLOR"]; ok { result.NoColor = true } + if _, ok := env["K6_LOG_NS_TIMESTAMPS"]; ok { + result.LogNanosecondTimestamps = true + } if _, ok := env["K6_PROFILING_ENABLED"]; ok { result.ProfilingEnabled = true } diff --git a/internal/cmd/root.go b/internal/cmd/root.go index 1acb71587..7fe8b9571 100644 --- a/internal/cmd/root.go +++ b/internal/cmd/root.go @@ -317,6 +317,10 @@ func rootCmdPersistentFlagSet(gs *state.GlobalState) *pflag.FlagSet { flags.BoolVar(&gs.Flags.NoColor, "no-color", gs.Flags.NoColor, "disable colored output") flags.Lookup("no-color").DefValue = strconv.FormatBool(gs.DefaultFlags.NoColor) + flags.BoolVar(&gs.Flags.LogNanosecondTimestamps, "log-ns-timestamps", + gs.Flags.LogNanosecondTimestamps, "switch log timestamp precision from second to nanosecond") + flags.Lookup("log-ns-timestamps").DefValue = strconv.FormatBool(gs.DefaultFlags.LogNanosecondTimestamps) + // TODO: support configuring these through environment variables as well? // either with croconf or through the hack above... flags.BoolVarP(&gs.Flags.Verbose, "verbose", "v", gs.DefaultFlags.Verbose, "enable verbose logging") @@ -388,19 +392,7 @@ func (c *rootCommand) setupLoggers(stop <-chan struct{}) error { return fmt.Errorf("unsupported log output '%s'", line) } - switch c.globalState.Flags.LogFormat { - case "raw": - c.globalState.Logger.SetFormatter(&RawFormatter{}) - c.globalState.Logger.Debug("Logger format: RAW") - case "json": - c.globalState.Logger.SetFormatter(&logrus.JSONFormatter{}) - c.globalState.Logger.Debug("Logger format: JSON") - default: - c.globalState.Logger.SetFormatter(&logrus.TextFormatter{ - ForceColors: loggerForceColors, DisableColors: c.globalState.Flags.NoColor, - }) - c.globalState.Logger.Debug("Logger format: TEXT") - } + setupLogFormat(c, loggerForceColors) secretsources, err := createSecretSources(c.globalState) if err != nil { @@ -443,6 +435,28 @@ func (c *rootCommand) setupLoggers(stop <-chan struct{}) error { return nil } +func setupLogFormat(c *rootCommand, loggerForceColors bool) { + timestampFormat := "" + if c.globalState.Flags.LogNanosecondTimestamps { + timestampFormat = time.RFC3339Nano + } + + switch c.globalState.Flags.LogFormat { + case "raw": + c.globalState.Logger.SetFormatter(&RawFormatter{}) + c.globalState.Logger.Debug("Logger format: RAW") + case "json": + c.globalState.Logger.SetFormatter(&logrus.JSONFormatter{TimestampFormat: timestampFormat}) + c.globalState.Logger.Debug("Logger format: JSON") + default: + c.globalState.Logger.SetFormatter(&logrus.TextFormatter{ + ForceColors: loggerForceColors, DisableColors: c.globalState.Flags.NoColor, + TimestampFormat: timestampFormat, + }) + c.globalState.Logger.Debug("Logger format: TEXT") + } +} + func (c *rootCommand) setLoggerHook(ctx context.Context, h log.AsyncHook) { c.loggersWg.Go(func() { h.Listen(ctx) diff --git a/internal/cmd/tests/cmd_run_test.go b/internal/cmd/tests/cmd_run_test.go index 8fdefe069..902e7e54d 100644 --- a/internal/cmd/tests/cmd_run_test.go +++ b/internal/cmd/tests/cmd_run_test.go @@ -3533,3 +3533,78 @@ func TestPLZCloudSecretsEnvVars(t *testing.T) { assert.Contains(t, stderr, `level=info msg="***SECRET_REDACTED***" source=console`) assert.NotContains(t, stderr, "plz-secret-value") } + +func TestLogNanosecondTimestampsFlag(t *testing.T) { + t.Parallel() + + testCases := []struct { + name string + additionalArg string + assertFunc func(log string, t *testing.T) + }{ + { + name: "json format with cli switch", + additionalArg: "--log-format=json", + assertFunc: func(log string, t *testing.T) { + parsed := &struct { + Msg string + Time time.Time + }{} + + require.NoError(t, json.Unmarshal([]byte(log), parsed)) + assert.NotZero(t, parsed.Time.Nanosecond(), "Logged timestamp should have nanoseconds") + }, + }, + { + name: "default format with color disabled with cli switch", + additionalArg: "--no-color", + assertFunc: func(log string, t *testing.T) { + pairs := strings.Split(log, " ") + require.NotZero(t, len(pairs)) + + keyValue := strings.Split(pairs[0], "=") + require.Len(t, keyValue, 2) + require.Equal(t, "time", keyValue[0]) + timestamp, err := time.Parse(time.RFC3339Nano, strings.Trim(keyValue[1], "\"")) + require.NoError(t, err) + + assert.NotZero(t, timestamp.Nanosecond(), "Logged timestamp should have nanoseconds") + }, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + + mainScript := ` + export default function () { + console.log("test 1 xdgf"); + }; + ` + + ts := NewGlobalTestState(t) + ts.Flags.LogNanosecondTimestamps = true + + require.NoError(t, fsext.WriteFile(ts.FS, filepath.Join(ts.Cwd, "script.js"), []byte(mainScript), 0o644)) + + ts.CmdArgs = []string{"k6", "run", "script.js", tc.additionalArg} + + cmd.ExecuteWithGlobalState(ts.GlobalState) + logs := strings.Trim(ts.Stderr.String(), "\n") + lines := strings.Split(logs, "\n") + require.NotZero(t, len(lines)) + + found := false + for _, line := range lines { + if strings.Contains(line, "test 1 xdgf") { + tc.assertFunc(line, t) + found = true + break + } + } + + require.True(t, found, "expected log line containing marker not found") + }) + } +} From 38c7c458b6dae645bc683cfc0e457baffaa3bbaf Mon Sep 17 00:00:00 2001 From: Jan Hildebrandt <32014057+janHildebrandt98@users.noreply.github.com> Date: Fri, 28 Aug 2026 17:44:48 +0200 Subject: [PATCH 126/182] Feature/improve invalid token error (#6339) * Add test * Add hint to cloud commands when server returned 401 * adjust comment * improve hint text --- internal/cloudapi/v6/client.go | 29 +++++++++++++++++-------- internal/cloudapi/v6/v6test/server.go | 31 ++++++++++++++++++++++++++- internal/cmd/cloud_login.go | 1 - internal/cmd/tests/cmd_cloud_test.go | 31 ++++++++++++++++++++++++++- 4 files changed, 80 insertions(+), 12 deletions(-) diff --git a/internal/cloudapi/v6/client.go b/internal/cloudapi/v6/client.go index 1c94141ab..526cf165c 100644 --- a/internal/cloudapi/v6/client.go +++ b/internal/cloudapi/v6/client.go @@ -11,6 +11,7 @@ import ( k6cloud "github.com/grafana/k6-cloud-openapi-client-go/k6" "github.com/sirupsen/logrus" + "go.k6.io/k6/v2/errext" "go.k6.io/k6/v2/internal/cloudapi/clientcfg" "go.k6.io/k6/v2/internal/cloudapi/httperr" ) @@ -82,18 +83,28 @@ func CheckResponse(r *http.Response, err error) error { return err } + var respErr error var payload ResponseError if err := json.Unmarshal(data, &payload); err != nil { if classified := httperr.ClassifyStatus(r.StatusCode); classified != nil { - return classified + respErr = classified + } else { + respErr = fmt.Errorf( + "unexpected HTTP error from %s: %d %s", + r.Request.URL, + r.StatusCode, + http.StatusText(r.StatusCode), + ) } - return fmt.Errorf( - "unexpected HTTP error from %s: %d %s", - r.Request.URL, - r.StatusCode, - http.StatusText(r.StatusCode), - ) + } else { + payload.Response = r + respErr = payload } - payload.Response = r - return payload + + if r.StatusCode == http.StatusUnauthorized { + return errext.WithHint(respErr, + "Authenticate by running `k6 cloud login` "+ + "or verify the active Grafana Cloud token (K6_CLOUD_TOKEN, options.cloud.token)") + } + return respErr } diff --git a/internal/cloudapi/v6/v6test/server.go b/internal/cloudapi/v6/v6test/server.go index a661f06d6..60c056bdf 100644 --- a/internal/cloudapi/v6/v6test/server.go +++ b/internal/cloudapi/v6/v6test/server.go @@ -58,6 +58,12 @@ type Config struct { // LoadZones is the load zone list returned by the load-zones endpoint. LoadZones []cloudapi.LoadZone + + // ErrorStatus, when non-zero, makes every request fail with this HTTP + // status and the real k6 Cloud API's error body for it, instead of + // the endpoint's normal canned response. Requires the value to be present + // in the forcedErrorMessages map or will panic + ErrorStatus int } // NewServer creates a test server that serves v6 API endpoints. @@ -94,13 +100,36 @@ func NewServer(t *testing.T, cfg Config) *Server { s.handleAbortTestRun, ) - srv := httptest.NewServer(mux) + var handler http.Handler = mux + if cfg.ErrorStatus != 0 { + handler = forcedErrorHandler(cfg.ErrorStatus) + } + + srv := httptest.NewServer(handler) s.Server = srv t.Cleanup(srv.Close) return s } +// forcedErrorHandler short-circuits every request with the given status and +// its real error body, regardless of route. +func forcedErrorHandler(status int) http.Handler { + forcedErrorMessages := map[int]string{ + http.StatusUnauthorized: "Invalid token", + } + + msg, ok := forcedErrorMessages[status] + if !ok { + panic(fmt.Sprintf("v6test: no error body registered for status %d", status)) + } + + return http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + res := k6cloud.NewErrorResponseApiModel(*k6cloud.NewErrorApiModel(msg, "error")) + writeJSON(w, status, res) + }) +} + func (s *Server) handleListProjects(w http.ResponseWriter, _ *http.Request) { projects := make([]k6cloud.ProjectApiModel, len(s.cfg.Projects)) now := time.Unix(0, 0).UTC() diff --git a/internal/cmd/cloud_login.go b/internal/cmd/cloud_login.go index cd08286e1..568b833a3 100644 --- a/internal/cmd/cloud_login.go +++ b/internal/cmd/cloud_login.go @@ -271,7 +271,6 @@ func authenticateUserToken( "Authentication failed as provided token or stack might not be valid."+ " Learn more: https://grafana.com/docs/grafana-cloud/testing/k6/author-run/tokens-and-cli-authentication."+ " Server error for details: %w", - err) } config.StackURL = null.StringFrom(stackURL) diff --git a/internal/cmd/tests/cmd_cloud_test.go b/internal/cmd/tests/cmd_cloud_test.go index c691e0717..f7f906d78 100644 --- a/internal/cmd/tests/cmd_cloud_test.go +++ b/internal/cmd/tests/cmd_cloud_test.go @@ -45,6 +45,20 @@ func runCloudTests(t *testing.T, setupCmd setupCommandFunc) { assert.Contains(t, stdout, `access token not configured`) }) + t.Run("TestCloudInvalidToken", func(t *testing.T) { + t.Parallel() + + ts := getSimpleCloudTestStateWithError(t, nil, setupCmd, nil, nil, http.StatusUnauthorized) + ts.ExpectedExitCode = -1 + cmd.ExecuteWithGlobalState(ts.GlobalState) + + stdout := ts.Stdout.String() + t.Log(stdout) + assert.Contains(t, stdout, `Invalid token`, "the real API error message should still be shown") + assert.Contains(t, stdout, "hint=\"Authenticate by running `k6 cloud login` or verify the active Grafana Cloud token (K6_CLOUD_TOKEN, options.cloud.token)\"", + "a 401 should come with a recovery hint pointing at `k6 cloud login`") + }) + t.Run("TestCloudStackNotConfigured", func(t *testing.T) { t.Parallel() @@ -232,7 +246,21 @@ func cloudTestStartSimple(tb testing.TB, testRunID int) http.Handler { }) } -func getSimpleCloudTestState(t *testing.T, script []byte, setupCmd setupCommandFunc, cliFlags []string, progressCallback func() *cloudapiv6.TestProgress) *GlobalTestState { +func getSimpleCloudTestState( + t *testing.T, script []byte, setupCmd setupCommandFunc, cliFlags []string, + progressCallback func() *cloudapiv6.TestProgress, +) *GlobalTestState { + return getSimpleCloudTestStateWithError(t, script, setupCmd, cliFlags, progressCallback, 0) +} + +// getSimpleCloudTestStateWithError is getSimpleCloudTestState plus the +// ability to make the mock v6 API fail every request with errorStatus (e.g. +// http.StatusUnauthorized), for testing how the CLI surfaces a failing +// cloud API call to the user. +func getSimpleCloudTestStateWithError( + t *testing.T, script []byte, setupCmd setupCommandFunc, cliFlags []string, + progressCallback func() *cloudapiv6.TestProgress, errorStatus int, +) *GlobalTestState { if script == nil { script = []byte("export let options = { cloud: { projectID: 1 } };\nexport default function() {}") } @@ -243,6 +271,7 @@ func getSimpleCloudTestState(t *testing.T, script []byte, setupCmd setupCommandF srv := v6test.NewServer(t, v6test.Config{ ProgressCallback: progressCallback, + ErrorStatus: errorStatus, }) ts := NewGlobalTestState(t) From 87a096e58bfd0af585315ab6b0b0433b2b2a2233 Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Fri, 28 Aug 2026 21:02:08 +0000 Subject: [PATCH 127/182] fix(deps): update otel to v1.46.0 (#6267) | datasource | package | from | to | | ---------- | ----------------------------------------------------------------- | ------- | ------- | | go | go.opentelemetry.io/otel | v1.44.0 | v1.46.0 | | go | go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc | v1.44.0 | v1.46.0 | | go | go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp | v1.44.0 | v1.46.0 | | go | go.opentelemetry.io/otel/exporters/otlp/otlptrace | v1.44.0 | v1.46.0 | | go | go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc | v1.44.0 | v1.46.0 | | go | go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp | v1.44.0 | v1.46.0 | | go | go.opentelemetry.io/otel/metric | v1.44.0 | v1.46.0 | | go | go.opentelemetry.io/otel/sdk | v1.44.0 | v1.46.0 | | go | go.opentelemetry.io/otel/sdk/metric | v1.44.0 | v1.46.0 | | go | go.opentelemetry.io/otel/trace | v1.44.0 | v1.46.0 | Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> --- go.mod | 28 +- go.sum | 63 +- .../github.com/go-logr/logr/context_noslog.go | 1 - .../github.com/go-logr/logr/context_slog.go | 1 - vendor/github.com/go-logr/logr/funcr/funcr.go | 47 +- .../github.com/go-logr/logr/funcr/slogsink.go | 22 +- vendor/github.com/go-logr/logr/sloghandler.go | 1 - vendor/github.com/go-logr/logr/slogr.go | 1 - vendor/github.com/go-logr/logr/slogsink.go | 1 - vendor/go.opentelemetry.io/otel/.lycheeignore | 14 + vendor/go.opentelemetry.io/otel/AGENTS.md | 3 + vendor/go.opentelemetry.io/otel/CHANGELOG.md | 108 +- vendor/go.opentelemetry.io/otel/VERSIONING.md | 6 + .../go.opentelemetry.io/otel/attribute/doc.go | 2 +- .../otel/attribute/encoder.go | 2 +- .../otel/attribute/filter.go | 2 +- .../otel/attribute/hash.go | 218 +- .../otel/attribute/internal/attribute.go | 2 +- .../otel/attribute/internal/xxhash/xxhash.go | 7 +- .../otel/attribute/iterator.go | 2 +- .../go.opentelemetry.io/otel/attribute/key.go | 134 +- .../go.opentelemetry.io/otel/attribute/kv.go | 80 +- .../otel/attribute/rawhelpers.go | 2 +- .../go.opentelemetry.io/otel/attribute/set.go | 5 +- .../otel/attribute/type_string.go | 5 +- .../otel/attribute/value.go | 312 ++- .../otel/baggage/baggage.go | 2 +- .../otel/baggage/context.go | 2 +- .../go.opentelemetry.io/otel/baggage/doc.go | 2 +- .../go.opentelemetry.io/otel/codes/codes.go | 4 +- vendor/go.opentelemetry.io/otel/codes/doc.go | 2 +- .../otel/dependencies.Dockerfile | 2 +- vendor/go.opentelemetry.io/otel/doc.go | 2 +- .../go.opentelemetry.io/otel/error_handler.go | 2 +- .../otlp/otlpmetric/otlpmetricgrpc/client.go | 2 +- .../otlp/otlpmetric/otlpmetricgrpc/config.go | 2 +- .../otlp/otlpmetric/otlpmetricgrpc/doc.go | 2 +- .../otlpmetric/otlpmetricgrpc/exporter.go | 2 +- .../internal/counter/counter.go | 8 +- .../internal/envconfig/envconfig.go | 10 +- .../otlpmetric/otlpmetricgrpc/internal/gen.go | 6 +- .../internal/observ/instrumentation.go | 6 +- .../otlpmetricgrpc/internal/observ/target.go | 31 +- .../internal/oconf/envconfig.go | 62 +- .../otlpmetricgrpc/internal/oconf/options.go | 19 +- .../internal/oconf/optiontypes.go | 8 +- .../otlpmetricgrpc/internal/oconf/tls.go | 8 +- .../otlpmetricgrpc/internal/partialsuccess.go | 10 +- .../otlpmetricgrpc/internal/retry/retry.go | 58 +- .../internal/transform/attribute.go | 17 +- .../internal/transform/error.go | 8 +- .../internal/transform/metricdata.go | 11 +- .../otlpmetricgrpc/internal/x/observ.go | 2 +- .../otlpmetric/otlpmetricgrpc/internal/x/x.go | 12 +- .../otlp/otlpmetric/otlpmetricgrpc/version.go | 4 +- .../otlp/otlpmetric/otlpmetrichttp/client.go | 26 +- .../otlp/otlpmetric/otlpmetrichttp/config.go | 7 +- .../otlp/otlpmetric/otlpmetrichttp/doc.go | 2 +- .../otlpmetric/otlpmetrichttp/exporter.go | 2 +- .../internal/counter/counter.go | 8 +- .../internal/envconfig/envconfig.go | 10 +- .../otlpmetric/otlpmetrichttp/internal/gen.go | 4 +- .../otlpmetrichttp/internal/observ/count.go | 2 +- .../internal/observ/instrumentation.go | 6 +- .../internal/oconf/envconfig.go | 62 +- .../otlpmetrichttp/internal/oconf/options.go | 19 +- .../internal/oconf/optiontypes.go | 8 +- .../otlpmetrichttp/internal/oconf/tls.go | 8 +- .../otlpmetrichttp/internal/partialsuccess.go | 10 +- .../otlpmetrichttp/internal/retry/retry.go | 58 +- .../internal/transform/attribute.go | 17 +- .../internal/transform/error.go | 8 +- .../internal/transform/metricdata.go | 11 +- .../otlpmetrichttp/internal/version.go | 4 +- .../otlpmetrichttp/internal/x/observ.go | 2 +- .../otlpmetric/otlpmetrichttp/internal/x/x.go | 12 +- .../otlp/otlpmetric/otlpmetrichttp/version.go | 2 +- .../otel/exporters/otlp/otlptrace/clients.go | 2 +- .../otel/exporters/otlp/otlptrace/doc.go | 2 +- .../otel/exporters/otlp/otlptrace/exporter.go | 6 +- .../internal/tracetransform/attribute.go | 8 +- .../tracetransform/instrumentation.go | 2 +- .../internal/tracetransform/resource.go | 2 +- .../otlptrace/internal/tracetransform/span.go | 26 +- .../otlp/otlptrace/otlptracegrpc/client.go | 10 +- .../otlp/otlptrace/otlptracegrpc/doc.go | 2 +- .../otlp/otlptrace/otlptracegrpc/exporter.go | 2 +- .../otlptracegrpc/internal/counter/counter.go | 8 +- .../internal/envconfig/envconfig.go | 10 +- .../otlptrace/otlptracegrpc/internal/gen.go | 6 +- .../otlptracegrpc/internal/observ/doc.go | 2 +- .../internal/observ/instrumentation.go | 6 +- .../otlptracegrpc/internal/observ/target.go | 31 +- .../internal/otlpconfig/envconfig.go | 83 +- .../internal/otlpconfig/options.go | 44 +- .../internal/otlpconfig/optiontypes.go | 20 +- .../otlptracegrpc/internal/otlpconfig/tls.go | 8 +- .../otlptracegrpc/internal/partialsuccess.go | 10 +- .../otlptracegrpc/internal/retry/retry.go | 58 +- .../otlptracegrpc/internal/version.go | 4 +- .../otlptracegrpc/internal/x/observ.go | 2 +- .../otlptrace/otlptracegrpc/internal/x/x.go | 12 +- .../otlp/otlptrace/otlptracegrpc/options.go | 2 +- .../otlp/otlptrace/otlptracehttp/client.go | 110 +- .../otlp/otlptrace/otlptracehttp/doc.go | 10 +- .../otlp/otlptrace/otlptracehttp/exporter.go | 2 +- .../otlptracehttp/internal/counter/counter.go | 8 +- .../internal/envconfig/envconfig.go | 10 +- .../otlptrace/otlptracehttp/internal/gen.go | 4 +- .../internal/observ/instrumentation.go | 6 +- .../internal/otlpconfig/envconfig.go | 83 +- .../internal/otlpconfig/options.go | 44 +- .../internal/otlpconfig/optiontypes.go | 20 +- .../otlptracehttp/internal/otlpconfig/tls.go | 8 +- .../otlpjson/export_trace_service_request.go | 642 +++++ .../otlpjson/export_trace_service_response.go | 22 + .../otlptracehttp/internal/partialsuccess.go | 10 +- .../otlptracehttp/internal/retry/retry.go | 58 +- .../otlptracehttp/internal/version.go | 4 +- .../otlptracehttp/internal/x/observ.go | 2 +- .../otlptrace/otlptracehttp/internal/x/x.go | 12 +- .../otlp/otlptrace/otlptracehttp/options.go | 26 +- .../otel/exporters/otlp/otlptrace/version.go | 4 +- vendor/go.opentelemetry.io/otel/handler.go | 2 +- .../otel/internal/baggage/baggage.go | 2 +- .../otel/internal/baggage/context.go | 2 +- .../internal/errorhandler/errorhandler.go | 2 +- .../otel/internal/global/handler.go | 2 +- .../otel/internal/global/instruments.go | 2 +- .../otel/internal/global/internal_logging.go | 2 +- .../otel/internal/global/meter.go | 2 +- .../otel/internal/global/propagator.go | 2 +- .../otel/internal/global/state.go | 2 +- .../otel/internal/global/trace.go | 2 +- .../otel/internal_logging.go | 2 +- vendor/go.opentelemetry.io/otel/metric.go | 2 +- .../otel/metric/asyncfloat64.go | 2 +- .../otel/metric/asyncint64.go | 2 +- .../go.opentelemetry.io/otel/metric/config.go | 2 +- vendor/go.opentelemetry.io/otel/metric/doc.go | 2 +- .../otel/metric/embedded/embedded.go | 2 +- .../otel/metric/instrument.go | 2 +- .../go.opentelemetry.io/otel/metric/meter.go | 2 +- .../otel/metric/noop/noop.go | 2 +- .../otel/metric/syncfloat64.go | 4 +- .../otel/metric/syncint64.go | 4 +- .../go.opentelemetry.io/otel/propagation.go | 2 +- .../otel/propagation/baggage.go | 2 +- .../otel/propagation/doc.go | 2 +- .../otel/propagation/propagation.go | 2 +- .../otel/propagation/trace_context.go | 2 +- .../otel/sdk/instrumentation/doc.go | 2 +- .../otel/sdk/instrumentation/library.go | 2 +- .../otel/sdk/instrumentation/scope.go | 2 +- .../otel/sdk/internal/attrnorm/dedup.go | 300 +++ .../otel/sdk/internal/attrnorm/truncate.go | 230 ++ .../otel/sdk/internal/x/features.go | 2 +- .../otel/sdk/internal/x/x.go | 12 +- .../otel/sdk/metric/aggregation.go | 2 +- .../otel/sdk/metric/cache.go | 2 +- .../otel/sdk/metric/config.go | 4 +- .../otel/sdk/metric/doc.go | 2 +- .../otel/sdk/metric/env.go | 2 +- .../otel/sdk/metric/exemplar.go | 2 +- .../otel/sdk/metric/exemplar/doc.go | 2 +- .../otel/sdk/metric/exemplar/exemplar.go | 2 +- .../otel/sdk/metric/exemplar/filter.go | 2 +- .../metric/exemplar/fixed_size_reservoir.go | 170 +- .../metric/exemplar/histogram_reservoir.go | 58 +- .../otel/sdk/metric/exemplar/next_tracker.go | 154 ++ .../otel/sdk/metric/exemplar/reservoir.go | 2 +- .../otel/sdk/metric/exemplar/storage.go | 57 +- .../otel/sdk/metric/exemplar/value.go | 2 +- .../otel/sdk/metric/exporter.go | 2 +- .../otel/sdk/metric/instrument.go | 55 +- .../metric/internal/aggregate/aggregate.go | 9 +- .../sdk/metric/internal/aggregate/atomic.go | 33 +- .../otel/sdk/metric/internal/aggregate/doc.go | 2 +- .../sdk/metric/internal/aggregate/drop.go | 4 +- .../sdk/metric/internal/aggregate/exemplar.go | 2 +- .../aggregate/exponential_histogram.go | 47 +- .../internal/aggregate/filtered_reservoir.go | 11 +- .../metric/internal/aggregate/histogram.go | 102 +- .../metric/internal/aggregate/lastvalue.go | 24 +- .../internal/aggregate/lazy_attributes.go | 146 ++ .../sdk/metric/internal/aggregate/limit.go | 2 +- .../otel/sdk/metric/internal/aggregate/sum.go | 23 +- .../sdk/metric/internal/attrnorm/dedup.go | 300 +++ .../otel/sdk/metric/internal/gen.go | 10 + .../metric/internal/observ/instrumentation.go | 6 +- .../internal/reservoir/concurrent_safe.go | 2 +- .../otel/sdk/metric/internal/reservoir/doc.go | 2 +- .../otel/sdk/metric/internal/reuse_slice.go | 2 +- .../otel/sdk/metric/internal/x/features.go | 22 + .../otel/sdk/metric/internal/x/x.go | 56 +- .../otel/sdk/metric/manual_reader.go | 2 +- .../otel/sdk/metric/meter.go | 16 +- .../otel/sdk/metric/metricdata/data.go | 2 +- .../otel/sdk/metric/metricdata/temporality.go | 2 +- .../otel/sdk/metric/periodic_reader.go | 4 +- .../otel/sdk/metric/pipeline.go | 2 +- .../otel/sdk/metric/provider.go | 6 +- .../otel/sdk/metric/reader.go | 2 +- .../otel/sdk/metric/splitmetrics.go | 2 +- .../otel/sdk/metric/version.go | 4 +- .../otel/sdk/metric/view.go | 2 +- .../otel/sdk/resource/auto.go | 2 +- .../otel/sdk/resource/builtin.go | 4 +- .../otel/sdk/resource/config.go | 6 +- .../otel/sdk/resource/container.go | 4 +- .../otel/sdk/resource/doc.go | 2 +- .../otel/sdk/resource/env.go | 4 +- .../otel/sdk/resource/host_id.go | 4 +- .../otel/sdk/resource/host_id_bsd.go | 2 +- .../otel/sdk/resource/host_id_darwin.go | 2 +- .../otel/sdk/resource/host_id_exec.go | 2 +- .../otel/sdk/resource/host_id_linux.go | 2 +- .../otel/sdk/resource/host_id_readfile.go | 2 +- .../otel/sdk/resource/host_id_unsupported.go | 2 +- .../otel/sdk/resource/host_id_windows.go | 2 +- .../otel/sdk/resource/os.go | 4 +- .../otel/sdk/resource/os_release_darwin.go | 2 +- .../otel/sdk/resource/os_release_unix.go | 2 +- .../otel/sdk/resource/os_unix.go | 2 +- .../otel/sdk/resource/os_unsupported.go | 2 +- .../otel/sdk/resource/os_windows.go | 2 +- .../otel/sdk/resource/process.go | 4 +- .../otel/sdk/resource/resource.go | 26 +- .../otel/sdk/trace/batch_span_processor.go | 7 +- .../go.opentelemetry.io/otel/sdk/trace/doc.go | 2 +- .../otel/sdk/trace/event.go | 2 +- .../otel/sdk/trace/evictedqueue.go | 2 +- .../otel/sdk/trace/id_generator.go | 2 +- .../otel/sdk/trace/internal/env/env.go | 2 +- .../internal/observ/batch_span_processor.go | 6 +- .../otel/sdk/trace/internal/observ/doc.go | 2 +- .../internal/observ/simple_span_processor.go | 46 +- .../otel/sdk/trace/internal/observ/tracer.go | 4 +- .../otel/sdk/trace/link.go | 2 +- .../otel/sdk/trace/provider.go | 61 +- .../otel/sdk/trace/sampler_env.go | 2 +- .../otel/sdk/trace/sampling.go | 2 +- .../otel/sdk/trace/simple_span_processor.go | 34 +- .../otel/sdk/trace/snapshot.go | 2 +- .../otel/sdk/trace/span.go | 281 +- .../otel/sdk/trace/span_exporter.go | 2 +- .../otel/sdk/trace/span_limits.go | 10 +- .../otel/sdk/trace/span_processor.go | 2 +- .../otel/sdk/trace/tracer.go | 2 +- .../go.opentelemetry.io/otel/sdk/version.go | 4 +- .../otel/semconv/internal/metricpool/pool.go | 48 + .../otel/semconv/v1.20.0/attribute_group.go | 2 +- .../otel/semconv/v1.20.0/doc.go | 2 +- .../otel/semconv/v1.20.0/event.go | 2 +- .../otel/semconv/v1.20.0/exception.go | 2 +- .../otel/semconv/v1.20.0/http.go | 2 +- .../otel/semconv/v1.20.0/resource.go | 2 +- .../otel/semconv/v1.20.0/schema.go | 2 +- .../otel/semconv/v1.20.0/trace.go | 2 +- .../otel/semconv/v1.24.0/attribute_group.go | 2 +- .../otel/semconv/v1.24.0/doc.go | 2 +- .../otel/semconv/v1.24.0/event.go | 2 +- .../otel/semconv/v1.24.0/exception.go | 2 +- .../otel/semconv/v1.24.0/metric.go | 2 +- .../otel/semconv/v1.24.0/resource.go | 2 +- .../otel/semconv/v1.24.0/schema.go | 2 +- .../otel/semconv/v1.24.0/trace.go | 2 +- .../otel/semconv/v1.37.0/attribute_group.go | 2 +- .../otel/semconv/v1.37.0/doc.go | 2 +- .../otel/semconv/v1.37.0/error_type.go | 2 +- .../otel/semconv/v1.37.0/exception.go | 2 +- .../otel/semconv/v1.37.0/schema.go | 2 +- .../otel/semconv/v1.41.0/MIGRATION.md | 17 - .../otel/semconv/v1.43.0/MIGRATION.md | 4 + .../{v1.41.0 => v1.43.0}/attribute_group.go | 2249 ++++------------- .../otel/semconv/{v1.41.0 => v1.43.0}/doc.go | 4 +- .../{v1.41.0 => v1.43.0}/error_type.go | 2 +- .../semconv/{v1.41.0 => v1.43.0}/exception.go | 2 +- .../{v1.41.0 => v1.43.0}/otelconv/metric.go | 327 ++- .../semconv/{v1.41.0 => v1.43.0}/schema.go | 4 +- vendor/go.opentelemetry.io/otel/trace.go | 2 +- vendor/go.opentelemetry.io/otel/trace/auto.go | 14 +- .../go.opentelemetry.io/otel/trace/config.go | 2 +- .../go.opentelemetry.io/otel/trace/context.go | 2 +- vendor/go.opentelemetry.io/otel/trace/doc.go | 2 +- .../otel/trace/embedded/embedded.go | 2 +- vendor/go.opentelemetry.io/otel/trace/hex.go | 2 +- .../otel/trace/internal/telemetry/attr.go | 2 +- .../otel/trace/internal/telemetry/doc.go | 2 +- .../otel/trace/internal/telemetry/id.go | 2 +- .../otel/trace/internal/telemetry/number.go | 2 +- .../otel/trace/internal/telemetry/resource.go | 2 +- .../otel/trace/internal/telemetry/scope.go | 2 +- .../otel/trace/internal/telemetry/span.go | 2 +- .../otel/trace/internal/telemetry/status.go | 2 +- .../otel/trace/internal/telemetry/traces.go | 2 +- .../otel/trace/internal/telemetry/value.go | 2 +- .../otel/trace/nonrecording.go | 2 +- vendor/go.opentelemetry.io/otel/trace/noop.go | 2 +- .../otel/trace/noop/noop.go | 2 +- .../otel/trace/provider.go | 2 +- vendor/go.opentelemetry.io/otel/trace/span.go | 2 +- .../go.opentelemetry.io/otel/trace/trace.go | 2 +- .../go.opentelemetry.io/otel/trace/tracer.go | 2 +- .../otel/trace/tracestate.go | 2 +- vendor/go.opentelemetry.io/otel/version.go | 4 +- vendor/modules.txt | 36 +- 307 files changed, 4919 insertions(+), 3540 deletions(-) create mode 100644 vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/otlpjson/export_trace_service_request.go create mode 100644 vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/otlpjson/export_trace_service_response.go create mode 100644 vendor/go.opentelemetry.io/otel/sdk/internal/attrnorm/dedup.go create mode 100644 vendor/go.opentelemetry.io/otel/sdk/internal/attrnorm/truncate.go create mode 100644 vendor/go.opentelemetry.io/otel/sdk/metric/exemplar/next_tracker.go create mode 100644 vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/lazy_attributes.go create mode 100644 vendor/go.opentelemetry.io/otel/sdk/metric/internal/attrnorm/dedup.go create mode 100644 vendor/go.opentelemetry.io/otel/sdk/metric/internal/gen.go create mode 100644 vendor/go.opentelemetry.io/otel/sdk/metric/internal/x/features.go create mode 100644 vendor/go.opentelemetry.io/otel/semconv/internal/metricpool/pool.go delete mode 100644 vendor/go.opentelemetry.io/otel/semconv/v1.41.0/MIGRATION.md create mode 100644 vendor/go.opentelemetry.io/otel/semconv/v1.43.0/MIGRATION.md rename vendor/go.opentelemetry.io/otel/semconv/{v1.41.0 => v1.43.0}/attribute_group.go (90%) rename vendor/go.opentelemetry.io/otel/semconv/{v1.41.0 => v1.43.0}/doc.go (83%) rename vendor/go.opentelemetry.io/otel/semconv/{v1.41.0 => v1.43.0}/error_type.go (96%) rename vendor/go.opentelemetry.io/otel/semconv/{v1.41.0 => v1.43.0}/exception.go (80%) rename vendor/go.opentelemetry.io/otel/semconv/{v1.41.0 => v1.43.0}/otelconv/metric.go (93%) rename vendor/go.opentelemetry.io/otel/semconv/{v1.41.0 => v1.43.0}/schema.go (75%) diff --git a/go.mod b/go.mod index f2ec9d5c5..8992ddfbb 100644 --- a/go.mod +++ b/go.mod @@ -45,16 +45,16 @@ require ( github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.12.1 github.com/tidwall/gjson v1.19.0 - go.opentelemetry.io/otel v1.44.0 - go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.44.0 - go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.44.0 - go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.44.0 - go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.44.0 - go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.44.0 - go.opentelemetry.io/otel/metric v1.44.0 - go.opentelemetry.io/otel/sdk v1.44.0 - go.opentelemetry.io/otel/sdk/metric v1.44.0 - go.opentelemetry.io/otel/trace v1.44.0 + go.opentelemetry.io/otel v1.46.0 + go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.46.0 + go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.46.0 + go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.46.0 + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.46.0 + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.46.0 + go.opentelemetry.io/otel/metric v1.46.0 + go.opentelemetry.io/otel/sdk v1.46.0 + go.opentelemetry.io/otel/sdk/metric v1.46.0 + go.opentelemetry.io/otel/trace v1.46.0 go.opentelemetry.io/proto/otlp v1.11.0 go.uber.org/goleak v1.3.0 golang.org/x/crypto v0.55.0 @@ -77,10 +77,10 @@ require ( github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/chromedp/sysutil v1.1.0 // indirect github.com/dlclark/regexp2/v2 v2.5.2 // indirect - github.com/go-logr/logr v1.4.3 // indirect + github.com/go-logr/logr v1.4.4 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/google/pprof v0.0.0-20260115054156-294ebfa9ad83 // indirect - github.com/grpc-ecosystem/grpc-gateway/v2 v2.29.0 // indirect + github.com/grpc-ecosystem/grpc-gateway/v2 v2.30.0 // indirect github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/jhump/protoreflect/v2 v2.0.0-beta.1 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect @@ -96,8 +96,8 @@ require ( go.yaml.in/yaml/v3 v3.0.5 // indirect golang.org/x/sys v0.47.0 // indirect golang.org/x/text v0.41.0 // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20260720211330-0afa2a65878a // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20260720211330-0afa2a65878a // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20260819154853-08b0e4226688 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20260819154853-08b0e4226688 // indirect gopkg.in/cenkalti/backoff.v1 v1.1.0 // indirect gopkg.in/validator.v2 v2.0.1 // indirect ) diff --git a/go.sum b/go.sum index 398e777ce..c69545ff0 100644 --- a/go.sum +++ b/go.sum @@ -54,8 +54,8 @@ github.com/go-json-experiment/json v0.0.0-20250211171154-1ae217ad3535/go.mod h1: github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY= github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI= -github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/logr v1.4.4 h1:tG4xh9yMsRCAiodLVTxyrkzSZ9+o0L1Kg/+cPVcbP/8= +github.com/go-logr/logr v1.4.4/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-sourcemap/sourcemap v2.1.4+incompatible h1:a+iTbH5auLKxaNwQFg0B+TCYl6lbukKPc7b5x0n1s6Q= @@ -103,8 +103,8 @@ github.com/grafana/xk6-dashboard-assets v0.1.2 h1:n2wqytPICn2ZYsKa9HE6GlvFXk+WjB github.com/grafana/xk6-dashboard-assets v0.1.2/go.mod h1:SeoRjvmFF8UhLIFDfvjqqwBtE8MtaIPYIDWqVJZEHDo= github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 h1:UH//fgunKIs4JdUbpDl1VZCDaL56wXCB/5+wF6uHfaI= github.com/grpc-ecosystem/go-grpc-middleware v1.4.0/go.mod h1:g5qyo/la0ALbONm6Vbp88Yd8NsDy6rZz+RcrMPxvld8= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.29.0 h1:5VipnvEpbqr2gA2VbM+nYVbkIF28c5ZQfqCBQ5g2xfk= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.29.0/go.mod h1:Hyl3n6Twe1hvtd9XUXDec4pTvgMSEixRuQKPTMH2bNs= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.30.0 h1:/Tnpcb2E0Pz/tN9s3bfEY2Q8ePCEX9iuS+cneUwncnw= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.30.0/go.mod h1:zOBXOsUaBSjKgmH4OGzV1esUpR3oUSCPYVd2cUBjKYY= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= @@ -123,9 +123,8 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= -github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/mattn/go-colorable v0.1.15 h1:+u9SLTRGnXv73cEsnsmoZBom+dMU88B2M0aDcWy0/jY= @@ -208,28 +207,28 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64= go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y= -go.opentelemetry.io/otel v1.44.0 h1:JjwHmHpA4iZ3wBxluu2fbbE7j4kqlE8jXyAyPXH7HqU= -go.opentelemetry.io/otel v1.44.0/go.mod h1:BMgjTHL9WPRlRjL2oZCBTL4whCGtXch2H4BhOPIAyYc= -go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.44.0 h1:SUplec5dp06reu1zaXmOXdvqH398taqrDXqUl99jxSc= -go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.44.0/go.mod h1:ho2g4N+ane+swq5I/VBkKWnRDY4kUINH3FuqyZqX/Ug= -go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.44.0 h1:RuynHbfU8JUEw7DyONgkVYg2SVtsoF28y0LGIr69jgA= -go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.44.0/go.mod h1:qZF+/lBs71APw8mlnEZcqZHMzqrYrsFiJOv83lX1OGo= -go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.44.0 h1:4YsVu3B8+3qtWYYrsUYgn0OG78pN0rnNPRGX4SbokQI= -go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.44.0/go.mod h1:+wnlSn0mD1ADVMe3v9Z/WIaiz6q6gL2J/ejaAmdmv80= -go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.44.0 h1:qazEJlUOQzhCpzQpFETGby7EdqjI1wsd0W+6Gg1SCTU= -go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.44.0/go.mod h1:fOD2Yefuxixkx3ahVNf0O/PERb6r4OlbxfATVnYvzCo= -go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.44.0 h1:lgh3PiVrRUWMLOVSkQicxzZll5NjF1r+AtsX1XRIHw0= -go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.44.0/go.mod h1:5Cnhth3m/AgOeTgE3ex12pPmiu/gGtZit03kSzx9X7s= -go.opentelemetry.io/otel/metric v1.44.0 h1:1w0gILTcHdr3YI+ixLyjemwrVnsMURbTZFrSYCdDdmc= -go.opentelemetry.io/otel/metric v1.44.0/go.mod h1:8O7hanEPBNgEMmybD3s2VBKcgWOCsA6tzHBPODAiquo= -go.opentelemetry.io/otel/metric/x v0.66.0 h1:YkCrx1zLOChi9ZcZ6euupOcsgzbVlec7D/xoEU1+cTA= -go.opentelemetry.io/otel/metric/x v0.66.0/go.mod h1:d1+BDj9t96do0/1LoU1ayfCv79ZgNE41qbhBvnMOBZk= -go.opentelemetry.io/otel/sdk v1.44.0 h1:nHYwb9lK+fJPU/dnT6s7W7Z8itMWyqrnVfbheVYrZ58= -go.opentelemetry.io/otel/sdk v1.44.0/go.mod h1:Osuydd3Se74nqjAKxid74N5eC+jfEqfTegHRnq58oK0= -go.opentelemetry.io/otel/sdk/metric v1.44.0 h1:3LlKgI+VjbVsjNRFZJZAJ30WjXC5VkNRks6si09iEfI= -go.opentelemetry.io/otel/sdk/metric v1.44.0/go.mod h1:5B5pMARnXxKhltooO4xUuCBorl65a4EpnTalObqOigA= -go.opentelemetry.io/otel/trace v1.44.0 h1:jxF5CsGYCe74MCRx2X4g7WsY/VBKRqqpNvXlX/6gtIk= -go.opentelemetry.io/otel/trace v1.44.0/go.mod h1:oLl1jrMQAVo6v3GAggN+1VH9VIz9iUSvW53sW1Q8PIE= +go.opentelemetry.io/otel v1.46.0 h1:FHt5/CDyVxi/8IM1CH7VE/rRgq3kLHa2mSTVMO8AWyc= +go.opentelemetry.io/otel v1.46.0/go.mod h1:Gj3SEScelsNC45tp4nSxRYlS+f5iez7W8XPMCt905kE= +go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.46.0 h1:qkDYCAFiZXLcs1L4aY+tP2wguQ4kURANqHOQMA2et2s= +go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.46.0/go.mod h1:tkipS4DRzmpAmvg+Gw4++O1IdDq6TVDnvnYU6cmbQVs= +go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.46.0 h1:AP23h/mFgb/lc7tdck1Kfn9qxsM8TAeNPCU5C3pzaps= +go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.46.0/go.mod h1:K4EqCe1b4kGk5WR690ntg9LaBfsPoV32FwthbyoptuA= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.46.0 h1:OFnwLJr+pF3iHrlGSzbxyuo6/6HyBlnlN1CWEJmBVcw= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.46.0/go.mod h1:716wFneO0ov19A2beH5hjfh9AK5z/VWNAtDijp1Y0/g= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.46.0 h1:w53CDeOA/Kurp7yRsegSr6pbbr759dOvJ+yNmWM6Hxs= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.46.0/go.mod h1:BOmGMCbAtvcJiSJ+hLuhgPLdDbimnraSl8irz3iY8sY= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.46.0 h1:KrC1YrQeSt46ITMWAbgQx1M1eV1/1TKzttrBzymPmss= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.46.0/go.mod h1:zDSEzoEqsOrgBeGvH66KRgxh90VonFyJqBHA0Pk3+rM= +go.opentelemetry.io/otel/metric v1.46.0 h1:yBnkXvgV7AXFILZc5K6IZe/CBFF3OS7BJ8ov6/lj0K8= +go.opentelemetry.io/otel/metric v1.46.0/go.mod h1:iPmdWqifKUdzziPkvvzIJXITl56fQx2mGM/DHLB3/2o= +go.opentelemetry.io/otel/metric/x v0.68.0 h1:TA/cBT23D3MnxYPwHL7YFOdYGdx0A0v+s7Mzotpd1dU= +go.opentelemetry.io/otel/metric/x v0.68.0/go.mod h1:agudOmvWhwUTjgibWDzxD2PoWYnpw5Ht5jISYOD2Hd4= +go.opentelemetry.io/otel/sdk v1.46.0 h1:h5CNQQjEbuQXY/JfZtgt3i7HVFV3aHPO2OAwO2eTYPI= +go.opentelemetry.io/otel/sdk v1.46.0/go.mod h1:GAERFXFt5SYCEB+YiKUbMBeza6UaDH7GmGOZEfh2gSM= +go.opentelemetry.io/otel/sdk/metric v1.46.0 h1:0piZ26EG4RBfebb2jhDH6ERCYHoVWduc3kLgPCwSnSE= +go.opentelemetry.io/otel/sdk/metric v1.46.0/go.mod h1:I1PbKrdVc8Qu8HYVDNtqVIwLwjNrhsV/uFuxfwg8mO4= +go.opentelemetry.io/otel/trace v1.46.0 h1:OULy7ccdJnZtJ0UDYFOIGaCmiWzJ8Vi2G/Rsu60qs1c= +go.opentelemetry.io/otel/trace v1.46.0/go.mod h1:J7GAXweO77XSFkB/rmAqk9D6ihszhFjLU+d9WuUxDLI= go.opentelemetry.io/proto/otlp v1.11.0 h1:5rrYs0Ykyj50sdU/JU0x8etU+LubXWb+gED6TbEdMIk= go.opentelemetry.io/proto/otlp v1.11.0/go.mod h1:SmVizdCOAm3XBtG1g1NnOdhW6jtddT72hLMhv8VwA8E= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= @@ -377,10 +376,10 @@ google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7 google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20200423170343-7949de9c1215/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto/googleapis/api v0.0.0-20260720211330-0afa2a65878a h1:97PfJ4tCxY5C7NzzgGqQEMZmXbISdvSArNNEOoUGKBg= -google.golang.org/genproto/googleapis/api v0.0.0-20260720211330-0afa2a65878a/go.mod h1:1brfde68Npq6+WA75c1EHWPijZEG1kMus61ygPZfn4A= -google.golang.org/genproto/googleapis/rpc v0.0.0-20260720211330-0afa2a65878a h1:qI/YMH1ep2qQtqcp00gMQyoU7mjvbhg88GJKCvfoLj0= -google.golang.org/genproto/googleapis/rpc v0.0.0-20260720211330-0afa2a65878a/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8= +google.golang.org/genproto/googleapis/api v0.0.0-20260819154853-08b0e4226688 h1:ax2KzoSRIZU/M0cIxri3pKxy99vniH1PVxWC6si/eZI= +google.golang.org/genproto/googleapis/api v0.0.0-20260819154853-08b0e4226688/go.mod h1:1RJ9BQGyNdZwkGc1eTqkErfRZ6RJyYPHZo73BZ1vQqI= +google.golang.org/genproto/googleapis/rpc v0.0.0-20260819154853-08b0e4226688 h1:cYNAzI2sUwhmCcoj9TxvihSrqsxt6uIkj3rDRhSDmW4= +google.golang.org/genproto/googleapis/rpc v0.0.0-20260819154853-08b0e4226688/go.mod h1:DjtHYE8FKJLivXcBEjGwndXfIC23G0VpXiXKqG179uA= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= diff --git a/vendor/github.com/go-logr/logr/context_noslog.go b/vendor/github.com/go-logr/logr/context_noslog.go index f012f9a18..0a3d1a125 100644 --- a/vendor/github.com/go-logr/logr/context_noslog.go +++ b/vendor/github.com/go-logr/logr/context_noslog.go @@ -1,5 +1,4 @@ //go:build !go1.21 -// +build !go1.21 /* Copyright 2019 The logr Authors. diff --git a/vendor/github.com/go-logr/logr/context_slog.go b/vendor/github.com/go-logr/logr/context_slog.go index 065ef0b82..c69eb01ba 100644 --- a/vendor/github.com/go-logr/logr/context_slog.go +++ b/vendor/github.com/go-logr/logr/context_slog.go @@ -1,5 +1,4 @@ //go:build go1.21 -// +build go1.21 /* Copyright 2019 The logr Authors. diff --git a/vendor/github.com/go-logr/logr/funcr/funcr.go b/vendor/github.com/go-logr/logr/funcr/funcr.go index b22c57d71..7f4996e9e 100644 --- a/vendor/github.com/go-logr/logr/funcr/funcr.go +++ b/vendor/github.com/go-logr/logr/funcr/funcr.go @@ -426,7 +426,7 @@ func (f Formatter) colon() byte { } func (f Formatter) pretty(value any) string { - return f.prettyWithFlags(value, 0, 0) + return f.prettyWithFlags(value, 0, 0, 0, nil) } const ( @@ -434,7 +434,13 @@ const ( ) // TODO: This is not fast. Most of the overhead goes here. -func (f Formatter) prettyWithFlags(value any, flags uint32, depth int) string { +// value: The value to render +// flags: Bitmask of flags (see above) +// depth: The current depth of nested structs, slices, arrays, and maps +// ptrDepth: The current depth of including pointer dereferences +// ptrMap: A map of pointers already seen, to avoid infinite recursion (usually +// nil unless ptrDepth is large) +func (f Formatter) prettyWithFlags(value any, flags uint32, depth int, ptrDepth int, ptrMap map[uintptr]bool) string { if depth > f.opts.MaxLogDepth { return `""` } @@ -504,7 +510,7 @@ func (f Formatter) prettyWithFlags(value any, flags uint32, depth int) string { // arbitrary keys might need escaping buf.WriteString(prettyString(k)) buf.WriteByte(f.colon()) - buf.WriteString(f.prettyWithFlags(v[i+1], 0, depth+1)) + buf.WriteString(f.prettyWithFlags(v[i+1], 0, depth+1, ptrDepth+1, ptrMap)) } if flags&flagRawStruct == 0 { buf.WriteByte('}') @@ -576,7 +582,7 @@ func (f Formatter) prettyWithFlags(value any, flags uint32, depth int) string { } printComma = true // if we got here, we are rendering a field if fld.Anonymous && fld.Type.Kind() == reflect.Struct && name == "" { - buf.WriteString(f.prettyWithFlags(v.Field(i).Interface(), flags|flagRawStruct, depth+1)) + buf.WriteString(f.prettyWithFlags(v.Field(i).Interface(), flags|flagRawStruct, depth+1, ptrDepth+1, ptrMap)) continue } if name == "" { @@ -585,7 +591,7 @@ func (f Formatter) prettyWithFlags(value any, flags uint32, depth int) string { // field names can't contain characters which need escaping buf.WriteString(f.quoted(name, false)) buf.WriteByte(f.colon()) - buf.WriteString(f.prettyWithFlags(v.Field(i).Interface(), 0, depth+1)) + buf.WriteString(f.prettyWithFlags(v.Field(i).Interface(), 0, depth+1, ptrDepth+1, ptrMap)) } if flags&flagRawStruct == 0 { buf.WriteByte('}') @@ -612,7 +618,7 @@ func (f Formatter) prettyWithFlags(value any, flags uint32, depth int) string { buf.WriteByte(f.comma()) } e := v.Index(i) - buf.WriteString(f.prettyWithFlags(e.Interface(), 0, depth+1)) + buf.WriteString(f.prettyWithFlags(e.Interface(), 0, depth+1, ptrDepth+1, ptrMap)) } buf.WriteByte(']') return buf.String() @@ -637,7 +643,8 @@ func (f Formatter) prettyWithFlags(value any, flags uint32, depth int) string { keystr = prettyString(keystr) } else { // prettyWithFlags will produce already-escaped values - keystr = f.prettyWithFlags(it.Key().Interface(), 0, depth+1) + // key depth is unrelated to overall depth + keystr = f.prettyWithFlags(it.Key().Interface(), 0, 0, ptrDepth, ptrMap) if t.Key().Kind() != reflect.String { // JSON only does string keys. Unlike Go's standard JSON, we'll // convert just about anything to a string. @@ -646,16 +653,34 @@ func (f Formatter) prettyWithFlags(value any, flags uint32, depth int) string { } buf.WriteString(keystr) buf.WriteByte(f.colon()) - buf.WriteString(f.prettyWithFlags(it.Value().Interface(), 0, depth+1)) + buf.WriteString(f.prettyWithFlags(it.Value().Interface(), 0, depth+1, ptrDepth+1, ptrMap)) i++ } buf.WriteByte('}') return buf.String() - case reflect.Ptr, reflect.Interface: + case reflect.Pointer, reflect.Interface: if v.IsNil() { return "null" } - return f.prettyWithFlags(v.Elem().Interface(), 0, depth) + // Special case: recursive pointers. For normal use we do not want to + // count pointer dereferences as depth, but if we see the same pointer + // again we have a recursion and need to stop. After a large number of + // pointer dereferences we will start tracking pointers to avoid the + // perf hit of doing it in the normal path. + // + // This should not happen accidentally (e.g. json decoding should never + // do this) but we can handle it gracefully. + if ptrMap != nil && ptrMap[uintptr(v.Pointer())] { + depth = f.opts.MaxLogDepth + 1 // force a depth error + } + const maxDepthFactor = 4 // arbitrary, but we want it large enough to not false-alert + if ptrDepth > f.opts.MaxLogDepth*maxDepthFactor && ptrMap == nil { + ptrMap = map[uintptr]bool{} + } + if ptrMap != nil { + ptrMap[(uintptr)(v.Pointer())] = true + } + return f.prettyWithFlags(v.Elem().Interface(), 0, depth, ptrDepth+1, ptrMap) } return fmt.Sprintf(`""`, t.Kind().String()) } @@ -697,7 +722,7 @@ func isEmpty(v reflect.Value) bool { return v.Float() == 0 case reflect.Complex64, reflect.Complex128: return v.Complex() == 0 - case reflect.Interface, reflect.Ptr: + case reflect.Interface, reflect.Pointer: return v.IsNil() } return false diff --git a/vendor/github.com/go-logr/logr/funcr/slogsink.go b/vendor/github.com/go-logr/logr/funcr/slogsink.go index 7bd84761e..8b519c91e 100644 --- a/vendor/github.com/go-logr/logr/funcr/slogsink.go +++ b/vendor/github.com/go-logr/logr/funcr/slogsink.go @@ -1,5 +1,4 @@ //go:build go1.21 -// +build go1.21 /* Copyright 2023 The logr Authors. @@ -33,7 +32,7 @@ const extraSlogSinkDepth = 3 // 2 for slog, 1 for SlogSink func (l fnlogger) Handle(_ context.Context, record slog.Record) error { kvList := make([]any, 0, 2*record.NumAttrs()) record.Attrs(func(attr slog.Attr) bool { - kvList = attrToKVs(attr, kvList) + kvList = attrToKVs(attr, kvList, l.opts.MaxLogDepth) return true }) @@ -49,7 +48,7 @@ func (l fnlogger) Handle(_ context.Context, record slog.Record) error { func (l fnlogger) WithAttrs(attrs []slog.Attr) logr.SlogSink { kvList := make([]any, 0, 2*len(attrs)) for _, attr := range attrs { - kvList = attrToKVs(attr, kvList) + kvList = attrToKVs(attr, kvList, l.opts.MaxLogDepth) } l.AddValues(kvList) return &l @@ -61,14 +60,25 @@ func (l fnlogger) WithGroup(name string) logr.SlogSink { } // attrToKVs appends a slog.Attr to a logr-style kvList. It handle slog Groups -// and other details of slog. -func attrToKVs(attr slog.Attr, kvList []any) []any { +// and other details of slog. maxDepth bounds recursion into nested groups so a +// deeply-nested slog.Group cannot exhaust the stack; it is decremented per group +// level and starts at the Formatter's MaxLogDepth (past which the formatter would +// truncate the rendering anyway). +func attrToKVs(attr slog.Attr, kvList []any, maxDepth int) []any { attrVal := attr.Value.Resolve() if attrVal.Kind() == slog.KindGroup { + if maxDepth <= 0 { + // Nesting is too deep to build without risking a stack overflow. + // Stop here; the formatter truncates below MaxLogDepth regardless. + if attr.Key != "" { + kvList = append(kvList, attr.Key, "") + } + return kvList + } groupVal := attrVal.Group() grpKVs := make([]any, 0, 2*len(groupVal)) for _, attr := range groupVal { - grpKVs = attrToKVs(attr, grpKVs) + grpKVs = attrToKVs(attr, grpKVs, maxDepth-1) } if attr.Key == "" { // slog says we have to inline these diff --git a/vendor/github.com/go-logr/logr/sloghandler.go b/vendor/github.com/go-logr/logr/sloghandler.go index 82d1ba494..befaf5510 100644 --- a/vendor/github.com/go-logr/logr/sloghandler.go +++ b/vendor/github.com/go-logr/logr/sloghandler.go @@ -1,5 +1,4 @@ //go:build go1.21 -// +build go1.21 /* Copyright 2023 The logr Authors. diff --git a/vendor/github.com/go-logr/logr/slogr.go b/vendor/github.com/go-logr/logr/slogr.go index 28a83d024..bfe80eb8d 100644 --- a/vendor/github.com/go-logr/logr/slogr.go +++ b/vendor/github.com/go-logr/logr/slogr.go @@ -1,5 +1,4 @@ //go:build go1.21 -// +build go1.21 /* Copyright 2023 The logr Authors. diff --git a/vendor/github.com/go-logr/logr/slogsink.go b/vendor/github.com/go-logr/logr/slogsink.go index 4060fcbc2..ab76ea99f 100644 --- a/vendor/github.com/go-logr/logr/slogsink.go +++ b/vendor/github.com/go-logr/logr/slogsink.go @@ -1,5 +1,4 @@ //go:build go1.21 -// +build go1.21 /* Copyright 2023 The logr Authors. diff --git a/vendor/go.opentelemetry.io/otel/.lycheeignore b/vendor/go.opentelemetry.io/otel/.lycheeignore index 994b677df..df0d328bf 100644 --- a/vendor/go.opentelemetry.io/otel/.lycheeignore +++ b/vendor/go.opentelemetry.io/otel/.lycheeignore @@ -11,3 +11,17 @@ http://4.3.2.1:78/user/123 file:///home/runner/work/opentelemetry-go/opentelemetry-go/exporters/otlp/otlptrace/otlptracegrpc/internal/observ/dns:/:4317 # URL works, but it has blocked link checkers. https://dl.acm.org/doi/10.1145/198429.198435 +https://pkg.go.dev/google.golang.org/grpc.*internal/resolver +https://golang.org/src/crypto/tls/generate_cert.go +https://github.com/grpc/grpc/blob/.*/doc/naming.md +https://github.com/open-telemetry/opentelemetry-specification/blob/.* +# Fake domains used in otlp options_test.go tests +https?://env\.endpoint.* +https?://env\.metrics\.endpoint.* +https?://env_metrics_endpoint.* +https?://env\.traces\.endpoint.* +https?://env_traces_endpoint.* +https?://someendpoint.* +https?://overrode\.by\.signal\.specific.* +https?://overrode_by_signal_specific.* +https?://proxy\.com.* diff --git a/vendor/go.opentelemetry.io/otel/AGENTS.md b/vendor/go.opentelemetry.io/otel/AGENTS.md index 26c0fc4dd..02db71528 100644 --- a/vendor/go.opentelemetry.io/otel/AGENTS.md +++ b/vendor/go.opentelemetry.io/otel/AGENTS.md @@ -47,6 +47,9 @@ For docs-only, test-only, or review-only tasks, still start with the required re - Prefer examples over long code snippets in GoDoc when practical. - Keep docs aligned with actual behavior. Do not leave stale comments, stale examples, or stale package documentation behind. - For user-visible changes, update `CHANGELOG.md` under the appropriate `Added`, `Changed`, `Deprecated`, `Fixed`, or `Removed` section within `## [Unreleased]`. + - Always put the PR number at the end of the line (e.g., `(#1234)`), NOT the issue number. + - If the PR number is not yet known, omit it until the PR is created, then update the changelog entry before merging. + - Always use references to the go module that is updated (e.g., `go.opentelemetry.io/otel/sdk/metric`), instead of just the path (e.g., `sdk/metric`). ## Repository habits diff --git a/vendor/go.opentelemetry.io/otel/CHANGELOG.md b/vendor/go.opentelemetry.io/otel/CHANGELOG.md index 6a90451f5..4d473a1e8 100644 --- a/vendor/go.opentelemetry.io/otel/CHANGELOG.md +++ b/vendor/go.opentelemetry.io/otel/CHANGELOG.md @@ -11,6 +11,103 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm +## [1.46.0/0.68.0/0.22.0/0.0.19] - 2026-08-25 + +This release is the last to support [Go 1.25]. +The next release will require at least [Go 1.26]. + +### Added + +- Support testing of [Go 1.27]. (#8811) +- Support `http/json` protocol in `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp`. (#8273, #8775, #8831) +- Add `Hasher` struct and methods in `go.opentelemetry.io/otel/attribute` to compute authoritative `Distinct` hashes incrementally for attribute filtering and deduplication. (#8598) + +### Changed + +- Lazily evaluate filtered and dropped attributes on measurement hot paths in `go.opentelemetry.io/otel/sdk/metric` to avoid unnecessary attribute set allocations. (#8598) +- Add `ErrExporterShutdown` to `go.opentelemetry.io/otel/sdk/log` and return it from the `go.opentelemetry.io/otel/exporters/stdout/stdoutlog`, `go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc`, and `go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp` exporters when `Export` is called after `Shutdown`. (#8773) +- Clarify in `go.opentelemetry.io/otel/log` that calling `Logger.Enabled` is optional and that cached results can become stale. (#8764) + +### Fixed + +- Export dropped attribute counts in OTLP log records from `go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc` and `go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp`. (#8829) +- Name span events created from OpenTracing logs after the `event` log field, falling back to `log`, instead of always using an empty name in `go.opentelemetry.io/otel/bridge/opentracing`. (#8648) +- Count exception attributes omitted due to the attribute count limit as dropped in `go.opentelemetry.io/otel/sdk/log`. (#8796) +- Prevent log record and instrumentation scope attributes with empty keys from reaching processors and exporters in `go.opentelemetry.io/otel/sdk/log`. (#8797) +- Fix a data race when span attributes are read concurrently in `go.opentelemetry.io/otel/sdk/trace`. (#8706) +- Prevent a panic in `(*Set).Filter` when called on a nil receiver in `go.opentelemetry.io/otel/attribute`. (#8792) +- The simple span and log processors record `otel.sdk.processor.{span,log}.processed` when the record is submitted to the exporter instead of after the export completes, and no longer set `error.type` from the export outcome, in `go.opentelemetry.io/otel/sdk/trace` and `go.opentelemetry.io/otel/sdk/log`. (#8705) +- Prevent `Resource.MarshalLog` from panicking on nil resources in `go.opentelemetry.io/otel/sdk/resource`. (#8758) + +## [1.45.0/0.67.0/0.21.0/0.0.18] - 2026-08-03 + +### Added + +- Add experimental observability metrics to `BatchProcessor` in `go.opentelemetry.io/otel/sdk/log`. (#7124) +- Add the experimental `WithUnsafeAttributes` no-copy attribute option to `go.opentelemetry.io/otel/metric/x` for future performance improvements. This API is a work in progress. (#8251) +- Add `Map` and `MapValue` functions for the new `MAP` attribute type in `go.opentelemetry.io/otel/attribute`. (#8445) +- Support `MAP` attributes in `go.opentelemetry.io/otel/exporters/otlp/otlptrace`. (#8453) +- Support `MAP` attributes in `go.opentelemetry.io/otel/exporters/otlp/otlplog`. (#8453) +- Support `MAP` attributes in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric`. (#8453) +- Support `MAP` attributes in `go.opentelemetry.io/otel/exporters/zipkin`. (#8453) +- Apply `AttributeValueLengthLimit` recursively to values contained in `attribute.MAP` attributes in `go.opentelemetry.io/otel/sdk/trace`. (#8454) +- Remove duplicate keys from `attribute.MAP` values in `go.opentelemetry.io/otel/sdk/resource` using last-value-wins semantics. (#8471) +- Remove duplicate keys by default from `attribute.MAP` values in instrumentation scope attributes in `go.opentelemetry.io/otel/sdk/log` using last-value-wins semantics. (#8471) +- Remove duplicate keys by default from `attribute.MAP` values in span, event, link, and instrumentation scope attributes in `go.opentelemetry.io/otel/sdk/trace` using last-value-wins semantics. (#8471) +- Remove duplicate keys by default from `attribute.MAP` values in measurement and instrumentation scope attributes in `go.opentelemetry.io/otel/sdk/metric` using last-value-wins semantics. (#8471) +- Extend `WithAllowKeyDuplication` in `go.opentelemetry.io/otel/sdk/log` to disable duplicate-key removal in `attribute.MAP` values for instrumentation scope attributes. (#8471) +- Add the `go.opentelemetry.io/otel/semconv/v1.42.0` package. + The package contains semantic conventions from the `v1.42.0` version of the OpenTelemetry Semantic Conventions. + See the [migration documentation](./semconv/v1.42.0/MIGRATION.md) for information on how to upgrade from `go.opentelemetry.io/otel/semconv/v1.41.0`. (#8484) +- Add `WithoutPanicRecording` as a `TracerProviderOption` in `go.opentelemetry.io/otel/sdk/trace` to disable exception event recording for panics. (#8532) +- Add the `go.opentelemetry.io/otel/semconv/v1.43.0` package. + The package contains semantic conventions from the `v1.43.0` version of the OpenTelemetry Semantic Conventions. + See the [migration documentation](./semconv/v1.43.0/MIGRATION.md) for information on how to upgrade from `go.opentelemetry.io/otel/semconv/v1.42.0`. (#8628) + +### Changed + +- `HistogramReservoir` in `go.opentelemetry.io/otel/sdk/metric/exemplar` now uses a time-unbiased sampling algorithm for exemplars. (#8306) +- ⚠️ **Breaking Change:** Use `go.opentelemetry.io/otel/attribute.Value` and `go.opentelemetry.io/otel/attribute.KeyValue` for log bodies and attributes in `go.opentelemetry.io/otel/log`, `go.opentelemetry.io/otel/log/logtest`, `go.opentelemetry.io/otel/sdk/log`, and `go.opentelemetry.io/otel/sdk/log/logtest`. (#8490) +- Encode log bodies and attributes as `go.opentelemetry.io/otel/attribute.Value` JSON in `go.opentelemetry.io/otel/exporters/stdout/stdoutlog`. (#8490) +- Improve the performance of hashing `BOOLSLICE`, `INT64SLICE`, `FLOAT64SLICE`, and `STRINGSLICE` attribute values by avoiding reflection for short slices in `go.opentelemetry.io/otel/attribute`. (#8511) +- ⚠️ **Breaking Change:** `WithEndpointURL` in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp` no longer appends the default signal path when an endpoint URL has no path, making the behavior consistent with `go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp` and with setting the endpoint through `OTEL_EXPORTER_OTLP_METRICS_ENDPOINT`. If the URL has no path component, the root path (`/`) is used. Use `WithEndpointURL(url.JoinPath(endpoint, "/v1/metrics"))` to preserve the previous behavior. (#8538) +- ⚠️ **Breaking Change:** `WithEndpointURL` in `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp` no longer appends the default signal path when an endpoint URL has no path, making the behavior consistent with `go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp` and with setting the endpoint through `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT`. If the URL has no path component, the root path (`/`) is used. Use `WithEndpointURL(url.JoinPath(endpoint, "/v1/traces"))` to preserve the previous behavior. (#8538) + +### Deprecated + +- Deprecate `WithExportBufferSize` in `go.opentelemetry.io/otel/sdk/log`. The option remains available for source compatibility but no longer affects behavior; `BatchProcessor` no longer maintains a separate export-request buffer. (#8620) + +### Removed + +- ⚠️ **Breaking Change:** Remove `Kind`, `Value`, `KeyValue`, their constructors, and attribute conversion helpers from `go.opentelemetry.io/otel/log`. (#8490) +- ⚠️ **Breaking Change:** Remove the `AttributeValueLengthLimit` and `AttributeCountLimit` fields from `RecordFactory` in `go.opentelemetry.io/otel/sdk/log/logtest`; records produced by the factory now keep attribute limits disabled so test code can append exact attributes. (#8556) + +### Fixed + +- Apply TLS certificates configured through environment variables to gRPC connections in `go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc`. +- Prevent panics in `go.opentelemetry.io/otel/bridge/opentracing` when OpenTracing baggage is propagated concurrently with `Span.SetBaggageItem`. +- Fix an off-by-one error in `FixedSizeReservoir` in `go.opentelemetry.io/otel/sdk/metric/exemplar` that prevented the first exemplar from being sampled after the reservoir was filled. (#8309) +- Interpret HTTP `Retry-After` header values as seconds instead of nanoseconds when retrying OTLP HTTP exports in `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp`, `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp`, and `go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp`. (#8383) +- Fix a memory leak in the `Reservoir` implementation in `go.opentelemetry.io/otel/sdk/metric/exemplar`, where storing the full `context.Context` pinned large objects such as gRPC transport buffers. (#8389) +- Prevent a non-empty attribute set whose computed hash is zero from collapsing to an empty set in `go.opentelemetry.io/otel/attribute`. (#8402) +- Fix histogram data point reuse in `go.opentelemetry.io/otel/sdk/metric` aggregation to avoid leaking stale sum, minimum, and maximum values when they are disabled in subsequent collections. (#8403) +- Avoid preallocating scope attributes when they are disabled in `go.opentelemetry.io/otel/exporters/prometheus`. (#8404) +- Support HTTP-date values in the HTTP `Retry-After` header when retrying OTLP HTTP exports in `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp`, `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp`, and `go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp`. (#8417) +- Reduce histogram heap allocations by reusing `BucketCounts` and `Exemplars` slices across `Collect` cycles in the cumulative histogram aggregation in `go.opentelemetry.io/otel/sdk/metric`. (#8428) +- Fix `go.opentelemetry.io/otel/exporters/stdout/stdouttrace` self-observability to record `error.type` on the operation-duration histogram when the `exportedSpans` metric is disabled. (#8432) +- Stop including trace exporter endpoint configuration in internal logs from `go.opentelemetry.io/otel/sdk/trace`, `go.opentelemetry.io/otel/exporters/otlp/otlptrace`, `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc`, `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp`, and `go.opentelemetry.io/otel/exporters/zipkin`. (#8438) +- Fix invalid error formatting for out-of-range JSON code values in `go.opentelemetry.io/otel/codes`. (#8497) +- Clarify in `go.opentelemetry.io/otel/log` that `Logger.Enabled` should be checked for every log emission because its result may change over time. (#8565) +- Preserve user-provided exception attributes while independently deriving missing exception message and type attributes in `go.opentelemetry.io/otel/sdk/log`. (#8566) +- Make `WithAttributeCountLimit(0)` and `OTEL_LOGRECORD_ATTRIBUTE_COUNT_LIMIT=0` discard all log record attributes in `go.opentelemetry.io/otel/sdk/log`. (#8570) +- Clarify that the `Record` methods of `Float64Histogram` and `Int64Histogram` in `go.opentelemetry.io/otel/metric` expect non-negative values. (#8574) +- Clarify in `go.opentelemetry.io/otel/log` that `LoggerProvider` implementations should retain an empty `Logger` name instead of replacing it with a default. (#8587) +- Ensure that the built-in processors in `go.opentelemetry.io/otel/sdk/log` call exporter `ForceFlush` during `Shutdown`. (#8599) +- Prevent processor operations in `go.opentelemetry.io/otel/sdk/log` from overlapping with processor shutdown or running after `LoggerProvider` shutdown. (#8608) +- Prevent `BatchProcessor` in `go.opentelemetry.io/otel/sdk/log` from busy-spinning under exporter backpressure and serialize dequeue, export, force-flush, and shutdown work in one worker. (#8620) +- Make `BatchProcessor` in `go.opentelemetry.io/otel/sdk/log` return errors encountered while draining records during `ForceFlush` and `Shutdown`, while continuing to attempt later batches as long as the request context remains valid. (#8620) +- Keep the default `BatchProcessor` maximum export batch size in `go.opentelemetry.io/otel/sdk/log` at or below the configured maximum queue size. (#8620) + ## [1.44.0/0.66.0/0.20.0/0.0.17] 2026-05-27 ### Added @@ -42,13 +139,13 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm Set `OTEL_GO_X_METRIC_EXPORT_BATCH_SIZE=` to enable for all periodic readers. See `go.opentelemetry.io/otel/sdk/metric/internal/x` for feature documentation. (#8071) - Add experimental self-observability metrics in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc`. - Enable with `OTEL_GO_X_SELF_OBSERVABILITY=true` environment variable. + Enable with `OTEL_GO_X_OBSERVABILITY=true` environment variable. See `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/x` for feature documentation. (#8192) - Add experimental self-observability metrics in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp`. - Enable with `OTEL_GO_X_SELF_OBSERVABILITY=true` environment variable. + Enable with `OTEL_GO_X_OBSERVABILITY=true` environment variable. See `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/x` for feature documentation. (#8194) - Add experimental self-observability metrics in `go.opentelemetry.io/otel/exporters/stdout/stdoutlog`. - Enable with `OTEL_GO_X_SELF_OBSERVABILITY=true` environment variable. + Enable with `OTEL_GO_X_OBSERVABILITY=true` environment variable. See `go.opentelemetry.io/otel/stdout/stdoutlog/internal/x` for feature documentation. (#8263) - Add `WithDefaultAttributes` to `go.opentelemetry.io/otel/metric/x` to support setting default attributes on instruments. (#8135) - Add `go.opentelemetry.io/otel/semconv/v1.41.0` package. @@ -3713,7 +3810,9 @@ It contains api and sdk for trace and meter. - CircleCI build CI manifest files. - CODEOWNERS file to track owners of this project. -[Unreleased]: https://github.com/open-telemetry/opentelemetry-go/compare/v1.44.0...HEAD +[Unreleased]: https://github.com/open-telemetry/opentelemetry-go/compare/v1.46.0...HEAD +[1.46.0/0.68.0/0.22.0/0.0.19]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v1.46.0 +[1.45.0/0.67.0/0.21.0/0.0.18]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v1.45.0 [1.44.0/0.66.0/0.20.0/0.0.17]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v1.44.0 [1.43.0/0.65.0/0.19.0]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v1.43.0 [1.42.0/0.64.0/0.18.0/0.0.16]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v1.42.0 @@ -3817,6 +3916,7 @@ It contains api and sdk for trace and meter. +[Go 1.27]: https://go.dev/doc/go1.27 [Go 1.26]: https://go.dev/doc/go1.26 [Go 1.25]: https://go.dev/doc/go1.25 [Go 1.24]: https://go.dev/doc/go1.24 diff --git a/vendor/go.opentelemetry.io/otel/VERSIONING.md b/vendor/go.opentelemetry.io/otel/VERSIONING.md index b27c9e84f..56eaa7d22 100644 --- a/vendor/go.opentelemetry.io/otel/VERSIONING.md +++ b/vendor/go.opentelemetry.io/otel/VERSIONING.md @@ -12,6 +12,12 @@ is designed so the following goals can be achieved. * [Semantic import versioning](https://github.com/golang/go/wiki/Modules#semantic-import-versioning) will be used. + * Stable module compatibility is understood in terms of the [Go 1 + compatibility guidelines](https://go.dev/doc/go1compat). Code that + compiled against an older version of a package should continue to compile + against newer versions of that package, subject to the exceptions in the + Go 1 compatibility guidelines and any additional exceptions documented + below. * Versions will comply with [semver 2.0](https://semver.org/spec/v2.0.0.html) with the following exceptions. * New methods may be added to exported API interfaces. All exported diff --git a/vendor/go.opentelemetry.io/otel/attribute/doc.go b/vendor/go.opentelemetry.io/otel/attribute/doc.go index eef51ebc2..c543f2ca6 100644 --- a/vendor/go.opentelemetry.io/otel/attribute/doc.go +++ b/vendor/go.opentelemetry.io/otel/attribute/doc.go @@ -2,4 +2,4 @@ // SPDX-License-Identifier: Apache-2.0 // Package attribute provides key and value attributes. -package attribute // import "go.opentelemetry.io/otel/attribute" +package attribute diff --git a/vendor/go.opentelemetry.io/otel/attribute/encoder.go b/vendor/go.opentelemetry.io/otel/attribute/encoder.go index ca186d8ac..413e7a185 100644 --- a/vendor/go.opentelemetry.io/otel/attribute/encoder.go +++ b/vendor/go.opentelemetry.io/otel/attribute/encoder.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package attribute // import "go.opentelemetry.io/otel/attribute" +package attribute import ( "bytes" diff --git a/vendor/go.opentelemetry.io/otel/attribute/filter.go b/vendor/go.opentelemetry.io/otel/attribute/filter.go index 624ebbe38..6dab64f5d 100644 --- a/vendor/go.opentelemetry.io/otel/attribute/filter.go +++ b/vendor/go.opentelemetry.io/otel/attribute/filter.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package attribute // import "go.opentelemetry.io/otel/attribute" +package attribute // Filter supports removing certain attributes from attribute sets. When // the filter returns true, the attribute will be kept in the filtered diff --git a/vendor/go.opentelemetry.io/otel/attribute/hash.go b/vendor/go.opentelemetry.io/otel/attribute/hash.go index 92f39ffe7..54c26e67a 100644 --- a/vendor/go.opentelemetry.io/otel/attribute/hash.go +++ b/vendor/go.opentelemetry.io/otel/attribute/hash.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package attribute // import "go.opentelemetry.io/otel/attribute" +package attribute import ( "fmt" @@ -29,16 +29,75 @@ const ( stringSliceID uint64 = 7453010373645655387 // "[]string" (little endian) byteSliceID uint64 = 6874028470941080415 // "_[]byte_" (little endian) sliceID uint64 = 7883494272577650031 // "__slice_" (little endian) + mapID uint64 = 6872316492666199903 // "__map___" (little endian) emptyID uint64 = 7305809155345288421 // "__empty_" (little endian) ) +// Hasher computes a Distinct value from KeyValue attributes supplied with +// Write. +// +// A Hasher must be obtained from [NewHasher]. The zero value is not usable and +// its methods will panic. +type Hasher struct { + h xxhash.Hash +} + +// NewHasher returns a new Hasher. +func NewHasher() *Hasher { + return &Hasher{h: xxhash.New()} +} + +// Reset resets h to its initial state so it can be reused. +func (h *Hasher) Reset() { + h.h.Reset() +} + +// Write adds kv to the hash. +// +// Write requires attributes to be supplied in ascending key order with no +// duplicate keys. To produce the same Distinct as Set.Equivalent, write +// attributes in ascending key order, with no more than one value for each key. +// If the source contains duplicate keys, retain the last value for each key +// before calling Write. +func (h *Hasher) Write(kv KeyValue) { + // hashKV mutates the digest h.h refers to in place and returns the same + // Hash value it was passed. Discarding the result keeps the digest pointer + // from flowing back into h, which would force the digest to be heap + // allocated for every Hasher. Keeping Write this small also keeps it within + // the inlining budget, which matters because hashKVs calls it per attribute. + _ = hashKV(h.h, kv) +} + +// Distinct returns the identifier for the attributes written to h. When Write +// is called as described above, it returns the same value as [Set.Equivalent]. +func (h *Hasher) Distinct() Distinct { + // No count of written attributes is needed to detect the empty case. The + // sum of a digest with nothing written to it is emptyHash, which is + // non-zero (0xef46db3751d8e999), so it passes through remapZeroHash + // unchanged and matches emptySet.Equivalent. + return Distinct{hash: remapZeroHash(h.h.Sum64())} +} + +// remapZeroHash remaps a 0 sum to a non-zero value, because hash == 0 is a +// reserved sentinel (treated as empty/invalid). +func remapZeroHash(sum uint64) uint64 { + if sum == 0 { + return 1 + } + return sum +} + // hashKVs returns a new xxHash64 hash of kvs. +// +// This routes through [Hasher] so that Set hashing and Hasher cannot disagree: +// there is exactly one implementation of how attributes are mixed and how the +// final sum is framed. func hashKVs(kvs []KeyValue) uint64 { - h := xxhash.New() + h := NewHasher() for _, kv := range kvs { - h = hashKV(h, kv) + h.Write(kv) } - return h.Sum64() + return h.Distinct().hash } // hashKV returns the xxHash64 hash of kv with h as the base. @@ -64,27 +123,79 @@ func hashValue(h xxhash.Hash, v Value) xxhash.Hash { h = h.String(v.stringly) case BOOLSLICE: h = h.Uint64(boolSliceID) - rv := reflect.ValueOf(v.slice) - for i := 0; i < rv.Len(); i++ { - h = h.Bool(rv.Index(i).Bool()) + switch vals := v.slice.(type) { + case [0]bool: + case [1]bool: + h = h.Bool(vals[0]) + case [2]bool: + h = h.Bool(vals[0]) + h = h.Bool(vals[1]) + case [3]bool: + h = h.Bool(vals[0]) + h = h.Bool(vals[1]) + h = h.Bool(vals[2]) + default: + rv := reflect.ValueOf(v.slice) + for i := 0; i < rv.Len(); i++ { + h = h.Bool(rv.Index(i).Bool()) + } } case INT64SLICE: h = h.Uint64(int64SliceID) - rv := reflect.ValueOf(v.slice) - for i := 0; i < rv.Len(); i++ { - h = h.Int64(rv.Index(i).Int()) + switch vals := v.slice.(type) { + case [0]int64: + case [1]int64: + h = h.Int64(vals[0]) + case [2]int64: + h = h.Int64(vals[0]) + h = h.Int64(vals[1]) + case [3]int64: + h = h.Int64(vals[0]) + h = h.Int64(vals[1]) + h = h.Int64(vals[2]) + default: + rv := reflect.ValueOf(v.slice) + for i := 0; i < rv.Len(); i++ { + h = h.Int64(rv.Index(i).Int()) + } } case FLOAT64SLICE: h = h.Uint64(float64SliceID) - rv := reflect.ValueOf(v.slice) - for i := 0; i < rv.Len(); i++ { - h = h.Float64(rv.Index(i).Float()) + switch vals := v.slice.(type) { + case [0]float64: + case [1]float64: + h = h.Float64(vals[0]) + case [2]float64: + h = h.Float64(vals[0]) + h = h.Float64(vals[1]) + case [3]float64: + h = h.Float64(vals[0]) + h = h.Float64(vals[1]) + h = h.Float64(vals[2]) + default: + rv := reflect.ValueOf(v.slice) + for i := 0; i < rv.Len(); i++ { + h = h.Float64(rv.Index(i).Float()) + } } case STRINGSLICE: h = h.Uint64(stringSliceID) - rv := reflect.ValueOf(v.slice) - for i := 0; i < rv.Len(); i++ { - h = h.String(rv.Index(i).String()) + switch vals := v.slice.(type) { + case [0]string: + case [1]string: + h = h.String(vals[0]) + case [2]string: + h = h.String(vals[0]) + h = h.String(vals[1]) + case [3]string: + h = h.String(vals[0]) + h = h.String(vals[1]) + h = h.String(vals[2]) + default: + rv := reflect.ValueOf(v.slice) + for i := 0; i < rv.Len(); i++ { + h = h.String(rv.Index(i).String()) + } } case BYTESLICE: h = h.Uint64(byteSliceID) @@ -95,21 +206,79 @@ func hashValue(h xxhash.Hash, v Value) xxhash.Hash { case [0]Value: // No values to hash, but the type identifier is still hashed above. case [1]Value: - h = hashValueSlice(h, vals[:]) + h = hashValue(h, vals[0]) case [2]Value: - h = hashValueSlice(h, vals[:]) + h = hashValue(h, vals[0]) + h = hashValue(h, vals[1]) case [3]Value: - h = hashValueSlice(h, vals[:]) + h = hashValue(h, vals[0]) + h = hashValue(h, vals[1]) + h = hashValue(h, vals[2]) case [4]Value: - h = hashValueSlice(h, vals[:]) + h = hashValue(h, vals[0]) + h = hashValue(h, vals[1]) + h = hashValue(h, vals[2]) + h = hashValue(h, vals[3]) case [5]Value: - h = hashValueSlice(h, vals[:]) + h = hashValue(h, vals[0]) + h = hashValue(h, vals[1]) + h = hashValue(h, vals[2]) + h = hashValue(h, vals[3]) + h = hashValue(h, vals[4]) default: rv := reflect.ValueOf(v.slice) for i := 0; i < rv.Len(); i++ { h = hashValue(h, rv.Index(i).Interface().(Value)) } } + case MAP: + h = h.Uint64(mapID) + switch vals := v.slice.(type) { + case [0]KeyValue: + // No values to hash, but the type identifier is still hashed above. + case [1]KeyValue: + h = h.String(string(vals[0].Key)) + h = hashValue(h, vals[0].Value) + case [2]KeyValue: + h = h.String(string(vals[0].Key)) + h = hashValue(h, vals[0].Value) + h = h.String(string(vals[1].Key)) + h = hashValue(h, vals[1].Value) + case [3]KeyValue: + h = h.String(string(vals[0].Key)) + h = hashValue(h, vals[0].Value) + h = h.String(string(vals[1].Key)) + h = hashValue(h, vals[1].Value) + h = h.String(string(vals[2].Key)) + h = hashValue(h, vals[2].Value) + case [4]KeyValue: + h = h.String(string(vals[0].Key)) + h = hashValue(h, vals[0].Value) + h = h.String(string(vals[1].Key)) + h = hashValue(h, vals[1].Value) + h = h.String(string(vals[2].Key)) + h = hashValue(h, vals[2].Value) + h = h.String(string(vals[3].Key)) + h = hashValue(h, vals[3].Value) + case [5]KeyValue: + h = h.String(string(vals[0].Key)) + h = hashValue(h, vals[0].Value) + h = h.String(string(vals[1].Key)) + h = hashValue(h, vals[1].Value) + h = h.String(string(vals[2].Key)) + h = hashValue(h, vals[2].Value) + h = h.String(string(vals[3].Key)) + h = hashValue(h, vals[3].Value) + h = h.String(string(vals[4].Key)) + h = hashValue(h, vals[4].Value) + default: + rv := reflect.ValueOf(v.slice) + for i := 0; i < rv.Len(); i++ { + kv := rv.Index(i).Interface().(KeyValue) + h = h.String(string(kv.Key)) + h = hashValue(h, kv.Value) + } + } case EMPTY: h = h.Uint64(emptyID) default: @@ -121,10 +290,3 @@ func hashValue(h xxhash.Hash, v Value) xxhash.Hash { } return h } - -func hashValueSlice(h xxhash.Hash, vals []Value) xxhash.Hash { - for _, v := range vals { - h = hashValue(h, v) - } - return h -} diff --git a/vendor/go.opentelemetry.io/otel/attribute/internal/attribute.go b/vendor/go.opentelemetry.io/otel/attribute/internal/attribute.go index d9f51fa2d..ec4a5f07f 100644 --- a/vendor/go.opentelemetry.io/otel/attribute/internal/attribute.go +++ b/vendor/go.opentelemetry.io/otel/attribute/internal/attribute.go @@ -5,7 +5,7 @@ Package attribute provide several helper functions for some commonly used logic of processing attributes. */ -package attribute // import "go.opentelemetry.io/otel/attribute/internal" +package attribute import ( "reflect" diff --git a/vendor/go.opentelemetry.io/otel/attribute/internal/xxhash/xxhash.go b/vendor/go.opentelemetry.io/otel/attribute/internal/xxhash/xxhash.go index 113a97838..4fcdd2dbe 100644 --- a/vendor/go.opentelemetry.io/otel/attribute/internal/xxhash/xxhash.go +++ b/vendor/go.opentelemetry.io/otel/attribute/internal/xxhash/xxhash.go @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // Package xxhash provides a wrapper around the xxhash library for attribute hashing. -package xxhash // import "go.opentelemetry.io/otel/attribute/internal/xxhash" +package xxhash import ( "encoding/binary" @@ -62,3 +62,8 @@ func (h Hash) String(val string) Hash { func (h Hash) Sum64() uint64 { return h.d.Sum64() } + +// Reset resets the hash to its initial state. +func (h Hash) Reset() { + h.d.Reset() +} diff --git a/vendor/go.opentelemetry.io/otel/attribute/iterator.go b/vendor/go.opentelemetry.io/otel/attribute/iterator.go index 8df6249f0..1afd00ff0 100644 --- a/vendor/go.opentelemetry.io/otel/attribute/iterator.go +++ b/vendor/go.opentelemetry.io/otel/attribute/iterator.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package attribute // import "go.opentelemetry.io/otel/attribute" +package attribute // Iterator allows iterating over the set of attributes in order, sorted by // key. diff --git a/vendor/go.opentelemetry.io/otel/attribute/key.go b/vendor/go.opentelemetry.io/otel/attribute/key.go index cdc7089e8..6403191c2 100644 --- a/vendor/go.opentelemetry.io/otel/attribute/key.go +++ b/vendor/go.opentelemetry.io/otel/attribute/key.go @@ -1,16 +1,16 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package attribute // import "go.opentelemetry.io/otel/attribute" +package attribute // Key represents the key part in key-value pairs. It's a string. The // allowed character set in the key depends on the use of the key. type Key string -// Bool creates a KeyValue instance with a BOOL Value. +// Bool returns a [KeyValue] for a bool value. // -// If creating both a key and value at the same time, use the provided -// convenience function instead -- Bool(name, value). +// If creating both a key and value at the same time, use the package-level +// [Bool] function. func (k Key) Bool(v bool) KeyValue { return KeyValue{ Key: k, @@ -18,10 +18,15 @@ func (k Key) Bool(v bool) KeyValue { } } -// BoolSlice creates a KeyValue instance with a BOOLSLICE Value. +// BoolSlice returns a [KeyValue] for a []bool value. // -// If creating both a key and value at the same time, use the provided -// convenience function instead -- BoolSlice(name, value). +// Note that many observability backends are not optimized to query, index, or +// aggregate complex attribute values. Complex values may also carry +// additional performance overhead. Prefer primitive values when +// possible. +// +// If creating both a key and value at the same time, use the package-level +// [BoolSlice] function. func (k Key) BoolSlice(v []bool) KeyValue { return KeyValue{ Key: k, @@ -29,10 +34,12 @@ func (k Key) BoolSlice(v []bool) KeyValue { } } -// Int creates a KeyValue instance with an INT64 Value. +// Int returns a [KeyValue] for an int value. +// +// It is provided as a convenience for [Key.Int64]. // -// If creating both a key and value at the same time, use the provided -// convenience function instead -- Int(name, value). +// If creating both a key and value at the same time, use the package-level [Int] +// function. func (k Key) Int(v int) KeyValue { return KeyValue{ Key: k, @@ -40,10 +47,17 @@ func (k Key) Int(v int) KeyValue { } } -// IntSlice creates a KeyValue instance with an INT64SLICE Value. +// IntSlice returns a [KeyValue] for a []int value. +// +// It is provided as a convenience for [Key.Int64Slice]. // -// If creating both a key and value at the same time, use the provided -// convenience function instead -- IntSlice(name, value). +// Note that many observability backends are not optimized to query, index, or +// aggregate complex attribute values. Complex values may also carry +// additional performance overhead. Prefer primitive values when +// possible. +// +// If creating both a key and value at the same time, use the package-level +// [IntSlice] function. func (k Key) IntSlice(v []int) KeyValue { return KeyValue{ Key: k, @@ -51,10 +65,10 @@ func (k Key) IntSlice(v []int) KeyValue { } } -// Int64 creates a KeyValue instance with an INT64 Value. +// Int64 returns a [KeyValue] for an int64 value. // -// If creating both a key and value at the same time, use the provided -// convenience function instead -- Int64(name, value). +// If creating both a key and value at the same time, use the package-level +// [Int64] function. func (k Key) Int64(v int64) KeyValue { return KeyValue{ Key: k, @@ -62,10 +76,15 @@ func (k Key) Int64(v int64) KeyValue { } } -// Int64Slice creates a KeyValue instance with an INT64SLICE Value. +// Int64Slice returns a [KeyValue] for a []int64 value. +// +// Note that many observability backends are not optimized to query, index, or +// aggregate complex attribute values. Complex values may also carry +// additional performance overhead. Prefer primitive values when +// possible. // -// If creating both a key and value at the same time, use the provided -// convenience function instead -- Int64Slice(name, value). +// If creating both a key and value at the same time, use the package-level +// [Int64Slice] function. func (k Key) Int64Slice(v []int64) KeyValue { return KeyValue{ Key: k, @@ -73,10 +92,10 @@ func (k Key) Int64Slice(v []int64) KeyValue { } } -// Float64 creates a KeyValue instance with a FLOAT64 Value. +// Float64 returns a [KeyValue] for a float64 value. // -// If creating both a key and value at the same time, use the provided -// convenience function instead -- Float64(name, value). +// If creating both a key and value at the same time, use the package-level +// [Float64] function. func (k Key) Float64(v float64) KeyValue { return KeyValue{ Key: k, @@ -84,10 +103,15 @@ func (k Key) Float64(v float64) KeyValue { } } -// Float64Slice creates a KeyValue instance with a FLOAT64SLICE Value. +// Float64Slice returns a [KeyValue] for a []float64 value. // -// If creating both a key and value at the same time, use the provided -// convenience function instead -- Float64(name, value). +// Note that many observability backends are not optimized to query, index, or +// aggregate complex attribute values. Complex values may also carry +// additional performance overhead. Prefer primitive values when +// possible. +// +// If creating both a key and value at the same time, use the package-level +// [Float64Slice] function. func (k Key) Float64Slice(v []float64) KeyValue { return KeyValue{ Key: k, @@ -95,10 +119,10 @@ func (k Key) Float64Slice(v []float64) KeyValue { } } -// String creates a KeyValue instance with a STRING Value. +// String returns a [KeyValue] for a string value. // -// If creating both a key and value at the same time, use the provided -// convenience function instead -- String(name, value). +// If creating both a key and value at the same time, use the package-level +// [String] function. func (k Key) String(v string) KeyValue { return KeyValue{ Key: k, @@ -106,10 +130,15 @@ func (k Key) String(v string) KeyValue { } } -// StringSlice creates a KeyValue instance with a STRINGSLICE Value. +// StringSlice returns a [KeyValue] for a []string value. +// +// Note that many observability backends are not optimized to query, index, or +// aggregate complex attribute values. Complex values may also carry +// additional performance overhead. Prefer primitive values when +// possible. // -// If creating both a key and value at the same time, use the provided -// convenience function instead -- StringSlice(name, value). +// If creating both a key and value at the same time, use the package-level +// [StringSlice] function. func (k Key) StringSlice(v []string) KeyValue { return KeyValue{ Key: k, @@ -117,10 +146,15 @@ func (k Key) StringSlice(v []string) KeyValue { } } -// ByteSlice creates a KeyValue instance with a BYTESLICE Value. +// ByteSlice returns a [KeyValue] for a []byte value. // -// If creating both a key and value at the same time, use the provided -// convenience function instead -- ByteSlice(name, value). +// Note that many observability backends are not optimized to query, index, or +// aggregate complex attribute values. Complex values may also carry +// additional performance overhead. Prefer primitive values when +// possible. +// +// If creating both a key and value at the same time, use the package-level +// [ByteSlice] function. func (k Key) ByteSlice(v []byte) KeyValue { return KeyValue{ Key: k, @@ -128,10 +162,15 @@ func (k Key) ByteSlice(v []byte) KeyValue { } } -// Slice creates a KeyValue instance with a SLICE Value. +// Slice returns a [KeyValue] for a []Value value. +// +// Note that many observability backends are not optimized to query, index, or +// aggregate complex attribute values. Complex values may also carry +// additional performance overhead. Prefer primitive values when +// possible. // -// If creating both a key and value at the same time, use the provided -// convenience function instead -- Slice(name, values...). +// If creating both a key and value at the same time, use the package-level +// [Slice] function. func (k Key) Slice(v ...Value) KeyValue { return KeyValue{ Key: k, @@ -139,6 +178,27 @@ func (k Key) Slice(v ...Value) KeyValue { } } +// Map returns a [KeyValue] for a []KeyValue value. +// +// Note that many observability backends are not optimized to query, index, or +// aggregate complex attribute values. Complex values may also carry +// additional performance overhead. Prefer primitive values when +// possible. +// +// Users should avoid providing duplicate keys; many receivers handle maps +// containing duplicate keys unpredictably. +// +// The order of v is not preserved. +// +// If creating both a key and value at the same time, use the package-level [Map] +// function. +func (k Key) Map(v ...KeyValue) KeyValue { + return KeyValue{ + Key: k, + Value: MapValue(v...), + } +} + // Defined reports whether the key is not empty. func (k Key) Defined() bool { return len(k) != 0 diff --git a/vendor/go.opentelemetry.io/otel/attribute/kv.go b/vendor/go.opentelemetry.io/otel/attribute/kv.go index eeb76a134..c4f0dd928 100644 --- a/vendor/go.opentelemetry.io/otel/attribute/kv.go +++ b/vendor/go.opentelemetry.io/otel/attribute/kv.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package attribute // import "go.opentelemetry.io/otel/attribute" +package attribute import ( "fmt" @@ -18,66 +18,120 @@ func (kv KeyValue) Valid() bool { return kv.Key.Defined() } -// Bool creates a KeyValue with a BOOL Value type. +// Bool returns a [KeyValue] for a bool value. func Bool(k string, v bool) KeyValue { return Key(k).Bool(v) } -// BoolSlice creates a KeyValue with a BOOLSLICE Value type. +// BoolSlice returns a [KeyValue] for a []bool value. +// +// Note that many observability backends are not optimized to query, index, or +// aggregate complex attribute values. Complex values may also carry +// additional performance overhead. Prefer primitive values when +// possible. func BoolSlice(k string, v []bool) KeyValue { return Key(k).BoolSlice(v) } -// Int creates a KeyValue with an INT64 Value type. +// Int returns a [KeyValue] for an int value. +// +// It is provided as a convenience for [Int64]. func Int(k string, v int) KeyValue { return Key(k).Int(v) } -// IntSlice creates a KeyValue with an INT64SLICE Value type. +// IntSlice returns a [KeyValue] for a []int value. +// +// It is provided as a convenience for [Int64Slice]. +// +// Note that many observability backends are not optimized to query, index, or +// aggregate complex attribute values. Complex values may also carry +// additional performance overhead. Prefer primitive values when +// possible. func IntSlice(k string, v []int) KeyValue { return Key(k).IntSlice(v) } -// Int64 creates a KeyValue with an INT64 Value type. +// Int64 returns a [KeyValue] for an int64 value. func Int64(k string, v int64) KeyValue { return Key(k).Int64(v) } -// Int64Slice creates a KeyValue with an INT64SLICE Value type. +// Int64Slice returns a [KeyValue] for a []int64 value. +// +// Note that many observability backends are not optimized to query, index, or +// aggregate complex attribute values. Complex values may also carry +// additional performance overhead. Prefer primitive values when +// possible. func Int64Slice(k string, v []int64) KeyValue { return Key(k).Int64Slice(v) } -// Float64 creates a KeyValue with a FLOAT64 Value type. +// Float64 returns a [KeyValue] for a float64 value. func Float64(k string, v float64) KeyValue { return Key(k).Float64(v) } -// Float64Slice creates a KeyValue with a FLOAT64SLICE Value type. +// Float64Slice returns a [KeyValue] for a []float64 value. +// +// Note that many observability backends are not optimized to query, index, or +// aggregate complex attribute values. Complex values may also carry +// additional performance overhead. Prefer primitive values when +// possible. func Float64Slice(k string, v []float64) KeyValue { return Key(k).Float64Slice(v) } -// String creates a KeyValue with a STRING Value type. +// String returns a [KeyValue] for a string value. func String(k, v string) KeyValue { return Key(k).String(v) } -// StringSlice creates a KeyValue with a STRINGSLICE Value type. +// StringSlice returns a [KeyValue] for a []string value. +// +// Note that many observability backends are not optimized to query, index, or +// aggregate complex attribute values. Complex values may also carry +// additional performance overhead. Prefer primitive values when +// possible. func StringSlice(k string, v []string) KeyValue { return Key(k).StringSlice(v) } -// ByteSlice creates a KeyValue with a BYTESLICE Value type. +// ByteSlice returns a [KeyValue] for a []byte value. +// +// Note that many observability backends are not optimized to query, index, or +// aggregate complex attribute values. Complex values may also carry +// additional performance overhead. Prefer primitive values when +// possible. func ByteSlice(k string, v []byte) KeyValue { return Key(k).ByteSlice(v) } -// Slice creates a KeyValue with a SLICE Value type. +// Slice returns a [KeyValue] for a []Value value. +// +// Note that many observability backends are not optimized to query, index, or +// aggregate complex attribute values. Complex values may also carry +// additional performance overhead. Prefer primitive values when +// possible. func Slice(k string, v ...Value) KeyValue { return Key(k).Slice(v...) } +// Map returns a [KeyValue] for a []KeyValue value. +// +// Note that many observability backends are not optimized to query, index, or +// aggregate complex attribute values. Complex values may also carry +// additional performance overhead. Prefer primitive values when +// possible. +// +// Users should avoid providing duplicate keys; many receivers handle maps +// containing duplicate keys unpredictably. +// +// The order of v is not preserved. +func Map(k string, v ...KeyValue) KeyValue { + return Key(k).Map(v...) +} + // Stringer creates a new key-value pair with a passed name and a string // value generated by the passed Stringer interface. func Stringer(k string, v fmt.Stringer) KeyValue { diff --git a/vendor/go.opentelemetry.io/otel/attribute/rawhelpers.go b/vendor/go.opentelemetry.io/otel/attribute/rawhelpers.go index 5791c6e7a..939e46f90 100644 --- a/vendor/go.opentelemetry.io/otel/attribute/rawhelpers.go +++ b/vendor/go.opentelemetry.io/otel/attribute/rawhelpers.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package attribute // import "go.opentelemetry.io/otel/attribute" +package attribute import ( "math" diff --git a/vendor/go.opentelemetry.io/otel/attribute/set.go b/vendor/go.opentelemetry.io/otel/attribute/set.go index a4b6ce81d..56a70a9f6 100644 --- a/vendor/go.opentelemetry.io/otel/attribute/set.go +++ b/vendor/go.opentelemetry.io/otel/attribute/set.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package attribute // import "go.opentelemetry.io/otel/attribute" +package attribute import ( "cmp" @@ -313,6 +313,9 @@ func filteredToFront(slice []KeyValue, keep Filter) int { // Filter returns a filtered copy of this Set. See the documentation for // NewSetWithSortableFiltered for more details. func (l *Set) Filter(re Filter) (Set, []KeyValue) { + if l == nil { + return emptySet, nil + } if re == nil { return *l, nil } diff --git a/vendor/go.opentelemetry.io/otel/attribute/type_string.go b/vendor/go.opentelemetry.io/otel/attribute/type_string.go index dbc01d324..ab5da2288 100644 --- a/vendor/go.opentelemetry.io/otel/attribute/type_string.go +++ b/vendor/go.opentelemetry.io/otel/attribute/type_string.go @@ -19,11 +19,12 @@ func _() { _ = x[STRINGSLICE-8] _ = x[BYTESLICE-9] _ = x[SLICE-10] + _ = x[MAP-11] } -const _Type_name = "EMPTYBOOLINT64FLOAT64STRINGBOOLSLICEINT64SLICEFLOAT64SLICESTRINGSLICEBYTESLICESLICE" +const _Type_name = "EMPTYBOOLINT64FLOAT64STRINGBOOLSLICEINT64SLICEFLOAT64SLICESTRINGSLICEBYTESLICESLICEMAP" -var _Type_index = [...]uint8{0, 5, 9, 14, 21, 27, 36, 46, 58, 69, 78, 83} +var _Type_index = [...]uint8{0, 5, 9, 14, 21, 27, 36, 46, 58, 69, 78, 83, 86} func (i Type) String() string { idx := int(i) - 0 diff --git a/vendor/go.opentelemetry.io/otel/attribute/value.go b/vendor/go.opentelemetry.io/otel/attribute/value.go index 0529fefae..07a0353a1 100644 --- a/vendor/go.opentelemetry.io/otel/attribute/value.go +++ b/vendor/go.opentelemetry.io/otel/attribute/value.go @@ -1,14 +1,16 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package attribute // import "go.opentelemetry.io/otel/attribute" +package attribute import ( + "cmp" "encoding/base64" "encoding/json" "fmt" "math" "reflect" + "slices" "strconv" "strings" "unicode/utf8" @@ -18,10 +20,10 @@ import ( //go:generate stringer -type=Type -// Type describes the type of the data Value holds. +// Type describes the kind of data a [Value] holds. type Type int // nolint: revive // redefines builtin Type. -// Value represents the value part in key-value pairs. +// Value represents the value in key-value pairs. // // Note that the zero value is a valid empty value. type Value struct { @@ -32,35 +34,40 @@ type Value struct { } const ( - // EMPTY is used for a Value with no value set. + // EMPTY identifies a Value with no data. EMPTY Type = iota - // BOOL is a boolean Type Value. + // BOOL identifies a Value containing a bool. BOOL - // INT64 is a 64-bit signed integral Type Value. + // INT64 identifies a Value containing an int64. INT64 - // FLOAT64 is a 64-bit floating point Type Value. + // FLOAT64 identifies a Value containing a float64. FLOAT64 - // STRING is a string Type Value. + // STRING identifies a Value containing a string. STRING - // BOOLSLICE is a slice of booleans Type Value. + // BOOLSLICE identifies a Value containing a []bool. BOOLSLICE - // INT64SLICE is a slice of 64-bit signed integral numbers Type Value. + // INT64SLICE identifies a Value containing a []int64. INT64SLICE - // FLOAT64SLICE is a slice of 64-bit floating point numbers Type Value. + // FLOAT64SLICE identifies a Value containing a []float64. FLOAT64SLICE - // STRINGSLICE is a slice of strings Type Value. + // STRINGSLICE identifies a Value containing a []string. STRINGSLICE - // BYTESLICE is a slice of bytes Type Value. + // BYTESLICE identifies a Value containing a []byte. BYTESLICE - // SLICE is a slice of Value Type values. + // SLICE identifies a Value containing a []Value. SLICE + // MAP identifies a Value containing a []KeyValue representation of a map. + // + // Note that MAP values may contain duplicate keys if duplicate keys are + // provided when creating the value. + MAP // INVALID is used for a Value with no value set. // // Deprecated: Use EMPTY instead as an empty value is a valid value. INVALID = EMPTY ) -// BoolValue creates a BOOL Value. +// BoolValue returns a [Value] for a bool value. func BoolValue(v bool) Value { return Value{ vtype: BOOL, @@ -68,17 +75,31 @@ func BoolValue(v bool) Value { } } -// BoolSliceValue creates a BOOLSLICE Value. +// BoolSliceValue returns a [Value] for a []bool value. +// +// Note that many observability backends are not optimized to query, index, or +// aggregate complex attribute values. Complex values may also carry +// additional performance overhead. Prefer primitive values when +// possible. func BoolSliceValue(v []bool) Value { return Value{vtype: BOOLSLICE, slice: attribute.SliceValue(v)} } -// IntValue creates an INT64 Value. +// IntValue returns a [Value] for an int value. +// +// It is provided as a convenience for [Int64Value]. func IntValue(v int) Value { return Int64Value(int64(v)) } -// IntSliceValue creates an INT64SLICE Value. +// IntSliceValue returns a [Value] for a []int value. +// +// It is provided as a convenience for [Int64SliceValue]. +// +// Note that many observability backends are not optimized to query, index, or +// aggregate complex attribute values. Complex values may also carry +// additional performance overhead. Prefer primitive values when +// possible. func IntSliceValue(v []int) Value { val := Value{vtype: INT64SLICE} @@ -104,7 +125,7 @@ func IntSliceValue(v []int) Value { return val } -// Int64Value creates an INT64 Value. +// Int64Value returns a [Value] for an int64 value. func Int64Value(v int64) Value { return Value{ vtype: INT64, @@ -112,12 +133,17 @@ func Int64Value(v int64) Value { } } -// Int64SliceValue creates an INT64SLICE Value. +// Int64SliceValue returns a [Value] for a []int64 value. +// +// Note that many observability backends are not optimized to query, index, or +// aggregate complex attribute values. Complex values may also carry +// additional performance overhead. Prefer primitive values when +// possible. func Int64SliceValue(v []int64) Value { return Value{vtype: INT64SLICE, slice: attribute.SliceValue(v)} } -// Float64Value creates a FLOAT64 Value. +// Float64Value returns a [Value] for a float64 value. func Float64Value(v float64) Value { return Value{ vtype: FLOAT64, @@ -125,12 +151,17 @@ func Float64Value(v float64) Value { } } -// Float64SliceValue creates a FLOAT64SLICE Value. +// Float64SliceValue returns a [Value] for a []float64 value. +// +// Note that many observability backends are not optimized to query, index, or +// aggregate complex attribute values. Complex values may also carry +// additional performance overhead. Prefer primitive values when +// possible. func Float64SliceValue(v []float64) Value { return Value{vtype: FLOAT64SLICE, slice: attribute.SliceValue(v)} } -// StringValue creates a STRING Value. +// StringValue returns a [Value] for a string value. func StringValue(v string) Value { return Value{ vtype: STRING, @@ -138,12 +169,22 @@ func StringValue(v string) Value { } } -// StringSliceValue creates a STRINGSLICE Value. +// StringSliceValue returns a [Value] for a []string value. +// +// Note that many observability backends are not optimized to query, index, or +// aggregate complex attribute values. Complex values may also carry +// additional performance overhead. Prefer primitive values when +// possible. func StringSliceValue(v []string) Value { return Value{vtype: STRINGSLICE, slice: attribute.SliceValue(v)} } -// ByteSliceValue creates a BYTESLICE Value. +// ByteSliceValue returns a [Value] for a []byte value. +// +// Note that many observability backends are not optimized to query, index, or +// aggregate complex attribute values. Complex values may also carry +// additional performance overhead. Prefer primitive values when +// possible. func ByteSliceValue(v []byte) Value { return Value{ vtype: BYTESLICE, @@ -151,12 +192,32 @@ func ByteSliceValue(v []byte) Value { } } -// SliceValue creates a SLICE Value. +// SliceValue returns a [Value] for a []Value value. +// +// Note that many observability backends are not optimized to query, index, or +// aggregate complex attribute values. Complex values may also carry +// additional performance overhead. Prefer primitive values when +// possible. func SliceValue(v ...Value) Value { return Value{vtype: SLICE, slice: sliceValue(v)} } -// Type returns a type of the Value. +// MapValue returns a [Value] for a []KeyValue value. +// +// Note that many observability backends are not optimized to query, index, or +// aggregate complex attribute values. Complex values may also carry +// additional performance overhead. Prefer primitive values when +// possible. +// +// Users should avoid providing duplicate keys; many receivers handle maps +// containing duplicate keys unpredictably. +// +// The order of v is not preserved. +func MapValue(v ...KeyValue) Value { + return Value{vtype: MAP, slice: mapValue(v)} +} + +// Type returns v's type. func (v Value) Type() Type { return v.vtype } @@ -277,6 +338,53 @@ func asValueSliceReflect(v any) []Value { return cpy } +// AsMap returns the []KeyValue value. Make sure that the Value's type is +// MAP. +// +// The returned slice is sorted by key and may differ from the order +// provided when creating the map value. +// +// The returned slice may contain duplicate keys if duplicate keys were +// provided when creating the map value. Callers should not assume the returned +// keys are unique. +func (v Value) AsMap() []KeyValue { + if v.vtype != MAP { + return nil + } + return v.asMap() +} + +func (v Value) asMap() []KeyValue { + switch vals := v.slice.(type) { + case [0]KeyValue: + return []KeyValue{} + case [1]KeyValue: + return []KeyValue{vals[0]} + case [2]KeyValue: + return []KeyValue{vals[0], vals[1]} + case [3]KeyValue: + return []KeyValue{vals[0], vals[1], vals[2]} + case [4]KeyValue: + return []KeyValue{vals[0], vals[1], vals[2], vals[3]} + case [5]KeyValue: + return []KeyValue{vals[0], vals[1], vals[2], vals[3], vals[4]} + default: + return asKeyValueSliceReflect(v.slice) + } +} + +func asKeyValueSliceReflect(v any) []KeyValue { + rv := reflect.ValueOf(v) + if !rv.IsValid() || rv.Kind() != reflect.Array || rv.Type().Elem() != reflect.TypeFor[KeyValue]() { + return nil + } + cpy := make([]KeyValue, rv.Len()) + if len(cpy) > 0 { + _ = reflect.Copy(reflect.ValueOf(cpy), rv) + } + return cpy +} + // AsByteSlice returns the bytes value. Make sure that the Value's type // is BYTESLICE. func (v Value) AsByteSlice() []byte { @@ -315,6 +423,8 @@ func (v Value) AsInterface() any { return v.asByteSlice() case SLICE: return v.asSlice() + case MAP: + return v.asMap() case EMPTY: return nil } @@ -327,10 +437,10 @@ func (v Value) AsInterface() any { // Strings are returned as-is without JSON quoting, booleans and integers use // JSON literals, floating-point values use JSON numbers except that NaN and // ±Inf are rendered as NaN, Infinity, and -Infinity, byte slices are -// base64-encoded, empty values are the empty string, and slices are encoded as -// JSON arrays. String, byte, and special floating-point values inside arrays -// are encoded as JSON strings, and empty values inside arrays are encoded as -// null. +// base64-encoded, empty values are the empty string, slices are encoded as JSON +// arrays, and maps are encoded as JSON objects. String, byte, and special +// floating-point values inside arrays and maps are encoded as JSON strings, and +// empty values inside arrays and maps are encoded as null. // // [OpenTelemetry AnyValue representation for non-OTLP protocols]: https://opentelemetry.io/docs/specs/otel/common/#anyvalue-representation-for-non-otlp-protocols func (v Value) String() string { @@ -355,6 +465,8 @@ func (v Value) String() string { return formatByteSlice(v.stringly) case SLICE: return formatValueSliceValue(v.slice) + case MAP: + return formatMapValue(v.slice) case EMPTY: return "" default: @@ -399,6 +511,8 @@ func (v Value) Emit() string { return formatByteSlice(v.stringly) case SLICE: return formatValueSliceValue(v.slice) + case MAP: + return formatMapValue(v.slice) case EMPTY: return "" default: @@ -439,6 +553,47 @@ func sliceValueReflect(v []Value) any { return cp.Interface() } +func mapValue(v []KeyValue) any { + switch len(v) { + case 0: + return [0]KeyValue{} + case 1: + return [1]KeyValue{v[0]} + case 2: + vals := [2]KeyValue{v[0], v[1]} + sortKeyValues(vals[:]) + return vals + case 3: + vals := [3]KeyValue{v[0], v[1], v[2]} + sortKeyValues(vals[:]) + return vals + case 4: + vals := [4]KeyValue{v[0], v[1], v[2], v[3]} + sortKeyValues(vals[:]) + return vals + case 5: + vals := [5]KeyValue{v[0], v[1], v[2], v[3], v[4]} + sortKeyValues(vals[:]) + return vals + default: + return mapValueReflect(v) + } +} + +func mapValueReflect(v []KeyValue) any { + cp := reflect.New(reflect.ArrayOf(len(v), reflect.TypeFor[KeyValue]())).Elem() + reflect.Copy(cp, reflect.ValueOf(v)) + vals := cp.Slice(0, len(v)).Interface().([]KeyValue) + sortKeyValues(vals) + return cp.Interface() +} + +func sortKeyValues(vals []KeyValue) { + slices.SortStableFunc(vals, func(a, b KeyValue) int { + return cmp.Compare(a.Key, b.Key) + }) +} + func formatBoolSliceValue(v any) string { switch vals := v.(type) { case [0]bool: @@ -807,6 +962,37 @@ func formatValueSliceReflect(v any) string { return b.String() } +func formatMapValue(v any) string { + switch vals := v.(type) { + case [0]KeyValue: + return "{}" + case [1]KeyValue: + return formatMap(vals[:]) + case [2]KeyValue: + return formatMap(vals[:]) + case [3]KeyValue: + return formatMap(vals[:]) + case [4]KeyValue: + return formatMap(vals[:]) + case [5]KeyValue: + return formatMap(vals[:]) + default: + return formatMapReflect(v) + } +} + +func formatMap(vals []KeyValue) string { + var b strings.Builder + appendMap(&b, vals) + return b.String() +} + +func formatMapReflect(v any) string { + var b strings.Builder + appendMapReflect(&b, reflect.ValueOf(v)) + return b.String() +} + func appendValueSliceValue(dst *strings.Builder, v any) { switch vals := v.(type) { case [0]Value: @@ -852,6 +1038,68 @@ func appendValueSliceReflect(dst *strings.Builder, rv reflect.Value) { _ = dst.WriteByte(']') } +func appendMapValue(dst *strings.Builder, v any) { + switch vals := v.(type) { + case [0]KeyValue: + _, _ = dst.WriteString("{}") + case [1]KeyValue: + appendMap(dst, vals[:]) + case [2]KeyValue: + appendMap(dst, vals[:]) + case [3]KeyValue: + appendMap(dst, vals[:]) + case [4]KeyValue: + appendMap(dst, vals[:]) + case [5]KeyValue: + appendMap(dst, vals[:]) + default: + appendMapReflect(dst, reflect.ValueOf(v)) + } +} + +func appendMap(dst *strings.Builder, vals []KeyValue) { + // Estimate 32 bytes per value for small values, plus key quotes, colon, + // and commas. Escaped keys and larger values grow the builder as needed. + size := len("{}") + len(vals)*commaLen + len(vals)*32 + for _, val := range vals { + size += len(val.Key) + len(`"":`) + } + + dst.Grow(size) + _ = dst.WriteByte('{') + for i, val := range vals { + if i > 0 { + _ = dst.WriteByte(',') + } + appendJSONString(dst, string(val.Key)) + _ = dst.WriteByte(':') + appendJSONValue(dst, val.Value) + } + _ = dst.WriteByte('}') +} + +func appendMapReflect(dst *strings.Builder, rv reflect.Value) { + // Estimate 32 bytes per value for small values, plus key quotes, colon, + // and commas. Escaped keys and larger values grow the builder as needed. + size := len("{}") + rv.Len()*commaLen + rv.Len()*32 + for i := 0; i < rv.Len(); i++ { + size += len(rv.Index(i).Field(0).String()) + len(`"":`) + } + + dst.Grow(size) + _ = dst.WriteByte('{') + for i := 0; i < rv.Len(); i++ { + if i > 0 { + _ = dst.WriteByte(',') + } + val := rv.Index(i).Interface().(KeyValue) + appendJSONString(dst, string(val.Key)) + _ = dst.WriteByte(':') + appendJSONValue(dst, val.Value) + } + _ = dst.WriteByte('}') +} + func appendJSONValue(dst *strings.Builder, v Value) { switch v.Type() { case BOOL: @@ -894,6 +1142,8 @@ func appendJSONValue(dst *strings.Builder, v Value) { _ = dst.WriteByte('"') case SLICE: appendValueSliceValue(dst, v.slice) + case MAP: + appendMapValue(dst, v.slice) case EMPTY: _, _ = dst.WriteString("null") default: diff --git a/vendor/go.opentelemetry.io/otel/baggage/baggage.go b/vendor/go.opentelemetry.io/otel/baggage/baggage.go index b290c6d6c..25c739d08 100644 --- a/vendor/go.opentelemetry.io/otel/baggage/baggage.go +++ b/vendor/go.opentelemetry.io/otel/baggage/baggage.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package baggage // import "go.opentelemetry.io/otel/baggage" +package baggage import ( "errors" diff --git a/vendor/go.opentelemetry.io/otel/baggage/context.go b/vendor/go.opentelemetry.io/otel/baggage/context.go index a572461a0..4d09b59aa 100644 --- a/vendor/go.opentelemetry.io/otel/baggage/context.go +++ b/vendor/go.opentelemetry.io/otel/baggage/context.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package baggage // import "go.opentelemetry.io/otel/baggage" +package baggage import ( "context" diff --git a/vendor/go.opentelemetry.io/otel/baggage/doc.go b/vendor/go.opentelemetry.io/otel/baggage/doc.go index b51d87cab..74d3a8709 100644 --- a/vendor/go.opentelemetry.io/otel/baggage/doc.go +++ b/vendor/go.opentelemetry.io/otel/baggage/doc.go @@ -6,4 +6,4 @@ Package baggage provides functionality for storing and retrieving baggage items in Go context. For propagating the baggage, see the go.opentelemetry.io/otel/propagation package. */ -package baggage // import "go.opentelemetry.io/otel/baggage" +package baggage diff --git a/vendor/go.opentelemetry.io/otel/codes/codes.go b/vendor/go.opentelemetry.io/otel/codes/codes.go index d48847ed8..9355545a8 100644 --- a/vendor/go.opentelemetry.io/otel/codes/codes.go +++ b/vendor/go.opentelemetry.io/otel/codes/codes.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package codes // import "go.opentelemetry.io/otel/codes" +package codes import ( "encoding/json" @@ -81,7 +81,7 @@ func (c *Code) UnmarshalJSON(b []byte) error { case float64: if ci, err := strconv.ParseUint(string(b), 10, 32); err == nil { if ci >= maxCode { - return fmt.Errorf("invalid code: %q", ci) + return fmt.Errorf("invalid code: %d", ci) } *c = Code(ci) // nolint: gosec // Bit size of 32 check above. diff --git a/vendor/go.opentelemetry.io/otel/codes/doc.go b/vendor/go.opentelemetry.io/otel/codes/doc.go index ee8db448b..1073f6543 100644 --- a/vendor/go.opentelemetry.io/otel/codes/doc.go +++ b/vendor/go.opentelemetry.io/otel/codes/doc.go @@ -7,4 +7,4 @@ Package codes defines the canonical error codes used by OpenTelemetry. It conforms to [the OpenTelemetry specification](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.20.0/specification/trace/api.md#set-status). */ -package codes // import "go.opentelemetry.io/otel/codes" +package codes diff --git a/vendor/go.opentelemetry.io/otel/dependencies.Dockerfile b/vendor/go.opentelemetry.io/otel/dependencies.Dockerfile index 74fa510bc..20eecba40 100644 --- a/vendor/go.opentelemetry.io/otel/dependencies.Dockerfile +++ b/vendor/go.opentelemetry.io/otel/dependencies.Dockerfile @@ -1,4 +1,4 @@ # This is a renovate-friendly source of Docker images. FROM python:3.13.6-slim-bullseye@sha256:e98b521460ee75bca92175c16247bdf7275637a8faaeb2bcfa19d879ae5c4b9a AS python -FROM otel/weaver:v0.23.0@sha256:7984ecb55b859eb3034ae9d836c4eeda137e2bdd0873b7ba2bb6c3d24d6ff457 AS weaver +FROM otel/weaver:v0.25.1@sha256:9ad46ca9cd4fa5974b121f886aa3e9946a8ef8ea905001a96c018d21f9db87ca AS weaver FROM avtodev/markdown-lint:v1@sha256:6aeedc2f49138ce7a1cd0adffc1b1c0321b841dc2102408967d9301c031949ee AS markdown diff --git a/vendor/go.opentelemetry.io/otel/doc.go b/vendor/go.opentelemetry.io/otel/doc.go index 921f85961..92b7a0566 100644 --- a/vendor/go.opentelemetry.io/otel/doc.go +++ b/vendor/go.opentelemetry.io/otel/doc.go @@ -22,4 +22,4 @@ To read more about logs, see go.opentelemetry.io/otel/log. To read more about propagation, see go.opentelemetry.io/otel/propagation and go.opentelemetry.io/otel/baggage. */ -package otel // import "go.opentelemetry.io/otel" +package otel diff --git a/vendor/go.opentelemetry.io/otel/error_handler.go b/vendor/go.opentelemetry.io/otel/error_handler.go index 67414c71e..06fd49da2 100644 --- a/vendor/go.opentelemetry.io/otel/error_handler.go +++ b/vendor/go.opentelemetry.io/otel/error_handler.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package otel // import "go.opentelemetry.io/otel" +package otel // ErrorHandler handles irremediable events. type ErrorHandler interface { diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/client.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/client.go index 22b845053..ee6b018dd 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/client.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/client.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package otlpmetricgrpc // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc" +package otlpmetricgrpc import ( "context" diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/config.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/config.go index 47eb85e9f..8f6fec81f 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/config.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/config.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package otlpmetricgrpc // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc" +package otlpmetricgrpc import ( "fmt" diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/doc.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/doc.go index 62b05626f..938cb6a48 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/doc.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/doc.go @@ -84,4 +84,4 @@ the experimental features. [Explicit Bucket Histogram Aggregation]: https://github.com/open-telemetry/opentelemetry-specification/blob/v1.26.0/specification/metrics/sdk.md#explicit-bucket-histogram-aggregation [Base2 Exponential Bucket Histogram Aggregation]: https://github.com/open-telemetry/opentelemetry-specification/blob/v1.26.0/specification/metrics/sdk.md#base2-exponential-bucket-histogram-aggregation */ -package otlpmetricgrpc // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc" +package otlpmetricgrpc diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/exporter.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/exporter.go index b567800e3..302c992ee 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/exporter.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/exporter.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package otlpmetricgrpc // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc" +package otlpmetricgrpc import ( "context" diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/counter/counter.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/counter/counter.go index df6b830d3..57c6acb78 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/counter/counter.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/counter/counter.go @@ -1,14 +1,14 @@ -// Code generated by gotmpl. DO NOT MODIFY. -// source: internal/shared/counter/counter.go.tmpl - // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/counter/counter.go.tmpl + // Package counter provides a simple counter for generating unique IDs. // // This package is used to generate unique IDs while allowing testing packages // to reset the counter. -package counter // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/counter" +package counter import "sync/atomic" diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/envconfig/envconfig.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/envconfig/envconfig.go index 2cd98b929..87764a695 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/envconfig/envconfig.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/envconfig/envconfig.go @@ -1,12 +1,12 @@ -// Code generated by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/envconfig/envconfig.go.tmpl - // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/otlp/envconfig/envconfig.go.tmpl + // Package envconfig provides functionality to parse configuration from // environment variables. -package envconfig // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/envconfig" +package envconfig import ( "crypto/tls" @@ -60,7 +60,7 @@ func WithString(n string, fn func(string)) func(e *EnvOptionsReader) { func WithBool(n string, fn func(bool)) ConfigFn { return func(e *EnvOptionsReader) { if v, ok := e.GetEnvValue(n); ok { - b := strings.ToLower(v) == "true" + b := strings.EqualFold(v, "true") fn(b) } } diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/gen.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/gen.go index c94f85ef4..df08789be 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/gen.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/gen.go @@ -2,12 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 // Package internal provides internal functionally for the otlpmetricgrpc package. -package internal // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal" +package internal //go:generate gotmpl --body=../../../../../internal/shared/otlp/partialsuccess.go.tmpl "--data={}" --out=partialsuccess.go //go:generate gotmpl --body=../../../../../internal/shared/otlp/partialsuccess_test.go.tmpl "--data={}" --out=partialsuccess_test.go -//go:generate gotmpl --body=../../../../../internal/shared/otlp/observ/target.go.tmpl "--data={ \"pkg\": \"observ\", \"pkg_path\": \"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/observ\" }" --out=observ/target.go +//go:generate gotmpl --body=../../../../../internal/shared/otlp/observ/target.go.tmpl "--data={ \"pkg\": \"observ\" }" --out=observ/target.go //go:generate gotmpl --body=../../../../../internal/shared/otlp/observ/target_test.go.tmpl "--data={ \"pkg\": \"observ\" }" --out=observ/target_test.go //go:generate gotmpl --body=../../../../../internal/shared/otlp/retry/retry.go.tmpl "--data={}" --out=retry/retry.go @@ -34,7 +34,7 @@ package internal // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/o //go:generate gotmpl --body=../../../../../internal/shared/otlp/otlpmetric/transform/metricdata.go.tmpl "--data={}" --out=transform/metricdata.go //go:generate gotmpl --body=../../../../../internal/shared/otlp/otlpmetric/transform/metricdata_test.go.tmpl "--data={}" --out=transform/metricdata_test.go -//go:generate gotmpl --body=../../../../../internal/shared/counter/counter.go.tmpl "--data={ \"pkg\": \"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/counter\" }" --out=counter/counter.go +//go:generate gotmpl --body=../../../../../internal/shared/counter/counter.go.tmpl "--data={}" --out=counter/counter.go //go:generate gotmpl --body=../../../../../internal/shared/counter/counter_test.go.tmpl "--data={}" --out=counter/counter_test.go //go:generate gotmpl --body=../../../../../internal/shared/x/x.go.tmpl "--data={ \"pkg\": \"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc\" }" --out=x/x.go diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/observ/instrumentation.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/observ/instrumentation.go index 2b4dbb5d8..a8ffd871b 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/observ/instrumentation.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/observ/instrumentation.go @@ -3,7 +3,7 @@ // Package observ provides self-observability metrics for OTLP metric exporters. // This is an experimental feature controlled by the x.Observability feature flag. -package observ // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/observ" +package observ import ( "context" @@ -17,8 +17,8 @@ import ( "go.opentelemetry.io/otel/internal/global" "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/sdk" - semconv "go.opentelemetry.io/otel/semconv/v1.41.0" - "go.opentelemetry.io/otel/semconv/v1.41.0/otelconv" + semconv "go.opentelemetry.io/otel/semconv/v1.43.0" + "go.opentelemetry.io/otel/semconv/v1.43.0/otelconv" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/observ/target.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/observ/target.go index 0be4501ec..3bd379882 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/observ/target.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/observ/target.go @@ -1,10 +1,10 @@ -// Code generated by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/observ/target.go.tmpl - // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package observ // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/observ" +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/otlp/observ/target.go.tmpl + +package observ import ( "errors" @@ -21,13 +21,13 @@ const ( ) // ParseCanonicalTarget parses a target string and returns the extracted host -// (domain address or IP), the target port, or an error. +// (domain name or IP address), the target port, or an error. // // If no port is specified, -1 is returned. // // If no host is specified, an empty string is returned. // -// The target string is expected to always have the form +// The target string must have the form // "://[authority]/". For example: // - "dns:///example.com:42" // - "dns://8.8.8.8/example.com:42" @@ -35,17 +35,16 @@ const ( // - "unix-abstract:///socket-name" // - "passthrough:///192.34.2.1:42" // -// The target is expected to come from the CanonicalTarget method of a gRPC -// Client. +// The target is expected to be returned by gRPC's ClientConn.CanonicalTarget +// method. func ParseCanonicalTarget(target string) (string, int, error) { const sep = "://" // Find scheme. Do not allocate the string by using url.Parse. - idx := strings.Index(target, sep) - if idx == -1 { + scheme, endpoint, found := strings.Cut(target, sep) + if !found { return "", -1, fmt.Errorf("invalid target %q: missing scheme", target) } - scheme, endpoint := target[:idx], target[idx+len(sep):] // Check for unix schemes. if scheme == schemeUnix || scheme == schemeUnixAbstract { @@ -61,7 +60,7 @@ func ParseCanonicalTarget(target string) (string, int, error) { return parseEndpoint(endpoint) } -// parseUnix parses unix socket targets. +// parseUnix parses Unix socket targets. func parseUnix(endpoint string) (string, int, error) { // Format: unix[-abstract]://path // @@ -71,8 +70,8 @@ func parseUnix(endpoint string) (string, int, error) { return endpoint, -1, nil } - // If there's no leading slash, it means there might be an authority - // Check for authority case (should error): "authority/path" + // If there is no leading slash, an authority might be present, which is + // invalid. Check for this case: "authority/path". if slashIdx := strings.Index(endpoint, "/"); slashIdx > 0 { return "", -1, fmt.Errorf("invalid (non-empty) authority: %s", endpoint[:slashIdx]) } @@ -98,8 +97,8 @@ func parseUnix(endpoint string) (string, int, error) { // - "[ipv6]:port" // - "[ipv6%zone]:port" // -// It returns the host or host%zone (domain address or IP), the port (or -1 if -// not specified), or an error if the input is not a valid. +// It returns the host or host%zone (domain name or IP address), the port (or +// -1 if not specified), or an error if the input is invalid. func parseEndpoint(endpoint string) (string, int, error) { // First check if the endpoint is just an IP address. if ip := parseIP(endpoint); ip != "" { diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/envconfig.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/envconfig.go index 7f947273b..700dc0d1c 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/envconfig.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/envconfig.go @@ -1,10 +1,10 @@ -// Code generated by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlpmetric/oconf/envconfig.go.tmpl - // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package oconf // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf" +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/otlp/otlpmetric/oconf/envconfig.go.tmpl + +package oconf import ( "crypto/tls" @@ -51,31 +51,37 @@ func getOptionsFromEnv() []GenericOption { tlsConf := &tls.Config{} DefaultEnvOptionsReader.Apply( envconfig.WithURL("ENDPOINT", func(u *url.URL) { - opts = append(opts, withEndpointScheme(u)) - opts = append(opts, newSplitOption(func(cfg Config) Config { - cfg.Metrics.Endpoint = u.Host - // For OTLP/HTTP endpoint URLs without a per-signal - // configuration, the passed endpoint is used as a base URL - // and the signals are sent to these paths relative to that. - cfg.Metrics.URLPath = path.Join(u.Path, DefaultMetricsPath) - return cfg - }, withEndpointForGRPC(u))) + opts = append( + opts, + withEndpointScheme(u), + newSplitOption(func(cfg Config) Config { + cfg.Metrics.Endpoint = u.Host + // For OTLP/HTTP endpoint URLs without a per-signal + // configuration, the passed endpoint is used as a base URL + // and the signals are sent to these paths relative to that. + cfg.Metrics.URLPath = path.Join(u.Path, DefaultMetricsPath) + return cfg + }, withEndpointForGRPC(u)), + ) }), envconfig.WithURL("METRICS_ENDPOINT", func(u *url.URL) { - opts = append(opts, withEndpointScheme(u)) - opts = append(opts, newSplitOption(func(cfg Config) Config { - cfg.Metrics.Endpoint = u.Host - // For endpoint URLs for OTLP/HTTP per-signal variables, the - // URL MUST be used as-is without any modification. The only - // exception is that if an URL contains no path part, the root - // path / MUST be used. - path := u.Path - if path == "" { - path = "/" - } - cfg.Metrics.URLPath = path - return cfg - }, withEndpointForGRPC(u))) + opts = append( + opts, + withEndpointScheme(u), + newSplitOption(func(cfg Config) Config { + cfg.Metrics.Endpoint = u.Host + // For endpoint URLs for OTLP/HTTP per-signal variables, the + // URL MUST be used as-is without any modification. The only + // exception is that if an URL contains no path part, the root + // path / MUST be used. + path := u.Path + if path == "" { + path = "/" + } + cfg.Metrics.URLPath = path + return cfg + }, withEndpointForGRPC(u)), + ) }), envconfig.WithCertPool("CERTIFICATE", func(p *x509.CertPool) { tlsConf.RootCAs = p }), envconfig.WithCertPool("METRICS_CERTIFICATE", func(p *x509.CertPool) { tlsConf.RootCAs = p }), @@ -152,7 +158,7 @@ func withInsecure(b bool) GenericOption { } func withTLSConfig(c *tls.Config, fn func(*tls.Config)) func(e *envconfig.EnvOptionsReader) { - return func(e *envconfig.EnvOptionsReader) { + return func(*envconfig.EnvOptionsReader) { if c.RootCAs != nil || len(c.Certificates) > 0 { fn(c) } diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options.go index b89d7eeb7..4b4f164e1 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options.go @@ -1,11 +1,11 @@ -// Code generated by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlpmetric/oconf/options.go.tmpl - // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/otlp/otlpmetric/oconf/options.go.tmpl + // Package oconf provides configuration for the otlpmetric exporters. -package oconf // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf" +package oconf import ( "crypto/tls" @@ -112,7 +112,7 @@ func NewHTTPConfig(opts ...HTTPOption) Config { // cleanPath returns a path with all spaces trimmed. If urlPath is empty, // defaultPath is returned instead. -func cleanPath(urlPath string, defaultPath string) string { +func cleanPath(urlPath, defaultPath string) string { tmp := strings.TrimSpace(urlPath) if tmp == "" || tmp == "." { return defaultPath @@ -148,7 +148,7 @@ func NewGRPCConfig(opts ...GRPCOption) Config { cfg.DialOptions = append(cfg.DialOptions, grpc.WithDefaultServiceConfig(cfg.ServiceConfig)) } // Prioritize GRPCCredentials over Insecure (passing both is an error). - if cfg.Metrics.GRPCCredentials != nil { + if cfg.Metrics.GRPCCredentials != nil { //nolint:gocritic // if-else is clearer than switch cfg.DialOptions = append(cfg.DialOptions, grpc.WithTransportCredentials(cfg.Metrics.GRPCCredentials)) } else if cfg.Metrics.Insecure { cfg.DialOptions = append(cfg.DialOptions, grpc.WithTransportCredentials(insecure.NewCredentials())) @@ -242,7 +242,7 @@ func (g *splitOption) ApplyHTTPOption(cfg Config) Config { func (splitOption) private() {} -func newSplitOption(httpFn func(cfg Config) Config, grpcFn func(cfg Config) Config) GenericOption { +func newSplitOption(httpFn, grpcFn func(cfg Config) Config) GenericOption { return &splitOption{httpFn: httpFn, grpcFn: grpcFn} } @@ -295,6 +295,11 @@ func WithEndpointURL(v string) GenericOption { cfg.Metrics.Endpoint = u.Host cfg.Metrics.URLPath = u.Path + if cfg.Metrics.URLPath == "" { + // For HTTP exporters, a URL without a path targets the root path. Set it explicitly so the default signal + // path is not appended by cleanPath. (URLPath is ignored by gRPC exporters.) + cfg.Metrics.URLPath = "/" + } cfg.Metrics.Insecure = u.Scheme != "https" return cfg diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/optiontypes.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/optiontypes.go index c18a6b1f2..79f77841a 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/optiontypes.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/optiontypes.go @@ -1,10 +1,10 @@ -// Code generated by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlpmetric/oconf/optiontypes.go.tmpl - // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package oconf // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf" +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/otlp/otlpmetric/oconf/optiontypes.go.tmpl + +package oconf import "time" diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/tls.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/tls.go index e4547b3a6..4ed82885a 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/tls.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/tls.go @@ -1,10 +1,10 @@ -// Code generated by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlpmetric/oconf/tls.go.tmpl - // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package oconf // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf" +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/otlp/otlpmetric/oconf/tls.go.tmpl + +package oconf import ( "crypto/tls" diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/partialsuccess.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/partialsuccess.go index 243abcb17..1138f2e71 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/partialsuccess.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/partialsuccess.go @@ -1,10 +1,10 @@ -// Code generated by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/partialsuccess.go - // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package internal // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal" +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/otlp/partialsuccess.go + +package internal import "fmt" @@ -41,7 +41,7 @@ func (ps PartialSuccess) As(target any) bool { } // Is supports the errors.Is() interface. -func (ps PartialSuccess) Is(err error) bool { +func (PartialSuccess) Is(err error) bool { _, ok := err.(PartialSuccess) return ok } diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/retry/retry.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/retry/retry.go index c14e5ae78..468c7c8eb 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/retry/retry.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/retry/retry.go @@ -1,13 +1,13 @@ -// Code generated by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/retry/retry.go.tmpl - // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/otlp/retry/retry.go.tmpl + // Package retry provides request retry functionality that can perform // configurable exponential backoff for transient errors and honor any // explicit throttle responses received. -package retry // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/retry" +package retry import ( "context" @@ -17,7 +17,7 @@ import ( "github.com/cenkalti/backoff/v5" ) -// DefaultConfig are the recommended defaults to use. +// DefaultConfig is the recommended default configuration. var DefaultConfig = Config{ Enabled: true, InitialInterval: 5 * time.Second, @@ -25,42 +25,40 @@ var DefaultConfig = Config{ MaxElapsedTime: time.Minute, } -// Config defines configuration for retrying batches in case of export failure -// using an exponential backoff. +// Config defines configuration for retrying batches after an export failure +// using exponential backoff. type Config struct { - // Enabled indicates whether to not retry sending batches in case of - // export failure. + // Enabled indicates whether to retry sending batches after an export + // failure. Enabled bool - // InitialInterval the time to wait after the first failure before + // InitialInterval is the time to wait after the first failure before // retrying. InitialInterval time.Duration - // MaxInterval is the upper bound on backoff interval. Once this value is - // reached the delay between consecutive retries will always be - // `MaxInterval`. + // MaxInterval is the upper bound on the backoff interval before + // randomization. Once this value is reached, the base interval remains at + // MaxInterval. MaxInterval time.Duration // MaxElapsedTime is the maximum amount of time (including retries) spent - // trying to send a request/batch. Once this value is reached, the data - // is discarded. + // trying to send a request/batch. Once this value is reached, retrying stops. MaxElapsedTime time.Duration } // RequestFunc wraps a request with retry logic. type RequestFunc func(context.Context, func(context.Context) error) error -// EvaluateFunc returns if an error is retry-able and if an explicit throttle -// duration should be honored that was included in the error. +// EvaluateFunc reports whether an error is retryable and returns any explicit +// throttle duration to honor. // -// The function must return true if the error argument is retry-able, -// otherwise it must return false for the first return parameter. +// The function must return true as its first return value if the error +// argument is retryable; otherwise, it must return false. // -// The function must return a non-zero time.Duration if the error contains -// explicit throttle duration that should be honored, otherwise it must return -// a zero valued time.Duration. +// The function must return a nonzero time.Duration if the error contains an +// explicit throttle duration that should be honored; otherwise, it must return +// the zero value for time.Duration. type EvaluateFunc func(error) (bool, time.Duration) -// RequestFunc returns a RequestFunc using the evaluate function to determine -// if requests can be retried and based on the exponential backoff -// configuration of c. +// RequestFunc returns a RequestFunc that uses evaluate to determine whether +// requests can be retried and uses c to configure exponential backoff. func (c Config) RequestFunc(evaluate EvaluateFunc) RequestFunc { if !c.Enabled { return func(ctx context.Context, fn func(context.Context) error) error { @@ -96,7 +94,7 @@ func (c Config) RequestFunc(evaluate EvaluateFunc) RequestFunc { // Check if context is canceled before attempting to wait and retry. if ctx.Err() != nil { - return fmt.Errorf("%w: %w", ctx.Err(), err) + return fmt.Errorf("%w: %w", context.Cause(ctx), err) } if maxElapsedTime != 0 && time.Since(startTime) > maxElapsedTime { @@ -119,12 +117,12 @@ func (c Config) RequestFunc(evaluate EvaluateFunc) RequestFunc { } } -// Allow override for testing. +// waitFunc can be overridden for testing. var waitFunc = wait -// wait takes the caller's context, and the amount of time to wait. It will -// return nil if the timer fires before or at the same time as the context's -// deadline. This indicates that the call can be retried. +// wait blocks until delay elapses or ctx is done. If both happen +// simultaneously, wait favors the elapsed delay and returns nil to indicate +// that the call can be retried. func wait(ctx context.Context, delay time.Duration) error { timer := time.NewTimer(delay) defer timer.Stop() diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/transform/attribute.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/transform/attribute.go index 96420d421..9fea51b46 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/transform/attribute.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/transform/attribute.go @@ -1,14 +1,15 @@ -// Code generated by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlpmetric/transform/attribute.go.tmpl - // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package transform // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/transform" +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/otlp/otlpmetric/transform/attribute.go.tmpl + +package transform import ( - "go.opentelemetry.io/otel/attribute" cpb "go.opentelemetry.io/proto/otlp/common/v1" + + "go.opentelemetry.io/otel/attribute" ) // AttrIter transforms an attribute iterator into OTLP key-values. @@ -91,6 +92,12 @@ func Value(v attribute.Value) *cpb.AnyValue { Values: attrValues(v.AsSlice()), }, } + case attribute.MAP: + av.Value = &cpb.AnyValue_KvlistValue{ + KvlistValue: &cpb.KeyValueList{ + Values: KeyValues(v.AsMap()), + }, + } case attribute.STRINGSLICE: av.Value = &cpb.AnyValue_ArrayValue{ ArrayValue: &cpb.ArrayValue{ diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/transform/error.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/transform/error.go index f03bfec41..728502222 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/transform/error.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/transform/error.go @@ -1,10 +1,10 @@ -// Code generated by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlpmetric/transform/error.go.tmpl - // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package transform // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/transform" +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/otlp/otlpmetric/transform/error.go.tmpl + +package transform import ( "errors" diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/transform/metricdata.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/transform/metricdata.go index 9c156e91b..6c07896a8 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/transform/metricdata.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/transform/metricdata.go @@ -1,21 +1,22 @@ -// Code generated by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlpmetric/transform/metricdata.go.tmpl - // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/otlp/otlpmetric/transform/metricdata.go.tmpl + // Package transform provides transformation functionality from the // sdk/metric/metricdata data-types into OTLP data-types. -package transform // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/transform" +package transform import ( "fmt" "time" - "go.opentelemetry.io/otel/sdk/metric/metricdata" cpb "go.opentelemetry.io/proto/otlp/common/v1" mpb "go.opentelemetry.io/proto/otlp/metrics/v1" rpb "go.opentelemetry.io/proto/otlp/resource/v1" + + "go.opentelemetry.io/otel/sdk/metric/metricdata" ) // ResourceMetrics returns an OTLP ResourceMetrics generated from rm. If rm diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/x/observ.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/x/observ.go index cc055ea47..f292e095c 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/x/observ.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/x/observ.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package x // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/x" +package x import "strings" diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/x/x.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/x/x.go index d42827877..212cdef44 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/x/x.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/x/x.go @@ -1,11 +1,11 @@ -// Code generated by gotmpl. DO NOT MODIFY. -// source: internal/shared/x/x.go.tmpl - // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/x/x.go.tmpl + // Package x documents experimental features for [go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc]. -package x // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/x" +package x import ( "os" @@ -34,9 +34,9 @@ func newFeature[T any](suffix []string, parse func(string) (T, bool)) Feature[T] // feature. func (f Feature[T]) Keys() []string { return f.keys } -// Lookup returns the user configured value for the feature and true if the +// Lookup returns the user-configured value for the feature and true if the // user has enabled the feature. Otherwise, if the feature is not enabled, a -// zero-value and false are returned. +// zero value and false are returned. func (f Feature[T]) Lookup() (v T, ok bool) { // https://github.com/open-telemetry/opentelemetry-specification/blob/62effed618589a0bec416a87e559c0a9d96289bb/specification/configuration/sdk-environment-variables.md#parsing-empty-value // diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/version.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/version.go index 8ee005c63..143faa636 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/version.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/version.go @@ -1,9 +1,9 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package otlpmetricgrpc // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc" +package otlpmetricgrpc // Version is the current release version of the OpenTelemetry OTLP over gRPC metrics exporter in use. func Version() string { - return "1.44.0" + return "1.46.0" } diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/client.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/client.go index b7ca17fe3..41aa7ff34 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/client.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/client.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package otlpmetrichttp // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp" +package otlpmetrichttp import ( "bytes" @@ -341,7 +341,7 @@ func (r *request) reset(ctx context.Context) { // retryableError represents a request failure that can be retried. type retryableError struct { - throttle int64 + throttle time.Duration err error } @@ -351,15 +351,29 @@ type retryableError struct { func newResponseError(header http.Header, wrapped error) error { var rErr retryableError if v := header.Get("Retry-After"); v != "" { - if t, err := strconv.ParseInt(v, 10, 64); err == nil { - rErr.throttle = t - } + rErr.throttle = retryAfterDuration(v) } rErr.err = wrapped return rErr } +func retryAfterDuration(v string) time.Duration { + if t, err := strconv.ParseInt(v, 10, 64); err == nil && t >= 0 { + const maxRetryAfterSeconds = int64(1<<63-1) / int64(time.Second) + if t > maxRetryAfterSeconds { + return time.Duration(1<<63 - 1) + } + return time.Duration(t) * time.Second + } + + if date, err := http.ParseTime(v); err == nil { + return max(time.Until(date), 0) + } + + return 0 +} + func (e retryableError) Error() string { if e.err != nil { return "retry-able request failure: " + e.err.Error() @@ -401,5 +415,5 @@ func evaluate(err error) (bool, time.Duration) { return false, 0 } - return true, time.Duration(rErr.throttle) + return true, rErr.throttle } diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/config.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/config.go index c6175507a..35e6bb12d 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/config.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/config.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package otlpmetrichttp // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp" +package otlpmetrichttp import ( "crypto/tls" @@ -86,6 +86,11 @@ func WithEndpoint(endpoint string) Option { // // If an invalid URL is provided, the default value will be kept. // +// The path of the provided URL is used as-is; with one exception: if the URL has +// no path, it is normalized to the root path ("/"). The default metrics path +// ("/v1/metrics") is not appended automatically. Use WithEndpoint if you want +// that behavior, or pass a URL that includes that path. +// // By default, if an environment variable is not set, and this option is not // passed, "localhost:4318" will be used. // diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/doc.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/doc.go index a2ea04922..a5e15efd6 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/doc.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/doc.go @@ -84,4 +84,4 @@ The configuration can be overridden by [WithAggregationSelector] option. [Explicit Bucket Histogram Aggregation]: https://github.com/open-telemetry/opentelemetry-specification/blob/v1.26.0/specification/metrics/sdk.md#explicit-bucket-histogram-aggregation [Base2 Exponential Bucket Histogram Aggregation]: https://github.com/open-telemetry/opentelemetry-specification/blob/v1.26.0/specification/metrics/sdk.md#base2-exponential-bucket-histogram-aggregation */ -package otlpmetrichttp // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp" +package otlpmetrichttp diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/exporter.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/exporter.go index 292645a38..ea4e20c23 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/exporter.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/exporter.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package otlpmetrichttp // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp" +package otlpmetrichttp import ( "context" diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/counter/counter.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/counter/counter.go index 267cb03d9..57c6acb78 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/counter/counter.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/counter/counter.go @@ -1,14 +1,14 @@ -// Code generated by gotmpl. DO NOT MODIFY. -// source: internal/shared/counter/counter.go.tmpl - // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/counter/counter.go.tmpl + // Package counter provides a simple counter for generating unique IDs. // // This package is used to generate unique IDs while allowing testing packages // to reset the counter. -package counter // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/counter" +package counter import "sync/atomic" diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/envconfig/envconfig.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/envconfig/envconfig.go index 8be035fca..87764a695 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/envconfig/envconfig.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/envconfig/envconfig.go @@ -1,12 +1,12 @@ -// Code generated by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/envconfig/envconfig.go.tmpl - // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/otlp/envconfig/envconfig.go.tmpl + // Package envconfig provides functionality to parse configuration from // environment variables. -package envconfig // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/envconfig" +package envconfig import ( "crypto/tls" @@ -60,7 +60,7 @@ func WithString(n string, fn func(string)) func(e *EnvOptionsReader) { func WithBool(n string, fn func(bool)) ConfigFn { return func(e *EnvOptionsReader) { if v, ok := e.GetEnvValue(n); ok { - b := strings.ToLower(v) == "true" + b := strings.EqualFold(v, "true") fn(b) } } diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/gen.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/gen.go index f3d165a57..9b1727caa 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/gen.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/gen.go @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // Package internal provides internal functionally for the otlpmetrichttp package. -package internal // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal" +package internal //go:generate gotmpl --body=../../../../../internal/shared/otlp/partialsuccess.go.tmpl "--data={}" --out=partialsuccess.go //go:generate gotmpl --body=../../../../../internal/shared/otlp/partialsuccess_test.go.tmpl "--data={}" --out=partialsuccess_test.go @@ -31,7 +31,7 @@ package internal // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/o //go:generate gotmpl --body=../../../../../internal/shared/otlp/otlpmetric/transform/metricdata.go.tmpl "--data={}" --out=transform/metricdata.go //go:generate gotmpl --body=../../../../../internal/shared/otlp/otlpmetric/transform/metricdata_test.go.tmpl "--data={}" --out=transform/metricdata_test.go -//go:generate gotmpl --body=../../../../../internal/shared/counter/counter.go.tmpl "--data={ \"pkg\": \"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/counter\" }" --out=counter/counter.go +//go:generate gotmpl --body=../../../../../internal/shared/counter/counter.go.tmpl "--data={}" --out=counter/counter.go //go:generate gotmpl --body=../../../../../internal/shared/counter/counter_test.go.tmpl "--data={}" --out=counter/counter_test.go //go:generate gotmpl --body=../../../../../internal/shared/x/x.go.tmpl "--data={ \"pkg\": \"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/x\" }" --out=x/x.go diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/observ/count.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/observ/count.go index 8b5bb1faa..b046b195e 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/observ/count.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/observ/count.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package observ // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/observ" +package observ import metricpb "go.opentelemetry.io/proto/otlp/metrics/v1" diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/observ/instrumentation.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/observ/instrumentation.go index 5db984a23..b28b2f886 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/observ/instrumentation.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/observ/instrumentation.go @@ -3,7 +3,7 @@ // Package observ provides experimental observability instrumentation for the // otlpmetrichttp exporter. -package observ // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/observ" +package observ import ( "context" @@ -25,8 +25,8 @@ import ( "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/x" "go.opentelemetry.io/otel/internal/global" "go.opentelemetry.io/otel/metric" - semconv "go.opentelemetry.io/otel/semconv/v1.41.0" - "go.opentelemetry.io/otel/semconv/v1.41.0/otelconv" + semconv "go.opentelemetry.io/otel/semconv/v1.43.0" + "go.opentelemetry.io/otel/semconv/v1.43.0/otelconv" ) const ( diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/envconfig.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/envconfig.go index 69224c97d..c0a6392dd 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/envconfig.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/envconfig.go @@ -1,10 +1,10 @@ -// Code generated by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlpmetric/oconf/envconfig.go.tmpl - // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package oconf // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf" +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/otlp/otlpmetric/oconf/envconfig.go.tmpl + +package oconf import ( "crypto/tls" @@ -51,31 +51,37 @@ func getOptionsFromEnv() []GenericOption { tlsConf := &tls.Config{} DefaultEnvOptionsReader.Apply( envconfig.WithURL("ENDPOINT", func(u *url.URL) { - opts = append(opts, withEndpointScheme(u)) - opts = append(opts, newSplitOption(func(cfg Config) Config { - cfg.Metrics.Endpoint = u.Host - // For OTLP/HTTP endpoint URLs without a per-signal - // configuration, the passed endpoint is used as a base URL - // and the signals are sent to these paths relative to that. - cfg.Metrics.URLPath = path.Join(u.Path, DefaultMetricsPath) - return cfg - }, withEndpointForGRPC(u))) + opts = append( + opts, + withEndpointScheme(u), + newSplitOption(func(cfg Config) Config { + cfg.Metrics.Endpoint = u.Host + // For OTLP/HTTP endpoint URLs without a per-signal + // configuration, the passed endpoint is used as a base URL + // and the signals are sent to these paths relative to that. + cfg.Metrics.URLPath = path.Join(u.Path, DefaultMetricsPath) + return cfg + }, withEndpointForGRPC(u)), + ) }), envconfig.WithURL("METRICS_ENDPOINT", func(u *url.URL) { - opts = append(opts, withEndpointScheme(u)) - opts = append(opts, newSplitOption(func(cfg Config) Config { - cfg.Metrics.Endpoint = u.Host - // For endpoint URLs for OTLP/HTTP per-signal variables, the - // URL MUST be used as-is without any modification. The only - // exception is that if an URL contains no path part, the root - // path / MUST be used. - path := u.Path - if path == "" { - path = "/" - } - cfg.Metrics.URLPath = path - return cfg - }, withEndpointForGRPC(u))) + opts = append( + opts, + withEndpointScheme(u), + newSplitOption(func(cfg Config) Config { + cfg.Metrics.Endpoint = u.Host + // For endpoint URLs for OTLP/HTTP per-signal variables, the + // URL MUST be used as-is without any modification. The only + // exception is that if an URL contains no path part, the root + // path / MUST be used. + path := u.Path + if path == "" { + path = "/" + } + cfg.Metrics.URLPath = path + return cfg + }, withEndpointForGRPC(u)), + ) }), envconfig.WithCertPool("CERTIFICATE", func(p *x509.CertPool) { tlsConf.RootCAs = p }), envconfig.WithCertPool("METRICS_CERTIFICATE", func(p *x509.CertPool) { tlsConf.RootCAs = p }), @@ -152,7 +158,7 @@ func withInsecure(b bool) GenericOption { } func withTLSConfig(c *tls.Config, fn func(*tls.Config)) func(e *envconfig.EnvOptionsReader) { - return func(e *envconfig.EnvOptionsReader) { + return func(*envconfig.EnvOptionsReader) { if c.RootCAs != nil || len(c.Certificates) > 0 { fn(c) } diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options.go index 3fa7cbe5f..a3e4641c2 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options.go @@ -1,11 +1,11 @@ -// Code generated by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlpmetric/oconf/options.go.tmpl - // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/otlp/otlpmetric/oconf/options.go.tmpl + // Package oconf provides configuration for the otlpmetric exporters. -package oconf // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf" +package oconf import ( "crypto/tls" @@ -112,7 +112,7 @@ func NewHTTPConfig(opts ...HTTPOption) Config { // cleanPath returns a path with all spaces trimmed. If urlPath is empty, // defaultPath is returned instead. -func cleanPath(urlPath string, defaultPath string) string { +func cleanPath(urlPath, defaultPath string) string { tmp := strings.TrimSpace(urlPath) if tmp == "" || tmp == "." { return defaultPath @@ -148,7 +148,7 @@ func NewGRPCConfig(opts ...GRPCOption) Config { cfg.DialOptions = append(cfg.DialOptions, grpc.WithDefaultServiceConfig(cfg.ServiceConfig)) } // Prioritize GRPCCredentials over Insecure (passing both is an error). - if cfg.Metrics.GRPCCredentials != nil { + if cfg.Metrics.GRPCCredentials != nil { //nolint:gocritic // if-else is clearer than switch cfg.DialOptions = append(cfg.DialOptions, grpc.WithTransportCredentials(cfg.Metrics.GRPCCredentials)) } else if cfg.Metrics.Insecure { cfg.DialOptions = append(cfg.DialOptions, grpc.WithTransportCredentials(insecure.NewCredentials())) @@ -242,7 +242,7 @@ func (g *splitOption) ApplyHTTPOption(cfg Config) Config { func (splitOption) private() {} -func newSplitOption(httpFn func(cfg Config) Config, grpcFn func(cfg Config) Config) GenericOption { +func newSplitOption(httpFn, grpcFn func(cfg Config) Config) GenericOption { return &splitOption{httpFn: httpFn, grpcFn: grpcFn} } @@ -295,6 +295,11 @@ func WithEndpointURL(v string) GenericOption { cfg.Metrics.Endpoint = u.Host cfg.Metrics.URLPath = u.Path + if cfg.Metrics.URLPath == "" { + // For HTTP exporters, a URL without a path targets the root path. Set it explicitly so the default signal + // path is not appended by cleanPath. (URLPath is ignored by gRPC exporters.) + cfg.Metrics.URLPath = "/" + } cfg.Metrics.Insecure = u.Scheme != "https" return cfg diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/optiontypes.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/optiontypes.go index d7b005c97..79f77841a 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/optiontypes.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/optiontypes.go @@ -1,10 +1,10 @@ -// Code generated by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlpmetric/oconf/optiontypes.go.tmpl - // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package oconf // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf" +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/otlp/otlpmetric/oconf/optiontypes.go.tmpl + +package oconf import "time" diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/tls.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/tls.go index e335cbd09..4ed82885a 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/tls.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/tls.go @@ -1,10 +1,10 @@ -// Code generated by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlpmetric/oconf/tls.go.tmpl - // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package oconf // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf" +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/otlp/otlpmetric/oconf/tls.go.tmpl + +package oconf import ( "crypto/tls" diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/partialsuccess.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/partialsuccess.go index 04190f530..1138f2e71 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/partialsuccess.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/partialsuccess.go @@ -1,10 +1,10 @@ -// Code generated by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/partialsuccess.go - // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package internal // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal" +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/otlp/partialsuccess.go + +package internal import "fmt" @@ -41,7 +41,7 @@ func (ps PartialSuccess) As(target any) bool { } // Is supports the errors.Is() interface. -func (ps PartialSuccess) Is(err error) bool { +func (PartialSuccess) Is(err error) bool { _, ok := err.(PartialSuccess) return ok } diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/retry/retry.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/retry/retry.go index b4b5c013d..468c7c8eb 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/retry/retry.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/retry/retry.go @@ -1,13 +1,13 @@ -// Code generated by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/retry/retry.go.tmpl - // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/otlp/retry/retry.go.tmpl + // Package retry provides request retry functionality that can perform // configurable exponential backoff for transient errors and honor any // explicit throttle responses received. -package retry // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/retry" +package retry import ( "context" @@ -17,7 +17,7 @@ import ( "github.com/cenkalti/backoff/v5" ) -// DefaultConfig are the recommended defaults to use. +// DefaultConfig is the recommended default configuration. var DefaultConfig = Config{ Enabled: true, InitialInterval: 5 * time.Second, @@ -25,42 +25,40 @@ var DefaultConfig = Config{ MaxElapsedTime: time.Minute, } -// Config defines configuration for retrying batches in case of export failure -// using an exponential backoff. +// Config defines configuration for retrying batches after an export failure +// using exponential backoff. type Config struct { - // Enabled indicates whether to not retry sending batches in case of - // export failure. + // Enabled indicates whether to retry sending batches after an export + // failure. Enabled bool - // InitialInterval the time to wait after the first failure before + // InitialInterval is the time to wait after the first failure before // retrying. InitialInterval time.Duration - // MaxInterval is the upper bound on backoff interval. Once this value is - // reached the delay between consecutive retries will always be - // `MaxInterval`. + // MaxInterval is the upper bound on the backoff interval before + // randomization. Once this value is reached, the base interval remains at + // MaxInterval. MaxInterval time.Duration // MaxElapsedTime is the maximum amount of time (including retries) spent - // trying to send a request/batch. Once this value is reached, the data - // is discarded. + // trying to send a request/batch. Once this value is reached, retrying stops. MaxElapsedTime time.Duration } // RequestFunc wraps a request with retry logic. type RequestFunc func(context.Context, func(context.Context) error) error -// EvaluateFunc returns if an error is retry-able and if an explicit throttle -// duration should be honored that was included in the error. +// EvaluateFunc reports whether an error is retryable and returns any explicit +// throttle duration to honor. // -// The function must return true if the error argument is retry-able, -// otherwise it must return false for the first return parameter. +// The function must return true as its first return value if the error +// argument is retryable; otherwise, it must return false. // -// The function must return a non-zero time.Duration if the error contains -// explicit throttle duration that should be honored, otherwise it must return -// a zero valued time.Duration. +// The function must return a nonzero time.Duration if the error contains an +// explicit throttle duration that should be honored; otherwise, it must return +// the zero value for time.Duration. type EvaluateFunc func(error) (bool, time.Duration) -// RequestFunc returns a RequestFunc using the evaluate function to determine -// if requests can be retried and based on the exponential backoff -// configuration of c. +// RequestFunc returns a RequestFunc that uses evaluate to determine whether +// requests can be retried and uses c to configure exponential backoff. func (c Config) RequestFunc(evaluate EvaluateFunc) RequestFunc { if !c.Enabled { return func(ctx context.Context, fn func(context.Context) error) error { @@ -96,7 +94,7 @@ func (c Config) RequestFunc(evaluate EvaluateFunc) RequestFunc { // Check if context is canceled before attempting to wait and retry. if ctx.Err() != nil { - return fmt.Errorf("%w: %w", ctx.Err(), err) + return fmt.Errorf("%w: %w", context.Cause(ctx), err) } if maxElapsedTime != 0 && time.Since(startTime) > maxElapsedTime { @@ -119,12 +117,12 @@ func (c Config) RequestFunc(evaluate EvaluateFunc) RequestFunc { } } -// Allow override for testing. +// waitFunc can be overridden for testing. var waitFunc = wait -// wait takes the caller's context, and the amount of time to wait. It will -// return nil if the timer fires before or at the same time as the context's -// deadline. This indicates that the call can be retried. +// wait blocks until delay elapses or ctx is done. If both happen +// simultaneously, wait favors the elapsed delay and returns nil to indicate +// that the call can be retried. func wait(ctx context.Context, delay time.Duration) error { timer := time.NewTimer(delay) defer timer.Stop() diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/transform/attribute.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/transform/attribute.go index 6a91ff2af..9fea51b46 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/transform/attribute.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/transform/attribute.go @@ -1,14 +1,15 @@ -// Code generated by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlpmetric/transform/attribute.go.tmpl - // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package transform // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/transform" +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/otlp/otlpmetric/transform/attribute.go.tmpl + +package transform import ( - "go.opentelemetry.io/otel/attribute" cpb "go.opentelemetry.io/proto/otlp/common/v1" + + "go.opentelemetry.io/otel/attribute" ) // AttrIter transforms an attribute iterator into OTLP key-values. @@ -91,6 +92,12 @@ func Value(v attribute.Value) *cpb.AnyValue { Values: attrValues(v.AsSlice()), }, } + case attribute.MAP: + av.Value = &cpb.AnyValue_KvlistValue{ + KvlistValue: &cpb.KeyValueList{ + Values: KeyValues(v.AsMap()), + }, + } case attribute.STRINGSLICE: av.Value = &cpb.AnyValue_ArrayValue{ ArrayValue: &cpb.ArrayValue{ diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/transform/error.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/transform/error.go index f65c87cbf..728502222 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/transform/error.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/transform/error.go @@ -1,10 +1,10 @@ -// Code generated by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlpmetric/transform/error.go.tmpl - // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package transform // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/transform" +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/otlp/otlpmetric/transform/error.go.tmpl + +package transform import ( "errors" diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/transform/metricdata.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/transform/metricdata.go index 5e5f26aa4..6c07896a8 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/transform/metricdata.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/transform/metricdata.go @@ -1,21 +1,22 @@ -// Code generated by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlpmetric/transform/metricdata.go.tmpl - // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/otlp/otlpmetric/transform/metricdata.go.tmpl + // Package transform provides transformation functionality from the // sdk/metric/metricdata data-types into OTLP data-types. -package transform // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/transform" +package transform import ( "fmt" "time" - "go.opentelemetry.io/otel/sdk/metric/metricdata" cpb "go.opentelemetry.io/proto/otlp/common/v1" mpb "go.opentelemetry.io/proto/otlp/metrics/v1" rpb "go.opentelemetry.io/proto/otlp/resource/v1" + + "go.opentelemetry.io/otel/sdk/metric/metricdata" ) // ResourceMetrics returns an OTLP ResourceMetrics generated from rm. If rm diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/version.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/version.go index 103ac79d0..aeb497f09 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/version.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/version.go @@ -1,8 +1,8 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package internal // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal" +package internal // Version is the current release version of the OpenTelemetry OTLP HTTP metric // exporter in use. -const Version = "1.44.0" +const Version = "1.46.0" diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/x/observ.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/x/observ.go index 296946a3b..76b6fdebd 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/x/observ.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/x/observ.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package x // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/x" +package x import "strings" diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/x/x.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/x/x.go index 663375f63..764a8d96e 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/x/x.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/x/x.go @@ -1,11 +1,11 @@ -// Code generated by gotmpl. DO NOT MODIFY. -// source: internal/shared/x/x.go.tmpl - // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/x/x.go.tmpl + // Package x documents experimental features for [go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/x]. -package x // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/x" +package x import ( "os" @@ -34,9 +34,9 @@ func newFeature[T any](suffix []string, parse func(string) (T, bool)) Feature[T] // feature. func (f Feature[T]) Keys() []string { return f.keys } -// Lookup returns the user configured value for the feature and true if the +// Lookup returns the user-configured value for the feature and true if the // user has enabled the feature. Otherwise, if the feature is not enabled, a -// zero-value and false are returned. +// zero value and false are returned. func (f Feature[T]) Lookup() (v T, ok bool) { // https://github.com/open-telemetry/opentelemetry-specification/blob/62effed618589a0bec416a87e559c0a9d96289bb/specification/configuration/sdk-environment-variables.md#parsing-empty-value // diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/version.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/version.go index da551839d..273e5e791 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/version.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/version.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package otlpmetrichttp // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp" +package otlpmetrichttp // Version is the current release version of the OpenTelemetry OTLP over HTTP/protobuf metrics exporter in use. func Version() string { diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/clients.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/clients.go index 3c1a625c0..d97fada29 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/clients.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/clients.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package otlptrace // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace" +package otlptrace import ( "context" diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/doc.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/doc.go index 09ad5eadb..5fd4bf5bb 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/doc.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/doc.go @@ -7,4 +7,4 @@ See the official OTLP span exporter implementations: - [go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc], - [go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp]. */ -package otlptrace // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace" +package otlptrace diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/exporter.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/exporter.go index 30446bd28..037d485d5 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/exporter.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/exporter.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package otlptrace // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace" +package otlptrace import ( "context" @@ -97,9 +97,9 @@ func NewUnstarted(client Client) *Exporter { func (e *Exporter) MarshalLog() any { return struct { Type string - Client Client + Client string }{ Type: "otlptrace", - Client: e.client, + Client: fmt.Sprintf("%T", e.client), } } diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/tracetransform/attribute.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/tracetransform/attribute.go index 0d43a5dc5..86a34d3b9 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/tracetransform/attribute.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/tracetransform/attribute.go @@ -3,7 +3,7 @@ // Package tracetransform provides conversion functionality for the otlptrace // exporters. -package tracetransform // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/tracetransform" +package tracetransform import ( commonpb "go.opentelemetry.io/proto/otlp/common/v1" @@ -97,6 +97,12 @@ func Value(v attribute.Value) *commonpb.AnyValue { Values: values(v.AsSlice()), }, } + case attribute.MAP: + av.Value = &commonpb.AnyValue_KvlistValue{ + KvlistValue: &commonpb.KeyValueList{ + Values: KeyValues(v.AsMap()), + }, + } case attribute.STRINGSLICE: av.Value = &commonpb.AnyValue_ArrayValue{ ArrayValue: &commonpb.ArrayValue{ diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/tracetransform/instrumentation.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/tracetransform/instrumentation.go index 43359c894..078a9db0a 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/tracetransform/instrumentation.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/tracetransform/instrumentation.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package tracetransform // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/tracetransform" +package tracetransform import ( commonpb "go.opentelemetry.io/proto/otlp/common/v1" diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/tracetransform/resource.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/tracetransform/resource.go index 526bb5e07..14e5bdc56 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/tracetransform/resource.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/tracetransform/resource.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package tracetransform // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/tracetransform" +package tracetransform import ( resourcepb "go.opentelemetry.io/proto/otlp/resource/v1" diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/tracetransform/span.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/tracetransform/span.go index d431fc451..3ab14b54f 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/tracetransform/span.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/tracetransform/span.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package tracetransform // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/tracetransform" +package tracetransform import ( "math" @@ -37,21 +37,22 @@ func Spans(sdl []tracesdk.ReadOnlySpan) []*tracepb.ResourceSpans { } rKey := sd.Resource().Equivalent() + scope := sd.InstrumentationScope() k := key{ r: rKey, - is: sd.InstrumentationScope(), + is: scope, } scopeSpan, iOk := ssm[k] if !iOk { // Either the resource or instrumentation scope were unknown. scopeSpan = &tracepb.ScopeSpans{ - Scope: InstrumentationScope(sd.InstrumentationScope()), + Scope: InstrumentationScope(scope), Spans: []*tracepb.Span{}, - SchemaUrl: sd.InstrumentationScope().SchemaURL, + SchemaUrl: scope.SchemaURL, } + ssm[k] = scopeSpan } scopeSpan.Spans = append(scopeSpan.Spans, span(sd)) - ssm[k] = scopeSpan rs, rOk := rsm[rKey] if !rOk { @@ -90,14 +91,16 @@ func span(sd tracesdk.ReadOnlySpan) *tracepb.Span { return nil } - tid := sd.SpanContext().TraceID() - sid := sd.SpanContext().SpanID() + spanContext := sd.SpanContext() + tid := spanContext.TraceID() + sid := spanContext.SpanID() + sdStatus := sd.Status() s := &tracepb.Span{ TraceId: tid[:], SpanId: sid[:], - TraceState: sd.SpanContext().TraceState().String(), - Status: status(sd.Status().Code, sd.Status().Description), + TraceState: spanContext.TraceState().String(), + Status: status(sdStatus.Code, sdStatus.Description), StartTimeUnixNano: uint64(max(0, sd.StartTime().UnixNano())), // nolint:gosec // Overflow checked. EndTimeUnixNano: uint64(max(0, sd.EndTime().UnixNano())), // nolint:gosec // Overflow checked. Links: links(sd.Links()), @@ -110,10 +113,11 @@ func span(sd tracesdk.ReadOnlySpan) *tracepb.Span { DroppedLinksCount: clampUint32(sd.DroppedLinks()), } - if psid := sd.Parent().SpanID(); psid.IsValid() { + sdParent := sd.Parent() + if psid := sdParent.SpanID(); psid.IsValid() { s.ParentSpanId = psid[:] } - s.Flags = buildSpanFlagsWith(sd.SpanContext().TraceFlags(), sd.Parent()) + s.Flags = buildSpanFlagsWith(spanContext.TraceFlags(), sdParent) return s } diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/client.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/client.go index e8b33d3fa..494bece44 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/client.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/client.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package otlptracegrpc // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc" +package otlptracegrpc import ( "context" @@ -328,12 +328,10 @@ func throttleDelay(s *status.Status) (bool, time.Duration) { } // MarshalLog is the marshaling function used by the logging system to represent this Client. -func (c *client) MarshalLog() any { +func (*client) MarshalLog() any { return struct { - Type string - Endpoint string + Type string }{ - Type: "otlptracegrpc", - Endpoint: c.endpoint, + Type: "otlptracegrpc", } } diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/doc.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/doc.go index b7bd429ff..b01358fc8 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/doc.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/doc.go @@ -62,4 +62,4 @@ The configuration can be overridden by [WithTLSCredentials], [WithGRPCConn] opti [W3C Baggage HTTP Header Content Format]: https://www.w3.org/TR/baggage/#header-content */ -package otlptracegrpc // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc" +package otlptracegrpc diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/exporter.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/exporter.go index b826b8424..d75b18443 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/exporter.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/exporter.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package otlptracegrpc // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc" +package otlptracegrpc import ( "context" diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/counter/counter.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/counter/counter.go index 323b2a2c9..57c6acb78 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/counter/counter.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/counter/counter.go @@ -1,14 +1,14 @@ -// Code generated by gotmpl. DO NOT MODIFY. -// source: internal/shared/counter/counter.go.tmpl - // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/counter/counter.go.tmpl + // Package counter provides a simple counter for generating unique IDs. // // This package is used to generate unique IDs while allowing testing packages // to reset the counter. -package counter // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/counter" +package counter import "sync/atomic" diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/envconfig/envconfig.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/envconfig/envconfig.go index 6eacdf311..87764a695 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/envconfig/envconfig.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/envconfig/envconfig.go @@ -1,12 +1,12 @@ -// Code generated by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/envconfig/envconfig.go.tmpl - // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/otlp/envconfig/envconfig.go.tmpl + // Package envconfig provides functionality to parse configuration from // environment variables. -package envconfig // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/envconfig" +package envconfig import ( "crypto/tls" @@ -60,7 +60,7 @@ func WithString(n string, fn func(string)) func(e *EnvOptionsReader) { func WithBool(n string, fn func(bool)) ConfigFn { return func(e *EnvOptionsReader) { if v, ok := e.GetEnvValue(n); ok { - b := strings.ToLower(v) == "true" + b := strings.EqualFold(v, "true") fn(b) } } diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/gen.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/gen.go index 7fe9c9f3a..ec16d0145 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/gen.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/gen.go @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // Package internal provides internal functionally for the otlptracegrpc package. -package internal // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal" +package internal //go:generate gotmpl --body=../../../../../internal/shared/otlp/partialsuccess.go.tmpl "--data={}" --out=partialsuccess.go //go:generate gotmpl --body=../../../../../internal/shared/otlp/partialsuccess_test.go.tmpl "--data={}" --out=partialsuccess_test.go @@ -27,8 +27,8 @@ package internal // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/ot //go:generate gotmpl --body=../../../../../internal/shared/x/x.go.tmpl "--data={ \"pkg\": \"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc\" }" --out=x/x.go //go:generate gotmpl --body=../../../../../internal/shared/x/x_test.go.tmpl "--data={}" --out=x/x_test.go -//go:generate gotmpl --body=../../../../../internal/shared/otlp/observ/target.go.tmpl "--data={ \"pkg\": \"observ\", \"pkg_path\": \"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/observ\" }" --out=observ/target.go +//go:generate gotmpl --body=../../../../../internal/shared/otlp/observ/target.go.tmpl "--data={ \"pkg\": \"observ\" }" --out=observ/target.go //go:generate gotmpl --body=../../../../../internal/shared/otlp/observ/target_test.go.tmpl "--data={ \"pkg\": \"observ\" }" --out=observ/target_test.go -//go:generate gotmpl --body=../../../../../internal/shared/counter/counter.go.tmpl "--data={ \"pkg\": \"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/counter\" }" --out=counter/counter.go +//go:generate gotmpl --body=../../../../../internal/shared/counter/counter.go.tmpl "--data={}" --out=counter/counter.go //go:generate gotmpl --body=../../../../../internal/shared/counter/counter_test.go.tmpl "--data={}" --out=counter/counter_test.go diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/observ/doc.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/observ/doc.go index 0dd54e4b9..32188bf72 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/observ/doc.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/observ/doc.go @@ -3,4 +3,4 @@ // Package observ provides experimental observability instrumentation for the // otlptracegrpc exporter. -package observ // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/observ" +package observ diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/observ/instrumentation.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/observ/instrumentation.go index 676a93514..d6730bc1e 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/observ/instrumentation.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/observ/instrumentation.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package observ // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/observ" +package observ import ( "context" @@ -18,8 +18,8 @@ import ( "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/x" "go.opentelemetry.io/otel/internal/global" "go.opentelemetry.io/otel/metric" - semconv "go.opentelemetry.io/otel/semconv/v1.41.0" - "go.opentelemetry.io/otel/semconv/v1.41.0/otelconv" + semconv "go.opentelemetry.io/otel/semconv/v1.43.0" + "go.opentelemetry.io/otel/semconv/v1.43.0/otelconv" ) const ( diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/observ/target.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/observ/target.go index 34eee27db..3bd379882 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/observ/target.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/observ/target.go @@ -1,10 +1,10 @@ -// Code generated by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/observ/target.go.tmpl - // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package observ // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/observ" +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/otlp/observ/target.go.tmpl + +package observ import ( "errors" @@ -21,13 +21,13 @@ const ( ) // ParseCanonicalTarget parses a target string and returns the extracted host -// (domain address or IP), the target port, or an error. +// (domain name or IP address), the target port, or an error. // // If no port is specified, -1 is returned. // // If no host is specified, an empty string is returned. // -// The target string is expected to always have the form +// The target string must have the form // "://[authority]/". For example: // - "dns:///example.com:42" // - "dns://8.8.8.8/example.com:42" @@ -35,17 +35,16 @@ const ( // - "unix-abstract:///socket-name" // - "passthrough:///192.34.2.1:42" // -// The target is expected to come from the CanonicalTarget method of a gRPC -// Client. +// The target is expected to be returned by gRPC's ClientConn.CanonicalTarget +// method. func ParseCanonicalTarget(target string) (string, int, error) { const sep = "://" // Find scheme. Do not allocate the string by using url.Parse. - idx := strings.Index(target, sep) - if idx == -1 { + scheme, endpoint, found := strings.Cut(target, sep) + if !found { return "", -1, fmt.Errorf("invalid target %q: missing scheme", target) } - scheme, endpoint := target[:idx], target[idx+len(sep):] // Check for unix schemes. if scheme == schemeUnix || scheme == schemeUnixAbstract { @@ -61,7 +60,7 @@ func ParseCanonicalTarget(target string) (string, int, error) { return parseEndpoint(endpoint) } -// parseUnix parses unix socket targets. +// parseUnix parses Unix socket targets. func parseUnix(endpoint string) (string, int, error) { // Format: unix[-abstract]://path // @@ -71,8 +70,8 @@ func parseUnix(endpoint string) (string, int, error) { return endpoint, -1, nil } - // If there's no leading slash, it means there might be an authority - // Check for authority case (should error): "authority/path" + // If there is no leading slash, an authority might be present, which is + // invalid. Check for this case: "authority/path". if slashIdx := strings.Index(endpoint, "/"); slashIdx > 0 { return "", -1, fmt.Errorf("invalid (non-empty) authority: %s", endpoint[:slashIdx]) } @@ -98,8 +97,8 @@ func parseUnix(endpoint string) (string, int, error) { // - "[ipv6]:port" // - "[ipv6%zone]:port" // -// It returns the host or host%zone (domain address or IP), the port (or -1 if -// not specified), or an error if the input is not a valid. +// It returns the host or host%zone (domain name or IP address), the port (or +// -1 if not specified), or an error if the input is invalid. func parseEndpoint(endpoint string) (string, int, error) { // First check if the endpoint is just an IP address. if ip := parseIP(endpoint); ip != "" { diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/envconfig.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/envconfig.go index 1d840be20..3bfc2a6f3 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/envconfig.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/envconfig.go @@ -1,10 +1,10 @@ -// Code generated by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlptrace/otlpconfig/envconfig.go.tmpl - // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package otlpconfig // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig" +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/otlp/otlptrace/otlpconfig/envconfig.go.tmpl + +package otlpconfig import ( "crypto/tls" @@ -49,31 +49,37 @@ func getOptionsFromEnv() []GenericOption { tlsConf := &tls.Config{} DefaultEnvOptionsReader.Apply( envconfig.WithURL("ENDPOINT", func(u *url.URL) { - opts = append(opts, withEndpointScheme(u)) - opts = append(opts, newSplitOption(func(cfg Config) Config { - cfg.Traces.Endpoint = u.Host - // For OTLP/HTTP endpoint URLs without a per-signal - // configuration, the passed endpoint is used as a base URL - // and the signals are sent to these paths relative to that. - cfg.Traces.URLPath = path.Join(u.Path, DefaultTracesPath) - return cfg - }, withEndpointForGRPC(u))) + opts = append( + opts, + withEndpointScheme(u), + newSplitOption(func(cfg Config) Config { + cfg.Traces.Endpoint = u.Host + // For OTLP/HTTP endpoint URLs without a per-signal + // configuration, the passed endpoint is used as a base URL + // and the signals are sent to these paths relative to that. + cfg.Traces.URLPath = path.Join(u.Path, DefaultTracesPath) + return cfg + }, withEndpointForGRPC(u)), + ) }), envconfig.WithURL("TRACES_ENDPOINT", func(u *url.URL) { - opts = append(opts, withEndpointScheme(u)) - opts = append(opts, newSplitOption(func(cfg Config) Config { - cfg.Traces.Endpoint = u.Host - // For endpoint URLs for OTLP/HTTP per-signal variables, the - // URL MUST be used as-is without any modification. The only - // exception is that if an URL contains no path part, the root - // path / MUST be used. - path := u.Path - if path == "" { - path = "/" - } - cfg.Traces.URLPath = path - return cfg - }, withEndpointForGRPC(u))) + opts = append( + opts, + withEndpointScheme(u), + newSplitOption(func(cfg Config) Config { + cfg.Traces.Endpoint = u.Host + // For endpoint URLs for OTLP/HTTP per-signal variables, the + // URL MUST be used as-is without any modification. The only + // exception is that if an URL contains no path part, the root + // path / MUST be used. + path := u.Path + if path == "" { + path = "/" + } + cfg.Traces.URLPath = path + return cfg + }, withEndpointForGRPC(u)), + ) }), envconfig.WithCertPool("CERTIFICATE", func(p *x509.CertPool) { tlsConf.RootCAs = p }), envconfig.WithCertPool("TRACES_CERTIFICATE", func(p *x509.CertPool) { tlsConf.RootCAs = p }), @@ -94,6 +100,8 @@ func getOptionsFromEnv() []GenericOption { envconfig.WithHeaders("TRACES_HEADERS", func(h map[string]string) { opts = append(opts, WithHeaders(h)) }), WithEnvCompression("COMPRESSION", func(c Compression) { opts = append(opts, WithCompression(c)) }), WithEnvCompression("TRACES_COMPRESSION", func(c Compression) { opts = append(opts, WithCompression(c)) }), + WithEnvProtocol("PROTOCOL", func(p Protocol) { opts = append(opts, WithProtocol(p)) }), + WithEnvProtocol("TRACES_PROTOCOL", func(p Protocol) { opts = append(opts, WithProtocol(p)) }), envconfig.WithDuration("TIMEOUT", func(d time.Duration) { opts = append(opts, WithTimeout(d)) }), envconfig.WithDuration("TRACES_TIMEOUT", func(d time.Duration) { opts = append(opts, WithTimeout(d)) }), ) @@ -133,6 +141,25 @@ func WithEnvCompression(n string, fn func(Compression)) func(e *envconfig.EnvOpt } } +// WithEnvProtocol retrieves the specified config and passes it to ConfigFn as a Protocol. +func WithEnvProtocol(n string, fn func(Protocol)) func(e *envconfig.EnvOptionsReader) { + return func(e *envconfig.EnvOptionsReader) { + if v, ok := e.GetEnvValue(n); ok { + protocol := ProtocolHTTPProtobuf + switch v { + case "grpc": + protocol = ProtocolGRPC + case "http/protobuf": + protocol = ProtocolHTTPProtobuf + case "http/json": + protocol = ProtocolHTTPJSON + } + + fn(protocol) + } + } +} + // revive:disable-next-line:flag-parameter func withInsecure(b bool) GenericOption { if b { @@ -142,7 +169,7 @@ func withInsecure(b bool) GenericOption { } func withTLSConfig(c *tls.Config, fn func(*tls.Config)) func(e *envconfig.EnvOptionsReader) { - return func(e *envconfig.EnvOptionsReader) { + return func(*envconfig.EnvOptionsReader) { if c.RootCAs != nil || len(c.Certificates) > 0 { fn(c) } diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options.go index d940b6762..a56847a3b 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options.go @@ -1,11 +1,11 @@ -// Code generated by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlptrace/otlpconfig/options.go.tmpl - // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/otlp/otlptrace/otlpconfig/options.go.tmpl + // Package otlpconfig provides configuration for the otlptrace exporters. -package otlpconfig // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig" +package otlpconfig import ( "crypto/tls" @@ -50,6 +50,7 @@ type ( TLSCfg *tls.Config Headers map[string]string Compression Compression + Protocol Protocol MaxRequestSize int Timeout time.Duration URLPath string @@ -84,6 +85,7 @@ func NewHTTPConfig(opts ...HTTPOption) Config { Endpoint: fmt.Sprintf("%s:%d", DefaultCollectorHost, DefaultCollectorHTTPPort), URLPath: DefaultTracesPath, Compression: NoCompression, + Protocol: ProtocolHTTPProtobuf, MaxRequestSize: DefaultMaxRequestSize, Timeout: DefaultTimeout, }, @@ -99,7 +101,7 @@ func NewHTTPConfig(opts ...HTTPOption) Config { // cleanPath returns a path with all spaces trimmed. If urlPath is empty, // defaultPath is returned instead. -func cleanPath(urlPath string, defaultPath string) string { +func cleanPath(urlPath, defaultPath string) string { tmp := strings.TrimSpace(urlPath) if tmp == "" || tmp == "." { return defaultPath @@ -119,6 +121,7 @@ func NewGRPCConfig(opts ...GRPCOption) Config { Endpoint: fmt.Sprintf("%s:%d", DefaultCollectorHost, DefaultCollectorGRPCPort), URLPath: DefaultTracesPath, Compression: NoCompression, + Protocol: ProtocolGRPC, MaxRequestSize: DefaultMaxRequestSize, Timeout: DefaultTimeout, }, @@ -134,7 +137,7 @@ func NewGRPCConfig(opts ...GRPCOption) Config { cfg.DialOptions = append(cfg.DialOptions, grpc.WithDefaultServiceConfig(cfg.ServiceConfig)) } // Prioritize GRPCCredentials over Insecure (passing both is an error). - if cfg.Traces.GRPCCredentials != nil { + if cfg.Traces.GRPCCredentials != nil { //nolint:gocritic // if-else is clearer than switch cfg.DialOptions = append(cfg.DialOptions, grpc.WithTransportCredentials(cfg.Traces.GRPCCredentials)) } else if cfg.Traces.Insecure { cfg.DialOptions = append(cfg.DialOptions, grpc.WithTransportCredentials(insecure.NewCredentials())) @@ -228,7 +231,7 @@ func (g *splitOption) ApplyHTTPOption(cfg Config) Config { func (splitOption) private() {} -func newSplitOption(httpFn func(cfg Config) Config, grpcFn func(cfg Config) Config) GenericOption { +func newSplitOption(httpFn, grpcFn func(cfg Config) Config) GenericOption { return &splitOption{httpFn: httpFn, grpcFn: grpcFn} } @@ -286,6 +289,11 @@ func WithEndpointURL(v string) GenericOption { cfg.Traces.Endpoint = u.Host cfg.Traces.URLPath = u.Path + if cfg.Traces.URLPath == "" { + // For HTTP exporters, a URL without a path targets the root path. Set it explicitly so the default signal + // path is not appended by cleanPath. (URLPath is ignored by gRPC exporters.) + cfg.Traces.URLPath = "/" + } cfg.Traces.Insecure = u.Scheme != "https" return cfg @@ -371,3 +379,25 @@ func WithHTTPClient(c *http.Client) GenericOption { return cfg }) } + +func WithProtocol(protocol Protocol) GenericOption { + return newSplitOption( + // For OTLP/HTTP endpoints, this is the encoding format of the payloads sent to the collector. + func(cfg Config) Config { + if protocol == ProtocolGRPC { + global.Warn("grpc is not a valid protocol for OTLP/HTTP, defaulting to http/protobuf") + protocol = ProtocolHTTPProtobuf + } + cfg.Traces.Protocol = protocol + return cfg + }, + // For OTLP/gRPC endpoints, it's always "grpc". + func(cfg Config) Config { + if protocol != ProtocolGRPC { + global.Debug("protocol option is ignored for OTLP/gRPC and is set to grpc") + } + cfg.Traces.Protocol = ProtocolGRPC + return cfg + }, + ) +} diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/optiontypes.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/optiontypes.go index 918490387..4f2da7427 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/optiontypes.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/optiontypes.go @@ -1,10 +1,10 @@ -// Code generated by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlptrace/otlpconfig/optiontypes.go.tmpl - // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package otlpconfig // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig" +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/otlp/otlptrace/otlpconfig/optiontypes.go.tmpl + +package otlpconfig const ( // DefaultCollectorGRPCPort is the default gRPC port of the collector. @@ -38,3 +38,15 @@ const ( // MarshalJSON tells the driver to send using json format. MarshalJSON ) + +// Protocol describes the transport protocol used to send data to the collector. +type Protocol int + +const ( + // ProtocolGRPC describes the "grpc" protocol. + ProtocolGRPC Protocol = iota + // ProtocolHTTPProtobuf describes the "http/protobuf" protocol. + ProtocolHTTPProtobuf + // ProtocolHTTPJSON describes the "http/json" protocol. + ProtocolHTTPJSON +) diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/tls.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/tls.go index ba6e41183..a14d5e6ec 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/tls.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/tls.go @@ -1,10 +1,10 @@ -// Code generated by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlptrace/otlpconfig/tls.go.tmpl - // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package otlpconfig // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig" +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/otlp/otlptrace/otlpconfig/tls.go.tmpl + +package otlpconfig import ( "crypto/tls" diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/partialsuccess.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/partialsuccess.go index a811a07b3..1138f2e71 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/partialsuccess.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/partialsuccess.go @@ -1,10 +1,10 @@ -// Code generated by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/partialsuccess.go - // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package internal // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal" +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/otlp/partialsuccess.go + +package internal import "fmt" @@ -41,7 +41,7 @@ func (ps PartialSuccess) As(target any) bool { } // Is supports the errors.Is() interface. -func (ps PartialSuccess) Is(err error) bool { +func (PartialSuccess) Is(err error) bool { _, ok := err.(PartialSuccess) return ok } diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/retry/retry.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/retry/retry.go index a7b8e81a7..468c7c8eb 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/retry/retry.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/retry/retry.go @@ -1,13 +1,13 @@ -// Code generated by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/retry/retry.go.tmpl - // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/otlp/retry/retry.go.tmpl + // Package retry provides request retry functionality that can perform // configurable exponential backoff for transient errors and honor any // explicit throttle responses received. -package retry // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/retry" +package retry import ( "context" @@ -17,7 +17,7 @@ import ( "github.com/cenkalti/backoff/v5" ) -// DefaultConfig are the recommended defaults to use. +// DefaultConfig is the recommended default configuration. var DefaultConfig = Config{ Enabled: true, InitialInterval: 5 * time.Second, @@ -25,42 +25,40 @@ var DefaultConfig = Config{ MaxElapsedTime: time.Minute, } -// Config defines configuration for retrying batches in case of export failure -// using an exponential backoff. +// Config defines configuration for retrying batches after an export failure +// using exponential backoff. type Config struct { - // Enabled indicates whether to not retry sending batches in case of - // export failure. + // Enabled indicates whether to retry sending batches after an export + // failure. Enabled bool - // InitialInterval the time to wait after the first failure before + // InitialInterval is the time to wait after the first failure before // retrying. InitialInterval time.Duration - // MaxInterval is the upper bound on backoff interval. Once this value is - // reached the delay between consecutive retries will always be - // `MaxInterval`. + // MaxInterval is the upper bound on the backoff interval before + // randomization. Once this value is reached, the base interval remains at + // MaxInterval. MaxInterval time.Duration // MaxElapsedTime is the maximum amount of time (including retries) spent - // trying to send a request/batch. Once this value is reached, the data - // is discarded. + // trying to send a request/batch. Once this value is reached, retrying stops. MaxElapsedTime time.Duration } // RequestFunc wraps a request with retry logic. type RequestFunc func(context.Context, func(context.Context) error) error -// EvaluateFunc returns if an error is retry-able and if an explicit throttle -// duration should be honored that was included in the error. +// EvaluateFunc reports whether an error is retryable and returns any explicit +// throttle duration to honor. // -// The function must return true if the error argument is retry-able, -// otherwise it must return false for the first return parameter. +// The function must return true as its first return value if the error +// argument is retryable; otherwise, it must return false. // -// The function must return a non-zero time.Duration if the error contains -// explicit throttle duration that should be honored, otherwise it must return -// a zero valued time.Duration. +// The function must return a nonzero time.Duration if the error contains an +// explicit throttle duration that should be honored; otherwise, it must return +// the zero value for time.Duration. type EvaluateFunc func(error) (bool, time.Duration) -// RequestFunc returns a RequestFunc using the evaluate function to determine -// if requests can be retried and based on the exponential backoff -// configuration of c. +// RequestFunc returns a RequestFunc that uses evaluate to determine whether +// requests can be retried and uses c to configure exponential backoff. func (c Config) RequestFunc(evaluate EvaluateFunc) RequestFunc { if !c.Enabled { return func(ctx context.Context, fn func(context.Context) error) error { @@ -96,7 +94,7 @@ func (c Config) RequestFunc(evaluate EvaluateFunc) RequestFunc { // Check if context is canceled before attempting to wait and retry. if ctx.Err() != nil { - return fmt.Errorf("%w: %w", ctx.Err(), err) + return fmt.Errorf("%w: %w", context.Cause(ctx), err) } if maxElapsedTime != 0 && time.Since(startTime) > maxElapsedTime { @@ -119,12 +117,12 @@ func (c Config) RequestFunc(evaluate EvaluateFunc) RequestFunc { } } -// Allow override for testing. +// waitFunc can be overridden for testing. var waitFunc = wait -// wait takes the caller's context, and the amount of time to wait. It will -// return nil if the timer fires before or at the same time as the context's -// deadline. This indicates that the call can be retried. +// wait blocks until delay elapses or ctx is done. If both happen +// simultaneously, wait favors the elapsed delay and returns nil to indicate +// that the call can be retried. func wait(ctx context.Context, delay time.Duration) error { timer := time.NewTimer(delay) defer timer.Stop() diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/version.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/version.go index 28e51e443..d26674e57 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/version.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/version.go @@ -1,8 +1,8 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package internal // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal" +package internal // Version is the current release version of the OpenTelemetry OTLP gRPC trace // exporter in use. -const Version = "1.44.0" +const Version = "1.46.0" diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/x/observ.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/x/observ.go index 4e89c6524..76b6fdebd 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/x/observ.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/x/observ.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package x // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/x" +package x import "strings" diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/x/x.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/x/x.go index 741ba62c9..71011358c 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/x/x.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/x/x.go @@ -1,11 +1,11 @@ -// Code generated by gotmpl. DO NOT MODIFY. -// source: internal/shared/x/x.go.tmpl - // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/x/x.go.tmpl + // Package x documents experimental features for [go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc]. -package x // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/x" +package x import ( "os" @@ -34,9 +34,9 @@ func newFeature[T any](suffix []string, parse func(string) (T, bool)) Feature[T] // feature. func (f Feature[T]) Keys() []string { return f.keys } -// Lookup returns the user configured value for the feature and true if the +// Lookup returns the user-configured value for the feature and true if the // user has enabled the feature. Otherwise, if the feature is not enabled, a -// zero-value and false are returned. +// zero value and false are returned. func (f Feature[T]) Lookup() (v T, ok bool) { // https://github.com/open-telemetry/opentelemetry-specification/blob/62effed618589a0bec416a87e559c0a9d96289bb/specification/configuration/sdk-environment-variables.md#parsing-empty-value // diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/options.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/options.go index b32006052..ea20363c0 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/options.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/options.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package otlptracegrpc // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc" +package otlptracegrpc import ( "fmt" diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/client.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/client.go index f81098b38..00b4572ef 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/client.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/client.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package otlptracehttp // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp" +package otlptracehttp import ( "bytes" @@ -27,10 +27,14 @@ import ( "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/counter" "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/observ" "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig" + "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/otlpjson" "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/retry" ) -const contentTypeProto = "application/x-protobuf" +const ( + contentTypeProto = "application/x-protobuf" + contentTypeJSON = "application/json" +) // maxResponseBodySize is the maximum number of bytes to read from a response // body. It is set to 4 MiB per the OTLP specification recommendation to @@ -160,19 +164,11 @@ func (c *client) UploadTraces(ctx context.Context, protoSpans []*tracepb.Resourc pbRequest := &coltracepb.ExportTraceServiceRequest{ ResourceSpans: protoSpans, } - rawRequest, err := proto.Marshal(pbRequest) - if err != nil { - return err - } ctx, cancel := c.contextWithStop(ctx) defer cancel() - if maxSize := c.cfg.MaxRequestSize; maxSize > 0 && len(rawRequest) > maxSize { - return fmt.Errorf("request body too large: exceeded %d bytes", maxSize) - } - - request, err := c.newRequest(rawRequest) + request, err := c.newRequest(pbRequest) if err != nil { return err } @@ -232,19 +228,26 @@ func (c *client) UploadTraces(ctx context.Context, protoSpans []*tracepb.Resourc return nil } - if resp.Header.Get("Content-Type") == "application/x-protobuf" { - var respProto coltracepb.ExportTraceServiceResponse + var respProto coltracepb.ExportTraceServiceResponse + switch resp.Header.Get("Content-Type") { + case contentTypeProto: if err := proto.Unmarshal(respData.Bytes(), &respProto); err != nil { return err } + case contentTypeJSON: + if err := otlpjson.UnmarshalExportTraceServiceResponse(respData.Bytes(), &respProto); err != nil { + return err + } + default: + return nil + } - if respProto.PartialSuccess != nil { - msg := respProto.PartialSuccess.GetErrorMessage() - n := respProto.PartialSuccess.GetRejectedSpans() - if n != 0 || msg != "" { - err := internal.TracePartialSuccessError(n, msg) - uploadErr = errors.Join(uploadErr, err) - } + if respProto.PartialSuccess != nil { + msg := respProto.PartialSuccess.GetErrorMessage() + n := respProto.PartialSuccess.GetRejectedSpans() + if n != 0 || msg != "" { + err := internal.TracePartialSuccessError(n, msg) + uploadErr = errors.Join(uploadErr, err) } } return nil @@ -283,7 +286,24 @@ func (c *client) UploadTraces(ctx context.Context, protoSpans []*tracepb.Resourc })) } -func (c *client) newRequest(body []byte) (request, error) { +func (c *client) marshalRequest(pbRequest *coltracepb.ExportTraceServiceRequest) ([]byte, error) { + if c.cfg.Protocol == otlpconfig.ProtocolHTTPJSON { + rawRequest, err := otlpjson.MarshalExportTraceServiceRequest(pbRequest) + if err != nil { + return nil, fmt.Errorf("failed to marshal request body in json: %w", err) + } + return rawRequest, nil + } + + rawRequest, err := proto.Marshal(pbRequest) + if err != nil { + return nil, fmt.Errorf("failed to marshal request body in protobuf: %w", err) + } + + return rawRequest, nil +} + +func (c *client) newRequest(pbRequest *coltracepb.ExportTraceServiceRequest) (request, error) { u := url.URL{Scheme: c.getScheme(), Host: c.cfg.Endpoint, Path: c.cfg.URLPath} r, err := http.NewRequestWithContext(context.Background(), http.MethodPost, u.String(), http.NoBody) if err != nil { @@ -297,6 +317,18 @@ func (c *client) newRequest(body []byte) (request, error) { r.Header.Set(k, v) } r.Header.Set("Content-Type", contentTypeProto) + if c.cfg.Protocol == otlpconfig.ProtocolHTTPJSON { + r.Header.Set("Content-Type", contentTypeJSON) + } + + body, err := c.marshalRequest(pbRequest) + if err != nil { + return request{Request: r}, err + } + + if maxSize := c.cfg.MaxRequestSize; maxSize > 0 && len(body) > maxSize { + return request{Request: r}, fmt.Errorf("request body too large: exceeded %d bytes", maxSize) + } req := request{Request: r} switch Compression(c.cfg.Compression) { @@ -334,15 +366,11 @@ func (c *client) newRequest(body []byte) (request, error) { } // MarshalLog is the marshaling function used by the logging system to represent this Client. -func (c *client) MarshalLog() any { +func (*client) MarshalLog() any { return struct { - Type string - Endpoint string - Insecure bool + Type string }{ - Type: "otlptracehttp", - Endpoint: c.cfg.Endpoint, - Insecure: c.cfg.Insecure, + Type: "otlptracehttp", } } @@ -376,7 +404,7 @@ func (r *request) reset(ctx context.Context) { // retryableError represents a request failure that can be retried. type retryableError struct { - throttle int64 + throttle time.Duration err error } @@ -385,16 +413,30 @@ type retryableError struct { // if it is not nil. func newResponseError(header http.Header, wrapped error) error { var rErr retryableError - if s, ok := header["Retry-After"]; ok { - if t, err := strconv.ParseInt(s[0], 10, 64); err == nil { - rErr.throttle = t - } + if v := header.Get("Retry-After"); v != "" { + rErr.throttle = retryAfterDuration(v) } rErr.err = wrapped return rErr } +func retryAfterDuration(v string) time.Duration { + if t, err := strconv.ParseInt(v, 10, 64); err == nil && t >= 0 { + const maxRetryAfterSeconds = int64(1<<63-1) / int64(time.Second) + if t > maxRetryAfterSeconds { + return time.Duration(1<<63 - 1) + } + return time.Duration(t) * time.Second + } + + if date, err := http.ParseTime(v); err == nil { + return max(time.Until(date), 0) + } + + return 0 +} + func (e retryableError) Error() string { if e.err != nil { return "retry-able request failure: " + e.err.Error() @@ -436,7 +478,7 @@ func evaluate(err error) (bool, time.Duration) { return false, 0 } - return true, time.Duration(rErr.throttle) + return true, rErr.throttle } func (c *client) getScheme() string { diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/doc.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/doc.go index 85645e118..5e881f946 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/doc.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/doc.go @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 /* -Package otlptracehttp provides an OTLP span exporter using HTTP with protobuf payloads. +Package otlptracehttp provides an OTLP span exporter using HTTP with protobuf or JSON payloads. By default the telemetry is sent to https://localhost:4318/v1/traces. Exporter should be created using [New]. @@ -63,6 +63,12 @@ the filepath to the client's private key to use in mTLS communication in PEM for OTEL_EXPORTER_OTLP_TRACES_CLIENT_KEY takes precedence over OTEL_EXPORTER_OTLP_CLIENT_KEY. The configuration can be overridden by [WithTLSClientConfig] option. +OTEL_EXPORTER_OTLP_PROTOCOL, OTEL_EXPORTER_OTLP_TRACES_PROTOCOL (default: "http/protobuf") - +the transport protocol the exporter uses. For OTLP/HTTP exporters, it indicates the encoding format of the payloads sent to the collector. +Supported value: "http/protobuf", "http/json". +OTEL_EXPORTER_OTLP_TRACES_PROTOCOL takes precedence over OTEL_EXPORTER_OTLP_PROTOCOL. +The configuration can be overridden by [WithEncoding] option. + [W3C Baggage HTTP Header Content Format]: https://www.w3.org/TR/baggage/#header-content */ -package otlptracehttp // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp" +package otlptracehttp diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/exporter.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/exporter.go index fae89ea4f..b6e1214c8 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/exporter.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/exporter.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package otlptracehttp // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp" +package otlptracehttp import ( "context" diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/counter/counter.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/counter/counter.go index 75e5c0c7e..57c6acb78 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/counter/counter.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/counter/counter.go @@ -1,14 +1,14 @@ -// Code generated by gotmpl. DO NOT MODIFY. -// source: internal/shared/counter/counter.go.tmpl - // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/counter/counter.go.tmpl + // Package counter provides a simple counter for generating unique IDs. // // This package is used to generate unique IDs while allowing testing packages // to reset the counter. -package counter // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/counter" +package counter import "sync/atomic" diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/envconfig/envconfig.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/envconfig/envconfig.go index f4385fb4e..87764a695 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/envconfig/envconfig.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/envconfig/envconfig.go @@ -1,12 +1,12 @@ -// Code generated by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/envconfig/envconfig.go.tmpl - // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/otlp/envconfig/envconfig.go.tmpl + // Package envconfig provides functionality to parse configuration from // environment variables. -package envconfig // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/envconfig" +package envconfig import ( "crypto/tls" @@ -60,7 +60,7 @@ func WithString(n string, fn func(string)) func(e *EnvOptionsReader) { func WithBool(n string, fn func(bool)) ConfigFn { return func(e *EnvOptionsReader) { if v, ok := e.GetEnvValue(n); ok { - b := strings.ToLower(v) == "true" + b := strings.EqualFold(v, "true") fn(b) } } diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/gen.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/gen.go index ca387432f..9064f6564 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/gen.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/gen.go @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // Package internal provides internal functionally for the otlptracehttp package. -package internal // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal" +package internal //go:generate gotmpl --body=../../../../../internal/shared/otlp/partialsuccess.go.tmpl "--data={}" --out=partialsuccess.go //go:generate gotmpl --body=../../../../../internal/shared/otlp/partialsuccess_test.go.tmpl "--data={}" --out=partialsuccess_test.go @@ -26,6 +26,6 @@ package internal // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/ot //go:generate gotmpl --body=../../../../../internal/shared/x/x.go.tmpl "--data={ \"pkg\": \"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp\" }" --out=x/x.go -//go:generate gotmpl --body=../../../../../internal/shared/counter/counter.go.tmpl "--data={ \"pkg\": \"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/counter\" }" --out=counter/counter.go +//go:generate gotmpl --body=../../../../../internal/shared/counter/counter.go.tmpl "--data={}" --out=counter/counter.go //go:generate gotmpl --body=../../../../../internal/shared/counter/counter_test.go.tmpl "--data={}" --out=counter/counter_test.go //go:generate gotmpl --body=../../../../../internal/shared/x/x_test.go.tmpl "--data={}" --out=x/x_test.go diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/observ/instrumentation.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/observ/instrumentation.go index 1f4fc55c6..14ef0bbd8 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/observ/instrumentation.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/observ/instrumentation.go @@ -3,7 +3,7 @@ // Package observ provides experimental observability instrumentation for the // otlptracehttp exporter. -package observ // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/observ" +package observ import ( "context" @@ -23,8 +23,8 @@ import ( "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/x" "go.opentelemetry.io/otel/internal/global" "go.opentelemetry.io/otel/metric" - semconv "go.opentelemetry.io/otel/semconv/v1.41.0" - "go.opentelemetry.io/otel/semconv/v1.41.0/otelconv" + semconv "go.opentelemetry.io/otel/semconv/v1.43.0" + "go.opentelemetry.io/otel/semconv/v1.43.0/otelconv" ) const ( diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/envconfig.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/envconfig.go index 121b02f5c..96f857f97 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/envconfig.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/envconfig.go @@ -1,10 +1,10 @@ -// Code generated by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlptrace/otlpconfig/envconfig.go.tmpl - // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package otlpconfig // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig" +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/otlp/otlptrace/otlpconfig/envconfig.go.tmpl + +package otlpconfig import ( "crypto/tls" @@ -49,31 +49,37 @@ func getOptionsFromEnv() []GenericOption { tlsConf := &tls.Config{} DefaultEnvOptionsReader.Apply( envconfig.WithURL("ENDPOINT", func(u *url.URL) { - opts = append(opts, withEndpointScheme(u)) - opts = append(opts, newSplitOption(func(cfg Config) Config { - cfg.Traces.Endpoint = u.Host - // For OTLP/HTTP endpoint URLs without a per-signal - // configuration, the passed endpoint is used as a base URL - // and the signals are sent to these paths relative to that. - cfg.Traces.URLPath = path.Join(u.Path, DefaultTracesPath) - return cfg - }, withEndpointForGRPC(u))) + opts = append( + opts, + withEndpointScheme(u), + newSplitOption(func(cfg Config) Config { + cfg.Traces.Endpoint = u.Host + // For OTLP/HTTP endpoint URLs without a per-signal + // configuration, the passed endpoint is used as a base URL + // and the signals are sent to these paths relative to that. + cfg.Traces.URLPath = path.Join(u.Path, DefaultTracesPath) + return cfg + }, withEndpointForGRPC(u)), + ) }), envconfig.WithURL("TRACES_ENDPOINT", func(u *url.URL) { - opts = append(opts, withEndpointScheme(u)) - opts = append(opts, newSplitOption(func(cfg Config) Config { - cfg.Traces.Endpoint = u.Host - // For endpoint URLs for OTLP/HTTP per-signal variables, the - // URL MUST be used as-is without any modification. The only - // exception is that if an URL contains no path part, the root - // path / MUST be used. - path := u.Path - if path == "" { - path = "/" - } - cfg.Traces.URLPath = path - return cfg - }, withEndpointForGRPC(u))) + opts = append( + opts, + withEndpointScheme(u), + newSplitOption(func(cfg Config) Config { + cfg.Traces.Endpoint = u.Host + // For endpoint URLs for OTLP/HTTP per-signal variables, the + // URL MUST be used as-is without any modification. The only + // exception is that if an URL contains no path part, the root + // path / MUST be used. + path := u.Path + if path == "" { + path = "/" + } + cfg.Traces.URLPath = path + return cfg + }, withEndpointForGRPC(u)), + ) }), envconfig.WithCertPool("CERTIFICATE", func(p *x509.CertPool) { tlsConf.RootCAs = p }), envconfig.WithCertPool("TRACES_CERTIFICATE", func(p *x509.CertPool) { tlsConf.RootCAs = p }), @@ -94,6 +100,8 @@ func getOptionsFromEnv() []GenericOption { envconfig.WithHeaders("TRACES_HEADERS", func(h map[string]string) { opts = append(opts, WithHeaders(h)) }), WithEnvCompression("COMPRESSION", func(c Compression) { opts = append(opts, WithCompression(c)) }), WithEnvCompression("TRACES_COMPRESSION", func(c Compression) { opts = append(opts, WithCompression(c)) }), + WithEnvProtocol("PROTOCOL", func(p Protocol) { opts = append(opts, WithProtocol(p)) }), + WithEnvProtocol("TRACES_PROTOCOL", func(p Protocol) { opts = append(opts, WithProtocol(p)) }), envconfig.WithDuration("TIMEOUT", func(d time.Duration) { opts = append(opts, WithTimeout(d)) }), envconfig.WithDuration("TRACES_TIMEOUT", func(d time.Duration) { opts = append(opts, WithTimeout(d)) }), ) @@ -133,6 +141,25 @@ func WithEnvCompression(n string, fn func(Compression)) func(e *envconfig.EnvOpt } } +// WithEnvProtocol retrieves the specified config and passes it to ConfigFn as a Protocol. +func WithEnvProtocol(n string, fn func(Protocol)) func(e *envconfig.EnvOptionsReader) { + return func(e *envconfig.EnvOptionsReader) { + if v, ok := e.GetEnvValue(n); ok { + protocol := ProtocolHTTPProtobuf + switch v { + case "grpc": + protocol = ProtocolGRPC + case "http/protobuf": + protocol = ProtocolHTTPProtobuf + case "http/json": + protocol = ProtocolHTTPJSON + } + + fn(protocol) + } + } +} + // revive:disable-next-line:flag-parameter func withInsecure(b bool) GenericOption { if b { @@ -142,7 +169,7 @@ func withInsecure(b bool) GenericOption { } func withTLSConfig(c *tls.Config, fn func(*tls.Config)) func(e *envconfig.EnvOptionsReader) { - return func(e *envconfig.EnvOptionsReader) { + return func(*envconfig.EnvOptionsReader) { if c.RootCAs != nil || len(c.Certificates) > 0 { fn(c) } diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options.go index 2abde6615..f1c1d2712 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options.go @@ -1,11 +1,11 @@ -// Code generated by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlptrace/otlpconfig/options.go.tmpl - // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/otlp/otlptrace/otlpconfig/options.go.tmpl + // Package otlpconfig provides configuration for the otlptrace exporters. -package otlpconfig // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig" +package otlpconfig import ( "crypto/tls" @@ -50,6 +50,7 @@ type ( TLSCfg *tls.Config Headers map[string]string Compression Compression + Protocol Protocol MaxRequestSize int Timeout time.Duration URLPath string @@ -84,6 +85,7 @@ func NewHTTPConfig(opts ...HTTPOption) Config { Endpoint: fmt.Sprintf("%s:%d", DefaultCollectorHost, DefaultCollectorHTTPPort), URLPath: DefaultTracesPath, Compression: NoCompression, + Protocol: ProtocolHTTPProtobuf, MaxRequestSize: DefaultMaxRequestSize, Timeout: DefaultTimeout, }, @@ -99,7 +101,7 @@ func NewHTTPConfig(opts ...HTTPOption) Config { // cleanPath returns a path with all spaces trimmed. If urlPath is empty, // defaultPath is returned instead. -func cleanPath(urlPath string, defaultPath string) string { +func cleanPath(urlPath, defaultPath string) string { tmp := strings.TrimSpace(urlPath) if tmp == "" || tmp == "." { return defaultPath @@ -119,6 +121,7 @@ func NewGRPCConfig(opts ...GRPCOption) Config { Endpoint: fmt.Sprintf("%s:%d", DefaultCollectorHost, DefaultCollectorGRPCPort), URLPath: DefaultTracesPath, Compression: NoCompression, + Protocol: ProtocolGRPC, MaxRequestSize: DefaultMaxRequestSize, Timeout: DefaultTimeout, }, @@ -134,7 +137,7 @@ func NewGRPCConfig(opts ...GRPCOption) Config { cfg.DialOptions = append(cfg.DialOptions, grpc.WithDefaultServiceConfig(cfg.ServiceConfig)) } // Prioritize GRPCCredentials over Insecure (passing both is an error). - if cfg.Traces.GRPCCredentials != nil { + if cfg.Traces.GRPCCredentials != nil { //nolint:gocritic // if-else is clearer than switch cfg.DialOptions = append(cfg.DialOptions, grpc.WithTransportCredentials(cfg.Traces.GRPCCredentials)) } else if cfg.Traces.Insecure { cfg.DialOptions = append(cfg.DialOptions, grpc.WithTransportCredentials(insecure.NewCredentials())) @@ -228,7 +231,7 @@ func (g *splitOption) ApplyHTTPOption(cfg Config) Config { func (splitOption) private() {} -func newSplitOption(httpFn func(cfg Config) Config, grpcFn func(cfg Config) Config) GenericOption { +func newSplitOption(httpFn, grpcFn func(cfg Config) Config) GenericOption { return &splitOption{httpFn: httpFn, grpcFn: grpcFn} } @@ -286,6 +289,11 @@ func WithEndpointURL(v string) GenericOption { cfg.Traces.Endpoint = u.Host cfg.Traces.URLPath = u.Path + if cfg.Traces.URLPath == "" { + // For HTTP exporters, a URL without a path targets the root path. Set it explicitly so the default signal + // path is not appended by cleanPath. (URLPath is ignored by gRPC exporters.) + cfg.Traces.URLPath = "/" + } cfg.Traces.Insecure = u.Scheme != "https" return cfg @@ -371,3 +379,25 @@ func WithHTTPClient(c *http.Client) GenericOption { return cfg }) } + +func WithProtocol(protocol Protocol) GenericOption { + return newSplitOption( + // For OTLP/HTTP endpoints, this is the encoding format of the payloads sent to the collector. + func(cfg Config) Config { + if protocol == ProtocolGRPC { + global.Warn("grpc is not a valid protocol for OTLP/HTTP, defaulting to http/protobuf") + protocol = ProtocolHTTPProtobuf + } + cfg.Traces.Protocol = protocol + return cfg + }, + // For OTLP/gRPC endpoints, it's always "grpc". + func(cfg Config) Config { + if protocol != ProtocolGRPC { + global.Debug("protocol option is ignored for OTLP/gRPC and is set to grpc") + } + cfg.Traces.Protocol = ProtocolGRPC + return cfg + }, + ) +} diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/optiontypes.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/optiontypes.go index 6a52b58cc..4f2da7427 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/optiontypes.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/optiontypes.go @@ -1,10 +1,10 @@ -// Code generated by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlptrace/otlpconfig/optiontypes.go.tmpl - // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package otlpconfig // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig" +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/otlp/otlptrace/otlpconfig/optiontypes.go.tmpl + +package otlpconfig const ( // DefaultCollectorGRPCPort is the default gRPC port of the collector. @@ -38,3 +38,15 @@ const ( // MarshalJSON tells the driver to send using json format. MarshalJSON ) + +// Protocol describes the transport protocol used to send data to the collector. +type Protocol int + +const ( + // ProtocolGRPC describes the "grpc" protocol. + ProtocolGRPC Protocol = iota + // ProtocolHTTPProtobuf describes the "http/protobuf" protocol. + ProtocolHTTPProtobuf + // ProtocolHTTPJSON describes the "http/json" protocol. + ProtocolHTTPJSON +) diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/tls.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/tls.go index 5b389cb03..a14d5e6ec 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/tls.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/tls.go @@ -1,10 +1,10 @@ -// Code generated by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlptrace/otlpconfig/tls.go.tmpl - // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package otlpconfig // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig" +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/otlp/otlptrace/otlpconfig/tls.go.tmpl + +package otlpconfig import ( "crypto/tls" diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/otlpjson/export_trace_service_request.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/otlpjson/export_trace_service_request.go new file mode 100644 index 000000000..9e7756f61 --- /dev/null +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/otlpjson/export_trace_service_request.go @@ -0,0 +1,642 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +// Package otlpjson implements OTLP JSON Protobuf encoding for trace data. +// +// The encoding conforms to the OTLP specs +// (https://opentelemetry.io/docs/specs/otlp/#json-protobuf-encoding): +// - trace ID and span ID byte arrays are encoded as case-insensitive hex-encoded strings +// - enum values encoded as integers +// - field names in lowerCamelCase +// - 64-bit integers encoded as quoted decimal strings (ProtoJSON specs) +package otlpjson + +import ( + "encoding/hex" + "encoding/json" + "fmt" + "math" + "strconv" + "strings" + + coltracepb "go.opentelemetry.io/proto/otlp/collector/trace/v1" + commonpb "go.opentelemetry.io/proto/otlp/common/v1" + resourcepb "go.opentelemetry.io/proto/otlp/resource/v1" + tracepb "go.opentelemetry.io/proto/otlp/trace/v1" +) + +// ExportTraceServiceRequest corresponds to coltracepb.ExportTraceServiceRequest. +type ExportTraceServiceRequest struct { + ResourceSpans []*ResourceSpans `json:"resourceSpans,omitempty"` +} + +// ResourceSpans corresponds to tracepb.ResourceSpans. +type ResourceSpans struct { + Resource *Resource `json:"resource,omitempty"` + ScopeSpans []*ScopeSpans `json:"scopeSpans,omitempty"` + SchemaURL string `json:"schemaUrl,omitempty"` +} + +// Resource corresponds to resourcepb.Resource. +type Resource struct { + Attributes []*KeyValue `json:"attributes,omitempty"` + DroppedAttributesCount uint32 `json:"droppedAttributesCount,omitempty"` + EntityRefs []*EntityRef `json:"entityRefs,omitempty"` +} + +// ScopeSpans corresponds to tracepb.ScopeSpans. +type ScopeSpans struct { + Scope *InstrumentationScope `json:"scope,omitempty"` + Spans []*Span `json:"spans,omitempty"` + SchemaURL string `json:"schemaUrl,omitempty"` +} + +// InstrumentationScope corresponds to tracepb.InstrumentationScope. +type InstrumentationScope struct { + Name string `json:"name,omitempty"` + Version string `json:"version,omitempty"` + Attributes []*KeyValue `json:"attributes,omitempty"` + DroppedAttributesCount uint32 `json:"droppedAttributesCount,omitempty"` +} + +// EntityRef corresponds to resourcepb.EntityRef. +type EntityRef struct { + SchemaURL string `json:"schemaUrl,omitempty"` + Type string `json:"type,omitempty"` + IdKeys []string `json:"idKeys,omitempty"` + DescriptionKeys []string `json:"descriptionKeys,omitempty"` +} + +// KeyValue corresponds to commonpb.KeyValue. +type KeyValue struct { + Key string `json:"key"` + Value *AnyValue `json:"value,omitempty"` +} + +// AnyValue corresponds to commonpb.AnyValue. +type AnyValue struct { + StringValue *string `json:"stringValue,omitempty"` + BoolValue *bool `json:"boolValue,omitempty"` + IntValue *Int64 `json:"intValue,omitempty"` + DoubleValue *Float64 `json:"doubleValue,omitempty"` + ArrayValue *ArrayValue `json:"arrayValue,omitempty"` + KvlistValue *KvlistValue `json:"kvlistValue,omitempty"` + BytesValue []byte `json:"bytesValue,omitempty"` +} + +// ArrayValue corresponds to commonpb.ArrayValue. +type ArrayValue struct { + Values []*AnyValue `json:"values,omitempty"` +} + +// KvlistValue corresponds to commonpb.KeyValueList. +type KvlistValue struct { + Values []*KeyValue `json:"values,omitempty"` +} + +// Span corresponds to tracepb.Span. +type Span struct { + TraceID TraceID `json:"traceId"` + SpanID SpanID `json:"spanId"` + TraceState string `json:"traceState,omitempty"` + ParentSpanID *SpanID `json:"parentSpanId,omitempty"` + Flags uint32 `json:"flags,omitempty"` + Name string `json:"name,omitempty"` + Kind int32 `json:"kind,omitempty"` + StartTimeUnixNano Uint64 `json:"startTimeUnixNano,omitempty"` + EndTimeUnixNano Uint64 `json:"endTimeUnixNano,omitempty"` + Attributes []*KeyValue `json:"attributes,omitempty"` + DroppedAttributesCount uint32 `json:"droppedAttributesCount,omitempty"` + Events []*Event `json:"events,omitempty"` + DroppedEventsCount uint32 `json:"droppedEventsCount,omitempty"` + Links []*Link `json:"links,omitempty"` + DroppedLinksCount uint32 `json:"droppedLinksCount,omitempty"` + Status *Status `json:"status,omitempty"` +} + +// Event corresponds to tracepb.Span_Event. +type Event struct { + TimeUnixNano Uint64 `json:"timeUnixNano,omitempty"` + Name string `json:"name,omitempty"` + Attributes []*KeyValue `json:"attributes,omitempty"` + DroppedAttributesCount uint32 `json:"droppedAttributesCount,omitempty"` +} + +// Link corresponds to tracepb.Span_Link. +type Link struct { + TraceID TraceID `json:"traceId"` + SpanID SpanID `json:"spanId"` + TraceState string `json:"traceState,omitempty"` + Attributes []*KeyValue `json:"attributes,omitempty"` + DroppedAttributesCount uint32 `json:"droppedAttributesCount,omitempty"` + Flags uint32 `json:"flags,omitempty"` +} + +// Status corresponds to tracepb.Status. +type Status struct { + Message string `json:"message,omitempty"` + Code int32 `json:"code,omitempty"` +} + +// MarshalExportTraceServiceRequest encodes an ExportTraceServiceRequest as JSON Protobuf encoded bytes. +func MarshalExportTraceServiceRequest(req *coltracepb.ExportTraceServiceRequest) ([]byte, error) { + if req == nil { + return []byte("{}"), nil + } + r := &ExportTraceServiceRequest{} + for _, rs := range req.ResourceSpans { + r.ResourceSpans = append(r.ResourceSpans, encodeResourceSpans(rs)) + } + return json.Marshal(r) +} + +func encodeResourceSpans(rs *tracepb.ResourceSpans) *ResourceSpans { + if rs == nil { + return nil + } + out := &ResourceSpans{SchemaURL: rs.SchemaUrl} + if rs.Resource != nil { + out.Resource = &Resource{ + Attributes: encodeKeyValues(rs.Resource.Attributes), + DroppedAttributesCount: rs.Resource.DroppedAttributesCount, + EntityRefs: encodeEntityRefs(rs.Resource.EntityRefs), + } + } + for _, ss := range rs.ScopeSpans { + out.ScopeSpans = append(out.ScopeSpans, encodeScopeSpans(ss)) + } + return out +} + +func encodeEntityRefs(ers []*commonpb.EntityRef) []*EntityRef { + if len(ers) == 0 { + return nil + } + out := make([]*EntityRef, len(ers)) + for i, er := range ers { + if er == nil { + continue + } + out[i] = &EntityRef{ + SchemaURL: er.SchemaUrl, + Type: er.Type, + IdKeys: er.IdKeys, + DescriptionKeys: er.DescriptionKeys, + } + } + return out +} + +func encodeScopeSpans(ss *tracepb.ScopeSpans) *ScopeSpans { + if ss == nil { + return nil + } + out := &ScopeSpans{SchemaURL: ss.SchemaUrl} + if ss.Scope != nil { + out.Scope = &InstrumentationScope{ + Name: ss.Scope.Name, + Version: ss.Scope.Version, + Attributes: encodeKeyValues(ss.Scope.Attributes), + DroppedAttributesCount: ss.Scope.DroppedAttributesCount, + } + } + for _, s := range ss.Spans { + out.Spans = append(out.Spans, encodeSpan(s)) + } + return out +} + +func encodeSpan(s *tracepb.Span) *Span { + if s == nil { + return nil + } + out := &Span{ + TraceState: s.TraceState, + Flags: s.Flags, + Name: s.Name, + Kind: int32(s.Kind), + StartTimeUnixNano: Uint64(s.StartTimeUnixNano), + EndTimeUnixNano: Uint64(s.EndTimeUnixNano), + Attributes: encodeKeyValues(s.Attributes), + DroppedAttributesCount: s.DroppedAttributesCount, + DroppedEventsCount: s.DroppedEventsCount, + DroppedLinksCount: s.DroppedLinksCount, + } + + copy(out.TraceID[:], s.TraceId) + copy(out.SpanID[:], s.SpanId) + + if len(s.ParentSpanId) > 0 { + var psid SpanID + copy(psid[:], s.ParentSpanId) + if psid != (SpanID{}) { + out.ParentSpanID = &psid + } + } + + for _, e := range s.Events { + if e == nil { + continue + } + out.Events = append(out.Events, &Event{ + TimeUnixNano: Uint64(e.TimeUnixNano), + Name: e.Name, + Attributes: encodeKeyValues(e.Attributes), + DroppedAttributesCount: e.DroppedAttributesCount, + }) + } + for _, l := range s.Links { + out.Links = append(out.Links, encodeLink(l)) + } + if s.Status != nil { + out.Status = &Status{ + Message: s.Status.Message, + Code: int32(s.Status.Code), + } + } + return out +} + +func encodeLink(l *tracepb.Span_Link) *Link { + if l == nil { + return nil + } + out := &Link{ + TraceState: l.TraceState, + Attributes: encodeKeyValues(l.Attributes), + DroppedAttributesCount: l.DroppedAttributesCount, + Flags: l.Flags, + } + copy(out.TraceID[:], l.TraceId) + copy(out.SpanID[:], l.SpanId) + return out +} + +func encodeKeyValues(kvs []*commonpb.KeyValue) []*KeyValue { + if len(kvs) == 0 { + return nil + } + out := make([]*KeyValue, len(kvs)) + for i, kv := range kvs { + if kv == nil { + continue + } + out[i] = &KeyValue{ + Key: kv.Key, + Value: encodeAnyValue(kv.Value), + } + } + return out +} + +func encodeAnyValue(av *commonpb.AnyValue) *AnyValue { + if av == nil { + return nil + } + out := &AnyValue{} + switch v := av.Value.(type) { + case *commonpb.AnyValue_StringValue: + out.StringValue = &v.StringValue + case *commonpb.AnyValue_BoolValue: + out.BoolValue = &v.BoolValue + case *commonpb.AnyValue_IntValue: + iv := Int64(v.IntValue) + out.IntValue = &iv + case *commonpb.AnyValue_DoubleValue: + dv := Float64(v.DoubleValue) + out.DoubleValue = &dv + case *commonpb.AnyValue_ArrayValue: + if v.ArrayValue != nil { + arr := &ArrayValue{} + for _, val := range v.ArrayValue.Values { + arr.Values = append(arr.Values, encodeAnyValue(val)) + } + out.ArrayValue = arr + } + case *commonpb.AnyValue_KvlistValue: + if v.KvlistValue != nil { + out.KvlistValue = &KvlistValue{ + Values: encodeKeyValues(v.KvlistValue.Values), + } + } + case *commonpb.AnyValue_BytesValue: + out.BytesValue = v.BytesValue + } + return out +} + +// UnmarshalExportTraceServiceRequest decodes JSON Protobuf encoded payload into an ExportTraceServiceRequest. +func UnmarshalExportTraceServiceRequest(data []byte, req *coltracepb.ExportTraceServiceRequest) error { + var jr ExportTraceServiceRequest + if err := json.Unmarshal(data, &jr); err != nil { + return err + } + + for _, rs := range jr.ResourceSpans { + req.ResourceSpans = append(req.ResourceSpans, decodeResourceSpans(rs)) + } + return nil +} + +func decodeResourceSpans(jrs *ResourceSpans) *tracepb.ResourceSpans { + rs := &tracepb.ResourceSpans{SchemaUrl: jrs.SchemaURL} + if jrs.Resource != nil { + rs.Resource = &resourcepb.Resource{ + Attributes: decodeKeyValues(jrs.Resource.Attributes), + DroppedAttributesCount: jrs.Resource.DroppedAttributesCount, + EntityRefs: decodeEntityRefs(jrs.Resource.EntityRefs), + } + } + for _, ss := range jrs.ScopeSpans { + rs.ScopeSpans = append(rs.ScopeSpans, decodeScopeSpans(ss)) + } + return rs +} + +func decodeEntityRefs(jers []*EntityRef) []*commonpb.EntityRef { + if len(jers) == 0 { + return nil + } + ers := make([]*commonpb.EntityRef, len(jers)) + for i, jer := range jers { + if jer == nil { + continue + } + ers[i] = &commonpb.EntityRef{ + SchemaUrl: jer.SchemaURL, + Type: jer.Type, + IdKeys: jer.IdKeys, + DescriptionKeys: jer.DescriptionKeys, + } + } + return ers +} + +func decodeScopeSpans(jss *ScopeSpans) *tracepb.ScopeSpans { + ss := &tracepb.ScopeSpans{SchemaUrl: jss.SchemaURL} + if jss.Scope != nil { + ss.Scope = &commonpb.InstrumentationScope{ + Name: jss.Scope.Name, + Version: jss.Scope.Version, + Attributes: decodeKeyValues(jss.Scope.Attributes), + DroppedAttributesCount: jss.Scope.DroppedAttributesCount, + } + } + for _, s := range jss.Spans { + ss.Spans = append(ss.Spans, decodeSpan(s)) + } + return ss +} + +func decodeSpan(js *Span) *tracepb.Span { + s := &tracepb.Span{ + TraceId: js.TraceID[:], + SpanId: js.SpanID[:], + TraceState: js.TraceState, + Flags: js.Flags, + Name: js.Name, + Kind: tracepb.Span_SpanKind(js.Kind), + StartTimeUnixNano: uint64(js.StartTimeUnixNano), + EndTimeUnixNano: uint64(js.EndTimeUnixNano), + Attributes: decodeKeyValues(js.Attributes), + DroppedAttributesCount: js.DroppedAttributesCount, + DroppedEventsCount: js.DroppedEventsCount, + DroppedLinksCount: js.DroppedLinksCount, + } + if js.ParentSpanID != nil { + s.ParentSpanId = js.ParentSpanID[:] + } + for _, e := range js.Events { + s.Events = append(s.Events, &tracepb.Span_Event{ + TimeUnixNano: uint64(e.TimeUnixNano), + Name: e.Name, + Attributes: decodeKeyValues(e.Attributes), + DroppedAttributesCount: e.DroppedAttributesCount, + }) + } + for _, l := range js.Links { + s.Links = append(s.Links, decodeLink(l)) + } + if js.Status != nil { + s.Status = &tracepb.Status{ + Message: js.Status.Message, + Code: tracepb.Status_StatusCode(js.Status.Code), + } + } + return s +} + +func decodeLink(jl *Link) *tracepb.Span_Link { + return &tracepb.Span_Link{ + TraceId: jl.TraceID[:], + SpanId: jl.SpanID[:], + TraceState: jl.TraceState, + Attributes: decodeKeyValues(jl.Attributes), + DroppedAttributesCount: jl.DroppedAttributesCount, + Flags: jl.Flags, + } +} + +func decodeKeyValues(jkvs []*KeyValue) []*commonpb.KeyValue { + if len(jkvs) == 0 { + return nil + } + kvs := make([]*commonpb.KeyValue, len(jkvs)) + for i, jkv := range jkvs { + kvs[i] = &commonpb.KeyValue{ + Key: jkv.Key, + Value: decodeAnyValue(jkv.Value), + } + } + return kvs +} + +func decodeAnyValue(jav *AnyValue) *commonpb.AnyValue { + if jav == nil { + return nil + } + av := &commonpb.AnyValue{} + switch { + case jav.StringValue != nil: + av.Value = &commonpb.AnyValue_StringValue{StringValue: *jav.StringValue} + case jav.BoolValue != nil: + av.Value = &commonpb.AnyValue_BoolValue{BoolValue: *jav.BoolValue} + case jav.IntValue != nil: + av.Value = &commonpb.AnyValue_IntValue{IntValue: int64(*jav.IntValue)} + case jav.DoubleValue != nil: + av.Value = &commonpb.AnyValue_DoubleValue{DoubleValue: float64(*jav.DoubleValue)} + case jav.ArrayValue != nil: + arr := &commonpb.ArrayValue{} + for _, v := range jav.ArrayValue.Values { + arr.Values = append(arr.Values, decodeAnyValue(v)) + } + av.Value = &commonpb.AnyValue_ArrayValue{ArrayValue: arr} + case jav.KvlistValue != nil: + av.Value = &commonpb.AnyValue_KvlistValue{ + KvlistValue: &commonpb.KeyValueList{ + Values: decodeKeyValues(jav.KvlistValue.Values), + }, + } + case jav.BytesValue != nil: + av.Value = &commonpb.AnyValue_BytesValue{BytesValue: jav.BytesValue} + } + return av +} + +// Float64 encodes non-finite values as strings per ProtoJSON specs. +type Float64 float64 + +func (f Float64) MarshalJSON() ([]byte, error) { + switch value := float64(f); { + case math.IsNaN(value): + return []byte(`"NaN"`), nil + case math.IsInf(value, 1): + return []byte(`"Infinity"`), nil + case math.IsInf(value, -1): + return []byte(`"-Infinity"`), nil + default: + return strconv.AppendFloat(nil, value, 'g', -1, 64), nil + } +} + +func (f *Float64) UnmarshalJSON(data []byte) error { + var str string + if err := json.Unmarshal(data, &str); err == nil { + switch str { + case "NaN": + *f = Float64(math.NaN()) + case "Infinity": + *f = Float64(math.Inf(1)) + case "-Infinity": + *f = Float64(math.Inf(-1)) + default: + var value *float64 + if str != strings.TrimSpace(str) || json.Unmarshal([]byte(str), &value) != nil || value == nil { + return fmt.Errorf("invalid float value %q", str) + } + *f = Float64(*value) + } + return nil + } + + var value float64 + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *f = Float64(value) + return nil +} + +// Int64 encodes int64 as a quoted decimal string per ProtoJSON specs. +type Int64 int64 + +func (i Int64) MarshalJSON() ([]byte, error) { + return []byte(`"` + strconv.FormatInt(int64(i), 10) + `"`), nil +} + +func (i *Int64) UnmarshalJSON(data []byte) error { + // expects either a string representation or a number + var s string + if err := json.Unmarshal(data, &s); err == nil { + v, err := strconv.ParseInt(s, 10, 64) + if err != nil { + return err + } + *i = Int64(v) + return nil + } + var v int64 + if err := json.Unmarshal(data, &v); err != nil { + return err + } + *i = Int64(v) + return nil +} + +// Uint64 encodes uint64 as a quoted decimal string per ProtoJSON specs. +type Uint64 uint64 + +func (i Uint64) MarshalJSON() ([]byte, error) { + return []byte(`"` + strconv.FormatUint(uint64(i), 10) + `"`), nil +} + +func (i *Uint64) UnmarshalJSON(data []byte) error { + // expects either a string representation or a number + var s string + if err := json.Unmarshal(data, &s); err == nil { + v, err := strconv.ParseUint(s, 10, 64) + if err != nil { + return err + } + *i = Uint64(v) + return nil + } + var v uint64 + if err := json.Unmarshal(data, &v); err != nil { + return err + } + *i = Uint64(v) + return nil +} + +const base16Alphabets = "0123456789ABCDEF" + +// TraceID encodes a 16-byte trace ID as a case-insensitive hex-encoded string. +type TraceID [16]byte + +func (t TraceID) MarshalJSON() ([]byte, error) { + var b [34]byte + b[0] = '"' + for i, v := range t { + b[1+i*2] = base16Alphabets[v>>4] + b[2+i*2] = base16Alphabets[v&0x0f] + } + b[33] = '"' + return b[:], nil +} + +func (t *TraceID) UnmarshalJSON(data []byte) error { + var str string + if err := json.Unmarshal(data, &str); err != nil { + return err + } + b, err := hex.DecodeString(str) + if err != nil { + return err + } + if len(b) != len(t) { + return fmt.Errorf("invalid trace ID length: got %d, want %d", len(b), len(t)) + } + copy(t[:], b) + return nil +} + +// SpanID encodes an 8-byte span ID as a case-insensitive hex-encoded string. +type SpanID [8]byte + +func (s SpanID) MarshalJSON() ([]byte, error) { + var b [18]byte + b[0] = '"' + for i, v := range s { + b[1+i*2] = base16Alphabets[v>>4] + b[2+i*2] = base16Alphabets[v&0x0f] + } + b[17] = '"' + return b[:], nil +} + +func (s *SpanID) UnmarshalJSON(data []byte) error { + var str string + if err := json.Unmarshal(data, &str); err != nil { + return err + } + b, err := hex.DecodeString(str) + if err != nil { + return err + } + if len(b) != len(s) { + return fmt.Errorf("invalid span ID length: got %d, want %d", len(b), len(s)) + } + copy(s[:], b) + return nil +} diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/otlpjson/export_trace_service_response.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/otlpjson/export_trace_service_response.go new file mode 100644 index 000000000..03e189a1a --- /dev/null +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/otlpjson/export_trace_service_response.go @@ -0,0 +1,22 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package otlpjson + +import ( + coltracepb "go.opentelemetry.io/proto/otlp/collector/trace/v1" + "google.golang.org/protobuf/encoding/protojson" +) + +// MarshalExportTraceServiceResponse encodes an ExportTraceServiceResponse as JSON Protobuf encoded bytes. +func MarshalExportTraceServiceResponse(resp *coltracepb.ExportTraceServiceResponse) ([]byte, error) { + return protojson.Marshal(resp) +} + +// UnmarshalExportTraceServiceResponse decodes JSON Protobuf encoded payload into an ExportTraceServiceResponse. +func UnmarshalExportTraceServiceResponse(data []byte, resp *coltracepb.ExportTraceServiceResponse) error { + // ignore message fields with unknown names per OTLP specs. + var unmarshaler protojson.UnmarshalOptions + unmarshaler.DiscardUnknown = true + return unmarshaler.Unmarshal(data, resp) +} diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/partialsuccess.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/partialsuccess.go index 33ff6c024..1138f2e71 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/partialsuccess.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/partialsuccess.go @@ -1,10 +1,10 @@ -// Code generated by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/partialsuccess.go - // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package internal // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal" +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/otlp/partialsuccess.go + +package internal import "fmt" @@ -41,7 +41,7 @@ func (ps PartialSuccess) As(target any) bool { } // Is supports the errors.Is() interface. -func (ps PartialSuccess) Is(err error) bool { +func (PartialSuccess) Is(err error) bool { _, ok := err.(PartialSuccess) return ok } diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/retry/retry.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/retry/retry.go index bf3980825..468c7c8eb 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/retry/retry.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/retry/retry.go @@ -1,13 +1,13 @@ -// Code generated by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/retry/retry.go.tmpl - // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/otlp/retry/retry.go.tmpl + // Package retry provides request retry functionality that can perform // configurable exponential backoff for transient errors and honor any // explicit throttle responses received. -package retry // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/retry" +package retry import ( "context" @@ -17,7 +17,7 @@ import ( "github.com/cenkalti/backoff/v5" ) -// DefaultConfig are the recommended defaults to use. +// DefaultConfig is the recommended default configuration. var DefaultConfig = Config{ Enabled: true, InitialInterval: 5 * time.Second, @@ -25,42 +25,40 @@ var DefaultConfig = Config{ MaxElapsedTime: time.Minute, } -// Config defines configuration for retrying batches in case of export failure -// using an exponential backoff. +// Config defines configuration for retrying batches after an export failure +// using exponential backoff. type Config struct { - // Enabled indicates whether to not retry sending batches in case of - // export failure. + // Enabled indicates whether to retry sending batches after an export + // failure. Enabled bool - // InitialInterval the time to wait after the first failure before + // InitialInterval is the time to wait after the first failure before // retrying. InitialInterval time.Duration - // MaxInterval is the upper bound on backoff interval. Once this value is - // reached the delay between consecutive retries will always be - // `MaxInterval`. + // MaxInterval is the upper bound on the backoff interval before + // randomization. Once this value is reached, the base interval remains at + // MaxInterval. MaxInterval time.Duration // MaxElapsedTime is the maximum amount of time (including retries) spent - // trying to send a request/batch. Once this value is reached, the data - // is discarded. + // trying to send a request/batch. Once this value is reached, retrying stops. MaxElapsedTime time.Duration } // RequestFunc wraps a request with retry logic. type RequestFunc func(context.Context, func(context.Context) error) error -// EvaluateFunc returns if an error is retry-able and if an explicit throttle -// duration should be honored that was included in the error. +// EvaluateFunc reports whether an error is retryable and returns any explicit +// throttle duration to honor. // -// The function must return true if the error argument is retry-able, -// otherwise it must return false for the first return parameter. +// The function must return true as its first return value if the error +// argument is retryable; otherwise, it must return false. // -// The function must return a non-zero time.Duration if the error contains -// explicit throttle duration that should be honored, otherwise it must return -// a zero valued time.Duration. +// The function must return a nonzero time.Duration if the error contains an +// explicit throttle duration that should be honored; otherwise, it must return +// the zero value for time.Duration. type EvaluateFunc func(error) (bool, time.Duration) -// RequestFunc returns a RequestFunc using the evaluate function to determine -// if requests can be retried and based on the exponential backoff -// configuration of c. +// RequestFunc returns a RequestFunc that uses evaluate to determine whether +// requests can be retried and uses c to configure exponential backoff. func (c Config) RequestFunc(evaluate EvaluateFunc) RequestFunc { if !c.Enabled { return func(ctx context.Context, fn func(context.Context) error) error { @@ -96,7 +94,7 @@ func (c Config) RequestFunc(evaluate EvaluateFunc) RequestFunc { // Check if context is canceled before attempting to wait and retry. if ctx.Err() != nil { - return fmt.Errorf("%w: %w", ctx.Err(), err) + return fmt.Errorf("%w: %w", context.Cause(ctx), err) } if maxElapsedTime != 0 && time.Since(startTime) > maxElapsedTime { @@ -119,12 +117,12 @@ func (c Config) RequestFunc(evaluate EvaluateFunc) RequestFunc { } } -// Allow override for testing. +// waitFunc can be overridden for testing. var waitFunc = wait -// wait takes the caller's context, and the amount of time to wait. It will -// return nil if the timer fires before or at the same time as the context's -// deadline. This indicates that the call can be retried. +// wait blocks until delay elapses or ctx is done. If both happen +// simultaneously, wait favors the elapsed delay and returns nil to indicate +// that the call can be retried. func wait(ctx context.Context, delay time.Duration) error { timer := time.NewTimer(delay) defer timer.Stop() diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/version.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/version.go index 882b67138..87fcc4c6e 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/version.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/version.go @@ -1,8 +1,8 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package internal // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal" +package internal // Version is the current release version of the OpenTelemetry OTLP HTTP trace // exporter in use. -const Version = "1.44.0" +const Version = "1.46.0" diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/x/observ.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/x/observ.go index ecae4a79c..76b6fdebd 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/x/observ.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/x/observ.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package x // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/x" +package x import "strings" diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/x/x.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/x/x.go index 099dab007..8959afcf5 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/x/x.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/x/x.go @@ -1,11 +1,11 @@ -// Code generated by gotmpl. DO NOT MODIFY. -// source: internal/shared/x/x.go.tmpl - // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/x/x.go.tmpl + // Package x documents experimental features for [go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp]. -package x // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/x" +package x import ( "os" @@ -34,9 +34,9 @@ func newFeature[T any](suffix []string, parse func(string) (T, bool)) Feature[T] // feature. func (f Feature[T]) Keys() []string { return f.keys } -// Lookup returns the user configured value for the feature and true if the +// Lookup returns the user-configured value for the feature and true if the // user has enabled the feature. Otherwise, if the feature is not enabled, a -// zero-value and false are returned. +// zero value and false are returned. func (f Feature[T]) Lookup() (v T, ok bool) { // https://github.com/open-telemetry/opentelemetry-specification/blob/62effed618589a0bec416a87e559c0a9d96289bb/specification/configuration/sdk-environment-variables.md#parsing-empty-value // diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/options.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/options.go index 291b5f9b6..b17ac12e1 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/options.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/options.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package otlptracehttp // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp" +package otlptracehttp import ( "crypto/tls" @@ -17,6 +17,9 @@ import ( // collector. type Compression otlpconfig.Compression +// Encoding describes the encoding used for payloads sent to the collector. +type Encoding int + // HTTPTransportProxyFunc is a function that resolves which URL to use as proxy for a given request. // This type is compatible with http.Transport.Proxy and can be used to set a custom proxy function // to the OTLP HTTP client. @@ -31,6 +34,13 @@ const ( GzipCompression = Compression(otlpconfig.GzipCompression) ) +const ( + // EncodingProtobuf tells the driver to send protobuf-encoded payloads. + EncodingProtobuf Encoding = iota + // EncodingJSON tells the driver to send JSON-encoded payloads. + EncodingJSON +) + // Option applies an option to the HTTP client. type Option interface { applyHTTPOption(otlpconfig.Config) otlpconfig.Config @@ -93,6 +103,11 @@ func WithEndpoint(endpoint string) Option { // // If an invalid URL is provided, the default value will be kept. // +// The path of the provided URL is used as-is; with one exception: if the URL has +// no path, it is normalized to the root path ("/"). The default traces path +// ("/v1/traces") is not appended automatically. Use WithEndpoint if you want +// that behavior, or pass a URL that includes that path. +// // By default, if an environment variable is not set, and this option is not // passed, "localhost:4318" will be used. // @@ -106,6 +121,15 @@ func WithCompression(compression Compression) Option { return wrappedOption{otlpconfig.WithCompression(otlpconfig.Compression(compression))} } +// WithEncoding tells the driver to use a specific encoding for the request payload. +func WithEncoding(encoding Encoding) Option { + protocol := otlpconfig.ProtocolHTTPProtobuf + if encoding == EncodingJSON { + protocol = otlpconfig.ProtocolHTTPJSON + } + return wrappedOption{otlpconfig.WithProtocol(protocol)} +} + // WithURLPath allows one to override the default URL path used // for sending traces. If unset, default ("/v1/traces") will be used. func WithURLPath(urlPath string) Option { diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/version.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/version.go index d847210db..fd8ee8102 100644 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/version.go +++ b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/version.go @@ -1,9 +1,9 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package otlptrace // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace" +package otlptrace // Version is the current release version of the OpenTelemetry OTLP trace exporter in use. func Version() string { - return "1.44.0" + return "1.46.0" } diff --git a/vendor/go.opentelemetry.io/otel/handler.go b/vendor/go.opentelemetry.io/otel/handler.go index 07623b679..1f45ea388 100644 --- a/vendor/go.opentelemetry.io/otel/handler.go +++ b/vendor/go.opentelemetry.io/otel/handler.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package otel // import "go.opentelemetry.io/otel" +package otel import ( "go.opentelemetry.io/otel/internal/global" diff --git a/vendor/go.opentelemetry.io/otel/internal/baggage/baggage.go b/vendor/go.opentelemetry.io/otel/internal/baggage/baggage.go index b4f85f44a..cbeb14fcd 100644 --- a/vendor/go.opentelemetry.io/otel/internal/baggage/baggage.go +++ b/vendor/go.opentelemetry.io/otel/internal/baggage/baggage.go @@ -10,7 +10,7 @@ this need this package would not need to exist and the `go.opentelemetry.io/otel/baggage` package would be the singular place where W3C baggage is handled. */ -package baggage // import "go.opentelemetry.io/otel/internal/baggage" +package baggage // List is the collection of baggage members. The W3C allows for duplicates, // but OpenTelemetry does not, therefore, this is represented as a map. diff --git a/vendor/go.opentelemetry.io/otel/internal/baggage/context.go b/vendor/go.opentelemetry.io/otel/internal/baggage/context.go index 3aea9c491..f3bece165 100644 --- a/vendor/go.opentelemetry.io/otel/internal/baggage/context.go +++ b/vendor/go.opentelemetry.io/otel/internal/baggage/context.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package baggage // import "go.opentelemetry.io/otel/internal/baggage" +package baggage import "context" diff --git a/vendor/go.opentelemetry.io/otel/internal/errorhandler/errorhandler.go b/vendor/go.opentelemetry.io/otel/internal/errorhandler/errorhandler.go index 3f0ab3131..de294461c 100644 --- a/vendor/go.opentelemetry.io/otel/internal/errorhandler/errorhandler.go +++ b/vendor/go.opentelemetry.io/otel/internal/errorhandler/errorhandler.go @@ -5,7 +5,7 @@ // // This package has no OTel dependencies, allowing it to be imported by any // package in the module without creating import cycles. -package errorhandler // import "go.opentelemetry.io/otel/internal/errorhandler" +package errorhandler import ( "errors" diff --git a/vendor/go.opentelemetry.io/otel/internal/global/handler.go b/vendor/go.opentelemetry.io/otel/internal/global/handler.go index 77d0425f5..6fb8034f8 100644 --- a/vendor/go.opentelemetry.io/otel/internal/global/handler.go +++ b/vendor/go.opentelemetry.io/otel/internal/global/handler.go @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // Package global provides the OpenTelemetry global API. -package global // import "go.opentelemetry.io/otel/internal/global" +package global import ( "go.opentelemetry.io/otel/internal/errorhandler" diff --git a/vendor/go.opentelemetry.io/otel/internal/global/instruments.go b/vendor/go.opentelemetry.io/otel/internal/global/instruments.go index 55255cddf..4db3fdcde 100644 --- a/vendor/go.opentelemetry.io/otel/internal/global/instruments.go +++ b/vendor/go.opentelemetry.io/otel/internal/global/instruments.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package global // import "go.opentelemetry.io/otel/internal/global" +package global import ( "context" diff --git a/vendor/go.opentelemetry.io/otel/internal/global/internal_logging.go b/vendor/go.opentelemetry.io/otel/internal/global/internal_logging.go index 86d7f4ba0..8e1327354 100644 --- a/vendor/go.opentelemetry.io/otel/internal/global/internal_logging.go +++ b/vendor/go.opentelemetry.io/otel/internal/global/internal_logging.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package global // import "go.opentelemetry.io/otel/internal/global" +package global import ( "log" diff --git a/vendor/go.opentelemetry.io/otel/internal/global/meter.go b/vendor/go.opentelemetry.io/otel/internal/global/meter.go index 50043d669..48be49037 100644 --- a/vendor/go.opentelemetry.io/otel/internal/global/meter.go +++ b/vendor/go.opentelemetry.io/otel/internal/global/meter.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package global // import "go.opentelemetry.io/otel/internal/global" +package global import ( "container/list" diff --git a/vendor/go.opentelemetry.io/otel/internal/global/propagator.go b/vendor/go.opentelemetry.io/otel/internal/global/propagator.go index 38560ff99..90c462ef0 100644 --- a/vendor/go.opentelemetry.io/otel/internal/global/propagator.go +++ b/vendor/go.opentelemetry.io/otel/internal/global/propagator.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package global // import "go.opentelemetry.io/otel/internal/global" +package global import ( "context" diff --git a/vendor/go.opentelemetry.io/otel/internal/global/state.go b/vendor/go.opentelemetry.io/otel/internal/global/state.go index 225c9e501..f8fcb82bc 100644 --- a/vendor/go.opentelemetry.io/otel/internal/global/state.go +++ b/vendor/go.opentelemetry.io/otel/internal/global/state.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package global // import "go.opentelemetry.io/otel/internal/global" +package global import ( "errors" diff --git a/vendor/go.opentelemetry.io/otel/internal/global/trace.go b/vendor/go.opentelemetry.io/otel/internal/global/trace.go index bf5cf3119..45899f8c0 100644 --- a/vendor/go.opentelemetry.io/otel/internal/global/trace.go +++ b/vendor/go.opentelemetry.io/otel/internal/global/trace.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package global // import "go.opentelemetry.io/otel/internal/global" +package global /* This file contains the forwarding implementation of the TracerProvider used as diff --git a/vendor/go.opentelemetry.io/otel/internal_logging.go b/vendor/go.opentelemetry.io/otel/internal_logging.go index 6de7f2e4d..3f6b7b10d 100644 --- a/vendor/go.opentelemetry.io/otel/internal_logging.go +++ b/vendor/go.opentelemetry.io/otel/internal_logging.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package otel // import "go.opentelemetry.io/otel" +package otel import ( "github.com/go-logr/logr" diff --git a/vendor/go.opentelemetry.io/otel/metric.go b/vendor/go.opentelemetry.io/otel/metric.go index 527d9aec8..30dbb4118 100644 --- a/vendor/go.opentelemetry.io/otel/metric.go +++ b/vendor/go.opentelemetry.io/otel/metric.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package otel // import "go.opentelemetry.io/otel" +package otel import ( "go.opentelemetry.io/otel/internal/global" diff --git a/vendor/go.opentelemetry.io/otel/metric/asyncfloat64.go b/vendor/go.opentelemetry.io/otel/metric/asyncfloat64.go index 1d21e2eb7..11e5b282f 100644 --- a/vendor/go.opentelemetry.io/otel/metric/asyncfloat64.go +++ b/vendor/go.opentelemetry.io/otel/metric/asyncfloat64.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package metric // import "go.opentelemetry.io/otel/metric" +package metric import ( "context" diff --git a/vendor/go.opentelemetry.io/otel/metric/asyncint64.go b/vendor/go.opentelemetry.io/otel/metric/asyncint64.go index 9d45a4d41..f5577b0c5 100644 --- a/vendor/go.opentelemetry.io/otel/metric/asyncint64.go +++ b/vendor/go.opentelemetry.io/otel/metric/asyncint64.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package metric // import "go.opentelemetry.io/otel/metric" +package metric import ( "context" diff --git a/vendor/go.opentelemetry.io/otel/metric/config.go b/vendor/go.opentelemetry.io/otel/metric/config.go index 889545e23..31a5da817 100644 --- a/vendor/go.opentelemetry.io/otel/metric/config.go +++ b/vendor/go.opentelemetry.io/otel/metric/config.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package metric // import "go.opentelemetry.io/otel/metric" +package metric import ( "slices" diff --git a/vendor/go.opentelemetry.io/otel/metric/doc.go b/vendor/go.opentelemetry.io/otel/metric/doc.go index 794e1a8ba..235e81f3a 100644 --- a/vendor/go.opentelemetry.io/otel/metric/doc.go +++ b/vendor/go.opentelemetry.io/otel/metric/doc.go @@ -201,4 +201,4 @@ fully implement all the API interfaces when a user updates their API. [OpenTelemetry documentation]: https://opentelemetry.io/docs/concepts/signals/metrics/ [GetMeterProvider]: https://pkg.go.dev/go.opentelemetry.io/otel#GetMeterProvider */ -package metric // import "go.opentelemetry.io/otel/metric" +package metric diff --git a/vendor/go.opentelemetry.io/otel/metric/embedded/embedded.go b/vendor/go.opentelemetry.io/otel/metric/embedded/embedded.go index 1a9dc6809..10f361b5b 100644 --- a/vendor/go.opentelemetry.io/otel/metric/embedded/embedded.go +++ b/vendor/go.opentelemetry.io/otel/metric/embedded/embedded.go @@ -11,7 +11,7 @@ // the API package). // // [OpenTelemetry metric API]: https://pkg.go.dev/go.opentelemetry.io/otel/metric -package embedded // import "go.opentelemetry.io/otel/metric/embedded" +package embedded // MeterProvider is embedded in // [go.opentelemetry.io/otel/metric.MeterProvider]. diff --git a/vendor/go.opentelemetry.io/otel/metric/instrument.go b/vendor/go.opentelemetry.io/otel/metric/instrument.go index 2e79ab568..e8c1c96cb 100644 --- a/vendor/go.opentelemetry.io/otel/metric/instrument.go +++ b/vendor/go.opentelemetry.io/otel/metric/instrument.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package metric // import "go.opentelemetry.io/otel/metric" +package metric import ( "go.opentelemetry.io/otel/attribute" diff --git a/vendor/go.opentelemetry.io/otel/metric/meter.go b/vendor/go.opentelemetry.io/otel/metric/meter.go index 5606ec4bd..70ff4c731 100644 --- a/vendor/go.opentelemetry.io/otel/metric/meter.go +++ b/vendor/go.opentelemetry.io/otel/metric/meter.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package metric // import "go.opentelemetry.io/otel/metric" +package metric import ( "context" diff --git a/vendor/go.opentelemetry.io/otel/metric/noop/noop.go b/vendor/go.opentelemetry.io/otel/metric/noop/noop.go index 634e73aee..80c0f2f22 100644 --- a/vendor/go.opentelemetry.io/otel/metric/noop/noop.go +++ b/vendor/go.opentelemetry.io/otel/metric/noop/noop.go @@ -10,7 +10,7 @@ // This implementation can be embedded in other implementations of the // OpenTelemetry metric API. Doing so will mean the implementation defaults to // no operation for methods it does not implement. -package noop // import "go.opentelemetry.io/otel/metric/noop" +package noop import ( "context" diff --git a/vendor/go.opentelemetry.io/otel/metric/syncfloat64.go b/vendor/go.opentelemetry.io/otel/metric/syncfloat64.go index 2101f686a..2770ac2dc 100644 --- a/vendor/go.opentelemetry.io/otel/metric/syncfloat64.go +++ b/vendor/go.opentelemetry.io/otel/metric/syncfloat64.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package metric // import "go.opentelemetry.io/otel/metric" +package metric import ( "context" @@ -158,6 +158,8 @@ type Float64Histogram interface { // Record adds an additional value to the distribution. // + // The incr value is expected to be non-negative. + // // Use the WithAttributeSet (or, if performance is not a concern, // the WithAttributes) option to include measurement attributes. // diff --git a/vendor/go.opentelemetry.io/otel/metric/syncint64.go b/vendor/go.opentelemetry.io/otel/metric/syncint64.go index 425c1a0d5..c8a739c90 100644 --- a/vendor/go.opentelemetry.io/otel/metric/syncint64.go +++ b/vendor/go.opentelemetry.io/otel/metric/syncint64.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package metric // import "go.opentelemetry.io/otel/metric" +package metric import ( "context" @@ -158,6 +158,8 @@ type Int64Histogram interface { // Record adds an additional value to the distribution. // + // The incr value is expected to be non-negative. + // // Use the WithAttributeSet (or, if performance is not a concern, // the WithAttributes) option to include measurement attributes. // diff --git a/vendor/go.opentelemetry.io/otel/propagation.go b/vendor/go.opentelemetry.io/otel/propagation.go index 2fd949733..05e9b11ce 100644 --- a/vendor/go.opentelemetry.io/otel/propagation.go +++ b/vendor/go.opentelemetry.io/otel/propagation.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package otel // import "go.opentelemetry.io/otel" +package otel import ( "go.opentelemetry.io/otel/internal/global" diff --git a/vendor/go.opentelemetry.io/otel/propagation/baggage.go b/vendor/go.opentelemetry.io/otel/propagation/baggage.go index d81b709a2..9d7ef7c89 100644 --- a/vendor/go.opentelemetry.io/otel/propagation/baggage.go +++ b/vendor/go.opentelemetry.io/otel/propagation/baggage.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package propagation // import "go.opentelemetry.io/otel/propagation" +package propagation import ( "context" diff --git a/vendor/go.opentelemetry.io/otel/propagation/doc.go b/vendor/go.opentelemetry.io/otel/propagation/doc.go index 33a3baf15..6e2bbbb18 100644 --- a/vendor/go.opentelemetry.io/otel/propagation/doc.go +++ b/vendor/go.opentelemetry.io/otel/propagation/doc.go @@ -10,4 +10,4 @@ package is the W3C Trace Context encoding (https://www.w3.org/TR/trace-context/), and W3C Baggage (https://www.w3.org/TR/baggage/). */ -package propagation // import "go.opentelemetry.io/otel/propagation" +package propagation diff --git a/vendor/go.opentelemetry.io/otel/propagation/propagation.go b/vendor/go.opentelemetry.io/otel/propagation/propagation.go index 0a32c59aa..a3891fbe7 100644 --- a/vendor/go.opentelemetry.io/otel/propagation/propagation.go +++ b/vendor/go.opentelemetry.io/otel/propagation/propagation.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package propagation // import "go.opentelemetry.io/otel/propagation" +package propagation import ( "context" diff --git a/vendor/go.opentelemetry.io/otel/propagation/trace_context.go b/vendor/go.opentelemetry.io/otel/propagation/trace_context.go index 11f404deb..ffaa90303 100644 --- a/vendor/go.opentelemetry.io/otel/propagation/trace_context.go +++ b/vendor/go.opentelemetry.io/otel/propagation/trace_context.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package propagation // import "go.opentelemetry.io/otel/propagation" +package propagation import ( "context" diff --git a/vendor/go.opentelemetry.io/otel/sdk/instrumentation/doc.go b/vendor/go.opentelemetry.io/otel/sdk/instrumentation/doc.go index a4faa6a03..39b34eabe 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/instrumentation/doc.go +++ b/vendor/go.opentelemetry.io/otel/sdk/instrumentation/doc.go @@ -10,4 +10,4 @@ // and // https://github.com/open-telemetry/oteps/blob/d226b677d73a785523fe9b9701be13225ebc528d/text/0201-scope-attributes.md // for more information. -package instrumentation // import "go.opentelemetry.io/otel/sdk/instrumentation" +package instrumentation diff --git a/vendor/go.opentelemetry.io/otel/sdk/instrumentation/library.go b/vendor/go.opentelemetry.io/otel/sdk/instrumentation/library.go index f2cdf3c65..8baf8dbb3 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/instrumentation/library.go +++ b/vendor/go.opentelemetry.io/otel/sdk/instrumentation/library.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package instrumentation // import "go.opentelemetry.io/otel/sdk/instrumentation" +package instrumentation // Library represents the instrumentation library. // diff --git a/vendor/go.opentelemetry.io/otel/sdk/instrumentation/scope.go b/vendor/go.opentelemetry.io/otel/sdk/instrumentation/scope.go index 34852a47b..1fd06db75 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/instrumentation/scope.go +++ b/vendor/go.opentelemetry.io/otel/sdk/instrumentation/scope.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package instrumentation // import "go.opentelemetry.io/otel/sdk/instrumentation" +package instrumentation import "go.opentelemetry.io/otel/attribute" diff --git a/vendor/go.opentelemetry.io/otel/sdk/internal/attrnorm/dedup.go b/vendor/go.opentelemetry.io/otel/sdk/internal/attrnorm/dedup.go new file mode 100644 index 000000000..fe9ddc96d --- /dev/null +++ b/vendor/go.opentelemetry.io/otel/sdk/internal/attrnorm/dedup.go @@ -0,0 +1,300 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/attrnorm/dedup.go.tmpl + +// Package attrnorm normalizes attribute values. +package attrnorm + +import ( + "reflect" + "unsafe" + + "go.opentelemetry.io/otel/attribute" +) + +var ( + keyValueType = reflect.TypeFor[attribute.KeyValue]() + valueType = reflect.TypeFor[attribute.Value]() +) + +// rawValue mirrors attribute.Value. It is used only to read immutable slice +// storage without calling AsMap or AsSlice on no-op paths. +type rawValue struct { + vtype attribute.Type + numeric uint64 + stringly string + slice any +} + +// Value returns value with all map values deduplicated and whether it changed. +// +// Duplicate map keys are resolved using last-value-wins semantics. +func Value(value attribute.Value) (attribute.Value, bool) { + switch value.Type() { + case attribute.SLICE: + return deduplicateSliceValue(value) + case attribute.MAP: + return deduplicateMapValue(value) + default: + return value, false + } +} + +// KeyValue returns kv with all map values deduplicated and whether it changed. +func KeyValue(kv attribute.KeyValue) (attribute.KeyValue, bool) { + value, changed := Value(kv.Value) + if changed { + kv.Value = value + } + return kv, changed +} + +// KeyValues returns kvs with all map values deduplicated and whether they changed. +// +// The returned slice is the original kvs slice if no value needs +// deduplication. Top-level keys in kvs are not deduplicated. +func KeyValues(kvs []attribute.KeyValue) ([]attribute.KeyValue, bool) { + // Preserve the caller's slice on the common no-op path. Once a changed + // value is found, copy the prior values exactly once and fill the rest in + // place as the scan continues. + var normalized []attribute.KeyValue + for i, kv := range kvs { + kv, changed := KeyValue(kv) + if normalized != nil { + normalized[i] = kv + continue + } + if !changed { + continue + } + + normalized = make([]attribute.KeyValue, len(kvs)) + copy(normalized, kvs[:i]) + normalized[i] = kv + } + if normalized == nil { + return kvs, false + } + return normalized, true +} + +// Set returns set with all map values deduplicated and whether it changed. +// +// The returned Set is the original set if no value needs deduplication. +// Top-level key uniqueness remains attribute.Set's responsibility; this only +// normalizes map attribute values. +func Set(set attribute.Set) (attribute.Set, bool) { + if set.Len() == 0 { + return set, false + } + + // Most attribute sets contain no duplicate map keys. Delay allocation until + // the first changed value so the no-op path returns the original Set. + var normalized []attribute.KeyValue + for i := range set.Len() { + kv, _ := set.Get(i) + kv, changed := KeyValue(kv) + if normalized != nil { + normalized = append(normalized, kv) + continue + } + if !changed { + continue + } + + normalized = make([]attribute.KeyValue, 0, set.Len()) + for j := range i { + prior, _ := set.Get(j) + normalized = append(normalized, prior) + } + normalized = append(normalized, kv) + } + if normalized == nil { + return set, false + } + + return attribute.NewSet(normalized...), true +} + +func deduplicateSliceValue(value attribute.Value) (attribute.Value, bool) { + storage := valueStorage(value) + length := valueLen(storage) + + // Slice values can contain map values, so recurse into each element while + // keeping the original attribute.Value when no element changes. + var normalized []attribute.Value + for i := range length { + elem := valueAt(storage, i) + elem, changed := Value(elem) + if normalized != nil { + normalized[i] = elem + continue + } + if !changed { + continue + } + + normalized = make([]attribute.Value, length) + for j := range i { + normalized[j] = valueAt(storage, j) + } + normalized[i] = elem + } + if normalized == nil { + return value, false + } + return attribute.SliceValue(normalized...), true +} + +func deduplicateMapValue(value attribute.Value) (attribute.Value, bool) { + storage := valueStorage(value) + length := keyValueLen(storage) + if length <= 1 { + // A single map entry cannot duplicate its own key, but its value might + // contain a map or slice that needs recursive normalization. + if length == 1 { + kv, changed := KeyValue(keyValueAt(storage, 0)) + if changed { + return attribute.MapValue(kv), true + } + } + return value, false + } + + var normalized []attribute.KeyValue + for i := 0; i < length; { + // attribute.MapValue stores key-values sorted by key using a stable + // sort. Equal keys therefore form a contiguous run, and the last + // element in that run is the last value provided by the caller. + first := keyValueAt(storage, i) + j := i + 1 + for j < length && keyValueAt(storage, j).Key == first.Key { + j++ + } + + kv, nestedChanged := KeyValue(keyValueAt(storage, j-1)) + // j-i > 1 means the current key run contained duplicates. + changed := nestedChanged || j-i > 1 + if normalized != nil { + normalized = append(normalized, kv) + } else if changed { + normalized = make([]attribute.KeyValue, 0, length) + for k := range i { + normalized = append(normalized, keyValueAt(storage, k)) + } + normalized = append(normalized, kv) + } + i = j + } + if normalized == nil { + return value, false + } + return attribute.MapValue(normalized...), true +} + +func valueStorage(value attribute.Value) any { + // attribute.Value does not expose allocation-free map/slice iteration. + // The raw mirror lets us read the immutable backing array directly and + // reserve AsMap/AsSlice-style allocation for paths that actually change. + return (*rawValue)( + unsafe.Pointer(&value), + ).slice //nolint:gosec // Read-only mirror of attribute.Value for allocation-free iteration. +} + +func valueLen(storage any) int { + // attribute.Value stores small slices in fixed-size array values. Handle + // the common sizes directly and fall back to reflection for larger arrays. + switch storage.(type) { + case [0]attribute.Value: + return 0 + case [1]attribute.Value: + return 1 + case [2]attribute.Value: + return 2 + case [3]attribute.Value: + return 3 + case [4]attribute.Value: + return 4 + case [5]attribute.Value: + return 5 + default: + return arrayLen(storage, valueType) + } +} + +func valueAt(storage any, i int) attribute.Value { + switch values := storage.(type) { + case [1]attribute.Value: + return values[i] + case [2]attribute.Value: + return values[i] + case [3]attribute.Value: + return values[i] + case [4]attribute.Value: + return values[i] + case [5]attribute.Value: + return values[i] + default: + return arrayAt[attribute.Value](storage, valueType, i) + } +} + +func keyValueLen(storage any) int { + // attribute.Value stores small maps in fixed-size key-value arrays. Handle + // the common sizes directly and fall back to reflection for larger arrays. + switch storage.(type) { + case [0]attribute.KeyValue: + return 0 + case [1]attribute.KeyValue: + return 1 + case [2]attribute.KeyValue: + return 2 + case [3]attribute.KeyValue: + return 3 + case [4]attribute.KeyValue: + return 4 + case [5]attribute.KeyValue: + return 5 + default: + return arrayLen(storage, keyValueType) + } +} + +func keyValueAt(storage any, i int) attribute.KeyValue { + switch kvs := storage.(type) { + case [1]attribute.KeyValue: + return kvs[i] + case [2]attribute.KeyValue: + return kvs[i] + case [3]attribute.KeyValue: + return kvs[i] + case [4]attribute.KeyValue: + return kvs[i] + case [5]attribute.KeyValue: + return kvs[i] + default: + return arrayAt[attribute.KeyValue](storage, keyValueType, i) + } +} + +func arrayLen(storage any, elem reflect.Type) int { + // Be defensive around invalid or unexpected Value storage. Returning zero + // makes malformed storage a no-op instead of panicking in telemetry paths. + array := reflect.ValueOf(storage) + if array.Kind() != reflect.Array || array.Type().Elem() != elem { + return 0 + } + return array.Len() +} + +func arrayAt[T any](storage any, elem reflect.Type, i int) T { + // Match arrayLen's fail-closed behavior for unexpected storage. + array := reflect.ValueOf(storage) + if array.Kind() != reflect.Array || array.Type().Elem() != elem || i < 0 || i >= array.Len() { + var zero T + return zero + } + return array.Index(i).Interface().(T) +} diff --git a/vendor/go.opentelemetry.io/otel/sdk/internal/attrnorm/truncate.go b/vendor/go.opentelemetry.io/otel/sdk/internal/attrnorm/truncate.go new file mode 100644 index 000000000..c8341599b --- /dev/null +++ b/vendor/go.opentelemetry.io/otel/sdk/internal/attrnorm/truncate.go @@ -0,0 +1,230 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/attrnorm/truncate.go.tmpl + +package attrnorm + +import ( + "slices" + "strings" + "unicode/utf8" + + "go.opentelemetry.io/otel/attribute" +) + +// Truncate returns a truncated version of attr. Only string, string slice, +// byte slice, slice, and map attribute values are truncated. String values are +// truncated according to limit. Each string slice value is truncated in this +// fashion (the slice length itself is unaffected), and byte slice values are +// truncated to at most limit bytes. For slice and map attribute values, the +// limit is applied recursively to contained values. +// +// No truncation is performed for a negative limit. +func Truncate(limit int, attr attribute.KeyValue) attribute.KeyValue { + if limit < 0 { + return attr + } + switch attr.Value.Type() { + case attribute.STRING: + v := attr.Value.AsString() + return attr.Key.String(truncate(limit, v)) + case attribute.STRINGSLICE: + v := attr.Value.AsStringSlice() + for i := range v { + v[i] = truncate(limit, v[i]) + } + return attr.Key.StringSlice(v) + case attribute.BYTESLICE: + v := attr.Value.AsString() + if len(v) > limit { + return attr.Key.ByteSlice([]byte(v[:limit])) + } + return attr + case attribute.SLICE: + v := attr.Value.AsSlice() + if !slices.ContainsFunc(v, func(e attribute.Value) bool { return needsTruncation(limit, e) }) { + return attr + } + newV := make([]attribute.Value, len(v)) + for i, elem := range v { + newV[i] = TruncateValue(limit, elem) + } + return attr.Key.Slice(newV...) + case attribute.MAP: + v := attr.Value.AsMap() + if !slices.ContainsFunc(v, func(kv attribute.KeyValue) bool { return needsTruncation(limit, kv.Value) }) { + return attr + } + newV := make([]attribute.KeyValue, len(v)) + for i, elem := range v { + elem.Value = TruncateValue(limit, elem.Value) + newV[i] = elem + } + return attr.Key.Map(newV...) + } + return attr +} + +// TruncateValue returns a truncated version of v. Only string, string +// slice, byte slice, and (recursively) slice and map values are modified. +// +// No truncation is performed for a negative limit. +func TruncateValue(limit int, v attribute.Value) attribute.Value { + if limit < 0 { + return v + } + + switch v.Type() { + case attribute.STRING: + return attribute.StringValue(truncate(limit, v.AsString())) + case attribute.STRINGSLICE: + ss := v.AsStringSlice() + for i := range ss { + ss[i] = truncate(limit, ss[i]) + } + return attribute.StringSliceValue(ss) + case attribute.BYTESLICE: + // len(v.AsString()) is identical to len(v.AsByteSlice()) but + // avoids allocating the full slice before truncation. + s := v.AsString() + if limit >= 0 && len(s) > limit { + return attribute.ByteSliceValue([]byte(s[:limit])) + } + case attribute.SLICE: + sl := v.AsSlice() + if !slices.ContainsFunc(sl, func(e attribute.Value) bool { return needsTruncation(limit, e) }) { + return v + } + newSl := make([]attribute.Value, len(sl)) + for i, elem := range sl { + newSl[i] = TruncateValue(limit, elem) + } + return attribute.SliceValue(newSl...) + case attribute.MAP: + m := v.AsMap() + if !slices.ContainsFunc(m, func(kv attribute.KeyValue) bool { return needsTruncation(limit, kv.Value) }) { + return v + } + newM := make([]attribute.KeyValue, len(m)) + for i, elem := range m { + elem.Value = TruncateValue(limit, elem.Value) + newM[i] = elem + } + return attribute.MapValue(newM...) + } + return v +} + +// stringNeedsTruncation reports whether s would be modified by truncate for the +// given limit. +func stringNeedsTruncation(limit int, s string) bool { + if limit < 0 || len(s) <= limit { + return false + } + return utf8.RuneCountInString(s) > limit || !utf8.ValidString(s) +} + +// needsTruncation reports whether v would be modified by TruncateValue for the +// given limit. +func needsTruncation(limit int, v attribute.Value) bool { + switch v.Type() { + case attribute.STRING: + return stringNeedsTruncation(limit, v.AsString()) + case attribute.BYTESLICE: + // len(v.AsString()) is identical to len(v.AsByteSlice()) but + // avoids memory allocation. + if limit >= 0 && len(v.AsString()) > limit { + return true + } + case attribute.STRINGSLICE: + for _, s := range v.AsStringSlice() { + if stringNeedsTruncation(limit, s) { + return true + } + } + case attribute.SLICE: + return slices.ContainsFunc(v.AsSlice(), func(e attribute.Value) bool { return needsTruncation(limit, e) }) + case attribute.MAP: + return slices.ContainsFunc( + v.AsMap(), + func(kv attribute.KeyValue) bool { return needsTruncation(limit, kv.Value) }, + ) + } + return false +} + +// truncate returns a version of s truncated according to limit. +// +// If limit is negative, it returns the original string. +// +// UTF-8 is supported. When truncating, all invalid UTF-8 bytes are dropped +// before applying truncation. +// +// If s already contains at most limit bytes, it is returned unchanged. No +// invalid characters are removed. +func truncate(limit int, s string) string { + // This prioritizes performance in the following order based on the most + // common expected use cases. + // + // - Values shorter than the default limit (128). + // - Strings with valid encodings that exceed the limit. + // - No limit. + // - Strings with invalid encodings that exceed the limit. + if limit < 0 || len(s) <= limit { + return s + } + + // Optimistically, assume all valid UTF-8. + var b strings.Builder + count := 0 + for i, c := range s { + if c != utf8.RuneError { + count++ + if count > limit { + return s[:i] + } + continue + } + + _, size := utf8.DecodeRuneInString(s[i:]) + if size == 1 { + // Invalid encoding. + b.Grow(len(s) - 1) + _, _ = b.WriteString(s[:i]) + s = s[i:] + break + } + } + + // Fast-path, no invalid input. + if b.Cap() == 0 { + return s + } + + // Truncate while validating UTF-8. + for i := 0; i < len(s) && count < limit; { + c := s[i] + if c < utf8.RuneSelf { + // Optimization for single byte runes (common case). + _ = b.WriteByte(c) + i++ + count++ + continue + } + + _, size := utf8.DecodeRuneInString(s[i:]) + if size == 1 { + // We checked for all 1-byte runes above, this is a RuneError. + i++ + continue + } + + _, _ = b.WriteString(s[i : i+size]) + i += size + count++ + } + + return b.String() +} diff --git a/vendor/go.opentelemetry.io/otel/sdk/internal/x/features.go b/vendor/go.opentelemetry.io/otel/sdk/internal/x/features.go index 694b64a31..13ff34b27 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/internal/x/features.go +++ b/vendor/go.opentelemetry.io/otel/sdk/internal/x/features.go @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // Package x documents experimental features for [go.opentelemetry.io/otel/sdk]. -package x // import "go.opentelemetry.io/otel/sdk/internal/x" +package x import "strings" diff --git a/vendor/go.opentelemetry.io/otel/sdk/internal/x/x.go b/vendor/go.opentelemetry.io/otel/sdk/internal/x/x.go index 13347e560..67eea20a7 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/internal/x/x.go +++ b/vendor/go.opentelemetry.io/otel/sdk/internal/x/x.go @@ -1,11 +1,11 @@ -// Code generated by gotmpl. DO NOT MODIFY. -// source: internal/shared/x/x.go.tmpl - // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/x/x.go.tmpl + // Package x documents experimental features for [go.opentelemetry.io/otel/sdk]. -package x // import "go.opentelemetry.io/otel/sdk/internal/x" +package x import ( "os" @@ -34,9 +34,9 @@ func newFeature[T any](suffix []string, parse func(string) (T, bool)) Feature[T] // feature. func (f Feature[T]) Keys() []string { return f.keys } -// Lookup returns the user configured value for the feature and true if the +// Lookup returns the user-configured value for the feature and true if the // user has enabled the feature. Otherwise, if the feature is not enabled, a -// zero-value and false are returned. +// zero value and false are returned. func (f Feature[T]) Lookup() (v T, ok bool) { // https://github.com/open-telemetry/opentelemetry-specification/blob/62effed618589a0bec416a87e559c0a9d96289bb/specification/configuration/sdk-environment-variables.md#parsing-empty-value // diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/aggregation.go b/vendor/go.opentelemetry.io/otel/sdk/metric/aggregation.go index e6f5cfb2a..f52e7ea54 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/aggregation.go +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/aggregation.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package metric // import "go.opentelemetry.io/otel/sdk/metric" +package metric import ( "errors" diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/cache.go b/vendor/go.opentelemetry.io/otel/sdk/metric/cache.go index 63b88f086..1d6f6a089 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/cache.go +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/cache.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package metric // import "go.opentelemetry.io/otel/sdk/metric" +package metric import ( "sync" diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/config.go b/vendor/go.opentelemetry.io/otel/sdk/metric/config.go index dda4e086d..444a8cfda 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/config.go +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/config.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package metric // import "go.opentelemetry.io/otel/sdk/metric" +package metric import ( "context" @@ -157,6 +157,8 @@ func WithView(views ...View) Option { // exemplar reservoir, but the exemplar reservoir makes the final decision of // whether to store an exemplar. // +// The filter must not be nil. +// // By default, the [exemplar.TraceBasedFilter] // is used. Exemplars can be entirely disabled by providing the // [exemplar.AlwaysOffFilter]. diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/doc.go b/vendor/go.opentelemetry.io/otel/sdk/metric/doc.go index 51e168c75..61410b330 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/doc.go +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/doc.go @@ -86,4 +86,4 @@ // // See [go.opentelemetry.io/otel/sdk/metric/internal/x] for information about // the experimental features. -package metric // import "go.opentelemetry.io/otel/sdk/metric" +package metric diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/env.go b/vendor/go.opentelemetry.io/otel/sdk/metric/env.go index a6c403797..132664a7e 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/env.go +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/env.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package metric // import "go.opentelemetry.io/otel/sdk/metric" +package metric import ( "os" diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/exemplar.go b/vendor/go.opentelemetry.io/otel/sdk/metric/exemplar.go index 993f001ae..fb124052c 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/exemplar.go +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/exemplar.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package metric // import "go.opentelemetry.io/otel/sdk/metric" +package metric import ( "reflect" diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/exemplar/doc.go b/vendor/go.opentelemetry.io/otel/sdk/metric/exemplar/doc.go index 9f2389376..f7e547617 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/exemplar/doc.go +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/exemplar/doc.go @@ -3,4 +3,4 @@ // Package exemplar provides an implementation of the OpenTelemetry exemplar // reservoir to be used in metric collection pipelines. -package exemplar // import "go.opentelemetry.io/otel/sdk/metric/exemplar" +package exemplar diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/exemplar/exemplar.go b/vendor/go.opentelemetry.io/otel/sdk/metric/exemplar/exemplar.go index 1ab694678..32913a6e5 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/exemplar/exemplar.go +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/exemplar/exemplar.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package exemplar // import "go.opentelemetry.io/otel/sdk/metric/exemplar" +package exemplar import ( "time" diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/exemplar/filter.go b/vendor/go.opentelemetry.io/otel/sdk/metric/exemplar/filter.go index b50f5c153..a9efd20d1 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/exemplar/filter.go +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/exemplar/filter.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package exemplar // import "go.opentelemetry.io/otel/sdk/metric/exemplar" +package exemplar import ( "context" diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/exemplar/fixed_size_reservoir.go b/vendor/go.opentelemetry.io/otel/sdk/metric/exemplar/fixed_size_reservoir.go index ce97ab1bf..48f2b464c 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/exemplar/fixed_size_reservoir.go +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/exemplar/fixed_size_reservoir.go @@ -1,12 +1,10 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package exemplar // import "go.opentelemetry.io/otel/sdk/metric/exemplar" +package exemplar import ( "context" - "math" - "math/rand/v2" "sync" "time" @@ -26,7 +24,12 @@ func FixedSizeReservoirProvider(k int) ReservoirProvider { // sample each one. If there are more than k, the Reservoir will then randomly // sample all additional measurement with a decreasing probability. func NewFixedSizeReservoir(k int) *FixedSizeReservoir { - return newFixedSizeReservoir(newStorage(k)) + r := &FixedSizeReservoir{ + storage: make([]measurement, k), + } + r.nt.k = k + r.nt.reset() + return r } var _ Reservoir = &FixedSizeReservoir{} @@ -37,43 +40,9 @@ var _ Reservoir = &FixedSizeReservoir{} // additional measurement with a decreasing probability. type FixedSizeReservoir struct { reservoir.ConcurrentSafe - *storage - mu sync.Mutex - - // count is the number of measurement seen. - count int64 - // next is the next count that will store a measurement at a random index - // once the reservoir has been filled. - next int64 - // w is the largest random number in a distribution that is used to compute - // the next next. - w float64 -} - -func newFixedSizeReservoir(s *storage) *FixedSizeReservoir { - r := &FixedSizeReservoir{ - storage: s, - } - if cap(r.measurements) > 0 { - r.reset() - } - return r -} - -// randomFloat64 returns, as a float64, a uniform pseudo-random number in the -// open interval (0.0,1.0). -func (*FixedSizeReservoir) randomFloat64() float64 { - // TODO: Use an algorithm that avoids rejection sampling. For example: - // - // const precision = 1 << 53 // 2^53 - // // Generate an integer in [1, 2^53 - 1] - // v := rand.Uint64() % (precision - 1) + 1 - // return float64(v) / float64(precision) - f := rand.Float64() - for f == 0 { - f = rand.Float64() - } - return f + mu sync.Mutex + storage []measurement + nt nextTracker } // Offer accepts the parameters associated with a measurement. The @@ -88,128 +57,39 @@ func (*FixedSizeReservoir) randomFloat64() float64 { // parameters are the value and dropped (filtered) attributes of the // measurement respectively. func (r *FixedSizeReservoir) Offer(ctx context.Context, t time.Time, n Value, a []attribute.KeyValue) { - if cap(r.measurements) == 0 { + if len(r.storage) == 0 { return } - // The following algorithm is "Algorithm L" from Li, Kim-Hung (4 December - // 1994). "Reservoir-Sampling Algorithms of Time Complexity - // O(n(1+log(N/n)))". ACM Transactions on Mathematical Software. 20 (4): - // 481–493 (https://dl.acm.org/doi/10.1145/198429.198435). - // - // A high-level overview of "Algorithm L": - // 0) Pre-calculate the random count greater than the storage size when - // an exemplar will be replaced. - // 1) Accept all measurements offered until the configured storage size is - // reached. - // 2) Loop: - // a) When the pre-calculate count is reached, replace a random - // existing exemplar with the offered measurement. - // b) Calculate the next random count greater than the existing one - // which will replace another exemplars - // - // The way a "replacement" count is computed is by looking at `n` number of - // independent random numbers each corresponding to an offered measurement. - // Of these numbers the smallest `k` (the same size as the storage - // capacity) of them are kept as a subset. The maximum value in this - // subset, called `w` is used to weight another random number generation - // for the next count that will be considered. - // - // By weighting the next count computation like described, it is able to - // perform a uniformly-weighted sampling algorithm based on the number of - // samples the reservoir has seen so far. The sampling will "slow down" as - // more and more samples are offered so as to reduce a bias towards those - // offered just prior to the end of the collection. - // - // This algorithm is preferred because of its balance of simplicity and - // performance. It will compute three random numbers (the bulk of - // computation time) for each item that becomes part of the reservoir, but - // it does not spend any time on items that do not. In particular it has an - // asymptotic runtime of O(k(1 + log(n/k)) where n is the number of - // measurements offered and k is the reservoir size. - // - // See https://en.wikipedia.org/wiki/Reservoir_sampling for an overview of - // this and other reservoir sampling algorithms. See - // https://github.com/MrAlias/reservoir-sampling for a performance - // comparison of reservoir sampling algorithms. - r.mu.Lock() defer r.mu.Unlock() - if int(r.count) < cap(r.measurements) { - r.store(ctx, int(r.count), t, n, a) - } else if r.count == r.next { - // Overwrite a random existing measurement with the one offered. - idx := int(rand.Int64N(int64(cap(r.measurements)))) - r.store(ctx, idx, t, n, a) - r.advance() + sampled, idx := r.nt.shouldSample() + if sampled { + r.storage[idx].store(ctx, t, n, a) } - r.count++ -} - -// reset resets r to the initial state. -func (r *FixedSizeReservoir) reset() { - // This resets the number of exemplars known. - r.count = 0 - // Random index inserts should only happen after the storage is full. - r.next = int64(cap(r.measurements)) - - // Initial random number in the series used to generate r.next. - // - // This is set before r.advance to reset or initialize the random number - // series. Without doing so it would always be 0 or never restart a new - // random number series. - // - // This maps the uniform random number in (0,1) to a geometric distribution - // over the same interval. The mean of the distribution is inversely - // proportional to the storage capacity. - r.w = math.Exp(math.Log(r.randomFloat64()) / float64(cap(r.measurements))) - - r.advance() -} - -// advance updates the count at which the offered measurement will overwrite an -// existing exemplar. -func (r *FixedSizeReservoir) advance() { - // Calculate the next value in the random number series. - // - // The current value of r.w is based on the max of a distribution of random - // numbers (i.e. `w = max(u_1,u_2,...,u_k)` for `k` equal to the capacity - // of the storage and each `u` in the interval (0,w)). To calculate the - // next r.w we use the fact that when the next exemplar is selected to be - // included in the storage an existing one will be dropped, and the - // corresponding random number in the set used to calculate r.w will also - // be replaced. The replacement random number will also be within (0,w), - // therefore the next r.w will be based on the same distribution (i.e. - // `max(u_1,u_2,...,u_k)`). Therefore, we can sample the next r.w by - // computing the next random number `u` and take r.w as `w * u^(1/k)`. - r.w *= math.Exp(math.Log(r.randomFloat64()) / float64(cap(r.measurements))) - // Use the new random number in the series to calculate the count of the - // next measurement that will be stored. - // - // Given 0 < r.w < 1, each iteration will result in subsequent r.w being - // smaller. This translates here into the next next being selected against - // a distribution with a higher mean (i.e. the expected value will increase - // and replacements become less likely) - // - // Important to note, the new r.next will always be at least 1 more than - // the last r.next. - r.next += int64(math.Log(r.randomFloat64())/math.Log(1-r.w)) + 1 } // Collect returns all the held exemplars. // -// The Reservoir state is preserved after this call. +// The stored exemplars are preserved after this call, but the sampling state is reset. func (r *FixedSizeReservoir) Collect(dest *[]Exemplar) { - if cap(r.measurements) == 0 { + if len(r.storage) == 0 { *dest = (*dest)[:0] return } r.mu.Lock() defer r.mu.Unlock() - r.storage.Collect(dest) + *dest = reset(*dest, len(r.storage), len(r.storage)) + var n int + for i := range r.storage { + if r.storage[i].exemplar(&(*dest)[n]) { + n++ + } + } + *dest = (*dest)[:n] // Call reset here even though it will reset r.count and restart the random // number series. This will persist any old exemplars as long as no new // measurements are offered, but it will also prioritize those new // measurements that are made over the older collection cycle ones. - r.reset() + r.nt.reset() } diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/exemplar/histogram_reservoir.go b/vendor/go.opentelemetry.io/otel/sdk/metric/exemplar/histogram_reservoir.go index dacac3eba..e1001e4dc 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/exemplar/histogram_reservoir.go +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/exemplar/histogram_reservoir.go @@ -1,12 +1,13 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package exemplar // import "go.opentelemetry.io/otel/sdk/metric/exemplar" +package exemplar import ( "context" "slices" "sort" + "sync" "time" "go.opentelemetry.io/otel/attribute" @@ -22,29 +23,39 @@ func HistogramReservoirProvider(bounds []float64) ReservoirProvider { } } -// NewHistogramReservoir returns a [HistogramReservoir] that samples the last -// measurement that falls within a histogram bucket. The histogram bucket -// upper-boundaries are define by bounds. +type bucket struct { + mu sync.Mutex + nt nextTracker + measurement +} + +// NewHistogramReservoir returns a [HistogramReservoir] that samples +// measurements that fall within a histogram bucket using Algorithm L. The +// histogram bucket upper-boundaries are defined by bounds. // // The passed bounds must be sorted before calling this function. func NewHistogramReservoir(bounds []float64) *HistogramReservoir { + buckets := make([]bucket, len(bounds)+1) + for i := range buckets { + buckets[i].nt.k = 1 + buckets[i].nt.reset() + } return &HistogramReservoir{ bounds: bounds, - storage: newStorage(len(bounds) + 1), + buckets: buckets, } } var _ Reservoir = &HistogramReservoir{} -// HistogramReservoir is a [Reservoir] that samples the last measurement that -// falls within a histogram bucket. The histogram bucket upper-boundaries are -// define by bounds. +// HistogramReservoir is a [Reservoir] that samples +// measurements that fall within a histogram bucket using Algorithm L. The +// histogram bucket upper-boundaries are defined by bounds. type HistogramReservoir struct { reservoir.ConcurrentSafe - *storage - // bounds are bucket bounds in ascending order. - bounds []float64 + bounds []float64 + buckets []bucket } // Offer accepts the parameters associated with a measurement. The @@ -69,14 +80,31 @@ func (r *HistogramReservoir) Offer(ctx context.Context, t time.Time, v Value, a panic("unknown value type") } - idx := sort.SearchFloat64s(r.bounds, n) + b := &r.buckets[sort.SearchFloat64s(r.bounds, n)] - r.store(ctx, idx, t, v, a) + b.mu.Lock() + defer b.mu.Unlock() + + sampled, _ := b.nt.shouldSample() + if sampled { + b.store(ctx, t, v, a) + } } // Collect returns all the held exemplars. // -// The Reservoir state is preserved after this call. +// The stored exemplars are preserved after this call, but the sampling state is reset. func (r *HistogramReservoir) Collect(dest *[]Exemplar) { - r.storage.Collect(dest) + *dest = reset(*dest, len(r.buckets), len(r.buckets)) + var n int + for i := range r.buckets { + b := &r.buckets[i] + b.mu.Lock() + if b.exemplar(&(*dest)[n]) { + n++ + } + b.nt.reset() + b.mu.Unlock() + } + *dest = (*dest)[:n] } diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/exemplar/next_tracker.go b/vendor/go.opentelemetry.io/otel/sdk/metric/exemplar/next_tracker.go new file mode 100644 index 000000000..da5eb241c --- /dev/null +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/exemplar/next_tracker.go @@ -0,0 +1,154 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package exemplar + +import ( + "math" + "math/rand/v2" +) + +// nextTracker tracks the next measurement that should be sampled using Algorithm L. +type nextTracker struct { + // count is the number of measurements seen. + count int64 + // next is the next count that will store a measurement at a random index + // once the reservoir has been filled. + next int64 + // w is the largest random number in a distribution that is used to compute + // the next next. + w float64 + // k is the size of the reservoir. + k int +} + +// reset resets the tracker to the initial state for a reservoir of size k. +func (t *nextTracker) reset() { + t.count = 0 + if t.k <= 0 { + return + } + // Random index inserts should only happen after the storage is full. + // -1 accounts for the fact that advance() will unconditionally add 1 to + // t.next below. + t.next = int64(t.k) - 1 + + // Initial random number in the series used to generate t.next. + // + // This is set before t.advance to reset or initialize the random number + // series. Without doing so it would always be 0 or never restart a new + // random number series. + // + // This maps the uniform random number in (0,1) to a geometric distribution + // over the same interval. The mean of the distribution is inversely + // proportional to the storage capacity. + t.w = math.Exp(math.Log(randomFloat64()) / float64(t.k)) + t.advance() +} + +// advance updates the count at which the offered measurement will overwrite an +// existing exemplar. +func (t *nextTracker) advance() { + // Use the current random number in the series to calculate the count of the + // next measurement that will be stored. + // + // Given 0 < t.w < 1, each iteration will result in subsequent t.w being + // smaller. This translates here into the next next being selected against + // a distribution with a higher mean (i.e. the expected value will increase + // and replacements become less likely) + // + // Important to note, the new t.next will always be at least 1 more than + // the last t.next. + t.next += int64(math.Log(randomFloat64())/math.Log(1-t.w)) + 1 + + // Calculate the next value in the random number series. + // + // The current value of t.w is based on the max of a distribution of random + // numbers (i.e. `w = max(u_1,u_2,...,u_k)` for `k` equal to the capacity + // of the storage and each `u` in the interval (0,w)). To calculate the + // next t.w we use the fact that when the next exemplar is selected to be + // included in the storage an existing one will be dropped, and the + // corresponding random number in the set used to calculate t.w will also + // be replaced. The replacement random number will also be within (0,w), + // therefore the next t.w will be based on the same distribution (i.e. + // `max(u_1,u_2,...,u_k)`). Therefore, we can sample the next t.w by + // computing the next random number `u` and take t.w as `w * u^(1/k)`. + t.w *= math.Exp(math.Log(randomFloat64()) / float64(t.k)) +} + +// shouldSample returns true if the measurement should be sampled. +// It also returns the index at which the measurement should be stored. +// +// The following algorithm is "Algorithm L" from Li, Kim-Hung (4 December +// 1994). "Reservoir-Sampling Algorithms of Time Complexity +// O(n(1+log(N/n)))". ACM Transactions on Mathematical Software. 20 (4): +// 481–493 (https://dl.acm.org/doi/10.1145/198429.198435). +// +// A high-level overview of "Algorithm L": +// 0. Pre-calculate the random count greater than the storage size when +// an exemplar will be replaced. +// 1. Accept all measurements offered until the configured storage size is +// reached. +// 2. Loop: +// a) When the pre-calculate count is reached, replace a random +// existing exemplar with the offered measurement. +// b) Calculate the next random count greater than the existing one +// which will replace another exemplars +// +// The way a "replacement" count is computed is by looking at `n` number of +// independent random numbers each corresponding to an offered measurement. +// Of these numbers the smallest `k` (the same size as the storage +// capacity) of them are kept as a subset. The maximum value in this +// subset, called `w` is used to weight another random number generation +// for the next count that will be considered. +// +// By weighting the next count computation like described, it is able to +// perform a uniformly-weighted sampling algorithm based on the number of +// samples the reservoir has seen so far. The sampling will "slow down" as +// more and more samples are offered so as to reduce a bias towards those +// offered just prior to the end of the collection. +// +// This algorithm is preferred because of its balance of simplicity and +// performance. It will compute three random numbers (the bulk of +// computation time) for each item that becomes part of the reservoir, but +// it does not spend any time on items that do not. In particular it has an +// asymptotic runtime of O(k(1 + log(n/k))) where n is the number of +// measurements offered and k is the reservoir size. +// +// See https://en.wikipedia.org/wiki/Reservoir_sampling for an overview of +// this and other reservoir sampling algorithms. See +// https://github.com/MrAlias/reservoir-sampling for a performance +// comparison of reservoir sampling algorithms. +func (t *nextTracker) shouldSample() (bool, int) { + if t.k <= 0 { + return false, 0 + } + if t.count < int64(t.k) { + idx := int(t.count) + t.count++ + return true, idx + } + if t.count == t.next { + idx := 0 + if t.k > 1 { + idx = int(rand.Int64N(int64(t.k))) + } + t.advance() + t.count++ + return true, idx + } + t.count++ + return false, 0 +} + +// randomFloat64 returns a pseudo-random value uniformly selected from +// {k / 2^53 | 1 <= k < 2^53}. +func randomFloat64() float64 { + // rand.Float64 returns a value in [0, 1). Retry in the extremely + // unlikely event that it returns zero to produce a value in (0, 1). + f := rand.Float64() + for f == 0 { + f = rand.Float64() + } + return f +} diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/exemplar/reservoir.go b/vendor/go.opentelemetry.io/otel/sdk/metric/exemplar/reservoir.go index ba5cd1a6b..a6cfdf44f 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/exemplar/reservoir.go +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/exemplar/reservoir.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package exemplar // import "go.opentelemetry.io/otel/sdk/metric/exemplar" +package exemplar import ( "context" diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/exemplar/storage.go b/vendor/go.opentelemetry.io/otel/sdk/metric/exemplar/storage.go index 790496027..9a0be05a2 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/exemplar/storage.go +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/exemplar/storage.go @@ -1,74 +1,41 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package exemplar // import "go.opentelemetry.io/otel/sdk/metric/exemplar" +package exemplar import ( "context" - "sync" "time" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" ) -// storage is an exemplar storage for [Reservoir] implementations. -type storage struct { - // measurements are the measurements sampled. - // - // This does not use []metricdata.Exemplar because it potentially would - // require an allocation for trace and span IDs in the hot path of Offer. - measurements []measurement -} - -func newStorage(n int) *storage { - return &storage{measurements: make([]measurement, n)} -} - -func (r *storage) store(ctx context.Context, idx int, ts time.Time, v Value, droppedAttr []attribute.KeyValue) { - r.measurements[idx].mux.Lock() - defer r.measurements[idx].mux.Unlock() - r.measurements[idx].FilteredAttributes = droppedAttr - r.measurements[idx].Time = ts - r.measurements[idx].Value = v - r.measurements[idx].Ctx = ctx - r.measurements[idx].valid = true -} - -// Collect returns all the held exemplars. -// -// The Reservoir state is preserved after this call. -func (r *storage) Collect(dest *[]Exemplar) { - *dest = reset(*dest, len(r.measurements), len(r.measurements)) - var n int - for i := range r.measurements { - if r.measurements[i].exemplar(&(*dest)[n]) { - n++ - } - } - *dest = (*dest)[:n] -} - // measurement is a measurement made by a telemetry system. type measurement struct { - mux sync.Mutex // FilteredAttributes are the attributes dropped during the measurement. FilteredAttributes []attribute.KeyValue // Time is the time when the measurement was made. Time time.Time // Value is the value of the measurement. Value Value - // Ctx is the context active when a measurement was made. - Ctx context.Context + // SpanContext is the SpanContext active when a measurement was made. + SpanContext trace.SpanContext valid bool } +func (m *measurement) store(ctx context.Context, ts time.Time, v Value, droppedAttr []attribute.KeyValue) { + m.FilteredAttributes = droppedAttr + m.Time = ts + m.Value = v + m.SpanContext = trace.SpanContextFromContext(ctx) + m.valid = true +} + // exemplar returns m as an [Exemplar]. // returns true if it populated the exemplar. func (m *measurement) exemplar(dest *Exemplar) bool { - m.mux.Lock() - defer m.mux.Unlock() if !m.valid { return false } @@ -77,7 +44,7 @@ func (m *measurement) exemplar(dest *Exemplar) bool { dest.Time = m.Time dest.Value = m.Value - sc := trace.SpanContextFromContext(m.Ctx) + sc := m.SpanContext if sc.HasTraceID() { traceID := sc.TraceID() dest.TraceID = traceID[:] diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/exemplar/value.go b/vendor/go.opentelemetry.io/otel/sdk/metric/exemplar/value.go index 590b089a8..c7d1645b6 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/exemplar/value.go +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/exemplar/value.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package exemplar // import "go.opentelemetry.io/otel/sdk/metric/exemplar" +package exemplar import "math" diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/exporter.go b/vendor/go.opentelemetry.io/otel/sdk/metric/exporter.go index 1969cb42c..7bec41529 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/exporter.go +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/exporter.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package metric // import "go.opentelemetry.io/otel/sdk/metric" +package metric import ( "context" diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/instrument.go b/vendor/go.opentelemetry.io/otel/sdk/metric/instrument.go index dfb4964d9..31f7afef9 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/instrument.go +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/instrument.go @@ -3,7 +3,7 @@ //go:generate stringer -type=InstrumentKind -trimprefix=InstrumentKind -package metric // import "go.opentelemetry.io/otel/sdk/metric" +package metric import ( "context" @@ -16,6 +16,7 @@ import ( "go.opentelemetry.io/otel/metric/embedded" "go.opentelemetry.io/otel/sdk/instrumentation" "go.opentelemetry.io/otel/sdk/metric/internal/aggregate" + "go.opentelemetry.io/otel/sdk/metric/internal/attrnorm" ) var zeroScope instrumentation.Scope @@ -180,6 +181,46 @@ func (i instID) normalize() instID { return i } +type rawAttributesOption interface { + RawAttributes() []attribute.KeyValue + Experimental() +} + +func extractRawKVs[T any](opts []T) []attribute.KeyValue { + var rawKVs []attribute.KeyValue + var count int + for _, opt := range opts { + if r, ok := any(opt).(rawAttributesOption); ok { + count++ + if count == 1 { + rawKVs = r.RawAttributes() + } else { + if count == 2 { + // Create a new slice to avoid modifying the original slice from the first option. + rawKVs = append([]attribute.KeyValue(nil), rawKVs...) + } + rawKVs = append(rawKVs, r.RawAttributes()...) + } + } + } + return rawKVs +} + +func resolveAttributes(configAttrs attribute.Set, rawKVs []attribute.KeyValue) attribute.Set { + configAttrs, _ = attrnorm.Set(configAttrs) + if len(rawKVs) == 0 { + return configAttrs + } + rawKVs, _ = attrnorm.KeyValues(rawKVs) + merged := make([]attribute.KeyValue, 0, configAttrs.Len()+len(rawKVs)) + merged = append(merged, configAttrs.ToSlice()...) + // rawKVs are appended after configAttrs, meaning they will override any duplicate keys in configAttrs. + // This behavior is documented in WithUnsafeAttributes. + merged = append(merged, rawKVs...) + // TODO(#7743): Defer computing the full attribute.NewSet. + return attribute.NewSet(merged...) +} + type int64Inst struct { measures []aggregate.Measure[int64] @@ -198,12 +239,14 @@ var ( func (i *int64Inst) Add(ctx context.Context, val int64, opts ...metric.AddOption) { c := metric.NewAddConfig(opts) - i.aggregate(ctx, val, c.Attributes()) + rawKVs := extractRawKVs(opts) + i.aggregate(ctx, val, resolveAttributes(c.Attributes(), rawKVs)) } func (i *int64Inst) Record(ctx context.Context, val int64, opts ...metric.RecordOption) { c := metric.NewRecordConfig(opts) - i.aggregate(ctx, val, c.Attributes()) + rawKVs := extractRawKVs(opts) + i.aggregate(ctx, val, resolveAttributes(c.Attributes(), rawKVs)) } func (i *int64Inst) Enabled(context.Context) bool { @@ -238,12 +281,14 @@ var ( func (i *float64Inst) Add(ctx context.Context, val float64, opts ...metric.AddOption) { c := metric.NewAddConfig(opts) - i.aggregate(ctx, val, c.Attributes()) + rawKVs := extractRawKVs(opts) + i.aggregate(ctx, val, resolveAttributes(c.Attributes(), rawKVs)) } func (i *float64Inst) Record(ctx context.Context, val float64, opts ...metric.RecordOption) { c := metric.NewRecordConfig(opts) - i.aggregate(ctx, val, c.Attributes()) + rawKVs := extractRawKVs(opts) + i.aggregate(ctx, val, resolveAttributes(c.Attributes(), rawKVs)) } func (i *float64Inst) Enabled(context.Context) bool { diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/aggregate.go b/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/aggregate.go index a35f3bcc1..98916ae76 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/aggregate.go +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/aggregate.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package aggregate // import "go.opentelemetry.io/otel/sdk/metric/internal/aggregate" +package aggregate import ( "context" @@ -57,18 +57,17 @@ func (b Builder[N]) resFunc() func(attribute.Set) FilteredExemplarReservoir[N] { return DropReservoir } -type fltrMeasure[N int64 | float64] func(ctx context.Context, value N, fltrAttr attribute.Set, droppedAttr []attribute.KeyValue) +type fltrMeasure[N int64 | float64] func(ctx context.Context, value N, lazy lazyFilteredAttributes) func (b Builder[N]) filter(f fltrMeasure[N]) Measure[N] { if b.Filter != nil { fltr := b.Filter // Copy to make it immutable after assignment. return func(ctx context.Context, n N, a attribute.Set) { - fAttr, dropped := a.Filter(fltr) - f(ctx, n, fAttr, dropped) + f(ctx, n, newLazyFilteredAttributes(a, fltr)) } } return func(ctx context.Context, n N, a attribute.Set) { - f(ctx, n, a, nil) + f(ctx, n, newLazyFilteredAttributes(a, nil)) } } diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/atomic.go b/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/atomic.go index eb69e9650..604ee0d56 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/atomic.go +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/atomic.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package aggregate // import "go.opentelemetry.io/otel/sdk/metric/internal/aggregate" +package aggregate import ( "math" @@ -221,23 +221,28 @@ func (l *hotColdWaitGroup) swapHotAndWait() uint64 { // limitedSyncMap is a sync.Map which enforces the aggregation limit on // attribute sets and provides a Len() function. -type limitedSyncMap struct { +type limitedSyncMap[V any] struct { sync.Map aggLimit int len int lenMux sync.Mutex } -func (m *limitedSyncMap) LoadOrStoreAttr(fltrAttr attribute.Set, newValue func(attribute.Set) any) any { - actual, loaded := m.Load(fltrAttr.Equivalent()) +// LoadOrStoreAttr performs lookup using lazy.Distinct() on the hot path without +// constructing a Set. If the entry is not found and the aggregation limit has not +// been exceeded, lazy.Set() is called to construct the attribute.Set for storage. +// If the aggregation limit is exceeded, overflowSet is used instead without calling lazy.Set(). +func (m *limitedSyncMap[V]) LoadOrStoreAttr(lazy lazyFilteredAttributes, newValue func(attribute.Set) V) V { + distinct := lazy.Distinct() + actual, loaded := m.Load(distinct) if loaded { - return actual + return actual.(V) } // If the overflow set exists, assume we have already overflowed and don't // bother with the slow path below. actual, loaded = m.Load(overflowSet.Equivalent()) if loaded { - return actual + return actual.(V) } // Slow path: add a new attribute set. m.lenMux.Lock() @@ -246,29 +251,33 @@ func (m *limitedSyncMap) LoadOrStoreAttr(fltrAttr attribute.Set, newValue func(a // re-fetch now that we hold the lock to ensure we don't use the overflow // set unless we are sure the attribute set isn't being written // concurrently. - actual, loaded = m.Load(fltrAttr.Equivalent()) + actual, loaded = m.Load(distinct) if loaded { - return actual + return actual.(V) } + var fltrAttr attribute.Set if m.aggLimit > 0 && m.len >= m.aggLimit-1 { fltrAttr = overflowSet + distinct = overflowSet.Equivalent() + } else { + fltrAttr = lazy.Set() } - actual, loaded = m.LoadOrStore(fltrAttr.Equivalent(), newValue(fltrAttr)) + actual, loaded = m.LoadOrStore(distinct, newValue(fltrAttr)) if !loaded { m.len++ } - return actual + return actual.(V) } -func (m *limitedSyncMap) Clear() { +func (m *limitedSyncMap[V]) Clear() { m.lenMux.Lock() defer m.lenMux.Unlock() m.len = 0 m.Map.Clear() } -func (m *limitedSyncMap) Len() int { +func (m *limitedSyncMap[V]) Len() int { m.lenMux.Lock() defer m.lenMux.Unlock() return m.len diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/doc.go b/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/doc.go index 7b7225e6e..c0399c408 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/doc.go +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/doc.go @@ -4,4 +4,4 @@ // Package aggregate provides aggregate types used compute aggregations and // cycle the state of metric measurements made by the SDK. These types and // functionality are meant only for internal SDK use. -package aggregate // import "go.opentelemetry.io/otel/sdk/metric/internal/aggregate" +package aggregate diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/drop.go b/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/drop.go index 7adfcaf85..c78bdc671 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/drop.go +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/drop.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package aggregate // import "go.opentelemetry.io/otel/sdk/metric/internal/aggregate" +package aggregate import ( "context" @@ -18,7 +18,7 @@ func DropReservoir[N int64 | float64](attribute.Set) FilteredExemplarReservoir[N type dropRes[N int64 | float64] struct{} // Offer does nothing, all measurements offered will be dropped. -func (*dropRes[N]) Offer(context.Context, N, []attribute.KeyValue) {} +func (*dropRes[N]) Offer(context.Context, N, lazyFilteredAttributes) {} // Collect resets dest. No exemplars will ever be returned. func (*dropRes[N]) Collect(dest *[]exemplar.Exemplar) { diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/exemplar.go b/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/exemplar.go index 25d709948..45b620419 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/exemplar.go +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/exemplar.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package aggregate // import "go.opentelemetry.io/otel/sdk/metric/internal/aggregate" +package aggregate import ( "sync" diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/exponential_histogram.go b/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/exponential_histogram.go index 767b1d6dc..f539be942 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/exponential_histogram.go +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/exponential_histogram.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package aggregate // import "go.opentelemetry.io/otel/sdk/metric/internal/aggregate" +package aggregate import ( "context" @@ -331,8 +331,7 @@ type expoHistogram[N int64 | float64] struct { func (e *expoHistogram[N]) measure( ctx context.Context, value N, - fltrAttr attribute.Set, - droppedAttr []attribute.KeyValue, + lazy lazyFilteredAttributes, ) { // Ignore NaN and infinity. if math.IsInf(float64(value), 0) || math.IsNaN(float64(value)) { @@ -342,13 +341,17 @@ func (e *expoHistogram[N]) measure( e.valuesMu.Lock() defer e.valuesMu.Unlock() - v, ok := e.values[fltrAttr.Equivalent()] + distinct := lazy.Distinct() + v, ok := e.values[distinct] if !ok { - fltrAttr = e.limit.Attributes(fltrAttr, e.values) - // If we overflowed, make sure we add to the existing overflow series - // if it already exists. - v, ok = e.values[fltrAttr.Equivalent()] + v, ok = e.values[overflowSet.Equivalent()] if !ok { + var fltrAttr attribute.Set + if e.limit.aggLimit > 0 && len(e.values) >= e.limit.aggLimit-1 { + fltrAttr = overflowSet + } else { + fltrAttr = lazy.Set() + } v = newExpoHistogramDataPoint[N](fltrAttr, e.maxSize, e.maxScale, e.noMinMax, e.noSum) r := e.newRes(fltrAttr) _, isDrop := r.(*dropRes[N]) @@ -360,7 +363,7 @@ func (e *expoHistogram[N]) measure( } v.record(value) if !v.dropExemplars { - v.res.Offer(ctx, value, droppedAttr) + v.res.Offer(ctx, value, lazy) } } @@ -412,12 +415,15 @@ func (e *expoHistogram[N]) delta( if !e.noSum { hDPts[i].Sum = val.sum.load() + } else { + hDPts[i].Sum = 0 } - if !e.noMinMax { - if val.minMax.set.Load() { - hDPts[i].Min = metricdata.NewExtrema(val.minMax.minimum.Load()) - hDPts[i].Max = metricdata.NewExtrema(val.minMax.maximum.Load()) - } + if !e.noMinMax && val.minMax.set.Load() { + hDPts[i].Min = metricdata.NewExtrema(val.minMax.minimum.Load()) + hDPts[i].Max = metricdata.NewExtrema(val.minMax.maximum.Load()) + } else { + hDPts[i].Min = metricdata.Extrema[N]{} + hDPts[i].Max = metricdata.Extrema[N]{} } collectExemplars(&hDPts[i].Exemplars, val.res.Collect) @@ -488,12 +494,15 @@ func (e *expoHistogram[N]) cumulative( if !e.noSum { hDPts[i].Sum = val.sum.load() + } else { + hDPts[i].Sum = 0 } - if !e.noMinMax { - if val.minMax.set.Load() { - hDPts[i].Min = metricdata.NewExtrema(val.minMax.minimum.Load()) - hDPts[i].Max = metricdata.NewExtrema(val.minMax.maximum.Load()) - } + if !e.noMinMax && val.minMax.set.Load() { + hDPts[i].Min = metricdata.NewExtrema(val.minMax.minimum.Load()) + hDPts[i].Max = metricdata.NewExtrema(val.minMax.maximum.Load()) + } else { + hDPts[i].Min = metricdata.Extrema[N]{} + hDPts[i].Max = metricdata.Extrema[N]{} } collectExemplars(&hDPts[i].Exemplars, val.res.Collect) diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/filtered_reservoir.go b/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/filtered_reservoir.go index e4f9409bc..20e26c57d 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/filtered_reservoir.go +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/filtered_reservoir.go @@ -1,14 +1,13 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package aggregate // import "go.opentelemetry.io/otel/sdk/metric/internal/aggregate" +package aggregate import ( "context" "sync" "time" - "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/sdk/metric/exemplar" "go.opentelemetry.io/otel/sdk/metric/internal/reservoir" ) @@ -22,7 +21,10 @@ type FilteredExemplarReservoir[N int64 | float64] interface { // The passed ctx needs to contain any baggage or span that were active // when the measurement was made. This information may be used by the // Reservoir in making a sampling decision. - Offer(ctx context.Context, val N, attr []attribute.KeyValue) + // + // The lazy parameter provides filtered attribute details when sampled, + // allowing dropped attributes to be computed only if the measurement is sampled. + Offer(ctx context.Context, val N, lazy lazyFilteredAttributes) // Collect returns all the held exemplars in the reservoir. Collect(dest *[]exemplar.Exemplar) } @@ -52,10 +54,11 @@ func NewFilteredExemplarReservoir[N int64 | float64]( } } -func (f *filteredExemplarReservoir[N]) Offer(ctx context.Context, val N, attr []attribute.KeyValue) { +func (f *filteredExemplarReservoir[N]) Offer(ctx context.Context, val N, lazy lazyFilteredAttributes) { if f.filter(ctx) { // only record the current time if we are sampling this measurement. ts := time.Now() + attr := lazy.Dropped() if !f.concurrentSafe { f.reservoirMux.Lock() defer f.reservoirMux.Unlock() diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/histogram.go b/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/histogram.go index 50c82ff32..89770dc20 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/histogram.go +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/histogram.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package aggregate // import "go.opentelemetry.io/otel/sdk/metric/internal/aggregate" +package aggregate import ( "context" @@ -44,8 +44,6 @@ type histogramPointCounters[N int64 | float64] struct { } func (b *histogramPointCounters[N]) loadCountsInto(into *[]uint64) uint64 { - // TODO (#3047): Making copies for counts incurs a large - // memory allocation footprint. Alternatives should be explored. counts := reset(*into, len(b.counts), len(b.counts)) count := uint64(0) for i := range b.counts { @@ -97,7 +95,7 @@ func (b *histogramPointCounters[N]) mergeIntoAndReset( // nolint:revive // Inten // unused attribute sets do not report in subsequent collect() calls. type deltaHistogram[N int64 | float64] struct { hcwg hotColdWaitGroup - hotColdValMap [2]limitedSyncMap + hotColdValMap [2]limitedSyncMap[*histogramPoint[N]] start time.Time noMinMax bool @@ -109,12 +107,11 @@ type deltaHistogram[N int64 | float64] struct { func (s *deltaHistogram[N]) measure( ctx context.Context, value N, - fltrAttr attribute.Set, - droppedAttr []attribute.KeyValue, + lazy lazyFilteredAttributes, ) { hotIdx := s.hcwg.start() defer s.hcwg.done(hotIdx) - h := s.hotColdValMap[hotIdx].LoadOrStoreAttr(fltrAttr, func(attr attribute.Set) any { + h := s.hotColdValMap[hotIdx].LoadOrStoreAttr(lazy, func(attr attribute.Set) *histogramPoint[N] { r := s.newRes(attr) _, isDrop := r.(*dropRes[N]) hPt := &histogramPoint[N]{ @@ -131,7 +128,7 @@ func (s *deltaHistogram[N]) measure( histogramPointCounters: histogramPointCounters[N]{counts: make([]atomic.Uint64, len(s.bounds)+1)}, } return hPt - }).(*histogramPoint[N]) + }) // This search will return an index in the range [0, len(s.bounds)], where // it will return len(s.bounds) if value is greater than the last element @@ -147,7 +144,7 @@ func (s *deltaHistogram[N]) measure( h.total.add(value) } if !h.dropExemplars { - h.res.Offer(ctx, value, droppedAttr) + h.res.Offer(ctx, value, lazy) } } @@ -171,7 +168,7 @@ func newDeltaHistogram[N int64 | float64]( noSum: noSum, bounds: b, newRes: r, - hotColdValMap: [2]limitedSyncMap{ + hotColdValMap: [2]limitedSyncMap[*histogramPoint[N]]{ {aggLimit: limit}, {aggLimit: limit}, }, @@ -212,13 +209,16 @@ func (s *deltaHistogram[N]) collect( if !s.noSum { hDPts[i].Sum = val.total.load() + } else { + hDPts[i].Sum = 0 } - if !s.noMinMax { - if val.minMax.set.Load() { - hDPts[i].Min = metricdata.NewExtrema(val.minMax.minimum.Load()) - hDPts[i].Max = metricdata.NewExtrema(val.minMax.maximum.Load()) - } + if !s.noMinMax && val.minMax.set.Load() { + hDPts[i].Min = metricdata.NewExtrema(val.minMax.minimum.Load()) + hDPts[i].Max = metricdata.NewExtrema(val.minMax.maximum.Load()) + } else { + hDPts[i].Min = metricdata.Extrema[N]{} + hDPts[i].Max = metricdata.Extrema[N]{} } collectExemplars(&hDPts[i].Exemplars, val.res.Collect) @@ -249,7 +249,7 @@ func (s *deltaHistogram[N]) collect( // to reading. Unlike deltaHistogram, this maintains a single map so that the // preserved attribute sets do not change when collect() is called. type cumulativeHistogram[N int64 | float64] struct { - values limitedSyncMap + values limitedSyncMap[*hotColdHistogramPoint[N]] start time.Time noMinMax bool @@ -278,17 +278,16 @@ func newCumulativeHistogram[N int64 | float64]( noSum: noSum, bounds: b, newRes: r, - values: limitedSyncMap{aggLimit: limit}, + values: limitedSyncMap[*hotColdHistogramPoint[N]]{aggLimit: limit}, } } func (s *cumulativeHistogram[N]) measure( ctx context.Context, value N, - fltrAttr attribute.Set, - droppedAttr []attribute.KeyValue, + lazy lazyFilteredAttributes, ) { - h := s.values.LoadOrStoreAttr(fltrAttr, func(attr attribute.Set) any { + h := s.values.LoadOrStoreAttr(lazy, func(attr attribute.Set) *hotColdHistogramPoint[N] { r := s.newRes(attr) _, isDrop := r.(*dropRes[N]) hPt := &hotColdHistogramPoint[N]{ @@ -313,7 +312,7 @@ func (s *cumulativeHistogram[N]) measure( }, } return hPt - }).(*hotColdHistogramPoint[N]) + }) // This search will return an index in the range [0, len(s.bounds)], where // it will return len(s.bounds) if value is greater than the last element @@ -333,7 +332,7 @@ func (s *cumulativeHistogram[N]) measure( h.hotColdPoint[hotIdx].total.add(value) } if !h.dropExemplars { - h.res.Offer(ctx, value, droppedAttr) + h.res.Offer(ctx, value, lazy) } } @@ -350,9 +349,16 @@ func (s *cumulativeHistogram[N]) collect( // Do not allow modification of our copy of bounds. bounds := slices.Clone(s.bounds) - // Values are being concurrently written while we iterate, so only use the - // current length for capacity. - hDPts := reset(h.DataPoints, 0, s.values.Len()) + // Pre-size hDPts so per-series destination slots are addressable by index. + // This lets loadCountsInto and collectExemplars reuse each slot's existing + // BucketCounts/Exemplars slices from the previous cycle. s.values is + // append-only here during cumulative collect, and limitedSyncMap only + // increments its len after a successful underlying LoadOrStore, so Range + // will visit at least n entries. Concurrent measurers may add more between + // Len() and Range; those extra slots are appended on demand inside the + // loop. + n := s.values.Len() + hDPts := reset(h.DataPoints, n, n) perSeriesStartTimeEnabled := x.PerSeriesStartTimestamps.Enabled() @@ -366,35 +372,41 @@ func (s *cumulativeHistogram[N]) collect( } // swap, observe, and clear the point readIdx := val.hcwg.swapHotAndWait() - var bucketCounts []uint64 - count := val.hotColdPoint[readIdx].loadCountsInto(&bucketCounts) - newPt := metricdata.HistogramDataPoint[N]{ - Attributes: val.attrs, - StartTime: startTime, - Time: t, - Count: count, - Bounds: bounds, - // The HistogramDataPoint field values returned need to be copies of - // the histogramPoint value as we will keep updating them. - BucketCounts: bucketCounts, - } + // Concurrent writers can grow s.values between Len() and Range. + // Cold-path grow. + if i >= len(hDPts) { + hDPts = append(hDPts, metricdata.HistogramDataPoint[N]{}) + } + dp := &hDPts[i] + + count := val.hotColdPoint[readIdx].loadCountsInto(&dp.BucketCounts) + dp.Attributes = val.attrs + dp.StartTime = startTime + dp.Time = t + dp.Count = count + dp.Bounds = bounds if !s.noSum { - newPt.Sum = val.hotColdPoint[readIdx].total.load() + dp.Sum = val.hotColdPoint[readIdx].total.load() + } else { + // Slot may be reused; clear stale Sum from previous series. + var zero N + dp.Sum = zero } - if !s.noMinMax { - if val.hotColdPoint[readIdx].minMax.set.Load() { - newPt.Min = metricdata.NewExtrema(val.hotColdPoint[readIdx].minMax.minimum.Load()) - newPt.Max = metricdata.NewExtrema(val.hotColdPoint[readIdx].minMax.maximum.Load()) - } + if !s.noMinMax && val.hotColdPoint[readIdx].minMax.set.Load() { + dp.Min = metricdata.NewExtrema(val.hotColdPoint[readIdx].minMax.minimum.Load()) + dp.Max = metricdata.NewExtrema(val.hotColdPoint[readIdx].minMax.maximum.Load()) + } else { + // Slot may be reused; clear stale Min/Max from previous series. + dp.Min = metricdata.Extrema[N]{} + dp.Max = metricdata.Extrema[N]{} } // Once we've read the point, merge it back into the hot histogram // point since it is cumulative. hotIdx := (readIdx + 1) % 2 val.hotColdPoint[readIdx].mergeIntoAndReset(&val.hotColdPoint[hotIdx], s.noMinMax, s.noSum) - collectExemplars(&newPt.Exemplars, val.res.Collect) - hDPts = append(hDPts, newPt) + collectExemplars(&dp.Exemplars, val.res.Collect) i++ // TODO (#3006): This will use an unbounded amount of memory if there diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/lastvalue.go b/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/lastvalue.go index 2af252ec5..ad68fac8d 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/lastvalue.go +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/lastvalue.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package aggregate // import "go.opentelemetry.io/otel/sdk/metric/internal/aggregate" +package aggregate import ( "context" @@ -24,16 +24,15 @@ type lastValuePoint[N int64 | float64] struct { // lastValueMap summarizes a set of measurements as the last one made. type lastValueMap[N int64 | float64] struct { newRes func(attribute.Set) FilteredExemplarReservoir[N] - values limitedSyncMap + values limitedSyncMap[*lastValuePoint[N]] } func (s *lastValueMap[N]) measure( ctx context.Context, value N, - fltrAttr attribute.Set, - droppedAttr []attribute.KeyValue, + lazy lazyFilteredAttributes, ) { - lv := s.values.LoadOrStoreAttr(fltrAttr, func(attr attribute.Set) any { + lv := s.values.LoadOrStoreAttr(lazy, func(attr attribute.Set) *lastValuePoint[N] { r := s.newRes(attr) _, isDrop := r.(*dropRes[N]) p := &lastValuePoint[N]{ @@ -44,11 +43,11 @@ func (s *lastValueMap[N]) measure( } p.value.Store(value) return p - }).(*lastValuePoint[N]) + }) lv.value.Store(value) if !lv.dropExemplars { - lv.res.Offer(ctx, value, droppedAttr) + lv.res.Offer(ctx, value, lazy) } } @@ -61,12 +60,12 @@ func newDeltaLastValue[N int64 | float64]( start: now(), hotColdValMap: [2]lastValueMap[N]{ { - values: limitedSyncMap{aggLimit: limit}, newRes: r, + values: limitedSyncMap[*lastValuePoint[N]]{aggLimit: limit}, }, { - values: limitedSyncMap{aggLimit: limit}, newRes: r, + values: limitedSyncMap[*lastValuePoint[N]]{aggLimit: limit}, }, }, } @@ -84,12 +83,11 @@ type deltaLastValue[N int64 | float64] struct { func (s *deltaLastValue[N]) measure( ctx context.Context, value N, - fltrAttr attribute.Set, - droppedAttr []attribute.KeyValue, + lazy lazyFilteredAttributes, ) { hotIdx := s.hcwg.start() defer s.hcwg.done(hotIdx) - s.hotColdValMap[hotIdx].measure(ctx, value, fltrAttr, droppedAttr) + s.hotColdValMap[hotIdx].measure(ctx, value, lazy) } func (s *deltaLastValue[N]) collect( @@ -148,8 +146,8 @@ func newCumulativeLastValue[N int64 | float64]( ) *cumulativeLastValue[N] { return &cumulativeLastValue[N]{ lastValueMap: lastValueMap[N]{ - values: limitedSyncMap{aggLimit: limit}, newRes: r, + values: limitedSyncMap[*lastValuePoint[N]]{aggLimit: limit}, }, start: now(), } diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/lazy_attributes.go b/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/lazy_attributes.go new file mode 100644 index 000000000..2fe886247 --- /dev/null +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/lazy_attributes.go @@ -0,0 +1,146 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package aggregate + +import ( + "math/bits" + + "go.opentelemetry.io/otel/attribute" +) + +type lazyFilteredAttributes struct { + orig attribute.Set + distinct attribute.Distinct + mask uint64 // bitmask of kept attributes (bit i == 1 if kept) for len <= 64 + bigMask []bool // fallback decision slice for len > 64 + hasDropped bool +} + +// newLazyFilteredAttributes filters orig using filter and computes the distinct +// hash of the resulting attributes. The filter function is evaluated once per +// attribute during initialization, and kept attribute indices are recorded in a +// bitmask so subsequent Set and Dropped calls do not re-evaluate filter. +func newLazyFilteredAttributes(orig attribute.Set, filter attribute.Filter) lazyFilteredAttributes { + if filter == nil { + return lazyFilteredAttributes{ + orig: orig, + distinct: orig.Equivalent(), + } + } + l := lazyFilteredAttributes{orig: orig, hasDropped: true} + + n := orig.Len() + hasher := attribute.NewHasher() + keptCount := 0 + for i := range n { + kv, _ := orig.Get(i) + if filter(kv) { + hasher.Write(kv) + l.recordKept(i, keptCount, n) + keptCount++ + } + } + if keptCount == n { + l.hasDropped = false + l.mask = 0 + l.bigMask = nil + l.distinct = orig.Equivalent() + return l + } + keptBefore64 := bits.OnesCount64(l.mask) + if keptCount-keptBefore64 > 0 { + l.ensureBigMask(n, keptCount) + } + l.distinct = hasher.Distinct() + return l +} + +// recordKept marks index i as kept in the bitmask or fallback slice. +func (l *lazyFilteredAttributes) recordKept(i, keptCount, total int) { + if i < 64 { + l.mask |= uint64(1) << i + return + } + if l.bigMask == nil && keptCount < i { + l.ensureBigMask(total, keptCount) + } + if l.bigMask != nil { + l.bigMask[i] = true + } +} + +// ensureBigMask initializes the bigMask slice and backfills any attributes past +// index 63 that were kept before attributes were dropped. +func (l *lazyFilteredAttributes) ensureBigMask(total, keptCount int) { + if l.bigMask != nil { + return + } + l.bigMask = make([]bool, total) + keptBefore64 := bits.OnesCount64(l.mask) + for j := 64; j < 64+(keptCount-keptBefore64); j++ { + l.bigMask[j] = true + } +} + +// isKept reports whether the attribute at index i was kept by the filter. +func (l lazyFilteredAttributes) isKept(i int) bool { + if i < 64 { + return (l.mask & (uint64(1) << i)) != 0 + } + return i < len(l.bigMask) && l.bigMask[i] +} + +// Distinct returns the precomputed Distinct hash of the filtered attributes. +func (l lazyFilteredAttributes) Distinct() attribute.Distinct { + return l.distinct +} + +// HasDroppedAttributes reports whether the filter dropped any attributes. +func (l lazyFilteredAttributes) HasDroppedAttributes() bool { + return l.hasDropped +} + +// Set constructs the filtered attribute Set using the recorded bitmask. +func (l lazyFilteredAttributes) Set() attribute.Set { + if !l.hasDropped { + return l.orig + } + if l.mask == 0 && l.bigMask == nil { + return attribute.NewSet() + } + n := l.orig.Len() + var kept []attribute.KeyValue + for i := range n { + if l.isKept(i) { + if kept == nil { + kept = make([]attribute.KeyValue, 0, n) + } + kv, _ := l.orig.Get(i) + kept = append(kept, kv) + } + } + return attribute.NewSet(kept...) +} + +// Dropped constructs the dropped attribute slice using the recorded bitmask. +func (l lazyFilteredAttributes) Dropped() []attribute.KeyValue { + if !l.hasDropped { + return nil + } + if l.mask == 0 && l.bigMask == nil { + return l.orig.ToSlice() + } + n := l.orig.Len() + var dropped []attribute.KeyValue + for i := range n { + if !l.isKept(i) { + if dropped == nil { + dropped = make([]attribute.KeyValue, 0, n) + } + kv, _ := l.orig.Get(i) + dropped = append(dropped, kv) + } + } + return dropped +} diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/limit.go b/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/limit.go index c19a1aff6..426a8b275 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/limit.go +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/limit.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package aggregate // import "go.opentelemetry.io/otel/sdk/metric/internal/aggregate" +package aggregate import "go.opentelemetry.io/otel/attribute" diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/sum.go b/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/sum.go index 0cd3c9457..c9a67cad8 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/sum.go +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/internal/aggregate/sum.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package aggregate // import "go.opentelemetry.io/otel/sdk/metric/internal/aggregate" +package aggregate import ( "context" @@ -21,17 +21,16 @@ type sumValue[N int64 | float64] struct { } type sumValueMap[N int64 | float64] struct { - values limitedSyncMap newRes func(attribute.Set) FilteredExemplarReservoir[N] + values limitedSyncMap[*sumValue[N]] } func (s *sumValueMap[N]) measure( ctx context.Context, value N, - fltrAttr attribute.Set, - droppedAttr []attribute.KeyValue, + lazy lazyFilteredAttributes, ) { - sv := s.values.LoadOrStoreAttr(fltrAttr, func(attr attribute.Set) any { + sv := s.values.LoadOrStoreAttr(lazy, func(attr attribute.Set) *sumValue[N] { r := s.newRes(attr) _, isDrop := r.(*dropRes[N]) return &sumValue[N]{ @@ -40,13 +39,13 @@ func (s *sumValueMap[N]) measure( startTime: now(), dropExemplars: isDrop, } - }).(*sumValue[N]) + }) sv.n.add(value) // It is possible for collection to race with measurement and observe the // exemplar in the batch of metrics after the add() for cumulative sums. // This is an accepted tradeoff to avoid locking during measurement. if !sv.dropExemplars { - sv.res.Offer(ctx, value, droppedAttr) + sv.res.Offer(ctx, value, lazy) } } @@ -63,12 +62,12 @@ func newDeltaSum[N int64 | float64]( start: now(), hotColdValMap: [2]sumValueMap[N]{ { - values: limitedSyncMap{aggLimit: limit}, newRes: r, + values: limitedSyncMap[*sumValue[N]]{aggLimit: limit}, }, { - values: limitedSyncMap{aggLimit: limit}, newRes: r, + values: limitedSyncMap[*sumValue[N]]{aggLimit: limit}, }, }, } @@ -83,10 +82,10 @@ type deltaSum[N int64 | float64] struct { hotColdValMap [2]sumValueMap[N] } -func (s *deltaSum[N]) measure(ctx context.Context, value N, fltrAttr attribute.Set, droppedAttr []attribute.KeyValue) { +func (s *deltaSum[N]) measure(ctx context.Context, value N, lazy lazyFilteredAttributes) { hotIdx := s.hcwg.start() defer s.hcwg.done(hotIdx) - s.hotColdValMap[hotIdx].measure(ctx, value, fltrAttr, droppedAttr) + s.hotColdValMap[hotIdx].measure(ctx, value, lazy) } func (s *deltaSum[N]) collect( @@ -140,8 +139,8 @@ func newCumulativeSum[N int64 | float64]( monotonic: monotonic, start: now(), sumValueMap: sumValueMap[N]{ - values: limitedSyncMap{aggLimit: limit}, newRes: r, + values: limitedSyncMap[*sumValue[N]]{aggLimit: limit}, }, } } diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/internal/attrnorm/dedup.go b/vendor/go.opentelemetry.io/otel/sdk/metric/internal/attrnorm/dedup.go new file mode 100644 index 000000000..fe9ddc96d --- /dev/null +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/internal/attrnorm/dedup.go @@ -0,0 +1,300 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/attrnorm/dedup.go.tmpl + +// Package attrnorm normalizes attribute values. +package attrnorm + +import ( + "reflect" + "unsafe" + + "go.opentelemetry.io/otel/attribute" +) + +var ( + keyValueType = reflect.TypeFor[attribute.KeyValue]() + valueType = reflect.TypeFor[attribute.Value]() +) + +// rawValue mirrors attribute.Value. It is used only to read immutable slice +// storage without calling AsMap or AsSlice on no-op paths. +type rawValue struct { + vtype attribute.Type + numeric uint64 + stringly string + slice any +} + +// Value returns value with all map values deduplicated and whether it changed. +// +// Duplicate map keys are resolved using last-value-wins semantics. +func Value(value attribute.Value) (attribute.Value, bool) { + switch value.Type() { + case attribute.SLICE: + return deduplicateSliceValue(value) + case attribute.MAP: + return deduplicateMapValue(value) + default: + return value, false + } +} + +// KeyValue returns kv with all map values deduplicated and whether it changed. +func KeyValue(kv attribute.KeyValue) (attribute.KeyValue, bool) { + value, changed := Value(kv.Value) + if changed { + kv.Value = value + } + return kv, changed +} + +// KeyValues returns kvs with all map values deduplicated and whether they changed. +// +// The returned slice is the original kvs slice if no value needs +// deduplication. Top-level keys in kvs are not deduplicated. +func KeyValues(kvs []attribute.KeyValue) ([]attribute.KeyValue, bool) { + // Preserve the caller's slice on the common no-op path. Once a changed + // value is found, copy the prior values exactly once and fill the rest in + // place as the scan continues. + var normalized []attribute.KeyValue + for i, kv := range kvs { + kv, changed := KeyValue(kv) + if normalized != nil { + normalized[i] = kv + continue + } + if !changed { + continue + } + + normalized = make([]attribute.KeyValue, len(kvs)) + copy(normalized, kvs[:i]) + normalized[i] = kv + } + if normalized == nil { + return kvs, false + } + return normalized, true +} + +// Set returns set with all map values deduplicated and whether it changed. +// +// The returned Set is the original set if no value needs deduplication. +// Top-level key uniqueness remains attribute.Set's responsibility; this only +// normalizes map attribute values. +func Set(set attribute.Set) (attribute.Set, bool) { + if set.Len() == 0 { + return set, false + } + + // Most attribute sets contain no duplicate map keys. Delay allocation until + // the first changed value so the no-op path returns the original Set. + var normalized []attribute.KeyValue + for i := range set.Len() { + kv, _ := set.Get(i) + kv, changed := KeyValue(kv) + if normalized != nil { + normalized = append(normalized, kv) + continue + } + if !changed { + continue + } + + normalized = make([]attribute.KeyValue, 0, set.Len()) + for j := range i { + prior, _ := set.Get(j) + normalized = append(normalized, prior) + } + normalized = append(normalized, kv) + } + if normalized == nil { + return set, false + } + + return attribute.NewSet(normalized...), true +} + +func deduplicateSliceValue(value attribute.Value) (attribute.Value, bool) { + storage := valueStorage(value) + length := valueLen(storage) + + // Slice values can contain map values, so recurse into each element while + // keeping the original attribute.Value when no element changes. + var normalized []attribute.Value + for i := range length { + elem := valueAt(storage, i) + elem, changed := Value(elem) + if normalized != nil { + normalized[i] = elem + continue + } + if !changed { + continue + } + + normalized = make([]attribute.Value, length) + for j := range i { + normalized[j] = valueAt(storage, j) + } + normalized[i] = elem + } + if normalized == nil { + return value, false + } + return attribute.SliceValue(normalized...), true +} + +func deduplicateMapValue(value attribute.Value) (attribute.Value, bool) { + storage := valueStorage(value) + length := keyValueLen(storage) + if length <= 1 { + // A single map entry cannot duplicate its own key, but its value might + // contain a map or slice that needs recursive normalization. + if length == 1 { + kv, changed := KeyValue(keyValueAt(storage, 0)) + if changed { + return attribute.MapValue(kv), true + } + } + return value, false + } + + var normalized []attribute.KeyValue + for i := 0; i < length; { + // attribute.MapValue stores key-values sorted by key using a stable + // sort. Equal keys therefore form a contiguous run, and the last + // element in that run is the last value provided by the caller. + first := keyValueAt(storage, i) + j := i + 1 + for j < length && keyValueAt(storage, j).Key == first.Key { + j++ + } + + kv, nestedChanged := KeyValue(keyValueAt(storage, j-1)) + // j-i > 1 means the current key run contained duplicates. + changed := nestedChanged || j-i > 1 + if normalized != nil { + normalized = append(normalized, kv) + } else if changed { + normalized = make([]attribute.KeyValue, 0, length) + for k := range i { + normalized = append(normalized, keyValueAt(storage, k)) + } + normalized = append(normalized, kv) + } + i = j + } + if normalized == nil { + return value, false + } + return attribute.MapValue(normalized...), true +} + +func valueStorage(value attribute.Value) any { + // attribute.Value does not expose allocation-free map/slice iteration. + // The raw mirror lets us read the immutable backing array directly and + // reserve AsMap/AsSlice-style allocation for paths that actually change. + return (*rawValue)( + unsafe.Pointer(&value), + ).slice //nolint:gosec // Read-only mirror of attribute.Value for allocation-free iteration. +} + +func valueLen(storage any) int { + // attribute.Value stores small slices in fixed-size array values. Handle + // the common sizes directly and fall back to reflection for larger arrays. + switch storage.(type) { + case [0]attribute.Value: + return 0 + case [1]attribute.Value: + return 1 + case [2]attribute.Value: + return 2 + case [3]attribute.Value: + return 3 + case [4]attribute.Value: + return 4 + case [5]attribute.Value: + return 5 + default: + return arrayLen(storage, valueType) + } +} + +func valueAt(storage any, i int) attribute.Value { + switch values := storage.(type) { + case [1]attribute.Value: + return values[i] + case [2]attribute.Value: + return values[i] + case [3]attribute.Value: + return values[i] + case [4]attribute.Value: + return values[i] + case [5]attribute.Value: + return values[i] + default: + return arrayAt[attribute.Value](storage, valueType, i) + } +} + +func keyValueLen(storage any) int { + // attribute.Value stores small maps in fixed-size key-value arrays. Handle + // the common sizes directly and fall back to reflection for larger arrays. + switch storage.(type) { + case [0]attribute.KeyValue: + return 0 + case [1]attribute.KeyValue: + return 1 + case [2]attribute.KeyValue: + return 2 + case [3]attribute.KeyValue: + return 3 + case [4]attribute.KeyValue: + return 4 + case [5]attribute.KeyValue: + return 5 + default: + return arrayLen(storage, keyValueType) + } +} + +func keyValueAt(storage any, i int) attribute.KeyValue { + switch kvs := storage.(type) { + case [1]attribute.KeyValue: + return kvs[i] + case [2]attribute.KeyValue: + return kvs[i] + case [3]attribute.KeyValue: + return kvs[i] + case [4]attribute.KeyValue: + return kvs[i] + case [5]attribute.KeyValue: + return kvs[i] + default: + return arrayAt[attribute.KeyValue](storage, keyValueType, i) + } +} + +func arrayLen(storage any, elem reflect.Type) int { + // Be defensive around invalid or unexpected Value storage. Returning zero + // makes malformed storage a no-op instead of panicking in telemetry paths. + array := reflect.ValueOf(storage) + if array.Kind() != reflect.Array || array.Type().Elem() != elem { + return 0 + } + return array.Len() +} + +func arrayAt[T any](storage any, elem reflect.Type, i int) T { + // Match arrayLen's fail-closed behavior for unexpected storage. + array := reflect.ValueOf(storage) + if array.Kind() != reflect.Array || array.Type().Elem() != elem || i < 0 || i >= array.Len() { + var zero T + return zero + } + return array.Index(i).Interface().(T) +} diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/internal/gen.go b/vendor/go.opentelemetry.io/otel/sdk/metric/internal/gen.go new file mode 100644 index 000000000..5f077dfe9 --- /dev/null +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/internal/gen.go @@ -0,0 +1,10 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +// Package internal provides internal functionality for the sdk/metric package. +package internal + +//go:generate gotmpl --body=../../../internal/shared/x/x.go.tmpl "--data={ \"pkg\": \"go.opentelemetry.io/otel/sdk/metric\" }" --out=x/x.go +//go:generate gotmpl --body=../../../internal/shared/x/x_test.go.tmpl "--data={}" --out=x/x_test.go +//go:generate gotmpl --body=../../../internal/shared/attrnorm/dedup.go.tmpl "--data={}" --out=attrnorm/dedup.go +//go:generate gotmpl --body=../../../internal/shared/attrnorm/dedup_test.go.tmpl "--data={}" --out=attrnorm/dedup_test.go diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/internal/observ/instrumentation.go b/vendor/go.opentelemetry.io/otel/sdk/metric/internal/observ/instrumentation.go index c580dcc30..b09748a79 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/internal/observ/instrumentation.go +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/internal/observ/instrumentation.go @@ -3,7 +3,7 @@ // Package observ provides experimental observability instrumentation for the // metric reader. -package observ // import "go.opentelemetry.io/otel/sdk/metric/internal/observ" +package observ import ( "context" @@ -16,8 +16,8 @@ import ( "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/sdk" "go.opentelemetry.io/otel/sdk/internal/x" - semconv "go.opentelemetry.io/otel/semconv/v1.41.0" - "go.opentelemetry.io/otel/semconv/v1.41.0/otelconv" + semconv "go.opentelemetry.io/otel/semconv/v1.43.0" + "go.opentelemetry.io/otel/semconv/v1.43.0/otelconv" ) const ( diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/internal/reservoir/concurrent_safe.go b/vendor/go.opentelemetry.io/otel/sdk/metric/internal/reservoir/concurrent_safe.go index 3be234a41..8542fd94b 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/internal/reservoir/concurrent_safe.go +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/internal/reservoir/concurrent_safe.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package reservoir // import "go.opentelemetry.io/otel/sdk/metric/internal/reservoir" +package reservoir // ConcurrentSafe is an interface that can be embedded in an // exemplar.Reservoir to indicate to the SDK that it is safe to invoke its diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/internal/reservoir/doc.go b/vendor/go.opentelemetry.io/otel/sdk/metric/internal/reservoir/doc.go index 6cd213b5f..6dbf906c8 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/internal/reservoir/doc.go +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/internal/reservoir/doc.go @@ -3,4 +3,4 @@ // Package reservoir contains experimental features used by built-in exemplar // reservoirs which require coordination with the metrics SDK. -package reservoir // import "go.opentelemetry.io/otel/sdk/metric/internal/reservoir" +package reservoir diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/internal/reuse_slice.go b/vendor/go.opentelemetry.io/otel/sdk/metric/internal/reuse_slice.go index ea452be6c..6ddf01473 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/internal/reuse_slice.go +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/internal/reuse_slice.go @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // Package internal provides internal functionality for the metric package. -package internal // import "go.opentelemetry.io/otel/sdk/metric/internal" +package internal // ReuseSlice returns a zeroed view of slice if its capacity is greater than or // equal to n. Otherwise, it returns a new []T with capacity equal to n. diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/internal/x/features.go b/vendor/go.opentelemetry.io/otel/sdk/metric/internal/x/features.go new file mode 100644 index 000000000..a8268702a --- /dev/null +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/internal/x/features.go @@ -0,0 +1,22 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package x + +import "strconv" + +// MetricExportBatchSize is an experimental feature flag that controls the +// max export batch size for metric data. +// +// To enable this feature set the OTEL_GO_X_METRIC_EXPORT_BATCH_SIZE environment +// variable to a positive integer value. +var MetricExportBatchSize = newFeature( + []string{"METRIC_EXPORT_BATCH_SIZE"}, + func(v string) (int, bool) { + val, err := strconv.Atoi(v) + if err == nil && val > 0 { + return val, true + } + return 0, false + }, +) diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/internal/x/x.go b/vendor/go.opentelemetry.io/otel/sdk/metric/internal/x/x.go index 8e3c62a13..fdb75b818 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/internal/x/x.go +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/internal/x/x.go @@ -1,50 +1,54 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -// Package x contains support for OTel metric SDK experimental features. -// -// This package should only be used for features defined in the specification. -// It should not be used for experiments or new project ideas. -package x // import "go.opentelemetry.io/otel/sdk/metric/internal/x" +// DO NOT MODIFY. Generated by gotmpl. +// source: internal/shared/x/x.go.tmpl + +// Package x documents experimental features for [go.opentelemetry.io/otel/sdk/metric]. +package x import ( "os" - "strconv" ) // Feature is an experimental feature control flag. It provides a uniform way // to interact with these feature flags and parse their values. type Feature[T any] struct { - key string + keys []string parse func(v string) (T, bool) } -//nolint:unused -func newFeature[T any](suffix string, parse func(string) (T, bool)) Feature[T] { +func newFeature[T any](suffix []string, parse func(string) (T, bool)) Feature[T] { const envKeyRoot = "OTEL_GO_X_" + keys := make([]string, 0, len(suffix)) + for _, s := range suffix { + keys = append(keys, envKeyRoot+s) + } return Feature[T]{ - key: envKeyRoot + suffix, + keys: keys, parse: parse, } } -// Key returns the environment variable key that needs to be set to enable the +// Keys returns the environment variable keys that can be set to enable the // feature. -func (f Feature[T]) Key() string { return f.key } +func (f Feature[T]) Keys() []string { return f.keys } -// Lookup returns the user configured value for the feature and true if the +// Lookup returns the user-configured value for the feature and true if the // user has enabled the feature. Otherwise, if the feature is not enabled, a -// zero-value and false are returned. +// zero value and false are returned. func (f Feature[T]) Lookup() (v T, ok bool) { // https://github.com/open-telemetry/opentelemetry-specification/blob/62effed618589a0bec416a87e559c0a9d96289bb/specification/configuration/sdk-environment-variables.md#parsing-empty-value // // > The SDK MUST interpret an empty value of an environment variable the // > same way as when the variable is unset. - vRaw := os.Getenv(f.key) - if vRaw == "" { - return v, ok + for _, key := range f.keys { + vRaw := os.Getenv(key) + if vRaw != "" { + return f.parse(vRaw) + } } - return f.parse(vRaw) + return v, ok } // Enabled reports whether the feature is enabled. @@ -52,19 +56,3 @@ func (f Feature[T]) Enabled() bool { _, ok := f.Lookup() return ok } - -// MetricExportBatchSize is an experimental feature flag that controls the -// max export batch size for metric data. -// -// To enable this feature set the OTEL_GO_X_METRIC_EXPORT_BATCH_SIZE environment -// variable to a positive integer value. -var MetricExportBatchSize = newFeature( - "METRIC_EXPORT_BATCH_SIZE", - func(v string) (int, bool) { - val, err := strconv.Atoi(v) - if err == nil && val > 0 { - return val, true - } - return 0, false - }, -) diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/manual_reader.go b/vendor/go.opentelemetry.io/otel/sdk/metric/manual_reader.go index 7e0cccdff..b98e255d8 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/manual_reader.go +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/manual_reader.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package metric // import "go.opentelemetry.io/otel/sdk/metric" +package metric import ( "context" diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/meter.go b/vendor/go.opentelemetry.io/otel/sdk/metric/meter.go index e9a2d5957..8c54974e0 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/meter.go +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/meter.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package metric // import "go.opentelemetry.io/otel/sdk/metric" +package metric import ( "context" @@ -593,11 +593,13 @@ func (r observer) ObserveFloat64(o metric.Float64Observable, v float64, opts ... return } c := metric.NewObserveConfig(opts) + rawKVs := extractRawKVs(opts) + set := resolveAttributes(c.Attributes(), rawKVs) // Access to r.pipe.float64Measure is already guarded by a lock in pipeline.produce. // TODO (#5946): Refactor pipeline and observable measures. measures := r.pipe.float64Measures[oImpl.observableID] for _, m := range measures { - m(context.Background(), v, c.Attributes()) + m(context.Background(), v, set) } } @@ -624,11 +626,13 @@ func (r observer) ObserveInt64(o metric.Int64Observable, v int64, opts ...metric return } c := metric.NewObserveConfig(opts) + rawKVs := extractRawKVs(opts) + set := resolveAttributes(c.Attributes(), rawKVs) // Access to r.pipe.int64Measures is already guarded b a lock in pipeline.produce. // TODO (#5946): Refactor pipeline and observable measures. measures := r.pipe.int64Measures[oImpl.observableID] for _, m := range measures { - m(context.Background(), v, c.Attributes()) + m(context.Background(), v, set) } } @@ -793,7 +797,8 @@ type int64Observer struct { func (o int64Observer) Observe(val int64, opts ...metric.ObserveOption) { c := metric.NewObserveConfig(opts) - o.observe(val, c.Attributes()) + rawKVs := extractRawKVs(opts) + o.observe(val, resolveAttributes(c.Attributes(), rawKVs)) } type float64Observer struct { @@ -803,7 +808,8 @@ type float64Observer struct { func (o float64Observer) Observe(val float64, opts ...metric.ObserveOption) { c := metric.NewObserveConfig(opts) - o.observe(val, c.Attributes()) + rawKVs := extractRawKVs(opts) + o.observe(val, resolveAttributes(c.Attributes(), rawKVs)) } func defaultAttributes[T any](opts []T) []attribute.Key { diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/metricdata/data.go b/vendor/go.opentelemetry.io/otel/sdk/metric/metricdata/data.go index af835e9d9..1caed336e 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/metricdata/data.go +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/metricdata/data.go @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // Package metricdata provides types for the metric SDK data model. -package metricdata // import "go.opentelemetry.io/otel/sdk/metric/metricdata" +package metricdata import ( "encoding/json" diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/metricdata/temporality.go b/vendor/go.opentelemetry.io/otel/sdk/metric/metricdata/temporality.go index 2ac840ff3..8d7c89d85 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/metricdata/temporality.go +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/metricdata/temporality.go @@ -3,7 +3,7 @@ //go:generate stringer -type=Temporality -package metricdata // import "go.opentelemetry.io/otel/sdk/metric/metricdata" +package metricdata // Temporality defines the window that an aggregation was calculated over. type Temporality uint8 diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/periodic_reader.go b/vendor/go.opentelemetry.io/otel/sdk/metric/periodic_reader.go index c1c2e3e2f..9f7712bd5 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/periodic_reader.go +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/periodic_reader.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package metric // import "go.opentelemetry.io/otel/sdk/metric" +package metric import ( "context" @@ -16,7 +16,7 @@ import ( "go.opentelemetry.io/otel/sdk/metric/internal/observ" "go.opentelemetry.io/otel/sdk/metric/internal/x" "go.opentelemetry.io/otel/sdk/metric/metricdata" - semconv "go.opentelemetry.io/otel/semconv/v1.41.0" + semconv "go.opentelemetry.io/otel/semconv/v1.43.0" ) // Default periodic reader timing. diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/pipeline.go b/vendor/go.opentelemetry.io/otel/sdk/metric/pipeline.go index 09d10eeb5..f04c2ddce 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/pipeline.go +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/pipeline.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package metric // import "go.opentelemetry.io/otel/sdk/metric" +package metric import ( "container/list" diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/provider.go b/vendor/go.opentelemetry.io/otel/sdk/metric/provider.go index fd4cdccd0..9f9f01f43 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/provider.go +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/provider.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package metric // import "go.opentelemetry.io/otel/sdk/metric" +package metric import ( "context" @@ -12,6 +12,7 @@ import ( "go.opentelemetry.io/otel/metric/embedded" "go.opentelemetry.io/otel/metric/noop" "go.opentelemetry.io/otel/sdk/instrumentation" + "go.opentelemetry.io/otel/sdk/metric/internal/attrnorm" ) // MeterProvider handles the creation and coordination of Meters. All Meters @@ -76,11 +77,12 @@ func (mp *MeterProvider) Meter(name string, options ...metric.MeterOption) metri } c := metric.NewMeterConfig(options...) + attrs, _ := attrnorm.Set(c.InstrumentationAttributes()) s := instrumentation.Scope{ Name: name, Version: c.InstrumentationVersion(), SchemaURL: c.SchemaURL(), - Attributes: c.InstrumentationAttributes(), + Attributes: attrs, } global.Info( diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/reader.go b/vendor/go.opentelemetry.io/otel/sdk/metric/reader.go index 556afcea6..505c9ad93 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/reader.go +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/reader.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package metric // import "go.opentelemetry.io/otel/sdk/metric" +package metric import ( "context" diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/splitmetrics.go b/vendor/go.opentelemetry.io/otel/sdk/metric/splitmetrics.go index a7931412b..b183cf486 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/splitmetrics.go +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/splitmetrics.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package metric // import "go.opentelemetry.io/otel/sdk/metric" +package metric import ( "go.opentelemetry.io/otel/sdk/metric/metricdata" diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/version.go b/vendor/go.opentelemetry.io/otel/sdk/metric/version.go index 3e1bea4b4..615db8225 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/version.go +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/version.go @@ -1,9 +1,9 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package metric // import "go.opentelemetry.io/otel/sdk/metric" +package metric // version is the current release version of the metric SDK in use. func version() string { - return "1.44.0" + return "1.46.0" } diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/view.go b/vendor/go.opentelemetry.io/otel/sdk/metric/view.go index 13fb7143c..3f98928f9 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/view.go +++ b/vendor/go.opentelemetry.io/otel/sdk/metric/view.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package metric // import "go.opentelemetry.io/otel/sdk/metric" +package metric import ( "errors" diff --git a/vendor/go.opentelemetry.io/otel/sdk/resource/auto.go b/vendor/go.opentelemetry.io/otel/sdk/resource/auto.go index c02aeefdd..8754313af 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/resource/auto.go +++ b/vendor/go.opentelemetry.io/otel/sdk/resource/auto.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package resource // import "go.opentelemetry.io/otel/sdk/resource" +package resource import ( "context" diff --git a/vendor/go.opentelemetry.io/otel/sdk/resource/builtin.go b/vendor/go.opentelemetry.io/otel/sdk/resource/builtin.go index 28823edd5..d5f6dc0a6 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/resource/builtin.go +++ b/vendor/go.opentelemetry.io/otel/sdk/resource/builtin.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package resource // import "go.opentelemetry.io/otel/sdk/resource" +package resource import ( "context" @@ -13,7 +13,7 @@ import ( "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/sdk" - semconv "go.opentelemetry.io/otel/semconv/v1.41.0" + semconv "go.opentelemetry.io/otel/semconv/v1.43.0" ) type ( diff --git a/vendor/go.opentelemetry.io/otel/sdk/resource/config.go b/vendor/go.opentelemetry.io/otel/sdk/resource/config.go index a3d647d92..c5ffa45d0 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/resource/config.go +++ b/vendor/go.opentelemetry.io/otel/sdk/resource/config.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package resource // import "go.opentelemetry.io/otel/sdk/resource" +package resource import ( "context" @@ -23,7 +23,9 @@ type Option interface { apply(config) config } -// WithAttributes adds attributes to the configured Resource. +// WithAttributes adds attributes to the configured Resource. Duplicate +// top-level attribute keys and duplicate keys inside map values are +// resolved using last-value-wins semantics. func WithAttributes(attributes ...attribute.KeyValue) Option { return WithDetectors(detectAttributes{attributes}) } diff --git a/vendor/go.opentelemetry.io/otel/sdk/resource/container.go b/vendor/go.opentelemetry.io/otel/sdk/resource/container.go index ce03e24c4..c81163bf8 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/resource/container.go +++ b/vendor/go.opentelemetry.io/otel/sdk/resource/container.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package resource // import "go.opentelemetry.io/otel/sdk/resource" +package resource import ( "bufio" @@ -11,7 +11,7 @@ import ( "os" "regexp" - semconv "go.opentelemetry.io/otel/semconv/v1.41.0" + semconv "go.opentelemetry.io/otel/semconv/v1.43.0" ) type containerIDProvider func() (string, error) diff --git a/vendor/go.opentelemetry.io/otel/sdk/resource/doc.go b/vendor/go.opentelemetry.io/otel/sdk/resource/doc.go index 64939a271..f5a79d3fe 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/resource/doc.go +++ b/vendor/go.opentelemetry.io/otel/sdk/resource/doc.go @@ -17,4 +17,4 @@ // // While this package provides a stable API, // the attributes added by resource detectors may change. -package resource // import "go.opentelemetry.io/otel/sdk/resource" +package resource diff --git a/vendor/go.opentelemetry.io/otel/sdk/resource/env.go b/vendor/go.opentelemetry.io/otel/sdk/resource/env.go index ac5691c08..0eeb1e2ae 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/resource/env.go +++ b/vendor/go.opentelemetry.io/otel/sdk/resource/env.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package resource // import "go.opentelemetry.io/otel/sdk/resource" +package resource import ( "context" @@ -12,7 +12,7 @@ import ( "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" - semconv "go.opentelemetry.io/otel/semconv/v1.41.0" + semconv "go.opentelemetry.io/otel/semconv/v1.43.0" ) const ( diff --git a/vendor/go.opentelemetry.io/otel/sdk/resource/host_id.go b/vendor/go.opentelemetry.io/otel/sdk/resource/host_id.go index cb38fa1a8..47219be22 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/resource/host_id.go +++ b/vendor/go.opentelemetry.io/otel/sdk/resource/host_id.go @@ -1,14 +1,14 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package resource // import "go.opentelemetry.io/otel/sdk/resource" +package resource import ( "context" "errors" "strings" - semconv "go.opentelemetry.io/otel/semconv/v1.41.0" + semconv "go.opentelemetry.io/otel/semconv/v1.43.0" ) type hostIDProvider func() (string, error) diff --git a/vendor/go.opentelemetry.io/otel/sdk/resource/host_id_bsd.go b/vendor/go.opentelemetry.io/otel/sdk/resource/host_id_bsd.go index 4c1c30f25..bcd174342 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/resource/host_id_bsd.go +++ b/vendor/go.opentelemetry.io/otel/sdk/resource/host_id_bsd.go @@ -3,7 +3,7 @@ //go:build dragonfly || freebsd || netbsd || openbsd || solaris -package resource // import "go.opentelemetry.io/otel/sdk/resource" +package resource var platformHostIDReader hostIDReader = &hostIDReaderBSD{ execCommand: execCommand, diff --git a/vendor/go.opentelemetry.io/otel/sdk/resource/host_id_darwin.go b/vendor/go.opentelemetry.io/otel/sdk/resource/host_id_darwin.go index b09fde3b7..81ece5b34 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/resource/host_id_darwin.go +++ b/vendor/go.opentelemetry.io/otel/sdk/resource/host_id_darwin.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package resource // import "go.opentelemetry.io/otel/sdk/resource" +package resource var platformHostIDReader hostIDReader = &hostIDReaderDarwin{ execCommand: execCommand, diff --git a/vendor/go.opentelemetry.io/otel/sdk/resource/host_id_exec.go b/vendor/go.opentelemetry.io/otel/sdk/resource/host_id_exec.go index e239ead02..c058f0d26 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/resource/host_id_exec.go +++ b/vendor/go.opentelemetry.io/otel/sdk/resource/host_id_exec.go @@ -3,7 +3,7 @@ //go:build darwin || dragonfly || freebsd || netbsd || openbsd || solaris -package resource // import "go.opentelemetry.io/otel/sdk/resource" +package resource import ( "context" diff --git a/vendor/go.opentelemetry.io/otel/sdk/resource/host_id_linux.go b/vendor/go.opentelemetry.io/otel/sdk/resource/host_id_linux.go index 4a26096c8..26cf6a5d1 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/resource/host_id_linux.go +++ b/vendor/go.opentelemetry.io/otel/sdk/resource/host_id_linux.go @@ -3,7 +3,7 @@ //go:build linux -package resource // import "go.opentelemetry.io/otel/sdk/resource" +package resource var platformHostIDReader hostIDReader = &hostIDReaderLinux{ readFile: readFile, diff --git a/vendor/go.opentelemetry.io/otel/sdk/resource/host_id_readfile.go b/vendor/go.opentelemetry.io/otel/sdk/resource/host_id_readfile.go index c95d87685..d955c2c90 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/resource/host_id_readfile.go +++ b/vendor/go.opentelemetry.io/otel/sdk/resource/host_id_readfile.go @@ -3,7 +3,7 @@ //go:build linux || dragonfly || freebsd || netbsd || openbsd || solaris -package resource // import "go.opentelemetry.io/otel/sdk/resource" +package resource import "os" diff --git a/vendor/go.opentelemetry.io/otel/sdk/resource/host_id_unsupported.go b/vendor/go.opentelemetry.io/otel/sdk/resource/host_id_unsupported.go index 63ad2fa4e..9f6ca8211 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/resource/host_id_unsupported.go +++ b/vendor/go.opentelemetry.io/otel/sdk/resource/host_id_unsupported.go @@ -3,7 +3,7 @@ //go:build !darwin && !dragonfly && !freebsd && !linux && !netbsd && !openbsd && !solaris && !windows -package resource // import "go.opentelemetry.io/otel/sdk/resource" +package resource // hostIDReaderUnsupported is a placeholder implementation for operating systems // for which this project currently doesn't support host.id diff --git a/vendor/go.opentelemetry.io/otel/sdk/resource/host_id_windows.go b/vendor/go.opentelemetry.io/otel/sdk/resource/host_id_windows.go index 2b8ca20b3..e9e4a0384 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/resource/host_id_windows.go +++ b/vendor/go.opentelemetry.io/otel/sdk/resource/host_id_windows.go @@ -3,7 +3,7 @@ //go:build windows -package resource // import "go.opentelemetry.io/otel/sdk/resource" +package resource import ( "golang.org/x/sys/windows/registry" diff --git a/vendor/go.opentelemetry.io/otel/sdk/resource/os.go b/vendor/go.opentelemetry.io/otel/sdk/resource/os.go index 4c0def414..6af491567 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/resource/os.go +++ b/vendor/go.opentelemetry.io/otel/sdk/resource/os.go @@ -1,14 +1,14 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package resource // import "go.opentelemetry.io/otel/sdk/resource" +package resource import ( "context" "strings" "go.opentelemetry.io/otel/attribute" - semconv "go.opentelemetry.io/otel/semconv/v1.41.0" + semconv "go.opentelemetry.io/otel/semconv/v1.43.0" ) type osDescriptionProvider func() (string, error) diff --git a/vendor/go.opentelemetry.io/otel/sdk/resource/os_release_darwin.go b/vendor/go.opentelemetry.io/otel/sdk/resource/os_release_darwin.go index 3d703c5d9..f12876d17 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/resource/os_release_darwin.go +++ b/vendor/go.opentelemetry.io/otel/sdk/resource/os_release_darwin.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package resource // import "go.opentelemetry.io/otel/sdk/resource" +package resource import ( "encoding/xml" diff --git a/vendor/go.opentelemetry.io/otel/sdk/resource/os_release_unix.go b/vendor/go.opentelemetry.io/otel/sdk/resource/os_release_unix.go index a1763267c..ad9285854 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/resource/os_release_unix.go +++ b/vendor/go.opentelemetry.io/otel/sdk/resource/os_release_unix.go @@ -3,7 +3,7 @@ //go:build aix || dragonfly || freebsd || linux || netbsd || openbsd || solaris || zos -package resource // import "go.opentelemetry.io/otel/sdk/resource" +package resource import ( "bufio" diff --git a/vendor/go.opentelemetry.io/otel/sdk/resource/os_unix.go b/vendor/go.opentelemetry.io/otel/sdk/resource/os_unix.go index 1cd87c398..ba5e48db2 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/resource/os_unix.go +++ b/vendor/go.opentelemetry.io/otel/sdk/resource/os_unix.go @@ -3,7 +3,7 @@ //go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris || zos -package resource // import "go.opentelemetry.io/otel/sdk/resource" +package resource import ( "fmt" diff --git a/vendor/go.opentelemetry.io/otel/sdk/resource/os_unsupported.go b/vendor/go.opentelemetry.io/otel/sdk/resource/os_unsupported.go index 25f629532..e2c19c2b3 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/resource/os_unsupported.go +++ b/vendor/go.opentelemetry.io/otel/sdk/resource/os_unsupported.go @@ -3,7 +3,7 @@ //go:build !aix && !darwin && !dragonfly && !freebsd && !linux && !netbsd && !openbsd && !solaris && !windows && !zos -package resource // import "go.opentelemetry.io/otel/sdk/resource" +package resource // platformOSDescription is a placeholder implementation for OSes // for which this project currently doesn't support os.description diff --git a/vendor/go.opentelemetry.io/otel/sdk/resource/os_windows.go b/vendor/go.opentelemetry.io/otel/sdk/resource/os_windows.go index ebd50826d..9b7648957 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/resource/os_windows.go +++ b/vendor/go.opentelemetry.io/otel/sdk/resource/os_windows.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package resource // import "go.opentelemetry.io/otel/sdk/resource" +package resource import ( "fmt" diff --git a/vendor/go.opentelemetry.io/otel/sdk/resource/process.go b/vendor/go.opentelemetry.io/otel/sdk/resource/process.go index b015f8233..a578fc325 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/resource/process.go +++ b/vendor/go.opentelemetry.io/otel/sdk/resource/process.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package resource // import "go.opentelemetry.io/otel/sdk/resource" +package resource import ( "context" @@ -11,7 +11,7 @@ import ( "path/filepath" "runtime" - semconv "go.opentelemetry.io/otel/semconv/v1.41.0" + semconv "go.opentelemetry.io/otel/semconv/v1.43.0" ) type ( diff --git a/vendor/go.opentelemetry.io/otel/sdk/resource/resource.go b/vendor/go.opentelemetry.io/otel/sdk/resource/resource.go index f715be53e..dcd7280ac 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/resource/resource.go +++ b/vendor/go.opentelemetry.io/otel/sdk/resource/resource.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package resource // import "go.opentelemetry.io/otel/sdk/resource" +package resource import ( "context" @@ -11,6 +11,7 @@ import ( "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/sdk/internal/attrnorm" "go.opentelemetry.io/otel/sdk/internal/x" ) @@ -47,6 +48,8 @@ var ( var ErrSchemaURLConflict = errors.New("conflicting Schema URL") // New returns a [Resource] built using opts. +// Duplicate top-level attribute keys and duplicate keys inside map +// values are resolved using last-value-wins semantics. // // This may return a partial Resource along with an error containing // [ErrPartialResource] if options that provide a [Detector] are used and that @@ -66,25 +69,29 @@ func New(ctx context.Context, opts ...Option) (*Resource, error) { return r, detect(ctx, r, cfg.detectors) } -// NewWithAttributes creates a resource from attrs and associates the resource with a -// schema URL. If attrs contains duplicate keys, the last value will be used. If attrs -// contains any invalid items those items will be dropped. The attrs are assumed to be -// in a schema identified by schemaURL. +// NewWithAttributes creates a resource from attrs and associates the resource +// with a schema URL. If attrs contains duplicate top-level attribute keys or +// duplicate keys inside map values, the last value will be used. If attrs +// contains any invalid items those items will be dropped. The attrs are assumed +// to be in a schema identified by schemaURL. func NewWithAttributes(schemaURL string, attrs ...attribute.KeyValue) *Resource { resource := NewSchemaless(attrs...) resource.schemaURL = schemaURL return resource } -// NewSchemaless creates a resource from attrs. If attrs contains duplicate keys, -// the last value will be used. If attrs contains any invalid items those items will -// be dropped. The resource will not be associated with a schema URL. If the schema +// NewSchemaless creates a resource from attrs. If attrs contains duplicate +// top-level attribute keys or duplicate keys inside map values, the last +// value will be used. If attrs contains any invalid items those items will be +// dropped. The resource will not be associated with a schema URL. If the schema // of the attrs is known use NewWithAttributes instead. func NewSchemaless(attrs ...attribute.KeyValue) *Resource { if len(attrs) == 0 { return &Resource{} } + attrs, _ = attrnorm.KeyValues(attrs) + // Ensure attributes comply with the specification: // https://github.com/open-telemetry/opentelemetry-specification/blob/v1.20.0/specification/common/README.md#attribute s, _ := attribute.NewSetWithFiltered(attrs, func(kv attribute.KeyValue) bool { @@ -113,6 +120,9 @@ func (r *Resource) String() string { // MarshalLog is the marshaling function used by the logging system to represent this Resource. func (r *Resource) MarshalLog() any { + if r == nil { + r = Empty() + } return struct { Attributes attribute.Set SchemaURL string diff --git a/vendor/go.opentelemetry.io/otel/sdk/trace/batch_span_processor.go b/vendor/go.opentelemetry.io/otel/sdk/trace/batch_span_processor.go index f9f2a6c2c..2b9560ee7 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/trace/batch_span_processor.go +++ b/vendor/go.opentelemetry.io/otel/sdk/trace/batch_span_processor.go @@ -1,11 +1,12 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package trace // import "go.opentelemetry.io/otel/sdk/trace" +package trace import ( "context" "errors" + "fmt" "sync" "sync/atomic" "time" @@ -435,11 +436,11 @@ func (bsp *batchSpanProcessor) enqueueDrop(ctx context.Context, sd ReadOnlySpan) func (bsp *batchSpanProcessor) MarshalLog() any { return struct { Type string - SpanExporter SpanExporter + SpanExporter string Config BatchSpanProcessorOptions }{ Type: "BatchSpanProcessor", - SpanExporter: bsp.e, + SpanExporter: fmt.Sprintf("%T", bsp.e), Config: bsp.o, } } diff --git a/vendor/go.opentelemetry.io/otel/sdk/trace/doc.go b/vendor/go.opentelemetry.io/otel/sdk/trace/doc.go index b502c7d47..b292fa311 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/trace/doc.go +++ b/vendor/go.opentelemetry.io/otel/sdk/trace/doc.go @@ -10,4 +10,4 @@ See https://opentelemetry.io. See [go.opentelemetry.io/otel/sdk/internal/x] for information about the experimental features. */ -package trace // import "go.opentelemetry.io/otel/sdk/trace" +package trace diff --git a/vendor/go.opentelemetry.io/otel/sdk/trace/event.go b/vendor/go.opentelemetry.io/otel/sdk/trace/event.go index 60a7ed134..49eac0459 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/trace/event.go +++ b/vendor/go.opentelemetry.io/otel/sdk/trace/event.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package trace // import "go.opentelemetry.io/otel/sdk/trace" +package trace import ( "time" diff --git a/vendor/go.opentelemetry.io/otel/sdk/trace/evictedqueue.go b/vendor/go.opentelemetry.io/otel/sdk/trace/evictedqueue.go index 8c308dd60..1f62b528c 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/trace/evictedqueue.go +++ b/vendor/go.opentelemetry.io/otel/sdk/trace/evictedqueue.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package trace // import "go.opentelemetry.io/otel/sdk/trace" +package trace import ( "slices" diff --git a/vendor/go.opentelemetry.io/otel/sdk/trace/id_generator.go b/vendor/go.opentelemetry.io/otel/sdk/trace/id_generator.go index 3649322a6..be22ac632 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/trace/id_generator.go +++ b/vendor/go.opentelemetry.io/otel/sdk/trace/id_generator.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package trace // import "go.opentelemetry.io/otel/sdk/trace" +package trace import ( "context" diff --git a/vendor/go.opentelemetry.io/otel/sdk/trace/internal/env/env.go b/vendor/go.opentelemetry.io/otel/sdk/trace/internal/env/env.go index 58f68df44..1385ae6fc 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/trace/internal/env/env.go +++ b/vendor/go.opentelemetry.io/otel/sdk/trace/internal/env/env.go @@ -3,7 +3,7 @@ // Package env provides types and functionality for environment variable support // in the OpenTelemetry SDK. -package env // import "go.opentelemetry.io/otel/sdk/trace/internal/env" +package env import ( "os" diff --git a/vendor/go.opentelemetry.io/otel/sdk/trace/internal/observ/batch_span_processor.go b/vendor/go.opentelemetry.io/otel/sdk/trace/internal/observ/batch_span_processor.go index c725ebf37..896ed517f 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/trace/internal/observ/batch_span_processor.go +++ b/vendor/go.opentelemetry.io/otel/sdk/trace/internal/observ/batch_span_processor.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package observ // import "go.opentelemetry.io/otel/sdk/trace/internal/observ" +package observ import ( "context" @@ -13,8 +13,8 @@ import ( "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/sdk" "go.opentelemetry.io/otel/sdk/internal/x" - semconv "go.opentelemetry.io/otel/semconv/v1.41.0" - "go.opentelemetry.io/otel/semconv/v1.41.0/otelconv" + semconv "go.opentelemetry.io/otel/semconv/v1.43.0" + "go.opentelemetry.io/otel/semconv/v1.43.0/otelconv" ) const ( diff --git a/vendor/go.opentelemetry.io/otel/sdk/trace/internal/observ/doc.go b/vendor/go.opentelemetry.io/otel/sdk/trace/internal/observ/doc.go index b542121e6..64fd5238d 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/trace/internal/observ/doc.go +++ b/vendor/go.opentelemetry.io/otel/sdk/trace/internal/observ/doc.go @@ -3,4 +3,4 @@ // Package observ provides observability instrumentation for the OTel trace SDK // package. -package observ // import "go.opentelemetry.io/otel/sdk/trace/internal/observ" +package observ diff --git a/vendor/go.opentelemetry.io/otel/sdk/trace/internal/observ/simple_span_processor.go b/vendor/go.opentelemetry.io/otel/sdk/trace/internal/observ/simple_span_processor.go index cf4b5d481..e7ca1a6d9 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/trace/internal/observ/simple_span_processor.go +++ b/vendor/go.opentelemetry.io/otel/sdk/trace/internal/observ/simple_span_processor.go @@ -1,38 +1,25 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package observ // import "go.opentelemetry.io/otel/sdk/trace/internal/observ" +package observ import ( "context" "fmt" - "sync" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/sdk" "go.opentelemetry.io/otel/sdk/internal/x" - semconv "go.opentelemetry.io/otel/semconv/v1.41.0" - "go.opentelemetry.io/otel/semconv/v1.41.0/otelconv" + semconv "go.opentelemetry.io/otel/semconv/v1.43.0" + "go.opentelemetry.io/otel/semconv/v1.43.0/otelconv" ) -var measureAttrsPool = sync.Pool{ - New: func() any { - // "component.name" + "component.type" + "error.type" - const n = 1 + 1 + 1 - s := make([]attribute.KeyValue, 0, n) - // Return a pointer to a slice instead of a slice itself - // to avoid allocations on every call. - return &s - }, -} - // SSP is the instrumentation for an OTel SDK SimpleSpanProcessor. type SSP struct { spansProcessedCounter metric.Int64Counter addOpts []metric.AddOption - attrs []attribute.KeyValue } // SSPComponentName returns the component name attribute for a @@ -70,29 +57,12 @@ func NewSSP(id int64) (*SSP, error) { return &SSP{ spansProcessedCounter: spansProcessedCounter.Inst(), addOpts: addOpts, - attrs: attrs, }, err } -// SpanProcessed records that a span has been processed by the SimpleSpanProcessor. -// If err is non-nil, it records the processing error as an attribute. -func (ssp *SSP) SpanProcessed(ctx context.Context, err error) { - ssp.spansProcessedCounter.Add(ctx, 1, ssp.addOption(err)...) -} - -func (ssp *SSP) addOption(err error) []metric.AddOption { - if err == nil { - return ssp.addOpts - } - attrs := measureAttrsPool.Get().(*[]attribute.KeyValue) - defer func() { - clear(*attrs) - *attrs = (*attrs)[:0] // reset the slice for reuse - measureAttrsPool.Put(attrs) - }() - *attrs = append(*attrs, ssp.attrs...) - *attrs = append(*attrs, semconv.ErrorType(err)) - // Do not inefficiently make a copy of attrs by using - // WithAttributes instead of WithAttributeSet. - return []metric.AddOption{metric.WithAttributeSet(attribute.NewSet(*attrs...))} +// SpanProcessed records that a span has been submitted to the exporter by the +// SimpleSpanProcessor. Per the semantic conventions, this count is recorded at +// submission time and MUST NOT be affected by the export outcome. +func (ssp *SSP) SpanProcessed(ctx context.Context) { + ssp.spansProcessedCounter.Add(ctx, 1, ssp.addOpts...) } diff --git a/vendor/go.opentelemetry.io/otel/sdk/trace/internal/observ/tracer.go b/vendor/go.opentelemetry.io/otel/sdk/trace/internal/observ/tracer.go index 5aae89e88..3428aa894 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/trace/internal/observ/tracer.go +++ b/vendor/go.opentelemetry.io/otel/sdk/trace/internal/observ/tracer.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package observ // import "go.opentelemetry.io/otel/sdk/trace/internal/observ" +package observ import ( "context" @@ -13,7 +13,7 @@ import ( "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/sdk" "go.opentelemetry.io/otel/sdk/internal/x" - "go.opentelemetry.io/otel/semconv/v1.41.0/otelconv" + "go.opentelemetry.io/otel/semconv/v1.43.0/otelconv" "go.opentelemetry.io/otel/trace" ) diff --git a/vendor/go.opentelemetry.io/otel/sdk/trace/link.go b/vendor/go.opentelemetry.io/otel/sdk/trace/link.go index c03bdc90f..d4a07a714 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/trace/link.go +++ b/vendor/go.opentelemetry.io/otel/sdk/trace/link.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package trace // import "go.opentelemetry.io/otel/sdk/trace" +package trace import ( "go.opentelemetry.io/otel/attribute" diff --git a/vendor/go.opentelemetry.io/otel/sdk/trace/provider.go b/vendor/go.opentelemetry.io/otel/sdk/trace/provider.go index 9d90c2eda..6b2368413 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/trace/provider.go +++ b/vendor/go.opentelemetry.io/otel/sdk/trace/provider.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package trace // import "go.opentelemetry.io/otel/sdk/trace" +package trace import ( "context" @@ -13,6 +13,7 @@ import ( "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/internal/global" "go.opentelemetry.io/otel/sdk/instrumentation" + "go.opentelemetry.io/otel/sdk/internal/attrnorm" "go.opentelemetry.io/otel/sdk/resource" "go.opentelemetry.io/otel/sdk/trace/internal/observ" "go.opentelemetry.io/otel/trace" @@ -42,22 +43,27 @@ type tracerProviderConfig struct { // resource contains attributes representing an entity that produces telemetry. resource *resource.Resource + + // panicRecordingDisabled disables recording exception events from panics. + panicRecordingDisabled bool } // MarshalLog is the marshaling function used by the logging system to represent this Provider. func (cfg tracerProviderConfig) MarshalLog() any { return struct { - SpanProcessors []SpanProcessor - SamplerType string - IDGeneratorType string - SpanLimits SpanLimits - Resource *resource.Resource + SpanProcessors []SpanProcessor + SamplerType string + IDGeneratorType string + SpanLimits SpanLimits + Resource *resource.Resource + PanicRecordingDisabled bool }{ - SpanProcessors: cfg.processors, - SamplerType: fmt.Sprintf("%T", cfg.sampler), - IDGeneratorType: fmt.Sprintf("%T", cfg.idGenerator), - SpanLimits: cfg.spanLimits, - Resource: cfg.resource, + SpanProcessors: cfg.processors, + SamplerType: fmt.Sprintf("%T", cfg.sampler), + IDGeneratorType: fmt.Sprintf("%T", cfg.idGenerator), + SpanLimits: cfg.spanLimits, + Resource: cfg.resource, + PanicRecordingDisabled: cfg.panicRecordingDisabled, } } @@ -74,10 +80,11 @@ type TracerProvider struct { // These fields are not protected by the lock mu. They are assumed to be // immutable after creation of the TracerProvider. - sampler Sampler - idGenerator IDGenerator - spanLimits SpanLimits - resource *resource.Resource + sampler Sampler + idGenerator IDGenerator + spanLimits SpanLimits + resource *resource.Resource + panicRecordingDisabled bool } var _ trace.TracerProvider = &TracerProvider{} @@ -112,11 +119,12 @@ func NewTracerProvider(opts ...TracerProviderOption) *TracerProvider { o = ensureValidTracerProviderConfig(o) tp := &TracerProvider{ - namedTracer: make(map[instrumentation.Scope]*tracer), - sampler: o.sampler, - idGenerator: o.idGenerator, - spanLimits: o.spanLimits, - resource: o.resource, + namedTracer: make(map[instrumentation.Scope]*tracer), + sampler: o.sampler, + idGenerator: o.idGenerator, + spanLimits: o.spanLimits, + resource: o.resource, + panicRecordingDisabled: o.panicRecordingDisabled, } global.Info("TracerProvider created", "config", o) @@ -142,6 +150,7 @@ func (p *TracerProvider) Tracer(name string, opts ...trace.TracerOption) trace.T return noop.NewTracerProvider().Tracer(name, opts...) } c := trace.NewTracerConfig(opts...) + attrs, _ := attrnorm.Set(c.InstrumentationAttributes()) if name == "" { name = defaultTracerName } @@ -149,7 +158,7 @@ func (p *TracerProvider) Tracer(name string, opts ...trace.TracerOption) trace.T Name: name, Version: c.InstrumentationVersion(), SchemaURL: c.SchemaURL(), - Attributes: c.InstrumentationAttributes(), + Attributes: attrs, } t, ok := func() (trace.Tracer, bool) { @@ -357,6 +366,16 @@ func WithSpanProcessor(sp SpanProcessor) TracerProviderOption { }) } +// WithoutPanicRecording configures the TracerProvider to not record exception +// events when a Span is ended while panicking. The panic continues to +// propagate, and the span is ended without adding the event. +func WithoutPanicRecording() TracerProviderOption { + return traceProviderOptionFunc(func(cfg tracerProviderConfig) tracerProviderConfig { + cfg.panicRecordingDisabled = true + return cfg + }) +} + // WithResource returns a TracerProviderOption that will configure the // Resource r as a TracerProvider's Resource. The configured Resource is // referenced by all the Tracers the TracerProvider creates. It represents the diff --git a/vendor/go.opentelemetry.io/otel/sdk/trace/sampler_env.go b/vendor/go.opentelemetry.io/otel/sdk/trace/sampler_env.go index 9b672a1d7..b0fa94ed2 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/trace/sampler_env.go +++ b/vendor/go.opentelemetry.io/otel/sdk/trace/sampler_env.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package trace // import "go.opentelemetry.io/otel/sdk/trace" +package trace import ( "errors" diff --git a/vendor/go.opentelemetry.io/otel/sdk/trace/sampling.go b/vendor/go.opentelemetry.io/otel/sdk/trace/sampling.go index 5a4c74318..c79177ae8 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/trace/sampling.go +++ b/vendor/go.opentelemetry.io/otel/sdk/trace/sampling.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package trace // import "go.opentelemetry.io/otel/sdk/trace" +package trace import ( "context" diff --git a/vendor/go.opentelemetry.io/otel/sdk/trace/simple_span_processor.go b/vendor/go.opentelemetry.io/otel/sdk/trace/simple_span_processor.go index 771e427a4..97985c498 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/trace/simple_span_processor.go +++ b/vendor/go.opentelemetry.io/otel/sdk/trace/simple_span_processor.go @@ -1,10 +1,11 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package trace // import "go.opentelemetry.io/otel/sdk/trace" +package trace import ( "context" + "fmt" "sync" "sync/atomic" @@ -66,19 +67,19 @@ func (ssp *simpleSpanProcessor) OnEnd(s ReadOnlySpan) { ssp.exporterMu.Lock() defer ssp.exporterMu.Unlock() - var err error - if ssp.exporter != nil && s.SpanContext().TraceFlags().IsSampled() { - err = ssp.exporter.ExportSpans(context.Background(), []ReadOnlySpan{s}) - if err != nil { - otel.Handle(err) - } - } - if ssp.inst != nil { // Add the span to the context to ensure the metric is recorded - // with the correct span context. + // with the correct span context. Record the span as processed before + // invoking the exporter so the count is unaffected by the export + // outcome. ctx := trace.ContextWithSpanContext(context.Background(), s.SpanContext()) - ssp.inst.SpanProcessed(ctx, err) + ssp.inst.SpanProcessed(ctx) + } + + if ssp.exporter != nil && s.SpanContext().TraceFlags().IsSampled() { + if err := ssp.exporter.ExportSpans(context.Background(), []ReadOnlySpan{s}); err != nil { + otel.Handle(err) + } } } @@ -140,11 +141,18 @@ func (*simpleSpanProcessor) ForceFlush(context.Context) error { // MarshalLog is the marshaling function used by the logging system to represent // this Span Processor. func (ssp *simpleSpanProcessor) MarshalLog() any { + // Shutdown clears exporter under exporterMu. + // Copy it while holding the same lock so MarshalLog + // can run concurrently without racing with Shutdown. + ssp.exporterMu.Lock() + exp := ssp.exporter + ssp.exporterMu.Unlock() + return struct { Type string - Exporter SpanExporter + Exporter string }{ Type: "SimpleSpanProcessor", - Exporter: ssp.exporter, + Exporter: fmt.Sprintf("%T", exp), } } diff --git a/vendor/go.opentelemetry.io/otel/sdk/trace/snapshot.go b/vendor/go.opentelemetry.io/otel/sdk/trace/snapshot.go index 63aa33780..8893dc39f 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/trace/snapshot.go +++ b/vendor/go.opentelemetry.io/otel/sdk/trace/snapshot.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package trace // import "go.opentelemetry.io/otel/sdk/trace" +package trace import ( "time" diff --git a/vendor/go.opentelemetry.io/otel/sdk/trace/span.go b/vendor/go.opentelemetry.io/otel/sdk/trace/span.go index d1d9af29d..aae977314 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/trace/span.go +++ b/vendor/go.opentelemetry.io/otel/sdk/trace/span.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package trace // import "go.opentelemetry.io/otel/sdk/trace" +package trace import ( "context" @@ -10,17 +10,16 @@ import ( "runtime" rt "runtime/trace" "slices" - "strings" "sync" "time" - "unicode/utf8" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/internal/global" "go.opentelemetry.io/otel/sdk/instrumentation" + "go.opentelemetry.io/otel/sdk/internal/attrnorm" "go.opentelemetry.io/otel/sdk/resource" - semconv "go.opentelemetry.io/otel/semconv/v1.41.0" + semconv "go.opentelemetry.io/otel/semconv/v1.43.0" "go.opentelemetry.io/otel/trace" "go.opentelemetry.io/otel/trace/embedded" ) @@ -139,6 +138,11 @@ type recordingSpan struct { attributes []attribute.KeyValue droppedAttributes int logDropAttrsOnce sync.Once + // attributesDirty indicates attributes may contain duplicate keys. + attributesDirty bool + // attributesShared indicates the attributes backing array has been exposed + // to a reader and must not be modified. + attributesShared bool // events are stored in FIFO queue capped by configured limit. events evictedQueue[Event] @@ -252,6 +256,11 @@ func (s *recordingSpan) SetAttributes(attributes ...attribute.KeyValue) { s.addDroppedAttr(len(attributes)) return } + maxCap := len(s.attributes) + len(attributes) + if limit > 0 { + maxCap = min(maxCap, limit) + } + s.ensureAttrsWritable(maxCap) // If adding these attributes could exceed the capacity of s perform a // de-duplication and truncation while adding to avoid over allocation. @@ -269,9 +278,24 @@ func (s *recordingSpan) SetAttributes(attributes ...attribute.KeyValue) { s.addDroppedAttr(1) continue } - a = truncateAttr(s.tracer.provider.spanLimits.AttributeValueLengthLimit, a) + a = dedupAttr(a) + a = attrnorm.Truncate(s.tracer.provider.spanLimits.AttributeValueLengthLimit, a) s.attributes = append(s.attributes, a) + s.attributesDirty = true + } +} + +// ensureAttrsWritable copies shared attributes into a backing array with at +// least capacity. This method assumes s.mu.Lock is held by the caller. +func (s *recordingSpan) ensureAttrsWritable(capacity int) { + if !s.attributesShared { + return } + capacity = max(capacity, len(s.attributes)) + attrs := make([]attribute.KeyValue, len(s.attributes), capacity) + copy(attrs, s.attributes) + s.attributes = attrs + s.attributesShared = false } // Declared as a var so tests can override. @@ -329,7 +353,8 @@ func (s *recordingSpan) addOverCapAttrs(limit int, attrs []attribute.KeyValue) { if idx, ok := exists[a.Key]; ok { // Perform all updates before dropping, even when at capacity. - a = truncateAttr(s.tracer.provider.spanLimits.AttributeValueLengthLimit, a) + a = dedupAttr(a) + a = attrnorm.Truncate(s.tracer.provider.spanLimits.AttributeValueLengthLimit, a) s.attributes[idx] = a continue } @@ -339,208 +364,31 @@ func (s *recordingSpan) addOverCapAttrs(limit int, attrs []attribute.KeyValue) { // updates are checked and performed. s.addDroppedAttr(1) } else { - a = truncateAttr(s.tracer.provider.spanLimits.AttributeValueLengthLimit, a) + a = dedupAttr(a) + a = attrnorm.Truncate(s.tracer.provider.spanLimits.AttributeValueLengthLimit, a) s.attributes = append(s.attributes, a) exists[a.Key] = len(s.attributes) - 1 } } } -// truncateAttr returns a truncated version of attr. Only string, string -// slice, byte slice, and slice attribute values are truncated. String values are truncated -// to at most a length of limit. Each string slice value is truncated in this -// fashion (the slice length itself is unaffected), and byte slice values are truncated to at most -// limit bytes. For slice attribute values, the limit is applied to each -// element recursively. -// -// No truncation is performed for a negative limit. -func truncateAttr(limit int, attr attribute.KeyValue) attribute.KeyValue { - if limit < 0 { - return attr - } +func dedupAttr(attr attribute.KeyValue) attribute.KeyValue { switch attr.Value.Type() { - case attribute.STRING: - v := attr.Value.AsString() - return attr.Key.String(truncate(limit, v)) - case attribute.STRINGSLICE: - v := attr.Value.AsStringSlice() - for i := range v { - v[i] = truncate(limit, v[i]) - } - return attr.Key.StringSlice(v) - case attribute.BYTESLICE: - v := attr.Value.AsString() - if len(v) > limit { - return attr.Key.ByteSlice([]byte(v[:limit])) - } + case attribute.SLICE, attribute.MAP: + attr, _ = attrnorm.KeyValue(attr) + return attr + default: return attr - case attribute.SLICE: - v := attr.Value.AsSlice() - if !slices.ContainsFunc(v, func(e attribute.Value) bool { return needsTruncation(limit, e) }) { - return attr - } - newV := make([]attribute.Value, len(v)) - for i, elem := range v { - newV[i] = truncateValue(limit, elem) - } - return attr.Key.Slice(newV...) - } - return attr -} - -// truncateValue returns a truncated version of v. Only string, string slice, -// byte slice, and (recursively) slice values are modified. -// -// No truncation is performed for a negative limit. -func truncateValue(limit int, v attribute.Value) attribute.Value { - switch v.Type() { - case attribute.STRING: - return attribute.StringValue(truncate(limit, v.AsString())) - case attribute.STRINGSLICE: - ss := v.AsStringSlice() - for i := range ss { - ss[i] = truncate(limit, ss[i]) - } - return attribute.StringSliceValue(ss) - - case attribute.BYTESLICE: - // len(v.AsString()) is identical to len(v.AsByteSlice()) but - // avoids allocating the full slice before truncation. - s := v.AsString() - if limit >= 0 && len(s) > limit { - return attribute.ByteSliceValue([]byte(s[:limit])) - } - case attribute.SLICE: - sl := v.AsSlice() - if !slices.ContainsFunc(sl, func(e attribute.Value) bool { return needsTruncation(limit, e) }) { - return v - } - newSl := make([]attribute.Value, len(sl)) - for i, elem := range sl { - newSl[i] = truncateValue(limit, elem) - } - return attribute.SliceValue(newSl...) - } - return v -} - -// stringNeedsTruncation reports whether s would be modified by truncate for the -// given limit. -func stringNeedsTruncation(limit int, s string) bool { - if limit < 0 || len(s) <= limit { - return false - } - return utf8.RuneCountInString(s) > limit || !utf8.ValidString(s) -} - -// needsTruncation reports whether v would be modified by truncateValue for the -// given limit. -func needsTruncation(limit int, v attribute.Value) bool { - switch v.Type() { - case attribute.STRING: - return stringNeedsTruncation(limit, v.AsString()) - case attribute.BYTESLICE: - // len(v.AsString()) is identical to len(v.AsByteSlice()) but - // avoids memory allocation. - if limit >= 0 && len(v.AsString()) > limit { - return true - } - case attribute.STRINGSLICE: - for _, s := range v.AsStringSlice() { - if stringNeedsTruncation(limit, s) { - return true - } - } - case attribute.SLICE: - return slices.ContainsFunc(v.AsSlice(), func(e attribute.Value) bool { return needsTruncation(limit, e) }) - } - return false -} - -// truncate returns a truncated version of s such that it contains less than -// the limit number of characters. Truncation is applied by returning the limit -// number of valid characters contained in s. -// -// If limit is negative, it returns the original string. -// -// UTF-8 is supported. When truncating, all invalid characters are dropped -// before applying truncation. -// -// If s already contains less than the limit number of bytes, it is returned -// unchanged. No invalid characters are removed. -func truncate(limit int, s string) string { - // This prioritize performance in the following order based on the most - // common expected use-cases. - // - // - Short values less than the default limit (128). - // - Strings with valid encodings that exceed the limit. - // - No limit. - // - Strings with invalid encodings that exceed the limit. - if limit < 0 || len(s) <= limit { - return s - } - - // Optimistically, assume all valid UTF-8. - var b strings.Builder - count := 0 - for i, c := range s { - if c != utf8.RuneError { - count++ - if count > limit { - return s[:i] - } - continue - } - - _, size := utf8.DecodeRuneInString(s[i:]) - if size == 1 { - // Invalid encoding. - b.Grow(len(s) - 1) - _, _ = b.WriteString(s[:i]) - s = s[i:] - break - } - } - - // Fast-path, no invalid input. - if b.Cap() == 0 { - return s - } - - // Truncate while validating UTF-8. - for i := 0; i < len(s) && count < limit; { - c := s[i] - if c < utf8.RuneSelf { - // Optimization for single byte runes (common case). - _ = b.WriteByte(c) - i++ - count++ - continue - } - - _, size := utf8.DecodeRuneInString(s[i:]) - if size == 1 { - // We checked for all 1-byte runes above, this is a RuneError. - i++ - continue - } - - _, _ = b.WriteString(s[i : i+size]) - i += size - count++ } - - return b.String() } // End ends the span. This method does nothing if the span is already ended or // is not being recorded. // -// The only SpanEndOption currently supported are [trace.WithTimestamp], and -// [trace.WithStackTrace]. -// -// If this method is called while panicking an error event is added to the -// Span before ending it and the panic is continued. +// The only supported SpanEndOptions are [trace.WithTimestamp] and [trace.WithStackTrace]. +// If this method is called while panicking and panic recording is not disabled +// on the TracerProvider, an error event is added to the Span before ending it +// and the panic is continued. func (s *recordingSpan) End(options ...trace.SpanEndOption) { // Do not start by checking if the span is being recorded which requires // acquiring a lock. Make a minimal check that the span is not nil. @@ -560,23 +408,25 @@ func (s *recordingSpan) End(options ...trace.SpanEndOption) { } config := trace.NewSpanEndConfig(options...) - if recovered := recover(); recovered != nil { - // Record but don't stop the panic. - defer panic(recovered) - opts := []trace.EventOption{ - trace.WithAttributes( - semconv.ExceptionType(typeStr(recovered)), - semconv.ExceptionMessage(fmt.Sprint(recovered)), - ), - } + if !s.tracer.provider.panicRecordingDisabled { + if recovered := recover(); recovered != nil { + // Record but don't stop the panic. + defer panic(recovered) + opts := []trace.EventOption{ + trace.WithAttributes( + semconv.ExceptionType(typeStr(recovered)), + semconv.ExceptionMessage(fmt.Sprint(recovered)), + ), + } - if config.StackTrace() { - opts = append(opts, trace.WithAttributes( - semconv.ExceptionStacktrace(recordStackTrace()), - )) - } + if config.StackTrace() { + opts = append(opts, trace.WithAttributes( + semconv.ExceptionStacktrace(recordStackTrace()), + )) + } - s.addEvent(semconv.ExceptionEventName, opts...) + s.addEvent(semconv.ExceptionEventName, opts...) + } } if s.executionTracerTaskEnd != nil { @@ -690,7 +540,8 @@ func (s *recordingSpan) AddEvent(name string, o ...trace.EventOption) { // This method assumes s.mu.Lock is held by the caller. func (s *recordingSpan) addEvent(name string, o ...trace.EventOption) { c := trace.NewEventConfig(o...) - e := Event{Name: name, Attributes: c.Attributes(), Time: c.Timestamp()} + attrs, _ := attrnorm.KeyValues(c.Attributes()) + e := Event{Name: name, Attributes: attrs, Time: c.Timestamp()} // Discard attributes over limit. limit := s.tracer.provider.spanLimits.AttributePerEventCountLimit @@ -765,6 +616,7 @@ func (s *recordingSpan) Attributes() []attribute.KeyValue { s.mu.Lock() defer s.mu.Unlock() s.dedupeAttrs() + s.attributesShared = cap(s.attributes) > 0 return s.attributes } @@ -772,6 +624,10 @@ func (s *recordingSpan) Attributes() []attribute.KeyValue { // // This method assumes s.mu.Lock is held by the caller. func (s *recordingSpan) dedupeAttrs() { + if !s.attributesDirty { + return + } + s.ensureAttrsWritable(len(s.attributes)) // Do not set a capacity when creating this map. Benchmark testing has // showed this to only add unused memory allocations in general use. exists := make(map[attribute.Key]int, len(s.attributes)) @@ -795,6 +651,7 @@ func (s *recordingSpan) dedupeAttrsFromRecord(record map[attribute.Key]int) { } clear(s.attributes[len(unique):]) // Erase unneeded elements to let GC collect objects. s.attributes = unique + s.attributesDirty = false } // Links returns the links of this span. @@ -863,7 +720,8 @@ func (s *recordingSpan) AddLink(link trace.Link) { return } - l := Link{SpanContext: link.SpanContext, Attributes: link.Attributes} + attrs, _ := attrnorm.KeyValues(link.Attributes) + l := Link{SpanContext: link.SpanContext, Attributes: attrs} // Discard attributes over limit. limit := s.tracer.provider.spanLimits.AttributePerLinkCountLimit @@ -937,6 +795,7 @@ func (s *recordingSpan) snapshot() ReadOnlySpan { if len(s.attributes) > 0 { s.dedupeAttrs() sd.attributes = s.attributes + s.attributesShared = true } sd.droppedAttributeCount = s.droppedAttributes if len(s.events.queue) > 0 { diff --git a/vendor/go.opentelemetry.io/otel/sdk/trace/span_exporter.go b/vendor/go.opentelemetry.io/otel/sdk/trace/span_exporter.go index 6bdda3d94..fad839a24 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/trace/span_exporter.go +++ b/vendor/go.opentelemetry.io/otel/sdk/trace/span_exporter.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package trace // import "go.opentelemetry.io/otel/sdk/trace" +package trace import "context" diff --git a/vendor/go.opentelemetry.io/otel/sdk/trace/span_limits.go b/vendor/go.opentelemetry.io/otel/sdk/trace/span_limits.go index 348ee0e80..5ee15a884 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/trace/span_limits.go +++ b/vendor/go.opentelemetry.io/otel/sdk/trace/span_limits.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package trace // import "go.opentelemetry.io/otel/sdk/trace" +package trace import "go.opentelemetry.io/otel/sdk/trace/internal/env" @@ -35,10 +35,10 @@ const ( type SpanLimits struct { // AttributeValueLengthLimit is the maximum allowed attribute value length. // - // This limit only applies to string, string slice, byte slice, and slice attribute - // values. Any string and byte slice longer than this value will be truncated to this - // length. For slice attribute values, the limit is applied to each string and byte slice - // element recursively. + // This limit only applies to string, string slice, byte slice, slice, and + // map attribute values. Any string and byte slice longer than this value + // will be truncated to this length. For slice and map attribute values, + // the limit is applied recursively to contained values. // // Setting this to a negative value means no limit is applied. AttributeValueLengthLimit int diff --git a/vendor/go.opentelemetry.io/otel/sdk/trace/span_processor.go b/vendor/go.opentelemetry.io/otel/sdk/trace/span_processor.go index af7f9177f..ffd093a2f 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/trace/span_processor.go +++ b/vendor/go.opentelemetry.io/otel/sdk/trace/span_processor.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package trace // import "go.opentelemetry.io/otel/sdk/trace" +package trace import ( "context" diff --git a/vendor/go.opentelemetry.io/otel/sdk/trace/tracer.go b/vendor/go.opentelemetry.io/otel/sdk/trace/tracer.go index e1d08fd4d..be576ffe0 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/trace/tracer.go +++ b/vendor/go.opentelemetry.io/otel/sdk/trace/tracer.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package trace // import "go.opentelemetry.io/otel/sdk/trace" +package trace import ( "context" diff --git a/vendor/go.opentelemetry.io/otel/sdk/version.go b/vendor/go.opentelemetry.io/otel/sdk/version.go index 218dce1f5..621d6d7e6 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/version.go +++ b/vendor/go.opentelemetry.io/otel/sdk/version.go @@ -2,9 +2,9 @@ // SPDX-License-Identifier: Apache-2.0 // Package sdk provides the OpenTelemetry default SDK for Go. -package sdk // import "go.opentelemetry.io/otel/sdk" +package sdk // Version is the current release version of the OpenTelemetry SDK in use. func Version() string { - return "1.44.0" + return "1.46.0" } diff --git a/vendor/go.opentelemetry.io/otel/semconv/internal/metricpool/pool.go b/vendor/go.opentelemetry.io/otel/semconv/internal/metricpool/pool.go new file mode 100644 index 000000000..c5f5ad46e --- /dev/null +++ b/vendor/go.opentelemetry.io/otel/semconv/internal/metricpool/pool.go @@ -0,0 +1,48 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +// Package metricpool provides shared pools for semantic convention metric +// measurement options. +package metricpool + +import ( + "sync" + + "go.opentelemetry.io/otel/metric" +) + +var ( + addOptionsPool = sync.Pool{New: func() any { + o := make([]metric.AddOption, 0, 1) + return &o + }} + recOptionsPool = sync.Pool{New: func() any { + o := make([]metric.RecordOption, 0, 1) + return &o + }} +) + +// AddOptions returns a pooled AddOption slice. +func AddOptions() *[]metric.AddOption { + return addOptionsPool.Get().(*[]metric.AddOption) +} + +// PutAddOptions clears, resets, and returns o to the shared AddOption pool. +func PutAddOptions(o *[]metric.AddOption) { + clear(*o) + *o = (*o)[:0] + addOptionsPool.Put(o) +} + +// RecordOptions returns a pooled RecordOption slice. +func RecordOptions() *[]metric.RecordOption { + return recOptionsPool.Get().(*[]metric.RecordOption) +} + +// PutRecordOptions clears, resets, and returns o to the shared RecordOption +// pool. +func PutRecordOptions(o *[]metric.RecordOption) { + clear(*o) + *o = (*o)[:0] + recOptionsPool.Put(o) +} diff --git a/vendor/go.opentelemetry.io/otel/semconv/v1.20.0/attribute_group.go b/vendor/go.opentelemetry.io/otel/semconv/v1.20.0/attribute_group.go index 6685c392b..eb27d3dff 100644 --- a/vendor/go.opentelemetry.io/otel/semconv/v1.20.0/attribute_group.go +++ b/vendor/go.opentelemetry.io/otel/semconv/v1.20.0/attribute_group.go @@ -3,7 +3,7 @@ // Code generated from semantic convention specification. DO NOT EDIT. -package semconv // import "go.opentelemetry.io/otel/semconv/v1.20.0" +package semconv import "go.opentelemetry.io/otel/attribute" diff --git a/vendor/go.opentelemetry.io/otel/semconv/v1.20.0/doc.go b/vendor/go.opentelemetry.io/otel/semconv/v1.20.0/doc.go index 0d1f55a8f..02e4c6cab 100644 --- a/vendor/go.opentelemetry.io/otel/semconv/v1.20.0/doc.go +++ b/vendor/go.opentelemetry.io/otel/semconv/v1.20.0/doc.go @@ -6,4 +6,4 @@ // OpenTelemetry semantic conventions are agreed standardized naming // patterns for OpenTelemetry things. This package represents the conventions // as of the v1.20.0 version of the OpenTelemetry specification. -package semconv // import "go.opentelemetry.io/otel/semconv/v1.20.0" +package semconv diff --git a/vendor/go.opentelemetry.io/otel/semconv/v1.20.0/event.go b/vendor/go.opentelemetry.io/otel/semconv/v1.20.0/event.go index 637763932..20b495e5a 100644 --- a/vendor/go.opentelemetry.io/otel/semconv/v1.20.0/event.go +++ b/vendor/go.opentelemetry.io/otel/semconv/v1.20.0/event.go @@ -3,7 +3,7 @@ // Code generated from semantic convention specification. DO NOT EDIT. -package semconv // import "go.opentelemetry.io/otel/semconv/v1.20.0" +package semconv import "go.opentelemetry.io/otel/attribute" diff --git a/vendor/go.opentelemetry.io/otel/semconv/v1.20.0/exception.go b/vendor/go.opentelemetry.io/otel/semconv/v1.20.0/exception.go index f40c97825..3fe84aae0 100644 --- a/vendor/go.opentelemetry.io/otel/semconv/v1.20.0/exception.go +++ b/vendor/go.opentelemetry.io/otel/semconv/v1.20.0/exception.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package semconv // import "go.opentelemetry.io/otel/semconv/v1.20.0" +package semconv const ( // ExceptionEventName is the name of the Span event representing an exception. diff --git a/vendor/go.opentelemetry.io/otel/semconv/v1.20.0/http.go b/vendor/go.opentelemetry.io/otel/semconv/v1.20.0/http.go index 9c1840631..5f6a66586 100644 --- a/vendor/go.opentelemetry.io/otel/semconv/v1.20.0/http.go +++ b/vendor/go.opentelemetry.io/otel/semconv/v1.20.0/http.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package semconv // import "go.opentelemetry.io/otel/semconv/v1.20.0" +package semconv // HTTP scheme attributes. var ( diff --git a/vendor/go.opentelemetry.io/otel/semconv/v1.20.0/resource.go b/vendor/go.opentelemetry.io/otel/semconv/v1.20.0/resource.go index 3d44dae27..d08b9cf6c 100644 --- a/vendor/go.opentelemetry.io/otel/semconv/v1.20.0/resource.go +++ b/vendor/go.opentelemetry.io/otel/semconv/v1.20.0/resource.go @@ -3,7 +3,7 @@ // Code generated from semantic convention specification. DO NOT EDIT. -package semconv // import "go.opentelemetry.io/otel/semconv/v1.20.0" +package semconv import "go.opentelemetry.io/otel/attribute" diff --git a/vendor/go.opentelemetry.io/otel/semconv/v1.20.0/schema.go b/vendor/go.opentelemetry.io/otel/semconv/v1.20.0/schema.go index 95d0210e3..e1655e30d 100644 --- a/vendor/go.opentelemetry.io/otel/semconv/v1.20.0/schema.go +++ b/vendor/go.opentelemetry.io/otel/semconv/v1.20.0/schema.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package semconv // import "go.opentelemetry.io/otel/semconv/v1.20.0" +package semconv // SchemaURL is the schema URL that matches the version of the semantic conventions // that this package defines. Semconv packages starting from v1.4.0 must declare diff --git a/vendor/go.opentelemetry.io/otel/semconv/v1.20.0/trace.go b/vendor/go.opentelemetry.io/otel/semconv/v1.20.0/trace.go index 90b1b0452..225e97c56 100644 --- a/vendor/go.opentelemetry.io/otel/semconv/v1.20.0/trace.go +++ b/vendor/go.opentelemetry.io/otel/semconv/v1.20.0/trace.go @@ -3,7 +3,7 @@ // Code generated from semantic convention specification. DO NOT EDIT. -package semconv // import "go.opentelemetry.io/otel/semconv/v1.20.0" +package semconv import "go.opentelemetry.io/otel/attribute" diff --git a/vendor/go.opentelemetry.io/otel/semconv/v1.24.0/attribute_group.go b/vendor/go.opentelemetry.io/otel/semconv/v1.24.0/attribute_group.go index cc050fb78..2777fa20f 100644 --- a/vendor/go.opentelemetry.io/otel/semconv/v1.24.0/attribute_group.go +++ b/vendor/go.opentelemetry.io/otel/semconv/v1.24.0/attribute_group.go @@ -3,7 +3,7 @@ // Code generated from semantic convention specification. DO NOT EDIT. -package semconv // import "go.opentelemetry.io/otel/semconv/v1.24.0" +package semconv import "go.opentelemetry.io/otel/attribute" diff --git a/vendor/go.opentelemetry.io/otel/semconv/v1.24.0/doc.go b/vendor/go.opentelemetry.io/otel/semconv/v1.24.0/doc.go index d27e8a8f8..f9f2295a0 100644 --- a/vendor/go.opentelemetry.io/otel/semconv/v1.24.0/doc.go +++ b/vendor/go.opentelemetry.io/otel/semconv/v1.24.0/doc.go @@ -6,4 +6,4 @@ // OpenTelemetry semantic conventions are agreed standardized naming // patterns for OpenTelemetry things. This package represents the v1.24.0 // version of the OpenTelemetry semantic conventions. -package semconv // import "go.opentelemetry.io/otel/semconv/v1.24.0" +package semconv diff --git a/vendor/go.opentelemetry.io/otel/semconv/v1.24.0/event.go b/vendor/go.opentelemetry.io/otel/semconv/v1.24.0/event.go index 6c019aafc..3b3d45a4a 100644 --- a/vendor/go.opentelemetry.io/otel/semconv/v1.24.0/event.go +++ b/vendor/go.opentelemetry.io/otel/semconv/v1.24.0/event.go @@ -3,7 +3,7 @@ // Code generated from semantic convention specification. DO NOT EDIT. -package semconv // import "go.opentelemetry.io/otel/semconv/v1.24.0" +package semconv import "go.opentelemetry.io/otel/attribute" diff --git a/vendor/go.opentelemetry.io/otel/semconv/v1.24.0/exception.go b/vendor/go.opentelemetry.io/otel/semconv/v1.24.0/exception.go index 7235bb51d..3fe84aae0 100644 --- a/vendor/go.opentelemetry.io/otel/semconv/v1.24.0/exception.go +++ b/vendor/go.opentelemetry.io/otel/semconv/v1.24.0/exception.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package semconv // import "go.opentelemetry.io/otel/semconv/v1.24.0" +package semconv const ( // ExceptionEventName is the name of the Span event representing an exception. diff --git a/vendor/go.opentelemetry.io/otel/semconv/v1.24.0/metric.go b/vendor/go.opentelemetry.io/otel/semconv/v1.24.0/metric.go index a6b953f62..aab205c13 100644 --- a/vendor/go.opentelemetry.io/otel/semconv/v1.24.0/metric.go +++ b/vendor/go.opentelemetry.io/otel/semconv/v1.24.0/metric.go @@ -3,7 +3,7 @@ // Code generated from semantic convention specification. DO NOT EDIT. -package semconv // import "go.opentelemetry.io/otel/semconv/v1.24.0" +package semconv const ( diff --git a/vendor/go.opentelemetry.io/otel/semconv/v1.24.0/resource.go b/vendor/go.opentelemetry.io/otel/semconv/v1.24.0/resource.go index d66bbe9c2..ac11e6e27 100644 --- a/vendor/go.opentelemetry.io/otel/semconv/v1.24.0/resource.go +++ b/vendor/go.opentelemetry.io/otel/semconv/v1.24.0/resource.go @@ -3,7 +3,7 @@ // Code generated from semantic convention specification. DO NOT EDIT. -package semconv // import "go.opentelemetry.io/otel/semconv/v1.24.0" +package semconv import "go.opentelemetry.io/otel/attribute" diff --git a/vendor/go.opentelemetry.io/otel/semconv/v1.24.0/schema.go b/vendor/go.opentelemetry.io/otel/semconv/v1.24.0/schema.go index fe80b1731..593aa1d77 100644 --- a/vendor/go.opentelemetry.io/otel/semconv/v1.24.0/schema.go +++ b/vendor/go.opentelemetry.io/otel/semconv/v1.24.0/schema.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package semconv // import "go.opentelemetry.io/otel/semconv/v1.24.0" +package semconv // SchemaURL is the schema URL that matches the version of the semantic conventions // that this package defines. Semconv packages starting from v1.4.0 must declare diff --git a/vendor/go.opentelemetry.io/otel/semconv/v1.24.0/trace.go b/vendor/go.opentelemetry.io/otel/semconv/v1.24.0/trace.go index c1718234e..f8124777d 100644 --- a/vendor/go.opentelemetry.io/otel/semconv/v1.24.0/trace.go +++ b/vendor/go.opentelemetry.io/otel/semconv/v1.24.0/trace.go @@ -3,7 +3,7 @@ // Code generated from semantic convention specification. DO NOT EDIT. -package semconv // import "go.opentelemetry.io/otel/semconv/v1.24.0" +package semconv import "go.opentelemetry.io/otel/attribute" diff --git a/vendor/go.opentelemetry.io/otel/semconv/v1.37.0/attribute_group.go b/vendor/go.opentelemetry.io/otel/semconv/v1.37.0/attribute_group.go index 2fcab2435..d20ad49ef 100644 --- a/vendor/go.opentelemetry.io/otel/semconv/v1.37.0/attribute_group.go +++ b/vendor/go.opentelemetry.io/otel/semconv/v1.37.0/attribute_group.go @@ -3,7 +3,7 @@ // Code generated from semantic convention specification. DO NOT EDIT. -package semconv // import "go.opentelemetry.io/otel/semconv/v1.37.0" +package semconv import "go.opentelemetry.io/otel/attribute" diff --git a/vendor/go.opentelemetry.io/otel/semconv/v1.37.0/doc.go b/vendor/go.opentelemetry.io/otel/semconv/v1.37.0/doc.go index 111010321..b67c64b96 100644 --- a/vendor/go.opentelemetry.io/otel/semconv/v1.37.0/doc.go +++ b/vendor/go.opentelemetry.io/otel/semconv/v1.37.0/doc.go @@ -6,4 +6,4 @@ // OpenTelemetry semantic conventions are agreed standardized naming // patterns for OpenTelemetry things. This package represents the v1.37.0 // version of the OpenTelemetry semantic conventions. -package semconv // import "go.opentelemetry.io/otel/semconv/v1.37.0" +package semconv diff --git a/vendor/go.opentelemetry.io/otel/semconv/v1.37.0/error_type.go b/vendor/go.opentelemetry.io/otel/semconv/v1.37.0/error_type.go index 267979c05..719241429 100644 --- a/vendor/go.opentelemetry.io/otel/semconv/v1.37.0/error_type.go +++ b/vendor/go.opentelemetry.io/otel/semconv/v1.37.0/error_type.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package semconv // import "go.opentelemetry.io/otel/semconv/v1.37.0" +package semconv import ( "reflect" diff --git a/vendor/go.opentelemetry.io/otel/semconv/v1.37.0/exception.go b/vendor/go.opentelemetry.io/otel/semconv/v1.37.0/exception.go index e67469a4f..3fe84aae0 100644 --- a/vendor/go.opentelemetry.io/otel/semconv/v1.37.0/exception.go +++ b/vendor/go.opentelemetry.io/otel/semconv/v1.37.0/exception.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package semconv // import "go.opentelemetry.io/otel/semconv/v1.37.0" +package semconv const ( // ExceptionEventName is the name of the Span event representing an exception. diff --git a/vendor/go.opentelemetry.io/otel/semconv/v1.37.0/schema.go b/vendor/go.opentelemetry.io/otel/semconv/v1.37.0/schema.go index f8a0b7044..0009b185b 100644 --- a/vendor/go.opentelemetry.io/otel/semconv/v1.37.0/schema.go +++ b/vendor/go.opentelemetry.io/otel/semconv/v1.37.0/schema.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package semconv // import "go.opentelemetry.io/otel/semconv/v1.37.0" +package semconv // SchemaURL is the schema URL that matches the version of the semantic conventions // that this package defines. Semconv packages starting from v1.4.0 must declare diff --git a/vendor/go.opentelemetry.io/otel/semconv/v1.41.0/MIGRATION.md b/vendor/go.opentelemetry.io/otel/semconv/v1.41.0/MIGRATION.md deleted file mode 100644 index ba52cadf7..000000000 --- a/vendor/go.opentelemetry.io/otel/semconv/v1.41.0/MIGRATION.md +++ /dev/null @@ -1,17 +0,0 @@ - -# Migration from v1.40.0 to v1.41.0 - -The `go.opentelemetry.io/otel/semconv/v1.41.0` package should be a drop-in replacement for `go.opentelemetry.io/otel/semconv/v1.40.0` with the following exceptions. - -## Removed - -The following declarations have been removed. -Refer to the [OpenTelemetry Semantic Conventions documentation] for deprecation instructions. - -If the type is not listed in the documentation as deprecated, it has been removed in this version due to lack of applicability or use. -If you use any of these non-deprecated declarations in your Go application, please [open an issue] describing your use-case. - -- `DeploymentEnvironmentName` - -[OpenTelemetry Semantic Conventions documentation]: https://github.com/open-telemetry/semantic-conventions -[open an issue]: https://github.com/open-telemetry/opentelemetry-go/issues/new?template=Blank+issue diff --git a/vendor/go.opentelemetry.io/otel/semconv/v1.43.0/MIGRATION.md b/vendor/go.opentelemetry.io/otel/semconv/v1.43.0/MIGRATION.md new file mode 100644 index 000000000..54d8e7d70 --- /dev/null +++ b/vendor/go.opentelemetry.io/otel/semconv/v1.43.0/MIGRATION.md @@ -0,0 +1,4 @@ + +# Migration from v1.42.0 to v1.43.0 + +The `go.opentelemetry.io/otel/semconv/v1.43.0` package should be a drop-in replacement for `go.opentelemetry.io/otel/semconv/v1.42.0`. diff --git a/vendor/go.opentelemetry.io/otel/semconv/v1.41.0/attribute_group.go b/vendor/go.opentelemetry.io/otel/semconv/v1.43.0/attribute_group.go similarity index 90% rename from vendor/go.opentelemetry.io/otel/semconv/v1.41.0/attribute_group.go rename to vendor/go.opentelemetry.io/otel/semconv/v1.43.0/attribute_group.go index 7cee08680..770388dfc 100644 --- a/vendor/go.opentelemetry.io/otel/semconv/v1.41.0/attribute_group.go +++ b/vendor/go.opentelemetry.io/otel/semconv/v1.43.0/attribute_group.go @@ -3,7 +3,7 @@ // Code generated from semantic convention specification. DO NOT EDIT. -package semconv // import "go.opentelemetry.io/otel/semconv/v1.41.0" +package semconv import "go.opentelemetry.io/otel/attribute" @@ -22,7 +22,7 @@ const ( // [Activity lifecycle callbacks], and from which the `OS identifiers` are // derived. // - // [Activity lifecycle callbacks]: https://developer.android.com/guide/components/activities/activity-lifecycle#lc + // [Activity lifecycle callbacks]: https://developer.android.com/guide/components/activities/activity-lifecycle#lifecycle-callbacks AndroidAppStateKey = attribute.Key("android.app.state") // AndroidOSAPILevelKey is the attribute Key conforming to the @@ -87,6 +87,24 @@ const ( // "9f2b833506aa6973a92fde9733e6271f", "my-app-1.0.0-code-123" AppBuildIDKey = attribute.Key("app.build_id") + // AppCrashIDKey is the attribute Key conforming to the "app.crash.id" semantic + // conventions. It represents a unique identifier representing an instance of an + // end-user facing app crash. + // + // Type: string + // RequirementLevel: Recommended + // Stability: Development + // + // Examples: "083d3d2d-9a0e-47f8-be3d-bc3c5538ba38" + // Note: Its value MAY be meaningful and be used as a reference for telemetry + // and metadata recorded by + // the same instrumentation (e.g. it is an ID generated by an external source + // that captured the crash). + // It MAY come from a source external to the instrumentation such that it can be + // used to look up additional + // data from other sources as well as facilitate deduplication. + AppCrashIDKey = attribute.Key("app.crash.id") + // AppInstallationIDKey is the attribute Key conforming to the // "app.installation.id" semantic conventions. It represents a unique identifier // representing the installation of an application on a specific device. @@ -252,6 +270,13 @@ func AppBuildID(val string) attribute.KeyValue { return AppBuildIDKey.String(val) } +// AppCrashID returns an attribute KeyValue conforming to the "app.crash.id" +// semantic conventions. It represents a unique identifier representing an +// instance of an end-user facing app crash. +func AppCrashID(val string) attribute.KeyValue { + return AppCrashIDKey.String(val) +} + // AppInstallationID returns an attribute KeyValue conforming to the // "app.installation.id" semantic conventions. It represents a unique identifier // representing the installation of an application on a specific device. @@ -1744,6 +1769,19 @@ const ( // Examples: 1000, 1002 AzureCosmosDBResponseSubStatusCodeKey = attribute.Key("azure.cosmosdb.response.sub_status_code") + // AzureResourceGroupNameKey is the attribute Key conforming to the + // "azure.resource_group.name" semantic conventions. It represents the name of + // the Azure [resource group] the resource belongs to. + // + // Type: string + // RequirementLevel: Recommended + // Stability: Development + // + // Examples: "my-resource-group", "rg-myapp-prod" + // + // [resource group]: https://learn.microsoft.com/azure/azure-resource-manager/management/manage-resource-groups-portal + AzureResourceGroupNameKey = attribute.Key("azure.resource_group.name") + // AzureResourceProviderNamespaceKey is the attribute Key conforming to the // "azure.resource_provider.namespace" semantic conventions. It represents the // [Azure Resource Provider Namespace] as recognized by the client. @@ -1808,6 +1846,15 @@ func AzureCosmosDBResponseSubStatusCode(val int) attribute.KeyValue { return AzureCosmosDBResponseSubStatusCodeKey.Int(val) } +// AzureResourceGroupName returns an attribute KeyValue conforming to the +// "azure.resource_group.name" semantic conventions. It represents the name of +// the Azure [resource group] the resource belongs to. +// +// [resource group]: https://learn.microsoft.com/azure/azure-resource-manager/management/manage-resource-groups-portal +func AzureResourceGroupName(val string) attribute.KeyValue { + return AzureResourceGroupNameKey.String(val) +} + // AzureResourceProviderNamespace returns an attribute KeyValue conforming to the // "azure.resource_provider.namespace" semantic conventions. It represents the // [Azure Resource Provider Namespace] as recognized by the client. @@ -1871,6 +1918,19 @@ const ( // [UA client hints API]: https://wicg.github.io/ua-client-hints/#interface BrowserBrandsKey = attribute.Key("browser.brands") + // BrowserDocumentURLFullKey is the attribute Key conforming to the + // "browser.document.url.full" semantic conventions. It represents the absolute + // URL of the current browser document according to [RFC3986]. + // + // Type: string + // RequirementLevel: Recommended + // Stability: Development + // + // Examples: "https://www.example.com/search?q=OpenTelemetry#SemConv" + // + // [RFC3986]: https://www.rfc-editor.org/rfc/rfc3986 + BrowserDocumentURLFullKey = attribute.Key("browser.document.url.full") + // BrowserLanguageKey is the attribute Key conforming to the "browser.language" // semantic conventions. It represents the preferred language of the user using // the browser. @@ -1933,6 +1993,15 @@ func BrowserBrands(val ...string) attribute.KeyValue { return BrowserBrandsKey.StringSlice(val) } +// BrowserDocumentURLFull returns an attribute KeyValue conforming to the +// "browser.document.url.full" semantic conventions. It represents the absolute +// URL of the current browser document according to [RFC3986]. +// +// [RFC3986]: https://www.rfc-editor.org/rfc/rfc3986 +func BrowserDocumentURLFull(val string) attribute.KeyValue { + return BrowserDocumentURLFullKey.String(val) +} + // BrowserLanguage returns an attribute KeyValue conforming to the // "browser.language" semantic conventions. It represents the preferred language // of the user using the browser. @@ -2107,7 +2176,7 @@ const ( // // Type: Enum // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "BUILD", "RUN", "SYNC" CICDPipelineActionNameKey = attribute.Key("cicd.pipeline.action.name") @@ -2118,7 +2187,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "Build and Test", "Lint", "Deploy Go Project", // "deploy_to_environment" @@ -2130,9 +2199,9 @@ const ( // // Type: Enum // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // - // Examples: "success", "failure", "timeout", "skipped" + // Examples: "success", "failure", "timeout", "skip" CICDPipelineResultKey = attribute.Key("cicd.pipeline.result") // CICDPipelineRunIDKey is the attribute Key conforming to the @@ -2141,7 +2210,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "120912" CICDPipelineRunIDKey = attribute.Key("cicd.pipeline.run.id") @@ -2152,7 +2221,7 @@ const ( // // Type: Enum // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "pending", "executing", "finalizing" CICDPipelineRunStateKey = attribute.Key("cicd.pipeline.run.state") @@ -2164,7 +2233,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: // "https://github.com/open-telemetry/semantic-conventions/actions/runs/9753949763?pr=1075" @@ -2180,7 +2249,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "Run GoLang Linter", "Go Build", "go-test", "deploy_binary" // @@ -2193,7 +2262,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "12097" // Note: For a given pipeline run and task, the `cicd.pipeline.task.run.id` MUST @@ -2209,9 +2278,9 @@ const ( // // Type: Enum // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // - // Examples: "success", "failure", "timeout", "skipped" + // Examples: "success", "failure", "timeout", "skip" CICDPipelineTaskRunResultKey = attribute.Key("cicd.pipeline.task.run.result") // CICDPipelineTaskRunURLFullKey is the attribute Key conforming to the @@ -2221,7 +2290,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: // "https://github.com/open-telemetry/semantic-conventions/actions/runs/9753949763/job/26920038674?pr=1075" @@ -2235,52 +2304,52 @@ const ( // // Type: Enum // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "build", "test", "deploy" CICDPipelineTaskTypeKey = attribute.Key("cicd.pipeline.task.type") // CICDSystemComponentKey is the attribute Key conforming to the // "cicd.system.component" semantic conventions. It represents the name of a - // component of the CICD system. + // component of the CI/CD system. // // Type: string // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "controller", "scheduler", "agent" CICDSystemComponentKey = attribute.Key("cicd.system.component") // CICDWorkerIDKey is the attribute Key conforming to the "cicd.worker.id" // semantic conventions. It represents the unique identifier of a worker within - // a CICD system. + // a CI/CD system. // // Type: string // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "abc123", "10.0.1.2", "controller" CICDWorkerIDKey = attribute.Key("cicd.worker.id") // CICDWorkerNameKey is the attribute Key conforming to the "cicd.worker.name" - // semantic conventions. It represents the name of a worker within a CICD + // semantic conventions. It represents the name of a worker within a CI/CD // system. // // Type: string // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "agent-abc", "controller", "Ubuntu LTS" CICDWorkerNameKey = attribute.Key("cicd.worker.name") // CICDWorkerStateKey is the attribute Key conforming to the "cicd.worker.state" - // semantic conventions. It represents the state of a CICD worker / agent. + // semantic conventions. It represents the state of a CI/CD worker / agent. // // Type: Enum // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // - // Examples: "idle", "busy", "down" + // Examples: "available", "busy", "offline" CICDWorkerStateKey = attribute.Key("cicd.worker.state") // CICDWorkerURLFullKey is the attribute Key conforming to the @@ -2290,7 +2359,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "https://cicd.example.org/worker/abc123" // @@ -2352,21 +2421,21 @@ func CICDPipelineTaskRunURLFull(val string) attribute.KeyValue { // CICDSystemComponent returns an attribute KeyValue conforming to the // "cicd.system.component" semantic conventions. It represents the name of a -// component of the CICD system. +// component of the CI/CD system. func CICDSystemComponent(val string) attribute.KeyValue { return CICDSystemComponentKey.String(val) } // CICDWorkerID returns an attribute KeyValue conforming to the "cicd.worker.id" // semantic conventions. It represents the unique identifier of a worker within a -// CICD system. +// CI/CD system. func CICDWorkerID(val string) attribute.KeyValue { return CICDWorkerIDKey.String(val) } // CICDWorkerName returns an attribute KeyValue conforming to the // "cicd.worker.name" semantic conventions. It represents the name of a worker -// within a CICD system. +// within a CI/CD system. func CICDWorkerName(val string) attribute.KeyValue { return CICDWorkerNameKey.String(val) } @@ -2384,39 +2453,39 @@ func CICDWorkerURLFull(val string) attribute.KeyValue { // Enum values for cicd.pipeline.action.name var ( // The pipeline run is executing a build. - // Stability: development + // Stability: release_candidate CICDPipelineActionNameBuild = CICDPipelineActionNameKey.String("BUILD") // The pipeline run is executing. - // Stability: development + // Stability: release_candidate CICDPipelineActionNameRun = CICDPipelineActionNameKey.String("RUN") // The pipeline run is executing a sync. - // Stability: development + // Stability: release_candidate CICDPipelineActionNameSync = CICDPipelineActionNameKey.String("SYNC") ) // Enum values for cicd.pipeline.result var ( // The pipeline run finished successfully. - // Stability: development + // Stability: release_candidate CICDPipelineResultSuccess = CICDPipelineResultKey.String("success") // The pipeline run did not finish successfully, eg. due to a compile error or a // failing test. Such failures are usually detected by non-zero exit codes of // the tools executed in the pipeline run. - // Stability: development + // Stability: release_candidate CICDPipelineResultFailure = CICDPipelineResultKey.String("failure") - // The pipeline run failed due to an error in the CICD system, eg. due to the + // The pipeline run failed due to an error in the CI/CD system, eg. due to the // worker being killed. - // Stability: development + // Stability: release_candidate CICDPipelineResultError = CICDPipelineResultKey.String("error") // A timeout caused the pipeline run to be interrupted. - // Stability: development + // Stability: release_candidate CICDPipelineResultTimeout = CICDPipelineResultKey.String("timeout") // The pipeline run was cancelled, eg. by a user manually cancelling the // pipeline run. - // Stability: development + // Stability: release_candidate CICDPipelineResultCancellation = CICDPipelineResultKey.String("cancellation") // The pipeline run was skipped, eg. due to a precondition not being met. - // Stability: development + // Stability: release_candidate CICDPipelineResultSkip = CICDPipelineResultKey.String("skip") ) @@ -2426,66 +2495,66 @@ var ( // the execution of the run starts (eg. time spent in a queue, provisioning // agents, creating run resources). // - // Stability: development + // Stability: release_candidate CICDPipelineRunStatePending = CICDPipelineRunStateKey.String("pending") // The executing state spans the execution of any run tasks (eg. build, test). - // Stability: development + // Stability: release_candidate CICDPipelineRunStateExecuting = CICDPipelineRunStateKey.String("executing") // The finalizing state spans from when the run has finished executing (eg. // cleanup of run resources). - // Stability: development + // Stability: release_candidate CICDPipelineRunStateFinalizing = CICDPipelineRunStateKey.String("finalizing") ) // Enum values for cicd.pipeline.task.run.result var ( // The task run finished successfully. - // Stability: development + // Stability: release_candidate CICDPipelineTaskRunResultSuccess = CICDPipelineTaskRunResultKey.String("success") // The task run did not finish successfully, eg. due to a compile error or a // failing test. Such failures are usually detected by non-zero exit codes of // the tools executed in the task run. - // Stability: development + // Stability: release_candidate CICDPipelineTaskRunResultFailure = CICDPipelineTaskRunResultKey.String("failure") - // The task run failed due to an error in the CICD system, eg. due to the worker - // being killed. - // Stability: development + // The task run failed due to an error in the CI/CD system, eg. due to the + // worker being killed. + // Stability: release_candidate CICDPipelineTaskRunResultError = CICDPipelineTaskRunResultKey.String("error") // A timeout caused the task run to be interrupted. - // Stability: development + // Stability: release_candidate CICDPipelineTaskRunResultTimeout = CICDPipelineTaskRunResultKey.String("timeout") // The task run was cancelled, eg. by a user manually cancelling the task run. - // Stability: development + // Stability: release_candidate CICDPipelineTaskRunResultCancellation = CICDPipelineTaskRunResultKey.String("cancellation") // The task run was skipped, eg. due to a precondition not being met. - // Stability: development + // Stability: release_candidate CICDPipelineTaskRunResultSkip = CICDPipelineTaskRunResultKey.String("skip") ) // Enum values for cicd.pipeline.task.type var ( // build - // Stability: development + // Stability: release_candidate CICDPipelineTaskTypeBuild = CICDPipelineTaskTypeKey.String("build") // test - // Stability: development + // Stability: release_candidate CICDPipelineTaskTypeTest = CICDPipelineTaskTypeKey.String("test") // deploy - // Stability: development + // Stability: release_candidate CICDPipelineTaskTypeDeploy = CICDPipelineTaskTypeKey.String("deploy") ) // Enum values for cicd.worker.state var ( - // The worker is not performing work for the CICD system. It is available to the - // CICD system to perform work on (online / idle). - // Stability: development + // The worker is not performing work for the CI/CD system. It is available to + // the CI/CD system to perform work on (online / idle). + // Stability: release_candidate CICDWorkerStateAvailable = CICDWorkerStateKey.String("available") - // The worker is performing work for the CICD system. - // Stability: development + // The worker is performing work for the CI/CD system. + // Stability: release_candidate CICDWorkerStateBusy = CICDWorkerStateKey.String("busy") - // The worker is not available to the CICD system (disconnected / down). - // Stability: development + // The worker is not available to the CI/CD system (disconnected / down). + // Stability: release_candidate CICDWorkerStateOffline = CICDWorkerStateKey.String("offline") ) @@ -2544,7 +2613,9 @@ const ( // RequirementLevel: Recommended // Stability: Development // - // Examples: "111111111111", "opentelemetry" + // Examples: "111111111111", "opentelemetry", + // "22222222-2222-2222-2222-222222222222" + // Note: For Azure, this is the subscription ID. CloudAccountIDKey = attribute.Key("cloud.account.id") // CloudAvailabilityZoneKey is the attribute Key conforming to the @@ -3436,7 +3507,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Release_Candidate + // Stability: Stable // // Examples: "a3bf90e006b2" // @@ -3472,7 +3543,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Release_Candidate + // Stability: Stable // // Examples: "gcr.io/opentelemetry/operator" ContainerImageNameKey = attribute.Key("container.image.name") @@ -3483,7 +3554,7 @@ const ( // // Type: string[] // RequirementLevel: Recommended - // Stability: Release_Candidate + // Stability: Stable // // Examples: // "example@sha256:afcc7f1ac1b49db317a7196c902e61c6c3c4607d63599ee1a82d702d249a0ccb", @@ -3502,7 +3573,7 @@ const ( // // Type: string[] // RequirementLevel: Recommended - // Stability: Release_Candidate + // Stability: Stable // // Examples: "v1.27.1", "3.5.7-0" // @@ -3691,7 +3762,7 @@ const ( // // Type: Enum // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "user", "system" CPUModeKey = attribute.Key("cpu.mode") @@ -3707,29 +3778,26 @@ func CPULogicalNumber(val int) attribute.KeyValue { // Enum values for cpu.mode var ( // User - // Stability: development + // Stability: release_candidate CPUModeUser = CPUModeKey.String("user") // System - // Stability: development + // Stability: release_candidate CPUModeSystem = CPUModeKey.String("system") // Nice - // Stability: development + // Stability: release_candidate CPUModeNice = CPUModeKey.String("nice") // Idle - // Stability: development + // Stability: release_candidate CPUModeIdle = CPUModeKey.String("idle") // IO Wait - // Stability: development + // Stability: release_candidate CPUModeIOWait = CPUModeKey.String("iowait") // Interrupt - // Stability: development + // Stability: release_candidate CPUModeInterrupt = CPUModeKey.String("interrupt") // Steal - // Stability: development + // Stability: release_candidate CPUModeSteal = CPUModeKey.String("steal") - // Kernel - // Stability: development - CPUModeKernel = CPUModeKey.String("kernel") ) // Namespace: db @@ -3803,15 +3871,46 @@ const ( // DBOperationBatchSizeKey is the attribute Key conforming to the // "db.operation.batch.size" semantic conventions. It represents the number of - // queries included in a batch operation. + // database operations included in a batch operation. // // Type: int // RequirementLevel: Recommended // Stability: Stable // // Examples: 2, 3, 4 - // Note: Operations are only considered batches when they contain two or more - // operations, and so `db.operation.batch.size` SHOULD never be `1`. + // Note: Except for empty batch requests described below, a batch operation + // contains two + // or more database operations explicitly submitted as separate operations in a + // single + // client call, protocol message, or database command. + // + // Requests to batch APIs that contain only one operation SHOULD be modeled as + // single + // operations, not as batch operations. + // + // A database call is not a batch operation solely because one operation accepts + // multiple operands, such as keys, rows, documents, points, or other data + // elements, + // including Redis [`MGET`] with + // multiple keys. + // + // In batch APIs that execute the same parameterized operation with parameter + // sets, + // each parameter set represents one database operation for determining whether + // the + // request is a batch operation. Requests with only one parameter set SHOULD be + // modeled + // as single operations, not as batch operations. + // + // `db.operation.batch.size` SHOULD be set to the number of operations in the + // batch. + // It SHOULD NOT be set for non-batch operations. + // + // A request to execute a batch operation with no operations SHOULD also be + // treated + // as a batch operation, and `db.operation.batch.size` SHOULD be set to `0`. + // + // [`MGET`]: https://redis.io/docs/latest/commands/mget/ DBOperationBatchSizeKey = attribute.Key("db.operation.batch.size") // DBOperationNameKey is the attribute Key conforming to the "db.operation.name" @@ -3980,7 +4079,7 @@ func DBNamespace(val string) attribute.KeyValue { // DBOperationBatchSize returns an attribute KeyValue conforming to the // "db.operation.batch.size" semantic conventions. It represents the number of -// queries included in a batch operation. +// database operations included in a batch operation. func DBOperationBatchSize(val int) attribute.KeyValue { return DBOperationBatchSizeKey.Int(val) } @@ -4511,7 +4610,7 @@ const ( // // Type: Enum // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "read" DiskIODirectionKey = attribute.Key("disk.io.direction") @@ -4520,10 +4619,10 @@ const ( // Enum values for disk.io.direction var ( // read - // Stability: development + // Stability: release_candidate DiskIODirectionRead = DiskIODirectionKey.String("read") // write - // Stability: development + // Stability: release_candidate DiskIODirectionWrite = DiskIODirectionKey.String("write") ) @@ -5496,6 +5595,45 @@ const ( // Examples: "256383" FileInodeKey = attribute.Key("file.inode") + // FileLockMechanismKey is the attribute Key conforming to the + // "file.lock.mechanism" semantic conventions. It represents the lock mechanism + // such as noted by [POSIX]. + // + // Type: string + // RequirementLevel: Recommended + // Stability: Development + // + // Examples: "POSIX", "FLOCK", "DELEG", "LEASE" + // + // [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html + FileLockMechanismKey = attribute.Key("file.lock.mechanism") + + // FileLockModeKey is the attribute Key conforming to the "file.lock.mode" + // semantic conventions. It represents the mode of lock or operation such as + // documented by [POSIX]. + // + // Type: string + // RequirementLevel: Recommended + // Stability: Development + // + // Examples: "ADVISORY", "MANDATORY", "BREAKING", "ACTIVE", "BREAKER" + // + // [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html + FileLockModeKey = attribute.Key("file.lock.mode") + + // FileLockTypeKey is the attribute Key conforming to the "file.lock.type" + // semantic conventions. It represents the lock type as represented by i.e. + // [POSIX]'s l_type. + // + // Type: Enum + // RequirementLevel: Recommended + // Stability: Development + // + // Examples: "read" + // + // [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html + FileLockTypeKey = attribute.Key("file.lock.type") + // FileModeKey is the attribute Key conforming to the "file.mode" semantic // conventions. It represents the mode of the file in octal representation. // @@ -5652,6 +5790,24 @@ func FileInode(val string) attribute.KeyValue { return FileInodeKey.String(val) } +// FileLockMechanism returns an attribute KeyValue conforming to the +// "file.lock.mechanism" semantic conventions. It represents the lock mechanism +// such as noted by [POSIX]. +// +// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html +func FileLockMechanism(val string) attribute.KeyValue { + return FileLockMechanismKey.String(val) +} + +// FileLockMode returns an attribute KeyValue conforming to the "file.lock.mode" +// semantic conventions. It represents the mode of lock or operation such as +// documented by [POSIX]. +// +// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html +func FileLockMode(val string) attribute.KeyValue { + return FileLockModeKey.String(val) +} + // FileMode returns an attribute KeyValue conforming to the "file.mode" semantic // conventions. It represents the mode of the file in octal representation. func FileMode(val string) attribute.KeyValue { @@ -5706,6 +5862,16 @@ func FileSymbolicLinkTargetPath(val string) attribute.KeyValue { return FileSymbolicLinkTargetPathKey.String(val) } +// Enum values for file.lock.type +var ( + // read + // Stability: development + FileLockTypeRead = FileLockTypeKey.String("read") + // write + // Stability: development + FileLockTypeWrite = FileLockTypeKey.String("write") +) + // Namespace: gcp const ( // GCPAppHubApplicationContainerKey is the attribute Key conforming to the @@ -6152,6 +6318,13 @@ func GCPGCEInstanceHostname(val string) attribute.KeyValue { return GCPGCEInstanceHostnameKey.String(val) } +// GCPGCEInstanceLabels returns an attribute KeyValue conforming to the +// "gcp.gce.instance.labels" semantic conventions. It represents the GCE instance +// labels, `` being the label name and the value being the label value. +func GCPGCEInstanceLabels(key string, val string) attribute.KeyValue { + return attribute.String("gcp.gce.instance.labels."+key, val) +} + // GCPGCEInstanceName returns an attribute KeyValue conforming to the // "gcp.gce.instance.name" semantic conventions. It represents the instance name // of a GCE instance. This is the value provided by `host.name`, the visible name @@ -6314,1270 +6487,94 @@ var ( GCPAppHubDestinationWorkloadEnvironmentTypeDevelopment = GCPAppHubDestinationWorkloadEnvironmentTypeKey.String("DEVELOPMENT") ) -// Namespace: gen_ai +// Namespace: geo const ( - // GenAIAgentDescriptionKey is the attribute Key conforming to the - // "gen_ai.agent.description" semantic conventions. It represents the free-form - // description of the GenAI agent provided by the application. + // GeoContinentCodeKey is the attribute Key conforming to the + // "geo.continent.code" semantic conventions. It represents the two-letter code + // representing continent’s name. // - // Type: string + // Type: Enum // RequirementLevel: Recommended // Stability: Development // - // Examples: "Helps with math problems", "Generates fiction stories" - GenAIAgentDescriptionKey = attribute.Key("gen_ai.agent.description") + // Examples: + GeoContinentCodeKey = attribute.Key("geo.continent.code") - // GenAIAgentIDKey is the attribute Key conforming to the "gen_ai.agent.id" - // semantic conventions. It represents the unique identifier of the GenAI agent. + // GeoCountryISOCodeKey is the attribute Key conforming to the + // "geo.country.iso_code" semantic conventions. It represents the two-letter ISO + // Country Code ([ISO 3166-1 alpha2]). // // Type: string // RequirementLevel: Recommended // Stability: Development // - // Examples: "asst_5j66UpCpwteGg4YSxUnt7lPY" - GenAIAgentIDKey = attribute.Key("gen_ai.agent.id") - - // GenAIAgentNameKey is the attribute Key conforming to the "gen_ai.agent.name" - // semantic conventions. It represents the human-readable name of the GenAI - // agent provided by the application. - // - // Type: string - // RequirementLevel: Recommended - // Stability: Development + // Examples: "CA" // - // Examples: "Math Tutor", "Fiction Writer" - GenAIAgentNameKey = attribute.Key("gen_ai.agent.name") + // [ISO 3166-1 alpha2]: https://wikipedia.org/wiki/ISO_3166-1#Codes + GeoCountryISOCodeKey = attribute.Key("geo.country.iso_code") - // GenAIAgentVersionKey is the attribute Key conforming to the - // "gen_ai.agent.version" semantic conventions. It represents the version of the - // GenAI agent. + // GeoLocalityNameKey is the attribute Key conforming to the "geo.locality.name" + // semantic conventions. It represents the locality name. Represents the name of + // a city, town, village, or similar populated place. // // Type: string // RequirementLevel: Recommended // Stability: Development // - // Examples: "1.0.0", "2025-05-01" - GenAIAgentVersionKey = attribute.Key("gen_ai.agent.version") + // Examples: "Montreal", "Berlin" + GeoLocalityNameKey = attribute.Key("geo.locality.name") - // GenAIConversationIDKey is the attribute Key conforming to the - // "gen_ai.conversation.id" semantic conventions. It represents the unique - // identifier for a conversation (session, thread), used to store and correlate - // messages within this conversation. + // GeoLocationLatKey is the attribute Key conforming to the "geo.location.lat" + // semantic conventions. It represents the latitude of the geo location in + // [WGS84]. // - // Type: string + // Type: double // RequirementLevel: Recommended // Stability: Development // - // Examples: "conv_5j66UpCpwteGg4YSxUnt7lPY" - GenAIConversationIDKey = attribute.Key("gen_ai.conversation.id") - - // GenAIDataSourceIDKey is the attribute Key conforming to the - // "gen_ai.data_source.id" semantic conventions. It represents the data source - // identifier. - // - // Type: string - // RequirementLevel: Recommended - // Stability: Development + // Examples: 45.505918 // - // Examples: "H7STPQYOND" - // Note: Data sources are used by AI agents and RAG applications to store - // grounding data. A data source may be an external database, object store, - // document collection, website, or any other storage system used by the GenAI - // agent or application. The `gen_ai.data_source.id` SHOULD match the identifier - // used by the GenAI system rather than a name specific to the external storage, - // such as a database or object store. Semantic conventions referencing - // `gen_ai.data_source.id` MAY also leverage additional attributes, such as - // `db.*`, to further identify and describe the data source. - GenAIDataSourceIDKey = attribute.Key("gen_ai.data_source.id") + // [WGS84]: https://wikipedia.org/wiki/World_Geodetic_System#WGS84 + GeoLocationLatKey = attribute.Key("geo.location.lat") - // GenAIEmbeddingsDimensionCountKey is the attribute Key conforming to the - // "gen_ai.embeddings.dimension.count" semantic conventions. It represents the - // number of dimensions the resulting output embeddings should have. + // GeoLocationLonKey is the attribute Key conforming to the "geo.location.lon" + // semantic conventions. It represents the longitude of the geo location in + // [WGS84]. // - // Type: int + // Type: double // RequirementLevel: Recommended // Stability: Development // - // Examples: 512, 1024 - GenAIEmbeddingsDimensionCountKey = attribute.Key("gen_ai.embeddings.dimension.count") - - // GenAIEvaluationExplanationKey is the attribute Key conforming to the - // "gen_ai.evaluation.explanation" semantic conventions. It represents a - // free-form explanation for the assigned score provided by the evaluator. - // - // Type: string - // RequirementLevel: Recommended - // Stability: Development + // Examples: -73.61483 // - // Examples: "The response is factually accurate but lacks sufficient detail to - // fully address the question." - GenAIEvaluationExplanationKey = attribute.Key("gen_ai.evaluation.explanation") + // [WGS84]: https://wikipedia.org/wiki/World_Geodetic_System#WGS84 + GeoLocationLonKey = attribute.Key("geo.location.lon") - // GenAIEvaluationNameKey is the attribute Key conforming to the - // "gen_ai.evaluation.name" semantic conventions. It represents the name of the - // evaluation metric used for the GenAI response. + // GeoPostalCodeKey is the attribute Key conforming to the "geo.postal_code" + // semantic conventions. It represents the postal code associated with the + // location. Values appropriate for this field may also be known as a postcode + // or ZIP code and will vary widely from country to country. // // Type: string // RequirementLevel: Recommended // Stability: Development // - // Examples: "Relevance", "IntentResolution" - GenAIEvaluationNameKey = attribute.Key("gen_ai.evaluation.name") + // Examples: "94040" + GeoPostalCodeKey = attribute.Key("geo.postal_code") - // GenAIEvaluationScoreLabelKey is the attribute Key conforming to the - // "gen_ai.evaluation.score.label" semantic conventions. It represents the human - // readable label for evaluation. + // GeoRegionISOCodeKey is the attribute Key conforming to the + // "geo.region.iso_code" semantic conventions. It represents the region ISO code + // ([ISO 3166-2]). // // Type: string // RequirementLevel: Recommended // Stability: Development // - // Examples: "relevant", "not_relevant", "correct", "incorrect", "pass", "fail" - // Note: This attribute provides a human-readable interpretation of the - // evaluation score produced by an evaluator. For example, a score value of 1 - // could mean "relevant" in one evaluation system and "not relevant" in another, - // depending on the scoring range and evaluator. The label SHOULD have low - // cardinality. Possible values depend on the evaluation metric and evaluator - // used; implementations SHOULD document the possible values. - GenAIEvaluationScoreLabelKey = attribute.Key("gen_ai.evaluation.score.label") - - // GenAIEvaluationScoreValueKey is the attribute Key conforming to the - // "gen_ai.evaluation.score.value" semantic conventions. It represents the - // evaluation score returned by the evaluator. - // - // Type: double - // RequirementLevel: Recommended - // Stability: Development + // Examples: "CA-QC" // - // Examples: 4.0 - GenAIEvaluationScoreValueKey = attribute.Key("gen_ai.evaluation.score.value") - - // GenAIInputMessagesKey is the attribute Key conforming to the - // "gen_ai.input.messages" semantic conventions. It represents the chat history - // provided to the model as an input. - // - // Type: any - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: "[\n {\n "role": "user",\n "parts": [\n {\n "type": "text",\n - // "content": "Weather in Paris?"\n }\n ]\n },\n {\n "role": "assistant",\n - // "parts": [\n {\n "type": "tool_call",\n "id": - // "call_VSPygqKTWdrhaFErNvMV18Yl",\n "name": "get_weather",\n "arguments": {\n - // "location": "Paris"\n }\n }\n ]\n },\n {\n "role": "tool",\n "parts": [\n {\n - // "type": "tool_call_response",\n "id": " call_VSPygqKTWdrhaFErNvMV18Yl",\n - // "result": "rainy, 57°F"\n }\n ]\n }\n]\n" - // Note: Instrumentations MUST follow [Input messages JSON schema]. - // When the attribute is recorded on events, it MUST be recorded in structured - // form. When recorded on spans, it MAY be recorded as a JSON string if - // structured - // format is not supported and SHOULD be recorded in structured form otherwise. - // - // Messages MUST be provided in the order they were sent to the model. - // Instrumentations MAY provide a way for users to filter or truncate - // input messages. - // - // > [!Warning] - // > This attribute is likely to contain sensitive information including - // > user/PII data. - // - // See [Recording content on attributes] - // section for more details. - // - // [Input messages JSON schema]: /docs/gen-ai/gen-ai-input-messages.json - // [Recording content on attributes]: /docs/gen-ai/gen-ai-spans.md#recording-content-on-attributes - GenAIInputMessagesKey = attribute.Key("gen_ai.input.messages") - - // GenAIOperationNameKey is the attribute Key conforming to the - // "gen_ai.operation.name" semantic conventions. It represents the name of the - // operation being performed. - // - // Type: Enum - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: - // Note: If one of the predefined values applies, but specific system uses a - // different name it's RECOMMENDED to document it in the semantic conventions - // for specific GenAI system and use system-specific name in the - // instrumentation. If a different name is not documented, instrumentation - // libraries SHOULD use applicable predefined value. - GenAIOperationNameKey = attribute.Key("gen_ai.operation.name") - - // GenAIOutputMessagesKey is the attribute Key conforming to the - // "gen_ai.output.messages" semantic conventions. It represents the messages - // returned by the model where each message represents a specific model response - // (choice, candidate). - // - // Type: any - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: "[\n {\n "role": "assistant",\n "parts": [\n {\n "type": "text",\n - // "content": "The weather in Paris is currently rainy with a temperature of - // 57°F."\n }\n ],\n "finish_reason": "stop"\n }\n]\n" - // Note: Instrumentations MUST follow [Output messages JSON schema] - // - // Each message represents a single output choice/candidate generated by - // the model. Each message corresponds to exactly one generation - // (choice/candidate) and vice versa - one choice cannot be split across - // multiple messages or one message cannot contain parts from multiple choices. - // - // When the attribute is recorded on events, it MUST be recorded in structured - // form. When recorded on spans, it MAY be recorded as a JSON string if - // structured - // format is not supported and SHOULD be recorded in structured form otherwise. - // - // Instrumentations MAY provide a way for users to filter or truncate - // output messages. - // - // > [!Warning] - // > This attribute is likely to contain sensitive information including - // > user/PII data. - // - // See [Recording content on attributes] - // section for more details. - // - // [Output messages JSON schema]: /docs/gen-ai/gen-ai-output-messages.json - // [Recording content on attributes]: /docs/gen-ai/gen-ai-spans.md#recording-content-on-attributes - GenAIOutputMessagesKey = attribute.Key("gen_ai.output.messages") - - // GenAIOutputTypeKey is the attribute Key conforming to the - // "gen_ai.output.type" semantic conventions. It represents the represents the - // content type requested by the client. - // - // Type: Enum - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: - // Note: This attribute SHOULD be used when the client requests output of a - // specific type. The model may return zero or more outputs of this type. - // This attribute specifies the output modality and not the actual output - // format. For example, if an image is requested, the actual output could be a - // URL pointing to an image file. - // Additional output format details may be recorded in the future in the - // `gen_ai.output.{type}.*` attributes. - GenAIOutputTypeKey = attribute.Key("gen_ai.output.type") - - // GenAIPromptNameKey is the attribute Key conforming to the - // "gen_ai.prompt.name" semantic conventions. It represents the name of the - // prompt that uniquely identifies it. - // - // Type: string - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: "analyze-code" - GenAIPromptNameKey = attribute.Key("gen_ai.prompt.name") - - // GenAIProviderNameKey is the attribute Key conforming to the - // "gen_ai.provider.name" semantic conventions. It represents the Generative AI - // provider as identified by the client or server instrumentation. - // - // Type: Enum - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: - // Note: The attribute SHOULD be set based on the instrumentation's best - // knowledge and may differ from the actual model provider. - // - // Multiple providers, including Azure OpenAI, Gemini, and AI hosting platforms - // are accessible using the OpenAI REST API and corresponding client libraries, - // but may proxy or host models from different providers. - // - // The `gen_ai.request.model`, `gen_ai.response.model`, and `server.address` - // attributes may help identify the actual system in use. - // - // The `gen_ai.provider.name` attribute acts as a discriminator that - // identifies the GenAI telemetry format flavor specific to that provider - // within GenAI semantic conventions. - // It SHOULD be set consistently with provider-specific attributes and signals. - // For example, GenAI spans, metrics, and events related to AWS Bedrock - // should have the `gen_ai.provider.name` set to `aws.bedrock` and include - // applicable `aws.bedrock.*` attributes and are not expected to include - // `openai.*` attributes. - GenAIProviderNameKey = attribute.Key("gen_ai.provider.name") - - // GenAIRequestChoiceCountKey is the attribute Key conforming to the - // "gen_ai.request.choice.count" semantic conventions. It represents the target - // number of candidate completions to return. - // - // Type: int - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: 3 - GenAIRequestChoiceCountKey = attribute.Key("gen_ai.request.choice.count") - - // GenAIRequestEncodingFormatsKey is the attribute Key conforming to the - // "gen_ai.request.encoding_formats" semantic conventions. It represents the - // encoding formats requested in an embeddings operation, if specified. - // - // Type: string[] - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: "base64"], ["float", "binary" - // Note: In some GenAI systems the encoding formats are called embedding types. - // Also, some GenAI systems only accept a single format per request. - GenAIRequestEncodingFormatsKey = attribute.Key("gen_ai.request.encoding_formats") - - // GenAIRequestFrequencyPenaltyKey is the attribute Key conforming to the - // "gen_ai.request.frequency_penalty" semantic conventions. It represents the - // frequency penalty setting for the GenAI request. - // - // Type: double - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: 0.1 - GenAIRequestFrequencyPenaltyKey = attribute.Key("gen_ai.request.frequency_penalty") - - // GenAIRequestMaxTokensKey is the attribute Key conforming to the - // "gen_ai.request.max_tokens" semantic conventions. It represents the maximum - // number of tokens the model generates for a request. - // - // Type: int - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: 100 - GenAIRequestMaxTokensKey = attribute.Key("gen_ai.request.max_tokens") - - // GenAIRequestModelKey is the attribute Key conforming to the - // "gen_ai.request.model" semantic conventions. It represents the name of the - // GenAI model a request is being made to. - // - // Type: string - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: gpt-4 - GenAIRequestModelKey = attribute.Key("gen_ai.request.model") - - // GenAIRequestPresencePenaltyKey is the attribute Key conforming to the - // "gen_ai.request.presence_penalty" semantic conventions. It represents the - // presence penalty setting for the GenAI request. - // - // Type: double - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: 0.1 - GenAIRequestPresencePenaltyKey = attribute.Key("gen_ai.request.presence_penalty") - - // GenAIRequestSeedKey is the attribute Key conforming to the - // "gen_ai.request.seed" semantic conventions. It represents the requests with - // same seed value more likely to return same result. - // - // Type: int - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: 100 - GenAIRequestSeedKey = attribute.Key("gen_ai.request.seed") - - // GenAIRequestStopSequencesKey is the attribute Key conforming to the - // "gen_ai.request.stop_sequences" semantic conventions. It represents the list - // of sequences that the model will use to stop generating further tokens. - // - // Type: string[] - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: "forest", "lived" - GenAIRequestStopSequencesKey = attribute.Key("gen_ai.request.stop_sequences") - - // GenAIRequestStreamKey is the attribute Key conforming to the - // "gen_ai.request.stream" semantic conventions. It represents the indicates - // whether the GenAI request was made in streaming mode. - // - // Type: boolean - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: - GenAIRequestStreamKey = attribute.Key("gen_ai.request.stream") - - // GenAIRequestTemperatureKey is the attribute Key conforming to the - // "gen_ai.request.temperature" semantic conventions. It represents the - // temperature setting for the GenAI request. - // - // Type: double - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: 0.0 - GenAIRequestTemperatureKey = attribute.Key("gen_ai.request.temperature") - - // GenAIRequestTopKKey is the attribute Key conforming to the - // "gen_ai.request.top_k" semantic conventions. It represents the top_k sampling - // setting for the GenAI request. - // - // Type: double - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: 1.0 - GenAIRequestTopKKey = attribute.Key("gen_ai.request.top_k") - - // GenAIRequestTopPKey is the attribute Key conforming to the - // "gen_ai.request.top_p" semantic conventions. It represents the top_p sampling - // setting for the GenAI request. - // - // Type: double - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: 1.0 - GenAIRequestTopPKey = attribute.Key("gen_ai.request.top_p") - - // GenAIResponseFinishReasonsKey is the attribute Key conforming to the - // "gen_ai.response.finish_reasons" semantic conventions. It represents the - // array of reasons the model stopped generating tokens, corresponding to each - // generation received. - // - // Type: string[] - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: "stop"], ["stop", "length" - GenAIResponseFinishReasonsKey = attribute.Key("gen_ai.response.finish_reasons") - - // GenAIResponseIDKey is the attribute Key conforming to the - // "gen_ai.response.id" semantic conventions. It represents the unique - // identifier for the completion. - // - // Type: string - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: "chatcmpl-123" - GenAIResponseIDKey = attribute.Key("gen_ai.response.id") - - // GenAIResponseModelKey is the attribute Key conforming to the - // "gen_ai.response.model" semantic conventions. It represents the name of the - // model that generated the response. - // - // Type: string - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: "gpt-4-0613" - GenAIResponseModelKey = attribute.Key("gen_ai.response.model") - - // GenAIResponseTimeToFirstChunkKey is the attribute Key conforming to the - // "gen_ai.response.time_to_first_chunk" semantic conventions. It represents the - // time to first chunk in a streaming response, measured from request issuance, - // in seconds. The value is measured from when the client issues the generation - // request to when the first chunk is received in the response stream. - // - // Type: double - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: 0.5, 1.2 - GenAIResponseTimeToFirstChunkKey = attribute.Key("gen_ai.response.time_to_first_chunk") - - // GenAIRetrievalDocumentsKey is the attribute Key conforming to the - // "gen_ai.retrieval.documents" semantic conventions. It represents the - // documents retrieved. - // - // Type: any - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: "[\n {\n "id": "doc_123",\n "score": 0.95\n },\n {\n "id": - // "doc_456",\n "score": 0.87\n },\n {\n "id": "doc_789",\n "score": 0.82\n - // }\n]\n" - // Note: Instrumentations MUST follow [Retrieval documents JSON schema]. - // When the attribute is recorded on events, it MUST be recorded in structured - // form. When recorded on spans, it MAY be recorded as a JSON string if - // structured - // format is not supported and SHOULD be recorded in structured form otherwise. - // - // Each document object SHOULD contain at least the following properties: - // `id` (string): A unique identifier for the document, `score` (double): The - // relevance score of the document - // - // [Retrieval documents JSON schema]: /docs/gen-ai/gen-ai-retrieval-documents.json - GenAIRetrievalDocumentsKey = attribute.Key("gen_ai.retrieval.documents") - - // GenAIRetrievalQueryTextKey is the attribute Key conforming to the - // "gen_ai.retrieval.query.text" semantic conventions. It represents the query - // text used for retrieval. - // - // Type: string - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: "What is the capital of France?", "weather in Paris" - // Note: > [!Warning] - // - // > This attribute may contain sensitive information. - GenAIRetrievalQueryTextKey = attribute.Key("gen_ai.retrieval.query.text") - - // GenAISystemInstructionsKey is the attribute Key conforming to the - // "gen_ai.system_instructions" semantic conventions. It represents the system - // message or instructions provided to the GenAI model separately from the chat - // history. - // - // Type: any - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: "[\n {\n "type": "text",\n "content": "You are an Agent that greet - // users, always use greetings tool to respond"\n }\n]\n", "[\n {\n "type": - // "text",\n "content": "You are a language translator."\n },\n {\n "type": - // "text",\n "content": "Your mission is to translate text in English to - // French."\n }\n]\n" - // Note: This attribute SHOULD be used when the corresponding provider or API - // allows to provide system instructions or messages separately from the - // chat history. - // - // Instructions that are part of the chat history SHOULD be recorded in - // `gen_ai.input.messages` attribute instead. - // - // Instrumentations MUST follow [System instructions JSON schema]. - // - // When recorded on spans, it MAY be recorded as a JSON string if structured - // format is not supported and SHOULD be recorded in structured form otherwise. - // - // Instrumentations MAY provide a way for users to filter or truncate - // system instructions. - // - // > [!Warning] - // > This attribute may contain sensitive information. - // - // See [Recording content on attributes] - // section for more details. - // - // [System instructions JSON schema]: /docs/gen-ai/gen-ai-system-instructions.json - // [Recording content on attributes]: /docs/gen-ai/gen-ai-spans.md#recording-content-on-attributes - GenAISystemInstructionsKey = attribute.Key("gen_ai.system_instructions") - - // GenAITokenTypeKey is the attribute Key conforming to the "gen_ai.token.type" - // semantic conventions. It represents the type of token being counted. - // - // Type: Enum - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: "input", "output" - GenAITokenTypeKey = attribute.Key("gen_ai.token.type") - - // GenAIToolCallArgumentsKey is the attribute Key conforming to the - // "gen_ai.tool.call.arguments" semantic conventions. It represents the - // parameters passed to the tool call. - // - // Type: any - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: "{\n "location": "San Francisco?",\n "date": "2025-10-01"\n}\n" - // Note: > [!WARNING] - // - // > This attribute may contain sensitive information. - // - // It's expected to be an object - in case a serialized string is available - // to the instrumentation, the instrumentation SHOULD do the best effort to - // deserialize it to an object. When recorded on spans, it MAY be recorded as a - // JSON string if structured format is not supported and SHOULD be recorded in - // structured form otherwise. - GenAIToolCallArgumentsKey = attribute.Key("gen_ai.tool.call.arguments") - - // GenAIToolCallIDKey is the attribute Key conforming to the - // "gen_ai.tool.call.id" semantic conventions. It represents the tool call - // identifier. - // - // Type: string - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: "call_mszuSIzqtI65i1wAUOE8w5H4" - GenAIToolCallIDKey = attribute.Key("gen_ai.tool.call.id") - - // GenAIToolCallResultKey is the attribute Key conforming to the - // "gen_ai.tool.call.result" semantic conventions. It represents the result - // returned by the tool call (if any and if execution was successful). - // - // Type: any - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: "{\n "temperature_range": {\n "high": 75,\n "low": 60\n },\n - // "conditions": "sunny"\n}\n" - // Note: > [!WARNING] - // - // > This attribute may contain sensitive information. - // - // It's expected to be an object - in case a serialized string is available - // to the instrumentation, the instrumentation SHOULD do the best effort to - // deserialize it to an object. When recorded on spans, it MAY be recorded as a - // JSON string if structured format is not supported and SHOULD be recorded in - // structured form otherwise. - GenAIToolCallResultKey = attribute.Key("gen_ai.tool.call.result") - - // GenAIToolDefinitionsKey is the attribute Key conforming to the - // "gen_ai.tool.definitions" semantic conventions. It represents the list of - // tool definitions available to the GenAI agent or model. - // - // Type: any - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: "[\n {\n "type": "function",\n "name": "get_current_weather",\n - // "description": "Get the current weather in a given location",\n "parameters": - // {\n "type": "object",\n "properties": {\n "location": {\n "type": "string",\n - // "description": "The city and state, e.g. San Francisco, CA"\n },\n "unit": - // {\n "type": "string",\n "enum": [\n "celsius",\n "fahrenheit"\n ]\n }\n },\n - // "required": [\n "location",\n "unit"\n ]\n }\n }\n]\n" - // Note: Instrumentations MUST follow [Tool Definitions JSON Schema]. - // - // When the attribute is recorded on events, it MUST be recorded in structured - // form. When recorded on spans, it MAY be recorded as a JSON string if - // structured - // format is not supported and SHOULD be recorded in structured form otherwise. - // - // Since this attribute could be large, it's NOT RECOMMENDED to populate - // non-required properties by default. Instrumentations MAY provide a way - // to enable populating optional properties. - // - // [Tool Definitions JSON Schema]: /docs/gen-ai/gen-ai-tool-definitions.json - GenAIToolDefinitionsKey = attribute.Key("gen_ai.tool.definitions") - - // GenAIToolDescriptionKey is the attribute Key conforming to the - // "gen_ai.tool.description" semantic conventions. It represents the tool - // description. - // - // Type: string - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: "Multiply two numbers" - GenAIToolDescriptionKey = attribute.Key("gen_ai.tool.description") - - // GenAIToolNameKey is the attribute Key conforming to the "gen_ai.tool.name" - // semantic conventions. It represents the name of the tool utilized by the - // agent. - // - // Type: string - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: "Flights" - GenAIToolNameKey = attribute.Key("gen_ai.tool.name") - - // GenAIToolTypeKey is the attribute Key conforming to the "gen_ai.tool.type" - // semantic conventions. It represents the type of the tool utilized by the - // agent. - // - // Type: string - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: "function", "extension", "datastore" - // Note: Extension: A tool executed on the agent-side to directly call external - // APIs, bridging the gap between the agent and real-world systems. - // Agent-side operations involve actions that are performed by the agent on the - // server or within the agent's controlled environment. - // Function: A tool executed on the client-side, where the agent generates - // parameters for a predefined function, and the client executes the logic. - // Client-side operations are actions taken on the user's end or within the - // client application. - // Datastore: A tool used by the agent to access and query structured or - // unstructured external data for retrieval-augmented tasks or knowledge - // updates. - GenAIToolTypeKey = attribute.Key("gen_ai.tool.type") - - // GenAIUsageCacheCreationInputTokensKey is the attribute Key conforming to the - // "gen_ai.usage.cache_creation.input_tokens" semantic conventions. It - // represents the number of input tokens written to a provider-managed cache. - // - // Type: int - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: 25 - // Note: The value SHOULD be included in `gen_ai.usage.input_tokens`. - GenAIUsageCacheCreationInputTokensKey = attribute.Key("gen_ai.usage.cache_creation.input_tokens") - - // GenAIUsageCacheReadInputTokensKey is the attribute Key conforming to the - // "gen_ai.usage.cache_read.input_tokens" semantic conventions. It represents - // the number of input tokens served from a provider-managed cache. - // - // Type: int - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: 50 - // Note: The value SHOULD be included in `gen_ai.usage.input_tokens`. - GenAIUsageCacheReadInputTokensKey = attribute.Key("gen_ai.usage.cache_read.input_tokens") - - // GenAIUsageInputTokensKey is the attribute Key conforming to the - // "gen_ai.usage.input_tokens" semantic conventions. It represents the number of - // tokens used in the GenAI input (prompt). - // - // Type: int - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: 100 - // Note: This value SHOULD include all types of input tokens, including cached - // tokens. - // Instrumentations SHOULD make a best effort to populate this value, using a - // total - // provided by the provider when available or, depending on the provider API, - // by summing different token types parsed from the provider output. - GenAIUsageInputTokensKey = attribute.Key("gen_ai.usage.input_tokens") - - // GenAIUsageOutputTokensKey is the attribute Key conforming to the - // "gen_ai.usage.output_tokens" semantic conventions. It represents the number - // of tokens used in the GenAI response (completion). - // - // Type: int - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: 180 - GenAIUsageOutputTokensKey = attribute.Key("gen_ai.usage.output_tokens") - - // GenAIUsageReasoningOutputTokensKey is the attribute Key conforming to the - // "gen_ai.usage.reasoning.output_tokens" semantic conventions. It represents - // the number of output tokens used for reasoning (e.g. chain-of-thought, - // extended thinking). - // - // Type: int - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: 50 - // Note: The value SHOULD be included in `gen_ai.usage.output_tokens`. - GenAIUsageReasoningOutputTokensKey = attribute.Key("gen_ai.usage.reasoning.output_tokens") - - // GenAIWorkflowNameKey is the attribute Key conforming to the - // "gen_ai.workflow.name" semantic conventions. It represents the human-readable - // name of the GenAI workflow provided by the application. - // - // Type: string - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: "multi_agent_rag", "customer_support_pipeline" - // Note: This attribute can be populated in different frameworks eg: name of the - // first chain in LangChain OR name of the crew in CrewAI. - GenAIWorkflowNameKey = attribute.Key("gen_ai.workflow.name") -) - -// GenAIAgentDescription returns an attribute KeyValue conforming to the -// "gen_ai.agent.description" semantic conventions. It represents the free-form -// description of the GenAI agent provided by the application. -func GenAIAgentDescription(val string) attribute.KeyValue { - return GenAIAgentDescriptionKey.String(val) -} - -// GenAIAgentID returns an attribute KeyValue conforming to the "gen_ai.agent.id" -// semantic conventions. It represents the unique identifier of the GenAI agent. -func GenAIAgentID(val string) attribute.KeyValue { - return GenAIAgentIDKey.String(val) -} - -// GenAIAgentName returns an attribute KeyValue conforming to the -// "gen_ai.agent.name" semantic conventions. It represents the human-readable -// name of the GenAI agent provided by the application. -func GenAIAgentName(val string) attribute.KeyValue { - return GenAIAgentNameKey.String(val) -} - -// GenAIAgentVersion returns an attribute KeyValue conforming to the -// "gen_ai.agent.version" semantic conventions. It represents the version of the -// GenAI agent. -func GenAIAgentVersion(val string) attribute.KeyValue { - return GenAIAgentVersionKey.String(val) -} - -// GenAIConversationID returns an attribute KeyValue conforming to the -// "gen_ai.conversation.id" semantic conventions. It represents the unique -// identifier for a conversation (session, thread), used to store and correlate -// messages within this conversation. -func GenAIConversationID(val string) attribute.KeyValue { - return GenAIConversationIDKey.String(val) -} - -// GenAIDataSourceID returns an attribute KeyValue conforming to the -// "gen_ai.data_source.id" semantic conventions. It represents the data source -// identifier. -func GenAIDataSourceID(val string) attribute.KeyValue { - return GenAIDataSourceIDKey.String(val) -} - -// GenAIEmbeddingsDimensionCount returns an attribute KeyValue conforming to the -// "gen_ai.embeddings.dimension.count" semantic conventions. It represents the -// number of dimensions the resulting output embeddings should have. -func GenAIEmbeddingsDimensionCount(val int) attribute.KeyValue { - return GenAIEmbeddingsDimensionCountKey.Int(val) -} - -// GenAIEvaluationExplanation returns an attribute KeyValue conforming to the -// "gen_ai.evaluation.explanation" semantic conventions. It represents a -// free-form explanation for the assigned score provided by the evaluator. -func GenAIEvaluationExplanation(val string) attribute.KeyValue { - return GenAIEvaluationExplanationKey.String(val) -} - -// GenAIEvaluationName returns an attribute KeyValue conforming to the -// "gen_ai.evaluation.name" semantic conventions. It represents the name of the -// evaluation metric used for the GenAI response. -func GenAIEvaluationName(val string) attribute.KeyValue { - return GenAIEvaluationNameKey.String(val) -} - -// GenAIEvaluationScoreLabel returns an attribute KeyValue conforming to the -// "gen_ai.evaluation.score.label" semantic conventions. It represents the human -// readable label for evaluation. -func GenAIEvaluationScoreLabel(val string) attribute.KeyValue { - return GenAIEvaluationScoreLabelKey.String(val) -} - -// GenAIEvaluationScoreValue returns an attribute KeyValue conforming to the -// "gen_ai.evaluation.score.value" semantic conventions. It represents the -// evaluation score returned by the evaluator. -func GenAIEvaluationScoreValue(val float64) attribute.KeyValue { - return GenAIEvaluationScoreValueKey.Float64(val) -} - -// GenAIPromptName returns an attribute KeyValue conforming to the -// "gen_ai.prompt.name" semantic conventions. It represents the name of the -// prompt that uniquely identifies it. -func GenAIPromptName(val string) attribute.KeyValue { - return GenAIPromptNameKey.String(val) -} - -// GenAIRequestChoiceCount returns an attribute KeyValue conforming to the -// "gen_ai.request.choice.count" semantic conventions. It represents the target -// number of candidate completions to return. -func GenAIRequestChoiceCount(val int) attribute.KeyValue { - return GenAIRequestChoiceCountKey.Int(val) -} - -// GenAIRequestEncodingFormats returns an attribute KeyValue conforming to the -// "gen_ai.request.encoding_formats" semantic conventions. It represents the -// encoding formats requested in an embeddings operation, if specified. -func GenAIRequestEncodingFormats(val ...string) attribute.KeyValue { - return GenAIRequestEncodingFormatsKey.StringSlice(val) -} - -// GenAIRequestFrequencyPenalty returns an attribute KeyValue conforming to the -// "gen_ai.request.frequency_penalty" semantic conventions. It represents the -// frequency penalty setting for the GenAI request. -func GenAIRequestFrequencyPenalty(val float64) attribute.KeyValue { - return GenAIRequestFrequencyPenaltyKey.Float64(val) -} - -// GenAIRequestMaxTokens returns an attribute KeyValue conforming to the -// "gen_ai.request.max_tokens" semantic conventions. It represents the maximum -// number of tokens the model generates for a request. -func GenAIRequestMaxTokens(val int) attribute.KeyValue { - return GenAIRequestMaxTokensKey.Int(val) -} - -// GenAIRequestModel returns an attribute KeyValue conforming to the -// "gen_ai.request.model" semantic conventions. It represents the name of the -// GenAI model a request is being made to. -func GenAIRequestModel(val string) attribute.KeyValue { - return GenAIRequestModelKey.String(val) -} - -// GenAIRequestPresencePenalty returns an attribute KeyValue conforming to the -// "gen_ai.request.presence_penalty" semantic conventions. It represents the -// presence penalty setting for the GenAI request. -func GenAIRequestPresencePenalty(val float64) attribute.KeyValue { - return GenAIRequestPresencePenaltyKey.Float64(val) -} - -// GenAIRequestSeed returns an attribute KeyValue conforming to the -// "gen_ai.request.seed" semantic conventions. It represents the requests with -// same seed value more likely to return same result. -func GenAIRequestSeed(val int) attribute.KeyValue { - return GenAIRequestSeedKey.Int(val) -} - -// GenAIRequestStopSequences returns an attribute KeyValue conforming to the -// "gen_ai.request.stop_sequences" semantic conventions. It represents the list -// of sequences that the model will use to stop generating further tokens. -func GenAIRequestStopSequences(val ...string) attribute.KeyValue { - return GenAIRequestStopSequencesKey.StringSlice(val) -} - -// GenAIRequestStream returns an attribute KeyValue conforming to the -// "gen_ai.request.stream" semantic conventions. It represents the indicates -// whether the GenAI request was made in streaming mode. -func GenAIRequestStream(val bool) attribute.KeyValue { - return GenAIRequestStreamKey.Bool(val) -} - -// GenAIRequestTemperature returns an attribute KeyValue conforming to the -// "gen_ai.request.temperature" semantic conventions. It represents the -// temperature setting for the GenAI request. -func GenAIRequestTemperature(val float64) attribute.KeyValue { - return GenAIRequestTemperatureKey.Float64(val) -} - -// GenAIRequestTopK returns an attribute KeyValue conforming to the -// "gen_ai.request.top_k" semantic conventions. It represents the top_k sampling -// setting for the GenAI request. -func GenAIRequestTopK(val float64) attribute.KeyValue { - return GenAIRequestTopKKey.Float64(val) -} - -// GenAIRequestTopP returns an attribute KeyValue conforming to the -// "gen_ai.request.top_p" semantic conventions. It represents the top_p sampling -// setting for the GenAI request. -func GenAIRequestTopP(val float64) attribute.KeyValue { - return GenAIRequestTopPKey.Float64(val) -} - -// GenAIResponseFinishReasons returns an attribute KeyValue conforming to the -// "gen_ai.response.finish_reasons" semantic conventions. It represents the array -// of reasons the model stopped generating tokens, corresponding to each -// generation received. -func GenAIResponseFinishReasons(val ...string) attribute.KeyValue { - return GenAIResponseFinishReasonsKey.StringSlice(val) -} - -// GenAIResponseID returns an attribute KeyValue conforming to the -// "gen_ai.response.id" semantic conventions. It represents the unique identifier -// for the completion. -func GenAIResponseID(val string) attribute.KeyValue { - return GenAIResponseIDKey.String(val) -} - -// GenAIResponseModel returns an attribute KeyValue conforming to the -// "gen_ai.response.model" semantic conventions. It represents the name of the -// model that generated the response. -func GenAIResponseModel(val string) attribute.KeyValue { - return GenAIResponseModelKey.String(val) -} - -// GenAIResponseTimeToFirstChunk returns an attribute KeyValue conforming to the -// "gen_ai.response.time_to_first_chunk" semantic conventions. It represents the -// time to first chunk in a streaming response, measured from request issuance, -// in seconds. The value is measured from when the client issues the generation -// request to when the first chunk is received in the response stream. -func GenAIResponseTimeToFirstChunk(val float64) attribute.KeyValue { - return GenAIResponseTimeToFirstChunkKey.Float64(val) -} - -// GenAIRetrievalQueryText returns an attribute KeyValue conforming to the -// "gen_ai.retrieval.query.text" semantic conventions. It represents the query -// text used for retrieval. -func GenAIRetrievalQueryText(val string) attribute.KeyValue { - return GenAIRetrievalQueryTextKey.String(val) -} - -// GenAIToolCallID returns an attribute KeyValue conforming to the -// "gen_ai.tool.call.id" semantic conventions. It represents the tool call -// identifier. -func GenAIToolCallID(val string) attribute.KeyValue { - return GenAIToolCallIDKey.String(val) -} - -// GenAIToolDescription returns an attribute KeyValue conforming to the -// "gen_ai.tool.description" semantic conventions. It represents the tool -// description. -func GenAIToolDescription(val string) attribute.KeyValue { - return GenAIToolDescriptionKey.String(val) -} - -// GenAIToolName returns an attribute KeyValue conforming to the -// "gen_ai.tool.name" semantic conventions. It represents the name of the tool -// utilized by the agent. -func GenAIToolName(val string) attribute.KeyValue { - return GenAIToolNameKey.String(val) -} - -// GenAIToolType returns an attribute KeyValue conforming to the -// "gen_ai.tool.type" semantic conventions. It represents the type of the tool -// utilized by the agent. -func GenAIToolType(val string) attribute.KeyValue { - return GenAIToolTypeKey.String(val) -} - -// GenAIUsageCacheCreationInputTokens returns an attribute KeyValue conforming to -// the "gen_ai.usage.cache_creation.input_tokens" semantic conventions. It -// represents the number of input tokens written to a provider-managed cache. -func GenAIUsageCacheCreationInputTokens(val int) attribute.KeyValue { - return GenAIUsageCacheCreationInputTokensKey.Int(val) -} - -// GenAIUsageCacheReadInputTokens returns an attribute KeyValue conforming to the -// "gen_ai.usage.cache_read.input_tokens" semantic conventions. It represents the -// number of input tokens served from a provider-managed cache. -func GenAIUsageCacheReadInputTokens(val int) attribute.KeyValue { - return GenAIUsageCacheReadInputTokensKey.Int(val) -} - -// GenAIUsageInputTokens returns an attribute KeyValue conforming to the -// "gen_ai.usage.input_tokens" semantic conventions. It represents the number of -// tokens used in the GenAI input (prompt). -func GenAIUsageInputTokens(val int) attribute.KeyValue { - return GenAIUsageInputTokensKey.Int(val) -} - -// GenAIUsageOutputTokens returns an attribute KeyValue conforming to the -// "gen_ai.usage.output_tokens" semantic conventions. It represents the number of -// tokens used in the GenAI response (completion). -func GenAIUsageOutputTokens(val int) attribute.KeyValue { - return GenAIUsageOutputTokensKey.Int(val) -} - -// GenAIUsageReasoningOutputTokens returns an attribute KeyValue conforming to -// the "gen_ai.usage.reasoning.output_tokens" semantic conventions. It represents -// the number of output tokens used for reasoning (e.g. chain-of-thought, -// extended thinking). -func GenAIUsageReasoningOutputTokens(val int) attribute.KeyValue { - return GenAIUsageReasoningOutputTokensKey.Int(val) -} - -// GenAIWorkflowName returns an attribute KeyValue conforming to the -// "gen_ai.workflow.name" semantic conventions. It represents the human-readable -// name of the GenAI workflow provided by the application. -func GenAIWorkflowName(val string) attribute.KeyValue { - return GenAIWorkflowNameKey.String(val) -} - -// Enum values for gen_ai.operation.name -var ( - // Chat completion operation such as [OpenAI Chat API] - // Stability: development - // - // [OpenAI Chat API]: https://platform.openai.com/docs/api-reference/chat - GenAIOperationNameChat = GenAIOperationNameKey.String("chat") - // Multimodal content generation operation such as [Gemini Generate Content] - // Stability: development - // - // [Gemini Generate Content]: https://ai.google.dev/api/generate-content - GenAIOperationNameGenerateContent = GenAIOperationNameKey.String("generate_content") - // Text completions operation such as [OpenAI Completions API (Legacy)] - // Stability: development - // - // [OpenAI Completions API (Legacy)]: https://platform.openai.com/docs/api-reference/completions - GenAIOperationNameTextCompletion = GenAIOperationNameKey.String("text_completion") - // Embeddings operation such as [OpenAI Create embeddings API] - // Stability: development - // - // [OpenAI Create embeddings API]: https://platform.openai.com/docs/api-reference/embeddings/create - GenAIOperationNameEmbeddings = GenAIOperationNameKey.String("embeddings") - // Retrieval operation such as [OpenAI Search Vector Store API] - // Stability: development - // - // [OpenAI Search Vector Store API]: https://platform.openai.com/docs/api-reference/vector-stores/search - GenAIOperationNameRetrieval = GenAIOperationNameKey.String("retrieval") - // Create GenAI agent - // Stability: development - GenAIOperationNameCreateAgent = GenAIOperationNameKey.String("create_agent") - // Invoke GenAI agent - // Stability: development - GenAIOperationNameInvokeAgent = GenAIOperationNameKey.String("invoke_agent") - // Execute a tool - // Stability: development - GenAIOperationNameExecuteTool = GenAIOperationNameKey.String("execute_tool") - // Invoke GenAI workflow - // Stability: development - GenAIOperationNameInvokeWorkflow = GenAIOperationNameKey.String("invoke_workflow") -) - -// Enum values for gen_ai.output.type -var ( - // Plain text - // Stability: development - GenAIOutputTypeText = GenAIOutputTypeKey.String("text") - // JSON object with known or unknown schema - // Stability: development - GenAIOutputTypeJSON = GenAIOutputTypeKey.String("json") - // Image - // Stability: development - GenAIOutputTypeImage = GenAIOutputTypeKey.String("image") - // Speech - // Stability: development - GenAIOutputTypeSpeech = GenAIOutputTypeKey.String("speech") -) - -// Enum values for gen_ai.provider.name -var ( - // [OpenAI] - // Stability: development - // - // [OpenAI]: https://openai.com/ - GenAIProviderNameOpenAI = GenAIProviderNameKey.String("openai") - // Any Google generative AI endpoint - // Stability: development - GenAIProviderNameGCPGenAI = GenAIProviderNameKey.String("gcp.gen_ai") - // [Vertex AI] - // Stability: development - // - // [Vertex AI]: https://cloud.google.com/vertex-ai - GenAIProviderNameGCPVertexAI = GenAIProviderNameKey.String("gcp.vertex_ai") - // [Gemini] - // Stability: development - // - // [Gemini]: https://cloud.google.com/products/gemini - GenAIProviderNameGCPGemini = GenAIProviderNameKey.String("gcp.gemini") - // [Anthropic] - // Stability: development - // - // [Anthropic]: https://www.anthropic.com/ - GenAIProviderNameAnthropic = GenAIProviderNameKey.String("anthropic") - // [Cohere] - // Stability: development - // - // [Cohere]: https://cohere.com/ - GenAIProviderNameCohere = GenAIProviderNameKey.String("cohere") - // Azure AI Inference - // Stability: development - GenAIProviderNameAzureAIInference = GenAIProviderNameKey.String("azure.ai.inference") - // [Azure OpenAI] - // Stability: development - // - // [Azure OpenAI]: https://learn.microsoft.com/en-us/azure/ai-services/openai/overview - GenAIProviderNameAzureAIOpenAI = GenAIProviderNameKey.String("azure.ai.openai") - // [IBM Watsonx AI] - // Stability: development - // - // [IBM Watsonx AI]: https://www.ibm.com/products/watsonx-ai - GenAIProviderNameIBMWatsonxAI = GenAIProviderNameKey.String("ibm.watsonx.ai") - // [AWS Bedrock] - // Stability: development - // - // [AWS Bedrock]: https://aws.amazon.com/bedrock - GenAIProviderNameAWSBedrock = GenAIProviderNameKey.String("aws.bedrock") - // [Perplexity] - // Stability: development - // - // [Perplexity]: https://www.perplexity.ai/ - GenAIProviderNamePerplexity = GenAIProviderNameKey.String("perplexity") - // [xAI] - // Stability: development - // - // [xAI]: https://x.ai/ - GenAIProviderNameXAI = GenAIProviderNameKey.String("x_ai") - // [DeepSeek] - // Stability: development - // - // [DeepSeek]: https://www.deepseek.com/ - GenAIProviderNameDeepseek = GenAIProviderNameKey.String("deepseek") - // [Groq] - // Stability: development - // - // [Groq]: https://groq.com/ - GenAIProviderNameGroq = GenAIProviderNameKey.String("groq") - // [Mistral AI] - // Stability: development - // - // [Mistral AI]: https://mistral.ai/ - GenAIProviderNameMistralAI = GenAIProviderNameKey.String("mistral_ai") -) - -// Enum values for gen_ai.token.type -var ( - // Input tokens (prompt, input, etc.) - // Stability: development - GenAITokenTypeInput = GenAITokenTypeKey.String("input") - // Output tokens (completion, response, etc.) - // Stability: development - GenAITokenTypeOutput = GenAITokenTypeKey.String("output") -) - -// Namespace: geo -const ( - // GeoContinentCodeKey is the attribute Key conforming to the - // "geo.continent.code" semantic conventions. It represents the two-letter code - // representing continent’s name. - // - // Type: Enum - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: - GeoContinentCodeKey = attribute.Key("geo.continent.code") - - // GeoCountryISOCodeKey is the attribute Key conforming to the - // "geo.country.iso_code" semantic conventions. It represents the two-letter ISO - // Country Code ([ISO 3166-1 alpha2]). - // - // Type: string - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: "CA" - // - // [ISO 3166-1 alpha2]: https://wikipedia.org/wiki/ISO_3166-1#Codes - GeoCountryISOCodeKey = attribute.Key("geo.country.iso_code") - - // GeoLocalityNameKey is the attribute Key conforming to the "geo.locality.name" - // semantic conventions. It represents the locality name. Represents the name of - // a city, town, village, or similar populated place. - // - // Type: string - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: "Montreal", "Berlin" - GeoLocalityNameKey = attribute.Key("geo.locality.name") - - // GeoLocationLatKey is the attribute Key conforming to the "geo.location.lat" - // semantic conventions. It represents the latitude of the geo location in - // [WGS84]. - // - // Type: double - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: 45.505918 - // - // [WGS84]: https://wikipedia.org/wiki/World_Geodetic_System#WGS84 - GeoLocationLatKey = attribute.Key("geo.location.lat") - - // GeoLocationLonKey is the attribute Key conforming to the "geo.location.lon" - // semantic conventions. It represents the longitude of the geo location in - // [WGS84]. - // - // Type: double - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: -73.61483 - // - // [WGS84]: https://wikipedia.org/wiki/World_Geodetic_System#WGS84 - GeoLocationLonKey = attribute.Key("geo.location.lon") - - // GeoPostalCodeKey is the attribute Key conforming to the "geo.postal_code" - // semantic conventions. It represents the postal code associated with the - // location. Values appropriate for this field may also be known as a postcode - // or ZIP code and will vary widely from country to country. - // - // Type: string - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: "94040" - GeoPostalCodeKey = attribute.Key("geo.postal_code") - - // GeoRegionISOCodeKey is the attribute Key conforming to the - // "geo.region.iso_code" semantic conventions. It represents the region ISO code - // ([ISO 3166-2]). - // - // Type: string - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: "CA-QC" - // - // [ISO 3166-2]: https://wikipedia.org/wiki/ISO_3166-2 - GeoRegionISOCodeKey = attribute.Key("geo.region.iso_code") -) + // [ISO 3166-2]: https://wikipedia.org/wiki/ISO_3166-2 + GeoRegionISOCodeKey = attribute.Key("geo.region.iso_code") +) // GeoCountryISOCode returns an attribute KeyValue conforming to the // "geo.country.iso_code" semantic conventions. It represents the two-letter ISO @@ -9201,7 +8198,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Release_Candidate + // Stability: Stable // // Examples: "opentelemetry-cluster" K8SClusterNameKey = attribute.Key("k8s.cluster.name") @@ -9212,7 +8209,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Release_Candidate + // Stability: Stable // // Examples: "218fc5a9-a5f1-4b54-aa05-46717d0ab26d" // Note: K8s doesn't have support for obtaining a cluster ID. If this is ever @@ -9241,6 +8238,19 @@ const ( // [ISO/IEC 9834-8 and ITU-T X.667]: https://www.itu.int/ITU-T/studygroups/com17/oid.html K8SClusterUIDKey = attribute.Key("k8s.cluster.uid") + // K8SContainerEphemeralStorageFsTypeKey is the attribute Key conforming to the + // "k8s.container.ephemeral_storage.fs_type" semantic conventions. It represents + // the type of file system component for ephemeral storage. + // + // Type: Enum + // RequirementLevel: Recommended + // Stability: Development + // + // Examples: "rootfs", "logs" + // Note: Eviction decisions based on ephemeral-storage resource limits are made + // based on the total container usage. + K8SContainerEphemeralStorageFsTypeKey = attribute.Key("k8s.container.ephemeral_storage.fs_type") + // K8SContainerNameKey is the attribute Key conforming to the // "k8s.container.name" semantic conventions. It represents the name of the // Container from Pod specification, must be unique within a Pod. Container @@ -9248,7 +8258,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Release_Candidate + // Stability: Stable // // Examples: "redis" K8SContainerNameKey = attribute.Key("k8s.container.name") @@ -9260,7 +8270,7 @@ const ( // // Type: int // RequirementLevel: Recommended - // Stability: Release_Candidate + // Stability: Stable // // Examples: K8SContainerRestartCountKey = attribute.Key("k8s.container.restart_count") @@ -9289,8 +8299,8 @@ const ( // "CreateContainerConfigError", "ErrImagePull", "ImagePullBackOff", // "OOMKilled", "Completed", "Error", "ContainerCannotRun" // - // [K8s ContainerStateWaiting]: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30/#containerstatewaiting-v1-core - // [K8s ContainerStateTerminated]: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30/#containerstateterminated-v1-core + // [K8s ContainerStateWaiting]: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.34/#containerstatewaiting-v1-core + // [K8s ContainerStateTerminated]: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.34/#containerstateterminated-v1-core K8SContainerStatusReasonKey = attribute.Key("k8s.container.status.reason") // K8SContainerStatusStateKey is the attribute Key conforming to the @@ -9303,7 +8313,7 @@ const ( // // Examples: "terminated", "running", "waiting" // - // [K8s ContainerState]: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30/#containerstate-v1-core + // [K8s ContainerState]: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.34/#containerstate-v1-core K8SContainerStatusStateKey = attribute.Key("k8s.container.status.state") // K8SCronJobNameKey is the attribute Key conforming to the "k8s.cronjob.name" @@ -9311,7 +8321,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Release_Candidate + // Stability: Stable // // Examples: "opentelemetry" K8SCronJobNameKey = attribute.Key("k8s.cronjob.name") @@ -9321,7 +8331,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Release_Candidate + // Stability: Stable // // Examples: "275ecb36-5aa8-4c2a-9c47-d8bb681b9aff" K8SCronJobUIDKey = attribute.Key("k8s.cronjob.uid") @@ -9332,7 +8342,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Release_Candidate + // Stability: Stable // // Examples: "opentelemetry" K8SDaemonSetNameKey = attribute.Key("k8s.daemonset.name") @@ -9342,7 +8352,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Release_Candidate + // Stability: Stable // // Examples: "275ecb36-5aa8-4c2a-9c47-d8bb681b9aff" K8SDaemonSetUIDKey = attribute.Key("k8s.daemonset.uid") @@ -9353,7 +8363,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Release_Candidate + // Stability: Stable // // Examples: "opentelemetry" K8SDeploymentNameKey = attribute.Key("k8s.deployment.name") @@ -9364,7 +8374,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Release_Candidate + // Stability: Stable // // Examples: "275ecb36-5aa8-4c2a-9c47-d8bb681b9aff" K8SDeploymentUIDKey = attribute.Key("k8s.deployment.uid") @@ -9454,7 +8464,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Release_Candidate + // Stability: Stable // // Examples: "opentelemetry" K8SJobNameKey = attribute.Key("k8s.job.name") @@ -9464,7 +8474,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Release_Candidate + // Stability: Stable // // Examples: "275ecb36-5aa8-4c2a-9c47-d8bb681b9aff" K8SJobUIDKey = attribute.Key("k8s.job.uid") @@ -9475,7 +8485,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Release_Candidate + // Stability: Stable // // Examples: "default" K8SNamespaceNameKey = attribute.Key("k8s.namespace.name") @@ -9492,7 +8502,7 @@ const ( // Note: This attribute aligns with the `phase` field of the // [K8s NamespaceStatus] // - // [K8s NamespaceStatus]: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30/#namespacestatus-v1-core + // [K8s NamespaceStatus]: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.34/#namespacestatus-v1-core K8SNamespacePhaseKey = attribute.Key("k8s.namespace.phase") // K8SNodeConditionStatusKey is the attribute Key conforming to the @@ -9507,7 +8517,7 @@ const ( // Note: This attribute aligns with the `status` field of the // [NodeCondition] // - // [NodeCondition]: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30/#nodecondition-v1-core + // [NodeCondition]: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.34/#nodecondition-v1-core K8SNodeConditionStatusKey = attribute.Key("k8s.node.condition.status") // K8SNodeConditionTypeKey is the attribute Key conforming to the @@ -9531,8 +8541,8 @@ const ( // When this occurs, the exact value as reported by the Kubernetes API SHOULD be // used. // - // [K8s documentation]: https://v1-32.docs.kubernetes.io/docs/reference/node/node-status/#condition - // [NodeCondition]: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30/#nodecondition-v1-core + // [K8s documentation]: https://kubernetes.io/docs/reference/node/node-status/#condition + // [NodeCondition]: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.34/#nodecondition-v1-core K8SNodeConditionTypeKey = attribute.Key("k8s.node.condition.type") // K8SNodeNameKey is the attribute Key conforming to the "k8s.node.name" @@ -9540,7 +8550,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Release_Candidate + // Stability: Stable // // Examples: "node-1" K8SNodeNameKey = attribute.Key("k8s.node.name") @@ -9561,7 +8571,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Release_Candidate + // Stability: Stable // // Examples: "1eb3a0c6-0477-4080-a9cb-0cb7db65c6a2" K8SNodeUIDKey = attribute.Key("k8s.node.uid") @@ -9661,7 +8671,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Release_Candidate + // Stability: Stable // // Examples: "collector-gateway" // Note: The K8s Pod spec has an optional hostname field, which can be used to @@ -9681,7 +8691,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Release_Candidate + // Stability: Stable // // Examples: "172.18.0.2" // Note: This attribute aligns with the `podIP` field of the @@ -9695,7 +8705,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Release_Candidate + // Stability: Stable // // Examples: "opentelemetry-pod-autoconf" K8SPodNameKey = attribute.Key("k8s.pod.name") @@ -9706,7 +8716,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Release_Candidate + // Stability: Stable // // Examples: "2025-12-04T08:41:03Z" // Note: Date and time at which the object was acknowledged by the Kubelet. @@ -9750,7 +8760,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Release_Candidate + // Stability: Stable // // Examples: "275ecb36-5aa8-4c2a-9c47-d8bb681b9aff" K8SPodUIDKey = attribute.Key("k8s.pod.uid") @@ -9761,7 +8771,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Release_Candidate + // Stability: Stable // // Examples: "opentelemetry" K8SReplicaSetNameKey = attribute.Key("k8s.replicaset.name") @@ -9772,7 +8782,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Release_Candidate + // Stability: Stable // // Examples: "275ecb36-5aa8-4c2a-9c47-d8bb681b9aff" K8SReplicaSetUIDKey = attribute.Key("k8s.replicaset.uid") @@ -9985,7 +8995,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Release_Candidate + // Stability: Stable // // Examples: "opentelemetry" K8SStatefulSetNameKey = attribute.Key("k8s.statefulset.name") @@ -9996,7 +9006,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Release_Candidate + // Stability: Stable // // Examples: "275ecb36-5aa8-4c2a-9c47-d8bb681b9aff" K8SStatefulSetUIDKey = attribute.Key("k8s.statefulset.uid") @@ -10011,7 +9021,7 @@ const ( // // Examples: "gold.storageclass.storage.k8s.io" // - // [StorageClass]: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30/#storageclass-v1-storage-k8s-io + // [StorageClass]: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.34/#storageclass-v1-storage-k8s-io K8SStorageclassNameKey = attribute.Key("k8s.storageclass.name") // K8SVolumeNameKey is the attribute Key conforming to the "k8s.volume.name" @@ -10559,7 +9569,7 @@ func K8SStatefulSetUID(val string) attribute.KeyValue { // "k8s.storageclass.name" semantic conventions. It represents the name of K8s // [StorageClass] object. // -// [StorageClass]: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30/#storageclass-v1-storage-k8s-io +// [StorageClass]: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.34/#storageclass-v1-storage-k8s-io func K8SStorageclassName(val string) attribute.KeyValue { return K8SStorageclassNameKey.String(val) } @@ -10571,6 +9581,16 @@ func K8SVolumeName(val string) attribute.KeyValue { return K8SVolumeNameKey.String(val) } +// Enum values for k8s.container.ephemeral_storage.fs_type +var ( + // For the container's writable layer usage. + // Stability: development + K8SContainerEphemeralStorageFsTypeRootfs = K8SContainerEphemeralStorageFsTypeKey.String("rootfs") + // For the container's log files usage (stdout/stderr). + // Stability: development + K8SContainerEphemeralStorageFsTypeLogs = K8SContainerEphemeralStorageFsTypeKey.String("logs") +) + // Enum values for k8s.container.status.reason var ( // The container is being created. @@ -10809,32 +9829,32 @@ var ( // A [persistentVolumeClaim] volume // Stability: development // - // [persistentVolumeClaim]: https://v1-30.docs.kubernetes.io/docs/concepts/storage/volumes/#persistentvolumeclaim + // [persistentVolumeClaim]: https://kubernetes.io/docs/concepts/storage/volumes/#persistentvolumeclaim K8SVolumeTypePersistentVolumeClaim = K8SVolumeTypeKey.String("persistentVolumeClaim") // A [configMap] volume // Stability: development // - // [configMap]: https://v1-30.docs.kubernetes.io/docs/concepts/storage/volumes/#configmap + // [configMap]: https://kubernetes.io/docs/concepts/storage/volumes/#configmap K8SVolumeTypeConfigMap = K8SVolumeTypeKey.String("configMap") // A [downwardAPI] volume // Stability: development // - // [downwardAPI]: https://v1-30.docs.kubernetes.io/docs/concepts/storage/volumes/#downwardapi + // [downwardAPI]: https://kubernetes.io/docs/concepts/storage/volumes/#downwardapi K8SVolumeTypeDownwardAPI = K8SVolumeTypeKey.String("downwardAPI") // An [emptyDir] volume // Stability: development // - // [emptyDir]: https://v1-30.docs.kubernetes.io/docs/concepts/storage/volumes/#emptydir + // [emptyDir]: https://kubernetes.io/docs/concepts/storage/volumes/#emptydir K8SVolumeTypeEmptyDir = K8SVolumeTypeKey.String("emptyDir") // A [secret] volume // Stability: development // - // [secret]: https://v1-30.docs.kubernetes.io/docs/concepts/storage/volumes/#secret + // [secret]: https://kubernetes.io/docs/concepts/storage/volumes/#secret K8SVolumeTypeSecret = K8SVolumeTypeKey.String("secret") // A [local] volume // Stability: development // - // [local]: https://v1-30.docs.kubernetes.io/docs/concepts/storage/volumes/#local + // [local]: https://kubernetes.io/docs/concepts/storage/volumes/#local K8SVolumeTypeLocal = K8SVolumeTypeKey.String("local") ) @@ -10959,227 +9979,45 @@ func LogFilePathResolved(val string) attribute.KeyValue { // original Log Record. func LogRecordOriginal(val string) attribute.KeyValue { return LogRecordOriginalKey.String(val) -} - -// LogRecordUID returns an attribute KeyValue conforming to the "log.record.uid" -// semantic conventions. It represents a unique identifier for the Log Record. -func LogRecordUID(val string) attribute.KeyValue { - return LogRecordUIDKey.String(val) -} - -// Enum values for log.iostream -var ( - // Logs from stdout stream - // Stability: development - LogIostreamStdout = LogIostreamKey.String("stdout") - // Events from stderr stream - // Stability: development - LogIostreamStderr = LogIostreamKey.String("stderr") -) - -// Namespace: mainframe -const ( - // MainframeLparNameKey is the attribute Key conforming to the - // "mainframe.lpar.name" semantic conventions. It represents the name of the - // logical partition that hosts a systems with a mainframe operating system. - // - // Type: string - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: "LPAR01" - MainframeLparNameKey = attribute.Key("mainframe.lpar.name") -) - -// MainframeLparName returns an attribute KeyValue conforming to the -// "mainframe.lpar.name" semantic conventions. It represents the name of the -// logical partition that hosts a systems with a mainframe operating system. -func MainframeLparName(val string) attribute.KeyValue { - return MainframeLparNameKey.String(val) -} - -// Namespace: mcp -const ( - // McpMethodNameKey is the attribute Key conforming to the "mcp.method.name" - // semantic conventions. It represents the name of the request or notification - // method. - // - // Type: Enum - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: - McpMethodNameKey = attribute.Key("mcp.method.name") - - // McpProtocolVersionKey is the attribute Key conforming to the - // "mcp.protocol.version" semantic conventions. It represents the [version] of - // the Model Context Protocol used. - // - // Type: string - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: "2025-06-18" - // - // [version]: https://modelcontextprotocol.io/specification/versioning - McpProtocolVersionKey = attribute.Key("mcp.protocol.version") - - // McpResourceURIKey is the attribute Key conforming to the "mcp.resource.uri" - // semantic conventions. It represents the value of the resource uri. - // - // Type: string - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: "postgres://database/customers/schema", - // "file:///home/user/documents/report.pdf" - // Note: This is a URI of the resource provided in the following requests or - // notifications: `resources/read`, `resources/subscribe`, - // `resources/unsubscribe`, or `notifications/resources/updated`. - McpResourceURIKey = attribute.Key("mcp.resource.uri") - - // McpSessionIDKey is the attribute Key conforming to the "mcp.session.id" - // semantic conventions. It represents the identifies [MCP session]. - // - // Type: string - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: "191c4850af6c49e08843a3f6c80e5046" - // - // [MCP session]: https://modelcontextprotocol.io/specification/2025-06-18/basic/transports#session-management - McpSessionIDKey = attribute.Key("mcp.session.id") -) - -// McpProtocolVersion returns an attribute KeyValue conforming to the -// "mcp.protocol.version" semantic conventions. It represents the [version] of -// the Model Context Protocol used. -// -// [version]: https://modelcontextprotocol.io/specification/versioning -func McpProtocolVersion(val string) attribute.KeyValue { - return McpProtocolVersionKey.String(val) -} - -// McpResourceURI returns an attribute KeyValue conforming to the -// "mcp.resource.uri" semantic conventions. It represents the value of the -// resource uri. -func McpResourceURI(val string) attribute.KeyValue { - return McpResourceURIKey.String(val) -} - -// McpSessionID returns an attribute KeyValue conforming to the "mcp.session.id" -// semantic conventions. It represents the identifies [MCP session]. -// -// [MCP session]: https://modelcontextprotocol.io/specification/2025-06-18/basic/transports#session-management -func McpSessionID(val string) attribute.KeyValue { - return McpSessionIDKey.String(val) -} - -// Enum values for mcp.method.name -var ( - // Notification cancelling a previously-issued request. - // - // Stability: development - McpMethodNameNotificationsCancelled = McpMethodNameKey.String("notifications/cancelled") - // Request to initialize the MCP client. - // - // Stability: development - McpMethodNameInitialize = McpMethodNameKey.String("initialize") - // Notification indicating that the MCP client has been initialized. - // - // Stability: development - McpMethodNameNotificationsInitialized = McpMethodNameKey.String("notifications/initialized") - // Notification indicating the progress for a long-running operation. - // - // Stability: development - McpMethodNameNotificationsProgress = McpMethodNameKey.String("notifications/progress") - // Request to check that the other party is still alive. - // - // Stability: development - McpMethodNamePing = McpMethodNameKey.String("ping") - // Request to list resources available on server. - // - // Stability: development - McpMethodNameResourcesList = McpMethodNameKey.String("resources/list") - // Request to list resource templates available on server. - // - // Stability: development - McpMethodNameResourcesTemplatesList = McpMethodNameKey.String("resources/templates/list") - // Request to read a resource. - // - // Stability: development - McpMethodNameResourcesRead = McpMethodNameKey.String("resources/read") - // Notification indicating that the list of resources has changed. - // - // Stability: development - McpMethodNameNotificationsResourcesListChanged = McpMethodNameKey.String("notifications/resources/list_changed") - // Request to subscribe to a resource. - // - // Stability: development - McpMethodNameResourcesSubscribe = McpMethodNameKey.String("resources/subscribe") - // Request to unsubscribe from resource updates. - // - // Stability: development - McpMethodNameResourcesUnsubscribe = McpMethodNameKey.String("resources/unsubscribe") - // Notification indicating that a resource has been updated. - // - // Stability: development - McpMethodNameNotificationsResourcesUpdated = McpMethodNameKey.String("notifications/resources/updated") - // Request to list prompts available on server. - // - // Stability: development - McpMethodNamePromptsList = McpMethodNameKey.String("prompts/list") - // Request to get a prompt. - // - // Stability: development - McpMethodNamePromptsGet = McpMethodNameKey.String("prompts/get") - // Notification indicating that the list of prompts has changed. - // - // Stability: development - McpMethodNameNotificationsPromptsListChanged = McpMethodNameKey.String("notifications/prompts/list_changed") - // Request to list tools available on server. - // - // Stability: development - McpMethodNameToolsList = McpMethodNameKey.String("tools/list") - // Request to call a tool. - // - // Stability: development - McpMethodNameToolsCall = McpMethodNameKey.String("tools/call") - // Notification indicating that the list of tools has changed. - // - // Stability: development - McpMethodNameNotificationsToolsListChanged = McpMethodNameKey.String("notifications/tools/list_changed") - // Request to set the logging level. - // - // Stability: development - McpMethodNameLoggingSetLevel = McpMethodNameKey.String("logging/setLevel") - // Notification indicating that a message has been received. - // - // Stability: development - McpMethodNameNotificationsMessage = McpMethodNameKey.String("notifications/message") - // Request to create a sampling message. - // - // Stability: development - McpMethodNameSamplingCreateMessage = McpMethodNameKey.String("sampling/createMessage") - // Request to complete a prompt. - // +} + +// LogRecordUID returns an attribute KeyValue conforming to the "log.record.uid" +// semantic conventions. It represents a unique identifier for the Log Record. +func LogRecordUID(val string) attribute.KeyValue { + return LogRecordUIDKey.String(val) +} + +// Enum values for log.iostream +var ( + // Logs from stdout stream // Stability: development - McpMethodNameCompletionComplete = McpMethodNameKey.String("completion/complete") - // Request to list roots available on server. - // + LogIostreamStdout = LogIostreamKey.String("stdout") + // Events from stderr stream // Stability: development - McpMethodNameRootsList = McpMethodNameKey.String("roots/list") - // Notification indicating that the list of roots has changed. + LogIostreamStderr = LogIostreamKey.String("stderr") +) + +// Namespace: mainframe +const ( + // MainframeLparNameKey is the attribute Key conforming to the + // "mainframe.lpar.name" semantic conventions. It represents the name of the + // logical partition that hosts a systems with a mainframe operating system. // - // Stability: development - McpMethodNameNotificationsRootsListChanged = McpMethodNameKey.String("notifications/roots/list_changed") - // Request from the server to elicit additional information from the user via - // the client + // Type: string + // RequirementLevel: Recommended + // Stability: Development // - // Stability: development - McpMethodNameElicitationCreate = McpMethodNameKey.String("elicitation/create") + // Examples: "LPAR01" + MainframeLparNameKey = attribute.Key("mainframe.lpar.name") ) +// MainframeLparName returns an attribute KeyValue conforming to the +// "mainframe.lpar.name" semantic conventions. It represents the name of the +// logical partition that hosts a systems with a mainframe operating system. +func MainframeLparName(val string) attribute.KeyValue { + return MainframeLparNameKey.String(val) +} + // Namespace: messaging const ( // MessagingBatchMessageCountKey is the attribute Key conforming to the @@ -12073,12 +10911,14 @@ const ( NetworkInterfaceNameKey = attribute.Key("network.interface.name") // NetworkIODirectionKey is the attribute Key conforming to the - // "network.io.direction" semantic conventions. It represents the network IO - // operation direction. + // "network.io.direction" semantic conventions. It represents the direction of + // traffic from the perspective of the observing host's physical or virtual + // network interface. It should not be used to represent the logical direction + // of a stateful connection or network flow. // // Type: Enum // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "transmit" NetworkIODirectionKey = attribute.Key("network.io.direction") @@ -12395,10 +11235,10 @@ var ( // Enum values for network.io.direction var ( // transmit - // Stability: development + // Stability: release_candidate NetworkIODirectionTransmit = NetworkIODirectionKey.String("transmit") // receive - // Stability: development + // Stability: release_candidate NetworkIODirectionReceive = NetworkIODirectionKey.String("receive") ) @@ -12577,90 +11417,6 @@ func OncRPCVersion(val int) attribute.KeyValue { return OncRPCVersionKey.Int(val) } -// Namespace: openai -const ( - // OpenAIAPITypeKey is the attribute Key conforming to the "openai.api.type" - // semantic conventions. It represents the type of OpenAI API being used. - // - // Type: Enum - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: - OpenAIAPITypeKey = attribute.Key("openai.api.type") - - // OpenAIRequestServiceTierKey is the attribute Key conforming to the - // "openai.request.service_tier" semantic conventions. It represents the service - // tier requested. May be a specific tier, default, or auto. - // - // Type: Enum - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: "auto", "default" - OpenAIRequestServiceTierKey = attribute.Key("openai.request.service_tier") - - // OpenAIResponseServiceTierKey is the attribute Key conforming to the - // "openai.response.service_tier" semantic conventions. It represents the - // service tier used for the response. - // - // Type: string - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: "scale", "default" - OpenAIResponseServiceTierKey = attribute.Key("openai.response.service_tier") - - // OpenAIResponseSystemFingerprintKey is the attribute Key conforming to the - // "openai.response.system_fingerprint" semantic conventions. It represents a - // fingerprint to track any eventual change in the Generative AI environment. - // - // Type: string - // RequirementLevel: Recommended - // Stability: Development - // - // Examples: "fp_44709d6fcb" - OpenAIResponseSystemFingerprintKey = attribute.Key("openai.response.system_fingerprint") -) - -// OpenAIResponseServiceTier returns an attribute KeyValue conforming to the -// "openai.response.service_tier" semantic conventions. It represents the service -// tier used for the response. -func OpenAIResponseServiceTier(val string) attribute.KeyValue { - return OpenAIResponseServiceTierKey.String(val) -} - -// OpenAIResponseSystemFingerprint returns an attribute KeyValue conforming to -// the "openai.response.system_fingerprint" semantic conventions. It represents a -// fingerprint to track any eventual change in the Generative AI environment. -func OpenAIResponseSystemFingerprint(val string) attribute.KeyValue { - return OpenAIResponseSystemFingerprintKey.String(val) -} - -// Enum values for openai.api.type -var ( - // The OpenAI [Chat Completions API]. - // Stability: development - // - // [Chat Completions API]: https://developers.openai.com/api/reference/chat-completions/overview - OpenAIAPITypeChatCompletions = OpenAIAPITypeKey.String("chat_completions") - // The OpenAI [Responses API]. - // Stability: development - // - // [Responses API]: https://developers.openai.com/api/reference/responses/overview - OpenAIAPITypeResponses = OpenAIAPITypeKey.String("responses") -) - -// Enum values for openai.request.service_tier -var ( - // The system will utilize scale tier credits until they are exhausted. - // Stability: development - OpenAIRequestServiceTierAuto = OpenAIRequestServiceTierKey.String("auto") - // The system will utilize the default scale tier. - // Stability: development - OpenAIRequestServiceTierDefault = OpenAIRequestServiceTierKey.String("default") -) - // Namespace: openshift const ( // OpenShiftClusterquotaNameKey is the attribute Key conforming to the @@ -12733,7 +11489,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "example.com", "corp.internal", "prod.db.local" // Note: This attribute SHOULD be set to the value of the `DB_DOMAIN` @@ -12753,7 +11509,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "ORCL1", "ORCL2", "ORCL3" // Note: There can be multiple instances associated with a single database @@ -12769,7 +11525,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "ORCL1", "FREE" // Note: This attribute SHOULD be set to the value of the parameter `DB_NAME` @@ -12782,7 +11538,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "PDB1", "FREEPDB" // Note: This attribute SHOULD reflect the PDB that the session is currently @@ -12800,7 +11556,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "order-processing-service", "db_low.adb.oraclecloud.com", // "db_high.adb.oraclecloud.com" @@ -13529,7 +12285,7 @@ const ( // // Type: int // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: 4 // Note: This field can be useful for querying or performing bucket analysis on @@ -13545,7 +12301,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "cmd/otelcol" ProcessCommandKey = attribute.Key("process.command") @@ -13561,7 +12317,7 @@ const ( // // Type: string[] // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "cmd/otecol", "--config=config.yaml" ProcessCommandArgsKey = attribute.Key("process.command_args") @@ -13576,7 +12332,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "C:\cmd\otecol --config="my directory\config.yaml"" ProcessCommandLineKey = attribute.Key("process.command_line") @@ -13588,7 +12344,7 @@ const ( // // Type: Enum // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: ProcessContextSwitchTypeKey = attribute.Key("process.context_switch.type") @@ -13599,7 +12355,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "2023-11-21T09:25:34.853Z" ProcessCreationTimeKey = attribute.Key("process.creation.time") @@ -13610,7 +12366,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "c89b11207f6479603b0d49bf291c092c2b719293" ProcessExecutableBuildIDGNUKey = attribute.Key("process.executable.build_id.gnu") @@ -13621,7 +12377,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: // "foh3mEXu7BLZjsN9pOwG/kATcXlYVCDEFouRMQed_/WwRFB1hPo9LBkekthSPG/x8hMC8emW2cCjXD0_1aY" @@ -13633,7 +12389,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "600DCAFE4A110000F2BF38C493F5FB92" // Note: GNU and Go build IDs may be stripped or unavailable in some @@ -13660,7 +12416,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "otelcol" ProcessExecutableNameKey = attribute.Key("process.executable.name") @@ -13673,7 +12429,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "/usr/bin/cmd/otelcol" ProcessExecutablePathKey = attribute.Key("process.executable.path") @@ -13683,7 +12439,7 @@ const ( // // Type: int // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: 127 ProcessExitCodeKey = attribute.Key("process.exit.code") @@ -13694,7 +12450,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "2023-11-21T09:26:12.315Z" ProcessExitTimeKey = attribute.Key("process.exit.time") @@ -13706,7 +12462,7 @@ const ( // // Type: int // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: 23 ProcessGroupLeaderPIDKey = attribute.Key("process.group_leader.pid") @@ -13717,7 +12473,7 @@ const ( // // Type: boolean // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: ProcessInteractiveKey = attribute.Key("process.interactive") @@ -13728,7 +12484,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "1:name=systemd:/user.slice/user-1000.slice/session-3.scope", // "0::/user.slice/user-1000.slice/user@1000.service/tmux-spawn-0267755b-4639-4a27-90ed-f19f88e53748.scope" @@ -13746,7 +12502,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "root" ProcessOwnerKey = attribute.Key("process.owner") @@ -13757,7 +12513,7 @@ const ( // // Type: int // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: 111 ProcessParentPIDKey = attribute.Key("process.parent_pid") @@ -13767,7 +12523,7 @@ const ( // // Type: int // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: 1234 ProcessPIDKey = attribute.Key("process.pid") @@ -13778,7 +12534,7 @@ const ( // // Type: int // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: 1000 ProcessRealUserIDKey = attribute.Key("process.real_user.id") @@ -13789,7 +12545,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "operator" ProcessRealUserNameKey = attribute.Key("process.real_user.name") @@ -13801,7 +12557,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: Eclipse OpenJ9 Eclipse OpenJ9 VM openj9-0.21.0 ProcessRuntimeDescriptionKey = attribute.Key("process.runtime.description") @@ -13812,7 +12568,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "OpenJDK Runtime Environment" ProcessRuntimeNameKey = attribute.Key("process.runtime.name") @@ -13823,7 +12579,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: 14.0.2 ProcessRuntimeVersionKey = attribute.Key("process.runtime.version") @@ -13834,7 +12590,7 @@ const ( // // Type: int // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: 1002 ProcessSavedUserIDKey = attribute.Key("process.saved_user.id") @@ -13845,7 +12601,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "operator" ProcessSavedUserNameKey = attribute.Key("process.saved_user.name") @@ -13857,7 +12613,7 @@ const ( // // Type: int // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: 14 ProcessSessionLeaderPIDKey = attribute.Key("process.session_leader.pid") @@ -13868,7 +12624,7 @@ const ( // // Type: Enum // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "running" // @@ -13880,7 +12636,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "cat /etc/hostname", "xfce4-session", "bash" // Note: In many Unix-like systems, process title (proctitle), is the string @@ -13894,7 +12650,7 @@ const ( // // Type: int // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: 1001 ProcessUserIDKey = attribute.Key("process.user.id") @@ -13905,7 +12661,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "root" ProcessUserNameKey = attribute.Key("process.user.name") @@ -13915,7 +12671,7 @@ const ( // // Type: int // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: 12 // Note: The process ID within a PID namespace. This is not necessarily unique @@ -13929,7 +12685,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "/root" ProcessWorkingDirectoryKey = attribute.Key("process.working_directory") @@ -14178,26 +12934,26 @@ func ProcessWorkingDirectory(val string) attribute.KeyValue { // Enum values for process.context_switch.type var ( // voluntary - // Stability: development + // Stability: release_candidate ProcessContextSwitchTypeVoluntary = ProcessContextSwitchTypeKey.String("voluntary") // involuntary - // Stability: development + // Stability: release_candidate ProcessContextSwitchTypeInvoluntary = ProcessContextSwitchTypeKey.String("involuntary") ) // Enum values for process.state var ( // running - // Stability: development + // Stability: release_candidate ProcessStateRunning = ProcessStateKey.String("running") // sleeping - // Stability: development + // Stability: release_candidate ProcessStateSleeping = ProcessStateKey.String("sleeping") // stopped - // Stability: development + // Stability: release_candidate ProcessStateStopped = ProcessStateKey.String("stopped") // defunct - // Stability: development + // Stability: release_candidate ProcessStateDefunct = ProcessStateKey.String("defunct") ) @@ -14293,6 +13049,12 @@ var ( // // [Rust]: https://wikipedia.org/wiki/Rust_(programming_language) ProfileFrameTypeRust = ProfileFrameTypeKey.String("rust") + // [LuaJIT] + // + // Stability: development + // + // [LuaJIT]: https://en.wikipedia.org/wiki/LuaJIT + ProfileFrameTypeLuajit = ProfileFrameTypeKey.String("luajit") ) // Namespace: rpc @@ -14642,7 +13404,7 @@ const ( // // Type: Enum // RequirementLevel: Recommended - // Stability: Development + // Stability: Alpha // // Examples: "critical", "high", "medium", "low" // Note: Application developers are encouraged to set `service.criticality` to @@ -14840,21 +13602,21 @@ var ( // Service is business-critical; downtime directly impacts revenue, user // experience, or core functionality. // - // Stability: development + // Stability: alpha ServiceCriticalityCritical = ServiceCriticalityKey.String("critical") // Service is important but has degradation tolerance or fallback mechanisms. // - // Stability: development + // Stability: alpha ServiceCriticalityHigh = ServiceCriticalityKey.String("high") // Service provides supplementary functionality; degradation has limited user // impact. // - // Stability: development + // Stability: alpha ServiceCriticalityMedium = ServiceCriticalityKey.String("medium") // Service is non-essential to core operations; used for background tasks or // internal tools. // - // Stability: development + // Stability: alpha ServiceCriticalityLow = ServiceCriticalityKey.String("low") ) @@ -15095,7 +13857,7 @@ const ( // // Type: Enum // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "minor" SystemPagingFaultTypeKey = attribute.Key("system.paging.fault.type") @@ -15216,10 +13978,10 @@ var ( // Enum values for system.paging.fault.type var ( // major - // Stability: development + // Stability: release_candidate SystemPagingFaultTypeMajor = SystemPagingFaultTypeKey.String("major") // minor - // Stability: development + // Stability: release_candidate SystemPagingFaultTypeMinor = SystemPagingFaultTypeKey.String("minor") ) @@ -15350,6 +14112,9 @@ var ( // java // Stability: stable TelemetrySDKLanguageJava = TelemetrySDKLanguageKey.String("java") + // kotlin + // Stability: stable + TelemetrySDKLanguageKotlin = TelemetrySDKLanguageKey.String("kotlin") // nodejs // Stability: stable TelemetrySDKLanguageNodejs = TelemetrySDKLanguageKey.String("nodejs") @@ -16191,8 +14956,9 @@ const ( // replaced by the // value `REDACTED`: // - // - [`AWSAccessKeyId`] - // - [`Signature`] + // - [`X-Amz-Signature`] + // - [`X-Amz-Credential`] + // - [`X-Amz-Security-Token`] // - [`sig`] // - [`X-Goog-Signature`] // @@ -16215,8 +14981,9 @@ const ( // `https://www.example.com/path?color=blue&sig=REDACTED`. // // [RFC3986]: https://www.rfc-editor.org/rfc/rfc3986 - // [`AWSAccessKeyId`]: https://docs.aws.amazon.com/AmazonS3/latest/userguide/RESTAuthentication.html#RESTAuthenticationQueryStringAuth - // [`Signature`]: https://docs.aws.amazon.com/AmazonS3/latest/userguide/RESTAuthentication.html#RESTAuthenticationQueryStringAuth + // [`X-Amz-Signature`]: https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_sigv-authentication-methods.html + // [`X-Amz-Credential`]: https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_sigv-authentication-methods.html + // [`X-Amz-Security-Token`]: https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_sigv-authentication-methods.html // [`sig`]: https://learn.microsoft.com/azure/storage/common/storage-sas-overview#sas-token // [`X-Goog-Signature`]: https://cloud.google.com/storage/docs/access-control/signed-urls URLFullKey = attribute.Key("url.full") @@ -16278,8 +15045,9 @@ const ( // Query string values for the following keys SHOULD be redacted by default and // replaced by the value `REDACTED`: // - // - [`AWSAccessKeyId`] - // - [`Signature`] + // - [`X-Amz-Signature`] + // - [`X-Amz-Credential`] + // - [`X-Amz-Security-Token`] // - [`sig`] // - [`X-Goog-Signature`] // @@ -16301,8 +15069,9 @@ const ( // `q=OpenTelemetry&sig=REDACTED`. // // [URI query]: https://www.rfc-editor.org/rfc/rfc3986#section-3.4 - // [`AWSAccessKeyId`]: https://docs.aws.amazon.com/AmazonS3/latest/userguide/RESTAuthentication.html#RESTAuthenticationQueryStringAuth - // [`Signature`]: https://docs.aws.amazon.com/AmazonS3/latest/userguide/RESTAuthentication.html#RESTAuthenticationQueryStringAuth + // [`X-Amz-Signature`]: https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_sigv-authentication-methods.html + // [`X-Amz-Credential`]: https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_sigv-authentication-methods.html + // [`X-Amz-Security-Token`]: https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_sigv-authentication-methods.html // [`sig`]: https://learn.microsoft.com/azure/storage/common/storage-sas-overview#sas-token // [`X-Goog-Signature`]: https://cloud.google.com/storage/docs/access-control/signed-urls URLQueryKey = attribute.Key("url.query") @@ -16752,7 +15521,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "123" VCSChangeIDKey = attribute.Key("vcs.change.id") @@ -16763,7 +15532,7 @@ const ( // // Type: Enum // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "open", "closed", "merged" VCSChangeStateKey = attribute.Key("vcs.change.state") @@ -16775,7 +15544,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "Fixes broken thing", "feat: add my new feature", "[chore] update // dependency" @@ -16787,7 +15556,7 @@ const ( // // Type: Enum // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "added", "removed" VCSLineChangeTypeKey = attribute.Key("vcs.line_change.type") @@ -16798,7 +15567,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "my-org", "myteam", "business-unit" VCSOwnerNameKey = attribute.Key("vcs.owner.name") @@ -16809,7 +15578,7 @@ const ( // // Type: Enum // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "github", "gitlab", "gitea", "bitbucket" VCSProviderNameKey = attribute.Key("vcs.provider.name") @@ -16820,7 +15589,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "my-feature-branch", "tag-1-test" // Note: `base` refers to the starting point of a change. For example, `main` @@ -16837,7 +15606,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "9d59409acf479dfa0df1aa568182e43e43df8bbe28d60fcf2bc52e30068802cc", // "main", "123", "HEAD" @@ -16869,7 +15638,7 @@ const ( // // Type: Enum // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "branch", "tag" // Note: `base` refers to the starting point of a change. For example, `main` @@ -16885,7 +15654,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "my-feature-branch", "tag-1-test" // Note: `head` refers to where you are right now; the current reference at a @@ -16901,7 +15670,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "9d59409acf479dfa0df1aa568182e43e43df8bbe28d60fcf2bc52e30068802cc", // "main", "123", "HEAD" @@ -16931,7 +15700,7 @@ const ( // // Type: Enum // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "branch", "tag" // Note: `head` refers to where you are right now; the current reference at a @@ -16945,7 +15714,7 @@ const ( // // Type: Enum // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "branch", "tag" // @@ -16959,7 +15728,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "semantic-conventions", "my-cool-repo" // Note: Due to it only being the name, it can clash with forks of the same @@ -16974,7 +15743,7 @@ const ( // // Type: string // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: // "https://github.com/opentelemetry/open-telemetry-collector-contrib", @@ -16991,7 +15760,7 @@ const ( // // Type: Enum // RequirementLevel: Recommended - // Stability: Development + // Stability: Release_Candidate // // Examples: "ahead", "behind" VCSRevisionDeltaDirectionKey = attribute.Key("vcs.revision_delta.direction") @@ -17082,53 +15851,53 @@ var ( // Open means the change is currently active and under review. It hasn't been // merged into the target branch yet, and it's still possible to make changes or // add comments. - // Stability: development + // Stability: release_candidate VCSChangeStateOpen = VCSChangeStateKey.String("open") // WIP (work-in-progress, draft) means the change is still in progress and not // yet ready for a full review. It might still undergo significant changes. - // Stability: development + // Stability: release_candidate VCSChangeStateWip = VCSChangeStateKey.String("wip") // Closed means the merge request has been closed without merging. This can // happen for various reasons, such as the changes being deemed unnecessary, the // issue being resolved in another way, or the author deciding to withdraw the // request. - // Stability: development + // Stability: release_candidate VCSChangeStateClosed = VCSChangeStateKey.String("closed") // Merged indicates that the change has been successfully integrated into the // target codebase. - // Stability: development + // Stability: release_candidate VCSChangeStateMerged = VCSChangeStateKey.String("merged") ) // Enum values for vcs.line_change.type var ( // How many lines were added. - // Stability: development + // Stability: release_candidate VCSLineChangeTypeAdded = VCSLineChangeTypeKey.String("added") // How many lines were removed. - // Stability: development + // Stability: release_candidate VCSLineChangeTypeRemoved = VCSLineChangeTypeKey.String("removed") ) // Enum values for vcs.provider.name var ( // [GitHub] - // Stability: development + // Stability: release_candidate // // [GitHub]: https://github.com VCSProviderNameGithub = VCSProviderNameKey.String("github") // [GitLab] - // Stability: development + // Stability: release_candidate // // [GitLab]: https://gitlab.com VCSProviderNameGitlab = VCSProviderNameKey.String("gitlab") // [Gitea] - // Stability: development + // Stability: release_candidate // // [Gitea]: https://gitea.io VCSProviderNameGitea = VCSProviderNameKey.String("gitea") // [Bitbucket] - // Stability: development + // Stability: release_candidate // // [Bitbucket]: https://bitbucket.org VCSProviderNameBitbucket = VCSProviderNameKey.String("bitbucket") @@ -17137,12 +15906,12 @@ var ( // Enum values for vcs.ref.base.type var ( // [branch] - // Stability: development + // Stability: release_candidate // // [branch]: https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefbranchabranch VCSRefBaseTypeBranch = VCSRefBaseTypeKey.String("branch") // [tag] - // Stability: development + // Stability: release_candidate // // [tag]: https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddeftagatag VCSRefBaseTypeTag = VCSRefBaseTypeKey.String("tag") @@ -17151,12 +15920,12 @@ var ( // Enum values for vcs.ref.head.type var ( // [branch] - // Stability: development + // Stability: release_candidate // // [branch]: https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefbranchabranch VCSRefHeadTypeBranch = VCSRefHeadTypeKey.String("branch") // [tag] - // Stability: development + // Stability: release_candidate // // [tag]: https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddeftagatag VCSRefHeadTypeTag = VCSRefHeadTypeKey.String("tag") @@ -17165,12 +15934,12 @@ var ( // Enum values for vcs.ref.type var ( // [branch] - // Stability: development + // Stability: release_candidate // // [branch]: https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefbranchabranch VCSRefTypeBranch = VCSRefTypeKey.String("branch") // [tag] - // Stability: development + // Stability: release_candidate // // [tag]: https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddeftagatag VCSRefTypeTag = VCSRefTypeKey.String("tag") @@ -17179,10 +15948,10 @@ var ( // Enum values for vcs.revision_delta.direction var ( // How many revisions the change is behind the target ref. - // Stability: development + // Stability: release_candidate VCSRevisionDeltaDirectionBehind = VCSRevisionDeltaDirectionKey.String("behind") // How many revisions the change is ahead of the target ref. - // Stability: development + // Stability: release_candidate VCSRevisionDeltaDirectionAhead = VCSRevisionDeltaDirectionKey.String("ahead") ) diff --git a/vendor/go.opentelemetry.io/otel/semconv/v1.41.0/doc.go b/vendor/go.opentelemetry.io/otel/semconv/v1.43.0/doc.go similarity index 83% rename from vendor/go.opentelemetry.io/otel/semconv/v1.41.0/doc.go rename to vendor/go.opentelemetry.io/otel/semconv/v1.43.0/doc.go index a45d424d8..aadce15c0 100644 --- a/vendor/go.opentelemetry.io/otel/semconv/v1.41.0/doc.go +++ b/vendor/go.opentelemetry.io/otel/semconv/v1.43.0/doc.go @@ -6,6 +6,6 @@ // Package semconv implements OpenTelemetry semantic conventions. // // OpenTelemetry semantic conventions are agreed standardized naming -// patterns for OpenTelemetry things. This package represents the v1.41.0 +// patterns for OpenTelemetry things. This package represents the v1.43.0 // version of the OpenTelemetry semantic conventions. -package semconv // import "go.opentelemetry.io/otel/semconv/v1.41.0" +package semconv diff --git a/vendor/go.opentelemetry.io/otel/semconv/v1.41.0/error_type.go b/vendor/go.opentelemetry.io/otel/semconv/v1.43.0/error_type.go similarity index 96% rename from vendor/go.opentelemetry.io/otel/semconv/v1.41.0/error_type.go rename to vendor/go.opentelemetry.io/otel/semconv/v1.43.0/error_type.go index 0b13f0de8..5d8eff222 100644 --- a/vendor/go.opentelemetry.io/otel/semconv/v1.41.0/error_type.go +++ b/vendor/go.opentelemetry.io/otel/semconv/v1.43.0/error_type.go @@ -3,7 +3,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package semconv // import "go.opentelemetry.io/otel/semconv/v1.41.0" +package semconv import ( "errors" diff --git a/vendor/go.opentelemetry.io/otel/semconv/v1.41.0/exception.go b/vendor/go.opentelemetry.io/otel/semconv/v1.43.0/exception.go similarity index 80% rename from vendor/go.opentelemetry.io/otel/semconv/v1.41.0/exception.go rename to vendor/go.opentelemetry.io/otel/semconv/v1.43.0/exception.go index 5f0151aff..6c9b05adb 100644 --- a/vendor/go.opentelemetry.io/otel/semconv/v1.41.0/exception.go +++ b/vendor/go.opentelemetry.io/otel/semconv/v1.43.0/exception.go @@ -3,7 +3,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package semconv // import "go.opentelemetry.io/otel/semconv/v1.41.0" +package semconv const ( // ExceptionEventName is the name of the Span event representing an exception. diff --git a/vendor/go.opentelemetry.io/otel/semconv/v1.41.0/otelconv/metric.go b/vendor/go.opentelemetry.io/otel/semconv/v1.43.0/otelconv/metric.go similarity index 93% rename from vendor/go.opentelemetry.io/otel/semconv/v1.41.0/otelconv/metric.go rename to vendor/go.opentelemetry.io/otel/semconv/v1.43.0/otelconv/metric.go index d50e19849..9eaf0fd9a 100644 --- a/vendor/go.opentelemetry.io/otel/semconv/v1.41.0/otelconv/metric.go +++ b/vendor/go.opentelemetry.io/otel/semconv/v1.43.0/otelconv/metric.go @@ -9,16 +9,11 @@ package otelconv import ( "context" - "sync" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/noop" -) - -var ( - addOptPool = &sync.Pool{New: func() any { return &[]metric.AddOption{} }} - recOptPool = &sync.Pool{New: func() any { return &[]metric.RecordOption{} }} + "go.opentelemetry.io/otel/semconv/internal/metricpool" ) // ErrorTypeAttr is an attribute conforming to the error.type semantic @@ -192,6 +187,12 @@ func (SDKExporterLogExported) Description() string { // non-rejected log records count as success. // If no rejection reason is available, `rejected` SHOULD be used as value for // `error.type`. +// If the exporter retries failed export attempts, the export operation is +// considered finished only after the final attempt has concluded. +// Each log record MUST be counted exactly once per export operation: +// intermediate failed attempts that are followed by a retry MUST NOT increment +// the counter, +// and `error.type` reflects the cause of the final attempt. func (m SDKExporterLogExported) Add( ctx context.Context, incr int64, @@ -205,12 +206,8 @@ func (m SDKExporterLogExported) Add( return } - o := addOptPool.Get().(*[]metric.AddOption) - defer func() { - clear(*o) - *o = (*o)[:0] - addOptPool.Put(o) - }() + o := metricpool.AddOptions() + defer metricpool.PutAddOptions(o) *o = append( *o, @@ -231,6 +228,12 @@ func (m SDKExporterLogExported) Add( // non-rejected log records count as success. // If no rejection reason is available, `rejected` SHOULD be used as value for // `error.type`. +// If the exporter retries failed export attempts, the export operation is +// considered finished only after the final attempt has concluded. +// Each log record MUST be counted exactly once per export operation: +// intermediate failed attempts that are followed by a retry MUST NOT increment +// the counter, +// and `error.type` reflects the cause of the final attempt. func (m SDKExporterLogExported) AddSet(ctx context.Context, incr int64, set attribute.Set) { if !m.Int64Counter.Enabled(ctx) { return @@ -240,12 +243,8 @@ func (m SDKExporterLogExported) AddSet(ctx context.Context, incr int64, set attr return } - o := addOptPool.Get().(*[]metric.AddOption) - defer func() { - clear(*o) - *o = (*o)[:0] - addOptPool.Put(o) - }() + o := metricpool.AddOptions() + defer metricpool.PutAddOptions(o) *o = append(*o, metric.WithAttributeSet(set)) m.Int64Counter.Add(ctx, incr, *o...) @@ -442,8 +441,10 @@ func (SDKExporterLogInflight) Description() string { // // All additional attrs passed are included in the recorded value. // -// For successful exports, `error.type` MUST NOT be set. For failed exports, -// `error.type` MUST contain the failure cause. +// Log records are counted as inflight from when they are passed to the exporter +// until the export operation has concluded. +// If the exporter retries failed export attempts, log records remain inflight +// across all retry attempts and any backoff between them. func (m SDKExporterLogInflight) Add( ctx context.Context, incr int64, @@ -457,12 +458,8 @@ func (m SDKExporterLogInflight) Add( return } - o := addOptPool.Get().(*[]metric.AddOption) - defer func() { - clear(*o) - *o = (*o)[:0] - addOptPool.Put(o) - }() + o := metricpool.AddOptions() + defer metricpool.PutAddOptions(o) *o = append( *o, @@ -476,8 +473,10 @@ func (m SDKExporterLogInflight) Add( // AddSet adds incr to the existing count for set. // -// For successful exports, `error.type` MUST NOT be set. For failed exports, -// `error.type` MUST contain the failure cause. +// Log records are counted as inflight from when they are passed to the exporter +// until the export operation has concluded. +// If the exporter retries failed export attempts, log records remain inflight +// across all retry attempts and any backoff between them. func (m SDKExporterLogInflight) AddSet(ctx context.Context, incr int64, set attribute.Set) { if !m.Int64UpDownCounter.Enabled(ctx) { return @@ -487,12 +486,8 @@ func (m SDKExporterLogInflight) AddSet(ctx context.Context, incr int64, set attr return } - o := addOptPool.Get().(*[]metric.AddOption) - defer func() { - clear(*o) - *o = (*o)[:0] - addOptPool.Put(o) - }() + o := metricpool.AddOptions() + defer metricpool.PutAddOptions(o) *o = append(*o, metric.WithAttributeSet(set)) m.Int64UpDownCounter.Add(ctx, incr, *o...) @@ -683,6 +678,12 @@ func (SDKExporterMetricDataPointExported) Description() string { // non-rejected data points count as success. // If no rejection reason is available, `rejected` SHOULD be used as value for // `error.type`. +// If the exporter retries failed export attempts, the export operation is +// considered finished only after the final attempt has concluded. +// Each metric data point MUST be counted exactly once per export operation: +// intermediate failed attempts that are followed by a retry MUST NOT increment +// the counter, +// and `error.type` reflects the cause of the final attempt. func (m SDKExporterMetricDataPointExported) Add( ctx context.Context, incr int64, @@ -696,12 +697,8 @@ func (m SDKExporterMetricDataPointExported) Add( return } - o := addOptPool.Get().(*[]metric.AddOption) - defer func() { - clear(*o) - *o = (*o)[:0] - addOptPool.Put(o) - }() + o := metricpool.AddOptions() + defer metricpool.PutAddOptions(o) *o = append( *o, @@ -722,6 +719,12 @@ func (m SDKExporterMetricDataPointExported) Add( // non-rejected data points count as success. // If no rejection reason is available, `rejected` SHOULD be used as value for // `error.type`. +// If the exporter retries failed export attempts, the export operation is +// considered finished only after the final attempt has concluded. +// Each metric data point MUST be counted exactly once per export operation: +// intermediate failed attempts that are followed by a retry MUST NOT increment +// the counter, +// and `error.type` reflects the cause of the final attempt. func (m SDKExporterMetricDataPointExported) AddSet(ctx context.Context, incr int64, set attribute.Set) { if !m.Int64Counter.Enabled(ctx) { return @@ -731,12 +734,8 @@ func (m SDKExporterMetricDataPointExported) AddSet(ctx context.Context, incr int return } - o := addOptPool.Get().(*[]metric.AddOption) - defer func() { - clear(*o) - *o = (*o)[:0] - addOptPool.Put(o) - }() + o := metricpool.AddOptions() + defer metricpool.PutAddOptions(o) *o = append(*o, metric.WithAttributeSet(set)) m.Int64Counter.Add(ctx, incr, *o...) @@ -935,8 +934,10 @@ func (SDKExporterMetricDataPointInflight) Description() string { // // All additional attrs passed are included in the recorded value. // -// For successful exports, `error.type` MUST NOT be set. For failed exports, -// `error.type` MUST contain the failure cause. +// Metric data points are counted as inflight from when they are passed to the +// exporter until the export operation has concluded. +// If the exporter retries failed export attempts, metric data points remain +// inflight across all retry attempts and any backoff between them. func (m SDKExporterMetricDataPointInflight) Add( ctx context.Context, incr int64, @@ -950,12 +951,8 @@ func (m SDKExporterMetricDataPointInflight) Add( return } - o := addOptPool.Get().(*[]metric.AddOption) - defer func() { - clear(*o) - *o = (*o)[:0] - addOptPool.Put(o) - }() + o := metricpool.AddOptions() + defer metricpool.PutAddOptions(o) *o = append( *o, @@ -969,8 +966,10 @@ func (m SDKExporterMetricDataPointInflight) Add( // AddSet adds incr to the existing count for set. // -// For successful exports, `error.type` MUST NOT be set. For failed exports, -// `error.type` MUST contain the failure cause. +// Metric data points are counted as inflight from when they are passed to the +// exporter until the export operation has concluded. +// If the exporter retries failed export attempts, metric data points remain +// inflight across all retry attempts and any backoff between them. func (m SDKExporterMetricDataPointInflight) AddSet(ctx context.Context, incr int64, set attribute.Set) { if !m.Int64UpDownCounter.Enabled(ctx) { return @@ -980,12 +979,8 @@ func (m SDKExporterMetricDataPointInflight) AddSet(ctx context.Context, incr int return } - o := addOptPool.Get().(*[]metric.AddOption) - defer func() { - clear(*o) - *o = (*o)[:0] - addOptPool.Put(o) - }() + o := metricpool.AddOptions() + defer metricpool.PutAddOptions(o) *o = append(*o, metric.WithAttributeSet(set)) m.Int64UpDownCounter.Add(ctx, incr, *o...) @@ -1175,6 +1170,11 @@ func (SDKExporterOperationDuration) Description() string { // successful // operations, `error.type` MUST NOT be set. For unsuccessful export operations, // `error.type` MUST contain a relevant failure cause. +// If the exporter retries failed export attempts, exactly one observation MUST +// be recorded per export operation, +// covering the wall-clock duration from the start of the first attempt through +// the conclusion of the final attempt (including any backoff between attempts). +// `error.type` reflects the cause of the final attempt. // // [http]: https://github.com/open-telemetry/opentelemetry-proto/blob/v1.5.0/docs/specification.md#full-success-1 // [grpc]: https://github.com/open-telemetry/opentelemetry-proto/blob/v1.5.0/docs/specification.md#full-success @@ -1191,12 +1191,8 @@ func (m SDKExporterOperationDuration) Record( return } - o := recOptPool.Get().(*[]metric.RecordOption) - defer func() { - clear(*o) - *o = (*o)[:0] - recOptPool.Put(o) - }() + o := metricpool.RecordOptions() + defer metricpool.PutRecordOptions(o) *o = append( *o, @@ -1216,6 +1212,11 @@ func (m SDKExporterOperationDuration) Record( // successful // operations, `error.type` MUST NOT be set. For unsuccessful export operations, // `error.type` MUST contain a relevant failure cause. +// If the exporter retries failed export attempts, exactly one observation MUST +// be recorded per export operation, +// covering the wall-clock duration from the start of the first attempt through +// the conclusion of the final attempt (including any backoff between attempts). +// `error.type` reflects the cause of the final attempt. // // [http]: https://github.com/open-telemetry/opentelemetry-proto/blob/v1.5.0/docs/specification.md#full-success-1 // [grpc]: https://github.com/open-telemetry/opentelemetry-proto/blob/v1.5.0/docs/specification.md#full-success @@ -1228,12 +1229,8 @@ func (m SDKExporterOperationDuration) RecordSet(ctx context.Context, val float64 return } - o := recOptPool.Get().(*[]metric.RecordOption) - defer func() { - clear(*o) - *o = (*o)[:0] - recOptPool.Put(o) - }() + o := metricpool.RecordOptions() + defer metricpool.PutRecordOptions(o) *o = append(*o, metric.WithAttributeSet(set)) m.Float64Histogram.Record(ctx, val, *o...) @@ -1357,6 +1354,11 @@ func (SDKExporterSpanExported) Description() string { // success. // If no rejection reason is available, `rejected` SHOULD be used as value for // `error.type`. +// If the exporter retries failed export attempts, the export operation is +// considered finished only after the final attempt has concluded. +// Each span MUST be counted exactly once per export operation: intermediate +// failed attempts that are followed by a retry MUST NOT increment the counter, +// and `error.type` reflects the cause of the final attempt. func (m SDKExporterSpanExported) Add( ctx context.Context, incr int64, @@ -1370,12 +1372,8 @@ func (m SDKExporterSpanExported) Add( return } - o := addOptPool.Get().(*[]metric.AddOption) - defer func() { - clear(*o) - *o = (*o)[:0] - addOptPool.Put(o) - }() + o := metricpool.AddOptions() + defer metricpool.PutAddOptions(o) *o = append( *o, @@ -1396,6 +1394,11 @@ func (m SDKExporterSpanExported) Add( // success. // If no rejection reason is available, `rejected` SHOULD be used as value for // `error.type`. +// If the exporter retries failed export attempts, the export operation is +// considered finished only after the final attempt has concluded. +// Each span MUST be counted exactly once per export operation: intermediate +// failed attempts that are followed by a retry MUST NOT increment the counter, +// and `error.type` reflects the cause of the final attempt. func (m SDKExporterSpanExported) AddSet(ctx context.Context, incr int64, set attribute.Set) { if !m.Int64Counter.Enabled(ctx) { return @@ -1405,12 +1408,8 @@ func (m SDKExporterSpanExported) AddSet(ctx context.Context, incr int64, set att return } - o := addOptPool.Get().(*[]metric.AddOption) - defer func() { - clear(*o) - *o = (*o)[:0] - addOptPool.Put(o) - }() + o := metricpool.AddOptions() + defer metricpool.PutAddOptions(o) *o = append(*o, metric.WithAttributeSet(set)) m.Int64Counter.Add(ctx, incr, *o...) @@ -1607,8 +1606,10 @@ func (SDKExporterSpanInflight) Description() string { // // All additional attrs passed are included in the recorded value. // -// For successful exports, `error.type` MUST NOT be set. For failed exports, -// `error.type` MUST contain the failure cause. +// Spans are counted as inflight from when they are passed to the exporter until +// the export operation has concluded. +// If the exporter retries failed export attempts, spans remain inflight across +// all retry attempts and any backoff between them. func (m SDKExporterSpanInflight) Add( ctx context.Context, incr int64, @@ -1622,12 +1623,8 @@ func (m SDKExporterSpanInflight) Add( return } - o := addOptPool.Get().(*[]metric.AddOption) - defer func() { - clear(*o) - *o = (*o)[:0] - addOptPool.Put(o) - }() + o := metricpool.AddOptions() + defer metricpool.PutAddOptions(o) *o = append( *o, @@ -1641,8 +1638,10 @@ func (m SDKExporterSpanInflight) Add( // AddSet adds incr to the existing count for set. // -// For successful exports, `error.type` MUST NOT be set. For failed exports, -// `error.type` MUST contain the failure cause. +// Spans are counted as inflight from when they are passed to the exporter until +// the export operation has concluded. +// If the exporter retries failed export attempts, spans remain inflight across +// all retry attempts and any backoff between them. func (m SDKExporterSpanInflight) AddSet(ctx context.Context, incr int64, set attribute.Set) { if !m.Int64UpDownCounter.Enabled(ctx) { return @@ -1652,12 +1651,8 @@ func (m SDKExporterSpanInflight) AddSet(ctx context.Context, incr int64, set att return } - o := addOptPool.Get().(*[]metric.AddOption) - defer func() { - clear(*o) - *o = (*o)[:0] - addOptPool.Put(o) - }() + o := metricpool.AddOptions() + defer metricpool.PutAddOptions(o) *o = append(*o, metric.WithAttributeSet(set)) m.Int64UpDownCounter.Add(ctx, incr, *o...) @@ -1846,12 +1841,8 @@ func (m SDKLogCreated) Add(ctx context.Context, incr int64, attrs ...attribute.K return } - o := addOptPool.Get().(*[]metric.AddOption) - defer func() { - clear(*o) - *o = (*o)[:0] - addOptPool.Put(o) - }() + o := metricpool.AddOptions() + defer metricpool.PutAddOptions(o) *o = append(*o, metric.WithAttributes(attrs...)) m.Int64Counter.Add(ctx, incr, *o...) @@ -1867,12 +1858,8 @@ func (m SDKLogCreated) AddSet(ctx context.Context, incr int64, set attribute.Set return } - o := addOptPool.Get().(*[]metric.AddOption) - defer func() { - clear(*o) - *o = (*o)[:0] - addOptPool.Put(o) - }() + o := metricpool.AddOptions() + defer metricpool.PutAddOptions(o) *o = append(*o, metric.WithAttributeSet(set)) m.Int64Counter.Add(ctx, incr, *o...) @@ -2018,12 +2005,8 @@ func (m SDKMetricReaderCollectionDuration) Record( return } - o := recOptPool.Get().(*[]metric.RecordOption) - defer func() { - clear(*o) - *o = (*o)[:0] - recOptPool.Put(o) - }() + o := metricpool.RecordOptions() + defer metricpool.PutRecordOptions(o) *o = append( *o, @@ -2051,12 +2034,8 @@ func (m SDKMetricReaderCollectionDuration) RecordSet(ctx context.Context, val fl return } - o := recOptPool.Get().(*[]metric.RecordOption) - defer func() { - clear(*o) - *o = (*o)[:0] - recOptPool.Put(o) - }() + o := metricpool.RecordOptions() + defer metricpool.PutRecordOptions(o) *o = append(*o, metric.WithAttributeSet(set)) m.Float64Histogram.Record(ctx, val, *o...) @@ -2148,6 +2127,11 @@ func (SDKProcessorLogProcessed) Description() string { // // For successful processing, `error.type` MUST NOT be set. For failed // processing, `error.type` MUST contain the failure cause. +// SDK Batching Log Record Processors MUST use `queue_full` as the value of +// `error.type` for log records dropped due to a full queue. +// SDK Log Record Processors MUST use `already_shutdown` as the value of +// `error.type` for log records dropped because the processor has already been +// shut down. // For the SDK Simple and Batching Log Record Processor a log record is // considered to be processed already when it has been submitted to the exporter, // not when the corresponding export call has finished. @@ -2164,12 +2148,8 @@ func (m SDKProcessorLogProcessed) Add( return } - o := addOptPool.Get().(*[]metric.AddOption) - defer func() { - clear(*o) - *o = (*o)[:0] - addOptPool.Put(o) - }() + o := metricpool.AddOptions() + defer metricpool.PutAddOptions(o) *o = append( *o, @@ -2185,6 +2165,11 @@ func (m SDKProcessorLogProcessed) Add( // // For successful processing, `error.type` MUST NOT be set. For failed // processing, `error.type` MUST contain the failure cause. +// SDK Batching Log Record Processors MUST use `queue_full` as the value of +// `error.type` for log records dropped due to a full queue. +// SDK Log Record Processors MUST use `already_shutdown` as the value of +// `error.type` for log records dropped because the processor has already been +// shut down. // For the SDK Simple and Batching Log Record Processor a log record is // considered to be processed already when it has been submitted to the exporter, // not when the corresponding export call has finished. @@ -2197,12 +2182,8 @@ func (m SDKProcessorLogProcessed) AddSet(ctx context.Context, incr int64, set at return } - o := addOptPool.Get().(*[]metric.AddOption) - defer func() { - clear(*o) - *o = (*o)[:0] - addOptPool.Put(o) - }() + o := metricpool.AddOptions() + defer metricpool.PutAddOptions(o) *o = append(*o, metric.WithAttributeSet(set)) m.Int64Counter.Add(ctx, incr, *o...) @@ -2210,8 +2191,6 @@ func (m SDKProcessorLogProcessed) AddSet(ctx context.Context, incr int64, set at // AttrErrorType returns an optional attribute for the "error.type" semantic // convention. It represents a low-cardinality description of the failure reason. -// SDK Batching Log Record Processors MUST use `queue_full` for log records -// dropped due to a full queue. func (SDKProcessorLogProcessed) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue { return attribute.String("error.type", string(val)) } @@ -2292,8 +2271,6 @@ func (SDKProcessorLogProcessedObservable) Description() string { // AttrErrorType returns an optional attribute for the "error.type" semantic // convention. It represents a low-cardinality description of the failure reason. -// SDK Batching Log Record Processors MUST use `queue_full` for log records -// dropped due to a full queue. func (SDKProcessorLogProcessedObservable) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue { return attribute.String("error.type", string(val)) } @@ -2525,6 +2502,10 @@ func (SDKProcessorSpanProcessed) Description() string { // // For successful processing, `error.type` MUST NOT be set. For failed // processing, `error.type` MUST contain the failure cause. +// SDK Batching Span Processors MUST use `queue_full` as the value of +// `error.type` for spans dropped due to a full queue. +// SDK Span Processors MUST use `already_shutdown` as the value of `error.type` +// for spans dropped because the processor has already been shut down. // For the SDK Simple and Batching Span Processor a span is considered to be // processed already when it has been submitted to the exporter, not when the // corresponding export call has finished. @@ -2541,12 +2522,8 @@ func (m SDKProcessorSpanProcessed) Add( return } - o := addOptPool.Get().(*[]metric.AddOption) - defer func() { - clear(*o) - *o = (*o)[:0] - addOptPool.Put(o) - }() + o := metricpool.AddOptions() + defer metricpool.PutAddOptions(o) *o = append( *o, @@ -2562,6 +2539,10 @@ func (m SDKProcessorSpanProcessed) Add( // // For successful processing, `error.type` MUST NOT be set. For failed // processing, `error.type` MUST contain the failure cause. +// SDK Batching Span Processors MUST use `queue_full` as the value of +// `error.type` for spans dropped due to a full queue. +// SDK Span Processors MUST use `already_shutdown` as the value of `error.type` +// for spans dropped because the processor has already been shut down. // For the SDK Simple and Batching Span Processor a span is considered to be // processed already when it has been submitted to the exporter, not when the // corresponding export call has finished. @@ -2574,12 +2555,8 @@ func (m SDKProcessorSpanProcessed) AddSet(ctx context.Context, incr int64, set a return } - o := addOptPool.Get().(*[]metric.AddOption) - defer func() { - clear(*o) - *o = (*o)[:0] - addOptPool.Put(o) - }() + o := metricpool.AddOptions() + defer metricpool.PutAddOptions(o) *o = append(*o, metric.WithAttributeSet(set)) m.Int64Counter.Add(ctx, incr, *o...) @@ -2587,8 +2564,6 @@ func (m SDKProcessorSpanProcessed) AddSet(ctx context.Context, incr int64, set a // AttrErrorType returns an optional attribute for the "error.type" semantic // convention. It represents a low-cardinality description of the failure reason. -// SDK Batching Span Processors MUST use `queue_full` for spans dropped due to a -// full queue. func (SDKProcessorSpanProcessed) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue { return attribute.String("error.type", string(val)) } @@ -2669,8 +2644,6 @@ func (SDKProcessorSpanProcessedObservable) Description() string { // AttrErrorType returns an optional attribute for the "error.type" semantic // convention. It represents a low-cardinality description of the failure reason. -// SDK Batching Span Processors MUST use `queue_full` for spans dropped due to a -// full queue. func (SDKProcessorSpanProcessedObservable) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue { return attribute.String("error.type", string(val)) } @@ -2899,6 +2872,9 @@ func (SDKSpanLive) Description() string { // Add adds incr to the existing count for attrs. // // All additional attrs passed are included in the recorded value. +// +// Non-recording spans are not counted, hence `otel.span.sampling_result` can +// only take values `RECORD_ONLY` and `RECORD_AND_SAMPLE`, not `DROP`. func (m SDKSpanLive) Add( ctx context.Context, incr int64, @@ -2912,12 +2888,8 @@ func (m SDKSpanLive) Add( return } - o := addOptPool.Get().(*[]metric.AddOption) - defer func() { - clear(*o) - *o = (*o)[:0] - addOptPool.Put(o) - }() + o := metricpool.AddOptions() + defer metricpool.PutAddOptions(o) *o = append( *o, @@ -2930,6 +2902,9 @@ func (m SDKSpanLive) Add( } // AddSet adds incr to the existing count for set. +// +// Non-recording spans are not counted, hence `otel.span.sampling_result` can +// only take values `RECORD_ONLY` and `RECORD_AND_SAMPLE`, not `DROP`. func (m SDKSpanLive) AddSet(ctx context.Context, incr int64, set attribute.Set) { if !m.Int64UpDownCounter.Enabled(ctx) { return @@ -2939,12 +2914,8 @@ func (m SDKSpanLive) AddSet(ctx context.Context, incr int64, set attribute.Set) return } - o := addOptPool.Get().(*[]metric.AddOption) - defer func() { - clear(*o) - *o = (*o)[:0] - addOptPool.Put(o) - }() + o := metricpool.AddOptions() + defer metricpool.PutAddOptions(o) *o = append(*o, metric.WithAttributeSet(set)) m.Int64UpDownCounter.Add(ctx, incr, *o...) @@ -3100,12 +3071,8 @@ func (m SDKSpanStarted) Add( return } - o := addOptPool.Get().(*[]metric.AddOption) - defer func() { - clear(*o) - *o = (*o)[:0] - addOptPool.Put(o) - }() + o := metricpool.AddOptions() + defer metricpool.PutAddOptions(o) *o = append( *o, @@ -3130,12 +3097,8 @@ func (m SDKSpanStarted) AddSet(ctx context.Context, incr int64, set attribute.Se return } - o := addOptPool.Get().(*[]metric.AddOption) - defer func() { - clear(*o) - *o = (*o)[:0] - addOptPool.Put(o) - }() + o := metricpool.AddOptions() + defer metricpool.PutAddOptions(o) *o = append(*o, metric.WithAttributeSet(set)) m.Int64Counter.Add(ctx, incr, *o...) diff --git a/vendor/go.opentelemetry.io/otel/semconv/v1.41.0/schema.go b/vendor/go.opentelemetry.io/otel/semconv/v1.43.0/schema.go similarity index 75% rename from vendor/go.opentelemetry.io/otel/semconv/v1.41.0/schema.go rename to vendor/go.opentelemetry.io/otel/semconv/v1.43.0/schema.go index 24948a48f..ce5f5f5c5 100644 --- a/vendor/go.opentelemetry.io/otel/semconv/v1.41.0/schema.go +++ b/vendor/go.opentelemetry.io/otel/semconv/v1.43.0/schema.go @@ -3,9 +3,9 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package semconv // import "go.opentelemetry.io/otel/semconv/v1.41.0" +package semconv // SchemaURL is the schema URL that matches the version of the semantic conventions // that this package defines. Semconv packages starting from v1.4.0 must declare // non-empty schema URL in the form https://opentelemetry.io/schemas/ -const SchemaURL = "https://opentelemetry.io/schemas/1.41.0" +const SchemaURL = "https://opentelemetry.io/schemas/1.43.0" diff --git a/vendor/go.opentelemetry.io/otel/trace.go b/vendor/go.opentelemetry.io/otel/trace.go index 6836c6547..9c1567a2e 100644 --- a/vendor/go.opentelemetry.io/otel/trace.go +++ b/vendor/go.opentelemetry.io/otel/trace.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package otel // import "go.opentelemetry.io/otel" +package otel import ( "go.opentelemetry.io/otel/internal/global" diff --git a/vendor/go.opentelemetry.io/otel/trace/auto.go b/vendor/go.opentelemetry.io/otel/trace/auto.go index a75cf047d..17cf898cd 100644 --- a/vendor/go.opentelemetry.io/otel/trace/auto.go +++ b/vendor/go.opentelemetry.io/otel/trace/auto.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package trace // import "go.opentelemetry.io/otel/trace" +package trace import ( "context" @@ -20,7 +20,7 @@ import ( "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" - semconv "go.opentelemetry.io/otel/semconv/v1.41.0" + semconv "go.opentelemetry.io/otel/semconv/v1.43.0" "go.opentelemetry.io/otel/trace/embedded" "go.opentelemetry.io/otel/trace/internal/telemetry" ) @@ -358,6 +358,16 @@ func convAttrValue(value attribute.Value) telemetry.Value { out = append(out, convAttrValue(v)) } return telemetry.SliceValue(out...) + case attribute.MAP: + kvs := value.AsMap() + out := make([]telemetry.Attr, 0, len(kvs)) + for _, kv := range kvs { + out = append(out, telemetry.Attr{ + Key: string(kv.Key), + Value: convAttrValue(kv.Value), + }) + } + return telemetry.MapValue(out...) } return telemetry.Value{} } diff --git a/vendor/go.opentelemetry.io/otel/trace/config.go b/vendor/go.opentelemetry.io/otel/trace/config.go index 4cedba5ac..862ecc898 100644 --- a/vendor/go.opentelemetry.io/otel/trace/config.go +++ b/vendor/go.opentelemetry.io/otel/trace/config.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package trace // import "go.opentelemetry.io/otel/trace" +package trace import ( "slices" diff --git a/vendor/go.opentelemetry.io/otel/trace/context.go b/vendor/go.opentelemetry.io/otel/trace/context.go index 8c45a7107..89927eda6 100644 --- a/vendor/go.opentelemetry.io/otel/trace/context.go +++ b/vendor/go.opentelemetry.io/otel/trace/context.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package trace // import "go.opentelemetry.io/otel/trace" +package trace import "context" diff --git a/vendor/go.opentelemetry.io/otel/trace/doc.go b/vendor/go.opentelemetry.io/otel/trace/doc.go index cdbf41d6d..57de8f348 100644 --- a/vendor/go.opentelemetry.io/otel/trace/doc.go +++ b/vendor/go.opentelemetry.io/otel/trace/doc.go @@ -116,4 +116,4 @@ It is strongly recommended that authors only embed That implementation is the only one OpenTelemetry authors can guarantee will fully implement all the API interfaces when a user updates their API. */ -package trace // import "go.opentelemetry.io/otel/trace" +package trace diff --git a/vendor/go.opentelemetry.io/otel/trace/embedded/embedded.go b/vendor/go.opentelemetry.io/otel/trace/embedded/embedded.go index 3e359a00b..59d8a510b 100644 --- a/vendor/go.opentelemetry.io/otel/trace/embedded/embedded.go +++ b/vendor/go.opentelemetry.io/otel/trace/embedded/embedded.go @@ -11,7 +11,7 @@ // the API package). // // [OpenTelemetry trace API]: https://pkg.go.dev/go.opentelemetry.io/otel/trace -package embedded // import "go.opentelemetry.io/otel/trace/embedded" +package embedded // TracerProvider is embedded in // [go.opentelemetry.io/otel/trace.TracerProvider]. diff --git a/vendor/go.opentelemetry.io/otel/trace/hex.go b/vendor/go.opentelemetry.io/otel/trace/hex.go index 1cbef1d4b..5f156b0dc 100644 --- a/vendor/go.opentelemetry.io/otel/trace/hex.go +++ b/vendor/go.opentelemetry.io/otel/trace/hex.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package trace // import "go.opentelemetry.io/otel/trace" +package trace const ( // hexLU is a hex lookup table of the 16 lowercase hex digits. diff --git a/vendor/go.opentelemetry.io/otel/trace/internal/telemetry/attr.go b/vendor/go.opentelemetry.io/otel/trace/internal/telemetry/attr.go index ff0f6eac6..9503318eb 100644 --- a/vendor/go.opentelemetry.io/otel/trace/internal/telemetry/attr.go +++ b/vendor/go.opentelemetry.io/otel/trace/internal/telemetry/attr.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package telemetry // import "go.opentelemetry.io/otel/trace/internal/telemetry" +package telemetry // Attr is a key-value pair. type Attr struct { diff --git a/vendor/go.opentelemetry.io/otel/trace/internal/telemetry/doc.go b/vendor/go.opentelemetry.io/otel/trace/internal/telemetry/doc.go index 5debe90bb..949e2165c 100644 --- a/vendor/go.opentelemetry.io/otel/trace/internal/telemetry/doc.go +++ b/vendor/go.opentelemetry.io/otel/trace/internal/telemetry/doc.go @@ -5,4 +5,4 @@ Package telemetry provides a lightweight representations of OpenTelemetry telemetry that is compatible with the OTLP JSON protobuf encoding. */ -package telemetry // import "go.opentelemetry.io/otel/trace/internal/telemetry" +package telemetry diff --git a/vendor/go.opentelemetry.io/otel/trace/internal/telemetry/id.go b/vendor/go.opentelemetry.io/otel/trace/internal/telemetry/id.go index bea56f2e7..3a6d6b87a 100644 --- a/vendor/go.opentelemetry.io/otel/trace/internal/telemetry/id.go +++ b/vendor/go.opentelemetry.io/otel/trace/internal/telemetry/id.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package telemetry // import "go.opentelemetry.io/otel/trace/internal/telemetry" +package telemetry import ( "encoding/hex" diff --git a/vendor/go.opentelemetry.io/otel/trace/internal/telemetry/number.go b/vendor/go.opentelemetry.io/otel/trace/internal/telemetry/number.go index f5e3a8cec..29e629d66 100644 --- a/vendor/go.opentelemetry.io/otel/trace/internal/telemetry/number.go +++ b/vendor/go.opentelemetry.io/otel/trace/internal/telemetry/number.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package telemetry // import "go.opentelemetry.io/otel/trace/internal/telemetry" +package telemetry import ( "encoding/json" diff --git a/vendor/go.opentelemetry.io/otel/trace/internal/telemetry/resource.go b/vendor/go.opentelemetry.io/otel/trace/internal/telemetry/resource.go index 1798a702d..cecad8bae 100644 --- a/vendor/go.opentelemetry.io/otel/trace/internal/telemetry/resource.go +++ b/vendor/go.opentelemetry.io/otel/trace/internal/telemetry/resource.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package telemetry // import "go.opentelemetry.io/otel/trace/internal/telemetry" +package telemetry import ( "bytes" diff --git a/vendor/go.opentelemetry.io/otel/trace/internal/telemetry/scope.go b/vendor/go.opentelemetry.io/otel/trace/internal/telemetry/scope.go index c2b4c635b..b6f2e28d4 100644 --- a/vendor/go.opentelemetry.io/otel/trace/internal/telemetry/scope.go +++ b/vendor/go.opentelemetry.io/otel/trace/internal/telemetry/scope.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package telemetry // import "go.opentelemetry.io/otel/trace/internal/telemetry" +package telemetry import ( "bytes" diff --git a/vendor/go.opentelemetry.io/otel/trace/internal/telemetry/span.go b/vendor/go.opentelemetry.io/otel/trace/internal/telemetry/span.go index 61c7819a2..0da6e5fd6 100644 --- a/vendor/go.opentelemetry.io/otel/trace/internal/telemetry/span.go +++ b/vendor/go.opentelemetry.io/otel/trace/internal/telemetry/span.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package telemetry // import "go.opentelemetry.io/otel/trace/internal/telemetry" +package telemetry import ( "bytes" diff --git a/vendor/go.opentelemetry.io/otel/trace/internal/telemetry/status.go b/vendor/go.opentelemetry.io/otel/trace/internal/telemetry/status.go index 1039bf40c..5dac1b2cb 100644 --- a/vendor/go.opentelemetry.io/otel/trace/internal/telemetry/status.go +++ b/vendor/go.opentelemetry.io/otel/trace/internal/telemetry/status.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package telemetry // import "go.opentelemetry.io/otel/trace/internal/telemetry" +package telemetry // StatusCode is the status of a Span. // diff --git a/vendor/go.opentelemetry.io/otel/trace/internal/telemetry/traces.go b/vendor/go.opentelemetry.io/otel/trace/internal/telemetry/traces.go index e5f10767c..44197b808 100644 --- a/vendor/go.opentelemetry.io/otel/trace/internal/telemetry/traces.go +++ b/vendor/go.opentelemetry.io/otel/trace/internal/telemetry/traces.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package telemetry // import "go.opentelemetry.io/otel/trace/internal/telemetry" +package telemetry import ( "bytes" diff --git a/vendor/go.opentelemetry.io/otel/trace/internal/telemetry/value.go b/vendor/go.opentelemetry.io/otel/trace/internal/telemetry/value.go index cb7927b81..9d2d68063 100644 --- a/vendor/go.opentelemetry.io/otel/trace/internal/telemetry/value.go +++ b/vendor/go.opentelemetry.io/otel/trace/internal/telemetry/value.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package telemetry // import "go.opentelemetry.io/otel/trace/internal/telemetry" +package telemetry import ( "bytes" diff --git a/vendor/go.opentelemetry.io/otel/trace/nonrecording.go b/vendor/go.opentelemetry.io/otel/trace/nonrecording.go index c00221e7b..d672f03c2 100644 --- a/vendor/go.opentelemetry.io/otel/trace/nonrecording.go +++ b/vendor/go.opentelemetry.io/otel/trace/nonrecording.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package trace // import "go.opentelemetry.io/otel/trace" +package trace // nonRecordingSpan is a minimal implementation of a Span that wraps a // SpanContext. It performs no operations other than to return the wrapped diff --git a/vendor/go.opentelemetry.io/otel/trace/noop.go b/vendor/go.opentelemetry.io/otel/trace/noop.go index 400fab123..b954251b2 100644 --- a/vendor/go.opentelemetry.io/otel/trace/noop.go +++ b/vendor/go.opentelemetry.io/otel/trace/noop.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package trace // import "go.opentelemetry.io/otel/trace" +package trace import ( "context" diff --git a/vendor/go.opentelemetry.io/otel/trace/noop/noop.go b/vendor/go.opentelemetry.io/otel/trace/noop/noop.go index 689d220df..4f8190e41 100644 --- a/vendor/go.opentelemetry.io/otel/trace/noop/noop.go +++ b/vendor/go.opentelemetry.io/otel/trace/noop/noop.go @@ -10,7 +10,7 @@ // This implementation can be embedded in other implementations of the // OpenTelemetry trace API. Doing so will mean the implementation defaults to // no operation for methods it does not implement. -package noop // import "go.opentelemetry.io/otel/trace/noop" +package noop import ( "context" diff --git a/vendor/go.opentelemetry.io/otel/trace/provider.go b/vendor/go.opentelemetry.io/otel/trace/provider.go index ef85cb70c..891cc0b8c 100644 --- a/vendor/go.opentelemetry.io/otel/trace/provider.go +++ b/vendor/go.opentelemetry.io/otel/trace/provider.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package trace // import "go.opentelemetry.io/otel/trace" +package trace import "go.opentelemetry.io/otel/trace/embedded" diff --git a/vendor/go.opentelemetry.io/otel/trace/span.go b/vendor/go.opentelemetry.io/otel/trace/span.go index d01e79366..603b2c146 100644 --- a/vendor/go.opentelemetry.io/otel/trace/span.go +++ b/vendor/go.opentelemetry.io/otel/trace/span.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package trace // import "go.opentelemetry.io/otel/trace" +package trace import ( "context" diff --git a/vendor/go.opentelemetry.io/otel/trace/trace.go b/vendor/go.opentelemetry.io/otel/trace/trace.go index e3d103c4b..c4c383819 100644 --- a/vendor/go.opentelemetry.io/otel/trace/trace.go +++ b/vendor/go.opentelemetry.io/otel/trace/trace.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package trace // import "go.opentelemetry.io/otel/trace" +package trace import ( "encoding/json" diff --git a/vendor/go.opentelemetry.io/otel/trace/tracer.go b/vendor/go.opentelemetry.io/otel/trace/tracer.go index 77952d2a0..7e6e5ee93 100644 --- a/vendor/go.opentelemetry.io/otel/trace/tracer.go +++ b/vendor/go.opentelemetry.io/otel/trace/tracer.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package trace // import "go.opentelemetry.io/otel/trace" +package trace import ( "context" diff --git a/vendor/go.opentelemetry.io/otel/trace/tracestate.go b/vendor/go.opentelemetry.io/otel/trace/tracestate.go index e9cb3fd4d..9ac78fa04 100644 --- a/vendor/go.opentelemetry.io/otel/trace/tracestate.go +++ b/vendor/go.opentelemetry.io/otel/trace/tracestate.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package trace // import "go.opentelemetry.io/otel/trace" +package trace import ( "encoding/json" diff --git a/vendor/go.opentelemetry.io/otel/version.go b/vendor/go.opentelemetry.io/otel/version.go index 72746acfd..f599bf285 100644 --- a/vendor/go.opentelemetry.io/otel/version.go +++ b/vendor/go.opentelemetry.io/otel/version.go @@ -1,9 +1,9 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package otel // import "go.opentelemetry.io/otel" +package otel // Version is the current release version of OpenTelemetry in use. func Version() string { - return "1.44.0" + return "1.46.0" } diff --git a/vendor/modules.txt b/vendor/modules.txt index fbee5a0bc..dbb17be9b 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -150,7 +150,7 @@ github.com/go-json-experiment/json/internal/jsonflags github.com/go-json-experiment/json/internal/jsonopts github.com/go-json-experiment/json/internal/jsonwire github.com/go-json-experiment/json/jsontext -# github.com/go-logr/logr v1.4.3 +# github.com/go-logr/logr v1.4.4 ## explicit; go 1.18 github.com/go-logr/logr github.com/go-logr/logr/funcr @@ -204,7 +204,7 @@ github.com/grafana/xk6-dashboard-assets github.com/grpc-ecosystem/go-grpc-middleware/retry github.com/grpc-ecosystem/go-grpc-middleware/util/backoffutils github.com/grpc-ecosystem/go-grpc-middleware/util/metautils -# github.com/grpc-ecosystem/grpc-gateway/v2 v2.29.0 +# github.com/grpc-ecosystem/grpc-gateway/v2 v2.30.0 ## explicit; go 1.25.0 github.com/grpc-ecosystem/grpc-gateway/v2/internal/httprule github.com/grpc-ecosystem/grpc-gateway/v2/runtime @@ -339,7 +339,7 @@ github.com/tidwall/pretty ## explicit; go 1.24.0 go.opentelemetry.io/auto/sdk go.opentelemetry.io/auto/sdk/internal/telemetry -# go.opentelemetry.io/otel v1.44.0 +# go.opentelemetry.io/otel v1.46.0 ## explicit; go 1.25.0 go.opentelemetry.io/otel go.opentelemetry.io/otel/attribute @@ -351,12 +351,13 @@ go.opentelemetry.io/otel/internal/baggage go.opentelemetry.io/otel/internal/errorhandler go.opentelemetry.io/otel/internal/global go.opentelemetry.io/otel/propagation +go.opentelemetry.io/otel/semconv/internal/metricpool go.opentelemetry.io/otel/semconv/v1.20.0 go.opentelemetry.io/otel/semconv/v1.24.0 go.opentelemetry.io/otel/semconv/v1.37.0 -go.opentelemetry.io/otel/semconv/v1.41.0 -go.opentelemetry.io/otel/semconv/v1.41.0/otelconv -# go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.44.0 +go.opentelemetry.io/otel/semconv/v1.43.0 +go.opentelemetry.io/otel/semconv/v1.43.0/otelconv +# go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.46.0 ## explicit; go 1.25.0 go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal @@ -367,7 +368,7 @@ go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/retry go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/transform go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/x -# go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.44.0 +# go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.46.0 ## explicit; go 1.25.0 go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal @@ -378,11 +379,11 @@ go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/retry go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/transform go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/x -# go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.44.0 +# go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.46.0 ## explicit; go 1.25.0 go.opentelemetry.io/otel/exporters/otlp/otlptrace go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/tracetransform -# go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.44.0 +# go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.46.0 ## explicit; go 1.25.0 go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal @@ -392,7 +393,7 @@ go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/observ go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/retry go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/x -# go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.44.0 +# go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.46.0 ## explicit; go 1.25.0 go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal @@ -400,33 +401,36 @@ go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/counter go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/envconfig go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/observ go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/otlpjson go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/retry go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/x -# go.opentelemetry.io/otel/metric v1.44.0 +# go.opentelemetry.io/otel/metric v1.46.0 ## explicit; go 1.25.0 go.opentelemetry.io/otel/metric go.opentelemetry.io/otel/metric/embedded go.opentelemetry.io/otel/metric/noop -# go.opentelemetry.io/otel/sdk v1.44.0 +# go.opentelemetry.io/otel/sdk v1.46.0 ## explicit; go 1.25.0 go.opentelemetry.io/otel/sdk go.opentelemetry.io/otel/sdk/instrumentation +go.opentelemetry.io/otel/sdk/internal/attrnorm go.opentelemetry.io/otel/sdk/internal/x go.opentelemetry.io/otel/sdk/resource go.opentelemetry.io/otel/sdk/trace go.opentelemetry.io/otel/sdk/trace/internal/env go.opentelemetry.io/otel/sdk/trace/internal/observ -# go.opentelemetry.io/otel/sdk/metric v1.44.0 +# go.opentelemetry.io/otel/sdk/metric v1.46.0 ## explicit; go 1.25.0 go.opentelemetry.io/otel/sdk/metric go.opentelemetry.io/otel/sdk/metric/exemplar go.opentelemetry.io/otel/sdk/metric/internal go.opentelemetry.io/otel/sdk/metric/internal/aggregate +go.opentelemetry.io/otel/sdk/metric/internal/attrnorm go.opentelemetry.io/otel/sdk/metric/internal/observ go.opentelemetry.io/otel/sdk/metric/internal/reservoir go.opentelemetry.io/otel/sdk/metric/internal/x go.opentelemetry.io/otel/sdk/metric/metricdata -# go.opentelemetry.io/otel/trace v1.44.0 +# go.opentelemetry.io/otel/trace v1.46.0 ## explicit; go 1.25.0 go.opentelemetry.io/otel/trace go.opentelemetry.io/otel/trace/embedded @@ -506,10 +510,10 @@ golang.org/x/text/unicode/rangetable # golang.org/x/time v0.15.0 ## explicit; go 1.25.0 golang.org/x/time/rate -# google.golang.org/genproto/googleapis/api v0.0.0-20260720211330-0afa2a65878a +# google.golang.org/genproto/googleapis/api v0.0.0-20260819154853-08b0e4226688 ## explicit; go 1.25.0 google.golang.org/genproto/googleapis/api/httpbody -# google.golang.org/genproto/googleapis/rpc v0.0.0-20260720211330-0afa2a65878a +# google.golang.org/genproto/googleapis/rpc v0.0.0-20260819154853-08b0e4226688 ## explicit; go 1.25.0 google.golang.org/genproto/googleapis/rpc/errdetails google.golang.org/genproto/googleapis/rpc/status From 9cb32757e54f84015838815076e576e857fed833 Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Mon, 31 Aug 2026 03:03:25 +0000 Subject: [PATCH 128/182] fix(deps): update module google.golang.org/grpc to v1.83.2 (#6358) | datasource | package | from | to | | ---------- | ---------------------- | ------- | ------- | | go | google.golang.org/grpc | v1.83.1 | v1.83.2 | Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 ++-- .../grpc/internal/transport/http2_server.go | 6 ++++++ vendor/google.golang.org/grpc/version.go | 2 +- vendor/modules.txt | 2 +- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 8992ddfbb..f902dd183 100644 --- a/go.mod +++ b/go.mod @@ -63,7 +63,7 @@ require ( golang.org/x/sync v0.22.0 golang.org/x/term v0.45.0 golang.org/x/time v0.15.0 - google.golang.org/grpc v1.83.1 + google.golang.org/grpc v1.83.2 google.golang.org/protobuf v1.36.12 gopkg.in/guregu/null.v3 v3.3.0 gopkg.in/yaml.v3 v3.0.1 diff --git a/go.sum b/go.sum index c69545ff0..a761263a1 100644 --- a/go.sum +++ b/go.sum @@ -385,8 +385,8 @@ google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyac google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= -google.golang.org/grpc v1.83.1 h1:HIO0+BEtBP6soyqvqC8sNUjZ7bTs+0hFQuFF+RAy++Y= -google.golang.org/grpc v1.83.1/go.mod h1:kDyl6SKsiHKt0uylY5gtn5cEjkrIOhQOGDgIc4JGwzQ= +google.golang.org/grpc v1.83.2 h1:EManeRomTObA0BU7I8vXgg/78uE5MJ9M8B39EX2WscU= +google.golang.org/grpc v1.83.2/go.mod h1:YPI1hK3kDked6iHvgX3tR0y+nX/qpMFKhPgFsokw1S8= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= diff --git a/vendor/google.golang.org/grpc/internal/transport/http2_server.go b/vendor/google.golang.org/grpc/internal/transport/http2_server.go index 63c6539a3..82e13e64a 100644 --- a/vendor/google.golang.org/grpc/internal/transport/http2_server.go +++ b/vendor/google.golang.org/grpc/internal/transport/http2_server.go @@ -522,6 +522,12 @@ func (t *http2Server) operateHeaders(ctx context.Context, frame *http2.MetaHeade delete(mdata, "host") } + // If :authority is still missing, i.e. no host or :authority header is + // present, reject the request as invalid. + if len(mdata[":authority"]) == 0 { + t.writeEarlyAbort(streamID, s.contentSubtype, status.New(codes.Internal, "no host or :authority header present"), http.StatusBadRequest, !frame.StreamEnded()) + return nil + } if frame.StreamEnded() { // s is just created by the caller. No lock needed. s.state = streamReadDone diff --git a/vendor/google.golang.org/grpc/version.go b/vendor/google.golang.org/grpc/version.go index 64ec3b3cf..835dc07fd 100644 --- a/vendor/google.golang.org/grpc/version.go +++ b/vendor/google.golang.org/grpc/version.go @@ -19,4 +19,4 @@ package grpc // Version is the current grpc version. -const Version = "1.83.1" +const Version = "1.83.2" diff --git a/vendor/modules.txt b/vendor/modules.txt index dbb17be9b..7986c940d 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -517,7 +517,7 @@ google.golang.org/genproto/googleapis/api/httpbody ## explicit; go 1.25.0 google.golang.org/genproto/googleapis/rpc/errdetails google.golang.org/genproto/googleapis/rpc/status -# google.golang.org/grpc v1.83.1 +# google.golang.org/grpc v1.83.2 ## explicit; go 1.25.0 google.golang.org/grpc google.golang.org/grpc/attributes From 687de4dc787877106bce3d06c320bbb3f5309393 Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Wed, 2 Sep 2026 03:02:14 +0000 Subject: [PATCH 129/182] fix(security/high/examples/grpc_server): update module google.golang.org/grpc to v1.83.1 [security] (#6363) | datasource | package | from | to | | ---------- | ---------------------- | ------- | ------- | | go | google.golang.org/grpc | v1.82.1 | v1.83.1 | Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> --- examples/grpc_server/go.mod | 4 ++-- examples/grpc_server/go.sum | 28 ++++++++++++++-------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/examples/grpc_server/go.mod b/examples/grpc_server/go.mod index 1815ee0f6..c431997cd 100644 --- a/examples/grpc_server/go.mod +++ b/examples/grpc_server/go.mod @@ -6,13 +6,13 @@ replace go.k6.io/k6 => ../../ require ( go.k6.io/k6/v2 v2.0.0-rc1 - google.golang.org/grpc v1.82.1 + google.golang.org/grpc v1.83.1 ) require ( golang.org/x/net v0.56.0 // indirect golang.org/x/sys v0.46.0 // indirect golang.org/x/text v0.39.0 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20260414002931-afd174a4e478 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20260526163538-3dc84a4a5aaa // indirect google.golang.org/protobuf v1.36.11 // indirect ) diff --git a/examples/grpc_server/go.sum b/examples/grpc_server/go.sum index 58178e5c1..e598f67f1 100644 --- a/examples/grpc_server/go.sum +++ b/examples/grpc_server/go.sum @@ -14,16 +14,16 @@ go.k6.io/k6/v2 v2.0.0-rc1 h1:el4d7gjBcGbxIxtKYgfpVS9728g9HXDZ6/t1KQn1w8M= go.k6.io/k6/v2 v2.0.0-rc1/go.mod h1:yzYXN2/xmcjLHgQl1MLd7DObVncNCPH3chZ3H9HPmck= go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64= go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y= -go.opentelemetry.io/otel v1.43.0 h1:mYIM03dnh5zfN7HautFE4ieIig9amkNANT+xcVxAj9I= -go.opentelemetry.io/otel v1.43.0/go.mod h1:JuG+u74mvjvcm8vj8pI5XiHy1zDeoCS2LB1spIq7Ay0= -go.opentelemetry.io/otel/metric v1.43.0 h1:d7638QeInOnuwOONPp4JAOGfbCEpYb+K6DVWvdxGzgM= -go.opentelemetry.io/otel/metric v1.43.0/go.mod h1:RDnPtIxvqlgO8GRW18W6Z/4P462ldprJtfxHxyKd2PY= -go.opentelemetry.io/otel/sdk v1.43.0 h1:pi5mE86i5rTeLXqoF/hhiBtUNcrAGHLKQdhg4h4V9Dg= -go.opentelemetry.io/otel/sdk v1.43.0/go.mod h1:P+IkVU3iWukmiit/Yf9AWvpyRDlUeBaRg6Y+C58QHzg= -go.opentelemetry.io/otel/sdk/metric v1.43.0 h1:S88dyqXjJkuBNLeMcVPRFXpRw2fuwdvfCGLEo89fDkw= -go.opentelemetry.io/otel/sdk/metric v1.43.0/go.mod h1:C/RJtwSEJ5hzTiUz5pXF1kILHStzb9zFlIEe85bhj6A= -go.opentelemetry.io/otel/trace v1.43.0 h1:BkNrHpup+4k4w+ZZ86CZoHHEkohws8AY+WTX09nk+3A= -go.opentelemetry.io/otel/trace v1.43.0/go.mod h1:/QJhyVBUUswCphDVxq+8mld+AvhXZLhe+8WVFxiFff0= +go.opentelemetry.io/otel v1.44.0 h1:JjwHmHpA4iZ3wBxluu2fbbE7j4kqlE8jXyAyPXH7HqU= +go.opentelemetry.io/otel v1.44.0/go.mod h1:BMgjTHL9WPRlRjL2oZCBTL4whCGtXch2H4BhOPIAyYc= +go.opentelemetry.io/otel/metric v1.44.0 h1:1w0gILTcHdr3YI+ixLyjemwrVnsMURbTZFrSYCdDdmc= +go.opentelemetry.io/otel/metric v1.44.0/go.mod h1:8O7hanEPBNgEMmybD3s2VBKcgWOCsA6tzHBPODAiquo= +go.opentelemetry.io/otel/sdk v1.44.0 h1:nHYwb9lK+fJPU/dnT6s7W7Z8itMWyqrnVfbheVYrZ58= +go.opentelemetry.io/otel/sdk v1.44.0/go.mod h1:Osuydd3Se74nqjAKxid74N5eC+jfEqfTegHRnq58oK0= +go.opentelemetry.io/otel/sdk/metric v1.44.0 h1:3LlKgI+VjbVsjNRFZJZAJ30WjXC5VkNRks6si09iEfI= +go.opentelemetry.io/otel/sdk/metric v1.44.0/go.mod h1:5B5pMARnXxKhltooO4xUuCBorl65a4EpnTalObqOigA= +go.opentelemetry.io/otel/trace v1.44.0 h1:jxF5CsGYCe74MCRx2X4g7WsY/VBKRqqpNvXlX/6gtIk= +go.opentelemetry.io/otel/trace v1.44.0/go.mod h1:oLl1jrMQAVo6v3GAggN+1VH9VIz9iUSvW53sW1Q8PIE= golang.org/x/net v0.56.0 h1:Rw8j/hFzGvJUZwNBXnAtf5sVDVt+65SK2C7IxCxZt5o= golang.org/x/net v0.56.0/go.mod h1:D3Ku6r+V6JROoZK144D2XfMHFcMq/0zSfLelVTCFKec= golang.org/x/sys v0.46.0 h1:noSf2Fq6F8DBgS+LysIkx7rIExoNHJsxOAtPp4rthXw= @@ -32,9 +32,9 @@ golang.org/x/text v0.39.0 h1:UbZz4pLOvn600D6Oh6GGEI6VAmndrEBLv8/6BEXzyus= golang.org/x/text v0.39.0/go.mod h1:3UwRclnC2g0TU9x8PZiyfOajCd1zaUNHF9cvqcQZ+ZM= gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4= gonum.org/v1/gonum v0.17.0/go.mod h1:El3tOrEuMpv2UdMrbNlKEh9vd86bmQ6vqIcDwxEOc1E= -google.golang.org/genproto/googleapis/rpc v0.0.0-20260414002931-afd174a4e478 h1:RmoJA1ujG+/lRGNfUnOMfhCy5EipVMyvUE+KNbPbTlw= -google.golang.org/genproto/googleapis/rpc v0.0.0-20260414002931-afd174a4e478/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8= -google.golang.org/grpc v1.82.1 h1:NnAxzGRA0677vCa4BUkOAnO5+FfQqVl9iUXeD0IqcGE= -google.golang.org/grpc v1.82.1/go.mod h1:yzTZ1TB1Z3SG+LIYaI+WiE8D5+PZ3ArnrSp8zF3+/ZA= +google.golang.org/genproto/googleapis/rpc v0.0.0-20260526163538-3dc84a4a5aaa h1:mZHHdPZl0dbGHCflZgAq/Q468DWVFcU2whhB2KAo8fk= +google.golang.org/genproto/googleapis/rpc v0.0.0-20260526163538-3dc84a4a5aaa/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8= +google.golang.org/grpc v1.83.1 h1:HIO0+BEtBP6soyqvqC8sNUjZ7bTs+0hFQuFF+RAy++Y= +google.golang.org/grpc v1.83.1/go.mod h1:kDyl6SKsiHKt0uylY5gtn5cEjkrIOhQOGDgIc4JGwzQ= google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE= google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= From 44a616745cdbc39fd141202b0c5748768f246fb7 Mon Sep 17 00:00:00 2001 From: Mihail Stoykov <312246+mstoykov@users.noreply.github.com> Date: Tue, 8 Sep 2026 12:44:16 +0300 Subject: [PATCH 130/182] ci: switch to grafana/k6-ci hosted golangci-lint config (#6380) The canonical golangci-lint config and the composite action that runs it now live in grafana/k6-ci. This drops k6's local action and config and calls k6-ci's action from the lint workflow, with k6-specific rules expressed as a small .golangci.patch at the repo root. .github/actions/lint/ -> deleted; action now lives in k6-ci .golangci.yml -> deleted; k6-ci hosts the base .golangci.patch -> new; k6-specific forbidigo / exclusion rules .github/workflows/lint.yml -> uses grafana/k6-ci/.github/actions/lint@ Makefile -> `make lint` materializes the merged config (base + patch) in build/lint/ and runs golangci-lint at the version on line 1. Adds `update-lint-patch` and `clean-lint`. The pinned k6-ci ref in lint.yml drives both CI and local lint (the Makefile greps the same line). Renovate manages the bump. Supersedes #5968 (action_ref support in the in-repo action becomes moot once the action lives in k6-ci). Co-authored-by: Claude Opus 4.7 (1M context) --- .github/actions/lint/action.yml | 36 -------- .github/workflows/lint.yml | 30 +++---- .gitignore | 1 + .golangci.patch | 26 ++++++ .golangci.yml | 148 -------------------------------- Makefile | 46 ++++++++-- 6 files changed, 78 insertions(+), 209 deletions(-) delete mode 100644 .github/actions/lint/action.yml create mode 100644 .golangci.patch delete mode 100644 .golangci.yml diff --git a/.github/actions/lint/action.yml b/.github/actions/lint/action.yml deleted file mode 100644 index 0a9d60bcf..000000000 --- a/.github/actions/lint/action.yml +++ /dev/null @@ -1,36 +0,0 @@ -name: golangci-lint-k6 -description: Run golangci-lint with the k6 ruleset - -runs: - using: composite - steps: - - name: Resolve Go versions - id: go_versions - uses: ./.github/actions/go-versions - - name: Install Go - uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6 - with: - go-version: ${{ steps.go_versions.outputs.current }} - check-latest: true - - name: Get golangci-lint version and download rules - shell: bash - env: - GITHUB_ACTION_REF: ${{ github.action_ref }} - GITHUB_HEAD_REF: ${{ github.head_ref }} - REPO_FULL_NAME: ${{ github.event.pull_request.head.repo.full_name }} - run: | - branch="${GITHUB_HEAD_REF:-master}" - if [ "${REPO_FULL_NAME}" != "grafana/k6" ]; then - branch="${GITHUB_ACTION_REF:-master}" - fi - rules_url="https://raw.githubusercontent.com/grafana/k6/${branch}/.golangci.yml" - echo "Downloading '${rules_url}' ..." - curl --silent --show-error --fail --no-location "${rules_url}" --output "${{ github.action_path }}/.golangci.yml" - - echo "GolangCIVersion=$(head -n 1 "${{ github.action_path }}/.golangci.yml" | tr -d '# ')" >> "${GITHUB_OUTPUT}" - id: getenv - - name: golangci-lint - uses: golangci/golangci-lint-action@ba0d7d2ec06a0ea1cb5fa41b2e4a3ab91d21278a # v9.3.0 - with: - version: ${{ steps.getenv.outputs.GolangCIVersion }} - args: "--config=${{ github.action_path }}/.golangci.yml" diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 48efd3d6a..e7baca01c 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -15,7 +15,7 @@ permissions: contents: read jobs: - deps: + generate-check: runs-on: ubuntu-latest steps: - name: Checkout code @@ -31,23 +31,19 @@ jobs: with: go-version: ${{ steps.go_versions.outputs.current }} check-latest: true - - name: Check dependencies - run: | - go version - test -z "$(go mod tidy && go mod vendor && git status --porcelain)" - go mod verify - name: Check code generation run: | make generate - test -z "$(git status --porcelain | tee >(cat 1>&2))" + if [ -n "$(git status --porcelain)" ]; then + echo "make generate produced changes:" + git status --porcelain + git --no-pager diff + exit 1 + fi - lint: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 - with: - persist-credentials: false - fetch-depth: 0 - - name: Run linters - uses: ./.github/actions/lint/ + k6-ci: + uses: grafana/k6-ci/.github/workflows/all.yml@777962b022a831166517639e542630d8b7d1455f # v0.4.0 + with: + k6-ci-ref: 777962b022a831166517639e542630d8b7d1455f # v0.4.0 + skip-tests: true + skip-extension-testing: true diff --git a/.gitignore b/.gitignore index 4e1968646..3f120dbad 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ /internal/js/modules/k6/experimental/streams/tests/wpt /internal/js/modules/k6/webcrypto/tests/wpt/ /.protoc +/build/ .vscode *.sublime-workspace diff --git a/.golangci.patch b/.golangci.patch new file mode 100644 index 000000000..ca83284ca --- /dev/null +++ b/.golangci.patch @@ -0,0 +1,26 @@ +diff --git a/.golangci.yml b/.golangci.yml +--- a/.golangci.yml ++++ b/.golangci.yml +@@ -101,6 +101,22 @@ linters: + - gosec + path: _(test|gen)\.go + - linters: ++ - contextcheck ++ - revive ++ path: js\/modules\/k6\/browser\/.*\.go ++ - linters: ++ - revive ++ path: js\/modules\/k6\/html\/.*\.go ++ text: 'exported: exported ' ++ - linters: ++ - paralleltest ++ - tparallel ++ path: js\/modules\/k6\/html\/.*\.go ++ - linters: ++ - paralleltest ++ - tparallel ++ path: js\/modules\/k6\/http\/.*_test\.go ++ - linters: + - forbidigo + text: use of `os\.(SyscallError|Signal|Interrupt)` forbidden + - linters: diff --git a/.golangci.yml b/.golangci.yml deleted file mode 100644 index 159d1a046..000000000 --- a/.golangci.yml +++ /dev/null @@ -1,148 +0,0 @@ -# v2.10.1 -# Please don't remove the first line. It uses in CI to determine the golangci version -version: "2" -linters: - default: none - enable: - - asasalint - - asciicheck - - bidichk - - bodyclose - - canonicalheader - - contextcheck - - copyloopvar - - cyclop - - dogsled - - dupl - - durationcheck - - errcheck - - errchkjson - - errname - - errorlint - - exhaustive - - fatcontext - - forbidigo - - forcetypeassert - - funlen - - gocheckcompilerdirectives - - gochecknoglobals - - gocognit - - goconst - - gocritic - - gomoddirectives - - goprintffuncname - - gosec - - govet - - importas - - ineffassign - - interfacebloat - - lll - - makezero - - misspell - - modernize - - nakedret - - nestif - - nilerr - - nilnil - - noctx - - nolintlint - - nosprintfhostport - - paralleltest - - prealloc - - predeclared - - promlinter - - reassign - - revive - - rowserrcheck - - sqlclosecheck - - staticcheck - - tparallel - - unconvert - - unparam - - unused - - usestdlibvars - - usetesting - - wastedassign - - whitespace - settings: - cyclop: - max-complexity: 25 - dupl: - threshold: 150 - exhaustive: - default-signifies-exhaustive: true - forbidigo: - forbid: - - pattern: ^(fmt\\.Print(|f|ln)|print|println)$ - - pattern: ^os\.(.*)$(# Using anything except Signal and SyscallError from the os package is forbidden )? - - pattern: ^syscall\.[^A-Z_]+$(# Using anything except constants from the syscall package is forbidden )? - - pattern: ^logrus\.Logger$ - - pattern: ^afero\.(.*)$(# Using afero outside of the fsext package is forbidden )? - funlen: - lines: 80 - statements: 60 - goconst: - min-len: 10 - min-occurrences: 4 - usetesting: - os-setenv: true - exclusions: - generated: lax - rules: - - linters: - - canonicalheader - - cyclop - - dupl - - forcetypeassert - - funlen - - gocognit - - lll - - gosec - path: _(test|gen)\.go - - linters: - - contextcheck - - revive - path: js\/modules\/k6\/browser\/.*\.go - - linters: - - revive - path: js\/modules\/k6\/html\/.*\.go - text: 'exported: exported ' - - linters: - - paralleltest - - tparallel - path: js\/modules\/k6\/html\/.*\.go - - linters: - - paralleltest - - tparallel - path: js\/modules\/k6\/http\/.*_test\.go - - linters: - - forbidigo - text: use of `os\.(SyscallError|Signal|Interrupt)` forbidden - - linters: - - forbidigo - text: use of `afero\.(.*)` forbidden - path: lib/fsext/.*\.go - - linters: - - revive - text: avoid meaningless package names - - linters: - - revive - text: avoid package names that conflict with Go standard library - paths: - - third_party$ - - builtin$ - - examples$ -issues: - max-issues-per-linter: 0 - max-same-issues: 0 -formatters: - enable: - - gofmt - - gofumpt - - goimports - exclusions: - generated: lax - paths: - - third_party$ - - builtin$ - - examples$ diff --git a/Makefile b/Makefile index 51332c92f..1bc88492d 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,15 @@ MAKEFLAGS += --silent -GOLANGCI_LINT_VERSION = $(shell head -n 1 .golangci.yml | tr -d '\# ') PROTOC_VERSION := 21.12 +LINT_WORKFLOW ?= .github/workflows/lint.yml +K6_CI_REF := $(shell grep -oE 'grafana/k6-ci/[^@[:space:]]+@[A-Za-z0-9._/-]+' $(LINT_WORKFLOW) | head -n1 | cut -d@ -f2) +LINT_BASE_URL := https://raw.githubusercontent.com/grafana/k6-ci/$(K6_CI_REF)/.golangci.yml +LINT_DIR ?= build/lint +LINT_BASE := $(LINT_DIR)/.golangci-base.yml +LINT_FINAL := $(LINT_DIR)/.golangci.yml +LINT_PATCH ?= .golangci.patch +GOLANGCI_LINT_VERSION = $(shell head -n 1 $(LINT_BASE) 2>/dev/null | tr -d '\# ') + ifeq ($(OS),Windows_NT) DETECTED_OS := Windows PROTOC_ARCHIVE := protoc-$(PROTOC_VERSION)-win64.zip @@ -51,14 +59,36 @@ format: grpc-server-run: go run -mod=mod examples/grpc_server/*.go -## check-linter-version: Checks if the linter version is the same as the one specified in the linter config. -check-linter-version: - (golangci-lint version | grep -E "version v?$(shell head -n 1 .golangci.yml | tr -d '\# v')") || echo "Your installation of golangci-lint is different from the one that is specified in k6's linter config (there it's $(shell head -n 1 .golangci.yml | tr -d '\# ')). Results could be different in the CI." +$(LINT_DIR): + mkdir -p $@ + +$(LINT_BASE): $(LINT_WORKFLOW) | $(LINT_DIR) + curl -fsSL $(LINT_BASE_URL) -o $@ + +$(LINT_FINAL): $(LINT_BASE) $(wildcard $(LINT_PATCH)) + cp $(LINT_BASE) $@ + @if [ -f $(LINT_PATCH) ]; then \ + echo "Applying $(LINT_PATCH)"; \ + git apply --directory=$(LINT_DIR) $(LINT_PATCH); \ + fi -## lint: Runs the linters. -lint: check-linter-version +## lint: Run golangci-lint with the k6-ci config + $(LINT_PATCH). +lint: $(LINT_FINAL) echo "Running linters..." - golangci-lint run ./... + go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) \ + run --config=$(LINT_FINAL) ./... + +## update-lint-patch: Regenerate $(LINT_PATCH) from the locally edited $(LINT_FINAL). +update-lint-patch: $(LINT_BASE) + @if [ ! -f $(LINT_FINAL) ]; then \ + echo "Run 'make lint' first to materialize $(LINT_FINAL), edit it, then re-run."; \ + exit 1; \ + fi + -diff -u --label a/.golangci.yml --label b/.golangci.yml $(LINT_BASE) $(LINT_FINAL) > $(LINT_PATCH) + +## clean-lint: Remove $(LINT_DIR). +clean-lint: + rm -rf $(LINT_DIR) ## tests: Executes any unit tests. tests: @@ -82,4 +112,4 @@ clean: @echo "cleaning" rm -f ./k6 -.PHONY: build format lint tests check check-linter-version help +.PHONY: build format lint tests check help update-lint-patch clean-lint From cdd7355b536141e37ae4497facfa3813f8736cf4 Mon Sep 17 00:00:00 2001 From: Vardan Torosyan Date: Tue, 8 Sep 2026 11:46:25 +0200 Subject: [PATCH 131/182] feat: add opt-in AIA certificate chain fetching (tlsAIAFetch) (#6137) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: add opt-in AIA certificate chain fetching (tlsAIAFetch) Go's crypto/tls does not fetch missing intermediate certificates via the Authority Information Access (AIA) extension; browsers do. Servers that send only a leaf certificate and rely on AIA to fill in the chain cause k6 TLS handshakes to fail with "x509: certificate signed by unknown authority" even when the chain is technically valid. This commit adds a new `tlsAIAFetch` option (env: K6_TLS_AIA_FETCH) that enables AIA chain fetching on a per-test basis. When enabled, k6 intercepts failed chain verification, follows IssuingCertificateURL fields (BFS, up to 5 hops), retries verification with any fetched intermediates, and then restores hostname verification — exactly what browsers do. Implementation details: - lib/netext/aia.go: core WrapTLSConfigForAIAFetching function; uses a separate http.Client (not measured as test traffic) with a 10s timeout; process-level sync.Map cache so repeated handshakes pay the HTTP cost at most once per AIA URL; circular-reference protection via seen map - lib/options.go: new TLSAIAFetch null.Bool option (default off) - internal/js/runner.go: opt-in wiring — wraps the per-VU tls.Config when tlsAIAFetch: true; no-op when insecureSkipTLSVerify is also true - internal/js/modules/k6/grpc/client.go: fix buildTLSConfig to copy VerifyPeerCertificate and VerifyConnection callbacks from the parent config, so AIA verification is not silently bypassed for gRPC connections that supply explicit TLS options (cacerts/cert/key) Tests: - lib/netext/aia_test.go: 10 parallel unit tests covering happy path, complete chain passthrough, disabled/plain-Go regression, InsecureSkip- Verify passthrough, unreachable URL, fetch timeout, HTTP error, malformed cert, circular AIA references, and hostname-mismatch enforcement - internal/js/runner_aia_test.go: full VU integration test (Source and Archive runners) verifying the enabled/disabled toggle end-to-end Fixes https://github.com/grafana/k6/issues/5941 Co-Authored-By: Claude Sonnet 4.6 * chore: fix lint issues in AIA implementation - aia.go: split var block so gochecknoglobals nolint directives are per-variable (golangci-lint v2 requires inline directives); extract buildVerifyPeerFn, verifyWithAIA, and buildVerifyConnFn to bring WrapTLSConfigForAIAFetching within the gocognit limit; fix makezero by using append instead of make+copy for the BFS queue; wrap the fetchAIAIntermediates signature to stay within the lll limit; remove unused //nolint:gosec on direct assignment (G402 only fires on struct literals); add //nolint:gosec to httpClient.Do for G704 (SSRF); add //nolint:contextcheck to runner.go call site (AIA fetches intentionally use context.Background inside the TLS callback) - aia_test.go: use closeBody helper for error-path tests (bodyclose); _, _ = fmt.Fprintln for errcheck; change nullLogger return type from *logrus.Logger to logrus.FieldLogger (forbidigo); add //nolint:noctx to net.Listen call; remove nolint directives that are unused because gosec/forcetypeassert are excluded for test files - runner_aia_test.go: remove unused //nolint:forcetypeassert - kill_other.go: remove obsolete // +build constraint (modernize) Co-Authored-By: Claude Sonnet 4.6 * fix: include TLSAIAFetch in Options.Apply merge Without this, tlsAIAFetch set in a script's options block would be silently dropped when k6 merges option sources (script + CLI flags + env vars), causing AIA fetching to never activate despite being configured. Co-Authored-By: Claude Sonnet 4.6 * test: add TLS handshake benchmarks for AIA fetching overhead Co-Authored-By: Claude Sonnet 4.6 * test: add benchmark for AIA enabled but not needed (complete chain) Co-Authored-By: Claude Sonnet 4.6 * fix(grpc): honour user-supplied cacerts when tlsAIAFetch is enabled When the VU tls.Config is AIA-wrapped and a grpc.connect() call supplies its own cacerts, buildTLSConfig previously copied the parent's VerifyPeerCertificate/VerifyConnection callbacks. Those callbacks captured the VU config's RootCAs, so the gRPC-supplied cp was silently ignored and the handshake failed with "x509: certificate signed by unknown authority" even when the correct CA was provided. Instead, re-wrap the gRPC-local tls.Config with WrapTLSConfigForAIAFetching when AIA is enabled at the VU level. The new closure captures the gRPC config, so its RootCAs (cp) is used for chain verification. Adds a targeted test that reproduces the failure and verifies the fix. * feat(aia): warn when AIA response is PKCS#7 (unsupported) Some CAs (notably Sectigo and others) serve intermediate certificates as PKCS#7/CMS bundles rather than raw DER or PEM. k6 does not currently parse that format, so the fetched intermediate is silently dropped and the chain remains incomplete — the user sees an "unknown authority" handshake failure with no clue that PKCS#7 was the cause. Detect PKCS#7 responses via the Content-Type header and by scanning for the ASN.1 signedData OID, and emit a Warn log pointing at the URL so users can diagnose the situation. Full PKCS#7 parser support is tracked as a follow-up. * chore: trim verbose comments in gRPC AIA fix and PKCS#7 warn * chore(grpc): fix lint issues in AIA cacerts test (noctx, gofmt) * refactor(aia): coalesce concurrent fetches, cache TTL, bound HTTP calls Address review feedback on the AIA fetching path: - Coalesce concurrent AIA fetches for the same URL via singleflight, so a cold-start burst of many VUs against the same server issues a single HTTP request rather than N parallel ones before the cache warms. - Add a 24h TTL to cached intermediates so long-running tests eventually pick up rotated certificates. - aiaMaxFetchDepth (5) now bounds the number of HTTP fetches, not the number of queue pops. Previously, chains where the server sent many certs plus an AIA URL exhausted the counter without ever fetching; genuinely deep chains can now complete. - Return nil (not an empty pool) when x509.SystemCertPool fails, so callers fall through to Go's default handling instead of substituting a pool that guarantees verification failure. - Clarify guard comments in buildVerifyConnFn. * fix(grpc): honour user InsecureSkipVerify intent when AIA is enabled When tlsAIAFetch was on at the VU level, buildTLSConfig copied parentConfig.InsecureSkipVerify (forced to true by the AIA wrapper) into the fresh gRPC config. The subsequent re-wrap then early-returned, leaving gRPC with InsecureSkipVerify=true and no verification at all — silently insecure even when cacerts were supplied. Take insecureSkipVerify from state.Options.InsecureSkipTLSVerify (the user's actual intent) rather than the wrapped parent config. Simplify TLSAIAFetch checks from .Valid && .Bool to .Bool so a future default-true still works. Add a regression test that a mismatched cacerts pool with AIA enabled rejects the handshake. * test: extract shared TLS chain helpers to testutils/tlstest The AIA tests in lib/netext and the gRPC AIA tests both hand-rolled a three-level root CA → intermediate → leaf chain plus a thread-safe AIA handler. Consolidate them into internal/lib/testutils/tlstest so both call sites share one implementation and future TLS-related tests have a common seed. * chore: trim verbose comments across AIA + gRPC AIA tests Drop banner separators, over-explanatory function docs, and comments that restate what the code obviously does. Keep only comments that explain non-obvious "why" (e.g. why we take insecureSkipVerify from state.Options rather than parentConfig, why singleflight, why the depth counter tracks fetches rather than queue pops). * chore(aia): simplify VerifyConnection guard to ServerName-only Drop the defensive len(PeerCertificates) > 0 check — always true when VerifyConnection fires on a client-side handshake. Keep the ServerName guard to mirror Go stdlib (x509.VerifyOptions.DNSName is skipped when empty, i.e. IP-only dials without SNI still succeed). * chore(aia): drop unused prev-callback chaining machinery No k6 caller of WrapTLSConfigForAIAFetching sets VerifyPeerCertificate or VerifyConnection before wrapping, so capturing and conditionally invoking the previous callbacks was dead code. Removed the parameter from both buildVerifyPeerFn and buildVerifyConnFn. * chore: restore doc comments on exported AIAHandler methods CI linter (revive) requires doc comments on exported symbols; trimmed them too aggressively in bf4499ba9. * test(grpc): user's insecureSkipTLSVerify must be honoured with or without AIA Regression coverage for the parent→per-connect handoff: both branches use a mismatched CA and rely on skip-verify to succeed. Complements TestBuildTLSConfig_AIARejectsMismatchedCACert (skip=false path). * chore(grpc): drop unused nolint:gosec on test's InsecureSkipVerify Test files are exempt from gosec's G402 rule; the directive triggered nolintlint. * fix(aia): drain queue for cached items even after fetch budget is spent The outer loop check bailed as soon as fetches hit aiaMaxFetchDepth, skipping cached items still in the queue that could have been added for free. Move the budget check to the inner loop (continue on the specific URL instead of break) so cached items keep flowing. * fix(aia): evict cached intermediates past their NotAfter TTL alone could hand out an expired intermediate: the cert may already be past NotAfter when we first fetch it, or expire during the 24h TTL window. An expired intermediate won't validate anyway. * refactor(aia): introduce per-Runner AIAFetcher bound to caller's dialer Two connected concerns from review: 1. The bare package-level aiaHTTPClient didn't respect k6's blocking lists, host overrides, or DNS resolver. AIA fetches could hit URLs a user's blockHostnames / blacklistIPs / hosts rules would deny. 2. aiaIntermediateCache and aiaFetchGroup were package globals, sharing state across tests running in the same process. Both fold into one change: an AIAFetcher struct owning the cache, singleflight group, and an http.Client built from a caller-supplied dial function. runner.go creates one per Runner using a Runner-level netext.Dialer (Blacklist, BlockedHostnames, Hosts, Resolver — no per-VU LocalIPs, AIA is auxiliary). gRPC's Connect() builds one per call from state.Dialer so per-connect cacerts still work. The default (tlsAIAFetch: false) is a no-op: the wrap call is behind a flag check in both call sites. * test(aia): cover per-fetcher cache isolation and dialer routing Two new unit tests in lib/netext: - TestAIAFetcher_UsesProvidedDialer: a failing dial makes the AIA fetch fail and TLS verification error with unknown authority, proving the fetcher actually routes through the caller's dial. - TestAIAFetcher_CacheIsolatedBetweenFetchers: two fetchers hitting the same AIA URL each pay one fetch — no cross-fetcher cache reuse. Also updates existing tests to the AIAFetcher API (NewAIAFetcher(nil) for the bare-client path used by tests). * chore(aia): address review — SetOptions init, keep-alive, proxy, gRPC TODO - Move AIAFetcher init from NewFromBundle into SetOptions, so external option changes rebuild the fetcher (mirrors setResolver). - Drop DisableKeepAlives on the AIA transport — idle conns auto-close and a reused connection saves a handshake on cross-server hits. - Add Proxy: http.ProxyFromEnvironment so AIA respects HTTPS_PROXY. - gRPC: per-Connect fetcher stays for now with a TODO pointing at the follow-up (thread Runner fetcher via lib.State). * fix(tls): fail closed on empty ServerName in AIA verify callback For IP-literal targets Go strips the ServerName from ConnectionState (SNI can't carry IPs), so the AIA verify callback previously returned nil, accepting any valid CA-signed chain. Return an error instead so the handshake fails; users hitting bare-IP targets must disable tlsAIAFetch or set insecureSkipTLSVerify. Test suite updates dial via "localhost" so existing paths keep exercising real hostname verification, plus a new test covers the IP-literal rejection path. * test(js): dial AIA integration test via localhost, not 127.0.0.1 The fail-close change in the AIA verify callback now rejects IP-literal targets. TestVUIntegrationAIAFetching dialed 127.0.0.1 with a matching IP SAN, which used to work but now hits the closed path. Switch the leaf's SAN and the dial address to "localhost" so SNI carries a ServerName the wrapper can verify. --------- Co-authored-by: Claude Sonnet 4.6 --- internal/cmd/tests/cmd_run_test.go | 2 +- .../modules/k6/browser/common/kill_other.go | 1 - .../js/modules/k6/execution/execution_test.go | 2 +- internal/js/modules/k6/grpc/client.go | 41 +- .../js/modules/k6/grpc/client_aia_test.go | 197 +++++++ internal/js/runner.go | 17 + internal/js/runner_aia_test.go | 225 ++++++++ internal/lib/testutils/tlstest/chain.go | 160 ++++++ lib/netext/aia.go | 327 +++++++++++ lib/netext/aia_test.go | 535 ++++++++++++++++++ lib/options.go | 9 + .../x/sync/singleflight/singleflight.go | 214 +++++++ vendor/modules.txt | 1 + 13 files changed, 1723 insertions(+), 8 deletions(-) create mode 100644 internal/js/modules/k6/grpc/client_aia_test.go create mode 100644 internal/js/runner_aia_test.go create mode 100644 internal/lib/testutils/tlstest/chain.go create mode 100644 lib/netext/aia.go create mode 100644 lib/netext/aia_test.go create mode 100644 vendor/golang.org/x/sync/singleflight/singleflight.go diff --git a/internal/cmd/tests/cmd_run_test.go b/internal/cmd/tests/cmd_run_test.go index 902e7e54d..8a3e78f03 100644 --- a/internal/cmd/tests/cmd_run_test.go +++ b/internal/cmd/tests/cmd_run_test.go @@ -522,7 +522,7 @@ func TestExecutionTestOptionsDefaultValues(t *testing.T) { loglines := ts.LoggerHook.Drain() require.Len(t, loglines, 1) - expected := `{"paused":null,"executionSegment":null,"executionSegmentSequence":null,"noSetup":null,"setupTimeout":null,"noTeardown":null,"teardownTimeout":null,"rps":null,"dns":{"ttl":null,"select":null,"policy":null},"maxRedirects":null,"userAgent":null,"batch":null,"batchPerHost":null,"httpDebug":null,"insecureSkipTLSVerify":null,"tlsCipherSuites":null,"tlsVersion":null,"tlsAuth":null,"throw":null,"thresholds":null,"blacklistIPs":null,"blockHostnames":null,"hosts":null,"noConnectionReuse":null,"noVUConnectionReuse":null,"minIterationDuration":null,"ext":null,"summaryTrendStats":["avg", "min", "med", "max", "p(90)", "p(95)"],"summaryTimeUnit":null,"systemTags":["check","error","error_code","expected_response","group","method","name","proto","scenario","service","status","subproto","tls_version","url"],"tags":null,"metricSamplesBufferSize":null,"noCookiesReset":null,"discardResponseBodies":null,"consoleOutput":null,"scenarios":{"default":{"vus":null,"iterations":1,"executor":"shared-iterations","maxDuration":null,"startTime":null,"env":null,"tags":null,"gracefulStop":null,"exec":null}},"localIPs":null,"handleSummaryTimeout":null,"features":null}` + expected := `{"paused":null,"executionSegment":null,"executionSegmentSequence":null,"noSetup":null,"setupTimeout":null,"noTeardown":null,"teardownTimeout":null,"rps":null,"dns":{"ttl":null,"select":null,"policy":null},"maxRedirects":null,"userAgent":null,"batch":null,"batchPerHost":null,"httpDebug":null,"insecureSkipTLSVerify":null,"tlsCipherSuites":null,"tlsVersion":null,"tlsAuth":null,"tlsAIAFetch":null,"throw":null,"thresholds":null,"blacklistIPs":null,"blockHostnames":null,"hosts":null,"noConnectionReuse":null,"noVUConnectionReuse":null,"minIterationDuration":null,"ext":null,"summaryTrendStats":["avg", "min", "med", "max", "p(90)", "p(95)"],"summaryTimeUnit":null,"systemTags":["check","error","error_code","expected_response","group","method","name","proto","scenario","service","status","subproto","tls_version","url"],"tags":null,"metricSamplesBufferSize":null,"noCookiesReset":null,"discardResponseBodies":null,"consoleOutput":null,"scenarios":{"default":{"vus":null,"iterations":1,"executor":"shared-iterations","maxDuration":null,"startTime":null,"env":null,"tags":null,"gracefulStop":null,"exec":null}},"localIPs":null,"handleSummaryTimeout":null,"features":null}` assert.JSONEq(t, expected, loglines[0].Message) } diff --git a/internal/js/modules/k6/browser/common/kill_other.go b/internal/js/modules/k6/browser/common/kill_other.go index 27e6d447e..991e294ef 100644 --- a/internal/js/modules/k6/browser/common/kill_other.go +++ b/internal/js/modules/k6/browser/common/kill_other.go @@ -1,5 +1,4 @@ //go:build !linux -// +build !linux package common diff --git a/internal/js/modules/k6/execution/execution_test.go b/internal/js/modules/k6/execution/execution_test.go index deae97ca6..8766c15b7 100644 --- a/internal/js/modules/k6/execution/execution_test.go +++ b/internal/js/modules/k6/execution/execution_test.go @@ -287,7 +287,7 @@ func TestFailTest(t *testing.T) { func TestOptionsTestFull(t *testing.T) { t.Parallel() - expected := `{"paused":true,"scenarios":{"const-vus":{"executor":"constant-vus","options":{"browser":{"someOption":true}},"startTime":"10s","gracefulStop":"30s","env":{"FOO":"bar"},"exec":"default","tags":{"tagkey":"tagvalue"},"vus":50,"duration":"10m0s"}},"executionSegment":"0:1/4","executionSegmentSequence":"0,1/4,1/2,1","noSetup":true,"setupTimeout":"1m0s","noTeardown":true,"teardownTimeout":"5m0s","rps":100,"dns":{"ttl":"1m","select":"roundRobin","policy":"any"},"maxRedirects":3,"userAgent":"k6-user-agent","batch":15,"batchPerHost":5,"httpDebug":"full","insecureSkipTLSVerify":true,"tlsCipherSuites":["TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"],"tlsVersion":{"min":"tls1.2","max":"tls1.3"},"tlsAuth":[{"domains":["example.com"],"cert":"mycert.pem","key":"mycert-key.pem","password":"mypwd"}],"throw":true,"thresholds":{"http_req_duration":[{"threshold":"rate>0.01","abortOnFail":true,"delayAbortEval":"10s"}]},"blacklistIPs":["192.0.2.0/24"],"blockHostnames":["test.k6.io","*.example.com"],"hosts":{"test.k6.io":"1.2.3.4:8443"},"noConnectionReuse":true,"noVUConnectionReuse":true,"minIterationDuration":"10s","ext":{"ext-one":{"rawkey":"rawvalue"}},"handleSummaryTimeout":null,"summaryTrendStats":["avg","min","max"],"summaryTimeUnit":"ms","systemTags":["iter","vu"],"tags":null,"metricSamplesBufferSize":8,"noCookiesReset":true,"discardResponseBodies":true,"consoleOutput":"loadtest.log","tags":{"runtag-key":"runtag-value"},"localIPs":"192.168.20.12-192.168.20.15,192.168.10.0/27","features":null}` + expected := `{"paused":true,"scenarios":{"const-vus":{"executor":"constant-vus","options":{"browser":{"someOption":true}},"startTime":"10s","gracefulStop":"30s","env":{"FOO":"bar"},"exec":"default","tags":{"tagkey":"tagvalue"},"vus":50,"duration":"10m0s"}},"executionSegment":"0:1/4","executionSegmentSequence":"0,1/4,1/2,1","noSetup":true,"setupTimeout":"1m0s","noTeardown":true,"teardownTimeout":"5m0s","rps":100,"dns":{"ttl":"1m","select":"roundRobin","policy":"any"},"maxRedirects":3,"userAgent":"k6-user-agent","batch":15,"batchPerHost":5,"httpDebug":"full","insecureSkipTLSVerify":true,"tlsCipherSuites":["TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"],"tlsVersion":{"min":"tls1.2","max":"tls1.3"},"tlsAuth":[{"domains":["example.com"],"cert":"mycert.pem","key":"mycert-key.pem","password":"mypwd"}],"tlsAIAFetch":null,"throw":true,"thresholds":{"http_req_duration":[{"threshold":"rate>0.01","abortOnFail":true,"delayAbortEval":"10s"}]},"blacklistIPs":["192.0.2.0/24"],"blockHostnames":["test.k6.io","*.example.com"],"hosts":{"test.k6.io":"1.2.3.4:8443"},"noConnectionReuse":true,"noVUConnectionReuse":true,"minIterationDuration":"10s","ext":{"ext-one":{"rawkey":"rawvalue"}},"handleSummaryTimeout":null,"summaryTrendStats":["avg","min","max"],"summaryTimeUnit":"ms","systemTags":["iter","vu"],"tags":null,"metricSamplesBufferSize":8,"noCookiesReset":true,"discardResponseBodies":true,"consoleOutput":"loadtest.log","tags":{"runtag-key":"runtag-value"},"localIPs":"192.168.20.12-192.168.20.15,192.168.10.0/27","features":null}` var ( rt = sobek.New() diff --git a/internal/js/modules/k6/grpc/client.go b/internal/js/modules/k6/grpc/client.go index 0d16e567a..82691c731 100644 --- a/internal/js/modules/k6/grpc/client.go +++ b/internal/js/modules/k6/grpc/client.go @@ -17,9 +17,12 @@ import ( "go.k6.io/k6/v2/internal/lib/netext/grpcext" "go.k6.io/k6/v2/js/common" "go.k6.io/k6/v2/js/modules" + "go.k6.io/k6/v2/lib" + "go.k6.io/k6/v2/lib/netext" "github.com/bufbuild/protocompile" "github.com/grafana/sobek" + "github.com/sirupsen/logrus" "google.golang.org/grpc" "google.golang.org/grpc/credentials" "google.golang.org/grpc/credentials/insecure" @@ -148,7 +151,10 @@ func decryptPrivateKey(key, password []byte) ([]byte, error) { return key, nil } -func buildTLSConfig(parentConfig *tls.Config, certificate, key []byte, caCertificates [][]byte) (*tls.Config, error) { +func buildTLSConfig( + parentConfig *tls.Config, certificate, key []byte, caCertificates [][]byte, + aiaFetcher *netext.AIAFetcher, insecureSkipVerify bool, logger logrus.FieldLogger, +) (*tls.Config, error) { var cp *x509.CertPool if len(caCertificates) > 0 { cp, _ = x509.SystemCertPool() @@ -162,9 +168,12 @@ func buildTLSConfig(parentConfig *tls.Config, certificate, key []byte, caCertifi // Ignoring 'TLS MinVersion is too low' because this tls.Config will inherit MinValue and MaxValue // from the vu state tls.Config + // Take insecureSkipVerify from the user's option, not parentConfig — the AIA wrapper + // forces parentConfig.InsecureSkipVerify to true internally, so inheriting silently + // disables verification. tlsCfg := &tls.Config{ CipherSuites: parentConfig.CipherSuites, - InsecureSkipVerify: parentConfig.InsecureSkipVerify, //nolint:gosec + InsecureSkipVerify: insecureSkipVerify, //nolint:gosec MinVersion: parentConfig.MinVersion, MaxVersion: parentConfig.MaxVersion, Renegotiation: parentConfig.Renegotiation, @@ -177,10 +186,17 @@ func buildTLSConfig(parentConfig *tls.Config, certificate, key []byte, caCertifi } tlsCfg.Certificates = []tls.Certificate{cert} } + // Re-wrap so the verification closure reads this config's RootCAs, not the VU's. + if aiaFetcher != nil { + tlsCfg = aiaFetcher.Wrap(tlsCfg, logger) + } return tlsCfg, nil } -func buildTLSConfigFromMap(parentConfig *tls.Config, tlsConfigMap map[string]any) (*tls.Config, error) { +func buildTLSConfigFromMap( + parentConfig *tls.Config, tlsConfigMap map[string]any, + aiaFetcher *netext.AIAFetcher, insecureSkipVerify bool, logger logrus.FieldLogger, +) (*tls.Config, error) { var cert, key, pass []byte var ca [][]byte var err error @@ -212,7 +228,21 @@ func buildTLSConfigFromMap(parentConfig *tls.Config, tlsConfigMap map[string]any ca = [][]byte{[]byte(caCertStr)} } } - return buildTLSConfig(parentConfig, cert, key, ca) + return buildTLSConfig(parentConfig, cert, key, ca, aiaFetcher, insecureSkipVerify, logger) +} + +// buildTLSConfigForConnect builds the per-connect TLS config from the state and TLS map. +// +// TODO: this creates a fresh AIAFetcher per grpc.connect() call, so its cache and +// singleflight group don't carry over between connect calls in the same VU. gRPC's +// AIA use is niche, so acceptable for now; revisit by threading the Runner-level +// fetcher through lib.State. +func buildTLSConfigForConnect(parent *tls.Config, tlsMap map[string]any, state *lib.State) (*tls.Config, error) { + var aiaFetcher *netext.AIAFetcher + if state.Options.TLSAIAFetch.Bool { + aiaFetcher = netext.NewAIAFetcher(state.Dialer.DialContext) + } + return buildTLSConfigFromMap(parent, tlsMap, aiaFetcher, state.Options.InsecureSkipTLSVerify.Bool, state.Logger) } // Connect is a block dial to the gRPC server at the given address (host:port) @@ -233,7 +263,8 @@ func (c *Client) Connect(addr string, params sobek.Value) (bool, error) { if !p.IsPlaintext { tlsCfg := state.TLSConfig.Clone() if len(p.TLS) > 0 { - if tlsCfg, err = buildTLSConfigFromMap(tlsCfg, p.TLS); err != nil { + tlsCfg, err = buildTLSConfigForConnect(tlsCfg, p.TLS, state) + if err != nil { return false, err } } diff --git a/internal/js/modules/k6/grpc/client_aia_test.go b/internal/js/modules/k6/grpc/client_aia_test.go new file mode 100644 index 000000000..a0102cf58 --- /dev/null +++ b/internal/js/modules/k6/grpc/client_aia_test.go @@ -0,0 +1,197 @@ +package grpc + +import ( + "context" + "crypto/tls" + "crypto/x509" + "encoding/pem" + "net" + "net/http" + "net/http/httptest" + "strings" + "testing" + "time" + + "github.com/sirupsen/logrus" + "github.com/stretchr/testify/require" + + "go.k6.io/k6/v2/internal/lib/testutils/tlstest" + "go.k6.io/k6/v2/lib/netext" +) + +// AIA verification must honour per-connect cacerts, not the VU config's RootCAs. +func TestBuildTLSConfig_AIAWithCustomCACerts(t *testing.T) { + t.Parallel() + + chain := tlstest.NewChain(t) + + aiaSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + w.Header().Set("Content-Type", "application/pkix-cert") + _, _ = w.Write(chain.IntermediateDER) + })) + t.Cleanup(aiaSrv.Close) + chain.SetAIAURL(aiaSrv.URL) + + tlsListener := newLeafOnlyTLSListener(t, chain) + t.Cleanup(func() { _ = tlsListener.Close() }) + + // VU config has no RootCAs — the user relies on per-connect cacerts. + vuCfg := &tls.Config{MinVersion: tls.VersionTLS12} + wrappedVU := netext.NewAIAFetcher(nil).Wrap(vuCfg, nullLogger()) + + rootPEM := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: chain.RootDER}) + tlsCfg, err := buildTLSConfig(wrappedVU, nil, nil, [][]byte{rootPEM}, netext.NewAIAFetcher(nil), false, nullLogger()) + require.NoError(t, err) + + tlsCfg.ServerName = "localhost" + + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + dialer := &tls.Dialer{Config: tlsCfg} + conn, err := dialer.DialContext(ctx, "tcp", tlsListener.Addr().String()) + require.NoError(t, err) + _ = conn.Close() +} + +func TestBuildTLSConfig_InsecureSkipVerifyIsHonoured(t *testing.T) { + t.Parallel() + + chain := tlstest.NewChain(t) + chain.SetAIAURL("http://127.0.0.1:1") // never reached; skip short-circuits + + tlsListener := newLeafOnlyTLSListener(t, chain) + t.Cleanup(func() { _ = tlsListener.Close() }) + + // Unrelated CA — verification would fail if it ran. + otherChain := tlstest.NewChain(t) + otherRootPEM := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: otherChain.RootDER}) + + for _, aiaEnabled := range []bool{false, true} { + name := "aia_off" + if aiaEnabled { + name = "aia_on" + } + t.Run(name, func(t *testing.T) { + t.Parallel() + + vuCfg := &tls.Config{ + MinVersion: tls.VersionTLS12, + InsecureSkipVerify: true, + } + parent := vuCfg + if aiaEnabled { + parent = netext.NewAIAFetcher(nil).Wrap(vuCfg, nullLogger()) + } + + var aiaFetcher *netext.AIAFetcher + if aiaEnabled { + aiaFetcher = netext.NewAIAFetcher(nil) + } + tlsCfg, err := buildTLSConfig(parent, nil, nil, [][]byte{otherRootPEM}, aiaFetcher, true, nullLogger()) + require.NoError(t, err) + require.True(t, tlsCfg.InsecureSkipVerify, "user asked to skip verification; must be honoured") + tlsCfg.ServerName = "localhost" + + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + dialer := &tls.Dialer{Config: tlsCfg} + conn, err := dialer.DialContext(ctx, "tcp", tlsListener.Addr().String()) + require.NoError(t, err, "handshake must succeed with insecureSkipTLSVerify even against a mismatched CA") + _ = conn.Close() + }) + } +} + +// Guard against silent insecurity: with AIA enabled and mismatched cacerts, the dial +// must fail — even though the AIA wrapper flips InsecureSkipVerify internally. +func TestBuildTLSConfig_AIARejectsMismatchedCACert(t *testing.T) { + t.Parallel() + + chain := tlstest.NewChain(t) + + aiaSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + w.Header().Set("Content-Type", "application/pkix-cert") + _, _ = w.Write(chain.IntermediateDER) + })) + t.Cleanup(aiaSrv.Close) + chain.SetAIAURL(aiaSrv.URL) + + tlsListener := newLeafOnlyTLSListener(t, chain) + t.Cleanup(func() { _ = tlsListener.Close() }) + + // Unrelated root — the caller supplies this as cacerts; the server presents a chain + // rooted in a different CA, so verification must fail. + otherChain := tlstest.NewChain(t) + otherRootPEM := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: otherChain.RootDER}) + + vuCfg := &tls.Config{MinVersion: tls.VersionTLS12} + wrappedVU := netext.NewAIAFetcher(nil).Wrap(vuCfg, nullLogger()) + + tlsCfg, err := buildTLSConfig(wrappedVU, nil, nil, [][]byte{otherRootPEM}, netext.NewAIAFetcher(nil), false, nullLogger()) + require.NoError(t, err) + tlsCfg.ServerName = "localhost" + + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + dialer := &tls.Dialer{Config: tlsCfg} + conn, err := dialer.DialContext(ctx, "tcp", tlsListener.Addr().String()) + if conn != nil { + _ = conn.Close() + } + require.Error(t, err, "AIA-enabled gRPC dial must fail when cacerts do not cover the server chain") + require.True(t, + strings.Contains(err.Error(), "unknown authority") || + strings.Contains(err.Error(), "signed by"), + "unexpected error: %v", err, + ) +} + +// newLeafOnlyTLSListener starts a raw tls.Listener serving only the leaf certificate. +func newLeafOnlyTLSListener(t testing.TB, c *tlstest.Chain) net.Listener { + t.Helper() + + leafCert, err := tls.X509KeyPair( + pemEncodeCert(c.LeafTLSCertificate(t).Certificate[0]), + pemEncodeKey(t, c), + ) + require.NoError(t, err) + + listener, err := tls.Listen("tcp", "127.0.0.1:0", &tls.Config{ + Certificates: []tls.Certificate{leafCert}, + MinVersion: tls.VersionTLS12, + }) + require.NoError(t, err) + + go func() { + for { + conn, acceptErr := listener.Accept() + if acceptErr != nil { + return + } + if tlsConn, ok := conn.(*tls.Conn); ok { + hctx, hcancel := context.WithTimeout(context.Background(), 5*time.Second) + _ = tlsConn.HandshakeContext(hctx) + hcancel() + } + _ = conn.Close() + } + }() + return listener +} + +func pemEncodeCert(der []byte) []byte { + return pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: der}) +} + +func pemEncodeKey(t testing.TB, c *tlstest.Chain) []byte { + t.Helper() + keyDER, err := x509.MarshalECPrivateKey(c.LeafKey) + require.NoError(t, err) + return pem.EncodeToMemory(&pem.Block{Type: "EC PRIVATE KEY", Bytes: keyDER}) +} + +func nullLogger() logrus.FieldLogger { + l := logrus.New() + l.SetLevel(logrus.PanicLevel) + return l +} diff --git a/internal/js/runner.go b/internal/js/runner.go index 4da79dbf6..db109f504 100644 --- a/internal/js/runner.go +++ b/internal/js/runner.go @@ -58,6 +58,9 @@ type Runner struct { RPSLimit *rate.Limiter RunTags *metrics.TagSet + // aiaFetcher owns the AIA cache + HTTP client when tlsAIAFetch is enabled. + aiaFetcher *netext.AIAFetcher + console *console setupData []byte BufferPool *lib.BufferPool @@ -194,6 +197,9 @@ func (r *Runner) newVU( }) tlsConfig.NameToCertificate = nameToCert //nolint:staticcheck } + if r.Bundle.Options.TLSAIAFetch.Bool { + tlsConfig = r.aiaFetcher.Wrap(tlsConfig, r.preInitState.Logger) //nolint:contextcheck + } transport := &http.Transport{ Proxy: http.ProxyFromEnvironment, TLSClientConfig: tlsConfig, @@ -579,6 +585,17 @@ func (r *Runner) SetOptions(opts lib.Options) error { return err } + // Rebuild the AIA fetcher against the new options — Blacklist / BlockedHostnames / + // Hosts / Resolver may have changed and the fetcher's dialer captures them. + runnerDialer := &netext.Dialer{ + Dialer: r.BaseDialer, + Resolver: r.Resolver, + Blacklist: opts.BlacklistIPs, + BlockedHostnames: opts.BlockedHostnames.Trie, + Hosts: opts.Hosts.Trie, + } + r.aiaFetcher = netext.NewAIAFetcher(runnerDialer.DialContext) + // FIXME: add tests r.RunTags = r.preInitState.Registry.RootTagSet().WithTagsFromMap(r.Bundle.Options.RunTags) diff --git a/internal/js/runner_aia_test.go b/internal/js/runner_aia_test.go new file mode 100644 index 000000000..040eaee3a --- /dev/null +++ b/internal/js/runner_aia_test.go @@ -0,0 +1,225 @@ +package js + +// Integration tests for AIA (Authority Information Access) certificate chain fetching. +// These tests exercise the full k6 stack: runner → VU → HTTP transport → TLS handshake. + +import ( + "crypto/rand" + "crypto/rsa" + "crypto/x509" + "crypto/x509/pkix" + "encoding/pem" + "fmt" + "math/big" + "net" + "net/http" + "net/http/httptest" + "sync" + "testing" + "time" + + logtest "github.com/sirupsen/logrus/hooks/test" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "gopkg.in/guregu/null.v3" + + "go.k6.io/k6/v2/lib" + "go.k6.io/k6/v2/metrics" +) + +// rsaIntermediateCA generates an intermediate CA certificate signed by parent. +// Unlike generateTLSCertificateWithCA, this sets IsCA=true so the resulting cert +// can sign other certificates (a plain leaf cert cannot act as an issuer). +func rsaIntermediateCA(t *testing.T, parent *x509.Certificate, parentKey *rsa.PrivateKey) ([]byte, *x509.Certificate, *rsa.PrivateKey) { + t.Helper() + + key, err := rsa.GenerateKey(rand.Reader, 2048) + require.NoError(t, err) + + sn, err := rand.Int(rand.Reader, new(big.Int).Lsh(big.NewInt(1), 128)) + require.NoError(t, err) + + tmpl := &x509.Certificate{ + SerialNumber: sn, + Subject: pkix.Name{CommonName: "Test Intermediate CA"}, + NotBefore: time.Now().Add(-time.Hour), + NotAfter: time.Now().Add(24 * time.Hour), + KeyUsage: x509.KeyUsageCertSign | x509.KeyUsageCRLSign, + BasicConstraintsValid: true, + IsCA: true, + SignatureAlgorithm: x509.SHA256WithRSA, + } + + der, err := x509.CreateCertificate(rand.Reader, tmpl, parent, &key.PublicKey, parentKey) + require.NoError(t, err) + + cert, err := x509.ParseCertificate(der) + require.NoError(t, err) + + certPEM := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: der}) + return certPEM, cert, key +} + +// rsaLeafWithAIA generates a leaf certificate signed by parent that advertises aiaURL +// in its Authority Information Access extension as the location of the issuer cert. +func rsaLeafWithAIA(t *testing.T, host string, parent *x509.Certificate, parentKey *rsa.PrivateKey, aiaURL string) ([]byte, []byte) { + t.Helper() + + key, err := rsa.GenerateKey(rand.Reader, 2048) + require.NoError(t, err) + + sn, err := rand.Int(rand.Reader, new(big.Int).Lsh(big.NewInt(1), 128)) + require.NoError(t, err) + + tmpl := &x509.Certificate{ + SerialNumber: sn, + Subject: pkix.Name{CommonName: host}, + NotBefore: time.Now().Add(-time.Hour), + NotAfter: time.Now().Add(24 * time.Hour), + KeyUsage: x509.KeyUsageDigitalSignature | x509.KeyUsageKeyEncipherment, + ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth}, + SignatureAlgorithm: x509.SHA256WithRSA, + IssuingCertificateURL: []string{aiaURL}, + } + if ip := net.ParseIP(host); ip != nil { + tmpl.IPAddresses = append(tmpl.IPAddresses, ip) + } else { + tmpl.DNSNames = append(tmpl.DNSNames, host) + } + + der, err := x509.CreateCertificate(rand.Reader, tmpl, parent, &key.PublicKey, parentKey) + require.NoError(t, err) + + certPEM := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: der}) + keyBytes, err := x509.MarshalPKCS8PrivateKey(key) + require.NoError(t, err) + keyPEM := pem.EncodeToMemory(&pem.Block{Type: "PRIVATE KEY", Bytes: keyBytes}) + return certPEM, keyPEM +} + +// TestVUIntegrationAIAFetching is a full end-to-end integration test: +// it runs k6 VUs against a TLS server that sends only a leaf certificate and +// requires AIA fetching to build the full chain to a trusted root. +// +// Two sub-tests verify the toggle behaviour: +// - AIAEnabled: tlsAIAFetch: true → connection succeeds +// - AIADisabled: default (off) → connection fails with x509 error +func TestVUIntegrationAIAFetching(t *testing.T) { + t.Parallel() + + // ── 1. Build a three-level certificate chain ──────────────────────────── + + // Root CA (self-signed, trusted by the test client) + rootCertPEM, rootKeyPEM := generateTLSCertificate(t, "127.0.0.1", time.Now(), time.Hour) + + rootBlock, _ := pem.Decode(rootCertPEM) + rootCert, err := x509.ParseCertificate(rootBlock.Bytes) + require.NoError(t, err) + + rootKeyBlock, _ := pem.Decode(rootKeyPEM) + rootKeyAny, err := x509.ParsePKCS8PrivateKey(rootKeyBlock.Bytes) + require.NoError(t, err) + rootKey, ok := rootKeyAny.(*rsa.PrivateKey) + require.True(t, ok) + + // ── 2. Start AIA server before building certs (we need its URL for the leaf) ── + + var ( + aiaMu sync.RWMutex + intermediarDER []byte + ) + aiaSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + aiaMu.RLock() + defer aiaMu.RUnlock() + w.Header().Set("Content-Type", "application/pkix-cert") + _, _ = w.Write(intermediarDER) + })) + t.Cleanup(aiaSrv.Close) + aiaURL := aiaSrv.URL + "/intermediate.der" + + // ── 3. Build intermediate CA and leaf with AIA URL ──────────────────────── + + _, interCert, interKey := rsaIntermediateCA(t, rootCert, rootKey) + + aiaMu.Lock() + intermediarDER = interCert.Raw // set before any request arrives + aiaMu.Unlock() + + // Use "localhost" so SNI carries a ServerName; Go strips IP literals from SNI + // and the AIA wrapper fails closed on empty ServerName. + leafCertPEM, leafKeyPEM := rsaLeafWithAIA(t, "localhost", interCert, interKey, aiaURL) + + // ── 4. Start TLS server that sends only the leaf (no intermediate chain) ── + + tlsSrv := getTestServerWithCertificate(t, leafCertPEM, leafKeyPEM) + go func() { _ = tlsSrv.Config.Serve(tlsSrv.Listener) }() + t.Cleanup(func() { require.NoError(t, tlsSrv.Config.Close()) }) + + _, port, err := net.SplitHostPort(tlsSrv.Listener.Addr().String()) + require.NoError(t, err) + serverAddr := "localhost:" + port + + rootPool := x509.NewCertPool() + rootPool.AddCert(rootCert) + + // ── 5. Table-driven sub-tests ───────────────────────────────────────────── + + testdata := map[string]struct { + aiaFetch null.Bool + errMsg string + }{ + // AIA fetching enabled: should build chain via AIA and succeed. + "AIAEnabled": {null.BoolFrom(true), ""}, + // AIA fetching disabled (default): incomplete chain, must fail. + "AIADisabled": {null.Bool{}, "certificate signed by unknown authority"}, + } + + for name, td := range testdata { + t.Run(name, func(t *testing.T) { + t.Parallel() + + script := fmt.Sprintf(` + var http = require("k6/http"); + exports.default = function() { http.get("https://%s/"); } + `, serverAddr) + + r1, err := getSimpleRunner(t, "/script.js", script) + require.NoError(t, err) + + opts := lib.Options{ + Throw: null.BoolFrom(true), + TLSAIAFetch: td.aiaFetch, + } + require.NoError(t, r1.SetOptions(opts)) + + r2, err := getSimpleArchiveRunner(t, r1.MakeArchive()) + require.NoError(t, err) + + runners := map[string]*Runner{"Source": r1, "Archive": r2} + for rname, r := range runners { + t.Run(rname, func(t *testing.T) { + t.Parallel() + r.preInitState.Logger, _ = logtest.NewNullLogger() + + ctx := t.Context() + initVU, err := r.NewVU(ctx, 1, 1, make(chan metrics.SampleContainer, 100)) + require.NoError(t, err) + + // Give the VU only the root CA – no intermediate. + // With AIA enabled, it should fetch the intermediate automatically. + initVU.(*VU).TLSConfig.RootCAs = rootPool + + vu := initVU.Activate(&lib.VUActivationParams{RunContext: ctx}) + runErr := vu.RunOnce() + + if td.errMsg != "" { + require.Error(t, runErr) + assert.Contains(t, runErr.Error(), td.errMsg) + } else { + require.NoError(t, runErr) + } + }) + } + }) + } +} diff --git a/internal/lib/testutils/tlstest/chain.go b/internal/lib/testutils/tlstest/chain.go new file mode 100644 index 000000000..b2caf917f --- /dev/null +++ b/internal/lib/testutils/tlstest/chain.go @@ -0,0 +1,160 @@ +// Package tlstest provides shared helpers for building root CA → intermediate → leaf +// chains used by AIA fetching tests. Test-only, do not import in production code. +package tlstest + +import ( + "crypto/ecdsa" + "crypto/elliptic" + "crypto/rand" + "crypto/tls" + "crypto/x509" + "crypto/x509/pkix" + "encoding/pem" + "math/big" + "net" + "net/http" + "sync" + "testing" + "time" + + "github.com/stretchr/testify/require" +) + +// Chain holds root CA → intermediate → leaf material. The leaf DER is generated on demand +// (LeafTLSCertificate) so callers can bake in an AIA URL first via SetAIAURL. +type Chain struct { + RootCert *x509.Certificate + RootDER []byte + RootKey *ecdsa.PrivateKey + IntermediateCert *x509.Certificate + IntermediateDER []byte + IntermediateKey *ecdsa.PrivateKey + LeafKey *ecdsa.PrivateKey + LeafTmpl *x509.Certificate + RootPool *x509.CertPool +} + +// NewChain builds a fresh root, intermediate and leaf template. Certificates use short +// (24h) lifetimes and P-256 keys. +func NewChain(t testing.TB) *Chain { + t.Helper() + + genKey := func() *ecdsa.PrivateKey { + k, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + require.NoError(t, err) + return k + } + serial := func() *big.Int { + n, err := rand.Int(rand.Reader, new(big.Int).Lsh(big.NewInt(1), 128)) + require.NoError(t, err) + return n + } + + rootKey := genKey() + rootTmpl := &x509.Certificate{ + SerialNumber: serial(), + Subject: pkix.Name{CommonName: "tlstest Root CA"}, + NotBefore: time.Now().Add(-time.Hour), + NotAfter: time.Now().Add(24 * time.Hour), + KeyUsage: x509.KeyUsageCertSign | x509.KeyUsageCRLSign, + BasicConstraintsValid: true, + IsCA: true, + } + rootDER, err := x509.CreateCertificate(rand.Reader, rootTmpl, rootTmpl, &rootKey.PublicKey, rootKey) + require.NoError(t, err) + rootCert, err := x509.ParseCertificate(rootDER) + require.NoError(t, err) + + interKey := genKey() + interTmpl := &x509.Certificate{ + SerialNumber: serial(), + Subject: pkix.Name{CommonName: "tlstest Intermediate CA"}, + NotBefore: time.Now().Add(-time.Hour), + NotAfter: time.Now().Add(24 * time.Hour), + KeyUsage: x509.KeyUsageCertSign | x509.KeyUsageCRLSign, + BasicConstraintsValid: true, + IsCA: true, + } + interDER, err := x509.CreateCertificate(rand.Reader, interTmpl, rootCert, &interKey.PublicKey, rootKey) + require.NoError(t, err) + interCert, err := x509.ParseCertificate(interDER) + require.NoError(t, err) + + leafKey := genKey() + leafTmpl := &x509.Certificate{ + SerialNumber: serial(), + Subject: pkix.Name{CommonName: "localhost"}, + NotBefore: time.Now().Add(-time.Hour), + NotAfter: time.Now().Add(24 * time.Hour), + KeyUsage: x509.KeyUsageDigitalSignature, + ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth}, + DNSNames: []string{"localhost"}, + IPAddresses: []net.IP{net.ParseIP("127.0.0.1")}, + } + + rootPool := x509.NewCertPool() + rootPool.AddCert(rootCert) + + return &Chain{ + RootCert: rootCert, + RootDER: rootDER, + RootKey: rootKey, + IntermediateCert: interCert, + IntermediateDER: interDER, + IntermediateKey: interKey, + LeafKey: leafKey, + LeafTmpl: leafTmpl, + RootPool: rootPool, + } +} + +// SetAIAURL sets the leaf's IssuingCertificateURL. Call before LeafTLSCertificate. +func (c *Chain) SetAIAURL(aiaURL string) { + c.LeafTmpl.IssuingCertificateURL = []string{aiaURL} +} + +// LeafTLSCertificate returns a tls.Certificate containing only the leaf (no intermediate). +func (c *Chain) LeafTLSCertificate(t testing.TB) tls.Certificate { + t.Helper() + leafDER, err := x509.CreateCertificate( + rand.Reader, c.LeafTmpl, c.IntermediateCert, &c.LeafKey.PublicKey, c.IntermediateKey, + ) + require.NoError(t, err) + leafKeyDER, err := x509.MarshalECPrivateKey(c.LeafKey) + require.NoError(t, err) + cert, err := tls.X509KeyPair( + pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: leafDER}), + pem.EncodeToMemory(&pem.Block{Type: "EC PRIVATE KEY", Bytes: leafKeyDER}), + ) + require.NoError(t, err) + return cert +} + +// FullChainTLSCertificate returns leaf + intermediate DER. +func (c *Chain) FullChainTLSCertificate(t testing.TB) tls.Certificate { + t.Helper() + cert := c.LeafTLSCertificate(t) + cert.Certificate = append(cert.Certificate, c.IntermediateCert.Raw) + return cert +} + +// AIAHandler serves the DER bytes set via SetCert with an application/pkix-cert Content-Type. +type AIAHandler struct { + mu sync.RWMutex + certDER []byte +} + +// SetCert atomically updates the DER bytes served by subsequent requests. +func (h *AIAHandler) SetCert(der []byte) { + h.mu.Lock() + h.certDER = der + h.mu.Unlock() +} + +// ServeHTTP writes the currently-set DER bytes as an AIA response. +func (h *AIAHandler) ServeHTTP(w http.ResponseWriter, _ *http.Request) { + h.mu.RLock() + defer h.mu.RUnlock() + w.Header().Set("Content-Type", "application/pkix-cert") + _, _ = w.Write(h.certDER) +} diff --git a/lib/netext/aia.go b/lib/netext/aia.go new file mode 100644 index 000000000..fb632cbf6 --- /dev/null +++ b/lib/netext/aia.go @@ -0,0 +1,327 @@ +package netext + +import ( + "bytes" + "context" + "crypto/tls" + "crypto/x509" + "encoding/pem" + "errors" + "fmt" + "io" + "net" + "net/http" + "strings" + "sync" + "time" + + "github.com/sirupsen/logrus" + "golang.org/x/sync/singleflight" +) + +const ( + aiaFetchTimeout = 10 * time.Second + aiaMaxCertSize = 64 * 1024 + aiaMaxFetchDepth = 5 + aiaCacheEntryTTL = 24 * time.Hour +) + +var ( + systemCertPoolOnce sync.Once //nolint:gochecknoglobals + cachedSystemPool *x509.CertPool //nolint:gochecknoglobals +) + +type aiaCacheEntry struct { + cert *x509.Certificate + storedAt time.Time +} + +// DialContextFunc matches net.Dialer.DialContext / lib.DialContexter.DialContext. +type DialContextFunc func(ctx context.Context, network, addr string) (net.Conn, error) + +// AIAFetcher fetches missing intermediate certificates via AIA. One instance per Runner +// keeps the cache and singleflight group isolated across in-process test runs. +type AIAFetcher struct { + httpClient *http.Client + cache sync.Map + fetchGroup singleflight.Group +} + +// NewAIAFetcher binds the fetcher's HTTP client to dial so AIA fetches respect the +// caller's blocking lists, host overrides and resolver. Nil dial uses net's default — +// intended for tests only. +func NewAIAFetcher(dial DialContextFunc) *AIAFetcher { + return &AIAFetcher{ + httpClient: &http.Client{ + Timeout: aiaFetchTimeout, + Transport: &http.Transport{ + Proxy: http.ProxyFromEnvironment, + DialContext: dial, + }, + }, + } +} + +// Wrap returns a *tls.Config whose verification callbacks fetch missing intermediates +// via AIA when the server presents an incomplete chain. Returned unchanged when +// InsecureSkipVerify is already set. +func (f *AIAFetcher) Wrap(cfg *tls.Config, logger logrus.FieldLogger) *tls.Config { + if cfg.InsecureSkipVerify { + return cfg + } + + newCfg := cfg.Clone() + + // Suppresses Go's built-in verification so we can interpose AIA fetching; + // hostname verification is restored in buildVerifyConnFn. + newCfg.InsecureSkipVerify = true + + // Callbacks read newCfg.RootCAs at handshake time (not capture-at-wrap-time) so + // callers can modify RootCAs after wrapping and have the change take effect. + newCfg.VerifyPeerCertificate = f.buildVerifyPeerFn(newCfg, logger) + newCfg.VerifyConnection = buildVerifyConnFn() + return newCfg +} + +// Returns nil on failure so x509.VerifyOptions falls through to Go's default system-pool +// handling, rather than substituting an empty pool that guarantees verification failure. +func getSystemCertPool(logger logrus.FieldLogger) *x509.CertPool { + systemCertPoolOnce.Do(func() { + pool, err := x509.SystemCertPool() + if err != nil { + logger.WithError(err).Debug("AIA: failed to load system cert pool") + return + } + cachedSystemPool = pool + }) + return cachedSystemPool +} + +func (f *AIAFetcher) buildVerifyPeerFn( + cfg *tls.Config, + logger logrus.FieldLogger, +) func([][]byte, [][]*x509.Certificate) error { + return func(rawCerts [][]byte, _ [][]*x509.Certificate) error { + if len(rawCerts) == 0 { + return errors.New("tls: server presented no certificates") + } + + certs := make([]*x509.Certificate, 0, len(rawCerts)) + for _, raw := range rawCerts { + cert, err := x509.ParseCertificate(raw) + if err != nil { + return fmt.Errorf("tls: failed to parse server certificate: %w", err) + } + certs = append(certs, cert) + } + + intermediates := x509.NewCertPool() + for _, c := range certs[1:] { + intermediates.AddCert(c) + } + + roots := cfg.RootCAs + if roots == nil { + roots = getSystemCertPool(logger) + } + + opts := x509.VerifyOptions{ + Roots: roots, + Intermediates: intermediates, + // Hostname verification runs in buildVerifyConnFn where cs.ServerName is available. + } + + return f.verifyWithAIA(certs, opts, intermediates, logger) + } +} + +func (f *AIAFetcher) verifyWithAIA( + certs []*x509.Certificate, + opts x509.VerifyOptions, + intermediates *x509.CertPool, + logger logrus.FieldLogger, +) error { + _, verifyErr := certs[0].Verify(opts) + if verifyErr == nil { + return nil + } + + // Only unknown-authority errors are AIA-fixable; expired, hostname mismatch, etc. aren't. + var unknownAuthErr x509.UnknownAuthorityError + if !errors.As(verifyErr, &unknownAuthErr) { + return verifyErr + } + + hasAIAURLs := false + for _, c := range certs { + if len(c.IssuingCertificateURL) > 0 { + hasAIAURLs = true + break + } + } + + for _, cert := range f.fetchAIAIntermediates(certs, logger) { + intermediates.AddCert(cert) + } + + _, retryErr := certs[0].Verify(opts) + if retryErr == nil { + return nil + } + if hasAIAURLs { + logger.WithError(retryErr).Warn( + "AIA: certificate chain incomplete after fetching intermediates; " + + "verify that the AIA endpoint is reachable and returns a valid certificate", + ) + } + return retryErr +} + +func buildVerifyConnFn() func(tls.ConnectionState) error { + return func(cs tls.ConnectionState) error { + // Empty ServerName = IP-literal target (Go strips IPs from SNI). We've disabled + // stdlib chain-and-hostname verification to interpose AIA, so fail closed rather + // than accept any valid chain. + if cs.ServerName == "" { + return errors.New( + "tlsAIAFetch: cannot verify hostname for IP-literal target " + + "(SNI is not sent for IP addresses); use a hostname, or disable tlsAIAFetch") + } + return cs.PeerCertificates[0].VerifyHostname(cs.ServerName) + } +} + +// The depth limit bounds HTTP fetches, not queue pops — cached items keep flowing even +// after we stop issuing new fetches. +func (f *AIAFetcher) fetchAIAIntermediates( + certs []*x509.Certificate, logger logrus.FieldLogger, +) []*x509.Certificate { + var fetched []*x509.Certificate + seen := make(map[string]bool) + fetches := 0 + + queue := make([]*x509.Certificate, 0, len(certs)) + queue = append(queue, certs...) + + for len(queue) > 0 { + cert := queue[0] + queue = queue[1:] + + for _, rawURL := range cert.IssuingCertificateURL { + if seen[rawURL] { + continue + } + seen[rawURL] = true + + issuer, ok := f.loadCachedAIACert(rawURL) + if !ok { + if fetches >= aiaMaxFetchDepth { + continue + } + fetches++ + var err error + issuer, err = f.fetchAndCacheAIACert(rawURL, logger) + if err != nil { + logger.WithError(err).WithField("url", rawURL).Debug("AIA intermediate certificate fetch failed") + continue + } + } + + fetched = append(fetched, issuer) + queue = append(queue, issuer) + } + } + + return fetched +} + +func (f *AIAFetcher) loadCachedAIACert(rawURL string) (*x509.Certificate, bool) { + raw, ok := f.cache.Load(rawURL) + if !ok { + return nil, false + } + entry := raw.(*aiaCacheEntry) //nolint:forcetypeassert + // Evict on TTL expiry or when the cert itself is past NotAfter — an expired + // intermediate won't validate anyway, and holding it would just waste retries. + if time.Since(entry.storedAt) > aiaCacheEntryTTL || time.Now().After(entry.cert.NotAfter) { + f.cache.Delete(rawURL) + return nil, false + } + return entry.cert, true +} + +func (f *AIAFetcher) fetchAndCacheAIACert( + rawURL string, logger logrus.FieldLogger, +) (*x509.Certificate, error) { + v, err, _ := f.fetchGroup.Do(rawURL, func() (any, error) { + // Re-check under the singleflight barrier: an earlier waiter may have populated it. + if cert, ok := f.loadCachedAIACert(rawURL); ok { + return cert, nil + } + cert, err := f.fetchCertFromAIAURL(rawURL, logger) + if err != nil { + return nil, err + } + f.cache.Store(rawURL, &aiaCacheEntry{cert: cert, storedAt: time.Now()}) + return cert, nil + }) + if err != nil { + return nil, err + } + return v.(*x509.Certificate), nil //nolint:forcetypeassert +} + +func (f *AIAFetcher) fetchCertFromAIAURL( + rawURL string, logger logrus.FieldLogger, +) (*x509.Certificate, error) { + // VerifyPeerCertificate provides no context to thread through; use our own timeout. + ctx, cancel := context.WithTimeout(context.Background(), aiaFetchTimeout) + defer cancel() + + req, err := http.NewRequestWithContext(ctx, http.MethodGet, rawURL, nil) + if err != nil { + return nil, fmt.Errorf("building AIA request: %w", err) + } + + resp, err := f.httpClient.Do(req) //nolint:gosec // G107: URL is from a server-presented cert AIA extension + if err != nil { + return nil, fmt.Errorf("fetching AIA certificate: %w", err) + } + defer resp.Body.Close() //nolint:errcheck + + if resp.StatusCode != http.StatusOK { + return nil, fmt.Errorf("AIA endpoint returned HTTP %d", resp.StatusCode) + } + + body, err := io.ReadAll(io.LimitReader(resp.Body, aiaMaxCertSize)) + if err != nil { + return nil, fmt.Errorf("reading AIA response: %w", err) + } + + if cert, parseErr := x509.ParseCertificate(body); parseErr == nil { + return cert, nil + } + + block, _ := pem.Decode(body) + if block == nil { + if isLikelyPKCS7(resp.Header.Get("Content-Type"), body) { + logger.WithField("url", rawURL).WithField("content-type", resp.Header.Get("Content-Type")). + Warn("AIA response is PKCS#7 (not currently supported); chain will remain incomplete") + } + return nil, errors.New("AIA response is neither valid DER nor PEM") + } + cert, err := x509.ParseCertificate(block.Bytes) + if err != nil { + return nil, fmt.Errorf("parsing PEM certificate from AIA response: %w", err) + } + return cert, nil +} + +func isLikelyPKCS7(contentType string, body []byte) bool { + ct := strings.ToLower(contentType) + if strings.Contains(ct, "pkcs7") || strings.Contains(ct, "pkcs-7") { + return true + } + // ASN.1 encoding of OID 1.2.840.113549.1.7.2 (id-signedData). + return bytes.Contains(body, []byte{0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x02}) +} diff --git a/lib/netext/aia_test.go b/lib/netext/aia_test.go new file mode 100644 index 000000000..f6b85a7c9 --- /dev/null +++ b/lib/netext/aia_test.go @@ -0,0 +1,535 @@ +package netext + +import ( + "context" + "crypto/ecdsa" + "crypto/elliptic" + "crypto/rand" + "crypto/tls" + "crypto/x509" + "crypto/x509/pkix" + "errors" + "fmt" + "math/big" + "net" + "net/http" + "net/http/httptest" + "strings" + "sync/atomic" + "testing" + "time" + + "github.com/sirupsen/logrus" + logtest "github.com/sirupsen/logrus/hooks/test" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "go.k6.io/k6/v2/internal/lib/testutils/tlstest" +) + +func buildChainWithAIA(t testing.TB, aiaURL string) *tlstest.Chain { + t.Helper() + c := tlstest.NewChain(t) + c.SetAIAURL(aiaURL) + return c +} + +// leafOnlyTLSServer serves only the leaf certificate — clients that need the intermediate +// see an incomplete chain. +func leafOnlyTLSServer(t testing.TB, c *tlstest.Chain) *httptest.Server { + t.Helper() + srv := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + _, _ = fmt.Fprintln(w, "ok") + })) + srv.TLS = &tls.Config{Certificates: []tls.Certificate{c.LeafTLSCertificate(t)}} + srv.StartTLS() + t.Cleanup(srv.Close) + return srv +} + +// Rewrites 127.0.0.1 → localhost so the wrapper sees a non-empty ServerName (Go strips +// IPs from SNI, and the wrapper fails closed on empty). The test chain's leaf has +// "localhost" as a DNS SAN. +func leafOnlyTLSServerURL(srv *httptest.Server) string { + return strings.Replace(srv.URL, "127.0.0.1", "localhost", 1) +} + +func startAIAServer(t testing.TB, h http.Handler) *httptest.Server { + t.Helper() + srv := httptest.NewServer(h) + t.Cleanup(srv.Close) + return srv +} + +func testHTTPClient(t testing.TB, tlsCfg *tls.Config) *http.Client { + t.Helper() + return &http.Client{Transport: &http.Transport{TLSClientConfig: tlsCfg}} +} + +func nullLogger() logrus.FieldLogger { + l := logrus.New() + l.SetOutput(nil) + l.SetLevel(logrus.PanicLevel) + return l +} + +func closeBody(resp *http.Response) { + if resp != nil { + _ = resp.Body.Close() + } +} + +func TestWrapTLSConfigForAIAFetching_HappyPath(t *testing.T) { + t.Parallel() + + h := &tlstest.AIAHandler{} + aiaSrv := startAIAServer(t, h) + chain := buildChainWithAIA(t, aiaSrv.URL+"/ca.der") + h.SetCert(chain.IntermediateDER) + + tlsSrv := leafOnlyTLSServer(t, chain) + + wrappedCfg := NewAIAFetcher(nil).Wrap(&tls.Config{RootCAs: chain.RootPool}, nullLogger()) + resp, err := testHTTPClient(t, wrappedCfg).Get(leafOnlyTLSServerURL(tlsSrv)) //nolint:noctx + require.NoError(t, err, "AIA fetching should resolve the incomplete chain") + _ = resp.Body.Close() +} + +func TestWrapTLSConfigForAIAFetching_CompleteChainPassesThrough(t *testing.T) { + t.Parallel() + + h := &tlstest.AIAHandler{} + aiaSrv := startAIAServer(t, h) + chain := buildChainWithAIA(t, aiaSrv.URL+"/ca.der") + h.SetCert(chain.IntermediateDER) + + srv := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + _, _ = fmt.Fprintln(w, "ok") + })) + srv.TLS = &tls.Config{Certificates: []tls.Certificate{chain.FullChainTLSCertificate(t)}} + srv.StartTLS() + t.Cleanup(srv.Close) + + wrappedCfg := NewAIAFetcher(nil).Wrap(&tls.Config{RootCAs: chain.RootPool}, nullLogger()) + resp, err := testHTTPClient(t, wrappedCfg).Get(strings.Replace(srv.URL, "127.0.0.1", "localhost", 1)) //nolint:noctx + require.NoError(t, err, "complete chain should succeed without any AIA fetch") + _ = resp.Body.Close() +} + +func TestWrapTLSConfigForAIAFetching_Disabled(t *testing.T) { + t.Parallel() + + h := &tlstest.AIAHandler{} + aiaSrv := startAIAServer(t, h) + chain := buildChainWithAIA(t, aiaSrv.URL+"/ca.der") + h.SetCert(chain.IntermediateDER) + + tlsSrv := leafOnlyTLSServer(t, chain) + + plainCfg := &tls.Config{RootCAs: chain.RootPool} + resp, err := testHTTPClient(t, plainCfg).Get(tlsSrv.URL) //nolint:noctx + closeBody(resp) + require.Error(t, err) + assert.Contains(t, err.Error(), "certificate signed by unknown authority", + "without AIA fetching the incomplete chain must be rejected") +} + +func TestWrapTLSConfigForAIAFetching_InsecureSkipVerifyUnchanged(t *testing.T) { + t.Parallel() + + cfg := &tls.Config{InsecureSkipVerify: true} + result := NewAIAFetcher(nil).Wrap(cfg, nullLogger()) + assert.Same(t, cfg, result, "wrapper must return the original config when InsecureSkipVerify is set") +} + +func TestWrapTLSConfigForAIAFetching_UnreachableAIAURL(t *testing.T) { + t.Parallel() + + // Grab a free port then close it — connections will be refused. + ln, err := net.Listen("tcp", "127.0.0.1:0") //nolint:noctx + require.NoError(t, err) + port := ln.Addr().(*net.TCPAddr).Port + require.NoError(t, ln.Close()) + + aiaURL := fmt.Sprintf("http://127.0.0.1:%d/ca.der", port) + chain := buildChainWithAIA(t, aiaURL) + tlsSrv := leafOnlyTLSServer(t, chain) + + fastClient := &http.Client{Timeout: 500 * time.Millisecond} + wrappedCfg := (&AIAFetcher{httpClient: fastClient}).Wrap( + &tls.Config{RootCAs: chain.RootPool}, + nullLogger(), + ) + + resp, err := testHTTPClient(t, wrappedCfg).Get(tlsSrv.URL) //nolint:noctx + closeBody(resp) + require.Error(t, err) + assert.Contains(t, err.Error(), "certificate signed by unknown authority", + "should fall back to the original x509 error when AIA URL is unreachable") +} + +func TestWrapTLSConfigForAIAFetching_FetchTimeout(t *testing.T) { + t.Parallel() + + // Accept the request but never respond — simulates a stalled AIA endpoint. + hangSrv := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) { + <-r.Context().Done() + })) + t.Cleanup(hangSrv.Close) + + chain := buildChainWithAIA(t, hangSrv.URL+"/ca.der") + tlsSrv := leafOnlyTLSServer(t, chain) + + const shortTimeout = 100 * time.Millisecond + fastClient := &http.Client{Timeout: shortTimeout} + wrappedCfg := (&AIAFetcher{httpClient: fastClient}).Wrap( + &tls.Config{RootCAs: chain.RootPool}, + nullLogger(), + ) + + start := time.Now() + resp, err := testHTTPClient(t, wrappedCfg).Get(tlsSrv.URL) //nolint:noctx + elapsed := time.Since(start) + closeBody(resp) + + require.Error(t, err) + assert.Less(t, elapsed, 5*shortTimeout, + "AIA fetch should time out quickly, not block for the full aiaFetchTimeout") + assert.Contains(t, err.Error(), "certificate signed by unknown authority", + "should report the original certificate error after the AIA timeout") +} + +func TestWrapTLSConfigForAIAFetching_AIAReturnsHTTPError(t *testing.T) { + t.Parallel() + + errSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + http.Error(w, "not here", http.StatusServiceUnavailable) + })) + t.Cleanup(errSrv.Close) + + chain := buildChainWithAIA(t, errSrv.URL+"/ca.der") + tlsSrv := leafOnlyTLSServer(t, chain) + + wrappedCfg := NewAIAFetcher(nil).Wrap(&tls.Config{RootCAs: chain.RootPool}, nullLogger()) + + resp, err := testHTTPClient(t, wrappedCfg).Get(tlsSrv.URL) //nolint:noctx + closeBody(resp) + require.Error(t, err) + assert.Contains(t, err.Error(), "certificate signed by unknown authority") +} + +func TestWrapTLSConfigForAIAFetching_MalformedAIACert(t *testing.T) { + t.Parallel() + + garbageSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + w.Header().Set("Content-Type", "application/pkix-cert") + _, _ = fmt.Fprint(w, "this is not a certificate") + })) + t.Cleanup(garbageSrv.Close) + + chain := buildChainWithAIA(t, garbageSrv.URL+"/ca.der") + tlsSrv := leafOnlyTLSServer(t, chain) + + wrappedCfg := NewAIAFetcher(nil).Wrap(&tls.Config{RootCAs: chain.RootPool}, nullLogger()) + + resp, err := testHTTPClient(t, wrappedCfg).Get(tlsSrv.URL) //nolint:noctx + closeBody(resp) + require.Error(t, err) + assert.Contains(t, err.Error(), "certificate signed by unknown authority", + "malformed AIA certificate should be silently ignored; original error is returned") +} + +func TestFetchCertFromAIAURL_PKCS7ResponseLogsWarn(t *testing.T) { + t.Parallel() + + // Body embeds the ASN.1 signedData OID so the heuristic fires without relying on Content-Type. + pkcs7Body := append([]byte{0x30, 0x82, 0x00, 0x00}, []byte{0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x02}...) + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + w.Header().Set("Content-Type", "application/pkcs7-mime") + _, _ = w.Write(pkcs7Body) + })) + t.Cleanup(srv.Close) + + logger, hook := logtest.NewNullLogger() + logger.SetLevel(logrus.WarnLevel) + + cert, err := NewAIAFetcher(nil).fetchCertFromAIAURL(srv.URL, logger) + require.Error(t, err) + assert.Nil(t, cert) + + var warned bool + for _, entry := range hook.AllEntries() { + if entry.Level == logrus.WarnLevel && strings.Contains(entry.Message, "PKCS#7") { + warned = true + break + } + } + assert.True(t, warned, "expected a Warn log about PKCS#7 not being supported") +} + +func TestWrapTLSConfigForAIAFetching_CircularAIAReferences(t *testing.T) { + t.Parallel() + + // Cycle: leaf → fetch decoy from server → decoy AIA points to same server → seen-map stops it. + h := &tlstest.AIAHandler{} + circularSrv := startAIAServer(t, h) + circularURL := circularSrv.URL + "/ca.der" + chain := buildChainWithAIA(t, circularURL) + + decoyKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + require.NoError(t, err) + decoySN, err := rand.Int(rand.Reader, new(big.Int).Lsh(big.NewInt(1), 128)) + require.NoError(t, err) + decoyTmpl := &x509.Certificate{ + SerialNumber: decoySN, + Subject: pkix.Name{CommonName: "Circular Decoy"}, + NotBefore: time.Now().Add(-time.Hour), + NotAfter: time.Now().Add(time.Hour), + IssuingCertificateURL: []string{circularURL}, // points back to itself + } + decoyDER, err := x509.CreateCertificate(rand.Reader, decoyTmpl, decoyTmpl, &decoyKey.PublicKey, decoyKey) + require.NoError(t, err) + h.SetCert(decoyDER) // AIA server serves the decoy (not the real intermediate) + + tlsSrv := leafOnlyTLSServer(t, chain) + + fastClient := &http.Client{Timeout: 2 * time.Second} + wrappedCfg := (&AIAFetcher{httpClient: fastClient}).Wrap( + &tls.Config{RootCAs: chain.RootPool}, + nullLogger(), + ) + + start := time.Now() + resp, err := testHTTPClient(t, wrappedCfg).Get(tlsSrv.URL) //nolint:noctx + elapsed := time.Since(start) + closeBody(resp) + + require.Error(t, err, "circular AIA chain must not succeed") + assert.Less(t, elapsed, 10*time.Second, "circular reference must terminate, not loop") + assert.Contains(t, err.Error(), "certificate signed by unknown authority") +} + +// AIA fetches must go through the dialer passed to NewAIAFetcher — a dialer that always +// errors makes the AIA fetch fail, leaving the chain incomplete. +func TestAIAFetcher_UsesProvidedDialer(t *testing.T) { + t.Parallel() + + h := &tlstest.AIAHandler{} + aiaSrv := startAIAServer(t, h) + chain := buildChainWithAIA(t, aiaSrv.URL+"/ca.der") + h.SetCert(chain.IntermediateDER) + + tlsSrv := leafOnlyTLSServer(t, chain) + + var dialCount int + failingDial := func(_ context.Context, _, _ string) (net.Conn, error) { + dialCount++ + return nil, errors.New("dial refused by test") + } + + wrappedCfg := NewAIAFetcher(failingDial).Wrap( + &tls.Config{RootCAs: chain.RootPool}, + nullLogger(), + ) + resp, err := testHTTPClient(t, wrappedCfg).Get(tlsSrv.URL) //nolint:noctx + closeBody(resp) + require.Error(t, err, "AIA fetch must use the provided dialer; when it fails, chain verification fails") + assert.Contains(t, err.Error(), "certificate signed by unknown authority") + assert.Positive(t, dialCount, "expected the provided dialer to be called for the AIA fetch") +} + +// Two fetchers must not share cache or singleflight state — one Runner's AIA state +// must not leak into another Runner running in the same process. +func TestAIAFetcher_CacheIsolatedBetweenFetchers(t *testing.T) { + t.Parallel() + + var aiaHits int32 + handler := &tlstest.AIAHandler{} + aiaSrv := startAIAServer(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + atomic.AddInt32(&aiaHits, 1) + handler.ServeHTTP(w, r) + })) + chain := buildChainWithAIA(t, aiaSrv.URL+"/ca.der") + handler.SetCert(chain.IntermediateDER) + + tlsSrv := leafOnlyTLSServer(t, chain) + + fetcherA := NewAIAFetcher(nil) + fetcherB := NewAIAFetcher(nil) + + // Fetcher A warms its cache. + respA, errA := testHTTPClient(t, fetcherA.Wrap(&tls.Config{RootCAs: chain.RootPool}, nullLogger())).Get(leafOnlyTLSServerURL(tlsSrv)) //nolint:noctx + require.NoError(t, errA) + _ = respA.Body.Close() + hitsAfterA := atomic.LoadInt32(&aiaHits) + require.Equal(t, int32(1), hitsAfterA, "fetcher A should have fetched once") + + // Fetcher B, independently, must hit the AIA server again — no shared cache. + respB, errB := testHTTPClient(t, fetcherB.Wrap(&tls.Config{RootCAs: chain.RootPool}, nullLogger())).Get(leafOnlyTLSServerURL(tlsSrv)) //nolint:noctx + require.NoError(t, errB) + _ = respB.Body.Close() + hitsAfterB := atomic.LoadInt32(&aiaHits) + assert.Equal(t, int32(2), hitsAfterB, "fetcher B must fetch independently; caches are not shared across fetchers") +} + +func TestWrapTLSConfigForAIAFetching_HostnameMismatchRejected(t *testing.T) { + t.Parallel() + + h := &tlstest.AIAHandler{} + aiaSrv := startAIAServer(t, h) + chain := buildChainWithAIA(t, aiaSrv.URL+"/ca.der") + h.SetCert(chain.IntermediateDER) + + tlsSrv := leafOnlyTLSServer(t, chain) + + wrappedCfg := NewAIAFetcher(nil).Wrap( + &tls.Config{ + RootCAs: chain.RootPool, + ServerName: "wrong.example.com", // deliberately wrong + }, + nullLogger(), + ) + + resp, err := testHTTPClient(t, wrappedCfg).Get(tlsSrv.URL) //nolint:noctx + closeBody(resp) + require.Error(t, err, "wrong hostname must be rejected even after AIA succeeds") +} + +// IP-literal targets have empty ServerName (SNI drops IPs). Since we've disabled stdlib +// hostname verification to interpose AIA, the wrapper must fail closed. +func TestWrapTLSConfigForAIAFetching_IPLiteralTargetRejected(t *testing.T) { + t.Parallel() + + h := &tlstest.AIAHandler{} + aiaSrv := startAIAServer(t, h) + chain := buildChainWithAIA(t, aiaSrv.URL+"/ca.der") + h.SetCert(chain.IntermediateDER) + + tlsSrv := leafOnlyTLSServer(t, chain) + + // httptest URLs use 127.0.0.1; Go strips IPs from SNI so ServerName is "". + wrappedCfg := NewAIAFetcher(nil).Wrap( + &tls.Config{RootCAs: chain.RootPool}, + nullLogger(), + ) + + resp, err := testHTTPClient(t, wrappedCfg).Get(tlsSrv.URL) //nolint:noctx + closeBody(resp) + require.Error(t, err, "IP-literal target must be rejected when tlsAIAFetch is enabled") + assert.Contains(t, err.Error(), "IP-literal target") +} + +// newBenchClient forces a fresh TCP+TLS handshake per request (no keep-alive, no session tickets). +func newBenchClient(tlsCfg *tls.Config) *http.Client { + cfg := tlsCfg.Clone() + cfg.SessionTicketsDisabled = true + return &http.Client{ + Transport: &http.Transport{ + TLSClientConfig: cfg, + DisableKeepAlives: true, + }, + } +} + +// BenchmarkTLSHandshake_Baseline: complete chain, no AIA wrapper — cost floor. +func BenchmarkTLSHandshake_Baseline(b *testing.B) { + h := &tlstest.AIAHandler{} + aiaSrv := startAIAServer(b, h) + chain := buildChainWithAIA(b, aiaSrv.URL+"/ca.der") + h.SetCert(chain.IntermediateDER) + + srv := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + _, _ = fmt.Fprintln(w, "ok") + })) + srv.TLS = &tls.Config{Certificates: []tls.Certificate{chain.FullChainTLSCertificate(b)}} + srv.StartTLS() + b.Cleanup(srv.Close) + + client := newBenchClient(&tls.Config{RootCAs: chain.RootPool}) + + b.ResetTimer() + for b.Loop() { + resp, err := client.Get(srv.URL) //nolint:noctx + require.NoError(b, err) + _ = resp.Body.Close() + } +} + +// BenchmarkTLSHandshake_AIANotNeeded: AIA wrapper active, but server sends full chain so +// no HTTP fetch is triggered. +func BenchmarkTLSHandshake_AIANotNeeded(b *testing.B) { + h := &tlstest.AIAHandler{} + aiaSrv := startAIAServer(b, h) + chain := buildChainWithAIA(b, aiaSrv.URL+"/ca.der") + h.SetCert(chain.IntermediateDER) + + srv := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + _, _ = fmt.Fprintln(w, "ok") + })) + srv.TLS = &tls.Config{Certificates: []tls.Certificate{chain.FullChainTLSCertificate(b)}} + srv.StartTLS() + b.Cleanup(srv.Close) + + wrappedCfg := NewAIAFetcher(nil).Wrap(&tls.Config{RootCAs: chain.RootPool}, nullLogger()) + client := newBenchClient(wrappedCfg) + + b.ResetTimer() + for b.Loop() { + resp, err := client.Get(srv.URL) //nolint:noctx + require.NoError(b, err) + _ = resp.Body.Close() + } +} + +// BenchmarkTLSHandshake_AIAWarmCache: steady-state cost when the intermediate is cached. +func BenchmarkTLSHandshake_AIAWarmCache(b *testing.B) { + h := &tlstest.AIAHandler{} + aiaSrv := startAIAServer(b, h) + aiaURL := aiaSrv.URL + "/ca.der" + chain := buildChainWithAIA(b, aiaURL) + h.SetCert(chain.IntermediateDER) + + tlsSrv := leafOnlyTLSServer(b, chain) + + wrappedCfg := NewAIAFetcher(nil).Wrap(&tls.Config{RootCAs: chain.RootPool}, nullLogger()) + + // Prime the cache with one request before timing starts. + primer := newBenchClient(wrappedCfg) + resp, err := primer.Get(tlsSrv.URL) //nolint:noctx + require.NoError(b, err) + _ = resp.Body.Close() + + client := newBenchClient(wrappedCfg) + + b.ResetTimer() + for b.Loop() { + resp, err := client.Get(tlsSrv.URL) //nolint:noctx + require.NoError(b, err) + _ = resp.Body.Close() + } +} + +// BenchmarkTLSHandshake_AIAColdCache: worst-case, every handshake triggers an AIA fetch. +func BenchmarkTLSHandshake_AIAColdCache(b *testing.B) { + h := &tlstest.AIAHandler{} + aiaSrv := startAIAServer(b, h) + aiaURL := aiaSrv.URL + "/ca.der" + chain := buildChainWithAIA(b, aiaURL) + h.SetCert(chain.IntermediateDER) + + tlsSrv := leafOnlyTLSServer(b, chain) + + fetcher := NewAIAFetcher(nil) + wrappedCfg := fetcher.Wrap(&tls.Config{RootCAs: chain.RootPool}, nullLogger()) + + client := newBenchClient(wrappedCfg) + + b.ResetTimer() + for b.Loop() { + fetcher.cache.Delete(aiaURL) // force a cold fetch on every iteration + + resp, err := client.Get(tlsSrv.URL) //nolint:noctx + require.NoError(b, err) + _ = resp.Body.Close() + } +} diff --git a/lib/options.go b/lib/options.go index 2f33a9ec8..5e9e2dad4 100644 --- a/lib/options.go +++ b/lib/options.go @@ -282,6 +282,12 @@ type Options struct { TLSVersion *TLSVersions `json:"tlsVersion" ignored:"true"` TLSAuth []*TLSAuth `json:"tlsAuth" envconfig:"K6_TLSAUTH"` + // Fetch missing intermediate certificates via the AIA (Authority Information Access) + // extension when the server presents an incomplete chain. Mirrors what browsers do. + // Disabled by default; opt in via tlsAIAFetch: true or K6_TLS_AIA_FETCH=true. + // Has no effect when InsecureSkipTLSVerify is true. + TLSAIAFetch null.Bool `json:"tlsAIAFetch" envconfig:"K6_TLS_AIA_FETCH"` + // Throw warnings (eg. failed HTTP requests) as errors instead of simply logging them. Throw null.Bool `json:"throw" envconfig:"K6_THROW"` @@ -446,6 +452,9 @@ func (o Options) Apply(opts Options) Options { if opts.InsecureSkipTLSVerify.Valid { o.InsecureSkipTLSVerify = opts.InsecureSkipTLSVerify } + if opts.TLSAIAFetch.Valid { + o.TLSAIAFetch = opts.TLSAIAFetch + } if opts.TLSCipherSuites != nil { o.TLSCipherSuites = opts.TLSCipherSuites } diff --git a/vendor/golang.org/x/sync/singleflight/singleflight.go b/vendor/golang.org/x/sync/singleflight/singleflight.go new file mode 100644 index 000000000..32e40bdc8 --- /dev/null +++ b/vendor/golang.org/x/sync/singleflight/singleflight.go @@ -0,0 +1,214 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package singleflight provides a duplicate function call suppression +// mechanism. +package singleflight // import "golang.org/x/sync/singleflight" + +import ( + "bytes" + "errors" + "fmt" + "runtime" + "runtime/debug" + "sync" +) + +// errGoexit indicates runtime.Goexit was called in +// the user-given function. +var errGoexit = errors.New("runtime.Goexit was called") + +// A panicError is an arbitrary value recovered from a panic +// with the stack trace during the execution of the given function. +type panicError struct { + value any + stack []byte +} + +// Error implements error interface. +func (p *panicError) Error() string { + return fmt.Sprintf("%v\n\n%s", p.value, p.stack) +} + +func (p *panicError) Unwrap() error { + err, ok := p.value.(error) + if !ok { + return nil + } + + return err +} + +func newPanicError(v any) error { + stack := debug.Stack() + + // The first line of the stack trace is of the form "goroutine N [status]:" + // but by the time the panic reaches Do the goroutine may no longer exist + // and its status will have changed. Trim out the misleading line. + if line := bytes.IndexByte(stack[:], '\n'); line >= 0 { + stack = stack[line+1:] + } + return &panicError{value: v, stack: stack} +} + +// call is an in-flight or completed singleflight.Do call +type call struct { + wg sync.WaitGroup + + // These fields are written once before the WaitGroup is done + // and are only read after the WaitGroup is done. + val any + err error + + // These fields are read and written with the singleflight + // mutex held before the WaitGroup is done, and are read but + // not written after the WaitGroup is done. + dups int + chans []chan<- Result +} + +// Group represents a class of work and forms a namespace in +// which units of work can be executed with duplicate suppression. +type Group struct { + mu sync.Mutex // protects m + m map[string]*call // lazily initialized +} + +// Result holds the results of Do, so they can be passed +// on a channel. +type Result struct { + Val any + Err error + Shared bool +} + +// Do executes and returns the results of the given function, making +// sure that only one execution is in-flight for a given key at a +// time. If a duplicate comes in, the duplicate caller waits for the +// original to complete and receives the same results. +// The return value shared indicates whether v was given to multiple callers. +func (g *Group) Do(key string, fn func() (any, error)) (v any, err error, shared bool) { + g.mu.Lock() + if g.m == nil { + g.m = make(map[string]*call) + } + if c, ok := g.m[key]; ok { + c.dups++ + g.mu.Unlock() + c.wg.Wait() + + if e, ok := c.err.(*panicError); ok { + panic(e) + } else if c.err == errGoexit { + runtime.Goexit() + } + return c.val, c.err, true + } + c := new(call) + c.wg.Add(1) + g.m[key] = c + g.mu.Unlock() + + g.doCall(c, key, fn) + return c.val, c.err, c.dups > 0 +} + +// DoChan is like Do but returns a channel that will receive the +// results when they are ready. +// +// The returned channel will not be closed. +func (g *Group) DoChan(key string, fn func() (any, error)) <-chan Result { + ch := make(chan Result, 1) + g.mu.Lock() + if g.m == nil { + g.m = make(map[string]*call) + } + if c, ok := g.m[key]; ok { + c.dups++ + c.chans = append(c.chans, ch) + g.mu.Unlock() + return ch + } + c := &call{chans: []chan<- Result{ch}} + c.wg.Add(1) + g.m[key] = c + g.mu.Unlock() + + go g.doCall(c, key, fn) + + return ch +} + +// doCall handles the single call for a key. +func (g *Group) doCall(c *call, key string, fn func() (any, error)) { + normalReturn := false + recovered := false + + // use double-defer to distinguish panic from runtime.Goexit, + // more details see https://golang.org/cl/134395 + defer func() { + // the given function invoked runtime.Goexit + if !normalReturn && !recovered { + c.err = errGoexit + } + + g.mu.Lock() + defer g.mu.Unlock() + c.wg.Done() + if g.m[key] == c { + delete(g.m, key) + } + + if e, ok := c.err.(*panicError); ok { + // In order to prevent the waiting channels from being blocked forever, + // needs to ensure that this panic cannot be recovered. + if len(c.chans) > 0 { + go panic(e) + select {} // Keep this goroutine around so that it will appear in the crash dump. + } else { + panic(e) + } + } else if c.err == errGoexit { + // Already in the process of goexit, no need to call again + } else { + // Normal return + for _, ch := range c.chans { + ch <- Result{c.val, c.err, c.dups > 0} + } + } + }() + + func() { + defer func() { + if !normalReturn { + // Ideally, we would wait to take a stack trace until we've determined + // whether this is a panic or a runtime.Goexit. + // + // Unfortunately, the only way we can distinguish the two is to see + // whether the recover stopped the goroutine from terminating, and by + // the time we know that, the part of the stack trace relevant to the + // panic has been discarded. + if r := recover(); r != nil { + c.err = newPanicError(r) + } + } + }() + + c.val, c.err = fn() + normalReturn = true + }() + + if !normalReturn { + recovered = true + } +} + +// Forget tells the singleflight to forget about a key. Future calls +// to Do for this key will call the function rather than waiting for +// an earlier call to complete. +func (g *Group) Forget(key string) { + g.mu.Lock() + delete(g.m, key) + g.mu.Unlock() +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 7986c940d..a103f10ef 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -477,6 +477,7 @@ golang.org/x/net/trace ## explicit; go 1.25.0 golang.org/x/sync/errgroup golang.org/x/sync/semaphore +golang.org/x/sync/singleflight # golang.org/x/sys v0.47.0 ## explicit; go 1.25.0 golang.org/x/sys/plan9 From 1e35440eea685de703fb990ffd21bf3e5d0bbdef Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Wed, 9 Sep 2026 06:02:19 +0000 Subject: [PATCH 132/182] fix(security/high/examples/grpc_server): update module google.golang.org/grpc to v1.83.2 [security] (#6383) | datasource | package | from | to | | ---------- | ---------------------- | ------- | ------- | | go | google.golang.org/grpc | v1.83.1 | v1.83.2 | Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> --- examples/grpc_server/go.mod | 8 ++++---- examples/grpc_server/go.sum | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/examples/grpc_server/go.mod b/examples/grpc_server/go.mod index c431997cd..3799f7135 100644 --- a/examples/grpc_server/go.mod +++ b/examples/grpc_server/go.mod @@ -6,13 +6,13 @@ replace go.k6.io/k6 => ../../ require ( go.k6.io/k6/v2 v2.0.0-rc1 - google.golang.org/grpc v1.83.1 + google.golang.org/grpc v1.83.2 ) require ( - golang.org/x/net v0.56.0 // indirect - golang.org/x/sys v0.46.0 // indirect - golang.org/x/text v0.39.0 // indirect + golang.org/x/net v0.58.0 // indirect + golang.org/x/sys v0.47.0 // indirect + golang.org/x/text v0.41.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20260526163538-3dc84a4a5aaa // indirect google.golang.org/protobuf v1.36.11 // indirect ) diff --git a/examples/grpc_server/go.sum b/examples/grpc_server/go.sum index e598f67f1..489eb6fef 100644 --- a/examples/grpc_server/go.sum +++ b/examples/grpc_server/go.sum @@ -24,17 +24,17 @@ go.opentelemetry.io/otel/sdk/metric v1.44.0 h1:3LlKgI+VjbVsjNRFZJZAJ30WjXC5VkNRk go.opentelemetry.io/otel/sdk/metric v1.44.0/go.mod h1:5B5pMARnXxKhltooO4xUuCBorl65a4EpnTalObqOigA= go.opentelemetry.io/otel/trace v1.44.0 h1:jxF5CsGYCe74MCRx2X4g7WsY/VBKRqqpNvXlX/6gtIk= go.opentelemetry.io/otel/trace v1.44.0/go.mod h1:oLl1jrMQAVo6v3GAggN+1VH9VIz9iUSvW53sW1Q8PIE= -golang.org/x/net v0.56.0 h1:Rw8j/hFzGvJUZwNBXnAtf5sVDVt+65SK2C7IxCxZt5o= -golang.org/x/net v0.56.0/go.mod h1:D3Ku6r+V6JROoZK144D2XfMHFcMq/0zSfLelVTCFKec= -golang.org/x/sys v0.46.0 h1:noSf2Fq6F8DBgS+LysIkx7rIExoNHJsxOAtPp4rthXw= -golang.org/x/sys v0.46.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= -golang.org/x/text v0.39.0 h1:UbZz4pLOvn600D6Oh6GGEI6VAmndrEBLv8/6BEXzyus= -golang.org/x/text v0.39.0/go.mod h1:3UwRclnC2g0TU9x8PZiyfOajCd1zaUNHF9cvqcQZ+ZM= +golang.org/x/net v0.58.0 h1:ynWG7rqYi4ccpTEuPZ2QGWHktVEM9DMCj9yzDE0Q7To= +golang.org/x/net v0.58.0/go.mod h1:YwCddHnFlT7eLQqVprV19OnhLGtc5xOKgE0RyqgfWAU= +golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs= +golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= +golang.org/x/text v0.41.0 h1:vz/seA0lnX87Othu2f/0L24RcgrXD9/YFTSuGjj3rH8= +golang.org/x/text v0.41.0/go.mod h1:jvf1O8ajNzZqhSrQBPbutR/EB83Cc0CFrezNQIwbb5M= gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4= gonum.org/v1/gonum v0.17.0/go.mod h1:El3tOrEuMpv2UdMrbNlKEh9vd86bmQ6vqIcDwxEOc1E= google.golang.org/genproto/googleapis/rpc v0.0.0-20260526163538-3dc84a4a5aaa h1:mZHHdPZl0dbGHCflZgAq/Q468DWVFcU2whhB2KAo8fk= google.golang.org/genproto/googleapis/rpc v0.0.0-20260526163538-3dc84a4a5aaa/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8= -google.golang.org/grpc v1.83.1 h1:HIO0+BEtBP6soyqvqC8sNUjZ7bTs+0hFQuFF+RAy++Y= -google.golang.org/grpc v1.83.1/go.mod h1:kDyl6SKsiHKt0uylY5gtn5cEjkrIOhQOGDgIc4JGwzQ= +google.golang.org/grpc v1.83.2 h1:EManeRomTObA0BU7I8vXgg/78uE5MJ9M8B39EX2WscU= +google.golang.org/grpc v1.83.2/go.mod h1:YPI1hK3kDked6iHvgX3tR0y+nX/qpMFKhPgFsokw1S8= google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE= google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= From 7debc9f7f1b82cd47653f664aa58187e702c102a Mon Sep 17 00:00:00 2001 From: Inanc Gumus Date: Wed, 9 Sep 2026 11:53:05 -0400 Subject: [PATCH 133/182] Add `--once` to run a script once (#6338) * Add --once to ask for a single run A quick smoke check needs one VU and one iteration. Users reached for --vus 1 --iterations 1, but those shortcuts conflict with a scenario instead of running it once. Register the --once flag and carry it through the config layers. It has no effect yet; later commits act on it. * Run the test once with --once --once was inert after the previous commit. The consolidated options still carried the script's own load. Rewrite the load into a shared-iterations scenario with one VU and one iteration. It runs before DeriveScenariosFromShortcuts, so an archive keeps the single run. Thresholds and run tags stay. * Reject --once with several scenarios applyOnce keeps a single scenario. With more than one, it would drop the rest without a word. Return an InvalidConfig error when the test has more than one scenario, so the user sees the conflict instead of a silent drop. * Keep the scenario name under --once applyOnce always named the run "default". The summary hid the user's scenario name, e.g. "ui". Read the name from the single scenario and give it to the shared-iterations run, so the summary shows the same name. * Keep the scenario exec under --once The single run always called the default function. A scenario with exec: 'api' ran the wrong one. GetExec reports an unset exec as the default function, so it cannot round-trip. Read the written exec field through JSON and keep it; an unset exec stays unset. * Keep the scenario env under --once The single run dropped the scenario's env. A script that read __ENV from the scenario saw nothing. Copy the scenario env onto the shared-iterations run. * Keep the scenario tags under --once The single run dropped the scenario's tags. Metrics from the run lost those tags. Copy the scenario tags onto the shared-iterations run. * Test --once in both cloud run modes k6 cloud run builds an archive, then runs it locally or uploads it. No test proved --once reached either path. Cover both: local execution runs once, and an upload carries the rewritten single-run archive. * Keep the scenario options under --once The single run dropped the scenario options. A browser scenario lost its browser options under --once. Copy the scenario options onto the shared-iterations run. * Test --once when creating and replaying archives --once touches archives at two stages. Creating one serializes the consolidated options; replaying one loads them before consolidation. Cover both: k6 archive --once writes the single run, and k6 run --once rewrites a plain archive on replay. * Let --once win over the lower layers A shortcut in the config file, script, or env survived consolidation and competed with the replacement scenario, e.g. K6_ITERATIONS=5 caused a derivation conflict. Clear vus, duration, iterations, stages, and the execution segment in each lower layer before the merge, so --once wins. * Warn about the shortcuts --once dropped The previous commit dropped the lower-layer shortcuts without a word. A user who set both --once and K6_VUS saw no sign the value was ignored. Take the layers by name and warn once, listing each dropped option under its layer in merge order. * Reject --once with a shortcut flag A shortcut in a lower layer is dropped with a warning. A shortcut on the CLI sits beside --once and asks for the opposite load. Reject --once together with --vus, --duration, --iterations, --stage, or --execution-segment, so the CLI does not send two conflicting orders. --- internal/cmd/config.go | 14 ++ internal/cmd/once.go | 134 +++++++++++++++ internal/cmd/once_test.go | 243 ++++++++++++++++++++++++++++ internal/cmd/options.go | 5 + internal/cmd/test_load.go | 11 ++ internal/cmd/tests/cmd_once_test.go | 175 ++++++++++++++++++++ 6 files changed, 582 insertions(+) create mode 100644 internal/cmd/once.go create mode 100644 internal/cmd/once_test.go create mode 100644 internal/cmd/tests/cmd_once_test.go diff --git a/internal/cmd/config.go b/internal/cmd/config.go index 617cdec15..c952723d9 100644 --- a/internal/cmd/config.go +++ b/internal/cmd/config.go @@ -51,6 +51,9 @@ type Config struct { NoUsageReport null.Bool `json:"noUsageReport" envconfig:"K6_NO_USAGE_REPORT"` WebDashboard null.Bool `json:"webDashboard" envconfig:"K6_WEB_DASHBOARD"` + // once carries --once between the layers. Unexported keeps json and envconfig out. + once bool + // NoArchiveUpload is an option that is only used when running in local-execution mode with the cloud run // command. // @@ -227,6 +230,17 @@ func getConsolidatedConfig( return Config{}, errext.WithExitCodeIfNone(err, exitcodes.InvalidConfig) } + // Lower layers drop their shortcuts before the merge; getOptions rejects the CLI ones. + if cliConf.once { + if err := dropOnceShortcuts(gs.Logger, map[string]*lib.Options{ + "config": &fileConf.Options, + "script": &runnerOpts, + "environment": &envConf.Options, + }); err != nil { + return Config{}, err + } + } + conf := cliConf.Apply(fileConf) warnOnShortHandOverride(conf.Options, runnerOpts, "script", gs.Logger) diff --git a/internal/cmd/once.go b/internal/cmd/once.go new file mode 100644 index 000000000..e108818ef --- /dev/null +++ b/internal/cmd/once.go @@ -0,0 +1,134 @@ +package cmd + +import ( + "encoding/json" + "fmt" + "maps" + "slices" + "strings" + + "github.com/sirupsen/logrus" + "github.com/spf13/pflag" + "gopkg.in/guregu/null.v3" + + "go.k6.io/k6/v2/errext" + "go.k6.io/k6/v2/errext/exitcodes" + "go.k6.io/k6/v2/lib" + "go.k6.io/k6/v2/lib/executor" +) + +// --once writes the load itself, so a CLI shortcut would fight the scenario it writes. +func checkOnceConflicts(flags *pflag.FlagSet) error { + if !getNullBool(flags, "once").Bool { + return nil + } + for _, name := range []string{ + "vus", "duration", "iterations", "stage", + "execution-segment", "execution-segment-sequence", + } { + if flags.Changed(name) { + return errext.WithExitCodeIfNone( + fmt.Errorf("--once cannot be combined with --%s", name), exitcodes.InvalidConfig) + } + } + return nil +} + +// A shortcut left in a lower layer drops or rewrites the scenario applyOnce writes. +func dropOnceShortcuts(logger logrus.FieldLogger, layers map[string]*lib.Options) error { + var unset lib.Options + + // k6 merges the layers in this order, and the warning follows it. + for _, name := range []string{"config", "script", "environment"} { + o, ok := layers[name] + if !ok { + return fmt.Errorf("missing %q layer", name) + } + + var dropped []string + drop := func(opt string, set bool) { + if set { + dropped = append(dropped, opt) + } + } + drop("vus", o.VUs.Valid) + drop("duration", o.Duration.Valid) + drop("iterations", o.Iterations.Valid) + drop("stages", o.Stages != nil) + drop("executionSegment", o.ExecutionSegment != nil) + drop("executionSegmentSequence", o.ExecutionSegmentSequence != nil) + + // Clearing an unset shortcut changes nothing, so only the naming above needs a check. + o.VUs = unset.VUs + o.Duration = unset.Duration + o.Iterations = unset.Iterations + o.Stages = unset.Stages + o.ExecutionSegment = unset.ExecutionSegment + o.ExecutionSegmentSequence = unset.ExecutionSegmentSequence + + if len(dropped) > 0 { + logger.Warnf("--once overrode %s in %q configuration", strings.Join(dropped, ", "), name) + } + } + + return nil +} + +// Bare --once never guesses which scenario runs, so several scenarios are ambiguous. +func rejectAmbiguousOnce(scenarios lib.ScenarioConfigs) error { + if len(scenarios) <= 1 { + return nil + } + names := slices.Sorted(maps.Keys(scenarios)) + return errext.WithExitCodeIfNone( + fmt.Errorf("--once can run only with a single scenario, but got: %s", + strings.Join(names, ", ")), exitcodes.InvalidConfig) +} + +// Runs before DeriveScenariosFromShortcuts, so the archive gets the same scenarios. +func applyOnce(opts lib.Options) (lib.Options, error) { + scenarios := opts.Scenarios + if len(scenarios) == 0 { + scenarios = lib.ScenarioConfigs{lib.DefaultScenarioName: nil} + } + + rewritten := make(lib.ScenarioConfigs, len(scenarios)) + for name, src := range scenarios { + sc, err := onceScenario(name, src) + if err != nil { + return opts, err + } + rewritten[name] = sc + } + opts.Scenarios = rewritten + + return opts, nil +} + +func onceScenario(name string, src lib.ExecutorConfig) (lib.ExecutorConfig, error) { + once := executor.NewSharedIterationsConfig(name) + once.VUs = null.IntFrom(1) + once.Iterations = null.IntFrom(1) + if src == nil { + return once, nil + } + + // GetExec collapses an unset exec and an explicit "default" to the same "default", + // and the interface exposes no raw getter, so read the null.String through JSON. + data, err := json.Marshal(src) + if err != nil { + return nil, fmt.Errorf("reading the %q scenario: %w", src.GetName(), err) + } + var raw struct { + Exec null.String `json:"exec"` + } + if err := json.Unmarshal(data, &raw); err != nil { + return nil, fmt.Errorf("reading the exec of the %q scenario: %w", src.GetName(), err) + } + once.Exec = raw.Exec + once.Env = src.GetEnv() + once.Tags = src.GetTags() + once.Options = src.GetScenarioOptions() + + return once, nil +} diff --git a/internal/cmd/once_test.go b/internal/cmd/once_test.go new file mode 100644 index 000000000..46e5d95b1 --- /dev/null +++ b/internal/cmd/once_test.go @@ -0,0 +1,243 @@ +package cmd + +import ( + "path/filepath" + "testing" + "time" + + "github.com/sirupsen/logrus" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "gopkg.in/guregu/null.v3" + + "go.k6.io/k6/v2/errext" + "go.k6.io/k6/v2/errext/exitcodes" + "go.k6.io/k6/v2/internal/cmd/tests" + "go.k6.io/k6/v2/internal/lib/testutils" + "go.k6.io/k6/v2/lib" + "go.k6.io/k6/v2/lib/executor" + "go.k6.io/k6/v2/lib/fsext" + "go.k6.io/k6/v2/lib/types" +) + +func TestApplyOncePreservesScenarioName(t *testing.T) { + t.Parallel() + + opts := lib.Options{Scenarios: lib.ScenarioConfigs{ + "ui": executor.NewConstantVUsConfig("ui"), + "api": executor.NewConstantVUsConfig("api"), + }} + + res, err := applyOnce(opts) + require.NoError(t, err) + require.Len(t, res.Scenarios, 2) + + for _, name := range []string{"ui", "api"} { + sc, ok := res.Scenarios[name].(executor.SharedIterationsConfig) + require.True(t, ok) + assert.Equal(t, name, sc.GetName()) + assert.Equal(t, null.IntFrom(1), sc.VUs) + assert.Equal(t, null.IntFrom(1), sc.Iterations) + } +} + +func mustExtractSingleSharedIterScenario(t *testing.T, opts lib.Options) executor.SharedIterationsConfig { + t.Helper() + + require.Len(t, opts.Scenarios, 1) + for _, sc := range opts.Scenarios { + shared, ok := sc.(executor.SharedIterationsConfig) + require.True(t, ok) + return shared + } + return executor.SharedIterationsConfig{} +} + +func TestApplyOncePreservesScenarioExec(t *testing.T) { + t.Parallel() + + for _, tt := range []struct { + name string + exec null.String + }{ + {"custom", null.StringFrom("api")}, + {"unset", null.String{}}, + } { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + src := executor.NewSharedIterationsConfig("ui") + src.Exec = tt.exec + opts := lib.Options{Scenarios: lib.ScenarioConfigs{"ui": src}} + + res, err := applyOnce(opts) + require.NoError(t, err) + assert.Equal(t, tt.exec, mustExtractSingleSharedIterScenario(t, res).Exec) + }) + } +} + +func TestApplyOncePreservesScenarioFields(t *testing.T) { + t.Parallel() + + for _, tt := range []struct { + name string + setup func(*executor.SharedIterationsConfig) + check func(*testing.T, executor.SharedIterationsConfig) + }{ + { + name: "env", + setup: func(s *executor.SharedIterationsConfig) { s.Env = map[string]string{"GREETING": "hi"} }, + check: func(t *testing.T, s executor.SharedIterationsConfig) { + t.Helper() + assert.Equal(t, map[string]string{"GREETING": "hi"}, s.Env) + }, + }, + { + name: "tags", + setup: func(s *executor.SharedIterationsConfig) { s.Tags = map[string]string{"team": "core"} }, + check: func(t *testing.T, s executor.SharedIterationsConfig) { + t.Helper() + assert.Equal(t, map[string]string{"team": "core"}, s.Tags) + }, + }, + { + name: "options", + setup: func(s *executor.SharedIterationsConfig) { + s.Options = &lib.ScenarioOptions{Browser: map[string]any{"type": "chromium"}} + }, + check: func(t *testing.T, s executor.SharedIterationsConfig) { + t.Helper() + assert.Equal(t, &lib.ScenarioOptions{Browser: map[string]any{"type": "chromium"}}, s.Options) + }, + }, + } { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + src := executor.NewSharedIterationsConfig("ui") + tt.setup(&src) + opts := lib.Options{Scenarios: lib.ScenarioConfigs{"ui": src}} + + res, err := applyOnce(opts) + require.NoError(t, err) + + sc := mustExtractSingleSharedIterScenario(t, res) + tt.check(t, sc) + }) + } +} + +func TestGetConsolidatedConfigOnceDropsLowerLayerShortcuts(t *testing.T) { + t.Parallel() + + ts := tests.NewGlobalTestState(t) + require.NoError(t, ts.FS.MkdirAll(filepath.Dir(ts.Flags.ConfigFilePath), 0o755)) + require.NoError(t, fsext.WriteFile(ts.FS, ts.Flags.ConfigFilePath, + []byte(`{"vus": 7, "stages": [{"duration": "10s", "target": 5}]}`), 0o644)) + ts.Env["K6_ITERATIONS"] = "5" + + segment, err := lib.NewExecutionSegmentFromString("0:1/2") + require.NoError(t, err) + runnerOpts := lib.Options{ + Duration: types.NullDurationFrom(time.Second), + ExecutionSegment: segment, + } + + conf, err := getConsolidatedConfig(ts.GlobalState, Config{once: true}, runnerOpts, nil) + require.NoError(t, err) + + assert.False(t, conf.VUs.Valid) + assert.False(t, conf.Duration.Valid) + assert.False(t, conf.Iterations.Valid) + assert.Nil(t, conf.Stages) + assert.Nil(t, conf.ExecutionSegment) +} + +func TestOncePreservesScenarioAcrossLayers(t *testing.T) { + t.Parallel() + + ts := tests.NewGlobalTestState(t) + require.NoError(t, ts.FS.MkdirAll(filepath.Dir(ts.Flags.ConfigFilePath), 0o755)) + require.NoError(t, fsext.WriteFile(ts.FS, ts.Flags.ConfigFilePath, []byte(`{"scenarios": { + "fromfile": { "executor": "constant-vus", "vus": 3, "duration": "2s", "exec": "api", + "env": { "GREETING": "hi" }, "tags": { "team": "core" }, + "options": { "browser": { "type": "chromium" } } } + }}`), 0o644)) + ts.Env["K6_ITERATIONS"] = "5" + + runnerOpts := lib.Options{Duration: types.NullDurationFrom(time.Second)} + + conf, err := getConsolidatedConfig(ts.GlobalState, Config{once: true}, runnerOpts, nil) + require.NoError(t, err) + + opts, err := applyOnce(conf.Options) + require.NoError(t, err) + + sc := mustExtractSingleSharedIterScenario(t, opts) + assert.Equal(t, "fromfile", sc.GetName()) + assert.Equal(t, null.IntFrom(1), sc.VUs) + assert.Equal(t, null.IntFrom(1), sc.Iterations) + assert.Equal(t, null.StringFrom("api"), sc.Exec) + assert.Equal(t, map[string]string{"GREETING": "hi"}, sc.Env) + assert.Equal(t, map[string]string{"team": "core"}, sc.Tags) + assert.Equal(t, &lib.ScenarioOptions{Browser: map[string]any{"type": "chromium"}}, sc.Options) +} + +func TestDropOnceShortcutsWarnsOnlyWhenItDropsShortcuts(t *testing.T) { + t.Parallel() + + logger, hook := testutils.NewLoggerWithHook(t, logrus.WarnLevel) + + require.NoError(t, dropOnceShortcuts(logger, map[string]*lib.Options{ + "config": {}, + "script": {}, + "environment": {}, + })) + assert.Empty(t, hook.Drain()) + + segment, err := lib.NewExecutionSegmentFromString("0:1/2") + require.NoError(t, err) + require.NoError(t, dropOnceShortcuts(logger, map[string]*lib.Options{ + "config": {VUs: null.IntFrom(1), Stages: []lib.Stage{ + {Duration: types.NullDurationFrom(time.Second), Target: null.IntFrom(1)}, + }}, + "script": { + VUs: null.IntFrom(1), Duration: types.NullDurationFrom(time.Second), + ExecutionSegment: segment, + }, + "environment": {Iterations: null.IntFrom(1)}, + })) + + entries := hook.Drain() + require.Len(t, entries, 3) + assert.Equal(t, `--once overrode vus, stages in "config" configuration`, entries[0].Message) + assert.Equal(t, `--once overrode vus, duration, executionSegment in "script" configuration`, entries[1].Message) + assert.Equal(t, `--once overrode iterations in "environment" configuration`, entries[2].Message) +} + +func TestGetOptionsRejectsOnceWithShortcut(t *testing.T) { + t.Parallel() + + for _, tt := range []struct{ flag, value string }{ + {"vus", "1"}, + {"duration", "10s"}, + {"iterations", "5"}, + {"stage", "10s:5"}, + {"execution-segment", "1/2:1"}, + } { + t.Run(tt.flag, func(t *testing.T) { + t.Parallel() + + flags := optionFlagSet() + require.NoError(t, flags.Parse([]string{"--once", "--" + tt.flag, tt.value})) + + _, err := getOptions(flags) + require.EqualError(t, err, "--once cannot be combined with --"+tt.flag) + + var ec errext.HasExitCode + require.ErrorAs(t, err, &ec) + assert.Equal(t, exitcodes.InvalidConfig, ec.ExitCode()) + }) + } +} diff --git a/internal/cmd/options.go b/internal/cmd/options.go index 5dd9e55bd..cbf5d760e 100644 --- a/internal/cmd/options.go +++ b/internal/cmd/options.go @@ -24,6 +24,7 @@ func optionFlagSet() *pflag.FlagSet { flags := pflag.NewFlagSet("", 0) flags.SortFlags = false + flags.Bool("once", false, "run the test with 1 VU and 1 iteration") flags.Int64P("vus", "u", 1, "number of virtual users") flags.DurationP("duration", "d", 0, "test duration limit") flags.Int64P("iterations", "i", 0, "script total iteration limit (among all VUs)") @@ -79,6 +80,10 @@ func optionFlagSet() *pflag.FlagSet { //nolint:funlen,gocognit,cyclop // this needs breaking up but probably should wait for croconf func getOptions(flags *pflag.FlagSet) (lib.Options, error) { + if err := checkOnceConflicts(flags); err != nil { + return lib.Options{}, err + } + opts := lib.Options{ VUs: getNullInt64(flags, "vus"), Duration: getNullDuration(flags, "duration"), diff --git a/internal/cmd/test_load.go b/internal/cmd/test_load.go index bfc633773..90d05b8a8 100644 --- a/internal/cmd/test_load.go +++ b/internal/cmd/test_load.go @@ -541,6 +541,8 @@ func (lt *loadedTest) consolidateDeriveAndValidateConfig( if err != nil { return nil, err } + // --once is CLI-only, so it rides on the CLI configuration layer. + cliConfig.once = getNullBool(cmd.Flags(), "once").Bool } gs.Logger.Debug("Consolidating config layers...") @@ -550,6 +552,15 @@ func (lt *loadedTest) consolidateDeriveAndValidateConfig( return nil, err } + if cliConfig.once { + if err = rejectAmbiguousOnce(consolidatedConfig.Scenarios); err != nil { + return nil, err + } + if consolidatedConfig.Options, err = applyOnce(consolidatedConfig.Options); err != nil { + return nil, err + } + } + gs.Logger.Debug("Parsing thresholds and validating config...") // Parse the thresholds, only if the --no-threshold flag is not set. // If parsing the threshold expressions failed, consider it as an diff --git a/internal/cmd/tests/cmd_once_test.go b/internal/cmd/tests/cmd_once_test.go new file mode 100644 index 000000000..90dfea3d8 --- /dev/null +++ b/internal/cmd/tests/cmd_once_test.go @@ -0,0 +1,175 @@ +package tests + +import ( + "bytes" + "path/filepath" + "strings" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "gopkg.in/guregu/null.v3" + + "go.k6.io/k6/v2/errext/exitcodes" + "go.k6.io/k6/v2/internal/cmd" + "go.k6.io/k6/v2/lib" + "go.k6.io/k6/v2/lib/executor" + "go.k6.io/k6/v2/lib/fsext" +) + +func TestRunOnce(t *testing.T) { + t.Parallel() + + script := ` + import { Counter } from 'k6/metrics'; + + export const options = { + tags: { top: 'level' }, + thresholds: { 'hits{top:level}': ['count==1'] }, + }; + + const hits = new Counter('hits'); + + export default function () { + hits.add(1); + console.log('once ran'); + } + ` + + ts := getSingleFileTestState(t, script, []string{"--log-output=stdout", "--once"}, 0) + cmd.ExecuteWithGlobalState(ts.GlobalState) + + stdout := ts.Stdout.String() + assert.Contains(t, stdout, "1 iterations shared among 1 VUs") + assert.Equal(t, 1, strings.Count(stdout, "once ran")) + assert.Contains(t, stdout, "hits{top:level}") + assert.Contains(t, stdout, "'count==1' count=1") +} + +func TestRunOnceRejectsMultipleScenarios(t *testing.T) { + t.Parallel() + + script := ` + export const options = { scenarios: { + s1: { executor: 'shared-iterations' }, + s2: { executor: 'shared-iterations' } + }}; + export default function() {} + ` + + ts := getSingleFileTestState(t, script, + []string{"--log-output=stdout", "--once"}, exitcodes.InvalidConfig) + cmd.ExecuteWithGlobalState(ts.GlobalState) + + assert.Contains(t, ts.Stdout.String(), + "--once can run only with a single scenario") +} + +const onceCloudScript = ` + export const options = { + cloud: { name: 'once', projectID: 123456 }, + scenarios: { + ui: { executor: 'shared-iterations', vus: 3, iterations: 9 } + } + }; + export default function() { console.log('once ran'); } +` + +func mustExtractSingleSharedIterScenario(t *testing.T, opts lib.Options) executor.SharedIterationsConfig { + t.Helper() + + require.Len(t, opts.Scenarios, 1) + for _, sc := range opts.Scenarios { + shared, ok := sc.(executor.SharedIterationsConfig) + require.True(t, ok) + return shared + } + return executor.SharedIterationsConfig{} +} + +func TestCloudRunOnceLocalExecution(t *testing.T) { + t.Parallel() + + ts := makeTestState(t, onceCloudScript, + []string{"--log-output=stdout", "--once", "--local-execution"}) + setupLocalExecutionProvMock(t, ts) + + cmd.ExecuteWithGlobalState(ts.GlobalState) + + stdout := ts.Stdout.String() + assert.Contains(t, stdout, "1 iterations shared among 1 VUs") + assert.Equal(t, 1, strings.Count(stdout, "once ran")) +} + +func TestCloudRunOnceUploadsRewrittenArchive(t *testing.T) { + t.Parallel() + + _, tarData := uploadAndCaptureArchive(t, + []string{"k6", "cloud", "run", "--once", "test.js"}, nil, onceCloudScript) + + arc, err := lib.ReadArchive(bytes.NewReader(tarData)) + require.NoError(t, err) + + sc := mustExtractSingleSharedIterScenario(t, arc.Options) + assert.Equal(t, null.IntFrom(1), sc.VUs) + assert.Equal(t, null.IntFrom(1), sc.Iterations) +} + +func buildArchive(t *testing.T, script string, flags ...string) []byte { + t.Helper() + + ts := NewGlobalTestState(t) + tarPath := filepath.Join(ts.Cwd, "archive.tar") + require.NoError(t, fsext.WriteFile( + ts.FS, filepath.Join(ts.Cwd, "test.js"), []byte(script), 0o644)) + ts.CmdArgs = append(append([]string{"k6", "archive"}, flags...), "-O", tarPath, "test.js") + + cmd.ExecuteWithGlobalState(ts.GlobalState) + + tarData, err := fsext.ReadFile(ts.FS, tarPath) + require.NoError(t, err) + + return tarData +} + +func TestArchiveOnceWritesRewrittenOptions(t *testing.T) { + t.Parallel() + + script := ` + export const options = { scenarios: { + ui: { executor: 'constant-vus', vus: 3, duration: '2s' } + }}; + export default function() {} + ` + + arc, err := lib.ReadArchive(bytes.NewReader(buildArchive(t, script, "--once"))) + require.NoError(t, err) + + sc := mustExtractSingleSharedIterScenario(t, arc.Options) + assert.Equal(t, null.IntFrom(1), sc.VUs) + assert.Equal(t, null.IntFrom(1), sc.Iterations) +} + +func TestRunOnceRewritesPlainArchive(t *testing.T) { + t.Parallel() + + script := ` + export const options = { scenarios: { + ui: { executor: 'shared-iterations', vus: 3, iterations: 9 } + }}; + export default function() { console.log('once ran'); } + ` + + tarData := buildArchive(t, script) + + ts := NewGlobalTestState(t) + tarPath := filepath.Join(ts.Cwd, "archive.tar") + require.NoError(t, fsext.WriteFile(ts.FS, tarPath, tarData, 0o644)) + ts.CmdArgs = []string{"k6", "run", "--log-output=stdout", "--once", tarPath} + + cmd.ExecuteWithGlobalState(ts.GlobalState) + + stdout := ts.Stdout.String() + assert.Contains(t, stdout, "1 iterations shared among 1 VUs") + assert.Equal(t, 1, strings.Count(stdout, "once ran")) +} From 05efeafe90b49fba83d760deaa29222159e0f128 Mon Sep 17 00:00:00 2001 From: Inanc Gumus Date: Wed, 9 Sep 2026 14:47:05 -0400 Subject: [PATCH 134/182] Record build origin in anonymous usage reports (#6369) --- Dockerfile | 3 ++- build-release.sh | 4 +++- internal/build/version.go | 4 ++++ internal/cmd/report.go | 3 +++ internal/cmd/report_test.go | 45 +++++++++++++++++++++++++++++++++++++ 5 files changed, 57 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9b65861bc..5cd28a3e8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,8 @@ WORKDIR $GOPATH/src/go.k6.io/k6 COPY . . ARG TARGETOS TARGETARCH RUN apk --no-cache add git=~2 -RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -trimpath -o /usr/bin/k6 +RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -trimpath \ + -ldflags "-X go.k6.io/k6/v2/internal/build.BuildOrigin=release" -o /usr/bin/k6 # Runtime stage FROM alpine:3.24.1@sha256:28bd5fe8b56d1bd048e5babf5b10710ebe0bae67db86916198a6eec434943f8b as release diff --git a/build-release.sh b/build-release.sh index 506e05a9c..07137fdf7 100755 --- a/build-release.sh +++ b/build-release.sh @@ -15,7 +15,9 @@ build() { local ALIAS="$1" SUFFIX="${2}" # Any other arguments are passed to the go build command as env vars local NAME="k6-${VERSION}-${ALIAS}" - local BUILD_ARGS=(-o "${OUT_DIR}/${NAME}/k6${SUFFIX}" -trimpath) + # -X marks the binary, and so the packages built from it, as an official build. + local BUILD_ARGS=(-o "${OUT_DIR}/${NAME}/k6${SUFFIX}" -trimpath + -ldflags "-X go.k6.io/k6/v2/internal/build.BuildOrigin=release") local PACKAGE_FORMATS IFS="," read -ra PACKAGE_FORMATS <<< "${3}" diff --git a/internal/build/version.go b/internal/build/version.go index 0f884d142..0e2fae694 100644 --- a/internal/build/version.go +++ b/internal/build/version.go @@ -4,3 +4,7 @@ package build // Version contains the current version of k6 // represented using Semantic Versioning expression. const Version = "2.2.0" + +// BuildOrigin records how this binary was built, e.g. "release", and a build command sets it with +// -ldflags "-X go.k6.io/k6/v2/internal/build.BuildOrigin=release". +var BuildOrigin string //nolint:gochecknoglobals // the Go linker can only set a package-level variable diff --git a/internal/cmd/report.go b/internal/cmd/report.go index fa4bbf759..231f66d19 100644 --- a/internal/cmd/report.go +++ b/internal/cmd/report.go @@ -49,6 +49,9 @@ func addEnvironmentInfo(m map[string]any, lookupEnv func(string) (string, bool)) m["goos"] = runtime.GOOS m["goarch"] = runtime.GOARCH m["is_ci"] = isCI(lookupEnv) + if build.BuildOrigin != "" { + m["build_origin"] = build.BuildOrigin + } } // createReport assembles the anonymous usage report for a run from its diff --git a/internal/cmd/report_test.go b/internal/cmd/report_test.go index 692be4583..0e46f1721 100644 --- a/internal/cmd/report_test.go +++ b/internal/cmd/report_test.go @@ -107,3 +107,48 @@ func TestCreateReport(t *testing.T) { assert.EqualValues(t, true, m["is_ci"]) }) } + +//nolint:paralleltest // swaps the package-global build.BuildOrigin, so the subtests must run serially. +func TestCreateReportBuildOrigin(t *testing.T) { + logger := testutils.NewLogger(t) + opts, err := executor.DeriveScenariosFromShortcuts(lib.Options{ + VUs: null.IntFrom(1), + Iterations: null.IntFrom(1), + }, logger) + require.NoError(t, err) + + newScheduler := func() *execution.Scheduler { + s, err := execution.NewScheduler(&lib.TestRunState{ + TestPreInitState: &lib.TestPreInitState{ + Logger: logger, + LookupEnv: func(string) (string, bool) { return "", false }, + }, + Options: opts, + }, local.NewController()) + require.NoError(t, err) + return s + } + + noCatalog := func() map[string]struct{} { return nil } + + t.Run("empty origin omits the field", func(t *testing.T) { + original := build.BuildOrigin + build.BuildOrigin = "" + t.Cleanup(func() { build.BuildOrigin = original }) + + m := createReport(usage.New(), newScheduler(), noCatalog) + + _, ok := m["build_origin"] + assert.False(t, ok) + }) + + t.Run("recorded origin appears in the report", func(t *testing.T) { + original := build.BuildOrigin + build.BuildOrigin = "release" + t.Cleanup(func() { build.BuildOrigin = original }) + + m := createReport(usage.New(), newScheduler(), noCatalog) + + assert.Equal(t, "release", m["build_origin"]) + }) +} From 1619547052cd065a4ad95ecc728297b23cfe1c1f Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Thu, 10 Sep 2026 11:54:07 +0200 Subject: [PATCH 135/182] fix(security/unknown/): update module golang.org/x/crypto to v0.56.0 [security] (#6367) | datasource | package | from | to | | ---------- | ------------------- | ------- | ------- | | go | golang.org/x/crypto | v0.55.0 | v0.56.0 | Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> --- go.mod | 6 ++---- go.sum | 4 ++-- vendor/modules.txt | 4 ++-- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index f902dd183..37acabbfa 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,6 @@ module go.k6.io/k6/v2 -go 1.25.0 - -toolchain go1.25.12 +go 1.26.0 require ( buf.build/gen/go/prometheus/prometheus/protocolbuffers/go v1.36.11-20260707164124-2360da55afce.1 @@ -57,7 +55,7 @@ require ( go.opentelemetry.io/otel/trace v1.46.0 go.opentelemetry.io/proto/otlp v1.11.0 go.uber.org/goleak v1.3.0 - golang.org/x/crypto v0.55.0 + golang.org/x/crypto v0.56.0 golang.org/x/crypto/x509roots/fallback v0.0.0-20260811175631-f44d03d253a1 golang.org/x/net v0.58.0 golang.org/x/sync v0.22.0 diff --git a/go.sum b/go.sum index a761263a1..156b1caca 100644 --- a/go.sum +++ b/go.sum @@ -249,8 +249,8 @@ golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliY golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= -golang.org/x/crypto v0.55.0 h1:+KWHjbgOaAQ66dh/YlkZKHlz9ZUlq61AFirAR9ntP8M= -golang.org/x/crypto v0.55.0/go.mod h1:uq0V9dE/fzQuJtbnL+2EhWOE63vo164FY8xqEnV9xis= +golang.org/x/crypto v0.56.0 h1:GUh5Ii4J5jtcseSMiRqr1jXCNHoxjeV9Fmekc2oLy6Y= +golang.org/x/crypto v0.56.0/go.mod h1:OMW5y6CY9l38uPLmxU6l6pwcXp1obtLo3e6gT7gQR2I= golang.org/x/crypto/x509roots/fallback v0.0.0-20260811175631-f44d03d253a1 h1:0LcVce0NOnpZF3lueZ6uAorLcATPGDmPolJYvQBE0ic= golang.org/x/crypto/x509roots/fallback v0.0.0-20260811175631-f44d03d253a1/go.mod h1:+UoQFNBq2p2wO+Q6ddVtYc25GZ6VNdOMyyrd4nrqrKs= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= diff --git a/vendor/modules.txt b/vendor/modules.txt index a103f10ef..f56f7928d 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -451,8 +451,8 @@ go.uber.org/goleak/internal/stack # go.yaml.in/yaml/v3 v3.0.5 ## explicit; go 1.16 go.yaml.in/yaml/v3 -# golang.org/x/crypto v0.55.0 -## explicit; go 1.25.0 +# golang.org/x/crypto v0.56.0 +## explicit; go 1.26.0 golang.org/x/crypto/md4 golang.org/x/crypto/ocsp golang.org/x/crypto/ripemd160 From 70a561fe444e71a16fadbf371fd66872fa357e20 Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Thu, 10 Sep 2026 13:04:17 +0200 Subject: [PATCH 136/182] fix(deps): update module github.com/andybalholm/brotli to v1.2.3 (#6357) | datasource | package | from | to | | ---------- | ----------------------------- | ------ | ------ | | go | github.com/andybalholm/brotli | v1.2.2 | v1.2.3 | Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 +- .../andybalholm/brotli/flate/LICENSE | 27 - .../andybalholm/brotli/flate/gzip.go | 65 --- .../brotli/flate/huffman_bit_writer.go | 517 ------------------ .../andybalholm/brotli/flate/huffman_code.go | 346 ------------ .../andybalholm/brotli/flate/token.go | 80 --- .../andybalholm/brotli/flate/writer.go | 66 --- vendor/github.com/andybalholm/brotli/http.go | 11 +- vendor/modules.txt | 3 +- 10 files changed, 10 insertions(+), 1111 deletions(-) delete mode 100644 vendor/github.com/andybalholm/brotli/flate/LICENSE delete mode 100644 vendor/github.com/andybalholm/brotli/flate/gzip.go delete mode 100644 vendor/github.com/andybalholm/brotli/flate/huffman_bit_writer.go delete mode 100644 vendor/github.com/andybalholm/brotli/flate/huffman_code.go delete mode 100644 vendor/github.com/andybalholm/brotli/flate/token.go delete mode 100644 vendor/github.com/andybalholm/brotli/flate/writer.go diff --git a/go.mod b/go.mod index 37acabbfa..20a3d02cc 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/Masterminds/semver/v3 v3.5.0 github.com/PuerkitoBio/goquery v1.12.0 github.com/Soontao/goHttpDigestClient v0.0.0-20170320082612-6d28bb1415c5 - github.com/andybalholm/brotli v1.2.2 + github.com/andybalholm/brotli v1.2.3 github.com/bufbuild/protocompile v0.14.1 github.com/chromedp/cdproto v0.0.0-20250803210736-d308e07a266d github.com/evanw/esbuild v0.28.2 diff --git a/go.sum b/go.sum index 156b1caca..8be40d955 100644 --- a/go.sum +++ b/go.sum @@ -12,8 +12,8 @@ github.com/PuerkitoBio/goquery v1.12.0 h1:pAcL4g3WRXekcB9AU/y1mbKez2dbY2AajVhtkO github.com/PuerkitoBio/goquery v1.12.0/go.mod h1:802ej+gV2y7bbIhOIoPY5sT183ZW0YFofScC4q/hIpQ= github.com/Soontao/goHttpDigestClient v0.0.0-20170320082612-6d28bb1415c5 h1:k+1+doEm31k0rRjCjLnGG3YRkuO9ljaEyS2ajZd6GK8= github.com/Soontao/goHttpDigestClient v0.0.0-20170320082612-6d28bb1415c5/go.mod h1:5Q4+CyR7+Q3VMG8f78ou+QSX/BNUNUx5W48eFRat8DQ= -github.com/andybalholm/brotli v1.2.2 h1:HzTuoo2ErYQqf5qvcJInB8uvqSVxRttzkFexPWtnceM= -github.com/andybalholm/brotli v1.2.2/go.mod h1:rzTDkvFWvIrjDXZHkuS16NPggd91W3kUSvPlQ1pLaKY= +github.com/andybalholm/brotli v1.2.3 h1:8H1qwOkl2LPfjf3YezB90JnCliZb6SInJ/OJkEbA5NQ= +github.com/andybalholm/brotli v1.2.3/go.mod h1:rzTDkvFWvIrjDXZHkuS16NPggd91W3kUSvPlQ1pLaKY= github.com/andybalholm/cascadia v1.3.3 h1:AG2YHrzJIm4BZ19iwJ/DAua6Btl3IwJX+VI4kktS1LM= github.com/andybalholm/cascadia v1.3.3/go.mod h1:xNd9bqTn98Ln4DwST8/nG+H0yuB8Hmgu1YHNnWw0GeA= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= diff --git a/vendor/github.com/andybalholm/brotli/flate/LICENSE b/vendor/github.com/andybalholm/brotli/flate/LICENSE deleted file mode 100644 index 6a66aea5e..000000000 --- a/vendor/github.com/andybalholm/brotli/flate/LICENSE +++ /dev/null @@ -1,27 +0,0 @@ -Copyright (c) 2009 The Go Authors. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above -copyright notice, this list of conditions and the following disclaimer -in the documentation and/or other materials provided with the -distribution. - * Neither the name of Google Inc. nor the names of its -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/vendor/github.com/andybalholm/brotli/flate/gzip.go b/vendor/github.com/andybalholm/brotli/flate/gzip.go deleted file mode 100644 index 16c628714..000000000 --- a/vendor/github.com/andybalholm/brotli/flate/gzip.go +++ /dev/null @@ -1,65 +0,0 @@ -package flate - -import ( - "hash/crc32" - "time" - - "github.com/andybalholm/brotli/matchfinder" -) - -func NewGZIPEncoder() matchfinder.Encoder { - return &gzipEncoder{ - f: NewEncoder(), - } -} - -type gzipEncoder struct { - f matchfinder.Encoder - length uint32 - crc uint32 - wroteHeader bool -} - -func (g *gzipEncoder) Reset() { - g.f.Reset() - g.length = 0 - g.crc = 0 - g.wroteHeader = false -} - -func appendUint32(dst []byte, n uint32) []byte { - return append(dst, - byte(n), - byte(n>>8), - byte(n>>16), - byte(n>>24), - ) -} - -func (g *gzipEncoder) Encode(dst []byte, src []byte, matches []matchfinder.Match, lastBlock bool) []byte { - if !g.wroteHeader { - dst = append(dst, - 0x1f, 0x8b, // magic number - 8, // CM = flate - 0, // FLG - ) - dst = appendUint32(dst, uint32(time.Now().Unix())) - dst = append(dst, - 0, // XFL - 255, // OS (unspecified) - ) - g.wroteHeader = true - } - - dst = g.f.Encode(dst, src, matches, lastBlock) - - g.length += uint32(len(src)) - g.crc = crc32.Update(g.crc, crc32.IEEETable, src) - - if lastBlock { - dst = appendUint32(dst, g.crc) - dst = appendUint32(dst, g.length) - } - - return dst -} diff --git a/vendor/github.com/andybalholm/brotli/flate/huffman_bit_writer.go b/vendor/github.com/andybalholm/brotli/flate/huffman_bit_writer.go deleted file mode 100644 index c60dfd44e..000000000 --- a/vendor/github.com/andybalholm/brotli/flate/huffman_bit_writer.go +++ /dev/null @@ -1,517 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package flate - -import ( - "github.com/andybalholm/brotli/matchfinder" -) - -const ( - // The largest offset code. - offsetCodeCount = 30 - - // The special code used to mark the end of a block. - endBlockMarker = 256 - - // The first length code. - lengthCodesStart = 257 - - // The number of codegen codes. - codegenCodeCount = 19 - badCode = 255 - - maxNumLit = 286 - maxStoreBlockSize = 65535 - baseMatchLength = 3 // The smallest match length per the RFC section 3.2.5 - baseMatchOffset = 1 // The smallest match offset -) - -// The number of extra bits needed by length code X - LENGTH_CODES_START. -var lengthExtraBits = []int8{ - /* 257 */ 0, 0, 0, - /* 260 */ 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, - /* 270 */ 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, - /* 280 */ 4, 5, 5, 5, 5, 0, -} - -// The length indicated by length code X - LENGTH_CODES_START. -var lengthBase = []int{ - 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, - 12, 14, 16, 20, 24, 28, 32, 40, 48, 56, - 64, 80, 96, 112, 128, 160, 192, 224, 255, -} - -// offset code word extra bits. -var offsetExtraBits = []int8{ - 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, - 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, - 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, -} - -var offsetBase = []int{ - 0x000000, 0x000001, 0x000002, 0x000003, 0x000004, - 0x000006, 0x000008, 0x00000c, 0x000010, 0x000018, - 0x000020, 0x000030, 0x000040, 0x000060, 0x000080, - 0x0000c0, 0x000100, 0x000180, 0x000200, 0x000300, - 0x000400, 0x000600, 0x000800, 0x000c00, 0x001000, - 0x001800, 0x002000, 0x003000, 0x004000, 0x006000, -} - -// The odd order in which the codegen code sizes are written. -var codegenOrder = []uint32{16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15} - -type huffmanBitWriter struct { - dst []byte - - // Data waiting to be written is the low nbits of bits. - bits uint64 - nbits uint - codegenFreq [codegenCodeCount]int32 - literalFreq []int32 - offsetFreq []int32 - codegen []uint8 - literalEncoding *huffmanEncoder - offsetEncoding *huffmanEncoder - codegenEncoding *huffmanEncoder -} - -func NewEncoder() matchfinder.Encoder { - return &huffmanBitWriter{ - literalFreq: make([]int32, maxNumLit), - offsetFreq: make([]int32, offsetCodeCount), - codegen: make([]uint8, maxNumLit+offsetCodeCount+1), - literalEncoding: newHuffmanEncoder(maxNumLit), - codegenEncoding: newHuffmanEncoder(codegenCodeCount), - offsetEncoding: newHuffmanEncoder(offsetCodeCount), - } -} - -func (w *huffmanBitWriter) Reset() { - w.bits, w.nbits = 0, 0 -} - -func (w *huffmanBitWriter) flush() { - dst := w.dst - for w.nbits != 0 { - dst = append(dst, byte(w.bits)) - w.bits >>= 8 - if w.nbits > 8 { // Avoid underflow - w.nbits -= 8 - } else { - w.nbits = 0 - } - } - w.bits = 0 - w.dst = dst -} - -func (w *huffmanBitWriter) writeBits(b int32, nb uint) { - w.bits |= uint64(b) << w.nbits - w.nbits += nb - if w.nbits >= 48 { - bits := w.bits - w.bits >>= 48 - w.nbits -= 48 - w.dst = append(w.dst, - byte(bits), - byte(bits>>8), - byte(bits>>16), - byte(bits>>24), - byte(bits>>32), - byte(bits>>40), - ) - } -} - -func (w *huffmanBitWriter) writeBytes(bytes []byte) { - if w.nbits&7 != 0 { - panic("writeBytes with unfinished bits") - } - for w.nbits != 0 { - w.dst = append(w.dst, byte(w.bits)) - w.bits >>= 8 - w.nbits -= 8 - } - w.dst = append(w.dst, bytes...) -} - -// RFC 1951 3.2.7 specifies a special run-length encoding for specifying -// the literal and offset lengths arrays (which are concatenated into a single -// array). This method generates that run-length encoding. -// -// The result is written into the codegen array, and the frequencies -// of each code is written into the codegenFreq array. -// Codes 0-15 are single byte codes. Codes 16-18 are followed by additional -// information. Code badCode is an end marker -// -// numLiterals The number of literals in literalEncoding -// numOffsets The number of offsets in offsetEncoding -// litenc, offenc The literal and offset encoder to use -func (w *huffmanBitWriter) generateCodegen(numLiterals int, numOffsets int, litEnc, offEnc *huffmanEncoder) { - for i := range w.codegenFreq { - w.codegenFreq[i] = 0 - } - // Note that we are using codegen both as a temporary variable for holding - // a copy of the frequencies, and as the place where we put the result. - // This is fine because the output is always shorter than the input used - // so far. - codegen := w.codegen // cache - // Copy the concatenated code sizes to codegen. Put a marker at the end. - cgnl := codegen[:numLiterals] - for i := range cgnl { - cgnl[i] = uint8(litEnc.codes[i].len) - } - - cgnl = codegen[numLiterals : numLiterals+numOffsets] - for i := range cgnl { - cgnl[i] = uint8(offEnc.codes[i].len) - } - codegen[numLiterals+numOffsets] = badCode - - size := codegen[0] - count := 1 - outIndex := 0 - for inIndex := 1; size != badCode; inIndex++ { - // INVARIANT: We have seen "count" copies of size that have not yet - // had output generated for them. - nextSize := codegen[inIndex] - if nextSize == size { - count++ - continue - } - // We need to generate codegen indicating "count" of size. - if size != 0 { - codegen[outIndex] = size - outIndex++ - w.codegenFreq[size]++ - count-- - for count >= 3 { - n := 6 - if n > count { - n = count - } - codegen[outIndex] = 16 - outIndex++ - codegen[outIndex] = uint8(n - 3) - outIndex++ - w.codegenFreq[16]++ - count -= n - } - } else { - for count >= 11 { - n := 138 - if n > count { - n = count - } - codegen[outIndex] = 18 - outIndex++ - codegen[outIndex] = uint8(n - 11) - outIndex++ - w.codegenFreq[18]++ - count -= n - } - if count >= 3 { - // count >= 3 && count <= 10 - codegen[outIndex] = 17 - outIndex++ - codegen[outIndex] = uint8(count - 3) - outIndex++ - w.codegenFreq[17]++ - count = 0 - } - } - count-- - for ; count >= 0; count-- { - codegen[outIndex] = size - outIndex++ - w.codegenFreq[size]++ - } - // Set up invariant for next time through the loop. - size = nextSize - count = 1 - } - // Marker indicating the end of the codegen. - codegen[outIndex] = badCode -} - -// dynamicSize returns the size of dynamically encoded data in bits. -func (w *huffmanBitWriter) dynamicSize(litEnc, offEnc *huffmanEncoder, extraBits int) (size, numCodegens int) { - numCodegens = len(w.codegenFreq) - for numCodegens > 4 && w.codegenFreq[codegenOrder[numCodegens-1]] == 0 { - numCodegens-- - } - header := 3 + 5 + 5 + 4 + (3 * numCodegens) + - w.codegenEncoding.bitLength(w.codegenFreq[:]) + - int(w.codegenFreq[16])*2 + - int(w.codegenFreq[17])*3 + - int(w.codegenFreq[18])*7 - size = header + - litEnc.bitLength(w.literalFreq) + - offEnc.bitLength(w.offsetFreq) + - extraBits - - return size, numCodegens -} - -// fixedSize returns the size of dynamically encoded data in bits. -func (w *huffmanBitWriter) fixedSize(extraBits int) int { - return 3 + - fixedLiteralEncoding.bitLength(w.literalFreq) + - fixedOffsetEncoding.bitLength(w.offsetFreq) + - extraBits -} - -// storedSize calculates the stored size, including header. -// The function returns the size in bits and whether the block -// fits inside a single block. -func (w *huffmanBitWriter) storedSize(in []byte) (int, bool) { - if in == nil { - return 0, false - } - if len(in) <= maxStoreBlockSize { - return (len(in) + 5) * 8, true - } - return 0, false -} - -func (w *huffmanBitWriter) writeCode(c hcode) { - w.bits |= uint64(c.code) << w.nbits - w.nbits += uint(c.len) - if w.nbits >= 48 { - bits := w.bits - w.bits >>= 48 - w.nbits -= 48 - w.dst = append(w.dst, - byte(bits), - byte(bits>>8), - byte(bits>>16), - byte(bits>>24), - byte(bits>>32), - byte(bits>>40), - ) - } -} - -// Write the header of a dynamic Huffman block to the output stream. -// -// numLiterals The number of literals specified in codegen -// numOffsets The number of offsets specified in codegen -// numCodegens The number of codegens used in codegen -func (w *huffmanBitWriter) writeDynamicHeader(numLiterals int, numOffsets int, numCodegens int, isEof bool) { - var firstBits int32 = 4 - if isEof { - firstBits = 5 - } - w.writeBits(firstBits, 3) - w.writeBits(int32(numLiterals-257), 5) - w.writeBits(int32(numOffsets-1), 5) - w.writeBits(int32(numCodegens-4), 4) - - for i := 0; i < numCodegens; i++ { - value := uint(w.codegenEncoding.codes[codegenOrder[i]].len) - w.writeBits(int32(value), 3) - } - - i := 0 - for { - var codeWord int = int(w.codegen[i]) - i++ - if codeWord == badCode { - break - } - w.writeCode(w.codegenEncoding.codes[uint32(codeWord)]) - - switch codeWord { - case 16: - w.writeBits(int32(w.codegen[i]), 2) - i++ - case 17: - w.writeBits(int32(w.codegen[i]), 3) - i++ - case 18: - w.writeBits(int32(w.codegen[i]), 7) - i++ - } - } -} - -func (w *huffmanBitWriter) writeStoredHeader(length int, isEof bool) { - var flag int32 - if isEof { - flag = 1 - } - w.writeBits(flag, 3) - w.flush() - w.writeBits(int32(length), 16) - w.writeBits(int32(^uint16(length)), 16) -} - -func (w *huffmanBitWriter) writeFixedHeader(isEof bool) { - // Indicate that we are a fixed Huffman block - var value int32 = 2 - if isEof { - value = 3 - } - w.writeBits(value, 3) -} - -// writeBlock will write a block of tokens with the smallest encoding. -func (w *huffmanBitWriter) writeBlock(matches []matchfinder.Match, eof bool, input []byte) { - numLiterals, numOffsets := w.makeStatistics(matches, input) - - var extraBits int - storedSize, storable := w.storedSize(input) - if storable { - // We only bother calculating the costs of the extra bits required by - // the length of offset fields (which will be the same for both fixed - // and dynamic encoding), if we need to compare those two encodings - // against stored encoding. - for lengthCode := lengthCodesStart + 8; lengthCode < numLiterals; lengthCode++ { - // First eight length codes have extra size = 0. - extraBits += int(w.literalFreq[lengthCode]) * int(lengthExtraBits[lengthCode-lengthCodesStart]) - } - for offsetCode := 4; offsetCode < numOffsets; offsetCode++ { - // First four offset codes have extra size = 0. - extraBits += int(w.offsetFreq[offsetCode]) * int(offsetExtraBits[offsetCode]) - } - } - - // Figure out smallest code. - // Fixed Huffman baseline. - var literalEncoding = fixedLiteralEncoding - var offsetEncoding = fixedOffsetEncoding - var size = w.fixedSize(extraBits) - - // Dynamic Huffman? - var numCodegens int - - // Generate codegen and codegenFrequencies, which indicates how to encode - // the literalEncoding and the offsetEncoding. - w.generateCodegen(numLiterals, numOffsets, w.literalEncoding, w.offsetEncoding) - w.codegenEncoding.generate(w.codegenFreq[:], 7) - dynamicSize, numCodegens := w.dynamicSize(w.literalEncoding, w.offsetEncoding, extraBits) - - if dynamicSize < size { - size = dynamicSize - literalEncoding = w.literalEncoding - offsetEncoding = w.offsetEncoding - } - - // Stored bytes? - if storable && storedSize < size { - w.writeStoredHeader(len(input), eof) - w.writeBytes(input) - return - } - - // Huffman. - if literalEncoding == fixedLiteralEncoding { - w.writeFixedHeader(eof) - } else { - w.writeDynamicHeader(numLiterals, numOffsets, numCodegens, eof) - } - - // Write the tokens. - w.writeTokens(matches, input, literalEncoding.codes, offsetEncoding.codes) - w.writeCode(literalEncoding.codes[endBlockMarker]) -} - -// makeStatistics indexes a slice of tokens, and updates -// literalFreq and offsetFreq, and generates literalEncoding -// and offsetEncoding. -// The number of literal and offset tokens is returned. -func (w *huffmanBitWriter) makeStatistics(matches []matchfinder.Match, input []byte) (numLiterals, numOffsets int) { - for i := range w.literalFreq { - w.literalFreq[i] = 0 - } - for i := range w.offsetFreq { - w.offsetFreq[i] = 0 - } - - pos := 0 - for _, m := range matches { - for _, c := range input[pos : pos+m.Unmatched] { - w.literalFreq[c]++ - } - pos += m.Unmatched - - if m.Length == 0 { - continue - } - w.literalFreq[lengthCodesStart+lengthCode(m.Length)]++ - w.offsetFreq[offsetCode(m.Distance)]++ - pos += m.Length - } - w.literalFreq[endBlockMarker]++ - - // get the number of literals - numLiterals = len(w.literalFreq) - for w.literalFreq[numLiterals-1] == 0 { - numLiterals-- - } - // get the number of offsets - numOffsets = len(w.offsetFreq) - for numOffsets > 0 && w.offsetFreq[numOffsets-1] == 0 { - numOffsets-- - } - if numOffsets == 0 { - // We haven't found a single match. If we want to go with the dynamic encoding, - // we should count at least one offset to be sure that the offset huffman tree could be encoded. - w.offsetFreq[0] = 1 - numOffsets = 1 - } - w.literalEncoding.generate(w.literalFreq, 15) - w.offsetEncoding.generate(w.offsetFreq, 15) - return -} - -// writeTokens writes a slice of tokens to the output. -// codes for literal and offset encoding must be supplied. -func (w *huffmanBitWriter) writeTokens(matches []matchfinder.Match, input []byte, leCodes, oeCodes []hcode) { - pos := 0 - for _, m := range matches { - for _, c := range input[pos : pos+m.Unmatched] { - w.writeCode(leCodes[c]) - } - pos += m.Unmatched - - // Write the length - length := m.Length - if length == 0 { - continue - } - lengthCode := lengthCode(length) - w.writeCode(leCodes[lengthCode+lengthCodesStart]) - extraLengthBits := uint(lengthExtraBits[lengthCode]) - if extraLengthBits > 0 { - extraLength := int32(length - baseMatchLength - lengthBase[lengthCode]) - w.writeBits(extraLength, extraLengthBits) - } - - // Write the offset - offset := m.Distance - offsetCode := offsetCode(offset) - w.writeCode(oeCodes[offsetCode]) - extraOffsetBits := uint(offsetExtraBits[offsetCode]) - if extraOffsetBits > 0 { - extraOffset := int32(offset - baseMatchOffset - offsetBase[offsetCode]) - w.writeBits(extraOffset, extraOffsetBits) - } - pos += m.Length - } -} - -func (w *huffmanBitWriter) Encode(dst []byte, src []byte, matches []matchfinder.Match, lastBlock bool) []byte { - w.dst = dst - - w.writeBlock(matches, lastBlock, src) - if lastBlock { - w.flush() - } - - dst = w.dst - w.dst = nil - return dst -} diff --git a/vendor/github.com/andybalholm/brotli/flate/huffman_code.go b/vendor/github.com/andybalholm/brotli/flate/huffman_code.go deleted file mode 100644 index 1d73f47d8..000000000 --- a/vendor/github.com/andybalholm/brotli/flate/huffman_code.go +++ /dev/null @@ -1,346 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package flate - -import ( - "math" - "math/bits" - "sort" -) - -// hcode is a huffman code with a bit code and bit length. -type hcode struct { - code, len uint16 -} - -type huffmanEncoder struct { - codes []hcode - freqcache []literalNode - bitCount [17]int32 - lns byLiteral // stored to avoid repeated allocation in generate - lfs byFreq // stored to avoid repeated allocation in generate -} - -type literalNode struct { - literal uint16 - freq int32 -} - -// A levelInfo describes the state of the constructed tree for a given depth. -type levelInfo struct { - // Our level. for better printing - level int32 - - // The frequency of the last node at this level - lastFreq int32 - - // The frequency of the next character to add to this level - nextCharFreq int32 - - // The frequency of the next pair (from level below) to add to this level. - // Only valid if the "needed" value of the next lower level is 0. - nextPairFreq int32 - - // The number of chains remaining to generate for this level before moving - // up to the next level - needed int32 -} - -// set sets the code and length of an hcode. -func (h *hcode) set(code uint16, length uint16) { - h.len = length - h.code = code -} - -func maxNode() literalNode { return literalNode{math.MaxUint16, math.MaxInt32} } - -func newHuffmanEncoder(size int) *huffmanEncoder { - return &huffmanEncoder{codes: make([]hcode, size)} -} - -// Generates a HuffmanCode corresponding to the fixed literal table -func generateFixedLiteralEncoding() *huffmanEncoder { - h := newHuffmanEncoder(maxNumLit) - codes := h.codes - var ch uint16 - for ch = 0; ch < maxNumLit; ch++ { - var bits uint16 - var size uint16 - switch { - case ch < 144: - // size 8, 000110000 .. 10111111 - bits = ch + 48 - size = 8 - case ch < 256: - // size 9, 110010000 .. 111111111 - bits = ch + 400 - 144 - size = 9 - case ch < 280: - // size 7, 0000000 .. 0010111 - bits = ch - 256 - size = 7 - default: - // size 8, 11000000 .. 11000111 - bits = ch + 192 - 280 - size = 8 - } - codes[ch] = hcode{code: reverseBits(bits, byte(size)), len: size} - } - return h -} - -func generateFixedOffsetEncoding() *huffmanEncoder { - h := newHuffmanEncoder(30) - codes := h.codes - for ch := range codes { - codes[ch] = hcode{code: reverseBits(uint16(ch), 5), len: 5} - } - return h -} - -var fixedLiteralEncoding *huffmanEncoder = generateFixedLiteralEncoding() -var fixedOffsetEncoding *huffmanEncoder = generateFixedOffsetEncoding() - -func (h *huffmanEncoder) bitLength(freq []int32) int { - var total int - for i, f := range freq { - if f != 0 { - total += int(f) * int(h.codes[i].len) - } - } - return total -} - -const maxBitsLimit = 16 - -// Return the number of literals assigned to each bit size in the Huffman encoding -// -// This method is only called when list.length >= 3 -// The cases of 0, 1, and 2 literals are handled by special case code. -// -// list An array of the literals with non-zero frequencies -// and their associated frequencies. The array is in order of increasing -// frequency, and has as its last element a special element with frequency -// MaxInt32 -// maxBits The maximum number of bits that should be used to encode any literal. -// Must be less than 16. -// return An integer array in which array[i] indicates the number of literals -// that should be encoded in i bits. -func (h *huffmanEncoder) bitCounts(list []literalNode, maxBits int32) []int32 { - if maxBits >= maxBitsLimit { - panic("flate: maxBits too large") - } - n := int32(len(list)) - list = list[0 : n+1] - list[n] = maxNode() - - // The tree can't have greater depth than n - 1, no matter what. This - // saves a little bit of work in some small cases - if maxBits > n-1 { - maxBits = n - 1 - } - - // Create information about each of the levels. - // A bogus "Level 0" whose sole purpose is so that - // level1.prev.needed==0. This makes level1.nextPairFreq - // be a legitimate value that never gets chosen. - var levels [maxBitsLimit]levelInfo - // leafCounts[i] counts the number of literals at the left - // of ancestors of the rightmost node at level i. - // leafCounts[i][j] is the number of literals at the left - // of the level j ancestor. - var leafCounts [maxBitsLimit][maxBitsLimit]int32 - - for level := int32(1); level <= maxBits; level++ { - // For every level, the first two items are the first two characters. - // We initialize the levels as if we had already figured this out. - levels[level] = levelInfo{ - level: level, - lastFreq: list[1].freq, - nextCharFreq: list[2].freq, - nextPairFreq: list[0].freq + list[1].freq, - } - leafCounts[level][level] = 2 - if level == 1 { - levels[level].nextPairFreq = math.MaxInt32 - } - } - - // We need a total of 2*n - 2 items at top level and have already generated 2. - levels[maxBits].needed = 2*n - 4 - - level := maxBits - for { - l := &levels[level] - if l.nextPairFreq == math.MaxInt32 && l.nextCharFreq == math.MaxInt32 { - // We've run out of both leafs and pairs. - // End all calculations for this level. - // To make sure we never come back to this level or any lower level, - // set nextPairFreq impossibly large. - l.needed = 0 - levels[level+1].nextPairFreq = math.MaxInt32 - level++ - continue - } - - prevFreq := l.lastFreq - if l.nextCharFreq < l.nextPairFreq { - // The next item on this row is a leaf node. - n := leafCounts[level][level] + 1 - l.lastFreq = l.nextCharFreq - // Lower leafCounts are the same of the previous node. - leafCounts[level][level] = n - l.nextCharFreq = list[n].freq - } else { - // The next item on this row is a pair from the previous row. - // nextPairFreq isn't valid until we generate two - // more values in the level below - l.lastFreq = l.nextPairFreq - // Take leaf counts from the lower level, except counts[level] remains the same. - copy(leafCounts[level][:level], leafCounts[level-1][:level]) - levels[l.level-1].needed = 2 - } - - if l.needed--; l.needed == 0 { - // We've done everything we need to do for this level. - // Continue calculating one level up. Fill in nextPairFreq - // of that level with the sum of the two nodes we've just calculated on - // this level. - if l.level == maxBits { - // All done! - break - } - levels[l.level+1].nextPairFreq = prevFreq + l.lastFreq - level++ - } else { - // If we stole from below, move down temporarily to replenish it. - for levels[level-1].needed > 0 { - level-- - } - } - } - - // Somethings is wrong if at the end, the top level is null or hasn't used - // all of the leaves. - if leafCounts[maxBits][maxBits] != n { - panic("leafCounts[maxBits][maxBits] != n") - } - - bitCount := h.bitCount[:maxBits+1] - bits := 1 - counts := &leafCounts[maxBits] - for level := maxBits; level > 0; level-- { - // chain.leafCount gives the number of literals requiring at least "bits" - // bits to encode. - bitCount[bits] = counts[level] - counts[level-1] - bits++ - } - return bitCount -} - -// Look at the leaves and assign them a bit count and an encoding as specified -// in RFC 1951 3.2.2 -func (h *huffmanEncoder) assignEncodingAndSize(bitCount []int32, list []literalNode) { - code := uint16(0) - for n, bits := range bitCount { - code <<= 1 - if n == 0 || bits == 0 { - continue - } - // The literals list[len(list)-bits] .. list[len(list)-bits] - // are encoded using "bits" bits, and get the values - // code, code + 1, .... The code values are - // assigned in literal order (not frequency order). - chunk := list[len(list)-int(bits):] - - h.lns.sort(chunk) - for _, node := range chunk { - h.codes[node.literal] = hcode{code: reverseBits(code, uint8(n)), len: uint16(n)} - code++ - } - list = list[0 : len(list)-int(bits)] - } -} - -// Update this Huffman Code object to be the minimum code for the specified frequency count. -// -// freq An array of frequencies, in which frequency[i] gives the frequency of literal i. -// maxBits The maximum number of bits to use for any literal. -func (h *huffmanEncoder) generate(freq []int32, maxBits int32) { - if h.freqcache == nil { - // Allocate a reusable buffer with the longest possible frequency table. - // Possible lengths are codegenCodeCount, offsetCodeCount and maxNumLit. - // The largest of these is maxNumLit, so we allocate for that case. - h.freqcache = make([]literalNode, maxNumLit+1) - } - list := h.freqcache[:len(freq)+1] - // Number of non-zero literals - count := 0 - // Set list to be the set of all non-zero literals and their frequencies - for i, f := range freq { - if f != 0 { - list[count] = literalNode{uint16(i), f} - count++ - } else { - list[count] = literalNode{} - h.codes[i].len = 0 - } - } - list[len(freq)] = literalNode{} - - list = list[:count] - if count <= 2 { - // Handle the small cases here, because they are awkward for the general case code. With - // two or fewer literals, everything has bit length 1. - for i, node := range list { - // "list" is in order of increasing literal value. - h.codes[node.literal].set(uint16(i), 1) - } - return - } - h.lfs.sort(list) - - // Get the number of literals for each bit count - bitCount := h.bitCounts(list, maxBits) - // And do the assignment - h.assignEncodingAndSize(bitCount, list) -} - -type byLiteral []literalNode - -func (s *byLiteral) sort(a []literalNode) { - *s = byLiteral(a) - sort.Sort(s) -} - -func (s byLiteral) Len() int { return len(s) } - -func (s byLiteral) Less(i, j int) bool { - return s[i].literal < s[j].literal -} - -func (s byLiteral) Swap(i, j int) { s[i], s[j] = s[j], s[i] } - -type byFreq []literalNode - -func (s *byFreq) sort(a []literalNode) { - *s = byFreq(a) - sort.Sort(s) -} - -func (s byFreq) Len() int { return len(s) } - -func (s byFreq) Less(i, j int) bool { - if s[i].freq == s[j].freq { - return s[i].literal < s[j].literal - } - return s[i].freq < s[j].freq -} - -func (s byFreq) Swap(i, j int) { s[i], s[j] = s[j], s[i] } - -func reverseBits(number uint16, bitLength byte) uint16 { - return bits.Reverse16(number << (16 - bitLength)) -} diff --git a/vendor/github.com/andybalholm/brotli/flate/token.go b/vendor/github.com/andybalholm/brotli/flate/token.go deleted file mode 100644 index 415b1b5e4..000000000 --- a/vendor/github.com/andybalholm/brotli/flate/token.go +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package flate - -import "log" - -// The length code for length X (MIN_MATCH_LENGTH <= X <= MAX_MATCH_LENGTH) -// is lengthCodes[length - MIN_MATCH_LENGTH] -var lengthCodes = [...]uint32{ - 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, - 9, 9, 10, 10, 11, 11, 12, 12, 12, 12, - 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, - 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, - 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, - 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, - 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, - 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, - 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, - 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, - 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, - 22, 22, 23, 23, 23, 23, 23, 23, 23, 23, - 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, - 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, - 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, - 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, - 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, - 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, - 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, - 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, - 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, - 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, - 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, - 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, - 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, - 27, 27, 27, 27, 27, 28, -} - -var offsetCodes = [...]uint32{ - 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, - 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, - 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, - 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, - 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, - 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, - 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, - 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, - 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, - 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, - 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, - 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, -} - -func lengthCode(len int) uint32 { - if len > 258 { - panic("match too long") - } - return lengthCodes[len-baseMatchLength] -} - -// Returns the offset code corresponding to a specific offset -func offsetCode(off int) uint32 { - if off > 32768 { - log.Println(off) - panic("match distance too high") - } - off -= baseMatchOffset - if off < len(offsetCodes) { - return offsetCodes[off] - } - if off>>7 < len(offsetCodes) { - return offsetCodes[off>>7] + 14 - } - return offsetCodes[off>>14] + 28 -} diff --git a/vendor/github.com/andybalholm/brotli/flate/writer.go b/vendor/github.com/andybalholm/brotli/flate/writer.go deleted file mode 100644 index 1e49d4897..000000000 --- a/vendor/github.com/andybalholm/brotli/flate/writer.go +++ /dev/null @@ -1,66 +0,0 @@ -package flate - -import ( - "io" - - "github.com/andybalholm/brotli/matchfinder" -) - -// NewWriter returns a new matchfinder.Writer that compresses data at the given level, -// in flate encoding. Levels 1–9 are available; levels outside this range will -// be replaced with the closest level available. -func NewWriter(w io.Writer, level int) *matchfinder.Writer { - return newWriter(w, level, NewEncoder()) -} - -// NewGZIPWriter returns a new matchfinder.Writer that compresses data at the given -// level, in gzip encoding. Levels 1–9 are available; levels outside this range -// will be replaced by the closest level available. -func NewGZIPWriter(w io.Writer, level int) *matchfinder.Writer { - return newWriter(w, level, NewGZIPEncoder()) -} - -func newWriter(w io.Writer, level int, e matchfinder.Encoder) *matchfinder.Writer { - var mf matchfinder.MatchFinder - if level < 2 { - mf = &matchfinder.ZFast{MaxDistance: 1 << 15} - } else if level == 2 { - mf = &matchfinder.ZDFast{MaxDistance: 1 << 15} - } else if level == 3 { - mf = &matchfinder.ZM{MaxDistance: 1 << 15} - } else if level == 4 { - mf = &matchfinder.Trio{MaxDistance: 1 << 15} - } else if level < 8 { - chainLen := 32 - switch level { - case 5: - chainLen = 8 - case 6: - chainLen = 16 - } - mf = &matchfinder.M4{ - MaxDistance: 1 << 15, - ChainLength: chainLen, - HashLen: 5, - DistanceBitCost: 66, - } - } else { - chainLen := 32 - hashLen := 5 - if level == 8 { - chainLen = 4 - } - mf = &matchfinder.Pathfinder{ - MaxDistance: 1 << 15, - ChainLength: chainLen, - HashLen: hashLen, - } - } - - return &matchfinder.Writer{ - Dest: w, - MatchFinder: mf, - Encoder: e, - BlockSize: 1 << 16, - } -} diff --git a/vendor/github.com/andybalholm/brotli/http.go b/vendor/github.com/andybalholm/brotli/http.go index 4640519a0..621eb0c29 100644 --- a/vendor/github.com/andybalholm/brotli/http.go +++ b/vendor/github.com/andybalholm/brotli/http.go @@ -1,11 +1,10 @@ package brotli import ( + "compress/gzip" "io" "net/http" "strings" - - "github.com/andybalholm/brotli/flate" ) // HTTPCompressor chooses a compression method (brotli, gzip, or none) based on @@ -25,10 +24,12 @@ func HTTPCompressorWithLevel(w http.ResponseWriter, r *http.Request, level int) switch encoding { case "br": w.Header().Set("Content-Encoding", "br") - return NewWriterV2(w, level) + return NewWriterLevel(w, level) case "gzip": - w.Header().Set("Content-Encoding", "gzip") - return flate.NewGZIPWriter(w, level) + if gzw, err := gzip.NewWriterLevel(w, level); err == nil { + w.Header().Set("Content-Encoding", "gzip") + return gzw + } } return nopCloser{w} } diff --git a/vendor/modules.txt b/vendor/modules.txt index f56f7928d..479601cbb 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -17,10 +17,9 @@ github.com/PuerkitoBio/goquery # github.com/Soontao/goHttpDigestClient v0.0.0-20170320082612-6d28bb1415c5 ## explicit github.com/Soontao/goHttpDigestClient -# github.com/andybalholm/brotli v1.2.2 +# github.com/andybalholm/brotli v1.2.3 ## explicit; go 1.22 github.com/andybalholm/brotli -github.com/andybalholm/brotli/flate github.com/andybalholm/brotli/matchfinder # github.com/andybalholm/cascadia v1.3.3 ## explicit; go 1.16 From 5cec142a5f1a7b21aec669b773c5c33fbbdc888c Mon Sep 17 00:00:00 2001 From: Gouranga Das Samrat Date: Thu, 10 Sep 2026 19:10:07 +0600 Subject: [PATCH 137/182] fix: resolve 32-bit overflow issues (#6385) - Use strconv.FormatInt with int64 cast for maxSafeInteger - Explicitly cast uint32 limits to uint64 in error formatting --- internal/dashboard/sse.go | 2 +- internal/output/prometheusrw/remote/client.go | 2 +- output/cloud/expv2/metrics_client.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/dashboard/sse.go b/internal/dashboard/sse.go index e8287ad2c..0e3ae99ce 100644 --- a/internal/dashboard/sse.go +++ b/internal/dashboard/sse.go @@ -80,7 +80,7 @@ func (emitter *eventEmitter) onEvent(name string, data any) { var retry []byte if name == stopEvent { - retry = []byte(strconv.Itoa(maxSafeInteger)) + retry = []byte(strconv.FormatInt(int64(maxSafeInteger), 10)) } id := strconv.FormatInt(emitter.id.Add(1), 10) diff --git a/internal/output/prometheusrw/remote/client.go b/internal/output/prometheusrw/remote/client.go index 7f1db14a7..a4efb78e2 100644 --- a/internal/output/prometheusrw/remote/client.go +++ b/internal/output/prometheusrw/remote/client.go @@ -128,7 +128,7 @@ func newWriteRequestBody(series []*prompb.TimeSeries) ([]byte, error) { } if snappy.MaxEncodedLen(len(b)) < 0 { return nil, fmt.Errorf("the protobuf message is too large to be handled by Snappy encoder; "+ - "size: %d, limit: %d", len(b), math.MaxUint32) + "size: %d, limit: %d", len(b), uint64(math.MaxUint32)) } return snappy.Encode(nil, b), nil } diff --git a/output/cloud/expv2/metrics_client.go b/output/cloud/expv2/metrics_client.go index f0131b2a3..34203f5c6 100644 --- a/output/cloud/expv2/metrics_client.go +++ b/output/cloud/expv2/metrics_client.go @@ -101,7 +101,7 @@ func newRequestBody(data *pbcloud.MetricSet) ([]byte, error) { // https://pkg.go.dev/github.com/klauspost/compress/snappy#NewBufferedWriter if snappy.MaxEncodedLen(len(b)) < 0 { return nil, fmt.Errorf("the Protobuf message is too large to be handled by Snappy encoder; "+ - "size: %d, limit: %d", len(b), 0xffffffff) + "size: %d, limit: %d", len(b), uint64(0xffffffff)) } return snappy.Encode(nil, b), nil } From 03786f49338170c1737775e3db67eacc4d0355e9 Mon Sep 17 00:00:00 2001 From: Rohan Patnaik Date: Thu, 10 Sep 2026 18:49:58 +0530 Subject: [PATCH 138/182] feat: add remote write labels (#6071) --- .../output/prometheusrw/remotewrite/config.go | 21 +++++++++ .../prometheusrw/remotewrite/config_test.go | 40 +++++++++++++++++ .../prometheusrw/remotewrite/prometheus.go | 26 +++++++++++ .../remotewrite/prometheus_test.go | 9 ++++ .../prometheusrw/remotewrite/remotewrite.go | 11 ++++- .../remotewrite/remotewrite_test.go | 43 +++++++++++++++++++ 6 files changed, 149 insertions(+), 1 deletion(-) diff --git a/internal/output/prometheusrw/remotewrite/config.go b/internal/output/prometheusrw/remotewrite/config.go index 5afbc0bd7..73809c806 100644 --- a/internal/output/prometheusrw/remotewrite/config.go +++ b/internal/output/prometheusrw/remotewrite/config.go @@ -36,6 +36,9 @@ type Config struct { // Headers contains additional headers that should be included in the HTTP requests. Headers map[string]string `json:"headers"` + // Labels contains additional labels that should be included in the remote write time series. + Labels map[string]string `json:"labels"` + // InsecureSkipTLSVerify skips TLS client side checks. InsecureSkipTLSVerify null.Bool `json:"insecureSkipTLSVerify" envconfig:"K6_PROMETHEUS_RW_INSECURE_SKIP_TLS_VERIFY"` @@ -224,6 +227,13 @@ func (conf Config) Apply(applied Config) Config { maps.Copy(conf.Headers, applied.Headers) } + if len(applied.Labels) > 0 { + if conf.Labels == nil { + conf.Labels = make(map[string]string) + } + maps.Copy(conf.Labels, applied.Labels) + } + if len(applied.TrendStats) > 0 { conf.TrendStats = make([]string, len(applied.TrendStats)) copy(conf.TrendStats, applied.TrendStats) @@ -291,6 +301,7 @@ func envMap(env map[string]string, prefix string) map[string]string { func parseEnvs(env map[string]string) (Config, error) { c := Config{ Headers: make(map[string]string), + Labels: make(map[string]string), } err := envconfig.Process("", &c, func(key string) (string, bool) { @@ -316,6 +327,16 @@ func parseEnvs(env map[string]string) (Config, error) { } } + if labels, labelsDefined := env["K6_PROMETHEUS_RW_LABELS"]; labelsDefined { + for kvPair := range strings.SplitSeq(labels, ",") { + key, value, ok := strings.Cut(kvPair, "=") + if !ok { + return c, fmt.Errorf("the provided label (%s) does not respect the expected format

Test
  1. One
` func TestNestedFrames(t *testing.T) { @@ -441,7 +436,7 @@ func TestPageInnerHTML(t *testing.T) { err := p.SetContent(sampleHTML, nil) require.NoError(t, err) popts := common.NewFrameInnerHTMLOptions(p.MainFrame().Timeout()) - require.NoError(t, popts.Parse(tb.vu.Context(), tb.toSobekValue(jsFrameBaseOpts{Timeout: "100"}))) + popts.Timeout = 100 * time.Millisecond _, err = p.InnerHTML("p", popts) require.Error(t, err) }) @@ -479,7 +474,7 @@ func TestPageInnerText(t *testing.T) { require.NoError(t, err) popts := common.NewFrameInnerTextOptions(p.MainFrame().Timeout()) - require.NoError(t, popts.Parse(tb.vu.Context(), tb.toSobekValue(jsFrameBaseOpts{Timeout: "100"}))) + popts.Timeout = 100 * time.Millisecond _, err = p.InnerText("p", popts) require.Error(t, err) }) From 76499d090cce5fe2ee00812eaa371fc0132e291a Mon Sep 17 00:00:00 2001 From: Inanc Gumus Date: Thu, 10 Sep 2026 11:27:26 -0400 Subject: [PATCH 141/182] Identify unique installations in anonymous usage reports (#6370) * Identify unique installations in usage reports Counting unique k6 installations needs a stable per-machine token. A random UUID kept beside the config carries no personal data, and a storage failure stays silent at debug level. * Test installation ID creation and reuse The same ID must come back on every run, and a stored value that is not a UUID is replaced by a fresh one. * Test a new ID after the stored one is gone A wiped config directory must keep reporting, so a missing file yields a fresh ID instead of an error. * Test that storage failures reach the caller Every failed read, write, or permission change must return an error, so the report omits the ID instead of claiming one k6 could not store. * Test owner-only installation ID permissions The ID must stay readable by its owner alone, including when the directory or the file already allows wider access. * Test the installation ID through the CLI The ID must reach the report from the run and the subcommand path alike, stay out of it when the user opts out, and never surface a storage failure to that user. --- internal/cmd/report.go | 47 +++++- internal/cmd/report_test.go | 142 ++++++++++++++++ .../cmd/tests/cmd_installation_id_test.go | 152 ++++++++++++++++++ internal/cmd/tests/test_state.go | 11 +- 4 files changed, 346 insertions(+), 6 deletions(-) create mode 100644 internal/cmd/tests/cmd_installation_id_test.go diff --git a/internal/cmd/report.go b/internal/cmd/report.go index 231f66d19..b0d32b0a5 100644 --- a/internal/cmd/report.go +++ b/internal/cmd/report.go @@ -4,16 +4,22 @@ import ( "bytes" "context" "encoding/json" + "errors" + "io/fs" "net/http" + "path/filepath" "runtime" "strconv" "time" + "github.com/google/uuid" + "go.k6.io/k6/v2/cmd/state" "go.k6.io/k6/v2/ext" "go.k6.io/k6/v2/internal/build" "go.k6.io/k6/v2/internal/execution" "go.k6.io/k6/v2/internal/usage" + "go.k6.io/k6/v2/lib/fsext" ) // extensionEntry identifies a used extension in the usage report by its Go @@ -142,13 +148,52 @@ func reportUsage(ctx context.Context, gs *state.GlobalState, create func(ctx con defer cancel() gs.Logger.Debug("Sending usage report...") - if err := postUsageReport(reportCtx, envLookup(gs.Env), create(reportCtx)); err != nil { + + m := create(reportCtx) + if id, err := installationID(gs); err != nil { + gs.Logger.WithError(err).Debug("Omitting the installation ID from the usage report") + } else { + m["installation_id"] = id + } + + if err := postUsageReport(reportCtx, envLookup(gs.Env), m); err != nil { gs.Logger.WithError(err).Debug("Error sending usage report") } else { gs.Logger.Debug("Usage report sent successfully") } } +func installationID(gs *state.GlobalState) (string, error) { + path := filepath.Join(gs.UserOSConfigDir, "k6", "installation-id") + + stored, err := fsext.ReadFile(gs.FS, path) + if err != nil && !errors.Is(err, fs.ErrNotExist) { + return "", err + } + if id, err := uuid.ParseBytes(stored); err == nil { + return id.String(), nil + } + + id, err := uuid.NewRandom() + if err != nil { + return "", err + } + dir := filepath.Dir(path) + if err := gs.FS.MkdirAll(dir, configDirMode); err != nil { + return "", err + } + if err := gs.FS.Chmod(dir, configDirMode); err != nil { + return "", err + } + if err := fsext.WriteFile(gs.FS, path, []byte(id.String()), configFileMode); err != nil { + return "", err + } + if err := gs.FS.Chmod(path, configFileMode); err != nil { + return "", err + } + return id.String(), nil +} + // defaultUsageReportURL is the production endpoint the anonymous usage report // is sent to when K6_USAGE_REPORT_URL is not set. const defaultUsageReportURL = "https://stats.grafana.org/k6-usage-report" diff --git a/internal/cmd/report_test.go b/internal/cmd/report_test.go index 0e46f1721..d851d79f0 100644 --- a/internal/cmd/report_test.go +++ b/internal/cmd/report_test.go @@ -1,11 +1,15 @@ package cmd import ( + "io/fs" + "path/filepath" "testing" "time" + "github.com/google/uuid" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.k6.io/k6/v2/cmd/state" "go.k6.io/k6/v2/internal/build" "go.k6.io/k6/v2/internal/execution" "go.k6.io/k6/v2/internal/execution/local" @@ -13,6 +17,7 @@ import ( "go.k6.io/k6/v2/internal/usage" "go.k6.io/k6/v2/lib" "go.k6.io/k6/v2/lib/executor" + "go.k6.io/k6/v2/lib/fsext" "gopkg.in/guregu/null.v3" ) @@ -108,6 +113,143 @@ func TestCreateReport(t *testing.T) { }) } +func TestInstallationID(t *testing.T) { + t.Parallel() + + const storedID = "123e4567-e89b-42d3-a456-426614174000" + + tests := []struct { + name string + stored string + want string + }{ + {name: "creates a UUID when none is stored"}, + {name: "reuses the stored UUID", stored: storedID, want: storedID}, + {name: "replaces an invalid stored value", stored: "not-a-uuid"}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + configDir := t.TempDir() + path := filepath.Join(configDir, "k6", "installation-id") + gs := &state.GlobalState{FS: fsext.NewOsFs(), UserOSConfigDir: configDir} + if tt.stored != "" { + require.NoError(t, gs.FS.MkdirAll(filepath.Dir(path), configDirMode)) + require.NoError(t, fsext.WriteFile(gs.FS, path, []byte(tt.stored), configFileMode)) + } + + got, err := installationID(gs) + + require.NoError(t, err) + require.NoError(t, uuid.Validate(got)) + if tt.want != "" { + require.Equal(t, tt.want, got) + } + saved, err := fsext.ReadFile(gs.FS, path) + require.NoError(t, err) + require.Equal(t, got, string(saved)) + }) + } +} + +func TestInstallationIDCreatesANewUUIDAfterDeletion(t *testing.T) { + t.Parallel() + + configDir := t.TempDir() + gs := &state.GlobalState{FS: fsext.NewOsFs(), UserOSConfigDir: configDir} + + first, err := installationID(gs) + require.NoError(t, err) + require.NoError(t, gs.FS.Remove(filepath.Join(configDir, "k6", "installation-id"))) + + second, err := installationID(gs) + + require.NoError(t, err) + require.NoError(t, uuid.Validate(second)) + require.NotEqual(t, first, second) +} + +func TestInstallationIDStorageErrors(t *testing.T) { + t.Parallel() + + idPath := filepath.Join(".config", "k6", "installation-id") + + tests := []struct { + name string + denied string + access int + }{ + {name: "the stored UUID cannot be read", denied: idPath, access: 1}, + {name: "the directory cannot be created", denied: filepath.Dir(idPath), access: 1}, + {name: "the new UUID cannot be saved", denied: idPath, access: 2}, + {name: "the directory permissions cannot be tightened", denied: filepath.Dir(idPath), access: 2}, + {name: "the file permissions cannot be tightened", denied: idPath, access: 3}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + accesses := 0 + denyingFS := fsext.NewChangePathFs(fsext.NewMemMapFs(), func(name string) (string, error) { + if name != tt.denied { + return name, nil + } + accesses++ + if accesses == tt.access { + return "", fs.ErrPermission + } + return name, nil + }) + gs := &state.GlobalState{FS: denyingFS, UserOSConfigDir: ".config"} + + got, err := installationID(gs) + + require.ErrorIs(t, err, fs.ErrPermission) + require.Empty(t, got) + }) + } +} + +func TestInstallationIDUsesSecurePermissions(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + dirMode fs.FileMode + fileMode fs.FileMode + }{ + {name: "creates them with owner-only access"}, + {name: "tightens pre-existing loose access", dirMode: 0o755, fileMode: 0o644}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + gs := &state.GlobalState{FS: fsext.NewMemMapFs(), UserOSConfigDir: ".config"} + path := filepath.Join(".config", "k6", "installation-id") + if tt.dirMode != 0 { + require.NoError(t, gs.FS.MkdirAll(filepath.Dir(path), tt.dirMode)) + require.NoError(t, fsext.WriteFile(gs.FS, path, []byte("not-a-uuid"), tt.fileMode)) + } + + _, err := installationID(gs) + require.NoError(t, err) + + finfo, err := gs.FS.Stat(path) + require.NoError(t, err) + assert.Equal(t, configFileMode, finfo.Mode().Perm()) + + dinfo, err := gs.FS.Stat(filepath.Dir(path)) + require.NoError(t, err) + assert.Equal(t, configDirMode, dinfo.Mode().Perm()) + }) + } +} + //nolint:paralleltest // swaps the package-global build.BuildOrigin, so the subtests must run serially. func TestCreateReportBuildOrigin(t *testing.T) { logger := testutils.NewLogger(t) diff --git a/internal/cmd/tests/cmd_installation_id_test.go b/internal/cmd/tests/cmd_installation_id_test.go new file mode 100644 index 000000000..d7ad04090 --- /dev/null +++ b/internal/cmd/tests/cmd_installation_id_test.go @@ -0,0 +1,152 @@ +package tests + +import ( + "bytes" + "encoding/json" + "io" + "io/fs" + "net/http" + "net/http/httptest" + "path/filepath" + "slices" + "strconv" + "strings" + "sync/atomic" + "testing" + + "github.com/google/uuid" + "github.com/sirupsen/logrus" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "go.k6.io/k6/v2/cmd/state" + "go.k6.io/k6/v2/internal/cmd" + "go.k6.io/k6/v2/internal/lib/testutils" + "go.k6.io/k6/v2/lib/fsext" +) + +func TestUsageReportInstallationID(t *testing.T) { + t.Parallel() + + registerReportTestSubcommand(t) + + tests := []struct { + name string + args []string + script string + configPath string + optOut bool + failedFS bool + }{ + { + name: "run reports the installation ID", + args: []string{"run", "-"}, + script: `export default function() {};`, + }, + { + name: "subcommand reports the installation ID", + args: []string{"x", "testsub"}, + }, + { + name: "a custom config path does not move the installation ID", + args: []string{"run", "-"}, + script: `export default function() {};`, + configPath: "elsewhere/k6.json", + }, + { + name: "run opt-out reports nothing and stores nothing", + args: []string{"run", "-"}, + script: `export default function() {};`, + optOut: true, + }, + { + name: "subcommand opt-out reports nothing and stores nothing", + args: []string{"x", "testsub"}, + optOut: true, + }, + { + name: "the installation ID it cannot store stays out of the report and the output", + args: []string{"x", "testsub"}, + failedFS: true, + }, + { + name: "the storage failure surfaces at debug level", + args: []string{"run", "-v", "-"}, + script: `export default function() {};`, + failedFS: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + var reportCount atomic.Int32 + var gotBody atomic.Value + reportServer := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) { + body, err := io.ReadAll(r.Body) + assert.NoError(t, err) + gotBody.Store(body) + reportCount.Add(1) + })) + t.Cleanup(reportServer.Close) + + ts := NewGlobalTestState(t) + ts.Env["K6_NO_USAGE_REPORT"] = strconv.FormatBool(tt.optOut) + ts.Env[state.UsageReportURL] = reportServer.URL + if tt.configPath != "" { + require.NoError(t, fsext.WriteFile(ts.FS, tt.configPath, []byte("{}"), 0o600)) + ts.Env["K6_CONFIG"] = tt.configPath + } + var idAccesses atomic.Int32 + ts.FS = fsext.NewChangePathFs(ts.FS, func(name string) (string, error) { + if !strings.HasSuffix(name, "installation-id") { + return name, nil + } + idAccesses.Add(1) + if tt.failedFS { + return "", fs.ErrPermission + } + return name, nil + }) + ts.CmdArgs = append([]string{"k6"}, tt.args...) + ts.Stdin = bytes.NewBufferString(tt.script) + ts.ReparseFlags() + + cmd.ExecuteWithGlobalState(ts.GlobalState) + + if tt.optOut { + require.Zero(t, reportCount.Load()) + require.Zero(t, idAccesses.Load()) + return + } + + require.Equal(t, int32(1), reportCount.Load()) + raw, ok := gotBody.Load().([]byte) + require.True(t, ok) + var report map[string]any + require.NoError(t, json.Unmarshal(raw, &report)) + require.NotEmpty(t, report["k6_version"]) + + if tt.failedFS { + require.NotContains(t, report, "installation_id") + + entries := ts.LoggerHook.Drain() + if slices.Contains(tt.args, "-v") { + require.True(t, testutils.LogContains(entries, logrus.DebugLevel, "Omitting the installation ID")) + return + } + require.Empty(t, entries) + require.Empty(t, ts.Stdout.String()) + return + } + + id, ok := report["installation_id"].(string) + require.True(t, ok) + require.NoError(t, uuid.Validate(id)) + saved, err := fsext.ReadFile(ts.FS, filepath.Join(".config", "k6", "installation-id")) + require.NoError(t, err) + require.Equal(t, id, string(saved)) + }) + } +} diff --git a/internal/cmd/tests/test_state.go b/internal/cmd/tests/test_state.go index d4e1dfd6b..864061066 100644 --- a/internal/cmd/tests/test_state.go +++ b/internal/cmd/tests/test_state.go @@ -90,11 +90,12 @@ func NewGlobalTestState(tb testing.TB) *GlobalTestState { defaultFlags := state.GetDefaultFlags(".config", ".cache") ts.GlobalState = &state.GlobalState{ - Ctx: ctx, - FS: fs, - Getwd: func() (string, error) { return ts.Cwd, nil }, - BinaryName: "k6", - CmdArgs: []string{}, + Ctx: ctx, + FS: fs, + Getwd: func() (string, error) { return ts.Cwd, nil }, + UserOSConfigDir: ".config", + BinaryName: "k6", + CmdArgs: []string{}, Env: map[string]string{ "K6_NO_USAGE_REPORT": "true", // Keep `k6 x` command-tree construction off the real registry.k6.io From 8589b24bc14817ecf2194d339d51e208d670d405 Mon Sep 17 00:00:00 2001 From: HwangRock <157935545+HwangRock@users.noreply.github.com> Date: Fri, 11 Sep 2026 06:50:55 +0900 Subject: [PATCH 142/182] fix: handle VU start error in ramping VUs executor (#5922) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: handle VU start error in ramping VUs executor scheduledVUsHandlerStrategy silently discarded the error from vuHandle.start() via `_ = ...start()`. When GetPlannedVU cannot pull a VU from the buffer (e.g. under overload) the executor was left in an inconsistent state. Log the error and cancel the executor, matching the pattern already used in runLoopsIfPossible. Propagate the cancellation by switching iterateSteps and runRemainingGracefulSteps to maxDurationCtx, and make waiter honor ctx cancellation for past-due steps (diff <= 0) so step scheduling stops promptly after a start failure instead of retrying until the planned schedule completes. * fix: surface VU start error from ramping VUs executor getVU() already logs the failure, so the extra "Cannot start a VU" line was a duplicate. Record the error on the run state instead and return it from Run(), so the failure reaches the scheduler like the other executors do. * fix: don't double-log VU start failures in ramping VUs executor getVU() logged the failure and Run() now returns it, so the scheduler logged it again — two error lines for one failure. Drop the executor's own log and let the scheduler report it, like the other executors do. Add a scheduler-level test asserting the failure is logged exactly once. --- internal/execution/scheduler_ext_test.go | 54 ++++++++++ lib/executor/ramping_vus.go | 35 +++++-- lib/executor/ramping_vus_test.go | 127 +++++++++++++++++++++++ 3 files changed, 210 insertions(+), 6 deletions(-) diff --git a/internal/execution/scheduler_ext_test.go b/internal/execution/scheduler_ext_test.go index d69caea48..e75c880fd 100644 --- a/internal/execution/scheduler_ext_test.go +++ b/internal/execution/scheduler_ext_test.go @@ -943,6 +943,60 @@ func TestSchedulerEndErrors(t *testing.T) { assert.Empty(t, hook.Entries) } +// TestSchedulerRampingVUsStartErrorLoggedOnce checks that, when a VU-start +// failure occurs during a real scheduler run, the failure is logged exactly +// once. The ramping VUs executor used to log the failure itself and then +// return it to the scheduler, which logs every non-nil executor result, +// producing two error-level entries for a single failure. +func TestSchedulerRampingVUsStartErrorLoggedOnce(t *testing.T) { + t.Parallel() + + config := executor.NewRampingVUsConfig("myscenario") + config.GracefulStop = types.NullDurationFrom(0) + config.StartVUs = null.IntFrom(2) + config.Stages = []executor.Stage{ + {Duration: types.NullDurationFrom(time.Second), Target: null.IntFrom(2)}, + } + + runner := &minirunner.MiniRunner{ + Fn: func(_ context.Context, _ *lib.State, _ chan<- metrics.SampleContainer) error { + return nil + }, + Options: lib.Options{ + Scenarios: lib.ScenarioConfigs{config.GetName(): config}, + }, + } + + logger, hook := logtest.NewNullLogger() + ctx, cancel, execScheduler, samples := newTestScheduler(t, runner, logger, lib.Options{}) + defer cancel() + + // Drain every planned VU so the executor cannot fetch one when it tries + // to start VUs, reproducing a "system overload" VU-start failure. + state := execScheduler.GetState() + maxVUs := lib.GetMaxPlannedVUs(config.GetExecutionRequirements(state.ExecutionTuple)) + entry := logrus.NewEntry(logger) + for range maxVUs { + _, err := state.GetPlannedVU(entry, false) + require.NoError(t, err) + } + + // Run through the real scheduler, not executor.Run() directly, since + // that's the path that determines how many times the failure is logged. + runErr := execScheduler.Run(ctx, ctx, samples) + require.Error(t, runErr) + require.Contains(t, runErr.Error(), "could not get a VU from the buffer in") + + var errorEntries []*logrus.Entry + for _, e := range hook.AllEntries() { + if e.Level == logrus.ErrorLevel { + errorEntries = append(errorEntries, e) + } + } + require.Len(t, errorEntries, 1, + "the VU-start failure must be logged exactly once, by the scheduler that receives it from Run()") +} + func TestSchedulerEndIterations(t *testing.T) { t.Parallel() registry := metrics.NewRegistry() diff --git a/lib/executor/ramping_vus.go b/lib/executor/ramping_vus.go index f0a3ea87d..ace1c0697 100644 --- a/lib/executor/ramping_vus.go +++ b/lib/executor/ramping_vus.go @@ -527,6 +527,7 @@ func (vlv *RampingVUs) Run(ctx context.Context, _ chan<- metrics.SampleContainer activeVUsCount: new(int64), started: startTime, runIteration: getIterationRunner(vlv.executionState, vlv.logger), + cancel: cancel, } progressFn := runState.makeProgressFn(regularDuration) @@ -551,16 +552,16 @@ func (vlv *RampingVUs) Run(ctx context.Context, _ chan<- metrics.SampleContainer handleNewScheduledVUs = runState.scheduledVUsHandlerStrategy() ) handledGracefulSteps := runState.iterateSteps( - ctx, + maxDurationCtx, handleNewMaxAllowedVUs, handleNewScheduledVUs, ) go runState.runRemainingGracefulSteps( - ctx, + maxDurationCtx, handleNewMaxAllowedVUs, handledGracefulSteps, ) - return nil + return runState.startErr } // rampingVUsRunState is created and initialized by the Run() method @@ -575,6 +576,13 @@ type rampingVUsRunState struct { wg sync.WaitGroup runIteration func(context.Context, lib.ActiveVU) bool // a helper closure function that runs a single iteration + cancel func() + + // startErr holds a VU-start failure so Run() can return it to its caller. + // It's only written and read from the Run() goroutine: the + // scheduledVUsHandlerStrategy() closure that sets it is invoked exclusively + // from iterateSteps(), which Run() calls synchronously (not in a goroutine). + startErr error } func (rs *rampingVUsRunState) makeProgressFn(regular time.Duration) (progressFn func() (float64, []string)) { @@ -597,7 +605,6 @@ func (rs *rampingVUsRunState) runLoopsIfPossible(ctx context.Context, cancel fun getVU := func() (lib.InitializedVU, error) { pvu, err := rs.executor.executionState.GetPlannedVU(rs.executor.logger, false) if err != nil { - rs.executor.logger.WithError(err).Error("Cannot get a VU from the buffer") cancel() return pvu, err } @@ -642,6 +649,9 @@ func (rs *rampingVUsRunState) iterateSteps( break } handleNewScheduledVUs(r) + if rs.startErr != nil { + break + } i++ } } @@ -685,7 +695,13 @@ func (rs *rampingVUsRunState) scheduledVUsHandlerStrategy() func(lib.ExecutionSt return func(raw lib.ExecutionStep) { pv := raw.PlannedVUs for ; cur < pv; cur++ { - _ = rs.vuHandles[cur].start() // TODO: handle the error + if err := rs.vuHandles[cur].start(); err != nil { + // Record the error so Run() can return it; the scheduler logs + // it once the executor returns. + rs.startErr = err + rs.cancel() + return + } } for ; pv < cur; cur-- { rs.vuHandles[cur-1].gracefulStop() @@ -711,7 +727,14 @@ func waiter(ctx context.Context, start time.Time) func(offset time.Duration) boo // now we do a step } } - return false + // honor cancellation even for past-due steps, where diff <= 0 and the + // select above is skipped + select { + case <-ctx.Done(): + return true + default: + return false + } } } diff --git a/lib/executor/ramping_vus_test.go b/lib/executor/ramping_vus_test.go index 81583a8b5..85120241c 100644 --- a/lib/executor/ramping_vus_test.go +++ b/lib/executor/ramping_vus_test.go @@ -6,17 +6,21 @@ import ( "fmt" "math/big" "math/rand" + "strings" "sync/atomic" "testing" "testing/synctest" "time" + "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "gopkg.in/guregu/null.v3" + "go.k6.io/k6/v2/internal/lib/testutils" "go.k6.io/k6/v2/lib" "go.k6.io/k6/v2/lib/types" + "go.k6.io/k6/v2/metrics" ) func TestRampingVUsConfigValidation(t *testing.T) { @@ -1210,3 +1214,126 @@ func TestSumRandomSegmentSequenceMatchesNoSegment(t *testing.T) { }) } } + +// TestRampingVUsVUStartError checks that a VU-start failure is returned by +// Run() instead of being swallowed, and that the executor doesn't log it +// itself, leaving that to the scheduler that receives the error. +func TestRampingVUsVUStartError(t *testing.T) { + t.Parallel() + + // The executor needs to start VUs immediately, which exercises the + // VU-start failure path once the planned VU buffer is exhausted. + config := RampingVUsConfig{ + BaseConfig: BaseConfig{GracefulStop: types.NullDurationFrom(0)}, + StartVUs: null.IntFrom(2), + Stages: []Stage{ + {Duration: types.NullDurationFrom(time.Second), Target: null.IntFrom(2)}, + }, + } + + runner := simpleRunner(func(_ context.Context, _ *lib.State) error { return nil }) + test := setupExecutorTest(t, "", "", lib.Options{}, runner, config) + defer test.cancel() + + // getVU() no longer logs the failure itself: it's returned from Run() + // instead, and it's the scheduler's job to log it once it receives that + // result. Attach a dedicated error hook to prove the executor stays quiet. + errorHook := testutils.NewLogHook(logrus.ErrorLevel) + test.executor.GetLogger().Logger.AddHook(errorHook) + + // Reproduce a "system overload" condition: drain every planned VU so the + // executor cannot fetch one when it tries to start VUs. + maxVUs := lib.GetMaxPlannedVUs(config.GetExecutionRequirements(test.state.ExecutionTuple)) + for range maxVUs { + _, err := test.state.GetPlannedVU(test.executor.GetLogger(), false) + require.NoError(t, err) + } + + engineOut := make(chan metrics.SampleContainer, 1000) + errCh := make(chan error, 1) + go func() { errCh <- test.executor.Run(test.ctx, engineOut) }() + + // Run must surface the VU-start failure to its caller instead of + // swallowing it. + select { + case err := <-errCh: + require.Error(t, err) + require.Contains(t, err.Error(), "could not get a VU from the buffer in") + case <-time.After(2 * lib.MaxRetriesGetPlannedVU * lib.MaxTimeToWaitForPlannedVU): + t.Fatal("executor did not stop after a VU-start failure") + } + + // Running the executor on its own must not log the failure: it's returned + // from Run() and the scheduler is the one that reports it. + require.Empty(t, errorHook.Drain()) +} + +// TestRampingVUsVUStartErrorMultiStage checks that, with a multi-stage ramp, +// the executor stops after the first VU-start failure instead of carrying on +// into later stages and hitting the same failure again for every later stage. +func TestRampingVUsVUStartErrorMultiStage(t *testing.T) { + t.Parallel() + + // A multi-stage ramp tries to schedule VUs across several stages; the + // executor must abort at the first VU-start failure, not at every stage. + config := RampingVUsConfig{ + BaseConfig: BaseConfig{GracefulStop: types.NullDurationFrom(0)}, + StartVUs: null.IntFrom(1), + Stages: []Stage{ + {Duration: types.NullDurationFrom(time.Second), Target: null.IntFrom(2)}, + {Duration: types.NullDurationFrom(time.Second), Target: null.IntFrom(3)}, + }, + } + + runner := simpleRunner(func(_ context.Context, _ *lib.State) error { return nil }) + test := setupExecutorTest(t, "", "", lib.Options{}, runner, config) + defer test.cancel() + + // The executor itself no longer logs VU-start failures (that's now the + // scheduler's job once Run() returns the error), so this hook is here to + // prove it stays quiet. + errorHook := testutils.NewLogHook(logrus.ErrorLevel) + test.executor.GetLogger().Logger.AddHook(errorHook) + + // Drain every planned VU so the executor cannot fetch one when it starts VUs. + maxVUs := lib.GetMaxPlannedVUs(config.GetExecutionRequirements(test.state.ExecutionTuple)) + for range maxVUs { + _, err := test.state.GetPlannedVU(test.executor.GetLogger(), false) + require.NoError(t, err) + } + + engineOut := make(chan metrics.SampleContainer, 1000) + errCh := make(chan error, 1) + go func() { errCh <- test.executor.Run(test.ctx, engineOut) }() + + select { + case err := <-errCh: + require.Error(t, err) + require.Contains(t, err.Error(), "could not get a VU from the buffer in") + case <-time.After(2 * lib.MaxRetriesGetPlannedVU * lib.MaxTimeToWaitForPlannedVU): + t.Fatal("executor did not stop after a VU-start failure") + } + + // GetPlannedVU() itself still warns once per retry while it waits for a VU + // to free up, up to lib.MaxRetriesGetPlannedVU times, before it gives up + // and returns the error above (see lib.ExecutionState.GetPlannedVU()). The + // drain above returns immediately without warning, so the only warnings + // come from the executor: if iterateSteps() aborts on the first VU-start + // failure like it should, the executor only tries (and fails) to fetch a + // VU once, so we see exactly lib.MaxRetriesGetPlannedVU such warnings. If + // the early-abort regressed and the executor kept going into later stages + // instead, it would retry (and warn) again for every later stage, + // inflating the count past lib.MaxRetriesGetPlannedVU. + const wantWarnMsg = "Could not get a VU from the buffer for" + var gotVUBufferWarns int + for _, entry := range test.logHook.Drain() { + if strings.Contains(entry.Message, wantWarnMsg) { + gotVUBufferWarns++ + } + } + require.Equal(t, lib.MaxRetriesGetPlannedVU, gotVUBufferWarns) + + // No error should be logged by the executor at all: it's returned from + // Run() and it's the scheduler's job to log it, not the executor's. + require.Empty(t, errorHook.Drain()) +} From 46e386108bd6fb3dad01a418c92573a523110798 Mon Sep 17 00:00:00 2001 From: Ankur Date: Thu, 10 Sep 2026 22:57:16 +0100 Subject: [PATCH 143/182] Fix browser web vitals lost on intermediate pages (#6163) * Refactor web vital emission to per-page buffer Web vital metrics were pushed immediately on every binding call. Move them into a per-FrameSession buffer flushed once per page: at each main-frame navigation boundary and at page close. Behaviour is unchanged, as each metric still emits a single sample and web_vital span per page. This lets a follow-up capture web vitals for every page in a navigation flow without duplicating samples or spans. The buffer is keyed by (url, metric name) and guarded by a mutex, because the initial navigation flush runs on the page-construction goroutine rather than the event-loop goroutine. * Fix web vitals lost on intermediate pages Enable web-vitals reportAllChanges so LCP/CLS/INP are reported during each page's lifetime instead of only on visibilitychange, which does not fire on hard navigations in headless Chrome. Together with per-page buffering, intermediate pages in a single-tab flow now record their web vitals (previously only the last page's were kept), still emitting one sample per page. Aggregates now include previously-dropped intermediate-page values. --- .../k6/browser/common/frame_session.go | 94 +++++++++++++++---- .../k6/browser/common/js/web_vital_init.js | 10 +- .../modules/k6/browser/tests/webvital_test.go | 82 ++++++++++++++++ 3 files changed, 163 insertions(+), 23 deletions(-) diff --git a/internal/js/modules/k6/browser/common/frame_session.go b/internal/js/modules/k6/browser/common/frame_session.go index 1441aed8f..fd8b10b63 100644 --- a/internal/js/modules/k6/browser/common/frame_session.go +++ b/internal/js/modules/k6/browser/common/frame_session.go @@ -42,6 +42,25 @@ type CPUProfile struct { Rate float64 } +// webVitalKey identifies a buffered web vital by the URL of the page it was +// measured on and the metric name. Keying by URL keeps distinct pages (and +// subframes) as separate series, while repeated reports for the same page and +// metric collapse onto a single buffered entry. +type webVitalKey struct { + url string + name string +} + +// webVitalSample is a buffered web vital metric sample together with the +// attributes needed to emit its web_vital trace span when the buffer is +// flushed. +type webVitalSample struct { + sample k6metrics.Sample + name string + spanID string + rating string +} + /* FrameSession is used for managing a frame's life-cycle, or in other words its full session. It manages all the event listening while deferring the state storage to the Frame and FrameManager @@ -87,6 +106,15 @@ type FrameSession struct { // onFrameNavigated, but subsequent calls to onFrameNavigated in the same // mainframe never again create a navigation span. initialNavDone bool + + // Web vital metrics are buffered per (url, metric name) and flushed once + // per page: at each main-frame navigation boundary and at page close. This + // keeps a single sample per page and metric even when a page reports a + // vital more than once. The mutex guards against the initial navigation's + // flush, which runs on the page-construction goroutine rather than the + // event-loop goroutine. + bufferedWebVitalsMu sync.Mutex + bufferedWebVitals map[webVitalKey]webVitalSample } // NewFrameSession initializes and returns a new FrameSession. @@ -119,6 +147,7 @@ func NewFrameSession( isolatedWorlds: make(map[string]bool), eventCh: make(chan Event), childSessions: make(map[cdp.FrameID]*FrameSession), + bufferedWebVitals: make(map[webVitalKey]webVitalSample), vu: k6ext.GetVU(ctx), k6Metrics: k6Metrics, logger: l, @@ -235,7 +264,7 @@ func (fs *FrameSession) initDomains() error { return nil } -//nolint:cyclop +//nolint:cyclop,funlen func (fs *FrameSession) initEvents() { fs.logger.Debugf("NewFrameSession:initEvents", "sid:%v tid:%v", fs.session.ID(), fs.targetID) @@ -255,6 +284,8 @@ func (fs *FrameSession) initEvents() { // If there is an active span for main frame, // end it before exiting so it can be flushed if fs.mainFrameSpan != nil { + // Flush the last page's buffered web vitals while its span is live. + fs.flushWebVitals() // The url needs to be added here instead of at the start of the span // because at the start of the span we don't know the correct url for // the page we're navigating to. At the end of the span we do have this @@ -373,28 +404,50 @@ func (fs *FrameSession) parseAndEmitWebVitalMetric(object string) error { tags = tags.With("rating", wv.Rating) - now := time.Now() - pushIfNotDone(fs.vu.Context(), fs.logger, state.Samples, k6metrics.ConnectedSamples{ - Samples: []k6metrics.Sample{ - { - TimeSeries: k6metrics.TimeSeries{Metric: metric, Tags: tags}, - Value: value, - Time: now, - }, + // Buffer the latest value for this page and metric instead of emitting it + // immediately. The buffer is flushed once per page so each page contributes + // a single sample per metric. + fs.bufferedWebVitalsMu.Lock() + fs.bufferedWebVitals[webVitalKey{url: wv.URL, name: wv.Name}] = webVitalSample{ + sample: k6metrics.Sample{ + TimeSeries: k6metrics.TimeSeries{Metric: metric, Tags: tags}, + Value: value, + Time: time.Now(), }, - }) - - _, span := TraceEvent( - fs.ctx, fs.targetID.String(), "web_vital", wv.SpanID, trace.WithAttributes( - attribute.String("web_vital.name", wv.Name), - attribute.Float64("web_vital.value", value), - attribute.String("web_vital.rating", wv.Rating), - )) - defer span.End() + name: wv.Name, + spanID: wv.SpanID, + rating: wv.Rating, + } + fs.bufferedWebVitalsMu.Unlock() return nil } +// flushWebVitals emits every buffered web vital metric sample and its +// web_vital trace span, then clears the buffer. Clearing makes the flush +// idempotent, so a page is emitted exactly once even when flushed at both a +// navigation boundary and at teardown. +func (fs *FrameSession) flushWebVitals() { + fs.bufferedWebVitalsMu.Lock() + defer fs.bufferedWebVitalsMu.Unlock() + + for key, wv := range fs.bufferedWebVitals { + pushIfNotDone(fs.vu.Context(), fs.logger, fs.vu.State().Samples, k6metrics.ConnectedSamples{ + Samples: []k6metrics.Sample{wv.sample}, + }) + + _, span := TraceEvent( + fs.ctx, fs.targetID.String(), "web_vital", wv.spanID, trace.WithAttributes( + attribute.String("web_vital.name", wv.name), + attribute.Float64("web_vital.value", wv.sample.Value), + attribute.String("web_vital.rating", wv.rating), + )) + span.End() + + delete(fs.bufferedWebVitals, key) + } +} + func (fs *FrameSession) onEventJavascriptDialogOpening(event *cdppage.EventJavascriptDialogOpening) { fs.logger.Debugf("FrameSession:onEventJavascriptDialogOpening", "sid:%v tid:%v url:%v dialogType:%s", @@ -822,6 +875,11 @@ func (fs *FrameSession) processNavigationSpan(id cdp.FrameID) { return } + // Flush the outgoing page's buffered web vitals while its navigation span + // is still live. This must run after the main-frame guard above so that a + // subframe load does not drain the main page's buffer. + fs.flushWebVitals() + // End the navigation span if it is non-nil if fs.mainFrameSpan != nil { // The url needs to be added here instead of at the start of the span diff --git a/internal/js/modules/k6/browser/common/js/web_vital_init.js b/internal/js/modules/k6/browser/common/js/web_vital_init.js index 7e1e3e970..e97e70376 100644 --- a/internal/js/modules/k6/browser/common/js/web_vital_init.js +++ b/internal/js/modules/k6/browser/common/js/web_vital_init.js @@ -19,12 +19,12 @@ function print(metric) { } function load() { - webVitals.onCLS(print); - webVitals.onLCP(print); + webVitals.onCLS(print, {reportAllChanges: true}); + webVitals.onLCP(print, {reportAllChanges: true}); - webVitals.onFCP(print); - webVitals.onINP(print); - webVitals.onTTFB(print); + webVitals.onFCP(print, {reportAllChanges: true}); + webVitals.onINP(print, {reportAllChanges: true}); + webVitals.onTTFB(print, {reportAllChanges: true}); } load(); diff --git a/internal/js/modules/k6/browser/tests/webvital_test.go b/internal/js/modules/k6/browser/tests/webvital_test.go index fda938afa..540927378 100644 --- a/internal/js/modules/k6/browser/tests/webvital_test.go +++ b/internal/js/modules/k6/browser/tests/webvital_test.go @@ -2,6 +2,7 @@ package tests import ( "runtime" + "strings" "testing" "github.com/stretchr/testify/assert" @@ -103,6 +104,87 @@ func TestWebVitalMetricNoInteraction(t *testing.T) { } } +// TestWebVitalMetricPerPage asserts that web vitals are recorded for every +// page in a single-tab navigation flow, not just the last one. It navigates +// one page across two distinct URLs and, without interacting with the first +// page, checks that the now-intermediate page still reports its LCP (as well +// as FCP and TTFB), with exactly one sample per (url, metric). +func TestWebVitalMetricPerPage(t *testing.T) { + t.Parallel() + if runtime.GOOS == "windows" { + t.Skip("timeouts on windows") + } + + var ( + samples = make(chan k6metrics.SampleContainer, 1000) + browser = newTestBrowser(t, withFileServer(), withSamples(samples)) + page = browser.NewPage(nil) + ) + + opts := &common.FrameGotoOptions{ + Timeout: common.DefaultTimeout, + } + + // Navigate to the first page and dwell so its web vitals settle and are + // reported before navigating away. The page is not interacted with, so + // without continuous reporting its LCP is never finalized. + resp, err := page.Goto(browser.staticURL("/web_vitals.html"), opts) + require.NoError(t, err) + require.NotNil(t, resp) + + page.WaitForTimeout(1000) + + // Navigate to a second, distinct page. This makes web_vitals.html an + // intermediate page whose web vitals would be lost without continuous + // reporting. + resp, err = page.Goto(browser.staticURL("/usual.html"), opts) + require.NoError(t, err) + require.NotNil(t, resp) + + require.NoError(t, page.Close()) + close(samples) + + // Count web vital samples per (url, metric). + type urlMetric struct{ url, metric string } + counts := make(map[urlMetric]int) + for sc := range samples { + for _, s := range sc.GetSamples() { + if !strings.HasPrefix(s.Metric.Name, "browser_web_vital_") { + continue + } + url, ok := s.Tags.Get("url") + require.Truef(t, ok, "web vital sample %s is missing a url tag", s.Metric.Name) + counts[urlMetric{url: url, metric: s.Metric.Name}]++ + } + } + + // The intermediate page must have recorded LCP, the key differentiator: + // without continuous reporting it finalizes only on visibilitychange, + // which does not fire on a hard navigation. FCP and TTFB are asserted as + // a sanity check (they finalize early during load). + intermediateHas := func(metric string) bool { + for k := range counts { + if k.metric == metric && strings.Contains(k.url, "web_vitals.html") { + return true + } + } + return false + } + assert.True(t, intermediateHas("browser_web_vital_lcp"), + "expected intermediate page web_vitals.html to record LCP") + assert.True(t, intermediateHas("browser_web_vital_fcp"), + "expected intermediate page web_vitals.html to record FCP") + assert.True(t, intermediateHas("browser_web_vital_ttfb"), + "expected intermediate page web_vitals.html to record TTFB") + + // Continuous reporting must not duplicate samples: each (url, metric) + // pair must be emitted exactly once. + for k, n := range counts { + assert.Equalf(t, 1, n, + "expected exactly one %s sample for %s, got %d", k.metric, k.url, n) + } +} + func markExpectedWebVitalsFromSamples(samples <-chan k6metrics.SampleContainer, expected map[string]bool) { for metric := range samples { for _, s := range metric.GetSamples() { From 238fdc103a001ac0f760a90fbad7e093bbfb934e Mon Sep 17 00:00:00 2001 From: cui fliter Date: Fri, 11 Sep 2026 16:22:48 +0800 Subject: [PATCH 144/182] httpext: close digest response body on read errors (#6355) Signed-off-by: cuishuang --- lib/netext/httpext/digest_transport.go | 2 +- lib/netext/httpext/digest_transport_test.go | 56 +++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 lib/netext/httpext/digest_transport_test.go diff --git a/lib/netext/httpext/digest_transport.go b/lib/netext/httpext/digest_transport.go index d8fe273f5..43f3721ac 100644 --- a/lib/netext/httpext/digest_transport.go +++ b/lib/netext/httpext/digest_transport.go @@ -37,10 +37,10 @@ func (t digestTransport) RoundTrip(req *http.Request) (*http.Response, error) { } respBody, err := io.ReadAll(noAuthResponse.Body) + _ = noAuthResponse.Body.Close() if err != nil { return nil, err } - _ = noAuthResponse.Body.Close() // Calculate the Authorization header // TODO: determine if we actually need the body, since I'm not sure that's diff --git a/lib/netext/httpext/digest_transport_test.go b/lib/netext/httpext/digest_transport_test.go new file mode 100644 index 000000000..345913813 --- /dev/null +++ b/lib/netext/httpext/digest_transport_test.go @@ -0,0 +1,56 @@ +package httpext + +import ( + "errors" + "net/http" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +type failingReadCloser struct { + err error + closed bool +} + +func (b *failingReadCloser) Read(_ []byte) (int, error) { + return 0, b.err +} + +func (b *failingReadCloser) Close() error { + b.closed = true + return nil +} + +type staticResponseTransport struct { + response *http.Response +} + +func (t staticResponseTransport) RoundTrip(_ *http.Request) (*http.Response, error) { + return t.response, nil +} + +func TestDigestTransportClosesUnauthorizedResponseBodyOnReadError(t *testing.T) { + t.Parallel() + + readErr := errors.New("read failed") + body := &failingReadCloser{err: readErr} + transport := digestTransport{ + originalTransport: staticResponseTransport{ + response: &http.Response{ + StatusCode: http.StatusUnauthorized, + Body: body, + }, + }, + } + req, err := http.NewRequestWithContext(t.Context(), http.MethodGet, "https://user:password@example.com", nil) + require.NoError(t, err) + + // The response must be nil when reading the challenge body fails. + response, err := transport.RoundTrip(req) //nolint:bodyclose + + require.ErrorIs(t, err, readErr) + assert.Nil(t, response) + assert.True(t, body.closed) +} From 94ad439c80770aa9dfeb128ff3b052c7ded1196e Mon Sep 17 00:00:00 2001 From: Jan Hildebrandt <32014057+janHildebrandt98@users.noreply.github.com> Date: Fri, 11 Sep 2026 14:49:08 +0200 Subject: [PATCH 145/182] Fix golangci findings (#6394) * Bump k6-ci reference to 0.5.0 * Fix modernize findings via golang-ci run --fix * adjust goconst linter to ignore browser mapping, tests and some other boilerplate files * Cleanup now unused helper functions (made obsolete by modernize) * fix prealloc * fix copyloopvar * fix govet * fix nolintlint * fix gosec * fix formatting * fix noctx * safe staticcheck fix * ignore trufflehog false positives * disable staticcheck for webcrypto package --- .github/workflows/auto-approve-renovate.yml | 2 +- .github/workflows/lint.yml | 4 +- .golangci.patch | 10 +- api/v1/client/client.go | 2 +- api/v1/group_routes_test.go | 4 +- api/v1/metric_routes_test.go | 6 +- api/v1/setup_teardown_routes_test.go | 2 +- api/v1/status_routes_test.go | 2 +- cloudapi/client.go | 2 +- cloudapi/logs.go | 6 +- cloudapi/logs_test.go | 8 +- cmd/state/state.go | 4 +- errext/abort_reason.go | 3 +- errext/exit_code.go | 3 +- errext/fields.go | 3 +- errext/format.go | 6 +- errext/hint.go | 3 +- ext/ext.go | 2 +- internal/api/server_test.go | 4 +- internal/cloudapi/provisioning/client.go | 2 +- internal/cloudapi/provisioning/notify.go | 3 +- internal/cloudapi/provisioning/test/server.go | 15 +- internal/cloudapi/v6/client.go | 3 +- internal/cloudapi/v6/errors_test.go | 6 +- internal/cmd/deps.go | 3 +- internal/cmd/launcher.go | 3 +- internal/cmd/report.go | 2 +- internal/cmd/root.go | 6 +- internal/cmd/test_load.go | 4 +- internal/cmd/tests/cmd_run_test.go | 8 +- internal/cmd/x_registry.go | 2 +- internal/dashboard/sse.go | 4 +- internal/dashboard/web.go | 2 +- internal/execution/scheduler_ext_test.go | 6 +- internal/features/features.go | 3 +- internal/js/bundle.go | 5 +- internal/js/init_and_modules_test.go | 4 +- internal/js/initcontext_test.go | 8 +- .../k6/browser/browser/mapping_test.go | 3 +- .../k6/browser/chromium/browser_type.go | 2 +- .../js/modules/k6/browser/common/device.go | 1 + .../k6/browser/common/element_handle.go | 3 +- .../modules/k6/browser/common/frame_test.go | 13 +- internal/js/modules/k6/browser/common/http.go | 3 +- .../k6/browser/common/network_manager.go | 2 +- internal/js/modules/k6/browser/common/page.go | 6 +- .../js/modules/k6/browser/common/page_test.go | 2 +- .../modules/k6/browser/keyboardlayout/us.go | 1 + .../k6/browser/storage/file_persister.go | 4 +- .../modules/k6/browser/tests/get_by_test.go | 130 +++++++++--------- .../modules/k6/browser/tests/test_browser.go | 5 - .../js/modules/k6/browser/tests/ws/server.go | 1 - .../experimental/streams/readable_streams.go | 3 +- .../writable_stream_default_controller.go | 3 +- internal/js/modules/k6/grpc/client_test.go | 4 +- .../js/modules/k6/webcrypto/elliptic_curve.go | 1 + internal/js/modules/k6/webcrypto/jwk.go | 5 +- .../js/modules/k6/websockets/websockets.go | 5 +- internal/js/runner.go | 6 +- internal/lib/summary/machine_readable.go | 5 +- .../grpc_wrappers_testing/service.go | 2 +- internal/loader/loader.go | 4 +- internal/loader/loader_test.go | 2 +- internal/loader/readsource.go | 5 +- internal/loader/readsource_test.go | 2 +- internal/log/loki.go | 2 +- internal/metrics/engine/engine.go | 6 +- internal/output/cloud/output.go | 3 +- internal/output/prometheusrw/remote/client.go | 4 +- internal/output/prometheusrw/sigv4/sigv4.go | 2 +- internal/secretsource/url/url.go | 2 +- internal/ui/form_fields.go | 2 +- internal/ui/pb/helpers.go | 4 +- js/common/init_error.go | 6 +- js/common/interrupt_error.go | 3 +- js/modules/k6/html/gen/gen_elements.go | 2 + js/modules/k6/http/cookiejar.go | 4 +- js/modules/k6/http/request.go | 9 +- js/modules/k6/http/request_test.go | 5 +- js/modules/k6/http/response.go | 3 +- lib/archive.go | 4 +- lib/executor/constant_arrival_rate_test.go | 14 +- lib/executor/ramping_arrival_rate.go | 8 +- lib/executor/ramping_arrival_rate_test.go | 24 ++-- lib/executor/ramping_vus_test.go | 18 +-- lib/executor/vu_handle_test.go | 112 +++++++-------- lib/limiter_test.go | 8 +- lib/netext/aia.go | 5 +- lib/netext/aia_test.go | 8 +- lib/netext/httpext/compression.go | 5 +- lib/netext/httpext/error_codes.go | 2 +- lib/netext/httpext/error_codes_test.go | 2 +- lib/netext/httpext/request.go | 4 +- lib/netext/httpext/request_test.go | 14 +- lib/options.go | 2 +- lib/options_test.go | 2 +- lib/types/trie.go | 19 +-- metrics/tags.go | 12 +- output/cloud/expv2/flush_test.go | 6 +- output/cloud/expv2/mapping.go | 2 +- output/cloud/expv2/output_test.go | 18 +-- secretsource/manager.go | 2 +- 102 files changed, 354 insertions(+), 382 deletions(-) diff --git a/.github/workflows/auto-approve-renovate.yml b/.github/workflows/auto-approve-renovate.yml index d47d20322..d002c4b36 100644 --- a/.github/workflows/auto-approve-renovate.yml +++ b/.github/workflows/auto-approve-renovate.yml @@ -11,4 +11,4 @@ permissions: id-token: write jobs: approve: - uses: grafana/k6-ci/.github/workflows/auto-approve-renovate.yml@777962b022a831166517639e542630d8b7d1455f # v0.4.0 + uses: grafana/k6-ci/.github/workflows/auto-approve-renovate.yml@03469f9ae7aad25369827832c456e8f8b7b8c1c2 # v0.5.0 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index e7baca01c..49ea7b93c 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -42,8 +42,8 @@ jobs: fi k6-ci: - uses: grafana/k6-ci/.github/workflows/all.yml@777962b022a831166517639e542630d8b7d1455f # v0.4.0 + uses: grafana/k6-ci/.github/workflows/all.yml@03469f9ae7aad25369827832c456e8f8b7b8c1c2 # v0.5.0 with: - k6-ci-ref: 777962b022a831166517639e542630d8b7d1455f # v0.4.0 + k6-ci-ref: 03469f9ae7aad25369827832c456e8f8b7b8c1c2 # v0.5.0 skip-tests: true skip-extension-testing: true diff --git a/.golangci.patch b/.golangci.patch index ca83284ca..2a47d961b 100644 --- a/.golangci.patch +++ b/.golangci.patch @@ -1,14 +1,20 @@ -diff --git a/.golangci.yml b/.golangci.yml --- a/.golangci.yml +++ b/.golangci.yml -@@ -101,6 +101,22 @@ linters: +@@ -99,8 +99,29 @@ + - gocognit + - lll - gosec ++ - goconst ++ - prealloc path: _(test|gen)\.go - linters: + - contextcheck + - revive + path: js\/modules\/k6\/browser\/.*\.go + - linters: ++ - goconst ++ path: js\/modules\/k6\/browser\/.*mapping\.go ++ - linters: + - revive + path: js\/modules\/k6\/html\/.*\.go + text: 'exported: exported ' diff --git a/api/v1/client/client.go b/api/v1/client/client.go index 8acec9f4c..378d72f5e 100644 --- a/api/v1/client/client.go +++ b/api/v1/client/client.go @@ -94,7 +94,7 @@ func (c *Client) CallAPI(ctx context.Context, method string, rel *url.URL, body, } req = req.WithContext(ctx) - res, err := c.httpClient.Do(req) //nolint:gosec + res, err := c.httpClient.Do(req) if err != nil { return err } diff --git a/api/v1/group_routes_test.go b/api/v1/group_routes_test.go index 5badc2690..069ae67b2 100644 --- a/api/v1/group_routes_test.go +++ b/api/v1/group_routes_test.go @@ -102,7 +102,7 @@ func TestGetGroups(t *testing.T) { t.Parallel() rw := httptest.NewRecorder() - NewHandler(cs).ServeHTTP(rw, httptest.NewRequest(http.MethodGet, "/v1/groups", nil)) + NewHandler(cs).ServeHTTP(rw, httptest.NewRequestWithContext(t.Context(), http.MethodGet, "/v1/groups", nil)) res := rw.Result() t.Cleanup(func() { assert.NoError(t, res.Body.Close()) @@ -158,7 +158,7 @@ func TestGetGroups(t *testing.T) { t.Run(gp.Name, func(t *testing.T) { t.Parallel() rw := httptest.NewRecorder() - NewHandler(cs).ServeHTTP(rw, httptest.NewRequest(http.MethodGet, "/v1/groups/"+gp.ID, nil)) + NewHandler(cs).ServeHTTP(rw, httptest.NewRequestWithContext(t.Context(), http.MethodGet, "/v1/groups/"+gp.ID, nil)) res := rw.Result() t.Cleanup(func() { assert.NoError(t, res.Body.Close()) diff --git a/api/v1/metric_routes_test.go b/api/v1/metric_routes_test.go index 0f31a5f20..92322ac69 100644 --- a/api/v1/metric_routes_test.go +++ b/api/v1/metric_routes_test.go @@ -29,7 +29,7 @@ func TestGetMetrics(t *testing.T) { cs.MetricsEngine.ObservedMetrics["my_metric"].Tainted = null.BoolFrom(true) rw := httptest.NewRecorder() - NewHandler(cs).ServeHTTP(rw, httptest.NewRequest(http.MethodGet, "/v1/metrics", nil)) + NewHandler(cs).ServeHTTP(rw, httptest.NewRequestWithContext(t.Context(), http.MethodGet, "/v1/metrics", nil)) res := rw.Result() t.Cleanup(func() { assert.NoError(t, res.Body.Close()) @@ -91,7 +91,7 @@ func TestGetMetric(t *testing.T) { t.Parallel() rw := httptest.NewRecorder() - NewHandler(cs).ServeHTTP(rw, httptest.NewRequest(http.MethodGet, "/v1/metrics/notreal", nil)) + NewHandler(cs).ServeHTTP(rw, httptest.NewRequestWithContext(t.Context(), http.MethodGet, "/v1/metrics/notreal", nil)) res := rw.Result() t.Cleanup(func() { assert.NoError(t, res.Body.Close()) @@ -103,7 +103,7 @@ func TestGetMetric(t *testing.T) { t.Parallel() rw := httptest.NewRecorder() - NewHandler(cs).ServeHTTP(rw, httptest.NewRequest(http.MethodGet, "/v1/metrics/my_metric", nil)) + NewHandler(cs).ServeHTTP(rw, httptest.NewRequestWithContext(t.Context(), http.MethodGet, "/v1/metrics/my_metric", nil)) res := rw.Result() t.Cleanup(func() { assert.NoError(t, res.Body.Close()) diff --git a/api/v1/setup_teardown_routes_test.go b/api/v1/setup_teardown_routes_test.go index c89d9332e..f0af9d205 100644 --- a/api/v1/setup_teardown_routes_test.go +++ b/api/v1/setup_teardown_routes_test.go @@ -166,7 +166,7 @@ func TestSetupData(t *testing.T) { checkSetup := func(method, body, expResult string) { rw := httptest.NewRecorder() - handler.ServeHTTP(rw, httptest.NewRequest(method, "/v1/setup", bytes.NewBufferString(body))) + handler.ServeHTTP(rw, httptest.NewRequestWithContext(t.Context(), method, "/v1/setup", bytes.NewBufferString(body))) res := rw.Result() t.Cleanup(func() { assert.NoError(t, res.Body.Close()) diff --git a/api/v1/status_routes_test.go b/api/v1/status_routes_test.go index f43ac296b..2dc5f32ef 100644 --- a/api/v1/status_routes_test.go +++ b/api/v1/status_routes_test.go @@ -19,7 +19,7 @@ func TestGetStatus(t *testing.T) { cs := getControlSurface(t, testState) rw := httptest.NewRecorder() - NewHandler(cs).ServeHTTP(rw, httptest.NewRequest(http.MethodGet, "/v1/status", nil)) + NewHandler(cs).ServeHTTP(rw, httptest.NewRequestWithContext(t.Context(), http.MethodGet, "/v1/status", nil)) res := rw.Result() t.Cleanup(func() { assert.NoError(t, res.Body.Close()) diff --git a/cloudapi/client.go b/cloudapi/client.go index 8fbcfe519..7ca3b70b0 100644 --- a/cloudapi/client.go +++ b/cloudapi/client.go @@ -152,7 +152,7 @@ func (c *Client) prepareHeaders(req *http.Request) { } func (c *Client) do(req *http.Request, v any, attempt int) (retry bool, err error) { - resp, err := c.client.Do(req) //nolint:gosec + resp, err := c.client.Do(req) defer func() { if resp != nil { diff --git a/cloudapi/logs.go b/cloudapi/logs.go index 806bc2519..eece3ea8b 100644 --- a/cloudapi/logs.go +++ b/cloudapi/logs.go @@ -139,7 +139,7 @@ func (c *Config) StreamLogsToLogger( msgBuffer := make(chan []byte, 10) defer close(msgBuffer) - var mostRecent int64 + var mostRecent atomic.Int64 go func() { for message := range msgBuffer { var m msg @@ -150,7 +150,7 @@ func (c *Config) StreamLogsToLogger( continue } ts := m.Log(logger) - atomic.StoreInt64(&mostRecent, ts) + mostRecent.Store(ts) } }() @@ -166,7 +166,7 @@ func (c *Config) StreamLogsToLogger( logger.WithError(err).Warn("error reading a log message from the cloud, trying to establish a fresh connection with the logs service...") //nolint:lll var since time.Time - if ts := atomic.LoadInt64(&mostRecent); ts > 0 { + if ts := mostRecent.Load(); ts > 0 { // add 1ns for avoid possible repetition since = time.Unix(0, ts).Add(time.Nanosecond) } else { diff --git a/cloudapi/logs_test.go b/cloudapi/logs_test.go index 38bf6d4b3..3f837f4aa 100644 --- a/cloudapi/logs_test.go +++ b/cloudapi/logs_test.go @@ -282,11 +282,11 @@ func TestStreamLogsToLogger(t *testing.T) { return start, err } - var requestsCount uint64 + var requestsCount atomic.Uint64 tb := httpmultibin.NewHTTPMultiBin(t) logtailHandleFunc(tb, func(conn *websocket.Conn, req *http.Request) { - requests := atomic.AddUint64(&requestsCount, 1) + requests := requestsCount.Add(1) start, err := startFilter(*req.URL) require.NoError(t, err) @@ -361,12 +361,12 @@ func TestStreamLogsToLogger(t *testing.T) { return start, err } - var requestsCount uint64 + var requestsCount atomic.Uint64 t0 := time.Now() tb := httpmultibin.NewHTTPMultiBin(t) logtailHandleFunc(tb, func(conn *websocket.Conn, req *http.Request) { - requests := atomic.AddUint64(&requestsCount, 1) + requests := requestsCount.Add(1) start, err := startFilter(*req.URL) require.NoError(t, err) diff --git a/cmd/state/state.go b/cmd/state/state.go index 101827b00..43efbf128 100644 --- a/cmd/state/state.go +++ b/cmd/state/state.go @@ -114,13 +114,13 @@ func NewGlobalState(ctx context.Context) *GlobalState { stderrTTY := !isDumbTerm && (isatty.IsTerminal(os.Stderr.Fd()) || isatty.IsCygwinTerminal(os.Stderr.Fd())) outMutex := &sync.Mutex{} stdout := &console.Writer{ - RawOutFd: int(os.Stdout.Fd()), //nolint:gosec + RawOutFd: int(os.Stdout.Fd()), Mutex: outMutex, Writer: colorable.NewColorable(os.Stdout), IsTTY: stdoutTTY, } stderr := &console.Writer{ - RawOutFd: int(os.Stderr.Fd()), //nolint:gosec + RawOutFd: int(os.Stderr.Fd()), Mutex: outMutex, Writer: colorable.NewColorable(os.Stderr), IsTTY: stderrTTY, diff --git a/errext/abort_reason.go b/errext/abort_reason.go index 429969866..a4dbf920f 100644 --- a/errext/abort_reason.go +++ b/errext/abort_reason.go @@ -31,8 +31,7 @@ func WithAbortReasonIfNone(err error, abortReason AbortReason) error { if err == nil { return nil // No error, do nothing } - var arerr HasAbortReason - if errors.As(err, &arerr) { + if _, ok := errors.AsType[HasAbortReason](err); ok { // The given error already has an abort reason, do nothing return err } diff --git a/errext/exit_code.go b/errext/exit_code.go index d141a3a72..5e7de1294 100644 --- a/errext/exit_code.go +++ b/errext/exit_code.go @@ -25,8 +25,7 @@ func WithExitCodeIfNone(err error, exitCode exitcodes.ExitCode) error { // No error, do nothing return nil } - var ecerr HasExitCode - if errors.As(err, &ecerr) { + if _, ok := errors.AsType[HasExitCode](err); ok { // The given error already has an exit code, do nothing return err } diff --git a/errext/fields.go b/errext/fields.go index 667fe3e44..5292ed1b2 100644 --- a/errext/fields.go +++ b/errext/fields.go @@ -28,8 +28,7 @@ func WithFields(err error, fields map[string]any) error { // FieldsFromErr returns structured log fields attached to err. func FieldsFromErr(err error) map[string]any { fields := map[string]any{} - var ferr fieldsError - if errors.As(err, &ferr) { + if ferr, ok := errors.AsType[fieldsError](err); ok { maps.Copy(fields, ferr.fields) } return fields diff --git a/errext/format.go b/errext/format.go index afd291106..7e2618b9a 100644 --- a/errext/format.go +++ b/errext/format.go @@ -14,13 +14,11 @@ func Format(err error) (string, map[string]any) { errText := err.Error() fields := FieldsFromErr(err) - var xerr Exception - if errors.As(err, &xerr) { + if xerr, ok := errors.AsType[Exception](err); ok { errText = xerr.StackTrace() fields["source"] = "stacktrace" } - var herr HasHint - if errors.As(err, &herr) { + if herr, ok := errors.AsType[HasHint](err); ok { fields["hint"] = herr.Hint() } diff --git a/errext/hint.go b/errext/hint.go index 1b053b120..93b14b16f 100644 --- a/errext/hint.go +++ b/errext/hint.go @@ -32,8 +32,7 @@ func (wh withHintError) Unwrap() error { func (wh withHintError) Hint() string { hint := wh.hint - var oldhint HasHint - if errors.As(wh.error, &oldhint) { + if oldhint, ok := errors.AsType[HasHint](wh.error); ok { // The given error already had a hint, wrap it hint = hint + " (" + oldhint.Hint() + ")" } diff --git a/ext/ext.go b/ext/ext.go index fc8e9f726..f020e230e 100644 --- a/ext/ext.go +++ b/ext/ext.go @@ -134,7 +134,7 @@ func extractModuleInfo(mod any) (path, version string) { t := reflect.TypeOf(mod) switch t.Kind() { - case reflect.Ptr: + case reflect.Pointer: if t.Elem() != nil { path = t.Elem().PkgPath() } diff --git a/internal/api/server_test.go b/internal/api/server_test.go index 6a5180990..78f278afc 100644 --- a/internal/api/server_test.go +++ b/internal/api/server_test.go @@ -29,7 +29,7 @@ func TestLogger(t *testing.T) { t.Run("path="+path, func(t *testing.T) { t.Parallel() rw := httptest.NewRecorder() - r := httptest.NewRequest(method, "http://example.com"+path, nil) + r := httptest.NewRequestWithContext(t.Context(), method, "http://example.com"+path, nil) l, hook := logtest.NewNullLogger() l.Level = logrus.DebugLevel @@ -61,7 +61,7 @@ func TestPing(t *testing.T) { mux := handlePing(logger) rw := httptest.NewRecorder() - r := httptest.NewRequest(http.MethodGet, "/ping", nil) + r := httptest.NewRequestWithContext(t.Context(), http.MethodGet, "/ping", nil) mux.ServeHTTP(rw, r) res := rw.Result() diff --git a/internal/cloudapi/provisioning/client.go b/internal/cloudapi/provisioning/client.go index a422ac7a9..a3c3edf55 100644 --- a/internal/cloudapi/provisioning/client.go +++ b/internal/cloudapi/provisioning/client.go @@ -109,7 +109,7 @@ func doWithRetry(httpClient *http.Client, req *http.Request) (*http.Response, er req.Body = body } - lastResp, lastErr = httpClient.Do(req) //nolint:gosec + lastResp, lastErr = httpClient.Do(req) if lastErr != nil { if attempt < clientcfg.MaxRetries { select { diff --git a/internal/cloudapi/provisioning/notify.go b/internal/cloudapi/provisioning/notify.go index f3d01873d..e7d38caf2 100644 --- a/internal/cloudapi/provisioning/notify.go +++ b/internal/cloudapi/provisioning/notify.go @@ -27,8 +27,7 @@ func mapTestErrorToNotifyCode(testErr error) *notifyError { return nil } - var hasAbortReason errext.HasAbortReason - if errors.As(testErr, &hasAbortReason) { + if hasAbortReason, ok := errors.AsType[errext.HasAbortReason](testErr); ok { switch hasAbortReason.AbortReason() { case errext.AbortedByUser, errext.AbortedByScriptAbort: return ¬ifyError{Code: 8036, Reason: testErr.Error()} diff --git a/internal/cloudapi/provisioning/test/server.go b/internal/cloudapi/provisioning/test/server.go index 968fd1baa..6b80d27d4 100644 --- a/internal/cloudapi/provisioning/test/server.go +++ b/internal/cloudapi/provisioning/test/server.go @@ -80,12 +80,12 @@ func (s *Server) HandleStartLocalExecution(loadTestID int64, handler http.Handle func DefaultStartLocalExecutionResponse() *k6cloud.StartLocalExecutionTestResponse { metrics := k6cloud.NewMetricsRuntimeConfig( "https://ingest.k6.io/v1/metrics", - *k6cloud.NewNullableString(strPtr("2s")), - *k6cloud.NewNullableInt32(int32Ptr(5)), - *k6cloud.NewNullableString(strPtr("3s")), - *k6cloud.NewNullableString(strPtr("1s")), - *k6cloud.NewNullableInt32(int32Ptr(50)), - *k6cloud.NewNullableInt32(int32Ptr(2000)), + *k6cloud.NewNullableString(new("2s")), + *k6cloud.NewNullableInt32(new(int32(5))), + *k6cloud.NewNullableString(new("3s")), + *k6cloud.NewNullableString(new("1s")), + *k6cloud.NewNullableInt32(new(int32(50))), + *k6cloud.NewNullableInt32(new(int32(2000))), ) secrets := k6cloud.NewSecretsRuntimeConfig( @@ -211,6 +211,3 @@ func (s *Server) HandleNotify(testRunID int64, handler http.HandlerFunc) { handler, ) } - -func strPtr(s string) *string { return &s } -func int32Ptr(i int32) *int32 { return &i } diff --git a/internal/cloudapi/v6/client.go b/internal/cloudapi/v6/client.go index 526cf165c..61b49354a 100644 --- a/internal/cloudapi/v6/client.go +++ b/internal/cloudapi/v6/client.go @@ -64,8 +64,7 @@ func (c *Client) BaseURL() string { // otherwise it tries to parse the body and return a parsed error. func CheckResponse(r *http.Response, err error) error { if err != nil { - var aerr *k6cloud.GenericOpenAPIError - if !errors.As(err, &aerr) { + if _, ok := errors.AsType[*k6cloud.GenericOpenAPIError](err); !ok { return err } } diff --git a/internal/cloudapi/v6/errors_test.go b/internal/cloudapi/v6/errors_test.go index a9c966ec7..1e2b20429 100644 --- a/internal/cloudapi/v6/errors_test.go +++ b/internal/cloudapi/v6/errors_test.go @@ -31,7 +31,7 @@ func TestResponseError_Error(t *testing.T) { respErr: ResponseError{ APIError: k6cloud.ErrorApiModel{ Message: "validation failed", - Target: *k6cloud.NewNullableString(k6cloud.PtrString("field_name")), + Target: *k6cloud.NewNullableString(new("field_name")), }, }, expected: "validation failed (target: 'field_name')", @@ -44,11 +44,11 @@ func TestResponseError_Error(t *testing.T) { Details: []k6cloud.ErrorDetailsApiModel{ { Message: "field is required", - Target: *k6cloud.NewNullableString(k6cloud.PtrString("first_property")), + Target: *k6cloud.NewNullableString(new("first_property")), }, { Message: "field must be positive", - Target: *k6cloud.NewNullableString(k6cloud.PtrString("second_property")), + Target: *k6cloud.NewNullableString(new("second_property")), }, }, }, diff --git a/internal/cmd/deps.go b/internal/cmd/deps.go index 98d6dda9a..f0ebf1208 100644 --- a/internal/cmd/deps.go +++ b/internal/cmd/deps.go @@ -43,8 +43,7 @@ func getCmdDeps(gs *state.GlobalState) *cobra.Command { func (c *depsCmd) run(cmd *cobra.Command, args []string) error { test, err := loadLocalTestWithoutRunner(c.gs, cmd, args) if err != nil { - var unsatisfiedErr binaryIsNotSatisfyingDependenciesError - if !errors.As(err, &unsatisfiedErr) { + if _, ok := errors.AsType[binaryIsNotSatisfyingDependenciesError](err); !ok { return err } } diff --git a/internal/cmd/launcher.go b/internal/cmd/launcher.go index ce268ee4e..cf8eb0bca 100644 --- a/internal/cmd/launcher.go +++ b/internal/cmd/launcher.go @@ -97,8 +97,7 @@ func (b *customBinary) run(ctx context.Context, gs *state.GlobalState) error { for { select { case err := <-done: - var exitError *exec.ExitError - if errors.As(err, &exitError) { + if exitError, ok := errors.AsType[*exec.ExitError](err); ok { return errext.WithExitCodeIfNone(errAlreadyReported, exitcodes.ExitCode(exitError.ExitCode())) //nolint:gosec } return err diff --git a/internal/cmd/report.go b/internal/cmd/report.go index b0d32b0a5..f11f8a258 100644 --- a/internal/cmd/report.go +++ b/internal/cmd/report.go @@ -214,7 +214,7 @@ func postUsageReport(ctx context.Context, lookupEnv func(string) (string, bool), } req.Header.Set("Content-Type", "application/json") - res, err := http.DefaultClient.Do(req) //nolint:gosec + res, err := http.DefaultClient.Do(req) if err == nil { _ = res.Body.Close() } diff --git a/internal/cmd/root.go b/internal/cmd/root.go index 7fe8b9571..4881c40e5 100644 --- a/internal/cmd/root.go +++ b/internal/cmd/root.go @@ -221,8 +221,7 @@ func (c *rootCommand) execute() { return } - var ecerr errext.HasExitCode - if errors.As(err, &ecerr) { + if ecerr, ok := errors.AsType[errext.HasExitCode](err); ok { exitCode = int(ecerr.ExitCode()) } @@ -262,8 +261,7 @@ func handleUnsatisfiedDependencies(err error, c *rootCommand) (exitcodes.ExitCod err = customBinary.run(c.globalState.Ctx, c.globalState) // this only happens if we actually ran the binary and it exited afterwads, in which case we propagate the exit code - var ecerr errext.HasExitCode - if errors.As(err, &ecerr) { + if ecerr, ok := errors.AsType[errext.HasExitCode](err); ok { return ecerr.ExitCode(), err } diff --git a/internal/cmd/test_load.go b/internal/cmd/test_load.go index 90d05b8a8..44a3f0d5a 100644 --- a/internal/cmd/test_load.go +++ b/internal/cmd/test_load.go @@ -488,9 +488,7 @@ func extractUnknownModules(err error) (dependencies, error) { return deps, nil } - var u modules.UnknownModulesError - - if errors.As(err, &u) { + if u, ok := errors.AsType[modules.UnknownModulesError](err); ok { for _, name := range u.List() { deps[name] = nil } diff --git a/internal/cmd/tests/cmd_run_test.go b/internal/cmd/tests/cmd_run_test.go index 8a3e78f03..0a6830b8c 100644 --- a/internal/cmd/tests/cmd_run_test.go +++ b/internal/cmd/tests/cmd_run_test.go @@ -2177,7 +2177,7 @@ func TestBadLogOutput(t *testing.T) { } // HACK: We need this so multiple tests can register differently named modules. -var uniqueModuleNumber uint64 //nolint:gochecknoglobals +var uniqueModuleNumber atomic.Uint64 //nolint:gochecknoglobals // Tests that the appropriate events are emitted in the correct order. func TestEventSystemOK(t *testing.T) { @@ -2185,7 +2185,7 @@ func TestEventSystemOK(t *testing.T) { ts := NewGlobalTestState(t) - moduleName := fmt.Sprintf("k6/x/testevents-%d", atomic.AddUint64(&uniqueModuleNumber, 1)) + moduleName := fmt.Sprintf("k6/x/testevents-%d", uniqueModuleNumber.Add(1)) mod := events.New(event.GlobalEvents, event.VUEvents) modules.Register(moduleName, mod) @@ -2311,7 +2311,7 @@ func TestEventSystemError(t *testing.T) { t.Parallel() ts := NewGlobalTestState(t) - moduleName := fmt.Sprintf("k6/x/testevents-%d", atomic.AddUint64(&uniqueModuleNumber, 1)) + moduleName := fmt.Sprintf("k6/x/testevents-%d", uniqueModuleNumber.Add(1)) mod := events.New(event.GlobalEvents, event.VUEvents) modules.Register(moduleName, mod) @@ -2368,7 +2368,7 @@ func BenchmarkRunEvents(b *testing.B) { for i := 0; i < b.N; i++ { ts := NewGlobalTestState(b) - moduleName := fmt.Sprintf("k6/x/testevents-%d", atomic.AddUint64(&uniqueModuleNumber, 1)) + moduleName := fmt.Sprintf("k6/x/testevents-%d", uniqueModuleNumber.Add(1)) mod := events.New(event.GlobalEvents, event.VUEvents) modules.Register(moduleName, mod) diff --git a/internal/cmd/x_registry.go b/internal/cmd/x_registry.go index 2f754613f..c320aeb62 100644 --- a/internal/cmd/x_registry.go +++ b/internal/cmd/x_registry.go @@ -110,7 +110,7 @@ func fetchCatalog(ctx context.Context, url string) (registrySubcommands, []byte, } // The URL can be overridden via env for tests and development; that is the // intended behaviour of the catalog override, not an SSRF vector. - resp, err := http.DefaultClient.Do(req) //nolint:gosec + resp, err := http.DefaultClient.Do(req) if err != nil { return nil, nil, fmt.Errorf("fetching extensions catalog: %w", err) } diff --git a/internal/dashboard/sse.go b/internal/dashboard/sse.go index 0e3ae99ce..8ac41b0fc 100644 --- a/internal/dashboard/sse.go +++ b/internal/dashboard/sse.go @@ -60,9 +60,7 @@ func (emitter *eventEmitter) onStart() error { } func (emitter *eventEmitter) onStop(reason error) error { - var err errext.HasAbortReason - - if !errors.As(reason, &err) { + if _, ok := errors.AsType[errext.HasAbortReason](reason); !ok { emitter.wait.Wait() } diff --git a/internal/dashboard/web.go b/internal/dashboard/web.go index ee41fb1cf..41983683d 100644 --- a/internal/dashboard/web.go +++ b/internal/dashboard/web.go @@ -99,7 +99,7 @@ func rootHandler(uiPath string) http.HandlerFunc { http.Redirect( w, r, - path.Join(uiPath, r.URL.Path)+"?endpoint=/", + path.Join(uiPath, "/")+"?endpoint=/", http.StatusTemporaryRedirect, ) diff --git a/internal/execution/scheduler_ext_test.go b/internal/execution/scheduler_ext_test.go index e75c880fd..f11f6011c 100644 --- a/internal/execution/scheduler_ext_test.go +++ b/internal/execution/scheduler_ext_test.go @@ -1164,13 +1164,13 @@ func TestDNSResolverCache(t *testing.T) { require.NoError(t, err) mr := mockresolver.New(map[string][]net.IP{"myhost": {net.ParseIP(sr("HTTPBIN_IP"))}}) - var newResolutions uint32 + var newResolutions atomic.Uint32 resolveHook := func(_ string, result []net.IP) { require.Len(t, result, 1) if result[0].String() == "127.0.0.1" { mr.Set("myhost", "127.0.0.254") } else { - atomic.AddUint32(&newResolutions, 1) + newResolutions.Add(1) } } mr.ResolveHook = resolveHook @@ -1185,7 +1185,7 @@ func TestDNSResolverCache(t *testing.T) { select { case err := <-errCh: require.NoError(t, err) - assert.Equal(t, tc.expNewResolutions, atomic.LoadUint32(&newResolutions)) + assert.Equal(t, tc.expNewResolutions, newResolutions.Load()) case <-time.After(10 * time.Second): t.Fatal("timed out") } diff --git a/internal/features/features.go b/internal/features/features.go index b609c4ba3..2a6353b93 100644 --- a/internal/features/features.go +++ b/internal/features/features.go @@ -168,8 +168,7 @@ func parseDefinitions(t reflect.Type) (*definitions, error) { byName: make(map[string]int), } - for i := range t.NumField() { - f := t.Field(i) + for f := range t.Fields() { if !f.IsExported() { continue } diff --git a/internal/js/bundle.go b/internal/js/bundle.go index 03f642078..447acfbef 100644 --- a/internal/js/bundle.go +++ b/internal/js/bundle.go @@ -246,7 +246,7 @@ func beautifyOptionsJSONUnmarshalError(data []byte, err error) error { if errors.As(err, &unmarshalTypError) { e := unmarshalTypError previousNewLineIndex := max(bytes.LastIndexByte(data[:e.Offset], '\n'), 0) - nextNewLineIndex := max(min(bytes.IndexByte(data[e.Offset:], '\n'), len(data)-1), (int)(e.Offset)) + nextNewLineIndex := max(min(bytes.IndexByte(data[e.Offset:], '\n'), len(data)-1), int(e.Offset)) info := strings.TrimSpace(string(data[previousNewLineIndex:nextNewLineIndex])) err = fmt.Errorf("parsing options from script got error while parsing %q: %w", info, e) @@ -374,8 +374,7 @@ func (b *Bundle) instantiate(vuImpl *moduleVUImpl, vuID uint64) (*BundleInstance } if err != nil { - var exception *sobek.Exception - if errors.As(err, &exception) { + if exception, ok := errors.AsType[*sobek.Exception](err); ok { err = &scriptExceptionError{inner: exception} } return nil, err diff --git a/internal/js/init_and_modules_test.go b/internal/js/init_and_modules_test.go index 9bf9dbd2f..852f861f3 100644 --- a/internal/js/init_and_modules_test.go +++ b/internal/js/init_and_modules_test.go @@ -36,13 +36,13 @@ func (cm *CheckModule) VuCtx(_ context.Context) { cm.vuCtxCalled++ } -var uniqueModuleNumber int64 //nolint:gochecknoglobals // we need this so multiple test can register differently named modules +var uniqueModuleNumber atomic.Int64 //nolint:gochecknoglobals // we need this so multiple test can register differently named modules func TestNewJSRunnerWithCustomModule(t *testing.T) { t.Parallel() checkModule := &CheckModule{t: t} - moduleName := fmt.Sprintf("k6/x/check-%d", atomic.AddInt64(&uniqueModuleNumber, 1)) + moduleName := fmt.Sprintf("k6/x/check-%d", uniqueModuleNumber.Add(1)) modules.Register(moduleName, checkModule) script := fmt.Sprintf(` diff --git a/internal/js/initcontext_test.go b/internal/js/initcontext_test.go index 77eaa2e84..6e9ee3ee6 100644 --- a/internal/js/initcontext_test.go +++ b/internal/js/initcontext_test.go @@ -346,13 +346,13 @@ func TestRequestWithBinaryFile(t *testing.T) { Options: lib.Options{}, Logger: logger, Transport: &http.Transport{ - DialContext: (netext.NewDialer( + DialContext: netext.NewDialer( net.Dialer{ Timeout: 10 * time.Second, KeepAlive: 60 * time.Second, }, netext.NewResolver(net.LookupIP, 0, types.DNSfirst, types.DNSpreferIPv4), - )).DialContext, + ).DialContext, }, BufferPool: lib.NewBufferPool(), Samples: make(chan metrics.SampleContainer, 500), @@ -487,13 +487,13 @@ func TestRequestWithMultipleBinaryFiles(t *testing.T) { Options: lib.Options{}, Logger: logger, Transport: &http.Transport{ - DialContext: (netext.NewDialer( + DialContext: netext.NewDialer( net.Dialer{ Timeout: 10 * time.Second, KeepAlive: 60 * time.Second, }, netext.NewResolver(net.LookupIP, 0, types.DNSfirst, types.DNSpreferIPv4), - )).DialContext, + ).DialContext, }, BufferPool: lib.NewBufferPool(), Samples: make(chan metrics.SampleContainer, 500), diff --git a/internal/js/modules/k6/browser/browser/mapping_test.go b/internal/js/modules/k6/browser/browser/mapping_test.go index 97aa2803e..18f8f22bb 100644 --- a/internal/js/modules/k6/browser/browser/mapping_test.go +++ b/internal/js/modules/k6/browser/browser/mapping_test.go @@ -82,8 +82,7 @@ func TestMappings(t *testing.T) { mapped = tt.mapp() tested = make(map[string]bool) ) - for i := 0; i < typ.NumMethod(); i++ { - method := typ.Method(i) + for method := range typ.Methods() { require.NotNil(t, method) // sobek uses methods that starts with lowercase. diff --git a/internal/js/modules/k6/browser/chromium/browser_type.go b/internal/js/modules/k6/browser/chromium/browser_type.go index b6d421e02..3acc85ced 100644 --- a/internal/js/modules/k6/browser/chromium/browser_type.go +++ b/internal/js/modules/k6/browser/chromium/browser_type.go @@ -271,7 +271,7 @@ func (b *BrowserType) Launch(ctx, vuCtx context.Context) (_ *common.Browser, bro func (b *BrowserType) launch( ctx, vuCtx context.Context, opts *common.BrowserOptions, logger *log.Logger, ) (_ *common.Browser, pid int, _ error) { - flags, err := prepareFlags(opts, &(b.vu.State()).Options) + flags, err := prepareFlags(opts, &b.vu.State().Options) if err != nil { return nil, 0, fmt.Errorf("%w", err) } diff --git a/internal/js/modules/k6/browser/common/device.go b/internal/js/modules/k6/browser/common/device.go index fbd3aca27..844f91577 100644 --- a/internal/js/modules/k6/browser/common/device.go +++ b/internal/js/modules/k6/browser/common/device.go @@ -1,3 +1,4 @@ +//nolint:goconst package common // Device represents an end-user device (computer, tablet, phone etc.) diff --git a/internal/js/modules/k6/browser/common/element_handle.go b/internal/js/modules/k6/browser/common/element_handle.go index 9ca06a655..5089e30cf 100644 --- a/internal/js/modules/k6/browser/common/element_handle.go +++ b/internal/js/modules/k6/browser/common/element_handle.go @@ -1868,8 +1868,7 @@ func errorFromDOMError(v any) error { default: return fmt.Errorf("unexpected DOM error type %T", v) } - var uerr *k6ext.UserFriendlyError - if errors.As(err, &uerr) { + if _, ok := errors.AsType[*k6ext.UserFriendlyError](err); ok { return err } if strings.Contains(serr, "timed out") { diff --git a/internal/js/modules/k6/browser/common/frame_test.go b/internal/js/modules/k6/browser/common/frame_test.go index b5c61b8ce..6938850a9 100644 --- a/internal/js/modules/k6/browser/common/frame_test.go +++ b/internal/js/modules/k6/browser/common/frame_test.go @@ -111,11 +111,6 @@ func (e *executionContextTestStub) eval( // this needs to be a pointer as otherw return e.evalFn(apiCtx, opts, js, args...) } -// toPtr is a helper function to convert a value to a pointer. -func toPtr[T any](v T) *T { - return &v -} - func TestBuildAttributeSelector(t *testing.T) { t.Parallel() @@ -153,28 +148,28 @@ func TestBuildAttributeSelector(t *testing.T) { name: "quoted_single_exact_false", attrName: "data-test", attrValue: "'Foo Bar'", - opts: &GetByBaseOptions{Exact: toPtr(false)}, + opts: &GetByBaseOptions{Exact: new(false)}, want: "internal:attr=[data-test='Foo Bar'i]", }, { name: "quoted_single_exact_true", attrName: "data-test", attrValue: "'Foo Bar'", - opts: &GetByBaseOptions{Exact: toPtr(true)}, + opts: &GetByBaseOptions{Exact: new(true)}, want: "internal:attr=[data-test='Foo Bar's]", }, { name: "quoted_double_exact_true", attrName: "data-test", attrValue: "\"Foo Bar\"", - opts: &GetByBaseOptions{Exact: toPtr(true)}, + opts: &GetByBaseOptions{Exact: new(true)}, want: "internal:attr=[data-test=\"Foo Bar\"s]", }, { name: "quoted_double_exact_false", attrName: "data-test", attrValue: "\"Foo Bar\"", - opts: &GetByBaseOptions{Exact: toPtr(false)}, + opts: &GetByBaseOptions{Exact: new(false)}, want: "internal:attr=[data-test=\"Foo Bar\"i]", }, { diff --git a/internal/js/modules/k6/browser/common/http.go b/internal/js/modules/k6/browser/common/http.go index 756a08e6f..5ca5c7408 100644 --- a/internal/js/modules/k6/browser/common/http.go +++ b/internal/js/modules/k6/browser/common/http.go @@ -135,8 +135,7 @@ func NewRequest(ctx context.Context, logger *log.Logger, rp NewRequestParams) (* u, err := url.Parse(ev.Request.URL) if err != nil { - var uerr *url.Error - if errors.As(err, &uerr) { + if uerr, ok := errors.AsType[*url.Error](err); ok { err = uerr.Err } return nil, fmt.Errorf("parsing URL %q: %w", ev.Request.URL, err) diff --git a/internal/js/modules/k6/browser/common/network_manager.go b/internal/js/modules/k6/browser/common/network_manager.go index 40fac6c72..2f490d227 100644 --- a/internal/js/modules/k6/browser/common/network_manager.go +++ b/internal/js/modules/k6/browser/common/network_manager.go @@ -33,7 +33,7 @@ import ( // Credentials holds HTTP authentication credentials. type Credentials struct { Username string `js:"username"` - Password string `js:"password"` //nolint:gosec + Password string `js:"password"` } // IsEmpty returns true if the credentials are empty. diff --git a/internal/js/modules/k6/browser/common/page.go b/internal/js/modules/k6/browser/common/page.go index 185d32093..6b28fd800 100644 --- a/internal/js/modules/k6/browser/common/page.go +++ b/internal/js/modules/k6/browser/common/page.go @@ -91,12 +91,14 @@ func (r ReducedMotion) String() string { return reducedMotionToString[r] } -var reducedMotionToString = map[ReducedMotion]string{ //nolint:gochecknoglobals +//nolint:goconst,gochecknoglobals +var reducedMotionToString = map[ReducedMotion]string{ ReducedMotionReduce: "reduce", ReducedMotionNoPreference: "no-preference", } -var reducedMotionToID = map[string]ReducedMotion{ //nolint:gochecknoglobals +//nolint:gochecknoglobals +var reducedMotionToID = map[string]ReducedMotion{ "reduce": ReducedMotionReduce, "no-preference": ReducedMotionNoPreference, } diff --git a/internal/js/modules/k6/browser/common/page_test.go b/internal/js/modules/k6/browser/common/page_test.go index 001da5224..d85e51af9 100644 --- a/internal/js/modules/k6/browser/common/page_test.go +++ b/internal/js/modules/k6/browser/common/page_test.go @@ -163,6 +163,6 @@ func TestPageOn(t *testing.T) { err := p.On("metric", handler) assert.NoError(t, err) - assert.Len(t, p.eventHandlers[("metric")], 1) + assert.Len(t, p.eventHandlers["metric"], 1) }) } diff --git a/internal/js/modules/k6/browser/keyboardlayout/us.go b/internal/js/modules/k6/browser/keyboardlayout/us.go index 4df9b0c50..3d23a8079 100644 --- a/internal/js/modules/k6/browser/keyboardlayout/us.go +++ b/internal/js/modules/k6/browser/keyboardlayout/us.go @@ -1,3 +1,4 @@ +//nolint:goconst package keyboardlayout //nolint:funlen diff --git a/internal/js/modules/k6/browser/storage/file_persister.go b/internal/js/modules/k6/browser/storage/file_persister.go index 9c668e351..1fe92eb5e 100644 --- a/internal/js/modules/k6/browser/storage/file_persister.go +++ b/internal/js/modules/k6/browser/storage/file_persister.go @@ -103,7 +103,7 @@ func (r *RemoteFilePersister) Persist(ctx context.Context, path string, data io. return fmt.Errorf("creating upload request: %w", err) } - resp, err := r.httpClient.Do(req) //nolint:gosec + resp, err := r.httpClient.Do(req) if err != nil { return fmt.Errorf("performing upload request: %w", err) } @@ -142,7 +142,7 @@ func (r *RemoteFilePersister) requestPresignedURL(ctx context.Context, path stri req.Header.Add(k, v) } - resp, err := r.httpClient.Do(req) //nolint:gosec + resp, err := r.httpClient.Do(req) if err != nil { return PresignedURLResponse{}, fmt.Errorf("performing request: %w", err) } diff --git a/internal/js/modules/k6/browser/tests/get_by_test.go b/internal/js/modules/k6/browser/tests/get_by_test.go index 19f159ac9..416725e45 100644 --- a/internal/js/modules/k6/browser/tests/get_by_test.go +++ b/internal/js/modules/k6/browser/tests/get_by_test.go @@ -39,31 +39,31 @@ func TestGetByRoleSuccess(t *testing.T) { { name: "link", role: "link", - opts: &common.GetByRoleOptions{Name: toPtr(`'Link text'`)}, + opts: &common.GetByRoleOptions{Name: new(`'Link text'`)}, expected: 1, expectedText: "Link text", }, { name: "area", role: "link", - opts: &common.GetByRoleOptions{Name: toPtr(`'Map area'`)}, + opts: &common.GetByRoleOptions{Name: new(`'Map area'`)}, expected: 1, expectedText: "", }, { name: "button", role: "button", - opts: &common.GetByRoleOptions{Name: toPtr(`'Click'`)}, + opts: &common.GetByRoleOptions{Name: new(`'Click'`)}, expected: 1, expectedText: "Click", }, { name: "submit_type", role: "button", - opts: &common.GetByRoleOptions{Name: toPtr(`'Submit'`)}, + opts: &common.GetByRoleOptions{Name: new(`'Submit'`)}, expected: 1, expectedText: "", }, { name: "image_type", role: "button", - opts: &common.GetByRoleOptions{Name: toPtr(`'Image Button'`)}, + opts: &common.GetByRoleOptions{Name: new(`'Image Button'`)}, expected: 1, expectedText: "", }, { @@ -79,13 +79,13 @@ func TestGetByRoleSuccess(t *testing.T) { { name: "text_type", role: "textbox", - opts: &common.GetByRoleOptions{Name: toPtr(`'Text type'`)}, + opts: &common.GetByRoleOptions{Name: new(`'Text type'`)}, expected: 1, expectedText: "", }, { name: "textarea", role: "textbox", - opts: &common.GetByRoleOptions{Name: toPtr(`'Text area'`)}, + opts: &common.GetByRoleOptions{Name: new(`'Text area'`)}, expected: 1, expectedText: "Textarea", }, { @@ -116,7 +116,7 @@ func TestGetByRoleSuccess(t *testing.T) { { name: "details_summary", role: "group", - opts: &common.GetByRoleOptions{Name: toPtr(`'details'`)}, + opts: &common.GetByRoleOptions{Name: new(`'details'`)}, expected: 1, expectedText: "SummaryDetails", }, { @@ -127,37 +127,37 @@ func TestGetByRoleSuccess(t *testing.T) { { name: "h1", role: "heading", - opts: &common.GetByRoleOptions{Level: toPtr(int64(1))}, + opts: &common.GetByRoleOptions{Level: new(int64(1))}, expected: 1, expectedText: "Heading1", }, { name: "h2", role: "heading", - opts: &common.GetByRoleOptions{Level: toPtr(int64(2))}, + opts: &common.GetByRoleOptions{Level: new(int64(2))}, expected: 1, expectedText: "Heading2", }, { name: "h3", role: "heading", - opts: &common.GetByRoleOptions{Level: toPtr(int64(3))}, + opts: &common.GetByRoleOptions{Level: new(int64(3))}, expected: 1, expectedText: "Heading3", }, { name: "h4", role: "heading", - opts: &common.GetByRoleOptions{Level: toPtr(int64(4))}, + opts: &common.GetByRoleOptions{Level: new(int64(4))}, expected: 1, expectedText: "Heading4", }, { name: "h5", role: "heading", - opts: &common.GetByRoleOptions{Level: toPtr(int64(5))}, + opts: &common.GetByRoleOptions{Level: new(int64(5))}, expected: 1, expectedText: "Heading5", }, { name: "h6", role: "heading", - opts: &common.GetByRoleOptions{Level: toPtr(int64(6))}, + opts: &common.GetByRoleOptions{Level: new(int64(6))}, expected: 1, expectedText: "Heading6", }, { @@ -168,7 +168,7 @@ func TestGetByRoleSuccess(t *testing.T) { { name: "img", role: "img", - opts: &common.GetByRoleOptions{Name: toPtr(`'Img'`)}, + opts: &common.GetByRoleOptions{Name: new(`'Img'`)}, expected: 1, expectedText: "", }, { @@ -179,25 +179,25 @@ func TestGetByRoleSuccess(t *testing.T) { { name: "ul_list", role: "list", - opts: &common.GetByRoleOptions{Name: toPtr(`'ul'`)}, + opts: &common.GetByRoleOptions{Name: new(`'ul'`)}, expected: 1, expectedText: "", }, { name: "ol_list", role: "list", - opts: &common.GetByRoleOptions{Name: toPtr(`'ol'`)}, + opts: &common.GetByRoleOptions{Name: new(`'ol'`)}, expected: 1, expectedText: "", }, { name: "ul_li_listitem", role: "listitem", - opts: &common.GetByRoleOptions{Name: toPtr(`'ul-li'`)}, + opts: &common.GetByRoleOptions{Name: new(`'ul-li'`)}, expected: 1, expectedText: "Item1", }, { name: "ol_li_listitem", role: "listitem", - opts: &common.GetByRoleOptions{Name: toPtr(`'ol-li'`)}, + opts: &common.GetByRoleOptions{Name: new(`'ol-li'`)}, expected: 1, expectedText: "Item2", }, { @@ -213,19 +213,19 @@ func TestGetByRoleSuccess(t *testing.T) { { name: "fieldset_legend", role: "group", - opts: &common.GetByRoleOptions{Name: toPtr(`'Legend'`)}, + opts: &common.GetByRoleOptions{Name: new(`'Legend'`)}, expected: 1, expectedText: "Legend", }, { name: "figure_figcaption", role: "figure", - opts: &common.GetByRoleOptions{Name: toPtr(`'Caption'`)}, + opts: &common.GetByRoleOptions{Name: new(`'Caption'`)}, expected: 1, expectedText: "Caption", }, { name: "table", role: "table", - opts: &common.GetByRoleOptions{Name: toPtr(`'table1'`)}, + opts: &common.GetByRoleOptions{Name: new(`'table1'`)}, expected: 1, expectedText: "", }, { @@ -241,43 +241,43 @@ func TestGetByRoleSuccess(t *testing.T) { { name: "table_head_cell", role: "cell", - opts: &common.GetByRoleOptions{Name: toPtr(`'th'`)}, + opts: &common.GetByRoleOptions{Name: new(`'th'`)}, expected: 1, expectedText: "Head Cell", }, { name: "table_head_gridcell", role: "gridcell", - opts: &common.GetByRoleOptions{Name: toPtr(`'th gridcell'`)}, + opts: &common.GetByRoleOptions{Name: new(`'th gridcell'`)}, expected: 1, expectedText: "Head Gridcell", }, { name: "table_body", role: "rowgroup", - opts: &common.GetByRoleOptions{Name: toPtr(`'tbody'`)}, + opts: &common.GetByRoleOptions{Name: new(`'tbody'`)}, expected: 1, expectedText: "Cell", }, { name: "table_foot", role: "rowgroup", - opts: &common.GetByRoleOptions{Name: toPtr(`'tfoot'`)}, + opts: &common.GetByRoleOptions{Name: new(`'tfoot'`)}, expected: 1, expectedText: "Foot", }, { name: "table_tr", role: "row", - opts: &common.GetByRoleOptions{Name: toPtr(`'tr'`)}, + opts: &common.GetByRoleOptions{Name: new(`'tr'`)}, expected: 1, expectedText: "Row", }, { name: "table_td_cell", role: "cell", - opts: &common.GetByRoleOptions{Name: toPtr(`'td'`)}, + opts: &common.GetByRoleOptions{Name: new(`'td'`)}, expected: 1, expectedText: "Column Cell", }, { name: "table_td_gridcell", role: "gridcell", - opts: &common.GetByRoleOptions{Name: toPtr(`'td gridcell'`)}, + opts: &common.GetByRoleOptions{Name: new(`'td gridcell'`)}, expected: 1, expectedText: "Column Gridcell", }, { @@ -316,14 +316,14 @@ func TestGetByRoleSuccess(t *testing.T) { { name: "form", role: "form", - opts: &common.GetByRoleOptions{Name: toPtr(`'form'`)}, + opts: &common.GetByRoleOptions{Name: new(`'form'`)}, expected: 1, expectedText: "", }, // Only works with aria labels. { name: "section", role: "region", - opts: &common.GetByRoleOptions{Name: toPtr(`'Region Section'`)}, + opts: &common.GetByRoleOptions{Name: new(`'Region Section'`)}, expected: 1, expectedText: "Region content", }, { @@ -369,7 +369,7 @@ func TestGetByRoleSuccess(t *testing.T) { { name: "menu", role: "list", - opts: &common.GetByRoleOptions{Name: toPtr(`'menu'`)}, + opts: &common.GetByRoleOptions{Name: new(`'menu'`)}, expected: 1, expectedText: "Menu item", }, { @@ -400,7 +400,7 @@ func TestGetByRoleSuccess(t *testing.T) { { name: "svg", role: "img", - opts: &common.GetByRoleOptions{Name: toPtr(`'svg'`)}, + opts: &common.GetByRoleOptions{Name: new(`'svg'`)}, expected: 1, expectedText: "", }, { @@ -411,13 +411,13 @@ func TestGetByRoleSuccess(t *testing.T) { { name: "select", role: "combobox", - opts: &common.GetByRoleOptions{Name: toPtr(`'select'`)}, + opts: &common.GetByRoleOptions{Name: new(`'select'`)}, expected: 1, expectedText: "", }, { name: "select_multiple", role: "listbox", - opts: &common.GetByRoleOptions{Name: toPtr(`'select multiple'`)}, + opts: &common.GetByRoleOptions{Name: new(`'select multiple'`)}, expected: 1, expectedText: "", }, { @@ -655,115 +655,115 @@ func TestGetByRoleSuccess(t *testing.T) { { name: "text_content_as_name", role: "button", - opts: &common.GetByRoleOptions{Name: toPtr(`'Submit Form'`)}, + opts: &common.GetByRoleOptions{Name: new(`'Submit Form'`)}, expected: 1, expectedText: "", }, { name: "not_exact", role: "button", - opts: &common.GetByRoleOptions{Name: toPtr(`'submit form'`), Exact: toPtr(false)}, + opts: &common.GetByRoleOptions{Name: new(`'submit form'`), Exact: new(false)}, expected: 1, expectedText: "", }, { name: "exact_no_match", role: "button", - opts: &common.GetByRoleOptions{Name: toPtr(`'submit form'`), Exact: toPtr(true)}, + opts: &common.GetByRoleOptions{Name: new(`'submit form'`), Exact: new(true)}, expected: 0, expectedText: "", }, { name: "exact_match", role: "button", - opts: &common.GetByRoleOptions{Name: toPtr(`'Submit Form'`), Exact: toPtr(true)}, + opts: &common.GetByRoleOptions{Name: new(`'Submit Form'`), Exact: new(true)}, expected: 1, expectedText: "", }, { name: "aria_label_as_name", role: "button", - opts: &common.GetByRoleOptions{Name: toPtr(`'Save Draft'`)}, + opts: &common.GetByRoleOptions{Name: new(`'Save Draft'`)}, expected: 1, expectedText: "", }, { name: "aria_labelledby_as_name", role: "button", - opts: &common.GetByRoleOptions{Name: toPtr(`'Upload'`)}, + opts: &common.GetByRoleOptions{Name: new(`'Upload'`)}, expected: 1, expectedText: "labelledby-upload-button", }, { name: "hidden_text_nodes_should_be_ignored", role: "button", - opts: &common.GetByRoleOptions{Name: toPtr(`'FooBar'`)}, + opts: &common.GetByRoleOptions{Name: new(`'FooBar'`)}, expected: 0, expectedText: "", }, { name: "only_visible_node", role: "button", - opts: &common.GetByRoleOptions{Name: toPtr(`'Bar'`)}, + opts: &common.GetByRoleOptions{Name: new(`'Bar'`)}, expected: 1, expectedText: "Bar", }, { name: "regex_matching", role: "heading", - opts: &common.GetByRoleOptions{Name: toPtr(`/^[a-z0-9]+$/`)}, + opts: &common.GetByRoleOptions{Name: new(`/^[a-z0-9]+$/`)}, expected: 1, expectedText: "abc123", }, { name: "selected_option", role: "option", - opts: &common.GetByRoleOptions{Selected: toPtr(true)}, + opts: &common.GetByRoleOptions{Selected: new(true)}, expected: 1, expectedText: "One", }, { name: "pressed_option", role: "button", - opts: &common.GetByRoleOptions{Pressed: toPtr(true)}, + opts: &common.GetByRoleOptions{Pressed: new(true)}, expected: 1, expectedText: "Toggle", }, { name: "expanded_option", role: "button", - opts: &common.GetByRoleOptions{Expanded: toPtr(true)}, + opts: &common.GetByRoleOptions{Expanded: new(true)}, expected: 1, expectedText: "Expanded", }, { name: "level_option", role: "heading", - opts: &common.GetByRoleOptions{Level: toPtr(int64(6))}, + opts: &common.GetByRoleOptions{Level: new(int64(6))}, expected: 1, expectedText: "Section", }, { name: "checked_option", role: "checkbox", - opts: &common.GetByRoleOptions{Checked: toPtr(true)}, + opts: &common.GetByRoleOptions{Checked: new(true)}, expected: 1, expectedText: "", }, { name: "radio_checked_option", role: "radio", - opts: &common.GetByRoleOptions{Checked: toPtr(true)}, + opts: &common.GetByRoleOptions{Checked: new(true)}, expected: 1, expectedText: "", }, { name: "disabled_option", role: "button", - opts: &common.GetByRoleOptions{Disabled: toPtr(true)}, + opts: &common.GetByRoleOptions{Disabled: new(true)}, expected: 1, expectedText: "Go", }, { name: "include_css_hidden", role: "button", - opts: &common.GetByRoleOptions{Name: toPtr(`'Hidden X Button'`), IncludeHidden: toPtr(true)}, + opts: &common.GetByRoleOptions{Name: new(`'Hidden X Button'`), IncludeHidden: new(true)}, expected: 1, expectedText: "X", }, { name: "include_aria_hidden", role: "button", - opts: &common.GetByRoleOptions{Name: toPtr(`'Hidden Hi Button'`), IncludeHidden: toPtr(true)}, + opts: &common.GetByRoleOptions{Name: new(`'Hidden Hi Button'`), IncludeHidden: new(true)}, expected: 1, expectedText: "Hi", }, { name: "combo_options", role: "button", - opts: &common.GetByRoleOptions{Pressed: toPtr(false), Name: toPtr(`'Archive'`), IncludeHidden: toPtr(true)}, + opts: &common.GetByRoleOptions{Pressed: new(false), Name: new(`'Archive'`), IncludeHidden: new(true)}, expected: 1, expectedText: "Combo Options Button", }, } @@ -817,7 +817,7 @@ func TestGetByRoleFailure(t *testing.T) { { "missing_quotes_on_string", "button", - &common.GetByRoleOptions{Name: toPtr(`Submit Form`)}, + &common.GetByRoleOptions{Name: new(`Submit Form`)}, "Error while parsing selector `button[name=Submit Form]` - unexpected symbol", }, { @@ -888,13 +888,13 @@ func TestGetByAltTextSuccess(t *testing.T) { { "exact_match", "'World Map'", - &common.GetByBaseOptions{Exact: toPtr(true)}, + &common.GetByBaseOptions{Exact: new(true)}, 1, }, { "no_exact_match", "'world map'", - &common.GetByBaseOptions{Exact: toPtr(true)}, + &common.GetByBaseOptions{Exact: new(true)}, 0, }, { @@ -967,13 +967,13 @@ func TestGetByLabelSuccess(t *testing.T) { { "exact_match", `"Password"`, - &common.GetByBaseOptions{Exact: toPtr(true)}, + &common.GetByBaseOptions{Exact: new(true)}, 1, }, { "no_exact_match", `"password"`, - &common.GetByBaseOptions{Exact: toPtr(true)}, + &common.GetByBaseOptions{Exact: new(true)}, 0, }, { @@ -1051,13 +1051,13 @@ func TestGetByPlaceholderSuccess(t *testing.T) { { "exact_match", "'Email address'", - &common.GetByBaseOptions{Exact: toPtr(true)}, + &common.GetByBaseOptions{Exact: new(true)}, 1, }, { "no_exact_match", "'email address'", - &common.GetByBaseOptions{Exact: toPtr(true)}, + &common.GetByBaseOptions{Exact: new(true)}, 0, }, { @@ -1147,13 +1147,13 @@ func TestGetByTitleSuccess(t *testing.T) { { "exact_match", "'Link to somewhere'", - &common.GetByBaseOptions{Exact: toPtr(true)}, + &common.GetByBaseOptions{Exact: new(true)}, 1, }, { "no_exact_match", "'link to somewhere'", - &common.GetByBaseOptions{Exact: toPtr(true)}, + &common.GetByBaseOptions{Exact: new(true)}, 0, }, { @@ -1341,14 +1341,14 @@ func TestGetByTextSuccess(t *testing.T) { { "exact_match", `"Learn more"`, - &common.GetByBaseOptions{Exact: toPtr(true)}, + &common.GetByBaseOptions{Exact: new(true)}, 1, "Learn more", }, { "no_exact_match", `"learn more"`, - &common.GetByBaseOptions{Exact: toPtr(true)}, + &common.GetByBaseOptions{Exact: new(true)}, 0, "", }, diff --git a/internal/js/modules/k6/browser/tests/test_browser.go b/internal/js/modules/k6/browser/tests/test_browser.go index 45613ba3f..6f4dbd54f 100644 --- a/internal/js/modules/k6/browser/tests/test_browser.go +++ b/internal/js/modules/k6/browser/tests/test_browser.go @@ -477,8 +477,3 @@ func asString(tb testing.TB, v any) string { require.True(tb, ok) return s } - -// toPtr is a helper function to convert a value to a pointer. -func toPtr[T any](v T) *T { - return &v -} diff --git a/internal/js/modules/k6/browser/tests/ws/server.go b/internal/js/modules/k6/browser/tests/ws/server.go index cc0e7b6c2..f6721557f 100644 --- a/internal/js/modules/k6/browser/tests/ws/server.go +++ b/internal/js/modules/k6/browser/tests/ws/server.go @@ -60,7 +60,6 @@ func NewServer(t testing.TB, opts ...func(*Server)) *Server { dialer := k6netext.NewDialer(net.Dialer{ Timeout: 2 * time.Second, KeepAlive: 10 * time.Second, - DualStack: true, }, k6netext.NewResolver(net.LookupIP, 0, k6types.DNSfirst, k6types.DNSpreferIPv4)) const wsURL = "wsbin.local" diff --git a/internal/js/modules/k6/experimental/streams/readable_streams.go b/internal/js/modules/k6/experimental/streams/readable_streams.go index 36e5174f2..93ea90988 100644 --- a/internal/js/modules/k6/experimental/streams/readable_streams.go +++ b/internal/js/modules/k6/experimental/streams/readable_streams.go @@ -218,8 +218,7 @@ func (stream *ReadableStream) pullAlgorithm( return func(obj *sobek.Object) *sobek.Promise { v, err := call(underlyingSource, obj) if err != nil { - var ex *sobek.Exception - if errors.As(err, &ex) { + if ex, ok := errors.AsType[*sobek.Exception](err); ok { return newRejectedPromise(stream.vu, ex.Value()) } return newRejectedPromise(stream.vu, err) diff --git a/internal/js/modules/k6/experimental/streams/writable_stream_default_controller.go b/internal/js/modules/k6/experimental/streams/writable_stream_default_controller.go index 1c9eb2d08..6bf89fb29 100644 --- a/internal/js/modules/k6/experimental/streams/writable_stream_default_controller.go +++ b/internal/js/modules/k6/experimental/streams/writable_stream_default_controller.go @@ -496,8 +496,7 @@ func (controller *WritableStreamDefaultController) toObject() (*sobek.Object, er // exceptionValue extracts the underlying JavaScript value from a Go error, if it wraps a // [sobek.Exception]. Otherwise, it returns the error as-is. func exceptionValue(err error) any { - var ex *sobek.Exception - if errors.As(err, &ex) { + if ex, ok := errors.AsType[*sobek.Exception](err); ok { return ex.Value() } return err diff --git a/internal/js/modules/k6/grpc/client_test.go b/internal/js/modules/k6/grpc/client_test.go index a42da69b5..13280dc03 100644 --- a/internal/js/modules/k6/grpc/client_test.go +++ b/internal/js/modules/k6/grpc/client_test.go @@ -1279,8 +1279,8 @@ func TestClient_TlsParameters(t *testing.T) { clientAuthCA := []byte("-----BEGIN CERTIFICATE-----\nMIIBWzCCAQGgAwIBAgIJAIQMBgLi+DV6MAoGCCqGSM49BAMCMBAxDjAMBgNVBAMM\nBU15IENBMCAXDTIyMDEyMTEyMjkzNloYDzMwMjEwNTI0MTIyOTM2WjAQMQ4wDAYD\nVQQDDAVNeSBDQTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABHnrghULHa2hSa/C\nWimwCn42KWdlPqd6/zs3JgLIxTvBHJJlfbhWbBqtybqyovWd3QykHMIpx0NZmpYn\nG8FoWpmjQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMBAf8EBTADAQH/MB0GA1Ud\nDgQWBBSkukBA8lgFvvBJAYKsoSUR+PX71jAKBggqhkjOPQQDAgNIADBFAiEAiFF7\nY54CMNRSBSVMgd4mQgrzJInRH88KpLsQ7VeOAaQCIEa0vaLln9zxIDZQKocml4Db\nAEJr8tDzMKIds6sRTBT4\n-----END CERTIFICATE-----") clientAuth := "-----BEGIN CERTIFICATE-----\\nMIIBVzCB/6ADAgECAgkAg/SeNG3XqB0wCgYIKoZIzj0EAwIwEDEOMAwGA1UEAwwF\\nTXkgQ0EwIBcNMjIwMTIxMTUxMjM0WhgPMzAyMTA1MjQxNTEyMzRaMBExDzANBgNV\\nBAMMBmNsaWVudDBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABKM7OJQMYG4KLtDA\\ngZ8zOg2PimHMmQnjD2HtI4cSwIUJJnvHWLowbFe9fk6XeP9b3dK1ImUI++/EZdVr\\nABAcngejPzA9MA4GA1UdDwEB/wQEAwIBBjAMBgNVHRMBAf8EAjAAMB0GA1UdDgQW\\nBBSttJe1mcPEnBOZ6wvKPG4zL0m1CzAKBggqhkjOPQQDAgNHADBEAiBPSLgKA/r9\\nu/FW6W+oy6Odm1kdNMGCI472iTn545GwJgIgb3UQPOUTOj0IN4JLJYfmYyXviqsy\\nzk9eWNHFXDA9U6U=\\n-----END CERTIFICATE-----" - clientAuthKey := ("-----BEGIN EC PRIVATE KEY-----\\nMHcCAQEEINDaMGkOT3thu1A0LfLJr3Jd011/aEG6OArmEQaujwgpoAoGCCqGSM49\\nAwEHoUQDQgAEozs4lAxgbgou0MCBnzM6DY+KYcyZCeMPYe0jhxLAhQkme8dYujBs\\nV71+Tpd4/1vd0rUiZQj778Rl1WsAEByeBw==\\n-----END EC PRIVATE KEY-----") - clientAuthKeyEncrypted := ("-----BEGIN EC PRIVATE KEY-----\\nProc-Type: 4,ENCRYPTED\\nDEK-Info: AES-256-CBC,3E311E9B602231BFB5C752071EE7D652\\n\\nsAKeqbacug0v4ruE1A0CACwGVEGBQVOl1CiGVp5RsxgNZKXzMS6EsTTNLw378coF\\nKXbF+he05HIuzToOz2ANLXov1iCrVpotKVB4l2obTQvg+5VET902ky99Mc9Us7jd\\nUwW8LpXlSlhcNWuUfK6wyosL42TbcIxjqZWaESW+6ww=\\n-----END EC PRIVATE KEY-----") + clientAuthKey := "-----BEGIN EC PRIVATE KEY-----\\nMHcCAQEEINDaMGkOT3thu1A0LfLJr3Jd011/aEG6OArmEQaujwgpoAoGCCqGSM49\\nAwEHoUQDQgAEozs4lAxgbgou0MCBnzM6DY+KYcyZCeMPYe0jhxLAhQkme8dYujBs\\nV71+Tpd4/1vd0rUiZQj778Rl1WsAEByeBw==\\n-----END EC PRIVATE KEY-----" + clientAuthKeyEncrypted := "-----BEGIN EC PRIVATE KEY-----\\nProc-Type: 4,ENCRYPTED\\nDEK-Info: AES-256-CBC,3E311E9B602231BFB5C752071EE7D652\\n\\nsAKeqbacug0v4ruE1A0CACwGVEGBQVOl1CiGVp5RsxgNZKXzMS6EsTTNLw378coF\\nKXbF+he05HIuzToOz2ANLXov1iCrVpotKVB4l2obTQvg+5VET902ky99Mc9Us7jd\\nUwW8LpXlSlhcNWuUfK6wyosL42TbcIxjqZWaESW+6ww=\\n-----END EC PRIVATE KEY-----" trivialKeyPassword := "abc123" trivialWrongKeyPassword := "abc321" diff --git a/internal/js/modules/k6/webcrypto/elliptic_curve.go b/internal/js/modules/k6/webcrypto/elliptic_curve.go index 552c97927..f831b9677 100644 --- a/internal/js/modules/k6/webcrypto/elliptic_curve.go +++ b/internal/js/modules/k6/webcrypto/elliptic_curve.go @@ -1,3 +1,4 @@ +//nolint:staticcheck //a bunch of deprecated logic is used in this package. Needs to be fixed. package webcrypto import ( diff --git a/internal/js/modules/k6/webcrypto/jwk.go b/internal/js/modules/k6/webcrypto/jwk.go index 556f950fb..5f1e922d4 100644 --- a/internal/js/modules/k6/webcrypto/jwk.go +++ b/internal/js/modules/k6/webcrypto/jwk.go @@ -1,3 +1,4 @@ +//nolint:staticcheck //a bunch of deprecated logic is used in this package. Needs to be fixed. package webcrypto import ( @@ -161,8 +162,8 @@ func encodeCurveBigInt(data *big.Int, curveBits int) string { // padLeft pads the byte slice with zeros to the left to ensure it has a specific length. func padLeft(bytes []byte, size int) []byte { - padding := make([]byte, size-len(bytes)) - return append(padding, bytes...) //nolint:makezero // we need to pad with zeros + padding := make([]byte, size-len(bytes), size) + return append(padding, bytes...) } func exportECJWK(key *CryptoKey) (any, error) { diff --git a/internal/js/modules/k6/websockets/websockets.go b/internal/js/modules/k6/websockets/websockets.go index 66076b216..15ee993b8 100644 --- a/internal/js/modules/k6/websockets/websockets.go +++ b/internal/js/modules/k6/websockets/websockets.go @@ -209,7 +209,7 @@ func defineWebsocket(rt *sobek.Runtime, w *webSocket) { "url", rt.ToValue(w.url.String()), sobek.FLAG_FALSE, sobek.FLAG_FALSE, sobek.FLAG_TRUE)) must(rt, w.obj.DefineAccessorProperty( // this needs to be with an accessor as we change the value "readyState", rt.ToValue(func() sobek.Value { - return rt.ToValue((uint)(w.readyState)) + return rt.ToValue(uint(w.readyState)) }), nil, sobek.FLAG_FALSE, sobek.FLAG_TRUE)) must(rt, w.obj.DefineAccessorProperty( "bufferedAmount", rt.ToValue(func() sobek.Value { return rt.ToValue(w.bufferedAmount) }), nil, @@ -543,10 +543,9 @@ func (w *webSocket) readPump(wg *sync.WaitGroup) { continue } - var closeErr *websocket.CloseError var code int var reason string - if errors.As(err, &closeErr) { + if closeErr, ok := errors.AsType[*websocket.CloseError](err); ok { code = closeErr.Code reason = closeErr.Text } diff --git a/internal/js/runner.go b/internal/js/runner.go index db109f504..467fac26c 100644 --- a/internal/js/runner.go +++ b/internal/js/runner.go @@ -894,8 +894,7 @@ func (u *ActiveVU) RunOnce() error { // Call the exported function. _, isFullIteration, totalTime, err := u.runFn(ctx, true, fn, cancel, u.setupData) if err != nil { - var x *sobek.InterruptedError - if errors.As(err, &x) { + if x, ok := errors.AsType[*sobek.InterruptedError](err); ok { if v, ok := x.Value().(*errext.InterruptError); ok { v.Reason = x.Error() err = v @@ -976,8 +975,7 @@ func (u *VU) runFn( u.moduleVUImpl.eventLoop.WaitOnRegistered() } endTime := time.Now() - var exception *sobek.Exception - if errors.As(err, &exception) { + if exception, ok := errors.AsType[*sobek.Exception](err); ok { err = &scriptExceptionError{inner: exception} } diff --git a/internal/lib/summary/machine_readable.go b/internal/lib/summary/machine_readable.go index 9a38c6824..9ad4020bd 100644 --- a/internal/lib/summary/machine_readable.go +++ b/internal/lib/summary/machine_readable.go @@ -70,9 +70,8 @@ func machineReadableSummaryResultsMetricsBuilder(metrics Metrics) []cog.Builder[ val := reflect.ValueOf(metrics) metricBuilders := make([]cog.Builder[machinereadable.Metric], 0) - for i := 0; i < val.NumField(); i++ { - value := val.Field(i) - metricsMap, isMetricsMap := value.Interface().(map[string]Metric) + for _, value := range val.Fields() { + metricsMap, isMetricsMap := reflect.TypeAssert[map[string]Metric](value) if !isMetricsMap { continue // Theoretically, this should never happen as all the struct fields satisfy the type. } diff --git a/internal/lib/testutils/httpmultibin/grpc_wrappers_testing/service.go b/internal/lib/testutils/httpmultibin/grpc_wrappers_testing/service.go index a0003e4c4..ac6f74c00 100644 --- a/internal/lib/testutils/httpmultibin/grpc_wrappers_testing/service.go +++ b/internal/lib/testutils/httpmultibin/grpc_wrappers_testing/service.go @@ -1,5 +1,5 @@ // Package grpc_wrappers_testing provides a test service that could be used for the testing gRPC wrappers -package grpc_wrappers_testing //nolint:revive // we want to be consistent with the other packages +package grpc_wrappers_testing import ( context "context" diff --git a/internal/loader/loader.go b/internal/loader/loader.go index d7c6cf044..5cedd2ac4 100644 --- a/internal/loader/loader.go +++ b/internal/loader/loader.go @@ -41,7 +41,7 @@ type unresolvableURLError string func (u unresolvableURLError) Error() string { // TODO potentially add more things about what k6 supports if users report being confused. - return fmt.Sprintf(`The moduleSpecifier %q couldn't be recognised as something k6 supports.`, (string)(u)) + return fmt.Sprintf(`The moduleSpecifier %q couldn't be recognised as something k6 supports.`, string(u)) } // Resolve a relative path to an absolute one. @@ -210,7 +210,7 @@ func fetch(logger logrus.FieldLogger, u string) ([]byte, error) { if err != nil { return nil, err } - res, err := http.DefaultClient.Do(req) //nolint:gosec + res, err := http.DefaultClient.Do(req) if err != nil { return nil, err } diff --git a/internal/loader/loader_test.go b/internal/loader/loader_test.go index 35a8fb70d..c8b8ffd20 100644 --- a/internal/loader/loader_test.go +++ b/internal/loader/loader_test.go @@ -210,7 +210,7 @@ func TestLoad(t *testing.T) { pwdURL, err := url.Parse(sr("HTTPSBIN_URL")) require.NoError(t, err) - moduleSpecifier := ("./robots.txt") + moduleSpecifier := "./robots.txt" moduleSpecifierURL, err := loader.Resolve(pwdURL, moduleSpecifier) require.NoError(t, err) diff --git a/internal/loader/readsource.go b/internal/loader/readsource.go index 3586c484f..623314209 100644 --- a/internal/loader/readsource.go +++ b/internal/loader/readsource.go @@ -47,9 +47,8 @@ func ReadSource( srcURL, err := Resolve(pwdURL, filepath.ToSlash(src)) if err != nil { - var unresolvedError unresolvableURLError - if errors.As(err, &unresolvedError) { - return nil, fmt.Errorf(fileSchemeCouldntBeLoadedMsg, (string)(unresolvedError)) //nolint:staticcheck + if unresolvedError, ok := errors.AsType[unresolvableURLError](err); ok { + return nil, fmt.Errorf(fileSchemeCouldntBeLoadedMsg, string(unresolvedError)) //nolint:staticcheck } return nil, err } diff --git a/internal/loader/readsource_test.go b/internal/loader/readsource_test.go index 3ba67b348..579e2289e 100644 --- a/internal/loader/readsource_test.go +++ b/internal/loader/readsource_test.go @@ -17,7 +17,7 @@ import ( type errorReader string func (e errorReader) Read(_ []byte) (int, error) { - return 0, errors.New((string)(e)) + return 0, errors.New(string(e)) } var _ io.Reader = errorReader("") diff --git a/internal/log/loki.go b/internal/log/loki.go index 173fa3caf..3cd319f5a 100644 --- a/internal/log/loki.go +++ b/internal/log/loki.go @@ -457,7 +457,7 @@ func (h *lokiHook) push(b bytes.Buffer) error { req.Header.Add(header[0], header[1]) } - res, err := h.client.Do(req) //nolint:gosec + res, err := h.client.Do(req) if res != nil { if res.StatusCode >= 400 { diff --git a/internal/metrics/engine/engine.go b/internal/metrics/engine/engine.go index 7cc130e9f..f369af533 100644 --- a/internal/metrics/engine/engine.go +++ b/internal/metrics/engine/engine.go @@ -29,7 +29,7 @@ type MetricsEngine struct { // These can be both top-level metrics or sub-metrics metricsWithThresholds []*metrics.Metric - breachedThresholdsCount uint32 + breachedThresholdsCount atomic.Uint32 // TODO: completely refactor: // - make these private, add a method to export the raw data @@ -249,7 +249,7 @@ func (me *MetricsEngine) evaluateThresholds( sort.Strings(breachedThresholds) me.logger.Debugf("Thresholds on %d metrics crossed: %v", len(breachedThresholds), breachedThresholds) } - atomic.StoreUint32(&me.breachedThresholdsCount, uint32(len(breachedThresholds))) //nolint:gosec + me.breachedThresholdsCount.Store(uint32(len(breachedThresholds))) //nolint:gosec return breachedThresholds, shouldAbort } @@ -257,5 +257,5 @@ func (me *MetricsEngine) evaluateThresholds( // the thresholds were breached (failed) during the last processing phase. This // API is safe to use concurrently. func (me *MetricsEngine) GetMetricsWithBreachedThresholdsCount() uint32 { - return atomic.LoadUint32(&me.breachedThresholdsCount) + return me.breachedThresholdsCount.Load() } diff --git a/internal/output/cloud/output.go b/internal/output/cloud/output.go index ba43541c4..1480443f1 100644 --- a/internal/output/cloud/output.go +++ b/internal/output/cloud/output.go @@ -423,8 +423,7 @@ func (out *Output) getRunStatus(testErr error) cloudapi.RunStatus { return cloudapi.RunStatusFinished } - var err errext.HasAbortReason - if errors.As(testErr, &err) { + if err, ok := errors.AsType[errext.HasAbortReason](testErr); ok { abortReason := err.AbortReason() switch abortReason { case errext.AbortedByUser: diff --git a/internal/output/prometheusrw/remote/client.go b/internal/output/prometheusrw/remote/client.go index a4efb78e2..d767b416a 100644 --- a/internal/output/prometheusrw/remote/client.go +++ b/internal/output/prometheusrw/remote/client.go @@ -30,7 +30,7 @@ type HTTPConfig struct { // BasicAuth holds the config for basic authentication. type BasicAuth struct { - Username, Password string //nolint:gosec + Username, Password string } // WriteClient is a client implementation of the Prometheus remote write protocol. @@ -100,7 +100,7 @@ func (c *WriteClient) Store(ctx context.Context, series []*prompb.TimeSeries) er req.Header.Set("Content-Type", "application/x-protobuf") req.Header.Set("X-Prometheus-Remote-Write-Version", "0.1.0") - resp, err := c.hc.Do(req) //nolint:gosec + resp, err := c.hc.Do(req) if err != nil { return fmt.Errorf("HTTP POST request failed: %w", err) } diff --git a/internal/output/prometheusrw/sigv4/sigv4.go b/internal/output/prometheusrw/sigv4/sigv4.go index 81d135ab4..f8f6d0a21 100644 --- a/internal/output/prometheusrw/sigv4/sigv4.go +++ b/internal/output/prometheusrw/sigv4/sigv4.go @@ -179,7 +179,7 @@ func buildCanonicalHeaders( var canonicalHeaders strings.Builder for _, h := range headers { if h == hostHeader { - _, _ = fmt.Fprintf(&canonicalHeaders, "%s:%s\n", hostHeader, stripExcessSpaces(host)) //nolint:gosec + _, _ = fmt.Fprintf(&canonicalHeaders, "%s:%s\n", hostHeader, stripExcessSpaces(host)) continue } diff --git a/internal/secretsource/url/url.go b/internal/secretsource/url/url.go index 60ee60352..c574dc3ce 100644 --- a/internal/secretsource/url/url.go +++ b/internal/secretsource/url/url.go @@ -183,7 +183,7 @@ func (us *urlSecrets) Get(key string) (string, error) { req.Header.Set(k, v) } - response, err := us.httpClient.Do(req) //nolint:gosec + response, err := us.httpClient.Do(req) if err != nil { // Network errors are retryable return fmt.Errorf("failed to get secret: %w", err), true diff --git a/internal/ui/form_fields.go b/internal/ui/form_fields.go index ebaf83a59..43daa30a2 100644 --- a/internal/ui/form_fields.go +++ b/internal/ui/form_fields.go @@ -107,7 +107,7 @@ func (f PasswordField) GetContents(r io.Reader) (string, error) { if !ok { return "", errors.New("cannot read password from the supplied terminal") } - password, err := term.ReadPassword(int(stdin.Fd())) //nolint:gosec + password, err := term.ReadPassword(int(stdin.Fd())) if err != nil { // Possibly running on Cygwin/mintty which doesn't emulate // pseudo terminals properly, so fallback to plain text input. diff --git a/internal/ui/pb/helpers.go b/internal/ui/pb/helpers.go index d952324ea..e7e3c8f7f 100644 --- a/internal/ui/pb/helpers.go +++ b/internal/ui/pb/helpers.go @@ -41,7 +41,7 @@ func GetFixedLengthFloatFormat(maxValue float64, precision uint) (formatStr stri if precision > 0 { resLen += precision + 1 } - return "%0" + strconv.FormatUint(uint64(resLen), 10) + "." + strconv.Itoa(int(precision)) + "f" //nolint:gosec + return "%0" + strconv.FormatUint(uint64(resLen), 10) + "." + strconv.Itoa(int(precision)) + "f" } // GetFixedLengthDuration takes a *positive* duration and its max value and @@ -68,7 +68,7 @@ func GetFixedLengthDuration(d, maxDuration time.Duration) (result string) { // Positions: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 buf := [18]byte{'0', '0', '0', '0', '0', '0', 'd', '0', '0', 'h', '0', '0', 'm', '0', '0', '.', '0', 's'} - u := d.Round(rounding) / (rounding) + u := d.Round(rounding) / rounding u, buf[16] = u/10, byte(u%10)+'0' //nolint:gosec u, buf[14] = u/10, byte(u%10)+'0' //nolint:gosec if maxDuration < 10*time.Second { diff --git a/js/common/init_error.go b/js/common/init_error.go index 8cfd53b64..054bd3919 100644 --- a/js/common/init_error.go +++ b/js/common/init_error.go @@ -5,13 +5,13 @@ type InitContextError string // NewInitContextError returns a new InitContextError with the provided message func NewInitContextError(msg string) InitContextError { - return (InitContextError)(msg) + return InitContextError(msg) } func (i InitContextError) Error() string { - return (string)(i) + return string(i) } func (i InitContextError) String() string { - return (string)(i) + return string(i) } diff --git a/js/common/interrupt_error.go b/js/common/interrupt_error.go index 9197b5fb0..9c8a11465 100644 --- a/js/common/interrupt_error.go +++ b/js/common/interrupt_error.go @@ -8,8 +8,7 @@ import ( // UnwrapSobekInterruptedError returns the internal error handled by Sobek. func UnwrapSobekInterruptedError(err error) error { - var sobekErr *sobek.InterruptedError - if errors.As(err, &sobekErr) { + if sobekErr, ok := errors.AsType[*sobek.InterruptedError](err); ok { if e, ok := sobekErr.Value().(error); ok { return e } diff --git a/js/modules/k6/html/gen/gen_elements.go b/js/modules/k6/html/gen/gen_elements.go index 2550b89f4..213af1a16 100644 --- a/js/modules/k6/html/gen/gen_elements.go +++ b/js/modules/k6/html/gen/gen_elements.go @@ -1,4 +1,6 @@ // Package main - this package generates some of the code for k6/html +// +//nolint:goconst package main import ( diff --git a/js/modules/k6/http/cookiejar.go b/js/modules/k6/http/cookiejar.go index 0c4a85c32..7059b437e 100644 --- a/js/modules/k6/http/cookiejar.go +++ b/js/modules/k6/http/cookiejar.go @@ -50,7 +50,7 @@ func (j CookieJar) Set(url, name, value string, opts sobek.Value) (bool, error) return false, err } - c := http.Cookie{Name: name, Value: value} + c := http.Cookie{Name: name, Value: value} //nolint:gosec // outgoing request cookie, not a Set-Cookie response paramsV := opts if !common.IsNullish(paramsV) { params := paramsV.ToObject(rt) @@ -110,7 +110,7 @@ func (j CookieJar) Delete(url, name string) error { return err } - c := http.Cookie{Name: name, MaxAge: -1} + c := http.Cookie{Name: name, MaxAge: -1} //nolint:gosec // outgoing request cookie, not a Set-Cookie response j.Jar.SetCookies(u, []*http.Cookie{&c}) return nil diff --git a/js/modules/k6/http/request.go b/js/modules/k6/http/request.go index 454281b47..82931e00e 100644 --- a/js/modules/k6/http/request.go +++ b/js/modules/k6/http/request.go @@ -75,8 +75,7 @@ func (c *Client) handleParseRequestError(err error) (*Response, error) { state.Logger.WithField("error", err).Warn("Request Failed") r := httpext.NewResponse() r.Error = err.Error() - var k6e httpext.K6Error - if errors.As(err, &k6e) { + if k6e, ok := errors.AsType[httpext.K6Error](err); ok { r.ErrorCode = int(k6e.Code) } return &Response{Response: r, client: c}, nil @@ -442,8 +441,7 @@ func (c *Client) prepareBatchArray(requests []any) ( parsedReq, err := c.parseBatchRequest(i, req) if err != nil { resp.Error = err.Error() - var k6e httpext.K6Error - if errors.As(err, &k6e) { + if k6e, ok := errors.AsType[httpext.K6Error](err); ok { resp.ErrorCode = int(k6e.Code) } results[i] = c.responseFromHTTPext(resp) @@ -472,8 +470,7 @@ func (c *Client) prepareBatchObject(requests map[string]any) ( parsedReq, err := c.parseBatchRequest(key, req) if err != nil { resp.Error = err.Error() - var k6e httpext.K6Error - if errors.As(err, &k6e) { + if k6e, ok := errors.AsType[httpext.K6Error](err); ok { resp.ErrorCode = int(k6e.Code) } results[key] = c.responseFromHTTPext(resp) diff --git a/js/modules/k6/http/request_test.go b/js/modules/k6/http/request_test.go index 3f03e284c..2253cec05 100644 --- a/js/modules/k6/http/request_test.go +++ b/js/modules/k6/http/request_test.go @@ -21,6 +21,7 @@ import ( "net/http/httptest" "net/url" "runtime" + "slices" "strconv" "strings" "testing" @@ -1513,8 +1514,8 @@ func TestRequestCompression(t *testing.T) { var prev io.Reader = compressedBuf if expectedEncoding != "" { - for i := len(algos) - 1; i >= 0; i-- { - prev = decompress(algos[i], prev) + for _, algo := range slices.Backward(algos) { + prev = decompress(algo, prev) } } diff --git a/js/modules/k6/http/response.go b/js/modules/k6/http/response.go index 634319806..14cd963b1 100644 --- a/js/modules/k6/http/response.go +++ b/js/modules/k6/http/response.go @@ -98,8 +98,7 @@ func (res *Response) JSON(selector ...string) sobek.Value { } if err := json.Unmarshal(body, &v); err != nil { - var syntaxError *json.SyntaxError - if errors.As(err, &syntaxError) { + if syntaxError, ok := errors.AsType[*json.SyntaxError](err); ok { err = checkErrorInJSON(body, int(syntaxError.Offset), err) } common.Throw(rt, err) diff --git a/lib/archive.go b/lib/archive.go index 450138ad8..00984afd6 100644 --- a/lib/archive.go +++ b/lib/archive.go @@ -60,7 +60,7 @@ type Archive struct { Data []byte `json:"-"` // Working directory for resolving relative paths. - Pwd string `json:"pwd"` //nolint:gosec // only for json + Pwd string `json:"pwd"` PwdURL *url.URL `json:"-"` Filesystems map[string]fsext.Fs `json:"-"` @@ -373,7 +373,7 @@ func (arc *Archive) json() ([]byte, error) { // this prevents <, >, and & from being escaped in JSON strings encoder.SetEscapeHTML(false) encoder.SetIndent("", " ") - if err := encoder.Encode(arc); err != nil { + if err := encoder.Encode(arc); err != nil { //nolint:gosec // pwd is not a password return nil, err } diff --git a/lib/executor/constant_arrival_rate_test.go b/lib/executor/constant_arrival_rate_test.go index 015470097..04a7159df 100644 --- a/lib/executor/constant_arrival_rate_test.go +++ b/lib/executor/constant_arrival_rate_test.go @@ -74,9 +74,9 @@ func TestConstantArrivalRateRunNotEnoughAllocatedVUsWarn(t *testing.T) { func TestConstantArrivalRateRunCorrectRate(t *testing.T) { t.Parallel() synctest.Test(t, func(t *testing.T) { - var count int64 + var count atomic.Int64 runner := simpleRunner(func(_ context.Context, _ *lib.State) error { - atomic.AddInt64(&count, 1) + count.Add(1) return nil }) @@ -94,13 +94,13 @@ func TestConstantArrivalRateRunCorrectRate(t *testing.T) { if i == 0 { break } - currentCount := atomic.SwapInt64(&count, 0) + currentCount := count.Swap(0) totalCount += currentCount // We have a relatively relaxed constraint here, but we also check // the final iteration count exactly below: assert.InDelta(t, 50, currentCount, 5) } - assert.InDelta(t, 250, totalCount+atomic.LoadInt64(&count), 2) + assert.InDelta(t, 250, totalCount+count.Load(), 2) }() synctest.Wait() engineOut := make(chan metrics.SampleContainer, 1000) @@ -169,11 +169,11 @@ func TestConstantArrivalRateRunCorrectTiming(t *testing.T) { t.Run(fmt.Sprintf("segment %s sequence %s", test.segment, test.sequence), func(t *testing.T) { t.Parallel() synctest.Test(t, func(t *testing.T) { - var count int64 + var count atomic.Int64 startTime := time.Now() expectedTimeInt64 := int64(test.start) runner := simpleRunner(func(_ context.Context, _ *lib.State) error { - current := atomic.AddInt64(&count, 1) + current := count.Add(1) expectedTime := test.start if current != 1 { @@ -210,7 +210,7 @@ func TestConstantArrivalRateRunCorrectTiming(t *testing.T) { for i := range seconds { time.Sleep(time.Second) - currentCount = atomic.LoadInt64(&count) + currentCount = count.Load() assert.InDelta(t, int64(i+1)*rateScaled, currentCount, 3) } }() diff --git a/lib/executor/ramping_arrival_rate.go b/lib/executor/ramping_arrival_rate.go index 35d8d5f89..136ca0e86 100644 --- a/lib/executor/ramping_arrival_rate.go +++ b/lib/executor/ramping_arrival_rate.go @@ -509,7 +509,7 @@ func (varr RampingArrivalRate) Run(parentCtx context.Context, out chan<- metrics // executing the received requests for iterations. type activeVUPool struct { iterations chan struct{} - running uint64 + running atomic.Uint64 execState *lib.ExecutionState wg sync.WaitGroup } @@ -536,7 +536,7 @@ func (p *activeVUPool) TryRunIteration() bool { // Running returns the number of the currently running VUs. func (p *activeVUPool) Running() uint64 { - return atomic.LoadUint64(&p.running) + return p.running.Load() } // AddVU adds the active VU to the pool of VUs for handling the incoming @@ -551,11 +551,11 @@ func (p *activeVUPool) AddVU(ctx context.Context, avu lib.ActiveVU, runfn func(c close(ch) for range p.iterations { - atomic.AddUint64(&p.running, uint64(1)) + p.running.Add(uint64(1)) p.execState.ModCurrentlyActiveVUsCount(+1) runfn(ctx, avu) p.execState.ModCurrentlyActiveVUsCount(-1) - atomic.AddUint64(&p.running, ^uint64(0)) + p.running.Add(^uint64(0)) } }() <-ch diff --git a/lib/executor/ramping_arrival_rate_test.go b/lib/executor/ramping_arrival_rate_test.go index a81b323b0..8dbee657e 100644 --- a/lib/executor/ramping_arrival_rate_test.go +++ b/lib/executor/ramping_arrival_rate_test.go @@ -73,9 +73,9 @@ func TestRampingArrivalRateRunCorrectRate(t *testing.T) { t.Parallel() synctest.Test(t, func(t *testing.T) { - var count int64 + var count atomic.Int64 runner := simpleRunner(func(_ context.Context, _ *lib.State) error { - atomic.AddInt64(&count, 1) + count.Add(1) return nil }) @@ -91,7 +91,7 @@ func TestRampingArrivalRateRunCorrectRate(t *testing.T) { case <-ctx.Done(): return } - currentCount = atomic.SwapInt64(&count, 0) + currentCount = count.Swap(0) assert.InDelta(t, 10, currentCount, 1) select { @@ -99,7 +99,7 @@ func TestRampingArrivalRateRunCorrectRate(t *testing.T) { case <-ctx.Done(): return } - currentCount = atomic.SwapInt64(&count, 0) + currentCount = count.Swap(0) assert.InDelta(t, 30, currentCount, 2) select { @@ -107,7 +107,7 @@ func TestRampingArrivalRateRunCorrectRate(t *testing.T) { case <-ctx.Done(): return } - currentCount = atomic.SwapInt64(&count, 0) + currentCount = count.Swap(0) assert.InDelta(t, 50, currentCount, 3) }(test.ctx) @@ -202,10 +202,10 @@ func TestRampingArrivalRateRunCorrectRateWithSlowRate(t *testing.T) { MaxVUs: null.IntFrom(3), } - var count int64 + var count atomic.Int64 ch := make(chan struct{}) // closed when new unplannedVU is started and signal to get to next iterations runner := simpleRunner(func(_ context.Context, _ *lib.State) error { - cur := atomic.AddInt64(&count, 1) + cur := count.Add(1) if cur == 1 { <-ch // wait to start again } @@ -219,12 +219,12 @@ func TestRampingArrivalRateRunCorrectRateWithSlowRate(t *testing.T) { engineOut := make(chan metrics.SampleContainer, 1000) test.state.SetInitVUFunc(func(ctx context.Context, _ *logrus.Entry) (lib.InitializedVU, error) { t.Log("init") - cur := atomic.LoadInt64(&count) + cur := count.Load() require.Equal(t, int64(1), cur) time.Sleep(time.Millisecond * 200) close(ch) time.Sleep(time.Millisecond * 200) - cur = atomic.LoadInt64(&count) + cur = count.Load() require.NotEqual(t, int64(1), cur) idl, idg := test.state.GetUniqueVUIdentifiers() @@ -295,9 +295,9 @@ func BenchmarkRampingArrivalRateRun(b *testing.B) { } }() - var count int64 + var count atomic.Int64 runner := simpleRunner(func(_ context.Context, _ *lib.State) error { - atomic.AddInt64(&count, 1) + count.Add(1) return nil }) @@ -335,7 +335,7 @@ func BenchmarkRampingArrivalRateRun(b *testing.B) { took := time.Since(start) assert.NoError(b, err) - iterations := float64(atomic.LoadInt64(&count)) + iterations := float64(count.Load()) b.ReportMetric(0, "ns/op") b.ReportMetric(iterations/took.Seconds(), "iterations/s") }) diff --git a/lib/executor/ramping_vus_test.go b/lib/executor/ramping_vus_test.go index 85120241c..fe1452d04 100644 --- a/lib/executor/ramping_vus_test.go +++ b/lib/executor/ramping_vus_test.go @@ -116,14 +116,14 @@ func TestRampingVUsRun(t *testing.T) { }, } - var iterCount int64 + var iterCount atomic.Int64 runner := simpleRunner(func(_ context.Context, _ *lib.State) error { // Sleeping for a weird duration somewhat offset from the // executor ticks to hopefully keep race conditions out of // our control from failing the test. time.Sleep(300 * time.Millisecond) - atomic.AddInt64(&iterCount, 1) + iterCount.Add(1) return nil }) @@ -148,7 +148,7 @@ func TestRampingVUsRun(t *testing.T) { require.NoError(t, <-errCh) assert.Equal(t, []int64{5, 3, 0}, result) - assert.Equal(t, int64(29), atomic.LoadInt64(&iterCount)) + assert.Equal(t, int64(29), iterCount.Load()) }) } @@ -361,15 +361,15 @@ func TestRampingVUsHandleRemainingVUs(t *testing.T) { } var ( - gotVuInterrupted uint32 - gotVuFinished uint32 + gotVuInterrupted atomic.Uint32 + gotVuFinished atomic.Uint32 ) runner := simpleRunner(func(ctx context.Context, _ *lib.State) error { select { case <-time.After(vuSleepDuration): - atomic.AddUint32(&gotVuFinished, 1) + gotVuFinished.Add(1) case <-ctx.Done(): - atomic.AddUint32(&gotVuInterrupted, 1) + gotVuInterrupted.Add(1) } return nil }) @@ -381,8 +381,8 @@ func TestRampingVUsHandleRemainingVUs(t *testing.T) { // sum(stages) + GracefulRampDown require.NoError(t, test.executor.Run(test.ctx, nil)) - assert.Equal(t, wantVuInterrupted, atomic.LoadUint32(&gotVuInterrupted)) - assert.Equal(t, wantVuFinished, atomic.LoadUint32(&gotVuFinished)) + assert.Equal(t, wantVuInterrupted, gotVuInterrupted.Load()) + assert.Equal(t, wantVuFinished, gotVuFinished.Load()) }) } diff --git a/lib/executor/vu_handle_test.go b/lib/executor/vu_handle_test.go index c94060829..2a9e6c150 100644 --- a/lib/executor/vu_handle_test.go +++ b/lib/executor/vu_handle_test.go @@ -40,28 +40,28 @@ func TestVUHandleRace(t *testing.T) { return nil } - var getVUCount uint64 - var returnVUCount uint64 + var getVUCount atomic.Uint64 + var returnVUCount atomic.Uint64 getVU := func() (lib.InitializedVU, error) { - return runner.NewVU(ctx, atomic.AddUint64(&getVUCount, 1), 0, nil) + return runner.NewVU(ctx, getVUCount.Add(1), 0, nil) } returnVU := func(_ lib.InitializedVU) { - atomic.AddUint64(&returnVUCount, 1) + returnVUCount.Add(1) // do something } - var interruptedIter int64 - var fullIterations int64 + var interruptedIter atomic.Int64 + var fullIterations atomic.Int64 runIter := func(ctx context.Context, vu lib.ActiveVU) bool { _ = vu.RunOnce() select { case <-ctx.Done(): // Don't log errors or emit iterations metrics from cancelled iterations - atomic.AddInt64(&interruptedIter, 1) + interruptedIter.Add(1) return false default: - atomic.AddInt64(&fullIterations, 1) + fullIterations.Add(1) return true } } @@ -96,19 +96,19 @@ func TestVUHandleRace(t *testing.T) { wg.Wait() vuHandle.hardStop() // STOP it time.Sleep(time.Millisecond * 50) - interruptedBefore := atomic.LoadInt64(&interruptedIter) - fullBefore := atomic.LoadInt64(&fullIterations) + interruptedBefore := interruptedIter.Load() + fullBefore := fullIterations.Load() _ = vuHandle.start() time.Sleep(time.Millisecond * 50) // just to be sure an iteration will squeeze in cancel() time.Sleep(time.Millisecond * 50) - interruptedAfter := atomic.LoadInt64(&interruptedIter) - fullAfter := atomic.LoadInt64(&fullIterations) + interruptedAfter := interruptedIter.Load() + fullAfter := fullIterations.Load() assert.True(t, interruptedBefore >= interruptedAfter-1, "too big of a difference %d >= %d - 1", interruptedBefore, interruptedAfter) assert.True(t, fullBefore+1 <= fullAfter, "too small of a difference %d + 1 <= %d", fullBefore, fullAfter) - require.Equal(t, atomic.LoadUint64(&getVUCount), atomic.LoadUint64(&returnVUCount)) + require.Equal(t, getVUCount.Load(), returnVUCount.Load()) } // this test is mostly interesting when -race is enabled @@ -129,31 +129,31 @@ func TestVUHandleStartStopRace(t *testing.T) { return nil } - var vuID uint64 + var vuID atomic.Uint64 testIterations := 10000 returned := make(chan struct{}) getVU := func() (lib.InitializedVU, error) { returned = make(chan struct{}) - return runner.NewVU(ctx, atomic.AddUint64(&vuID, 1), 0, nil) + return runner.NewVU(ctx, vuID.Add(1), 0, nil) } returnVU := func(v lib.InitializedVU) { - require.Equal(t, atomic.LoadUint64(&vuID), v.(*minirunner.VU).ID) + require.Equal(t, vuID.Load(), v.(*minirunner.VU).ID) close(returned) } - var interruptedIter int64 - var fullIterations int64 + var interruptedIter atomic.Int64 + var fullIterations atomic.Int64 runIter := func(ctx context.Context, vu lib.ActiveVU) bool { _ = vu.RunOnce() select { case <-ctx.Done(): // Don't log errors or emit iterations metrics from cancelled iterations - atomic.AddInt64(&interruptedIter, 1) + interruptedIter.Add(1) return false default: - atomic.AddInt64(&fullIterations, 1) + fullIterations.Add(1) return true } } @@ -174,14 +174,14 @@ func TestVUHandleStartStopRace(t *testing.T) { vuHandle.hardStop() // STOP it time.Sleep(time.Millisecond * 5) - interruptedBefore := atomic.LoadInt64(&interruptedIter) - fullBefore := atomic.LoadInt64(&fullIterations) + interruptedBefore := interruptedIter.Load() + fullBefore := fullIterations.Load() _ = vuHandle.start() time.Sleep(time.Millisecond * 50) // just to be sure an iteration will squeeze in cancel() time.Sleep(time.Millisecond * 5) - interruptedAfter := atomic.LoadInt64(&interruptedIter) - fullAfter := atomic.LoadInt64(&fullIterations) + interruptedAfter := interruptedIter.Load() + fullAfter := fullIterations.Load() assert.True(t, interruptedBefore >= interruptedAfter-1, "too big of a difference %d >= %d - 1", interruptedBefore, interruptedAfter) assert.True(t, fullBefore+1 <= fullAfter, @@ -190,18 +190,18 @@ func TestVUHandleStartStopRace(t *testing.T) { type handleVUTest struct { runner *minirunner.MiniRunner - getVUCount uint32 - returnVUCount uint32 - interruptedIter int64 - fullIterations int64 + getVUCount atomic.Uint32 + returnVUCount atomic.Uint32 + interruptedIter atomic.Int64 + fullIterations atomic.Int64 } func (h *handleVUTest) getVU() (lib.InitializedVU, error) { - return h.runner.NewVU(context.Background(), uint64(atomic.AddUint32(&h.getVUCount, 1)), 0, nil) + return h.runner.NewVU(context.Background(), uint64(h.getVUCount.Add(1)), 0, nil) } func (h *handleVUTest) returnVU(_ lib.InitializedVU) { - atomic.AddUint32(&h.returnVUCount, 1) + h.returnVUCount.Add(1) } func (h *handleVUTest) runIter(ctx context.Context, _ lib.ActiveVU) bool { @@ -213,10 +213,10 @@ func (h *handleVUTest) runIter(ctx context.Context, _ lib.ActiveVU) bool { select { case <-ctx.Done(): // Don't log errors or emit iterations metrics from cancelled iterations - atomic.AddInt64(&h.interruptedIter, 1) + h.interruptedIter.Add(1) return false default: - atomic.AddInt64(&h.fullIterations, 1) + h.fullIterations.Add(1) return true } } @@ -250,17 +250,17 @@ func TestVUHandleSimple(t *testing.T) { err = vuHandle.start() require.NoError(t, err) time.Sleep(time.Millisecond * 1500) - assert.EqualValues(t, 1, atomic.LoadUint32(&test.getVUCount)) - assert.EqualValues(t, 0, atomic.LoadUint32(&test.returnVUCount)) - assert.EqualValues(t, 0, atomic.LoadInt64(&test.interruptedIter)) - assert.EqualValues(t, 1, atomic.LoadInt64(&test.fullIterations)) + assert.EqualValues(t, 1, test.getVUCount.Load()) + assert.EqualValues(t, 0, test.returnVUCount.Load()) + assert.EqualValues(t, 0, test.interruptedIter.Load()) + assert.EqualValues(t, 1, test.fullIterations.Load()) cancel() wg.Wait() time.Sleep(time.Millisecond * 5) - assert.EqualValues(t, 1, atomic.LoadUint32(&test.getVUCount)) - assert.EqualValues(t, 1, atomic.LoadUint32(&test.returnVUCount)) - assert.EqualValues(t, 1, atomic.LoadInt64(&test.interruptedIter)) - assert.EqualValues(t, 1, atomic.LoadInt64(&test.fullIterations)) + assert.EqualValues(t, 1, test.getVUCount.Load()) + assert.EqualValues(t, 1, test.returnVUCount.Load()) + assert.EqualValues(t, 1, test.interruptedIter.Load()) + assert.EqualValues(t, 1, test.fullIterations.Load()) }) }) @@ -287,10 +287,10 @@ func TestVUHandleSimple(t *testing.T) { time.Sleep(time.Millisecond * 50) vuHandle.gracefulStop() time.Sleep(time.Millisecond * 1500) - assert.EqualValues(t, 1, atomic.LoadUint32(&test.getVUCount)) - assert.EqualValues(t, 1, atomic.LoadUint32(&test.returnVUCount)) - assert.EqualValues(t, 0, atomic.LoadInt64(&test.interruptedIter)) - assert.EqualValues(t, 1, atomic.LoadInt64(&test.fullIterations)) + assert.EqualValues(t, 1, test.getVUCount.Load()) + assert.EqualValues(t, 1, test.returnVUCount.Load()) + assert.EqualValues(t, 0, test.interruptedIter.Load()) + assert.EqualValues(t, 1, test.fullIterations.Load()) err = vuHandle.start() require.NoError(t, err) time.Sleep(time.Millisecond * 1500) @@ -298,10 +298,10 @@ func TestVUHandleSimple(t *testing.T) { wg.Wait() time.Sleep(time.Millisecond * 50) - assert.EqualValues(t, 2, atomic.LoadUint32(&test.getVUCount)) - assert.EqualValues(t, 2, atomic.LoadUint32(&test.returnVUCount)) - assert.EqualValues(t, 1, atomic.LoadInt64(&test.interruptedIter)) - assert.EqualValues(t, 2, atomic.LoadInt64(&test.fullIterations)) + assert.EqualValues(t, 2, test.getVUCount.Load()) + assert.EqualValues(t, 2, test.returnVUCount.Load()) + assert.EqualValues(t, 1, test.interruptedIter.Load()) + assert.EqualValues(t, 2, test.fullIterations.Load()) }) }) @@ -328,10 +328,10 @@ func TestVUHandleSimple(t *testing.T) { time.Sleep(time.Millisecond * 5) vuHandle.hardStop() time.Sleep(time.Millisecond * 15) - assert.EqualValues(t, 1, atomic.LoadUint32(&test.getVUCount)) - assert.EqualValues(t, 1, atomic.LoadUint32(&test.returnVUCount)) - assert.EqualValues(t, 1, atomic.LoadInt64(&test.interruptedIter)) - assert.EqualValues(t, 0, atomic.LoadInt64(&test.fullIterations)) + assert.EqualValues(t, 1, test.getVUCount.Load()) + assert.EqualValues(t, 1, test.returnVUCount.Load()) + assert.EqualValues(t, 1, test.interruptedIter.Load()) + assert.EqualValues(t, 0, test.fullIterations.Load()) err = vuHandle.start() require.NoError(t, err) time.Sleep(time.Millisecond * 1500) @@ -339,10 +339,10 @@ func TestVUHandleSimple(t *testing.T) { wg.Wait() time.Sleep(time.Millisecond * 5) - assert.EqualValues(t, 2, atomic.LoadUint32(&test.getVUCount)) - assert.EqualValues(t, 2, atomic.LoadUint32(&test.returnVUCount)) - assert.EqualValues(t, 2, atomic.LoadInt64(&test.interruptedIter)) - assert.EqualValues(t, 1, atomic.LoadInt64(&test.fullIterations)) + assert.EqualValues(t, 2, test.getVUCount.Load()) + assert.EqualValues(t, 2, test.returnVUCount.Load()) + assert.EqualValues(t, 2, test.interruptedIter.Load()) + assert.EqualValues(t, 1, test.fullIterations.Load()) }) }) } diff --git a/lib/limiter_test.go b/lib/limiter_test.go index ec1c7a80b..0dee9bfbb 100644 --- a/lib/limiter_test.go +++ b/lib/limiter_test.go @@ -59,17 +59,17 @@ func TestSlotLimiters(t *testing.T) { wg.Add(tc.limit) } - var counter uint32 + var counter atomic.Uint32 for i := 0; i < tc.launches; i++ { go func() { l.Begin() - atomic.AddUint32(&counter, 1) + counter.Add(1) wg.Done() }() } wg.Wait() - assert.EqualValues(t, tc.expMid, atomic.LoadUint32(&counter)) + assert.EqualValues(t, tc.expMid, counter.Load()) if tc.limit != 0 && tc.limit < tc.launches { wg.Add(tc.launches - tc.limit) @@ -77,7 +77,7 @@ func TestSlotLimiters(t *testing.T) { l.End() } wg.Wait() - assert.EqualValues(t, tc.launches, atomic.LoadUint32(&counter)) + assert.EqualValues(t, tc.launches, counter.Load()) } }) } diff --git a/lib/netext/aia.go b/lib/netext/aia.go index fb632cbf6..d24be11ab 100644 --- a/lib/netext/aia.go +++ b/lib/netext/aia.go @@ -147,8 +147,7 @@ func (f *AIAFetcher) verifyWithAIA( } // Only unknown-authority errors are AIA-fixable; expired, hostname mismatch, etc. aren't. - var unknownAuthErr x509.UnknownAuthorityError - if !errors.As(verifyErr, &unknownAuthErr) { + if _, ok := errors.AsType[x509.UnknownAuthorityError](verifyErr); !ok { return verifyErr } @@ -283,7 +282,7 @@ func (f *AIAFetcher) fetchCertFromAIAURL( return nil, fmt.Errorf("building AIA request: %w", err) } - resp, err := f.httpClient.Do(req) //nolint:gosec // G107: URL is from a server-presented cert AIA extension + resp, err := f.httpClient.Do(req) if err != nil { return nil, fmt.Errorf("fetching AIA certificate: %w", err) } diff --git a/lib/netext/aia_test.go b/lib/netext/aia_test.go index f6b85a7c9..e21682d6a 100644 --- a/lib/netext/aia_test.go +++ b/lib/netext/aia_test.go @@ -343,10 +343,10 @@ func TestAIAFetcher_UsesProvidedDialer(t *testing.T) { func TestAIAFetcher_CacheIsolatedBetweenFetchers(t *testing.T) { t.Parallel() - var aiaHits int32 + var aiaHits atomic.Int32 handler := &tlstest.AIAHandler{} aiaSrv := startAIAServer(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - atomic.AddInt32(&aiaHits, 1) + aiaHits.Add(1) handler.ServeHTTP(w, r) })) chain := buildChainWithAIA(t, aiaSrv.URL+"/ca.der") @@ -361,14 +361,14 @@ func TestAIAFetcher_CacheIsolatedBetweenFetchers(t *testing.T) { respA, errA := testHTTPClient(t, fetcherA.Wrap(&tls.Config{RootCAs: chain.RootPool}, nullLogger())).Get(leafOnlyTLSServerURL(tlsSrv)) //nolint:noctx require.NoError(t, errA) _ = respA.Body.Close() - hitsAfterA := atomic.LoadInt32(&aiaHits) + hitsAfterA := aiaHits.Load() require.Equal(t, int32(1), hitsAfterA, "fetcher A should have fetched once") // Fetcher B, independently, must hit the AIA server again — no shared cache. respB, errB := testHTTPClient(t, fetcherB.Wrap(&tls.Config{RootCAs: chain.RootPool}, nullLogger())).Get(leafOnlyTLSServerURL(tlsSrv)) //nolint:noctx require.NoError(t, errB) _ = respB.Body.Close() - hitsAfterB := atomic.LoadInt32(&aiaHits) + hitsAfterB := aiaHits.Load() assert.Equal(t, int32(2), hitsAfterB, "fetcher B must fetch independently; caches are not shared across fetchers") } diff --git a/lib/netext/httpext/compression.go b/lib/netext/httpext/compression.go index fa46f1521..3a52382e1 100644 --- a/lib/netext/httpext/compression.go +++ b/lib/netext/httpext/compression.go @@ -8,6 +8,7 @@ import ( "fmt" "io" "net/http" + "slices" "strings" "github.com/andybalholm/brotli" @@ -149,8 +150,8 @@ func readResponseBody( contentEncodings := strings.Split(resp.Header.Get("Content-Encoding"), ",") // Transparently decompress the body if it's has a content-encoding we // support. If not, simply return it as it is. - for i := len(contentEncodings) - 1; i >= 0; i-- { - contentEncoding := strings.TrimSpace(contentEncodings[i]) + for _, contentEncoding := range slices.Backward(contentEncodings) { + contentEncoding := strings.TrimSpace(contentEncoding) if compression, err := CompressionTypeString(contentEncoding); err == nil { decoder, err := pickDecoder(compression, rc) if err != nil { diff --git a/lib/netext/httpext/error_codes.go b/lib/netext/httpext/error_codes.go index 2e4251c4a..7f8119e41 100644 --- a/lib/netext/httpext/error_codes.go +++ b/lib/netext/httpext/error_codes.go @@ -190,7 +190,7 @@ func errorCodeForNetOpError(err *net.OpError) (errCode, string) { case syscall.Errno: return netUnknownErrnoErrorCode, fmt.Sprintf(netUnknownErrnoErrorCodeMsg, - err.Op, (int)(inErr), runtime.GOOS, inErr.Error()) //nolint:gosec + err.Op, int(inErr), runtime.GOOS, inErr.Error()) default: return defaultTCPErrorCode, err.Error() } diff --git a/lib/netext/httpext/error_codes_test.go b/lib/netext/httpext/error_codes_test.go index 7ec224868..b4da36ed1 100644 --- a/lib/netext/httpext/error_codes_test.go +++ b/lib/netext/httpext/error_codes_test.go @@ -58,7 +58,7 @@ func TestBlackListedIPError(t *testing.T) { type timeoutError bool func (t timeoutError) Timeout() bool { - return (bool)(t) + return bool(t) } func (t timeoutError) Error() string { diff --git a/lib/netext/httpext/request.go b/lib/netext/httpext/request.go index f88f04daa..4536d74a4 100644 --- a/lib/netext/httpext/request.go +++ b/lib/netext/httpext/request.go @@ -268,7 +268,7 @@ func MakeRequest(ctx context.Context, state *lib.State, preq *ParsedHTTPRequest) reqCtx, cancelFunc := context.WithTimeout(ctx, preq.Timeout) defer cancelFunc() mreq := preq.Req.WithContext(reqCtx) - res, resErr := client.Do(mreq) //nolint:gosec + res, resErr := client.Do(mreq) // TODO(imiric): It would be safer to check for a writeable // response body here instead of status code, but those are @@ -349,6 +349,7 @@ func MakeRequest(ctx context.Context, state *lib.State, preq *ParsedHTTPRequest) func SetRequestCookies(req *http.Request, jar *cookiejar.Jar, reqCookies map[string]*HTTPRequestCookie) { replacedCookies := make(map[string]struct{}) for key, reqCookie := range reqCookies { + //nolint:gosec // outgoing request cookie, not a Set-Cookie response req.AddCookie(&http.Cookie{Name: key, Value: reqCookie.Value}) if reqCookie.Replace { replacedCookies[key] = struct{}{} @@ -356,6 +357,7 @@ func SetRequestCookies(req *http.Request, jar *cookiejar.Jar, reqCookies map[str } for _, c := range jar.Cookies(req.URL) { if _, ok := replacedCookies[c.Name]; !ok { + //nolint:gosec // outgoing request cookie, not a Set-Cookie response req.AddCookie(&http.Cookie{Name: c.Name, Value: c.Value}) } } diff --git a/lib/netext/httpext/request_test.go b/lib/netext/httpext/request_test.go index dbd0ca08a..88bf4b860 100644 --- a/lib/netext/httpext/request_test.go +++ b/lib/netext/httpext/request_test.go @@ -28,7 +28,7 @@ import ( type reader func([]byte) (int, error) func (r reader) Read(a []byte) (int, error) { - return ((func([]byte) (int, error))(r))(a) + return (func([]byte) (int, error))(r)(a) } const ( @@ -45,7 +45,7 @@ func badReadBody() io.Reader { type closer func() error func (c closer) Close() error { - return ((func() error)(c))() + return (func() error)(c)() } func badCloseBody() io.ReadCloser { @@ -208,8 +208,8 @@ func TestURL(t *testing.T) { {"https://example.com/", "https://example.com/"}, {"https://example.com/${}", "https://example.com/${}"}, {"https://user@example.com/", "https://****@example.com/"}, - {"https://user:pass@example.com/", "https://****:****@example.com/"}, - {"https://user:pass@example.com/path?a=1&b=2", "https://****:****@example.com/path?a=1&b=2"}, + {"https://user:pass@example.com/", "https://****:****@example.com/"}, //trufflehog:ignore + {"https://user:pass@example.com/path?a=1&b=2", "https://****:****@example.com/path?a=1&b=2"}, //trufflehog:ignore {"https://user:pass@example.com/${}/${}", "https://****:****@example.com/${}/${}"}, {"@malformed/url", "@malformed/url"}, {"not a url", "not a url"}, @@ -533,9 +533,9 @@ func TestMakeRequestFailedHostInitializesHeadersAndCookies(t *testing.T) { func TestMakeRequestRPSLimit(t *testing.T) { t.Parallel() - var requests int64 + var requests atomic.Int64 ts := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { - atomic.AddInt64(&requests, 1) + requests.Add(1) })) defer ts.Close() @@ -574,7 +574,7 @@ func TestMakeRequestRPSLimit(t *testing.T) { select { case <-timer.C: timer.Stop() - val := atomic.LoadInt64(&requests) + val := requests.Load() assert.NotEmpty(t, val) assert.InDelta(t, val, 3, 3) return diff --git a/lib/options.go b/lib/options.go index 5e9e2dad4..a2c466589 100644 --- a/lib/options.go +++ b/lib/options.go @@ -586,7 +586,7 @@ func (o Options) ForEachSpecified(structTag string, callback func(key string, va shouldCall = fieldVal.Len() > 0 case reflect.Map: shouldCall = fieldVal.Len() > 0 - case reflect.Ptr: + case reflect.Pointer: shouldCall = !fieldVal.IsNil() default: panic(fmt.Sprintf("Unknown Options field %#v", fieldType)) diff --git a/lib/options_test.go b/lib/options_test.go index 3d24e935f..00c1d6549 100644 --- a/lib/options_test.go +++ b/lib/options_test.go @@ -119,7 +119,7 @@ func TestOptions(t *testing.T) { opts := Options{}.Apply(Options{TLSCipherSuites: &TLSCipherSuites{suiteID}}) assert.NotNil(t, opts.TLSCipherSuites) - assert.Len(t, *(opts.TLSCipherSuites), 1) + assert.Len(t, *opts.TLSCipherSuites, 1) assert.Equal(t, suiteID, (*opts.TLSCipherSuites)[0]) }) } diff --git a/lib/types/trie.go b/lib/types/trie.go index 260564d01..2252e9854 100644 --- a/lib/types/trie.go +++ b/lib/types/trie.go @@ -1,6 +1,9 @@ package types -import "strings" +import ( + "slices" + "strings" +) type trieNode struct { isLeaf bool @@ -15,12 +18,12 @@ func (t *trieNode) insert(s string) { } ptr := t - for i := len(runes) - 1; i >= 0; i-- { - c, ok := ptr.children[runes[i]] + for _, rune0 := range slices.Backward(runes) { + c, ok := ptr.children[rune0] if !ok { - ptr.children[runes[i]] = &trieNode{children: map[rune]*trieNode{}} - c = ptr.children[runes[i]] + ptr.children[rune0] = &trieNode{children: map[rune]*trieNode{}} + c = ptr.children[rune0] } ptr = c @@ -36,8 +39,8 @@ func (t *trieNode) contains(s string) (string, bool) { found := true ptr := t - for i := len(rs) - 1; i >= 0; i-- { - child, ok := ptr.children[rs[i]] + for _, r := range slices.Backward(rs) { + child, ok := ptr.children[r] if _, wOk := ptr.children['*']; wOk { wMatch = builder.String() + string('*') @@ -48,7 +51,7 @@ func (t *trieNode) contains(s string) (string, bool) { break } - builder.WriteRune(rs[i]) + builder.WriteRune(r) ptr = child } diff --git a/metrics/tags.go b/metrics/tags.go index 503a826a8..f68b6b85c 100644 --- a/metrics/tags.go +++ b/metrics/tags.go @@ -34,7 +34,7 @@ type TagSet atlas.Node // If a tag with the specified name already exists in the set, it will be // overwritten with the new value in the returned set. func (ts *TagSet) With(name, value string) *TagSet { - return (*TagSet)(((*atlas.Node)(ts)).AddLink(name, value)) + return (*TagSet)((*atlas.Node)(ts).AddLink(name, value)) } // Without returns another TagSet object that contains all of the tags from the @@ -47,29 +47,29 @@ func (ts *TagSet) With(name, value string) *TagSet { // If a tag with the specified name doesn't exist in the set, it will return the // receiver. func (ts *TagSet) Without(name string) *TagSet { - return (*TagSet)(((*atlas.Node)(ts)).DeleteKey(name)) + return (*TagSet)((*atlas.Node)(ts).DeleteKey(name)) } // Get returns the value of the tag with the given name and true, if that tag // exists in the set, and an empty string and false otherwise. func (ts *TagSet) Get(name string) (string, bool) { - return ((*atlas.Node)(ts)).ValueByKey(name) + return (*atlas.Node)(ts).ValueByKey(name) } // Contains checks that each key=value tag pair in the provided TagSet exists in // the receiver tag set as well, i.e. that the given set is a sub-set of it. func (ts *TagSet) Contains(other *TagSet) bool { - return ((*atlas.Node)(ts)).Contains((*atlas.Node)(other)) + return (*atlas.Node)(ts).Contains((*atlas.Node)(other)) } // IsEmpty checks if the tag set is empty, i.e. if it's the root atlas node. func (ts *TagSet) IsEmpty() bool { - return ((*atlas.Node)(ts)).IsRoot() + return (*atlas.Node)(ts).IsRoot() } // Map returns a {key: value} string map with all of the tags in the set. func (ts *TagSet) Map() map[string]string { - return ((*atlas.Node)(ts)).Path() + return (*atlas.Node)(ts).Path() } // WithTagsFromMap sorts the given tags by their keys and adds them to the diff --git a/output/cloud/expv2/flush_test.go b/output/cloud/expv2/flush_test.go index fd7e6f87b..ccefdf849 100644 --- a/output/cloud/expv2/flush_test.go +++ b/output/cloud/expv2/flush_test.go @@ -322,11 +322,11 @@ type pusherMock struct { // errFn if this defined, it is called at the end of push // and result error is returned. errFn func() error - pushCalled int64 + pushCalled atomic.Int64 } func (pm *pusherMock) timesCalled() int { - return int(atomic.LoadInt64(&pm.pushCalled)) + return int(pm.pushCalled.Load()) } func (pm *pusherMock) push(_ context.Context, ms *pbcloud.MetricSet) error { @@ -334,7 +334,7 @@ func (pm *pusherMock) push(_ context.Context, ms *pbcloud.MetricSet) error { pm.hook(ms) } - atomic.AddInt64(&pm.pushCalled, 1) + pm.pushCalled.Add(1) if pm.errFn != nil { return pm.errFn() diff --git a/output/cloud/expv2/mapping.go b/output/cloud/expv2/mapping.go index ca76de38d..ec2047002 100644 --- a/output/cloud/expv2/mapping.go +++ b/output/cloud/expv2/mapping.go @@ -14,7 +14,7 @@ import ( // TODO: unit test func mapTimeSeriesLabelsProto(tags *metrics.TagSet) ([]*pbcloud.Label, []string) { - labels := make([]*pbcloud.Label, 0, ((*atlas.Node)(tags)).Len()) + labels := make([]*pbcloud.Label, 0, (*atlas.Node)(tags).Len()) var discardedLabels []string // TODO: move this as a shared func diff --git a/output/cloud/expv2/output_test.go b/output/cloud/expv2/output_test.go index 68b28d67e..763c2cc82 100644 --- a/output/cloud/expv2/output_test.go +++ b/output/cloud/expv2/output_test.go @@ -274,9 +274,9 @@ func TestOutputPeriodicInvoke(t *testing.T) { t.Parallel() stop := make(chan struct{}) - var called uint64 + var called atomic.Uint64 cb := func() { - updated := atomic.AddUint64(&called, 1) + updated := called.Add(1) if updated == 2 { close(stop) } @@ -284,7 +284,7 @@ func TestOutputPeriodicInvoke(t *testing.T) { o := Output{stop: stop} o.periodicInvoke(time.Duration(1), cb) // loop <-stop - assert.Greater(t, atomic.LoadUint64(&called), uint64(1)) + assert.Greater(t, called.Load(), uint64(1)) } func TestOutputStopWithTestError(t *testing.T) { @@ -315,9 +315,9 @@ func TestOutputFlushTicks(t *testing.T) { // operations continues concurrently if one more tick is sent in the meantime. // // The second request unblocks. - var requestsCount int64 + var requestsCount atomic.Int64 flusherMock := func(context.Context) { - updated := atomic.AddInt64(&requestsCount, 1) + updated := requestsCount.Add(1) if updated == 2 { close(done) return @@ -336,7 +336,7 @@ func TestOutputFlushTicks(t *testing.T) { case <-time.After(5 * time.Second): t.Error("timed out") case <-done: - assert.NotZero(t, atomic.LoadInt64(&requestsCount)) + assert.NotZero(t, requestsCount.Load()) } close(o.stop) synctest.Wait() @@ -416,9 +416,9 @@ func TestOutputFlushRequestMetadatasConcurrently(t *testing.T) { // operations continues concurrently if one more tick is sent in the meantime. // // The second request unblocks. - var requestsCount int64 + var requestsCount atomic.Int64 flusherMock := func(context.Context) { - updated := atomic.AddInt64(&requestsCount, 1) + updated := requestsCount.Add(1) if updated == 2 { close(done) return @@ -439,7 +439,7 @@ func TestOutputFlushRequestMetadatasConcurrently(t *testing.T) { case <-time.After(5 * time.Second): t.Error("timed out") case <-done: - assert.NotZero(t, atomic.LoadInt64(&requestsCount)) + assert.NotZero(t, requestsCount.Load()) } close(o.stop) synctest.Wait() diff --git a/secretsource/manager.go b/secretsource/manager.go index 360b8f834..2f5347ce9 100644 --- a/secretsource/manager.go +++ b/secretsource/manager.go @@ -79,5 +79,5 @@ func (sm *Manager) Get(sourceName, key string) (string, error) { type UnknownSourceError string func (u UnknownSourceError) Error() string { - return fmt.Sprintf("no secret source with name %q is configured", (string)(u)) + return fmt.Sprintf("no secret source with name %q is configured", string(u)) } From 92eff844af9fa464002f0997de4e24a9f43c9873 Mon Sep 17 00:00:00 2001 From: Inanc Gumus Date: Fri, 11 Sep 2026 09:26:16 -0400 Subject: [PATCH 146/182] Add `--scenario` to select scenarios in the script by name (#6360) * Move config preparation to the entry point Prepare configuration sources before merging them so execution features can operate independently at the CLI boundary. * Add standalone scenario selection Run explicitly named workloads with their configuration intact. Reject CLI load shortcuts and ignore lower-layer shortcuts with warnings so selection survives merging and archive replay. * Compose scenario selection with once Explicit selection resolves multi-scenario ambiguity while bare once keeps rejecting ambiguous workloads. * Skip thresholds for excluded scenarios Scenario selection should not fail checks for workloads it excludes. Keep shared thresholds and warn about skipped scenario filters, including the effect on samples tagged by other scenarios. * Simplify scenario selection and its tests Keep the selection contract with fewer passes and less test scaffolding. Feature coordination stays in the CLI entry point. --- internal/cmd/config.go | 42 +++--- internal/cmd/config_consolidation_test.go | 6 +- internal/cmd/once_test.go | 18 ++- internal/cmd/options.go | 4 + internal/cmd/scenarios.go | 115 ++++++++++++++++ internal/cmd/scenarios_test.go | 112 ++++++++++++++++ internal/cmd/test_load.go | 53 +++++++- internal/cmd/tests/cmd_scenarios_test.go | 151 ++++++++++++++++++++++ 8 files changed, 470 insertions(+), 31 deletions(-) create mode 100644 internal/cmd/scenarios.go create mode 100644 internal/cmd/scenarios_test.go create mode 100644 internal/cmd/tests/cmd_scenarios_test.go diff --git a/internal/cmd/config.go b/internal/cmd/config.go index c952723d9..5cd5db4f7 100644 --- a/internal/cmd/config.go +++ b/internal/cmd/config.go @@ -207,6 +207,22 @@ func readEnvConfig(envMap map[string]string) (Config, error) { return conf, err } +// readConfigLayers reads file and environment options before merging them. +func readConfigLayers(gs *state.GlobalState) (Config, Config, error) { + fileConf, err := readDiskConfig(gs) + if err != nil { + err = fmt.Errorf("failed to load the configuration file from the local file system: %w", err) + return Config{}, Config{}, errext.WithExitCodeIfNone(err, exitcodes.InvalidConfig) + } + + envConf, err := readEnvConfig(gs.Env) + if err != nil { + return Config{}, Config{}, errext.WithExitCodeIfNone(err, exitcodes.InvalidConfig) + } + + return fileConf, envConf, nil +} + // getConsolidatedConfig assemble the final consolidated configuration from all of the different sources: // - start with the CLI-provided options to get shadowed (non-Valid) defaults in there // - add the global file config options @@ -217,30 +233,8 @@ func readEnvConfig(envMap map[string]string) (Config, error) { // TODO: add better validation, more explicit default values and improve consistency between formats // TODO: accumulate all errors and differentiate between the layers? func getConsolidatedConfig( - gs *state.GlobalState, cliConf Config, runnerOpts lib.Options, flags *features.Flags, + gs *state.GlobalState, cliConf, fileConf, envConf Config, runnerOpts lib.Options, flags *features.Flags, ) (Config, error) { - fileConf, err := readDiskConfig(gs) - if err != nil { - err = fmt.Errorf("failed to load the configuration file from the local file system: %w", err) - return Config{}, errext.WithExitCodeIfNone(err, exitcodes.InvalidConfig) - } - - envConf, err := readEnvConfig(gs.Env) - if err != nil { - return Config{}, errext.WithExitCodeIfNone(err, exitcodes.InvalidConfig) - } - - // Lower layers drop their shortcuts before the merge; getOptions rejects the CLI ones. - if cliConf.once { - if err := dropOnceShortcuts(gs.Logger, map[string]*lib.Options{ - "config": &fileConf.Options, - "script": &runnerOpts, - "environment": &envConf.Options, - }); err != nil { - return Config{}, err - } - } - conf := cliConf.Apply(fileConf) warnOnShortHandOverride(conf.Options, runnerOpts, "script", gs.Logger) @@ -268,7 +262,7 @@ func getConsolidatedConfig( // for CLI flags in cmd.getOptions, in case other configuration sources // (e.g. env vars) overrode our default value. This is not done in // lib.Options.Validate to avoid circular imports. - if _, err = metrics.GetResolversForTrendColumns(conf.SummaryTrendStats); err != nil { + if _, err := metrics.GetResolversForTrendColumns(conf.SummaryTrendStats); err != nil { return Config{}, err } diff --git a/internal/cmd/config_consolidation_test.go b/internal/cmd/config_consolidation_test.go index 71274f372..6ac0daf0d 100644 --- a/internal/cmd/config_consolidation_test.go +++ b/internal/cmd/config_consolidation_test.go @@ -608,7 +608,11 @@ func runTestCase(t *testing.T, testCase configConsolidationTestCase, subCmd stri if testCase.options.runner != nil { opts = *testCase.options.runner } - consolidatedConfig, err := getConsolidatedConfig(ts.GlobalState, cliConf, opts, testCase.options.features) + var consolidatedConfig Config + fileConf, envConf, err := readConfigLayers(ts.GlobalState) + if err == nil { + consolidatedConfig, err = getConsolidatedConfig(ts.GlobalState, cliConf, fileConf, envConf, opts, testCase.options.features) + } if testCase.expected.consolidationError { require.Error(t, err) return diff --git a/internal/cmd/once_test.go b/internal/cmd/once_test.go index 46e5d95b1..3c9c0d276 100644 --- a/internal/cmd/once_test.go +++ b/internal/cmd/once_test.go @@ -144,7 +144,14 @@ func TestGetConsolidatedConfigOnceDropsLowerLayerShortcuts(t *testing.T) { ExecutionSegment: segment, } - conf, err := getConsolidatedConfig(ts.GlobalState, Config{once: true}, runnerOpts, nil) + fileConf, envConf, err := readConfigLayers(ts.GlobalState) + require.NoError(t, err) + require.NoError(t, dropOnceShortcuts(ts.Logger, map[string]*lib.Options{ + "config": &fileConf.Options, + "script": &runnerOpts, + "environment": &envConf.Options, + })) + conf, err := getConsolidatedConfig(ts.GlobalState, Config{}, fileConf, envConf, runnerOpts, nil) require.NoError(t, err) assert.False(t, conf.VUs.Valid) @@ -168,7 +175,14 @@ func TestOncePreservesScenarioAcrossLayers(t *testing.T) { runnerOpts := lib.Options{Duration: types.NullDurationFrom(time.Second)} - conf, err := getConsolidatedConfig(ts.GlobalState, Config{once: true}, runnerOpts, nil) + fileConf, envConf, err := readConfigLayers(ts.GlobalState) + require.NoError(t, err) + require.NoError(t, dropOnceShortcuts(ts.Logger, map[string]*lib.Options{ + "config": &fileConf.Options, + "script": &runnerOpts, + "environment": &envConf.Options, + })) + conf, err := getConsolidatedConfig(ts.GlobalState, Config{}, fileConf, envConf, runnerOpts, nil) require.NoError(t, err) opts, err := applyOnce(conf.Options) diff --git a/internal/cmd/options.go b/internal/cmd/options.go index cbf5d760e..c687f80cc 100644 --- a/internal/cmd/options.go +++ b/internal/cmd/options.go @@ -25,6 +25,7 @@ func optionFlagSet() *pflag.FlagSet { flags.SortFlags = false flags.Bool("once", false, "run the test with 1 VU and 1 iteration") + flags.StringSlice("scenario", nil, "run scenarios by name (comma-separated)") flags.Int64P("vus", "u", 1, "number of virtual users") flags.DurationP("duration", "d", 0, "test duration limit") flags.Int64P("iterations", "i", 0, "script total iteration limit (among all VUs)") @@ -83,6 +84,9 @@ func getOptions(flags *pflag.FlagSet) (lib.Options, error) { if err := checkOnceConflicts(flags); err != nil { return lib.Options{}, err } + if err := checkScenarioConflicts(flags); err != nil { + return lib.Options{}, err + } opts := lib.Options{ VUs: getNullInt64(flags, "vus"), diff --git a/internal/cmd/scenarios.go b/internal/cmd/scenarios.go new file mode 100644 index 000000000..b343419ef --- /dev/null +++ b/internal/cmd/scenarios.go @@ -0,0 +1,115 @@ +package cmd + +import ( + "fmt" + "maps" + "slices" + "strings" + + "github.com/sirupsen/logrus" + "github.com/spf13/pflag" + + "go.k6.io/k6/v2/errext" + "go.k6.io/k6/v2/errext/exitcodes" + "go.k6.io/k6/v2/lib" + "go.k6.io/k6/v2/metrics" +) + +func checkScenarioConflicts(flags *pflag.FlagSet) error { + if !flags.Changed("scenario") { + return nil + } + for _, name := range []string{"vus", "duration", "iterations", "stage"} { + if flags.Changed(name) { + return errext.WithExitCodeIfNone( + fmt.Errorf("--scenario cannot be combined with --%s", name), exitcodes.InvalidConfig) + } + } + return nil +} + +func dropScenarioShortcuts(logger logrus.FieldLogger, layers map[string]*lib.Options) error { + var unset lib.Options + for _, name := range []string{"config", "script", "environment"} { + opts, ok := layers[name] + if !ok { + return fmt.Errorf("missing %q layer", name) + } + + var dropped []string + if opts.VUs.Valid { + dropped = append(dropped, "vus") + } + if opts.Duration.Valid { + dropped = append(dropped, "duration") + } + if opts.Iterations.Valid { + dropped = append(dropped, "iterations") + } + if opts.Stages != nil { + dropped = append(dropped, "stages") + } + opts.VUs = unset.VUs + opts.Duration = unset.Duration + opts.Iterations = unset.Iterations + opts.Stages = unset.Stages + if len(dropped) > 0 { + logger.Warnf("--scenario overrode %s in %q configuration", strings.Join(dropped, ", "), name) + } + } + return nil +} + +func selectScenarios(opts lib.Options, names []string) (lib.Options, error) { + selected := make(lib.ScenarioConfigs, len(names)) + for _, name := range names { + if sc, ok := opts.Scenarios[name]; ok { + selected[name] = sc + continue + } + + available := strings.Join(slices.Sorted(maps.Keys(opts.Scenarios)), ", ") + err := fmt.Errorf("scenario %q not found; available scenarios: %s", name, available) + if len(opts.Scenarios) == 0 { + err = fmt.Errorf("scenario %q not found; the script does not have any named scenario", name) + } + + return opts, errext.WithExitCodeIfNone(err, exitcodes.InvalidConfig) + } + + opts.Scenarios = selected + + return opts, nil +} + +func dropScenarioThresholds(logger logrus.FieldLogger, opts *lib.Options, configured lib.ScenarioConfigs) { + opts.Thresholds = maps.Clone(opts.Thresholds) + var dropped []string + for metricName := range opts.Thresholds { + _, tags, err := metrics.ParseMetricName(metricName) + if err != nil { + // Only --no-thresholds permits malformed filters past threshold validation. + continue + } + // Match AddSubmetric's normalization and last-value-wins handling of repeated tags. + for _, tag := range slices.Backward(tags) { + key, value, _ := strings.Cut(tag, ":") + if strings.Trim(strings.TrimSpace(key), `"'`) != "scenario" { + continue + } + name := strings.Trim(strings.TrimSpace(value), `"'`) + _, exists := configured[name] + _, selected := opts.Scenarios[name] + if exists && !selected { + delete(opts.Thresholds, metricName) + dropped = append(dropped, metricName) + } + break + } + } + if len(dropped) > 0 { + slices.Sort(dropped) + logger.Warnf("--scenario skipped thresholds for excluded scenarios: %s; "+ + "these thresholds remain skipped even if another scenario emits matching tags", strings.Join(dropped, "; ")) + } +} diff --git a/internal/cmd/scenarios_test.go b/internal/cmd/scenarios_test.go new file mode 100644 index 000000000..a76f695e6 --- /dev/null +++ b/internal/cmd/scenarios_test.go @@ -0,0 +1,112 @@ +package cmd + +import ( + "maps" + "slices" + "strings" + "testing" + "time" + + "github.com/sirupsen/logrus" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "gopkg.in/guregu/null.v3" + + "go.k6.io/k6/v2/errext" + "go.k6.io/k6/v2/errext/exitcodes" + "go.k6.io/k6/v2/internal/lib/testutils" + "go.k6.io/k6/v2/lib" + "go.k6.io/k6/v2/lib/executor" + "go.k6.io/k6/v2/lib/types" + "go.k6.io/k6/v2/metrics" +) + +func TestSelectScenarios(t *testing.T) { + t.Parallel() + + ui := executor.NewConstantVUsConfig("ui") + ui.VUs = null.IntFrom(7) + ui.Duration = types.NullDurationFrom(30 * time.Second) + ui.Exec = null.StringFrom("uiFn") + ui.Env = map[string]string{"GREETING": "hi"} + ui.Tags = map[string]string{"team": "core"} + ui.Options = &lib.ScenarioOptions{Browser: map[string]any{"type": "chromium"}} + + api := executor.NewConstantVUsConfig("api") + + all := lib.ScenarioConfigs{"ui": ui, "api": api, "db": executor.NewConstantVUsConfig("db")} + + res, err := selectScenarios(lib.Options{Scenarios: all}, []string{"ui", "api"}) + require.NoError(t, err) + assert.Equal(t, lib.ScenarioConfigs{"ui": ui, "api": api}, res.Scenarios) + assert.Len(t, all, 3) + + _, err = selectScenarios(lib.Options{Scenarios: all}, []string{"ui", "gone"}) + require.EqualError(t, err, `scenario "gone" not found; available scenarios: api, db, ui`) + var ec errext.HasExitCode + require.ErrorAs(t, err, &ec) + assert.Equal(t, exitcodes.InvalidConfig, ec.ExitCode()) + + _, err = selectScenarios(lib.Options{}, []string{"default"}) + require.EqualError(t, err, `scenario "default" not found; the script does not have any named scenario`) +} + +func TestGetOptionsScenarioShortcuts(t *testing.T) { + t.Parallel() + + for _, tt := range []struct { + flag, value string + allowed bool + }{ + {"vus", "2", false}, + {"duration", "1s", false}, + {"iterations", "2", false}, + {"stage", "1s:2", false}, + {"execution-segment", "0:1/2", true}, + {"execution-segment-sequence", "0,1/2,1", true}, + } { + t.Run(tt.flag, func(t *testing.T) { + t.Parallel() + flags := optionFlagSet() + require.NoError(t, flags.Parse([]string{"--scenario", "ui", "--" + tt.flag, tt.value})) + _, err := getOptions(flags) + if tt.allowed { + require.NoError(t, err) + return + } + require.EqualError(t, err, "--scenario cannot be combined with --"+tt.flag) + var ec errext.HasExitCode + require.ErrorAs(t, err, &ec) + assert.Equal(t, exitcodes.InvalidConfig, ec.ExitCode()) + }) + } +} + +func TestDropScenarioThresholds(t *testing.T) { + t.Parallel() + + kept := []string{ + "iterations", "iterations{name:scenario:api}", "iterations{scenario:ui}", + "iterations{scenario:unknown}", "iterations{scenario:api,scenario:ui}", + "iterations{scenario:api", + } + dropped := []string{ + "iterations{ 'scenario' : 'api', name:login}", + "iterations{scenario:api}", "iterations{scenario:ui,scenario:api}", + } + thresholds := make(map[string]metrics.Thresholds) + for _, name := range slices.Concat(kept, dropped) { + thresholds[name] = metrics.NewThresholds([]string{"count>0"}) + } + opts := lib.Options{Scenarios: lib.ScenarioConfigs{"ui": nil}, Thresholds: thresholds} + logger, hook := testutils.NewLoggerWithHook(t, logrus.WarnLevel) + dropScenarioThresholds(logger, &opts, lib.ScenarioConfigs{"ui": nil, "api": nil}) + + assert.ElementsMatch(t, kept, slices.Collect(maps.Keys(opts.Thresholds))) + assert.Len(t, thresholds, len(kept)+len(dropped)) + assert.Equal(t, []string{"--scenario skipped thresholds for excluded scenarios: " + + strings.Join(dropped, "; ") + "; these thresholds remain skipped even if another scenario emits matching tags"}, hook.Lines()) + + dropScenarioThresholds(logger, &opts, opts.Scenarios) + assert.Empty(t, hook.Lines()) +} diff --git a/internal/cmd/test_load.go b/internal/cmd/test_load.go index 44a3f0d5a..8307f44f4 100644 --- a/internal/cmd/test_load.go +++ b/internal/cmd/test_load.go @@ -527,6 +527,7 @@ func detectTestType(data []byte) string { return testTypeJS } +//nolint:funlen // Keep CLI feature ordering together. func (lt *loadedTest) consolidateDeriveAndValidateConfig( gs *state.GlobalState, cmd *cobra.Command, cliConfGetter func(flags *pflag.FlagSet) (Config, error), // TODO: obviate @@ -543,17 +544,57 @@ func (lt *loadedTest) consolidateDeriveAndValidateConfig( cliConfig.once = getNullBool(cmd.Flags(), "once").Bool } + var scenarioNames []string + if cmd.Flags().Changed("scenario") { + var err error + scenarioNames, err = cmd.Flags().GetStringSlice("scenario") + if err != nil { + return nil, err + } + if len(scenarioNames) == 0 { + return nil, errext.WithExitCodeIfNone( + errors.New("--scenario requires at least one scenario name"), + exitcodes.InvalidConfig) + } + } + gs.Logger.Debug("Consolidating config layers...") + fileConf, envConf, err := readConfigLayers(gs) + if err != nil { + return nil, err + } + runnerOpts := lt.initRunner.GetOptions() + // Lower layers drop their shortcuts before the merge; getOptions rejects the CLI ones. + layers := map[string]*lib.Options{ + "config": &fileConf.Options, + "script": &runnerOpts, + "environment": &envConf.Options, + } + if cliConfig.once { + err = dropOnceShortcuts(gs.Logger, layers) + } else if scenarioNames != nil { + err = dropScenarioShortcuts(gs.Logger, layers) + } + if err != nil { + return nil, err + } consolidatedConfig, err := getConsolidatedConfig( - gs, cliConfig, lt.initRunner.GetOptions(), lt.preInitState.FeatureFlags) + gs, cliConfig, fileConf, envConf, runnerOpts, lt.preInitState.FeatureFlags) if err != nil { return nil, err } + configuredScenarios := consolidatedConfig.Scenarios + switch { + case scenarioNames != nil: + consolidatedConfig.Options, err = selectScenarios(consolidatedConfig.Options, scenarioNames) + case cliConfig.once: + err = rejectAmbiguousOnce(consolidatedConfig.Scenarios) + } + if err != nil { + return nil, err + } if cliConfig.once { - if err = rejectAmbiguousOnce(consolidatedConfig.Scenarios); err != nil { - return nil, err - } if consolidatedConfig.Options, err = applyOnce(consolidatedConfig.Options); err != nil { return nil, err } @@ -577,6 +618,10 @@ func (lt *loadedTest) consolidateDeriveAndValidateConfig( } } + if scenarioNames != nil { + dropScenarioThresholds(gs.Logger, &consolidatedConfig.Options, configuredScenarios) + } + derivedConfig, err := deriveAndValidateConfig(consolidatedConfig, lt.initRunner.IsExecutable, gs.Logger) if err != nil { return nil, err diff --git a/internal/cmd/tests/cmd_scenarios_test.go b/internal/cmd/tests/cmd_scenarios_test.go new file mode 100644 index 000000000..cca1911e5 --- /dev/null +++ b/internal/cmd/tests/cmd_scenarios_test.go @@ -0,0 +1,151 @@ +package tests + +import ( + "bytes" + "path/filepath" + "strings" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "gopkg.in/guregu/null.v3" + + "go.k6.io/k6/v2/errext/exitcodes" + "go.k6.io/k6/v2/internal/cmd" + "go.k6.io/k6/v2/lib" + "go.k6.io/k6/v2/lib/executor" + "go.k6.io/k6/v2/lib/fsext" +) + +const scenariosScript = ` + import exec from 'k6/execution'; + export const options = { + cloud: { name: 'pick', projectID: 123456 }, + vus: 1, duration: '1ms', iterations: 1, stages: [], + thresholds: { + iterations: ['count>0'], + 'iterations{scenario:api}': ['count>0'], + 'iterations{scenario:db}': ['count>0'] + }, + scenarios: { + ui: { executor: 'per-vu-iterations', vus: 2, iterations: 1 }, + api: { executor: 'shared-iterations', vus: 1, iterations: 2 }, + db: { executor: 'shared-iterations', vus: 1, iterations: 1 } + } + }; + export default function() { console.log('ran ' + exec.scenario.name); } +` + +func TestScenariosFilterArchive(t *testing.T) { + t.Parallel() + + for name, build := range map[string]func(*testing.T) []byte{ + "local archive": func(t *testing.T) []byte { + return buildArchive(t, scenariosScript, "--scenario", "ui,api") + }, + "cloud run": func(t *testing.T) []byte { + _, data := uploadAndCaptureArchive(t, + []string{"k6", "cloud", "run", "--scenario", "ui,api", "test.js"}, nil, scenariosScript) + return data + }, + } { + t.Run(name, func(t *testing.T) { + t.Parallel() + + tarData := build(t) + arc, err := lib.ReadArchive(bytes.NewReader(tarData)) + require.NoError(t, err) + + require.Len(t, arc.Options.Scenarios, 2) + assert.NotContains(t, arc.Options.Scenarios, "db") + + ui, ok := arc.Options.Scenarios["ui"].(executor.PerVUIterationsConfig) + require.True(t, ok) + assert.Equal(t, null.IntFrom(2), ui.VUs) + assert.Equal(t, null.IntFrom(1), ui.Iterations) + assert.NotContains(t, arc.Options.Thresholds, "iterations{scenario:db}") + assert.Contains(t, arc.Options.Thresholds, "iterations") + assert.Contains(t, arc.Options.Thresholds, "iterations{scenario:api}") + assert.False(t, arc.Options.VUs.Valid) + assert.False(t, arc.Options.Duration.Valid) + assert.False(t, arc.Options.Iterations.Valid) + assert.Nil(t, arc.Options.Stages) + + ts := NewGlobalTestState(t) + tarPath := filepath.Join(ts.Cwd, "archive.tar") + require.NoError(t, fsext.WriteFile(ts.FS, tarPath, tarData, 0o644)) + ts.CmdArgs = []string{"k6", "run", "--log-output=stdout", tarPath} + cmd.ExecuteWithGlobalState(ts.GlobalState) + + stdout := ts.Stdout.String() + assert.Equal(t, 2, strings.Count(stdout, "ran ui")) + assert.Equal(t, 2, strings.Count(stdout, "ran api")) + assert.NotContains(t, stdout, "ran db") + assert.NotContains(t, stdout, "ran default") + assert.NotContains(t, stdout, "--scenario skipped thresholds") + }) + } +} + +func TestRunScenarios(t *testing.T) { + t.Parallel() + + ts := getSingleFileTestState(t, scenariosScript, + []string{"--log-output=stdout", "--log-format=raw", "--scenario", "api"}, 0) + ts.Env["K6_ITERATIONS"] = "1" + cmd.ExecuteWithGlobalState(ts.GlobalState) + + stdout := ts.Stdout.String() + assert.Equal(t, 2, strings.Count(stdout, "ran api")) + assert.NotContains(t, stdout, "ran ui") + assert.NotContains(t, stdout, "ran db") + assert.NotContains(t, stdout, "ran default") + assert.Contains(t, stdout, `--scenario overrode vus, duration, iterations, stages in "script" configuration`) + assert.Contains(t, stdout, `--scenario overrode iterations in "environment" configuration`) + assert.Contains(t, stdout, "--scenario skipped thresholds for excluded scenarios: iterations{scenario:db}; "+ + "these thresholds remain skipped even if another scenario emits matching tags") + assert.Equal(t, 1, strings.Count(stdout, "--scenario skipped thresholds")) +} + +func TestScenarioThresholdValidation(t *testing.T) { + t.Parallel() + + script := strings.Replace(scenariosScript, + "'iterations{scenario:db}': ['count>0']", "'iterations{scenario:db}': ['invalid']", 1) + for noThresholds, exitCode := range map[string]exitcodes.ExitCode{ + "false": exitcodes.InvalidConfig, + "true": 0, + } { + t.Run(noThresholds, func(t *testing.T) { + t.Parallel() + ts := getSingleFileTestState(t, script, + []string{"--scenario", "api", "--no-thresholds=" + noThresholds}, exitCode) + cmd.ExecuteWithGlobalState(ts.GlobalState) + }) + } +} + +func TestRunScenariosOnce(t *testing.T) { + t.Parallel() + + ts := getSingleFileTestState(t, scenariosScript, + []string{"--log-output=stdout", "--scenario", "ui,api", "--once"}, 0) + cmd.ExecuteWithGlobalState(ts.GlobalState) + + stdout := ts.Stdout.String() + assert.Equal(t, 1, strings.Count(stdout, "ran ui")) + assert.Equal(t, 1, strings.Count(stdout, "ran api")) + assert.NotContains(t, stdout, "ran db") +} + +func TestRunRejectsEmptyScenarios(t *testing.T) { + t.Parallel() + + ts := getSingleFileTestState(t, scenariosScript, + []string{"--log-output=stdout", "--scenario="}, exitcodes.InvalidConfig) + cmd.ExecuteWithGlobalState(ts.GlobalState) + + stdout := ts.Stdout.String() + assert.Contains(t, stdout, "requires at least one scenario name") + assert.NotContains(t, stdout, "ran ") +} From c204bdf41a61eefaf4f4ce2ef80313a95de670de Mon Sep 17 00:00:00 2001 From: Mihail Stoykov <312246+mstoykov@users.noreply.github.com> Date: Fri, 11 Sep 2026 16:29:16 +0300 Subject: [PATCH 147/182] Update Sobek and TC39 coverage (#6382) --- go.mod | 4 +- go.sum | 8 +- ...breaking_test_errors-stripTypes=false.json | 37 +- .../breaking_test_errors-stripTypes=true.json | 37 +- internal/js/tc39/tc39_test.go | 11 +- .../github.com/dlclark/regexp2/v2/decode.go | 167 ++++++ .../dlclark/regexp2/v2/helpers/ascii.go | 75 +++ .../dlclark/regexp2/v2/helpers/indexof.go | 156 +++-- .../regexp2/v2/helpers/searchvalues.go | 65 ++- vendor/github.com/dlclark/regexp2/v2/match.go | 123 ++-- .../github.com/dlclark/regexp2/v2/regexp.go | 174 +++--- .../dlclark/regexp2/v2/regexp_codegen.go | 13 + .../github.com/dlclark/regexp2/v2/replace.go | 114 ++-- .../github.com/dlclark/regexp2/v2/runner.go | 159 +++--- vendor/github.com/dlclark/regexp2/v2/split.go | 73 ++- .../dlclark/regexp2/v2/stringprefixfilter.go | 36 +- .../dlclark/regexp2/v2/syntax/charclass.go | 11 +- .../dlclark/regexp2/v2/syntax/code.go | 38 +- .../dlclark/regexp2/v2/syntax/grapheme.go | 294 ++++++++++ .../regexp2/v2/syntax/optimizations.go | 55 +- .../dlclark/regexp2/v2/syntax/parser.go | 181 +++++- .../dlclark/regexp2/v2/syntax/prefix.go | 3 + .../regexp2/v2/syntax/prefixanalyzer.go | 52 +- .../dlclark/regexp2/v2/syntax/tree.go | 114 +++- .../regexp2/v2/syntax/unicode_alias_tables.go | 536 ++++++++++++++++++ .../dlclark/regexp2/v2/syntax/writer.go | 183 +++++- .../grafana/sobek/.tc39_test262_checkout.sh | 1 + vendor/github.com/grafana/sobek/base64.go | 369 ++++++++++++ .../github.com/grafana/sobek/builtin_array.go | 4 +- .../github.com/grafana/sobek/builtin_error.go | 25 +- .../github.com/grafana/sobek/builtin_json.go | 50 ++ .../grafana/sobek/builtin_promise.go | 8 +- .../grafana/sobek/builtin_regexp.go | 4 +- .../github.com/grafana/sobek/builtin_set.go | 342 ++++++++++- .../grafana/sobek/builtin_typedarrays.go | 284 +++++++++- .../grafana/sobek/builtin_weakmap.go | 30 +- .../grafana/sobek/builtin_weakset.go | 4 +- vendor/github.com/grafana/sobek/ftoa/ftoa.go | 2 +- vendor/github.com/grafana/sobek/map.go | 6 + vendor/github.com/grafana/sobek/object.go | 12 +- .../github.com/grafana/sobek/parser/regexp.go | 52 +- .../grafana/sobek/parser/statement.go | 3 +- vendor/github.com/grafana/sobek/runtime.go | 10 +- vendor/github.com/grafana/sobek/value.go | 2 +- vendor/modules.txt | 4 +- 45 files changed, 3343 insertions(+), 588 deletions(-) create mode 100644 vendor/github.com/dlclark/regexp2/v2/decode.go create mode 100644 vendor/github.com/dlclark/regexp2/v2/helpers/ascii.go create mode 100644 vendor/github.com/dlclark/regexp2/v2/syntax/grapheme.go create mode 100644 vendor/github.com/grafana/sobek/base64.go diff --git a/go.mod b/go.mod index 20a3d02cc..6d075f5cc 100644 --- a/go.mod +++ b/go.mod @@ -20,7 +20,7 @@ require ( github.com/gorilla/websocket v1.5.3 github.com/grafana/k6-cloud-openapi-client-go v0.0.3-0.20260716125012-97c96146fa7c github.com/grafana/k6provider v0.5.0 - github.com/grafana/sobek v0.0.0-20260727154728-7781506a890f + github.com/grafana/sobek v0.0.0-20260908083152-4698bc773ae7 github.com/grafana/sobek-webapi-encoding v0.1.0 github.com/grafana/xk6-dashboard-assets v0.1.2 github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 @@ -74,7 +74,7 @@ require ( github.com/cenkalti/backoff/v5 v5.0.3 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/chromedp/sysutil v1.1.0 // indirect - github.com/dlclark/regexp2/v2 v2.5.2 // indirect + github.com/dlclark/regexp2/v2 v2.7.2 // indirect github.com/go-logr/logr v1.4.4 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/google/pprof v0.0.0-20260115054156-294ebfa9ad83 // indirect diff --git a/go.sum b/go.sum index 8be40d955..e87ba6aaa 100644 --- a/go.sum +++ b/go.sum @@ -35,8 +35,8 @@ github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGX github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dlclark/regexp2/v2 v2.5.2 h1:HAsucWRhsqcDzl6Ua9aR8JwYOTzrZyPrF0/FNxJVAI0= -github.com/dlclark/regexp2/v2 v2.5.2/go.mod h1:avUrQvPaLz2DrFNHJF0taWAFFX2C1GMSSoeiqFjcBmU= +github.com/dlclark/regexp2/v2 v2.7.2 h1:nBhTfGMNPCDloto6XZRFJ5wpi+lym2eUMHRBY0diX30= +github.com/dlclark/regexp2/v2 v2.7.2/go.mod h1:avUrQvPaLz2DrFNHJF0taWAFFX2C1GMSSoeiqFjcBmU= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= @@ -95,8 +95,8 @@ github.com/grafana/k6-cloud-openapi-client-go v0.0.3-0.20260716125012-97c96146fa github.com/grafana/k6-cloud-openapi-client-go v0.0.3-0.20260716125012-97c96146fa7c/go.mod h1:RhZGBq6e90zSi0EME83c6S1qkOzD8pP0MNETqieWX0k= github.com/grafana/k6provider v0.5.0 h1:SwItWPOMQHfRytezQBKpeXLxjNmcyD/x9PTA28pEbwg= github.com/grafana/k6provider v0.5.0/go.mod h1:R9WKthnwk96E47m6w/mnC13hhBYTn5iMdP5caFt/t5k= -github.com/grafana/sobek v0.0.0-20260727154728-7781506a890f h1:YNPYRCa0yVIPtLYrzNzsfObrRZJQDupuGL3zW3SWn0M= -github.com/grafana/sobek v0.0.0-20260727154728-7781506a890f/go.mod h1:Sza3zAy+gfXCTtzbPuijuT5odA6N3lQxMTVpCP8sC/4= +github.com/grafana/sobek v0.0.0-20260908083152-4698bc773ae7 h1:f26plQRDZSSPpQe7XgbFaFQQpGk8aplm7FFTXia+n+s= +github.com/grafana/sobek v0.0.0-20260908083152-4698bc773ae7/go.mod h1:+udxaTNa4JhADyCEyHjZDviHJyW8M9u7BX33b9zeskc= github.com/grafana/sobek-webapi-encoding v0.1.0 h1:2qf2pUiI6j33vl2etSE0Id4mfSQ4Jfa0VVfUuSccAkI= github.com/grafana/sobek-webapi-encoding v0.1.0/go.mod h1:IegnWm83cyZ8qTnfL6Rivmx7dpMVE+w3CblopwfL/go= github.com/grafana/xk6-dashboard-assets v0.1.2 h1:n2wqytPICn2ZYsKa9HE6GlvFXk+WjByMfT4eM+ms3gE= diff --git a/internal/js/tc39/breaking_test_errors-stripTypes=false.json b/internal/js/tc39/breaking_test_errors-stripTypes=false.json index f0d8bf770..7348d9288 100644 --- a/internal/js/tc39/breaking_test_errors-stripTypes=false.json +++ b/internal/js/tc39/breaking_test_errors-stripTypes=false.json @@ -9,8 +9,6 @@ "test/annexB/built-ins/RegExp/RegExp-leading-escape-BMP.js-strict:true": "test/annexB/built-ins/RegExp/RegExp-leading-escape-BMP.js: Test262Error: Code unit: d800 Expected SameValue(«\"\\\\\\\\\\\\ud800\"», «\"\\\\\\ud800\"») to be true ", "test/annexB/built-ins/RegExp/RegExp-trailing-escape-BMP.js-strict:true": "test/annexB/built-ins/RegExp/RegExp-trailing-escape-BMP.js: Test262Error: Code unit: d800 Expected SameValue(«\"a\\\\\\\\\\\\ud800\"», «\"a\\\\\\ud800\"») to be true ", "test/annexB/built-ins/RegExp/prototype/compile/pattern-string-invalid-u.js-strict:true": "test/annexB/built-ins/RegExp/prototype/compile/pattern-string-invalid-u.js: Test262Error: invalid pattern: { Expected a SyntaxError to be thrown but no exception was thrown at all ", - "test/built-ins/AggregateError/errors-iterabletolist.js-strict:true": "test/built-ins/AggregateError/errors-iterabletolist.js: Test262Error: GetMethod(obj, @@iterator) returns undefined Expected a TypeError to be thrown but no exception was thrown at all ", - "test/built-ins/Array/prototype/flat/non-numeric-depth-should-not-throw.js-strict:true": "test/built-ins/Array/prototype/flat/non-numeric-depth-should-not-throw.js: Test262Error: Actual [1, 2] and expected [1, 2] should have the same contents. a.flat(undefined) uses default depth of 1 ", "test/built-ins/AsyncFunction/AsyncFunction-is-subclass.js-strict:true": "test/built-ins/AsyncFunction/AsyncFunction-is-subclass.js: Test262Error: Prototype of constructor is Function Expected SameValue(«function () { [native code] }», «function Function() { [native code] }») to be true ", "test/built-ins/DataView/prototype/setBigInt64/immutable-buffer.js-strict:true": "test/built-ins/DataView/prototype/setBigInt64/immutable-buffer.js: TypeError: Object has no member 'transferToImmutable' ", "test/built-ins/DataView/prototype/setBigUint64/immutable-buffer.js-strict:true": "test/built-ins/DataView/prototype/setBigUint64/immutable-buffer.js: TypeError: Object has no member 'transferToImmutable' ", @@ -24,17 +22,6 @@ "test/built-ins/DataView/prototype/setUint32/immutable-buffer.js-strict:true": "test/built-ins/DataView/prototype/setUint32/immutable-buffer.js: TypeError: Object has no member 'transferToImmutable' ", "test/built-ins/DataView/prototype/setUint8/immutable-buffer.js-strict:true": "test/built-ins/DataView/prototype/setUint8/immutable-buffer.js: TypeError: Object has no member 'transferToImmutable' ", "test/built-ins/Date/UTC/fp-evaluation-order.js-strict:true": "test/built-ins/Date/UTC/fp-evaluation-order.js: Test262Error: order of operations / precision in MakeTime Expected SameValue(«29256», «29312») to be true ", - "test/built-ins/Error/error-message-tostring-symbol.js-strict:true": "test/built-ins/Error/error-message-tostring-symbol.js: Test262Error: If _message_ is a Symbol, Error must throw TypeError Expected a TypeError to be thrown but no exception was thrown at all ", - "test/built-ins/Error/isError/bigints.js-strict:true": "test/built-ins/Error/isError/bigints.js: TypeError: Object has no member 'isError' ", - "test/built-ins/Error/isError/error-subclass.js-strict:true": "test/built-ins/Error/isError/error-subclass.js: TypeError: Object has no member 'isError' ", - "test/built-ins/Error/isError/errors.js-strict:true": "test/built-ins/Error/isError/errors.js: TypeError: Object has no member 'isError' ", - "test/built-ins/Error/isError/fake-errors.js-strict:true": "test/built-ins/Error/isError/fake-errors.js: TypeError: Object has no member 'isError' ", - "test/built-ins/Error/isError/is-a-constructor.js-strict:true": "test/built-ins/Error/isError/is-a-constructor.js: Test262Error: isConstructor invoked with a non-function value ", - "test/built-ins/Error/isError/name.js-strict:true": "test/built-ins/Error/isError/name.js: TypeError: Cannot read property 'name' of undefined ", - "test/built-ins/Error/isError/non-error-objects.js-strict:true": "test/built-ins/Error/isError/non-error-objects.js: TypeError: Object has no member 'isError' ", - "test/built-ins/Error/isError/primitives.js-strict:true": "test/built-ins/Error/isError/primitives.js: TypeError: Object has no member 'isError' ", - "test/built-ins/Error/isError/prop-desc.js-strict:true": "test/built-ins/Error/isError/prop-desc.js: Test262Error: obj should have an own property isError ", - "test/built-ins/Error/isError/symbols.js-strict:true": "test/built-ins/Error/isError/symbols.js: TypeError: Object has no member 'isError' ", "test/built-ins/Function/internals/Construct/base-ctor-revoked-proxy.js-strict:true": "test/built-ins/Function/internals/Construct/base-ctor-revoked-proxy.js: Test262Error: Expected a TypeError to be thrown but no exception was thrown at all ", "test/built-ins/Iterator/concat/arguments-checked-in-order.js-strict:true": "test/built-ins/Iterator/concat/arguments-checked-in-order.js: Test262Error: Expected a TypeError but got a ReferenceError ", "test/built-ins/Iterator/concat/fresh-iterator-result.js-strict:true": "test/built-ins/Iterator/concat/fresh-iterator-result.js: ReferenceError: Iterator is not defined ", @@ -146,27 +133,12 @@ "test/built-ins/Iterator/zipKeyed/suspended-start-iterator-close-calls-return.js-strict:true": "test/built-ins/Iterator/zipKeyed/suspended-start-iterator-close-calls-return.js: ReferenceError: Iterator is not defined ", "test/built-ins/Iterator/zipKeyed/suspended-yield-iterator-close-calls-next.js-strict:true": "test/built-ins/Iterator/zipKeyed/suspended-yield-iterator-close-calls-next.js: ReferenceError: Iterator is not defined ", "test/built-ins/Iterator/zipKeyed/suspended-yield-iterator-close-calls-return.js-strict:true": "test/built-ins/Iterator/zipKeyed/suspended-yield-iterator-close-calls-return.js: ReferenceError: Iterator is not defined ", - "test/built-ins/JSON/isRawJSON/basic.js-strict:true": "test/built-ins/JSON/isRawJSON/basic.js: TypeError: Object has no member 'isRawJSON' ", - "test/built-ins/JSON/isRawJSON/builtin.js-strict:true": "test/built-ins/JSON/isRawJSON/builtin.js: Test262Error: JSON.isRawJSON is extensible ", - "test/built-ins/JSON/isRawJSON/length.js-strict:true": "test/built-ins/JSON/isRawJSON/length.js: TypeError: Cannot convert undefined or null to object ", - "test/built-ins/JSON/isRawJSON/name.js-strict:true": "test/built-ins/JSON/isRawJSON/name.js: TypeError: Cannot convert undefined or null to object ", - "test/built-ins/JSON/isRawJSON/not-a-constructor.js-strict:true": "test/built-ins/JSON/isRawJSON/not-a-constructor.js: Test262Error: isConstructor invoked with a non-function value ", - "test/built-ins/JSON/isRawJSON/prop-desc.js-strict:true": "test/built-ins/JSON/isRawJSON/prop-desc.js: Test262Error: obj should have an own property isRawJSON ", "test/built-ins/JSON/parse/reviver-call-args-after-forward-modification.js-strict:true": "test/built-ins/JSON/parse/reviver-call-args-after-forward-modification.js: TypeError: Value is not object coercible ", "test/built-ins/JSON/parse/reviver-context-source-array-literal.js-strict:true": "test/built-ins/JSON/parse/reviver-context-source-array-literal.js: Test262Error: context should be an object Expected SameValue(«\"undefined\"», «\"object\"») to be true ", "test/built-ins/JSON/parse/reviver-context-source-object-literal.js-strict:true": "test/built-ins/JSON/parse/reviver-context-source-object-literal.js: Test262Error: context should be an object Expected SameValue(«\"undefined\"», «\"object\"») to be true ", "test/built-ins/JSON/parse/reviver-context-source-primitive-literal.js-strict:true": "test/built-ins/JSON/parse/reviver-context-source-primitive-literal.js: Test262Error: context should be an object Expected SameValue(«\"undefined\"», «\"object\"») to be true ", "test/built-ins/JSON/parse/reviver-forward-modifies-object.js-strict:true": "test/built-ins/JSON/parse/reviver-forward-modifies-object.js: TypeError: Value is not object coercible ", - "test/built-ins/JSON/rawJSON/basic.js-strict:true": "test/built-ins/JSON/rawJSON/basic.js: TypeError: Object has no member 'rawJSON' ", "test/built-ins/JSON/rawJSON/bigint-raw-json-can-be-stringified.js-strict:true": "test/built-ins/JSON/rawJSON/bigint-raw-json-can-be-stringified.js: TypeError: Value is not object coercible ", - "test/built-ins/JSON/rawJSON/builtin.js-strict:true": "test/built-ins/JSON/rawJSON/builtin.js: Test262Error: JSON.rawJSON is extensible ", - "test/built-ins/JSON/rawJSON/illegal-empty-and-start-end-chars.js-strict:true": "test/built-ins/JSON/rawJSON/illegal-empty-and-start-end-chars.js: Test262Error: Expected a SyntaxError but got a TypeError ", - "test/built-ins/JSON/rawJSON/invalid-JSON-text.js-strict:true": "test/built-ins/JSON/rawJSON/invalid-JSON-text.js: Test262Error: Expected a SyntaxError but got a TypeError ", - "test/built-ins/JSON/rawJSON/length.js-strict:true": "test/built-ins/JSON/rawJSON/length.js: TypeError: Cannot convert undefined or null to object ", - "test/built-ins/JSON/rawJSON/name.js-strict:true": "test/built-ins/JSON/rawJSON/name.js: TypeError: Cannot convert undefined or null to object ", - "test/built-ins/JSON/rawJSON/not-a-constructor.js-strict:true": "test/built-ins/JSON/rawJSON/not-a-constructor.js: Test262Error: isConstructor invoked with a non-function value ", - "test/built-ins/JSON/rawJSON/prop-desc.js-strict:true": "test/built-ins/JSON/rawJSON/prop-desc.js: Test262Error: obj should have an own property rawJSON ", - "test/built-ins/JSON/rawJSON/returns-expected-object.js-strict:true": "test/built-ins/JSON/rawJSON/returns-expected-object.js: TypeError: Object has no member 'rawJSON' ", "test/built-ins/Map/prototype/getOrInsert/append-new-values-normalizes-zero-key.js-strict:true": "test/built-ins/Map/prototype/getOrInsert/append-new-values-normalizes-zero-key.js: TypeError: Object has no member 'getOrInsert' ", "test/built-ins/Map/prototype/getOrInsert/append-new-values.js-strict:true": "test/built-ins/Map/prototype/getOrInsert/append-new-values.js: TypeError: Object has no member 'getOrInsert' ", "test/built-ins/Map/prototype/getOrInsert/append-value-if-key-is-not-present-different-key-types.js-strict:true": "test/built-ins/Map/prototype/getOrInsert/append-value-if-key-is-not-present-different-key-types.js: TypeError: Object has no member 'getOrInsert' ", @@ -192,9 +164,6 @@ "test/built-ins/Map/prototype/getOrInsertComputed/returns-value-if-key-is-not-present-different-key-types.js-strict:true": "test/built-ins/Map/prototype/getOrInsertComputed/returns-value-if-key-is-not-present-different-key-types.js: TypeError: Object has no member 'getOrInsertComputed' ", "test/built-ins/Map/prototype/getOrInsertComputed/returns-value-if-key-is-present-different-key-types.js-strict:true": "test/built-ins/Map/prototype/getOrInsertComputed/returns-value-if-key-is-present-different-key-types.js: TypeError: Object has no member 'getOrInsertComputed' ", "test/built-ins/Map/prototype/getOrInsertComputed/returns-value-normalized-zero-key.js-strict:true": "test/built-ins/Map/prototype/getOrInsertComputed/returns-value-normalized-zero-key.js: TypeError: Object has no member 'getOrInsertComputed' ", - "test/built-ins/NativeErrors/nativeerror-tostring-message-throws-symbol.js-strict:true": "test/built-ins/NativeErrors/nativeerror-tostring-message-throws-symbol.js: Test262Error: If _message_ is a Symbol, EvalError should throw a TypeError Expected a TypeError to be thrown but no exception was thrown at all ", - "test/built-ins/Object/prototype/setPrototypeOf-with-non-circular-values-__proto__.js-strict:true": "test/built-ins/Object/prototype/setPrototypeOf-with-non-circular-values-__proto__.js: Test262Error: Object.setPrototypeOf(ObjProto, { __proto__: null }) throws a TypeError Expected a TypeError to be thrown but no exception was thrown at all ", - "test/built-ins/Object/prototype/setPrototypeOf-with-non-circular-values.js-strict:true": "test/built-ins/Object/prototype/setPrototypeOf-with-non-circular-values.js: Test262Error: Object.setPrototypeOf(ObjProto, Object.create(null)) throws a TypeError Expected a TypeError to be thrown but no exception was thrown at all ", "test/built-ins/RegExp/CharacterClassEscapes/character-class-digit-class-escape-negative-cases.js-strict:true": "test/built-ins/RegExp/CharacterClassEscapes/character-class-digit-class-escape-negative-cases.js: SyntaxError: Invalid flags supplied to RegExp constructor 'v' ", "test/built-ins/RegExp/CharacterClassEscapes/character-class-digit-class-escape-positive-cases.js-strict:true": "test/built-ins/RegExp/CharacterClassEscapes/character-class-digit-class-escape-positive-cases.js: SyntaxError: Invalid flags supplied to RegExp constructor 'v' ", "test/built-ins/RegExp/CharacterClassEscapes/character-class-non-digit-class-escape-negative-cases.js-strict:true": "test/built-ins/RegExp/CharacterClassEscapes/character-class-non-digit-class-escape-negative-cases.js: SyntaxError: Invalid flags supplied to RegExp constructor 'v' ", @@ -208,6 +177,7 @@ "test/built-ins/RegExp/CharacterClassEscapes/character-class-word-class-escape-negative-cases.js-strict:true": "test/built-ins/RegExp/CharacterClassEscapes/character-class-word-class-escape-negative-cases.js: SyntaxError: Invalid flags supplied to RegExp constructor 'v' ", "test/built-ins/RegExp/CharacterClassEscapes/character-class-word-class-escape-positive-cases.js-strict:true": "test/built-ins/RegExp/CharacterClassEscapes/character-class-word-class-escape-positive-cases.js: SyntaxError: Invalid flags supplied to RegExp constructor 'v' ", "test/built-ins/RegExp/lookahead-quantifier-match-groups.js-strict:true": "test/built-ins/RegExp/lookahead-quantifier-match-groups.js: Test262Error: Actual [a, abc] and expected [a, undefined] should have the same contents. ? quantifier ", + "test/built-ins/RegExp/named-groups/non-unicode-property-names-valid.js-strict:true": "test/built-ins/RegExp/named-groups/non-unicode-property-names-valid.js: SyntaxError: Invalid regular expression (regexp2): (?<\\ud835\\udc53\\ud835\\udc5c\\ud835\\udc65>fox).*(?<\\ud835\\udcd3\\ud835\\udcf8\\ud835\\udcf0>dog) (Invalid regular expression (regexp2): (?<\\ud835\\udc53\\ud835\\udc5c\\ud835\\udc65>fox).*(?<\\ud835\\udcd3\\ud835\\udcf8\\ud835\\udcf0>dog) (error parsing regexp: invalid capture group name in `(?<\\ud835\\udc53\\ud835\\udc5c\\ud835\\udc65>fox).*(?<\\ud835\\udcd3\\ud835\\udcf8\\ud835\\udcf0>dog)`)) ", "test/built-ins/RegExp/nullable-quantifier.js-strict:true": "test/built-ins/RegExp/nullable-quantifier.js: Test262Error: The regex is expected to match the whole string Expected SameValue(«\"a\"», «\"ab\"») to be true ", "test/built-ins/RegExp/quantifier-integer-limit.js-strict:true": "test/built-ins/RegExp/quantifier-integer-limit.js: SyntaxError: Invalid regular expression (regexp2): b{9007199254740991} (Invalid regular expression (regexp2): b{9007199254740991} (error parsing regexp: capture group number out of range in `b{9007199254740991}`)) ", "test/built-ins/RegExp/unicode_full_case_folding.js-strict:true": "test/built-ins/RegExp/unicode_full_case_folding.js: Test262Error: \\u0390 does not match \\u1fd3 ", @@ -359,6 +329,11 @@ "test/language/literals/regexp/invalid-optional-negative-lookbehind.js-strict:true": "test/language/literals/regexp/invalid-optional-negative-lookbehind.js: error is not an object (Test262: This statement should not be evaluated.)", "test/language/literals/regexp/invalid-range-lookbehind.js-strict:true": "test/language/literals/regexp/invalid-range-lookbehind.js: error is not an object (Test262: This statement should not be evaluated.)", "test/language/literals/regexp/invalid-range-negative-lookbehind.js-strict:true": "test/language/literals/regexp/invalid-range-negative-lookbehind.js: error is not an object (Test262: This statement should not be evaluated.)", + "test/language/literals/regexp/named-groups/invalid-duplicate-groupspecifier-2-u.js-strict:true": "test/language/literals/regexp/named-groups/invalid-duplicate-groupspecifier-2-u.js: error is not an object (Test262: This statement should not be evaluated.)", + "test/language/literals/regexp/named-groups/invalid-duplicate-groupspecifier-2.js-strict:true": "test/language/literals/regexp/named-groups/invalid-duplicate-groupspecifier-2.js: error is not an object (Test262: This statement should not be evaluated.)", + "test/language/literals/regexp/named-groups/invalid-duplicate-groupspecifier-u.js-strict:true": "test/language/literals/regexp/named-groups/invalid-duplicate-groupspecifier-u.js: error is not an object (Test262: This statement should not be evaluated.)", + "test/language/literals/regexp/named-groups/invalid-duplicate-groupspecifier.js-strict:true": "test/language/literals/regexp/named-groups/invalid-duplicate-groupspecifier.js: error is not an object (Test262: This statement should not be evaluated.)", + "test/language/literals/regexp/named-groups/invalid-identity-escape-in-capture-u.js-strict:true": "test/language/literals/regexp/named-groups/invalid-identity-escape-in-capture-u.js: error is not an object (Test262: This statement should not be evaluated.)", "test/language/literals/regexp/u-case-mapping.js-strict:true": "test/language/literals/regexp/u-case-mapping.js: Test262Error: Case mapping is not applied in the absence of the `u` flag Expected SameValue(«true», «false») to be true ", "test/language/literals/regexp/u-invalid-class-escape.js-strict:true": "test/language/literals/regexp/u-invalid-class-escape.js: error is not an object (Test262: This statement should not be evaluated.)", "test/language/literals/regexp/u-invalid-extended-pattern-char.js-strict:true": "test/language/literals/regexp/u-invalid-extended-pattern-char.js: error is not an object (Test262: This statement should not be evaluated.)", diff --git a/internal/js/tc39/breaking_test_errors-stripTypes=true.json b/internal/js/tc39/breaking_test_errors-stripTypes=true.json index e9e133ec7..d521509d4 100644 --- a/internal/js/tc39/breaking_test_errors-stripTypes=true.json +++ b/internal/js/tc39/breaking_test_errors-stripTypes=true.json @@ -9,8 +9,6 @@ "test/annexB/built-ins/RegExp/RegExp-leading-escape-BMP.js-strict:true": "test/annexB/built-ins/RegExp/RegExp-leading-escape-BMP.js: Test262Error: Code unit: d800 Expected SameValue(«\"\\\\\\\\\\\\ud800\"», «\"\\\\\\ud800\"») to be true ", "test/annexB/built-ins/RegExp/RegExp-trailing-escape-BMP.js-strict:true": "test/annexB/built-ins/RegExp/RegExp-trailing-escape-BMP.js: Test262Error: Code unit: d800 Expected SameValue(«\"a\\\\\\\\\\\\ud800\"», «\"a\\\\\\ud800\"») to be true ", "test/annexB/built-ins/RegExp/prototype/compile/pattern-string-invalid-u.js-strict:true": "test/annexB/built-ins/RegExp/prototype/compile/pattern-string-invalid-u.js: Test262Error: invalid pattern: { Expected a SyntaxError to be thrown but no exception was thrown at all ", - "test/built-ins/AggregateError/errors-iterabletolist.js-strict:true": "test/built-ins/AggregateError/errors-iterabletolist.js: Test262Error: GetMethod(obj, @@iterator) returns undefined Expected a TypeError to be thrown but no exception was thrown at all ", - "test/built-ins/Array/prototype/flat/non-numeric-depth-should-not-throw.js-strict:true": "test/built-ins/Array/prototype/flat/non-numeric-depth-should-not-throw.js: Test262Error: Actual [1, 2] and expected [1, 2] should have the same contents. a.flat(undefined) uses default depth of 1 ", "test/built-ins/AsyncFunction/AsyncFunction-is-subclass.js-strict:true": "test/built-ins/AsyncFunction/AsyncFunction-is-subclass.js: Test262Error: Prototype of constructor is Function Expected SameValue(«function () { [native code] }», «function Function() { [native code] }») to be true ", "test/built-ins/DataView/prototype/setBigInt64/immutable-buffer.js-strict:true": "test/built-ins/DataView/prototype/setBigInt64/immutable-buffer.js: TypeError: Object has no member 'transferToImmutable' ", "test/built-ins/DataView/prototype/setBigUint64/immutable-buffer.js-strict:true": "test/built-ins/DataView/prototype/setBigUint64/immutable-buffer.js: TypeError: Object has no member 'transferToImmutable' ", @@ -24,17 +22,6 @@ "test/built-ins/DataView/prototype/setUint32/immutable-buffer.js-strict:true": "test/built-ins/DataView/prototype/setUint32/immutable-buffer.js: TypeError: Object has no member 'transferToImmutable' ", "test/built-ins/DataView/prototype/setUint8/immutable-buffer.js-strict:true": "test/built-ins/DataView/prototype/setUint8/immutable-buffer.js: TypeError: Object has no member 'transferToImmutable' ", "test/built-ins/Date/UTC/fp-evaluation-order.js-strict:true": "test/built-ins/Date/UTC/fp-evaluation-order.js: Test262Error: order of operations / precision in MakeTime Expected SameValue(«29256», «29312») to be true ", - "test/built-ins/Error/error-message-tostring-symbol.js-strict:true": "test/built-ins/Error/error-message-tostring-symbol.js: Test262Error: If _message_ is a Symbol, Error must throw TypeError Expected a TypeError to be thrown but no exception was thrown at all ", - "test/built-ins/Error/isError/bigints.js-strict:true": "test/built-ins/Error/isError/bigints.js: TypeError: Object has no member 'isError' ", - "test/built-ins/Error/isError/error-subclass.js-strict:true": "test/built-ins/Error/isError/error-subclass.js: TypeError: Object has no member 'isError' ", - "test/built-ins/Error/isError/errors.js-strict:true": "test/built-ins/Error/isError/errors.js: TypeError: Object has no member 'isError' ", - "test/built-ins/Error/isError/fake-errors.js-strict:true": "test/built-ins/Error/isError/fake-errors.js: TypeError: Object has no member 'isError' ", - "test/built-ins/Error/isError/is-a-constructor.js-strict:true": "test/built-ins/Error/isError/is-a-constructor.js: Test262Error: isConstructor invoked with a non-function value ", - "test/built-ins/Error/isError/name.js-strict:true": "test/built-ins/Error/isError/name.js: TypeError: Cannot read property 'name' of undefined ", - "test/built-ins/Error/isError/non-error-objects.js-strict:true": "test/built-ins/Error/isError/non-error-objects.js: TypeError: Object has no member 'isError' ", - "test/built-ins/Error/isError/primitives.js-strict:true": "test/built-ins/Error/isError/primitives.js: TypeError: Object has no member 'isError' ", - "test/built-ins/Error/isError/prop-desc.js-strict:true": "test/built-ins/Error/isError/prop-desc.js: Test262Error: obj should have an own property isError ", - "test/built-ins/Error/isError/symbols.js-strict:true": "test/built-ins/Error/isError/symbols.js: TypeError: Object has no member 'isError' ", "test/built-ins/Function/internals/Construct/base-ctor-revoked-proxy.js-strict:true": "test/built-ins/Function/internals/Construct/base-ctor-revoked-proxy.js: Test262Error: Expected a TypeError to be thrown but no exception was thrown at all ", "test/built-ins/Iterator/concat/arguments-checked-in-order.js-strict:true": "test/built-ins/Iterator/concat/arguments-checked-in-order.js: Test262Error: Expected a TypeError but got a ReferenceError ", "test/built-ins/Iterator/concat/fresh-iterator-result.js-strict:true": "test/built-ins/Iterator/concat/fresh-iterator-result.js: ReferenceError: Iterator is not defined ", @@ -146,27 +133,12 @@ "test/built-ins/Iterator/zipKeyed/suspended-start-iterator-close-calls-return.js-strict:true": "test/built-ins/Iterator/zipKeyed/suspended-start-iterator-close-calls-return.js: ReferenceError: Iterator is not defined ", "test/built-ins/Iterator/zipKeyed/suspended-yield-iterator-close-calls-next.js-strict:true": "test/built-ins/Iterator/zipKeyed/suspended-yield-iterator-close-calls-next.js: ReferenceError: Iterator is not defined ", "test/built-ins/Iterator/zipKeyed/suspended-yield-iterator-close-calls-return.js-strict:true": "test/built-ins/Iterator/zipKeyed/suspended-yield-iterator-close-calls-return.js: ReferenceError: Iterator is not defined ", - "test/built-ins/JSON/isRawJSON/basic.js-strict:true": "test/built-ins/JSON/isRawJSON/basic.js: TypeError: Object has no member 'isRawJSON' ", - "test/built-ins/JSON/isRawJSON/builtin.js-strict:true": "test/built-ins/JSON/isRawJSON/builtin.js: Test262Error: JSON.isRawJSON is extensible ", - "test/built-ins/JSON/isRawJSON/length.js-strict:true": "test/built-ins/JSON/isRawJSON/length.js: TypeError: Cannot convert undefined or null to object ", - "test/built-ins/JSON/isRawJSON/name.js-strict:true": "test/built-ins/JSON/isRawJSON/name.js: TypeError: Cannot convert undefined or null to object ", - "test/built-ins/JSON/isRawJSON/not-a-constructor.js-strict:true": "test/built-ins/JSON/isRawJSON/not-a-constructor.js: Test262Error: isConstructor invoked with a non-function value ", - "test/built-ins/JSON/isRawJSON/prop-desc.js-strict:true": "test/built-ins/JSON/isRawJSON/prop-desc.js: Test262Error: obj should have an own property isRawJSON ", "test/built-ins/JSON/parse/reviver-call-args-after-forward-modification.js-strict:true": "test/built-ins/JSON/parse/reviver-call-args-after-forward-modification.js: TypeError: Value is not object coercible ", "test/built-ins/JSON/parse/reviver-context-source-array-literal.js-strict:true": "test/built-ins/JSON/parse/reviver-context-source-array-literal.js: Test262Error: context should be an object Expected SameValue(«\"undefined\"», «\"object\"») to be true ", "test/built-ins/JSON/parse/reviver-context-source-object-literal.js-strict:true": "test/built-ins/JSON/parse/reviver-context-source-object-literal.js: Test262Error: context should be an object Expected SameValue(«\"undefined\"», «\"object\"») to be true ", "test/built-ins/JSON/parse/reviver-context-source-primitive-literal.js-strict:true": "test/built-ins/JSON/parse/reviver-context-source-primitive-literal.js: Test262Error: context should be an object Expected SameValue(«\"undefined\"», «\"object\"») to be true ", "test/built-ins/JSON/parse/reviver-forward-modifies-object.js-strict:true": "test/built-ins/JSON/parse/reviver-forward-modifies-object.js: TypeError: Value is not object coercible ", - "test/built-ins/JSON/rawJSON/basic.js-strict:true": "test/built-ins/JSON/rawJSON/basic.js: TypeError: Object has no member 'rawJSON' ", "test/built-ins/JSON/rawJSON/bigint-raw-json-can-be-stringified.js-strict:true": "test/built-ins/JSON/rawJSON/bigint-raw-json-can-be-stringified.js: TypeError: Value is not object coercible ", - "test/built-ins/JSON/rawJSON/builtin.js-strict:true": "test/built-ins/JSON/rawJSON/builtin.js: Test262Error: JSON.rawJSON is extensible ", - "test/built-ins/JSON/rawJSON/illegal-empty-and-start-end-chars.js-strict:true": "test/built-ins/JSON/rawJSON/illegal-empty-and-start-end-chars.js: Test262Error: Expected a SyntaxError but got a TypeError ", - "test/built-ins/JSON/rawJSON/invalid-JSON-text.js-strict:true": "test/built-ins/JSON/rawJSON/invalid-JSON-text.js: Test262Error: Expected a SyntaxError but got a TypeError ", - "test/built-ins/JSON/rawJSON/length.js-strict:true": "test/built-ins/JSON/rawJSON/length.js: TypeError: Cannot convert undefined or null to object ", - "test/built-ins/JSON/rawJSON/name.js-strict:true": "test/built-ins/JSON/rawJSON/name.js: TypeError: Cannot convert undefined or null to object ", - "test/built-ins/JSON/rawJSON/not-a-constructor.js-strict:true": "test/built-ins/JSON/rawJSON/not-a-constructor.js: Test262Error: isConstructor invoked with a non-function value ", - "test/built-ins/JSON/rawJSON/prop-desc.js-strict:true": "test/built-ins/JSON/rawJSON/prop-desc.js: Test262Error: obj should have an own property rawJSON ", - "test/built-ins/JSON/rawJSON/returns-expected-object.js-strict:true": "test/built-ins/JSON/rawJSON/returns-expected-object.js: TypeError: Object has no member 'rawJSON' ", "test/built-ins/Map/prototype/getOrInsert/append-new-values-normalizes-zero-key.js-strict:true": "test/built-ins/Map/prototype/getOrInsert/append-new-values-normalizes-zero-key.js: TypeError: Object has no member 'getOrInsert' ", "test/built-ins/Map/prototype/getOrInsert/append-new-values.js-strict:true": "test/built-ins/Map/prototype/getOrInsert/append-new-values.js: TypeError: Object has no member 'getOrInsert' ", "test/built-ins/Map/prototype/getOrInsert/append-value-if-key-is-not-present-different-key-types.js-strict:true": "test/built-ins/Map/prototype/getOrInsert/append-value-if-key-is-not-present-different-key-types.js: TypeError: Object has no member 'getOrInsert' ", @@ -192,9 +164,6 @@ "test/built-ins/Map/prototype/getOrInsertComputed/returns-value-if-key-is-not-present-different-key-types.js-strict:true": "test/built-ins/Map/prototype/getOrInsertComputed/returns-value-if-key-is-not-present-different-key-types.js: TypeError: Object has no member 'getOrInsertComputed' ", "test/built-ins/Map/prototype/getOrInsertComputed/returns-value-if-key-is-present-different-key-types.js-strict:true": "test/built-ins/Map/prototype/getOrInsertComputed/returns-value-if-key-is-present-different-key-types.js: TypeError: Object has no member 'getOrInsertComputed' ", "test/built-ins/Map/prototype/getOrInsertComputed/returns-value-normalized-zero-key.js-strict:true": "test/built-ins/Map/prototype/getOrInsertComputed/returns-value-normalized-zero-key.js: TypeError: Object has no member 'getOrInsertComputed' ", - "test/built-ins/NativeErrors/nativeerror-tostring-message-throws-symbol.js-strict:true": "test/built-ins/NativeErrors/nativeerror-tostring-message-throws-symbol.js: Test262Error: If _message_ is a Symbol, EvalError should throw a TypeError Expected a TypeError to be thrown but no exception was thrown at all ", - "test/built-ins/Object/prototype/setPrototypeOf-with-non-circular-values-__proto__.js-strict:true": "test/built-ins/Object/prototype/setPrototypeOf-with-non-circular-values-__proto__.js: Test262Error: Object.setPrototypeOf(ObjProto, { __proto__: null }) throws a TypeError Expected a TypeError to be thrown but no exception was thrown at all ", - "test/built-ins/Object/prototype/setPrototypeOf-with-non-circular-values.js-strict:true": "test/built-ins/Object/prototype/setPrototypeOf-with-non-circular-values.js: Test262Error: Object.setPrototypeOf(ObjProto, Object.create(null)) throws a TypeError Expected a TypeError to be thrown but no exception was thrown at all ", "test/built-ins/RegExp/CharacterClassEscapes/character-class-digit-class-escape-negative-cases.js-strict:true": "test/built-ins/RegExp/CharacterClassEscapes/character-class-digit-class-escape-negative-cases.js: SyntaxError: Invalid flags supplied to RegExp constructor 'v' ", "test/built-ins/RegExp/CharacterClassEscapes/character-class-digit-class-escape-positive-cases.js-strict:true": "test/built-ins/RegExp/CharacterClassEscapes/character-class-digit-class-escape-positive-cases.js: SyntaxError: Invalid flags supplied to RegExp constructor 'v' ", "test/built-ins/RegExp/CharacterClassEscapes/character-class-non-digit-class-escape-negative-cases.js-strict:true": "test/built-ins/RegExp/CharacterClassEscapes/character-class-non-digit-class-escape-negative-cases.js: SyntaxError: Invalid flags supplied to RegExp constructor 'v' ", @@ -208,6 +177,7 @@ "test/built-ins/RegExp/CharacterClassEscapes/character-class-word-class-escape-negative-cases.js-strict:true": "test/built-ins/RegExp/CharacterClassEscapes/character-class-word-class-escape-negative-cases.js: SyntaxError: Invalid flags supplied to RegExp constructor 'v' ", "test/built-ins/RegExp/CharacterClassEscapes/character-class-word-class-escape-positive-cases.js-strict:true": "test/built-ins/RegExp/CharacterClassEscapes/character-class-word-class-escape-positive-cases.js: SyntaxError: Invalid flags supplied to RegExp constructor 'v' ", "test/built-ins/RegExp/lookahead-quantifier-match-groups.js-strict:true": "test/built-ins/RegExp/lookahead-quantifier-match-groups.js: Test262Error: Actual [a, abc] and expected [a, undefined] should have the same contents. ? quantifier ", + "test/built-ins/RegExp/named-groups/non-unicode-property-names-valid.js-strict:true": "test/built-ins/RegExp/named-groups/non-unicode-property-names-valid.js: SyntaxError: Invalid regular expression (regexp2): (?<\\ud835\\udc53\\ud835\\udc5c\\ud835\\udc65>fox).*(?<\\ud835\\udcd3\\ud835\\udcf8\\ud835\\udcf0>dog) (Invalid regular expression (regexp2): (?<\\ud835\\udc53\\ud835\\udc5c\\ud835\\udc65>fox).*(?<\\ud835\\udcd3\\ud835\\udcf8\\ud835\\udcf0>dog) (error parsing regexp: invalid capture group name in `(?<\\ud835\\udc53\\ud835\\udc5c\\ud835\\udc65>fox).*(?<\\ud835\\udcd3\\ud835\\udcf8\\ud835\\udcf0>dog)`)) ", "test/built-ins/RegExp/nullable-quantifier.js-strict:true": "test/built-ins/RegExp/nullable-quantifier.js: Test262Error: The regex is expected to match the whole string Expected SameValue(«\"a\"», «\"ab\"») to be true ", "test/built-ins/RegExp/quantifier-integer-limit.js-strict:true": "test/built-ins/RegExp/quantifier-integer-limit.js: SyntaxError: Invalid regular expression (regexp2): b{9007199254740991} (Invalid regular expression (regexp2): b{9007199254740991} (error parsing regexp: capture group number out of range in `b{9007199254740991}`)) ", "test/built-ins/RegExp/unicode_full_case_folding.js-strict:true": "test/built-ins/RegExp/unicode_full_case_folding.js: Test262Error: \\u0390 does not match \\u1fd3 ", @@ -359,6 +329,11 @@ "test/language/literals/regexp/invalid-optional-negative-lookbehind.js-strict:true": "test/language/literals/regexp/invalid-optional-negative-lookbehind.js: error is not an object (Test262: This statement should not be evaluated.)", "test/language/literals/regexp/invalid-range-lookbehind.js-strict:true": "test/language/literals/regexp/invalid-range-lookbehind.js: error is not an object (Test262: This statement should not be evaluated.)", "test/language/literals/regexp/invalid-range-negative-lookbehind.js-strict:true": "test/language/literals/regexp/invalid-range-negative-lookbehind.js: error is not an object (Test262: This statement should not be evaluated.)", + "test/language/literals/regexp/named-groups/invalid-duplicate-groupspecifier-2-u.js-strict:true": "test/language/literals/regexp/named-groups/invalid-duplicate-groupspecifier-2-u.js: error is not an object (Test262: This statement should not be evaluated.)", + "test/language/literals/regexp/named-groups/invalid-duplicate-groupspecifier-2.js-strict:true": "test/language/literals/regexp/named-groups/invalid-duplicate-groupspecifier-2.js: error is not an object (Test262: This statement should not be evaluated.)", + "test/language/literals/regexp/named-groups/invalid-duplicate-groupspecifier-u.js-strict:true": "test/language/literals/regexp/named-groups/invalid-duplicate-groupspecifier-u.js: error is not an object (Test262: This statement should not be evaluated.)", + "test/language/literals/regexp/named-groups/invalid-duplicate-groupspecifier.js-strict:true": "test/language/literals/regexp/named-groups/invalid-duplicate-groupspecifier.js: error is not an object (Test262: This statement should not be evaluated.)", + "test/language/literals/regexp/named-groups/invalid-identity-escape-in-capture-u.js-strict:true": "test/language/literals/regexp/named-groups/invalid-identity-escape-in-capture-u.js: error is not an object (Test262: This statement should not be evaluated.)", "test/language/literals/regexp/u-case-mapping.js-strict:true": "test/language/literals/regexp/u-case-mapping.js: Test262Error: Case mapping is not applied in the absence of the `u` flag Expected SameValue(«true», «false») to be true ", "test/language/literals/regexp/u-invalid-class-escape.js-strict:true": "test/language/literals/regexp/u-invalid-class-escape.js: error is not an object (Test262: This statement should not be evaluated.)", "test/language/literals/regexp/u-invalid-extended-pattern-char.js-strict:true": "test/language/literals/regexp/u-invalid-extended-pattern-char.js: error is not an object (Test262: This statement should not be evaluated.)", diff --git a/internal/js/tc39/tc39_test.go b/internal/js/tc39/tc39_test.go index 02a96c951..88abe45b6 100644 --- a/internal/js/tc39/tc39_test.go +++ b/internal/js/tc39/tc39_test.go @@ -54,15 +54,13 @@ var ( false) featuresBlockList = []string{ - "IsHTMLDDA", // not supported at all - "async-iteration", // not supported at all - "String.prototype.replaceAll", // not supported at all, Stage 4 since 2020 - "dynamic-import", // not support in k6 + "IsHTMLDDA", // not supported at all + "async-iteration", // not supported at all + "dynamic-import", // not support in k6 // from Sobek "Symbol.asyncIterator", "resizable-arraybuffer", - "regexp-named-groups", "regexp-duplicate-named-groups", "regexp-unicode-property-escapes", "regexp-match-indices", @@ -72,7 +70,6 @@ var ( "tail-call-optimization", "Temporal", "import-assertions", - "logical-assignment-operators", "Atomics", "Atomics.waitAsync", "Atomics.pause", @@ -88,10 +85,8 @@ var ( "regexp-v-flag", "iterator-helpers", "symbols-as-weakmap-keys", - "uint8array-base64", "String.prototype.toWellFormed", "explicit-resource-management", - "set-methods", "promise-try", "promise-with-resolvers", "array-grouping", diff --git a/vendor/github.com/dlclark/regexp2/v2/decode.go b/vendor/github.com/dlclark/regexp2/v2/decode.go new file mode 100644 index 000000000..b0b834f7d --- /dev/null +++ b/vendor/github.com/dlclark/regexp2/v2/decode.go @@ -0,0 +1,167 @@ +package regexp2 + +import ( + "unicode/utf8" + + "github.com/dlclark/regexp2/v2/helpers" +) + +// decodedInput is the engine's rune view of a string. When the pattern cannot +// look behind a candidate start, the slice may begin at that candidate instead +// of byte 0. +type decodedInput struct { + runes []rune + pooled *[]rune + runeStart int // index in runes of the requested startAt; -1 if not a rune boundary + runeOffset int // original-string rune index of runes[0] + byteOffset int // original-string byte index of runes[0] + ascii bool // every decoded rune is ASCII; invalid UTF-8 is not ASCII +} + +// decodeFrom is the first original-string byte that must be decoded. 0 means +// the whole string; a later index is only used when slicing is safe. +func (re *Regexp) decodeFrom(s string, startAt int) int { + if startAt <= 0 || re.RightToLeft() { + return 0 + } + need := re.decodeLeftContextRunes() + if need < 0 { + return 0 + } + if need > 0 { + return prevRuneByte(s, startAt) + } + return startAt +} + +func (re *Regexp) decodeLeftContextRunes() int { + if re.code != nil { + return re.code.LeftContextRunes + } + return re.leftContextRunes +} + +// stringSearchOrigin preserves the caller's origin when \G may observe it. +// Such patterns retain the whole input, so no decode offset is needed. +// Otherwise the origin is unobservable and the candidate is sufficient. +func (re *Regexp) stringSearchOrigin(input string, startAt, candidate int) int { + if !re.RightToLeft() && re.decodeLeftContextRunes() < 0 { + if startAt <= 0 { + return 0 + } + return utf8.RuneCountInString(input[:startAt]) + } + return candidate +} + +// decodeString converts s to []rune for the MatchString startAt<=0 path. +// Keep this as close as possible to a single UTF-8 walk so 4–30 byte +// matches stay cheap. +func decodeString(s string, maxCachedLength int) ([]rune, *[]rune) { + buf, pooled := pooledRuneBuffers.get(len(s), maxCachedLength) + if len(s) >= helpers.ASCIIScanMin { + n, _ := helpers.DecodeString(s, buf) + return buf[:n], pooled + } + n := 0 + for _, ch := range s { + buf[n] = ch + n++ + } + return buf[:n], pooled +} + +func (re *Regexp) decodeStringInput(s string, startAt int, pooled bool) decodedInput { + maxCachedLength := 0 + if pooled { + maxCachedLength = re.optimizations.MaxCachedRuneBufferLength + } + return decodeInput(s, startAt, re.decodeFrom(s, startAt), maxCachedLength, true) +} + +// decodeInput converts s[decodeFrom:] to runes. startAt is a byte index in s. +// If startAt < 0 or is not a rune boundary, runeStart is -1. needOffsets walks +// the skipped prefix to fill runeOffset; MatchString does not need that field. +func decodeInput(s string, startAt, decodeFrom, maxCachedLength int, needOffsets bool) decodedInput { + if decodeFrom < 0 { + decodeFrom = 0 + } + if decodeFrom > len(s) { + decodeFrom = len(s) + } + + substr := s[decodeFrom:] + buf, pooledBuffer := pooledRuneBuffers.get(len(substr), maxCachedLength) + n, ascii := helpers.DecodeString(substr, buf) + runes := buf[:n] + + out := decodedInput{ + runes: runes, + pooled: pooledBuffer, + byteOffset: decodeFrom, + ascii: ascii, + runeStart: startRuneIndex(s, startAt, decodeFrom, n, ascii), + } + + if !needOffsets { + return out + } + + // Byte index equals rune index only when the skipped prefix is also ASCII. + if ascii && (decodeFrom == 0 || helpers.IsASCII(s[:decodeFrom])) { + out.runeOffset = decodeFrom + return out + } + if decodeFrom > 0 { + out.runeOffset = utf8.RuneCountInString(s[:decodeFrom]) + } + return out +} + +func startRuneIndex(s string, startAt, decodeFrom, runeCount int, ascii bool) int { + if startAt < 0 { + return -1 + } + if startAt < decodeFrom || startAt > len(s) { + return -1 + } + if startAt == decodeFrom { + return 0 + } + if startAt == len(s) { + return runeCount + } + if ascii { + return startAt - decodeFrom + } + rel := startAt - decodeFrom + i := 0 + for strIdx := range s[decodeFrom:] { + if strIdx == rel { + return i + } + if strIdx > rel { + return -1 + } + i++ + } + return -1 +} + +func prevRuneByte(s string, byteIndex int) int { + if byteIndex <= 0 { + return 0 + } + _, size := utf8.DecodeLastRuneInString(s[:byteIndex]) + if size <= 0 { + return byteIndex - 1 + } + return byteIndex - size +} + +func (d decodedInput) release() { + if d.pooled != nil { + *d.pooled = d.runes + pooledRuneBuffers.put(d.pooled) + } +} diff --git a/vendor/github.com/dlclark/regexp2/v2/helpers/ascii.go b/vendor/github.com/dlclark/regexp2/v2/helpers/ascii.go new file mode 100644 index 000000000..a7b4829ad --- /dev/null +++ b/vendor/github.com/dlclark/regexp2/v2/helpers/ascii.go @@ -0,0 +1,75 @@ +package helpers + +import ( + "unicode/utf8" + "unsafe" +) + +const asciiHighBits = 0x8080808080808080 + +// ASCIIScanMin is the input length where a separate ASCII probe plus a tight +// copy beats a single UTF-8 range loop. Short matches stay on the one-pass path. +const ASCIIScanMin = 64 + +// ASCIISearchMin is the haystack length where stdlib/SIMD string search beats +// a scalar first-rune scan. Below this, needle setup and unaligned +// bytes.Index retries dominate. +const ASCIISearchMin = 32 + +// IsASCII reports whether s contains only bytes below utf8.RuneSelf. +func IsASCII(s string) bool { + n := len(s) + if n == 0 { + return true + } + + b := unsafe.Slice(unsafe.StringData(s), n) + i := 0 + for ; i < n && uintptr(unsafe.Pointer(&b[i]))&7 != 0; i++ { + if b[i] >= utf8.RuneSelf { + return false + } + } + for ; i+8 <= n; i += 8 { + v := *(*uint64)(unsafe.Pointer(&b[i])) + if v&asciiHighBits != 0 { + return false + } + } + for ; i < n; i++ { + if b[i] >= utf8.RuneSelf { + return false + } + } + return true +} + +// IsASCIIRunes reports whether every rune in in is an ASCII code point. +func IsASCIIRunes(in []rune) bool { + for _, ch := range in { + if ch >= utf8.RuneSelf { + return false + } + } + return true +} + +// DecodeString writes the runes of s into buf, which must have length >= len(s). +// It returns the rune count and whether s was all ASCII. +func DecodeString(s string, buf []rune) (n int, ascii bool) { + if len(s) >= ASCIIScanMin && IsASCII(s) { + for i := 0; i < len(s); i++ { + buf[i] = rune(s[i]) + } + return len(s), true + } + ascii = true + for _, ch := range s { + if ch >= utf8.RuneSelf { + ascii = false + } + buf[n] = ch + n++ + } + return n, ascii +} diff --git a/vendor/github.com/dlclark/regexp2/v2/helpers/indexof.go b/vendor/github.com/dlclark/regexp2/v2/helpers/indexof.go index 8d24a8c08..5cd13e079 100644 --- a/vendor/github.com/dlclark/regexp2/v2/helpers/indexof.go +++ b/vendor/github.com/dlclark/regexp2/v2/helpers/indexof.go @@ -11,11 +11,30 @@ import ( ) func IndexOfAny(in []rune, find []rune) int { - // special case - if len(find) == 0 { + switch len(find) { + case 0: + return -1 + case 1: + return IndexOfAny1(in, find[0]) + case 2: + return IndexOfAny2(in, find[0], find[1]) + case 3: + return IndexOfAny3(in, find[0], find[1], find[2]) + } + + if IsASCIIRunes(find) { + var bits [2]uint64 + for _, c := range find { + bits[c>>6] |= 1 << (c & 63) + } + for i, c := range in { + if uint32(c) < 128 && bits[c>>6]&(1<<(c&63)) != 0 { + return i + } + } return -1 } - // naive version + for i, c := range in { if slices.Contains(find, c) { return i @@ -25,8 +44,10 @@ func IndexOfAny(in []rune, find []rune) int { } func IndexOfAny1(in []rune, find rune) int { - //TODO: bytes optimization? - return slices.Index(in, find) + if len(in) < ASCIISearchMin { + return slices.Index(in, find) + } + return indexOfRuneBytes(runeSliceBytes(in), find) } func IndexOfAny2(in []rune, find1, find2 rune) int { @@ -125,28 +146,34 @@ func IndexFunc(in []rune, f func(ch rune) bool) int { } func IndexOfAnyExceptInSet(in []rune, set syntax.CharSet) int { - //TODO: this - panic("not implemented") + for i, c := range in { + if !set.Contains(c) { + return i + } + } + return -1 } func LastIndexOf(in []rune, find []rune) int { - end := len(in) - len(find) - first := find[0] - lastOffset := len(find) - 1 - last := find[lastOffset] - for i := end; i >= 0; i-- { - //TODO: check 2 chars needed? - // match start and end...check the middle - if in[i] == first && in[i+lastOffset] == last { - // found our first char - // check if the rest are equal - if bytesEqual(in[i:i+len(find)], find) { - return i - } + if len(find) == 0 { + return len(in) + } + if len(in) < len(find) { + return -1 + } + haystack := runeSliceBytes(in) + needle := runeSliceBytes(find) + end := len(haystack) + for end >= len(needle) { + idx := bytes.LastIndex(haystack[:end], needle) + if idx < 0 { + return -1 } + if idx%4 == 0 { + return idx / 4 + } + end = idx + len(needle) - 1 } - - //not found return -1 } @@ -160,15 +187,10 @@ func LastIndexOfAnyExcept1(in []rune, not rune) int { } func LastIndexOfAny1(in []rune, find rune) int { - for i := len(in) - 1; i >= 0; i-- { - if in[i] == find { - // found our char - return i - } + if len(in) == 0 { + return -1 } - - //not found - return -1 + return lastIndexOfRuneBytes(runeSliceBytes(in), find) } func LastIndexOfAnyInRange(in []rune, first, last rune) int { @@ -291,30 +313,66 @@ func foldASCII(c rune) rune { } func IndexOf(in []rune, find []rune) int { - /* - Since we auto-gen the find code this shouldn't happen - if len(find) == 0 { - //special case - return -1 - }*/ + if len(find) == 0 { + return 0 + } + if len(in) < len(find) { + return -1 + } end := len(in) - len(find) first := find[0] - //TODO: benchmark checking last char too or first two chars - for i := 0; i <= end; i++ { - // match start...check the rest - if in[i] == first { - // found our first char - // check if the rest are equal - if bytesEqual(in[i:i+len(find)], find) { - return i - } - /*if slices.Equal(in[i:i+len(find)], find) { - return i - }*/ + for i := 0; i <= end; { + off := IndexOfAny1(in[i:end+1], first) + if off < 0 { + return -1 + } + i += off + if bytesEqual(in[i:i+len(find)], find) { + return i } + i++ } + return -1 +} + +func runeSliceBytes(in []rune) []byte { + if len(in) == 0 { + return nil + } + return unsafe.Slice((*byte)(unsafe.Pointer(&in[0])), len(in)*4) +} - //not found +func indexOfRuneBytes(haystack []byte, find rune) int { + needleRune := [1]rune{find} + needle := runeSliceBytes(needleRune[:]) + start := 0 + for { + idx := bytes.Index(haystack[start:], needle) + if idx < 0 { + return -1 + } + idx += start + if idx%4 == 0 { + return idx / 4 + } + start = idx + 1 + } +} + +func lastIndexOfRuneBytes(haystack []byte, find rune) int { + needleRune := [1]rune{find} + needle := runeSliceBytes(needleRune[:]) + end := len(haystack) + for end >= 4 { + idx := bytes.LastIndex(haystack[:end], needle) + if idx < 0 { + return -1 + } + if idx%4 == 0 { + return idx / 4 + } + end = idx + 3 + } return -1 } diff --git a/vendor/github.com/dlclark/regexp2/v2/helpers/searchvalues.go b/vendor/github.com/dlclark/regexp2/v2/helpers/searchvalues.go index bafbcfbc2..0346d7d48 100644 --- a/vendor/github.com/dlclark/regexp2/v2/helpers/searchvalues.go +++ b/vendor/github.com/dlclark/regexp2/v2/helpers/searchvalues.go @@ -64,14 +64,30 @@ func (s AsciiSearchValues) IndexOfAnyExcept(chars []rune) int { // return the last index of our original vals values within the slice given func (s AsciiSearchValues) LastIndexOfAny(chars []rune) int { - panic("not implemented") - //TODO: this + for i := len(chars) - 1; i >= 0; i-- { + c := chars[i] + if c > unicode.MaxASCII { + continue + } + if s.set[c/64]&(1<<(c%64)) != 0 { + return i + } + } + return -1 } // return the last index of our original vals values within the slice given func (s AsciiSearchValues) LastIndexOfAnyExcept(chars []rune) int { - panic("not implemented") - //TODO: this + for i := len(chars) - 1; i >= 0; i-- { + c := chars[i] + if c > unicode.MaxASCII { + return i + } + if s.set[c/64]&(1<<(c%64)) == 0 { + return i + } + } + return -1 } type RuneSearchValues struct { @@ -79,37 +95,40 @@ type RuneSearchValues struct { } func newRuneSearchValues(vals []rune) RuneSearchValues { - //TODO: pre-calc the stuff we need to make each IndexOf go faster return RuneSearchValues{vals: vals} - } func NewRuneSearchValues(vals string) RuneSearchValues { return newRuneSearchValues([]rune(vals)) } -// return the first index of our original vals values within the slice given func (s RuneSearchValues) IndexOfAny(chars []rune) int { - //naive implementation - //TODO: this return IndexOfAny(chars, s.vals) } -// return the first index of our original vals values within the slice given func (s RuneSearchValues) IndexOfAnyExcept(chars []rune) int { - //TODO: this return IndexOfAnyExcept(chars, s.vals) } -// return the last index of our original vals values within the slice given func (s RuneSearchValues) LastIndexOfAny(chars []rune) int { - panic("not implemented") + if len(s.vals) == 1 { + return LastIndexOfAny1(chars, s.vals[0]) + } + for i := len(chars) - 1; i >= 0; i-- { + if slices.Contains(s.vals, chars[i]) { + return i + } + } + return -1 } -// return the last index of our original vals values within the slice given func (s RuneSearchValues) LastIndexOfAnyExcept(chars []rune) int { - panic("not implemented") - //TODO: this + for i := len(chars) - 1; i >= 0; i-- { + if !slices.Contains(s.vals, chars[i]) { + return i + } + } + return -1 } type StringSearchValues struct { @@ -145,11 +164,21 @@ func NewStringSearchValues(vals [][]rune, ignoreCase bool) StringSearchValues { } func (s StringSearchValues) StartsWith(chars []rune) int { - panic("not implemented") + for _, val := range s.vals { + if StartsWith(chars, val) { + return 0 + } + } + return -1 } func (s StringSearchValues) StartsWithIgnoreCase(chars []rune) int { - panic("not implemented") + for _, val := range s.vals { + if StartsWithIgnoreCase(chars, val) { + return 0 + } + } + return -1 } func (s StringSearchValues) IndexOfAny(in []rune) int { diff --git a/vendor/github.com/dlclark/regexp2/v2/match.go b/vendor/github.com/dlclark/regexp2/v2/match.go index 4003ff0f5..91d83d08d 100644 --- a/vendor/github.com/dlclark/regexp2/v2/match.go +++ b/vendor/github.com/dlclark/regexp2/v2/match.go @@ -44,8 +44,9 @@ type Group struct { type Capture struct { // the original string text *matchText - // RuneIndex is the position in the underlying rune slice where the first character of - // captured substring was found. Even if you pass in a string this will be in Runes. + // RuneIndex is the rune index in the original input where the capture starts. + // For string input this counts runes from the start of that string, not of + // any internally sliced decode buffer. RuneIndex int // RuneLength is the number of runes in the captured substring. RuneLength int @@ -55,24 +56,46 @@ type matchText struct { runes []rune input string hasStringInput bool + runeOffset int // original-string rune index of runes[0] + byteOffset int // original-string byte index of runes[0] byteOffsets []int byteOffsetsReady bool } -// String returns the captured text as a String +// String returns the captured text. For string input it is a slice of the +// original haystack: it does not allocate and keeps the original string alive. func (c *Capture) String() string { - return string(c.text.runes[c.RuneIndex : c.RuneIndex+c.RuneLength]) + if c.text == nil { + return "" + } + if c.text.hasStringInput { + start, length := c.ByteRange() + return c.text.input[start : start+length] + } + start := c.runeSliceIndex() + return string(c.text.runes[start : start+c.RuneLength]) } // Runes returns the captured text as a rune slice func (c *Capture) Runes() []rune { - return c.text.runes[c.RuneIndex : c.RuneIndex+c.RuneLength] + if c.text == nil { + return nil + } + start := c.runeSliceIndex() + return c.text.runes[start : start+c.RuneLength] +} + +func (c *Capture) runeSliceIndex() int { + if c.text == nil { + return c.RuneIndex + } + return c.RuneIndex - c.text.runeOffset } // ByteRange returns the UTF-8 byte index and byte length of the captured -// substring. The first call lazily caches byte offsets on shared match text, -// so it is not safe to call concurrently with ByteRange on another capture -// from the same match until the cache has been initialized. +// substring. Matches returned to callers have offsets computed when the match +// is tidied, so concurrent ByteRange/String on captures of the same match is +// then safe. Internal match objects may still initialize the cache on first use. func (c *Capture) ByteRange() (index, length int) { if c.text == nil { return c.RuneIndex, c.RuneLength @@ -85,53 +108,61 @@ func newMatchText(r []rune) *matchText { } func newStringMatchText(input string, r []rune) *matchText { - return &matchText{runes: r, input: input, hasStringInput: true} + return newStringMatchTextAt(input, r, 0, 0) +} + +func newStringMatchTextAt(input string, r []rune, runeOffset, byteOffset int) *matchText { + return &matchText{ + runes: r, + input: input, + hasStringInput: true, + runeOffset: runeOffset, + byteOffset: byteOffset, + // Every decoded rune consumes at least one byte, even invalid UTF-8. + // Equal lengths therefore mean byte and rune offsets are identical. + byteOffsetsReady: len(input)-byteOffset == len(r), + } } -func (t *matchText) byteRange(runeIndex, runeLength int) (int, int) { - if !t.byteOffsetsReady { - t.byteOffsets = t.buildByteOffsets() - t.byteOffsetsReady = true +func (t *matchText) ensureByteOffsets() { + if t == nil || t.byteOffsetsReady { + return } + t.byteOffsets = t.buildByteOffsets() + t.byteOffsetsReady = true +} + +func (t *matchText) byteRange(runeIndex, runeLength int) (int, int) { + localRuneIndex := runeIndex - t.runeOffset + t.ensureByteOffsets() if t.byteOffsets == nil { - return runeIndex, runeLength + return t.byteOffset + localRuneIndex, runeLength } - byteIndex := t.byteOffsets[runeIndex] - return byteIndex, t.byteOffsets[runeIndex+runeLength] - byteIndex + byteIndex := t.byteOffsets[localRuneIndex] + return t.byteOffset + byteIndex, t.byteOffsets[localRuneIndex+runeLength] - byteIndex } func (t *matchText) buildByteOffsets() []int { if t.hasStringInput { - return stringByteOffsets(t.input) + return stringByteOffsets(t.input[t.byteOffset:], len(t.runes)) } return runeByteOffsets(t.runes) } -func stringByteOffsets(s string) []int { - var byteOffsets []int - runeIndex := 0 - for strIdx, ch := range s { - if byteOffsets != nil { - byteOffsets[runeIndex] = strIdx - } - runeLen := utf8.RuneLen(ch) - if ch == utf8.RuneError { - _, runeLen = utf8.DecodeRuneInString(s[strIdx:]) - } - if byteOffsets == nil && (strIdx != runeIndex || runeLen != 1) { - byteOffsets = make([]int, len(s)+1) - for i := 0; i < runeIndex; i++ { - byteOffsets[i] = i - } - byteOffsets[runeIndex] = strIdx - } - runeIndex++ +func stringByteOffsets(s string, runeCount int) []int { + if len(s) == runeCount { + return nil } - if byteOffsets != nil { - byteOffsets[runeIndex] = len(s) - return byteOffsets[:runeIndex+1] + // Decoding already established the rune count. A range walk gives the + // original byte positions, including one-byte invalid UTF-8 sequences. + offsets := make([]int, runeCount+1) + i := 0 + for byteIndex := range s { + offsets[i] = byteIndex + i++ } - return nil + offsets[runeCount] = len(s) + return offsets } func runeByteOffsets(runes []rune) []int { @@ -199,6 +230,9 @@ func (m *Match) tidy(textpos int) { m.capcount = m.matchcount[0] //copy our root capture to the list m.Captures = []Capture{m.Capture} + if m.text != nil && m.text.hasStringInput { + m.text.ensureByteOffsets() + } if m.balancing { // The idea here is that we want to compact all of our unbalanced captures. To do that we @@ -340,9 +374,11 @@ func (m *Match) GroupByName(name string) *Group { func (m *Match) GroupByNumber(num int) *Group { // check our sparse map if m.sparseCaps != nil { - if newNum, ok := m.sparseCaps[num]; ok { - num = newNum + newNum, ok := m.sparseCaps[num] + if !ok { + return nil } + num = newNum } if num >= len(m.matchcount) || num < 0 { return nil @@ -415,6 +451,9 @@ func newCapture(text *matchText, runeIndex, runeLength int) Capture { } func setCaptureFields(c *Capture, runeIndex, runeLength int) { + if c.text != nil { + runeIndex += c.text.runeOffset + } c.RuneIndex = runeIndex c.RuneLength = runeLength } diff --git a/vendor/github.com/dlclark/regexp2/v2/regexp.go b/vendor/github.com/dlclark/regexp2/v2/regexp.go index c3f2adb32..632207071 100644 --- a/vendor/github.com/dlclark/regexp2/v2/regexp.go +++ b/vendor/github.com/dlclark/regexp2/v2/regexp.go @@ -13,7 +13,6 @@ import ( "errors" "log" "math" - "sort" "strconv" "sync" "time" @@ -64,6 +63,9 @@ type Regexp struct { executeQuick func(r *Runner) error stringPrefixFilter StringPrefixFilter quickCode *syntax.Code // bool-only program with unobservable captures removed + // leftContextRunes is used when code is nil (registered engines). + // The interpreter reads the same value from code.LeftContextRunes. + leftContextRunes int } // Compile parses a regular expression and returns, if successful, @@ -126,7 +128,9 @@ func makeQuickCode(code *syntax.Code) *syntax.Code { } quick := *code quick.Codes = code.QuickCodes + quick.Dispatches = code.QuickDispatches quick.QuickCodes = nil + quick.QuickDispatches = nil return &quick } @@ -240,12 +244,7 @@ func (re *Regexp) FindStringMatch(s string) (*Match, error) { if !ok { return nil, nil } - - r, runeStart := re.getRunesAndStart(s, startAt) - if runeStart < 0 { - runeStart = 0 - } - return re.run(false, runeStart, -1, r, newStringMatchText(s, r)) + return re.findDecodedStringMatch(s, startAt, -1) } // FindRunesMatch searches the input rune slice for a Regexp match @@ -255,21 +254,25 @@ func (re *Regexp) FindRunesMatch(r []rune) (*Match, error) { // FindStringMatchStartingAt searches the input string for a Regexp match starting at the startAt index func (re *Regexp) FindStringMatchStartingAt(s string, startAt int) (*Match, error) { - startAt, ok, err := re.findStringMatchStart(s, startAt) + candidate, ok, err := re.findStringMatchStart(s, startAt) if err != nil { return nil, err } if !ok { return nil, nil } + return re.findDecodedStringMatch(s, candidate, startAt) +} - r, startAt := re.getRunesAndStart(s, startAt) - if startAt == -1 { - // we didn't find our start index in the string -- that's a problem - return nil, errors.New("startAt must align to the start of a valid rune in the input string") - } - - return re.run(false, startAt, -1, r, newStringMatchText(s, r)) +func (re *Regexp) findDecodedStringMatch(s string, candidate, startAt int) (*Match, error) { + // Returned matches retain their rune data, so this path must not consume a + // pooled buffer that can never be returned. + d := re.decodeStringInput(s, candidate, false) + runner := re.getRunner() + defer re.putRunner(runner) + text := newStringMatchTextAt(s, d.runes, d.runeOffset, d.byteOffset) + origin := re.stringSearchOrigin(s, startAt, d.runeStart) + return runner.scan(d.runes, text, origin, d.runeStart, -1, false, re.MatchTimeout) } // FindRunesMatchStartingAt searches the input rune slice for a Regexp match starting at the startAt index @@ -292,36 +295,28 @@ func (re *Regexp) FindAllStringIndex(s string, n int) ([][]int, error) { return nil, nil } + // Index results only need byte offsets. Keep the mapper relative to the + // decoded suffix so neither decoding nor mapping has to count prefix runes. + d := decodeInput(s, startAt, re.decodeFrom(s, startAt), re.optimizations.MaxCachedRuneBufferLength, false) runner := re.getRunner() - var input []rune - var pooledInput *[]rune - runeStart := 0 - if startAt == 0 { - input, pooledInput = runner.decodeString(s) - } else { - input, runeStart, pooledInput = runner.decodeStringWithStart(s, startAt) - } defer func() { re.putRunner(runner) - if pooledInput != nil { - *pooledInput = input - pooledRuneBuffers.put(pooledInput) - } + d.release() }() - - if runeStart < 0 { - runeStart = 0 + byteOffsets := stringByteMapper{input: s[d.byteOffset:]} + if re.RightToLeft() { + byteOffsets.runePos = len(d.runes) + byteOffsets.bytePos = len(byteOffsets.input) } - - byteOffsets := newStringByteMapper(s) if re.quickCode != nil { runner.code = re.quickCode } - return re.findAllRunesIndex(runner, input, runeStart, n, func(runeIndex, runeLength int) (int, int) { - if byteOffsets == nil { - return runeIndex, runeIndex + runeLength + origin := re.stringSearchOrigin(s, -1, d.runeStart) + return re.findAllRunesIndex(runner, d.runes, origin, d.runeStart, n, func(runeIndex, runeLength int) (int, int) { + if len(d.runes) == len(byteOffsets.input) { + return d.byteOffset + runeIndex, d.byteOffset + runeIndex + runeLength } - return byteOffsets.byteIndex(runeIndex), byteOffsets.byteIndex(runeIndex + runeLength) + return d.byteOffset + byteOffsets.byteIndex(runeIndex), d.byteOffset + byteOffsets.byteIndex(runeIndex+runeLength) }) } @@ -342,12 +337,12 @@ func (re *Regexp) FindAllRunesIndex(r []rune, n int) ([][]int, error) { if re.quickCode != nil { runner.code = re.quickCode } - return re.findAllRunesIndex(runner, r, startAt, n, func(runeIndex, runeLength int) (int, int) { + return re.findAllRunesIndex(runner, r, startAt, startAt, n, func(runeIndex, runeLength int) (int, int) { return runeIndex, runeIndex + runeLength }) } -func (re *Regexp) findAllRunesIndex(runner *Runner, input []rune, startAt, n int, makeIndex func(runeIndex, runeLength int) (int, int)) ([][]int, error) { +func (re *Regexp) findAllRunesIndex(runner *Runner, input []rune, origin, startAt, n int, makeIndex func(runeIndex, runeLength int) (int, int)) ([][]int, error) { var out [][]int var flat []int if n > 0 { @@ -358,7 +353,7 @@ func (re *Regexp) findAllRunesIndex(runner *Runner, input []rune, startAt, n int prevEnd := -1 previousMatchLength := -1 for n != 0 { - m, err := runner.scan(input, nil, startAt, previousMatchLength, true, re.MatchTimeout) + m, err := runner.scan(input, nil, origin, startAt, previousMatchLength, true, re.MatchTimeout) if err != nil { return nil, err } @@ -366,57 +361,49 @@ func (re *Regexp) findAllRunesIndex(runner *Runner, input []rune, startAt, n int break } - if m.RuneLength != 0 || m.RuneIndex != prevEnd { - start, end := makeIndex(m.RuneIndex, m.RuneLength) + localIndex := m.runeSliceIndex() + if m.RuneLength != 0 || localIndex != prevEnd { + start, end := makeIndex(localIndex, m.RuneLength) flat = append(flat, start, end) out = append(out, flat[len(flat)-2:len(flat):len(flat)]) - prevEnd = m.RuneIndex + m.RuneLength + prevEnd = localIndex + m.RuneLength if n > 0 { n-- } } startAt = m.textpos + origin = startAt previousMatchLength = m.RuneLength } return out, nil } type stringByteMapper struct { - runeIndexes []int - deltas []int -} - -func newStringByteMapper(s string) *stringByteMapper { - var mapper *stringByteMapper - runeIndex := 0 - delta := 0 - for strIdx, ch := range s { - runeLen := utf8.RuneLen(ch) - if ch == utf8.RuneError { - _, runeLen = utf8.DecodeRuneInString(s[strIdx:]) - } - if runeLen != 1 { - if mapper == nil { - mapper = &stringByteMapper{} - } - delta += runeLen - 1 - mapper.runeIndexes = append(mapper.runeIndexes, runeIndex+1) - mapper.deltas = append(mapper.deltas, delta) - } - runeIndex++ - } - return mapper + input string + runePos int + bytePos int } +// runeIndex is relative to input; each invalid UTF-8 byte counts as one rune. func (m *stringByteMapper) byteIndex(runeIndex int) int { - i := sort.Search(len(m.runeIndexes), func(i int) bool { - return m.runeIndexes[i] > runeIndex - }) - 1 - if i < 0 { - return runeIndex + for m.runePos < runeIndex { + size := 1 + if m.input[m.bytePos] >= utf8.RuneSelf { + _, size = utf8.DecodeRuneInString(m.input[m.bytePos:]) + } + m.bytePos += size + m.runePos++ } - return runeIndex + m.deltas[i] + for m.runePos > runeIndex { + size := 1 + if m.input[m.bytePos-1] >= utf8.RuneSelf { + _, size = utf8.DecodeLastRuneInString(m.input[:m.bytePos]) + } + m.bytePos -= size + m.runePos-- + } + return m.bytePos } // FindNextMatch returns the next match in the same input string as the match parameter. @@ -440,10 +427,6 @@ func (re *Regexp) MatchString(s string) (bool, error) { return re.matchStringAt(s, candidateByteIndex) } - return re.matchString(s) -} - -func (re *Regexp) matchString(s string) (bool, error) { return re.matchStringAt(s, -1) } @@ -453,12 +436,16 @@ func (re *Regexp) matchStringAt(s string, startAt int) (bool, error) { var pooledInput *[]rune runeStart := 0 if startAt <= 0 { - input, pooledInput = runner.decodeString(s) + // Common path: decode the whole string without start/offset work. + input, pooledInput = decodeString(s, re.optimizations.MaxCachedRuneBufferLength) if re.RightToLeft() { runeStart = len(input) } } else { - input, runeStart, pooledInput = runner.decodeStringWithStart(s, startAt) + d := decodeInput(s, startAt, re.decodeFrom(s, startAt), re.optimizations.MaxCachedRuneBufferLength, false) + input = d.runes + pooledInput = d.pooled + runeStart = d.runeStart if runeStart < 0 { runeStart = 0 } @@ -474,41 +461,14 @@ func (re *Regexp) matchStringAt(s string, startAt int) (bool, error) { runner.code = re.quickCode } - m, err := runner.scan(input, nil, runeStart, -1, true, re.MatchTimeout) + origin := re.stringSearchOrigin(s, -1, runeStart) + m, err := runner.scan(input, nil, origin, runeStart, -1, true, re.MatchTimeout) if err != nil { return false, err } return m != nil, nil } -func (re *Regexp) getRunesAndStart(s string, startAt int) ([]rune, int) { - if startAt < 0 { - if re.RightToLeft() { - r := getRunes(s) - return r, len(r) - } - return getRunes(s), 0 - } - ret := make([]rune, len(s)) - i := 0 - runeIdx := -1 - for strIdx, r := range s { - if strIdx == startAt { - runeIdx = i - } - ret[i] = r - i++ - } - if startAt == len(s) { - runeIdx = i - } - return ret[:i], runeIdx -} - -func getRunes(s string) []rune { - return []rune(s) -} - // MatchRunes return true if the runes matches the regex // error will be set if a timeout occurs func (re *Regexp) MatchRunes(r []rune) (bool, error) { diff --git a/vendor/github.com/dlclark/regexp2/v2/regexp_codegen.go b/vendor/github.com/dlclark/regexp2/v2/regexp_codegen.go index cfef08781..52248772c 100644 --- a/vendor/github.com/dlclark/regexp2/v2/regexp_codegen.go +++ b/vendor/github.com/dlclark/regexp2/v2/regexp_codegen.go @@ -13,6 +13,14 @@ type RuntimeEngineData struct { Execute func(*Runner) error ExecuteQuick func(*Runner) error // optional bool-only execution with unobservable captures removed StringPrefixFilter StringPrefixFilter // optional pre-decode candidate search for string input + // LeftContextKnown reports that LeftContextRunes was computed by the + // code generator. If it is false, decoded string input is never sliced; + // older generated engines omit the field and must keep the full string. + LeftContextKnown bool + // LeftContextRunes is how many runes before a candidate start matching + // may inspect. 0 means none, 1 means a single previous rune, and -1 + // means do not slice (lookbehind or \G). Ignored unless LeftContextKnown. + LeftContextRunes int } type cacheKey struct { @@ -30,6 +38,10 @@ func RegisterEngine(pattern string, engine RuntimeEngineData, options ...Compile } func newEngineRegexp(pattern string, c compileConfig, engine RuntimeEngineData) *Regexp { + leftContext := -1 + if engine.LeftContextKnown { + leftContext = engine.LeftContextRunes + } re := &Regexp{ pattern: pattern, options: c.regexOptions, @@ -44,6 +56,7 @@ func newEngineRegexp(pattern string, c compileConfig, engine RuntimeEngineData) execute: engine.Execute, executeQuick: engine.ExecuteQuick, stringPrefixFilter: engine.StringPrefixFilter, + leftContextRunes: leftContext, } re.initCaches() return re diff --git a/vendor/github.com/dlclark/regexp2/v2/replace.go b/vendor/github.com/dlclark/regexp2/v2/replace.go index 9b965caf4..acf0c66ad 100644 --- a/vendor/github.com/dlclark/regexp2/v2/replace.go +++ b/vendor/github.com/dlclark/regexp2/v2/replace.go @@ -4,6 +4,7 @@ import ( "bytes" "errors" + "github.com/dlclark/regexp2/v2/helpers" "github.com/dlclark/regexp2/v2/syntax" ) @@ -27,6 +28,15 @@ func writeRunes(buf *bytes.Buffer, text []rune, start, end int) { } } +func writeUnmatched(buf *bytes.Buffer, input string, d *decodedInput, start, end int) { + // Equal byte/rune lengths can include invalid UTF-8, which must be re-encoded. + if d.ascii { + buf.WriteString(input[start:end]) + } else { + writeRunes(buf, d.runes, start, end) + } +} + func compactBalancedMatches(m *Match) { for cap := 0; cap < len(m.matchcount); cap++ { limit := m.matchcount[cap] * 2 @@ -87,15 +97,15 @@ func replace(regex *Regexp, data *syntax.ReplacerData, evaluator MatchEvaluator, } buf := &bytes.Buffer{} - text := m.text.runes if !regex.RightToLeft() { prevat := 0 for m != nil { - if m.RuneIndex != prevat { - buf.WriteString(string(text[prevat:m.RuneIndex])) + start, end := matchInputSpan(m) + if start > prevat { + buf.WriteString(input[prevat:start]) } - prevat = m.RuneIndex + m.RuneLength + prevat = end buf.WriteString(evaluator(*m)) count-- @@ -108,18 +118,19 @@ func replace(regex *Regexp, data *syntax.ReplacerData, evaluator MatchEvaluator, } } - if prevat < len(text) { - buf.WriteString(string(text[prevat:])) + if prevat < len(input) { + buf.WriteString(input[prevat:]) } } else { - prevat := len(text) + prevat := len(input) var al []string for m != nil { - if m.RuneIndex+m.RuneLength != prevat { - al = append(al, string(text[m.RuneIndex+m.RuneLength:prevat])) + start, end := matchInputSpan(m) + if end < prevat { + al = append(al, input[end:prevat]) } - prevat = m.RuneIndex + prevat = start al = append(al, evaluator(*m)) count-- @@ -133,7 +144,7 @@ func replace(regex *Regexp, data *syntax.ReplacerData, evaluator MatchEvaluator, } if prevat > 0 { - buf.WriteString(string(text[:prevat])) + buf.WriteString(input[:prevat]) } for i := len(al) - 1; i >= 0; i-- { @@ -144,20 +155,39 @@ func replace(regex *Regexp, data *syntax.ReplacerData, evaluator MatchEvaluator, return buf.String(), nil } +// matchInputSpan returns the UTF-8 byte range of m in its original string input. +func matchInputSpan(m *Match) (start, end int) { + if m.text != nil && m.text.hasStringInput { + start, length := m.ByteRange() + return start, start + length + } + return m.RuneIndex, m.RuneIndex + m.RuneLength +} + func replaceRunnerLTR(regex *Regexp, data *syntax.ReplacerData, input string, startAt, count int) (string, error) { if startAt > len(input) { return "", errors.New("startAt must be less than the length of the input string") } + // Short inputs are cheaper to decode directly. For longer inputs, validate + // startAt before rejecting a miss. Keep the original scan start: anchors + // and replacement rules may need context before the candidate. + if len(input) >= helpers.ASCIISearchMin { + if _, ok, err := regex.findStringMatchStart(input, startAt); err != nil { + return "", err + } else if !ok { + return input, nil + } + } runner := regex.getRunner() - text, runeStart, pooledText := runner.decodeStringWithStart(input, startAt) + d := decodeInput(input, startAt, 0, regex.optimizations.MaxCachedRuneBufferLength, false) + text := d.runes textInfo := newStringMatchText(input, text) defer func() { regex.putRunner(runner) - if pooledText != nil { - pooledRuneBuffers.put(pooledText) - } + d.release() }() + runeStart := d.runeStart if startAt >= 0 && runeStart < 0 { return "", errors.New("startAt must align to the start of a valid rune in the input string") } @@ -165,7 +195,7 @@ func replaceRunnerLTR(regex *Regexp, data *syntax.ReplacerData, input string, st runeStart = 0 } - m, err := runner.scan(text, textInfo, runeStart, -1, true, regex.MatchTimeout) + m, err := runner.scan(text, textInfo, runeStart, runeStart, -1, true, regex.MatchTimeout) if err != nil { return "", err } @@ -184,10 +214,11 @@ func replaceRunnerLTR(regex *Regexp, data *syntax.ReplacerData, input string, st compactBalancedMatches(m) } - if m.RuneIndex != prevat { - writeRunes(buf, text, prevat, m.RuneIndex) + local := m.runeSliceIndex() + if local != prevat { + writeUnmatched(buf, input, &d, prevat, local) } - prevat = m.RuneIndex + m.RuneLength + prevat = local + m.RuneLength replacementImpl(data, buf, m) count-- @@ -195,14 +226,14 @@ func replaceRunnerLTR(regex *Regexp, data *syntax.ReplacerData, input string, st break } - m, err = runner.scan(text, textInfo, m.textpos, m.RuneLength, true, regex.MatchTimeout) + m, err = runner.scan(text, textInfo, m.textpos, m.textpos, m.RuneLength, true, regex.MatchTimeout) if err != nil { return "", err } } if prevat < len(text) { - writeRunes(buf, text, prevat, len(text)) + writeUnmatched(buf, input, &d, prevat, len(text)) } return buf.String(), nil } @@ -213,14 +244,14 @@ func replaceRunnerRTL(regex *Regexp, data *syntax.ReplacerData, input string, st } runner := regex.getRunner() - text, runeStart, pooledText := runner.decodeStringWithStart(input, startAt) + d := decodeInput(input, startAt, 0, regex.optimizations.MaxCachedRuneBufferLength, false) + text := d.runes textInfo := newStringMatchText(input, text) defer func() { regex.putRunner(runner) - if pooledText != nil { - pooledRuneBuffers.put(pooledText) - } + d.release() }() + runeStart := d.runeStart if startAt >= 0 && runeStart < 0 { return "", errors.New("startAt must align to the start of a valid rune in the input string") } @@ -228,7 +259,7 @@ func replaceRunnerRTL(regex *Regexp, data *syntax.ReplacerData, input string, st runeStart = len(text) } - m, err := runner.scan(text, textInfo, runeStart, -1, true, regex.MatchTimeout) + m, err := runner.scan(text, textInfo, runeStart, runeStart, -1, true, regex.MatchTimeout) if err != nil { return "", err } @@ -249,10 +280,16 @@ func replaceRunnerRTL(regex *Regexp, data *syntax.ReplacerData, input string, st compactBalancedMatches(m) } - if m.RuneIndex+m.RuneLength != prevat { - al = append(al, string(text[m.RuneIndex+m.RuneLength:prevat])) + local := m.runeSliceIndex() + if local+m.RuneLength != prevat { + // As in writeUnmatched, only ASCII permits copying original bytes. + if d.ascii { + al = append(al, input[local+m.RuneLength:prevat]) + } else { + al = append(al, string(text[local+m.RuneLength:prevat])) + } } - prevat = m.RuneIndex + prevat = local replacementImplRTL(data, &al, m) count-- @@ -260,14 +297,14 @@ func replaceRunnerRTL(regex *Regexp, data *syntax.ReplacerData, input string, st break } - m, err = runner.scan(text, textInfo, m.textpos, m.RuneLength, true, regex.MatchTimeout) + m, err = runner.scan(text, textInfo, m.textpos, m.textpos, m.RuneLength, true, regex.MatchTimeout) if err != nil { return "", err } } if prevat > 0 { - writeRunes(buf, text, 0, prevat) + writeUnmatched(buf, input, &d, 0, prevat) } for i := len(al) - 1; i >= 0; i-- { buf.WriteString(al[i]) @@ -287,11 +324,12 @@ func replacementImpl(data *syntax.ReplacerData, buf *bytes.Buffer, m *Match) { } else { switch -replaceSpecials - 1 - r { // special insertion patterns case replaceLeftPortion: - for i := 0; i < m.RuneIndex; i++ { + end := m.runeSliceIndex() + for i := 0; i < end; i++ { buf.WriteRune(m.text.runes[i]) } case replaceRightPortion: - for i := m.RuneIndex + m.RuneLength; i < len(m.text.runes); i++ { + for i := m.runeSliceIndex() + m.RuneLength; i < len(m.text.runes); i++ { buf.WriteRune(m.text.runes[i]) } case replaceLastGroup: @@ -309,7 +347,10 @@ func replacementImplRTL(data *syntax.ReplacerData, al *[]string, m *Match) { l := *al buf := &bytes.Buffer{} - for _, r := range data.Rules { + // The caller reverses the complete segment list, so emit each + // replacement's fragments in reverse order as well. + for i := len(data.Rules) - 1; i >= 0; i-- { + r := data.Rules[i] buf.Reset() if r >= 0 { // string lookup l = append(l, data.Strings[r]) @@ -319,11 +360,12 @@ func replacementImplRTL(data *syntax.ReplacerData, al *[]string, m *Match) { } else { switch -replaceSpecials - 1 - r { // special insertion patterns case replaceLeftPortion: - for i := 0; i < m.RuneIndex; i++ { + end := m.runeSliceIndex() + for i := 0; i < end; i++ { buf.WriteRune(m.text.runes[i]) } case replaceRightPortion: - for i := m.RuneIndex + m.RuneLength; i < len(m.text.runes); i++ { + for i := m.runeSliceIndex() + m.RuneLength; i < len(m.text.runes); i++ { buf.WriteRune(m.text.runes[i]) } case replaceLastGroup: diff --git a/vendor/github.com/dlclark/regexp2/v2/runner.go b/vendor/github.com/dlclark/regexp2/v2/runner.go index b70980fc1..58463564e 100644 --- a/vendor/github.com/dlclark/regexp2/v2/runner.go +++ b/vendor/github.com/dlclark/regexp2/v2/runner.go @@ -94,26 +94,12 @@ func (re *Regexp) run(quick bool, textstart, previousMatchLength int, input []ru runner.code = re.quickCode } - return runner.scan(input, textInfo, textstart, previousMatchLength, quick, re.MatchTimeout) + return runner.scan(input, textInfo, textstart, textstart, previousMatchLength, quick, re.MatchTimeout) } -// Scans the string to find the first match. Uses the Match object -// both to feed text in and as a place to store matches that come out. -// -// All the action is in the Go() method. Our -// responsibility is to load up the class members before -// calling Go. -// -// The optimizer can compute a set of candidate starting characters, -// and we could use a separate method Skip() that will quickly scan past -// any characters that we know can't match. -// -// The input slice is passed separately from matchText so quick scans can avoid -// allocating match metadata. When textInfo is nil, successful matches are only -// used as a boolean result and capture text is intentionally unavailable. If -// we collapsed down to just textInfo it would "escape" and hit the GC for fast -// scans without captures. -func (r *Runner) scan(rt []rune, textInfo *matchText, textstart, previousMatchLength int, quick bool, timeout time.Duration) (*Match, error) { +// scan starts at candidate while preserving textstart for \G. Both are rune +// indexes in rt. A nil textInfo allows quick scans to omit capture metadata. +func (r *Runner) scan(rt []rune, textInfo *matchText, textstart, candidate, previousMatchLength int, quick bool, timeout time.Duration) (*Match, error) { r.timeout = timeout r.ignoreTimeout = (time.Duration(math.MaxInt64) == timeout) r.debug = r.re.Debug() @@ -132,8 +118,7 @@ func (r *Runner) scan(rt []rune, textInfo *matchText, textstart, previousMatchLe stoppos = 0 } - r.Runtextpos = textstart - //initted := false + r.Runtextpos = candidate // setup our scanner functions findFirstChar := r.re.findFirstChar @@ -232,7 +217,6 @@ func executeDefault(r *Runner) error { if err := r.goTo(0); err != nil { return err } - for { if r.debug { @@ -258,6 +242,56 @@ func executeDefault(r *Runner) error { } continue + case syntax.Dispatch: + // Dispatch only peeks at the next rune. It consumes it after finding a + // matching branch, so a failed dispatch leaves the input position alone. + if r.forwardchars() < 1 { + break + } + // Pick the next rune in the current execution direction. + pos := r.Runtextpos + if r.rightToLeft { + pos-- + } + ch := r.Runtext[pos] + tableIndex := r.operand(0) + table := &r.code.Dispatches[tableIndex] + branch := -1 + if ch >= 0 && ch < 128 { + if table.ASCII != nil { + // Larger dispatches use a direct ASCII branch lookup. + branch = int(table.ASCII[ch]) - 1 + } else { + // Smaller dispatches use two compact ASCII bitmasks per set. + word := int(ch >> 6) + bit := uint64(1) << (ch & 63) + for i := range table.Sets { + if table.ASCIIMasks[i*2+word]&bit != 0 { + branch = i + break + } + } + } + } else { + // Non-ASCII runes fall back to the complete character sets. + for i, setIndex := range table.Sets { + if r.code.Sets[setIndex].Contains(ch) { + branch = i + break + } + } + } + if branch < 0 { + break + } + // The selected branch starts with this rune, so consume it and jump + // directly to the rest of that branch. + r.Runtextpos += r.bump() + if err := r.goTo(table.Branches[branch]); err != nil { + return err + } + continue + case syntax.Testref: if !r.runmatch.isMatched(r.operand(0)) { break @@ -670,7 +704,7 @@ func executeDefault(r *Runner) error { case syntax.Set: - if r.forwardchars() < 1 || !r.code.Sets[r.operand(0)].CharIn(r.forwardcharnext()) { + if r.forwardchars() < 1 || !r.code.Sets[r.operand(0)].Contains(r.forwardcharnext()) { break } @@ -685,6 +719,13 @@ func executeDefault(r *Runner) error { r.advance(1) continue + case syntax.Grapheme: + if !r.TryMatchGrapheme(r.rightToLeft) { + break + } + r.advance(0) + continue + case syntax.Ref: capnum := r.operand(0) @@ -752,7 +793,7 @@ func executeDefault(r *Runner) error { set := r.code.Sets[r.operand(0)] for c > 0 { - if !set.CharIn(r.forwardcharnext()) { + if !set.Contains(r.forwardcharnext()) { goto BreakBackward } c-- @@ -823,7 +864,7 @@ func executeDefault(r *Runner) error { i := c for ; i > 0; i-- { - if !set.CharIn(r.forwardcharnext()) { + if !set.Contains(r.forwardcharnext()) { r.backwardnext() break } @@ -940,7 +981,7 @@ func executeDefault(r *Runner) error { pos := r.trackPeekN(1) r.textto(pos) - if !r.code.Sets[r.operand(0)].CharIn(r.forwardcharnext()) { + if !r.code.Sets[r.operand(0)].Contains(r.forwardcharnext()) { break } @@ -1059,6 +1100,22 @@ func (r *Runner) textPos() int { return r.Runtextpos } +// TryMatchGrapheme consumes one Unicode extended grapheme cluster in the +// runner's current direction. It is exported for regexp2cg-generated engines. +func (r *Runner) TryMatchGrapheme(rightToLeft bool) bool { + var boundary int + if rightToLeft { + boundary = syntax.PreviousGraphemeClusterBoundary(r.Runtext, r.Runtextpos) + } else { + boundary = syntax.NextGraphemeClusterBoundary(r.Runtext, r.Runtextpos) + } + if boundary < 0 { + return false + } + r.Runtextpos = boundary + return true +} + // push onto the backtracking stack func (r *Runner) trackpos() int { return len(r.runtrack) - r.Runtrackpos @@ -1447,8 +1504,8 @@ func findFirstCharDefault(r *Runner) bool { } else { for i := r.forwardchars(); i > 0; i-- { n := r.forwardcharnext() - //fmt.Printf("%v in %v: %v\n", string(n), set.String(), set.CharIn(n)) - if set.CharIn(n) { + //fmt.Printf("%v in %v: %v\n", string(n), set.String(), set.Contains(n)) + if set.Contains(n) { r.backwardnext() return true } @@ -1720,7 +1777,7 @@ func findLiteralAfterLoopLeftToRight(r *Runner, literal *syntax.LiteralAfterLoop } start := literalIndex - for start > r.Runtextpos && literal.LoopNode.Set.CharIn(r.Runtext[start-1]) { + for start > r.Runtextpos && literal.LoopNode.Set.Contains(r.Runtext[start-1]) { start-- } if hasRequiredLengthAt(r, start) { @@ -1760,7 +1817,7 @@ func findRequiredLandmarkChainLeftToRight(r *Runner, chain *syntax.RequiredLandm if candidate < r.Runtextpos { candidate = r.Runtextpos } - for candidate > r.Runtextpos && chain.LeadingLoopSet.CharIn(r.Runtext[candidate-1]) { + for candidate > r.Runtextpos && chain.LeadingLoopSet.Contains(r.Runtext[candidate-1]) { candidate-- } if hasRequiredLengthAt(r, candidate) { @@ -1794,7 +1851,7 @@ func findNextRequiredLandmarkRunes(input []rune, startAt, endAt int, landmark sy func requiredLandmarkAlternativeMatch(input []rune, start, endAt int, alt syntax.RequiredLandmarkAlternative) (requiredLandmarkMatch, bool) { if alt.RequireWhitespaceBefore && - (start == 0 || alt.LeadingWhitespaceSet == nil || !alt.LeadingWhitespaceSet.CharIn(input[start-1])) { + (start == 0 || alt.LeadingWhitespaceSet == nil || !alt.LeadingWhitespaceSet.Contains(input[start-1])) { return requiredLandmarkMatch{}, false } @@ -1810,7 +1867,7 @@ func requiredLandmarkAlternativeMatch(input []rune, start, endAt int, alt syntax if maxRepeat <= 0 { maxRepeat = alt.MinRepeat } - for end < endAt && end-start < maxRepeat && alt.Set.CharIn(input[end]) { + for end < endAt && end-start < maxRepeat && alt.Set.Contains(input[end]) { end++ } if end-start < alt.MinRepeat { @@ -1821,12 +1878,12 @@ func requiredLandmarkAlternativeMatch(input []rune, start, endAt int, alt syntax } if alt.RequireWhitespaceAfter && - (end >= endAt || alt.TrailingWhitespaceSet == nil || !alt.TrailingWhitespaceSet.CharIn(input[end])) { + (end >= endAt || alt.TrailingWhitespaceSet == nil || !alt.TrailingWhitespaceSet.Contains(input[end])) { return requiredLandmarkMatch{}, false } matchStart := start - for matchStart > 0 && alt.LeadingWhitespaceSet != nil && alt.LeadingWhitespaceSet.CharIn(input[matchStart-1]) { + for matchStart > 0 && alt.LeadingWhitespaceSet != nil && alt.LeadingWhitespaceSet.Contains(input[matchStart-1]) { matchStart-- } return requiredLandmarkMatch{Start: matchStart, CoreStart: start, End: end}, true @@ -1913,7 +1970,7 @@ func charInFixedDistanceSet(set syntax.FixedDistanceSet, ch rune) bool { } return found } - return set.Set != nil && set.Set.CharIn(ch) + return set.Set != nil && set.Set.Contains(ch) } func latestPossibleStart(r *Runner) int { @@ -1999,9 +2056,7 @@ func (r *Runner) tidyMatch(quick bool) *Match { m.textpos = r.Runtextpos if m.matchcount[0] > 0 { interval := m.matches[0] - // bytes indices aren't used so just use fast path - m.RuneIndex = interval[0] - m.RuneLength = interval[1] + setCaptureFields(&m.Capture, interval[0], interval[1]) } return m } @@ -2173,36 +2228,6 @@ func (r *Runner) initTrackCount() { } } -// decodeString converts s to []rune using a shared size-classed buffer pool when -// allowed by the regexp optimization settings. Pooled slices must be returned -// after the runner is done with them. -func (r *Runner) decodeString(s string) ([]rune, *[]rune) { - buf, pooled := pooledRuneBuffers.get(len(s), r.re.optimizations.MaxCachedRuneBufferLength) - n := 0 - for _, ch := range s { - buf[n] = ch - n++ - } - return buf[:n], pooled -} - -func (r *Runner) decodeStringWithStart(s string, startAt int) (runes []rune, runeStart int, pooled *[]rune) { - buf, pooled := pooledRuneBuffers.get(len(s), r.re.optimizations.MaxCachedRuneBufferLength) - n := 0 - runeStart = -1 - for strIdx, ch := range s { - if startAt >= 0 && strIdx == startAt { - runeStart = n - } - buf[n] = ch - n++ - } - if startAt >= 0 && startAt == len(s) { - runeStart = n - } - return buf[:n], runeStart, pooled -} - // getRunner returns a runner to use for matching re. func (re *Regexp) getRunner() *Runner { if re.runnerPool == nil { diff --git a/vendor/github.com/dlclark/regexp2/v2/split.go b/vendor/github.com/dlclark/regexp2/v2/split.go index 1dbe0dcd1..3c1233544 100644 --- a/vendor/github.com/dlclark/regexp2/v2/split.go +++ b/vendor/github.com/dlclark/regexp2/v2/split.go @@ -3,6 +3,7 @@ package regexp2 import ( "errors" "math" + "slices" ) // Split splits the given input string using the pattern and returns @@ -30,24 +31,58 @@ func (re *Regexp) Split(input string, count int) ([]string, error) { count = math.MaxInt } - // iterate through the matches + startAt, ok, err := re.findStringMatchStart(input, -1) + if err != nil { + return nil, err + } + if !ok { + return []string{input}, nil + } + d := decodeInput(input, startAt, re.decodeFrom(input, startAt), re.optimizations.MaxCachedRuneBufferLength, false) + runner := re.getRunner() + defer func() { + re.putRunner(runner) + d.release() + }() + text := newStringMatchTextAt(input, d.runes, 0, d.byteOffset) + + // Keep captures in the reusable match, but only materialize output strings. + // Passing text also ensures registered engines use their capturing program. priorIndex := 0 + if re.RightToLeft() { + priorIndex = len(input) + } var retVal []string - var txt []rune + matched := false - m, err := re.FindStringMatch(input) + origin := re.stringSearchOrigin(input, -1, d.runeStart) + m, err := runner.scan(d.runes, text, origin, d.runeStart, -1, true, re.MatchTimeout) - for ; m != nil && count > 0; m, err = re.FindNextMatch(m) { - txt = m.text.runes - // if we have an m, we don't have an err - // append our match - retVal = append(retVal, string(txt[priorIndex:m.RuneIndex])) - // append any capture groups, skipping group 0 - gs := m.Groups() - for i := 1; i < len(gs); i++ { - retVal = append(retVal, gs[i].String()) + for ; m != nil && count > 0; m, err = runner.scan(d.runes, text, m.textpos, m.textpos, m.RuneLength, true, re.MatchTimeout) { + if m.balancing { + compactBalancedMatches(m) + } + matched = true + start, end := matchInputSpan(m) + if re.RightToLeft() { + retVal = append(retVal, input[end:priorIndex]) + } else { + retVal = append(retVal, input[priorIndex:start]) + } + // Preserve group order and empty strings for unmatched groups without + // allocating Group objects or their capture histories. + for group := 1; group < len(m.matchcount); group++ { + value := "" + if m.matchcount[group] > 0 { + capture := newCapture(text, m.matchIndex(group), m.matchLength(group)) + value = capture.String() + } + retVal = append(retVal, value) + } + priorIndex = end + if re.RightToLeft() { + priorIndex = start } - priorIndex = m.RuneIndex + m.RuneLength count-- } @@ -55,13 +90,15 @@ func (re *Regexp) Split(input string, count int) ([]string, error) { return nil, err } - if txt == nil { - // we never matched, return the original string + if !matched { return []string{input}, nil } - // append our remainder - retVal = append(retVal, string(txt[priorIndex:])) - + if re.RightToLeft() { + retVal = append(retVal, input[:priorIndex]) + slices.Reverse(retVal) + } else { + retVal = append(retVal, input[priorIndex:]) + } return retVal, nil } diff --git a/vendor/github.com/dlclark/regexp2/v2/stringprefixfilter.go b/vendor/github.com/dlclark/regexp2/v2/stringprefixfilter.go index 080b8c290..a041ad239 100644 --- a/vendor/github.com/dlclark/regexp2/v2/stringprefixfilter.go +++ b/vendor/github.com/dlclark/regexp2/v2/stringprefixfilter.go @@ -140,6 +140,26 @@ func (s asciiSetStringScanner) index(input string) int { return -1 } +// A literal U+FFFD also matches invalid UTF-8 bytes once decoded. Keep the +// byte filter for valid strings, and let the rune engine handle invalid input. +// Ordinary literals return the original filter without a per-search check. +func withRuneErrorFallback(filter StringPrefixFilter, literals ...string) StringPrefixFilter { + for _, literal := range literals { + if strings.ContainsRune(literal, utf8.RuneError) { + return func(input string, startAt int) (int, bool) { + if startAt < 0 || startAt > len(input) { + return 0, false + } + if !utf8.ValidString(input[startAt:]) { + return startAt, true + } + return filter(input, startAt) + } + } + } + return filter +} + func stringIndexPrefixFilter(prefix string, ignoreCase bool, minRequiredLength int) StringPrefixFilter { if prefix == "" { return nil @@ -148,7 +168,7 @@ func stringIndexPrefixFilter(prefix string, ignoreCase bool, minRequiredLength i return nil } - return func(input string, startAt int) (candidateByteIndex int, ok bool) { + return withRuneErrorFallback(func(input string, startAt int) (candidateByteIndex int, ok bool) { if !hasMinRequiredBytes(input, startAt, minRequiredLength) { return 0, false } @@ -163,7 +183,7 @@ func stringIndexPrefixFilter(prefix string, ignoreCase bool, minRequiredLength i return 0, false } return startAt + offset, true - } + }, prefix) } func stringIndexPrefixesFilter(prefixes []string, ignoreCase bool, minRequiredLength int) StringPrefixFilter { @@ -182,9 +202,9 @@ func stringIndexPrefixesFilter(prefixes []string, ignoreCase bool, minRequiredLe return filter.index } - return func(input string, startAt int) (candidateByteIndex int, ok bool) { + return withRuneErrorFallback(func(input string, startAt int) (candidateByteIndex int, ok bool) { return indexAnyPrefixFallback(input, startAt, prefixes, ignoreCase, minRequiredLength) - } + }, prefixes...) } func indexAnyPrefixFallback(input string, startAt int, prefixes []string, ignoreCase bool, minRequiredLength int) (candidateByteIndex int, ok bool) { @@ -322,7 +342,7 @@ func stringFixedDistanceStringFilter(literal string, distance, minRequiredLength return nil } - return func(input string, startAt int) (candidateByteIndex int, ok bool) { + return withRuneErrorFallback(func(input string, startAt int) (candidateByteIndex int, ok bool) { if !hasMinRequiredBytes(input, startAt, minRequiredLength) { return 0, false } @@ -344,7 +364,7 @@ func stringFixedDistanceStringFilter(literal string, distance, minRequiredLength searchAt = literalIndex + 1 } return 0, false - } + }, literal) } func stringLiteralAfterLoopFilter(literal *syntax.LiteralAfterLoop, minRequiredLength int) StringPrefixFilter { @@ -355,7 +375,7 @@ func stringLiteralAfterLoopFilter(literal *syntax.LiteralAfterLoop, minRequiredL return nil } - return func(input string, startAt int) (candidateByteIndex int, ok bool) { + return withRuneErrorFallback(func(input string, startAt int) (candidateByteIndex int, ok bool) { if !hasMinRequiredBytes(input, startAt, minRequiredLength) { return 0, false } @@ -363,7 +383,7 @@ func stringLiteralAfterLoopFilter(literal *syntax.LiteralAfterLoop, minRequiredL return 0, false } return startAt, true - } + }, literal.String) } func stringHasLiteralAfterLoop(input string, searchAt int, literal *syntax.LiteralAfterLoop) bool { diff --git a/vendor/github.com/dlclark/regexp2/v2/syntax/charclass.go b/vendor/github.com/dlclark/regexp2/v2/syntax/charclass.go index b00fc9ad8..30f61fa11 100644 --- a/vendor/github.com/dlclark/regexp2/v2/syntax/charclass.go +++ b/vendor/github.com/dlclark/regexp2/v2/syntax/charclass.go @@ -295,13 +295,20 @@ func NewCharSetRuntime(buf string) CharSet { // CharIn returns true if the rune is in our character set (either ranges or categories). // It handles negations and subtracted sub-charsets. func (c CharSet) CharIn(ch rune) bool { + return c.Contains(ch) +} + +// Contains reports whether ch is in the character set, including negation and +// subtraction. It is equivalent to CharIn but avoids copying the set on each +// call when testing many runes. +func (c *CharSet) Contains(ch rune) bool { if ch >= 0 && ch < 128 && c.ascii != nil { return (c.ascii.bits[ch/64] & (1 << (uint(ch) % 64))) != 0 } return c.charInSlow(ch) } -func (c CharSet) charInSlow(ch rune) bool { +func (c *CharSet) charInSlow(ch rune) bool { val := false // in s && !s.subtracted @@ -346,7 +353,7 @@ func (c CharSet) charInSlow(ch rune) bool { // get subtracted recurse if val && c.sub != nil { - val = !c.sub.CharIn(ch) + val = !c.sub.Contains(ch) } //log.Printf("Char '%v' in %v == %v", string(ch), c.String(), val) diff --git a/vendor/github.com/dlclark/regexp2/v2/syntax/code.go b/vendor/github.com/dlclark/regexp2/v2/syntax/code.go index 405cd6c22..69cad9661 100644 --- a/vendor/github.com/dlclark/regexp2/v2/syntax/code.go +++ b/vendor/github.com/dlclark/regexp2/v2/syntax/code.go @@ -91,6 +91,11 @@ const ( Setloopatomic InstOp = 45 // Updates the bumpalong position to the current position. UpdateBumpalong InstOp = 46 + // Matches one Unicode extended grapheme cluster (\X). + Grapheme InstOp = 47 + // Selects and consumes the next character using a disjoint branch table. + // Operand 0 is an index into Code.Dispatches. + Dispatch InstOp = 48 // Modifiers for alternate modes @@ -105,6 +110,7 @@ type Code struct { Codes []int // the code Strings [][]rune // string table Sets []*CharSet //character set table + Dispatches []DispatchTable // shared match tables for deterministic alternations TrackCount int // how many instructions use backtracking Caps map[int]int // mapping of user group numbers -> impl group slots Capsize int // number of impl group slots @@ -114,7 +120,23 @@ type Code struct { RightToLeft bool // true if right to left FindOptimizations *FindOptimizations // analyzed candidate search strategy QuickCodes []int // bool-only code with unobservable captures removed + QuickDispatches []DispatchTable // lightweight tables targeting QuickCodes CaptureSlotInUse []bool // capture slots observable by the pattern itself during quick matches + // LeftContextRunes is how many runes before a candidate start matching may + // inspect. 0 means none, 1 means a single previous rune (or slack so ^/\A + // do not see the candidate as the origin), and -1 means do not slice + // (lookbehind or \G). + LeftContextRunes int +} + +// DispatchTable maps disjoint character sets to branch indices. Larger tables +// use a direct ASCII lookup, small tables use compact masks, and non-ASCII +// runes inspect the full sets. +type DispatchTable struct { + Sets []int + Branches []int + ASCII *[128]uint16 // entry index + 1; zero means no branch + ASCIIMasks []uint64 // two membership words per branch when ASCII is nil } // captureSlotsInUse returns the capture slots whose values can affect matching. @@ -190,11 +212,11 @@ func opcodeSize(op InstOp) int { switch op { case Nothing, Bol, Eol, Boundary, Nonboundary, ECMABoundary, NonECMABoundary, Beginning, Start, EndZ, - End, Nullmark, Setmark, Getmark, Setjump, Backjump, Forejump, Stop, UpdateBumpalong: + End, Nullmark, Setmark, Getmark, Setjump, Backjump, Forejump, Stop, UpdateBumpalong, Grapheme: return 1 case One, Notone, Multi, Ref, Testref, Goto, Nullcount, Setcount, Lazybranch, Branchmark, Lazybranchmark, - Prune, Set: + Prune, Set, Dispatch: return 2 case Capturemark, Branchcount, Lazybranchcount, Onerep, Notonerep, Oneloop, Notoneloop, Onelazy, Notonelazy, @@ -221,7 +243,7 @@ var codeStr = []string{ "Prune", "Stop", "ECMABoundary", "NonECMABoundary", "Oneloopatomic", "Notoneloopatomic", "Setloopatomic", - "Bumpalong", + "Bumpalong", "Grapheme", "Dispatch", } func operatorDescription(op InstOp) string { @@ -268,6 +290,16 @@ func (c *Code) OpcodeDescription(offset int) string { buf.WriteString("Set = ") buf.WriteString(c.Sets[c.Codes[offset+1]].String()) + case Dispatch: + tableIndex := c.Codes[offset+1] + fmt.Fprintf(buf, "Table = %d", tableIndex) + if tableIndex >= 0 && tableIndex < len(c.Dispatches) { + table := &c.Dispatches[tableIndex] + for i, setIndex := range table.Sets { + fmt.Fprintf(buf, ", %s -> %d", c.Sets[setIndex].String(), table.Branches[i]) + } + } + case Multi: fmt.Fprintf(buf, "String = %s", string(c.Strings[c.Codes[offset+1]])) diff --git a/vendor/github.com/dlclark/regexp2/v2/syntax/grapheme.go b/vendor/github.com/dlclark/regexp2/v2/syntax/grapheme.go new file mode 100644 index 000000000..c4faf3553 --- /dev/null +++ b/vendor/github.com/dlclark/regexp2/v2/syntax/grapheme.go @@ -0,0 +1,294 @@ +package syntax + +import "unicode" + +type graphemeBreakClass uint8 + +const ( + graphemeOther graphemeBreakClass = iota + graphemeCR + graphemeLF + graphemeControl + graphemeExtend + graphemeZWJ + graphemeRegionalIndicator + graphemePrepend + graphemeSpacingMark + graphemeL + graphemeV + graphemeT + graphemeLV + graphemeLVT +) + +type indicConjunctBreakClass uint8 + +const ( + indicNone indicConjunctBreakClass = iota + indicConsonant + indicExtend + indicLinker +) + +type graphemeProperties struct { + breakClass graphemeBreakClass + indicClass indicConjunctBreakClass + extendedPictographic bool +} + +// NextGraphemeClusterBoundary returns the first extended-grapheme boundary +// after start, or -1 when start is not a valid input position. It implements +// the Unicode 17 rules from UAX #29 with a small state machine, avoiding the +// backtracking and repeated character-class probes of an equivalent regexp. +func NextGraphemeClusterBoundary(text []rune, start int) int { + if start < 0 || start >= len(text) { + return -1 + } + + previous := graphemePropertiesFor(text[start]) + state := graphemeForwardState{} + state.consume(previous) + + for pos := start + 1; pos < len(text); pos++ { + current := graphemePropertiesFor(text[pos]) + if isGraphemeBoundaryForward(previous.breakClass, current, state) { + return pos + } + state.consume(current) + previous = current + } + return len(text) +} + +// PreviousGraphemeClusterBoundary returns the first extended-grapheme boundary +// before end, or -1 when end is not a valid input position. +func PreviousGraphemeClusterBoundary(text []rune, end int) int { + if end <= 0 || end > len(text) { + return -1 + } + for pos := end - 1; pos > 0; pos-- { + if isGraphemeBoundary(text, pos) { + return pos + } + } + return 0 +} + +type graphemeForwardState struct { + regionalIndicatorCount int + extendedPictographicRun bool + zwjAfterPictographic bool + indicConsonantRun bool + indicLinkerSeen bool +} + +func (s *graphemeForwardState) consume(properties graphemeProperties) { + if properties.breakClass == graphemeRegionalIndicator { + s.regionalIndicatorCount++ + } else { + s.regionalIndicatorCount = 0 + } + + if properties.breakClass == graphemeZWJ { + s.zwjAfterPictographic = s.extendedPictographicRun + } else { + s.zwjAfterPictographic = false + } + if properties.extendedPictographic { + s.extendedPictographicRun = true + } else if properties.breakClass != graphemeExtend { + s.extendedPictographicRun = false + } + + switch properties.indicClass { + case indicConsonant: + s.indicConsonantRun = true + s.indicLinkerSeen = false + case indicExtend: + // Extend preserves a preceding consonant/linker run. + case indicLinker: + if s.indicConsonantRun { + s.indicLinkerSeen = true + } + default: + s.indicConsonantRun = false + s.indicLinkerSeen = false + } +} + +func isGraphemeBoundaryForward(previous graphemeBreakClass, current graphemeProperties, state graphemeForwardState) bool { + if previous == graphemeCR && current.breakClass == graphemeLF { // GB3 + return false + } + if isGraphemeControl(previous) || isGraphemeControl(current.breakClass) { // GB4, GB5 + return true + } + if hangulNoBreak(previous, current.breakClass) { // GB6, GB7, GB8 + return false + } + if current.breakClass == graphemeExtend || current.breakClass == graphemeZWJ || current.breakClass == graphemeSpacingMark { // GB9, GB9a + return false + } + if previous == graphemePrepend { // GB9b + return false + } + if current.indicClass == indicConsonant && state.indicConsonantRun && state.indicLinkerSeen { // GB9c + return false + } + if current.extendedPictographic && state.zwjAfterPictographic { // GB11 + return false + } + if previous == graphemeRegionalIndicator && current.breakClass == graphemeRegionalIndicator && state.regionalIndicatorCount%2 == 1 { // GB12, GB13 + return false + } + return true +} + +func isGraphemeBoundary(text []rune, pos int) bool { + previous := graphemePropertiesFor(text[pos-1]) + current := graphemePropertiesFor(text[pos]) + if previous.breakClass == graphemeCR && current.breakClass == graphemeLF { // GB3 + return false + } + if isGraphemeControl(previous.breakClass) || isGraphemeControl(current.breakClass) { // GB4, GB5 + return true + } + if hangulNoBreak(previous.breakClass, current.breakClass) { // GB6, GB7, GB8 + return false + } + if current.breakClass == graphemeExtend || current.breakClass == graphemeZWJ || current.breakClass == graphemeSpacingMark { // GB9, GB9a + return false + } + if previous.breakClass == graphemePrepend { // GB9b + return false + } + if current.indicClass == indicConsonant && hasIndicConjunctBefore(text, pos) { // GB9c + return false + } + if current.extendedPictographic && hasExtendedPictographicZWJBefore(text, pos) { // GB11 + return false + } + if previous.breakClass == graphemeRegionalIndicator && current.breakClass == graphemeRegionalIndicator { // GB12, GB13 + count := 0 + for i := pos - 1; i >= 0 && graphemeClass(text[i]) == graphemeRegionalIndicator; i-- { + count++ + } + return count%2 == 0 + } + return true +} + +func hasIndicConjunctBefore(text []rune, pos int) bool { + linkerSeen := false + for i := pos - 1; i >= 0; i-- { + switch indicClass(text[i]) { + case indicExtend: + continue + case indicLinker: + linkerSeen = true + continue + case indicConsonant: + return linkerSeen + default: + return false + } + } + return false +} + +func hasExtendedPictographicZWJBefore(text []rune, pos int) bool { + i := pos - 1 + if i < 0 || graphemeClass(text[i]) != graphemeZWJ { + return false + } + for i--; i >= 0 && graphemeClass(text[i]) == graphemeExtend; i-- { + } + return i >= 0 && unicode.Is(unicodeAliasExtended_Pictographic, text[i]) +} + +func isGraphemeControl(class graphemeBreakClass) bool { + return class == graphemeCR || class == graphemeLF || class == graphemeControl +} + +func hangulNoBreak(previous, current graphemeBreakClass) bool { + return previous == graphemeL && (current == graphemeL || current == graphemeV || current == graphemeLV || current == graphemeLVT) || + (previous == graphemeLV || previous == graphemeV) && (current == graphemeV || current == graphemeT) || + (previous == graphemeLVT || previous == graphemeT) && current == graphemeT +} + +func indicClass(ch rune) indicConjunctBreakClass { + if ch < 0x300 { + return indicNone + } + if unicode.Is(unicodeAliasIndic_Conjunct_Break_Consonant, ch) { + return indicConsonant + } + if unicode.Is(unicodeAliasIndic_Conjunct_Break_Linker, ch) { + return indicLinker + } + if unicode.Is(unicodeAliasIndic_Conjunct_Break_Extend, ch) { + return indicExtend + } + return indicNone +} + +func graphemePropertiesFor(ch rune) graphemeProperties { + if ch <= unicode.MaxASCII { + return graphemeProperties{breakClass: graphemeClass(ch)} + } + return graphemeProperties{ + breakClass: graphemeClass(ch), + indicClass: indicClass(ch), + extendedPictographic: ch >= 0xA9 && unicode.Is(unicodeAliasExtended_Pictographic, ch), + } +} + +func graphemeClass(ch rune) graphemeBreakClass { + if ch <= unicode.MaxASCII { + switch ch { + case '\r': + return graphemeCR + case '\n': + return graphemeLF + default: + if ch < ' ' || ch == 0x7F { + return graphemeControl + } + return graphemeOther + } + } + if ch == 0x200D { + return graphemeZWJ + } + if ch >= 0x1F1E6 && ch <= 0x1F1FF { + return graphemeRegionalIndicator + } + if ch >= 0xAC00 && ch <= 0xD7A3 { + if (ch-0xAC00)%28 == 0 { + return graphemeLV + } + return graphemeLVT + } + if ch >= 0x1100 && ch <= 0x115F || ch >= 0xA960 && ch <= 0xA97C { + return graphemeL + } + if ch >= 0x1160 && ch <= 0x11A7 || ch >= 0xD7B0 && ch <= 0xD7C6 { + return graphemeV + } + if ch >= 0x11A8 && ch <= 0x11FF || ch >= 0xD7CB && ch <= 0xD7FB { + return graphemeT + } + if unicode.Is(unicodeAliasGrapheme_Cluster_Break_Control, ch) { + return graphemeControl + } + if unicode.Is(unicodeAliasGrapheme_Cluster_Break_Extend, ch) { + return graphemeExtend + } + if unicode.Is(unicodeAliasGrapheme_Cluster_Break_Prepend, ch) { + return graphemePrepend + } + if unicode.Is(unicodeAliasGrapheme_Cluster_Break_SpacingMark, ch) { + return graphemeSpacingMark + } + return graphemeOther +} diff --git a/vendor/github.com/dlclark/regexp2/v2/syntax/optimizations.go b/vendor/github.com/dlclark/regexp2/v2/syntax/optimizations.go index 8b726891e..67d77539b 100644 --- a/vendor/github.com/dlclark/regexp2/v2/syntax/optimizations.go +++ b/vendor/github.com/dlclark/regexp2/v2/syntax/optimizations.go @@ -11,20 +11,20 @@ type FindOptimizations struct { rightToLeft bool asciiLookups [][]uint - FindMode FindNextStartingPositionMode - LeadingAnchor NodeType - TrailingAnchor NodeType - MinRequiredLength int - MaxPossibleLength int - LeadingPrefix string - LeadingPrefixes []string - LeadingPrefixesRunes [][]rune + FindMode FindNextStartingPositionMode + LeadingAnchor NodeType + TrailingAnchor NodeType + MinRequiredLength int + MaxPossibleLength int + LeadingPrefix string + LeadingPrefixes []string + LeadingPrefixesRunes [][]rune //LeadingStrings *helpers.StringSearchValues - FixedDistanceLiteral FixedDistanceLiteral - FixedDistanceSets []FixedDistanceSet - LiteralAfterLoop *LiteralAfterLoop - LandmarkChain *RequiredLandmarkChain + FixedDistanceLiteral FixedDistanceLiteral + FixedDistanceSets []FixedDistanceSet + LiteralAfterLoop *LiteralAfterLoop + LandmarkChain *RequiredLandmarkChain LeadingPrefixFirstRunes []rune } @@ -461,9 +461,16 @@ func newFindOptimizationsForNode(root *RegexNode, opt ParseOptions, isLeadingPar // We're now left-to-right only and looking for multiple prefixes and/or sets. - // If there are multiple leading strings, we can search for any of them. - // this works in the interpreter, but we avoid it due to additional cost during construction - + // Multiple leading strings let the finder jump between candidate prefixes. + // Case-sensitive prefixes are cheap to collect and help the interpreter. + // Case-insensitive prefix explosion is still limited to code generation. + if prefixes := findPrefixes(root, false); len(prefixes) > 1 { + f.LeadingPrefixes = prefixes + f.LeadingPrefixesRunes = toRunePrefixes(prefixes) + f.LeadingPrefixFirstRunes = leadingPrefixFirstRunes(f.LeadingPrefixesRunes) + f.FindMode = LeadingStrings_LeftToRight + return f + } if !interpreter { ciPrefixes := findPrefixes(root, true) if len(ciPrefixes) > 1 { @@ -471,10 +478,6 @@ func newFindOptimizationsForNode(root *RegexNode, opt ParseOptions, isLeadingPar f.LeadingPrefixesRunes = toRunePrefixes(ciPrefixes) f.LeadingPrefixFirstRunes = leadingPrefixFirstRunes(f.LeadingPrefixesRunes) f.FindMode = LeadingStrings_OrdinalIgnoreCase_LeftToRight - /*SYSTEM_TEXT_REGULAREXPRESSIONS - if usesRfoTryFind { - f.LeadingStrings = helpers.NewSearchValues(f.LeadingPrefixes, true) - }*/ return f } } @@ -517,20 +520,6 @@ func newFindOptimizationsForNode(root *RegexNode, opt ParseOptions, isLeadingPar // In some searches, we may use multiple sets, so we want the subsequent ones to also be the efficiency runners-up. slices.SortFunc(fixedDistanceSets, compareFixedDistanceSetsByQuality) - // If the best fixed-distance set is composed of high-frequency characters, IndexOfAny on - // those characters is likely to match too many positions. Prefer a case-sensitive - // multi-prefix search when one is available. - if !interpreter && !mayContainCaseInsensitiveMatching(root) && hasHighFrequencyChars(fixedDistanceSets[0]) { - caseSensitivePrefixes := findPrefixes(root, false) - if len(caseSensitivePrefixes) > 1 { - f.LeadingPrefixes = caseSensitivePrefixes - f.LeadingPrefixesRunes = toRunePrefixes(caseSensitivePrefixes) - f.LeadingPrefixFirstRunes = leadingPrefixFirstRunes(f.LeadingPrefixesRunes) - f.FindMode = LeadingStrings_LeftToRight - return f - } - } - // If there is no literal after the loop, use whatever set we got. // If there is a literal after the loop, consider it to be better than a negated set and better than a set with many characters. if literalAfterLoop == nil || (len(fixedDistanceSets[0].Chars) > 0 && !fixedDistanceSets[0].Negated) { diff --git a/vendor/github.com/dlclark/regexp2/v2/syntax/parser.go b/vendor/github.com/dlclark/regexp2/v2/syntax/parser.go index 9e9029a8c..0e8428284 100644 --- a/vendor/github.com/dlclark/regexp2/v2/syntax/parser.go +++ b/vendor/github.com/dlclark/regexp2/v2/syntax/parser.go @@ -636,11 +636,16 @@ func (p *parser) scanRegex() (*RegexNode, error) { } case '\\': + quoted := !p.useOptionE() && p.charsRight() > 0 && p.rightChar(0) == 'Q' n, err := p.scanBackslash(false) if err != nil { return nil, err } - p.addUnitNode(n) + if quoted { + p.addQuotedUnit(n) + } else { + p.addUnitNode(n) + } case '^': if p.useOptionM() { @@ -702,7 +707,7 @@ func (p *parser) scanRegex() (*RegexNode, error) { // Handle quantifiers for p.unit != nil { var min, max int - var lazy bool + var lazy, possessive bool switch ch { case '*': @@ -753,18 +758,19 @@ func (p *parser) scanRegex() (*RegexNode, error) { return nil, err } - if p.charsRight() == 0 || p.rightChar(0) != '?' { - lazy = false - } else { + if p.charsRight() > 0 && p.rightChar(0) == '?' { p.moveRight(1) lazy = true + } else if p.charsRight() > 0 && p.rightChar(0) == '+' && !p.useOptionE() { + p.moveRight(1) + possessive = true } if min > max { return nil, p.getErr(ErrInvalidRepeatSize) } - p.addConcatenate3(lazy, min, max) + p.addConcatenate3(lazy, possessive, min, max) } ContinueOuterScan: @@ -1280,6 +1286,37 @@ func (p *parser) scanBackslash(scanOnly bool) (*RegexNode, error) { } switch ch := p.rightChar(0); ch { + case 'Q': + if p.useOptionE() { + return p.scanBasicBackslash(scanOnly) + } + p.moveRight(1) + quoted := p.scanQuoted() + if scanOnly { + return nil, nil + } + return newRegexNodeStr(NtMulti, p.options&^IgnoreCase, quoted), nil + + case 'R': + if p.useOptionE() || p.useRE2() { + return p.scanBasicBackslash(scanOnly) + } + p.moveRight(1) + if scanOnly { + return nil, nil + } + return newUnicodeNewlineNode(p.options), nil + + case 'X': + if p.useOptionE() || p.useRE2() { + return p.scanBasicBackslash(scanOnly) + } + p.moveRight(1) + if scanOnly { + return nil, nil + } + return newRegexNode(NtGrapheme, p.options), nil + case 'b', 'B', 'A', 'G', 'Z', 'z': p.moveRight(1) return newRegexNode(p.typeFromCode(ch), p.options), nil @@ -1354,6 +1391,58 @@ func (p *parser) scanBackslash(scanOnly bool) (*RegexNode, error) { } } +// newUnicodeNewlineNode constructs \R from existing general-purpose nodes. +// Its branches have disjoint starting sets, and the optional LF is atomic, so +// reduction can remove the outer atomic wrapper without changing semantics. +func newUnicodeNewlineNode(options RegexOptions) *RegexNode { + options &^= IgnoreCase + + lead, optional := '\r', '\n' + if options&RightToLeft != 0 { + // Stored concatenations are already in execution order. In RTL, consume + // LF first and then the optional preceding CR. + lead, optional = '\n', '\r' + } + + newlines := &CharSet{} + for _, ch := range []rune{'\n', '\v', '\f', '\u0085', '\u2028', '\u2029'} { + if ch != lead { + newlines.addChar(ch) + } + } + if '\r' != lead { + newlines.addChar('\r') + } + + crlf := newRegexNode(NtConcatenate, options) + crlf.addChild(newRegexNodeCh(NtOne, options, lead)) + crlf.addChild(newRegexNodeCh(NtOne, options, optional).makeQuantifier(false, 0, 1)) + + alternate := newRegexNode(NtAlternate, options) + alternate.addChild(newRegexNodeSet(NtSet, options, newlines)) + alternate.addChild(crlf) + + atomic := newRegexNode(NtAtomic, options) + atomic.addChild(alternate) + return atomic +} + +// scanQuoted scans the literal text after \Q through the next \E, or through +// the end of the pattern when there is no terminator. +func (p *parser) scanQuoted() []rune { + start := p.textpos() + var quoted []rune + for p.charsRight() > 0 { + if p.rightChar(0) == '\\' && p.charsRight() > 1 && p.rightChar(1) == 'E' { + quoted = append(quoted, p.pattern[start:p.textpos()]...) + p.moveRight(2) + return quoted + } + p.moveRight(1) + } + return append(quoted, p.pattern[start:p.textpos()]...) +} + // Scans \-style backreferences and character escapes func (p *parser) scanBasicBackslash(scanOnly bool) (*RegexNode, error) { if p.charsRight() == 0 { @@ -1684,6 +1773,7 @@ func (p *parser) scanCharSet(caseInsensitive, scanOnly bool) (*CharSet, error) { inRange := false firstChar := true closed := false + var quoted []rune var cc *CharSet if !scanOnly { @@ -1697,11 +1787,33 @@ func (p *parser) scanCharSet(caseInsensitive, scanOnly bool) (*CharSet, error) { } } - for ; p.charsRight() > 0; firstChar = false { + for ; p.charsRight() > 0 || len(quoted) > 0; firstChar = false { fTranslatedChar := false - ch = p.moveRightGetChar() + for { + if len(quoted) > 0 { + ch = quoted[0] + quoted = quoted[1:] + fTranslatedChar = true + break + } + ch = p.moveRightGetChar() + if ch == '\\' && !p.useOptionE() && p.charsRight() > 0 && p.rightChar(0) == 'Q' { + p.moveRight(1) + quoted = p.scanQuoted() + if len(quoted) == 0 { + if p.charsRight() == 0 { + break + } + continue + } + continue + } + break + } if ch == ']' { - if !firstChar { + if fTranslatedChar { + // A quoted closing bracket is an ordinary class member. + } else if !firstChar { closed = true break } else if p.useOptionE() { @@ -1712,7 +1824,7 @@ func (p *parser) scanCharSet(caseInsensitive, scanOnly bool) (*CharSet, error) { break } - } else if ch == '\\' && p.charsRight() > 0 { + } else if ch == '\\' && !fTranslatedChar && p.charsRight() > 0 { switch ch = p.moveRightGetChar(); ch { case 'D', 'd': if !scanOnly { @@ -1815,7 +1927,7 @@ func (p *parser) scanCharSet(caseInsensitive, scanOnly bool) (*CharSet, error) { } fTranslatedChar = true } - } else if ch == '[' { + } else if ch == '[' && !fTranslatedChar { // This is code for Posix style properties - [:Ll:] or [:IsTibetan:]. // It currently doesn't do anything other than skip the whole thing! if p.charsRight() > 0 && p.rightChar(0) == ':' && !inRange { @@ -2291,11 +2403,54 @@ func (p *parser) addConcatenate() { } // Finish the current quantifiable (when a quantifier is found) -func (p *parser) addConcatenate3(lazy bool, min, max int) { - p.concatenation.addChild(p.unit.makeQuantifier(lazy, min, max)) +func (p *parser) addConcatenate3(lazy, possessive bool, min, max int) { + node := p.unit.makeQuantifier(lazy, min, max) + if possessive { + atomic := newRegexNode(NtAtomic, p.options) + atomic.addChild(node) + node = atomic + } + p.concatenation.addChild(node) p.unit = nil } +// addQuotedUnit adds the literal characters scanned by \Q...\E. All but the +// final character are completed immediately so a following quantifier applies +// to the final literal character, just as if each character had been escaped. +func (p *parser) addQuotedUnit(node *RegexNode) { + quoted := node.Str + if len(quoted) == 0 { + p.restoreLastUnit() + if p.unit == nil { + p.unit = newRegexNode(NtEmpty, p.options) + } + return + } + for _, ch := range quoted[:len(quoted)-1] { + p.concatenation.addChild(newRegexNodeCh(NtOne, p.options, ch)) + } + p.unit = newRegexNodeCh(NtOne, p.options, quoted[len(quoted)-1]) +} + +// restoreLastUnit makes an immediately preceding literal quantifiable again +// when an empty \Q\E appears between it and its quantifier. +func (p *parser) restoreLastUnit() { + if len(p.concatenation.Children) == 0 { + return + } + last := len(p.concatenation.Children) - 1 + node := p.concatenation.Children[last] + p.concatenation.Children = p.concatenation.Children[:last] + node.Parent = nil + if node.T == NtMulti && len(node.Str) > 1 { + prefix := append([]rune(nil), node.Str[:len(node.Str)-1]...) + p.concatenation.addChild(newRegexNodeStr(NtMulti, node.Options, prefix)) + p.unit = newRegexNodeCh(NtOne, p.options, node.Str[len(node.Str)-1]) + return + } + p.unit = node +} + // Sets the current unit to a single char node func (p *parser) addUnitOne(ch rune) { p.unit = newRegexNodeCh(NtOne, p.options, ch) diff --git a/vendor/github.com/dlclark/regexp2/v2/syntax/prefix.go b/vendor/github.com/dlclark/regexp2/v2/syntax/prefix.go index af5a8c06b..0f6ad4aa4 100644 --- a/vendor/github.com/dlclark/regexp2/v2/syntax/prefix.go +++ b/vendor/github.com/dlclark/regexp2/v2/syntax/prefix.go @@ -245,6 +245,9 @@ func (s *regexFcd) calculateFC(nt NodeType, node *RegexNode, CurIndex int) { case NtSetloop, NtSetlazy, NtSetloopatomic: s.pushFC(regexFc{cc: node.Set.Copy(), nullable: node.M == 0, caseInsensitive: ci}) + case NtGrapheme: + s.pushFC(regexFc{cc: *AnyClass(), nullable: false}) + case NtRef: s.pushFC(regexFc{cc: *AnyClass(), nullable: true, caseInsensitive: false}) diff --git a/vendor/github.com/dlclark/regexp2/v2/syntax/prefixanalyzer.go b/vendor/github.com/dlclark/regexp2/v2/syntax/prefixanalyzer.go index ac030de14..4c421053f 100644 --- a/vendor/github.com/dlclark/regexp2/v2/syntax/prefixanalyzer.go +++ b/vendor/github.com/dlclark/regexp2/v2/syntax/prefixanalyzer.go @@ -123,6 +123,11 @@ func tryFindFirstCharClass(node *RegexNode, ccIn **CharSet) int { } return 0 + case NtGrapheme: + // Every rune can begin a grapheme, so there is no useful candidate + // restriction to derive. + return 0 + // Zero-width elements. These don't contribute to the starting set, so return null to indicate a caller // should keep looking past them. case NtEmpty, NtNothing, NtBol, NtEol, NtBoundary, NtNonboundary, NtECMABoundary, NtNonECMABoundary, @@ -532,6 +537,9 @@ func findPrefixesCore(node *RegexNode, res *[]*bytes.Buffer, ignoreCase bool) bo // that comprise the set. For case-insensitive, we need the set to be two ASCII letters that case fold to the same thing. // As with One and loops, set loops are handled the same as sets up to the min iteration limit. case NtSet, NtSetloop, NtSetlazy, NtSetloopatomic: + if node.Set == nil || node.Set.IsNegated() { + return false + } setChars := node.Set.GetSetChars(maxPrefixes) @@ -1035,50 +1043,6 @@ func sumFrequencies(chars []rune) float32 { return sum } -func hasHighFrequencyChars(set FixedDistanceSet) bool { - if set.Negated { - return true - } - - // Sets without extracted chars can't be frequency-analyzed. - // Single-char sets use IndexOf, which is a strong filter regardless of frequency. - if len(set.Chars) <= 1 { - return false - } - - totalFrequency := sumFrequencies(set.Chars) - - // If the average frequency of the set's chars exceeds this threshold, the - // characters are common enough that a multi-string search may be a better filter. - const highFrequencyThreshold = 0.6 - return totalFrequency >= highFrequencyThreshold*float32(len(set.Chars)) -} - -func mayContainCaseInsensitiveMatching(node *RegexNode) bool { - if node.Options&IgnoreCase != 0 { - return true - } - - if node.Set != nil { - chars := node.Set.GetSetChars(maxPrefixes) - for _, ch := range chars { - if participatesInCaseConversion(ch) && - slices.Contains(chars, unicode.ToLower(ch)) && - slices.Contains(chars, unicode.ToUpper(ch)) { - return true - } - } - } - - for _, child := range node.Children { - if mayContainCaseInsensitiveMatching(child) { - return true - } - } - - return false -} - // Percent occurrences in source text (100 * char count / total count) var frequency = []float32{ 0.000 /* '\x00' */, 0.000 /* '\x01' */, 0.000 /* '\x02' */, 0.000 /* '\x03' */, 0.000 /* '\x04' */, 0.000 /* '\x05' */, 0.000 /* '\x06' */, 0.000, /* '\x07' */ diff --git a/vendor/github.com/dlclark/regexp2/v2/syntax/tree.go b/vendor/github.com/dlclark/regexp2/v2/syntax/tree.go index 960f1a191..bc754a2ad 100644 --- a/vendor/github.com/dlclark/regexp2/v2/syntax/tree.go +++ b/vendor/github.com/dlclark/regexp2/v2/syntax/tree.go @@ -128,6 +128,8 @@ const ( NtSetloopatomic NodeType = 45 // Updates the bumpalong position to the current position. NtUpdateBumpalong NodeType = 46 + // Matches one Unicode extended grapheme cluster (\X). + NtGrapheme NodeType = 47 ) func newRegexNode(t NodeType, opt RegexOptions) *RegexNode { @@ -693,10 +695,117 @@ func (n *RegexNode) reduceAtomic() *RegexNode { // For everything else, try to reduce ending backtracking of the last contained expression. default: child.eliminateEndingBacktracking() + if child.T == NtAlternate && child.hasDisjointStartingSets() && child.hasOnlyIntrinsicallyAtomicBranches() { + return child + } return atomic } } +// hasDisjointStartingSets reports whether every branch is non-nullable and +// begins with a character set that cannot overlap any other branch. In that +// case, once one branch has matched, no sibling branch could match the same +// starting position. +func (n *RegexNode) hasDisjointStartingSets() bool { + _, ok := n.disjointStartingSets() + return ok +} + +// disjointStartingSets returns the non-nullable first-character set for each +// branch when all of those sets are pairwise disjoint. +func (n *RegexNode) disjointStartingSets() ([]*CharSet, bool) { + sets := make([]*CharSet, 0, len(n.Children)) + for _, branch := range n.Children { + var set *CharSet + if tryFindFirstCharClass(branch, &set) != 1 || set == nil { + return nil, false + } + for _, previous := range sets { + if set.MayOverlap(previous) { + return nil, false + } + } + sets = append(sets, set) + } + return sets, true +} + +// disjointAtomicBranchSets returns the first-character sets when an +// alternation can select a branch without leaving a backtracking choice. +func (n *RegexNode) disjointAtomicBranchSets() ([]*CharSet, bool) { + if n.T != NtAlternate || !n.hasOnlyIntrinsicallyAtomicBranches() { + return nil, false + } + return n.disjointStartingSets() +} + +// dispatchCandidates returns disjoint branch sets and the leading nodes that +// can be folded into a consuming Dispatch instruction. +func (n *RegexNode) dispatchCandidates() ([]*CharSet, []*RegexNode, []bool, bool) { + if len(n.Children) >= 1<<16 { + return nil, nil, nil, false + } + sets, ok := n.disjointAtomicBranchSets() + if !ok { + return nil, nil, nil, false + } + + leaders := make([]*RegexNode, len(n.Children)) + complete := make([]bool, len(n.Children)) + for i := range leaders { + branch := n.Children[i] + leader := branch + if leader.T == NtConcatenate && len(leader.Children) > 0 { + leader = leader.Children[0] + } + switch leader.T { + case NtOne, NtNotone, NtSet, NtMulti: + leaders[i] = leader + default: + return nil, nil, nil, false + } + complete[i] = leader == branch && (leader.T != NtMulti || len(leader.Str) == 1) + } + return sets, leaders, complete, true +} + +func (n *RegexNode) hasOnlyIntrinsicallyAtomicBranches() bool { + for _, branch := range n.Children { + if !branch.isIntrinsicallyAtomic() { + return false + } + } + return true +} + +// isIntrinsicallyAtomic reports whether a successful match of this node has no +// alternative input-consuming path to explore if something later fails. +func (n *RegexNode) isIntrinsicallyAtomic() bool { + switch n.T { + case NtOne, NtNotone, NtSet, NtMulti, NtRef, NtGrapheme, + NtBol, NtEol, NtBoundary, NtNonboundary, NtECMABoundary, NtNonECMABoundary, + NtBeginning, NtStart, NtEndZ, NtEnd, NtNothing, NtEmpty, NtUpdateBumpalong, + NtOneloopatomic, NtNotoneloopatomic, NtSetloopatomic, + NtPosLook, NtNegLook, NtAtomic: + return true + + case NtOneloop, NtNotoneloop, NtSetloop, NtOnelazy, NtNotonelazy, NtSetlazy: + return n.M == n.N + + case NtCapture, NtGroup: + return len(n.Children) == 1 && n.Children[0].isIntrinsicallyAtomic() + + case NtConcatenate: + for _, child := range n.Children { + if !child.isIntrinsicallyAtomic() { + return false + } + } + return true + } + return false +} + func (n *RegexNode) makeLoopAtomic() { switch n.T { @@ -1871,7 +1980,7 @@ func (n *RegexNode) makeQuantifier(lazy bool, min, max int) *RegexNode { // If the result is 0, there is no minimum we can enforce. func (n *RegexNode) ComputeMinLength() int { switch n.T { - case NtOne, NtNotone, NtSet: + case NtOne, NtNotone, NtSet, NtGrapheme: // single char return 1 case NtMulti: @@ -1943,6 +2052,8 @@ func (n *RegexNode) computeMaxLength() int { switch n.T { case NtOne, NtNotone, NtSet: return 1 + case NtGrapheme: + return -1 case NtMulti: return len(n.Str) case NtNotonelazy, NtNotoneloop, NtNotoneloopatomic, @@ -2055,6 +2166,7 @@ var typeStr = []string{ "ECMABoundary", "NonECMABoundary", "OneloopAtomic", "NotoneloopAtomic", "SetloopAtomic", "UpdateBumpalong", + "Grapheme", } func (n *RegexNode) Description() string { diff --git a/vendor/github.com/dlclark/regexp2/v2/syntax/unicode_alias_tables.go b/vendor/github.com/dlclark/regexp2/v2/syntax/unicode_alias_tables.go index a165b57ea..7a231d7bd 100644 --- a/vendor/github.com/dlclark/regexp2/v2/syntax/unicode_alias_tables.go +++ b/vendor/github.com/dlclark/regexp2/v2/syntax/unicode_alias_tables.go @@ -41,6 +41,9 @@ var unicodeAliasCategories = map[string]*unicode.RangeTable{ "Grapheme_Cluster_Break=T": unicodeAliasGrapheme_Cluster_Break_T, "Grapheme_Cluster_Break=V": unicodeAliasGrapheme_Cluster_Break_V, "Grapheme_Cluster_Break=ZWJ": unicodeAliasGrapheme_Cluster_Break_ZWJ, + "Indic_Conjunct_Break=Consonant": unicodeAliasIndic_Conjunct_Break_Consonant, + "Indic_Conjunct_Break=Extend": unicodeAliasIndic_Conjunct_Break_Extend, + "Indic_Conjunct_Break=Linker": unicodeAliasIndic_Conjunct_Break_Linker, "Math": unicodeAliasMath, "Sentence_Break=ATerm": unicodeAliasSentence_Break_ATerm, "Sentence_Break=CR": unicodeAliasSentence_Break_CR, @@ -90,6 +93,8 @@ var unicodeSupportedPropertyAliases = map[string]string{ "extpict": "Extended_Pictographic", "gcb": "Grapheme_Cluster_Break", "graphemeclusterbreak": "Grapheme_Cluster_Break", + "incb": "Indic_Conjunct_Break", + "indicconjunctbreak": "Indic_Conjunct_Break", "math": "Math", "sb": "Sentence_Break", "sentencebreak": "Sentence_Break", @@ -118,6 +123,11 @@ var unicodeSupportedPropertyValueAliases = map[string]map[string]string{ "v": "V", "zwj": "ZWJ", }, + "Indic_Conjunct_Break": { + "consonant": "Consonant", + "extend": "Extend", + "linker": "Linker", + }, "Sentence_Break": { "at": "ATerm", "aterm": "ATerm", @@ -6056,3 +6066,529 @@ var unicodeAliasWord_Break_ZWJ = &unicode.RangeTable{ {Lo: 0x200D, Hi: 0x200D, Stride: 1}, }, } + +var unicodeAliasIndic_Conjunct_Break_Consonant = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0x915, Hi: 0x939, Stride: 1}, + {Lo: 0x958, Hi: 0x95F, Stride: 1}, + {Lo: 0x978, Hi: 0x97F, Stride: 1}, + {Lo: 0x995, Hi: 0x9A8, Stride: 1}, + {Lo: 0x9AA, Hi: 0x9B0, Stride: 1}, + {Lo: 0x9B2, Hi: 0x9B2, Stride: 1}, + {Lo: 0x9B6, Hi: 0x9B9, Stride: 1}, + {Lo: 0x9DC, Hi: 0x9DD, Stride: 1}, + {Lo: 0x9DF, Hi: 0x9DF, Stride: 1}, + {Lo: 0x9F0, Hi: 0x9F1, Stride: 1}, + {Lo: 0xA95, Hi: 0xAA8, Stride: 1}, + {Lo: 0xAAA, Hi: 0xAB0, Stride: 1}, + {Lo: 0xAB2, Hi: 0xAB3, Stride: 1}, + {Lo: 0xAB5, Hi: 0xAB9, Stride: 1}, + {Lo: 0xAF9, Hi: 0xAF9, Stride: 1}, + {Lo: 0xB15, Hi: 0xB28, Stride: 1}, + {Lo: 0xB2A, Hi: 0xB30, Stride: 1}, + {Lo: 0xB32, Hi: 0xB33, Stride: 1}, + {Lo: 0xB35, Hi: 0xB39, Stride: 1}, + {Lo: 0xB5C, Hi: 0xB5D, Stride: 1}, + {Lo: 0xB5F, Hi: 0xB5F, Stride: 1}, + {Lo: 0xB71, Hi: 0xB71, Stride: 1}, + {Lo: 0xC15, Hi: 0xC28, Stride: 1}, + {Lo: 0xC2A, Hi: 0xC39, Stride: 1}, + {Lo: 0xC58, Hi: 0xC5A, Stride: 1}, + {Lo: 0xD15, Hi: 0xD3A, Stride: 1}, + {Lo: 0x1000, Hi: 0x102A, Stride: 1}, + {Lo: 0x103F, Hi: 0x103F, Stride: 1}, + {Lo: 0x1050, Hi: 0x1055, Stride: 1}, + {Lo: 0x105A, Hi: 0x105D, Stride: 1}, + {Lo: 0x1061, Hi: 0x1061, Stride: 1}, + {Lo: 0x1065, Hi: 0x1066, Stride: 1}, + {Lo: 0x106E, Hi: 0x1070, Stride: 1}, + {Lo: 0x1075, Hi: 0x1081, Stride: 1}, + {Lo: 0x108E, Hi: 0x108E, Stride: 1}, + {Lo: 0x1780, Hi: 0x17B3, Stride: 1}, + {Lo: 0x1A20, Hi: 0x1A54, Stride: 1}, + {Lo: 0x1B0B, Hi: 0x1B0C, Stride: 1}, + {Lo: 0x1B13, Hi: 0x1B33, Stride: 1}, + {Lo: 0x1B45, Hi: 0x1B4C, Stride: 1}, + {Lo: 0x1B83, Hi: 0x1BA0, Stride: 1}, + {Lo: 0x1BAE, Hi: 0x1BAF, Stride: 1}, + {Lo: 0x1BBB, Hi: 0x1BBD, Stride: 1}, + {Lo: 0xA989, Hi: 0xA98B, Stride: 1}, + {Lo: 0xA98F, Hi: 0xA9B2, Stride: 1}, + {Lo: 0xA9E0, Hi: 0xA9E4, Stride: 1}, + {Lo: 0xA9E7, Hi: 0xA9EF, Stride: 1}, + {Lo: 0xA9FA, Hi: 0xA9FE, Stride: 1}, + {Lo: 0xAA60, Hi: 0xAA6F, Stride: 1}, + {Lo: 0xAA71, Hi: 0xAA73, Stride: 1}, + {Lo: 0xAA7A, Hi: 0xAA7A, Stride: 1}, + {Lo: 0xAA7E, Hi: 0xAA7F, Stride: 1}, + {Lo: 0xAAE0, Hi: 0xAAEA, Stride: 1}, + {Lo: 0xABC0, Hi: 0xABDA, Stride: 1}, + }, + R32: []unicode.Range32{ + {Lo: 0x10A00, Hi: 0x10A00, Stride: 1}, + {Lo: 0x10A10, Hi: 0x10A13, Stride: 1}, + {Lo: 0x10A15, Hi: 0x10A17, Stride: 1}, + {Lo: 0x10A19, Hi: 0x10A35, Stride: 1}, + {Lo: 0x11103, Hi: 0x11126, Stride: 1}, + {Lo: 0x11144, Hi: 0x11144, Stride: 1}, + {Lo: 0x11147, Hi: 0x11147, Stride: 1}, + {Lo: 0x11380, Hi: 0x11389, Stride: 1}, + {Lo: 0x1138B, Hi: 0x1138B, Stride: 1}, + {Lo: 0x1138E, Hi: 0x1138E, Stride: 1}, + {Lo: 0x11390, Hi: 0x113B5, Stride: 1}, + {Lo: 0x11900, Hi: 0x11906, Stride: 1}, + {Lo: 0x11909, Hi: 0x11909, Stride: 1}, + {Lo: 0x1190C, Hi: 0x11913, Stride: 1}, + {Lo: 0x11915, Hi: 0x11916, Stride: 1}, + {Lo: 0x11918, Hi: 0x1192F, Stride: 1}, + {Lo: 0x11A00, Hi: 0x11A00, Stride: 1}, + {Lo: 0x11A0B, Hi: 0x11A32, Stride: 1}, + {Lo: 0x11A50, Hi: 0x11A50, Stride: 1}, + {Lo: 0x11A5C, Hi: 0x11A83, Stride: 1}, + {Lo: 0x11F04, Hi: 0x11F10, Stride: 1}, + {Lo: 0x11F12, Hi: 0x11F33, Stride: 1}, + }, +} + +var unicodeAliasIndic_Conjunct_Break_Extend = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0x300, Hi: 0x36F, Stride: 1}, + {Lo: 0x483, Hi: 0x487, Stride: 1}, + {Lo: 0x488, Hi: 0x489, Stride: 1}, + {Lo: 0x591, Hi: 0x5BD, Stride: 1}, + {Lo: 0x5BF, Hi: 0x5BF, Stride: 1}, + {Lo: 0x5C1, Hi: 0x5C2, Stride: 1}, + {Lo: 0x5C4, Hi: 0x5C5, Stride: 1}, + {Lo: 0x5C7, Hi: 0x5C7, Stride: 1}, + {Lo: 0x610, Hi: 0x61A, Stride: 1}, + {Lo: 0x64B, Hi: 0x65F, Stride: 1}, + {Lo: 0x670, Hi: 0x670, Stride: 1}, + {Lo: 0x6D6, Hi: 0x6DC, Stride: 1}, + {Lo: 0x6DF, Hi: 0x6E4, Stride: 1}, + {Lo: 0x6E7, Hi: 0x6E8, Stride: 1}, + {Lo: 0x6EA, Hi: 0x6ED, Stride: 1}, + {Lo: 0x711, Hi: 0x711, Stride: 1}, + {Lo: 0x730, Hi: 0x74A, Stride: 1}, + {Lo: 0x7A6, Hi: 0x7B0, Stride: 1}, + {Lo: 0x7EB, Hi: 0x7F3, Stride: 1}, + {Lo: 0x7FD, Hi: 0x7FD, Stride: 1}, + {Lo: 0x816, Hi: 0x819, Stride: 1}, + {Lo: 0x81B, Hi: 0x823, Stride: 1}, + {Lo: 0x825, Hi: 0x827, Stride: 1}, + {Lo: 0x829, Hi: 0x82D, Stride: 1}, + {Lo: 0x859, Hi: 0x85B, Stride: 1}, + {Lo: 0x897, Hi: 0x89F, Stride: 1}, + {Lo: 0x8CA, Hi: 0x8E1, Stride: 1}, + {Lo: 0x8E3, Hi: 0x902, Stride: 1}, + {Lo: 0x93A, Hi: 0x93A, Stride: 1}, + {Lo: 0x93C, Hi: 0x93C, Stride: 1}, + {Lo: 0x941, Hi: 0x948, Stride: 1}, + {Lo: 0x951, Hi: 0x957, Stride: 1}, + {Lo: 0x962, Hi: 0x963, Stride: 1}, + {Lo: 0x981, Hi: 0x981, Stride: 1}, + {Lo: 0x9BC, Hi: 0x9BC, Stride: 1}, + {Lo: 0x9BE, Hi: 0x9BE, Stride: 1}, + {Lo: 0x9C1, Hi: 0x9C4, Stride: 1}, + {Lo: 0x9D7, Hi: 0x9D7, Stride: 1}, + {Lo: 0x9E2, Hi: 0x9E3, Stride: 1}, + {Lo: 0x9FE, Hi: 0x9FE, Stride: 1}, + {Lo: 0xA01, Hi: 0xA02, Stride: 1}, + {Lo: 0xA3C, Hi: 0xA3C, Stride: 1}, + {Lo: 0xA41, Hi: 0xA42, Stride: 1}, + {Lo: 0xA47, Hi: 0xA48, Stride: 1}, + {Lo: 0xA4B, Hi: 0xA4D, Stride: 1}, + {Lo: 0xA51, Hi: 0xA51, Stride: 1}, + {Lo: 0xA70, Hi: 0xA71, Stride: 1}, + {Lo: 0xA75, Hi: 0xA75, Stride: 1}, + {Lo: 0xA81, Hi: 0xA82, Stride: 1}, + {Lo: 0xABC, Hi: 0xABC, Stride: 1}, + {Lo: 0xAC1, Hi: 0xAC5, Stride: 1}, + {Lo: 0xAC7, Hi: 0xAC8, Stride: 1}, + {Lo: 0xAE2, Hi: 0xAE3, Stride: 1}, + {Lo: 0xAFA, Hi: 0xAFF, Stride: 1}, + {Lo: 0xB01, Hi: 0xB01, Stride: 1}, + {Lo: 0xB3C, Hi: 0xB3C, Stride: 1}, + {Lo: 0xB3E, Hi: 0xB3E, Stride: 1}, + {Lo: 0xB3F, Hi: 0xB3F, Stride: 1}, + {Lo: 0xB41, Hi: 0xB44, Stride: 1}, + {Lo: 0xB55, Hi: 0xB56, Stride: 1}, + {Lo: 0xB57, Hi: 0xB57, Stride: 1}, + {Lo: 0xB62, Hi: 0xB63, Stride: 1}, + {Lo: 0xB82, Hi: 0xB82, Stride: 1}, + {Lo: 0xBBE, Hi: 0xBBE, Stride: 1}, + {Lo: 0xBC0, Hi: 0xBC0, Stride: 1}, + {Lo: 0xBCD, Hi: 0xBCD, Stride: 1}, + {Lo: 0xBD7, Hi: 0xBD7, Stride: 1}, + {Lo: 0xC00, Hi: 0xC00, Stride: 1}, + {Lo: 0xC04, Hi: 0xC04, Stride: 1}, + {Lo: 0xC3C, Hi: 0xC3C, Stride: 1}, + {Lo: 0xC3E, Hi: 0xC40, Stride: 1}, + {Lo: 0xC46, Hi: 0xC48, Stride: 1}, + {Lo: 0xC4A, Hi: 0xC4C, Stride: 1}, + {Lo: 0xC55, Hi: 0xC56, Stride: 1}, + {Lo: 0xC62, Hi: 0xC63, Stride: 1}, + {Lo: 0xC81, Hi: 0xC81, Stride: 1}, + {Lo: 0xCBC, Hi: 0xCBC, Stride: 1}, + {Lo: 0xCBF, Hi: 0xCBF, Stride: 1}, + {Lo: 0xCC0, Hi: 0xCC0, Stride: 1}, + {Lo: 0xCC2, Hi: 0xCC2, Stride: 1}, + {Lo: 0xCC6, Hi: 0xCC6, Stride: 1}, + {Lo: 0xCC7, Hi: 0xCC8, Stride: 1}, + {Lo: 0xCCA, Hi: 0xCCB, Stride: 1}, + {Lo: 0xCCC, Hi: 0xCCD, Stride: 1}, + {Lo: 0xCD5, Hi: 0xCD6, Stride: 1}, + {Lo: 0xCE2, Hi: 0xCE3, Stride: 1}, + {Lo: 0xD00, Hi: 0xD01, Stride: 1}, + {Lo: 0xD3B, Hi: 0xD3C, Stride: 1}, + {Lo: 0xD3E, Hi: 0xD3E, Stride: 1}, + {Lo: 0xD41, Hi: 0xD44, Stride: 1}, + {Lo: 0xD57, Hi: 0xD57, Stride: 1}, + {Lo: 0xD62, Hi: 0xD63, Stride: 1}, + {Lo: 0xD81, Hi: 0xD81, Stride: 1}, + {Lo: 0xDCA, Hi: 0xDCA, Stride: 1}, + {Lo: 0xDCF, Hi: 0xDCF, Stride: 1}, + {Lo: 0xDD2, Hi: 0xDD4, Stride: 1}, + {Lo: 0xDD6, Hi: 0xDD6, Stride: 1}, + {Lo: 0xDDF, Hi: 0xDDF, Stride: 1}, + {Lo: 0xE31, Hi: 0xE31, Stride: 1}, + {Lo: 0xE34, Hi: 0xE3A, Stride: 1}, + {Lo: 0xE47, Hi: 0xE4E, Stride: 1}, + {Lo: 0xEB1, Hi: 0xEB1, Stride: 1}, + {Lo: 0xEB4, Hi: 0xEBC, Stride: 1}, + {Lo: 0xEC8, Hi: 0xECE, Stride: 1}, + {Lo: 0xF18, Hi: 0xF19, Stride: 1}, + {Lo: 0xF35, Hi: 0xF35, Stride: 1}, + {Lo: 0xF37, Hi: 0xF37, Stride: 1}, + {Lo: 0xF39, Hi: 0xF39, Stride: 1}, + {Lo: 0xF71, Hi: 0xF7E, Stride: 1}, + {Lo: 0xF80, Hi: 0xF84, Stride: 1}, + {Lo: 0xF86, Hi: 0xF87, Stride: 1}, + {Lo: 0xF8D, Hi: 0xF97, Stride: 1}, + {Lo: 0xF99, Hi: 0xFBC, Stride: 1}, + {Lo: 0xFC6, Hi: 0xFC6, Stride: 1}, + {Lo: 0x102D, Hi: 0x1030, Stride: 1}, + {Lo: 0x1032, Hi: 0x1037, Stride: 1}, + {Lo: 0x103A, Hi: 0x103A, Stride: 1}, + {Lo: 0x103D, Hi: 0x103E, Stride: 1}, + {Lo: 0x1058, Hi: 0x1059, Stride: 1}, + {Lo: 0x105E, Hi: 0x1060, Stride: 1}, + {Lo: 0x1071, Hi: 0x1074, Stride: 1}, + {Lo: 0x1082, Hi: 0x1082, Stride: 1}, + {Lo: 0x1085, Hi: 0x1086, Stride: 1}, + {Lo: 0x108D, Hi: 0x108D, Stride: 1}, + {Lo: 0x109D, Hi: 0x109D, Stride: 1}, + {Lo: 0x135D, Hi: 0x135F, Stride: 1}, + {Lo: 0x1712, Hi: 0x1714, Stride: 1}, + {Lo: 0x1715, Hi: 0x1715, Stride: 1}, + {Lo: 0x1732, Hi: 0x1733, Stride: 1}, + {Lo: 0x1734, Hi: 0x1734, Stride: 1}, + {Lo: 0x1752, Hi: 0x1753, Stride: 1}, + {Lo: 0x1772, Hi: 0x1773, Stride: 1}, + {Lo: 0x17B4, Hi: 0x17B5, Stride: 1}, + {Lo: 0x17B7, Hi: 0x17BD, Stride: 1}, + {Lo: 0x17C6, Hi: 0x17C6, Stride: 1}, + {Lo: 0x17C9, Hi: 0x17D1, Stride: 1}, + {Lo: 0x17D3, Hi: 0x17D3, Stride: 1}, + {Lo: 0x17DD, Hi: 0x17DD, Stride: 1}, + {Lo: 0x180B, Hi: 0x180D, Stride: 1}, + {Lo: 0x180F, Hi: 0x180F, Stride: 1}, + {Lo: 0x1885, Hi: 0x1886, Stride: 1}, + {Lo: 0x18A9, Hi: 0x18A9, Stride: 1}, + {Lo: 0x1920, Hi: 0x1922, Stride: 1}, + {Lo: 0x1927, Hi: 0x1928, Stride: 1}, + {Lo: 0x1932, Hi: 0x1932, Stride: 1}, + {Lo: 0x1939, Hi: 0x193B, Stride: 1}, + {Lo: 0x1A17, Hi: 0x1A18, Stride: 1}, + {Lo: 0x1A1B, Hi: 0x1A1B, Stride: 1}, + {Lo: 0x1A56, Hi: 0x1A56, Stride: 1}, + {Lo: 0x1A58, Hi: 0x1A5E, Stride: 1}, + {Lo: 0x1A62, Hi: 0x1A62, Stride: 1}, + {Lo: 0x1A65, Hi: 0x1A6C, Stride: 1}, + {Lo: 0x1A73, Hi: 0x1A7C, Stride: 1}, + {Lo: 0x1A7F, Hi: 0x1A7F, Stride: 1}, + {Lo: 0x1AB0, Hi: 0x1ABD, Stride: 1}, + {Lo: 0x1ABE, Hi: 0x1ABE, Stride: 1}, + {Lo: 0x1ABF, Hi: 0x1ADD, Stride: 1}, + {Lo: 0x1AE0, Hi: 0x1AEB, Stride: 1}, + {Lo: 0x1B00, Hi: 0x1B03, Stride: 1}, + {Lo: 0x1B34, Hi: 0x1B34, Stride: 1}, + {Lo: 0x1B35, Hi: 0x1B35, Stride: 1}, + {Lo: 0x1B36, Hi: 0x1B3A, Stride: 1}, + {Lo: 0x1B3B, Hi: 0x1B3B, Stride: 1}, + {Lo: 0x1B3C, Hi: 0x1B3C, Stride: 1}, + {Lo: 0x1B3D, Hi: 0x1B3D, Stride: 1}, + {Lo: 0x1B42, Hi: 0x1B42, Stride: 1}, + {Lo: 0x1B43, Hi: 0x1B43, Stride: 1}, + {Lo: 0x1B6B, Hi: 0x1B73, Stride: 1}, + {Lo: 0x1B80, Hi: 0x1B81, Stride: 1}, + {Lo: 0x1BA2, Hi: 0x1BA5, Stride: 1}, + {Lo: 0x1BA8, Hi: 0x1BA9, Stride: 1}, + {Lo: 0x1BAA, Hi: 0x1BAA, Stride: 1}, + {Lo: 0x1BAC, Hi: 0x1BAD, Stride: 1}, + {Lo: 0x1BE6, Hi: 0x1BE6, Stride: 1}, + {Lo: 0x1BE8, Hi: 0x1BE9, Stride: 1}, + {Lo: 0x1BED, Hi: 0x1BED, Stride: 1}, + {Lo: 0x1BEF, Hi: 0x1BF1, Stride: 1}, + {Lo: 0x1BF2, Hi: 0x1BF3, Stride: 1}, + {Lo: 0x1C2C, Hi: 0x1C33, Stride: 1}, + {Lo: 0x1C36, Hi: 0x1C37, Stride: 1}, + {Lo: 0x1CD0, Hi: 0x1CD2, Stride: 1}, + {Lo: 0x1CD4, Hi: 0x1CE0, Stride: 1}, + {Lo: 0x1CE2, Hi: 0x1CE8, Stride: 1}, + {Lo: 0x1CED, Hi: 0x1CED, Stride: 1}, + {Lo: 0x1CF4, Hi: 0x1CF4, Stride: 1}, + {Lo: 0x1CF8, Hi: 0x1CF9, Stride: 1}, + {Lo: 0x1DC0, Hi: 0x1DFF, Stride: 1}, + {Lo: 0x200D, Hi: 0x200D, Stride: 1}, + {Lo: 0x20D0, Hi: 0x20DC, Stride: 1}, + {Lo: 0x20DD, Hi: 0x20E0, Stride: 1}, + {Lo: 0x20E1, Hi: 0x20E1, Stride: 1}, + {Lo: 0x20E2, Hi: 0x20E4, Stride: 1}, + {Lo: 0x20E5, Hi: 0x20F0, Stride: 1}, + {Lo: 0x2CEF, Hi: 0x2CF1, Stride: 1}, + {Lo: 0x2D7F, Hi: 0x2D7F, Stride: 1}, + {Lo: 0x2DE0, Hi: 0x2DFF, Stride: 1}, + {Lo: 0x302A, Hi: 0x302D, Stride: 1}, + {Lo: 0x302E, Hi: 0x302F, Stride: 1}, + {Lo: 0x3099, Hi: 0x309A, Stride: 1}, + {Lo: 0xA66F, Hi: 0xA66F, Stride: 1}, + {Lo: 0xA670, Hi: 0xA672, Stride: 1}, + {Lo: 0xA674, Hi: 0xA67D, Stride: 1}, + {Lo: 0xA69E, Hi: 0xA69F, Stride: 1}, + {Lo: 0xA6F0, Hi: 0xA6F1, Stride: 1}, + {Lo: 0xA802, Hi: 0xA802, Stride: 1}, + {Lo: 0xA806, Hi: 0xA806, Stride: 1}, + {Lo: 0xA80B, Hi: 0xA80B, Stride: 1}, + {Lo: 0xA825, Hi: 0xA826, Stride: 1}, + {Lo: 0xA82C, Hi: 0xA82C, Stride: 1}, + {Lo: 0xA8C4, Hi: 0xA8C5, Stride: 1}, + {Lo: 0xA8E0, Hi: 0xA8F1, Stride: 1}, + {Lo: 0xA8FF, Hi: 0xA8FF, Stride: 1}, + {Lo: 0xA926, Hi: 0xA92D, Stride: 1}, + {Lo: 0xA947, Hi: 0xA951, Stride: 1}, + {Lo: 0xA953, Hi: 0xA953, Stride: 1}, + {Lo: 0xA980, Hi: 0xA982, Stride: 1}, + {Lo: 0xA9B3, Hi: 0xA9B3, Stride: 1}, + {Lo: 0xA9B6, Hi: 0xA9B9, Stride: 1}, + {Lo: 0xA9BC, Hi: 0xA9BD, Stride: 1}, + {Lo: 0xA9E5, Hi: 0xA9E5, Stride: 1}, + {Lo: 0xAA29, Hi: 0xAA2E, Stride: 1}, + {Lo: 0xAA31, Hi: 0xAA32, Stride: 1}, + {Lo: 0xAA35, Hi: 0xAA36, Stride: 1}, + {Lo: 0xAA43, Hi: 0xAA43, Stride: 1}, + {Lo: 0xAA4C, Hi: 0xAA4C, Stride: 1}, + {Lo: 0xAA7C, Hi: 0xAA7C, Stride: 1}, + {Lo: 0xAAB0, Hi: 0xAAB0, Stride: 1}, + {Lo: 0xAAB2, Hi: 0xAAB4, Stride: 1}, + {Lo: 0xAAB7, Hi: 0xAAB8, Stride: 1}, + {Lo: 0xAABE, Hi: 0xAABF, Stride: 1}, + {Lo: 0xAAC1, Hi: 0xAAC1, Stride: 1}, + {Lo: 0xAAEC, Hi: 0xAAED, Stride: 1}, + {Lo: 0xABE5, Hi: 0xABE5, Stride: 1}, + {Lo: 0xABE8, Hi: 0xABE8, Stride: 1}, + {Lo: 0xABED, Hi: 0xABED, Stride: 1}, + {Lo: 0xFB1E, Hi: 0xFB1E, Stride: 1}, + {Lo: 0xFE00, Hi: 0xFE0F, Stride: 1}, + {Lo: 0xFE20, Hi: 0xFE2F, Stride: 1}, + {Lo: 0xFF9E, Hi: 0xFF9F, Stride: 1}, + }, + R32: []unicode.Range32{ + {Lo: 0x101FD, Hi: 0x101FD, Stride: 1}, + {Lo: 0x102E0, Hi: 0x102E0, Stride: 1}, + {Lo: 0x10376, Hi: 0x1037A, Stride: 1}, + {Lo: 0x10A01, Hi: 0x10A03, Stride: 1}, + {Lo: 0x10A05, Hi: 0x10A06, Stride: 1}, + {Lo: 0x10A0C, Hi: 0x10A0F, Stride: 1}, + {Lo: 0x10A38, Hi: 0x10A3A, Stride: 1}, + {Lo: 0x10AE5, Hi: 0x10AE6, Stride: 1}, + {Lo: 0x10D24, Hi: 0x10D27, Stride: 1}, + {Lo: 0x10D69, Hi: 0x10D6D, Stride: 1}, + {Lo: 0x10EAB, Hi: 0x10EAC, Stride: 1}, + {Lo: 0x10EFA, Hi: 0x10EFF, Stride: 1}, + {Lo: 0x10F46, Hi: 0x10F50, Stride: 1}, + {Lo: 0x10F82, Hi: 0x10F85, Stride: 1}, + {Lo: 0x11001, Hi: 0x11001, Stride: 1}, + {Lo: 0x11038, Hi: 0x11046, Stride: 1}, + {Lo: 0x11070, Hi: 0x11070, Stride: 1}, + {Lo: 0x11073, Hi: 0x11074, Stride: 1}, + {Lo: 0x1107F, Hi: 0x11081, Stride: 1}, + {Lo: 0x110B3, Hi: 0x110B6, Stride: 1}, + {Lo: 0x110B9, Hi: 0x110BA, Stride: 1}, + {Lo: 0x110C2, Hi: 0x110C2, Stride: 1}, + {Lo: 0x11100, Hi: 0x11102, Stride: 1}, + {Lo: 0x11127, Hi: 0x1112B, Stride: 1}, + {Lo: 0x1112D, Hi: 0x11132, Stride: 1}, + {Lo: 0x11134, Hi: 0x11134, Stride: 1}, + {Lo: 0x11173, Hi: 0x11173, Stride: 1}, + {Lo: 0x11180, Hi: 0x11181, Stride: 1}, + {Lo: 0x111B6, Hi: 0x111BE, Stride: 1}, + {Lo: 0x111C0, Hi: 0x111C0, Stride: 1}, + {Lo: 0x111C9, Hi: 0x111CC, Stride: 1}, + {Lo: 0x111CF, Hi: 0x111CF, Stride: 1}, + {Lo: 0x1122F, Hi: 0x11231, Stride: 1}, + {Lo: 0x11234, Hi: 0x11234, Stride: 1}, + {Lo: 0x11235, Hi: 0x11235, Stride: 1}, + {Lo: 0x11236, Hi: 0x11237, Stride: 1}, + {Lo: 0x1123E, Hi: 0x1123E, Stride: 1}, + {Lo: 0x11241, Hi: 0x11241, Stride: 1}, + {Lo: 0x112DF, Hi: 0x112DF, Stride: 1}, + {Lo: 0x112E3, Hi: 0x112EA, Stride: 1}, + {Lo: 0x11300, Hi: 0x11301, Stride: 1}, + {Lo: 0x1133B, Hi: 0x1133C, Stride: 1}, + {Lo: 0x1133E, Hi: 0x1133E, Stride: 1}, + {Lo: 0x11340, Hi: 0x11340, Stride: 1}, + {Lo: 0x1134D, Hi: 0x1134D, Stride: 1}, + {Lo: 0x11357, Hi: 0x11357, Stride: 1}, + {Lo: 0x11366, Hi: 0x1136C, Stride: 1}, + {Lo: 0x11370, Hi: 0x11374, Stride: 1}, + {Lo: 0x113B8, Hi: 0x113B8, Stride: 1}, + {Lo: 0x113BB, Hi: 0x113C0, Stride: 1}, + {Lo: 0x113C2, Hi: 0x113C2, Stride: 1}, + {Lo: 0x113C5, Hi: 0x113C5, Stride: 1}, + {Lo: 0x113C7, Hi: 0x113C9, Stride: 1}, + {Lo: 0x113CE, Hi: 0x113CE, Stride: 1}, + {Lo: 0x113CF, Hi: 0x113CF, Stride: 1}, + {Lo: 0x113D2, Hi: 0x113D2, Stride: 1}, + {Lo: 0x113E1, Hi: 0x113E2, Stride: 1}, + {Lo: 0x11438, Hi: 0x1143F, Stride: 1}, + {Lo: 0x11442, Hi: 0x11444, Stride: 1}, + {Lo: 0x11446, Hi: 0x11446, Stride: 1}, + {Lo: 0x1145E, Hi: 0x1145E, Stride: 1}, + {Lo: 0x114B0, Hi: 0x114B0, Stride: 1}, + {Lo: 0x114B3, Hi: 0x114B8, Stride: 1}, + {Lo: 0x114BA, Hi: 0x114BA, Stride: 1}, + {Lo: 0x114BD, Hi: 0x114BD, Stride: 1}, + {Lo: 0x114BF, Hi: 0x114C0, Stride: 1}, + {Lo: 0x114C2, Hi: 0x114C3, Stride: 1}, + {Lo: 0x115AF, Hi: 0x115AF, Stride: 1}, + {Lo: 0x115B2, Hi: 0x115B5, Stride: 1}, + {Lo: 0x115BC, Hi: 0x115BD, Stride: 1}, + {Lo: 0x115BF, Hi: 0x115C0, Stride: 1}, + {Lo: 0x115DC, Hi: 0x115DD, Stride: 1}, + {Lo: 0x11633, Hi: 0x1163A, Stride: 1}, + {Lo: 0x1163D, Hi: 0x1163D, Stride: 1}, + {Lo: 0x1163F, Hi: 0x11640, Stride: 1}, + {Lo: 0x116AB, Hi: 0x116AB, Stride: 1}, + {Lo: 0x116AD, Hi: 0x116AD, Stride: 1}, + {Lo: 0x116B0, Hi: 0x116B5, Stride: 1}, + {Lo: 0x116B6, Hi: 0x116B6, Stride: 1}, + {Lo: 0x116B7, Hi: 0x116B7, Stride: 1}, + {Lo: 0x1171D, Hi: 0x1171D, Stride: 1}, + {Lo: 0x1171F, Hi: 0x1171F, Stride: 1}, + {Lo: 0x11722, Hi: 0x11725, Stride: 1}, + {Lo: 0x11727, Hi: 0x1172B, Stride: 1}, + {Lo: 0x1182F, Hi: 0x11837, Stride: 1}, + {Lo: 0x11839, Hi: 0x1183A, Stride: 1}, + {Lo: 0x11930, Hi: 0x11930, Stride: 1}, + {Lo: 0x1193B, Hi: 0x1193C, Stride: 1}, + {Lo: 0x1193D, Hi: 0x1193D, Stride: 1}, + {Lo: 0x11943, Hi: 0x11943, Stride: 1}, + {Lo: 0x119D4, Hi: 0x119D7, Stride: 1}, + {Lo: 0x119DA, Hi: 0x119DB, Stride: 1}, + {Lo: 0x119E0, Hi: 0x119E0, Stride: 1}, + {Lo: 0x11A01, Hi: 0x11A0A, Stride: 1}, + {Lo: 0x11A33, Hi: 0x11A38, Stride: 1}, + {Lo: 0x11A3B, Hi: 0x11A3E, Stride: 1}, + {Lo: 0x11A51, Hi: 0x11A56, Stride: 1}, + {Lo: 0x11A59, Hi: 0x11A5B, Stride: 1}, + {Lo: 0x11A8A, Hi: 0x11A96, Stride: 1}, + {Lo: 0x11A98, Hi: 0x11A98, Stride: 1}, + {Lo: 0x11B60, Hi: 0x11B60, Stride: 1}, + {Lo: 0x11B62, Hi: 0x11B64, Stride: 1}, + {Lo: 0x11B66, Hi: 0x11B66, Stride: 1}, + {Lo: 0x11C30, Hi: 0x11C36, Stride: 1}, + {Lo: 0x11C38, Hi: 0x11C3D, Stride: 1}, + {Lo: 0x11C3F, Hi: 0x11C3F, Stride: 1}, + {Lo: 0x11C92, Hi: 0x11CA7, Stride: 1}, + {Lo: 0x11CAA, Hi: 0x11CB0, Stride: 1}, + {Lo: 0x11CB2, Hi: 0x11CB3, Stride: 1}, + {Lo: 0x11CB5, Hi: 0x11CB6, Stride: 1}, + {Lo: 0x11D31, Hi: 0x11D36, Stride: 1}, + {Lo: 0x11D3A, Hi: 0x11D3A, Stride: 1}, + {Lo: 0x11D3C, Hi: 0x11D3D, Stride: 1}, + {Lo: 0x11D3F, Hi: 0x11D45, Stride: 1}, + {Lo: 0x11D47, Hi: 0x11D47, Stride: 1}, + {Lo: 0x11D90, Hi: 0x11D91, Stride: 1}, + {Lo: 0x11D95, Hi: 0x11D95, Stride: 1}, + {Lo: 0x11D97, Hi: 0x11D97, Stride: 1}, + {Lo: 0x11EF3, Hi: 0x11EF4, Stride: 1}, + {Lo: 0x11F00, Hi: 0x11F01, Stride: 1}, + {Lo: 0x11F36, Hi: 0x11F3A, Stride: 1}, + {Lo: 0x11F40, Hi: 0x11F40, Stride: 1}, + {Lo: 0x11F41, Hi: 0x11F41, Stride: 1}, + {Lo: 0x11F5A, Hi: 0x11F5A, Stride: 1}, + {Lo: 0x13440, Hi: 0x13440, Stride: 1}, + {Lo: 0x13447, Hi: 0x13455, Stride: 1}, + {Lo: 0x1611E, Hi: 0x16129, Stride: 1}, + {Lo: 0x1612D, Hi: 0x1612F, Stride: 1}, + {Lo: 0x16AF0, Hi: 0x16AF4, Stride: 1}, + {Lo: 0x16B30, Hi: 0x16B36, Stride: 1}, + {Lo: 0x16F4F, Hi: 0x16F4F, Stride: 1}, + {Lo: 0x16F8F, Hi: 0x16F92, Stride: 1}, + {Lo: 0x16FE4, Hi: 0x16FE4, Stride: 1}, + {Lo: 0x16FF0, Hi: 0x16FF1, Stride: 1}, + {Lo: 0x1BC9D, Hi: 0x1BC9E, Stride: 1}, + {Lo: 0x1CF00, Hi: 0x1CF2D, Stride: 1}, + {Lo: 0x1CF30, Hi: 0x1CF46, Stride: 1}, + {Lo: 0x1D165, Hi: 0x1D166, Stride: 1}, + {Lo: 0x1D167, Hi: 0x1D169, Stride: 1}, + {Lo: 0x1D16D, Hi: 0x1D172, Stride: 1}, + {Lo: 0x1D17B, Hi: 0x1D182, Stride: 1}, + {Lo: 0x1D185, Hi: 0x1D18B, Stride: 1}, + {Lo: 0x1D1AA, Hi: 0x1D1AD, Stride: 1}, + {Lo: 0x1D242, Hi: 0x1D244, Stride: 1}, + {Lo: 0x1DA00, Hi: 0x1DA36, Stride: 1}, + {Lo: 0x1DA3B, Hi: 0x1DA6C, Stride: 1}, + {Lo: 0x1DA75, Hi: 0x1DA75, Stride: 1}, + {Lo: 0x1DA84, Hi: 0x1DA84, Stride: 1}, + {Lo: 0x1DA9B, Hi: 0x1DA9F, Stride: 1}, + {Lo: 0x1DAA1, Hi: 0x1DAAF, Stride: 1}, + {Lo: 0x1E000, Hi: 0x1E006, Stride: 1}, + {Lo: 0x1E008, Hi: 0x1E018, Stride: 1}, + {Lo: 0x1E01B, Hi: 0x1E021, Stride: 1}, + {Lo: 0x1E023, Hi: 0x1E024, Stride: 1}, + {Lo: 0x1E026, Hi: 0x1E02A, Stride: 1}, + {Lo: 0x1E08F, Hi: 0x1E08F, Stride: 1}, + {Lo: 0x1E130, Hi: 0x1E136, Stride: 1}, + {Lo: 0x1E2AE, Hi: 0x1E2AE, Stride: 1}, + {Lo: 0x1E2EC, Hi: 0x1E2EF, Stride: 1}, + {Lo: 0x1E4EC, Hi: 0x1E4EF, Stride: 1}, + {Lo: 0x1E5EE, Hi: 0x1E5EF, Stride: 1}, + {Lo: 0x1E6E3, Hi: 0x1E6E3, Stride: 1}, + {Lo: 0x1E6E6, Hi: 0x1E6E6, Stride: 1}, + {Lo: 0x1E6EE, Hi: 0x1E6EF, Stride: 1}, + {Lo: 0x1E6F5, Hi: 0x1E6F5, Stride: 1}, + {Lo: 0x1E8D0, Hi: 0x1E8D6, Stride: 1}, + {Lo: 0x1E944, Hi: 0x1E94A, Stride: 1}, + {Lo: 0x1F3FB, Hi: 0x1F3FF, Stride: 1}, + {Lo: 0xE0020, Hi: 0xE007F, Stride: 1}, + {Lo: 0xE0100, Hi: 0xE01EF, Stride: 1}, + }, +} + +var unicodeAliasIndic_Conjunct_Break_Linker = &unicode.RangeTable{ + R16: []unicode.Range16{ + {Lo: 0x94D, Hi: 0x94D, Stride: 1}, + {Lo: 0x9CD, Hi: 0x9CD, Stride: 1}, + {Lo: 0xACD, Hi: 0xACD, Stride: 1}, + {Lo: 0xB4D, Hi: 0xB4D, Stride: 1}, + {Lo: 0xC4D, Hi: 0xC4D, Stride: 1}, + {Lo: 0xD4D, Hi: 0xD4D, Stride: 1}, + {Lo: 0x1039, Hi: 0x1039, Stride: 1}, + {Lo: 0x17D2, Hi: 0x17D2, Stride: 1}, + {Lo: 0x1A60, Hi: 0x1A60, Stride: 1}, + {Lo: 0x1B44, Hi: 0x1B44, Stride: 1}, + {Lo: 0x1BAB, Hi: 0x1BAB, Stride: 1}, + {Lo: 0xA9C0, Hi: 0xA9C0, Stride: 1}, + {Lo: 0xAAF6, Hi: 0xAAF6, Stride: 1}, + }, + R32: []unicode.Range32{ + {Lo: 0x10A3F, Hi: 0x10A3F, Stride: 1}, + {Lo: 0x11133, Hi: 0x11133, Stride: 1}, + {Lo: 0x113D0, Hi: 0x113D0, Stride: 1}, + {Lo: 0x1193E, Hi: 0x1193E, Stride: 1}, + {Lo: 0x11A47, Hi: 0x11A47, Stride: 1}, + {Lo: 0x11A99, Hi: 0x11A99, Stride: 1}, + {Lo: 0x11F42, Hi: 0x11F42, Stride: 1}, + }, +} diff --git a/vendor/github.com/dlclark/regexp2/v2/syntax/writer.go b/vendor/github.com/dlclark/regexp2/v2/syntax/writer.go index ab7f7feac..ec1818e70 100644 --- a/vendor/github.com/dlclark/regexp2/v2/syntax/writer.go +++ b/vendor/github.com/dlclark/regexp2/v2/syntax/writer.go @@ -20,7 +20,16 @@ func Write(tree *RegexTree) (*Code, error) { if err != nil { return nil, err } + if !dispatchTablesEqual(code.Dispatches, quickCode.Dispatches) { + return nil, fmt.Errorf("full and quick dispatch tables differ") + } + for i := range quickCode.Dispatches { + quickCode.Dispatches[i].Sets = code.Dispatches[i].Sets + quickCode.Dispatches[i].ASCII = code.Dispatches[i].ASCII + quickCode.Dispatches[i].ASCIIMasks = code.Dispatches[i].ASCIIMasks + } code.QuickCodes = quickCode.Codes + code.QuickDispatches = quickCode.Dispatches } return code, nil } @@ -31,6 +40,10 @@ func newWriter(quickCaptureSlots []bool) writer { emitted: make([]int, 2), stringhash: make(map[string]int), sethash: make(map[string]int), + preconsumed: make(map[*RegexNode]bool), + dispatchInfo: make(map[*RegexNode]dispatchInfo), + dispatchCodes: make(map[*RegexNode]int), + dispatchGotos: make(map[*RegexNode][]int), quickCaptureSlots: quickCaptureSlots, } } @@ -44,6 +57,11 @@ type writer struct { stringtable [][]rune sethash map[string]int settable []*CharSet + dispatchtable []DispatchTable + preconsumed map[*RegexNode]bool + dispatchInfo map[*RegexNode]dispatchInfo + dispatchCodes map[*RegexNode]int + dispatchGotos map[*RegexNode][]int counting bool count int trackcount int @@ -51,6 +69,30 @@ type writer struct { quickCaptureSlots []bool } +type dispatchInfo struct { + sets []*CharSet + leaders []*RegexNode + complete []bool + ok bool +} + +func dispatchTablesEqual(left, right []DispatchTable) bool { + if len(left) != len(right) { + return false + } + for i := range left { + if !slices.Equal(left[i].Sets, right[i].Sets) || + !slices.Equal(left[i].ASCIIMasks, right[i].ASCIIMasks) || + (left[i].ASCII == nil) != (right[i].ASCII == nil) { + return false + } + if left[i].ASCII != nil && *left[i].ASCII != *right[i].ASCII { + return false + } + } + return true +} + const ( BeforeChild NodeType = 64 AfterChild NodeType = 128 @@ -91,6 +133,8 @@ func (w *writer) codeFromTree(tree *RegexTree) (*Code, error) { for { if !w.counting { w.emitted = make([]int, w.count) + w.dispatchCodes = make(map[*RegexNode]int) + w.dispatchGotos = make(map[*RegexNode][]int) } curNode = tree.Root @@ -138,7 +182,7 @@ func (w *writer) codeFromTree(tree *RegexTree) (*Code, error) { w.counting = false } if w.quickCaptureSlots != nil { - return &Code{Codes: w.emitted, TrackCount: w.trackcount}, nil + return &Code{Codes: w.emitted, Dispatches: w.dispatchtable, TrackCount: w.trackcount}, nil } fcPrefix := getFirstCharsPrefix(tree) @@ -161,6 +205,7 @@ func (w *writer) codeFromTree(tree *RegexTree) (*Code, error) { Codes: w.emitted, Strings: w.stringtable, Sets: w.settable, + Dispatches: w.dispatchtable, TrackCount: w.trackcount, Caps: w.caps, Capsize: capsize, @@ -170,9 +215,47 @@ func (w *writer) codeFromTree(tree *RegexTree) (*Code, error) { Anchors: getAnchors(tree), RightToLeft: rtl, FindOptimizations: tree.FindOptimizations, + LeftContextRunes: AnalyzeLeftContext(tree.Root), }, nil } +// AnalyzeLeftContext returns how many runes before a candidate start the matcher +// may inspect. Slicing the input down to that candidate is legal only when no +// opcode depends on the original search origin or unbounded left text. +// +// 0 never looks left of the start position +// 1 one previous rune is enough for \b, or to keep ^/\A from seeing +// the candidate as the original start (they test leftchars()==0) +// -1 do not slice: lookbehind, or \G (NtStart), which keys off textstart +func AnalyzeLeftContext(n *RegexNode) int { + if n == nil { + return 0 + } + + need := 0 + switch n.T { + case NtPosLook, NtNegLook: + if n.Options&RightToLeft != 0 { + return -1 + } + case NtStart: + return -1 + case NtBol, NtBeginning, NtBoundary, NtNonboundary, NtECMABoundary, NtNonECMABoundary: + need = 1 + } + + for _, child := range n.Children { + childNeed := AnalyzeLeftContext(child) + if childNeed < 0 { + return -1 + } + if childNeed > need { + need = childNeed + } + } + return need +} + // The main RegexCode generator. It does a depth-first walk // through the tree and calls EmitFragment to emits code before // and after each child of an interior node, and at each leaf. @@ -192,13 +275,37 @@ func (w *writer) emitFragment(nodetype NodeType, node *RegexNode, curIndex int) case NtConcatenate | BeforeChild, NtConcatenate | AfterChild, NtEmpty: case NtAlternate | BeforeChild: - if curIndex < len(node.Children)-1 { + if sets, leaders, _, ok := w.getDispatchCandidates(node); ok { + if curIndex == 0 { + w.dispatchCodes[node] = w.dispatchCode(sets) + w.emit1(Dispatch|bits, w.dispatchCodes[node]) + } + w.preconsumed[leaders[curIndex]] = true + w.patchDispatchBranch(node, curIndex, w.curPos()) + } else if curIndex < len(node.Children)-1 { w.pushInt(w.curPos()) w.emit1(Lazybranch, 0) } case NtAlternate | AfterChild: - if curIndex < len(node.Children)-1 { + if _, _, complete, ok := w.getDispatchCandidates(node); ok { + if curIndex < len(node.Children)-1 && !complete[curIndex] { + gotoPos := w.curPos() + w.emit1(Goto, 0) + w.dispatchGotos[node] = append(w.dispatchGotos[node], gotoPos) + } + if curIndex == len(node.Children)-1 { + end := w.curPos() + for _, gotoPos := range w.dispatchGotos[node] { + w.patchJump(gotoPos, end) + } + for branch, isComplete := range complete { + if isComplete { + w.patchDispatchBranch(node, branch, end) + } + } + } + } else if curIndex < len(node.Children)-1 { lbPos := w.popInt() w.pushInt(w.curPos()) w.emit1(Goto, 0) @@ -342,7 +449,9 @@ func (w *writer) emitFragment(nodetype NodeType, node *RegexNode, curIndex int) w.emit(Forejump) case NtOne, NtNotone: - w.emit1(InstOp(node.T|ntBits), int(node.Ch)) + if !w.preconsumed[node] { + w.emit1(InstOp(node.T|ntBits), int(node.Ch)) + } case NtNotoneloop, NtNotoneloopatomic, NtNotonelazy, NtOneloop, NtOneloopatomic, NtOnelazy: if node.M > 0 { @@ -373,10 +482,22 @@ func (w *writer) emitFragment(nodetype NodeType, node *RegexNode, curIndex int) } case NtMulti: - w.emit1(InstOp(node.T|ntBits), w.stringCode(node.Str)) + str := node.Str + if w.preconsumed[node] { + if bits&Rtl != 0 { + str = str[:len(str)-1] + } else { + str = str[1:] + } + } + if len(str) > 0 { + w.emit1(InstOp(node.T|ntBits), w.stringCode(str)) + } case NtSet: - w.emit1(InstOp(node.T|ntBits), w.setCode(node.Set)) + if !w.preconsumed[node] { + w.emit1(InstOp(node.T|ntBits), w.setCode(node.Set)) + } case NtRef: w.emit1(InstOp(node.T|ntBits), w.mapCapnum(node.M)) @@ -384,6 +505,9 @@ func (w *writer) emitFragment(nodetype NodeType, node *RegexNode, curIndex int) case NtNothing, NtBol, NtEol, NtBoundary, NtNonboundary, NtECMABoundary, NtNonECMABoundary, NtBeginning, NtStart, NtEndZ, NtEnd, NtUpdateBumpalong: w.emit(InstOp(node.T)) + case NtGrapheme: + w.emit(InstOp(node.T | ntBits)) + default: return fmt.Errorf("unexpected opcode in regular expression generation: %v", nodetype) } @@ -434,6 +558,53 @@ func (w *writer) patchJump(offset, jumpDest int) { w.emitted[offset+1] = jumpDest } +func (w *writer) getDispatchCandidates(node *RegexNode) ([]*CharSet, []*RegexNode, []bool, bool) { + if info, found := w.dispatchInfo[node]; found { + return info.sets, info.leaders, info.complete, info.ok + } + sets, leaders, complete, ok := node.dispatchCandidates() + w.dispatchInfo[node] = dispatchInfo{sets: sets, leaders: leaders, complete: complete, ok: ok} + return sets, leaders, complete, ok +} + +func (w *writer) dispatchCode(sets []*CharSet) int { + if w.counting { + return 0 + } + table := DispatchTable{ + Sets: make([]int, len(sets)), + Branches: make([]int, len(sets)), + } + if len(sets) >= 4 { + table.ASCII = &[128]uint16{} + } else { + table.ASCIIMasks = make([]uint64, len(sets)*2) + } + for i, set := range sets { + table.Sets[i] = w.setCode(set) + for ch := rune(0); ch < 128; ch++ { + if set.CharIn(ch) { + if table.ASCII != nil { + table.ASCII[ch] = uint16(i + 1) + } else { + table.ASCIIMasks[i*2+int(ch>>6)] |= uint64(1) << (ch & 63) + } + } + } + } + index := len(w.dispatchtable) + w.dispatchtable = append(w.dispatchtable, table) + return index +} + +func (w *writer) patchDispatchBranch(node *RegexNode, branch, target int) { + if w.counting { + return + } + table := w.dispatchCodes[node] + w.dispatchtable[table].Branches[branch] = target +} + // Returns an index in the set table for a charset // uses a map to eliminate duplicates. func (w *writer) setCode(set *CharSet) int { diff --git a/vendor/github.com/grafana/sobek/.tc39_test262_checkout.sh b/vendor/github.com/grafana/sobek/.tc39_test262_checkout.sh index ea7317829..7c7b53dab 100644 --- a/vendor/github.com/grafana/sobek/.tc39_test262_checkout.sh +++ b/vendor/github.com/grafana/sobek/.tc39_test262_checkout.sh @@ -5,6 +5,7 @@ sha=3af36bec45bd4f72d4b57366653578e1e4dafef7 mkdir -p testdata/test262 cd testdata/test262 git init +git config core.autocrlf false git remote add origin https://github.com/tc39/test262.git git fetch origin --depth=1 "${sha}" git reset --hard "${sha}" diff --git a/vendor/github.com/grafana/sobek/base64.go b/vendor/github.com/grafana/sobek/base64.go new file mode 100644 index 000000000..b1fe66466 --- /dev/null +++ b/vendor/github.com/grafana/sobek/base64.go @@ -0,0 +1,369 @@ +package sobek + +import ( + "errors" + "strconv" +) + +type base64LastChunkHandling uint8 + +const ( + base64LastChunkHandlingInvalid base64LastChunkHandling = iota + base64LastChunkHandlingLoose + base64LastChunkHandlingStrict + base64LastChunkHandlingStop +) + +var base64DecodeMap = func() (t [256]byte) { + for i := range t { + t[i] = 0xff + } + for i, c := range "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" { + t[c] = byte(i) + } + return +}() + +var base64DecodeMapUrl = func() (t [256]byte) { + for i := range t { + t[i] = 0xff + } + for i, c := range "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_" { + t[c] = byte(i) + } + return +}() + +// TC39 Abstract Operations for Uint8Array Objects - [SkipAsciiWhitespace(string, index)]. +// +// [SkipAsciiWhitespace(string, index)]: https://tc39.es/ecma262/multipage/indexed-collections.html#sec-skipasciiwhitespace +func skipAsciiWhitespace(s String, index int) int { + length := s.Length() + for index < length { + switch s.CharAt(index) { + case 0x0009, 0x000A, 0x000C, 0x000D, 0x0020: + index++ + default: + return index + } + } + return index +} + +func base64Assemble32Checked(n1, n2, n3, n4 byte) uint32 { + return uint32(n1)<<18 | + uint32(n2)<<12 | + uint32(n3)<<6 | + uint32(n4) +} + +func base64Assemble32(n1, n2, n3, n4 byte) (dn uint32, ok bool) { + // Check that all the digits are valid. If any of them was 0xff, their + // bitwise OR will be 0xff. + if n1|n2|n3|n4 == 0xff { + return 0, false + } + return base64Assemble32Checked(n1, n2, n3, n4), true +} + +func base64Assemble64(n1, n2, n3, n4, n5, n6, n7, n8 byte) (dn uint64, ok bool) { + // Check that all the digits are valid. If any of them was 0xff, their + // bitwise OR will be 0xff. + if n1|n2|n3|n4|n5|n6|n7|n8 == 0xff { + return 0, false + } + return uint64(n1)<<42 | + uint64(n2)<<36 | + uint64(n3)<<30 | + uint64(n4)<<24 | + uint64(n5)<<18 | + uint64(n6)<<12 | + uint64(n7)<<6 | + uint64(n8), + true +} + +func base64Put6Bytes(b []byte, v uint64) { + _ = b[5] // early bounds check to guarantee safety of writes below + b[0] = byte(v >> 40) + b[1] = byte(v >> 32) + b[2] = byte(v >> 24) + b[3] = byte(v >> 16) + b[4] = byte(v >> 8) + b[5] = byte(v) +} + +func base64Put3Bytes(b []byte, v uint32) { + _ = b[2] // early bounds check to guarantee safety of writes below + b[0] = byte(v >> 16) + b[1] = byte(v >> 8) + b[2] = byte(v) +} + +// TC39 Abstract Operations for Uint8Array Objects - [DecodeFinalBase64Chunk(chunk, throwOnExtraBits)]. +// chunk must contain 2 or 3 characters of the standard base64 alphabet. +// +// [DecodeFinalBase64Chunk(chunk, throwOnExtraBits)]: https://tc39.es/ecma262/multipage/indexed-collections.html#sec-decodefinalbase64chunk +func decodeFinalBase64Chunk(chunk [4]byte, chunkLength int, throwOnExtraBits bool) ([3]byte, int, error) { + + n := base64Assemble32Checked(chunk[0], chunk[1], chunk[2], chunk[3]) + + var res [3]byte + base64Put3Bytes(res[:], n) + + if chunkLength == 2 { + if throwOnExtraBits && res[1] != 0 { + return [3]byte{}, 0, errors.New("extra bits in the last base64 character") + } + return res, 1, nil + } + if throwOnExtraBits && res[2] != 0 { + return [3]byte{}, 0, errors.New("extra bits in the last base64 character") + } + return res, 2, nil +} + +// TC39 Abstract Operations for Uint8Array Objects - [FromBase64(string, alphabet, lastChunkHandling)], +// +// [FromBase64(string, alphabet, lastChunkHandling, maxLength)]: https://tc39.es/ecma262/multipage/indexed-collections.html#sec-frombase64 +func fromBase64(s String, decodeMap *[256]byte, lastChunkHandling base64LastChunkHandling) (read int, bytes []byte, err error) { + // 4 characters of input decode into at most 3 bytes, so a buffer of the + // upper-bound size makes fromBase64Into behave as if maxLength were absent. + dst := make([]byte, (s.Length()+3)/4*3) + read, written, err := fromBase64Into(s, decodeMap, lastChunkHandling, dst) + return read, dst[:written], err +} + +// Decode a base64-encoded ASCII string. +// The fast case algorithm is borrowed from the standard Go encoding/base64. +func base64DecodeAscii(a asciiString, s String, decodeMap *[256]byte, lastChunkHandling base64LastChunkHandling, dst []byte) (read, written int, err error) { + // Lift the nil check outside of the loop. decodeMap is directly + // used later in this function, to let the compiler know that the + // receiver can't be nil. + _ = *decodeMap + + for strconv.IntSize >= 64 && len(a)-read >= 8 && len(dst)-written >= 6 { + src2 := a[read : read+8] + if dn, ok := base64Assemble64( + decodeMap[src2[0]], + decodeMap[src2[1]], + decodeMap[src2[2]], + decodeMap[src2[3]], + decodeMap[src2[4]], + decodeMap[src2[5]], + decodeMap[src2[6]], + decodeMap[src2[7]], + ); ok { + base64Put6Bytes(dst[written:], dn) + written += 6 + read += 8 + } else { + var eof bool + read, written, eof, err = base64DecodeChunk(s, read, len(a), decodeMap, lastChunkHandling, dst, written) + if eof || err != nil { + return + } + } + } + + for len(a)-read >= 4 && len(dst)-written >= 3 { + src2 := a[read : read+4] + if dn, ok := base64Assemble32( + decodeMap[src2[0]], + decodeMap[src2[1]], + decodeMap[src2[2]], + decodeMap[src2[3]], + ); ok { + base64Put3Bytes(dst[written:], dn) + written += 3 + read += 4 + } else { + var eof bool + read, written, eof, err = base64DecodeChunk(s, read, len(a), decodeMap, lastChunkHandling, dst, written) + if eof || err != nil { + return + } + } + } + + if written == len(dst) { + return + } + + for eof := false; !eof; { + read, written, eof, err = base64DecodeChunk(s, read, len(a), decodeMap, lastChunkHandling, dst, written) + if err != nil { + return + } + } + return +} + +// Decode a base64-encoded Unicode string. +// The fast case algorithm is borrowed from the standard Go encoding/base64. +func base64DecodeUnicode(u unicodeString, s String, decodeMap *[256]byte, lastChunkHandling base64LastChunkHandling, dst []byte) (read, written int, err error) { + u = u[1:] // Skip BOM + + // Lift the nil check outside of the loop. decodeMap is directly + // used later in this function, to let the compiler know that the + // receiver can't be nil. + _ = *decodeMap + + for strconv.IntSize >= 64 && len(u)-read >= 8 && len(dst)-written >= 6 { + src2 := u[read : read+8] + // Make sure there are no code units above 255 + if (src2[0]|src2[1]|src2[2]|src2[3]|src2[4]|src2[5]|src2[6]|src2[7])&0xFF00 == 0 { + if dn, ok := base64Assemble64( + decodeMap[byte(src2[0])], + decodeMap[byte(src2[1])], + decodeMap[byte(src2[2])], + decodeMap[byte(src2[3])], + decodeMap[byte(src2[4])], + decodeMap[byte(src2[5])], + decodeMap[byte(src2[6])], + decodeMap[byte(src2[7])], + ); ok { + base64Put6Bytes(dst[written:], dn) + written += 6 + read += 8 + continue + } + } + var eof bool + read, written, eof, err = base64DecodeChunk(s, read, len(u), decodeMap, lastChunkHandling, dst, written) + if eof || err != nil { + return + } + } + + for len(u)-read >= 4 && len(dst)-written >= 3 { + src2 := u[read : read+4] + // Make sure there are no code units above 255 + if (src2[0]|src2[1]|src2[2]|src2[3])&0xFF00 == 0 { + if dn, ok := base64Assemble32( + decodeMap[byte(src2[0])], + decodeMap[byte(src2[1])], + decodeMap[byte(src2[2])], + decodeMap[byte(src2[3])], + ); ok { + base64Put3Bytes(dst[written:], dn) + written += 3 + read += 4 + continue + } + } + var eof bool + read, written, eof, err = base64DecodeChunk(s, read, len(u), decodeMap, lastChunkHandling, dst, written) + if eof || err != nil { + return + } + } + + if written == len(dst) { + return + } + + for eof := false; !eof; { + read, written, eof, err = base64DecodeChunk(s, read, len(u), decodeMap, lastChunkHandling, dst, written) + if err != nil { + return + } + } + return +} + +// Decode a single base64 chunk where fast case fails (either because there are whitespaces or because it's the last chunk, short or padded). +func base64DecodeChunk(s String, index, length int, decodeMap *[256]byte, lastChunkHandling base64LastChunkHandling, dst []byte, dstIndex int) (newIndex int, newDstIndex int, eof bool, err error) { + newIndex = index + newDstIndex = dstIndex + var chunk [4]byte + chunkLength := 0 + for { + index = skipAsciiWhitespace(s, index) + if index == length { + eof = true + if chunkLength > 0 { + if lastChunkHandling == base64LastChunkHandlingStop { + return + } + if lastChunkHandling == base64LastChunkHandlingStrict { + err = errors.New("missing padding in the last chunk") + return + } + // lastChunkHandling is "loose" + if chunkLength == 1 { + err = errors.New("a single extra base64 character in the last chunk") + return + } + dec, n, _ := decodeFinalBase64Chunk(chunk, chunkLength, false) + newDstIndex += copy(dst[newDstIndex:], dec[:n]) + } + newIndex = length + return + } + char := s.CharAt(index) + index++ + if char == '=' { + if chunkLength < 2 { + err = errors.New("unexpected padding character") + return + } + index = skipAsciiWhitespace(s, index) + if chunkLength == 2 { + if index == length { + if lastChunkHandling == base64LastChunkHandlingStop { + eof = true + return + } + err = errors.New("missing padding character") + return + } + if s.CharAt(index) == '=' { + index = skipAsciiWhitespace(s, index+1) + } + } + if index < length { + err = errors.New("unexpected character after padding") + return + } + dec, n, decErr := decodeFinalBase64Chunk(chunk, chunkLength, lastChunkHandling == base64LastChunkHandlingStrict) + if decErr != nil { + err = decErr + return + } + newDstIndex += copy(dst[newDstIndex:], dec[:n]) + newIndex = length + eof = true + return + } + if char >= 128 { + err = errors.New("invalid base64 character") + return + } + b := decodeMap[char] + if b == 0xff { + err = errors.New("invalid base64 character") + return + } + remaining := len(dst) - newDstIndex + if (remaining == 1 && chunkLength == 2) || (remaining == 2 && chunkLength == 3) { + eof = true + return + } + chunk[chunkLength] = b + chunkLength++ + if chunkLength == 4 { + n := base64Assemble32Checked(chunk[0], chunk[1], chunk[2], chunk[3]) + if remaining > 3 { + base64Put3Bytes(dst[newDstIndex:], n) + newDstIndex += 3 + } else { + base64Put3Bytes(chunk[:], n) + newDstIndex += copy(dst[newDstIndex:], chunk[:]) + eof = true + } + newIndex = index + return + } + } +} diff --git a/vendor/github.com/grafana/sobek/builtin_array.go b/vendor/github.com/grafana/sobek/builtin_array.go index 4e577f576..4f4b04424 100644 --- a/vendor/github.com/grafana/sobek/builtin_array.go +++ b/vendor/github.com/grafana/sobek/builtin_array.go @@ -1194,8 +1194,8 @@ func (r *Runtime) arrayproto_flat(call FunctionCall) Value { o := call.This.ToObject(r) l := toLength(o.self.getStr("length", nil)) depthNum := int64(1) - if len(call.Arguments) > 0 { - depthNum = call.Argument(0).ToInteger() + if arg := call.Argument(0); arg != _undefined { + depthNum = arg.ToInteger() } a := arraySpeciesCreate(o, 0) r.flattenIntoArray(a, o, l, 0, depthNum, nil, nil) diff --git a/vendor/github.com/grafana/sobek/builtin_error.go b/vendor/github.com/grafana/sobek/builtin_error.go index 132fae6d2..eb0764c74 100644 --- a/vendor/github.com/grafana/sobek/builtin_error.go +++ b/vendor/github.com/grafana/sobek/builtin_error.go @@ -122,7 +122,7 @@ func (r *Runtime) newErrorObject(proto *Object, class string) *errorObject { func (r *Runtime) builtin_Error(args []Value, proto *Object) *Object { obj := r.newErrorObject(proto, classError) if len(args) > 0 && args[0] != _undefined { - obj._putProp("message", args[0].ToString(), true, false, true) + obj._putProp("message", args[0].toString(), true, false, true) } if len(args) > 1 && args[1] != _undefined { if options, ok := args[1].(*Object); ok { @@ -144,10 +144,11 @@ func (r *Runtime) builtin_AggregateError(args []Value, proto *Object) *Object { if len(args) > 1 && args[1] != nil && args[1] != _undefined { obj._putProp("message", args[1].toString(), true, false, true) } - var errors []Value + items := _undefined if len(args) > 0 { - errors = r.iterableToList(args[0], nil) + items = args[0] } + errors := r.iterableToList(items, nil) obj._putProp("errors", r.newArrayValues(errors), true, false, true) if len(args) > 2 && args[2] != _undefined { @@ -166,6 +167,22 @@ func (r *Runtime) builtin_AggregateError(args []Value, proto *Object) *Object { return obj.val } +func (r *Runtime) newAggregateErrorErrors(errors []Value) *Object { + proto := r.getPrototypeFromCtor(r.getAggregateError(), nil, nil) + obj := r.newErrorObject(proto, classError) + obj._putProp("errors", r.newArrayValues(errors), true, false, true) + return obj.val +} + +func (r *Runtime) error_isError(call FunctionCall) Value { + if o, ok := call.Argument(0).(*Object); ok { + if o.self.className() == classError { + return valueTrue + } + } + return valueFalse +} + func writeErrorString(sb *StringBuilder, obj *Object) String { var nameStr, msgStr String name := obj.self.getStr("name", nil) @@ -229,6 +246,8 @@ func (r *Runtime) getError() *Object { ret = &Object{runtime: r} r.global.Error = ret r.newNativeFuncConstruct(ret, r.builtin_Error, "Error", r.getErrorPrototype(), 1) + o := ret.self + o._putProp("isError", r.newNativeFunc(r.error_isError, "isError", 1), true, false, true) } return ret } diff --git a/vendor/github.com/grafana/sobek/builtin_json.go b/vendor/github.com/grafana/sobek/builtin_json.go index 2b2b7d02f..ffe8a30ca 100644 --- a/vendor/github.com/grafana/sobek/builtin_json.go +++ b/vendor/github.com/grafana/sobek/builtin_json.go @@ -364,6 +364,10 @@ func (ctx *_builtinJSON_stringifyContext) str(key Value, holder *Object) bool { case *valueBigInt: ctx.r.typeErrorResult(true, "Do not know how to serialize a BigInt") case *Object: + if value1.self.className() == classRawJSON { + ctx.buf.WriteString(value1.self.getStr("rawJSON", nil).String()) + return true + } for _, object := range ctx.stack { if value1.SameAs(object) { ctx.r.typeErrorResult(true, "Converting circular structure to JSON") @@ -528,6 +532,50 @@ func (ctx *_builtinJSON_stringifyContext) quote(str String) { ctx.buf.WriteByte('"') } +func (r *Runtime) builtinJSON_rawJSON(call FunctionCall) Value { + arg := call.Argument(0) + + var jsonString String + switch dd := arg.(type) { + case String: + jsonString = dd + if jsonString.Length() == 0 { + panic(r.newSyntaxError("\"\" is unacceptable as raw JSON")) + } + first := jsonString.CharAt(0) + last := jsonString.CharAt(jsonString.Length() - 1) + if first == '{' || first == '[' || + first == ' ' || first == '\n' || first == '\r' || first == '\t' || + last == ' ' || last == '\n' || last == '\r' || last == '\t' { + panic(r.newSyntaxError("\"" + arg.String() + "\" is unacceptable as raw JSON")) + } + if !json.Valid([]byte(jsonString.String())) { + panic(r.newSyntaxError("\"" + arg.String() + "\" is not a valid JSON")) + } + case valueBool, valueInt, *valueBigInt, valueFloat, valueNull: + jsonString = dd.toString() + case *Symbol: + panic(r.NewTypeError("Cannot convert a Symbol value to a string")) + default: + panic(r.newSyntaxError(arg.String() + " is not a valid JSON")) + } + + o := r.newBaseObject(nil, classRawJSON) + o._putProp("rawJSON", jsonString, false, true, false) + o.preventExtensions(true) + return o.val +} + +func (r *Runtime) builtinJSON_isRawJSON(call FunctionCall) Value { + arg := call.Argument(0) + if o, ok := arg.(*Object); ok { + if o.self.className() == classRawJSON { + return valueTrue + } + } + return valueFalse +} + func (r *Runtime) getJSON() *Object { ret := r.global.JSON if ret == nil { @@ -536,6 +584,8 @@ func (r *Runtime) getJSON() *Object { r.global.JSON = ret JSON._putProp("parse", r.newNativeFunc(r.builtinJSON_parse, "parse", 2), true, false, true) JSON._putProp("stringify", r.newNativeFunc(r.builtinJSON_stringify, "stringify", 3), true, false, true) + JSON._putProp("rawJSON", r.newNativeFunc(r.builtinJSON_rawJSON, "rawJSON", 1), true, false, true) + JSON._putProp("isRawJSON", r.newNativeFunc(r.builtinJSON_isRawJSON, "isRawJSON", 1), true, false, true) JSON._putSym(SymToStringTag, valueProp(asciiString(classJSON), false, false, true)) } return ret diff --git a/vendor/github.com/grafana/sobek/builtin_promise.go b/vendor/github.com/grafana/sobek/builtin_promise.go index bc05f7682..8a6e99605 100644 --- a/vendor/github.com/grafana/sobek/builtin_promise.go +++ b/vendor/github.com/grafana/sobek/builtin_promise.go @@ -503,9 +503,7 @@ func (r *Runtime) promise_any(call FunctionCall) Value { errors[index] = call.Argument(0) remainingElementsCount-- if remainingElementsCount == 0 { - _error := r.builtin_new(r.getAggregateError(), nil) - _error.self._putProp("errors", r.newArrayValues(errors), true, false, true) - pcap.reject(_error) + pcap.reject(r.newAggregateErrorErrors(errors)) } return _undefined }, "", 1) @@ -515,9 +513,7 @@ func (r *Runtime) promise_any(call FunctionCall) Value { }) remainingElementsCount-- if remainingElementsCount == 0 { - _error := r.builtin_new(r.getAggregateError(), nil) - _error.self._putProp("errors", r.newArrayValues(errors), true, false, true) - pcap.reject(_error) + pcap.reject(r.newAggregateErrorErrors(errors)) } }) return pcap.promise diff --git a/vendor/github.com/grafana/sobek/builtin_regexp.go b/vendor/github.com/grafana/sobek/builtin_regexp.go index 552038b2b..0e86683b0 100644 --- a/vendor/github.com/grafana/sobek/builtin_regexp.go +++ b/vendor/github.com/grafana/sobek/builtin_regexp.go @@ -302,7 +302,7 @@ func compileRegexp(patternStr, flags string) (p *regexpPattern, err error) { func (r *Runtime) _newRegExp(patternStr String, flags string, proto *Object) *regexpObject { pattern, err := compileRegexpFromValueString(patternStr, flags) if err != nil { - panic(r.newSyntaxError(err.Error(), -1)) + panic(r.newSyntaxError(err.Error())) } return r.newRegExpp(pattern, patternStr, proto) } @@ -400,7 +400,7 @@ func (r *Runtime) regexpproto_compile(call FunctionCall) Value { } pattern, err = compileRegexpFromValueString(source, flags) if err != nil { - panic(r.newSyntaxError(err.Error(), -1)) + panic(r.newSyntaxError(err.Error())) } this.pattern = pattern this.source = source diff --git a/vendor/github.com/grafana/sobek/builtin_set.go b/vendor/github.com/grafana/sobek/builtin_set.go index 45d956f11..f52e4526e 100644 --- a/vendor/github.com/grafana/sobek/builtin_set.go +++ b/vendor/github.com/grafana/sobek/builtin_set.go @@ -109,6 +109,22 @@ func (so *setObject) exportToMap(dst reflect.Value, typ reflect.Type, ctx *objec return nil } +func (r *Runtime) newSet(prototype *Object) *setObject { + o := &Object{runtime: r} + so := &setObject{} + so.class = classObject + so.val = o + so.extensible = true + o.self = so + so.prototype = prototype + so.init() + return so +} + +func (r *Runtime) newSetObject() *setObject { + return r.newSet(r.getSetPrototype()) +} + func (r *Runtime) setProto_add(call FunctionCall) Value { thisObj := r.toObject(call.This) so, ok := thisObj.self.(*setObject) @@ -188,6 +204,215 @@ func (r *Runtime) setProto_getSize(call FunctionCall) Value { return intToValue(int64(so.m.size)) } +func (r *Runtime) setProto_difference(call FunctionCall) Value { + thisObj := r.toObject(call.This) + so, ok := thisObj.self.(*setObject) + if !ok { + panic(r.NewTypeError("Method Set.prototype.difference called on incompatible receiver %s", r.objectproto_toString(FunctionCall{This: thisObj}))) + } + otherRecord := r.getSetRecord(call.Argument(0)) + result := r.newSetObject() + // 4. Let resultSetData be a copy of set.[[SetData]]. + + // 5. If SetDataSize(set.[[SetData]]) ≤ otherRecord.[[Size]], then + if so.m.size <= otherRecord.size { + // We can skip the copy if we are certain that the other set is a native Set object + if otherRecord.isStd() { + otherSet := otherRecord.stdObj + iter := so.m.newIter() + for { + entry := iter.next() + if entry == nil { + break + } + if !otherSet.m.has(entry.key) { + result.m.set(entry.key, nil) + } + } + } else { + so.m.copyTo(result.m) + iter := so.m.newIter() + for { + entry := iter.next() + if entry == nil { + break + } + if otherRecord.has(entry.key) { + result.m.remove(entry.key) + } + } + } + } else { + so.m.copyTo(result.m) + otherRecord.iterateKeys(func(key Value) bool { + result.m.remove(key) + return true + }) + } + return result.val +} + +func (r *Runtime) setProto_intersection(call FunctionCall) Value { + thisObj := r.toObject(call.This) + so, ok := thisObj.self.(*setObject) + if !ok { + panic(r.NewTypeError("Method Set.prototype.intersection called on incompatible receiver %s", r.objectproto_toString(FunctionCall{This: thisObj}))) + } + otherRecord := r.getSetRecord(call.Argument(0)) + result := r.newSetObject() + + if so.m.size <= otherRecord.size { + iter := so.m.newIter() + for { + entry := iter.next() + if entry == nil { + break + } + if otherRecord.has(entry.key) { + result.m.set(entry.key, nil) + } + } + } else { + otherRecord.iterateKeys(func(key Value) bool { + if so.m.has(key) { + result.m.set(key, nil) + } + return true + }) + } + return result.val +} + +func (r *Runtime) setProto_isDisjointFrom(call FunctionCall) Value { + thisObj := r.toObject(call.This) + so, ok := thisObj.self.(*setObject) + if !ok { + panic(r.NewTypeError("Method Set.prototype.isDisjointFrom called on incompatible receiver %s", r.objectproto_toString(FunctionCall{This: thisObj}))) + } + otherRecord := r.getSetRecord(call.Argument(0)) + + if so.m.size <= otherRecord.size { + iter := so.m.newIter() + for { + entry := iter.next() + if entry == nil { + break + } + if otherRecord.has(entry.key) { + return valueFalse + } + } + return valueTrue + } + + result := valueTrue + otherRecord.iterateKeys(func(key Value) bool { + if so.m.has(key) { + result = valueFalse + return false + } + return true + }) + return result +} + +func (r *Runtime) setProto_isSubsetOf(call FunctionCall) Value { + thisObj := r.toObject(call.This) + so, ok := thisObj.self.(*setObject) + if !ok { + panic(r.NewTypeError("Method Set.prototype.isSubsetOf called on incompatible receiver %s", r.objectproto_toString(FunctionCall{This: thisObj}))) + } + otherRecord := r.getSetRecord(call.Argument(0)) + + if so.m.size > otherRecord.size { + return valueFalse + } + + iter := so.m.newIter() + for { + entry := iter.next() + if entry == nil { + break + } + if !otherRecord.has(entry.key) { + return valueFalse + } + } + return valueTrue +} + +func (r *Runtime) setProto_isSupersetOf(call FunctionCall) Value { + thisObj := r.toObject(call.This) + so, ok := thisObj.self.(*setObject) + if !ok { + panic(r.NewTypeError("Method Set.prototype.isSupersetOf called on incompatible receiver %s", r.objectproto_toString(FunctionCall{This: thisObj}))) + } + otherRecord := r.getSetRecord(call.Argument(0)) + + if so.m.size < otherRecord.size { + return valueFalse + } + + result := valueTrue + otherRecord.iterateKeys(func(key Value) bool { + if !so.m.has(key) { + result = valueFalse + return false + } + return true + }) + return result +} + +func (r *Runtime) setProto_symmetricDifference(call FunctionCall) Value { + thisObj := r.toObject(call.This) + so, ok := thisObj.self.(*setObject) + if !ok { + panic(r.NewTypeError("Method Set.prototype.symmetricDifference called on incompatible receiver %s", r.objectproto_toString(FunctionCall{This: thisObj}))) + } + otherRecord := r.getSetRecord(call.Argument(0)) + result := r.newSetObject() + so.m.copyTo(result.m) + + otherRecord.iterateKeys(func(key Value) bool { + // ii. Let resultIndex be SetDataIndex(resultSetData, next). + // iii. If resultIndex is not-found, let alreadyInResult be false; else let alreadyInResult be true. + alreadyInResult := result.m.has(key) + // iv. If SetDataHas(set.[[SetData]], next) is true, then + if so.m.has(key) { + // 1. If alreadyInResult is true, set resultSetData[resultIndex] to empty. + if alreadyInResult { + result.m.remove(key) + } + // v. Else, + } else { + // 1. If alreadyInResult is false, append next to resultSetData. + if !alreadyInResult { + result.m.set(key, nil) + } + } + return true + }) + return result.val +} + +func (r *Runtime) setProto_union(call FunctionCall) Value { + thisObj := r.toObject(call.This) + so, ok := thisObj.self.(*setObject) + if !ok { + panic(r.NewTypeError("Method Set.prototype.union called on incompatible receiver %s", r.objectproto_toString(FunctionCall{This: thisObj}))) + } + otherRecord := r.getSetRecord(call.Argument(0)) + result := r.newSetObject() + so.m.copyTo(result.m) + + otherRecord.iterateKeys(func(key Value) bool { + result.m.set(key, nil) + return true + }) + return result.val +} + func (r *Runtime) setProto_values(call FunctionCall) Value { return r.createSetIterator(call.This, iterationKindValue) } @@ -197,15 +422,8 @@ func (r *Runtime) builtin_newSet(args []Value, newTarget *Object) *Object { panic(r.needNew("Set")) } proto := r.getPrototypeFromCtor(newTarget, r.global.Set, r.global.SetPrototype) - o := &Object{runtime: r} - - so := &setObject{} - so.class = classObject - so.val = o - so.extensible = true - o.self = so - so.prototype = proto - so.init() + so := r.newSet(proto) + o := so.val if len(args) > 0 { if arg := args[0]; arg != nil && arg != _undefined && arg != _null { adder := so.getStr("add", nil) @@ -271,6 +489,93 @@ func (r *Runtime) setIterProto_next(call FunctionCall) Value { panic(r.NewTypeError("Method Set Iterator.prototype.next called on incompatible receiver %s", r.objectproto_toString(FunctionCall{This: thisObj}))) } +type setRecord struct { + o *Object + size int + has func(Value) bool + iterateKeys func(func(Value) bool) + stdObj *setObject +} + +func (sr *setRecord) isStd() bool { + return sr.stdObj != nil +} + +func (r *Runtime) getSetRecord(value Value) *setRecord { + // 1. If obj is not an Object, throw a TypeError exception. + o, ok := value.(*Object) + if !ok { + panic(r.NewTypeError("value is not an Object")) + } + + // 2. Let rawSize be ? Get(obj, "size"). + rawSize := nilSafe(o.self.getStr("size", nil)) + // 3. Let numberSize be ? ToNumber(rawSize). + // 4. NOTE: If rawSize is undefined, then numberSize will be NaN. + numberSize := rawSize.ToNumber() + // 5. If numberSize is NaN, throw a TypeError exception. + if IsNaN(numberSize) { + panic(r.NewTypeError("size is NaN")) + } + // 6. Let intSize be ! ToIntegerOrInfinity(numberSize). + intSize := toInt(numberSize) + // 7. If intSize < 0, throw a RangeError exception. + if intSize < 0 { + panic(r.newErrorf(r.getRangeError(), "Invalid size: %d", intSize)) + } + + // 8. Let has be ? Get(obj, "has"). + has := o.self.getStr("has", nil) + // 9. If IsCallable(has) is false, throw a TypeError exception. + hasFn := toMethod(has) + if hasFn == nil { + panic(r.NewTypeError("Object does not have a valid 'has' method")) + } + + // 10. Let keys be ? Get(obj, "keys"). + keys := o.self.getStr("keys", nil) + // 11. If IsCallable(keys) is false, throw a TypeError exception. + keysFn := toMethod(keys) + if keysFn == nil { + panic(r.NewTypeError("Object does not have a valid 'keys' method")) + } + + // 12. Return a new Set Record { [[SetObject]]: obj, [[Size]]: intSize, [[Has]]: has, [[Keys]]: keys }. + + // common case for native Set objects + if setObj, ok := o.self.(*setObject); ok && has == r.global.setHas && keys == r.global.setValues { + return &setRecord{ + o: o, + size: intSize, + stdObj: setObj, + has: setObj.m.has, + iterateKeys: func(f func(Value) bool) { + iter := setObj.m.newIter() + for { + entry := iter.next() + if entry == nil { + break + } + if !f(entry.key) { + break + } + } + }, + } + } + + return &setRecord{ + o: o, + size: intSize, + has: func(v Value) bool { + return nilSafe(hasFn(FunctionCall{This: o, Arguments: []Value{v}})).ToBoolean() + }, + iterateKeys: func(f func(Value) bool) { + r.forOfMethod(o, keysFn, f) + }, + } +} + func (r *Runtime) createSetProto(val *Object) objectImpl { o := newBaseObjectObj(val, r.global.ObjectPrototype, classObject) @@ -281,7 +586,8 @@ func (r *Runtime) createSetProto(val *Object) objectImpl { o._putProp("clear", r.newNativeFunc(r.setProto_clear, "clear", 0), true, false, true) o._putProp("delete", r.newNativeFunc(r.setProto_delete, "delete", 1), true, false, true) o._putProp("forEach", r.newNativeFunc(r.setProto_forEach, "forEach", 1), true, false, true) - o._putProp("has", r.newNativeFunc(r.setProto_has, "has", 1), true, false, true) + r.global.setHas = r.newNativeFunc(r.setProto_has, "has", 1) + o._putProp("has", r.global.setHas, true, false, true) o.setOwnStr("size", &valueProperty{ getterFunc: r.newNativeFunc(r.setProto_getSize, "get size", 0), accessor: true, @@ -289,11 +595,19 @@ func (r *Runtime) createSetProto(val *Object) objectImpl { configurable: true, }, true) - valuesFunc := r.newNativeFunc(r.setProto_values, "values", 0) - o._putProp("values", valuesFunc, true, false, true) - o._putProp("keys", valuesFunc, true, false, true) + o._putProp("difference", r.newNativeFunc(r.setProto_difference, "difference", 1), true, false, true) + o._putProp("intersection", r.newNativeFunc(r.setProto_intersection, "intersection", 1), true, false, true) + o._putProp("isDisjointFrom", r.newNativeFunc(r.setProto_isDisjointFrom, "isDisjointFrom", 1), true, false, true) + o._putProp("isSubsetOf", r.newNativeFunc(r.setProto_isSubsetOf, "isSubsetOf", 1), true, false, true) + o._putProp("isSupersetOf", r.newNativeFunc(r.setProto_isSupersetOf, "isSupersetOf", 1), true, false, true) + o._putProp("symmetricDifference", r.newNativeFunc(r.setProto_symmetricDifference, "symmetricDifference", 1), true, false, true) + o._putProp("union", r.newNativeFunc(r.setProto_union, "union", 1), true, false, true) + + r.global.setValues = r.newNativeFunc(r.setProto_values, "values", 0) + o._putProp("values", r.global.setValues, true, false, true) + o._putProp("keys", r.global.setValues, true, false, true) o._putProp("entries", r.newNativeFunc(r.setProto_entries, "entries", 0), true, false, true) - o._putSym(SymIterator, valueProp(valuesFunc, true, false, true)) + o._putSym(SymIterator, valueProp(r.global.setValues, true, false, true)) o._putSym(SymToStringTag, valueProp(asciiString(classSet), false, false, true)) return o diff --git a/vendor/github.com/grafana/sobek/builtin_typedarrays.go b/vendor/github.com/grafana/sobek/builtin_typedarrays.go index 6ca87d7b5..8368f58d4 100644 --- a/vendor/github.com/grafana/sobek/builtin_typedarrays.go +++ b/vendor/github.com/grafana/sobek/builtin_typedarrays.go @@ -1,6 +1,9 @@ package sobek import ( + stdbase64 "encoding/base64" + stdhex "encoding/hex" + "errors" "fmt" "math" "sort" @@ -1506,6 +1509,17 @@ func (r *Runtime) _newTypedArrayFromTypedArray(src *typedArrayObject, newTarget return dst.val } +// Creates typedArrayObject from directly by data to avoiding extra allocation. +// Caller must not retain or modify it, because the underlying ArrayBuffer takes ownership of it. +// len(data) must be a multiple of the element size. +func (r *Runtime) newTypedArrayWithData(data []byte, newTarget *Object, taCtor typedArrayObjectCtor, proto *Object) *typedArrayObject { + ab := r._newArrayBuffer(r.getArrayBufferPrototype(), nil) + ab.data = data + ta := taCtor(ab, 0, 0, r.getPrototypeFromCtor(newTarget, nil, proto)) + ta.length = len(data) / ta.elemSize + return ta +} + func (r *Runtime) _newTypedArray(args []Value, newTarget *Object, taCtor typedArrayObjectCtor, proto *Object) *Object { if newTarget == nil { panic(r.needNew("TypedArray")) @@ -1575,6 +1589,203 @@ func (r *Runtime) newBigUint64Array(args []Value, newTarget, proto *Object) *Obj return r._newTypedArray(args, newTarget, r.newBigUint64ArrayObject, proto) } +func (r *Runtime) uint8Array_fromHex(call FunctionCall) Value { + s, ok := call.Argument(0).(String) + if !ok { + panic(r.NewTypeError("Uint8Array.fromHex requires a string")) + } + b, err := fromHex(s) + if err != nil { + panic(r.newSyntaxError(err.Error())) // SyntaxError for odd-length-input or illegal-characters + } + return r.newTypedArrayWithData(b, r.getUint8Array(), r.newUint8ArrayObject, nil).val +} + +func (r *Runtime) uint8Array_fromBase64(call FunctionCall) Value { + // 1. If string is not a String, throw a TypeError exception. + s, ok := call.Argument(0).(String) + if !ok { + panic(r.NewTypeError("Uint8Array.fromBase64 requires a string")) + } + // 2. Let opts be ? GetOptionsObject(options). + // 3.-8. Get and validate "alphabet" and "lastChunkHandling". + decodeMap, lastChunkHandling := r.parseFromBase64Options(call.Argument(1)) + + // 9. Let result be FromBase64(string, alphabet, lastChunkHandling). + _, b, err := fromBase64(s, decodeMap, lastChunkHandling) + if err != nil { + panic(r.newSyntaxError(err.Error())) + } + return r.newTypedArrayWithData(b, r.getUint8Array(), r.newUint8ArrayObject, nil).val +} + +// parseFromBase64Options reads the "alphabet" and "lastChunkHandling" options shared by +// Uint8Array.fromBase64 and Uint8Array.prototype.setFromBase64. +func (r *Runtime) parseFromBase64Options(options Value) (decodeMap *[256]byte, lastChunkHandling base64LastChunkHandling) { + // The defaults above are what an empty options object yields, so an undefined + // one needs no allocation to be read. + if options == nil || options == _undefined { + return &base64DecodeMap, base64LastChunkHandlingLoose + } + opts, ok := options.(*Object) + if !ok { + panic(r.NewTypeError("Options is not an object")) + } + if v := opts.self.getStr("alphabet", nil); v != nil && v != _undefined { + str, ok := v.(String) + if ok { + switch str.String() { + case "base64": + decodeMap = &base64DecodeMap + case "base64url": + decodeMap = &base64DecodeMapUrl + } + } + if decodeMap == nil { + panic(r.NewTypeError("alphabet must be \"base64\" or \"base64url\"")) + } + } else { + decodeMap = &base64DecodeMap + } + if v := opts.self.getStr("lastChunkHandling", nil); v != nil && v != _undefined { + str, ok := v.(String) + if ok { + switch str.String() { + case "loose": + lastChunkHandling = base64LastChunkHandlingLoose + case "strict": + lastChunkHandling = base64LastChunkHandlingStrict + case "stop-before-partial": + lastChunkHandling = base64LastChunkHandlingStop + } + } + if lastChunkHandling == base64LastChunkHandlingInvalid { + panic(r.NewTypeError(`lastChunkHandling must be "loose", "strict" or "stop-before-partial"`)) + } + } else { + lastChunkHandling = base64LastChunkHandlingLoose + } + return +} + +func (r *Runtime) uint8ArrayProto_toBase64(call FunctionCall) Value { + ta := r.validateUint8Array(call.This) + enc := r.parseToBase64Encoding(call.Argument(0)) + // GetUint8ArrayBytes runs after the option getters, which may have detached the buffer. + toEnc := r.getUint8ArrayBytes(ta) + buf := make([]byte, enc.EncodedLen(len(toEnc))) + enc.Encode(buf, toEnc) + return asciiString(unsafe.String(unsafe.SliceData(buf), len(buf))) +} + +// parseToBase64Encoding reads the "alphabet" and "omitPadding" options of +// Uint8Array.prototype.toBase64(section 3. to 10.) and returns the encoding they select: +// the base64 encoding of section 4 of RFC 4648, or the base64url encoding of section 5. +func (r *Runtime) parseToBase64Encoding(options Value) *stdbase64.Encoding { + // The defaults are "base64" and omitPadding false. + if options == nil || options == _undefined { + return stdbase64.StdEncoding + } + // 3. Let opts be ? GetOptionsObject(options). + opts, ok := options.(*Object) + if !ok { + panic(r.NewTypeError("Options is not an object")) + } + // 4. Let alphabet be ? Get(opts, "alphabet"). + alphabetVal := nilSafe(opts.self.getStr("alphabet", nil)) + // 5. If alphabet is undefined, set alphabet to "base64". + alphabet := "base64" + if alphabetVal != _undefined { + str, ok := alphabetVal.(String) + if ok { + alphabet = str.String() + } + // 6. If alphabet is neither "base64" nor "base64url", throw a TypeError exception. + if !ok || (alphabet != "base64" && alphabet != "base64url") { + panic(r.NewTypeError(`alphabet must be "base64" or "base64url"`)) + } + } + // 7.-8. Let omitPadding be ToBoolean(? Get(opts, "omitPadding")). + omitPadding := false + if v := opts.self.getStr("omitPadding", nil); v != nil { + omitPadding = v.ToBoolean() + } + if alphabet == "base64" { + if omitPadding { + return stdbase64.RawStdEncoding + } + return stdbase64.StdEncoding + } + if omitPadding { + return stdbase64.RawURLEncoding + } + return stdbase64.URLEncoding +} + +func (r *Runtime) uint8ArrayProto_toHex(call FunctionCall) Value { + ta := r.validateUint8Array(call.This) + toEnc := r.getUint8ArrayBytes(ta) + buf := make([]byte, stdhex.EncodedLen(len(toEnc))) + stdhex.Encode(buf, toEnc) + return asciiString(unsafe.String(unsafe.SliceData(buf), len(buf))) +} + +func (r *Runtime) uint8ArrayProto_setFromHex(call FunctionCall) Value { + // 2. Perform ? ValidateUint8Array(into). + ta := r.validateUint8Array(call.This) + // 3. If string is not a String, throw a TypeError exception. + s, ok := call.Argument(0).(String) + if !ok { + panic(r.NewTypeError("Uint8Array.prototype.setFromHex requires a string")) + } + + // 6. Let result be FromHex(string, byteLength). + into := r.getUint8ArrayBytes(ta) + // Whatever was decoded before the error has already been written into the + // destination, as required by the spec (SetUint8ArrayBytes runs before the throw). + // Writes data directly, instead of using [SetUint8ArrayBytes], to avoiding extra allocation. + written, err := fromHexInto(s, len(into), into) + if err != nil { + panic(r.newSyntaxError(err.Error())) + } + res := r.NewObject() + res.self.setOwnStr("read", intToValue(int64(2*written)), false) + res.self.setOwnStr("written", intToValue(int64(written)), false) + return res +} + +func (r *Runtime) uint8ArrayProto_setFromBase64(call FunctionCall) Value { + // 2. Perform ? ValidateUint8Array(ta). + ta := r.validateUint8Array(call.This) + // 3. If string is not a String, throw a TypeError exception. + s, ok := call.Argument(0).(String) + if !ok { + panic(r.NewTypeError("Uint8Array.prototype.setFromBase64 requires a string")) + } + // 4. Let opts be ? GetOptionsObject(options). + // 5.-10. Get and validate "alphabet" and "lastChunkHandling". + decodeMap, lastChunkHandling := r.parseFromBase64Options(call.Argument(1)) + + // 11.-12. Let taRecord be ? ValidateTypedArrayBounds(taRecord, seq-cst), + // and let byteLength be TypedArrayLength(taRecord). + // The option getters above may have detached the buffer; getUint8ArrayBytes throws then. + into := r.getUint8ArrayBytes(ta) + // 13.-18. Let result be FromBase64(string, alphabet, lastChunkHandling, byteLength). + // Whatever was decoded before an error has already been written into the + // destination, as required by the spec (SetUint8ArrayBytes runs before the throw). + // Writes data directly, instead of using [SetUint8ArrayBytes], to avoiding extra allocation. + read, written, err := fromBase64Into(s, decodeMap, lastChunkHandling, into) + + if err != nil { + panic(r.newSyntaxError(err.Error())) + } + + res := r.NewObject() + res.self.setOwnStr("read", intToValue(int64(read)), false) + res.self.setOwnStr("written", intToValue(int64(written)), false) + return res +} + func (r *Runtime) createArrayBufferProto(val *Object) objectImpl { b := newBaseObjectObj(val, r.global.ObjectPrototype, classObject) byteLengthProp := &valueProperty{ @@ -1621,7 +1832,7 @@ func (r *Runtime) getTypedArray() *Object { return ret } -func (r *Runtime) createTypedArrayCtor(val *Object, ctor func(args []Value, newTarget, proto *Object) *Object, name unistring.String, bytesPerElement int) { +func (r *Runtime) createTypedArrayCtor(val *Object, ctor func(args []Value, newTarget, proto *Object) *Object, name unistring.String, bytesPerElement int) *baseObject { p := r.newBaseObject(r.getTypedArrayPrototype(), classObject) o := r.newNativeConstructOnly(val, func(args []Value, newTarget *Object) *Object { return ctor(args, newTarget, p.val) @@ -1633,6 +1844,7 @@ func (r *Runtime) createTypedArrayCtor(val *Object, ctor func(args []Value, newT bpe := intToValue(int64(bytesPerElement)) o._putProp("BYTES_PER_ELEMENT", bpe, false, false, false) p._putProp("BYTES_PER_ELEMENT", bpe, false, false, false) + return p } func addTypedArrays(t *objectTemplate) { @@ -1767,7 +1979,20 @@ func (r *Runtime) getUint8Array() *Object { if ret == nil { ret = &Object{runtime: r} r.global.Uint8Array = ret - r.createTypedArrayCtor(ret, r.newUint8Array, "Uint8Array", 1) + p := r.createTypedArrayCtor(ret, r.newUint8Array, "Uint8Array", 1) + + // Applies Uint8Array only, not other TypedArrays. + // implements Uint8Array.fromHex/Uint8Array.fromBase64 static method + o := ret.self.(*nativeFuncObject) + o._putProp("fromBase64", r.newNativeFunc(r.uint8Array_fromBase64, "fromBase64", 1), true, false, true) + o._putProp("fromHex", r.newNativeFunc(r.uint8Array_fromHex, "fromHex", 1), true, false, true) + + // implements Uint8Array.prototype.setFromHex/Uint8Array.prototype.setFromBase64 method + p._putProp("setFromBase64", r.newNativeFunc(r.uint8ArrayProto_setFromBase64, "setFromBase64", 1), true, false, true) + p._putProp("setFromHex", r.newNativeFunc(r.uint8ArrayProto_setFromHex, "setFromHex", 1), true, false, true) + // implements Uint8Array.prototype.toHex/Uint8Array.prototype.toBase64 method + p._putProp("toBase64", r.newNativeFunc(r.uint8ArrayProto_toBase64, "toBase64", 0), true, false, true) + p._putProp("toHex", r.newNativeFunc(r.uint8ArrayProto_toHex, "toHex", 0), true, false, true) } return ret } @@ -1977,3 +2202,58 @@ func (r *Runtime) getArrayBuffer() *Object { } return ret } + +// TC39 Abstract Operations for Uint8Array Objects - [ValidateUint8Array(ta)]. +// If ta.[[TypedArrayName]] is not "Uint8Array", throw a TypeError exception. +// +// [ValidateUint8Array(ta)]: https://tc39.es/ecma262/multipage/indexed-collections.html#sec-validateuint8array +func (r *Runtime) validateUint8Array(v Value) *typedArrayObject { + if obj, ok := v.(*Object); ok { + if ta, ok := obj.self.(*typedArrayObject); ok { + if _, ok := ta.typedArray.(*uint8Array); ok { + // Don't call ensureNotDetached. + // Because Uint8Array.prototype.toBase64 checks for detachedness after side-effects are finished + return ta + } + } + } + panic(r.NewTypeError("Receiver must be a Uint8Array")) +} + +// TC39 Abstract Operations for Uint8Array Objects - [GetUint8ArrayBytes(ta)]. +// +// [GetUint8ArrayBytes(ta)]: https://tc39.es/ecma262/multipage/indexed-collections.html#sec-getuint8arraybytes +func (r *Runtime) getUint8ArrayBytes(ta *typedArrayObject) []byte { + ta.viewedArrayBuf.ensureNotDetached(true) + return ta.viewedArrayBuf.data[ta.offset : ta.offset+ta.length] +} + +// https://tc39.es/ecma262/multipage/indexed-collections.html#sec-frombase64 +func fromBase64Into(s String, decodeMap *[256]byte, lastChunkHandling base64LastChunkHandling, dst []byte) (read, written int, err error) { + a, u := devirtualizeString(s) + if u == nil { + return base64DecodeAscii(a, s, decodeMap, lastChunkHandling, dst) + } + + return base64DecodeUnicode(u, s, decodeMap, lastChunkHandling, dst) +} + +// https://tc39.es/ecma262/multipage/indexed-collections.html#sec-fromhex +func fromHex(s String) ([]byte, error) { + b, err := stdhex.DecodeString(s.String()) + return b, err +} + +// https://tc39.es/ecma262/multipage/indexed-collections.html#sec-fromhex +func fromHexInto(s String, maxLength int, dst []byte) (written int, err error) { + // Length() counts UTF-16 code units. + length := s.Length() + if length%2 != 0 { + return 0, errors.New("string should have an even number of characters") + } + // while read < length and the number of elements in bytes < maxLength. + if length > maxLength*2 { + s = s.Substring(0, maxLength*2) + } + return stdhex.Decode(dst, []byte(s.String())) +} diff --git a/vendor/github.com/grafana/sobek/builtin_weakmap.go b/vendor/github.com/grafana/sobek/builtin_weakmap.go index 14294acfc..760a1b36a 100644 --- a/vendor/github.com/grafana/sobek/builtin_weakmap.go +++ b/vendor/github.com/grafana/sobek/builtin_weakmap.go @@ -7,52 +7,52 @@ import ( ) type weakMap struct { - m map[uint64]Value + m map[weak.Pointer[Object]]Value sync.Mutex } func (wm *weakMap) set(key *Object, value Value) { - id := key.getId() + p := weak.Make(key) wm.Lock() - _, exists := wm.m[id] - wm.m[id] = value + _, exists := wm.m[p] + wm.m[p] = value wm.Unlock() if !exists { wmPtr := weak.Make(wm) // do not hold strong reference to wm so that it could be collected by GC - runtime.AddCleanup(key, func(id uint64) { + runtime.AddCleanup(key, func(p weak.Pointer[Object]) { wm := wmPtr.Value() if wm == nil { return } wm.Lock() - delete(wm.m, id) + delete(wm.m, p) wm.Unlock() - }, id) + }, p) } } func (wm *weakMap) get(key *Object) (res Value) { - id := key.getId() + p := weak.Make(key) wm.Lock() - res = wm.m[id] + res = wm.m[p] wm.Unlock() return } func (wm *weakMap) remove(key *Object) (removed bool) { - id := key.getId() + p := weak.Make(key) wm.Lock() - if _, removed = wm.m[id]; removed { - delete(wm.m, id) + if _, removed = wm.m[p]; removed { + delete(wm.m, p) } wm.Unlock() return } func (wm *weakMap) has(key *Object) bool { - id := key.getId() + p := weak.Make(key) wm.Lock() - _, exists := wm.m[id] + _, exists := wm.m[p] wm.Unlock() return exists } @@ -65,7 +65,7 @@ type weakMapObject struct { func (wmo *weakMapObject) init() { wmo.baseObject.init() wmo.m = weakMap{ - m: make(map[uint64]Value), + m: make(map[weak.Pointer[Object]]Value), } } diff --git a/vendor/github.com/grafana/sobek/builtin_weakset.go b/vendor/github.com/grafana/sobek/builtin_weakset.go index 9109c2c6d..4b2b1fbbe 100644 --- a/vendor/github.com/grafana/sobek/builtin_weakset.go +++ b/vendor/github.com/grafana/sobek/builtin_weakset.go @@ -1,5 +1,7 @@ package sobek +import "weak" + type weakSetObject struct { baseObject s weakMap @@ -8,7 +10,7 @@ type weakSetObject struct { func (ws *weakSetObject) init() { ws.baseObject.init() ws.s = weakMap{ - m: make(map[uint64]Value), + m: make(map[weak.Pointer[Object]]Value), } } diff --git a/vendor/github.com/grafana/sobek/ftoa/ftoa.go b/vendor/github.com/grafana/sobek/ftoa/ftoa.go index dd266ec46..6d64d74b8 100644 --- a/vendor/github.com/grafana/sobek/ftoa/ftoa.go +++ b/vendor/github.com/grafana/sobek/ftoa/ftoa.go @@ -536,7 +536,6 @@ func ftoa(d float64, mode int, biasUp bool, ndigits int, buf []byte) ([]byte, in b.Lsh(b, 1) j1 = b.Cmp(S) if (j1 > 0) || (j1 == 0 && (((dig & 1) == 1) || biasUp)) { - dig++ if dig == '9' { buf = append(buf, '9') buf, flag := roundOff(buf, startPos) @@ -546,6 +545,7 @@ func ftoa(d float64, mode int, biasUp bool, ndigits int, buf []byte) ([]byte, in } return buf, k + 1 } + dig++ } } buf = append(buf, dig) diff --git a/vendor/github.com/grafana/sobek/map.go b/vendor/github.com/grafana/sobek/map.go index 26dd400cf..bd2a885f8 100644 --- a/vendor/github.com/grafana/sobek/map.go +++ b/vendor/github.com/grafana/sobek/map.go @@ -167,3 +167,9 @@ func (m *orderedMap) clear() { m.hashTable = make(map[uint64]*mapEntry) m.size = 0 } + +func (m *orderedMap) copyTo(dest *orderedMap) { + for entry := m.iterFirst; entry != nil; entry = entry.iterNext { + dest.set(entry.key, entry.value) + } +} diff --git a/vendor/github.com/grafana/sobek/object.go b/vendor/github.com/grafana/sobek/object.go index acac475b0..4c1b97c73 100644 --- a/vendor/github.com/grafana/sobek/object.go +++ b/vendor/github.com/grafana/sobek/object.go @@ -5,7 +5,6 @@ import ( "math" "reflect" "sort" - "unsafe" "github.com/grafana/sobek/unistring" ) @@ -27,6 +26,7 @@ const ( classRegExp = "RegExp" classDate = "Date" classJSON = "JSON" + classRawJSON = "RawJSON" classGlobal = "global" classPromise = "Promise" @@ -454,6 +454,12 @@ func (o *baseObject) setProto(proto *Object, throw bool) bool { if current.SameAs(proto) { return true } + // 10.4.7 Immutable Prototype Exotic Objects + // Object.prototype seems like the only immutable prototype exotic object + if o.val == o.val.runtime.global.ObjectPrototype { + o.val.runtime.typeErrorResult(throw, "Immutable prototype object 'Object.prototype' cannot have their prototype set") + return false + } if !o.extensible { o.val.runtime.typeErrorResult(throw, "%s is not extensible", o.val) return false @@ -1617,10 +1623,6 @@ func (o *Object) defineOwnProperty(n Value, desc PropertyDescriptor, throw bool) } } -func (o *Object) getId() uint64 { - return uint64(uintptr(unsafe.Pointer(o))) -} - func (o *guardedObject) guard(props ...unistring.String) { if o.guardedProps == nil { o.guardedProps = make(map[unistring.String]struct{}) diff --git a/vendor/github.com/grafana/sobek/parser/regexp.go b/vendor/github.com/grafana/sobek/parser/regexp.go index 775fcbdd6..ff833c8eb 100644 --- a/vendor/github.com/grafana/sobek/parser/regexp.go +++ b/vendor/github.com/grafana/sobek/parser/regexp.go @@ -255,15 +255,25 @@ func (self *_RegExp_parser) scanBracket() { } self.pass() - for self.chr != -1 { - if self.chr == ']' { - break - } else if self.chr == '\\' { - self.read() - self.scanEscape(true) + if self.chr == '^' { + self.pass() + } + for self.chr != -1 && self.chr != ']' { + leftIsClass := self.scanClassAtom() + if self.unicode || self.chr != '-' { continue } - self.pass() + if self.offset >= self.length || self.str[self.offset] == ']' { + continue + } + if leftIsClass || self.nextIsCharacterClassEscape() { + // A '-' next to a class escape is a literal, not a range operator. + self.writeString(`\-`) + self.read() + } else { + self.pass() + } + self.scanClassAtom() } if self.chr != ']' { self.error(true, "Unterminated character class") @@ -272,6 +282,34 @@ func (self *_RegExp_parser) scanBracket() { self.pass() } +// scanClassAtom writes a single class atom and reports whether it stands for more than one character. +func (self *_RegExp_parser) scanClassAtom() bool { + if self.chr == '\\' { + self.read() + isClass := isCharacterClassEscape(self.chr) + self.scanEscape(true) + return isClass + } + if self.chr == '-' && !self.unicode { + // A '-' in atom position is a literal; escape it so re2 cannot pair it with the next atom. + self.writeString(`\-`) + self.read() + return false + } + self.pass() + return false +} + +// isCharacterClassEscape reports whether c is a class escape standing for more than one character. +func isCharacterClassEscape(c rune) bool { + return c == 'd' || c == 'D' || c == 's' || c == 'S' || c == 'w' || c == 'W' +} + +// nextIsCharacterClassEscape reports whether the input after the current character is a class escape. +func (self *_RegExp_parser) nextIsCharacterClassEscape() bool { + return self.offset+1 < self.length && self.str[self.offset] == '\\' && isCharacterClassEscape(rune(self.str[self.offset+1])) +} + // \... func (self *_RegExp_parser) scanEscape(inClass bool) { offset := self.chrOffset diff --git a/vendor/github.com/grafana/sobek/parser/statement.go b/vendor/github.com/grafana/sobek/parser/statement.go index f9aee304d..620500853 100644 --- a/vendor/github.com/grafana/sobek/parser/statement.go +++ b/vendor/github.com/grafana/sobek/parser/statement.go @@ -982,7 +982,6 @@ func (self *_parser) parseSourceMap() *sourcemap.Consumer { } if err != nil { - self.error(file.Idx(0), "Could not load source map: %v", err) return nil } if data == nil { @@ -992,7 +991,7 @@ func (self *_parser) parseSourceMap() *sourcemap.Consumer { if sm, err := sourcemap.Parse(self.file.Name(), data); err == nil { return sm } else { - self.error(file.Idx(0), "Could not parse source map: %v", err) + return nil } } return nil diff --git a/vendor/github.com/grafana/sobek/runtime.go b/vendor/github.com/grafana/sobek/runtime.go index bb95249f5..8971db619 100644 --- a/vendor/github.com/grafana/sobek/runtime.go +++ b/vendor/github.com/grafana/sobek/runtime.go @@ -143,6 +143,8 @@ type global struct { weakMapAdder *Object mapAdder *Object setAdder *Object + setHas *Object + setValues *Object arrayValues *Object arrayToString *Object @@ -489,7 +491,7 @@ func (r *Runtime) newReferenceError(name unistring.String) Value { return r.newErrorf(r.getReferenceError(), "%s is not defined", name) } -func (r *Runtime) newSyntaxError(msg string, offset int) Value { +func (r *Runtime) newSyntaxError(msg string) Value { return r.builtin_new(r.getSyntaxError(), []Value{newStringValue(msg)}) } @@ -2802,7 +2804,11 @@ func (ir *iteratorRecord) close() { // When using outside of Runtime.Run (i.e. when calling directly from Go code, not from a JS function implemented // in Go) it must be enclosed in Try. See the example. func (r *Runtime) ForOf(iterable Value, step func(curValue Value) (continueIteration bool)) { - iter := r.getIterator(iterable, nil) + r.forOfMethod(iterable, nil, step) +} + +func (r *Runtime) forOfMethod(iterable Value, method func(FunctionCall) Value, step func(curValue Value) (continueIteration bool)) { + iter := r.getIterator(iterable, method) for { value, ex := iter.step() if ex != nil { diff --git a/vendor/github.com/grafana/sobek/value.go b/vendor/github.com/grafana/sobek/value.go index 18f5b5ded..5c9d7348d 100644 --- a/vendor/github.com/grafana/sobek/value.go +++ b/vendor/github.com/grafana/sobek/value.go @@ -798,7 +798,7 @@ func (o *Object) ExportType() reflect.Type { } func (o *Object) hash(*maphash.Hash) uint64 { - return o.getId() + return uint64(uintptr(unsafe.Pointer(o))) } // Get an object's property by name. diff --git a/vendor/modules.txt b/vendor/modules.txt index 479601cbb..26f08a2bc 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -106,7 +106,7 @@ github.com/chromedp/cdproto/webauthn # github.com/chromedp/sysutil v1.1.0 ## explicit; go 1.23 github.com/chromedp/sysutil -# github.com/dlclark/regexp2/v2 v2.5.2 +# github.com/dlclark/regexp2/v2 v2.7.2 ## explicit; go 1.25 github.com/dlclark/regexp2/v2 github.com/dlclark/regexp2/v2/helpers @@ -181,7 +181,7 @@ github.com/grafana/k6-cloud-openapi-client-go/k6 # github.com/grafana/k6provider v0.5.0 ## explicit; go 1.24.0 github.com/grafana/k6provider -# github.com/grafana/sobek v0.0.0-20260727154728-7781506a890f +# github.com/grafana/sobek v0.0.0-20260908083152-4698bc773ae7 ## explicit; go 1.25.0 github.com/grafana/sobek github.com/grafana/sobek/ast From 8d06114777191d21ef885d05c5f8aa9e1ed838ae Mon Sep 17 00:00:00 2001 From: kausthubhk Date: Fri, 11 Sep 2026 20:00:16 +0530 Subject: [PATCH 148/182] Fix sending duration with HTTPS proxies (#6349) * Fix sending duration with HTTPS proxies * Explain GotConn sending boundary --- lib/netext/httpext/tracer.go | 19 +++++-------------- lib/netext/httpext/tracer_test.go | 24 +++++++++++++++++++++++- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/lib/netext/httpext/tracer.go b/lib/netext/httpext/tracer.go index 81b35cc14..673770d8a 100644 --- a/lib/netext/httpext/tracer.go +++ b/lib/netext/httpext/tracer.go @@ -343,21 +343,12 @@ func (t *Tracer) Done() *Trail { if tlsHandshakeDone != 0 && tlsHandshakeStart != 0 { trail.TLSHandshaking = time.Duration(tlsHandshakeDone - tlsHandshakeStart) } + // Sending starts once the connection is obtained, whether it is plain, TLS, + // reused, or tunneled through an HTTPS proxy. + if gotConn != 0 && wroteRequest > gotConn { + trail.Sending = time.Duration(wroteRequest - gotConn) + } if wroteRequest != 0 { - switch { - case tlsHandshakeDone != 0: - // If the request was sent over TLS, we need to use - // TLS Handshake Done time to calculate sending duration - trail.Sending = time.Duration(wroteRequest - tlsHandshakeDone) - case connectDone != 0: - // Otherwise, use the end of the normal connection - trail.Sending = time.Duration(wroteRequest - connectDone) - default: - // Finally, this handles the strange HTTP/2 case where the GotConn() hook - // gets called first, but with Reused=false - trail.Sending = time.Duration(wroteRequest - gotConn) - } - if gotFirstResponseByte != 0 { // We started receiving at least some response back diff --git a/lib/netext/httpext/tracer_test.go b/lib/netext/httpext/tracer_test.go index a4fb18126..bd89531a6 100644 --- a/lib/netext/httpext/tracer_test.go +++ b/lib/netext/httpext/tracer_test.go @@ -236,10 +236,32 @@ func TestTracerNegativeHttpSendingValues(t *testing.T) { builtinMetrics := metrics.RegisterBuiltinMetrics(registry) trail.SaveSamples(builtinMetrics, &metrics.TagsAndMeta{Tags: registry.RootTagSet()}) - require.True(t, trail.Sending > 0) + require.GreaterOrEqual(t, trail.Sending, time.Duration(0)) } } +func TestTracerSendingStartsAtGotConn(t *testing.T) { + t.Parallel() + + const interval = time.Millisecond + getConn := time.Now().Add(-5 * interval).UnixNano() + // With an HTTPS proxy and target, k6 keeps the first TLS handshake completion, + // which occurs before the target connection is available and GotConn() is called. + firstTLSHandshakeDone := getConn + int64(interval) + tracer := &Tracer{ + getConn: getConn, + tlsHandshakeDone: firstTLSHandshakeDone, + gotConn: firstTLSHandshakeDone + int64(2*interval), + wroteRequest: firstTLSHandshakeDone + int64(3*interval), + gotFirstResponseByte: firstTLSHandshakeDone + int64(4*interval), + } + + trail := tracer.Done() + assert.Equal(t, 3*interval, trail.Blocked) + assert.Equal(t, interval, trail.Sending) + assert.Equal(t, trail.EndTime.Sub(time.Unix(0, getConn)), trail.Blocked+trail.Duration) +} + func TestTracerError(t *testing.T) { t.Parallel() srv := httptest.NewTLSServer(httpbin.New().Handler()) From 4bb65a26e979ea486077c672602dc94e1cf81557 Mon Sep 17 00:00:00 2001 From: Mihail Stoykov <312246+mstoykov@users.noreply.github.com> Date: Tue, 15 Sep 2026 10:53:22 +0300 Subject: [PATCH 149/182] feat(js): propagate metric context through promise reactions (#6340) Add the experimental async-metric-context feature flag and use it to treat tags and metadata as async-local context. Each promise reaction receives a cloned snapshot, mutations flow to asynchronous work created by that reaction, and the interrupted context is restored when the reaction exits. Install the Sobek async-context tracker when each VU runtime is created. This makes propagation available to promises and modules and installs the tracker before setup or teardown can queue reactions. Provide common helpers for callbacks that run outside Sobek promise reactions. Applying a captured context without metadata measured 84.60 ns/op, 32 B/op, and one allocation in five one-second runs with GOMAXPROCS=1. Four metadata entries measured 480.0 ns/op, 704 B/op, and five allocations. Keep the behavior opt-in through --features async-metric-context, K6_FEATURES, or the JSON features configuration. Disabled runs do not install the tracker or apply callback snapshots. Related issues: https://github.com/grafana/k6/issues/2728 https://github.com/grafana/k6/issues/2848 https://github.com/grafana/k6/issues/3392 https://github.com/grafana/k6/issues/5435 https://github.com/grafana/k6/issues/5673 Earlier proposal: https://github.com/grafana/k6/pull/2863 --- examples/async_metric_context.js | 63 +++++++++ .../cmd/tests/cmd_run_async_context_test.go | 58 ++++++++ internal/cmd/tests/cmd_run_test.go | 19 ++- internal/features/features.go | 11 +- internal/js/bundle.go | 3 + internal/js/runner.go | 1 + js/common/metriccontext.go | 117 ++++++++++++++++ js/common/metriccontext_test.go | 131 ++++++++++++++++++ lib/vu_state.go | 2 + 9 files changed, 395 insertions(+), 10 deletions(-) create mode 100644 examples/async_metric_context.js create mode 100644 internal/cmd/tests/cmd_run_async_context_test.go create mode 100644 js/common/metriccontext.go create mode 100644 js/common/metriccontext_test.go diff --git a/examples/async_metric_context.js b/examples/async_metric_context.js new file mode 100644 index 000000000..39b5c4746 --- /dev/null +++ b/examples/async_metric_context.js @@ -0,0 +1,63 @@ +// Run with: +// k6 run --features async-metric-context examples/async_metric_context.js + +import { check } from 'k6'; +import exec from 'k6/execution'; +import { Counter } from 'k6/metrics'; + +const callbackPhases = new Counter('callback_phases'); + +export const options = { + iterations: 1, + thresholds: { + callback_phases: ['count == 6'], + checks: ['rate == 1'], + }, +}; + +function setContext(owner, phase) { + exec.vu.metrics.tags.owner = owner; + exec.vu.metrics.tags.phase = phase; + exec.vu.metrics.metadata.trace = owner; + exec.vu.metrics.metadata.step = phase; +} + +function contextMatches(owner, phase) { + return exec.vu.metrics.tags.owner === owner + && exec.vu.metrics.tags.phase === phase + && exec.vu.metrics.metadata.trace === owner + && exec.vu.metrics.metadata.step === phase; +} + +export default async function () { + let releaseAlpha; + let releaseBeta; + const alphaGate = new Promise(resolve => { releaseAlpha = resolve; }); + const betaGate = new Promise(resolve => { releaseBeta = resolve; }); + + const register = (owner, gate) => { + setContext(owner, 'registered'); + return gate.then(async () => { + for (const phase of ['first', 'second', 'third']) { + setContext(owner, phase); + await Promise.resolve(); + callbackPhases.add(1); + check(null, { + [`${owner}:${phase} kept its context`]: () => contextMatches(owner, phase), + }); + } + }); + }; + + const alpha = register('alpha', alphaGate); + const beta = register('beta', betaGate); + + setContext('root', 'waiting'); + releaseBeta(); + releaseAlpha(); + await Promise.all([alpha, beta]); + + check(null, { + 'the awaiting context was restored': () => contextMatches('root', 'waiting'), + }); +} diff --git a/internal/cmd/tests/cmd_run_async_context_test.go b/internal/cmd/tests/cmd_run_async_context_test.go new file mode 100644 index 000000000..09bc562eb --- /dev/null +++ b/internal/cmd/tests/cmd_run_async_context_test.go @@ -0,0 +1,58 @@ +package tests + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "go.k6.io/k6/v2/internal/cmd" + "go.k6.io/k6/v2/lib/fsext" +) + +func TestRunAsyncMetricContextWithoutK6Module(t *testing.T) { + t.Parallel() + + script := ` + import exec from 'k6/execution'; + import { Counter } from 'k6/metrics'; + + const callbackPhases = new Counter('callback_phases'); + const delay = ms => new Promise(resolve => setTimeout(resolve, ms)); + + export default function () { + let release; + const gate = new Promise(resolve => { release = resolve; }); + exec.vu.metrics.tags.owner = 'registered'; + exec.vu.metrics.metadata.trace = 'registered'; + const pending = gate.then(async () => { + for (const phase of ['first', 'second', 'third']) { + exec.vu.metrics.tags.phase = phase; + exec.vu.metrics.metadata.step = phase; + if (phase === 'second') { + await delay(0); + } else { + await Promise.resolve(); + } + callbackPhases.add(1, {phase_name: phase}); + } + }); + exec.vu.metrics.tags.owner = 'root'; + exec.vu.metrics.metadata.trace = 'root'; + release(); + return pending; + } + ` + + ts := getSingleFileTestState(t, script, + []string{"--features", "async-metric-context", "--out", "json=results.json", "--summary-mode=disabled"}, 0) + cmd.ExecuteWithGlobalState(ts.GlobalState) + + results, err := fsext.ReadFile(ts.FS, "results.json") + require.NoError(t, err) + for _, phase := range []string{"first", "second", "third"} { + assert.Equal(t, []float64{1}, getSampleValuesWithMetadata(t, results, "callback_phases", map[string]string{ + "owner": "registered", "phase": phase, "phase_name": phase, + }, map[string]string{"trace": "registered", "step": phase})) + } +} diff --git a/internal/cmd/tests/cmd_run_test.go b/internal/cmd/tests/cmd_run_test.go index 0a6830b8c..57c2c88ec 100644 --- a/internal/cmd/tests/cmd_run_test.go +++ b/internal/cmd/tests/cmd_run_test.go @@ -1603,14 +1603,23 @@ func TestMetricTagAndSetupDataIsolation(t *testing.T) { } func getSampleValues(t *testing.T, jsonOutput []byte, metric string, tags map[string]string) []float64 { + return getSampleValuesWithMetadata(t, jsonOutput, metric, tags, nil) +} + +func getSampleValuesWithMetadata( + t *testing.T, jsonOutput []byte, metric string, tags, metadata map[string]string, +) []float64 { jsonLines := bytes.Split(jsonOutput, []byte("\n")) result := []float64{} - tagsMatch := func(rawTags any) bool { - sampleTags, ok := rawTags.(map[string]any) + valuesMatch := func(rawValues any, expected map[string]string) bool { + if len(expected) == 0 { + return true + } + sampleValues, ok := rawValues.(map[string]any) require.True(t, ok) - for k, v := range tags { - rv, sok := sampleTags[k] + for k, v := range expected { + rv, sok := sampleValues[k] if !sok { return false } @@ -1642,7 +1651,7 @@ func getSampleValues(t *testing.T, jsonOutput []byte, metric string, tags map[st sampleData, ok := line["data"].(map[string]any) require.True(t, ok) - if !tagsMatch(sampleData["tags"]) { + if !valuesMatch(sampleData["tags"], tags) || !valuesMatch(sampleData["metadata"], metadata) { continue } diff --git a/internal/features/features.go b/internal/features/features.go index 2a6353b93..3cb0bfd76 100644 --- a/internal/features/features.go +++ b/internal/features/features.go @@ -41,11 +41,12 @@ func (l Lifecycle) String() string { // Flags declares every feature flag as a tagged bool field. type Flags struct { - NativeHistograms bool `lifecycle:"experimental" help:"Use native histograms for trend metrics"` - MergeRunTags bool `lifecycle:"experimental" help:"Merge run tags across config layers instead of replacing"` - FreezeEnv bool `lifecycle:"experimental" help:"Freeze __ENV object to prevent modifications from JS code"` - _ noCopy - activated []string + NativeHistograms bool `lifecycle:"experimental" help:"Use native histograms for trend metrics"` + MergeRunTags bool `lifecycle:"experimental" help:"Merge run tags across config layers instead of replacing"` + FreezeEnv bool `lifecycle:"experimental" help:"Freeze __ENV object to prevent modifications from JS code"` + AsyncMetricContext bool `lifecycle:"experimental" help:"Propagate metric context through asynchronous operations"` + _ noCopy + activated []string } // Activated returns a copy of the sorted canonical names of active features. diff --git a/internal/js/bundle.go b/internal/js/bundle.go index 447acfbef..3a3eeb342 100644 --- a/internal/js/bundle.go +++ b/internal/js/bundle.go @@ -266,6 +266,9 @@ func (b *Bundle) Instantiate(ctx context.Context, vuID uint64) (*BundleInstance, local: event.NewEventSystem(100, b.preInitState.Logger), }, } + if b.preInitState.FeatureFlags != nil && b.preInitState.FeatureFlags.AsyncMetricContext { + vuImpl.runtime.SetAsyncContextTracker(common.NewMetricContextTracker(vuImpl.State)) + } vuImpl.eventLoop = eventloop.New(vuImpl) bi, err := b.instantiate(vuImpl, vuID) if err != nil { diff --git a/internal/js/runner.go b/internal/js/runner.go index 467fac26c..0339c1f3b 100644 --- a/internal/js/runner.go +++ b/internal/js/runner.go @@ -253,6 +253,7 @@ func (r *Runner) newVU( Samples: vu.Samples, Tags: lib.NewVUStateTags(vu.Runner.RunTags), BuiltinMetrics: r.preInitState.BuiltinMetrics, + FeatureFlags: r.preInitState.FeatureFlags, TracerProvider: r.preInitState.TracerProvider, Usage: r.preInitState.Usage, TestStatus: r.preInitState.TestStatus, diff --git a/js/common/metriccontext.go b/js/common/metriccontext.go new file mode 100644 index 000000000..2d1633a9d --- /dev/null +++ b/js/common/metriccontext.go @@ -0,0 +1,117 @@ +package common + +import ( + "github.com/grafana/sobek" + + "go.k6.io/k6/v2/lib" + "go.k6.io/k6/v2/metrics" +) + +// metricContextTracker propagates metric context through promise reactions, including await +// continuations. Promise reactions do not nest and run on the event-loop goroutine. +type metricContextTracker struct { + state func() *lib.State + restore func() +} + +// CapturedMetricContext is an immutable registration-time metric context. Its zero value is a +// disabled context, so callers don't need separate feature-flag or nil-state branches. +type CapturedMetricContext struct { + state *lib.State + tagsAndMeta metrics.TagsAndMeta +} + +var _ sobek.AsyncContextTracker = (*metricContextTracker)(nil) + +// NewMetricContextTracker returns an async-context tracker backed by the current VU state. +func NewMetricContextTracker(state func() *lib.State) sobek.AsyncContextTracker { + return &metricContextTracker{state: state} +} + +// Grab captures the metric context when a promise reaction is created. +func (t *metricContextTracker) Grab() any { + state := t.state() + if state == nil || state.Tags == nil { + return nil + } + return state.Tags.GetCurrentValues() +} + +// Resumed applies the context captured for a promise reaction. +func (t *metricContextTracker) Resumed(trackingObject any) { + captured, ok := trackingObject.(metrics.TagsAndMeta) + state := t.state() + if !ok || state == nil || state.Tags == nil { + t.restore = nil + return + } + t.restore = ApplyMetricContext(state, captured) +} + +// Exited restores the context that was active before the promise reaction ran. +func (t *metricContextTracker) Exited() { + if t.restore != nil { + t.restore() + t.restore = nil + } +} + +// AsyncMetricContextEnabled reports whether asynchronous metric-context propagation is enabled. +func AsyncMetricContextEnabled(state *lib.State) bool { + return state != nil && state.FeatureFlags != nil && state.FeatureFlags.AsyncMetricContext +} + +// CaptureMetricContext captures the current tags and metadata for work that will run outside +// Sobek's promise machinery. +func CaptureMetricContext(state *lib.State) CapturedMetricContext { + if !AsyncMetricContextEnabled(state) || state.Tags == nil { + return CapturedMetricContext{} + } + return CapturedMetricContext{state: state, tagsAndMeta: state.Tags.GetCurrentValues()} +} + +// Enter installs a clone of the captured context and returns a function that restores the context +// it interrupted. Entering a disabled context is a no-op. +func (c CapturedMetricContext) Enter() (restore func()) { + if c.state == nil { + return func() {} + } + return ApplyMetricContext(c.state, c.tagsAndMeta) +} + +// RunWithMetricContext executes fn under captured and supports callbacks that return a value. +func RunWithMetricContext[T any](captured CapturedMetricContext, fn func() (T, error)) (T, error) { + if captured.state == nil { + return fn() + } + restore := captured.Enter() + defer restore() + return fn() +} + +// WrapSobekCallable captures invocation under c while preserving the callable's arguments and +// return value. +func (c CapturedMetricContext) WrapSobekCallable(fn sobek.Callable) sobek.Callable { + if fn == nil || c.state == nil { + return fn + } + return func(this sobek.Value, args ...sobek.Value) (sobek.Value, error) { + return RunWithMetricContext(c, func() (sobek.Value, error) { + return fn(this, args...) + }) + } +} + +// ApplyMetricContext replaces the current tags and metadata until the returned function restores +// them. Both assignments clone metadata so mutations cannot change a reusable captured snapshot. +func ApplyMetricContext(state *lib.State, captured metrics.TagsAndMeta) (restore func()) { + previous := state.Tags.GetCurrentValues() + state.Tags.Modify(func(tagsAndMeta *metrics.TagsAndMeta) { + *tagsAndMeta = captured.Clone() + }) + return func() { + state.Tags.Modify(func(tagsAndMeta *metrics.TagsAndMeta) { + *tagsAndMeta = previous + }) + } +} diff --git a/js/common/metriccontext_test.go b/js/common/metriccontext_test.go new file mode 100644 index 000000000..751183006 --- /dev/null +++ b/js/common/metriccontext_test.go @@ -0,0 +1,131 @@ +package common + +import ( + "strconv" + "testing" + + "github.com/stretchr/testify/require" + + "go.k6.io/k6/v2/internal/features" + "go.k6.io/k6/v2/lib" + "go.k6.io/k6/v2/metrics" +) + +func newMetricContextState(enabled bool) *lib.State { + registry := metrics.NewRegistry() + return &lib.State{ + FeatureFlags: &features.Flags{AsyncMetricContext: enabled}, + Tags: lib.NewVUStateTags( + registry.RootTagSet().WithTagsFromMap(map[string]string{"group": lib.RootGroupPath}), + ), + } +} + +func setMetricContext(state *lib.State, group, phase, trace string) { + state.Tags.Modify(func(tagsAndMeta *metrics.TagsAndMeta) { + tagsAndMeta.SetTag("group", group) + tagsAndMeta.SetTag("phase", phase) + tagsAndMeta.SetMetadata("trace", trace) + }) +} + +func requireMetricContext(t *testing.T, state *lib.State, group, phase, trace string) { + t.Helper() + current := state.Tags.GetCurrentValues() + actualGroup, _ := current.Tags.Get("group") + actualPhase, _ := current.Tags.Get("phase") + require.Equal(t, group, actualGroup) + require.Equal(t, phase, actualPhase) + require.Equal(t, trace, current.Metadata["trace"]) +} + +func TestCapturedMetricContext(t *testing.T) { + t.Parallel() + + state := newMetricContextState(true) + setMetricContext(state, "::registered", "registered", "registered") + captured := CaptureMetricContext(state) + setMetricContext(state, "::active", "active", "active") + + restore := captured.Enter() + requireMetricContext(t, state, "::registered", "registered", "registered") + setMetricContext(state, "::callback", "callback", "callback") + restore() + requireMetricContext(t, state, "::active", "active", "active") + + // A reusable snapshot must not retain mutations from its previous invocation. + restore = captured.Enter() + requireMetricContext(t, state, "::registered", "registered", "registered") + restore() +} + +func TestCapturedMetricContextDisabled(t *testing.T) { + t.Parallel() + + state := newMetricContextState(false) + setMetricContext(state, "::registered", "registered", "registered") + captured := CaptureMetricContext(state) + setMetricContext(state, "::active", "active", "active") + + restore := captured.Enter() + requireMetricContext(t, state, "::active", "active", "active") + setMetricContext(state, "::callback", "callback", "callback") + restore() + requireMetricContext(t, state, "::callback", "callback", "callback") +} + +func TestRunWithMetricContext(t *testing.T) { + t.Parallel() + + state := newMetricContextState(true) + setMetricContext(state, "::registered", "registered", "registered") + captured := CaptureMetricContext(state) + setMetricContext(state, "::active", "active", "active") + + value, err := RunWithMetricContext(captured, func() (string, error) { + requireMetricContext(t, state, "::registered", "registered", "registered") + setMetricContext(state, "::callback", "callback", "callback") + return "result", nil + }) + require.NoError(t, err) + require.Equal(t, "result", value) + requireMetricContext(t, state, "::active", "active", "active") +} + +func TestMetricContextTracker(t *testing.T) { + t.Parallel() + + state := newMetricContextState(true) + tracker := NewMetricContextTracker(func() *lib.State { return state }) + setMetricContext(state, "::registered", "registered", "registered") + captured := tracker.Grab() + setMetricContext(state, "::active", "active", "active") + + tracker.Resumed(captured) + requireMetricContext(t, state, "::registered", "registered", "registered") + setMetricContext(state, "::callback", "callback", "callback") + tracker.Exited() + requireMetricContext(t, state, "::active", "active", "active") +} + +func BenchmarkCapturedMetricContext(b *testing.B) { + for _, metadataEntries := range []int{0, 4} { + b.Run(strconv.Itoa(metadataEntries)+"_metadata", func(b *testing.B) { + state := newMetricContextState(true) + state.Tags.Modify(func(tagsAndMeta *metrics.TagsAndMeta) { + tagsAndMeta.SetTag("phase", "registered") + for i := range metadataEntries { + tagsAndMeta.SetMetadata(string(rune('a'+i)), "value") + } + }) + captured := CaptureMetricContext(state) + + b.ReportAllocs() + b.ResetTimer() + for b.Loop() { + restore := captured.Enter() + restore() + } + }) + } +} diff --git a/lib/vu_state.go b/lib/vu_state.go index 593df7d02..ee507432d 100644 --- a/lib/vu_state.go +++ b/lib/vu_state.go @@ -12,6 +12,7 @@ import ( "go.opentelemetry.io/otel/trace" "golang.org/x/time/rate" + "go.k6.io/k6/v2/internal/features" "go.k6.io/k6/v2/internal/usage" "go.k6.io/k6/v2/metrics" ) @@ -49,6 +50,7 @@ type State struct { // TestPreInitState. The Samples channel might also benefit from that... Options Options BuiltinMetrics *metrics.BuiltinMetrics + FeatureFlags *features.Flags // Logger instance for every VU. Logger logrus.FieldLogger From ed3ead1beec7e1be775d3a343ee199e88a0aad6f Mon Sep 17 00:00:00 2001 From: Mihail Stoykov <312246+mstoykov@users.noreply.github.com> Date: Tue, 15 Sep 2026 12:12:50 +0300 Subject: [PATCH 150/182] feat(js): support async callbacks in group() (#6341) When async-metric-context is enabled, allow group() callbacks to return Promise-like values. Keep the group's complete metric context across await continuations and promise reactions, and emit group_duration once when the result settles. Restore the parent context after the callback returns or throws. Handle throwing then accessors and custom thenables that settle synchronously, preserve rejection identity, and prevent duplicate duration emission. Disabled runs retain the previous async-function error and synchronous tag behavior. Synchronous callbacks continue to return their original values without entering the asynchronous settlement path. Five one-second runs with GOMAXPROCS=1 measured an awaited resolved promise at 4.934 us/op, 5,376 B/op, and 89 allocations with the feature enabled. The disabled path measured 4.828 us/op, 5,328 B/op, and 87 allocations. Timing ranges overlapped, while the allocation difference was stable. Returning a group around a resolved promise measured 8.796 us/op, 8,424 B/op, and 135 allocations. Awaiting the group measured 11.711 us/op, 10,584 B/op, and 173 allocations. --- .../tests/cmd_run_async_group_http_test.go | 50 + .../cmd/tests/cmd_run_async_group_test.go | 180 ++++ internal/js/modules/k6/asyncgroup.go | 135 +++ internal/js/modules/k6/asyncgroup_test.go | 919 ++++++++++++++++++ internal/js/modules/k6/k6.go | 93 +- internal/js/modules/k6/k6_test.go | 52 +- 6 files changed, 1401 insertions(+), 28 deletions(-) create mode 100644 internal/cmd/tests/cmd_run_async_group_http_test.go create mode 100644 internal/cmd/tests/cmd_run_async_group_test.go create mode 100644 internal/js/modules/k6/asyncgroup.go create mode 100644 internal/js/modules/k6/asyncgroup_test.go diff --git a/internal/cmd/tests/cmd_run_async_group_http_test.go b/internal/cmd/tests/cmd_run_async_group_http_test.go new file mode 100644 index 000000000..3a8e87e65 --- /dev/null +++ b/internal/cmd/tests/cmd_run_async_group_http_test.go @@ -0,0 +1,50 @@ +package tests + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "go.k6.io/k6/v2/internal/cmd" + "go.k6.io/k6/v2/internal/lib/testutils/httpmultibin" + "go.k6.io/k6/v2/lib/fsext" +) + +func TestRunAsyncGroupHTTP(t *testing.T) { + t.Parallel() + + tb := httpmultibin.NewHTTPMultiBin(t) + script := tb.Replacer.Replace(` + import http from 'k6/http'; + import { check, group } from 'k6'; + + export const options = { + hosts: { 'HTTPBIN_DOMAIN': 'HTTPBIN_IP' }, + }; + + export default async function () { + await group('async request', async () => { + const response = await http.asyncRequest('GET', 'HTTPBIN_URL/get'); + check(response, { inside: response => response.status === 200 }); + }); + check(null, { after: true }); + } + `) + + ts := getSingleFileTestState(t, script, + []string{"--features", "async-metric-context", "--out", "json=results.json", "--summary-mode=disabled"}, 0) + cmd.ExecuteWithGlobalState(ts.GlobalState) + + results, err := fsext.ReadFile(ts.FS, "results.json") + require.NoError(t, err) + assert.Equal(t, []float64{1}, getSampleValues(t, results, "checks", map[string]string{ + "check": "inside", "group": "::async request", + })) + assert.Equal(t, []float64{1}, getSampleValues(t, results, "checks", map[string]string{ + "check": "after", "group": "", + })) + assert.Len(t, getSampleValues(t, results, "http_reqs", map[string]string{ + "group": "::async request", + }), 1) +} diff --git a/internal/cmd/tests/cmd_run_async_group_test.go b/internal/cmd/tests/cmd_run_async_group_test.go new file mode 100644 index 000000000..0c98eaef4 --- /dev/null +++ b/internal/cmd/tests/cmd_run_async_group_test.go @@ -0,0 +1,180 @@ +package tests + +import ( + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "go.k6.io/k6/v2/internal/cmd" + "go.k6.io/k6/v2/lib/fsext" +) + +func runAsyncGroupIntegrationScript(t *testing.T, script string, archived bool) []byte { + t.Helper() + + var ts *GlobalTestState + if archived { + archiveState := NewGlobalTestState(t) + require.NoError(t, fsext.WriteFile( + archiveState.FS, filepath.Join(archiveState.Cwd, "test.js"), []byte(script), 0o644)) + archiveState.CmdArgs = []string{"k6", "archive", "test.js"} + cmd.ExecuteWithGlobalState(archiveState.GlobalState) + + archive, err := fsext.ReadFile(archiveState.FS, "archive.tar") + require.NoError(t, err) + ts = NewGlobalTestState(t) + require.NoError(t, fsext.WriteFile(ts.FS, filepath.Join(ts.Cwd, "archive.tar"), archive, 0o644)) + ts.CmdArgs = []string{ + "k6", "run", "--features", "async-metric-context", "--out", "json=results.json", + "--summary-mode=disabled", "archive.tar", + } + } else { + ts = getSingleFileTestState(t, script, + []string{"--features", "async-metric-context", "--out", "json=results.json", "--summary-mode=disabled"}, 0) + } + + cmd.ExecuteWithGlobalState(ts.GlobalState) + results, err := fsext.ReadFile(ts.FS, "results.json") + require.NoError(t, err) + return results +} + +func TestRunAsyncGroupSetupAndTeardownReactionsKeepStageGroup(t *testing.T) { + t.Parallel() + + script := ` + import { check, group } from 'k6'; + + export const options = { + setupTimeout: '1s', + teardownTimeout: '1s', + systemTags: ['group', 'check'], + }; + + function queueReaction(stage) { + Promise.resolve().then(() => check(null, {[stage]: true})); + group('warmup', () => {}); + } + + export function setup() { queueReaction('setup'); } + export default function() {} + export function teardown() { queueReaction('teardown'); } + ` + + for _, variant := range []struct { + name string + archived bool + }{{"source", false}, {"archive", true}} { + t.Run(variant.name, func(t *testing.T) { + t.Parallel() + results := runAsyncGroupIntegrationScript(t, script, variant.archived) + for _, stage := range []string{"setup", "teardown"} { + assert.Equal(t, []float64{1}, getSampleValues(t, results, "checks", map[string]string{ + "check": stage, "group": "::" + stage, + })) + } + }) + } +} + +func TestRunOverlappingAsyncGroupsEmitIndependentTags(t *testing.T) { + t.Parallel() + + script := ` + import { check, group } from 'k6'; + + export const options = { systemTags: ['group', 'check'] }; + + const delay = ms => new Promise(resolve => setTimeout(resolve, ms)); + + export default async function() { + const names = ['alpha', 'beta', 'gamma', 'delta']; + const grouped = names.map((name, index) => group(name, async () => { + check(null, {[name + ':start']: true}); + await delay((names.length - index) * 2); + check(null, {[name + ':finish']: true}); + })); + await Promise.all(grouped); + check(null, {'outside:after': true}); + } + ` + + for _, variant := range []struct { + name string + archived bool + }{{"source", false}, {"archive", true}} { + t.Run(variant.name, func(t *testing.T) { + t.Parallel() + results := runAsyncGroupIntegrationScript(t, script, variant.archived) + for _, group := range []string{"alpha", "beta", "gamma", "delta"} { + for _, phase := range []string{"start", "finish"} { + assert.Equal(t, []float64{1}, getSampleValues(t, results, "checks", map[string]string{ + "check": group + ":" + phase, "group": "::" + group, + })) + } + assert.Len(t, getSampleValues(t, results, "group_duration", map[string]string{ + "group": "::" + group, + }), 1) + } + assert.Equal(t, []float64{1}, getSampleValues(t, results, "checks", map[string]string{ + "check": "outside:after", "group": "", + })) + }) + } +} + +func TestRunAsyncGroupSampleTagOverrideDoesNotMutateContext(t *testing.T) { + t.Parallel() + + script := ` + import { group } from 'k6'; + import exec from 'k6/execution'; + import { Counter } from 'k6/metrics'; + + const events = new Counter('events'); + + function setContext(owner, phase) { + exec.vu.metrics.tags.owner = owner; + exec.vu.metrics.tags.phase = phase; + exec.vu.metrics.metadata.trace = owner; + exec.vu.metrics.metadata.step = phase; + } + + export default function () { + setContext('root', 'root'); + + group('checkout', () => { + setContext('checkout', 'body'); + + events.add(1, { kind: 'grouped' }); + events.add(1, { kind: 'ungrouped', group: '' }); + events.add(1, { kind: 'grouped-again' }); + }); + + events.add(1, { kind: 'outside' }); + } + ` + + results := runAsyncGroupIntegrationScript(t, script, false) + for _, sample := range []struct { + kind string + group string + owner string + phase string + }{ + {kind: "grouped", group: "::checkout", owner: "checkout", phase: "body"}, + {kind: "ungrouped", group: "", owner: "checkout", phase: "body"}, + {kind: "grouped-again", group: "::checkout", owner: "checkout", phase: "body"}, + {kind: "outside", group: "", owner: "root", phase: "root"}, + } { + assert.Equal(t, []float64{1}, getSampleValuesWithMetadata(t, results, "events", map[string]string{ + "kind": sample.kind, "group": sample.group, "owner": sample.owner, "phase": sample.phase, + }, map[string]string{"trace": sample.owner, "step": sample.phase})) + } + + assert.Len(t, getSampleValuesWithMetadata(t, results, "group_duration", map[string]string{ + "group": "::checkout", "owner": "root", "phase": "root", + }, map[string]string{"trace": "root", "step": "root"}), 1) +} diff --git a/internal/js/modules/k6/asyncgroup.go b/internal/js/modules/k6/asyncgroup.go new file mode 100644 index 000000000..deff54773 --- /dev/null +++ b/internal/js/modules/k6/asyncgroup.go @@ -0,0 +1,135 @@ +package k6 + +import ( + "reflect" + "time" + + "github.com/grafana/sobek" + + "go.k6.io/k6/v2/js/modules" + "go.k6.io/k6/v2/metrics" +) + +// asyncGroup retains the invocation state used by the settlement handlers. +type asyncGroup struct { + vu modules.VU + start time.Time + tagsAndMeta metrics.TagsAndMeta + // settled prevents duplicate emission and tells Group when a thenable settled synchronously. + settled bool +} + +func (g *asyncGroup) emitDuration() { + if g.settled { + return + } + g.settled = true + + // Group only creates asyncGroup for an active VU, whose state remains allocated across + // iterations and cancellation. + emitGroupDuration(g.vu, g.start, time.Now(), g.tagsAndMeta) +} + +func emitGroupDuration(vu modules.VU, start, end time.Time, tagsAndMeta metrics.TagsAndMeta) { + state := vu.State() + metrics.PushIfNotDone(vu.Context(), state.Samples, metrics.Sample{ + TimeSeries: metrics.TimeSeries{ + Metric: state.BuiltinMetrics.GroupDuration, + Tags: tagsAndMeta.Tags, + }, + Time: end, + Value: metrics.D(end.Sub(start)), + Metadata: tagsAndMeta.Metadata, + }) +} + +func (g *asyncGroup) onFulfilled(call sobek.FunctionCall) sobek.Value { + g.emitDuration() + return call.Argument(0) +} + +func (g *asyncGroup) onRejected(call sobek.FunctionCall) sobek.Value { + g.emitDuration() + // Sobek uses a panic to throw an arbitrary JavaScript value from a Go callback. Returning a Go + // error here would wrap the value and change the promise's rejection reason. + panic(call.Argument(0)) +} + +// runAsyncGroup attaches duration emission to a callback's Promise-like result. +func (mi *K6) runAsyncGroup( + start time.Time, + tagsAndMeta metrics.TagsAndMeta, + thenFn sobek.Callable, + thenable sobek.Value, +) (sobek.Value, bool, error) { + g := &asyncGroup{ + vu: mi.vu, + start: start, + tagsAndMeta: tagsAndMeta, + } + result, err := g.run(thenFn, thenable) + return result, g.settled, err +} + +func (g *asyncGroup) run(thenFn sobek.Callable, thenable sobek.Value) (sobek.Value, error) { + rt := g.vu.Runtime() + if thenable.ExportType() == reflect.TypeFor[*sobek.Promise]() { + return thenFn( + thenable, + rt.ToValue(g.onFulfilled), + rt.ToValue(g.onRejected), + ) + } + + // A generic thenable is not required to return a Promise from then(). Assimilate its settlement + // into a Sobek Promise so group() remains awaitable and inherits Promise resolution semantics, + // including first-settlement-wins and recursively adopting another Promise. + promise, resolve, reject := rt.NewPromise() + settle := func(settler func(any) error) func(sobek.FunctionCall) sobek.Value { + return func(call sobek.FunctionCall) sobek.Value { + if err := settler(call.Argument(0)); err != nil { + panic(err) + } + return sobek.Undefined() + } + } + + _, err := thenFn( + thenable, + rt.ToValue(settle(resolve)), + rt.ToValue(settle(reject)), + ) + if err != nil { + // A JavaScript throw while invoking then() rejects the assimilating Promise. If the thenable + // already settled, Sobek's resolving functions ignore this later rejection. + exception, ok := err.(*sobek.Exception) //nolint:errorlint // preserve the JavaScript value + if !ok { + return nil, err + } + if err = reject(exception.Value()); err != nil { + return nil, err + } + } + + // Continue through the common settlement path: reject may have been ignored if the thenable + // settled first, and the handlers below own duration emission. + promiseValue := rt.ToValue(promise) + promiseThen, ok := asThenable(promiseValue) + if !ok { + panic("new Sobek promise has no callable then method") + } + return promiseThen( + promiseValue, + rt.ToValue(g.onFulfilled), + rt.ToValue(g.onRejected), + ) +} + +// Property access follows JavaScript semantics and may throw. +func asThenable(v sobek.Value) (sobek.Callable, bool) { + obj, ok := v.(*sobek.Object) + if !ok { + return nil, false + } + return sobek.AssertFunction(obj.Get("then")) +} diff --git a/internal/js/modules/k6/asyncgroup_test.go b/internal/js/modules/k6/asyncgroup_test.go new file mode 100644 index 000000000..905804777 --- /dev/null +++ b/internal/js/modules/k6/asyncgroup_test.go @@ -0,0 +1,919 @@ +package k6 + +import ( + "strings" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "go.k6.io/k6/v2/lib" + "go.k6.io/k6/v2/metrics" +) + +func checkGroups(t *testing.T, tc *testCase) map[string]string { + t.Helper() + + checks := make(map[string]string) + checksMetric := tc.testRuntime.VU.State().BuiltinMetrics.Checks + for _, sampleContainer := range metrics.GetBufferedSamples(tc.samples) { + for _, sample := range sampleContainer.GetSamples() { + if sample.Metric != checksMetric { + continue + } + name, ok := sample.Tags.Get(metrics.TagCheck.String()) + require.True(t, ok) + _, duplicate := checks[name] + require.Falsef(t, duplicate, "duplicate check sample %q", name) + assert.Equal(t, float64(1), sample.Value, "check %q failed", name) + group, _ := sample.Tags.Get(metrics.TagGroup.String()) + checks[name] = group + } + } + return checks +} + +func newOrderRecorder(t *testing.T, tc *testCase) *[]string { + t.Helper() + order := new([]string) + require.NoError(t, tc.testRuntime.VU.Runtime().Set("mark", func(s string) { + *order = append(*order, s) + })) + return order +} + +// Regression test for #2728 and #3392. +func TestThenContinuationKeepsGroup(t *testing.T) { + t.Parallel() + tc := testCaseRuntime(t) + + _, err := tc.testRuntime.RunOnEventLoop(` + (async () => { + const delay = () => { return Promise.resolve(); }; + await k6.group("coolgroup", () => { + k6.check(null, {sync: true}); + return delay(1).then(() => { k6.check(null, {continuation: true}); }); + }); + k6.check(null, {after: true}); + })() + `) + require.NoError(t, err) + + assert.Equal(t, map[string]string{ + "sync": "::coolgroup", + "continuation": "::coolgroup", + "after": lib.RootGroupPath, + }, checkGroups(t, tc)) +} + +// Regression test for #2728's manual group re-entry workaround. +func TestManualGroupInThenContinuation(t *testing.T) { + t.Parallel() + tc := testCaseRuntime(t) + + _, err := tc.testRuntime.RunOnEventLoop(` + (async () => { + const delay = () => { return Promise.resolve(); }; + await delay(1).then(() => { + k6.check(null, {before: true}); + return k6.group("coolgroup", () => { k6.check(null, {inside: true}); }); + }); + k6.check(null, {after: true}); + })() + `) + require.NoError(t, err) + + assert.Equal(t, map[string]string{ + "before": lib.RootGroupPath, + "inside": "::coolgroup", + "after": lib.RootGroupPath, + }, checkGroups(t, tc)) +} + +// Regression test for #2848. +func TestAsyncGroupExecutionOrder(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + script string + expected []string + }{ + { + name: "synchronous work outside group", + script: ` + (async () => { + await k6.group("somename", async () => { + mark("A"); + await Promise.resolve(); + mark("B"); + }); + mark("after-group"); + })(); + mark("C"); + `, + expected: []string{"A", "C", "B", "after-group"}, + }, + { + name: "queued promise reaction", + script: ` + (async () => { + await k6.group("somename", async () => { + mark("A"); + await Promise.resolve(); + mark("B"); + }); + mark("after-group"); + })(); + Promise.resolve("D").then(() => { mark("D"); }); + mark("C"); + `, + expected: []string{"A", "C", "B", "D", "after-group"}, + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + t.Parallel() + + tc := testCaseRuntime(t) + order := newOrderRecorder(t, tc) + _, err := tc.testRuntime.RunOnEventLoop(test.script) + require.NoError(t, err) + require.Equal(t, test.expected, *order) + }) + } +} + +// Regression test for #5435. +func TestConcurrentAsyncGroupsDurationsAndTags(t *testing.T) { + t.Parallel() + + tc := testCaseRuntime(t) + _, err := tc.testRuntime.RunOnEventLoop(` + (async () => { + const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); + const check = (name) => k6.check(null, {[name]: true}); + const slow = k6.group("coolgroup", async () => { + check("slow:start"); + await delay(10); + check("slow:afterFirst"); + await delay(40).then(() => {}); + check("slow:afterSecond"); + }); + const fast = k6.group("fastgroup", async () => { + check("fast:start"); + await delay(10).then(() => {}); + check("fast:afterFirst"); + }); + await Promise.all([slow, fast]); + check("after"); + })() + `) + require.NoError(t, err) + + builtinMetrics := tc.testRuntime.VU.State().BuiltinMetrics + durByGroup := map[string]float64{} + durationCounts := map[string]int{} + checkGroups := map[string]string{} + var checkCount int + for _, sampleContainer := range metrics.GetBufferedSamples(tc.samples) { + for _, sample := range sampleContainer.GetSamples() { + group, _ := sample.Tags.Get(metrics.TagGroup.String()) + switch sample.Metric { + case builtinMetrics.GroupDuration: + durByGroup[group] = sample.Value + durationCounts[group]++ + case builtinMetrics.Checks: + checkCount++ + name, ok := sample.Tags.Get(metrics.TagCheck.String()) + require.True(t, ok) + assert.Equal(t, float64(1), sample.Value, "check %q failed", name) + checkGroups[name] = group + } + } + } + assert.Equal(t, 6, checkCount) + assert.Equal(t, map[string]int{"::coolgroup": 1, "::fastgroup": 1}, durationCounts) + + assert.Equal(t, map[string]string{ + "slow:start": "::coolgroup", + "slow:afterFirst": "::coolgroup", + "slow:afterSecond": "::coolgroup", + "fast:start": "::fastgroup", + "fast:afterFirst": "::fastgroup", + "after": lib.RootGroupPath, + }, checkGroups) + + slow, okSlow := durByGroup["::coolgroup"] + fast, okFast := durByGroup["::fastgroup"] + + require.True(t, okSlow, "missing group_duration for ::coolgroup, got %v", durByGroup) + require.True(t, okFast, "missing group_duration for ::fastgroup, got %v", durByGroup) + + t.Logf("group_duration ::coolgroup (slow) = %.2fms, ::fastgroup (fast) = %.2fms", slow, fast) + + assert.Greater(t, slow, fast, + "slow group (::coolgroup=%.2fms) must last clearly longer than fast group (::fastgroup=%.2fms)", + slow, fast) +} + +func TestConcurrentAsyncGroupsKeepIndependentTags(t *testing.T) { + t.Parallel() + + tc := testCaseRuntime(t) + + _, err := tc.testRuntime.RunOnEventLoop(` + (async () => { + const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); + const check = (name) => k6.check(null, {[name]: true}); + const names = ["alpha", "beta", "gamma", "delta"]; + const grouped = names.map((name, index) => k6.group(name, async () => { + check(name + ":start"); + await delay((index + 1) * 5); + check(name + ":afterTimer"); + await Promise.resolve(); + check(name + ":afterPromise"); + })); + await Promise.all(grouped); + check("after"); + })() + `) + require.NoError(t, err) + + durationCounts := make(map[string]int) + checkGroups := make(map[string]string) + var checkCount int + builtinMetrics := tc.testRuntime.VU.State().BuiltinMetrics + for _, sampleContainer := range metrics.GetBufferedSamples(tc.samples) { + for _, sample := range sampleContainer.GetSamples() { + group, _ := sample.Tags.Get(metrics.TagGroup.String()) + switch sample.Metric { + case builtinMetrics.GroupDuration: + durationCounts[group]++ + case builtinMetrics.Checks: + checkCount++ + name, ok := sample.Tags.Get(metrics.TagCheck.String()) + require.True(t, ok) + assert.Equal(t, float64(1), sample.Value, "check %q failed", name) + checkGroups[name] = group + } + } + } + require.Equal(t, 13, checkCount) + require.Len(t, checkGroups, 13) + + for check, group := range checkGroups { + if check == "after" { + assert.Equal(t, lib.RootGroupPath, group) + continue + } + + name, _, ok := strings.Cut(check, ":") + require.True(t, ok, "invalid check name %q", check) + expectedGroup, pathErr := lib.NewGroupPath(lib.RootGroupPath, name) + require.NoError(t, pathErr) + assert.Equalf(t, expectedGroup, group, "check %q saw the wrong group", check) + } + + assert.Equal(t, map[string]int{ + "::alpha": 1, + "::beta": 1, + "::gamma": 1, + "::delta": 1, + }, durationCounts) +} + +func TestAsyncGroupScopesCompleteMetricContext(t *testing.T) { + t.Parallel() + + tc := testCaseRuntime(t) + state := tc.testRuntime.VU.State() + setContext := func(phase string) { + state.Tags.Modify(func(tagsAndMeta *metrics.TagsAndMeta) { + tagsAndMeta.SetTag("phase", phase) + tagsAndMeta.SetMetadata("trace", phase) + }) + } + setContext("root") + require.NoError(t, tc.testRuntime.VU.Runtime().Set("setContext", setContext)) + + _, err := tc.testRuntime.RunOnEventLoop(` + (async () => { + await k6.group("g", async () => { + setContext("inside"); + k6.check(null, {beforeAwait: true}); + await Promise.resolve(); + k6.check(null, {afterAwait: true}); + }); + k6.check(null, {outside: true}); + })() + `) + require.NoError(t, err) + + wantPhase := map[string]string{ + "beforeAwait": "inside", + "afterAwait": "inside", + "outside": "root", + } + for _, sampleContainer := range metrics.GetBufferedSamples(tc.samples) { + for _, sample := range sampleContainer.GetSamples() { + if sample.Metric != state.BuiltinMetrics.Checks { + continue + } + name, _ := sample.Tags.Get(metrics.TagCheck.String()) + phase, _ := sample.Tags.Get("phase") + assert.Equal(t, wantPhase[name], phase, "check %q used the wrong tag context", name) + assert.Equal(t, wantPhase[name], sample.Metadata["trace"], + "check %q used the wrong metadata context", name) + delete(wantPhase, name) + } + } + require.Empty(t, wantPhase) + + current := state.Tags.GetCurrentValues() + phase, _ := current.Tags.Get("phase") + require.Equal(t, "root", phase) + require.Equal(t, "root", current.Metadata["trace"]) +} + +func TestDisabledAsyncMetricContextKeepsMutableTagsLive(t *testing.T) { + t.Parallel() + + tc := testCaseRuntimeWithAsyncMetricContext(t, false) + state := tc.testRuntime.VU.State() + state.Tags.Modify(func(tagsAndMeta *metrics.TagsAndMeta) { + tagsAndMeta.SetTag("phase", "before") + tagsAndMeta.SetMetadata("trace", "before") + }) + require.NoError(t, tc.testRuntime.VU.Runtime().Set("setContext", func() { + state.Tags.Modify(func(tagsAndMeta *metrics.TagsAndMeta) { + tagsAndMeta.SetTag("phase", "after") + tagsAndMeta.SetMetadata("trace", "after") + }) + })) + + _, err := tc.testRuntime.RunOnEventLoop(`k6.group("g", () => setContext())`) + require.NoError(t, err) + + current := state.Tags.GetCurrentValues() + phase, _ := current.Tags.Get("phase") + require.Equal(t, "after", phase) + require.Equal(t, "after", current.Metadata["trace"]) + + samples := metrics.GetBufferedSamples(tc.samples) + require.Len(t, samples, 1) + sample, ok := samples[0].(metrics.Sample) + require.True(t, ok) + phase, _ = sample.Tags.Get("phase") + require.Equal(t, "after", phase) + require.Equal(t, "after", sample.Metadata["trace"]) +} + +// Regression test for #5673. +func TestAsyncContextGroupPropagation(t *testing.T) { + t.Parallel() + tc := testCaseRuntime(t) + + _, err := tc.testRuntime.RunOnEventLoop(` + const delay = (t) => new Promise((r) => setTimeout(r, t)); + (async () => { + await k6.group("coolgroup", async () => { + k6.check(null, {sync: true}); + await delay(5); + k6.check(null, {afterAwait: true}); + await delay(5).then(() => { k6.check(null, {continuation: true}); }); + }); + k6.check(null, {after: true}); + })() + `) + require.NoError(t, err) + + assert.Equal(t, map[string]string{ + "sync": "::coolgroup", + "afterAwait": "::coolgroup", + "continuation": "::coolgroup", + "after": lib.RootGroupPath, + }, checkGroups(t, tc)) +} + +func TestGroupTrackerRestoresStageGroup(t *testing.T) { + t.Parallel() + + for _, stage := range []string{"setup", "teardown"} { + t.Run(stage, func(t *testing.T) { + t.Parallel() + tc := testCaseRuntime(t) + stageGroup, err := lib.NewGroupPath(lib.RootGroupPath, stage) + require.NoError(t, err) + tc.testRuntime.VU.State().Tags.Modify(func(tagsAndMeta *metrics.TagsAndMeta) { + tagsAndMeta.SetSystemTagOrMeta(metrics.TagGroup, stageGroup) + }) + + _, err = tc.testRuntime.RunOnEventLoop(` + Promise.resolve().then(() => k6.check(null, {reaction: true})); + k6.group("warmup", () => {}); + `) + require.NoError(t, err) + + assert.Equal(t, map[string]string{"reaction": stageGroup}, checkGroups(t, tc)) + group, _ := tc.testRuntime.VU.State().Tags.GetCurrentValues().Tags.Get( + metrics.TagGroup.String()) + require.Equal(t, stageGroup, group) + }) + } +} + +func TestGroupSupportsPromiseLikeThenable(t *testing.T) { + t.Parallel() + tc := testCaseRuntime(t) + order := newOrderRecorder(t, tc) + + _, err := tc.testRuntime.RunOnEventLoop(` + (async () => { + const grouped = k6.group("custom", () => ({ + then(onFulfilled) { + setTimeout(() => { + mark("settled"); + onFulfilled(42); + }, 1); + } + })); + mark(grouped instanceof Promise ? "promise" : "not-promise"); + const value = await grouped; + mark("after:" + value); + })(); + `) + require.NoError(t, err) + require.Equal(t, []string{"promise", "settled", "after:42"}, *order) +} + +func TestGroupThenablePreservesSettlementIdentity(t *testing.T) { + t.Parallel() + tc := testCaseRuntime(t) + + _, err := tc.testRuntime.RunOnEventLoop(` + (async () => { + const fulfillment = {}; + const fulfilled = await k6.group("fulfilled", () => ({ + then(onFulfilled) { return Promise.resolve(fulfillment).then(onFulfilled); } + })); + if (fulfilled !== fulfillment) { + throw new Error("fulfillment identity changed"); + } + + const rejection = {}; + let caught; + try { + await k6.group("rejected", () => ({ + then(_, onRejected) { return Promise.reject(rejection).then(undefined, onRejected); } + })); + } catch (reason) { + caught = reason; + } + if (caught !== rejection) { + throw new Error("rejection identity changed"); + } + })(); + `) + require.NoError(t, err) +} + +// Primitive results must not be boxed for thenable detection. +func TestGroupSynchronousResultStaysSynchronous(t *testing.T) { + t.Parallel() + tc := testCaseRuntime(t) + + result, err := tc.testRuntime.RunOnEventLoop(` + let thenCalled = false; + Number.prototype.then = function() { thenCalled = true; }; + const result = k6.group("sync", () => 42); + if (thenCalled) { throw new Error("synchronous result was treated as a thenable"); } + result; + `) + require.NoError(t, err) + require.Equal(t, int64(42), result.Export()) + group, _ := tc.testRuntime.VU.State().Tags.GetCurrentValues().Tags.Get(metrics.TagGroup.String()) + require.Equal(t, lib.RootGroupPath, group) + + samples := metrics.GetBufferedSamples(tc.samples) + require.Len(t, samples, 1) + sample, ok := samples[0].(metrics.Sample) + require.True(t, ok) + require.Equal(t, tc.testRuntime.VU.State().BuiltinMetrics.GroupDuration, sample.Metric) + metricGroup, ok := sample.Tags.Get(metrics.TagGroup.String()) + require.True(t, ok) + require.Equal(t, "::sync", metricGroup) +} + +// group_duration uses the tag and metadata snapshot captured before the callback runs. +func TestGroupDurationUsesEntryTagsAndMetadata(t *testing.T) { + t.Parallel() + + for name, script := range map[string]string{ + "sync": `k6.group("g", () => setPhase("after"));`, + "async": `(async () => { + await k6.group("g", async () => { + setPhase("after"); + await Promise.resolve(); + }); + })();`, + } { + t.Run(name, func(t *testing.T) { + t.Parallel() + tc := testCaseRuntime(t) + state := tc.testRuntime.VU.State() + state.Tags.Modify(func(tagsAndMeta *metrics.TagsAndMeta) { + tagsAndMeta.SetTag("phase", "before") + tagsAndMeta.SetMetadata("trace", "before") + }) + require.NoError(t, tc.testRuntime.VU.Runtime().Set("setPhase", func(phase string) { + state.Tags.Modify(func(tagsAndMeta *metrics.TagsAndMeta) { + tagsAndMeta.SetTag("phase", phase) + tagsAndMeta.SetMetadata("trace", phase) + }) + })) + + _, err := tc.testRuntime.RunOnEventLoop(script) + require.NoError(t, err) + + samples := metrics.GetBufferedSamples(tc.samples) + require.Len(t, samples, 1) + sample, ok := samples[0].(metrics.Sample) + require.True(t, ok) + phase, ok := sample.Tags.Get("phase") + require.True(t, ok) + require.Equal(t, "before", phase) + require.Equal(t, "before", sample.Metadata["trace"]) + }) + } +} + +// A throwing then getter must restore the parent and still record duration. +func TestGroupThrowingThenGetterRestoresParent(t *testing.T) { + t.Parallel() + tc := testCaseRuntime(t) + + _, err := tc.testRuntime.RunOnEventLoop(` + try { + k6.group("bad", () => ({ + get then() { throw new Error("boom"); } + })); + } catch (_) {} + k6.check(null, {afterFailure: true}); + k6.group("next", () => k6.check(null, {next: true})); + k6.check(null, {afterNext: true}); + `) + require.NoError(t, err) + + builtinMetrics := tc.testRuntime.VU.State().BuiltinMetrics + var badGroupDurations int + checks := make(map[string]string) + for _, sc := range metrics.GetBufferedSamples(tc.samples) { + for _, sample := range sc.GetSamples() { + group, _ := sample.Tags.Get(metrics.TagGroup.String()) + switch sample.Metric { + case builtinMetrics.GroupDuration: + if group == "::bad" { + badGroupDurations++ + } + case builtinMetrics.Checks: + name, ok := sample.Tags.Get(metrics.TagCheck.String()) + require.True(t, ok) + assert.Equal(t, float64(1), sample.Value, "check %q failed", name) + checks[name] = group + } + } + } + assert.Equal(t, map[string]string{ + "afterFailure": lib.RootGroupPath, + "next": "::next", + "afterNext": lib.RootGroupPath, + }, checks) + require.Equal(t, 1, badGroupDurations) +} + +// The Go implementation must not depend on the old private JavaScript globals. +func TestGroupNotTamperableViaGlobals(t *testing.T) { + t.Parallel() + tc := testCaseRuntime(t) + + _, err := tc.testRuntime.RunOnEventLoop(` + globalThis.__k6group = function () { throw new Error("hijacked group()"); }; + globalThis.__k6AsyncGroup = { getGroupTag: function () { return "tampered"; } }; + k6.group("real", () => { k6.check(null, {inside: true}); }); + `) + require.NoError(t, err) + assert.Equal(t, map[string]string{"inside": "::real"}, checkGroups(t, tc)) +} + +// A synchronously throwing then() rejects the returned promise and still records duration. +func TestGroupThenableThrowsStillEmitsDuration(t *testing.T) { + t.Parallel() + tc := testCaseRuntime(t) + + _, err := tc.testRuntime.RunOnEventLoop(` + (async () => { + const reason = {}; + let caught; + try { + await k6.group("g", () => ({ then() { throw reason; } })); + } catch (error) { + caught = error; + } + if (caught !== reason) { + throw new Error("rejection identity changed"); + } + })(); + `) + require.NoError(t, err) + + gd := tc.testRuntime.VU.State().BuiltinMetrics.GroupDuration + expectedGroup, err2 := lib.NewGroupPath(lib.RootGroupPath, "g") + require.NoError(t, err2) + + var found bool + for _, sc := range metrics.GetBufferedSamples(tc.samples) { + for _, s := range sc.GetSamples() { + if s.Metric == gd { + g, _ := s.Tags.Get("group") + if g == expectedGroup { + found = true + } + } + } + } + require.True(t, found, "group_duration for %q must be emitted even when the thenable throws synchronously", expectedGroup) +} + +func TestGroupSynchronousThenableRejectionEmitsDurationOnce(t *testing.T) { + t.Parallel() + tc := testCaseRuntime(t) + + _, err := tc.testRuntime.RunOnEventLoop(` + (async () => { + const rejection = new Error('rejected'); + let caught; + try { + await k6.group('g', () => ({ + then(_, reject) { reject(rejection); }, + })); + } catch (reason) { + caught = reason; + } + if (caught !== rejection) { + throw new Error('rejection identity changed'); + } + k6.check(null, {after: true}); + })(); + `) + require.NoError(t, err) + + var durations int + for _, sc := range metrics.GetBufferedSamples(tc.samples) { + for _, sample := range sc.GetSamples() { + group, _ := sample.Tags.Get(metrics.TagGroup.String()) + switch sample.Metric { + case tc.testRuntime.VU.State().BuiltinMetrics.GroupDuration: + if group == "::g" { + durations++ + } + case tc.testRuntime.VU.State().BuiltinMetrics.Checks: + assert.Equal(t, lib.RootGroupPath, group) + } + } + } + require.Equal(t, 1, durations) +} + +// Compare benchmark deltas: RunOnEventLoop adds the same compile and drain +// overhead to every case. + +func benchRun(b *testing.B, tc *testCase, src string) { + b.Helper() + if _, err := tc.testRuntime.RunOnEventLoop(src); err != nil { + b.Fatal(err) + } +} + +// Prevent group_duration emission from filling the sample buffer. +func benchDrainSamples(tc *testCase) func() { + done := make(chan struct{}) + go func() { + for { + select { + case <-done: + return + case <-tc.samples: + } + } + }() + return func() { close(done) } +} + +func BenchmarkNoGroupSync(b *testing.B) { + tc := testCaseRuntime(b) + defer benchDrainSamples(tc)() + benchRun(b, tc, `globalThis.work = () => 42;`) + + b.ReportAllocs() + b.ResetTimer() + for b.Loop() { + benchRun(b, tc, `work()`) + } +} + +func BenchmarkNoGroupSyncFeatureDisabled(b *testing.B) { + tc := testCaseRuntimeWithAsyncMetricContext(b, false) + defer benchDrainSamples(tc)() + benchRun(b, tc, `globalThis.work = () => 42;`) + + b.ReportAllocs() + b.ResetTimer() + for b.Loop() { + benchRun(b, tc, `work()`) + } +} + +func BenchmarkGroupSync(b *testing.B) { + tc := testCaseRuntime(b) + defer benchDrainSamples(tc)() + benchRun(b, tc, `globalThis.work = () => { k6.group("x", () => {}); };`) + + b.ReportAllocs() + b.ResetTimer() + for b.Loop() { + benchRun(b, tc, `work()`) + } +} + +func BenchmarkGroupAsync(b *testing.B) { + tc := testCaseRuntime(b) + defer benchDrainSamples(tc)() + benchRun(b, tc, `globalThis.work = () => k6.group("x", async () => { await Promise.resolve(); });`) + + b.ReportAllocs() + b.ResetTimer() + for b.Loop() { + benchRun(b, tc, `work()`) + } +} + +func BenchmarkPromiseOnce(b *testing.B) { + tc := testCaseRuntime(b) + defer benchDrainSamples(tc)() + benchRun(b, tc, `globalThis.work = () => Promise.resolve(1);`) + + b.ReportAllocs() + b.ResetTimer() + for b.Loop() { + benchRun(b, tc, `work()`) + } +} + +func BenchmarkAwaitPromiseOnce(b *testing.B) { + tc := testCaseRuntime(b) + defer benchDrainSamples(tc)() + benchRun(b, tc, `globalThis.work = async () => { await Promise.resolve(); };`) + + b.ReportAllocs() + b.ResetTimer() + for b.Loop() { + benchRun(b, tc, `work()`) + } +} + +func BenchmarkAwaitPromiseOnceFeatureDisabled(b *testing.B) { + tc := testCaseRuntimeWithAsyncMetricContext(b, false) + defer benchDrainSamples(tc)() + benchRun(b, tc, `globalThis.work = async () => { await Promise.resolve(); };`) + + b.ReportAllocs() + b.ResetTimer() + for b.Loop() { + benchRun(b, tc, `work()`) + } +} + +func BenchmarkAwaitGroupPromise(b *testing.B) { + tc := testCaseRuntime(b) + defer benchDrainSamples(tc)() + benchRun(b, tc, `globalThis.work = async () => { await k6.group("x", () => Promise.resolve()); };`) + + b.ReportAllocs() + b.ResetTimer() + for b.Loop() { + benchRun(b, tc, `work()`) + } +} + +func BenchmarkGroupPromise(b *testing.B) { + tc := testCaseRuntime(b) + defer benchDrainSamples(tc)() + benchRun(b, tc, `globalThis.work = () => k6.group("x", () => Promise.resolve(1));`) + + b.ReportAllocs() + b.ResetTimer() + for b.Loop() { + benchRun(b, tc, `work()`) + } +} + +const benchPromiseWorkload = `globalThis.work = async () => { + let value = 0; + for (let i = 0; i < 100; i++) { + value = await Promise.resolve(value + 1); + } + return value; +};` + +func BenchmarkPromiseWorkload(b *testing.B) { + tc := testCaseRuntime(b) + defer benchDrainSamples(tc)() + benchRun(b, tc, benchPromiseWorkload) + + b.ReportAllocs() + b.ResetTimer() + for b.Loop() { + benchRun(b, tc, `work()`) + } +} + +const benchSparseAsyncGroup = `globalThis.work = async () => { + let value = 0; + for (let i = 0; i < 100; i++) { + if (i === 50) { + value = await k6.group("x", async () => Promise.resolve(value + 1)); + } else { + value = await Promise.resolve(value + 1); + } + } + return value; +};` + +func BenchmarkSparseAsyncGroup(b *testing.B) { + tc := testCaseRuntime(b) + defer benchDrainSamples(tc)() + benchRun(b, tc, benchSparseAsyncGroup) + + b.ReportAllocs() + b.ResetTimer() + for b.Loop() { + benchRun(b, tc, `work()`) + } +} + +const benchSparsePromiseGroup = `globalThis.work = async () => { + let value = 0; + for (let i = 0; i < 100; i++) { + if (i === 50) { + value = await k6.group("x", () => Promise.resolve(value + 1)); + } else { + value = await Promise.resolve(value + 1); + } + } + return value; +};` + +func BenchmarkSparsePromiseGroup(b *testing.B) { + tc := testCaseRuntime(b) + defer benchDrainSamples(tc)() + benchRun(b, tc, benchSparsePromiseGroup) + + b.ReportAllocs() + b.ResetTimer() + for b.Loop() { + benchRun(b, tc, `work()`) + } +} + +const benchPromiseChain = `globalThis.work = () => { + let p = Promise.resolve(0); + for (let i = 0; i < 20; i++) { + p = p.then((v) => v + 1); + } + return p; +};` + +func BenchmarkPromiseChainFeatureDisabled(b *testing.B) { + tc := testCaseRuntimeWithAsyncMetricContext(b, false) + benchRun(b, tc, benchPromiseChain) + + b.ReportAllocs() + b.ResetTimer() + for b.Loop() { + benchRun(b, tc, `work()`) + } +} + +// Compare with BenchmarkPromiseChainFeatureDisabled to measure tracker overhead. +func BenchmarkPromiseChainWithTracker(b *testing.B) { + tc := testCaseRuntime(b) + benchRun(b, tc, benchPromiseChain) + + b.ReportAllocs() + b.ResetTimer() + for b.Loop() { + benchRun(b, tc, `work()`) + } +} diff --git a/internal/js/modules/k6/k6.go b/internal/js/modules/k6/k6.go index 9a0366e05..d4992acc7 100644 --- a/internal/js/modules/k6/k6.go +++ b/internal/js/modules/k6/k6.go @@ -30,7 +30,8 @@ type ( // K6 represents an instance of the k6 module. K6 struct { - vu modules.VU + vu modules.VU + asyncGroups bool } ) @@ -47,7 +48,17 @@ func New() *RootModule { // NewModuleInstance implements the modules.Module interface to return // a new instance for each VU. func (*RootModule) NewModuleInstance(vu modules.VU) modules.Instance { - return &K6{vu: vu} + asyncGroups := asyncGroupsEnabled(vu) + return &K6{vu: vu, asyncGroups: asyncGroups} +} + +func asyncGroupsEnabled(vu modules.VU) bool { + if state := vu.State(); state != nil { + return common.AsyncMetricContextEnabled(state) + } + initEnv := vu.InitEnv() + return initEnv != nil && initEnv.TestPreInitState != nil && + initEnv.FeatureFlags != nil && initEnv.FeatureFlags.AsyncMetricContext } // Exports returns the exports of the k6 module. @@ -85,7 +96,10 @@ func (mi *K6) RandomSeed(seed int64) { mi.vu.Runtime().SetRandSource(randSource) } -// Group wraps a function call and executes it within the provided group name. +// Group executes a callback under the provided group name. +// +// With the async-metric-context feature enabled, async callbacks retain their metric +// context through promise reactions and group_duration covers their lifetime. func (mi *K6) Group(name string, val sobek.Value) (sobek.Value, error) { state := mi.vu.State() if state == nil { @@ -99,12 +113,13 @@ func (mi *K6) Group(name string, val sobek.Value) (sobek.Value, error) { if !ok { return nil, errors.New("group() requires a callback as a second argument") } - if common.IsAsyncFunction(mi.vu.Runtime(), val) { + if !mi.asyncGroups && common.IsAsyncFunction(mi.vu.Runtime(), val) { return sobek.Undefined(), errors.New("group() does not support async functions as arguments, " + "please see https://grafana.com/docs/k6/latest/javascript-api/k6/group/ for more info") } - oldGroupName, _ := state.Tags.GetCurrentValues().Tags.Get(metrics.TagGroup.String()) - // TODO: what are we doing if group is not tagged + + parentTagsAndMeta := state.Tags.GetCurrentValues() + oldGroupName, _ := parentTagsAndMeta.Tags.Get(metrics.TagGroup.String()) newGroupName, err := lib.NewGroupPath(oldGroupName, name) if err != nil { return sobek.Undefined(), err @@ -112,35 +127,63 @@ func (mi *K6) Group(name string, val sobek.Value) (sobek.Value, error) { shouldUpdateTag := state.Options.SystemTags.Has(metrics.TagGroup) if shouldUpdateTag { - state.Tags.Modify(func(tagsAndMeta *metrics.TagsAndMeta) { - tagsAndMeta.SetSystemTagOrMeta(metrics.TagGroup, newGroupName) - }) + setGroupTag(state, newGroupName) + } + var groupTagsAndMeta metrics.TagsAndMeta + if mi.asyncGroups { + groupTagsAndMeta = state.Tags.GetCurrentValues() } + synchronous := true + var startTime, endTime time.Time defer func() { - if shouldUpdateTag { + if synchronous { + if endTime.IsZero() { + endTime = time.Now() + } + durationTagsAndMeta := groupTagsAndMeta + if !mi.asyncGroups { + durationTagsAndMeta = state.Tags.GetCurrentValues() + } + emitGroupDuration(mi.vu, startTime, endTime, durationTagsAndMeta) + } + if mi.asyncGroups { state.Tags.Modify(func(tagsAndMeta *metrics.TagsAndMeta) { - tagsAndMeta.SetSystemTagOrMeta(metrics.TagGroup, oldGroupName) + *tagsAndMeta = parentTagsAndMeta }) + } else if shouldUpdateTag { + setGroupTag(state, oldGroupName) } }() - startTime := time.Now() + startTime = time.Now() ret, err := fn(sobek.Undefined()) - t := time.Now() + endTime = time.Now() + if err != nil || !mi.asyncGroups { + return ret, err + } - ctx := mi.vu.Context() - ctm := state.Tags.GetCurrentValues() - metrics.PushIfNotDone(ctx, state.Samples, metrics.Sample{ - TimeSeries: metrics.TimeSeries{ - Metric: state.BuiltinMetrics.GroupDuration, - Tags: ctm.Tags, - }, - Time: t, - Value: metrics.D(t.Sub(startTime)), - Metadata: ctm.Metadata, - }) + thenFn, isThenable := asThenable(ret) + if !isThenable { + return ret, nil + } - return ret, err + asyncResult, settled, err := mi.runAsyncGroup(startTime, groupTagsAndMeta, thenFn, ret) + if err != nil { + // A custom thenable may invoke a settlement handler synchronously. In that case the handler + // emitted the duration before its rejection propagated back through then(). + synchronous = !settled + return nil, err + } + // Settlement handlers now own duration emission. Until they are installed successfully, the + // deferred synchronous path must retain ownership so an initialization error still emits once. + synchronous = false + return asyncResult, nil +} + +func setGroupTag(state *lib.State, name string) { + state.Tags.Modify(func(tagsAndMeta *metrics.TagsAndMeta) { + tagsAndMeta.SetSystemTagOrMeta(metrics.TagGroup, name) + }) } // Check will emit check metrics for the provided checks. diff --git a/internal/js/modules/k6/k6_test.go b/internal/js/modules/k6/k6_test.go index 19d493f02..08094ca7b 100644 --- a/internal/js/modules/k6/k6_test.go +++ b/internal/js/modules/k6/k6_test.go @@ -5,9 +5,12 @@ import ( "testing" "time" + "github.com/grafana/sobek" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.k6.io/k6/v2/internal/features" + "go.k6.io/k6/v2/js/common" "go.k6.io/k6/v2/js/modulestest" "go.k6.io/k6/v2/lib" "go.k6.io/k6/v2/metrics" @@ -87,6 +90,20 @@ func TestRandSeed(t *testing.T) { func TestGroup(t *testing.T) { t.Parallel() + t.Run("init context", func(t *testing.T) { + t.Parallel() + rt := sobek.New() + vu := &modulestest.VU{ + RuntimeField: rt, + InitEnvField: &common.InitEnvironment{}, + } + mi, ok := New().NewModuleInstance(vu).(*K6) + require.True(t, ok) + + _, err := mi.Group("group", rt.ToValue(func() {})) + require.ErrorIs(t, err, ErrGroupInInitContext) + }) + t.Run("Valid", func(t *testing.T) { t.Parallel() tc := testCaseRuntime(t) @@ -113,15 +130,32 @@ func TestGroup(t *testing.T) { t.Run("async function", func(t *testing.T) { t.Parallel() tc := testCaseRuntime(t) - _, err := tc.testRuntime.RunOnEventLoop(`k6.group("something", async function() { })`) - assert.ErrorContains(t, err, "group() does not support async functions as arguments") + state := tc.testRuntime.VU.State() + require.NoError(t, tc.testRuntime.VU.Runtime().Set("fn", func() { + groupTag, ok := state.Tags.GetCurrentValues().Tags.Get("group") + require.True(t, ok) + assert.Equal(t, "::something", groupTag) + })) + _, err := tc.testRuntime.RunOnEventLoop( + `k6.group("something", async function() { fn(); await Promise.resolve(); })`) + assert.NoError(t, err) + groupTag, ok := state.Tags.GetCurrentValues().Tags.Get("group") + require.True(t, ok) + assert.Equal(t, "", groupTag) }) t.Run("async lambda", func(t *testing.T) { t.Parallel() tc := testCaseRuntime(t) _, err := tc.testRuntime.RunOnEventLoop(`k6.group("something", async () => { })`) - assert.ErrorContains(t, err, "group() does not support async functions as arguments") + assert.NoError(t, err) + }) + + t.Run("async function disabled", func(t *testing.T) { + t.Parallel() + tc := testCaseRuntimeWithAsyncMetricContext(t, false) + _, err := tc.testRuntime.RunOnEventLoop(`k6.group("something", async () => {})`) + assert.ErrorContains(t, err, "group() does not support async functions") }) } @@ -372,7 +406,13 @@ type testCase struct { } func testCaseRuntime(t testing.TB) *testCase { + return testCaseRuntimeWithAsyncMetricContext(t, true) +} + +func testCaseRuntimeWithAsyncMetricContext(t testing.TB, enabled bool) *testCase { testRuntime := modulestest.NewRuntime(t) + featureFlags := &features.Flags{AsyncMetricContext: enabled} + testRuntime.VU.InitEnvField.FeatureFlags = featureFlags m, ok := New().NewModuleInstance(testRuntime.VU).(*K6) require.True(t, ok) require.NoError(t, testRuntime.VU.RuntimeField.Set("k6", m.Exports().Named)) @@ -380,6 +420,7 @@ func testCaseRuntime(t testing.TB) *testCase { registry := metrics.NewRegistry() samples := make(chan metrics.SampleContainer, 1000) state := &lib.State{ + FeatureFlags: featureFlags, Options: lib.Options{ SystemTags: &metrics.DefaultSystemTagSet, }, @@ -388,6 +429,11 @@ func testCaseRuntime(t testing.TB) *testCase { BuiltinMetrics: metrics.RegisterBuiltinMetrics(registry), } testRuntime.MoveToVUContext(state) + if enabled { + testRuntime.VU.RuntimeField.SetAsyncContextTracker( + common.NewMetricContextTracker(testRuntime.VU.State), + ) + } return &testCase{ samples: samples, From 2ce1cfff471956ffdd636ea4d94cf2f2231201fc Mon Sep 17 00:00:00 2001 From: Mihail Stoykov <312246+mstoykov@users.noreply.github.com> Date: Tue, 15 Sep 2026 12:13:37 +0300 Subject: [PATCH 151/182] Fix cleared timer callbacks and connecting WebSocket hangs (#6351) * timers: prevent cleared tasks from running later callbacks Timer callbacks were queued as a generic runFirstTask operation. If a timer expired and queued its task while JavaScript was still running, clearTimeout could remove that timer before dispatch. The stale task then popped the new queue head and ran a later timeout or interval too early. The sorted queue introduced by 05ee9051a fixed timer ordering. The head rearm added by df2c3dfb3 handled timers cleared before their Go timer fired. Neither change could retract an event-loop task that had already been queued. Bind each queued task to its exact timer instance and ignore the task when that instance is no longer active. This keeps timeout and interval identity aligned from definition through event-loop execution. Cover both clear APIs against timeouts and intervals, including an expired sole timer and an expired queue head. Repeat the regressions across reused runtimes, and verify stale work cannot consume replacement timers from a newly created task queue. Add a WebSocket regression showing how prematurely running a later close callback could block the event loop and prevent a VU from finishing. * websockets: cancel pending handshakes on close WebSocket.close() sent a close frame to the unbuffered write queue in every active state. While CONNECTING, the write pump does not exist until the HTTP upgrade succeeds. A slow upgrade therefore blocked the JavaScript event loop, and a failed upgrade left no receiver at all, hanging the VU. Give each handshake a cancelable context and close its pending transport when the context ends. Coordinate connection publication with close() under the connection mutex: if cancellation wins, do not queue a close frame; if establishment wins, start the socket loop before close() can use the normal unbuffered closing path. This avoids both a receiver-less send and a race at the end of the HTTP upgrade. Keep bufferedAmount updates on the JavaScript event loop while ordering successful write completions before causally dependent inbound events. This preserves the immediate value after send() and prevents an echoed message from observing bytes that have already been written. Make that regression listener synchronous so assertion failures close the socket instead of becoming unobserved promise rejections that strand the test. Limit the child context to handshake establishment. Established sockets, pumps, and metrics remain governed by the longer-lived VU context. Also validate close arguments before state-based no-op handling. Preserve the timer regression from the preceding timer fix by asserting event order after the WebSocket lifecycle change. Cover the pending handshake close, establishment race, VU cancellation, readyState transitions, validation after CLOSED, and bufferedAmount event ordering. Related history: - 7e82c3dfc corrected readyState exposure. - 15c30ca20 added close code and reason handling while retaining the synchronous queue send. - d838f20be fixed an analogous no-consumer shutdown deadlock in ping and pong handlers. - 133cd8138 fixes a complementary post-write-failure queue hang on another branch and is not in this branch's ancestry. * websockets: preserve close code while connecting --- .../js/modules/k6/websockets/websockets.go | 183 ++++++++++++----- .../modules/k6/websockets/websockets_test.go | 184 +++++++++++++++++- internal/js/tc55/timers/timers.go | 73 +++---- internal/js/tc55/timers/timers_test.go | 122 ++++++++++++ 4 files changed, 471 insertions(+), 91 deletions(-) diff --git a/internal/js/modules/k6/websockets/websockets.go b/internal/js/modules/k6/websockets/websockets.go index 15ee993b8..4072adc06 100644 --- a/internal/js/modules/k6/websockets/websockets.go +++ b/internal/js/modules/k6/websockets/websockets.go @@ -95,8 +95,14 @@ type webSocket struct { obj *sobek.Object // the object that is given to js to interact with the WebSocket started time.Time - done chan struct{} - writeQueueCh chan message + done chan struct{} + writeQueueCh chan message + connectCancel context.CancelFunc + + connectionMu sync.Mutex + // pendingConnection and publishing conn are guarded by connectionMu. Once connected, it also + // orders successful writes before events for data that the peer can only send after that write. + pendingConnection net.Conn eventListeners *eventListeners @@ -145,6 +151,7 @@ func (r *WebSocketsAPI) websocket(c sobek.ConstructorCall) *sobek.Object { } } + connectionCtx, connectCancel := context.WithCancel(r.vu.Context()) w := &webSocket{ vu: r.vu, blobConstructor: r.blobConstructor, @@ -154,6 +161,7 @@ func (r *WebSocketsAPI) websocket(c sobek.ConstructorCall) *sobek.Object { builtinMetrics: r.vu.State().BuiltinMetrics, done: make(chan struct{}), writeQueueCh: make(chan message), + connectCancel: connectCancel, eventListeners: newEventListeners(), obj: rt.NewObject(), tagsAndMeta: params.tagsAndMeta, @@ -164,7 +172,7 @@ func (r *WebSocketsAPI) websocket(c sobek.ConstructorCall) *sobek.Object { // Maybe have this after the goroutine below ?!? defineWebsocket(rt, w) - go w.establishConnection(params) + go w.establishConnection(connectionCtx, params) return w.obj } @@ -290,34 +298,19 @@ type message struct { } // documented https://websockets.spec.whatwg.org/#concept-websocket-establish -func (w *webSocket) establishConnection(params *wsParams) { +func (w *webSocket) establishConnection(ctx context.Context, params *wsParams) { + defer w.connectCancel() + state := w.vu.State() w.started = time.Now() - var tlsConfig *tls.Config - if state.TLSConfig != nil { - tlsConfig = state.TLSConfig.Clone() - tlsConfig.NextProtos = []string{"http/1.1"} - } - // technically we have to do a fetch request here, so ... uh do normal one ;) - wsd := websocket.Dialer{ - HandshakeTimeout: time.Second * 60, // TODO configurable - // Pass a custom net.DialContext function to websocket.Dialer that will substitute - // the underlying net.Conn with our own tracked netext.Conn - NetDialContext: state.Dialer.DialContext, - Proxy: http.ProxyFromEnvironment, - TLSClientConfig: tlsConfig, - EnableCompression: params.enableCompression, - Subprotocols: params.subprocotols, - } - - // this is needed because of how interfaces work and that wsd.Jar is http.Cookiejar - if params.cookieJar != nil { - wsd.Jar = params.cookieJar - } - - ctx := w.vu.Context() + handshakeDone := make(chan struct{}) + go w.closePendingConnectionOnContextDone(ctx, handshakeDone) start := time.Now() - conn, httpResponse, connErr := wsd.DialContext(ctx, w.url.String(), params.headers) + conn, httpResponse, connErr := w.dial(ctx, params) + w.connectionMu.Lock() + w.pendingConnection = nil + w.connectionMu.Unlock() + close(handshakeDone) connectionEnd := time.Now() connectionDuration := metrics.D(connectionEnd.Sub(start)) @@ -341,10 +334,8 @@ func (w *webSocket) establishConnection(params *wsParams) { w.extensions = httpResponse.Header.Values("Sec-WebSocket-Extensions") w.tagsAndMeta.SetSystemTagOrMetaIfEnabled(systemTags, metrics.TagSubproto, w.protocol) } - w.conn = conn - nameTagValue, nameTagManuallySet := params.tagsAndMeta.Tags.Get(metrics.TagName.String()) - // After k6 v0.41.0, the `name` and `url` tags have the exact same values: + // After k6 v0.41.0, the name and URL tags have the same values. if nameTagManuallySet { w.tagsAndMeta.SetSystemTagOrMetaIfEnabled(systemTags, metrics.TagURL, nameTagValue) } else { @@ -352,7 +343,8 @@ func (w *webSocket) establishConnection(params *wsParams) { w.tagsAndMeta.SetSystemTagOrMetaIfEnabled(systemTags, metrics.TagName, w.url.String()) } - w.emitConnectionMetrics(ctx, start, connectionDuration) + //nolint:contextcheck // Handshake cancellation must not suppress connection metrics. + w.emitConnectionMetrics(w.vu.Context(), start, connectionDuration) if connErr != nil { // Pass the error to the user script before exiting immediately w.tq.Queue(func() error { @@ -361,12 +353,88 @@ func (w *webSocket) establishConnection(params *wsParams) { w.tq.Close() return } + + w.connectionMu.Lock() + if ctx.Err() != nil { + w.connectionMu.Unlock() + _ = conn.Close() + w.tq.Queue(func() error { + return w.connectionClosedWithError(ctx.Err()) + }) + w.tq.Close() + return + } + w.conn = conn + //nolint:contextcheck // An established connection is governed by the longer-lived VU context. go w.loop() + w.connectionMu.Unlock() w.tq.Queue(func() error { return w.connectionConnected() }) } +func (w *webSocket) dial(ctx context.Context, params *wsParams) (*websocket.Conn, *http.Response, error) { + state := w.vu.State() + var tlsConfig *tls.Config + if state.TLSConfig != nil { + tlsConfig = state.TLSConfig.Clone() + tlsConfig.NextProtos = []string{"http/1.1"} + } + // technically we have to do a fetch request here, so ... uh do normal one ;) + wsd := websocket.Dialer{ + HandshakeTimeout: time.Second * 60, // TODO configurable + // Pass a custom net.DialContext function to websocket.Dialer that will substitute + // the underlying net.Conn with our own tracked netext.Conn + NetDialContext: func(ctx context.Context, network, addr string) (net.Conn, error) { + conn, err := state.Dialer.DialContext(ctx, network, addr) + if err != nil { + return nil, err + } + + w.connectionMu.Lock() + if ctx.Err() != nil { + w.connectionMu.Unlock() + _ = conn.Close() + return nil, ctx.Err() + } + w.pendingConnection = conn + w.connectionMu.Unlock() + + return conn, nil + }, + Proxy: http.ProxyFromEnvironment, + TLSClientConfig: tlsConfig, + EnableCompression: params.enableCompression, + Subprotocols: params.subprocotols, + } + + // this is needed because of how interfaces work and that wsd.Jar is http.Cookiejar + if params.cookieJar != nil { + wsd.Jar = params.cookieJar + } + + return wsd.DialContext(ctx, w.url.String(), params.headers) +} + +func (w *webSocket) closePendingConnectionOnContextDone(ctx context.Context, handshakeDone <-chan struct{}) { + select { + case <-ctx.Done(): + case <-handshakeDone: + return + } + w.closePendingConnection() +} + +func (w *webSocket) closePendingConnection() { + w.connectionMu.Lock() + conn := w.pendingConnection + w.pendingConnection = nil + w.connectionMu.Unlock() + if conn != nil { + _ = conn.Close() + } +} + // emitConnectionMetrics emits the metrics for a websocket connection. func (w *webSocket) emitConnectionMetrics(ctx context.Context, start time.Time, duration float64) { state := w.vu.State() @@ -417,8 +485,8 @@ func (w *webSocket) loop() { return nil }) - ctx := w.vu.Context() wg := new(sync.WaitGroup) + ctx := w.vu.Context() defer func() { metrics.PushIfNotDone(ctx, w.vu.State().Samples, metrics.Sample{ @@ -535,11 +603,15 @@ func (w *webSocket) readPump(wg *sync.WaitGroup) { for { messageType, data, err := w.conn.ReadMessage() if err == nil { + // An immediate peer response can arrive before WriteMessage() returns. Wait for the + // writer to queue its bufferedAmount update before queuing the corresponding event. + w.connectionMu.Lock() w.queueMessage(&message{ mtype: messageType, data: data, t: time.Now(), }) + w.connectionMu.Unlock() continue } @@ -583,6 +655,10 @@ func (w *webSocket) writePump(wg *sync.WaitGroup) { } size := len(msg.data) + // Lock before writing because the peer can respond while WriteMessage() is still + // returning. Keep the lock through Queue() so readPump cannot queue that response + // ahead of the bufferedAmount update on the JavaScript event loop. + w.connectionMu.Lock() err := func() error { if msg.mtype != websocket.PingMessage { return w.conn.WriteMessage(msg.mtype, msg.data) @@ -591,6 +667,15 @@ func (w *webSocket) writePump(wg *sync.WaitGroup) { // WriteControl is concurrently okay return w.conn.WriteControl(msg.mtype, msg.data, msg.t.Add(writeWait)) }() + if err == nil { + // This from the specification needs to happen like that instead of with + // atomics or locks outside of the event loop. + w.tq.Queue(func() error { + w.bufferedAmount -= size + return nil + }) + } + w.connectionMu.Unlock() if err != nil { w.tq.Queue(func() error { _ = w.conn.Close() // TODO fix @@ -599,12 +684,6 @@ func (w *webSocket) writePump(wg *sync.WaitGroup) { }) return } - // This from the specification needs to happen like that instead of with - // atomics or locks outside of the event loop - w.tq.Queue(func() error { - w.bufferedAmount -= size - return nil - }) metrics.PushIfNotDone(ctx, samplesOutput, metrics.Sample{ TimeSeries: metrics.TimeSeries{ @@ -789,10 +868,6 @@ func isValidCloseReason(reason string) bool { } func (w *webSocket) close(code int, reason string) error { - if w.readyState == CLOSED || w.readyState == CLOSING { - return nil - } - if code != 0 && !isValidClientCloseCode(code) { return fmt.Errorf( "InvalidAccessError: Failed to execute 'close' on 'WebSocket': "+ @@ -806,13 +881,31 @@ func (w *webSocket) close(code int, reason string) error { `SyntaxError: Failed to execute 'close' on 'WebSocket': The message must not be greater than 123 bytes`, ) } - + if w.readyState == CLOSED || w.readyState == CLOSING { + return nil + } if code == 0 { code = websocket.CloseNormalClosure } + w.closeCode = code + wasConnecting := w.readyState == CONNECTING w.readyState = CLOSING - w.closeCode = code + if wasConnecting { + w.connectionMu.Lock() + w.connectCancel() + pendingConnection := w.pendingConnection + w.pendingConnection = nil + connectionEstablished := w.conn != nil + w.connectionMu.Unlock() + + if pendingConnection != nil { + _ = pendingConnection.Close() + } + if !connectionEstablished { + return nil + } + } w.writeQueueCh <- message{ mtype: websocket.CloseMessage, diff --git a/internal/js/modules/k6/websockets/websockets_test.go b/internal/js/modules/k6/websockets/websockets_test.go index f8fc690e2..483f7c865 100644 --- a/internal/js/modules/k6/websockets/websockets_test.go +++ b/internal/js/modules/k6/websockets/websockets_test.go @@ -202,6 +202,25 @@ func (ts *testState) addHandler(uri string, upgrader *websocket.Upgrader, messag })) } +func runOnEventLoopWithTimeout(t *testing.T, runtime *modulestest.Runtime, code string) error { + t.Helper() + + result := make(chan error, 1) + go func() { + _, err := runtime.RunOnEventLoop(code) + result <- err + }() + + select { + case err := <-result: + return err + case <-time.After(3 * time.Second): + runtime.CancelContext() + t.Fatal("event loop did not finish") + return nil + } +} + type testMessage struct { kind int data []byte @@ -223,6 +242,145 @@ func TestBasic(t *testing.T) { assertSessionMetricsEmitted(t, samples, "", sr("WSBIN_URL/ws-echo"), http.StatusSwitchingProtocols, "") } +func TestClearedExpiredTimerDoesNotCloseConnectingWebSocket(t *testing.T) { + t.Parallel() + + ts := newTestState(t) + requestStarted := make(chan struct{}) + ts.tb.Mux.HandleFunc("/ws-delayed-failure", func(w http.ResponseWriter, _ *http.Request) { + close(requestStarted) + time.Sleep(250 * time.Millisecond) + http.Error(w, "handshake failed", http.StatusBadRequest) + }) + + require.NoError(t, ts.runtime.VU.RuntimeField.Set("waitForRequest", func() { <-requestStarted })) + require.NoError(t, ts.runtime.VU.RuntimeField.Set("sleep", time.Sleep)) + + err := runOnEventLoopWithTimeout(t, ts.runtime, ts.tb.Replacer.Replace(` + const ws = new WebSocket("WSBIN_URL/ws-delayed-failure"); + ws.onerror = () => call("error"); + + setTimeout(() => { + call("close timer"); + ws.close(); + }, 1000); + const canceledTimer = setTimeout(() => {}, 10); + + waitForRequest(); + sleep(20_000_000); + clearTimeout(canceledTimer); + `)) + require.NoError(t, err) + require.Equal(t, []string{"error", "close timer"}, ts.callRecorder.Recorded()) +} + +func TestCloseWhileConnectingCancelsHandshake(t *testing.T) { + t.Parallel() + + ts := newTestState(t) + requestStarted := make(chan struct{}) + requestCanceled := make(chan struct{}) + ts.tb.Mux.HandleFunc("/ws-pending-handshake", func(_ http.ResponseWriter, req *http.Request) { + close(requestStarted) + <-req.Context().Done() + close(requestCanceled) + }) + + require.NoError(t, ts.runtime.VU.RuntimeField.Set("waitForRequest", func() { <-requestStarted })) + err := runOnEventLoopWithTimeout(t, ts.runtime, ts.tb.Replacer.Replace(` + const ws = new WebSocket("WSBIN_URL/ws-pending-handshake"); + ws.onerror = () => call("error:" + ws.readyState); + ws.onclose = (event) => call("close:" + ws.readyState + ":" + event.code); + + waitForRequest(); + call("before:" + ws.readyState); + ws.close(); + call("after:" + ws.readyState); + `)) + require.NoError(t, err) + require.Equal(t, []string{"before:0", "after:2", "error:3", "close:3:1000"}, ts.callRecorder.Recorded()) + + select { + case <-requestCanceled: + case <-time.After(time.Second): + t.Fatal("WebSocket handshake was not canceled") + } +} + +func TestCloseWhileHandshakeBecomesEstablished(t *testing.T) { + t.Parallel() + + ts := newTestState(t) + upgraded := make(chan struct{}) + serverDone := make(chan struct{}) + ts.tb.Mux.HandleFunc("/ws-close-during-upgrade", func(w http.ResponseWriter, req *http.Request) { + conn, err := (&websocket.Upgrader{}).Upgrade(w, req, w.Header()) + if err != nil { + ts.errors <- fmt.Errorf("cannot upgrade request: %w", err) + return + } + close(upgraded) + defer close(serverDone) + defer func() { _ = conn.Close() }() + for { + if _, _, err = conn.ReadMessage(); err != nil { + return + } + } + }) + + require.NoError(t, ts.runtime.VU.RuntimeField.Set("waitForUpgrade", func() { <-upgraded })) + require.NoError(t, ts.runtime.VU.RuntimeField.Set("sleep", time.Sleep)) + err := runOnEventLoopWithTimeout(t, ts.runtime, ts.tb.Replacer.Replace(` + const ws = new WebSocket("WSBIN_URL/ws-close-during-upgrade"); + ws.onopen = () => call("open"); + ws.onerror = () => call("error:" + ws.readyState); + ws.onclose = (event) => call("close:" + ws.readyState + ":" + event.code); + + waitForUpgrade(); + sleep(20_000_000); + call("before:" + ws.readyState); + ws.close(3001); + call("after:" + ws.readyState); + `)) + require.NoError(t, err) + require.Equal(t, []string{"before:0", "after:2", "error:3", "close:3:3001"}, ts.callRecorder.Recorded()) + + select { + case <-serverDone: + case <-time.After(time.Second): + t.Fatal("established WebSocket connection was not closed") + } +} + +func TestContextCancelWhileConnectingCancelsHandshake(t *testing.T) { + t.Parallel() + + ts := newTestState(t) + requestStarted := make(chan struct{}) + requestCanceled := make(chan struct{}) + ts.tb.Mux.HandleFunc("/ws-canceled-context", func(_ http.ResponseWriter, req *http.Request) { + close(requestStarted) + <-req.Context().Done() + close(requestCanceled) + }) + + require.NoError(t, ts.runtime.VU.RuntimeField.Set("waitForRequest", func() { <-requestStarted })) + require.NoError(t, ts.runtime.VU.RuntimeField.Set("cancel", ts.runtime.CancelContext)) + err := runOnEventLoopWithTimeout(t, ts.runtime, ts.tb.Replacer.Replace(` + new WebSocket("WSBIN_URL/ws-canceled-context"); + waitForRequest(); + cancel(); + `)) + require.NoError(t, err) + + select { + case <-requestCanceled: + case <-time.After(time.Second): + t.Fatal("WebSocket handshake survived VU context cancellation") + } +} + func TestBasicSendBlob(t *testing.T) { t.Parallel() ts := newTestState(t) @@ -1568,7 +1726,7 @@ func testArrayBufferViewBufferedAmount(t *testing.T, viewName string) { if (ws.bufferedAmount != sent.byteLength) { throw new Error("Expected " + sent.byteLength + " bufferedAmount got " + ws.bufferedAmount); } - ws.onmessage = async (e) => { + ws.onmessage = (e) => { if (ws.bufferedAmount != 0) { throw new Error("Expected 0 bufferedAmount got " + ws.bufferedAmount); } @@ -1682,6 +1840,30 @@ func TestCloseWithReasonTooLong(t *testing.T) { assertSessionMetricsEmitted(t, samples, "", sr("WSBIN_URL/ws-echo"), http.StatusSwitchingProtocols, "") } +func TestCloseValidatesArgumentsWhenClosed(t *testing.T) { + t.Parallel() + + ts := newTestState(t) + _, err := ts.runtime.RunOnEventLoop(ts.tb.Replacer.Replace(` + const ws = new WebSocket("WSBIN_URL/ws-echo"); + ws.onopen = () => ws.close(); + ws.onclose = () => { + try { + ws.close(1001); + } catch (_) { + call("invalid code"); + } + try { + ws.close(1000, "a really really long reason about why we are closing this connection, which is clearly over the top and too long, long enough to be longer than the allowed amount of 123 bytes"); + } catch (_) { + call("invalid reason"); + } + }; + `)) + require.NoError(t, err) + require.Equal(t, []string{"invalid code", "invalid reason"}, ts.callRecorder.Recorded()) +} + func TestRemoteCloseWithCodeAndReason(t *testing.T) { t.Parallel() ts := newTestState(t) diff --git a/internal/js/tc55/timers/timers.go b/internal/js/tc55/timers/timers.go index 40a089013..4f5fe1175 100644 --- a/internal/js/tc55/timers/timers.go +++ b/internal/js/tc55/timers/timers.go @@ -20,7 +20,7 @@ type timers struct { timerIDCounter uint64 - timers map[uint64]time.Time + timers map[uint64]*timer // Maybe in the future if this moves to core it will be expanded to have multiple queues queue *timerQueue @@ -46,7 +46,7 @@ func SetupGlobally(vu modules.VU) error { func newTimers(vu modules.VU) *timers { return &timers{ vu: vu, - timers: make(map[uint64]time.Time), + timers: make(map[uint64]*timer), queue: new(timerQueue), } } @@ -138,40 +138,22 @@ func (e *timers) timerInitialization( common.Throw(e.vu.Runtime(), fmt.Errorf("%s's callback isn't a callable function", name)) } - task := func() error { - // Specification 8.1: If id does not exist in global's map of active timers, then abort these steps. - if _, exist := e.timers[id]; !exist { - return nil - } - - err := e.call(callback, args) - - if _, exist := e.timers[id]; !exist { // 8.4 - return err - } - - if repeat { - e.timerInitialization(callback, timeout, args, repeat, id) - } else { - delete(e.timers, id) - } - - return err - } - - e.runAfterTimeout(&timer{ + t := &timer{ id: id, - task: task, nextTrigger: time.Now().Add(time.Duration(timeout * float64(time.Millisecond))), name: name, - }) + } + t.task = func() error { + return e.runTask(t, callback, timeout, args, repeat) + } + e.runAfterTimeout(t) } // https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#run-steps-after-a-timeout // Notes: this just takes timers as makes the implementation way easier and we do not currently need // most of the functionality provided func (e *timers) runAfterTimeout(t *timer) { - e.timers[t.id] = t.nextTrigger + e.timers[t.id] = t // as we have only one orderingId we have one queue index := e.queue.add(t) @@ -183,13 +165,23 @@ func (e *timers) runAfterTimeout(t *timer) { e.setupTaskTimeout() } -func (e *timers) runFirstTask() error { - t := e.queue.pop() - if t == nil { - return nil // everything was cleared +func (e *timers) runTask( + t *timer, callback sobek.Callable, timeout float64, args []sobek.Value, repeat bool, +) error { + if e.timers[t.id] != t { + return nil // the timer was cleared after its task was queued } + e.queue.remove(t.id) - err := t.task() + err := e.call(callback, args) + + if e.timers[t.id] == t { + if repeat { + e.timerInitialization(callback, timeout, args, repeat, t.id) + } else { + delete(e.timers, t.id) + } + } if e.queue.length() > 0 { e.setupTaskTimeout() @@ -202,14 +194,15 @@ func (e *timers) runFirstTask() error { func (e *timers) setupTaskTimeout() { e.queue.stopTimer() - delay := -time.Since(e.timers[e.queue.first().id]) + t := e.queue.first() + delay := -time.Since(t.nextTrigger) if e.taskQueue == nil { e.taskQueue = taskqueue.New(e.vu.RegisterCallback) e.setupTaskQueueCloserOnIterationEnd() } q := e.taskQueue e.queue.head = time.AfterFunc(delay, func() { - q.Queue(e.runFirstTask) + q.Queue(t.task) }) } @@ -264,7 +257,7 @@ func (e *timers) setupTaskQueueCloserOnIterationEnd() { }) q.Close() case <-ch: - e.timers = make(map[uint64]time.Time) + e.timers = make(map[uint64]*timer) e.queue.stopTimer() e.queue = new(timerQueue) e.taskQueue = nil @@ -315,16 +308,6 @@ func (tq *timerQueue) remove(id uint64) { }) } -func (tq *timerQueue) pop() *timer { - length := len(tq.queue) - if length == 0 { - return nil - } - t := tq.queue[0] - tq.queue = slices.Delete(tq.queue, 0, 1) - return t -} - func (tq *timerQueue) length() int { return len(tq.queue) } diff --git a/internal/js/tc55/timers/timers_test.go b/internal/js/tc55/timers/timers_test.go index 7ff45e3f9..1ab2574aa 100644 --- a/internal/js/tc55/timers/timers_test.go +++ b/internal/js/tc55/timers/timers_test.go @@ -225,3 +225,125 @@ func TestClearFirstTimeoutWhenMultiple(t *testing.T) { require.GreaterOrEqual(t, log[0].Sub(start), time.Second) }) } + +func TestClearExpiredFirstTimerBeforeItsTaskRuns(t *testing.T) { + t.Parallel() + tests := []struct { + name string + script string + }{ + { + name: "clear timeout with clearTimeout", + script: ` + var canceledTimer = setTimeout(() => {}, 10); + sleep(20_000_000); + clearTimeout(canceledTimer); + `, + }, + { + name: "clear timeout with clearInterval", + script: ` + var canceledTimer = setTimeout(() => {}, 10); + sleep(20_000_000); + clearInterval(canceledTimer); + `, + }, + { + name: "clear interval with clearTimeout", + script: ` + var canceledTimer = setInterval(() => {}, 10); + sleep(20_000_000); + clearTimeout(canceledTimer); + `, + }, + { + name: "clear interval with clearInterval", + script: ` + var canceledTimer = setInterval(() => {}, 10); + sleep(20_000_000); + clearInterval(canceledTimer); + `, + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + t.Parallel() + + synctest.Test(t, func(t *testing.T) { + runtime := newRuntime(t) + rt := runtime.VU.Runtime() + var firedAt time.Time + + require.NoError(t, rt.Set("sleep", time.Sleep)) + require.NoError(t, rt.Set("record", func() { firedAt = time.Now() })) + + for i := range 1000 { + firedAt = time.Time{} + start := time.Now() + _, err := runtime.RunOnEventLoop("setTimeout(record, 1000);" + test.script) + require.NoErrorf(t, err, "iteration %d", i) + require.Falsef(t, firedAt.IsZero(), "iteration %d", i) + require.GreaterOrEqualf(t, firedAt.Sub(start), time.Second, "iteration %d", i) + } + }) + }) + } +} + +func TestClearExpiredOnlyTimerBeforeItsTaskRuns(t *testing.T) { + t.Parallel() + synctest.Test(t, func(t *testing.T) { + runtime := newRuntime(t) + rt := runtime.VU.Runtime() + + require.NoError(t, rt.Set("sleep", time.Sleep)) + + for i := range 1000 { + _, err := runtime.RunOnEventLoop(` + var canceledTimer = setTimeout(() => { + throw new Error("canceled timer ran"); + }, 10); + sleep(20_000_000); + clearTimeout(canceledTimer); + `) + require.NoErrorf(t, err, "iteration %d", i) + } + }) +} + +func TestClearedExpiredTimerDoesNotRunNewTimersEarly(t *testing.T) { + t.Parallel() + synctest.Test(t, func(t *testing.T) { + runtime := newRuntime(t) + rt := runtime.VU.Runtime() + type call struct { + name string + firedAt time.Time + } + var calls []call + + require.NoError(t, rt.Set("sleep", time.Sleep)) + require.NoError(t, rt.Set("record", func(name string) { + calls = append(calls, call{name: name, firedAt: time.Now()}) + })) + + for i := range 1000 { + calls = calls[:0] + start := time.Now() + _, err := runtime.RunOnEventLoop(` + var canceledTimer = setTimeout(() => record("canceled"), 10); + sleep(20_000_000); + clearTimeout(canceledTimer); + setTimeout(record, 100, "first"); + setTimeout(record, 200, "second"); + `) + require.NoErrorf(t, err, "iteration %d", i) + require.Lenf(t, calls, 2, "iteration %d", i) + require.Equalf(t, "first", calls[0].name, "iteration %d", i) + require.Equalf(t, "second", calls[1].name, "iteration %d", i) + require.GreaterOrEqualf(t, calls[0].firedAt.Sub(start), 100*time.Millisecond, "iteration %d", i) + require.GreaterOrEqualf(t, calls[1].firedAt.Sub(start), 200*time.Millisecond, "iteration %d", i) + } + }) +} From 0bd687829e1e8df8764518286d8784d521f82a92 Mon Sep 17 00:00:00 2001 From: Mihail Stoykov <312246+mstoykov@users.noreply.github.com> Date: Tue, 15 Sep 2026 12:44:16 +0300 Subject: [PATCH 152/182] ci: source Go versions from k6-ci (#6398) Resolve the current and previous Go versions from the pinned k6-ci v0.5.0 action in six CI workflows. Remove the superseded local Go-version action and environment file. Remove checkout steps that existed only to load the local action. Read the golangci-lint version after refreshing the pinned configuration. --- .github/actions/go-versions/action.yml | 22 ---------------------- .github/go-versions.env | 8 -------- .github/workflows/lint.yml | 5 +++-- .github/workflows/tc39.yml | 2 +- .github/workflows/test-browser.yml | 6 +----- .github/workflows/test.yml | 6 +----- .github/workflows/wpt.yml | 2 +- .github/workflows/xk6.yml | 2 +- Makefile | 3 +-- 9 files changed, 9 insertions(+), 47 deletions(-) delete mode 100644 .github/actions/go-versions/action.yml delete mode 100644 .github/go-versions.env diff --git a/.github/actions/go-versions/action.yml b/.github/actions/go-versions/action.yml deleted file mode 100644 index fff69d506..000000000 --- a/.github/actions/go-versions/action.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: "Go versions" -description: "Expose the central Go versions (current and N-1) from .github/go-versions.env" - -outputs: - current: - description: "Current Go version (e.g. 1.26.x)." - value: ${{ steps.read.outputs.current }} - prev: - description: "Previous (N-1) Go version (e.g. 1.25.x)." - value: ${{ steps.read.outputs.prev }} - -runs: - using: "composite" - steps: - - name: Read go-versions.env - id: read - shell: bash - run: | - set -euo pipefail - source "${GITHUB_ACTION_PATH}/../../go-versions.env" - echo "current=${GO_VERSION_CURRENT}" >> "$GITHUB_OUTPUT" - echo "prev=${GO_VERSION_PREV}" >> "$GITHUB_OUTPUT" diff --git a/.github/go-versions.env b/.github/go-versions.env deleted file mode 100644 index 53bdc990c..000000000 --- a/.github/go-versions.env +++ /dev/null @@ -1,8 +0,0 @@ -# Single source of truth for the Go versions used across the CI workflows. -# -# Both values are bumped manually with each Go release: -# GO_VERSION_CURRENT - the current Go minor version. -# GO_VERSION_PREV - the deliberate N-1 version (one minor behind CURRENT) -# kept for backwards-compatibility coverage. -GO_VERSION_CURRENT=1.26.x -GO_VERSION_PREV=1.25.x diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 49ea7b93c..7a8343d9c 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -25,11 +25,12 @@ jobs: fetch-depth: 0 - name: Resolve Go versions id: go_versions - uses: ./.github/actions/go-versions + uses: grafana/k6-ci/.github/actions/go-versions@03469f9ae7aad25369827832c456e8f8b7b8c1c2 # v0.5.0 - name: Install Go uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6 with: - go-version: ${{ steps.go_versions.outputs.current }} + # Use Go 1.26 until https://github.com/grafana/k6/issues/6399 is resolved. + go-version: ${{ steps.go_versions.outputs.prev }} check-latest: true - name: Check code generation run: | diff --git a/.github/workflows/tc39.yml b/.github/workflows/tc39.yml index 90505d7df..e488aa4a4 100644 --- a/.github/workflows/tc39.yml +++ b/.github/workflows/tc39.yml @@ -30,7 +30,7 @@ jobs: persist-credentials: false - name: Resolve Go versions id: go_versions - uses: ./.github/actions/go-versions + uses: grafana/k6-ci/.github/actions/go-versions@03469f9ae7aad25369827832c456e8f8b7b8c1c2 # v0.5.0 - name: Install Go uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6 with: diff --git a/.github/workflows/test-browser.yml b/.github/workflows/test-browser.yml index 1d5fda7ca..5176bede4 100644 --- a/.github/workflows/test-browser.yml +++ b/.github/workflows/test-browser.yml @@ -23,13 +23,9 @@ jobs: go_current: ${{ steps.go_versions.outputs.current }} go_prev: ${{ steps.go_versions.outputs.prev }} steps: - - name: Checkout code - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 - with: - persist-credentials: false - name: Resolve Go versions id: go_versions - uses: ./.github/actions/go-versions + uses: grafana/k6-ci/.github/actions/go-versions@03469f9ae7aad25369827832c456e8f8b7b8c1c2 # v0.5.0 test-prev: needs: configure diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 00030166e..41e89c9f2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,13 +23,9 @@ jobs: go_current: ${{ steps.go_versions.outputs.current }} go_prev: ${{ steps.go_versions.outputs.prev }} steps: - - name: Checkout code - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 - with: - persist-credentials: false - name: Resolve Go versions id: go_versions - uses: ./.github/actions/go-versions + uses: grafana/k6-ci/.github/actions/go-versions@03469f9ae7aad25369827832c456e8f8b7b8c1c2 # v0.5.0 test-prev: needs: configure diff --git a/.github/workflows/wpt.yml b/.github/workflows/wpt.yml index 24b357ada..67a0a4f6a 100644 --- a/.github/workflows/wpt.yml +++ b/.github/workflows/wpt.yml @@ -23,7 +23,7 @@ jobs: persist-credentials: false - name: Resolve Go versions id: go_versions - uses: ./.github/actions/go-versions + uses: grafana/k6-ci/.github/actions/go-versions@03469f9ae7aad25369827832c456e8f8b7b8c1c2 # v0.5.0 - name: Install Go uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6 with: diff --git a/.github/workflows/xk6.yml b/.github/workflows/xk6.yml index 61c9534dc..4efcd1611 100644 --- a/.github/workflows/xk6.yml +++ b/.github/workflows/xk6.yml @@ -34,7 +34,7 @@ jobs: - name: Resolve Go versions id: go_versions if: matrix.go != 'tip' - uses: ./.github/actions/go-versions + uses: grafana/k6-ci/.github/actions/go-versions@03469f9ae7aad25369827832c456e8f8b7b8c1c2 # v0.5.0 - name: Install Go if: matrix.go != 'tip' uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6 diff --git a/Makefile b/Makefile index 1bc88492d..2dd8c8f8a 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,6 @@ LINT_DIR ?= build/lint LINT_BASE := $(LINT_DIR)/.golangci-base.yml LINT_FINAL := $(LINT_DIR)/.golangci.yml LINT_PATCH ?= .golangci.patch -GOLANGCI_LINT_VERSION = $(shell head -n 1 $(LINT_BASE) 2>/dev/null | tr -d '\# ') ifeq ($(OS),Windows_NT) DETECTED_OS := Windows @@ -75,7 +74,7 @@ $(LINT_FINAL): $(LINT_BASE) $(wildcard $(LINT_PATCH)) ## lint: Run golangci-lint with the k6-ci config + $(LINT_PATCH). lint: $(LINT_FINAL) echo "Running linters..." - go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) \ + go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$$(head -n 1 $(LINT_BASE) | tr -d '# ') \ run --config=$(LINT_FINAL) ./... ## update-lint-patch: Regenerate $(LINT_PATCH) from the locally edited $(LINT_FINAL). From 0ae3c2989e5b7d24e5d18080aa72aa968ad5015f Mon Sep 17 00:00:00 2001 From: Mihail Stoykov <312246+mstoykov@users.noreply.github.com> Date: Tue, 15 Sep 2026 13:13:07 +0300 Subject: [PATCH 153/182] feat(js): propagate metric context into timer callbacks (#6342) When async-metric-context is enabled, capture the complete tags and metadata active when setTimeout or setInterval registers a callback. Apply a cloned snapshot for each invocation and restore the interrupted context afterward. Callback mutations remain visible to asynchronous work created by the callback but do not leak into its parent or later interval ticks. Repeating intervals reuse the original registration snapshot when they rearm. Timers run outside Sobek promise reactions and therefore require an explicit snapshot. Disabled runs pass callbacks through the existing path without allocating or applying metric context. Tests cover one-shot and repeating timers, complete tag and metadata restoration, callback-mutation isolation, and reusable interval snapshots. --- internal/js/tc55/timers/timers.go | 4 ++ internal/js/tc55/timers/timers_test.go | 88 ++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) diff --git a/internal/js/tc55/timers/timers.go b/internal/js/tc55/timers/timers.go index 4f5fe1175..e11b1402b 100644 --- a/internal/js/tc55/timers/timers.go +++ b/internal/js/tc55/timers/timers.go @@ -81,6 +81,7 @@ func (e *timers) call(callback sobek.Callable, args []sobek.Value) error { func (e *timers) setTimeout(callback sobek.Callable, delay float64, args ...sobek.Value) uint64 { id := e.nextID() + callback = common.CaptureMetricContext(e.vu.State()).WrapSobekCallable(callback) e.timerInitialization(callback, delay, args, false, id) return id } @@ -111,6 +112,7 @@ func (e *timers) freeEventLoopIfPossible() { func (e *timers) setInterval(callback sobek.Callable, delay float64, args ...sobek.Value) uint64 { id := e.nextID() + callback = common.CaptureMetricContext(e.vu.State()).WrapSobekCallable(callback) e.timerInitialization(callback, delay, args, true, id) return id } @@ -121,6 +123,8 @@ func (e *timers) clearInterval(id uint64) { // https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#timer-initialisation-steps // NOTE: previousId from the specification is always send and it is basically id +// +// Repeated timers must reuse the registration-time metric context when they rearm. func (e *timers) timerInitialization( callback sobek.Callable, timeout float64, args []sobek.Value, repeat bool, id uint64, ) { diff --git a/internal/js/tc55/timers/timers_test.go b/internal/js/tc55/timers/timers_test.go index 1ab2574aa..0519ea003 100644 --- a/internal/js/tc55/timers/timers_test.go +++ b/internal/js/tc55/timers/timers_test.go @@ -8,7 +8,10 @@ import ( "github.com/stretchr/testify/require" + "go.k6.io/k6/v2/internal/features" "go.k6.io/k6/v2/js/modulestest" + "go.k6.io/k6/v2/lib" + "go.k6.io/k6/v2/metrics" ) func newRuntime(t testing.TB) *modulestest.Runtime { @@ -204,6 +207,91 @@ func TestSetTimeoutContextCancel(t *testing.T) { } } +func newGroupRuntime(t testing.TB) (*modulestest.Runtime, *[]string) { + t.Helper() + runtime := modulestest.NewRuntime(t) + + registry := metrics.NewRegistry() + state := &lib.State{ + FeatureFlags: &features.Flags{AsyncMetricContext: true}, + Options: lib.Options{ + SystemTags: &metrics.DefaultSystemTagSet, + }, + Tags: lib.NewVUStateTags(registry.RootTagSet().WithTagsFromMap( + map[string]string{"group": lib.RootGroupPath})), + BuiltinMetrics: metrics.RegisterBuiltinMetrics(registry), + } + runtime.MoveToVUContext(state) + + rt := runtime.VU.Runtime() + require.NoError(t, rt.Set("setcontext", func(group, phase, trace string) { + state.Tags.Modify(func(tm *metrics.TagsAndMeta) { + tm.SetSystemTagOrMeta(metrics.TagGroup, group) + tm.SetTag("phase", phase) + tm.SetMetadata("trace", trace) + }) + })) + got := new([]string) + require.NoError(t, rt.Set("record", func() { + current := state.Tags.GetCurrentValues() + group, _ := current.Tags.Get("group") + phase, _ := current.Tags.Get("phase") + *got = append(*got, group+"|"+phase+"|"+current.Metadata["trace"]) + })) + return runtime, got +} + +func TestSetTimeoutGroupTag(t *testing.T) { + t.Parallel() + + runtime, got := newGroupRuntime(t) + + _, err := runtime.RunOnEventLoop(` + setcontext("::mygroup", "registered", "registered"); + setTimeout(() => { record(); }, 0); + setcontext("", "active", "active"); + setTimeout(() => { record(); }, 1); + record(); + `) + require.NoError(t, err) + require.Equal(t, []string{"|active|active", "::mygroup|registered|registered", "|active|active"}, *got) + current := runtime.VU.State().Tags.GetCurrentValues() + liveGroup, _ := current.Tags.Get("group") + require.Equal(t, lib.RootGroupPath, liveGroup) + phase, _ := current.Tags.Get("phase") + require.Equal(t, "active", phase) + require.Equal(t, "active", current.Metadata["trace"]) +} + +func TestSetIntervalGroupTag(t *testing.T) { + t.Parallel() + synctest.Test(t, func(t *testing.T) { + runtime, got := newGroupRuntime(t) + + _, err := runtime.RunOnEventLoop(` + var i = 0; + setcontext("::mygroup", "registered", "registered"); + let s = setInterval(() => { + record(); + setcontext("::callback", "callback", "callback"); + i++; + if (i > 2) { clearInterval(s); } + }, 1); + setcontext("", "active", "active"); + `) + require.NoError(t, err) + require.Equal(t, []string{ + "::mygroup|registered|registered", + "::mygroup|registered|registered", + "::mygroup|registered|registered", + }, *got) + current := runtime.VU.State().Tags.GetCurrentValues() + phase, _ := current.Tags.Get("phase") + require.Equal(t, "active", phase) + require.Equal(t, "active", current.Metadata["trace"]) + }) +} + func TestClearFirstTimeoutWhenMultiple(t *testing.T) { t.Parallel() synctest.Test(t, func(t *testing.T) { From 94e183b54b142f8ba33d5f6c2b245c2a0b79e04e Mon Sep 17 00:00:00 2001 From: Mihail Stoykov <312246+mstoykov@users.noreply.github.com> Date: Tue, 15 Sep 2026 13:28:29 +0300 Subject: [PATCH 154/182] chore: update expected tc39 failures after go bump (#6409) --- .../tc39/breaking_test_errors-stripTypes=false.json | 13 ------------- .../tc39/breaking_test_errors-stripTypes=true.json | 13 ------------- 2 files changed, 26 deletions(-) diff --git a/internal/js/tc39/breaking_test_errors-stripTypes=false.json b/internal/js/tc39/breaking_test_errors-stripTypes=false.json index 7348d9288..84ababf26 100644 --- a/internal/js/tc39/breaking_test_errors-stripTypes=false.json +++ b/internal/js/tc39/breaking_test_errors-stripTypes=false.json @@ -180,7 +180,6 @@ "test/built-ins/RegExp/named-groups/non-unicode-property-names-valid.js-strict:true": "test/built-ins/RegExp/named-groups/non-unicode-property-names-valid.js: SyntaxError: Invalid regular expression (regexp2): (?<\\ud835\\udc53\\ud835\\udc5c\\ud835\\udc65>fox).*(?<\\ud835\\udcd3\\ud835\\udcf8\\ud835\\udcf0>dog) (Invalid regular expression (regexp2): (?<\\ud835\\udc53\\ud835\\udc5c\\ud835\\udc65>fox).*(?<\\ud835\\udcd3\\ud835\\udcf8\\ud835\\udcf0>dog) (error parsing regexp: invalid capture group name in `(?<\\ud835\\udc53\\ud835\\udc5c\\ud835\\udc65>fox).*(?<\\ud835\\udcd3\\ud835\\udcf8\\ud835\\udcf0>dog)`)) ", "test/built-ins/RegExp/nullable-quantifier.js-strict:true": "test/built-ins/RegExp/nullable-quantifier.js: Test262Error: The regex is expected to match the whole string Expected SameValue(«\"a\"», «\"ab\"») to be true ", "test/built-ins/RegExp/quantifier-integer-limit.js-strict:true": "test/built-ins/RegExp/quantifier-integer-limit.js: SyntaxError: Invalid regular expression (regexp2): b{9007199254740991} (Invalid regular expression (regexp2): b{9007199254740991} (error parsing regexp: capture group number out of range in `b{9007199254740991}`)) ", - "test/built-ins/RegExp/unicode_full_case_folding.js-strict:true": "test/built-ins/RegExp/unicode_full_case_folding.js: Test262Error: \\u0390 does not match \\u1fd3 ", "test/built-ins/RegExp/unicode_restricted_brackets.js-strict:true": "test/built-ins/RegExp/unicode_restricted_brackets.js: Test262Error: RegExp(\"]\", \"u\"): Expected a SyntaxError to be thrown but no exception was thrown at all ", "test/built-ins/RegExp/unicode_restricted_character_class_escape.js-strict:true": "test/built-ins/RegExp/unicode_restricted_character_class_escape.js: Test262Error: RegExp(\"[\\d-a]\", \"u\"): Expected a SyntaxError to be thrown but no exception was thrown at all ", "test/built-ins/RegExp/unicode_restricted_identity_escape.js-strict:true": "test/built-ins/RegExp/unicode_restricted_identity_escape.js: Test262Error: Invalid IdentityEscape in AtomEscape: '\\\u0000' Expected a SyntaxError to be thrown but no exception was thrown at all ", @@ -222,18 +221,6 @@ "test/language/expressions/import.meta/syntax/goal-module.js-strict:true": "test/language/expressions/import.meta/syntax/goal-module.js: file:///TestTC39/test262/test/language/expressions/import.meta/syntax/goal-module.js: Line 15:1 import not supported in script (and 3 more errors)", "test/language/expressions/optional-chaining/iteration-statement-for-await-of.js-strict:true": "test/language/expressions/optional-chaining/iteration-statement-for-await-of.js: test/language/expressions/optional-chaining/iteration-statement-for-await-of.js: Line 32:7 Unexpected token await (and 9 more errors)", "test/language/expressions/optional-chaining/member-expression.js-strict:true": "test/language/expressions/optional-chaining/member-expression.js: SyntaxError: Async generators are not supported yet ", - "test/language/identifiers/part-unicode-15.1.0-class-escaped.js-strict:true": "test/language/identifiers/part-unicode-15.1.0-class-escaped.js: test/language/identifiers/part-unicode-15.1.0-class-escaped.js: Line 20:22 Unexpected token ILLEGAL (and 1 more errors)", - "test/language/identifiers/part-unicode-15.1.0-class.js-strict:true": "test/language/identifiers/part-unicode-15.1.0-class.js: test/language/identifiers/part-unicode-15.1.0-class.js: Line 17:11 Unexpected token ILLEGAL (and 4 more errors)", - "test/language/identifiers/part-unicode-15.1.0-escaped.js-strict:true": "test/language/identifiers/part-unicode-15.1.0-escaped.js: test/language/identifiers/part-unicode-15.1.0-escaped.js: Line 17:5 Unexpected token ILLEGAL (and 1 more errors)", - "test/language/identifiers/part-unicode-15.1.0.js-strict:true": "test/language/identifiers/part-unicode-15.1.0.js: test/language/identifiers/part-unicode-15.1.0.js: Line 15:12 Unexpected token ILLEGAL (and 3 more errors)", - "test/language/identifiers/part-unicode-16.0.0-class-escaped.js-strict:true": "test/language/identifiers/part-unicode-16.0.0-class-escaped.js: test/language/identifiers/part-unicode-16.0.0-class-escaped.js: Line 20:10 Unexpected token ILLEGAL (and 3 more errors)", - "test/language/identifiers/part-unicode-16.0.0-class.js-strict:true": "test/language/identifiers/part-unicode-16.0.0-class.js: test/language/identifiers/part-unicode-16.0.0-class.js: Line 17:5 Unexpected token ILLEGAL (and 133 more errors)", - "test/language/identifiers/part-unicode-16.0.0-escaped.js-strict:true": "test/language/identifiers/part-unicode-16.0.0-escaped.js: test/language/identifiers/part-unicode-16.0.0-escaped.js: Line 17:5 Unexpected token ILLEGAL (and 1 more errors)", - "test/language/identifiers/part-unicode-16.0.0.js-strict:true": "test/language/identifiers/part-unicode-16.0.0.js: test/language/identifiers/part-unicode-16.0.0.js: Line 15:6 Unexpected token ILLEGAL (and 132 more errors)", - "test/language/identifiers/part-unicode-17.0.0-class-escaped.js-strict:true": "test/language/identifiers/part-unicode-17.0.0-class-escaped.js: test/language/identifiers/part-unicode-17.0.0-class-escaped.js: Line 20:10 Unexpected token ILLEGAL (and 48 more errors)", - "test/language/identifiers/part-unicode-17.0.0-class.js-strict:true": "test/language/identifiers/part-unicode-17.0.0-class.js: test/language/identifiers/part-unicode-17.0.0-class.js: Line 17:5 Unexpected token ILLEGAL (and 54 more errors)", - "test/language/identifiers/part-unicode-17.0.0-escaped.js-strict:true": "test/language/identifiers/part-unicode-17.0.0-escaped.js: test/language/identifiers/part-unicode-17.0.0-escaped.js: Line 17:5 Unexpected token ILLEGAL (and 1 more errors)", - "test/language/identifiers/part-unicode-17.0.0.js-strict:true": "test/language/identifiers/part-unicode-17.0.0.js: test/language/identifiers/part-unicode-17.0.0.js: Line 15:6 Unexpected token ILLEGAL (and 53 more errors)", "test/language/import/import-defer/deferred-namespace-object/exotic-object-behavior.js-strict:true": "test/language/import/import-defer/deferred-namespace-object/exotic-object-behavior.js: file:///TestTC39/test262/test/language/import/import-defer/deferred-namespace-object/exotic-object-behavior.js: Line 27:14 Unexpected token *", "test/language/import/import-defer/deferred-namespace-object/identity.js-strict:true": "test/language/import/import-defer/deferred-namespace-object/identity.js: file:///TestTC39/test262/test/language/import/import-defer/deferred-namespace-object/identity.js: Line 36:14 Unexpected token *", "test/language/import/import-defer/deferred-namespace-object/to-string-tag.js-strict:true": "test/language/import/import-defer/deferred-namespace-object/to-string-tag.js: file:///TestTC39/test262/test/language/import/import-defer/deferred-namespace-object/to-string-tag.js: Line 29:14 Unexpected token *", diff --git a/internal/js/tc39/breaking_test_errors-stripTypes=true.json b/internal/js/tc39/breaking_test_errors-stripTypes=true.json index d521509d4..63f1d1d7b 100644 --- a/internal/js/tc39/breaking_test_errors-stripTypes=true.json +++ b/internal/js/tc39/breaking_test_errors-stripTypes=true.json @@ -180,7 +180,6 @@ "test/built-ins/RegExp/named-groups/non-unicode-property-names-valid.js-strict:true": "test/built-ins/RegExp/named-groups/non-unicode-property-names-valid.js: SyntaxError: Invalid regular expression (regexp2): (?<\\ud835\\udc53\\ud835\\udc5c\\ud835\\udc65>fox).*(?<\\ud835\\udcd3\\ud835\\udcf8\\ud835\\udcf0>dog) (Invalid regular expression (regexp2): (?<\\ud835\\udc53\\ud835\\udc5c\\ud835\\udc65>fox).*(?<\\ud835\\udcd3\\ud835\\udcf8\\ud835\\udcf0>dog) (error parsing regexp: invalid capture group name in `(?<\\ud835\\udc53\\ud835\\udc5c\\ud835\\udc65>fox).*(?<\\ud835\\udcd3\\ud835\\udcf8\\ud835\\udcf0>dog)`)) ", "test/built-ins/RegExp/nullable-quantifier.js-strict:true": "test/built-ins/RegExp/nullable-quantifier.js: Test262Error: The regex is expected to match the whole string Expected SameValue(«\"a\"», «\"ab\"») to be true ", "test/built-ins/RegExp/quantifier-integer-limit.js-strict:true": "test/built-ins/RegExp/quantifier-integer-limit.js: SyntaxError: Invalid regular expression (regexp2): b{9007199254740991} (Invalid regular expression (regexp2): b{9007199254740991} (error parsing regexp: capture group number out of range in `b{9007199254740991}`)) ", - "test/built-ins/RegExp/unicode_full_case_folding.js-strict:true": "test/built-ins/RegExp/unicode_full_case_folding.js: Test262Error: \\u0390 does not match \\u1fd3 ", "test/built-ins/RegExp/unicode_restricted_brackets.js-strict:true": "test/built-ins/RegExp/unicode_restricted_brackets.js: Test262Error: RegExp(\"]\", \"u\"): Expected a SyntaxError to be thrown but no exception was thrown at all ", "test/built-ins/RegExp/unicode_restricted_character_class_escape.js-strict:true": "test/built-ins/RegExp/unicode_restricted_character_class_escape.js: Test262Error: RegExp(\"[\\d-a]\", \"u\"): Expected a SyntaxError to be thrown but no exception was thrown at all ", "test/built-ins/RegExp/unicode_restricted_identity_escape.js-strict:true": "test/built-ins/RegExp/unicode_restricted_identity_escape.js: Test262Error: Invalid IdentityEscape in AtomEscape: '\\\u0000' Expected a SyntaxError to be thrown but no exception was thrown at all ", @@ -222,18 +221,6 @@ "test/language/expressions/import.meta/syntax/goal-module.js-strict:true": "test/language/expressions/import.meta/syntax/goal-module.js: file:///TestTC39/test262/test/language/expressions/import.meta/syntax/goal-module.js: Line 15:1 import not supported in script (and 3 more errors)", "test/language/expressions/optional-chaining/iteration-statement-for-await-of.js-strict:true": "test/language/expressions/optional-chaining/iteration-statement-for-await-of.js: test/language/expressions/optional-chaining/iteration-statement-for-await-of.js: Line 32:7 Unexpected token await (and 9 more errors)", "test/language/expressions/optional-chaining/member-expression.js-strict:true": "test/language/expressions/optional-chaining/member-expression.js: SyntaxError: Async generators are not supported yet ", - "test/language/identifiers/part-unicode-15.1.0-class-escaped.js-strict:true": "test/language/identifiers/part-unicode-15.1.0-class-escaped.js: test/language/identifiers/part-unicode-15.1.0-class-escaped.js: Line 20:22 Unexpected token ILLEGAL (and 1 more errors)", - "test/language/identifiers/part-unicode-15.1.0-class.js-strict:true": "test/language/identifiers/part-unicode-15.1.0-class.js: test/language/identifiers/part-unicode-15.1.0-class.js: Line 17:11 Unexpected token ILLEGAL (and 4 more errors)", - "test/language/identifiers/part-unicode-15.1.0-escaped.js-strict:true": "test/language/identifiers/part-unicode-15.1.0-escaped.js: test/language/identifiers/part-unicode-15.1.0-escaped.js: Line 17:5 Unexpected token ILLEGAL (and 1 more errors)", - "test/language/identifiers/part-unicode-15.1.0.js-strict:true": "test/language/identifiers/part-unicode-15.1.0.js: test/language/identifiers/part-unicode-15.1.0.js: Line 15:12 Unexpected token ILLEGAL (and 3 more errors)", - "test/language/identifiers/part-unicode-16.0.0-class-escaped.js-strict:true": "test/language/identifiers/part-unicode-16.0.0-class-escaped.js: test/language/identifiers/part-unicode-16.0.0-class-escaped.js: Line 20:10 Unexpected token ILLEGAL (and 3 more errors)", - "test/language/identifiers/part-unicode-16.0.0-class.js-strict:true": "test/language/identifiers/part-unicode-16.0.0-class.js: test/language/identifiers/part-unicode-16.0.0-class.js: Line 17:5 Unexpected token ILLEGAL (and 133 more errors)", - "test/language/identifiers/part-unicode-16.0.0-escaped.js-strict:true": "test/language/identifiers/part-unicode-16.0.0-escaped.js: test/language/identifiers/part-unicode-16.0.0-escaped.js: Line 17:5 Unexpected token ILLEGAL (and 1 more errors)", - "test/language/identifiers/part-unicode-16.0.0.js-strict:true": "test/language/identifiers/part-unicode-16.0.0.js: test/language/identifiers/part-unicode-16.0.0.js: Line 15:6 Unexpected token ILLEGAL (and 132 more errors)", - "test/language/identifiers/part-unicode-17.0.0-class-escaped.js-strict:true": "test/language/identifiers/part-unicode-17.0.0-class-escaped.js: test/language/identifiers/part-unicode-17.0.0-class-escaped.js: Line 20:10 Unexpected token ILLEGAL (and 48 more errors)", - "test/language/identifiers/part-unicode-17.0.0-class.js-strict:true": "test/language/identifiers/part-unicode-17.0.0-class.js: test/language/identifiers/part-unicode-17.0.0-class.js: Line 17:5 Unexpected token ILLEGAL (and 54 more errors)", - "test/language/identifiers/part-unicode-17.0.0-escaped.js-strict:true": "test/language/identifiers/part-unicode-17.0.0-escaped.js: test/language/identifiers/part-unicode-17.0.0-escaped.js: Line 17:5 Unexpected token ILLEGAL (and 1 more errors)", - "test/language/identifiers/part-unicode-17.0.0.js-strict:true": "test/language/identifiers/part-unicode-17.0.0.js: test/language/identifiers/part-unicode-17.0.0.js: Line 15:6 Unexpected token ILLEGAL (and 53 more errors)", "test/language/import/import-defer/deferred-namespace-object/exotic-object-behavior.js-strict:true": "test/language/import/import-defer/deferred-namespace-object/exotic-object-behavior.js: file:///TestTC39/test262/test/language/import/import-defer/deferred-namespace-object/exotic-object-behavior.js: Line 27:14 Unexpected token *", "test/language/import/import-defer/deferred-namespace-object/identity.js-strict:true": "test/language/import/import-defer/deferred-namespace-object/identity.js: file:///TestTC39/test262/test/language/import/import-defer/deferred-namespace-object/identity.js: Line 36:14 Unexpected token *", "test/language/import/import-defer/deferred-namespace-object/to-string-tag.js-strict:true": "test/language/import/import-defer/deferred-namespace-object/to-string-tag.js: file:///TestTC39/test262/test/language/import/import-defer/deferred-namespace-object/to-string-tag.js: Line 29:14 Unexpected token *", From c4c0fe90e56f0ef199fa8dbee09975b252b3a00e Mon Sep 17 00:00:00 2001 From: Mihail Stoykov <312246+mstoykov@users.noreply.github.com> Date: Tue, 15 Sep 2026 13:38:32 +0300 Subject: [PATCH 155/182] feat(js): propagate metric context into WebSocket listeners (#6343) When async-metric-context is enabled, capture the complete tags and metadata active when a k6/websockets listener is registered. Apply the same behavior to on-event properties and addEventListener, then restore the interrupted context after every callback. WebSocket events enter JavaScript through the event loop rather than Sobek promise reactions, so listener registration needs an explicit context snapshot. Mutations are isolated to the callback and asynchronous work it creates. Disabled runs retain the direct listener path without a wrapper. Enabled registrations capture one context and create one wrapper; each delivery clones metadata while applying and restoring that context. The CLI integration test activates the feature and verifies group and custom-tag snapshots for open, message, and root-registered close listeners. --- .../cmd_run_async_group_websockets_test.go | 60 +++++++++++++++++++ .../js/modules/k6/websockets/websockets.go | 20 ++++++- 2 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 internal/cmd/tests/cmd_run_async_group_websockets_test.go diff --git a/internal/cmd/tests/cmd_run_async_group_websockets_test.go b/internal/cmd/tests/cmd_run_async_group_websockets_test.go new file mode 100644 index 000000000..fe773b223 --- /dev/null +++ b/internal/cmd/tests/cmd_run_async_group_websockets_test.go @@ -0,0 +1,60 @@ +package tests + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "go.k6.io/k6/v2/internal/cmd" + "go.k6.io/k6/v2/internal/lib/testutils/httpmultibin" + "go.k6.io/k6/v2/lib/fsext" +) + +func TestRunAsyncGroupWebSocketListeners(t *testing.T) { + t.Parallel() + + tb := httpmultibin.NewHTTPMultiBin(t) + script := tb.Replacer.Replace(` + import { check, group } from 'k6'; + import exec from 'k6/execution'; + import { WebSocket } from 'k6/websockets'; + + export const options = { + hosts: { 'HTTPBIN_DOMAIN': 'HTTPBIN_IP' }, + }; + + export default function () { + exec.vu.metrics.tags.owner = 'registered'; + const ws = new WebSocket('WSBIN_URL/ws-echo'); + group('wsgroup', () => { + ws.onopen = () => { + check(null, { open: true }); + exec.vu.metrics.tags.callback = 'open'; + ws.send('something'); + }; + ws.addEventListener('message', () => { + check(null, { message: true }); + ws.close(); + }); + }); + exec.vu.metrics.tags.owner = 'active'; + ws.onclose = () => check(null, { close: true }); + } + `) + + ts := getSingleFileTestState(t, script, + []string{"--features", "async-metric-context", "--out", "json=results.json", "--summary-mode=disabled"}, 0) + cmd.ExecuteWithGlobalState(ts.GlobalState) + + results, err := fsext.ReadFile(ts.FS, "results.json") + require.NoError(t, err) + for _, check := range []string{"open", "message"} { + assert.Equal(t, []float64{1}, getSampleValues(t, results, "checks", map[string]string{ + "check": check, "group": "::wsgroup", "owner": "registered", + })) + } + assert.Equal(t, []float64{1}, getSampleValues(t, results, "checks", map[string]string{ + "check": "close", "group": "", "owner": "active", + })) +} diff --git a/internal/js/modules/k6/websockets/websockets.go b/internal/js/modules/k6/websockets/websockets.go index 4072adc06..90529fc9f 100644 --- a/internal/js/modules/k6/websockets/websockets.go +++ b/internal/js/modules/k6/websockets/websockets.go @@ -263,7 +263,8 @@ func defineWebsocket(rt *sobek.Runtime, w *webSocket) { common.Throw(rt, fmt.Errorf("a value for '%s' should be callable", property)) } - el.setOn(func(v sobek.Value) (sobek.Value, error) { return fn(sobek.Undefined(), v) }) + el.setOn(w.wrapUnderCurrentMetricContext( + func(v sobek.Value) (sobek.Value, error) { return fn(sobek.Undefined(), v) })) return nil }), sobek.FLAG_FALSE, sobek.FLAG_TRUE)) @@ -1043,9 +1044,24 @@ func (w *webSocket) addEventListener(event string, handler func(sobek.Value) (so common.Throw(w.vu.Runtime(), fmt.Errorf("handler for event type %q isn't a callable function", event)) } - if err := w.eventListeners.add(event, handler); err != nil { + if err := w.eventListeners.add(event, w.wrapUnderCurrentMetricContext(handler)); err != nil { w.vu.State().Logger.Warnf("can't add event handler: %s", err) } } +// WebSocket listeners run outside Sobek's promise machinery. +func (w *webSocket) wrapUnderCurrentMetricContext( + fn func(sobek.Value) (sobek.Value, error), +) func(sobek.Value) (sobek.Value, error) { + if !common.AsyncMetricContextEnabled(w.vu.State()) { + return fn + } + captured := common.CaptureMetricContext(w.vu.State()) + return func(v sobek.Value) (sobek.Value, error) { + return common.RunWithMetricContext(captured, func() (sobek.Value, error) { + return fn(v) + }) + } +} + // TODO add remove listeners From 08c6e1b0ed0f0ff48a16cbb767ac090805a060dd Mon Sep 17 00:00:00 2001 From: Mihail Stoykov <312246+mstoykov@users.noreply.github.com> Date: Tue, 15 Sep 2026 14:39:06 +0300 Subject: [PATCH 156/182] feat(js): propagate metric context into gRPC stream listeners (#6344) When async-metric-context is enabled, capture the complete tags and metadata active when a gRPC stream listener is registered. Apply that context while handling data, end, error, and other stream events, then restore the interrupted context after the listener returns or throws. Stream events enter JavaScript through task-queue callbacks rather than Sobek promise reactions, so they require an explicit registration-time snapshot. Callback mutations remain local to that callback and its async descendants. Disabled runs retain the direct listener path without a wrapper. The module-specific CLI test verifies group and custom-tag snapshots for data and root-registered end listeners. Cross-module integration coverage overlaps promise reactions, HTTP, timers, WebSocket listeners, and gRPC stream listeners. It mutates tags and metadata across multiple await boundaries and verifies callback, protocol metric, group_duration, and parent-context attribution. --- ...run_async_group_concurrent_modules_test.go | 234 ++++++++++++++++++ .../tests/cmd_run_async_group_grpc_test.go | 66 +++++ internal/cmd/tests/grpc.go | 8 +- internal/js/modules/k6/grpc/stream.go | 17 +- 4 files changed, 322 insertions(+), 3 deletions(-) create mode 100644 internal/cmd/tests/cmd_run_async_group_concurrent_modules_test.go create mode 100644 internal/cmd/tests/cmd_run_async_group_grpc_test.go diff --git a/internal/cmd/tests/cmd_run_async_group_concurrent_modules_test.go b/internal/cmd/tests/cmd_run_async_group_concurrent_modules_test.go new file mode 100644 index 000000000..ff43d84a5 --- /dev/null +++ b/internal/cmd/tests/cmd_run_async_group_concurrent_modules_test.go @@ -0,0 +1,234 @@ +package tests + +import ( + "os" + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "go.k6.io/k6/v2/internal/cmd" + "go.k6.io/k6/v2/internal/lib/testutils/httpmultibin" + "go.k6.io/k6/v2/lib/fsext" +) + +func TestRunConcurrentAsyncGroupsAcrossModules(t *testing.T) { + t.Parallel() + + httpBin := httpmultibin.NewHTTPMultiBin(t) + grpcBin := NewGRPC(t) + script := httpBin.Replacer.Replace(grpcBin.Replacer.Replace(` + import { check, group } from 'k6'; + import exec from 'k6/execution'; + import http from 'k6/http'; + import { Client, Stream } from 'k6/net/grpc'; + import { WebSocket } from 'k6/websockets'; + + export const options = { + hosts: { 'HTTPBIN_DOMAIN': 'HTTPBIN_IP' }, + }; + + const client = new Client(); + client.load([], './route_guide.proto'); + const delay = ms => new Promise(resolve => setTimeout(resolve, ms)); + const phases = ['first', 'second', 'third']; + const changeContext = (name, phase) => { + const value = name + ':' + phase; + exec.vu.metrics.tags.phase = value; + exec.vu.metrics.metadata.step = value; + }; + const crossBoundary = phase => phase === 'second' ? delay(0) : Promise.resolve(); + const recordContext = (name, phase) => check(null, {[name + ':' + phase]: true}); + + export default async function () { + client.connect('GRPCBIN_ADDR', { plaintext: true }); + exec.vu.metrics.tags.owner = 'root'; + exec.vu.metrics.tags.phase = 'root'; + exec.vu.metrics.metadata.trace = 'root'; + exec.vu.metrics.metadata.step = 'root'; + + let release; + const gate = new Promise(resolve => { release = resolve; }); + let started = 0; + const start = (name, operation) => { + exec.vu.metrics.tags.owner = name; + exec.vu.metrics.metadata.trace = name; + const pending = group(name, () => { + started++; + check(null, {[name + ':start']: true}); + return operation(); + }); + exec.vu.metrics.tags.owner = 'root'; + exec.vu.metrics.metadata.trace = 'root'; + return pending; + }; + + const pending = [ + start('http', async () => { + await gate; + for (const phase of phases) { + changeContext('http', phase); + await crossBoundary(phase); + recordContext('http', phase); + } + const response = await http.asyncRequest('GET', 'HTTPBIN_URL/get'); + check(response, {'http:finish': value => value.status === 200}); + }), + start('websocket', () => new Promise((resolve, reject) => { + const ws = new WebSocket('WSBIN_URL/ws-echo'); + ws.addEventListener('open', () => ws.send('hello')); + ws.addEventListener('message', async event => { + try { + check(event, {'websocket:message': value => value.data === 'hello'}); + for (const phase of phases) { + changeContext('websocket', phase); + await crossBoundary(phase); + recordContext('websocket', phase); + } + ws.close(); + } catch (error) { + reject(error); + } + }); + ws.addEventListener('close', () => { + check(null, {'websocket:finish': true}); + resolve(); + }); + ws.addEventListener('error', () => reject(new Error('WebSocket failed'))); + })), + start('grpc', () => new Promise((resolve, reject) => { + const stream = new Stream(client, 'main.FeatureExplorer/ListFeatures'); + let handlingData = false; + let dataHandled = false; + let streamEnded = false; + const finish = () => { + if (dataHandled && streamEnded) resolve(); + }; + stream.on('data', async data => { + if (handlingData) return; + handlingData = true; + try { + check(data, {'grpc:data': value => value.name !== ''}); + for (const phase of phases) { + changeContext('grpc', phase); + await crossBoundary(phase); + recordContext('grpc', phase); + } + dataHandled = true; + finish(); + } catch (error) { + reject(error); + } + }); + stream.on('end', () => { + check(null, {'grpc:finish': true}); + streamEnded = true; + finish(); + }); + stream.on('error', reject); + stream.write({ + lo: { latitude: 407838351, longitude: -746143763 }, + hi: { latitude: 407838351, longitude: -746143763 }, + }); + stream.end(); + })), + start('timer', () => new Promise((resolve, reject) => { + setTimeout(async () => { + try { + for (const phase of phases) { + changeContext('timer', phase); + await crossBoundary(phase); + recordContext('timer', phase); + } + check(null, {'timer:finish': true}); + resolve(); + } catch (error) { + reject(error); + } + }, 1); + })), + start('promise', () => gate.then(async () => { + for (const phase of phases) { + changeContext('promise', phase); + await crossBoundary(phase); + recordContext('promise', phase); + } + check(null, {'promise:finish': true}); + })), + ]; + + // The event loop cannot run any protocol or timer callback before this point. + check(null, {'all-started': () => started === pending.length}); + release(); + await Promise.all(pending); + check(null, {'outside:finish': true}); + client.close(); + } + `)) + + ts := getSingleFileTestState(t, script, + []string{"--features", "async-metric-context", "--out", "json=results.json", "--summary-mode=disabled"}, 0) + proto, err := os.ReadFile(projectRootPath + "internal/lib/testutils/grpcservice/route_guide.proto") //nolint:forbidigo + require.NoError(t, err) + require.NoError(t, fsext.WriteFile(ts.FS, filepath.Join(ts.Cwd, "route_guide.proto"), proto, 0o644)) + cmd.ExecuteWithGlobalState(ts.GlobalState) + + results, err := fsext.ReadFile(ts.FS, "results.json") + require.NoError(t, err) + for _, name := range []string{"http", "websocket", "grpc", "timer", "promise"} { + assert.Equal(t, []float64{1}, getSampleValuesWithMetadata(t, results, "checks", map[string]string{ + "check": name + ":start", "group": "::" + name, "owner": name, + }, map[string]string{"trace": name})) + assert.Len(t, getSampleValuesWithMetadata(t, results, "group_duration", map[string]string{ + "group": "::" + name, "owner": name, "phase": "root", + }, map[string]string{"trace": name, "step": "root"}), 1) + for _, phase := range []string{"first", "second", "third"} { + value := name + ":" + phase + assert.Equal(t, []float64{1}, getSampleValuesWithMetadata(t, results, "checks", map[string]string{ + "check": value, "group": "::" + name, "owner": name, "phase": value, + }, map[string]string{"trace": name, "step": value})) + } + } + + for _, expected := range []struct { + check string + group string + phase string + }{ + {"http:finish", "http", "http:third"}, + {"websocket:message", "websocket", "root"}, + {"websocket:finish", "websocket", "root"}, + {"grpc:finish", "grpc", "root"}, + {"timer:finish", "timer", "timer:third"}, + {"promise:finish", "promise", "promise:third"}, + } { + assert.Equal(t, []float64{1}, getSampleValuesWithMetadata(t, results, "checks", map[string]string{ + "check": expected.check, "group": "::" + expected.group, "owner": expected.group, + "phase": expected.phase, + }, map[string]string{"trace": expected.group, "step": expected.phase})) + } + assert.NotEmpty(t, getSampleValuesWithMetadata(t, results, "checks", map[string]string{ + "check": "grpc:data", "group": "::grpc", "owner": "grpc", "phase": "root", + }, map[string]string{"trace": "grpc", "step": "root"})) + + for _, expected := range []struct { + metric string + group string + phase string + }{ + {"http_reqs", "http", "http:third"}, + {"ws_msgs_received", "websocket", "root"}, + {"grpc_streams_msgs_received", "grpc", "root"}, + } { + assert.NotEmpty(t, getSampleValuesWithMetadata(t, results, expected.metric, map[string]string{ + "group": "::" + expected.group, "owner": expected.group, "phase": expected.phase, + }, map[string]string{"trace": expected.group, "step": expected.phase})) + } + assert.Equal(t, []float64{1}, getSampleValuesWithMetadata(t, results, "checks", map[string]string{ + "check": "all-started", "group": "", "owner": "root", "phase": "root", + }, map[string]string{"trace": "root", "step": "root"})) + assert.Equal(t, []float64{1}, getSampleValuesWithMetadata(t, results, "checks", map[string]string{ + "check": "outside:finish", "group": "", "owner": "root", "phase": "root", + }, map[string]string{"trace": "root", "step": "root"})) +} diff --git a/internal/cmd/tests/cmd_run_async_group_grpc_test.go b/internal/cmd/tests/cmd_run_async_group_grpc_test.go new file mode 100644 index 000000000..73767e2b1 --- /dev/null +++ b/internal/cmd/tests/cmd_run_async_group_grpc_test.go @@ -0,0 +1,66 @@ +package tests + +import ( + "os" + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "go.k6.io/k6/v2/internal/cmd" + "go.k6.io/k6/v2/lib/fsext" +) + +func TestRunAsyncGroupGRPCStreamListeners(t *testing.T) { + t.Parallel() + + tb := NewGRPC(t) + script := tb.Replacer.Replace(` + import { check, group } from 'k6'; + import exec from 'k6/execution'; + import { Client, Stream } from 'k6/net/grpc'; + + const client = new Client(); + client.load([], './route_guide.proto'); + + export default async function () { + client.connect('GRPCBIN_ADDR', { plaintext: true }); + const stream = new Stream(client, 'main.FeatureExplorer/ListFeatures'); + await new Promise((resolve, reject) => { + exec.vu.metrics.tags.owner = 'registered'; + group('grpcgroup', () => { + stream.on('data', data => check(data, { data: value => value.name !== '' })); + }); + exec.vu.metrics.tags.owner = 'active'; + stream.on('end', () => { + check(null, { end: true }); + client.close(); + resolve(); + }); + stream.on('error', reject); + stream.write({ + lo: { latitude: 407838351, longitude: -746143763 }, + hi: { latitude: 407838351, longitude: -746143763 }, + }); + stream.end(); + }); + } + `) + + ts := getSingleFileTestState(t, script, + []string{"--features", "async-metric-context", "--out", "json=results.json", "--summary-mode=disabled"}, 0) + proto, err := os.ReadFile(projectRootPath + "internal/lib/testutils/grpcservice/route_guide.proto") //nolint:forbidigo + require.NoError(t, err) + require.NoError(t, fsext.WriteFile(ts.FS, filepath.Join(ts.Cwd, "route_guide.proto"), proto, 0o644)) + cmd.ExecuteWithGlobalState(ts.GlobalState) + + results, err := fsext.ReadFile(ts.FS, "results.json") + require.NoError(t, err) + assert.NotEmpty(t, getSampleValues(t, results, "checks", map[string]string{ + "check": "data", "group": "::grpcgroup", "owner": "registered", + })) + assert.Equal(t, []float64{1}, getSampleValues(t, results, "checks", map[string]string{ + "check": "end", "group": "", "owner": "active", + })) +} diff --git a/internal/cmd/tests/grpc.go b/internal/cmd/tests/grpc.go index e6bdb919f..025fa172c 100644 --- a/internal/cmd/tests/grpc.go +++ b/internal/cmd/tests/grpc.go @@ -30,8 +30,12 @@ func NewGRPC(t testing.TB) *GRPC { } features := grpcservice.LoadFeatures("") - grpcservice.RegisterRouteGuideServer(grpcServer, grpcservice.NewRouteGuideServer(features...)) - grpcservice.RegisterFeatureExplorerServer(grpcServer, grpcservice.NewFeatureExplorerServer(features...)) + routeGuide := grpcservice.NewRouteGuideServer(features...) + routeGuide.Logf = t.Logf + grpcservice.RegisterRouteGuideServer(grpcServer, routeGuide) + featureExplorer := grpcservice.NewFeatureExplorerServer(features...) + featureExplorer.Logf = t.Logf + grpcservice.RegisterFeatureExplorerServer(grpcServer, featureExplorer) reflection.Register(grpcServer) go func() { diff --git a/internal/js/modules/k6/grpc/stream.go b/internal/js/modules/k6/grpc/stream.go index 9942e7854..afbb70169 100644 --- a/internal/js/modules/k6/grpc/stream.go +++ b/internal/js/modules/k6/grpc/stream.go @@ -308,11 +308,26 @@ func (s *stream) on(event string, handler func(sobek.Value, sobek.Value) (sobek. common.Throw(s.vu.Runtime(), fmt.Errorf("handler for %q event isn't a callable function", event)) } - if err := s.eventListeners.add(event, handler); err != nil { + if err := s.eventListeners.add(event, s.wrapUnderCurrentMetricContext(handler)); err != nil { s.vu.State().Logger.Warnf("can't register %s event handler: %s", event, err) } } +// Stream listeners run outside Sobek's promise machinery. +func (s *stream) wrapUnderCurrentMetricContext( + fn func(sobek.Value, sobek.Value) (sobek.Value, error), +) func(sobek.Value, sobek.Value) (sobek.Value, error) { + if !common.AsyncMetricContextEnabled(s.vu.State()) { + return fn + } + captured := common.CaptureMetricContext(s.vu.State()) + return func(v, metadata sobek.Value) (sobek.Value, error) { + return common.RunWithMetricContext(captured, func() (sobek.Value, error) { + return fn(v, metadata) + }) + } +} + // write writes a message to the stream func (s *stream) write(input sobek.Value) { if s.writingState != opened { From f4982c7e27533f72bd872b107cdf4ad3ad20c6e0 Mon Sep 17 00:00:00 2001 From: Yatharth Katta Date: Wed, 16 Sep 2026 04:55:44 +0530 Subject: [PATCH 157/182] Fix missing space in --no-usage-report help text (#6402) --- internal/cmd/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/cmd/config.go b/internal/cmd/config.go index 5cd5db4f7..480c4708b 100644 --- a/internal/cmd/config.go +++ b/internal/cmd/config.go @@ -35,7 +35,7 @@ func configFlagSet() *pflag.FlagSet { flags.Bool( "no-usage-report", false, - "don't send anonymous usage"+"stats (https://grafana.com/docs/k6/latest/set-up/usage-collection/)", + "don't send anonymous usage stats (https://grafana.com/docs/k6/latest/set-up/usage-collection/)", ) flags.StringArray("features", nil, "enable feature flags (comma-separated)") return flags From 01d3c934edffb931ac9898fd6d8d16721c49eac8 Mon Sep 17 00:00:00 2001 From: John Pei <90728829+JohnPei1@users.noreply.github.com> Date: Wed, 16 Sep 2026 17:49:46 -0400 Subject: [PATCH 158/182] Fix dispose and getContext data race (#6327) * Fix dispose and getContext data race. Closes #5328 * Expand contextMu coverage to all b.context accesses * Cover public context getter in regression test and add result assertions * update stale comment --- .../js/modules/k6/browser/common/browser.go | 21 +++---- .../modules/k6/browser/common/browser_test.go | 57 +++++++++++++++++++ 2 files changed, 66 insertions(+), 12 deletions(-) diff --git a/internal/js/modules/k6/browser/common/browser.go b/internal/js/modules/k6/browser/common/browser.go index b513ccd7a..46adcd256 100644 --- a/internal/js/modules/k6/browser/common/browser.go +++ b/internal/js/modules/k6/browser/common/browser.go @@ -43,15 +43,7 @@ type Browser struct { // A *Connection is saved to this field, see: connect(). conn connection - // This mutex is only needed in an edge case where we have multiple - // instances of k6 connecting to the same chrome instance. In this - // case when a page is created by the first k6 instance, the second - // instance of k6 will also receive an onAttachedToTarget event. When - // this occurs there's a small chance that at the same time a new - // context is being created by the second k6 instance. So the read - // occurs in getDefaultBrowserContextOrMatchedID which is called by - // onAttachedToTarget, and the write in NewContext. This mutex protects - // the read/write race condition for this one case. + // contextMu protects concurrent access to the browser contexts. contextMu sync.RWMutex context *BrowserContext defaultContext *BrowserContext @@ -181,7 +173,9 @@ func (b *Browser) disposeContext(id cdp.BrowserContextID) error { if err := action.Do(cdp.WithExecutor(b.vuCtx, b.conn)); err != nil { return fmt.Errorf("disposing browser context ID %s: %w", id, err) } + b.contextMu.Lock() b.context = nil + b.contextMu.Unlock() return nil } @@ -688,14 +682,17 @@ func (b *Browser) waitForPagesToDetach(timeout time.Duration) { // CloseContext is a short-cut function to close the current browser's context. // If there is no active browser context, it returns an error. func (b *Browser) CloseContext() error { - if b.context == nil { + context := b.Context() + if context == nil { return errors.New("cannot close context as none is active in browser") } - return b.context.Close() + return context.Close() } // Context returns the current browser context or nil. func (b *Browser) Context() *BrowserContext { + b.contextMu.RLock() + defer b.contextMu.RUnlock() return b.context } @@ -713,7 +710,7 @@ func (b *Browser) NewContext(opts *BrowserContextOptions) (*BrowserContext, erro if b.closing.Load() { return nil, spanRecordErrorf(span, "browser has been closed") } - if b.context != nil { + if b.Context() != nil { return nil, spanRecordErrorf(span, "existing browser context must be closed before creating a new one") } if opts == nil { diff --git a/internal/js/modules/k6/browser/common/browser_test.go b/internal/js/modules/k6/browser/common/browser_test.go index 9607c84ef..2bdfeb860 100644 --- a/internal/js/modules/k6/browser/common/browser_test.go +++ b/internal/js/modules/k6/browser/common/browser_test.go @@ -3,6 +3,7 @@ package common import ( "context" "errors" + "sync" "testing" "time" @@ -242,6 +243,62 @@ func TestConnectionOnAttachedToTarget(t *testing.T) { } } +func TestBrowserContextDisposeAndLookupRace(t *testing.T) { + t.Parallel() + + const browserContextID cdp.BrowserContextID = "context" + + ctx, cancel := context.WithCancel(context.Background()) + t.Cleanup(cancel) + b := newBrowser(context.Background(), ctx, cancel, nil, NewLocalBrowserOptions(), log.NewNullLogger()) + b.context = &BrowserContext{id: browserContextID} + b.defaultContext = &BrowserContext{} + b.conn = fakeConn{ + execute: func(context.Context, string, any, any) error { + return nil + }, + } + + const iterations = 100 + const workers = 3 + var ( + wg sync.WaitGroup + disposeErrors = make(chan error, workers*iterations) + lookupContexts = make(chan *BrowserContext, workers*iterations) + ) + + for range workers { // make multiple goroutines + wg.Add(2) + go func() { // writes to context + defer wg.Done() + for range iterations { + disposeErrors <- b.disposeContext(browserContextID) + } + }() + + go func() { // reads from context + defer wg.Done() + for range iterations { + lookupContexts <- b.getDefaultBrowserContextOrMatchedID(browserContextID) + b.Context() + } + }() + } + + wg.Wait() + close(disposeErrors) + close(lookupContexts) + + for err := range disposeErrors { + require.NoError(t, err) + } + for browserContext := range lookupContexts { + require.NotNil(t, browserContext) + } + require.Nil(t, b.Context()) + require.Same(t, b.defaultContext, b.getDefaultBrowserContextOrMatchedID(browserContextID)) +} + // TestBrowserRejectedTarget ensures a target the connection accepts but the // browser rejects (isAttachedPageValid) is resumed and then detached from, // like the connection-level rejection in TestConnectionRejectedTarget. From bf2835cf606bfc86b2e80dccb3ab4ba481e32cbe Mon Sep 17 00:00:00 2001 From: Mihail Stoykov <312246+mstoykov@users.noreply.github.com> Date: Thu, 17 Sep 2026 10:22:56 +0300 Subject: [PATCH 159/182] Fix implicit area role test fixture (#6413) * Fix implicit area role test fixture * Make implicit area fixture accessible * Include hidden image map areas in role test --- internal/js/modules/k6/browser/tests/get_by_test.go | 10 +++++++--- .../k6/browser/tests/static/get_by_role_implicit.html | 3 ++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/internal/js/modules/k6/browser/tests/get_by_test.go b/internal/js/modules/k6/browser/tests/get_by_test.go index 416725e45..14e61910c 100644 --- a/internal/js/modules/k6/browser/tests/get_by_test.go +++ b/internal/js/modules/k6/browser/tests/get_by_test.go @@ -43,9 +43,13 @@ func TestGetByRoleSuccess(t *testing.T) { expected: 1, expectedText: "Link text", }, { - name: "area", - role: "link", - opts: &common.GetByRoleOptions{Name: new(`'Map area'`)}, + // Chromium styles as display:none, including valid image-map hotspots. + name: "area", + role: "link", + opts: &common.GetByRoleOptions{ + Name: new(`'Map area'`), + IncludeHidden: new(true), + }, expected: 1, expectedText: "", }, { diff --git a/internal/js/modules/k6/browser/tests/static/get_by_role_implicit.html b/internal/js/modules/k6/browser/tests/static/get_by_role_implicit.html index d15a3b141..4aa261854 100644 --- a/internal/js/modules/k6/browser/tests/static/get_by_role_implicit.html +++ b/internal/js/modules/k6/browser/tests/static/get_by_role_implicit.html @@ -10,7 +10,8 @@ Link text - + + From de2ab4a723e08a39c7e64954adecfa5cba048522 Mon Sep 17 00:00:00 2001 From: Mihail Stoykov <312246+mstoykov@users.noreply.github.com> Date: Thu, 17 Sep 2026 16:34:55 +0300 Subject: [PATCH 160/182] fix(js): mention async-metric-context feature flag in group() async error (#6408) When group() is called with an async callback and the async-metric-context experimental feature is not enabled, the returned error now tells the user how to enable it (--features async-metric-context / K6_FEATURES) instead of implying async callbacks are unsupported outright. Addresses review feedback on #6341. Co-authored-by: Claude Opus 4.8 --- internal/js/modules/k6/k6.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/js/modules/k6/k6.go b/internal/js/modules/k6/k6.go index d4992acc7..2423f4b3a 100644 --- a/internal/js/modules/k6/k6.go +++ b/internal/js/modules/k6/k6.go @@ -114,7 +114,9 @@ func (mi *K6) Group(name string, val sobek.Value) (sobek.Value, error) { return nil, errors.New("group() requires a callback as a second argument") } if !mi.asyncGroups && common.IsAsyncFunction(mi.vu.Runtime(), val) { - return sobek.Undefined(), errors.New("group() does not support async functions as arguments, " + + return sobek.Undefined(), errors.New("group() does not support async functions as arguments " + + "unless the async-metric-context experimental feature is enabled " + + "(pass --features async-metric-context or set K6_FEATURES=async-metric-context), " + "please see https://grafana.com/docs/k6/latest/javascript-api/k6/group/ for more info") } From dcbc7e79ba0af1130d5fa1e68e2decfa14eea103 Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Thu, 17 Sep 2026 09:53:29 -0400 Subject: [PATCH 161/182] fix(deps): update module github.com/klauspost/compress to v1.20.0 (#6266) | datasource | package | from | to | | ---------- | ----------------------------- | ------- | ------- | | go | github.com/klauspost/compress | v1.19.1 | v1.20.0 | Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 +- .../klauspost/compress/flate/deflate.go | 1 + .../klauspost/compress/flate/fast_encoder.go | 3 +- .../klauspost/compress/flate/inflate.go | 12 +- .../klauspost/compress/flate/inflate_gen.go | 112 +- .../klauspost/compress/flate/regmask_amd64.go | 37 - .../klauspost/compress/flate/regmask_other.go | 39 - .../compress/huff0/decompress_amd64.go | 203 +- .../compress/huff0/decompress_amd64.s | 210 +- .../compress/huff0/decompress_arm64.go | 37 + .../compress/huff0/decompress_arm64.s | 796 + .../compress/huff0/decompress_asm.go | 193 + .../compress/huff0/decompress_generic.go | 2 +- .../compress/internal/regmask/regmask.go | 50 + .../compress/internal/regmask/regmask_386.go | 39 + .../s2/{encode_amd64.go => encode_asm.go} | 4 +- .../klauspost/compress/s2/encode_better.go | 8 +- .../klauspost/compress/s2/encode_go.go | 4 +- .../klauspost/compress/s2/encodeblock_amd64.s | 844 +- .../klauspost/compress/s2/encodeblock_arm64.s | 23562 ++++++++++++++++ ...ncodeblock_amd64.go => encodeblock_asm.go} | 4 +- .../klauspost/compress/s2/lz4convert.go | 4 +- .../klauspost/compress/s2/lz4sconvert.go | 4 +- .../klauspost/compress/s2/reader.go | 6 +- .../klauspost/compress/s2/writer.go | 6 +- .../klauspost/compress/zstd/blockdec.go | 9 +- .../klauspost/compress/zstd/dict.go | 85 +- .../compress/zstd/fse_decoder_arm64.s | 25 +- .../compress/zstd/internal/xxhash/xxhash.go | 12 + .../zstd/internal/xxhash/xxhash_amd64.s | 6 +- .../zstd/internal/xxhash/xxhash_arm64.s | 6 +- .../klauspost/compress/zstd/seqdec_amd64.s | 736 +- .../klauspost/compress/zstd/seqdec_arm64.s | 1083 +- .../klauspost/compress/zstd/seqdec_asm.go | 33 +- vendor/modules.txt | 5 +- 36 files changed, 26132 insertions(+), 2054 deletions(-) delete mode 100644 vendor/github.com/klauspost/compress/flate/regmask_amd64.go delete mode 100644 vendor/github.com/klauspost/compress/flate/regmask_other.go create mode 100644 vendor/github.com/klauspost/compress/huff0/decompress_arm64.go create mode 100644 vendor/github.com/klauspost/compress/huff0/decompress_arm64.s create mode 100644 vendor/github.com/klauspost/compress/huff0/decompress_asm.go create mode 100644 vendor/github.com/klauspost/compress/internal/regmask/regmask.go create mode 100644 vendor/github.com/klauspost/compress/internal/regmask/regmask_386.go rename vendor/github.com/klauspost/compress/s2/{encode_amd64.go => encode_asm.go} (98%) create mode 100644 vendor/github.com/klauspost/compress/s2/encodeblock_arm64.s rename vendor/github.com/klauspost/compress/s2/{encodeblock_amd64.go => encodeblock_asm.go} (98%) diff --git a/go.mod b/go.mod index 6d075f5cc..612f93da9 100644 --- a/go.mod +++ b/go.mod @@ -26,7 +26,7 @@ require ( github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 github.com/influxdata/influxdb1-client v0.0.0-20190402204710-8ff2fc3824fc github.com/jhump/protoreflect v1.18.0 - github.com/klauspost/compress v1.19.1 + github.com/klauspost/compress v1.20.0 github.com/mattn/go-colorable v0.1.15 github.com/mattn/go-isatty v0.0.24 github.com/mccutchen/go-httpbin/v2 v2.25.0 diff --git a/go.sum b/go.sum index e87ba6aaa..e77762ca3 100644 --- a/go.sum +++ b/go.sum @@ -116,8 +116,8 @@ github.com/jhump/protoreflect/v2 v2.0.0-beta.1 h1:Dw1rslK/VotaUGYsv53XVWITr+5RCP github.com/jhump/protoreflect/v2 v2.0.0-beta.1/go.mod h1:D9LBEowZyv8/iSu97FU2zmXG3JxVTmNw21mu63niFzU= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/klauspost/compress v1.19.1 h1:VsB4HPswih7mmZ8WleSFQ75c/Ui1M4trX5oAsJnhSlk= -github.com/klauspost/compress v1.19.1/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ= +github.com/klauspost/compress v1.20.0 h1:a3C1ke2ohxFymNlb2HWAHjDeKCI90scRskErZkR0ezA= +github.com/klauspost/compress v1.20.0/go.mod h1:LUdAzn7YLVvxLpc7y3V1m40wESHTgc1422pwwBSKYuI= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= diff --git a/vendor/github.com/klauspost/compress/flate/deflate.go b/vendor/github.com/klauspost/compress/flate/deflate.go index 57d17eeab..73d81088e 100644 --- a/vendor/github.com/klauspost/compress/flate/deflate.go +++ b/vendor/github.com/klauspost/compress/flate/deflate.go @@ -260,6 +260,7 @@ func (d *compressor) fillWindow(b []byte) { } // Update window information. d.windowEnd += n + d.blockStart = d.windowEnd s.index = n } diff --git a/vendor/github.com/klauspost/compress/flate/fast_encoder.go b/vendor/github.com/klauspost/compress/flate/fast_encoder.go index 791c9dcbf..a8cdc5c99 100644 --- a/vendor/github.com/klauspost/compress/flate/fast_encoder.go +++ b/vendor/github.com/klauspost/compress/flate/fast_encoder.go @@ -9,6 +9,7 @@ import ( "fmt" "github.com/klauspost/compress/internal/le" + "github.com/klauspost/compress/internal/regmask" ) type fastEnc interface { @@ -108,7 +109,7 @@ type tableEntryPrev struct { // hash7 returns the hash of the lowest 7 bytes of u to fit in a hash table with h bits. // Preferably h should be a constant and should always be <64. func hash7(u uint64, h uint8) uint32 { - return uint32(((u << (64 - 56)) * prime7bytes) >> ((64 - h) & reg8SizeMask64)) + return uint32(((u << (64 - 56)) * prime7bytes) >> ((64 - h) & regmask.Shift64ByUint8)) } // hashLen returns a hash of the lowest mls bytes of with length output bits. diff --git a/vendor/github.com/klauspost/compress/flate/inflate.go b/vendor/github.com/klauspost/compress/flate/inflate.go index 39dd683b2..ad0ad3e22 100644 --- a/vendor/github.com/klauspost/compress/flate/inflate.go +++ b/vendor/github.com/klauspost/compress/flate/inflate.go @@ -14,6 +14,8 @@ import ( "io" "math/bits" "sync" + + "github.com/klauspost/compress/internal/regmask" ) const ( @@ -557,8 +559,8 @@ func (f *decompressor) readHuffman() error { return err } } - rep += int(f.b & uint32(1<<(nb®SizeMaskUint32)-1)) - f.b >>= nb & regSizeMaskUint32 + rep += int(f.b & uint32(1<<(nb®mask.Shift32ByUint)-1)) + f.b >>= nb & regmask.Shift32ByUint f.nb -= nb if i+rep > n { if debugDecode { @@ -731,7 +733,7 @@ func (f *decompressor) moreBits() error { return noEOF(err) } f.roffset++ - f.b |= uint32(c) << (f.nb & regSizeMaskUint32) + f.b |= uint32(c) << (f.nb & regmask.Shift32ByUint) f.nb += 8 return nil } @@ -756,7 +758,7 @@ func (f *decompressor) huffSym(h *huffmanDecoder) (int, error) { return 0, noEOF(err) } f.roffset++ - b |= uint32(c) << (nb & regSizeMaskUint32) + b |= uint32(c) << (nb & regmask.Shift32ByUint) nb += 8 } chunk := h.chunks[b&(huffmanNumChunks-1)] @@ -775,7 +777,7 @@ func (f *decompressor) huffSym(h *huffmanDecoder) (int, error) { f.err = CorruptInputError(f.roffset) return 0, f.err } - f.b = b >> (n & regSizeMaskUint32) + f.b = b >> (n & regmask.Shift32ByUint) f.nb = nb - n return int(chunk >> huffmanValueShift), nil } diff --git a/vendor/github.com/klauspost/compress/flate/inflate_gen.go b/vendor/github.com/klauspost/compress/flate/inflate_gen.go index e80f19656..3bc1cf1cb 100644 --- a/vendor/github.com/klauspost/compress/flate/inflate_gen.go +++ b/vendor/github.com/klauspost/compress/flate/inflate_gen.go @@ -8,6 +8,8 @@ import ( "fmt" "math/bits" "strings" + + "github.com/klauspost/compress/internal/regmask" ) func peekBufio(fr *bufio.Reader) ([]byte, error) { @@ -62,7 +64,7 @@ readLiteral: return } f.roffset++ - fb |= uint32(c) << (fnb & regSizeMaskUint32) + fb |= uint32(c) << (fnb & regmask.Shift32ByUint) fnb += 8 } chunk := f.hl.chunks[fb&(huffmanNumChunks-1)] @@ -80,7 +82,7 @@ readLiteral: f.err = CorruptInputError(f.roffset) return } - fb = fb >> (n & regSizeMaskUint32) + fb = fb >> (n & regmask.Shift32ByUint) fnb = fnb - n v = int(chunk >> huffmanValueShift) break @@ -122,11 +124,11 @@ readLiteral: return } f.roffset++ - fb |= uint32(c) << (fnb & regSizeMaskUint32) + fb |= uint32(c) << (fnb & regmask.Shift32ByUint) fnb += 8 } length += int(fb & bitMask32[n]) - fb >>= n & regSizeMaskUint32 + fb >>= n & regmask.Shift32ByUint fnb -= n default: if debugDecode { @@ -150,7 +152,7 @@ readLiteral: return } f.roffset++ - fb |= uint32(c) << (fnb & regSizeMaskUint32) + fb |= uint32(c) << (fnb & regmask.Shift32ByUint) fnb += 8 } dist = uint32(bits.Reverse8(uint8(fb & 0x1F << 3))) @@ -174,7 +176,7 @@ readLiteral: return } f.roffset++ - fb |= uint32(c) << (fnb & regSizeMaskUint32) + fb |= uint32(c) << (fnb & regmask.Shift32ByUint) fnb += 8 } chunk := f.hd.chunks[fb&(huffmanNumChunks-1)] @@ -192,7 +194,7 @@ readLiteral: f.err = CorruptInputError(f.roffset) return } - fb = fb >> (n & regSizeMaskUint32) + fb = fb >> (n & regmask.Shift32ByUint) fnb = fnb - n dist = uint32(chunk >> huffmanValueShift) break @@ -206,7 +208,7 @@ readLiteral: case dist < maxNumDist: nb := uint(dist-2) >> 1 // have 1 bit in bottom of dist, need nb more. - extra := (dist & 1) << (nb & regSizeMaskUint32) + extra := (dist & 1) << (nb & regmask.Shift32ByUint) for fnb < nb { c, err := fr.ReadByte() if err != nil { @@ -218,13 +220,13 @@ readLiteral: return } f.roffset++ - fb |= uint32(c) << (fnb & regSizeMaskUint32) + fb |= uint32(c) << (fnb & regmask.Shift32ByUint) fnb += 8 } extra |= fb & bitMask32[nb] - fb >>= nb & regSizeMaskUint32 + fb >>= nb & regmask.Shift32ByUint fnb -= nb - dist = 1<<((nb+1)®SizeMaskUint32) + 1 + extra + dist = 1<<((nb+1)®mask.Shift32ByUint) + 1 + extra // slower: dist = bitMask32[nb+1] + 2 + extra default: f.b, f.nb = fb, fnb @@ -313,7 +315,7 @@ readLiteral: return } f.roffset++ - fb |= uint32(c) << (fnb & regSizeMaskUint32) + fb |= uint32(c) << (fnb & regmask.Shift32ByUint) fnb += 8 } chunk := f.hl.chunks[fb&(huffmanNumChunks-1)] @@ -331,7 +333,7 @@ readLiteral: f.err = CorruptInputError(f.roffset) return } - fb = fb >> (n & regSizeMaskUint32) + fb = fb >> (n & regmask.Shift32ByUint) fnb = fnb - n v = int(chunk >> huffmanValueShift) break @@ -373,11 +375,11 @@ readLiteral: return } f.roffset++ - fb |= uint32(c) << (fnb & regSizeMaskUint32) + fb |= uint32(c) << (fnb & regmask.Shift32ByUint) fnb += 8 } length += int(fb & bitMask32[n]) - fb >>= n & regSizeMaskUint32 + fb >>= n & regmask.Shift32ByUint fnb -= n default: if debugDecode { @@ -401,7 +403,7 @@ readLiteral: return } f.roffset++ - fb |= uint32(c) << (fnb & regSizeMaskUint32) + fb |= uint32(c) << (fnb & regmask.Shift32ByUint) fnb += 8 } dist = uint32(bits.Reverse8(uint8(fb & 0x1F << 3))) @@ -425,7 +427,7 @@ readLiteral: return } f.roffset++ - fb |= uint32(c) << (fnb & regSizeMaskUint32) + fb |= uint32(c) << (fnb & regmask.Shift32ByUint) fnb += 8 } chunk := f.hd.chunks[fb&(huffmanNumChunks-1)] @@ -443,7 +445,7 @@ readLiteral: f.err = CorruptInputError(f.roffset) return } - fb = fb >> (n & regSizeMaskUint32) + fb = fb >> (n & regmask.Shift32ByUint) fnb = fnb - n dist = uint32(chunk >> huffmanValueShift) break @@ -457,7 +459,7 @@ readLiteral: case dist < maxNumDist: nb := uint(dist-2) >> 1 // have 1 bit in bottom of dist, need nb more. - extra := (dist & 1) << (nb & regSizeMaskUint32) + extra := (dist & 1) << (nb & regmask.Shift32ByUint) for fnb < nb { c, err := fr.ReadByte() if err != nil { @@ -469,13 +471,13 @@ readLiteral: return } f.roffset++ - fb |= uint32(c) << (fnb & regSizeMaskUint32) + fb |= uint32(c) << (fnb & regmask.Shift32ByUint) fnb += 8 } extra |= fb & bitMask32[nb] - fb >>= nb & regSizeMaskUint32 + fb >>= nb & regmask.Shift32ByUint fnb -= nb - dist = 1<<((nb+1)®SizeMaskUint32) + 1 + extra + dist = 1<<((nb+1)®mask.Shift32ByUint) + 1 + extra // slower: dist = bitMask32[nb+1] + 2 + extra default: f.b, f.nb = fb, fnb @@ -573,7 +575,7 @@ readLiteral: c := pbuf[pos] pos++ f.roffset++ - fb |= uint32(c) << (fnb & regSizeMaskUint32) + fb |= uint32(c) << (fnb & regmask.Shift32ByUint) fnb += 8 } chunk := f.hl.chunks[fb&(huffmanNumChunks-1)] @@ -592,7 +594,7 @@ readLiteral: f.err = CorruptInputError(f.roffset) return } - fb = fb >> (n & regSizeMaskUint32) + fb = fb >> (n & regmask.Shift32ByUint) fnb = fnb - n v = int(chunk >> huffmanValueShift) break @@ -643,11 +645,11 @@ readLiteral: c := pbuf[pos] pos++ f.roffset++ - fb |= uint32(c) << (fnb & regSizeMaskUint32) + fb |= uint32(c) << (fnb & regmask.Shift32ByUint) fnb += 8 } length += int(fb & bitMask32[n]) - fb >>= n & regSizeMaskUint32 + fb >>= n & regmask.Shift32ByUint fnb -= n default: fr.Discard(pos) @@ -679,7 +681,7 @@ readLiteral: c := pbuf[pos] pos++ f.roffset++ - fb |= uint32(c) << (fnb & regSizeMaskUint32) + fb |= uint32(c) << (fnb & regmask.Shift32ByUint) fnb += 8 } dist = uint32(bits.Reverse8(uint8(fb & 0x1F << 3))) @@ -710,7 +712,7 @@ readLiteral: c := pbuf[pos] pos++ f.roffset++ - fb |= uint32(c) << (fnb & regSizeMaskUint32) + fb |= uint32(c) << (fnb & regmask.Shift32ByUint) fnb += 8 } chunk := f.hd.chunks[fb&(huffmanNumChunks-1)] @@ -729,7 +731,7 @@ readLiteral: f.err = CorruptInputError(f.roffset) return } - fb = fb >> (n & regSizeMaskUint32) + fb = fb >> (n & regmask.Shift32ByUint) fnb = fnb - n dist = uint32(chunk >> huffmanValueShift) break @@ -743,7 +745,7 @@ readLiteral: case dist < maxNumDist: nb := uint(dist-2) >> 1 // have 1 bit in bottom of dist, need nb more. - extra := (dist & 1) << (nb & regSizeMaskUint32) + extra := (dist & 1) << (nb & regmask.Shift32ByUint) for fnb < nb { if pos >= len(pbuf) { fr.Discard(pos) @@ -762,13 +764,13 @@ readLiteral: c := pbuf[pos] pos++ f.roffset++ - fb |= uint32(c) << (fnb & regSizeMaskUint32) + fb |= uint32(c) << (fnb & regmask.Shift32ByUint) fnb += 8 } extra |= fb & bitMask32[nb] - fb >>= nb & regSizeMaskUint32 + fb >>= nb & regmask.Shift32ByUint fnb -= nb - dist = 1<<((nb+1)®SizeMaskUint32) + 1 + extra + dist = 1<<((nb+1)®mask.Shift32ByUint) + 1 + extra // slower: dist = bitMask32[nb+1] + 2 + extra default: fr.Discard(pos) @@ -860,7 +862,7 @@ readLiteral: return } f.roffset++ - fb |= uint32(c) << (fnb & regSizeMaskUint32) + fb |= uint32(c) << (fnb & regmask.Shift32ByUint) fnb += 8 } chunk := f.hl.chunks[fb&(huffmanNumChunks-1)] @@ -878,7 +880,7 @@ readLiteral: f.err = CorruptInputError(f.roffset) return } - fb = fb >> (n & regSizeMaskUint32) + fb = fb >> (n & regmask.Shift32ByUint) fnb = fnb - n v = int(chunk >> huffmanValueShift) break @@ -920,11 +922,11 @@ readLiteral: return } f.roffset++ - fb |= uint32(c) << (fnb & regSizeMaskUint32) + fb |= uint32(c) << (fnb & regmask.Shift32ByUint) fnb += 8 } length += int(fb & bitMask32[n]) - fb >>= n & regSizeMaskUint32 + fb >>= n & regmask.Shift32ByUint fnb -= n default: if debugDecode { @@ -948,7 +950,7 @@ readLiteral: return } f.roffset++ - fb |= uint32(c) << (fnb & regSizeMaskUint32) + fb |= uint32(c) << (fnb & regmask.Shift32ByUint) fnb += 8 } dist = uint32(bits.Reverse8(uint8(fb & 0x1F << 3))) @@ -972,7 +974,7 @@ readLiteral: return } f.roffset++ - fb |= uint32(c) << (fnb & regSizeMaskUint32) + fb |= uint32(c) << (fnb & regmask.Shift32ByUint) fnb += 8 } chunk := f.hd.chunks[fb&(huffmanNumChunks-1)] @@ -990,7 +992,7 @@ readLiteral: f.err = CorruptInputError(f.roffset) return } - fb = fb >> (n & regSizeMaskUint32) + fb = fb >> (n & regmask.Shift32ByUint) fnb = fnb - n dist = uint32(chunk >> huffmanValueShift) break @@ -1004,7 +1006,7 @@ readLiteral: case dist < maxNumDist: nb := uint(dist-2) >> 1 // have 1 bit in bottom of dist, need nb more. - extra := (dist & 1) << (nb & regSizeMaskUint32) + extra := (dist & 1) << (nb & regmask.Shift32ByUint) for fnb < nb { c, err := fr.ReadByte() if err != nil { @@ -1016,13 +1018,13 @@ readLiteral: return } f.roffset++ - fb |= uint32(c) << (fnb & regSizeMaskUint32) + fb |= uint32(c) << (fnb & regmask.Shift32ByUint) fnb += 8 } extra |= fb & bitMask32[nb] - fb >>= nb & regSizeMaskUint32 + fb >>= nb & regmask.Shift32ByUint fnb -= nb - dist = 1<<((nb+1)®SizeMaskUint32) + 1 + extra + dist = 1<<((nb+1)®mask.Shift32ByUint) + 1 + extra // slower: dist = bitMask32[nb+1] + 2 + extra default: f.b, f.nb = fb, fnb @@ -1111,7 +1113,7 @@ readLiteral: return } f.roffset++ - fb |= uint32(c) << (fnb & regSizeMaskUint32) + fb |= uint32(c) << (fnb & regmask.Shift32ByUint) fnb += 8 } chunk := f.hl.chunks[fb&(huffmanNumChunks-1)] @@ -1129,7 +1131,7 @@ readLiteral: f.err = CorruptInputError(f.roffset) return } - fb = fb >> (n & regSizeMaskUint32) + fb = fb >> (n & regmask.Shift32ByUint) fnb = fnb - n v = int(chunk >> huffmanValueShift) break @@ -1171,11 +1173,11 @@ readLiteral: return } f.roffset++ - fb |= uint32(c) << (fnb & regSizeMaskUint32) + fb |= uint32(c) << (fnb & regmask.Shift32ByUint) fnb += 8 } length += int(fb & bitMask32[n]) - fb >>= n & regSizeMaskUint32 + fb >>= n & regmask.Shift32ByUint fnb -= n default: if debugDecode { @@ -1199,7 +1201,7 @@ readLiteral: return } f.roffset++ - fb |= uint32(c) << (fnb & regSizeMaskUint32) + fb |= uint32(c) << (fnb & regmask.Shift32ByUint) fnb += 8 } dist = uint32(bits.Reverse8(uint8(fb & 0x1F << 3))) @@ -1223,7 +1225,7 @@ readLiteral: return } f.roffset++ - fb |= uint32(c) << (fnb & regSizeMaskUint32) + fb |= uint32(c) << (fnb & regmask.Shift32ByUint) fnb += 8 } chunk := f.hd.chunks[fb&(huffmanNumChunks-1)] @@ -1241,7 +1243,7 @@ readLiteral: f.err = CorruptInputError(f.roffset) return } - fb = fb >> (n & regSizeMaskUint32) + fb = fb >> (n & regmask.Shift32ByUint) fnb = fnb - n dist = uint32(chunk >> huffmanValueShift) break @@ -1255,7 +1257,7 @@ readLiteral: case dist < maxNumDist: nb := uint(dist-2) >> 1 // have 1 bit in bottom of dist, need nb more. - extra := (dist & 1) << (nb & regSizeMaskUint32) + extra := (dist & 1) << (nb & regmask.Shift32ByUint) for fnb < nb { c, err := fr.ReadByte() if err != nil { @@ -1267,13 +1269,13 @@ readLiteral: return } f.roffset++ - fb |= uint32(c) << (fnb & regSizeMaskUint32) + fb |= uint32(c) << (fnb & regmask.Shift32ByUint) fnb += 8 } extra |= fb & bitMask32[nb] - fb >>= nb & regSizeMaskUint32 + fb >>= nb & regmask.Shift32ByUint fnb -= nb - dist = 1<<((nb+1)®SizeMaskUint32) + 1 + extra + dist = 1<<((nb+1)®mask.Shift32ByUint) + 1 + extra // slower: dist = bitMask32[nb+1] + 2 + extra default: f.b, f.nb = fb, fnb diff --git a/vendor/github.com/klauspost/compress/flate/regmask_amd64.go b/vendor/github.com/klauspost/compress/flate/regmask_amd64.go deleted file mode 100644 index 6ed28061b..000000000 --- a/vendor/github.com/klauspost/compress/flate/regmask_amd64.go +++ /dev/null @@ -1,37 +0,0 @@ -package flate - -const ( - // Masks for shifts with register sizes of the shift value. - // This can be used to work around the x86 design of shifting by mod register size. - // It can be used when a variable shift is always smaller than the register size. - - // reg8SizeMaskX - shift value is 8 bits, shifted is X - reg8SizeMask8 = 7 - reg8SizeMask16 = 15 - reg8SizeMask32 = 31 - reg8SizeMask64 = 63 - - // reg16SizeMaskX - shift value is 16 bits, shifted is X - reg16SizeMask8 = reg8SizeMask8 - reg16SizeMask16 = reg8SizeMask16 - reg16SizeMask32 = reg8SizeMask32 - reg16SizeMask64 = reg8SizeMask64 - - // reg32SizeMaskX - shift value is 32 bits, shifted is X - reg32SizeMask8 = reg8SizeMask8 - reg32SizeMask16 = reg8SizeMask16 - reg32SizeMask32 = reg8SizeMask32 - reg32SizeMask64 = reg8SizeMask64 - - // reg64SizeMaskX - shift value is 64 bits, shifted is X - reg64SizeMask8 = reg8SizeMask8 - reg64SizeMask16 = reg8SizeMask16 - reg64SizeMask32 = reg8SizeMask32 - reg64SizeMask64 = reg8SizeMask64 - - // regSizeMaskUintX - shift value is uint, shifted is X - regSizeMaskUint8 = reg8SizeMask8 - regSizeMaskUint16 = reg8SizeMask16 - regSizeMaskUint32 = reg8SizeMask32 - regSizeMaskUint64 = reg8SizeMask64 -) diff --git a/vendor/github.com/klauspost/compress/flate/regmask_other.go b/vendor/github.com/klauspost/compress/flate/regmask_other.go deleted file mode 100644 index e62caf711..000000000 --- a/vendor/github.com/klauspost/compress/flate/regmask_other.go +++ /dev/null @@ -1,39 +0,0 @@ -//go:build !amd64 - -package flate - -const ( - // Masks for shifts with register sizes of the shift value. - // This can be used to work around the x86 design of shifting by mod register size. - // It can be used when a variable shift is always smaller than the register size. - - // reg8SizeMaskX - shift value is 8 bits, shifted is X - reg8SizeMask8 = 0xff - reg8SizeMask16 = 0xff - reg8SizeMask32 = 0xff - reg8SizeMask64 = 0xff - - // reg16SizeMaskX - shift value is 16 bits, shifted is X - reg16SizeMask8 = 0xffff - reg16SizeMask16 = 0xffff - reg16SizeMask32 = 0xffff - reg16SizeMask64 = 0xffff - - // reg32SizeMaskX - shift value is 32 bits, shifted is X - reg32SizeMask8 = 0xffffffff - reg32SizeMask16 = 0xffffffff - reg32SizeMask32 = 0xffffffff - reg32SizeMask64 = 0xffffffff - - // reg64SizeMaskX - shift value is 64 bits, shifted is X - reg64SizeMask8 = 0xffffffffffffffff - reg64SizeMask16 = 0xffffffffffffffff - reg64SizeMask32 = 0xffffffffffffffff - reg64SizeMask64 = 0xffffffffffffffff - - // regSizeMaskUintX - shift value is uint, shifted is X - regSizeMaskUint8 = ^uint(0) - regSizeMaskUint16 = ^uint(0) - regSizeMaskUint32 = ^uint(0) - regSizeMaskUint64 = ^uint(0) -) diff --git a/vendor/github.com/klauspost/compress/huff0/decompress_amd64.go b/vendor/github.com/klauspost/compress/huff0/decompress_amd64.go index 2d6ef64be..7035d656d 100644 --- a/vendor/github.com/klauspost/compress/huff0/decompress_amd64.go +++ b/vendor/github.com/klauspost/compress/huff0/decompress_amd64.go @@ -1,222 +1,49 @@ //go:build amd64 && !appengine && !noasm && gc -// This file contains the specialisation of Decoder.Decompress4X -// and Decoder.Decompress1X that use an asm implementation of thir main loops. +// amd64 stubs and dispatch for the asm loops used by decompress_asm.go. package huff0 import ( - "errors" - "fmt" - "github.com/klauspost/compress/internal/cpuinfo" ) -// decompress4x_main_loop_x86 is an x86 assembler implementation +// decompress4x_main_loop_amd64 is an x86 assembler implementation // of Decompress4X when tablelog > 8. // //go:noescape func decompress4x_main_loop_amd64(ctx *decompress4xContext) -// decompress4x_8b_loop_x86 is an x86 assembler implementation +// decompress4x_8b_main_loop_amd64 is an x86 assembler implementation // of Decompress4X when tablelog <= 8 which decodes 4 entries // per loop. // //go:noescape func decompress4x_8b_main_loop_amd64(ctx *decompress4xContext) -// fallback8BitSize is the size where using Go version is faster. -const fallback8BitSize = 800 - -type decompress4xContext struct { - pbr *[4]bitReaderShifted - peekBits uint8 - out *byte - dstEvery int - tbl *dEntrySingle - decoded int - limit *byte -} - -// Decompress4X will decompress a 4X encoded stream. -// The length of the supplied input must match the end of a block exactly. -// The *capacity* of the dst slice must match the destination size of -// the uncompressed data exactly. -func (d *Decoder) Decompress4X(dst, src []byte) ([]byte, error) { - if len(d.dt.single) == 0 { - return nil, errors.New("no table loaded") - } - if len(src) < 6+(4*1) { - return nil, errors.New("input too small") - } - - use8BitTables := d.actualTableLog <= 8 - if cap(dst) < fallback8BitSize && use8BitTables { - return d.decompress4X8bit(dst, src) - } - - var br [4]bitReaderShifted - // Decode "jump table" - start := 6 - for i := range 3 { - length := int(src[i*2]) | (int(src[i*2+1]) << 8) - if start+length >= len(src) { - return nil, errors.New("truncated input (or invalid offset)") - } - err := br[i].init(src[start : start+length]) - if err != nil { - return nil, err - } - start += length - } - err := br[3].init(src[start:]) - if err != nil { - return nil, err - } - - // destination, offset to match first output - dstSize := cap(dst) - dst = dst[:dstSize] - out := dst - dstEvery := (dstSize + 3) / 4 - - const tlSize = 1 << tableLogMax - const tlMask = tlSize - 1 - single := d.dt.single[:tlSize] - - var decoded int - - if len(out) > 4*4 && !(br[0].off < 4 || br[1].off < 4 || br[2].off < 4 || br[3].off < 4) { - ctx := decompress4xContext{ - pbr: &br, - peekBits: uint8((64 - d.actualTableLog) & 63), // see: bitReaderShifted.peekBitsFast() - out: &out[0], - dstEvery: dstEvery, - tbl: &single[0], - limit: &out[dstEvery-4], // Always stop decoding when first buffer gets here to avoid writing OOB on last. - } - if use8BitTables { - decompress4x_8b_main_loop_amd64(&ctx) - } else { - decompress4x_main_loop_amd64(&ctx) - } - - decoded = ctx.decoded - out = out[decoded/4:] - } - - // Decode remaining. - remainBytes := dstEvery - (decoded / 4) - for i := range br { - offset := dstEvery * i - endsAt := min(offset+remainBytes, len(out)) - br := &br[i] - bitsLeft := br.remaining() - for bitsLeft > 0 { - br.fill() - if offset >= endsAt { - return nil, errors.New("corruption detected: stream overrun 4") - } - - // Read value and increment offset. - val := br.peekBitsFast(d.actualTableLog) - v := single[val&tlMask].entry - nBits := uint8(v) - br.advance(nBits) - bitsLeft -= uint(nBits) - out[offset] = uint8(v >> 8) - offset++ - } - if offset != endsAt { - return nil, fmt.Errorf("corruption detected: short output block %d, end %d != %d", i, offset, endsAt) - } - decoded += offset - dstEvery*i - err = br.close() - if err != nil { - return nil, err - } - } - if dstSize != decoded { - return nil, errors.New("corruption detected: short output block") - } - return dst, nil -} - -// decompress4x_main_loop_x86 is an x86 assembler implementation +// decompress1x_main_loop_amd64 is an x86 assembler implementation // of Decompress1X when tablelog > 8. // //go:noescape func decompress1x_main_loop_amd64(ctx *decompress1xContext) -// decompress4x_main_loop_x86 is an x86 with BMI2 assembler implementation +// decompress1x_main_loop_bmi2 is an x86 with BMI2 assembler implementation // of Decompress1X when tablelog > 8. // //go:noescape func decompress1x_main_loop_bmi2(ctx *decompress1xContext) -type decompress1xContext struct { - pbr *bitReaderShifted - peekBits uint8 - out *byte - outCap int - tbl *dEntrySingle - decoded int +func decompress4x_main_loop_asm(ctx *decompress4xContext) { + decompress4x_main_loop_amd64(ctx) } -// Error reported by asm implementations -const error_max_decoded_size_exeeded = -1 - -// Decompress1X will decompress a 1X encoded stream. -// The cap of the output buffer will be the maximum decompressed size. -// The length of the supplied input must match the end of a block exactly. -func (d *Decoder) Decompress1X(dst, src []byte) ([]byte, error) { - if len(d.dt.single) == 0 { - return nil, errors.New("no table loaded") - } - var br bitReaderShifted - err := br.init(src) - if err != nil { - return dst, err - } - maxDecodedSize := cap(dst) - dst = dst[:maxDecodedSize] - - const tlSize = 1 << tableLogMax - const tlMask = tlSize - 1 - - if maxDecodedSize >= 4 { - ctx := decompress1xContext{ - pbr: &br, - out: &dst[0], - outCap: maxDecodedSize, - peekBits: uint8((64 - d.actualTableLog) & 63), // see: bitReaderShifted.peekBitsFast() - tbl: &d.dt.single[0], - } - - if cpuinfo.HasBMI2() { - decompress1x_main_loop_bmi2(&ctx) - } else { - decompress1x_main_loop_amd64(&ctx) - } - if ctx.decoded == error_max_decoded_size_exeeded { - return nil, ErrMaxDecodedSizeExceeded - } - - dst = dst[:ctx.decoded] - } +func decompress4x_8b_main_loop_asm(ctx *decompress4xContext) { + decompress4x_8b_main_loop_amd64(ctx) +} - // br < 8, so uint8 is fine - bitsLeft := uint8(br.off)*8 + 64 - br.bitsRead - for bitsLeft > 0 { - br.fill() - if len(dst) >= maxDecodedSize { - br.close() - return nil, ErrMaxDecodedSizeExceeded - } - v := d.dt.single[br.peekBitsFast(d.actualTableLog)&tlMask] - nBits := uint8(v.entry) - br.advance(nBits) - bitsLeft -= nBits - dst = append(dst, uint8(v.entry>>8)) +func decompress1x_main_loop_asm(ctx *decompress1xContext) { + if cpuinfo.HasBMI2() { + decompress1x_main_loop_bmi2(ctx) + } else { + decompress1x_main_loop_amd64(ctx) } - return dst, br.close() } diff --git a/vendor/github.com/klauspost/compress/huff0/decompress_amd64.s b/vendor/github.com/klauspost/compress/huff0/decompress_amd64.s index c4c7ab2d1..920628c51 100644 --- a/vendor/github.com/klauspost/compress/huff0/decompress_amd64.s +++ b/vendor/github.com/klauspost/compress/huff0/decompress_amd64.s @@ -1,6 +1,6 @@ -// Code generated by command: go run gen.go -out ../decompress_amd64.s -pkg=huff0. DO NOT EDIT. +// Code generated by command: go run gen.go -out ../decompress.s -arch amd64,arm64 -pkg=huff0. DO NOT EDIT. -//go:build amd64 && !appengine && !noasm && gc +//go:build !appengine && !noasm && gc // func decompress4x_main_loop_amd64(ctx *decompress4xContext) TEXT ·decompress4x_main_loop_amd64(SB), $0-8 @@ -47,12 +47,12 @@ skip_fill0: SHRQ CL, R13 // v0 := table[val0&mask] - MOVW (R9)(R13*2), CX + MOVWQZX (R9)(R13*2), CX // br0.advance(uint8(v0.entry) - MOVB CH, AL - SHLQ CL, R11 - ADDB CL, R12 + MOVBLZX CH, AX + SHLQ CL, R11 + ADDB CL, R12 // val1 := br0.peekTopBits(peekBits) MOVQ DI, CX @@ -60,7 +60,7 @@ skip_fill0: SHRQ CL, R13 // v1 := table[val1&mask] - MOVW (R9)(R13*2), CX + MOVWQZX (R9)(R13*2), CX // br0.advance(uint8(v1.entry)) MOVB CH, AH @@ -104,12 +104,12 @@ skip_fill1: SHRQ CL, R13 // v0 := table[val0&mask] - MOVW (R9)(R13*2), CX + MOVWQZX (R9)(R13*2), CX // br1.advance(uint8(v0.entry) - MOVB CH, AL - SHLQ CL, R11 - ADDB CL, R12 + MOVBLZX CH, AX + SHLQ CL, R11 + ADDB CL, R12 // val1 := br1.peekTopBits(peekBits) MOVQ DI, CX @@ -117,7 +117,7 @@ skip_fill1: SHRQ CL, R13 // v1 := table[val1&mask] - MOVW (R9)(R13*2), CX + MOVWQZX (R9)(R13*2), CX // br1.advance(uint8(v1.entry)) MOVB CH, AH @@ -161,12 +161,12 @@ skip_fill2: SHRQ CL, R13 // v0 := table[val0&mask] - MOVW (R9)(R13*2), CX + MOVWQZX (R9)(R13*2), CX // br2.advance(uint8(v0.entry) - MOVB CH, AL - SHLQ CL, R11 - ADDB CL, R12 + MOVBLZX CH, AX + SHLQ CL, R11 + ADDB CL, R12 // val1 := br2.peekTopBits(peekBits) MOVQ DI, CX @@ -174,7 +174,7 @@ skip_fill2: SHRQ CL, R13 // v1 := table[val1&mask] - MOVW (R9)(R13*2), CX + MOVWQZX (R9)(R13*2), CX // br2.advance(uint8(v1.entry)) MOVB CH, AH @@ -218,12 +218,12 @@ skip_fill3: SHRQ CL, R13 // v0 := table[val0&mask] - MOVW (R9)(R13*2), CX + MOVWQZX (R9)(R13*2), CX // br3.advance(uint8(v0.entry) - MOVB CH, AL - SHLQ CL, R11 - ADDB CL, R12 + MOVBLZX CH, AX + SHLQ CL, R11 + ADDB CL, R12 // val1 := br3.peekTopBits(peekBits) MOVQ DI, CX @@ -231,7 +231,7 @@ skip_fill3: SHRQ CL, R13 // v1 := table[val1&mask] - MOVW (R9)(R13*2), CX + MOVWQZX (R9)(R13*2), CX // br3.advance(uint8(v1.entry)) MOVB CH, AH @@ -259,13 +259,13 @@ skip_fill3: // func decompress4x_8b_main_loop_amd64(ctx *decompress4xContext) TEXT ·decompress4x_8b_main_loop_amd64(SB), $0-8 // Preload values - MOVQ ctx+0(FP), CX - MOVBQZX 8(CX), DI - MOVQ 16(CX), BX - MOVQ 48(CX), SI - MOVQ 24(CX), R8 - MOVQ 32(CX), R9 - MOVQ (CX), R10 + MOVQ ctx+0(FP), AX + MOVBQZX 8(AX), DI + MOVQ 16(AX), BX + MOVQ 48(AX), SI + MOVQ 24(AX), R8 + MOVQ 32(AX), R9 + MOVQ (AX), R10 // Main loop main_loop: @@ -278,35 +278,35 @@ main_loop: MOVBQZX 40(R10), R12 CMPQ R12, $0x20 JBE skip_fill0 - MOVQ 24(R10), R13 + MOVQ 24(R10), AX SUBQ $0x20, R12 - SUBQ $0x04, R13 - MOVQ (R10), R14 + SUBQ $0x04, AX + MOVQ (R10), R13 // b.value |= uint64(low) << (b.bitsRead & 63) - MOVL (R13)(R14*1), R14 + MOVL (AX)(R13*1), R13 MOVQ R12, CX - SHLQ CL, R14 - MOVQ R13, 24(R10) - ORQ R14, R11 + SHLQ CL, R13 + MOVQ AX, 24(R10) + ORQ R13, R11 // exhausted += (br0.off < 4) - CMPQ R13, $0x04 + CMPQ AX, $0x04 ADCB $+0, DL skip_fill0: // val0 := br0.peekTopBits(peekBits) - MOVQ R11, R13 + MOVQ R11, AX MOVQ DI, CX - SHRQ CL, R13 + SHRQ CL, AX // v0 := table[val0&mask] - MOVW (R9)(R13*2), CX + MOVWQZX (R9)(AX*2), CX // br0.advance(uint8(v0.entry) - MOVB CH, AL - SHLQ CL, R11 - ADDB CL, R12 + MOVBLZX CH, AX + SHLQ CL, R11 + ADDB CL, R12 // val1 := br0.peekTopBits(peekBits) MOVQ R11, R13 @@ -314,7 +314,7 @@ skip_fill0: SHRQ CL, R13 // v1 := table[val0&mask] - MOVW (R9)(R13*2), CX + MOVWQZX (R9)(R13*2), CX // br0.advance(uint8(v1.entry) MOVB CH, AH @@ -328,7 +328,7 @@ skip_fill0: SHRQ CL, R13 // v2 := table[val0&mask] - MOVW (R9)(R13*2), CX + MOVWQZX (R9)(R13*2), CX // br0.advance(uint8(v2.entry) MOVB CH, AH @@ -341,7 +341,7 @@ skip_fill0: SHRQ CL, R13 // v3 := table[val0&mask] - MOVW (R9)(R13*2), CX + MOVWQZX (R9)(R13*2), CX // br0.advance(uint8(v3.entry) MOVB CH, AL @@ -365,35 +365,35 @@ skip_fill0: MOVBQZX 88(R10), R12 CMPQ R12, $0x20 JBE skip_fill1 - MOVQ 72(R10), R13 + MOVQ 72(R10), AX SUBQ $0x20, R12 - SUBQ $0x04, R13 - MOVQ 48(R10), R14 + SUBQ $0x04, AX + MOVQ 48(R10), R13 // b.value |= uint64(low) << (b.bitsRead & 63) - MOVL (R13)(R14*1), R14 + MOVL (AX)(R13*1), R13 MOVQ R12, CX - SHLQ CL, R14 - MOVQ R13, 72(R10) - ORQ R14, R11 + SHLQ CL, R13 + MOVQ AX, 72(R10) + ORQ R13, R11 // exhausted += (br1.off < 4) - CMPQ R13, $0x04 + CMPQ AX, $0x04 ADCB $+0, DL skip_fill1: // val0 := br1.peekTopBits(peekBits) - MOVQ R11, R13 + MOVQ R11, AX MOVQ DI, CX - SHRQ CL, R13 + SHRQ CL, AX // v0 := table[val0&mask] - MOVW (R9)(R13*2), CX + MOVWQZX (R9)(AX*2), CX // br1.advance(uint8(v0.entry) - MOVB CH, AL - SHLQ CL, R11 - ADDB CL, R12 + MOVBLZX CH, AX + SHLQ CL, R11 + ADDB CL, R12 // val1 := br1.peekTopBits(peekBits) MOVQ R11, R13 @@ -401,7 +401,7 @@ skip_fill1: SHRQ CL, R13 // v1 := table[val0&mask] - MOVW (R9)(R13*2), CX + MOVWQZX (R9)(R13*2), CX // br1.advance(uint8(v1.entry) MOVB CH, AH @@ -415,7 +415,7 @@ skip_fill1: SHRQ CL, R13 // v2 := table[val0&mask] - MOVW (R9)(R13*2), CX + MOVWQZX (R9)(R13*2), CX // br1.advance(uint8(v2.entry) MOVB CH, AH @@ -428,7 +428,7 @@ skip_fill1: SHRQ CL, R13 // v3 := table[val0&mask] - MOVW (R9)(R13*2), CX + MOVWQZX (R9)(R13*2), CX // br1.advance(uint8(v3.entry) MOVB CH, AL @@ -452,35 +452,35 @@ skip_fill1: MOVBQZX 136(R10), R12 CMPQ R12, $0x20 JBE skip_fill2 - MOVQ 120(R10), R13 + MOVQ 120(R10), AX SUBQ $0x20, R12 - SUBQ $0x04, R13 - MOVQ 96(R10), R14 + SUBQ $0x04, AX + MOVQ 96(R10), R13 // b.value |= uint64(low) << (b.bitsRead & 63) - MOVL (R13)(R14*1), R14 + MOVL (AX)(R13*1), R13 MOVQ R12, CX - SHLQ CL, R14 - MOVQ R13, 120(R10) - ORQ R14, R11 + SHLQ CL, R13 + MOVQ AX, 120(R10) + ORQ R13, R11 // exhausted += (br2.off < 4) - CMPQ R13, $0x04 + CMPQ AX, $0x04 ADCB $+0, DL skip_fill2: // val0 := br2.peekTopBits(peekBits) - MOVQ R11, R13 + MOVQ R11, AX MOVQ DI, CX - SHRQ CL, R13 + SHRQ CL, AX // v0 := table[val0&mask] - MOVW (R9)(R13*2), CX + MOVWQZX (R9)(AX*2), CX // br2.advance(uint8(v0.entry) - MOVB CH, AL - SHLQ CL, R11 - ADDB CL, R12 + MOVBLZX CH, AX + SHLQ CL, R11 + ADDB CL, R12 // val1 := br2.peekTopBits(peekBits) MOVQ R11, R13 @@ -488,7 +488,7 @@ skip_fill2: SHRQ CL, R13 // v1 := table[val0&mask] - MOVW (R9)(R13*2), CX + MOVWQZX (R9)(R13*2), CX // br2.advance(uint8(v1.entry) MOVB CH, AH @@ -502,7 +502,7 @@ skip_fill2: SHRQ CL, R13 // v2 := table[val0&mask] - MOVW (R9)(R13*2), CX + MOVWQZX (R9)(R13*2), CX // br2.advance(uint8(v2.entry) MOVB CH, AH @@ -515,7 +515,7 @@ skip_fill2: SHRQ CL, R13 // v3 := table[val0&mask] - MOVW (R9)(R13*2), CX + MOVWQZX (R9)(R13*2), CX // br2.advance(uint8(v3.entry) MOVB CH, AL @@ -539,35 +539,35 @@ skip_fill2: MOVBQZX 184(R10), R12 CMPQ R12, $0x20 JBE skip_fill3 - MOVQ 168(R10), R13 + MOVQ 168(R10), AX SUBQ $0x20, R12 - SUBQ $0x04, R13 - MOVQ 144(R10), R14 + SUBQ $0x04, AX + MOVQ 144(R10), R13 // b.value |= uint64(low) << (b.bitsRead & 63) - MOVL (R13)(R14*1), R14 + MOVL (AX)(R13*1), R13 MOVQ R12, CX - SHLQ CL, R14 - MOVQ R13, 168(R10) - ORQ R14, R11 + SHLQ CL, R13 + MOVQ AX, 168(R10) + ORQ R13, R11 // exhausted += (br3.off < 4) - CMPQ R13, $0x04 + CMPQ AX, $0x04 ADCB $+0, DL skip_fill3: // val0 := br3.peekTopBits(peekBits) - MOVQ R11, R13 + MOVQ R11, AX MOVQ DI, CX - SHRQ CL, R13 + SHRQ CL, AX // v0 := table[val0&mask] - MOVW (R9)(R13*2), CX + MOVWQZX (R9)(AX*2), CX // br3.advance(uint8(v0.entry) - MOVB CH, AL - SHLQ CL, R11 - ADDB CL, R12 + MOVBLZX CH, AX + SHLQ CL, R11 + ADDB CL, R12 // val1 := br3.peekTopBits(peekBits) MOVQ R11, R13 @@ -575,7 +575,7 @@ skip_fill3: SHRQ CL, R13 // v1 := table[val0&mask] - MOVW (R9)(R13*2), CX + MOVWQZX (R9)(R13*2), CX // br3.advance(uint8(v1.entry) MOVB CH, AH @@ -589,7 +589,7 @@ skip_fill3: SHRQ CL, R13 // v2 := table[val0&mask] - MOVW (R9)(R13*2), CX + MOVWQZX (R9)(R13*2), CX // br3.advance(uint8(v2.entry) MOVB CH, AH @@ -602,7 +602,7 @@ skip_fill3: SHRQ CL, R13 // v3 := table[val0&mask] - MOVW (R9)(R13*2), CX + MOVWQZX (R9)(R13*2), CX // br3.advance(uint8(v3.entry) MOVB CH, AL @@ -667,7 +667,7 @@ bitReader_fillFast_1_end: MOVQ DI, CX MOVQ R10, R12 SHRQ CL, R12 - MOVW (SI)(R12*2), CX + MOVWQZX (SI)(R12*2), CX MOVB CH, AL MOVBQZX CL, CX ADDQ CX, R11 @@ -675,7 +675,7 @@ bitReader_fillFast_1_end: MOVQ DI, CX MOVQ R10, R12 SHRQ CL, R12 - MOVW (SI)(R12*2), CX + MOVWQZX (SI)(R12*2), CX MOVB CH, AH MOVBQZX CL, CX ADDQ CX, R11 @@ -694,7 +694,7 @@ bitReader_fillFast_2_end: MOVQ DI, CX MOVQ R10, R12 SHRQ CL, R12 - MOVW (SI)(R12*2), CX + MOVWQZX (SI)(R12*2), CX MOVB CH, AH MOVBQZX CL, CX ADDQ CX, R11 @@ -702,7 +702,7 @@ bitReader_fillFast_2_end: MOVQ DI, CX MOVQ R10, R12 SHRQ CL, R12 - MOVW (SI)(R12*2), CX + MOVWQZX (SI)(R12*2), CX MOVB CH, AL MOVBQZX CL, CX ADDQ CX, R11 @@ -769,13 +769,13 @@ main_loop: bitReader_fillFast_1_end: SHRXQ DI, R10, CX - MOVW (SI)(CX*2), CX + MOVWQZX (SI)(CX*2), CX MOVB CH, AL MOVBQZX CL, CX ADDQ CX, R11 SHLXQ CX, R10, R10 SHRXQ DI, R10, CX - MOVW (SI)(CX*2), CX + MOVWQZX (SI)(CX*2), CX MOVB CH, AH MOVBQZX CL, CX ADDQ CX, R11 @@ -791,13 +791,13 @@ bitReader_fillFast_1_end: bitReader_fillFast_2_end: SHRXQ DI, R10, CX - MOVW (SI)(CX*2), CX + MOVWQZX (SI)(CX*2), CX MOVB CH, AH MOVBQZX CL, CX ADDQ CX, R11 SHLXQ CX, R10, R10 SHRXQ DI, R10, CX - MOVW (SI)(CX*2), CX + MOVWQZX (SI)(CX*2), CX MOVB CH, AL MOVBQZX CL, CX ADDQ CX, R11 diff --git a/vendor/github.com/klauspost/compress/huff0/decompress_arm64.go b/vendor/github.com/klauspost/compress/huff0/decompress_arm64.go new file mode 100644 index 000000000..8ba3c810e --- /dev/null +++ b/vendor/github.com/klauspost/compress/huff0/decompress_arm64.go @@ -0,0 +1,37 @@ +//go:build arm64 && !appengine && !noasm && gc + +// arm64 stubs and dispatch for the asm loops used by decompress_asm.go. +// The asm (decompress_arm64.s) is generated by the avo arm64 lowering +// printer from the same source as the amd64 asm; see _generate/gen.go. +package huff0 + +// decompress4x_main_loop_arm64 is an arm64 assembler implementation +// of Decompress4X when tablelog > 8. +// +//go:noescape +func decompress4x_main_loop_arm64(ctx *decompress4xContext) + +// decompress4x_8b_main_loop_arm64 is an arm64 assembler implementation +// of Decompress4X when tablelog <= 8 which decodes 4 entries +// per loop. +// +//go:noescape +func decompress4x_8b_main_loop_arm64(ctx *decompress4xContext) + +// decompress1x_main_loop_arm64 is an arm64 assembler implementation +// of Decompress1X when tablelog > 8. +// +//go:noescape +func decompress1x_main_loop_arm64(ctx *decompress1xContext) + +func decompress4x_main_loop_asm(ctx *decompress4xContext) { + decompress4x_main_loop_arm64(ctx) +} + +func decompress4x_8b_main_loop_asm(ctx *decompress4xContext) { + decompress4x_8b_main_loop_arm64(ctx) +} + +func decompress1x_main_loop_asm(ctx *decompress1xContext) { + decompress1x_main_loop_arm64(ctx) +} diff --git a/vendor/github.com/klauspost/compress/huff0/decompress_arm64.s b/vendor/github.com/klauspost/compress/huff0/decompress_arm64.s new file mode 100644 index 000000000..357df28e9 --- /dev/null +++ b/vendor/github.com/klauspost/compress/huff0/decompress_arm64.s @@ -0,0 +1,796 @@ +// Code generated by command: go run gen.go -out ../decompress.s -arch amd64,arm64 -pkg=huff0. DO NOT EDIT. +// EXPERIMENTAL arm64 output lowered from an amd64 avo program. + +//go:build arm64 && (!appengine && !noasm && gc) + +// func decompress4x_main_loop_amd64(ctx *decompress4xContext) +TEXT ·decompress4x_main_loop_arm64(SB), $0-8 + // Preload values + MOVD ctx+0(FP), R0 + MOVBU 8(R0), R6 + MOVD 16(R0), R3 + MOVD 48(R0), R5 + MOVD 24(R0), R7 + MOVD 32(R0), R8 + MOVD (R0), R9 + + // Main loop +main_loop: + MOVD $0, R2 + CMP R5, R3 + CSET GE, R16 + BFI $0, R16, $8, R2 + + // br0.fillFast32() + MOVD 32(R9), R10 + MOVBU 40(R9), R11 + CMP $0x20, R11 + BLS skip_fill0 + MOVD 24(R9), R0 + SUB $0x20, R11, R11 + SUB $0x04, R0, R0 + MOVD (R9), R12 + + // b.value |= uint64(low) << (b.bitsRead & 63) + MOVWU (R0)(R12), R12 + MOVD R11, R1 + LSL R1, R12, R12 + MOVD R0, 24(R9) + ORR R12, R10, R10 + + // exhausted += (br0.off < 4) + CMP $0x04, R0 + CSINC HS, R2, R2, R16 + BFI $0, R16, $8, R2 + +skip_fill0: + // val0 := br0.peekTopBits(peekBits) + MOVD R10, R12 + MOVD R6, R1 + LSR R1, R12, R12 + + // v0 := table[val0&mask] + MOVHU (R8)(R12<<1), R1 + + // br0.advance(uint8(v0.entry) + UBFX $8, R1, $8, R0 + LSL R1, R10, R10 + ADD R1, R11, R15 + BFI $0, R15, $8, R11 + + // val1 := br0.peekTopBits(peekBits) + MOVD R6, R1 + MOVD R10, R12 + LSR R1, R12, R12 + + // v1 := table[val1&mask] + MOVHU (R8)(R12<<1), R1 + + // br0.advance(uint8(v1.entry)) + UBFX $8, R1, $8, R16 + BFI $8, R16, $8, R0 + LSL R1, R10, R10 + ADD R1, R11, R15 + BFI $0, R15, $8, R11 + + // these two writes get coalesced + // out[id * dstEvery + 0] = uint8(v0.entry >> 8) + // out[id * dstEvery + 1] = uint8(v1.entry >> 8) + MOVH R0, (R3) + + // update the bitreader structure + MOVD R10, 32(R9) + MOVB R11, 40(R9) + + // br1.fillFast32() + MOVD 80(R9), R10 + MOVBU 88(R9), R11 + CMP $0x20, R11 + BLS skip_fill1 + MOVD 72(R9), R0 + SUB $0x20, R11, R11 + SUB $0x04, R0, R0 + MOVD 48(R9), R12 + + // b.value |= uint64(low) << (b.bitsRead & 63) + MOVWU (R0)(R12), R12 + MOVD R11, R1 + LSL R1, R12, R12 + MOVD R0, 72(R9) + ORR R12, R10, R10 + + // exhausted += (br1.off < 4) + CMP $0x04, R0 + CSINC HS, R2, R2, R16 + BFI $0, R16, $8, R2 + +skip_fill1: + // val0 := br1.peekTopBits(peekBits) + MOVD R10, R12 + MOVD R6, R1 + LSR R1, R12, R12 + + // v0 := table[val0&mask] + MOVHU (R8)(R12<<1), R1 + + // br1.advance(uint8(v0.entry) + UBFX $8, R1, $8, R0 + LSL R1, R10, R10 + ADD R1, R11, R15 + BFI $0, R15, $8, R11 + + // val1 := br1.peekTopBits(peekBits) + MOVD R6, R1 + MOVD R10, R12 + LSR R1, R12, R12 + + // v1 := table[val1&mask] + MOVHU (R8)(R12<<1), R1 + + // br1.advance(uint8(v1.entry)) + UBFX $8, R1, $8, R16 + BFI $8, R16, $8, R0 + LSL R1, R10, R10 + ADD R1, R11, R15 + BFI $0, R15, $8, R11 + + // these two writes get coalesced + // out[id * dstEvery + 0] = uint8(v0.entry >> 8) + // out[id * dstEvery + 1] = uint8(v1.entry >> 8) + MOVH R0, (R3)(R7) + + // update the bitreader structure + MOVD R10, 80(R9) + MOVB R11, 88(R9) + + // br2.fillFast32() + MOVD 128(R9), R10 + MOVBU 136(R9), R11 + CMP $0x20, R11 + BLS skip_fill2 + MOVD 120(R9), R0 + SUB $0x20, R11, R11 + SUB $0x04, R0, R0 + MOVD 96(R9), R12 + + // b.value |= uint64(low) << (b.bitsRead & 63) + MOVWU (R0)(R12), R12 + MOVD R11, R1 + LSL R1, R12, R12 + MOVD R0, 120(R9) + ORR R12, R10, R10 + + // exhausted += (br2.off < 4) + CMP $0x04, R0 + CSINC HS, R2, R2, R16 + BFI $0, R16, $8, R2 + +skip_fill2: + // val0 := br2.peekTopBits(peekBits) + MOVD R10, R12 + MOVD R6, R1 + LSR R1, R12, R12 + + // v0 := table[val0&mask] + MOVHU (R8)(R12<<1), R1 + + // br2.advance(uint8(v0.entry) + UBFX $8, R1, $8, R0 + LSL R1, R10, R10 + ADD R1, R11, R15 + BFI $0, R15, $8, R11 + + // val1 := br2.peekTopBits(peekBits) + MOVD R6, R1 + MOVD R10, R12 + LSR R1, R12, R12 + + // v1 := table[val1&mask] + MOVHU (R8)(R12<<1), R1 + + // br2.advance(uint8(v1.entry)) + UBFX $8, R1, $8, R16 + BFI $8, R16, $8, R0 + LSL R1, R10, R10 + ADD R1, R11, R15 + BFI $0, R15, $8, R11 + + // these two writes get coalesced + // out[id * dstEvery + 0] = uint8(v0.entry >> 8) + // out[id * dstEvery + 1] = uint8(v1.entry >> 8) + MOVH R0, (R3)(R7<<1) + + // update the bitreader structure + MOVD R10, 128(R9) + MOVB R11, 136(R9) + + // br3.fillFast32() + MOVD 176(R9), R10 + MOVBU 184(R9), R11 + CMP $0x20, R11 + BLS skip_fill3 + MOVD 168(R9), R0 + SUB $0x20, R11, R11 + SUB $0x04, R0, R0 + MOVD 144(R9), R12 + + // b.value |= uint64(low) << (b.bitsRead & 63) + MOVWU (R0)(R12), R12 + MOVD R11, R1 + LSL R1, R12, R12 + MOVD R0, 168(R9) + ORR R12, R10, R10 + + // exhausted += (br3.off < 4) + CMP $0x04, R0 + CSINC HS, R2, R2, R16 + BFI $0, R16, $8, R2 + +skip_fill3: + // val0 := br3.peekTopBits(peekBits) + MOVD R10, R12 + MOVD R6, R1 + LSR R1, R12, R12 + + // v0 := table[val0&mask] + MOVHU (R8)(R12<<1), R1 + + // br3.advance(uint8(v0.entry) + UBFX $8, R1, $8, R0 + LSL R1, R10, R10 + ADD R1, R11, R15 + BFI $0, R15, $8, R11 + + // val1 := br3.peekTopBits(peekBits) + MOVD R6, R1 + MOVD R10, R12 + LSR R1, R12, R12 + + // v1 := table[val1&mask] + MOVHU (R8)(R12<<1), R1 + + // br3.advance(uint8(v1.entry)) + UBFX $8, R1, $8, R16 + BFI $8, R16, $8, R0 + LSL R1, R10, R10 + ADD R1, R11, R15 + BFI $0, R15, $8, R11 + + // these two writes get coalesced + // out[id * dstEvery + 0] = uint8(v0.entry >> 8) + // out[id * dstEvery + 1] = uint8(v1.entry >> 8) + ADD R7<<1, R7, R1 + MOVH R0, (R3)(R1) + + // update the bitreader structure + MOVD R10, 176(R9) + MOVB R11, 184(R9) + ADD $0x02, R3, R3 + TST $0xff, R2 + BEQ main_loop + MOVD ctx+0(FP), R0 + MOVD 16(R0), R16 + SUB R16, R3, R3 + LSL $0x02, R3, R3 + MOVD R3, 40(R0) + RET + +// func decompress4x_8b_main_loop_amd64(ctx *decompress4xContext) +TEXT ·decompress4x_8b_main_loop_arm64(SB), $0-8 + // Preload values + MOVD ctx+0(FP), R0 + MOVBU 8(R0), R6 + MOVD 16(R0), R3 + MOVD 48(R0), R5 + MOVD 24(R0), R7 + MOVD 32(R0), R8 + MOVD (R0), R9 + + // Main loop +main_loop: + MOVD $0, R2 + CMP R5, R3 + CSET GE, R16 + BFI $0, R16, $8, R2 + + // br0.fillFast32() + MOVD 32(R9), R10 + MOVBU 40(R9), R11 + CMP $0x20, R11 + BLS skip_fill0 + MOVD 24(R9), R0 + SUB $0x20, R11, R11 + SUB $0x04, R0, R0 + MOVD (R9), R12 + + // b.value |= uint64(low) << (b.bitsRead & 63) + MOVWU (R0)(R12), R12 + MOVD R11, R1 + LSL R1, R12, R12 + MOVD R0, 24(R9) + ORR R12, R10, R10 + + // exhausted += (br0.off < 4) + CMP $0x04, R0 + CSINC HS, R2, R2, R16 + BFI $0, R16, $8, R2 + +skip_fill0: + // val0 := br0.peekTopBits(peekBits) + MOVD R10, R0 + MOVD R6, R1 + LSR R1, R0, R0 + + // v0 := table[val0&mask] + MOVHU (R8)(R0<<1), R1 + + // br0.advance(uint8(v0.entry) + UBFX $8, R1, $8, R0 + LSL R1, R10, R10 + ADD R1, R11, R15 + BFI $0, R15, $8, R11 + + // val1 := br0.peekTopBits(peekBits) + MOVD R10, R12 + MOVD R6, R1 + LSR R1, R12, R12 + + // v1 := table[val0&mask] + MOVHU (R8)(R12<<1), R1 + + // br0.advance(uint8(v1.entry) + UBFX $8, R1, $8, R16 + BFI $8, R16, $8, R0 + LSL R1, R10, R10 + ADD R1, R11, R15 + BFI $0, R15, $8, R11 + REVW R0, R0 + + // val2 := br0.peekTopBits(peekBits) + MOVD R10, R12 + MOVD R6, R1 + LSR R1, R12, R12 + + // v2 := table[val0&mask] + MOVHU (R8)(R12<<1), R1 + + // br0.advance(uint8(v2.entry) + UBFX $8, R1, $8, R16 + BFI $8, R16, $8, R0 + LSL R1, R10, R10 + ADD R1, R11, R15 + BFI $0, R15, $8, R11 + + // val3 := br0.peekTopBits(peekBits) + MOVD R10, R12 + MOVD R6, R1 + LSR R1, R12, R12 + + // v3 := table[val0&mask] + MOVHU (R8)(R12<<1), R1 + + // br0.advance(uint8(v3.entry) + UBFX $8, R1, $8, R16 + BFI $0, R16, $8, R0 + LSL R1, R10, R10 + ADD R1, R11, R15 + BFI $0, R15, $8, R11 + REVW R0, R0 + + // these four writes get coalesced + // out[id * dstEvery + 0] = uint8(v0.entry >> 8) + // out[id * dstEvery + 1] = uint8(v1.entry >> 8) + // out[id * dstEvery + 3] = uint8(v2.entry >> 8) + // out[id * dstEvery + 4] = uint8(v3.entry >> 8) + MOVW R0, (R3) + + // update the bitreader structure + MOVD R10, 32(R9) + MOVB R11, 40(R9) + + // br1.fillFast32() + MOVD 80(R9), R10 + MOVBU 88(R9), R11 + CMP $0x20, R11 + BLS skip_fill1 + MOVD 72(R9), R0 + SUB $0x20, R11, R11 + SUB $0x04, R0, R0 + MOVD 48(R9), R12 + + // b.value |= uint64(low) << (b.bitsRead & 63) + MOVWU (R0)(R12), R12 + MOVD R11, R1 + LSL R1, R12, R12 + MOVD R0, 72(R9) + ORR R12, R10, R10 + + // exhausted += (br1.off < 4) + CMP $0x04, R0 + CSINC HS, R2, R2, R16 + BFI $0, R16, $8, R2 + +skip_fill1: + // val0 := br1.peekTopBits(peekBits) + MOVD R10, R0 + MOVD R6, R1 + LSR R1, R0, R0 + + // v0 := table[val0&mask] + MOVHU (R8)(R0<<1), R1 + + // br1.advance(uint8(v0.entry) + UBFX $8, R1, $8, R0 + LSL R1, R10, R10 + ADD R1, R11, R15 + BFI $0, R15, $8, R11 + + // val1 := br1.peekTopBits(peekBits) + MOVD R10, R12 + MOVD R6, R1 + LSR R1, R12, R12 + + // v1 := table[val0&mask] + MOVHU (R8)(R12<<1), R1 + + // br1.advance(uint8(v1.entry) + UBFX $8, R1, $8, R16 + BFI $8, R16, $8, R0 + LSL R1, R10, R10 + ADD R1, R11, R15 + BFI $0, R15, $8, R11 + REVW R0, R0 + + // val2 := br1.peekTopBits(peekBits) + MOVD R10, R12 + MOVD R6, R1 + LSR R1, R12, R12 + + // v2 := table[val0&mask] + MOVHU (R8)(R12<<1), R1 + + // br1.advance(uint8(v2.entry) + UBFX $8, R1, $8, R16 + BFI $8, R16, $8, R0 + LSL R1, R10, R10 + ADD R1, R11, R15 + BFI $0, R15, $8, R11 + + // val3 := br1.peekTopBits(peekBits) + MOVD R10, R12 + MOVD R6, R1 + LSR R1, R12, R12 + + // v3 := table[val0&mask] + MOVHU (R8)(R12<<1), R1 + + // br1.advance(uint8(v3.entry) + UBFX $8, R1, $8, R16 + BFI $0, R16, $8, R0 + LSL R1, R10, R10 + ADD R1, R11, R15 + BFI $0, R15, $8, R11 + REVW R0, R0 + + // these four writes get coalesced + // out[id * dstEvery + 0] = uint8(v0.entry >> 8) + // out[id * dstEvery + 1] = uint8(v1.entry >> 8) + // out[id * dstEvery + 3] = uint8(v2.entry >> 8) + // out[id * dstEvery + 4] = uint8(v3.entry >> 8) + MOVW R0, (R3)(R7) + + // update the bitreader structure + MOVD R10, 80(R9) + MOVB R11, 88(R9) + + // br2.fillFast32() + MOVD 128(R9), R10 + MOVBU 136(R9), R11 + CMP $0x20, R11 + BLS skip_fill2 + MOVD 120(R9), R0 + SUB $0x20, R11, R11 + SUB $0x04, R0, R0 + MOVD 96(R9), R12 + + // b.value |= uint64(low) << (b.bitsRead & 63) + MOVWU (R0)(R12), R12 + MOVD R11, R1 + LSL R1, R12, R12 + MOVD R0, 120(R9) + ORR R12, R10, R10 + + // exhausted += (br2.off < 4) + CMP $0x04, R0 + CSINC HS, R2, R2, R16 + BFI $0, R16, $8, R2 + +skip_fill2: + // val0 := br2.peekTopBits(peekBits) + MOVD R10, R0 + MOVD R6, R1 + LSR R1, R0, R0 + + // v0 := table[val0&mask] + MOVHU (R8)(R0<<1), R1 + + // br2.advance(uint8(v0.entry) + UBFX $8, R1, $8, R0 + LSL R1, R10, R10 + ADD R1, R11, R15 + BFI $0, R15, $8, R11 + + // val1 := br2.peekTopBits(peekBits) + MOVD R10, R12 + MOVD R6, R1 + LSR R1, R12, R12 + + // v1 := table[val0&mask] + MOVHU (R8)(R12<<1), R1 + + // br2.advance(uint8(v1.entry) + UBFX $8, R1, $8, R16 + BFI $8, R16, $8, R0 + LSL R1, R10, R10 + ADD R1, R11, R15 + BFI $0, R15, $8, R11 + REVW R0, R0 + + // val2 := br2.peekTopBits(peekBits) + MOVD R10, R12 + MOVD R6, R1 + LSR R1, R12, R12 + + // v2 := table[val0&mask] + MOVHU (R8)(R12<<1), R1 + + // br2.advance(uint8(v2.entry) + UBFX $8, R1, $8, R16 + BFI $8, R16, $8, R0 + LSL R1, R10, R10 + ADD R1, R11, R15 + BFI $0, R15, $8, R11 + + // val3 := br2.peekTopBits(peekBits) + MOVD R10, R12 + MOVD R6, R1 + LSR R1, R12, R12 + + // v3 := table[val0&mask] + MOVHU (R8)(R12<<1), R1 + + // br2.advance(uint8(v3.entry) + UBFX $8, R1, $8, R16 + BFI $0, R16, $8, R0 + LSL R1, R10, R10 + ADD R1, R11, R15 + BFI $0, R15, $8, R11 + REVW R0, R0 + + // these four writes get coalesced + // out[id * dstEvery + 0] = uint8(v0.entry >> 8) + // out[id * dstEvery + 1] = uint8(v1.entry >> 8) + // out[id * dstEvery + 3] = uint8(v2.entry >> 8) + // out[id * dstEvery + 4] = uint8(v3.entry >> 8) + ADD R7<<1, R3, R15 + MOVW R0, (R15) + + // update the bitreader structure + MOVD R10, 128(R9) + MOVB R11, 136(R9) + + // br3.fillFast32() + MOVD 176(R9), R10 + MOVBU 184(R9), R11 + CMP $0x20, R11 + BLS skip_fill3 + MOVD 168(R9), R0 + SUB $0x20, R11, R11 + SUB $0x04, R0, R0 + MOVD 144(R9), R12 + + // b.value |= uint64(low) << (b.bitsRead & 63) + MOVWU (R0)(R12), R12 + MOVD R11, R1 + LSL R1, R12, R12 + MOVD R0, 168(R9) + ORR R12, R10, R10 + + // exhausted += (br3.off < 4) + CMP $0x04, R0 + CSINC HS, R2, R2, R16 + BFI $0, R16, $8, R2 + +skip_fill3: + // val0 := br3.peekTopBits(peekBits) + MOVD R10, R0 + MOVD R6, R1 + LSR R1, R0, R0 + + // v0 := table[val0&mask] + MOVHU (R8)(R0<<1), R1 + + // br3.advance(uint8(v0.entry) + UBFX $8, R1, $8, R0 + LSL R1, R10, R10 + ADD R1, R11, R15 + BFI $0, R15, $8, R11 + + // val1 := br3.peekTopBits(peekBits) + MOVD R10, R12 + MOVD R6, R1 + LSR R1, R12, R12 + + // v1 := table[val0&mask] + MOVHU (R8)(R12<<1), R1 + + // br3.advance(uint8(v1.entry) + UBFX $8, R1, $8, R16 + BFI $8, R16, $8, R0 + LSL R1, R10, R10 + ADD R1, R11, R15 + BFI $0, R15, $8, R11 + REVW R0, R0 + + // val2 := br3.peekTopBits(peekBits) + MOVD R10, R12 + MOVD R6, R1 + LSR R1, R12, R12 + + // v2 := table[val0&mask] + MOVHU (R8)(R12<<1), R1 + + // br3.advance(uint8(v2.entry) + UBFX $8, R1, $8, R16 + BFI $8, R16, $8, R0 + LSL R1, R10, R10 + ADD R1, R11, R15 + BFI $0, R15, $8, R11 + + // val3 := br3.peekTopBits(peekBits) + MOVD R10, R12 + MOVD R6, R1 + LSR R1, R12, R12 + + // v3 := table[val0&mask] + MOVHU (R8)(R12<<1), R1 + + // br3.advance(uint8(v3.entry) + UBFX $8, R1, $8, R16 + BFI $0, R16, $8, R0 + LSL R1, R10, R10 + ADD R1, R11, R15 + BFI $0, R15, $8, R11 + REVW R0, R0 + + // these four writes get coalesced + // out[id * dstEvery + 0] = uint8(v0.entry >> 8) + // out[id * dstEvery + 1] = uint8(v1.entry >> 8) + // out[id * dstEvery + 3] = uint8(v2.entry >> 8) + // out[id * dstEvery + 4] = uint8(v3.entry >> 8) + ADD R7<<1, R7, R1 + MOVW R0, (R3)(R1) + + // update the bitreader structure + MOVD R10, 176(R9) + MOVB R11, 184(R9) + ADD $0x04, R3, R3 + TST $0xff, R2 + BEQ main_loop + MOVD ctx+0(FP), R0 + MOVD 16(R0), R16 + SUB R16, R3, R3 + LSL $0x02, R3, R3 + MOVD R3, 40(R0) + RET + +// func decompress1x_main_loop_amd64(ctx *decompress1xContext) +TEXT ·decompress1x_main_loop_arm64(SB), $0-8 + MOVD ctx+0(FP), R1 + MOVD 16(R1), R2 + MOVD 24(R1), R3 + CMP $0x04, R3 + BLO error_max_decoded_size_exceeded + ADD R3, R2, R3 + MOVD (R1), R5 + MOVD (R5), R7 + MOVD 24(R5), R8 + MOVD 32(R5), R9 + MOVBU 40(R5), R10 + MOVD 32(R1), R5 + MOVBU 8(R1), R6 + JMP loop_condition + +main_loop: + // Check if we have room for 4 bytes in the output buffer + ADD $4, R2, R1 + CMP R3, R1 + BGE error_max_decoded_size_exceeded + + // Decode 4 values + CMP $0x20, R10 + BLT bitReader_fillFast_1_end + SUB $0x20, R10, R10 + SUB $0x04, R8, R8 + MOVWU (R7)(R8), R11 + MOVD R10, R1 + LSL R1, R11, R11 + ORR R11, R9, R9 + +bitReader_fillFast_1_end: + MOVD R6, R1 + MOVD R9, R11 + LSR R1, R11, R11 + MOVHU (R5)(R11<<1), R1 + UBFX $8, R1, $8, R16 + BFI $0, R16, $8, R0 + MOVBU R1, R1 + ADD R1, R10, R10 + LSL R1, R9, R9 + MOVD R6, R1 + MOVD R9, R11 + LSR R1, R11, R11 + MOVHU (R5)(R11<<1), R1 + UBFX $8, R1, $8, R16 + BFI $8, R16, $8, R0 + MOVBU R1, R1 + ADD R1, R10, R10 + LSL R1, R9, R9 + REVW R0, R0 + CMP $0x20, R10 + BLT bitReader_fillFast_2_end + SUB $0x20, R10, R10 + SUB $0x04, R8, R8 + MOVWU (R7)(R8), R11 + MOVD R10, R1 + LSL R1, R11, R11 + ORR R11, R9, R9 + +bitReader_fillFast_2_end: + MOVD R6, R1 + MOVD R9, R11 + LSR R1, R11, R11 + MOVHU (R5)(R11<<1), R1 + UBFX $8, R1, $8, R16 + BFI $8, R16, $8, R0 + MOVBU R1, R1 + ADD R1, R10, R10 + LSL R1, R9, R9 + MOVD R6, R1 + MOVD R9, R11 + LSR R1, R11, R11 + MOVHU (R5)(R11<<1), R1 + UBFX $8, R1, $8, R16 + BFI $0, R16, $8, R0 + MOVBU R1, R1 + ADD R1, R10, R10 + LSL R1, R9, R9 + REVW R0, R0 + + // Store the decoded values + MOVW R0, (R2) + ADD $0x04, R2, R2 + +loop_condition: + CMP $0x08, R8 + BGE main_loop + + // Update ctx structure + MOVD ctx+0(FP), R0 + MOVD 16(R0), R16 + SUB R16, R2, R2 + MOVD R2, 40(R0) + MOVD (R0), R0 + MOVD R8, 24(R0) + MOVD R9, 32(R0) + MOVB R10, 40(R0) + RET + + // Report error +error_max_decoded_size_exceeded: + MOVD ctx+0(FP), R0 + MOVD $-1, R1 + MOVD R1, 40(R0) + RET + +// skipped decompress1x_main_loop_bmi2 (generic twin preferred on arm64) diff --git a/vendor/github.com/klauspost/compress/huff0/decompress_asm.go b/vendor/github.com/klauspost/compress/huff0/decompress_asm.go new file mode 100644 index 000000000..4854dd436 --- /dev/null +++ b/vendor/github.com/klauspost/compress/huff0/decompress_asm.go @@ -0,0 +1,193 @@ +//go:build (amd64 || arm64) && !appengine && !noasm && gc + +// This file contains the specialisation of Decoder.Decompress4X +// and Decoder.Decompress1X that use an asm implementation of their main loops. +// The asm function stubs and any per-arch dispatch live in decompress_amd64.go +// and decompress_arm64.go. +package huff0 + +import ( + "errors" + "fmt" +) + +// fallback8BitSize is the size where using Go version is faster. +const fallback8BitSize = 800 + +type decompress4xContext struct { + pbr *[4]bitReaderShifted + peekBits uint8 + out *byte + dstEvery int + tbl *dEntrySingle + decoded int + limit *byte +} + +// Decompress4X will decompress a 4X encoded stream. +// The length of the supplied input must match the end of a block exactly. +// The *capacity* of the dst slice must match the destination size of +// the uncompressed data exactly. +func (d *Decoder) Decompress4X(dst, src []byte) ([]byte, error) { + if len(d.dt.single) == 0 { + return nil, errors.New("no table loaded") + } + if len(src) < 6+(4*1) { + return nil, errors.New("input too small") + } + + use8BitTables := d.actualTableLog <= 8 + if cap(dst) < fallback8BitSize && use8BitTables { + return d.decompress4X8bit(dst, src) + } + + var br [4]bitReaderShifted + // Decode "jump table" + start := 6 + for i := range 3 { + length := int(src[i*2]) | (int(src[i*2+1]) << 8) + if start+length >= len(src) { + return nil, errors.New("truncated input (or invalid offset)") + } + err := br[i].init(src[start : start+length]) + if err != nil { + return nil, err + } + start += length + } + err := br[3].init(src[start:]) + if err != nil { + return nil, err + } + + // destination, offset to match first output + dstSize := cap(dst) + dst = dst[:dstSize] + out := dst + dstEvery := (dstSize + 3) / 4 + + const tlSize = 1 << tableLogMax + const tlMask = tlSize - 1 + single := d.dt.single[:tlSize] + + var decoded int + + if len(out) > 4*4 && !(br[0].off < 4 || br[1].off < 4 || br[2].off < 4 || br[3].off < 4) { + ctx := decompress4xContext{ + pbr: &br, + peekBits: uint8((64 - d.actualTableLog) & 63), // see: bitReaderShifted.peekBitsFast() + out: &out[0], + dstEvery: dstEvery, + tbl: &single[0], + limit: &out[dstEvery-4], // Always stop decoding when first buffer gets here to avoid writing OOB on last. + } + if use8BitTables { + decompress4x_8b_main_loop_asm(&ctx) + } else { + decompress4x_main_loop_asm(&ctx) + } + + decoded = ctx.decoded + out = out[decoded/4:] + } + + // Decode remaining. + remainBytes := dstEvery - (decoded / 4) + for i := range br { + offset := dstEvery * i + endsAt := min(offset+remainBytes, len(out)) + br := &br[i] + bitsLeft := br.remaining() + for bitsLeft > 0 { + br.fill() + if offset >= endsAt { + return nil, errors.New("corruption detected: stream overrun 4") + } + + // Read value and increment offset. + val := br.peekBitsFast(d.actualTableLog) + v := single[val&tlMask].entry + nBits := uint8(v) + br.advance(nBits) + bitsLeft -= uint(nBits) + out[offset] = uint8(v >> 8) + offset++ + } + if offset != endsAt { + return nil, fmt.Errorf("corruption detected: short output block %d, end %d != %d", i, offset, endsAt) + } + decoded += offset - dstEvery*i + err = br.close() + if err != nil { + return nil, err + } + } + if dstSize != decoded { + return nil, errors.New("corruption detected: short output block") + } + return dst, nil +} + +type decompress1xContext struct { + pbr *bitReaderShifted + peekBits uint8 + out *byte + outCap int + tbl *dEntrySingle + decoded int +} + +// Error reported by asm implementations +const error_max_decoded_size_exeeded = -1 + +// Decompress1X will decompress a 1X encoded stream. +// The cap of the output buffer will be the maximum decompressed size. +// The length of the supplied input must match the end of a block exactly. +func (d *Decoder) Decompress1X(dst, src []byte) ([]byte, error) { + if len(d.dt.single) == 0 { + return nil, errors.New("no table loaded") + } + var br bitReaderShifted + err := br.init(src) + if err != nil { + return dst, err + } + maxDecodedSize := cap(dst) + dst = dst[:maxDecodedSize] + + const tlSize = 1 << tableLogMax + const tlMask = tlSize - 1 + + if maxDecodedSize >= 4 { + ctx := decompress1xContext{ + pbr: &br, + out: &dst[0], + outCap: maxDecodedSize, + peekBits: uint8((64 - d.actualTableLog) & 63), // see: bitReaderShifted.peekBitsFast() + tbl: &d.dt.single[0], + } + + decompress1x_main_loop_asm(&ctx) + if ctx.decoded == error_max_decoded_size_exeeded { + return nil, ErrMaxDecodedSizeExceeded + } + + dst = dst[:ctx.decoded] + } + + // br < 8, so uint8 is fine + bitsLeft := uint8(br.off)*8 + 64 - br.bitsRead + for bitsLeft > 0 { + br.fill() + if len(dst) >= maxDecodedSize { + br.close() + return nil, ErrMaxDecodedSizeExceeded + } + v := d.dt.single[br.peekBitsFast(d.actualTableLog)&tlMask] + nBits := uint8(v.entry) + br.advance(nBits) + bitsLeft -= nBits + dst = append(dst, uint8(v.entry>>8)) + } + return dst, br.close() +} diff --git a/vendor/github.com/klauspost/compress/huff0/decompress_generic.go b/vendor/github.com/klauspost/compress/huff0/decompress_generic.go index 610392322..e1bca5c68 100644 --- a/vendor/github.com/klauspost/compress/huff0/decompress_generic.go +++ b/vendor/github.com/klauspost/compress/huff0/decompress_generic.go @@ -1,4 +1,4 @@ -//go:build !amd64 || appengine || !gc || noasm +//go:build (!amd64 && !arm64) || appengine || !gc || noasm // This file contains a generic implementation of Decoder.Decompress4X. package huff0 diff --git a/vendor/github.com/klauspost/compress/internal/regmask/regmask.go b/vendor/github.com/klauspost/compress/internal/regmask/regmask.go new file mode 100644 index 000000000..3da49d154 --- /dev/null +++ b/vendor/github.com/klauspost/compress/internal/regmask/regmask.go @@ -0,0 +1,50 @@ +//go:build !386 + +// Package regmask provides masks for variable shift counts. +// +// Go defines a shift by more than the width of the shifted value as producing +// zero, so the compiler has to guard every variable shift against that: on +// amd64 with a CMP and an SBB, on arm64 with a CMP and a CSEL, and so on. When +// the count is known to be smaller than the width anyway, masking it with the +// width minus one lets the compiler drop the guard. The mask itself costs +// nothing on the architectures whose shift instructions already use only the +// low bits of the count, which the compiler knows about. +// +// Each constant is named for the width of the value being shifted and the type +// of the shift count, and may only be used where the count is always smaller +// than that width: +// +// x := y >> (n & regmask.Shift64ByUint) // y is 64 bits, n is a uint below 64 +package regmask + +const ( + // ShiftNByUint8 - shifting an N bit value by a uint8 + Shift8ByUint8 = 7 + Shift16ByUint8 = 15 + Shift32ByUint8 = 31 + Shift64ByUint8 = 63 + + // ShiftNByUint16 - shifting an N bit value by a uint16 + Shift8ByUint16 = Shift8ByUint8 + Shift16ByUint16 = Shift16ByUint8 + Shift32ByUint16 = Shift32ByUint8 + Shift64ByUint16 = Shift64ByUint8 + + // ShiftNByUint32 - shifting an N bit value by a uint32 + Shift8ByUint32 = Shift8ByUint8 + Shift16ByUint32 = Shift16ByUint8 + Shift32ByUint32 = Shift32ByUint8 + Shift64ByUint32 = Shift64ByUint8 + + // ShiftNByUint64 - shifting an N bit value by a uint64 + Shift8ByUint64 = Shift8ByUint8 + Shift16ByUint64 = Shift16ByUint8 + Shift32ByUint64 = Shift32ByUint8 + Shift64ByUint64 = Shift64ByUint8 + + // ShiftNByUint - shifting an N bit value by a uint + Shift8ByUint = Shift8ByUint8 + Shift16ByUint = Shift16ByUint8 + Shift32ByUint = Shift32ByUint8 + Shift64ByUint = Shift64ByUint8 +) diff --git a/vendor/github.com/klauspost/compress/internal/regmask/regmask_386.go b/vendor/github.com/klauspost/compress/internal/regmask/regmask_386.go new file mode 100644 index 000000000..ff15f7c1a --- /dev/null +++ b/vendor/github.com/klauspost/compress/internal/regmask/regmask_386.go @@ -0,0 +1,39 @@ +//go:build 386 + +package regmask + +// A 64 bit shift on 386 is synthesized from 32 bit instructions, and masking its +// count makes the compiler emit more code rather than less, so those masks are +// no-ops here: each is the largest value its count type can hold, which the +// compiler folds away. Shifts of narrower values behave as elsewhere. +const ( + // ShiftNByUint8 - shifting an N bit value by a uint8 + Shift8ByUint8 = 7 + Shift16ByUint8 = 15 + Shift32ByUint8 = 31 + Shift64ByUint8 = 0xff + + // ShiftNByUint16 - shifting an N bit value by a uint16 + Shift8ByUint16 = Shift8ByUint8 + Shift16ByUint16 = Shift16ByUint8 + Shift32ByUint16 = Shift32ByUint8 + Shift64ByUint16 = 0xffff + + // ShiftNByUint32 - shifting an N bit value by a uint32 + Shift8ByUint32 = Shift8ByUint8 + Shift16ByUint32 = Shift16ByUint8 + Shift32ByUint32 = Shift32ByUint8 + Shift64ByUint32 = 0xffffffff + + // ShiftNByUint64 - shifting an N bit value by a uint64 + Shift8ByUint64 = Shift8ByUint8 + Shift16ByUint64 = Shift16ByUint8 + Shift32ByUint64 = Shift32ByUint8 + Shift64ByUint64 = 0xffffffffffffffff + + // ShiftNByUint - shifting an N bit value by a uint + Shift8ByUint = Shift8ByUint8 + Shift16ByUint = Shift16ByUint8 + Shift32ByUint = Shift32ByUint8 + Shift64ByUint = ^uint(0) +) diff --git a/vendor/github.com/klauspost/compress/s2/encode_amd64.go b/vendor/github.com/klauspost/compress/s2/encode_asm.go similarity index 98% rename from vendor/github.com/klauspost/compress/s2/encode_amd64.go rename to vendor/github.com/klauspost/compress/s2/encode_asm.go index 68d72a41d..eee24e721 100644 --- a/vendor/github.com/klauspost/compress/s2/encode_amd64.go +++ b/vendor/github.com/klauspost/compress/s2/encode_asm.go @@ -1,4 +1,4 @@ -//go:build !appengine && !noasm && gc +//go:build (amd64 || arm64) && !appengine && !noasm && gc package s2 @@ -8,7 +8,7 @@ import ( "github.com/klauspost/compress/internal/race" ) -const hasAmd64Asm = true +const hasAsm = true var encPools [4]sync.Pool diff --git a/vendor/github.com/klauspost/compress/s2/encode_better.go b/vendor/github.com/klauspost/compress/s2/encode_better.go index adbc57c4d..2509d1c99 100644 --- a/vendor/github.com/klauspost/compress/s2/encode_better.go +++ b/vendor/github.com/klauspost/compress/s2/encode_better.go @@ -86,12 +86,18 @@ func encodeBlockBetterGo(dst, src []byte) (d int) { // We initialize repeat to 0, so we never match on first attempt repeat := 0 + // Cap the adaptive skip, as encodeBetterBlockAsm and the snappy Go encoder + // below already do. Without a cap, a long stretch with no matches lets the + // skip grow geometrically until it strides past the start of the next + // compressible region and loses the matches there. + const maxSkip = 100 + for { candidateL := 0 nextS := 0 for { // Next src position to check - nextS = s + (s-nextEmit)>>7 + 1 + nextS = s + min((s-nextEmit)>>7+1, maxSkip) if nextS > sLimit { goto emitRemainder } diff --git a/vendor/github.com/klauspost/compress/s2/encode_go.go b/vendor/github.com/klauspost/compress/s2/encode_go.go index 5597f3ef2..0270d33bc 100644 --- a/vendor/github.com/klauspost/compress/s2/encode_go.go +++ b/vendor/github.com/klauspost/compress/s2/encode_go.go @@ -1,4 +1,4 @@ -//go:build !amd64 || appengine || !gc || noasm +//go:build (!amd64 && !arm64) || appengine || !gc || noasm package s2 @@ -7,7 +7,7 @@ import ( "math/bits" ) -const hasAmd64Asm = false +const hasAsm = false // encodeBlock encodes a non-empty src to a guaranteed-large-enough dst. It // assumes that the varint-encoded length of the decompressed bytes has already diff --git a/vendor/github.com/klauspost/compress/s2/encodeblock_amd64.s b/vendor/github.com/klauspost/compress/s2/encodeblock_amd64.s index df9be687b..92a177564 100644 --- a/vendor/github.com/klauspost/compress/s2/encodeblock_amd64.s +++ b/vendor/github.com/klauspost/compress/s2/encodeblock_amd64.s @@ -1,6 +1,6 @@ -// Code generated by command: go run gen.go -out ../encodeblock_amd64.s -stubs ../encodeblock_amd64.go -pkg=s2. DO NOT EDIT. +// Code generated by command: go run gen.go -out ../encodeblock_amd64.s -stubs ../encodeblock_asm.go -pkg=s2. DO NOT EDIT. -//go:build !appengine && !noasm && gc && !noasm +//go:build (amd64 || arm64) && !appengine && !noasm && gc && !noasm #include "textflag.h" @@ -274,16 +274,10 @@ matchlen_loopback_16_repeat_extend_encodeBlockAsm: JMP matchlen_loopback_16_repeat_extend_encodeBlockAsm matchlen_bsf_16repeat_extend_encodeBlockAsm: -#ifdef GOAMD64_v3 TZCNTQ R13, R13 - -#else - BSFQ R13, R13 - -#endif - SARQ $0x03, R13 - LEAL 8(R12)(R13*1), R12 - JMP repeat_extend_forward_end_encodeBlockAsm + SARQ $0x03, R13 + LEAL 8(R12)(R13*1), R12 + JMP repeat_extend_forward_end_encodeBlockAsm matchlen_match8_repeat_extend_encodeBlockAsm: CMPL R9, $0x08 @@ -296,16 +290,10 @@ matchlen_match8_repeat_extend_encodeBlockAsm: JMP matchlen_match4_repeat_extend_encodeBlockAsm matchlen_bsf_8_repeat_extend_encodeBlockAsm: -#ifdef GOAMD64_v3 TZCNTQ R11, R11 - -#else - BSFQ R11, R11 - -#endif - SARQ $0x03, R11 - LEAL (R12)(R11*1), R12 - JMP repeat_extend_forward_end_encodeBlockAsm + SARQ $0x03, R11 + LEAL (R12)(R11*1), R12 + JMP repeat_extend_forward_end_encodeBlockAsm matchlen_match4_repeat_extend_encodeBlockAsm: CMPL R9, $0x04 @@ -898,16 +886,10 @@ matchlen_loopback_16_match_nolit_encodeBlockAsm: JMP matchlen_loopback_16_match_nolit_encodeBlockAsm matchlen_bsf_16match_nolit_encodeBlockAsm: -#ifdef GOAMD64_v3 TZCNTQ R11, R11 - -#else - BSFQ R11, R11 - -#endif - SARQ $0x03, R11 - LEAL 8(R10)(R11*1), R10 - JMP match_nolit_end_encodeBlockAsm + SARQ $0x03, R11 + LEAL 8(R10)(R11*1), R10 + JMP match_nolit_end_encodeBlockAsm matchlen_match8_match_nolit_encodeBlockAsm: CMPL DI, $0x08 @@ -920,16 +902,10 @@ matchlen_match8_match_nolit_encodeBlockAsm: JMP matchlen_match4_match_nolit_encodeBlockAsm matchlen_bsf_8_match_nolit_encodeBlockAsm: -#ifdef GOAMD64_v3 TZCNTQ R9, R9 - -#else - BSFQ R9, R9 - -#endif - SARQ $0x03, R9 - LEAL (R10)(R9*1), R10 - JMP match_nolit_end_encodeBlockAsm + SARQ $0x03, R9 + LEAL (R10)(R9*1), R10 + JMP match_nolit_end_encodeBlockAsm matchlen_match4_match_nolit_encodeBlockAsm: CMPL DI, $0x04 @@ -1689,16 +1665,10 @@ matchlen_loopback_16_repeat_extend_encodeBlockAsm4MB: JMP matchlen_loopback_16_repeat_extend_encodeBlockAsm4MB matchlen_bsf_16repeat_extend_encodeBlockAsm4MB: -#ifdef GOAMD64_v3 TZCNTQ R13, R13 - -#else - BSFQ R13, R13 - -#endif - SARQ $0x03, R13 - LEAL 8(R12)(R13*1), R12 - JMP repeat_extend_forward_end_encodeBlockAsm4MB + SARQ $0x03, R13 + LEAL 8(R12)(R13*1), R12 + JMP repeat_extend_forward_end_encodeBlockAsm4MB matchlen_match8_repeat_extend_encodeBlockAsm4MB: CMPL R9, $0x08 @@ -1711,16 +1681,10 @@ matchlen_match8_repeat_extend_encodeBlockAsm4MB: JMP matchlen_match4_repeat_extend_encodeBlockAsm4MB matchlen_bsf_8_repeat_extend_encodeBlockAsm4MB: -#ifdef GOAMD64_v3 TZCNTQ R11, R11 - -#else - BSFQ R11, R11 - -#endif - SARQ $0x03, R11 - LEAL (R12)(R11*1), R12 - JMP repeat_extend_forward_end_encodeBlockAsm4MB + SARQ $0x03, R11 + LEAL (R12)(R11*1), R12 + JMP repeat_extend_forward_end_encodeBlockAsm4MB matchlen_match4_repeat_extend_encodeBlockAsm4MB: CMPL R9, $0x04 @@ -2263,16 +2227,10 @@ matchlen_loopback_16_match_nolit_encodeBlockAsm4MB: JMP matchlen_loopback_16_match_nolit_encodeBlockAsm4MB matchlen_bsf_16match_nolit_encodeBlockAsm4MB: -#ifdef GOAMD64_v3 TZCNTQ R11, R11 - -#else - BSFQ R11, R11 - -#endif - SARQ $0x03, R11 - LEAL 8(R10)(R11*1), R10 - JMP match_nolit_end_encodeBlockAsm4MB + SARQ $0x03, R11 + LEAL 8(R10)(R11*1), R10 + JMP match_nolit_end_encodeBlockAsm4MB matchlen_match8_match_nolit_encodeBlockAsm4MB: CMPL DI, $0x08 @@ -2285,16 +2243,10 @@ matchlen_match8_match_nolit_encodeBlockAsm4MB: JMP matchlen_match4_match_nolit_encodeBlockAsm4MB matchlen_bsf_8_match_nolit_encodeBlockAsm4MB: -#ifdef GOAMD64_v3 TZCNTQ R9, R9 - -#else - BSFQ R9, R9 - -#endif - SARQ $0x03, R9 - LEAL (R10)(R9*1), R10 - JMP match_nolit_end_encodeBlockAsm4MB + SARQ $0x03, R9 + LEAL (R10)(R9*1), R10 + JMP match_nolit_end_encodeBlockAsm4MB matchlen_match4_match_nolit_encodeBlockAsm4MB: CMPL DI, $0x04 @@ -3006,16 +2958,10 @@ matchlen_loopback_16_repeat_extend_encodeBlockAsm12B: JMP matchlen_loopback_16_repeat_extend_encodeBlockAsm12B matchlen_bsf_16repeat_extend_encodeBlockAsm12B: -#ifdef GOAMD64_v3 TZCNTQ R13, R13 - -#else - BSFQ R13, R13 - -#endif - SARQ $0x03, R13 - LEAL 8(R12)(R13*1), R12 - JMP repeat_extend_forward_end_encodeBlockAsm12B + SARQ $0x03, R13 + LEAL 8(R12)(R13*1), R12 + JMP repeat_extend_forward_end_encodeBlockAsm12B matchlen_match8_repeat_extend_encodeBlockAsm12B: CMPL R9, $0x08 @@ -3028,16 +2974,10 @@ matchlen_match8_repeat_extend_encodeBlockAsm12B: JMP matchlen_match4_repeat_extend_encodeBlockAsm12B matchlen_bsf_8_repeat_extend_encodeBlockAsm12B: -#ifdef GOAMD64_v3 TZCNTQ R11, R11 - -#else - BSFQ R11, R11 - -#endif - SARQ $0x03, R11 - LEAL (R12)(R11*1), R12 - JMP repeat_extend_forward_end_encodeBlockAsm12B + SARQ $0x03, R11 + LEAL (R12)(R11*1), R12 + JMP repeat_extend_forward_end_encodeBlockAsm12B matchlen_match4_repeat_extend_encodeBlockAsm12B: CMPL R9, $0x04 @@ -3458,16 +3398,10 @@ matchlen_loopback_16_match_nolit_encodeBlockAsm12B: JMP matchlen_loopback_16_match_nolit_encodeBlockAsm12B matchlen_bsf_16match_nolit_encodeBlockAsm12B: -#ifdef GOAMD64_v3 TZCNTQ R11, R11 - -#else - BSFQ R11, R11 - -#endif - SARQ $0x03, R11 - LEAL 8(R10)(R11*1), R10 - JMP match_nolit_end_encodeBlockAsm12B + SARQ $0x03, R11 + LEAL 8(R10)(R11*1), R10 + JMP match_nolit_end_encodeBlockAsm12B matchlen_match8_match_nolit_encodeBlockAsm12B: CMPL DI, $0x08 @@ -3480,16 +3414,10 @@ matchlen_match8_match_nolit_encodeBlockAsm12B: JMP matchlen_match4_match_nolit_encodeBlockAsm12B matchlen_bsf_8_match_nolit_encodeBlockAsm12B: -#ifdef GOAMD64_v3 TZCNTQ R9, R9 - -#else - BSFQ R9, R9 - -#endif - SARQ $0x03, R9 - LEAL (R10)(R9*1), R10 - JMP match_nolit_end_encodeBlockAsm12B + SARQ $0x03, R9 + LEAL (R10)(R9*1), R10 + JMP match_nolit_end_encodeBlockAsm12B matchlen_match4_match_nolit_encodeBlockAsm12B: CMPL DI, $0x04 @@ -4091,16 +4019,10 @@ matchlen_loopback_16_repeat_extend_encodeBlockAsm10B: JMP matchlen_loopback_16_repeat_extend_encodeBlockAsm10B matchlen_bsf_16repeat_extend_encodeBlockAsm10B: -#ifdef GOAMD64_v3 TZCNTQ R13, R13 - -#else - BSFQ R13, R13 - -#endif - SARQ $0x03, R13 - LEAL 8(R12)(R13*1), R12 - JMP repeat_extend_forward_end_encodeBlockAsm10B + SARQ $0x03, R13 + LEAL 8(R12)(R13*1), R12 + JMP repeat_extend_forward_end_encodeBlockAsm10B matchlen_match8_repeat_extend_encodeBlockAsm10B: CMPL R9, $0x08 @@ -4113,16 +4035,10 @@ matchlen_match8_repeat_extend_encodeBlockAsm10B: JMP matchlen_match4_repeat_extend_encodeBlockAsm10B matchlen_bsf_8_repeat_extend_encodeBlockAsm10B: -#ifdef GOAMD64_v3 TZCNTQ R11, R11 - -#else - BSFQ R11, R11 - -#endif - SARQ $0x03, R11 - LEAL (R12)(R11*1), R12 - JMP repeat_extend_forward_end_encodeBlockAsm10B + SARQ $0x03, R11 + LEAL (R12)(R11*1), R12 + JMP repeat_extend_forward_end_encodeBlockAsm10B matchlen_match4_repeat_extend_encodeBlockAsm10B: CMPL R9, $0x04 @@ -4543,16 +4459,10 @@ matchlen_loopback_16_match_nolit_encodeBlockAsm10B: JMP matchlen_loopback_16_match_nolit_encodeBlockAsm10B matchlen_bsf_16match_nolit_encodeBlockAsm10B: -#ifdef GOAMD64_v3 TZCNTQ R11, R11 - -#else - BSFQ R11, R11 - -#endif - SARQ $0x03, R11 - LEAL 8(R10)(R11*1), R10 - JMP match_nolit_end_encodeBlockAsm10B + SARQ $0x03, R11 + LEAL 8(R10)(R11*1), R10 + JMP match_nolit_end_encodeBlockAsm10B matchlen_match8_match_nolit_encodeBlockAsm10B: CMPL DI, $0x08 @@ -4565,16 +4475,10 @@ matchlen_match8_match_nolit_encodeBlockAsm10B: JMP matchlen_match4_match_nolit_encodeBlockAsm10B matchlen_bsf_8_match_nolit_encodeBlockAsm10B: -#ifdef GOAMD64_v3 TZCNTQ R9, R9 - -#else - BSFQ R9, R9 - -#endif - SARQ $0x03, R9 - LEAL (R10)(R9*1), R10 - JMP match_nolit_end_encodeBlockAsm10B + SARQ $0x03, R9 + LEAL (R10)(R9*1), R10 + JMP match_nolit_end_encodeBlockAsm10B matchlen_match4_match_nolit_encodeBlockAsm10B: CMPL DI, $0x04 @@ -5176,16 +5080,10 @@ matchlen_loopback_16_repeat_extend_encodeBlockAsm8B: JMP matchlen_loopback_16_repeat_extend_encodeBlockAsm8B matchlen_bsf_16repeat_extend_encodeBlockAsm8B: -#ifdef GOAMD64_v3 TZCNTQ R13, R13 - -#else - BSFQ R13, R13 - -#endif - SARQ $0x03, R13 - LEAL 8(R12)(R13*1), R12 - JMP repeat_extend_forward_end_encodeBlockAsm8B + SARQ $0x03, R13 + LEAL 8(R12)(R13*1), R12 + JMP repeat_extend_forward_end_encodeBlockAsm8B matchlen_match8_repeat_extend_encodeBlockAsm8B: CMPL R9, $0x08 @@ -5198,16 +5096,10 @@ matchlen_match8_repeat_extend_encodeBlockAsm8B: JMP matchlen_match4_repeat_extend_encodeBlockAsm8B matchlen_bsf_8_repeat_extend_encodeBlockAsm8B: -#ifdef GOAMD64_v3 TZCNTQ R11, R11 - -#else - BSFQ R11, R11 - -#endif - SARQ $0x03, R11 - LEAL (R12)(R11*1), R12 - JMP repeat_extend_forward_end_encodeBlockAsm8B + SARQ $0x03, R11 + LEAL (R12)(R11*1), R12 + JMP repeat_extend_forward_end_encodeBlockAsm8B matchlen_match4_repeat_extend_encodeBlockAsm8B: CMPL R9, $0x04 @@ -5614,16 +5506,10 @@ matchlen_loopback_16_match_nolit_encodeBlockAsm8B: JMP matchlen_loopback_16_match_nolit_encodeBlockAsm8B matchlen_bsf_16match_nolit_encodeBlockAsm8B: -#ifdef GOAMD64_v3 TZCNTQ R11, R11 - -#else - BSFQ R11, R11 - -#endif - SARQ $0x03, R11 - LEAL 8(R10)(R11*1), R10 - JMP match_nolit_end_encodeBlockAsm8B + SARQ $0x03, R11 + LEAL 8(R10)(R11*1), R10 + JMP match_nolit_end_encodeBlockAsm8B matchlen_match8_match_nolit_encodeBlockAsm8B: CMPL DI, $0x08 @@ -5636,16 +5522,10 @@ matchlen_match8_match_nolit_encodeBlockAsm8B: JMP matchlen_match4_match_nolit_encodeBlockAsm8B matchlen_bsf_8_match_nolit_encodeBlockAsm8B: -#ifdef GOAMD64_v3 TZCNTQ R9, R9 - -#else - BSFQ R9, R9 - -#endif - SARQ $0x03, R9 - LEAL (R10)(R9*1), R10 - JMP match_nolit_end_encodeBlockAsm8B + SARQ $0x03, R9 + LEAL (R10)(R9*1), R10 + JMP match_nolit_end_encodeBlockAsm8B matchlen_match4_match_nolit_encodeBlockAsm8B: CMPL DI, $0x04 @@ -6140,16 +6020,10 @@ matchlen_loopback_16_match_nolit_encodeBetterBlockAsm: JMP matchlen_loopback_16_match_nolit_encodeBetterBlockAsm matchlen_bsf_16match_nolit_encodeBetterBlockAsm: -#ifdef GOAMD64_v3 TZCNTQ R13, R13 - -#else - BSFQ R13, R13 - -#endif - SARQ $0x03, R13 - LEAL 8(R12)(R13*1), R12 - JMP match_nolit_end_encodeBetterBlockAsm + SARQ $0x03, R13 + LEAL 8(R12)(R13*1), R12 + JMP match_nolit_end_encodeBetterBlockAsm matchlen_match8_match_nolit_encodeBetterBlockAsm: CMPL R8, $0x08 @@ -6162,16 +6036,10 @@ matchlen_match8_match_nolit_encodeBetterBlockAsm: JMP matchlen_match4_match_nolit_encodeBetterBlockAsm matchlen_bsf_8_match_nolit_encodeBetterBlockAsm: -#ifdef GOAMD64_v3 TZCNTQ R11, R11 - -#else - BSFQ R11, R11 - -#endif - SARQ $0x03, R11 - LEAL (R12)(R11*1), R12 - JMP match_nolit_end_encodeBetterBlockAsm + SARQ $0x03, R11 + LEAL (R12)(R11*1), R12 + JMP match_nolit_end_encodeBetterBlockAsm matchlen_match4_match_nolit_encodeBetterBlockAsm: CMPL R8, $0x04 @@ -7235,16 +7103,10 @@ matchlen_loopback_16_match_nolit_encodeBetterBlockAsm4MB: JMP matchlen_loopback_16_match_nolit_encodeBetterBlockAsm4MB matchlen_bsf_16match_nolit_encodeBetterBlockAsm4MB: -#ifdef GOAMD64_v3 TZCNTQ R13, R13 - -#else - BSFQ R13, R13 - -#endif - SARQ $0x03, R13 - LEAL 8(R12)(R13*1), R12 - JMP match_nolit_end_encodeBetterBlockAsm4MB + SARQ $0x03, R13 + LEAL 8(R12)(R13*1), R12 + JMP match_nolit_end_encodeBetterBlockAsm4MB matchlen_match8_match_nolit_encodeBetterBlockAsm4MB: CMPL R8, $0x08 @@ -7257,16 +7119,10 @@ matchlen_match8_match_nolit_encodeBetterBlockAsm4MB: JMP matchlen_match4_match_nolit_encodeBetterBlockAsm4MB matchlen_bsf_8_match_nolit_encodeBetterBlockAsm4MB: -#ifdef GOAMD64_v3 TZCNTQ R11, R11 - -#else - BSFQ R11, R11 - -#endif - SARQ $0x03, R11 - LEAL (R12)(R11*1), R12 - JMP match_nolit_end_encodeBetterBlockAsm4MB + SARQ $0x03, R11 + LEAL (R12)(R11*1), R12 + JMP match_nolit_end_encodeBetterBlockAsm4MB matchlen_match4_match_nolit_encodeBetterBlockAsm4MB: CMPL R8, $0x04 @@ -8256,16 +8112,10 @@ matchlen_loopback_16_match_nolit_encodeBetterBlockAsm12B: JMP matchlen_loopback_16_match_nolit_encodeBetterBlockAsm12B matchlen_bsf_16match_nolit_encodeBetterBlockAsm12B: -#ifdef GOAMD64_v3 TZCNTQ R13, R13 - -#else - BSFQ R13, R13 - -#endif - SARQ $0x03, R13 - LEAL 8(R12)(R13*1), R12 - JMP match_nolit_end_encodeBetterBlockAsm12B + SARQ $0x03, R13 + LEAL 8(R12)(R13*1), R12 + JMP match_nolit_end_encodeBetterBlockAsm12B matchlen_match8_match_nolit_encodeBetterBlockAsm12B: CMPL R8, $0x08 @@ -8278,16 +8128,10 @@ matchlen_match8_match_nolit_encodeBetterBlockAsm12B: JMP matchlen_match4_match_nolit_encodeBetterBlockAsm12B matchlen_bsf_8_match_nolit_encodeBetterBlockAsm12B: -#ifdef GOAMD64_v3 TZCNTQ R11, R11 - -#else - BSFQ R11, R11 - -#endif - SARQ $0x03, R11 - LEAL (R12)(R11*1), R12 - JMP match_nolit_end_encodeBetterBlockAsm12B + SARQ $0x03, R11 + LEAL (R12)(R11*1), R12 + JMP match_nolit_end_encodeBetterBlockAsm12B matchlen_match4_match_nolit_encodeBetterBlockAsm12B: CMPL R8, $0x04 @@ -9130,16 +8974,10 @@ matchlen_loopback_16_match_nolit_encodeBetterBlockAsm10B: JMP matchlen_loopback_16_match_nolit_encodeBetterBlockAsm10B matchlen_bsf_16match_nolit_encodeBetterBlockAsm10B: -#ifdef GOAMD64_v3 TZCNTQ R13, R13 - -#else - BSFQ R13, R13 - -#endif - SARQ $0x03, R13 - LEAL 8(R12)(R13*1), R12 - JMP match_nolit_end_encodeBetterBlockAsm10B + SARQ $0x03, R13 + LEAL 8(R12)(R13*1), R12 + JMP match_nolit_end_encodeBetterBlockAsm10B matchlen_match8_match_nolit_encodeBetterBlockAsm10B: CMPL R8, $0x08 @@ -9152,16 +8990,10 @@ matchlen_match8_match_nolit_encodeBetterBlockAsm10B: JMP matchlen_match4_match_nolit_encodeBetterBlockAsm10B matchlen_bsf_8_match_nolit_encodeBetterBlockAsm10B: -#ifdef GOAMD64_v3 TZCNTQ R11, R11 - -#else - BSFQ R11, R11 - -#endif - SARQ $0x03, R11 - LEAL (R12)(R11*1), R12 - JMP match_nolit_end_encodeBetterBlockAsm10B + SARQ $0x03, R11 + LEAL (R12)(R11*1), R12 + JMP match_nolit_end_encodeBetterBlockAsm10B matchlen_match4_match_nolit_encodeBetterBlockAsm10B: CMPL R8, $0x04 @@ -10004,16 +9836,10 @@ matchlen_loopback_16_match_nolit_encodeBetterBlockAsm8B: JMP matchlen_loopback_16_match_nolit_encodeBetterBlockAsm8B matchlen_bsf_16match_nolit_encodeBetterBlockAsm8B: -#ifdef GOAMD64_v3 TZCNTQ R13, R13 - -#else - BSFQ R13, R13 - -#endif - SARQ $0x03, R13 - LEAL 8(R12)(R13*1), R12 - JMP match_nolit_end_encodeBetterBlockAsm8B + SARQ $0x03, R13 + LEAL 8(R12)(R13*1), R12 + JMP match_nolit_end_encodeBetterBlockAsm8B matchlen_match8_match_nolit_encodeBetterBlockAsm8B: CMPL R8, $0x08 @@ -10026,16 +9852,10 @@ matchlen_match8_match_nolit_encodeBetterBlockAsm8B: JMP matchlen_match4_match_nolit_encodeBetterBlockAsm8B matchlen_bsf_8_match_nolit_encodeBetterBlockAsm8B: -#ifdef GOAMD64_v3 TZCNTQ R11, R11 - -#else - BSFQ R11, R11 - -#endif - SARQ $0x03, R11 - LEAL (R12)(R11*1), R12 - JMP match_nolit_end_encodeBetterBlockAsm8B + SARQ $0x03, R11 + LEAL (R12)(R11*1), R12 + JMP match_nolit_end_encodeBetterBlockAsm8B matchlen_match4_match_nolit_encodeBetterBlockAsm8B: CMPL R8, $0x04 @@ -10985,16 +10805,10 @@ matchlen_loopback_16_repeat_extend_encodeSnappyBlockAsm: JMP matchlen_loopback_16_repeat_extend_encodeSnappyBlockAsm matchlen_bsf_16repeat_extend_encodeSnappyBlockAsm: -#ifdef GOAMD64_v3 TZCNTQ R12, R12 - -#else - BSFQ R12, R12 - -#endif - SARQ $0x03, R12 - LEAL 8(R11)(R12*1), R11 - JMP repeat_extend_forward_end_encodeSnappyBlockAsm + SARQ $0x03, R12 + LEAL 8(R11)(R12*1), R11 + JMP repeat_extend_forward_end_encodeSnappyBlockAsm matchlen_match8_repeat_extend_encodeSnappyBlockAsm: CMPL R8, $0x08 @@ -11007,16 +10821,10 @@ matchlen_match8_repeat_extend_encodeSnappyBlockAsm: JMP matchlen_match4_repeat_extend_encodeSnappyBlockAsm matchlen_bsf_8_repeat_extend_encodeSnappyBlockAsm: -#ifdef GOAMD64_v3 TZCNTQ R10, R10 - -#else - BSFQ R10, R10 - -#endif - SARQ $0x03, R10 - LEAL (R11)(R10*1), R11 - JMP repeat_extend_forward_end_encodeSnappyBlockAsm + SARQ $0x03, R10 + LEAL (R11)(R10*1), R11 + JMP repeat_extend_forward_end_encodeSnappyBlockAsm matchlen_match4_repeat_extend_encodeSnappyBlockAsm: CMPL R8, $0x04 @@ -11329,16 +11137,10 @@ matchlen_loopback_16_match_nolit_encodeSnappyBlockAsm: JMP matchlen_loopback_16_match_nolit_encodeSnappyBlockAsm matchlen_bsf_16match_nolit_encodeSnappyBlockAsm: -#ifdef GOAMD64_v3 TZCNTQ R11, R11 - -#else - BSFQ R11, R11 - -#endif - SARQ $0x03, R11 - LEAL 8(R10)(R11*1), R10 - JMP match_nolit_end_encodeSnappyBlockAsm + SARQ $0x03, R11 + LEAL 8(R10)(R11*1), R10 + JMP match_nolit_end_encodeSnappyBlockAsm matchlen_match8_match_nolit_encodeSnappyBlockAsm: CMPL DI, $0x08 @@ -11351,16 +11153,10 @@ matchlen_match8_match_nolit_encodeSnappyBlockAsm: JMP matchlen_match4_match_nolit_encodeSnappyBlockAsm matchlen_bsf_8_match_nolit_encodeSnappyBlockAsm: -#ifdef GOAMD64_v3 TZCNTQ R9, R9 - -#else - BSFQ R9, R9 - -#endif - SARQ $0x03, R9 - LEAL (R10)(R9*1), R10 - JMP match_nolit_end_encodeSnappyBlockAsm + SARQ $0x03, R9 + LEAL (R10)(R9*1), R10 + JMP match_nolit_end_encodeSnappyBlockAsm matchlen_match4_match_nolit_encodeSnappyBlockAsm: CMPL DI, $0x04 @@ -11901,16 +11697,10 @@ matchlen_loopback_16_repeat_extend_encodeSnappyBlockAsm64K: JMP matchlen_loopback_16_repeat_extend_encodeSnappyBlockAsm64K matchlen_bsf_16repeat_extend_encodeSnappyBlockAsm64K: -#ifdef GOAMD64_v3 TZCNTQ R12, R12 - -#else - BSFQ R12, R12 - -#endif - SARQ $0x03, R12 - LEAL 8(R11)(R12*1), R11 - JMP repeat_extend_forward_end_encodeSnappyBlockAsm64K + SARQ $0x03, R12 + LEAL 8(R11)(R12*1), R11 + JMP repeat_extend_forward_end_encodeSnappyBlockAsm64K matchlen_match8_repeat_extend_encodeSnappyBlockAsm64K: CMPL R8, $0x08 @@ -11923,16 +11713,10 @@ matchlen_match8_repeat_extend_encodeSnappyBlockAsm64K: JMP matchlen_match4_repeat_extend_encodeSnappyBlockAsm64K matchlen_bsf_8_repeat_extend_encodeSnappyBlockAsm64K: -#ifdef GOAMD64_v3 TZCNTQ R10, R10 - -#else - BSFQ R10, R10 - -#endif - SARQ $0x03, R10 - LEAL (R11)(R10*1), R11 - JMP repeat_extend_forward_end_encodeSnappyBlockAsm64K + SARQ $0x03, R10 + LEAL (R11)(R10*1), R11 + JMP repeat_extend_forward_end_encodeSnappyBlockAsm64K matchlen_match4_repeat_extend_encodeSnappyBlockAsm64K: CMPL R8, $0x04 @@ -12205,16 +11989,10 @@ matchlen_loopback_16_match_nolit_encodeSnappyBlockAsm64K: JMP matchlen_loopback_16_match_nolit_encodeSnappyBlockAsm64K matchlen_bsf_16match_nolit_encodeSnappyBlockAsm64K: -#ifdef GOAMD64_v3 TZCNTQ R11, R11 - -#else - BSFQ R11, R11 - -#endif - SARQ $0x03, R11 - LEAL 8(R10)(R11*1), R10 - JMP match_nolit_end_encodeSnappyBlockAsm64K + SARQ $0x03, R11 + LEAL 8(R10)(R11*1), R10 + JMP match_nolit_end_encodeSnappyBlockAsm64K matchlen_match8_match_nolit_encodeSnappyBlockAsm64K: CMPL DI, $0x08 @@ -12227,16 +12005,10 @@ matchlen_match8_match_nolit_encodeSnappyBlockAsm64K: JMP matchlen_match4_match_nolit_encodeSnappyBlockAsm64K matchlen_bsf_8_match_nolit_encodeSnappyBlockAsm64K: -#ifdef GOAMD64_v3 TZCNTQ R9, R9 - -#else - BSFQ R9, R9 - -#endif - SARQ $0x03, R9 - LEAL (R10)(R9*1), R10 - JMP match_nolit_end_encodeSnappyBlockAsm64K + SARQ $0x03, R9 + LEAL (R10)(R9*1), R10 + JMP match_nolit_end_encodeSnappyBlockAsm64K matchlen_match4_match_nolit_encodeSnappyBlockAsm64K: CMPL DI, $0x04 @@ -12737,16 +12509,10 @@ matchlen_loopback_16_repeat_extend_encodeSnappyBlockAsm12B: JMP matchlen_loopback_16_repeat_extend_encodeSnappyBlockAsm12B matchlen_bsf_16repeat_extend_encodeSnappyBlockAsm12B: -#ifdef GOAMD64_v3 TZCNTQ R12, R12 - -#else - BSFQ R12, R12 - -#endif - SARQ $0x03, R12 - LEAL 8(R11)(R12*1), R11 - JMP repeat_extend_forward_end_encodeSnappyBlockAsm12B + SARQ $0x03, R12 + LEAL 8(R11)(R12*1), R11 + JMP repeat_extend_forward_end_encodeSnappyBlockAsm12B matchlen_match8_repeat_extend_encodeSnappyBlockAsm12B: CMPL R8, $0x08 @@ -12759,16 +12525,10 @@ matchlen_match8_repeat_extend_encodeSnappyBlockAsm12B: JMP matchlen_match4_repeat_extend_encodeSnappyBlockAsm12B matchlen_bsf_8_repeat_extend_encodeSnappyBlockAsm12B: -#ifdef GOAMD64_v3 TZCNTQ R10, R10 - -#else - BSFQ R10, R10 - -#endif - SARQ $0x03, R10 - LEAL (R11)(R10*1), R11 - JMP repeat_extend_forward_end_encodeSnappyBlockAsm12B + SARQ $0x03, R10 + LEAL (R11)(R10*1), R11 + JMP repeat_extend_forward_end_encodeSnappyBlockAsm12B matchlen_match4_repeat_extend_encodeSnappyBlockAsm12B: CMPL R8, $0x04 @@ -13041,16 +12801,10 @@ matchlen_loopback_16_match_nolit_encodeSnappyBlockAsm12B: JMP matchlen_loopback_16_match_nolit_encodeSnappyBlockAsm12B matchlen_bsf_16match_nolit_encodeSnappyBlockAsm12B: -#ifdef GOAMD64_v3 TZCNTQ R11, R11 - -#else - BSFQ R11, R11 - -#endif - SARQ $0x03, R11 - LEAL 8(R10)(R11*1), R10 - JMP match_nolit_end_encodeSnappyBlockAsm12B + SARQ $0x03, R11 + LEAL 8(R10)(R11*1), R10 + JMP match_nolit_end_encodeSnappyBlockAsm12B matchlen_match8_match_nolit_encodeSnappyBlockAsm12B: CMPL DI, $0x08 @@ -13063,16 +12817,10 @@ matchlen_match8_match_nolit_encodeSnappyBlockAsm12B: JMP matchlen_match4_match_nolit_encodeSnappyBlockAsm12B matchlen_bsf_8_match_nolit_encodeSnappyBlockAsm12B: -#ifdef GOAMD64_v3 TZCNTQ R9, R9 - -#else - BSFQ R9, R9 - -#endif - SARQ $0x03, R9 - LEAL (R10)(R9*1), R10 - JMP match_nolit_end_encodeSnappyBlockAsm12B + SARQ $0x03, R9 + LEAL (R10)(R9*1), R10 + JMP match_nolit_end_encodeSnappyBlockAsm12B matchlen_match4_match_nolit_encodeSnappyBlockAsm12B: CMPL DI, $0x04 @@ -13573,16 +13321,10 @@ matchlen_loopback_16_repeat_extend_encodeSnappyBlockAsm10B: JMP matchlen_loopback_16_repeat_extend_encodeSnappyBlockAsm10B matchlen_bsf_16repeat_extend_encodeSnappyBlockAsm10B: -#ifdef GOAMD64_v3 TZCNTQ R12, R12 - -#else - BSFQ R12, R12 - -#endif - SARQ $0x03, R12 - LEAL 8(R11)(R12*1), R11 - JMP repeat_extend_forward_end_encodeSnappyBlockAsm10B + SARQ $0x03, R12 + LEAL 8(R11)(R12*1), R11 + JMP repeat_extend_forward_end_encodeSnappyBlockAsm10B matchlen_match8_repeat_extend_encodeSnappyBlockAsm10B: CMPL R8, $0x08 @@ -13595,16 +13337,10 @@ matchlen_match8_repeat_extend_encodeSnappyBlockAsm10B: JMP matchlen_match4_repeat_extend_encodeSnappyBlockAsm10B matchlen_bsf_8_repeat_extend_encodeSnappyBlockAsm10B: -#ifdef GOAMD64_v3 TZCNTQ R10, R10 - -#else - BSFQ R10, R10 - -#endif - SARQ $0x03, R10 - LEAL (R11)(R10*1), R11 - JMP repeat_extend_forward_end_encodeSnappyBlockAsm10B + SARQ $0x03, R10 + LEAL (R11)(R10*1), R11 + JMP repeat_extend_forward_end_encodeSnappyBlockAsm10B matchlen_match4_repeat_extend_encodeSnappyBlockAsm10B: CMPL R8, $0x04 @@ -13877,16 +13613,10 @@ matchlen_loopback_16_match_nolit_encodeSnappyBlockAsm10B: JMP matchlen_loopback_16_match_nolit_encodeSnappyBlockAsm10B matchlen_bsf_16match_nolit_encodeSnappyBlockAsm10B: -#ifdef GOAMD64_v3 TZCNTQ R11, R11 - -#else - BSFQ R11, R11 - -#endif - SARQ $0x03, R11 - LEAL 8(R10)(R11*1), R10 - JMP match_nolit_end_encodeSnappyBlockAsm10B + SARQ $0x03, R11 + LEAL 8(R10)(R11*1), R10 + JMP match_nolit_end_encodeSnappyBlockAsm10B matchlen_match8_match_nolit_encodeSnappyBlockAsm10B: CMPL DI, $0x08 @@ -13899,16 +13629,10 @@ matchlen_match8_match_nolit_encodeSnappyBlockAsm10B: JMP matchlen_match4_match_nolit_encodeSnappyBlockAsm10B matchlen_bsf_8_match_nolit_encodeSnappyBlockAsm10B: -#ifdef GOAMD64_v3 TZCNTQ R9, R9 - -#else - BSFQ R9, R9 - -#endif - SARQ $0x03, R9 - LEAL (R10)(R9*1), R10 - JMP match_nolit_end_encodeSnappyBlockAsm10B + SARQ $0x03, R9 + LEAL (R10)(R9*1), R10 + JMP match_nolit_end_encodeSnappyBlockAsm10B matchlen_match4_match_nolit_encodeSnappyBlockAsm10B: CMPL DI, $0x04 @@ -14409,16 +14133,10 @@ matchlen_loopback_16_repeat_extend_encodeSnappyBlockAsm8B: JMP matchlen_loopback_16_repeat_extend_encodeSnappyBlockAsm8B matchlen_bsf_16repeat_extend_encodeSnappyBlockAsm8B: -#ifdef GOAMD64_v3 TZCNTQ R12, R12 - -#else - BSFQ R12, R12 - -#endif - SARQ $0x03, R12 - LEAL 8(R11)(R12*1), R11 - JMP repeat_extend_forward_end_encodeSnappyBlockAsm8B + SARQ $0x03, R12 + LEAL 8(R11)(R12*1), R11 + JMP repeat_extend_forward_end_encodeSnappyBlockAsm8B matchlen_match8_repeat_extend_encodeSnappyBlockAsm8B: CMPL R8, $0x08 @@ -14431,16 +14149,10 @@ matchlen_match8_repeat_extend_encodeSnappyBlockAsm8B: JMP matchlen_match4_repeat_extend_encodeSnappyBlockAsm8B matchlen_bsf_8_repeat_extend_encodeSnappyBlockAsm8B: -#ifdef GOAMD64_v3 TZCNTQ R10, R10 - -#else - BSFQ R10, R10 - -#endif - SARQ $0x03, R10 - LEAL (R11)(R10*1), R11 - JMP repeat_extend_forward_end_encodeSnappyBlockAsm8B + SARQ $0x03, R10 + LEAL (R11)(R10*1), R11 + JMP repeat_extend_forward_end_encodeSnappyBlockAsm8B matchlen_match4_repeat_extend_encodeSnappyBlockAsm8B: CMPL R8, $0x04 @@ -14711,16 +14423,10 @@ matchlen_loopback_16_match_nolit_encodeSnappyBlockAsm8B: JMP matchlen_loopback_16_match_nolit_encodeSnappyBlockAsm8B matchlen_bsf_16match_nolit_encodeSnappyBlockAsm8B: -#ifdef GOAMD64_v3 TZCNTQ R11, R11 - -#else - BSFQ R11, R11 - -#endif - SARQ $0x03, R11 - LEAL 8(R10)(R11*1), R10 - JMP match_nolit_end_encodeSnappyBlockAsm8B + SARQ $0x03, R11 + LEAL 8(R10)(R11*1), R10 + JMP match_nolit_end_encodeSnappyBlockAsm8B matchlen_match8_match_nolit_encodeSnappyBlockAsm8B: CMPL DI, $0x08 @@ -14733,16 +14439,10 @@ matchlen_match8_match_nolit_encodeSnappyBlockAsm8B: JMP matchlen_match4_match_nolit_encodeSnappyBlockAsm8B matchlen_bsf_8_match_nolit_encodeSnappyBlockAsm8B: -#ifdef GOAMD64_v3 TZCNTQ R9, R9 - -#else - BSFQ R9, R9 - -#endif - SARQ $0x03, R9 - LEAL (R10)(R9*1), R10 - JMP match_nolit_end_encodeSnappyBlockAsm8B + SARQ $0x03, R9 + LEAL (R10)(R9*1), R10 + JMP match_nolit_end_encodeSnappyBlockAsm8B matchlen_match4_match_nolit_encodeSnappyBlockAsm8B: CMPL DI, $0x04 @@ -15144,16 +14844,10 @@ matchlen_loopback_16_match_nolit_encodeSnappyBetterBlockAsm: JMP matchlen_loopback_16_match_nolit_encodeSnappyBetterBlockAsm matchlen_bsf_16match_nolit_encodeSnappyBetterBlockAsm: -#ifdef GOAMD64_v3 TZCNTQ R13, R13 - -#else - BSFQ R13, R13 - -#endif - SARQ $0x03, R13 - LEAL 8(R12)(R13*1), R12 - JMP match_nolit_end_encodeSnappyBetterBlockAsm + SARQ $0x03, R13 + LEAL 8(R12)(R13*1), R12 + JMP match_nolit_end_encodeSnappyBetterBlockAsm matchlen_match8_match_nolit_encodeSnappyBetterBlockAsm: CMPL R8, $0x08 @@ -15166,16 +14860,10 @@ matchlen_match8_match_nolit_encodeSnappyBetterBlockAsm: JMP matchlen_match4_match_nolit_encodeSnappyBetterBlockAsm matchlen_bsf_8_match_nolit_encodeSnappyBetterBlockAsm: -#ifdef GOAMD64_v3 TZCNTQ R11, R11 - -#else - BSFQ R11, R11 - -#endif - SARQ $0x03, R11 - LEAL (R12)(R11*1), R12 - JMP match_nolit_end_encodeSnappyBetterBlockAsm + SARQ $0x03, R11 + LEAL (R12)(R11*1), R12 + JMP match_nolit_end_encodeSnappyBetterBlockAsm matchlen_match4_match_nolit_encodeSnappyBetterBlockAsm: CMPL R8, $0x04 @@ -15790,16 +15478,10 @@ matchlen_loopback_16_match_nolit_encodeSnappyBetterBlockAsm64K: JMP matchlen_loopback_16_match_nolit_encodeSnappyBetterBlockAsm64K matchlen_bsf_16match_nolit_encodeSnappyBetterBlockAsm64K: -#ifdef GOAMD64_v3 TZCNTQ R13, R13 - -#else - BSFQ R13, R13 - -#endif - SARQ $0x03, R13 - LEAL 8(R12)(R13*1), R12 - JMP match_nolit_end_encodeSnappyBetterBlockAsm64K + SARQ $0x03, R13 + LEAL 8(R12)(R13*1), R12 + JMP match_nolit_end_encodeSnappyBetterBlockAsm64K matchlen_match8_match_nolit_encodeSnappyBetterBlockAsm64K: CMPL R8, $0x08 @@ -15812,16 +15494,10 @@ matchlen_match8_match_nolit_encodeSnappyBetterBlockAsm64K: JMP matchlen_match4_match_nolit_encodeSnappyBetterBlockAsm64K matchlen_bsf_8_match_nolit_encodeSnappyBetterBlockAsm64K: -#ifdef GOAMD64_v3 TZCNTQ R11, R11 - -#else - BSFQ R11, R11 - -#endif - SARQ $0x03, R11 - LEAL (R12)(R11*1), R12 - JMP match_nolit_end_encodeSnappyBetterBlockAsm64K + SARQ $0x03, R11 + LEAL (R12)(R11*1), R12 + JMP match_nolit_end_encodeSnappyBetterBlockAsm64K matchlen_match4_match_nolit_encodeSnappyBetterBlockAsm64K: CMPL R8, $0x04 @@ -16371,16 +16047,10 @@ matchlen_loopback_16_match_nolit_encodeSnappyBetterBlockAsm12B: JMP matchlen_loopback_16_match_nolit_encodeSnappyBetterBlockAsm12B matchlen_bsf_16match_nolit_encodeSnappyBetterBlockAsm12B: -#ifdef GOAMD64_v3 TZCNTQ R13, R13 - -#else - BSFQ R13, R13 - -#endif - SARQ $0x03, R13 - LEAL 8(R12)(R13*1), R12 - JMP match_nolit_end_encodeSnappyBetterBlockAsm12B + SARQ $0x03, R13 + LEAL 8(R12)(R13*1), R12 + JMP match_nolit_end_encodeSnappyBetterBlockAsm12B matchlen_match8_match_nolit_encodeSnappyBetterBlockAsm12B: CMPL R8, $0x08 @@ -16393,16 +16063,10 @@ matchlen_match8_match_nolit_encodeSnappyBetterBlockAsm12B: JMP matchlen_match4_match_nolit_encodeSnappyBetterBlockAsm12B matchlen_bsf_8_match_nolit_encodeSnappyBetterBlockAsm12B: -#ifdef GOAMD64_v3 TZCNTQ R11, R11 - -#else - BSFQ R11, R11 - -#endif - SARQ $0x03, R11 - LEAL (R12)(R11*1), R12 - JMP match_nolit_end_encodeSnappyBetterBlockAsm12B + SARQ $0x03, R11 + LEAL (R12)(R11*1), R12 + JMP match_nolit_end_encodeSnappyBetterBlockAsm12B matchlen_match4_match_nolit_encodeSnappyBetterBlockAsm12B: CMPL R8, $0x04 @@ -16952,16 +16616,10 @@ matchlen_loopback_16_match_nolit_encodeSnappyBetterBlockAsm10B: JMP matchlen_loopback_16_match_nolit_encodeSnappyBetterBlockAsm10B matchlen_bsf_16match_nolit_encodeSnappyBetterBlockAsm10B: -#ifdef GOAMD64_v3 TZCNTQ R13, R13 - -#else - BSFQ R13, R13 - -#endif - SARQ $0x03, R13 - LEAL 8(R12)(R13*1), R12 - JMP match_nolit_end_encodeSnappyBetterBlockAsm10B + SARQ $0x03, R13 + LEAL 8(R12)(R13*1), R12 + JMP match_nolit_end_encodeSnappyBetterBlockAsm10B matchlen_match8_match_nolit_encodeSnappyBetterBlockAsm10B: CMPL R8, $0x08 @@ -16974,16 +16632,10 @@ matchlen_match8_match_nolit_encodeSnappyBetterBlockAsm10B: JMP matchlen_match4_match_nolit_encodeSnappyBetterBlockAsm10B matchlen_bsf_8_match_nolit_encodeSnappyBetterBlockAsm10B: -#ifdef GOAMD64_v3 TZCNTQ R11, R11 - -#else - BSFQ R11, R11 - -#endif - SARQ $0x03, R11 - LEAL (R12)(R11*1), R12 - JMP match_nolit_end_encodeSnappyBetterBlockAsm10B + SARQ $0x03, R11 + LEAL (R12)(R11*1), R12 + JMP match_nolit_end_encodeSnappyBetterBlockAsm10B matchlen_match4_match_nolit_encodeSnappyBetterBlockAsm10B: CMPL R8, $0x04 @@ -17533,16 +17185,10 @@ matchlen_loopback_16_match_nolit_encodeSnappyBetterBlockAsm8B: JMP matchlen_loopback_16_match_nolit_encodeSnappyBetterBlockAsm8B matchlen_bsf_16match_nolit_encodeSnappyBetterBlockAsm8B: -#ifdef GOAMD64_v3 TZCNTQ R13, R13 - -#else - BSFQ R13, R13 - -#endif - SARQ $0x03, R13 - LEAL 8(R12)(R13*1), R12 - JMP match_nolit_end_encodeSnappyBetterBlockAsm8B + SARQ $0x03, R13 + LEAL 8(R12)(R13*1), R12 + JMP match_nolit_end_encodeSnappyBetterBlockAsm8B matchlen_match8_match_nolit_encodeSnappyBetterBlockAsm8B: CMPL R8, $0x08 @@ -17555,16 +17201,10 @@ matchlen_match8_match_nolit_encodeSnappyBetterBlockAsm8B: JMP matchlen_match4_match_nolit_encodeSnappyBetterBlockAsm8B matchlen_bsf_8_match_nolit_encodeSnappyBetterBlockAsm8B: -#ifdef GOAMD64_v3 TZCNTQ R11, R11 - -#else - BSFQ R11, R11 - -#endif - SARQ $0x03, R11 - LEAL (R12)(R11*1), R12 - JMP match_nolit_end_encodeSnappyBetterBlockAsm8B + SARQ $0x03, R11 + LEAL (R12)(R11*1), R12 + JMP match_nolit_end_encodeSnappyBetterBlockAsm8B matchlen_match4_match_nolit_encodeSnappyBetterBlockAsm8B: CMPL R8, $0x04 @@ -18138,16 +17778,10 @@ matchlen_loopback_16_repeat_extend_calcBlockSize: JMP matchlen_loopback_16_repeat_extend_calcBlockSize matchlen_bsf_16repeat_extend_calcBlockSize: -#ifdef GOAMD64_v3 TZCNTQ R12, R12 - -#else - BSFQ R12, R12 - -#endif - SARQ $0x03, R12 - LEAL 8(R11)(R12*1), R11 - JMP repeat_extend_forward_end_calcBlockSize + SARQ $0x03, R12 + LEAL 8(R11)(R12*1), R11 + JMP repeat_extend_forward_end_calcBlockSize matchlen_match8_repeat_extend_calcBlockSize: CMPL R8, $0x08 @@ -18160,16 +17794,10 @@ matchlen_match8_repeat_extend_calcBlockSize: JMP matchlen_match4_repeat_extend_calcBlockSize matchlen_bsf_8_repeat_extend_calcBlockSize: -#ifdef GOAMD64_v3 TZCNTQ R10, R10 - -#else - BSFQ R10, R10 - -#endif - SARQ $0x03, R10 - LEAL (R11)(R10*1), R11 - JMP repeat_extend_forward_end_calcBlockSize + SARQ $0x03, R10 + LEAL (R11)(R10*1), R11 + JMP repeat_extend_forward_end_calcBlockSize matchlen_match4_repeat_extend_calcBlockSize: CMPL R8, $0x04 @@ -18371,16 +17999,10 @@ matchlen_loopback_16_match_nolit_calcBlockSize: JMP matchlen_loopback_16_match_nolit_calcBlockSize matchlen_bsf_16match_nolit_calcBlockSize: -#ifdef GOAMD64_v3 TZCNTQ R11, R11 - -#else - BSFQ R11, R11 - -#endif - SARQ $0x03, R11 - LEAL 8(R10)(R11*1), R10 - JMP match_nolit_end_calcBlockSize + SARQ $0x03, R11 + LEAL 8(R10)(R11*1), R10 + JMP match_nolit_end_calcBlockSize matchlen_match8_match_nolit_calcBlockSize: CMPL DI, $0x08 @@ -18393,16 +18015,10 @@ matchlen_match8_match_nolit_calcBlockSize: JMP matchlen_match4_match_nolit_calcBlockSize matchlen_bsf_8_match_nolit_calcBlockSize: -#ifdef GOAMD64_v3 TZCNTQ R9, R9 - -#else - BSFQ R9, R9 - -#endif - SARQ $0x03, R9 - LEAL (R10)(R9*1), R10 - JMP match_nolit_end_calcBlockSize + SARQ $0x03, R9 + LEAL (R10)(R9*1), R10 + JMP match_nolit_end_calcBlockSize matchlen_match4_match_nolit_calcBlockSize: CMPL DI, $0x04 @@ -18723,16 +18339,10 @@ matchlen_loopback_16_repeat_extend_calcBlockSizeSmall: JMP matchlen_loopback_16_repeat_extend_calcBlockSizeSmall matchlen_bsf_16repeat_extend_calcBlockSizeSmall: -#ifdef GOAMD64_v3 TZCNTQ R12, R12 - -#else - BSFQ R12, R12 - -#endif - SARQ $0x03, R12 - LEAL 8(R11)(R12*1), R11 - JMP repeat_extend_forward_end_calcBlockSizeSmall + SARQ $0x03, R12 + LEAL 8(R11)(R12*1), R11 + JMP repeat_extend_forward_end_calcBlockSizeSmall matchlen_match8_repeat_extend_calcBlockSizeSmall: CMPL R8, $0x08 @@ -18745,16 +18355,10 @@ matchlen_match8_repeat_extend_calcBlockSizeSmall: JMP matchlen_match4_repeat_extend_calcBlockSizeSmall matchlen_bsf_8_repeat_extend_calcBlockSizeSmall: -#ifdef GOAMD64_v3 TZCNTQ R10, R10 - -#else - BSFQ R10, R10 - -#endif - SARQ $0x03, R10 - LEAL (R11)(R10*1), R11 - JMP repeat_extend_forward_end_calcBlockSizeSmall + SARQ $0x03, R10 + LEAL (R11)(R10*1), R11 + JMP repeat_extend_forward_end_calcBlockSizeSmall matchlen_match4_repeat_extend_calcBlockSizeSmall: CMPL R8, $0x04 @@ -18926,16 +18530,10 @@ matchlen_loopback_16_match_nolit_calcBlockSizeSmall: JMP matchlen_loopback_16_match_nolit_calcBlockSizeSmall matchlen_bsf_16match_nolit_calcBlockSizeSmall: -#ifdef GOAMD64_v3 TZCNTQ R11, R11 - -#else - BSFQ R11, R11 - -#endif - SARQ $0x03, R11 - LEAL 8(R10)(R11*1), R10 - JMP match_nolit_end_calcBlockSizeSmall + SARQ $0x03, R11 + LEAL 8(R10)(R11*1), R10 + JMP match_nolit_end_calcBlockSizeSmall matchlen_match8_match_nolit_calcBlockSizeSmall: CMPL DI, $0x08 @@ -18948,16 +18546,10 @@ matchlen_match8_match_nolit_calcBlockSizeSmall: JMP matchlen_match4_match_nolit_calcBlockSizeSmall matchlen_bsf_8_match_nolit_calcBlockSizeSmall: -#ifdef GOAMD64_v3 TZCNTQ R9, R9 - -#else - BSFQ R9, R9 - -#endif - SARQ $0x03, R9 - LEAL (R10)(R9*1), R10 - JMP match_nolit_end_calcBlockSizeSmall + SARQ $0x03, R9 + LEAL (R10)(R9*1), R10 + JMP match_nolit_end_calcBlockSizeSmall matchlen_match4_match_nolit_calcBlockSizeSmall: CMPL DI, $0x04 @@ -19737,16 +19329,10 @@ matchlen_loopback_16_standalone: JMP matchlen_loopback_16_standalone matchlen_bsf_16standalone: -#ifdef GOAMD64_v3 TZCNTQ DI, DI - -#else - BSFQ DI, DI - -#endif - SARQ $0x03, DI - LEAL 8(SI)(DI*1), SI - JMP gen_match_len_end + SARQ $0x03, DI + LEAL 8(SI)(DI*1), SI + JMP gen_match_len_end matchlen_match8_standalone: CMPL DX, $0x08 @@ -19759,16 +19345,10 @@ matchlen_match8_standalone: JMP matchlen_match4_standalone matchlen_bsf_8_standalone: -#ifdef GOAMD64_v3 TZCNTQ BX, BX - -#else - BSFQ BX, BX - -#endif - SARQ $0x03, BX - LEAL (SI)(BX*1), SI - JMP gen_match_len_end + SARQ $0x03, BX + LEAL (SI)(BX*1), SI + JMP gen_match_len_end matchlen_match4_standalone: CMPL DX, $0x04 diff --git a/vendor/github.com/klauspost/compress/s2/encodeblock_arm64.s b/vendor/github.com/klauspost/compress/s2/encodeblock_arm64.s new file mode 100644 index 000000000..cfcb9e409 --- /dev/null +++ b/vendor/github.com/klauspost/compress/s2/encodeblock_arm64.s @@ -0,0 +1,23562 @@ +// Code generated by command: go run gen.go -out ../encodeblock.s -arch arm64 -arm64gen -pkg=s2. DO NOT EDIT. +// EXPERIMENTAL arm64 output lowered from an amd64 avo program. + +//go:build arm64 && ((amd64 || arm64) && !appengine && !noasm && gc && !noasm) + +#include "textflag.h" + +// func encodeBlockAsm(dst []byte, src []byte, tmp *[65536]byte) int +// Requires: BMI, SSE2 +TEXT ·encodeBlockAsm(SB), $24-64 + MOVD tmp+48(FP), R0 + MOVD dst_base+0(FP), R1 + MOVD $0x00000200, R2 + MOVD R0, R3 + VEOR V0.B16, V0.B16, V0.B16 + +zero_loop_encodeBlockAsm: + FMOVQ F0, (R3) + FMOVQ F0, 16(R3) + FMOVQ F0, 32(R3) + FMOVQ F0, 48(R3) + FMOVQ F0, 64(R3) + FMOVQ F0, 80(R3) + FMOVQ F0, 96(R3) + FMOVQ F0, 112(R3) + ADD $0x80, R3, R3 + SUBS $1, R2, R2 + BNE zero_loop_encodeBlockAsm + MOVD $0x00000000, R16 + MOVW R16, 20(RSP) + MOVD src_len+32(FP), R2 + SUB $9, R2, R3 + SUB $8, R2, R5 + MOVW R5, 16(RSP) + LSR $0x05, R2, R2 + SUBW R2, R3, R3 + ADD R3, R1, R3 + MOVD R3, 8(RSP) + MOVD $0x00000001, R2 + MOVW R2, 24(RSP) + MOVD src_base+24(FP), R3 + +search_loop_encodeBlockAsm: + MOVWU R2, R5 + MOVWU 20(RSP), R16 + SUBW R16, R5, R5 + LSRW $0x06, R5, R5 + ADD R5, R2, R5 + ADD $4, R5, R5 + MOVWU R5, R5 + MOVWU 16(RSP), R16 + CMPW R16, R5 + BHS emit_remainder_encodeBlockAsm + MOVD (R3)(R2), R6 + MOVW R5, 28(RSP) + MOVD $0x0000cf1bbcdcbf9b, R8 + MOVD R6, R9 + MOVD R6, R10 + LSR $0x08, R10, R10 + LSL $0x10, R9, R9 + MUL R8, R9, R9 + LSR $0x32, R9, R9 + LSL $0x10, R10, R10 + MUL R8, R10, R10 + LSR $0x32, R10, R10 + MOVWU (R0)(R9<<2), R5 + MOVWU (R0)(R10<<2), R7 + MOVW R2, (R0)(R9<<2) + ADD $1, R2, R9 + MOVWU R9, R9 + MOVW R9, (R0)(R10<<2) + MOVD R6, R9 + LSR $0x10, R9, R9 + LSL $0x10, R9, R9 + MUL R8, R9, R9 + LSR $0x32, R9, R9 + MOVWU R2, R8 + MOVWU 24(RSP), R16 + SUBW R16, R8, R8 + ADD R8, R3, R15 + MOVWU 1(R15), R10 + MOVD R6, R8 + LSR $0x08, R8, R8 + CMPW R10, R8 + BNE no_repeat_found_encodeBlockAsm + ADD $1, R2, R6 + MOVWU R6, R6 + MOVWU 20(RSP), R7 + MOVWU R6, R5 + MOVWU 24(RSP), R16 + SUBSW R16, R5, R5 + BEQ repeat_extend_back_end_encodeBlockAsm + +repeat_extend_back_loop_encodeBlockAsm: + CMPW R7, R6 + BLS repeat_extend_back_end_encodeBlockAsm + ADD R5, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R8 + ADD R6, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R9 + AND $0xff, R9, R16 + AND $0xff, R8, R15 + CMP R16, R15 + BNE repeat_extend_back_end_encodeBlockAsm + SUB $1, R6, R6 + MOVWU R6, R6 + SUBSW $1, R5, R5 + BNE repeat_extend_back_loop_encodeBlockAsm + +repeat_extend_back_end_encodeBlockAsm: + MOVWU R6, R5 + MOVWU 20(RSP), R16 + SUBW R16, R5, R5 + ADD R5, R1, R5 + ADD $5, R5, R5 + MOVD 8(RSP), R16 + CMP R16, R5 + BLO repeat_dst_size_check_encodeBlockAsm + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +repeat_dst_size_check_encodeBlockAsm: + MOVWU 20(RSP), R5 + CMPW R6, R5 + BEQ emit_literal_done_repeat_emit_encodeBlockAsm + MOVWU R6, R8 + MOVW R6, 20(RSP) + ADD R5, R3, R9 + SUBW R5, R8, R8 + SUB $1, R8, R5 + MOVWU R5, R5 + CMPW $0x3c, R5 + BLO one_byte_repeat_emit_encodeBlockAsm + CMPW $0x00000100, R5 + BLO two_bytes_repeat_emit_encodeBlockAsm + CMPW $0x00010000, R5 + BLO three_bytes_repeat_emit_encodeBlockAsm + CMPW $0x01000000, R5 + BLO four_bytes_repeat_emit_encodeBlockAsm + MOVD $0xfc, R16 + MOVB R16, (R1) + MOVW R5, 1(R1) + ADD $0x05, R1, R1 + JMP memmove_long_repeat_emit_encodeBlockAsm + +four_bytes_repeat_emit_encodeBlockAsm: + MOVWU R5, R10 + LSRW $0x10, R10, R10 + MOVD $0xf8, R16 + MOVB R16, (R1) + MOVH R5, 1(R1) + MOVB R10, 3(R1) + ADD $0x04, R1, R1 + JMP memmove_long_repeat_emit_encodeBlockAsm + +three_bytes_repeat_emit_encodeBlockAsm: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R5, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_repeat_emit_encodeBlockAsm + +two_bytes_repeat_emit_encodeBlockAsm: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R5, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R5 + BLO memmove_repeat_emit_encodeBlockAsm + JMP memmove_long_repeat_emit_encodeBlockAsm + +one_byte_repeat_emit_encodeBlockAsm: + LSLW $0x02, R5, R16 + BFI $0, R16, $8, R5 + MOVB R5, (R1) + ADD $0x01, R1, R1 + +memmove_repeat_emit_encodeBlockAsm: + ADD R8, R1, R5 + + // genMemMoveShort + CMP $0x08, R8 + BLS emit_lit_memmove_repeat_emit_encodeBlockAsm_memmove_move_8 + CMP $0x10, R8 + BLS emit_lit_memmove_repeat_emit_encodeBlockAsm_memmove_move_8through16 + CMP $0x20, R8 + BLS emit_lit_memmove_repeat_emit_encodeBlockAsm_memmove_move_17through32 + JMP emit_lit_memmove_repeat_emit_encodeBlockAsm_memmove_move_33through64 + +emit_lit_memmove_repeat_emit_encodeBlockAsm_memmove_move_8: + MOVD (R9), R10 + MOVD R10, (R1) + JMP memmove_end_copy_repeat_emit_encodeBlockAsm + +emit_lit_memmove_repeat_emit_encodeBlockAsm_memmove_move_8through16: + MOVD (R9), R10 + ADD R8, R9, R15 + MOVD -8(R15), R9 + MOVD R10, (R1) + ADD R8, R1, R15 + MOVD R9, -8(R15) + JMP memmove_end_copy_repeat_emit_encodeBlockAsm + +emit_lit_memmove_repeat_emit_encodeBlockAsm_memmove_move_17through32: + FMOVQ (R9), F0 + ADD R8, R9, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_repeat_emit_encodeBlockAsm + +emit_lit_memmove_repeat_emit_encodeBlockAsm_memmove_move_33through64: + FMOVQ (R9), F0 + FMOVQ 16(R9), F1 + ADD R8, R9, R15 + FMOVQ -32(R15), F2 + ADD R8, R9, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R8, R1, R15 + FMOVQ F2, -32(R15) + ADD R8, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_repeat_emit_encodeBlockAsm: + MOVD R5, R1 + JMP emit_literal_done_repeat_emit_encodeBlockAsm + +memmove_long_repeat_emit_encodeBlockAsm: + ADD R8, R1, R5 + + // genMemMoveLong + MOVD R9, R10 + MOVD R1, R11 + MOVD R8, R12 + +emit_lit_memmove_long_repeat_emit_encodeBlockAsmlarge_big_loop_back: + FMOVQ (R10), F0 + FMOVQ 16(R10), F1 + FMOVQ F0, (R11) + FMOVQ F1, 16(R11) + ADD $0x20, R10, R10 + ADD $0x20, R11, R11 + SUB $0x20, R12, R12 + CMP $0x20, R12 + BHS emit_lit_memmove_long_repeat_emit_encodeBlockAsmlarge_big_loop_back + ADD R8, R9, R15 + FMOVQ -32(R15), F0 + ADD R8, R9, R15 + FMOVQ -16(R15), F1 + ADD R8, R1, R15 + FMOVQ F0, -32(R15) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + MOVD R5, R1 + +emit_literal_done_repeat_emit_encodeBlockAsm: + ADDW $0x05, R2, R2 + MOVWU R2, R5 + MOVWU 24(RSP), R16 + SUBW R16, R5, R5 + MOVD src_len+32(FP), R8 + SUBW R2, R8, R8 + ADD R2, R3, R9 + ADD R5, R3, R5 + + // matchLen + MOVD $0, R11 + +matchlen_loopback_16_repeat_extend_encodeBlockAsm: + CMPW $0x10, R8 + BLO matchlen_match8_repeat_extend_encodeBlockAsm + MOVD (R9)(R11), R10 + ADD R11, R9, R15 + MOVD 8(R15), R12 + MOVD (R5)(R11), R16 + EOR R16, R10, R10 + TST R10, R10 + BNE matchlen_bsf_8_repeat_extend_encodeBlockAsm + ADD R11, R5, R15 + MOVD 8(R15), R16 + EOR R16, R12, R12 + TST R12, R12 + BNE matchlen_bsf_16repeat_extend_encodeBlockAsm + SUB $16, R8, R8 + MOVWU R8, R8 + ADD $16, R11, R11 + MOVWU R11, R11 + JMP matchlen_loopback_16_repeat_extend_encodeBlockAsm + +matchlen_bsf_16repeat_extend_encodeBlockAsm: + RBIT R12, R12 + CLZ R12, R12 + ASR $0x03, R12, R12 + ADD R12, R11, R11 + ADD $8, R11, R11 + MOVWU R11, R11 + JMP repeat_extend_forward_end_encodeBlockAsm + +matchlen_match8_repeat_extend_encodeBlockAsm: + CMPW $0x08, R8 + BLO matchlen_match4_repeat_extend_encodeBlockAsm + MOVD (R9)(R11), R10 + MOVD (R5)(R11), R16 + EOR R16, R10, R10 + TST R10, R10 + BNE matchlen_bsf_8_repeat_extend_encodeBlockAsm + SUB $8, R8, R8 + MOVWU R8, R8 + ADD $8, R11, R11 + MOVWU R11, R11 + JMP matchlen_match4_repeat_extend_encodeBlockAsm + +matchlen_bsf_8_repeat_extend_encodeBlockAsm: + RBIT R10, R10 + CLZ R10, R10 + ASR $0x03, R10, R10 + ADD R10, R11, R11 + MOVWU R11, R11 + JMP repeat_extend_forward_end_encodeBlockAsm + +matchlen_match4_repeat_extend_encodeBlockAsm: + CMPW $0x04, R8 + BLO matchlen_match2_repeat_extend_encodeBlockAsm + MOVWU (R9)(R11), R10 + MOVWU (R5)(R11), R16 + CMPW R10, R16 + BNE matchlen_match2_repeat_extend_encodeBlockAsm + SUB $4, R8, R8 + MOVWU R8, R8 + ADD $4, R11, R11 + MOVWU R11, R11 + +matchlen_match2_repeat_extend_encodeBlockAsm: + CMPW $0x01, R8 + BEQ matchlen_match1_repeat_extend_encodeBlockAsm + BLO repeat_extend_forward_end_encodeBlockAsm + MOVHU (R9)(R11), R16 + BFI $0, R16, $16, R10 + ADD R11, R5, R15 + MOVHU (R15), R15 + AND $0xffff, R10, R16 + CMP R16, R15 + BNE matchlen_match1_repeat_extend_encodeBlockAsm + ADD $2, R11, R11 + MOVWU R11, R11 + SUBSW $0x02, R8, R8 + BEQ repeat_extend_forward_end_encodeBlockAsm + +matchlen_match1_repeat_extend_encodeBlockAsm: + MOVBU (R9)(R11), R16 + BFI $0, R16, $8, R10 + ADD R11, R5, R15 + MOVBU (R15), R15 + AND $0xff, R10, R16 + CMP R16, R15 + BNE repeat_extend_forward_end_encodeBlockAsm + ADD $1, R11, R11 + MOVWU R11, R11 + +repeat_extend_forward_end_encodeBlockAsm: + ADDW R11, R2, R2 + MOVWU R2, R5 + SUBW R6, R5, R5 + MOVWU 24(RSP), R6 + TSTW R7, R7 + BEQ repeat_as_copy_encodeBlockAsm + + // emitRepeat +emit_repeat_again_match_repeat_encodeBlockAsm: + MOVWU R5, R7 + SUB $4, R5, R5 + MOVWU R5, R5 + CMPW $0x08, R7 + BLS repeat_two_match_repeat_encodeBlockAsm + CMPW $0x0c, R7 + BHS cant_repeat_two_offset_match_repeat_encodeBlockAsm + CMPW $0x00000800, R6 + BLO repeat_two_offset_match_repeat_encodeBlockAsm + +cant_repeat_two_offset_match_repeat_encodeBlockAsm: + CMPW $0x00000104, R5 + BLO repeat_three_match_repeat_encodeBlockAsm + CMPW $0x00010100, R5 + BLO repeat_four_match_repeat_encodeBlockAsm + CMPW $0x0100ffff, R5 + BLO repeat_five_match_repeat_encodeBlockAsm + SUB $16842747, R5, R5 + MOVWU R5, R5 + MOVD $0xfffb001d, R16 + MOVW R16, (R1) + MOVD $0xff, R16 + MOVB R16, 4(R1) + ADD $0x05, R1, R1 + JMP emit_repeat_again_match_repeat_encodeBlockAsm + +repeat_five_match_repeat_encodeBlockAsm: + SUB $65536, R5, R5 + MOVWU R5, R5 + MOVWU R5, R6 + MOVD $0x001d, R16 + MOVH R16, (R1) + MOVH R5, 2(R1) + ASRW $0x10, R6, R6 + MOVB R6, 4(R1) + ADD $0x05, R1, R1 + JMP repeat_end_emit_encodeBlockAsm + +repeat_four_match_repeat_encodeBlockAsm: + SUB $256, R5, R5 + MOVWU R5, R5 + MOVD $0x0019, R16 + MOVH R16, (R1) + MOVH R5, 2(R1) + ADD $0x04, R1, R1 + JMP repeat_end_emit_encodeBlockAsm + +repeat_three_match_repeat_encodeBlockAsm: + SUB $4, R5, R5 + MOVWU R5, R5 + MOVD $0x0015, R16 + MOVH R16, (R1) + MOVB R5, 2(R1) + ADD $0x03, R1, R1 + JMP repeat_end_emit_encodeBlockAsm + +repeat_two_match_repeat_encodeBlockAsm: + LSLW $0x02, R5, R5 + ORRW $0x01, R5, R5 + MOVH R5, (R1) + ADD $0x02, R1, R1 + JMP repeat_end_emit_encodeBlockAsm + +repeat_two_offset_match_repeat_encodeBlockAsm: + MOVD $0, R7 + ADD R5<<2, R7, R5 + ADD $1, R5, R5 + MOVWU R5, R5 + MOVB R6, 1(R1) + ASRW $0x08, R6, R6 + LSLW $0x05, R6, R6 + ORRW R6, R5, R5 + MOVB R5, (R1) + ADD $0x02, R1, R1 + JMP repeat_end_emit_encodeBlockAsm + +repeat_as_copy_encodeBlockAsm: + // emitCopy + CMPW $0x00010000, R6 + BLO two_byte_offset_repeat_as_copy_encodeBlockAsm + CMPW $0x40, R5 + BLS four_bytes_remain_repeat_as_copy_encodeBlockAsm + MOVD $0xff, R16 + MOVB R16, (R1) + MOVW R6, 1(R1) + SUB $64, R5, R5 + MOVWU R5, R5 + ADD $0x05, R1, R1 + CMPW $0x04, R5 + BLO four_bytes_remain_repeat_as_copy_encodeBlockAsm + + // emitRepeat +emit_repeat_again_repeat_as_copy_encodeBlockAsm_emit_copy: + MOVWU R5, R7 + SUB $4, R5, R5 + MOVWU R5, R5 + CMPW $0x08, R7 + BLS repeat_two_repeat_as_copy_encodeBlockAsm_emit_copy + CMPW $0x0c, R7 + BHS cant_repeat_two_offset_repeat_as_copy_encodeBlockAsm_emit_copy + CMPW $0x00000800, R6 + BLO repeat_two_offset_repeat_as_copy_encodeBlockAsm_emit_copy + +cant_repeat_two_offset_repeat_as_copy_encodeBlockAsm_emit_copy: + CMPW $0x00000104, R5 + BLO repeat_three_repeat_as_copy_encodeBlockAsm_emit_copy + CMPW $0x00010100, R5 + BLO repeat_four_repeat_as_copy_encodeBlockAsm_emit_copy + CMPW $0x0100ffff, R5 + BLO repeat_five_repeat_as_copy_encodeBlockAsm_emit_copy + SUB $16842747, R5, R5 + MOVWU R5, R5 + MOVD $0xfffb001d, R16 + MOVW R16, (R1) + MOVD $0xff, R16 + MOVB R16, 4(R1) + ADD $0x05, R1, R1 + JMP emit_repeat_again_repeat_as_copy_encodeBlockAsm_emit_copy + +repeat_five_repeat_as_copy_encodeBlockAsm_emit_copy: + SUB $65536, R5, R5 + MOVWU R5, R5 + MOVWU R5, R6 + MOVD $0x001d, R16 + MOVH R16, (R1) + MOVH R5, 2(R1) + ASRW $0x10, R6, R6 + MOVB R6, 4(R1) + ADD $0x05, R1, R1 + JMP repeat_end_emit_encodeBlockAsm + +repeat_four_repeat_as_copy_encodeBlockAsm_emit_copy: + SUB $256, R5, R5 + MOVWU R5, R5 + MOVD $0x0019, R16 + MOVH R16, (R1) + MOVH R5, 2(R1) + ADD $0x04, R1, R1 + JMP repeat_end_emit_encodeBlockAsm + +repeat_three_repeat_as_copy_encodeBlockAsm_emit_copy: + SUB $4, R5, R5 + MOVWU R5, R5 + MOVD $0x0015, R16 + MOVH R16, (R1) + MOVB R5, 2(R1) + ADD $0x03, R1, R1 + JMP repeat_end_emit_encodeBlockAsm + +repeat_two_repeat_as_copy_encodeBlockAsm_emit_copy: + LSLW $0x02, R5, R5 + ORRW $0x01, R5, R5 + MOVH R5, (R1) + ADD $0x02, R1, R1 + JMP repeat_end_emit_encodeBlockAsm + +repeat_two_offset_repeat_as_copy_encodeBlockAsm_emit_copy: + MOVD $0, R7 + ADD R5<<2, R7, R5 + ADD $1, R5, R5 + MOVWU R5, R5 + MOVB R6, 1(R1) + ASRW $0x08, R6, R6 + LSLW $0x05, R6, R6 + ORRW R6, R5, R5 + MOVB R5, (R1) + ADD $0x02, R1, R1 + JMP repeat_end_emit_encodeBlockAsm + +four_bytes_remain_repeat_as_copy_encodeBlockAsm: + TSTW R5, R5 + BEQ repeat_end_emit_encodeBlockAsm + MOVD $0, R7 + ADD R5<<2, R7, R5 + SUB $1, R5, R5 + MOVWU R5, R5 + MOVB R5, (R1) + MOVW R6, 1(R1) + ADD $0x05, R1, R1 + JMP repeat_end_emit_encodeBlockAsm + +two_byte_offset_repeat_as_copy_encodeBlockAsm: + CMPW $0x40, R5 + BLS two_byte_offset_short_repeat_as_copy_encodeBlockAsm + CMPW $0x00000800, R6 + BHS long_offset_short_repeat_as_copy_encodeBlockAsm + MOVD $0x00000001, R7 + ADD $16, R7, R7 + MOVWU R7, R7 + MOVB R6, 1(R1) + MOVWU R6, R8 + LSRW $0x08, R8, R8 + LSLW $0x05, R8, R8 + ORRW R8, R7, R7 + MOVB R7, (R1) + ADD $0x02, R1, R1 + SUBW $0x08, R5, R5 + + // emitRepeat + SUB $4, R5, R5 + MOVWU R5, R5 + JMP cant_repeat_two_offset_repeat_as_copy_encodeBlockAsm_emit_copy_short_2b + +emit_repeat_again_repeat_as_copy_encodeBlockAsm_emit_copy_short_2b: + MOVWU R5, R7 + SUB $4, R5, R5 + MOVWU R5, R5 + CMPW $0x08, R7 + BLS repeat_two_repeat_as_copy_encodeBlockAsm_emit_copy_short_2b + CMPW $0x0c, R7 + BHS cant_repeat_two_offset_repeat_as_copy_encodeBlockAsm_emit_copy_short_2b + CMPW $0x00000800, R6 + BLO repeat_two_offset_repeat_as_copy_encodeBlockAsm_emit_copy_short_2b + +cant_repeat_two_offset_repeat_as_copy_encodeBlockAsm_emit_copy_short_2b: + CMPW $0x00000104, R5 + BLO repeat_three_repeat_as_copy_encodeBlockAsm_emit_copy_short_2b + CMPW $0x00010100, R5 + BLO repeat_four_repeat_as_copy_encodeBlockAsm_emit_copy_short_2b + CMPW $0x0100ffff, R5 + BLO repeat_five_repeat_as_copy_encodeBlockAsm_emit_copy_short_2b + SUB $16842747, R5, R5 + MOVWU R5, R5 + MOVD $0xfffb001d, R16 + MOVW R16, (R1) + MOVD $0xff, R16 + MOVB R16, 4(R1) + ADD $0x05, R1, R1 + JMP emit_repeat_again_repeat_as_copy_encodeBlockAsm_emit_copy_short_2b + +repeat_five_repeat_as_copy_encodeBlockAsm_emit_copy_short_2b: + SUB $65536, R5, R5 + MOVWU R5, R5 + MOVWU R5, R6 + MOVD $0x001d, R16 + MOVH R16, (R1) + MOVH R5, 2(R1) + ASRW $0x10, R6, R6 + MOVB R6, 4(R1) + ADD $0x05, R1, R1 + JMP repeat_end_emit_encodeBlockAsm + +repeat_four_repeat_as_copy_encodeBlockAsm_emit_copy_short_2b: + SUB $256, R5, R5 + MOVWU R5, R5 + MOVD $0x0019, R16 + MOVH R16, (R1) + MOVH R5, 2(R1) + ADD $0x04, R1, R1 + JMP repeat_end_emit_encodeBlockAsm + +repeat_three_repeat_as_copy_encodeBlockAsm_emit_copy_short_2b: + SUB $4, R5, R5 + MOVWU R5, R5 + MOVD $0x0015, R16 + MOVH R16, (R1) + MOVB R5, 2(R1) + ADD $0x03, R1, R1 + JMP repeat_end_emit_encodeBlockAsm + +repeat_two_repeat_as_copy_encodeBlockAsm_emit_copy_short_2b: + LSLW $0x02, R5, R5 + ORRW $0x01, R5, R5 + MOVH R5, (R1) + ADD $0x02, R1, R1 + JMP repeat_end_emit_encodeBlockAsm + +repeat_two_offset_repeat_as_copy_encodeBlockAsm_emit_copy_short_2b: + MOVD $0, R7 + ADD R5<<2, R7, R5 + ADD $1, R5, R5 + MOVWU R5, R5 + MOVB R6, 1(R1) + ASRW $0x08, R6, R6 + LSLW $0x05, R6, R6 + ORRW R6, R5, R5 + MOVB R5, (R1) + ADD $0x02, R1, R1 + JMP repeat_end_emit_encodeBlockAsm + +long_offset_short_repeat_as_copy_encodeBlockAsm: + MOVD $0xee, R16 + MOVB R16, (R1) + MOVH R6, 1(R1) + SUB $60, R5, R5 + MOVWU R5, R5 + ADD $0x03, R1, R1 + + // emitRepeat +emit_repeat_again_repeat_as_copy_encodeBlockAsm_emit_copy_short: + MOVWU R5, R7 + SUB $4, R5, R5 + MOVWU R5, R5 + CMPW $0x08, R7 + BLS repeat_two_repeat_as_copy_encodeBlockAsm_emit_copy_short + CMPW $0x0c, R7 + BHS cant_repeat_two_offset_repeat_as_copy_encodeBlockAsm_emit_copy_short + CMPW $0x00000800, R6 + BLO repeat_two_offset_repeat_as_copy_encodeBlockAsm_emit_copy_short + +cant_repeat_two_offset_repeat_as_copy_encodeBlockAsm_emit_copy_short: + CMPW $0x00000104, R5 + BLO repeat_three_repeat_as_copy_encodeBlockAsm_emit_copy_short + CMPW $0x00010100, R5 + BLO repeat_four_repeat_as_copy_encodeBlockAsm_emit_copy_short + CMPW $0x0100ffff, R5 + BLO repeat_five_repeat_as_copy_encodeBlockAsm_emit_copy_short + SUB $16842747, R5, R5 + MOVWU R5, R5 + MOVD $0xfffb001d, R16 + MOVW R16, (R1) + MOVD $0xff, R16 + MOVB R16, 4(R1) + ADD $0x05, R1, R1 + JMP emit_repeat_again_repeat_as_copy_encodeBlockAsm_emit_copy_short + +repeat_five_repeat_as_copy_encodeBlockAsm_emit_copy_short: + SUB $65536, R5, R5 + MOVWU R5, R5 + MOVWU R5, R6 + MOVD $0x001d, R16 + MOVH R16, (R1) + MOVH R5, 2(R1) + ASRW $0x10, R6, R6 + MOVB R6, 4(R1) + ADD $0x05, R1, R1 + JMP repeat_end_emit_encodeBlockAsm + +repeat_four_repeat_as_copy_encodeBlockAsm_emit_copy_short: + SUB $256, R5, R5 + MOVWU R5, R5 + MOVD $0x0019, R16 + MOVH R16, (R1) + MOVH R5, 2(R1) + ADD $0x04, R1, R1 + JMP repeat_end_emit_encodeBlockAsm + +repeat_three_repeat_as_copy_encodeBlockAsm_emit_copy_short: + SUB $4, R5, R5 + MOVWU R5, R5 + MOVD $0x0015, R16 + MOVH R16, (R1) + MOVB R5, 2(R1) + ADD $0x03, R1, R1 + JMP repeat_end_emit_encodeBlockAsm + +repeat_two_repeat_as_copy_encodeBlockAsm_emit_copy_short: + LSLW $0x02, R5, R5 + ORRW $0x01, R5, R5 + MOVH R5, (R1) + ADD $0x02, R1, R1 + JMP repeat_end_emit_encodeBlockAsm + +repeat_two_offset_repeat_as_copy_encodeBlockAsm_emit_copy_short: + MOVD $0, R7 + ADD R5<<2, R7, R5 + ADD $1, R5, R5 + MOVWU R5, R5 + MOVB R6, 1(R1) + ASRW $0x08, R6, R6 + LSLW $0x05, R6, R6 + ORRW R6, R5, R5 + MOVB R5, (R1) + ADD $0x02, R1, R1 + JMP repeat_end_emit_encodeBlockAsm + +two_byte_offset_short_repeat_as_copy_encodeBlockAsm: + MOVWU R5, R7 + LSLW $0x02, R7, R7 + CMPW $0x0c, R5 + BHS emit_copy_three_repeat_as_copy_encodeBlockAsm + CMPW $0x00000800, R6 + BHS emit_copy_three_repeat_as_copy_encodeBlockAsm + SUB $15, R7, R7 + MOVWU R7, R7 + MOVB R6, 1(R1) + LSRW $0x08, R6, R6 + LSLW $0x05, R6, R6 + ORRW R6, R7, R7 + MOVB R7, (R1) + ADD $0x02, R1, R1 + JMP repeat_end_emit_encodeBlockAsm + +emit_copy_three_repeat_as_copy_encodeBlockAsm: + SUB $2, R7, R7 + MOVWU R7, R7 + MOVB R7, (R1) + MOVH R6, 1(R1) + ADD $0x03, R1, R1 + +repeat_end_emit_encodeBlockAsm: + MOVW R2, 20(RSP) + JMP search_loop_encodeBlockAsm + +no_repeat_found_encodeBlockAsm: + MOVWU (R3)(R5), R16 + CMPW R6, R16 + BEQ candidate_match_encodeBlockAsm + LSR $0x08, R6, R6 + MOVWU (R0)(R9<<2), R5 + ADD $2, R2, R8 + MOVWU R8, R8 + MOVWU (R3)(R7), R16 + CMPW R6, R16 + BEQ candidate2_match_encodeBlockAsm + MOVW R8, (R0)(R9<<2) + LSR $0x08, R6, R6 + MOVWU (R3)(R5), R16 + CMPW R6, R16 + BEQ candidate3_match_encodeBlockAsm + MOVWU 28(RSP), R2 + JMP search_loop_encodeBlockAsm + +candidate3_match_encodeBlockAsm: + ADDW $0x02, R2, R2 + JMP candidate_match_encodeBlockAsm + +candidate2_match_encodeBlockAsm: + MOVW R8, (R0)(R9<<2) + ADDW $1, R2, R2 + MOVWU R7, R5 + +candidate_match_encodeBlockAsm: + MOVWU 20(RSP), R6 + TSTW R5, R5 + BEQ match_extend_back_end_encodeBlockAsm + +match_extend_back_loop_encodeBlockAsm: + CMPW R6, R2 + BLS match_extend_back_end_encodeBlockAsm + ADD R5, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R7 + ADD R2, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R8 + AND $0xff, R8, R16 + AND $0xff, R7, R15 + CMP R16, R15 + BNE match_extend_back_end_encodeBlockAsm + SUB $1, R2, R2 + MOVWU R2, R2 + SUBSW $1, R5, R5 + BEQ match_extend_back_end_encodeBlockAsm + JMP match_extend_back_loop_encodeBlockAsm + +match_extend_back_end_encodeBlockAsm: + MOVWU R2, R6 + MOVWU 20(RSP), R16 + SUBW R16, R6, R6 + ADD R6, R1, R6 + ADD $5, R6, R6 + MOVD 8(RSP), R16 + CMP R16, R6 + BLO match_dst_size_check_encodeBlockAsm + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +match_dst_size_check_encodeBlockAsm: + MOVWU R2, R6 + MOVWU 20(RSP), R7 + CMPW R6, R7 + BEQ emit_literal_done_match_emit_encodeBlockAsm + MOVWU R6, R8 + MOVW R6, 20(RSP) + ADD R7, R3, R6 + SUBW R7, R8, R8 + SUB $1, R8, R7 + MOVWU R7, R7 + CMPW $0x3c, R7 + BLO one_byte_match_emit_encodeBlockAsm + CMPW $0x00000100, R7 + BLO two_bytes_match_emit_encodeBlockAsm + CMPW $0x00010000, R7 + BLO three_bytes_match_emit_encodeBlockAsm + CMPW $0x01000000, R7 + BLO four_bytes_match_emit_encodeBlockAsm + MOVD $0xfc, R16 + MOVB R16, (R1) + MOVW R7, 1(R1) + ADD $0x05, R1, R1 + JMP memmove_long_match_emit_encodeBlockAsm + +four_bytes_match_emit_encodeBlockAsm: + MOVWU R7, R9 + LSRW $0x10, R9, R9 + MOVD $0xf8, R16 + MOVB R16, (R1) + MOVH R7, 1(R1) + MOVB R9, 3(R1) + ADD $0x04, R1, R1 + JMP memmove_long_match_emit_encodeBlockAsm + +three_bytes_match_emit_encodeBlockAsm: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R7, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_match_emit_encodeBlockAsm + +two_bytes_match_emit_encodeBlockAsm: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R7, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R7 + BLO memmove_match_emit_encodeBlockAsm + JMP memmove_long_match_emit_encodeBlockAsm + +one_byte_match_emit_encodeBlockAsm: + LSLW $0x02, R7, R16 + BFI $0, R16, $8, R7 + MOVB R7, (R1) + ADD $0x01, R1, R1 + +memmove_match_emit_encodeBlockAsm: + ADD R8, R1, R7 + + // genMemMoveShort + CMP $0x08, R8 + BLS emit_lit_memmove_match_emit_encodeBlockAsm_memmove_move_8 + CMP $0x10, R8 + BLS emit_lit_memmove_match_emit_encodeBlockAsm_memmove_move_8through16 + CMP $0x20, R8 + BLS emit_lit_memmove_match_emit_encodeBlockAsm_memmove_move_17through32 + JMP emit_lit_memmove_match_emit_encodeBlockAsm_memmove_move_33through64 + +emit_lit_memmove_match_emit_encodeBlockAsm_memmove_move_8: + MOVD (R6), R9 + MOVD R9, (R1) + JMP memmove_end_copy_match_emit_encodeBlockAsm + +emit_lit_memmove_match_emit_encodeBlockAsm_memmove_move_8through16: + MOVD (R6), R9 + ADD R8, R6, R15 + MOVD -8(R15), R6 + MOVD R9, (R1) + ADD R8, R1, R15 + MOVD R6, -8(R15) + JMP memmove_end_copy_match_emit_encodeBlockAsm + +emit_lit_memmove_match_emit_encodeBlockAsm_memmove_move_17through32: + FMOVQ (R6), F0 + ADD R8, R6, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_match_emit_encodeBlockAsm + +emit_lit_memmove_match_emit_encodeBlockAsm_memmove_move_33through64: + FMOVQ (R6), F0 + FMOVQ 16(R6), F1 + ADD R8, R6, R15 + FMOVQ -32(R15), F2 + ADD R8, R6, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R8, R1, R15 + FMOVQ F2, -32(R15) + ADD R8, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_match_emit_encodeBlockAsm: + MOVD R7, R1 + JMP emit_literal_done_match_emit_encodeBlockAsm + +memmove_long_match_emit_encodeBlockAsm: + ADD R8, R1, R7 + + // genMemMoveLong + MOVD R6, R9 + MOVD R1, R10 + MOVD R8, R11 + +emit_lit_memmove_long_match_emit_encodeBlockAsmlarge_big_loop_back: + FMOVQ (R9), F0 + FMOVQ 16(R9), F1 + FMOVQ F0, (R10) + FMOVQ F1, 16(R10) + ADD $0x20, R9, R9 + ADD $0x20, R10, R10 + SUB $0x20, R11, R11 + CMP $0x20, R11 + BHS emit_lit_memmove_long_match_emit_encodeBlockAsmlarge_big_loop_back + ADD R8, R6, R15 + FMOVQ -32(R15), F0 + ADD R8, R6, R15 + FMOVQ -16(R15), F1 + ADD R8, R1, R15 + FMOVQ F0, -32(R15) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + MOVD R7, R1 + +emit_literal_done_match_emit_encodeBlockAsm: +match_nolit_loop_encodeBlockAsm: + MOVWU R2, R6 + SUBW R5, R6, R6 + MOVW R6, 24(RSP) + ADDW $0x04, R2, R2 + ADDW $0x04, R5, R5 + MOVD src_len+32(FP), R6 + SUBW R2, R6, R6 + ADD R2, R3, R7 + ADD R5, R3, R5 + + // matchLen + MOVD $0, R9 + +matchlen_loopback_16_match_nolit_encodeBlockAsm: + CMPW $0x10, R6 + BLO matchlen_match8_match_nolit_encodeBlockAsm + MOVD (R7)(R9), R8 + ADD R9, R7, R15 + MOVD 8(R15), R10 + MOVD (R5)(R9), R16 + EOR R16, R8, R8 + TST R8, R8 + BNE matchlen_bsf_8_match_nolit_encodeBlockAsm + ADD R9, R5, R15 + MOVD 8(R15), R16 + EOR R16, R10, R10 + TST R10, R10 + BNE matchlen_bsf_16match_nolit_encodeBlockAsm + SUB $16, R6, R6 + MOVWU R6, R6 + ADD $16, R9, R9 + MOVWU R9, R9 + JMP matchlen_loopback_16_match_nolit_encodeBlockAsm + +matchlen_bsf_16match_nolit_encodeBlockAsm: + RBIT R10, R10 + CLZ R10, R10 + ASR $0x03, R10, R10 + ADD R10, R9, R9 + ADD $8, R9, R9 + MOVWU R9, R9 + JMP match_nolit_end_encodeBlockAsm + +matchlen_match8_match_nolit_encodeBlockAsm: + CMPW $0x08, R6 + BLO matchlen_match4_match_nolit_encodeBlockAsm + MOVD (R7)(R9), R8 + MOVD (R5)(R9), R16 + EOR R16, R8, R8 + TST R8, R8 + BNE matchlen_bsf_8_match_nolit_encodeBlockAsm + SUB $8, R6, R6 + MOVWU R6, R6 + ADD $8, R9, R9 + MOVWU R9, R9 + JMP matchlen_match4_match_nolit_encodeBlockAsm + +matchlen_bsf_8_match_nolit_encodeBlockAsm: + RBIT R8, R8 + CLZ R8, R8 + ASR $0x03, R8, R8 + ADD R8, R9, R9 + MOVWU R9, R9 + JMP match_nolit_end_encodeBlockAsm + +matchlen_match4_match_nolit_encodeBlockAsm: + CMPW $0x04, R6 + BLO matchlen_match2_match_nolit_encodeBlockAsm + MOVWU (R7)(R9), R8 + MOVWU (R5)(R9), R16 + CMPW R8, R16 + BNE matchlen_match2_match_nolit_encodeBlockAsm + SUB $4, R6, R6 + MOVWU R6, R6 + ADD $4, R9, R9 + MOVWU R9, R9 + +matchlen_match2_match_nolit_encodeBlockAsm: + CMPW $0x01, R6 + BEQ matchlen_match1_match_nolit_encodeBlockAsm + BLO match_nolit_end_encodeBlockAsm + MOVHU (R7)(R9), R16 + BFI $0, R16, $16, R8 + ADD R9, R5, R15 + MOVHU (R15), R15 + AND $0xffff, R8, R16 + CMP R16, R15 + BNE matchlen_match1_match_nolit_encodeBlockAsm + ADD $2, R9, R9 + MOVWU R9, R9 + SUBSW $0x02, R6, R6 + BEQ match_nolit_end_encodeBlockAsm + +matchlen_match1_match_nolit_encodeBlockAsm: + MOVBU (R7)(R9), R16 + BFI $0, R16, $8, R8 + ADD R9, R5, R15 + MOVBU (R15), R15 + AND $0xff, R8, R16 + CMP R16, R15 + BNE match_nolit_end_encodeBlockAsm + ADD $1, R9, R9 + MOVWU R9, R9 + +match_nolit_end_encodeBlockAsm: + ADDW R9, R2, R2 + MOVWU 24(RSP), R5 + ADDW $0x04, R9, R9 + MOVW R2, 20(RSP) + + // emitCopy + CMPW $0x00010000, R5 + BLO two_byte_offset_match_nolit_encodeBlockAsm + CMPW $0x40, R9 + BLS four_bytes_remain_match_nolit_encodeBlockAsm + MOVD $0xff, R16 + MOVB R16, (R1) + MOVW R5, 1(R1) + SUB $64, R9, R9 + MOVWU R9, R9 + ADD $0x05, R1, R1 + CMPW $0x04, R9 + BLO four_bytes_remain_match_nolit_encodeBlockAsm + + // emitRepeat +emit_repeat_again_match_nolit_encodeBlockAsm_emit_copy: + MOVWU R9, R6 + SUB $4, R9, R9 + MOVWU R9, R9 + CMPW $0x08, R6 + BLS repeat_two_match_nolit_encodeBlockAsm_emit_copy + CMPW $0x0c, R6 + BHS cant_repeat_two_offset_match_nolit_encodeBlockAsm_emit_copy + CMPW $0x00000800, R5 + BLO repeat_two_offset_match_nolit_encodeBlockAsm_emit_copy + +cant_repeat_two_offset_match_nolit_encodeBlockAsm_emit_copy: + CMPW $0x00000104, R9 + BLO repeat_three_match_nolit_encodeBlockAsm_emit_copy + CMPW $0x00010100, R9 + BLO repeat_four_match_nolit_encodeBlockAsm_emit_copy + CMPW $0x0100ffff, R9 + BLO repeat_five_match_nolit_encodeBlockAsm_emit_copy + SUB $16842747, R9, R9 + MOVWU R9, R9 + MOVD $0xfffb001d, R16 + MOVW R16, (R1) + MOVD $0xff, R16 + MOVB R16, 4(R1) + ADD $0x05, R1, R1 + JMP emit_repeat_again_match_nolit_encodeBlockAsm_emit_copy + +repeat_five_match_nolit_encodeBlockAsm_emit_copy: + SUB $65536, R9, R9 + MOVWU R9, R9 + MOVWU R9, R5 + MOVD $0x001d, R16 + MOVH R16, (R1) + MOVH R9, 2(R1) + ASRW $0x10, R5, R5 + MOVB R5, 4(R1) + ADD $0x05, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm + +repeat_four_match_nolit_encodeBlockAsm_emit_copy: + SUB $256, R9, R9 + MOVWU R9, R9 + MOVD $0x0019, R16 + MOVH R16, (R1) + MOVH R9, 2(R1) + ADD $0x04, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm + +repeat_three_match_nolit_encodeBlockAsm_emit_copy: + SUB $4, R9, R9 + MOVWU R9, R9 + MOVD $0x0015, R16 + MOVH R16, (R1) + MOVB R9, 2(R1) + ADD $0x03, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm + +repeat_two_match_nolit_encodeBlockAsm_emit_copy: + LSLW $0x02, R9, R9 + ORRW $0x01, R9, R9 + MOVH R9, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm + +repeat_two_offset_match_nolit_encodeBlockAsm_emit_copy: + MOVD $0, R6 + ADD R9<<2, R6, R9 + ADD $1, R9, R9 + MOVWU R9, R9 + MOVB R5, 1(R1) + ASRW $0x08, R5, R5 + LSLW $0x05, R5, R5 + ORRW R5, R9, R9 + MOVB R9, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm + +four_bytes_remain_match_nolit_encodeBlockAsm: + TSTW R9, R9 + BEQ match_nolit_emitcopy_end_encodeBlockAsm + MOVD $0, R6 + ADD R9<<2, R6, R9 + SUB $1, R9, R9 + MOVWU R9, R9 + MOVB R9, (R1) + MOVW R5, 1(R1) + ADD $0x05, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm + +two_byte_offset_match_nolit_encodeBlockAsm: + CMPW $0x40, R9 + BLS two_byte_offset_short_match_nolit_encodeBlockAsm + CMPW $0x00000800, R5 + BHS long_offset_short_match_nolit_encodeBlockAsm + MOVD $0x00000001, R6 + ADD $16, R6, R6 + MOVWU R6, R6 + MOVB R5, 1(R1) + MOVWU R5, R7 + LSRW $0x08, R7, R7 + LSLW $0x05, R7, R7 + ORRW R7, R6, R6 + MOVB R6, (R1) + ADD $0x02, R1, R1 + SUBW $0x08, R9, R9 + + // emitRepeat + SUB $4, R9, R9 + MOVWU R9, R9 + JMP cant_repeat_two_offset_match_nolit_encodeBlockAsm_emit_copy_short_2b + +emit_repeat_again_match_nolit_encodeBlockAsm_emit_copy_short_2b: + MOVWU R9, R6 + SUB $4, R9, R9 + MOVWU R9, R9 + CMPW $0x08, R6 + BLS repeat_two_match_nolit_encodeBlockAsm_emit_copy_short_2b + CMPW $0x0c, R6 + BHS cant_repeat_two_offset_match_nolit_encodeBlockAsm_emit_copy_short_2b + CMPW $0x00000800, R5 + BLO repeat_two_offset_match_nolit_encodeBlockAsm_emit_copy_short_2b + +cant_repeat_two_offset_match_nolit_encodeBlockAsm_emit_copy_short_2b: + CMPW $0x00000104, R9 + BLO repeat_three_match_nolit_encodeBlockAsm_emit_copy_short_2b + CMPW $0x00010100, R9 + BLO repeat_four_match_nolit_encodeBlockAsm_emit_copy_short_2b + CMPW $0x0100ffff, R9 + BLO repeat_five_match_nolit_encodeBlockAsm_emit_copy_short_2b + SUB $16842747, R9, R9 + MOVWU R9, R9 + MOVD $0xfffb001d, R16 + MOVW R16, (R1) + MOVD $0xff, R16 + MOVB R16, 4(R1) + ADD $0x05, R1, R1 + JMP emit_repeat_again_match_nolit_encodeBlockAsm_emit_copy_short_2b + +repeat_five_match_nolit_encodeBlockAsm_emit_copy_short_2b: + SUB $65536, R9, R9 + MOVWU R9, R9 + MOVWU R9, R5 + MOVD $0x001d, R16 + MOVH R16, (R1) + MOVH R9, 2(R1) + ASRW $0x10, R5, R5 + MOVB R5, 4(R1) + ADD $0x05, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm + +repeat_four_match_nolit_encodeBlockAsm_emit_copy_short_2b: + SUB $256, R9, R9 + MOVWU R9, R9 + MOVD $0x0019, R16 + MOVH R16, (R1) + MOVH R9, 2(R1) + ADD $0x04, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm + +repeat_three_match_nolit_encodeBlockAsm_emit_copy_short_2b: + SUB $4, R9, R9 + MOVWU R9, R9 + MOVD $0x0015, R16 + MOVH R16, (R1) + MOVB R9, 2(R1) + ADD $0x03, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm + +repeat_two_match_nolit_encodeBlockAsm_emit_copy_short_2b: + LSLW $0x02, R9, R9 + ORRW $0x01, R9, R9 + MOVH R9, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm + +repeat_two_offset_match_nolit_encodeBlockAsm_emit_copy_short_2b: + MOVD $0, R6 + ADD R9<<2, R6, R9 + ADD $1, R9, R9 + MOVWU R9, R9 + MOVB R5, 1(R1) + ASRW $0x08, R5, R5 + LSLW $0x05, R5, R5 + ORRW R5, R9, R9 + MOVB R9, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm + +long_offset_short_match_nolit_encodeBlockAsm: + MOVD $0xee, R16 + MOVB R16, (R1) + MOVH R5, 1(R1) + SUB $60, R9, R9 + MOVWU R9, R9 + ADD $0x03, R1, R1 + + // emitRepeat +emit_repeat_again_match_nolit_encodeBlockAsm_emit_copy_short: + MOVWU R9, R6 + SUB $4, R9, R9 + MOVWU R9, R9 + CMPW $0x08, R6 + BLS repeat_two_match_nolit_encodeBlockAsm_emit_copy_short + CMPW $0x0c, R6 + BHS cant_repeat_two_offset_match_nolit_encodeBlockAsm_emit_copy_short + CMPW $0x00000800, R5 + BLO repeat_two_offset_match_nolit_encodeBlockAsm_emit_copy_short + +cant_repeat_two_offset_match_nolit_encodeBlockAsm_emit_copy_short: + CMPW $0x00000104, R9 + BLO repeat_three_match_nolit_encodeBlockAsm_emit_copy_short + CMPW $0x00010100, R9 + BLO repeat_four_match_nolit_encodeBlockAsm_emit_copy_short + CMPW $0x0100ffff, R9 + BLO repeat_five_match_nolit_encodeBlockAsm_emit_copy_short + SUB $16842747, R9, R9 + MOVWU R9, R9 + MOVD $0xfffb001d, R16 + MOVW R16, (R1) + MOVD $0xff, R16 + MOVB R16, 4(R1) + ADD $0x05, R1, R1 + JMP emit_repeat_again_match_nolit_encodeBlockAsm_emit_copy_short + +repeat_five_match_nolit_encodeBlockAsm_emit_copy_short: + SUB $65536, R9, R9 + MOVWU R9, R9 + MOVWU R9, R5 + MOVD $0x001d, R16 + MOVH R16, (R1) + MOVH R9, 2(R1) + ASRW $0x10, R5, R5 + MOVB R5, 4(R1) + ADD $0x05, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm + +repeat_four_match_nolit_encodeBlockAsm_emit_copy_short: + SUB $256, R9, R9 + MOVWU R9, R9 + MOVD $0x0019, R16 + MOVH R16, (R1) + MOVH R9, 2(R1) + ADD $0x04, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm + +repeat_three_match_nolit_encodeBlockAsm_emit_copy_short: + SUB $4, R9, R9 + MOVWU R9, R9 + MOVD $0x0015, R16 + MOVH R16, (R1) + MOVB R9, 2(R1) + ADD $0x03, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm + +repeat_two_match_nolit_encodeBlockAsm_emit_copy_short: + LSLW $0x02, R9, R9 + ORRW $0x01, R9, R9 + MOVH R9, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm + +repeat_two_offset_match_nolit_encodeBlockAsm_emit_copy_short: + MOVD $0, R6 + ADD R9<<2, R6, R9 + ADD $1, R9, R9 + MOVWU R9, R9 + MOVB R5, 1(R1) + ASRW $0x08, R5, R5 + LSLW $0x05, R5, R5 + ORRW R5, R9, R9 + MOVB R9, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm + +two_byte_offset_short_match_nolit_encodeBlockAsm: + MOVWU R9, R6 + LSLW $0x02, R6, R6 + CMPW $0x0c, R9 + BHS emit_copy_three_match_nolit_encodeBlockAsm + CMPW $0x00000800, R5 + BHS emit_copy_three_match_nolit_encodeBlockAsm + SUB $15, R6, R6 + MOVWU R6, R6 + MOVB R5, 1(R1) + LSRW $0x08, R5, R5 + LSLW $0x05, R5, R5 + ORRW R5, R6, R6 + MOVB R6, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm + +emit_copy_three_match_nolit_encodeBlockAsm: + SUB $2, R6, R6 + MOVWU R6, R6 + MOVB R6, (R1) + MOVH R5, 1(R1) + ADD $0x03, R1, R1 + +match_nolit_emitcopy_end_encodeBlockAsm: + MOVWU 16(RSP), R16 + CMPW R16, R2 + BHS emit_remainder_encodeBlockAsm + ADD R2, R3, R15 + MOVD -2(R15), R6 + MOVD 8(RSP), R16 + CMP R16, R1 + BLO match_nolit_dst_ok_encodeBlockAsm + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +match_nolit_dst_ok_encodeBlockAsm: + MOVD $0x0000cf1bbcdcbf9b, R8 + MOVD R6, R7 + LSR $0x10, R6, R6 + MOVD R6, R5 + LSL $0x10, R7, R7 + MUL R8, R7, R7 + LSR $0x32, R7, R7 + LSL $0x10, R5, R5 + MUL R8, R5, R5 + LSR $0x32, R5, R5 + SUB $2, R2, R8 + MOVWU R8, R8 + ADD R5<<2, R0, R9 + MOVWU (R9), R5 + MOVW R8, (R0)(R7<<2) + MOVW R2, (R9) + MOVWU (R3)(R5), R16 + CMPW R6, R16 + BEQ match_nolit_loop_encodeBlockAsm + ADDW $1, R2, R2 + JMP search_loop_encodeBlockAsm + +emit_remainder_encodeBlockAsm: + MOVD src_len+32(FP), R0 + MOVWU 20(RSP), R16 + SUBW R16, R0, R0 + ADD R0, R1, R0 + ADD $5, R0, R0 + MOVD 8(RSP), R16 + CMP R16, R0 + BLO emit_remainder_ok_encodeBlockAsm + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +emit_remainder_ok_encodeBlockAsm: + MOVD src_len+32(FP), R0 + MOVWU 20(RSP), R2 + CMPW R0, R2 + BEQ emit_literal_done_emit_remainder_encodeBlockAsm + MOVWU R0, R5 + MOVW R0, 20(RSP) + ADD R2, R3, R0 + SUBW R2, R5, R5 + SUB $1, R5, R2 + MOVWU R2, R2 + CMPW $0x3c, R2 + BLO one_byte_emit_remainder_encodeBlockAsm + CMPW $0x00000100, R2 + BLO two_bytes_emit_remainder_encodeBlockAsm + CMPW $0x00010000, R2 + BLO three_bytes_emit_remainder_encodeBlockAsm + CMPW $0x01000000, R2 + BLO four_bytes_emit_remainder_encodeBlockAsm + MOVD $0xfc, R16 + MOVB R16, (R1) + MOVW R2, 1(R1) + ADD $0x05, R1, R1 + JMP memmove_long_emit_remainder_encodeBlockAsm + +four_bytes_emit_remainder_encodeBlockAsm: + MOVWU R2, R3 + LSRW $0x10, R3, R3 + MOVD $0xf8, R16 + MOVB R16, (R1) + MOVH R2, 1(R1) + MOVB R3, 3(R1) + ADD $0x04, R1, R1 + JMP memmove_long_emit_remainder_encodeBlockAsm + +three_bytes_emit_remainder_encodeBlockAsm: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R2, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_emit_remainder_encodeBlockAsm + +two_bytes_emit_remainder_encodeBlockAsm: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R2, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R2 + BLO memmove_emit_remainder_encodeBlockAsm + JMP memmove_long_emit_remainder_encodeBlockAsm + +one_byte_emit_remainder_encodeBlockAsm: + LSLW $0x02, R2, R16 + BFI $0, R16, $8, R2 + MOVB R2, (R1) + ADD $0x01, R1, R1 + +memmove_emit_remainder_encodeBlockAsm: + ADD R5, R1, R2 + MOVWU R5, R3 + + // genMemMoveShort + CMP $0x03, R3 + BLO emit_lit_memmove_emit_remainder_encodeBlockAsm_memmove_move_1or2 + BEQ emit_lit_memmove_emit_remainder_encodeBlockAsm_memmove_move_3 + CMP $0x08, R3 + BLO emit_lit_memmove_emit_remainder_encodeBlockAsm_memmove_move_4through7 + CMP $0x10, R3 + BLS emit_lit_memmove_emit_remainder_encodeBlockAsm_memmove_move_8through16 + CMP $0x20, R3 + BLS emit_lit_memmove_emit_remainder_encodeBlockAsm_memmove_move_17through32 + JMP emit_lit_memmove_emit_remainder_encodeBlockAsm_memmove_move_33through64 + +emit_lit_memmove_emit_remainder_encodeBlockAsm_memmove_move_1or2: + MOVBU (R0), R16 + BFI $0, R16, $8, R5 + ADD R3, R0, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R0 + MOVB R5, (R1) + ADD R3, R1, R15 + MOVB R0, -1(R15) + JMP memmove_end_copy_emit_remainder_encodeBlockAsm + +emit_lit_memmove_emit_remainder_encodeBlockAsm_memmove_move_3: + MOVHU (R0), R16 + BFI $0, R16, $16, R5 + MOVBU 2(R0), R16 + BFI $0, R16, $8, R0 + MOVH R5, (R1) + MOVB R0, 2(R1) + JMP memmove_end_copy_emit_remainder_encodeBlockAsm + +emit_lit_memmove_emit_remainder_encodeBlockAsm_memmove_move_4through7: + MOVWU (R0), R5 + ADD R3, R0, R15 + MOVWU -4(R15), R0 + MOVW R5, (R1) + ADD R3, R1, R15 + MOVW R0, -4(R15) + JMP memmove_end_copy_emit_remainder_encodeBlockAsm + +emit_lit_memmove_emit_remainder_encodeBlockAsm_memmove_move_8through16: + MOVD (R0), R5 + ADD R3, R0, R15 + MOVD -8(R15), R0 + MOVD R5, (R1) + ADD R3, R1, R15 + MOVD R0, -8(R15) + JMP memmove_end_copy_emit_remainder_encodeBlockAsm + +emit_lit_memmove_emit_remainder_encodeBlockAsm_memmove_move_17through32: + FMOVQ (R0), F0 + ADD R3, R0, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R3, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_emit_remainder_encodeBlockAsm + +emit_lit_memmove_emit_remainder_encodeBlockAsm_memmove_move_33through64: + FMOVQ (R0), F0 + FMOVQ 16(R0), F1 + ADD R3, R0, R15 + FMOVQ -32(R15), F2 + ADD R3, R0, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R3, R1, R15 + FMOVQ F2, -32(R15) + ADD R3, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_emit_remainder_encodeBlockAsm: + MOVD R2, R1 + JMP emit_literal_done_emit_remainder_encodeBlockAsm + +memmove_long_emit_remainder_encodeBlockAsm: + ADD R5, R1, R2 + MOVWU R5, R3 + + // genMemMoveLong + MOVD R0, R5 + MOVD R1, R6 + MOVD R3, R7 + +emit_lit_memmove_long_emit_remainder_encodeBlockAsmlarge_big_loop_back: + FMOVQ (R5), F0 + FMOVQ 16(R5), F1 + FMOVQ F0, (R6) + FMOVQ F1, 16(R6) + ADD $0x20, R5, R5 + ADD $0x20, R6, R6 + SUB $0x20, R7, R7 + CMP $0x20, R7 + BHS emit_lit_memmove_long_emit_remainder_encodeBlockAsmlarge_big_loop_back + ADD R3, R0, R15 + FMOVQ -32(R15), F0 + ADD R3, R0, R15 + FMOVQ -16(R15), F1 + ADD R3, R1, R15 + FMOVQ F0, -32(R15) + ADD R3, R1, R15 + FMOVQ F1, -16(R15) + MOVD R2, R1 + +emit_literal_done_emit_remainder_encodeBlockAsm: + MOVD dst_base+0(FP), R0 + SUB R0, R1, R1 + MOVD R1, ret+56(FP) + RET + +// func encodeBlockAsm4MB(dst []byte, src []byte, tmp *[65536]byte) int +// Requires: BMI, SSE2 +TEXT ·encodeBlockAsm4MB(SB), $24-64 + MOVD tmp+48(FP), R0 + MOVD dst_base+0(FP), R1 + MOVD $0x00000200, R2 + MOVD R0, R3 + VEOR V0.B16, V0.B16, V0.B16 + +zero_loop_encodeBlockAsm4MB: + FMOVQ F0, (R3) + FMOVQ F0, 16(R3) + FMOVQ F0, 32(R3) + FMOVQ F0, 48(R3) + FMOVQ F0, 64(R3) + FMOVQ F0, 80(R3) + FMOVQ F0, 96(R3) + FMOVQ F0, 112(R3) + ADD $0x80, R3, R3 + SUBS $1, R2, R2 + BNE zero_loop_encodeBlockAsm4MB + MOVD $0x00000000, R16 + MOVW R16, 20(RSP) + MOVD src_len+32(FP), R2 + SUB $9, R2, R3 + SUB $8, R2, R5 + MOVW R5, 16(RSP) + LSR $0x05, R2, R2 + SUBW R2, R3, R3 + ADD R3, R1, R3 + MOVD R3, 8(RSP) + MOVD $0x00000001, R2 + MOVW R2, 24(RSP) + MOVD src_base+24(FP), R3 + +search_loop_encodeBlockAsm4MB: + MOVWU R2, R5 + MOVWU 20(RSP), R16 + SUBW R16, R5, R5 + LSRW $0x06, R5, R5 + ADD R5, R2, R5 + ADD $4, R5, R5 + MOVWU R5, R5 + MOVWU 16(RSP), R16 + CMPW R16, R5 + BHS emit_remainder_encodeBlockAsm4MB + MOVD (R3)(R2), R6 + MOVW R5, 28(RSP) + MOVD $0x0000cf1bbcdcbf9b, R8 + MOVD R6, R9 + MOVD R6, R10 + LSR $0x08, R10, R10 + LSL $0x10, R9, R9 + MUL R8, R9, R9 + LSR $0x32, R9, R9 + LSL $0x10, R10, R10 + MUL R8, R10, R10 + LSR $0x32, R10, R10 + MOVWU (R0)(R9<<2), R5 + MOVWU (R0)(R10<<2), R7 + MOVW R2, (R0)(R9<<2) + ADD $1, R2, R9 + MOVWU R9, R9 + MOVW R9, (R0)(R10<<2) + MOVD R6, R9 + LSR $0x10, R9, R9 + LSL $0x10, R9, R9 + MUL R8, R9, R9 + LSR $0x32, R9, R9 + MOVWU R2, R8 + MOVWU 24(RSP), R16 + SUBW R16, R8, R8 + ADD R8, R3, R15 + MOVWU 1(R15), R10 + MOVD R6, R8 + LSR $0x08, R8, R8 + CMPW R10, R8 + BNE no_repeat_found_encodeBlockAsm4MB + ADD $1, R2, R6 + MOVWU R6, R6 + MOVWU 20(RSP), R7 + MOVWU R6, R5 + MOVWU 24(RSP), R16 + SUBSW R16, R5, R5 + BEQ repeat_extend_back_end_encodeBlockAsm4MB + +repeat_extend_back_loop_encodeBlockAsm4MB: + CMPW R7, R6 + BLS repeat_extend_back_end_encodeBlockAsm4MB + ADD R5, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R8 + ADD R6, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R9 + AND $0xff, R9, R16 + AND $0xff, R8, R15 + CMP R16, R15 + BNE repeat_extend_back_end_encodeBlockAsm4MB + SUB $1, R6, R6 + MOVWU R6, R6 + SUBSW $1, R5, R5 + BNE repeat_extend_back_loop_encodeBlockAsm4MB + +repeat_extend_back_end_encodeBlockAsm4MB: + MOVWU R6, R5 + MOVWU 20(RSP), R16 + SUBW R16, R5, R5 + ADD R5, R1, R5 + ADD $4, R5, R5 + MOVD 8(RSP), R16 + CMP R16, R5 + BLO repeat_dst_size_check_encodeBlockAsm4MB + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +repeat_dst_size_check_encodeBlockAsm4MB: + MOVWU 20(RSP), R5 + CMPW R6, R5 + BEQ emit_literal_done_repeat_emit_encodeBlockAsm4MB + MOVWU R6, R8 + MOVW R6, 20(RSP) + ADD R5, R3, R9 + SUBW R5, R8, R8 + SUB $1, R8, R5 + MOVWU R5, R5 + CMPW $0x3c, R5 + BLO one_byte_repeat_emit_encodeBlockAsm4MB + CMPW $0x00000100, R5 + BLO two_bytes_repeat_emit_encodeBlockAsm4MB + CMPW $0x00010000, R5 + BLO three_bytes_repeat_emit_encodeBlockAsm4MB + MOVWU R5, R10 + LSRW $0x10, R10, R10 + MOVD $0xf8, R16 + MOVB R16, (R1) + MOVH R5, 1(R1) + MOVB R10, 3(R1) + ADD $0x04, R1, R1 + JMP memmove_long_repeat_emit_encodeBlockAsm4MB + +three_bytes_repeat_emit_encodeBlockAsm4MB: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R5, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_repeat_emit_encodeBlockAsm4MB + +two_bytes_repeat_emit_encodeBlockAsm4MB: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R5, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R5 + BLO memmove_repeat_emit_encodeBlockAsm4MB + JMP memmove_long_repeat_emit_encodeBlockAsm4MB + +one_byte_repeat_emit_encodeBlockAsm4MB: + LSLW $0x02, R5, R16 + BFI $0, R16, $8, R5 + MOVB R5, (R1) + ADD $0x01, R1, R1 + +memmove_repeat_emit_encodeBlockAsm4MB: + ADD R8, R1, R5 + + // genMemMoveShort + CMP $0x08, R8 + BLS emit_lit_memmove_repeat_emit_encodeBlockAsm4MB_memmove_move_8 + CMP $0x10, R8 + BLS emit_lit_memmove_repeat_emit_encodeBlockAsm4MB_memmove_move_8through16 + CMP $0x20, R8 + BLS emit_lit_memmove_repeat_emit_encodeBlockAsm4MB_memmove_move_17through32 + JMP emit_lit_memmove_repeat_emit_encodeBlockAsm4MB_memmove_move_33through64 + +emit_lit_memmove_repeat_emit_encodeBlockAsm4MB_memmove_move_8: + MOVD (R9), R10 + MOVD R10, (R1) + JMP memmove_end_copy_repeat_emit_encodeBlockAsm4MB + +emit_lit_memmove_repeat_emit_encodeBlockAsm4MB_memmove_move_8through16: + MOVD (R9), R10 + ADD R8, R9, R15 + MOVD -8(R15), R9 + MOVD R10, (R1) + ADD R8, R1, R15 + MOVD R9, -8(R15) + JMP memmove_end_copy_repeat_emit_encodeBlockAsm4MB + +emit_lit_memmove_repeat_emit_encodeBlockAsm4MB_memmove_move_17through32: + FMOVQ (R9), F0 + ADD R8, R9, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_repeat_emit_encodeBlockAsm4MB + +emit_lit_memmove_repeat_emit_encodeBlockAsm4MB_memmove_move_33through64: + FMOVQ (R9), F0 + FMOVQ 16(R9), F1 + ADD R8, R9, R15 + FMOVQ -32(R15), F2 + ADD R8, R9, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R8, R1, R15 + FMOVQ F2, -32(R15) + ADD R8, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_repeat_emit_encodeBlockAsm4MB: + MOVD R5, R1 + JMP emit_literal_done_repeat_emit_encodeBlockAsm4MB + +memmove_long_repeat_emit_encodeBlockAsm4MB: + ADD R8, R1, R5 + + // genMemMoveLong + MOVD R9, R10 + MOVD R1, R11 + MOVD R8, R12 + +emit_lit_memmove_long_repeat_emit_encodeBlockAsm4MBlarge_big_loop_back: + FMOVQ (R10), F0 + FMOVQ 16(R10), F1 + FMOVQ F0, (R11) + FMOVQ F1, 16(R11) + ADD $0x20, R10, R10 + ADD $0x20, R11, R11 + SUB $0x20, R12, R12 + CMP $0x20, R12 + BHS emit_lit_memmove_long_repeat_emit_encodeBlockAsm4MBlarge_big_loop_back + ADD R8, R9, R15 + FMOVQ -32(R15), F0 + ADD R8, R9, R15 + FMOVQ -16(R15), F1 + ADD R8, R1, R15 + FMOVQ F0, -32(R15) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + MOVD R5, R1 + +emit_literal_done_repeat_emit_encodeBlockAsm4MB: + ADDW $0x05, R2, R2 + MOVWU R2, R5 + MOVWU 24(RSP), R16 + SUBW R16, R5, R5 + MOVD src_len+32(FP), R8 + SUBW R2, R8, R8 + ADD R2, R3, R9 + ADD R5, R3, R5 + + // matchLen + MOVD $0, R11 + +matchlen_loopback_16_repeat_extend_encodeBlockAsm4MB: + CMPW $0x10, R8 + BLO matchlen_match8_repeat_extend_encodeBlockAsm4MB + MOVD (R9)(R11), R10 + ADD R11, R9, R15 + MOVD 8(R15), R12 + MOVD (R5)(R11), R16 + EOR R16, R10, R10 + TST R10, R10 + BNE matchlen_bsf_8_repeat_extend_encodeBlockAsm4MB + ADD R11, R5, R15 + MOVD 8(R15), R16 + EOR R16, R12, R12 + TST R12, R12 + BNE matchlen_bsf_16repeat_extend_encodeBlockAsm4MB + SUB $16, R8, R8 + MOVWU R8, R8 + ADD $16, R11, R11 + MOVWU R11, R11 + JMP matchlen_loopback_16_repeat_extend_encodeBlockAsm4MB + +matchlen_bsf_16repeat_extend_encodeBlockAsm4MB: + RBIT R12, R12 + CLZ R12, R12 + ASR $0x03, R12, R12 + ADD R12, R11, R11 + ADD $8, R11, R11 + MOVWU R11, R11 + JMP repeat_extend_forward_end_encodeBlockAsm4MB + +matchlen_match8_repeat_extend_encodeBlockAsm4MB: + CMPW $0x08, R8 + BLO matchlen_match4_repeat_extend_encodeBlockAsm4MB + MOVD (R9)(R11), R10 + MOVD (R5)(R11), R16 + EOR R16, R10, R10 + TST R10, R10 + BNE matchlen_bsf_8_repeat_extend_encodeBlockAsm4MB + SUB $8, R8, R8 + MOVWU R8, R8 + ADD $8, R11, R11 + MOVWU R11, R11 + JMP matchlen_match4_repeat_extend_encodeBlockAsm4MB + +matchlen_bsf_8_repeat_extend_encodeBlockAsm4MB: + RBIT R10, R10 + CLZ R10, R10 + ASR $0x03, R10, R10 + ADD R10, R11, R11 + MOVWU R11, R11 + JMP repeat_extend_forward_end_encodeBlockAsm4MB + +matchlen_match4_repeat_extend_encodeBlockAsm4MB: + CMPW $0x04, R8 + BLO matchlen_match2_repeat_extend_encodeBlockAsm4MB + MOVWU (R9)(R11), R10 + MOVWU (R5)(R11), R16 + CMPW R10, R16 + BNE matchlen_match2_repeat_extend_encodeBlockAsm4MB + SUB $4, R8, R8 + MOVWU R8, R8 + ADD $4, R11, R11 + MOVWU R11, R11 + +matchlen_match2_repeat_extend_encodeBlockAsm4MB: + CMPW $0x01, R8 + BEQ matchlen_match1_repeat_extend_encodeBlockAsm4MB + BLO repeat_extend_forward_end_encodeBlockAsm4MB + MOVHU (R9)(R11), R16 + BFI $0, R16, $16, R10 + ADD R11, R5, R15 + MOVHU (R15), R15 + AND $0xffff, R10, R16 + CMP R16, R15 + BNE matchlen_match1_repeat_extend_encodeBlockAsm4MB + ADD $2, R11, R11 + MOVWU R11, R11 + SUBSW $0x02, R8, R8 + BEQ repeat_extend_forward_end_encodeBlockAsm4MB + +matchlen_match1_repeat_extend_encodeBlockAsm4MB: + MOVBU (R9)(R11), R16 + BFI $0, R16, $8, R10 + ADD R11, R5, R15 + MOVBU (R15), R15 + AND $0xff, R10, R16 + CMP R16, R15 + BNE repeat_extend_forward_end_encodeBlockAsm4MB + ADD $1, R11, R11 + MOVWU R11, R11 + +repeat_extend_forward_end_encodeBlockAsm4MB: + ADDW R11, R2, R2 + MOVWU R2, R5 + SUBW R6, R5, R5 + MOVWU 24(RSP), R6 + TSTW R7, R7 + BEQ repeat_as_copy_encodeBlockAsm4MB + + // emitRepeat + MOVWU R5, R7 + SUB $4, R5, R5 + MOVWU R5, R5 + CMPW $0x08, R7 + BLS repeat_two_match_repeat_encodeBlockAsm4MB + CMPW $0x0c, R7 + BHS cant_repeat_two_offset_match_repeat_encodeBlockAsm4MB + CMPW $0x00000800, R6 + BLO repeat_two_offset_match_repeat_encodeBlockAsm4MB + +cant_repeat_two_offset_match_repeat_encodeBlockAsm4MB: + CMPW $0x00000104, R5 + BLO repeat_three_match_repeat_encodeBlockAsm4MB + CMPW $0x00010100, R5 + BLO repeat_four_match_repeat_encodeBlockAsm4MB + SUB $65536, R5, R5 + MOVWU R5, R5 + MOVWU R5, R6 + MOVD $0x001d, R16 + MOVH R16, (R1) + MOVH R5, 2(R1) + ASRW $0x10, R6, R6 + MOVB R6, 4(R1) + ADD $0x05, R1, R1 + JMP repeat_end_emit_encodeBlockAsm4MB + +repeat_four_match_repeat_encodeBlockAsm4MB: + SUB $256, R5, R5 + MOVWU R5, R5 + MOVD $0x0019, R16 + MOVH R16, (R1) + MOVH R5, 2(R1) + ADD $0x04, R1, R1 + JMP repeat_end_emit_encodeBlockAsm4MB + +repeat_three_match_repeat_encodeBlockAsm4MB: + SUB $4, R5, R5 + MOVWU R5, R5 + MOVD $0x0015, R16 + MOVH R16, (R1) + MOVB R5, 2(R1) + ADD $0x03, R1, R1 + JMP repeat_end_emit_encodeBlockAsm4MB + +repeat_two_match_repeat_encodeBlockAsm4MB: + LSLW $0x02, R5, R5 + ORRW $0x01, R5, R5 + MOVH R5, (R1) + ADD $0x02, R1, R1 + JMP repeat_end_emit_encodeBlockAsm4MB + +repeat_two_offset_match_repeat_encodeBlockAsm4MB: + MOVD $0, R7 + ADD R5<<2, R7, R5 + ADD $1, R5, R5 + MOVWU R5, R5 + MOVB R6, 1(R1) + ASRW $0x08, R6, R6 + LSLW $0x05, R6, R6 + ORRW R6, R5, R5 + MOVB R5, (R1) + ADD $0x02, R1, R1 + JMP repeat_end_emit_encodeBlockAsm4MB + +repeat_as_copy_encodeBlockAsm4MB: + // emitCopy + CMPW $0x00010000, R6 + BLO two_byte_offset_repeat_as_copy_encodeBlockAsm4MB + CMPW $0x40, R5 + BLS four_bytes_remain_repeat_as_copy_encodeBlockAsm4MB + MOVD $0xff, R16 + MOVB R16, (R1) + MOVW R6, 1(R1) + SUB $64, R5, R5 + MOVWU R5, R5 + ADD $0x05, R1, R1 + CMPW $0x04, R5 + BLO four_bytes_remain_repeat_as_copy_encodeBlockAsm4MB + + // emitRepeat + MOVWU R5, R7 + SUB $4, R5, R5 + MOVWU R5, R5 + CMPW $0x08, R7 + BLS repeat_two_repeat_as_copy_encodeBlockAsm4MB_emit_copy + CMPW $0x0c, R7 + BHS cant_repeat_two_offset_repeat_as_copy_encodeBlockAsm4MB_emit_copy + CMPW $0x00000800, R6 + BLO repeat_two_offset_repeat_as_copy_encodeBlockAsm4MB_emit_copy + +cant_repeat_two_offset_repeat_as_copy_encodeBlockAsm4MB_emit_copy: + CMPW $0x00000104, R5 + BLO repeat_three_repeat_as_copy_encodeBlockAsm4MB_emit_copy + CMPW $0x00010100, R5 + BLO repeat_four_repeat_as_copy_encodeBlockAsm4MB_emit_copy + SUB $65536, R5, R5 + MOVWU R5, R5 + MOVWU R5, R6 + MOVD $0x001d, R16 + MOVH R16, (R1) + MOVH R5, 2(R1) + ASRW $0x10, R6, R6 + MOVB R6, 4(R1) + ADD $0x05, R1, R1 + JMP repeat_end_emit_encodeBlockAsm4MB + +repeat_four_repeat_as_copy_encodeBlockAsm4MB_emit_copy: + SUB $256, R5, R5 + MOVWU R5, R5 + MOVD $0x0019, R16 + MOVH R16, (R1) + MOVH R5, 2(R1) + ADD $0x04, R1, R1 + JMP repeat_end_emit_encodeBlockAsm4MB + +repeat_three_repeat_as_copy_encodeBlockAsm4MB_emit_copy: + SUB $4, R5, R5 + MOVWU R5, R5 + MOVD $0x0015, R16 + MOVH R16, (R1) + MOVB R5, 2(R1) + ADD $0x03, R1, R1 + JMP repeat_end_emit_encodeBlockAsm4MB + +repeat_two_repeat_as_copy_encodeBlockAsm4MB_emit_copy: + LSLW $0x02, R5, R5 + ORRW $0x01, R5, R5 + MOVH R5, (R1) + ADD $0x02, R1, R1 + JMP repeat_end_emit_encodeBlockAsm4MB + +repeat_two_offset_repeat_as_copy_encodeBlockAsm4MB_emit_copy: + MOVD $0, R7 + ADD R5<<2, R7, R5 + ADD $1, R5, R5 + MOVWU R5, R5 + MOVB R6, 1(R1) + ASRW $0x08, R6, R6 + LSLW $0x05, R6, R6 + ORRW R6, R5, R5 + MOVB R5, (R1) + ADD $0x02, R1, R1 + JMP repeat_end_emit_encodeBlockAsm4MB + +four_bytes_remain_repeat_as_copy_encodeBlockAsm4MB: + TSTW R5, R5 + BEQ repeat_end_emit_encodeBlockAsm4MB + MOVD $0, R7 + ADD R5<<2, R7, R5 + SUB $1, R5, R5 + MOVWU R5, R5 + MOVB R5, (R1) + MOVW R6, 1(R1) + ADD $0x05, R1, R1 + JMP repeat_end_emit_encodeBlockAsm4MB + +two_byte_offset_repeat_as_copy_encodeBlockAsm4MB: + CMPW $0x40, R5 + BLS two_byte_offset_short_repeat_as_copy_encodeBlockAsm4MB + CMPW $0x00000800, R6 + BHS long_offset_short_repeat_as_copy_encodeBlockAsm4MB + MOVD $0x00000001, R7 + ADD $16, R7, R7 + MOVWU R7, R7 + MOVB R6, 1(R1) + LSRW $0x08, R6, R6 + LSLW $0x05, R6, R6 + ORRW R6, R7, R7 + MOVB R7, (R1) + ADD $0x02, R1, R1 + SUBW $0x08, R5, R5 + + // emitRepeat + SUB $4, R5, R5 + MOVWU R5, R5 + JMP cant_repeat_two_offset_repeat_as_copy_encodeBlockAsm4MB_emit_copy_short_2b + MOVWU R5, R7 + SUB $4, R5, R5 + MOVWU R5, R5 + CMPW $0x08, R7 + BLS repeat_two_repeat_as_copy_encodeBlockAsm4MB_emit_copy_short_2b + CMPW $0x0c, R7 + BHS cant_repeat_two_offset_repeat_as_copy_encodeBlockAsm4MB_emit_copy_short_2b + CMPW $0x00000800, R6 + BLO repeat_two_offset_repeat_as_copy_encodeBlockAsm4MB_emit_copy_short_2b + +cant_repeat_two_offset_repeat_as_copy_encodeBlockAsm4MB_emit_copy_short_2b: + CMPW $0x00000104, R5 + BLO repeat_three_repeat_as_copy_encodeBlockAsm4MB_emit_copy_short_2b + CMPW $0x00010100, R5 + BLO repeat_four_repeat_as_copy_encodeBlockAsm4MB_emit_copy_short_2b + SUB $65536, R5, R5 + MOVWU R5, R5 + MOVWU R5, R6 + MOVD $0x001d, R16 + MOVH R16, (R1) + MOVH R5, 2(R1) + ASRW $0x10, R6, R6 + MOVB R6, 4(R1) + ADD $0x05, R1, R1 + JMP repeat_end_emit_encodeBlockAsm4MB + +repeat_four_repeat_as_copy_encodeBlockAsm4MB_emit_copy_short_2b: + SUB $256, R5, R5 + MOVWU R5, R5 + MOVD $0x0019, R16 + MOVH R16, (R1) + MOVH R5, 2(R1) + ADD $0x04, R1, R1 + JMP repeat_end_emit_encodeBlockAsm4MB + +repeat_three_repeat_as_copy_encodeBlockAsm4MB_emit_copy_short_2b: + SUB $4, R5, R5 + MOVWU R5, R5 + MOVD $0x0015, R16 + MOVH R16, (R1) + MOVB R5, 2(R1) + ADD $0x03, R1, R1 + JMP repeat_end_emit_encodeBlockAsm4MB + +repeat_two_repeat_as_copy_encodeBlockAsm4MB_emit_copy_short_2b: + LSLW $0x02, R5, R5 + ORRW $0x01, R5, R5 + MOVH R5, (R1) + ADD $0x02, R1, R1 + JMP repeat_end_emit_encodeBlockAsm4MB + +repeat_two_offset_repeat_as_copy_encodeBlockAsm4MB_emit_copy_short_2b: + MOVD $0, R7 + ADD R5<<2, R7, R5 + ADD $1, R5, R5 + MOVWU R5, R5 + MOVB R6, 1(R1) + ASRW $0x08, R6, R6 + LSLW $0x05, R6, R6 + ORRW R6, R5, R5 + MOVB R5, (R1) + ADD $0x02, R1, R1 + JMP repeat_end_emit_encodeBlockAsm4MB + +long_offset_short_repeat_as_copy_encodeBlockAsm4MB: + MOVD $0xee, R16 + MOVB R16, (R1) + MOVH R6, 1(R1) + SUB $60, R5, R5 + MOVWU R5, R5 + ADD $0x03, R1, R1 + + // emitRepeat + MOVWU R5, R7 + SUB $4, R5, R5 + MOVWU R5, R5 + CMPW $0x08, R7 + BLS repeat_two_repeat_as_copy_encodeBlockAsm4MB_emit_copy_short + CMPW $0x0c, R7 + BHS cant_repeat_two_offset_repeat_as_copy_encodeBlockAsm4MB_emit_copy_short + CMPW $0x00000800, R6 + BLO repeat_two_offset_repeat_as_copy_encodeBlockAsm4MB_emit_copy_short + +cant_repeat_two_offset_repeat_as_copy_encodeBlockAsm4MB_emit_copy_short: + CMPW $0x00000104, R5 + BLO repeat_three_repeat_as_copy_encodeBlockAsm4MB_emit_copy_short + CMPW $0x00010100, R5 + BLO repeat_four_repeat_as_copy_encodeBlockAsm4MB_emit_copy_short + SUB $65536, R5, R5 + MOVWU R5, R5 + MOVWU R5, R6 + MOVD $0x001d, R16 + MOVH R16, (R1) + MOVH R5, 2(R1) + ASRW $0x10, R6, R6 + MOVB R6, 4(R1) + ADD $0x05, R1, R1 + JMP repeat_end_emit_encodeBlockAsm4MB + +repeat_four_repeat_as_copy_encodeBlockAsm4MB_emit_copy_short: + SUB $256, R5, R5 + MOVWU R5, R5 + MOVD $0x0019, R16 + MOVH R16, (R1) + MOVH R5, 2(R1) + ADD $0x04, R1, R1 + JMP repeat_end_emit_encodeBlockAsm4MB + +repeat_three_repeat_as_copy_encodeBlockAsm4MB_emit_copy_short: + SUB $4, R5, R5 + MOVWU R5, R5 + MOVD $0x0015, R16 + MOVH R16, (R1) + MOVB R5, 2(R1) + ADD $0x03, R1, R1 + JMP repeat_end_emit_encodeBlockAsm4MB + +repeat_two_repeat_as_copy_encodeBlockAsm4MB_emit_copy_short: + LSLW $0x02, R5, R5 + ORRW $0x01, R5, R5 + MOVH R5, (R1) + ADD $0x02, R1, R1 + JMP repeat_end_emit_encodeBlockAsm4MB + +repeat_two_offset_repeat_as_copy_encodeBlockAsm4MB_emit_copy_short: + MOVD $0, R7 + ADD R5<<2, R7, R5 + ADD $1, R5, R5 + MOVWU R5, R5 + MOVB R6, 1(R1) + ASRW $0x08, R6, R6 + LSLW $0x05, R6, R6 + ORRW R6, R5, R5 + MOVB R5, (R1) + ADD $0x02, R1, R1 + JMP repeat_end_emit_encodeBlockAsm4MB + +two_byte_offset_short_repeat_as_copy_encodeBlockAsm4MB: + MOVWU R5, R7 + LSLW $0x02, R7, R7 + CMPW $0x0c, R5 + BHS emit_copy_three_repeat_as_copy_encodeBlockAsm4MB + CMPW $0x00000800, R6 + BHS emit_copy_three_repeat_as_copy_encodeBlockAsm4MB + SUB $15, R7, R7 + MOVWU R7, R7 + MOVB R6, 1(R1) + LSRW $0x08, R6, R6 + LSLW $0x05, R6, R6 + ORRW R6, R7, R7 + MOVB R7, (R1) + ADD $0x02, R1, R1 + JMP repeat_end_emit_encodeBlockAsm4MB + +emit_copy_three_repeat_as_copy_encodeBlockAsm4MB: + SUB $2, R7, R7 + MOVWU R7, R7 + MOVB R7, (R1) + MOVH R6, 1(R1) + ADD $0x03, R1, R1 + +repeat_end_emit_encodeBlockAsm4MB: + MOVW R2, 20(RSP) + JMP search_loop_encodeBlockAsm4MB + +no_repeat_found_encodeBlockAsm4MB: + MOVWU (R3)(R5), R16 + CMPW R6, R16 + BEQ candidate_match_encodeBlockAsm4MB + LSR $0x08, R6, R6 + MOVWU (R0)(R9<<2), R5 + ADD $2, R2, R8 + MOVWU R8, R8 + MOVWU (R3)(R7), R16 + CMPW R6, R16 + BEQ candidate2_match_encodeBlockAsm4MB + MOVW R8, (R0)(R9<<2) + LSR $0x08, R6, R6 + MOVWU (R3)(R5), R16 + CMPW R6, R16 + BEQ candidate3_match_encodeBlockAsm4MB + MOVWU 28(RSP), R2 + JMP search_loop_encodeBlockAsm4MB + +candidate3_match_encodeBlockAsm4MB: + ADDW $0x02, R2, R2 + JMP candidate_match_encodeBlockAsm4MB + +candidate2_match_encodeBlockAsm4MB: + MOVW R8, (R0)(R9<<2) + ADDW $1, R2, R2 + MOVWU R7, R5 + +candidate_match_encodeBlockAsm4MB: + MOVWU 20(RSP), R6 + TSTW R5, R5 + BEQ match_extend_back_end_encodeBlockAsm4MB + +match_extend_back_loop_encodeBlockAsm4MB: + CMPW R6, R2 + BLS match_extend_back_end_encodeBlockAsm4MB + ADD R5, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R7 + ADD R2, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R8 + AND $0xff, R8, R16 + AND $0xff, R7, R15 + CMP R16, R15 + BNE match_extend_back_end_encodeBlockAsm4MB + SUB $1, R2, R2 + MOVWU R2, R2 + SUBSW $1, R5, R5 + BEQ match_extend_back_end_encodeBlockAsm4MB + JMP match_extend_back_loop_encodeBlockAsm4MB + +match_extend_back_end_encodeBlockAsm4MB: + MOVWU R2, R6 + MOVWU 20(RSP), R16 + SUBW R16, R6, R6 + ADD R6, R1, R6 + ADD $4, R6, R6 + MOVD 8(RSP), R16 + CMP R16, R6 + BLO match_dst_size_check_encodeBlockAsm4MB + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +match_dst_size_check_encodeBlockAsm4MB: + MOVWU R2, R6 + MOVWU 20(RSP), R7 + CMPW R6, R7 + BEQ emit_literal_done_match_emit_encodeBlockAsm4MB + MOVWU R6, R8 + MOVW R6, 20(RSP) + ADD R7, R3, R6 + SUBW R7, R8, R8 + SUB $1, R8, R7 + MOVWU R7, R7 + CMPW $0x3c, R7 + BLO one_byte_match_emit_encodeBlockAsm4MB + CMPW $0x00000100, R7 + BLO two_bytes_match_emit_encodeBlockAsm4MB + CMPW $0x00010000, R7 + BLO three_bytes_match_emit_encodeBlockAsm4MB + MOVWU R7, R9 + LSRW $0x10, R9, R9 + MOVD $0xf8, R16 + MOVB R16, (R1) + MOVH R7, 1(R1) + MOVB R9, 3(R1) + ADD $0x04, R1, R1 + JMP memmove_long_match_emit_encodeBlockAsm4MB + +three_bytes_match_emit_encodeBlockAsm4MB: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R7, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_match_emit_encodeBlockAsm4MB + +two_bytes_match_emit_encodeBlockAsm4MB: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R7, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R7 + BLO memmove_match_emit_encodeBlockAsm4MB + JMP memmove_long_match_emit_encodeBlockAsm4MB + +one_byte_match_emit_encodeBlockAsm4MB: + LSLW $0x02, R7, R16 + BFI $0, R16, $8, R7 + MOVB R7, (R1) + ADD $0x01, R1, R1 + +memmove_match_emit_encodeBlockAsm4MB: + ADD R8, R1, R7 + + // genMemMoveShort + CMP $0x08, R8 + BLS emit_lit_memmove_match_emit_encodeBlockAsm4MB_memmove_move_8 + CMP $0x10, R8 + BLS emit_lit_memmove_match_emit_encodeBlockAsm4MB_memmove_move_8through16 + CMP $0x20, R8 + BLS emit_lit_memmove_match_emit_encodeBlockAsm4MB_memmove_move_17through32 + JMP emit_lit_memmove_match_emit_encodeBlockAsm4MB_memmove_move_33through64 + +emit_lit_memmove_match_emit_encodeBlockAsm4MB_memmove_move_8: + MOVD (R6), R9 + MOVD R9, (R1) + JMP memmove_end_copy_match_emit_encodeBlockAsm4MB + +emit_lit_memmove_match_emit_encodeBlockAsm4MB_memmove_move_8through16: + MOVD (R6), R9 + ADD R8, R6, R15 + MOVD -8(R15), R6 + MOVD R9, (R1) + ADD R8, R1, R15 + MOVD R6, -8(R15) + JMP memmove_end_copy_match_emit_encodeBlockAsm4MB + +emit_lit_memmove_match_emit_encodeBlockAsm4MB_memmove_move_17through32: + FMOVQ (R6), F0 + ADD R8, R6, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_match_emit_encodeBlockAsm4MB + +emit_lit_memmove_match_emit_encodeBlockAsm4MB_memmove_move_33through64: + FMOVQ (R6), F0 + FMOVQ 16(R6), F1 + ADD R8, R6, R15 + FMOVQ -32(R15), F2 + ADD R8, R6, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R8, R1, R15 + FMOVQ F2, -32(R15) + ADD R8, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_match_emit_encodeBlockAsm4MB: + MOVD R7, R1 + JMP emit_literal_done_match_emit_encodeBlockAsm4MB + +memmove_long_match_emit_encodeBlockAsm4MB: + ADD R8, R1, R7 + + // genMemMoveLong + MOVD R6, R9 + MOVD R1, R10 + MOVD R8, R11 + +emit_lit_memmove_long_match_emit_encodeBlockAsm4MBlarge_big_loop_back: + FMOVQ (R9), F0 + FMOVQ 16(R9), F1 + FMOVQ F0, (R10) + FMOVQ F1, 16(R10) + ADD $0x20, R9, R9 + ADD $0x20, R10, R10 + SUB $0x20, R11, R11 + CMP $0x20, R11 + BHS emit_lit_memmove_long_match_emit_encodeBlockAsm4MBlarge_big_loop_back + ADD R8, R6, R15 + FMOVQ -32(R15), F0 + ADD R8, R6, R15 + FMOVQ -16(R15), F1 + ADD R8, R1, R15 + FMOVQ F0, -32(R15) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + MOVD R7, R1 + +emit_literal_done_match_emit_encodeBlockAsm4MB: +match_nolit_loop_encodeBlockAsm4MB: + MOVWU R2, R6 + SUBW R5, R6, R6 + MOVW R6, 24(RSP) + ADDW $0x04, R2, R2 + ADDW $0x04, R5, R5 + MOVD src_len+32(FP), R6 + SUBW R2, R6, R6 + ADD R2, R3, R7 + ADD R5, R3, R5 + + // matchLen + MOVD $0, R9 + +matchlen_loopback_16_match_nolit_encodeBlockAsm4MB: + CMPW $0x10, R6 + BLO matchlen_match8_match_nolit_encodeBlockAsm4MB + MOVD (R7)(R9), R8 + ADD R9, R7, R15 + MOVD 8(R15), R10 + MOVD (R5)(R9), R16 + EOR R16, R8, R8 + TST R8, R8 + BNE matchlen_bsf_8_match_nolit_encodeBlockAsm4MB + ADD R9, R5, R15 + MOVD 8(R15), R16 + EOR R16, R10, R10 + TST R10, R10 + BNE matchlen_bsf_16match_nolit_encodeBlockAsm4MB + SUB $16, R6, R6 + MOVWU R6, R6 + ADD $16, R9, R9 + MOVWU R9, R9 + JMP matchlen_loopback_16_match_nolit_encodeBlockAsm4MB + +matchlen_bsf_16match_nolit_encodeBlockAsm4MB: + RBIT R10, R10 + CLZ R10, R10 + ASR $0x03, R10, R10 + ADD R10, R9, R9 + ADD $8, R9, R9 + MOVWU R9, R9 + JMP match_nolit_end_encodeBlockAsm4MB + +matchlen_match8_match_nolit_encodeBlockAsm4MB: + CMPW $0x08, R6 + BLO matchlen_match4_match_nolit_encodeBlockAsm4MB + MOVD (R7)(R9), R8 + MOVD (R5)(R9), R16 + EOR R16, R8, R8 + TST R8, R8 + BNE matchlen_bsf_8_match_nolit_encodeBlockAsm4MB + SUB $8, R6, R6 + MOVWU R6, R6 + ADD $8, R9, R9 + MOVWU R9, R9 + JMP matchlen_match4_match_nolit_encodeBlockAsm4MB + +matchlen_bsf_8_match_nolit_encodeBlockAsm4MB: + RBIT R8, R8 + CLZ R8, R8 + ASR $0x03, R8, R8 + ADD R8, R9, R9 + MOVWU R9, R9 + JMP match_nolit_end_encodeBlockAsm4MB + +matchlen_match4_match_nolit_encodeBlockAsm4MB: + CMPW $0x04, R6 + BLO matchlen_match2_match_nolit_encodeBlockAsm4MB + MOVWU (R7)(R9), R8 + MOVWU (R5)(R9), R16 + CMPW R8, R16 + BNE matchlen_match2_match_nolit_encodeBlockAsm4MB + SUB $4, R6, R6 + MOVWU R6, R6 + ADD $4, R9, R9 + MOVWU R9, R9 + +matchlen_match2_match_nolit_encodeBlockAsm4MB: + CMPW $0x01, R6 + BEQ matchlen_match1_match_nolit_encodeBlockAsm4MB + BLO match_nolit_end_encodeBlockAsm4MB + MOVHU (R7)(R9), R16 + BFI $0, R16, $16, R8 + ADD R9, R5, R15 + MOVHU (R15), R15 + AND $0xffff, R8, R16 + CMP R16, R15 + BNE matchlen_match1_match_nolit_encodeBlockAsm4MB + ADD $2, R9, R9 + MOVWU R9, R9 + SUBSW $0x02, R6, R6 + BEQ match_nolit_end_encodeBlockAsm4MB + +matchlen_match1_match_nolit_encodeBlockAsm4MB: + MOVBU (R7)(R9), R16 + BFI $0, R16, $8, R8 + ADD R9, R5, R15 + MOVBU (R15), R15 + AND $0xff, R8, R16 + CMP R16, R15 + BNE match_nolit_end_encodeBlockAsm4MB + ADD $1, R9, R9 + MOVWU R9, R9 + +match_nolit_end_encodeBlockAsm4MB: + ADDW R9, R2, R2 + MOVWU 24(RSP), R5 + ADDW $0x04, R9, R9 + MOVW R2, 20(RSP) + + // emitCopy + CMPW $0x00010000, R5 + BLO two_byte_offset_match_nolit_encodeBlockAsm4MB + CMPW $0x40, R9 + BLS four_bytes_remain_match_nolit_encodeBlockAsm4MB + MOVD $0xff, R16 + MOVB R16, (R1) + MOVW R5, 1(R1) + SUB $64, R9, R9 + MOVWU R9, R9 + ADD $0x05, R1, R1 + CMPW $0x04, R9 + BLO four_bytes_remain_match_nolit_encodeBlockAsm4MB + + // emitRepeat + MOVWU R9, R6 + SUB $4, R9, R9 + MOVWU R9, R9 + CMPW $0x08, R6 + BLS repeat_two_match_nolit_encodeBlockAsm4MB_emit_copy + CMPW $0x0c, R6 + BHS cant_repeat_two_offset_match_nolit_encodeBlockAsm4MB_emit_copy + CMPW $0x00000800, R5 + BLO repeat_two_offset_match_nolit_encodeBlockAsm4MB_emit_copy + +cant_repeat_two_offset_match_nolit_encodeBlockAsm4MB_emit_copy: + CMPW $0x00000104, R9 + BLO repeat_three_match_nolit_encodeBlockAsm4MB_emit_copy + CMPW $0x00010100, R9 + BLO repeat_four_match_nolit_encodeBlockAsm4MB_emit_copy + SUB $65536, R9, R9 + MOVWU R9, R9 + MOVWU R9, R5 + MOVD $0x001d, R16 + MOVH R16, (R1) + MOVH R9, 2(R1) + ASRW $0x10, R5, R5 + MOVB R5, 4(R1) + ADD $0x05, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm4MB + +repeat_four_match_nolit_encodeBlockAsm4MB_emit_copy: + SUB $256, R9, R9 + MOVWU R9, R9 + MOVD $0x0019, R16 + MOVH R16, (R1) + MOVH R9, 2(R1) + ADD $0x04, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm4MB + +repeat_three_match_nolit_encodeBlockAsm4MB_emit_copy: + SUB $4, R9, R9 + MOVWU R9, R9 + MOVD $0x0015, R16 + MOVH R16, (R1) + MOVB R9, 2(R1) + ADD $0x03, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm4MB + +repeat_two_match_nolit_encodeBlockAsm4MB_emit_copy: + LSLW $0x02, R9, R9 + ORRW $0x01, R9, R9 + MOVH R9, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm4MB + +repeat_two_offset_match_nolit_encodeBlockAsm4MB_emit_copy: + MOVD $0, R6 + ADD R9<<2, R6, R9 + ADD $1, R9, R9 + MOVWU R9, R9 + MOVB R5, 1(R1) + ASRW $0x08, R5, R5 + LSLW $0x05, R5, R5 + ORRW R5, R9, R9 + MOVB R9, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm4MB + +four_bytes_remain_match_nolit_encodeBlockAsm4MB: + TSTW R9, R9 + BEQ match_nolit_emitcopy_end_encodeBlockAsm4MB + MOVD $0, R6 + ADD R9<<2, R6, R9 + SUB $1, R9, R9 + MOVWU R9, R9 + MOVB R9, (R1) + MOVW R5, 1(R1) + ADD $0x05, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm4MB + +two_byte_offset_match_nolit_encodeBlockAsm4MB: + CMPW $0x40, R9 + BLS two_byte_offset_short_match_nolit_encodeBlockAsm4MB + CMPW $0x00000800, R5 + BHS long_offset_short_match_nolit_encodeBlockAsm4MB + MOVD $0x00000001, R6 + ADD $16, R6, R6 + MOVWU R6, R6 + MOVB R5, 1(R1) + LSRW $0x08, R5, R5 + LSLW $0x05, R5, R5 + ORRW R5, R6, R6 + MOVB R6, (R1) + ADD $0x02, R1, R1 + SUBW $0x08, R9, R9 + + // emitRepeat + SUB $4, R9, R9 + MOVWU R9, R9 + JMP cant_repeat_two_offset_match_nolit_encodeBlockAsm4MB_emit_copy_short_2b + MOVWU R9, R6 + SUB $4, R9, R9 + MOVWU R9, R9 + CMPW $0x08, R6 + BLS repeat_two_match_nolit_encodeBlockAsm4MB_emit_copy_short_2b + CMPW $0x0c, R6 + BHS cant_repeat_two_offset_match_nolit_encodeBlockAsm4MB_emit_copy_short_2b + CMPW $0x00000800, R5 + BLO repeat_two_offset_match_nolit_encodeBlockAsm4MB_emit_copy_short_2b + +cant_repeat_two_offset_match_nolit_encodeBlockAsm4MB_emit_copy_short_2b: + CMPW $0x00000104, R9 + BLO repeat_three_match_nolit_encodeBlockAsm4MB_emit_copy_short_2b + CMPW $0x00010100, R9 + BLO repeat_four_match_nolit_encodeBlockAsm4MB_emit_copy_short_2b + SUB $65536, R9, R9 + MOVWU R9, R9 + MOVWU R9, R5 + MOVD $0x001d, R16 + MOVH R16, (R1) + MOVH R9, 2(R1) + ASRW $0x10, R5, R5 + MOVB R5, 4(R1) + ADD $0x05, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm4MB + +repeat_four_match_nolit_encodeBlockAsm4MB_emit_copy_short_2b: + SUB $256, R9, R9 + MOVWU R9, R9 + MOVD $0x0019, R16 + MOVH R16, (R1) + MOVH R9, 2(R1) + ADD $0x04, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm4MB + +repeat_three_match_nolit_encodeBlockAsm4MB_emit_copy_short_2b: + SUB $4, R9, R9 + MOVWU R9, R9 + MOVD $0x0015, R16 + MOVH R16, (R1) + MOVB R9, 2(R1) + ADD $0x03, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm4MB + +repeat_two_match_nolit_encodeBlockAsm4MB_emit_copy_short_2b: + LSLW $0x02, R9, R9 + ORRW $0x01, R9, R9 + MOVH R9, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm4MB + +repeat_two_offset_match_nolit_encodeBlockAsm4MB_emit_copy_short_2b: + MOVD $0, R6 + ADD R9<<2, R6, R9 + ADD $1, R9, R9 + MOVWU R9, R9 + MOVB R5, 1(R1) + ASRW $0x08, R5, R5 + LSLW $0x05, R5, R5 + ORRW R5, R9, R9 + MOVB R9, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm4MB + +long_offset_short_match_nolit_encodeBlockAsm4MB: + MOVD $0xee, R16 + MOVB R16, (R1) + MOVH R5, 1(R1) + SUB $60, R9, R9 + MOVWU R9, R9 + ADD $0x03, R1, R1 + + // emitRepeat + MOVWU R9, R6 + SUB $4, R9, R9 + MOVWU R9, R9 + CMPW $0x08, R6 + BLS repeat_two_match_nolit_encodeBlockAsm4MB_emit_copy_short + CMPW $0x0c, R6 + BHS cant_repeat_two_offset_match_nolit_encodeBlockAsm4MB_emit_copy_short + CMPW $0x00000800, R5 + BLO repeat_two_offset_match_nolit_encodeBlockAsm4MB_emit_copy_short + +cant_repeat_two_offset_match_nolit_encodeBlockAsm4MB_emit_copy_short: + CMPW $0x00000104, R9 + BLO repeat_three_match_nolit_encodeBlockAsm4MB_emit_copy_short + CMPW $0x00010100, R9 + BLO repeat_four_match_nolit_encodeBlockAsm4MB_emit_copy_short + SUB $65536, R9, R9 + MOVWU R9, R9 + MOVWU R9, R5 + MOVD $0x001d, R16 + MOVH R16, (R1) + MOVH R9, 2(R1) + ASRW $0x10, R5, R5 + MOVB R5, 4(R1) + ADD $0x05, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm4MB + +repeat_four_match_nolit_encodeBlockAsm4MB_emit_copy_short: + SUB $256, R9, R9 + MOVWU R9, R9 + MOVD $0x0019, R16 + MOVH R16, (R1) + MOVH R9, 2(R1) + ADD $0x04, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm4MB + +repeat_three_match_nolit_encodeBlockAsm4MB_emit_copy_short: + SUB $4, R9, R9 + MOVWU R9, R9 + MOVD $0x0015, R16 + MOVH R16, (R1) + MOVB R9, 2(R1) + ADD $0x03, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm4MB + +repeat_two_match_nolit_encodeBlockAsm4MB_emit_copy_short: + LSLW $0x02, R9, R9 + ORRW $0x01, R9, R9 + MOVH R9, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm4MB + +repeat_two_offset_match_nolit_encodeBlockAsm4MB_emit_copy_short: + MOVD $0, R6 + ADD R9<<2, R6, R9 + ADD $1, R9, R9 + MOVWU R9, R9 + MOVB R5, 1(R1) + ASRW $0x08, R5, R5 + LSLW $0x05, R5, R5 + ORRW R5, R9, R9 + MOVB R9, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm4MB + +two_byte_offset_short_match_nolit_encodeBlockAsm4MB: + MOVWU R9, R6 + LSLW $0x02, R6, R6 + CMPW $0x0c, R9 + BHS emit_copy_three_match_nolit_encodeBlockAsm4MB + CMPW $0x00000800, R5 + BHS emit_copy_three_match_nolit_encodeBlockAsm4MB + SUB $15, R6, R6 + MOVWU R6, R6 + MOVB R5, 1(R1) + LSRW $0x08, R5, R5 + LSLW $0x05, R5, R5 + ORRW R5, R6, R6 + MOVB R6, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm4MB + +emit_copy_three_match_nolit_encodeBlockAsm4MB: + SUB $2, R6, R6 + MOVWU R6, R6 + MOVB R6, (R1) + MOVH R5, 1(R1) + ADD $0x03, R1, R1 + +match_nolit_emitcopy_end_encodeBlockAsm4MB: + MOVWU 16(RSP), R16 + CMPW R16, R2 + BHS emit_remainder_encodeBlockAsm4MB + ADD R2, R3, R15 + MOVD -2(R15), R6 + MOVD 8(RSP), R16 + CMP R16, R1 + BLO match_nolit_dst_ok_encodeBlockAsm4MB + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +match_nolit_dst_ok_encodeBlockAsm4MB: + MOVD $0x0000cf1bbcdcbf9b, R8 + MOVD R6, R7 + LSR $0x10, R6, R6 + MOVD R6, R5 + LSL $0x10, R7, R7 + MUL R8, R7, R7 + LSR $0x32, R7, R7 + LSL $0x10, R5, R5 + MUL R8, R5, R5 + LSR $0x32, R5, R5 + SUB $2, R2, R8 + MOVWU R8, R8 + ADD R5<<2, R0, R9 + MOVWU (R9), R5 + MOVW R8, (R0)(R7<<2) + MOVW R2, (R9) + MOVWU (R3)(R5), R16 + CMPW R6, R16 + BEQ match_nolit_loop_encodeBlockAsm4MB + ADDW $1, R2, R2 + JMP search_loop_encodeBlockAsm4MB + +emit_remainder_encodeBlockAsm4MB: + MOVD src_len+32(FP), R0 + MOVWU 20(RSP), R16 + SUBW R16, R0, R0 + ADD R0, R1, R0 + ADD $4, R0, R0 + MOVD 8(RSP), R16 + CMP R16, R0 + BLO emit_remainder_ok_encodeBlockAsm4MB + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +emit_remainder_ok_encodeBlockAsm4MB: + MOVD src_len+32(FP), R0 + MOVWU 20(RSP), R2 + CMPW R0, R2 + BEQ emit_literal_done_emit_remainder_encodeBlockAsm4MB + MOVWU R0, R5 + MOVW R0, 20(RSP) + ADD R2, R3, R0 + SUBW R2, R5, R5 + SUB $1, R5, R2 + MOVWU R2, R2 + CMPW $0x3c, R2 + BLO one_byte_emit_remainder_encodeBlockAsm4MB + CMPW $0x00000100, R2 + BLO two_bytes_emit_remainder_encodeBlockAsm4MB + CMPW $0x00010000, R2 + BLO three_bytes_emit_remainder_encodeBlockAsm4MB + MOVWU R2, R3 + LSRW $0x10, R3, R3 + MOVD $0xf8, R16 + MOVB R16, (R1) + MOVH R2, 1(R1) + MOVB R3, 3(R1) + ADD $0x04, R1, R1 + JMP memmove_long_emit_remainder_encodeBlockAsm4MB + +three_bytes_emit_remainder_encodeBlockAsm4MB: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R2, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_emit_remainder_encodeBlockAsm4MB + +two_bytes_emit_remainder_encodeBlockAsm4MB: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R2, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R2 + BLO memmove_emit_remainder_encodeBlockAsm4MB + JMP memmove_long_emit_remainder_encodeBlockAsm4MB + +one_byte_emit_remainder_encodeBlockAsm4MB: + LSLW $0x02, R2, R16 + BFI $0, R16, $8, R2 + MOVB R2, (R1) + ADD $0x01, R1, R1 + +memmove_emit_remainder_encodeBlockAsm4MB: + ADD R5, R1, R2 + MOVWU R5, R3 + + // genMemMoveShort + CMP $0x03, R3 + BLO emit_lit_memmove_emit_remainder_encodeBlockAsm4MB_memmove_move_1or2 + BEQ emit_lit_memmove_emit_remainder_encodeBlockAsm4MB_memmove_move_3 + CMP $0x08, R3 + BLO emit_lit_memmove_emit_remainder_encodeBlockAsm4MB_memmove_move_4through7 + CMP $0x10, R3 + BLS emit_lit_memmove_emit_remainder_encodeBlockAsm4MB_memmove_move_8through16 + CMP $0x20, R3 + BLS emit_lit_memmove_emit_remainder_encodeBlockAsm4MB_memmove_move_17through32 + JMP emit_lit_memmove_emit_remainder_encodeBlockAsm4MB_memmove_move_33through64 + +emit_lit_memmove_emit_remainder_encodeBlockAsm4MB_memmove_move_1or2: + MOVBU (R0), R16 + BFI $0, R16, $8, R5 + ADD R3, R0, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R0 + MOVB R5, (R1) + ADD R3, R1, R15 + MOVB R0, -1(R15) + JMP memmove_end_copy_emit_remainder_encodeBlockAsm4MB + +emit_lit_memmove_emit_remainder_encodeBlockAsm4MB_memmove_move_3: + MOVHU (R0), R16 + BFI $0, R16, $16, R5 + MOVBU 2(R0), R16 + BFI $0, R16, $8, R0 + MOVH R5, (R1) + MOVB R0, 2(R1) + JMP memmove_end_copy_emit_remainder_encodeBlockAsm4MB + +emit_lit_memmove_emit_remainder_encodeBlockAsm4MB_memmove_move_4through7: + MOVWU (R0), R5 + ADD R3, R0, R15 + MOVWU -4(R15), R0 + MOVW R5, (R1) + ADD R3, R1, R15 + MOVW R0, -4(R15) + JMP memmove_end_copy_emit_remainder_encodeBlockAsm4MB + +emit_lit_memmove_emit_remainder_encodeBlockAsm4MB_memmove_move_8through16: + MOVD (R0), R5 + ADD R3, R0, R15 + MOVD -8(R15), R0 + MOVD R5, (R1) + ADD R3, R1, R15 + MOVD R0, -8(R15) + JMP memmove_end_copy_emit_remainder_encodeBlockAsm4MB + +emit_lit_memmove_emit_remainder_encodeBlockAsm4MB_memmove_move_17through32: + FMOVQ (R0), F0 + ADD R3, R0, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R3, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_emit_remainder_encodeBlockAsm4MB + +emit_lit_memmove_emit_remainder_encodeBlockAsm4MB_memmove_move_33through64: + FMOVQ (R0), F0 + FMOVQ 16(R0), F1 + ADD R3, R0, R15 + FMOVQ -32(R15), F2 + ADD R3, R0, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R3, R1, R15 + FMOVQ F2, -32(R15) + ADD R3, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_emit_remainder_encodeBlockAsm4MB: + MOVD R2, R1 + JMP emit_literal_done_emit_remainder_encodeBlockAsm4MB + +memmove_long_emit_remainder_encodeBlockAsm4MB: + ADD R5, R1, R2 + MOVWU R5, R3 + + // genMemMoveLong + MOVD R0, R5 + MOVD R1, R6 + MOVD R3, R7 + +emit_lit_memmove_long_emit_remainder_encodeBlockAsm4MBlarge_big_loop_back: + FMOVQ (R5), F0 + FMOVQ 16(R5), F1 + FMOVQ F0, (R6) + FMOVQ F1, 16(R6) + ADD $0x20, R5, R5 + ADD $0x20, R6, R6 + SUB $0x20, R7, R7 + CMP $0x20, R7 + BHS emit_lit_memmove_long_emit_remainder_encodeBlockAsm4MBlarge_big_loop_back + ADD R3, R0, R15 + FMOVQ -32(R15), F0 + ADD R3, R0, R15 + FMOVQ -16(R15), F1 + ADD R3, R1, R15 + FMOVQ F0, -32(R15) + ADD R3, R1, R15 + FMOVQ F1, -16(R15) + MOVD R2, R1 + +emit_literal_done_emit_remainder_encodeBlockAsm4MB: + MOVD dst_base+0(FP), R0 + SUB R0, R1, R1 + MOVD R1, ret+56(FP) + RET + +// func encodeBlockAsm12B(dst []byte, src []byte, tmp *[16384]byte) int +// Requires: BMI, SSE2 +TEXT ·encodeBlockAsm12B(SB), $24-64 + MOVD tmp+48(FP), R0 + MOVD dst_base+0(FP), R1 + MOVD $0x00000080, R2 + MOVD R0, R3 + VEOR V0.B16, V0.B16, V0.B16 + +zero_loop_encodeBlockAsm12B: + FMOVQ F0, (R3) + FMOVQ F0, 16(R3) + FMOVQ F0, 32(R3) + FMOVQ F0, 48(R3) + FMOVQ F0, 64(R3) + FMOVQ F0, 80(R3) + FMOVQ F0, 96(R3) + FMOVQ F0, 112(R3) + ADD $0x80, R3, R3 + SUBS $1, R2, R2 + BNE zero_loop_encodeBlockAsm12B + MOVD $0x00000000, R16 + MOVW R16, 20(RSP) + MOVD src_len+32(FP), R2 + SUB $9, R2, R3 + SUB $8, R2, R5 + MOVW R5, 16(RSP) + LSR $0x05, R2, R2 + SUBW R2, R3, R3 + ADD R3, R1, R3 + MOVD R3, 8(RSP) + MOVD $0x00000001, R2 + MOVW R2, 24(RSP) + MOVD src_base+24(FP), R3 + +search_loop_encodeBlockAsm12B: + MOVWU R2, R5 + MOVWU 20(RSP), R16 + SUBW R16, R5, R5 + LSRW $0x05, R5, R5 + ADD R5, R2, R5 + ADD $4, R5, R5 + MOVWU R5, R5 + MOVWU 16(RSP), R16 + CMPW R16, R5 + BHS emit_remainder_encodeBlockAsm12B + MOVD (R3)(R2), R6 + MOVW R5, 28(RSP) + MOVD $0x000000cf1bbcdcbb, R8 + MOVD R6, R9 + MOVD R6, R10 + LSR $0x08, R10, R10 + LSL $0x18, R9, R9 + MUL R8, R9, R9 + LSR $0x34, R9, R9 + LSL $0x18, R10, R10 + MUL R8, R10, R10 + LSR $0x34, R10, R10 + MOVWU (R0)(R9<<2), R5 + MOVWU (R0)(R10<<2), R7 + MOVW R2, (R0)(R9<<2) + ADD $1, R2, R9 + MOVWU R9, R9 + MOVW R9, (R0)(R10<<2) + MOVD R6, R9 + LSR $0x10, R9, R9 + LSL $0x18, R9, R9 + MUL R8, R9, R9 + LSR $0x34, R9, R9 + MOVWU R2, R8 + MOVWU 24(RSP), R16 + SUBW R16, R8, R8 + ADD R8, R3, R15 + MOVWU 1(R15), R10 + MOVD R6, R8 + LSR $0x08, R8, R8 + CMPW R10, R8 + BNE no_repeat_found_encodeBlockAsm12B + ADD $1, R2, R6 + MOVWU R6, R6 + MOVWU 20(RSP), R7 + MOVWU R6, R5 + MOVWU 24(RSP), R16 + SUBSW R16, R5, R5 + BEQ repeat_extend_back_end_encodeBlockAsm12B + +repeat_extend_back_loop_encodeBlockAsm12B: + CMPW R7, R6 + BLS repeat_extend_back_end_encodeBlockAsm12B + ADD R5, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R8 + ADD R6, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R9 + AND $0xff, R9, R16 + AND $0xff, R8, R15 + CMP R16, R15 + BNE repeat_extend_back_end_encodeBlockAsm12B + SUB $1, R6, R6 + MOVWU R6, R6 + SUBSW $1, R5, R5 + BNE repeat_extend_back_loop_encodeBlockAsm12B + +repeat_extend_back_end_encodeBlockAsm12B: + MOVWU R6, R5 + MOVWU 20(RSP), R16 + SUBW R16, R5, R5 + ADD R5, R1, R5 + ADD $3, R5, R5 + MOVD 8(RSP), R16 + CMP R16, R5 + BLO repeat_dst_size_check_encodeBlockAsm12B + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +repeat_dst_size_check_encodeBlockAsm12B: + MOVWU 20(RSP), R5 + CMPW R6, R5 + BEQ emit_literal_done_repeat_emit_encodeBlockAsm12B + MOVWU R6, R8 + MOVW R6, 20(RSP) + ADD R5, R3, R9 + SUBW R5, R8, R8 + SUB $1, R8, R5 + MOVWU R5, R5 + CMPW $0x3c, R5 + BLO one_byte_repeat_emit_encodeBlockAsm12B + CMPW $0x00000100, R5 + BLO two_bytes_repeat_emit_encodeBlockAsm12B + BLO three_bytes_repeat_emit_encodeBlockAsm12B + +three_bytes_repeat_emit_encodeBlockAsm12B: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R5, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_repeat_emit_encodeBlockAsm12B + +two_bytes_repeat_emit_encodeBlockAsm12B: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R5, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R5 + BLO memmove_repeat_emit_encodeBlockAsm12B + JMP memmove_long_repeat_emit_encodeBlockAsm12B + +one_byte_repeat_emit_encodeBlockAsm12B: + LSLW $0x02, R5, R16 + BFI $0, R16, $8, R5 + MOVB R5, (R1) + ADD $0x01, R1, R1 + +memmove_repeat_emit_encodeBlockAsm12B: + ADD R8, R1, R5 + + // genMemMoveShort + CMP $0x08, R8 + BLS emit_lit_memmove_repeat_emit_encodeBlockAsm12B_memmove_move_8 + CMP $0x10, R8 + BLS emit_lit_memmove_repeat_emit_encodeBlockAsm12B_memmove_move_8through16 + CMP $0x20, R8 + BLS emit_lit_memmove_repeat_emit_encodeBlockAsm12B_memmove_move_17through32 + JMP emit_lit_memmove_repeat_emit_encodeBlockAsm12B_memmove_move_33through64 + +emit_lit_memmove_repeat_emit_encodeBlockAsm12B_memmove_move_8: + MOVD (R9), R10 + MOVD R10, (R1) + JMP memmove_end_copy_repeat_emit_encodeBlockAsm12B + +emit_lit_memmove_repeat_emit_encodeBlockAsm12B_memmove_move_8through16: + MOVD (R9), R10 + ADD R8, R9, R15 + MOVD -8(R15), R9 + MOVD R10, (R1) + ADD R8, R1, R15 + MOVD R9, -8(R15) + JMP memmove_end_copy_repeat_emit_encodeBlockAsm12B + +emit_lit_memmove_repeat_emit_encodeBlockAsm12B_memmove_move_17through32: + FMOVQ (R9), F0 + ADD R8, R9, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_repeat_emit_encodeBlockAsm12B + +emit_lit_memmove_repeat_emit_encodeBlockAsm12B_memmove_move_33through64: + FMOVQ (R9), F0 + FMOVQ 16(R9), F1 + ADD R8, R9, R15 + FMOVQ -32(R15), F2 + ADD R8, R9, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R8, R1, R15 + FMOVQ F2, -32(R15) + ADD R8, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_repeat_emit_encodeBlockAsm12B: + MOVD R5, R1 + JMP emit_literal_done_repeat_emit_encodeBlockAsm12B + +memmove_long_repeat_emit_encodeBlockAsm12B: + ADD R8, R1, R5 + + // genMemMoveLong + MOVD R9, R10 + MOVD R1, R11 + MOVD R8, R12 + +emit_lit_memmove_long_repeat_emit_encodeBlockAsm12Blarge_big_loop_back: + FMOVQ (R10), F0 + FMOVQ 16(R10), F1 + FMOVQ F0, (R11) + FMOVQ F1, 16(R11) + ADD $0x20, R10, R10 + ADD $0x20, R11, R11 + SUB $0x20, R12, R12 + CMP $0x20, R12 + BHS emit_lit_memmove_long_repeat_emit_encodeBlockAsm12Blarge_big_loop_back + ADD R8, R9, R15 + FMOVQ -32(R15), F0 + ADD R8, R9, R15 + FMOVQ -16(R15), F1 + ADD R8, R1, R15 + FMOVQ F0, -32(R15) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + MOVD R5, R1 + +emit_literal_done_repeat_emit_encodeBlockAsm12B: + ADDW $0x05, R2, R2 + MOVWU R2, R5 + MOVWU 24(RSP), R16 + SUBW R16, R5, R5 + MOVD src_len+32(FP), R8 + SUBW R2, R8, R8 + ADD R2, R3, R9 + ADD R5, R3, R5 + + // matchLen + MOVD $0, R11 + +matchlen_loopback_16_repeat_extend_encodeBlockAsm12B: + CMPW $0x10, R8 + BLO matchlen_match8_repeat_extend_encodeBlockAsm12B + MOVD (R9)(R11), R10 + ADD R11, R9, R15 + MOVD 8(R15), R12 + MOVD (R5)(R11), R16 + EOR R16, R10, R10 + TST R10, R10 + BNE matchlen_bsf_8_repeat_extend_encodeBlockAsm12B + ADD R11, R5, R15 + MOVD 8(R15), R16 + EOR R16, R12, R12 + TST R12, R12 + BNE matchlen_bsf_16repeat_extend_encodeBlockAsm12B + SUB $16, R8, R8 + MOVWU R8, R8 + ADD $16, R11, R11 + MOVWU R11, R11 + JMP matchlen_loopback_16_repeat_extend_encodeBlockAsm12B + +matchlen_bsf_16repeat_extend_encodeBlockAsm12B: + RBIT R12, R12 + CLZ R12, R12 + ASR $0x03, R12, R12 + ADD R12, R11, R11 + ADD $8, R11, R11 + MOVWU R11, R11 + JMP repeat_extend_forward_end_encodeBlockAsm12B + +matchlen_match8_repeat_extend_encodeBlockAsm12B: + CMPW $0x08, R8 + BLO matchlen_match4_repeat_extend_encodeBlockAsm12B + MOVD (R9)(R11), R10 + MOVD (R5)(R11), R16 + EOR R16, R10, R10 + TST R10, R10 + BNE matchlen_bsf_8_repeat_extend_encodeBlockAsm12B + SUB $8, R8, R8 + MOVWU R8, R8 + ADD $8, R11, R11 + MOVWU R11, R11 + JMP matchlen_match4_repeat_extend_encodeBlockAsm12B + +matchlen_bsf_8_repeat_extend_encodeBlockAsm12B: + RBIT R10, R10 + CLZ R10, R10 + ASR $0x03, R10, R10 + ADD R10, R11, R11 + MOVWU R11, R11 + JMP repeat_extend_forward_end_encodeBlockAsm12B + +matchlen_match4_repeat_extend_encodeBlockAsm12B: + CMPW $0x04, R8 + BLO matchlen_match2_repeat_extend_encodeBlockAsm12B + MOVWU (R9)(R11), R10 + MOVWU (R5)(R11), R16 + CMPW R10, R16 + BNE matchlen_match2_repeat_extend_encodeBlockAsm12B + SUB $4, R8, R8 + MOVWU R8, R8 + ADD $4, R11, R11 + MOVWU R11, R11 + +matchlen_match2_repeat_extend_encodeBlockAsm12B: + CMPW $0x01, R8 + BEQ matchlen_match1_repeat_extend_encodeBlockAsm12B + BLO repeat_extend_forward_end_encodeBlockAsm12B + MOVHU (R9)(R11), R16 + BFI $0, R16, $16, R10 + ADD R11, R5, R15 + MOVHU (R15), R15 + AND $0xffff, R10, R16 + CMP R16, R15 + BNE matchlen_match1_repeat_extend_encodeBlockAsm12B + ADD $2, R11, R11 + MOVWU R11, R11 + SUBSW $0x02, R8, R8 + BEQ repeat_extend_forward_end_encodeBlockAsm12B + +matchlen_match1_repeat_extend_encodeBlockAsm12B: + MOVBU (R9)(R11), R16 + BFI $0, R16, $8, R10 + ADD R11, R5, R15 + MOVBU (R15), R15 + AND $0xff, R10, R16 + CMP R16, R15 + BNE repeat_extend_forward_end_encodeBlockAsm12B + ADD $1, R11, R11 + MOVWU R11, R11 + +repeat_extend_forward_end_encodeBlockAsm12B: + ADDW R11, R2, R2 + MOVWU R2, R5 + SUBW R6, R5, R5 + MOVWU 24(RSP), R6 + TSTW R7, R7 + BEQ repeat_as_copy_encodeBlockAsm12B + + // emitRepeat + MOVWU R5, R7 + SUB $4, R5, R5 + MOVWU R5, R5 + CMPW $0x08, R7 + BLS repeat_two_match_repeat_encodeBlockAsm12B + CMPW $0x0c, R7 + BHS cant_repeat_two_offset_match_repeat_encodeBlockAsm12B + CMPW $0x00000800, R6 + BLO repeat_two_offset_match_repeat_encodeBlockAsm12B + +cant_repeat_two_offset_match_repeat_encodeBlockAsm12B: + CMPW $0x00000104, R5 + BLO repeat_three_match_repeat_encodeBlockAsm12B + SUB $256, R5, R5 + MOVWU R5, R5 + MOVD $0x0019, R16 + MOVH R16, (R1) + MOVH R5, 2(R1) + ADD $0x04, R1, R1 + JMP repeat_end_emit_encodeBlockAsm12B + +repeat_three_match_repeat_encodeBlockAsm12B: + SUB $4, R5, R5 + MOVWU R5, R5 + MOVD $0x0015, R16 + MOVH R16, (R1) + MOVB R5, 2(R1) + ADD $0x03, R1, R1 + JMP repeat_end_emit_encodeBlockAsm12B + +repeat_two_match_repeat_encodeBlockAsm12B: + LSLW $0x02, R5, R5 + ORRW $0x01, R5, R5 + MOVH R5, (R1) + ADD $0x02, R1, R1 + JMP repeat_end_emit_encodeBlockAsm12B + +repeat_two_offset_match_repeat_encodeBlockAsm12B: + MOVD $0, R7 + ADD R5<<2, R7, R5 + ADD $1, R5, R5 + MOVWU R5, R5 + MOVB R6, 1(R1) + ASRW $0x08, R6, R6 + LSLW $0x05, R6, R6 + ORRW R6, R5, R5 + MOVB R5, (R1) + ADD $0x02, R1, R1 + JMP repeat_end_emit_encodeBlockAsm12B + +repeat_as_copy_encodeBlockAsm12B: + // emitCopy + CMPW $0x40, R5 + BLS two_byte_offset_short_repeat_as_copy_encodeBlockAsm12B + CMPW $0x00000800, R6 + BHS long_offset_short_repeat_as_copy_encodeBlockAsm12B + MOVD $0x00000001, R7 + ADD $16, R7, R7 + MOVWU R7, R7 + MOVB R6, 1(R1) + LSRW $0x08, R6, R6 + LSLW $0x05, R6, R6 + ORRW R6, R7, R7 + MOVB R7, (R1) + ADD $0x02, R1, R1 + SUBW $0x08, R5, R5 + + // emitRepeat + SUB $4, R5, R5 + MOVWU R5, R5 + JMP cant_repeat_two_offset_repeat_as_copy_encodeBlockAsm12B_emit_copy_short_2b + MOVWU R5, R7 + SUB $4, R5, R5 + MOVWU R5, R5 + CMPW $0x08, R7 + BLS repeat_two_repeat_as_copy_encodeBlockAsm12B_emit_copy_short_2b + CMPW $0x0c, R7 + BHS cant_repeat_two_offset_repeat_as_copy_encodeBlockAsm12B_emit_copy_short_2b + CMPW $0x00000800, R6 + BLO repeat_two_offset_repeat_as_copy_encodeBlockAsm12B_emit_copy_short_2b + +cant_repeat_two_offset_repeat_as_copy_encodeBlockAsm12B_emit_copy_short_2b: + CMPW $0x00000104, R5 + BLO repeat_three_repeat_as_copy_encodeBlockAsm12B_emit_copy_short_2b + SUB $256, R5, R5 + MOVWU R5, R5 + MOVD $0x0019, R16 + MOVH R16, (R1) + MOVH R5, 2(R1) + ADD $0x04, R1, R1 + JMP repeat_end_emit_encodeBlockAsm12B + +repeat_three_repeat_as_copy_encodeBlockAsm12B_emit_copy_short_2b: + SUB $4, R5, R5 + MOVWU R5, R5 + MOVD $0x0015, R16 + MOVH R16, (R1) + MOVB R5, 2(R1) + ADD $0x03, R1, R1 + JMP repeat_end_emit_encodeBlockAsm12B + +repeat_two_repeat_as_copy_encodeBlockAsm12B_emit_copy_short_2b: + LSLW $0x02, R5, R5 + ORRW $0x01, R5, R5 + MOVH R5, (R1) + ADD $0x02, R1, R1 + JMP repeat_end_emit_encodeBlockAsm12B + +repeat_two_offset_repeat_as_copy_encodeBlockAsm12B_emit_copy_short_2b: + MOVD $0, R7 + ADD R5<<2, R7, R5 + ADD $1, R5, R5 + MOVWU R5, R5 + MOVB R6, 1(R1) + ASRW $0x08, R6, R6 + LSLW $0x05, R6, R6 + ORRW R6, R5, R5 + MOVB R5, (R1) + ADD $0x02, R1, R1 + JMP repeat_end_emit_encodeBlockAsm12B + +long_offset_short_repeat_as_copy_encodeBlockAsm12B: + MOVD $0xee, R16 + MOVB R16, (R1) + MOVH R6, 1(R1) + SUB $60, R5, R5 + MOVWU R5, R5 + ADD $0x03, R1, R1 + + // emitRepeat + MOVWU R5, R7 + SUB $4, R5, R5 + MOVWU R5, R5 + CMPW $0x08, R7 + BLS repeat_two_repeat_as_copy_encodeBlockAsm12B_emit_copy_short + CMPW $0x0c, R7 + BHS cant_repeat_two_offset_repeat_as_copy_encodeBlockAsm12B_emit_copy_short + CMPW $0x00000800, R6 + BLO repeat_two_offset_repeat_as_copy_encodeBlockAsm12B_emit_copy_short + +cant_repeat_two_offset_repeat_as_copy_encodeBlockAsm12B_emit_copy_short: + CMPW $0x00000104, R5 + BLO repeat_three_repeat_as_copy_encodeBlockAsm12B_emit_copy_short + SUB $256, R5, R5 + MOVWU R5, R5 + MOVD $0x0019, R16 + MOVH R16, (R1) + MOVH R5, 2(R1) + ADD $0x04, R1, R1 + JMP repeat_end_emit_encodeBlockAsm12B + +repeat_three_repeat_as_copy_encodeBlockAsm12B_emit_copy_short: + SUB $4, R5, R5 + MOVWU R5, R5 + MOVD $0x0015, R16 + MOVH R16, (R1) + MOVB R5, 2(R1) + ADD $0x03, R1, R1 + JMP repeat_end_emit_encodeBlockAsm12B + +repeat_two_repeat_as_copy_encodeBlockAsm12B_emit_copy_short: + LSLW $0x02, R5, R5 + ORRW $0x01, R5, R5 + MOVH R5, (R1) + ADD $0x02, R1, R1 + JMP repeat_end_emit_encodeBlockAsm12B + +repeat_two_offset_repeat_as_copy_encodeBlockAsm12B_emit_copy_short: + MOVD $0, R7 + ADD R5<<2, R7, R5 + ADD $1, R5, R5 + MOVWU R5, R5 + MOVB R6, 1(R1) + ASRW $0x08, R6, R6 + LSLW $0x05, R6, R6 + ORRW R6, R5, R5 + MOVB R5, (R1) + ADD $0x02, R1, R1 + JMP repeat_end_emit_encodeBlockAsm12B + +two_byte_offset_short_repeat_as_copy_encodeBlockAsm12B: + MOVWU R5, R7 + LSLW $0x02, R7, R7 + CMPW $0x0c, R5 + BHS emit_copy_three_repeat_as_copy_encodeBlockAsm12B + CMPW $0x00000800, R6 + BHS emit_copy_three_repeat_as_copy_encodeBlockAsm12B + SUB $15, R7, R7 + MOVWU R7, R7 + MOVB R6, 1(R1) + LSRW $0x08, R6, R6 + LSLW $0x05, R6, R6 + ORRW R6, R7, R7 + MOVB R7, (R1) + ADD $0x02, R1, R1 + JMP repeat_end_emit_encodeBlockAsm12B + +emit_copy_three_repeat_as_copy_encodeBlockAsm12B: + SUB $2, R7, R7 + MOVWU R7, R7 + MOVB R7, (R1) + MOVH R6, 1(R1) + ADD $0x03, R1, R1 + +repeat_end_emit_encodeBlockAsm12B: + MOVW R2, 20(RSP) + JMP search_loop_encodeBlockAsm12B + +no_repeat_found_encodeBlockAsm12B: + MOVWU (R3)(R5), R16 + CMPW R6, R16 + BEQ candidate_match_encodeBlockAsm12B + LSR $0x08, R6, R6 + MOVWU (R0)(R9<<2), R5 + ADD $2, R2, R8 + MOVWU R8, R8 + MOVWU (R3)(R7), R16 + CMPW R6, R16 + BEQ candidate2_match_encodeBlockAsm12B + MOVW R8, (R0)(R9<<2) + LSR $0x08, R6, R6 + MOVWU (R3)(R5), R16 + CMPW R6, R16 + BEQ candidate3_match_encodeBlockAsm12B + MOVWU 28(RSP), R2 + JMP search_loop_encodeBlockAsm12B + +candidate3_match_encodeBlockAsm12B: + ADDW $0x02, R2, R2 + JMP candidate_match_encodeBlockAsm12B + +candidate2_match_encodeBlockAsm12B: + MOVW R8, (R0)(R9<<2) + ADDW $1, R2, R2 + MOVWU R7, R5 + +candidate_match_encodeBlockAsm12B: + MOVWU 20(RSP), R6 + TSTW R5, R5 + BEQ match_extend_back_end_encodeBlockAsm12B + +match_extend_back_loop_encodeBlockAsm12B: + CMPW R6, R2 + BLS match_extend_back_end_encodeBlockAsm12B + ADD R5, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R7 + ADD R2, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R8 + AND $0xff, R8, R16 + AND $0xff, R7, R15 + CMP R16, R15 + BNE match_extend_back_end_encodeBlockAsm12B + SUB $1, R2, R2 + MOVWU R2, R2 + SUBSW $1, R5, R5 + BEQ match_extend_back_end_encodeBlockAsm12B + JMP match_extend_back_loop_encodeBlockAsm12B + +match_extend_back_end_encodeBlockAsm12B: + MOVWU R2, R6 + MOVWU 20(RSP), R16 + SUBW R16, R6, R6 + ADD R6, R1, R6 + ADD $3, R6, R6 + MOVD 8(RSP), R16 + CMP R16, R6 + BLO match_dst_size_check_encodeBlockAsm12B + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +match_dst_size_check_encodeBlockAsm12B: + MOVWU R2, R6 + MOVWU 20(RSP), R7 + CMPW R6, R7 + BEQ emit_literal_done_match_emit_encodeBlockAsm12B + MOVWU R6, R8 + MOVW R6, 20(RSP) + ADD R7, R3, R6 + SUBW R7, R8, R8 + SUB $1, R8, R7 + MOVWU R7, R7 + CMPW $0x3c, R7 + BLO one_byte_match_emit_encodeBlockAsm12B + CMPW $0x00000100, R7 + BLO two_bytes_match_emit_encodeBlockAsm12B + BLO three_bytes_match_emit_encodeBlockAsm12B + +three_bytes_match_emit_encodeBlockAsm12B: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R7, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_match_emit_encodeBlockAsm12B + +two_bytes_match_emit_encodeBlockAsm12B: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R7, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R7 + BLO memmove_match_emit_encodeBlockAsm12B + JMP memmove_long_match_emit_encodeBlockAsm12B + +one_byte_match_emit_encodeBlockAsm12B: + LSLW $0x02, R7, R16 + BFI $0, R16, $8, R7 + MOVB R7, (R1) + ADD $0x01, R1, R1 + +memmove_match_emit_encodeBlockAsm12B: + ADD R8, R1, R7 + + // genMemMoveShort + CMP $0x08, R8 + BLS emit_lit_memmove_match_emit_encodeBlockAsm12B_memmove_move_8 + CMP $0x10, R8 + BLS emit_lit_memmove_match_emit_encodeBlockAsm12B_memmove_move_8through16 + CMP $0x20, R8 + BLS emit_lit_memmove_match_emit_encodeBlockAsm12B_memmove_move_17through32 + JMP emit_lit_memmove_match_emit_encodeBlockAsm12B_memmove_move_33through64 + +emit_lit_memmove_match_emit_encodeBlockAsm12B_memmove_move_8: + MOVD (R6), R9 + MOVD R9, (R1) + JMP memmove_end_copy_match_emit_encodeBlockAsm12B + +emit_lit_memmove_match_emit_encodeBlockAsm12B_memmove_move_8through16: + MOVD (R6), R9 + ADD R8, R6, R15 + MOVD -8(R15), R6 + MOVD R9, (R1) + ADD R8, R1, R15 + MOVD R6, -8(R15) + JMP memmove_end_copy_match_emit_encodeBlockAsm12B + +emit_lit_memmove_match_emit_encodeBlockAsm12B_memmove_move_17through32: + FMOVQ (R6), F0 + ADD R8, R6, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_match_emit_encodeBlockAsm12B + +emit_lit_memmove_match_emit_encodeBlockAsm12B_memmove_move_33through64: + FMOVQ (R6), F0 + FMOVQ 16(R6), F1 + ADD R8, R6, R15 + FMOVQ -32(R15), F2 + ADD R8, R6, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R8, R1, R15 + FMOVQ F2, -32(R15) + ADD R8, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_match_emit_encodeBlockAsm12B: + MOVD R7, R1 + JMP emit_literal_done_match_emit_encodeBlockAsm12B + +memmove_long_match_emit_encodeBlockAsm12B: + ADD R8, R1, R7 + + // genMemMoveLong + MOVD R6, R9 + MOVD R1, R10 + MOVD R8, R11 + +emit_lit_memmove_long_match_emit_encodeBlockAsm12Blarge_big_loop_back: + FMOVQ (R9), F0 + FMOVQ 16(R9), F1 + FMOVQ F0, (R10) + FMOVQ F1, 16(R10) + ADD $0x20, R9, R9 + ADD $0x20, R10, R10 + SUB $0x20, R11, R11 + CMP $0x20, R11 + BHS emit_lit_memmove_long_match_emit_encodeBlockAsm12Blarge_big_loop_back + ADD R8, R6, R15 + FMOVQ -32(R15), F0 + ADD R8, R6, R15 + FMOVQ -16(R15), F1 + ADD R8, R1, R15 + FMOVQ F0, -32(R15) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + MOVD R7, R1 + +emit_literal_done_match_emit_encodeBlockAsm12B: +match_nolit_loop_encodeBlockAsm12B: + MOVWU R2, R6 + SUBW R5, R6, R6 + MOVW R6, 24(RSP) + ADDW $0x04, R2, R2 + ADDW $0x04, R5, R5 + MOVD src_len+32(FP), R6 + SUBW R2, R6, R6 + ADD R2, R3, R7 + ADD R5, R3, R5 + + // matchLen + MOVD $0, R9 + +matchlen_loopback_16_match_nolit_encodeBlockAsm12B: + CMPW $0x10, R6 + BLO matchlen_match8_match_nolit_encodeBlockAsm12B + MOVD (R7)(R9), R8 + ADD R9, R7, R15 + MOVD 8(R15), R10 + MOVD (R5)(R9), R16 + EOR R16, R8, R8 + TST R8, R8 + BNE matchlen_bsf_8_match_nolit_encodeBlockAsm12B + ADD R9, R5, R15 + MOVD 8(R15), R16 + EOR R16, R10, R10 + TST R10, R10 + BNE matchlen_bsf_16match_nolit_encodeBlockAsm12B + SUB $16, R6, R6 + MOVWU R6, R6 + ADD $16, R9, R9 + MOVWU R9, R9 + JMP matchlen_loopback_16_match_nolit_encodeBlockAsm12B + +matchlen_bsf_16match_nolit_encodeBlockAsm12B: + RBIT R10, R10 + CLZ R10, R10 + ASR $0x03, R10, R10 + ADD R10, R9, R9 + ADD $8, R9, R9 + MOVWU R9, R9 + JMP match_nolit_end_encodeBlockAsm12B + +matchlen_match8_match_nolit_encodeBlockAsm12B: + CMPW $0x08, R6 + BLO matchlen_match4_match_nolit_encodeBlockAsm12B + MOVD (R7)(R9), R8 + MOVD (R5)(R9), R16 + EOR R16, R8, R8 + TST R8, R8 + BNE matchlen_bsf_8_match_nolit_encodeBlockAsm12B + SUB $8, R6, R6 + MOVWU R6, R6 + ADD $8, R9, R9 + MOVWU R9, R9 + JMP matchlen_match4_match_nolit_encodeBlockAsm12B + +matchlen_bsf_8_match_nolit_encodeBlockAsm12B: + RBIT R8, R8 + CLZ R8, R8 + ASR $0x03, R8, R8 + ADD R8, R9, R9 + MOVWU R9, R9 + JMP match_nolit_end_encodeBlockAsm12B + +matchlen_match4_match_nolit_encodeBlockAsm12B: + CMPW $0x04, R6 + BLO matchlen_match2_match_nolit_encodeBlockAsm12B + MOVWU (R7)(R9), R8 + MOVWU (R5)(R9), R16 + CMPW R8, R16 + BNE matchlen_match2_match_nolit_encodeBlockAsm12B + SUB $4, R6, R6 + MOVWU R6, R6 + ADD $4, R9, R9 + MOVWU R9, R9 + +matchlen_match2_match_nolit_encodeBlockAsm12B: + CMPW $0x01, R6 + BEQ matchlen_match1_match_nolit_encodeBlockAsm12B + BLO match_nolit_end_encodeBlockAsm12B + MOVHU (R7)(R9), R16 + BFI $0, R16, $16, R8 + ADD R9, R5, R15 + MOVHU (R15), R15 + AND $0xffff, R8, R16 + CMP R16, R15 + BNE matchlen_match1_match_nolit_encodeBlockAsm12B + ADD $2, R9, R9 + MOVWU R9, R9 + SUBSW $0x02, R6, R6 + BEQ match_nolit_end_encodeBlockAsm12B + +matchlen_match1_match_nolit_encodeBlockAsm12B: + MOVBU (R7)(R9), R16 + BFI $0, R16, $8, R8 + ADD R9, R5, R15 + MOVBU (R15), R15 + AND $0xff, R8, R16 + CMP R16, R15 + BNE match_nolit_end_encodeBlockAsm12B + ADD $1, R9, R9 + MOVWU R9, R9 + +match_nolit_end_encodeBlockAsm12B: + ADDW R9, R2, R2 + MOVWU 24(RSP), R5 + ADDW $0x04, R9, R9 + MOVW R2, 20(RSP) + + // emitCopy + CMPW $0x40, R9 + BLS two_byte_offset_short_match_nolit_encodeBlockAsm12B + CMPW $0x00000800, R5 + BHS long_offset_short_match_nolit_encodeBlockAsm12B + MOVD $0x00000001, R6 + ADD $16, R6, R6 + MOVWU R6, R6 + MOVB R5, 1(R1) + LSRW $0x08, R5, R5 + LSLW $0x05, R5, R5 + ORRW R5, R6, R6 + MOVB R6, (R1) + ADD $0x02, R1, R1 + SUBW $0x08, R9, R9 + + // emitRepeat + SUB $4, R9, R9 + MOVWU R9, R9 + JMP cant_repeat_two_offset_match_nolit_encodeBlockAsm12B_emit_copy_short_2b + MOVWU R9, R6 + SUB $4, R9, R9 + MOVWU R9, R9 + CMPW $0x08, R6 + BLS repeat_two_match_nolit_encodeBlockAsm12B_emit_copy_short_2b + CMPW $0x0c, R6 + BHS cant_repeat_two_offset_match_nolit_encodeBlockAsm12B_emit_copy_short_2b + CMPW $0x00000800, R5 + BLO repeat_two_offset_match_nolit_encodeBlockAsm12B_emit_copy_short_2b + +cant_repeat_two_offset_match_nolit_encodeBlockAsm12B_emit_copy_short_2b: + CMPW $0x00000104, R9 + BLO repeat_three_match_nolit_encodeBlockAsm12B_emit_copy_short_2b + SUB $256, R9, R9 + MOVWU R9, R9 + MOVD $0x0019, R16 + MOVH R16, (R1) + MOVH R9, 2(R1) + ADD $0x04, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm12B + +repeat_three_match_nolit_encodeBlockAsm12B_emit_copy_short_2b: + SUB $4, R9, R9 + MOVWU R9, R9 + MOVD $0x0015, R16 + MOVH R16, (R1) + MOVB R9, 2(R1) + ADD $0x03, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm12B + +repeat_two_match_nolit_encodeBlockAsm12B_emit_copy_short_2b: + LSLW $0x02, R9, R9 + ORRW $0x01, R9, R9 + MOVH R9, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm12B + +repeat_two_offset_match_nolit_encodeBlockAsm12B_emit_copy_short_2b: + MOVD $0, R6 + ADD R9<<2, R6, R9 + ADD $1, R9, R9 + MOVWU R9, R9 + MOVB R5, 1(R1) + ASRW $0x08, R5, R5 + LSLW $0x05, R5, R5 + ORRW R5, R9, R9 + MOVB R9, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm12B + +long_offset_short_match_nolit_encodeBlockAsm12B: + MOVD $0xee, R16 + MOVB R16, (R1) + MOVH R5, 1(R1) + SUB $60, R9, R9 + MOVWU R9, R9 + ADD $0x03, R1, R1 + + // emitRepeat + MOVWU R9, R6 + SUB $4, R9, R9 + MOVWU R9, R9 + CMPW $0x08, R6 + BLS repeat_two_match_nolit_encodeBlockAsm12B_emit_copy_short + CMPW $0x0c, R6 + BHS cant_repeat_two_offset_match_nolit_encodeBlockAsm12B_emit_copy_short + CMPW $0x00000800, R5 + BLO repeat_two_offset_match_nolit_encodeBlockAsm12B_emit_copy_short + +cant_repeat_two_offset_match_nolit_encodeBlockAsm12B_emit_copy_short: + CMPW $0x00000104, R9 + BLO repeat_three_match_nolit_encodeBlockAsm12B_emit_copy_short + SUB $256, R9, R9 + MOVWU R9, R9 + MOVD $0x0019, R16 + MOVH R16, (R1) + MOVH R9, 2(R1) + ADD $0x04, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm12B + +repeat_three_match_nolit_encodeBlockAsm12B_emit_copy_short: + SUB $4, R9, R9 + MOVWU R9, R9 + MOVD $0x0015, R16 + MOVH R16, (R1) + MOVB R9, 2(R1) + ADD $0x03, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm12B + +repeat_two_match_nolit_encodeBlockAsm12B_emit_copy_short: + LSLW $0x02, R9, R9 + ORRW $0x01, R9, R9 + MOVH R9, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm12B + +repeat_two_offset_match_nolit_encodeBlockAsm12B_emit_copy_short: + MOVD $0, R6 + ADD R9<<2, R6, R9 + ADD $1, R9, R9 + MOVWU R9, R9 + MOVB R5, 1(R1) + ASRW $0x08, R5, R5 + LSLW $0x05, R5, R5 + ORRW R5, R9, R9 + MOVB R9, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm12B + +two_byte_offset_short_match_nolit_encodeBlockAsm12B: + MOVWU R9, R6 + LSLW $0x02, R6, R6 + CMPW $0x0c, R9 + BHS emit_copy_three_match_nolit_encodeBlockAsm12B + CMPW $0x00000800, R5 + BHS emit_copy_three_match_nolit_encodeBlockAsm12B + SUB $15, R6, R6 + MOVWU R6, R6 + MOVB R5, 1(R1) + LSRW $0x08, R5, R5 + LSLW $0x05, R5, R5 + ORRW R5, R6, R6 + MOVB R6, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm12B + +emit_copy_three_match_nolit_encodeBlockAsm12B: + SUB $2, R6, R6 + MOVWU R6, R6 + MOVB R6, (R1) + MOVH R5, 1(R1) + ADD $0x03, R1, R1 + +match_nolit_emitcopy_end_encodeBlockAsm12B: + MOVWU 16(RSP), R16 + CMPW R16, R2 + BHS emit_remainder_encodeBlockAsm12B + ADD R2, R3, R15 + MOVD -2(R15), R6 + MOVD 8(RSP), R16 + CMP R16, R1 + BLO match_nolit_dst_ok_encodeBlockAsm12B + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +match_nolit_dst_ok_encodeBlockAsm12B: + MOVD $0x000000cf1bbcdcbb, R8 + MOVD R6, R7 + LSR $0x10, R6, R6 + MOVD R6, R5 + LSL $0x18, R7, R7 + MUL R8, R7, R7 + LSR $0x34, R7, R7 + LSL $0x18, R5, R5 + MUL R8, R5, R5 + LSR $0x34, R5, R5 + SUB $2, R2, R8 + MOVWU R8, R8 + ADD R5<<2, R0, R9 + MOVWU (R9), R5 + MOVW R8, (R0)(R7<<2) + MOVW R2, (R9) + MOVWU (R3)(R5), R16 + CMPW R6, R16 + BEQ match_nolit_loop_encodeBlockAsm12B + ADDW $1, R2, R2 + JMP search_loop_encodeBlockAsm12B + +emit_remainder_encodeBlockAsm12B: + MOVD src_len+32(FP), R0 + MOVWU 20(RSP), R16 + SUBW R16, R0, R0 + ADD R0, R1, R0 + ADD $3, R0, R0 + MOVD 8(RSP), R16 + CMP R16, R0 + BLO emit_remainder_ok_encodeBlockAsm12B + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +emit_remainder_ok_encodeBlockAsm12B: + MOVD src_len+32(FP), R0 + MOVWU 20(RSP), R2 + CMPW R0, R2 + BEQ emit_literal_done_emit_remainder_encodeBlockAsm12B + MOVWU R0, R5 + MOVW R0, 20(RSP) + ADD R2, R3, R0 + SUBW R2, R5, R5 + SUB $1, R5, R2 + MOVWU R2, R2 + CMPW $0x3c, R2 + BLO one_byte_emit_remainder_encodeBlockAsm12B + CMPW $0x00000100, R2 + BLO two_bytes_emit_remainder_encodeBlockAsm12B + BLO three_bytes_emit_remainder_encodeBlockAsm12B + +three_bytes_emit_remainder_encodeBlockAsm12B: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R2, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_emit_remainder_encodeBlockAsm12B + +two_bytes_emit_remainder_encodeBlockAsm12B: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R2, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R2 + BLO memmove_emit_remainder_encodeBlockAsm12B + JMP memmove_long_emit_remainder_encodeBlockAsm12B + +one_byte_emit_remainder_encodeBlockAsm12B: + LSLW $0x02, R2, R16 + BFI $0, R16, $8, R2 + MOVB R2, (R1) + ADD $0x01, R1, R1 + +memmove_emit_remainder_encodeBlockAsm12B: + ADD R5, R1, R2 + MOVWU R5, R3 + + // genMemMoveShort + CMP $0x03, R3 + BLO emit_lit_memmove_emit_remainder_encodeBlockAsm12B_memmove_move_1or2 + BEQ emit_lit_memmove_emit_remainder_encodeBlockAsm12B_memmove_move_3 + CMP $0x08, R3 + BLO emit_lit_memmove_emit_remainder_encodeBlockAsm12B_memmove_move_4through7 + CMP $0x10, R3 + BLS emit_lit_memmove_emit_remainder_encodeBlockAsm12B_memmove_move_8through16 + CMP $0x20, R3 + BLS emit_lit_memmove_emit_remainder_encodeBlockAsm12B_memmove_move_17through32 + JMP emit_lit_memmove_emit_remainder_encodeBlockAsm12B_memmove_move_33through64 + +emit_lit_memmove_emit_remainder_encodeBlockAsm12B_memmove_move_1or2: + MOVBU (R0), R16 + BFI $0, R16, $8, R5 + ADD R3, R0, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R0 + MOVB R5, (R1) + ADD R3, R1, R15 + MOVB R0, -1(R15) + JMP memmove_end_copy_emit_remainder_encodeBlockAsm12B + +emit_lit_memmove_emit_remainder_encodeBlockAsm12B_memmove_move_3: + MOVHU (R0), R16 + BFI $0, R16, $16, R5 + MOVBU 2(R0), R16 + BFI $0, R16, $8, R0 + MOVH R5, (R1) + MOVB R0, 2(R1) + JMP memmove_end_copy_emit_remainder_encodeBlockAsm12B + +emit_lit_memmove_emit_remainder_encodeBlockAsm12B_memmove_move_4through7: + MOVWU (R0), R5 + ADD R3, R0, R15 + MOVWU -4(R15), R0 + MOVW R5, (R1) + ADD R3, R1, R15 + MOVW R0, -4(R15) + JMP memmove_end_copy_emit_remainder_encodeBlockAsm12B + +emit_lit_memmove_emit_remainder_encodeBlockAsm12B_memmove_move_8through16: + MOVD (R0), R5 + ADD R3, R0, R15 + MOVD -8(R15), R0 + MOVD R5, (R1) + ADD R3, R1, R15 + MOVD R0, -8(R15) + JMP memmove_end_copy_emit_remainder_encodeBlockAsm12B + +emit_lit_memmove_emit_remainder_encodeBlockAsm12B_memmove_move_17through32: + FMOVQ (R0), F0 + ADD R3, R0, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R3, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_emit_remainder_encodeBlockAsm12B + +emit_lit_memmove_emit_remainder_encodeBlockAsm12B_memmove_move_33through64: + FMOVQ (R0), F0 + FMOVQ 16(R0), F1 + ADD R3, R0, R15 + FMOVQ -32(R15), F2 + ADD R3, R0, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R3, R1, R15 + FMOVQ F2, -32(R15) + ADD R3, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_emit_remainder_encodeBlockAsm12B: + MOVD R2, R1 + JMP emit_literal_done_emit_remainder_encodeBlockAsm12B + +memmove_long_emit_remainder_encodeBlockAsm12B: + ADD R5, R1, R2 + MOVWU R5, R3 + + // genMemMoveLong + MOVD R0, R5 + MOVD R1, R6 + MOVD R3, R7 + +emit_lit_memmove_long_emit_remainder_encodeBlockAsm12Blarge_big_loop_back: + FMOVQ (R5), F0 + FMOVQ 16(R5), F1 + FMOVQ F0, (R6) + FMOVQ F1, 16(R6) + ADD $0x20, R5, R5 + ADD $0x20, R6, R6 + SUB $0x20, R7, R7 + CMP $0x20, R7 + BHS emit_lit_memmove_long_emit_remainder_encodeBlockAsm12Blarge_big_loop_back + ADD R3, R0, R15 + FMOVQ -32(R15), F0 + ADD R3, R0, R15 + FMOVQ -16(R15), F1 + ADD R3, R1, R15 + FMOVQ F0, -32(R15) + ADD R3, R1, R15 + FMOVQ F1, -16(R15) + MOVD R2, R1 + +emit_literal_done_emit_remainder_encodeBlockAsm12B: + MOVD dst_base+0(FP), R0 + SUB R0, R1, R1 + MOVD R1, ret+56(FP) + RET + +// func encodeBlockAsm10B(dst []byte, src []byte, tmp *[4096]byte) int +// Requires: BMI, SSE2 +TEXT ·encodeBlockAsm10B(SB), $24-64 + MOVD tmp+48(FP), R0 + MOVD dst_base+0(FP), R1 + MOVD $0x00000020, R2 + MOVD R0, R3 + VEOR V0.B16, V0.B16, V0.B16 + +zero_loop_encodeBlockAsm10B: + FMOVQ F0, (R3) + FMOVQ F0, 16(R3) + FMOVQ F0, 32(R3) + FMOVQ F0, 48(R3) + FMOVQ F0, 64(R3) + FMOVQ F0, 80(R3) + FMOVQ F0, 96(R3) + FMOVQ F0, 112(R3) + ADD $0x80, R3, R3 + SUBS $1, R2, R2 + BNE zero_loop_encodeBlockAsm10B + MOVD $0x00000000, R16 + MOVW R16, 20(RSP) + MOVD src_len+32(FP), R2 + SUB $9, R2, R3 + SUB $8, R2, R5 + MOVW R5, 16(RSP) + LSR $0x05, R2, R2 + SUBW R2, R3, R3 + ADD R3, R1, R3 + MOVD R3, 8(RSP) + MOVD $0x00000001, R2 + MOVW R2, 24(RSP) + MOVD src_base+24(FP), R3 + +search_loop_encodeBlockAsm10B: + MOVWU R2, R5 + MOVWU 20(RSP), R16 + SUBW R16, R5, R5 + LSRW $0x05, R5, R5 + ADD R5, R2, R5 + ADD $4, R5, R5 + MOVWU R5, R5 + MOVWU 16(RSP), R16 + CMPW R16, R5 + BHS emit_remainder_encodeBlockAsm10B + MOVD (R3)(R2), R6 + MOVW R5, 28(RSP) + MOVD $0x9e3779b1, R8 + MOVD R6, R9 + MOVD R6, R10 + LSR $0x08, R10, R10 + LSL $0x20, R9, R9 + MUL R8, R9, R9 + LSR $0x36, R9, R9 + LSL $0x20, R10, R10 + MUL R8, R10, R10 + LSR $0x36, R10, R10 + MOVWU (R0)(R9<<2), R5 + MOVWU (R0)(R10<<2), R7 + MOVW R2, (R0)(R9<<2) + ADD $1, R2, R9 + MOVWU R9, R9 + MOVW R9, (R0)(R10<<2) + MOVD R6, R9 + LSR $0x10, R9, R9 + LSL $0x20, R9, R9 + MUL R8, R9, R9 + LSR $0x36, R9, R9 + MOVWU R2, R8 + MOVWU 24(RSP), R16 + SUBW R16, R8, R8 + ADD R8, R3, R15 + MOVWU 1(R15), R10 + MOVD R6, R8 + LSR $0x08, R8, R8 + CMPW R10, R8 + BNE no_repeat_found_encodeBlockAsm10B + ADD $1, R2, R6 + MOVWU R6, R6 + MOVWU 20(RSP), R7 + MOVWU R6, R5 + MOVWU 24(RSP), R16 + SUBSW R16, R5, R5 + BEQ repeat_extend_back_end_encodeBlockAsm10B + +repeat_extend_back_loop_encodeBlockAsm10B: + CMPW R7, R6 + BLS repeat_extend_back_end_encodeBlockAsm10B + ADD R5, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R8 + ADD R6, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R9 + AND $0xff, R9, R16 + AND $0xff, R8, R15 + CMP R16, R15 + BNE repeat_extend_back_end_encodeBlockAsm10B + SUB $1, R6, R6 + MOVWU R6, R6 + SUBSW $1, R5, R5 + BNE repeat_extend_back_loop_encodeBlockAsm10B + +repeat_extend_back_end_encodeBlockAsm10B: + MOVWU R6, R5 + MOVWU 20(RSP), R16 + SUBW R16, R5, R5 + ADD R5, R1, R5 + ADD $3, R5, R5 + MOVD 8(RSP), R16 + CMP R16, R5 + BLO repeat_dst_size_check_encodeBlockAsm10B + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +repeat_dst_size_check_encodeBlockAsm10B: + MOVWU 20(RSP), R5 + CMPW R6, R5 + BEQ emit_literal_done_repeat_emit_encodeBlockAsm10B + MOVWU R6, R8 + MOVW R6, 20(RSP) + ADD R5, R3, R9 + SUBW R5, R8, R8 + SUB $1, R8, R5 + MOVWU R5, R5 + CMPW $0x3c, R5 + BLO one_byte_repeat_emit_encodeBlockAsm10B + CMPW $0x00000100, R5 + BLO two_bytes_repeat_emit_encodeBlockAsm10B + BLO three_bytes_repeat_emit_encodeBlockAsm10B + +three_bytes_repeat_emit_encodeBlockAsm10B: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R5, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_repeat_emit_encodeBlockAsm10B + +two_bytes_repeat_emit_encodeBlockAsm10B: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R5, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R5 + BLO memmove_repeat_emit_encodeBlockAsm10B + JMP memmove_long_repeat_emit_encodeBlockAsm10B + +one_byte_repeat_emit_encodeBlockAsm10B: + LSLW $0x02, R5, R16 + BFI $0, R16, $8, R5 + MOVB R5, (R1) + ADD $0x01, R1, R1 + +memmove_repeat_emit_encodeBlockAsm10B: + ADD R8, R1, R5 + + // genMemMoveShort + CMP $0x08, R8 + BLS emit_lit_memmove_repeat_emit_encodeBlockAsm10B_memmove_move_8 + CMP $0x10, R8 + BLS emit_lit_memmove_repeat_emit_encodeBlockAsm10B_memmove_move_8through16 + CMP $0x20, R8 + BLS emit_lit_memmove_repeat_emit_encodeBlockAsm10B_memmove_move_17through32 + JMP emit_lit_memmove_repeat_emit_encodeBlockAsm10B_memmove_move_33through64 + +emit_lit_memmove_repeat_emit_encodeBlockAsm10B_memmove_move_8: + MOVD (R9), R10 + MOVD R10, (R1) + JMP memmove_end_copy_repeat_emit_encodeBlockAsm10B + +emit_lit_memmove_repeat_emit_encodeBlockAsm10B_memmove_move_8through16: + MOVD (R9), R10 + ADD R8, R9, R15 + MOVD -8(R15), R9 + MOVD R10, (R1) + ADD R8, R1, R15 + MOVD R9, -8(R15) + JMP memmove_end_copy_repeat_emit_encodeBlockAsm10B + +emit_lit_memmove_repeat_emit_encodeBlockAsm10B_memmove_move_17through32: + FMOVQ (R9), F0 + ADD R8, R9, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_repeat_emit_encodeBlockAsm10B + +emit_lit_memmove_repeat_emit_encodeBlockAsm10B_memmove_move_33through64: + FMOVQ (R9), F0 + FMOVQ 16(R9), F1 + ADD R8, R9, R15 + FMOVQ -32(R15), F2 + ADD R8, R9, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R8, R1, R15 + FMOVQ F2, -32(R15) + ADD R8, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_repeat_emit_encodeBlockAsm10B: + MOVD R5, R1 + JMP emit_literal_done_repeat_emit_encodeBlockAsm10B + +memmove_long_repeat_emit_encodeBlockAsm10B: + ADD R8, R1, R5 + + // genMemMoveLong + MOVD R9, R10 + MOVD R1, R11 + MOVD R8, R12 + +emit_lit_memmove_long_repeat_emit_encodeBlockAsm10Blarge_big_loop_back: + FMOVQ (R10), F0 + FMOVQ 16(R10), F1 + FMOVQ F0, (R11) + FMOVQ F1, 16(R11) + ADD $0x20, R10, R10 + ADD $0x20, R11, R11 + SUB $0x20, R12, R12 + CMP $0x20, R12 + BHS emit_lit_memmove_long_repeat_emit_encodeBlockAsm10Blarge_big_loop_back + ADD R8, R9, R15 + FMOVQ -32(R15), F0 + ADD R8, R9, R15 + FMOVQ -16(R15), F1 + ADD R8, R1, R15 + FMOVQ F0, -32(R15) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + MOVD R5, R1 + +emit_literal_done_repeat_emit_encodeBlockAsm10B: + ADDW $0x05, R2, R2 + MOVWU R2, R5 + MOVWU 24(RSP), R16 + SUBW R16, R5, R5 + MOVD src_len+32(FP), R8 + SUBW R2, R8, R8 + ADD R2, R3, R9 + ADD R5, R3, R5 + + // matchLen + MOVD $0, R11 + +matchlen_loopback_16_repeat_extend_encodeBlockAsm10B: + CMPW $0x10, R8 + BLO matchlen_match8_repeat_extend_encodeBlockAsm10B + MOVD (R9)(R11), R10 + ADD R11, R9, R15 + MOVD 8(R15), R12 + MOVD (R5)(R11), R16 + EOR R16, R10, R10 + TST R10, R10 + BNE matchlen_bsf_8_repeat_extend_encodeBlockAsm10B + ADD R11, R5, R15 + MOVD 8(R15), R16 + EOR R16, R12, R12 + TST R12, R12 + BNE matchlen_bsf_16repeat_extend_encodeBlockAsm10B + SUB $16, R8, R8 + MOVWU R8, R8 + ADD $16, R11, R11 + MOVWU R11, R11 + JMP matchlen_loopback_16_repeat_extend_encodeBlockAsm10B + +matchlen_bsf_16repeat_extend_encodeBlockAsm10B: + RBIT R12, R12 + CLZ R12, R12 + ASR $0x03, R12, R12 + ADD R12, R11, R11 + ADD $8, R11, R11 + MOVWU R11, R11 + JMP repeat_extend_forward_end_encodeBlockAsm10B + +matchlen_match8_repeat_extend_encodeBlockAsm10B: + CMPW $0x08, R8 + BLO matchlen_match4_repeat_extend_encodeBlockAsm10B + MOVD (R9)(R11), R10 + MOVD (R5)(R11), R16 + EOR R16, R10, R10 + TST R10, R10 + BNE matchlen_bsf_8_repeat_extend_encodeBlockAsm10B + SUB $8, R8, R8 + MOVWU R8, R8 + ADD $8, R11, R11 + MOVWU R11, R11 + JMP matchlen_match4_repeat_extend_encodeBlockAsm10B + +matchlen_bsf_8_repeat_extend_encodeBlockAsm10B: + RBIT R10, R10 + CLZ R10, R10 + ASR $0x03, R10, R10 + ADD R10, R11, R11 + MOVWU R11, R11 + JMP repeat_extend_forward_end_encodeBlockAsm10B + +matchlen_match4_repeat_extend_encodeBlockAsm10B: + CMPW $0x04, R8 + BLO matchlen_match2_repeat_extend_encodeBlockAsm10B + MOVWU (R9)(R11), R10 + MOVWU (R5)(R11), R16 + CMPW R10, R16 + BNE matchlen_match2_repeat_extend_encodeBlockAsm10B + SUB $4, R8, R8 + MOVWU R8, R8 + ADD $4, R11, R11 + MOVWU R11, R11 + +matchlen_match2_repeat_extend_encodeBlockAsm10B: + CMPW $0x01, R8 + BEQ matchlen_match1_repeat_extend_encodeBlockAsm10B + BLO repeat_extend_forward_end_encodeBlockAsm10B + MOVHU (R9)(R11), R16 + BFI $0, R16, $16, R10 + ADD R11, R5, R15 + MOVHU (R15), R15 + AND $0xffff, R10, R16 + CMP R16, R15 + BNE matchlen_match1_repeat_extend_encodeBlockAsm10B + ADD $2, R11, R11 + MOVWU R11, R11 + SUBSW $0x02, R8, R8 + BEQ repeat_extend_forward_end_encodeBlockAsm10B + +matchlen_match1_repeat_extend_encodeBlockAsm10B: + MOVBU (R9)(R11), R16 + BFI $0, R16, $8, R10 + ADD R11, R5, R15 + MOVBU (R15), R15 + AND $0xff, R10, R16 + CMP R16, R15 + BNE repeat_extend_forward_end_encodeBlockAsm10B + ADD $1, R11, R11 + MOVWU R11, R11 + +repeat_extend_forward_end_encodeBlockAsm10B: + ADDW R11, R2, R2 + MOVWU R2, R5 + SUBW R6, R5, R5 + MOVWU 24(RSP), R6 + TSTW R7, R7 + BEQ repeat_as_copy_encodeBlockAsm10B + + // emitRepeat + MOVWU R5, R7 + SUB $4, R5, R5 + MOVWU R5, R5 + CMPW $0x08, R7 + BLS repeat_two_match_repeat_encodeBlockAsm10B + CMPW $0x0c, R7 + BHS cant_repeat_two_offset_match_repeat_encodeBlockAsm10B + CMPW $0x00000800, R6 + BLO repeat_two_offset_match_repeat_encodeBlockAsm10B + +cant_repeat_two_offset_match_repeat_encodeBlockAsm10B: + CMPW $0x00000104, R5 + BLO repeat_three_match_repeat_encodeBlockAsm10B + SUB $256, R5, R5 + MOVWU R5, R5 + MOVD $0x0019, R16 + MOVH R16, (R1) + MOVH R5, 2(R1) + ADD $0x04, R1, R1 + JMP repeat_end_emit_encodeBlockAsm10B + +repeat_three_match_repeat_encodeBlockAsm10B: + SUB $4, R5, R5 + MOVWU R5, R5 + MOVD $0x0015, R16 + MOVH R16, (R1) + MOVB R5, 2(R1) + ADD $0x03, R1, R1 + JMP repeat_end_emit_encodeBlockAsm10B + +repeat_two_match_repeat_encodeBlockAsm10B: + LSLW $0x02, R5, R5 + ORRW $0x01, R5, R5 + MOVH R5, (R1) + ADD $0x02, R1, R1 + JMP repeat_end_emit_encodeBlockAsm10B + +repeat_two_offset_match_repeat_encodeBlockAsm10B: + MOVD $0, R7 + ADD R5<<2, R7, R5 + ADD $1, R5, R5 + MOVWU R5, R5 + MOVB R6, 1(R1) + ASRW $0x08, R6, R6 + LSLW $0x05, R6, R6 + ORRW R6, R5, R5 + MOVB R5, (R1) + ADD $0x02, R1, R1 + JMP repeat_end_emit_encodeBlockAsm10B + +repeat_as_copy_encodeBlockAsm10B: + // emitCopy + CMPW $0x40, R5 + BLS two_byte_offset_short_repeat_as_copy_encodeBlockAsm10B + CMPW $0x00000800, R6 + BHS long_offset_short_repeat_as_copy_encodeBlockAsm10B + MOVD $0x00000001, R7 + ADD $16, R7, R7 + MOVWU R7, R7 + MOVB R6, 1(R1) + LSRW $0x08, R6, R6 + LSLW $0x05, R6, R6 + ORRW R6, R7, R7 + MOVB R7, (R1) + ADD $0x02, R1, R1 + SUBW $0x08, R5, R5 + + // emitRepeat + SUB $4, R5, R5 + MOVWU R5, R5 + JMP cant_repeat_two_offset_repeat_as_copy_encodeBlockAsm10B_emit_copy_short_2b + MOVWU R5, R7 + SUB $4, R5, R5 + MOVWU R5, R5 + CMPW $0x08, R7 + BLS repeat_two_repeat_as_copy_encodeBlockAsm10B_emit_copy_short_2b + CMPW $0x0c, R7 + BHS cant_repeat_two_offset_repeat_as_copy_encodeBlockAsm10B_emit_copy_short_2b + CMPW $0x00000800, R6 + BLO repeat_two_offset_repeat_as_copy_encodeBlockAsm10B_emit_copy_short_2b + +cant_repeat_two_offset_repeat_as_copy_encodeBlockAsm10B_emit_copy_short_2b: + CMPW $0x00000104, R5 + BLO repeat_three_repeat_as_copy_encodeBlockAsm10B_emit_copy_short_2b + SUB $256, R5, R5 + MOVWU R5, R5 + MOVD $0x0019, R16 + MOVH R16, (R1) + MOVH R5, 2(R1) + ADD $0x04, R1, R1 + JMP repeat_end_emit_encodeBlockAsm10B + +repeat_three_repeat_as_copy_encodeBlockAsm10B_emit_copy_short_2b: + SUB $4, R5, R5 + MOVWU R5, R5 + MOVD $0x0015, R16 + MOVH R16, (R1) + MOVB R5, 2(R1) + ADD $0x03, R1, R1 + JMP repeat_end_emit_encodeBlockAsm10B + +repeat_two_repeat_as_copy_encodeBlockAsm10B_emit_copy_short_2b: + LSLW $0x02, R5, R5 + ORRW $0x01, R5, R5 + MOVH R5, (R1) + ADD $0x02, R1, R1 + JMP repeat_end_emit_encodeBlockAsm10B + +repeat_two_offset_repeat_as_copy_encodeBlockAsm10B_emit_copy_short_2b: + MOVD $0, R7 + ADD R5<<2, R7, R5 + ADD $1, R5, R5 + MOVWU R5, R5 + MOVB R6, 1(R1) + ASRW $0x08, R6, R6 + LSLW $0x05, R6, R6 + ORRW R6, R5, R5 + MOVB R5, (R1) + ADD $0x02, R1, R1 + JMP repeat_end_emit_encodeBlockAsm10B + +long_offset_short_repeat_as_copy_encodeBlockAsm10B: + MOVD $0xee, R16 + MOVB R16, (R1) + MOVH R6, 1(R1) + SUB $60, R5, R5 + MOVWU R5, R5 + ADD $0x03, R1, R1 + + // emitRepeat + MOVWU R5, R7 + SUB $4, R5, R5 + MOVWU R5, R5 + CMPW $0x08, R7 + BLS repeat_two_repeat_as_copy_encodeBlockAsm10B_emit_copy_short + CMPW $0x0c, R7 + BHS cant_repeat_two_offset_repeat_as_copy_encodeBlockAsm10B_emit_copy_short + CMPW $0x00000800, R6 + BLO repeat_two_offset_repeat_as_copy_encodeBlockAsm10B_emit_copy_short + +cant_repeat_two_offset_repeat_as_copy_encodeBlockAsm10B_emit_copy_short: + CMPW $0x00000104, R5 + BLO repeat_three_repeat_as_copy_encodeBlockAsm10B_emit_copy_short + SUB $256, R5, R5 + MOVWU R5, R5 + MOVD $0x0019, R16 + MOVH R16, (R1) + MOVH R5, 2(R1) + ADD $0x04, R1, R1 + JMP repeat_end_emit_encodeBlockAsm10B + +repeat_three_repeat_as_copy_encodeBlockAsm10B_emit_copy_short: + SUB $4, R5, R5 + MOVWU R5, R5 + MOVD $0x0015, R16 + MOVH R16, (R1) + MOVB R5, 2(R1) + ADD $0x03, R1, R1 + JMP repeat_end_emit_encodeBlockAsm10B + +repeat_two_repeat_as_copy_encodeBlockAsm10B_emit_copy_short: + LSLW $0x02, R5, R5 + ORRW $0x01, R5, R5 + MOVH R5, (R1) + ADD $0x02, R1, R1 + JMP repeat_end_emit_encodeBlockAsm10B + +repeat_two_offset_repeat_as_copy_encodeBlockAsm10B_emit_copy_short: + MOVD $0, R7 + ADD R5<<2, R7, R5 + ADD $1, R5, R5 + MOVWU R5, R5 + MOVB R6, 1(R1) + ASRW $0x08, R6, R6 + LSLW $0x05, R6, R6 + ORRW R6, R5, R5 + MOVB R5, (R1) + ADD $0x02, R1, R1 + JMP repeat_end_emit_encodeBlockAsm10B + +two_byte_offset_short_repeat_as_copy_encodeBlockAsm10B: + MOVWU R5, R7 + LSLW $0x02, R7, R7 + CMPW $0x0c, R5 + BHS emit_copy_three_repeat_as_copy_encodeBlockAsm10B + CMPW $0x00000800, R6 + BHS emit_copy_three_repeat_as_copy_encodeBlockAsm10B + SUB $15, R7, R7 + MOVWU R7, R7 + MOVB R6, 1(R1) + LSRW $0x08, R6, R6 + LSLW $0x05, R6, R6 + ORRW R6, R7, R7 + MOVB R7, (R1) + ADD $0x02, R1, R1 + JMP repeat_end_emit_encodeBlockAsm10B + +emit_copy_three_repeat_as_copy_encodeBlockAsm10B: + SUB $2, R7, R7 + MOVWU R7, R7 + MOVB R7, (R1) + MOVH R6, 1(R1) + ADD $0x03, R1, R1 + +repeat_end_emit_encodeBlockAsm10B: + MOVW R2, 20(RSP) + JMP search_loop_encodeBlockAsm10B + +no_repeat_found_encodeBlockAsm10B: + MOVWU (R3)(R5), R16 + CMPW R6, R16 + BEQ candidate_match_encodeBlockAsm10B + LSR $0x08, R6, R6 + MOVWU (R0)(R9<<2), R5 + ADD $2, R2, R8 + MOVWU R8, R8 + MOVWU (R3)(R7), R16 + CMPW R6, R16 + BEQ candidate2_match_encodeBlockAsm10B + MOVW R8, (R0)(R9<<2) + LSR $0x08, R6, R6 + MOVWU (R3)(R5), R16 + CMPW R6, R16 + BEQ candidate3_match_encodeBlockAsm10B + MOVWU 28(RSP), R2 + JMP search_loop_encodeBlockAsm10B + +candidate3_match_encodeBlockAsm10B: + ADDW $0x02, R2, R2 + JMP candidate_match_encodeBlockAsm10B + +candidate2_match_encodeBlockAsm10B: + MOVW R8, (R0)(R9<<2) + ADDW $1, R2, R2 + MOVWU R7, R5 + +candidate_match_encodeBlockAsm10B: + MOVWU 20(RSP), R6 + TSTW R5, R5 + BEQ match_extend_back_end_encodeBlockAsm10B + +match_extend_back_loop_encodeBlockAsm10B: + CMPW R6, R2 + BLS match_extend_back_end_encodeBlockAsm10B + ADD R5, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R7 + ADD R2, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R8 + AND $0xff, R8, R16 + AND $0xff, R7, R15 + CMP R16, R15 + BNE match_extend_back_end_encodeBlockAsm10B + SUB $1, R2, R2 + MOVWU R2, R2 + SUBSW $1, R5, R5 + BEQ match_extend_back_end_encodeBlockAsm10B + JMP match_extend_back_loop_encodeBlockAsm10B + +match_extend_back_end_encodeBlockAsm10B: + MOVWU R2, R6 + MOVWU 20(RSP), R16 + SUBW R16, R6, R6 + ADD R6, R1, R6 + ADD $3, R6, R6 + MOVD 8(RSP), R16 + CMP R16, R6 + BLO match_dst_size_check_encodeBlockAsm10B + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +match_dst_size_check_encodeBlockAsm10B: + MOVWU R2, R6 + MOVWU 20(RSP), R7 + CMPW R6, R7 + BEQ emit_literal_done_match_emit_encodeBlockAsm10B + MOVWU R6, R8 + MOVW R6, 20(RSP) + ADD R7, R3, R6 + SUBW R7, R8, R8 + SUB $1, R8, R7 + MOVWU R7, R7 + CMPW $0x3c, R7 + BLO one_byte_match_emit_encodeBlockAsm10B + CMPW $0x00000100, R7 + BLO two_bytes_match_emit_encodeBlockAsm10B + BLO three_bytes_match_emit_encodeBlockAsm10B + +three_bytes_match_emit_encodeBlockAsm10B: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R7, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_match_emit_encodeBlockAsm10B + +two_bytes_match_emit_encodeBlockAsm10B: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R7, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R7 + BLO memmove_match_emit_encodeBlockAsm10B + JMP memmove_long_match_emit_encodeBlockAsm10B + +one_byte_match_emit_encodeBlockAsm10B: + LSLW $0x02, R7, R16 + BFI $0, R16, $8, R7 + MOVB R7, (R1) + ADD $0x01, R1, R1 + +memmove_match_emit_encodeBlockAsm10B: + ADD R8, R1, R7 + + // genMemMoveShort + CMP $0x08, R8 + BLS emit_lit_memmove_match_emit_encodeBlockAsm10B_memmove_move_8 + CMP $0x10, R8 + BLS emit_lit_memmove_match_emit_encodeBlockAsm10B_memmove_move_8through16 + CMP $0x20, R8 + BLS emit_lit_memmove_match_emit_encodeBlockAsm10B_memmove_move_17through32 + JMP emit_lit_memmove_match_emit_encodeBlockAsm10B_memmove_move_33through64 + +emit_lit_memmove_match_emit_encodeBlockAsm10B_memmove_move_8: + MOVD (R6), R9 + MOVD R9, (R1) + JMP memmove_end_copy_match_emit_encodeBlockAsm10B + +emit_lit_memmove_match_emit_encodeBlockAsm10B_memmove_move_8through16: + MOVD (R6), R9 + ADD R8, R6, R15 + MOVD -8(R15), R6 + MOVD R9, (R1) + ADD R8, R1, R15 + MOVD R6, -8(R15) + JMP memmove_end_copy_match_emit_encodeBlockAsm10B + +emit_lit_memmove_match_emit_encodeBlockAsm10B_memmove_move_17through32: + FMOVQ (R6), F0 + ADD R8, R6, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_match_emit_encodeBlockAsm10B + +emit_lit_memmove_match_emit_encodeBlockAsm10B_memmove_move_33through64: + FMOVQ (R6), F0 + FMOVQ 16(R6), F1 + ADD R8, R6, R15 + FMOVQ -32(R15), F2 + ADD R8, R6, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R8, R1, R15 + FMOVQ F2, -32(R15) + ADD R8, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_match_emit_encodeBlockAsm10B: + MOVD R7, R1 + JMP emit_literal_done_match_emit_encodeBlockAsm10B + +memmove_long_match_emit_encodeBlockAsm10B: + ADD R8, R1, R7 + + // genMemMoveLong + MOVD R6, R9 + MOVD R1, R10 + MOVD R8, R11 + +emit_lit_memmove_long_match_emit_encodeBlockAsm10Blarge_big_loop_back: + FMOVQ (R9), F0 + FMOVQ 16(R9), F1 + FMOVQ F0, (R10) + FMOVQ F1, 16(R10) + ADD $0x20, R9, R9 + ADD $0x20, R10, R10 + SUB $0x20, R11, R11 + CMP $0x20, R11 + BHS emit_lit_memmove_long_match_emit_encodeBlockAsm10Blarge_big_loop_back + ADD R8, R6, R15 + FMOVQ -32(R15), F0 + ADD R8, R6, R15 + FMOVQ -16(R15), F1 + ADD R8, R1, R15 + FMOVQ F0, -32(R15) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + MOVD R7, R1 + +emit_literal_done_match_emit_encodeBlockAsm10B: +match_nolit_loop_encodeBlockAsm10B: + MOVWU R2, R6 + SUBW R5, R6, R6 + MOVW R6, 24(RSP) + ADDW $0x04, R2, R2 + ADDW $0x04, R5, R5 + MOVD src_len+32(FP), R6 + SUBW R2, R6, R6 + ADD R2, R3, R7 + ADD R5, R3, R5 + + // matchLen + MOVD $0, R9 + +matchlen_loopback_16_match_nolit_encodeBlockAsm10B: + CMPW $0x10, R6 + BLO matchlen_match8_match_nolit_encodeBlockAsm10B + MOVD (R7)(R9), R8 + ADD R9, R7, R15 + MOVD 8(R15), R10 + MOVD (R5)(R9), R16 + EOR R16, R8, R8 + TST R8, R8 + BNE matchlen_bsf_8_match_nolit_encodeBlockAsm10B + ADD R9, R5, R15 + MOVD 8(R15), R16 + EOR R16, R10, R10 + TST R10, R10 + BNE matchlen_bsf_16match_nolit_encodeBlockAsm10B + SUB $16, R6, R6 + MOVWU R6, R6 + ADD $16, R9, R9 + MOVWU R9, R9 + JMP matchlen_loopback_16_match_nolit_encodeBlockAsm10B + +matchlen_bsf_16match_nolit_encodeBlockAsm10B: + RBIT R10, R10 + CLZ R10, R10 + ASR $0x03, R10, R10 + ADD R10, R9, R9 + ADD $8, R9, R9 + MOVWU R9, R9 + JMP match_nolit_end_encodeBlockAsm10B + +matchlen_match8_match_nolit_encodeBlockAsm10B: + CMPW $0x08, R6 + BLO matchlen_match4_match_nolit_encodeBlockAsm10B + MOVD (R7)(R9), R8 + MOVD (R5)(R9), R16 + EOR R16, R8, R8 + TST R8, R8 + BNE matchlen_bsf_8_match_nolit_encodeBlockAsm10B + SUB $8, R6, R6 + MOVWU R6, R6 + ADD $8, R9, R9 + MOVWU R9, R9 + JMP matchlen_match4_match_nolit_encodeBlockAsm10B + +matchlen_bsf_8_match_nolit_encodeBlockAsm10B: + RBIT R8, R8 + CLZ R8, R8 + ASR $0x03, R8, R8 + ADD R8, R9, R9 + MOVWU R9, R9 + JMP match_nolit_end_encodeBlockAsm10B + +matchlen_match4_match_nolit_encodeBlockAsm10B: + CMPW $0x04, R6 + BLO matchlen_match2_match_nolit_encodeBlockAsm10B + MOVWU (R7)(R9), R8 + MOVWU (R5)(R9), R16 + CMPW R8, R16 + BNE matchlen_match2_match_nolit_encodeBlockAsm10B + SUB $4, R6, R6 + MOVWU R6, R6 + ADD $4, R9, R9 + MOVWU R9, R9 + +matchlen_match2_match_nolit_encodeBlockAsm10B: + CMPW $0x01, R6 + BEQ matchlen_match1_match_nolit_encodeBlockAsm10B + BLO match_nolit_end_encodeBlockAsm10B + MOVHU (R7)(R9), R16 + BFI $0, R16, $16, R8 + ADD R9, R5, R15 + MOVHU (R15), R15 + AND $0xffff, R8, R16 + CMP R16, R15 + BNE matchlen_match1_match_nolit_encodeBlockAsm10B + ADD $2, R9, R9 + MOVWU R9, R9 + SUBSW $0x02, R6, R6 + BEQ match_nolit_end_encodeBlockAsm10B + +matchlen_match1_match_nolit_encodeBlockAsm10B: + MOVBU (R7)(R9), R16 + BFI $0, R16, $8, R8 + ADD R9, R5, R15 + MOVBU (R15), R15 + AND $0xff, R8, R16 + CMP R16, R15 + BNE match_nolit_end_encodeBlockAsm10B + ADD $1, R9, R9 + MOVWU R9, R9 + +match_nolit_end_encodeBlockAsm10B: + ADDW R9, R2, R2 + MOVWU 24(RSP), R5 + ADDW $0x04, R9, R9 + MOVW R2, 20(RSP) + + // emitCopy + CMPW $0x40, R9 + BLS two_byte_offset_short_match_nolit_encodeBlockAsm10B + CMPW $0x00000800, R5 + BHS long_offset_short_match_nolit_encodeBlockAsm10B + MOVD $0x00000001, R6 + ADD $16, R6, R6 + MOVWU R6, R6 + MOVB R5, 1(R1) + LSRW $0x08, R5, R5 + LSLW $0x05, R5, R5 + ORRW R5, R6, R6 + MOVB R6, (R1) + ADD $0x02, R1, R1 + SUBW $0x08, R9, R9 + + // emitRepeat + SUB $4, R9, R9 + MOVWU R9, R9 + JMP cant_repeat_two_offset_match_nolit_encodeBlockAsm10B_emit_copy_short_2b + MOVWU R9, R6 + SUB $4, R9, R9 + MOVWU R9, R9 + CMPW $0x08, R6 + BLS repeat_two_match_nolit_encodeBlockAsm10B_emit_copy_short_2b + CMPW $0x0c, R6 + BHS cant_repeat_two_offset_match_nolit_encodeBlockAsm10B_emit_copy_short_2b + CMPW $0x00000800, R5 + BLO repeat_two_offset_match_nolit_encodeBlockAsm10B_emit_copy_short_2b + +cant_repeat_two_offset_match_nolit_encodeBlockAsm10B_emit_copy_short_2b: + CMPW $0x00000104, R9 + BLO repeat_three_match_nolit_encodeBlockAsm10B_emit_copy_short_2b + SUB $256, R9, R9 + MOVWU R9, R9 + MOVD $0x0019, R16 + MOVH R16, (R1) + MOVH R9, 2(R1) + ADD $0x04, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm10B + +repeat_three_match_nolit_encodeBlockAsm10B_emit_copy_short_2b: + SUB $4, R9, R9 + MOVWU R9, R9 + MOVD $0x0015, R16 + MOVH R16, (R1) + MOVB R9, 2(R1) + ADD $0x03, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm10B + +repeat_two_match_nolit_encodeBlockAsm10B_emit_copy_short_2b: + LSLW $0x02, R9, R9 + ORRW $0x01, R9, R9 + MOVH R9, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm10B + +repeat_two_offset_match_nolit_encodeBlockAsm10B_emit_copy_short_2b: + MOVD $0, R6 + ADD R9<<2, R6, R9 + ADD $1, R9, R9 + MOVWU R9, R9 + MOVB R5, 1(R1) + ASRW $0x08, R5, R5 + LSLW $0x05, R5, R5 + ORRW R5, R9, R9 + MOVB R9, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm10B + +long_offset_short_match_nolit_encodeBlockAsm10B: + MOVD $0xee, R16 + MOVB R16, (R1) + MOVH R5, 1(R1) + SUB $60, R9, R9 + MOVWU R9, R9 + ADD $0x03, R1, R1 + + // emitRepeat + MOVWU R9, R6 + SUB $4, R9, R9 + MOVWU R9, R9 + CMPW $0x08, R6 + BLS repeat_two_match_nolit_encodeBlockAsm10B_emit_copy_short + CMPW $0x0c, R6 + BHS cant_repeat_two_offset_match_nolit_encodeBlockAsm10B_emit_copy_short + CMPW $0x00000800, R5 + BLO repeat_two_offset_match_nolit_encodeBlockAsm10B_emit_copy_short + +cant_repeat_two_offset_match_nolit_encodeBlockAsm10B_emit_copy_short: + CMPW $0x00000104, R9 + BLO repeat_three_match_nolit_encodeBlockAsm10B_emit_copy_short + SUB $256, R9, R9 + MOVWU R9, R9 + MOVD $0x0019, R16 + MOVH R16, (R1) + MOVH R9, 2(R1) + ADD $0x04, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm10B + +repeat_three_match_nolit_encodeBlockAsm10B_emit_copy_short: + SUB $4, R9, R9 + MOVWU R9, R9 + MOVD $0x0015, R16 + MOVH R16, (R1) + MOVB R9, 2(R1) + ADD $0x03, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm10B + +repeat_two_match_nolit_encodeBlockAsm10B_emit_copy_short: + LSLW $0x02, R9, R9 + ORRW $0x01, R9, R9 + MOVH R9, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm10B + +repeat_two_offset_match_nolit_encodeBlockAsm10B_emit_copy_short: + MOVD $0, R6 + ADD R9<<2, R6, R9 + ADD $1, R9, R9 + MOVWU R9, R9 + MOVB R5, 1(R1) + ASRW $0x08, R5, R5 + LSLW $0x05, R5, R5 + ORRW R5, R9, R9 + MOVB R9, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm10B + +two_byte_offset_short_match_nolit_encodeBlockAsm10B: + MOVWU R9, R6 + LSLW $0x02, R6, R6 + CMPW $0x0c, R9 + BHS emit_copy_three_match_nolit_encodeBlockAsm10B + CMPW $0x00000800, R5 + BHS emit_copy_three_match_nolit_encodeBlockAsm10B + SUB $15, R6, R6 + MOVWU R6, R6 + MOVB R5, 1(R1) + LSRW $0x08, R5, R5 + LSLW $0x05, R5, R5 + ORRW R5, R6, R6 + MOVB R6, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm10B + +emit_copy_three_match_nolit_encodeBlockAsm10B: + SUB $2, R6, R6 + MOVWU R6, R6 + MOVB R6, (R1) + MOVH R5, 1(R1) + ADD $0x03, R1, R1 + +match_nolit_emitcopy_end_encodeBlockAsm10B: + MOVWU 16(RSP), R16 + CMPW R16, R2 + BHS emit_remainder_encodeBlockAsm10B + ADD R2, R3, R15 + MOVD -2(R15), R6 + MOVD 8(RSP), R16 + CMP R16, R1 + BLO match_nolit_dst_ok_encodeBlockAsm10B + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +match_nolit_dst_ok_encodeBlockAsm10B: + MOVD $0x9e3779b1, R8 + MOVD R6, R7 + LSR $0x10, R6, R6 + MOVD R6, R5 + LSL $0x20, R7, R7 + MUL R8, R7, R7 + LSR $0x36, R7, R7 + LSL $0x20, R5, R5 + MUL R8, R5, R5 + LSR $0x36, R5, R5 + SUB $2, R2, R8 + MOVWU R8, R8 + ADD R5<<2, R0, R9 + MOVWU (R9), R5 + MOVW R8, (R0)(R7<<2) + MOVW R2, (R9) + MOVWU (R3)(R5), R16 + CMPW R6, R16 + BEQ match_nolit_loop_encodeBlockAsm10B + ADDW $1, R2, R2 + JMP search_loop_encodeBlockAsm10B + +emit_remainder_encodeBlockAsm10B: + MOVD src_len+32(FP), R0 + MOVWU 20(RSP), R16 + SUBW R16, R0, R0 + ADD R0, R1, R0 + ADD $3, R0, R0 + MOVD 8(RSP), R16 + CMP R16, R0 + BLO emit_remainder_ok_encodeBlockAsm10B + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +emit_remainder_ok_encodeBlockAsm10B: + MOVD src_len+32(FP), R0 + MOVWU 20(RSP), R2 + CMPW R0, R2 + BEQ emit_literal_done_emit_remainder_encodeBlockAsm10B + MOVWU R0, R5 + MOVW R0, 20(RSP) + ADD R2, R3, R0 + SUBW R2, R5, R5 + SUB $1, R5, R2 + MOVWU R2, R2 + CMPW $0x3c, R2 + BLO one_byte_emit_remainder_encodeBlockAsm10B + CMPW $0x00000100, R2 + BLO two_bytes_emit_remainder_encodeBlockAsm10B + BLO three_bytes_emit_remainder_encodeBlockAsm10B + +three_bytes_emit_remainder_encodeBlockAsm10B: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R2, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_emit_remainder_encodeBlockAsm10B + +two_bytes_emit_remainder_encodeBlockAsm10B: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R2, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R2 + BLO memmove_emit_remainder_encodeBlockAsm10B + JMP memmove_long_emit_remainder_encodeBlockAsm10B + +one_byte_emit_remainder_encodeBlockAsm10B: + LSLW $0x02, R2, R16 + BFI $0, R16, $8, R2 + MOVB R2, (R1) + ADD $0x01, R1, R1 + +memmove_emit_remainder_encodeBlockAsm10B: + ADD R5, R1, R2 + MOVWU R5, R3 + + // genMemMoveShort + CMP $0x03, R3 + BLO emit_lit_memmove_emit_remainder_encodeBlockAsm10B_memmove_move_1or2 + BEQ emit_lit_memmove_emit_remainder_encodeBlockAsm10B_memmove_move_3 + CMP $0x08, R3 + BLO emit_lit_memmove_emit_remainder_encodeBlockAsm10B_memmove_move_4through7 + CMP $0x10, R3 + BLS emit_lit_memmove_emit_remainder_encodeBlockAsm10B_memmove_move_8through16 + CMP $0x20, R3 + BLS emit_lit_memmove_emit_remainder_encodeBlockAsm10B_memmove_move_17through32 + JMP emit_lit_memmove_emit_remainder_encodeBlockAsm10B_memmove_move_33through64 + +emit_lit_memmove_emit_remainder_encodeBlockAsm10B_memmove_move_1or2: + MOVBU (R0), R16 + BFI $0, R16, $8, R5 + ADD R3, R0, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R0 + MOVB R5, (R1) + ADD R3, R1, R15 + MOVB R0, -1(R15) + JMP memmove_end_copy_emit_remainder_encodeBlockAsm10B + +emit_lit_memmove_emit_remainder_encodeBlockAsm10B_memmove_move_3: + MOVHU (R0), R16 + BFI $0, R16, $16, R5 + MOVBU 2(R0), R16 + BFI $0, R16, $8, R0 + MOVH R5, (R1) + MOVB R0, 2(R1) + JMP memmove_end_copy_emit_remainder_encodeBlockAsm10B + +emit_lit_memmove_emit_remainder_encodeBlockAsm10B_memmove_move_4through7: + MOVWU (R0), R5 + ADD R3, R0, R15 + MOVWU -4(R15), R0 + MOVW R5, (R1) + ADD R3, R1, R15 + MOVW R0, -4(R15) + JMP memmove_end_copy_emit_remainder_encodeBlockAsm10B + +emit_lit_memmove_emit_remainder_encodeBlockAsm10B_memmove_move_8through16: + MOVD (R0), R5 + ADD R3, R0, R15 + MOVD -8(R15), R0 + MOVD R5, (R1) + ADD R3, R1, R15 + MOVD R0, -8(R15) + JMP memmove_end_copy_emit_remainder_encodeBlockAsm10B + +emit_lit_memmove_emit_remainder_encodeBlockAsm10B_memmove_move_17through32: + FMOVQ (R0), F0 + ADD R3, R0, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R3, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_emit_remainder_encodeBlockAsm10B + +emit_lit_memmove_emit_remainder_encodeBlockAsm10B_memmove_move_33through64: + FMOVQ (R0), F0 + FMOVQ 16(R0), F1 + ADD R3, R0, R15 + FMOVQ -32(R15), F2 + ADD R3, R0, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R3, R1, R15 + FMOVQ F2, -32(R15) + ADD R3, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_emit_remainder_encodeBlockAsm10B: + MOVD R2, R1 + JMP emit_literal_done_emit_remainder_encodeBlockAsm10B + +memmove_long_emit_remainder_encodeBlockAsm10B: + ADD R5, R1, R2 + MOVWU R5, R3 + + // genMemMoveLong + MOVD R0, R5 + MOVD R1, R6 + MOVD R3, R7 + +emit_lit_memmove_long_emit_remainder_encodeBlockAsm10Blarge_big_loop_back: + FMOVQ (R5), F0 + FMOVQ 16(R5), F1 + FMOVQ F0, (R6) + FMOVQ F1, 16(R6) + ADD $0x20, R5, R5 + ADD $0x20, R6, R6 + SUB $0x20, R7, R7 + CMP $0x20, R7 + BHS emit_lit_memmove_long_emit_remainder_encodeBlockAsm10Blarge_big_loop_back + ADD R3, R0, R15 + FMOVQ -32(R15), F0 + ADD R3, R0, R15 + FMOVQ -16(R15), F1 + ADD R3, R1, R15 + FMOVQ F0, -32(R15) + ADD R3, R1, R15 + FMOVQ F1, -16(R15) + MOVD R2, R1 + +emit_literal_done_emit_remainder_encodeBlockAsm10B: + MOVD dst_base+0(FP), R0 + SUB R0, R1, R1 + MOVD R1, ret+56(FP) + RET + +// func encodeBlockAsm8B(dst []byte, src []byte, tmp *[1024]byte) int +// Requires: BMI, SSE2 +TEXT ·encodeBlockAsm8B(SB), $24-64 + MOVD tmp+48(FP), R0 + MOVD dst_base+0(FP), R1 + MOVD $0x00000008, R2 + MOVD R0, R3 + VEOR V0.B16, V0.B16, V0.B16 + +zero_loop_encodeBlockAsm8B: + FMOVQ F0, (R3) + FMOVQ F0, 16(R3) + FMOVQ F0, 32(R3) + FMOVQ F0, 48(R3) + FMOVQ F0, 64(R3) + FMOVQ F0, 80(R3) + FMOVQ F0, 96(R3) + FMOVQ F0, 112(R3) + ADD $0x80, R3, R3 + SUBS $1, R2, R2 + BNE zero_loop_encodeBlockAsm8B + MOVD $0x00000000, R16 + MOVW R16, 20(RSP) + MOVD src_len+32(FP), R2 + SUB $9, R2, R3 + SUB $8, R2, R5 + MOVW R5, 16(RSP) + LSR $0x05, R2, R2 + SUBW R2, R3, R3 + ADD R3, R1, R3 + MOVD R3, 8(RSP) + MOVD $0x00000001, R2 + MOVW R2, 24(RSP) + MOVD src_base+24(FP), R3 + +search_loop_encodeBlockAsm8B: + MOVWU R2, R5 + MOVWU 20(RSP), R16 + SUBW R16, R5, R5 + LSRW $0x04, R5, R5 + ADD R5, R2, R5 + ADD $4, R5, R5 + MOVWU R5, R5 + MOVWU 16(RSP), R16 + CMPW R16, R5 + BHS emit_remainder_encodeBlockAsm8B + MOVD (R3)(R2), R6 + MOVW R5, 28(RSP) + MOVD $0x9e3779b1, R8 + MOVD R6, R9 + MOVD R6, R10 + LSR $0x08, R10, R10 + LSL $0x20, R9, R9 + MUL R8, R9, R9 + LSR $0x38, R9, R9 + LSL $0x20, R10, R10 + MUL R8, R10, R10 + LSR $0x38, R10, R10 + MOVWU (R0)(R9<<2), R5 + MOVWU (R0)(R10<<2), R7 + MOVW R2, (R0)(R9<<2) + ADD $1, R2, R9 + MOVWU R9, R9 + MOVW R9, (R0)(R10<<2) + MOVD R6, R9 + LSR $0x10, R9, R9 + LSL $0x20, R9, R9 + MUL R8, R9, R9 + LSR $0x38, R9, R9 + MOVWU R2, R8 + MOVWU 24(RSP), R16 + SUBW R16, R8, R8 + ADD R8, R3, R15 + MOVWU 1(R15), R10 + MOVD R6, R8 + LSR $0x08, R8, R8 + CMPW R10, R8 + BNE no_repeat_found_encodeBlockAsm8B + ADD $1, R2, R6 + MOVWU R6, R6 + MOVWU 20(RSP), R7 + MOVWU R6, R5 + MOVWU 24(RSP), R16 + SUBSW R16, R5, R5 + BEQ repeat_extend_back_end_encodeBlockAsm8B + +repeat_extend_back_loop_encodeBlockAsm8B: + CMPW R7, R6 + BLS repeat_extend_back_end_encodeBlockAsm8B + ADD R5, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R8 + ADD R6, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R9 + AND $0xff, R9, R16 + AND $0xff, R8, R15 + CMP R16, R15 + BNE repeat_extend_back_end_encodeBlockAsm8B + SUB $1, R6, R6 + MOVWU R6, R6 + SUBSW $1, R5, R5 + BNE repeat_extend_back_loop_encodeBlockAsm8B + +repeat_extend_back_end_encodeBlockAsm8B: + MOVWU R6, R5 + MOVWU 20(RSP), R16 + SUBW R16, R5, R5 + ADD R5, R1, R5 + ADD $3, R5, R5 + MOVD 8(RSP), R16 + CMP R16, R5 + BLO repeat_dst_size_check_encodeBlockAsm8B + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +repeat_dst_size_check_encodeBlockAsm8B: + MOVWU 20(RSP), R5 + CMPW R6, R5 + BEQ emit_literal_done_repeat_emit_encodeBlockAsm8B + MOVWU R6, R8 + MOVW R6, 20(RSP) + ADD R5, R3, R9 + SUBW R5, R8, R8 + SUB $1, R8, R5 + MOVWU R5, R5 + CMPW $0x3c, R5 + BLO one_byte_repeat_emit_encodeBlockAsm8B + CMPW $0x00000100, R5 + BLO two_bytes_repeat_emit_encodeBlockAsm8B + BLO three_bytes_repeat_emit_encodeBlockAsm8B + +three_bytes_repeat_emit_encodeBlockAsm8B: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R5, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_repeat_emit_encodeBlockAsm8B + +two_bytes_repeat_emit_encodeBlockAsm8B: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R5, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R5 + BLO memmove_repeat_emit_encodeBlockAsm8B + JMP memmove_long_repeat_emit_encodeBlockAsm8B + +one_byte_repeat_emit_encodeBlockAsm8B: + LSLW $0x02, R5, R16 + BFI $0, R16, $8, R5 + MOVB R5, (R1) + ADD $0x01, R1, R1 + +memmove_repeat_emit_encodeBlockAsm8B: + ADD R8, R1, R5 + + // genMemMoveShort + CMP $0x08, R8 + BLS emit_lit_memmove_repeat_emit_encodeBlockAsm8B_memmove_move_8 + CMP $0x10, R8 + BLS emit_lit_memmove_repeat_emit_encodeBlockAsm8B_memmove_move_8through16 + CMP $0x20, R8 + BLS emit_lit_memmove_repeat_emit_encodeBlockAsm8B_memmove_move_17through32 + JMP emit_lit_memmove_repeat_emit_encodeBlockAsm8B_memmove_move_33through64 + +emit_lit_memmove_repeat_emit_encodeBlockAsm8B_memmove_move_8: + MOVD (R9), R10 + MOVD R10, (R1) + JMP memmove_end_copy_repeat_emit_encodeBlockAsm8B + +emit_lit_memmove_repeat_emit_encodeBlockAsm8B_memmove_move_8through16: + MOVD (R9), R10 + ADD R8, R9, R15 + MOVD -8(R15), R9 + MOVD R10, (R1) + ADD R8, R1, R15 + MOVD R9, -8(R15) + JMP memmove_end_copy_repeat_emit_encodeBlockAsm8B + +emit_lit_memmove_repeat_emit_encodeBlockAsm8B_memmove_move_17through32: + FMOVQ (R9), F0 + ADD R8, R9, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_repeat_emit_encodeBlockAsm8B + +emit_lit_memmove_repeat_emit_encodeBlockAsm8B_memmove_move_33through64: + FMOVQ (R9), F0 + FMOVQ 16(R9), F1 + ADD R8, R9, R15 + FMOVQ -32(R15), F2 + ADD R8, R9, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R8, R1, R15 + FMOVQ F2, -32(R15) + ADD R8, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_repeat_emit_encodeBlockAsm8B: + MOVD R5, R1 + JMP emit_literal_done_repeat_emit_encodeBlockAsm8B + +memmove_long_repeat_emit_encodeBlockAsm8B: + ADD R8, R1, R5 + + // genMemMoveLong + MOVD R9, R10 + MOVD R1, R11 + MOVD R8, R12 + +emit_lit_memmove_long_repeat_emit_encodeBlockAsm8Blarge_big_loop_back: + FMOVQ (R10), F0 + FMOVQ 16(R10), F1 + FMOVQ F0, (R11) + FMOVQ F1, 16(R11) + ADD $0x20, R10, R10 + ADD $0x20, R11, R11 + SUB $0x20, R12, R12 + CMP $0x20, R12 + BHS emit_lit_memmove_long_repeat_emit_encodeBlockAsm8Blarge_big_loop_back + ADD R8, R9, R15 + FMOVQ -32(R15), F0 + ADD R8, R9, R15 + FMOVQ -16(R15), F1 + ADD R8, R1, R15 + FMOVQ F0, -32(R15) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + MOVD R5, R1 + +emit_literal_done_repeat_emit_encodeBlockAsm8B: + ADDW $0x05, R2, R2 + MOVWU R2, R5 + MOVWU 24(RSP), R16 + SUBW R16, R5, R5 + MOVD src_len+32(FP), R8 + SUBW R2, R8, R8 + ADD R2, R3, R9 + ADD R5, R3, R5 + + // matchLen + MOVD $0, R11 + +matchlen_loopback_16_repeat_extend_encodeBlockAsm8B: + CMPW $0x10, R8 + BLO matchlen_match8_repeat_extend_encodeBlockAsm8B + MOVD (R9)(R11), R10 + ADD R11, R9, R15 + MOVD 8(R15), R12 + MOVD (R5)(R11), R16 + EOR R16, R10, R10 + TST R10, R10 + BNE matchlen_bsf_8_repeat_extend_encodeBlockAsm8B + ADD R11, R5, R15 + MOVD 8(R15), R16 + EOR R16, R12, R12 + TST R12, R12 + BNE matchlen_bsf_16repeat_extend_encodeBlockAsm8B + SUB $16, R8, R8 + MOVWU R8, R8 + ADD $16, R11, R11 + MOVWU R11, R11 + JMP matchlen_loopback_16_repeat_extend_encodeBlockAsm8B + +matchlen_bsf_16repeat_extend_encodeBlockAsm8B: + RBIT R12, R12 + CLZ R12, R12 + ASR $0x03, R12, R12 + ADD R12, R11, R11 + ADD $8, R11, R11 + MOVWU R11, R11 + JMP repeat_extend_forward_end_encodeBlockAsm8B + +matchlen_match8_repeat_extend_encodeBlockAsm8B: + CMPW $0x08, R8 + BLO matchlen_match4_repeat_extend_encodeBlockAsm8B + MOVD (R9)(R11), R10 + MOVD (R5)(R11), R16 + EOR R16, R10, R10 + TST R10, R10 + BNE matchlen_bsf_8_repeat_extend_encodeBlockAsm8B + SUB $8, R8, R8 + MOVWU R8, R8 + ADD $8, R11, R11 + MOVWU R11, R11 + JMP matchlen_match4_repeat_extend_encodeBlockAsm8B + +matchlen_bsf_8_repeat_extend_encodeBlockAsm8B: + RBIT R10, R10 + CLZ R10, R10 + ASR $0x03, R10, R10 + ADD R10, R11, R11 + MOVWU R11, R11 + JMP repeat_extend_forward_end_encodeBlockAsm8B + +matchlen_match4_repeat_extend_encodeBlockAsm8B: + CMPW $0x04, R8 + BLO matchlen_match2_repeat_extend_encodeBlockAsm8B + MOVWU (R9)(R11), R10 + MOVWU (R5)(R11), R16 + CMPW R10, R16 + BNE matchlen_match2_repeat_extend_encodeBlockAsm8B + SUB $4, R8, R8 + MOVWU R8, R8 + ADD $4, R11, R11 + MOVWU R11, R11 + +matchlen_match2_repeat_extend_encodeBlockAsm8B: + CMPW $0x01, R8 + BEQ matchlen_match1_repeat_extend_encodeBlockAsm8B + BLO repeat_extend_forward_end_encodeBlockAsm8B + MOVHU (R9)(R11), R16 + BFI $0, R16, $16, R10 + ADD R11, R5, R15 + MOVHU (R15), R15 + AND $0xffff, R10, R16 + CMP R16, R15 + BNE matchlen_match1_repeat_extend_encodeBlockAsm8B + ADD $2, R11, R11 + MOVWU R11, R11 + SUBSW $0x02, R8, R8 + BEQ repeat_extend_forward_end_encodeBlockAsm8B + +matchlen_match1_repeat_extend_encodeBlockAsm8B: + MOVBU (R9)(R11), R16 + BFI $0, R16, $8, R10 + ADD R11, R5, R15 + MOVBU (R15), R15 + AND $0xff, R10, R16 + CMP R16, R15 + BNE repeat_extend_forward_end_encodeBlockAsm8B + ADD $1, R11, R11 + MOVWU R11, R11 + +repeat_extend_forward_end_encodeBlockAsm8B: + ADDW R11, R2, R2 + MOVWU R2, R5 + SUBW R6, R5, R5 + MOVWU 24(RSP), R6 + TSTW R7, R7 + BEQ repeat_as_copy_encodeBlockAsm8B + + // emitRepeat + MOVWU R5, R6 + SUB $4, R5, R5 + MOVWU R5, R5 + CMPW $0x08, R6 + BLS repeat_two_match_repeat_encodeBlockAsm8B + CMPW $0x0c, R6 + BHS cant_repeat_two_offset_match_repeat_encodeBlockAsm8B + +cant_repeat_two_offset_match_repeat_encodeBlockAsm8B: + CMPW $0x00000104, R5 + BLO repeat_three_match_repeat_encodeBlockAsm8B + SUB $256, R5, R5 + MOVWU R5, R5 + MOVD $0x0019, R16 + MOVH R16, (R1) + MOVH R5, 2(R1) + ADD $0x04, R1, R1 + JMP repeat_end_emit_encodeBlockAsm8B + +repeat_three_match_repeat_encodeBlockAsm8B: + SUB $4, R5, R5 + MOVWU R5, R5 + MOVD $0x0015, R16 + MOVH R16, (R1) + MOVB R5, 2(R1) + ADD $0x03, R1, R1 + JMP repeat_end_emit_encodeBlockAsm8B + +repeat_two_match_repeat_encodeBlockAsm8B: + LSLW $0x02, R5, R5 + ORRW $0x01, R5, R5 + MOVH R5, (R1) + ADD $0x02, R1, R1 + JMP repeat_end_emit_encodeBlockAsm8B + MOVD $0, R7 + ADD R5<<2, R7, R5 + ADD $1, R5, R5 + MOVWU R5, R5 + MOVB R6, 1(R1) + ASRW $0x08, R6, R6 + LSLW $0x05, R6, R6 + ORRW R6, R5, R5 + MOVB R5, (R1) + ADD $0x02, R1, R1 + JMP repeat_end_emit_encodeBlockAsm8B + +repeat_as_copy_encodeBlockAsm8B: + // emitCopy + CMPW $0x40, R5 + BLS two_byte_offset_short_repeat_as_copy_encodeBlockAsm8B + CMPW $0x00000800, R6 + BHS long_offset_short_repeat_as_copy_encodeBlockAsm8B + MOVD $0x00000001, R7 + ADD $16, R7, R7 + MOVWU R7, R7 + MOVB R6, 1(R1) + LSRW $0x08, R6, R6 + LSLW $0x05, R6, R6 + ORRW R6, R7, R7 + MOVB R7, (R1) + ADD $0x02, R1, R1 + SUBW $0x08, R5, R5 + + // emitRepeat + SUB $4, R5, R5 + MOVWU R5, R5 + JMP cant_repeat_two_offset_repeat_as_copy_encodeBlockAsm8B_emit_copy_short_2b + MOVWU R5, R6 + SUB $4, R5, R5 + MOVWU R5, R5 + CMPW $0x08, R6 + BLS repeat_two_repeat_as_copy_encodeBlockAsm8B_emit_copy_short_2b + CMPW $0x0c, R6 + BHS cant_repeat_two_offset_repeat_as_copy_encodeBlockAsm8B_emit_copy_short_2b + +cant_repeat_two_offset_repeat_as_copy_encodeBlockAsm8B_emit_copy_short_2b: + CMPW $0x00000104, R5 + BLO repeat_three_repeat_as_copy_encodeBlockAsm8B_emit_copy_short_2b + SUB $256, R5, R5 + MOVWU R5, R5 + MOVD $0x0019, R16 + MOVH R16, (R1) + MOVH R5, 2(R1) + ADD $0x04, R1, R1 + JMP repeat_end_emit_encodeBlockAsm8B + +repeat_three_repeat_as_copy_encodeBlockAsm8B_emit_copy_short_2b: + SUB $4, R5, R5 + MOVWU R5, R5 + MOVD $0x0015, R16 + MOVH R16, (R1) + MOVB R5, 2(R1) + ADD $0x03, R1, R1 + JMP repeat_end_emit_encodeBlockAsm8B + +repeat_two_repeat_as_copy_encodeBlockAsm8B_emit_copy_short_2b: + LSLW $0x02, R5, R5 + ORRW $0x01, R5, R5 + MOVH R5, (R1) + ADD $0x02, R1, R1 + JMP repeat_end_emit_encodeBlockAsm8B + MOVD $0, R7 + ADD R5<<2, R7, R5 + ADD $1, R5, R5 + MOVWU R5, R5 + MOVB R6, 1(R1) + ASRW $0x08, R6, R6 + LSLW $0x05, R6, R6 + ORRW R6, R5, R5 + MOVB R5, (R1) + ADD $0x02, R1, R1 + JMP repeat_end_emit_encodeBlockAsm8B + +long_offset_short_repeat_as_copy_encodeBlockAsm8B: + MOVD $0xee, R16 + MOVB R16, (R1) + MOVH R6, 1(R1) + SUB $60, R5, R5 + MOVWU R5, R5 + ADD $0x03, R1, R1 + + // emitRepeat + MOVWU R5, R6 + SUB $4, R5, R5 + MOVWU R5, R5 + CMPW $0x08, R6 + BLS repeat_two_repeat_as_copy_encodeBlockAsm8B_emit_copy_short + CMPW $0x0c, R6 + BHS cant_repeat_two_offset_repeat_as_copy_encodeBlockAsm8B_emit_copy_short + +cant_repeat_two_offset_repeat_as_copy_encodeBlockAsm8B_emit_copy_short: + CMPW $0x00000104, R5 + BLO repeat_three_repeat_as_copy_encodeBlockAsm8B_emit_copy_short + SUB $256, R5, R5 + MOVWU R5, R5 + MOVD $0x0019, R16 + MOVH R16, (R1) + MOVH R5, 2(R1) + ADD $0x04, R1, R1 + JMP repeat_end_emit_encodeBlockAsm8B + +repeat_three_repeat_as_copy_encodeBlockAsm8B_emit_copy_short: + SUB $4, R5, R5 + MOVWU R5, R5 + MOVD $0x0015, R16 + MOVH R16, (R1) + MOVB R5, 2(R1) + ADD $0x03, R1, R1 + JMP repeat_end_emit_encodeBlockAsm8B + +repeat_two_repeat_as_copy_encodeBlockAsm8B_emit_copy_short: + LSLW $0x02, R5, R5 + ORRW $0x01, R5, R5 + MOVH R5, (R1) + ADD $0x02, R1, R1 + JMP repeat_end_emit_encodeBlockAsm8B + MOVD $0, R7 + ADD R5<<2, R7, R5 + ADD $1, R5, R5 + MOVWU R5, R5 + MOVB R6, 1(R1) + ASRW $0x08, R6, R6 + LSLW $0x05, R6, R6 + ORRW R6, R5, R5 + MOVB R5, (R1) + ADD $0x02, R1, R1 + JMP repeat_end_emit_encodeBlockAsm8B + +two_byte_offset_short_repeat_as_copy_encodeBlockAsm8B: + MOVWU R5, R7 + LSLW $0x02, R7, R7 + CMPW $0x0c, R5 + BHS emit_copy_three_repeat_as_copy_encodeBlockAsm8B + SUB $15, R7, R7 + MOVWU R7, R7 + MOVB R6, 1(R1) + LSRW $0x08, R6, R6 + LSLW $0x05, R6, R6 + ORRW R6, R7, R7 + MOVB R7, (R1) + ADD $0x02, R1, R1 + JMP repeat_end_emit_encodeBlockAsm8B + +emit_copy_three_repeat_as_copy_encodeBlockAsm8B: + SUB $2, R7, R7 + MOVWU R7, R7 + MOVB R7, (R1) + MOVH R6, 1(R1) + ADD $0x03, R1, R1 + +repeat_end_emit_encodeBlockAsm8B: + MOVW R2, 20(RSP) + JMP search_loop_encodeBlockAsm8B + +no_repeat_found_encodeBlockAsm8B: + MOVWU (R3)(R5), R16 + CMPW R6, R16 + BEQ candidate_match_encodeBlockAsm8B + LSR $0x08, R6, R6 + MOVWU (R0)(R9<<2), R5 + ADD $2, R2, R8 + MOVWU R8, R8 + MOVWU (R3)(R7), R16 + CMPW R6, R16 + BEQ candidate2_match_encodeBlockAsm8B + MOVW R8, (R0)(R9<<2) + LSR $0x08, R6, R6 + MOVWU (R3)(R5), R16 + CMPW R6, R16 + BEQ candidate3_match_encodeBlockAsm8B + MOVWU 28(RSP), R2 + JMP search_loop_encodeBlockAsm8B + +candidate3_match_encodeBlockAsm8B: + ADDW $0x02, R2, R2 + JMP candidate_match_encodeBlockAsm8B + +candidate2_match_encodeBlockAsm8B: + MOVW R8, (R0)(R9<<2) + ADDW $1, R2, R2 + MOVWU R7, R5 + +candidate_match_encodeBlockAsm8B: + MOVWU 20(RSP), R6 + TSTW R5, R5 + BEQ match_extend_back_end_encodeBlockAsm8B + +match_extend_back_loop_encodeBlockAsm8B: + CMPW R6, R2 + BLS match_extend_back_end_encodeBlockAsm8B + ADD R5, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R7 + ADD R2, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R8 + AND $0xff, R8, R16 + AND $0xff, R7, R15 + CMP R16, R15 + BNE match_extend_back_end_encodeBlockAsm8B + SUB $1, R2, R2 + MOVWU R2, R2 + SUBSW $1, R5, R5 + BEQ match_extend_back_end_encodeBlockAsm8B + JMP match_extend_back_loop_encodeBlockAsm8B + +match_extend_back_end_encodeBlockAsm8B: + MOVWU R2, R6 + MOVWU 20(RSP), R16 + SUBW R16, R6, R6 + ADD R6, R1, R6 + ADD $3, R6, R6 + MOVD 8(RSP), R16 + CMP R16, R6 + BLO match_dst_size_check_encodeBlockAsm8B + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +match_dst_size_check_encodeBlockAsm8B: + MOVWU R2, R6 + MOVWU 20(RSP), R7 + CMPW R6, R7 + BEQ emit_literal_done_match_emit_encodeBlockAsm8B + MOVWU R6, R8 + MOVW R6, 20(RSP) + ADD R7, R3, R6 + SUBW R7, R8, R8 + SUB $1, R8, R7 + MOVWU R7, R7 + CMPW $0x3c, R7 + BLO one_byte_match_emit_encodeBlockAsm8B + CMPW $0x00000100, R7 + BLO two_bytes_match_emit_encodeBlockAsm8B + BLO three_bytes_match_emit_encodeBlockAsm8B + +three_bytes_match_emit_encodeBlockAsm8B: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R7, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_match_emit_encodeBlockAsm8B + +two_bytes_match_emit_encodeBlockAsm8B: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R7, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R7 + BLO memmove_match_emit_encodeBlockAsm8B + JMP memmove_long_match_emit_encodeBlockAsm8B + +one_byte_match_emit_encodeBlockAsm8B: + LSLW $0x02, R7, R16 + BFI $0, R16, $8, R7 + MOVB R7, (R1) + ADD $0x01, R1, R1 + +memmove_match_emit_encodeBlockAsm8B: + ADD R8, R1, R7 + + // genMemMoveShort + CMP $0x08, R8 + BLS emit_lit_memmove_match_emit_encodeBlockAsm8B_memmove_move_8 + CMP $0x10, R8 + BLS emit_lit_memmove_match_emit_encodeBlockAsm8B_memmove_move_8through16 + CMP $0x20, R8 + BLS emit_lit_memmove_match_emit_encodeBlockAsm8B_memmove_move_17through32 + JMP emit_lit_memmove_match_emit_encodeBlockAsm8B_memmove_move_33through64 + +emit_lit_memmove_match_emit_encodeBlockAsm8B_memmove_move_8: + MOVD (R6), R9 + MOVD R9, (R1) + JMP memmove_end_copy_match_emit_encodeBlockAsm8B + +emit_lit_memmove_match_emit_encodeBlockAsm8B_memmove_move_8through16: + MOVD (R6), R9 + ADD R8, R6, R15 + MOVD -8(R15), R6 + MOVD R9, (R1) + ADD R8, R1, R15 + MOVD R6, -8(R15) + JMP memmove_end_copy_match_emit_encodeBlockAsm8B + +emit_lit_memmove_match_emit_encodeBlockAsm8B_memmove_move_17through32: + FMOVQ (R6), F0 + ADD R8, R6, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_match_emit_encodeBlockAsm8B + +emit_lit_memmove_match_emit_encodeBlockAsm8B_memmove_move_33through64: + FMOVQ (R6), F0 + FMOVQ 16(R6), F1 + ADD R8, R6, R15 + FMOVQ -32(R15), F2 + ADD R8, R6, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R8, R1, R15 + FMOVQ F2, -32(R15) + ADD R8, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_match_emit_encodeBlockAsm8B: + MOVD R7, R1 + JMP emit_literal_done_match_emit_encodeBlockAsm8B + +memmove_long_match_emit_encodeBlockAsm8B: + ADD R8, R1, R7 + + // genMemMoveLong + MOVD R6, R9 + MOVD R1, R10 + MOVD R8, R11 + +emit_lit_memmove_long_match_emit_encodeBlockAsm8Blarge_big_loop_back: + FMOVQ (R9), F0 + FMOVQ 16(R9), F1 + FMOVQ F0, (R10) + FMOVQ F1, 16(R10) + ADD $0x20, R9, R9 + ADD $0x20, R10, R10 + SUB $0x20, R11, R11 + CMP $0x20, R11 + BHS emit_lit_memmove_long_match_emit_encodeBlockAsm8Blarge_big_loop_back + ADD R8, R6, R15 + FMOVQ -32(R15), F0 + ADD R8, R6, R15 + FMOVQ -16(R15), F1 + ADD R8, R1, R15 + FMOVQ F0, -32(R15) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + MOVD R7, R1 + +emit_literal_done_match_emit_encodeBlockAsm8B: +match_nolit_loop_encodeBlockAsm8B: + MOVWU R2, R6 + SUBW R5, R6, R6 + MOVW R6, 24(RSP) + ADDW $0x04, R2, R2 + ADDW $0x04, R5, R5 + MOVD src_len+32(FP), R6 + SUBW R2, R6, R6 + ADD R2, R3, R7 + ADD R5, R3, R5 + + // matchLen + MOVD $0, R9 + +matchlen_loopback_16_match_nolit_encodeBlockAsm8B: + CMPW $0x10, R6 + BLO matchlen_match8_match_nolit_encodeBlockAsm8B + MOVD (R7)(R9), R8 + ADD R9, R7, R15 + MOVD 8(R15), R10 + MOVD (R5)(R9), R16 + EOR R16, R8, R8 + TST R8, R8 + BNE matchlen_bsf_8_match_nolit_encodeBlockAsm8B + ADD R9, R5, R15 + MOVD 8(R15), R16 + EOR R16, R10, R10 + TST R10, R10 + BNE matchlen_bsf_16match_nolit_encodeBlockAsm8B + SUB $16, R6, R6 + MOVWU R6, R6 + ADD $16, R9, R9 + MOVWU R9, R9 + JMP matchlen_loopback_16_match_nolit_encodeBlockAsm8B + +matchlen_bsf_16match_nolit_encodeBlockAsm8B: + RBIT R10, R10 + CLZ R10, R10 + ASR $0x03, R10, R10 + ADD R10, R9, R9 + ADD $8, R9, R9 + MOVWU R9, R9 + JMP match_nolit_end_encodeBlockAsm8B + +matchlen_match8_match_nolit_encodeBlockAsm8B: + CMPW $0x08, R6 + BLO matchlen_match4_match_nolit_encodeBlockAsm8B + MOVD (R7)(R9), R8 + MOVD (R5)(R9), R16 + EOR R16, R8, R8 + TST R8, R8 + BNE matchlen_bsf_8_match_nolit_encodeBlockAsm8B + SUB $8, R6, R6 + MOVWU R6, R6 + ADD $8, R9, R9 + MOVWU R9, R9 + JMP matchlen_match4_match_nolit_encodeBlockAsm8B + +matchlen_bsf_8_match_nolit_encodeBlockAsm8B: + RBIT R8, R8 + CLZ R8, R8 + ASR $0x03, R8, R8 + ADD R8, R9, R9 + MOVWU R9, R9 + JMP match_nolit_end_encodeBlockAsm8B + +matchlen_match4_match_nolit_encodeBlockAsm8B: + CMPW $0x04, R6 + BLO matchlen_match2_match_nolit_encodeBlockAsm8B + MOVWU (R7)(R9), R8 + MOVWU (R5)(R9), R16 + CMPW R8, R16 + BNE matchlen_match2_match_nolit_encodeBlockAsm8B + SUB $4, R6, R6 + MOVWU R6, R6 + ADD $4, R9, R9 + MOVWU R9, R9 + +matchlen_match2_match_nolit_encodeBlockAsm8B: + CMPW $0x01, R6 + BEQ matchlen_match1_match_nolit_encodeBlockAsm8B + BLO match_nolit_end_encodeBlockAsm8B + MOVHU (R7)(R9), R16 + BFI $0, R16, $16, R8 + ADD R9, R5, R15 + MOVHU (R15), R15 + AND $0xffff, R8, R16 + CMP R16, R15 + BNE matchlen_match1_match_nolit_encodeBlockAsm8B + ADD $2, R9, R9 + MOVWU R9, R9 + SUBSW $0x02, R6, R6 + BEQ match_nolit_end_encodeBlockAsm8B + +matchlen_match1_match_nolit_encodeBlockAsm8B: + MOVBU (R7)(R9), R16 + BFI $0, R16, $8, R8 + ADD R9, R5, R15 + MOVBU (R15), R15 + AND $0xff, R8, R16 + CMP R16, R15 + BNE match_nolit_end_encodeBlockAsm8B + ADD $1, R9, R9 + MOVWU R9, R9 + +match_nolit_end_encodeBlockAsm8B: + ADDW R9, R2, R2 + MOVWU 24(RSP), R5 + ADDW $0x04, R9, R9 + MOVW R2, 20(RSP) + + // emitCopy + CMPW $0x40, R9 + BLS two_byte_offset_short_match_nolit_encodeBlockAsm8B + CMPW $0x00000800, R5 + BHS long_offset_short_match_nolit_encodeBlockAsm8B + MOVD $0x00000001, R6 + ADD $16, R6, R6 + MOVWU R6, R6 + MOVB R5, 1(R1) + LSRW $0x08, R5, R5 + LSLW $0x05, R5, R5 + ORRW R5, R6, R6 + MOVB R6, (R1) + ADD $0x02, R1, R1 + SUBW $0x08, R9, R9 + + // emitRepeat + SUB $4, R9, R9 + MOVWU R9, R9 + JMP cant_repeat_two_offset_match_nolit_encodeBlockAsm8B_emit_copy_short_2b + MOVWU R9, R5 + SUB $4, R9, R9 + MOVWU R9, R9 + CMPW $0x08, R5 + BLS repeat_two_match_nolit_encodeBlockAsm8B_emit_copy_short_2b + CMPW $0x0c, R5 + BHS cant_repeat_two_offset_match_nolit_encodeBlockAsm8B_emit_copy_short_2b + +cant_repeat_two_offset_match_nolit_encodeBlockAsm8B_emit_copy_short_2b: + CMPW $0x00000104, R9 + BLO repeat_three_match_nolit_encodeBlockAsm8B_emit_copy_short_2b + SUB $256, R9, R9 + MOVWU R9, R9 + MOVD $0x0019, R16 + MOVH R16, (R1) + MOVH R9, 2(R1) + ADD $0x04, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm8B + +repeat_three_match_nolit_encodeBlockAsm8B_emit_copy_short_2b: + SUB $4, R9, R9 + MOVWU R9, R9 + MOVD $0x0015, R16 + MOVH R16, (R1) + MOVB R9, 2(R1) + ADD $0x03, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm8B + +repeat_two_match_nolit_encodeBlockAsm8B_emit_copy_short_2b: + LSLW $0x02, R9, R9 + ORRW $0x01, R9, R9 + MOVH R9, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm8B + MOVD $0, R6 + ADD R9<<2, R6, R9 + ADD $1, R9, R9 + MOVWU R9, R9 + MOVB R5, 1(R1) + ASRW $0x08, R5, R5 + LSLW $0x05, R5, R5 + ORRW R5, R9, R9 + MOVB R9, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm8B + +long_offset_short_match_nolit_encodeBlockAsm8B: + MOVD $0xee, R16 + MOVB R16, (R1) + MOVH R5, 1(R1) + SUB $60, R9, R9 + MOVWU R9, R9 + ADD $0x03, R1, R1 + + // emitRepeat + MOVWU R9, R5 + SUB $4, R9, R9 + MOVWU R9, R9 + CMPW $0x08, R5 + BLS repeat_two_match_nolit_encodeBlockAsm8B_emit_copy_short + CMPW $0x0c, R5 + BHS cant_repeat_two_offset_match_nolit_encodeBlockAsm8B_emit_copy_short + +cant_repeat_two_offset_match_nolit_encodeBlockAsm8B_emit_copy_short: + CMPW $0x00000104, R9 + BLO repeat_three_match_nolit_encodeBlockAsm8B_emit_copy_short + SUB $256, R9, R9 + MOVWU R9, R9 + MOVD $0x0019, R16 + MOVH R16, (R1) + MOVH R9, 2(R1) + ADD $0x04, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm8B + +repeat_three_match_nolit_encodeBlockAsm8B_emit_copy_short: + SUB $4, R9, R9 + MOVWU R9, R9 + MOVD $0x0015, R16 + MOVH R16, (R1) + MOVB R9, 2(R1) + ADD $0x03, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm8B + +repeat_two_match_nolit_encodeBlockAsm8B_emit_copy_short: + LSLW $0x02, R9, R9 + ORRW $0x01, R9, R9 + MOVH R9, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm8B + MOVD $0, R6 + ADD R9<<2, R6, R9 + ADD $1, R9, R9 + MOVWU R9, R9 + MOVB R5, 1(R1) + ASRW $0x08, R5, R5 + LSLW $0x05, R5, R5 + ORRW R5, R9, R9 + MOVB R9, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm8B + +two_byte_offset_short_match_nolit_encodeBlockAsm8B: + MOVWU R9, R6 + LSLW $0x02, R6, R6 + CMPW $0x0c, R9 + BHS emit_copy_three_match_nolit_encodeBlockAsm8B + SUB $15, R6, R6 + MOVWU R6, R6 + MOVB R5, 1(R1) + LSRW $0x08, R5, R5 + LSLW $0x05, R5, R5 + ORRW R5, R6, R6 + MOVB R6, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBlockAsm8B + +emit_copy_three_match_nolit_encodeBlockAsm8B: + SUB $2, R6, R6 + MOVWU R6, R6 + MOVB R6, (R1) + MOVH R5, 1(R1) + ADD $0x03, R1, R1 + +match_nolit_emitcopy_end_encodeBlockAsm8B: + MOVWU 16(RSP), R16 + CMPW R16, R2 + BHS emit_remainder_encodeBlockAsm8B + ADD R2, R3, R15 + MOVD -2(R15), R6 + MOVD 8(RSP), R16 + CMP R16, R1 + BLO match_nolit_dst_ok_encodeBlockAsm8B + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +match_nolit_dst_ok_encodeBlockAsm8B: + MOVD $0x9e3779b1, R8 + MOVD R6, R7 + LSR $0x10, R6, R6 + MOVD R6, R5 + LSL $0x20, R7, R7 + MUL R8, R7, R7 + LSR $0x38, R7, R7 + LSL $0x20, R5, R5 + MUL R8, R5, R5 + LSR $0x38, R5, R5 + SUB $2, R2, R8 + MOVWU R8, R8 + ADD R5<<2, R0, R9 + MOVWU (R9), R5 + MOVW R8, (R0)(R7<<2) + MOVW R2, (R9) + MOVWU (R3)(R5), R16 + CMPW R6, R16 + BEQ match_nolit_loop_encodeBlockAsm8B + ADDW $1, R2, R2 + JMP search_loop_encodeBlockAsm8B + +emit_remainder_encodeBlockAsm8B: + MOVD src_len+32(FP), R0 + MOVWU 20(RSP), R16 + SUBW R16, R0, R0 + ADD R0, R1, R0 + ADD $3, R0, R0 + MOVD 8(RSP), R16 + CMP R16, R0 + BLO emit_remainder_ok_encodeBlockAsm8B + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +emit_remainder_ok_encodeBlockAsm8B: + MOVD src_len+32(FP), R0 + MOVWU 20(RSP), R2 + CMPW R0, R2 + BEQ emit_literal_done_emit_remainder_encodeBlockAsm8B + MOVWU R0, R5 + MOVW R0, 20(RSP) + ADD R2, R3, R0 + SUBW R2, R5, R5 + SUB $1, R5, R2 + MOVWU R2, R2 + CMPW $0x3c, R2 + BLO one_byte_emit_remainder_encodeBlockAsm8B + CMPW $0x00000100, R2 + BLO two_bytes_emit_remainder_encodeBlockAsm8B + BLO three_bytes_emit_remainder_encodeBlockAsm8B + +three_bytes_emit_remainder_encodeBlockAsm8B: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R2, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_emit_remainder_encodeBlockAsm8B + +two_bytes_emit_remainder_encodeBlockAsm8B: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R2, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R2 + BLO memmove_emit_remainder_encodeBlockAsm8B + JMP memmove_long_emit_remainder_encodeBlockAsm8B + +one_byte_emit_remainder_encodeBlockAsm8B: + LSLW $0x02, R2, R16 + BFI $0, R16, $8, R2 + MOVB R2, (R1) + ADD $0x01, R1, R1 + +memmove_emit_remainder_encodeBlockAsm8B: + ADD R5, R1, R2 + MOVWU R5, R3 + + // genMemMoveShort + CMP $0x03, R3 + BLO emit_lit_memmove_emit_remainder_encodeBlockAsm8B_memmove_move_1or2 + BEQ emit_lit_memmove_emit_remainder_encodeBlockAsm8B_memmove_move_3 + CMP $0x08, R3 + BLO emit_lit_memmove_emit_remainder_encodeBlockAsm8B_memmove_move_4through7 + CMP $0x10, R3 + BLS emit_lit_memmove_emit_remainder_encodeBlockAsm8B_memmove_move_8through16 + CMP $0x20, R3 + BLS emit_lit_memmove_emit_remainder_encodeBlockAsm8B_memmove_move_17through32 + JMP emit_lit_memmove_emit_remainder_encodeBlockAsm8B_memmove_move_33through64 + +emit_lit_memmove_emit_remainder_encodeBlockAsm8B_memmove_move_1or2: + MOVBU (R0), R16 + BFI $0, R16, $8, R5 + ADD R3, R0, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R0 + MOVB R5, (R1) + ADD R3, R1, R15 + MOVB R0, -1(R15) + JMP memmove_end_copy_emit_remainder_encodeBlockAsm8B + +emit_lit_memmove_emit_remainder_encodeBlockAsm8B_memmove_move_3: + MOVHU (R0), R16 + BFI $0, R16, $16, R5 + MOVBU 2(R0), R16 + BFI $0, R16, $8, R0 + MOVH R5, (R1) + MOVB R0, 2(R1) + JMP memmove_end_copy_emit_remainder_encodeBlockAsm8B + +emit_lit_memmove_emit_remainder_encodeBlockAsm8B_memmove_move_4through7: + MOVWU (R0), R5 + ADD R3, R0, R15 + MOVWU -4(R15), R0 + MOVW R5, (R1) + ADD R3, R1, R15 + MOVW R0, -4(R15) + JMP memmove_end_copy_emit_remainder_encodeBlockAsm8B + +emit_lit_memmove_emit_remainder_encodeBlockAsm8B_memmove_move_8through16: + MOVD (R0), R5 + ADD R3, R0, R15 + MOVD -8(R15), R0 + MOVD R5, (R1) + ADD R3, R1, R15 + MOVD R0, -8(R15) + JMP memmove_end_copy_emit_remainder_encodeBlockAsm8B + +emit_lit_memmove_emit_remainder_encodeBlockAsm8B_memmove_move_17through32: + FMOVQ (R0), F0 + ADD R3, R0, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R3, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_emit_remainder_encodeBlockAsm8B + +emit_lit_memmove_emit_remainder_encodeBlockAsm8B_memmove_move_33through64: + FMOVQ (R0), F0 + FMOVQ 16(R0), F1 + ADD R3, R0, R15 + FMOVQ -32(R15), F2 + ADD R3, R0, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R3, R1, R15 + FMOVQ F2, -32(R15) + ADD R3, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_emit_remainder_encodeBlockAsm8B: + MOVD R2, R1 + JMP emit_literal_done_emit_remainder_encodeBlockAsm8B + +memmove_long_emit_remainder_encodeBlockAsm8B: + ADD R5, R1, R2 + MOVWU R5, R3 + + // genMemMoveLong + MOVD R0, R5 + MOVD R1, R6 + MOVD R3, R7 + +emit_lit_memmove_long_emit_remainder_encodeBlockAsm8Blarge_big_loop_back: + FMOVQ (R5), F0 + FMOVQ 16(R5), F1 + FMOVQ F0, (R6) + FMOVQ F1, 16(R6) + ADD $0x20, R5, R5 + ADD $0x20, R6, R6 + SUB $0x20, R7, R7 + CMP $0x20, R7 + BHS emit_lit_memmove_long_emit_remainder_encodeBlockAsm8Blarge_big_loop_back + ADD R3, R0, R15 + FMOVQ -32(R15), F0 + ADD R3, R0, R15 + FMOVQ -16(R15), F1 + ADD R3, R1, R15 + FMOVQ F0, -32(R15) + ADD R3, R1, R15 + FMOVQ F1, -16(R15) + MOVD R2, R1 + +emit_literal_done_emit_remainder_encodeBlockAsm8B: + MOVD dst_base+0(FP), R0 + SUB R0, R1, R1 + MOVD R1, ret+56(FP) + RET + +// func encodeBetterBlockAsm(dst []byte, src []byte, tmp *[589824]byte) int +// Requires: BMI, SSE2 +TEXT ·encodeBetterBlockAsm(SB), $24-64 + MOVD tmp+48(FP), R0 + MOVD dst_base+0(FP), R1 + MOVD $0x00001200, R2 + MOVD R0, R3 + VEOR V0.B16, V0.B16, V0.B16 + +zero_loop_encodeBetterBlockAsm: + FMOVQ F0, (R3) + FMOVQ F0, 16(R3) + FMOVQ F0, 32(R3) + FMOVQ F0, 48(R3) + FMOVQ F0, 64(R3) + FMOVQ F0, 80(R3) + FMOVQ F0, 96(R3) + FMOVQ F0, 112(R3) + ADD $0x80, R3, R3 + SUBS $1, R2, R2 + BNE zero_loop_encodeBetterBlockAsm + MOVD $0x00000000, R16 + MOVW R16, 20(RSP) + MOVD src_len+32(FP), R2 + SUB $6, R2, R3 + SUB $8, R2, R5 + MOVW R5, 16(RSP) + LSR $0x05, R2, R2 + SUBW R2, R3, R3 + ADD R3, R1, R3 + MOVD R3, 8(RSP) + MOVD $0x00000001, R2 + MOVD $0x00000000, R16 + MOVW R16, 24(RSP) + MOVD src_base+24(FP), R3 + +search_loop_encodeBetterBlockAsm: + MOVWU R2, R5 + MOVWU 20(RSP), R16 + SUBW R16, R5, R5 + LSRW $0x07, R5, R5 + CMPW $0x63, R5 + BLS check_maxskip_ok_encodeBetterBlockAsm + ADD $100, R2, R5 + MOVWU R5, R5 + JMP check_maxskip_cont_encodeBetterBlockAsm + +check_maxskip_ok_encodeBetterBlockAsm: + ADD R5, R2, R5 + ADD $1, R5, R5 + MOVWU R5, R5 + +check_maxskip_cont_encodeBetterBlockAsm: + MOVWU 16(RSP), R16 + CMPW R16, R5 + BHS emit_remainder_encodeBetterBlockAsm + MOVD (R3)(R2), R6 + MOVW R5, 28(RSP) + MOVD $0x00cf1bbcdcbfa563, R8 + MOVD $0x9e3779b1, R5 + MOVD R6, R9 + MOVD R6, R10 + LSL $0x08, R9, R9 + MUL R8, R9, R9 + LSR $0x2f, R9, R9 + LSL $0x20, R10, R10 + MUL R5, R10, R10 + LSR $0x32, R10, R10 + MOVWU (R0)(R9<<2), R5 + ADD R10<<2, R0, R15 + MOVWU 524288(R15), R7 + MOVW R2, (R0)(R9<<2) + ADD R10<<2, R0, R15 + MOVW R2, 524288(R15) + MOVD (R3)(R5), R9 + MOVD (R3)(R7), R10 + CMP R6, R9 + BEQ candidate_match_encodeBetterBlockAsm + CMP R6, R10 + BNE no_short_found_encodeBetterBlockAsm + MOVWU R7, R5 + JMP candidate_match_encodeBetterBlockAsm + +no_short_found_encodeBetterBlockAsm: + CMPW R6, R9 + BEQ candidate_match_encodeBetterBlockAsm + CMPW R6, R10 + BEQ candidateS_match_encodeBetterBlockAsm + MOVWU 28(RSP), R2 + JMP search_loop_encodeBetterBlockAsm + +candidateS_match_encodeBetterBlockAsm: + LSR $0x08, R6, R6 + MOVD R6, R9 + LSL $0x08, R9, R9 + MUL R8, R9, R9 + LSR $0x2f, R9, R9 + MOVWU (R0)(R9<<2), R5 + ADDW $1, R2, R2 + MOVW R2, (R0)(R9<<2) + MOVWU (R3)(R5), R16 + CMPW R6, R16 + BEQ candidate_match_encodeBetterBlockAsm + SUBW $1, R2, R2 + MOVWU R7, R5 + +candidate_match_encodeBetterBlockAsm: + MOVWU 20(RSP), R6 + TSTW R5, R5 + BEQ match_extend_back_end_encodeBetterBlockAsm + +match_extend_back_loop_encodeBetterBlockAsm: + CMPW R6, R2 + BLS match_extend_back_end_encodeBetterBlockAsm + ADD R5, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R7 + ADD R2, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R8 + AND $0xff, R8, R16 + AND $0xff, R7, R15 + CMP R16, R15 + BNE match_extend_back_end_encodeBetterBlockAsm + SUB $1, R2, R2 + MOVWU R2, R2 + SUBSW $1, R5, R5 + BEQ match_extend_back_end_encodeBetterBlockAsm + JMP match_extend_back_loop_encodeBetterBlockAsm + +match_extend_back_end_encodeBetterBlockAsm: + MOVWU R2, R6 + MOVWU 20(RSP), R16 + SUBW R16, R6, R6 + ADD R6, R1, R6 + ADD $5, R6, R6 + MOVD 8(RSP), R16 + CMP R16, R6 + BLO match_dst_size_check_encodeBetterBlockAsm + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +match_dst_size_check_encodeBetterBlockAsm: + MOVWU R2, R6 + ADDW $0x04, R2, R2 + ADDW $0x04, R5, R5 + MOVD src_len+32(FP), R7 + SUBW R2, R7, R7 + ADD R2, R3, R8 + ADD R5, R3, R9 + + // matchLen + MOVD $0, R11 + +matchlen_loopback_16_match_nolit_encodeBetterBlockAsm: + CMPW $0x10, R7 + BLO matchlen_match8_match_nolit_encodeBetterBlockAsm + MOVD (R8)(R11), R10 + ADD R11, R8, R15 + MOVD 8(R15), R12 + MOVD (R9)(R11), R16 + EOR R16, R10, R10 + TST R10, R10 + BNE matchlen_bsf_8_match_nolit_encodeBetterBlockAsm + ADD R11, R9, R15 + MOVD 8(R15), R16 + EOR R16, R12, R12 + TST R12, R12 + BNE matchlen_bsf_16match_nolit_encodeBetterBlockAsm + SUB $16, R7, R7 + MOVWU R7, R7 + ADD $16, R11, R11 + MOVWU R11, R11 + JMP matchlen_loopback_16_match_nolit_encodeBetterBlockAsm + +matchlen_bsf_16match_nolit_encodeBetterBlockAsm: + RBIT R12, R12 + CLZ R12, R12 + ASR $0x03, R12, R12 + ADD R12, R11, R11 + ADD $8, R11, R11 + MOVWU R11, R11 + JMP match_nolit_end_encodeBetterBlockAsm + +matchlen_match8_match_nolit_encodeBetterBlockAsm: + CMPW $0x08, R7 + BLO matchlen_match4_match_nolit_encodeBetterBlockAsm + MOVD (R8)(R11), R10 + MOVD (R9)(R11), R16 + EOR R16, R10, R10 + TST R10, R10 + BNE matchlen_bsf_8_match_nolit_encodeBetterBlockAsm + SUB $8, R7, R7 + MOVWU R7, R7 + ADD $8, R11, R11 + MOVWU R11, R11 + JMP matchlen_match4_match_nolit_encodeBetterBlockAsm + +matchlen_bsf_8_match_nolit_encodeBetterBlockAsm: + RBIT R10, R10 + CLZ R10, R10 + ASR $0x03, R10, R10 + ADD R10, R11, R11 + MOVWU R11, R11 + JMP match_nolit_end_encodeBetterBlockAsm + +matchlen_match4_match_nolit_encodeBetterBlockAsm: + CMPW $0x04, R7 + BLO matchlen_match2_match_nolit_encodeBetterBlockAsm + MOVWU (R8)(R11), R10 + MOVWU (R9)(R11), R16 + CMPW R10, R16 + BNE matchlen_match2_match_nolit_encodeBetterBlockAsm + SUB $4, R7, R7 + MOVWU R7, R7 + ADD $4, R11, R11 + MOVWU R11, R11 + +matchlen_match2_match_nolit_encodeBetterBlockAsm: + CMPW $0x01, R7 + BEQ matchlen_match1_match_nolit_encodeBetterBlockAsm + BLO match_nolit_end_encodeBetterBlockAsm + MOVHU (R8)(R11), R16 + BFI $0, R16, $16, R10 + ADD R11, R9, R15 + MOVHU (R15), R15 + AND $0xffff, R10, R16 + CMP R16, R15 + BNE matchlen_match1_match_nolit_encodeBetterBlockAsm + ADD $2, R11, R11 + MOVWU R11, R11 + SUBSW $0x02, R7, R7 + BEQ match_nolit_end_encodeBetterBlockAsm + +matchlen_match1_match_nolit_encodeBetterBlockAsm: + MOVBU (R8)(R11), R16 + BFI $0, R16, $8, R10 + ADD R11, R9, R15 + MOVBU (R15), R15 + AND $0xff, R10, R16 + CMP R16, R15 + BNE match_nolit_end_encodeBetterBlockAsm + ADD $1, R11, R11 + MOVWU R11, R11 + +match_nolit_end_encodeBetterBlockAsm: + MOVWU R2, R7 + SUBW R5, R7, R7 + + // Check if repeat + MOVWU 24(RSP), R16 + CMPW R7, R16 + BEQ match_is_repeat_encodeBetterBlockAsm + CMPW $0x01, R11 + BHI match_length_ok_encodeBetterBlockAsm + CMPW $0x0000ffff, R7 + BLS match_length_ok_encodeBetterBlockAsm + MOVWU 28(RSP), R2 + ADDW $1, R2, R2 + JMP search_loop_encodeBetterBlockAsm + +match_length_ok_encodeBetterBlockAsm: + MOVW R7, 24(RSP) + MOVWU 20(RSP), R5 + CMPW R6, R5 + BEQ emit_literal_done_match_emit_encodeBetterBlockAsm + MOVWU R6, R8 + MOVW R6, 20(RSP) + ADD R5, R3, R9 + SUBW R5, R8, R8 + SUB $1, R8, R5 + MOVWU R5, R5 + CMPW $0x3c, R5 + BLO one_byte_match_emit_encodeBetterBlockAsm + CMPW $0x00000100, R5 + BLO two_bytes_match_emit_encodeBetterBlockAsm + CMPW $0x00010000, R5 + BLO three_bytes_match_emit_encodeBetterBlockAsm + CMPW $0x01000000, R5 + BLO four_bytes_match_emit_encodeBetterBlockAsm + MOVD $0xfc, R16 + MOVB R16, (R1) + MOVW R5, 1(R1) + ADD $0x05, R1, R1 + JMP memmove_long_match_emit_encodeBetterBlockAsm + +four_bytes_match_emit_encodeBetterBlockAsm: + MOVWU R5, R10 + LSRW $0x10, R10, R10 + MOVD $0xf8, R16 + MOVB R16, (R1) + MOVH R5, 1(R1) + MOVB R10, 3(R1) + ADD $0x04, R1, R1 + JMP memmove_long_match_emit_encodeBetterBlockAsm + +three_bytes_match_emit_encodeBetterBlockAsm: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R5, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_match_emit_encodeBetterBlockAsm + +two_bytes_match_emit_encodeBetterBlockAsm: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R5, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R5 + BLO memmove_match_emit_encodeBetterBlockAsm + JMP memmove_long_match_emit_encodeBetterBlockAsm + +one_byte_match_emit_encodeBetterBlockAsm: + LSLW $0x02, R5, R16 + BFI $0, R16, $8, R5 + MOVB R5, (R1) + ADD $0x01, R1, R1 + +memmove_match_emit_encodeBetterBlockAsm: + ADD R8, R1, R5 + + // genMemMoveShort + CMP $0x04, R8 + BLS emit_lit_memmove_match_emit_encodeBetterBlockAsm_memmove_move_4 + CMP $0x08, R8 + BLO emit_lit_memmove_match_emit_encodeBetterBlockAsm_memmove_move_4through7 + CMP $0x10, R8 + BLS emit_lit_memmove_match_emit_encodeBetterBlockAsm_memmove_move_8through16 + CMP $0x20, R8 + BLS emit_lit_memmove_match_emit_encodeBetterBlockAsm_memmove_move_17through32 + JMP emit_lit_memmove_match_emit_encodeBetterBlockAsm_memmove_move_33through64 + +emit_lit_memmove_match_emit_encodeBetterBlockAsm_memmove_move_4: + MOVWU (R9), R10 + MOVW R10, (R1) + JMP memmove_end_copy_match_emit_encodeBetterBlockAsm + +emit_lit_memmove_match_emit_encodeBetterBlockAsm_memmove_move_4through7: + MOVWU (R9), R10 + ADD R8, R9, R15 + MOVWU -4(R15), R9 + MOVW R10, (R1) + ADD R8, R1, R15 + MOVW R9, -4(R15) + JMP memmove_end_copy_match_emit_encodeBetterBlockAsm + +emit_lit_memmove_match_emit_encodeBetterBlockAsm_memmove_move_8through16: + MOVD (R9), R10 + ADD R8, R9, R15 + MOVD -8(R15), R9 + MOVD R10, (R1) + ADD R8, R1, R15 + MOVD R9, -8(R15) + JMP memmove_end_copy_match_emit_encodeBetterBlockAsm + +emit_lit_memmove_match_emit_encodeBetterBlockAsm_memmove_move_17through32: + FMOVQ (R9), F0 + ADD R8, R9, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_match_emit_encodeBetterBlockAsm + +emit_lit_memmove_match_emit_encodeBetterBlockAsm_memmove_move_33through64: + FMOVQ (R9), F0 + FMOVQ 16(R9), F1 + ADD R8, R9, R15 + FMOVQ -32(R15), F2 + ADD R8, R9, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R8, R1, R15 + FMOVQ F2, -32(R15) + ADD R8, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_match_emit_encodeBetterBlockAsm: + MOVD R5, R1 + JMP emit_literal_done_match_emit_encodeBetterBlockAsm + +memmove_long_match_emit_encodeBetterBlockAsm: + ADD R8, R1, R5 + + // genMemMoveLong + MOVD R9, R10 + MOVD R1, R12 + MOVD R8, R13 + +emit_lit_memmove_long_match_emit_encodeBetterBlockAsmlarge_big_loop_back: + FMOVQ (R10), F0 + FMOVQ 16(R10), F1 + FMOVQ F0, (R12) + FMOVQ F1, 16(R12) + ADD $0x20, R10, R10 + ADD $0x20, R12, R12 + SUB $0x20, R13, R13 + CMP $0x20, R13 + BHS emit_lit_memmove_long_match_emit_encodeBetterBlockAsmlarge_big_loop_back + ADD R8, R9, R15 + FMOVQ -32(R15), F0 + ADD R8, R9, R15 + FMOVQ -16(R15), F1 + ADD R8, R1, R15 + FMOVQ F0, -32(R15) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + MOVD R5, R1 + +emit_literal_done_match_emit_encodeBetterBlockAsm: + ADDW R11, R2, R2 + ADDW $0x04, R11, R11 + MOVW R2, 20(RSP) + + // emitCopy + CMPW $0x00010000, R7 + BLO two_byte_offset_match_nolit_encodeBetterBlockAsm + CMPW $0x40, R11 + BLS four_bytes_remain_match_nolit_encodeBetterBlockAsm + MOVD $0xff, R16 + MOVB R16, (R1) + MOVW R7, 1(R1) + SUB $64, R11, R11 + MOVWU R11, R11 + ADD $0x05, R1, R1 + CMPW $0x04, R11 + BLO four_bytes_remain_match_nolit_encodeBetterBlockAsm + + // emitRepeat +emit_repeat_again_match_nolit_encodeBetterBlockAsm_emit_copy: + MOVWU R11, R5 + SUB $4, R11, R11 + MOVWU R11, R11 + CMPW $0x08, R5 + BLS repeat_two_match_nolit_encodeBetterBlockAsm_emit_copy + CMPW $0x0c, R5 + BHS cant_repeat_two_offset_match_nolit_encodeBetterBlockAsm_emit_copy + CMPW $0x00000800, R7 + BLO repeat_two_offset_match_nolit_encodeBetterBlockAsm_emit_copy + +cant_repeat_two_offset_match_nolit_encodeBetterBlockAsm_emit_copy: + CMPW $0x00000104, R11 + BLO repeat_three_match_nolit_encodeBetterBlockAsm_emit_copy + CMPW $0x00010100, R11 + BLO repeat_four_match_nolit_encodeBetterBlockAsm_emit_copy + CMPW $0x0100ffff, R11 + BLO repeat_five_match_nolit_encodeBetterBlockAsm_emit_copy + SUB $16842747, R11, R11 + MOVWU R11, R11 + MOVD $0xfffb001d, R16 + MOVW R16, (R1) + MOVD $0xff, R16 + MOVB R16, 4(R1) + ADD $0x05, R1, R1 + JMP emit_repeat_again_match_nolit_encodeBetterBlockAsm_emit_copy + +repeat_five_match_nolit_encodeBetterBlockAsm_emit_copy: + SUB $65536, R11, R11 + MOVWU R11, R11 + MOVWU R11, R7 + MOVD $0x001d, R16 + MOVH R16, (R1) + MOVH R11, 2(R1) + ASRW $0x10, R7, R7 + MOVB R7, 4(R1) + ADD $0x05, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm + +repeat_four_match_nolit_encodeBetterBlockAsm_emit_copy: + SUB $256, R11, R11 + MOVWU R11, R11 + MOVD $0x0019, R16 + MOVH R16, (R1) + MOVH R11, 2(R1) + ADD $0x04, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm + +repeat_three_match_nolit_encodeBetterBlockAsm_emit_copy: + SUB $4, R11, R11 + MOVWU R11, R11 + MOVD $0x0015, R16 + MOVH R16, (R1) + MOVB R11, 2(R1) + ADD $0x03, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm + +repeat_two_match_nolit_encodeBetterBlockAsm_emit_copy: + LSLW $0x02, R11, R11 + ORRW $0x01, R11, R11 + MOVH R11, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm + +repeat_two_offset_match_nolit_encodeBetterBlockAsm_emit_copy: + MOVD $0, R5 + ADD R11<<2, R5, R11 + ADD $1, R11, R11 + MOVWU R11, R11 + MOVB R7, 1(R1) + ASRW $0x08, R7, R7 + LSLW $0x05, R7, R7 + ORRW R7, R11, R11 + MOVB R11, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm + +four_bytes_remain_match_nolit_encodeBetterBlockAsm: + TSTW R11, R11 + BEQ match_nolit_emitcopy_end_encodeBetterBlockAsm + MOVD $0, R5 + ADD R11<<2, R5, R11 + SUB $1, R11, R11 + MOVWU R11, R11 + MOVB R11, (R1) + MOVW R7, 1(R1) + ADD $0x05, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm + +two_byte_offset_match_nolit_encodeBetterBlockAsm: + CMPW $0x40, R11 + BLS two_byte_offset_short_match_nolit_encodeBetterBlockAsm + CMPW $0x00000800, R7 + BHS long_offset_short_match_nolit_encodeBetterBlockAsm + MOVD $0x00000001, R5 + ADD $16, R5, R5 + MOVWU R5, R5 + MOVB R7, 1(R1) + MOVWU R7, R8 + LSRW $0x08, R8, R8 + LSLW $0x05, R8, R8 + ORRW R8, R5, R5 + MOVB R5, (R1) + ADD $0x02, R1, R1 + SUBW $0x08, R11, R11 + + // emitRepeat + SUB $4, R11, R11 + MOVWU R11, R11 + JMP cant_repeat_two_offset_match_nolit_encodeBetterBlockAsm_emit_copy_short_2b + +emit_repeat_again_match_nolit_encodeBetterBlockAsm_emit_copy_short_2b: + MOVWU R11, R5 + SUB $4, R11, R11 + MOVWU R11, R11 + CMPW $0x08, R5 + BLS repeat_two_match_nolit_encodeBetterBlockAsm_emit_copy_short_2b + CMPW $0x0c, R5 + BHS cant_repeat_two_offset_match_nolit_encodeBetterBlockAsm_emit_copy_short_2b + CMPW $0x00000800, R7 + BLO repeat_two_offset_match_nolit_encodeBetterBlockAsm_emit_copy_short_2b + +cant_repeat_two_offset_match_nolit_encodeBetterBlockAsm_emit_copy_short_2b: + CMPW $0x00000104, R11 + BLO repeat_three_match_nolit_encodeBetterBlockAsm_emit_copy_short_2b + CMPW $0x00010100, R11 + BLO repeat_four_match_nolit_encodeBetterBlockAsm_emit_copy_short_2b + CMPW $0x0100ffff, R11 + BLO repeat_five_match_nolit_encodeBetterBlockAsm_emit_copy_short_2b + SUB $16842747, R11, R11 + MOVWU R11, R11 + MOVD $0xfffb001d, R16 + MOVW R16, (R1) + MOVD $0xff, R16 + MOVB R16, 4(R1) + ADD $0x05, R1, R1 + JMP emit_repeat_again_match_nolit_encodeBetterBlockAsm_emit_copy_short_2b + +repeat_five_match_nolit_encodeBetterBlockAsm_emit_copy_short_2b: + SUB $65536, R11, R11 + MOVWU R11, R11 + MOVWU R11, R7 + MOVD $0x001d, R16 + MOVH R16, (R1) + MOVH R11, 2(R1) + ASRW $0x10, R7, R7 + MOVB R7, 4(R1) + ADD $0x05, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm + +repeat_four_match_nolit_encodeBetterBlockAsm_emit_copy_short_2b: + SUB $256, R11, R11 + MOVWU R11, R11 + MOVD $0x0019, R16 + MOVH R16, (R1) + MOVH R11, 2(R1) + ADD $0x04, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm + +repeat_three_match_nolit_encodeBetterBlockAsm_emit_copy_short_2b: + SUB $4, R11, R11 + MOVWU R11, R11 + MOVD $0x0015, R16 + MOVH R16, (R1) + MOVB R11, 2(R1) + ADD $0x03, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm + +repeat_two_match_nolit_encodeBetterBlockAsm_emit_copy_short_2b: + LSLW $0x02, R11, R11 + ORRW $0x01, R11, R11 + MOVH R11, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm + +repeat_two_offset_match_nolit_encodeBetterBlockAsm_emit_copy_short_2b: + MOVD $0, R5 + ADD R11<<2, R5, R11 + ADD $1, R11, R11 + MOVWU R11, R11 + MOVB R7, 1(R1) + ASRW $0x08, R7, R7 + LSLW $0x05, R7, R7 + ORRW R7, R11, R11 + MOVB R11, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm + +long_offset_short_match_nolit_encodeBetterBlockAsm: + MOVD $0xee, R16 + MOVB R16, (R1) + MOVH R7, 1(R1) + SUB $60, R11, R11 + MOVWU R11, R11 + ADD $0x03, R1, R1 + + // emitRepeat +emit_repeat_again_match_nolit_encodeBetterBlockAsm_emit_copy_short: + MOVWU R11, R5 + SUB $4, R11, R11 + MOVWU R11, R11 + CMPW $0x08, R5 + BLS repeat_two_match_nolit_encodeBetterBlockAsm_emit_copy_short + CMPW $0x0c, R5 + BHS cant_repeat_two_offset_match_nolit_encodeBetterBlockAsm_emit_copy_short + CMPW $0x00000800, R7 + BLO repeat_two_offset_match_nolit_encodeBetterBlockAsm_emit_copy_short + +cant_repeat_two_offset_match_nolit_encodeBetterBlockAsm_emit_copy_short: + CMPW $0x00000104, R11 + BLO repeat_three_match_nolit_encodeBetterBlockAsm_emit_copy_short + CMPW $0x00010100, R11 + BLO repeat_four_match_nolit_encodeBetterBlockAsm_emit_copy_short + CMPW $0x0100ffff, R11 + BLO repeat_five_match_nolit_encodeBetterBlockAsm_emit_copy_short + SUB $16842747, R11, R11 + MOVWU R11, R11 + MOVD $0xfffb001d, R16 + MOVW R16, (R1) + MOVD $0xff, R16 + MOVB R16, 4(R1) + ADD $0x05, R1, R1 + JMP emit_repeat_again_match_nolit_encodeBetterBlockAsm_emit_copy_short + +repeat_five_match_nolit_encodeBetterBlockAsm_emit_copy_short: + SUB $65536, R11, R11 + MOVWU R11, R11 + MOVWU R11, R7 + MOVD $0x001d, R16 + MOVH R16, (R1) + MOVH R11, 2(R1) + ASRW $0x10, R7, R7 + MOVB R7, 4(R1) + ADD $0x05, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm + +repeat_four_match_nolit_encodeBetterBlockAsm_emit_copy_short: + SUB $256, R11, R11 + MOVWU R11, R11 + MOVD $0x0019, R16 + MOVH R16, (R1) + MOVH R11, 2(R1) + ADD $0x04, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm + +repeat_three_match_nolit_encodeBetterBlockAsm_emit_copy_short: + SUB $4, R11, R11 + MOVWU R11, R11 + MOVD $0x0015, R16 + MOVH R16, (R1) + MOVB R11, 2(R1) + ADD $0x03, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm + +repeat_two_match_nolit_encodeBetterBlockAsm_emit_copy_short: + LSLW $0x02, R11, R11 + ORRW $0x01, R11, R11 + MOVH R11, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm + +repeat_two_offset_match_nolit_encodeBetterBlockAsm_emit_copy_short: + MOVD $0, R5 + ADD R11<<2, R5, R11 + ADD $1, R11, R11 + MOVWU R11, R11 + MOVB R7, 1(R1) + ASRW $0x08, R7, R7 + LSLW $0x05, R7, R7 + ORRW R7, R11, R11 + MOVB R11, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm + +two_byte_offset_short_match_nolit_encodeBetterBlockAsm: + MOVWU R11, R5 + LSLW $0x02, R5, R5 + CMPW $0x0c, R11 + BHS emit_copy_three_match_nolit_encodeBetterBlockAsm + CMPW $0x00000800, R7 + BHS emit_copy_three_match_nolit_encodeBetterBlockAsm + SUB $15, R5, R5 + MOVWU R5, R5 + MOVB R7, 1(R1) + LSRW $0x08, R7, R7 + LSLW $0x05, R7, R7 + ORRW R7, R5, R5 + MOVB R5, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm + +emit_copy_three_match_nolit_encodeBetterBlockAsm: + SUB $2, R5, R5 + MOVWU R5, R5 + MOVB R5, (R1) + MOVH R7, 1(R1) + ADD $0x03, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm + +match_is_repeat_encodeBetterBlockAsm: + MOVWU 20(RSP), R5 + CMPW R6, R5 + BEQ emit_literal_done_match_emit_repeat_encodeBetterBlockAsm + MOVWU R6, R8 + MOVW R6, 20(RSP) + ADD R5, R3, R9 + SUBW R5, R8, R8 + SUB $1, R8, R5 + MOVWU R5, R5 + CMPW $0x3c, R5 + BLO one_byte_match_emit_repeat_encodeBetterBlockAsm + CMPW $0x00000100, R5 + BLO two_bytes_match_emit_repeat_encodeBetterBlockAsm + CMPW $0x00010000, R5 + BLO three_bytes_match_emit_repeat_encodeBetterBlockAsm + CMPW $0x01000000, R5 + BLO four_bytes_match_emit_repeat_encodeBetterBlockAsm + MOVD $0xfc, R16 + MOVB R16, (R1) + MOVW R5, 1(R1) + ADD $0x05, R1, R1 + JMP memmove_long_match_emit_repeat_encodeBetterBlockAsm + +four_bytes_match_emit_repeat_encodeBetterBlockAsm: + MOVWU R5, R10 + LSRW $0x10, R10, R10 + MOVD $0xf8, R16 + MOVB R16, (R1) + MOVH R5, 1(R1) + MOVB R10, 3(R1) + ADD $0x04, R1, R1 + JMP memmove_long_match_emit_repeat_encodeBetterBlockAsm + +three_bytes_match_emit_repeat_encodeBetterBlockAsm: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R5, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_match_emit_repeat_encodeBetterBlockAsm + +two_bytes_match_emit_repeat_encodeBetterBlockAsm: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R5, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R5 + BLO memmove_match_emit_repeat_encodeBetterBlockAsm + JMP memmove_long_match_emit_repeat_encodeBetterBlockAsm + +one_byte_match_emit_repeat_encodeBetterBlockAsm: + LSLW $0x02, R5, R16 + BFI $0, R16, $8, R5 + MOVB R5, (R1) + ADD $0x01, R1, R1 + +memmove_match_emit_repeat_encodeBetterBlockAsm: + ADD R8, R1, R5 + + // genMemMoveShort + CMP $0x04, R8 + BLS emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm_memmove_move_4 + CMP $0x08, R8 + BLO emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm_memmove_move_4through7 + CMP $0x10, R8 + BLS emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm_memmove_move_8through16 + CMP $0x20, R8 + BLS emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm_memmove_move_17through32 + JMP emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm_memmove_move_33through64 + +emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm_memmove_move_4: + MOVWU (R9), R10 + MOVW R10, (R1) + JMP memmove_end_copy_match_emit_repeat_encodeBetterBlockAsm + +emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm_memmove_move_4through7: + MOVWU (R9), R10 + ADD R8, R9, R15 + MOVWU -4(R15), R9 + MOVW R10, (R1) + ADD R8, R1, R15 + MOVW R9, -4(R15) + JMP memmove_end_copy_match_emit_repeat_encodeBetterBlockAsm + +emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm_memmove_move_8through16: + MOVD (R9), R10 + ADD R8, R9, R15 + MOVD -8(R15), R9 + MOVD R10, (R1) + ADD R8, R1, R15 + MOVD R9, -8(R15) + JMP memmove_end_copy_match_emit_repeat_encodeBetterBlockAsm + +emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm_memmove_move_17through32: + FMOVQ (R9), F0 + ADD R8, R9, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_match_emit_repeat_encodeBetterBlockAsm + +emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm_memmove_move_33through64: + FMOVQ (R9), F0 + FMOVQ 16(R9), F1 + ADD R8, R9, R15 + FMOVQ -32(R15), F2 + ADD R8, R9, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R8, R1, R15 + FMOVQ F2, -32(R15) + ADD R8, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_match_emit_repeat_encodeBetterBlockAsm: + MOVD R5, R1 + JMP emit_literal_done_match_emit_repeat_encodeBetterBlockAsm + +memmove_long_match_emit_repeat_encodeBetterBlockAsm: + ADD R8, R1, R5 + + // genMemMoveLong + MOVD R9, R10 + MOVD R1, R12 + MOVD R8, R13 + +emit_lit_memmove_long_match_emit_repeat_encodeBetterBlockAsmlarge_big_loop_back: + FMOVQ (R10), F0 + FMOVQ 16(R10), F1 + FMOVQ F0, (R12) + FMOVQ F1, 16(R12) + ADD $0x20, R10, R10 + ADD $0x20, R12, R12 + SUB $0x20, R13, R13 + CMP $0x20, R13 + BHS emit_lit_memmove_long_match_emit_repeat_encodeBetterBlockAsmlarge_big_loop_back + ADD R8, R9, R15 + FMOVQ -32(R15), F0 + ADD R8, R9, R15 + FMOVQ -16(R15), F1 + ADD R8, R1, R15 + FMOVQ F0, -32(R15) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + MOVD R5, R1 + +emit_literal_done_match_emit_repeat_encodeBetterBlockAsm: + ADDW R11, R2, R2 + ADDW $0x04, R11, R11 + MOVW R2, 20(RSP) + + // emitRepeat +emit_repeat_again_match_nolit_repeat_encodeBetterBlockAsm: + MOVWU R11, R5 + SUB $4, R11, R11 + MOVWU R11, R11 + CMPW $0x08, R5 + BLS repeat_two_match_nolit_repeat_encodeBetterBlockAsm + CMPW $0x0c, R5 + BHS cant_repeat_two_offset_match_nolit_repeat_encodeBetterBlockAsm + CMPW $0x00000800, R7 + BLO repeat_two_offset_match_nolit_repeat_encodeBetterBlockAsm + +cant_repeat_two_offset_match_nolit_repeat_encodeBetterBlockAsm: + CMPW $0x00000104, R11 + BLO repeat_three_match_nolit_repeat_encodeBetterBlockAsm + CMPW $0x00010100, R11 + BLO repeat_four_match_nolit_repeat_encodeBetterBlockAsm + CMPW $0x0100ffff, R11 + BLO repeat_five_match_nolit_repeat_encodeBetterBlockAsm + SUB $16842747, R11, R11 + MOVWU R11, R11 + MOVD $0xfffb001d, R16 + MOVW R16, (R1) + MOVD $0xff, R16 + MOVB R16, 4(R1) + ADD $0x05, R1, R1 + JMP emit_repeat_again_match_nolit_repeat_encodeBetterBlockAsm + +repeat_five_match_nolit_repeat_encodeBetterBlockAsm: + SUB $65536, R11, R11 + MOVWU R11, R11 + MOVWU R11, R7 + MOVD $0x001d, R16 + MOVH R16, (R1) + MOVH R11, 2(R1) + ASRW $0x10, R7, R7 + MOVB R7, 4(R1) + ADD $0x05, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm + +repeat_four_match_nolit_repeat_encodeBetterBlockAsm: + SUB $256, R11, R11 + MOVWU R11, R11 + MOVD $0x0019, R16 + MOVH R16, (R1) + MOVH R11, 2(R1) + ADD $0x04, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm + +repeat_three_match_nolit_repeat_encodeBetterBlockAsm: + SUB $4, R11, R11 + MOVWU R11, R11 + MOVD $0x0015, R16 + MOVH R16, (R1) + MOVB R11, 2(R1) + ADD $0x03, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm + +repeat_two_match_nolit_repeat_encodeBetterBlockAsm: + LSLW $0x02, R11, R11 + ORRW $0x01, R11, R11 + MOVH R11, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm + +repeat_two_offset_match_nolit_repeat_encodeBetterBlockAsm: + MOVD $0, R5 + ADD R11<<2, R5, R11 + ADD $1, R11, R11 + MOVWU R11, R11 + MOVB R7, 1(R1) + ASRW $0x08, R7, R7 + LSLW $0x05, R7, R7 + ORRW R7, R11, R11 + MOVB R11, (R1) + ADD $0x02, R1, R1 + +match_nolit_emitcopy_end_encodeBetterBlockAsm: + MOVWU 16(RSP), R16 + CMPW R16, R2 + BHS emit_remainder_encodeBetterBlockAsm + MOVD 8(RSP), R16 + CMP R16, R1 + BLO match_nolit_dst_ok_encodeBetterBlockAsm + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +match_nolit_dst_ok_encodeBetterBlockAsm: + MOVD $0x00cf1bbcdcbfa563, R5 + MOVD $0x9e3779b1, R7 + ADD $1, R6, R6 + SUB $2, R2, R8 + MOVD (R3)(R6), R9 + ADD R6, R3, R15 + MOVD 1(R15), R10 + MOVD (R3)(R8), R11 + ADD R8, R3, R15 + MOVD 1(R15), R12 + LSL $0x08, R9, R9 + MUL R5, R9, R9 + LSR $0x2f, R9, R9 + LSL $0x20, R10, R10 + MUL R7, R10, R10 + LSR $0x32, R10, R10 + LSL $0x08, R11, R11 + MUL R5, R11, R11 + LSR $0x2f, R11, R11 + LSL $0x20, R12, R12 + MUL R7, R12, R12 + LSR $0x32, R12, R12 + ADD $1, R6, R7 + ADD $1, R8, R13 + MOVW R6, (R0)(R9<<2) + MOVW R8, (R0)(R11<<2) + ADD R10<<2, R0, R15 + MOVW R7, 524288(R15) + ADD R12<<2, R0, R15 + MOVW R13, 524288(R15) + ADD R6, R8, R7 + ADD $1, R7, R7 + LSR $0x01, R7, R7 + ADD $0x01, R6, R6 + SUB $0x01, R8, R8 + +index_loop_encodeBetterBlockAsm: + CMP R8, R7 + BHS search_loop_encodeBetterBlockAsm + MOVD (R3)(R6), R9 + MOVD (R3)(R7), R10 + LSL $0x08, R9, R9 + MUL R5, R9, R9 + LSR $0x2f, R9, R9 + LSL $0x08, R10, R10 + MUL R5, R10, R10 + LSR $0x2f, R10, R10 + MOVW R6, (R0)(R9<<2) + MOVW R7, (R0)(R10<<2) + ADD $0x02, R6, R6 + ADD $0x02, R7, R7 + JMP index_loop_encodeBetterBlockAsm + +emit_remainder_encodeBetterBlockAsm: + MOVD src_len+32(FP), R0 + MOVWU 20(RSP), R16 + SUBW R16, R0, R0 + ADD R0, R1, R0 + ADD $5, R0, R0 + MOVD 8(RSP), R16 + CMP R16, R0 + BLO emit_remainder_ok_encodeBetterBlockAsm + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +emit_remainder_ok_encodeBetterBlockAsm: + MOVD src_len+32(FP), R0 + MOVWU 20(RSP), R2 + CMPW R0, R2 + BEQ emit_literal_done_emit_remainder_encodeBetterBlockAsm + MOVWU R0, R5 + MOVW R0, 20(RSP) + ADD R2, R3, R0 + SUBW R2, R5, R5 + SUB $1, R5, R2 + MOVWU R2, R2 + CMPW $0x3c, R2 + BLO one_byte_emit_remainder_encodeBetterBlockAsm + CMPW $0x00000100, R2 + BLO two_bytes_emit_remainder_encodeBetterBlockAsm + CMPW $0x00010000, R2 + BLO three_bytes_emit_remainder_encodeBetterBlockAsm + CMPW $0x01000000, R2 + BLO four_bytes_emit_remainder_encodeBetterBlockAsm + MOVD $0xfc, R16 + MOVB R16, (R1) + MOVW R2, 1(R1) + ADD $0x05, R1, R1 + JMP memmove_long_emit_remainder_encodeBetterBlockAsm + +four_bytes_emit_remainder_encodeBetterBlockAsm: + MOVWU R2, R3 + LSRW $0x10, R3, R3 + MOVD $0xf8, R16 + MOVB R16, (R1) + MOVH R2, 1(R1) + MOVB R3, 3(R1) + ADD $0x04, R1, R1 + JMP memmove_long_emit_remainder_encodeBetterBlockAsm + +three_bytes_emit_remainder_encodeBetterBlockAsm: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R2, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_emit_remainder_encodeBetterBlockAsm + +two_bytes_emit_remainder_encodeBetterBlockAsm: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R2, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R2 + BLO memmove_emit_remainder_encodeBetterBlockAsm + JMP memmove_long_emit_remainder_encodeBetterBlockAsm + +one_byte_emit_remainder_encodeBetterBlockAsm: + LSLW $0x02, R2, R16 + BFI $0, R16, $8, R2 + MOVB R2, (R1) + ADD $0x01, R1, R1 + +memmove_emit_remainder_encodeBetterBlockAsm: + ADD R5, R1, R2 + MOVWU R5, R3 + + // genMemMoveShort + CMP $0x03, R3 + BLO emit_lit_memmove_emit_remainder_encodeBetterBlockAsm_memmove_move_1or2 + BEQ emit_lit_memmove_emit_remainder_encodeBetterBlockAsm_memmove_move_3 + CMP $0x08, R3 + BLO emit_lit_memmove_emit_remainder_encodeBetterBlockAsm_memmove_move_4through7 + CMP $0x10, R3 + BLS emit_lit_memmove_emit_remainder_encodeBetterBlockAsm_memmove_move_8through16 + CMP $0x20, R3 + BLS emit_lit_memmove_emit_remainder_encodeBetterBlockAsm_memmove_move_17through32 + JMP emit_lit_memmove_emit_remainder_encodeBetterBlockAsm_memmove_move_33through64 + +emit_lit_memmove_emit_remainder_encodeBetterBlockAsm_memmove_move_1or2: + MOVBU (R0), R16 + BFI $0, R16, $8, R5 + ADD R3, R0, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R0 + MOVB R5, (R1) + ADD R3, R1, R15 + MOVB R0, -1(R15) + JMP memmove_end_copy_emit_remainder_encodeBetterBlockAsm + +emit_lit_memmove_emit_remainder_encodeBetterBlockAsm_memmove_move_3: + MOVHU (R0), R16 + BFI $0, R16, $16, R5 + MOVBU 2(R0), R16 + BFI $0, R16, $8, R0 + MOVH R5, (R1) + MOVB R0, 2(R1) + JMP memmove_end_copy_emit_remainder_encodeBetterBlockAsm + +emit_lit_memmove_emit_remainder_encodeBetterBlockAsm_memmove_move_4through7: + MOVWU (R0), R5 + ADD R3, R0, R15 + MOVWU -4(R15), R0 + MOVW R5, (R1) + ADD R3, R1, R15 + MOVW R0, -4(R15) + JMP memmove_end_copy_emit_remainder_encodeBetterBlockAsm + +emit_lit_memmove_emit_remainder_encodeBetterBlockAsm_memmove_move_8through16: + MOVD (R0), R5 + ADD R3, R0, R15 + MOVD -8(R15), R0 + MOVD R5, (R1) + ADD R3, R1, R15 + MOVD R0, -8(R15) + JMP memmove_end_copy_emit_remainder_encodeBetterBlockAsm + +emit_lit_memmove_emit_remainder_encodeBetterBlockAsm_memmove_move_17through32: + FMOVQ (R0), F0 + ADD R3, R0, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R3, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_emit_remainder_encodeBetterBlockAsm + +emit_lit_memmove_emit_remainder_encodeBetterBlockAsm_memmove_move_33through64: + FMOVQ (R0), F0 + FMOVQ 16(R0), F1 + ADD R3, R0, R15 + FMOVQ -32(R15), F2 + ADD R3, R0, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R3, R1, R15 + FMOVQ F2, -32(R15) + ADD R3, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_emit_remainder_encodeBetterBlockAsm: + MOVD R2, R1 + JMP emit_literal_done_emit_remainder_encodeBetterBlockAsm + +memmove_long_emit_remainder_encodeBetterBlockAsm: + ADD R5, R1, R2 + MOVWU R5, R3 + + // genMemMoveLong + MOVD R0, R5 + MOVD R1, R6 + MOVD R3, R7 + +emit_lit_memmove_long_emit_remainder_encodeBetterBlockAsmlarge_big_loop_back: + FMOVQ (R5), F0 + FMOVQ 16(R5), F1 + FMOVQ F0, (R6) + FMOVQ F1, 16(R6) + ADD $0x20, R5, R5 + ADD $0x20, R6, R6 + SUB $0x20, R7, R7 + CMP $0x20, R7 + BHS emit_lit_memmove_long_emit_remainder_encodeBetterBlockAsmlarge_big_loop_back + ADD R3, R0, R15 + FMOVQ -32(R15), F0 + ADD R3, R0, R15 + FMOVQ -16(R15), F1 + ADD R3, R1, R15 + FMOVQ F0, -32(R15) + ADD R3, R1, R15 + FMOVQ F1, -16(R15) + MOVD R2, R1 + +emit_literal_done_emit_remainder_encodeBetterBlockAsm: + MOVD dst_base+0(FP), R0 + SUB R0, R1, R1 + MOVD R1, ret+56(FP) + RET + +// func encodeBetterBlockAsm4MB(dst []byte, src []byte, tmp *[589824]byte) int +// Requires: BMI, SSE2 +TEXT ·encodeBetterBlockAsm4MB(SB), $24-64 + MOVD tmp+48(FP), R0 + MOVD dst_base+0(FP), R1 + MOVD $0x00001200, R2 + MOVD R0, R3 + VEOR V0.B16, V0.B16, V0.B16 + +zero_loop_encodeBetterBlockAsm4MB: + FMOVQ F0, (R3) + FMOVQ F0, 16(R3) + FMOVQ F0, 32(R3) + FMOVQ F0, 48(R3) + FMOVQ F0, 64(R3) + FMOVQ F0, 80(R3) + FMOVQ F0, 96(R3) + FMOVQ F0, 112(R3) + ADD $0x80, R3, R3 + SUBS $1, R2, R2 + BNE zero_loop_encodeBetterBlockAsm4MB + MOVD $0x00000000, R16 + MOVW R16, 20(RSP) + MOVD src_len+32(FP), R2 + SUB $6, R2, R3 + SUB $8, R2, R5 + MOVW R5, 16(RSP) + LSR $0x05, R2, R2 + SUBW R2, R3, R3 + ADD R3, R1, R3 + MOVD R3, 8(RSP) + MOVD $0x00000001, R2 + MOVD $0x00000000, R16 + MOVW R16, 24(RSP) + MOVD src_base+24(FP), R3 + +search_loop_encodeBetterBlockAsm4MB: + MOVWU R2, R5 + MOVWU 20(RSP), R16 + SUBW R16, R5, R5 + LSRW $0x07, R5, R5 + CMPW $0x63, R5 + BLS check_maxskip_ok_encodeBetterBlockAsm4MB + ADD $100, R2, R5 + MOVWU R5, R5 + JMP check_maxskip_cont_encodeBetterBlockAsm4MB + +check_maxskip_ok_encodeBetterBlockAsm4MB: + ADD R5, R2, R5 + ADD $1, R5, R5 + MOVWU R5, R5 + +check_maxskip_cont_encodeBetterBlockAsm4MB: + MOVWU 16(RSP), R16 + CMPW R16, R5 + BHS emit_remainder_encodeBetterBlockAsm4MB + MOVD (R3)(R2), R6 + MOVW R5, 28(RSP) + MOVD $0x00cf1bbcdcbfa563, R8 + MOVD $0x9e3779b1, R5 + MOVD R6, R9 + MOVD R6, R10 + LSL $0x08, R9, R9 + MUL R8, R9, R9 + LSR $0x2f, R9, R9 + LSL $0x20, R10, R10 + MUL R5, R10, R10 + LSR $0x32, R10, R10 + MOVWU (R0)(R9<<2), R5 + ADD R10<<2, R0, R15 + MOVWU 524288(R15), R7 + MOVW R2, (R0)(R9<<2) + ADD R10<<2, R0, R15 + MOVW R2, 524288(R15) + MOVD (R3)(R5), R9 + MOVD (R3)(R7), R10 + CMP R6, R9 + BEQ candidate_match_encodeBetterBlockAsm4MB + CMP R6, R10 + BNE no_short_found_encodeBetterBlockAsm4MB + MOVWU R7, R5 + JMP candidate_match_encodeBetterBlockAsm4MB + +no_short_found_encodeBetterBlockAsm4MB: + CMPW R6, R9 + BEQ candidate_match_encodeBetterBlockAsm4MB + CMPW R6, R10 + BEQ candidateS_match_encodeBetterBlockAsm4MB + MOVWU 28(RSP), R2 + JMP search_loop_encodeBetterBlockAsm4MB + +candidateS_match_encodeBetterBlockAsm4MB: + LSR $0x08, R6, R6 + MOVD R6, R9 + LSL $0x08, R9, R9 + MUL R8, R9, R9 + LSR $0x2f, R9, R9 + MOVWU (R0)(R9<<2), R5 + ADDW $1, R2, R2 + MOVW R2, (R0)(R9<<2) + MOVWU (R3)(R5), R16 + CMPW R6, R16 + BEQ candidate_match_encodeBetterBlockAsm4MB + SUBW $1, R2, R2 + MOVWU R7, R5 + +candidate_match_encodeBetterBlockAsm4MB: + MOVWU 20(RSP), R6 + TSTW R5, R5 + BEQ match_extend_back_end_encodeBetterBlockAsm4MB + +match_extend_back_loop_encodeBetterBlockAsm4MB: + CMPW R6, R2 + BLS match_extend_back_end_encodeBetterBlockAsm4MB + ADD R5, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R7 + ADD R2, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R8 + AND $0xff, R8, R16 + AND $0xff, R7, R15 + CMP R16, R15 + BNE match_extend_back_end_encodeBetterBlockAsm4MB + SUB $1, R2, R2 + MOVWU R2, R2 + SUBSW $1, R5, R5 + BEQ match_extend_back_end_encodeBetterBlockAsm4MB + JMP match_extend_back_loop_encodeBetterBlockAsm4MB + +match_extend_back_end_encodeBetterBlockAsm4MB: + MOVWU R2, R6 + MOVWU 20(RSP), R16 + SUBW R16, R6, R6 + ADD R6, R1, R6 + ADD $4, R6, R6 + MOVD 8(RSP), R16 + CMP R16, R6 + BLO match_dst_size_check_encodeBetterBlockAsm4MB + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +match_dst_size_check_encodeBetterBlockAsm4MB: + MOVWU R2, R6 + ADDW $0x04, R2, R2 + ADDW $0x04, R5, R5 + MOVD src_len+32(FP), R7 + SUBW R2, R7, R7 + ADD R2, R3, R8 + ADD R5, R3, R9 + + // matchLen + MOVD $0, R11 + +matchlen_loopback_16_match_nolit_encodeBetterBlockAsm4MB: + CMPW $0x10, R7 + BLO matchlen_match8_match_nolit_encodeBetterBlockAsm4MB + MOVD (R8)(R11), R10 + ADD R11, R8, R15 + MOVD 8(R15), R12 + MOVD (R9)(R11), R16 + EOR R16, R10, R10 + TST R10, R10 + BNE matchlen_bsf_8_match_nolit_encodeBetterBlockAsm4MB + ADD R11, R9, R15 + MOVD 8(R15), R16 + EOR R16, R12, R12 + TST R12, R12 + BNE matchlen_bsf_16match_nolit_encodeBetterBlockAsm4MB + SUB $16, R7, R7 + MOVWU R7, R7 + ADD $16, R11, R11 + MOVWU R11, R11 + JMP matchlen_loopback_16_match_nolit_encodeBetterBlockAsm4MB + +matchlen_bsf_16match_nolit_encodeBetterBlockAsm4MB: + RBIT R12, R12 + CLZ R12, R12 + ASR $0x03, R12, R12 + ADD R12, R11, R11 + ADD $8, R11, R11 + MOVWU R11, R11 + JMP match_nolit_end_encodeBetterBlockAsm4MB + +matchlen_match8_match_nolit_encodeBetterBlockAsm4MB: + CMPW $0x08, R7 + BLO matchlen_match4_match_nolit_encodeBetterBlockAsm4MB + MOVD (R8)(R11), R10 + MOVD (R9)(R11), R16 + EOR R16, R10, R10 + TST R10, R10 + BNE matchlen_bsf_8_match_nolit_encodeBetterBlockAsm4MB + SUB $8, R7, R7 + MOVWU R7, R7 + ADD $8, R11, R11 + MOVWU R11, R11 + JMP matchlen_match4_match_nolit_encodeBetterBlockAsm4MB + +matchlen_bsf_8_match_nolit_encodeBetterBlockAsm4MB: + RBIT R10, R10 + CLZ R10, R10 + ASR $0x03, R10, R10 + ADD R10, R11, R11 + MOVWU R11, R11 + JMP match_nolit_end_encodeBetterBlockAsm4MB + +matchlen_match4_match_nolit_encodeBetterBlockAsm4MB: + CMPW $0x04, R7 + BLO matchlen_match2_match_nolit_encodeBetterBlockAsm4MB + MOVWU (R8)(R11), R10 + MOVWU (R9)(R11), R16 + CMPW R10, R16 + BNE matchlen_match2_match_nolit_encodeBetterBlockAsm4MB + SUB $4, R7, R7 + MOVWU R7, R7 + ADD $4, R11, R11 + MOVWU R11, R11 + +matchlen_match2_match_nolit_encodeBetterBlockAsm4MB: + CMPW $0x01, R7 + BEQ matchlen_match1_match_nolit_encodeBetterBlockAsm4MB + BLO match_nolit_end_encodeBetterBlockAsm4MB + MOVHU (R8)(R11), R16 + BFI $0, R16, $16, R10 + ADD R11, R9, R15 + MOVHU (R15), R15 + AND $0xffff, R10, R16 + CMP R16, R15 + BNE matchlen_match1_match_nolit_encodeBetterBlockAsm4MB + ADD $2, R11, R11 + MOVWU R11, R11 + SUBSW $0x02, R7, R7 + BEQ match_nolit_end_encodeBetterBlockAsm4MB + +matchlen_match1_match_nolit_encodeBetterBlockAsm4MB: + MOVBU (R8)(R11), R16 + BFI $0, R16, $8, R10 + ADD R11, R9, R15 + MOVBU (R15), R15 + AND $0xff, R10, R16 + CMP R16, R15 + BNE match_nolit_end_encodeBetterBlockAsm4MB + ADD $1, R11, R11 + MOVWU R11, R11 + +match_nolit_end_encodeBetterBlockAsm4MB: + MOVWU R2, R7 + SUBW R5, R7, R7 + + // Check if repeat + MOVWU 24(RSP), R16 + CMPW R7, R16 + BEQ match_is_repeat_encodeBetterBlockAsm4MB + CMPW $0x01, R11 + BHI match_length_ok_encodeBetterBlockAsm4MB + CMPW $0x0000ffff, R7 + BLS match_length_ok_encodeBetterBlockAsm4MB + MOVWU 28(RSP), R2 + ADDW $1, R2, R2 + JMP search_loop_encodeBetterBlockAsm4MB + +match_length_ok_encodeBetterBlockAsm4MB: + MOVW R7, 24(RSP) + MOVWU 20(RSP), R5 + CMPW R6, R5 + BEQ emit_literal_done_match_emit_encodeBetterBlockAsm4MB + MOVWU R6, R8 + MOVW R6, 20(RSP) + ADD R5, R3, R9 + SUBW R5, R8, R8 + SUB $1, R8, R5 + MOVWU R5, R5 + CMPW $0x3c, R5 + BLO one_byte_match_emit_encodeBetterBlockAsm4MB + CMPW $0x00000100, R5 + BLO two_bytes_match_emit_encodeBetterBlockAsm4MB + CMPW $0x00010000, R5 + BLO three_bytes_match_emit_encodeBetterBlockAsm4MB + MOVWU R5, R10 + LSRW $0x10, R10, R10 + MOVD $0xf8, R16 + MOVB R16, (R1) + MOVH R5, 1(R1) + MOVB R10, 3(R1) + ADD $0x04, R1, R1 + JMP memmove_long_match_emit_encodeBetterBlockAsm4MB + +three_bytes_match_emit_encodeBetterBlockAsm4MB: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R5, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_match_emit_encodeBetterBlockAsm4MB + +two_bytes_match_emit_encodeBetterBlockAsm4MB: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R5, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R5 + BLO memmove_match_emit_encodeBetterBlockAsm4MB + JMP memmove_long_match_emit_encodeBetterBlockAsm4MB + +one_byte_match_emit_encodeBetterBlockAsm4MB: + LSLW $0x02, R5, R16 + BFI $0, R16, $8, R5 + MOVB R5, (R1) + ADD $0x01, R1, R1 + +memmove_match_emit_encodeBetterBlockAsm4MB: + ADD R8, R1, R5 + + // genMemMoveShort + CMP $0x04, R8 + BLS emit_lit_memmove_match_emit_encodeBetterBlockAsm4MB_memmove_move_4 + CMP $0x08, R8 + BLO emit_lit_memmove_match_emit_encodeBetterBlockAsm4MB_memmove_move_4through7 + CMP $0x10, R8 + BLS emit_lit_memmove_match_emit_encodeBetterBlockAsm4MB_memmove_move_8through16 + CMP $0x20, R8 + BLS emit_lit_memmove_match_emit_encodeBetterBlockAsm4MB_memmove_move_17through32 + JMP emit_lit_memmove_match_emit_encodeBetterBlockAsm4MB_memmove_move_33through64 + +emit_lit_memmove_match_emit_encodeBetterBlockAsm4MB_memmove_move_4: + MOVWU (R9), R10 + MOVW R10, (R1) + JMP memmove_end_copy_match_emit_encodeBetterBlockAsm4MB + +emit_lit_memmove_match_emit_encodeBetterBlockAsm4MB_memmove_move_4through7: + MOVWU (R9), R10 + ADD R8, R9, R15 + MOVWU -4(R15), R9 + MOVW R10, (R1) + ADD R8, R1, R15 + MOVW R9, -4(R15) + JMP memmove_end_copy_match_emit_encodeBetterBlockAsm4MB + +emit_lit_memmove_match_emit_encodeBetterBlockAsm4MB_memmove_move_8through16: + MOVD (R9), R10 + ADD R8, R9, R15 + MOVD -8(R15), R9 + MOVD R10, (R1) + ADD R8, R1, R15 + MOVD R9, -8(R15) + JMP memmove_end_copy_match_emit_encodeBetterBlockAsm4MB + +emit_lit_memmove_match_emit_encodeBetterBlockAsm4MB_memmove_move_17through32: + FMOVQ (R9), F0 + ADD R8, R9, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_match_emit_encodeBetterBlockAsm4MB + +emit_lit_memmove_match_emit_encodeBetterBlockAsm4MB_memmove_move_33through64: + FMOVQ (R9), F0 + FMOVQ 16(R9), F1 + ADD R8, R9, R15 + FMOVQ -32(R15), F2 + ADD R8, R9, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R8, R1, R15 + FMOVQ F2, -32(R15) + ADD R8, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_match_emit_encodeBetterBlockAsm4MB: + MOVD R5, R1 + JMP emit_literal_done_match_emit_encodeBetterBlockAsm4MB + +memmove_long_match_emit_encodeBetterBlockAsm4MB: + ADD R8, R1, R5 + + // genMemMoveLong + MOVD R9, R10 + MOVD R1, R12 + MOVD R8, R13 + +emit_lit_memmove_long_match_emit_encodeBetterBlockAsm4MBlarge_big_loop_back: + FMOVQ (R10), F0 + FMOVQ 16(R10), F1 + FMOVQ F0, (R12) + FMOVQ F1, 16(R12) + ADD $0x20, R10, R10 + ADD $0x20, R12, R12 + SUB $0x20, R13, R13 + CMP $0x20, R13 + BHS emit_lit_memmove_long_match_emit_encodeBetterBlockAsm4MBlarge_big_loop_back + ADD R8, R9, R15 + FMOVQ -32(R15), F0 + ADD R8, R9, R15 + FMOVQ -16(R15), F1 + ADD R8, R1, R15 + FMOVQ F0, -32(R15) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + MOVD R5, R1 + +emit_literal_done_match_emit_encodeBetterBlockAsm4MB: + ADDW R11, R2, R2 + ADDW $0x04, R11, R11 + MOVW R2, 20(RSP) + + // emitCopy + CMPW $0x00010000, R7 + BLO two_byte_offset_match_nolit_encodeBetterBlockAsm4MB + CMPW $0x40, R11 + BLS four_bytes_remain_match_nolit_encodeBetterBlockAsm4MB + MOVD $0xff, R16 + MOVB R16, (R1) + MOVW R7, 1(R1) + SUB $64, R11, R11 + MOVWU R11, R11 + ADD $0x05, R1, R1 + CMPW $0x04, R11 + BLO four_bytes_remain_match_nolit_encodeBetterBlockAsm4MB + + // emitRepeat + MOVWU R11, R5 + SUB $4, R11, R11 + MOVWU R11, R11 + CMPW $0x08, R5 + BLS repeat_two_match_nolit_encodeBetterBlockAsm4MB_emit_copy + CMPW $0x0c, R5 + BHS cant_repeat_two_offset_match_nolit_encodeBetterBlockAsm4MB_emit_copy + CMPW $0x00000800, R7 + BLO repeat_two_offset_match_nolit_encodeBetterBlockAsm4MB_emit_copy + +cant_repeat_two_offset_match_nolit_encodeBetterBlockAsm4MB_emit_copy: + CMPW $0x00000104, R11 + BLO repeat_three_match_nolit_encodeBetterBlockAsm4MB_emit_copy + CMPW $0x00010100, R11 + BLO repeat_four_match_nolit_encodeBetterBlockAsm4MB_emit_copy + SUB $65536, R11, R11 + MOVWU R11, R11 + MOVWU R11, R7 + MOVD $0x001d, R16 + MOVH R16, (R1) + MOVH R11, 2(R1) + ASRW $0x10, R7, R7 + MOVB R7, 4(R1) + ADD $0x05, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm4MB + +repeat_four_match_nolit_encodeBetterBlockAsm4MB_emit_copy: + SUB $256, R11, R11 + MOVWU R11, R11 + MOVD $0x0019, R16 + MOVH R16, (R1) + MOVH R11, 2(R1) + ADD $0x04, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm4MB + +repeat_three_match_nolit_encodeBetterBlockAsm4MB_emit_copy: + SUB $4, R11, R11 + MOVWU R11, R11 + MOVD $0x0015, R16 + MOVH R16, (R1) + MOVB R11, 2(R1) + ADD $0x03, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm4MB + +repeat_two_match_nolit_encodeBetterBlockAsm4MB_emit_copy: + LSLW $0x02, R11, R11 + ORRW $0x01, R11, R11 + MOVH R11, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm4MB + +repeat_two_offset_match_nolit_encodeBetterBlockAsm4MB_emit_copy: + MOVD $0, R5 + ADD R11<<2, R5, R11 + ADD $1, R11, R11 + MOVWU R11, R11 + MOVB R7, 1(R1) + ASRW $0x08, R7, R7 + LSLW $0x05, R7, R7 + ORRW R7, R11, R11 + MOVB R11, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm4MB + +four_bytes_remain_match_nolit_encodeBetterBlockAsm4MB: + TSTW R11, R11 + BEQ match_nolit_emitcopy_end_encodeBetterBlockAsm4MB + MOVD $0, R5 + ADD R11<<2, R5, R11 + SUB $1, R11, R11 + MOVWU R11, R11 + MOVB R11, (R1) + MOVW R7, 1(R1) + ADD $0x05, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm4MB + +two_byte_offset_match_nolit_encodeBetterBlockAsm4MB: + CMPW $0x40, R11 + BLS two_byte_offset_short_match_nolit_encodeBetterBlockAsm4MB + CMPW $0x00000800, R7 + BHS long_offset_short_match_nolit_encodeBetterBlockAsm4MB + MOVD $0x00000001, R5 + ADD $16, R5, R5 + MOVWU R5, R5 + MOVB R7, 1(R1) + LSRW $0x08, R7, R7 + LSLW $0x05, R7, R7 + ORRW R7, R5, R5 + MOVB R5, (R1) + ADD $0x02, R1, R1 + SUBW $0x08, R11, R11 + + // emitRepeat + SUB $4, R11, R11 + MOVWU R11, R11 + JMP cant_repeat_two_offset_match_nolit_encodeBetterBlockAsm4MB_emit_copy_short_2b + MOVWU R11, R5 + SUB $4, R11, R11 + MOVWU R11, R11 + CMPW $0x08, R5 + BLS repeat_two_match_nolit_encodeBetterBlockAsm4MB_emit_copy_short_2b + CMPW $0x0c, R5 + BHS cant_repeat_two_offset_match_nolit_encodeBetterBlockAsm4MB_emit_copy_short_2b + CMPW $0x00000800, R7 + BLO repeat_two_offset_match_nolit_encodeBetterBlockAsm4MB_emit_copy_short_2b + +cant_repeat_two_offset_match_nolit_encodeBetterBlockAsm4MB_emit_copy_short_2b: + CMPW $0x00000104, R11 + BLO repeat_three_match_nolit_encodeBetterBlockAsm4MB_emit_copy_short_2b + CMPW $0x00010100, R11 + BLO repeat_four_match_nolit_encodeBetterBlockAsm4MB_emit_copy_short_2b + SUB $65536, R11, R11 + MOVWU R11, R11 + MOVWU R11, R7 + MOVD $0x001d, R16 + MOVH R16, (R1) + MOVH R11, 2(R1) + ASRW $0x10, R7, R7 + MOVB R7, 4(R1) + ADD $0x05, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm4MB + +repeat_four_match_nolit_encodeBetterBlockAsm4MB_emit_copy_short_2b: + SUB $256, R11, R11 + MOVWU R11, R11 + MOVD $0x0019, R16 + MOVH R16, (R1) + MOVH R11, 2(R1) + ADD $0x04, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm4MB + +repeat_three_match_nolit_encodeBetterBlockAsm4MB_emit_copy_short_2b: + SUB $4, R11, R11 + MOVWU R11, R11 + MOVD $0x0015, R16 + MOVH R16, (R1) + MOVB R11, 2(R1) + ADD $0x03, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm4MB + +repeat_two_match_nolit_encodeBetterBlockAsm4MB_emit_copy_short_2b: + LSLW $0x02, R11, R11 + ORRW $0x01, R11, R11 + MOVH R11, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm4MB + +repeat_two_offset_match_nolit_encodeBetterBlockAsm4MB_emit_copy_short_2b: + MOVD $0, R5 + ADD R11<<2, R5, R11 + ADD $1, R11, R11 + MOVWU R11, R11 + MOVB R7, 1(R1) + ASRW $0x08, R7, R7 + LSLW $0x05, R7, R7 + ORRW R7, R11, R11 + MOVB R11, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm4MB + +long_offset_short_match_nolit_encodeBetterBlockAsm4MB: + MOVD $0xee, R16 + MOVB R16, (R1) + MOVH R7, 1(R1) + SUB $60, R11, R11 + MOVWU R11, R11 + ADD $0x03, R1, R1 + + // emitRepeat + MOVWU R11, R5 + SUB $4, R11, R11 + MOVWU R11, R11 + CMPW $0x08, R5 + BLS repeat_two_match_nolit_encodeBetterBlockAsm4MB_emit_copy_short + CMPW $0x0c, R5 + BHS cant_repeat_two_offset_match_nolit_encodeBetterBlockAsm4MB_emit_copy_short + CMPW $0x00000800, R7 + BLO repeat_two_offset_match_nolit_encodeBetterBlockAsm4MB_emit_copy_short + +cant_repeat_two_offset_match_nolit_encodeBetterBlockAsm4MB_emit_copy_short: + CMPW $0x00000104, R11 + BLO repeat_three_match_nolit_encodeBetterBlockAsm4MB_emit_copy_short + CMPW $0x00010100, R11 + BLO repeat_four_match_nolit_encodeBetterBlockAsm4MB_emit_copy_short + SUB $65536, R11, R11 + MOVWU R11, R11 + MOVWU R11, R7 + MOVD $0x001d, R16 + MOVH R16, (R1) + MOVH R11, 2(R1) + ASRW $0x10, R7, R7 + MOVB R7, 4(R1) + ADD $0x05, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm4MB + +repeat_four_match_nolit_encodeBetterBlockAsm4MB_emit_copy_short: + SUB $256, R11, R11 + MOVWU R11, R11 + MOVD $0x0019, R16 + MOVH R16, (R1) + MOVH R11, 2(R1) + ADD $0x04, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm4MB + +repeat_three_match_nolit_encodeBetterBlockAsm4MB_emit_copy_short: + SUB $4, R11, R11 + MOVWU R11, R11 + MOVD $0x0015, R16 + MOVH R16, (R1) + MOVB R11, 2(R1) + ADD $0x03, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm4MB + +repeat_two_match_nolit_encodeBetterBlockAsm4MB_emit_copy_short: + LSLW $0x02, R11, R11 + ORRW $0x01, R11, R11 + MOVH R11, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm4MB + +repeat_two_offset_match_nolit_encodeBetterBlockAsm4MB_emit_copy_short: + MOVD $0, R5 + ADD R11<<2, R5, R11 + ADD $1, R11, R11 + MOVWU R11, R11 + MOVB R7, 1(R1) + ASRW $0x08, R7, R7 + LSLW $0x05, R7, R7 + ORRW R7, R11, R11 + MOVB R11, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm4MB + +two_byte_offset_short_match_nolit_encodeBetterBlockAsm4MB: + MOVWU R11, R5 + LSLW $0x02, R5, R5 + CMPW $0x0c, R11 + BHS emit_copy_three_match_nolit_encodeBetterBlockAsm4MB + CMPW $0x00000800, R7 + BHS emit_copy_three_match_nolit_encodeBetterBlockAsm4MB + SUB $15, R5, R5 + MOVWU R5, R5 + MOVB R7, 1(R1) + LSRW $0x08, R7, R7 + LSLW $0x05, R7, R7 + ORRW R7, R5, R5 + MOVB R5, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm4MB + +emit_copy_three_match_nolit_encodeBetterBlockAsm4MB: + SUB $2, R5, R5 + MOVWU R5, R5 + MOVB R5, (R1) + MOVH R7, 1(R1) + ADD $0x03, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm4MB + +match_is_repeat_encodeBetterBlockAsm4MB: + MOVWU 20(RSP), R5 + CMPW R6, R5 + BEQ emit_literal_done_match_emit_repeat_encodeBetterBlockAsm4MB + MOVWU R6, R8 + MOVW R6, 20(RSP) + ADD R5, R3, R9 + SUBW R5, R8, R8 + SUB $1, R8, R5 + MOVWU R5, R5 + CMPW $0x3c, R5 + BLO one_byte_match_emit_repeat_encodeBetterBlockAsm4MB + CMPW $0x00000100, R5 + BLO two_bytes_match_emit_repeat_encodeBetterBlockAsm4MB + CMPW $0x00010000, R5 + BLO three_bytes_match_emit_repeat_encodeBetterBlockAsm4MB + MOVWU R5, R10 + LSRW $0x10, R10, R10 + MOVD $0xf8, R16 + MOVB R16, (R1) + MOVH R5, 1(R1) + MOVB R10, 3(R1) + ADD $0x04, R1, R1 + JMP memmove_long_match_emit_repeat_encodeBetterBlockAsm4MB + +three_bytes_match_emit_repeat_encodeBetterBlockAsm4MB: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R5, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_match_emit_repeat_encodeBetterBlockAsm4MB + +two_bytes_match_emit_repeat_encodeBetterBlockAsm4MB: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R5, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R5 + BLO memmove_match_emit_repeat_encodeBetterBlockAsm4MB + JMP memmove_long_match_emit_repeat_encodeBetterBlockAsm4MB + +one_byte_match_emit_repeat_encodeBetterBlockAsm4MB: + LSLW $0x02, R5, R16 + BFI $0, R16, $8, R5 + MOVB R5, (R1) + ADD $0x01, R1, R1 + +memmove_match_emit_repeat_encodeBetterBlockAsm4MB: + ADD R8, R1, R5 + + // genMemMoveShort + CMP $0x04, R8 + BLS emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm4MB_memmove_move_4 + CMP $0x08, R8 + BLO emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm4MB_memmove_move_4through7 + CMP $0x10, R8 + BLS emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm4MB_memmove_move_8through16 + CMP $0x20, R8 + BLS emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm4MB_memmove_move_17through32 + JMP emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm4MB_memmove_move_33through64 + +emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm4MB_memmove_move_4: + MOVWU (R9), R10 + MOVW R10, (R1) + JMP memmove_end_copy_match_emit_repeat_encodeBetterBlockAsm4MB + +emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm4MB_memmove_move_4through7: + MOVWU (R9), R10 + ADD R8, R9, R15 + MOVWU -4(R15), R9 + MOVW R10, (R1) + ADD R8, R1, R15 + MOVW R9, -4(R15) + JMP memmove_end_copy_match_emit_repeat_encodeBetterBlockAsm4MB + +emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm4MB_memmove_move_8through16: + MOVD (R9), R10 + ADD R8, R9, R15 + MOVD -8(R15), R9 + MOVD R10, (R1) + ADD R8, R1, R15 + MOVD R9, -8(R15) + JMP memmove_end_copy_match_emit_repeat_encodeBetterBlockAsm4MB + +emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm4MB_memmove_move_17through32: + FMOVQ (R9), F0 + ADD R8, R9, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_match_emit_repeat_encodeBetterBlockAsm4MB + +emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm4MB_memmove_move_33through64: + FMOVQ (R9), F0 + FMOVQ 16(R9), F1 + ADD R8, R9, R15 + FMOVQ -32(R15), F2 + ADD R8, R9, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R8, R1, R15 + FMOVQ F2, -32(R15) + ADD R8, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_match_emit_repeat_encodeBetterBlockAsm4MB: + MOVD R5, R1 + JMP emit_literal_done_match_emit_repeat_encodeBetterBlockAsm4MB + +memmove_long_match_emit_repeat_encodeBetterBlockAsm4MB: + ADD R8, R1, R5 + + // genMemMoveLong + MOVD R9, R10 + MOVD R1, R12 + MOVD R8, R13 + +emit_lit_memmove_long_match_emit_repeat_encodeBetterBlockAsm4MBlarge_big_loop_back: + FMOVQ (R10), F0 + FMOVQ 16(R10), F1 + FMOVQ F0, (R12) + FMOVQ F1, 16(R12) + ADD $0x20, R10, R10 + ADD $0x20, R12, R12 + SUB $0x20, R13, R13 + CMP $0x20, R13 + BHS emit_lit_memmove_long_match_emit_repeat_encodeBetterBlockAsm4MBlarge_big_loop_back + ADD R8, R9, R15 + FMOVQ -32(R15), F0 + ADD R8, R9, R15 + FMOVQ -16(R15), F1 + ADD R8, R1, R15 + FMOVQ F0, -32(R15) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + MOVD R5, R1 + +emit_literal_done_match_emit_repeat_encodeBetterBlockAsm4MB: + ADDW R11, R2, R2 + ADDW $0x04, R11, R11 + MOVW R2, 20(RSP) + + // emitRepeat + MOVWU R11, R5 + SUB $4, R11, R11 + MOVWU R11, R11 + CMPW $0x08, R5 + BLS repeat_two_match_nolit_repeat_encodeBetterBlockAsm4MB + CMPW $0x0c, R5 + BHS cant_repeat_two_offset_match_nolit_repeat_encodeBetterBlockAsm4MB + CMPW $0x00000800, R7 + BLO repeat_two_offset_match_nolit_repeat_encodeBetterBlockAsm4MB + +cant_repeat_two_offset_match_nolit_repeat_encodeBetterBlockAsm4MB: + CMPW $0x00000104, R11 + BLO repeat_three_match_nolit_repeat_encodeBetterBlockAsm4MB + CMPW $0x00010100, R11 + BLO repeat_four_match_nolit_repeat_encodeBetterBlockAsm4MB + SUB $65536, R11, R11 + MOVWU R11, R11 + MOVWU R11, R7 + MOVD $0x001d, R16 + MOVH R16, (R1) + MOVH R11, 2(R1) + ASRW $0x10, R7, R7 + MOVB R7, 4(R1) + ADD $0x05, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm4MB + +repeat_four_match_nolit_repeat_encodeBetterBlockAsm4MB: + SUB $256, R11, R11 + MOVWU R11, R11 + MOVD $0x0019, R16 + MOVH R16, (R1) + MOVH R11, 2(R1) + ADD $0x04, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm4MB + +repeat_three_match_nolit_repeat_encodeBetterBlockAsm4MB: + SUB $4, R11, R11 + MOVWU R11, R11 + MOVD $0x0015, R16 + MOVH R16, (R1) + MOVB R11, 2(R1) + ADD $0x03, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm4MB + +repeat_two_match_nolit_repeat_encodeBetterBlockAsm4MB: + LSLW $0x02, R11, R11 + ORRW $0x01, R11, R11 + MOVH R11, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm4MB + +repeat_two_offset_match_nolit_repeat_encodeBetterBlockAsm4MB: + MOVD $0, R5 + ADD R11<<2, R5, R11 + ADD $1, R11, R11 + MOVWU R11, R11 + MOVB R7, 1(R1) + ASRW $0x08, R7, R7 + LSLW $0x05, R7, R7 + ORRW R7, R11, R11 + MOVB R11, (R1) + ADD $0x02, R1, R1 + +match_nolit_emitcopy_end_encodeBetterBlockAsm4MB: + MOVWU 16(RSP), R16 + CMPW R16, R2 + BHS emit_remainder_encodeBetterBlockAsm4MB + MOVD 8(RSP), R16 + CMP R16, R1 + BLO match_nolit_dst_ok_encodeBetterBlockAsm4MB + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +match_nolit_dst_ok_encodeBetterBlockAsm4MB: + MOVD $0x00cf1bbcdcbfa563, R5 + MOVD $0x9e3779b1, R7 + ADD $1, R6, R6 + SUB $2, R2, R8 + MOVD (R3)(R6), R9 + ADD R6, R3, R15 + MOVD 1(R15), R10 + MOVD (R3)(R8), R11 + ADD R8, R3, R15 + MOVD 1(R15), R12 + LSL $0x08, R9, R9 + MUL R5, R9, R9 + LSR $0x2f, R9, R9 + LSL $0x20, R10, R10 + MUL R7, R10, R10 + LSR $0x32, R10, R10 + LSL $0x08, R11, R11 + MUL R5, R11, R11 + LSR $0x2f, R11, R11 + LSL $0x20, R12, R12 + MUL R7, R12, R12 + LSR $0x32, R12, R12 + ADD $1, R6, R7 + ADD $1, R8, R13 + MOVW R6, (R0)(R9<<2) + MOVW R8, (R0)(R11<<2) + ADD R10<<2, R0, R15 + MOVW R7, 524288(R15) + ADD R12<<2, R0, R15 + MOVW R13, 524288(R15) + ADD R6, R8, R7 + ADD $1, R7, R7 + LSR $0x01, R7, R7 + ADD $0x01, R6, R6 + SUB $0x01, R8, R8 + +index_loop_encodeBetterBlockAsm4MB: + CMP R8, R7 + BHS search_loop_encodeBetterBlockAsm4MB + MOVD (R3)(R6), R9 + MOVD (R3)(R7), R10 + LSL $0x08, R9, R9 + MUL R5, R9, R9 + LSR $0x2f, R9, R9 + LSL $0x08, R10, R10 + MUL R5, R10, R10 + LSR $0x2f, R10, R10 + MOVW R6, (R0)(R9<<2) + MOVW R7, (R0)(R10<<2) + ADD $0x02, R6, R6 + ADD $0x02, R7, R7 + JMP index_loop_encodeBetterBlockAsm4MB + +emit_remainder_encodeBetterBlockAsm4MB: + MOVD src_len+32(FP), R0 + MOVWU 20(RSP), R16 + SUBW R16, R0, R0 + ADD R0, R1, R0 + ADD $4, R0, R0 + MOVD 8(RSP), R16 + CMP R16, R0 + BLO emit_remainder_ok_encodeBetterBlockAsm4MB + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +emit_remainder_ok_encodeBetterBlockAsm4MB: + MOVD src_len+32(FP), R0 + MOVWU 20(RSP), R2 + CMPW R0, R2 + BEQ emit_literal_done_emit_remainder_encodeBetterBlockAsm4MB + MOVWU R0, R5 + MOVW R0, 20(RSP) + ADD R2, R3, R0 + SUBW R2, R5, R5 + SUB $1, R5, R2 + MOVWU R2, R2 + CMPW $0x3c, R2 + BLO one_byte_emit_remainder_encodeBetterBlockAsm4MB + CMPW $0x00000100, R2 + BLO two_bytes_emit_remainder_encodeBetterBlockAsm4MB + CMPW $0x00010000, R2 + BLO three_bytes_emit_remainder_encodeBetterBlockAsm4MB + MOVWU R2, R3 + LSRW $0x10, R3, R3 + MOVD $0xf8, R16 + MOVB R16, (R1) + MOVH R2, 1(R1) + MOVB R3, 3(R1) + ADD $0x04, R1, R1 + JMP memmove_long_emit_remainder_encodeBetterBlockAsm4MB + +three_bytes_emit_remainder_encodeBetterBlockAsm4MB: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R2, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_emit_remainder_encodeBetterBlockAsm4MB + +two_bytes_emit_remainder_encodeBetterBlockAsm4MB: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R2, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R2 + BLO memmove_emit_remainder_encodeBetterBlockAsm4MB + JMP memmove_long_emit_remainder_encodeBetterBlockAsm4MB + +one_byte_emit_remainder_encodeBetterBlockAsm4MB: + LSLW $0x02, R2, R16 + BFI $0, R16, $8, R2 + MOVB R2, (R1) + ADD $0x01, R1, R1 + +memmove_emit_remainder_encodeBetterBlockAsm4MB: + ADD R5, R1, R2 + MOVWU R5, R3 + + // genMemMoveShort + CMP $0x03, R3 + BLO emit_lit_memmove_emit_remainder_encodeBetterBlockAsm4MB_memmove_move_1or2 + BEQ emit_lit_memmove_emit_remainder_encodeBetterBlockAsm4MB_memmove_move_3 + CMP $0x08, R3 + BLO emit_lit_memmove_emit_remainder_encodeBetterBlockAsm4MB_memmove_move_4through7 + CMP $0x10, R3 + BLS emit_lit_memmove_emit_remainder_encodeBetterBlockAsm4MB_memmove_move_8through16 + CMP $0x20, R3 + BLS emit_lit_memmove_emit_remainder_encodeBetterBlockAsm4MB_memmove_move_17through32 + JMP emit_lit_memmove_emit_remainder_encodeBetterBlockAsm4MB_memmove_move_33through64 + +emit_lit_memmove_emit_remainder_encodeBetterBlockAsm4MB_memmove_move_1or2: + MOVBU (R0), R16 + BFI $0, R16, $8, R5 + ADD R3, R0, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R0 + MOVB R5, (R1) + ADD R3, R1, R15 + MOVB R0, -1(R15) + JMP memmove_end_copy_emit_remainder_encodeBetterBlockAsm4MB + +emit_lit_memmove_emit_remainder_encodeBetterBlockAsm4MB_memmove_move_3: + MOVHU (R0), R16 + BFI $0, R16, $16, R5 + MOVBU 2(R0), R16 + BFI $0, R16, $8, R0 + MOVH R5, (R1) + MOVB R0, 2(R1) + JMP memmove_end_copy_emit_remainder_encodeBetterBlockAsm4MB + +emit_lit_memmove_emit_remainder_encodeBetterBlockAsm4MB_memmove_move_4through7: + MOVWU (R0), R5 + ADD R3, R0, R15 + MOVWU -4(R15), R0 + MOVW R5, (R1) + ADD R3, R1, R15 + MOVW R0, -4(R15) + JMP memmove_end_copy_emit_remainder_encodeBetterBlockAsm4MB + +emit_lit_memmove_emit_remainder_encodeBetterBlockAsm4MB_memmove_move_8through16: + MOVD (R0), R5 + ADD R3, R0, R15 + MOVD -8(R15), R0 + MOVD R5, (R1) + ADD R3, R1, R15 + MOVD R0, -8(R15) + JMP memmove_end_copy_emit_remainder_encodeBetterBlockAsm4MB + +emit_lit_memmove_emit_remainder_encodeBetterBlockAsm4MB_memmove_move_17through32: + FMOVQ (R0), F0 + ADD R3, R0, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R3, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_emit_remainder_encodeBetterBlockAsm4MB + +emit_lit_memmove_emit_remainder_encodeBetterBlockAsm4MB_memmove_move_33through64: + FMOVQ (R0), F0 + FMOVQ 16(R0), F1 + ADD R3, R0, R15 + FMOVQ -32(R15), F2 + ADD R3, R0, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R3, R1, R15 + FMOVQ F2, -32(R15) + ADD R3, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_emit_remainder_encodeBetterBlockAsm4MB: + MOVD R2, R1 + JMP emit_literal_done_emit_remainder_encodeBetterBlockAsm4MB + +memmove_long_emit_remainder_encodeBetterBlockAsm4MB: + ADD R5, R1, R2 + MOVWU R5, R3 + + // genMemMoveLong + MOVD R0, R5 + MOVD R1, R6 + MOVD R3, R7 + +emit_lit_memmove_long_emit_remainder_encodeBetterBlockAsm4MBlarge_big_loop_back: + FMOVQ (R5), F0 + FMOVQ 16(R5), F1 + FMOVQ F0, (R6) + FMOVQ F1, 16(R6) + ADD $0x20, R5, R5 + ADD $0x20, R6, R6 + SUB $0x20, R7, R7 + CMP $0x20, R7 + BHS emit_lit_memmove_long_emit_remainder_encodeBetterBlockAsm4MBlarge_big_loop_back + ADD R3, R0, R15 + FMOVQ -32(R15), F0 + ADD R3, R0, R15 + FMOVQ -16(R15), F1 + ADD R3, R1, R15 + FMOVQ F0, -32(R15) + ADD R3, R1, R15 + FMOVQ F1, -16(R15) + MOVD R2, R1 + +emit_literal_done_emit_remainder_encodeBetterBlockAsm4MB: + MOVD dst_base+0(FP), R0 + SUB R0, R1, R1 + MOVD R1, ret+56(FP) + RET + +// func encodeBetterBlockAsm12B(dst []byte, src []byte, tmp *[81920]byte) int +// Requires: BMI, SSE2 +TEXT ·encodeBetterBlockAsm12B(SB), $24-64 + MOVD tmp+48(FP), R0 + MOVD dst_base+0(FP), R1 + MOVD $0x00000280, R2 + MOVD R0, R3 + VEOR V0.B16, V0.B16, V0.B16 + +zero_loop_encodeBetterBlockAsm12B: + FMOVQ F0, (R3) + FMOVQ F0, 16(R3) + FMOVQ F0, 32(R3) + FMOVQ F0, 48(R3) + FMOVQ F0, 64(R3) + FMOVQ F0, 80(R3) + FMOVQ F0, 96(R3) + FMOVQ F0, 112(R3) + ADD $0x80, R3, R3 + SUBS $1, R2, R2 + BNE zero_loop_encodeBetterBlockAsm12B + MOVD $0x00000000, R16 + MOVW R16, 20(RSP) + MOVD src_len+32(FP), R2 + SUB $6, R2, R3 + SUB $8, R2, R5 + MOVW R5, 16(RSP) + LSR $0x05, R2, R2 + SUBW R2, R3, R3 + ADD R3, R1, R3 + MOVD R3, 8(RSP) + MOVD $0x00000001, R2 + MOVD $0x00000000, R16 + MOVW R16, 24(RSP) + MOVD src_base+24(FP), R3 + +search_loop_encodeBetterBlockAsm12B: + MOVWU R2, R5 + MOVWU 20(RSP), R16 + SUBW R16, R5, R5 + LSRW $0x06, R5, R5 + ADD R5, R2, R5 + ADD $1, R5, R5 + MOVWU R5, R5 + MOVWU 16(RSP), R16 + CMPW R16, R5 + BHS emit_remainder_encodeBetterBlockAsm12B + MOVD (R3)(R2), R6 + MOVW R5, 28(RSP) + MOVD $0x0000cf1bbcdcbf9b, R8 + MOVD $0x9e3779b1, R5 + MOVD R6, R9 + MOVD R6, R10 + LSL $0x10, R9, R9 + MUL R8, R9, R9 + LSR $0x32, R9, R9 + LSL $0x20, R10, R10 + MUL R5, R10, R10 + LSR $0x34, R10, R10 + MOVWU (R0)(R9<<2), R5 + ADD R10<<2, R0, R15 + MOVWU 65536(R15), R7 + MOVW R2, (R0)(R9<<2) + ADD R10<<2, R0, R15 + MOVW R2, 65536(R15) + MOVD (R3)(R5), R9 + MOVD (R3)(R7), R10 + CMP R6, R9 + BEQ candidate_match_encodeBetterBlockAsm12B + CMP R6, R10 + BNE no_short_found_encodeBetterBlockAsm12B + MOVWU R7, R5 + JMP candidate_match_encodeBetterBlockAsm12B + +no_short_found_encodeBetterBlockAsm12B: + CMPW R6, R9 + BEQ candidate_match_encodeBetterBlockAsm12B + CMPW R6, R10 + BEQ candidateS_match_encodeBetterBlockAsm12B + MOVWU 28(RSP), R2 + JMP search_loop_encodeBetterBlockAsm12B + +candidateS_match_encodeBetterBlockAsm12B: + LSR $0x08, R6, R6 + MOVD R6, R9 + LSL $0x10, R9, R9 + MUL R8, R9, R9 + LSR $0x32, R9, R9 + MOVWU (R0)(R9<<2), R5 + ADDW $1, R2, R2 + MOVW R2, (R0)(R9<<2) + MOVWU (R3)(R5), R16 + CMPW R6, R16 + BEQ candidate_match_encodeBetterBlockAsm12B + SUBW $1, R2, R2 + MOVWU R7, R5 + +candidate_match_encodeBetterBlockAsm12B: + MOVWU 20(RSP), R6 + TSTW R5, R5 + BEQ match_extend_back_end_encodeBetterBlockAsm12B + +match_extend_back_loop_encodeBetterBlockAsm12B: + CMPW R6, R2 + BLS match_extend_back_end_encodeBetterBlockAsm12B + ADD R5, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R7 + ADD R2, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R8 + AND $0xff, R8, R16 + AND $0xff, R7, R15 + CMP R16, R15 + BNE match_extend_back_end_encodeBetterBlockAsm12B + SUB $1, R2, R2 + MOVWU R2, R2 + SUBSW $1, R5, R5 + BEQ match_extend_back_end_encodeBetterBlockAsm12B + JMP match_extend_back_loop_encodeBetterBlockAsm12B + +match_extend_back_end_encodeBetterBlockAsm12B: + MOVWU R2, R6 + MOVWU 20(RSP), R16 + SUBW R16, R6, R6 + ADD R6, R1, R6 + ADD $3, R6, R6 + MOVD 8(RSP), R16 + CMP R16, R6 + BLO match_dst_size_check_encodeBetterBlockAsm12B + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +match_dst_size_check_encodeBetterBlockAsm12B: + MOVWU R2, R6 + ADDW $0x04, R2, R2 + ADDW $0x04, R5, R5 + MOVD src_len+32(FP), R7 + SUBW R2, R7, R7 + ADD R2, R3, R8 + ADD R5, R3, R9 + + // matchLen + MOVD $0, R11 + +matchlen_loopback_16_match_nolit_encodeBetterBlockAsm12B: + CMPW $0x10, R7 + BLO matchlen_match8_match_nolit_encodeBetterBlockAsm12B + MOVD (R8)(R11), R10 + ADD R11, R8, R15 + MOVD 8(R15), R12 + MOVD (R9)(R11), R16 + EOR R16, R10, R10 + TST R10, R10 + BNE matchlen_bsf_8_match_nolit_encodeBetterBlockAsm12B + ADD R11, R9, R15 + MOVD 8(R15), R16 + EOR R16, R12, R12 + TST R12, R12 + BNE matchlen_bsf_16match_nolit_encodeBetterBlockAsm12B + SUB $16, R7, R7 + MOVWU R7, R7 + ADD $16, R11, R11 + MOVWU R11, R11 + JMP matchlen_loopback_16_match_nolit_encodeBetterBlockAsm12B + +matchlen_bsf_16match_nolit_encodeBetterBlockAsm12B: + RBIT R12, R12 + CLZ R12, R12 + ASR $0x03, R12, R12 + ADD R12, R11, R11 + ADD $8, R11, R11 + MOVWU R11, R11 + JMP match_nolit_end_encodeBetterBlockAsm12B + +matchlen_match8_match_nolit_encodeBetterBlockAsm12B: + CMPW $0x08, R7 + BLO matchlen_match4_match_nolit_encodeBetterBlockAsm12B + MOVD (R8)(R11), R10 + MOVD (R9)(R11), R16 + EOR R16, R10, R10 + TST R10, R10 + BNE matchlen_bsf_8_match_nolit_encodeBetterBlockAsm12B + SUB $8, R7, R7 + MOVWU R7, R7 + ADD $8, R11, R11 + MOVWU R11, R11 + JMP matchlen_match4_match_nolit_encodeBetterBlockAsm12B + +matchlen_bsf_8_match_nolit_encodeBetterBlockAsm12B: + RBIT R10, R10 + CLZ R10, R10 + ASR $0x03, R10, R10 + ADD R10, R11, R11 + MOVWU R11, R11 + JMP match_nolit_end_encodeBetterBlockAsm12B + +matchlen_match4_match_nolit_encodeBetterBlockAsm12B: + CMPW $0x04, R7 + BLO matchlen_match2_match_nolit_encodeBetterBlockAsm12B + MOVWU (R8)(R11), R10 + MOVWU (R9)(R11), R16 + CMPW R10, R16 + BNE matchlen_match2_match_nolit_encodeBetterBlockAsm12B + SUB $4, R7, R7 + MOVWU R7, R7 + ADD $4, R11, R11 + MOVWU R11, R11 + +matchlen_match2_match_nolit_encodeBetterBlockAsm12B: + CMPW $0x01, R7 + BEQ matchlen_match1_match_nolit_encodeBetterBlockAsm12B + BLO match_nolit_end_encodeBetterBlockAsm12B + MOVHU (R8)(R11), R16 + BFI $0, R16, $16, R10 + ADD R11, R9, R15 + MOVHU (R15), R15 + AND $0xffff, R10, R16 + CMP R16, R15 + BNE matchlen_match1_match_nolit_encodeBetterBlockAsm12B + ADD $2, R11, R11 + MOVWU R11, R11 + SUBSW $0x02, R7, R7 + BEQ match_nolit_end_encodeBetterBlockAsm12B + +matchlen_match1_match_nolit_encodeBetterBlockAsm12B: + MOVBU (R8)(R11), R16 + BFI $0, R16, $8, R10 + ADD R11, R9, R15 + MOVBU (R15), R15 + AND $0xff, R10, R16 + CMP R16, R15 + BNE match_nolit_end_encodeBetterBlockAsm12B + ADD $1, R11, R11 + MOVWU R11, R11 + +match_nolit_end_encodeBetterBlockAsm12B: + MOVWU R2, R7 + SUBW R5, R7, R7 + + // Check if repeat + MOVWU 24(RSP), R16 + CMPW R7, R16 + BEQ match_is_repeat_encodeBetterBlockAsm12B + MOVW R7, 24(RSP) + MOVWU 20(RSP), R5 + CMPW R6, R5 + BEQ emit_literal_done_match_emit_encodeBetterBlockAsm12B + MOVWU R6, R8 + MOVW R6, 20(RSP) + ADD R5, R3, R9 + SUBW R5, R8, R8 + SUB $1, R8, R5 + MOVWU R5, R5 + CMPW $0x3c, R5 + BLO one_byte_match_emit_encodeBetterBlockAsm12B + CMPW $0x00000100, R5 + BLO two_bytes_match_emit_encodeBetterBlockAsm12B + BLO three_bytes_match_emit_encodeBetterBlockAsm12B + +three_bytes_match_emit_encodeBetterBlockAsm12B: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R5, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_match_emit_encodeBetterBlockAsm12B + +two_bytes_match_emit_encodeBetterBlockAsm12B: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R5, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R5 + BLO memmove_match_emit_encodeBetterBlockAsm12B + JMP memmove_long_match_emit_encodeBetterBlockAsm12B + +one_byte_match_emit_encodeBetterBlockAsm12B: + LSLW $0x02, R5, R16 + BFI $0, R16, $8, R5 + MOVB R5, (R1) + ADD $0x01, R1, R1 + +memmove_match_emit_encodeBetterBlockAsm12B: + ADD R8, R1, R5 + + // genMemMoveShort + CMP $0x04, R8 + BLS emit_lit_memmove_match_emit_encodeBetterBlockAsm12B_memmove_move_4 + CMP $0x08, R8 + BLO emit_lit_memmove_match_emit_encodeBetterBlockAsm12B_memmove_move_4through7 + CMP $0x10, R8 + BLS emit_lit_memmove_match_emit_encodeBetterBlockAsm12B_memmove_move_8through16 + CMP $0x20, R8 + BLS emit_lit_memmove_match_emit_encodeBetterBlockAsm12B_memmove_move_17through32 + JMP emit_lit_memmove_match_emit_encodeBetterBlockAsm12B_memmove_move_33through64 + +emit_lit_memmove_match_emit_encodeBetterBlockAsm12B_memmove_move_4: + MOVWU (R9), R10 + MOVW R10, (R1) + JMP memmove_end_copy_match_emit_encodeBetterBlockAsm12B + +emit_lit_memmove_match_emit_encodeBetterBlockAsm12B_memmove_move_4through7: + MOVWU (R9), R10 + ADD R8, R9, R15 + MOVWU -4(R15), R9 + MOVW R10, (R1) + ADD R8, R1, R15 + MOVW R9, -4(R15) + JMP memmove_end_copy_match_emit_encodeBetterBlockAsm12B + +emit_lit_memmove_match_emit_encodeBetterBlockAsm12B_memmove_move_8through16: + MOVD (R9), R10 + ADD R8, R9, R15 + MOVD -8(R15), R9 + MOVD R10, (R1) + ADD R8, R1, R15 + MOVD R9, -8(R15) + JMP memmove_end_copy_match_emit_encodeBetterBlockAsm12B + +emit_lit_memmove_match_emit_encodeBetterBlockAsm12B_memmove_move_17through32: + FMOVQ (R9), F0 + ADD R8, R9, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_match_emit_encodeBetterBlockAsm12B + +emit_lit_memmove_match_emit_encodeBetterBlockAsm12B_memmove_move_33through64: + FMOVQ (R9), F0 + FMOVQ 16(R9), F1 + ADD R8, R9, R15 + FMOVQ -32(R15), F2 + ADD R8, R9, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R8, R1, R15 + FMOVQ F2, -32(R15) + ADD R8, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_match_emit_encodeBetterBlockAsm12B: + MOVD R5, R1 + JMP emit_literal_done_match_emit_encodeBetterBlockAsm12B + +memmove_long_match_emit_encodeBetterBlockAsm12B: + ADD R8, R1, R5 + + // genMemMoveLong + MOVD R9, R10 + MOVD R1, R12 + MOVD R8, R13 + +emit_lit_memmove_long_match_emit_encodeBetterBlockAsm12Blarge_big_loop_back: + FMOVQ (R10), F0 + FMOVQ 16(R10), F1 + FMOVQ F0, (R12) + FMOVQ F1, 16(R12) + ADD $0x20, R10, R10 + ADD $0x20, R12, R12 + SUB $0x20, R13, R13 + CMP $0x20, R13 + BHS emit_lit_memmove_long_match_emit_encodeBetterBlockAsm12Blarge_big_loop_back + ADD R8, R9, R15 + FMOVQ -32(R15), F0 + ADD R8, R9, R15 + FMOVQ -16(R15), F1 + ADD R8, R1, R15 + FMOVQ F0, -32(R15) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + MOVD R5, R1 + +emit_literal_done_match_emit_encodeBetterBlockAsm12B: + ADDW R11, R2, R2 + ADDW $0x04, R11, R11 + MOVW R2, 20(RSP) + + // emitCopy + CMPW $0x40, R11 + BLS two_byte_offset_short_match_nolit_encodeBetterBlockAsm12B + CMPW $0x00000800, R7 + BHS long_offset_short_match_nolit_encodeBetterBlockAsm12B + MOVD $0x00000001, R5 + ADD $16, R5, R5 + MOVWU R5, R5 + MOVB R7, 1(R1) + LSRW $0x08, R7, R7 + LSLW $0x05, R7, R7 + ORRW R7, R5, R5 + MOVB R5, (R1) + ADD $0x02, R1, R1 + SUBW $0x08, R11, R11 + + // emitRepeat + SUB $4, R11, R11 + MOVWU R11, R11 + JMP cant_repeat_two_offset_match_nolit_encodeBetterBlockAsm12B_emit_copy_short_2b + MOVWU R11, R5 + SUB $4, R11, R11 + MOVWU R11, R11 + CMPW $0x08, R5 + BLS repeat_two_match_nolit_encodeBetterBlockAsm12B_emit_copy_short_2b + CMPW $0x0c, R5 + BHS cant_repeat_two_offset_match_nolit_encodeBetterBlockAsm12B_emit_copy_short_2b + CMPW $0x00000800, R7 + BLO repeat_two_offset_match_nolit_encodeBetterBlockAsm12B_emit_copy_short_2b + +cant_repeat_two_offset_match_nolit_encodeBetterBlockAsm12B_emit_copy_short_2b: + CMPW $0x00000104, R11 + BLO repeat_three_match_nolit_encodeBetterBlockAsm12B_emit_copy_short_2b + SUB $256, R11, R11 + MOVWU R11, R11 + MOVD $0x0019, R16 + MOVH R16, (R1) + MOVH R11, 2(R1) + ADD $0x04, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm12B + +repeat_three_match_nolit_encodeBetterBlockAsm12B_emit_copy_short_2b: + SUB $4, R11, R11 + MOVWU R11, R11 + MOVD $0x0015, R16 + MOVH R16, (R1) + MOVB R11, 2(R1) + ADD $0x03, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm12B + +repeat_two_match_nolit_encodeBetterBlockAsm12B_emit_copy_short_2b: + LSLW $0x02, R11, R11 + ORRW $0x01, R11, R11 + MOVH R11, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm12B + +repeat_two_offset_match_nolit_encodeBetterBlockAsm12B_emit_copy_short_2b: + MOVD $0, R5 + ADD R11<<2, R5, R11 + ADD $1, R11, R11 + MOVWU R11, R11 + MOVB R7, 1(R1) + ASRW $0x08, R7, R7 + LSLW $0x05, R7, R7 + ORRW R7, R11, R11 + MOVB R11, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm12B + +long_offset_short_match_nolit_encodeBetterBlockAsm12B: + MOVD $0xee, R16 + MOVB R16, (R1) + MOVH R7, 1(R1) + SUB $60, R11, R11 + MOVWU R11, R11 + ADD $0x03, R1, R1 + + // emitRepeat + MOVWU R11, R5 + SUB $4, R11, R11 + MOVWU R11, R11 + CMPW $0x08, R5 + BLS repeat_two_match_nolit_encodeBetterBlockAsm12B_emit_copy_short + CMPW $0x0c, R5 + BHS cant_repeat_two_offset_match_nolit_encodeBetterBlockAsm12B_emit_copy_short + CMPW $0x00000800, R7 + BLO repeat_two_offset_match_nolit_encodeBetterBlockAsm12B_emit_copy_short + +cant_repeat_two_offset_match_nolit_encodeBetterBlockAsm12B_emit_copy_short: + CMPW $0x00000104, R11 + BLO repeat_three_match_nolit_encodeBetterBlockAsm12B_emit_copy_short + SUB $256, R11, R11 + MOVWU R11, R11 + MOVD $0x0019, R16 + MOVH R16, (R1) + MOVH R11, 2(R1) + ADD $0x04, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm12B + +repeat_three_match_nolit_encodeBetterBlockAsm12B_emit_copy_short: + SUB $4, R11, R11 + MOVWU R11, R11 + MOVD $0x0015, R16 + MOVH R16, (R1) + MOVB R11, 2(R1) + ADD $0x03, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm12B + +repeat_two_match_nolit_encodeBetterBlockAsm12B_emit_copy_short: + LSLW $0x02, R11, R11 + ORRW $0x01, R11, R11 + MOVH R11, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm12B + +repeat_two_offset_match_nolit_encodeBetterBlockAsm12B_emit_copy_short: + MOVD $0, R5 + ADD R11<<2, R5, R11 + ADD $1, R11, R11 + MOVWU R11, R11 + MOVB R7, 1(R1) + ASRW $0x08, R7, R7 + LSLW $0x05, R7, R7 + ORRW R7, R11, R11 + MOVB R11, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm12B + +two_byte_offset_short_match_nolit_encodeBetterBlockAsm12B: + MOVWU R11, R5 + LSLW $0x02, R5, R5 + CMPW $0x0c, R11 + BHS emit_copy_three_match_nolit_encodeBetterBlockAsm12B + CMPW $0x00000800, R7 + BHS emit_copy_three_match_nolit_encodeBetterBlockAsm12B + SUB $15, R5, R5 + MOVWU R5, R5 + MOVB R7, 1(R1) + LSRW $0x08, R7, R7 + LSLW $0x05, R7, R7 + ORRW R7, R5, R5 + MOVB R5, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm12B + +emit_copy_three_match_nolit_encodeBetterBlockAsm12B: + SUB $2, R5, R5 + MOVWU R5, R5 + MOVB R5, (R1) + MOVH R7, 1(R1) + ADD $0x03, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm12B + +match_is_repeat_encodeBetterBlockAsm12B: + MOVWU 20(RSP), R5 + CMPW R6, R5 + BEQ emit_literal_done_match_emit_repeat_encodeBetterBlockAsm12B + MOVWU R6, R8 + MOVW R6, 20(RSP) + ADD R5, R3, R9 + SUBW R5, R8, R8 + SUB $1, R8, R5 + MOVWU R5, R5 + CMPW $0x3c, R5 + BLO one_byte_match_emit_repeat_encodeBetterBlockAsm12B + CMPW $0x00000100, R5 + BLO two_bytes_match_emit_repeat_encodeBetterBlockAsm12B + BLO three_bytes_match_emit_repeat_encodeBetterBlockAsm12B + +three_bytes_match_emit_repeat_encodeBetterBlockAsm12B: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R5, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_match_emit_repeat_encodeBetterBlockAsm12B + +two_bytes_match_emit_repeat_encodeBetterBlockAsm12B: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R5, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R5 + BLO memmove_match_emit_repeat_encodeBetterBlockAsm12B + JMP memmove_long_match_emit_repeat_encodeBetterBlockAsm12B + +one_byte_match_emit_repeat_encodeBetterBlockAsm12B: + LSLW $0x02, R5, R16 + BFI $0, R16, $8, R5 + MOVB R5, (R1) + ADD $0x01, R1, R1 + +memmove_match_emit_repeat_encodeBetterBlockAsm12B: + ADD R8, R1, R5 + + // genMemMoveShort + CMP $0x04, R8 + BLS emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm12B_memmove_move_4 + CMP $0x08, R8 + BLO emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm12B_memmove_move_4through7 + CMP $0x10, R8 + BLS emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm12B_memmove_move_8through16 + CMP $0x20, R8 + BLS emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm12B_memmove_move_17through32 + JMP emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm12B_memmove_move_33through64 + +emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm12B_memmove_move_4: + MOVWU (R9), R10 + MOVW R10, (R1) + JMP memmove_end_copy_match_emit_repeat_encodeBetterBlockAsm12B + +emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm12B_memmove_move_4through7: + MOVWU (R9), R10 + ADD R8, R9, R15 + MOVWU -4(R15), R9 + MOVW R10, (R1) + ADD R8, R1, R15 + MOVW R9, -4(R15) + JMP memmove_end_copy_match_emit_repeat_encodeBetterBlockAsm12B + +emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm12B_memmove_move_8through16: + MOVD (R9), R10 + ADD R8, R9, R15 + MOVD -8(R15), R9 + MOVD R10, (R1) + ADD R8, R1, R15 + MOVD R9, -8(R15) + JMP memmove_end_copy_match_emit_repeat_encodeBetterBlockAsm12B + +emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm12B_memmove_move_17through32: + FMOVQ (R9), F0 + ADD R8, R9, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_match_emit_repeat_encodeBetterBlockAsm12B + +emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm12B_memmove_move_33through64: + FMOVQ (R9), F0 + FMOVQ 16(R9), F1 + ADD R8, R9, R15 + FMOVQ -32(R15), F2 + ADD R8, R9, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R8, R1, R15 + FMOVQ F2, -32(R15) + ADD R8, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_match_emit_repeat_encodeBetterBlockAsm12B: + MOVD R5, R1 + JMP emit_literal_done_match_emit_repeat_encodeBetterBlockAsm12B + +memmove_long_match_emit_repeat_encodeBetterBlockAsm12B: + ADD R8, R1, R5 + + // genMemMoveLong + MOVD R9, R10 + MOVD R1, R12 + MOVD R8, R13 + +emit_lit_memmove_long_match_emit_repeat_encodeBetterBlockAsm12Blarge_big_loop_back: + FMOVQ (R10), F0 + FMOVQ 16(R10), F1 + FMOVQ F0, (R12) + FMOVQ F1, 16(R12) + ADD $0x20, R10, R10 + ADD $0x20, R12, R12 + SUB $0x20, R13, R13 + CMP $0x20, R13 + BHS emit_lit_memmove_long_match_emit_repeat_encodeBetterBlockAsm12Blarge_big_loop_back + ADD R8, R9, R15 + FMOVQ -32(R15), F0 + ADD R8, R9, R15 + FMOVQ -16(R15), F1 + ADD R8, R1, R15 + FMOVQ F0, -32(R15) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + MOVD R5, R1 + +emit_literal_done_match_emit_repeat_encodeBetterBlockAsm12B: + ADDW R11, R2, R2 + ADDW $0x04, R11, R11 + MOVW R2, 20(RSP) + + // emitRepeat + MOVWU R11, R5 + SUB $4, R11, R11 + MOVWU R11, R11 + CMPW $0x08, R5 + BLS repeat_two_match_nolit_repeat_encodeBetterBlockAsm12B + CMPW $0x0c, R5 + BHS cant_repeat_two_offset_match_nolit_repeat_encodeBetterBlockAsm12B + CMPW $0x00000800, R7 + BLO repeat_two_offset_match_nolit_repeat_encodeBetterBlockAsm12B + +cant_repeat_two_offset_match_nolit_repeat_encodeBetterBlockAsm12B: + CMPW $0x00000104, R11 + BLO repeat_three_match_nolit_repeat_encodeBetterBlockAsm12B + SUB $256, R11, R11 + MOVWU R11, R11 + MOVD $0x0019, R16 + MOVH R16, (R1) + MOVH R11, 2(R1) + ADD $0x04, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm12B + +repeat_three_match_nolit_repeat_encodeBetterBlockAsm12B: + SUB $4, R11, R11 + MOVWU R11, R11 + MOVD $0x0015, R16 + MOVH R16, (R1) + MOVB R11, 2(R1) + ADD $0x03, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm12B + +repeat_two_match_nolit_repeat_encodeBetterBlockAsm12B: + LSLW $0x02, R11, R11 + ORRW $0x01, R11, R11 + MOVH R11, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm12B + +repeat_two_offset_match_nolit_repeat_encodeBetterBlockAsm12B: + MOVD $0, R5 + ADD R11<<2, R5, R11 + ADD $1, R11, R11 + MOVWU R11, R11 + MOVB R7, 1(R1) + ASRW $0x08, R7, R7 + LSLW $0x05, R7, R7 + ORRW R7, R11, R11 + MOVB R11, (R1) + ADD $0x02, R1, R1 + +match_nolit_emitcopy_end_encodeBetterBlockAsm12B: + MOVWU 16(RSP), R16 + CMPW R16, R2 + BHS emit_remainder_encodeBetterBlockAsm12B + MOVD 8(RSP), R16 + CMP R16, R1 + BLO match_nolit_dst_ok_encodeBetterBlockAsm12B + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +match_nolit_dst_ok_encodeBetterBlockAsm12B: + MOVD $0x0000cf1bbcdcbf9b, R5 + MOVD $0x9e3779b1, R7 + ADD $1, R6, R6 + SUB $2, R2, R8 + MOVD (R3)(R6), R9 + ADD R6, R3, R15 + MOVD 1(R15), R10 + MOVD (R3)(R8), R11 + ADD R8, R3, R15 + MOVD 1(R15), R12 + LSL $0x10, R9, R9 + MUL R5, R9, R9 + LSR $0x32, R9, R9 + LSL $0x20, R10, R10 + MUL R7, R10, R10 + LSR $0x34, R10, R10 + LSL $0x10, R11, R11 + MUL R5, R11, R11 + LSR $0x32, R11, R11 + LSL $0x20, R12, R12 + MUL R7, R12, R12 + LSR $0x34, R12, R12 + ADD $1, R6, R7 + ADD $1, R8, R13 + MOVW R6, (R0)(R9<<2) + MOVW R8, (R0)(R11<<2) + ADD R10<<2, R0, R15 + MOVW R7, 65536(R15) + ADD R12<<2, R0, R15 + MOVW R13, 65536(R15) + ADD R6, R8, R7 + ADD $1, R7, R7 + LSR $0x01, R7, R7 + ADD $0x01, R6, R6 + SUB $0x01, R8, R8 + +index_loop_encodeBetterBlockAsm12B: + CMP R8, R7 + BHS search_loop_encodeBetterBlockAsm12B + MOVD (R3)(R6), R9 + MOVD (R3)(R7), R10 + LSL $0x10, R9, R9 + MUL R5, R9, R9 + LSR $0x32, R9, R9 + LSL $0x10, R10, R10 + MUL R5, R10, R10 + LSR $0x32, R10, R10 + MOVW R6, (R0)(R9<<2) + MOVW R7, (R0)(R10<<2) + ADD $0x02, R6, R6 + ADD $0x02, R7, R7 + JMP index_loop_encodeBetterBlockAsm12B + +emit_remainder_encodeBetterBlockAsm12B: + MOVD src_len+32(FP), R0 + MOVWU 20(RSP), R16 + SUBW R16, R0, R0 + ADD R0, R1, R0 + ADD $3, R0, R0 + MOVD 8(RSP), R16 + CMP R16, R0 + BLO emit_remainder_ok_encodeBetterBlockAsm12B + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +emit_remainder_ok_encodeBetterBlockAsm12B: + MOVD src_len+32(FP), R0 + MOVWU 20(RSP), R2 + CMPW R0, R2 + BEQ emit_literal_done_emit_remainder_encodeBetterBlockAsm12B + MOVWU R0, R5 + MOVW R0, 20(RSP) + ADD R2, R3, R0 + SUBW R2, R5, R5 + SUB $1, R5, R2 + MOVWU R2, R2 + CMPW $0x3c, R2 + BLO one_byte_emit_remainder_encodeBetterBlockAsm12B + CMPW $0x00000100, R2 + BLO two_bytes_emit_remainder_encodeBetterBlockAsm12B + BLO three_bytes_emit_remainder_encodeBetterBlockAsm12B + +three_bytes_emit_remainder_encodeBetterBlockAsm12B: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R2, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_emit_remainder_encodeBetterBlockAsm12B + +two_bytes_emit_remainder_encodeBetterBlockAsm12B: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R2, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R2 + BLO memmove_emit_remainder_encodeBetterBlockAsm12B + JMP memmove_long_emit_remainder_encodeBetterBlockAsm12B + +one_byte_emit_remainder_encodeBetterBlockAsm12B: + LSLW $0x02, R2, R16 + BFI $0, R16, $8, R2 + MOVB R2, (R1) + ADD $0x01, R1, R1 + +memmove_emit_remainder_encodeBetterBlockAsm12B: + ADD R5, R1, R2 + MOVWU R5, R3 + + // genMemMoveShort + CMP $0x03, R3 + BLO emit_lit_memmove_emit_remainder_encodeBetterBlockAsm12B_memmove_move_1or2 + BEQ emit_lit_memmove_emit_remainder_encodeBetterBlockAsm12B_memmove_move_3 + CMP $0x08, R3 + BLO emit_lit_memmove_emit_remainder_encodeBetterBlockAsm12B_memmove_move_4through7 + CMP $0x10, R3 + BLS emit_lit_memmove_emit_remainder_encodeBetterBlockAsm12B_memmove_move_8through16 + CMP $0x20, R3 + BLS emit_lit_memmove_emit_remainder_encodeBetterBlockAsm12B_memmove_move_17through32 + JMP emit_lit_memmove_emit_remainder_encodeBetterBlockAsm12B_memmove_move_33through64 + +emit_lit_memmove_emit_remainder_encodeBetterBlockAsm12B_memmove_move_1or2: + MOVBU (R0), R16 + BFI $0, R16, $8, R5 + ADD R3, R0, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R0 + MOVB R5, (R1) + ADD R3, R1, R15 + MOVB R0, -1(R15) + JMP memmove_end_copy_emit_remainder_encodeBetterBlockAsm12B + +emit_lit_memmove_emit_remainder_encodeBetterBlockAsm12B_memmove_move_3: + MOVHU (R0), R16 + BFI $0, R16, $16, R5 + MOVBU 2(R0), R16 + BFI $0, R16, $8, R0 + MOVH R5, (R1) + MOVB R0, 2(R1) + JMP memmove_end_copy_emit_remainder_encodeBetterBlockAsm12B + +emit_lit_memmove_emit_remainder_encodeBetterBlockAsm12B_memmove_move_4through7: + MOVWU (R0), R5 + ADD R3, R0, R15 + MOVWU -4(R15), R0 + MOVW R5, (R1) + ADD R3, R1, R15 + MOVW R0, -4(R15) + JMP memmove_end_copy_emit_remainder_encodeBetterBlockAsm12B + +emit_lit_memmove_emit_remainder_encodeBetterBlockAsm12B_memmove_move_8through16: + MOVD (R0), R5 + ADD R3, R0, R15 + MOVD -8(R15), R0 + MOVD R5, (R1) + ADD R3, R1, R15 + MOVD R0, -8(R15) + JMP memmove_end_copy_emit_remainder_encodeBetterBlockAsm12B + +emit_lit_memmove_emit_remainder_encodeBetterBlockAsm12B_memmove_move_17through32: + FMOVQ (R0), F0 + ADD R3, R0, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R3, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_emit_remainder_encodeBetterBlockAsm12B + +emit_lit_memmove_emit_remainder_encodeBetterBlockAsm12B_memmove_move_33through64: + FMOVQ (R0), F0 + FMOVQ 16(R0), F1 + ADD R3, R0, R15 + FMOVQ -32(R15), F2 + ADD R3, R0, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R3, R1, R15 + FMOVQ F2, -32(R15) + ADD R3, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_emit_remainder_encodeBetterBlockAsm12B: + MOVD R2, R1 + JMP emit_literal_done_emit_remainder_encodeBetterBlockAsm12B + +memmove_long_emit_remainder_encodeBetterBlockAsm12B: + ADD R5, R1, R2 + MOVWU R5, R3 + + // genMemMoveLong + MOVD R0, R5 + MOVD R1, R6 + MOVD R3, R7 + +emit_lit_memmove_long_emit_remainder_encodeBetterBlockAsm12Blarge_big_loop_back: + FMOVQ (R5), F0 + FMOVQ 16(R5), F1 + FMOVQ F0, (R6) + FMOVQ F1, 16(R6) + ADD $0x20, R5, R5 + ADD $0x20, R6, R6 + SUB $0x20, R7, R7 + CMP $0x20, R7 + BHS emit_lit_memmove_long_emit_remainder_encodeBetterBlockAsm12Blarge_big_loop_back + ADD R3, R0, R15 + FMOVQ -32(R15), F0 + ADD R3, R0, R15 + FMOVQ -16(R15), F1 + ADD R3, R1, R15 + FMOVQ F0, -32(R15) + ADD R3, R1, R15 + FMOVQ F1, -16(R15) + MOVD R2, R1 + +emit_literal_done_emit_remainder_encodeBetterBlockAsm12B: + MOVD dst_base+0(FP), R0 + SUB R0, R1, R1 + MOVD R1, ret+56(FP) + RET + +// func encodeBetterBlockAsm10B(dst []byte, src []byte, tmp *[20480]byte) int +// Requires: BMI, SSE2 +TEXT ·encodeBetterBlockAsm10B(SB), $24-64 + MOVD tmp+48(FP), R0 + MOVD dst_base+0(FP), R1 + MOVD $0x000000a0, R2 + MOVD R0, R3 + VEOR V0.B16, V0.B16, V0.B16 + +zero_loop_encodeBetterBlockAsm10B: + FMOVQ F0, (R3) + FMOVQ F0, 16(R3) + FMOVQ F0, 32(R3) + FMOVQ F0, 48(R3) + FMOVQ F0, 64(R3) + FMOVQ F0, 80(R3) + FMOVQ F0, 96(R3) + FMOVQ F0, 112(R3) + ADD $0x80, R3, R3 + SUBS $1, R2, R2 + BNE zero_loop_encodeBetterBlockAsm10B + MOVD $0x00000000, R16 + MOVW R16, 20(RSP) + MOVD src_len+32(FP), R2 + SUB $6, R2, R3 + SUB $8, R2, R5 + MOVW R5, 16(RSP) + LSR $0x05, R2, R2 + SUBW R2, R3, R3 + ADD R3, R1, R3 + MOVD R3, 8(RSP) + MOVD $0x00000001, R2 + MOVD $0x00000000, R16 + MOVW R16, 24(RSP) + MOVD src_base+24(FP), R3 + +search_loop_encodeBetterBlockAsm10B: + MOVWU R2, R5 + MOVWU 20(RSP), R16 + SUBW R16, R5, R5 + LSRW $0x05, R5, R5 + ADD R5, R2, R5 + ADD $1, R5, R5 + MOVWU R5, R5 + MOVWU 16(RSP), R16 + CMPW R16, R5 + BHS emit_remainder_encodeBetterBlockAsm10B + MOVD (R3)(R2), R6 + MOVW R5, 28(RSP) + MOVD $0x0000cf1bbcdcbf9b, R8 + MOVD $0x9e3779b1, R5 + MOVD R6, R9 + MOVD R6, R10 + LSL $0x10, R9, R9 + MUL R8, R9, R9 + LSR $0x34, R9, R9 + LSL $0x20, R10, R10 + MUL R5, R10, R10 + LSR $0x36, R10, R10 + MOVWU (R0)(R9<<2), R5 + ADD R10<<2, R0, R15 + MOVWU 16384(R15), R7 + MOVW R2, (R0)(R9<<2) + ADD R10<<2, R0, R15 + MOVW R2, 16384(R15) + MOVD (R3)(R5), R9 + MOVD (R3)(R7), R10 + CMP R6, R9 + BEQ candidate_match_encodeBetterBlockAsm10B + CMP R6, R10 + BNE no_short_found_encodeBetterBlockAsm10B + MOVWU R7, R5 + JMP candidate_match_encodeBetterBlockAsm10B + +no_short_found_encodeBetterBlockAsm10B: + CMPW R6, R9 + BEQ candidate_match_encodeBetterBlockAsm10B + CMPW R6, R10 + BEQ candidateS_match_encodeBetterBlockAsm10B + MOVWU 28(RSP), R2 + JMP search_loop_encodeBetterBlockAsm10B + +candidateS_match_encodeBetterBlockAsm10B: + LSR $0x08, R6, R6 + MOVD R6, R9 + LSL $0x10, R9, R9 + MUL R8, R9, R9 + LSR $0x34, R9, R9 + MOVWU (R0)(R9<<2), R5 + ADDW $1, R2, R2 + MOVW R2, (R0)(R9<<2) + MOVWU (R3)(R5), R16 + CMPW R6, R16 + BEQ candidate_match_encodeBetterBlockAsm10B + SUBW $1, R2, R2 + MOVWU R7, R5 + +candidate_match_encodeBetterBlockAsm10B: + MOVWU 20(RSP), R6 + TSTW R5, R5 + BEQ match_extend_back_end_encodeBetterBlockAsm10B + +match_extend_back_loop_encodeBetterBlockAsm10B: + CMPW R6, R2 + BLS match_extend_back_end_encodeBetterBlockAsm10B + ADD R5, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R7 + ADD R2, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R8 + AND $0xff, R8, R16 + AND $0xff, R7, R15 + CMP R16, R15 + BNE match_extend_back_end_encodeBetterBlockAsm10B + SUB $1, R2, R2 + MOVWU R2, R2 + SUBSW $1, R5, R5 + BEQ match_extend_back_end_encodeBetterBlockAsm10B + JMP match_extend_back_loop_encodeBetterBlockAsm10B + +match_extend_back_end_encodeBetterBlockAsm10B: + MOVWU R2, R6 + MOVWU 20(RSP), R16 + SUBW R16, R6, R6 + ADD R6, R1, R6 + ADD $3, R6, R6 + MOVD 8(RSP), R16 + CMP R16, R6 + BLO match_dst_size_check_encodeBetterBlockAsm10B + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +match_dst_size_check_encodeBetterBlockAsm10B: + MOVWU R2, R6 + ADDW $0x04, R2, R2 + ADDW $0x04, R5, R5 + MOVD src_len+32(FP), R7 + SUBW R2, R7, R7 + ADD R2, R3, R8 + ADD R5, R3, R9 + + // matchLen + MOVD $0, R11 + +matchlen_loopback_16_match_nolit_encodeBetterBlockAsm10B: + CMPW $0x10, R7 + BLO matchlen_match8_match_nolit_encodeBetterBlockAsm10B + MOVD (R8)(R11), R10 + ADD R11, R8, R15 + MOVD 8(R15), R12 + MOVD (R9)(R11), R16 + EOR R16, R10, R10 + TST R10, R10 + BNE matchlen_bsf_8_match_nolit_encodeBetterBlockAsm10B + ADD R11, R9, R15 + MOVD 8(R15), R16 + EOR R16, R12, R12 + TST R12, R12 + BNE matchlen_bsf_16match_nolit_encodeBetterBlockAsm10B + SUB $16, R7, R7 + MOVWU R7, R7 + ADD $16, R11, R11 + MOVWU R11, R11 + JMP matchlen_loopback_16_match_nolit_encodeBetterBlockAsm10B + +matchlen_bsf_16match_nolit_encodeBetterBlockAsm10B: + RBIT R12, R12 + CLZ R12, R12 + ASR $0x03, R12, R12 + ADD R12, R11, R11 + ADD $8, R11, R11 + MOVWU R11, R11 + JMP match_nolit_end_encodeBetterBlockAsm10B + +matchlen_match8_match_nolit_encodeBetterBlockAsm10B: + CMPW $0x08, R7 + BLO matchlen_match4_match_nolit_encodeBetterBlockAsm10B + MOVD (R8)(R11), R10 + MOVD (R9)(R11), R16 + EOR R16, R10, R10 + TST R10, R10 + BNE matchlen_bsf_8_match_nolit_encodeBetterBlockAsm10B + SUB $8, R7, R7 + MOVWU R7, R7 + ADD $8, R11, R11 + MOVWU R11, R11 + JMP matchlen_match4_match_nolit_encodeBetterBlockAsm10B + +matchlen_bsf_8_match_nolit_encodeBetterBlockAsm10B: + RBIT R10, R10 + CLZ R10, R10 + ASR $0x03, R10, R10 + ADD R10, R11, R11 + MOVWU R11, R11 + JMP match_nolit_end_encodeBetterBlockAsm10B + +matchlen_match4_match_nolit_encodeBetterBlockAsm10B: + CMPW $0x04, R7 + BLO matchlen_match2_match_nolit_encodeBetterBlockAsm10B + MOVWU (R8)(R11), R10 + MOVWU (R9)(R11), R16 + CMPW R10, R16 + BNE matchlen_match2_match_nolit_encodeBetterBlockAsm10B + SUB $4, R7, R7 + MOVWU R7, R7 + ADD $4, R11, R11 + MOVWU R11, R11 + +matchlen_match2_match_nolit_encodeBetterBlockAsm10B: + CMPW $0x01, R7 + BEQ matchlen_match1_match_nolit_encodeBetterBlockAsm10B + BLO match_nolit_end_encodeBetterBlockAsm10B + MOVHU (R8)(R11), R16 + BFI $0, R16, $16, R10 + ADD R11, R9, R15 + MOVHU (R15), R15 + AND $0xffff, R10, R16 + CMP R16, R15 + BNE matchlen_match1_match_nolit_encodeBetterBlockAsm10B + ADD $2, R11, R11 + MOVWU R11, R11 + SUBSW $0x02, R7, R7 + BEQ match_nolit_end_encodeBetterBlockAsm10B + +matchlen_match1_match_nolit_encodeBetterBlockAsm10B: + MOVBU (R8)(R11), R16 + BFI $0, R16, $8, R10 + ADD R11, R9, R15 + MOVBU (R15), R15 + AND $0xff, R10, R16 + CMP R16, R15 + BNE match_nolit_end_encodeBetterBlockAsm10B + ADD $1, R11, R11 + MOVWU R11, R11 + +match_nolit_end_encodeBetterBlockAsm10B: + MOVWU R2, R7 + SUBW R5, R7, R7 + + // Check if repeat + MOVWU 24(RSP), R16 + CMPW R7, R16 + BEQ match_is_repeat_encodeBetterBlockAsm10B + MOVW R7, 24(RSP) + MOVWU 20(RSP), R5 + CMPW R6, R5 + BEQ emit_literal_done_match_emit_encodeBetterBlockAsm10B + MOVWU R6, R8 + MOVW R6, 20(RSP) + ADD R5, R3, R9 + SUBW R5, R8, R8 + SUB $1, R8, R5 + MOVWU R5, R5 + CMPW $0x3c, R5 + BLO one_byte_match_emit_encodeBetterBlockAsm10B + CMPW $0x00000100, R5 + BLO two_bytes_match_emit_encodeBetterBlockAsm10B + BLO three_bytes_match_emit_encodeBetterBlockAsm10B + +three_bytes_match_emit_encodeBetterBlockAsm10B: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R5, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_match_emit_encodeBetterBlockAsm10B + +two_bytes_match_emit_encodeBetterBlockAsm10B: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R5, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R5 + BLO memmove_match_emit_encodeBetterBlockAsm10B + JMP memmove_long_match_emit_encodeBetterBlockAsm10B + +one_byte_match_emit_encodeBetterBlockAsm10B: + LSLW $0x02, R5, R16 + BFI $0, R16, $8, R5 + MOVB R5, (R1) + ADD $0x01, R1, R1 + +memmove_match_emit_encodeBetterBlockAsm10B: + ADD R8, R1, R5 + + // genMemMoveShort + CMP $0x04, R8 + BLS emit_lit_memmove_match_emit_encodeBetterBlockAsm10B_memmove_move_4 + CMP $0x08, R8 + BLO emit_lit_memmove_match_emit_encodeBetterBlockAsm10B_memmove_move_4through7 + CMP $0x10, R8 + BLS emit_lit_memmove_match_emit_encodeBetterBlockAsm10B_memmove_move_8through16 + CMP $0x20, R8 + BLS emit_lit_memmove_match_emit_encodeBetterBlockAsm10B_memmove_move_17through32 + JMP emit_lit_memmove_match_emit_encodeBetterBlockAsm10B_memmove_move_33through64 + +emit_lit_memmove_match_emit_encodeBetterBlockAsm10B_memmove_move_4: + MOVWU (R9), R10 + MOVW R10, (R1) + JMP memmove_end_copy_match_emit_encodeBetterBlockAsm10B + +emit_lit_memmove_match_emit_encodeBetterBlockAsm10B_memmove_move_4through7: + MOVWU (R9), R10 + ADD R8, R9, R15 + MOVWU -4(R15), R9 + MOVW R10, (R1) + ADD R8, R1, R15 + MOVW R9, -4(R15) + JMP memmove_end_copy_match_emit_encodeBetterBlockAsm10B + +emit_lit_memmove_match_emit_encodeBetterBlockAsm10B_memmove_move_8through16: + MOVD (R9), R10 + ADD R8, R9, R15 + MOVD -8(R15), R9 + MOVD R10, (R1) + ADD R8, R1, R15 + MOVD R9, -8(R15) + JMP memmove_end_copy_match_emit_encodeBetterBlockAsm10B + +emit_lit_memmove_match_emit_encodeBetterBlockAsm10B_memmove_move_17through32: + FMOVQ (R9), F0 + ADD R8, R9, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_match_emit_encodeBetterBlockAsm10B + +emit_lit_memmove_match_emit_encodeBetterBlockAsm10B_memmove_move_33through64: + FMOVQ (R9), F0 + FMOVQ 16(R9), F1 + ADD R8, R9, R15 + FMOVQ -32(R15), F2 + ADD R8, R9, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R8, R1, R15 + FMOVQ F2, -32(R15) + ADD R8, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_match_emit_encodeBetterBlockAsm10B: + MOVD R5, R1 + JMP emit_literal_done_match_emit_encodeBetterBlockAsm10B + +memmove_long_match_emit_encodeBetterBlockAsm10B: + ADD R8, R1, R5 + + // genMemMoveLong + MOVD R9, R10 + MOVD R1, R12 + MOVD R8, R13 + +emit_lit_memmove_long_match_emit_encodeBetterBlockAsm10Blarge_big_loop_back: + FMOVQ (R10), F0 + FMOVQ 16(R10), F1 + FMOVQ F0, (R12) + FMOVQ F1, 16(R12) + ADD $0x20, R10, R10 + ADD $0x20, R12, R12 + SUB $0x20, R13, R13 + CMP $0x20, R13 + BHS emit_lit_memmove_long_match_emit_encodeBetterBlockAsm10Blarge_big_loop_back + ADD R8, R9, R15 + FMOVQ -32(R15), F0 + ADD R8, R9, R15 + FMOVQ -16(R15), F1 + ADD R8, R1, R15 + FMOVQ F0, -32(R15) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + MOVD R5, R1 + +emit_literal_done_match_emit_encodeBetterBlockAsm10B: + ADDW R11, R2, R2 + ADDW $0x04, R11, R11 + MOVW R2, 20(RSP) + + // emitCopy + CMPW $0x40, R11 + BLS two_byte_offset_short_match_nolit_encodeBetterBlockAsm10B + CMPW $0x00000800, R7 + BHS long_offset_short_match_nolit_encodeBetterBlockAsm10B + MOVD $0x00000001, R5 + ADD $16, R5, R5 + MOVWU R5, R5 + MOVB R7, 1(R1) + LSRW $0x08, R7, R7 + LSLW $0x05, R7, R7 + ORRW R7, R5, R5 + MOVB R5, (R1) + ADD $0x02, R1, R1 + SUBW $0x08, R11, R11 + + // emitRepeat + SUB $4, R11, R11 + MOVWU R11, R11 + JMP cant_repeat_two_offset_match_nolit_encodeBetterBlockAsm10B_emit_copy_short_2b + MOVWU R11, R5 + SUB $4, R11, R11 + MOVWU R11, R11 + CMPW $0x08, R5 + BLS repeat_two_match_nolit_encodeBetterBlockAsm10B_emit_copy_short_2b + CMPW $0x0c, R5 + BHS cant_repeat_two_offset_match_nolit_encodeBetterBlockAsm10B_emit_copy_short_2b + CMPW $0x00000800, R7 + BLO repeat_two_offset_match_nolit_encodeBetterBlockAsm10B_emit_copy_short_2b + +cant_repeat_two_offset_match_nolit_encodeBetterBlockAsm10B_emit_copy_short_2b: + CMPW $0x00000104, R11 + BLO repeat_three_match_nolit_encodeBetterBlockAsm10B_emit_copy_short_2b + SUB $256, R11, R11 + MOVWU R11, R11 + MOVD $0x0019, R16 + MOVH R16, (R1) + MOVH R11, 2(R1) + ADD $0x04, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm10B + +repeat_three_match_nolit_encodeBetterBlockAsm10B_emit_copy_short_2b: + SUB $4, R11, R11 + MOVWU R11, R11 + MOVD $0x0015, R16 + MOVH R16, (R1) + MOVB R11, 2(R1) + ADD $0x03, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm10B + +repeat_two_match_nolit_encodeBetterBlockAsm10B_emit_copy_short_2b: + LSLW $0x02, R11, R11 + ORRW $0x01, R11, R11 + MOVH R11, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm10B + +repeat_two_offset_match_nolit_encodeBetterBlockAsm10B_emit_copy_short_2b: + MOVD $0, R5 + ADD R11<<2, R5, R11 + ADD $1, R11, R11 + MOVWU R11, R11 + MOVB R7, 1(R1) + ASRW $0x08, R7, R7 + LSLW $0x05, R7, R7 + ORRW R7, R11, R11 + MOVB R11, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm10B + +long_offset_short_match_nolit_encodeBetterBlockAsm10B: + MOVD $0xee, R16 + MOVB R16, (R1) + MOVH R7, 1(R1) + SUB $60, R11, R11 + MOVWU R11, R11 + ADD $0x03, R1, R1 + + // emitRepeat + MOVWU R11, R5 + SUB $4, R11, R11 + MOVWU R11, R11 + CMPW $0x08, R5 + BLS repeat_two_match_nolit_encodeBetterBlockAsm10B_emit_copy_short + CMPW $0x0c, R5 + BHS cant_repeat_two_offset_match_nolit_encodeBetterBlockAsm10B_emit_copy_short + CMPW $0x00000800, R7 + BLO repeat_two_offset_match_nolit_encodeBetterBlockAsm10B_emit_copy_short + +cant_repeat_two_offset_match_nolit_encodeBetterBlockAsm10B_emit_copy_short: + CMPW $0x00000104, R11 + BLO repeat_three_match_nolit_encodeBetterBlockAsm10B_emit_copy_short + SUB $256, R11, R11 + MOVWU R11, R11 + MOVD $0x0019, R16 + MOVH R16, (R1) + MOVH R11, 2(R1) + ADD $0x04, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm10B + +repeat_three_match_nolit_encodeBetterBlockAsm10B_emit_copy_short: + SUB $4, R11, R11 + MOVWU R11, R11 + MOVD $0x0015, R16 + MOVH R16, (R1) + MOVB R11, 2(R1) + ADD $0x03, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm10B + +repeat_two_match_nolit_encodeBetterBlockAsm10B_emit_copy_short: + LSLW $0x02, R11, R11 + ORRW $0x01, R11, R11 + MOVH R11, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm10B + +repeat_two_offset_match_nolit_encodeBetterBlockAsm10B_emit_copy_short: + MOVD $0, R5 + ADD R11<<2, R5, R11 + ADD $1, R11, R11 + MOVWU R11, R11 + MOVB R7, 1(R1) + ASRW $0x08, R7, R7 + LSLW $0x05, R7, R7 + ORRW R7, R11, R11 + MOVB R11, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm10B + +two_byte_offset_short_match_nolit_encodeBetterBlockAsm10B: + MOVWU R11, R5 + LSLW $0x02, R5, R5 + CMPW $0x0c, R11 + BHS emit_copy_three_match_nolit_encodeBetterBlockAsm10B + CMPW $0x00000800, R7 + BHS emit_copy_three_match_nolit_encodeBetterBlockAsm10B + SUB $15, R5, R5 + MOVWU R5, R5 + MOVB R7, 1(R1) + LSRW $0x08, R7, R7 + LSLW $0x05, R7, R7 + ORRW R7, R5, R5 + MOVB R5, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm10B + +emit_copy_three_match_nolit_encodeBetterBlockAsm10B: + SUB $2, R5, R5 + MOVWU R5, R5 + MOVB R5, (R1) + MOVH R7, 1(R1) + ADD $0x03, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm10B + +match_is_repeat_encodeBetterBlockAsm10B: + MOVWU 20(RSP), R5 + CMPW R6, R5 + BEQ emit_literal_done_match_emit_repeat_encodeBetterBlockAsm10B + MOVWU R6, R8 + MOVW R6, 20(RSP) + ADD R5, R3, R9 + SUBW R5, R8, R8 + SUB $1, R8, R5 + MOVWU R5, R5 + CMPW $0x3c, R5 + BLO one_byte_match_emit_repeat_encodeBetterBlockAsm10B + CMPW $0x00000100, R5 + BLO two_bytes_match_emit_repeat_encodeBetterBlockAsm10B + BLO three_bytes_match_emit_repeat_encodeBetterBlockAsm10B + +three_bytes_match_emit_repeat_encodeBetterBlockAsm10B: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R5, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_match_emit_repeat_encodeBetterBlockAsm10B + +two_bytes_match_emit_repeat_encodeBetterBlockAsm10B: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R5, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R5 + BLO memmove_match_emit_repeat_encodeBetterBlockAsm10B + JMP memmove_long_match_emit_repeat_encodeBetterBlockAsm10B + +one_byte_match_emit_repeat_encodeBetterBlockAsm10B: + LSLW $0x02, R5, R16 + BFI $0, R16, $8, R5 + MOVB R5, (R1) + ADD $0x01, R1, R1 + +memmove_match_emit_repeat_encodeBetterBlockAsm10B: + ADD R8, R1, R5 + + // genMemMoveShort + CMP $0x04, R8 + BLS emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm10B_memmove_move_4 + CMP $0x08, R8 + BLO emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm10B_memmove_move_4through7 + CMP $0x10, R8 + BLS emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm10B_memmove_move_8through16 + CMP $0x20, R8 + BLS emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm10B_memmove_move_17through32 + JMP emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm10B_memmove_move_33through64 + +emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm10B_memmove_move_4: + MOVWU (R9), R10 + MOVW R10, (R1) + JMP memmove_end_copy_match_emit_repeat_encodeBetterBlockAsm10B + +emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm10B_memmove_move_4through7: + MOVWU (R9), R10 + ADD R8, R9, R15 + MOVWU -4(R15), R9 + MOVW R10, (R1) + ADD R8, R1, R15 + MOVW R9, -4(R15) + JMP memmove_end_copy_match_emit_repeat_encodeBetterBlockAsm10B + +emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm10B_memmove_move_8through16: + MOVD (R9), R10 + ADD R8, R9, R15 + MOVD -8(R15), R9 + MOVD R10, (R1) + ADD R8, R1, R15 + MOVD R9, -8(R15) + JMP memmove_end_copy_match_emit_repeat_encodeBetterBlockAsm10B + +emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm10B_memmove_move_17through32: + FMOVQ (R9), F0 + ADD R8, R9, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_match_emit_repeat_encodeBetterBlockAsm10B + +emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm10B_memmove_move_33through64: + FMOVQ (R9), F0 + FMOVQ 16(R9), F1 + ADD R8, R9, R15 + FMOVQ -32(R15), F2 + ADD R8, R9, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R8, R1, R15 + FMOVQ F2, -32(R15) + ADD R8, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_match_emit_repeat_encodeBetterBlockAsm10B: + MOVD R5, R1 + JMP emit_literal_done_match_emit_repeat_encodeBetterBlockAsm10B + +memmove_long_match_emit_repeat_encodeBetterBlockAsm10B: + ADD R8, R1, R5 + + // genMemMoveLong + MOVD R9, R10 + MOVD R1, R12 + MOVD R8, R13 + +emit_lit_memmove_long_match_emit_repeat_encodeBetterBlockAsm10Blarge_big_loop_back: + FMOVQ (R10), F0 + FMOVQ 16(R10), F1 + FMOVQ F0, (R12) + FMOVQ F1, 16(R12) + ADD $0x20, R10, R10 + ADD $0x20, R12, R12 + SUB $0x20, R13, R13 + CMP $0x20, R13 + BHS emit_lit_memmove_long_match_emit_repeat_encodeBetterBlockAsm10Blarge_big_loop_back + ADD R8, R9, R15 + FMOVQ -32(R15), F0 + ADD R8, R9, R15 + FMOVQ -16(R15), F1 + ADD R8, R1, R15 + FMOVQ F0, -32(R15) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + MOVD R5, R1 + +emit_literal_done_match_emit_repeat_encodeBetterBlockAsm10B: + ADDW R11, R2, R2 + ADDW $0x04, R11, R11 + MOVW R2, 20(RSP) + + // emitRepeat + MOVWU R11, R5 + SUB $4, R11, R11 + MOVWU R11, R11 + CMPW $0x08, R5 + BLS repeat_two_match_nolit_repeat_encodeBetterBlockAsm10B + CMPW $0x0c, R5 + BHS cant_repeat_two_offset_match_nolit_repeat_encodeBetterBlockAsm10B + CMPW $0x00000800, R7 + BLO repeat_two_offset_match_nolit_repeat_encodeBetterBlockAsm10B + +cant_repeat_two_offset_match_nolit_repeat_encodeBetterBlockAsm10B: + CMPW $0x00000104, R11 + BLO repeat_three_match_nolit_repeat_encodeBetterBlockAsm10B + SUB $256, R11, R11 + MOVWU R11, R11 + MOVD $0x0019, R16 + MOVH R16, (R1) + MOVH R11, 2(R1) + ADD $0x04, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm10B + +repeat_three_match_nolit_repeat_encodeBetterBlockAsm10B: + SUB $4, R11, R11 + MOVWU R11, R11 + MOVD $0x0015, R16 + MOVH R16, (R1) + MOVB R11, 2(R1) + ADD $0x03, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm10B + +repeat_two_match_nolit_repeat_encodeBetterBlockAsm10B: + LSLW $0x02, R11, R11 + ORRW $0x01, R11, R11 + MOVH R11, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm10B + +repeat_two_offset_match_nolit_repeat_encodeBetterBlockAsm10B: + MOVD $0, R5 + ADD R11<<2, R5, R11 + ADD $1, R11, R11 + MOVWU R11, R11 + MOVB R7, 1(R1) + ASRW $0x08, R7, R7 + LSLW $0x05, R7, R7 + ORRW R7, R11, R11 + MOVB R11, (R1) + ADD $0x02, R1, R1 + +match_nolit_emitcopy_end_encodeBetterBlockAsm10B: + MOVWU 16(RSP), R16 + CMPW R16, R2 + BHS emit_remainder_encodeBetterBlockAsm10B + MOVD 8(RSP), R16 + CMP R16, R1 + BLO match_nolit_dst_ok_encodeBetterBlockAsm10B + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +match_nolit_dst_ok_encodeBetterBlockAsm10B: + MOVD $0x0000cf1bbcdcbf9b, R5 + MOVD $0x9e3779b1, R7 + ADD $1, R6, R6 + SUB $2, R2, R8 + MOVD (R3)(R6), R9 + ADD R6, R3, R15 + MOVD 1(R15), R10 + MOVD (R3)(R8), R11 + ADD R8, R3, R15 + MOVD 1(R15), R12 + LSL $0x10, R9, R9 + MUL R5, R9, R9 + LSR $0x34, R9, R9 + LSL $0x20, R10, R10 + MUL R7, R10, R10 + LSR $0x36, R10, R10 + LSL $0x10, R11, R11 + MUL R5, R11, R11 + LSR $0x34, R11, R11 + LSL $0x20, R12, R12 + MUL R7, R12, R12 + LSR $0x36, R12, R12 + ADD $1, R6, R7 + ADD $1, R8, R13 + MOVW R6, (R0)(R9<<2) + MOVW R8, (R0)(R11<<2) + ADD R10<<2, R0, R15 + MOVW R7, 16384(R15) + ADD R12<<2, R0, R15 + MOVW R13, 16384(R15) + ADD R6, R8, R7 + ADD $1, R7, R7 + LSR $0x01, R7, R7 + ADD $0x01, R6, R6 + SUB $0x01, R8, R8 + +index_loop_encodeBetterBlockAsm10B: + CMP R8, R7 + BHS search_loop_encodeBetterBlockAsm10B + MOVD (R3)(R6), R9 + MOVD (R3)(R7), R10 + LSL $0x10, R9, R9 + MUL R5, R9, R9 + LSR $0x34, R9, R9 + LSL $0x10, R10, R10 + MUL R5, R10, R10 + LSR $0x34, R10, R10 + MOVW R6, (R0)(R9<<2) + MOVW R7, (R0)(R10<<2) + ADD $0x02, R6, R6 + ADD $0x02, R7, R7 + JMP index_loop_encodeBetterBlockAsm10B + +emit_remainder_encodeBetterBlockAsm10B: + MOVD src_len+32(FP), R0 + MOVWU 20(RSP), R16 + SUBW R16, R0, R0 + ADD R0, R1, R0 + ADD $3, R0, R0 + MOVD 8(RSP), R16 + CMP R16, R0 + BLO emit_remainder_ok_encodeBetterBlockAsm10B + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +emit_remainder_ok_encodeBetterBlockAsm10B: + MOVD src_len+32(FP), R0 + MOVWU 20(RSP), R2 + CMPW R0, R2 + BEQ emit_literal_done_emit_remainder_encodeBetterBlockAsm10B + MOVWU R0, R5 + MOVW R0, 20(RSP) + ADD R2, R3, R0 + SUBW R2, R5, R5 + SUB $1, R5, R2 + MOVWU R2, R2 + CMPW $0x3c, R2 + BLO one_byte_emit_remainder_encodeBetterBlockAsm10B + CMPW $0x00000100, R2 + BLO two_bytes_emit_remainder_encodeBetterBlockAsm10B + BLO three_bytes_emit_remainder_encodeBetterBlockAsm10B + +three_bytes_emit_remainder_encodeBetterBlockAsm10B: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R2, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_emit_remainder_encodeBetterBlockAsm10B + +two_bytes_emit_remainder_encodeBetterBlockAsm10B: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R2, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R2 + BLO memmove_emit_remainder_encodeBetterBlockAsm10B + JMP memmove_long_emit_remainder_encodeBetterBlockAsm10B + +one_byte_emit_remainder_encodeBetterBlockAsm10B: + LSLW $0x02, R2, R16 + BFI $0, R16, $8, R2 + MOVB R2, (R1) + ADD $0x01, R1, R1 + +memmove_emit_remainder_encodeBetterBlockAsm10B: + ADD R5, R1, R2 + MOVWU R5, R3 + + // genMemMoveShort + CMP $0x03, R3 + BLO emit_lit_memmove_emit_remainder_encodeBetterBlockAsm10B_memmove_move_1or2 + BEQ emit_lit_memmove_emit_remainder_encodeBetterBlockAsm10B_memmove_move_3 + CMP $0x08, R3 + BLO emit_lit_memmove_emit_remainder_encodeBetterBlockAsm10B_memmove_move_4through7 + CMP $0x10, R3 + BLS emit_lit_memmove_emit_remainder_encodeBetterBlockAsm10B_memmove_move_8through16 + CMP $0x20, R3 + BLS emit_lit_memmove_emit_remainder_encodeBetterBlockAsm10B_memmove_move_17through32 + JMP emit_lit_memmove_emit_remainder_encodeBetterBlockAsm10B_memmove_move_33through64 + +emit_lit_memmove_emit_remainder_encodeBetterBlockAsm10B_memmove_move_1or2: + MOVBU (R0), R16 + BFI $0, R16, $8, R5 + ADD R3, R0, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R0 + MOVB R5, (R1) + ADD R3, R1, R15 + MOVB R0, -1(R15) + JMP memmove_end_copy_emit_remainder_encodeBetterBlockAsm10B + +emit_lit_memmove_emit_remainder_encodeBetterBlockAsm10B_memmove_move_3: + MOVHU (R0), R16 + BFI $0, R16, $16, R5 + MOVBU 2(R0), R16 + BFI $0, R16, $8, R0 + MOVH R5, (R1) + MOVB R0, 2(R1) + JMP memmove_end_copy_emit_remainder_encodeBetterBlockAsm10B + +emit_lit_memmove_emit_remainder_encodeBetterBlockAsm10B_memmove_move_4through7: + MOVWU (R0), R5 + ADD R3, R0, R15 + MOVWU -4(R15), R0 + MOVW R5, (R1) + ADD R3, R1, R15 + MOVW R0, -4(R15) + JMP memmove_end_copy_emit_remainder_encodeBetterBlockAsm10B + +emit_lit_memmove_emit_remainder_encodeBetterBlockAsm10B_memmove_move_8through16: + MOVD (R0), R5 + ADD R3, R0, R15 + MOVD -8(R15), R0 + MOVD R5, (R1) + ADD R3, R1, R15 + MOVD R0, -8(R15) + JMP memmove_end_copy_emit_remainder_encodeBetterBlockAsm10B + +emit_lit_memmove_emit_remainder_encodeBetterBlockAsm10B_memmove_move_17through32: + FMOVQ (R0), F0 + ADD R3, R0, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R3, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_emit_remainder_encodeBetterBlockAsm10B + +emit_lit_memmove_emit_remainder_encodeBetterBlockAsm10B_memmove_move_33through64: + FMOVQ (R0), F0 + FMOVQ 16(R0), F1 + ADD R3, R0, R15 + FMOVQ -32(R15), F2 + ADD R3, R0, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R3, R1, R15 + FMOVQ F2, -32(R15) + ADD R3, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_emit_remainder_encodeBetterBlockAsm10B: + MOVD R2, R1 + JMP emit_literal_done_emit_remainder_encodeBetterBlockAsm10B + +memmove_long_emit_remainder_encodeBetterBlockAsm10B: + ADD R5, R1, R2 + MOVWU R5, R3 + + // genMemMoveLong + MOVD R0, R5 + MOVD R1, R6 + MOVD R3, R7 + +emit_lit_memmove_long_emit_remainder_encodeBetterBlockAsm10Blarge_big_loop_back: + FMOVQ (R5), F0 + FMOVQ 16(R5), F1 + FMOVQ F0, (R6) + FMOVQ F1, 16(R6) + ADD $0x20, R5, R5 + ADD $0x20, R6, R6 + SUB $0x20, R7, R7 + CMP $0x20, R7 + BHS emit_lit_memmove_long_emit_remainder_encodeBetterBlockAsm10Blarge_big_loop_back + ADD R3, R0, R15 + FMOVQ -32(R15), F0 + ADD R3, R0, R15 + FMOVQ -16(R15), F1 + ADD R3, R1, R15 + FMOVQ F0, -32(R15) + ADD R3, R1, R15 + FMOVQ F1, -16(R15) + MOVD R2, R1 + +emit_literal_done_emit_remainder_encodeBetterBlockAsm10B: + MOVD dst_base+0(FP), R0 + SUB R0, R1, R1 + MOVD R1, ret+56(FP) + RET + +// func encodeBetterBlockAsm8B(dst []byte, src []byte, tmp *[5120]byte) int +// Requires: BMI, SSE2 +TEXT ·encodeBetterBlockAsm8B(SB), $24-64 + MOVD tmp+48(FP), R0 + MOVD dst_base+0(FP), R1 + MOVD $0x00000028, R2 + MOVD R0, R3 + VEOR V0.B16, V0.B16, V0.B16 + +zero_loop_encodeBetterBlockAsm8B: + FMOVQ F0, (R3) + FMOVQ F0, 16(R3) + FMOVQ F0, 32(R3) + FMOVQ F0, 48(R3) + FMOVQ F0, 64(R3) + FMOVQ F0, 80(R3) + FMOVQ F0, 96(R3) + FMOVQ F0, 112(R3) + ADD $0x80, R3, R3 + SUBS $1, R2, R2 + BNE zero_loop_encodeBetterBlockAsm8B + MOVD $0x00000000, R16 + MOVW R16, 20(RSP) + MOVD src_len+32(FP), R2 + SUB $6, R2, R3 + SUB $8, R2, R5 + MOVW R5, 16(RSP) + LSR $0x05, R2, R2 + SUBW R2, R3, R3 + ADD R3, R1, R3 + MOVD R3, 8(RSP) + MOVD $0x00000001, R2 + MOVD $0x00000000, R16 + MOVW R16, 24(RSP) + MOVD src_base+24(FP), R3 + +search_loop_encodeBetterBlockAsm8B: + MOVWU R2, R5 + MOVWU 20(RSP), R16 + SUBW R16, R5, R5 + LSRW $0x04, R5, R5 + ADD R5, R2, R5 + ADD $1, R5, R5 + MOVWU R5, R5 + MOVWU 16(RSP), R16 + CMPW R16, R5 + BHS emit_remainder_encodeBetterBlockAsm8B + MOVD (R3)(R2), R6 + MOVW R5, 28(RSP) + MOVD $0x0000cf1bbcdcbf9b, R8 + MOVD $0x9e3779b1, R5 + MOVD R6, R9 + MOVD R6, R10 + LSL $0x10, R9, R9 + MUL R8, R9, R9 + LSR $0x36, R9, R9 + LSL $0x20, R10, R10 + MUL R5, R10, R10 + LSR $0x38, R10, R10 + MOVWU (R0)(R9<<2), R5 + ADD R10<<2, R0, R15 + MOVWU 4096(R15), R7 + MOVW R2, (R0)(R9<<2) + ADD R10<<2, R0, R15 + MOVW R2, 4096(R15) + MOVD (R3)(R5), R9 + MOVD (R3)(R7), R10 + CMP R6, R9 + BEQ candidate_match_encodeBetterBlockAsm8B + CMP R6, R10 + BNE no_short_found_encodeBetterBlockAsm8B + MOVWU R7, R5 + JMP candidate_match_encodeBetterBlockAsm8B + +no_short_found_encodeBetterBlockAsm8B: + CMPW R6, R9 + BEQ candidate_match_encodeBetterBlockAsm8B + CMPW R6, R10 + BEQ candidateS_match_encodeBetterBlockAsm8B + MOVWU 28(RSP), R2 + JMP search_loop_encodeBetterBlockAsm8B + +candidateS_match_encodeBetterBlockAsm8B: + LSR $0x08, R6, R6 + MOVD R6, R9 + LSL $0x10, R9, R9 + MUL R8, R9, R9 + LSR $0x36, R9, R9 + MOVWU (R0)(R9<<2), R5 + ADDW $1, R2, R2 + MOVW R2, (R0)(R9<<2) + MOVWU (R3)(R5), R16 + CMPW R6, R16 + BEQ candidate_match_encodeBetterBlockAsm8B + SUBW $1, R2, R2 + MOVWU R7, R5 + +candidate_match_encodeBetterBlockAsm8B: + MOVWU 20(RSP), R6 + TSTW R5, R5 + BEQ match_extend_back_end_encodeBetterBlockAsm8B + +match_extend_back_loop_encodeBetterBlockAsm8B: + CMPW R6, R2 + BLS match_extend_back_end_encodeBetterBlockAsm8B + ADD R5, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R7 + ADD R2, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R8 + AND $0xff, R8, R16 + AND $0xff, R7, R15 + CMP R16, R15 + BNE match_extend_back_end_encodeBetterBlockAsm8B + SUB $1, R2, R2 + MOVWU R2, R2 + SUBSW $1, R5, R5 + BEQ match_extend_back_end_encodeBetterBlockAsm8B + JMP match_extend_back_loop_encodeBetterBlockAsm8B + +match_extend_back_end_encodeBetterBlockAsm8B: + MOVWU R2, R6 + MOVWU 20(RSP), R16 + SUBW R16, R6, R6 + ADD R6, R1, R6 + ADD $3, R6, R6 + MOVD 8(RSP), R16 + CMP R16, R6 + BLO match_dst_size_check_encodeBetterBlockAsm8B + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +match_dst_size_check_encodeBetterBlockAsm8B: + MOVWU R2, R6 + ADDW $0x04, R2, R2 + ADDW $0x04, R5, R5 + MOVD src_len+32(FP), R7 + SUBW R2, R7, R7 + ADD R2, R3, R8 + ADD R5, R3, R9 + + // matchLen + MOVD $0, R11 + +matchlen_loopback_16_match_nolit_encodeBetterBlockAsm8B: + CMPW $0x10, R7 + BLO matchlen_match8_match_nolit_encodeBetterBlockAsm8B + MOVD (R8)(R11), R10 + ADD R11, R8, R15 + MOVD 8(R15), R12 + MOVD (R9)(R11), R16 + EOR R16, R10, R10 + TST R10, R10 + BNE matchlen_bsf_8_match_nolit_encodeBetterBlockAsm8B + ADD R11, R9, R15 + MOVD 8(R15), R16 + EOR R16, R12, R12 + TST R12, R12 + BNE matchlen_bsf_16match_nolit_encodeBetterBlockAsm8B + SUB $16, R7, R7 + MOVWU R7, R7 + ADD $16, R11, R11 + MOVWU R11, R11 + JMP matchlen_loopback_16_match_nolit_encodeBetterBlockAsm8B + +matchlen_bsf_16match_nolit_encodeBetterBlockAsm8B: + RBIT R12, R12 + CLZ R12, R12 + ASR $0x03, R12, R12 + ADD R12, R11, R11 + ADD $8, R11, R11 + MOVWU R11, R11 + JMP match_nolit_end_encodeBetterBlockAsm8B + +matchlen_match8_match_nolit_encodeBetterBlockAsm8B: + CMPW $0x08, R7 + BLO matchlen_match4_match_nolit_encodeBetterBlockAsm8B + MOVD (R8)(R11), R10 + MOVD (R9)(R11), R16 + EOR R16, R10, R10 + TST R10, R10 + BNE matchlen_bsf_8_match_nolit_encodeBetterBlockAsm8B + SUB $8, R7, R7 + MOVWU R7, R7 + ADD $8, R11, R11 + MOVWU R11, R11 + JMP matchlen_match4_match_nolit_encodeBetterBlockAsm8B + +matchlen_bsf_8_match_nolit_encodeBetterBlockAsm8B: + RBIT R10, R10 + CLZ R10, R10 + ASR $0x03, R10, R10 + ADD R10, R11, R11 + MOVWU R11, R11 + JMP match_nolit_end_encodeBetterBlockAsm8B + +matchlen_match4_match_nolit_encodeBetterBlockAsm8B: + CMPW $0x04, R7 + BLO matchlen_match2_match_nolit_encodeBetterBlockAsm8B + MOVWU (R8)(R11), R10 + MOVWU (R9)(R11), R16 + CMPW R10, R16 + BNE matchlen_match2_match_nolit_encodeBetterBlockAsm8B + SUB $4, R7, R7 + MOVWU R7, R7 + ADD $4, R11, R11 + MOVWU R11, R11 + +matchlen_match2_match_nolit_encodeBetterBlockAsm8B: + CMPW $0x01, R7 + BEQ matchlen_match1_match_nolit_encodeBetterBlockAsm8B + BLO match_nolit_end_encodeBetterBlockAsm8B + MOVHU (R8)(R11), R16 + BFI $0, R16, $16, R10 + ADD R11, R9, R15 + MOVHU (R15), R15 + AND $0xffff, R10, R16 + CMP R16, R15 + BNE matchlen_match1_match_nolit_encodeBetterBlockAsm8B + ADD $2, R11, R11 + MOVWU R11, R11 + SUBSW $0x02, R7, R7 + BEQ match_nolit_end_encodeBetterBlockAsm8B + +matchlen_match1_match_nolit_encodeBetterBlockAsm8B: + MOVBU (R8)(R11), R16 + BFI $0, R16, $8, R10 + ADD R11, R9, R15 + MOVBU (R15), R15 + AND $0xff, R10, R16 + CMP R16, R15 + BNE match_nolit_end_encodeBetterBlockAsm8B + ADD $1, R11, R11 + MOVWU R11, R11 + +match_nolit_end_encodeBetterBlockAsm8B: + MOVWU R2, R7 + SUBW R5, R7, R7 + + // Check if repeat + MOVWU 24(RSP), R16 + CMPW R7, R16 + BEQ match_is_repeat_encodeBetterBlockAsm8B + MOVW R7, 24(RSP) + MOVWU 20(RSP), R5 + CMPW R6, R5 + BEQ emit_literal_done_match_emit_encodeBetterBlockAsm8B + MOVWU R6, R8 + MOVW R6, 20(RSP) + ADD R5, R3, R9 + SUBW R5, R8, R8 + SUB $1, R8, R5 + MOVWU R5, R5 + CMPW $0x3c, R5 + BLO one_byte_match_emit_encodeBetterBlockAsm8B + CMPW $0x00000100, R5 + BLO two_bytes_match_emit_encodeBetterBlockAsm8B + BLO three_bytes_match_emit_encodeBetterBlockAsm8B + +three_bytes_match_emit_encodeBetterBlockAsm8B: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R5, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_match_emit_encodeBetterBlockAsm8B + +two_bytes_match_emit_encodeBetterBlockAsm8B: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R5, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R5 + BLO memmove_match_emit_encodeBetterBlockAsm8B + JMP memmove_long_match_emit_encodeBetterBlockAsm8B + +one_byte_match_emit_encodeBetterBlockAsm8B: + LSLW $0x02, R5, R16 + BFI $0, R16, $8, R5 + MOVB R5, (R1) + ADD $0x01, R1, R1 + +memmove_match_emit_encodeBetterBlockAsm8B: + ADD R8, R1, R5 + + // genMemMoveShort + CMP $0x04, R8 + BLS emit_lit_memmove_match_emit_encodeBetterBlockAsm8B_memmove_move_4 + CMP $0x08, R8 + BLO emit_lit_memmove_match_emit_encodeBetterBlockAsm8B_memmove_move_4through7 + CMP $0x10, R8 + BLS emit_lit_memmove_match_emit_encodeBetterBlockAsm8B_memmove_move_8through16 + CMP $0x20, R8 + BLS emit_lit_memmove_match_emit_encodeBetterBlockAsm8B_memmove_move_17through32 + JMP emit_lit_memmove_match_emit_encodeBetterBlockAsm8B_memmove_move_33through64 + +emit_lit_memmove_match_emit_encodeBetterBlockAsm8B_memmove_move_4: + MOVWU (R9), R10 + MOVW R10, (R1) + JMP memmove_end_copy_match_emit_encodeBetterBlockAsm8B + +emit_lit_memmove_match_emit_encodeBetterBlockAsm8B_memmove_move_4through7: + MOVWU (R9), R10 + ADD R8, R9, R15 + MOVWU -4(R15), R9 + MOVW R10, (R1) + ADD R8, R1, R15 + MOVW R9, -4(R15) + JMP memmove_end_copy_match_emit_encodeBetterBlockAsm8B + +emit_lit_memmove_match_emit_encodeBetterBlockAsm8B_memmove_move_8through16: + MOVD (R9), R10 + ADD R8, R9, R15 + MOVD -8(R15), R9 + MOVD R10, (R1) + ADD R8, R1, R15 + MOVD R9, -8(R15) + JMP memmove_end_copy_match_emit_encodeBetterBlockAsm8B + +emit_lit_memmove_match_emit_encodeBetterBlockAsm8B_memmove_move_17through32: + FMOVQ (R9), F0 + ADD R8, R9, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_match_emit_encodeBetterBlockAsm8B + +emit_lit_memmove_match_emit_encodeBetterBlockAsm8B_memmove_move_33through64: + FMOVQ (R9), F0 + FMOVQ 16(R9), F1 + ADD R8, R9, R15 + FMOVQ -32(R15), F2 + ADD R8, R9, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R8, R1, R15 + FMOVQ F2, -32(R15) + ADD R8, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_match_emit_encodeBetterBlockAsm8B: + MOVD R5, R1 + JMP emit_literal_done_match_emit_encodeBetterBlockAsm8B + +memmove_long_match_emit_encodeBetterBlockAsm8B: + ADD R8, R1, R5 + + // genMemMoveLong + MOVD R9, R10 + MOVD R1, R12 + MOVD R8, R13 + +emit_lit_memmove_long_match_emit_encodeBetterBlockAsm8Blarge_big_loop_back: + FMOVQ (R10), F0 + FMOVQ 16(R10), F1 + FMOVQ F0, (R12) + FMOVQ F1, 16(R12) + ADD $0x20, R10, R10 + ADD $0x20, R12, R12 + SUB $0x20, R13, R13 + CMP $0x20, R13 + BHS emit_lit_memmove_long_match_emit_encodeBetterBlockAsm8Blarge_big_loop_back + ADD R8, R9, R15 + FMOVQ -32(R15), F0 + ADD R8, R9, R15 + FMOVQ -16(R15), F1 + ADD R8, R1, R15 + FMOVQ F0, -32(R15) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + MOVD R5, R1 + +emit_literal_done_match_emit_encodeBetterBlockAsm8B: + ADDW R11, R2, R2 + ADDW $0x04, R11, R11 + MOVW R2, 20(RSP) + + // emitCopy + CMPW $0x40, R11 + BLS two_byte_offset_short_match_nolit_encodeBetterBlockAsm8B + CMPW $0x00000800, R7 + BHS long_offset_short_match_nolit_encodeBetterBlockAsm8B + MOVD $0x00000001, R5 + ADD $16, R5, R5 + MOVWU R5, R5 + MOVB R7, 1(R1) + LSRW $0x08, R7, R7 + LSLW $0x05, R7, R7 + ORRW R7, R5, R5 + MOVB R5, (R1) + ADD $0x02, R1, R1 + SUBW $0x08, R11, R11 + + // emitRepeat + SUB $4, R11, R11 + MOVWU R11, R11 + JMP cant_repeat_two_offset_match_nolit_encodeBetterBlockAsm8B_emit_copy_short_2b + MOVWU R11, R5 + SUB $4, R11, R11 + MOVWU R11, R11 + CMPW $0x08, R5 + BLS repeat_two_match_nolit_encodeBetterBlockAsm8B_emit_copy_short_2b + CMPW $0x0c, R5 + BHS cant_repeat_two_offset_match_nolit_encodeBetterBlockAsm8B_emit_copy_short_2b + +cant_repeat_two_offset_match_nolit_encodeBetterBlockAsm8B_emit_copy_short_2b: + CMPW $0x00000104, R11 + BLO repeat_three_match_nolit_encodeBetterBlockAsm8B_emit_copy_short_2b + SUB $256, R11, R11 + MOVWU R11, R11 + MOVD $0x0019, R16 + MOVH R16, (R1) + MOVH R11, 2(R1) + ADD $0x04, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm8B + +repeat_three_match_nolit_encodeBetterBlockAsm8B_emit_copy_short_2b: + SUB $4, R11, R11 + MOVWU R11, R11 + MOVD $0x0015, R16 + MOVH R16, (R1) + MOVB R11, 2(R1) + ADD $0x03, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm8B + +repeat_two_match_nolit_encodeBetterBlockAsm8B_emit_copy_short_2b: + LSLW $0x02, R11, R11 + ORRW $0x01, R11, R11 + MOVH R11, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm8B + MOVD $0, R5 + ADD R11<<2, R5, R11 + ADD $1, R11, R11 + MOVWU R11, R11 + MOVB R7, 1(R1) + ASRW $0x08, R7, R7 + LSLW $0x05, R7, R7 + ORRW R7, R11, R11 + MOVB R11, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm8B + +long_offset_short_match_nolit_encodeBetterBlockAsm8B: + MOVD $0xee, R16 + MOVB R16, (R1) + MOVH R7, 1(R1) + SUB $60, R11, R11 + MOVWU R11, R11 + ADD $0x03, R1, R1 + + // emitRepeat + MOVWU R11, R5 + SUB $4, R11, R11 + MOVWU R11, R11 + CMPW $0x08, R5 + BLS repeat_two_match_nolit_encodeBetterBlockAsm8B_emit_copy_short + CMPW $0x0c, R5 + BHS cant_repeat_two_offset_match_nolit_encodeBetterBlockAsm8B_emit_copy_short + +cant_repeat_two_offset_match_nolit_encodeBetterBlockAsm8B_emit_copy_short: + CMPW $0x00000104, R11 + BLO repeat_three_match_nolit_encodeBetterBlockAsm8B_emit_copy_short + SUB $256, R11, R11 + MOVWU R11, R11 + MOVD $0x0019, R16 + MOVH R16, (R1) + MOVH R11, 2(R1) + ADD $0x04, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm8B + +repeat_three_match_nolit_encodeBetterBlockAsm8B_emit_copy_short: + SUB $4, R11, R11 + MOVWU R11, R11 + MOVD $0x0015, R16 + MOVH R16, (R1) + MOVB R11, 2(R1) + ADD $0x03, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm8B + +repeat_two_match_nolit_encodeBetterBlockAsm8B_emit_copy_short: + LSLW $0x02, R11, R11 + ORRW $0x01, R11, R11 + MOVH R11, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm8B + MOVD $0, R5 + ADD R11<<2, R5, R11 + ADD $1, R11, R11 + MOVWU R11, R11 + MOVB R7, 1(R1) + ASRW $0x08, R7, R7 + LSLW $0x05, R7, R7 + ORRW R7, R11, R11 + MOVB R11, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm8B + +two_byte_offset_short_match_nolit_encodeBetterBlockAsm8B: + MOVWU R11, R5 + LSLW $0x02, R5, R5 + CMPW $0x0c, R11 + BHS emit_copy_three_match_nolit_encodeBetterBlockAsm8B + SUB $15, R5, R5 + MOVWU R5, R5 + MOVB R7, 1(R1) + LSRW $0x08, R7, R7 + LSLW $0x05, R7, R7 + ORRW R7, R5, R5 + MOVB R5, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm8B + +emit_copy_three_match_nolit_encodeBetterBlockAsm8B: + SUB $2, R5, R5 + MOVWU R5, R5 + MOVB R5, (R1) + MOVH R7, 1(R1) + ADD $0x03, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm8B + +match_is_repeat_encodeBetterBlockAsm8B: + MOVWU 20(RSP), R5 + CMPW R6, R5 + BEQ emit_literal_done_match_emit_repeat_encodeBetterBlockAsm8B + MOVWU R6, R7 + MOVW R6, 20(RSP) + ADD R5, R3, R8 + SUBW R5, R7, R7 + SUB $1, R7, R5 + MOVWU R5, R5 + CMPW $0x3c, R5 + BLO one_byte_match_emit_repeat_encodeBetterBlockAsm8B + CMPW $0x00000100, R5 + BLO two_bytes_match_emit_repeat_encodeBetterBlockAsm8B + BLO three_bytes_match_emit_repeat_encodeBetterBlockAsm8B + +three_bytes_match_emit_repeat_encodeBetterBlockAsm8B: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R5, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_match_emit_repeat_encodeBetterBlockAsm8B + +two_bytes_match_emit_repeat_encodeBetterBlockAsm8B: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R5, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R5 + BLO memmove_match_emit_repeat_encodeBetterBlockAsm8B + JMP memmove_long_match_emit_repeat_encodeBetterBlockAsm8B + +one_byte_match_emit_repeat_encodeBetterBlockAsm8B: + LSLW $0x02, R5, R16 + BFI $0, R16, $8, R5 + MOVB R5, (R1) + ADD $0x01, R1, R1 + +memmove_match_emit_repeat_encodeBetterBlockAsm8B: + ADD R7, R1, R5 + + // genMemMoveShort + CMP $0x04, R7 + BLS emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm8B_memmove_move_4 + CMP $0x08, R7 + BLO emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm8B_memmove_move_4through7 + CMP $0x10, R7 + BLS emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm8B_memmove_move_8through16 + CMP $0x20, R7 + BLS emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm8B_memmove_move_17through32 + JMP emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm8B_memmove_move_33through64 + +emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm8B_memmove_move_4: + MOVWU (R8), R9 + MOVW R9, (R1) + JMP memmove_end_copy_match_emit_repeat_encodeBetterBlockAsm8B + +emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm8B_memmove_move_4through7: + MOVWU (R8), R9 + ADD R7, R8, R15 + MOVWU -4(R15), R8 + MOVW R9, (R1) + ADD R7, R1, R15 + MOVW R8, -4(R15) + JMP memmove_end_copy_match_emit_repeat_encodeBetterBlockAsm8B + +emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm8B_memmove_move_8through16: + MOVD (R8), R9 + ADD R7, R8, R15 + MOVD -8(R15), R8 + MOVD R9, (R1) + ADD R7, R1, R15 + MOVD R8, -8(R15) + JMP memmove_end_copy_match_emit_repeat_encodeBetterBlockAsm8B + +emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm8B_memmove_move_17through32: + FMOVQ (R8), F0 + ADD R7, R8, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R7, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_match_emit_repeat_encodeBetterBlockAsm8B + +emit_lit_memmove_match_emit_repeat_encodeBetterBlockAsm8B_memmove_move_33through64: + FMOVQ (R8), F0 + FMOVQ 16(R8), F1 + ADD R7, R8, R15 + FMOVQ -32(R15), F2 + ADD R7, R8, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R7, R1, R15 + FMOVQ F2, -32(R15) + ADD R7, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_match_emit_repeat_encodeBetterBlockAsm8B: + MOVD R5, R1 + JMP emit_literal_done_match_emit_repeat_encodeBetterBlockAsm8B + +memmove_long_match_emit_repeat_encodeBetterBlockAsm8B: + ADD R7, R1, R5 + + // genMemMoveLong + MOVD R8, R9 + MOVD R1, R10 + MOVD R7, R12 + +emit_lit_memmove_long_match_emit_repeat_encodeBetterBlockAsm8Blarge_big_loop_back: + FMOVQ (R9), F0 + FMOVQ 16(R9), F1 + FMOVQ F0, (R10) + FMOVQ F1, 16(R10) + ADD $0x20, R9, R9 + ADD $0x20, R10, R10 + SUB $0x20, R12, R12 + CMP $0x20, R12 + BHS emit_lit_memmove_long_match_emit_repeat_encodeBetterBlockAsm8Blarge_big_loop_back + ADD R7, R8, R15 + FMOVQ -32(R15), F0 + ADD R7, R8, R15 + FMOVQ -16(R15), F1 + ADD R7, R1, R15 + FMOVQ F0, -32(R15) + ADD R7, R1, R15 + FMOVQ F1, -16(R15) + MOVD R5, R1 + +emit_literal_done_match_emit_repeat_encodeBetterBlockAsm8B: + ADDW R11, R2, R2 + ADDW $0x04, R11, R11 + MOVW R2, 20(RSP) + + // emitRepeat + MOVWU R11, R5 + SUB $4, R11, R11 + MOVWU R11, R11 + CMPW $0x08, R5 + BLS repeat_two_match_nolit_repeat_encodeBetterBlockAsm8B + CMPW $0x0c, R5 + BHS cant_repeat_two_offset_match_nolit_repeat_encodeBetterBlockAsm8B + +cant_repeat_two_offset_match_nolit_repeat_encodeBetterBlockAsm8B: + CMPW $0x00000104, R11 + BLO repeat_three_match_nolit_repeat_encodeBetterBlockAsm8B + SUB $256, R11, R11 + MOVWU R11, R11 + MOVD $0x0019, R16 + MOVH R16, (R1) + MOVH R11, 2(R1) + ADD $0x04, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm8B + +repeat_three_match_nolit_repeat_encodeBetterBlockAsm8B: + SUB $4, R11, R11 + MOVWU R11, R11 + MOVD $0x0015, R16 + MOVH R16, (R1) + MOVB R11, 2(R1) + ADD $0x03, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm8B + +repeat_two_match_nolit_repeat_encodeBetterBlockAsm8B: + LSLW $0x02, R11, R11 + ORRW $0x01, R11, R11 + MOVH R11, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeBetterBlockAsm8B + MOVD $0, R5 + ADD R11<<2, R5, R11 + ADD $1, R11, R11 + MOVWU R11, R11 + MOVB R7, 1(R1) + ASRW $0x08, R7, R7 + LSLW $0x05, R7, R7 + ORRW R7, R11, R11 + MOVB R11, (R1) + ADD $0x02, R1, R1 + +match_nolit_emitcopy_end_encodeBetterBlockAsm8B: + MOVWU 16(RSP), R16 + CMPW R16, R2 + BHS emit_remainder_encodeBetterBlockAsm8B + MOVD 8(RSP), R16 + CMP R16, R1 + BLO match_nolit_dst_ok_encodeBetterBlockAsm8B + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +match_nolit_dst_ok_encodeBetterBlockAsm8B: + MOVD $0x0000cf1bbcdcbf9b, R5 + MOVD $0x9e3779b1, R7 + ADD $1, R6, R6 + SUB $2, R2, R8 + MOVD (R3)(R6), R9 + ADD R6, R3, R15 + MOVD 1(R15), R10 + MOVD (R3)(R8), R11 + ADD R8, R3, R15 + MOVD 1(R15), R12 + LSL $0x10, R9, R9 + MUL R5, R9, R9 + LSR $0x36, R9, R9 + LSL $0x20, R10, R10 + MUL R7, R10, R10 + LSR $0x38, R10, R10 + LSL $0x10, R11, R11 + MUL R5, R11, R11 + LSR $0x36, R11, R11 + LSL $0x20, R12, R12 + MUL R7, R12, R12 + LSR $0x38, R12, R12 + ADD $1, R6, R7 + ADD $1, R8, R13 + MOVW R6, (R0)(R9<<2) + MOVW R8, (R0)(R11<<2) + ADD R10<<2, R0, R15 + MOVW R7, 4096(R15) + ADD R12<<2, R0, R15 + MOVW R13, 4096(R15) + ADD R6, R8, R7 + ADD $1, R7, R7 + LSR $0x01, R7, R7 + ADD $0x01, R6, R6 + SUB $0x01, R8, R8 + +index_loop_encodeBetterBlockAsm8B: + CMP R8, R7 + BHS search_loop_encodeBetterBlockAsm8B + MOVD (R3)(R6), R9 + MOVD (R3)(R7), R10 + LSL $0x10, R9, R9 + MUL R5, R9, R9 + LSR $0x36, R9, R9 + LSL $0x10, R10, R10 + MUL R5, R10, R10 + LSR $0x36, R10, R10 + MOVW R6, (R0)(R9<<2) + MOVW R7, (R0)(R10<<2) + ADD $0x02, R6, R6 + ADD $0x02, R7, R7 + JMP index_loop_encodeBetterBlockAsm8B + +emit_remainder_encodeBetterBlockAsm8B: + MOVD src_len+32(FP), R0 + MOVWU 20(RSP), R16 + SUBW R16, R0, R0 + ADD R0, R1, R0 + ADD $3, R0, R0 + MOVD 8(RSP), R16 + CMP R16, R0 + BLO emit_remainder_ok_encodeBetterBlockAsm8B + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +emit_remainder_ok_encodeBetterBlockAsm8B: + MOVD src_len+32(FP), R0 + MOVWU 20(RSP), R2 + CMPW R0, R2 + BEQ emit_literal_done_emit_remainder_encodeBetterBlockAsm8B + MOVWU R0, R5 + MOVW R0, 20(RSP) + ADD R2, R3, R0 + SUBW R2, R5, R5 + SUB $1, R5, R2 + MOVWU R2, R2 + CMPW $0x3c, R2 + BLO one_byte_emit_remainder_encodeBetterBlockAsm8B + CMPW $0x00000100, R2 + BLO two_bytes_emit_remainder_encodeBetterBlockAsm8B + BLO three_bytes_emit_remainder_encodeBetterBlockAsm8B + +three_bytes_emit_remainder_encodeBetterBlockAsm8B: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R2, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_emit_remainder_encodeBetterBlockAsm8B + +two_bytes_emit_remainder_encodeBetterBlockAsm8B: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R2, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R2 + BLO memmove_emit_remainder_encodeBetterBlockAsm8B + JMP memmove_long_emit_remainder_encodeBetterBlockAsm8B + +one_byte_emit_remainder_encodeBetterBlockAsm8B: + LSLW $0x02, R2, R16 + BFI $0, R16, $8, R2 + MOVB R2, (R1) + ADD $0x01, R1, R1 + +memmove_emit_remainder_encodeBetterBlockAsm8B: + ADD R5, R1, R2 + MOVWU R5, R3 + + // genMemMoveShort + CMP $0x03, R3 + BLO emit_lit_memmove_emit_remainder_encodeBetterBlockAsm8B_memmove_move_1or2 + BEQ emit_lit_memmove_emit_remainder_encodeBetterBlockAsm8B_memmove_move_3 + CMP $0x08, R3 + BLO emit_lit_memmove_emit_remainder_encodeBetterBlockAsm8B_memmove_move_4through7 + CMP $0x10, R3 + BLS emit_lit_memmove_emit_remainder_encodeBetterBlockAsm8B_memmove_move_8through16 + CMP $0x20, R3 + BLS emit_lit_memmove_emit_remainder_encodeBetterBlockAsm8B_memmove_move_17through32 + JMP emit_lit_memmove_emit_remainder_encodeBetterBlockAsm8B_memmove_move_33through64 + +emit_lit_memmove_emit_remainder_encodeBetterBlockAsm8B_memmove_move_1or2: + MOVBU (R0), R16 + BFI $0, R16, $8, R5 + ADD R3, R0, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R0 + MOVB R5, (R1) + ADD R3, R1, R15 + MOVB R0, -1(R15) + JMP memmove_end_copy_emit_remainder_encodeBetterBlockAsm8B + +emit_lit_memmove_emit_remainder_encodeBetterBlockAsm8B_memmove_move_3: + MOVHU (R0), R16 + BFI $0, R16, $16, R5 + MOVBU 2(R0), R16 + BFI $0, R16, $8, R0 + MOVH R5, (R1) + MOVB R0, 2(R1) + JMP memmove_end_copy_emit_remainder_encodeBetterBlockAsm8B + +emit_lit_memmove_emit_remainder_encodeBetterBlockAsm8B_memmove_move_4through7: + MOVWU (R0), R5 + ADD R3, R0, R15 + MOVWU -4(R15), R0 + MOVW R5, (R1) + ADD R3, R1, R15 + MOVW R0, -4(R15) + JMP memmove_end_copy_emit_remainder_encodeBetterBlockAsm8B + +emit_lit_memmove_emit_remainder_encodeBetterBlockAsm8B_memmove_move_8through16: + MOVD (R0), R5 + ADD R3, R0, R15 + MOVD -8(R15), R0 + MOVD R5, (R1) + ADD R3, R1, R15 + MOVD R0, -8(R15) + JMP memmove_end_copy_emit_remainder_encodeBetterBlockAsm8B + +emit_lit_memmove_emit_remainder_encodeBetterBlockAsm8B_memmove_move_17through32: + FMOVQ (R0), F0 + ADD R3, R0, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R3, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_emit_remainder_encodeBetterBlockAsm8B + +emit_lit_memmove_emit_remainder_encodeBetterBlockAsm8B_memmove_move_33through64: + FMOVQ (R0), F0 + FMOVQ 16(R0), F1 + ADD R3, R0, R15 + FMOVQ -32(R15), F2 + ADD R3, R0, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R3, R1, R15 + FMOVQ F2, -32(R15) + ADD R3, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_emit_remainder_encodeBetterBlockAsm8B: + MOVD R2, R1 + JMP emit_literal_done_emit_remainder_encodeBetterBlockAsm8B + +memmove_long_emit_remainder_encodeBetterBlockAsm8B: + ADD R5, R1, R2 + MOVWU R5, R3 + + // genMemMoveLong + MOVD R0, R5 + MOVD R1, R6 + MOVD R3, R7 + +emit_lit_memmove_long_emit_remainder_encodeBetterBlockAsm8Blarge_big_loop_back: + FMOVQ (R5), F0 + FMOVQ 16(R5), F1 + FMOVQ F0, (R6) + FMOVQ F1, 16(R6) + ADD $0x20, R5, R5 + ADD $0x20, R6, R6 + SUB $0x20, R7, R7 + CMP $0x20, R7 + BHS emit_lit_memmove_long_emit_remainder_encodeBetterBlockAsm8Blarge_big_loop_back + ADD R3, R0, R15 + FMOVQ -32(R15), F0 + ADD R3, R0, R15 + FMOVQ -16(R15), F1 + ADD R3, R1, R15 + FMOVQ F0, -32(R15) + ADD R3, R1, R15 + FMOVQ F1, -16(R15) + MOVD R2, R1 + +emit_literal_done_emit_remainder_encodeBetterBlockAsm8B: + MOVD dst_base+0(FP), R0 + SUB R0, R1, R1 + MOVD R1, ret+56(FP) + RET + +// func encodeSnappyBlockAsm(dst []byte, src []byte, tmp *[65536]byte) int +// Requires: BMI, SSE2 +TEXT ·encodeSnappyBlockAsm(SB), $24-64 + MOVD tmp+48(FP), R0 + MOVD dst_base+0(FP), R1 + MOVD $0x00000200, R2 + MOVD R0, R3 + VEOR V0.B16, V0.B16, V0.B16 + +zero_loop_encodeSnappyBlockAsm: + FMOVQ F0, (R3) + FMOVQ F0, 16(R3) + FMOVQ F0, 32(R3) + FMOVQ F0, 48(R3) + FMOVQ F0, 64(R3) + FMOVQ F0, 80(R3) + FMOVQ F0, 96(R3) + FMOVQ F0, 112(R3) + ADD $0x80, R3, R3 + SUBS $1, R2, R2 + BNE zero_loop_encodeSnappyBlockAsm + MOVD $0x00000000, R16 + MOVW R16, 20(RSP) + MOVD src_len+32(FP), R2 + SUB $9, R2, R3 + SUB $8, R2, R5 + MOVW R5, 16(RSP) + LSR $0x05, R2, R2 + SUBW R2, R3, R3 + ADD R3, R1, R3 + MOVD R3, 8(RSP) + MOVD $0x00000001, R2 + MOVW R2, 24(RSP) + MOVD src_base+24(FP), R3 + +search_loop_encodeSnappyBlockAsm: + MOVWU R2, R5 + MOVWU 20(RSP), R16 + SUBW R16, R5, R5 + LSRW $0x06, R5, R5 + ADD R5, R2, R5 + ADD $4, R5, R5 + MOVWU R5, R5 + MOVWU 16(RSP), R16 + CMPW R16, R5 + BHS emit_remainder_encodeSnappyBlockAsm + MOVD (R3)(R2), R6 + MOVW R5, 28(RSP) + MOVD $0x0000cf1bbcdcbf9b, R8 + MOVD R6, R9 + MOVD R6, R10 + LSR $0x08, R10, R10 + LSL $0x10, R9, R9 + MUL R8, R9, R9 + LSR $0x32, R9, R9 + LSL $0x10, R10, R10 + MUL R8, R10, R10 + LSR $0x32, R10, R10 + MOVWU (R0)(R9<<2), R5 + MOVWU (R0)(R10<<2), R7 + MOVW R2, (R0)(R9<<2) + ADD $1, R2, R9 + MOVWU R9, R9 + MOVW R9, (R0)(R10<<2) + MOVD R6, R9 + LSR $0x10, R9, R9 + LSL $0x10, R9, R9 + MUL R8, R9, R9 + LSR $0x32, R9, R9 + MOVWU R2, R8 + MOVWU 24(RSP), R16 + SUBW R16, R8, R8 + ADD R8, R3, R15 + MOVWU 1(R15), R10 + MOVD R6, R8 + LSR $0x08, R8, R8 + CMPW R10, R8 + BNE no_repeat_found_encodeSnappyBlockAsm + ADD $1, R2, R6 + MOVWU R6, R6 + MOVWU 20(RSP), R5 + MOVWU R6, R7 + MOVWU 24(RSP), R16 + SUBSW R16, R7, R7 + BEQ repeat_extend_back_end_encodeSnappyBlockAsm + +repeat_extend_back_loop_encodeSnappyBlockAsm: + CMPW R5, R6 + BLS repeat_extend_back_end_encodeSnappyBlockAsm + ADD R7, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R8 + ADD R6, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R9 + AND $0xff, R9, R16 + AND $0xff, R8, R15 + CMP R16, R15 + BNE repeat_extend_back_end_encodeSnappyBlockAsm + SUB $1, R6, R6 + MOVWU R6, R6 + SUBSW $1, R7, R7 + BNE repeat_extend_back_loop_encodeSnappyBlockAsm + +repeat_extend_back_end_encodeSnappyBlockAsm: + MOVWU R6, R5 + MOVWU 20(RSP), R16 + SUBW R16, R5, R5 + ADD R5, R1, R5 + ADD $5, R5, R5 + MOVD 8(RSP), R16 + CMP R16, R5 + BLO repeat_dst_size_check_encodeSnappyBlockAsm + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +repeat_dst_size_check_encodeSnappyBlockAsm: + MOVWU 20(RSP), R5 + CMPW R6, R5 + BEQ emit_literal_done_repeat_emit_encodeSnappyBlockAsm + MOVWU R6, R7 + MOVW R6, 20(RSP) + ADD R5, R3, R8 + SUBW R5, R7, R7 + SUB $1, R7, R5 + MOVWU R5, R5 + CMPW $0x3c, R5 + BLO one_byte_repeat_emit_encodeSnappyBlockAsm + CMPW $0x00000100, R5 + BLO two_bytes_repeat_emit_encodeSnappyBlockAsm + CMPW $0x00010000, R5 + BLO three_bytes_repeat_emit_encodeSnappyBlockAsm + CMPW $0x01000000, R5 + BLO four_bytes_repeat_emit_encodeSnappyBlockAsm + MOVD $0xfc, R16 + MOVB R16, (R1) + MOVW R5, 1(R1) + ADD $0x05, R1, R1 + JMP memmove_long_repeat_emit_encodeSnappyBlockAsm + +four_bytes_repeat_emit_encodeSnappyBlockAsm: + MOVWU R5, R9 + LSRW $0x10, R9, R9 + MOVD $0xf8, R16 + MOVB R16, (R1) + MOVH R5, 1(R1) + MOVB R9, 3(R1) + ADD $0x04, R1, R1 + JMP memmove_long_repeat_emit_encodeSnappyBlockAsm + +three_bytes_repeat_emit_encodeSnappyBlockAsm: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R5, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_repeat_emit_encodeSnappyBlockAsm + +two_bytes_repeat_emit_encodeSnappyBlockAsm: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R5, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R5 + BLO memmove_repeat_emit_encodeSnappyBlockAsm + JMP memmove_long_repeat_emit_encodeSnappyBlockAsm + +one_byte_repeat_emit_encodeSnappyBlockAsm: + LSLW $0x02, R5, R16 + BFI $0, R16, $8, R5 + MOVB R5, (R1) + ADD $0x01, R1, R1 + +memmove_repeat_emit_encodeSnappyBlockAsm: + ADD R7, R1, R5 + + // genMemMoveShort + CMP $0x08, R7 + BLS emit_lit_memmove_repeat_emit_encodeSnappyBlockAsm_memmove_move_8 + CMP $0x10, R7 + BLS emit_lit_memmove_repeat_emit_encodeSnappyBlockAsm_memmove_move_8through16 + CMP $0x20, R7 + BLS emit_lit_memmove_repeat_emit_encodeSnappyBlockAsm_memmove_move_17through32 + JMP emit_lit_memmove_repeat_emit_encodeSnappyBlockAsm_memmove_move_33through64 + +emit_lit_memmove_repeat_emit_encodeSnappyBlockAsm_memmove_move_8: + MOVD (R8), R9 + MOVD R9, (R1) + JMP memmove_end_copy_repeat_emit_encodeSnappyBlockAsm + +emit_lit_memmove_repeat_emit_encodeSnappyBlockAsm_memmove_move_8through16: + MOVD (R8), R9 + ADD R7, R8, R15 + MOVD -8(R15), R8 + MOVD R9, (R1) + ADD R7, R1, R15 + MOVD R8, -8(R15) + JMP memmove_end_copy_repeat_emit_encodeSnappyBlockAsm + +emit_lit_memmove_repeat_emit_encodeSnappyBlockAsm_memmove_move_17through32: + FMOVQ (R8), F0 + ADD R7, R8, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R7, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_repeat_emit_encodeSnappyBlockAsm + +emit_lit_memmove_repeat_emit_encodeSnappyBlockAsm_memmove_move_33through64: + FMOVQ (R8), F0 + FMOVQ 16(R8), F1 + ADD R7, R8, R15 + FMOVQ -32(R15), F2 + ADD R7, R8, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R7, R1, R15 + FMOVQ F2, -32(R15) + ADD R7, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_repeat_emit_encodeSnappyBlockAsm: + MOVD R5, R1 + JMP emit_literal_done_repeat_emit_encodeSnappyBlockAsm + +memmove_long_repeat_emit_encodeSnappyBlockAsm: + ADD R7, R1, R5 + + // genMemMoveLong + MOVD R8, R9 + MOVD R1, R10 + MOVD R7, R11 + +emit_lit_memmove_long_repeat_emit_encodeSnappyBlockAsmlarge_big_loop_back: + FMOVQ (R9), F0 + FMOVQ 16(R9), F1 + FMOVQ F0, (R10) + FMOVQ F1, 16(R10) + ADD $0x20, R9, R9 + ADD $0x20, R10, R10 + SUB $0x20, R11, R11 + CMP $0x20, R11 + BHS emit_lit_memmove_long_repeat_emit_encodeSnappyBlockAsmlarge_big_loop_back + ADD R7, R8, R15 + FMOVQ -32(R15), F0 + ADD R7, R8, R15 + FMOVQ -16(R15), F1 + ADD R7, R1, R15 + FMOVQ F0, -32(R15) + ADD R7, R1, R15 + FMOVQ F1, -16(R15) + MOVD R5, R1 + +emit_literal_done_repeat_emit_encodeSnappyBlockAsm: + ADDW $0x05, R2, R2 + MOVWU R2, R5 + MOVWU 24(RSP), R16 + SUBW R16, R5, R5 + MOVD src_len+32(FP), R7 + SUBW R2, R7, R7 + ADD R2, R3, R8 + ADD R5, R3, R5 + + // matchLen + MOVD $0, R10 + +matchlen_loopback_16_repeat_extend_encodeSnappyBlockAsm: + CMPW $0x10, R7 + BLO matchlen_match8_repeat_extend_encodeSnappyBlockAsm + MOVD (R8)(R10), R9 + ADD R10, R8, R15 + MOVD 8(R15), R11 + MOVD (R5)(R10), R16 + EOR R16, R9, R9 + TST R9, R9 + BNE matchlen_bsf_8_repeat_extend_encodeSnappyBlockAsm + ADD R10, R5, R15 + MOVD 8(R15), R16 + EOR R16, R11, R11 + TST R11, R11 + BNE matchlen_bsf_16repeat_extend_encodeSnappyBlockAsm + SUB $16, R7, R7 + MOVWU R7, R7 + ADD $16, R10, R10 + MOVWU R10, R10 + JMP matchlen_loopback_16_repeat_extend_encodeSnappyBlockAsm + +matchlen_bsf_16repeat_extend_encodeSnappyBlockAsm: + RBIT R11, R11 + CLZ R11, R11 + ASR $0x03, R11, R11 + ADD R11, R10, R10 + ADD $8, R10, R10 + MOVWU R10, R10 + JMP repeat_extend_forward_end_encodeSnappyBlockAsm + +matchlen_match8_repeat_extend_encodeSnappyBlockAsm: + CMPW $0x08, R7 + BLO matchlen_match4_repeat_extend_encodeSnappyBlockAsm + MOVD (R8)(R10), R9 + MOVD (R5)(R10), R16 + EOR R16, R9, R9 + TST R9, R9 + BNE matchlen_bsf_8_repeat_extend_encodeSnappyBlockAsm + SUB $8, R7, R7 + MOVWU R7, R7 + ADD $8, R10, R10 + MOVWU R10, R10 + JMP matchlen_match4_repeat_extend_encodeSnappyBlockAsm + +matchlen_bsf_8_repeat_extend_encodeSnappyBlockAsm: + RBIT R9, R9 + CLZ R9, R9 + ASR $0x03, R9, R9 + ADD R9, R10, R10 + MOVWU R10, R10 + JMP repeat_extend_forward_end_encodeSnappyBlockAsm + +matchlen_match4_repeat_extend_encodeSnappyBlockAsm: + CMPW $0x04, R7 + BLO matchlen_match2_repeat_extend_encodeSnappyBlockAsm + MOVWU (R8)(R10), R9 + MOVWU (R5)(R10), R16 + CMPW R9, R16 + BNE matchlen_match2_repeat_extend_encodeSnappyBlockAsm + SUB $4, R7, R7 + MOVWU R7, R7 + ADD $4, R10, R10 + MOVWU R10, R10 + +matchlen_match2_repeat_extend_encodeSnappyBlockAsm: + CMPW $0x01, R7 + BEQ matchlen_match1_repeat_extend_encodeSnappyBlockAsm + BLO repeat_extend_forward_end_encodeSnappyBlockAsm + MOVHU (R8)(R10), R16 + BFI $0, R16, $16, R9 + ADD R10, R5, R15 + MOVHU (R15), R15 + AND $0xffff, R9, R16 + CMP R16, R15 + BNE matchlen_match1_repeat_extend_encodeSnappyBlockAsm + ADD $2, R10, R10 + MOVWU R10, R10 + SUBSW $0x02, R7, R7 + BEQ repeat_extend_forward_end_encodeSnappyBlockAsm + +matchlen_match1_repeat_extend_encodeSnappyBlockAsm: + MOVBU (R8)(R10), R16 + BFI $0, R16, $8, R9 + ADD R10, R5, R15 + MOVBU (R15), R15 + AND $0xff, R9, R16 + CMP R16, R15 + BNE repeat_extend_forward_end_encodeSnappyBlockAsm + ADD $1, R10, R10 + MOVWU R10, R10 + +repeat_extend_forward_end_encodeSnappyBlockAsm: + ADDW R10, R2, R2 + MOVWU R2, R5 + SUBW R6, R5, R5 + MOVWU 24(RSP), R6 + + // emitCopy + CMPW $0x00010000, R6 + BLO two_byte_offset_repeat_as_copy_encodeSnappyBlockAsm + +four_bytes_loop_back_repeat_as_copy_encodeSnappyBlockAsm: + CMPW $0x40, R5 + BLS four_bytes_remain_repeat_as_copy_encodeSnappyBlockAsm + MOVD $0xff, R16 + MOVB R16, (R1) + MOVW R6, 1(R1) + SUB $64, R5, R5 + MOVWU R5, R5 + ADD $0x05, R1, R1 + CMPW $0x04, R5 + BLO four_bytes_remain_repeat_as_copy_encodeSnappyBlockAsm + JMP four_bytes_loop_back_repeat_as_copy_encodeSnappyBlockAsm + +four_bytes_remain_repeat_as_copy_encodeSnappyBlockAsm: + TSTW R5, R5 + BEQ repeat_end_emit_encodeSnappyBlockAsm + MOVD $0, R7 + ADD R5<<2, R7, R5 + SUB $1, R5, R5 + MOVWU R5, R5 + MOVB R5, (R1) + MOVW R6, 1(R1) + ADD $0x05, R1, R1 + JMP repeat_end_emit_encodeSnappyBlockAsm + +two_byte_offset_repeat_as_copy_encodeSnappyBlockAsm: + CMPW $0x40, R5 + BLS two_byte_offset_short_repeat_as_copy_encodeSnappyBlockAsm + MOVD $0xee, R16 + MOVB R16, (R1) + MOVH R6, 1(R1) + SUB $60, R5, R5 + MOVWU R5, R5 + ADD $0x03, R1, R1 + JMP two_byte_offset_repeat_as_copy_encodeSnappyBlockAsm + +two_byte_offset_short_repeat_as_copy_encodeSnappyBlockAsm: + MOVWU R5, R7 + LSLW $0x02, R7, R7 + CMPW $0x0c, R5 + BHS emit_copy_three_repeat_as_copy_encodeSnappyBlockAsm + CMPW $0x00000800, R6 + BHS emit_copy_three_repeat_as_copy_encodeSnappyBlockAsm + SUB $15, R7, R7 + MOVWU R7, R7 + MOVB R6, 1(R1) + LSRW $0x08, R6, R6 + LSLW $0x05, R6, R6 + ORRW R6, R7, R7 + MOVB R7, (R1) + ADD $0x02, R1, R1 + JMP repeat_end_emit_encodeSnappyBlockAsm + +emit_copy_three_repeat_as_copy_encodeSnappyBlockAsm: + SUB $2, R7, R7 + MOVWU R7, R7 + MOVB R7, (R1) + MOVH R6, 1(R1) + ADD $0x03, R1, R1 + +repeat_end_emit_encodeSnappyBlockAsm: + MOVW R2, 20(RSP) + JMP search_loop_encodeSnappyBlockAsm + +no_repeat_found_encodeSnappyBlockAsm: + MOVWU (R3)(R5), R16 + CMPW R6, R16 + BEQ candidate_match_encodeSnappyBlockAsm + LSR $0x08, R6, R6 + MOVWU (R0)(R9<<2), R5 + ADD $2, R2, R8 + MOVWU R8, R8 + MOVWU (R3)(R7), R16 + CMPW R6, R16 + BEQ candidate2_match_encodeSnappyBlockAsm + MOVW R8, (R0)(R9<<2) + LSR $0x08, R6, R6 + MOVWU (R3)(R5), R16 + CMPW R6, R16 + BEQ candidate3_match_encodeSnappyBlockAsm + MOVWU 28(RSP), R2 + JMP search_loop_encodeSnappyBlockAsm + +candidate3_match_encodeSnappyBlockAsm: + ADDW $0x02, R2, R2 + JMP candidate_match_encodeSnappyBlockAsm + +candidate2_match_encodeSnappyBlockAsm: + MOVW R8, (R0)(R9<<2) + ADDW $1, R2, R2 + MOVWU R7, R5 + +candidate_match_encodeSnappyBlockAsm: + MOVWU 20(RSP), R6 + TSTW R5, R5 + BEQ match_extend_back_end_encodeSnappyBlockAsm + +match_extend_back_loop_encodeSnappyBlockAsm: + CMPW R6, R2 + BLS match_extend_back_end_encodeSnappyBlockAsm + ADD R5, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R7 + ADD R2, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R8 + AND $0xff, R8, R16 + AND $0xff, R7, R15 + CMP R16, R15 + BNE match_extend_back_end_encodeSnappyBlockAsm + SUB $1, R2, R2 + MOVWU R2, R2 + SUBSW $1, R5, R5 + BEQ match_extend_back_end_encodeSnappyBlockAsm + JMP match_extend_back_loop_encodeSnappyBlockAsm + +match_extend_back_end_encodeSnappyBlockAsm: + MOVWU R2, R6 + MOVWU 20(RSP), R16 + SUBW R16, R6, R6 + ADD R6, R1, R6 + ADD $5, R6, R6 + MOVD 8(RSP), R16 + CMP R16, R6 + BLO match_dst_size_check_encodeSnappyBlockAsm + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +match_dst_size_check_encodeSnappyBlockAsm: + MOVWU R2, R6 + MOVWU 20(RSP), R7 + CMPW R6, R7 + BEQ emit_literal_done_match_emit_encodeSnappyBlockAsm + MOVWU R6, R8 + MOVW R6, 20(RSP) + ADD R7, R3, R6 + SUBW R7, R8, R8 + SUB $1, R8, R7 + MOVWU R7, R7 + CMPW $0x3c, R7 + BLO one_byte_match_emit_encodeSnappyBlockAsm + CMPW $0x00000100, R7 + BLO two_bytes_match_emit_encodeSnappyBlockAsm + CMPW $0x00010000, R7 + BLO three_bytes_match_emit_encodeSnappyBlockAsm + CMPW $0x01000000, R7 + BLO four_bytes_match_emit_encodeSnappyBlockAsm + MOVD $0xfc, R16 + MOVB R16, (R1) + MOVW R7, 1(R1) + ADD $0x05, R1, R1 + JMP memmove_long_match_emit_encodeSnappyBlockAsm + +four_bytes_match_emit_encodeSnappyBlockAsm: + MOVWU R7, R9 + LSRW $0x10, R9, R9 + MOVD $0xf8, R16 + MOVB R16, (R1) + MOVH R7, 1(R1) + MOVB R9, 3(R1) + ADD $0x04, R1, R1 + JMP memmove_long_match_emit_encodeSnappyBlockAsm + +three_bytes_match_emit_encodeSnappyBlockAsm: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R7, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_match_emit_encodeSnappyBlockAsm + +two_bytes_match_emit_encodeSnappyBlockAsm: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R7, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R7 + BLO memmove_match_emit_encodeSnappyBlockAsm + JMP memmove_long_match_emit_encodeSnappyBlockAsm + +one_byte_match_emit_encodeSnappyBlockAsm: + LSLW $0x02, R7, R16 + BFI $0, R16, $8, R7 + MOVB R7, (R1) + ADD $0x01, R1, R1 + +memmove_match_emit_encodeSnappyBlockAsm: + ADD R8, R1, R7 + + // genMemMoveShort + CMP $0x08, R8 + BLS emit_lit_memmove_match_emit_encodeSnappyBlockAsm_memmove_move_8 + CMP $0x10, R8 + BLS emit_lit_memmove_match_emit_encodeSnappyBlockAsm_memmove_move_8through16 + CMP $0x20, R8 + BLS emit_lit_memmove_match_emit_encodeSnappyBlockAsm_memmove_move_17through32 + JMP emit_lit_memmove_match_emit_encodeSnappyBlockAsm_memmove_move_33through64 + +emit_lit_memmove_match_emit_encodeSnappyBlockAsm_memmove_move_8: + MOVD (R6), R9 + MOVD R9, (R1) + JMP memmove_end_copy_match_emit_encodeSnappyBlockAsm + +emit_lit_memmove_match_emit_encodeSnappyBlockAsm_memmove_move_8through16: + MOVD (R6), R9 + ADD R8, R6, R15 + MOVD -8(R15), R6 + MOVD R9, (R1) + ADD R8, R1, R15 + MOVD R6, -8(R15) + JMP memmove_end_copy_match_emit_encodeSnappyBlockAsm + +emit_lit_memmove_match_emit_encodeSnappyBlockAsm_memmove_move_17through32: + FMOVQ (R6), F0 + ADD R8, R6, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_match_emit_encodeSnappyBlockAsm + +emit_lit_memmove_match_emit_encodeSnappyBlockAsm_memmove_move_33through64: + FMOVQ (R6), F0 + FMOVQ 16(R6), F1 + ADD R8, R6, R15 + FMOVQ -32(R15), F2 + ADD R8, R6, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R8, R1, R15 + FMOVQ F2, -32(R15) + ADD R8, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_match_emit_encodeSnappyBlockAsm: + MOVD R7, R1 + JMP emit_literal_done_match_emit_encodeSnappyBlockAsm + +memmove_long_match_emit_encodeSnappyBlockAsm: + ADD R8, R1, R7 + + // genMemMoveLong + MOVD R6, R9 + MOVD R1, R10 + MOVD R8, R11 + +emit_lit_memmove_long_match_emit_encodeSnappyBlockAsmlarge_big_loop_back: + FMOVQ (R9), F0 + FMOVQ 16(R9), F1 + FMOVQ F0, (R10) + FMOVQ F1, 16(R10) + ADD $0x20, R9, R9 + ADD $0x20, R10, R10 + SUB $0x20, R11, R11 + CMP $0x20, R11 + BHS emit_lit_memmove_long_match_emit_encodeSnappyBlockAsmlarge_big_loop_back + ADD R8, R6, R15 + FMOVQ -32(R15), F0 + ADD R8, R6, R15 + FMOVQ -16(R15), F1 + ADD R8, R1, R15 + FMOVQ F0, -32(R15) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + MOVD R7, R1 + +emit_literal_done_match_emit_encodeSnappyBlockAsm: +match_nolit_loop_encodeSnappyBlockAsm: + MOVWU R2, R6 + SUBW R5, R6, R6 + MOVW R6, 24(RSP) + ADDW $0x04, R2, R2 + ADDW $0x04, R5, R5 + MOVD src_len+32(FP), R6 + SUBW R2, R6, R6 + ADD R2, R3, R7 + ADD R5, R3, R5 + + // matchLen + MOVD $0, R9 + +matchlen_loopback_16_match_nolit_encodeSnappyBlockAsm: + CMPW $0x10, R6 + BLO matchlen_match8_match_nolit_encodeSnappyBlockAsm + MOVD (R7)(R9), R8 + ADD R9, R7, R15 + MOVD 8(R15), R10 + MOVD (R5)(R9), R16 + EOR R16, R8, R8 + TST R8, R8 + BNE matchlen_bsf_8_match_nolit_encodeSnappyBlockAsm + ADD R9, R5, R15 + MOVD 8(R15), R16 + EOR R16, R10, R10 + TST R10, R10 + BNE matchlen_bsf_16match_nolit_encodeSnappyBlockAsm + SUB $16, R6, R6 + MOVWU R6, R6 + ADD $16, R9, R9 + MOVWU R9, R9 + JMP matchlen_loopback_16_match_nolit_encodeSnappyBlockAsm + +matchlen_bsf_16match_nolit_encodeSnappyBlockAsm: + RBIT R10, R10 + CLZ R10, R10 + ASR $0x03, R10, R10 + ADD R10, R9, R9 + ADD $8, R9, R9 + MOVWU R9, R9 + JMP match_nolit_end_encodeSnappyBlockAsm + +matchlen_match8_match_nolit_encodeSnappyBlockAsm: + CMPW $0x08, R6 + BLO matchlen_match4_match_nolit_encodeSnappyBlockAsm + MOVD (R7)(R9), R8 + MOVD (R5)(R9), R16 + EOR R16, R8, R8 + TST R8, R8 + BNE matchlen_bsf_8_match_nolit_encodeSnappyBlockAsm + SUB $8, R6, R6 + MOVWU R6, R6 + ADD $8, R9, R9 + MOVWU R9, R9 + JMP matchlen_match4_match_nolit_encodeSnappyBlockAsm + +matchlen_bsf_8_match_nolit_encodeSnappyBlockAsm: + RBIT R8, R8 + CLZ R8, R8 + ASR $0x03, R8, R8 + ADD R8, R9, R9 + MOVWU R9, R9 + JMP match_nolit_end_encodeSnappyBlockAsm + +matchlen_match4_match_nolit_encodeSnappyBlockAsm: + CMPW $0x04, R6 + BLO matchlen_match2_match_nolit_encodeSnappyBlockAsm + MOVWU (R7)(R9), R8 + MOVWU (R5)(R9), R16 + CMPW R8, R16 + BNE matchlen_match2_match_nolit_encodeSnappyBlockAsm + SUB $4, R6, R6 + MOVWU R6, R6 + ADD $4, R9, R9 + MOVWU R9, R9 + +matchlen_match2_match_nolit_encodeSnappyBlockAsm: + CMPW $0x01, R6 + BEQ matchlen_match1_match_nolit_encodeSnappyBlockAsm + BLO match_nolit_end_encodeSnappyBlockAsm + MOVHU (R7)(R9), R16 + BFI $0, R16, $16, R8 + ADD R9, R5, R15 + MOVHU (R15), R15 + AND $0xffff, R8, R16 + CMP R16, R15 + BNE matchlen_match1_match_nolit_encodeSnappyBlockAsm + ADD $2, R9, R9 + MOVWU R9, R9 + SUBSW $0x02, R6, R6 + BEQ match_nolit_end_encodeSnappyBlockAsm + +matchlen_match1_match_nolit_encodeSnappyBlockAsm: + MOVBU (R7)(R9), R16 + BFI $0, R16, $8, R8 + ADD R9, R5, R15 + MOVBU (R15), R15 + AND $0xff, R8, R16 + CMP R16, R15 + BNE match_nolit_end_encodeSnappyBlockAsm + ADD $1, R9, R9 + MOVWU R9, R9 + +match_nolit_end_encodeSnappyBlockAsm: + ADDW R9, R2, R2 + MOVWU 24(RSP), R5 + ADDW $0x04, R9, R9 + MOVW R2, 20(RSP) + + // emitCopy + CMPW $0x00010000, R5 + BLO two_byte_offset_match_nolit_encodeSnappyBlockAsm + +four_bytes_loop_back_match_nolit_encodeSnappyBlockAsm: + CMPW $0x40, R9 + BLS four_bytes_remain_match_nolit_encodeSnappyBlockAsm + MOVD $0xff, R16 + MOVB R16, (R1) + MOVW R5, 1(R1) + SUB $64, R9, R9 + MOVWU R9, R9 + ADD $0x05, R1, R1 + CMPW $0x04, R9 + BLO four_bytes_remain_match_nolit_encodeSnappyBlockAsm + JMP four_bytes_loop_back_match_nolit_encodeSnappyBlockAsm + +four_bytes_remain_match_nolit_encodeSnappyBlockAsm: + TSTW R9, R9 + BEQ match_nolit_emitcopy_end_encodeSnappyBlockAsm + MOVD $0, R6 + ADD R9<<2, R6, R9 + SUB $1, R9, R9 + MOVWU R9, R9 + MOVB R9, (R1) + MOVW R5, 1(R1) + ADD $0x05, R1, R1 + JMP match_nolit_emitcopy_end_encodeSnappyBlockAsm + +two_byte_offset_match_nolit_encodeSnappyBlockAsm: + CMPW $0x40, R9 + BLS two_byte_offset_short_match_nolit_encodeSnappyBlockAsm + MOVD $0xee, R16 + MOVB R16, (R1) + MOVH R5, 1(R1) + SUB $60, R9, R9 + MOVWU R9, R9 + ADD $0x03, R1, R1 + JMP two_byte_offset_match_nolit_encodeSnappyBlockAsm + +two_byte_offset_short_match_nolit_encodeSnappyBlockAsm: + MOVWU R9, R6 + LSLW $0x02, R6, R6 + CMPW $0x0c, R9 + BHS emit_copy_three_match_nolit_encodeSnappyBlockAsm + CMPW $0x00000800, R5 + BHS emit_copy_three_match_nolit_encodeSnappyBlockAsm + SUB $15, R6, R6 + MOVWU R6, R6 + MOVB R5, 1(R1) + LSRW $0x08, R5, R5 + LSLW $0x05, R5, R5 + ORRW R5, R6, R6 + MOVB R6, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeSnappyBlockAsm + +emit_copy_three_match_nolit_encodeSnappyBlockAsm: + SUB $2, R6, R6 + MOVWU R6, R6 + MOVB R6, (R1) + MOVH R5, 1(R1) + ADD $0x03, R1, R1 + +match_nolit_emitcopy_end_encodeSnappyBlockAsm: + MOVWU 16(RSP), R16 + CMPW R16, R2 + BHS emit_remainder_encodeSnappyBlockAsm + ADD R2, R3, R15 + MOVD -2(R15), R6 + MOVD 8(RSP), R16 + CMP R16, R1 + BLO match_nolit_dst_ok_encodeSnappyBlockAsm + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +match_nolit_dst_ok_encodeSnappyBlockAsm: + MOVD $0x0000cf1bbcdcbf9b, R8 + MOVD R6, R7 + LSR $0x10, R6, R6 + MOVD R6, R5 + LSL $0x10, R7, R7 + MUL R8, R7, R7 + LSR $0x32, R7, R7 + LSL $0x10, R5, R5 + MUL R8, R5, R5 + LSR $0x32, R5, R5 + SUB $2, R2, R8 + MOVWU R8, R8 + ADD R5<<2, R0, R9 + MOVWU (R9), R5 + MOVW R8, (R0)(R7<<2) + MOVW R2, (R9) + MOVWU (R3)(R5), R16 + CMPW R6, R16 + BEQ match_nolit_loop_encodeSnappyBlockAsm + ADDW $1, R2, R2 + JMP search_loop_encodeSnappyBlockAsm + +emit_remainder_encodeSnappyBlockAsm: + MOVD src_len+32(FP), R0 + MOVWU 20(RSP), R16 + SUBW R16, R0, R0 + ADD R0, R1, R0 + ADD $5, R0, R0 + MOVD 8(RSP), R16 + CMP R16, R0 + BLO emit_remainder_ok_encodeSnappyBlockAsm + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +emit_remainder_ok_encodeSnappyBlockAsm: + MOVD src_len+32(FP), R0 + MOVWU 20(RSP), R2 + CMPW R0, R2 + BEQ emit_literal_done_emit_remainder_encodeSnappyBlockAsm + MOVWU R0, R5 + MOVW R0, 20(RSP) + ADD R2, R3, R0 + SUBW R2, R5, R5 + SUB $1, R5, R2 + MOVWU R2, R2 + CMPW $0x3c, R2 + BLO one_byte_emit_remainder_encodeSnappyBlockAsm + CMPW $0x00000100, R2 + BLO two_bytes_emit_remainder_encodeSnappyBlockAsm + CMPW $0x00010000, R2 + BLO three_bytes_emit_remainder_encodeSnappyBlockAsm + CMPW $0x01000000, R2 + BLO four_bytes_emit_remainder_encodeSnappyBlockAsm + MOVD $0xfc, R16 + MOVB R16, (R1) + MOVW R2, 1(R1) + ADD $0x05, R1, R1 + JMP memmove_long_emit_remainder_encodeSnappyBlockAsm + +four_bytes_emit_remainder_encodeSnappyBlockAsm: + MOVWU R2, R3 + LSRW $0x10, R3, R3 + MOVD $0xf8, R16 + MOVB R16, (R1) + MOVH R2, 1(R1) + MOVB R3, 3(R1) + ADD $0x04, R1, R1 + JMP memmove_long_emit_remainder_encodeSnappyBlockAsm + +three_bytes_emit_remainder_encodeSnappyBlockAsm: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R2, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_emit_remainder_encodeSnappyBlockAsm + +two_bytes_emit_remainder_encodeSnappyBlockAsm: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R2, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R2 + BLO memmove_emit_remainder_encodeSnappyBlockAsm + JMP memmove_long_emit_remainder_encodeSnappyBlockAsm + +one_byte_emit_remainder_encodeSnappyBlockAsm: + LSLW $0x02, R2, R16 + BFI $0, R16, $8, R2 + MOVB R2, (R1) + ADD $0x01, R1, R1 + +memmove_emit_remainder_encodeSnappyBlockAsm: + ADD R5, R1, R2 + MOVWU R5, R3 + + // genMemMoveShort + CMP $0x03, R3 + BLO emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm_memmove_move_1or2 + BEQ emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm_memmove_move_3 + CMP $0x08, R3 + BLO emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm_memmove_move_4through7 + CMP $0x10, R3 + BLS emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm_memmove_move_8through16 + CMP $0x20, R3 + BLS emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm_memmove_move_17through32 + JMP emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm_memmove_move_33through64 + +emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm_memmove_move_1or2: + MOVBU (R0), R16 + BFI $0, R16, $8, R5 + ADD R3, R0, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R0 + MOVB R5, (R1) + ADD R3, R1, R15 + MOVB R0, -1(R15) + JMP memmove_end_copy_emit_remainder_encodeSnappyBlockAsm + +emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm_memmove_move_3: + MOVHU (R0), R16 + BFI $0, R16, $16, R5 + MOVBU 2(R0), R16 + BFI $0, R16, $8, R0 + MOVH R5, (R1) + MOVB R0, 2(R1) + JMP memmove_end_copy_emit_remainder_encodeSnappyBlockAsm + +emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm_memmove_move_4through7: + MOVWU (R0), R5 + ADD R3, R0, R15 + MOVWU -4(R15), R0 + MOVW R5, (R1) + ADD R3, R1, R15 + MOVW R0, -4(R15) + JMP memmove_end_copy_emit_remainder_encodeSnappyBlockAsm + +emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm_memmove_move_8through16: + MOVD (R0), R5 + ADD R3, R0, R15 + MOVD -8(R15), R0 + MOVD R5, (R1) + ADD R3, R1, R15 + MOVD R0, -8(R15) + JMP memmove_end_copy_emit_remainder_encodeSnappyBlockAsm + +emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm_memmove_move_17through32: + FMOVQ (R0), F0 + ADD R3, R0, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R3, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_emit_remainder_encodeSnappyBlockAsm + +emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm_memmove_move_33through64: + FMOVQ (R0), F0 + FMOVQ 16(R0), F1 + ADD R3, R0, R15 + FMOVQ -32(R15), F2 + ADD R3, R0, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R3, R1, R15 + FMOVQ F2, -32(R15) + ADD R3, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_emit_remainder_encodeSnappyBlockAsm: + MOVD R2, R1 + JMP emit_literal_done_emit_remainder_encodeSnappyBlockAsm + +memmove_long_emit_remainder_encodeSnappyBlockAsm: + ADD R5, R1, R2 + MOVWU R5, R3 + + // genMemMoveLong + MOVD R0, R5 + MOVD R1, R6 + MOVD R3, R7 + +emit_lit_memmove_long_emit_remainder_encodeSnappyBlockAsmlarge_big_loop_back: + FMOVQ (R5), F0 + FMOVQ 16(R5), F1 + FMOVQ F0, (R6) + FMOVQ F1, 16(R6) + ADD $0x20, R5, R5 + ADD $0x20, R6, R6 + SUB $0x20, R7, R7 + CMP $0x20, R7 + BHS emit_lit_memmove_long_emit_remainder_encodeSnappyBlockAsmlarge_big_loop_back + ADD R3, R0, R15 + FMOVQ -32(R15), F0 + ADD R3, R0, R15 + FMOVQ -16(R15), F1 + ADD R3, R1, R15 + FMOVQ F0, -32(R15) + ADD R3, R1, R15 + FMOVQ F1, -16(R15) + MOVD R2, R1 + +emit_literal_done_emit_remainder_encodeSnappyBlockAsm: + MOVD dst_base+0(FP), R0 + SUB R0, R1, R1 + MOVD R1, ret+56(FP) + RET + +// func encodeSnappyBlockAsm64K(dst []byte, src []byte, tmp *[65536]byte) int +// Requires: BMI, SSE2 +TEXT ·encodeSnappyBlockAsm64K(SB), $24-64 + MOVD tmp+48(FP), R0 + MOVD dst_base+0(FP), R1 + MOVD $0x00000200, R2 + MOVD R0, R3 + VEOR V0.B16, V0.B16, V0.B16 + +zero_loop_encodeSnappyBlockAsm64K: + FMOVQ F0, (R3) + FMOVQ F0, 16(R3) + FMOVQ F0, 32(R3) + FMOVQ F0, 48(R3) + FMOVQ F0, 64(R3) + FMOVQ F0, 80(R3) + FMOVQ F0, 96(R3) + FMOVQ F0, 112(R3) + ADD $0x80, R3, R3 + SUBS $1, R2, R2 + BNE zero_loop_encodeSnappyBlockAsm64K + MOVD $0x00000000, R16 + MOVW R16, 20(RSP) + MOVD src_len+32(FP), R2 + SUB $9, R2, R3 + SUB $8, R2, R5 + MOVW R5, 16(RSP) + LSR $0x05, R2, R2 + SUBW R2, R3, R3 + ADD R3, R1, R3 + MOVD R3, 8(RSP) + MOVD $0x00000001, R2 + MOVW R2, 24(RSP) + MOVD src_base+24(FP), R3 + +search_loop_encodeSnappyBlockAsm64K: + MOVWU R2, R5 + MOVWU 20(RSP), R16 + SUBW R16, R5, R5 + LSRW $0x06, R5, R5 + ADD R5, R2, R5 + ADD $4, R5, R5 + MOVWU R5, R5 + MOVWU 16(RSP), R16 + CMPW R16, R5 + BHS emit_remainder_encodeSnappyBlockAsm64K + MOVD (R3)(R2), R6 + MOVW R5, 28(RSP) + MOVD $0x0000cf1bbcdcbf9b, R8 + MOVD R6, R9 + MOVD R6, R10 + LSR $0x08, R10, R10 + LSL $0x10, R9, R9 + MUL R8, R9, R9 + LSR $0x32, R9, R9 + LSL $0x10, R10, R10 + MUL R8, R10, R10 + LSR $0x32, R10, R10 + MOVWU (R0)(R9<<2), R5 + MOVWU (R0)(R10<<2), R7 + MOVW R2, (R0)(R9<<2) + ADD $1, R2, R9 + MOVWU R9, R9 + MOVW R9, (R0)(R10<<2) + MOVD R6, R9 + LSR $0x10, R9, R9 + LSL $0x10, R9, R9 + MUL R8, R9, R9 + LSR $0x32, R9, R9 + MOVWU R2, R8 + MOVWU 24(RSP), R16 + SUBW R16, R8, R8 + ADD R8, R3, R15 + MOVWU 1(R15), R10 + MOVD R6, R8 + LSR $0x08, R8, R8 + CMPW R10, R8 + BNE no_repeat_found_encodeSnappyBlockAsm64K + ADD $1, R2, R6 + MOVWU R6, R6 + MOVWU 20(RSP), R5 + MOVWU R6, R7 + MOVWU 24(RSP), R16 + SUBSW R16, R7, R7 + BEQ repeat_extend_back_end_encodeSnappyBlockAsm64K + +repeat_extend_back_loop_encodeSnappyBlockAsm64K: + CMPW R5, R6 + BLS repeat_extend_back_end_encodeSnappyBlockAsm64K + ADD R7, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R8 + ADD R6, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R9 + AND $0xff, R9, R16 + AND $0xff, R8, R15 + CMP R16, R15 + BNE repeat_extend_back_end_encodeSnappyBlockAsm64K + SUB $1, R6, R6 + MOVWU R6, R6 + SUBSW $1, R7, R7 + BNE repeat_extend_back_loop_encodeSnappyBlockAsm64K + +repeat_extend_back_end_encodeSnappyBlockAsm64K: + MOVWU R6, R5 + MOVWU 20(RSP), R16 + SUBW R16, R5, R5 + ADD R5, R1, R5 + ADD $3, R5, R5 + MOVD 8(RSP), R16 + CMP R16, R5 + BLO repeat_dst_size_check_encodeSnappyBlockAsm64K + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +repeat_dst_size_check_encodeSnappyBlockAsm64K: + MOVWU 20(RSP), R5 + CMPW R6, R5 + BEQ emit_literal_done_repeat_emit_encodeSnappyBlockAsm64K + MOVWU R6, R7 + MOVW R6, 20(RSP) + ADD R5, R3, R8 + SUBW R5, R7, R7 + SUB $1, R7, R5 + MOVWU R5, R5 + CMPW $0x3c, R5 + BLO one_byte_repeat_emit_encodeSnappyBlockAsm64K + CMPW $0x00000100, R5 + BLO two_bytes_repeat_emit_encodeSnappyBlockAsm64K + BLO three_bytes_repeat_emit_encodeSnappyBlockAsm64K + +three_bytes_repeat_emit_encodeSnappyBlockAsm64K: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R5, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_repeat_emit_encodeSnappyBlockAsm64K + +two_bytes_repeat_emit_encodeSnappyBlockAsm64K: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R5, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R5 + BLO memmove_repeat_emit_encodeSnappyBlockAsm64K + JMP memmove_long_repeat_emit_encodeSnappyBlockAsm64K + +one_byte_repeat_emit_encodeSnappyBlockAsm64K: + LSLW $0x02, R5, R16 + BFI $0, R16, $8, R5 + MOVB R5, (R1) + ADD $0x01, R1, R1 + +memmove_repeat_emit_encodeSnappyBlockAsm64K: + ADD R7, R1, R5 + + // genMemMoveShort + CMP $0x08, R7 + BLS emit_lit_memmove_repeat_emit_encodeSnappyBlockAsm64K_memmove_move_8 + CMP $0x10, R7 + BLS emit_lit_memmove_repeat_emit_encodeSnappyBlockAsm64K_memmove_move_8through16 + CMP $0x20, R7 + BLS emit_lit_memmove_repeat_emit_encodeSnappyBlockAsm64K_memmove_move_17through32 + JMP emit_lit_memmove_repeat_emit_encodeSnappyBlockAsm64K_memmove_move_33through64 + +emit_lit_memmove_repeat_emit_encodeSnappyBlockAsm64K_memmove_move_8: + MOVD (R8), R9 + MOVD R9, (R1) + JMP memmove_end_copy_repeat_emit_encodeSnappyBlockAsm64K + +emit_lit_memmove_repeat_emit_encodeSnappyBlockAsm64K_memmove_move_8through16: + MOVD (R8), R9 + ADD R7, R8, R15 + MOVD -8(R15), R8 + MOVD R9, (R1) + ADD R7, R1, R15 + MOVD R8, -8(R15) + JMP memmove_end_copy_repeat_emit_encodeSnappyBlockAsm64K + +emit_lit_memmove_repeat_emit_encodeSnappyBlockAsm64K_memmove_move_17through32: + FMOVQ (R8), F0 + ADD R7, R8, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R7, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_repeat_emit_encodeSnappyBlockAsm64K + +emit_lit_memmove_repeat_emit_encodeSnappyBlockAsm64K_memmove_move_33through64: + FMOVQ (R8), F0 + FMOVQ 16(R8), F1 + ADD R7, R8, R15 + FMOVQ -32(R15), F2 + ADD R7, R8, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R7, R1, R15 + FMOVQ F2, -32(R15) + ADD R7, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_repeat_emit_encodeSnappyBlockAsm64K: + MOVD R5, R1 + JMP emit_literal_done_repeat_emit_encodeSnappyBlockAsm64K + +memmove_long_repeat_emit_encodeSnappyBlockAsm64K: + ADD R7, R1, R5 + + // genMemMoveLong + MOVD R8, R9 + MOVD R1, R10 + MOVD R7, R11 + +emit_lit_memmove_long_repeat_emit_encodeSnappyBlockAsm64Klarge_big_loop_back: + FMOVQ (R9), F0 + FMOVQ 16(R9), F1 + FMOVQ F0, (R10) + FMOVQ F1, 16(R10) + ADD $0x20, R9, R9 + ADD $0x20, R10, R10 + SUB $0x20, R11, R11 + CMP $0x20, R11 + BHS emit_lit_memmove_long_repeat_emit_encodeSnappyBlockAsm64Klarge_big_loop_back + ADD R7, R8, R15 + FMOVQ -32(R15), F0 + ADD R7, R8, R15 + FMOVQ -16(R15), F1 + ADD R7, R1, R15 + FMOVQ F0, -32(R15) + ADD R7, R1, R15 + FMOVQ F1, -16(R15) + MOVD R5, R1 + +emit_literal_done_repeat_emit_encodeSnappyBlockAsm64K: + ADDW $0x05, R2, R2 + MOVWU R2, R5 + MOVWU 24(RSP), R16 + SUBW R16, R5, R5 + MOVD src_len+32(FP), R7 + SUBW R2, R7, R7 + ADD R2, R3, R8 + ADD R5, R3, R5 + + // matchLen + MOVD $0, R10 + +matchlen_loopback_16_repeat_extend_encodeSnappyBlockAsm64K: + CMPW $0x10, R7 + BLO matchlen_match8_repeat_extend_encodeSnappyBlockAsm64K + MOVD (R8)(R10), R9 + ADD R10, R8, R15 + MOVD 8(R15), R11 + MOVD (R5)(R10), R16 + EOR R16, R9, R9 + TST R9, R9 + BNE matchlen_bsf_8_repeat_extend_encodeSnappyBlockAsm64K + ADD R10, R5, R15 + MOVD 8(R15), R16 + EOR R16, R11, R11 + TST R11, R11 + BNE matchlen_bsf_16repeat_extend_encodeSnappyBlockAsm64K + SUB $16, R7, R7 + MOVWU R7, R7 + ADD $16, R10, R10 + MOVWU R10, R10 + JMP matchlen_loopback_16_repeat_extend_encodeSnappyBlockAsm64K + +matchlen_bsf_16repeat_extend_encodeSnappyBlockAsm64K: + RBIT R11, R11 + CLZ R11, R11 + ASR $0x03, R11, R11 + ADD R11, R10, R10 + ADD $8, R10, R10 + MOVWU R10, R10 + JMP repeat_extend_forward_end_encodeSnappyBlockAsm64K + +matchlen_match8_repeat_extend_encodeSnappyBlockAsm64K: + CMPW $0x08, R7 + BLO matchlen_match4_repeat_extend_encodeSnappyBlockAsm64K + MOVD (R8)(R10), R9 + MOVD (R5)(R10), R16 + EOR R16, R9, R9 + TST R9, R9 + BNE matchlen_bsf_8_repeat_extend_encodeSnappyBlockAsm64K + SUB $8, R7, R7 + MOVWU R7, R7 + ADD $8, R10, R10 + MOVWU R10, R10 + JMP matchlen_match4_repeat_extend_encodeSnappyBlockAsm64K + +matchlen_bsf_8_repeat_extend_encodeSnappyBlockAsm64K: + RBIT R9, R9 + CLZ R9, R9 + ASR $0x03, R9, R9 + ADD R9, R10, R10 + MOVWU R10, R10 + JMP repeat_extend_forward_end_encodeSnappyBlockAsm64K + +matchlen_match4_repeat_extend_encodeSnappyBlockAsm64K: + CMPW $0x04, R7 + BLO matchlen_match2_repeat_extend_encodeSnappyBlockAsm64K + MOVWU (R8)(R10), R9 + MOVWU (R5)(R10), R16 + CMPW R9, R16 + BNE matchlen_match2_repeat_extend_encodeSnappyBlockAsm64K + SUB $4, R7, R7 + MOVWU R7, R7 + ADD $4, R10, R10 + MOVWU R10, R10 + +matchlen_match2_repeat_extend_encodeSnappyBlockAsm64K: + CMPW $0x01, R7 + BEQ matchlen_match1_repeat_extend_encodeSnappyBlockAsm64K + BLO repeat_extend_forward_end_encodeSnappyBlockAsm64K + MOVHU (R8)(R10), R16 + BFI $0, R16, $16, R9 + ADD R10, R5, R15 + MOVHU (R15), R15 + AND $0xffff, R9, R16 + CMP R16, R15 + BNE matchlen_match1_repeat_extend_encodeSnappyBlockAsm64K + ADD $2, R10, R10 + MOVWU R10, R10 + SUBSW $0x02, R7, R7 + BEQ repeat_extend_forward_end_encodeSnappyBlockAsm64K + +matchlen_match1_repeat_extend_encodeSnappyBlockAsm64K: + MOVBU (R8)(R10), R16 + BFI $0, R16, $8, R9 + ADD R10, R5, R15 + MOVBU (R15), R15 + AND $0xff, R9, R16 + CMP R16, R15 + BNE repeat_extend_forward_end_encodeSnappyBlockAsm64K + ADD $1, R10, R10 + MOVWU R10, R10 + +repeat_extend_forward_end_encodeSnappyBlockAsm64K: + ADDW R10, R2, R2 + MOVWU R2, R5 + SUBW R6, R5, R5 + MOVWU 24(RSP), R6 + + // emitCopy +two_byte_offset_repeat_as_copy_encodeSnappyBlockAsm64K: + CMPW $0x40, R5 + BLS two_byte_offset_short_repeat_as_copy_encodeSnappyBlockAsm64K + MOVD $0xee, R16 + MOVB R16, (R1) + MOVH R6, 1(R1) + SUB $60, R5, R5 + MOVWU R5, R5 + ADD $0x03, R1, R1 + JMP two_byte_offset_repeat_as_copy_encodeSnappyBlockAsm64K + +two_byte_offset_short_repeat_as_copy_encodeSnappyBlockAsm64K: + MOVWU R5, R7 + LSLW $0x02, R7, R7 + CMPW $0x0c, R5 + BHS emit_copy_three_repeat_as_copy_encodeSnappyBlockAsm64K + CMPW $0x00000800, R6 + BHS emit_copy_three_repeat_as_copy_encodeSnappyBlockAsm64K + SUB $15, R7, R7 + MOVWU R7, R7 + MOVB R6, 1(R1) + LSRW $0x08, R6, R6 + LSLW $0x05, R6, R6 + ORRW R6, R7, R7 + MOVB R7, (R1) + ADD $0x02, R1, R1 + JMP repeat_end_emit_encodeSnappyBlockAsm64K + +emit_copy_three_repeat_as_copy_encodeSnappyBlockAsm64K: + SUB $2, R7, R7 + MOVWU R7, R7 + MOVB R7, (R1) + MOVH R6, 1(R1) + ADD $0x03, R1, R1 + +repeat_end_emit_encodeSnappyBlockAsm64K: + MOVW R2, 20(RSP) + JMP search_loop_encodeSnappyBlockAsm64K + +no_repeat_found_encodeSnappyBlockAsm64K: + MOVWU (R3)(R5), R16 + CMPW R6, R16 + BEQ candidate_match_encodeSnappyBlockAsm64K + LSR $0x08, R6, R6 + MOVWU (R0)(R9<<2), R5 + ADD $2, R2, R8 + MOVWU R8, R8 + MOVWU (R3)(R7), R16 + CMPW R6, R16 + BEQ candidate2_match_encodeSnappyBlockAsm64K + MOVW R8, (R0)(R9<<2) + LSR $0x08, R6, R6 + MOVWU (R3)(R5), R16 + CMPW R6, R16 + BEQ candidate3_match_encodeSnappyBlockAsm64K + MOVWU 28(RSP), R2 + JMP search_loop_encodeSnappyBlockAsm64K + +candidate3_match_encodeSnappyBlockAsm64K: + ADDW $0x02, R2, R2 + JMP candidate_match_encodeSnappyBlockAsm64K + +candidate2_match_encodeSnappyBlockAsm64K: + MOVW R8, (R0)(R9<<2) + ADDW $1, R2, R2 + MOVWU R7, R5 + +candidate_match_encodeSnappyBlockAsm64K: + MOVWU 20(RSP), R6 + TSTW R5, R5 + BEQ match_extend_back_end_encodeSnappyBlockAsm64K + +match_extend_back_loop_encodeSnappyBlockAsm64K: + CMPW R6, R2 + BLS match_extend_back_end_encodeSnappyBlockAsm64K + ADD R5, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R7 + ADD R2, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R8 + AND $0xff, R8, R16 + AND $0xff, R7, R15 + CMP R16, R15 + BNE match_extend_back_end_encodeSnappyBlockAsm64K + SUB $1, R2, R2 + MOVWU R2, R2 + SUBSW $1, R5, R5 + BEQ match_extend_back_end_encodeSnappyBlockAsm64K + JMP match_extend_back_loop_encodeSnappyBlockAsm64K + +match_extend_back_end_encodeSnappyBlockAsm64K: + MOVWU R2, R6 + MOVWU 20(RSP), R16 + SUBW R16, R6, R6 + ADD R6, R1, R6 + ADD $3, R6, R6 + MOVD 8(RSP), R16 + CMP R16, R6 + BLO match_dst_size_check_encodeSnappyBlockAsm64K + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +match_dst_size_check_encodeSnappyBlockAsm64K: + MOVWU R2, R6 + MOVWU 20(RSP), R7 + CMPW R6, R7 + BEQ emit_literal_done_match_emit_encodeSnappyBlockAsm64K + MOVWU R6, R8 + MOVW R6, 20(RSP) + ADD R7, R3, R6 + SUBW R7, R8, R8 + SUB $1, R8, R7 + MOVWU R7, R7 + CMPW $0x3c, R7 + BLO one_byte_match_emit_encodeSnappyBlockAsm64K + CMPW $0x00000100, R7 + BLO two_bytes_match_emit_encodeSnappyBlockAsm64K + BLO three_bytes_match_emit_encodeSnappyBlockAsm64K + +three_bytes_match_emit_encodeSnappyBlockAsm64K: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R7, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_match_emit_encodeSnappyBlockAsm64K + +two_bytes_match_emit_encodeSnappyBlockAsm64K: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R7, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R7 + BLO memmove_match_emit_encodeSnappyBlockAsm64K + JMP memmove_long_match_emit_encodeSnappyBlockAsm64K + +one_byte_match_emit_encodeSnappyBlockAsm64K: + LSLW $0x02, R7, R16 + BFI $0, R16, $8, R7 + MOVB R7, (R1) + ADD $0x01, R1, R1 + +memmove_match_emit_encodeSnappyBlockAsm64K: + ADD R8, R1, R7 + + // genMemMoveShort + CMP $0x08, R8 + BLS emit_lit_memmove_match_emit_encodeSnappyBlockAsm64K_memmove_move_8 + CMP $0x10, R8 + BLS emit_lit_memmove_match_emit_encodeSnappyBlockAsm64K_memmove_move_8through16 + CMP $0x20, R8 + BLS emit_lit_memmove_match_emit_encodeSnappyBlockAsm64K_memmove_move_17through32 + JMP emit_lit_memmove_match_emit_encodeSnappyBlockAsm64K_memmove_move_33through64 + +emit_lit_memmove_match_emit_encodeSnappyBlockAsm64K_memmove_move_8: + MOVD (R6), R9 + MOVD R9, (R1) + JMP memmove_end_copy_match_emit_encodeSnappyBlockAsm64K + +emit_lit_memmove_match_emit_encodeSnappyBlockAsm64K_memmove_move_8through16: + MOVD (R6), R9 + ADD R8, R6, R15 + MOVD -8(R15), R6 + MOVD R9, (R1) + ADD R8, R1, R15 + MOVD R6, -8(R15) + JMP memmove_end_copy_match_emit_encodeSnappyBlockAsm64K + +emit_lit_memmove_match_emit_encodeSnappyBlockAsm64K_memmove_move_17through32: + FMOVQ (R6), F0 + ADD R8, R6, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_match_emit_encodeSnappyBlockAsm64K + +emit_lit_memmove_match_emit_encodeSnappyBlockAsm64K_memmove_move_33through64: + FMOVQ (R6), F0 + FMOVQ 16(R6), F1 + ADD R8, R6, R15 + FMOVQ -32(R15), F2 + ADD R8, R6, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R8, R1, R15 + FMOVQ F2, -32(R15) + ADD R8, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_match_emit_encodeSnappyBlockAsm64K: + MOVD R7, R1 + JMP emit_literal_done_match_emit_encodeSnappyBlockAsm64K + +memmove_long_match_emit_encodeSnappyBlockAsm64K: + ADD R8, R1, R7 + + // genMemMoveLong + MOVD R6, R9 + MOVD R1, R10 + MOVD R8, R11 + +emit_lit_memmove_long_match_emit_encodeSnappyBlockAsm64Klarge_big_loop_back: + FMOVQ (R9), F0 + FMOVQ 16(R9), F1 + FMOVQ F0, (R10) + FMOVQ F1, 16(R10) + ADD $0x20, R9, R9 + ADD $0x20, R10, R10 + SUB $0x20, R11, R11 + CMP $0x20, R11 + BHS emit_lit_memmove_long_match_emit_encodeSnappyBlockAsm64Klarge_big_loop_back + ADD R8, R6, R15 + FMOVQ -32(R15), F0 + ADD R8, R6, R15 + FMOVQ -16(R15), F1 + ADD R8, R1, R15 + FMOVQ F0, -32(R15) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + MOVD R7, R1 + +emit_literal_done_match_emit_encodeSnappyBlockAsm64K: +match_nolit_loop_encodeSnappyBlockAsm64K: + MOVWU R2, R6 + SUBW R5, R6, R6 + MOVW R6, 24(RSP) + ADDW $0x04, R2, R2 + ADDW $0x04, R5, R5 + MOVD src_len+32(FP), R6 + SUBW R2, R6, R6 + ADD R2, R3, R7 + ADD R5, R3, R5 + + // matchLen + MOVD $0, R9 + +matchlen_loopback_16_match_nolit_encodeSnappyBlockAsm64K: + CMPW $0x10, R6 + BLO matchlen_match8_match_nolit_encodeSnappyBlockAsm64K + MOVD (R7)(R9), R8 + ADD R9, R7, R15 + MOVD 8(R15), R10 + MOVD (R5)(R9), R16 + EOR R16, R8, R8 + TST R8, R8 + BNE matchlen_bsf_8_match_nolit_encodeSnappyBlockAsm64K + ADD R9, R5, R15 + MOVD 8(R15), R16 + EOR R16, R10, R10 + TST R10, R10 + BNE matchlen_bsf_16match_nolit_encodeSnappyBlockAsm64K + SUB $16, R6, R6 + MOVWU R6, R6 + ADD $16, R9, R9 + MOVWU R9, R9 + JMP matchlen_loopback_16_match_nolit_encodeSnappyBlockAsm64K + +matchlen_bsf_16match_nolit_encodeSnappyBlockAsm64K: + RBIT R10, R10 + CLZ R10, R10 + ASR $0x03, R10, R10 + ADD R10, R9, R9 + ADD $8, R9, R9 + MOVWU R9, R9 + JMP match_nolit_end_encodeSnappyBlockAsm64K + +matchlen_match8_match_nolit_encodeSnappyBlockAsm64K: + CMPW $0x08, R6 + BLO matchlen_match4_match_nolit_encodeSnappyBlockAsm64K + MOVD (R7)(R9), R8 + MOVD (R5)(R9), R16 + EOR R16, R8, R8 + TST R8, R8 + BNE matchlen_bsf_8_match_nolit_encodeSnappyBlockAsm64K + SUB $8, R6, R6 + MOVWU R6, R6 + ADD $8, R9, R9 + MOVWU R9, R9 + JMP matchlen_match4_match_nolit_encodeSnappyBlockAsm64K + +matchlen_bsf_8_match_nolit_encodeSnappyBlockAsm64K: + RBIT R8, R8 + CLZ R8, R8 + ASR $0x03, R8, R8 + ADD R8, R9, R9 + MOVWU R9, R9 + JMP match_nolit_end_encodeSnappyBlockAsm64K + +matchlen_match4_match_nolit_encodeSnappyBlockAsm64K: + CMPW $0x04, R6 + BLO matchlen_match2_match_nolit_encodeSnappyBlockAsm64K + MOVWU (R7)(R9), R8 + MOVWU (R5)(R9), R16 + CMPW R8, R16 + BNE matchlen_match2_match_nolit_encodeSnappyBlockAsm64K + SUB $4, R6, R6 + MOVWU R6, R6 + ADD $4, R9, R9 + MOVWU R9, R9 + +matchlen_match2_match_nolit_encodeSnappyBlockAsm64K: + CMPW $0x01, R6 + BEQ matchlen_match1_match_nolit_encodeSnappyBlockAsm64K + BLO match_nolit_end_encodeSnappyBlockAsm64K + MOVHU (R7)(R9), R16 + BFI $0, R16, $16, R8 + ADD R9, R5, R15 + MOVHU (R15), R15 + AND $0xffff, R8, R16 + CMP R16, R15 + BNE matchlen_match1_match_nolit_encodeSnappyBlockAsm64K + ADD $2, R9, R9 + MOVWU R9, R9 + SUBSW $0x02, R6, R6 + BEQ match_nolit_end_encodeSnappyBlockAsm64K + +matchlen_match1_match_nolit_encodeSnappyBlockAsm64K: + MOVBU (R7)(R9), R16 + BFI $0, R16, $8, R8 + ADD R9, R5, R15 + MOVBU (R15), R15 + AND $0xff, R8, R16 + CMP R16, R15 + BNE match_nolit_end_encodeSnappyBlockAsm64K + ADD $1, R9, R9 + MOVWU R9, R9 + +match_nolit_end_encodeSnappyBlockAsm64K: + ADDW R9, R2, R2 + MOVWU 24(RSP), R5 + ADDW $0x04, R9, R9 + MOVW R2, 20(RSP) + + // emitCopy +two_byte_offset_match_nolit_encodeSnappyBlockAsm64K: + CMPW $0x40, R9 + BLS two_byte_offset_short_match_nolit_encodeSnappyBlockAsm64K + MOVD $0xee, R16 + MOVB R16, (R1) + MOVH R5, 1(R1) + SUB $60, R9, R9 + MOVWU R9, R9 + ADD $0x03, R1, R1 + JMP two_byte_offset_match_nolit_encodeSnappyBlockAsm64K + +two_byte_offset_short_match_nolit_encodeSnappyBlockAsm64K: + MOVWU R9, R6 + LSLW $0x02, R6, R6 + CMPW $0x0c, R9 + BHS emit_copy_three_match_nolit_encodeSnappyBlockAsm64K + CMPW $0x00000800, R5 + BHS emit_copy_three_match_nolit_encodeSnappyBlockAsm64K + SUB $15, R6, R6 + MOVWU R6, R6 + MOVB R5, 1(R1) + LSRW $0x08, R5, R5 + LSLW $0x05, R5, R5 + ORRW R5, R6, R6 + MOVB R6, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeSnappyBlockAsm64K + +emit_copy_three_match_nolit_encodeSnappyBlockAsm64K: + SUB $2, R6, R6 + MOVWU R6, R6 + MOVB R6, (R1) + MOVH R5, 1(R1) + ADD $0x03, R1, R1 + +match_nolit_emitcopy_end_encodeSnappyBlockAsm64K: + MOVWU 16(RSP), R16 + CMPW R16, R2 + BHS emit_remainder_encodeSnappyBlockAsm64K + ADD R2, R3, R15 + MOVD -2(R15), R6 + MOVD 8(RSP), R16 + CMP R16, R1 + BLO match_nolit_dst_ok_encodeSnappyBlockAsm64K + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +match_nolit_dst_ok_encodeSnappyBlockAsm64K: + MOVD $0x0000cf1bbcdcbf9b, R8 + MOVD R6, R7 + LSR $0x10, R6, R6 + MOVD R6, R5 + LSL $0x10, R7, R7 + MUL R8, R7, R7 + LSR $0x32, R7, R7 + LSL $0x10, R5, R5 + MUL R8, R5, R5 + LSR $0x32, R5, R5 + SUB $2, R2, R8 + MOVWU R8, R8 + ADD R5<<2, R0, R9 + MOVWU (R9), R5 + MOVW R8, (R0)(R7<<2) + MOVW R2, (R9) + MOVWU (R3)(R5), R16 + CMPW R6, R16 + BEQ match_nolit_loop_encodeSnappyBlockAsm64K + ADDW $1, R2, R2 + JMP search_loop_encodeSnappyBlockAsm64K + +emit_remainder_encodeSnappyBlockAsm64K: + MOVD src_len+32(FP), R0 + MOVWU 20(RSP), R16 + SUBW R16, R0, R0 + ADD R0, R1, R0 + ADD $3, R0, R0 + MOVD 8(RSP), R16 + CMP R16, R0 + BLO emit_remainder_ok_encodeSnappyBlockAsm64K + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +emit_remainder_ok_encodeSnappyBlockAsm64K: + MOVD src_len+32(FP), R0 + MOVWU 20(RSP), R2 + CMPW R0, R2 + BEQ emit_literal_done_emit_remainder_encodeSnappyBlockAsm64K + MOVWU R0, R5 + MOVW R0, 20(RSP) + ADD R2, R3, R0 + SUBW R2, R5, R5 + SUB $1, R5, R2 + MOVWU R2, R2 + CMPW $0x3c, R2 + BLO one_byte_emit_remainder_encodeSnappyBlockAsm64K + CMPW $0x00000100, R2 + BLO two_bytes_emit_remainder_encodeSnappyBlockAsm64K + BLO three_bytes_emit_remainder_encodeSnappyBlockAsm64K + +three_bytes_emit_remainder_encodeSnappyBlockAsm64K: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R2, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_emit_remainder_encodeSnappyBlockAsm64K + +two_bytes_emit_remainder_encodeSnappyBlockAsm64K: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R2, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R2 + BLO memmove_emit_remainder_encodeSnappyBlockAsm64K + JMP memmove_long_emit_remainder_encodeSnappyBlockAsm64K + +one_byte_emit_remainder_encodeSnappyBlockAsm64K: + LSLW $0x02, R2, R16 + BFI $0, R16, $8, R2 + MOVB R2, (R1) + ADD $0x01, R1, R1 + +memmove_emit_remainder_encodeSnappyBlockAsm64K: + ADD R5, R1, R2 + MOVWU R5, R3 + + // genMemMoveShort + CMP $0x03, R3 + BLO emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm64K_memmove_move_1or2 + BEQ emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm64K_memmove_move_3 + CMP $0x08, R3 + BLO emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm64K_memmove_move_4through7 + CMP $0x10, R3 + BLS emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm64K_memmove_move_8through16 + CMP $0x20, R3 + BLS emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm64K_memmove_move_17through32 + JMP emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm64K_memmove_move_33through64 + +emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm64K_memmove_move_1or2: + MOVBU (R0), R16 + BFI $0, R16, $8, R5 + ADD R3, R0, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R0 + MOVB R5, (R1) + ADD R3, R1, R15 + MOVB R0, -1(R15) + JMP memmove_end_copy_emit_remainder_encodeSnappyBlockAsm64K + +emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm64K_memmove_move_3: + MOVHU (R0), R16 + BFI $0, R16, $16, R5 + MOVBU 2(R0), R16 + BFI $0, R16, $8, R0 + MOVH R5, (R1) + MOVB R0, 2(R1) + JMP memmove_end_copy_emit_remainder_encodeSnappyBlockAsm64K + +emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm64K_memmove_move_4through7: + MOVWU (R0), R5 + ADD R3, R0, R15 + MOVWU -4(R15), R0 + MOVW R5, (R1) + ADD R3, R1, R15 + MOVW R0, -4(R15) + JMP memmove_end_copy_emit_remainder_encodeSnappyBlockAsm64K + +emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm64K_memmove_move_8through16: + MOVD (R0), R5 + ADD R3, R0, R15 + MOVD -8(R15), R0 + MOVD R5, (R1) + ADD R3, R1, R15 + MOVD R0, -8(R15) + JMP memmove_end_copy_emit_remainder_encodeSnappyBlockAsm64K + +emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm64K_memmove_move_17through32: + FMOVQ (R0), F0 + ADD R3, R0, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R3, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_emit_remainder_encodeSnappyBlockAsm64K + +emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm64K_memmove_move_33through64: + FMOVQ (R0), F0 + FMOVQ 16(R0), F1 + ADD R3, R0, R15 + FMOVQ -32(R15), F2 + ADD R3, R0, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R3, R1, R15 + FMOVQ F2, -32(R15) + ADD R3, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_emit_remainder_encodeSnappyBlockAsm64K: + MOVD R2, R1 + JMP emit_literal_done_emit_remainder_encodeSnappyBlockAsm64K + +memmove_long_emit_remainder_encodeSnappyBlockAsm64K: + ADD R5, R1, R2 + MOVWU R5, R3 + + // genMemMoveLong + MOVD R0, R5 + MOVD R1, R6 + MOVD R3, R7 + +emit_lit_memmove_long_emit_remainder_encodeSnappyBlockAsm64Klarge_big_loop_back: + FMOVQ (R5), F0 + FMOVQ 16(R5), F1 + FMOVQ F0, (R6) + FMOVQ F1, 16(R6) + ADD $0x20, R5, R5 + ADD $0x20, R6, R6 + SUB $0x20, R7, R7 + CMP $0x20, R7 + BHS emit_lit_memmove_long_emit_remainder_encodeSnappyBlockAsm64Klarge_big_loop_back + ADD R3, R0, R15 + FMOVQ -32(R15), F0 + ADD R3, R0, R15 + FMOVQ -16(R15), F1 + ADD R3, R1, R15 + FMOVQ F0, -32(R15) + ADD R3, R1, R15 + FMOVQ F1, -16(R15) + MOVD R2, R1 + +emit_literal_done_emit_remainder_encodeSnappyBlockAsm64K: + MOVD dst_base+0(FP), R0 + SUB R0, R1, R1 + MOVD R1, ret+56(FP) + RET + +// func encodeSnappyBlockAsm12B(dst []byte, src []byte, tmp *[16384]byte) int +// Requires: BMI, SSE2 +TEXT ·encodeSnappyBlockAsm12B(SB), $24-64 + MOVD tmp+48(FP), R0 + MOVD dst_base+0(FP), R1 + MOVD $0x00000080, R2 + MOVD R0, R3 + VEOR V0.B16, V0.B16, V0.B16 + +zero_loop_encodeSnappyBlockAsm12B: + FMOVQ F0, (R3) + FMOVQ F0, 16(R3) + FMOVQ F0, 32(R3) + FMOVQ F0, 48(R3) + FMOVQ F0, 64(R3) + FMOVQ F0, 80(R3) + FMOVQ F0, 96(R3) + FMOVQ F0, 112(R3) + ADD $0x80, R3, R3 + SUBS $1, R2, R2 + BNE zero_loop_encodeSnappyBlockAsm12B + MOVD $0x00000000, R16 + MOVW R16, 20(RSP) + MOVD src_len+32(FP), R2 + SUB $9, R2, R3 + SUB $8, R2, R5 + MOVW R5, 16(RSP) + LSR $0x05, R2, R2 + SUBW R2, R3, R3 + ADD R3, R1, R3 + MOVD R3, 8(RSP) + MOVD $0x00000001, R2 + MOVW R2, 24(RSP) + MOVD src_base+24(FP), R3 + +search_loop_encodeSnappyBlockAsm12B: + MOVWU R2, R5 + MOVWU 20(RSP), R16 + SUBW R16, R5, R5 + LSRW $0x05, R5, R5 + ADD R5, R2, R5 + ADD $4, R5, R5 + MOVWU R5, R5 + MOVWU 16(RSP), R16 + CMPW R16, R5 + BHS emit_remainder_encodeSnappyBlockAsm12B + MOVD (R3)(R2), R6 + MOVW R5, 28(RSP) + MOVD $0x000000cf1bbcdcbb, R8 + MOVD R6, R9 + MOVD R6, R10 + LSR $0x08, R10, R10 + LSL $0x18, R9, R9 + MUL R8, R9, R9 + LSR $0x34, R9, R9 + LSL $0x18, R10, R10 + MUL R8, R10, R10 + LSR $0x34, R10, R10 + MOVWU (R0)(R9<<2), R5 + MOVWU (R0)(R10<<2), R7 + MOVW R2, (R0)(R9<<2) + ADD $1, R2, R9 + MOVWU R9, R9 + MOVW R9, (R0)(R10<<2) + MOVD R6, R9 + LSR $0x10, R9, R9 + LSL $0x18, R9, R9 + MUL R8, R9, R9 + LSR $0x34, R9, R9 + MOVWU R2, R8 + MOVWU 24(RSP), R16 + SUBW R16, R8, R8 + ADD R8, R3, R15 + MOVWU 1(R15), R10 + MOVD R6, R8 + LSR $0x08, R8, R8 + CMPW R10, R8 + BNE no_repeat_found_encodeSnappyBlockAsm12B + ADD $1, R2, R6 + MOVWU R6, R6 + MOVWU 20(RSP), R5 + MOVWU R6, R7 + MOVWU 24(RSP), R16 + SUBSW R16, R7, R7 + BEQ repeat_extend_back_end_encodeSnappyBlockAsm12B + +repeat_extend_back_loop_encodeSnappyBlockAsm12B: + CMPW R5, R6 + BLS repeat_extend_back_end_encodeSnappyBlockAsm12B + ADD R7, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R8 + ADD R6, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R9 + AND $0xff, R9, R16 + AND $0xff, R8, R15 + CMP R16, R15 + BNE repeat_extend_back_end_encodeSnappyBlockAsm12B + SUB $1, R6, R6 + MOVWU R6, R6 + SUBSW $1, R7, R7 + BNE repeat_extend_back_loop_encodeSnappyBlockAsm12B + +repeat_extend_back_end_encodeSnappyBlockAsm12B: + MOVWU R6, R5 + MOVWU 20(RSP), R16 + SUBW R16, R5, R5 + ADD R5, R1, R5 + ADD $3, R5, R5 + MOVD 8(RSP), R16 + CMP R16, R5 + BLO repeat_dst_size_check_encodeSnappyBlockAsm12B + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +repeat_dst_size_check_encodeSnappyBlockAsm12B: + MOVWU 20(RSP), R5 + CMPW R6, R5 + BEQ emit_literal_done_repeat_emit_encodeSnappyBlockAsm12B + MOVWU R6, R7 + MOVW R6, 20(RSP) + ADD R5, R3, R8 + SUBW R5, R7, R7 + SUB $1, R7, R5 + MOVWU R5, R5 + CMPW $0x3c, R5 + BLO one_byte_repeat_emit_encodeSnappyBlockAsm12B + CMPW $0x00000100, R5 + BLO two_bytes_repeat_emit_encodeSnappyBlockAsm12B + BLO three_bytes_repeat_emit_encodeSnappyBlockAsm12B + +three_bytes_repeat_emit_encodeSnappyBlockAsm12B: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R5, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_repeat_emit_encodeSnappyBlockAsm12B + +two_bytes_repeat_emit_encodeSnappyBlockAsm12B: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R5, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R5 + BLO memmove_repeat_emit_encodeSnappyBlockAsm12B + JMP memmove_long_repeat_emit_encodeSnappyBlockAsm12B + +one_byte_repeat_emit_encodeSnappyBlockAsm12B: + LSLW $0x02, R5, R16 + BFI $0, R16, $8, R5 + MOVB R5, (R1) + ADD $0x01, R1, R1 + +memmove_repeat_emit_encodeSnappyBlockAsm12B: + ADD R7, R1, R5 + + // genMemMoveShort + CMP $0x08, R7 + BLS emit_lit_memmove_repeat_emit_encodeSnappyBlockAsm12B_memmove_move_8 + CMP $0x10, R7 + BLS emit_lit_memmove_repeat_emit_encodeSnappyBlockAsm12B_memmove_move_8through16 + CMP $0x20, R7 + BLS emit_lit_memmove_repeat_emit_encodeSnappyBlockAsm12B_memmove_move_17through32 + JMP emit_lit_memmove_repeat_emit_encodeSnappyBlockAsm12B_memmove_move_33through64 + +emit_lit_memmove_repeat_emit_encodeSnappyBlockAsm12B_memmove_move_8: + MOVD (R8), R9 + MOVD R9, (R1) + JMP memmove_end_copy_repeat_emit_encodeSnappyBlockAsm12B + +emit_lit_memmove_repeat_emit_encodeSnappyBlockAsm12B_memmove_move_8through16: + MOVD (R8), R9 + ADD R7, R8, R15 + MOVD -8(R15), R8 + MOVD R9, (R1) + ADD R7, R1, R15 + MOVD R8, -8(R15) + JMP memmove_end_copy_repeat_emit_encodeSnappyBlockAsm12B + +emit_lit_memmove_repeat_emit_encodeSnappyBlockAsm12B_memmove_move_17through32: + FMOVQ (R8), F0 + ADD R7, R8, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R7, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_repeat_emit_encodeSnappyBlockAsm12B + +emit_lit_memmove_repeat_emit_encodeSnappyBlockAsm12B_memmove_move_33through64: + FMOVQ (R8), F0 + FMOVQ 16(R8), F1 + ADD R7, R8, R15 + FMOVQ -32(R15), F2 + ADD R7, R8, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R7, R1, R15 + FMOVQ F2, -32(R15) + ADD R7, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_repeat_emit_encodeSnappyBlockAsm12B: + MOVD R5, R1 + JMP emit_literal_done_repeat_emit_encodeSnappyBlockAsm12B + +memmove_long_repeat_emit_encodeSnappyBlockAsm12B: + ADD R7, R1, R5 + + // genMemMoveLong + MOVD R8, R9 + MOVD R1, R10 + MOVD R7, R11 + +emit_lit_memmove_long_repeat_emit_encodeSnappyBlockAsm12Blarge_big_loop_back: + FMOVQ (R9), F0 + FMOVQ 16(R9), F1 + FMOVQ F0, (R10) + FMOVQ F1, 16(R10) + ADD $0x20, R9, R9 + ADD $0x20, R10, R10 + SUB $0x20, R11, R11 + CMP $0x20, R11 + BHS emit_lit_memmove_long_repeat_emit_encodeSnappyBlockAsm12Blarge_big_loop_back + ADD R7, R8, R15 + FMOVQ -32(R15), F0 + ADD R7, R8, R15 + FMOVQ -16(R15), F1 + ADD R7, R1, R15 + FMOVQ F0, -32(R15) + ADD R7, R1, R15 + FMOVQ F1, -16(R15) + MOVD R5, R1 + +emit_literal_done_repeat_emit_encodeSnappyBlockAsm12B: + ADDW $0x05, R2, R2 + MOVWU R2, R5 + MOVWU 24(RSP), R16 + SUBW R16, R5, R5 + MOVD src_len+32(FP), R7 + SUBW R2, R7, R7 + ADD R2, R3, R8 + ADD R5, R3, R5 + + // matchLen + MOVD $0, R10 + +matchlen_loopback_16_repeat_extend_encodeSnappyBlockAsm12B: + CMPW $0x10, R7 + BLO matchlen_match8_repeat_extend_encodeSnappyBlockAsm12B + MOVD (R8)(R10), R9 + ADD R10, R8, R15 + MOVD 8(R15), R11 + MOVD (R5)(R10), R16 + EOR R16, R9, R9 + TST R9, R9 + BNE matchlen_bsf_8_repeat_extend_encodeSnappyBlockAsm12B + ADD R10, R5, R15 + MOVD 8(R15), R16 + EOR R16, R11, R11 + TST R11, R11 + BNE matchlen_bsf_16repeat_extend_encodeSnappyBlockAsm12B + SUB $16, R7, R7 + MOVWU R7, R7 + ADD $16, R10, R10 + MOVWU R10, R10 + JMP matchlen_loopback_16_repeat_extend_encodeSnappyBlockAsm12B + +matchlen_bsf_16repeat_extend_encodeSnappyBlockAsm12B: + RBIT R11, R11 + CLZ R11, R11 + ASR $0x03, R11, R11 + ADD R11, R10, R10 + ADD $8, R10, R10 + MOVWU R10, R10 + JMP repeat_extend_forward_end_encodeSnappyBlockAsm12B + +matchlen_match8_repeat_extend_encodeSnappyBlockAsm12B: + CMPW $0x08, R7 + BLO matchlen_match4_repeat_extend_encodeSnappyBlockAsm12B + MOVD (R8)(R10), R9 + MOVD (R5)(R10), R16 + EOR R16, R9, R9 + TST R9, R9 + BNE matchlen_bsf_8_repeat_extend_encodeSnappyBlockAsm12B + SUB $8, R7, R7 + MOVWU R7, R7 + ADD $8, R10, R10 + MOVWU R10, R10 + JMP matchlen_match4_repeat_extend_encodeSnappyBlockAsm12B + +matchlen_bsf_8_repeat_extend_encodeSnappyBlockAsm12B: + RBIT R9, R9 + CLZ R9, R9 + ASR $0x03, R9, R9 + ADD R9, R10, R10 + MOVWU R10, R10 + JMP repeat_extend_forward_end_encodeSnappyBlockAsm12B + +matchlen_match4_repeat_extend_encodeSnappyBlockAsm12B: + CMPW $0x04, R7 + BLO matchlen_match2_repeat_extend_encodeSnappyBlockAsm12B + MOVWU (R8)(R10), R9 + MOVWU (R5)(R10), R16 + CMPW R9, R16 + BNE matchlen_match2_repeat_extend_encodeSnappyBlockAsm12B + SUB $4, R7, R7 + MOVWU R7, R7 + ADD $4, R10, R10 + MOVWU R10, R10 + +matchlen_match2_repeat_extend_encodeSnappyBlockAsm12B: + CMPW $0x01, R7 + BEQ matchlen_match1_repeat_extend_encodeSnappyBlockAsm12B + BLO repeat_extend_forward_end_encodeSnappyBlockAsm12B + MOVHU (R8)(R10), R16 + BFI $0, R16, $16, R9 + ADD R10, R5, R15 + MOVHU (R15), R15 + AND $0xffff, R9, R16 + CMP R16, R15 + BNE matchlen_match1_repeat_extend_encodeSnappyBlockAsm12B + ADD $2, R10, R10 + MOVWU R10, R10 + SUBSW $0x02, R7, R7 + BEQ repeat_extend_forward_end_encodeSnappyBlockAsm12B + +matchlen_match1_repeat_extend_encodeSnappyBlockAsm12B: + MOVBU (R8)(R10), R16 + BFI $0, R16, $8, R9 + ADD R10, R5, R15 + MOVBU (R15), R15 + AND $0xff, R9, R16 + CMP R16, R15 + BNE repeat_extend_forward_end_encodeSnappyBlockAsm12B + ADD $1, R10, R10 + MOVWU R10, R10 + +repeat_extend_forward_end_encodeSnappyBlockAsm12B: + ADDW R10, R2, R2 + MOVWU R2, R5 + SUBW R6, R5, R5 + MOVWU 24(RSP), R6 + + // emitCopy +two_byte_offset_repeat_as_copy_encodeSnappyBlockAsm12B: + CMPW $0x40, R5 + BLS two_byte_offset_short_repeat_as_copy_encodeSnappyBlockAsm12B + MOVD $0xee, R16 + MOVB R16, (R1) + MOVH R6, 1(R1) + SUB $60, R5, R5 + MOVWU R5, R5 + ADD $0x03, R1, R1 + JMP two_byte_offset_repeat_as_copy_encodeSnappyBlockAsm12B + +two_byte_offset_short_repeat_as_copy_encodeSnappyBlockAsm12B: + MOVWU R5, R7 + LSLW $0x02, R7, R7 + CMPW $0x0c, R5 + BHS emit_copy_three_repeat_as_copy_encodeSnappyBlockAsm12B + CMPW $0x00000800, R6 + BHS emit_copy_three_repeat_as_copy_encodeSnappyBlockAsm12B + SUB $15, R7, R7 + MOVWU R7, R7 + MOVB R6, 1(R1) + LSRW $0x08, R6, R6 + LSLW $0x05, R6, R6 + ORRW R6, R7, R7 + MOVB R7, (R1) + ADD $0x02, R1, R1 + JMP repeat_end_emit_encodeSnappyBlockAsm12B + +emit_copy_three_repeat_as_copy_encodeSnappyBlockAsm12B: + SUB $2, R7, R7 + MOVWU R7, R7 + MOVB R7, (R1) + MOVH R6, 1(R1) + ADD $0x03, R1, R1 + +repeat_end_emit_encodeSnappyBlockAsm12B: + MOVW R2, 20(RSP) + JMP search_loop_encodeSnappyBlockAsm12B + +no_repeat_found_encodeSnappyBlockAsm12B: + MOVWU (R3)(R5), R16 + CMPW R6, R16 + BEQ candidate_match_encodeSnappyBlockAsm12B + LSR $0x08, R6, R6 + MOVWU (R0)(R9<<2), R5 + ADD $2, R2, R8 + MOVWU R8, R8 + MOVWU (R3)(R7), R16 + CMPW R6, R16 + BEQ candidate2_match_encodeSnappyBlockAsm12B + MOVW R8, (R0)(R9<<2) + LSR $0x08, R6, R6 + MOVWU (R3)(R5), R16 + CMPW R6, R16 + BEQ candidate3_match_encodeSnappyBlockAsm12B + MOVWU 28(RSP), R2 + JMP search_loop_encodeSnappyBlockAsm12B + +candidate3_match_encodeSnappyBlockAsm12B: + ADDW $0x02, R2, R2 + JMP candidate_match_encodeSnappyBlockAsm12B + +candidate2_match_encodeSnappyBlockAsm12B: + MOVW R8, (R0)(R9<<2) + ADDW $1, R2, R2 + MOVWU R7, R5 + +candidate_match_encodeSnappyBlockAsm12B: + MOVWU 20(RSP), R6 + TSTW R5, R5 + BEQ match_extend_back_end_encodeSnappyBlockAsm12B + +match_extend_back_loop_encodeSnappyBlockAsm12B: + CMPW R6, R2 + BLS match_extend_back_end_encodeSnappyBlockAsm12B + ADD R5, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R7 + ADD R2, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R8 + AND $0xff, R8, R16 + AND $0xff, R7, R15 + CMP R16, R15 + BNE match_extend_back_end_encodeSnappyBlockAsm12B + SUB $1, R2, R2 + MOVWU R2, R2 + SUBSW $1, R5, R5 + BEQ match_extend_back_end_encodeSnappyBlockAsm12B + JMP match_extend_back_loop_encodeSnappyBlockAsm12B + +match_extend_back_end_encodeSnappyBlockAsm12B: + MOVWU R2, R6 + MOVWU 20(RSP), R16 + SUBW R16, R6, R6 + ADD R6, R1, R6 + ADD $3, R6, R6 + MOVD 8(RSP), R16 + CMP R16, R6 + BLO match_dst_size_check_encodeSnappyBlockAsm12B + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +match_dst_size_check_encodeSnappyBlockAsm12B: + MOVWU R2, R6 + MOVWU 20(RSP), R7 + CMPW R6, R7 + BEQ emit_literal_done_match_emit_encodeSnappyBlockAsm12B + MOVWU R6, R8 + MOVW R6, 20(RSP) + ADD R7, R3, R6 + SUBW R7, R8, R8 + SUB $1, R8, R7 + MOVWU R7, R7 + CMPW $0x3c, R7 + BLO one_byte_match_emit_encodeSnappyBlockAsm12B + CMPW $0x00000100, R7 + BLO two_bytes_match_emit_encodeSnappyBlockAsm12B + BLO three_bytes_match_emit_encodeSnappyBlockAsm12B + +three_bytes_match_emit_encodeSnappyBlockAsm12B: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R7, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_match_emit_encodeSnappyBlockAsm12B + +two_bytes_match_emit_encodeSnappyBlockAsm12B: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R7, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R7 + BLO memmove_match_emit_encodeSnappyBlockAsm12B + JMP memmove_long_match_emit_encodeSnappyBlockAsm12B + +one_byte_match_emit_encodeSnappyBlockAsm12B: + LSLW $0x02, R7, R16 + BFI $0, R16, $8, R7 + MOVB R7, (R1) + ADD $0x01, R1, R1 + +memmove_match_emit_encodeSnappyBlockAsm12B: + ADD R8, R1, R7 + + // genMemMoveShort + CMP $0x08, R8 + BLS emit_lit_memmove_match_emit_encodeSnappyBlockAsm12B_memmove_move_8 + CMP $0x10, R8 + BLS emit_lit_memmove_match_emit_encodeSnappyBlockAsm12B_memmove_move_8through16 + CMP $0x20, R8 + BLS emit_lit_memmove_match_emit_encodeSnappyBlockAsm12B_memmove_move_17through32 + JMP emit_lit_memmove_match_emit_encodeSnappyBlockAsm12B_memmove_move_33through64 + +emit_lit_memmove_match_emit_encodeSnappyBlockAsm12B_memmove_move_8: + MOVD (R6), R9 + MOVD R9, (R1) + JMP memmove_end_copy_match_emit_encodeSnappyBlockAsm12B + +emit_lit_memmove_match_emit_encodeSnappyBlockAsm12B_memmove_move_8through16: + MOVD (R6), R9 + ADD R8, R6, R15 + MOVD -8(R15), R6 + MOVD R9, (R1) + ADD R8, R1, R15 + MOVD R6, -8(R15) + JMP memmove_end_copy_match_emit_encodeSnappyBlockAsm12B + +emit_lit_memmove_match_emit_encodeSnappyBlockAsm12B_memmove_move_17through32: + FMOVQ (R6), F0 + ADD R8, R6, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_match_emit_encodeSnappyBlockAsm12B + +emit_lit_memmove_match_emit_encodeSnappyBlockAsm12B_memmove_move_33through64: + FMOVQ (R6), F0 + FMOVQ 16(R6), F1 + ADD R8, R6, R15 + FMOVQ -32(R15), F2 + ADD R8, R6, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R8, R1, R15 + FMOVQ F2, -32(R15) + ADD R8, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_match_emit_encodeSnappyBlockAsm12B: + MOVD R7, R1 + JMP emit_literal_done_match_emit_encodeSnappyBlockAsm12B + +memmove_long_match_emit_encodeSnappyBlockAsm12B: + ADD R8, R1, R7 + + // genMemMoveLong + MOVD R6, R9 + MOVD R1, R10 + MOVD R8, R11 + +emit_lit_memmove_long_match_emit_encodeSnappyBlockAsm12Blarge_big_loop_back: + FMOVQ (R9), F0 + FMOVQ 16(R9), F1 + FMOVQ F0, (R10) + FMOVQ F1, 16(R10) + ADD $0x20, R9, R9 + ADD $0x20, R10, R10 + SUB $0x20, R11, R11 + CMP $0x20, R11 + BHS emit_lit_memmove_long_match_emit_encodeSnappyBlockAsm12Blarge_big_loop_back + ADD R8, R6, R15 + FMOVQ -32(R15), F0 + ADD R8, R6, R15 + FMOVQ -16(R15), F1 + ADD R8, R1, R15 + FMOVQ F0, -32(R15) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + MOVD R7, R1 + +emit_literal_done_match_emit_encodeSnappyBlockAsm12B: +match_nolit_loop_encodeSnappyBlockAsm12B: + MOVWU R2, R6 + SUBW R5, R6, R6 + MOVW R6, 24(RSP) + ADDW $0x04, R2, R2 + ADDW $0x04, R5, R5 + MOVD src_len+32(FP), R6 + SUBW R2, R6, R6 + ADD R2, R3, R7 + ADD R5, R3, R5 + + // matchLen + MOVD $0, R9 + +matchlen_loopback_16_match_nolit_encodeSnappyBlockAsm12B: + CMPW $0x10, R6 + BLO matchlen_match8_match_nolit_encodeSnappyBlockAsm12B + MOVD (R7)(R9), R8 + ADD R9, R7, R15 + MOVD 8(R15), R10 + MOVD (R5)(R9), R16 + EOR R16, R8, R8 + TST R8, R8 + BNE matchlen_bsf_8_match_nolit_encodeSnappyBlockAsm12B + ADD R9, R5, R15 + MOVD 8(R15), R16 + EOR R16, R10, R10 + TST R10, R10 + BNE matchlen_bsf_16match_nolit_encodeSnappyBlockAsm12B + SUB $16, R6, R6 + MOVWU R6, R6 + ADD $16, R9, R9 + MOVWU R9, R9 + JMP matchlen_loopback_16_match_nolit_encodeSnappyBlockAsm12B + +matchlen_bsf_16match_nolit_encodeSnappyBlockAsm12B: + RBIT R10, R10 + CLZ R10, R10 + ASR $0x03, R10, R10 + ADD R10, R9, R9 + ADD $8, R9, R9 + MOVWU R9, R9 + JMP match_nolit_end_encodeSnappyBlockAsm12B + +matchlen_match8_match_nolit_encodeSnappyBlockAsm12B: + CMPW $0x08, R6 + BLO matchlen_match4_match_nolit_encodeSnappyBlockAsm12B + MOVD (R7)(R9), R8 + MOVD (R5)(R9), R16 + EOR R16, R8, R8 + TST R8, R8 + BNE matchlen_bsf_8_match_nolit_encodeSnappyBlockAsm12B + SUB $8, R6, R6 + MOVWU R6, R6 + ADD $8, R9, R9 + MOVWU R9, R9 + JMP matchlen_match4_match_nolit_encodeSnappyBlockAsm12B + +matchlen_bsf_8_match_nolit_encodeSnappyBlockAsm12B: + RBIT R8, R8 + CLZ R8, R8 + ASR $0x03, R8, R8 + ADD R8, R9, R9 + MOVWU R9, R9 + JMP match_nolit_end_encodeSnappyBlockAsm12B + +matchlen_match4_match_nolit_encodeSnappyBlockAsm12B: + CMPW $0x04, R6 + BLO matchlen_match2_match_nolit_encodeSnappyBlockAsm12B + MOVWU (R7)(R9), R8 + MOVWU (R5)(R9), R16 + CMPW R8, R16 + BNE matchlen_match2_match_nolit_encodeSnappyBlockAsm12B + SUB $4, R6, R6 + MOVWU R6, R6 + ADD $4, R9, R9 + MOVWU R9, R9 + +matchlen_match2_match_nolit_encodeSnappyBlockAsm12B: + CMPW $0x01, R6 + BEQ matchlen_match1_match_nolit_encodeSnappyBlockAsm12B + BLO match_nolit_end_encodeSnappyBlockAsm12B + MOVHU (R7)(R9), R16 + BFI $0, R16, $16, R8 + ADD R9, R5, R15 + MOVHU (R15), R15 + AND $0xffff, R8, R16 + CMP R16, R15 + BNE matchlen_match1_match_nolit_encodeSnappyBlockAsm12B + ADD $2, R9, R9 + MOVWU R9, R9 + SUBSW $0x02, R6, R6 + BEQ match_nolit_end_encodeSnappyBlockAsm12B + +matchlen_match1_match_nolit_encodeSnappyBlockAsm12B: + MOVBU (R7)(R9), R16 + BFI $0, R16, $8, R8 + ADD R9, R5, R15 + MOVBU (R15), R15 + AND $0xff, R8, R16 + CMP R16, R15 + BNE match_nolit_end_encodeSnappyBlockAsm12B + ADD $1, R9, R9 + MOVWU R9, R9 + +match_nolit_end_encodeSnappyBlockAsm12B: + ADDW R9, R2, R2 + MOVWU 24(RSP), R5 + ADDW $0x04, R9, R9 + MOVW R2, 20(RSP) + + // emitCopy +two_byte_offset_match_nolit_encodeSnappyBlockAsm12B: + CMPW $0x40, R9 + BLS two_byte_offset_short_match_nolit_encodeSnappyBlockAsm12B + MOVD $0xee, R16 + MOVB R16, (R1) + MOVH R5, 1(R1) + SUB $60, R9, R9 + MOVWU R9, R9 + ADD $0x03, R1, R1 + JMP two_byte_offset_match_nolit_encodeSnappyBlockAsm12B + +two_byte_offset_short_match_nolit_encodeSnappyBlockAsm12B: + MOVWU R9, R6 + LSLW $0x02, R6, R6 + CMPW $0x0c, R9 + BHS emit_copy_three_match_nolit_encodeSnappyBlockAsm12B + CMPW $0x00000800, R5 + BHS emit_copy_three_match_nolit_encodeSnappyBlockAsm12B + SUB $15, R6, R6 + MOVWU R6, R6 + MOVB R5, 1(R1) + LSRW $0x08, R5, R5 + LSLW $0x05, R5, R5 + ORRW R5, R6, R6 + MOVB R6, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeSnappyBlockAsm12B + +emit_copy_three_match_nolit_encodeSnappyBlockAsm12B: + SUB $2, R6, R6 + MOVWU R6, R6 + MOVB R6, (R1) + MOVH R5, 1(R1) + ADD $0x03, R1, R1 + +match_nolit_emitcopy_end_encodeSnappyBlockAsm12B: + MOVWU 16(RSP), R16 + CMPW R16, R2 + BHS emit_remainder_encodeSnappyBlockAsm12B + ADD R2, R3, R15 + MOVD -2(R15), R6 + MOVD 8(RSP), R16 + CMP R16, R1 + BLO match_nolit_dst_ok_encodeSnappyBlockAsm12B + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +match_nolit_dst_ok_encodeSnappyBlockAsm12B: + MOVD $0x000000cf1bbcdcbb, R8 + MOVD R6, R7 + LSR $0x10, R6, R6 + MOVD R6, R5 + LSL $0x18, R7, R7 + MUL R8, R7, R7 + LSR $0x34, R7, R7 + LSL $0x18, R5, R5 + MUL R8, R5, R5 + LSR $0x34, R5, R5 + SUB $2, R2, R8 + MOVWU R8, R8 + ADD R5<<2, R0, R9 + MOVWU (R9), R5 + MOVW R8, (R0)(R7<<2) + MOVW R2, (R9) + MOVWU (R3)(R5), R16 + CMPW R6, R16 + BEQ match_nolit_loop_encodeSnappyBlockAsm12B + ADDW $1, R2, R2 + JMP search_loop_encodeSnappyBlockAsm12B + +emit_remainder_encodeSnappyBlockAsm12B: + MOVD src_len+32(FP), R0 + MOVWU 20(RSP), R16 + SUBW R16, R0, R0 + ADD R0, R1, R0 + ADD $3, R0, R0 + MOVD 8(RSP), R16 + CMP R16, R0 + BLO emit_remainder_ok_encodeSnappyBlockAsm12B + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +emit_remainder_ok_encodeSnappyBlockAsm12B: + MOVD src_len+32(FP), R0 + MOVWU 20(RSP), R2 + CMPW R0, R2 + BEQ emit_literal_done_emit_remainder_encodeSnappyBlockAsm12B + MOVWU R0, R5 + MOVW R0, 20(RSP) + ADD R2, R3, R0 + SUBW R2, R5, R5 + SUB $1, R5, R2 + MOVWU R2, R2 + CMPW $0x3c, R2 + BLO one_byte_emit_remainder_encodeSnappyBlockAsm12B + CMPW $0x00000100, R2 + BLO two_bytes_emit_remainder_encodeSnappyBlockAsm12B + BLO three_bytes_emit_remainder_encodeSnappyBlockAsm12B + +three_bytes_emit_remainder_encodeSnappyBlockAsm12B: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R2, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_emit_remainder_encodeSnappyBlockAsm12B + +two_bytes_emit_remainder_encodeSnappyBlockAsm12B: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R2, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R2 + BLO memmove_emit_remainder_encodeSnappyBlockAsm12B + JMP memmove_long_emit_remainder_encodeSnappyBlockAsm12B + +one_byte_emit_remainder_encodeSnappyBlockAsm12B: + LSLW $0x02, R2, R16 + BFI $0, R16, $8, R2 + MOVB R2, (R1) + ADD $0x01, R1, R1 + +memmove_emit_remainder_encodeSnappyBlockAsm12B: + ADD R5, R1, R2 + MOVWU R5, R3 + + // genMemMoveShort + CMP $0x03, R3 + BLO emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm12B_memmove_move_1or2 + BEQ emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm12B_memmove_move_3 + CMP $0x08, R3 + BLO emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm12B_memmove_move_4through7 + CMP $0x10, R3 + BLS emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm12B_memmove_move_8through16 + CMP $0x20, R3 + BLS emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm12B_memmove_move_17through32 + JMP emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm12B_memmove_move_33through64 + +emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm12B_memmove_move_1or2: + MOVBU (R0), R16 + BFI $0, R16, $8, R5 + ADD R3, R0, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R0 + MOVB R5, (R1) + ADD R3, R1, R15 + MOVB R0, -1(R15) + JMP memmove_end_copy_emit_remainder_encodeSnappyBlockAsm12B + +emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm12B_memmove_move_3: + MOVHU (R0), R16 + BFI $0, R16, $16, R5 + MOVBU 2(R0), R16 + BFI $0, R16, $8, R0 + MOVH R5, (R1) + MOVB R0, 2(R1) + JMP memmove_end_copy_emit_remainder_encodeSnappyBlockAsm12B + +emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm12B_memmove_move_4through7: + MOVWU (R0), R5 + ADD R3, R0, R15 + MOVWU -4(R15), R0 + MOVW R5, (R1) + ADD R3, R1, R15 + MOVW R0, -4(R15) + JMP memmove_end_copy_emit_remainder_encodeSnappyBlockAsm12B + +emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm12B_memmove_move_8through16: + MOVD (R0), R5 + ADD R3, R0, R15 + MOVD -8(R15), R0 + MOVD R5, (R1) + ADD R3, R1, R15 + MOVD R0, -8(R15) + JMP memmove_end_copy_emit_remainder_encodeSnappyBlockAsm12B + +emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm12B_memmove_move_17through32: + FMOVQ (R0), F0 + ADD R3, R0, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R3, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_emit_remainder_encodeSnappyBlockAsm12B + +emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm12B_memmove_move_33through64: + FMOVQ (R0), F0 + FMOVQ 16(R0), F1 + ADD R3, R0, R15 + FMOVQ -32(R15), F2 + ADD R3, R0, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R3, R1, R15 + FMOVQ F2, -32(R15) + ADD R3, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_emit_remainder_encodeSnappyBlockAsm12B: + MOVD R2, R1 + JMP emit_literal_done_emit_remainder_encodeSnappyBlockAsm12B + +memmove_long_emit_remainder_encodeSnappyBlockAsm12B: + ADD R5, R1, R2 + MOVWU R5, R3 + + // genMemMoveLong + MOVD R0, R5 + MOVD R1, R6 + MOVD R3, R7 + +emit_lit_memmove_long_emit_remainder_encodeSnappyBlockAsm12Blarge_big_loop_back: + FMOVQ (R5), F0 + FMOVQ 16(R5), F1 + FMOVQ F0, (R6) + FMOVQ F1, 16(R6) + ADD $0x20, R5, R5 + ADD $0x20, R6, R6 + SUB $0x20, R7, R7 + CMP $0x20, R7 + BHS emit_lit_memmove_long_emit_remainder_encodeSnappyBlockAsm12Blarge_big_loop_back + ADD R3, R0, R15 + FMOVQ -32(R15), F0 + ADD R3, R0, R15 + FMOVQ -16(R15), F1 + ADD R3, R1, R15 + FMOVQ F0, -32(R15) + ADD R3, R1, R15 + FMOVQ F1, -16(R15) + MOVD R2, R1 + +emit_literal_done_emit_remainder_encodeSnappyBlockAsm12B: + MOVD dst_base+0(FP), R0 + SUB R0, R1, R1 + MOVD R1, ret+56(FP) + RET + +// func encodeSnappyBlockAsm10B(dst []byte, src []byte, tmp *[4096]byte) int +// Requires: BMI, SSE2 +TEXT ·encodeSnappyBlockAsm10B(SB), $24-64 + MOVD tmp+48(FP), R0 + MOVD dst_base+0(FP), R1 + MOVD $0x00000020, R2 + MOVD R0, R3 + VEOR V0.B16, V0.B16, V0.B16 + +zero_loop_encodeSnappyBlockAsm10B: + FMOVQ F0, (R3) + FMOVQ F0, 16(R3) + FMOVQ F0, 32(R3) + FMOVQ F0, 48(R3) + FMOVQ F0, 64(R3) + FMOVQ F0, 80(R3) + FMOVQ F0, 96(R3) + FMOVQ F0, 112(R3) + ADD $0x80, R3, R3 + SUBS $1, R2, R2 + BNE zero_loop_encodeSnappyBlockAsm10B + MOVD $0x00000000, R16 + MOVW R16, 20(RSP) + MOVD src_len+32(FP), R2 + SUB $9, R2, R3 + SUB $8, R2, R5 + MOVW R5, 16(RSP) + LSR $0x05, R2, R2 + SUBW R2, R3, R3 + ADD R3, R1, R3 + MOVD R3, 8(RSP) + MOVD $0x00000001, R2 + MOVW R2, 24(RSP) + MOVD src_base+24(FP), R3 + +search_loop_encodeSnappyBlockAsm10B: + MOVWU R2, R5 + MOVWU 20(RSP), R16 + SUBW R16, R5, R5 + LSRW $0x05, R5, R5 + ADD R5, R2, R5 + ADD $4, R5, R5 + MOVWU R5, R5 + MOVWU 16(RSP), R16 + CMPW R16, R5 + BHS emit_remainder_encodeSnappyBlockAsm10B + MOVD (R3)(R2), R6 + MOVW R5, 28(RSP) + MOVD $0x9e3779b1, R8 + MOVD R6, R9 + MOVD R6, R10 + LSR $0x08, R10, R10 + LSL $0x20, R9, R9 + MUL R8, R9, R9 + LSR $0x36, R9, R9 + LSL $0x20, R10, R10 + MUL R8, R10, R10 + LSR $0x36, R10, R10 + MOVWU (R0)(R9<<2), R5 + MOVWU (R0)(R10<<2), R7 + MOVW R2, (R0)(R9<<2) + ADD $1, R2, R9 + MOVWU R9, R9 + MOVW R9, (R0)(R10<<2) + MOVD R6, R9 + LSR $0x10, R9, R9 + LSL $0x20, R9, R9 + MUL R8, R9, R9 + LSR $0x36, R9, R9 + MOVWU R2, R8 + MOVWU 24(RSP), R16 + SUBW R16, R8, R8 + ADD R8, R3, R15 + MOVWU 1(R15), R10 + MOVD R6, R8 + LSR $0x08, R8, R8 + CMPW R10, R8 + BNE no_repeat_found_encodeSnappyBlockAsm10B + ADD $1, R2, R6 + MOVWU R6, R6 + MOVWU 20(RSP), R5 + MOVWU R6, R7 + MOVWU 24(RSP), R16 + SUBSW R16, R7, R7 + BEQ repeat_extend_back_end_encodeSnappyBlockAsm10B + +repeat_extend_back_loop_encodeSnappyBlockAsm10B: + CMPW R5, R6 + BLS repeat_extend_back_end_encodeSnappyBlockAsm10B + ADD R7, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R8 + ADD R6, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R9 + AND $0xff, R9, R16 + AND $0xff, R8, R15 + CMP R16, R15 + BNE repeat_extend_back_end_encodeSnappyBlockAsm10B + SUB $1, R6, R6 + MOVWU R6, R6 + SUBSW $1, R7, R7 + BNE repeat_extend_back_loop_encodeSnappyBlockAsm10B + +repeat_extend_back_end_encodeSnappyBlockAsm10B: + MOVWU R6, R5 + MOVWU 20(RSP), R16 + SUBW R16, R5, R5 + ADD R5, R1, R5 + ADD $3, R5, R5 + MOVD 8(RSP), R16 + CMP R16, R5 + BLO repeat_dst_size_check_encodeSnappyBlockAsm10B + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +repeat_dst_size_check_encodeSnappyBlockAsm10B: + MOVWU 20(RSP), R5 + CMPW R6, R5 + BEQ emit_literal_done_repeat_emit_encodeSnappyBlockAsm10B + MOVWU R6, R7 + MOVW R6, 20(RSP) + ADD R5, R3, R8 + SUBW R5, R7, R7 + SUB $1, R7, R5 + MOVWU R5, R5 + CMPW $0x3c, R5 + BLO one_byte_repeat_emit_encodeSnappyBlockAsm10B + CMPW $0x00000100, R5 + BLO two_bytes_repeat_emit_encodeSnappyBlockAsm10B + BLO three_bytes_repeat_emit_encodeSnappyBlockAsm10B + +three_bytes_repeat_emit_encodeSnappyBlockAsm10B: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R5, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_repeat_emit_encodeSnappyBlockAsm10B + +two_bytes_repeat_emit_encodeSnappyBlockAsm10B: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R5, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R5 + BLO memmove_repeat_emit_encodeSnappyBlockAsm10B + JMP memmove_long_repeat_emit_encodeSnappyBlockAsm10B + +one_byte_repeat_emit_encodeSnappyBlockAsm10B: + LSLW $0x02, R5, R16 + BFI $0, R16, $8, R5 + MOVB R5, (R1) + ADD $0x01, R1, R1 + +memmove_repeat_emit_encodeSnappyBlockAsm10B: + ADD R7, R1, R5 + + // genMemMoveShort + CMP $0x08, R7 + BLS emit_lit_memmove_repeat_emit_encodeSnappyBlockAsm10B_memmove_move_8 + CMP $0x10, R7 + BLS emit_lit_memmove_repeat_emit_encodeSnappyBlockAsm10B_memmove_move_8through16 + CMP $0x20, R7 + BLS emit_lit_memmove_repeat_emit_encodeSnappyBlockAsm10B_memmove_move_17through32 + JMP emit_lit_memmove_repeat_emit_encodeSnappyBlockAsm10B_memmove_move_33through64 + +emit_lit_memmove_repeat_emit_encodeSnappyBlockAsm10B_memmove_move_8: + MOVD (R8), R9 + MOVD R9, (R1) + JMP memmove_end_copy_repeat_emit_encodeSnappyBlockAsm10B + +emit_lit_memmove_repeat_emit_encodeSnappyBlockAsm10B_memmove_move_8through16: + MOVD (R8), R9 + ADD R7, R8, R15 + MOVD -8(R15), R8 + MOVD R9, (R1) + ADD R7, R1, R15 + MOVD R8, -8(R15) + JMP memmove_end_copy_repeat_emit_encodeSnappyBlockAsm10B + +emit_lit_memmove_repeat_emit_encodeSnappyBlockAsm10B_memmove_move_17through32: + FMOVQ (R8), F0 + ADD R7, R8, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R7, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_repeat_emit_encodeSnappyBlockAsm10B + +emit_lit_memmove_repeat_emit_encodeSnappyBlockAsm10B_memmove_move_33through64: + FMOVQ (R8), F0 + FMOVQ 16(R8), F1 + ADD R7, R8, R15 + FMOVQ -32(R15), F2 + ADD R7, R8, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R7, R1, R15 + FMOVQ F2, -32(R15) + ADD R7, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_repeat_emit_encodeSnappyBlockAsm10B: + MOVD R5, R1 + JMP emit_literal_done_repeat_emit_encodeSnappyBlockAsm10B + +memmove_long_repeat_emit_encodeSnappyBlockAsm10B: + ADD R7, R1, R5 + + // genMemMoveLong + MOVD R8, R9 + MOVD R1, R10 + MOVD R7, R11 + +emit_lit_memmove_long_repeat_emit_encodeSnappyBlockAsm10Blarge_big_loop_back: + FMOVQ (R9), F0 + FMOVQ 16(R9), F1 + FMOVQ F0, (R10) + FMOVQ F1, 16(R10) + ADD $0x20, R9, R9 + ADD $0x20, R10, R10 + SUB $0x20, R11, R11 + CMP $0x20, R11 + BHS emit_lit_memmove_long_repeat_emit_encodeSnappyBlockAsm10Blarge_big_loop_back + ADD R7, R8, R15 + FMOVQ -32(R15), F0 + ADD R7, R8, R15 + FMOVQ -16(R15), F1 + ADD R7, R1, R15 + FMOVQ F0, -32(R15) + ADD R7, R1, R15 + FMOVQ F1, -16(R15) + MOVD R5, R1 + +emit_literal_done_repeat_emit_encodeSnappyBlockAsm10B: + ADDW $0x05, R2, R2 + MOVWU R2, R5 + MOVWU 24(RSP), R16 + SUBW R16, R5, R5 + MOVD src_len+32(FP), R7 + SUBW R2, R7, R7 + ADD R2, R3, R8 + ADD R5, R3, R5 + + // matchLen + MOVD $0, R10 + +matchlen_loopback_16_repeat_extend_encodeSnappyBlockAsm10B: + CMPW $0x10, R7 + BLO matchlen_match8_repeat_extend_encodeSnappyBlockAsm10B + MOVD (R8)(R10), R9 + ADD R10, R8, R15 + MOVD 8(R15), R11 + MOVD (R5)(R10), R16 + EOR R16, R9, R9 + TST R9, R9 + BNE matchlen_bsf_8_repeat_extend_encodeSnappyBlockAsm10B + ADD R10, R5, R15 + MOVD 8(R15), R16 + EOR R16, R11, R11 + TST R11, R11 + BNE matchlen_bsf_16repeat_extend_encodeSnappyBlockAsm10B + SUB $16, R7, R7 + MOVWU R7, R7 + ADD $16, R10, R10 + MOVWU R10, R10 + JMP matchlen_loopback_16_repeat_extend_encodeSnappyBlockAsm10B + +matchlen_bsf_16repeat_extend_encodeSnappyBlockAsm10B: + RBIT R11, R11 + CLZ R11, R11 + ASR $0x03, R11, R11 + ADD R11, R10, R10 + ADD $8, R10, R10 + MOVWU R10, R10 + JMP repeat_extend_forward_end_encodeSnappyBlockAsm10B + +matchlen_match8_repeat_extend_encodeSnappyBlockAsm10B: + CMPW $0x08, R7 + BLO matchlen_match4_repeat_extend_encodeSnappyBlockAsm10B + MOVD (R8)(R10), R9 + MOVD (R5)(R10), R16 + EOR R16, R9, R9 + TST R9, R9 + BNE matchlen_bsf_8_repeat_extend_encodeSnappyBlockAsm10B + SUB $8, R7, R7 + MOVWU R7, R7 + ADD $8, R10, R10 + MOVWU R10, R10 + JMP matchlen_match4_repeat_extend_encodeSnappyBlockAsm10B + +matchlen_bsf_8_repeat_extend_encodeSnappyBlockAsm10B: + RBIT R9, R9 + CLZ R9, R9 + ASR $0x03, R9, R9 + ADD R9, R10, R10 + MOVWU R10, R10 + JMP repeat_extend_forward_end_encodeSnappyBlockAsm10B + +matchlen_match4_repeat_extend_encodeSnappyBlockAsm10B: + CMPW $0x04, R7 + BLO matchlen_match2_repeat_extend_encodeSnappyBlockAsm10B + MOVWU (R8)(R10), R9 + MOVWU (R5)(R10), R16 + CMPW R9, R16 + BNE matchlen_match2_repeat_extend_encodeSnappyBlockAsm10B + SUB $4, R7, R7 + MOVWU R7, R7 + ADD $4, R10, R10 + MOVWU R10, R10 + +matchlen_match2_repeat_extend_encodeSnappyBlockAsm10B: + CMPW $0x01, R7 + BEQ matchlen_match1_repeat_extend_encodeSnappyBlockAsm10B + BLO repeat_extend_forward_end_encodeSnappyBlockAsm10B + MOVHU (R8)(R10), R16 + BFI $0, R16, $16, R9 + ADD R10, R5, R15 + MOVHU (R15), R15 + AND $0xffff, R9, R16 + CMP R16, R15 + BNE matchlen_match1_repeat_extend_encodeSnappyBlockAsm10B + ADD $2, R10, R10 + MOVWU R10, R10 + SUBSW $0x02, R7, R7 + BEQ repeat_extend_forward_end_encodeSnappyBlockAsm10B + +matchlen_match1_repeat_extend_encodeSnappyBlockAsm10B: + MOVBU (R8)(R10), R16 + BFI $0, R16, $8, R9 + ADD R10, R5, R15 + MOVBU (R15), R15 + AND $0xff, R9, R16 + CMP R16, R15 + BNE repeat_extend_forward_end_encodeSnappyBlockAsm10B + ADD $1, R10, R10 + MOVWU R10, R10 + +repeat_extend_forward_end_encodeSnappyBlockAsm10B: + ADDW R10, R2, R2 + MOVWU R2, R5 + SUBW R6, R5, R5 + MOVWU 24(RSP), R6 + + // emitCopy +two_byte_offset_repeat_as_copy_encodeSnappyBlockAsm10B: + CMPW $0x40, R5 + BLS two_byte_offset_short_repeat_as_copy_encodeSnappyBlockAsm10B + MOVD $0xee, R16 + MOVB R16, (R1) + MOVH R6, 1(R1) + SUB $60, R5, R5 + MOVWU R5, R5 + ADD $0x03, R1, R1 + JMP two_byte_offset_repeat_as_copy_encodeSnappyBlockAsm10B + +two_byte_offset_short_repeat_as_copy_encodeSnappyBlockAsm10B: + MOVWU R5, R7 + LSLW $0x02, R7, R7 + CMPW $0x0c, R5 + BHS emit_copy_three_repeat_as_copy_encodeSnappyBlockAsm10B + CMPW $0x00000800, R6 + BHS emit_copy_three_repeat_as_copy_encodeSnappyBlockAsm10B + SUB $15, R7, R7 + MOVWU R7, R7 + MOVB R6, 1(R1) + LSRW $0x08, R6, R6 + LSLW $0x05, R6, R6 + ORRW R6, R7, R7 + MOVB R7, (R1) + ADD $0x02, R1, R1 + JMP repeat_end_emit_encodeSnappyBlockAsm10B + +emit_copy_three_repeat_as_copy_encodeSnappyBlockAsm10B: + SUB $2, R7, R7 + MOVWU R7, R7 + MOVB R7, (R1) + MOVH R6, 1(R1) + ADD $0x03, R1, R1 + +repeat_end_emit_encodeSnappyBlockAsm10B: + MOVW R2, 20(RSP) + JMP search_loop_encodeSnappyBlockAsm10B + +no_repeat_found_encodeSnappyBlockAsm10B: + MOVWU (R3)(R5), R16 + CMPW R6, R16 + BEQ candidate_match_encodeSnappyBlockAsm10B + LSR $0x08, R6, R6 + MOVWU (R0)(R9<<2), R5 + ADD $2, R2, R8 + MOVWU R8, R8 + MOVWU (R3)(R7), R16 + CMPW R6, R16 + BEQ candidate2_match_encodeSnappyBlockAsm10B + MOVW R8, (R0)(R9<<2) + LSR $0x08, R6, R6 + MOVWU (R3)(R5), R16 + CMPW R6, R16 + BEQ candidate3_match_encodeSnappyBlockAsm10B + MOVWU 28(RSP), R2 + JMP search_loop_encodeSnappyBlockAsm10B + +candidate3_match_encodeSnappyBlockAsm10B: + ADDW $0x02, R2, R2 + JMP candidate_match_encodeSnappyBlockAsm10B + +candidate2_match_encodeSnappyBlockAsm10B: + MOVW R8, (R0)(R9<<2) + ADDW $1, R2, R2 + MOVWU R7, R5 + +candidate_match_encodeSnappyBlockAsm10B: + MOVWU 20(RSP), R6 + TSTW R5, R5 + BEQ match_extend_back_end_encodeSnappyBlockAsm10B + +match_extend_back_loop_encodeSnappyBlockAsm10B: + CMPW R6, R2 + BLS match_extend_back_end_encodeSnappyBlockAsm10B + ADD R5, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R7 + ADD R2, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R8 + AND $0xff, R8, R16 + AND $0xff, R7, R15 + CMP R16, R15 + BNE match_extend_back_end_encodeSnappyBlockAsm10B + SUB $1, R2, R2 + MOVWU R2, R2 + SUBSW $1, R5, R5 + BEQ match_extend_back_end_encodeSnappyBlockAsm10B + JMP match_extend_back_loop_encodeSnappyBlockAsm10B + +match_extend_back_end_encodeSnappyBlockAsm10B: + MOVWU R2, R6 + MOVWU 20(RSP), R16 + SUBW R16, R6, R6 + ADD R6, R1, R6 + ADD $3, R6, R6 + MOVD 8(RSP), R16 + CMP R16, R6 + BLO match_dst_size_check_encodeSnappyBlockAsm10B + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +match_dst_size_check_encodeSnappyBlockAsm10B: + MOVWU R2, R6 + MOVWU 20(RSP), R7 + CMPW R6, R7 + BEQ emit_literal_done_match_emit_encodeSnappyBlockAsm10B + MOVWU R6, R8 + MOVW R6, 20(RSP) + ADD R7, R3, R6 + SUBW R7, R8, R8 + SUB $1, R8, R7 + MOVWU R7, R7 + CMPW $0x3c, R7 + BLO one_byte_match_emit_encodeSnappyBlockAsm10B + CMPW $0x00000100, R7 + BLO two_bytes_match_emit_encodeSnappyBlockAsm10B + BLO three_bytes_match_emit_encodeSnappyBlockAsm10B + +three_bytes_match_emit_encodeSnappyBlockAsm10B: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R7, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_match_emit_encodeSnappyBlockAsm10B + +two_bytes_match_emit_encodeSnappyBlockAsm10B: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R7, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R7 + BLO memmove_match_emit_encodeSnappyBlockAsm10B + JMP memmove_long_match_emit_encodeSnappyBlockAsm10B + +one_byte_match_emit_encodeSnappyBlockAsm10B: + LSLW $0x02, R7, R16 + BFI $0, R16, $8, R7 + MOVB R7, (R1) + ADD $0x01, R1, R1 + +memmove_match_emit_encodeSnappyBlockAsm10B: + ADD R8, R1, R7 + + // genMemMoveShort + CMP $0x08, R8 + BLS emit_lit_memmove_match_emit_encodeSnappyBlockAsm10B_memmove_move_8 + CMP $0x10, R8 + BLS emit_lit_memmove_match_emit_encodeSnappyBlockAsm10B_memmove_move_8through16 + CMP $0x20, R8 + BLS emit_lit_memmove_match_emit_encodeSnappyBlockAsm10B_memmove_move_17through32 + JMP emit_lit_memmove_match_emit_encodeSnappyBlockAsm10B_memmove_move_33through64 + +emit_lit_memmove_match_emit_encodeSnappyBlockAsm10B_memmove_move_8: + MOVD (R6), R9 + MOVD R9, (R1) + JMP memmove_end_copy_match_emit_encodeSnappyBlockAsm10B + +emit_lit_memmove_match_emit_encodeSnappyBlockAsm10B_memmove_move_8through16: + MOVD (R6), R9 + ADD R8, R6, R15 + MOVD -8(R15), R6 + MOVD R9, (R1) + ADD R8, R1, R15 + MOVD R6, -8(R15) + JMP memmove_end_copy_match_emit_encodeSnappyBlockAsm10B + +emit_lit_memmove_match_emit_encodeSnappyBlockAsm10B_memmove_move_17through32: + FMOVQ (R6), F0 + ADD R8, R6, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_match_emit_encodeSnappyBlockAsm10B + +emit_lit_memmove_match_emit_encodeSnappyBlockAsm10B_memmove_move_33through64: + FMOVQ (R6), F0 + FMOVQ 16(R6), F1 + ADD R8, R6, R15 + FMOVQ -32(R15), F2 + ADD R8, R6, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R8, R1, R15 + FMOVQ F2, -32(R15) + ADD R8, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_match_emit_encodeSnappyBlockAsm10B: + MOVD R7, R1 + JMP emit_literal_done_match_emit_encodeSnappyBlockAsm10B + +memmove_long_match_emit_encodeSnappyBlockAsm10B: + ADD R8, R1, R7 + + // genMemMoveLong + MOVD R6, R9 + MOVD R1, R10 + MOVD R8, R11 + +emit_lit_memmove_long_match_emit_encodeSnappyBlockAsm10Blarge_big_loop_back: + FMOVQ (R9), F0 + FMOVQ 16(R9), F1 + FMOVQ F0, (R10) + FMOVQ F1, 16(R10) + ADD $0x20, R9, R9 + ADD $0x20, R10, R10 + SUB $0x20, R11, R11 + CMP $0x20, R11 + BHS emit_lit_memmove_long_match_emit_encodeSnappyBlockAsm10Blarge_big_loop_back + ADD R8, R6, R15 + FMOVQ -32(R15), F0 + ADD R8, R6, R15 + FMOVQ -16(R15), F1 + ADD R8, R1, R15 + FMOVQ F0, -32(R15) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + MOVD R7, R1 + +emit_literal_done_match_emit_encodeSnappyBlockAsm10B: +match_nolit_loop_encodeSnappyBlockAsm10B: + MOVWU R2, R6 + SUBW R5, R6, R6 + MOVW R6, 24(RSP) + ADDW $0x04, R2, R2 + ADDW $0x04, R5, R5 + MOVD src_len+32(FP), R6 + SUBW R2, R6, R6 + ADD R2, R3, R7 + ADD R5, R3, R5 + + // matchLen + MOVD $0, R9 + +matchlen_loopback_16_match_nolit_encodeSnappyBlockAsm10B: + CMPW $0x10, R6 + BLO matchlen_match8_match_nolit_encodeSnappyBlockAsm10B + MOVD (R7)(R9), R8 + ADD R9, R7, R15 + MOVD 8(R15), R10 + MOVD (R5)(R9), R16 + EOR R16, R8, R8 + TST R8, R8 + BNE matchlen_bsf_8_match_nolit_encodeSnappyBlockAsm10B + ADD R9, R5, R15 + MOVD 8(R15), R16 + EOR R16, R10, R10 + TST R10, R10 + BNE matchlen_bsf_16match_nolit_encodeSnappyBlockAsm10B + SUB $16, R6, R6 + MOVWU R6, R6 + ADD $16, R9, R9 + MOVWU R9, R9 + JMP matchlen_loopback_16_match_nolit_encodeSnappyBlockAsm10B + +matchlen_bsf_16match_nolit_encodeSnappyBlockAsm10B: + RBIT R10, R10 + CLZ R10, R10 + ASR $0x03, R10, R10 + ADD R10, R9, R9 + ADD $8, R9, R9 + MOVWU R9, R9 + JMP match_nolit_end_encodeSnappyBlockAsm10B + +matchlen_match8_match_nolit_encodeSnappyBlockAsm10B: + CMPW $0x08, R6 + BLO matchlen_match4_match_nolit_encodeSnappyBlockAsm10B + MOVD (R7)(R9), R8 + MOVD (R5)(R9), R16 + EOR R16, R8, R8 + TST R8, R8 + BNE matchlen_bsf_8_match_nolit_encodeSnappyBlockAsm10B + SUB $8, R6, R6 + MOVWU R6, R6 + ADD $8, R9, R9 + MOVWU R9, R9 + JMP matchlen_match4_match_nolit_encodeSnappyBlockAsm10B + +matchlen_bsf_8_match_nolit_encodeSnappyBlockAsm10B: + RBIT R8, R8 + CLZ R8, R8 + ASR $0x03, R8, R8 + ADD R8, R9, R9 + MOVWU R9, R9 + JMP match_nolit_end_encodeSnappyBlockAsm10B + +matchlen_match4_match_nolit_encodeSnappyBlockAsm10B: + CMPW $0x04, R6 + BLO matchlen_match2_match_nolit_encodeSnappyBlockAsm10B + MOVWU (R7)(R9), R8 + MOVWU (R5)(R9), R16 + CMPW R8, R16 + BNE matchlen_match2_match_nolit_encodeSnappyBlockAsm10B + SUB $4, R6, R6 + MOVWU R6, R6 + ADD $4, R9, R9 + MOVWU R9, R9 + +matchlen_match2_match_nolit_encodeSnappyBlockAsm10B: + CMPW $0x01, R6 + BEQ matchlen_match1_match_nolit_encodeSnappyBlockAsm10B + BLO match_nolit_end_encodeSnappyBlockAsm10B + MOVHU (R7)(R9), R16 + BFI $0, R16, $16, R8 + ADD R9, R5, R15 + MOVHU (R15), R15 + AND $0xffff, R8, R16 + CMP R16, R15 + BNE matchlen_match1_match_nolit_encodeSnappyBlockAsm10B + ADD $2, R9, R9 + MOVWU R9, R9 + SUBSW $0x02, R6, R6 + BEQ match_nolit_end_encodeSnappyBlockAsm10B + +matchlen_match1_match_nolit_encodeSnappyBlockAsm10B: + MOVBU (R7)(R9), R16 + BFI $0, R16, $8, R8 + ADD R9, R5, R15 + MOVBU (R15), R15 + AND $0xff, R8, R16 + CMP R16, R15 + BNE match_nolit_end_encodeSnappyBlockAsm10B + ADD $1, R9, R9 + MOVWU R9, R9 + +match_nolit_end_encodeSnappyBlockAsm10B: + ADDW R9, R2, R2 + MOVWU 24(RSP), R5 + ADDW $0x04, R9, R9 + MOVW R2, 20(RSP) + + // emitCopy +two_byte_offset_match_nolit_encodeSnappyBlockAsm10B: + CMPW $0x40, R9 + BLS two_byte_offset_short_match_nolit_encodeSnappyBlockAsm10B + MOVD $0xee, R16 + MOVB R16, (R1) + MOVH R5, 1(R1) + SUB $60, R9, R9 + MOVWU R9, R9 + ADD $0x03, R1, R1 + JMP two_byte_offset_match_nolit_encodeSnappyBlockAsm10B + +two_byte_offset_short_match_nolit_encodeSnappyBlockAsm10B: + MOVWU R9, R6 + LSLW $0x02, R6, R6 + CMPW $0x0c, R9 + BHS emit_copy_three_match_nolit_encodeSnappyBlockAsm10B + CMPW $0x00000800, R5 + BHS emit_copy_three_match_nolit_encodeSnappyBlockAsm10B + SUB $15, R6, R6 + MOVWU R6, R6 + MOVB R5, 1(R1) + LSRW $0x08, R5, R5 + LSLW $0x05, R5, R5 + ORRW R5, R6, R6 + MOVB R6, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeSnappyBlockAsm10B + +emit_copy_three_match_nolit_encodeSnappyBlockAsm10B: + SUB $2, R6, R6 + MOVWU R6, R6 + MOVB R6, (R1) + MOVH R5, 1(R1) + ADD $0x03, R1, R1 + +match_nolit_emitcopy_end_encodeSnappyBlockAsm10B: + MOVWU 16(RSP), R16 + CMPW R16, R2 + BHS emit_remainder_encodeSnappyBlockAsm10B + ADD R2, R3, R15 + MOVD -2(R15), R6 + MOVD 8(RSP), R16 + CMP R16, R1 + BLO match_nolit_dst_ok_encodeSnappyBlockAsm10B + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +match_nolit_dst_ok_encodeSnappyBlockAsm10B: + MOVD $0x9e3779b1, R8 + MOVD R6, R7 + LSR $0x10, R6, R6 + MOVD R6, R5 + LSL $0x20, R7, R7 + MUL R8, R7, R7 + LSR $0x36, R7, R7 + LSL $0x20, R5, R5 + MUL R8, R5, R5 + LSR $0x36, R5, R5 + SUB $2, R2, R8 + MOVWU R8, R8 + ADD R5<<2, R0, R9 + MOVWU (R9), R5 + MOVW R8, (R0)(R7<<2) + MOVW R2, (R9) + MOVWU (R3)(R5), R16 + CMPW R6, R16 + BEQ match_nolit_loop_encodeSnappyBlockAsm10B + ADDW $1, R2, R2 + JMP search_loop_encodeSnappyBlockAsm10B + +emit_remainder_encodeSnappyBlockAsm10B: + MOVD src_len+32(FP), R0 + MOVWU 20(RSP), R16 + SUBW R16, R0, R0 + ADD R0, R1, R0 + ADD $3, R0, R0 + MOVD 8(RSP), R16 + CMP R16, R0 + BLO emit_remainder_ok_encodeSnappyBlockAsm10B + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +emit_remainder_ok_encodeSnappyBlockAsm10B: + MOVD src_len+32(FP), R0 + MOVWU 20(RSP), R2 + CMPW R0, R2 + BEQ emit_literal_done_emit_remainder_encodeSnappyBlockAsm10B + MOVWU R0, R5 + MOVW R0, 20(RSP) + ADD R2, R3, R0 + SUBW R2, R5, R5 + SUB $1, R5, R2 + MOVWU R2, R2 + CMPW $0x3c, R2 + BLO one_byte_emit_remainder_encodeSnappyBlockAsm10B + CMPW $0x00000100, R2 + BLO two_bytes_emit_remainder_encodeSnappyBlockAsm10B + BLO three_bytes_emit_remainder_encodeSnappyBlockAsm10B + +three_bytes_emit_remainder_encodeSnappyBlockAsm10B: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R2, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_emit_remainder_encodeSnappyBlockAsm10B + +two_bytes_emit_remainder_encodeSnappyBlockAsm10B: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R2, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R2 + BLO memmove_emit_remainder_encodeSnappyBlockAsm10B + JMP memmove_long_emit_remainder_encodeSnappyBlockAsm10B + +one_byte_emit_remainder_encodeSnappyBlockAsm10B: + LSLW $0x02, R2, R16 + BFI $0, R16, $8, R2 + MOVB R2, (R1) + ADD $0x01, R1, R1 + +memmove_emit_remainder_encodeSnappyBlockAsm10B: + ADD R5, R1, R2 + MOVWU R5, R3 + + // genMemMoveShort + CMP $0x03, R3 + BLO emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm10B_memmove_move_1or2 + BEQ emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm10B_memmove_move_3 + CMP $0x08, R3 + BLO emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm10B_memmove_move_4through7 + CMP $0x10, R3 + BLS emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm10B_memmove_move_8through16 + CMP $0x20, R3 + BLS emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm10B_memmove_move_17through32 + JMP emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm10B_memmove_move_33through64 + +emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm10B_memmove_move_1or2: + MOVBU (R0), R16 + BFI $0, R16, $8, R5 + ADD R3, R0, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R0 + MOVB R5, (R1) + ADD R3, R1, R15 + MOVB R0, -1(R15) + JMP memmove_end_copy_emit_remainder_encodeSnappyBlockAsm10B + +emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm10B_memmove_move_3: + MOVHU (R0), R16 + BFI $0, R16, $16, R5 + MOVBU 2(R0), R16 + BFI $0, R16, $8, R0 + MOVH R5, (R1) + MOVB R0, 2(R1) + JMP memmove_end_copy_emit_remainder_encodeSnappyBlockAsm10B + +emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm10B_memmove_move_4through7: + MOVWU (R0), R5 + ADD R3, R0, R15 + MOVWU -4(R15), R0 + MOVW R5, (R1) + ADD R3, R1, R15 + MOVW R0, -4(R15) + JMP memmove_end_copy_emit_remainder_encodeSnappyBlockAsm10B + +emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm10B_memmove_move_8through16: + MOVD (R0), R5 + ADD R3, R0, R15 + MOVD -8(R15), R0 + MOVD R5, (R1) + ADD R3, R1, R15 + MOVD R0, -8(R15) + JMP memmove_end_copy_emit_remainder_encodeSnappyBlockAsm10B + +emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm10B_memmove_move_17through32: + FMOVQ (R0), F0 + ADD R3, R0, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R3, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_emit_remainder_encodeSnappyBlockAsm10B + +emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm10B_memmove_move_33through64: + FMOVQ (R0), F0 + FMOVQ 16(R0), F1 + ADD R3, R0, R15 + FMOVQ -32(R15), F2 + ADD R3, R0, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R3, R1, R15 + FMOVQ F2, -32(R15) + ADD R3, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_emit_remainder_encodeSnappyBlockAsm10B: + MOVD R2, R1 + JMP emit_literal_done_emit_remainder_encodeSnappyBlockAsm10B + +memmove_long_emit_remainder_encodeSnappyBlockAsm10B: + ADD R5, R1, R2 + MOVWU R5, R3 + + // genMemMoveLong + MOVD R0, R5 + MOVD R1, R6 + MOVD R3, R7 + +emit_lit_memmove_long_emit_remainder_encodeSnappyBlockAsm10Blarge_big_loop_back: + FMOVQ (R5), F0 + FMOVQ 16(R5), F1 + FMOVQ F0, (R6) + FMOVQ F1, 16(R6) + ADD $0x20, R5, R5 + ADD $0x20, R6, R6 + SUB $0x20, R7, R7 + CMP $0x20, R7 + BHS emit_lit_memmove_long_emit_remainder_encodeSnappyBlockAsm10Blarge_big_loop_back + ADD R3, R0, R15 + FMOVQ -32(R15), F0 + ADD R3, R0, R15 + FMOVQ -16(R15), F1 + ADD R3, R1, R15 + FMOVQ F0, -32(R15) + ADD R3, R1, R15 + FMOVQ F1, -16(R15) + MOVD R2, R1 + +emit_literal_done_emit_remainder_encodeSnappyBlockAsm10B: + MOVD dst_base+0(FP), R0 + SUB R0, R1, R1 + MOVD R1, ret+56(FP) + RET + +// func encodeSnappyBlockAsm8B(dst []byte, src []byte, tmp *[1024]byte) int +// Requires: BMI, SSE2 +TEXT ·encodeSnappyBlockAsm8B(SB), $24-64 + MOVD tmp+48(FP), R0 + MOVD dst_base+0(FP), R1 + MOVD $0x00000008, R2 + MOVD R0, R3 + VEOR V0.B16, V0.B16, V0.B16 + +zero_loop_encodeSnappyBlockAsm8B: + FMOVQ F0, (R3) + FMOVQ F0, 16(R3) + FMOVQ F0, 32(R3) + FMOVQ F0, 48(R3) + FMOVQ F0, 64(R3) + FMOVQ F0, 80(R3) + FMOVQ F0, 96(R3) + FMOVQ F0, 112(R3) + ADD $0x80, R3, R3 + SUBS $1, R2, R2 + BNE zero_loop_encodeSnappyBlockAsm8B + MOVD $0x00000000, R16 + MOVW R16, 20(RSP) + MOVD src_len+32(FP), R2 + SUB $9, R2, R3 + SUB $8, R2, R5 + MOVW R5, 16(RSP) + LSR $0x05, R2, R2 + SUBW R2, R3, R3 + ADD R3, R1, R3 + MOVD R3, 8(RSP) + MOVD $0x00000001, R2 + MOVW R2, 24(RSP) + MOVD src_base+24(FP), R3 + +search_loop_encodeSnappyBlockAsm8B: + MOVWU R2, R5 + MOVWU 20(RSP), R16 + SUBW R16, R5, R5 + LSRW $0x04, R5, R5 + ADD R5, R2, R5 + ADD $4, R5, R5 + MOVWU R5, R5 + MOVWU 16(RSP), R16 + CMPW R16, R5 + BHS emit_remainder_encodeSnappyBlockAsm8B + MOVD (R3)(R2), R6 + MOVW R5, 28(RSP) + MOVD $0x9e3779b1, R8 + MOVD R6, R9 + MOVD R6, R10 + LSR $0x08, R10, R10 + LSL $0x20, R9, R9 + MUL R8, R9, R9 + LSR $0x38, R9, R9 + LSL $0x20, R10, R10 + MUL R8, R10, R10 + LSR $0x38, R10, R10 + MOVWU (R0)(R9<<2), R5 + MOVWU (R0)(R10<<2), R7 + MOVW R2, (R0)(R9<<2) + ADD $1, R2, R9 + MOVWU R9, R9 + MOVW R9, (R0)(R10<<2) + MOVD R6, R9 + LSR $0x10, R9, R9 + LSL $0x20, R9, R9 + MUL R8, R9, R9 + LSR $0x38, R9, R9 + MOVWU R2, R8 + MOVWU 24(RSP), R16 + SUBW R16, R8, R8 + ADD R8, R3, R15 + MOVWU 1(R15), R10 + MOVD R6, R8 + LSR $0x08, R8, R8 + CMPW R10, R8 + BNE no_repeat_found_encodeSnappyBlockAsm8B + ADD $1, R2, R6 + MOVWU R6, R6 + MOVWU 20(RSP), R5 + MOVWU R6, R7 + MOVWU 24(RSP), R16 + SUBSW R16, R7, R7 + BEQ repeat_extend_back_end_encodeSnappyBlockAsm8B + +repeat_extend_back_loop_encodeSnappyBlockAsm8B: + CMPW R5, R6 + BLS repeat_extend_back_end_encodeSnappyBlockAsm8B + ADD R7, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R8 + ADD R6, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R9 + AND $0xff, R9, R16 + AND $0xff, R8, R15 + CMP R16, R15 + BNE repeat_extend_back_end_encodeSnappyBlockAsm8B + SUB $1, R6, R6 + MOVWU R6, R6 + SUBSW $1, R7, R7 + BNE repeat_extend_back_loop_encodeSnappyBlockAsm8B + +repeat_extend_back_end_encodeSnappyBlockAsm8B: + MOVWU R6, R5 + MOVWU 20(RSP), R16 + SUBW R16, R5, R5 + ADD R5, R1, R5 + ADD $3, R5, R5 + MOVD 8(RSP), R16 + CMP R16, R5 + BLO repeat_dst_size_check_encodeSnappyBlockAsm8B + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +repeat_dst_size_check_encodeSnappyBlockAsm8B: + MOVWU 20(RSP), R5 + CMPW R6, R5 + BEQ emit_literal_done_repeat_emit_encodeSnappyBlockAsm8B + MOVWU R6, R7 + MOVW R6, 20(RSP) + ADD R5, R3, R8 + SUBW R5, R7, R7 + SUB $1, R7, R5 + MOVWU R5, R5 + CMPW $0x3c, R5 + BLO one_byte_repeat_emit_encodeSnappyBlockAsm8B + CMPW $0x00000100, R5 + BLO two_bytes_repeat_emit_encodeSnappyBlockAsm8B + BLO three_bytes_repeat_emit_encodeSnappyBlockAsm8B + +three_bytes_repeat_emit_encodeSnappyBlockAsm8B: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R5, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_repeat_emit_encodeSnappyBlockAsm8B + +two_bytes_repeat_emit_encodeSnappyBlockAsm8B: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R5, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R5 + BLO memmove_repeat_emit_encodeSnappyBlockAsm8B + JMP memmove_long_repeat_emit_encodeSnappyBlockAsm8B + +one_byte_repeat_emit_encodeSnappyBlockAsm8B: + LSLW $0x02, R5, R16 + BFI $0, R16, $8, R5 + MOVB R5, (R1) + ADD $0x01, R1, R1 + +memmove_repeat_emit_encodeSnappyBlockAsm8B: + ADD R7, R1, R5 + + // genMemMoveShort + CMP $0x08, R7 + BLS emit_lit_memmove_repeat_emit_encodeSnappyBlockAsm8B_memmove_move_8 + CMP $0x10, R7 + BLS emit_lit_memmove_repeat_emit_encodeSnappyBlockAsm8B_memmove_move_8through16 + CMP $0x20, R7 + BLS emit_lit_memmove_repeat_emit_encodeSnappyBlockAsm8B_memmove_move_17through32 + JMP emit_lit_memmove_repeat_emit_encodeSnappyBlockAsm8B_memmove_move_33through64 + +emit_lit_memmove_repeat_emit_encodeSnappyBlockAsm8B_memmove_move_8: + MOVD (R8), R9 + MOVD R9, (R1) + JMP memmove_end_copy_repeat_emit_encodeSnappyBlockAsm8B + +emit_lit_memmove_repeat_emit_encodeSnappyBlockAsm8B_memmove_move_8through16: + MOVD (R8), R9 + ADD R7, R8, R15 + MOVD -8(R15), R8 + MOVD R9, (R1) + ADD R7, R1, R15 + MOVD R8, -8(R15) + JMP memmove_end_copy_repeat_emit_encodeSnappyBlockAsm8B + +emit_lit_memmove_repeat_emit_encodeSnappyBlockAsm8B_memmove_move_17through32: + FMOVQ (R8), F0 + ADD R7, R8, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R7, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_repeat_emit_encodeSnappyBlockAsm8B + +emit_lit_memmove_repeat_emit_encodeSnappyBlockAsm8B_memmove_move_33through64: + FMOVQ (R8), F0 + FMOVQ 16(R8), F1 + ADD R7, R8, R15 + FMOVQ -32(R15), F2 + ADD R7, R8, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R7, R1, R15 + FMOVQ F2, -32(R15) + ADD R7, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_repeat_emit_encodeSnappyBlockAsm8B: + MOVD R5, R1 + JMP emit_literal_done_repeat_emit_encodeSnappyBlockAsm8B + +memmove_long_repeat_emit_encodeSnappyBlockAsm8B: + ADD R7, R1, R5 + + // genMemMoveLong + MOVD R8, R9 + MOVD R1, R10 + MOVD R7, R11 + +emit_lit_memmove_long_repeat_emit_encodeSnappyBlockAsm8Blarge_big_loop_back: + FMOVQ (R9), F0 + FMOVQ 16(R9), F1 + FMOVQ F0, (R10) + FMOVQ F1, 16(R10) + ADD $0x20, R9, R9 + ADD $0x20, R10, R10 + SUB $0x20, R11, R11 + CMP $0x20, R11 + BHS emit_lit_memmove_long_repeat_emit_encodeSnappyBlockAsm8Blarge_big_loop_back + ADD R7, R8, R15 + FMOVQ -32(R15), F0 + ADD R7, R8, R15 + FMOVQ -16(R15), F1 + ADD R7, R1, R15 + FMOVQ F0, -32(R15) + ADD R7, R1, R15 + FMOVQ F1, -16(R15) + MOVD R5, R1 + +emit_literal_done_repeat_emit_encodeSnappyBlockAsm8B: + ADDW $0x05, R2, R2 + MOVWU R2, R5 + MOVWU 24(RSP), R16 + SUBW R16, R5, R5 + MOVD src_len+32(FP), R7 + SUBW R2, R7, R7 + ADD R2, R3, R8 + ADD R5, R3, R5 + + // matchLen + MOVD $0, R10 + +matchlen_loopback_16_repeat_extend_encodeSnappyBlockAsm8B: + CMPW $0x10, R7 + BLO matchlen_match8_repeat_extend_encodeSnappyBlockAsm8B + MOVD (R8)(R10), R9 + ADD R10, R8, R15 + MOVD 8(R15), R11 + MOVD (R5)(R10), R16 + EOR R16, R9, R9 + TST R9, R9 + BNE matchlen_bsf_8_repeat_extend_encodeSnappyBlockAsm8B + ADD R10, R5, R15 + MOVD 8(R15), R16 + EOR R16, R11, R11 + TST R11, R11 + BNE matchlen_bsf_16repeat_extend_encodeSnappyBlockAsm8B + SUB $16, R7, R7 + MOVWU R7, R7 + ADD $16, R10, R10 + MOVWU R10, R10 + JMP matchlen_loopback_16_repeat_extend_encodeSnappyBlockAsm8B + +matchlen_bsf_16repeat_extend_encodeSnappyBlockAsm8B: + RBIT R11, R11 + CLZ R11, R11 + ASR $0x03, R11, R11 + ADD R11, R10, R10 + ADD $8, R10, R10 + MOVWU R10, R10 + JMP repeat_extend_forward_end_encodeSnappyBlockAsm8B + +matchlen_match8_repeat_extend_encodeSnappyBlockAsm8B: + CMPW $0x08, R7 + BLO matchlen_match4_repeat_extend_encodeSnappyBlockAsm8B + MOVD (R8)(R10), R9 + MOVD (R5)(R10), R16 + EOR R16, R9, R9 + TST R9, R9 + BNE matchlen_bsf_8_repeat_extend_encodeSnappyBlockAsm8B + SUB $8, R7, R7 + MOVWU R7, R7 + ADD $8, R10, R10 + MOVWU R10, R10 + JMP matchlen_match4_repeat_extend_encodeSnappyBlockAsm8B + +matchlen_bsf_8_repeat_extend_encodeSnappyBlockAsm8B: + RBIT R9, R9 + CLZ R9, R9 + ASR $0x03, R9, R9 + ADD R9, R10, R10 + MOVWU R10, R10 + JMP repeat_extend_forward_end_encodeSnappyBlockAsm8B + +matchlen_match4_repeat_extend_encodeSnappyBlockAsm8B: + CMPW $0x04, R7 + BLO matchlen_match2_repeat_extend_encodeSnappyBlockAsm8B + MOVWU (R8)(R10), R9 + MOVWU (R5)(R10), R16 + CMPW R9, R16 + BNE matchlen_match2_repeat_extend_encodeSnappyBlockAsm8B + SUB $4, R7, R7 + MOVWU R7, R7 + ADD $4, R10, R10 + MOVWU R10, R10 + +matchlen_match2_repeat_extend_encodeSnappyBlockAsm8B: + CMPW $0x01, R7 + BEQ matchlen_match1_repeat_extend_encodeSnappyBlockAsm8B + BLO repeat_extend_forward_end_encodeSnappyBlockAsm8B + MOVHU (R8)(R10), R16 + BFI $0, R16, $16, R9 + ADD R10, R5, R15 + MOVHU (R15), R15 + AND $0xffff, R9, R16 + CMP R16, R15 + BNE matchlen_match1_repeat_extend_encodeSnappyBlockAsm8B + ADD $2, R10, R10 + MOVWU R10, R10 + SUBSW $0x02, R7, R7 + BEQ repeat_extend_forward_end_encodeSnappyBlockAsm8B + +matchlen_match1_repeat_extend_encodeSnappyBlockAsm8B: + MOVBU (R8)(R10), R16 + BFI $0, R16, $8, R9 + ADD R10, R5, R15 + MOVBU (R15), R15 + AND $0xff, R9, R16 + CMP R16, R15 + BNE repeat_extend_forward_end_encodeSnappyBlockAsm8B + ADD $1, R10, R10 + MOVWU R10, R10 + +repeat_extend_forward_end_encodeSnappyBlockAsm8B: + ADDW R10, R2, R2 + MOVWU R2, R5 + SUBW R6, R5, R5 + MOVWU 24(RSP), R6 + + // emitCopy +two_byte_offset_repeat_as_copy_encodeSnappyBlockAsm8B: + CMPW $0x40, R5 + BLS two_byte_offset_short_repeat_as_copy_encodeSnappyBlockAsm8B + MOVD $0xee, R16 + MOVB R16, (R1) + MOVH R6, 1(R1) + SUB $60, R5, R5 + MOVWU R5, R5 + ADD $0x03, R1, R1 + JMP two_byte_offset_repeat_as_copy_encodeSnappyBlockAsm8B + +two_byte_offset_short_repeat_as_copy_encodeSnappyBlockAsm8B: + MOVWU R5, R7 + LSLW $0x02, R7, R7 + CMPW $0x0c, R5 + BHS emit_copy_three_repeat_as_copy_encodeSnappyBlockAsm8B + SUB $15, R7, R7 + MOVWU R7, R7 + MOVB R6, 1(R1) + LSRW $0x08, R6, R6 + LSLW $0x05, R6, R6 + ORRW R6, R7, R7 + MOVB R7, (R1) + ADD $0x02, R1, R1 + JMP repeat_end_emit_encodeSnappyBlockAsm8B + +emit_copy_three_repeat_as_copy_encodeSnappyBlockAsm8B: + SUB $2, R7, R7 + MOVWU R7, R7 + MOVB R7, (R1) + MOVH R6, 1(R1) + ADD $0x03, R1, R1 + +repeat_end_emit_encodeSnappyBlockAsm8B: + MOVW R2, 20(RSP) + JMP search_loop_encodeSnappyBlockAsm8B + +no_repeat_found_encodeSnappyBlockAsm8B: + MOVWU (R3)(R5), R16 + CMPW R6, R16 + BEQ candidate_match_encodeSnappyBlockAsm8B + LSR $0x08, R6, R6 + MOVWU (R0)(R9<<2), R5 + ADD $2, R2, R8 + MOVWU R8, R8 + MOVWU (R3)(R7), R16 + CMPW R6, R16 + BEQ candidate2_match_encodeSnappyBlockAsm8B + MOVW R8, (R0)(R9<<2) + LSR $0x08, R6, R6 + MOVWU (R3)(R5), R16 + CMPW R6, R16 + BEQ candidate3_match_encodeSnappyBlockAsm8B + MOVWU 28(RSP), R2 + JMP search_loop_encodeSnappyBlockAsm8B + +candidate3_match_encodeSnappyBlockAsm8B: + ADDW $0x02, R2, R2 + JMP candidate_match_encodeSnappyBlockAsm8B + +candidate2_match_encodeSnappyBlockAsm8B: + MOVW R8, (R0)(R9<<2) + ADDW $1, R2, R2 + MOVWU R7, R5 + +candidate_match_encodeSnappyBlockAsm8B: + MOVWU 20(RSP), R6 + TSTW R5, R5 + BEQ match_extend_back_end_encodeSnappyBlockAsm8B + +match_extend_back_loop_encodeSnappyBlockAsm8B: + CMPW R6, R2 + BLS match_extend_back_end_encodeSnappyBlockAsm8B + ADD R5, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R7 + ADD R2, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R8 + AND $0xff, R8, R16 + AND $0xff, R7, R15 + CMP R16, R15 + BNE match_extend_back_end_encodeSnappyBlockAsm8B + SUB $1, R2, R2 + MOVWU R2, R2 + SUBSW $1, R5, R5 + BEQ match_extend_back_end_encodeSnappyBlockAsm8B + JMP match_extend_back_loop_encodeSnappyBlockAsm8B + +match_extend_back_end_encodeSnappyBlockAsm8B: + MOVWU R2, R6 + MOVWU 20(RSP), R16 + SUBW R16, R6, R6 + ADD R6, R1, R6 + ADD $3, R6, R6 + MOVD 8(RSP), R16 + CMP R16, R6 + BLO match_dst_size_check_encodeSnappyBlockAsm8B + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +match_dst_size_check_encodeSnappyBlockAsm8B: + MOVWU R2, R6 + MOVWU 20(RSP), R7 + CMPW R6, R7 + BEQ emit_literal_done_match_emit_encodeSnappyBlockAsm8B + MOVWU R6, R8 + MOVW R6, 20(RSP) + ADD R7, R3, R6 + SUBW R7, R8, R8 + SUB $1, R8, R7 + MOVWU R7, R7 + CMPW $0x3c, R7 + BLO one_byte_match_emit_encodeSnappyBlockAsm8B + CMPW $0x00000100, R7 + BLO two_bytes_match_emit_encodeSnappyBlockAsm8B + BLO three_bytes_match_emit_encodeSnappyBlockAsm8B + +three_bytes_match_emit_encodeSnappyBlockAsm8B: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R7, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_match_emit_encodeSnappyBlockAsm8B + +two_bytes_match_emit_encodeSnappyBlockAsm8B: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R7, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R7 + BLO memmove_match_emit_encodeSnappyBlockAsm8B + JMP memmove_long_match_emit_encodeSnappyBlockAsm8B + +one_byte_match_emit_encodeSnappyBlockAsm8B: + LSLW $0x02, R7, R16 + BFI $0, R16, $8, R7 + MOVB R7, (R1) + ADD $0x01, R1, R1 + +memmove_match_emit_encodeSnappyBlockAsm8B: + ADD R8, R1, R7 + + // genMemMoveShort + CMP $0x08, R8 + BLS emit_lit_memmove_match_emit_encodeSnappyBlockAsm8B_memmove_move_8 + CMP $0x10, R8 + BLS emit_lit_memmove_match_emit_encodeSnappyBlockAsm8B_memmove_move_8through16 + CMP $0x20, R8 + BLS emit_lit_memmove_match_emit_encodeSnappyBlockAsm8B_memmove_move_17through32 + JMP emit_lit_memmove_match_emit_encodeSnappyBlockAsm8B_memmove_move_33through64 + +emit_lit_memmove_match_emit_encodeSnappyBlockAsm8B_memmove_move_8: + MOVD (R6), R9 + MOVD R9, (R1) + JMP memmove_end_copy_match_emit_encodeSnappyBlockAsm8B + +emit_lit_memmove_match_emit_encodeSnappyBlockAsm8B_memmove_move_8through16: + MOVD (R6), R9 + ADD R8, R6, R15 + MOVD -8(R15), R6 + MOVD R9, (R1) + ADD R8, R1, R15 + MOVD R6, -8(R15) + JMP memmove_end_copy_match_emit_encodeSnappyBlockAsm8B + +emit_lit_memmove_match_emit_encodeSnappyBlockAsm8B_memmove_move_17through32: + FMOVQ (R6), F0 + ADD R8, R6, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_match_emit_encodeSnappyBlockAsm8B + +emit_lit_memmove_match_emit_encodeSnappyBlockAsm8B_memmove_move_33through64: + FMOVQ (R6), F0 + FMOVQ 16(R6), F1 + ADD R8, R6, R15 + FMOVQ -32(R15), F2 + ADD R8, R6, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R8, R1, R15 + FMOVQ F2, -32(R15) + ADD R8, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_match_emit_encodeSnappyBlockAsm8B: + MOVD R7, R1 + JMP emit_literal_done_match_emit_encodeSnappyBlockAsm8B + +memmove_long_match_emit_encodeSnappyBlockAsm8B: + ADD R8, R1, R7 + + // genMemMoveLong + MOVD R6, R9 + MOVD R1, R10 + MOVD R8, R11 + +emit_lit_memmove_long_match_emit_encodeSnappyBlockAsm8Blarge_big_loop_back: + FMOVQ (R9), F0 + FMOVQ 16(R9), F1 + FMOVQ F0, (R10) + FMOVQ F1, 16(R10) + ADD $0x20, R9, R9 + ADD $0x20, R10, R10 + SUB $0x20, R11, R11 + CMP $0x20, R11 + BHS emit_lit_memmove_long_match_emit_encodeSnappyBlockAsm8Blarge_big_loop_back + ADD R8, R6, R15 + FMOVQ -32(R15), F0 + ADD R8, R6, R15 + FMOVQ -16(R15), F1 + ADD R8, R1, R15 + FMOVQ F0, -32(R15) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + MOVD R7, R1 + +emit_literal_done_match_emit_encodeSnappyBlockAsm8B: +match_nolit_loop_encodeSnappyBlockAsm8B: + MOVWU R2, R6 + SUBW R5, R6, R6 + MOVW R6, 24(RSP) + ADDW $0x04, R2, R2 + ADDW $0x04, R5, R5 + MOVD src_len+32(FP), R6 + SUBW R2, R6, R6 + ADD R2, R3, R7 + ADD R5, R3, R5 + + // matchLen + MOVD $0, R9 + +matchlen_loopback_16_match_nolit_encodeSnappyBlockAsm8B: + CMPW $0x10, R6 + BLO matchlen_match8_match_nolit_encodeSnappyBlockAsm8B + MOVD (R7)(R9), R8 + ADD R9, R7, R15 + MOVD 8(R15), R10 + MOVD (R5)(R9), R16 + EOR R16, R8, R8 + TST R8, R8 + BNE matchlen_bsf_8_match_nolit_encodeSnappyBlockAsm8B + ADD R9, R5, R15 + MOVD 8(R15), R16 + EOR R16, R10, R10 + TST R10, R10 + BNE matchlen_bsf_16match_nolit_encodeSnappyBlockAsm8B + SUB $16, R6, R6 + MOVWU R6, R6 + ADD $16, R9, R9 + MOVWU R9, R9 + JMP matchlen_loopback_16_match_nolit_encodeSnappyBlockAsm8B + +matchlen_bsf_16match_nolit_encodeSnappyBlockAsm8B: + RBIT R10, R10 + CLZ R10, R10 + ASR $0x03, R10, R10 + ADD R10, R9, R9 + ADD $8, R9, R9 + MOVWU R9, R9 + JMP match_nolit_end_encodeSnappyBlockAsm8B + +matchlen_match8_match_nolit_encodeSnappyBlockAsm8B: + CMPW $0x08, R6 + BLO matchlen_match4_match_nolit_encodeSnappyBlockAsm8B + MOVD (R7)(R9), R8 + MOVD (R5)(R9), R16 + EOR R16, R8, R8 + TST R8, R8 + BNE matchlen_bsf_8_match_nolit_encodeSnappyBlockAsm8B + SUB $8, R6, R6 + MOVWU R6, R6 + ADD $8, R9, R9 + MOVWU R9, R9 + JMP matchlen_match4_match_nolit_encodeSnappyBlockAsm8B + +matchlen_bsf_8_match_nolit_encodeSnappyBlockAsm8B: + RBIT R8, R8 + CLZ R8, R8 + ASR $0x03, R8, R8 + ADD R8, R9, R9 + MOVWU R9, R9 + JMP match_nolit_end_encodeSnappyBlockAsm8B + +matchlen_match4_match_nolit_encodeSnappyBlockAsm8B: + CMPW $0x04, R6 + BLO matchlen_match2_match_nolit_encodeSnappyBlockAsm8B + MOVWU (R7)(R9), R8 + MOVWU (R5)(R9), R16 + CMPW R8, R16 + BNE matchlen_match2_match_nolit_encodeSnappyBlockAsm8B + SUB $4, R6, R6 + MOVWU R6, R6 + ADD $4, R9, R9 + MOVWU R9, R9 + +matchlen_match2_match_nolit_encodeSnappyBlockAsm8B: + CMPW $0x01, R6 + BEQ matchlen_match1_match_nolit_encodeSnappyBlockAsm8B + BLO match_nolit_end_encodeSnappyBlockAsm8B + MOVHU (R7)(R9), R16 + BFI $0, R16, $16, R8 + ADD R9, R5, R15 + MOVHU (R15), R15 + AND $0xffff, R8, R16 + CMP R16, R15 + BNE matchlen_match1_match_nolit_encodeSnappyBlockAsm8B + ADD $2, R9, R9 + MOVWU R9, R9 + SUBSW $0x02, R6, R6 + BEQ match_nolit_end_encodeSnappyBlockAsm8B + +matchlen_match1_match_nolit_encodeSnappyBlockAsm8B: + MOVBU (R7)(R9), R16 + BFI $0, R16, $8, R8 + ADD R9, R5, R15 + MOVBU (R15), R15 + AND $0xff, R8, R16 + CMP R16, R15 + BNE match_nolit_end_encodeSnappyBlockAsm8B + ADD $1, R9, R9 + MOVWU R9, R9 + +match_nolit_end_encodeSnappyBlockAsm8B: + ADDW R9, R2, R2 + MOVWU 24(RSP), R5 + ADDW $0x04, R9, R9 + MOVW R2, 20(RSP) + + // emitCopy +two_byte_offset_match_nolit_encodeSnappyBlockAsm8B: + CMPW $0x40, R9 + BLS two_byte_offset_short_match_nolit_encodeSnappyBlockAsm8B + MOVD $0xee, R16 + MOVB R16, (R1) + MOVH R5, 1(R1) + SUB $60, R9, R9 + MOVWU R9, R9 + ADD $0x03, R1, R1 + JMP two_byte_offset_match_nolit_encodeSnappyBlockAsm8B + +two_byte_offset_short_match_nolit_encodeSnappyBlockAsm8B: + MOVWU R9, R6 + LSLW $0x02, R6, R6 + CMPW $0x0c, R9 + BHS emit_copy_three_match_nolit_encodeSnappyBlockAsm8B + SUB $15, R6, R6 + MOVWU R6, R6 + MOVB R5, 1(R1) + LSRW $0x08, R5, R5 + LSLW $0x05, R5, R5 + ORRW R5, R6, R6 + MOVB R6, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeSnappyBlockAsm8B + +emit_copy_three_match_nolit_encodeSnappyBlockAsm8B: + SUB $2, R6, R6 + MOVWU R6, R6 + MOVB R6, (R1) + MOVH R5, 1(R1) + ADD $0x03, R1, R1 + +match_nolit_emitcopy_end_encodeSnappyBlockAsm8B: + MOVWU 16(RSP), R16 + CMPW R16, R2 + BHS emit_remainder_encodeSnappyBlockAsm8B + ADD R2, R3, R15 + MOVD -2(R15), R6 + MOVD 8(RSP), R16 + CMP R16, R1 + BLO match_nolit_dst_ok_encodeSnappyBlockAsm8B + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +match_nolit_dst_ok_encodeSnappyBlockAsm8B: + MOVD $0x9e3779b1, R8 + MOVD R6, R7 + LSR $0x10, R6, R6 + MOVD R6, R5 + LSL $0x20, R7, R7 + MUL R8, R7, R7 + LSR $0x38, R7, R7 + LSL $0x20, R5, R5 + MUL R8, R5, R5 + LSR $0x38, R5, R5 + SUB $2, R2, R8 + MOVWU R8, R8 + ADD R5<<2, R0, R9 + MOVWU (R9), R5 + MOVW R8, (R0)(R7<<2) + MOVW R2, (R9) + MOVWU (R3)(R5), R16 + CMPW R6, R16 + BEQ match_nolit_loop_encodeSnappyBlockAsm8B + ADDW $1, R2, R2 + JMP search_loop_encodeSnappyBlockAsm8B + +emit_remainder_encodeSnappyBlockAsm8B: + MOVD src_len+32(FP), R0 + MOVWU 20(RSP), R16 + SUBW R16, R0, R0 + ADD R0, R1, R0 + ADD $3, R0, R0 + MOVD 8(RSP), R16 + CMP R16, R0 + BLO emit_remainder_ok_encodeSnappyBlockAsm8B + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +emit_remainder_ok_encodeSnappyBlockAsm8B: + MOVD src_len+32(FP), R0 + MOVWU 20(RSP), R2 + CMPW R0, R2 + BEQ emit_literal_done_emit_remainder_encodeSnappyBlockAsm8B + MOVWU R0, R5 + MOVW R0, 20(RSP) + ADD R2, R3, R0 + SUBW R2, R5, R5 + SUB $1, R5, R2 + MOVWU R2, R2 + CMPW $0x3c, R2 + BLO one_byte_emit_remainder_encodeSnappyBlockAsm8B + CMPW $0x00000100, R2 + BLO two_bytes_emit_remainder_encodeSnappyBlockAsm8B + BLO three_bytes_emit_remainder_encodeSnappyBlockAsm8B + +three_bytes_emit_remainder_encodeSnappyBlockAsm8B: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R2, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_emit_remainder_encodeSnappyBlockAsm8B + +two_bytes_emit_remainder_encodeSnappyBlockAsm8B: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R2, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R2 + BLO memmove_emit_remainder_encodeSnappyBlockAsm8B + JMP memmove_long_emit_remainder_encodeSnappyBlockAsm8B + +one_byte_emit_remainder_encodeSnappyBlockAsm8B: + LSLW $0x02, R2, R16 + BFI $0, R16, $8, R2 + MOVB R2, (R1) + ADD $0x01, R1, R1 + +memmove_emit_remainder_encodeSnappyBlockAsm8B: + ADD R5, R1, R2 + MOVWU R5, R3 + + // genMemMoveShort + CMP $0x03, R3 + BLO emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm8B_memmove_move_1or2 + BEQ emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm8B_memmove_move_3 + CMP $0x08, R3 + BLO emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm8B_memmove_move_4through7 + CMP $0x10, R3 + BLS emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm8B_memmove_move_8through16 + CMP $0x20, R3 + BLS emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm8B_memmove_move_17through32 + JMP emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm8B_memmove_move_33through64 + +emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm8B_memmove_move_1or2: + MOVBU (R0), R16 + BFI $0, R16, $8, R5 + ADD R3, R0, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R0 + MOVB R5, (R1) + ADD R3, R1, R15 + MOVB R0, -1(R15) + JMP memmove_end_copy_emit_remainder_encodeSnappyBlockAsm8B + +emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm8B_memmove_move_3: + MOVHU (R0), R16 + BFI $0, R16, $16, R5 + MOVBU 2(R0), R16 + BFI $0, R16, $8, R0 + MOVH R5, (R1) + MOVB R0, 2(R1) + JMP memmove_end_copy_emit_remainder_encodeSnappyBlockAsm8B + +emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm8B_memmove_move_4through7: + MOVWU (R0), R5 + ADD R3, R0, R15 + MOVWU -4(R15), R0 + MOVW R5, (R1) + ADD R3, R1, R15 + MOVW R0, -4(R15) + JMP memmove_end_copy_emit_remainder_encodeSnappyBlockAsm8B + +emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm8B_memmove_move_8through16: + MOVD (R0), R5 + ADD R3, R0, R15 + MOVD -8(R15), R0 + MOVD R5, (R1) + ADD R3, R1, R15 + MOVD R0, -8(R15) + JMP memmove_end_copy_emit_remainder_encodeSnappyBlockAsm8B + +emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm8B_memmove_move_17through32: + FMOVQ (R0), F0 + ADD R3, R0, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R3, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_emit_remainder_encodeSnappyBlockAsm8B + +emit_lit_memmove_emit_remainder_encodeSnappyBlockAsm8B_memmove_move_33through64: + FMOVQ (R0), F0 + FMOVQ 16(R0), F1 + ADD R3, R0, R15 + FMOVQ -32(R15), F2 + ADD R3, R0, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R3, R1, R15 + FMOVQ F2, -32(R15) + ADD R3, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_emit_remainder_encodeSnappyBlockAsm8B: + MOVD R2, R1 + JMP emit_literal_done_emit_remainder_encodeSnappyBlockAsm8B + +memmove_long_emit_remainder_encodeSnappyBlockAsm8B: + ADD R5, R1, R2 + MOVWU R5, R3 + + // genMemMoveLong + MOVD R0, R5 + MOVD R1, R6 + MOVD R3, R7 + +emit_lit_memmove_long_emit_remainder_encodeSnappyBlockAsm8Blarge_big_loop_back: + FMOVQ (R5), F0 + FMOVQ 16(R5), F1 + FMOVQ F0, (R6) + FMOVQ F1, 16(R6) + ADD $0x20, R5, R5 + ADD $0x20, R6, R6 + SUB $0x20, R7, R7 + CMP $0x20, R7 + BHS emit_lit_memmove_long_emit_remainder_encodeSnappyBlockAsm8Blarge_big_loop_back + ADD R3, R0, R15 + FMOVQ -32(R15), F0 + ADD R3, R0, R15 + FMOVQ -16(R15), F1 + ADD R3, R1, R15 + FMOVQ F0, -32(R15) + ADD R3, R1, R15 + FMOVQ F1, -16(R15) + MOVD R2, R1 + +emit_literal_done_emit_remainder_encodeSnappyBlockAsm8B: + MOVD dst_base+0(FP), R0 + SUB R0, R1, R1 + MOVD R1, ret+56(FP) + RET + +// func encodeSnappyBetterBlockAsm(dst []byte, src []byte, tmp *[589824]byte) int +// Requires: BMI, SSE2 +TEXT ·encodeSnappyBetterBlockAsm(SB), $24-64 + MOVD tmp+48(FP), R0 + MOVD dst_base+0(FP), R1 + MOVD $0x00001200, R2 + MOVD R0, R3 + VEOR V0.B16, V0.B16, V0.B16 + +zero_loop_encodeSnappyBetterBlockAsm: + FMOVQ F0, (R3) + FMOVQ F0, 16(R3) + FMOVQ F0, 32(R3) + FMOVQ F0, 48(R3) + FMOVQ F0, 64(R3) + FMOVQ F0, 80(R3) + FMOVQ F0, 96(R3) + FMOVQ F0, 112(R3) + ADD $0x80, R3, R3 + SUBS $1, R2, R2 + BNE zero_loop_encodeSnappyBetterBlockAsm + MOVD $0x00000000, R16 + MOVW R16, 20(RSP) + MOVD src_len+32(FP), R2 + SUB $9, R2, R3 + SUB $8, R2, R5 + MOVW R5, 16(RSP) + LSR $0x05, R2, R2 + SUBW R2, R3, R3 + ADD R3, R1, R3 + MOVD R3, 8(RSP) + MOVD $0x00000001, R2 + MOVD $0x00000000, R16 + MOVW R16, 24(RSP) + MOVD src_base+24(FP), R3 + +search_loop_encodeSnappyBetterBlockAsm: + MOVWU R2, R5 + MOVWU 20(RSP), R16 + SUBW R16, R5, R5 + LSRW $0x07, R5, R5 + CMPW $0x63, R5 + BLS check_maxskip_ok_encodeSnappyBetterBlockAsm + ADD $100, R2, R5 + MOVWU R5, R5 + JMP check_maxskip_cont_encodeSnappyBetterBlockAsm + +check_maxskip_ok_encodeSnappyBetterBlockAsm: + ADD R5, R2, R5 + ADD $1, R5, R5 + MOVWU R5, R5 + +check_maxskip_cont_encodeSnappyBetterBlockAsm: + MOVWU 16(RSP), R16 + CMPW R16, R5 + BHS emit_remainder_encodeSnappyBetterBlockAsm + MOVD (R3)(R2), R6 + MOVW R5, 28(RSP) + MOVD $0x00cf1bbcdcbfa563, R8 + MOVD $0x9e3779b1, R5 + MOVD R6, R9 + MOVD R6, R10 + LSL $0x08, R9, R9 + MUL R8, R9, R9 + LSR $0x2f, R9, R9 + LSL $0x20, R10, R10 + MUL R5, R10, R10 + LSR $0x32, R10, R10 + MOVWU (R0)(R9<<2), R5 + ADD R10<<2, R0, R15 + MOVWU 524288(R15), R7 + MOVW R2, (R0)(R9<<2) + ADD R10<<2, R0, R15 + MOVW R2, 524288(R15) + MOVD (R3)(R5), R9 + MOVD (R3)(R7), R10 + CMP R6, R9 + BEQ candidate_match_encodeSnappyBetterBlockAsm + CMP R6, R10 + BNE no_short_found_encodeSnappyBetterBlockAsm + MOVWU R7, R5 + JMP candidate_match_encodeSnappyBetterBlockAsm + +no_short_found_encodeSnappyBetterBlockAsm: + CMPW R6, R9 + BEQ candidate_match_encodeSnappyBetterBlockAsm + CMPW R6, R10 + BEQ candidateS_match_encodeSnappyBetterBlockAsm + MOVWU 28(RSP), R2 + JMP search_loop_encodeSnappyBetterBlockAsm + +candidateS_match_encodeSnappyBetterBlockAsm: + LSR $0x08, R6, R6 + MOVD R6, R9 + LSL $0x08, R9, R9 + MUL R8, R9, R9 + LSR $0x2f, R9, R9 + MOVWU (R0)(R9<<2), R5 + ADDW $1, R2, R2 + MOVW R2, (R0)(R9<<2) + MOVWU (R3)(R5), R16 + CMPW R6, R16 + BEQ candidate_match_encodeSnappyBetterBlockAsm + SUBW $1, R2, R2 + MOVWU R7, R5 + +candidate_match_encodeSnappyBetterBlockAsm: + MOVWU 20(RSP), R6 + TSTW R5, R5 + BEQ match_extend_back_end_encodeSnappyBetterBlockAsm + +match_extend_back_loop_encodeSnappyBetterBlockAsm: + CMPW R6, R2 + BLS match_extend_back_end_encodeSnappyBetterBlockAsm + ADD R5, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R7 + ADD R2, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R8 + AND $0xff, R8, R16 + AND $0xff, R7, R15 + CMP R16, R15 + BNE match_extend_back_end_encodeSnappyBetterBlockAsm + SUB $1, R2, R2 + MOVWU R2, R2 + SUBSW $1, R5, R5 + BEQ match_extend_back_end_encodeSnappyBetterBlockAsm + JMP match_extend_back_loop_encodeSnappyBetterBlockAsm + +match_extend_back_end_encodeSnappyBetterBlockAsm: + MOVWU R2, R6 + MOVWU 20(RSP), R16 + SUBW R16, R6, R6 + ADD R6, R1, R6 + ADD $5, R6, R6 + MOVD 8(RSP), R16 + CMP R16, R6 + BLO match_dst_size_check_encodeSnappyBetterBlockAsm + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +match_dst_size_check_encodeSnappyBetterBlockAsm: + MOVWU R2, R6 + ADDW $0x04, R2, R2 + ADDW $0x04, R5, R5 + MOVD src_len+32(FP), R7 + SUBW R2, R7, R7 + ADD R2, R3, R8 + ADD R5, R3, R9 + + // matchLen + MOVD $0, R11 + +matchlen_loopback_16_match_nolit_encodeSnappyBetterBlockAsm: + CMPW $0x10, R7 + BLO matchlen_match8_match_nolit_encodeSnappyBetterBlockAsm + MOVD (R8)(R11), R10 + ADD R11, R8, R15 + MOVD 8(R15), R12 + MOVD (R9)(R11), R16 + EOR R16, R10, R10 + TST R10, R10 + BNE matchlen_bsf_8_match_nolit_encodeSnappyBetterBlockAsm + ADD R11, R9, R15 + MOVD 8(R15), R16 + EOR R16, R12, R12 + TST R12, R12 + BNE matchlen_bsf_16match_nolit_encodeSnappyBetterBlockAsm + SUB $16, R7, R7 + MOVWU R7, R7 + ADD $16, R11, R11 + MOVWU R11, R11 + JMP matchlen_loopback_16_match_nolit_encodeSnappyBetterBlockAsm + +matchlen_bsf_16match_nolit_encodeSnappyBetterBlockAsm: + RBIT R12, R12 + CLZ R12, R12 + ASR $0x03, R12, R12 + ADD R12, R11, R11 + ADD $8, R11, R11 + MOVWU R11, R11 + JMP match_nolit_end_encodeSnappyBetterBlockAsm + +matchlen_match8_match_nolit_encodeSnappyBetterBlockAsm: + CMPW $0x08, R7 + BLO matchlen_match4_match_nolit_encodeSnappyBetterBlockAsm + MOVD (R8)(R11), R10 + MOVD (R9)(R11), R16 + EOR R16, R10, R10 + TST R10, R10 + BNE matchlen_bsf_8_match_nolit_encodeSnappyBetterBlockAsm + SUB $8, R7, R7 + MOVWU R7, R7 + ADD $8, R11, R11 + MOVWU R11, R11 + JMP matchlen_match4_match_nolit_encodeSnappyBetterBlockAsm + +matchlen_bsf_8_match_nolit_encodeSnappyBetterBlockAsm: + RBIT R10, R10 + CLZ R10, R10 + ASR $0x03, R10, R10 + ADD R10, R11, R11 + MOVWU R11, R11 + JMP match_nolit_end_encodeSnappyBetterBlockAsm + +matchlen_match4_match_nolit_encodeSnappyBetterBlockAsm: + CMPW $0x04, R7 + BLO matchlen_match2_match_nolit_encodeSnappyBetterBlockAsm + MOVWU (R8)(R11), R10 + MOVWU (R9)(R11), R16 + CMPW R10, R16 + BNE matchlen_match2_match_nolit_encodeSnappyBetterBlockAsm + SUB $4, R7, R7 + MOVWU R7, R7 + ADD $4, R11, R11 + MOVWU R11, R11 + +matchlen_match2_match_nolit_encodeSnappyBetterBlockAsm: + CMPW $0x01, R7 + BEQ matchlen_match1_match_nolit_encodeSnappyBetterBlockAsm + BLO match_nolit_end_encodeSnappyBetterBlockAsm + MOVHU (R8)(R11), R16 + BFI $0, R16, $16, R10 + ADD R11, R9, R15 + MOVHU (R15), R15 + AND $0xffff, R10, R16 + CMP R16, R15 + BNE matchlen_match1_match_nolit_encodeSnappyBetterBlockAsm + ADD $2, R11, R11 + MOVWU R11, R11 + SUBSW $0x02, R7, R7 + BEQ match_nolit_end_encodeSnappyBetterBlockAsm + +matchlen_match1_match_nolit_encodeSnappyBetterBlockAsm: + MOVBU (R8)(R11), R16 + BFI $0, R16, $8, R10 + ADD R11, R9, R15 + MOVBU (R15), R15 + AND $0xff, R10, R16 + CMP R16, R15 + BNE match_nolit_end_encodeSnappyBetterBlockAsm + ADD $1, R11, R11 + MOVWU R11, R11 + +match_nolit_end_encodeSnappyBetterBlockAsm: + MOVWU R2, R7 + SUBW R5, R7, R7 + + // Check if repeat + CMPW $0x01, R11 + BHI match_length_ok_encodeSnappyBetterBlockAsm + CMPW $0x0000ffff, R7 + BLS match_length_ok_encodeSnappyBetterBlockAsm + MOVWU 28(RSP), R2 + ADDW $1, R2, R2 + JMP search_loop_encodeSnappyBetterBlockAsm + +match_length_ok_encodeSnappyBetterBlockAsm: + MOVW R7, 24(RSP) + MOVWU 20(RSP), R5 + CMPW R6, R5 + BEQ emit_literal_done_match_emit_encodeSnappyBetterBlockAsm + MOVWU R6, R8 + MOVW R6, 20(RSP) + ADD R5, R3, R9 + SUBW R5, R8, R8 + SUB $1, R8, R5 + MOVWU R5, R5 + CMPW $0x3c, R5 + BLO one_byte_match_emit_encodeSnappyBetterBlockAsm + CMPW $0x00000100, R5 + BLO two_bytes_match_emit_encodeSnappyBetterBlockAsm + CMPW $0x00010000, R5 + BLO three_bytes_match_emit_encodeSnappyBetterBlockAsm + CMPW $0x01000000, R5 + BLO four_bytes_match_emit_encodeSnappyBetterBlockAsm + MOVD $0xfc, R16 + MOVB R16, (R1) + MOVW R5, 1(R1) + ADD $0x05, R1, R1 + JMP memmove_long_match_emit_encodeSnappyBetterBlockAsm + +four_bytes_match_emit_encodeSnappyBetterBlockAsm: + MOVWU R5, R10 + LSRW $0x10, R10, R10 + MOVD $0xf8, R16 + MOVB R16, (R1) + MOVH R5, 1(R1) + MOVB R10, 3(R1) + ADD $0x04, R1, R1 + JMP memmove_long_match_emit_encodeSnappyBetterBlockAsm + +three_bytes_match_emit_encodeSnappyBetterBlockAsm: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R5, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_match_emit_encodeSnappyBetterBlockAsm + +two_bytes_match_emit_encodeSnappyBetterBlockAsm: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R5, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R5 + BLO memmove_match_emit_encodeSnappyBetterBlockAsm + JMP memmove_long_match_emit_encodeSnappyBetterBlockAsm + +one_byte_match_emit_encodeSnappyBetterBlockAsm: + LSLW $0x02, R5, R16 + BFI $0, R16, $8, R5 + MOVB R5, (R1) + ADD $0x01, R1, R1 + +memmove_match_emit_encodeSnappyBetterBlockAsm: + ADD R8, R1, R5 + + // genMemMoveShort + CMP $0x08, R8 + BLS emit_lit_memmove_match_emit_encodeSnappyBetterBlockAsm_memmove_move_8 + CMP $0x10, R8 + BLS emit_lit_memmove_match_emit_encodeSnappyBetterBlockAsm_memmove_move_8through16 + CMP $0x20, R8 + BLS emit_lit_memmove_match_emit_encodeSnappyBetterBlockAsm_memmove_move_17through32 + JMP emit_lit_memmove_match_emit_encodeSnappyBetterBlockAsm_memmove_move_33through64 + +emit_lit_memmove_match_emit_encodeSnappyBetterBlockAsm_memmove_move_8: + MOVD (R9), R10 + MOVD R10, (R1) + JMP memmove_end_copy_match_emit_encodeSnappyBetterBlockAsm + +emit_lit_memmove_match_emit_encodeSnappyBetterBlockAsm_memmove_move_8through16: + MOVD (R9), R10 + ADD R8, R9, R15 + MOVD -8(R15), R9 + MOVD R10, (R1) + ADD R8, R1, R15 + MOVD R9, -8(R15) + JMP memmove_end_copy_match_emit_encodeSnappyBetterBlockAsm + +emit_lit_memmove_match_emit_encodeSnappyBetterBlockAsm_memmove_move_17through32: + FMOVQ (R9), F0 + ADD R8, R9, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_match_emit_encodeSnappyBetterBlockAsm + +emit_lit_memmove_match_emit_encodeSnappyBetterBlockAsm_memmove_move_33through64: + FMOVQ (R9), F0 + FMOVQ 16(R9), F1 + ADD R8, R9, R15 + FMOVQ -32(R15), F2 + ADD R8, R9, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R8, R1, R15 + FMOVQ F2, -32(R15) + ADD R8, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_match_emit_encodeSnappyBetterBlockAsm: + MOVD R5, R1 + JMP emit_literal_done_match_emit_encodeSnappyBetterBlockAsm + +memmove_long_match_emit_encodeSnappyBetterBlockAsm: + ADD R8, R1, R5 + + // genMemMoveLong + MOVD R9, R10 + MOVD R1, R12 + MOVD R8, R13 + +emit_lit_memmove_long_match_emit_encodeSnappyBetterBlockAsmlarge_big_loop_back: + FMOVQ (R10), F0 + FMOVQ 16(R10), F1 + FMOVQ F0, (R12) + FMOVQ F1, 16(R12) + ADD $0x20, R10, R10 + ADD $0x20, R12, R12 + SUB $0x20, R13, R13 + CMP $0x20, R13 + BHS emit_lit_memmove_long_match_emit_encodeSnappyBetterBlockAsmlarge_big_loop_back + ADD R8, R9, R15 + FMOVQ -32(R15), F0 + ADD R8, R9, R15 + FMOVQ -16(R15), F1 + ADD R8, R1, R15 + FMOVQ F0, -32(R15) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + MOVD R5, R1 + +emit_literal_done_match_emit_encodeSnappyBetterBlockAsm: + ADDW R11, R2, R2 + ADDW $0x04, R11, R11 + MOVW R2, 20(RSP) + + // emitCopy + CMPW $0x00010000, R7 + BLO two_byte_offset_match_nolit_encodeSnappyBetterBlockAsm + +four_bytes_loop_back_match_nolit_encodeSnappyBetterBlockAsm: + CMPW $0x40, R11 + BLS four_bytes_remain_match_nolit_encodeSnappyBetterBlockAsm + MOVD $0xff, R16 + MOVB R16, (R1) + MOVW R7, 1(R1) + SUB $64, R11, R11 + MOVWU R11, R11 + ADD $0x05, R1, R1 + CMPW $0x04, R11 + BLO four_bytes_remain_match_nolit_encodeSnappyBetterBlockAsm + JMP four_bytes_loop_back_match_nolit_encodeSnappyBetterBlockAsm + +four_bytes_remain_match_nolit_encodeSnappyBetterBlockAsm: + TSTW R11, R11 + BEQ match_nolit_emitcopy_end_encodeSnappyBetterBlockAsm + MOVD $0, R5 + ADD R11<<2, R5, R11 + SUB $1, R11, R11 + MOVWU R11, R11 + MOVB R11, (R1) + MOVW R7, 1(R1) + ADD $0x05, R1, R1 + JMP match_nolit_emitcopy_end_encodeSnappyBetterBlockAsm + +two_byte_offset_match_nolit_encodeSnappyBetterBlockAsm: + CMPW $0x40, R11 + BLS two_byte_offset_short_match_nolit_encodeSnappyBetterBlockAsm + MOVD $0xee, R16 + MOVB R16, (R1) + MOVH R7, 1(R1) + SUB $60, R11, R11 + MOVWU R11, R11 + ADD $0x03, R1, R1 + JMP two_byte_offset_match_nolit_encodeSnappyBetterBlockAsm + +two_byte_offset_short_match_nolit_encodeSnappyBetterBlockAsm: + MOVWU R11, R5 + LSLW $0x02, R5, R5 + CMPW $0x0c, R11 + BHS emit_copy_three_match_nolit_encodeSnappyBetterBlockAsm + CMPW $0x00000800, R7 + BHS emit_copy_three_match_nolit_encodeSnappyBetterBlockAsm + SUB $15, R5, R5 + MOVWU R5, R5 + MOVB R7, 1(R1) + LSRW $0x08, R7, R7 + LSLW $0x05, R7, R7 + ORRW R7, R5, R5 + MOVB R5, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeSnappyBetterBlockAsm + +emit_copy_three_match_nolit_encodeSnappyBetterBlockAsm: + SUB $2, R5, R5 + MOVWU R5, R5 + MOVB R5, (R1) + MOVH R7, 1(R1) + ADD $0x03, R1, R1 + +match_nolit_emitcopy_end_encodeSnappyBetterBlockAsm: + MOVWU 16(RSP), R16 + CMPW R16, R2 + BHS emit_remainder_encodeSnappyBetterBlockAsm + MOVD 8(RSP), R16 + CMP R16, R1 + BLO match_nolit_dst_ok_encodeSnappyBetterBlockAsm + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +match_nolit_dst_ok_encodeSnappyBetterBlockAsm: + MOVD $0x00cf1bbcdcbfa563, R5 + MOVD $0x9e3779b1, R7 + ADD $1, R6, R6 + SUB $2, R2, R8 + MOVD (R3)(R6), R9 + ADD R6, R3, R15 + MOVD 1(R15), R10 + MOVD (R3)(R8), R11 + ADD R8, R3, R15 + MOVD 1(R15), R12 + LSL $0x08, R9, R9 + MUL R5, R9, R9 + LSR $0x2f, R9, R9 + LSL $0x20, R10, R10 + MUL R7, R10, R10 + LSR $0x32, R10, R10 + LSL $0x08, R11, R11 + MUL R5, R11, R11 + LSR $0x2f, R11, R11 + LSL $0x20, R12, R12 + MUL R7, R12, R12 + LSR $0x32, R12, R12 + ADD $1, R6, R7 + ADD $1, R8, R13 + MOVW R6, (R0)(R9<<2) + MOVW R8, (R0)(R11<<2) + ADD R10<<2, R0, R15 + MOVW R7, 524288(R15) + ADD R12<<2, R0, R15 + MOVW R13, 524288(R15) + ADD R6, R8, R7 + ADD $1, R7, R7 + LSR $0x01, R7, R7 + ADD $0x01, R6, R6 + SUB $0x01, R8, R8 + +index_loop_encodeSnappyBetterBlockAsm: + CMP R8, R7 + BHS search_loop_encodeSnappyBetterBlockAsm + MOVD (R3)(R6), R9 + MOVD (R3)(R7), R10 + LSL $0x08, R9, R9 + MUL R5, R9, R9 + LSR $0x2f, R9, R9 + LSL $0x08, R10, R10 + MUL R5, R10, R10 + LSR $0x2f, R10, R10 + MOVW R6, (R0)(R9<<2) + MOVW R7, (R0)(R10<<2) + ADD $0x02, R6, R6 + ADD $0x02, R7, R7 + JMP index_loop_encodeSnappyBetterBlockAsm + +emit_remainder_encodeSnappyBetterBlockAsm: + MOVD src_len+32(FP), R0 + MOVWU 20(RSP), R16 + SUBW R16, R0, R0 + ADD R0, R1, R0 + ADD $5, R0, R0 + MOVD 8(RSP), R16 + CMP R16, R0 + BLO emit_remainder_ok_encodeSnappyBetterBlockAsm + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +emit_remainder_ok_encodeSnappyBetterBlockAsm: + MOVD src_len+32(FP), R0 + MOVWU 20(RSP), R2 + CMPW R0, R2 + BEQ emit_literal_done_emit_remainder_encodeSnappyBetterBlockAsm + MOVWU R0, R5 + MOVW R0, 20(RSP) + ADD R2, R3, R0 + SUBW R2, R5, R5 + SUB $1, R5, R2 + MOVWU R2, R2 + CMPW $0x3c, R2 + BLO one_byte_emit_remainder_encodeSnappyBetterBlockAsm + CMPW $0x00000100, R2 + BLO two_bytes_emit_remainder_encodeSnappyBetterBlockAsm + CMPW $0x00010000, R2 + BLO three_bytes_emit_remainder_encodeSnappyBetterBlockAsm + CMPW $0x01000000, R2 + BLO four_bytes_emit_remainder_encodeSnappyBetterBlockAsm + MOVD $0xfc, R16 + MOVB R16, (R1) + MOVW R2, 1(R1) + ADD $0x05, R1, R1 + JMP memmove_long_emit_remainder_encodeSnappyBetterBlockAsm + +four_bytes_emit_remainder_encodeSnappyBetterBlockAsm: + MOVWU R2, R3 + LSRW $0x10, R3, R3 + MOVD $0xf8, R16 + MOVB R16, (R1) + MOVH R2, 1(R1) + MOVB R3, 3(R1) + ADD $0x04, R1, R1 + JMP memmove_long_emit_remainder_encodeSnappyBetterBlockAsm + +three_bytes_emit_remainder_encodeSnappyBetterBlockAsm: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R2, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_emit_remainder_encodeSnappyBetterBlockAsm + +two_bytes_emit_remainder_encodeSnappyBetterBlockAsm: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R2, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R2 + BLO memmove_emit_remainder_encodeSnappyBetterBlockAsm + JMP memmove_long_emit_remainder_encodeSnappyBetterBlockAsm + +one_byte_emit_remainder_encodeSnappyBetterBlockAsm: + LSLW $0x02, R2, R16 + BFI $0, R16, $8, R2 + MOVB R2, (R1) + ADD $0x01, R1, R1 + +memmove_emit_remainder_encodeSnappyBetterBlockAsm: + ADD R5, R1, R2 + MOVWU R5, R3 + + // genMemMoveShort + CMP $0x03, R3 + BLO emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm_memmove_move_1or2 + BEQ emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm_memmove_move_3 + CMP $0x08, R3 + BLO emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm_memmove_move_4through7 + CMP $0x10, R3 + BLS emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm_memmove_move_8through16 + CMP $0x20, R3 + BLS emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm_memmove_move_17through32 + JMP emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm_memmove_move_33through64 + +emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm_memmove_move_1or2: + MOVBU (R0), R16 + BFI $0, R16, $8, R5 + ADD R3, R0, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R0 + MOVB R5, (R1) + ADD R3, R1, R15 + MOVB R0, -1(R15) + JMP memmove_end_copy_emit_remainder_encodeSnappyBetterBlockAsm + +emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm_memmove_move_3: + MOVHU (R0), R16 + BFI $0, R16, $16, R5 + MOVBU 2(R0), R16 + BFI $0, R16, $8, R0 + MOVH R5, (R1) + MOVB R0, 2(R1) + JMP memmove_end_copy_emit_remainder_encodeSnappyBetterBlockAsm + +emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm_memmove_move_4through7: + MOVWU (R0), R5 + ADD R3, R0, R15 + MOVWU -4(R15), R0 + MOVW R5, (R1) + ADD R3, R1, R15 + MOVW R0, -4(R15) + JMP memmove_end_copy_emit_remainder_encodeSnappyBetterBlockAsm + +emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm_memmove_move_8through16: + MOVD (R0), R5 + ADD R3, R0, R15 + MOVD -8(R15), R0 + MOVD R5, (R1) + ADD R3, R1, R15 + MOVD R0, -8(R15) + JMP memmove_end_copy_emit_remainder_encodeSnappyBetterBlockAsm + +emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm_memmove_move_17through32: + FMOVQ (R0), F0 + ADD R3, R0, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R3, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_emit_remainder_encodeSnappyBetterBlockAsm + +emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm_memmove_move_33through64: + FMOVQ (R0), F0 + FMOVQ 16(R0), F1 + ADD R3, R0, R15 + FMOVQ -32(R15), F2 + ADD R3, R0, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R3, R1, R15 + FMOVQ F2, -32(R15) + ADD R3, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_emit_remainder_encodeSnappyBetterBlockAsm: + MOVD R2, R1 + JMP emit_literal_done_emit_remainder_encodeSnappyBetterBlockAsm + +memmove_long_emit_remainder_encodeSnappyBetterBlockAsm: + ADD R5, R1, R2 + MOVWU R5, R3 + + // genMemMoveLong + MOVD R0, R5 + MOVD R1, R6 + MOVD R3, R7 + +emit_lit_memmove_long_emit_remainder_encodeSnappyBetterBlockAsmlarge_big_loop_back: + FMOVQ (R5), F0 + FMOVQ 16(R5), F1 + FMOVQ F0, (R6) + FMOVQ F1, 16(R6) + ADD $0x20, R5, R5 + ADD $0x20, R6, R6 + SUB $0x20, R7, R7 + CMP $0x20, R7 + BHS emit_lit_memmove_long_emit_remainder_encodeSnappyBetterBlockAsmlarge_big_loop_back + ADD R3, R0, R15 + FMOVQ -32(R15), F0 + ADD R3, R0, R15 + FMOVQ -16(R15), F1 + ADD R3, R1, R15 + FMOVQ F0, -32(R15) + ADD R3, R1, R15 + FMOVQ F1, -16(R15) + MOVD R2, R1 + +emit_literal_done_emit_remainder_encodeSnappyBetterBlockAsm: + MOVD dst_base+0(FP), R0 + SUB R0, R1, R1 + MOVD R1, ret+56(FP) + RET + +// func encodeSnappyBetterBlockAsm64K(dst []byte, src []byte, tmp *[294912]byte) int +// Requires: BMI, SSE2 +TEXT ·encodeSnappyBetterBlockAsm64K(SB), $24-64 + MOVD tmp+48(FP), R0 + MOVD dst_base+0(FP), R1 + MOVD $0x00000900, R2 + MOVD R0, R3 + VEOR V0.B16, V0.B16, V0.B16 + +zero_loop_encodeSnappyBetterBlockAsm64K: + FMOVQ F0, (R3) + FMOVQ F0, 16(R3) + FMOVQ F0, 32(R3) + FMOVQ F0, 48(R3) + FMOVQ F0, 64(R3) + FMOVQ F0, 80(R3) + FMOVQ F0, 96(R3) + FMOVQ F0, 112(R3) + ADD $0x80, R3, R3 + SUBS $1, R2, R2 + BNE zero_loop_encodeSnappyBetterBlockAsm64K + MOVD $0x00000000, R16 + MOVW R16, 20(RSP) + MOVD src_len+32(FP), R2 + SUB $9, R2, R3 + SUB $8, R2, R5 + MOVW R5, 16(RSP) + LSR $0x05, R2, R2 + SUBW R2, R3, R3 + ADD R3, R1, R3 + MOVD R3, 8(RSP) + MOVD $0x00000001, R2 + MOVD $0x00000000, R16 + MOVW R16, 24(RSP) + MOVD src_base+24(FP), R3 + +search_loop_encodeSnappyBetterBlockAsm64K: + MOVWU R2, R5 + MOVWU 20(RSP), R16 + SUBW R16, R5, R5 + LSRW $0x07, R5, R5 + ADD R5, R2, R5 + ADD $1, R5, R5 + MOVWU R5, R5 + MOVWU 16(RSP), R16 + CMPW R16, R5 + BHS emit_remainder_encodeSnappyBetterBlockAsm64K + MOVD (R3)(R2), R6 + MOVW R5, 28(RSP) + MOVD $0x00cf1bbcdcbfa563, R8 + MOVD $0x9e3779b1, R5 + MOVD R6, R9 + MOVD R6, R10 + LSL $0x08, R9, R9 + MUL R8, R9, R9 + LSR $0x30, R9, R9 + LSL $0x20, R10, R10 + MUL R5, R10, R10 + LSR $0x33, R10, R10 + MOVWU (R0)(R9<<2), R5 + ADD R10<<2, R0, R15 + MOVWU 262144(R15), R7 + MOVW R2, (R0)(R9<<2) + ADD R10<<2, R0, R15 + MOVW R2, 262144(R15) + MOVD (R3)(R5), R9 + MOVD (R3)(R7), R10 + CMP R6, R9 + BEQ candidate_match_encodeSnappyBetterBlockAsm64K + CMP R6, R10 + BNE no_short_found_encodeSnappyBetterBlockAsm64K + MOVWU R7, R5 + JMP candidate_match_encodeSnappyBetterBlockAsm64K + +no_short_found_encodeSnappyBetterBlockAsm64K: + CMPW R6, R9 + BEQ candidate_match_encodeSnappyBetterBlockAsm64K + CMPW R6, R10 + BEQ candidateS_match_encodeSnappyBetterBlockAsm64K + MOVWU 28(RSP), R2 + JMP search_loop_encodeSnappyBetterBlockAsm64K + +candidateS_match_encodeSnappyBetterBlockAsm64K: + LSR $0x08, R6, R6 + MOVD R6, R9 + LSL $0x08, R9, R9 + MUL R8, R9, R9 + LSR $0x30, R9, R9 + MOVWU (R0)(R9<<2), R5 + ADDW $1, R2, R2 + MOVW R2, (R0)(R9<<2) + MOVWU (R3)(R5), R16 + CMPW R6, R16 + BEQ candidate_match_encodeSnappyBetterBlockAsm64K + SUBW $1, R2, R2 + MOVWU R7, R5 + +candidate_match_encodeSnappyBetterBlockAsm64K: + MOVWU 20(RSP), R6 + TSTW R5, R5 + BEQ match_extend_back_end_encodeSnappyBetterBlockAsm64K + +match_extend_back_loop_encodeSnappyBetterBlockAsm64K: + CMPW R6, R2 + BLS match_extend_back_end_encodeSnappyBetterBlockAsm64K + ADD R5, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R7 + ADD R2, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R8 + AND $0xff, R8, R16 + AND $0xff, R7, R15 + CMP R16, R15 + BNE match_extend_back_end_encodeSnappyBetterBlockAsm64K + SUB $1, R2, R2 + MOVWU R2, R2 + SUBSW $1, R5, R5 + BEQ match_extend_back_end_encodeSnappyBetterBlockAsm64K + JMP match_extend_back_loop_encodeSnappyBetterBlockAsm64K + +match_extend_back_end_encodeSnappyBetterBlockAsm64K: + MOVWU R2, R6 + MOVWU 20(RSP), R16 + SUBW R16, R6, R6 + ADD R6, R1, R6 + ADD $3, R6, R6 + MOVD 8(RSP), R16 + CMP R16, R6 + BLO match_dst_size_check_encodeSnappyBetterBlockAsm64K + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +match_dst_size_check_encodeSnappyBetterBlockAsm64K: + MOVWU R2, R6 + ADDW $0x04, R2, R2 + ADDW $0x04, R5, R5 + MOVD src_len+32(FP), R7 + SUBW R2, R7, R7 + ADD R2, R3, R8 + ADD R5, R3, R9 + + // matchLen + MOVD $0, R11 + +matchlen_loopback_16_match_nolit_encodeSnappyBetterBlockAsm64K: + CMPW $0x10, R7 + BLO matchlen_match8_match_nolit_encodeSnappyBetterBlockAsm64K + MOVD (R8)(R11), R10 + ADD R11, R8, R15 + MOVD 8(R15), R12 + MOVD (R9)(R11), R16 + EOR R16, R10, R10 + TST R10, R10 + BNE matchlen_bsf_8_match_nolit_encodeSnappyBetterBlockAsm64K + ADD R11, R9, R15 + MOVD 8(R15), R16 + EOR R16, R12, R12 + TST R12, R12 + BNE matchlen_bsf_16match_nolit_encodeSnappyBetterBlockAsm64K + SUB $16, R7, R7 + MOVWU R7, R7 + ADD $16, R11, R11 + MOVWU R11, R11 + JMP matchlen_loopback_16_match_nolit_encodeSnappyBetterBlockAsm64K + +matchlen_bsf_16match_nolit_encodeSnappyBetterBlockAsm64K: + RBIT R12, R12 + CLZ R12, R12 + ASR $0x03, R12, R12 + ADD R12, R11, R11 + ADD $8, R11, R11 + MOVWU R11, R11 + JMP match_nolit_end_encodeSnappyBetterBlockAsm64K + +matchlen_match8_match_nolit_encodeSnappyBetterBlockAsm64K: + CMPW $0x08, R7 + BLO matchlen_match4_match_nolit_encodeSnappyBetterBlockAsm64K + MOVD (R8)(R11), R10 + MOVD (R9)(R11), R16 + EOR R16, R10, R10 + TST R10, R10 + BNE matchlen_bsf_8_match_nolit_encodeSnappyBetterBlockAsm64K + SUB $8, R7, R7 + MOVWU R7, R7 + ADD $8, R11, R11 + MOVWU R11, R11 + JMP matchlen_match4_match_nolit_encodeSnappyBetterBlockAsm64K + +matchlen_bsf_8_match_nolit_encodeSnappyBetterBlockAsm64K: + RBIT R10, R10 + CLZ R10, R10 + ASR $0x03, R10, R10 + ADD R10, R11, R11 + MOVWU R11, R11 + JMP match_nolit_end_encodeSnappyBetterBlockAsm64K + +matchlen_match4_match_nolit_encodeSnappyBetterBlockAsm64K: + CMPW $0x04, R7 + BLO matchlen_match2_match_nolit_encodeSnappyBetterBlockAsm64K + MOVWU (R8)(R11), R10 + MOVWU (R9)(R11), R16 + CMPW R10, R16 + BNE matchlen_match2_match_nolit_encodeSnappyBetterBlockAsm64K + SUB $4, R7, R7 + MOVWU R7, R7 + ADD $4, R11, R11 + MOVWU R11, R11 + +matchlen_match2_match_nolit_encodeSnappyBetterBlockAsm64K: + CMPW $0x01, R7 + BEQ matchlen_match1_match_nolit_encodeSnappyBetterBlockAsm64K + BLO match_nolit_end_encodeSnappyBetterBlockAsm64K + MOVHU (R8)(R11), R16 + BFI $0, R16, $16, R10 + ADD R11, R9, R15 + MOVHU (R15), R15 + AND $0xffff, R10, R16 + CMP R16, R15 + BNE matchlen_match1_match_nolit_encodeSnappyBetterBlockAsm64K + ADD $2, R11, R11 + MOVWU R11, R11 + SUBSW $0x02, R7, R7 + BEQ match_nolit_end_encodeSnappyBetterBlockAsm64K + +matchlen_match1_match_nolit_encodeSnappyBetterBlockAsm64K: + MOVBU (R8)(R11), R16 + BFI $0, R16, $8, R10 + ADD R11, R9, R15 + MOVBU (R15), R15 + AND $0xff, R10, R16 + CMP R16, R15 + BNE match_nolit_end_encodeSnappyBetterBlockAsm64K + ADD $1, R11, R11 + MOVWU R11, R11 + +match_nolit_end_encodeSnappyBetterBlockAsm64K: + MOVWU R2, R7 + SUBW R5, R7, R7 + + // Check if repeat + MOVW R7, 24(RSP) + MOVWU 20(RSP), R5 + CMPW R6, R5 + BEQ emit_literal_done_match_emit_encodeSnappyBetterBlockAsm64K + MOVWU R6, R8 + MOVW R6, 20(RSP) + ADD R5, R3, R9 + SUBW R5, R8, R8 + SUB $1, R8, R5 + MOVWU R5, R5 + CMPW $0x3c, R5 + BLO one_byte_match_emit_encodeSnappyBetterBlockAsm64K + CMPW $0x00000100, R5 + BLO two_bytes_match_emit_encodeSnappyBetterBlockAsm64K + BLO three_bytes_match_emit_encodeSnappyBetterBlockAsm64K + +three_bytes_match_emit_encodeSnappyBetterBlockAsm64K: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R5, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_match_emit_encodeSnappyBetterBlockAsm64K + +two_bytes_match_emit_encodeSnappyBetterBlockAsm64K: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R5, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R5 + BLO memmove_match_emit_encodeSnappyBetterBlockAsm64K + JMP memmove_long_match_emit_encodeSnappyBetterBlockAsm64K + +one_byte_match_emit_encodeSnappyBetterBlockAsm64K: + LSLW $0x02, R5, R16 + BFI $0, R16, $8, R5 + MOVB R5, (R1) + ADD $0x01, R1, R1 + +memmove_match_emit_encodeSnappyBetterBlockAsm64K: + ADD R8, R1, R5 + + // genMemMoveShort + CMP $0x08, R8 + BLS emit_lit_memmove_match_emit_encodeSnappyBetterBlockAsm64K_memmove_move_8 + CMP $0x10, R8 + BLS emit_lit_memmove_match_emit_encodeSnappyBetterBlockAsm64K_memmove_move_8through16 + CMP $0x20, R8 + BLS emit_lit_memmove_match_emit_encodeSnappyBetterBlockAsm64K_memmove_move_17through32 + JMP emit_lit_memmove_match_emit_encodeSnappyBetterBlockAsm64K_memmove_move_33through64 + +emit_lit_memmove_match_emit_encodeSnappyBetterBlockAsm64K_memmove_move_8: + MOVD (R9), R10 + MOVD R10, (R1) + JMP memmove_end_copy_match_emit_encodeSnappyBetterBlockAsm64K + +emit_lit_memmove_match_emit_encodeSnappyBetterBlockAsm64K_memmove_move_8through16: + MOVD (R9), R10 + ADD R8, R9, R15 + MOVD -8(R15), R9 + MOVD R10, (R1) + ADD R8, R1, R15 + MOVD R9, -8(R15) + JMP memmove_end_copy_match_emit_encodeSnappyBetterBlockAsm64K + +emit_lit_memmove_match_emit_encodeSnappyBetterBlockAsm64K_memmove_move_17through32: + FMOVQ (R9), F0 + ADD R8, R9, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_match_emit_encodeSnappyBetterBlockAsm64K + +emit_lit_memmove_match_emit_encodeSnappyBetterBlockAsm64K_memmove_move_33through64: + FMOVQ (R9), F0 + FMOVQ 16(R9), F1 + ADD R8, R9, R15 + FMOVQ -32(R15), F2 + ADD R8, R9, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R8, R1, R15 + FMOVQ F2, -32(R15) + ADD R8, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_match_emit_encodeSnappyBetterBlockAsm64K: + MOVD R5, R1 + JMP emit_literal_done_match_emit_encodeSnappyBetterBlockAsm64K + +memmove_long_match_emit_encodeSnappyBetterBlockAsm64K: + ADD R8, R1, R5 + + // genMemMoveLong + MOVD R9, R10 + MOVD R1, R12 + MOVD R8, R13 + +emit_lit_memmove_long_match_emit_encodeSnappyBetterBlockAsm64Klarge_big_loop_back: + FMOVQ (R10), F0 + FMOVQ 16(R10), F1 + FMOVQ F0, (R12) + FMOVQ F1, 16(R12) + ADD $0x20, R10, R10 + ADD $0x20, R12, R12 + SUB $0x20, R13, R13 + CMP $0x20, R13 + BHS emit_lit_memmove_long_match_emit_encodeSnappyBetterBlockAsm64Klarge_big_loop_back + ADD R8, R9, R15 + FMOVQ -32(R15), F0 + ADD R8, R9, R15 + FMOVQ -16(R15), F1 + ADD R8, R1, R15 + FMOVQ F0, -32(R15) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + MOVD R5, R1 + +emit_literal_done_match_emit_encodeSnappyBetterBlockAsm64K: + ADDW R11, R2, R2 + ADDW $0x04, R11, R11 + MOVW R2, 20(RSP) + + // emitCopy +two_byte_offset_match_nolit_encodeSnappyBetterBlockAsm64K: + CMPW $0x40, R11 + BLS two_byte_offset_short_match_nolit_encodeSnappyBetterBlockAsm64K + MOVD $0xee, R16 + MOVB R16, (R1) + MOVH R7, 1(R1) + SUB $60, R11, R11 + MOVWU R11, R11 + ADD $0x03, R1, R1 + JMP two_byte_offset_match_nolit_encodeSnappyBetterBlockAsm64K + +two_byte_offset_short_match_nolit_encodeSnappyBetterBlockAsm64K: + MOVWU R11, R5 + LSLW $0x02, R5, R5 + CMPW $0x0c, R11 + BHS emit_copy_three_match_nolit_encodeSnappyBetterBlockAsm64K + CMPW $0x00000800, R7 + BHS emit_copy_three_match_nolit_encodeSnappyBetterBlockAsm64K + SUB $15, R5, R5 + MOVWU R5, R5 + MOVB R7, 1(R1) + LSRW $0x08, R7, R7 + LSLW $0x05, R7, R7 + ORRW R7, R5, R5 + MOVB R5, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeSnappyBetterBlockAsm64K + +emit_copy_three_match_nolit_encodeSnappyBetterBlockAsm64K: + SUB $2, R5, R5 + MOVWU R5, R5 + MOVB R5, (R1) + MOVH R7, 1(R1) + ADD $0x03, R1, R1 + +match_nolit_emitcopy_end_encodeSnappyBetterBlockAsm64K: + MOVWU 16(RSP), R16 + CMPW R16, R2 + BHS emit_remainder_encodeSnappyBetterBlockAsm64K + MOVD 8(RSP), R16 + CMP R16, R1 + BLO match_nolit_dst_ok_encodeSnappyBetterBlockAsm64K + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +match_nolit_dst_ok_encodeSnappyBetterBlockAsm64K: + MOVD $0x00cf1bbcdcbfa563, R5 + MOVD $0x9e3779b1, R7 + ADD $1, R6, R6 + SUB $2, R2, R8 + MOVD (R3)(R6), R9 + ADD R6, R3, R15 + MOVD 1(R15), R10 + MOVD (R3)(R8), R11 + ADD R8, R3, R15 + MOVD 1(R15), R12 + LSL $0x08, R9, R9 + MUL R5, R9, R9 + LSR $0x30, R9, R9 + LSL $0x20, R10, R10 + MUL R7, R10, R10 + LSR $0x33, R10, R10 + LSL $0x08, R11, R11 + MUL R5, R11, R11 + LSR $0x30, R11, R11 + LSL $0x20, R12, R12 + MUL R7, R12, R12 + LSR $0x33, R12, R12 + ADD $1, R6, R7 + ADD $1, R8, R13 + MOVW R6, (R0)(R9<<2) + MOVW R8, (R0)(R11<<2) + ADD R10<<2, R0, R15 + MOVW R7, 262144(R15) + ADD R12<<2, R0, R15 + MOVW R13, 262144(R15) + ADD R6, R8, R7 + ADD $1, R7, R7 + LSR $0x01, R7, R7 + ADD $0x01, R6, R6 + SUB $0x01, R8, R8 + +index_loop_encodeSnappyBetterBlockAsm64K: + CMP R8, R7 + BHS search_loop_encodeSnappyBetterBlockAsm64K + MOVD (R3)(R6), R9 + MOVD (R3)(R7), R10 + LSL $0x08, R9, R9 + MUL R5, R9, R9 + LSR $0x30, R9, R9 + LSL $0x08, R10, R10 + MUL R5, R10, R10 + LSR $0x30, R10, R10 + MOVW R6, (R0)(R9<<2) + MOVW R7, (R0)(R10<<2) + ADD $0x02, R6, R6 + ADD $0x02, R7, R7 + JMP index_loop_encodeSnappyBetterBlockAsm64K + +emit_remainder_encodeSnappyBetterBlockAsm64K: + MOVD src_len+32(FP), R0 + MOVWU 20(RSP), R16 + SUBW R16, R0, R0 + ADD R0, R1, R0 + ADD $3, R0, R0 + MOVD 8(RSP), R16 + CMP R16, R0 + BLO emit_remainder_ok_encodeSnappyBetterBlockAsm64K + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +emit_remainder_ok_encodeSnappyBetterBlockAsm64K: + MOVD src_len+32(FP), R0 + MOVWU 20(RSP), R2 + CMPW R0, R2 + BEQ emit_literal_done_emit_remainder_encodeSnappyBetterBlockAsm64K + MOVWU R0, R5 + MOVW R0, 20(RSP) + ADD R2, R3, R0 + SUBW R2, R5, R5 + SUB $1, R5, R2 + MOVWU R2, R2 + CMPW $0x3c, R2 + BLO one_byte_emit_remainder_encodeSnappyBetterBlockAsm64K + CMPW $0x00000100, R2 + BLO two_bytes_emit_remainder_encodeSnappyBetterBlockAsm64K + BLO three_bytes_emit_remainder_encodeSnappyBetterBlockAsm64K + +three_bytes_emit_remainder_encodeSnappyBetterBlockAsm64K: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R2, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_emit_remainder_encodeSnappyBetterBlockAsm64K + +two_bytes_emit_remainder_encodeSnappyBetterBlockAsm64K: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R2, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R2 + BLO memmove_emit_remainder_encodeSnappyBetterBlockAsm64K + JMP memmove_long_emit_remainder_encodeSnappyBetterBlockAsm64K + +one_byte_emit_remainder_encodeSnappyBetterBlockAsm64K: + LSLW $0x02, R2, R16 + BFI $0, R16, $8, R2 + MOVB R2, (R1) + ADD $0x01, R1, R1 + +memmove_emit_remainder_encodeSnappyBetterBlockAsm64K: + ADD R5, R1, R2 + MOVWU R5, R3 + + // genMemMoveShort + CMP $0x03, R3 + BLO emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm64K_memmove_move_1or2 + BEQ emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm64K_memmove_move_3 + CMP $0x08, R3 + BLO emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm64K_memmove_move_4through7 + CMP $0x10, R3 + BLS emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm64K_memmove_move_8through16 + CMP $0x20, R3 + BLS emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm64K_memmove_move_17through32 + JMP emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm64K_memmove_move_33through64 + +emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm64K_memmove_move_1or2: + MOVBU (R0), R16 + BFI $0, R16, $8, R5 + ADD R3, R0, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R0 + MOVB R5, (R1) + ADD R3, R1, R15 + MOVB R0, -1(R15) + JMP memmove_end_copy_emit_remainder_encodeSnappyBetterBlockAsm64K + +emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm64K_memmove_move_3: + MOVHU (R0), R16 + BFI $0, R16, $16, R5 + MOVBU 2(R0), R16 + BFI $0, R16, $8, R0 + MOVH R5, (R1) + MOVB R0, 2(R1) + JMP memmove_end_copy_emit_remainder_encodeSnappyBetterBlockAsm64K + +emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm64K_memmove_move_4through7: + MOVWU (R0), R5 + ADD R3, R0, R15 + MOVWU -4(R15), R0 + MOVW R5, (R1) + ADD R3, R1, R15 + MOVW R0, -4(R15) + JMP memmove_end_copy_emit_remainder_encodeSnappyBetterBlockAsm64K + +emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm64K_memmove_move_8through16: + MOVD (R0), R5 + ADD R3, R0, R15 + MOVD -8(R15), R0 + MOVD R5, (R1) + ADD R3, R1, R15 + MOVD R0, -8(R15) + JMP memmove_end_copy_emit_remainder_encodeSnappyBetterBlockAsm64K + +emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm64K_memmove_move_17through32: + FMOVQ (R0), F0 + ADD R3, R0, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R3, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_emit_remainder_encodeSnappyBetterBlockAsm64K + +emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm64K_memmove_move_33through64: + FMOVQ (R0), F0 + FMOVQ 16(R0), F1 + ADD R3, R0, R15 + FMOVQ -32(R15), F2 + ADD R3, R0, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R3, R1, R15 + FMOVQ F2, -32(R15) + ADD R3, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_emit_remainder_encodeSnappyBetterBlockAsm64K: + MOVD R2, R1 + JMP emit_literal_done_emit_remainder_encodeSnappyBetterBlockAsm64K + +memmove_long_emit_remainder_encodeSnappyBetterBlockAsm64K: + ADD R5, R1, R2 + MOVWU R5, R3 + + // genMemMoveLong + MOVD R0, R5 + MOVD R1, R6 + MOVD R3, R7 + +emit_lit_memmove_long_emit_remainder_encodeSnappyBetterBlockAsm64Klarge_big_loop_back: + FMOVQ (R5), F0 + FMOVQ 16(R5), F1 + FMOVQ F0, (R6) + FMOVQ F1, 16(R6) + ADD $0x20, R5, R5 + ADD $0x20, R6, R6 + SUB $0x20, R7, R7 + CMP $0x20, R7 + BHS emit_lit_memmove_long_emit_remainder_encodeSnappyBetterBlockAsm64Klarge_big_loop_back + ADD R3, R0, R15 + FMOVQ -32(R15), F0 + ADD R3, R0, R15 + FMOVQ -16(R15), F1 + ADD R3, R1, R15 + FMOVQ F0, -32(R15) + ADD R3, R1, R15 + FMOVQ F1, -16(R15) + MOVD R2, R1 + +emit_literal_done_emit_remainder_encodeSnappyBetterBlockAsm64K: + MOVD dst_base+0(FP), R0 + SUB R0, R1, R1 + MOVD R1, ret+56(FP) + RET + +// func encodeSnappyBetterBlockAsm12B(dst []byte, src []byte, tmp *[81920]byte) int +// Requires: BMI, SSE2 +TEXT ·encodeSnappyBetterBlockAsm12B(SB), $24-64 + MOVD tmp+48(FP), R0 + MOVD dst_base+0(FP), R1 + MOVD $0x00000280, R2 + MOVD R0, R3 + VEOR V0.B16, V0.B16, V0.B16 + +zero_loop_encodeSnappyBetterBlockAsm12B: + FMOVQ F0, (R3) + FMOVQ F0, 16(R3) + FMOVQ F0, 32(R3) + FMOVQ F0, 48(R3) + FMOVQ F0, 64(R3) + FMOVQ F0, 80(R3) + FMOVQ F0, 96(R3) + FMOVQ F0, 112(R3) + ADD $0x80, R3, R3 + SUBS $1, R2, R2 + BNE zero_loop_encodeSnappyBetterBlockAsm12B + MOVD $0x00000000, R16 + MOVW R16, 20(RSP) + MOVD src_len+32(FP), R2 + SUB $9, R2, R3 + SUB $8, R2, R5 + MOVW R5, 16(RSP) + LSR $0x05, R2, R2 + SUBW R2, R3, R3 + ADD R3, R1, R3 + MOVD R3, 8(RSP) + MOVD $0x00000001, R2 + MOVD $0x00000000, R16 + MOVW R16, 24(RSP) + MOVD src_base+24(FP), R3 + +search_loop_encodeSnappyBetterBlockAsm12B: + MOVWU R2, R5 + MOVWU 20(RSP), R16 + SUBW R16, R5, R5 + LSRW $0x06, R5, R5 + ADD R5, R2, R5 + ADD $1, R5, R5 + MOVWU R5, R5 + MOVWU 16(RSP), R16 + CMPW R16, R5 + BHS emit_remainder_encodeSnappyBetterBlockAsm12B + MOVD (R3)(R2), R6 + MOVW R5, 28(RSP) + MOVD $0x0000cf1bbcdcbf9b, R8 + MOVD $0x9e3779b1, R5 + MOVD R6, R9 + MOVD R6, R10 + LSL $0x10, R9, R9 + MUL R8, R9, R9 + LSR $0x32, R9, R9 + LSL $0x20, R10, R10 + MUL R5, R10, R10 + LSR $0x34, R10, R10 + MOVWU (R0)(R9<<2), R5 + ADD R10<<2, R0, R15 + MOVWU 65536(R15), R7 + MOVW R2, (R0)(R9<<2) + ADD R10<<2, R0, R15 + MOVW R2, 65536(R15) + MOVD (R3)(R5), R9 + MOVD (R3)(R7), R10 + CMP R6, R9 + BEQ candidate_match_encodeSnappyBetterBlockAsm12B + CMP R6, R10 + BNE no_short_found_encodeSnappyBetterBlockAsm12B + MOVWU R7, R5 + JMP candidate_match_encodeSnappyBetterBlockAsm12B + +no_short_found_encodeSnappyBetterBlockAsm12B: + CMPW R6, R9 + BEQ candidate_match_encodeSnappyBetterBlockAsm12B + CMPW R6, R10 + BEQ candidateS_match_encodeSnappyBetterBlockAsm12B + MOVWU 28(RSP), R2 + JMP search_loop_encodeSnappyBetterBlockAsm12B + +candidateS_match_encodeSnappyBetterBlockAsm12B: + LSR $0x08, R6, R6 + MOVD R6, R9 + LSL $0x10, R9, R9 + MUL R8, R9, R9 + LSR $0x32, R9, R9 + MOVWU (R0)(R9<<2), R5 + ADDW $1, R2, R2 + MOVW R2, (R0)(R9<<2) + MOVWU (R3)(R5), R16 + CMPW R6, R16 + BEQ candidate_match_encodeSnappyBetterBlockAsm12B + SUBW $1, R2, R2 + MOVWU R7, R5 + +candidate_match_encodeSnappyBetterBlockAsm12B: + MOVWU 20(RSP), R6 + TSTW R5, R5 + BEQ match_extend_back_end_encodeSnappyBetterBlockAsm12B + +match_extend_back_loop_encodeSnappyBetterBlockAsm12B: + CMPW R6, R2 + BLS match_extend_back_end_encodeSnappyBetterBlockAsm12B + ADD R5, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R7 + ADD R2, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R8 + AND $0xff, R8, R16 + AND $0xff, R7, R15 + CMP R16, R15 + BNE match_extend_back_end_encodeSnappyBetterBlockAsm12B + SUB $1, R2, R2 + MOVWU R2, R2 + SUBSW $1, R5, R5 + BEQ match_extend_back_end_encodeSnappyBetterBlockAsm12B + JMP match_extend_back_loop_encodeSnappyBetterBlockAsm12B + +match_extend_back_end_encodeSnappyBetterBlockAsm12B: + MOVWU R2, R6 + MOVWU 20(RSP), R16 + SUBW R16, R6, R6 + ADD R6, R1, R6 + ADD $3, R6, R6 + MOVD 8(RSP), R16 + CMP R16, R6 + BLO match_dst_size_check_encodeSnappyBetterBlockAsm12B + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +match_dst_size_check_encodeSnappyBetterBlockAsm12B: + MOVWU R2, R6 + ADDW $0x04, R2, R2 + ADDW $0x04, R5, R5 + MOVD src_len+32(FP), R7 + SUBW R2, R7, R7 + ADD R2, R3, R8 + ADD R5, R3, R9 + + // matchLen + MOVD $0, R11 + +matchlen_loopback_16_match_nolit_encodeSnappyBetterBlockAsm12B: + CMPW $0x10, R7 + BLO matchlen_match8_match_nolit_encodeSnappyBetterBlockAsm12B + MOVD (R8)(R11), R10 + ADD R11, R8, R15 + MOVD 8(R15), R12 + MOVD (R9)(R11), R16 + EOR R16, R10, R10 + TST R10, R10 + BNE matchlen_bsf_8_match_nolit_encodeSnappyBetterBlockAsm12B + ADD R11, R9, R15 + MOVD 8(R15), R16 + EOR R16, R12, R12 + TST R12, R12 + BNE matchlen_bsf_16match_nolit_encodeSnappyBetterBlockAsm12B + SUB $16, R7, R7 + MOVWU R7, R7 + ADD $16, R11, R11 + MOVWU R11, R11 + JMP matchlen_loopback_16_match_nolit_encodeSnappyBetterBlockAsm12B + +matchlen_bsf_16match_nolit_encodeSnappyBetterBlockAsm12B: + RBIT R12, R12 + CLZ R12, R12 + ASR $0x03, R12, R12 + ADD R12, R11, R11 + ADD $8, R11, R11 + MOVWU R11, R11 + JMP match_nolit_end_encodeSnappyBetterBlockAsm12B + +matchlen_match8_match_nolit_encodeSnappyBetterBlockAsm12B: + CMPW $0x08, R7 + BLO matchlen_match4_match_nolit_encodeSnappyBetterBlockAsm12B + MOVD (R8)(R11), R10 + MOVD (R9)(R11), R16 + EOR R16, R10, R10 + TST R10, R10 + BNE matchlen_bsf_8_match_nolit_encodeSnappyBetterBlockAsm12B + SUB $8, R7, R7 + MOVWU R7, R7 + ADD $8, R11, R11 + MOVWU R11, R11 + JMP matchlen_match4_match_nolit_encodeSnappyBetterBlockAsm12B + +matchlen_bsf_8_match_nolit_encodeSnappyBetterBlockAsm12B: + RBIT R10, R10 + CLZ R10, R10 + ASR $0x03, R10, R10 + ADD R10, R11, R11 + MOVWU R11, R11 + JMP match_nolit_end_encodeSnappyBetterBlockAsm12B + +matchlen_match4_match_nolit_encodeSnappyBetterBlockAsm12B: + CMPW $0x04, R7 + BLO matchlen_match2_match_nolit_encodeSnappyBetterBlockAsm12B + MOVWU (R8)(R11), R10 + MOVWU (R9)(R11), R16 + CMPW R10, R16 + BNE matchlen_match2_match_nolit_encodeSnappyBetterBlockAsm12B + SUB $4, R7, R7 + MOVWU R7, R7 + ADD $4, R11, R11 + MOVWU R11, R11 + +matchlen_match2_match_nolit_encodeSnappyBetterBlockAsm12B: + CMPW $0x01, R7 + BEQ matchlen_match1_match_nolit_encodeSnappyBetterBlockAsm12B + BLO match_nolit_end_encodeSnappyBetterBlockAsm12B + MOVHU (R8)(R11), R16 + BFI $0, R16, $16, R10 + ADD R11, R9, R15 + MOVHU (R15), R15 + AND $0xffff, R10, R16 + CMP R16, R15 + BNE matchlen_match1_match_nolit_encodeSnappyBetterBlockAsm12B + ADD $2, R11, R11 + MOVWU R11, R11 + SUBSW $0x02, R7, R7 + BEQ match_nolit_end_encodeSnappyBetterBlockAsm12B + +matchlen_match1_match_nolit_encodeSnappyBetterBlockAsm12B: + MOVBU (R8)(R11), R16 + BFI $0, R16, $8, R10 + ADD R11, R9, R15 + MOVBU (R15), R15 + AND $0xff, R10, R16 + CMP R16, R15 + BNE match_nolit_end_encodeSnappyBetterBlockAsm12B + ADD $1, R11, R11 + MOVWU R11, R11 + +match_nolit_end_encodeSnappyBetterBlockAsm12B: + MOVWU R2, R7 + SUBW R5, R7, R7 + + // Check if repeat + MOVW R7, 24(RSP) + MOVWU 20(RSP), R5 + CMPW R6, R5 + BEQ emit_literal_done_match_emit_encodeSnappyBetterBlockAsm12B + MOVWU R6, R8 + MOVW R6, 20(RSP) + ADD R5, R3, R9 + SUBW R5, R8, R8 + SUB $1, R8, R5 + MOVWU R5, R5 + CMPW $0x3c, R5 + BLO one_byte_match_emit_encodeSnappyBetterBlockAsm12B + CMPW $0x00000100, R5 + BLO two_bytes_match_emit_encodeSnappyBetterBlockAsm12B + BLO three_bytes_match_emit_encodeSnappyBetterBlockAsm12B + +three_bytes_match_emit_encodeSnappyBetterBlockAsm12B: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R5, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_match_emit_encodeSnappyBetterBlockAsm12B + +two_bytes_match_emit_encodeSnappyBetterBlockAsm12B: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R5, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R5 + BLO memmove_match_emit_encodeSnappyBetterBlockAsm12B + JMP memmove_long_match_emit_encodeSnappyBetterBlockAsm12B + +one_byte_match_emit_encodeSnappyBetterBlockAsm12B: + LSLW $0x02, R5, R16 + BFI $0, R16, $8, R5 + MOVB R5, (R1) + ADD $0x01, R1, R1 + +memmove_match_emit_encodeSnappyBetterBlockAsm12B: + ADD R8, R1, R5 + + // genMemMoveShort + CMP $0x08, R8 + BLS emit_lit_memmove_match_emit_encodeSnappyBetterBlockAsm12B_memmove_move_8 + CMP $0x10, R8 + BLS emit_lit_memmove_match_emit_encodeSnappyBetterBlockAsm12B_memmove_move_8through16 + CMP $0x20, R8 + BLS emit_lit_memmove_match_emit_encodeSnappyBetterBlockAsm12B_memmove_move_17through32 + JMP emit_lit_memmove_match_emit_encodeSnappyBetterBlockAsm12B_memmove_move_33through64 + +emit_lit_memmove_match_emit_encodeSnappyBetterBlockAsm12B_memmove_move_8: + MOVD (R9), R10 + MOVD R10, (R1) + JMP memmove_end_copy_match_emit_encodeSnappyBetterBlockAsm12B + +emit_lit_memmove_match_emit_encodeSnappyBetterBlockAsm12B_memmove_move_8through16: + MOVD (R9), R10 + ADD R8, R9, R15 + MOVD -8(R15), R9 + MOVD R10, (R1) + ADD R8, R1, R15 + MOVD R9, -8(R15) + JMP memmove_end_copy_match_emit_encodeSnappyBetterBlockAsm12B + +emit_lit_memmove_match_emit_encodeSnappyBetterBlockAsm12B_memmove_move_17through32: + FMOVQ (R9), F0 + ADD R8, R9, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_match_emit_encodeSnappyBetterBlockAsm12B + +emit_lit_memmove_match_emit_encodeSnappyBetterBlockAsm12B_memmove_move_33through64: + FMOVQ (R9), F0 + FMOVQ 16(R9), F1 + ADD R8, R9, R15 + FMOVQ -32(R15), F2 + ADD R8, R9, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R8, R1, R15 + FMOVQ F2, -32(R15) + ADD R8, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_match_emit_encodeSnappyBetterBlockAsm12B: + MOVD R5, R1 + JMP emit_literal_done_match_emit_encodeSnappyBetterBlockAsm12B + +memmove_long_match_emit_encodeSnappyBetterBlockAsm12B: + ADD R8, R1, R5 + + // genMemMoveLong + MOVD R9, R10 + MOVD R1, R12 + MOVD R8, R13 + +emit_lit_memmove_long_match_emit_encodeSnappyBetterBlockAsm12Blarge_big_loop_back: + FMOVQ (R10), F0 + FMOVQ 16(R10), F1 + FMOVQ F0, (R12) + FMOVQ F1, 16(R12) + ADD $0x20, R10, R10 + ADD $0x20, R12, R12 + SUB $0x20, R13, R13 + CMP $0x20, R13 + BHS emit_lit_memmove_long_match_emit_encodeSnappyBetterBlockAsm12Blarge_big_loop_back + ADD R8, R9, R15 + FMOVQ -32(R15), F0 + ADD R8, R9, R15 + FMOVQ -16(R15), F1 + ADD R8, R1, R15 + FMOVQ F0, -32(R15) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + MOVD R5, R1 + +emit_literal_done_match_emit_encodeSnappyBetterBlockAsm12B: + ADDW R11, R2, R2 + ADDW $0x04, R11, R11 + MOVW R2, 20(RSP) + + // emitCopy +two_byte_offset_match_nolit_encodeSnappyBetterBlockAsm12B: + CMPW $0x40, R11 + BLS two_byte_offset_short_match_nolit_encodeSnappyBetterBlockAsm12B + MOVD $0xee, R16 + MOVB R16, (R1) + MOVH R7, 1(R1) + SUB $60, R11, R11 + MOVWU R11, R11 + ADD $0x03, R1, R1 + JMP two_byte_offset_match_nolit_encodeSnappyBetterBlockAsm12B + +two_byte_offset_short_match_nolit_encodeSnappyBetterBlockAsm12B: + MOVWU R11, R5 + LSLW $0x02, R5, R5 + CMPW $0x0c, R11 + BHS emit_copy_three_match_nolit_encodeSnappyBetterBlockAsm12B + CMPW $0x00000800, R7 + BHS emit_copy_three_match_nolit_encodeSnappyBetterBlockAsm12B + SUB $15, R5, R5 + MOVWU R5, R5 + MOVB R7, 1(R1) + LSRW $0x08, R7, R7 + LSLW $0x05, R7, R7 + ORRW R7, R5, R5 + MOVB R5, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeSnappyBetterBlockAsm12B + +emit_copy_three_match_nolit_encodeSnappyBetterBlockAsm12B: + SUB $2, R5, R5 + MOVWU R5, R5 + MOVB R5, (R1) + MOVH R7, 1(R1) + ADD $0x03, R1, R1 + +match_nolit_emitcopy_end_encodeSnappyBetterBlockAsm12B: + MOVWU 16(RSP), R16 + CMPW R16, R2 + BHS emit_remainder_encodeSnappyBetterBlockAsm12B + MOVD 8(RSP), R16 + CMP R16, R1 + BLO match_nolit_dst_ok_encodeSnappyBetterBlockAsm12B + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +match_nolit_dst_ok_encodeSnappyBetterBlockAsm12B: + MOVD $0x0000cf1bbcdcbf9b, R5 + MOVD $0x9e3779b1, R7 + ADD $1, R6, R6 + SUB $2, R2, R8 + MOVD (R3)(R6), R9 + ADD R6, R3, R15 + MOVD 1(R15), R10 + MOVD (R3)(R8), R11 + ADD R8, R3, R15 + MOVD 1(R15), R12 + LSL $0x10, R9, R9 + MUL R5, R9, R9 + LSR $0x32, R9, R9 + LSL $0x20, R10, R10 + MUL R7, R10, R10 + LSR $0x34, R10, R10 + LSL $0x10, R11, R11 + MUL R5, R11, R11 + LSR $0x32, R11, R11 + LSL $0x20, R12, R12 + MUL R7, R12, R12 + LSR $0x34, R12, R12 + ADD $1, R6, R7 + ADD $1, R8, R13 + MOVW R6, (R0)(R9<<2) + MOVW R8, (R0)(R11<<2) + ADD R10<<2, R0, R15 + MOVW R7, 65536(R15) + ADD R12<<2, R0, R15 + MOVW R13, 65536(R15) + ADD R6, R8, R7 + ADD $1, R7, R7 + LSR $0x01, R7, R7 + ADD $0x01, R6, R6 + SUB $0x01, R8, R8 + +index_loop_encodeSnappyBetterBlockAsm12B: + CMP R8, R7 + BHS search_loop_encodeSnappyBetterBlockAsm12B + MOVD (R3)(R6), R9 + MOVD (R3)(R7), R10 + LSL $0x10, R9, R9 + MUL R5, R9, R9 + LSR $0x32, R9, R9 + LSL $0x10, R10, R10 + MUL R5, R10, R10 + LSR $0x32, R10, R10 + MOVW R6, (R0)(R9<<2) + MOVW R7, (R0)(R10<<2) + ADD $0x02, R6, R6 + ADD $0x02, R7, R7 + JMP index_loop_encodeSnappyBetterBlockAsm12B + +emit_remainder_encodeSnappyBetterBlockAsm12B: + MOVD src_len+32(FP), R0 + MOVWU 20(RSP), R16 + SUBW R16, R0, R0 + ADD R0, R1, R0 + ADD $3, R0, R0 + MOVD 8(RSP), R16 + CMP R16, R0 + BLO emit_remainder_ok_encodeSnappyBetterBlockAsm12B + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +emit_remainder_ok_encodeSnappyBetterBlockAsm12B: + MOVD src_len+32(FP), R0 + MOVWU 20(RSP), R2 + CMPW R0, R2 + BEQ emit_literal_done_emit_remainder_encodeSnappyBetterBlockAsm12B + MOVWU R0, R5 + MOVW R0, 20(RSP) + ADD R2, R3, R0 + SUBW R2, R5, R5 + SUB $1, R5, R2 + MOVWU R2, R2 + CMPW $0x3c, R2 + BLO one_byte_emit_remainder_encodeSnappyBetterBlockAsm12B + CMPW $0x00000100, R2 + BLO two_bytes_emit_remainder_encodeSnappyBetterBlockAsm12B + BLO three_bytes_emit_remainder_encodeSnappyBetterBlockAsm12B + +three_bytes_emit_remainder_encodeSnappyBetterBlockAsm12B: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R2, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_emit_remainder_encodeSnappyBetterBlockAsm12B + +two_bytes_emit_remainder_encodeSnappyBetterBlockAsm12B: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R2, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R2 + BLO memmove_emit_remainder_encodeSnappyBetterBlockAsm12B + JMP memmove_long_emit_remainder_encodeSnappyBetterBlockAsm12B + +one_byte_emit_remainder_encodeSnappyBetterBlockAsm12B: + LSLW $0x02, R2, R16 + BFI $0, R16, $8, R2 + MOVB R2, (R1) + ADD $0x01, R1, R1 + +memmove_emit_remainder_encodeSnappyBetterBlockAsm12B: + ADD R5, R1, R2 + MOVWU R5, R3 + + // genMemMoveShort + CMP $0x03, R3 + BLO emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm12B_memmove_move_1or2 + BEQ emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm12B_memmove_move_3 + CMP $0x08, R3 + BLO emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm12B_memmove_move_4through7 + CMP $0x10, R3 + BLS emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm12B_memmove_move_8through16 + CMP $0x20, R3 + BLS emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm12B_memmove_move_17through32 + JMP emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm12B_memmove_move_33through64 + +emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm12B_memmove_move_1or2: + MOVBU (R0), R16 + BFI $0, R16, $8, R5 + ADD R3, R0, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R0 + MOVB R5, (R1) + ADD R3, R1, R15 + MOVB R0, -1(R15) + JMP memmove_end_copy_emit_remainder_encodeSnappyBetterBlockAsm12B + +emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm12B_memmove_move_3: + MOVHU (R0), R16 + BFI $0, R16, $16, R5 + MOVBU 2(R0), R16 + BFI $0, R16, $8, R0 + MOVH R5, (R1) + MOVB R0, 2(R1) + JMP memmove_end_copy_emit_remainder_encodeSnappyBetterBlockAsm12B + +emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm12B_memmove_move_4through7: + MOVWU (R0), R5 + ADD R3, R0, R15 + MOVWU -4(R15), R0 + MOVW R5, (R1) + ADD R3, R1, R15 + MOVW R0, -4(R15) + JMP memmove_end_copy_emit_remainder_encodeSnappyBetterBlockAsm12B + +emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm12B_memmove_move_8through16: + MOVD (R0), R5 + ADD R3, R0, R15 + MOVD -8(R15), R0 + MOVD R5, (R1) + ADD R3, R1, R15 + MOVD R0, -8(R15) + JMP memmove_end_copy_emit_remainder_encodeSnappyBetterBlockAsm12B + +emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm12B_memmove_move_17through32: + FMOVQ (R0), F0 + ADD R3, R0, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R3, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_emit_remainder_encodeSnappyBetterBlockAsm12B + +emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm12B_memmove_move_33through64: + FMOVQ (R0), F0 + FMOVQ 16(R0), F1 + ADD R3, R0, R15 + FMOVQ -32(R15), F2 + ADD R3, R0, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R3, R1, R15 + FMOVQ F2, -32(R15) + ADD R3, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_emit_remainder_encodeSnappyBetterBlockAsm12B: + MOVD R2, R1 + JMP emit_literal_done_emit_remainder_encodeSnappyBetterBlockAsm12B + +memmove_long_emit_remainder_encodeSnappyBetterBlockAsm12B: + ADD R5, R1, R2 + MOVWU R5, R3 + + // genMemMoveLong + MOVD R0, R5 + MOVD R1, R6 + MOVD R3, R7 + +emit_lit_memmove_long_emit_remainder_encodeSnappyBetterBlockAsm12Blarge_big_loop_back: + FMOVQ (R5), F0 + FMOVQ 16(R5), F1 + FMOVQ F0, (R6) + FMOVQ F1, 16(R6) + ADD $0x20, R5, R5 + ADD $0x20, R6, R6 + SUB $0x20, R7, R7 + CMP $0x20, R7 + BHS emit_lit_memmove_long_emit_remainder_encodeSnappyBetterBlockAsm12Blarge_big_loop_back + ADD R3, R0, R15 + FMOVQ -32(R15), F0 + ADD R3, R0, R15 + FMOVQ -16(R15), F1 + ADD R3, R1, R15 + FMOVQ F0, -32(R15) + ADD R3, R1, R15 + FMOVQ F1, -16(R15) + MOVD R2, R1 + +emit_literal_done_emit_remainder_encodeSnappyBetterBlockAsm12B: + MOVD dst_base+0(FP), R0 + SUB R0, R1, R1 + MOVD R1, ret+56(FP) + RET + +// func encodeSnappyBetterBlockAsm10B(dst []byte, src []byte, tmp *[20480]byte) int +// Requires: BMI, SSE2 +TEXT ·encodeSnappyBetterBlockAsm10B(SB), $24-64 + MOVD tmp+48(FP), R0 + MOVD dst_base+0(FP), R1 + MOVD $0x000000a0, R2 + MOVD R0, R3 + VEOR V0.B16, V0.B16, V0.B16 + +zero_loop_encodeSnappyBetterBlockAsm10B: + FMOVQ F0, (R3) + FMOVQ F0, 16(R3) + FMOVQ F0, 32(R3) + FMOVQ F0, 48(R3) + FMOVQ F0, 64(R3) + FMOVQ F0, 80(R3) + FMOVQ F0, 96(R3) + FMOVQ F0, 112(R3) + ADD $0x80, R3, R3 + SUBS $1, R2, R2 + BNE zero_loop_encodeSnappyBetterBlockAsm10B + MOVD $0x00000000, R16 + MOVW R16, 20(RSP) + MOVD src_len+32(FP), R2 + SUB $9, R2, R3 + SUB $8, R2, R5 + MOVW R5, 16(RSP) + LSR $0x05, R2, R2 + SUBW R2, R3, R3 + ADD R3, R1, R3 + MOVD R3, 8(RSP) + MOVD $0x00000001, R2 + MOVD $0x00000000, R16 + MOVW R16, 24(RSP) + MOVD src_base+24(FP), R3 + +search_loop_encodeSnappyBetterBlockAsm10B: + MOVWU R2, R5 + MOVWU 20(RSP), R16 + SUBW R16, R5, R5 + LSRW $0x05, R5, R5 + ADD R5, R2, R5 + ADD $1, R5, R5 + MOVWU R5, R5 + MOVWU 16(RSP), R16 + CMPW R16, R5 + BHS emit_remainder_encodeSnappyBetterBlockAsm10B + MOVD (R3)(R2), R6 + MOVW R5, 28(RSP) + MOVD $0x0000cf1bbcdcbf9b, R8 + MOVD $0x9e3779b1, R5 + MOVD R6, R9 + MOVD R6, R10 + LSL $0x10, R9, R9 + MUL R8, R9, R9 + LSR $0x34, R9, R9 + LSL $0x20, R10, R10 + MUL R5, R10, R10 + LSR $0x36, R10, R10 + MOVWU (R0)(R9<<2), R5 + ADD R10<<2, R0, R15 + MOVWU 16384(R15), R7 + MOVW R2, (R0)(R9<<2) + ADD R10<<2, R0, R15 + MOVW R2, 16384(R15) + MOVD (R3)(R5), R9 + MOVD (R3)(R7), R10 + CMP R6, R9 + BEQ candidate_match_encodeSnappyBetterBlockAsm10B + CMP R6, R10 + BNE no_short_found_encodeSnappyBetterBlockAsm10B + MOVWU R7, R5 + JMP candidate_match_encodeSnappyBetterBlockAsm10B + +no_short_found_encodeSnappyBetterBlockAsm10B: + CMPW R6, R9 + BEQ candidate_match_encodeSnappyBetterBlockAsm10B + CMPW R6, R10 + BEQ candidateS_match_encodeSnappyBetterBlockAsm10B + MOVWU 28(RSP), R2 + JMP search_loop_encodeSnappyBetterBlockAsm10B + +candidateS_match_encodeSnappyBetterBlockAsm10B: + LSR $0x08, R6, R6 + MOVD R6, R9 + LSL $0x10, R9, R9 + MUL R8, R9, R9 + LSR $0x34, R9, R9 + MOVWU (R0)(R9<<2), R5 + ADDW $1, R2, R2 + MOVW R2, (R0)(R9<<2) + MOVWU (R3)(R5), R16 + CMPW R6, R16 + BEQ candidate_match_encodeSnappyBetterBlockAsm10B + SUBW $1, R2, R2 + MOVWU R7, R5 + +candidate_match_encodeSnappyBetterBlockAsm10B: + MOVWU 20(RSP), R6 + TSTW R5, R5 + BEQ match_extend_back_end_encodeSnappyBetterBlockAsm10B + +match_extend_back_loop_encodeSnappyBetterBlockAsm10B: + CMPW R6, R2 + BLS match_extend_back_end_encodeSnappyBetterBlockAsm10B + ADD R5, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R7 + ADD R2, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R8 + AND $0xff, R8, R16 + AND $0xff, R7, R15 + CMP R16, R15 + BNE match_extend_back_end_encodeSnappyBetterBlockAsm10B + SUB $1, R2, R2 + MOVWU R2, R2 + SUBSW $1, R5, R5 + BEQ match_extend_back_end_encodeSnappyBetterBlockAsm10B + JMP match_extend_back_loop_encodeSnappyBetterBlockAsm10B + +match_extend_back_end_encodeSnappyBetterBlockAsm10B: + MOVWU R2, R6 + MOVWU 20(RSP), R16 + SUBW R16, R6, R6 + ADD R6, R1, R6 + ADD $3, R6, R6 + MOVD 8(RSP), R16 + CMP R16, R6 + BLO match_dst_size_check_encodeSnappyBetterBlockAsm10B + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +match_dst_size_check_encodeSnappyBetterBlockAsm10B: + MOVWU R2, R6 + ADDW $0x04, R2, R2 + ADDW $0x04, R5, R5 + MOVD src_len+32(FP), R7 + SUBW R2, R7, R7 + ADD R2, R3, R8 + ADD R5, R3, R9 + + // matchLen + MOVD $0, R11 + +matchlen_loopback_16_match_nolit_encodeSnappyBetterBlockAsm10B: + CMPW $0x10, R7 + BLO matchlen_match8_match_nolit_encodeSnappyBetterBlockAsm10B + MOVD (R8)(R11), R10 + ADD R11, R8, R15 + MOVD 8(R15), R12 + MOVD (R9)(R11), R16 + EOR R16, R10, R10 + TST R10, R10 + BNE matchlen_bsf_8_match_nolit_encodeSnappyBetterBlockAsm10B + ADD R11, R9, R15 + MOVD 8(R15), R16 + EOR R16, R12, R12 + TST R12, R12 + BNE matchlen_bsf_16match_nolit_encodeSnappyBetterBlockAsm10B + SUB $16, R7, R7 + MOVWU R7, R7 + ADD $16, R11, R11 + MOVWU R11, R11 + JMP matchlen_loopback_16_match_nolit_encodeSnappyBetterBlockAsm10B + +matchlen_bsf_16match_nolit_encodeSnappyBetterBlockAsm10B: + RBIT R12, R12 + CLZ R12, R12 + ASR $0x03, R12, R12 + ADD R12, R11, R11 + ADD $8, R11, R11 + MOVWU R11, R11 + JMP match_nolit_end_encodeSnappyBetterBlockAsm10B + +matchlen_match8_match_nolit_encodeSnappyBetterBlockAsm10B: + CMPW $0x08, R7 + BLO matchlen_match4_match_nolit_encodeSnappyBetterBlockAsm10B + MOVD (R8)(R11), R10 + MOVD (R9)(R11), R16 + EOR R16, R10, R10 + TST R10, R10 + BNE matchlen_bsf_8_match_nolit_encodeSnappyBetterBlockAsm10B + SUB $8, R7, R7 + MOVWU R7, R7 + ADD $8, R11, R11 + MOVWU R11, R11 + JMP matchlen_match4_match_nolit_encodeSnappyBetterBlockAsm10B + +matchlen_bsf_8_match_nolit_encodeSnappyBetterBlockAsm10B: + RBIT R10, R10 + CLZ R10, R10 + ASR $0x03, R10, R10 + ADD R10, R11, R11 + MOVWU R11, R11 + JMP match_nolit_end_encodeSnappyBetterBlockAsm10B + +matchlen_match4_match_nolit_encodeSnappyBetterBlockAsm10B: + CMPW $0x04, R7 + BLO matchlen_match2_match_nolit_encodeSnappyBetterBlockAsm10B + MOVWU (R8)(R11), R10 + MOVWU (R9)(R11), R16 + CMPW R10, R16 + BNE matchlen_match2_match_nolit_encodeSnappyBetterBlockAsm10B + SUB $4, R7, R7 + MOVWU R7, R7 + ADD $4, R11, R11 + MOVWU R11, R11 + +matchlen_match2_match_nolit_encodeSnappyBetterBlockAsm10B: + CMPW $0x01, R7 + BEQ matchlen_match1_match_nolit_encodeSnappyBetterBlockAsm10B + BLO match_nolit_end_encodeSnappyBetterBlockAsm10B + MOVHU (R8)(R11), R16 + BFI $0, R16, $16, R10 + ADD R11, R9, R15 + MOVHU (R15), R15 + AND $0xffff, R10, R16 + CMP R16, R15 + BNE matchlen_match1_match_nolit_encodeSnappyBetterBlockAsm10B + ADD $2, R11, R11 + MOVWU R11, R11 + SUBSW $0x02, R7, R7 + BEQ match_nolit_end_encodeSnappyBetterBlockAsm10B + +matchlen_match1_match_nolit_encodeSnappyBetterBlockAsm10B: + MOVBU (R8)(R11), R16 + BFI $0, R16, $8, R10 + ADD R11, R9, R15 + MOVBU (R15), R15 + AND $0xff, R10, R16 + CMP R16, R15 + BNE match_nolit_end_encodeSnappyBetterBlockAsm10B + ADD $1, R11, R11 + MOVWU R11, R11 + +match_nolit_end_encodeSnappyBetterBlockAsm10B: + MOVWU R2, R7 + SUBW R5, R7, R7 + + // Check if repeat + MOVW R7, 24(RSP) + MOVWU 20(RSP), R5 + CMPW R6, R5 + BEQ emit_literal_done_match_emit_encodeSnappyBetterBlockAsm10B + MOVWU R6, R8 + MOVW R6, 20(RSP) + ADD R5, R3, R9 + SUBW R5, R8, R8 + SUB $1, R8, R5 + MOVWU R5, R5 + CMPW $0x3c, R5 + BLO one_byte_match_emit_encodeSnappyBetterBlockAsm10B + CMPW $0x00000100, R5 + BLO two_bytes_match_emit_encodeSnappyBetterBlockAsm10B + BLO three_bytes_match_emit_encodeSnappyBetterBlockAsm10B + +three_bytes_match_emit_encodeSnappyBetterBlockAsm10B: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R5, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_match_emit_encodeSnappyBetterBlockAsm10B + +two_bytes_match_emit_encodeSnappyBetterBlockAsm10B: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R5, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R5 + BLO memmove_match_emit_encodeSnappyBetterBlockAsm10B + JMP memmove_long_match_emit_encodeSnappyBetterBlockAsm10B + +one_byte_match_emit_encodeSnappyBetterBlockAsm10B: + LSLW $0x02, R5, R16 + BFI $0, R16, $8, R5 + MOVB R5, (R1) + ADD $0x01, R1, R1 + +memmove_match_emit_encodeSnappyBetterBlockAsm10B: + ADD R8, R1, R5 + + // genMemMoveShort + CMP $0x08, R8 + BLS emit_lit_memmove_match_emit_encodeSnappyBetterBlockAsm10B_memmove_move_8 + CMP $0x10, R8 + BLS emit_lit_memmove_match_emit_encodeSnappyBetterBlockAsm10B_memmove_move_8through16 + CMP $0x20, R8 + BLS emit_lit_memmove_match_emit_encodeSnappyBetterBlockAsm10B_memmove_move_17through32 + JMP emit_lit_memmove_match_emit_encodeSnappyBetterBlockAsm10B_memmove_move_33through64 + +emit_lit_memmove_match_emit_encodeSnappyBetterBlockAsm10B_memmove_move_8: + MOVD (R9), R10 + MOVD R10, (R1) + JMP memmove_end_copy_match_emit_encodeSnappyBetterBlockAsm10B + +emit_lit_memmove_match_emit_encodeSnappyBetterBlockAsm10B_memmove_move_8through16: + MOVD (R9), R10 + ADD R8, R9, R15 + MOVD -8(R15), R9 + MOVD R10, (R1) + ADD R8, R1, R15 + MOVD R9, -8(R15) + JMP memmove_end_copy_match_emit_encodeSnappyBetterBlockAsm10B + +emit_lit_memmove_match_emit_encodeSnappyBetterBlockAsm10B_memmove_move_17through32: + FMOVQ (R9), F0 + ADD R8, R9, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_match_emit_encodeSnappyBetterBlockAsm10B + +emit_lit_memmove_match_emit_encodeSnappyBetterBlockAsm10B_memmove_move_33through64: + FMOVQ (R9), F0 + FMOVQ 16(R9), F1 + ADD R8, R9, R15 + FMOVQ -32(R15), F2 + ADD R8, R9, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R8, R1, R15 + FMOVQ F2, -32(R15) + ADD R8, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_match_emit_encodeSnappyBetterBlockAsm10B: + MOVD R5, R1 + JMP emit_literal_done_match_emit_encodeSnappyBetterBlockAsm10B + +memmove_long_match_emit_encodeSnappyBetterBlockAsm10B: + ADD R8, R1, R5 + + // genMemMoveLong + MOVD R9, R10 + MOVD R1, R12 + MOVD R8, R13 + +emit_lit_memmove_long_match_emit_encodeSnappyBetterBlockAsm10Blarge_big_loop_back: + FMOVQ (R10), F0 + FMOVQ 16(R10), F1 + FMOVQ F0, (R12) + FMOVQ F1, 16(R12) + ADD $0x20, R10, R10 + ADD $0x20, R12, R12 + SUB $0x20, R13, R13 + CMP $0x20, R13 + BHS emit_lit_memmove_long_match_emit_encodeSnappyBetterBlockAsm10Blarge_big_loop_back + ADD R8, R9, R15 + FMOVQ -32(R15), F0 + ADD R8, R9, R15 + FMOVQ -16(R15), F1 + ADD R8, R1, R15 + FMOVQ F0, -32(R15) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + MOVD R5, R1 + +emit_literal_done_match_emit_encodeSnappyBetterBlockAsm10B: + ADDW R11, R2, R2 + ADDW $0x04, R11, R11 + MOVW R2, 20(RSP) + + // emitCopy +two_byte_offset_match_nolit_encodeSnappyBetterBlockAsm10B: + CMPW $0x40, R11 + BLS two_byte_offset_short_match_nolit_encodeSnappyBetterBlockAsm10B + MOVD $0xee, R16 + MOVB R16, (R1) + MOVH R7, 1(R1) + SUB $60, R11, R11 + MOVWU R11, R11 + ADD $0x03, R1, R1 + JMP two_byte_offset_match_nolit_encodeSnappyBetterBlockAsm10B + +two_byte_offset_short_match_nolit_encodeSnappyBetterBlockAsm10B: + MOVWU R11, R5 + LSLW $0x02, R5, R5 + CMPW $0x0c, R11 + BHS emit_copy_three_match_nolit_encodeSnappyBetterBlockAsm10B + CMPW $0x00000800, R7 + BHS emit_copy_three_match_nolit_encodeSnappyBetterBlockAsm10B + SUB $15, R5, R5 + MOVWU R5, R5 + MOVB R7, 1(R1) + LSRW $0x08, R7, R7 + LSLW $0x05, R7, R7 + ORRW R7, R5, R5 + MOVB R5, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeSnappyBetterBlockAsm10B + +emit_copy_three_match_nolit_encodeSnappyBetterBlockAsm10B: + SUB $2, R5, R5 + MOVWU R5, R5 + MOVB R5, (R1) + MOVH R7, 1(R1) + ADD $0x03, R1, R1 + +match_nolit_emitcopy_end_encodeSnappyBetterBlockAsm10B: + MOVWU 16(RSP), R16 + CMPW R16, R2 + BHS emit_remainder_encodeSnappyBetterBlockAsm10B + MOVD 8(RSP), R16 + CMP R16, R1 + BLO match_nolit_dst_ok_encodeSnappyBetterBlockAsm10B + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +match_nolit_dst_ok_encodeSnappyBetterBlockAsm10B: + MOVD $0x0000cf1bbcdcbf9b, R5 + MOVD $0x9e3779b1, R7 + ADD $1, R6, R6 + SUB $2, R2, R8 + MOVD (R3)(R6), R9 + ADD R6, R3, R15 + MOVD 1(R15), R10 + MOVD (R3)(R8), R11 + ADD R8, R3, R15 + MOVD 1(R15), R12 + LSL $0x10, R9, R9 + MUL R5, R9, R9 + LSR $0x34, R9, R9 + LSL $0x20, R10, R10 + MUL R7, R10, R10 + LSR $0x36, R10, R10 + LSL $0x10, R11, R11 + MUL R5, R11, R11 + LSR $0x34, R11, R11 + LSL $0x20, R12, R12 + MUL R7, R12, R12 + LSR $0x36, R12, R12 + ADD $1, R6, R7 + ADD $1, R8, R13 + MOVW R6, (R0)(R9<<2) + MOVW R8, (R0)(R11<<2) + ADD R10<<2, R0, R15 + MOVW R7, 16384(R15) + ADD R12<<2, R0, R15 + MOVW R13, 16384(R15) + ADD R6, R8, R7 + ADD $1, R7, R7 + LSR $0x01, R7, R7 + ADD $0x01, R6, R6 + SUB $0x01, R8, R8 + +index_loop_encodeSnappyBetterBlockAsm10B: + CMP R8, R7 + BHS search_loop_encodeSnappyBetterBlockAsm10B + MOVD (R3)(R6), R9 + MOVD (R3)(R7), R10 + LSL $0x10, R9, R9 + MUL R5, R9, R9 + LSR $0x34, R9, R9 + LSL $0x10, R10, R10 + MUL R5, R10, R10 + LSR $0x34, R10, R10 + MOVW R6, (R0)(R9<<2) + MOVW R7, (R0)(R10<<2) + ADD $0x02, R6, R6 + ADD $0x02, R7, R7 + JMP index_loop_encodeSnappyBetterBlockAsm10B + +emit_remainder_encodeSnappyBetterBlockAsm10B: + MOVD src_len+32(FP), R0 + MOVWU 20(RSP), R16 + SUBW R16, R0, R0 + ADD R0, R1, R0 + ADD $3, R0, R0 + MOVD 8(RSP), R16 + CMP R16, R0 + BLO emit_remainder_ok_encodeSnappyBetterBlockAsm10B + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +emit_remainder_ok_encodeSnappyBetterBlockAsm10B: + MOVD src_len+32(FP), R0 + MOVWU 20(RSP), R2 + CMPW R0, R2 + BEQ emit_literal_done_emit_remainder_encodeSnappyBetterBlockAsm10B + MOVWU R0, R5 + MOVW R0, 20(RSP) + ADD R2, R3, R0 + SUBW R2, R5, R5 + SUB $1, R5, R2 + MOVWU R2, R2 + CMPW $0x3c, R2 + BLO one_byte_emit_remainder_encodeSnappyBetterBlockAsm10B + CMPW $0x00000100, R2 + BLO two_bytes_emit_remainder_encodeSnappyBetterBlockAsm10B + BLO three_bytes_emit_remainder_encodeSnappyBetterBlockAsm10B + +three_bytes_emit_remainder_encodeSnappyBetterBlockAsm10B: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R2, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_emit_remainder_encodeSnappyBetterBlockAsm10B + +two_bytes_emit_remainder_encodeSnappyBetterBlockAsm10B: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R2, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R2 + BLO memmove_emit_remainder_encodeSnappyBetterBlockAsm10B + JMP memmove_long_emit_remainder_encodeSnappyBetterBlockAsm10B + +one_byte_emit_remainder_encodeSnappyBetterBlockAsm10B: + LSLW $0x02, R2, R16 + BFI $0, R16, $8, R2 + MOVB R2, (R1) + ADD $0x01, R1, R1 + +memmove_emit_remainder_encodeSnappyBetterBlockAsm10B: + ADD R5, R1, R2 + MOVWU R5, R3 + + // genMemMoveShort + CMP $0x03, R3 + BLO emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm10B_memmove_move_1or2 + BEQ emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm10B_memmove_move_3 + CMP $0x08, R3 + BLO emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm10B_memmove_move_4through7 + CMP $0x10, R3 + BLS emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm10B_memmove_move_8through16 + CMP $0x20, R3 + BLS emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm10B_memmove_move_17through32 + JMP emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm10B_memmove_move_33through64 + +emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm10B_memmove_move_1or2: + MOVBU (R0), R16 + BFI $0, R16, $8, R5 + ADD R3, R0, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R0 + MOVB R5, (R1) + ADD R3, R1, R15 + MOVB R0, -1(R15) + JMP memmove_end_copy_emit_remainder_encodeSnappyBetterBlockAsm10B + +emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm10B_memmove_move_3: + MOVHU (R0), R16 + BFI $0, R16, $16, R5 + MOVBU 2(R0), R16 + BFI $0, R16, $8, R0 + MOVH R5, (R1) + MOVB R0, 2(R1) + JMP memmove_end_copy_emit_remainder_encodeSnappyBetterBlockAsm10B + +emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm10B_memmove_move_4through7: + MOVWU (R0), R5 + ADD R3, R0, R15 + MOVWU -4(R15), R0 + MOVW R5, (R1) + ADD R3, R1, R15 + MOVW R0, -4(R15) + JMP memmove_end_copy_emit_remainder_encodeSnappyBetterBlockAsm10B + +emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm10B_memmove_move_8through16: + MOVD (R0), R5 + ADD R3, R0, R15 + MOVD -8(R15), R0 + MOVD R5, (R1) + ADD R3, R1, R15 + MOVD R0, -8(R15) + JMP memmove_end_copy_emit_remainder_encodeSnappyBetterBlockAsm10B + +emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm10B_memmove_move_17through32: + FMOVQ (R0), F0 + ADD R3, R0, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R3, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_emit_remainder_encodeSnappyBetterBlockAsm10B + +emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm10B_memmove_move_33through64: + FMOVQ (R0), F0 + FMOVQ 16(R0), F1 + ADD R3, R0, R15 + FMOVQ -32(R15), F2 + ADD R3, R0, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R3, R1, R15 + FMOVQ F2, -32(R15) + ADD R3, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_emit_remainder_encodeSnappyBetterBlockAsm10B: + MOVD R2, R1 + JMP emit_literal_done_emit_remainder_encodeSnappyBetterBlockAsm10B + +memmove_long_emit_remainder_encodeSnappyBetterBlockAsm10B: + ADD R5, R1, R2 + MOVWU R5, R3 + + // genMemMoveLong + MOVD R0, R5 + MOVD R1, R6 + MOVD R3, R7 + +emit_lit_memmove_long_emit_remainder_encodeSnappyBetterBlockAsm10Blarge_big_loop_back: + FMOVQ (R5), F0 + FMOVQ 16(R5), F1 + FMOVQ F0, (R6) + FMOVQ F1, 16(R6) + ADD $0x20, R5, R5 + ADD $0x20, R6, R6 + SUB $0x20, R7, R7 + CMP $0x20, R7 + BHS emit_lit_memmove_long_emit_remainder_encodeSnappyBetterBlockAsm10Blarge_big_loop_back + ADD R3, R0, R15 + FMOVQ -32(R15), F0 + ADD R3, R0, R15 + FMOVQ -16(R15), F1 + ADD R3, R1, R15 + FMOVQ F0, -32(R15) + ADD R3, R1, R15 + FMOVQ F1, -16(R15) + MOVD R2, R1 + +emit_literal_done_emit_remainder_encodeSnappyBetterBlockAsm10B: + MOVD dst_base+0(FP), R0 + SUB R0, R1, R1 + MOVD R1, ret+56(FP) + RET + +// func encodeSnappyBetterBlockAsm8B(dst []byte, src []byte, tmp *[5120]byte) int +// Requires: BMI, SSE2 +TEXT ·encodeSnappyBetterBlockAsm8B(SB), $24-64 + MOVD tmp+48(FP), R0 + MOVD dst_base+0(FP), R1 + MOVD $0x00000028, R2 + MOVD R0, R3 + VEOR V0.B16, V0.B16, V0.B16 + +zero_loop_encodeSnappyBetterBlockAsm8B: + FMOVQ F0, (R3) + FMOVQ F0, 16(R3) + FMOVQ F0, 32(R3) + FMOVQ F0, 48(R3) + FMOVQ F0, 64(R3) + FMOVQ F0, 80(R3) + FMOVQ F0, 96(R3) + FMOVQ F0, 112(R3) + ADD $0x80, R3, R3 + SUBS $1, R2, R2 + BNE zero_loop_encodeSnappyBetterBlockAsm8B + MOVD $0x00000000, R16 + MOVW R16, 20(RSP) + MOVD src_len+32(FP), R2 + SUB $9, R2, R3 + SUB $8, R2, R5 + MOVW R5, 16(RSP) + LSR $0x05, R2, R2 + SUBW R2, R3, R3 + ADD R3, R1, R3 + MOVD R3, 8(RSP) + MOVD $0x00000001, R2 + MOVD $0x00000000, R16 + MOVW R16, 24(RSP) + MOVD src_base+24(FP), R3 + +search_loop_encodeSnappyBetterBlockAsm8B: + MOVWU R2, R5 + MOVWU 20(RSP), R16 + SUBW R16, R5, R5 + LSRW $0x04, R5, R5 + ADD R5, R2, R5 + ADD $1, R5, R5 + MOVWU R5, R5 + MOVWU 16(RSP), R16 + CMPW R16, R5 + BHS emit_remainder_encodeSnappyBetterBlockAsm8B + MOVD (R3)(R2), R6 + MOVW R5, 28(RSP) + MOVD $0x0000cf1bbcdcbf9b, R8 + MOVD $0x9e3779b1, R5 + MOVD R6, R9 + MOVD R6, R10 + LSL $0x10, R9, R9 + MUL R8, R9, R9 + LSR $0x36, R9, R9 + LSL $0x20, R10, R10 + MUL R5, R10, R10 + LSR $0x38, R10, R10 + MOVWU (R0)(R9<<2), R5 + ADD R10<<2, R0, R15 + MOVWU 4096(R15), R7 + MOVW R2, (R0)(R9<<2) + ADD R10<<2, R0, R15 + MOVW R2, 4096(R15) + MOVD (R3)(R5), R9 + MOVD (R3)(R7), R10 + CMP R6, R9 + BEQ candidate_match_encodeSnappyBetterBlockAsm8B + CMP R6, R10 + BNE no_short_found_encodeSnappyBetterBlockAsm8B + MOVWU R7, R5 + JMP candidate_match_encodeSnappyBetterBlockAsm8B + +no_short_found_encodeSnappyBetterBlockAsm8B: + CMPW R6, R9 + BEQ candidate_match_encodeSnappyBetterBlockAsm8B + CMPW R6, R10 + BEQ candidateS_match_encodeSnappyBetterBlockAsm8B + MOVWU 28(RSP), R2 + JMP search_loop_encodeSnappyBetterBlockAsm8B + +candidateS_match_encodeSnappyBetterBlockAsm8B: + LSR $0x08, R6, R6 + MOVD R6, R9 + LSL $0x10, R9, R9 + MUL R8, R9, R9 + LSR $0x36, R9, R9 + MOVWU (R0)(R9<<2), R5 + ADDW $1, R2, R2 + MOVW R2, (R0)(R9<<2) + MOVWU (R3)(R5), R16 + CMPW R6, R16 + BEQ candidate_match_encodeSnappyBetterBlockAsm8B + SUBW $1, R2, R2 + MOVWU R7, R5 + +candidate_match_encodeSnappyBetterBlockAsm8B: + MOVWU 20(RSP), R6 + TSTW R5, R5 + BEQ match_extend_back_end_encodeSnappyBetterBlockAsm8B + +match_extend_back_loop_encodeSnappyBetterBlockAsm8B: + CMPW R6, R2 + BLS match_extend_back_end_encodeSnappyBetterBlockAsm8B + ADD R5, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R7 + ADD R2, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R8 + AND $0xff, R8, R16 + AND $0xff, R7, R15 + CMP R16, R15 + BNE match_extend_back_end_encodeSnappyBetterBlockAsm8B + SUB $1, R2, R2 + MOVWU R2, R2 + SUBSW $1, R5, R5 + BEQ match_extend_back_end_encodeSnappyBetterBlockAsm8B + JMP match_extend_back_loop_encodeSnappyBetterBlockAsm8B + +match_extend_back_end_encodeSnappyBetterBlockAsm8B: + MOVWU R2, R6 + MOVWU 20(RSP), R16 + SUBW R16, R6, R6 + ADD R6, R1, R6 + ADD $3, R6, R6 + MOVD 8(RSP), R16 + CMP R16, R6 + BLO match_dst_size_check_encodeSnappyBetterBlockAsm8B + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +match_dst_size_check_encodeSnappyBetterBlockAsm8B: + MOVWU R2, R6 + ADDW $0x04, R2, R2 + ADDW $0x04, R5, R5 + MOVD src_len+32(FP), R7 + SUBW R2, R7, R7 + ADD R2, R3, R8 + ADD R5, R3, R9 + + // matchLen + MOVD $0, R11 + +matchlen_loopback_16_match_nolit_encodeSnappyBetterBlockAsm8B: + CMPW $0x10, R7 + BLO matchlen_match8_match_nolit_encodeSnappyBetterBlockAsm8B + MOVD (R8)(R11), R10 + ADD R11, R8, R15 + MOVD 8(R15), R12 + MOVD (R9)(R11), R16 + EOR R16, R10, R10 + TST R10, R10 + BNE matchlen_bsf_8_match_nolit_encodeSnappyBetterBlockAsm8B + ADD R11, R9, R15 + MOVD 8(R15), R16 + EOR R16, R12, R12 + TST R12, R12 + BNE matchlen_bsf_16match_nolit_encodeSnappyBetterBlockAsm8B + SUB $16, R7, R7 + MOVWU R7, R7 + ADD $16, R11, R11 + MOVWU R11, R11 + JMP matchlen_loopback_16_match_nolit_encodeSnappyBetterBlockAsm8B + +matchlen_bsf_16match_nolit_encodeSnappyBetterBlockAsm8B: + RBIT R12, R12 + CLZ R12, R12 + ASR $0x03, R12, R12 + ADD R12, R11, R11 + ADD $8, R11, R11 + MOVWU R11, R11 + JMP match_nolit_end_encodeSnappyBetterBlockAsm8B + +matchlen_match8_match_nolit_encodeSnappyBetterBlockAsm8B: + CMPW $0x08, R7 + BLO matchlen_match4_match_nolit_encodeSnappyBetterBlockAsm8B + MOVD (R8)(R11), R10 + MOVD (R9)(R11), R16 + EOR R16, R10, R10 + TST R10, R10 + BNE matchlen_bsf_8_match_nolit_encodeSnappyBetterBlockAsm8B + SUB $8, R7, R7 + MOVWU R7, R7 + ADD $8, R11, R11 + MOVWU R11, R11 + JMP matchlen_match4_match_nolit_encodeSnappyBetterBlockAsm8B + +matchlen_bsf_8_match_nolit_encodeSnappyBetterBlockAsm8B: + RBIT R10, R10 + CLZ R10, R10 + ASR $0x03, R10, R10 + ADD R10, R11, R11 + MOVWU R11, R11 + JMP match_nolit_end_encodeSnappyBetterBlockAsm8B + +matchlen_match4_match_nolit_encodeSnappyBetterBlockAsm8B: + CMPW $0x04, R7 + BLO matchlen_match2_match_nolit_encodeSnappyBetterBlockAsm8B + MOVWU (R8)(R11), R10 + MOVWU (R9)(R11), R16 + CMPW R10, R16 + BNE matchlen_match2_match_nolit_encodeSnappyBetterBlockAsm8B + SUB $4, R7, R7 + MOVWU R7, R7 + ADD $4, R11, R11 + MOVWU R11, R11 + +matchlen_match2_match_nolit_encodeSnappyBetterBlockAsm8B: + CMPW $0x01, R7 + BEQ matchlen_match1_match_nolit_encodeSnappyBetterBlockAsm8B + BLO match_nolit_end_encodeSnappyBetterBlockAsm8B + MOVHU (R8)(R11), R16 + BFI $0, R16, $16, R10 + ADD R11, R9, R15 + MOVHU (R15), R15 + AND $0xffff, R10, R16 + CMP R16, R15 + BNE matchlen_match1_match_nolit_encodeSnappyBetterBlockAsm8B + ADD $2, R11, R11 + MOVWU R11, R11 + SUBSW $0x02, R7, R7 + BEQ match_nolit_end_encodeSnappyBetterBlockAsm8B + +matchlen_match1_match_nolit_encodeSnappyBetterBlockAsm8B: + MOVBU (R8)(R11), R16 + BFI $0, R16, $8, R10 + ADD R11, R9, R15 + MOVBU (R15), R15 + AND $0xff, R10, R16 + CMP R16, R15 + BNE match_nolit_end_encodeSnappyBetterBlockAsm8B + ADD $1, R11, R11 + MOVWU R11, R11 + +match_nolit_end_encodeSnappyBetterBlockAsm8B: + MOVWU R2, R7 + SUBW R5, R7, R7 + + // Check if repeat + MOVW R7, 24(RSP) + MOVWU 20(RSP), R5 + CMPW R6, R5 + BEQ emit_literal_done_match_emit_encodeSnappyBetterBlockAsm8B + MOVWU R6, R8 + MOVW R6, 20(RSP) + ADD R5, R3, R9 + SUBW R5, R8, R8 + SUB $1, R8, R5 + MOVWU R5, R5 + CMPW $0x3c, R5 + BLO one_byte_match_emit_encodeSnappyBetterBlockAsm8B + CMPW $0x00000100, R5 + BLO two_bytes_match_emit_encodeSnappyBetterBlockAsm8B + BLO three_bytes_match_emit_encodeSnappyBetterBlockAsm8B + +three_bytes_match_emit_encodeSnappyBetterBlockAsm8B: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R5, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_match_emit_encodeSnappyBetterBlockAsm8B + +two_bytes_match_emit_encodeSnappyBetterBlockAsm8B: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R5, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R5 + BLO memmove_match_emit_encodeSnappyBetterBlockAsm8B + JMP memmove_long_match_emit_encodeSnappyBetterBlockAsm8B + +one_byte_match_emit_encodeSnappyBetterBlockAsm8B: + LSLW $0x02, R5, R16 + BFI $0, R16, $8, R5 + MOVB R5, (R1) + ADD $0x01, R1, R1 + +memmove_match_emit_encodeSnappyBetterBlockAsm8B: + ADD R8, R1, R5 + + // genMemMoveShort + CMP $0x08, R8 + BLS emit_lit_memmove_match_emit_encodeSnappyBetterBlockAsm8B_memmove_move_8 + CMP $0x10, R8 + BLS emit_lit_memmove_match_emit_encodeSnappyBetterBlockAsm8B_memmove_move_8through16 + CMP $0x20, R8 + BLS emit_lit_memmove_match_emit_encodeSnappyBetterBlockAsm8B_memmove_move_17through32 + JMP emit_lit_memmove_match_emit_encodeSnappyBetterBlockAsm8B_memmove_move_33through64 + +emit_lit_memmove_match_emit_encodeSnappyBetterBlockAsm8B_memmove_move_8: + MOVD (R9), R10 + MOVD R10, (R1) + JMP memmove_end_copy_match_emit_encodeSnappyBetterBlockAsm8B + +emit_lit_memmove_match_emit_encodeSnappyBetterBlockAsm8B_memmove_move_8through16: + MOVD (R9), R10 + ADD R8, R9, R15 + MOVD -8(R15), R9 + MOVD R10, (R1) + ADD R8, R1, R15 + MOVD R9, -8(R15) + JMP memmove_end_copy_match_emit_encodeSnappyBetterBlockAsm8B + +emit_lit_memmove_match_emit_encodeSnappyBetterBlockAsm8B_memmove_move_17through32: + FMOVQ (R9), F0 + ADD R8, R9, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_match_emit_encodeSnappyBetterBlockAsm8B + +emit_lit_memmove_match_emit_encodeSnappyBetterBlockAsm8B_memmove_move_33through64: + FMOVQ (R9), F0 + FMOVQ 16(R9), F1 + ADD R8, R9, R15 + FMOVQ -32(R15), F2 + ADD R8, R9, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R8, R1, R15 + FMOVQ F2, -32(R15) + ADD R8, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_match_emit_encodeSnappyBetterBlockAsm8B: + MOVD R5, R1 + JMP emit_literal_done_match_emit_encodeSnappyBetterBlockAsm8B + +memmove_long_match_emit_encodeSnappyBetterBlockAsm8B: + ADD R8, R1, R5 + + // genMemMoveLong + MOVD R9, R10 + MOVD R1, R12 + MOVD R8, R13 + +emit_lit_memmove_long_match_emit_encodeSnappyBetterBlockAsm8Blarge_big_loop_back: + FMOVQ (R10), F0 + FMOVQ 16(R10), F1 + FMOVQ F0, (R12) + FMOVQ F1, 16(R12) + ADD $0x20, R10, R10 + ADD $0x20, R12, R12 + SUB $0x20, R13, R13 + CMP $0x20, R13 + BHS emit_lit_memmove_long_match_emit_encodeSnappyBetterBlockAsm8Blarge_big_loop_back + ADD R8, R9, R15 + FMOVQ -32(R15), F0 + ADD R8, R9, R15 + FMOVQ -16(R15), F1 + ADD R8, R1, R15 + FMOVQ F0, -32(R15) + ADD R8, R1, R15 + FMOVQ F1, -16(R15) + MOVD R5, R1 + +emit_literal_done_match_emit_encodeSnappyBetterBlockAsm8B: + ADDW R11, R2, R2 + ADDW $0x04, R11, R11 + MOVW R2, 20(RSP) + + // emitCopy +two_byte_offset_match_nolit_encodeSnappyBetterBlockAsm8B: + CMPW $0x40, R11 + BLS two_byte_offset_short_match_nolit_encodeSnappyBetterBlockAsm8B + MOVD $0xee, R16 + MOVB R16, (R1) + MOVH R7, 1(R1) + SUB $60, R11, R11 + MOVWU R11, R11 + ADD $0x03, R1, R1 + JMP two_byte_offset_match_nolit_encodeSnappyBetterBlockAsm8B + +two_byte_offset_short_match_nolit_encodeSnappyBetterBlockAsm8B: + MOVWU R11, R5 + LSLW $0x02, R5, R5 + CMPW $0x0c, R11 + BHS emit_copy_three_match_nolit_encodeSnappyBetterBlockAsm8B + SUB $15, R5, R5 + MOVWU R5, R5 + MOVB R7, 1(R1) + LSRW $0x08, R7, R7 + LSLW $0x05, R7, R7 + ORRW R7, R5, R5 + MOVB R5, (R1) + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_encodeSnappyBetterBlockAsm8B + +emit_copy_three_match_nolit_encodeSnappyBetterBlockAsm8B: + SUB $2, R5, R5 + MOVWU R5, R5 + MOVB R5, (R1) + MOVH R7, 1(R1) + ADD $0x03, R1, R1 + +match_nolit_emitcopy_end_encodeSnappyBetterBlockAsm8B: + MOVWU 16(RSP), R16 + CMPW R16, R2 + BHS emit_remainder_encodeSnappyBetterBlockAsm8B + MOVD 8(RSP), R16 + CMP R16, R1 + BLO match_nolit_dst_ok_encodeSnappyBetterBlockAsm8B + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +match_nolit_dst_ok_encodeSnappyBetterBlockAsm8B: + MOVD $0x0000cf1bbcdcbf9b, R5 + MOVD $0x9e3779b1, R7 + ADD $1, R6, R6 + SUB $2, R2, R8 + MOVD (R3)(R6), R9 + ADD R6, R3, R15 + MOVD 1(R15), R10 + MOVD (R3)(R8), R11 + ADD R8, R3, R15 + MOVD 1(R15), R12 + LSL $0x10, R9, R9 + MUL R5, R9, R9 + LSR $0x36, R9, R9 + LSL $0x20, R10, R10 + MUL R7, R10, R10 + LSR $0x38, R10, R10 + LSL $0x10, R11, R11 + MUL R5, R11, R11 + LSR $0x36, R11, R11 + LSL $0x20, R12, R12 + MUL R7, R12, R12 + LSR $0x38, R12, R12 + ADD $1, R6, R7 + ADD $1, R8, R13 + MOVW R6, (R0)(R9<<2) + MOVW R8, (R0)(R11<<2) + ADD R10<<2, R0, R15 + MOVW R7, 4096(R15) + ADD R12<<2, R0, R15 + MOVW R13, 4096(R15) + ADD R6, R8, R7 + ADD $1, R7, R7 + LSR $0x01, R7, R7 + ADD $0x01, R6, R6 + SUB $0x01, R8, R8 + +index_loop_encodeSnappyBetterBlockAsm8B: + CMP R8, R7 + BHS search_loop_encodeSnappyBetterBlockAsm8B + MOVD (R3)(R6), R9 + MOVD (R3)(R7), R10 + LSL $0x10, R9, R9 + MUL R5, R9, R9 + LSR $0x36, R9, R9 + LSL $0x10, R10, R10 + MUL R5, R10, R10 + LSR $0x36, R10, R10 + MOVW R6, (R0)(R9<<2) + MOVW R7, (R0)(R10<<2) + ADD $0x02, R6, R6 + ADD $0x02, R7, R7 + JMP index_loop_encodeSnappyBetterBlockAsm8B + +emit_remainder_encodeSnappyBetterBlockAsm8B: + MOVD src_len+32(FP), R0 + MOVWU 20(RSP), R16 + SUBW R16, R0, R0 + ADD R0, R1, R0 + ADD $3, R0, R0 + MOVD 8(RSP), R16 + CMP R16, R0 + BLO emit_remainder_ok_encodeSnappyBetterBlockAsm8B + MOVD $0x00000000, R16 + MOVD R16, ret+56(FP) + RET + +emit_remainder_ok_encodeSnappyBetterBlockAsm8B: + MOVD src_len+32(FP), R0 + MOVWU 20(RSP), R2 + CMPW R0, R2 + BEQ emit_literal_done_emit_remainder_encodeSnappyBetterBlockAsm8B + MOVWU R0, R5 + MOVW R0, 20(RSP) + ADD R2, R3, R0 + SUBW R2, R5, R5 + SUB $1, R5, R2 + MOVWU R2, R2 + CMPW $0x3c, R2 + BLO one_byte_emit_remainder_encodeSnappyBetterBlockAsm8B + CMPW $0x00000100, R2 + BLO two_bytes_emit_remainder_encodeSnappyBetterBlockAsm8B + BLO three_bytes_emit_remainder_encodeSnappyBetterBlockAsm8B + +three_bytes_emit_remainder_encodeSnappyBetterBlockAsm8B: + MOVD $0xf4, R16 + MOVB R16, (R1) + MOVH R2, 1(R1) + ADD $0x03, R1, R1 + JMP memmove_long_emit_remainder_encodeSnappyBetterBlockAsm8B + +two_bytes_emit_remainder_encodeSnappyBetterBlockAsm8B: + MOVD $0xf0, R16 + MOVB R16, (R1) + MOVB R2, 1(R1) + ADD $0x02, R1, R1 + CMPW $0x40, R2 + BLO memmove_emit_remainder_encodeSnappyBetterBlockAsm8B + JMP memmove_long_emit_remainder_encodeSnappyBetterBlockAsm8B + +one_byte_emit_remainder_encodeSnappyBetterBlockAsm8B: + LSLW $0x02, R2, R16 + BFI $0, R16, $8, R2 + MOVB R2, (R1) + ADD $0x01, R1, R1 + +memmove_emit_remainder_encodeSnappyBetterBlockAsm8B: + ADD R5, R1, R2 + MOVWU R5, R3 + + // genMemMoveShort + CMP $0x03, R3 + BLO emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm8B_memmove_move_1or2 + BEQ emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm8B_memmove_move_3 + CMP $0x08, R3 + BLO emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm8B_memmove_move_4through7 + CMP $0x10, R3 + BLS emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm8B_memmove_move_8through16 + CMP $0x20, R3 + BLS emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm8B_memmove_move_17through32 + JMP emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm8B_memmove_move_33through64 + +emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm8B_memmove_move_1or2: + MOVBU (R0), R16 + BFI $0, R16, $8, R5 + ADD R3, R0, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R0 + MOVB R5, (R1) + ADD R3, R1, R15 + MOVB R0, -1(R15) + JMP memmove_end_copy_emit_remainder_encodeSnappyBetterBlockAsm8B + +emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm8B_memmove_move_3: + MOVHU (R0), R16 + BFI $0, R16, $16, R5 + MOVBU 2(R0), R16 + BFI $0, R16, $8, R0 + MOVH R5, (R1) + MOVB R0, 2(R1) + JMP memmove_end_copy_emit_remainder_encodeSnappyBetterBlockAsm8B + +emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm8B_memmove_move_4through7: + MOVWU (R0), R5 + ADD R3, R0, R15 + MOVWU -4(R15), R0 + MOVW R5, (R1) + ADD R3, R1, R15 + MOVW R0, -4(R15) + JMP memmove_end_copy_emit_remainder_encodeSnappyBetterBlockAsm8B + +emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm8B_memmove_move_8through16: + MOVD (R0), R5 + ADD R3, R0, R15 + MOVD -8(R15), R0 + MOVD R5, (R1) + ADD R3, R1, R15 + MOVD R0, -8(R15) + JMP memmove_end_copy_emit_remainder_encodeSnappyBetterBlockAsm8B + +emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm8B_memmove_move_17through32: + FMOVQ (R0), F0 + ADD R3, R0, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R1) + ADD R3, R1, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_emit_remainder_encodeSnappyBetterBlockAsm8B + +emit_lit_memmove_emit_remainder_encodeSnappyBetterBlockAsm8B_memmove_move_33through64: + FMOVQ (R0), F0 + FMOVQ 16(R0), F1 + ADD R3, R0, R15 + FMOVQ -32(R15), F2 + ADD R3, R0, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R1) + FMOVQ F1, 16(R1) + ADD R3, R1, R15 + FMOVQ F2, -32(R15) + ADD R3, R1, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_emit_remainder_encodeSnappyBetterBlockAsm8B: + MOVD R2, R1 + JMP emit_literal_done_emit_remainder_encodeSnappyBetterBlockAsm8B + +memmove_long_emit_remainder_encodeSnappyBetterBlockAsm8B: + ADD R5, R1, R2 + MOVWU R5, R3 + + // genMemMoveLong + MOVD R0, R5 + MOVD R1, R6 + MOVD R3, R7 + +emit_lit_memmove_long_emit_remainder_encodeSnappyBetterBlockAsm8Blarge_big_loop_back: + FMOVQ (R5), F0 + FMOVQ 16(R5), F1 + FMOVQ F0, (R6) + FMOVQ F1, 16(R6) + ADD $0x20, R5, R5 + ADD $0x20, R6, R6 + SUB $0x20, R7, R7 + CMP $0x20, R7 + BHS emit_lit_memmove_long_emit_remainder_encodeSnappyBetterBlockAsm8Blarge_big_loop_back + ADD R3, R0, R15 + FMOVQ -32(R15), F0 + ADD R3, R0, R15 + FMOVQ -16(R15), F1 + ADD R3, R1, R15 + FMOVQ F0, -32(R15) + ADD R3, R1, R15 + FMOVQ F1, -16(R15) + MOVD R2, R1 + +emit_literal_done_emit_remainder_encodeSnappyBetterBlockAsm8B: + MOVD dst_base+0(FP), R0 + SUB R0, R1, R1 + MOVD R1, ret+56(FP) + RET + +// func calcBlockSize(src []byte, tmp *[32768]byte) int +// Requires: BMI, SSE2 +TEXT ·calcBlockSize(SB), $24-40 + MOVD tmp+24(FP), R0 + MOVD $0, R1 + MOVD $0x00000100, R2 + MOVD R0, R3 + VEOR V0.B16, V0.B16, V0.B16 + +zero_loop_calcBlockSize: + FMOVQ F0, (R3) + FMOVQ F0, 16(R3) + FMOVQ F0, 32(R3) + FMOVQ F0, 48(R3) + FMOVQ F0, 64(R3) + FMOVQ F0, 80(R3) + FMOVQ F0, 96(R3) + FMOVQ F0, 112(R3) + ADD $0x80, R3, R3 + SUBS $1, R2, R2 + BNE zero_loop_calcBlockSize + MOVD $0x00000000, R16 + MOVW R16, 20(RSP) + MOVD src_len+8(FP), R2 + SUB $9, R2, R3 + SUB $8, R2, R5 + MOVW R5, 16(RSP) + LSR $0x05, R2, R2 + SUBW R2, R3, R3 + ADD R3, R1, R3 + MOVD R3, 8(RSP) + MOVD $0x00000001, R2 + MOVW R2, 24(RSP) + MOVD src_base+0(FP), R3 + +search_loop_calcBlockSize: + MOVWU R2, R5 + MOVWU 20(RSP), R16 + SUBW R16, R5, R5 + LSRW $0x05, R5, R5 + ADD R5, R2, R5 + ADD $4, R5, R5 + MOVWU R5, R5 + MOVWU 16(RSP), R16 + CMPW R16, R5 + BHS emit_remainder_calcBlockSize + MOVD (R3)(R2), R6 + MOVW R5, 28(RSP) + MOVD $0x0000cf1bbcdcbf9b, R8 + MOVD R6, R9 + MOVD R6, R10 + LSR $0x08, R10, R10 + LSL $0x10, R9, R9 + MUL R8, R9, R9 + LSR $0x33, R9, R9 + LSL $0x10, R10, R10 + MUL R8, R10, R10 + LSR $0x33, R10, R10 + MOVWU (R0)(R9<<2), R5 + MOVWU (R0)(R10<<2), R7 + MOVW R2, (R0)(R9<<2) + ADD $1, R2, R9 + MOVWU R9, R9 + MOVW R9, (R0)(R10<<2) + MOVD R6, R9 + LSR $0x10, R9, R9 + LSL $0x10, R9, R9 + MUL R8, R9, R9 + LSR $0x33, R9, R9 + MOVWU R2, R8 + MOVWU 24(RSP), R16 + SUBW R16, R8, R8 + ADD R8, R3, R15 + MOVWU 1(R15), R10 + MOVD R6, R8 + LSR $0x08, R8, R8 + CMPW R10, R8 + BNE no_repeat_found_calcBlockSize + ADD $1, R2, R6 + MOVWU R6, R6 + MOVWU 20(RSP), R5 + MOVWU R6, R7 + MOVWU 24(RSP), R16 + SUBSW R16, R7, R7 + BEQ repeat_extend_back_end_calcBlockSize + +repeat_extend_back_loop_calcBlockSize: + CMPW R5, R6 + BLS repeat_extend_back_end_calcBlockSize + ADD R7, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R8 + ADD R6, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R9 + AND $0xff, R9, R16 + AND $0xff, R8, R15 + CMP R16, R15 + BNE repeat_extend_back_end_calcBlockSize + SUB $1, R6, R6 + MOVWU R6, R6 + SUBSW $1, R7, R7 + BNE repeat_extend_back_loop_calcBlockSize + +repeat_extend_back_end_calcBlockSize: + MOVWU R6, R5 + MOVWU 20(RSP), R16 + SUBW R16, R5, R5 + ADD R5, R1, R5 + ADD $5, R5, R5 + MOVD 8(RSP), R16 + CMP R16, R5 + BLO repeat_dst_size_check_calcBlockSize + MOVD $0x00000000, R16 + MOVD R16, ret+32(FP) + RET + +repeat_dst_size_check_calcBlockSize: + MOVWU 20(RSP), R5 + CMPW R6, R5 + BEQ emit_literal_done_repeat_emit_calcBlockSize + MOVWU R6, R7 + MOVW R6, 20(RSP) + ADD R5, R3, R8 + SUBW R5, R7, R7 + SUB $1, R7, R5 + MOVWU R5, R5 + CMPW $0x3c, R5 + BLO one_byte_repeat_emit_calcBlockSize + CMPW $0x00000100, R5 + BLO two_bytes_repeat_emit_calcBlockSize + CMPW $0x00010000, R5 + BLO three_bytes_repeat_emit_calcBlockSize + CMPW $0x01000000, R5 + BLO four_bytes_repeat_emit_calcBlockSize + ADD $0x05, R1, R1 + JMP memmove_long_repeat_emit_calcBlockSize + +four_bytes_repeat_emit_calcBlockSize: + ADD $0x04, R1, R1 + JMP memmove_long_repeat_emit_calcBlockSize + +three_bytes_repeat_emit_calcBlockSize: + ADD $0x03, R1, R1 + JMP memmove_long_repeat_emit_calcBlockSize + +two_bytes_repeat_emit_calcBlockSize: + ADD $0x02, R1, R1 + CMPW $0x40, R5 + BLO memmove_repeat_emit_calcBlockSize + JMP memmove_long_repeat_emit_calcBlockSize + +one_byte_repeat_emit_calcBlockSize: + ADD $0x01, R1, R1 + +memmove_repeat_emit_calcBlockSize: + ADD R7, R1, R1 + JMP emit_literal_done_repeat_emit_calcBlockSize + +memmove_long_repeat_emit_calcBlockSize: + ADD R7, R1, R1 + +emit_literal_done_repeat_emit_calcBlockSize: + ADDW $0x05, R2, R2 + MOVWU R2, R5 + MOVWU 24(RSP), R16 + SUBW R16, R5, R5 + MOVD src_len+8(FP), R7 + SUBW R2, R7, R7 + ADD R2, R3, R8 + ADD R5, R3, R5 + + // matchLen + MOVD $0, R10 + +matchlen_loopback_16_repeat_extend_calcBlockSize: + CMPW $0x10, R7 + BLO matchlen_match8_repeat_extend_calcBlockSize + MOVD (R8)(R10), R9 + ADD R10, R8, R15 + MOVD 8(R15), R11 + MOVD (R5)(R10), R16 + EOR R16, R9, R9 + TST R9, R9 + BNE matchlen_bsf_8_repeat_extend_calcBlockSize + ADD R10, R5, R15 + MOVD 8(R15), R16 + EOR R16, R11, R11 + TST R11, R11 + BNE matchlen_bsf_16repeat_extend_calcBlockSize + SUB $16, R7, R7 + MOVWU R7, R7 + ADD $16, R10, R10 + MOVWU R10, R10 + JMP matchlen_loopback_16_repeat_extend_calcBlockSize + +matchlen_bsf_16repeat_extend_calcBlockSize: + RBIT R11, R11 + CLZ R11, R11 + ASR $0x03, R11, R11 + ADD R11, R10, R10 + ADD $8, R10, R10 + MOVWU R10, R10 + JMP repeat_extend_forward_end_calcBlockSize + +matchlen_match8_repeat_extend_calcBlockSize: + CMPW $0x08, R7 + BLO matchlen_match4_repeat_extend_calcBlockSize + MOVD (R8)(R10), R9 + MOVD (R5)(R10), R16 + EOR R16, R9, R9 + TST R9, R9 + BNE matchlen_bsf_8_repeat_extend_calcBlockSize + SUB $8, R7, R7 + MOVWU R7, R7 + ADD $8, R10, R10 + MOVWU R10, R10 + JMP matchlen_match4_repeat_extend_calcBlockSize + +matchlen_bsf_8_repeat_extend_calcBlockSize: + RBIT R9, R9 + CLZ R9, R9 + ASR $0x03, R9, R9 + ADD R9, R10, R10 + MOVWU R10, R10 + JMP repeat_extend_forward_end_calcBlockSize + +matchlen_match4_repeat_extend_calcBlockSize: + CMPW $0x04, R7 + BLO matchlen_match2_repeat_extend_calcBlockSize + MOVWU (R8)(R10), R9 + MOVWU (R5)(R10), R16 + CMPW R9, R16 + BNE matchlen_match2_repeat_extend_calcBlockSize + SUB $4, R7, R7 + MOVWU R7, R7 + ADD $4, R10, R10 + MOVWU R10, R10 + +matchlen_match2_repeat_extend_calcBlockSize: + CMPW $0x01, R7 + BEQ matchlen_match1_repeat_extend_calcBlockSize + BLO repeat_extend_forward_end_calcBlockSize + MOVHU (R8)(R10), R16 + BFI $0, R16, $16, R9 + ADD R10, R5, R15 + MOVHU (R15), R15 + AND $0xffff, R9, R16 + CMP R16, R15 + BNE matchlen_match1_repeat_extend_calcBlockSize + ADD $2, R10, R10 + MOVWU R10, R10 + SUBSW $0x02, R7, R7 + BEQ repeat_extend_forward_end_calcBlockSize + +matchlen_match1_repeat_extend_calcBlockSize: + MOVBU (R8)(R10), R16 + BFI $0, R16, $8, R9 + ADD R10, R5, R15 + MOVBU (R15), R15 + AND $0xff, R9, R16 + CMP R16, R15 + BNE repeat_extend_forward_end_calcBlockSize + ADD $1, R10, R10 + MOVWU R10, R10 + +repeat_extend_forward_end_calcBlockSize: + ADDW R10, R2, R2 + MOVWU R2, R5 + SUBW R6, R5, R5 + MOVWU 24(RSP), R6 + + // emitCopy + CMPW $0x00010000, R6 + BLO two_byte_offset_repeat_as_copy_calcBlockSize + +four_bytes_loop_back_repeat_as_copy_calcBlockSize: + CMPW $0x40, R5 + BLS four_bytes_remain_repeat_as_copy_calcBlockSize + SUB $64, R5, R5 + MOVWU R5, R5 + ADD $0x05, R1, R1 + CMPW $0x04, R5 + BLO four_bytes_remain_repeat_as_copy_calcBlockSize + JMP four_bytes_loop_back_repeat_as_copy_calcBlockSize + +four_bytes_remain_repeat_as_copy_calcBlockSize: + TSTW R5, R5 + BEQ repeat_end_emit_calcBlockSize + MOVD $0, R5 + ADD $0x05, R1, R1 + JMP repeat_end_emit_calcBlockSize + +two_byte_offset_repeat_as_copy_calcBlockSize: + CMPW $0x40, R5 + BLS two_byte_offset_short_repeat_as_copy_calcBlockSize + SUB $60, R5, R5 + MOVWU R5, R5 + ADD $0x03, R1, R1 + JMP two_byte_offset_repeat_as_copy_calcBlockSize + +two_byte_offset_short_repeat_as_copy_calcBlockSize: + MOVWU R5, R7 + LSLW $0x02, R7, R7 + CMPW $0x0c, R5 + BHS emit_copy_three_repeat_as_copy_calcBlockSize + CMPW $0x00000800, R6 + BHS emit_copy_three_repeat_as_copy_calcBlockSize + ADD $0x02, R1, R1 + JMP repeat_end_emit_calcBlockSize + +emit_copy_three_repeat_as_copy_calcBlockSize: + ADD $0x03, R1, R1 + +repeat_end_emit_calcBlockSize: + MOVW R2, 20(RSP) + JMP search_loop_calcBlockSize + +no_repeat_found_calcBlockSize: + MOVWU (R3)(R5), R16 + CMPW R6, R16 + BEQ candidate_match_calcBlockSize + LSR $0x08, R6, R6 + MOVWU (R0)(R9<<2), R5 + ADD $2, R2, R8 + MOVWU R8, R8 + MOVWU (R3)(R7), R16 + CMPW R6, R16 + BEQ candidate2_match_calcBlockSize + MOVW R8, (R0)(R9<<2) + LSR $0x08, R6, R6 + MOVWU (R3)(R5), R16 + CMPW R6, R16 + BEQ candidate3_match_calcBlockSize + MOVWU 28(RSP), R2 + JMP search_loop_calcBlockSize + +candidate3_match_calcBlockSize: + ADDW $0x02, R2, R2 + JMP candidate_match_calcBlockSize + +candidate2_match_calcBlockSize: + MOVW R8, (R0)(R9<<2) + ADDW $1, R2, R2 + MOVWU R7, R5 + +candidate_match_calcBlockSize: + MOVWU 20(RSP), R6 + TSTW R5, R5 + BEQ match_extend_back_end_calcBlockSize + +match_extend_back_loop_calcBlockSize: + CMPW R6, R2 + BLS match_extend_back_end_calcBlockSize + ADD R5, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R7 + ADD R2, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R8 + AND $0xff, R8, R16 + AND $0xff, R7, R15 + CMP R16, R15 + BNE match_extend_back_end_calcBlockSize + SUB $1, R2, R2 + MOVWU R2, R2 + SUBSW $1, R5, R5 + BEQ match_extend_back_end_calcBlockSize + JMP match_extend_back_loop_calcBlockSize + +match_extend_back_end_calcBlockSize: + MOVWU R2, R6 + MOVWU 20(RSP), R16 + SUBW R16, R6, R6 + ADD R6, R1, R6 + ADD $5, R6, R6 + MOVD 8(RSP), R16 + CMP R16, R6 + BLO match_dst_size_check_calcBlockSize + MOVD $0x00000000, R16 + MOVD R16, ret+32(FP) + RET + +match_dst_size_check_calcBlockSize: + MOVWU R2, R6 + MOVWU 20(RSP), R7 + CMPW R6, R7 + BEQ emit_literal_done_match_emit_calcBlockSize + MOVWU R6, R8 + MOVW R6, 20(RSP) + ADD R7, R3, R6 + SUBW R7, R8, R8 + SUB $1, R8, R6 + MOVWU R6, R6 + CMPW $0x3c, R6 + BLO one_byte_match_emit_calcBlockSize + CMPW $0x00000100, R6 + BLO two_bytes_match_emit_calcBlockSize + CMPW $0x00010000, R6 + BLO three_bytes_match_emit_calcBlockSize + CMPW $0x01000000, R6 + BLO four_bytes_match_emit_calcBlockSize + ADD $0x05, R1, R1 + JMP memmove_long_match_emit_calcBlockSize + +four_bytes_match_emit_calcBlockSize: + ADD $0x04, R1, R1 + JMP memmove_long_match_emit_calcBlockSize + +three_bytes_match_emit_calcBlockSize: + ADD $0x03, R1, R1 + JMP memmove_long_match_emit_calcBlockSize + +two_bytes_match_emit_calcBlockSize: + ADD $0x02, R1, R1 + CMPW $0x40, R6 + BLO memmove_match_emit_calcBlockSize + JMP memmove_long_match_emit_calcBlockSize + +one_byte_match_emit_calcBlockSize: + ADD $0x01, R1, R1 + +memmove_match_emit_calcBlockSize: + ADD R8, R1, R1 + JMP emit_literal_done_match_emit_calcBlockSize + +memmove_long_match_emit_calcBlockSize: + ADD R8, R1, R1 + +emit_literal_done_match_emit_calcBlockSize: +match_nolit_loop_calcBlockSize: + MOVWU R2, R6 + SUBW R5, R6, R6 + MOVW R6, 24(RSP) + ADDW $0x04, R2, R2 + ADDW $0x04, R5, R5 + MOVD src_len+8(FP), R6 + SUBW R2, R6, R6 + ADD R2, R3, R7 + ADD R5, R3, R5 + + // matchLen + MOVD $0, R9 + +matchlen_loopback_16_match_nolit_calcBlockSize: + CMPW $0x10, R6 + BLO matchlen_match8_match_nolit_calcBlockSize + MOVD (R7)(R9), R8 + ADD R9, R7, R15 + MOVD 8(R15), R10 + MOVD (R5)(R9), R16 + EOR R16, R8, R8 + TST R8, R8 + BNE matchlen_bsf_8_match_nolit_calcBlockSize + ADD R9, R5, R15 + MOVD 8(R15), R16 + EOR R16, R10, R10 + TST R10, R10 + BNE matchlen_bsf_16match_nolit_calcBlockSize + SUB $16, R6, R6 + MOVWU R6, R6 + ADD $16, R9, R9 + MOVWU R9, R9 + JMP matchlen_loopback_16_match_nolit_calcBlockSize + +matchlen_bsf_16match_nolit_calcBlockSize: + RBIT R10, R10 + CLZ R10, R10 + ASR $0x03, R10, R10 + ADD R10, R9, R9 + ADD $8, R9, R9 + MOVWU R9, R9 + JMP match_nolit_end_calcBlockSize + +matchlen_match8_match_nolit_calcBlockSize: + CMPW $0x08, R6 + BLO matchlen_match4_match_nolit_calcBlockSize + MOVD (R7)(R9), R8 + MOVD (R5)(R9), R16 + EOR R16, R8, R8 + TST R8, R8 + BNE matchlen_bsf_8_match_nolit_calcBlockSize + SUB $8, R6, R6 + MOVWU R6, R6 + ADD $8, R9, R9 + MOVWU R9, R9 + JMP matchlen_match4_match_nolit_calcBlockSize + +matchlen_bsf_8_match_nolit_calcBlockSize: + RBIT R8, R8 + CLZ R8, R8 + ASR $0x03, R8, R8 + ADD R8, R9, R9 + MOVWU R9, R9 + JMP match_nolit_end_calcBlockSize + +matchlen_match4_match_nolit_calcBlockSize: + CMPW $0x04, R6 + BLO matchlen_match2_match_nolit_calcBlockSize + MOVWU (R7)(R9), R8 + MOVWU (R5)(R9), R16 + CMPW R8, R16 + BNE matchlen_match2_match_nolit_calcBlockSize + SUB $4, R6, R6 + MOVWU R6, R6 + ADD $4, R9, R9 + MOVWU R9, R9 + +matchlen_match2_match_nolit_calcBlockSize: + CMPW $0x01, R6 + BEQ matchlen_match1_match_nolit_calcBlockSize + BLO match_nolit_end_calcBlockSize + MOVHU (R7)(R9), R16 + BFI $0, R16, $16, R8 + ADD R9, R5, R15 + MOVHU (R15), R15 + AND $0xffff, R8, R16 + CMP R16, R15 + BNE matchlen_match1_match_nolit_calcBlockSize + ADD $2, R9, R9 + MOVWU R9, R9 + SUBSW $0x02, R6, R6 + BEQ match_nolit_end_calcBlockSize + +matchlen_match1_match_nolit_calcBlockSize: + MOVBU (R7)(R9), R16 + BFI $0, R16, $8, R8 + ADD R9, R5, R15 + MOVBU (R15), R15 + AND $0xff, R8, R16 + CMP R16, R15 + BNE match_nolit_end_calcBlockSize + ADD $1, R9, R9 + MOVWU R9, R9 + +match_nolit_end_calcBlockSize: + ADDW R9, R2, R2 + MOVWU 24(RSP), R5 + ADDW $0x04, R9, R9 + MOVW R2, 20(RSP) + + // emitCopy + CMPW $0x00010000, R5 + BLO two_byte_offset_match_nolit_calcBlockSize + +four_bytes_loop_back_match_nolit_calcBlockSize: + CMPW $0x40, R9 + BLS four_bytes_remain_match_nolit_calcBlockSize + SUB $64, R9, R9 + MOVWU R9, R9 + ADD $0x05, R1, R1 + CMPW $0x04, R9 + BLO four_bytes_remain_match_nolit_calcBlockSize + JMP four_bytes_loop_back_match_nolit_calcBlockSize + +four_bytes_remain_match_nolit_calcBlockSize: + TSTW R9, R9 + BEQ match_nolit_emitcopy_end_calcBlockSize + MOVD $0, R5 + ADD $0x05, R1, R1 + JMP match_nolit_emitcopy_end_calcBlockSize + +two_byte_offset_match_nolit_calcBlockSize: + CMPW $0x40, R9 + BLS two_byte_offset_short_match_nolit_calcBlockSize + SUB $60, R9, R9 + MOVWU R9, R9 + ADD $0x03, R1, R1 + JMP two_byte_offset_match_nolit_calcBlockSize + +two_byte_offset_short_match_nolit_calcBlockSize: + MOVWU R9, R6 + LSLW $0x02, R6, R6 + CMPW $0x0c, R9 + BHS emit_copy_three_match_nolit_calcBlockSize + CMPW $0x00000800, R5 + BHS emit_copy_three_match_nolit_calcBlockSize + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_calcBlockSize + +emit_copy_three_match_nolit_calcBlockSize: + ADD $0x03, R1, R1 + +match_nolit_emitcopy_end_calcBlockSize: + MOVWU 16(RSP), R16 + CMPW R16, R2 + BHS emit_remainder_calcBlockSize + ADD R2, R3, R15 + MOVD -2(R15), R6 + MOVD 8(RSP), R16 + CMP R16, R1 + BLO match_nolit_dst_ok_calcBlockSize + MOVD $0x00000000, R16 + MOVD R16, ret+32(FP) + RET + +match_nolit_dst_ok_calcBlockSize: + MOVD $0x0000cf1bbcdcbf9b, R8 + MOVD R6, R7 + LSR $0x10, R6, R6 + MOVD R6, R5 + LSL $0x10, R7, R7 + MUL R8, R7, R7 + LSR $0x33, R7, R7 + LSL $0x10, R5, R5 + MUL R8, R5, R5 + LSR $0x33, R5, R5 + SUB $2, R2, R8 + MOVWU R8, R8 + ADD R5<<2, R0, R9 + MOVWU (R9), R5 + MOVW R8, (R0)(R7<<2) + MOVW R2, (R9) + MOVWU (R3)(R5), R16 + CMPW R6, R16 + BEQ match_nolit_loop_calcBlockSize + ADDW $1, R2, R2 + JMP search_loop_calcBlockSize + +emit_remainder_calcBlockSize: + MOVD src_len+8(FP), R0 + MOVWU 20(RSP), R16 + SUBW R16, R0, R0 + ADD R0, R1, R0 + ADD $5, R0, R0 + MOVD 8(RSP), R16 + CMP R16, R0 + BLO emit_remainder_ok_calcBlockSize + MOVD $0x00000000, R16 + MOVD R16, ret+32(FP) + RET + +emit_remainder_ok_calcBlockSize: + MOVD src_len+8(FP), R0 + MOVWU 20(RSP), R2 + CMPW R0, R2 + BEQ emit_literal_done_emit_remainder_calcBlockSize + MOVWU R0, R5 + MOVW R0, 20(RSP) + ADD R2, R3, R0 + SUBW R2, R5, R5 + SUB $1, R5, R0 + MOVWU R0, R0 + CMPW $0x3c, R0 + BLO one_byte_emit_remainder_calcBlockSize + CMPW $0x00000100, R0 + BLO two_bytes_emit_remainder_calcBlockSize + CMPW $0x00010000, R0 + BLO three_bytes_emit_remainder_calcBlockSize + CMPW $0x01000000, R0 + BLO four_bytes_emit_remainder_calcBlockSize + ADD $0x05, R1, R1 + JMP memmove_long_emit_remainder_calcBlockSize + +four_bytes_emit_remainder_calcBlockSize: + ADD $0x04, R1, R1 + JMP memmove_long_emit_remainder_calcBlockSize + +three_bytes_emit_remainder_calcBlockSize: + ADD $0x03, R1, R1 + JMP memmove_long_emit_remainder_calcBlockSize + +two_bytes_emit_remainder_calcBlockSize: + ADD $0x02, R1, R1 + CMPW $0x40, R0 + BLO memmove_emit_remainder_calcBlockSize + JMP memmove_long_emit_remainder_calcBlockSize + +one_byte_emit_remainder_calcBlockSize: + ADD $0x01, R1, R1 + +memmove_emit_remainder_calcBlockSize: + ADD R5, R1, R0 + MOVD R0, R1 + JMP emit_literal_done_emit_remainder_calcBlockSize + +memmove_long_emit_remainder_calcBlockSize: + ADD R5, R1, R0 + MOVD R0, R1 + +emit_literal_done_emit_remainder_calcBlockSize: + MOVD R1, ret+32(FP) + RET + +// func calcBlockSizeSmall(src []byte, tmp *[2048]byte) int +// Requires: BMI, SSE2 +TEXT ·calcBlockSizeSmall(SB), $24-40 + MOVD tmp+24(FP), R0 + MOVD $0, R1 + MOVD $0x00000010, R2 + MOVD R0, R3 + VEOR V0.B16, V0.B16, V0.B16 + +zero_loop_calcBlockSizeSmall: + FMOVQ F0, (R3) + FMOVQ F0, 16(R3) + FMOVQ F0, 32(R3) + FMOVQ F0, 48(R3) + FMOVQ F0, 64(R3) + FMOVQ F0, 80(R3) + FMOVQ F0, 96(R3) + FMOVQ F0, 112(R3) + ADD $0x80, R3, R3 + SUBS $1, R2, R2 + BNE zero_loop_calcBlockSizeSmall + MOVD $0x00000000, R16 + MOVW R16, 20(RSP) + MOVD src_len+8(FP), R2 + SUB $9, R2, R3 + SUB $8, R2, R5 + MOVW R5, 16(RSP) + LSR $0x05, R2, R2 + SUBW R2, R3, R3 + ADD R3, R1, R3 + MOVD R3, 8(RSP) + MOVD $0x00000001, R2 + MOVW R2, 24(RSP) + MOVD src_base+0(FP), R3 + +search_loop_calcBlockSizeSmall: + MOVWU R2, R5 + MOVWU 20(RSP), R16 + SUBW R16, R5, R5 + LSRW $0x04, R5, R5 + ADD R5, R2, R5 + ADD $4, R5, R5 + MOVWU R5, R5 + MOVWU 16(RSP), R16 + CMPW R16, R5 + BHS emit_remainder_calcBlockSizeSmall + MOVD (R3)(R2), R6 + MOVW R5, 28(RSP) + MOVD $0x9e3779b1, R8 + MOVD R6, R9 + MOVD R6, R10 + LSR $0x08, R10, R10 + LSL $0x20, R9, R9 + MUL R8, R9, R9 + LSR $0x37, R9, R9 + LSL $0x20, R10, R10 + MUL R8, R10, R10 + LSR $0x37, R10, R10 + MOVWU (R0)(R9<<2), R5 + MOVWU (R0)(R10<<2), R7 + MOVW R2, (R0)(R9<<2) + ADD $1, R2, R9 + MOVWU R9, R9 + MOVW R9, (R0)(R10<<2) + MOVD R6, R9 + LSR $0x10, R9, R9 + LSL $0x20, R9, R9 + MUL R8, R9, R9 + LSR $0x37, R9, R9 + MOVWU R2, R8 + MOVWU 24(RSP), R16 + SUBW R16, R8, R8 + ADD R8, R3, R15 + MOVWU 1(R15), R10 + MOVD R6, R8 + LSR $0x08, R8, R8 + CMPW R10, R8 + BNE no_repeat_found_calcBlockSizeSmall + ADD $1, R2, R6 + MOVWU R6, R6 + MOVWU 20(RSP), R5 + MOVWU R6, R7 + MOVWU 24(RSP), R16 + SUBSW R16, R7, R7 + BEQ repeat_extend_back_end_calcBlockSizeSmall + +repeat_extend_back_loop_calcBlockSizeSmall: + CMPW R5, R6 + BLS repeat_extend_back_end_calcBlockSizeSmall + ADD R7, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R8 + ADD R6, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R9 + AND $0xff, R9, R16 + AND $0xff, R8, R15 + CMP R16, R15 + BNE repeat_extend_back_end_calcBlockSizeSmall + SUB $1, R6, R6 + MOVWU R6, R6 + SUBSW $1, R7, R7 + BNE repeat_extend_back_loop_calcBlockSizeSmall + +repeat_extend_back_end_calcBlockSizeSmall: + MOVWU R6, R5 + MOVWU 20(RSP), R16 + SUBW R16, R5, R5 + ADD R5, R1, R5 + ADD $3, R5, R5 + MOVD 8(RSP), R16 + CMP R16, R5 + BLO repeat_dst_size_check_calcBlockSizeSmall + MOVD $0x00000000, R16 + MOVD R16, ret+32(FP) + RET + +repeat_dst_size_check_calcBlockSizeSmall: + MOVWU 20(RSP), R5 + CMPW R6, R5 + BEQ emit_literal_done_repeat_emit_calcBlockSizeSmall + MOVWU R6, R7 + MOVW R6, 20(RSP) + ADD R5, R3, R8 + SUBW R5, R7, R7 + SUB $1, R7, R5 + MOVWU R5, R5 + CMPW $0x3c, R5 + BLO one_byte_repeat_emit_calcBlockSizeSmall + CMPW $0x00000100, R5 + BLO two_bytes_repeat_emit_calcBlockSizeSmall + BLO three_bytes_repeat_emit_calcBlockSizeSmall + +three_bytes_repeat_emit_calcBlockSizeSmall: + ADD $0x03, R1, R1 + JMP memmove_long_repeat_emit_calcBlockSizeSmall + +two_bytes_repeat_emit_calcBlockSizeSmall: + ADD $0x02, R1, R1 + CMPW $0x40, R5 + BLO memmove_repeat_emit_calcBlockSizeSmall + JMP memmove_long_repeat_emit_calcBlockSizeSmall + +one_byte_repeat_emit_calcBlockSizeSmall: + ADD $0x01, R1, R1 + +memmove_repeat_emit_calcBlockSizeSmall: + ADD R7, R1, R1 + JMP emit_literal_done_repeat_emit_calcBlockSizeSmall + +memmove_long_repeat_emit_calcBlockSizeSmall: + ADD R7, R1, R1 + +emit_literal_done_repeat_emit_calcBlockSizeSmall: + ADDW $0x05, R2, R2 + MOVWU R2, R5 + MOVWU 24(RSP), R16 + SUBW R16, R5, R5 + MOVD src_len+8(FP), R7 + SUBW R2, R7, R7 + ADD R2, R3, R8 + ADD R5, R3, R5 + + // matchLen + MOVD $0, R10 + +matchlen_loopback_16_repeat_extend_calcBlockSizeSmall: + CMPW $0x10, R7 + BLO matchlen_match8_repeat_extend_calcBlockSizeSmall + MOVD (R8)(R10), R9 + ADD R10, R8, R15 + MOVD 8(R15), R11 + MOVD (R5)(R10), R16 + EOR R16, R9, R9 + TST R9, R9 + BNE matchlen_bsf_8_repeat_extend_calcBlockSizeSmall + ADD R10, R5, R15 + MOVD 8(R15), R16 + EOR R16, R11, R11 + TST R11, R11 + BNE matchlen_bsf_16repeat_extend_calcBlockSizeSmall + SUB $16, R7, R7 + MOVWU R7, R7 + ADD $16, R10, R10 + MOVWU R10, R10 + JMP matchlen_loopback_16_repeat_extend_calcBlockSizeSmall + +matchlen_bsf_16repeat_extend_calcBlockSizeSmall: + RBIT R11, R11 + CLZ R11, R11 + ASR $0x03, R11, R11 + ADD R11, R10, R10 + ADD $8, R10, R10 + MOVWU R10, R10 + JMP repeat_extend_forward_end_calcBlockSizeSmall + +matchlen_match8_repeat_extend_calcBlockSizeSmall: + CMPW $0x08, R7 + BLO matchlen_match4_repeat_extend_calcBlockSizeSmall + MOVD (R8)(R10), R9 + MOVD (R5)(R10), R16 + EOR R16, R9, R9 + TST R9, R9 + BNE matchlen_bsf_8_repeat_extend_calcBlockSizeSmall + SUB $8, R7, R7 + MOVWU R7, R7 + ADD $8, R10, R10 + MOVWU R10, R10 + JMP matchlen_match4_repeat_extend_calcBlockSizeSmall + +matchlen_bsf_8_repeat_extend_calcBlockSizeSmall: + RBIT R9, R9 + CLZ R9, R9 + ASR $0x03, R9, R9 + ADD R9, R10, R10 + MOVWU R10, R10 + JMP repeat_extend_forward_end_calcBlockSizeSmall + +matchlen_match4_repeat_extend_calcBlockSizeSmall: + CMPW $0x04, R7 + BLO matchlen_match2_repeat_extend_calcBlockSizeSmall + MOVWU (R8)(R10), R9 + MOVWU (R5)(R10), R16 + CMPW R9, R16 + BNE matchlen_match2_repeat_extend_calcBlockSizeSmall + SUB $4, R7, R7 + MOVWU R7, R7 + ADD $4, R10, R10 + MOVWU R10, R10 + +matchlen_match2_repeat_extend_calcBlockSizeSmall: + CMPW $0x01, R7 + BEQ matchlen_match1_repeat_extend_calcBlockSizeSmall + BLO repeat_extend_forward_end_calcBlockSizeSmall + MOVHU (R8)(R10), R16 + BFI $0, R16, $16, R9 + ADD R10, R5, R15 + MOVHU (R15), R15 + AND $0xffff, R9, R16 + CMP R16, R15 + BNE matchlen_match1_repeat_extend_calcBlockSizeSmall + ADD $2, R10, R10 + MOVWU R10, R10 + SUBSW $0x02, R7, R7 + BEQ repeat_extend_forward_end_calcBlockSizeSmall + +matchlen_match1_repeat_extend_calcBlockSizeSmall: + MOVBU (R8)(R10), R16 + BFI $0, R16, $8, R9 + ADD R10, R5, R15 + MOVBU (R15), R15 + AND $0xff, R9, R16 + CMP R16, R15 + BNE repeat_extend_forward_end_calcBlockSizeSmall + ADD $1, R10, R10 + MOVWU R10, R10 + +repeat_extend_forward_end_calcBlockSizeSmall: + ADDW R10, R2, R2 + MOVWU R2, R5 + SUBW R6, R5, R5 + MOVWU 24(RSP), R6 + + // emitCopy +two_byte_offset_repeat_as_copy_calcBlockSizeSmall: + CMPW $0x40, R5 + BLS two_byte_offset_short_repeat_as_copy_calcBlockSizeSmall + SUB $60, R5, R5 + MOVWU R5, R5 + ADD $0x03, R1, R1 + JMP two_byte_offset_repeat_as_copy_calcBlockSizeSmall + +two_byte_offset_short_repeat_as_copy_calcBlockSizeSmall: + MOVWU R5, R6 + LSLW $0x02, R6, R6 + CMPW $0x0c, R5 + BHS emit_copy_three_repeat_as_copy_calcBlockSizeSmall + ADD $0x02, R1, R1 + JMP repeat_end_emit_calcBlockSizeSmall + +emit_copy_three_repeat_as_copy_calcBlockSizeSmall: + ADD $0x03, R1, R1 + +repeat_end_emit_calcBlockSizeSmall: + MOVW R2, 20(RSP) + JMP search_loop_calcBlockSizeSmall + +no_repeat_found_calcBlockSizeSmall: + MOVWU (R3)(R5), R16 + CMPW R6, R16 + BEQ candidate_match_calcBlockSizeSmall + LSR $0x08, R6, R6 + MOVWU (R0)(R9<<2), R5 + ADD $2, R2, R8 + MOVWU R8, R8 + MOVWU (R3)(R7), R16 + CMPW R6, R16 + BEQ candidate2_match_calcBlockSizeSmall + MOVW R8, (R0)(R9<<2) + LSR $0x08, R6, R6 + MOVWU (R3)(R5), R16 + CMPW R6, R16 + BEQ candidate3_match_calcBlockSizeSmall + MOVWU 28(RSP), R2 + JMP search_loop_calcBlockSizeSmall + +candidate3_match_calcBlockSizeSmall: + ADDW $0x02, R2, R2 + JMP candidate_match_calcBlockSizeSmall + +candidate2_match_calcBlockSizeSmall: + MOVW R8, (R0)(R9<<2) + ADDW $1, R2, R2 + MOVWU R7, R5 + +candidate_match_calcBlockSizeSmall: + MOVWU 20(RSP), R6 + TSTW R5, R5 + BEQ match_extend_back_end_calcBlockSizeSmall + +match_extend_back_loop_calcBlockSizeSmall: + CMPW R6, R2 + BLS match_extend_back_end_calcBlockSizeSmall + ADD R5, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R7 + ADD R2, R3, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R8 + AND $0xff, R8, R16 + AND $0xff, R7, R15 + CMP R16, R15 + BNE match_extend_back_end_calcBlockSizeSmall + SUB $1, R2, R2 + MOVWU R2, R2 + SUBSW $1, R5, R5 + BEQ match_extend_back_end_calcBlockSizeSmall + JMP match_extend_back_loop_calcBlockSizeSmall + +match_extend_back_end_calcBlockSizeSmall: + MOVWU R2, R6 + MOVWU 20(RSP), R16 + SUBW R16, R6, R6 + ADD R6, R1, R6 + ADD $3, R6, R6 + MOVD 8(RSP), R16 + CMP R16, R6 + BLO match_dst_size_check_calcBlockSizeSmall + MOVD $0x00000000, R16 + MOVD R16, ret+32(FP) + RET + +match_dst_size_check_calcBlockSizeSmall: + MOVWU R2, R6 + MOVWU 20(RSP), R7 + CMPW R6, R7 + BEQ emit_literal_done_match_emit_calcBlockSizeSmall + MOVWU R6, R8 + MOVW R6, 20(RSP) + ADD R7, R3, R6 + SUBW R7, R8, R8 + SUB $1, R8, R6 + MOVWU R6, R6 + CMPW $0x3c, R6 + BLO one_byte_match_emit_calcBlockSizeSmall + CMPW $0x00000100, R6 + BLO two_bytes_match_emit_calcBlockSizeSmall + BLO three_bytes_match_emit_calcBlockSizeSmall + +three_bytes_match_emit_calcBlockSizeSmall: + ADD $0x03, R1, R1 + JMP memmove_long_match_emit_calcBlockSizeSmall + +two_bytes_match_emit_calcBlockSizeSmall: + ADD $0x02, R1, R1 + CMPW $0x40, R6 + BLO memmove_match_emit_calcBlockSizeSmall + JMP memmove_long_match_emit_calcBlockSizeSmall + +one_byte_match_emit_calcBlockSizeSmall: + ADD $0x01, R1, R1 + +memmove_match_emit_calcBlockSizeSmall: + ADD R8, R1, R1 + JMP emit_literal_done_match_emit_calcBlockSizeSmall + +memmove_long_match_emit_calcBlockSizeSmall: + ADD R8, R1, R1 + +emit_literal_done_match_emit_calcBlockSizeSmall: +match_nolit_loop_calcBlockSizeSmall: + MOVWU R2, R6 + SUBW R5, R6, R6 + MOVW R6, 24(RSP) + ADDW $0x04, R2, R2 + ADDW $0x04, R5, R5 + MOVD src_len+8(FP), R6 + SUBW R2, R6, R6 + ADD R2, R3, R7 + ADD R5, R3, R5 + + // matchLen + MOVD $0, R9 + +matchlen_loopback_16_match_nolit_calcBlockSizeSmall: + CMPW $0x10, R6 + BLO matchlen_match8_match_nolit_calcBlockSizeSmall + MOVD (R7)(R9), R8 + ADD R9, R7, R15 + MOVD 8(R15), R10 + MOVD (R5)(R9), R16 + EOR R16, R8, R8 + TST R8, R8 + BNE matchlen_bsf_8_match_nolit_calcBlockSizeSmall + ADD R9, R5, R15 + MOVD 8(R15), R16 + EOR R16, R10, R10 + TST R10, R10 + BNE matchlen_bsf_16match_nolit_calcBlockSizeSmall + SUB $16, R6, R6 + MOVWU R6, R6 + ADD $16, R9, R9 + MOVWU R9, R9 + JMP matchlen_loopback_16_match_nolit_calcBlockSizeSmall + +matchlen_bsf_16match_nolit_calcBlockSizeSmall: + RBIT R10, R10 + CLZ R10, R10 + ASR $0x03, R10, R10 + ADD R10, R9, R9 + ADD $8, R9, R9 + MOVWU R9, R9 + JMP match_nolit_end_calcBlockSizeSmall + +matchlen_match8_match_nolit_calcBlockSizeSmall: + CMPW $0x08, R6 + BLO matchlen_match4_match_nolit_calcBlockSizeSmall + MOVD (R7)(R9), R8 + MOVD (R5)(R9), R16 + EOR R16, R8, R8 + TST R8, R8 + BNE matchlen_bsf_8_match_nolit_calcBlockSizeSmall + SUB $8, R6, R6 + MOVWU R6, R6 + ADD $8, R9, R9 + MOVWU R9, R9 + JMP matchlen_match4_match_nolit_calcBlockSizeSmall + +matchlen_bsf_8_match_nolit_calcBlockSizeSmall: + RBIT R8, R8 + CLZ R8, R8 + ASR $0x03, R8, R8 + ADD R8, R9, R9 + MOVWU R9, R9 + JMP match_nolit_end_calcBlockSizeSmall + +matchlen_match4_match_nolit_calcBlockSizeSmall: + CMPW $0x04, R6 + BLO matchlen_match2_match_nolit_calcBlockSizeSmall + MOVWU (R7)(R9), R8 + MOVWU (R5)(R9), R16 + CMPW R8, R16 + BNE matchlen_match2_match_nolit_calcBlockSizeSmall + SUB $4, R6, R6 + MOVWU R6, R6 + ADD $4, R9, R9 + MOVWU R9, R9 + +matchlen_match2_match_nolit_calcBlockSizeSmall: + CMPW $0x01, R6 + BEQ matchlen_match1_match_nolit_calcBlockSizeSmall + BLO match_nolit_end_calcBlockSizeSmall + MOVHU (R7)(R9), R16 + BFI $0, R16, $16, R8 + ADD R9, R5, R15 + MOVHU (R15), R15 + AND $0xffff, R8, R16 + CMP R16, R15 + BNE matchlen_match1_match_nolit_calcBlockSizeSmall + ADD $2, R9, R9 + MOVWU R9, R9 + SUBSW $0x02, R6, R6 + BEQ match_nolit_end_calcBlockSizeSmall + +matchlen_match1_match_nolit_calcBlockSizeSmall: + MOVBU (R7)(R9), R16 + BFI $0, R16, $8, R8 + ADD R9, R5, R15 + MOVBU (R15), R15 + AND $0xff, R8, R16 + CMP R16, R15 + BNE match_nolit_end_calcBlockSizeSmall + ADD $1, R9, R9 + MOVWU R9, R9 + +match_nolit_end_calcBlockSizeSmall: + ADDW R9, R2, R2 + MOVWU 24(RSP), R5 + ADDW $0x04, R9, R9 + MOVW R2, 20(RSP) + + // emitCopy +two_byte_offset_match_nolit_calcBlockSizeSmall: + CMPW $0x40, R9 + BLS two_byte_offset_short_match_nolit_calcBlockSizeSmall + SUB $60, R9, R9 + MOVWU R9, R9 + ADD $0x03, R1, R1 + JMP two_byte_offset_match_nolit_calcBlockSizeSmall + +two_byte_offset_short_match_nolit_calcBlockSizeSmall: + MOVWU R9, R5 + LSLW $0x02, R5, R5 + CMPW $0x0c, R9 + BHS emit_copy_three_match_nolit_calcBlockSizeSmall + ADD $0x02, R1, R1 + JMP match_nolit_emitcopy_end_calcBlockSizeSmall + +emit_copy_three_match_nolit_calcBlockSizeSmall: + ADD $0x03, R1, R1 + +match_nolit_emitcopy_end_calcBlockSizeSmall: + MOVWU 16(RSP), R16 + CMPW R16, R2 + BHS emit_remainder_calcBlockSizeSmall + ADD R2, R3, R15 + MOVD -2(R15), R6 + MOVD 8(RSP), R16 + CMP R16, R1 + BLO match_nolit_dst_ok_calcBlockSizeSmall + MOVD $0x00000000, R16 + MOVD R16, ret+32(FP) + RET + +match_nolit_dst_ok_calcBlockSizeSmall: + MOVD $0x9e3779b1, R8 + MOVD R6, R7 + LSR $0x10, R6, R6 + MOVD R6, R5 + LSL $0x20, R7, R7 + MUL R8, R7, R7 + LSR $0x37, R7, R7 + LSL $0x20, R5, R5 + MUL R8, R5, R5 + LSR $0x37, R5, R5 + SUB $2, R2, R8 + MOVWU R8, R8 + ADD R5<<2, R0, R9 + MOVWU (R9), R5 + MOVW R8, (R0)(R7<<2) + MOVW R2, (R9) + MOVWU (R3)(R5), R16 + CMPW R6, R16 + BEQ match_nolit_loop_calcBlockSizeSmall + ADDW $1, R2, R2 + JMP search_loop_calcBlockSizeSmall + +emit_remainder_calcBlockSizeSmall: + MOVD src_len+8(FP), R0 + MOVWU 20(RSP), R16 + SUBW R16, R0, R0 + ADD R0, R1, R0 + ADD $3, R0, R0 + MOVD 8(RSP), R16 + CMP R16, R0 + BLO emit_remainder_ok_calcBlockSizeSmall + MOVD $0x00000000, R16 + MOVD R16, ret+32(FP) + RET + +emit_remainder_ok_calcBlockSizeSmall: + MOVD src_len+8(FP), R0 + MOVWU 20(RSP), R2 + CMPW R0, R2 + BEQ emit_literal_done_emit_remainder_calcBlockSizeSmall + MOVWU R0, R5 + MOVW R0, 20(RSP) + ADD R2, R3, R0 + SUBW R2, R5, R5 + SUB $1, R5, R0 + MOVWU R0, R0 + CMPW $0x3c, R0 + BLO one_byte_emit_remainder_calcBlockSizeSmall + CMPW $0x00000100, R0 + BLO two_bytes_emit_remainder_calcBlockSizeSmall + BLO three_bytes_emit_remainder_calcBlockSizeSmall + +three_bytes_emit_remainder_calcBlockSizeSmall: + ADD $0x03, R1, R1 + JMP memmove_long_emit_remainder_calcBlockSizeSmall + +two_bytes_emit_remainder_calcBlockSizeSmall: + ADD $0x02, R1, R1 + CMPW $0x40, R0 + BLO memmove_emit_remainder_calcBlockSizeSmall + JMP memmove_long_emit_remainder_calcBlockSizeSmall + +one_byte_emit_remainder_calcBlockSizeSmall: + ADD $0x01, R1, R1 + +memmove_emit_remainder_calcBlockSizeSmall: + ADD R5, R1, R0 + MOVD R0, R1 + JMP emit_literal_done_emit_remainder_calcBlockSizeSmall + +memmove_long_emit_remainder_calcBlockSizeSmall: + ADD R5, R1, R0 + MOVD R0, R1 + +emit_literal_done_emit_remainder_calcBlockSizeSmall: + MOVD R1, ret+32(FP) + RET + +// func emitLiteral(dst []byte, lit []byte) int +// Requires: SSE2 +TEXT ·emitLiteral(SB), NOSPLIT, $0-56 + MOVD lit_len+32(FP), R2 + MOVD dst_base+0(FP), R0 + MOVD lit_base+24(FP), R1 + TST R2, R2 + BEQ emit_literal_end_standalone_skip + MOVWU R2, R3 + SUB $1, R2, R5 + MOVWU R5, R5 + CMPW $0x3c, R5 + BLO one_byte_standalone + CMPW $0x00000100, R5 + BLO two_bytes_standalone + CMPW $0x00010000, R5 + BLO three_bytes_standalone + CMPW $0x01000000, R5 + BLO four_bytes_standalone + MOVD $0xfc, R16 + MOVB R16, (R0) + MOVW R5, 1(R0) + ADD $0x05, R3, R3 + ADD $0x05, R0, R0 + JMP memmove_long_standalone + +four_bytes_standalone: + MOVWU R5, R6 + LSRW $0x10, R6, R6 + MOVD $0xf8, R16 + MOVB R16, (R0) + MOVH R5, 1(R0) + MOVB R6, 3(R0) + ADD $0x04, R3, R3 + ADD $0x04, R0, R0 + JMP memmove_long_standalone + +three_bytes_standalone: + MOVD $0xf4, R16 + MOVB R16, (R0) + MOVH R5, 1(R0) + ADD $0x03, R3, R3 + ADD $0x03, R0, R0 + JMP memmove_long_standalone + +two_bytes_standalone: + MOVD $0xf0, R16 + MOVB R16, (R0) + MOVB R5, 1(R0) + ADD $0x02, R3, R3 + ADD $0x02, R0, R0 + CMPW $0x40, R5 + BLO memmove_standalone + JMP memmove_long_standalone + +one_byte_standalone: + LSLW $0x02, R5, R16 + BFI $0, R16, $8, R5 + MOVB R5, (R0) + ADD $0x01, R3, R3 + ADD $0x01, R0, R0 + +memmove_standalone: + // genMemMoveShort + CMP $0x03, R2 + BLO emit_lit_memmove_standalone_memmove_move_1or2 + BEQ emit_lit_memmove_standalone_memmove_move_3 + CMP $0x08, R2 + BLO emit_lit_memmove_standalone_memmove_move_4through7 + CMP $0x10, R2 + BLS emit_lit_memmove_standalone_memmove_move_8through16 + CMP $0x20, R2 + BLS emit_lit_memmove_standalone_memmove_move_17through32 + JMP emit_lit_memmove_standalone_memmove_move_33through64 + +emit_lit_memmove_standalone_memmove_move_1or2: + MOVBU (R1), R16 + BFI $0, R16, $8, R5 + ADD R2, R1, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R1 + MOVB R5, (R0) + ADD R2, R0, R15 + MOVB R1, -1(R15) + JMP emit_literal_end_standalone + +emit_lit_memmove_standalone_memmove_move_3: + MOVHU (R1), R16 + BFI $0, R16, $16, R5 + MOVBU 2(R1), R16 + BFI $0, R16, $8, R1 + MOVH R5, (R0) + MOVB R1, 2(R0) + JMP emit_literal_end_standalone + +emit_lit_memmove_standalone_memmove_move_4through7: + MOVWU (R1), R5 + ADD R2, R1, R15 + MOVWU -4(R15), R1 + MOVW R5, (R0) + ADD R2, R0, R15 + MOVW R1, -4(R15) + JMP emit_literal_end_standalone + +emit_lit_memmove_standalone_memmove_move_8through16: + MOVD (R1), R5 + ADD R2, R1, R15 + MOVD -8(R15), R1 + MOVD R5, (R0) + ADD R2, R0, R15 + MOVD R1, -8(R15) + JMP emit_literal_end_standalone + +emit_lit_memmove_standalone_memmove_move_17through32: + FMOVQ (R1), F0 + ADD R2, R1, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R0) + ADD R2, R0, R15 + FMOVQ F1, -16(R15) + JMP emit_literal_end_standalone + +emit_lit_memmove_standalone_memmove_move_33through64: + FMOVQ (R1), F0 + FMOVQ 16(R1), F1 + ADD R2, R1, R15 + FMOVQ -32(R15), F2 + ADD R2, R1, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R0) + FMOVQ F1, 16(R0) + ADD R2, R0, R15 + FMOVQ F2, -32(R15) + ADD R2, R0, R15 + FMOVQ F3, -16(R15) + JMP emit_literal_end_standalone + JMP emit_literal_end_standalone + +memmove_long_standalone: + // genMemMoveLong + MOVD R1, R5 + MOVD R0, R6 + MOVD R2, R7 + +emit_lit_memmove_long_standalonelarge_big_loop_back: + FMOVQ (R5), F0 + FMOVQ 16(R5), F1 + FMOVQ F0, (R6) + FMOVQ F1, 16(R6) + ADD $0x20, R5, R5 + ADD $0x20, R6, R6 + SUB $0x20, R7, R7 + CMP $0x20, R7 + BHS emit_lit_memmove_long_standalonelarge_big_loop_back + ADD R2, R1, R15 + FMOVQ -32(R15), F0 + ADD R2, R1, R15 + FMOVQ -16(R15), F1 + ADD R2, R0, R15 + FMOVQ F0, -32(R15) + ADD R2, R0, R15 + FMOVQ F1, -16(R15) + JMP emit_literal_end_standalone + JMP emit_literal_end_standalone + +emit_literal_end_standalone_skip: + MOVD $0, R3 + +emit_literal_end_standalone: + MOVD R3, ret+48(FP) + RET + +// func emitRepeat(dst []byte, offset int, length int) int +TEXT ·emitRepeat(SB), NOSPLIT, $0-48 + MOVD $0, R3 + MOVD dst_base+0(FP), R0 + MOVD offset+24(FP), R1 + MOVD length+32(FP), R2 + + // emitRepeat +emit_repeat_again_standalone: + MOVWU R2, R5 + SUB $4, R2, R2 + MOVWU R2, R2 + CMPW $0x08, R5 + BLS repeat_two_standalone + CMPW $0x0c, R5 + BHS cant_repeat_two_offset_standalone + CMPW $0x00000800, R1 + BLO repeat_two_offset_standalone + +cant_repeat_two_offset_standalone: + CMPW $0x00000104, R2 + BLO repeat_three_standalone + CMPW $0x00010100, R2 + BLO repeat_four_standalone + CMPW $0x0100ffff, R2 + BLO repeat_five_standalone + SUB $16842747, R2, R2 + MOVWU R2, R2 + MOVD $0xfffb001d, R16 + MOVW R16, (R0) + MOVD $0xff, R16 + MOVB R16, 4(R0) + ADD $0x05, R0, R0 + ADD $0x05, R3, R3 + JMP emit_repeat_again_standalone + +repeat_five_standalone: + SUB $65536, R2, R2 + MOVWU R2, R2 + MOVWU R2, R1 + MOVD $0x001d, R16 + MOVH R16, (R0) + MOVH R2, 2(R0) + ASRW $0x10, R1, R1 + MOVB R1, 4(R0) + ADD $0x05, R3, R3 + ADD $0x05, R0, R0 + JMP gen_emit_repeat_end + +repeat_four_standalone: + SUB $256, R2, R2 + MOVWU R2, R2 + MOVD $0x0019, R16 + MOVH R16, (R0) + MOVH R2, 2(R0) + ADD $0x04, R3, R3 + ADD $0x04, R0, R0 + JMP gen_emit_repeat_end + +repeat_three_standalone: + SUB $4, R2, R2 + MOVWU R2, R2 + MOVD $0x0015, R16 + MOVH R16, (R0) + MOVB R2, 2(R0) + ADD $0x03, R3, R3 + ADD $0x03, R0, R0 + JMP gen_emit_repeat_end + +repeat_two_standalone: + LSLW $0x02, R2, R2 + ORRW $0x01, R2, R2 + MOVH R2, (R0) + ADD $0x02, R3, R3 + ADD $0x02, R0, R0 + JMP gen_emit_repeat_end + +repeat_two_offset_standalone: + MOVD $0, R5 + ADD R2<<2, R5, R2 + ADD $1, R2, R2 + MOVWU R2, R2 + MOVB R1, 1(R0) + ASRW $0x08, R1, R1 + LSLW $0x05, R1, R1 + ORRW R1, R2, R2 + MOVB R2, (R0) + ADD $0x02, R3, R3 + ADD $0x02, R0, R0 + +gen_emit_repeat_end: + MOVD R3, ret+40(FP) + RET + +// func emitCopy(dst []byte, offset int, length int) int +TEXT ·emitCopy(SB), NOSPLIT, $0-48 + MOVD $0, R3 + MOVD dst_base+0(FP), R0 + MOVD offset+24(FP), R1 + MOVD length+32(FP), R2 + + // emitCopy + CMPW $0x00010000, R1 + BLO two_byte_offset_standalone + CMPW $0x40, R2 + BLS four_bytes_remain_standalone + MOVD $0xff, R16 + MOVB R16, (R0) + MOVW R1, 1(R0) + SUB $64, R2, R2 + MOVWU R2, R2 + ADD $0x05, R3, R3 + ADD $0x05, R0, R0 + CMPW $0x04, R2 + BLO four_bytes_remain_standalone + + // emitRepeat +emit_repeat_again_standalone_emit_copy: + MOVWU R2, R5 + SUB $4, R2, R2 + MOVWU R2, R2 + CMPW $0x08, R5 + BLS repeat_two_standalone_emit_copy + CMPW $0x0c, R5 + BHS cant_repeat_two_offset_standalone_emit_copy + CMPW $0x00000800, R1 + BLO repeat_two_offset_standalone_emit_copy + +cant_repeat_two_offset_standalone_emit_copy: + CMPW $0x00000104, R2 + BLO repeat_three_standalone_emit_copy + CMPW $0x00010100, R2 + BLO repeat_four_standalone_emit_copy + CMPW $0x0100ffff, R2 + BLO repeat_five_standalone_emit_copy + SUB $16842747, R2, R2 + MOVWU R2, R2 + MOVD $0xfffb001d, R16 + MOVW R16, (R0) + MOVD $0xff, R16 + MOVB R16, 4(R0) + ADD $0x05, R0, R0 + ADD $0x05, R3, R3 + JMP emit_repeat_again_standalone_emit_copy + +repeat_five_standalone_emit_copy: + SUB $65536, R2, R2 + MOVWU R2, R2 + MOVWU R2, R1 + MOVD $0x001d, R16 + MOVH R16, (R0) + MOVH R2, 2(R0) + ASRW $0x10, R1, R1 + MOVB R1, 4(R0) + ADD $0x05, R3, R3 + ADD $0x05, R0, R0 + JMP gen_emit_copy_end + +repeat_four_standalone_emit_copy: + SUB $256, R2, R2 + MOVWU R2, R2 + MOVD $0x0019, R16 + MOVH R16, (R0) + MOVH R2, 2(R0) + ADD $0x04, R3, R3 + ADD $0x04, R0, R0 + JMP gen_emit_copy_end + +repeat_three_standalone_emit_copy: + SUB $4, R2, R2 + MOVWU R2, R2 + MOVD $0x0015, R16 + MOVH R16, (R0) + MOVB R2, 2(R0) + ADD $0x03, R3, R3 + ADD $0x03, R0, R0 + JMP gen_emit_copy_end + +repeat_two_standalone_emit_copy: + LSLW $0x02, R2, R2 + ORRW $0x01, R2, R2 + MOVH R2, (R0) + ADD $0x02, R3, R3 + ADD $0x02, R0, R0 + JMP gen_emit_copy_end + +repeat_two_offset_standalone_emit_copy: + MOVD $0, R5 + ADD R2<<2, R5, R2 + ADD $1, R2, R2 + MOVWU R2, R2 + MOVB R1, 1(R0) + ASRW $0x08, R1, R1 + LSLW $0x05, R1, R1 + ORRW R1, R2, R2 + MOVB R2, (R0) + ADD $0x02, R3, R3 + ADD $0x02, R0, R0 + JMP gen_emit_copy_end + +four_bytes_remain_standalone: + TSTW R2, R2 + BEQ gen_emit_copy_end + MOVD $0, R5 + ADD R2<<2, R5, R2 + SUB $1, R2, R2 + MOVWU R2, R2 + MOVB R2, (R0) + MOVW R1, 1(R0) + ADD $0x05, R3, R3 + ADD $0x05, R0, R0 + JMP gen_emit_copy_end + +two_byte_offset_standalone: + CMPW $0x40, R2 + BLS two_byte_offset_short_standalone + CMPW $0x00000800, R1 + BHS long_offset_short_standalone + MOVD $0x00000001, R5 + ADD $16, R5, R5 + MOVWU R5, R5 + MOVB R1, 1(R0) + MOVWU R1, R6 + LSRW $0x08, R6, R6 + LSLW $0x05, R6, R6 + ORRW R6, R5, R5 + MOVB R5, (R0) + ADD $0x02, R3, R3 + ADD $0x02, R0, R0 + SUBW $0x08, R2, R2 + + // emitRepeat + SUB $4, R2, R2 + MOVWU R2, R2 + JMP cant_repeat_two_offset_standalone_emit_copy_short_2b + +emit_repeat_again_standalone_emit_copy_short_2b: + MOVWU R2, R5 + SUB $4, R2, R2 + MOVWU R2, R2 + CMPW $0x08, R5 + BLS repeat_two_standalone_emit_copy_short_2b + CMPW $0x0c, R5 + BHS cant_repeat_two_offset_standalone_emit_copy_short_2b + CMPW $0x00000800, R1 + BLO repeat_two_offset_standalone_emit_copy_short_2b + +cant_repeat_two_offset_standalone_emit_copy_short_2b: + CMPW $0x00000104, R2 + BLO repeat_three_standalone_emit_copy_short_2b + CMPW $0x00010100, R2 + BLO repeat_four_standalone_emit_copy_short_2b + CMPW $0x0100ffff, R2 + BLO repeat_five_standalone_emit_copy_short_2b + SUB $16842747, R2, R2 + MOVWU R2, R2 + MOVD $0xfffb001d, R16 + MOVW R16, (R0) + MOVD $0xff, R16 + MOVB R16, 4(R0) + ADD $0x05, R0, R0 + ADD $0x05, R3, R3 + JMP emit_repeat_again_standalone_emit_copy_short_2b + +repeat_five_standalone_emit_copy_short_2b: + SUB $65536, R2, R2 + MOVWU R2, R2 + MOVWU R2, R1 + MOVD $0x001d, R16 + MOVH R16, (R0) + MOVH R2, 2(R0) + ASRW $0x10, R1, R1 + MOVB R1, 4(R0) + ADD $0x05, R3, R3 + ADD $0x05, R0, R0 + JMP gen_emit_copy_end + +repeat_four_standalone_emit_copy_short_2b: + SUB $256, R2, R2 + MOVWU R2, R2 + MOVD $0x0019, R16 + MOVH R16, (R0) + MOVH R2, 2(R0) + ADD $0x04, R3, R3 + ADD $0x04, R0, R0 + JMP gen_emit_copy_end + +repeat_three_standalone_emit_copy_short_2b: + SUB $4, R2, R2 + MOVWU R2, R2 + MOVD $0x0015, R16 + MOVH R16, (R0) + MOVB R2, 2(R0) + ADD $0x03, R3, R3 + ADD $0x03, R0, R0 + JMP gen_emit_copy_end + +repeat_two_standalone_emit_copy_short_2b: + LSLW $0x02, R2, R2 + ORRW $0x01, R2, R2 + MOVH R2, (R0) + ADD $0x02, R3, R3 + ADD $0x02, R0, R0 + JMP gen_emit_copy_end + +repeat_two_offset_standalone_emit_copy_short_2b: + MOVD $0, R5 + ADD R2<<2, R5, R2 + ADD $1, R2, R2 + MOVWU R2, R2 + MOVB R1, 1(R0) + ASRW $0x08, R1, R1 + LSLW $0x05, R1, R1 + ORRW R1, R2, R2 + MOVB R2, (R0) + ADD $0x02, R3, R3 + ADD $0x02, R0, R0 + JMP gen_emit_copy_end + +long_offset_short_standalone: + MOVD $0xee, R16 + MOVB R16, (R0) + MOVH R1, 1(R0) + SUB $60, R2, R2 + MOVWU R2, R2 + ADD $0x03, R0, R0 + ADD $0x03, R3, R3 + + // emitRepeat +emit_repeat_again_standalone_emit_copy_short: + MOVWU R2, R5 + SUB $4, R2, R2 + MOVWU R2, R2 + CMPW $0x08, R5 + BLS repeat_two_standalone_emit_copy_short + CMPW $0x0c, R5 + BHS cant_repeat_two_offset_standalone_emit_copy_short + CMPW $0x00000800, R1 + BLO repeat_two_offset_standalone_emit_copy_short + +cant_repeat_two_offset_standalone_emit_copy_short: + CMPW $0x00000104, R2 + BLO repeat_three_standalone_emit_copy_short + CMPW $0x00010100, R2 + BLO repeat_four_standalone_emit_copy_short + CMPW $0x0100ffff, R2 + BLO repeat_five_standalone_emit_copy_short + SUB $16842747, R2, R2 + MOVWU R2, R2 + MOVD $0xfffb001d, R16 + MOVW R16, (R0) + MOVD $0xff, R16 + MOVB R16, 4(R0) + ADD $0x05, R0, R0 + ADD $0x05, R3, R3 + JMP emit_repeat_again_standalone_emit_copy_short + +repeat_five_standalone_emit_copy_short: + SUB $65536, R2, R2 + MOVWU R2, R2 + MOVWU R2, R1 + MOVD $0x001d, R16 + MOVH R16, (R0) + MOVH R2, 2(R0) + ASRW $0x10, R1, R1 + MOVB R1, 4(R0) + ADD $0x05, R3, R3 + ADD $0x05, R0, R0 + JMP gen_emit_copy_end + +repeat_four_standalone_emit_copy_short: + SUB $256, R2, R2 + MOVWU R2, R2 + MOVD $0x0019, R16 + MOVH R16, (R0) + MOVH R2, 2(R0) + ADD $0x04, R3, R3 + ADD $0x04, R0, R0 + JMP gen_emit_copy_end + +repeat_three_standalone_emit_copy_short: + SUB $4, R2, R2 + MOVWU R2, R2 + MOVD $0x0015, R16 + MOVH R16, (R0) + MOVB R2, 2(R0) + ADD $0x03, R3, R3 + ADD $0x03, R0, R0 + JMP gen_emit_copy_end + +repeat_two_standalone_emit_copy_short: + LSLW $0x02, R2, R2 + ORRW $0x01, R2, R2 + MOVH R2, (R0) + ADD $0x02, R3, R3 + ADD $0x02, R0, R0 + JMP gen_emit_copy_end + +repeat_two_offset_standalone_emit_copy_short: + MOVD $0, R5 + ADD R2<<2, R5, R2 + ADD $1, R2, R2 + MOVWU R2, R2 + MOVB R1, 1(R0) + ASRW $0x08, R1, R1 + LSLW $0x05, R1, R1 + ORRW R1, R2, R2 + MOVB R2, (R0) + ADD $0x02, R3, R3 + ADD $0x02, R0, R0 + JMP gen_emit_copy_end + +two_byte_offset_short_standalone: + MOVWU R2, R5 + LSLW $0x02, R5, R5 + CMPW $0x0c, R2 + BHS emit_copy_three_standalone + CMPW $0x00000800, R1 + BHS emit_copy_three_standalone + SUB $15, R5, R5 + MOVWU R5, R5 + MOVB R1, 1(R0) + LSRW $0x08, R1, R1 + LSLW $0x05, R1, R1 + ORRW R1, R5, R5 + MOVB R5, (R0) + ADD $0x02, R3, R3 + ADD $0x02, R0, R0 + JMP gen_emit_copy_end + +emit_copy_three_standalone: + SUB $2, R5, R5 + MOVWU R5, R5 + MOVB R5, (R0) + MOVH R1, 1(R0) + ADD $0x03, R3, R3 + ADD $0x03, R0, R0 + +gen_emit_copy_end: + MOVD R3, ret+40(FP) + RET + +// func emitCopyNoRepeat(dst []byte, offset int, length int) int +TEXT ·emitCopyNoRepeat(SB), NOSPLIT, $0-48 + MOVD $0, R3 + MOVD dst_base+0(FP), R0 + MOVD offset+24(FP), R1 + MOVD length+32(FP), R2 + + // emitCopy + CMPW $0x00010000, R1 + BLO two_byte_offset_standalone_snappy + +four_bytes_loop_back_standalone_snappy: + CMPW $0x40, R2 + BLS four_bytes_remain_standalone_snappy + MOVD $0xff, R16 + MOVB R16, (R0) + MOVW R1, 1(R0) + SUB $64, R2, R2 + MOVWU R2, R2 + ADD $0x05, R3, R3 + ADD $0x05, R0, R0 + CMPW $0x04, R2 + BLO four_bytes_remain_standalone_snappy + JMP four_bytes_loop_back_standalone_snappy + +four_bytes_remain_standalone_snappy: + TSTW R2, R2 + BEQ gen_emit_copy_end_snappy + MOVD $0, R5 + ADD R2<<2, R5, R2 + SUB $1, R2, R2 + MOVWU R2, R2 + MOVB R2, (R0) + MOVW R1, 1(R0) + ADD $0x05, R3, R3 + ADD $0x05, R0, R0 + JMP gen_emit_copy_end_snappy + +two_byte_offset_standalone_snappy: + CMPW $0x40, R2 + BLS two_byte_offset_short_standalone_snappy + MOVD $0xee, R16 + MOVB R16, (R0) + MOVH R1, 1(R0) + SUB $60, R2, R2 + MOVWU R2, R2 + ADD $0x03, R0, R0 + ADD $0x03, R3, R3 + JMP two_byte_offset_standalone_snappy + +two_byte_offset_short_standalone_snappy: + MOVWU R2, R5 + LSLW $0x02, R5, R5 + CMPW $0x0c, R2 + BHS emit_copy_three_standalone_snappy + CMPW $0x00000800, R1 + BHS emit_copy_three_standalone_snappy + SUB $15, R5, R5 + MOVWU R5, R5 + MOVB R1, 1(R0) + LSRW $0x08, R1, R1 + LSLW $0x05, R1, R1 + ORRW R1, R5, R5 + MOVB R5, (R0) + ADD $0x02, R3, R3 + ADD $0x02, R0, R0 + JMP gen_emit_copy_end_snappy + +emit_copy_three_standalone_snappy: + SUB $2, R5, R5 + MOVWU R5, R5 + MOVB R5, (R0) + MOVH R1, 1(R0) + ADD $0x03, R3, R3 + ADD $0x03, R0, R0 + +gen_emit_copy_end_snappy: + MOVD R3, ret+40(FP) + RET + +// func matchLen(a []byte, b []byte) int +// Requires: BMI +TEXT ·matchLen(SB), NOSPLIT, $0-56 + MOVD a_base+0(FP), R0 + MOVD b_base+24(FP), R1 + MOVD a_len+8(FP), R2 + + // matchLen + MOVD $0, R5 + +matchlen_loopback_16_standalone: + CMPW $0x10, R2 + BLO matchlen_match8_standalone + MOVD (R0)(R5), R3 + ADD R5, R0, R15 + MOVD 8(R15), R6 + MOVD (R1)(R5), R16 + EOR R16, R3, R3 + TST R3, R3 + BNE matchlen_bsf_8_standalone + ADD R5, R1, R15 + MOVD 8(R15), R16 + EOR R16, R6, R6 + TST R6, R6 + BNE matchlen_bsf_16standalone + SUB $16, R2, R2 + MOVWU R2, R2 + ADD $16, R5, R5 + MOVWU R5, R5 + JMP matchlen_loopback_16_standalone + +matchlen_bsf_16standalone: + RBIT R6, R6 + CLZ R6, R6 + ASR $0x03, R6, R6 + ADD R6, R5, R5 + ADD $8, R5, R5 + MOVWU R5, R5 + JMP gen_match_len_end + +matchlen_match8_standalone: + CMPW $0x08, R2 + BLO matchlen_match4_standalone + MOVD (R0)(R5), R3 + MOVD (R1)(R5), R16 + EOR R16, R3, R3 + TST R3, R3 + BNE matchlen_bsf_8_standalone + SUB $8, R2, R2 + MOVWU R2, R2 + ADD $8, R5, R5 + MOVWU R5, R5 + JMP matchlen_match4_standalone + +matchlen_bsf_8_standalone: + RBIT R3, R3 + CLZ R3, R3 + ASR $0x03, R3, R3 + ADD R3, R5, R5 + MOVWU R5, R5 + JMP gen_match_len_end + +matchlen_match4_standalone: + CMPW $0x04, R2 + BLO matchlen_match2_standalone + MOVWU (R0)(R5), R3 + MOVWU (R1)(R5), R16 + CMPW R3, R16 + BNE matchlen_match2_standalone + SUB $4, R2, R2 + MOVWU R2, R2 + ADD $4, R5, R5 + MOVWU R5, R5 + +matchlen_match2_standalone: + CMPW $0x01, R2 + BEQ matchlen_match1_standalone + BLO gen_match_len_end + MOVHU (R0)(R5), R16 + BFI $0, R16, $16, R3 + ADD R5, R1, R15 + MOVHU (R15), R15 + AND $0xffff, R3, R16 + CMP R16, R15 + BNE matchlen_match1_standalone + ADD $2, R5, R5 + MOVWU R5, R5 + SUBSW $0x02, R2, R2 + BEQ gen_match_len_end + +matchlen_match1_standalone: + MOVBU (R0)(R5), R16 + BFI $0, R16, $8, R3 + ADD R5, R1, R15 + MOVBU (R15), R15 + AND $0xff, R3, R16 + CMP R16, R15 + BNE gen_match_len_end + ADD $1, R5, R5 + MOVWU R5, R5 + +gen_match_len_end: + MOVD R5, ret+48(FP) + RET + +// func cvtLZ4BlockAsm(dst []byte, src []byte) (uncompressed int, dstUsed int) +// Requires: SSE2 +TEXT ·cvtLZ4BlockAsm(SB), NOSPLIT, $0-64 + MOVD $0, R5 + MOVD dst_base+0(FP), R0 + MOVD dst_len+8(FP), R1 + MOVD src_base+24(FP), R2 + MOVD src_len+32(FP), R3 + ADD R3, R2, R3 + ADD R1, R0, R1 + SUB $8, R1, R1 + MOVD $0, R6 + +lz4_s2_loop: + CMP R3, R2 + BHS lz4_s2_corrupt + CMP R1, R0 + BHS lz4_s2_dstfull + MOVBU (R2), R7 + MOVD R7, R8 + MOVD R7, R9 + LSR $0x04, R8, R8 + AND $0x0f, R9, R9 + CMP $0xf0, R7 + BLO lz4_s2_ll_end + +lz4_s2_ll_loop: + ADD $1, R2, R2 + CMP R3, R2 + BHS lz4_s2_corrupt + MOVBU (R2), R7 + ADD R7, R8, R8 + CMP $0xff, R7 + BEQ lz4_s2_ll_loop + +lz4_s2_ll_end: + ADD R8, R2, R7 + ADD $0x04, R9, R9 + CMP R3, R7 + BHS lz4_s2_corrupt + ADD $1, R2, R2 + ADD $1, R7, R7 + TST R8, R8 + BEQ lz4_s2_lits_done + ADD R8, R0, R10 + CMP R1, R10 + BHS lz4_s2_dstfull + ADD R8, R5, R5 + SUB $1, R8, R10 + MOVWU R10, R10 + CMPW $0x3c, R10 + BLO one_byte_lz4_s2 + CMPW $0x00000100, R10 + BLO two_bytes_lz4_s2 + CMPW $0x00010000, R10 + BLO three_bytes_lz4_s2 + CMPW $0x01000000, R10 + BLO four_bytes_lz4_s2 + MOVD $0xfc, R16 + MOVB R16, (R0) + MOVW R10, 1(R0) + ADD $0x05, R0, R0 + JMP memmove_long_lz4_s2 + +four_bytes_lz4_s2: + MOVWU R10, R11 + LSRW $0x10, R11, R11 + MOVD $0xf8, R16 + MOVB R16, (R0) + MOVH R10, 1(R0) + MOVB R11, 3(R0) + ADD $0x04, R0, R0 + JMP memmove_long_lz4_s2 + +three_bytes_lz4_s2: + MOVD $0xf4, R16 + MOVB R16, (R0) + MOVH R10, 1(R0) + ADD $0x03, R0, R0 + JMP memmove_long_lz4_s2 + +two_bytes_lz4_s2: + MOVD $0xf0, R16 + MOVB R16, (R0) + MOVB R10, 1(R0) + ADD $0x02, R0, R0 + CMPW $0x40, R10 + BLO memmove_lz4_s2 + JMP memmove_long_lz4_s2 + +one_byte_lz4_s2: + LSLW $0x02, R10, R16 + BFI $0, R16, $8, R10 + MOVB R10, (R0) + ADD $0x01, R0, R0 + +memmove_lz4_s2: + ADD R8, R0, R10 + + // genMemMoveShort + CMP $0x08, R8 + BLS emit_lit_memmove_lz4_s2_memmove_move_8 + CMP $0x10, R8 + BLS emit_lit_memmove_lz4_s2_memmove_move_8through16 + CMP $0x20, R8 + BLS emit_lit_memmove_lz4_s2_memmove_move_17through32 + JMP emit_lit_memmove_lz4_s2_memmove_move_33through64 + +emit_lit_memmove_lz4_s2_memmove_move_8: + MOVD (R2), R11 + MOVD R11, (R0) + JMP memmove_end_copy_lz4_s2 + +emit_lit_memmove_lz4_s2_memmove_move_8through16: + MOVD (R2), R11 + ADD R8, R2, R15 + MOVD -8(R15), R2 + MOVD R11, (R0) + ADD R8, R0, R15 + MOVD R2, -8(R15) + JMP memmove_end_copy_lz4_s2 + +emit_lit_memmove_lz4_s2_memmove_move_17through32: + FMOVQ (R2), F0 + ADD R8, R2, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R0) + ADD R8, R0, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_lz4_s2 + +emit_lit_memmove_lz4_s2_memmove_move_33through64: + FMOVQ (R2), F0 + FMOVQ 16(R2), F1 + ADD R8, R2, R15 + FMOVQ -32(R15), F2 + ADD R8, R2, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R0) + FMOVQ F1, 16(R0) + ADD R8, R0, R15 + FMOVQ F2, -32(R15) + ADD R8, R0, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_lz4_s2: + MOVD R10, R0 + JMP lz4_s2_lits_emit_done + +memmove_long_lz4_s2: + ADD R8, R0, R10 + + // genMemMoveLong + MOVD R2, R11 + MOVD R0, R12 + MOVD R8, R13 + +emit_lit_memmove_long_lz4_s2large_big_loop_back: + FMOVQ (R11), F0 + FMOVQ 16(R11), F1 + FMOVQ F0, (R12) + FMOVQ F1, 16(R12) + ADD $0x20, R11, R11 + ADD $0x20, R12, R12 + SUB $0x20, R13, R13 + CMP $0x20, R13 + BHS emit_lit_memmove_long_lz4_s2large_big_loop_back + ADD R8, R2, R15 + FMOVQ -32(R15), F0 + ADD R8, R2, R15 + FMOVQ -16(R15), F1 + ADD R8, R0, R15 + FMOVQ F0, -32(R15) + ADD R8, R0, R15 + FMOVQ F1, -16(R15) + MOVD R10, R0 + +lz4_s2_lits_emit_done: + MOVD R7, R2 + +lz4_s2_lits_done: + CMP R3, R2 + BNE lz4_s2_match + CMP $0x04, R9 + BEQ lz4_s2_done + JMP lz4_s2_corrupt + +lz4_s2_match: + ADD $2, R2, R7 + CMP R3, R7 + BHS lz4_s2_corrupt + MOVHU (R2), R8 + MOVD R7, R2 + TST R8, R8 + BEQ lz4_s2_corrupt + CMP R5, R8 + BHI lz4_s2_corrupt + CMP $0x13, R9 + BNE lz4_s2_ml_done + +lz4_s2_ml_loop: + MOVBU (R2), R7 + ADD $1, R2, R2 + ADD R7, R9, R9 + CMP R3, R2 + BHS lz4_s2_corrupt + CMP $0xff, R7 + BEQ lz4_s2_ml_loop + +lz4_s2_ml_done: + ADD R9, R5, R5 + CMP R6, R8 + BNE lz4_s2_docopy + + // emitRepeat +emit_repeat_again_lz4_s2: + MOVWU R9, R7 + SUB $4, R9, R9 + MOVWU R9, R9 + CMPW $0x08, R7 + BLS repeat_two_lz4_s2 + CMPW $0x0c, R7 + BHS cant_repeat_two_offset_lz4_s2 + CMPW $0x00000800, R8 + BLO repeat_two_offset_lz4_s2 + +cant_repeat_two_offset_lz4_s2: + CMPW $0x00000104, R9 + BLO repeat_three_lz4_s2 + CMPW $0x00010100, R9 + BLO repeat_four_lz4_s2 + CMPW $0x0100ffff, R9 + BLO repeat_five_lz4_s2 + SUB $16842747, R9, R9 + MOVWU R9, R9 + MOVD $0xfffb001d, R16 + MOVW R16, (R0) + MOVD $0xff, R16 + MOVB R16, 4(R0) + ADD $0x05, R0, R0 + JMP emit_repeat_again_lz4_s2 + +repeat_five_lz4_s2: + SUB $65536, R9, R9 + MOVWU R9, R9 + MOVWU R9, R8 + MOVD $0x001d, R16 + MOVH R16, (R0) + MOVH R9, 2(R0) + ASRW $0x10, R8, R8 + MOVB R8, 4(R0) + ADD $0x05, R0, R0 + JMP lz4_s2_loop + +repeat_four_lz4_s2: + SUB $256, R9, R9 + MOVWU R9, R9 + MOVD $0x0019, R16 + MOVH R16, (R0) + MOVH R9, 2(R0) + ADD $0x04, R0, R0 + JMP lz4_s2_loop + +repeat_three_lz4_s2: + SUB $4, R9, R9 + MOVWU R9, R9 + MOVD $0x0015, R16 + MOVH R16, (R0) + MOVB R9, 2(R0) + ADD $0x03, R0, R0 + JMP lz4_s2_loop + +repeat_two_lz4_s2: + LSLW $0x02, R9, R9 + ORRW $0x01, R9, R9 + MOVH R9, (R0) + ADD $0x02, R0, R0 + JMP lz4_s2_loop + +repeat_two_offset_lz4_s2: + MOVD $0, R7 + ADD R9<<2, R7, R9 + ADD $1, R9, R9 + MOVWU R9, R9 + MOVB R8, 1(R0) + ASRW $0x08, R8, R8 + LSLW $0x05, R8, R8 + ORRW R8, R9, R9 + MOVB R9, (R0) + ADD $0x02, R0, R0 + JMP lz4_s2_loop + +lz4_s2_docopy: + MOVD R8, R6 + + // emitCopy + CMPW $0x40, R9 + BLS two_byte_offset_short_lz4_s2 + CMPW $0x00000800, R8 + BHS long_offset_short_lz4_s2 + MOVD $0x00000001, R7 + ADD $16, R7, R7 + MOVWU R7, R7 + MOVB R8, 1(R0) + MOVWU R8, R10 + LSRW $0x08, R10, R10 + LSLW $0x05, R10, R10 + ORRW R10, R7, R7 + MOVB R7, (R0) + ADD $0x02, R0, R0 + SUBW $0x08, R9, R9 + + // emitRepeat + SUB $4, R9, R9 + MOVWU R9, R9 + JMP cant_repeat_two_offset_lz4_s2_emit_copy_short_2b + +emit_repeat_again_lz4_s2_emit_copy_short_2b: + MOVWU R9, R7 + SUB $4, R9, R9 + MOVWU R9, R9 + CMPW $0x08, R7 + BLS repeat_two_lz4_s2_emit_copy_short_2b + CMPW $0x0c, R7 + BHS cant_repeat_two_offset_lz4_s2_emit_copy_short_2b + CMPW $0x00000800, R8 + BLO repeat_two_offset_lz4_s2_emit_copy_short_2b + +cant_repeat_two_offset_lz4_s2_emit_copy_short_2b: + CMPW $0x00000104, R9 + BLO repeat_three_lz4_s2_emit_copy_short_2b + CMPW $0x00010100, R9 + BLO repeat_four_lz4_s2_emit_copy_short_2b + CMPW $0x0100ffff, R9 + BLO repeat_five_lz4_s2_emit_copy_short_2b + SUB $16842747, R9, R9 + MOVWU R9, R9 + MOVD $0xfffb001d, R16 + MOVW R16, (R0) + MOVD $0xff, R16 + MOVB R16, 4(R0) + ADD $0x05, R0, R0 + JMP emit_repeat_again_lz4_s2_emit_copy_short_2b + +repeat_five_lz4_s2_emit_copy_short_2b: + SUB $65536, R9, R9 + MOVWU R9, R9 + MOVWU R9, R8 + MOVD $0x001d, R16 + MOVH R16, (R0) + MOVH R9, 2(R0) + ASRW $0x10, R8, R8 + MOVB R8, 4(R0) + ADD $0x05, R0, R0 + JMP lz4_s2_loop + +repeat_four_lz4_s2_emit_copy_short_2b: + SUB $256, R9, R9 + MOVWU R9, R9 + MOVD $0x0019, R16 + MOVH R16, (R0) + MOVH R9, 2(R0) + ADD $0x04, R0, R0 + JMP lz4_s2_loop + +repeat_three_lz4_s2_emit_copy_short_2b: + SUB $4, R9, R9 + MOVWU R9, R9 + MOVD $0x0015, R16 + MOVH R16, (R0) + MOVB R9, 2(R0) + ADD $0x03, R0, R0 + JMP lz4_s2_loop + +repeat_two_lz4_s2_emit_copy_short_2b: + LSLW $0x02, R9, R9 + ORRW $0x01, R9, R9 + MOVH R9, (R0) + ADD $0x02, R0, R0 + JMP lz4_s2_loop + +repeat_two_offset_lz4_s2_emit_copy_short_2b: + MOVD $0, R7 + ADD R9<<2, R7, R9 + ADD $1, R9, R9 + MOVWU R9, R9 + MOVB R8, 1(R0) + ASRW $0x08, R8, R8 + LSLW $0x05, R8, R8 + ORRW R8, R9, R9 + MOVB R9, (R0) + ADD $0x02, R0, R0 + JMP lz4_s2_loop + +long_offset_short_lz4_s2: + MOVD $0xee, R16 + MOVB R16, (R0) + MOVH R8, 1(R0) + SUB $60, R9, R9 + MOVWU R9, R9 + ADD $0x03, R0, R0 + + // emitRepeat +emit_repeat_again_lz4_s2_emit_copy_short: + MOVWU R9, R7 + SUB $4, R9, R9 + MOVWU R9, R9 + CMPW $0x08, R7 + BLS repeat_two_lz4_s2_emit_copy_short + CMPW $0x0c, R7 + BHS cant_repeat_two_offset_lz4_s2_emit_copy_short + CMPW $0x00000800, R8 + BLO repeat_two_offset_lz4_s2_emit_copy_short + +cant_repeat_two_offset_lz4_s2_emit_copy_short: + CMPW $0x00000104, R9 + BLO repeat_three_lz4_s2_emit_copy_short + CMPW $0x00010100, R9 + BLO repeat_four_lz4_s2_emit_copy_short + CMPW $0x0100ffff, R9 + BLO repeat_five_lz4_s2_emit_copy_short + SUB $16842747, R9, R9 + MOVWU R9, R9 + MOVD $0xfffb001d, R16 + MOVW R16, (R0) + MOVD $0xff, R16 + MOVB R16, 4(R0) + ADD $0x05, R0, R0 + JMP emit_repeat_again_lz4_s2_emit_copy_short + +repeat_five_lz4_s2_emit_copy_short: + SUB $65536, R9, R9 + MOVWU R9, R9 + MOVWU R9, R8 + MOVD $0x001d, R16 + MOVH R16, (R0) + MOVH R9, 2(R0) + ASRW $0x10, R8, R8 + MOVB R8, 4(R0) + ADD $0x05, R0, R0 + JMP lz4_s2_loop + +repeat_four_lz4_s2_emit_copy_short: + SUB $256, R9, R9 + MOVWU R9, R9 + MOVD $0x0019, R16 + MOVH R16, (R0) + MOVH R9, 2(R0) + ADD $0x04, R0, R0 + JMP lz4_s2_loop + +repeat_three_lz4_s2_emit_copy_short: + SUB $4, R9, R9 + MOVWU R9, R9 + MOVD $0x0015, R16 + MOVH R16, (R0) + MOVB R9, 2(R0) + ADD $0x03, R0, R0 + JMP lz4_s2_loop + +repeat_two_lz4_s2_emit_copy_short: + LSLW $0x02, R9, R9 + ORRW $0x01, R9, R9 + MOVH R9, (R0) + ADD $0x02, R0, R0 + JMP lz4_s2_loop + +repeat_two_offset_lz4_s2_emit_copy_short: + MOVD $0, R7 + ADD R9<<2, R7, R9 + ADD $1, R9, R9 + MOVWU R9, R9 + MOVB R8, 1(R0) + ASRW $0x08, R8, R8 + LSLW $0x05, R8, R8 + ORRW R8, R9, R9 + MOVB R9, (R0) + ADD $0x02, R0, R0 + JMP lz4_s2_loop + +two_byte_offset_short_lz4_s2: + MOVWU R9, R7 + LSLW $0x02, R7, R7 + CMPW $0x0c, R9 + BHS emit_copy_three_lz4_s2 + CMPW $0x00000800, R8 + BHS emit_copy_three_lz4_s2 + SUB $15, R7, R7 + MOVWU R7, R7 + MOVB R8, 1(R0) + LSRW $0x08, R8, R8 + LSLW $0x05, R8, R8 + ORRW R8, R7, R7 + MOVB R7, (R0) + ADD $0x02, R0, R0 + JMP lz4_s2_loop + +emit_copy_three_lz4_s2: + SUB $2, R7, R7 + MOVWU R7, R7 + MOVB R7, (R0) + MOVH R8, 1(R0) + ADD $0x03, R0, R0 + JMP lz4_s2_loop + +lz4_s2_done: + MOVD dst_base+0(FP), R1 + SUB R1, R0, R0 + MOVD R5, uncompressed+48(FP) + MOVD R0, dstUsed+56(FP) + RET + +lz4_s2_corrupt: + MOVD $0, R0 + SUB $1, R0, R5 + MOVD R5, uncompressed+48(FP) + RET + +lz4_s2_dstfull: + MOVD $0, R0 + SUB $2, R0, R5 + MOVD R5, uncompressed+48(FP) + RET + +// func cvtLZ4sBlockAsm(dst []byte, src []byte) (uncompressed int, dstUsed int) +// Requires: SSE2 +TEXT ·cvtLZ4sBlockAsm(SB), NOSPLIT, $0-64 + MOVD $0, R5 + MOVD dst_base+0(FP), R0 + MOVD dst_len+8(FP), R1 + MOVD src_base+24(FP), R2 + MOVD src_len+32(FP), R3 + ADD R3, R2, R3 + ADD R1, R0, R1 + SUB $8, R1, R1 + MOVD $0, R6 + +lz4s_s2_loop: + CMP R3, R2 + BHS lz4s_s2_corrupt + CMP R1, R0 + BHS lz4s_s2_dstfull + MOVBU (R2), R7 + MOVD R7, R8 + MOVD R7, R9 + LSR $0x04, R8, R8 + AND $0x0f, R9, R9 + CMP $0xf0, R7 + BLO lz4s_s2_ll_end + +lz4s_s2_ll_loop: + ADD $1, R2, R2 + CMP R3, R2 + BHS lz4s_s2_corrupt + MOVBU (R2), R7 + ADD R7, R8, R8 + CMP $0xff, R7 + BEQ lz4s_s2_ll_loop + +lz4s_s2_ll_end: + ADD R8, R2, R7 + ADD $0x03, R9, R9 + CMP R3, R7 + BHS lz4s_s2_corrupt + ADD $1, R2, R2 + ADD $1, R7, R7 + TST R8, R8 + BEQ lz4s_s2_lits_done + ADD R8, R0, R10 + CMP R1, R10 + BHS lz4s_s2_dstfull + ADD R8, R5, R5 + SUB $1, R8, R10 + MOVWU R10, R10 + CMPW $0x3c, R10 + BLO one_byte_lz4s_s2 + CMPW $0x00000100, R10 + BLO two_bytes_lz4s_s2 + CMPW $0x00010000, R10 + BLO three_bytes_lz4s_s2 + CMPW $0x01000000, R10 + BLO four_bytes_lz4s_s2 + MOVD $0xfc, R16 + MOVB R16, (R0) + MOVW R10, 1(R0) + ADD $0x05, R0, R0 + JMP memmove_long_lz4s_s2 + +four_bytes_lz4s_s2: + MOVWU R10, R11 + LSRW $0x10, R11, R11 + MOVD $0xf8, R16 + MOVB R16, (R0) + MOVH R10, 1(R0) + MOVB R11, 3(R0) + ADD $0x04, R0, R0 + JMP memmove_long_lz4s_s2 + +three_bytes_lz4s_s2: + MOVD $0xf4, R16 + MOVB R16, (R0) + MOVH R10, 1(R0) + ADD $0x03, R0, R0 + JMP memmove_long_lz4s_s2 + +two_bytes_lz4s_s2: + MOVD $0xf0, R16 + MOVB R16, (R0) + MOVB R10, 1(R0) + ADD $0x02, R0, R0 + CMPW $0x40, R10 + BLO memmove_lz4s_s2 + JMP memmove_long_lz4s_s2 + +one_byte_lz4s_s2: + LSLW $0x02, R10, R16 + BFI $0, R16, $8, R10 + MOVB R10, (R0) + ADD $0x01, R0, R0 + +memmove_lz4s_s2: + ADD R8, R0, R10 + + // genMemMoveShort + CMP $0x08, R8 + BLS emit_lit_memmove_lz4s_s2_memmove_move_8 + CMP $0x10, R8 + BLS emit_lit_memmove_lz4s_s2_memmove_move_8through16 + CMP $0x20, R8 + BLS emit_lit_memmove_lz4s_s2_memmove_move_17through32 + JMP emit_lit_memmove_lz4s_s2_memmove_move_33through64 + +emit_lit_memmove_lz4s_s2_memmove_move_8: + MOVD (R2), R11 + MOVD R11, (R0) + JMP memmove_end_copy_lz4s_s2 + +emit_lit_memmove_lz4s_s2_memmove_move_8through16: + MOVD (R2), R11 + ADD R8, R2, R15 + MOVD -8(R15), R2 + MOVD R11, (R0) + ADD R8, R0, R15 + MOVD R2, -8(R15) + JMP memmove_end_copy_lz4s_s2 + +emit_lit_memmove_lz4s_s2_memmove_move_17through32: + FMOVQ (R2), F0 + ADD R8, R2, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R0) + ADD R8, R0, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_lz4s_s2 + +emit_lit_memmove_lz4s_s2_memmove_move_33through64: + FMOVQ (R2), F0 + FMOVQ 16(R2), F1 + ADD R8, R2, R15 + FMOVQ -32(R15), F2 + ADD R8, R2, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R0) + FMOVQ F1, 16(R0) + ADD R8, R0, R15 + FMOVQ F2, -32(R15) + ADD R8, R0, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_lz4s_s2: + MOVD R10, R0 + JMP lz4s_s2_lits_emit_done + +memmove_long_lz4s_s2: + ADD R8, R0, R10 + + // genMemMoveLong + MOVD R2, R11 + MOVD R0, R12 + MOVD R8, R13 + +emit_lit_memmove_long_lz4s_s2large_big_loop_back: + FMOVQ (R11), F0 + FMOVQ 16(R11), F1 + FMOVQ F0, (R12) + FMOVQ F1, 16(R12) + ADD $0x20, R11, R11 + ADD $0x20, R12, R12 + SUB $0x20, R13, R13 + CMP $0x20, R13 + BHS emit_lit_memmove_long_lz4s_s2large_big_loop_back + ADD R8, R2, R15 + FMOVQ -32(R15), F0 + ADD R8, R2, R15 + FMOVQ -16(R15), F1 + ADD R8, R0, R15 + FMOVQ F0, -32(R15) + ADD R8, R0, R15 + FMOVQ F1, -16(R15) + MOVD R10, R0 + +lz4s_s2_lits_emit_done: + MOVD R7, R2 + +lz4s_s2_lits_done: + CMP R3, R2 + BNE lz4s_s2_match + CMP $0x03, R9 + BEQ lz4s_s2_done + JMP lz4s_s2_corrupt + +lz4s_s2_match: + CMP $0x03, R9 + BEQ lz4s_s2_loop + ADD $2, R2, R7 + CMP R3, R7 + BHS lz4s_s2_corrupt + MOVHU (R2), R8 + MOVD R7, R2 + TST R8, R8 + BEQ lz4s_s2_corrupt + CMP R5, R8 + BHI lz4s_s2_corrupt + CMP $0x12, R9 + BNE lz4s_s2_ml_done + +lz4s_s2_ml_loop: + MOVBU (R2), R7 + ADD $1, R2, R2 + ADD R7, R9, R9 + CMP R3, R2 + BHS lz4s_s2_corrupt + CMP $0xff, R7 + BEQ lz4s_s2_ml_loop + +lz4s_s2_ml_done: + ADD R9, R5, R5 + CMP R6, R8 + BNE lz4s_s2_docopy + + // emitRepeat +emit_repeat_again_lz4_s2: + MOVWU R9, R7 + SUB $4, R9, R9 + MOVWU R9, R9 + CMPW $0x08, R7 + BLS repeat_two_lz4_s2 + CMPW $0x0c, R7 + BHS cant_repeat_two_offset_lz4_s2 + CMPW $0x00000800, R8 + BLO repeat_two_offset_lz4_s2 + +cant_repeat_two_offset_lz4_s2: + CMPW $0x00000104, R9 + BLO repeat_three_lz4_s2 + CMPW $0x00010100, R9 + BLO repeat_four_lz4_s2 + CMPW $0x0100ffff, R9 + BLO repeat_five_lz4_s2 + SUB $16842747, R9, R9 + MOVWU R9, R9 + MOVD $0xfffb001d, R16 + MOVW R16, (R0) + MOVD $0xff, R16 + MOVB R16, 4(R0) + ADD $0x05, R0, R0 + JMP emit_repeat_again_lz4_s2 + +repeat_five_lz4_s2: + SUB $65536, R9, R9 + MOVWU R9, R9 + MOVWU R9, R8 + MOVD $0x001d, R16 + MOVH R16, (R0) + MOVH R9, 2(R0) + ASRW $0x10, R8, R8 + MOVB R8, 4(R0) + ADD $0x05, R0, R0 + JMP lz4s_s2_loop + +repeat_four_lz4_s2: + SUB $256, R9, R9 + MOVWU R9, R9 + MOVD $0x0019, R16 + MOVH R16, (R0) + MOVH R9, 2(R0) + ADD $0x04, R0, R0 + JMP lz4s_s2_loop + +repeat_three_lz4_s2: + SUB $4, R9, R9 + MOVWU R9, R9 + MOVD $0x0015, R16 + MOVH R16, (R0) + MOVB R9, 2(R0) + ADD $0x03, R0, R0 + JMP lz4s_s2_loop + +repeat_two_lz4_s2: + LSLW $0x02, R9, R9 + ORRW $0x01, R9, R9 + MOVH R9, (R0) + ADD $0x02, R0, R0 + JMP lz4s_s2_loop + +repeat_two_offset_lz4_s2: + MOVD $0, R7 + ADD R9<<2, R7, R9 + ADD $1, R9, R9 + MOVWU R9, R9 + MOVB R8, 1(R0) + ASRW $0x08, R8, R8 + LSLW $0x05, R8, R8 + ORRW R8, R9, R9 + MOVB R9, (R0) + ADD $0x02, R0, R0 + JMP lz4s_s2_loop + +lz4s_s2_docopy: + MOVD R8, R6 + + // emitCopy + CMPW $0x40, R9 + BLS two_byte_offset_short_lz4_s2 + CMPW $0x00000800, R8 + BHS long_offset_short_lz4_s2 + MOVD $0x00000001, R7 + ADD $16, R7, R7 + MOVWU R7, R7 + MOVB R8, 1(R0) + MOVWU R8, R10 + LSRW $0x08, R10, R10 + LSLW $0x05, R10, R10 + ORRW R10, R7, R7 + MOVB R7, (R0) + ADD $0x02, R0, R0 + SUBW $0x08, R9, R9 + + // emitRepeat + SUB $4, R9, R9 + MOVWU R9, R9 + JMP cant_repeat_two_offset_lz4_s2_emit_copy_short_2b + +emit_repeat_again_lz4_s2_emit_copy_short_2b: + MOVWU R9, R7 + SUB $4, R9, R9 + MOVWU R9, R9 + CMPW $0x08, R7 + BLS repeat_two_lz4_s2_emit_copy_short_2b + CMPW $0x0c, R7 + BHS cant_repeat_two_offset_lz4_s2_emit_copy_short_2b + CMPW $0x00000800, R8 + BLO repeat_two_offset_lz4_s2_emit_copy_short_2b + +cant_repeat_two_offset_lz4_s2_emit_copy_short_2b: + CMPW $0x00000104, R9 + BLO repeat_three_lz4_s2_emit_copy_short_2b + CMPW $0x00010100, R9 + BLO repeat_four_lz4_s2_emit_copy_short_2b + CMPW $0x0100ffff, R9 + BLO repeat_five_lz4_s2_emit_copy_short_2b + SUB $16842747, R9, R9 + MOVWU R9, R9 + MOVD $0xfffb001d, R16 + MOVW R16, (R0) + MOVD $0xff, R16 + MOVB R16, 4(R0) + ADD $0x05, R0, R0 + JMP emit_repeat_again_lz4_s2_emit_copy_short_2b + +repeat_five_lz4_s2_emit_copy_short_2b: + SUB $65536, R9, R9 + MOVWU R9, R9 + MOVWU R9, R8 + MOVD $0x001d, R16 + MOVH R16, (R0) + MOVH R9, 2(R0) + ASRW $0x10, R8, R8 + MOVB R8, 4(R0) + ADD $0x05, R0, R0 + JMP lz4s_s2_loop + +repeat_four_lz4_s2_emit_copy_short_2b: + SUB $256, R9, R9 + MOVWU R9, R9 + MOVD $0x0019, R16 + MOVH R16, (R0) + MOVH R9, 2(R0) + ADD $0x04, R0, R0 + JMP lz4s_s2_loop + +repeat_three_lz4_s2_emit_copy_short_2b: + SUB $4, R9, R9 + MOVWU R9, R9 + MOVD $0x0015, R16 + MOVH R16, (R0) + MOVB R9, 2(R0) + ADD $0x03, R0, R0 + JMP lz4s_s2_loop + +repeat_two_lz4_s2_emit_copy_short_2b: + LSLW $0x02, R9, R9 + ORRW $0x01, R9, R9 + MOVH R9, (R0) + ADD $0x02, R0, R0 + JMP lz4s_s2_loop + +repeat_two_offset_lz4_s2_emit_copy_short_2b: + MOVD $0, R7 + ADD R9<<2, R7, R9 + ADD $1, R9, R9 + MOVWU R9, R9 + MOVB R8, 1(R0) + ASRW $0x08, R8, R8 + LSLW $0x05, R8, R8 + ORRW R8, R9, R9 + MOVB R9, (R0) + ADD $0x02, R0, R0 + JMP lz4s_s2_loop + +long_offset_short_lz4_s2: + MOVD $0xee, R16 + MOVB R16, (R0) + MOVH R8, 1(R0) + SUB $60, R9, R9 + MOVWU R9, R9 + ADD $0x03, R0, R0 + + // emitRepeat +emit_repeat_again_lz4_s2_emit_copy_short: + MOVWU R9, R7 + SUB $4, R9, R9 + MOVWU R9, R9 + CMPW $0x08, R7 + BLS repeat_two_lz4_s2_emit_copy_short + CMPW $0x0c, R7 + BHS cant_repeat_two_offset_lz4_s2_emit_copy_short + CMPW $0x00000800, R8 + BLO repeat_two_offset_lz4_s2_emit_copy_short + +cant_repeat_two_offset_lz4_s2_emit_copy_short: + CMPW $0x00000104, R9 + BLO repeat_three_lz4_s2_emit_copy_short + CMPW $0x00010100, R9 + BLO repeat_four_lz4_s2_emit_copy_short + CMPW $0x0100ffff, R9 + BLO repeat_five_lz4_s2_emit_copy_short + SUB $16842747, R9, R9 + MOVWU R9, R9 + MOVD $0xfffb001d, R16 + MOVW R16, (R0) + MOVD $0xff, R16 + MOVB R16, 4(R0) + ADD $0x05, R0, R0 + JMP emit_repeat_again_lz4_s2_emit_copy_short + +repeat_five_lz4_s2_emit_copy_short: + SUB $65536, R9, R9 + MOVWU R9, R9 + MOVWU R9, R8 + MOVD $0x001d, R16 + MOVH R16, (R0) + MOVH R9, 2(R0) + ASRW $0x10, R8, R8 + MOVB R8, 4(R0) + ADD $0x05, R0, R0 + JMP lz4s_s2_loop + +repeat_four_lz4_s2_emit_copy_short: + SUB $256, R9, R9 + MOVWU R9, R9 + MOVD $0x0019, R16 + MOVH R16, (R0) + MOVH R9, 2(R0) + ADD $0x04, R0, R0 + JMP lz4s_s2_loop + +repeat_three_lz4_s2_emit_copy_short: + SUB $4, R9, R9 + MOVWU R9, R9 + MOVD $0x0015, R16 + MOVH R16, (R0) + MOVB R9, 2(R0) + ADD $0x03, R0, R0 + JMP lz4s_s2_loop + +repeat_two_lz4_s2_emit_copy_short: + LSLW $0x02, R9, R9 + ORRW $0x01, R9, R9 + MOVH R9, (R0) + ADD $0x02, R0, R0 + JMP lz4s_s2_loop + +repeat_two_offset_lz4_s2_emit_copy_short: + MOVD $0, R7 + ADD R9<<2, R7, R9 + ADD $1, R9, R9 + MOVWU R9, R9 + MOVB R8, 1(R0) + ASRW $0x08, R8, R8 + LSLW $0x05, R8, R8 + ORRW R8, R9, R9 + MOVB R9, (R0) + ADD $0x02, R0, R0 + JMP lz4s_s2_loop + +two_byte_offset_short_lz4_s2: + MOVWU R9, R7 + LSLW $0x02, R7, R7 + CMPW $0x0c, R9 + BHS emit_copy_three_lz4_s2 + CMPW $0x00000800, R8 + BHS emit_copy_three_lz4_s2 + SUB $15, R7, R7 + MOVWU R7, R7 + MOVB R8, 1(R0) + LSRW $0x08, R8, R8 + LSLW $0x05, R8, R8 + ORRW R8, R7, R7 + MOVB R7, (R0) + ADD $0x02, R0, R0 + JMP lz4s_s2_loop + +emit_copy_three_lz4_s2: + SUB $2, R7, R7 + MOVWU R7, R7 + MOVB R7, (R0) + MOVH R8, 1(R0) + ADD $0x03, R0, R0 + JMP lz4s_s2_loop + +lz4s_s2_done: + MOVD dst_base+0(FP), R1 + SUB R1, R0, R0 + MOVD R5, uncompressed+48(FP) + MOVD R0, dstUsed+56(FP) + RET + +lz4s_s2_corrupt: + MOVD $0, R0 + SUB $1, R0, R5 + MOVD R5, uncompressed+48(FP) + RET + +lz4s_s2_dstfull: + MOVD $0, R0 + SUB $2, R0, R5 + MOVD R5, uncompressed+48(FP) + RET + +// func cvtLZ4BlockSnappyAsm(dst []byte, src []byte) (uncompressed int, dstUsed int) +// Requires: SSE2 +TEXT ·cvtLZ4BlockSnappyAsm(SB), NOSPLIT, $0-64 + MOVD $0, R5 + MOVD dst_base+0(FP), R0 + MOVD dst_len+8(FP), R1 + MOVD src_base+24(FP), R2 + MOVD src_len+32(FP), R3 + ADD R3, R2, R3 + ADD R1, R0, R1 + SUB $8, R1, R1 + +lz4_snappy_loop: + CMP R3, R2 + BHS lz4_snappy_corrupt + CMP R1, R0 + BHS lz4_snappy_dstfull + MOVBU (R2), R6 + MOVD R6, R7 + MOVD R6, R8 + LSR $0x04, R7, R7 + AND $0x0f, R8, R8 + CMP $0xf0, R6 + BLO lz4_snappy_ll_end + +lz4_snappy_ll_loop: + ADD $1, R2, R2 + CMP R3, R2 + BHS lz4_snappy_corrupt + MOVBU (R2), R6 + ADD R6, R7, R7 + CMP $0xff, R6 + BEQ lz4_snappy_ll_loop + +lz4_snappy_ll_end: + ADD R7, R2, R6 + ADD $0x04, R8, R8 + CMP R3, R6 + BHS lz4_snappy_corrupt + ADD $1, R2, R2 + ADD $1, R6, R6 + TST R7, R7 + BEQ lz4_snappy_lits_done + ADD R7, R0, R9 + CMP R1, R9 + BHS lz4_snappy_dstfull + ADD R7, R5, R5 + SUB $1, R7, R9 + MOVWU R9, R9 + CMPW $0x3c, R9 + BLO one_byte_lz4_snappy + CMPW $0x00000100, R9 + BLO two_bytes_lz4_snappy + CMPW $0x00010000, R9 + BLO three_bytes_lz4_snappy + CMPW $0x01000000, R9 + BLO four_bytes_lz4_snappy + MOVD $0xfc, R16 + MOVB R16, (R0) + MOVW R9, 1(R0) + ADD $0x05, R0, R0 + JMP memmove_long_lz4_snappy + +four_bytes_lz4_snappy: + MOVWU R9, R10 + LSRW $0x10, R10, R10 + MOVD $0xf8, R16 + MOVB R16, (R0) + MOVH R9, 1(R0) + MOVB R10, 3(R0) + ADD $0x04, R0, R0 + JMP memmove_long_lz4_snappy + +three_bytes_lz4_snappy: + MOVD $0xf4, R16 + MOVB R16, (R0) + MOVH R9, 1(R0) + ADD $0x03, R0, R0 + JMP memmove_long_lz4_snappy + +two_bytes_lz4_snappy: + MOVD $0xf0, R16 + MOVB R16, (R0) + MOVB R9, 1(R0) + ADD $0x02, R0, R0 + CMPW $0x40, R9 + BLO memmove_lz4_snappy + JMP memmove_long_lz4_snappy + +one_byte_lz4_snappy: + LSLW $0x02, R9, R16 + BFI $0, R16, $8, R9 + MOVB R9, (R0) + ADD $0x01, R0, R0 + +memmove_lz4_snappy: + ADD R7, R0, R9 + + // genMemMoveShort + CMP $0x08, R7 + BLS emit_lit_memmove_lz4_snappy_memmove_move_8 + CMP $0x10, R7 + BLS emit_lit_memmove_lz4_snappy_memmove_move_8through16 + CMP $0x20, R7 + BLS emit_lit_memmove_lz4_snappy_memmove_move_17through32 + JMP emit_lit_memmove_lz4_snappy_memmove_move_33through64 + +emit_lit_memmove_lz4_snappy_memmove_move_8: + MOVD (R2), R10 + MOVD R10, (R0) + JMP memmove_end_copy_lz4_snappy + +emit_lit_memmove_lz4_snappy_memmove_move_8through16: + MOVD (R2), R10 + ADD R7, R2, R15 + MOVD -8(R15), R2 + MOVD R10, (R0) + ADD R7, R0, R15 + MOVD R2, -8(R15) + JMP memmove_end_copy_lz4_snappy + +emit_lit_memmove_lz4_snappy_memmove_move_17through32: + FMOVQ (R2), F0 + ADD R7, R2, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R0) + ADD R7, R0, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_lz4_snappy + +emit_lit_memmove_lz4_snappy_memmove_move_33through64: + FMOVQ (R2), F0 + FMOVQ 16(R2), F1 + ADD R7, R2, R15 + FMOVQ -32(R15), F2 + ADD R7, R2, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R0) + FMOVQ F1, 16(R0) + ADD R7, R0, R15 + FMOVQ F2, -32(R15) + ADD R7, R0, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_lz4_snappy: + MOVD R9, R0 + JMP lz4_snappy_lits_emit_done + +memmove_long_lz4_snappy: + ADD R7, R0, R9 + + // genMemMoveLong + MOVD R2, R10 + MOVD R0, R11 + MOVD R7, R12 + +emit_lit_memmove_long_lz4_snappylarge_big_loop_back: + FMOVQ (R10), F0 + FMOVQ 16(R10), F1 + FMOVQ F0, (R11) + FMOVQ F1, 16(R11) + ADD $0x20, R10, R10 + ADD $0x20, R11, R11 + SUB $0x20, R12, R12 + CMP $0x20, R12 + BHS emit_lit_memmove_long_lz4_snappylarge_big_loop_back + ADD R7, R2, R15 + FMOVQ -32(R15), F0 + ADD R7, R2, R15 + FMOVQ -16(R15), F1 + ADD R7, R0, R15 + FMOVQ F0, -32(R15) + ADD R7, R0, R15 + FMOVQ F1, -16(R15) + MOVD R9, R0 + +lz4_snappy_lits_emit_done: + MOVD R6, R2 + +lz4_snappy_lits_done: + CMP R3, R2 + BNE lz4_snappy_match + CMP $0x04, R8 + BEQ lz4_snappy_done + JMP lz4_snappy_corrupt + +lz4_snappy_match: + ADD $2, R2, R6 + CMP R3, R6 + BHS lz4_snappy_corrupt + MOVHU (R2), R7 + MOVD R6, R2 + TST R7, R7 + BEQ lz4_snappy_corrupt + CMP R5, R7 + BHI lz4_snappy_corrupt + CMP $0x13, R8 + BNE lz4_snappy_ml_done + +lz4_snappy_ml_loop: + MOVBU (R2), R6 + ADD $1, R2, R2 + ADD R6, R8, R8 + CMP R3, R2 + BHS lz4_snappy_corrupt + CMP $0xff, R6 + BEQ lz4_snappy_ml_loop + +lz4_snappy_ml_done: + ADD R8, R5, R5 + + // emitCopy +two_byte_offset_lz4_s2: + CMPW $0x40, R8 + BLS two_byte_offset_short_lz4_s2 + MOVD $0xee, R16 + MOVB R16, (R0) + MOVH R7, 1(R0) + SUB $60, R8, R8 + MOVWU R8, R8 + ADD $0x03, R0, R0 + CMP R1, R0 + BHS lz4_snappy_loop + JMP two_byte_offset_lz4_s2 + +two_byte_offset_short_lz4_s2: + MOVWU R8, R6 + LSLW $0x02, R6, R6 + CMPW $0x0c, R8 + BHS emit_copy_three_lz4_s2 + CMPW $0x00000800, R7 + BHS emit_copy_three_lz4_s2 + SUB $15, R6, R6 + MOVWU R6, R6 + MOVB R7, 1(R0) + LSRW $0x08, R7, R7 + LSLW $0x05, R7, R7 + ORRW R7, R6, R6 + MOVB R6, (R0) + ADD $0x02, R0, R0 + JMP lz4_snappy_loop + +emit_copy_three_lz4_s2: + SUB $2, R6, R6 + MOVWU R6, R6 + MOVB R6, (R0) + MOVH R7, 1(R0) + ADD $0x03, R0, R0 + JMP lz4_snappy_loop + +lz4_snappy_done: + MOVD dst_base+0(FP), R1 + SUB R1, R0, R0 + MOVD R5, uncompressed+48(FP) + MOVD R0, dstUsed+56(FP) + RET + +lz4_snappy_corrupt: + MOVD $0, R0 + SUB $1, R0, R5 + MOVD R5, uncompressed+48(FP) + RET + +lz4_snappy_dstfull: + MOVD $0, R0 + SUB $2, R0, R5 + MOVD R5, uncompressed+48(FP) + RET + +// func cvtLZ4sBlockSnappyAsm(dst []byte, src []byte) (uncompressed int, dstUsed int) +// Requires: SSE2 +TEXT ·cvtLZ4sBlockSnappyAsm(SB), NOSPLIT, $0-64 + MOVD $0, R5 + MOVD dst_base+0(FP), R0 + MOVD dst_len+8(FP), R1 + MOVD src_base+24(FP), R2 + MOVD src_len+32(FP), R3 + ADD R3, R2, R3 + ADD R1, R0, R1 + SUB $8, R1, R1 + +lz4s_snappy_loop: + CMP R3, R2 + BHS lz4s_snappy_corrupt + CMP R1, R0 + BHS lz4s_snappy_dstfull + MOVBU (R2), R6 + MOVD R6, R7 + MOVD R6, R8 + LSR $0x04, R7, R7 + AND $0x0f, R8, R8 + CMP $0xf0, R6 + BLO lz4s_snappy_ll_end + +lz4s_snappy_ll_loop: + ADD $1, R2, R2 + CMP R3, R2 + BHS lz4s_snappy_corrupt + MOVBU (R2), R6 + ADD R6, R7, R7 + CMP $0xff, R6 + BEQ lz4s_snappy_ll_loop + +lz4s_snappy_ll_end: + ADD R7, R2, R6 + ADD $0x03, R8, R8 + CMP R3, R6 + BHS lz4s_snappy_corrupt + ADD $1, R2, R2 + ADD $1, R6, R6 + TST R7, R7 + BEQ lz4s_snappy_lits_done + ADD R7, R0, R9 + CMP R1, R9 + BHS lz4s_snappy_dstfull + ADD R7, R5, R5 + SUB $1, R7, R9 + MOVWU R9, R9 + CMPW $0x3c, R9 + BLO one_byte_lz4s_snappy + CMPW $0x00000100, R9 + BLO two_bytes_lz4s_snappy + CMPW $0x00010000, R9 + BLO three_bytes_lz4s_snappy + CMPW $0x01000000, R9 + BLO four_bytes_lz4s_snappy + MOVD $0xfc, R16 + MOVB R16, (R0) + MOVW R9, 1(R0) + ADD $0x05, R0, R0 + JMP memmove_long_lz4s_snappy + +four_bytes_lz4s_snappy: + MOVWU R9, R10 + LSRW $0x10, R10, R10 + MOVD $0xf8, R16 + MOVB R16, (R0) + MOVH R9, 1(R0) + MOVB R10, 3(R0) + ADD $0x04, R0, R0 + JMP memmove_long_lz4s_snappy + +three_bytes_lz4s_snappy: + MOVD $0xf4, R16 + MOVB R16, (R0) + MOVH R9, 1(R0) + ADD $0x03, R0, R0 + JMP memmove_long_lz4s_snappy + +two_bytes_lz4s_snappy: + MOVD $0xf0, R16 + MOVB R16, (R0) + MOVB R9, 1(R0) + ADD $0x02, R0, R0 + CMPW $0x40, R9 + BLO memmove_lz4s_snappy + JMP memmove_long_lz4s_snappy + +one_byte_lz4s_snappy: + LSLW $0x02, R9, R16 + BFI $0, R16, $8, R9 + MOVB R9, (R0) + ADD $0x01, R0, R0 + +memmove_lz4s_snappy: + ADD R7, R0, R9 + + // genMemMoveShort + CMP $0x08, R7 + BLS emit_lit_memmove_lz4s_snappy_memmove_move_8 + CMP $0x10, R7 + BLS emit_lit_memmove_lz4s_snappy_memmove_move_8through16 + CMP $0x20, R7 + BLS emit_lit_memmove_lz4s_snappy_memmove_move_17through32 + JMP emit_lit_memmove_lz4s_snappy_memmove_move_33through64 + +emit_lit_memmove_lz4s_snappy_memmove_move_8: + MOVD (R2), R10 + MOVD R10, (R0) + JMP memmove_end_copy_lz4s_snappy + +emit_lit_memmove_lz4s_snappy_memmove_move_8through16: + MOVD (R2), R10 + ADD R7, R2, R15 + MOVD -8(R15), R2 + MOVD R10, (R0) + ADD R7, R0, R15 + MOVD R2, -8(R15) + JMP memmove_end_copy_lz4s_snappy + +emit_lit_memmove_lz4s_snappy_memmove_move_17through32: + FMOVQ (R2), F0 + ADD R7, R2, R15 + FMOVQ -16(R15), F1 + FMOVQ F0, (R0) + ADD R7, R0, R15 + FMOVQ F1, -16(R15) + JMP memmove_end_copy_lz4s_snappy + +emit_lit_memmove_lz4s_snappy_memmove_move_33through64: + FMOVQ (R2), F0 + FMOVQ 16(R2), F1 + ADD R7, R2, R15 + FMOVQ -32(R15), F2 + ADD R7, R2, R15 + FMOVQ -16(R15), F3 + FMOVQ F0, (R0) + FMOVQ F1, 16(R0) + ADD R7, R0, R15 + FMOVQ F2, -32(R15) + ADD R7, R0, R15 + FMOVQ F3, -16(R15) + +memmove_end_copy_lz4s_snappy: + MOVD R9, R0 + JMP lz4s_snappy_lits_emit_done + +memmove_long_lz4s_snappy: + ADD R7, R0, R9 + + // genMemMoveLong + MOVD R2, R10 + MOVD R0, R11 + MOVD R7, R12 + +emit_lit_memmove_long_lz4s_snappylarge_big_loop_back: + FMOVQ (R10), F0 + FMOVQ 16(R10), F1 + FMOVQ F0, (R11) + FMOVQ F1, 16(R11) + ADD $0x20, R10, R10 + ADD $0x20, R11, R11 + SUB $0x20, R12, R12 + CMP $0x20, R12 + BHS emit_lit_memmove_long_lz4s_snappylarge_big_loop_back + ADD R7, R2, R15 + FMOVQ -32(R15), F0 + ADD R7, R2, R15 + FMOVQ -16(R15), F1 + ADD R7, R0, R15 + FMOVQ F0, -32(R15) + ADD R7, R0, R15 + FMOVQ F1, -16(R15) + MOVD R9, R0 + +lz4s_snappy_lits_emit_done: + MOVD R6, R2 + +lz4s_snappy_lits_done: + CMP R3, R2 + BNE lz4s_snappy_match + CMP $0x03, R8 + BEQ lz4s_snappy_done + JMP lz4s_snappy_corrupt + +lz4s_snappy_match: + CMP $0x03, R8 + BEQ lz4s_snappy_loop + ADD $2, R2, R6 + CMP R3, R6 + BHS lz4s_snappy_corrupt + MOVHU (R2), R7 + MOVD R6, R2 + TST R7, R7 + BEQ lz4s_snappy_corrupt + CMP R5, R7 + BHI lz4s_snappy_corrupt + CMP $0x12, R8 + BNE lz4s_snappy_ml_done + +lz4s_snappy_ml_loop: + MOVBU (R2), R6 + ADD $1, R2, R2 + ADD R6, R8, R8 + CMP R3, R2 + BHS lz4s_snappy_corrupt + CMP $0xff, R6 + BEQ lz4s_snappy_ml_loop + +lz4s_snappy_ml_done: + ADD R8, R5, R5 + + // emitCopy +two_byte_offset_lz4_s2: + CMPW $0x40, R8 + BLS two_byte_offset_short_lz4_s2 + MOVD $0xee, R16 + MOVB R16, (R0) + MOVH R7, 1(R0) + SUB $60, R8, R8 + MOVWU R8, R8 + ADD $0x03, R0, R0 + CMP R1, R0 + BHS lz4s_snappy_loop + JMP two_byte_offset_lz4_s2 + +two_byte_offset_short_lz4_s2: + MOVWU R8, R6 + LSLW $0x02, R6, R6 + CMPW $0x0c, R8 + BHS emit_copy_three_lz4_s2 + CMPW $0x00000800, R7 + BHS emit_copy_three_lz4_s2 + SUB $15, R6, R6 + MOVWU R6, R6 + MOVB R7, 1(R0) + LSRW $0x08, R7, R7 + LSLW $0x05, R7, R7 + ORRW R7, R6, R6 + MOVB R6, (R0) + ADD $0x02, R0, R0 + JMP lz4s_snappy_loop + +emit_copy_three_lz4_s2: + SUB $2, R6, R6 + MOVWU R6, R6 + MOVB R6, (R0) + MOVH R7, 1(R0) + ADD $0x03, R0, R0 + JMP lz4s_snappy_loop + +lz4s_snappy_done: + MOVD dst_base+0(FP), R1 + SUB R1, R0, R0 + MOVD R5, uncompressed+48(FP) + MOVD R0, dstUsed+56(FP) + RET + +lz4s_snappy_corrupt: + MOVD $0, R0 + SUB $1, R0, R5 + MOVD R5, uncompressed+48(FP) + RET + +lz4s_snappy_dstfull: + MOVD $0, R0 + SUB $2, R0, R5 + MOVD R5, uncompressed+48(FP) + RET diff --git a/vendor/github.com/klauspost/compress/s2/encodeblock_amd64.go b/vendor/github.com/klauspost/compress/s2/encodeblock_asm.go similarity index 98% rename from vendor/github.com/klauspost/compress/s2/encodeblock_amd64.go rename to vendor/github.com/klauspost/compress/s2/encodeblock_asm.go index f43aa8154..fb602efd5 100644 --- a/vendor/github.com/klauspost/compress/s2/encodeblock_amd64.go +++ b/vendor/github.com/klauspost/compress/s2/encodeblock_asm.go @@ -1,6 +1,6 @@ -// Code generated by command: go run gen.go -out ../encodeblock_amd64.s -stubs ../encodeblock_amd64.go -pkg=s2. DO NOT EDIT. +// Code generated by command: go run gen.go -out ../encodeblock_amd64.s -stubs ../encodeblock_asm.go -pkg=s2. DO NOT EDIT. -//go:build !appengine && !noasm && gc && !noasm +//go:build (amd64 || arm64) && !appengine && !noasm && gc && !noasm package s2 diff --git a/vendor/github.com/klauspost/compress/s2/lz4convert.go b/vendor/github.com/klauspost/compress/s2/lz4convert.go index 46ed908e3..01b5fb5c9 100644 --- a/vendor/github.com/klauspost/compress/s2/lz4convert.go +++ b/vendor/github.com/klauspost/compress/s2/lz4convert.go @@ -32,7 +32,7 @@ func (l *LZ4Converter) ConvertBlock(dst, src []byte) ([]byte, int, error) { s, d := 0, len(dst) dst = dst[:cap(dst)] - if !debug && hasAmd64Asm { + if !debug && hasAsm { res, sz := cvtLZ4BlockAsm(dst[d:], src) if res < 0 { const ( @@ -288,7 +288,7 @@ func (l *LZ4Converter) ConvertBlockSnappy(dst, src []byte) ([]byte, int, error) s, d := 0, len(dst) dst = dst[:cap(dst)] // Use assembly when possible - if !debug && hasAmd64Asm { + if !debug && hasAsm { res, sz := cvtLZ4BlockSnappyAsm(dst[d:], src) if res < 0 { const ( diff --git a/vendor/github.com/klauspost/compress/s2/lz4sconvert.go b/vendor/github.com/klauspost/compress/s2/lz4sconvert.go index 000f39719..7b4de58ff 100644 --- a/vendor/github.com/klauspost/compress/s2/lz4sconvert.go +++ b/vendor/github.com/klauspost/compress/s2/lz4sconvert.go @@ -37,7 +37,7 @@ func (l *LZ4sConverter) ConvertBlock(dst, src []byte) ([]byte, int, error) { s, d := 0, len(dst) dst = dst[:cap(dst)] - if !debug && hasAmd64Asm { + if !debug && hasAsm { res, sz := cvtLZ4sBlockAsm(dst[d:], src) if res < 0 { const ( @@ -297,7 +297,7 @@ func (l *LZ4sConverter) ConvertBlockSnappy(dst, src []byte) ([]byte, int, error) s, d := 0, len(dst) dst = dst[:cap(dst)] // Use assembly when possible - if !debug && hasAmd64Asm { + if !debug && hasAsm { res, sz := cvtLZ4sBlockSnappyAsm(dst[d:], src) if res < 0 { const ( diff --git a/vendor/github.com/klauspost/compress/s2/reader.go b/vendor/github.com/klauspost/compress/s2/reader.go index 17443e2c1..5c6cb4cfd 100644 --- a/vendor/github.com/klauspost/compress/s2/reader.go +++ b/vendor/github.com/klauspost/compress/s2/reader.go @@ -451,9 +451,7 @@ func (r *Reader) DecodeConcurrent(w io.Writer, concurrent int) (written int64, e } // Writer var wg sync.WaitGroup - wg.Add(1) - go func() { - defer wg.Done() + wg.Go(func() { for toWrite := range queue { entry := <-toWrite reUse <- toWrite @@ -480,7 +478,7 @@ func (r *Reader) DecodeConcurrent(w io.Writer, concurrent int) (written int64, e } aWritten += int64(n) } - }() + }) defer func() { if r.err != nil { diff --git a/vendor/github.com/klauspost/compress/s2/writer.go b/vendor/github.com/klauspost/compress/s2/writer.go index 09f1cff3a..8cf2e4e91 100644 --- a/vendor/github.com/klauspost/compress/s2/writer.go +++ b/vendor/github.com/klauspost/compress/s2/writer.go @@ -139,11 +139,9 @@ func (w *Writer) Reset(writer io.Writer) { toWrite := make(chan chan result, w.concurrency) w.output = toWrite - w.writerWg.Add(1) // Start a writer goroutine that will write all output in order. - go func() { - defer w.writerWg.Done() + w.writerWg.Go(func() { // Get a queued write. for write := range toWrite { @@ -175,7 +173,7 @@ func (w *Writer) Reset(writer io.Writer) { // This can be used for synchronizing flushes. close(write) } - }() + }) } // Write satisfies the io.Writer interface. diff --git a/vendor/github.com/klauspost/compress/zstd/blockdec.go b/vendor/github.com/klauspost/compress/zstd/blockdec.go index 2329e996f..51f9da038 100644 --- a/vendor/github.com/klauspost/compress/zstd/blockdec.go +++ b/vendor/github.com/klauspost/compress/zstd/blockdec.go @@ -400,8 +400,9 @@ func (b *blockDec) decodeLiterals(in []byte, hist *history) (remain []byte, err } } var err error - // Use our out buffer. - huff.MaxDecodedSize = litRegenSize + // Decoder.Decompress* uses cap(dst) for the size limit. Do not write + // MaxDecodedSize on hist.huffTree: with a trained dictionary that + // pointer aliases the shared dict.litEnc and concurrent DecodeAll races. if fourStreams { literals, err = huff.Decoder().Decompress4X(b.literalBuf[:0:litRegenSize], literals) } else { @@ -673,10 +674,6 @@ func (b *blockDec) executeSequences(hist *history) error { hbytes := hist.b if len(hbytes) > hist.windowSize { hbytes = hbytes[len(hbytes)-hist.windowSize:] - // We do not need history anymore. - if hist.dict != nil { - hist.dict.content = nil - } } hist.decoders.windowSize = hist.windowSize hist.decoders.out = b.dst[:0] diff --git a/vendor/github.com/klauspost/compress/zstd/dict.go b/vendor/github.com/klauspost/compress/zstd/dict.go index 4f1c4938c..67f40e791 100644 --- a/vendor/github.com/klauspost/compress/zstd/dict.go +++ b/vendor/github.com/klauspost/compress/zstd/dict.go @@ -296,40 +296,81 @@ func BuildDict(o BuildDictOptions) ([]byte, error) { if offset > 3 { newOffsets[offset-3]++ } else { - newOffsets[uint32(o.Offsets[offset-1])]++ + // Repeat codes reference the training Offsets. Skip unset + // (zero) entries so they are not ranked as real offsets. + prev := o.Offsets[offset-1] + if prev > 0 { + newOffsets[uint32(prev)]++ + } } } } // Find most used offsets. var sortedOffsets []uint32 for k := range newOffsets { + if k == 0 { + continue + } sortedOffsets = append(sortedOffsets, k) } sort.Slice(sortedOffsets, func(i, j int) bool { a, b := sortedOffsets[i], sortedOffsets[j] - if a == b { + ca, cb := newOffsets[a], newOffsets[b] + if ca == cb { // Prefer the longer offset - return sortedOffsets[i] > sortedOffsets[j] + return a > b } - return newOffsets[sortedOffsets[i]] > newOffsets[sortedOffsets[j]] + return ca > cb }) - if len(sortedOffsets) > 3 { - if debug { - print("Offsets:") - for i, v := range sortedOffsets { - if i > 20 { - break - } - printf("[%d: %d],", v, newOffsets[v]) + if debug { + print("Offsets:") + for i, v := range sortedOffsets { + if i > 20 { + break } - println("") + printf("[%d: %d],", v, newOffsets[v]) + } + println("") + } + // Dictionary recent-offsets must be three positive values within the + // history. Ranked matches may be fewer (or empty when only unset + // repeat codes were seen), so fill remaining slots with defaults. + used := make(map[int]bool, 3) + var finalOffsets [3]int + nOff := 0 + for _, v := range sortedOffsets { + iv := int(v) + if iv <= 0 || iv > len(hist) || used[iv] { + continue + } + finalOffsets[nOff] = iv + used[iv] = true + nOff++ + if nOff == 3 { + break } - - sortedOffsets = sortedOffsets[:3] } - for i, v := range sortedOffsets { - o.Offsets[i] = int(v) + for _, def := range []int{1, 4, 8} { + if nOff == 3 { + break + } + if def <= len(hist) && !used[def] { + finalOffsets[nOff] = def + used[def] = true + nOff++ + } + } + for def := 1; nOff < 3 && def <= len(hist); def++ { + if !used[def] { + finalOffsets[nOff] = def + used[def] = true + nOff++ + } + } + if nOff < 3 { + return nil, fmt.Errorf("could not determine 3 valid dictionary offsets (history size %d)", len(hist)) } + o.Offsets = finalOffsets if debug { println("New repeat offsets", o.Offsets) } @@ -337,6 +378,9 @@ func BuildDict(o BuildDictOptions) ([]byte, error) { if nUsed == 0 || seqs == 0 { return nil, fmt.Errorf("%d blocks, %d sequences found", nUsed, seqs) } + if litTotal == 0 { + return nil, errors.New("0 literals found") + } if debug { println("Sequences:", seqs, "Blocks:", nUsed, "Literals:", litTotal) } @@ -517,11 +561,10 @@ func BuildDict(o BuildDictOptions) ([]byte, error) { out.Write(binary.LittleEndian.AppendUint32(nil, uint32(o.Offsets[1]))) out.Write(binary.LittleEndian.AppendUint32(nil, uint32(o.Offsets[2]))) out.Write(hist) + if _, err := loadDict(out.Bytes()); err != nil { + return nil, fmt.Errorf("built dictionary failed validation: %w", err) + } if debug { - _, err := loadDict(out.Bytes()) - if err != nil { - panic(err) - } i, err := InspectDictionary(out.Bytes()) if err != nil { panic(err) diff --git a/vendor/github.com/klauspost/compress/zstd/fse_decoder_arm64.s b/vendor/github.com/klauspost/compress/zstd/fse_decoder_arm64.s index 77ee3913f..b6b460787 100644 --- a/vendor/github.com/klauspost/compress/zstd/fse_decoder_arm64.s +++ b/vendor/github.com/klauspost/compress/zstd/fse_decoder_arm64.s @@ -1,7 +1,7 @@ // Code generated by command: go run gen_fse.go -out ../fse_decoder.s -arch amd64,arm64 -pkg=zstd. DO NOT EDIT. // EXPERIMENTAL arm64 output lowered from an amd64 avo program. -//go:build arm64 && !appengine && !noasm && gc && !noasm +//go:build arm64 && (!appengine && !noasm && gc && !noasm) // func buildDtable_asm(s *fseDecoder, ctx *buildDtableAsmContext) int TEXT ·buildDtable_asm(SB), $0-24 @@ -26,11 +26,10 @@ TEXT ·buildDtable_asm(SB), $0-24 JMP init_main_loop_condition init_main_loop: - ADD R8<<1, R1, R15 - MOVH (R15), R9 - AND $0xffff, R9, R15 + MOVH (R1)(R8<<1), R9 MOVD $-1, R16 AND $0xffff, R16, R16 + AND $0xffff, R9, R15 CMP R16, R15 BNE do_not_update_high_threshold ADD R7<<3, R5, R15 @@ -39,8 +38,7 @@ init_main_loop: MOVD $0x0000000000000001, R9 do_not_update_high_threshold: - ADD R8<<1, R3, R15 - MOVH R9, (R15) + MOVH R9, (R3)(R8<<1) ADD $1, R8, R8 init_main_loop_condition: @@ -64,8 +62,7 @@ init_main_loop_condition: spread_main_loop: MOVD $0, R12 - ADD R11<<1, R1, R15 - MOVH (R15), R13 + MOVH (R1)(R11<<1), R13 JMP spread_inner_loop_condition spread_inner_loop: @@ -102,11 +99,9 @@ spread_check_ok: build_table_main_table: ADD R6<<3, R5, R15 MOVBU 1(R15), R1 - ADD R1<<1, R3, R15 - MOVHU (R15), R7 + MOVHU (R3)(R1<<1), R7 ADD $1, R7, R8 - ADD R1<<1, R3, R15 - MOVH R8, (R15) + MOVH R8, (R3)(R1<<1) MOVD R7, R8 CLZ R8, R16 MOVD $63, R8 @@ -129,12 +124,10 @@ build_table_main_table: RET build_table_check1_ok: - AND $0xff, R1, R15 - AND $0xff, R1, R16 - TST R16, R15 + TST $0xff, R1 BNE build_table_check2_ok - AND $0xffff, R7, R15 AND $0xffff, R6, R16 + AND $0xffff, R7, R15 CMP R16, R15 BNE build_table_check2_ok MOVD ctx+8(FP), R0 diff --git a/vendor/github.com/klauspost/compress/zstd/internal/xxhash/xxhash.go b/vendor/github.com/klauspost/compress/zstd/internal/xxhash/xxhash.go index fc40c8200..9c0cbc168 100644 --- a/vendor/github.com/klauspost/compress/zstd/internal/xxhash/xxhash.go +++ b/vendor/github.com/klauspost/compress/zstd/internal/xxhash/xxhash.go @@ -52,6 +52,11 @@ func (d *Digest) Reset() { d.n = 0 } +// maxAsmSize bounds the input handed to a single writeBlocks call. Assembly is +// never preemptible, so an unbounded call holds every P in stop-the-world for +// its duration. Whole 32-byte blocks, so Write can feed it in pieces. +const maxAsmSize = 128 << 10 // 4096 whole 32-byte blocks + // Size always returns 8 bytes. func (d *Digest) Size() int { return 8 } @@ -83,6 +88,13 @@ func (d *Digest) Write(b []byte) (n int, err error) { d.n = 0 } + for len(b) >= maxAsmSize { + // Assembly is not preemptible, so hashing a large buffer in one call + // blocks every stop-the-world for the whole call. Feed it in chunks. + writeBlocks(d, b[:maxAsmSize]) + b = b[maxAsmSize:] + } + if len(b) >= 32 { // One or more full blocks left. nw := writeBlocks(d, b) diff --git a/vendor/github.com/klauspost/compress/zstd/internal/xxhash/xxhash_amd64.s b/vendor/github.com/klauspost/compress/zstd/internal/xxhash/xxhash_amd64.s index ddb63aa91..e4c688efd 100644 --- a/vendor/github.com/klauspost/compress/zstd/internal/xxhash/xxhash_amd64.s +++ b/vendor/github.com/klauspost/compress/zstd/internal/xxhash/xxhash_amd64.s @@ -175,7 +175,11 @@ finalize: RET // func writeBlocks(d *Digest, b []byte) int -TEXT ·writeBlocks(SB), NOSPLIT|NOFRAME, $0-40 +// +// Deliberately not NOSPLIT: the stack check is the preemption point that lets a +// stop-the-world proceed between chunks. The frame must be >= abi.StackSmall +// (128), or the assembler marks this leaf NOSPLIT anyway and drops that check. +TEXT ·writeBlocks(SB), $128-40 // Load fixed primes needed for round. MOVQ ·primes+0(SB), prime1 MOVQ ·primes+8(SB), prime2 diff --git a/vendor/github.com/klauspost/compress/zstd/internal/xxhash/xxhash_arm64.s b/vendor/github.com/klauspost/compress/zstd/internal/xxhash/xxhash_arm64.s index ae7d4d329..e88cc2fc9 100644 --- a/vendor/github.com/klauspost/compress/zstd/internal/xxhash/xxhash_arm64.s +++ b/vendor/github.com/klauspost/compress/zstd/internal/xxhash/xxhash_arm64.s @@ -163,7 +163,11 @@ finalize: RET // func writeBlocks(s *Digest, b []byte) int -TEXT ·writeBlocks(SB), NOSPLIT|NOFRAME, $0-40 +// +// Deliberately not NOSPLIT: the stack check is the preemption point that lets a +// stop-the-world proceed between chunks. The frame must be >= abi.StackSmall +// (128), or the assembler marks this leaf NOSPLIT anyway and drops that check. +TEXT ·writeBlocks(SB), $128-40 LDP ·primes+0(SB), (prime1, prime2) // Load state. Assume v[1-4] are stored contiguously. diff --git a/vendor/github.com/klauspost/compress/zstd/seqdec_amd64.s b/vendor/github.com/klauspost/compress/zstd/seqdec_amd64.s index 3fc381c7a..9c4f8d352 100644 --- a/vendor/github.com/klauspost/compress/zstd/seqdec_amd64.s +++ b/vendor/github.com/klauspost/compress/zstd/seqdec_amd64.s @@ -55,43 +55,43 @@ sequenceDecs_decode_amd64_fill_check_overread: sequenceDecs_decode_amd64_fill_end: // Update offset - MOVQ R9, AX - MOVQ BX, CX - MOVQ DX, R15 - SHLQ CL, R15 - MOVB AH, CL - SHRQ $0x20, AX - TESTQ CX, CX - JZ sequenceDecs_decode_amd64_of_update_zero - ADDQ CX, BX - CMPQ BX, $0x40 - JA sequenceDecs_decode_amd64_of_update_zero - CMPQ CX, $0x40 - JAE sequenceDecs_decode_amd64_of_update_zero - NEGQ CX - SHRQ CL, R15 - ADDQ R15, AX + MOVQ R9, AX + MOVQ BX, CX + MOVQ DX, R15 + SHLQ CL, R15 + MOVBLZX AH, CX + SHRQ $0x20, AX + TESTQ CX, CX + JZ sequenceDecs_decode_amd64_of_update_zero + ADDQ CX, BX + CMPQ BX, $0x40 + JA sequenceDecs_decode_amd64_of_update_zero + CMPQ CX, $0x40 + JAE sequenceDecs_decode_amd64_of_update_zero + NEGQ CX + SHRQ CL, R15 + ADDQ R15, AX sequenceDecs_decode_amd64_of_update_zero: MOVQ AX, 16(R10) // Update match length - MOVQ R8, AX - MOVQ BX, CX - MOVQ DX, R15 - SHLQ CL, R15 - MOVB AH, CL - SHRQ $0x20, AX - TESTQ CX, CX - JZ sequenceDecs_decode_amd64_ml_update_zero - ADDQ CX, BX - CMPQ BX, $0x40 - JA sequenceDecs_decode_amd64_ml_update_zero - CMPQ CX, $0x40 - JAE sequenceDecs_decode_amd64_ml_update_zero - NEGQ CX - SHRQ CL, R15 - ADDQ R15, AX + MOVQ R8, AX + MOVQ BX, CX + MOVQ DX, R15 + SHLQ CL, R15 + MOVBLZX AH, CX + SHRQ $0x20, AX + TESTQ CX, CX + JZ sequenceDecs_decode_amd64_ml_update_zero + ADDQ CX, BX + CMPQ BX, $0x40 + JA sequenceDecs_decode_amd64_ml_update_zero + CMPQ CX, $0x40 + JAE sequenceDecs_decode_amd64_ml_update_zero + NEGQ CX + SHRQ CL, R15 + ADDQ R15, AX sequenceDecs_decode_amd64_ml_update_zero: MOVQ AX, 8(R10) @@ -126,22 +126,22 @@ sequenceDecs_decode_amd64_fill_2_check_overread: sequenceDecs_decode_amd64_fill_2_end: // Update literal length - MOVQ DI, AX - MOVQ BX, CX - MOVQ DX, R15 - SHLQ CL, R15 - MOVB AH, CL - SHRQ $0x20, AX - TESTQ CX, CX - JZ sequenceDecs_decode_amd64_ll_update_zero - ADDQ CX, BX - CMPQ BX, $0x40 - JA sequenceDecs_decode_amd64_ll_update_zero - CMPQ CX, $0x40 - JAE sequenceDecs_decode_amd64_ll_update_zero - NEGQ CX - SHRQ CL, R15 - ADDQ R15, AX + MOVQ DI, AX + MOVQ BX, CX + MOVQ DX, R15 + SHLQ CL, R15 + MOVBLZX AH, CX + SHRQ $0x20, AX + TESTQ CX, CX + JZ sequenceDecs_decode_amd64_ll_update_zero + ADDQ CX, BX + CMPQ BX, $0x40 + JA sequenceDecs_decode_amd64_ll_update_zero + CMPQ CX, $0x40 + JAE sequenceDecs_decode_amd64_ll_update_zero + NEGQ CX + SHRQ CL, R15 + ADDQ R15, AX sequenceDecs_decode_amd64_ll_update_zero: MOVQ AX, (R10) @@ -163,7 +163,7 @@ sequenceDecs_decode_amd64_ll_update_zero: MOVQ CX, BX ROLQ CL, R15 MOVL $0x00000001, BP - MOVB R14, CL + MOVBLZX R14, CX SHLL CL, BP DECL BP ANDQ BP, R15 @@ -182,7 +182,7 @@ sequenceDecs_decode_amd64_ll_update_zero: MOVQ CX, BX ROLQ CL, R15 MOVL $0x00000001, BP - MOVB R14, CL + MOVBLZX R14, CX SHLL CL, BP DECL BP ANDQ BP, R15 @@ -201,7 +201,7 @@ sequenceDecs_decode_amd64_ll_update_zero: MOVQ CX, BX ROLQ CL, R15 MOVL $0x00000001, BP - MOVB R14, CL + MOVBLZX R14, CX SHLL CL, BP DECL BP ANDQ BP, R15 @@ -383,64 +383,64 @@ sequenceDecs_decode_56_amd64_fill_check_overread: sequenceDecs_decode_56_amd64_fill_end: // Update offset - MOVQ R9, AX - MOVQ BX, CX - MOVQ DX, R15 - SHLQ CL, R15 - MOVB AH, CL - SHRQ $0x20, AX - TESTQ CX, CX - JZ sequenceDecs_decode_56_amd64_of_update_zero - ADDQ CX, BX - CMPQ BX, $0x40 - JA sequenceDecs_decode_56_amd64_of_update_zero - CMPQ CX, $0x40 - JAE sequenceDecs_decode_56_amd64_of_update_zero - NEGQ CX - SHRQ CL, R15 - ADDQ R15, AX + MOVQ R9, AX + MOVQ BX, CX + MOVQ DX, R15 + SHLQ CL, R15 + MOVBLZX AH, CX + SHRQ $0x20, AX + TESTQ CX, CX + JZ sequenceDecs_decode_56_amd64_of_update_zero + ADDQ CX, BX + CMPQ BX, $0x40 + JA sequenceDecs_decode_56_amd64_of_update_zero + CMPQ CX, $0x40 + JAE sequenceDecs_decode_56_amd64_of_update_zero + NEGQ CX + SHRQ CL, R15 + ADDQ R15, AX sequenceDecs_decode_56_amd64_of_update_zero: MOVQ AX, 16(R10) // Update match length - MOVQ R8, AX - MOVQ BX, CX - MOVQ DX, R15 - SHLQ CL, R15 - MOVB AH, CL - SHRQ $0x20, AX - TESTQ CX, CX - JZ sequenceDecs_decode_56_amd64_ml_update_zero - ADDQ CX, BX - CMPQ BX, $0x40 - JA sequenceDecs_decode_56_amd64_ml_update_zero - CMPQ CX, $0x40 - JAE sequenceDecs_decode_56_amd64_ml_update_zero - NEGQ CX - SHRQ CL, R15 - ADDQ R15, AX + MOVQ R8, AX + MOVQ BX, CX + MOVQ DX, R15 + SHLQ CL, R15 + MOVBLZX AH, CX + SHRQ $0x20, AX + TESTQ CX, CX + JZ sequenceDecs_decode_56_amd64_ml_update_zero + ADDQ CX, BX + CMPQ BX, $0x40 + JA sequenceDecs_decode_56_amd64_ml_update_zero + CMPQ CX, $0x40 + JAE sequenceDecs_decode_56_amd64_ml_update_zero + NEGQ CX + SHRQ CL, R15 + ADDQ R15, AX sequenceDecs_decode_56_amd64_ml_update_zero: MOVQ AX, 8(R10) // Update literal length - MOVQ DI, AX - MOVQ BX, CX - MOVQ DX, R15 - SHLQ CL, R15 - MOVB AH, CL - SHRQ $0x20, AX - TESTQ CX, CX - JZ sequenceDecs_decode_56_amd64_ll_update_zero - ADDQ CX, BX - CMPQ BX, $0x40 - JA sequenceDecs_decode_56_amd64_ll_update_zero - CMPQ CX, $0x40 - JAE sequenceDecs_decode_56_amd64_ll_update_zero - NEGQ CX - SHRQ CL, R15 - ADDQ R15, AX + MOVQ DI, AX + MOVQ BX, CX + MOVQ DX, R15 + SHLQ CL, R15 + MOVBLZX AH, CX + SHRQ $0x20, AX + TESTQ CX, CX + JZ sequenceDecs_decode_56_amd64_ll_update_zero + ADDQ CX, BX + CMPQ BX, $0x40 + JA sequenceDecs_decode_56_amd64_ll_update_zero + CMPQ CX, $0x40 + JAE sequenceDecs_decode_56_amd64_ll_update_zero + NEGQ CX + SHRQ CL, R15 + ADDQ R15, AX sequenceDecs_decode_56_amd64_ll_update_zero: MOVQ AX, (R10) @@ -462,7 +462,7 @@ sequenceDecs_decode_56_amd64_ll_update_zero: MOVQ CX, BX ROLQ CL, R15 MOVL $0x00000001, BP - MOVB R14, CL + MOVBLZX R14, CX SHLL CL, BP DECL BP ANDQ BP, R15 @@ -481,7 +481,7 @@ sequenceDecs_decode_56_amd64_ll_update_zero: MOVQ CX, BX ROLQ CL, R15 MOVL $0x00000001, BP - MOVB R14, CL + MOVBLZX R14, CX SHLL CL, BP DECL BP ANDQ BP, R15 @@ -500,7 +500,7 @@ sequenceDecs_decode_56_amd64_ll_update_zero: MOVQ CX, BX ROLQ CL, R15 MOVL $0x00000001, BP - MOVB R14, CL + MOVBLZX R14, CX SHLL CL, BP DECL BP ANDQ BP, R15 @@ -1258,13 +1258,13 @@ copy_4_small: JMP copy_4_move_8through16 copy_4_move_3: - MOVW (R14), R11 - MOVB 2(R14), R12 - MOVW R11, (BX) - MOVB R12, 2(BX) - ADDQ R13, R14 - ADDQ R13, BX - JMP copy_4_end + MOVWQZX (R14), R11 + MOVB 2(R14), R12 + MOVW R11, (BX) + MOVB R12, 2(BX) + ADDQ R13, R14 + ADDQ R13, BX + JMP copy_4_end copy_4_move_4through7: MOVL (R14), R11 @@ -1327,13 +1327,13 @@ copy_5_move_1or2: JMP copy_5_end copy_5_move_3: - MOVW (R14), R15 - MOVB 2(R14), BP - MOVW R15, (BX) - MOVB BP, 2(BX) - ADDQ R11, R14 - ADDQ R11, BX - JMP copy_5_end + MOVWQZX (R14), R15 + MOVB 2(R14), BP + MOVW R15, (BX) + MOVB BP, 2(BX) + ADDQ R11, R14 + ADDQ R11, BX + JMP copy_5_end copy_5_move_4through7: MOVL (R14), R15 @@ -1384,12 +1384,12 @@ copy_overlapping_match: ADDQ R13, DI copy_slow_3: - MOVB (R11), R12 - MOVB R12, (BX) - INCQ R11 - INCQ BX - DECQ R13 - JNZ copy_slow_3 + MOVBQZX (R11), R12 + MOVB R12, (BX) + INCQ R11 + INCQ BX + DECQ R13 + JNZ copy_slow_3 handle_loop: ADDQ $0x18, AX @@ -1494,13 +1494,13 @@ copy_1_move_1or2: JMP copy_1_end copy_1_move_3: - MOVW (SI), R14 - MOVB 2(SI), R15 - MOVW R14, (BX) - MOVB R15, 2(BX) - ADDQ R11, SI - ADDQ R11, BX - JMP copy_1_end + MOVWQZX (SI), R14 + MOVB 2(SI), R15 + MOVW R14, (BX) + MOVB R15, 2(BX) + ADDQ R11, SI + ADDQ R11, BX + JMP copy_1_end copy_1_move_4through7: MOVL (SI), R14 @@ -1563,13 +1563,13 @@ copy_4_small: JMP copy_4_move_8through16 copy_4_move_3: - MOVW (R14), R11 - MOVB 2(R14), R12 - MOVW R11, (BX) - MOVB R12, 2(BX) - ADDQ R13, R14 - ADDQ R13, BX - JMP copy_4_end + MOVWQZX (R14), R11 + MOVB 2(R14), R12 + MOVW R11, (BX) + MOVB R12, 2(BX) + ADDQ R13, R14 + ADDQ R13, BX + JMP copy_4_end copy_4_move_4through7: MOVL (R14), R11 @@ -1632,13 +1632,13 @@ copy_5_move_1or2: JMP copy_5_end copy_5_move_3: - MOVW (R14), R15 - MOVB 2(R14), BP - MOVW R15, (BX) - MOVB BP, 2(BX) - ADDQ R11, R14 - ADDQ R11, BX - JMP copy_5_end + MOVWQZX (R14), R15 + MOVB 2(R14), BP + MOVW R15, (BX) + MOVB BP, 2(BX) + ADDQ R11, R14 + ADDQ R11, BX + JMP copy_5_end copy_5_move_4through7: MOVL (R14), R15 @@ -1707,13 +1707,13 @@ copy_2_move_1or2: JMP copy_2_end copy_2_move_3: - MOVW (R11), R12 - MOVB 2(R11), R14 - MOVW R12, (BX) - MOVB R14, 2(BX) - ADDQ R13, R11 - ADDQ R13, BX - JMP copy_2_end + MOVWQZX (R11), R12 + MOVB 2(R11), R14 + MOVW R12, (BX) + MOVB R14, 2(BX) + ADDQ R13, R11 + ADDQ R13, BX + JMP copy_2_end copy_2_move_4through7: MOVL (R11), R12 @@ -1740,12 +1740,12 @@ copy_overlapping_match: ADDQ R13, DI copy_slow_3: - MOVB (R11), R12 - MOVB R12, (BX) - INCQ R11 - INCQ BX - DECQ R13 - JNZ copy_slow_3 + MOVBQZX (R11), R12 + MOVB R12, (BX) + INCQ R11 + INCQ BX + DECQ R13 + JNZ copy_slow_3 handle_loop: ADDQ $0x18, AX @@ -1853,43 +1853,43 @@ sequenceDecs_decodeSync_amd64_fill_check_overread: sequenceDecs_decodeSync_amd64_fill_end: // Update offset - MOVQ R9, AX - MOVQ BX, CX - MOVQ DX, R14 - SHLQ CL, R14 - MOVB AH, CL - SHRQ $0x20, AX - TESTQ CX, CX - JZ sequenceDecs_decodeSync_amd64_of_update_zero - ADDQ CX, BX - CMPQ BX, $0x40 - JA sequenceDecs_decodeSync_amd64_of_update_zero - CMPQ CX, $0x40 - JAE sequenceDecs_decodeSync_amd64_of_update_zero - NEGQ CX - SHRQ CL, R14 - ADDQ R14, AX + MOVQ R9, AX + MOVQ BX, CX + MOVQ DX, R14 + SHLQ CL, R14 + MOVBLZX AH, CX + SHRQ $0x20, AX + TESTQ CX, CX + JZ sequenceDecs_decodeSync_amd64_of_update_zero + ADDQ CX, BX + CMPQ BX, $0x40 + JA sequenceDecs_decodeSync_amd64_of_update_zero + CMPQ CX, $0x40 + JAE sequenceDecs_decodeSync_amd64_of_update_zero + NEGQ CX + SHRQ CL, R14 + ADDQ R14, AX sequenceDecs_decodeSync_amd64_of_update_zero: MOVQ AX, 8(SP) // Update match length - MOVQ R8, AX - MOVQ BX, CX - MOVQ DX, R14 - SHLQ CL, R14 - MOVB AH, CL - SHRQ $0x20, AX - TESTQ CX, CX - JZ sequenceDecs_decodeSync_amd64_ml_update_zero - ADDQ CX, BX - CMPQ BX, $0x40 - JA sequenceDecs_decodeSync_amd64_ml_update_zero - CMPQ CX, $0x40 - JAE sequenceDecs_decodeSync_amd64_ml_update_zero - NEGQ CX - SHRQ CL, R14 - ADDQ R14, AX + MOVQ R8, AX + MOVQ BX, CX + MOVQ DX, R14 + SHLQ CL, R14 + MOVBLZX AH, CX + SHRQ $0x20, AX + TESTQ CX, CX + JZ sequenceDecs_decodeSync_amd64_ml_update_zero + ADDQ CX, BX + CMPQ BX, $0x40 + JA sequenceDecs_decodeSync_amd64_ml_update_zero + CMPQ CX, $0x40 + JAE sequenceDecs_decodeSync_amd64_ml_update_zero + NEGQ CX + SHRQ CL, R14 + ADDQ R14, AX sequenceDecs_decodeSync_amd64_ml_update_zero: MOVQ AX, 16(SP) @@ -1924,22 +1924,22 @@ sequenceDecs_decodeSync_amd64_fill_2_check_overread: sequenceDecs_decodeSync_amd64_fill_2_end: // Update literal length - MOVQ DI, AX - MOVQ BX, CX - MOVQ DX, R14 - SHLQ CL, R14 - MOVB AH, CL - SHRQ $0x20, AX - TESTQ CX, CX - JZ sequenceDecs_decodeSync_amd64_ll_update_zero - ADDQ CX, BX - CMPQ BX, $0x40 - JA sequenceDecs_decodeSync_amd64_ll_update_zero - CMPQ CX, $0x40 - JAE sequenceDecs_decodeSync_amd64_ll_update_zero - NEGQ CX - SHRQ CL, R14 - ADDQ R14, AX + MOVQ DI, AX + MOVQ BX, CX + MOVQ DX, R14 + SHLQ CL, R14 + MOVBLZX AH, CX + SHRQ $0x20, AX + TESTQ CX, CX + JZ sequenceDecs_decodeSync_amd64_ll_update_zero + ADDQ CX, BX + CMPQ BX, $0x40 + JA sequenceDecs_decodeSync_amd64_ll_update_zero + CMPQ CX, $0x40 + JAE sequenceDecs_decodeSync_amd64_ll_update_zero + NEGQ CX + SHRQ CL, R14 + ADDQ R14, AX sequenceDecs_decodeSync_amd64_ll_update_zero: MOVQ AX, 24(SP) @@ -1961,7 +1961,7 @@ sequenceDecs_decodeSync_amd64_ll_update_zero: MOVQ CX, BX ROLQ CL, R14 MOVL $0x00000001, R15 - MOVB R13, CL + MOVBLZX R13, CX SHLL CL, R15 DECL R15 ANDQ R15, R14 @@ -1980,7 +1980,7 @@ sequenceDecs_decodeSync_amd64_ll_update_zero: MOVQ CX, BX ROLQ CL, R14 MOVL $0x00000001, R15 - MOVB R13, CL + MOVBLZX R13, CX SHLL CL, R15 DECL R15 ANDQ R15, R14 @@ -1999,7 +1999,7 @@ sequenceDecs_decodeSync_amd64_ll_update_zero: MOVQ CX, BX ROLQ CL, R14 MOVL $0x00000001, R15 - MOVB R13, CL + MOVBLZX R13, CX SHLL CL, R15 DECL R15 ANDQ R15, R14 @@ -2081,7 +2081,7 @@ sequenceDecs_decodeSync_amd64_match_len_ofs_ok: MOVQ 16(SP), R13 // Check if we have enough space in s.out - LEAQ (AX)(R13*1), R14 + LEAQ 16(AX)(R13*1), R14 ADDQ R10, R14 CMPQ R14, 32(SP) JA error_not_enough_space @@ -2143,13 +2143,13 @@ copy_4_small: JMP copy_4_move_8through16 copy_4_move_3: - MOVW (R14), AX - MOVB 2(R14), CL - MOVW AX, (R10) - MOVB CL, 2(R10) - ADDQ R13, R14 - ADDQ R13, R10 - JMP copy_4_end + MOVWQZX (R14), AX + MOVB 2(R14), CL + MOVW AX, (R10) + MOVB CL, 2(R10) + ADDQ R13, R14 + ADDQ R13, R10 + JMP copy_4_end copy_4_move_4through7: MOVL (R14), AX @@ -2209,13 +2209,13 @@ copy_5_move_1or2: JMP copy_5_end copy_5_move_3: - MOVW (R14), R15 - MOVB 2(R14), BP - MOVW R15, (R10) - MOVB BP, 2(R10) - ADDQ AX, R14 - ADDQ AX, R10 - JMP copy_5_end + MOVWQZX (R14), R15 + MOVB 2(R14), BP + MOVW R15, (R10) + MOVB BP, 2(R10) + ADDQ AX, R14 + ADDQ AX, R10 + JMP copy_5_end copy_5_move_4through7: MOVL (R14), R15 @@ -2266,12 +2266,12 @@ copy_overlapping_match: ADDQ R13, R12 copy_slow_3: - MOVB (AX), CL - MOVB CL, (R10) - INCQ AX - INCQ R10 - DECQ R13 - JNZ copy_slow_3 + MOVBQZX (AX), CX + MOVB CL, (R10) + INCQ AX + INCQ R10 + DECQ R13 + JNZ copy_slow_3 handle_loop: MOVQ ctx+16(FP), AX @@ -2601,7 +2601,7 @@ sequenceDecs_decodeSync_bmi2_match_len_ofs_ok: MOVQ 16(SP), R13 // Check if we have enough space in s.out - LEAQ (CX)(R13*1), R14 + LEAQ 16(CX)(R13*1), R14 ADDQ R9, R14 CMPQ R14, 32(SP) JA error_not_enough_space @@ -2663,13 +2663,13 @@ copy_4_small: JMP copy_4_move_8through16 copy_4_move_3: - MOVW (R14), CX - MOVB 2(R14), R12 - MOVW CX, (R9) - MOVB R12, 2(R9) - ADDQ R13, R14 - ADDQ R13, R9 - JMP copy_4_end + MOVWQZX (R14), CX + MOVB 2(R14), R12 + MOVW CX, (R9) + MOVB R12, 2(R9) + ADDQ R13, R14 + ADDQ R13, R9 + JMP copy_4_end copy_4_move_4through7: MOVL (R14), CX @@ -2729,13 +2729,13 @@ copy_5_move_1or2: JMP copy_5_end copy_5_move_3: - MOVW (R14), R15 - MOVB 2(R14), BP - MOVW R15, (R9) - MOVB BP, 2(R9) - ADDQ CX, R14 - ADDQ CX, R9 - JMP copy_5_end + MOVWQZX (R14), R15 + MOVB 2(R14), BP + MOVW R15, (R9) + MOVB BP, 2(R9) + ADDQ CX, R14 + ADDQ CX, R9 + JMP copy_5_end copy_5_move_4through7: MOVL (R14), R15 @@ -2786,12 +2786,12 @@ copy_overlapping_match: ADDQ R13, R11 copy_slow_3: - MOVB (CX), R12 - MOVB R12, (R9) - INCQ CX - INCQ R9 - DECQ R13 - JNZ copy_slow_3 + MOVBQZX (CX), R12 + MOVB R12, (R9) + INCQ CX + INCQ R9 + DECQ R13 + JNZ copy_slow_3 handle_loop: MOVQ ctx+16(FP), CX @@ -2935,43 +2935,43 @@ sequenceDecs_decodeSync_safe_amd64_fill_check_overread: sequenceDecs_decodeSync_safe_amd64_fill_end: // Update offset - MOVQ R9, AX - MOVQ BX, CX - MOVQ DX, R14 - SHLQ CL, R14 - MOVB AH, CL - SHRQ $0x20, AX - TESTQ CX, CX - JZ sequenceDecs_decodeSync_safe_amd64_of_update_zero - ADDQ CX, BX - CMPQ BX, $0x40 - JA sequenceDecs_decodeSync_safe_amd64_of_update_zero - CMPQ CX, $0x40 - JAE sequenceDecs_decodeSync_safe_amd64_of_update_zero - NEGQ CX - SHRQ CL, R14 - ADDQ R14, AX + MOVQ R9, AX + MOVQ BX, CX + MOVQ DX, R14 + SHLQ CL, R14 + MOVBLZX AH, CX + SHRQ $0x20, AX + TESTQ CX, CX + JZ sequenceDecs_decodeSync_safe_amd64_of_update_zero + ADDQ CX, BX + CMPQ BX, $0x40 + JA sequenceDecs_decodeSync_safe_amd64_of_update_zero + CMPQ CX, $0x40 + JAE sequenceDecs_decodeSync_safe_amd64_of_update_zero + NEGQ CX + SHRQ CL, R14 + ADDQ R14, AX sequenceDecs_decodeSync_safe_amd64_of_update_zero: MOVQ AX, 8(SP) // Update match length - MOVQ R8, AX - MOVQ BX, CX - MOVQ DX, R14 - SHLQ CL, R14 - MOVB AH, CL - SHRQ $0x20, AX - TESTQ CX, CX - JZ sequenceDecs_decodeSync_safe_amd64_ml_update_zero - ADDQ CX, BX - CMPQ BX, $0x40 - JA sequenceDecs_decodeSync_safe_amd64_ml_update_zero - CMPQ CX, $0x40 - JAE sequenceDecs_decodeSync_safe_amd64_ml_update_zero - NEGQ CX - SHRQ CL, R14 - ADDQ R14, AX + MOVQ R8, AX + MOVQ BX, CX + MOVQ DX, R14 + SHLQ CL, R14 + MOVBLZX AH, CX + SHRQ $0x20, AX + TESTQ CX, CX + JZ sequenceDecs_decodeSync_safe_amd64_ml_update_zero + ADDQ CX, BX + CMPQ BX, $0x40 + JA sequenceDecs_decodeSync_safe_amd64_ml_update_zero + CMPQ CX, $0x40 + JAE sequenceDecs_decodeSync_safe_amd64_ml_update_zero + NEGQ CX + SHRQ CL, R14 + ADDQ R14, AX sequenceDecs_decodeSync_safe_amd64_ml_update_zero: MOVQ AX, 16(SP) @@ -3006,22 +3006,22 @@ sequenceDecs_decodeSync_safe_amd64_fill_2_check_overread: sequenceDecs_decodeSync_safe_amd64_fill_2_end: // Update literal length - MOVQ DI, AX - MOVQ BX, CX - MOVQ DX, R14 - SHLQ CL, R14 - MOVB AH, CL - SHRQ $0x20, AX - TESTQ CX, CX - JZ sequenceDecs_decodeSync_safe_amd64_ll_update_zero - ADDQ CX, BX - CMPQ BX, $0x40 - JA sequenceDecs_decodeSync_safe_amd64_ll_update_zero - CMPQ CX, $0x40 - JAE sequenceDecs_decodeSync_safe_amd64_ll_update_zero - NEGQ CX - SHRQ CL, R14 - ADDQ R14, AX + MOVQ DI, AX + MOVQ BX, CX + MOVQ DX, R14 + SHLQ CL, R14 + MOVBLZX AH, CX + SHRQ $0x20, AX + TESTQ CX, CX + JZ sequenceDecs_decodeSync_safe_amd64_ll_update_zero + ADDQ CX, BX + CMPQ BX, $0x40 + JA sequenceDecs_decodeSync_safe_amd64_ll_update_zero + CMPQ CX, $0x40 + JAE sequenceDecs_decodeSync_safe_amd64_ll_update_zero + NEGQ CX + SHRQ CL, R14 + ADDQ R14, AX sequenceDecs_decodeSync_safe_amd64_ll_update_zero: MOVQ AX, 24(SP) @@ -3043,7 +3043,7 @@ sequenceDecs_decodeSync_safe_amd64_ll_update_zero: MOVQ CX, BX ROLQ CL, R14 MOVL $0x00000001, R15 - MOVB R13, CL + MOVBLZX R13, CX SHLL CL, R15 DECL R15 ANDQ R15, R14 @@ -3062,7 +3062,7 @@ sequenceDecs_decodeSync_safe_amd64_ll_update_zero: MOVQ CX, BX ROLQ CL, R14 MOVL $0x00000001, R15 - MOVB R13, CL + MOVBLZX R13, CX SHLL CL, R15 DECL R15 ANDQ R15, R14 @@ -3081,7 +3081,7 @@ sequenceDecs_decodeSync_safe_amd64_ll_update_zero: MOVQ CX, BX ROLQ CL, R14 MOVL $0x00000001, R15 - MOVB R13, CL + MOVBLZX R13, CX SHLL CL, R15 DECL R15 ANDQ R15, R14 @@ -3206,13 +3206,13 @@ copy_1_move_1or2: JMP copy_1_end copy_1_move_3: - MOVW (R11), R14 - MOVB 2(R11), R15 - MOVW R14, (R10) - MOVB R15, 2(R10) - ADDQ AX, R11 - ADDQ AX, R10 - JMP copy_1_end + MOVWQZX (R11), R14 + MOVB 2(R11), R15 + MOVW R14, (R10) + MOVB R15, 2(R10) + ADDQ AX, R11 + ADDQ AX, R10 + JMP copy_1_end copy_1_move_4through7: MOVL (R11), R14 @@ -3276,13 +3276,13 @@ copy_4_small: JMP copy_4_move_8through16 copy_4_move_3: - MOVW (R14), AX - MOVB 2(R14), CL - MOVW AX, (R10) - MOVB CL, 2(R10) - ADDQ R13, R14 - ADDQ R13, R10 - JMP copy_4_end + MOVWQZX (R14), AX + MOVB 2(R14), CL + MOVW AX, (R10) + MOVB CL, 2(R10) + ADDQ R13, R14 + ADDQ R13, R10 + JMP copy_4_end copy_4_move_4through7: MOVL (R14), AX @@ -3342,13 +3342,13 @@ copy_5_move_1or2: JMP copy_5_end copy_5_move_3: - MOVW (R14), R15 - MOVB 2(R14), BP - MOVW R15, (R10) - MOVB BP, 2(R10) - ADDQ AX, R14 - ADDQ AX, R10 - JMP copy_5_end + MOVWQZX (R14), R15 + MOVB 2(R14), BP + MOVW R15, (R10) + MOVB BP, 2(R10) + ADDQ AX, R14 + ADDQ AX, R10 + JMP copy_5_end copy_5_move_4through7: MOVL (R14), R15 @@ -3417,13 +3417,13 @@ copy_2_move_1or2: JMP copy_2_end copy_2_move_3: - MOVW (AX), CX - MOVB 2(AX), R14 - MOVW CX, (R10) - MOVB R14, 2(R10) - ADDQ R13, AX - ADDQ R13, R10 - JMP copy_2_end + MOVWQZX (AX), CX + MOVB 2(AX), R14 + MOVW CX, (R10) + MOVB R14, 2(R10) + ADDQ R13, AX + ADDQ R13, R10 + JMP copy_2_end copy_2_move_4through7: MOVL (AX), CX @@ -3450,12 +3450,12 @@ copy_overlapping_match: ADDQ R13, R12 copy_slow_3: - MOVB (AX), CL - MOVB CL, (R10) - INCQ AX - INCQ R10 - DECQ R13 - JNZ copy_slow_3 + MOVBQZX (AX), CX + MOVB CL, (R10) + INCQ AX + INCQ R10 + DECQ R13 + JNZ copy_slow_3 handle_loop: MOVQ ctx+16(FP), AX @@ -3828,13 +3828,13 @@ copy_1_move_1or2: JMP copy_1_end copy_1_move_3: - MOVW (R10), R14 - MOVB 2(R10), R15 - MOVW R14, (R9) - MOVB R15, 2(R9) - ADDQ CX, R10 - ADDQ CX, R9 - JMP copy_1_end + MOVWQZX (R10), R14 + MOVB 2(R10), R15 + MOVW R14, (R9) + MOVB R15, 2(R9) + ADDQ CX, R10 + ADDQ CX, R9 + JMP copy_1_end copy_1_move_4through7: MOVL (R10), R14 @@ -3898,13 +3898,13 @@ copy_4_small: JMP copy_4_move_8through16 copy_4_move_3: - MOVW (R14), CX - MOVB 2(R14), R12 - MOVW CX, (R9) - MOVB R12, 2(R9) - ADDQ R13, R14 - ADDQ R13, R9 - JMP copy_4_end + MOVWQZX (R14), CX + MOVB 2(R14), R12 + MOVW CX, (R9) + MOVB R12, 2(R9) + ADDQ R13, R14 + ADDQ R13, R9 + JMP copy_4_end copy_4_move_4through7: MOVL (R14), CX @@ -3964,13 +3964,13 @@ copy_5_move_1or2: JMP copy_5_end copy_5_move_3: - MOVW (R14), R15 - MOVB 2(R14), BP - MOVW R15, (R9) - MOVB BP, 2(R9) - ADDQ CX, R14 - ADDQ CX, R9 - JMP copy_5_end + MOVWQZX (R14), R15 + MOVB 2(R14), BP + MOVW R15, (R9) + MOVB BP, 2(R9) + ADDQ CX, R14 + ADDQ CX, R9 + JMP copy_5_end copy_5_move_4through7: MOVL (R14), R15 @@ -4039,13 +4039,13 @@ copy_2_move_1or2: JMP copy_2_end copy_2_move_3: - MOVW (CX), R12 - MOVB 2(CX), R14 - MOVW R12, (R9) - MOVB R14, 2(R9) - ADDQ R13, CX - ADDQ R13, R9 - JMP copy_2_end + MOVWQZX (CX), R12 + MOVB 2(CX), R14 + MOVW R12, (R9) + MOVB R14, 2(R9) + ADDQ R13, CX + ADDQ R13, R9 + JMP copy_2_end copy_2_move_4through7: MOVL (CX), R12 @@ -4072,12 +4072,12 @@ copy_overlapping_match: ADDQ R13, R11 copy_slow_3: - MOVB (CX), R12 - MOVB R12, (R9) - INCQ CX - INCQ R9 - DECQ R13 - JNZ copy_slow_3 + MOVBQZX (CX), R12 + MOVB R12, (R9) + INCQ CX + INCQ R9 + DECQ R13 + JNZ copy_slow_3 handle_loop: MOVQ ctx+16(FP), CX diff --git a/vendor/github.com/klauspost/compress/zstd/seqdec_arm64.s b/vendor/github.com/klauspost/compress/zstd/seqdec_arm64.s index a468e5fc2..fa48be19e 100644 --- a/vendor/github.com/klauspost/compress/zstd/seqdec_arm64.s +++ b/vendor/github.com/klauspost/compress/zstd/seqdec_arm64.s @@ -1,7 +1,7 @@ // Code generated by command: go run gen.go -out ../seqdec.s -arch amd64,arm64 -pkg=zstd. DO NOT EDIT. // EXPERIMENTAL arm64 output lowered from an amd64 avo program. -//go:build arm64 && !appengine && !noasm && gc && !noasm +//go:build arm64 && (!appengine && !noasm && gc && !noasm) // func sequenceDecs_decode_amd64(s *sequenceDecs, br *bitReader, ctx *decodeAsmContext) int // Requires: CMOV @@ -12,7 +12,7 @@ TEXT ·sequenceDecs_decode_arm64(SB), $8-32 MOVD (R1), R0 MOVD 32(R1), R5 ADD R5, R0, R0 - MOVD R0, (RSP) + MOVD R0, 8(RSP) MOVD ctx+16(FP), R0 MOVD 72(R0), R6 MOVD 80(R0), R7 @@ -24,7 +24,7 @@ TEXT ·sequenceDecs_decode_arm64(SB), $8-32 MOVD 160(R0), R12 sequenceDecs_decode_amd64_main_loop: - MOVD (RSP), R13 + MOVD 8(RSP), R13 // Fill bitreader to have enough for the offset and match length. CMP $0x08, R5 @@ -148,14 +148,12 @@ sequenceDecs_decode_amd64_ll_update_zero: MOVD R0, (R9) // Fill bitreader for state updates - MOVD R13, (RSP) - MOVD R8, R0 - LSR $0x08, R0, R0 - MOVBU R0, R0 - MOVD ctx+16(FP), R1 - MOVD 96(R1), R16 - CMP $0x00, R16 - BEQ sequenceDecs_decode_amd64_skip_update + MOVD R13, 8(RSP) + UBFX $8, R8, $8, R0 + MOVD ctx+16(FP), R1 + MOVD 96(R1), R16 + CMP $0x00, R16 + BEQ sequenceDecs_decode_amd64_skip_update // Update Literal Length State MOVBU R6, R13 @@ -166,7 +164,7 @@ sequenceDecs_decode_amd64_ll_update_zero: NEG R1, R16 ROR R16, R14, R14 MOVD $0x00000001, R4 - MOVB R13, R1 + MOVBU R13, R1 LSLW R1, R4, R4 SUBW $1, R4, R4 AND R4, R14, R14 @@ -175,8 +173,7 @@ sequenceDecs_decode_amd64_ll_update_zero: // Load ctx.llTable MOVD ctx+16(FP), R1 MOVD (R1), R1 - ADD R6<<3, R1, R15 - MOVD (R15), R6 + MOVD (R1)(R6<<3), R6 // Update Match Length State MOVBU R7, R13 @@ -187,7 +184,7 @@ sequenceDecs_decode_amd64_ll_update_zero: NEG R1, R16 ROR R16, R14, R14 MOVD $0x00000001, R4 - MOVB R13, R1 + MOVBU R13, R1 LSLW R1, R4, R4 SUBW $1, R4, R4 AND R4, R14, R14 @@ -196,8 +193,7 @@ sequenceDecs_decode_amd64_ll_update_zero: // Load ctx.mlTable MOVD ctx+16(FP), R1 MOVD 24(R1), R1 - ADD R7<<3, R1, R15 - MOVD (R15), R7 + MOVD (R1)(R7<<3), R7 // Update Offset State MOVBU R8, R13 @@ -208,7 +204,7 @@ sequenceDecs_decode_amd64_ll_update_zero: NEG R1, R16 ROR R16, R14, R14 MOVD $0x00000001, R4 - MOVB R13, R1 + MOVBU R13, R1 LSLW R1, R4, R4 SUBW $1, R4, R4 AND R4, R14, R14 @@ -217,8 +213,7 @@ sequenceDecs_decode_amd64_ll_update_zero: // Load ctx.ofTable MOVD ctx+16(FP), R1 MOVD 48(R1), R1 - ADD R8<<3, R1, R15 - MOVD (R15), R8 + MOVD (R1)(R8<<3), R8 sequenceDecs_decode_amd64_skip_update: // Adjust offset @@ -360,7 +355,7 @@ TEXT ·sequenceDecs_decode_56_arm64(SB), $8-32 MOVD (R1), R0 MOVD 32(R1), R5 ADD R5, R0, R0 - MOVD R0, (RSP) + MOVD R0, 8(RSP) MOVD ctx+16(FP), R0 MOVD 72(R0), R6 MOVD 80(R0), R7 @@ -372,7 +367,7 @@ TEXT ·sequenceDecs_decode_56_arm64(SB), $8-32 MOVD 160(R0), R12 sequenceDecs_decode_56_amd64_main_loop: - MOVD (RSP), R13 + MOVD 8(RSP), R13 // Fill bitreader to have enough for the offset and match length. CMP $0x08, R5 @@ -467,14 +462,12 @@ sequenceDecs_decode_56_amd64_ll_update_zero: MOVD R0, (R9) // Fill bitreader for state updates - MOVD R13, (RSP) - MOVD R8, R0 - LSR $0x08, R0, R0 - MOVBU R0, R0 - MOVD ctx+16(FP), R1 - MOVD 96(R1), R16 - CMP $0x00, R16 - BEQ sequenceDecs_decode_56_amd64_skip_update + MOVD R13, 8(RSP) + UBFX $8, R8, $8, R0 + MOVD ctx+16(FP), R1 + MOVD 96(R1), R16 + CMP $0x00, R16 + BEQ sequenceDecs_decode_56_amd64_skip_update // Update Literal Length State MOVBU R6, R13 @@ -485,7 +478,7 @@ sequenceDecs_decode_56_amd64_ll_update_zero: NEG R1, R16 ROR R16, R14, R14 MOVD $0x00000001, R4 - MOVB R13, R1 + MOVBU R13, R1 LSLW R1, R4, R4 SUBW $1, R4, R4 AND R4, R14, R14 @@ -494,8 +487,7 @@ sequenceDecs_decode_56_amd64_ll_update_zero: // Load ctx.llTable MOVD ctx+16(FP), R1 MOVD (R1), R1 - ADD R6<<3, R1, R15 - MOVD (R15), R6 + MOVD (R1)(R6<<3), R6 // Update Match Length State MOVBU R7, R13 @@ -506,7 +498,7 @@ sequenceDecs_decode_56_amd64_ll_update_zero: NEG R1, R16 ROR R16, R14, R14 MOVD $0x00000001, R4 - MOVB R13, R1 + MOVBU R13, R1 LSLW R1, R4, R4 SUBW $1, R4, R4 AND R4, R14, R14 @@ -515,8 +507,7 @@ sequenceDecs_decode_56_amd64_ll_update_zero: // Load ctx.mlTable MOVD ctx+16(FP), R1 MOVD 24(R1), R1 - ADD R7<<3, R1, R15 - MOVD (R15), R7 + MOVD (R1)(R7<<3), R7 // Update Offset State MOVBU R8, R13 @@ -527,7 +518,7 @@ sequenceDecs_decode_56_amd64_ll_update_zero: NEG R1, R16 ROR R16, R14, R14 MOVD $0x00000001, R4 - MOVB R13, R1 + MOVBU R13, R1 LSLW R1, R4, R4 SUBW $1, R4, R4 AND R4, R14, R14 @@ -536,8 +527,7 @@ sequenceDecs_decode_56_amd64_ll_update_zero: // Load ctx.ofTable MOVD ctx+16(FP), R1 MOVD 48(R1), R1 - ADD R8<<3, R1, R15 - MOVD (R15), R8 + MOVD (R1)(R8<<3), R8 sequenceDecs_decode_56_amd64_skip_update: // Adjust offset @@ -710,16 +700,16 @@ main_loop: MOVD $0, R13 copy_1: - ADD R13, R5, R15 - VLD1 (R15), [V0.B16] - ADD R13, R3, R15 - VST1 [V0.B16], (R15) - ADD $0x10, R13, R13 - CMP R10, R13 - BLO copy_1 - ADD R10, R5, R5 - ADD R10, R3, R3 - ADD R10, R6, R6 + ADD R13, R5, R15 + FMOVQ (R15), F0 + ADD R13, R3, R15 + FMOVQ F0, (R15) + ADD $0x10, R13, R13 + CMP R10, R13 + BLO copy_1 + ADD R10, R5, R5 + ADD R10, R3, R3 + ADD R10, R6, R6 // Malformed input if seq.mo > t+len(hist) || seq.mo > s.windowSize) check_offset: @@ -742,21 +732,19 @@ check_offset: BLO copy_4_small copy_4_loop: - VLD1 (R13), [V0.B16] - VST1 [V0.B16], (R3) - ADD $0x10, R13, R13 - ADD $0x10, R3, R3 - SUBS $0x10, R10, R10 - BHS copy_4_loop - ADD R10, R13, R13 - ADD $16, R13, R13 - ADD R10, R3, R3 - ADD $16, R3, R3 - ADD $-16, R13, R15 - VLD1 (R15), [V0.B16] - ADD $-16, R3, R15 - VST1 [V0.B16], (R15) - JMP copy_4_end + FMOVQ (R13), F0 + FMOVQ F0, (R3) + ADD $0x10, R13, R13 + ADD $0x10, R3, R3 + SUBS $0x10, R10, R10 + BHS copy_4_loop + ADD R10, R13, R13 + ADD $16, R13, R13 + ADD R10, R3, R3 + ADD $16, R3, R3 + FMOVQ -16(R13), F0 + FMOVQ F0, -16(R3) + JMP copy_4_end copy_4_small: CMP $0x03, R12 @@ -766,13 +754,14 @@ copy_4_small: JMP copy_4_move_8through16 copy_4_move_3: - MOVH (R13), R10 - MOVB 2(R13), R11 - MOVH R10, (R3) - MOVB R11, 2(R3) - ADD R12, R13, R13 - ADD R12, R3, R3 - JMP copy_4_end + MOVHU (R13), R10 + MOVBU 2(R13), R16 + BFI $0, R16, $8, R11 + MOVH R10, (R3) + MOVB R11, 2(R3) + ADD R12, R13, R13 + ADD R12, R3, R3 + JMP copy_4_end copy_4_move_4through7: MOVWU (R13), R10 @@ -809,21 +798,19 @@ copy_all_from_history: BLO copy_5_small copy_5_loop: - VLD1 (R13), [V0.B16] - VST1 [V0.B16], (R3) - ADD $0x10, R13, R13 - ADD $0x10, R3, R3 - SUBS $0x10, R14, R14 - BHS copy_5_loop - ADD R14, R13, R13 - ADD $16, R13, R13 - ADD R14, R3, R3 - ADD $16, R3, R3 - ADD $-16, R13, R15 - VLD1 (R15), [V0.B16] - ADD $-16, R3, R15 - VST1 [V0.B16], (R15) - JMP copy_5_end + FMOVQ (R13), F0 + FMOVQ F0, (R3) + ADD $0x10, R13, R13 + ADD $0x10, R3, R3 + SUBS $0x10, R14, R14 + BHS copy_5_loop + ADD R14, R13, R13 + ADD $16, R13, R13 + ADD R14, R3, R3 + ADD $16, R3, R3 + FMOVQ -16(R13), F0 + FMOVQ F0, -16(R3) + JMP copy_5_end copy_5_small: CMP $0x03, R10 @@ -834,24 +821,27 @@ copy_5_small: JMP copy_5_move_8through16 copy_5_move_1or2: - MOVB (R13), R14 - ADD R10, R13, R15 - MOVB -1(R15), R4 - MOVB R14, (R3) - ADD R10, R3, R15 - MOVB R4, -1(R15) - ADD R10, R13, R13 - ADD R10, R3, R3 - JMP copy_5_end + MOVBU (R13), R16 + BFI $0, R16, $8, R14 + ADD R10, R13, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R4 + MOVB R14, (R3) + ADD R10, R3, R15 + MOVB R4, -1(R15) + ADD R10, R13, R13 + ADD R10, R3, R3 + JMP copy_5_end copy_5_move_3: - MOVH (R13), R14 - MOVB 2(R13), R4 - MOVH R14, (R3) - MOVB R4, 2(R3) - ADD R10, R13, R13 - ADD R10, R3, R3 - JMP copy_5_end + MOVHU (R13), R14 + MOVBU 2(R13), R16 + BFI $0, R16, $8, R4 + MOVH R14, (R3) + MOVB R4, 2(R3) + ADD R10, R13, R13 + ADD R10, R3, R3 + JMP copy_5_end copy_5_move_4through7: MOVWU (R13), R14 @@ -893,25 +883,25 @@ copy_match: ADD R12, R3, R3 copy_2: - VLD1 (R10), [V0.B16] - VST1 [V0.B16], (R11) - ADD $0x10, R10, R10 - ADD $0x10, R11, R11 - SUBS $0x10, R12, R12 - BHI copy_2 - JMP handle_loop + FMOVQ (R10), F0 + FMOVQ F0, (R11) + ADD $0x10, R10, R10 + ADD $0x10, R11, R11 + SUBS $0x10, R12, R12 + BHI copy_2 + JMP handle_loop // Copy overlapping match copy_overlapping_match: ADD R12, R6, R6 copy_slow_3: - MOVB (R10), R11 - MOVB R11, (R3) - ADD $1, R10, R10 - ADD $1, R3, R3 - SUBS $1, R12, R12 - BNE copy_slow_3 + MOVBU (R10), R11 + MOVB R11, (R3) + ADD $1, R10, R10 + ADD $1, R3, R3 + SUBS $1, R12, R12 + BNE copy_slow_3 handle_loop: ADD $0x18, R0, R0 @@ -991,21 +981,19 @@ main_loop: BLO copy_1_small copy_1_loop: - VLD1 (R5), [V0.B16] - VST1 [V0.B16], (R3) - ADD $0x10, R5, R5 - ADD $0x10, R3, R3 - SUBS $0x10, R13, R13 - BHS copy_1_loop - ADD R13, R5, R5 - ADD $16, R5, R5 - ADD R13, R3, R3 - ADD $16, R3, R3 - ADD $-16, R5, R15 - VLD1 (R15), [V0.B16] - ADD $-16, R3, R15 - VST1 [V0.B16], (R15) - JMP copy_1_end + FMOVQ (R5), F0 + FMOVQ F0, (R3) + ADD $0x10, R5, R5 + ADD $0x10, R3, R3 + SUBS $0x10, R13, R13 + BHS copy_1_loop + ADD R13, R5, R5 + ADD $16, R5, R5 + ADD R13, R3, R3 + ADD $16, R3, R3 + FMOVQ -16(R5), F0 + FMOVQ F0, -16(R3) + JMP copy_1_end copy_1_small: CMP $0x03, R10 @@ -1016,24 +1004,27 @@ copy_1_small: JMP copy_1_move_8through16 copy_1_move_1or2: - MOVB (R5), R13 - ADD R10, R5, R15 - MOVB -1(R15), R14 - MOVB R13, (R3) - ADD R10, R3, R15 - MOVB R14, -1(R15) - ADD R10, R5, R5 - ADD R10, R3, R3 - JMP copy_1_end + MOVBU (R5), R16 + BFI $0, R16, $8, R13 + ADD R10, R5, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R14 + MOVB R13, (R3) + ADD R10, R3, R15 + MOVB R14, -1(R15) + ADD R10, R5, R5 + ADD R10, R3, R3 + JMP copy_1_end copy_1_move_3: - MOVH (R5), R13 - MOVB 2(R5), R14 - MOVH R13, (R3) - MOVB R14, 2(R3) - ADD R10, R5, R5 - ADD R10, R3, R3 - JMP copy_1_end + MOVHU (R5), R13 + MOVBU 2(R5), R16 + BFI $0, R16, $8, R14 + MOVH R13, (R3) + MOVB R14, 2(R3) + ADD R10, R5, R5 + ADD R10, R3, R3 + JMP copy_1_end copy_1_move_4through7: MOVWU (R5), R13 @@ -1080,21 +1071,19 @@ check_offset: BLO copy_4_small copy_4_loop: - VLD1 (R13), [V0.B16] - VST1 [V0.B16], (R3) - ADD $0x10, R13, R13 - ADD $0x10, R3, R3 - SUBS $0x10, R10, R10 - BHS copy_4_loop - ADD R10, R13, R13 - ADD $16, R13, R13 - ADD R10, R3, R3 - ADD $16, R3, R3 - ADD $-16, R13, R15 - VLD1 (R15), [V0.B16] - ADD $-16, R3, R15 - VST1 [V0.B16], (R15) - JMP copy_4_end + FMOVQ (R13), F0 + FMOVQ F0, (R3) + ADD $0x10, R13, R13 + ADD $0x10, R3, R3 + SUBS $0x10, R10, R10 + BHS copy_4_loop + ADD R10, R13, R13 + ADD $16, R13, R13 + ADD R10, R3, R3 + ADD $16, R3, R3 + FMOVQ -16(R13), F0 + FMOVQ F0, -16(R3) + JMP copy_4_end copy_4_small: CMP $0x03, R12 @@ -1104,13 +1093,14 @@ copy_4_small: JMP copy_4_move_8through16 copy_4_move_3: - MOVH (R13), R10 - MOVB 2(R13), R11 - MOVH R10, (R3) - MOVB R11, 2(R3) - ADD R12, R13, R13 - ADD R12, R3, R3 - JMP copy_4_end + MOVHU (R13), R10 + MOVBU 2(R13), R16 + BFI $0, R16, $8, R11 + MOVH R10, (R3) + MOVB R11, 2(R3) + ADD R12, R13, R13 + ADD R12, R3, R3 + JMP copy_4_end copy_4_move_4through7: MOVWU (R13), R10 @@ -1147,21 +1137,19 @@ copy_all_from_history: BLO copy_5_small copy_5_loop: - VLD1 (R13), [V0.B16] - VST1 [V0.B16], (R3) - ADD $0x10, R13, R13 - ADD $0x10, R3, R3 - SUBS $0x10, R14, R14 - BHS copy_5_loop - ADD R14, R13, R13 - ADD $16, R13, R13 - ADD R14, R3, R3 - ADD $16, R3, R3 - ADD $-16, R13, R15 - VLD1 (R15), [V0.B16] - ADD $-16, R3, R15 - VST1 [V0.B16], (R15) - JMP copy_5_end + FMOVQ (R13), F0 + FMOVQ F0, (R3) + ADD $0x10, R13, R13 + ADD $0x10, R3, R3 + SUBS $0x10, R14, R14 + BHS copy_5_loop + ADD R14, R13, R13 + ADD $16, R13, R13 + ADD R14, R3, R3 + ADD $16, R3, R3 + FMOVQ -16(R13), F0 + FMOVQ F0, -16(R3) + JMP copy_5_end copy_5_small: CMP $0x03, R10 @@ -1172,24 +1160,27 @@ copy_5_small: JMP copy_5_move_8through16 copy_5_move_1or2: - MOVB (R13), R14 - ADD R10, R13, R15 - MOVB -1(R15), R4 - MOVB R14, (R3) - ADD R10, R3, R15 - MOVB R4, -1(R15) - ADD R10, R13, R13 - ADD R10, R3, R3 - JMP copy_5_end + MOVBU (R13), R16 + BFI $0, R16, $8, R14 + ADD R10, R13, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R4 + MOVB R14, (R3) + ADD R10, R3, R15 + MOVB R4, -1(R15) + ADD R10, R13, R13 + ADD R10, R3, R3 + JMP copy_5_end copy_5_move_3: - MOVH (R13), R14 - MOVB 2(R13), R4 - MOVH R14, (R3) - MOVB R4, 2(R3) - ADD R10, R13, R13 - ADD R10, R3, R3 - JMP copy_5_end + MOVHU (R13), R14 + MOVBU 2(R13), R16 + BFI $0, R16, $8, R4 + MOVH R14, (R3) + MOVB R4, 2(R3) + ADD R10, R13, R13 + ADD R10, R3, R3 + JMP copy_5_end copy_5_move_4through7: MOVWU (R13), R14 @@ -1232,21 +1223,19 @@ copy_match: BLO copy_2_small copy_2_loop: - VLD1 (R10), [V0.B16] - VST1 [V0.B16], (R3) - ADD $0x10, R10, R10 - ADD $0x10, R3, R3 - SUBS $0x10, R11, R11 - BHS copy_2_loop - ADD R11, R10, R10 - ADD $16, R10, R10 - ADD R11, R3, R3 - ADD $16, R3, R3 - ADD $-16, R10, R15 - VLD1 (R15), [V0.B16] - ADD $-16, R3, R15 - VST1 [V0.B16], (R15) - JMP copy_2_end + FMOVQ (R10), F0 + FMOVQ F0, (R3) + ADD $0x10, R10, R10 + ADD $0x10, R3, R3 + SUBS $0x10, R11, R11 + BHS copy_2_loop + ADD R11, R10, R10 + ADD $16, R10, R10 + ADD R11, R3, R3 + ADD $16, R3, R3 + FMOVQ -16(R10), F0 + FMOVQ F0, -16(R3) + JMP copy_2_end copy_2_small: CMP $0x03, R12 @@ -1257,24 +1246,27 @@ copy_2_small: JMP copy_2_move_8through16 copy_2_move_1or2: - MOVB (R10), R11 - ADD R12, R10, R15 - MOVB -1(R15), R13 - MOVB R11, (R3) - ADD R12, R3, R15 - MOVB R13, -1(R15) - ADD R12, R10, R10 - ADD R12, R3, R3 - JMP copy_2_end + MOVBU (R10), R16 + BFI $0, R16, $8, R11 + ADD R12, R10, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R13 + MOVB R11, (R3) + ADD R12, R3, R15 + MOVB R13, -1(R15) + ADD R12, R10, R10 + ADD R12, R3, R3 + JMP copy_2_end copy_2_move_3: - MOVH (R10), R11 - MOVB 2(R10), R13 - MOVH R11, (R3) - MOVB R13, 2(R3) - ADD R12, R10, R10 - ADD R12, R3, R3 - JMP copy_2_end + MOVHU (R10), R11 + MOVBU 2(R10), R16 + BFI $0, R16, $8, R13 + MOVH R11, (R3) + MOVB R13, 2(R3) + ADD R12, R10, R10 + ADD R12, R3, R3 + JMP copy_2_end copy_2_move_4through7: MOVWU (R10), R11 @@ -1305,12 +1297,12 @@ copy_overlapping_match: ADD R12, R6, R6 copy_slow_3: - MOVB (R10), R11 - MOVB R11, (R3) - ADD $1, R10, R10 - ADD $1, R3, R3 - SUBS $1, R12, R12 - BNE copy_slow_3 + MOVBU (R10), R11 + MOVB R11, (R3) + ADD $1, R10, R10 + ADD $1, R3, R3 + SUBS $1, R12, R12 + BNE copy_slow_3 handle_loop: ADD $0x18, R0, R0 @@ -1361,41 +1353,41 @@ TEXT ·sequenceDecs_decodeSync_arm64(SB), $64-32 MOVD (R1), R0 MOVD 32(R1), R5 ADD R5, R0, R0 - MOVD R0, (RSP) + MOVD R0, 8(RSP) MOVD ctx+16(FP), R0 MOVD 72(R0), R6 MOVD 80(R0), R7 MOVD 88(R0), R8 MOVD $0, R1 - MOVD R1, 8(RSP) MOVD R1, 16(RSP) MOVD R1, 24(RSP) + MOVD R1, 32(RSP) MOVD 112(R0), R9 MOVD 128(R0), R1 - MOVD R1, 32(RSP) + MOVD R1, 40(RSP) MOVD 144(R0), R10 MOVD 136(R0), R11 MOVD 200(R0), R1 - MOVD R1, 56(RSP) + MOVD R1, 64(RSP) MOVD 176(R0), R1 - MOVD R1, 48(RSP) + MOVD R1, 56(RSP) MOVD 184(R0), R0 - MOVD R0, 40(RSP) - MOVD 40(RSP), R0 - MOVD 48(RSP), R16 + MOVD R0, 48(RSP) + MOVD 48(RSP), R0 + MOVD 56(RSP), R16 ADD R0, R16, R16 - MOVD R16, 48(RSP) + MOVD R16, 56(RSP) // Calculate pointer to s.out[cap(s.out)] (a past-end pointer) - MOVD 32(RSP), R16 + MOVD 40(RSP), R16 ADD R9, R16, R16 - MOVD R16, 32(RSP) + MOVD R16, 40(RSP) // outBase += outPosition ADD R11, R9, R9 sequenceDecs_decodeSync_amd64_main_loop: - MOVD (RSP), R12 + MOVD 8(RSP), R12 // Fill bitreader to have enough for the offset and match length. CMP $0x08, R5 @@ -1445,7 +1437,7 @@ sequenceDecs_decodeSync_amd64_fill_end: ADD R13, R0, R0 sequenceDecs_decodeSync_amd64_of_update_zero: - MOVD R0, 8(RSP) + MOVD R0, 16(RSP) // Update match length MOVD R7, R0 @@ -1466,7 +1458,7 @@ sequenceDecs_decodeSync_amd64_of_update_zero: ADD R13, R0, R0 sequenceDecs_decodeSync_amd64_ml_update_zero: - MOVD R0, 16(RSP) + MOVD R0, 24(RSP) // Fill bitreader to have enough for the remaining CMP $0x08, R5 @@ -1516,17 +1508,15 @@ sequenceDecs_decodeSync_amd64_fill_2_end: ADD R13, R0, R0 sequenceDecs_decodeSync_amd64_ll_update_zero: - MOVD R0, 24(RSP) + MOVD R0, 32(RSP) // Fill bitreader for state updates - MOVD R12, (RSP) - MOVD R8, R0 - LSR $0x08, R0, R0 - MOVBU R0, R0 - MOVD ctx+16(FP), R1 - MOVD 96(R1), R16 - CMP $0x00, R16 - BEQ sequenceDecs_decodeSync_amd64_skip_update + MOVD R12, 8(RSP) + UBFX $8, R8, $8, R0 + MOVD ctx+16(FP), R1 + MOVD 96(R1), R16 + CMP $0x00, R16 + BEQ sequenceDecs_decodeSync_amd64_skip_update // Update Literal Length State MOVBU R6, R12 @@ -1537,7 +1527,7 @@ sequenceDecs_decodeSync_amd64_ll_update_zero: NEG R1, R16 ROR R16, R13, R13 MOVD $0x00000001, R14 - MOVB R12, R1 + MOVBU R12, R1 LSLW R1, R14, R14 SUBW $1, R14, R14 AND R14, R13, R13 @@ -1546,8 +1536,7 @@ sequenceDecs_decodeSync_amd64_ll_update_zero: // Load ctx.llTable MOVD ctx+16(FP), R1 MOVD (R1), R1 - ADD R6<<3, R1, R15 - MOVD (R15), R6 + MOVD (R1)(R6<<3), R6 // Update Match Length State MOVBU R7, R12 @@ -1558,7 +1547,7 @@ sequenceDecs_decodeSync_amd64_ll_update_zero: NEG R1, R16 ROR R16, R13, R13 MOVD $0x00000001, R14 - MOVB R12, R1 + MOVBU R12, R1 LSLW R1, R14, R14 SUBW $1, R14, R14 AND R14, R13, R13 @@ -1567,8 +1556,7 @@ sequenceDecs_decodeSync_amd64_ll_update_zero: // Load ctx.mlTable MOVD ctx+16(FP), R1 MOVD 24(R1), R1 - ADD R7<<3, R1, R15 - MOVD (R15), R7 + MOVD (R1)(R7<<3), R7 // Update Offset State MOVBU R8, R12 @@ -1579,7 +1567,7 @@ sequenceDecs_decodeSync_amd64_ll_update_zero: NEG R1, R16 ROR R16, R13, R13 MOVD $0x00000001, R14 - MOVB R12, R1 + MOVBU R12, R1 LSLW R1, R14, R14 SUBW $1, R14, R14 AND R14, R13, R13 @@ -1588,24 +1576,21 @@ sequenceDecs_decodeSync_amd64_ll_update_zero: // Load ctx.ofTable MOVD ctx+16(FP), R1 MOVD 48(R1), R1 - ADD R8<<3, R1, R15 - MOVD (R15), R8 + MOVD (R1)(R8<<3), R8 sequenceDecs_decodeSync_amd64_skip_update: // Adjust offset - MOVD s+0(FP), R1 - MOVD 8(RSP), R12 - CMP $0x01, R0 - BLS sequenceDecs_decodeSync_amd64_adjust_offsetB_1_or_0 - ADD $144, R1, R15 - VLD1 (R15), [V0.B16] - MOVD R12, 144(R1) - ADD $152, R1, R15 - VST1 [V0.B16], (R15) - JMP sequenceDecs_decodeSync_amd64_after_adjust + MOVD s+0(FP), R1 + MOVD 16(RSP), R12 + CMP $0x01, R0 + BLS sequenceDecs_decodeSync_amd64_adjust_offsetB_1_or_0 + FMOVQ 144(R1), F0 + MOVD R12, 144(R1) + FMOVQ F0, 152(R1) + JMP sequenceDecs_decodeSync_amd64_after_adjust sequenceDecs_decodeSync_amd64_adjust_offsetB_1_or_0: - MOVD 24(RSP), R16 + MOVD 32(RSP), R16 CMP $0x00000000, R16 BNE sequenceDecs_decodeSync_amd64_adjust_offset_maybezero ADD $1, R12, R12 @@ -1643,11 +1628,11 @@ sequenceDecs_decodeSync_amd64_adjust_skip: MOVD R13, R12 sequenceDecs_decodeSync_amd64_after_adjust: - MOVD R12, 8(RSP) + MOVD R12, 16(RSP) // Check values - MOVD 16(RSP), R0 - MOVD 24(RSP), R1 + MOVD 24(RSP), R0 + MOVD 32(RSP), R1 ADD R1, R0, R13 MOVD s+0(FP), R14 MOVD 256(R14), R16 @@ -1666,14 +1651,15 @@ sequenceDecs_decodeSync_amd64_after_adjust: BNE sequenceDecs_decodeSync_amd64_error_match_len_ofs_mismatch sequenceDecs_decodeSync_amd64_match_len_ofs_ok: - MOVD 24(RSP), R0 - MOVD 8(RSP), R1 - MOVD 16(RSP), R12 + MOVD 32(RSP), R0 + MOVD 16(RSP), R1 + MOVD 24(RSP), R12 // Check if we have enough space in s.out ADD R12, R0, R13 + ADD $16, R13, R13 ADD R9, R13, R13 - MOVD 32(RSP), R16 + MOVD 40(RSP), R16 CMP R16, R13 BHI error_not_enough_space @@ -1683,25 +1669,25 @@ sequenceDecs_decodeSync_amd64_match_len_ofs_ok: MOVD $0, R13 copy_1: - ADD R13, R10, R15 - VLD1 (R15), [V0.B16] - ADD R13, R9, R15 - VST1 [V0.B16], (R15) - ADD $0x10, R13, R13 - CMP R0, R13 - BLO copy_1 - ADD R0, R10, R10 - ADD R0, R9, R9 - ADD R0, R11, R11 + ADD R13, R10, R15 + FMOVQ (R15), F0 + ADD R13, R9, R15 + FMOVQ F0, (R15) + ADD $0x10, R13, R13 + CMP R0, R13 + BLO copy_1 + ADD R0, R10, R10 + ADD R0, R9, R9 + ADD R0, R11, R11 // Malformed input if seq.mo > t+len(hist) || seq.mo > s.windowSize) check_offset: MOVD R11, R0 - MOVD 40(RSP), R16 + MOVD 48(RSP), R16 ADD R16, R0, R0 CMP R0, R1 BGT error_match_off_too_big - MOVD 56(RSP), R16 + MOVD 64(RSP), R16 CMP R16, R1 BGT error_match_off_too_big @@ -1709,7 +1695,7 @@ check_offset: MOVD R1, R0 SUBS R11, R0, R0 BLS copy_match - MOVD 48(RSP), R13 + MOVD 56(RSP), R13 SUB R0, R13, R13 CMP R0, R12 BGT copy_all_from_history @@ -1718,21 +1704,19 @@ check_offset: BLO copy_4_small copy_4_loop: - VLD1 (R13), [V0.B16] - VST1 [V0.B16], (R9) - ADD $0x10, R13, R13 - ADD $0x10, R9, R9 - SUBS $0x10, R0, R0 - BHS copy_4_loop - ADD R0, R13, R13 - ADD $16, R13, R13 - ADD R0, R9, R9 - ADD $16, R9, R9 - ADD $-16, R13, R15 - VLD1 (R15), [V0.B16] - ADD $-16, R9, R15 - VST1 [V0.B16], (R15) - JMP copy_4_end + FMOVQ (R13), F0 + FMOVQ F0, (R9) + ADD $0x10, R13, R13 + ADD $0x10, R9, R9 + SUBS $0x10, R0, R0 + BHS copy_4_loop + ADD R0, R13, R13 + ADD $16, R13, R13 + ADD R0, R9, R9 + ADD $16, R9, R9 + FMOVQ -16(R13), F0 + FMOVQ F0, -16(R9) + JMP copy_4_end copy_4_small: CMP $0x03, R12 @@ -1742,13 +1726,14 @@ copy_4_small: JMP copy_4_move_8through16 copy_4_move_3: - MOVH (R13), R0 - MOVB 2(R13), R1 - MOVH R0, (R9) - MOVB R1, 2(R9) - ADD R12, R13, R13 - ADD R12, R9, R9 - JMP copy_4_end + MOVHU (R13), R0 + MOVBU 2(R13), R16 + BFI $0, R16, $8, R1 + MOVH R0, (R9) + MOVB R1, 2(R9) + ADD R12, R13, R13 + ADD R12, R9, R9 + JMP copy_4_end copy_4_move_4through7: MOVWU (R13), R0 @@ -1782,21 +1767,19 @@ copy_all_from_history: BLO copy_5_small copy_5_loop: - VLD1 (R13), [V0.B16] - VST1 [V0.B16], (R9) - ADD $0x10, R13, R13 - ADD $0x10, R9, R9 - SUBS $0x10, R14, R14 - BHS copy_5_loop - ADD R14, R13, R13 - ADD $16, R13, R13 - ADD R14, R9, R9 - ADD $16, R9, R9 - ADD $-16, R13, R15 - VLD1 (R15), [V0.B16] - ADD $-16, R9, R15 - VST1 [V0.B16], (R15) - JMP copy_5_end + FMOVQ (R13), F0 + FMOVQ F0, (R9) + ADD $0x10, R13, R13 + ADD $0x10, R9, R9 + SUBS $0x10, R14, R14 + BHS copy_5_loop + ADD R14, R13, R13 + ADD $16, R13, R13 + ADD R14, R9, R9 + ADD $16, R9, R9 + FMOVQ -16(R13), F0 + FMOVQ F0, -16(R9) + JMP copy_5_end copy_5_small: CMP $0x03, R0 @@ -1807,24 +1790,27 @@ copy_5_small: JMP copy_5_move_8through16 copy_5_move_1or2: - MOVB (R13), R14 - ADD R0, R13, R15 - MOVB -1(R15), R4 - MOVB R14, (R9) - ADD R0, R9, R15 - MOVB R4, -1(R15) - ADD R0, R13, R13 - ADD R0, R9, R9 - JMP copy_5_end + MOVBU (R13), R16 + BFI $0, R16, $8, R14 + ADD R0, R13, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R4 + MOVB R14, (R9) + ADD R0, R9, R15 + MOVB R4, -1(R15) + ADD R0, R13, R13 + ADD R0, R9, R9 + JMP copy_5_end copy_5_move_3: - MOVH (R13), R14 - MOVB 2(R13), R4 - MOVH R14, (R9) - MOVB R4, 2(R9) - ADD R0, R13, R13 - ADD R0, R9, R9 - JMP copy_5_end + MOVHU (R13), R14 + MOVBU 2(R13), R16 + BFI $0, R16, $8, R4 + MOVH R14, (R9) + MOVB R4, 2(R9) + ADD R0, R13, R13 + ADD R0, R9, R9 + JMP copy_5_end copy_5_move_4through7: MOVWU (R13), R14 @@ -1866,25 +1852,25 @@ copy_match: ADD R12, R9, R9 copy_2: - VLD1 (R0), [V0.B16] - VST1 [V0.B16], (R1) - ADD $0x10, R0, R0 - ADD $0x10, R1, R1 - SUBS $0x10, R12, R12 - BHI copy_2 - JMP handle_loop + FMOVQ (R0), F0 + FMOVQ F0, (R1) + ADD $0x10, R0, R0 + ADD $0x10, R1, R1 + SUBS $0x10, R12, R12 + BHI copy_2 + JMP handle_loop // Copy overlapping match copy_overlapping_match: ADD R12, R11, R11 copy_slow_3: - MOVB (R0), R1 - MOVB R1, (R9) - ADD $1, R0, R0 - ADD $1, R9, R9 - SUBS $1, R12, R12 - BNE copy_slow_3 + MOVBU (R0), R1 + MOVB R1, (R9) + ADD $1, R0, R0 + ADD $1, R9, R9 + SUBS $1, R12, R12 + BNE copy_slow_3 handle_loop: MOVD ctx+16(FP), R0 @@ -1913,7 +1899,7 @@ loop_finished: // Return with match length error sequenceDecs_decodeSync_amd64_error_match_len_ofs_mismatch: - MOVD 16(RSP), R0 + MOVD 24(RSP), R0 MOVD ctx+16(FP), R1 MOVD R0, 216(R1) MOVD $0x00000001, R16 @@ -1923,7 +1909,7 @@ sequenceDecs_decodeSync_amd64_error_match_len_ofs_mismatch: // Return with match too long error sequenceDecs_decodeSync_amd64_error_match_len_too_big: MOVD ctx+16(FP), R0 - MOVD 16(RSP), R1 + MOVD 24(RSP), R1 MOVD R1, 216(R0) MOVD $0x00000002, R16 MOVD R16, ret+24(FP) @@ -1932,7 +1918,7 @@ sequenceDecs_decodeSync_amd64_error_match_len_too_big: // Return with match offset too long error error_match_off_too_big: MOVD ctx+16(FP), R0 - MOVD 8(RSP), R1 + MOVD 16(RSP), R1 MOVD R1, 224(R0) MOVD R11, 136(R0) MOVD $0x00000003, R16 @@ -1942,7 +1928,7 @@ error_match_off_too_big: // Return with not enough literals error error_not_enough_literals: MOVD ctx+16(FP), R0 - MOVD 24(RSP), R1 + MOVD 32(RSP), R1 MOVD R1, 208(R0) MOVD $0x00000004, R16 MOVD R16, ret+24(FP) @@ -1957,9 +1943,9 @@ error_overread: // Return with not enough output space error error_not_enough_space: MOVD ctx+16(FP), R0 - MOVD 24(RSP), R1 + MOVD 32(RSP), R1 MOVD R1, 208(R0) - MOVD 16(RSP), R1 + MOVD 24(RSP), R1 MOVD R1, 216(R0) MOVD R11, 136(R0) MOVD $0x00000005, R16 @@ -1977,41 +1963,41 @@ TEXT ·sequenceDecs_decodeSync_safe_arm64(SB), $64-32 MOVD (R1), R0 MOVD 32(R1), R5 ADD R5, R0, R0 - MOVD R0, (RSP) + MOVD R0, 8(RSP) MOVD ctx+16(FP), R0 MOVD 72(R0), R6 MOVD 80(R0), R7 MOVD 88(R0), R8 MOVD $0, R1 - MOVD R1, 8(RSP) MOVD R1, 16(RSP) MOVD R1, 24(RSP) + MOVD R1, 32(RSP) MOVD 112(R0), R9 MOVD 128(R0), R1 - MOVD R1, 32(RSP) + MOVD R1, 40(RSP) MOVD 144(R0), R10 MOVD 136(R0), R11 MOVD 200(R0), R1 - MOVD R1, 56(RSP) + MOVD R1, 64(RSP) MOVD 176(R0), R1 - MOVD R1, 48(RSP) + MOVD R1, 56(RSP) MOVD 184(R0), R0 - MOVD R0, 40(RSP) - MOVD 40(RSP), R0 - MOVD 48(RSP), R16 + MOVD R0, 48(RSP) + MOVD 48(RSP), R0 + MOVD 56(RSP), R16 ADD R0, R16, R16 - MOVD R16, 48(RSP) + MOVD R16, 56(RSP) // Calculate pointer to s.out[cap(s.out)] (a past-end pointer) - MOVD 32(RSP), R16 + MOVD 40(RSP), R16 ADD R9, R16, R16 - MOVD R16, 32(RSP) + MOVD R16, 40(RSP) // outBase += outPosition ADD R11, R9, R9 sequenceDecs_decodeSync_safe_amd64_main_loop: - MOVD (RSP), R12 + MOVD 8(RSP), R12 // Fill bitreader to have enough for the offset and match length. CMP $0x08, R5 @@ -2061,7 +2047,7 @@ sequenceDecs_decodeSync_safe_amd64_fill_end: ADD R13, R0, R0 sequenceDecs_decodeSync_safe_amd64_of_update_zero: - MOVD R0, 8(RSP) + MOVD R0, 16(RSP) // Update match length MOVD R7, R0 @@ -2082,7 +2068,7 @@ sequenceDecs_decodeSync_safe_amd64_of_update_zero: ADD R13, R0, R0 sequenceDecs_decodeSync_safe_amd64_ml_update_zero: - MOVD R0, 16(RSP) + MOVD R0, 24(RSP) // Fill bitreader to have enough for the remaining CMP $0x08, R5 @@ -2132,17 +2118,15 @@ sequenceDecs_decodeSync_safe_amd64_fill_2_end: ADD R13, R0, R0 sequenceDecs_decodeSync_safe_amd64_ll_update_zero: - MOVD R0, 24(RSP) + MOVD R0, 32(RSP) // Fill bitreader for state updates - MOVD R12, (RSP) - MOVD R8, R0 - LSR $0x08, R0, R0 - MOVBU R0, R0 - MOVD ctx+16(FP), R1 - MOVD 96(R1), R16 - CMP $0x00, R16 - BEQ sequenceDecs_decodeSync_safe_amd64_skip_update + MOVD R12, 8(RSP) + UBFX $8, R8, $8, R0 + MOVD ctx+16(FP), R1 + MOVD 96(R1), R16 + CMP $0x00, R16 + BEQ sequenceDecs_decodeSync_safe_amd64_skip_update // Update Literal Length State MOVBU R6, R12 @@ -2153,7 +2137,7 @@ sequenceDecs_decodeSync_safe_amd64_ll_update_zero: NEG R1, R16 ROR R16, R13, R13 MOVD $0x00000001, R14 - MOVB R12, R1 + MOVBU R12, R1 LSLW R1, R14, R14 SUBW $1, R14, R14 AND R14, R13, R13 @@ -2162,8 +2146,7 @@ sequenceDecs_decodeSync_safe_amd64_ll_update_zero: // Load ctx.llTable MOVD ctx+16(FP), R1 MOVD (R1), R1 - ADD R6<<3, R1, R15 - MOVD (R15), R6 + MOVD (R1)(R6<<3), R6 // Update Match Length State MOVBU R7, R12 @@ -2174,7 +2157,7 @@ sequenceDecs_decodeSync_safe_amd64_ll_update_zero: NEG R1, R16 ROR R16, R13, R13 MOVD $0x00000001, R14 - MOVB R12, R1 + MOVBU R12, R1 LSLW R1, R14, R14 SUBW $1, R14, R14 AND R14, R13, R13 @@ -2183,8 +2166,7 @@ sequenceDecs_decodeSync_safe_amd64_ll_update_zero: // Load ctx.mlTable MOVD ctx+16(FP), R1 MOVD 24(R1), R1 - ADD R7<<3, R1, R15 - MOVD (R15), R7 + MOVD (R1)(R7<<3), R7 // Update Offset State MOVBU R8, R12 @@ -2195,7 +2177,7 @@ sequenceDecs_decodeSync_safe_amd64_ll_update_zero: NEG R1, R16 ROR R16, R13, R13 MOVD $0x00000001, R14 - MOVB R12, R1 + MOVBU R12, R1 LSLW R1, R14, R14 SUBW $1, R14, R14 AND R14, R13, R13 @@ -2204,24 +2186,21 @@ sequenceDecs_decodeSync_safe_amd64_ll_update_zero: // Load ctx.ofTable MOVD ctx+16(FP), R1 MOVD 48(R1), R1 - ADD R8<<3, R1, R15 - MOVD (R15), R8 + MOVD (R1)(R8<<3), R8 sequenceDecs_decodeSync_safe_amd64_skip_update: // Adjust offset - MOVD s+0(FP), R1 - MOVD 8(RSP), R12 - CMP $0x01, R0 - BLS sequenceDecs_decodeSync_safe_amd64_adjust_offsetB_1_or_0 - ADD $144, R1, R15 - VLD1 (R15), [V0.B16] - MOVD R12, 144(R1) - ADD $152, R1, R15 - VST1 [V0.B16], (R15) - JMP sequenceDecs_decodeSync_safe_amd64_after_adjust + MOVD s+0(FP), R1 + MOVD 16(RSP), R12 + CMP $0x01, R0 + BLS sequenceDecs_decodeSync_safe_amd64_adjust_offsetB_1_or_0 + FMOVQ 144(R1), F0 + MOVD R12, 144(R1) + FMOVQ F0, 152(R1) + JMP sequenceDecs_decodeSync_safe_amd64_after_adjust sequenceDecs_decodeSync_safe_amd64_adjust_offsetB_1_or_0: - MOVD 24(RSP), R16 + MOVD 32(RSP), R16 CMP $0x00000000, R16 BNE sequenceDecs_decodeSync_safe_amd64_adjust_offset_maybezero ADD $1, R12, R12 @@ -2259,11 +2238,11 @@ sequenceDecs_decodeSync_safe_amd64_adjust_skip: MOVD R13, R12 sequenceDecs_decodeSync_safe_amd64_after_adjust: - MOVD R12, 8(RSP) + MOVD R12, 16(RSP) // Check values - MOVD 16(RSP), R0 - MOVD 24(RSP), R1 + MOVD 24(RSP), R0 + MOVD 32(RSP), R1 ADD R1, R0, R13 MOVD s+0(FP), R14 MOVD 256(R14), R16 @@ -2282,14 +2261,14 @@ sequenceDecs_decodeSync_safe_amd64_after_adjust: BNE sequenceDecs_decodeSync_safe_amd64_error_match_len_ofs_mismatch sequenceDecs_decodeSync_safe_amd64_match_len_ofs_ok: - MOVD 24(RSP), R0 - MOVD 8(RSP), R1 - MOVD 16(RSP), R12 + MOVD 32(RSP), R0 + MOVD 16(RSP), R1 + MOVD 24(RSP), R12 // Check if we have enough space in s.out ADD R12, R0, R13 ADD R9, R13, R13 - MOVD 32(RSP), R16 + MOVD 40(RSP), R16 CMP R16, R13 BHI error_not_enough_space @@ -2301,21 +2280,19 @@ sequenceDecs_decodeSync_safe_amd64_match_len_ofs_ok: BLO copy_1_small copy_1_loop: - VLD1 (R10), [V0.B16] - VST1 [V0.B16], (R9) - ADD $0x10, R10, R10 - ADD $0x10, R9, R9 - SUBS $0x10, R13, R13 - BHS copy_1_loop - ADD R13, R10, R10 - ADD $16, R10, R10 - ADD R13, R9, R9 - ADD $16, R9, R9 - ADD $-16, R10, R15 - VLD1 (R15), [V0.B16] - ADD $-16, R9, R15 - VST1 [V0.B16], (R15) - JMP copy_1_end + FMOVQ (R10), F0 + FMOVQ F0, (R9) + ADD $0x10, R10, R10 + ADD $0x10, R9, R9 + SUBS $0x10, R13, R13 + BHS copy_1_loop + ADD R13, R10, R10 + ADD $16, R10, R10 + ADD R13, R9, R9 + ADD $16, R9, R9 + FMOVQ -16(R10), F0 + FMOVQ F0, -16(R9) + JMP copy_1_end copy_1_small: CMP $0x03, R0 @@ -2326,24 +2303,27 @@ copy_1_small: JMP copy_1_move_8through16 copy_1_move_1or2: - MOVB (R10), R13 - ADD R0, R10, R15 - MOVB -1(R15), R14 - MOVB R13, (R9) - ADD R0, R9, R15 - MOVB R14, -1(R15) - ADD R0, R10, R10 - ADD R0, R9, R9 - JMP copy_1_end + MOVBU (R10), R16 + BFI $0, R16, $8, R13 + ADD R0, R10, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R14 + MOVB R13, (R9) + ADD R0, R9, R15 + MOVB R14, -1(R15) + ADD R0, R10, R10 + ADD R0, R9, R9 + JMP copy_1_end copy_1_move_3: - MOVH (R10), R13 - MOVB 2(R10), R14 - MOVH R13, (R9) - MOVB R14, 2(R9) - ADD R0, R10, R10 - ADD R0, R9, R9 - JMP copy_1_end + MOVHU (R10), R13 + MOVBU 2(R10), R16 + BFI $0, R16, $8, R14 + MOVH R13, (R9) + MOVB R14, 2(R9) + ADD R0, R10, R10 + ADD R0, R9, R9 + JMP copy_1_end copy_1_move_4through7: MOVWU (R10), R13 @@ -2372,11 +2352,11 @@ copy_1_end: // Malformed input if seq.mo > t+len(hist) || seq.mo > s.windowSize) check_offset: MOVD R11, R0 - MOVD 40(RSP), R16 + MOVD 48(RSP), R16 ADD R16, R0, R0 CMP R0, R1 BGT error_match_off_too_big - MOVD 56(RSP), R16 + MOVD 64(RSP), R16 CMP R16, R1 BGT error_match_off_too_big @@ -2384,7 +2364,7 @@ check_offset: MOVD R1, R0 SUBS R11, R0, R0 BLS copy_match - MOVD 48(RSP), R13 + MOVD 56(RSP), R13 SUB R0, R13, R13 CMP R0, R12 BGT copy_all_from_history @@ -2393,21 +2373,19 @@ check_offset: BLO copy_4_small copy_4_loop: - VLD1 (R13), [V0.B16] - VST1 [V0.B16], (R9) - ADD $0x10, R13, R13 - ADD $0x10, R9, R9 - SUBS $0x10, R0, R0 - BHS copy_4_loop - ADD R0, R13, R13 - ADD $16, R13, R13 - ADD R0, R9, R9 - ADD $16, R9, R9 - ADD $-16, R13, R15 - VLD1 (R15), [V0.B16] - ADD $-16, R9, R15 - VST1 [V0.B16], (R15) - JMP copy_4_end + FMOVQ (R13), F0 + FMOVQ F0, (R9) + ADD $0x10, R13, R13 + ADD $0x10, R9, R9 + SUBS $0x10, R0, R0 + BHS copy_4_loop + ADD R0, R13, R13 + ADD $16, R13, R13 + ADD R0, R9, R9 + ADD $16, R9, R9 + FMOVQ -16(R13), F0 + FMOVQ F0, -16(R9) + JMP copy_4_end copy_4_small: CMP $0x03, R12 @@ -2417,13 +2395,14 @@ copy_4_small: JMP copy_4_move_8through16 copy_4_move_3: - MOVH (R13), R0 - MOVB 2(R13), R1 - MOVH R0, (R9) - MOVB R1, 2(R9) - ADD R12, R13, R13 - ADD R12, R9, R9 - JMP copy_4_end + MOVHU (R13), R0 + MOVBU 2(R13), R16 + BFI $0, R16, $8, R1 + MOVH R0, (R9) + MOVB R1, 2(R9) + ADD R12, R13, R13 + ADD R12, R9, R9 + JMP copy_4_end copy_4_move_4through7: MOVWU (R13), R0 @@ -2457,21 +2436,19 @@ copy_all_from_history: BLO copy_5_small copy_5_loop: - VLD1 (R13), [V0.B16] - VST1 [V0.B16], (R9) - ADD $0x10, R13, R13 - ADD $0x10, R9, R9 - SUBS $0x10, R14, R14 - BHS copy_5_loop - ADD R14, R13, R13 - ADD $16, R13, R13 - ADD R14, R9, R9 - ADD $16, R9, R9 - ADD $-16, R13, R15 - VLD1 (R15), [V0.B16] - ADD $-16, R9, R15 - VST1 [V0.B16], (R15) - JMP copy_5_end + FMOVQ (R13), F0 + FMOVQ F0, (R9) + ADD $0x10, R13, R13 + ADD $0x10, R9, R9 + SUBS $0x10, R14, R14 + BHS copy_5_loop + ADD R14, R13, R13 + ADD $16, R13, R13 + ADD R14, R9, R9 + ADD $16, R9, R9 + FMOVQ -16(R13), F0 + FMOVQ F0, -16(R9) + JMP copy_5_end copy_5_small: CMP $0x03, R0 @@ -2482,24 +2459,27 @@ copy_5_small: JMP copy_5_move_8through16 copy_5_move_1or2: - MOVB (R13), R14 - ADD R0, R13, R15 - MOVB -1(R15), R4 - MOVB R14, (R9) - ADD R0, R9, R15 - MOVB R4, -1(R15) - ADD R0, R13, R13 - ADD R0, R9, R9 - JMP copy_5_end + MOVBU (R13), R16 + BFI $0, R16, $8, R14 + ADD R0, R13, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R4 + MOVB R14, (R9) + ADD R0, R9, R15 + MOVB R4, -1(R15) + ADD R0, R13, R13 + ADD R0, R9, R9 + JMP copy_5_end copy_5_move_3: - MOVH (R13), R14 - MOVB 2(R13), R4 - MOVH R14, (R9) - MOVB R4, 2(R9) - ADD R0, R13, R13 - ADD R0, R9, R9 - JMP copy_5_end + MOVHU (R13), R14 + MOVBU 2(R13), R16 + BFI $0, R16, $8, R4 + MOVH R14, (R9) + MOVB R4, 2(R9) + ADD R0, R13, R13 + ADD R0, R9, R9 + JMP copy_5_end copy_5_move_4through7: MOVWU (R13), R14 @@ -2542,21 +2522,19 @@ copy_match: BLO copy_2_small copy_2_loop: - VLD1 (R0), [V0.B16] - VST1 [V0.B16], (R9) - ADD $0x10, R0, R0 - ADD $0x10, R9, R9 - SUBS $0x10, R1, R1 - BHS copy_2_loop - ADD R1, R0, R0 - ADD $16, R0, R0 - ADD R1, R9, R9 - ADD $16, R9, R9 - ADD $-16, R0, R15 - VLD1 (R15), [V0.B16] - ADD $-16, R9, R15 - VST1 [V0.B16], (R15) - JMP copy_2_end + FMOVQ (R0), F0 + FMOVQ F0, (R9) + ADD $0x10, R0, R0 + ADD $0x10, R9, R9 + SUBS $0x10, R1, R1 + BHS copy_2_loop + ADD R1, R0, R0 + ADD $16, R0, R0 + ADD R1, R9, R9 + ADD $16, R9, R9 + FMOVQ -16(R0), F0 + FMOVQ F0, -16(R9) + JMP copy_2_end copy_2_small: CMP $0x03, R12 @@ -2567,24 +2545,27 @@ copy_2_small: JMP copy_2_move_8through16 copy_2_move_1or2: - MOVB (R0), R1 - ADD R12, R0, R15 - MOVB -1(R15), R13 - MOVB R1, (R9) - ADD R12, R9, R15 - MOVB R13, -1(R15) - ADD R12, R0, R0 - ADD R12, R9, R9 - JMP copy_2_end + MOVBU (R0), R16 + BFI $0, R16, $8, R1 + ADD R12, R0, R15 + MOVBU -1(R15), R16 + BFI $0, R16, $8, R13 + MOVB R1, (R9) + ADD R12, R9, R15 + MOVB R13, -1(R15) + ADD R12, R0, R0 + ADD R12, R9, R9 + JMP copy_2_end copy_2_move_3: - MOVH (R0), R1 - MOVB 2(R0), R13 - MOVH R1, (R9) - MOVB R13, 2(R9) - ADD R12, R0, R0 - ADD R12, R9, R9 - JMP copy_2_end + MOVHU (R0), R1 + MOVBU 2(R0), R16 + BFI $0, R16, $8, R13 + MOVH R1, (R9) + MOVB R13, 2(R9) + ADD R12, R0, R0 + ADD R12, R9, R9 + JMP copy_2_end copy_2_move_4through7: MOVWU (R0), R1 @@ -2615,12 +2596,12 @@ copy_overlapping_match: ADD R12, R11, R11 copy_slow_3: - MOVB (R0), R1 - MOVB R1, (R9) - ADD $1, R0, R0 - ADD $1, R9, R9 - SUBS $1, R12, R12 - BNE copy_slow_3 + MOVBU (R0), R1 + MOVB R1, (R9) + ADD $1, R0, R0 + ADD $1, R9, R9 + SUBS $1, R12, R12 + BNE copy_slow_3 handle_loop: MOVD ctx+16(FP), R0 @@ -2649,7 +2630,7 @@ loop_finished: // Return with match length error sequenceDecs_decodeSync_safe_amd64_error_match_len_ofs_mismatch: - MOVD 16(RSP), R0 + MOVD 24(RSP), R0 MOVD ctx+16(FP), R1 MOVD R0, 216(R1) MOVD $0x00000001, R16 @@ -2659,7 +2640,7 @@ sequenceDecs_decodeSync_safe_amd64_error_match_len_ofs_mismatch: // Return with match too long error sequenceDecs_decodeSync_safe_amd64_error_match_len_too_big: MOVD ctx+16(FP), R0 - MOVD 16(RSP), R1 + MOVD 24(RSP), R1 MOVD R1, 216(R0) MOVD $0x00000002, R16 MOVD R16, ret+24(FP) @@ -2668,7 +2649,7 @@ sequenceDecs_decodeSync_safe_amd64_error_match_len_too_big: // Return with match offset too long error error_match_off_too_big: MOVD ctx+16(FP), R0 - MOVD 8(RSP), R1 + MOVD 16(RSP), R1 MOVD R1, 224(R0) MOVD R11, 136(R0) MOVD $0x00000003, R16 @@ -2678,7 +2659,7 @@ error_match_off_too_big: // Return with not enough literals error error_not_enough_literals: MOVD ctx+16(FP), R0 - MOVD 24(RSP), R1 + MOVD 32(RSP), R1 MOVD R1, 208(R0) MOVD $0x00000004, R16 MOVD R16, ret+24(FP) @@ -2693,9 +2674,9 @@ error_overread: // Return with not enough output space error error_not_enough_space: MOVD ctx+16(FP), R0 - MOVD 24(RSP), R1 + MOVD 32(RSP), R1 MOVD R1, 208(R0) - MOVD 16(RSP), R1 + MOVD 24(RSP), R1 MOVD R1, 216(R0) MOVD R11, 136(R0) MOVD $0x00000005, R16 diff --git a/vendor/github.com/klauspost/compress/zstd/seqdec_asm.go b/vendor/github.com/klauspost/compress/zstd/seqdec_asm.go index 55405f391..42ce5de71 100644 --- a/vendor/github.com/klauspost/compress/zstd/seqdec_asm.go +++ b/vendor/github.com/klauspost/compress/zstd/seqdec_asm.go @@ -77,6 +77,35 @@ const errorNotEnoughSpace = 5 // error reported when bits are overread. const errorOverread = 6 +// useSafeDecodeSync reports whether decodeSyncSimple must use the bounds-exact +// ("safe") copy variants for the current buffer geometry. +// +// When the output and literal buffers have compressedBlockOverAlloc (16) +// bytes of slack past their logical use, the assembly may use extended +// memory copies that read and write in 16-byte blocks, overrunning the end +// of a literal run or match by up to 15 bytes. Otherwise it must use the +// bounds-exact ("safe") copies. This mirrors the analogous, always-dynamic +// selection in executeSimple below. +// +// The unsafe copies were disabled in #644 (2022) as a mitigation for a +// crash, but that crash's root cause — an unguarded bitReader overread that +// produced out-of-range match offsets/lengths — was fixed three days later +// in #645, which also added the fuzz corpus that has guarded this path since. +// See #1168. An asan-instrumented fuzz job (see .github/workflows/go.yml) +// covers the extended-copy path, which -race and plain fuzzing cannot. +func (s *sequenceDecs) useSafeDecodeSync() bool { + if s.maxSyncLen == 0 && cap(s.out)-len(s.out) < maxCompressedBlockSizeAlloc { + return true + } + if s.maxSyncLen > 0 && cap(s.out)-len(s.out)-compressedBlockOverAlloc < int(s.maxSyncLen) { + return true + } + if cap(s.literals) < len(s.literals)+compressedBlockOverAlloc { + return true + } + return false +} + // decode sequences from the stream with the provided history but without a dictionary. func (s *sequenceDecs) decodeSyncSimple(hist []byte) (bool, error) { if len(s.dict) > 0 { @@ -86,9 +115,7 @@ func (s *sequenceDecs) decodeSyncSimple(hist []byte) (bool, error) { return false, nil } - // FIXME: Using unsafe memory copies leads to rare, random crashes - // with fuzz testing. It is therefore disabled for now. - const useSafe = true + useSafe := s.useSafeDecodeSync() br := s.br diff --git a/vendor/modules.txt b/vendor/modules.txt index 26f08a2bc..595cc796d 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -231,8 +231,8 @@ github.com/jhump/protoreflect/v2/internal/reparse github.com/jhump/protoreflect/v2/internal/sort github.com/jhump/protoreflect/v2/protoresolve github.com/jhump/protoreflect/v2/sourceinfo -# github.com/klauspost/compress v1.19.1 -## explicit; go 1.24 +# github.com/klauspost/compress v1.20.0 +## explicit; go 1.25 github.com/klauspost/compress github.com/klauspost/compress/flate github.com/klauspost/compress/fse @@ -241,6 +241,7 @@ github.com/klauspost/compress/huff0 github.com/klauspost/compress/internal/cpuinfo github.com/klauspost/compress/internal/le github.com/klauspost/compress/internal/race +github.com/klauspost/compress/internal/regmask github.com/klauspost/compress/internal/snapref github.com/klauspost/compress/s2 github.com/klauspost/compress/snappy From b73b1f5db22b53b9b211e2b89938c4222dd06002 Mon Sep 17 00:00:00 2001 From: hyuraku <32809703+hyuraku@users.noreply.github.com> Date: Fri, 18 Sep 2026 00:01:25 +0900 Subject: [PATCH 162/182] fix(webcrypto): stop getRandomValues from panicking on bad input (#6368) * fix(webcrypto): Validate getRandomValues input * test(webcrypto): cover invalid getRandomValues inputs * fix(webcrypto): throw ECMAScript TypeErrors for invalid input --- internal/js/modules/k6/webcrypto/crypto.go | 15 +++ .../js/modules/k6/webcrypto/crypto_test.go | 119 ++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 internal/js/modules/k6/webcrypto/crypto_test.go diff --git a/internal/js/modules/k6/webcrypto/crypto.go b/internal/js/modules/k6/webcrypto/crypto.go index 1f054e96d..150504148 100644 --- a/internal/js/modules/k6/webcrypto/crypto.go +++ b/internal/js/modules/k6/webcrypto/crypto.go @@ -36,6 +36,15 @@ type Crypto struct { // // [specification]: https://www.w3.org/TR/WebCryptoAPI/#Crypto-method-getRandomValues func (c *Crypto) GetRandomValues(typedArray sobek.Value) sobek.Value { + // The typedArray parameter is not optional in the specification's WebIDL + // definition, so reject a missing or nullish one before IsInstanceOf gets + // to dereference it. This is an ECMAScript TypeError rather than one of the + // WebCrypto error names, which is what browsers and Node throw here, and + // what a nullish argument already produced before this check existed. + if common.IsNullish(typedArray) { + panic(c.vu.Runtime().NewTypeError("typedArray parameter is required")) + } + acceptedTypes := []JSType{ Int8ArrayConstructor, Uint8ArrayConstructor, @@ -61,6 +70,12 @@ func (c *Crypto) GetRandomValues(typedArray sobek.Value) sobek.Value { common.Throw(c.vu.Runtime(), NewError(TypeMismatchError, "typedArray parameter isn't a TypedArray instance")) } + // The length property is script-controlled and can be overridden with a + // negative value, which would make the make() call below panic. + if objLength < 0 { + panic(c.vu.Runtime().NewTypeError("typedArray parameter's length is negative")) + } + if objLength > maxRandomValuesLength { common.Throw( c.vu.Runtime(), diff --git a/internal/js/modules/k6/webcrypto/crypto_test.go b/internal/js/modules/k6/webcrypto/crypto_test.go new file mode 100644 index 000000000..b6253b2a2 --- /dev/null +++ b/internal/js/modules/k6/webcrypto/crypto_test.go @@ -0,0 +1,119 @@ +// Note: this test lives in the webcrypto_test package because js/modulestest +// imports webcrypto, so an in-package test would create an import cycle. +package webcrypto_test + +import ( + "fmt" + "testing" + + "github.com/grafana/sobek" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "go.k6.io/k6/v2/js/modulestest" +) + +// catchScript runs the given statements and reports what the script saw, so the +// assertions can look at the thrown value the way a user's test would, instead +// of at the Go error RunString wraps it in. +const catchScript = ` + (function () { + try { + %s + return { threw: false }; + } catch (e) { + return { threw: true, isTypeError: e instanceof TypeError, text: String(e) }; + } + })() +` + +// TestGetRandomValuesRejectsBadInput asserts that bad input to +// crypto.getRandomValues() is reported to the script as a catchable error, +// instead of taking the whole k6 process down with a Go panic. +// +// See https://github.com/grafana/k6/issues/6320 +func TestGetRandomValuesRejectsBadInput(t *testing.T) { + t.Parallel() + + testCases := []struct { + name string + script string + // wantTypeError is true when the script should see a genuine ECMAScript + // TypeError, so that `e instanceof TypeError` holds the way it does in + // browsers and in Node. The WebCrypto error names are not ECMAScript + // errors, so they are reported as GoError instead. + wantTypeError bool + // wantMessage is a substring of the thrown value's string form. + wantMessage string + }{ + { + // GetRandomValues receives a nil sobek.Value, and IsInstanceOf + // dereferences it. The WebIDL argument is required, so browsers + // throw a TypeError here. + name: "no argument", + script: `crypto.getRandomValues()`, + wantTypeError: true, + wantMessage: "typedArray parameter is required", + }, + { + // A nullish argument already threw a TypeError before the check + // that fixes the case above existed, so it has to keep throwing + // one, or scripts branching on `e instanceof TypeError` break. + name: "null argument", + script: `crypto.getRandomValues(null)`, + wantTypeError: true, + wantMessage: "typedArray parameter is required", + }, + { + name: "undefined argument", + script: `crypto.getRandomValues(undefined)`, + wantTypeError: true, + wantMessage: "typedArray parameter is required", + }, + { + // Not an ArrayBufferView at all. Today k6 reports this as a + // TypeMismatchError, which the spec reserves for views of the + // wrong element type (Float32Array, DataView, ...). Left as it is, + // since it never panicked and changing it is a separate concern. + name: "not a TypedArray", + script: `crypto.getRandomValues({})`, + wantTypeError: false, + wantMessage: "TypeMismatchError", + }, + { + // The array is a real Uint8Array, so the element type is fine, + // but make([]byte, -1) panics. + name: "length overridden with a negative value", + script: ` + const a = new Uint8Array(4); + Object.defineProperty(a, "length", { value: -1 }); + crypto.getRandomValues(a); + `, + wantTypeError: true, + wantMessage: "typedArray parameter's length is negative", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + + // NewRuntime already calls webcrypto.SetupGlobally, so the + // crypto object is available as a global. + rt := modulestest.NewRuntime(t) + + var ( + got sobek.Value + err error + ) + require.NotPanics(t, func() { + got, err = rt.VU.Runtime().RunString(fmt.Sprintf(catchScript, tc.script)) + }) + require.NoError(t, err) + + result := got.ToObject(rt.VU.Runtime()) + require.True(t, result.Get("threw").ToBoolean(), "the script was expected to throw") + assert.Equal(t, tc.wantTypeError, result.Get("isTypeError").ToBoolean()) + assert.Contains(t, result.Get("text").String(), tc.wantMessage) + }) + } +} From 5e8d90667ca3324cf5e840893d7aed2a63a7b5f9 Mon Sep 17 00:00:00 2001 From: Inanc Gumus Date: Thu, 17 Sep 2026 11:01:56 -0400 Subject: [PATCH 163/182] Fix selector waits for absent elements (#6412) Hidden and detached waits should succeed when no element matches. Return null to JavaScript in that case and preserve element handles when a hidden element still exists. --- .../browser/browser/element_handle_mapping.go | 4 + .../browser/element_handle_mapping_test.go | 9 +++ .../js/modules/k6/browser/common/frame.go | 3 + .../k6/browser/common/js/injected_script.js | 2 +- .../js/modules/k6/browser/tests/page_test.go | 81 +++++++++++-------- 5 files changed, 64 insertions(+), 35 deletions(-) diff --git a/internal/js/modules/k6/browser/browser/element_handle_mapping.go b/internal/js/modules/k6/browser/browser/element_handle_mapping.go index 7e7098246..b4d97d2b1 100644 --- a/internal/js/modules/k6/browser/browser/element_handle_mapping.go +++ b/internal/js/modules/k6/browser/browser/element_handle_mapping.go @@ -15,6 +15,10 @@ import ( // mapElementHandle to the JS module. func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint:gocognit,funlen,cyclop + if eh == nil { + return nil + } + rt := vu.Runtime() maps := mapping{ "boundingBox": func() *sobek.Promise { diff --git a/internal/js/modules/k6/browser/browser/element_handle_mapping_test.go b/internal/js/modules/k6/browser/browser/element_handle_mapping_test.go index 7f84dab97..69695322a 100644 --- a/internal/js/modules/k6/browser/browser/element_handle_mapping_test.go +++ b/internal/js/modules/k6/browser/browser/element_handle_mapping_test.go @@ -4,6 +4,7 @@ import ( "testing" "time" + "github.com/grafana/sobek" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -674,3 +675,11 @@ func TestParseElementHandleScreenshotOptions(t *testing.T) { }) } } + +func TestMapElementHandleNil(t *testing.T) { + t.Parallel() + + vu := k6test.NewVU(t) + value := vu.Runtime().ToValue(mapElementHandle(moduleVU{VU: vu}, nil)) + assert.True(t, sobek.IsNull(value)) +} diff --git a/internal/js/modules/k6/browser/common/frame.go b/internal/js/modules/k6/browser/common/frame.go index 1cd852efd..16e8ca1db 100644 --- a/internal/js/modules/k6/browser/common/frame.go +++ b/internal/js/modules/k6/browser/common/frame.go @@ -501,6 +501,9 @@ func (f *Frame) waitForSelector(selector string, opts *FrameWaitForSelectorOptio return nil, err } if handle == nil { + if opts.State == DOMElementStateHidden || opts.State == DOMElementStateDetached { + return nil, nil //nolint:nilnil + } return nil, fmt.Errorf("waiting for selector %q did not result in any nodes", selector) } diff --git a/internal/js/modules/k6/browser/common/js/injected_script.js b/internal/js/modules/k6/browser/common/js/injected_script.js index 535702ba4..dc3347a60 100644 --- a/internal/js/modules/k6/browser/common/js/injected_script.js +++ b/internal/js/modules/k6/browser/common/js/injected_script.js @@ -2597,7 +2597,7 @@ class InjectedScript { case "visible": return visible ? element : continuePolling; case "hidden": - return !visible ? element : continuePolling; + return !visible ? element || true : continuePolling; } }; diff --git a/internal/js/modules/k6/browser/tests/page_test.go b/internal/js/modules/k6/browser/tests/page_test.go index 0ffd31d0f..b44ce7c4b 100644 --- a/internal/js/modules/k6/browser/tests/page_test.go +++ b/internal/js/modules/k6/browser/tests/page_test.go @@ -1473,33 +1473,45 @@ func TestPageWaitForSelector(t *testing.T) { } testCases := []struct { - name string - url string - opts map[string]any - customTimeout time.Duration - selector string - errAssert func(*testing.T, error) + name string + selector string + state common.DOMElementState + timeout time.Duration + wantNil bool + wantErr string }{ { name: "should wait for selector", - url: "wait_for.html", selector: "#my-div", - errAssert: func(t *testing.T, e error) { - t.Helper() - assert.Nil(t, e) - }, + state: common.DOMElementStateVisible, + timeout: common.DefaultTimeout, }, { - name: "should TO waiting for selector", - url: "wait_for.html", - // set a timeout smaller than the time - // it takes the element to show up - customTimeout: time.Nanosecond, - selector: "#my-div", - errAssert: func(t *testing.T, e error) { - t.Helper() - assert.ErrorContains(t, e, "timed out after") - }, + name: "should TO waiting for selector", + selector: "#my-div", + state: common.DOMElementStateVisible, + timeout: time.Nanosecond, + wantErr: "timed out after", + }, + { + name: "absent hidden element", + selector: "#absent", + state: common.DOMElementStateHidden, + timeout: time.Second, + wantNil: true, + }, + { + name: "absent detached element", + selector: "#absent", + state: common.DOMElementStateDetached, + timeout: time.Second, + wantNil: true, + }, + { + name: "existing hidden element", + selector: "head", + state: common.DOMElementStateHidden, + timeout: time.Second, }, } @@ -1508,24 +1520,25 @@ func TestPageWaitForSelector(t *testing.T) { t.Parallel() tb := newTestBrowser(t, withFileServer()) - page := tb.NewPage(nil) - opts := &common.FrameGotoOptions{ + _, err := page.Goto(tb.staticURL("wait_for.html"), &common.FrameGotoOptions{ Timeout: common.DefaultTimeout, - } - _, err := page.Goto( - tb.staticURL(tc.url), - opts, - ) + }) require.NoError(t, err) - timeout := page.MainFrame().Timeout() - if tc.customTimeout != 0 { - timeout = tc.customTimeout + opts := common.NewFrameWaitForSelectorOptions(tc.timeout) + opts.State = tc.state + element, err := page.WaitForSelector(tc.selector, opts) + if tc.wantErr != "" { + require.ErrorContains(t, err, tc.wantErr) + return + } + require.NoError(t, err) + if tc.wantNil { + assert.Nil(t, element) + } else { + assert.NotNil(t, element) } - - _, err = page.WaitForSelector(tc.selector, common.NewFrameWaitForSelectorOptions(timeout)) - tc.errAssert(t, err) }) } } From 0c0eb0a1c2fc0feb74febd1a2f3a486b32f6d29a Mon Sep 17 00:00:00 2001 From: Inanc Gumus Date: Thu, 17 Sep 2026 11:04:30 -0400 Subject: [PATCH 164/182] browser: bound screenshot capture time (#6414) * Bound screenshot capture by configured timeouts Unanswered layout and capture requests used the page lifetime, leaving scripts unable to handle screenshot failures before teardown. Apply the screenshot deadline to shared capture work and restore the viewport and background with a bounded cleanup context. Keep the page usable after the operation times out and preserve cancellation. * Simplify screenshot regression coverage Exercise deadline and cancellation behavior through page screenshots in one table. Check the actual background reset and keep failed viewport restoration from reporting a size the browser did not accept. Drop the redundant viewport return value now that restoration preserves the original emulation settings. --- .../k6/browser/common/element_handle.go | 6 +- .../k6/browser/common/frame_session.go | 9 +- internal/js/modules/k6/browser/common/page.go | 23 ++- .../common/screenshot_deadline_test.go | 162 ++++++++++++++++++ .../k6/browser/common/screenshotter.go | 129 +++++++------- .../js/modules/k6/browser/tests/page_test.go | 32 +++- 6 files changed, 283 insertions(+), 78 deletions(-) create mode 100644 internal/js/modules/k6/browser/common/screenshot_deadline_test.go diff --git a/internal/js/modules/k6/browser/common/element_handle.go b/internal/js/modules/k6/browser/common/element_handle.go index 5089e30cf..3f97a9211 100644 --- a/internal/js/modules/k6/browser/common/element_handle.go +++ b/internal/js/modules/k6/browser/common/element_handle.go @@ -1391,9 +1391,13 @@ func (h *ElementHandle) Screenshot( span.SetAttributes(attribute.String("screenshot.path", opts.Path)) - s := newScreenshotter(spanCtx, sp, h.logger) + s, cancel := newScreenshotter(spanCtx, opts.Timeout, sp, h.logger) + defer cancel() buf, err := s.screenshotElement(h, opts) if err != nil { + if errors.Is(s.ctx.Err(), context.DeadlineExceeded) && h.ctx.Err() == nil { + err = &k6ext.UserFriendlyError{Err: err, Timeout: opts.Timeout} + } return nil, spanRecordErrorf(span, "taking screenshot of elementHandle: %w", err) } diff --git a/internal/js/modules/k6/browser/common/frame_session.go b/internal/js/modules/k6/browser/common/frame_session.go index fd8b10b63..5cedef4f7 100644 --- a/internal/js/modules/k6/browser/common/frame_session.go +++ b/internal/js/modules/k6/browser/common/frame_session.go @@ -563,7 +563,7 @@ func (fs *FrameSession) initOptions() error { if fs.isMainFrame() { optActions = append(optActions, emulation.SetFocusEmulationEnabled(true)) - if err := fs.updateViewport(); err != nil { + if err := fs.updateViewport(fs.ctx, fs.page.emulatedSize); err != nil { fs.logger.Debugf("NewFrameSession:initOptions:updateViewport", "sid:%v tid:%v, err:%v", fs.session.ID(), fs.targetID, err) @@ -1279,7 +1279,7 @@ func (fs *FrameSession) updateRequestInterception(enable bool) error { return fs.networkManager.setRequestInterception(enable) } -func (fs *FrameSession) updateViewport() error { +func (fs *FrameSession) updateViewport(ctx context.Context, emulatedSize *EmulatedSize) error { fs.logger.Debugf("NewFrameSession:updateViewport", "sid:%v tid:%v", fs.session.ID(), fs.targetID) // other frames don't have viewports and, @@ -1292,7 +1292,6 @@ func (fs *FrameSession) updateViewport() error { } opts := fs.page.browserCtx.opts - emulatedSize := fs.page.emulatedSize if emulatedSize == nil { return nil } @@ -1311,7 +1310,7 @@ func (fs *FrameSession) updateViewport() error { WithScreenOrientation(&orientation). WithScreenWidth(screen.Width). WithScreenHeight(screen.Height) - if err := action.Do(cdp.WithExecutor(fs.ctx, fs.session)); err != nil { + if err := action.Do(cdp.WithExecutor(ctx, fs.session)); err != nil { return fmt.Errorf("emulating viewport: %w", err) } @@ -1326,7 +1325,7 @@ func (fs *FrameSession) updateViewport() error { Width: viewport.Width, Height: viewport.Height, }) - if err := action2.Do(cdp.WithExecutor(fs.ctx, fs.session)); err != nil { + if err := action2.Do(cdp.WithExecutor(ctx, fs.session)); err != nil { return fmt.Errorf("setting window bounds: %w", err) } } diff --git a/internal/js/modules/k6/browser/common/page.go b/internal/js/modules/k6/browser/common/page.go index 6b28fd800..108b7334c 100644 --- a/internal/js/modules/k6/browser/common/page.go +++ b/internal/js/modules/k6/browser/common/page.go @@ -802,21 +802,24 @@ func (p *Page) hasRoutes() bool { return len(p.routes) > 0 } -func (p *Page) resetViewport() error { +func (p *Page) resetViewport(ctx context.Context) error { p.logger.Debugf("Page:resetViewport", "sid:%v", p.sessionID()) action := emulation.SetDeviceMetricsOverride(0, 0, 0, false) - return action.Do(cdp.WithExecutor(p.ctx, p.session)) + return action.Do(cdp.WithExecutor(ctx, p.session)) } -func (p *Page) setEmulatedSize(emulatedSize *EmulatedSize) error { +func (p *Page) setEmulatedSize(ctx context.Context, emulatedSize *EmulatedSize) error { p.logger.Debugf("Page:setEmulatedSize", "sid:%v", p.sessionID()) + if err := p.mainFrameSession.updateViewport(ctx, emulatedSize); err != nil { + return err + } p.emulatedSize = emulatedSize - return p.mainFrameSession.updateViewport() + return nil } -func (p *Page) setViewportSize(viewportSize *Size) error { +func (p *Page) setViewportSize(ctx context.Context, viewportSize *Size) error { p.logger.Debugf("Page:setViewportSize", "sid:%v vps:%v", p.sessionID(), viewportSize) @@ -828,7 +831,7 @@ func (p *Page) setViewportSize(viewportSize *Size) error { Width: int64(viewportSize.Width), Height: int64(viewportSize.Height), } - return p.setEmulatedSize(NewEmulatedSize(viewport, screen)) + return p.setEmulatedSize(ctx, NewEmulatedSize(viewport, screen)) } func (p *Page) updateExtraHTTPHeaders() error { @@ -1696,9 +1699,13 @@ func (p *Page) Screenshot(opts *PageScreenshotOptions, sp ScreenshotPersister) ( span.SetAttributes(attribute.String("screenshot.path", opts.Path)) - s := newScreenshotter(spanCtx, sp, p.logger) + s, cancel := newScreenshotter(spanCtx, p.defaultTimeout(), sp, p.logger) + defer cancel() buf, err := s.screenshotPage(p, opts) if err != nil { + if errors.Is(s.ctx.Err(), context.DeadlineExceeded) && p.ctx.Err() == nil { + err = &k6ext.UserFriendlyError{Err: err, Timeout: p.defaultTimeout()} + } return nil, spanRecordErrorf(span, "taking screenshot of page: %w", err) } @@ -1753,7 +1760,7 @@ func (p *Page) SetInputFiles(selector string, files *Files, opts *FrameSetInputF func (p *Page) SetViewportSize(viewportSize *Size) error { p.logger.Debugf("Page:SetViewportSize", "sid:%v", p.sessionID()) - if err := p.setViewportSize(viewportSize); err != nil { + if err := p.setViewportSize(p.ctx, viewportSize); err != nil { return fmt.Errorf("setting viewport size: %w", err) } diff --git a/internal/js/modules/k6/browser/common/screenshot_deadline_test.go b/internal/js/modules/k6/browser/common/screenshot_deadline_test.go new file mode 100644 index 000000000..697c3b9f5 --- /dev/null +++ b/internal/js/modules/k6/browser/common/screenshot_deadline_test.go @@ -0,0 +1,162 @@ +package common + +import ( + "context" + "errors" + "fmt" + "testing" + "testing/synctest" + "time" + + "github.com/chromedp/cdproto/cdp" + "github.com/chromedp/cdproto/emulation" + "github.com/chromedp/cdproto/page" + "github.com/stretchr/testify/require" + "go.k6.io/k6/v2/internal/js/modules/k6/browser/log" +) + +type screenshotDeadlineSession struct { + session + blocked string + backgroundColors []*cdp.RGBA + backgroundRestoreErr bool +} + +const screenshotTimeout = 20 * time.Millisecond + +func (s *screenshotDeadlineSession) Execute(ctx context.Context, method string, params, result any) error { + if err := ctx.Err(); err != nil { + return err + } + if method == s.blocked { + <-ctx.Done() + return ctx.Err() + } + + switch method { + case "Page.getLayoutMetrics": + result.(*page.GetLayoutMetricsReturns).CSSVisualViewport = &page.VisualViewport{Scale: 1} + case "Page.captureScreenshot": + case "Emulation.setDefaultBackgroundColorOverride": + color := params.(*emulation.SetDefaultBackgroundColorOverrideParams).Color + s.backgroundColors = append(s.backgroundColors, color) + if s.backgroundRestoreErr && color == nil { + return errors.New("background restore failed") + } + case "Emulation.setDeviceMetricsOverride": + default: + return fmt.Errorf("unexpected CDP method %q", method) + } + return nil +} + +func testScreenshotPage(ctx context.Context, sess session, timeout time.Duration) *Page { + settings := NewTimeoutSettings(nil) + settings.setDefaultTimeout(timeout) + return &Page{ + ctx: ctx, session: sess, timeoutSettings: settings, logger: log.NewNullLogger(), + emulatedSize: NewEmulatedSize(Viewport{Width: 100, Height: 100}, Screen{Width: 100, Height: 100}), + } +} + +func TestScreenshotBehavior(t *testing.T) { + t.Parallel() + for _, tc := range []struct { + name string + blocked string + timeout, cancelAfter time.Duration + wantErr error + omitBackground bool + backgroundRestoreErr bool + }{ + { + name: "deadline at layout metrics", blocked: "Page.getLayoutMetrics", + timeout: screenshotTimeout, wantErr: context.DeadlineExceeded, + }, + { + name: "deadline at capture", blocked: "Page.captureScreenshot", + timeout: screenshotTimeout, wantErr: context.DeadlineExceeded, + }, + { + name: "restores transparent background", blocked: "Page.captureScreenshot", + timeout: screenshotTimeout, wantErr: context.DeadlineExceeded, omitBackground: true, + }, + { + name: "joins background restore error", blocked: "Page.captureScreenshot", + timeout: screenshotTimeout, wantErr: context.DeadlineExceeded, + omitBackground: true, backgroundRestoreErr: true, + }, + { + name: "parent cancellation with timeout", blocked: "Page.getLayoutMetrics", + timeout: time.Second, cancelAfter: 20 * time.Millisecond, wantErr: context.Canceled, + }, + { + name: "parent cancellation with zero timeout", blocked: "Page.getLayoutMetrics", + cancelAfter: 20 * time.Millisecond, wantErr: context.Canceled, + }, + } { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + synctest.Test(t, func(t *testing.T) { + ctx, cancel := context.WithTimeout(t.Context(), 100*time.Millisecond) + defer cancel() + if tc.cancelAfter > 0 { + go func() { + time.Sleep(tc.cancelAfter) + cancel() + }() + } + sess := &screenshotDeadlineSession{ + session: &Session{}, blocked: tc.blocked, + backgroundRestoreErr: tc.backgroundRestoreErr, + } + p := testScreenshotPage(ctx, sess, tc.timeout) + opts := NewPageScreenshotOptions() + opts.OmitBackground = tc.omitBackground + + start := time.Now() + _, err := p.Screenshot(opts, nil) + require.ErrorIs(t, err, tc.wantErr) + require.Equal(t, screenshotTimeout, time.Since(start)) + if errors.Is(tc.wantErr, context.DeadlineExceeded) { + require.ErrorContains(t, err, "timed out after 20ms") + } + if tc.omitBackground { + require.Equal(t, []*cdp.RGBA{{A: 0}, nil}, sess.backgroundColors) + } + if tc.backgroundRestoreErr { + require.ErrorContains(t, err, "resetting screenshot background color: background restore failed") + } + if tc.cancelAfter > 0 { + require.ErrorIs(t, ctx.Err(), context.Canceled) + } else { + require.NoError(t, ctx.Err()) + } + }) + }) + } +} + +func TestScreenshotRestoreUsesBoundedCleanup(t *testing.T) { + t.Parallel() + synctest.Test(t, func(t *testing.T) { + ctx := t.Context() + sess := &screenshotDeadlineSession{session: &Session{}, blocked: "Emulation.setDeviceMetricsOverride"} + logger := log.NewNullLogger() + temporarySize := NewEmulatedSize(Viewport{Width: 300, Height: 300}, Screen{Width: 300, Height: 300}) + p := &Page{ + ctx: ctx, session: sess, logger: logger, emulatedSize: temporarySize, + browserCtx: &BrowserContext{opts: DefaultBrowserContextOptions()}, + } + p.mainFrameSession = &FrameSession{ctx: ctx, session: sess, page: p, logger: logger} + s, stop := newScreenshotter(ctx, 20*time.Millisecond, nil, logger) + stop() + + start := time.Now() + err := s.restoreViewport(p, NewEmulatedSize(Viewport{Width: 100, Height: 100}, Screen{Width: 200, Height: 200})) + require.ErrorIs(t, err, context.DeadlineExceeded) + require.Equal(t, screenshotCleanupTimeout, time.Since(start)) + require.NoError(t, ctx.Err()) + require.Same(t, temporarySize, p.emulatedSize, "failed restoration must not update the cached viewport") + }) +} diff --git a/internal/js/modules/k6/browser/common/screenshotter.go b/internal/js/modules/k6/browser/common/screenshotter.go index 4caa5b9c9..d905d8fc7 100644 --- a/internal/js/modules/k6/browser/common/screenshotter.go +++ b/internal/js/modules/k6/browser/common/screenshotter.go @@ -9,6 +9,7 @@ import ( "io" "math" "strings" + "time" "github.com/chromedp/cdproto/cdp" "github.com/chromedp/cdproto/emulation" @@ -72,16 +73,32 @@ func (f *ImageFormat) UnmarshalJSON(b []byte) error { type screenshotter struct { ctx context.Context + parentCtx context.Context persister ScreenshotPersister logger *log.Logger } +// Cleanup gets a short independent budget after the operation deadline expires. +const screenshotCleanupTimeout = time.Second + func newScreenshotter( ctx context.Context, + timeout time.Duration, sp ScreenshotPersister, logger *log.Logger, -) *screenshotter { - return &screenshotter{ctx, sp, logger} +) (*screenshotter, context.CancelFunc) { + parentCtx := ctx + var cancel context.CancelFunc + if timeout > 0 { + ctx, cancel = context.WithTimeout(ctx, timeout) + } else { + ctx, cancel = context.WithCancel(ctx) + } + return &screenshotter{ctx: ctx, parentCtx: parentCtx, persister: sp, logger: logger}, cancel +} + +func (s *screenshotter) cleanupContext() (context.Context, context.CancelFunc) { + return context.WithTimeout(s.parentCtx, screenshotCleanupTimeout) } func (s *screenshotter) fullPageSize(p *Page) (*Size, error) { @@ -118,11 +135,10 @@ func (s *screenshotter) fullPageSize(p *Page) (*Size, error) { return &size, nil } -func (s *screenshotter) originalViewportSize(p *Page) (*Size, *Size, error) { - originalViewportSize := p.viewportSize() - viewportSize := originalViewportSize +func (s *screenshotter) originalViewportSize(p *Page) (*Size, error) { + viewportSize := p.viewportSize() if viewportSize.Width != 0 || viewportSize.Height != 0 { - return &viewportSize, &originalViewportSize, nil + return &viewportSize, nil } opts := evalOptions{ @@ -134,40 +150,46 @@ func (s *screenshotter) originalViewportSize(p *Page) (*Size, *Size, error) { { width: window.innerWidth, height: window.innerHeight } )`) if err != nil { - return nil, nil, fmt.Errorf("getting viewport dimensions: %w", err) + return nil, fmt.Errorf("getting viewport dimensions: %w", err) } var returnVal Size if err := convert(result, &returnVal); err != nil { - return nil, nil, fmt.Errorf("unpacking window size: %w", err) + return nil, fmt.Errorf("unpacking window size: %w", err) } viewportSize.Width = returnVal.Width viewportSize.Height = returnVal.Height - return &viewportSize, &originalViewportSize, nil + return &viewportSize, nil } -func (s *screenshotter) restoreViewport(p *Page, originalViewport *Size) error { - if originalViewport != nil { - return p.setViewportSize(originalViewport) +func (s *screenshotter) restoreViewport(p *Page, originalSize *EmulatedSize) error { + ctx, cancel := s.cleanupContext() + defer cancel() + if originalSize != nil { + return p.setEmulatedSize(ctx, originalSize) } - return p.resetViewport() + return p.resetViewport(ctx) } func (s *screenshotter) screenshot( sess session, doc, viewport *Rect, format ImageFormat, omitBackground bool, quality int64, path string, -) ([]byte, error) { - var ( - buf []byte - clip *cdppage.Viewport - ) +) (buf []byte, err error) { + var clip *cdppage.Viewport capture := cdppage.CaptureScreenshot() shouldSetDefaultBackground := omitBackground && format == "png" if shouldSetDefaultBackground { action := emulation.SetDefaultBackgroundColorOverride(). WithColor(&cdp.RGBA{R: 0, G: 0, B: 0, A: 0}) + defer func() { + ctx, cancel := s.cleanupContext() + defer cancel() + if restoreErr := emulation.SetDefaultBackgroundColorOverride().Do(cdp.WithExecutor(ctx, sess)); restoreErr != nil { + err = errors.Join(err, fmt.Errorf("resetting screenshot background color: %w", restoreErr)) + } + }() if err := action.Do(cdp.WithExecutor(s.ctx, sess)); err != nil { return nil, fmt.Errorf("setting screenshot background transparency: %w", err) } @@ -221,13 +243,6 @@ func (s *screenshotter) screenshot( return nil, fmt.Errorf("capturing screenshot: %w", err) } - if shouldSetDefaultBackground { - action := emulation.SetDefaultBackgroundColorOverride() - if err := action.Do(cdp.WithExecutor(s.ctx, sess)); err != nil { - return nil, fmt.Errorf("resetting screenshot background color: %w", err) - } - } - // Save screenshot capture to file if path != "" { if err := s.persister.Persist(s.ctx, path, bytes.NewBuffer(buf)); err != nil { @@ -269,12 +284,15 @@ func getViewPortDimensions(ctx context.Context, sess session, logger *log.Logger return visualViewportScale, visualViewportPageX, visualViewportPageY, nil } -func (s *screenshotter) screenshotElement(h *ElementHandle, opts *ElementHandleScreenshotOptions) ([]byte, error) { +func (s *screenshotter) screenshotElement( + h *ElementHandle, opts *ElementHandleScreenshotOptions, +) (buf []byte, err error) { format := opts.Format - viewportSize, originalViewportSize, err := s.originalViewportSize(h.frame.page) + viewportSize, err := s.originalViewportSize(h.frame.page) if err != nil { return nil, fmt.Errorf("getting original viewport size: %w", err) } + originalSize := h.frame.page.emulatedSize err = h.waitAndScrollIntoViewIfNeeded(h.ctx, false, true, opts.Timeout) if err != nil { @@ -292,14 +310,18 @@ func (s *screenshotter) screenshotElement(h *ElementHandle, opts *ElementHandleS return nil, fmt.Errorf("node has 0 height") } - var overriddenViewportSize *Size fitsViewport := bbox.Width <= viewportSize.Width && bbox.Height <= viewportSize.Height if !fitsViewport { //nolint:nestif - overriddenViewportSize = Size{ + overriddenViewportSize := Size{ Width: math.Max(viewportSize.Width, bbox.Width), Height: math.Max(viewportSize.Height, bbox.Height), }.enclosingIntSize() - if err := h.frame.page.setViewportSize(overriddenViewportSize); err != nil { + defer func() { + if restoreErr := s.restoreViewport(h.frame.page, originalSize); restoreErr != nil { + err = errors.Join(err, fmt.Errorf("restoring viewport: %w", restoreErr)) + } + }() + if err := h.frame.page.setViewportSize(s.ctx, overriddenViewportSize); err != nil { return nil, fmt.Errorf("setting viewport size to %s: %w", overriddenViewportSize, err) } @@ -333,7 +355,7 @@ func (s *screenshotter) screenshotElement(h *ElementHandle, opts *ElementHandleS documentRect.X += returnVal.X documentRect.Y += returnVal.Y - buf, err := s.screenshot( + return s.screenshot( h.frame.page.session, documentRect.enclosingIntRect(), nil, // viewportRect @@ -342,19 +364,9 @@ func (s *screenshotter) screenshotElement(h *ElementHandle, opts *ElementHandleS opts.Quality, opts.Path, ) - if err != nil { - return nil, err - } - if overriddenViewportSize != nil { - if err := s.restoreViewport(h.frame.page, originalViewportSize); err != nil { - return nil, fmt.Errorf("restoring viewport: %w", err) - } - } - - return buf, nil } -func (s *screenshotter) screenshotPage(p *Page, opts *PageScreenshotOptions) ([]byte, error) { +func (s *screenshotter) screenshotPage(p *Page, opts *PageScreenshotOptions) (buf []byte, err error) { format := opts.Format // Infer file format by path @@ -364,15 +376,16 @@ func (s *screenshotter) screenshotPage(p *Page, opts *PageScreenshotOptions) ([] } } - viewportSize, originalViewportSize, err := s.originalViewportSize(p) + viewportSize, err := s.originalViewportSize(p) if err != nil { return nil, fmt.Errorf("getting original viewport size: %w", err) } + originalSize := p.emulatedSize if opts.FullPage { //nolint:nestif - fullPageSize, err := s.fullPageSize(p) - if err != nil { - return nil, fmt.Errorf("getting full page size: %w", err) + fullPageSize, sizeErr := s.fullPageSize(p) + if sizeErr != nil { + return nil, fmt.Errorf("getting full page size: %w", sizeErr) } documentRect := &Rect{ X: 0, @@ -380,13 +393,17 @@ func (s *screenshotter) screenshotPage(p *Page, opts *PageScreenshotOptions) ([] Width: fullPageSize.Width, Height: fullPageSize.Height, } - var overriddenViewportSize *Size fitsViewport := fullPageSize.Width <= viewportSize.Width && fullPageSize.Height <= viewportSize.Height if !fitsViewport { - overriddenViewportSize = fullPageSize - if err := p.setViewportSize(overriddenViewportSize); err != nil { + defer func() { + if restoreErr := s.restoreViewport(p, originalSize); restoreErr != nil { + err = errors.Join(err, fmt.Errorf("restoring viewport to %s: %w", + viewportSize, restoreErr)) + } + }() + if err := p.setViewportSize(s.ctx, fullPageSize); err != nil { return nil, fmt.Errorf("setting viewport size to %s: %w", - overriddenViewportSize, err) + fullPageSize, err) } } if opts.Clip != nil { @@ -401,17 +418,7 @@ func (s *screenshotter) screenshotPage(p *Page, opts *PageScreenshotOptions) ([] } } - buf, err := s.screenshot(p.session, documentRect, nil, format, opts.OmitBackground, opts.Quality, opts.Path) - if err != nil { - return nil, err - } - if overriddenViewportSize != nil { - if err := s.restoreViewport(p, originalViewportSize); err != nil { - return nil, fmt.Errorf("restoring viewport to %s: %w", - originalViewportSize, err) - } - } - return buf, nil + return s.screenshot(p.session, documentRect, nil, format, opts.OmitBackground, opts.Quality, opts.Path) } viewportRect := &Rect{ diff --git a/internal/js/modules/k6/browser/tests/page_test.go b/internal/js/modules/k6/browser/tests/page_test.go index b44ce7c4b..3c3b10f5b 100644 --- a/internal/js/modules/k6/browser/tests/page_test.go +++ b/internal/js/modules/k6/browser/tests/page_test.go @@ -674,6 +674,16 @@ func TestPageSetChecked(t *testing.T) { assert.False(t, checked) } +type timeoutScreenshotPersister struct { + called bool +} + +func (p *timeoutScreenshotPersister) Persist(ctx context.Context, _ string, _ io.Reader) error { + p.called = true + <-ctx.Done() + return ctx.Err() +} + func TestPageScreenshotFullpage(t *testing.T) { t.Parallel() @@ -693,7 +703,7 @@ func TestPageScreenshotFullpage(t *testing.T) { const div = document.createElement('div'); div.style.width = '1280px'; - div.style.height = '800px'; + div.style.height = '1600px'; div.style.background = 'linear-gradient(to bottom, red, blue)'; document.body.appendChild(div); @@ -710,21 +720,37 @@ func TestPageScreenshotFullpage(t *testing.T) { opts.FullPage = true buf, err := p.Screenshot(opts, &mockPersister{}) require.NoError(t, err) + assert.Equal(t, map[string]float64{"width": 1280, "height": 800}, p.ViewportSize()) + viewportRestored, err := p.Evaluate(`() => window.innerWidth === 1280 && window.innerHeight === 800`) + require.NoError(t, err) + assert.Equal(t, true, viewportRestored) reader := bytes.NewReader(buf) img, err := png.Decode(reader) assert.Nil(t, err) assert.Equal(t, 1280, img.Bounds().Max.X, "want: screenshot width is 1280px, got: %dpx", img.Bounds().Max.X) - assert.Equal(t, 800, img.Bounds().Max.Y, "want: screenshot height is 800px, got: %dpx", img.Bounds().Max.Y) + assert.Equal(t, 1600, img.Bounds().Max.Y, "want: screenshot height is 1600px, got: %dpx", img.Bounds().Max.Y) // Allow tolerance to account for differences in rendering between // different platforms and browsers. The goal is to ensure that the // screenshot is mostly red at the top and mostly blue at the bottom. r, _, b, _ := img.At(0, 0).RGBA() assert.Truef(t, r > b*2, "want: the top pixel to be dominantly red, got R: %d, B: %d", r, b) - r, _, b, _ = img.At(0, 799).RGBA() + r, _, b, _ = img.At(0, 1599).RGBA() assert.Truef(t, b > r*2, "want: the bottom pixel to be dominantly blue, got R: %d, B: %d", r, b) + + // A deadline after capture must also restore the enlarged viewport. + p.SetDefaultTimeout(2000) + opts.Path = "unused.png" + persister := &timeoutScreenshotPersister{} + _, err = p.Screenshot(opts, persister) + require.ErrorIs(t, err, context.DeadlineExceeded) + require.True(t, persister.called) + assert.Equal(t, map[string]float64{"width": 1280, "height": 800}, p.ViewportSize()) + viewportRestored, err = p.Evaluate(`() => window.innerWidth === 1280 && window.innerHeight === 800`) + require.NoError(t, err) + assert.Equal(t, true, viewportRestored) } func TestPageTitle(t *testing.T) { From 3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee Mon Sep 17 00:00:00 2001 From: Olha Yevtushenko Date: Fri, 18 Sep 2026 13:51:21 +0300 Subject: [PATCH 165/182] feat: add execution_result to /v1/status API (#6388) --- api/v1/status.go | 37 +++++++++++++++++++----------- api/v1/status_routes_test.go | 20 ++++++++++++++++ internal/cmd/run.go | 17 +++++++++++++- internal/cmd/tests/cmd_run_test.go | 34 +++++++++++++++++++++++++++ lib/execution.go | 19 +++++++++++++++ 5 files changed, 113 insertions(+), 14 deletions(-) diff --git a/api/v1/status.go b/api/v1/status.go index c82a000f0..d1753ee7c 100644 --- a/api/v1/status.go +++ b/api/v1/status.go @@ -10,16 +10,26 @@ import ( type Status struct { Status lib.ExecutionStatus `json:"status" yaml:"status"` - Paused null.Bool `json:"paused" yaml:"paused"` - VUs null.Int `json:"vus" yaml:"vus"` - VUsMax null.Int `json:"vus-max" yaml:"vus-max"` - Stopped bool `json:"stopped" yaml:"stopped"` - Running bool `json:"running" yaml:"running"` - Tainted bool `json:"tainted" yaml:"tainted"` + Paused null.Bool `json:"paused" yaml:"paused"` + VUs null.Int `json:"vus" yaml:"vus"` + VUsMax null.Int `json:"vus-max" yaml:"vus-max"` + Stopped bool `json:"stopped" yaml:"stopped"` + Running bool `json:"running" yaml:"running"` + Tainted bool `json:"tainted" yaml:"tainted"` + ExecutionResult *ExecutionResult `json:"execution_result" yaml:"execution_result"` +} + +// ExecutionResult represents the result of a completed test execution. +type ExecutionResult struct { + ExitCode int `json:"exit_code" yaml:"exit_code"` } func newStatus(cs *ControlSurface) Status { executionState := cs.Scheduler.GetState() + var executionResult *ExecutionResult + if exitCode, ok := executionState.GetExecutionResult(); ok { + executionResult = &ExecutionResult{ExitCode: exitCode} + } isStopped := false select { case <-cs.RunCtx.Done(): @@ -27,12 +37,13 @@ func newStatus(cs *ControlSurface) Status { default: } return Status{ - Status: executionState.GetCurrentExecutionStatus(), - Running: executionState.HasStarted() && !executionState.HasEnded(), - Paused: null.BoolFrom(executionState.IsPaused()), - Stopped: isStopped, - VUs: null.IntFrom(executionState.GetCurrentlyActiveVUsCount()), - VUsMax: null.IntFrom(executionState.GetInitializedVUsCount()), - Tainted: cs.MetricsEngine.GetMetricsWithBreachedThresholdsCount() > 0, + Status: executionState.GetCurrentExecutionStatus(), + Running: executionState.HasStarted() && !executionState.HasEnded(), + Paused: null.BoolFrom(executionState.IsPaused()), + Stopped: isStopped, + VUs: null.IntFrom(executionState.GetCurrentlyActiveVUsCount()), + VUsMax: null.IntFrom(executionState.GetInitializedVUsCount()), + Tainted: cs.MetricsEngine.GetMetricsWithBreachedThresholdsCount() > 0, + ExecutionResult: executionResult, } } diff --git a/api/v1/status_routes_test.go b/api/v1/status_routes_test.go index 2dc5f32ef..b767634ec 100644 --- a/api/v1/status_routes_test.go +++ b/api/v1/status_routes_test.go @@ -7,6 +7,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "go.k6.io/k6/v2/internal/lib/testutils/minirunner" "go.k6.io/k6/v2/lib" @@ -49,5 +50,24 @@ func TestGetStatus(t *testing.T) { assert.True(t, status.VUsMax.Valid) assert.False(t, status.Stopped) assert.False(t, status.Tainted) + assert.Nil(t, status.ExecutionResult) + assert.Contains(t, rw.Body.String(), `"execution_result":null`) }) } + +func TestGetStatusExecutionResult(t *testing.T) { + t.Parallel() + + testState := getTestRunState(t, lib.Options{}, &minirunner.MiniRunner{}) + cs := getControlSurface(t, testState) + cs.Scheduler.GetState().SetExecutionResult(108) + + rw := httptest.NewRecorder() + NewHandler(cs).ServeHTTP( + rw, httptest.NewRequestWithContext(t.Context(), http.MethodGet, "/v1/status", nil), + ) + + var statusEnvelop StatusJSONAPI + require.NoError(t, json.Unmarshal(rw.Body.Bytes(), &statusEnvelop)) + assert.Equal(t, &ExecutionResult{ExitCode: 108}, statusEnvelop.Status().ExecutionResult) +} diff --git a/internal/cmd/run.go b/internal/cmd/run.go index 6e4a8865d..ad018af03 100644 --- a/internal/cmd/run.go +++ b/internal/cmd/run.go @@ -470,6 +470,7 @@ func (c *cmdRun) run(cmd *cobra.Command, args []string) (err error) { if err != nil { err = common.UnwrapSobekInterruptedError(err) logger.WithError(err).Debug("Test finished with an error") + setExecutionResult(executionState, err) return err } @@ -483,17 +484,31 @@ func (c *cmdRun) run(cmd *cobra.Command, args []string) (err error) { // ensure we return an error indicating that the test run was marked as failed, and the proper // exit code is used. if testRunState.TestStatus.Failed() { - return errext.WithExitCodeIfNone( + err = errext.WithExitCodeIfNone( fmt.Errorf("test run was marked as failed"), exitcodes.MarkedAsFailed, ) + setExecutionResult(executionState, err) + return err } logger.Debug("Test finished cleanly") + setExecutionResult(executionState, nil) return nil } +func setExecutionResult(executionState *lib.ExecutionState, err error) { + exitCode := 0 + if err != nil { + exitCode = -1 + if ecerr, ok := errors.AsType[errext.HasExitCode](err); ok { + exitCode = int(ecerr.ExitCode()) + } + } + executionState.SetExecutionResult(exitCode) +} + func getSummaryMode(runtimeOptions lib.RuntimeOptions) (summary.Mode, bool, error) { sm, err := summary.ValidateMode(runtimeOptions.SummaryMode.String) if err != nil { diff --git a/internal/cmd/tests/cmd_run_test.go b/internal/cmd/tests/cmd_run_test.go index 57c2c88ec..a2062e2b9 100644 --- a/internal/cmd/tests/cmd_run_test.go +++ b/internal/cmd/tests/cmd_run_test.go @@ -1187,6 +1187,40 @@ func runTestWithLinger(t *testing.T, ts *GlobalTestState) { cmd.ExecuteWithGlobalState(ts.GlobalState) } +func TestExecutionResultWithLinger(t *testing.T) { + t.Parallel() + + addr := getFreeBindAddr(t) + script := ` + import exec from 'k6/execution'; + export default function () { exec.test.abort('foo'); } + ` + ts := getSingleFileTestState(t, script, + []string{"-v", "--log-output=stdout", "--linger", "--address", addr}, exitcodes.ScriptAborted) + ts.Flags.Address = addr + + sendSignal := injectMockSignalNotifier(ts) + asyncWaitForStdoutAndRun(t, ts, 15, time.Second, "waiting for Ctrl+C to continue", func() { + defer func() { + sendSignal <- syscall.SIGINT + <-sendSignal + }() + + req, err := http.NewRequestWithContext(ts.Ctx, http.MethodGet, fmt.Sprintf("http://%s/v1/status", addr), nil) + require.NoError(t, err) + resp, err := http.DefaultClient.Do(req) + require.NoError(t, err) + defer func() { assert.NoError(t, resp.Body.Close()) }() + + body, err := io.ReadAll(resp.Body) + require.NoError(t, err) + assert.Equal(t, int64(exitcodes.ScriptAborted), + gjson.GetBytes(body, "data.attributes.execution_result.exit_code").Int()) + }) + + cmd.ExecuteWithGlobalState(ts.GlobalState) +} + func TestAbortedByScriptSetupError(t *testing.T) { t.Parallel() script := ` diff --git a/lib/execution.go b/lib/execution.go index 6132372ff..0b292f72f 100644 --- a/lib/execution.go +++ b/lib/execution.go @@ -158,6 +158,10 @@ type ExecutionState struct { // observability of the k6 test run progress. executionStatus *uint32 + // The exit code that will result from the completed test execution. It is + // unset until the execution result is known. + executionResultExitCode atomic.Pointer[int] + // A nanosecond UNIX timestamp that is set when the test is actually // started. The default 0 value is used to denote that the test hasn't // started yet... @@ -323,6 +327,21 @@ func (es *ExecutionState) GetCurrentExecutionStatus() ExecutionStatus { return ExecutionStatus(atomic.LoadUint32(es.executionStatus)) } +// SetExecutionResult records the exit code resulting from the test execution. +func (es *ExecutionState) SetExecutionResult(exitCode int) { + es.executionResultExitCode.Store(&exitCode) +} + +// GetExecutionResult returns the test execution's exit code when it is known. +func (es *ExecutionState) GetExecutionResult() (int, bool) { + exitCode := es.executionResultExitCode.Load() + if exitCode == nil { + return 0, false + } + + return *exitCode, true +} + // MarkStarted saves the current timestamp as the test start time. // // CAUTION: Calling MarkStarted() a second time for the same execution state will From 09d4bc5132fa710138e23ebe3a54550093d032bc Mon Sep 17 00:00:00 2001 From: jgaalen Date: Sun, 20 Sep 2026 12:35:48 +0200 Subject: [PATCH 166/182] Remove weekly k6packager schedule --- .github/workflows/packager.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/packager.yml b/.github/workflows/packager.yml index 6edec1d30..892380ed3 100644 --- a/.github/workflows/packager.yml +++ b/.github/workflows/packager.yml @@ -2,8 +2,6 @@ name: k6packager on: # Enable manually triggering this workflow via the API or web UI workflow_dispatch: - schedule: - - cron: '0 0 * * 0' # weekly (Sundays at 00:00) defaults: run: From cff7da7c101ac30179bd7b1b4bd5f71c7435ca7b Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Mon, 21 Sep 2026 03:01:31 +0000 Subject: [PATCH 167/182] fix(deps): update module google.golang.org/grpc to v1.84.0 (#6478) | datasource | package | from | to | | ---------- | ---------------------- | ------- | ------- | | go | google.golang.org/grpc | v1.83.2 | v1.84.0 | Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 +- .../endpointsharding/endpointsharding.go | 339 ++++++------ .../grpc/balancer/pickfirst/pickfirst.go | 50 +- .../grpc_binarylog_v1/binarylog.pb.go | 6 +- vendor/google.golang.org/grpc/call.go | 27 +- vendor/google.golang.org/grpc/clientconn.go | 1 + .../grpc/internal/buffer/unbounded.go | 32 +- .../grpc/internal/envconfig/envconfig.go | 7 + .../grpc/internal/envconfig/xds.go | 5 + .../internal/grpcsync/callback_serializer.go | 6 +- .../grpc/internal/grpcsync/refcounted.go | 109 ++++ .../grpc/internal/internal.go | 4 + .../grpc/internal/resolver/config_selector.go | 15 +- .../grpc/internal/transport/controlbuf.go | 17 + .../grpc/internal/transport/http2_client.go | 57 +- .../grpc/internal/transport/http2_server.go | 1 + .../grpc/internal/transport/http_util.go | 53 +- .../grpc/internal/transport/transport.go | 18 +- .../grpc/metadata/metadata.go | 71 +++ .../grpc/resolver_wrapper.go | 2 +- vendor/google.golang.org/grpc/server.go | 490 ++++-------------- vendor/google.golang.org/grpc/stream.go | 194 +++++-- vendor/google.golang.org/grpc/version.go | 2 +- vendor/modules.txt | 2 +- 25 files changed, 778 insertions(+), 736 deletions(-) create mode 100644 vendor/google.golang.org/grpc/internal/grpcsync/refcounted.go diff --git a/go.mod b/go.mod index 612f93da9..9866f1cdd 100644 --- a/go.mod +++ b/go.mod @@ -61,7 +61,7 @@ require ( golang.org/x/sync v0.22.0 golang.org/x/term v0.45.0 golang.org/x/time v0.15.0 - google.golang.org/grpc v1.83.2 + google.golang.org/grpc v1.84.0 google.golang.org/protobuf v1.36.12 gopkg.in/guregu/null.v3 v3.3.0 gopkg.in/yaml.v3 v3.0.1 diff --git a/go.sum b/go.sum index e77762ca3..0a23c85a8 100644 --- a/go.sum +++ b/go.sum @@ -385,8 +385,8 @@ google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyac google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= -google.golang.org/grpc v1.83.2 h1:EManeRomTObA0BU7I8vXgg/78uE5MJ9M8B39EX2WscU= -google.golang.org/grpc v1.83.2/go.mod h1:YPI1hK3kDked6iHvgX3tR0y+nX/qpMFKhPgFsokw1S8= +google.golang.org/grpc v1.84.0 h1:soMyaPJ8pAak5PIQ0DGBUir0XRo2fRoMqhNWMLlLxO0= +google.golang.org/grpc v1.84.0/go.mod h1:ljCht0DrxQrXBDRTZp52Qxh3Ffk8CdYm2sj4O2QN2C0= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= diff --git a/vendor/google.golang.org/grpc/balancer/endpointsharding/endpointsharding.go b/vendor/google.golang.org/grpc/balancer/endpointsharding/endpointsharding.go index 12479f698..22dbc5228 100644 --- a/vendor/google.golang.org/grpc/balancer/endpointsharding/endpointsharding.go +++ b/vendor/google.golang.org/grpc/balancer/endpointsharding/endpointsharding.go @@ -39,27 +39,14 @@ import ( var randIntN = rand.IntN -// ChildState is the balancer state of a child along with the endpoint which -// identifies the child balancer. +// ChildState is the state of a child balancer. type ChildState struct { - Endpoint resolver.Endpoint - State balancer.State - - // Balancer exposes only the ExitIdler interface of the child LB policy. - // Other methods of the child policy are called only by endpointsharding. - Balancer ExitIdler -} - -// ExitIdler provides access to only the ExitIdle method of the child balancer. -type ExitIdler interface { - // ExitIdle instructs the LB policy to reconnect to backends / exit the - // IDLE state, if appropriate and possible. Note that SubConns that enter - // the IDLE state will not reconnect until SubConn.Connect is called. - ExitIdle() + Endpoint resolver.Endpoint // Endpoint of the child balancer. + State balancer.State // State of the child balancer. + ExitIdle func() // Function to exit the child balancer from IDLE state. } -// Options are the options to configure the behaviour of the -// endpointsharding balancer. +// Options configure the behaviour of the endpointsharding balancer. type Options struct { // DisableAutoReconnect allows the balancer to keep child balancer in the // IDLE state until they are explicitly triggered to exit using the @@ -77,14 +64,13 @@ type ChildBuilderFunc func(cc balancer.ClientConn, opts balancer.BuildOptions) b // policies each owning a single endpoint. The endpointsharding balancer // forwards the LoadBalancingConfig in ClientConn state updates to its children. func NewBalancer(cc balancer.ClientConn, opts balancer.BuildOptions, childBuilder ChildBuilderFunc, esOpts Options) balancer.Balancer { - es := &endpointSharding{ + return &endpointSharding{ cc: cc, bOpts: opts, esOpts: esOpts, childBuilder: childBuilder, + endpoints: resolver.NewEndpointMap[*endpointState](), } - es.children.Store(resolver.NewEndpointMap[*balancerWrapper]()) - return es } // endpointSharding is a balancer that wraps child balancers. It creates a child @@ -96,124 +82,129 @@ type endpointSharding struct { esOpts Options childBuilder ChildBuilderFunc - // childMu synchronizes calls to any single child. It must be held for all - // calls into a child. To avoid deadlocks, do not acquire childMu while - // holding mu. - childMu sync.Mutex - children atomic.Pointer[resolver.EndpointMap[*balancerWrapper]] - - // inhibitChildUpdates is set during UpdateClientConnState/ResolverError - // calls (calls to children will each produce an update, only want one - // update). - inhibitChildUpdates atomic.Bool - - // mu synchronizes access to the state stored in balancerWrappers in the - // children field. mu must not be held during calls into a child since - // synchronous calls back from the child may require taking mu, causing a - // deadlock. To avoid deadlocks, do not acquire childMu while holding mu. - mu sync.Mutex + // mu guards access to the below fields and guarantees mutual exclusion + // between top-down methods (like UpdateClientConnState, ResolverError etc, + // which are already serialized) and bottom-up methods (like UpdateState) + // that can be called concurrently. + // + // Lock ordering & deadlock prevention: + // Child callbacks (like UpdateState) acquire this mutex to push state updates + // to the parent. This establishes a strict lock ordering: + // [endpointState.childMu] -> [endpointSharding.mu] + // + // To prevent deadlocks, we must never invert this order. Therefore, we must + // never call any methods on a child balancer while holding this mutex. If we + // did, and that child balancer invoked UpdateState synchronously, it would + // attempt to re-acquire this mutex, causing a deadlock. + // + // Concurrency: + // Top-down operations need to iterate over all children. To ensure a + // single, clean aggregated update at the end of such operations, we inhibit + // intermediate updates from children. We grab this mutex briefly to set + // `inhibitChildUpdates = true` and immediately release it. This allows us + // to perform the potentially slow, top-down child updates without holding + // any parent locks. Once finished, we grab the mutex again to unset the + // flag and push the final aggregated state. An update from a child during + // this time will *only* update the child state, and will not access the + // endpoints map or push an aggregated state to the parent. + mu sync.Mutex + endpoints *resolver.EndpointMap[*endpointState] + inhibitChildUpdates bool } // rotateEndpoints returns a slice of all the input endpoints rotated a random // amount. func rotateEndpoints(es []resolver.Endpoint) []resolver.Endpoint { - les := len(es) - if les == 0 { + n := len(es) + if n == 0 { return es } - r := randIntN(les) + r := randIntN(n) + // Make a copy to avoid mutating data beyond the end of es. - ret := make([]resolver.Endpoint, les) + ret := make([]resolver.Endpoint, n) copy(ret, es[r:]) - copy(ret[les-r:], es[:r]) + copy(ret[n-r:], es[:r]) return ret } // UpdateClientConnState creates a child for new endpoints and deletes children // for endpoints that are no longer present. It also updates all the children, // and sends a single synchronous update of the childrens' aggregated state at -// the end of the UpdateClientConnState operation. If any endpoint has no -// addresses it will ignore that endpoint. Otherwise, returns first error found -// from a child, but fully processes the new update. +// the end of the UpdateClientConnState operation. +// +// Returns the first error found from a child, but fully processes the update. func (es *endpointSharding) UpdateClientConnState(state balancer.ClientConnState) error { - es.childMu.Lock() - defer es.childMu.Unlock() - - es.inhibitChildUpdates.Store(true) - defer func() { - es.inhibitChildUpdates.Store(false) - es.updateState() - }() - var ret error - - children := es.children.Load() - newChildren := resolver.NewEndpointMap[*balancerWrapper]() + es.inhibitUpdatesFromChildren() - // Update/Create new children. + // Update/create child balancers for each endpoint in the update. Note that we + // don't hold the mutex here, but this is fine because inhibitChildUpdates is + // true, and therefore UpdateState will not access es.endpoints. + var retErr error + newEndpoints := resolver.NewEndpointMap[*endpointState]() for _, endpoint := range rotateEndpoints(state.ResolverState.Endpoints) { - if _, ok := newChildren.Get(endpoint); ok { - // Endpoint child was already created, continue to avoid duplicate - // update. + if _, ok := newEndpoints.Get(endpoint); ok { + // Skip duplicate endpoints. continue } - childBalancer, ok := children.Get(endpoint) + epState, ok := es.endpoints.Get(endpoint) if ok { - // Endpoint attributes may have changed, update the stored endpoint. - es.mu.Lock() - childBalancer.childState.Endpoint = endpoint - es.mu.Unlock() + // Endpoint child already exists, update the stored endpoint. + epState.endpoint = endpoint } else { - childBalancer = &balancerWrapper{ - childState: ChildState{Endpoint: endpoint}, - ClientConn: es.cc, - es: es, + // Endpoint child does not exist, create a new one. + epState = &endpointState{ + ClientConn: es.cc, + parent: es, + endpoint: endpoint, + disableAutoReconnect: es.esOpts.DisableAutoReconnect, } - childBalancer.childState.Balancer = childBalancer - childBalancer.child = es.childBuilder(childBalancer, es.bOpts) + epState.childLB = es.childBuilder(epState, es.bOpts) } - newChildren.Set(endpoint, childBalancer) - if err := childBalancer.updateClientConnStateLocked(balancer.ClientConnState{ + // Update the endpoint state for the endpoint. + newEndpoints.Set(endpoint, epState) + + if err := epState.updateClientConnState(balancer.ClientConnState{ BalancerConfig: state.BalancerConfig, ResolverState: resolver.State{ Endpoints: []resolver.Endpoint{endpoint}, Attributes: state.ResolverState.Attributes, }, - }); err != nil && ret == nil { - // Return first error found, and always commit full processing of - // updating children. If desired to process more specific errors - // across all endpoints, caller should make these specific - // validations, this is a current limitation for simplicity sake. - ret = err + }); err != nil && retErr == nil { + // Keep the first error found from any child. + retErr = err } } + // Delete old children that are no longer present. - for e, child := range children.All() { - if _, ok := newChildren.Get(e); !ok { - child.closeLocked() + for e, child := range es.endpoints.All() { + if _, ok := newEndpoints.Get(e); !ok { + child.close() } } - es.children.Store(newChildren) - if newChildren.Len() == 0 { - return balancer.ErrBadResolverState + + if newEndpoints.Len() == 0 { + retErr = balancer.ErrBadResolverState } - return ret + + es.mu.Lock() + es.endpoints = newEndpoints + es.inhibitChildUpdates = false + es.updateStateLocked() + es.mu.Unlock() + + return retErr } // ResolverError forwards the resolver error to all of the endpointSharding's // children and sends a single synchronous update of the childStates at the end // of the ResolverError operation. func (es *endpointSharding) ResolverError(err error) { - es.childMu.Lock() - defer es.childMu.Unlock() - es.inhibitChildUpdates.Store(true) - defer func() { - es.inhibitChildUpdates.Store(false) - es.updateState() - }() - children := es.children.Load() - for _, child := range children.All() { - child.resolverErrorLocked(err) + es.inhibitUpdatesFromChildren() + for _, child := range es.endpoints.All() { + child.resolverError(err) } + es.allowUpdatesFromChildren() } func (es *endpointSharding) UpdateSubConnState(balancer.SubConn, balancer.SubConnState) { @@ -221,41 +212,49 @@ func (es *endpointSharding) UpdateSubConnState(balancer.SubConn, balancer.SubCon } func (es *endpointSharding) Close() { - es.childMu.Lock() - defer es.childMu.Unlock() - children := es.children.Load() - for _, child := range children.All() { - child.closeLocked() + es.inhibitUpdatesFromChildren() + for _, child := range es.endpoints.All() { + child.close() } } func (es *endpointSharding) ExitIdle() { - es.childMu.Lock() - defer es.childMu.Unlock() - for _, bw := range es.children.Load().All() { - if !bw.isClosed { - bw.child.ExitIdle() - } + es.inhibitUpdatesFromChildren() + for _, child := range es.endpoints.All() { + child.exitIdle() } + es.allowUpdatesFromChildren() } -// updateState updates this component's state. It sends the aggregated state, -// and a picker with round robin behavior with all the child states present if -// needed. -func (es *endpointSharding) updateState() { - if es.inhibitChildUpdates.Load() { - return - } - var readyPickers, connectingPickers, idlePickers, transientFailurePickers []balancer.Picker +func (es *endpointSharding) inhibitUpdatesFromChildren() { + es.mu.Lock() + es.inhibitChildUpdates = true + es.mu.Unlock() +} +func (es *endpointSharding) allowUpdatesFromChildren() { es.mu.Lock() - defer es.mu.Unlock() + es.inhibitChildUpdates = false + es.updateStateLocked() + es.mu.Unlock() +} - children := es.children.Load() - childStates := make([]ChildState, 0, children.Len()) +// updateStateLocked updates this component's state. It sends the aggregated +// state, and a picker with round robin behavior with all the child states +// present if needed. This method must only be called when inhibitChildUpdates +// is false. +// +// Caller must hold es.mu. +func (es *endpointSharding) updateStateLocked() { + var readyPickers, connectingPickers, idlePickers, transientFailurePickers []balancer.Picker - for _, child := range children.All() { - childState := child.childState + childStates := make([]ChildState, 0, es.endpoints.Len()) + for _, epState := range es.endpoints.All() { + childState := ChildState{ + Endpoint: epState.endpoint, + State: epState.state, + ExitIdle: func() { go epState.exitIdle() }, + } childStates = append(childStates, childState) childPicker := childState.State.Picker switch childState.State.ConnectivityState { @@ -292,14 +291,14 @@ func (es *endpointSharding) updateState() { aggState = connectivity.TransientFailure pickers = []balancer.Picker{base.NewErrPicker(errors.New("no children to pick from"))} } // No children (resolver error before valid update). - p := &pickerWithChildStates{ - pickers: pickers, - childStates: childStates, - next: uint32(randIntN(len(pickers))), - } + es.cc.UpdateState(balancer.State{ ConnectivityState: aggState, - Picker: p, + Picker: &pickerWithChildStates{ + pickers: pickers, + childStates: childStates, + next: uint32(randIntN(len(pickers))), + }, }) } @@ -328,61 +327,59 @@ func ChildStatesFromPicker(picker balancer.Picker) []ChildState { return p.childStates } -// balancerWrapper is a wrapper of a balancer. It ID's a child balancer by -// endpoint, and persists recent child balancer state. -type balancerWrapper struct { - // The following fields are initialized at build time and read-only after - // that and therefore do not need to be guarded by a mutex. - - // child contains the wrapped balancer. Access its methods only through - // methods on balancerWrapper to ensure proper synchronization - child balancer.Balancer - balancer.ClientConn // embed to intercept UpdateState, doesn't deal with SubConns +// endpointState is the internal state maintained for each endpoint. +type endpointState struct { + balancer.ClientConn // Embedded to intercept UpdateState - es *endpointSharding + parent *endpointSharding // Parent endpointsharding balancer. + endpoint resolver.Endpoint // Endpoint of the child balancer. + state balancer.State // State of the child balancer. + disableAutoReconnect bool // Whether to disable auto reconnect for this child. - // Access to the following fields is guarded by es.mu. - - childState ChildState - isClosed bool + childMu sync.Mutex // Guarantees mutual exclusion for Balancer API calls to the child balancer. + childLB balancer.Balancer // Child balancer. + closed bool // Tracks closure of the child balancer to ensure ExitIdle is not called after Close(). } -func (bw *balancerWrapper) UpdateState(state balancer.State) { - bw.es.mu.Lock() - bw.childState.State = state - bw.es.mu.Unlock() - if state.ConnectivityState == connectivity.Idle && !bw.es.esOpts.DisableAutoReconnect { - bw.ExitIdle() +func (es *endpointState) UpdateState(state balancer.State) { + es.parent.mu.Lock() + es.state = state + if !es.parent.inhibitChildUpdates { + es.parent.updateStateLocked() + } + es.parent.mu.Unlock() + + if state.ConnectivityState == connectivity.Idle && !es.disableAutoReconnect { + go es.exitIdle() } - bw.es.updateState() } -// ExitIdle pings an IDLE child balancer to exit idle in a new goroutine to -// avoid deadlocks due to synchronous balancer state updates. -func (bw *balancerWrapper) ExitIdle() { - go func() { - bw.es.childMu.Lock() - if !bw.isClosed { - bw.child.ExitIdle() - } - bw.es.childMu.Unlock() - }() +func (es *endpointState) updateClientConnState(state balancer.ClientConnState) error { + es.childMu.Lock() + err := es.childLB.UpdateClientConnState(state) + es.childMu.Unlock() + return err } -// updateClientConnStateLocked delivers the ClientConnState to the child -// balancer. Callers must hold the child mutex of the parent endpointsharding -// balancer. -func (bw *balancerWrapper) updateClientConnStateLocked(ccs balancer.ClientConnState) error { - return bw.child.UpdateClientConnState(ccs) +func (es *endpointState) resolverError(err error) { + es.childMu.Lock() + es.childLB.ResolverError(err) + es.childMu.Unlock() } -// closeLocked closes the child balancer. Callers must hold the child mutext of -// the parent endpointsharding balancer. -func (bw *balancerWrapper) closeLocked() { - bw.child.Close() - bw.isClosed = true +func (es *endpointState) close() { + es.childMu.Lock() + if !es.closed { + es.closed = true + es.childLB.Close() + } + es.childMu.Unlock() } -func (bw *balancerWrapper) resolverErrorLocked(err error) { - bw.child.ResolverError(err) +func (es *endpointState) exitIdle() { + es.childMu.Lock() + if !es.closed { + es.childLB.ExitIdle() + } + es.childMu.Unlock() } diff --git a/vendor/google.golang.org/grpc/balancer/pickfirst/pickfirst.go b/vendor/google.golang.org/grpc/balancer/pickfirst/pickfirst.go index d48bc304c..ddd08f537 100644 --- a/vendor/google.golang.org/grpc/balancer/pickfirst/pickfirst.go +++ b/vendor/google.golang.org/grpc/balancer/pickfirst/pickfirst.go @@ -36,7 +36,6 @@ import ( "google.golang.org/grpc/balancer/pickfirst/internal" "google.golang.org/grpc/connectivity" "google.golang.org/grpc/experimental/balancer/weight" - expstats "google.golang.org/grpc/experimental/stats" "google.golang.org/grpc/grpclog" "google.golang.org/grpc/internal/envconfig" internalgrpclog "google.golang.org/grpc/internal/grpclog" @@ -56,30 +55,7 @@ const Name = "pick_first" // attributes to indicate whether the health listener usage is enabled. type enableHealthListenerKeyType struct{} -var ( - logger = grpclog.Component("pick-first-leaf-lb") - disconnectionsMetric = expstats.RegisterInt64Count(expstats.MetricDescriptor{ - Name: "grpc.lb.pick_first.disconnections", - Description: "EXPERIMENTAL. Number of times the selected subchannel becomes disconnected.", - Unit: "{disconnection}", - Labels: []string{"grpc.target"}, - Default: false, - }) - connectionAttemptsSucceededMetric = expstats.RegisterInt64Count(expstats.MetricDescriptor{ - Name: "grpc.lb.pick_first.connection_attempts_succeeded", - Description: "EXPERIMENTAL. Number of successful connection attempts.", - Unit: "{attempt}", - Labels: []string{"grpc.target"}, - Default: false, - }) - connectionAttemptsFailedMetric = expstats.RegisterInt64Count(expstats.MetricDescriptor{ - Name: "grpc.lb.pick_first.connection_attempts_failed", - Description: "EXPERIMENTAL. Number of failed connection attempts.", - Unit: "{attempt}", - Labels: []string{"grpc.target"}, - Default: false, - }) -) +var logger = grpclog.Component("pick-first-leaf-lb") const ( // TODO: change to pick-first when this becomes the default pick_first policy. @@ -101,11 +77,9 @@ const ( type pickfirstBuilder struct{} -func (pickfirstBuilder) Build(cc balancer.ClientConn, bo balancer.BuildOptions) balancer.Balancer { +func (pickfirstBuilder) Build(cc balancer.ClientConn, _ balancer.BuildOptions) balancer.Balancer { b := &pickfirstBalancer{ - cc: cc, - target: bo.Target.String(), - metricsRecorder: cc.MetricsRecorder(), + cc: cc, subConns: resolver.NewAddressMapV2[*scData](), state: connectivity.Connecting, @@ -185,10 +159,8 @@ func (b *pickfirstBalancer) newSCData(addr resolver.Address) (*scData, error) { type pickfirstBalancer struct { // The following fields are initialized at build time and read-only after // that and therefore do not need to be guarded by a mutex. - logger *internalgrpclog.PrefixLogger - cc balancer.ClientConn - target string - metricsRecorder expstats.MetricsRecorder // guaranteed to be non nil + logger *internalgrpclog.PrefixLogger + cc balancer.ClientConn // The mutex is used to ensure synchronization of updates triggered // from the idle picker and the already serialized resolver, @@ -633,14 +605,11 @@ func (b *pickfirstBalancer) updateSubConnState(sd *scData, newState balancer.Sub return } - // Record a connection attempt when exiting CONNECTING. if newState.ConnectivityState == connectivity.TransientFailure { sd.connectionFailedInFirstPass = true - connectionAttemptsFailedMetric.Record(b.metricsRecorder, 1, b.target) } if newState.ConnectivityState == connectivity.Ready { - connectionAttemptsSucceededMetric.Record(b.metricsRecorder, 1, b.target) b.shutdownRemainingLocked(sd) if !b.addressList.seekTo(sd.addr) { // This should not fail as we should have only one SubConn after @@ -689,15 +658,6 @@ func (b *pickfirstBalancer) updateSubConnState(sd *scData, newState balancer.Sub // the first address when the picker is used. b.shutdownRemainingLocked(sd) sd.effectiveState = newState.ConnectivityState - // READY SubConn interspliced in between CONNECTING and IDLE, need to - // account for that. - if oldState == connectivity.Connecting { - // A known issue (https://github.com/grpc/grpc-go/issues/7862) - // causes a race that prevents the READY state change notification. - // This works around it. - connectionAttemptsSucceededMetric.Record(b.metricsRecorder, 1, b.target) - } - disconnectionsMetric.Record(b.metricsRecorder, 1, b.target) b.addressList.reset() b.updateBalancerState(balancer.State{ ConnectivityState: connectivity.Idle, diff --git a/vendor/google.golang.org/grpc/binarylog/grpc_binarylog_v1/binarylog.pb.go b/vendor/google.golang.org/grpc/binarylog/grpc_binarylog_v1/binarylog.pb.go index 296123e20..6c249fdaf 100644 --- a/vendor/google.golang.org/grpc/binarylog/grpc_binarylog_v1/binarylog.pb.go +++ b/vendor/google.golang.org/grpc/binarylog/grpc_binarylog_v1/binarylog.pb.go @@ -679,7 +679,7 @@ func (x *Message) GetData() []byte { // A list of metadata pairs, used in the payload of client header, // server header, and server trailer. // Implementations may omit some entries to honor the header limits -// of GRPC_BINARY_LOG_CONFIG. +// of GRPC_BINARY_LOG_FILTER. // // Header keys added by gRPC are omitted. To be more specific, // implementations will not log the following entries, and this is @@ -689,7 +689,9 @@ func (x *Message) GetData() []byte { // or keys like 'lb-token' // - transport specific entries, including but not limited to: // ':path', ':authority', 'content-encoding', 'user-agent', 'te', etc -// - entries added for call credentials +// - entries added for call credentials (on client side, excludes all +// such headers; on server side, excludes only the "authorization" +// header) // // Implementations must always log grpc-trace-bin if it is present. // Practically speaking it will only be visible on server side because diff --git a/vendor/google.golang.org/grpc/call.go b/vendor/google.golang.org/grpc/call.go index 788c89c16..2079bf4ed 100644 --- a/vendor/google.golang.org/grpc/call.go +++ b/vendor/google.golang.org/grpc/call.go @@ -20,6 +20,10 @@ package grpc import ( "context" + "io" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" ) // Invoke sends the RPC request on the wire and returns after response is @@ -67,8 +71,27 @@ func invoke(ctx context.Context, method string, req, reply any, cc *ClientConn, if err != nil { return err } - if err := cs.SendMsg(req); err != nil { + // In case of nil or io.EOF error, call RecvMsg. + if err := cs.SendMsg(req); err != nil && err != io.EOF { + return err + } + // CloseSend is needed because in some scenarios (e.g., xDS), the same + // interceptors are used to process both unary and streaming RPCs. Calling + // CloseSend signals to those interceptors that no more messages are on the + // way. + if err := cs.CloseSend(); err != nil && err != io.EOF { return err } - return cs.RecvMsg(reply) + if err := cs.RecvMsg(reply); err != nil { + return err + } + // Call RecvMsg again to get the trailers. + err = cs.RecvMsg(reply) + if err == io.EOF { + return nil + } + if err == nil { + return status.Error(codes.Internal, "cardinality violation: expected for non server-streaming RPCs, but received another message") + } + return err } diff --git a/vendor/google.golang.org/grpc/clientconn.go b/vendor/google.golang.org/grpc/clientconn.go index b27c7e84a..f5ce07197 100644 --- a/vendor/google.golang.org/grpc/clientconn.go +++ b/vendor/google.golang.org/grpc/clientconn.go @@ -553,6 +553,7 @@ func chainStreamClientInterceptors(cc *ClientConn) { if cc.dopts.streamInt != nil { interceptors = append([]StreamClientInterceptor{cc.dopts.streamInt}, interceptors...) } + interceptors = append(interceptors, defaultStreamInterceptor) var chainedInt StreamClientInterceptor if len(interceptors) == 0 { chainedInt = nil diff --git a/vendor/google.golang.org/grpc/internal/buffer/unbounded.go b/vendor/google.golang.org/grpc/internal/buffer/unbounded.go index 467392b8d..d1f4b634b 100644 --- a/vendor/google.golang.org/grpc/internal/buffer/unbounded.go +++ b/vendor/google.golang.org/grpc/internal/buffer/unbounded.go @@ -27,32 +27,29 @@ import ( // extra goroutines. This is typically used for passing updates from one entity // to another within gRPC. // +// To avoid extra memory allocations and type assertions, using any on +// performance-critical code paths is discouraged. Use concrete types wherever +// possible when instantiating Unbounded. +// // All methods on this type are thread-safe and don't block on anything except // the underlying mutex used for synchronization. -// -// Unbounded supports values of any type to be stored in it by using a channel -// of `any`. This means that a call to Put() incurs an extra memory allocation, -// and also that users need a type assertion while reading. For performance -// critical code paths, using Unbounded is strongly discouraged and defining a -// new type specific implementation of this buffer is preferred. See -// internal/transport/transport.go for an example of this. -type Unbounded struct { - c chan any +type Unbounded[T any] struct { + c chan T closed bool closing bool mu sync.Mutex - backlog []any + backlog []T } // NewUnbounded returns a new instance of Unbounded. -func NewUnbounded() *Unbounded { - return &Unbounded{c: make(chan any, 1)} +func NewUnbounded[T any]() *Unbounded[T] { + return &Unbounded[T]{c: make(chan T, 1)} } var errBufferClosed = errors.New("Put called on closed buffer.Unbounded") // Put adds t to the unbounded buffer. -func (b *Unbounded) Put(t any) error { +func (b *Unbounded[T]) Put(t T) error { b.mu.Lock() defer b.mu.Unlock() if b.closing { @@ -72,13 +69,14 @@ func (b *Unbounded) Put(t any) error { // Load sends the earliest buffered data, if any, onto the read channel returned // by Get(). Users are expected to call this every time they successfully read a // value from the read channel. -func (b *Unbounded) Load() { +func (b *Unbounded[T]) Load() { b.mu.Lock() defer b.mu.Unlock() if len(b.backlog) > 0 { select { case b.c <- b.backlog[0]: - b.backlog[0] = nil + var zero T + b.backlog[0] = zero b.backlog = b.backlog[1:] default: } @@ -96,14 +94,14 @@ func (b *Unbounded) Load() { // // If the unbounded buffer is closed, the read channel returned by this method // is closed after all data is drained. -func (b *Unbounded) Get() <-chan any { +func (b *Unbounded[T]) Get() <-chan T { return b.c } // Close closes the unbounded buffer. No subsequent data may be Put(), and the // channel returned from Get() will be closed after all the data is read and // Load() is called for the final time. -func (b *Unbounded) Close() { +func (b *Unbounded[T]) Close() { b.mu.Lock() defer b.mu.Unlock() if b.closing { diff --git a/vendor/google.golang.org/grpc/internal/envconfig/envconfig.go b/vendor/google.golang.org/grpc/internal/envconfig/envconfig.go index 333448127..dc6fc0c4c 100644 --- a/vendor/google.golang.org/grpc/internal/envconfig/envconfig.go +++ b/vendor/google.golang.org/grpc/internal/envconfig/envconfig.go @@ -153,6 +153,13 @@ var ( // TODO: Remove this env var once v1.83.0 is released. ControlBufferThrottleLimit = uint64FromEnv("GRPC_GO_EXPERIMENTAL_CONTROL_BUFFER_THROTTLE_LIMIT", 100, 1, 10000) + // ALTSMaxFrameSize is the maximum frame size for ALTS in bytes. + // This can be overridden by setting the environment variable + // "GRPC_GO_EXPERIMENTAL_ALTS_MAX_FRAME_SIZE" (min: 4096, max: 512*1024, capped at + // 512KiB to match altsWriteBufferMaxSize in + // credentials/alts/internal/conn/record.go). + ALTSMaxFrameSize = uint64FromEnv("GRPC_GO_EXPERIMENTAL_ALTS_MAX_FRAME_SIZE", 4096, 4096, 512*1024) + // EnableReceiveBufferCompaction enables the compaction of data buffers // to reduce the number of buffers in the receive buffer. // diff --git a/vendor/google.golang.org/grpc/internal/envconfig/xds.go b/vendor/google.golang.org/grpc/internal/envconfig/xds.go index e4b691913..5ec39bd75 100644 --- a/vendor/google.golang.org/grpc/internal/envconfig/xds.go +++ b/vendor/google.golang.org/grpc/internal/envconfig/xds.go @@ -98,4 +98,9 @@ var ( // filter. For more details, see: // https://github.com/grpc/proposal/blob/master/A83-xds-gcp-authn-filter.md GCPAuthenticationFilterEnabled = boolFromEnv("GRPC_EXPERIMENTAL_XDS_GCP_AUTHENTICATION_FILTER", false) + + // XDSClientExtAuthzEnabled indicates whether the external authorization + // filter is enabled on the client side. For more details, see: + // https://github.com/grpc/proposal/blob/master/A92-xds-ext-authz.md + XDSClientExtAuthzEnabled = boolFromEnv("GRPC_EXPERIMENTAL_XDS_EXT_AUTHZ_ON_CLIENT", false) ) diff --git a/vendor/google.golang.org/grpc/internal/grpcsync/callback_serializer.go b/vendor/google.golang.org/grpc/internal/grpcsync/callback_serializer.go index d4999fcca..caa9dd68e 100644 --- a/vendor/google.golang.org/grpc/internal/grpcsync/callback_serializer.go +++ b/vendor/google.golang.org/grpc/internal/grpcsync/callback_serializer.go @@ -41,7 +41,7 @@ type CallbackSerializer struct { // its resources. done chan struct{} - callbacks *buffer.Unbounded + callbacks *buffer.Unbounded[func(context.Context)] } // NewCallbackSerializer returns a new CallbackSerializer instance. The provided @@ -52,7 +52,7 @@ type CallbackSerializer struct { func NewCallbackSerializer(ctx context.Context) *CallbackSerializer { cs := &CallbackSerializer{ done: make(chan struct{}), - callbacks: buffer.NewUnbounded(), + callbacks: buffer.NewUnbounded[func(context.Context)](), } go cs.run(ctx) return cs @@ -113,7 +113,7 @@ func (cs *CallbackSerializer) run(ctx context.Context) { // Run all callbacks. for cb := range cs.callbacks.Get() { cs.callbacks.Load() - cb.(func(context.Context))(ctx) + cb(ctx) } } diff --git a/vendor/google.golang.org/grpc/internal/grpcsync/refcounted.go b/vendor/google.golang.org/grpc/internal/grpcsync/refcounted.go new file mode 100644 index 000000000..bca9b8375 --- /dev/null +++ b/vendor/google.golang.org/grpc/internal/grpcsync/refcounted.go @@ -0,0 +1,109 @@ +/* + * + * Copyright 2026 gRPC 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. + * + */ + +package grpcsync + +import ( + "sync/atomic" + + "google.golang.org/grpc/grpclog" +) + +var logger = grpclog.Component("grpcsync") + +// RefCounted is a reference counted wrapper of type T. It tracks the number of +// active references and runs a cleanup when the last reference is released. +type RefCounted[T any] struct { + val T + refCount atomic.Int32 + onZero func() +} + +// NewRefCounted creates a new RefCounted instance wrapping the given value with +// initial refcount of one. +// +// The value should typically be a pointer, interface, or handle rather than a +// plain value type (such as a struct or primitive value). +// +// The provided onZero callback must not be nil, and is executed exactly once +// when the reference count drops to zero. Panics if onZero is nil. +// +// WARNING: onZero runs synchronously inside Decrement; it must not acquire +// locks held by Decrement callers. +func NewRefCounted[T any](val T, onZero func()) *RefCounted[T] { + if onZero == nil { + panic("grpcsync: onZero callback cannot be nil") + } + rc := &RefCounted[T]{ + val: val, + onZero: onZero, + } + rc.refCount.Store(1) + return rc +} + +// Value returns the encapsulated resource. +func (rc *RefCounted[T]) Value() T { + return rc.val +} + +// TryIncrement attempts to increment the reference count, returning true if +// successful. It returns false if the count has already reached 0, indicating +// the resource has been cleaned up and cannot be resurrected. +// +// WARNING: Avoid calling TryIncrement on hot paths when an active reference is +// already guaranteed by the caller; use Increment instead to bypass the +// CompareAndSwap loop overhead. TryIncrement should be reserved for speculative +// lookups (such as fetching from a cache or map) where the resource might be +// dead. +func (rc *RefCounted[T]) TryIncrement() bool { + // Utilize a CompareAndSwap loop to prevent race conditions where a concurrent + // decrement could drop the count to zero between the read and the increment + // operation, which would otherwise inadvertently resurrect a closed resource. + for { + count := rc.refCount.Load() + if count <= 0 { + return false // Already dead or dying + } + if rc.refCount.CompareAndSwap(count, count+1) { + return true + } + } +} + +// Increment increments the reference count. +// +// WARNING: Call Increment only when there is a guarantee that an active +// reference is already present, ensuring the resource is not dead. If there is +// a possibility that the resource is dead or its reference count might have +// reached zero, call TryIncrement instead. +func (rc *RefCounted[T]) Increment() { + if rc.refCount.Add(1) <= 1 { + logger.Errorf("Resource already closed or dead") + } +} + +// Decrement decrements the reference count. If it drops to zero, the onZero +// callback is executed synchronously before this method returns. +func (rc *RefCounted[T]) Decrement() { + if v := rc.refCount.Add(-1); v < 0 { + logger.Errorf("Refcount cannot be negative") + } else if v == 0 { + rc.onZero() + } +} diff --git a/vendor/google.golang.org/grpc/internal/internal.go b/vendor/google.golang.org/grpc/internal/internal.go index 4b3d563f8..2b7fa6b08 100644 --- a/vendor/google.golang.org/grpc/internal/internal.go +++ b/vendor/google.golang.org/grpc/internal/internal.go @@ -245,6 +245,10 @@ var ( AsyncReporterCleanupDelegate = func(cleanup func()) func() { return cleanup } + + // XDSFilterWrapperOption returns a ServerOption that sets the internal + // stream wrapper used for server-side xDS HTTP filters. + XDSFilterWrapperOption any // func(func(grpc.ServerStream) (grpc.ServerStream, error)) grpc.ServerOption ) // HealthChecker defines the signature of the client-side LB channel health diff --git a/vendor/google.golang.org/grpc/internal/resolver/config_selector.go b/vendor/google.golang.org/grpc/internal/resolver/config_selector.go index 238950bbb..ead6dda4e 100644 --- a/vendor/google.golang.org/grpc/internal/resolver/config_selector.go +++ b/vendor/google.golang.org/grpc/internal/resolver/config_selector.go @@ -42,6 +42,10 @@ type RPCInfo struct { // efficiency reasons. SelectConfig should not be blocking. Context context.Context Method string // i.e. "/Service/Method" + // Authority is the target authority (host) name of the RPC. This is required + // for HTTP filters (such as external processing) to populate request + // attributes. + Authority string } // RPCConfig describes the configuration to use for each RPC. @@ -54,17 +58,6 @@ type RPCConfig struct { Interceptor any } -// ServerInterceptor is an interceptor for incoming RPC's on gRPC server side. -type ServerInterceptor interface { - // AllowRPC checks if an incoming RPC is allowed to proceed based on - // information about connection RPC was received on, and HTTP Headers. This - // information will be piped into context. - AllowRPC(ctx context.Context) error // TODO: Make this a real interceptor for filters such as rate limiting. - // Close closes the interceptor. Once called, no new calls to NewStream are - // accepted. Ongoing calls to NewStream are allowed to complete. - Close() -} - type csKeyType string const csKey = csKeyType("grpc.internal.resolver.configSelector") diff --git a/vendor/google.golang.org/grpc/internal/transport/controlbuf.go b/vendor/google.golang.org/grpc/internal/transport/controlbuf.go index b9bae0249..89c938fdb 100644 --- a/vendor/google.golang.org/grpc/internal/transport/controlbuf.go +++ b/vendor/google.golang.org/grpc/internal/transport/controlbuf.go @@ -219,6 +219,17 @@ type outFlowControlSizeRequest struct { resp chan uint32 } +// outStreamRequestForTesting is used by tests to retrieve a pointer to an outStream +// safely inside the loopyWriter goroutine without racing on loopyWriter.estdStreams. +// By holding the *outStream pointer while streams and transports close down, tests +// can inspect settled accounting values (such as bytesOutStanding) after loopyWriter +// has run to completion without any data races. +type outStreamRequestForTesting struct { + throttledItem + streamID uint32 + resp chan *outStream +} + // closeConnection is an instruction to tell the loopy writer to flush the // framer and exit, which will cause the transport's connection to be closed // (by the client or server). The transport itself will close after the reader @@ -799,6 +810,10 @@ func (l *loopyWriter) outFlowControlSizeRequestHandler(o *outFlowControlSizeRequ o.resp <- l.sendQuota } +func (l *loopyWriter) outStreamRequestHandler(o *outStreamRequestForTesting) { + o.resp <- l.estdStreams[o.streamID] +} + func (l *loopyWriter) cleanupStreamHandler(c *cleanupStream) error { c.onWrite() if str, ok := l.estdStreams[c.streamID]; ok { @@ -896,6 +911,8 @@ func (l *loopyWriter) handle(i any) error { return l.goAwayHandler(i) case *outFlowControlSizeRequest: l.outFlowControlSizeRequestHandler(i) + case *outStreamRequestForTesting: + l.outStreamRequestHandler(i) case closeConnection: // Just return a non-I/O error and run() will flush and close the // connection. diff --git a/vendor/google.golang.org/grpc/internal/transport/http2_client.go b/vendor/google.golang.org/grpc/internal/transport/http2_client.go index 10d197741..720fc4e5b 100644 --- a/vendor/google.golang.org/grpc/internal/transport/http2_client.go +++ b/vendor/google.golang.org/grpc/internal/transport/http2_client.go @@ -554,8 +554,6 @@ func (t *http2Client) createHeaderFields(ctx context.Context, callHdr *CallHdr) if err != nil { return nil, err } - // TODO(mmukhi): Benchmark if the performance gets better if count the metadata and other header fields - // first and create a slice of that exact size. // Make the slice of certain predictable size to reduce allocations made by append. hfLen := 7 // :method, :scheme, :path, :authority, content-type, user-agent, te hfLen += len(authData) + len(callAuthData) @@ -575,6 +573,21 @@ func (t *http2Client) createHeaderFields(ctx context.Context, callHdr *CallHdr) if _, ok := ctx.Deadline(); ok { hfLen++ } + // Count the metadata header fields as well so the slice is not reallocated + // while they are appended below. Reserved headers are dropped when writing, + // so this may slightly over-count, which is preferable to growing the slice. + md, added, mdOK := metadataFromOutgoingContextRaw(ctx) + if mdOK { + for _, vv := range md { + hfLen += len(vv) + } + for _, vv := range added { + hfLen += len(vv) / 2 + } + } + for _, vv := range t.md { + hfLen += len(vv) + } headerFields := make([]hpack.HeaderField, 0, hfLen) headerFields = append(headerFields, hpack.HeaderField{Name: ":method", Value: "POST"}) headerFields = append(headerFields, hpack.HeaderField{Name: ":scheme", Value: t.scheme}) @@ -619,7 +632,7 @@ func (t *http2Client) createHeaderFields(ctx context.Context, callHdr *CallHdr) headerFields = append(headerFields, hpack.HeaderField{Name: k, Value: encodeMetadataHeader(k, v)}) } - if md, added, ok := metadataFromOutgoingContextRaw(ctx); ok { + if mdOK { var k string for k, vv := range md { // HTTP doesn't allow you to set pseudoheaders after non pseudoheaders were set. @@ -648,6 +661,9 @@ func (t *http2Client) createHeaderFields(ctx context.Context, callHdr *CallHdr) if isReservedHeader(k) { continue } + if err := imetadata.ValidatePair(k, vv...); err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } for _, v := range vv { headerFields = append(headerFields, hpack.HeaderField{Name: k, Value: encodeMetadataHeader(k, v)}) } @@ -691,6 +707,9 @@ func (t *http2Client) getTrAuthData(ctx context.Context, audience string) (map[s for k, v := range data { // Capital header names are illegal in HTTP/2. k = strings.ToLower(k) + if err := imetadata.ValidatePair(k, v); err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } authData[k] = v } } @@ -724,6 +743,9 @@ func (t *http2Client) getCallAuthData(ctx context.Context, audience string, call for k, v := range data { // Capital header names are illegal in HTTP/2 k = strings.ToLower(k) + if err := imetadata.ValidatePair(k, v); err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } callAuthData[k] = v } } @@ -1226,23 +1248,26 @@ func (t *http2Client) handleData(f *parsedDataFrame) { t.closeStream(s, io.EOF, true, http2.ErrCodeFlowControl, status.New(codes.Internal, err.Error()), nil, false) return } + } - if s.nonGRPCStatus != nil { - // The frame should be handled as a non-gRPC response body - st := s.handleNonGRPCData(f) - if st != nil { - t.closeStream(s, st.Err(), true, http2.ErrCodeProtocol, st, nil, true) - return - } - if w := s.fc.onRead(size); w > 0 { - t.controlBuf.put(&outgoingWindowUpdate{ - streamID: s.id, - increment: w, - }) - } + if s.nonGRPCStatus != nil { + // The frame should be handled as a non-gRPC response body. A non-nil + // status also covers END_STREAM, so no separate handling is needed below. + st := s.handleNonGRPCData(f) + if st != nil { + t.closeStream(s, st.Err(), true, http2.ErrCodeProtocol, st, nil, true) return } + if w := s.fc.onRead(size); w > 0 { + t.controlBuf.put(&outgoingWindowUpdate{ + streamID: s.id, + increment: w, + }) + } + return + } + if size > 0 { dataLen := f.data.Len() if f.Header().Flags.Has(http2.FlagDataPadded) { if w := s.fc.onRead(size - uint32(dataLen)); w > 0 { diff --git a/vendor/google.golang.org/grpc/internal/transport/http2_server.go b/vendor/google.golang.org/grpc/internal/transport/http2_server.go index 82e13e64a..f11e88cc5 100644 --- a/vendor/google.golang.org/grpc/internal/transport/http2_server.go +++ b/vendor/google.golang.org/grpc/internal/transport/http2_server.go @@ -531,6 +531,7 @@ func (t *http2Server) operateHeaders(ctx context.Context, frame *http2.MetaHeade if frame.StreamEnded() { // s is just created by the caller. No lock needed. s.state = streamReadDone + s.write(recvMsg{err: io.EOF}) } if timeoutSet { s.ctx, s.cancel = context.WithTimeout(ctx, timeout) diff --git a/vendor/google.golang.org/grpc/internal/transport/http_util.go b/vendor/google.golang.org/grpc/internal/transport/http_util.go index c34975ffe..faa42f8ca 100644 --- a/vendor/google.golang.org/grpc/internal/transport/http_util.go +++ b/vendor/google.golang.org/grpc/internal/transport/http_util.go @@ -300,24 +300,29 @@ func decodeGrpcMessageUnchecked(msg string) string { type bufWriter struct { pool *imem.SimpleBufferPool - buf []byte + bufHandle *[]byte offset int batchSize int conn io.Writer err error } +// unsharedBufWriter keeps the unshared slice header in the writer allocation. +type unsharedBufWriter struct { + bufWriter + buf []byte +} + func newBufWriter(conn io.Writer, batchSize int, pool *imem.SimpleBufferPool) *bufWriter { - w := &bufWriter{ - batchSize: batchSize, - conn: conn, - pool: pool, - } - // this indicates that we should use non shared buf - if pool == nil { - w.buf = make([]byte, batchSize) + if pool == nil && batchSize > 0 { + w := &unsharedBufWriter{ + bufWriter: bufWriter{batchSize: batchSize, conn: conn}, + buf: make([]byte, batchSize), + } + w.bufHandle = &w.buf + return &w.bufWriter } - return w + return &bufWriter{batchSize: batchSize, conn: conn, pool: pool} } func (w *bufWriter) Write(b []byte) (int, error) { @@ -328,13 +333,13 @@ func (w *bufWriter) Write(b []byte) (int, error) { n, err := w.conn.Write(b) return n, toIOError(err) } - if w.buf == nil { - b := w.pool.Get(w.batchSize) - w.buf = *b + if w.bufHandle == nil { + w.bufHandle = w.pool.Get(w.batchSize) } + buf := *w.bufHandle written := 0 for len(b) > 0 { - copied := copy(w.buf[w.offset:], b) + copied := copy(buf[w.offset:], b) b = b[copied:] written += copied w.offset += copied @@ -350,15 +355,17 @@ func (w *bufWriter) Write(b []byte) (int, error) { func (w *bufWriter) Flush() error { err := w.flushKeepBuffer() - // Only release the buffer if we are in a "shared" mode - if w.buf != nil && w.pool != nil { - b := w.buf - w.pool.Put(&b) - w.buf = nil - } + w.releaseBuffer() return err } +func (w *bufWriter) releaseBuffer() { + if w.pool != nil && w.bufHandle != nil { + w.pool.Put(w.bufHandle) + w.bufHandle = nil + } +} + func (w *bufWriter) flushKeepBuffer() error { if w.err != nil { return w.err @@ -366,9 +373,13 @@ func (w *bufWriter) flushKeepBuffer() error { if w.offset == 0 { return nil } - _, w.err = w.conn.Write(w.buf[:w.offset]) + buf := *w.bufHandle + _, w.err = w.conn.Write(buf[:w.offset]) w.err = toIOError(w.err) w.offset = 0 + if w.err != nil { + w.releaseBuffer() + } return w.err } diff --git a/vendor/google.golang.org/grpc/internal/transport/transport.go b/vendor/google.golang.org/grpc/internal/transport/transport.go index 5fc901e5c..fc656b36c 100644 --- a/vendor/google.golang.org/grpc/internal/transport/transport.go +++ b/vendor/google.golang.org/grpc/internal/transport/transport.go @@ -89,10 +89,10 @@ type recvMsg struct { // recvBuffer is an unbounded channel of recvMsg structs. // -// Note: recvBuffer differs from buffer.Unbounded only in the fact that it -// holds a channel of recvMsg structs instead of objects implementing "item" -// interface. recvBuffer is written to much more often and using strict recvMsg -// structs helps avoid allocation in "recvBuffer.put" +// Note: recvBuffer differs from buffer.Unbounded in that it provides in-place +// value initialization (via init) to avoid struct pointer allocations on +// streams, and automatically frees pooled mem.Buffer payloads when stream +// errors occur. type recvBuffer struct { c chan recvMsg mu sync.Mutex @@ -466,15 +466,18 @@ func (s *Stream) ReadMessageHeader(header []byte) (err error) { return er } s.readRequester.requestRead(len(header)) + bytesRead := 0 for len(header) != 0 { n, err := s.trReader.ReadMessageHeader(header) + bytesRead += n header = header[n:] if len(header) == 0 { err = nil } if err != nil { - if n > 0 && err == io.EOF { + if bytesRead > 0 && err == io.EOF { err = io.ErrUnexpectedEOF + s.trReader.er = err } return err } @@ -505,19 +508,22 @@ func (s *Stream) read(n int) (data mem.BufferSlice, err error) { allocCap := min(ceil(n, http2MaxFrameLen), 128) data = make(mem.BufferSlice, 0, allocCap) s.readRequester.requestRead(n) + bytesRead := 0 for n != 0 { buf, err := s.trReader.Read(n) var bufLen int if buf != nil { bufLen = buf.Len() } + bytesRead += bufLen n -= bufLen if n == 0 { err = nil } if err != nil { - if bufLen > 0 && err == io.EOF { + if bytesRead > 0 && err == io.EOF { err = io.ErrUnexpectedEOF + s.trReader.er = err } data.Free() return nil, err diff --git a/vendor/google.golang.org/grpc/metadata/metadata.go b/vendor/google.golang.org/grpc/metadata/metadata.go index d2e15253b..2b79204b4 100644 --- a/vendor/google.golang.org/grpc/metadata/metadata.go +++ b/vendor/google.golang.org/grpc/metadata/metadata.go @@ -24,6 +24,7 @@ package metadata // import "google.golang.org/grpc/metadata" import ( "context" "fmt" + "sort" "strings" "google.golang.org/grpc/internal" @@ -90,6 +91,76 @@ func Pairs(kv ...string) MD { return md } +// loggableMetadataKeys is the set of metadata keys whose values are known not +// to carry credentials or other sensitive data, and are therefore safe to print +// verbatim in String. Values for any key not in this set are redacted. Keys are +// in metadata's canonical lowercase form. +// +// The list is intentionally restricted to standardized gRPC and HTTP/2 protocol +// headers. Everything else, including all application-defined keys, is +// censored. +// Note that this list might change as we add/remove support for +// metadata types. +var loggableMetadataKeys = map[string]bool{ + "content-type": true, + "te": true, + "user-agent": true, + "grpc-encoding": true, + "grpc-accept-encoding": true, + "grpc-timeout": true, + "grpc-status": true, + "grpc-message-type": true, + "grpc-previous-rpc-attempts": true, + "grpc-retry-pushback-ms": true, +} + +// String implements fmt.Stringer to allow metadata to be printed when stored in +// a context. +// +// To avoid accidentally leaking credentials or other sensitive data (for +// example via log(md), or by logging a value that happens to contain metadata), +// String reports only keys on an allowlist of standardized, non-sensitive +// protocol headers (see loggableMetadataKeys). Every other key is omitted +// entirely, along with its values, because a key name may itself be sensitive; +// only the number of omitted keys is reported, as "". This is a +// best-effort guard against accidents, not a security boundary: a caller that +// genuinely wants the full contents can still print map[string][]string(md) +// directly. +// +// Note that this only affects verbs that use the Stringer, such as %v and %s. +// The %#v verb prints the underlying map with all values and is not redacted. +// Users should not rely on the output of this method to be stable +// # Experimental +// +// Notice: This API is EXPERIMENTAL and may be changed or removed in a later +// release. +func (md MD) String() string { + keys := make([]string, 0, len(md)) + for k := range md { + if loggableMetadataKeys[strings.ToLower(k)] { + keys = append(keys, k) + } + } + sort.Strings(keys) + + var sb strings.Builder + sb.WriteString("map[") + for i, k := range keys { + if i > 0 { + sb.WriteByte(' ') + } + fmt.Fprintf(&sb, "%s:%v", k, md[k]) + } + if redacted := len(md) - len(keys); redacted > 0 { + if len(keys) > 0 { + sb.WriteByte(' ') + } + fmt.Fprintf(&sb, "<%d redacted>", redacted) + } + sb.WriteByte(']') + return sb.String() +} + // Len returns the number of items in md. func (md MD) Len() int { return len(md) diff --git a/vendor/google.golang.org/grpc/resolver_wrapper.go b/vendor/google.golang.org/grpc/resolver_wrapper.go index 6e6137643..f8b0fd38f 100644 --- a/vendor/google.golang.org/grpc/resolver_wrapper.go +++ b/vendor/google.golang.org/grpc/resolver_wrapper.go @@ -188,7 +188,7 @@ func (ccr *ccResolverWrapper) ParseServiceConfig(scJSON string) *serviceconfig.P // addChannelzTraceEvent adds a channelz trace event containing the new // state received from resolver implementations. func (ccr *ccResolverWrapper) addChannelzTraceEvent(s resolver.State) { - if !logger.V(0) && !channelz.IsOn() { + if !logger.V(2) && !channelz.IsOn() { return } var updates []string diff --git a/vendor/google.golang.org/grpc/server.go b/vendor/google.golang.org/grpc/server.go index cf0a20671..4ab54115b 100644 --- a/vendor/google.golang.org/grpc/server.go +++ b/vendor/google.golang.org/grpc/server.go @@ -89,6 +89,7 @@ func init() { internal.MetricsRecorderForServer = func(srv *Server) estats.MetricsRecorder { return istats.NewMetricsRecorderList(srv.opts.statsHandlers) } + internal.XDSFilterWrapperOption = xdsFilterWrapperOption } var statusOK = status.New(codes.OK, "") @@ -117,10 +118,8 @@ type ServiceDesc struct { // serviceInfo wraps information about a service. It is very similar to // ServiceDesc and is constructed from it for internal purposes. type serviceInfo struct { - // Contains the implementation for the methods in this service. - serviceImpl any - methods map[string]*MethodDesc - streams map[string]*StreamDesc + serviceImpl any // Implementation for the methods in this service. + streams map[string]*StreamDesc // Streaming descriptors and wrapped unary descriptors for this service. mdata any } @@ -183,6 +182,7 @@ type serverOptions struct { bufferPool mem.BufferPool waitForHandlers bool staticWindowSize bool + streamWrapper func(ServerStream) (ServerStream, error) } var defaultServerOptions = serverOptions{ @@ -663,6 +663,14 @@ func bufferPool(bufferPool mem.BufferPool) ServerOption { }) } +// xdsFilterWrapperOption returns a ServerOption that sets the server-level +// stream wrapper (used internally by xDS server filters). +func xdsFilterWrapperOption(w func(ServerStream) (ServerStream, error)) ServerOption { + return newFuncServerOption(func(o *serverOptions) { + o.streamWrapper = w + }) +} + // serverWorkerResetThreshold defines how often the stack must be reset. Every // N requests, by spawning a new goroutine in its place, a worker can reset its // stack so that large stacks don't live in memory forever. 2^16 should allow @@ -790,18 +798,22 @@ func (s *Server) register(sd *ServiceDesc, ss any) { } info := &serviceInfo{ serviceImpl: ss, - methods: make(map[string]*MethodDesc), streams: make(map[string]*StreamDesc), mdata: sd.Metadata, } - for i := range sd.Methods { - d := &sd.Methods[i] - info.methods[d.MethodName] = d - } for i := range sd.Streams { d := &sd.Streams[i] info.streams[d.StreamName] = d } + for i := range sd.Methods { + d := &sd.Methods[i] + info.streams[d.MethodName] = &StreamDesc{ + StreamName: d.MethodName, + Handler: s.wrapUnaryHandler(d), + ServerStreams: false, + ClientStreams: false, + } + } s.services[sd.ServiceName] = info } @@ -827,20 +839,26 @@ type ServiceInfo struct { func (s *Server) GetServiceInfo() map[string]ServiceInfo { ret := make(map[string]ServiceInfo) for n, srv := range s.services { - methods := make([]MethodInfo, 0, len(srv.methods)+len(srv.streams)) - for m := range srv.methods { - methods = append(methods, MethodInfo{ - Name: m, - IsClientStream: false, - IsServerStream: false, - }) + methods := make([]MethodInfo, 0, len(srv.streams)) + // Iterate over unary methods first to maintain backward compatibility of order. + for m, d := range srv.streams { + if !d.ClientStreams && !d.ServerStreams { + methods = append(methods, MethodInfo{ + Name: m, + IsClientStream: false, + IsServerStream: false, + }) + } } + // Iterate over streaming methods. for m, d := range srv.streams { - methods = append(methods, MethodInfo{ - Name: m, - IsClientStream: d.ClientStreams, - IsServerStream: d.ServerStreams, - }) + if d.ClientStreams || d.ServerStreams { + methods = append(methods, MethodInfo{ + Name: m, + IsClientStream: d.ClientStreams, + IsServerStream: d.ServerStreams, + }) + } } ret[n] = ServiceInfo{ @@ -1185,42 +1203,6 @@ func (s *Server) incrCallsFailed() { s.channelz.ServerMetrics.CallsFailed.Add(1) } -func (s *Server) sendResponse(ctx context.Context, stream *transport.ServerStream, msg any, cp Compressor, opts *transport.WriteOptions, comp encoding.Compressor) error { - data, err := encode(s.getCodec(stream.ContentSubtype()), msg) - if err != nil { - channelz.Error(logger, s.channelz, "grpc: server failed to encode response: ", err) - return err - } - - compData, pf, err := compress(data, cp, comp, s.opts.bufferPool) - if err != nil { - data.Free() - channelz.Error(logger, s.channelz, "grpc: server failed to compress response: ", err) - return err - } - - hdr, payload := msgHeader(data, compData, pf) - - defer func() { - compData.Free() - data.Free() - // payload does not need to be freed here, it is either data or compData, both of - // which are already freed. - }() - - dataLen := data.Len() - payloadLen := payload.Len() - // TODO(dfawley): should we be checking len(data) instead? - if payloadLen > s.opts.maxSendMessageSize { - return status.Errorf(codes.ResourceExhausted, "grpc: trying to send message larger than max (%d vs. %d)", payloadLen, s.opts.maxSendMessageSize) - } - err = stream.Write(hdr, payload, opts) - if err == nil && s.statsHandler != nil { - s.statsHandler.HandleRPC(ctx, outPayload(false, msg, dataLen, payloadLen, time.Now())) - } - return err -} - // chainUnaryServerInterceptors chains all unary server interceptors into one. func chainUnaryServerInterceptors(s *Server) { // Prepend opts.unaryInt to the chaining interceptors if it exists, since unaryInt will @@ -1257,300 +1239,6 @@ func getChainUnaryHandler(interceptors []UnaryServerInterceptor, curr int, info } } -func (s *Server) processUnaryRPC(ctx context.Context, stream *transport.ServerStream, info *serviceInfo, md *MethodDesc, trInfo *traceInfo) (err error) { - sh := s.statsHandler - if sh != nil || trInfo != nil || channelz.IsOn() { - if channelz.IsOn() { - s.incrCallsStarted() - } - var statsBegin *stats.Begin - if sh != nil { - statsBegin = &stats.Begin{ - BeginTime: time.Now(), - IsClientStream: false, - IsServerStream: false, - } - sh.HandleRPC(ctx, statsBegin) - } - if trInfo != nil { - trInfo.tr.LazyLog(&trInfo.firstLine, false) - } - // The deferred error handling for tracing, stats handler and channelz are - // combined into one function to reduce stack usage -- a defer takes ~56-64 - // bytes on the stack, so overflowing the stack will require a stack - // re-allocation, which is expensive. - // - // To maintain behavior similar to separate deferred statements, statements - // should be executed in the reverse order. That is, tracing first, stats - // handler second, and channelz last. Note that panics *within* defers will - // lead to different behavior, but that's an acceptable compromise; that - // would be undefined behavior territory anyway. - defer func() { - if trInfo != nil { - if err != nil && err != io.EOF { - trInfo.tr.LazyLog(&fmtStringer{"%v", []any{err}}, true) - trInfo.tr.SetError() - } - trInfo.tr.Finish() - } - - if sh != nil { - end := &stats.End{ - BeginTime: statsBegin.BeginTime, - EndTime: time.Now(), - } - if err != nil && err != io.EOF { - end.Error = toRPCErr(err) - } - sh.HandleRPC(ctx, end) - } - - if channelz.IsOn() { - if err != nil && err != io.EOF { - s.incrCallsFailed() - } else { - s.incrCallsSucceeded() - } - } - }() - } - var binlogs []binarylog.MethodLogger - if ml := binarylog.GetMethodLogger(stream.Method()); ml != nil { - binlogs = append(binlogs, ml) - } - if s.opts.binaryLogger != nil { - if ml := s.opts.binaryLogger.GetMethodLogger(stream.Method()); ml != nil { - binlogs = append(binlogs, ml) - } - } - if len(binlogs) != 0 { - md, _ := metadata.FromIncomingContext(ctx) - logEntry := &binarylog.ClientHeader{ - Header: md, - MethodName: stream.Method(), - PeerAddr: nil, - } - if deadline, ok := ctx.Deadline(); ok { - logEntry.Timeout = time.Until(deadline) - if logEntry.Timeout < 0 { - logEntry.Timeout = 0 - } - } - if a := md[":authority"]; len(a) > 0 { - logEntry.Authority = a[0] - } - if peer, ok := peer.FromContext(ctx); ok { - logEntry.PeerAddr = peer.Addr - } - for _, binlog := range binlogs { - binlog.Log(ctx, logEntry) - } - } - - // comp and cp are used for compression. decomp and dc are used for - // decompression. If comp and decomp are both set, they are the same; - // however they are kept separate to ensure that at most one of the - // compressor/decompressor variable pairs are set for use later. - var comp, decomp encoding.Compressor - var cp Compressor - var dc Decompressor - var sendCompressorName string - - // If dc is set and matches the stream's compression, use it. Otherwise, try - // to find a matching registered compressor for decomp. - if rc := stream.RecvCompress(); s.opts.dc != nil && s.opts.dc.Type() == rc { - dc = s.opts.dc - } else if rc != "" && rc != encoding.Identity { - decomp = encoding.GetCompressor(rc) - if decomp == nil { - st := status.Newf(codes.Unimplemented, "grpc: Decompressor is not installed for grpc-encoding %q", rc) - stream.WriteStatus(st) - return st.Err() - } - } - - // If cp is set, use it. Otherwise, attempt to compress the response using - // the incoming message compression method. - // - // NOTE: this needs to be ahead of all handling, https://github.com/grpc/grpc-go/issues/686. - if s.opts.cp != nil { - cp = s.opts.cp - sendCompressorName = cp.Type() - } else if rc := stream.RecvCompress(); rc != "" && rc != encoding.Identity { - // Legacy compressor not specified; attempt to respond with same encoding. - comp = encoding.GetCompressor(rc) - if comp != nil { - sendCompressorName = comp.Name() - } - } - - if sendCompressorName != "" { - if err := stream.SetSendCompress(sendCompressorName); err != nil { - return status.Errorf(codes.Internal, "grpc: failed to set send compressor: %v", err) - } - } - - var payInfo *payloadInfo - if sh != nil || len(binlogs) != 0 { - payInfo = &payloadInfo{} - defer payInfo.free() - } - - d, err := recvAndDecompress(&parser{r: stream, bufferPool: s.opts.bufferPool}, stream, dc, s.opts.maxReceiveMessageSize, payInfo, decomp, true) - if err != nil { - if e := stream.WriteStatus(status.Convert(err)); e != nil { - channelz.Warningf(logger, s.channelz, "grpc: Server.processUnaryRPC failed to write status: %v", e) - } - return err - } - freed := false - dataFree := func() { - if !freed { - d.Free() - freed = true - } - } - defer dataFree() - df := func(v any) error { - defer dataFree() - if err := s.getCodec(stream.ContentSubtype()).Unmarshal(d, v); err != nil { - return status.Errorf(codes.Internal, "grpc: error unmarshalling request: %v", err) - } - - if sh != nil { - sh.HandleRPC(ctx, &stats.InPayload{ - RecvTime: time.Now(), - Payload: v, - Length: d.Len(), - WireLength: payInfo.compressedLength + headerLen, - CompressedLength: payInfo.compressedLength, - }) - } - if len(binlogs) != 0 { - cm := &binarylog.ClientMessage{ - Message: d.Materialize(), - } - for _, binlog := range binlogs { - binlog.Log(ctx, cm) - } - } - if trInfo != nil { - trInfo.tr.LazyLog(&payload{sent: false, msg: v}, true) - } - return nil - } - ctx = NewContextWithServerTransportStream(ctx, stream) - reply, appErr := md.Handler(info.serviceImpl, ctx, df, s.opts.unaryInt) - if appErr != nil { - appStatus, ok := status.FromError(appErr) - if !ok { - // Convert non-status application error to a status error with code - // Unknown, but handle context errors specifically. - appStatus = status.FromContextError(appErr) - appErr = appStatus.Err() - } - if trInfo != nil { - trInfo.tr.LazyLog(stringer(appStatus.Message()), true) - trInfo.tr.SetError() - } - if e := stream.WriteStatus(appStatus); e != nil { - channelz.Warningf(logger, s.channelz, "grpc: Server.processUnaryRPC failed to write status: %v", e) - } - if len(binlogs) != 0 { - if h, _ := stream.Header(); h.Len() > 0 { - // Only log serverHeader if there was header. Otherwise it can - // be trailer only. - sh := &binarylog.ServerHeader{ - Header: h, - } - for _, binlog := range binlogs { - binlog.Log(ctx, sh) - } - } - st := &binarylog.ServerTrailer{ - Trailer: stream.Trailer(), - Err: appErr, - } - for _, binlog := range binlogs { - binlog.Log(ctx, st) - } - } - return appErr - } - if trInfo != nil { - trInfo.tr.LazyLog(stringer("OK"), false) - } - opts := &transport.WriteOptions{Last: true} - - // Server handler could have set new compressor by calling SetSendCompressor. - // In case it is set, we need to use it for compressing outbound message. - if stream.SendCompress() != sendCompressorName { - comp = encoding.GetCompressor(stream.SendCompress()) - } - if err := s.sendResponse(ctx, stream, reply, cp, opts, comp); err != nil { - if err == io.EOF { - // The entire stream is done (for unary RPC only). - return err - } - if sts, ok := status.FromError(err); ok { - if e := stream.WriteStatus(sts); e != nil { - channelz.Warningf(logger, s.channelz, "grpc: Server.processUnaryRPC failed to write status: %v", e) - } - } else { - switch st := err.(type) { - case transport.ConnectionError: - // Nothing to do here. - default: - panic(fmt.Sprintf("grpc: Unexpected error (%T) from sendResponse: %v", st, st)) - } - } - if len(binlogs) != 0 { - h, _ := stream.Header() - sh := &binarylog.ServerHeader{ - Header: h, - } - st := &binarylog.ServerTrailer{ - Trailer: stream.Trailer(), - Err: appErr, - } - for _, binlog := range binlogs { - binlog.Log(ctx, sh) - binlog.Log(ctx, st) - } - } - return err - } - if len(binlogs) != 0 { - h, _ := stream.Header() - sh := &binarylog.ServerHeader{ - Header: h, - } - sm := &binarylog.ServerMessage{ - Message: reply, - } - for _, binlog := range binlogs { - binlog.Log(ctx, sh) - binlog.Log(ctx, sm) - } - } - if trInfo != nil { - trInfo.tr.LazyLog(&payload{sent: true, msg: reply}, true) - } - // TODO: Should we be logging if writing status failed here, like above? - // Should the logging be in WriteStatus? Should we ignore the WriteStatus - // error or allow the stats handler to see it? - if len(binlogs) != 0 { - st := &binarylog.ServerTrailer{ - Trailer: stream.Trailer(), - Err: appErr, - } - for _, binlog := range binlogs { - binlog.Log(ctx, st) - } - } - return stream.WriteStatus(statusOK) -} - // chainStreamServerInterceptors chains all stream server interceptors into one. func chainStreamServerInterceptors(s *Server) { // Prepend opts.streamInt to the chaining interceptors if it exists, since streamInt will @@ -1587,7 +1275,21 @@ func getChainStreamHandler(interceptors []StreamServerInterceptor, curr int, inf } } -func (s *Server) processStreamingRPC(ctx context.Context, stream *transport.ServerStream, info *serviceInfo, sd *StreamDesc, trInfo *traceInfo) (err error) { +// wrapUnaryHandler converts a standard Unary Method Descriptor into a +// StreamHandler, allowing Unary RPCs to be processed via the same unified +// pipeline as Streaming RPCs. +func (s *Server) wrapUnaryHandler(md *MethodDesc) StreamHandler { + return func(srv any, stream ServerStream) error { + df := func(v any) error { return stream.RecvMsg(v) } + reply, err := md.Handler(srv, stream.Context(), df, s.opts.unaryInt) + if err != nil { + return err + } + return stream.SendMsg(reply) + } +} + +func (s *Server) processRPC(ctx context.Context, stream *transport.ServerStream, info *serviceInfo, sd *StreamDesc, trInfo *traceInfo) (err error) { if channelz.IsOn() { s.incrCallsStarted() } @@ -1615,7 +1317,16 @@ func (s *Server) processStreamingRPC(ctx context.Context, stream *transport.Serv } if sh != nil || trInfo != nil || channelz.IsOn() { - // See comment in processUnaryRPC on defers. + // The deferred error handling for tracing, stats handler and channelz are + // combined into one function to reduce stack usage -- a defer takes ~56-64 + // bytes on the stack, so overflowing the stack will require a stack + // re-allocation, which is expensive. + // + // To maintain behavior similar to separate deferred statements, statements + // should be executed in the reverse order. That is, tracing first, stats + // handler second, and channelz last. Note that panics *within* defers will + // lead to different behavior, but that's an acceptable compromise; that + // would be undefined behavior territory anyway. defer func() { if trInfo != nil { ss.mu.Lock() @@ -1689,7 +1400,7 @@ func (s *Server) processStreamingRPC(ctx context.Context, stream *transport.Serv ss.decompressorV1 = encoding.GetCompressor(rc) if ss.decompressorV1 == nil { st := status.Newf(codes.Unimplemented, "grpc: Decompressor is not installed for grpc-encoding %q", rc) - ss.s.WriteStatus(st) + ss.writeStatus(st) return st.Err() } } @@ -1717,23 +1428,34 @@ func (s *Server) processStreamingRPC(ctx context.Context, stream *transport.Serv ss.ctx = newContextWithRPCInfo(ss.ctx, false, ss.codec, ss.compressorV0, ss.compressorV1) - if trInfo != nil { - trInfo.tr.LazyLog(&trInfo.firstLine, false) - } + // Execute the xDS HTTP filter interceptors. var appErr error - var server any - if info != nil { - server = info.serviceImpl + var wrappedStream ServerStream = ss + if s.opts.streamWrapper != nil { + wrappedStream, appErr = s.opts.streamWrapper(ss) } - if s.opts.streamInt == nil { - appErr = sd.Handler(server, ss) - } else { - info := &StreamServerInfo{ - FullMethod: stream.Method(), - IsClientStream: sd.ClientStreams, - IsServerStream: sd.ServerStreams, + + if appErr == nil { + if trInfo != nil { + trInfo.tr.LazyLog(&trInfo.firstLine, false) + } + var server any + if info != nil { + server = info.serviceImpl + } + if s.opts.streamInt == nil || (!sd.ClientStreams && !sd.ServerStreams) { + // If there is no stream interceptor, or if this is a unary RPC, call + // the handler directly. The wrapped unary handler will call the unary + // interceptor if it exists. + appErr = sd.Handler(server, wrappedStream) + } else { + info := &StreamServerInfo{ + FullMethod: stream.Method(), + IsClientStream: sd.ClientStreams, + IsServerStream: sd.ServerStreams, + } + appErr = s.opts.streamInt(server, wrappedStream, info, sd.Handler) } - appErr = s.opts.streamInt(server, ss, info, sd.Handler) } if appErr != nil { appStatus, ok := status.FromError(appErr) @@ -1750,6 +1472,17 @@ func (s *Server) processStreamingRPC(ctx context.Context, stream *transport.Serv ss.mu.Unlock() } if len(ss.binlogs) != 0 { + if !ss.serverHeaderBinlogged { + if h, _ := ss.s.Header(); h.Len() > 0 { + sh := &binarylog.ServerHeader{ + Header: h, + } + ss.serverHeaderBinlogged = true + for _, binlog := range ss.binlogs { + binlog.Log(ctx, sh) + } + } + } st := &binarylog.ServerTrailer{ Trailer: ss.s.Trailer(), Err: appErr, @@ -1758,8 +1491,9 @@ func (s *Server) processStreamingRPC(ctx context.Context, stream *transport.Serv binlog.Log(ctx, st) } } - ss.s.WriteStatus(appStatus) - // TODO: Should we log an error from WriteStatus here and below? + if err := ss.writeStatus(appStatus); err != nil { + channelz.Warningf(logger, s.channelz, "grpc: Server.processRPC failed to write status: %v", err) + } return appErr } if trInfo != nil { @@ -1776,7 +1510,10 @@ func (s *Server) processStreamingRPC(ctx context.Context, stream *transport.Serv binlog.Log(ctx, st) } } - return ss.s.WriteStatus(statusOK) + if err := ss.writeStatus(statusOK); err != nil { + channelz.Warningf(logger, s.channelz, "grpc: Server.processRPC failed to write status: %v", err) + } + return err } func (s *Server) handleMalformedMethodName(stream *transport.ServerStream, ti *traceInfo) { @@ -1854,18 +1591,14 @@ func (s *Server) handleStream(t transport.ServerTransport, stream *transport.Ser srv, knownService := s.services[service] if knownService { - if md, ok := srv.methods[method]; ok { - s.processUnaryRPC(ctx, stream, srv, md, ti) - return - } if sd, ok := srv.streams[method]; ok { - s.processStreamingRPC(ctx, stream, srv, sd, ti) + s.processRPC(ctx, stream, srv, sd, ti) return } } // Unknown service, or known server unknown method. if unknownDesc := s.opts.unknownStreamDesc; unknownDesc != nil { - s.processStreamingRPC(ctx, stream, nil, unknownDesc, ti) + s.processRPC(ctx, stream, nil, unknownDesc, ti) return } var errDesc string @@ -2069,9 +1802,6 @@ func (s *Server) isRegisteredMethod(serviceMethod string) bool { method := serviceMethod[pos+1:] srv, knownService := s.services[service] if knownService { - if _, ok := srv.methods[method]; ok { - return true - } if _, ok := srv.streams[method]; ok { return true } diff --git a/vendor/google.golang.org/grpc/stream.go b/vendor/google.golang.org/grpc/stream.go index 51aff85df..52e59f2c5 100644 --- a/vendor/google.golang.org/grpc/stream.go +++ b/vendor/google.golang.org/grpc/stream.go @@ -28,6 +28,7 @@ import ( "strconv" "strings" "sync" + "sync/atomic" "time" "google.golang.org/grpc/balancer" @@ -148,6 +149,94 @@ type ClientStream interface { RecvMsg(m any) error } +// clientStreamWrapper wraps a ClientStream and handles SendMsg, CloseSend, and +// RecvMsg parities based on the nature of stream. +type clientStreamWrapper struct { + ClientStream + desc *StreamDesc + closeSendCalled atomic.Bool +} + +// CloseSend closes the send direction of the stream. The implementation ensures +// that CloseSend is only called once on the underlying ClientStream, even if +// CloseSend is called multiple times on the wrapper. +func (w *clientStreamWrapper) CloseSend() error { + if w.closeSendCalled.Swap(true) { + return nil + } + return w.ClientStream.CloseSend() +} + +// SendMsg sends message m across the stream. For RPCs where client can call +// SendMsg only once, i.e. only server-streaming RPCs, it converts io.EOF to nil +// and immediately calls CloseSend to trigger any interceptor hooks. +func (w *clientStreamWrapper) SendMsg(m any) error { + err := w.ClientStream.SendMsg(m) + // If the RPC is a client-streaming RPC, the client can send multiple + // messages. In this case, the client should handle any type of + // error,including io.EOF and call CloseSend once it is done sending messages. + if w.desc.ClientStreams { + return err + } + + if err == io.EOF { + // For non-client-streaming RPCs, we return nil instead of EOF on error + // because the generated code requires it. finish is not called; RecvMsg() + // will call it with the stream's status independently. + return nil + } + if err != nil { + return err + } + // In some scenarios (e.g., xDS), the same interceptors process both unary and + // streaming RPCs, relying on CloseSend to signal that no more messages are on + // the way. Although protobuf-generated stubs already invoke CloseSend for + // server-streaming RPCs, it is explicitly called here to ensure downstream + // interceptors are also notified when callers interact with the ClientStream + // API directly. + if err := w.CloseSend(); err != nil && err != io.EOF { + return err + } + return nil + +} + +// RecvMsg receives message m from the stream. For RPCs that call RecvMsg only +// once i.e. only client streaming RPCs, it calls the underlying RecvMsg a +// second time after receiving the first message to get the trailers. +func (w *clientStreamWrapper) RecvMsg(m any) error { + err := w.ClientStream.RecvMsg(m) + if err != nil { + return err + } + if w.desc.ServerStreams { + return nil + } + // Call RecvMsg again for non-server streaming RPCs to get the trailers and + // ensure RPC has completed successfully. + err = w.ClientStream.RecvMsg(m) + if err == io.EOF { + return nil + } + if err == nil { + return status.Error(codes.Internal, "cardinality violation: expected for non server-streaming RPCs, but received another message") + } + return err +} + +// defaultStreamInterceptor is a StreamClientInterceptor which wraps the +// ClientStream and is always invoked as the first interceptor. It consolidates +// behavior for different RPC types at the level closest to the application, +// which simplifies the underlying stream implementation and other interceptors +// by avoiding duplicate or scattered handling. +func defaultStreamInterceptor(ctx context.Context, desc *StreamDesc, cc *ClientConn, method string, streamer Streamer, opts ...CallOption) (ClientStream, error) { + cs, err := streamer(ctx, desc, cc, method, opts...) + if err != nil { + return nil, err + } + return &clientStreamWrapper{ClientStream: cs, desc: desc}, nil +} + // NewStream creates a new Stream for the client side. This is typically // called by generated code. ctx is used for the lifetime of the stream. // @@ -253,14 +342,11 @@ func newClientStream(ctx context.Context, desc *StreamDesc, cc *ClientConn, meth mc := &emptyMethodConfig var onCommit func() - newStream := func(ctx context.Context, filterOpts ...CallOption) (ClientStream, error) { - if filterOpts != nil { - opts = combine(opts, filterOpts) - } + newStream := func(ctx context.Context, opts ...CallOption) (ClientStream, error) { return newClientStreamWithParams(ctx, desc, cc, method, mc, onCommit, nameResolutionDelayed, opts...) } - rpcInfo := iresolver.RPCInfo{Context: ctx, Method: method} + rpcInfo := iresolver.RPCInfo{Context: ctx, Method: method, Authority: cc.authority} rpcConfig, err := cc.safeConfigSelector.SelectConfig(rpcInfo) if err != nil { if st, ok := status.FromError(err); ok { @@ -278,13 +364,23 @@ func newClientStream(ctx context.Context, desc *StreamDesc, cc *ClientConn, meth ctx = rpcConfig.Context } mc = &rpcConfig.MethodConfig - onCommit = rpcConfig.OnCommitted + + if rpcConfig.OnCommitted != nil { + onCommit = rpcConfig.OnCommitted + // Register an OnFinish CallOption with the OnCommitted callback to + // ensure it is invoked on stream termination, even if the stream + // fails early before committing. Implementations of OnCommitted are + // expected to be idempotent (e.g., guarded by sync.Once), since both + // onCommit and OnFinish may run for a single RPC. + opts = append(opts, OnFinish(func(error) { rpcConfig.OnCommitted() })) + } + if rpcConfig.Interceptor != nil { rpcInfo.Context = nil ns := newStream if interceptor, ok := rpcConfig.Interceptor.(clientInterceptor); ok { - newStream = func(ctx context.Context, filterOpts ...CallOption) (ClientStream, error) { - cs, err := interceptor.NewStream(ctx, rpcInfo, ns, filterOpts...) + newStream = func(ctx context.Context, opts ...CallOption) (ClientStream, error) { + cs, err := interceptor.NewStream(ctx, rpcInfo, ns, opts...) if err != nil { return nil, toRPCErr(err) } @@ -296,7 +392,7 @@ func newClientStream(ctx context.Context, desc *StreamDesc, cc *ClientConn, meth } } - return newStream(ctx) + return newStream(ctx, opts...) } func newClientStreamWithParams(ctx context.Context, desc *StreamDesc, cc *ClientConn, method string, mc *serviceconfig.MethodConfig, onCommit func(), nameResolutionDelayed bool, opts ...CallOption) (_ ClientStream, err error) { @@ -543,6 +639,9 @@ func (a *csAttempt) newStream() error { // maintained in it are local to the attempt. When the attempt has to be // retried, a new instance of csAttempt will be created. if a.pickResult.Metadata != nil { + if err := imetadata.Validate(a.pickResult.Metadata); err != nil { + return status.Error(codes.Internal, err.Error()) + } // We currently do not have a function it the metadata package which // merges given metadata with existing metadata in a context. Existing // function `AppendToOutgoingContext()` takes a variadic argument of key @@ -1044,8 +1143,8 @@ func (cs *clientStream) RecvMsg(m any) error { binlog.Log(cs.ctx, sm) } } - if err != nil || !cs.desc.ServerStreams { - // err != nil or non-server-streaming indicates end of stream. + if err != nil { + // err != nil indicates end of stream. cs.finish(err) } return err @@ -1093,7 +1192,8 @@ func (cs *clientStream) finish(err error) { } cs.finished = true cs.commitAttemptLocked() - if cs.attempt != nil { + attemptCreated := cs.attempt != nil + if attemptCreated { cs.attempt.finish(err) // after functions all rely upon having a stream. if cs.attempt.transportStream != nil { @@ -1131,7 +1231,13 @@ func (cs *clientStream) finish(err error) { if err == nil { cs.retryThrottler.successfulRPC() } - endOfClientStream(cs.cc, err, cs.opts...) + // If no attempt was ever created, stream creation has failed, and the + // cleanup is left to newClientStream, whose deferred cleanup invokes + // endOfClientStream if the call fails. Invoking it here as well would + // run the cleanup twice for the same call. + if attemptCreated { + endOfClientStream(cs.cc, err, cs.opts...) + } cs.cancel() } @@ -1145,12 +1251,6 @@ func (a *csAttempt) sendMsg(m any, hdr []byte, payld mem.BufferSlice, dataLength a.mu.Unlock() } if err := a.transportStream.Write(hdr, payld, &transport.WriteOptions{Last: !cs.desc.ClientStreams}); err != nil { - if !cs.desc.ClientStreams { - // For non-client-streaming RPCs, we return nil instead of EOF on error - // because the generated code requires it. finish is not called; RecvMsg() - // will call it with the stream's status independently. - return nil - } return io.EOF } if a.statsHandler != nil { @@ -1218,18 +1318,7 @@ func (a *csAttempt) recvMsg(m any, payInfo *payloadInfo) (err error) { Length: payInfo.uncompressedBytes.Len(), }) } - if cs.desc.ServerStreams { - // Subsequent messages should be received by subsequent RecvMsg calls. - return nil - } - // Special handling for non-server-stream rpcs. - // This recv expects EOF or errors, so we don't collect inPayload. - if err := recv(&a.parser, cs.codec, a.transportStream, a.decompressorV0, m, *cs.callInfo.maxReceiveMessageSize, nil, a.decompressorV1, false); err == io.EOF { - return a.transportStream.Status().Err() // non-server streaming Recv returns nil on success - } else if err != nil { - return toRPCErr(err) - } - return status.Error(codes.Internal, "cardinality violation: expected for non server-streaming RPCs, but received another message") + return nil } func (a *csAttempt) finish(err error) { @@ -1399,7 +1488,7 @@ func newNonRetryClientStream(ctx context.Context, desc *StreamDesc, method strin } }() } - return as, nil + return &clientStreamWrapper{ClientStream: as, desc: desc}, nil } type addrConnStream struct { @@ -1497,12 +1586,6 @@ func (as *addrConnStream) SendMsg(m any) (err error) { } if err := as.transportStream.Write(hdr, payload, &transport.WriteOptions{Last: !as.desc.ClientStreams}); err != nil { - if !as.desc.ClientStreams { - // For non-client-streaming RPCs, we return nil instead of EOF on error - // because the generated code requires it. finish is not called; RecvMsg() - // will call it with the stream's status independently. - return nil - } return io.EOF } @@ -1511,8 +1594,8 @@ func (as *addrConnStream) SendMsg(m any) (err error) { func (as *addrConnStream) RecvMsg(m any) (err error) { defer func() { - if err != nil || !as.desc.ServerStreams { - // err != nil or non-server-streaming indicates end of stream. + if err != nil { + // err != nil indicates end of stream. as.finish(err) } }() @@ -1551,20 +1634,7 @@ func (as *addrConnStream) RecvMsg(m any) (err error) { return toRPCErr(err) } as.receivedFirstMsg = true - - if as.desc.ServerStreams { - // Subsequent messages should be received by subsequent RecvMsg calls. - return nil - } - - // Special handling for non-server-stream rpcs. - // This recv expects EOF or errors, so we don't collect inPayload. - if err := recv(&as.parser, as.codec, as.transportStream, as.decompressorV0, m, *as.callInfo.maxReceiveMessageSize, nil, as.decompressorV1, false); err == io.EOF { - return as.transportStream.Status().Err() // non-server streaming Recv returns nil on success - } else if err != nil { - return toRPCErr(err) - } - return status.Error(codes.Internal, "cardinality violation: expected for non server-streaming RPCs, but received another message") + return nil } func (as *addrConnStream) finish(err error) { @@ -1675,6 +1745,8 @@ type serverStream struct { // synchronized. serverHeaderBinlogged bool + statusWritten atomic.Bool // True if status has been written to the transport. + mu sync.Mutex // protects trInfo.tr after the service handler runs. } @@ -1723,6 +1795,16 @@ func (ss *serverStream) SetTrailer(md metadata.MD) { ss.s.SetTrailer(md) } +// writeStatus sends the status of a stream to the client. It uses an atomic +// CAS to guarantee that the status is written to the transport exactly once, +// even if called concurrently. +func (ss *serverStream) writeStatus(st *status.Status) error { + if !ss.statusWritten.CompareAndSwap(false, true) { + return nil + } + return ss.s.WriteStatus(st) +} + func (ss *serverStream) SendMsg(m any) (err error) { defer func() { if ss.trInfo != nil { @@ -1739,7 +1821,7 @@ func (ss *serverStream) SendMsg(m any) (err error) { } if err != nil && err != io.EOF { st, _ := status.FromError(toRPCErr(err)) - ss.s.WriteStatus(st) + ss.writeStatus(st) // Non-user specified status was sent out. This should be an error // case (as a server side Cancel maybe). // @@ -1822,7 +1904,7 @@ func (ss *serverStream) RecvMsg(m any) (err error) { } if err != nil && err != io.EOF { st, _ := status.FromError(toRPCErr(err)) - ss.s.WriteStatus(st) + ss.writeStatus(st) // Non-user specified status was sent out. This should be an error // case (as a server side Cancel maybe). // diff --git a/vendor/google.golang.org/grpc/version.go b/vendor/google.golang.org/grpc/version.go index 835dc07fd..75f8ef50d 100644 --- a/vendor/google.golang.org/grpc/version.go +++ b/vendor/google.golang.org/grpc/version.go @@ -19,4 +19,4 @@ package grpc // Version is the current grpc version. -const Version = "1.83.2" +const Version = "1.84.0" diff --git a/vendor/modules.txt b/vendor/modules.txt index 595cc796d..65aa8f8d9 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -518,7 +518,7 @@ google.golang.org/genproto/googleapis/api/httpbody ## explicit; go 1.25.0 google.golang.org/genproto/googleapis/rpc/errdetails google.golang.org/genproto/googleapis/rpc/status -# google.golang.org/grpc v1.83.2 +# google.golang.org/grpc v1.84.0 ## explicit; go 1.25.0 google.golang.org/grpc google.golang.org/grpc/attributes From 03666b6af72746220f218c9a9dfbbe84df3741c4 Mon Sep 17 00:00:00 2001 From: "renovate-sh-app[bot]" <219655108+renovate-sh-app[bot]@users.noreply.github.com> Date: Mon, 21 Sep 2026 09:02:34 +0000 Subject: [PATCH 168/182] chore(deps): update golang docker tag to v1.27.1 (#6376) | datasource | package | from | to | | ---------- | ------- | ------ | ------ | | docker | golang | 1.27.0 | 1.27.1 | Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 5cd28a3e8..72cc306de 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM --platform=$BUILDPLATFORM golang:1.27.0-alpine@sha256:4c9fe60190a2a3350ddc51de80d0224b8a6698d12bdfc999fee45ea9d6c46dbc as builder +FROM --platform=$BUILDPLATFORM golang:1.27.1-alpine@sha256:4cb7ac979db5fcc41cae44b2227ba5ab8a51e8807f40d9ba4dee20a0ad960b5b as builder WORKDIR $GOPATH/src/go.k6.io/k6 COPY . . ARG TARGETOS TARGETARCH From 40e7c09055a78f8fba327f098c36668b3cf996cf Mon Sep 17 00:00:00 2001 From: Mihail Stoykov <312246+mstoykov@users.noreply.github.com> Date: Mon, 21 Sep 2026 16:26:26 +0300 Subject: [PATCH 169/182] feat(browser): propagate metric context into callbacks and metrics (#6345) Browser callbacks and CDP network events cross execution boundaries that Sobek's Promise tracking cannot observe. Requests and Web Vitals can be reported after the JavaScript call or group that initiated them has returned. Reading the VU's live tags at that point makes attribution depend on response timing and unrelated subsequent operations. Capture the complete metric context when browser callbacks are registered and restore it while invoking page events, waitForEvent predicates, routes, and browser-context callbacks. Track the context of browser operations that can initiate network traffic. Keep launched operations active until their returned Promise settles and retain the most recently finished operation for delayed CDP events. Discard calls that fail before launching an operation. Cover pages, frames, locators, element and JavaScript handles, keyboard, mouse, and touchscreen APIs. Explicitly classify every mapped callable as network or passive. Passive observers such as waitForResponse must remain unwrapped; otherwise, they can compete with the operation that initiated a request and make attribution timing-dependent. Requiring classification also makes newly added APIs fail closed instead of silently receiving the wrong behavior. CDP does not expose a general causal link between an API call and all traffic it triggers, so network attribution remains best-effort. Prefer an applicable frame-loader binding, then the latest active operation, the most recently finished operation, the page fallback, and finally the live VU context. Snapshot the selected context when NetworkManager creates a request so later operations cannot retag its response metrics. Preserve that snapshot across redirects, bind document navigations to their loaders, propagate opener context to popup pages, and use the navigation context for asynchronously reported Web Vitals. When async-metric-context is disabled, skip callback snapshots, operation wrappers, loader bindings, and request-owned snapshots, preserving the existing emit-time behavior. Add unit and integration coverage for callbacks, passive and network mapping classification, delayed requests, redirects, input actions, popups, standalone JavaScript handles, tags, metadata, Web Vitals, and teardown-safe metric emission. Add the metric-context example to the browser E2E workflow. --- .github/workflows/browser_e2e.yml | 1 + examples/browser/async_metric_context.js | 67 ++ .../browser/browser_context_mapping.go | 75 ++- .../k6/browser/browser/browser_mapping.go | 43 +- .../k6/browser/browser/chromium_mapping.go | 8 +- .../browser/console_message_mapping.go | 20 +- .../browser/browser/element_handle_mapping.go | 144 ++-- .../browser/browser/frame_locator_mapping.go | 40 +- .../k6/browser/browser/frame_mapping.go | 216 +++--- .../js/modules/k6/browser/browser/helpers.go | 11 + .../k6/browser/browser/js_handle_mapping.go | 39 +- .../k6/browser/browser/keyboard_mapping.go | 24 +- .../k6/browser/browser/locator_mapping.go | 197 +++--- .../js/modules/k6/browser/browser/mapping.go | 194 ++++++ .../k6/browser/browser/mapping_test.go | 225 +++++++ .../browser/browser/metric_event_mapping.go | 8 +- .../k6/browser/browser/mouse_mapping.go | 24 +- .../k6/browser/browser/page_mapping.go | 314 ++++----- .../k6/browser/browser/request_mapping.go | 46 +- .../k6/browser/browser/response_mapping.go | 60 +- .../k6/browser/browser/route_mapping.go | 20 +- .../k6/browser/browser/touchscreen_mapping.go | 8 +- .../k6/browser/browser/worker_mapping.go | 4 +- .../k6/browser/common/element_handle.go | 8 + .../js/modules/k6/browser/common/frame.go | 9 + .../k6/browser/common/frame_manager.go | 3 + .../k6/browser/common/frame_session.go | 13 +- .../k6/browser/common/frame_session_test.go | 88 +++ internal/js/modules/k6/browser/common/http.go | 7 + .../js/modules/k6/browser/common/js_handle.go | 13 + .../js/modules/k6/browser/common/locator.go | 8 + .../k6/browser/common/network_manager.go | 72 +- .../k6/browser/common/network_manager_test.go | 141 ++++ internal/js/modules/k6/browser/common/page.go | 135 ++++ .../js/modules/k6/browser/common/page_test.go | 94 +++ .../k6/browser/tests/asyncgroup_test.go | 615 ++++++++++++++++++ 36 files changed, 2371 insertions(+), 623 deletions(-) create mode 100644 examples/browser/async_metric_context.js create mode 100644 internal/js/modules/k6/browser/common/frame_session_test.go create mode 100644 internal/js/modules/k6/browser/tests/asyncgroup_test.go diff --git a/.github/workflows/browser_e2e.yml b/.github/workflows/browser_e2e.yml index e6f176e8c..e40bbfc26 100644 --- a/.github/workflows/browser_e2e.yml +++ b/.github/workflows/browser_e2e.yml @@ -71,6 +71,7 @@ jobs: export K6_BROWSER_EXECUTABLE_PATH=/usr/bin/google-chrome fi export K6_BROWSER_HEADLESS=true + export K6_FEATURES=async-metric-context export K6_NO_USAGE_REPORT=true for f in examples/browser/*.js; do if [ "$f" == "examples/browser/hosts.js" ] && [ "$RUNNER_OS" == "Windows" ]; then diff --git a/examples/browser/async_metric_context.js b/examples/browser/async_metric_context.js new file mode 100644 index 000000000..ce3cac48d --- /dev/null +++ b/examples/browser/async_metric_context.js @@ -0,0 +1,67 @@ +// Run with: +// k6 run --features async-metric-context examples/browser/async_metric_context.js + +import { browser } from 'k6/browser'; +import { check, group } from 'k6'; +import exec from 'k6/execution'; + +export const options = { + scenarios: { + ui: { + executor: 'shared-iterations', + iterations: 1, + options: { + browser: { + type: 'chromium', + }, + }, + }, + }, + thresholds: { + 'browser_http_req_duration{group:::navigation,owner:browser-navigation}': ['max >= 0'], + checks: ['rate == 1'], + }, +}; + +function contextMatches(owner, groupName) { + return exec.vu.metrics.tags.owner === owner + && exec.vu.metrics.tags.group === groupName + && exec.vu.metrics.metadata.trace === owner; +} + +export default async function () { + const page = await browser.newPage(); + exec.vu.metrics.tags.owner = 'root'; + exec.vu.metrics.metadata.trace = 'root'; + + let observedRequest = false; + try { + await group('navigation', async () => { + exec.vu.metrics.tags.owner = 'browser-navigation'; + exec.vu.metrics.metadata.trace = 'browser-navigation'; + + page.on('request', request => { + if (!request.url().startsWith('https://quickpizza.grafana.com/')) { + return; + } + observedRequest = true; + check(null, { + 'request callback kept its registration context': () => ( + contextMatches('browser-navigation', '::navigation') + ), + }); + }); + + await page.goto('https://quickpizza.grafana.com/', { waitUntil: 'domcontentloaded' }); + await page.title(); + page.url(); + }); + + check(null, { + 'navigation emitted a request event': () => observedRequest, + 'the context outside the group was restored': () => contextMatches('root', ''), + }); + } finally { + await page.close(); + } +} diff --git a/internal/js/modules/k6/browser/browser/browser_context_mapping.go b/internal/js/modules/k6/browser/browser/browser_context_mapping.go index fb495182d..a77c24225 100644 --- a/internal/js/modules/k6/browser/browser/browser_context_mapping.go +++ b/internal/js/modules/k6/browser/browser/browser_context_mapping.go @@ -20,13 +20,13 @@ func mapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //nolin } rt := vu.Runtime() - return mapping{ - "addCookies": func(cookies []*common.Cookie) *sobek.Promise { + return finishMapping(mapping{ + "addCookies": passiveCall(func(cookies []*common.Cookie) *sobek.Promise { return promise(vu, func() (any, error) { return nil, bc.AddCookies(cookies) //nolint:wrapcheck }) - }, - "addInitScript": func(script sobek.Value) *sobek.Promise { + }), + "addInitScript": passiveCall(func(script sobek.Value) *sobek.Promise { return promise(vu, func() (any, error) { if k6common.IsNullish(script) { return nil, nil @@ -54,33 +54,33 @@ func mapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //nolin return nil, bc.AddInitScript(source) //nolint:wrapcheck }) - }, - "browser": func() mapping { + }), + "browser": passiveCall(func() mapping { return mapBrowser(vu, func() (*common.Browser, error) { return bc.Browser(), nil }) - }, - "clearCookies": func() *sobek.Promise { + }), + "clearCookies": passiveCall(func() *sobek.Promise { return promise(vu, func() (any, error) { return nil, bc.ClearCookies() //nolint:wrapcheck }) - }, - "clearPermissions": func() *sobek.Promise { + }), + "clearPermissions": passiveCall(func() *sobek.Promise { return promise(vu, func() (any, error) { return nil, bc.ClearPermissions() //nolint:wrapcheck }) - }, - "close": func() *sobek.Promise { + }), + "close": passiveCall(func() *sobek.Promise { return promise(vu, func() (any, error) { return nil, bc.Close() //nolint:wrapcheck }) - }, - "cookies": func(urls ...string) *sobek.Promise { + }), + "cookies": passiveCall(func(urls ...string) *sobek.Promise { return promise(vu, func() (any, error) { return bc.Cookies(urls...) //nolint:wrapcheck }) - }, - "grantPermissions": func(permissions []string, opts sobek.Value) (*sobek.Promise, error) { + }), + "grantPermissions": passiveCall(func(permissions []string, opts sobek.Value) (*sobek.Promise, error) { popts, err := exportTo[common.GrantPermissionsOptions](vu.Runtime(), opts) if err != nil { return nil, fmt.Errorf("parsing grant permission options: %w", err) @@ -88,10 +88,10 @@ func mapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //nolin return promise(vu, func() (any, error) { return nil, bc.GrantPermissions(permissions, popts) }), nil - }, - "setDefaultNavigationTimeout": bc.SetDefaultNavigationTimeout, - "setDefaultTimeout": bc.SetDefaultTimeout, - "setGeolocation": func(geolocation sobek.Value) (*sobek.Promise, error) { + }), + "setDefaultNavigationTimeout": passiveCall(bc.SetDefaultNavigationTimeout), + "setDefaultTimeout": passiveCall(bc.SetDefaultTimeout), + "setGeolocation": passiveCall(func(geolocation sobek.Value) (*sobek.Promise, error) { gl, err := exportTo[common.Geolocation](vu.Runtime(), geolocation) if err != nil { return nil, fmt.Errorf("parsing geo location: %w", err) @@ -99,8 +99,8 @@ func mapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //nolin return promise(vu, func() (any, error) { return nil, bc.SetGeolocation(&gl) }), nil - }, - "setHTTPCredentials": func(httpCredentials sobek.Value) (*sobek.Promise, error) { + }), + "setHTTPCredentials": passiveCall(func(httpCredentials sobek.Value) (*sobek.Promise, error) { creds, err := exportTo[common.Credentials](rt, httpCredentials) if err != nil { return nil, fmt.Errorf("parsing HTTP credentials: %w", err) @@ -108,13 +108,13 @@ func mapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //nolin return promise(vu, func() (any, error) { return nil, bc.SetHTTPCredentials(creds) //nolint:staticcheck }), nil - }, - "setOffline": func(offline bool) *sobek.Promise { + }), + "setOffline": passiveCall(func(offline bool) *sobek.Promise { return promise(vu, func() (any, error) { return nil, bc.SetOffline(offline) //nolint:wrapcheck }) - }, - "waitForEvent": func(event string, optsOrPredicate sobek.Value) (*sobek.Promise, error) { + }), + "waitForEvent": passiveCall(func(event string, optsOrPredicate sobek.Value) (*sobek.Promise, error) { rt := vu.Runtime() ctx := vu.Context() @@ -128,8 +128,9 @@ func mapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //nolin // Waits until the event that satisfies the predicate. if popts.PredicateFn != nil { + captured := k6common.CaptureMetricContext(vu.State()) pred = func(p *common.Page) (bool, error) { - return queueTask(ctx, vu.get(ctx, p.TargetID()), func() (bool, error) { + return queueTaskWithMetricContext(ctx, vu.get(ctx, p.TargetID()), captured, func() (bool, error) { v, err := popts.PredicateFn(rt.ToValue(p)) if err != nil { return false, err @@ -151,8 +152,8 @@ func mapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //nolin } return mapPage(vu, p), nil }), nil - }, - "pages": func() *sobek.Object { + }), + "pages": passiveCall(func() *sobek.Object { var ( mpages []mapping pages = bc.Pages() @@ -166,17 +167,25 @@ func mapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //nolin } return rt.ToValue(mpages).ToObject(rt) - }, - "newPage": func() *sobek.Promise { + }), + "newPage": passiveCall(func() *sobek.Promise { + var setNetworkTags func(*common.Page) + if k6common.AsyncMetricContextEnabled(vu.State()) { + tagsAndMeta := vu.State().Tags.GetCurrentValues() + setNetworkTags = func(page *common.Page) { page.SetNetworkFallbackTagsAndMeta(tagsAndMeta) } + } return promise(vu, func() (any, error) { page, err := bc.NewPage() if err != nil { return nil, err //nolint:wrapcheck } + if setNetworkTags != nil { + setNetworkTags(page) + } return mapPage(vu, page), nil }) - }, - } + }), + }) } // waitForEventOptions are the options used by the browserContext.waitForEvent API. diff --git a/internal/js/modules/k6/browser/browser/browser_mapping.go b/internal/js/modules/k6/browser/browser/browser_mapping.go index 7d1d0ce4b..827e6a020 100644 --- a/internal/js/modules/k6/browser/browser/browser_mapping.go +++ b/internal/js/modules/k6/browser/browser/browser_mapping.go @@ -6,6 +6,7 @@ import ( "github.com/grafana/sobek" "go.k6.io/k6/v2/internal/js/modules/k6/browser/common" + k6common "go.k6.io/k6/v2/js/common" ) // browserProvider is a function that provides a browser instance. @@ -18,14 +19,14 @@ type browserProvider func() (*common.Browser, error) //nolint:gocognit,funlen func mapBrowser(vu moduleVU, browser browserProvider) mapping { m := mapping{ - "context": func() (mapping, error) { + "context": passiveCall(func() (mapping, error) { b, err := browser() if err != nil { return nil, err } return mapBrowserContext(vu, b.Context()), nil - }, - "closeContext": func() *sobek.Promise { + }), + "closeContext": passiveCall(func() *sobek.Promise { return promise(vu, func() (any, error) { b, err := browser() if err != nil { @@ -33,15 +34,15 @@ func mapBrowser(vu moduleVU, browser browserProvider) mapping { } return nil, b.CloseContext() //nolint:wrapcheck }) - }, - "isConnected": func() (bool, error) { + }), + "isConnected": passiveCall(func() (bool, error) { b, err := browser() if err != nil { return false, err } return b.IsConnected(), nil - }, - "newContext": func(opts sobek.Value) (*sobek.Promise, error) { + }), + "newContext": passiveCall(func(opts sobek.Value) (*sobek.Promise, error) { popts, err := parseBrowserContextOptions(vu.Runtime(), opts) if err != nil { return nil, fmt.Errorf("parsing browser.newContext options: %w", err) @@ -61,26 +62,31 @@ func mapBrowser(vu moduleVU, browser browserProvider) mapping { return mapBrowserContext(vu, bctx), nil }), nil - }, - "userAgent": func() (string, error) { + }), + "userAgent": passiveCall(func() (string, error) { b, err := browser() if err != nil { return "", err } return b.UserAgent(), nil - }, - "version": func() (string, error) { + }), + "version": passiveCall(func() (string, error) { b, err := browser() if err != nil { return "", err } return b.Version(), nil - }, - "newPage": func(opts sobek.Value) (*sobek.Promise, error) { + }), + "newPage": passiveCall(func(opts sobek.Value) (*sobek.Promise, error) { popts, err := parseBrowserContextOptions(vu.Runtime(), opts) if err != nil { return nil, fmt.Errorf("parsing browser.newPage options: %w", err) } + var setNetworkTags func(*common.Page) + if k6common.AsyncMetricContextEnabled(vu.State()) { + tagsAndMeta := vu.State().Tags.GetCurrentValues() + setNetworkTags = func(page *common.Page) { page.SetNetworkFallbackTagsAndMeta(tagsAndMeta) } + } return promise(vu, func() (any, error) { b, err := browser() if err != nil { @@ -90,18 +96,21 @@ func mapBrowser(vu moduleVU, browser browserProvider) mapping { if err != nil { return nil, err //nolint:wrapcheck } + if setNetworkTags != nil { + setNetworkTags(page) + } if err := initBrowserContext(b.Context(), vu.testRunID); err != nil { return nil, err } return mapPage(vu, page), nil }), nil - }, + }), } addUserManagedClose(vu, m, browser) - return m + return finishMapping(m) } // addUserManagedClose adds a close() method to the browser mapping when the @@ -124,13 +133,13 @@ func addUserManagedClose(vu moduleVU, m mapping, browser browserProvider) { if !ok { return } - m["close"] = func() *sobek.Promise { + m["close"] = passiveCall(func() *sobek.Promise { return promise(vu, func() (any, error) { vu.untrackUserManagedBrowser(iter, b) b.Close() return nil, nil }) - } + }) } func initBrowserContext(bctx *common.BrowserContext, testRunID string) error { diff --git a/internal/js/modules/k6/browser/browser/chromium_mapping.go b/internal/js/modules/k6/browser/browser/chromium_mapping.go index b5f21b272..53fd16cf6 100644 --- a/internal/js/modules/k6/browser/browser/chromium_mapping.go +++ b/internal/js/modules/k6/browser/browser/chromium_mapping.go @@ -11,8 +11,8 @@ import ( // mapChromium maps the Chromium browser type API to the JS module. func mapChromium(vu moduleVU, bt *chromium.BrowserType) mapping { - return mapping{ - "connectOverCDP": func(wsEndpoint string) *sobek.Promise { + return finishMapping(mapping{ + "connectOverCDP": passiveCall(func(wsEndpoint string) *sobek.Promise { return promise(vu, func() (any, error) { iter := vu.State().Iteration @@ -35,6 +35,6 @@ func mapChromium(vu moduleVU, bt *chromium.BrowserType) mapping { return b, nil }), nil }) - }, - } + }), + }) } diff --git a/internal/js/modules/k6/browser/browser/console_message_mapping.go b/internal/js/modules/k6/browser/browser/console_message_mapping.go index 1a6d3e037..ec1f75e01 100644 --- a/internal/js/modules/k6/browser/browser/console_message_mapping.go +++ b/internal/js/modules/k6/browser/browser/console_message_mapping.go @@ -8,8 +8,8 @@ import ( func mapConsoleMessage(vu moduleVU, event common.PageEvent) mapping { cm := event.ConsoleMessage - return mapping{ - "args": func() []mapping { + return finishMapping(mapping{ + "args": passiveCall(func() []mapping { args := cm.Args margs := make([]mapping, 0, len(args)) for _, arg := range args { @@ -18,17 +18,17 @@ func mapConsoleMessage(vu moduleVU, event common.PageEvent) mapping { } return margs - }, + }), // page(), text() and type() are defined as // functions in order to match Playwright's API - "page": func() mapping { + "page": passiveCall(func() mapping { return mapPage(vu, cm.Page) - }, - "text": func() string { + }), + "text": passiveCall(func() string { return cm.Text - }, - "type": func() string { + }), + "type": passiveCall(func() string { return cm.Type - }, - } + }), + }) } diff --git a/internal/js/modules/k6/browser/browser/element_handle_mapping.go b/internal/js/modules/k6/browser/browser/element_handle_mapping.go index b4d97d2b1..9ab237e8d 100644 --- a/internal/js/modules/k6/browser/browser/element_handle_mapping.go +++ b/internal/js/modules/k6/browser/browser/element_handle_mapping.go @@ -21,7 +21,7 @@ func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint: rt := vu.Runtime() maps := mapping{ - "boundingBox": func() *sobek.Promise { + "boundingBox": passiveCall(func() *sobek.Promise { return promise(vu, func() (any, error) { box, err := eh.BoundingBox() // We want to avoid errors when an element is not visible or detached and instead @@ -31,8 +31,8 @@ func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint: } return box, err }) - }, - "check": func(opts sobek.Value) (*sobek.Promise, error) { + }), + "check": networkCall(func(opts sobek.Value) (*sobek.Promise, error) { popts, err := parseElementHandleSetCheckedOptions(rt, opts, eh.DefaultTimeout()) if err != nil { return nil, fmt.Errorf("parsing check options: %w", err) @@ -40,8 +40,8 @@ func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint: return promise(vu, func() (any, error) { return nil, eh.Check(popts) //nolint:wrapcheck }), nil - }, - "click": func(opts sobek.Value) (*sobek.Promise, error) { + }), + "click": networkCall(func(opts sobek.Value) (*sobek.Promise, error) { popts, err := parseElementHandleClickOptions(rt, opts, eh.Timeout()) if err != nil { return nil, fmt.Errorf("parsing element click options: %w", err) @@ -51,8 +51,8 @@ func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint: err := eh.Click(popts) return nil, err //nolint:wrapcheck }), nil - }, - "contentFrame": func() *sobek.Promise { + }), + "contentFrame": passiveCall(func() *sobek.Promise { return promise(vu, func() (any, error) { f, err := eh.ContentFrame() if err != nil { @@ -60,8 +60,8 @@ func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint: } return mapFrame(vu, f), nil }) - }, - "dblclick": func(opts sobek.Value) (*sobek.Promise, error) { + }), + "dblclick": networkCall(func(opts sobek.Value) (*sobek.Promise, error) { popts, err := parseElementHandleDblclickOptions(rt, opts, eh.DefaultTimeout()) if err != nil { return nil, fmt.Errorf("parsing element double click options: %w", err) @@ -69,13 +69,13 @@ func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint: return promise(vu, func() (any, error) { return nil, eh.Dblclick(popts) //nolint:wrapcheck }), nil - }, - "dispatchEvent": func(typ string, eventInit sobek.Value) *sobek.Promise { + }), + "dispatchEvent": networkCall(func(typ string, eventInit sobek.Value) *sobek.Promise { return promise(vu, func() (any, error) { return nil, eh.DispatchEvent(typ, exportArg(eventInit)) //nolint:wrapcheck }) - }, - "fill": func(value string, opts sobek.Value) (*sobek.Promise, error) { + }), + "fill": networkCall(func(value string, opts sobek.Value) (*sobek.Promise, error) { popts := common.NewElementHandleBaseOptions(eh.DefaultTimeout()) if err := parseElementHandleBaseOptions(popts, rt, opts); err != nil { return nil, fmt.Errorf("parsing element fill options: %w", err) @@ -83,13 +83,13 @@ func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint: return promise(vu, func() (any, error) { return nil, eh.Fill(value, popts) //nolint:wrapcheck }), nil - }, - "focus": func() *sobek.Promise { + }), + "focus": networkCall(func() *sobek.Promise { return promise(vu, func() (any, error) { return nil, eh.Focus() //nolint:wrapcheck }) - }, - "getAttribute": func(name string) *sobek.Promise { + }), + "getAttribute": passiveCall(func(name string) *sobek.Promise { return promise(vu, func() (any, error) { s, ok, err := eh.GetAttribute(name) if err != nil { @@ -100,8 +100,8 @@ func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint: } return s, nil }) - }, - "hover": func(opts sobek.Value) (*sobek.Promise, error) { + }), + "hover": networkCall(func(opts sobek.Value) (*sobek.Promise, error) { popts, err := parseElementHandleHoverOptions(rt, opts, eh.DefaultTimeout()) if err != nil { return nil, fmt.Errorf("parsing element hover options: %w", err) @@ -109,18 +109,18 @@ func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint: return promise(vu, func() (any, error) { return nil, eh.Hover(popts) //nolint:wrapcheck }), nil - }, - "innerHTML": func() *sobek.Promise { + }), + "innerHTML": passiveCall(func() *sobek.Promise { return promise(vu, func() (any, error) { return eh.InnerHTML() //nolint:wrapcheck }) - }, - "innerText": func() *sobek.Promise { + }), + "innerText": passiveCall(func() *sobek.Promise { return promise(vu, func() (any, error) { return eh.InnerText() //nolint:wrapcheck }) - }, - "inputValue": func(opts sobek.Value) (*sobek.Promise, error) { + }), + "inputValue": passiveCall(func(opts sobek.Value) (*sobek.Promise, error) { popts := common.NewElementHandleBaseOptions(eh.DefaultTimeout()) if err := parseElementHandleBaseOptions(popts, rt, opts); err != nil { return nil, fmt.Errorf("parsing element input value options: %w", err) @@ -128,38 +128,38 @@ func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint: return promise(vu, func() (any, error) { return eh.InputValue(popts) //nolint:wrapcheck }), nil - }, - "isChecked": func() *sobek.Promise { + }), + "isChecked": passiveCall(func() *sobek.Promise { return promise(vu, func() (any, error) { return eh.IsChecked() //nolint:wrapcheck }) - }, - "isDisabled": func() *sobek.Promise { + }), + "isDisabled": passiveCall(func() *sobek.Promise { return promise(vu, func() (any, error) { return eh.IsDisabled() //nolint:wrapcheck }) - }, - "isEditable": func() *sobek.Promise { + }), + "isEditable": passiveCall(func() *sobek.Promise { return promise(vu, func() (any, error) { return eh.IsEditable() //nolint:wrapcheck }) - }, - "isEnabled": func() *sobek.Promise { + }), + "isEnabled": passiveCall(func() *sobek.Promise { return promise(vu, func() (any, error) { return eh.IsEnabled() //nolint:wrapcheck }) - }, - "isHidden": func() *sobek.Promise { + }), + "isHidden": passiveCall(func() *sobek.Promise { return promise(vu, func() (any, error) { return eh.IsHidden() //nolint:wrapcheck }) - }, - "isVisible": func() *sobek.Promise { + }), + "isVisible": passiveCall(func() *sobek.Promise { return promise(vu, func() (any, error) { return eh.IsVisible() //nolint:wrapcheck }) - }, - "ownerFrame": func() *sobek.Promise { + }), + "ownerFrame": passiveCall(func() *sobek.Promise { return promise(vu, func() (any, error) { f, err := eh.OwnerFrame() if err != nil { @@ -167,8 +167,8 @@ func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint: } return mapFrame(vu, f), nil }) - }, - "press": func(key string, opts sobek.Value) (*sobek.Promise, error) { + }), + "press": networkCall(func(key string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseElementHandlePressOptions(rt, opts, eh.DefaultTimeout()) if err != nil { return nil, fmt.Errorf("parsing press %q options: %w", key, err) @@ -176,8 +176,8 @@ func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint: return promise(vu, func() (any, error) { return nil, eh.Press(key, popts) //nolint:wrapcheck }), nil - }, - "screenshot": func(opts sobek.Value) (*sobek.Promise, error) { + }), + "screenshot": passiveCall(func(opts sobek.Value) (*sobek.Promise, error) { popts, err := parseElementHandleScreenshotOptions(rt, opts, eh.Timeout()) if err != nil { return nil, fmt.Errorf("parsing element handle screenshot options: %w", err) @@ -193,8 +193,8 @@ func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint: return &ab, nil }), nil - }, - "scrollIntoViewIfNeeded": func(opts sobek.Value) (*sobek.Promise, error) { + }), + "scrollIntoViewIfNeeded": passiveCall(func(opts sobek.Value) (*sobek.Promise, error) { popts := common.NewElementHandleBaseOptions(eh.DefaultTimeout()) if err := parseElementHandleBaseOptions(popts, rt, opts); err != nil { return nil, fmt.Errorf("parsing scrollIntoViewIfNeeded options: %w", err) @@ -202,8 +202,8 @@ func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint: return promise(vu, func() (any, error) { return nil, eh.ScrollIntoViewIfNeeded(popts) //nolint:wrapcheck }), nil - }, - "selectOption": func(values sobek.Value, opts sobek.Value) (*sobek.Promise, error) { + }), + "selectOption": networkCall(func(values sobek.Value, opts sobek.Value) (*sobek.Promise, error) { convValues, err := ConvertSelectOptionValues(vu.Runtime(), values) if err != nil { return nil, fmt.Errorf("parsing select options values: %w", err) @@ -215,8 +215,8 @@ func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint: return promise(vu, func() (any, error) { return eh.SelectOption(convValues, popts) //nolint:wrapcheck }), nil - }, - "selectText": func(opts sobek.Value) (*sobek.Promise, error) { + }), + "selectText": networkCall(func(opts sobek.Value) (*sobek.Promise, error) { popts := common.NewElementHandleBaseOptions(eh.DefaultTimeout()) if err := parseElementHandleBaseOptions(popts, rt, opts); err != nil { return nil, fmt.Errorf("parsing selectText options: %w", err) @@ -224,8 +224,8 @@ func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint: return promise(vu, func() (any, error) { return nil, eh.SelectText(popts) //nolint:wrapcheck }), nil - }, - "setChecked": func(checked bool, opts sobek.Value) (*sobek.Promise, error) { + }), + "setChecked": networkCall(func(checked bool, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseElementHandleSetCheckedOptions(rt, opts, eh.DefaultTimeout()) if err != nil { return nil, fmt.Errorf("parsing setChecked options: %w", err) @@ -233,8 +233,8 @@ func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint: return promise(vu, func() (any, error) { return nil, eh.SetChecked(checked, popts) //nolint:wrapcheck }), nil - }, - "setInputFiles": func(files sobek.Value, opts sobek.Value) (*sobek.Promise, error) { + }), + "setInputFiles": networkCall(func(files sobek.Value, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseElementHandleSetInputFilesOptions(rt, opts, eh.DefaultTimeout()) if err != nil { return nil, fmt.Errorf("parsing setInputFiles options: %w", err) @@ -246,8 +246,8 @@ func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint: return promise(vu, func() (any, error) { return nil, eh.SetInputFiles(&pfiles, popts) //nolint:wrapcheck }), nil - }, - "tap": func(opts sobek.Value) (*sobek.Promise, error) { + }), + "tap": networkCall(func(opts sobek.Value) (*sobek.Promise, error) { popts, err := parseElementHandleTapOptions(rt, opts, eh.Timeout()) if err != nil { return nil, fmt.Errorf("parsing element tap options: %w", err) @@ -255,8 +255,8 @@ func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint: return promise(vu, func() (any, error) { return nil, eh.Tap(popts) //nolint:wrapcheck }), nil - }, - "textContent": func() *sobek.Promise { + }), + "textContent": passiveCall(func() *sobek.Promise { return promise(vu, func() (any, error) { s, ok, err := eh.TextContent() if err != nil { @@ -267,8 +267,8 @@ func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint: } return s, nil }) - }, - "type": func(text string, opts sobek.Value) (*sobek.Promise, error) { + }), + "type": networkCall(func(text string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseElementHandleTypeOptions(rt, opts, eh.DefaultTimeout()) if err != nil { return nil, fmt.Errorf("parsing type options: %w", err) @@ -276,8 +276,8 @@ func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint: return promise(vu, func() (any, error) { return nil, eh.Type(text, popts) //nolint:wrapcheck }), nil - }, - "uncheck": func(opts sobek.Value) (*sobek.Promise, error) { + }), + "uncheck": networkCall(func(opts sobek.Value) (*sobek.Promise, error) { popts, err := parseElementHandleSetCheckedOptions(rt, opts, eh.DefaultTimeout()) if err != nil { return nil, fmt.Errorf("parsing uncheck options: %w", err) @@ -285,8 +285,8 @@ func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint: return promise(vu, func() (any, error) { return nil, eh.Uncheck(popts) //nolint:wrapcheck }), nil - }, - "waitForElementState": func(state string, opts sobek.Value) (*sobek.Promise, error) { + }), + "waitForElementState": passiveCall(func(state string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseElementHandleWaitForElementStateOptions(rt, opts, eh.DefaultTimeout()) if err != nil { return nil, fmt.Errorf("parsing waitForElementState options: %w", err) @@ -294,8 +294,8 @@ func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint: return promise(vu, func() (any, error) { return nil, eh.WaitForElementState(state, popts) //nolint:wrapcheck }), nil - }, - "waitForSelector": func(selector string, opts sobek.Value) (*sobek.Promise, error) { + }), + "waitForSelector": passiveCall(func(selector string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameWaitForSelectorOptions(rt, opts, eh.DefaultTimeout()) if err != nil { return nil, fmt.Errorf("parsing waitForSelector %q options: %w", selector, err) @@ -307,9 +307,9 @@ func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint: } return mapElementHandle(vu, eh), nil }), nil - }, + }), } - maps["$"] = func(selector string) *sobek.Promise { + maps["$"] = passiveCall(func(selector string) *sobek.Promise { return promise(vu, func() (any, error) { eh, err := eh.Query(selector, common.StrictModeOff) if err != nil { @@ -325,8 +325,8 @@ func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint: return ehm, nil }) - } - maps["$$"] = func(selector string) *sobek.Promise { + }) + maps["$$"] = passiveCall(func(selector string) *sobek.Promise { return promise(vu, func() (any, error) { ehs, err := eh.QueryAll(selector) if err != nil { @@ -339,12 +339,12 @@ func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint: } return mehs, nil }) - } + }) - jsHandleMap := mapJSHandle(vu, eh) + jsHandleMap := newJSHandleMapping(vu, eh) maps0.Copy(maps, jsHandleMap) - return maps + return withPageNetworkCalls(vu, eh.Page(), maps) } // parseElementHandleTypeOptions parses the element handle type options from a Sobek value. diff --git a/internal/js/modules/k6/browser/browser/frame_locator_mapping.go b/internal/js/modules/k6/browser/browser/frame_locator_mapping.go index af6cd224c..dd86aea8d 100644 --- a/internal/js/modules/k6/browser/browser/frame_locator_mapping.go +++ b/internal/js/modules/k6/browser/browser/frame_locator_mapping.go @@ -11,8 +11,8 @@ import ( // mapFrameLocator API to the JS module. func mapFrameLocator(vu moduleVU, fl *common.FrameLocator) mapping { rt := vu.Runtime() - return mapping{ - "getByAltText": func(alt sobek.Value, opts sobek.Value) (*sobek.Object, error) { + return finishMapping(mapping{ + "getByAltText": passiveCall(func(alt sobek.Value, opts sobek.Value) (*sobek.Object, error) { if k6common.IsNullish(alt) { return nil, errors.New("missing required argument 'altText'") } @@ -20,8 +20,8 @@ func mapFrameLocator(vu moduleVU, fl *common.FrameLocator) mapping { ml := mapLocator(vu, fl.GetByAltText(palt, popts)) return rt.ToValue(ml).ToObject(rt), nil - }, - "getByLabel": func(label sobek.Value, opts sobek.Value) (*sobek.Object, error) { + }), + "getByLabel": passiveCall(func(label sobek.Value, opts sobek.Value) (*sobek.Object, error) { if k6common.IsNullish(label) { return nil, errors.New("missing required argument 'label'") } @@ -29,8 +29,8 @@ func mapFrameLocator(vu moduleVU, fl *common.FrameLocator) mapping { ml := mapLocator(vu, fl.GetByLabel(plabel, popts)) return rt.ToValue(ml).ToObject(rt), nil - }, - "getByPlaceholder": func(placeholder sobek.Value, opts sobek.Value) (*sobek.Object, error) { + }), + "getByPlaceholder": passiveCall(func(placeholder sobek.Value, opts sobek.Value) (*sobek.Object, error) { if k6common.IsNullish(placeholder) { return nil, errors.New("missing required argument 'placeholder'") } @@ -38,8 +38,8 @@ func mapFrameLocator(vu moduleVU, fl *common.FrameLocator) mapping { ml := mapLocator(vu, fl.GetByPlaceholder(pplaceholder, popts)) return rt.ToValue(ml).ToObject(rt), nil - }, - "getByRole": func(role sobek.Value, opts sobek.Value) (*sobek.Object, error) { + }), + "getByRole": passiveCall(func(role sobek.Value, opts sobek.Value) (*sobek.Object, error) { if k6common.IsNullish(role) { return nil, errors.New("missing required argument 'role'") } @@ -47,8 +47,8 @@ func mapFrameLocator(vu moduleVU, fl *common.FrameLocator) mapping { ml := mapLocator(vu, fl.GetByRole(role.String(), popts)) return rt.ToValue(ml).ToObject(rt), nil - }, - "getByTestId": func(testID sobek.Value) (*sobek.Object, error) { + }), + "getByTestId": passiveCall(func(testID sobek.Value) (*sobek.Object, error) { if k6common.IsNullish(testID) { return nil, errors.New("missing required argument 'testId'") } @@ -56,8 +56,8 @@ func mapFrameLocator(vu moduleVU, fl *common.FrameLocator) mapping { ml := mapLocator(vu, fl.GetByTestID(ptestID)) return rt.ToValue(ml).ToObject(rt), nil - }, - "getByText": func(text sobek.Value, opts sobek.Value) (*sobek.Object, error) { + }), + "getByText": passiveCall(func(text sobek.Value, opts sobek.Value) (*sobek.Object, error) { if k6common.IsNullish(text) { return nil, errors.New("missing required argument 'text'") } @@ -65,8 +65,8 @@ func mapFrameLocator(vu moduleVU, fl *common.FrameLocator) mapping { ml := mapLocator(vu, fl.GetByText(ptext, popts)) return rt.ToValue(ml).ToObject(rt), nil - }, - "getByTitle": func(title sobek.Value, opts sobek.Value) (*sobek.Object, error) { + }), + "getByTitle": passiveCall(func(title sobek.Value, opts sobek.Value) (*sobek.Object, error) { if k6common.IsNullish(title) { return nil, errors.New("missing required argument 'title'") } @@ -74,13 +74,13 @@ func mapFrameLocator(vu moduleVU, fl *common.FrameLocator) mapping { ml := mapLocator(vu, fl.GetByTitle(ptitle, popts)) return rt.ToValue(ml).ToObject(rt), nil - }, - "locator": func(selector string, opts sobek.Value) mapping { + }), + "locator": passiveCall(func(selector string, opts sobek.Value) mapping { return mapLocator(vu, fl.Locator(selector, parseLocatorOptions(rt, opts))) - }, - "frameLocator": func(selector string) *sobek.Object { + }), + "frameLocator": passiveCall(func(selector string) *sobek.Object { mfl := mapFrameLocator(vu, fl.FrameLocator(selector)) return rt.ToValue(mfl).ToObject(rt) - }, - } + }), + }) } diff --git a/internal/js/modules/k6/browser/browser/frame_mapping.go b/internal/js/modules/k6/browser/browser/frame_mapping.go index 576f3275c..307c57dbc 100644 --- a/internal/js/modules/k6/browser/browser/frame_mapping.go +++ b/internal/js/modules/k6/browser/browser/frame_mapping.go @@ -17,7 +17,7 @@ import ( func mapFrame(vu moduleVU, f *common.Frame) mapping { rt := vu.Runtime() maps := mapping{ - "check": func(selector string, opts sobek.Value) (*sobek.Promise, error) { + "check": networkCall(func(selector string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameCheckOptions(rt, opts, f.Timeout()) if err != nil { return nil, fmt.Errorf("parsing new frame check options: %w", err) @@ -25,16 +25,16 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { return promise(vu, func() (any, error) { return nil, f.Check(selector, popts) //nolint:wrapcheck }), nil - }, - "childFrames": func() []mapping { + }), + "childFrames": passiveCall(func() []mapping { cfs := f.ChildFrames() mcfs := make([]mapping, 0, len(cfs)) for _, fr := range cfs { mcfs = append(mcfs, mapFrame(vu, fr)) } return mcfs - }, - "click": func(selector string, opts sobek.Value) (*sobek.Promise, error) { + }), + "click": networkCall(func(selector string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameClickOptions(rt, opts, f.Timeout()) if err != nil { return nil, err @@ -44,13 +44,13 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { err := f.Click(selector, popts) return nil, err //nolint:wrapcheck }), nil - }, - "content": func() *sobek.Promise { + }), + "content": passiveCall(func() *sobek.Promise { return promise(vu, func() (any, error) { return f.Content() //nolint:wrapcheck }) - }, - "dblclick": func(selector string, opts sobek.Value) (*sobek.Promise, error) { + }), + "dblclick": networkCall(func(selector string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameDblclickOptions(rt, opts, f.Timeout()) if err != nil { return nil, fmt.Errorf("parsing double click options: %w", err) @@ -58,8 +58,8 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { return promise(vu, func() (any, error) { return nil, f.Dblclick(selector, popts) //nolint:wrapcheck }), nil - }, - "dispatchEvent": func(selector, typ string, eventInit, opts sobek.Value) (*sobek.Promise, error) { + }), + "dispatchEvent": networkCall(func(selector, typ string, eventInit, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameDispatchEventOptions(rt, opts, f.Timeout()) if err != nil { return nil, fmt.Errorf("parsing frame dispatch event options: %w", err) @@ -68,8 +68,8 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { return promise(vu, func() (any, error) { return nil, f.DispatchEvent(selector, typ, earg, popts) //nolint:wrapcheck }), nil - }, - "evaluate": func(pageFunc sobek.Value, gargs ...sobek.Value) (*sobek.Promise, error) { + }), + "evaluate": networkCall(func(pageFunc sobek.Value, gargs ...sobek.Value) (*sobek.Promise, error) { if sobekEmptyString(pageFunc) { return nil, fmt.Errorf("evaluate requires a page function") } @@ -78,8 +78,8 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { return promise(vu, func() (any, error) { return f.Evaluate(funcString, gopts...) }), nil - }, - "evaluateHandle": func(pageFunc sobek.Value, gargs ...sobek.Value) (*sobek.Promise, error) { + }), + "evaluateHandle": networkCall(func(pageFunc sobek.Value, gargs ...sobek.Value) (*sobek.Promise, error) { if sobekEmptyString(pageFunc) { return nil, fmt.Errorf("evaluateHandle requires a page function") } @@ -92,8 +92,8 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { } return mapJSHandle(vu, jsh), nil }), nil - }, - "fill": func(selector, value string, opts sobek.Value) (*sobek.Promise, error) { + }), + "fill": networkCall(func(selector, value string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameFillOptions(rt, opts, f.Timeout()) if err != nil { return nil, fmt.Errorf("parsing fill options: %w", err) @@ -101,8 +101,8 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { return promise(vu, func() (any, error) { return nil, f.Fill(selector, value, popts) //nolint:wrapcheck }), nil - }, - "focus": func(selector string, opts sobek.Value) (*sobek.Promise, error) { + }), + "focus": networkCall(func(selector string, opts sobek.Value) (*sobek.Promise, error) { popts := common.NewFrameBaseOptions(f.Timeout()) if err := parseFrameBaseOptions(popts, rt, opts); err != nil { return nil, fmt.Errorf("parsing focus options: %w", err) @@ -110,8 +110,8 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { return promise(vu, func() (any, error) { return nil, f.Focus(selector, popts) //nolint:wrapcheck }), nil - }, - "frameElement": func() *sobek.Promise { + }), + "frameElement": passiveCall(func() *sobek.Promise { return promise(vu, func() (any, error) { fe, err := f.FrameElement() if err != nil { @@ -119,8 +119,8 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { } return mapElementHandle(vu, fe), nil }) - }, - "getAttribute": func(selector, name string, opts sobek.Value) (*sobek.Promise, error) { + }), + "getAttribute": passiveCall(func(selector, name string, opts sobek.Value) (*sobek.Promise, error) { popts := common.NewFrameBaseOptions(f.Timeout()) if err := parseFrameBaseOptions(popts, rt, opts); err != nil { return nil, fmt.Errorf("parsing getAttribute options: %w", err) @@ -135,8 +135,8 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { } return s, nil }), nil - }, - "getByAltText": func(alt sobek.Value, opts sobek.Value) (*sobek.Object, error) { + }), + "getByAltText": passiveCall(func(alt sobek.Value, opts sobek.Value) (*sobek.Object, error) { if k6common.IsNullish(alt) { return nil, errors.New("missing required argument 'altText'") } @@ -144,8 +144,8 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { ml := mapLocator(vu, f.GetByAltText(palt, popts)) return rt.ToValue(ml).ToObject(rt), nil - }, - "getByLabel": func(label sobek.Value, opts sobek.Value) (*sobek.Object, error) { + }), + "getByLabel": passiveCall(func(label sobek.Value, opts sobek.Value) (*sobek.Object, error) { if k6common.IsNullish(label) { return nil, errors.New("missing required argument 'label'") } @@ -153,8 +153,8 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { ml := mapLocator(vu, f.GetByLabel(plabel, popts)) return rt.ToValue(ml).ToObject(rt), nil - }, - "getByPlaceholder": func(placeholder sobek.Value, opts sobek.Value) (*sobek.Object, error) { + }), + "getByPlaceholder": passiveCall(func(placeholder sobek.Value, opts sobek.Value) (*sobek.Object, error) { if k6common.IsNullish(placeholder) { return nil, errors.New("missing required argument 'placeholder'") } @@ -162,8 +162,8 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { ml := mapLocator(vu, f.GetByPlaceholder(pplaceholder, popts)) return rt.ToValue(ml).ToObject(rt), nil - }, - "getByRole": func(role sobek.Value, opts sobek.Value) (*sobek.Object, error) { + }), + "getByRole": passiveCall(func(role sobek.Value, opts sobek.Value) (*sobek.Object, error) { if k6common.IsNullish(role) { return nil, errors.New("missing required argument 'role'") } @@ -171,8 +171,8 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { ml := mapLocator(vu, f.GetByRole(role.String(), popts)) return rt.ToValue(ml).ToObject(rt), nil - }, - "getByTestId": func(testID sobek.Value) (*sobek.Object, error) { + }), + "getByTestId": passiveCall(func(testID sobek.Value) (*sobek.Object, error) { if k6common.IsNullish(testID) { return nil, errors.New("missing required argument 'testId'") } @@ -180,8 +180,8 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { ml := mapLocator(vu, f.GetByTestID(ptestID)) return rt.ToValue(ml).ToObject(rt), nil - }, - "getByText": func(text sobek.Value, opts sobek.Value) (*sobek.Object, error) { + }), + "getByText": passiveCall(func(text sobek.Value, opts sobek.Value) (*sobek.Object, error) { if k6common.IsNullish(text) { return nil, errors.New("missing required argument 'text'") } @@ -189,8 +189,8 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { ml := mapLocator(vu, f.GetByText(ptext, popts)) return rt.ToValue(ml).ToObject(rt), nil - }, - "getByTitle": func(title sobek.Value, opts sobek.Value) (*sobek.Object, error) { + }), + "getByTitle": passiveCall(func(title sobek.Value, opts sobek.Value) (*sobek.Object, error) { if k6common.IsNullish(title) { return nil, errors.New("missing required argument 'title'") } @@ -198,8 +198,8 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { ml := mapLocator(vu, f.GetByTitle(ptitle, popts)) return rt.ToValue(ml).ToObject(rt), nil - }, - "goto": func(url string, opts sobek.Value) (*sobek.Promise, error) { + }), + "goto": networkCall(func(url string, opts sobek.Value) (*sobek.Promise, error) { gopts, err := parseFrameGotoOptions(rt, opts, f.Referrer(), f.NavigationTimeout()) if err != nil { return nil, fmt.Errorf("parsing frame navigation options to %q: %w", url, err) @@ -212,8 +212,8 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { return mapResponse(vu, resp), nil }), nil - }, - "hover": func(selector string, opts sobek.Value) (*sobek.Promise, error) { + }), + "hover": networkCall(func(selector string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameHoverOptions(rt, opts, f.Timeout()) if err != nil { return nil, fmt.Errorf("parsing hover options: %w", err) @@ -221,8 +221,8 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { return promise(vu, func() (any, error) { return nil, f.Hover(selector, popts) //nolint:wrapcheck }), nil - }, - "innerHTML": func(selector string, opts sobek.Value) (*sobek.Promise, error) { + }), + "innerHTML": passiveCall(func(selector string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameInnerHTMLOptions(rt, opts, f.Timeout()) if err != nil { return nil, fmt.Errorf("parsing inner HTML options: %w", err) @@ -230,8 +230,8 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { return promise(vu, func() (any, error) { return f.InnerHTML(selector, popts) //nolint:wrapcheck }), nil - }, - "innerText": func(selector string, opts sobek.Value) (*sobek.Promise, error) { + }), + "innerText": passiveCall(func(selector string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameInnerTextOptions(rt, opts, f.Timeout()) if err != nil { return nil, fmt.Errorf("parsing inner text options: %w", err) @@ -239,8 +239,8 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { return promise(vu, func() (any, error) { return f.InnerText(selector, popts) //nolint:wrapcheck }), nil - }, - "inputValue": func(selector string, opts sobek.Value) (*sobek.Promise, error) { + }), + "inputValue": passiveCall(func(selector string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameInputValueOptions(rt, opts, f.Timeout()) if err != nil { return nil, fmt.Errorf("parsing input value options: %w", err) @@ -248,8 +248,8 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { return promise(vu, func() (any, error) { return f.InputValue(selector, popts) //nolint:wrapcheck }), nil - }, - "isChecked": func(selector string, opts sobek.Value) (*sobek.Promise, error) { + }), + "isChecked": passiveCall(func(selector string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameIsCheckedOptions(rt, opts, f.Timeout()) if err != nil { return nil, fmt.Errorf("parsing isChecked options of selector %q: %w", selector, err) @@ -257,9 +257,9 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { return promise(vu, func() (any, error) { return f.IsChecked(selector, popts) //nolint:wrapcheck }), nil - }, - "isDetached": f.IsDetached, - "isDisabled": func(selector string, opts sobek.Value) (*sobek.Promise, error) { + }), + "isDetached": passiveCall(f.IsDetached), + "isDisabled": passiveCall(func(selector string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameIsDisabledOptions(rt, opts, f.Timeout()) if err != nil { return nil, fmt.Errorf("parsing isDisabled options of selector %q: %w", selector, err) @@ -267,8 +267,8 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { return promise(vu, func() (any, error) { return f.IsDisabled(selector, popts) //nolint:wrapcheck }), nil - }, - "isEditable": func(selector string, opts sobek.Value) (*sobek.Promise, error) { + }), + "isEditable": passiveCall(func(selector string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameIsEditableOptions(rt, opts, f.Timeout()) if err != nil { return nil, fmt.Errorf("parse isEditable options of selector %q: %w", selector, err) @@ -276,8 +276,8 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { return promise(vu, func() (any, error) { return f.IsEditable(selector, popts) //nolint:wrapcheck }), nil - }, - "isEnabled": func(selector string, opts sobek.Value) (*sobek.Promise, error) { + }), + "isEnabled": passiveCall(func(selector string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameIsEnabledOptions(rt, opts, f.Timeout()) if err != nil { return nil, fmt.Errorf("parse isEnabled options of selector %q: %w", selector, err) @@ -285,8 +285,8 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { return promise(vu, func() (any, error) { return f.IsEnabled(selector, popts) //nolint:wrapcheck }), nil - }, - "isHidden": func(selector string, opts sobek.Value) (*sobek.Promise, error) { + }), + "isHidden": passiveCall(func(selector string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameIsHiddenOptions(rt, opts) if err != nil { return nil, fmt.Errorf("parse isHidden options of selector %q: %w", selector, err) @@ -294,8 +294,8 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { return promise(vu, func() (any, error) { return f.IsHidden(selector, popts) //nolint:wrapcheck }), nil - }, - "isVisible": func(selector string, opts sobek.Value) (*sobek.Promise, error) { + }), + "isVisible": passiveCall(func(selector string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameIsVisibleOptions(rt, opts) if err != nil { return nil, fmt.Errorf("parse isVisible options of selector %q: %w", selector, err) @@ -303,22 +303,22 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { return promise(vu, func() (any, error) { return f.IsVisible(selector, popts) //nolint:wrapcheck }), nil - }, - "locator": func(selector string, opts sobek.Value) mapping { + }), + "locator": passiveCall(func(selector string, opts sobek.Value) mapping { return mapLocator(vu, f.Locator(selector, parseLocatorOptions(rt, opts))) - }, - "frameLocator": func(selector string) *sobek.Object { + }), + "frameLocator": passiveCall(func(selector string) *sobek.Object { mfl := mapFrameLocator(vu, f.FrameLocator(selector)) return rt.ToValue(mfl).ToObject(rt) - }, - "name": f.Name, - "page": func() mapping { + }), + "name": passiveCall(f.Name), + "page": passiveCall(func() mapping { return mapPage(vu, f.Page()) - }, - "parentFrame": func() mapping { + }), + "parentFrame": passiveCall(func() mapping { return mapFrame(vu, f.ParentFrame()) - }, - "press": func(selector, key string, opts sobek.Value) (*sobek.Promise, error) { + }), + "press": networkCall(func(selector, key string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFramePressOptions(rt, opts, f.Timeout()) if err != nil { return nil, fmt.Errorf("parse press options of selector %q on key %q: %w", selector, key, err) @@ -326,8 +326,8 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { return promise(vu, func() (any, error) { return nil, f.Press(selector, key, popts) //nolint:wrapcheck }), nil - }, - "selectOption": func(selector string, values sobek.Value, opts sobek.Value) (*sobek.Promise, error) { + }), + "selectOption": networkCall(func(selector string, values sobek.Value, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameSelectOptionOptions(rt, opts, f.Timeout()) if err != nil { return nil, fmt.Errorf("parsing select option options: %w", err) @@ -341,8 +341,8 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { return promise(vu, func() (any, error) { return f.SelectOption(selector, convValues, popts) //nolint:wrapcheck }), nil - }, - "setChecked": func(selector string, checked bool, opts sobek.Value) (*sobek.Promise, error) { + }), + "setChecked": networkCall(func(selector string, checked bool, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameCheckOptions(rt, opts, f.Timeout()) if err != nil { return nil, fmt.Errorf("parsing frame set check options: %w", err) @@ -351,8 +351,8 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { return promise(vu, func() (any, error) { return nil, f.SetChecked(selector, checked, popts) //nolint:wrapcheck }), nil - }, - "setContent": func(html string, opts sobek.Value) (*sobek.Promise, error) { + }), + "setContent": networkCall(func(html string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameSetContentOptions(rt, opts, f.Page().NavigationTimeout()) if err != nil { return nil, fmt.Errorf("parsing setContent options: %w", err) @@ -360,8 +360,8 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { return promise(vu, func() (any, error) { return nil, f.SetContent(html, popts) //nolint:wrapcheck }), nil - }, - "setInputFiles": func(selector string, files sobek.Value, opts sobek.Value) (*sobek.Promise, error) { + }), + "setInputFiles": networkCall(func(selector string, files sobek.Value, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameSetInputFilesOptions(rt, opts, f.Timeout()) if err != nil { return nil, fmt.Errorf("parsing setInputFiles options: %w", err) @@ -375,8 +375,8 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { return promise(vu, func() (any, error) { return nil, f.SetInputFiles(selector, pfiles, popts) //nolint:wrapcheck }), nil - }, - "tap": func(selector string, opts sobek.Value) (*sobek.Promise, error) { + }), + "tap": networkCall(func(selector string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameTapOptions(rt, opts, f.Timeout()) if err != nil { return nil, fmt.Errorf("parsing frame tap options: %w", err) @@ -384,8 +384,8 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { return promise(vu, func() (any, error) { return nil, f.Tap(selector, popts) //nolint:wrapcheck }), nil - }, - "textContent": func(selector string, opts sobek.Value) (*sobek.Promise, error) { + }), + "textContent": passiveCall(func(selector string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameTextContentOptions(rt, opts, f.Timeout()) if err != nil { return nil, fmt.Errorf("parsing text content options: %w", err) @@ -401,13 +401,13 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { } return s, nil }), nil - }, - "title": func() *sobek.Promise { + }), + "title": passiveCall(func() *sobek.Promise { return promise(vu, func() (any, error) { return f.Title() }) - }, - "type": func(selector, text string, opts sobek.Value) (*sobek.Promise, error) { + }), + "type": networkCall(func(selector, text string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameTypeOptions(rt, opts, f.Timeout()) if err != nil { return nil, fmt.Errorf("parsing type options: %w", err) @@ -416,8 +416,8 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { return promise(vu, func() (any, error) { return nil, f.Type(selector, text, popts) //nolint:wrapcheck }), nil - }, - "uncheck": func(selector string, opts sobek.Value) (*sobek.Promise, error) { + }), + "uncheck": networkCall(func(selector string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameUncheckOptions(rt, opts, f.Timeout()) if err != nil { return nil, fmt.Errorf("parsing frame uncheck options %q: %w", selector, err) @@ -426,9 +426,9 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { return promise(vu, func() (any, error) { return nil, f.Uncheck(selector, popts) //nolint:wrapcheck }), nil - }, - "url": f.URL, - "waitForFunction": func(pageFunc, opts sobek.Value, args ...sobek.Value) (*sobek.Promise, error) { + }), + "url": passiveCall(f.URL), + "waitForFunction": networkCall(func(pageFunc, opts sobek.Value, args ...sobek.Value) (*sobek.Promise, error) { js, popts, pargs, err := parseWaitForFunctionArgs( rt, f.Timeout(), pageFunc, opts, args..., ) @@ -439,8 +439,8 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { return promise(vu, func() (result any, reason error) { return f.WaitForFunction(js, popts, pargs...) //nolint:wrapcheck }), nil - }, - "waitForLoadState": func(state string, opts sobek.Value) (*sobek.Promise, error) { + }), + "waitForLoadState": passiveCall(func(state string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameWaitForLoadStateOptions(rt, opts, f.Timeout()) if err != nil { return nil, fmt.Errorf("parsing waitForLoadState %q options: %w", state, err) @@ -449,11 +449,11 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { return promise(vu, func() (any, error) { return nil, f.WaitForLoadState(state, popts) //nolint:wrapcheck }), nil - }, - "waitForNavigation": func(opts sobek.Value) (*sobek.Promise, error) { + }), + "waitForNavigation": passiveCall(func(opts sobek.Value) (*sobek.Promise, error) { return mapWaitForNavigation(rt, vu, f, opts) - }, - "waitForSelector": func(selector string, opts sobek.Value) (*sobek.Promise, error) { + }), + "waitForSelector": passiveCall(func(selector string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameWaitForSelectorOptions(rt, opts, f.Timeout()) if err != nil { return nil, fmt.Errorf("parsing wait for selector %q options: %w", selector, err) @@ -466,18 +466,18 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { } return mapElementHandle(vu, eh), nil }), nil - }, - "waitForTimeout": func(timeout int64) *sobek.Promise { + }), + "waitForTimeout": passiveCall(func(timeout int64) *sobek.Promise { return promise(vu, func() (any, error) { f.WaitForTimeout(timeout) return nil, nil }) - }, - "waitForURL": func(url sobek.Value, opts sobek.Value) (*sobek.Promise, error) { + }), + "waitForURL": passiveCall(func(url sobek.Value, opts sobek.Value) (*sobek.Promise, error) { return mapWaitForURL(rt, vu, f, url, opts) - }, + }), } - maps["$"] = func(selector string) *sobek.Promise { + maps["$"] = passiveCall(func(selector string) *sobek.Promise { return promise(vu, func() (any, error) { eh, err := f.Query(selector, common.StrictModeOff) if err != nil { @@ -493,8 +493,8 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { return ehm, nil }) - } - maps["$$"] = func(selector string) *sobek.Promise { + }) + maps["$$"] = passiveCall(func(selector string) *sobek.Promise { return promise(vu, func() (any, error) { ehs, err := f.QueryAll(selector) if err != nil { @@ -507,9 +507,9 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { } return mehs, nil }) - } + }) - return maps + return withPageNetworkCalls(vu, f.Page(), maps) } // parseFrameCheckOptions parses the frame check options from a Sobek value. diff --git a/internal/js/modules/k6/browser/browser/helpers.go b/internal/js/modules/k6/browser/browser/helpers.go index 375c254a3..dc58dca2b 100644 --- a/internal/js/modules/k6/browser/browser/helpers.go +++ b/internal/js/modules/k6/browser/browser/helpers.go @@ -131,6 +131,17 @@ func queueTask[T any]( } } +func queueTaskWithMetricContext[T any]( + ctx context.Context, + tq *taskqueue.TaskQueue, + captured k6common.CapturedMetricContext, + fn func() (T, error), +) (future func() (T, error)) { + return queueTask(ctx, tq, func() (T, error) { + return k6common.RunWithMetricContext(captured, fn) + }) +} + // newTaskQueue returns a new [taskqueue.TaskQueue] that is closed after // the returned cancel function is called or when the VU's context is done. // diff --git a/internal/js/modules/k6/browser/browser/js_handle_mapping.go b/internal/js/modules/k6/browser/browser/js_handle_mapping.go index bf3149f23..55b081245 100644 --- a/internal/js/modules/k6/browser/browser/js_handle_mapping.go +++ b/internal/js/modules/k6/browser/browser/js_handle_mapping.go @@ -10,16 +10,31 @@ import ( // mapJSHandle to the JS module. func mapJSHandle(vu moduleVU, jsh common.JSHandleAPI) mapping { + // Register network operations against the handle's owning page so that + // network-classified calls (evaluate/evaluateHandle) invoked directly on a + // standalone handle are attributed like they are on element handles. Page() + // is not part of the JS-facing JSHandleAPI, so reach it via the concrete + // implementations (BaseJSHandle/ElementHandle). It is nil for worker or + // isolated-world handles, in which case withPageNetworkCalls falls back to + // finishing the mapping without a network-operation begin. + var page *common.Page + if ph, ok := jsh.(interface{ Page() *common.Page }); ok { + page = ph.Page() + } + return withPageNetworkCalls(vu, page, newJSHandleMapping(vu, jsh)) +} + +func newJSHandleMapping(vu moduleVU, jsh common.JSHandleAPI) mapping { return mapping{ - "asElement": func() mapping { + "asElement": passiveCall(func() mapping { return mapElementHandle(vu, jsh.AsElement()) - }, - "dispose": func() *sobek.Promise { + }), + "dispose": passiveCall(func() *sobek.Promise { return promise(vu, func() (any, error) { return nil, jsh.Dispose() }) - }, - "evaluate": func(pageFunc sobek.Value, gargs ...sobek.Value) (*sobek.Promise, error) { + }), + "evaluate": networkCall(func(pageFunc sobek.Value, gargs ...sobek.Value) (*sobek.Promise, error) { if sobekEmptyString(pageFunc) { return nil, fmt.Errorf("evaluate requires a page function") } @@ -28,8 +43,8 @@ func mapJSHandle(vu moduleVU, jsh common.JSHandleAPI) mapping { return promise(vu, func() (any, error) { return jsh.Evaluate(funcString, gopts...) }), nil - }, - "evaluateHandle": func(pageFunc sobek.Value, gargs ...sobek.Value) (*sobek.Promise, error) { + }), + "evaluateHandle": networkCall(func(pageFunc sobek.Value, gargs ...sobek.Value) (*sobek.Promise, error) { if sobekEmptyString(pageFunc) { return nil, fmt.Errorf("evaluateHandle requires a page function") } @@ -42,8 +57,8 @@ func mapJSHandle(vu moduleVU, jsh common.JSHandleAPI) mapping { } return mapJSHandle(vu, h), nil }), nil - }, - "getProperties": func() *sobek.Promise { + }), + "getProperties": passiveCall(func() *sobek.Promise { return promise(vu, func() (any, error) { props, err := jsh.GetProperties() if err != nil { @@ -56,11 +71,11 @@ func mapJSHandle(vu moduleVU, jsh common.JSHandleAPI) mapping { } return dst, nil }) - }, - "jsonValue": func() *sobek.Promise { + }), + "jsonValue": passiveCall(func() *sobek.Promise { return promise(vu, func() (any, error) { return jsh.JSONValue() //nolint:wrapcheck }) - }, + }), } } diff --git a/internal/js/modules/k6/browser/browser/keyboard_mapping.go b/internal/js/modules/k6/browser/browser/keyboard_mapping.go index 1ae0fdb57..bc1be9c7a 100644 --- a/internal/js/modules/k6/browser/browser/keyboard_mapping.go +++ b/internal/js/modules/k6/browser/browser/keyboard_mapping.go @@ -9,18 +9,22 @@ import ( ) func mapKeyboard(vu moduleVU, kb *common.Keyboard) mapping { + return finishMapping(newKeyboardMapping(vu, kb)) +} + +func newKeyboardMapping(vu moduleVU, kb *common.Keyboard) mapping { return mapping{ - "down": func(key string) *sobek.Promise { + "down": networkCall(func(key string) *sobek.Promise { return promise(vu, func() (any, error) { return nil, kb.Down(key) //nolint:wrapcheck }) - }, - "up": func(key string) *sobek.Promise { + }), + "up": networkCall(func(key string) *sobek.Promise { return promise(vu, func() (any, error) { return nil, kb.Up(key) //nolint:wrapcheck }) - }, - "press": func(key string, opts sobek.Value) (*sobek.Promise, error) { + }), + "press": networkCall(func(key string, opts sobek.Value) (*sobek.Promise, error) { kbopts, err := exportTo[common.KeyboardOptions](vu.Runtime(), opts) if err != nil { return nil, fmt.Errorf("parsing keyboard options: %w", err) @@ -28,8 +32,8 @@ func mapKeyboard(vu moduleVU, kb *common.Keyboard) mapping { return promise(vu, func() (any, error) { return nil, kb.Press(key, kbopts) }), nil - }, - "type": func(text string, opts sobek.Value) (*sobek.Promise, error) { + }), + "type": networkCall(func(text string, opts sobek.Value) (*sobek.Promise, error) { kbopts, err := exportTo[common.KeyboardOptions](vu.Runtime(), opts) if err != nil { return nil, fmt.Errorf("parsing keyboard options: %w", err) @@ -37,11 +41,11 @@ func mapKeyboard(vu moduleVU, kb *common.Keyboard) mapping { return promise(vu, func() (any, error) { return nil, kb.Type(text, kbopts) }), nil - }, - "insertText": func(text string) *sobek.Promise { + }), + "insertText": networkCall(func(text string) *sobek.Promise { return promise(vu, func() (any, error) { return nil, kb.InsertText(text) //nolint:wrapcheck }) - }, + }), } } diff --git a/internal/js/modules/k6/browser/browser/locator_mapping.go b/internal/js/modules/k6/browser/browser/locator_mapping.go index 51b2442e7..57a7564bc 100644 --- a/internal/js/modules/k6/browser/browser/locator_mapping.go +++ b/internal/js/modules/k6/browser/browser/locator_mapping.go @@ -16,8 +16,8 @@ import ( //nolint:gocognit,funlen,cyclop func mapLocator(vu moduleVU, lo *common.Locator) mapping { rt := vu.Runtime() - return mapping{ - "all": func() *sobek.Promise { + maps := mapping{ + "all": passiveCall(func() *sobek.Promise { return promise(vu, func() (any, error) { all, err := lo.All() if err != nil { @@ -30,8 +30,8 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { } return res, nil }) - }, - "boundingBox": func(opts sobek.Value) (*sobek.Promise, error) { + }), + "boundingBox": passiveCall(func(opts sobek.Value) (*sobek.Promise, error) { popts := common.NewFrameBaseOptions(lo.Timeout()) if err := parseFrameBaseOptions(popts, rt, opts); err != nil { return nil, fmt.Errorf("parsing locator bounding box options: %w", err) @@ -41,12 +41,12 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { // We want to avoid errors when an element is not visible or detached and instead // opt to return a nil rectangle -- this matches Playwright's behaviour. if errors.Is(err, common.ErrElementNotVisible) || errors.Is(err, common.ErrElementNotAttachedToDOM) { - return nil, nil + return nil, nil //nolint:nilnil // Absence maps to JavaScript null. } return box, err }), nil - }, - "clear": func(opts sobek.Value) (*sobek.Promise, error) { + }), + "clear": networkCall(func(opts sobek.Value) (*sobek.Promise, error) { copts, err := parseFrameFillOptions(rt, opts, lo.Timeout()) if err != nil { return nil, fmt.Errorf("parsing clear options: %w", err) @@ -54,8 +54,8 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { return promise(vu, func() (any, error) { return nil, lo.Clear(copts) //nolint:wrapcheck }), nil - }, - "click": func(opts sobek.Value) (*sobek.Promise, error) { + }), + "click": networkCall(func(opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameClickOptions(rt, opts, lo.Timeout()) if err != nil { return nil, err @@ -64,17 +64,17 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { return promise(vu, func() (any, error) { return nil, lo.Click(popts) //nolint:wrapcheck }), nil - }, - "contentFrame": func() *sobek.Object { + }), + "contentFrame": passiveCall(func() *sobek.Object { ml := mapFrameLocator(vu, lo.ContentFrame()) return rt.ToValue(ml).ToObject(rt) - }, - "count": func() *sobek.Promise { + }), + "count": passiveCall(func() *sobek.Promise { return promise(vu, func() (any, error) { return lo.Count() //nolint:wrapcheck }) - }, - "dblclick": func(opts sobek.Value) (*sobek.Promise, error) { + }), + "dblclick": networkCall(func(opts sobek.Value) (*sobek.Promise, error) { copts, err := parseFrameDblclickOptions(rt, opts, lo.Timeout()) if err != nil { return nil, fmt.Errorf("parsing double click options: %w", err) @@ -82,8 +82,8 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { return promise(vu, func() (any, error) { return nil, lo.Dblclick(copts) //nolint:wrapcheck }), nil - }, - "evaluate": func(pageFunc sobek.Value, gargs ...sobek.Value) (*sobek.Promise, error) { + }), + "evaluate": networkCall(func(pageFunc sobek.Value, gargs ...sobek.Value) (*sobek.Promise, error) { if sobekEmptyString(pageFunc) { return nil, fmt.Errorf("evaluate requires a page function") } @@ -92,8 +92,8 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { return promise(vu, func() (any, error) { return lo.Evaluate(funcString, gopts...) }), nil - }, - "evaluateHandle": func(pageFunc sobek.Value, gargs ...sobek.Value) (*sobek.Promise, error) { + }), + "evaluateHandle": networkCall(func(pageFunc sobek.Value, gargs ...sobek.Value) (*sobek.Promise, error) { if sobekEmptyString(pageFunc) { return nil, fmt.Errorf("evaluateHandle requires a page function") } @@ -106,8 +106,8 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { } return mapJSHandle(vu, jsh), nil }), nil - }, - "setChecked": func(checked bool, opts sobek.Value) (*sobek.Promise, error) { + }), + "setChecked": networkCall(func(checked bool, opts sobek.Value) (*sobek.Promise, error) { copts, err := parseFrameCheckOptions(rt, opts, lo.Timeout()) if err != nil { return nil, fmt.Errorf("parsing set checked options: %w", err) @@ -115,8 +115,8 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { return promise(vu, func() (any, error) { return nil, lo.SetChecked(checked, copts) //nolint:wrapcheck }), nil - }, - "check": func(opts sobek.Value) (*sobek.Promise, error) { + }), + "check": networkCall(func(opts sobek.Value) (*sobek.Promise, error) { copts, err := parseFrameCheckOptions(rt, opts, lo.Timeout()) if err != nil { return nil, fmt.Errorf("parsing check options: %w", err) @@ -124,8 +124,8 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { return promise(vu, func() (any, error) { return nil, lo.Check(copts) //nolint:wrapcheck }), nil - }, - "uncheck": func(opts sobek.Value) (*sobek.Promise, error) { + }), + "uncheck": networkCall(func(opts sobek.Value) (*sobek.Promise, error) { copts, err := parseFrameUncheckOptions(rt, opts, lo.Timeout()) if err != nil { return nil, fmt.Errorf("parsing uncheck options: %w", err) @@ -133,8 +133,8 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { return promise(vu, func() (any, error) { return nil, lo.Uncheck(copts) //nolint:wrapcheck }), nil - }, - "isChecked": func(opts sobek.Value) (*sobek.Promise, error) { + }), + "isChecked": passiveCall(func(opts sobek.Value) (*sobek.Promise, error) { copts, err := parseFrameIsCheckedOptions(rt, opts, lo.Timeout()) if err != nil { return nil, fmt.Errorf("parsing is checked options: %w", err) @@ -142,8 +142,8 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { return promise(vu, func() (any, error) { return lo.IsChecked(copts) //nolint:wrapcheck }), nil - }, - "isEditable": func(opts sobek.Value) (*sobek.Promise, error) { + }), + "isEditable": passiveCall(func(opts sobek.Value) (*sobek.Promise, error) { copts, err := parseFrameIsEditableOptions(rt, opts, lo.Timeout()) if err != nil { return nil, fmt.Errorf("parsing is editable options: %w", err) @@ -151,8 +151,8 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { return promise(vu, func() (any, error) { return lo.IsEditable(copts) //nolint:wrapcheck }), nil - }, - "isEnabled": func(opts sobek.Value) (*sobek.Promise, error) { + }), + "isEnabled": passiveCall(func(opts sobek.Value) (*sobek.Promise, error) { copts, err := parseFrameIsEnabledOptions(rt, opts, lo.Timeout()) if err != nil { return nil, fmt.Errorf("parsing is enabled options: %w", err) @@ -160,8 +160,8 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { return promise(vu, func() (any, error) { return lo.IsEnabled(copts) //nolint:wrapcheck }), nil - }, - "isDisabled": func(opts sobek.Value) (*sobek.Promise, error) { + }), + "isDisabled": passiveCall(func(opts sobek.Value) (*sobek.Promise, error) { copts, err := parseFrameIsDisabledOptions(rt, opts, lo.Timeout()) if err != nil { return nil, fmt.Errorf("parsing is disabled options: %w", err) @@ -169,8 +169,8 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { return promise(vu, func() (any, error) { return lo.IsDisabled(copts) //nolint:wrapcheck }), nil - }, - "isInViewport": func(opts sobek.Value) (*sobek.Promise, error) { + }), + "isInViewport": passiveCall(func(opts sobek.Value) (*sobek.Promise, error) { copts, err := parseFrameIsInViewportOptions(rt, opts, lo.Timeout()) if err != nil { return nil, fmt.Errorf("parsing is in viewport options: %w", err) @@ -178,18 +178,18 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { return promise(vu, func() (any, error) { return lo.IsInViewport(copts) //nolint:wrapcheck }), nil - }, - "isVisible": func() *sobek.Promise { + }), + "isVisible": passiveCall(func() *sobek.Promise { return promise(vu, func() (any, error) { return lo.IsVisible() //nolint:wrapcheck }) - }, - "isHidden": func() *sobek.Promise { + }), + "isHidden": passiveCall(func() *sobek.Promise { return promise(vu, func() (any, error) { return lo.IsHidden() //nolint:wrapcheck }) - }, - "fill": func(value string, opts sobek.Value) (*sobek.Promise, error) { + }), + "fill": networkCall(func(value string, opts sobek.Value) (*sobek.Promise, error) { copts, err := parseFrameFillOptions(rt, opts, lo.Timeout()) if err != nil { return nil, fmt.Errorf("parsing fill options: %w", err) @@ -197,17 +197,17 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { return promise(vu, func() (any, error) { return nil, lo.Fill(value, copts) //nolint:wrapcheck }), nil - }, - "filter": func(opts sobek.Value) mapping { + }), + "filter": passiveCall(func(opts sobek.Value) mapping { return mapLocator(vu, lo.Filter(&common.LocatorFilterOptions{ LocatorOptions: parseLocatorOptions(rt, opts), })) - }, - "first": func() *sobek.Object { + }), + "first": passiveCall(func() *sobek.Object { ml := mapLocator(vu, lo.First()) return rt.ToValue(ml).ToObject(rt) - }, - "focus": func(opts sobek.Value) (*sobek.Promise, error) { + }), + "focus": networkCall(func(opts sobek.Value) (*sobek.Promise, error) { copts := common.NewFrameBaseOptions(lo.Timeout()) if err := parseFrameBaseOptions(copts, rt, opts); err != nil { return nil, fmt.Errorf("parsing focus options: %w", err) @@ -215,8 +215,8 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { return promise(vu, func() (any, error) { return nil, lo.Focus(copts) //nolint:wrapcheck }), nil - }, - "getAttribute": func(name string, opts sobek.Value) (*sobek.Promise, error) { + }), + "getAttribute": passiveCall(func(name string, opts sobek.Value) (*sobek.Promise, error) { copts := common.NewFrameBaseOptions(lo.Timeout()) if err := parseFrameBaseOptions(copts, rt, opts); err != nil { return nil, fmt.Errorf("parsing get attribute options: %w", err) @@ -227,12 +227,12 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { return nil, err //nolint:wrapcheck } if !ok { - return nil, nil + return nil, nil //nolint:nilnil // Absence maps to JavaScript null. } return s, nil }), nil - }, - "getByAltText": func(alt sobek.Value, opts sobek.Value) (*sobek.Object, error) { + }), + "getByAltText": passiveCall(func(alt sobek.Value, opts sobek.Value) (*sobek.Object, error) { if k6common.IsNullish(alt) { return nil, errors.New("missing required argument 'altText'") } @@ -240,8 +240,8 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { ml := mapLocator(vu, lo.GetByAltText(palt, popts)) return rt.ToValue(ml).ToObject(rt), nil - }, - "getByLabel": func(label sobek.Value, opts sobek.Value) (*sobek.Object, error) { + }), + "getByLabel": passiveCall(func(label sobek.Value, opts sobek.Value) (*sobek.Object, error) { if k6common.IsNullish(label) { return nil, errors.New("missing required argument 'label'") } @@ -249,8 +249,8 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { ml := mapLocator(vu, lo.GetByLabel(plabel, popts)) return rt.ToValue(ml).ToObject(rt), nil - }, - "getByPlaceholder": func(placeholder sobek.Value, opts sobek.Value) (*sobek.Object, error) { + }), + "getByPlaceholder": passiveCall(func(placeholder sobek.Value, opts sobek.Value) (*sobek.Object, error) { if k6common.IsNullish(placeholder) { return nil, errors.New("missing required argument 'placeholder'") } @@ -258,8 +258,8 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { ml := mapLocator(vu, lo.GetByPlaceholder(pplaceholder, popts)) return rt.ToValue(ml).ToObject(rt), nil - }, - "getByRole": func(role sobek.Value, opts sobek.Value) (*sobek.Object, error) { + }), + "getByRole": passiveCall(func(role sobek.Value, opts sobek.Value) (*sobek.Object, error) { if k6common.IsNullish(role) { return nil, errors.New("missing required argument 'role'") } @@ -267,8 +267,8 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { ml := mapLocator(vu, lo.GetByRole(role.String(), popts)) return rt.ToValue(ml).ToObject(rt), nil - }, - "getByTestId": func(testID sobek.Value) (*sobek.Object, error) { + }), + "getByTestId": passiveCall(func(testID sobek.Value) (*sobek.Object, error) { if k6common.IsNullish(testID) { return nil, errors.New("missing required argument 'testId'") } @@ -276,8 +276,8 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { ml := mapLocator(vu, lo.GetByTestID(ptestID)) return rt.ToValue(ml).ToObject(rt), nil - }, - "getByText": func(text sobek.Value, opts sobek.Value) (*sobek.Object, error) { + }), + "getByText": passiveCall(func(text sobek.Value, opts sobek.Value) (*sobek.Object, error) { if k6common.IsNullish(text) { return nil, errors.New("missing required argument 'text'") } @@ -285,8 +285,8 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { ml := mapLocator(vu, lo.GetByText(ptext, popts)) return rt.ToValue(ml).ToObject(rt), nil - }, - "getByTitle": func(title sobek.Value, opts sobek.Value) (*sobek.Object, error) { + }), + "getByTitle": passiveCall(func(title sobek.Value, opts sobek.Value) (*sobek.Object, error) { if k6common.IsNullish(title) { return nil, errors.New("missing required argument 'title'") } @@ -294,15 +294,15 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { ml := mapLocator(vu, lo.GetByTitle(ptitle, popts)) return rt.ToValue(ml).ToObject(rt), nil - }, - "locator": func(selector string, opts sobek.Value) mapping { + }), + "locator": passiveCall(func(selector string, opts sobek.Value) mapping { return mapLocator(vu, lo.Locator(selector, parseLocatorOptions(rt, opts))) - }, - "frameLocator": func(selector string) *sobek.Object { + }), + "frameLocator": passiveCall(func(selector string) *sobek.Object { mfl := mapFrameLocator(vu, lo.FrameLocator(selector)) return rt.ToValue(mfl).ToObject(rt) - }, - "innerHTML": func(opts sobek.Value) (*sobek.Promise, error) { + }), + "innerHTML": passiveCall(func(opts sobek.Value) (*sobek.Promise, error) { copts, err := parseFrameInnerHTMLOptions(rt, opts, lo.Timeout()) if err != nil { return nil, fmt.Errorf("parsing inner HTML options: %w", err) @@ -310,8 +310,8 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { return promise(vu, func() (any, error) { return lo.InnerHTML(copts) //nolint:wrapcheck }), nil - }, - "innerText": func(opts sobek.Value) (*sobek.Promise, error) { + }), + "innerText": passiveCall(func(opts sobek.Value) (*sobek.Promise, error) { copts, err := parseFrameInnerTextOptions(rt, opts, lo.Timeout()) if err != nil { return nil, fmt.Errorf("parsing inner text options: %w", err) @@ -319,16 +319,16 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { return promise(vu, func() (any, error) { return lo.InnerText(copts) //nolint:wrapcheck }), nil - }, - "last": func() *sobek.Object { + }), + "last": passiveCall(func() *sobek.Object { ml := mapLocator(vu, lo.Last()) return rt.ToValue(ml).ToObject(rt) - }, - "nth": func(nth int) *sobek.Object { + }), + "nth": passiveCall(func(nth int) *sobek.Object { ml := mapLocator(vu, lo.Nth(nth)) return rt.ToValue(ml).ToObject(rt) - }, - "textContent": func(opts sobek.Value) (*sobek.Promise, error) { + }), + "textContent": passiveCall(func(opts sobek.Value) (*sobek.Promise, error) { copts, err := parseFrameTextContentOptions(rt, opts, lo.Timeout()) if err != nil { return nil, fmt.Errorf("parsing text content options: %w", err) @@ -339,12 +339,12 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { return nil, err //nolint:wrapcheck } if !ok { - return nil, nil + return nil, nil //nolint:nilnil // Absence maps to JavaScript null. } return s, nil }), nil - }, - "inputValue": func(opts sobek.Value) (*sobek.Promise, error) { + }), + "inputValue": passiveCall(func(opts sobek.Value) (*sobek.Promise, error) { copts, err := parseFrameInputValueOptions(rt, opts, lo.Timeout()) if err != nil { return nil, fmt.Errorf("parsing input value options: %w", err) @@ -352,8 +352,8 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { return promise(vu, func() (any, error) { return lo.InputValue(copts) //nolint:wrapcheck }), nil - }, - "selectOption": func(values sobek.Value, opts sobek.Value) (*sobek.Promise, error) { + }), + "selectOption": networkCall(func(values sobek.Value, opts sobek.Value) (*sobek.Promise, error) { copts, err := parseFrameSelectOptionOptions(rt, opts, lo.Timeout()) if err != nil { return nil, fmt.Errorf("parsing select option options: %w", err) @@ -365,8 +365,8 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { return promise(vu, func() (any, error) { return lo.SelectOption(convValues, copts) //nolint:wrapcheck }), nil - }, - "press": func(key string, opts sobek.Value) (*sobek.Promise, error) { + }), + "press": networkCall(func(key string, opts sobek.Value) (*sobek.Promise, error) { copts, err := parseFramePressOptions(rt, opts, lo.Timeout()) if err != nil { return nil, fmt.Errorf("parsing press options: %w", err) @@ -374,9 +374,9 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { return promise(vu, func() (any, error) { return nil, lo.Press(key, copts) //nolint:wrapcheck }), nil - }, + }), - "pressSequentially": func(text string, opts sobek.Value) (*sobek.Promise, error) { + "pressSequentially": networkCall(func(text string, opts sobek.Value) (*sobek.Promise, error) { copts, err := parseFrameTypeOptions(rt, opts, lo.Timeout()) if err != nil { return nil, fmt.Errorf("parsing locator press sequentially options: %w", err) @@ -384,9 +384,9 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { return promise(vu, func() (any, error) { return nil, lo.PressSequentially(text, copts) //nolint:wrapcheck }), nil - }, + }), - "type": func(text string, opts sobek.Value) (*sobek.Promise, error) { + "type": networkCall(func(text string, opts sobek.Value) (*sobek.Promise, error) { copts, err := parseFrameTypeOptions(rt, opts, lo.Timeout()) if err != nil { return nil, fmt.Errorf("parsing type options: %w", err) @@ -394,8 +394,8 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { return promise(vu, func() (any, error) { return nil, lo.Type(text, copts) //nolint:wrapcheck }), nil - }, - "hover": func(opts sobek.Value) (*sobek.Promise, error) { + }), + "hover": networkCall(func(opts sobek.Value) (*sobek.Promise, error) { copts, err := parseFrameHoverOptions(rt, opts, lo.Timeout()) if err != nil { return nil, fmt.Errorf("parsing hover options: %w", err) @@ -403,8 +403,8 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { return promise(vu, func() (any, error) { return nil, lo.Hover(copts) //nolint:wrapcheck }), nil - }, - "tap": func(opts sobek.Value) (*sobek.Promise, error) { + }), + "tap": networkCall(func(opts sobek.Value) (*sobek.Promise, error) { copts, err := parseFrameTapOptions(rt, opts, lo.DefaultTimeout()) if err != nil { return nil, fmt.Errorf("parsing locator tap options: %w", err) @@ -412,8 +412,8 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { return promise(vu, func() (any, error) { return nil, lo.Tap(copts) //nolint:wrapcheck }), nil - }, - "dispatchEvent": func(typ string, eventInit, opts sobek.Value) (*sobek.Promise, error) { + }), + "dispatchEvent": networkCall(func(typ string, eventInit, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameDispatchEventOptions(rt, opts, lo.DefaultTimeout()) if err != nil { return nil, fmt.Errorf("parsing locator dispatch event options: %w", err) @@ -421,8 +421,8 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { return promise(vu, func() (any, error) { return nil, lo.DispatchEvent(typ, exportArg(eventInit), popts) //nolint:wrapcheck }), nil - }, - "waitFor": func(opts sobek.Value) (*sobek.Promise, error) { + }), + "waitFor": passiveCall(func(opts sobek.Value) (*sobek.Promise, error) { copts, err := parseFrameWaitForSelectorOptions(rt, opts, lo.Timeout()) if err != nil { return nil, fmt.Errorf("parsing wait for options: %w", err) @@ -430,8 +430,9 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { return promise(vu, func() (any, error) { return nil, lo.WaitFor(copts) //nolint:wrapcheck }), nil - }, + }), } + return withPageNetworkCalls(vu, lo.Page(), maps) } func parseLocatorOptions(rt *sobek.Runtime, opts sobek.Value) *common.LocatorOptions { diff --git a/internal/js/modules/k6/browser/browser/mapping.go b/internal/js/modules/k6/browser/browser/mapping.go index cc58fa71f..202db5d66 100644 --- a/internal/js/modules/k6/browser/browser/mapping.go +++ b/internal/js/modules/k6/browser/browser/mapping.go @@ -3,6 +3,7 @@ package browser import ( "fmt" "reflect" + "sync" "time" "github.com/grafana/sobek" @@ -18,6 +19,199 @@ import ( // and customization over our API. type mapping = map[string]any +type mappingCallKind uint8 + +const ( + mappingCallPassive mappingCallKind = iota + 1 + mappingCallNetwork +) + +type mappingCall struct { + fn any + kind mappingCallKind +} + +// Browser requests can arrive after the mapped call that initiated them settles. Requiring every +// callable to choose a kind prevents a passive waiter from silently becoming a competing operation. +func passiveCall(fn any) mappingCall { + return mappingCall{fn: fn, kind: mappingCallPassive} +} + +func networkCall(fn any) mappingCall { + return mappingCall{fn: fn, kind: mappingCallNetwork} +} + +func finishMapping(m mapping) mapping { + return finishMappingCalls(moduleVU{}, m, nil, "") +} + +func withPageNetworkCalls(vu moduleVU, page *common.Page, m mapping) mapping { + var begin func() (finishAndRetain, abortAndDiscard func()) + if page != nil && k6common.AsyncMetricContextEnabled(vu.State()) { + begin = func() (finishAndRetain, abortAndDiscard func()) { + state := vu.State() + if state == nil || state.Tags == nil { + return func() {}, func() {} + } + return page.BeginNetworkOperation(state.Tags.GetCurrentValues()) + } + } + return finishMappingCalls(vu, m, begin, "") +} + +func finishMappingCalls( + vu moduleVU, + m mapping, + begin func() (finishAndRetain, abortAndDiscard func()), + path string, +) mapping { + for name, value := range m { + callPath := name + if path != "" { + callPath = path + "." + name + } + switch value := value.(type) { + case mapping: + m[name] = finishMappingCalls(vu, value, begin, callPath) + case mappingCall: + fn := reflect.ValueOf(value.fn) + if !fn.IsValid() || fn.Kind() != reflect.Func { + panic(fmt.Sprintf("browser mapping %q classifies non-callable %T", callPath, value.fn)) + } + switch value.kind { + case mappingCallPassive: + m[name] = value.fn + case mappingCallNetwork: + if begin == nil { + m[name] = value.fn + break + } + m[name], _ = aroundMappingCall(vu, value.fn, begin) + default: + panic(fmt.Sprintf("browser mapping call %q has invalid classification", callPath)) + } + default: + valueType := reflect.TypeOf(value) + if valueType != nil && valueType.Kind() == reflect.Func { + panic(fmt.Sprintf("browser mapping call %q must be classified", callPath)) + } + m[name] = value + } + } + return m +} + +func aroundMappingCalls( + vu moduleVU, + m mapping, + begin func() (finishAndRetain, abortAndDiscard func()), +) mapping { + return finishMappingCalls(vu, m, begin, "") +} + +func aroundMappingCall( + vu moduleVU, + value any, + begin func() (finishAndRetain, abortAndDiscard func()), +) (any, bool) { + original := reflect.ValueOf(value) + if original.Kind() != reflect.Func { + return nil, false + } + wrapped := reflect.MakeFunc(original.Type(), func(args []reflect.Value) []reflect.Value { + finishAndRetain, abortAndDiscard := begin() + operationLaunched := false + defer func() { + if !operationLaunched { + abortAndDiscard() + } + }() + + results := callMapping(original, args) + if mappingCallFailed(results) { + return results + } + operationLaunched = wrapMappingPromise(vu, results, finishAndRetain) + if !operationLaunched { + finishAndRetain() + operationLaunched = true + } + return results + }) + return wrapped.Interface(), true +} + +func callMapping(fn reflect.Value, args []reflect.Value) []reflect.Value { + if fn.Type().IsVariadic() { + return fn.CallSlice(args) + } + return fn.Call(args) +} + +func mappingCallFailed(results []reflect.Value) bool { + for _, result := range results { + if err, ok := reflect.TypeAssert[error](result); ok && err != nil { + return true + } + } + return false +} + +func wrapMappingPromise(vu moduleVU, results []reflect.Value, finishAndRetain func()) bool { + for i, result := range results { + promise, ok := reflect.TypeAssert[*sobek.Promise](result) + if !ok || promise == nil { + continue + } + results[i] = reflect.ValueOf(endOperationOnPromiseSettlement(vu, promise, finishAndRetain)) + return true + } + return false +} + +func endOperationOnPromiseSettlement( + vu moduleVU, + promise *sobek.Promise, + finishAndRetain func(), +) *sobek.Promise { + rt := vu.Runtime() + wrapped, resolve, reject := rt.NewPromise() + finishAndRetain = sync.OnceFunc(finishAndRetain) + + onFulfilled := func(call sobek.FunctionCall) sobek.Value { + finishAndRetain() + if err := resolve(call.Argument(0)); err != nil { + k6common.Throw(rt, err) + } + return sobek.Undefined() + } + onRejected := func(call sobek.FunctionCall) sobek.Value { + // Rejection means the launched operation settled unsuccessfully, not that it never + // reached the browser. Retain its context for related CDP requests observed afterward. + finishAndRetain() + if err := reject(call.Argument(0)); err != nil { + k6common.Throw(rt, err) + } + return sobek.Undefined() + } + + then, ok := sobek.AssertFunction(rt.ToValue(promise).ToObject(rt).Get("then")) + if !ok { + panic("browser promise has no callable then method") + } + if _, err := then( + rt.ToValue(promise), + rt.ToValue(onFulfilled), + rt.ToValue(onRejected), + ); err != nil { + finishAndRetain() + if rejectErr := reject(err); rejectErr != nil { + k6common.Throw(rt, rejectErr) + } + } + return wrapped +} + // mapToSobek maps a browser-module mapping to a Sobek object. // The motivation of this mapping was to support $ and $$ wildcard // methods. diff --git a/internal/js/modules/k6/browser/browser/mapping_test.go b/internal/js/modules/k6/browser/browser/mapping_test.go index 18f8f22bb..c0b94565b 100644 --- a/internal/js/modules/k6/browser/browser/mapping_test.go +++ b/internal/js/modules/k6/browser/browser/mapping_test.go @@ -7,6 +7,7 @@ import ( "testing" "github.com/grafana/sobek" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.k6.io/k6/v2/internal/js/modules/k6/browser/common" @@ -48,6 +49,230 @@ func customMappings() map[string]string { } } +func TestAroundMappingCallsIncludesAllNestedMappings(t *testing.T) { + t.Parallel() + + var calls []string + vu := moduleVU{VU: &k6modulestest.VU{RuntimeField: sobek.New()}} + m := aroundMappingCalls(vu, mapping{ + "top": networkCall(func(value string) string { + calls = append(calls, "top:"+value) + return value + }), + "skipped": networkCall(func() { + calls = append(calls, "skipped") + }), + "nested": mapping{ + "call": networkCall(func(value int) int { + calls = append(calls, "nested") + return value + }), + }, + }, func() (func(), func()) { + calls = append(calls, "begin") + return func() { calls = append(calls, "finish and retain") }, + func() { calls = append(calls, "abort and discard") } + }) + + require.Equal(t, "value", m["top"].(func(string) string)("value")) + m["skipped"].(func())() + nested := m["nested"].(mapping) + require.Equal(t, 42, nested["call"].(func(int) int)(42)) + require.Equal(t, []string{ + "begin", "top:value", "finish and retain", + "begin", "skipped", "finish and retain", + "begin", "nested", "finish and retain", + }, calls) +} + +func TestAroundMappingCallsLeavesPassiveCallsUnwrapped(t *testing.T) { + t.Parallel() + + started := false + called := false + vu := moduleVU{VU: &k6modulestest.VU{RuntimeField: sobek.New()}} + m := aroundMappingCalls(vu, mapping{ + "call": passiveCall(func() { called = true }), + }, func() (func(), func()) { + started = true + return func() {}, func() {} + }) + + m["call"].(func())() + assert.True(t, called) + assert.False(t, started) +} + +func TestFinishMappingRequiresExplicitCallClassification(t *testing.T) { + t.Parallel() + + require.PanicsWithValue(t, `browser mapping call "nested.call" must be classified`, func() { + finishMapping(mapping{ + "nested": mapping{ + "call": func() {}, + }, + }) + }) +} + +func TestFinishMappingPreservesReturnedMappings(t *testing.T) { + t.Parallel() + + rt := sobek.New() + m := finishMapping(mapping{ + "context": passiveCall(func() mapping { + return finishMapping(mapping{ + "pages": passiveCall(func() int { return 1 }), + }) + }), + }) + require.NoError(t, rt.Set("browser", m)) + + value, err := rt.RunString(`browser.context().pages()`) + require.NoError(t, err) + require.Equal(t, int64(1), value.ToInteger()) +} + +func TestAroundMappingCallsAbortsFailedCallBeforeLaunch(t *testing.T) { + t.Parallel() + + expectedErr := assert.AnError + abortedAndDiscarded := false + finishedAndRetained := false + vu := moduleVU{VU: &k6modulestest.VU{RuntimeField: sobek.New()}} + m := aroundMappingCalls(vu, mapping{ + "call": networkCall(func() (*sobek.Promise, error) { return nil, expectedErr }), + }, func() (func(), func()) { + return func() { finishedAndRetained = true }, func() { abortedAndDiscarded = true } + }) + + promise, err := m["call"].(func() (*sobek.Promise, error))() + assert.Nil(t, promise) + assert.ErrorIs(t, err, expectedErr) + assert.False(t, finishedAndRetained) + assert.True(t, abortedAndDiscarded) +} + +func TestAroundMappingCallsKeepsOperationUntilPromiseSettles(t *testing.T) { + t.Parallel() + + rt := sobek.New() + vu := moduleVU{VU: &k6modulestest.VU{RuntimeField: rt}} + promise, resolve, _ := rt.NewPromise() + active := false + m := aroundMappingCalls(vu, mapping{ + "call": networkCall(func() *sobek.Promise { return promise }), + }, func() (func(), func()) { + active = true + return func() { active = false }, func() { active = false } + }) + + wrapped := m["call"].(func() *sobek.Promise)() + assert.True(t, active) + require.NoError(t, resolve("result")) + _, err := rt.RunString(`0`) + require.NoError(t, err) + assert.False(t, active) + assert.Equal(t, sobek.PromiseStateFulfilled, wrapped.State()) + assert.Equal(t, "result", wrapped.Result().String()) +} + +func TestAroundMappingCallsRetainsOperationWhenPromiseRejects(t *testing.T) { + t.Parallel() + + rt := sobek.New() + vu := moduleVU{VU: &k6modulestest.VU{RuntimeField: rt}} + promise, _, reject := rt.NewPromise() + abortedAndDiscarded := false + finishedAndRetained := false + m := aroundMappingCalls(vu, mapping{ + "call": networkCall(func() *sobek.Promise { return promise }), + }, func() (func(), func()) { + return func() { finishedAndRetained = true }, func() { abortedAndDiscarded = true } + }) + + wrapped := m["call"].(func() *sobek.Promise)() + require.NoError(t, reject("failure")) + _, err := rt.RunString(`0`) + require.NoError(t, err) + assert.True(t, finishedAndRetained) + assert.False(t, abortedAndDiscarded) + assert.Equal(t, sobek.PromiseStateRejected, wrapped.State()) + assert.Equal(t, "failure", wrapped.Result().String()) +} + +func BenchmarkAroundMappingCalls(b *testing.B) { + for name, mapped := range map[string]bool{ + "direct": false, + "wrapped": true, + } { + b.Run(name, func(b *testing.B) { + rt := sobek.New() + vu := moduleVU{VU: &k6modulestest.VU{RuntimeField: rt}} + fn := func(value int64) int64 { return value } + if mapped { + fn = aroundMappingCalls(vu, mapping{"call": networkCall(fn)}, func() (func(), func()) { + return func() {}, func() {} + })["call"].(func(int64) int64) + } + require.NoError(b, rt.Set("call", fn)) + call, err := rt.RunString(`() => call(42)`) + require.NoError(b, err) + invoke, ok := sobek.AssertFunction(call) + require.True(b, ok) + + b.ReportAllocs() + for b.Loop() { + _, err = invoke(sobek.Undefined()) + if err != nil { + b.Fatal(err) + } + } + }) + } +} + +func BenchmarkAroundMappingPromiseCalls(b *testing.B) { + for name, mapped := range map[string]bool{ + "direct": false, + "wrapped": true, + } { + b.Run(name, func(b *testing.B) { + rt := sobek.New() + vu := moduleVU{VU: &k6modulestest.VU{RuntimeField: rt}} + fn := func() *sobek.Promise { + promise, resolve, _ := rt.NewPromise() + if err := resolve(42); err != nil { + b.Fatal(err) + } + return promise + } + if mapped { + fn = aroundMappingCalls(vu, mapping{"call": networkCall(fn)}, func() (func(), func()) { + return func() {}, func() {} + })["call"].(func() *sobek.Promise) + } + require.NoError(b, rt.Set("call", fn)) + call, err := rt.RunString(`() => call()`) + require.NoError(b, err) + invoke, ok := sobek.AssertFunction(call) + require.True(b, ok) + drain, err := sobek.Compile("drain.js", "0", false) + require.NoError(b, err) + + b.ReportAllocs() + for b.Loop() { + if _, err = invoke(sobek.Undefined()); err != nil { + b.Fatal(err) + } + if _, err = rt.RunProgram(drain); err != nil { + b.Fatal(err) + } + } + }) + } +} + // TestMappings tests that all the methods of the API (api/) are // to the module. This is to ensure that we don't forget to map // a new method to the module. diff --git a/internal/js/modules/k6/browser/browser/metric_event_mapping.go b/internal/js/modules/k6/browser/browser/metric_event_mapping.go index de76bf36b..37d1244c1 100644 --- a/internal/js/modules/k6/browser/browser/metric_event_mapping.go +++ b/internal/js/modules/k6/browser/browser/metric_event_mapping.go @@ -11,8 +11,8 @@ func mapMetricEvent(vu moduleVU, event common.PageEvent) mapping { rt := vu.Runtime() em := event.Metric - return mapping{ - "tag": func(urls common.TagMatches) error { + return finishMapping(mapping{ + "tag": passiveCall(func(urls common.TagMatches) error { callback := func(pattern, url string) (bool, error) { matched, err := rt.RunString(pattern + `.test('` + url + `')`) if err != nil { @@ -22,6 +22,6 @@ func mapMetricEvent(vu moduleVU, event common.PageEvent) mapping { } return em.Tag(callback, urls) //nolint:wrapcheck - }, - } + }), + }) } diff --git a/internal/js/modules/k6/browser/browser/mouse_mapping.go b/internal/js/modules/k6/browser/browser/mouse_mapping.go index 7016bafe4..8bc1c37f9 100644 --- a/internal/js/modules/k6/browser/browser/mouse_mapping.go +++ b/internal/js/modules/k6/browser/browser/mouse_mapping.go @@ -12,8 +12,12 @@ import ( func mapMouse(vu moduleVU, m *common.Mouse) mapping { rt := vu.Runtime() + return finishMapping(newMouseMapping(vu, m, rt)) +} + +func newMouseMapping(vu moduleVU, m *common.Mouse, rt *sobek.Runtime) mapping { return mapping{ - "click": func(x float64, y float64, opts sobek.Value) (*sobek.Promise, error) { + "click": networkCall(func(x float64, y float64, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseMouseClickOptions(rt, opts) if err != nil { return nil, fmt.Errorf("parsing mouse click options: %w", err) @@ -21,8 +25,8 @@ func mapMouse(vu moduleVU, m *common.Mouse) mapping { return promise(vu, func() (any, error) { return nil, m.Click(x, y, popts) //nolint:wrapcheck }), nil - }, - "dblClick": func(x float64, y float64, opts sobek.Value) (*sobek.Promise, error) { + }), + "dblClick": networkCall(func(x float64, y float64, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseMouseDblClickOptions(rt, opts) if err != nil { return nil, fmt.Errorf("parsing mouse double click options: %w", err) @@ -30,8 +34,8 @@ func mapMouse(vu moduleVU, m *common.Mouse) mapping { return promise(vu, func() (any, error) { return nil, m.DblClick(x, y, popts) //nolint:wrapcheck }), nil - }, - "down": func(opts sobek.Value) (*sobek.Promise, error) { + }), + "down": networkCall(func(opts sobek.Value) (*sobek.Promise, error) { popts, err := parseMouseDownUpOptions(rt, opts) if err != nil { return nil, fmt.Errorf("parsing mouse down options: %w", err) @@ -39,8 +43,8 @@ func mapMouse(vu moduleVU, m *common.Mouse) mapping { return promise(vu, func() (any, error) { return nil, m.Down(popts) //nolint:wrapcheck }), nil - }, - "up": func(opts sobek.Value) (*sobek.Promise, error) { + }), + "up": networkCall(func(opts sobek.Value) (*sobek.Promise, error) { popts, err := parseMouseDownUpOptions(rt, opts) if err != nil { return nil, fmt.Errorf("parsing mouse up options: %w", err) @@ -48,8 +52,8 @@ func mapMouse(vu moduleVU, m *common.Mouse) mapping { return promise(vu, func() (any, error) { return nil, m.Up(popts) //nolint:wrapcheck }), nil - }, - "move": func(x float64, y float64, opts sobek.Value) (*sobek.Promise, error) { + }), + "move": networkCall(func(x float64, y float64, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseMouseMoveOptions(rt, opts) if err != nil { return nil, fmt.Errorf("parsing mouse move options: %w", err) @@ -57,7 +61,7 @@ func mapMouse(vu moduleVU, m *common.Mouse) mapping { return promise(vu, func() (any, error) { return nil, m.Move(x, y, popts) //nolint:wrapcheck }), nil - }, + }), } } diff --git a/internal/js/modules/k6/browser/browser/page_mapping.go b/internal/js/modules/k6/browser/browser/page_mapping.go index c25337b24..40593cff8 100644 --- a/internal/js/modules/k6/browser/browser/page_mapping.go +++ b/internal/js/modules/k6/browser/browser/page_mapping.go @@ -22,12 +22,12 @@ import ( func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop rt := vu.Runtime() maps := mapping{ - "bringToFront": func() *sobek.Promise { + "bringToFront": networkCall(func() *sobek.Promise { return promise(vu, func() (any, error) { return nil, p.BringToFront() //nolint:wrapcheck }) - }, - "check": func(selector string, opts sobek.Value) (*sobek.Promise, error) { + }), + "check": networkCall(func(selector string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameCheckOptions(rt, opts, p.MainFrame().Timeout()) if err != nil { return nil, fmt.Errorf("parsing new frame check options: %w", err) @@ -35,8 +35,8 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return promise(vu, func() (any, error) { return nil, p.Check(selector, popts) //nolint:wrapcheck }), nil - }, - "click": func(selector string, opts sobek.Value) (*sobek.Promise, error) { + }), + "click": networkCall(func(selector string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameClickOptions(rt, opts, p.MainFrame().Timeout()) if err != nil { return nil, err @@ -46,8 +46,8 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop err := p.Click(selector, popts) return nil, err //nolint:wrapcheck }), nil - }, - "close": func(opts sobek.Value) *sobek.Promise { + }), + "close": networkCall(func(opts sobek.Value) *sobek.Promise { // TODO when opts are implemented for this function, parse them here before calling promise() // in a goroutine off the event loop. As that will race with anything running on the event loop. return promise(vu, func() (any, error) { @@ -60,16 +60,16 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return nil, err //nolint:wrapcheck }) - }, - "content": func() *sobek.Promise { + }), + "content": passiveCall(func() *sobek.Promise { return promise(vu, func() (any, error) { return p.Content() //nolint:wrapcheck }) - }, - "context": func() mapping { + }), + "context": passiveCall(func() mapping { return mapBrowserContext(vu, p.Context()) - }, - "dblclick": func(selector string, opts sobek.Value) (*sobek.Promise, error) { + }), + "dblclick": networkCall(func(selector string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameDblclickOptions(rt, opts, p.MainFrame().Timeout()) if err != nil { return nil, fmt.Errorf("parsing double click options: %w", err) @@ -77,8 +77,8 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return promise(vu, func() (any, error) { return nil, p.Dblclick(selector, popts) //nolint:wrapcheck }), nil - }, - "dispatchEvent": func(selector, typ string, eventInit, opts sobek.Value) (*sobek.Promise, error) { + }), + "dispatchEvent": networkCall(func(selector, typ string, eventInit, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameDispatchEventOptions(rt, opts, p.MainFrame().Timeout()) if err != nil { return nil, fmt.Errorf("parsing page dispatch event options: %w", err) @@ -87,8 +87,8 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return promise(vu, func() (any, error) { return nil, p.DispatchEvent(selector, typ, earg, popts) //nolint:wrapcheck }), nil - }, - "emulateMedia": func(opts sobek.Value) (*sobek.Promise, error) { + }), + "emulateMedia": networkCall(func(opts sobek.Value) (*sobek.Promise, error) { popts, err := parsePageEmulateMediaOptions(rt, opts, common.NewPageEmulateMediaOptions(p)) if err != nil { return nil, fmt.Errorf("parsing emulateMedia options: %w", err) @@ -96,13 +96,13 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return promise(vu, func() (any, error) { return nil, p.EmulateMedia(popts) //nolint:wrapcheck }), nil - }, - "emulateVisionDeficiency": func(typ string) *sobek.Promise { + }), + "emulateVisionDeficiency": passiveCall(func(typ string) *sobek.Promise { return promise(vu, func() (any, error) { return nil, p.EmulateVisionDeficiency(typ) //nolint:wrapcheck }) - }, - "evaluate": func(pageFunc sobek.Value, gargs ...sobek.Value) (*sobek.Promise, error) { + }), + "evaluate": networkCall(func(pageFunc sobek.Value, gargs ...sobek.Value) (*sobek.Promise, error) { if sobekEmptyString(pageFunc) { return nil, fmt.Errorf("evaluate requires a page function") } @@ -111,8 +111,8 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return promise(vu, func() (any, error) { return p.Evaluate(funcString, gopts...) }), nil - }, - "evaluateHandle": func(pageFunc sobek.Value, gargs ...sobek.Value) (*sobek.Promise, error) { + }), + "evaluateHandle": networkCall(func(pageFunc sobek.Value, gargs ...sobek.Value) (*sobek.Promise, error) { if sobekEmptyString(pageFunc) { return nil, fmt.Errorf("evaluateHandle requires a page function") } @@ -125,8 +125,8 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop } return mapJSHandle(vu, jsh), nil }), nil - }, - "fill": func(selector string, value string, opts sobek.Value) (*sobek.Promise, error) { + }), + "fill": networkCall(func(selector string, value string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameFillOptions(rt, opts, p.MainFrame().Timeout()) if err != nil { return nil, fmt.Errorf("parsing fill options: %w", err) @@ -134,8 +134,8 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return promise(vu, func() (any, error) { return nil, p.Fill(selector, value, popts) //nolint:wrapcheck }), nil - }, - "focus": func(selector string, opts sobek.Value) (*sobek.Promise, error) { + }), + "focus": networkCall(func(selector string, opts sobek.Value) (*sobek.Promise, error) { popts := common.NewFrameBaseOptions(p.MainFrame().Timeout()) if err := parseFrameBaseOptions(popts, rt, opts); err != nil { return nil, fmt.Errorf("parsing focus options: %w", err) @@ -143,16 +143,16 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return promise(vu, func() (any, error) { return nil, p.Focus(selector, popts) //nolint:wrapcheck }), nil - }, - "frames": func() *sobek.Object { + }), + "frames": passiveCall(func() *sobek.Object { frs := p.Frames() mfrs := make([]mapping, 0, len(frs)) for _, fr := range frs { mfrs = append(mfrs, mapFrame(vu, fr)) } return rt.ToValue(mfrs).ToObject(rt) - }, - "getAttribute": func(selector string, name string, opts sobek.Value) (*sobek.Promise, error) { + }), + "getAttribute": passiveCall(func(selector string, name string, opts sobek.Value) (*sobek.Promise, error) { popts := common.NewFrameBaseOptions(p.MainFrame().Timeout()) if err := parseFrameBaseOptions(popts, rt, opts); err != nil { return nil, fmt.Errorf("parsing getAttribute options: %w", err) @@ -167,8 +167,8 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop } return s, nil }), nil - }, - "getByRole": func(role sobek.Value, opts sobek.Value) (*sobek.Object, error) { + }), + "getByRole": passiveCall(func(role sobek.Value, opts sobek.Value) (*sobek.Object, error) { if k6common.IsNullish(role) { return nil, errors.New("missing required argument 'role'") } @@ -176,8 +176,8 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop ml := mapLocator(vu, p.GetByRole(role.String(), popts)) return rt.ToValue(ml).ToObject(rt), nil - }, - "getByAltText": func(alt sobek.Value, opts sobek.Value) (*sobek.Object, error) { + }), + "getByAltText": passiveCall(func(alt sobek.Value, opts sobek.Value) (*sobek.Object, error) { if k6common.IsNullish(alt) { return nil, errors.New("missing required argument 'altText'") } @@ -185,8 +185,8 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop ml := mapLocator(vu, p.GetByAltText(palt, popts)) return rt.ToValue(ml).ToObject(rt), nil - }, - "getByLabel": func(label sobek.Value, opts sobek.Value) (*sobek.Object, error) { + }), + "getByLabel": passiveCall(func(label sobek.Value, opts sobek.Value) (*sobek.Object, error) { if k6common.IsNullish(label) { return nil, errors.New("missing required argument 'label'") } @@ -194,8 +194,8 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop ml := mapLocator(vu, p.GetByLabel(plabel, popts)) return rt.ToValue(ml).ToObject(rt), nil - }, - "getByPlaceholder": func(placeholder sobek.Value, opts sobek.Value) (*sobek.Object, error) { + }), + "getByPlaceholder": passiveCall(func(placeholder sobek.Value, opts sobek.Value) (*sobek.Object, error) { if k6common.IsNullish(placeholder) { return nil, errors.New("missing required argument 'placeholder'") } @@ -203,8 +203,8 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop ml := mapLocator(vu, p.GetByPlaceholder(pplaceholder, popts)) return rt.ToValue(ml).ToObject(rt), nil - }, - "getByTitle": func(title sobek.Value, opts sobek.Value) (*sobek.Object, error) { + }), + "getByTitle": passiveCall(func(title sobek.Value, opts sobek.Value) (*sobek.Object, error) { if k6common.IsNullish(title) { return nil, errors.New("missing required argument 'title'") } @@ -212,8 +212,8 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop ml := mapLocator(vu, p.GetByTitle(ptitle, popts)) return rt.ToValue(ml).ToObject(rt), nil - }, - "getByTestId": func(testID sobek.Value) (*sobek.Object, error) { + }), + "getByTestId": passiveCall(func(testID sobek.Value) (*sobek.Object, error) { if k6common.IsNullish(testID) { return nil, errors.New("missing required argument 'testId'") } @@ -221,8 +221,8 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop ml := mapLocator(vu, p.GetByTestID(ptestID)) return rt.ToValue(ml).ToObject(rt), nil - }, - "getByText": func(text sobek.Value, opts sobek.Value) (*sobek.Object, error) { + }), + "getByText": passiveCall(func(text sobek.Value, opts sobek.Value) (*sobek.Object, error) { if k6common.IsNullish(text) { return nil, errors.New("missing required argument 'text'") } @@ -230,8 +230,8 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop ml := mapLocator(vu, p.GetByText(ptext, popts)) return rt.ToValue(ml).ToObject(rt), nil - }, - "goto": func(url string, opts sobek.Value) (*sobek.Promise, error) { + }), + "goto": networkCall(func(url string, opts sobek.Value) (*sobek.Promise, error) { gopts, err := parseFrameGotoOptions( rt, opts, p.Referrer(), @@ -248,8 +248,8 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return mapResponse(vu, resp), nil }), nil - }, - "hover": func(selector string, opts sobek.Value) (*sobek.Promise, error) { + }), + "hover": networkCall(func(selector string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameHoverOptions(rt, opts, p.MainFrame().Timeout()) if err != nil { return nil, fmt.Errorf("parsing hover options: %w", err) @@ -257,8 +257,8 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return promise(vu, func() (any, error) { return nil, p.Hover(selector, popts) //nolint:wrapcheck }), nil - }, - "innerHTML": func(selector string, opts sobek.Value) (*sobek.Promise, error) { + }), + "innerHTML": passiveCall(func(selector string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameInnerHTMLOptions(rt, opts, p.MainFrame().Timeout()) if err != nil { return nil, fmt.Errorf("parsing inner HTML options: %w", err) @@ -266,8 +266,8 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return promise(vu, func() (any, error) { return p.InnerHTML(selector, popts) //nolint:wrapcheck }), nil - }, - "innerText": func(selector string, opts sobek.Value) (*sobek.Promise, error) { + }), + "innerText": passiveCall(func(selector string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameInnerTextOptions(rt, opts, p.MainFrame().Timeout()) if err != nil { return nil, fmt.Errorf("parsing inner text options: %w", err) @@ -275,8 +275,8 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return promise(vu, func() (any, error) { return p.InnerText(selector, popts) //nolint:wrapcheck }), nil - }, - "inputValue": func(selector string, opts sobek.Value) (*sobek.Promise, error) { + }), + "inputValue": passiveCall(func(selector string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameInputValueOptions(rt, opts, p.MainFrame().Timeout()) if err != nil { return nil, fmt.Errorf("parsing input value options: %w", err) @@ -284,8 +284,8 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return promise(vu, func() (any, error) { return p.InputValue(selector, popts) //nolint:wrapcheck }), nil - }, - "isChecked": func(selector string, opts sobek.Value) (*sobek.Promise, error) { + }), + "isChecked": passiveCall(func(selector string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameIsCheckedOptions(rt, opts, p.MainFrame().Timeout()) if err != nil { return nil, fmt.Errorf("parse isChecked options of selector %q: %w", selector, err) @@ -293,9 +293,9 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return promise(vu, func() (any, error) { return p.IsChecked(selector, popts) //nolint:wrapcheck }), nil - }, - "isClosed": p.IsClosed, - "isDisabled": func(selector string, opts sobek.Value) (*sobek.Promise, error) { + }), + "isClosed": passiveCall(p.IsClosed), + "isDisabled": passiveCall(func(selector string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameIsDisabledOptions(rt, opts, p.MainFrame().Timeout()) if err != nil { return nil, fmt.Errorf("parse isDisabled options of selector %q: %w", selector, err) @@ -303,8 +303,8 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return promise(vu, func() (any, error) { return p.IsDisabled(selector, popts) //nolint:wrapcheck }), nil - }, - "isEditable": func(selector string, opts sobek.Value) (*sobek.Promise, error) { + }), + "isEditable": passiveCall(func(selector string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameIsEditableOptions(rt, opts, p.MainFrame().Timeout()) if err != nil { return nil, fmt.Errorf("parse isEditabled options of selector %q: %w", selector, err) @@ -312,8 +312,8 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return promise(vu, func() (any, error) { return p.IsEditable(selector, popts) //nolint:wrapcheck }), nil - }, - "isEnabled": func(selector string, opts sobek.Value) (*sobek.Promise, error) { + }), + "isEnabled": passiveCall(func(selector string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameIsEnabledOptions(rt, opts, p.MainFrame().Timeout()) if err != nil { return nil, fmt.Errorf("parse isEnabled options of selector %q: %w", selector, err) @@ -321,8 +321,8 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return promise(vu, func() (any, error) { return p.IsEnabled(selector, popts) //nolint:wrapcheck }), nil - }, - "isHidden": func(selector string, opts sobek.Value) (*sobek.Promise, error) { + }), + "isHidden": passiveCall(func(selector string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameIsHiddenOptions(rt, opts) if err != nil { return nil, fmt.Errorf("parse isHidden options of selector %q: %w", selector, err) @@ -330,8 +330,8 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return promise(vu, func() (any, error) { return p.IsHidden(selector, popts) //nolint:wrapcheck }), nil - }, - "isVisible": func(selector string, opts sobek.Value) (*sobek.Promise, error) { + }), + "isVisible": passiveCall(func(selector string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameIsVisibleOptions(rt, opts) if err != nil { return nil, fmt.Errorf("parsing isVisible options of selector %q: %w", selector, err) @@ -339,28 +339,28 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return promise(vu, func() (any, error) { return p.IsVisible(selector, popts) //nolint:wrapcheck }), nil - }, - "keyboard": mapKeyboard(vu, p.GetKeyboard()), - "locator": func(selector string, opts sobek.Value) *sobek.Object { + }), + "keyboard": newKeyboardMapping(vu, p.GetKeyboard()), + "locator": passiveCall(func(selector string, opts sobek.Value) *sobek.Object { ml := mapLocator(vu, p.Locator(selector, parseLocatorOptions(rt, opts))) return rt.ToValue(ml).ToObject(rt) - }, - "frameLocator": func(selector string) *sobek.Object { + }), + "frameLocator": passiveCall(func(selector string) *sobek.Object { mfl := mapFrameLocator(vu, p.FrameLocator(selector)) return rt.ToValue(mfl).ToObject(rt) - }, - "mainFrame": func() *sobek.Object { + }), + "mainFrame": passiveCall(func() *sobek.Object { mf := mapFrame(vu, p.MainFrame()) return rt.ToValue(mf).ToObject(rt) - }, - "mouse": mapMouse(vu, p.GetMouse()), - "on": mapPageOn(vu, p), - "opener": func() *sobek.Promise { + }), + "mouse": newMouseMapping(vu, p.GetMouse(), rt), + "on": passiveCall(mapPageOn(vu, p)), + "opener": passiveCall(func() *sobek.Promise { return promise(vu, func() (any, error) { return p.Opener(), nil }) - }, - "press": func(selector string, key string, opts sobek.Value) (*sobek.Promise, error) { + }), + "press": networkCall(func(selector string, key string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFramePressOptions(rt, opts, p.Timeout()) if err != nil { return nil, fmt.Errorf("parsing press options of selector %q: %w", selector, err) @@ -368,8 +368,8 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return promise(vu, func() (any, error) { return nil, p.Press(selector, key, popts) //nolint:wrapcheck }), nil - }, - "reload": func(opts sobek.Value) (*sobek.Promise, error) { + }), + "reload": networkCall(func(opts sobek.Value) (*sobek.Promise, error) { popts := common.NewPageReloadOptions(common.LifecycleEventLoad, p.NavigationTimeout()) if err := popts.Parse(vu.Context(), opts); err != nil { return nil, fmt.Errorf("parsing reload options: %w", err) @@ -384,8 +384,8 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop } return mapResponse(vu, resp), nil }), nil - }, - "goBack": func(opts sobek.Value) (*sobek.Promise, error) { + }), + "goBack": networkCall(func(opts sobek.Value) (*sobek.Promise, error) { popts := common.NewPageGoBackForwardOptions(common.LifecycleEventLoad, p.NavigationTimeout()) if err := popts.Parse(vu.Context(), opts); err != nil { return nil, fmt.Errorf("parsing page go back options: %w", err) @@ -400,8 +400,8 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop } return mapResponse(vu, resp), nil }), nil - }, - "goForward": func(opts sobek.Value) (*sobek.Promise, error) { + }), + "goForward": networkCall(func(opts sobek.Value) (*sobek.Promise, error) { popts := common.NewPageGoBackForwardOptions(common.LifecycleEventLoad, p.NavigationTimeout()) if err := popts.Parse(vu.Context(), opts); err != nil { return nil, fmt.Errorf("parsing page go forward options: %w", err) @@ -416,9 +416,9 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop } return mapResponse(vu, resp), nil }), nil - }, - "route": mapPageRoute(vu, p), - "screenshot": func(opts sobek.Value) (*sobek.Promise, error) { + }), + "route": passiveCall(mapPageRoute(vu, p)), + "screenshot": passiveCall(func(opts sobek.Value) (*sobek.Promise, error) { popts, err := parsePageScreenshotOptions(rt, opts) if err != nil { return nil, fmt.Errorf("parsing page screenshot options: %w", err) @@ -441,8 +441,8 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop }() return promise, nil - }, - "selectOption": func(selector string, values sobek.Value, opts sobek.Value) (*sobek.Promise, error) { + }), + "selectOption": networkCall(func(selector string, values sobek.Value, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameSelectOptionOptions(rt, opts, p.MainFrame().Timeout()) if err != nil { return nil, fmt.Errorf("parsing select option options: %w", err) @@ -455,8 +455,8 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return promise(vu, func() (any, error) { return p.SelectOption(selector, convValues, popts) //nolint:wrapcheck }), nil - }, - "setChecked": func(selector string, checked bool, opts sobek.Value) (*sobek.Promise, error) { + }), + "setChecked": networkCall(func(selector string, checked bool, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameCheckOptions(rt, opts, p.MainFrame().Timeout()) if err != nil { return nil, fmt.Errorf("parsing frame set check options: %w", err) @@ -465,8 +465,8 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return promise(vu, func() (any, error) { return nil, p.SetChecked(selector, checked, popts) //nolint:wrapcheck }), nil - }, - "setContent": func(html string, opts sobek.Value) (*sobek.Promise, error) { + }), + "setContent": networkCall(func(html string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameSetContentOptions(rt, opts, p.MainFrame().NavigationTimeout()) if err != nil { return nil, fmt.Errorf("parsing setContent options: %w", err) @@ -474,15 +474,15 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return promise(vu, func() (any, error) { return nil, p.SetContent(html, popts) //nolint:wrapcheck }), nil - }, - "setDefaultNavigationTimeout": p.SetDefaultNavigationTimeout, - "setDefaultTimeout": p.SetDefaultTimeout, - "setExtraHTTPHeaders": func(headers map[string]string) *sobek.Promise { + }), + "setDefaultNavigationTimeout": passiveCall(p.SetDefaultNavigationTimeout), + "setDefaultTimeout": passiveCall(p.SetDefaultTimeout), + "setExtraHTTPHeaders": passiveCall(func(headers map[string]string) *sobek.Promise { return promise(vu, func() (any, error) { return nil, p.SetExtraHTTPHeaders(headers) //nolint:wrapcheck }) - }, - "setInputFiles": func(selector string, files sobek.Value, opts sobek.Value) (*sobek.Promise, error) { + }), + "setInputFiles": networkCall(func(selector string, files sobek.Value, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameSetInputFilesOptions(rt, opts, p.MainFrame().Timeout()) if err != nil { return nil, fmt.Errorf("parsing setInputFiles options: %w", err) @@ -496,8 +496,8 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return promise(vu, func() (any, error) { return nil, p.SetInputFiles(selector, pfiles, popts) //nolint:wrapcheck }), nil - }, - "setViewportSize": func(viewportSize sobek.Value) (*sobek.Promise, error) { + }), + "setViewportSize": networkCall(func(viewportSize sobek.Value) (*sobek.Promise, error) { s, err := parseSize(rt, viewportSize) if err != nil { return nil, fmt.Errorf("parsing viewport size: %w", err) @@ -505,8 +505,8 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return promise(vu, func() (any, error) { return nil, p.SetViewportSize(s) //nolint:wrapcheck }), nil - }, - "tap": func(selector string, opts sobek.Value) (*sobek.Promise, error) { + }), + "tap": networkCall(func(selector string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameTapOptions(rt, opts, p.Timeout()) if err != nil { return nil, fmt.Errorf("parsing page tap options: %w", err) @@ -514,8 +514,8 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return promise(vu, func() (any, error) { return nil, p.Tap(selector, popts) //nolint:wrapcheck }), nil - }, - "textContent": func(selector string, opts sobek.Value) (*sobek.Promise, error) { + }), + "textContent": passiveCall(func(selector string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameTextContentOptions(rt, opts, p.MainFrame().Timeout()) if err != nil { return nil, fmt.Errorf("parsing text content options: %w", err) @@ -531,24 +531,24 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop } return s, nil }), nil - }, - "throttleCPU": func(cpuProfile common.CPUProfile) *sobek.Promise { + }), + "throttleCPU": passiveCall(func(cpuProfile common.CPUProfile) *sobek.Promise { return promise(vu, func() (any, error) { return nil, p.ThrottleCPU(cpuProfile) //nolint:wrapcheck }) - }, - "throttleNetwork": func(networkProfile common.NetworkProfile) *sobek.Promise { + }), + "throttleNetwork": passiveCall(func(networkProfile common.NetworkProfile) *sobek.Promise { return promise(vu, func() (any, error) { return nil, p.ThrottleNetwork(networkProfile) //nolint:wrapcheck }) - }, - "title": func() *sobek.Promise { + }), + "title": passiveCall(func() *sobek.Promise { return promise(vu, func() (any, error) { return p.Title() //nolint:wrapcheck }) - }, - "touchscreen": mapTouchscreen(vu, p.GetTouchscreen()), - "type": func(selector string, text string, opts sobek.Value) (*sobek.Promise, error) { + }), + "touchscreen": newTouchscreenMapping(vu, p.GetTouchscreen()), + "type": networkCall(func(selector string, text string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameTypeOptions(rt, opts, p.MainFrame().Timeout()) if err != nil { return nil, fmt.Errorf("parsing type options: %w", err) @@ -557,8 +557,8 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return promise(vu, func() (any, error) { return nil, p.Type(selector, text, popts) //nolint:wrapcheck }), nil - }, - "uncheck": func(selector string, opts sobek.Value) (*sobek.Promise, error) { + }), + "uncheck": networkCall(func(selector string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameUncheckOptions(rt, opts, p.MainFrame().Timeout()) if err != nil { return nil, fmt.Errorf("parsing frame uncheck options %q: %w", selector, err) @@ -567,20 +567,20 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return promise(vu, func() (any, error) { return nil, p.Uncheck(selector, popts) //nolint:wrapcheck }), nil - }, - "unroute": func(url string) (*sobek.Promise, error) { + }), + "unroute": passiveCall(func(url string) (*sobek.Promise, error) { return promise(vu, func() (any, error) { return nil, p.Unroute(url) }), nil - }, - "unrouteAll": func() (*sobek.Promise, error) { + }), + "unrouteAll": passiveCall(func() (*sobek.Promise, error) { return promise(vu, func() (any, error) { return nil, p.UnrouteAll() }), nil - }, - "url": p.URL, - "viewportSize": p.ViewportSize, - "waitForFunction": func(pageFunc, opts sobek.Value, args ...sobek.Value) (*sobek.Promise, error) { + }), + "url": passiveCall(p.URL), + "viewportSize": passiveCall(p.ViewportSize), + "waitForFunction": networkCall(func(pageFunc, opts sobek.Value, args ...sobek.Value) (*sobek.Promise, error) { js, popts, pargs, err := parseWaitForFunctionArgs( rt, p.Timeout(), pageFunc, opts, args..., ) @@ -591,8 +591,8 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return promise(vu, func() (result any, reason error) { return p.WaitForFunction(js, popts, pargs...) //nolint:wrapcheck }), nil - }, - "waitForLoadState": func(state string, opts sobek.Value) (*sobek.Promise, error) { + }), + "waitForLoadState": passiveCall(func(state string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameWaitForLoadStateOptions(rt, opts, p.MainFrame().Timeout()) if err != nil { return nil, fmt.Errorf("parsing waitForLoadState %q options: %w", state, err) @@ -601,11 +601,11 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return promise(vu, func() (any, error) { return nil, p.WaitForLoadState(state, popts) //nolint:wrapcheck }), nil - }, - "waitForNavigation": func(opts sobek.Value) (*sobek.Promise, error) { + }), + "waitForNavigation": passiveCall(func(opts sobek.Value) (*sobek.Promise, error) { return mapWaitForNavigation(rt, vu, p, opts) - }, - "waitForSelector": func(selector string, opts sobek.Value) (*sobek.Promise, error) { + }), + "waitForSelector": passiveCall(func(selector string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameWaitForSelectorOptions(rt, opts, p.MainFrame().Timeout()) if err != nil { return nil, fmt.Errorf("parsing wait for selector %q options: %w", selector, err) @@ -618,17 +618,17 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop } return mapElementHandle(vu, eh), nil }), nil - }, - "waitForTimeout": func(timeout int64) *sobek.Promise { + }), + "waitForTimeout": passiveCall(func(timeout int64) *sobek.Promise { return promise(vu, func() (any, error) { p.WaitForTimeout(timeout) return nil, nil }) - }, - "waitForURL": func(url sobek.Value, opts sobek.Value) (*sobek.Promise, error) { + }), + "waitForURL": passiveCall(func(url sobek.Value, opts sobek.Value) (*sobek.Promise, error) { return mapWaitForURL(rt, vu, p, url, opts) - }, - "waitForResponse": func(url sobek.Value, opts sobek.Value) (*sobek.Promise, error) { + }), + "waitForResponse": passiveCall(func(url sobek.Value, opts sobek.Value) (*sobek.Promise, error) { popts, err := parsePageWaitForResponseOptions(vu.Context(), opts, p.Timeout()) if err != nil { return nil, fmt.Errorf("parsing waitForResponse options: %w", err) @@ -648,8 +648,8 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop defer stop() return p.WaitForResponse(val, popts, newRegExMatcher(ctx, vu, tq)) }), nil - }, - "waitForRequest": func(url sobek.Value, opts sobek.Value) (*sobek.Promise, error) { + }), + "waitForRequest": passiveCall(func(url sobek.Value, opts sobek.Value) (*sobek.Promise, error) { popts, err := parsePageWaitForRequestOptions(vu.Context(), opts, p.Timeout()) if err != nil { return nil, fmt.Errorf("parsing waitForRequest options: %w", err) @@ -669,8 +669,8 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop defer stop() return p.WaitForRequest(val, popts, newRegExMatcher(ctx, vu, tq)) }), nil - }, - "waitForEvent": func(event common.PageEventName, opts sobek.Value) (*sobek.Promise, error) { + }), + "waitForEvent": passiveCall(func(event common.PageEventName, opts sobek.Value) (*sobek.Promise, error) { // AVOID using a default case to force handling new event types explicitly // so that the linter can catch unhandled event types as non-exhaustive switch. // Otherwise, we might miss mapping new [PageEvent] types added in the future. @@ -701,12 +701,14 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop ctx := vu.Context() tq := vu.get(ctx, p.TargetID()) + captured := k6common.CaptureMetricContext(vu.State()) + return promise(vu, func() (any, error) { rpe, err := p.WaitForEvent(event, popts, func(pe common.PageEvent) (bool, error) { if fn == nil { return true, nil } - return queueTask(ctx, tq, func() (bool, error) { + return queueTaskWithMetricContext(ctx, tq, captured, func() (bool, error) { m, err := mapPageEvent(vu, pe) if err != nil { return false, err @@ -723,8 +725,8 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop } return mapPageEvent(vu, rpe) }), nil - }, - "workers": func() *sobek.Object { + }), + "workers": passiveCall(func() *sobek.Object { workers := p.Workers() mws := make([]mapping, 0, len(workers)) for _, w := range workers { @@ -732,9 +734,9 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop mws = append(mws, mw) } return rt.ToValue(mws).ToObject(rt) - }, + }), } - maps["$"] = func(selector string) *sobek.Promise { + maps["$"] = passiveCall(func(selector string) *sobek.Promise { return promise(vu, func() (any, error) { eh, err := p.Query(selector) if err != nil { @@ -750,8 +752,8 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return ehm, nil }) - } - maps["$$"] = func(selector string) *sobek.Promise { + }) + maps["$$"] = passiveCall(func(selector string) *sobek.Promise { return promise(vu, func() (any, error) { ehs, err := p.QueryAll(selector) if err != nil { @@ -764,9 +766,11 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop } return mehs, nil }) - } + }) - return maps + // CDP request events run outside the event loop, so keep the context of each mapped call available + // until its returned promise settles. Loader-associated requests take precedence when possible. + return withPageNetworkCalls(vu, p, maps) } // mapPageOn enables using various page.on event handlers with the page.on method. @@ -795,9 +799,10 @@ func mapPageOn(vu moduleVU, p *common.Page) func(common.PageEventName, sobek.Cal ctx := vu.Context() tq := vu.get(ctx, p.TargetID()) + captured := k6common.CaptureMetricContext(vu.State()) return p.On(eventName, func(event common.PageEvent) error { - wait := queueTask(ctx, tq, func() (sobek.Value, error) { + wait := queueTaskWithMetricContext(ctx, tq, captured, func() (sobek.Value, error) { _, err := handle(sobek.Undefined(), vu.Runtime().ToValue(pageEvent.mapp(vu, event))) if err != nil { return nil, fmt.Errorf("executing page.on('%s') handler: %w", eventName, err) @@ -974,9 +979,10 @@ func mapPageRoute(vu moduleVU, p *common.Page) func(sobek.Value, sobek.Callable) ppath := parseStringOrRegex(path, false) tq := vu.get(ctx, p.TargetID()) + captured := k6common.CaptureMetricContext(vu.State()) route := func(r *common.Route) error { - _, err := queueTask(ctx, tq, func() (any, error) { + _, err := queueTaskWithMetricContext(ctx, tq, captured, func() (any, error) { return cb(sobek.Undefined(), vu.Runtime().ToValue(mapRoute(vu, r))) })() if errors.Is(err, context.Canceled) { diff --git a/internal/js/modules/k6/browser/browser/request_mapping.go b/internal/js/modules/k6/browser/browser/request_mapping.go index dd650f8cc..430d040ea 100644 --- a/internal/js/modules/k6/browser/browser/request_mapping.go +++ b/internal/js/modules/k6/browser/browser/request_mapping.go @@ -16,17 +16,17 @@ func mapRequestEvent(vu moduleVU, event common.PageEvent) mapping { func mapRequest(vu moduleVU, r *common.Request) mapping { rt := vu.Runtime() maps := mapping{ - "allHeaders": func() *sobek.Promise { + "allHeaders": passiveCall(func() *sobek.Promise { return promise(vu, func() (any, error) { r.WaitForRawHeaders() return r.AllHeaders(), nil }) - }, - "frame": func() *sobek.Object { + }), + "frame": passiveCall(func() *sobek.Object { mf := mapFrame(vu, r.Frame()) return rt.ToValue(mf).ToObject(rt) - }, - "headerValue": func(name string) *sobek.Promise { + }), + "headerValue": passiveCall(func(name string) *sobek.Promise { return promise(vu, func() (any, error) { r.WaitForRawHeaders() v, ok := r.HeaderValue(name) @@ -36,32 +36,32 @@ func mapRequest(vu moduleVU, r *common.Request) mapping { return v, nil }) - }, - "headers": r.Headers, - "headersArray": func() *sobek.Promise { + }), + "headers": passiveCall(r.Headers), + "headersArray": passiveCall(func() *sobek.Promise { return promise(vu, func() (any, error) { r.WaitForRawHeaders() return r.HeadersArray(), nil }) - }, - "isNavigationRequest": r.IsNavigationRequest, - "method": r.Method, - "postData": func() any { + }), + "isNavigationRequest": passiveCall(r.IsNavigationRequest), + "method": passiveCall(r.Method), + "postData": passiveCall(func() any { p := r.PostData() if p == "" { return nil } return p - }, - "postDataBuffer": func() any { + }), + "postDataBuffer": passiveCall(func() any { p := r.PostDataBuffer() if len(p) == 0 { return nil } return rt.NewArrayBuffer(p) - }, - "resourceType": r.ResourceType, - "response": func() *sobek.Promise { + }), + "resourceType": passiveCall(r.ResourceType), + "response": passiveCall(func() *sobek.Promise { return promise(vu, func() (any, error) { resp := r.Response() if resp == nil { @@ -69,12 +69,12 @@ func mapRequest(vu moduleVU, r *common.Request) mapping { } return mapResponse(vu, resp), nil }) - }, - "size": r.Size, - "timing": r.Timing, - "url": r.URL, - "failure": r.Failure, + }), + "size": passiveCall(r.Size), + "timing": passiveCall(r.Timing), + "url": passiveCall(r.URL), + "failure": passiveCall(r.Failure), } - return maps + return finishMapping(maps) } diff --git a/internal/js/modules/k6/browser/browser/response_mapping.go b/internal/js/modules/k6/browser/browser/response_mapping.go index 43e0844b3..3cf494a38 100644 --- a/internal/js/modules/k6/browser/browser/response_mapping.go +++ b/internal/js/modules/k6/browser/browser/response_mapping.go @@ -18,13 +18,13 @@ func mapResponse(vu moduleVU, r *common.Response) mapping { return nil } maps := mapping{ - "allHeaders": func() *sobek.Promise { + "allHeaders": passiveCall(func() *sobek.Promise { return promise(vu, func() (any, error) { r.WaitForRawHeaders() return r.AllHeaders(), nil }) - }, - "body": func() *sobek.Promise { + }), + "body": passiveCall(func() *sobek.Promise { rt := vu.Runtime() promise, res, rej := rt.NewPromise() callback := vu.RegisterCallback() @@ -42,11 +42,11 @@ func mapResponse(vu moduleVU, r *common.Response) mapping { }) }() return promise - }, - "frame": func() mapping { + }), + "frame": passiveCall(func() mapping { return mapFrame(vu, r.Frame()) - }, - "headerValue": func(name string) *sobek.Promise { + }), + "headerValue": passiveCall(func(name string) *sobek.Promise { return promise(vu, func() (any, error) { r.WaitForRawHeaders() v, ok := r.HeaderValue(name) @@ -55,53 +55,53 @@ func mapResponse(vu moduleVU, r *common.Response) mapping { } return v, nil }) - }, - "headerValues": func(name string) *sobek.Promise { + }), + "headerValues": passiveCall(func(name string) *sobek.Promise { return promise(vu, func() (any, error) { r.WaitForRawHeaders() return r.HeaderValues(name), nil }) - }, - "headers": r.Headers, - "headersArray": func() *sobek.Promise { + }), + "headers": passiveCall(r.Headers), + "headersArray": passiveCall(func() *sobek.Promise { return promise(vu, func() (any, error) { r.WaitForRawHeaders() return r.HeadersArray(), nil }) - }, - "json": func() *sobek.Promise { + }), + "json": passiveCall(func() *sobek.Promise { return promise(vu, func() (any, error) { return r.JSON() //nolint: wrapcheck }) - }, - "ok": r.Ok, - "request": func() mapping { + }), + "ok": passiveCall(r.Ok), + "request": passiveCall(func() mapping { return mapRequest(vu, r.Request()) - }, - "securityDetails": func() *sobek.Promise { + }), + "securityDetails": passiveCall(func() *sobek.Promise { return promise(vu, func() (any, error) { return r.SecurityDetails(), nil }) - }, - "serverAddr": func() *sobek.Promise { + }), + "serverAddr": passiveCall(func() *sobek.Promise { return promise(vu, func() (any, error) { return r.ServerAddr(), nil }) - }, - "size": func() *sobek.Promise { + }), + "size": passiveCall(func() *sobek.Promise { return promise(vu, func() (any, error) { return r.Size(), nil }) - }, - "status": r.Status, - "statusText": r.StatusText, - "url": r.URL, - "text": func() *sobek.Promise { + }), + "status": passiveCall(r.Status), + "statusText": passiveCall(r.StatusText), + "url": passiveCall(r.URL), + "text": passiveCall(func() *sobek.Promise { return promise(vu, func() (any, error) { return r.Text() //nolint:wrapcheck }) - }, + }), } - return maps + return finishMapping(maps) } diff --git a/internal/js/modules/k6/browser/browser/route_mapping.go b/internal/js/modules/k6/browser/browser/route_mapping.go index 44b099201..6eac4181a 100644 --- a/internal/js/modules/k6/browser/browser/route_mapping.go +++ b/internal/js/modules/k6/browser/browser/route_mapping.go @@ -13,13 +13,13 @@ import ( // mapRoute to the JS module. func mapRoute(vu moduleVU, route *common.Route) mapping { - return mapping{ - "abort": func(reason string) *sobek.Promise { + return finishMapping(mapping{ + "abort": passiveCall(func(reason string) *sobek.Promise { return promise(vu, func() (any, error) { return nil, route.Abort(reason) }) - }, - "continue": func(opts sobek.Value) *sobek.Promise { + }), + "continue": passiveCall(func(opts sobek.Value) *sobek.Promise { copts, err := parseContinueOptions(vu.Context(), opts) return promise(vu, func() (any, error) { if err != nil { @@ -27,8 +27,8 @@ func mapRoute(vu moduleVU, route *common.Route) mapping { } return nil, route.Continue(copts) }) - }, - "fulfill": func(opts sobek.Value) *sobek.Promise { + }), + "fulfill": passiveCall(func(opts sobek.Value) *sobek.Promise { fopts, err := parseFulfillOptions(vu.Context(), opts) return promise(vu, func() (any, error) { if err != nil { @@ -36,11 +36,11 @@ func mapRoute(vu moduleVU, route *common.Route) mapping { } return nil, route.Fulfill(fopts) }) - }, - "request": func() mapping { + }), + "request": passiveCall(func() mapping { return mapRequest(vu, route.Request()) - }, - } + }), + }) } func parseContinueOptions(ctx context.Context, opts sobek.Value) (common.ContinueOptions, error) { diff --git a/internal/js/modules/k6/browser/browser/touchscreen_mapping.go b/internal/js/modules/k6/browser/browser/touchscreen_mapping.go index 01ea47aa6..275ab78d4 100644 --- a/internal/js/modules/k6/browser/browser/touchscreen_mapping.go +++ b/internal/js/modules/k6/browser/browser/touchscreen_mapping.go @@ -8,11 +8,15 @@ import ( // mapTouchscreen to the JS module. func mapTouchscreen(vu moduleVU, ts *common.Touchscreen) mapping { + return finishMapping(newTouchscreenMapping(vu, ts)) +} + +func newTouchscreenMapping(vu moduleVU, ts *common.Touchscreen) mapping { return mapping{ - "tap": func(x float64, y float64) *sobek.Promise { + "tap": networkCall(func(x float64, y float64) *sobek.Promise { return promise(vu, func() (result any, reason error) { return nil, ts.Tap(x, y) //nolint:wrapcheck }) - }, + }), } } diff --git a/internal/js/modules/k6/browser/browser/worker_mapping.go b/internal/js/modules/k6/browser/browser/worker_mapping.go index 6c94cef6f..4d5732423 100644 --- a/internal/js/modules/k6/browser/browser/worker_mapping.go +++ b/internal/js/modules/k6/browser/browser/worker_mapping.go @@ -6,7 +6,7 @@ import ( // mapWorker to the JS module. func mapWorker(_ moduleVU, w *common.Worker) mapping { - return mapping{ + return finishMapping(mapping{ "url": w.URL(), - } + }) } diff --git a/internal/js/modules/k6/browser/common/element_handle.go b/internal/js/modules/k6/browser/common/element_handle.go index 3f97a9211..51efcf30b 100644 --- a/internal/js/modules/k6/browser/common/element_handle.go +++ b/internal/js/modules/k6/browser/common/element_handle.go @@ -50,6 +50,14 @@ type ElementHandle struct { frame *Frame } +// Page returns the page that owns the element handle. +func (h *ElementHandle) Page() *Page { + if h == nil || h.frame == nil { + return nil + } + return h.frame.Page() +} + // String returns a string representation of ElementHandle. // It exists mostly for debugging where we don't want fmt.Sprintf to just // go through a complex object and try to stringify it. diff --git a/internal/js/modules/k6/browser/common/frame.go b/internal/js/modules/k6/browser/common/frame.go index 16e8ca1db..7e6320406 100644 --- a/internal/js/modules/k6/browser/common/frame.go +++ b/internal/js/modules/k6/browser/common/frame.go @@ -1668,6 +1668,15 @@ func (f *Frame) QueryAll(selector string) ([]*ElementHandle, error) { // Page returns page that owns frame. func (f *Frame) Page() *Page { + if f == nil { + return nil + } + if f.page != nil { + return f.page + } + if f.manager == nil { + return nil + } return f.manager.page } diff --git a/internal/js/modules/k6/browser/common/frame_manager.go b/internal/js/modules/k6/browser/common/frame_manager.go index ac6ba0bc2..35cf4185d 100644 --- a/internal/js/modules/k6/browser/common/frame_manager.go +++ b/internal/js/modules/k6/browser/common/frame_manager.go @@ -456,6 +456,9 @@ func (m *FrameManager) removeFramesRecursively(frame *Frame) error { if err := frame.detach(); err != nil { return fmt.Errorf("removing frames recursively: detaching frame: %w", err) } + if m.page != nil { + m.page.clearNetworkLoaderContext(cdp.FrameID(frame.ID())) + } m.framesMu.Lock() m.logger.Debugf("FrameManager:removeFramesRecursively:delParentFrame", diff --git a/internal/js/modules/k6/browser/common/frame_session.go b/internal/js/modules/k6/browser/common/frame_session.go index 5cedef4f7..83a1932ca 100644 --- a/internal/js/modules/k6/browser/common/frame_session.go +++ b/internal/js/modules/k6/browser/common/frame_session.go @@ -17,6 +17,7 @@ import ( "go.k6.io/k6/v2/internal/js/modules/k6/browser/k6ext" "go.k6.io/k6/v2/internal/js/modules/k6/browser/log" + k6common "go.k6.io/k6/v2/js/common" k6modules "go.k6.io/k6/v2/js/modules" k6metrics "go.k6.io/k6/v2/metrics" @@ -397,7 +398,17 @@ func (fs *FrameSession) parseAndEmitWebVitalMetric(object string) error { } state := fs.vu.State() - tags := state.Tags.GetCurrentValues().Tags + // Web Vitals are reported asynchronously through a CDP binding, long after the navigation that + // produced them. Reading live tags here would attribute the sample to whatever group/tags happen + // to be active at report time. When async metric context is enabled, prefer the context captured + // by the navigation operation instead, mirroring how NetworkManager attributes delayed requests. + tagsAndMeta := state.Tags.GetCurrentValues() + if k6common.AsyncMetricContextEnabled(state) { + if captured, ok := fs.page.getNetworkTagsAndMeta(); ok { + tagsAndMeta = captured + } + } + tags := tagsAndMeta.Tags if state.Options.SystemTags.Has(k6metrics.TagURL) { tags = handleURLTag(fs.page, wv.URL, http.MethodGet, tags) } diff --git a/internal/js/modules/k6/browser/common/frame_session_test.go b/internal/js/modules/k6/browser/common/frame_session_test.go new file mode 100644 index 000000000..39129036b --- /dev/null +++ b/internal/js/modules/k6/browser/common/frame_session_test.go @@ -0,0 +1,88 @@ +package common + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "go.k6.io/k6/v2/internal/features" + "go.k6.io/k6/v2/internal/js/modules/k6/browser/k6ext" + "go.k6.io/k6/v2/internal/js/modules/k6/browser/k6ext/k6test" + "go.k6.io/k6/v2/internal/js/modules/k6/browser/log" + k6metrics "go.k6.io/k6/v2/metrics" +) + +// reportWebVitalGroup builds a FrameSession backed by a test VU, captures a +// navigation's metric context under navGroup, then changes the live group tag +// to liveGroup before reporting an LCP web vital. It returns the group tag on +// the resulting buffered sample. asyncEnabled toggles the async-metric-context +// feature flag. +func reportWebVitalGroup(t *testing.T, asyncEnabled bool, navGroup, liveGroup string) string { + t.Helper() + + registry := k6metrics.NewRegistry() + k6m := k6ext.RegisterCustomMetrics(registry) + vu := k6test.NewVU(t) + vu.ActivateVU() + + state := vu.State() + state.FeatureFlags = &features.Flags{AsyncMetricContext: asyncEnabled} + + page := &Page{} + // Capture the navigation's metric context, then settle the operation so it + // becomes the page's most-recently-completed network operation, mirroring a + // page load finishing before the browser reports its web vitals. + state.Tags.Modify(func(tagsAndMeta *k6metrics.TagsAndMeta) { + tagsAndMeta.SetTag(k6metrics.TagGroup.String(), navGroup) + }) + finishAndRetain, _ := page.BeginNetworkOperation(state.Tags.GetCurrentValues()) + finishAndRetain() + + // The VU moves on: the live group tag no longer reflects the navigation that + // produced the web vital. + state.Tags.Modify(func(tagsAndMeta *k6metrics.TagsAndMeta) { + tagsAndMeta.SetTag(k6metrics.TagGroup.String(), liveGroup) + }) + + fs := &FrameSession{ + ctx: vu.Context(), + vu: vu, + page: page, + k6Metrics: k6m, + bufferedWebVitals: make(map[webVitalKey]webVitalSample), + logger: log.NewNullLogger(), + } + + const lcp = `{"Name":"LCP","Value":123.4,"Rating":"good","URL":"https://example.test/"}` + require.NoError(t, fs.parseAndEmitWebVitalMetric(lcp)) + require.Len(t, fs.bufferedWebVitals, 1) + + var group string + for _, wv := range fs.bufferedWebVitals { + g, ok := wv.sample.Tags.Get(k6metrics.TagGroup.String()) + require.True(t, ok) + group = g + } + return group +} + +// TestParseAndEmitWebVitalMetricUsesNavigationContext verifies that, with the +// async-metric-context feature enabled, a web vital reported asynchronously is +// attributed to the group active during the navigation that produced it, rather +// than whatever group happens to be active when the CDP binding event fires. +func TestParseAndEmitWebVitalMetricUsesNavigationContext(t *testing.T) { + t.Parallel() + + t.Run("enabled uses captured navigation group", func(t *testing.T) { + t.Parallel() + group := reportWebVitalGroup(t, true, "::nav", "::after") + assert.Equal(t, "::nav", group) + }) + + t.Run("disabled uses live group", func(t *testing.T) { + t.Parallel() + group := reportWebVitalGroup(t, false, "::nav", "::after") + assert.Equal(t, "::after", group) + }) +} diff --git a/internal/js/modules/k6/browser/common/http.go b/internal/js/modules/k6/browser/common/http.go index 5ca5c7408..4183ace35 100644 --- a/internal/js/modules/k6/browser/common/http.go +++ b/internal/js/modules/k6/browser/common/http.go @@ -20,6 +20,7 @@ import ( "go.k6.io/k6/v2/internal/js/modules/k6/browser/log" k6modules "go.k6.io/k6/v2/js/modules" + k6metrics "go.k6.io/k6/v2/metrics" ) // These ResourceTypes are duplicates of CDP's network.ResourceType. We want to work @@ -113,6 +114,8 @@ type Request struct { timestamp time.Time wallTime time.Time responseEndTiming float64 + tagsAndMeta k6metrics.TagsAndMeta + networkOperation *networkOperationContext } // NewRequestParams are input parameters for NewRequest. @@ -122,6 +125,8 @@ type NewRequestParams struct { redirectChain []*Request interceptionID fetch.RequestID allowInterception bool + tagsAndMeta k6metrics.TagsAndMeta + networkOperation *networkOperationContext } // NewRequest creates a new HTTP request. @@ -176,6 +181,8 @@ func NewRequest(ctx context.Context, logger *log.Logger, rp NewRequestParams) (* headers: make(map[string][]string, len(ev.Request.Headers)), ctx: ctx, rawHeadersCh: make(chan struct{}), + tagsAndMeta: rp.tagsAndMeta, + networkOperation: rp.networkOperation, } for n, v := range ev.Request.Headers { if s, ok := v.(string); ok { diff --git a/internal/js/modules/k6/browser/common/js_handle.go b/internal/js/modules/k6/browser/common/js_handle.go index 46e448367..055b18fc5 100644 --- a/internal/js/modules/k6/browser/common/js_handle.go +++ b/internal/js/modules/k6/browser/common/js_handle.go @@ -87,6 +87,19 @@ func (h *BaseJSHandle) AsElement() *ElementHandle { return nil } +// Page returns the page that owns this handle, or nil when the handle is not +// associated with a frame (e.g. a worker or isolated-world execution context). +func (h *BaseJSHandle) Page() *Page { + if h == nil || h.execCtx == nil { + return nil + } + frame := h.execCtx.Frame() + if frame == nil { + return nil + } + return frame.Page() +} + // Dispose releases the remote object. func (h *BaseJSHandle) Dispose() error { err := h.dispose() diff --git a/internal/js/modules/k6/browser/common/locator.go b/internal/js/modules/k6/browser/common/locator.go index b28b5bb9a..e748d1f31 100644 --- a/internal/js/modules/k6/browser/common/locator.go +++ b/internal/js/modules/k6/browser/common/locator.go @@ -26,6 +26,14 @@ type Locator struct { log *log.Logger } +// Page returns the page that owns the locator. +func (l *Locator) Page() *Page { + if l == nil || l.frame == nil { + return nil + } + return l.frame.Page() +} + // LocatorOptions allows modifying the [Locator] behavior. type LocatorOptions struct { // Matches only elements that contain the specified text. diff --git a/internal/js/modules/k6/browser/common/network_manager.go b/internal/js/modules/k6/browser/common/network_manager.go index 2f490d227..811fc670c 100644 --- a/internal/js/modules/k6/browser/common/network_manager.go +++ b/internal/js/modules/k6/browser/common/network_manager.go @@ -17,6 +17,7 @@ import ( "go.k6.io/k6/v2/internal/js/modules/k6/browser/k6ext" + k6common "go.k6.io/k6/v2/js/common" k6modules "go.k6.io/k6/v2/js/modules" k6lib "go.k6.io/k6/v2/lib" k6netext "go.k6.io/k6/v2/lib/netext" @@ -210,10 +211,61 @@ func (m *NetworkManager) deleteRequestByID(reqID network.RequestID) { delete(m.reqIDToRequest, reqID) } +func (m *NetworkManager) networkTagsAndMeta( + state *k6lib.State, + event *network.EventRequestWillBeSent, + redirectChain []*Request, +) (k6metrics.TagsAndMeta, *networkOperationContext) { + if !k6common.AsyncMetricContextEnabled(state) { + return k6metrics.TagsAndMeta{}, nil + } + if len(redirectChain) > 0 { + previous := redirectChain[len(redirectChain)-1] + operation := previous.networkOperation + if m.frameManager != nil && m.frameManager.page != nil { + _, bindLoaderContext := requestLoaderContext(event) + if bindLoaderContext { + m.frameManager.page.bindNetworkLoaderOperation(event.FrameID, event.LoaderID, operation) + } + } + return previous.tagsAndMeta, operation + } + if m.frameManager != nil && m.frameManager.page != nil { + preferLoaderContext, bindLoaderContext := requestLoaderContext(event) + if tagsAndMeta, operation, ok := m.frameManager.page.getNetworkTagsAndMetaForRequest( + event.FrameID, event.LoaderID, preferLoaderContext, bindLoaderContext, + ); ok { + return tagsAndMeta, operation + } + } + return state.Tags.GetCurrentValues(), nil +} + +func requestLoaderContext(event *network.EventRequestWillBeSent) (prefer, bind bool) { + bind = event.Type == network.ResourceTypeDocument + initiatorType := network.InitiatorTypeOther + if event.Initiator != nil { + initiatorType = event.Initiator.Type + } + // A loader identifies navigation and parser-driven resource traffic, but it is also shared by + // unrelated fetches later in the document. Keep script traffic on the operation fallback. + prefer = bind || initiatorType == network.InitiatorTypeParser || + initiatorType == network.InitiatorTypePreload || + initiatorType == network.InitiatorTypeSignedExchange + return prefer, bind +} + func (m *NetworkManager) emitRequestMetrics(req *Request) { state := m.vu.State() + if state == nil { + return // CDP events can arrive after iteration teardown. + } - tags := state.Tags.GetCurrentValues().Tags + tagsAndMeta := req.tagsAndMeta + if tagsAndMeta.Tags == nil { + tagsAndMeta = state.Tags.GetCurrentValues() + } + tags := tagsAndMeta.Tags if state.Options.SystemTags.Has(k6metrics.TagMethod) { tags = tags.With("method", req.method) } @@ -228,13 +280,17 @@ func (m *NetworkManager) emitRequestMetrics(req *Request) { TimeSeries: k6metrics.TimeSeries{Metric: m.customMetrics.BrowserDataSent, Tags: tags}, Value: float64(req.Size().Total()), Time: req.wallTime, + Metadata: tagsAndMeta.Metadata, }, }, }) } -func (m *NetworkManager) emitResponseMetrics(resp *Response, req *Request) { +func (m *NetworkManager) emitResponseMetrics(resp *Response, req *Request) { //nolint:funlen state := m.vu.State() + if state == nil { + return // CDP events can arrive after iteration teardown. + } // In some scenarios we might not receive a ResponseReceived CDP event, in // which case the response won't be created. So to emit as much metric data @@ -267,7 +323,11 @@ func (m *NetworkManager) emitResponseMetrics(resp *Response, req *Request) { "response is nil url:%s method:%s", req.url, req.method) } - tags := state.Tags.GetCurrentValues().Tags + tagsAndMeta := req.tagsAndMeta + if tagsAndMeta.Tags == nil { + tagsAndMeta = state.Tags.GetCurrentValues() + } + tags := tagsAndMeta.Tags if state.Options.SystemTags.Has(k6metrics.TagMethod) { tags = tags.With("method", req.method) } @@ -295,11 +355,13 @@ func (m *NetworkManager) emitResponseMetrics(resp *Response, req *Request) { TimeSeries: k6metrics.TimeSeries{Metric: m.customMetrics.BrowserHTTPReqDuration, Tags: tags}, Value: k6metrics.D(wallTime.Sub(req.wallTime)), Time: wallTime, + Metadata: tagsAndMeta.Metadata, }, { TimeSeries: k6metrics.TimeSeries{Metric: m.customMetrics.BrowserDataReceived, Tags: tags}, Value: float64(bodySize), Time: wallTime, + Metadata: tagsAndMeta.Metadata, }, }, }) @@ -311,6 +373,7 @@ func (m *NetworkManager) emitResponseMetrics(resp *Response, req *Request) { TimeSeries: k6metrics.TimeSeries{Metric: m.customMetrics.BrowserHTTPReqFailed, Tags: tags}, Value: failed, Time: wallTime, + Metadata: tagsAndMeta.Metadata, }, }, }) @@ -541,6 +604,7 @@ func (m *NetworkManager) onRequest(event *network.EventRequestWillBeSent, } else { redirectChain = make([]*Request, 0) } + tagsAndMeta, networkOperation := m.networkTagsAndMeta(m.vu.State(), event, redirectChain) var frame *Frame = nil var ok bool @@ -577,6 +641,8 @@ func (m *NetworkManager) onRequest(event *network.EventRequestWillBeSent, redirectChain: redirectChain, interceptionID: interceptionID, allowInterception: m.userReqInterceptionEnabled, + tagsAndMeta: tagsAndMeta, + networkOperation: networkOperation, }) if err != nil { m.logger.Errorf("NetworkManager", "creating request: %s", err) diff --git a/internal/js/modules/k6/browser/common/network_manager_test.go b/internal/js/modules/k6/browser/common/network_manager_test.go index 94bedf4e8..63e45922c 100644 --- a/internal/js/modules/k6/browser/common/network_manager_test.go +++ b/internal/js/modules/k6/browser/common/network_manager_test.go @@ -7,6 +7,7 @@ import ( "testing" "time" + "go.k6.io/k6/v2/internal/features" "go.k6.io/k6/v2/internal/js/modules/k6/browser/k6ext" "go.k6.io/k6/v2/internal/js/modules/k6/browser/k6ext/k6test" "go.k6.io/k6/v2/internal/js/modules/k6/browser/log" @@ -318,6 +319,146 @@ func TestNetworkManagerEmitRequestResponseMetricsTimingSkew(t *testing.T) { } } +func TestNetworkManagerMetricsRetainRequestTagsAndMetadata(t *testing.T) { + t.Parallel() + + registry := k6metrics.NewRegistry() + k6m := k6ext.RegisterCustomMetrics(registry) + vu := k6test.NewVU(t) + vu.ActivateVU() + + state := vu.State() + state.Tags.Modify(func(tagsAndMeta *k6metrics.TagsAndMeta) { + tagsAndMeta.SetTag(k6metrics.TagGroup.String(), "::request") + tagsAndMeta.SetTag("phase", "request") + tagsAndMeta.SetMetadata("trace", "request") + }) + + now := time.Now() + req, err := NewRequest(vu.Context(), log.NewNullLogger(), NewRequestParams{ + event: &network.EventRequestWillBeSent{ + Request: &network.Request{URL: "https://example.test/"}, + Timestamp: (*cdp.MonotonicTime)(&now), + WallTime: (*cdp.TimeSinceEpoch)(&now), + }, + tagsAndMeta: state.Tags.GetCurrentValues(), + }) + require.NoError(t, err) + + state.Tags.Modify(func(tagsAndMeta *k6metrics.TagsAndMeta) { + tagsAndMeta.SetTag(k6metrics.TagGroup.String(), "") + tagsAndMeta.SetTag("phase", "after") + tagsAndMeta.SetMetadata("trace", "after") + }) + + nm := &NetworkManager{ + ctx: vu.Context(), + vu: vu, + customMetrics: k6m, + eventInterceptor: &EventInterceptorMock{}, + } + nm.emitRequestMetrics(req) + resp := NewHTTPResponse(vu.Context(), req, &network.Response{ + URL: req.URL(), + Timing: &network.ResourceTiming{}, + }, (*cdp.MonotonicTime)(&now)) + nm.emitResponseMetrics(resp, req) + + n := vu.AssertSamples(func(sample k6metrics.Sample) { + group, ok := sample.Tags.Get(k6metrics.TagGroup.String()) + require.True(t, ok) + assert.Equal(t, "::request", group) + phase, ok := sample.Tags.Get("phase") + require.True(t, ok) + assert.Equal(t, "request", phase) + assert.Equal(t, "request", sample.Metadata["trace"]) + }) + assert.Equal(t, 4, n) +} + +func TestNetworkManagerRedirectKeepsLoaderOperation(t *testing.T) { + t.Parallel() + + nm, _ := newTestNetworkManager(t, k6lib.Options{}) + state := nm.vu.State() + state.FeatureFlags = &features.Flags{AsyncMetricContext: true} + page := &Page{} + nm.frameManager.page = page + + state.Tags.Modify(func(tagsAndMeta *k6metrics.TagsAndMeta) { + tagsAndMeta.SetTag("operation", "navigation") + }) + navigationFinishAndRetain, _ := page.BeginNetworkOperation(state.Tags.GetCurrentValues()) + navigationTags, navigationOperation := nm.networkTagsAndMeta(state, &network.EventRequestWillBeSent{ + FrameID: cdp.FrameID("frame"), + LoaderID: cdp.LoaderID("initial-loader"), + Type: network.ResourceTypeDocument, + }, nil) + require.NotNil(t, navigationOperation) + navigationFinishAndRetain() + + state.Tags.Modify(func(tagsAndMeta *k6metrics.TagsAndMeta) { + tagsAndMeta.SetTag("operation", "unrelated") + }) + unrelatedFinishAndRetain, _ := page.BeginNetworkOperation(state.Tags.GetCurrentValues()) + defer unrelatedFinishAndRetain() + + redirectTags, redirectOperation := nm.networkTagsAndMeta(state, &network.EventRequestWillBeSent{ + FrameID: cdp.FrameID("frame"), + LoaderID: cdp.LoaderID("redirect-loader"), + Type: network.ResourceTypeDocument, + }, []*Request{{ + tagsAndMeta: navigationTags, + networkOperation: navigationOperation, + }}) + assert.Same(t, navigationOperation, redirectOperation) + operation, _ := redirectTags.Tags.Get("operation") + assert.Equal(t, "navigation", operation) + + loaderTags, loaderOperation, ok := page.getNetworkTagsAndMetaForRequest( + cdp.FrameID("frame"), cdp.LoaderID("redirect-loader"), true, false, + ) + require.True(t, ok) + assert.Same(t, navigationOperation, loaderOperation) + operation, _ = loaderTags.Tags.Get("operation") + assert.Equal(t, "navigation", operation) +} + +func TestRequestLoaderContext(t *testing.T) { + t.Parallel() + + for _, testCase := range []struct { + name string + typ network.ResourceType + initiator *network.Initiator + prefer bool + bind bool + }{ + {name: "document", typ: network.ResourceTypeDocument, prefer: true, bind: true}, + {name: "parser", initiator: &network.Initiator{Type: network.InitiatorTypeParser}, prefer: true}, + {name: "preload", initiator: &network.Initiator{Type: network.InitiatorTypePreload}, prefer: true}, + { + name: "signed exchange", + initiator: &network.Initiator{Type: network.InitiatorTypeSignedExchange}, + prefer: true, + }, + {name: "script", initiator: &network.Initiator{Type: network.InitiatorTypeScript}}, + {name: "preflight", initiator: &network.Initiator{Type: network.InitiatorTypePreflight}}, + {name: "unknown initiator"}, + } { + t.Run(testCase.name, func(t *testing.T) { + t.Parallel() + + prefer, bind := requestLoaderContext(&network.EventRequestWillBeSent{ + Type: testCase.typ, + Initiator: testCase.initiator, + }) + assert.Equal(t, testCase.prefer, prefer) + assert.Equal(t, testCase.bind, bind) + }) + } +} + func TestRequestForOnLoadingFinished(t *testing.T) { t.Parallel() diff --git a/internal/js/modules/k6/browser/common/page.go b/internal/js/modules/k6/browser/common/page.go index 108b7334c..2be0fd43c 100644 --- a/internal/js/modules/k6/browser/common/page.go +++ b/internal/js/modules/k6/browser/common/page.go @@ -27,6 +27,7 @@ import ( "go.k6.io/k6/v2/internal/js/modules/k6/browser/k6ext" "go.k6.io/k6/v2/internal/js/modules/k6/browser/log" + k6metrics "go.k6.io/k6/v2/metrics" ) // BlankPage represents a blank page. @@ -273,6 +274,15 @@ type Page struct { backgroundPage bool + // Supplies the fallback for requests that cannot be associated with an active browser operation. + networkFallbackTagsAndMeta atomic.Pointer[k6metrics.TagsAndMeta] + networkRecentOperation *networkOperationContext + networkOperationID atomic.Uint64 + networkOperations []*networkOperationContext + networkLoaderOperations map[cdp.LoaderID]*networkOperationContext + networkFrameLoaders map[cdp.FrameID]cdp.LoaderID + networkOperationsMu sync.Mutex + eventCh chan Event eventHandlers map[PageEventName][]pageEventHandlerRecord eventHandlersMu sync.RWMutex @@ -325,6 +335,14 @@ func NewPage( logger: logger, } + // Popup pages are created off the event loop, so inherit the context of the operation that opened + // them, or the opener's fallback when no operation is active. + if opener != nil { + if tagsAndMeta, ok := opener.getNetworkTagsAndMeta(); ok { + p.networkFallbackTagsAndMeta.Store(&tagsAndMeta) + } + } + p.logger.Debugf("Page:NewPage", "sid:%v tid:%v backgroundPage:%t", p.sessionID(), tid, bp) @@ -1226,6 +1244,123 @@ func (p *Page) GetTouchscreen() *Touchscreen { return p.Touchscreen } +type networkOperationContext struct { + id uint64 + tagsAndMeta k6metrics.TagsAndMeta +} + +// SetNetworkFallbackTagsAndMeta records the tags and metadata for requests that cannot be +// associated with an active browser operation. +func (p *Page) SetNetworkFallbackTagsAndMeta(tagsAndMeta k6metrics.TagsAndMeta) { + p.networkFallbackTagsAndMeta.Store(&tagsAndMeta) +} + +// BeginNetworkOperation makes tagsAndMeta available to requests observed while the operation is +// active. Calling finishAndRetain keeps it for CDP request events that arrive just after the +// operation settles, including unsuccessful settlement. Calling abortAndDiscard instead removes it +// when the browser operation was not launched. +func (p *Page) BeginNetworkOperation( + tagsAndMeta k6metrics.TagsAndMeta, +) (finishAndRetain, abortAndDiscard func()) { + operation := &networkOperationContext{ + id: p.networkOperationID.Add(1), + tagsAndMeta: tagsAndMeta, + } + p.networkOperationsMu.Lock() + p.networkOperations = append(p.networkOperations, operation) + p.networkOperationsMu.Unlock() + + var once sync.Once + remove := func(keepRecent bool) { + once.Do(func() { + p.networkOperationsMu.Lock() + defer p.networkOperationsMu.Unlock() + if keepRecent { + p.networkRecentOperation = operation + } + for i := range p.networkOperations { + if p.networkOperations[i].id != operation.id { + continue + } + p.networkOperations = append(p.networkOperations[:i], p.networkOperations[i+1:]...) + return + } + }) + } + return func() { remove(true) }, func() { remove(false) } +} + +func (p *Page) getNetworkTagsAndMeta() (k6metrics.TagsAndMeta, bool) { + tagsAndMeta, _, ok := p.getNetworkTagsAndMetaForRequest("", "", false, false) + return tagsAndMeta, ok +} + +func (p *Page) getNetworkTagsAndMetaForRequest( + frameID cdp.FrameID, + loaderID cdp.LoaderID, + preferLoaderContext bool, + bindLoaderContext bool, +) (k6metrics.TagsAndMeta, *networkOperationContext, bool) { + p.networkOperationsMu.Lock() + var operation *networkOperationContext + if preferLoaderContext && loaderID != "" { + operation = p.networkLoaderOperations[loaderID] + } + if operation == nil { + if n := len(p.networkOperations); n > 0 { + operation = p.networkOperations[n-1] + } else { + operation = p.networkRecentOperation + } + } + if bindLoaderContext && loaderID != "" && operation != nil { + p.bindNetworkLoaderOperationLocked(frameID, loaderID, operation) + } + p.networkOperationsMu.Unlock() + + if operation != nil { + return operation.tagsAndMeta, operation, true + } + + if tagsAndMeta := p.networkFallbackTagsAndMeta.Load(); tagsAndMeta != nil { + return *tagsAndMeta, nil, true + } + return k6metrics.TagsAndMeta{}, nil, false +} + +func (p *Page) bindNetworkLoaderOperation( + frameID cdp.FrameID, loaderID cdp.LoaderID, operation *networkOperationContext, +) { + if loaderID == "" || operation == nil { + return + } + p.networkOperationsMu.Lock() + defer p.networkOperationsMu.Unlock() + p.bindNetworkLoaderOperationLocked(frameID, loaderID, operation) +} + +func (p *Page) bindNetworkLoaderOperationLocked( + frameID cdp.FrameID, loaderID cdp.LoaderID, operation *networkOperationContext, +) { + if p.networkLoaderOperations == nil { + p.networkLoaderOperations = make(map[cdp.LoaderID]*networkOperationContext) + p.networkFrameLoaders = make(map[cdp.FrameID]cdp.LoaderID) + } + if previousLoaderID := p.networkFrameLoaders[frameID]; previousLoaderID != loaderID { + delete(p.networkLoaderOperations, previousLoaderID) + } + p.networkLoaderOperations[loaderID] = operation + p.networkFrameLoaders[frameID] = loaderID +} + +func (p *Page) clearNetworkLoaderContext(frameID cdp.FrameID) { + p.networkOperationsMu.Lock() + loaderID := p.networkFrameLoaders[frameID] + delete(p.networkLoaderOperations, loaderID) + delete(p.networkFrameLoaders, frameID) + p.networkOperationsMu.Unlock() +} + // Goto will navigate the page to the specified URL and return a HTTP response object. func (p *Page) Goto(url string, opts *FrameGotoOptions) (*Response, error) { p.logger.Debugf("Page:Goto", "sid:%v url:%q", p.sessionID(), url) diff --git a/internal/js/modules/k6/browser/common/page_test.go b/internal/js/modules/k6/browser/common/page_test.go index d85e51af9..9af4d9fc8 100644 --- a/internal/js/modules/k6/browser/common/page_test.go +++ b/internal/js/modules/k6/browser/common/page_test.go @@ -5,8 +5,11 @@ import ( "errors" "testing" + "github.com/chromedp/cdproto/cdp" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "go.k6.io/k6/v2/metrics" ) // TestPageLocator can be removed later on when we add integration @@ -166,3 +169,94 @@ func TestPageOn(t *testing.T) { assert.Len(t, p.eventHandlers["metric"], 1) }) } + +func TestPageNetworkOperationContext(t *testing.T) { + t.Parallel() + + registry := metrics.NewRegistry() + metricContext := func(name string) metrics.TagsAndMeta { + return metrics.TagsAndMeta{ + Tags: registry.RootTagSet().With("context", name), + Metadata: map[string]string{"context": name}, + } + } + contextName := func(tagsAndMeta metrics.TagsAndMeta) string { + name, _ := tagsAndMeta.Tags.Get("context") + assert.Equal(t, name, tagsAndMeta.Metadata["context"]) + return name + } + + p := &Page{} + p.SetNetworkFallbackTagsAndMeta(metricContext("fallback")) + tagsAndMeta, ok := p.getNetworkTagsAndMeta() + require.True(t, ok) + assert.Equal(t, "fallback", contextName(tagsAndMeta)) + + firstFinishAndRetain, _ := p.BeginNetworkOperation(metricContext("first")) + secondFinishAndRetain, _ := p.BeginNetworkOperation(metricContext("second")) + + tagsAndMeta, ok = p.getNetworkTagsAndMeta() + require.True(t, ok) + assert.Equal(t, "second", contextName(tagsAndMeta)) + + firstFinishAndRetain() + tagsAndMeta, ok = p.getNetworkTagsAndMeta() + require.True(t, ok) + assert.Equal(t, "second", contextName(tagsAndMeta)) + + secondFinishAndRetain() + secondFinishAndRetain() + tagsAndMeta, ok = p.getNetworkTagsAndMeta() + require.True(t, ok) + assert.Equal(t, "second", contextName(tagsAndMeta)) + + _, failedAbortAndDiscard := p.BeginNetworkOperation(metricContext("failed")) + failedAbortAndDiscard() + tagsAndMeta, ok = p.getNetworkTagsAndMeta() + require.True(t, ok) + assert.Equal(t, "second", contextName(tagsAndMeta)) +} + +func TestPageNetworkLoaderContextOutlivesUnrelatedCalls(t *testing.T) { + t.Parallel() + + registry := metrics.NewRegistry() + metricContext := func(name string) metrics.TagsAndMeta { + return metrics.TagsAndMeta{Tags: registry.RootTagSet().With("context", name)} + } + contextName := func(tagsAndMeta metrics.TagsAndMeta) string { + name, _ := tagsAndMeta.Tags.Get("context") + return name + } + + p := &Page{} + navigationFinishAndRetain, _ := p.BeginNetworkOperation(metricContext("navigation")) + tagsAndMeta, _, ok := p.getNetworkTagsAndMetaForRequest( + cdp.FrameID("frame"), cdp.LoaderID("loader"), true, true, + ) + require.True(t, ok) + assert.Equal(t, "navigation", contextName(tagsAndMeta)) + navigationFinishAndRetain() + + inspectionFinishAndRetain, _ := p.BeginNetworkOperation(metricContext("inspection")) + inspectionFinishAndRetain() + + tagsAndMeta, _, ok = p.getNetworkTagsAndMetaForRequest( + cdp.FrameID("frame"), cdp.LoaderID("loader"), true, false, + ) + require.True(t, ok) + assert.Equal(t, "navigation", contextName(tagsAndMeta)) + + tagsAndMeta, _, ok = p.getNetworkTagsAndMetaForRequest( + cdp.FrameID("frame"), cdp.LoaderID("loader"), false, false, + ) + require.True(t, ok) + assert.Equal(t, "inspection", contextName(tagsAndMeta)) + + p.clearNetworkLoaderContext(cdp.FrameID("frame")) + tagsAndMeta, _, ok = p.getNetworkTagsAndMetaForRequest( + cdp.FrameID("frame"), cdp.LoaderID("loader"), true, false, + ) + require.True(t, ok) + assert.Equal(t, "inspection", contextName(tagsAndMeta)) +} diff --git a/internal/js/modules/k6/browser/tests/asyncgroup_test.go b/internal/js/modules/k6/browser/tests/asyncgroup_test.go new file mode 100644 index 000000000..def167968 --- /dev/null +++ b/internal/js/modules/k6/browser/tests/asyncgroup_test.go @@ -0,0 +1,615 @@ +package tests + +import ( + "fmt" + "net/http" + "strings" + "sync" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "go.k6.io/k6/v2/internal/features" + k6mod "go.k6.io/k6/v2/internal/js/modules/k6" + k6exec "go.k6.io/k6/v2/internal/js/modules/k6/execution" + k6common "go.k6.io/k6/v2/js/common" + "go.k6.io/k6/v2/metrics" +) + +func prepareAsyncGroupBrowser(t *testing.T, tb *testBrowser) { + t.Helper() + tb.vu.StartIteration(t) + tb.vu.State().FeatureFlags = &features.Flags{AsyncMetricContext: true} + tb.vu.Runtime().SetAsyncContextTracker(k6common.NewMetricContextTracker(tb.vu.State)) + + k6Instance := k6mod.New().NewModuleInstance(tb.vu) + tb.vu.SetVar(t, "k6", k6Instance.Exports().Named) + execInstance := k6exec.New().NewModuleInstance(tb.vu) + tb.vu.SetVar(t, "exec", execInstance.Exports().Default) +} + +func collectBrowserSamples(tb *testBrowser) []metrics.Sample { + var samples []metrics.Sample + tb.vu.AssertSamples(func(sample metrics.Sample) { + samples = append(samples, sample) + }) + return samples +} + +func assertBrowserCheckGroups(t *testing.T, samples []metrics.Sample, expected map[string]string) { + t.Helper() + + seen := make(map[string]bool, len(expected)) + for _, sample := range samples { + if sample.Metric.Name != metrics.ChecksName { + continue + } + name, ok := sample.Tags.Get(metrics.TagCheck.String()) + require.True(t, ok) + expectedGroup, ok := expected[name] + require.Truef(t, ok, "unexpected check %q", name) + assert.Equal(t, float64(1), sample.Value, "check %q failed", name) + group, _ := sample.Tags.Get(metrics.TagGroup.String()) + assert.Equal(t, expectedGroup, group, "check %q ran under wrong group", name) + seen[name] = true + } + for name := range expected { + assert.Truef(t, seen[name], "missing check %q", name) + } +} + +func TestAsyncGroupBrowserEventListeners(t *testing.T) { + t.Parallel() + + tb := newTestBrowser(t, withHTTPServer()) + prepareAsyncGroupBrowser(t, tb) + + serve := func(page, api, css string) { + tb.withHandler(page, func(w http.ResponseWriter, _ *http.Request) { + _, err := fmt.Fprintf(w, ` + + +`, css, api) + require.NoError(t, err) + }) + tb.withHandler(api, func(w http.ResponseWriter, _ *http.Request) { + _, err := fmt.Fprint(w, `{"ok":true}`) + require.NoError(t, err) + }) + tb.withHandler(css, func(w http.ResponseWriter, _ *http.Request) { + w.Header().Set("Content-Type", "text/css") + _, err := fmt.Fprint(w, `body{background:#fff}`) + require.NoError(t, err) + }) + } + serve("/home1", "/api1", "/style1.css") + serve("/home2", "/api2", "/style2.css") + + _, err := tb.vu.RunAsync(t, ` + async function loadPageInGroup(groupName, label, url, createFromContext) { + await k6.group(groupName, async () => { + let context; + let page; + if (createFromContext) { + context = await browser.newContext(); + page = await context.newPage(); + } else { + page = await browser.newPage(); + context = page.context(); + } + exec.vu.metrics.tags.owner = label + ':registered'; + page.on('request', (request) => { + k6.check(null, {[label]: true}); + }); + exec.vu.metrics.tags.owner = label + ':active'; + await page.goto(url, {waitUntil: 'networkidle'}); + await page.close(); + await context.close(); + }); + } + + await loadPageInGroup('page1', 'page1', '%s', false); + await loadPageInGroup('page2', 'page2', '%s', true); + `, tb.url("/home1"), tb.url("/home2")) + require.NoError(t, err) + + samples := collectBrowserSamples(tb) + assertBrowserCheckGroups(t, samples, map[string]string{ + "page1": "::page1", + "page2": "::page2", + }) + for _, sample := range samples { + if sample.Metric.Name != metrics.ChecksName { + continue + } + name, _ := sample.Tags.Get(metrics.TagCheck.String()) + owner, _ := sample.Tags.Get("owner") + assert.Equal(t, name+":registered", owner, "check %q used the wrong metric context", name) + } + + netGroups := map[string]int{} + var netSamples int + for _, s := range samples { + switch s.Metric.Name { + case "browser_data_sent", "browser_data_received": + netSamples++ + g, _ := s.Tags.Get("group") + netGroups[g]++ + } + } + require.Positive(t, netSamples, "expected browser network metric samples") + assert.Zero(t, netGroups[""], + "browser network metrics must not be attributed to the root group; got distribution %v", netGroups) + assert.Positive(t, netGroups["::page1"], "expected browser network metrics attributed to ::page1") + assert.Positive(t, netGroups["::page2"], "expected browser network metrics attributed to ::page2") +} + +func TestAsyncGroupBrowserTaskCallbacks(t *testing.T) { + t.Parallel() + + tb := newTestBrowser(t, withHTTPServer()) + prepareAsyncGroupBrowser(t, tb) + tb.withHandler("/callbacks", func(w http.ResponseWriter, _ *http.Request) { + _, err := fmt.Fprint(w, `callbacks`) + require.NoError(t, err) + }) + + _, err := tb.vu.RunAsync(t, ` + await k6.group('callbacks', async () => { + const context = await browser.newContext(); + const contextEvent = context.waitForEvent('page', { + timeout: 5000, + predicate: () => { + k6.check(null, {'context.waitForEvent': true}); + return true; + }, + }); + const page = await context.newPage(); + await contextEvent; + + await page.route('%s', route => { + k6.check(null, {'page.route': true}); + route.continue(); + }); + const requestEvent = page.waitForEvent('request', { + timeout: 5000, + predicate: request => { + k6.check(null, {'page.waitForEvent': true}); + return request.url() === '%s'; + }, + }); + await page.goto('%s'); + await requestEvent; + await page.close(); + await context.close(); + }); + k6.check(null, {after: true}); + `, tb.url("/callbacks"), tb.url("/callbacks"), tb.url("/callbacks")) + require.NoError(t, err) + + assertBrowserCheckGroups(t, collectBrowserSamples(tb), map[string]string{ + "context.waitForEvent": "::callbacks", + "page.route": "::callbacks", + "page.waitForEvent": "::callbacks", + "after": "", + }) +} + +func TestAsyncGroupBrowserAsyncCallbacksKeepContextMutations(t *testing.T) { + t.Parallel() + + tb := newTestBrowser(t, withHTTPServer()) + prepareAsyncGroupBrowser(t, tb) + tb.withHandler("/async-callbacks", func(w http.ResponseWriter, _ *http.Request) { + _, err := fmt.Fprint(w, `async callbacks`) + require.NoError(t, err) + }) + + _, err := tb.vu.RunAsync(t, ` + exec.vu.metrics.tags.owner = 'root'; + exec.vu.metrics.tags.phase = 'root'; + exec.vu.metrics.metadata.trace = 'root'; + exec.vu.metrics.metadata.step = 'root'; + + const delay = ms => new Promise(resolve => setTimeout(resolve, ms)); + const deferred = () => { + let resolve; + let reject; + const promise = new Promise((res, rej) => { + resolve = res; + reject = rej; + }); + return {promise, resolve, reject}; + }; + const phases = ['first', 'second', 'third']; + const changeContext = (name, phase) => { + const value = name + ':' + phase; + exec.vu.metrics.tags.phase = value; + exec.vu.metrics.metadata.step = value; + }; + const crossBoundary = phase => phase === 'second' ? delay(0) : Promise.resolve(); + const recordContext = (name, phase) => k6.check(null, {[name + ':' + phase]: true}); + + await k6.group('browser-callbacks', async () => { + exec.vu.metrics.tags.owner = 'browser'; + exec.vu.metrics.metadata.trace = 'browser'; + const page = await browser.newPage(); + const eventFinished = deferred(); + const routeFinished = deferred(); + + page.on('request', async request => { + if (request.url() !== '%s') return; + try { + for (const phase of phases) { + changeContext('event', phase); + await crossBoundary(phase); + recordContext('event', phase); + } + eventFinished.resolve(); + } catch (error) { + eventFinished.reject(error); + } + }); + await page.route('%s', async route => { + try { + for (const phase of phases) { + changeContext('route', phase); + await crossBoundary(phase); + recordContext('route', phase); + } + await route.continue(); + routeFinished.resolve(); + } catch (error) { + routeFinished.reject(error); + } + }); + + await page.goto('%s'); + await Promise.all([eventFinished.promise, routeFinished.promise]); + await page.close(); + }); + k6.check(null, {after: true}); + `, tb.url("/async-callbacks"), tb.url("/async-callbacks"), tb.url("/async-callbacks")) + require.NoError(t, err) + + expected := map[string]string{"after": "root"} + for _, callback := range []string{"event", "route"} { + for _, phase := range []string{"first", "second", "third"} { + value := callback + ":" + phase + expected[value] = value + } + } + for _, sample := range collectBrowserSamples(tb) { + if sample.Metric.Name != metrics.ChecksName { + continue + } + name, _ := sample.Tags.Get(metrics.TagCheck.String()) + phase, ok := expected[name] + require.Truef(t, ok, "unexpected check %q", name) + assert.Equal(t, float64(1), sample.Value, "check %q failed", name) + assert.Equal(t, phase, sample.Metadata["step"], "check %q used the wrong metadata", name) + actualPhase, _ := sample.Tags.Get("phase") + assert.Equal(t, phase, actualPhase, "check %q used the wrong tag", name) + if name == "after" { + group, _ := sample.Tags.Get(metrics.TagGroup.String()) + assert.Empty(t, group) + owner, _ := sample.Tags.Get("owner") + assert.Equal(t, "root", owner) + assert.Equal(t, "root", sample.Metadata["trace"]) + } else { + group, _ := sample.Tags.Get(metrics.TagGroup.String()) + assert.Equal(t, "::browser-callbacks", group) + owner, _ := sample.Tags.Get("owner") + assert.Equal(t, "browser", owner) + assert.Equal(t, "browser", sample.Metadata["trace"]) + } + delete(expected, name) + } + require.Empty(t, expected) +} + +func TestAsyncGroupBrowserInputActions(t *testing.T) { + t.Parallel() + + tb := newTestBrowser(t, withHTTPServer()) + prepareAsyncGroupBrowser(t, tb) + tb.withHandler("/inputs", func(w http.ResponseWriter, _ *http.Request) { + _, err := fmt.Fprint(w, ` + + + +`) + require.NoError(t, err) + }) + for _, path := range []string{"/keyboard", "/mouse", "/touch"} { + tb.withHandler(path, func(w http.ResponseWriter, _ *http.Request) { + _, err := fmt.Fprint(w, `{"ok":true}`) + require.NoError(t, err) + }) + } + + _, err := tb.vu.RunAsync(t, ` + const context = await browser.newContext({hasTouch: true}); + const page = await context.newPage(); + await page.goto('%s'); + + const waitForRequest = path => page.waitForEvent('request', { + timeout: 5000, + predicate: request => request.url().endsWith(path), + }); + + await page.locator('#keyboard').focus(); + await k6.group('keyboard', async () => { + const request = waitForRequest('/keyboard'); + await page.keyboard.press('Enter'); + await request; + }); + + const mouseBox = await page.locator('#mouse').boundingBox(); + await k6.group('mouse', async () => { + const request = waitForRequest('/mouse'); + await page.mouse.click(mouseBox.x + mouseBox.width / 2, mouseBox.y + mouseBox.height / 2); + await request; + }); + + const touchBox = await page.locator('#touch').boundingBox(); + await k6.group('touch', async () => { + const request = waitForRequest('/touch'); + await page.touchscreen.tap(touchBox.x + touchBox.width / 2, touchBox.y + touchBox.height / 2); + await request; + }); + await page.close(); + await context.close(); + `, tb.url("/inputs")) + require.NoError(t, err) + + expected := map[string]string{ + tb.url("/keyboard"): "::keyboard", + tb.url("/mouse"): "::mouse", + tb.url("/touch"): "::touch", + } + seen := make(map[string]bool, len(expected)) + for _, sample := range collectBrowserSamples(tb) { + if sample.Metric.Name != "browser_data_sent" && sample.Metric.Name != "browser_data_received" { + continue + } + url, _ := sample.Tags.Get(metrics.TagURL.String()) + expectedGroup, ok := expected[url] + if !ok { + continue + } + group, _ := sample.Tags.Get(metrics.TagGroup.String()) + assert.Equal(t, expectedGroup, group, "%s had the wrong group", url) + seen[url] = true + } + for url := range expected { + assert.Truef(t, seen[url], "missing browser network samples for %s", url) + } +} + +func TestAsyncGroupPopupInheritsNetworkGroup(t *testing.T) { + t.Parallel() + + tb := newTestBrowser(t, withHTTPServer()) + prepareAsyncGroupBrowser(t, tb) + tb.withHandler("/opener", func(w http.ResponseWriter, _ *http.Request) { + _, err := fmt.Fprint(w, ``) + require.NoError(t, err) + }) + tb.withHandler("/popup", func(w http.ResponseWriter, _ *http.Request) { + _, err := fmt.Fprint(w, ``) + require.NoError(t, err) + }) + tb.withHandler("/popup-api", func(w http.ResponseWriter, _ *http.Request) { + _, err := fmt.Fprint(w, `{"ok":true}`) + require.NoError(t, err) + }) + + _, err := tb.vu.RunAsync(t, ` + await k6.group('popup', async () => { + const context = await browser.newContext(); + const opener = await context.newPage(); + const popupEvent = context.waitForEvent('page'); + await opener.goto('%s'); + await popupEvent; + await new Promise(resolve => setTimeout(resolve, 250)); + await context.close(); + }); + `, tb.url("/opener")) + require.NoError(t, err) + + var popupSamples int + for _, sample := range collectBrowserSamples(tb) { + if sample.Metric.Name != "browser_data_sent" && sample.Metric.Name != "browser_data_received" { + continue + } + url, _ := sample.Tags.Get(metrics.TagURL.String()) + if !strings.Contains(url, "/popup") { + continue + } + popupSamples++ + group, _ := sample.Tags.Get(metrics.TagGroup.String()) + assert.Equal(t, "::popup", group, "popup network sample had the wrong group") + } + require.Positive(t, popupSamples, "expected popup network metric samples") +} + +func TestAsyncGroupBrowserRequestRetainsTagsAndMetadata(t *testing.T) { + t.Parallel() + + tb := newTestBrowser(t, withHTTPServer()) + prepareAsyncGroupBrowser(t, tb) + + releaseSlow := make(chan struct{}) + var releaseOnce sync.Once + t.Cleanup(func() { releaseOnce.Do(func() { close(releaseSlow) }) }) + tb.vu.SetVar(t, "releaseSlow", func() { releaseOnce.Do(func() { close(releaseSlow) }) }) + tb.withHandler("/empty", func(w http.ResponseWriter, _ *http.Request) { + _, err := fmt.Fprint(w, `snapshot`) + require.NoError(t, err) + }) + tb.withHandler("/slow", func(w http.ResponseWriter, r *http.Request) { + select { + case <-releaseSlow: + case <-r.Context().Done(): + } + _, err := fmt.Fprint(w, `{"ok":true}`) + require.NoError(t, err) + }) + + _, err := tb.vu.RunAsync(t, ` + const page = await browser.newPage(); + await page.goto('%s'); + const started = page.waitForEvent('request', { + timeout: 5000, + predicate: request => request.url() === '%s', + }); + + exec.vu.metrics.tags.phase = 'request'; + exec.vu.metrics.metadata.trace = 'request'; + const slow = k6.group('request', () => page.evaluate(() => fetch('%s'))); + // Wait until NetworkManager has created the Request and copied the page snapshot. + await started; + + exec.vu.metrics.tags.phase = 'after'; + exec.vu.metrics.metadata.trace = 'after'; + k6.group('after', () => page.url()); + + releaseSlow(); + await slow; + await page.close(); + `, tb.url("/empty"), tb.url("/slow"), tb.url("/slow")) + require.NoError(t, err) + + var samples int + for _, sample := range collectBrowserSamples(tb) { + url, _ := sample.Tags.Get(metrics.TagURL.String()) + if url != tb.url("/slow") { + continue + } + samples++ + group, _ := sample.Tags.Get(metrics.TagGroup.String()) + assert.Equal(t, "::request", group) + phase, _ := sample.Tags.Get("phase") + assert.Equal(t, "request", phase) + assert.Equal(t, "request", sample.Metadata["trace"]) + } + require.Positive(t, samples, "expected browser network metric samples for the delayed request") +} + +func TestAsyncGroupBrowserReadOnlyCallDoesNotRetagActiveOperation(t *testing.T) { + t.Parallel() + + tb := newTestBrowser(t, withHTTPServer()) + prepareAsyncGroupBrowser(t, tb) + tb.withHandler("/empty", func(w http.ResponseWriter, _ *http.Request) { + _, err := fmt.Fprint(w, `operation context + +`) + require.NoError(t, err) + }) + for _, path := range []string{"/operation", "/locator", "/frame", "/element", "/element-handle"} { + tb.withHandler(path, func(w http.ResponseWriter, _ *http.Request) { + _, err := fmt.Fprint(w, `{"ok":true}`) + require.NoError(t, err) + }) + } + + _, err := tb.vu.RunAsync(t, ` + const page = await browser.newPage(); + await page.goto('%s'); + + const operation = k6.group('operation', () => { + exec.vu.metrics.tags.phase = 'operation'; + exec.vu.metrics.metadata.trace = 'operation'; + return page.evaluate(() => new Promise((resolve, reject) => { + setTimeout(() => fetch('%s').then(() => resolve(), reject), 100); + })); + }); + + await new Promise(resolve => setTimeout(resolve, 25)); + k6.group('inspection', () => { + exec.vu.metrics.tags.phase = 'inspection'; + exec.vu.metrics.metadata.trace = 'inspection'; + page.url(); + }); + + await operation; + + const locator = page.locator('#request'); + const locatorResponse = page.waitForResponse('%s'); + await k6.group('locator-operation', () => { + exec.vu.metrics.tags.phase = 'locator'; + exec.vu.metrics.metadata.trace = 'locator'; + return locator.click(); + }); + await locatorResponse; + + const frame = page.mainFrame(); + await k6.group('frame-operation', () => { + exec.vu.metrics.tags.phase = 'frame'; + exec.vu.metrics.metadata.trace = 'frame'; + return frame.evaluate(() => fetch('%s').then(() => null)); + }); + + const element = await page.$('#request'); + await k6.group('element-operation', () => { + exec.vu.metrics.tags.phase = 'element'; + exec.vu.metrics.metadata.trace = 'element'; + return element.evaluate((_, url) => fetch(url).then(() => null), '%s'); + }); + + const elementHandleResponse = page.waitForResponse('%s'); + const evaluatedHandle = await k6.group('element-handle-operation', () => { + exec.vu.metrics.tags.phase = 'element-handle'; + exec.vu.metrics.metadata.trace = 'element-handle'; + return element.evaluateHandle((node, url) => { + fetch(url); + return node; + }, '%s'); + }); + await elementHandleResponse; + await evaluatedHandle.dispose(); + + await page.close(); + `, tb.url("/empty"), tb.url("/operation"), tb.url("/locator"), tb.url("/frame"), + tb.url("/element"), tb.url("/element-handle"), tb.url("/element-handle")) + require.NoError(t, err) + + expected := map[string]struct { + group string + phase string + }{ + tb.url("/operation"): {group: "::operation", phase: "operation"}, + tb.url("/locator"): {group: "::locator-operation", phase: "locator"}, + tb.url("/frame"): {group: "::frame-operation", phase: "frame"}, + tb.url("/element"): {group: "::element-operation", phase: "element"}, + tb.url("/element-handle"): { + group: "::element-handle-operation", phase: "element-handle", + }, + } + seen := make(map[string]bool, len(expected)) + for _, sample := range collectBrowserSamples(tb) { + url, _ := sample.Tags.Get(metrics.TagURL.String()) + want, ok := expected[url] + if !ok { + continue + } + seen[url] = true + group, _ := sample.Tags.Get(metrics.TagGroup.String()) + assert.Equal(t, want.group, group) + phase, _ := sample.Tags.Get("phase") + assert.Equal(t, want.phase, phase) + assert.Equal(t, want.phase, sample.Metadata["trace"]) + } + for url := range expected { + assert.Truef(t, seen[url], "expected browser network metric samples for %s", url) + } +} From 3aee1add8bf1c2483ef60a20437276ae044b1a19 Mon Sep 17 00:00:00 2001 From: Inanc Gumus Date: Mon, 21 Sep 2026 11:05:42 -0400 Subject: [PATCH 170/182] Bump k6 version to 2.3.0 (#6417) --- internal/build/version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/build/version.go b/internal/build/version.go index 0e2fae694..5c8283924 100644 --- a/internal/build/version.go +++ b/internal/build/version.go @@ -3,7 +3,7 @@ package build // Version contains the current version of k6 // represented using Semantic Versioning expression. -const Version = "2.2.0" +const Version = "2.3.0" // BuildOrigin records how this binary was built, e.g. "release", and a build command sets it with // -ldflags "-X go.k6.io/k6/v2/internal/build.BuildOrigin=release". From e0887846143ab176d4b5483c9d52cf3b3e009f1a Mon Sep 17 00:00:00 2001 From: Inanc Gumus Date: Mon, 21 Sep 2026 11:05:52 -0400 Subject: [PATCH 171/182] Add v2.3.0 release notes (#6389) * Add v2.3.0 release notes Starts the v2.3.0 cycle. The release notes file has to exist on master before the tag is pushed, because build.yml builds the GitHub release body from 'release notes/v2.3.0.md'. Seeded from the template; entries land as PRs merge. * Update v2.3.0 release notes * Show how once transforms a duration scenario * Include the latest merged release fixes * Explain scenario selection before single-run mode Show how to run an existing workload without script edits, then combine selection with once for focused smoke tests. Related: #6360 * Preserve the existing once release documentation Keep the combination example under scenario selection and restore the existing once section unchanged. * Add JavaScript features and proxy timing fix * Document async groups and timer fixes * Include usage-report help fix in release notes * Add browser context race fix to release notes * Pin release notes docs link to v2.3 * Note browser role-selector fixture update * Use straight quotes in release notes * Link to docs for scenario selection with once * Update async guidance and dependency notes * Add browser and random-value fixes to notes * Document REST execution results in release notes * Credit REST status external contributor * Update release dependency versions * Remove blank lines between release note items --- release notes/v2.3.0.md | 233 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 233 insertions(+) create mode 100644 release notes/v2.3.0.md diff --git a/release notes/v2.3.0.md b/release notes/v2.3.0.md new file mode 100644 index 000000000..8b2eb0b36 --- /dev/null +++ b/release notes/v2.3.0.md @@ -0,0 +1,233 @@ +k6 `v2.3.0` is here 🎉! This release includes: + +- A `--scenario` flag to run selected parts of a test without editing the script. +- A `--once` flag to reuse load-test scripts for smoke and functional testing. +- Experimental async `group()` support that keeps metrics in the right group across `await`. +- Built-in byte encoding, Set operations, and raw JSON values. +- Opt-in fetching of missing TLS certificates for servers that work in browsers but fail in k6. +- Static labels for Prometheus remote write, nanosecond log timestamps, and WebSocket ready-state constants. + +## New features + +### Run selected scenarios [#6360](https://github.com/grafana/k6/pull/6360) + +When a script tests several services or user journeys, you may only need to run the part you are working on. The new `--scenario` flag lets you select named scenarios without editing the script, adding environment-variable selection code, or splitting it into separate scripts. This addresses the long-standing [request to run a subset of scenarios](https://github.com/grafana/k6/issues/2780). + +For example, this script defines two workloads: + +```js +import http from 'k6/http'; + +export const options = { + scenarios: { + homepage: { + executor: 'shared-iterations', + exec: 'homepage', + vus: 2, + iterations: 10, + }, + contacts: { + executor: 'shared-iterations', + exec: 'contacts', + vus: 1, + iterations: 5, + }, + }, +}; + +export function homepage() { + http.get('https://test.k6.io/'); +} + +export function contacts() { + http.get('https://test.k6.io/contacts.php'); +} +``` + +Run only the homepage workload, keeping its two VUs and ten total iterations: + +```shell +k6 run --scenario homepage script.js +``` + +Select multiple scenarios with comma-separated names: + +```shell +k6 run --scenario homepage,contacts script.js +``` + +Each selected scenario keeps its executor, load, timing, function, environment, tags, and browser options. Without the flag, k6 runs all configured scenarios. Selection also works with `k6 cloud run` and `k6 archive`; archives retain the selected configuration. + +Names must match configured scenarios. Load shortcuts such as `--vus` and `--duration` cannot be combined with selection; set the workload in each scenario instead. k6 warns and skips thresholds tagged for configured scenarios you exclude, while keeping global thresholds and other filters. See the [scenario documentation](https://grafana.com/docs/k6/v2.3.x/using-k6/scenarios/#run-selected-scenarios) for details. + +### Run a script once with `--once` [#6338](https://github.com/grafana/k6/pull/6338) + +The `--once` flag is now the recommended way to run a script once, for both protocol and browser tests, while preserving the scenario's function and browser configuration. It supports scripts with at most one scenario and works with `k6 run`, `k6 cloud run`, and `k6 archive`. For example, this configuration runs `checkout()` repeatedly with ten VUs for 30 seconds: + +```js +export const options = { + scenarios: { + checkout: { + executor: 'constant-vus', + exec: 'checkout', + vus: 10, + duration: '30s', + }, + }, +}; +// The rest of the script defines checkout(). +``` + +```shell +k6 run --once script.js +``` + +With `--once`, k6 changes this scenario to `shared-iterations` with one VU and one iteration, calling `checkout()` once instead of repeatedly for 30 seconds. Previously, shortcuts such as `--vus 1 --iterations 1` replaced the script's scenarios with a default scenario, discarding settings such as the selected function and browser options. This broke browser scripts because the configuration needed to launch Chromium was missing; `--once` keeps that configuration. To combine scenario selection with `--once`, see [Run each selected scenario once](https://grafana.com/docs/k6/v2.3.x/using-k6/scenarios/#run-each-selected-scenario-once). + +### Keep metrics grouped across asynchronous calls [#6340](https://github.com/grafana/k6/pull/6340), [#6341](https://github.com/grafana/k6/pull/6341), [#6342](https://github.com/grafana/k6/pull/6342), [#6343](https://github.com/grafana/k6/pull/6343), [#6344](https://github.com/grafana/k6/pull/6344) + +You can now use an async function in `group()` by enabling the experimental `async-metric-context` feature. Requests and checks after an `await` keep their group, and `group_duration` measures until the callback's returned promise settles. Previously, `group()` rejected async functions, and promise callbacks could lose the group tag. + +```js +import { check, group } from 'k6'; +import http from 'k6/http'; + +export default async function () { + await group('browse', async () => { + const response = await http.asyncRequest('GET', 'https://test.k6.io/'); + check(response, { 'page loaded': (r) => r.status === 200 }); + await http.asyncRequest('GET', 'https://test.k6.io/contacts.php'); + }); +} +``` + +```shell +k6 run --features async-metric-context script.js +``` + +Both requests and the check belong to `browse`, including the work after the first `await`. The feature also preserves custom tags and metadata across promises, timer callbacks, `k6/websockets` listeners, and gRPC stream listeners. Changes inside a group or callback stay local to that work and its asynchronous descendants instead of leaking into unrelated work. + +### Fetch missing TLS certificates [#6137](https://github.com/grafana/k6/pull/6137) + +Some HTTPS servers work in browsers but fail in k6 because they omit an intermediate certificate. The new `tlsAIAFetch` option lets k6 fetch that missing certificate while still verifying the server's identity: + +```js +export const options = { + tlsAIAFetch: true, +}; +``` + +This is opt-in and works with HTTP and gRPC connections. Thanks, @vtorosyan! + +### Static labels for Prometheus remote write [#6071](https://github.com/grafana/k6/pull/6071) + +When several k6 instances send metrics to the same Prometheus server, labels let you tell their results apart. Use `K6_PROMETHEUS_RW_LABELS` to identify the job, environment, or server on every time series sent by that output: + +```shell +K6_PROMETHEUS_RW_LABELS="environment=production,server=srv1" \ +k6 run --out experimental-prometheus-rw script.js +``` + +Thanks, @rohan-patnaik! + +### Nanosecond log timestamps [#6310](https://github.com/grafana/k6/pull/6310) + +Logs with second-precision timestamps can lose their order when a log service sorts messages emitted within the same second. Enable nanosecond timestamps with `--log-ns-timestamps` to make those messages easier to order and correlate: + +```shell +k6 --log-ns-timestamps --log-format=json run script.js +``` + +This also works with plain-text logs when `--no-color` is set. + +### WebSocket ready-state constants [#6306](https://github.com/grafana/k6/pull/6306) + +The `WebSocket` constructor and its instances now expose the same connection-state constants as browsers: `CONNECTING`, `OPEN`, `CLOSING`, and `CLOSED`. For an existing socket, you can check its state before sending a message: + +```js +if (socket.readyState === WebSocket.OPEN) { + socket.send('hello'); +} +``` + +### Encode bytes and compare sets with JavaScript built-ins [#6382](https://github.com/grafana/k6/pull/6382) + +You can now convert `Uint8Array` data to and from hex or base64 with built-in methods, and compare sets with operations such as `difference()`, `intersection()`, and `union()`. Use them to prepare binary test data or check which fields are missing from a response. + +```javascript +const bytes = Uint8Array.fromHex('6b36'); +console.log(bytes.toBase64()); // azY= + +const expected = new Set(['id', 'name', 'email']); +const received = new Set(['id', 'name']); +console.log([...expected.difference(received)]); // ["email"] +``` + +The Sobek update also adds `Error.isError()`, `JSON.rawJSON()`, and `JSON.isRawJSON()`. For example, `JSON.rawJSON()` lets you include an exact numeric value in a JSON payload without rounding it to a JavaScript `Number` first: + +```javascript +JSON.stringify({ id: JSON.rawJSON('9007199254740993') }); +// '{"id":9007199254740993}' +``` + +Thanks to @arukiidou and @xtrafrancyz for the upstream implementations! + +### Read the execution result before k6 exits [#6388](https://github.com/grafana/k6/pull/6388) + +When k6 stays alive with `--linger`, tools monitoring the process cannot use its exit status to tell whether the test finished successfully or aborted. The REST API's `/v1/status` response now includes `execution_result`, with the test's exit code once it is known. Before then, the field is `null`. Thanks, @yorugac! + +For example, query a lingering process after a script calls `exec.test.abort()`: + +```shell +curl -s http://localhost:6565/v1/status | jq '.data.attributes.execution_result' +``` + +```json +{ + "exit_code": 108 +} +``` + +## UX improvements and enhancements + +- [#6408](https://github.com/grafana/k6/pull/6408) Explains how to enable experimental async support when `group()` rejects an async callback. +- [#6402](https://github.com/grafana/k6/pull/6402) Fixes a missing space in the `--no-usage-report` help text. Thanks, @yats0x7! +- [#6339](https://github.com/grafana/k6/pull/6339) Adds login and token-configuration guidance when Grafana Cloud commands return an authentication error. Thanks, @Swapnil-Biswas! + +## Bug fixes + +- [#6414](https://github.com/grafana/k6/pull/6414) Stops screenshot capture from waiting until the page closes when a browser command does not respond, so scripts can catch the timeout and continue cleanup. +- [#6412](https://github.com/grafana/k6/pull/6412) Lets waits for hidden or detached browser elements finish when the element is already absent, instead of timing out or throwing an error. +- [#6368](https://github.com/grafana/k6/pull/6368) Makes `crypto.getRandomValues()` throw a catchable `TypeError` instead of crashing k6 when called without an argument or with a typed array whose length was overridden to a negative value. Thanks, @hyuraku! +- [#6327](https://github.com/grafana/k6/pull/6327) Fixes a data race when closing a browser context while other browser operations access it. Thanks, @JohnPei1! +- [#6351](https://github.com/grafana/k6/pull/6351) Prevents clearing an expired timer from running a later timeout or interval too early, and fixes VUs hanging when a `k6/websockets` connection is closed before its handshake finishes. +- [#6349](https://github.com/grafana/k6/pull/6349) Fixes inflated `http_req_sending` and `http_req_duration` values when making HTTPS requests through an HTTPS proxy. Thanks, @kausthubhk! +- [#5922](https://github.com/grafana/k6/pull/5922) Stops the test with an error when a ramping-VU scenario cannot start a VU, instead of silently stopping the scenario and reporting success. Thanks, @HwangRock! +- [#6163](https://github.com/grafana/k6/pull/6163) Preserves Web Vitals from intermediate pages when a browser test navigates several times in the same tab, so results include those pages as well as the last one. +- [#6355](https://github.com/grafana/k6/pull/6355) Prevents a response-body leak when reading a digest authentication challenge fails. Thanks, @cuishuang! +- [#5949](https://github.com/grafana/k6/pull/5949) Supports sending metrics to InfluxDB behind a reverse proxy with a URL path prefix, such as `https://host/influxdb/database`. Thanks, @o6ivp! +- [#6235](https://github.com/grafana/k6/pull/6235) Uses forward slashes in remote screenshot paths on Windows. Thanks, @adarshsm! +- [#6238](https://github.com/grafana/k6/pull/6238) Sends `null` and `undefined` form fields as empty values instead of the string ``, and warns when a nested object cannot be encoded as a form field. Thanks, @djedi-knight! +- [#6279](https://github.com/grafana/k6/pull/6279) Fixes browser tests stalling when VUs share a remote Chrome instance, so pages can run concurrently. +- [#6298](https://github.com/grafana/k6/pull/6298) Preserves browser trace spans that were lost when a test ended. Thanks, @mem! +- [#6385](https://github.com/grafana/k6/pull/6385) Fixes an integer overflow that prevented compilation on 32-bit ARM and x86 systems. Thanks, @GourangaDasSamrat! + +## Maintenance and internal improvements + +- [#6413](https://github.com/grafana/k6/pull/6413) Updates the browser role-selector test fixture for Chromium's image-map rendering. +- [#6369](https://github.com/grafana/k6/pull/6369), [#6370](https://github.com/grafana/k6/pull/6370) Adds the binary's build origin and a locally stored random installation ID to usage reports, helping distinguish build sources and measure active installations. Both respect `--no-usage-report`. +- [#6209](https://github.com/grafana/k6/pull/6209) Simplifies the internal handling of Cloud commands. Thanks, @moko-poi! +- [#6236](https://github.com/grafana/k6/pull/6236) Adds a smoke test before publishing browser Docker images to catch missing or broken Chromium installations. +- [#6245](https://github.com/grafana/k6/pull/6245) Enables CI on the v1 maintenance branch. +- [#6246](https://github.com/grafana/k6/pull/6246), [#6277](https://github.com/grafana/k6/pull/6277) Automates approvals and merging for eligible dependency updates. +- [#6256](https://github.com/grafana/k6/pull/6256), [#6271](https://github.com/grafana/k6/pull/6271) Improves contributor acknowledgments and the release checklist. +- [#6270](https://github.com/grafana/k6/pull/6270) Restores Debian package publishing after `bzip2` was removed from the packaging base image. +- [#6301](https://github.com/grafana/k6/pull/6301), [#6373](https://github.com/grafana/k6/pull/6373) Corrects the TC39 test-package path and built-in module locations in contributor documentation. Thanks, @umekikazuya and @ashrafiucse! +- [#6312](https://github.com/grafana/k6/pull/6312), [#6380](https://github.com/grafana/k6/pull/6380), [#6394](https://github.com/grafana/k6/pull/6394), [#6398](https://github.com/grafana/k6/pull/6398) Uses shared CI workflows, lint configuration, and Go test versions, and fixes findings from the newer linter. +- [#6409](https://github.com/grafana/k6/pull/6409) Updates Test262 expectations for Unicode tests that pass with the newer Go version. +- [#6325](https://github.com/grafana/k6/pull/6325) Moves browser option parsing into the JavaScript mapping layer without changing script behavior. Thanks, @Shobhit-Nagpal! +- [#6265](https://github.com/grafana/k6/pull/6265), [#6266](https://github.com/grafana/k6/pull/6266), [#6267](https://github.com/grafana/k6/pull/6267), [#6303](https://github.com/grafana/k6/pull/6303), [#6304](https://github.com/grafana/k6/pull/6304), [#6331](https://github.com/grafana/k6/pull/6331), [#6332](https://github.com/grafana/k6/pull/6332), [#6357](https://github.com/grafana/k6/pull/6357), [#6358](https://github.com/grafana/k6/pull/6358), [#6363](https://github.com/grafana/k6/pull/6363), [#6367](https://github.com/grafana/k6/pull/6367), [#6383](https://github.com/grafana/k6/pull/6383), [#6376](https://github.com/grafana/k6/pull/6376), [#6478](https://github.com/grafana/k6/pull/6478) Updates the Docker build image to Go 1.27.1, raises the module's minimum Go version to 1.26.0, and updates gRPC to v1.84.0 (the example server uses v1.83.2), OpenTelemetry to v1.46.0, Brotli to v1.2.3, `klauspost/compress` to v1.20.0, esbuild to v0.28.2, Testify to v1.12.1, Protobuf to v1.36.12, `golang.org/x/crypto` to v0.56.0, and related Go dependencies. + +## External contributors + +Thanks to @adarshsm, @arukiidou, @ashrafiucse, @cuishuang, @djedi-knight, @GourangaDasSamrat, @HwangRock, @hyuraku, @JohnPei1, @kausthubhk, @mem, @moko-poi, @o6ivp, @rohan-patnaik, @Shobhit-Nagpal, @Swapnil-Biswas, @umekikazuya, @vtorosyan, @xtrafrancyz, @yats0x7, and @yorugac for their contributions. From 1868f4e5bef42de1890d4916ceae2c5dcbd4fd10 Mon Sep 17 00:00:00 2001 From: jgaalen Date: Tue, 29 Sep 2026 13:29:56 +0200 Subject: [PATCH 172/182] Enable native async group transactions in the Breaking-IT fork --- internal/cmd/archive_test.go | 3 +- .../cmd/tests/cmd_cloud_run_features_test.go | 4 +- internal/cmd/tests/cmd_run_features_test.go | 5 +- internal/cmd/tests/cmd_run_test.go | 2 +- internal/cmd/tests/fork_default_group_test.go | 65 +++++ internal/features/features.go | 7 +- internal/features/fork_defaults_test.go | 64 +++++ internal/features/resolve.go | 9 +- internal/js/modules/k6/asyncgroup.go | 17 +- .../browser/tests/fork_group_outcome_test.go | 57 +++++ .../js/modules/k6/fork_group_outcome_test.go | 99 ++++++++ internal/js/modules/k6/k6.go | 7 +- internal/output/breakingit/README.md | 108 ++++++++ internal/output/breakingit/breakingit.go | 24 +- internal/output/breakingit/transactions.go | 26 ++ .../output/breakingit/transactions_test.go | 238 ++++++++++++++++++ metrics/sample.go | 5 + 17 files changed, 715 insertions(+), 25 deletions(-) create mode 100644 internal/cmd/tests/fork_default_group_test.go create mode 100644 internal/features/fork_defaults_test.go create mode 100644 internal/js/modules/k6/browser/tests/fork_group_outcome_test.go create mode 100644 internal/js/modules/k6/fork_group_outcome_test.go create mode 100644 internal/output/breakingit/README.md create mode 100644 internal/output/breakingit/transactions.go create mode 100644 internal/output/breakingit/transactions_test.go diff --git a/internal/cmd/archive_test.go b/internal/cmd/archive_test.go index 31410f23d..01ed78079 100644 --- a/internal/cmd/archive_test.go +++ b/internal/cmd/archive_test.go @@ -183,7 +183,8 @@ func TestArchiveContainsEnv(t *testing.T) { // then unpacked metadata should contain the environment variables with the proper values require.NoError(t, json.Unmarshal(data, &metadata)) - require.Len(t, metadata.Env, 2) + require.Len(t, metadata.Env, 3) + require.Equal(t, "async-metric-context", metadata.Env["K6_FEATURES"]) require.Contains(t, metadata.Env, "ENV1") require.Contains(t, metadata.Env, "ENV2") diff --git a/internal/cmd/tests/cmd_cloud_run_features_test.go b/internal/cmd/tests/cmd_cloud_run_features_test.go index 3333c445f..fdf6df56a 100644 --- a/internal/cmd/tests/cmd_cloud_run_features_test.go +++ b/internal/cmd/tests/cmd_cloud_run_features_test.go @@ -153,6 +153,6 @@ export default function () {};` archiveEnv, _ := uploadAndCaptureArchive(t, []string{"k6", "cloud", "run", "test.js"}, nil, script) - _, ok := archiveEnv["K6_FEATURES"] - assert.False(t, ok, "options.features must not convey to the worker") + assert.Equal(t, "async-metric-context", archiveEnv["K6_FEATURES"], + "only the fork default, not options.features, should convey to the worker") } diff --git a/internal/cmd/tests/cmd_run_features_test.go b/internal/cmd/tests/cmd_run_features_test.go index b1ccee032..c0e8fa714 100644 --- a/internal/cmd/tests/cmd_run_features_test.go +++ b/internal/cmd/tests/cmd_run_features_test.go @@ -64,7 +64,7 @@ func TestRunWithoutFeatureFlag(t *testing.T) { tagged := runAndNativeHistTagged(t, ts) assert.Empty(t, tagged, "no feature tag without activation") - assert.Nil(t, ts.Usage.Map()["features"]) + assert.Equal(t, []string{"async-metric-context"}, ts.Usage.Map()["features"]) for _, e := range ts.LoggerHook.Drain() { assert.NotEqual(t, "native-histograms", e.Data["feature"]) @@ -154,7 +154,8 @@ func TestRunWarnsOnScriptOptionsFeatures(t *testing.T) { tagged := runAndNativeHistTagged(t, ts) assert.Empty(t, tagged, "options.features must not activate the flag") - assert.Nil(t, ts.Usage.Map()["features"], "options.features must not contribute to telemetry") + assert.Equal(t, []string{"async-metric-context"}, ts.Usage.Map()["features"], + "only the fork default, not options.features, should be active") var sawOptionsWarn bool for _, e := range ts.LoggerHook.Drain() { diff --git a/internal/cmd/tests/cmd_run_test.go b/internal/cmd/tests/cmd_run_test.go index a6f9c4488..bf07f5c6e 100644 --- a/internal/cmd/tests/cmd_run_test.go +++ b/internal/cmd/tests/cmd_run_test.go @@ -522,7 +522,7 @@ func TestExecutionTestOptionsDefaultValues(t *testing.T) { loglines := ts.LoggerHook.Drain() require.Len(t, loglines, 1) - expected := `{"paused":null,"executionSegment":null,"executionSegmentSequence":null,"noSetup":null,"setupTimeout":null,"noTeardown":null,"teardownTimeout":null,"rps":null,"dns":{"ttl":null,"select":null,"policy":null},"maxRedirects":null,"userAgent":null,"batch":null,"batchPerHost":null,"httpErrorData":null,"httpDebug":null,"insecureSkipTLSVerify":null,"tlsCipherSuites":null,"tlsVersion":null,"tlsAuth":null,"tlsAIAFetch":null,"throw":null,"thresholds":null,"blacklistIPs":null,"blockHostnames":null,"hosts":null,"noConnectionReuse":null,"noVUConnectionReuse":null,"minIterationDuration":null,"ext":null,"summaryTrendStats":["avg", "min", "med", "max", "p(90)", "p(95)"],"summaryTimeUnit":null,"systemTags":["check","error","error_code","expected_response","group","method","name","proto","scenario","service","status","subproto","tls_version","url"],"tags":null,"metricSamplesBufferSize":null,"noCookiesReset":null,"discardResponseBodies":null,"consoleOutput":null,"scenarios":{"default":{"vus":null,"iterations":1,"executor":"shared-iterations","maxDuration":null,"startTime":null,"env":null,"tags":null,"gracefulStop":null,"exec":null}},"localIPs":null,"handleSummaryTimeout":null,"features":null}` + expected := `{"paused":null,"executionSegment":null,"executionSegmentSequence":null,"noSetup":null,"setupTimeout":null,"noTeardown":null,"teardownTimeout":null,"rps":null,"dns":{"ttl":null,"select":null,"policy":null},"maxRedirects":null,"userAgent":null,"batch":null,"batchPerHost":null,"httpErrorData":null,"httpDebug":null,"insecureSkipTLSVerify":null,"tlsCipherSuites":null,"tlsVersion":null,"tlsAuth":null,"tlsAIAFetch":null,"throw":null,"thresholds":null,"blacklistIPs":null,"blockHostnames":null,"hosts":null,"noConnectionReuse":null,"noVUConnectionReuse":null,"minIterationDuration":null,"ext":null,"summaryTrendStats":["avg", "min", "med", "max", "p(90)", "p(95)"],"summaryTimeUnit":null,"systemTags":["check","error","error_code","expected_response","group","method","name","proto","scenario","service","status","subproto","tls_version","url"],"tags":{"k6_feature_async_metric_context":"true"},"metricSamplesBufferSize":null,"noCookiesReset":null,"discardResponseBodies":null,"consoleOutput":null,"scenarios":{"default":{"vus":null,"iterations":1,"executor":"shared-iterations","maxDuration":null,"startTime":null,"env":null,"tags":null,"gracefulStop":null,"exec":null}},"localIPs":null,"handleSummaryTimeout":null,"features":null}` assert.JSONEq(t, expected, loglines[0].Message) } diff --git a/internal/cmd/tests/fork_default_group_test.go b/internal/cmd/tests/fork_default_group_test.go new file mode 100644 index 000000000..873e0c6c4 --- /dev/null +++ b/internal/cmd/tests/fork_default_group_test.go @@ -0,0 +1,65 @@ +package tests + +import ( + "maps" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "go.k6.io/k6/v2/internal/cmd" + "go.k6.io/k6/v2/lib/fsext" +) + +func TestForkDefaultGroupAndOptOut(t *testing.T) { + t.Parallel() + for _, test := range []struct { + name string + args []string + env map[string]string + enabled bool + }{ + {name: "default", enabled: true}, + {name: "CLI opt-out", args: []string{"--features="}}, + {name: "environment opt-out", env: map[string]string{"K6_FEATURES": ""}}, + {name: "explicit list replaces default", args: []string{"--features=merge-run-tags"}}, + } { + t.Run(test.name, func(t *testing.T) { + t.Parallel() + args := append([]string{"--out=json=results.json", "--summary-mode=disabled"}, test.args...) + ts := getSingleFileTestState(t, ` + import { check, group } from 'k6'; + export default async function () { + let supported = false; + try { + await group('step', async () => { + await Promise.resolve(); + check(true, { inside: value => value }); + }); + supported = true; + } catch (error) { + if (!String(error).includes('group() does not support async')) throw error; + } + check(supported, { supported: value => value }); + } + `, args, 0) + maps.Copy(ts.Env, test.env) + cmd.ExecuteWithGlobalState(ts.GlobalState) + results, err := fsext.ReadFile(ts.FS, "results.json") + require.NoError(t, err) + want := float64(0) + if test.enabled { + want = 1 + assert.Equal(t, []float64{1}, getSampleValues(t, results, "checks", map[string]string{ + "check": "inside", "group": "::step", + })) + assert.Len(t, getSampleValues(t, results, "group_duration", map[string]string{"group": "::step"}), 1) + } else { + assert.Empty(t, getSampleValues(t, results, "group_duration", nil)) + } + assert.Equal(t, []float64{want}, getSampleValues(t, results, "checks", map[string]string{ + "check": "supported", "group": "", + })) + }) + } +} diff --git a/internal/features/features.go b/internal/features/features.go index 3cb0bfd76..53dfd3ef5 100644 --- a/internal/features/features.go +++ b/internal/features/features.go @@ -83,7 +83,9 @@ func Init( logger logrus.FieldLogger, cli, json Source, runtimeEnv map[string]string, ) (*Flags, error) { flags := &Flags{} - active, err := initInto(reflect.ValueOf(flags).Elem(), logger, cli, json, runtimeEnv, defaultAliases()) + // Fork default, below explicit CLI/env/JSON lists (including empty opt-out lists). + active, err := initInto(reflect.ValueOf(flags).Elem(), logger, cli, json, runtimeEnv, + defaultAliases(), "async-metric-context") if err != nil { return nil, err } @@ -103,6 +105,7 @@ func allOf(t reflect.Type) ([]Flag, error) { func initInto( target reflect.Value, logger logrus.FieldLogger, cli, json Source, runtimeEnv map[string]string, aliases []alias, + defaults ...string, ) ([]string, error) { defs, err := parseDefinitions(target.Type()) if err != nil { @@ -115,7 +118,7 @@ func initInto( } } - return resolveInto(defs, target, cli, resolveEnvSurface(defs, runtimeEnv, logger), json, logger) + return resolveInto(defs, target, cli, resolveEnvSurface(defs, runtimeEnv, logger), json, logger, defaults...) } // definition holds the parsed metadata and field index for one flag field. diff --git a/internal/features/fork_defaults_test.go b/internal/features/fork_defaults_test.go new file mode 100644 index 000000000..8284fbfde --- /dev/null +++ b/internal/features/fork_defaults_test.go @@ -0,0 +1,64 @@ +package features + +import ( + "testing" + + "github.com/sirupsen/logrus" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestForkDefaultAsyncMetricContext(t *testing.T) { + t.Parallel() + for _, test := range []struct { + name string + cli Source + json Source + env map[string]string + active []string + }{ + {name: "default", active: []string{"async-metric-context"}}, + {name: "empty CLI opts out", cli: supplied(""), active: []string{}}, + {name: "empty env opts out", env: map[string]string{"K6_FEATURES": ""}, active: []string{}}, + {name: "empty JSON opts out", json: supplied(""), active: []string{}}, + {name: "explicit list replaces default", cli: supplied("merge-run-tags"), active: []string{"merge-run-tags"}}, + { + name: "explicit list includes default", cli: supplied("merge-run-tags,async-metric-context"), + active: []string{"async-metric-context", "merge-run-tags"}, + }, + { + name: "env overrides JSON", json: supplied("async-metric-context"), + env: map[string]string{"K6_FEATURES": ""}, active: []string{}, + }, + { + name: "CLI overrides env", cli: supplied(""), + env: map[string]string{"K6_FEATURES": "async-metric-context"}, active: []string{}, + }, + { + name: "CLI re-enables", cli: supplied("async-metric-context"), + env: map[string]string{"K6_FEATURES": ""}, active: []string{"async-metric-context"}, + }, + } { + t.Run(test.name, func(t *testing.T) { + t.Parallel() + flags, err := Init(logrus.New(), test.cli, test.json, test.env) + require.NoError(t, err) + assert.Equal(t, test.active, flags.Activated()) + wantAsync := false + for _, name := range test.active { + wantAsync = wantAsync || name == "async-metric-context" + } + assert.Equal(t, wantAsync, flags.AsyncMetricContext) + assert.Equal(t, wantAsync, flags.Tags()["k6_feature_async_metric_context"] == "true") + }) + } + definitions, err := All() + require.NoError(t, err) + for _, definition := range definitions { + if definition.Name == "async-metric-context" { + assert.Equal(t, Experimental, definition.Lifecycle) + return + } + } + t.Fatal("async-metric-context definition missing") +} diff --git a/internal/features/resolve.go b/internal/features/resolve.go index 94b9be092..d8e93e1cb 100644 --- a/internal/features/resolve.go +++ b/internal/features/resolve.go @@ -31,6 +31,7 @@ func resolveInto(defs *definitions, target reflect.Value, cli, env, json Source, logger logrus.FieldLogger, + defaults ...string, ) ([]string, error) { if target.Type() != defs.typ { return nil, fmt.Errorf("features: resolveInto target type %s does not match definition type %s", @@ -48,8 +49,7 @@ func resolveInto(defs *definitions, case json.Supplied: winner, source = json, "json" default: - forceGA(defs, target) - return []string{}, nil + winner, source = Source{Values: defaults}, "default" } activated := make(map[string]struct{}) @@ -90,7 +90,10 @@ func resolveInto(defs *definitions, activated[name] = struct{}{} - logActivation(logger, name, defs.definitions[idx].flag.Lifecycle) + // Defaults must not add unsolicited INFO output, particularly for quiet runs. + if source != "default" { + logActivation(logger, name, defs.definitions[idx].flag.Lifecycle) + } } setFields(defs, target, activated) diff --git a/internal/js/modules/k6/asyncgroup.go b/internal/js/modules/k6/asyncgroup.go index deff54773..b4770bde7 100644 --- a/internal/js/modules/k6/asyncgroup.go +++ b/internal/js/modules/k6/asyncgroup.go @@ -19,7 +19,7 @@ type asyncGroup struct { settled bool } -func (g *asyncGroup) emitDuration() { +func (g *asyncGroup) emitDuration(failed bool) { if g.settled { return } @@ -27,29 +27,30 @@ func (g *asyncGroup) emitDuration() { // Group only creates asyncGroup for an active VU, whose state remains allocated across // iterations and cancellation. - emitGroupDuration(g.vu, g.start, time.Now(), g.tagsAndMeta) + emitGroupDuration(g.vu, g.start, time.Now(), g.tagsAndMeta, failed) } -func emitGroupDuration(vu modules.VU, start, end time.Time, tagsAndMeta metrics.TagsAndMeta) { +func emitGroupDuration(vu modules.VU, start, end time.Time, tagsAndMeta metrics.TagsAndMeta, failed bool) { state := vu.State() metrics.PushIfNotDone(vu.Context(), state.Samples, metrics.Sample{ TimeSeries: metrics.TimeSeries{ Metric: state.BuiltinMetrics.GroupDuration, Tags: tagsAndMeta.Tags, }, - Time: end, - Value: metrics.D(end.Sub(start)), - Metadata: tagsAndMeta.Metadata, + Time: end, + Value: metrics.D(end.Sub(start)), + Metadata: tagsAndMeta.Metadata, + GroupFailed: failed, }) } func (g *asyncGroup) onFulfilled(call sobek.FunctionCall) sobek.Value { - g.emitDuration() + g.emitDuration(false) return call.Argument(0) } func (g *asyncGroup) onRejected(call sobek.FunctionCall) sobek.Value { - g.emitDuration() + g.emitDuration(true) // Sobek uses a panic to throw an arbitrary JavaScript value from a Go callback. Returning a Go // error here would wrap the value and change the promise's rejection reason. panic(call.Argument(0)) diff --git a/internal/js/modules/k6/browser/tests/fork_group_outcome_test.go b/internal/js/modules/k6/browser/tests/fork_group_outcome_test.go new file mode 100644 index 000000000..3ff61daec --- /dev/null +++ b/internal/js/modules/k6/browser/tests/fork_group_outcome_test.go @@ -0,0 +1,57 @@ +package tests + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "go.k6.io/k6/v2/metrics" +) + +func TestBrowserGroupTransactionOutcomes(t *testing.T) { + t.Parallel() + + tb := newTestBrowser(t) + prepareAsyncGroupBrowser(t, tb) + _, err := tb.vu.RunAsync(t, ` + const page = await browser.newPage(); + try { + await k6.group('success', async () => { + await page.setContent('

Checkout

'); + await page.locator('h1').waitFor({state: 'visible'}); + }); + try { + await k6.group('failure', async () => { + await page.goto('http://127.0.0.1:1'); + }); + throw new Error('expected an unsafe-port navigation failure'); + } catch (error) { + if (!String(error).includes('ERR_UNSAFE_PORT')) throw error; + } + await k6.group('caught', async () => { + try { await page.goto('http://127.0.0.1:1'); } catch (_) {} + }); + } finally { + await page.close(); + } + `) + require.NoError(t, err) + + outcomes := map[string][]bool{} + errors := map[string]int{} + for _, sample := range collectBrowserSamples(tb) { + group, _ := sample.Tags.Get("group") + switch sample.Metric.Name { + case metrics.GroupDurationName: + outcomes[group] = append(outcomes[group], sample.GroupFailed) + assert.Greater(t, sample.Value, float64(0)) + case "browser_errors": + errors[group]++ + } + } + assert.Equal(t, map[string][]bool{ + "::success": {false}, "::failure": {true}, "::caught": {false}, + }, outcomes) + assert.Equal(t, map[string]int{"::failure": 1, "::caught": 1}, errors) +} diff --git a/internal/js/modules/k6/fork_group_outcome_test.go b/internal/js/modules/k6/fork_group_outcome_test.go new file mode 100644 index 000000000..eaf225834 --- /dev/null +++ b/internal/js/modules/k6/fork_group_outcome_test.go @@ -0,0 +1,99 @@ +package k6 + +import ( + "fmt" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "go.k6.io/k6/v2/metrics" +) + +func TestGroupTransactionOutcome(t *testing.T) { + t.Parallel() + + cases := []struct { + name string + callback string + async bool + failed bool + }{ + {"sync success", `() => 42`, false, false}, + {"sync throw", `() => { throw new Error('failed'); }`, false, true}, + {"sync with feature", `() => 42`, true, false}, + {"sync throw with feature", `() => { throw new Error('failed'); }`, true, true}, + {"async success", `async () => { await Promise.resolve(); return 42; }`, true, false}, + {"async rejection", `async () => { await Promise.resolve(); throw new Error('failed'); }`, true, true}, + {"primitive rejection", `() => Promise.reject(undefined)`, true, true}, + {"caught rejection", `async () => { try { await Promise.reject('failed'); } catch (_) {} }`, true, false}, + {"failed check", `async () => { k6.check(false, {bad: value => value}); }`, true, false}, + {"check then throw", `async () => { if (!k6.check(false, {bad: v => v})) throw 'bad'; }`, true, true}, + {"throwing getter", `() => ({get then() { throw 'failed'; }})`, true, true}, + {"thenable resolve", `() => ({then(resolve) { resolve(42); }})`, true, false}, + {"thenable reject", `() => ({then(_, reject) { reject('failed'); }})`, true, true}, + {"thenable throw", `() => ({then() { throw 'failed'; }})`, true, true}, + {"first settlement wins", `() => ({then(resolve, reject) { resolve(42); reject('late'); }})`, true, false}, + } + for _, test := range cases { + t.Run(test.name, func(t *testing.T) { + t.Parallel() + tc := testCaseRuntimeWithAsyncMetricContext(t, test.async) + _, err := tc.testRuntime.RunOnEventLoop(fmt.Sprintf(` + (async () => { + let failed = false; + try { await k6.group('step', %s); } catch (_) { failed = true; } + if (failed !== %t) throw new Error('callback outcome changed'); + })() + `, test.callback, test.failed)) + require.NoError(t, err) + var durations []metrics.Sample + for _, container := range metrics.GetBufferedSamples(tc.samples) { + for _, sample := range container.GetSamples() { + if sample.Metric.Name == metrics.GroupDurationName { + durations = append(durations, sample) + } + } + } + require.Len(t, durations, 1) + assert.Equal(t, test.failed, durations[0].GroupFailed) + assert.Equal(t, map[string]string{"group": "::step"}, durations[0].Tags.Map()) + assert.GreaterOrEqual(t, durations[0].Value, float64(0)) + }) + } +} + +func TestGroupTransactionOutcomesStayIsolated(t *testing.T) { + t.Parallel() + tc := testCaseRuntime(t) + _, err := tc.testRuntime.RunOnEventLoop(` + (async () => { + await Promise.allSettled([ + k6.group('same', async () => { await Promise.resolve(); throw 'failed'; }), + k6.group('same', async () => { await Promise.resolve(); }), + ]); + await k6.group('parent', async () => { + try { await k6.group('child', async () => { throw 'failed'; }); } catch (_) {} + }); + try { + await k6.group('uncaught', async () => { + await k6.group('child', async () => { throw 'failed'; }); + }); + } catch (_) {} + })() + `) + require.NoError(t, err) + outcomes := map[string][]bool{} + for _, container := range metrics.GetBufferedSamples(tc.samples) { + for _, sample := range container.GetSamples() { + if sample.Metric.Name == metrics.GroupDurationName { + group, _ := sample.Tags.Get("group") + outcomes[group] = append(outcomes[group], sample.GroupFailed) + } + } + } + assert.Equal(t, map[string][]bool{ + "::same": {true, false}, "::parent": {false}, "::parent::child": {true}, + "::uncaught": {true}, "::uncaught::child": {true}, + }, outcomes) +} diff --git a/internal/js/modules/k6/k6.go b/internal/js/modules/k6/k6.go index 2423f4b3a..1014011fa 100644 --- a/internal/js/modules/k6/k6.go +++ b/internal/js/modules/k6/k6.go @@ -136,6 +136,9 @@ func (mi *K6) Group(name string, val sobek.Value) (sobek.Value, error) { groupTagsAndMeta = state.Tags.GetCurrentValues() } synchronous := true + // Default to failure so a thrown property getter or other unwinding path is not + // exported as a successful BreakTest transaction. + groupSucceeded := false var startTime, endTime time.Time defer func() { if synchronous { @@ -146,7 +149,7 @@ func (mi *K6) Group(name string, val sobek.Value) (sobek.Value, error) { if !mi.asyncGroups { durationTagsAndMeta = state.Tags.GetCurrentValues() } - emitGroupDuration(mi.vu, startTime, endTime, durationTagsAndMeta) + emitGroupDuration(mi.vu, startTime, endTime, durationTagsAndMeta, !groupSucceeded) } if mi.asyncGroups { state.Tags.Modify(func(tagsAndMeta *metrics.TagsAndMeta) { @@ -161,11 +164,13 @@ func (mi *K6) Group(name string, val sobek.Value) (sobek.Value, error) { ret, err := fn(sobek.Undefined()) endTime = time.Now() if err != nil || !mi.asyncGroups { + groupSucceeded = err == nil return ret, err } thenFn, isThenable := asThenable(ret) if !isThenable { + groupSucceeded = true return ret, nil } diff --git a/internal/output/breakingit/README.md b/internal/output/breakingit/README.md new file mode 100644 index 000000000..c30219386 --- /dev/null +++ b/internal/output/breakingit/README.md @@ -0,0 +1,108 @@ +# BreakTest transactions + +The `breakingit` exporter accepts both native k6 `group_duration` samples and the +legacy custom `pages` Trend. They use the existing `transactions` table (or +`transactions_sm` for synthetic monitoring); no database migration is required. + +## Native groups (preferred for new scripts) + +This fork enables k6 2.3's experimental async metric context by default, in both +normal and lean builds. No feature flag is needed for browser groups: + +```sh +k6 run --out breakingit=https://your-pg-proxy script.js +``` + +Keep the existing `PG_PROXY_TOKEN`, run/location, and synthetic-monitoring +configuration; set `BASE_URL` for the example below. + +To restore upstream's opt-in behavior for a run, use `k6 run --features='' script.js` +or `K6_FEATURES='' k6 run script.js`. An explicit feature list **replaces** the +default, following the existing CLI > environment > JSON configuration precedence. +If selecting other features, include `async-metric-context` in that list to keep it +enabled. An explicit JSON `"features": []` also disables the default unless a +higher-priority source overrides it. This remains an experimental feature, not GA. + +Compared with the disabled behavior, group-local changes to VU metric tags and +metadata are restored on exit rather than leaking into subsequent steps. + +```javascript +import { browser } from 'k6/browser'; +import { check, group } from 'k6'; +import { setTimeout } from 'k6/timers'; + +export const options = { + scenarios: { + checkout: { + executor: 'shared-iterations', + vus: 1, + iterations: 1, + options: { browser: { type: 'chromium' } }, + }, + }, +}; + +export default async function () { + const page = await browser.newPage(); + try { + // Keep think time outside the group so it is not part of response_time. + await new Promise(resolve => setTimeout(resolve, 1000)); + await group('01_OpenHomepage', async () => { + const response = await page.goto(__ENV.BASE_URL); + if (!check(response, { 'homepage is 200': r => r && r.status() === 200 })) { + throw new Error('Homepage did not return 200'); + } + await page.locator('.hero-product img').waitFor({ state: 'visible' }); + }); + } finally { + await page.close(); + } +} +``` + +Each completed group invocation becomes one transaction: + +- `transaction_name`: the group path without its leading `::`, for example + `Checkout::Payment`. Nested groups produce separate parent and child rows; + the parent duration includes its children, so these durations are not additive. +- `response_time`: the whole callback/returned-promise lifetime in integer + milliseconds, including waits inside the group, on success **and** failure. +- `success`: `false` if the callback throws or its returned promise rejects; + otherwise `true`. The fork carries this outcome on the duration sample, without + adding tags or matching unrelated samples by name/timestamp. +- Browser requests and browser errors retain the group context and are associated + with the same transaction name. A group is not limited to HTTP requests: waits, + interactions, and other awaited work count toward its duration. + +A failed `check()` still writes an error record, but does not by itself reject the +group. Throw on a failed check when it should fail the transaction, as above. +Likewise, HTTP error status codes do not automatically reject `page.goto()`. +Errors caught inside a group do not fail that group. Catching a rejection outside +the group does not change its failed outcome. Always await/return the work being +measured. Work aborted before group completion may have no duration sample. + +Keep the `group` system tag enabled (the default) so names and associations are +available. Without it, transaction names fall back to `name` or `/`. + +## Legacy support and migration + +Existing `new Trend('pages', true)` scripts keep working unchanged: the `page` tag +is preferred as the transaction name and emitted samples remain successful rows. +If a legacy helper emits `pages` only on success, its failures still have no +transaction-duration row. This legacy behavior is deliberately preserved. + +`BREAKINGIT_TRANSACTION_SOURCE` selects which duration metrics become transactions: + +- `both` (default): export `pages` and `group_duration`. Use this for a mix of + legacy and native steps that each emit only one of the two duration metrics. +- `groups`: export only `group_duration`. Use this while wrapping old helpers + in native groups, to avoid recording the same step twice. +- `pages`: export only legacy `pages` durations. + +This selector affects only transaction rows, not requests, checks, browser errors, +or k6's own metric aggregation. Invalid values stop exporter initialization. +There is no automatic deduplication: names/timestamps cannot reliably distinguish +an intentional nested transaction from two measurements of the same step. + +For a full migration, remove `pages.add()` and use `await group(...)` for timing +and context, while keeping any business checks and throwing on failures. diff --git a/internal/output/breakingit/breakingit.go b/internal/output/breakingit/breakingit.go index 56e83ed74..9dcc29d98 100644 --- a/internal/output/breakingit/breakingit.go +++ b/internal/output/breakingit/breakingit.go @@ -17,6 +17,7 @@ import ( "net/url" "os" "regexp" + "strconv" "strings" "sync" "time" @@ -86,6 +87,7 @@ type Logger struct { envTags map[string]string customPatterns map[string]string isSynthetic bool + transactionSource transactionSource } func New(params output.Params) (output.Output, error) { @@ -107,6 +109,10 @@ func New(params output.Params) (output.Output, error) { if token == "" { return nil, fmt.Errorf("PG_PROXY_TOKEN is required for Authorization") } + transactionSource, err := parseTransactionSource(params.Environment["BREAKINGIT_TRANSACTION_SOURCE"]) + if err != nil { + return nil, err + } // HTTP client with keep-alive and TLS skip per proxy config tr := &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}} @@ -174,6 +180,7 @@ func New(params output.Params) (output.Output, error) { envTags: envTags, customPatterns: customPatterns, isSynthetic: isSynthetic, + transactionSource: transactionSource, } l.batchTimer = time.NewTimer(time.Second) go l.batchLoop() @@ -561,6 +568,10 @@ func (l *Logger) AddMetricSamples(samples []metrics.SampleContainer) { l.mu.Unlock() continue } + if (s.Metric.Name == "pages" && l.transactionSource == transactionsGroups) || + (s.Metric.Name == "group_duration" && l.transactionSource == transactionsPages) { + continue + } // pages -> transactions if s.Metric.Name == "pages" { m := s.Tags.Map() @@ -620,8 +631,9 @@ func (l *Logger) AddMetricSamples(samples []metrics.SampleContainer) { l.mu.Unlock() continue } - // k6 http group transactions -> transactions + // Native HTTP and browser groups -> transactions. if s.Metric.Name == "group_duration" { + success := strconv.FormatBool(!s.GroupFailed) m := s.Tags.Map() // Derive transaction_name from 'group' tag, fallback to 'name' nameRaw := fmt.Sprintf("%v", m["group"]) @@ -643,7 +655,7 @@ func (l *Logger) AddMetricSamples(samples []metrics.SampleContainer) { fmt.Sprintf("%v", l.envTags["node_name"]), fmt.Sprintf("%v", m["scenario"]), // thread_group_name from k6 scenario nameRaw, - "true", + success, "", "", fmtInt(s.Value), @@ -655,7 +667,7 @@ func (l *Logger) AddMetricSamples(samples []metrics.SampleContainer) { fmt.Sprintf("%v", l.envTags["run_id"]), fmt.Sprintf("%v", l.envTags["location"]), nameRaw, - "true", + success, "", "", fmtInt(s.Value), @@ -820,8 +832,10 @@ func (l *Logger) processHttpGroup(g *MetricGroup) { transactionName = g.Tags["transaction"] } else if g.Tags["group"] != "" { transactionName = strings.TrimPrefix(g.Tags["group"], "::") - // For browser, group is often auto-filled from path/name in copyTagsForHTTP; treat that as empty so we don't duplicate sampler_name. - if isBrowser && (transactionName == samplerName || transactionName == "/") { + // Native group paths start with "::". Keep these even when their name matches + // the request path; only discard the path/name fallback from copyTagsForHTTP. + if isBrowser && !strings.HasPrefix(g.Tags["group"], "::") && + (transactionName == samplerName || transactionName == "/") { transactionName = "" } } diff --git a/internal/output/breakingit/transactions.go b/internal/output/breakingit/transactions.go new file mode 100644 index 000000000..ae8df8177 --- /dev/null +++ b/internal/output/breakingit/transactions.go @@ -0,0 +1,26 @@ +package breakingit + +import "fmt" + +type transactionSource uint8 + +const ( + // Keep both existing mappings enabled by default for backwards compatibility. + transactionsBoth transactionSource = iota + transactionsPages + transactionsGroups +) + +func parseTransactionSource(value string) (transactionSource, error) { + switch value { + case "", "both": + return transactionsBoth, nil + case "pages": + return transactionsPages, nil + case "groups": + return transactionsGroups, nil + default: + return transactionsBoth, fmt.Errorf( + "invalid BREAKINGIT_TRANSACTION_SOURCE %q: expected both, pages, or groups", value) + } +} diff --git a/internal/output/breakingit/transactions_test.go b/internal/output/breakingit/transactions_test.go new file mode 100644 index 000000000..9d1368f91 --- /dev/null +++ b/internal/output/breakingit/transactions_test.go @@ -0,0 +1,238 @@ +package breakingit + +import ( + "bytes" + "compress/gzip" + "encoding/csv" + "fmt" + "io" + "mime" + "mime/multipart" + "net/http" + "net/http/httptest" + "testing" + "time" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "go.k6.io/k6/v2/metrics" + "go.k6.io/k6/v2/output" +) + +func newTransactionTestLogger(synthetic bool) *Logger { + return &Logger{ + out: io.Discard, isSynthetic: synthetic, + bufHTTP: &bytes.Buffer{}, bufVUs: &bytes.Buffer{}, + bufTrans: &bytes.Buffer{}, bufErrors: &bytes.Buffer{}, + pendingHttpGroups: make(map[int64]*MetricGroup), + envTags: map[string]string{ + "run_id": "run-123", "location": "Amsterdam", "node_name": "node-1", + "scenario_name": "checkout", + }, + } +} + +func transactionTestSample(name string, tags map[string]string, failed bool) metrics.Sample { + registry := metrics.NewRegistry() + return metrics.Sample{ + TimeSeries: metrics.TimeSeries{ + Metric: registry.MustNewMetric(name, metrics.Trend), + Tags: registry.RootTagSet().WithTagsFromMap(tags), + }, + Time: time.Date(2026, 9, 24, 12, 0, 0, 123000000, time.UTC), Value: 123.987, + GroupFailed: failed, + } +} + +func TestTransactionRows(t *testing.T) { + t.Parallel() + tests := []struct { + name, metric, expectedName string + tags map[string]string + failed bool + }{ + {"legacy page", "pages", "01_Home", map[string]string{"page": "01_Home", "group": "::wrapper"}, false}, + {"legacy URL fallback", "pages", "/home", map[string]string{"name": "https://example.test/home"}, false}, + {"legacy default", "pages", "/", nil, false}, + {"native success", "group_duration", "01_Home", map[string]string{"group": "::01_Home"}, false}, + {"native failure", "group_duration", "02_Pay", map[string]string{"group": "::02_Pay"}, true}, + {"nested", "group_duration", "Checkout::Payment", map[string]string{"group": "::Checkout::Payment"}, true}, + {"CSV escaping", "group_duration", "A,\"B\"\nC", map[string]string{"group": "::A,\"B\"\nC"}, false}, + {"group fallback", "group_duration", "fallback", map[string]string{"name": "fallback"}, false}, + {"group default", "group_duration", "/", nil, false}, + } + for _, synthetic := range []bool{false, true} { + for _, test := range tests { + t.Run(fmt.Sprintf("synthetic=%t/%s", synthetic, test.name), func(t *testing.T) { + t.Parallel() + l := newTransactionTestLogger(synthetic) + sample := transactionTestSample(test.metric, test.tags, test.failed) + sample.Tags = sample.Tags.With("scenario", "browser_checkout") + l.AddMetricSamples([]metrics.SampleContainer{sample}) + rows, err := csv.NewReader(l.bufTrans).ReadAll() + require.NoError(t, err) + expected := []string{ + "2026-09-24T12:00:00.123Z", "run-123", "Amsterdam", test.expectedName, + fmt.Sprint(!test.failed), "", "", "123", + } + if synthetic { + expected = []string{ + "2026-09-24T12:00:00.123Z", "checkout", "Amsterdam", "node-1", + "browser_checkout", test.expectedName, fmt.Sprint(!test.failed), + "", "", "123", "run-123", + } + } + assert.Equal(t, [][]string{expected}, rows) + }) + } + } +} + +func TestTransactionSource(t *testing.T) { + t.Parallel() + for _, test := range []struct { + value string + want []string + }{ + {"", []string{"legacy", "native"}}, + {"both", []string{"legacy", "native"}}, + {"pages", []string{"legacy"}}, + {"groups", []string{"native"}}, + } { + t.Run(test.value, func(t *testing.T) { + t.Parallel() + l := newTransactionTestLogger(false) + var err error + l.transactionSource, err = parseTransactionSource(test.value) + require.NoError(t, err) + l.AddMetricSamples([]metrics.SampleContainer{metrics.Samples{ + transactionTestSample("pages", map[string]string{"page": "legacy"}, false), + transactionTestSample("group_duration", map[string]string{"group": "::native"}, false), + }}) + rows, err := csv.NewReader(l.bufTrans).ReadAll() + require.NoError(t, err) + var names []string + for _, row := range rows { + names = append(names, row[3]) + } + assert.Equal(t, test.want, names) + // Filtering transaction durations must not drop failed checks. + check := transactionTestSample("checks", map[string]string{"group": "::native", "check": "bad"}, false) + check.Value = 0 + l.AddMetricSamples([]metrics.SampleContainer{check}) + errors, err := csv.NewReader(l.bufErrors).ReadAll() + require.NoError(t, err) + require.Len(t, errors, 1) + assert.Equal(t, "native", errors[0][4]) + }) + } +} + +func TestTransactionSourceConfiguration(t *testing.T) { + t.Setenv("PG_PROXY_TOKEN", "test-token") + for _, value := range []string{"", "both", "groups", "pages", "invalid"} { + exporter, err := New(output.Params{ + ConfigArgument: "http://127.0.0.1", StdOut: io.Discard, + Environment: map[string]string{"BREAKINGIT_TRANSACTION_SOURCE": value}, + }) + if value == "invalid" { + require.ErrorContains(t, err, "BREAKINGIT_TRANSACTION_SOURCE") + require.Nil(t, exporter) + continue + } + require.NoError(t, err) + t.Cleanup(func() { assert.NoError(t, exporter.Stop()) }) + want, err := parseTransactionSource(value) + require.NoError(t, err) + assert.Equal(t, want, exporter.(*Logger).transactionSource, "source=%q", value) + } +} + +func TestBrowserRequestKeepsExplicitGroup(t *testing.T) { + t.Parallel() + for _, synthetic := range []bool{false, true} { + for _, test := range []struct{ group, path, want string }{ + {"::Checkout::Pay", "/pay", "Checkout::Pay"}, + {"::/home", "/home", "/home"}, + {"::/", "/", "/"}, + {"/home", "/home", ""}, + {"/", "/", ""}, + } { + l := newTransactionTestLogger(synthetic) + l.processHttpGroup(&MetricGroup{ + Tags: map[string]string{"group": test.group, "path": test.path, "resource_type": "Document"}, + }) + rows, err := csv.NewReader(l.bufHTTP).ReadAll() + require.NoError(t, err) + require.Len(t, rows, 1) + index := 3 + if synthetic { + index = 5 + } + assert.Equal(t, test.want, rows[0][index], "group=%q synthetic=%t", test.group, synthetic) + } + } +} + +func TestTransactionsSentToProxy(t *testing.T) { + t.Parallel() + for _, synthetic := range []bool{false, true} { + t.Run(fmt.Sprint(synthetic), func(t *testing.T) { + t.Parallel() + type batch struct { + table string + rows [][]string + } + batches := make(chan batch, 1) + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + assert.Equal(t, "/ingest/batch", r.URL.Path) + assert.Equal(t, "Bearer test-token", r.Header.Get("Authorization")) + assert.Equal(t, "gzip", r.Header.Get("Content-Encoding")) + gz, err := gzip.NewReader(r.Body) + if !assert.NoError(t, err) { + w.WriteHeader(http.StatusOK) + return + } + defer func() { assert.NoError(t, gz.Close()) }() + _, params, err := mime.ParseMediaType(r.Header.Get("Content-Type")) + assert.NoError(t, err) + reader := multipart.NewReader(gz, params["boundary"]) + part, err := reader.NextPart() + if !assert.NoError(t, err) { + w.WriteHeader(http.StatusOK) + return + } + assert.Equal(t, "csv", part.Header.Get("X-Format")) + rows, err := csv.NewReader(part).ReadAll() + assert.NoError(t, err) + batches <- batch{part.Header.Get("X-Table"), rows} + _, err = reader.NextPart() + assert.ErrorIs(t, err, io.EOF) + w.WriteHeader(http.StatusOK) + })) + defer server.Close() + l := newTransactionTestLogger(synthetic) + l.proxyURL, l.token, l.httpClient = server.URL, "test-token", server.Client() + l.AddMetricSamples([]metrics.SampleContainer{ + transactionTestSample("pages", map[string]string{"page": "legacy"}, false), + transactionTestSample("group_duration", map[string]string{"group": "::native"}, true), + }) + l.flush() + select { + case got := <-batches: + wantTable, index := "public.transactions", 3 + if synthetic { + wantTable, index = "public.transactions_sm", 5 + } + assert.Equal(t, wantTable, got.table) + require.Len(t, got.rows, 2) + assert.Equal(t, []string{"legacy", "true"}, got.rows[0][index:index+2]) + assert.Equal(t, []string{"native", "false"}, got.rows[1][index:index+2]) + default: + t.Fatal("no transaction batch received") + } + assert.Zero(t, l.bufTrans.Len()) + }) + } +} diff --git a/metrics/sample.go b/metrics/sample.go index 6cf3cfdb7..2561a4ee0 100644 --- a/metrics/sample.go +++ b/metrics/sample.go @@ -37,6 +37,11 @@ type Sample struct { HTTPErrorReqBody string HTTPErrorResHeaders string HTTPErrorResBody string + + // GroupFailed is set on group_duration when the callback throws or its returned promise + // rejects. The breakingit output uses it for transaction outcomes without adding metric tags. + // Failed checks and errors caught inside the callback do not make a group fail. + GroupFailed bool } // SampleContainer is a simple abstraction that allows sample From d3dc5122b2b08f18d3abd1a89942e91a0995264d Mon Sep 17 00:00:00 2001 From: jgaalen Date: Tue, 29 Sep 2026 13:30:01 +0200 Subject: [PATCH 173/182] Fix metric context restoration during nested native promise settlement --- .../browser/tests/asyncgroup_context_test.go | 94 +++++++++++++++++++ js/common/metriccontext.go | 27 ++++-- js/common/metriccontext_test.go | 77 +++++++++++++++ 3 files changed, 188 insertions(+), 10 deletions(-) create mode 100644 internal/js/modules/k6/browser/tests/asyncgroup_context_test.go diff --git a/internal/js/modules/k6/browser/tests/asyncgroup_context_test.go b/internal/js/modules/k6/browser/tests/asyncgroup_context_test.go new file mode 100644 index 000000000..5a234298e --- /dev/null +++ b/internal/js/modules/k6/browser/tests/asyncgroup_context_test.go @@ -0,0 +1,94 @@ +package tests + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "go.k6.io/k6/v2/internal/js/modules/k6/browser/k6ext/k6test" + "go.k6.io/k6/v2/metrics" +) + +func TestAsyncGroupBrowserIterationContext(t *testing.T) { + t.Parallel() + + for _, nested := range []bool{false, true} { + name := "sequential" + if nested { + name = "nested_rejection" + } + t.Run(name, func(t *testing.T) { + t.Parallel() // Each browser VU must restore its own context independently. + tb := newTestBrowser(t) + prepareAsyncGroupBrowser(t, tb) + for iteration := range 3 { + if iteration > 0 { + tb.vu.State().Iteration = int64(iteration) + tb.vu.StartIteration(t, k6test.WithIteration(iteration)) + } + _, err := tb.vu.RunAsync(t, ` + const context = await browser.newContext(); + try { + const page = await context.newPage(); + const runGroups = async () => { + await k6.group('first', async () => { + await page.goto('data:text/html,

First

'); + k6.check(null, {first: true}); + }); + if (%t) { + const reason = {message: 'original rejection'}; + try { + await k6.group('rejected', async () => { + await page.goto('data:text/html,

Rejected

'); + throw reason; + }); + throw new Error('expected rejection'); + } catch (error) { + if (error !== reason) throw error; + } + } + await k6.group('last', async () => { + await page.goto('data:text/html,

Last

'); + k6.check(null, {last: true}); + }); + }; + if (%t) { await k6.group('parent', runGroups); } + else { await runGroups(); } + k6.check(null, {outside: true}); + } finally { + await context.close(); + k6.check(null, {cleanup: true}); + } + `, nested, nested) + require.NoError(t, err) + // Inspect ambient state after the event loop drains, not only JS await continuations. + group, _ := tb.vu.State().Tags.GetCurrentValues().Tags.Get("group") + assert.Empty(t, group, "context leaked after iteration %d", iteration) + tb.vu.EndIteration(t, k6test.WithIteration(iteration)) + } + + prefix := "" + expected := map[string]int{"::first": 3, "::last": 3} + if nested { + prefix = "::parent" + expected = map[string]int{ + "::parent": 3, "::parent::first": 3, "::parent::last": 3, "::parent::rejected": 3, + } + } + samples := collectBrowserSamples(tb) + counts := map[string]int{} + for _, sample := range samples { + if sample.Metric.Name == metrics.GroupDurationName { + group, _ := sample.Tags.Get("group") + counts[group]++ + assert.Positive(t, sample.Value) + } + } + assert.Equal(t, expected, counts) + assertBrowserCheckGroups(t, samples, map[string]string{ + "first": prefix + "::first", "last": prefix + "::last", "outside": "", "cleanup": "", + }) + }) + } +} diff --git a/js/common/metriccontext.go b/js/common/metriccontext.go index 2d1633a9d..accc27379 100644 --- a/js/common/metriccontext.go +++ b/js/common/metriccontext.go @@ -8,10 +8,11 @@ import ( ) // metricContextTracker propagates metric context through promise reactions, including await -// continuations. Promise reactions do not nest and run on the event-loop goroutine. +// continuations. Reactions run on the event-loop goroutine, but a native handler that settles +// another promise can re-enter Sobek's job queue before its own reaction exits. type metricContextTracker struct { - state func() *lib.State - restore func() + state func() *lib.State + restores []func() } // CapturedMetricContext is an immutable registration-time metric context. Its zero value is a @@ -41,18 +42,24 @@ func (t *metricContextTracker) Grab() any { func (t *metricContextTracker) Resumed(trackingObject any) { captured, ok := trackingObject.(metrics.TagsAndMeta) state := t.state() - if !ok || state == nil || state.Tags == nil { - t.restore = nil - return + var restore func() + if ok && state != nil && state.Tags != nil { + restore = ApplyMetricContext(state, captured) } - t.restore = ApplyMetricContext(state, captured) + t.restores = append(t.restores, restore) } // Exited restores the context that was active before the promise reaction ran. func (t *metricContextTracker) Exited() { - if t.restore != nil { - t.restore() - t.restore = nil + if len(t.restores) == 0 { + return + } + last := len(t.restores) - 1 + restore := t.restores[last] + t.restores[last] = nil + t.restores = t.restores[:last] + if restore != nil { + restore() } } diff --git a/js/common/metriccontext_test.go b/js/common/metriccontext_test.go index 751183006..149d31632 100644 --- a/js/common/metriccontext_test.go +++ b/js/common/metriccontext_test.go @@ -4,6 +4,7 @@ import ( "strconv" "testing" + "github.com/grafana/sobek" "github.com/stretchr/testify/require" "go.k6.io/k6/v2/internal/features" @@ -129,3 +130,79 @@ func BenchmarkCapturedMetricContext(b *testing.B) { }) } } + +// A native promise handler can settle another promise while Sobek drains jobs. The +// nested Go-to-JS call drains its reactions before the outer handler exits. +func TestMetricContextTrackerNativePromiseSettlement(t *testing.T) { + t.Parallel() + for _, rejectInner := range []bool{false, true} { + t.Run(strconv.FormatBool(rejectInner), func(t *testing.T) { + t.Parallel() + state := newMetricContextState(true) + rt := sobek.New() + rt.SetAsyncContextTracker(NewMetricContextTracker(func() *lib.State { return state })) + outer, resolveOuter, _ := rt.NewPromise() + inner, resolveInner, reject := rt.NewPromise() + require.NoError(t, rt.Set("outer", outer)) + require.NoError(t, rt.Set("inner", inner)) + setMetricContext(state, "::outer", "outer", "outer") + require.NoError(t, rt.Set("settle", func(sobek.FunctionCall) sobek.Value { + requireMetricContext(t, state, "::outer", "outer", "outer") + if rejectInner { + require.NoError(t, reject("reason")) + } else { + require.NoError(t, resolveInner("value")) + } + requireMetricContext(t, state, "::outer", "outer", "outer") + return sobek.Undefined() + })) + _, err := rt.RunString(`outer.then(settle)`) + require.NoError(t, err) + setMetricContext(state, "::inner", "inner", "inner") + require.NoError(t, rt.Set("checkInner", func() { + requireMetricContext(t, state, "::inner", "inner", "inner") + })) + _, err = rt.RunString(`inner.then(checkInner, checkInner)`) + require.NoError(t, err) + setMetricContext(state, "", "root", "root") + require.NoError(t, resolveOuter(nil)) + requireMetricContext(t, state, "", "root", "root") + }) + } +} + +func TestMetricContextTrackerNestedUntrackedReaction(t *testing.T) { + t.Parallel() + state := newMetricContextState(true) + tracker := NewMetricContextTracker(func() *lib.State { return state }) + setMetricContext(state, "::registered", "registered", "registered") + captured := tracker.Grab() + setMetricContext(state, "", "root", "root") + tracker.Resumed(captured) + // Init-context reactions have no captured tags but must still balance their exit. + tracker.Resumed(nil) + tracker.Exited() + requireMetricContext(t, state, "::registered", "registered", "registered") + tracker.Exited() + requireMetricContext(t, state, "", "root", "root") +} + +func TestMetricContextTrackerVUIsolation(t *testing.T) { + t.Parallel() + states := []*lib.State{newMetricContextState(true), newMetricContextState(true)} + trackers := make([]sobek.AsyncContextTracker, len(states)) + for i, state := range states { + trackers[i] = NewMetricContextTracker(func() *lib.State { return state }) + group := "::vu" + strconv.Itoa(i) + setMetricContext(state, group, group, group) + captured := trackers[i].Grab() + setMetricContext(state, "", "root", "root") + trackers[i].Resumed(captured) + } + // These are independent VUs, so their exits need not follow a shared stack order. + trackers[0].Exited() + requireMetricContext(t, states[0], "", "root", "root") + requireMetricContext(t, states[1], "::vu1", "::vu1", "::vu1") + trackers[1].Exited() + requireMetricContext(t, states[1], "", "root", "root") +} From 37dead08bed0abb8baeb429f1d6583d15ed2229a Mon Sep 17 00:00:00 2001 From: jgaalen Date: Tue, 29 Sep 2026 13:30:41 +0200 Subject: [PATCH 174/182] Document consolidated fork baseline and build workflow --- FORK.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/FORK.md b/FORK.md index 67ad09ec6..fab8e5cf4 100644 --- a/FORK.md +++ b/FORK.md @@ -29,7 +29,29 @@ code to the k6 executable. - Excludes extension-usage, installation-ID, and build-origin reporting in all builds. Basic anonymous run statistics retain the existing `K6_NO_USAGE_REPORT` opt-out. - Preserves custom browser timings and error payloads with upstream async metric context. +- Enables async metric context by default, with explicit feature lists retaining opt-out control. +- Exports native group durations and failure outcomes as BreakTest transactions alongside legacy + `pages` metrics. See [transaction configuration](internal/output/breakingit/README.md). +- Restores metric context correctly when native promise settlement re-enters the runtime, preventing + browser group paths from accumulating across iterations. - Excludes upstream's Grafana-specific Renovate approval automation. +## Development and builds in jgaalen/k6 + +`master` is the consolidated development branch, based on upstream k6 v2.3.0. The `breakingit` branch +is kept aligned after integrations. Build from `master` to include the fork customizations, native +group transactions, and the browser group-context fix together. Feature branches can contain work +that has not yet been integrated; `codex/browser-admission-control` remains a separate feature. + +```sh +git switch master +git pull --ff-only origin master +./build-linux-binaries.sh +``` + +The build script reads the source in the current checkout and writes Linux and macOS binaries for +amd64 and arm64 into `dist/`. It does not install or deploy them. Its displayed `VERSION` value is +informational; use the binary's `version` command and SHA-256 checksum to identify an artifact. + For the complete change history, compare the `breakingit` branch with the upstream [grafana/k6](https://github.com/grafana/k6) repository. From 513e2cd00d634b85d89a559b423d5cb0a1a3b12a Mon Sep 17 00:00:00 2001 From: jgaalen Date: Tue, 18 Aug 2026 21:49:21 +0200 Subject: [PATCH 175/182] Add browser admission control --- .../modules/k6/browser/browser/admission.go | 399 ++++++++++++++++++ .../k6/browser/browser/admission_linux.go | 75 ++++ .../k6/browser/browser/admission_other.go | 7 + .../k6/browser/browser/admission_test.go | 191 +++++++++ .../js/modules/k6/browser/browser/module.go | 8 + .../js/modules/k6/browser/browser/registry.go | 60 ++- internal/js/modules/k6/browser/env/env.go | 20 + internal/output/breakingit/breakingit.go | 101 +++-- internal/output/breakingit/breakingit_test.go | 121 ++++++ 9 files changed, 936 insertions(+), 46 deletions(-) create mode 100644 internal/js/modules/k6/browser/browser/admission.go create mode 100644 internal/js/modules/k6/browser/browser/admission_linux.go create mode 100644 internal/js/modules/k6/browser/browser/admission_other.go create mode 100644 internal/js/modules/k6/browser/browser/admission_test.go create mode 100644 internal/output/breakingit/breakingit_test.go diff --git a/internal/js/modules/k6/browser/browser/admission.go b/internal/js/modules/k6/browser/browser/admission.go new file mode 100644 index 000000000..9b8f44b90 --- /dev/null +++ b/internal/js/modules/k6/browser/browser/admission.go @@ -0,0 +1,399 @@ +package browser + +import ( + "context" + "fmt" + "strconv" + "sync" + "time" + + "go.k6.io/k6/v2/internal/js/modules/k6/browser/chromium" + "go.k6.io/k6/v2/internal/js/modules/k6/browser/common" + "go.k6.io/k6/v2/internal/js/modules/k6/browser/env" + + k6modules "go.k6.io/k6/v2/js/modules" + k6metrics "go.k6.io/k6/v2/metrics" +) + +const ( + defaultBrowserAdmissionPollInterval = 250 * time.Millisecond + defaultBrowserEndpointCooldown = 5 * time.Second + browserAdmissionBlockedLogInterval = 30 * time.Second +) + +type browserResourceSnapshot struct { + availableMemoryMB int64 + memoryKnown bool + availableShmMB int64 + shmKnown bool +} + +type browserResourceProbe func() browserResourceSnapshot + +type browserAdmissionMetrics struct { + active *k6metrics.Metric + waiting *k6metrics.Metric +} + +type browserAdmissionReporter func(active, waiting int) + +type browserAdmissionBlock struct { + reason string + active int + waiting int + maxActive int + minAvailableMemoryMB int + minAvailableShmMB int + resources browserResourceSnapshot +} + +type browserAdmissionBlockedReporter func(block browserAdmissionBlock) + +type remoteBrowserEndpoint struct { + wsURL string + active int + unhealthyUntil time.Time +} + +type browserLease struct { + registry *remoteRegistry + endpointIndex int + wsURL string + once sync.Once + onChange browserAdmissionReporter +} + +func (l *browserLease) release() { + if l == nil || l.registry == nil { + return + } + l.once.Do(func() { + active, waiting := l.registry.release(l.endpointIndex) + if l.onChange != nil { + l.onChange(active, waiting) + } + }) +} + +func (r *remoteRegistry) configureAdmission(envLookup env.LookupFunc) error { + var err error + r.maxActiveContexts, err = lookupNonNegativeInt(envLookup, env.BrowserMaxActiveContexts) + if err != nil { + return err + } + r.minAvailableMemoryMB, err = lookupNonNegativeInt(envLookup, env.BrowserMinAvailableMemoryMB) + if err != nil { + return err + } + r.minAvailableShmMB, err = lookupNonNegativeInt(envLookup, env.BrowserMinAvailableShmMB) + if err != nil { + return err + } + r.pollInterval, err = lookupPositiveDuration( + envLookup, env.BrowserAdmissionPollInterval, defaultBrowserAdmissionPollInterval, + ) + if err != nil { + return err + } + r.endpointCooldown, err = lookupPositiveDuration( + envLookup, env.BrowserEndpointCooldown, defaultBrowserEndpointCooldown, + ) + if err != nil { + return err + } + r.resourceProbe = probeBrowserResources + r.endpoints = make([]remoteBrowserEndpoint, 0, len(r.wsURLs)) + for _, wsURL := range r.wsURLs { + r.endpoints = append(r.endpoints, remoteBrowserEndpoint{wsURL: wsURL}) + } + return nil +} + +func lookupNonNegativeInt(envLookup env.LookupFunc, key string) (int, error) { + value, ok := envLookup(key) + if !ok || value == "" { + return 0, nil + } + parsed, err := strconv.Atoi(value) + if err != nil || parsed < 0 { + return 0, fmt.Errorf("%s must be a non-negative integer", key) + } + return parsed, nil +} + +func lookupPositiveDuration(envLookup env.LookupFunc, key string, fallback time.Duration) (time.Duration, error) { + value, ok := envLookup(key) + if !ok || value == "" { + return fallback, nil + } + parsed, err := time.ParseDuration(value) + if err != nil || parsed <= 0 { + return 0, fmt.Errorf("%s must be a positive duration", key) + } + return parsed, nil +} + +func (r *remoteRegistry) admissionEnabled() bool { + return r.maxActiveContexts > 0 || r.minAvailableMemoryMB > 0 || r.minAvailableShmMB > 0 +} + +func (r *remoteRegistry) endpointCount() int { + r.mu.Lock() + defer r.mu.Unlock() + return len(r.endpoints) +} + +func (r *remoteRegistry) acquire( + ctx context.Context, excluded map[int]struct{}, +) (*browserLease, error) { + return r.acquireWithReporter(ctx, excluded, nil) +} + +func (r *remoteRegistry) acquireWithReporter( + ctx context.Context, excluded map[int]struct{}, report browserAdmissionReporter, +) (*browserLease, error) { + return r.acquireWithTelemetry(ctx, excluded, report, nil) +} + +func (r *remoteRegistry) acquireWithTelemetry( + ctx context.Context, + excluded map[int]struct{}, + report browserAdmissionReporter, + reportBlocked browserAdmissionBlockedReporter, +) (*browserLease, error) { + r.mu.Lock() + r.waitingContexts++ + active, waiting := r.activeContexts, r.waitingContexts + r.mu.Unlock() + if report != nil { + report(active, waiting) + } + + for { + resources := r.resourceProbe() + now := time.Now() + r.mu.Lock() + blockedBy := r.blockReasonLocked(resources) + endpointIndex := -1 + if blockedBy == "" { + endpointIndex = r.selectEndpointLocked(now, excluded) + if r.isRemote && endpointIndex < 0 { + blockedBy = "endpoint" + } + } + if blockedBy == "" { + r.waitingContexts-- + r.activeContexts++ + wsURL := "" + if endpointIndex >= 0 { + r.endpoints[endpointIndex].active++ + wsURL = r.endpoints[endpointIndex].wsURL + } + active, waiting = r.activeContexts, r.waitingContexts + r.mu.Unlock() + if report != nil { + report(active, waiting) + } + return &browserLease{ + registry: r, + endpointIndex: endpointIndex, + wsURL: wsURL, + onChange: report, + }, nil + } + shouldReportBlocked := reportBlocked != nil && r.shouldReportBlockedLocked(blockedBy, now) + block := browserAdmissionBlock{ + reason: blockedBy, + active: r.activeContexts, + waiting: r.waitingContexts, + maxActive: r.maxActiveContexts, + minAvailableMemoryMB: r.minAvailableMemoryMB, + minAvailableShmMB: r.minAvailableShmMB, + resources: resources, + } + r.mu.Unlock() + if shouldReportBlocked { + reportBlocked(block) + } + + timer := time.NewTimer(r.pollInterval) + select { + case <-ctx.Done(): + if !timer.Stop() { + <-timer.C + } + r.mu.Lock() + if r.waitingContexts > 0 { + r.waitingContexts-- + } + active, waiting = r.activeContexts, r.waitingContexts + r.mu.Unlock() + if report != nil { + report(active, waiting) + } + return nil, ctx.Err() + case <-timer.C: + } + } +} + +func (r *remoteRegistry) blockReasonLocked(resources browserResourceSnapshot) string { + if r.maxActiveContexts > 0 && r.activeContexts >= r.maxActiveContexts { + return "capacity" + } + if r.minAvailableMemoryMB > 0 && resources.memoryKnown && + resources.availableMemoryMB < int64(r.minAvailableMemoryMB) { + return "memory" + } + if r.minAvailableShmMB > 0 && resources.shmKnown && + resources.availableShmMB < int64(r.minAvailableShmMB) { + return "shm" + } + return "" +} + +func (r *remoteRegistry) shouldReportBlockedLocked(reason string, now time.Time) bool { + if reason != r.lastBlockedReason || now.Sub(r.lastBlockedLog) >= browserAdmissionBlockedLogInterval { + r.lastBlockedReason = reason + r.lastBlockedLog = now + return true + } + return false +} + +func (r *remoteRegistry) selectEndpointLocked(now time.Time, excluded map[int]struct{}) int { + if !r.isRemote { + return -1 + } + best := -1 + for offset := range len(r.endpoints) { + index := (r.nextEndpoint + offset) % len(r.endpoints) + endpoint := &r.endpoints[index] + if _, skip := excluded[index]; skip || now.Before(endpoint.unhealthyUntil) { + continue + } + if best < 0 || endpoint.active < r.endpoints[best].active { + best = index + } + } + if best >= 0 { + r.nextEndpoint = (best + 1) % len(r.endpoints) + } + return best +} + +func (r *remoteRegistry) release(endpointIndex int) (active, waiting int) { + r.mu.Lock() + defer r.mu.Unlock() + if r.activeContexts > 0 { + r.activeContexts-- + } + if endpointIndex >= 0 && endpointIndex < len(r.endpoints) && r.endpoints[endpointIndex].active > 0 { + r.endpoints[endpointIndex].active-- + } + return r.activeContexts, r.waitingContexts +} + +func newBrowserAdmissionReporter( + vu k6modules.VU, admissionMetrics *browserAdmissionMetrics, +) browserAdmissionReporter { + if admissionMetrics == nil || admissionMetrics.active == nil || admissionMetrics.waiting == nil { + return nil + } + return func(active, waiting int) { + state := vu.State() + if state == nil { + return + } + now := time.Now() + tags := state.Tags.GetCurrentValues().Tags + k6metrics.PushIfNotDone(vu.Context(), state.Samples, k6metrics.ConnectedSamples{ + Samples: []k6metrics.Sample{ + { + TimeSeries: k6metrics.TimeSeries{Metric: admissionMetrics.active, Tags: tags}, + Time: now, + Value: float64(active), + }, + { + TimeSeries: k6metrics.TimeSeries{Metric: admissionMetrics.waiting, Tags: tags}, + Time: now, + Value: float64(waiting), + }, + }, + Tags: tags, + Time: now, + }) + } +} + +func newBrowserAdmissionBlockedReporter(vu k6modules.VU) browserAdmissionBlockedReporter { + return func(block browserAdmissionBlock) { + state := vu.State() + if state == nil { + return + } + state.Logger.Infof( + "browser admission blocked_by=%s active=%d waiting=%d max_active=%d "+ + "available_memory_mb=%d memory_known=%t min_memory_mb=%d "+ + "available_shm_mb=%d shm_known=%t min_shm_mb=%d", + block.reason, block.active, block.waiting, block.maxActive, + block.resources.availableMemoryMB, block.resources.memoryKnown, block.minAvailableMemoryMB, + block.resources.availableShmMB, block.resources.shmKnown, block.minAvailableShmMB, + ) + } +} + +func (r *remoteRegistry) markEndpointFailed(endpointIndex int) { + if endpointIndex < 0 { + return + } + r.mu.Lock() + defer r.mu.Unlock() + if endpointIndex < len(r.endpoints) { + r.endpoints[endpointIndex].unhealthyUntil = time.Now().Add(r.endpointCooldown) + } +} + +func buildAdmittedBrowser( + ctx, vuCtx context.Context, + vu k6modules.VU, + bt *chromium.BrowserType, + remote *remoteRegistry, + pids *pidRegistry, +) (*common.Browser, *browserLease, error) { + excluded := make(map[int]struct{}) + report := newBrowserAdmissionReporter(vu, remote.admissionMetrics) + reportBlocked := newBrowserAdmissionBlockedReporter(vu) + for { + lease, err := remote.acquireWithTelemetry(vuCtx, excluded, report, reportBlocked) + if err != nil { + return nil, nil, err + } + + if !remote.isRemote { + browser, pid, launchErr := bt.Launch(ctx, vuCtx) + if launchErr != nil { + lease.release() + return nil, nil, launchErr //nolint:wrapcheck + } + pids.registerPid(pid) + return browser, lease, nil + } + + browser, connectErr := bt.Connect(ctx, vuCtx, lease.wsURL) + if connectErr == nil { + return browser, lease, nil + } + + remote.markEndpointFailed(lease.endpointIndex) + lease.release() + excluded[lease.endpointIndex] = struct{}{} + vu.State().Logger.Warnf( + "remote browser endpoint %q failed; quarantining it for %s and trying another: %v", + lease.wsURL, remote.endpointCooldown, connectErr, + ) + if len(excluded) >= remote.endpointCount() { + clear(excluded) + } + } +} diff --git a/internal/js/modules/k6/browser/browser/admission_linux.go b/internal/js/modules/k6/browser/browser/admission_linux.go new file mode 100644 index 000000000..100f34216 --- /dev/null +++ b/internal/js/modules/k6/browser/browser/admission_linux.go @@ -0,0 +1,75 @@ +//go:build linux + +package browser + +import ( + "os" + "strconv" + "strings" + + "golang.org/x/sys/unix" +) + +const bytesPerMiB = 1024 * 1024 + +func probeBrowserResources() browserResourceSnapshot { + var snapshot browserResourceSnapshot + if data, err := os.ReadFile("/proc/meminfo"); err == nil { + for _, line := range strings.Split(string(data), "\n") { + fields := strings.Fields(line) + if len(fields) < 2 || fields[0] != "MemAvailable:" { + continue + } + if availableKB, err := strconv.ParseInt(fields[1], 10, 64); err == nil { + snapshot.availableMemoryMB = availableKB / 1024 + snapshot.memoryKnown = true + } + break + } + } + if cgroupAvailableMB, ok := cgroupAvailableMemoryMB(); ok && + (!snapshot.memoryKnown || cgroupAvailableMB < snapshot.availableMemoryMB) { + snapshot.availableMemoryMB = cgroupAvailableMB + snapshot.memoryKnown = true + } + + var stat unix.Statfs_t + if err := unix.Statfs("/dev/shm", &stat); err == nil { + snapshot.availableShmMB = int64(stat.Bavail) * int64(stat.Bsize) / bytesPerMiB + snapshot.shmKnown = true + } + return snapshot +} + +func cgroupAvailableMemoryMB() (int64, bool) { + for _, files := range [][2]string{ + {"/sys/fs/cgroup/memory.max", "/sys/fs/cgroup/memory.current"}, + {"/sys/fs/cgroup/memory/memory.limit_in_bytes", "/sys/fs/cgroup/memory/memory.usage_in_bytes"}, + } { + limitRaw, err := os.ReadFile(files[0]) + if err != nil { + continue + } + limitText := strings.TrimSpace(string(limitRaw)) + if limitText == "max" { + continue + } + limit, err := strconv.ParseInt(limitText, 10, 64) + if err != nil || limit <= 0 || limit >= 1<<60 { + continue + } + currentRaw, err := os.ReadFile(files[1]) + if err != nil { + continue + } + current, err := strconv.ParseInt(strings.TrimSpace(string(currentRaw)), 10, 64) + if err != nil || current < 0 { + continue + } + if current >= limit { + return 0, true + } + return (limit - current) / bytesPerMiB, true + } + return 0, false +} diff --git a/internal/js/modules/k6/browser/browser/admission_other.go b/internal/js/modules/k6/browser/browser/admission_other.go new file mode 100644 index 000000000..5da180400 --- /dev/null +++ b/internal/js/modules/k6/browser/browser/admission_other.go @@ -0,0 +1,7 @@ +//go:build !linux + +package browser + +func probeBrowserResources() browserResourceSnapshot { + return browserResourceSnapshot{} +} diff --git a/internal/js/modules/k6/browser/browser/admission_test.go b/internal/js/modules/k6/browser/browser/admission_test.go new file mode 100644 index 000000000..f4a790755 --- /dev/null +++ b/internal/js/modules/k6/browser/browser/admission_test.go @@ -0,0 +1,191 @@ +package browser + +import ( + "context" + "errors" + "testing" + "time" + + "github.com/stretchr/testify/require" + + "go.k6.io/k6/v2/internal/js/modules/k6/browser/env" +) + +func admissionLookup(values map[string]string) env.LookupFunc { + return func(key string) (string, bool) { + value, ok := values[key] + return value, ok + } +} + +func TestBrowserAdmissionCapsActiveContexts(t *testing.T) { + t.Parallel() + + registry, err := newRemoteRegistry(admissionLookup(map[string]string{ + env.WebSocketURLs: "ws://browser-1,ws://browser-2", + env.BrowserMaxActiveContexts: "2", + env.BrowserAdmissionPollInterval: "5ms", + })) + require.NoError(t, err) + registry.resourceProbe = func() browserResourceSnapshot { return browserResourceSnapshot{} } + + first, err := registry.acquire(context.Background(), nil) + require.NoError(t, err) + second, err := registry.acquire(context.Background(), nil) + require.NoError(t, err) + + waitCtx, cancel := context.WithTimeout(context.Background(), 25*time.Millisecond) + defer cancel() + _, err = registry.acquire(waitCtx, nil) + require.ErrorIs(t, err, context.DeadlineExceeded) + + first.release() + third, err := registry.acquire(context.Background(), nil) + require.NoError(t, err) + second.release() + third.release() +} + +func TestBrowserAdmissionReportsActiveAndWaitingContexts(t *testing.T) { + t.Parallel() + + registry, err := newRemoteRegistry(admissionLookup(map[string]string{ + env.WebSocketURLs: "ws://browser-1", + env.BrowserMaxActiveContexts: "1", + env.BrowserAdmissionPollInterval: "5ms", + })) + require.NoError(t, err) + registry.resourceProbe = func() browserResourceSnapshot { return browserResourceSnapshot{} } + + type counts struct{ active, waiting int } + reports := make([]counts, 0, 6) + report := func(active, waiting int) { + reports = append(reports, counts{active: active, waiting: waiting}) + } + + lease, err := registry.acquireWithReporter(context.Background(), nil, report) + require.NoError(t, err) + require.Equal(t, counts{active: 1, waiting: 0}, reports[len(reports)-1]) + + waitCtx, cancel := context.WithTimeout(context.Background(), 25*time.Millisecond) + defer cancel() + _, err = registry.acquireWithReporter(waitCtx, nil, report) + require.ErrorIs(t, err, context.DeadlineExceeded) + require.Contains(t, reports, counts{active: 1, waiting: 1}) + require.Equal(t, counts{active: 1, waiting: 0}, reports[len(reports)-1]) + + lease.release() + require.Equal(t, counts{active: 0, waiting: 0}, reports[len(reports)-1]) +} + +func TestBrowserAdmissionReportsWhyAcquisitionIsBlocked(t *testing.T) { + t.Parallel() + + registry, err := newRemoteRegistry(admissionLookup(map[string]string{ + env.WebSocketURLs: "ws://browser-1", + env.BrowserMaxActiveContexts: "1", + env.BrowserAdmissionPollInterval: "5ms", + })) + require.NoError(t, err) + registry.resourceProbe = func() browserResourceSnapshot { return browserResourceSnapshot{} } + + lease, err := registry.acquire(context.Background(), nil) + require.NoError(t, err) + + blocked := make(chan browserAdmissionBlock, 1) + waitCtx, cancel := context.WithTimeout(context.Background(), 25*time.Millisecond) + defer cancel() + _, err = registry.acquireWithTelemetry(waitCtx, nil, nil, func(block browserAdmissionBlock) { + select { + case blocked <- block: + default: + } + }) + require.ErrorIs(t, err, context.DeadlineExceeded) + + reported := <-blocked + require.Equal(t, "capacity", reported.reason) + require.Equal(t, 1, reported.active) + require.Equal(t, 1, reported.waiting) + require.Equal(t, 1, reported.maxActive) + lease.release() +} + +func TestBrowserAdmissionBalancesAndQuarantinesEndpoints(t *testing.T) { + t.Parallel() + + registry, err := newRemoteRegistry(admissionLookup(map[string]string{ + env.WebSocketURLs: "ws://browser-1,ws://browser-2,ws://browser-3", + env.BrowserMaxActiveContexts: "10", + env.BrowserEndpointCooldown: "1h", + })) + require.NoError(t, err) + registry.resourceProbe = func() browserResourceSnapshot { return browserResourceSnapshot{} } + + first, err := registry.acquire(context.Background(), nil) + require.NoError(t, err) + second, err := registry.acquire(context.Background(), nil) + require.NoError(t, err) + third, err := registry.acquire(context.Background(), nil) + require.NoError(t, err) + require.ElementsMatch(t, + []string{"ws://browser-1", "ws://browser-2", "ws://browser-3"}, + []string{first.wsURL, second.wsURL, third.wsURL}, + ) + + registry.markEndpointFailed(first.endpointIndex) + first.release() + fourth, err := registry.acquire(context.Background(), nil) + require.NoError(t, err) + require.NotEqual(t, first.wsURL, fourth.wsURL) + + second.release() + third.release() + fourth.release() +} + +func TestBrowserAdmissionWaitsForResourceHeadroom(t *testing.T) { + t.Parallel() + + registry, err := newRemoteRegistry(admissionLookup(map[string]string{ + env.WebSocketURLs: "ws://browser-1", + env.BrowserMinAvailableMemoryMB: "2048", + env.BrowserMinAvailableShmMB: "768", + env.BrowserAdmissionPollInterval: "5ms", + })) + require.NoError(t, err) + registry.resourceProbe = func() browserResourceSnapshot { + return browserResourceSnapshot{ + availableMemoryMB: 2047, + memoryKnown: true, + availableShmMB: 767, + shmKnown: true, + } + } + + waitCtx, cancel := context.WithTimeout(context.Background(), 25*time.Millisecond) + defer cancel() + _, err = registry.acquire(waitCtx, nil) + require.True(t, errors.Is(err, context.DeadlineExceeded)) + + registry.resourceProbe = func() browserResourceSnapshot { + return browserResourceSnapshot{ + availableMemoryMB: 4096, + memoryKnown: true, + availableShmMB: 1024, + shmKnown: true, + } + } + lease, err := registry.acquire(context.Background(), nil) + require.NoError(t, err) + lease.release() +} + +func TestBrowserAdmissionRejectsInvalidConfiguration(t *testing.T) { + t.Parallel() + + _, err := newRemoteRegistry(admissionLookup(map[string]string{ + env.BrowserMaxActiveContexts: "not-a-number", + })) + require.EqualError(t, err, "K6_BROWSER_MAX_ACTIVE_CONTEXTS must be a non-negative integer") +} diff --git a/internal/js/modules/k6/browser/browser/module.go b/internal/js/modules/k6/browser/browser/module.go index 74b1e04c4..3a00bdf8e 100644 --- a/internal/js/modules/k6/browser/browser/module.go +++ b/internal/js/modules/k6/browser/browser/module.go @@ -39,6 +39,8 @@ type ( filePersister filePersister testRunID string browserErrors *k6metrics.Metric + browserActiveVUs *k6metrics.Metric + browserWaitingVUs *k6metrics.Metric screenshotOnError bool } @@ -137,6 +139,12 @@ func (m *RootModule) initialize(vu k6modules.VU) { m.testRunID = e } m.browserErrors = initEnv.Registry.MustNewMetric("browser_errors", k6metrics.Counter) + m.browserActiveVUs = initEnv.Registry.MustNewMetric("browser_active_vus", k6metrics.Gauge) + m.browserWaitingVUs = initEnv.Registry.MustNewMetric("browser_waiting_vus", k6metrics.Gauge) + m.remoteRegistry.admissionMetrics = &browserAdmissionMetrics{ + active: m.browserActiveVUs, + waiting: m.browserWaitingVUs, + } if v, ok := initEnv.LookupEnv(env.ScreenshotOnError); ok && v == "true" { m.screenshotOnError = true } diff --git a/internal/js/modules/k6/browser/browser/registry.go b/internal/js/modules/k6/browser/browser/registry.go index 1ddc54f2e..3db4af6c4 100644 --- a/internal/js/modules/k6/browser/browser/registry.go +++ b/internal/js/modules/k6/browser/browser/registry.go @@ -11,6 +11,7 @@ import ( "strconv" "strings" "sync" + "time" "go.opentelemetry.io/otel/attribute" oteltrace "go.opentelemetry.io/otel/trace" @@ -63,6 +64,21 @@ func (r *pidRegistry) Pids() []int { type remoteRegistry struct { isRemote bool wsURLs []string + + mu sync.Mutex + endpoints []remoteBrowserEndpoint + nextEndpoint int + activeContexts int + maxActiveContexts int + minAvailableMemoryMB int + minAvailableShmMB int + pollInterval time.Duration + endpointCooldown time.Duration + resourceProbe browserResourceProbe + waitingContexts int + admissionMetrics *browserAdmissionMetrics + lastBlockedReason string + lastBlockedLog time.Time } // newRemoteRegistry will create a new RemoteRegistry. This will @@ -81,11 +97,13 @@ func newRemoteRegistry(envLookup env.LookupFunc) (*remoteRegistry, error) { if isRemote { r.isRemote = isRemote r.wsURLs = wsURLs - return r, nil + } else { + r.isRemote, r.wsURLs = checkForBrowserWSURLs(envLookup) } - r.isRemote, r.wsURLs = checkForBrowserWSURLs(envLookup) - + if err := r.configureAdmission(envLookup); err != nil { + return nil, err + } return r, nil } @@ -179,6 +197,8 @@ type browserRegistry struct { mu sync.RWMutex m map[int64]*common.Browser + // leases tracks admission capacity held by each managed browser iteration. + leases map[int64]*browserLease // userManaged holds browsers created via chromium.connectOverCDP, keyed by // iteration. Unlike m (browsers k6 launches/connects from scenario options), // these are connected by the script at runtime. k6 still sweeps them on @@ -189,7 +209,7 @@ type browserRegistry struct { buildFn browserBuildFunc } -type browserBuildFunc func(ctx, vuCtx context.Context) (*common.Browser, error) +type browserBuildFunc func(ctx, vuCtx context.Context) (*common.Browser, *browserLease, error) // newBrowserRegistry should only take a background context, not a context from // k6 (i.e. vu). The reason for this is that we want to control the chromium @@ -208,7 +228,10 @@ func newBrowserRegistry( tracesMetadata map[string]string, ) *browserRegistry { bt := chromium.NewBrowserType(vu) - builder := func(ctx, vuCtx context.Context) (*common.Browser, error) { + builder := func(ctx, vuCtx context.Context) (*common.Browser, *browserLease, error) { + if remote.admissionEnabled() { + return buildAdmittedBrowser(ctx, vuCtx, vu, bt, remote, pids) + } var ( err error b *common.Browser @@ -218,24 +241,25 @@ func newBrowserRegistry( if isRemoteBrowser { b, err = bt.Connect(ctx, vuCtx, wsURL) if err != nil { - return nil, err //nolint:wrapcheck + return nil, nil, err //nolint:wrapcheck } } else { var pid int b, pid, err = bt.Launch(ctx, vuCtx) if err != nil { - return nil, err //nolint:wrapcheck + return nil, nil, err //nolint:wrapcheck } pids.registerPid(pid) } - return b, nil + return b, nil, nil } r := &browserRegistry{ vu: vu, tracesMetadata: tracesMetadata, m: make(map[int64]*common.Browser), + leases: make(map[int64]*browserLease), userManaged: make(map[int64][]*common.Browser), buildFn: builder, } @@ -321,16 +345,19 @@ func (r *browserRegistry) handleIterEvents( tracerCtx := common.WithTracer(r.vu.Context(), r.tr.tracer) tracedCtx := r.tr.startIterationTrace(tracerCtx, data) - b, err := r.buildFn(ctx, tracedCtx) + b, lease, err := r.buildFn(ctx, tracedCtx) if err != nil { e.Done() + if vuCtx.Err() != nil { + continue + } k6ext.Abortf(vuCtx, "error building browser on IterStart: %v", err) // Continue so we don't block the k6 event system producer. // Test will be aborted by k6, which will previously send the // 'Exit' event so browser resources cleanup can be guaranteed. continue } - r.setBrowser(data.Iteration, b) + r.setBrowser(data.Iteration, b, lease) case k6event.IterEnd: // Always sweep user-managed browsers and end any iteration trace, // even for non-browser iterations (connectOverCDP runs in @@ -378,11 +405,14 @@ func (r *browserRegistry) handleExitEvent(exitCh <-chan *k6event.Event, unsubscr r.stopTracesRegistry() } -func (r *browserRegistry) setBrowser(id int64, b *common.Browser) { +func (r *browserRegistry) setBrowser(id int64, b *common.Browser, lease *browserLease) { r.mu.Lock() defer r.mu.Unlock() r.m[id] = b + if lease != nil { + r.leases[id] = lease + } } func (r *browserRegistry) getBrowser(id int64) (*common.Browser, error) { @@ -404,6 +434,10 @@ func (r *browserRegistry) deleteBrowser(id int64) { b.Close() delete(r.m, id) } + if lease, ok := r.leases[id]; ok { + lease.release() + delete(r.leases, id) + } } // This is only used in a test. Avoids having to manipulate the mutex in the @@ -422,6 +456,10 @@ func (r *browserRegistry) clear() { for id, b := range r.m { b.Close() delete(r.m, id) + if lease, ok := r.leases[id]; ok { + lease.release() + delete(r.leases, id) + } } for iter, browsers := range r.userManaged { for _, b := range browsers { diff --git a/internal/js/modules/k6/browser/env/env.go b/internal/js/modules/k6/browser/env/env.go index 5264b3e02..279e53457 100644 --- a/internal/js/modules/k6/browser/env/env.go +++ b/internal/js/modules/k6/browser/env/env.go @@ -39,6 +39,26 @@ const ( // BrowserGlobalTimeout is an environment variable that can be used // to set the global timeout for the browser. BrowserGlobalTimeout = "K6_BROWSER_TIMEOUT" + + // BrowserMaxActiveContexts caps the number of managed browser contexts + // that may be active at once across all VUs. + BrowserMaxActiveContexts = "K6_BROWSER_MAX_ACTIVE_CONTEXTS" + + // BrowserMinAvailableMemoryMB pauses new managed browser contexts while + // system available memory is below this many MiB. + BrowserMinAvailableMemoryMB = "K6_BROWSER_MIN_AVAILABLE_MEMORY_MB" + + // BrowserMinAvailableShmMB pauses new managed browser contexts while + // /dev/shm available space is below this many MiB. + BrowserMinAvailableShmMB = "K6_BROWSER_MIN_AVAILABLE_SHM_MB" + + // BrowserAdmissionPollInterval controls how often a VU waiting for browser + // capacity rechecks resource headroom. + BrowserAdmissionPollInterval = "K6_BROWSER_ADMISSION_POLL_INTERVAL" + + // BrowserEndpointCooldown controls how long a failed remote browser + // endpoint is quarantined before it can be retried. + BrowserEndpointCooldown = "K6_BROWSER_ENDPOINT_COOLDOWN" ) // Logging and debugging. diff --git a/internal/output/breakingit/breakingit.go b/internal/output/breakingit/breakingit.go index 9dcc29d98..71bdab7a3 100644 --- a/internal/output/breakingit/breakingit.go +++ b/internal/output/breakingit/breakingit.go @@ -6,8 +6,8 @@ import ( "crypto/rand" "crypto/sha256" "crypto/tls" - "encoding/hex" "encoding/csv" + "encoding/hex" "encoding/json" "fmt" "io" @@ -69,9 +69,9 @@ type Logger struct { httpClient *http.Client // batch buffers - mu sync.Mutex - bufHTTP *bytes.Buffer - bufVUs *bytes.Buffer + mu sync.Mutex + bufHTTP *bytes.Buffer + bufVUs *bytes.Buffer bufTrans *bytes.Buffer bufErrors *bytes.Buffer batchTimer *time.Timer @@ -88,6 +88,10 @@ type Logger struct { customPatterns map[string]string isSynthetic bool transactionSource transactionSource + browserAdmission bool + browserActiveVUs int64 + browserActivePeak int64 + browserWaitingVUs int64 } func New(params output.Params) (output.Output, error) { @@ -181,6 +185,7 @@ func New(params output.Params) (output.Output, error) { customPatterns: customPatterns, isSynthetic: isSynthetic, transactionSource: transactionSource, + browserAdmission: os.Getenv("K6_BROWSER_MAX_ACTIVE_CONTEXTS") != "", } l.batchTimer = time.NewTimer(time.Second) go l.batchLoop() @@ -541,6 +546,21 @@ func (l *Logger) AddMetricSamples(samples []metrics.SampleContainer) { for _, sc := range samples { for _, s := range sc.GetSamples() { ts := s.Time.UnixNano() + if s.Metric.Name == "browser_active_vus" { + l.mu.Lock() + l.browserActiveVUs = int64(s.Value) + if l.browserActiveVUs > l.browserActivePeak { + l.browserActivePeak = l.browserActiveVUs + } + l.mu.Unlock() + continue + } + if s.Metric.Name == "browser_waiting_vus" { + l.mu.Lock() + l.browserWaitingVUs = int64(s.Value) + l.mu.Unlock() + continue + } canonicalKey := httpMetricCanonicalKey(s.Metric.Name) if canonicalKey != "" { l.mu.Lock() @@ -682,16 +702,27 @@ func (l *Logger) AddMetricSamples(samples []metrics.SampleContainer) { } // vus -> virtual_users (active_threads) if s.Metric.Name == "vus" && !l.isSynthetic { + activeVUs := int64(s.Value) + l.mu.Lock() + if l.browserAdmission { + if l.browserActivePeak < activeVUs { + activeVUs = l.browserActivePeak + } + // Admission emits a release immediately before the same VU acquires + // its next context. Export the peak seen in this output interval so + // that handoff does not look like a VU disappeared. Seed the next + // interval with the current value so sustained drops remain visible. + l.browserActivePeak = l.browserActiveVUs + } row := []string{ time.Unix(0, ts).UTC().Format(time.RFC3339Nano), fmt.Sprintf("%v", l.envTags["run_id"]), fmt.Sprintf("%v", l.envTags["location"]), fmt.Sprintf("%v", l.envTags["node_name"]), - fmt.Sprintf("%d", int64(s.Value)), // active_threads - "", // started_threads (unknown) - "", // finished_threads (unknown) + fmt.Sprintf("%d", activeVUs), // active_threads + "", // started_threads (unknown) + "", // finished_threads (unknown) } - l.mu.Lock() wv := csv.NewWriter(l.bufVUs) _ = wv.Write(row) wv.Flush() @@ -733,20 +764,20 @@ func (l *Logger) AddMetricSamples(samples []metrics.SampleContainer) { fmt.Sprintf("%v", l.envTags["scenario_name"]), // scenario_name fmt.Sprintf("%v", l.envTags["location"]), // location fmt.Sprintf("%v", l.envTags["node_name"]), // node_name - m["scenario"], // thread_group_name - transactionName, // transaction_name - samplerName, // sampler_name - responseCode, // response_code - responseTime, // response_time - "", // connection_time - url, // url - "", // assertions - checkMsg, // response_message - requestData, // request_headers (used for request data) - "", // response_headers - responseData, // response_data - id, // id (UUIDv7 generated from measurement timestamp) - fmt.Sprintf("%v", l.envTags["run_id"]), // run_id last + m["scenario"], // thread_group_name + transactionName, // transaction_name + samplerName, // sampler_name + responseCode, // response_code + responseTime, // response_time + "", // connection_time + url, // url + "", // assertions + checkMsg, // response_message + requestData, // request_headers (used for request data) + "", // response_headers + responseData, // response_data + id, // id (UUIDv7 generated from measurement timestamp) + fmt.Sprintf("%v", l.envTags["run_id"]), // run_id last } l.mu.Lock() we := csv.NewWriter(l.bufErrors) @@ -1241,19 +1272,19 @@ func (l *Logger) processBrowserError(s metrics.Sample, ts int64) { fmt.Sprintf("%v", l.envTags["scenario_name"]), // scenario_name fmt.Sprintf("%v", l.envTags["location"]), // location fmt.Sprintf("%v", l.envTags["node_name"]), // node_name - m["scenario"], // thread_group_name - transactionName, // transaction_name - samplerName, // sampler_name - "", // response_code - "", // response_time - "", // connection_time - "", // url - "", // assertions - errMsg, // response_message - "", // request_headers - "", // response_headers - screenshotHash, // response_data (screenshot hash reference) - id, // id (UUIDv7) + m["scenario"], // thread_group_name + transactionName, // transaction_name + samplerName, // sampler_name + "", // response_code + "", // response_time + "", // connection_time + "", // url + "", // assertions + errMsg, // response_message + "", // request_headers + "", // response_headers + screenshotHash, // response_data (screenshot hash reference) + id, // id (UUIDv7) fmt.Sprintf("%v", l.envTags["run_id"]), // run_id last } l.mu.Lock() diff --git a/internal/output/breakingit/breakingit_test.go b/internal/output/breakingit/breakingit_test.go new file mode 100644 index 000000000..d9e570b52 --- /dev/null +++ b/internal/output/breakingit/breakingit_test.go @@ -0,0 +1,121 @@ +package breakingit + +import ( + "bytes" + "encoding/csv" + "strings" + "testing" + "time" + + "github.com/stretchr/testify/require" + "go.k6.io/k6/v2/metrics" +) + +func TestBrowserAdmissionStoresAdmittedVUs(t *testing.T) { + t.Parallel() + + registry := metrics.NewRegistry() + activeMetric := registry.MustNewMetric("browser_active_vus", metrics.Gauge) + waitingMetric := registry.MustNewMetric("browser_waiting_vus", metrics.Gauge) + vusMetric := registry.MustNewMetric("vus", metrics.Gauge) + tags := registry.RootTagSet() + now := time.Now() + logger := &Logger{ + bufVUs: &bytes.Buffer{}, + envTags: map[string]string{"run_id": "run", "location": "local", "node_name": "node"}, + browserAdmission: true, + } + + logger.AddMetricSamples([]metrics.SampleContainer{metrics.ConnectedSamples{ + Samples: []metrics.Sample{ + {TimeSeries: metrics.TimeSeries{Metric: activeMetric, Tags: tags}, Time: now, Value: 7}, + {TimeSeries: metrics.TimeSeries{Metric: waitingMetric, Tags: tags}, Time: now, Value: 13}, + {TimeSeries: metrics.TimeSeries{Metric: vusMetric, Tags: tags}, Time: now, Value: 20}, + }, + }}) + + row, err := csv.NewReader(strings.NewReader(logger.bufVUs.String())).Read() + require.NoError(t, err) + require.Equal(t, "7", row[4]) + require.EqualValues(t, 7, logger.browserActiveVUs) + require.EqualValues(t, 13, logger.browserWaitingVUs) +} + +func TestRegularRunStoresExecutorVUs(t *testing.T) { + t.Parallel() + + registry := metrics.NewRegistry() + vusMetric := registry.MustNewMetric("vus", metrics.Gauge) + now := time.Now() + logger := &Logger{ + bufVUs: &bytes.Buffer{}, + envTags: map[string]string{"run_id": "run", "location": "local", "node_name": "node"}, + } + + logger.AddMetricSamples([]metrics.SampleContainer{metrics.ConnectedSamples{ + Samples: []metrics.Sample{{ + TimeSeries: metrics.TimeSeries{Metric: vusMetric, Tags: registry.RootTagSet()}, + Time: now, + Value: 20, + }}, + }}) + + row, err := csv.NewReader(strings.NewReader(logger.bufVUs.String())).Read() + require.NoError(t, err) + require.Equal(t, "20", row[4]) +} + +func TestBrowserAdmissionDoesNotHideExecutorRampDown(t *testing.T) { + t.Parallel() + + registry := metrics.NewRegistry() + activeMetric := registry.MustNewMetric("browser_active_vus", metrics.Gauge) + vusMetric := registry.MustNewMetric("vus", metrics.Gauge) + now := time.Now() + logger := &Logger{ + bufVUs: &bytes.Buffer{}, + envTags: map[string]string{"run_id": "run", "location": "local", "node_name": "node"}, + browserAdmission: true, + } + tags := registry.RootTagSet() + + logger.AddMetricSamples([]metrics.SampleContainer{metrics.ConnectedSamples{ + Samples: []metrics.Sample{ + {TimeSeries: metrics.TimeSeries{Metric: activeMetric, Tags: tags}, Time: now, Value: 7}, + {TimeSeries: metrics.TimeSeries{Metric: vusMetric, Tags: tags}, Time: now, Value: 5}, + }, + }}) + + row, err := csv.NewReader(strings.NewReader(logger.bufVUs.String())).Read() + require.NoError(t, err) + require.Equal(t, "5", row[4]) +} + +func TestBrowserAdmissionIgnoresBriefContextHandoff(t *testing.T) { + t.Parallel() + + registry := metrics.NewRegistry() + activeMetric := registry.MustNewMetric("browser_active_vus", metrics.Gauge) + vusMetric := registry.MustNewMetric("vus", metrics.Gauge) + tags := registry.RootTagSet() + now := time.Now() + logger := &Logger{ + bufVUs: &bytes.Buffer{}, + envTags: map[string]string{"run_id": "run", "location": "local", "node_name": "node"}, + browserAdmission: true, + } + + logger.AddMetricSamples([]metrics.SampleContainer{metrics.ConnectedSamples{ + Samples: []metrics.Sample{ + {TimeSeries: metrics.TimeSeries{Metric: activeMetric, Tags: tags}, Time: now, Value: 7}, + {TimeSeries: metrics.TimeSeries{Metric: activeMetric, Tags: tags}, Time: now, Value: 6}, + {TimeSeries: metrics.TimeSeries{Metric: vusMetric, Tags: tags}, Time: now, Value: 20}, + {TimeSeries: metrics.TimeSeries{Metric: vusMetric, Tags: tags}, Time: now.Add(time.Second), Value: 20}, + }, + }}) + + rows, err := csv.NewReader(strings.NewReader(logger.bufVUs.String())).ReadAll() + require.NoError(t, err) + require.Equal(t, "7", rows[0][4], "the peak hides a release/reacquire handoff") + require.Equal(t, "6", rows[1][4], "a lower value lasting a full interval remains visible") +} From daf508046d3ab281205cd92715ee98b6cd970348 Mon Sep 17 00:00:00 2001 From: jgaalen Date: Tue, 29 Sep 2026 20:06:11 +0200 Subject: [PATCH 176/182] Document breakingit build branch and admission configuration --- FORK.md | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/FORK.md b/FORK.md index fab8e5cf4..38a5e8b85 100644 --- a/FORK.md +++ b/FORK.md @@ -38,14 +38,14 @@ code to the k6 executable. ## Development and builds in jgaalen/k6 -`master` is the consolidated development branch, based on upstream k6 v2.3.0. The `breakingit` branch -is kept aligned after integrations. Build from `master` to include the fork customizations, native -group transactions, and the browser group-context fix together. Feature branches can contain work -that has not yet been integrated; `codex/browser-admission-control` remains a separate feature. +`breakingit` is the custom build branch, based on upstream k6 v2.3.0. Build from `breakingit` to +include the fork customizations, native group transactions, browser group-context fix, and browser +admission control together. Upstream releases are integrated through `master` and then merged into +`breakingit`; push custom changes only to the jgaalen/k6 fork. ```sh -git switch master -git pull --ff-only origin master +git switch breakingit +git pull --ff-only origin breakingit ./build-linux-binaries.sh ``` @@ -53,5 +53,18 @@ The build script reads the source in the current checkout and writes Linux and m amd64 and arm64 into `dist/`. It does not install or deploy them. Its displayed `VERSION` value is informational; use the binary's `version` command and SHA-256 checksum to identify an artifact. +## Browser admission control + +Admission is opt-in. A new binary alone does not enable it. BreakTest must pass the computed +`K6_BROWSER_MAX_ACTIVE_CONTEXTS`, `K6_BROWSER_MIN_AVAILABLE_MEMORY_MB`, and +`K6_BROWSER_MIN_AVAILABLE_SHM_MB` settings to k6. The corresponding BreakTest sizing integration +from PR #401 must be present in its active code; it is not part of this repository. + +When enabled, managed browser iterations acquire a shared capacity lease, choose a healthy browser +endpoint, and release the lease at iteration end. Additional VUs wait when capacity or resource +headroom is unavailable. Endpoint cooldown defaults to 5 seconds and admission polling to 250 ms. +Resource probes measure the k6 host/container; they do not measure a separate remote browser host. +Requested executor VUs can exceed admitted browser VUs, so report achieved concurrency separately. + For the complete change history, compare the `breakingit` branch with the upstream [grafana/k6](https://github.com/grafana/k6) repository. From 1639fed365b7fe51d82a489925e07bb830f1127b Mon Sep 17 00:00:00 2001 From: jgaalen Date: Tue, 29 Sep 2026 21:41:13 +0200 Subject: [PATCH 177/182] Revert browser admission control while preserving async group fixes --- FORK.md | 19 +- .../modules/k6/browser/browser/admission.go | 399 ------------------ .../k6/browser/browser/admission_linux.go | 75 ---- .../k6/browser/browser/admission_other.go | 7 - .../k6/browser/browser/admission_test.go | 191 --------- .../js/modules/k6/browser/browser/module.go | 8 - .../js/modules/k6/browser/browser/registry.go | 60 +-- internal/js/modules/k6/browser/env/env.go | 20 - internal/output/breakingit/breakingit.go | 101 ++--- internal/output/breakingit/breakingit_test.go | 121 ------ 10 files changed, 49 insertions(+), 952 deletions(-) delete mode 100644 internal/js/modules/k6/browser/browser/admission.go delete mode 100644 internal/js/modules/k6/browser/browser/admission_linux.go delete mode 100644 internal/js/modules/k6/browser/browser/admission_other.go delete mode 100644 internal/js/modules/k6/browser/browser/admission_test.go delete mode 100644 internal/output/breakingit/breakingit_test.go diff --git a/FORK.md b/FORK.md index 38a5e8b85..785c2894e 100644 --- a/FORK.md +++ b/FORK.md @@ -39,9 +39,9 @@ code to the k6 executable. ## Development and builds in jgaalen/k6 `breakingit` is the custom build branch, based on upstream k6 v2.3.0. Build from `breakingit` to -include the fork customizations, native group transactions, browser group-context fix, and browser -admission control together. Upstream releases are integrated through `master` and then merged into -`breakingit`; push custom changes only to the jgaalen/k6 fork. +include the fork customizations, native group transactions and the browser group-context fix together. +Upstream releases are integrated through `master` and then merged into `breakingit`; push custom +changes only to the jgaalen/k6 fork. ```sh git switch breakingit @@ -53,18 +53,5 @@ The build script reads the source in the current checkout and writes Linux and m amd64 and arm64 into `dist/`. It does not install or deploy them. Its displayed `VERSION` value is informational; use the binary's `version` command and SHA-256 checksum to identify an artifact. -## Browser admission control - -Admission is opt-in. A new binary alone does not enable it. BreakTest must pass the computed -`K6_BROWSER_MAX_ACTIVE_CONTEXTS`, `K6_BROWSER_MIN_AVAILABLE_MEMORY_MB`, and -`K6_BROWSER_MIN_AVAILABLE_SHM_MB` settings to k6. The corresponding BreakTest sizing integration -from PR #401 must be present in its active code; it is not part of this repository. - -When enabled, managed browser iterations acquire a shared capacity lease, choose a healthy browser -endpoint, and release the lease at iteration end. Additional VUs wait when capacity or resource -headroom is unavailable. Endpoint cooldown defaults to 5 seconds and admission polling to 250 ms. -Resource probes measure the k6 host/container; they do not measure a separate remote browser host. -Requested executor VUs can exceed admitted browser VUs, so report achieved concurrency separately. - For the complete change history, compare the `breakingit` branch with the upstream [grafana/k6](https://github.com/grafana/k6) repository. diff --git a/internal/js/modules/k6/browser/browser/admission.go b/internal/js/modules/k6/browser/browser/admission.go deleted file mode 100644 index 9b8f44b90..000000000 --- a/internal/js/modules/k6/browser/browser/admission.go +++ /dev/null @@ -1,399 +0,0 @@ -package browser - -import ( - "context" - "fmt" - "strconv" - "sync" - "time" - - "go.k6.io/k6/v2/internal/js/modules/k6/browser/chromium" - "go.k6.io/k6/v2/internal/js/modules/k6/browser/common" - "go.k6.io/k6/v2/internal/js/modules/k6/browser/env" - - k6modules "go.k6.io/k6/v2/js/modules" - k6metrics "go.k6.io/k6/v2/metrics" -) - -const ( - defaultBrowserAdmissionPollInterval = 250 * time.Millisecond - defaultBrowserEndpointCooldown = 5 * time.Second - browserAdmissionBlockedLogInterval = 30 * time.Second -) - -type browserResourceSnapshot struct { - availableMemoryMB int64 - memoryKnown bool - availableShmMB int64 - shmKnown bool -} - -type browserResourceProbe func() browserResourceSnapshot - -type browserAdmissionMetrics struct { - active *k6metrics.Metric - waiting *k6metrics.Metric -} - -type browserAdmissionReporter func(active, waiting int) - -type browserAdmissionBlock struct { - reason string - active int - waiting int - maxActive int - minAvailableMemoryMB int - minAvailableShmMB int - resources browserResourceSnapshot -} - -type browserAdmissionBlockedReporter func(block browserAdmissionBlock) - -type remoteBrowserEndpoint struct { - wsURL string - active int - unhealthyUntil time.Time -} - -type browserLease struct { - registry *remoteRegistry - endpointIndex int - wsURL string - once sync.Once - onChange browserAdmissionReporter -} - -func (l *browserLease) release() { - if l == nil || l.registry == nil { - return - } - l.once.Do(func() { - active, waiting := l.registry.release(l.endpointIndex) - if l.onChange != nil { - l.onChange(active, waiting) - } - }) -} - -func (r *remoteRegistry) configureAdmission(envLookup env.LookupFunc) error { - var err error - r.maxActiveContexts, err = lookupNonNegativeInt(envLookup, env.BrowserMaxActiveContexts) - if err != nil { - return err - } - r.minAvailableMemoryMB, err = lookupNonNegativeInt(envLookup, env.BrowserMinAvailableMemoryMB) - if err != nil { - return err - } - r.minAvailableShmMB, err = lookupNonNegativeInt(envLookup, env.BrowserMinAvailableShmMB) - if err != nil { - return err - } - r.pollInterval, err = lookupPositiveDuration( - envLookup, env.BrowserAdmissionPollInterval, defaultBrowserAdmissionPollInterval, - ) - if err != nil { - return err - } - r.endpointCooldown, err = lookupPositiveDuration( - envLookup, env.BrowserEndpointCooldown, defaultBrowserEndpointCooldown, - ) - if err != nil { - return err - } - r.resourceProbe = probeBrowserResources - r.endpoints = make([]remoteBrowserEndpoint, 0, len(r.wsURLs)) - for _, wsURL := range r.wsURLs { - r.endpoints = append(r.endpoints, remoteBrowserEndpoint{wsURL: wsURL}) - } - return nil -} - -func lookupNonNegativeInt(envLookup env.LookupFunc, key string) (int, error) { - value, ok := envLookup(key) - if !ok || value == "" { - return 0, nil - } - parsed, err := strconv.Atoi(value) - if err != nil || parsed < 0 { - return 0, fmt.Errorf("%s must be a non-negative integer", key) - } - return parsed, nil -} - -func lookupPositiveDuration(envLookup env.LookupFunc, key string, fallback time.Duration) (time.Duration, error) { - value, ok := envLookup(key) - if !ok || value == "" { - return fallback, nil - } - parsed, err := time.ParseDuration(value) - if err != nil || parsed <= 0 { - return 0, fmt.Errorf("%s must be a positive duration", key) - } - return parsed, nil -} - -func (r *remoteRegistry) admissionEnabled() bool { - return r.maxActiveContexts > 0 || r.minAvailableMemoryMB > 0 || r.minAvailableShmMB > 0 -} - -func (r *remoteRegistry) endpointCount() int { - r.mu.Lock() - defer r.mu.Unlock() - return len(r.endpoints) -} - -func (r *remoteRegistry) acquire( - ctx context.Context, excluded map[int]struct{}, -) (*browserLease, error) { - return r.acquireWithReporter(ctx, excluded, nil) -} - -func (r *remoteRegistry) acquireWithReporter( - ctx context.Context, excluded map[int]struct{}, report browserAdmissionReporter, -) (*browserLease, error) { - return r.acquireWithTelemetry(ctx, excluded, report, nil) -} - -func (r *remoteRegistry) acquireWithTelemetry( - ctx context.Context, - excluded map[int]struct{}, - report browserAdmissionReporter, - reportBlocked browserAdmissionBlockedReporter, -) (*browserLease, error) { - r.mu.Lock() - r.waitingContexts++ - active, waiting := r.activeContexts, r.waitingContexts - r.mu.Unlock() - if report != nil { - report(active, waiting) - } - - for { - resources := r.resourceProbe() - now := time.Now() - r.mu.Lock() - blockedBy := r.blockReasonLocked(resources) - endpointIndex := -1 - if blockedBy == "" { - endpointIndex = r.selectEndpointLocked(now, excluded) - if r.isRemote && endpointIndex < 0 { - blockedBy = "endpoint" - } - } - if blockedBy == "" { - r.waitingContexts-- - r.activeContexts++ - wsURL := "" - if endpointIndex >= 0 { - r.endpoints[endpointIndex].active++ - wsURL = r.endpoints[endpointIndex].wsURL - } - active, waiting = r.activeContexts, r.waitingContexts - r.mu.Unlock() - if report != nil { - report(active, waiting) - } - return &browserLease{ - registry: r, - endpointIndex: endpointIndex, - wsURL: wsURL, - onChange: report, - }, nil - } - shouldReportBlocked := reportBlocked != nil && r.shouldReportBlockedLocked(blockedBy, now) - block := browserAdmissionBlock{ - reason: blockedBy, - active: r.activeContexts, - waiting: r.waitingContexts, - maxActive: r.maxActiveContexts, - minAvailableMemoryMB: r.minAvailableMemoryMB, - minAvailableShmMB: r.minAvailableShmMB, - resources: resources, - } - r.mu.Unlock() - if shouldReportBlocked { - reportBlocked(block) - } - - timer := time.NewTimer(r.pollInterval) - select { - case <-ctx.Done(): - if !timer.Stop() { - <-timer.C - } - r.mu.Lock() - if r.waitingContexts > 0 { - r.waitingContexts-- - } - active, waiting = r.activeContexts, r.waitingContexts - r.mu.Unlock() - if report != nil { - report(active, waiting) - } - return nil, ctx.Err() - case <-timer.C: - } - } -} - -func (r *remoteRegistry) blockReasonLocked(resources browserResourceSnapshot) string { - if r.maxActiveContexts > 0 && r.activeContexts >= r.maxActiveContexts { - return "capacity" - } - if r.minAvailableMemoryMB > 0 && resources.memoryKnown && - resources.availableMemoryMB < int64(r.minAvailableMemoryMB) { - return "memory" - } - if r.minAvailableShmMB > 0 && resources.shmKnown && - resources.availableShmMB < int64(r.minAvailableShmMB) { - return "shm" - } - return "" -} - -func (r *remoteRegistry) shouldReportBlockedLocked(reason string, now time.Time) bool { - if reason != r.lastBlockedReason || now.Sub(r.lastBlockedLog) >= browserAdmissionBlockedLogInterval { - r.lastBlockedReason = reason - r.lastBlockedLog = now - return true - } - return false -} - -func (r *remoteRegistry) selectEndpointLocked(now time.Time, excluded map[int]struct{}) int { - if !r.isRemote { - return -1 - } - best := -1 - for offset := range len(r.endpoints) { - index := (r.nextEndpoint + offset) % len(r.endpoints) - endpoint := &r.endpoints[index] - if _, skip := excluded[index]; skip || now.Before(endpoint.unhealthyUntil) { - continue - } - if best < 0 || endpoint.active < r.endpoints[best].active { - best = index - } - } - if best >= 0 { - r.nextEndpoint = (best + 1) % len(r.endpoints) - } - return best -} - -func (r *remoteRegistry) release(endpointIndex int) (active, waiting int) { - r.mu.Lock() - defer r.mu.Unlock() - if r.activeContexts > 0 { - r.activeContexts-- - } - if endpointIndex >= 0 && endpointIndex < len(r.endpoints) && r.endpoints[endpointIndex].active > 0 { - r.endpoints[endpointIndex].active-- - } - return r.activeContexts, r.waitingContexts -} - -func newBrowserAdmissionReporter( - vu k6modules.VU, admissionMetrics *browserAdmissionMetrics, -) browserAdmissionReporter { - if admissionMetrics == nil || admissionMetrics.active == nil || admissionMetrics.waiting == nil { - return nil - } - return func(active, waiting int) { - state := vu.State() - if state == nil { - return - } - now := time.Now() - tags := state.Tags.GetCurrentValues().Tags - k6metrics.PushIfNotDone(vu.Context(), state.Samples, k6metrics.ConnectedSamples{ - Samples: []k6metrics.Sample{ - { - TimeSeries: k6metrics.TimeSeries{Metric: admissionMetrics.active, Tags: tags}, - Time: now, - Value: float64(active), - }, - { - TimeSeries: k6metrics.TimeSeries{Metric: admissionMetrics.waiting, Tags: tags}, - Time: now, - Value: float64(waiting), - }, - }, - Tags: tags, - Time: now, - }) - } -} - -func newBrowserAdmissionBlockedReporter(vu k6modules.VU) browserAdmissionBlockedReporter { - return func(block browserAdmissionBlock) { - state := vu.State() - if state == nil { - return - } - state.Logger.Infof( - "browser admission blocked_by=%s active=%d waiting=%d max_active=%d "+ - "available_memory_mb=%d memory_known=%t min_memory_mb=%d "+ - "available_shm_mb=%d shm_known=%t min_shm_mb=%d", - block.reason, block.active, block.waiting, block.maxActive, - block.resources.availableMemoryMB, block.resources.memoryKnown, block.minAvailableMemoryMB, - block.resources.availableShmMB, block.resources.shmKnown, block.minAvailableShmMB, - ) - } -} - -func (r *remoteRegistry) markEndpointFailed(endpointIndex int) { - if endpointIndex < 0 { - return - } - r.mu.Lock() - defer r.mu.Unlock() - if endpointIndex < len(r.endpoints) { - r.endpoints[endpointIndex].unhealthyUntil = time.Now().Add(r.endpointCooldown) - } -} - -func buildAdmittedBrowser( - ctx, vuCtx context.Context, - vu k6modules.VU, - bt *chromium.BrowserType, - remote *remoteRegistry, - pids *pidRegistry, -) (*common.Browser, *browserLease, error) { - excluded := make(map[int]struct{}) - report := newBrowserAdmissionReporter(vu, remote.admissionMetrics) - reportBlocked := newBrowserAdmissionBlockedReporter(vu) - for { - lease, err := remote.acquireWithTelemetry(vuCtx, excluded, report, reportBlocked) - if err != nil { - return nil, nil, err - } - - if !remote.isRemote { - browser, pid, launchErr := bt.Launch(ctx, vuCtx) - if launchErr != nil { - lease.release() - return nil, nil, launchErr //nolint:wrapcheck - } - pids.registerPid(pid) - return browser, lease, nil - } - - browser, connectErr := bt.Connect(ctx, vuCtx, lease.wsURL) - if connectErr == nil { - return browser, lease, nil - } - - remote.markEndpointFailed(lease.endpointIndex) - lease.release() - excluded[lease.endpointIndex] = struct{}{} - vu.State().Logger.Warnf( - "remote browser endpoint %q failed; quarantining it for %s and trying another: %v", - lease.wsURL, remote.endpointCooldown, connectErr, - ) - if len(excluded) >= remote.endpointCount() { - clear(excluded) - } - } -} diff --git a/internal/js/modules/k6/browser/browser/admission_linux.go b/internal/js/modules/k6/browser/browser/admission_linux.go deleted file mode 100644 index 100f34216..000000000 --- a/internal/js/modules/k6/browser/browser/admission_linux.go +++ /dev/null @@ -1,75 +0,0 @@ -//go:build linux - -package browser - -import ( - "os" - "strconv" - "strings" - - "golang.org/x/sys/unix" -) - -const bytesPerMiB = 1024 * 1024 - -func probeBrowserResources() browserResourceSnapshot { - var snapshot browserResourceSnapshot - if data, err := os.ReadFile("/proc/meminfo"); err == nil { - for _, line := range strings.Split(string(data), "\n") { - fields := strings.Fields(line) - if len(fields) < 2 || fields[0] != "MemAvailable:" { - continue - } - if availableKB, err := strconv.ParseInt(fields[1], 10, 64); err == nil { - snapshot.availableMemoryMB = availableKB / 1024 - snapshot.memoryKnown = true - } - break - } - } - if cgroupAvailableMB, ok := cgroupAvailableMemoryMB(); ok && - (!snapshot.memoryKnown || cgroupAvailableMB < snapshot.availableMemoryMB) { - snapshot.availableMemoryMB = cgroupAvailableMB - snapshot.memoryKnown = true - } - - var stat unix.Statfs_t - if err := unix.Statfs("/dev/shm", &stat); err == nil { - snapshot.availableShmMB = int64(stat.Bavail) * int64(stat.Bsize) / bytesPerMiB - snapshot.shmKnown = true - } - return snapshot -} - -func cgroupAvailableMemoryMB() (int64, bool) { - for _, files := range [][2]string{ - {"/sys/fs/cgroup/memory.max", "/sys/fs/cgroup/memory.current"}, - {"/sys/fs/cgroup/memory/memory.limit_in_bytes", "/sys/fs/cgroup/memory/memory.usage_in_bytes"}, - } { - limitRaw, err := os.ReadFile(files[0]) - if err != nil { - continue - } - limitText := strings.TrimSpace(string(limitRaw)) - if limitText == "max" { - continue - } - limit, err := strconv.ParseInt(limitText, 10, 64) - if err != nil || limit <= 0 || limit >= 1<<60 { - continue - } - currentRaw, err := os.ReadFile(files[1]) - if err != nil { - continue - } - current, err := strconv.ParseInt(strings.TrimSpace(string(currentRaw)), 10, 64) - if err != nil || current < 0 { - continue - } - if current >= limit { - return 0, true - } - return (limit - current) / bytesPerMiB, true - } - return 0, false -} diff --git a/internal/js/modules/k6/browser/browser/admission_other.go b/internal/js/modules/k6/browser/browser/admission_other.go deleted file mode 100644 index 5da180400..000000000 --- a/internal/js/modules/k6/browser/browser/admission_other.go +++ /dev/null @@ -1,7 +0,0 @@ -//go:build !linux - -package browser - -func probeBrowserResources() browserResourceSnapshot { - return browserResourceSnapshot{} -} diff --git a/internal/js/modules/k6/browser/browser/admission_test.go b/internal/js/modules/k6/browser/browser/admission_test.go deleted file mode 100644 index f4a790755..000000000 --- a/internal/js/modules/k6/browser/browser/admission_test.go +++ /dev/null @@ -1,191 +0,0 @@ -package browser - -import ( - "context" - "errors" - "testing" - "time" - - "github.com/stretchr/testify/require" - - "go.k6.io/k6/v2/internal/js/modules/k6/browser/env" -) - -func admissionLookup(values map[string]string) env.LookupFunc { - return func(key string) (string, bool) { - value, ok := values[key] - return value, ok - } -} - -func TestBrowserAdmissionCapsActiveContexts(t *testing.T) { - t.Parallel() - - registry, err := newRemoteRegistry(admissionLookup(map[string]string{ - env.WebSocketURLs: "ws://browser-1,ws://browser-2", - env.BrowserMaxActiveContexts: "2", - env.BrowserAdmissionPollInterval: "5ms", - })) - require.NoError(t, err) - registry.resourceProbe = func() browserResourceSnapshot { return browserResourceSnapshot{} } - - first, err := registry.acquire(context.Background(), nil) - require.NoError(t, err) - second, err := registry.acquire(context.Background(), nil) - require.NoError(t, err) - - waitCtx, cancel := context.WithTimeout(context.Background(), 25*time.Millisecond) - defer cancel() - _, err = registry.acquire(waitCtx, nil) - require.ErrorIs(t, err, context.DeadlineExceeded) - - first.release() - third, err := registry.acquire(context.Background(), nil) - require.NoError(t, err) - second.release() - third.release() -} - -func TestBrowserAdmissionReportsActiveAndWaitingContexts(t *testing.T) { - t.Parallel() - - registry, err := newRemoteRegistry(admissionLookup(map[string]string{ - env.WebSocketURLs: "ws://browser-1", - env.BrowserMaxActiveContexts: "1", - env.BrowserAdmissionPollInterval: "5ms", - })) - require.NoError(t, err) - registry.resourceProbe = func() browserResourceSnapshot { return browserResourceSnapshot{} } - - type counts struct{ active, waiting int } - reports := make([]counts, 0, 6) - report := func(active, waiting int) { - reports = append(reports, counts{active: active, waiting: waiting}) - } - - lease, err := registry.acquireWithReporter(context.Background(), nil, report) - require.NoError(t, err) - require.Equal(t, counts{active: 1, waiting: 0}, reports[len(reports)-1]) - - waitCtx, cancel := context.WithTimeout(context.Background(), 25*time.Millisecond) - defer cancel() - _, err = registry.acquireWithReporter(waitCtx, nil, report) - require.ErrorIs(t, err, context.DeadlineExceeded) - require.Contains(t, reports, counts{active: 1, waiting: 1}) - require.Equal(t, counts{active: 1, waiting: 0}, reports[len(reports)-1]) - - lease.release() - require.Equal(t, counts{active: 0, waiting: 0}, reports[len(reports)-1]) -} - -func TestBrowserAdmissionReportsWhyAcquisitionIsBlocked(t *testing.T) { - t.Parallel() - - registry, err := newRemoteRegistry(admissionLookup(map[string]string{ - env.WebSocketURLs: "ws://browser-1", - env.BrowserMaxActiveContexts: "1", - env.BrowserAdmissionPollInterval: "5ms", - })) - require.NoError(t, err) - registry.resourceProbe = func() browserResourceSnapshot { return browserResourceSnapshot{} } - - lease, err := registry.acquire(context.Background(), nil) - require.NoError(t, err) - - blocked := make(chan browserAdmissionBlock, 1) - waitCtx, cancel := context.WithTimeout(context.Background(), 25*time.Millisecond) - defer cancel() - _, err = registry.acquireWithTelemetry(waitCtx, nil, nil, func(block browserAdmissionBlock) { - select { - case blocked <- block: - default: - } - }) - require.ErrorIs(t, err, context.DeadlineExceeded) - - reported := <-blocked - require.Equal(t, "capacity", reported.reason) - require.Equal(t, 1, reported.active) - require.Equal(t, 1, reported.waiting) - require.Equal(t, 1, reported.maxActive) - lease.release() -} - -func TestBrowserAdmissionBalancesAndQuarantinesEndpoints(t *testing.T) { - t.Parallel() - - registry, err := newRemoteRegistry(admissionLookup(map[string]string{ - env.WebSocketURLs: "ws://browser-1,ws://browser-2,ws://browser-3", - env.BrowserMaxActiveContexts: "10", - env.BrowserEndpointCooldown: "1h", - })) - require.NoError(t, err) - registry.resourceProbe = func() browserResourceSnapshot { return browserResourceSnapshot{} } - - first, err := registry.acquire(context.Background(), nil) - require.NoError(t, err) - second, err := registry.acquire(context.Background(), nil) - require.NoError(t, err) - third, err := registry.acquire(context.Background(), nil) - require.NoError(t, err) - require.ElementsMatch(t, - []string{"ws://browser-1", "ws://browser-2", "ws://browser-3"}, - []string{first.wsURL, second.wsURL, third.wsURL}, - ) - - registry.markEndpointFailed(first.endpointIndex) - first.release() - fourth, err := registry.acquire(context.Background(), nil) - require.NoError(t, err) - require.NotEqual(t, first.wsURL, fourth.wsURL) - - second.release() - third.release() - fourth.release() -} - -func TestBrowserAdmissionWaitsForResourceHeadroom(t *testing.T) { - t.Parallel() - - registry, err := newRemoteRegistry(admissionLookup(map[string]string{ - env.WebSocketURLs: "ws://browser-1", - env.BrowserMinAvailableMemoryMB: "2048", - env.BrowserMinAvailableShmMB: "768", - env.BrowserAdmissionPollInterval: "5ms", - })) - require.NoError(t, err) - registry.resourceProbe = func() browserResourceSnapshot { - return browserResourceSnapshot{ - availableMemoryMB: 2047, - memoryKnown: true, - availableShmMB: 767, - shmKnown: true, - } - } - - waitCtx, cancel := context.WithTimeout(context.Background(), 25*time.Millisecond) - defer cancel() - _, err = registry.acquire(waitCtx, nil) - require.True(t, errors.Is(err, context.DeadlineExceeded)) - - registry.resourceProbe = func() browserResourceSnapshot { - return browserResourceSnapshot{ - availableMemoryMB: 4096, - memoryKnown: true, - availableShmMB: 1024, - shmKnown: true, - } - } - lease, err := registry.acquire(context.Background(), nil) - require.NoError(t, err) - lease.release() -} - -func TestBrowserAdmissionRejectsInvalidConfiguration(t *testing.T) { - t.Parallel() - - _, err := newRemoteRegistry(admissionLookup(map[string]string{ - env.BrowserMaxActiveContexts: "not-a-number", - })) - require.EqualError(t, err, "K6_BROWSER_MAX_ACTIVE_CONTEXTS must be a non-negative integer") -} diff --git a/internal/js/modules/k6/browser/browser/module.go b/internal/js/modules/k6/browser/browser/module.go index 3a00bdf8e..74b1e04c4 100644 --- a/internal/js/modules/k6/browser/browser/module.go +++ b/internal/js/modules/k6/browser/browser/module.go @@ -39,8 +39,6 @@ type ( filePersister filePersister testRunID string browserErrors *k6metrics.Metric - browserActiveVUs *k6metrics.Metric - browserWaitingVUs *k6metrics.Metric screenshotOnError bool } @@ -139,12 +137,6 @@ func (m *RootModule) initialize(vu k6modules.VU) { m.testRunID = e } m.browserErrors = initEnv.Registry.MustNewMetric("browser_errors", k6metrics.Counter) - m.browserActiveVUs = initEnv.Registry.MustNewMetric("browser_active_vus", k6metrics.Gauge) - m.browserWaitingVUs = initEnv.Registry.MustNewMetric("browser_waiting_vus", k6metrics.Gauge) - m.remoteRegistry.admissionMetrics = &browserAdmissionMetrics{ - active: m.browserActiveVUs, - waiting: m.browserWaitingVUs, - } if v, ok := initEnv.LookupEnv(env.ScreenshotOnError); ok && v == "true" { m.screenshotOnError = true } diff --git a/internal/js/modules/k6/browser/browser/registry.go b/internal/js/modules/k6/browser/browser/registry.go index 3db4af6c4..1ddc54f2e 100644 --- a/internal/js/modules/k6/browser/browser/registry.go +++ b/internal/js/modules/k6/browser/browser/registry.go @@ -11,7 +11,6 @@ import ( "strconv" "strings" "sync" - "time" "go.opentelemetry.io/otel/attribute" oteltrace "go.opentelemetry.io/otel/trace" @@ -64,21 +63,6 @@ func (r *pidRegistry) Pids() []int { type remoteRegistry struct { isRemote bool wsURLs []string - - mu sync.Mutex - endpoints []remoteBrowserEndpoint - nextEndpoint int - activeContexts int - maxActiveContexts int - minAvailableMemoryMB int - minAvailableShmMB int - pollInterval time.Duration - endpointCooldown time.Duration - resourceProbe browserResourceProbe - waitingContexts int - admissionMetrics *browserAdmissionMetrics - lastBlockedReason string - lastBlockedLog time.Time } // newRemoteRegistry will create a new RemoteRegistry. This will @@ -97,13 +81,11 @@ func newRemoteRegistry(envLookup env.LookupFunc) (*remoteRegistry, error) { if isRemote { r.isRemote = isRemote r.wsURLs = wsURLs - } else { - r.isRemote, r.wsURLs = checkForBrowserWSURLs(envLookup) + return r, nil } - if err := r.configureAdmission(envLookup); err != nil { - return nil, err - } + r.isRemote, r.wsURLs = checkForBrowserWSURLs(envLookup) + return r, nil } @@ -197,8 +179,6 @@ type browserRegistry struct { mu sync.RWMutex m map[int64]*common.Browser - // leases tracks admission capacity held by each managed browser iteration. - leases map[int64]*browserLease // userManaged holds browsers created via chromium.connectOverCDP, keyed by // iteration. Unlike m (browsers k6 launches/connects from scenario options), // these are connected by the script at runtime. k6 still sweeps them on @@ -209,7 +189,7 @@ type browserRegistry struct { buildFn browserBuildFunc } -type browserBuildFunc func(ctx, vuCtx context.Context) (*common.Browser, *browserLease, error) +type browserBuildFunc func(ctx, vuCtx context.Context) (*common.Browser, error) // newBrowserRegistry should only take a background context, not a context from // k6 (i.e. vu). The reason for this is that we want to control the chromium @@ -228,10 +208,7 @@ func newBrowserRegistry( tracesMetadata map[string]string, ) *browserRegistry { bt := chromium.NewBrowserType(vu) - builder := func(ctx, vuCtx context.Context) (*common.Browser, *browserLease, error) { - if remote.admissionEnabled() { - return buildAdmittedBrowser(ctx, vuCtx, vu, bt, remote, pids) - } + builder := func(ctx, vuCtx context.Context) (*common.Browser, error) { var ( err error b *common.Browser @@ -241,25 +218,24 @@ func newBrowserRegistry( if isRemoteBrowser { b, err = bt.Connect(ctx, vuCtx, wsURL) if err != nil { - return nil, nil, err //nolint:wrapcheck + return nil, err //nolint:wrapcheck } } else { var pid int b, pid, err = bt.Launch(ctx, vuCtx) if err != nil { - return nil, nil, err //nolint:wrapcheck + return nil, err //nolint:wrapcheck } pids.registerPid(pid) } - return b, nil, nil + return b, nil } r := &browserRegistry{ vu: vu, tracesMetadata: tracesMetadata, m: make(map[int64]*common.Browser), - leases: make(map[int64]*browserLease), userManaged: make(map[int64][]*common.Browser), buildFn: builder, } @@ -345,19 +321,16 @@ func (r *browserRegistry) handleIterEvents( tracerCtx := common.WithTracer(r.vu.Context(), r.tr.tracer) tracedCtx := r.tr.startIterationTrace(tracerCtx, data) - b, lease, err := r.buildFn(ctx, tracedCtx) + b, err := r.buildFn(ctx, tracedCtx) if err != nil { e.Done() - if vuCtx.Err() != nil { - continue - } k6ext.Abortf(vuCtx, "error building browser on IterStart: %v", err) // Continue so we don't block the k6 event system producer. // Test will be aborted by k6, which will previously send the // 'Exit' event so browser resources cleanup can be guaranteed. continue } - r.setBrowser(data.Iteration, b, lease) + r.setBrowser(data.Iteration, b) case k6event.IterEnd: // Always sweep user-managed browsers and end any iteration trace, // even for non-browser iterations (connectOverCDP runs in @@ -405,14 +378,11 @@ func (r *browserRegistry) handleExitEvent(exitCh <-chan *k6event.Event, unsubscr r.stopTracesRegistry() } -func (r *browserRegistry) setBrowser(id int64, b *common.Browser, lease *browserLease) { +func (r *browserRegistry) setBrowser(id int64, b *common.Browser) { r.mu.Lock() defer r.mu.Unlock() r.m[id] = b - if lease != nil { - r.leases[id] = lease - } } func (r *browserRegistry) getBrowser(id int64) (*common.Browser, error) { @@ -434,10 +404,6 @@ func (r *browserRegistry) deleteBrowser(id int64) { b.Close() delete(r.m, id) } - if lease, ok := r.leases[id]; ok { - lease.release() - delete(r.leases, id) - } } // This is only used in a test. Avoids having to manipulate the mutex in the @@ -456,10 +422,6 @@ func (r *browserRegistry) clear() { for id, b := range r.m { b.Close() delete(r.m, id) - if lease, ok := r.leases[id]; ok { - lease.release() - delete(r.leases, id) - } } for iter, browsers := range r.userManaged { for _, b := range browsers { diff --git a/internal/js/modules/k6/browser/env/env.go b/internal/js/modules/k6/browser/env/env.go index 279e53457..5264b3e02 100644 --- a/internal/js/modules/k6/browser/env/env.go +++ b/internal/js/modules/k6/browser/env/env.go @@ -39,26 +39,6 @@ const ( // BrowserGlobalTimeout is an environment variable that can be used // to set the global timeout for the browser. BrowserGlobalTimeout = "K6_BROWSER_TIMEOUT" - - // BrowserMaxActiveContexts caps the number of managed browser contexts - // that may be active at once across all VUs. - BrowserMaxActiveContexts = "K6_BROWSER_MAX_ACTIVE_CONTEXTS" - - // BrowserMinAvailableMemoryMB pauses new managed browser contexts while - // system available memory is below this many MiB. - BrowserMinAvailableMemoryMB = "K6_BROWSER_MIN_AVAILABLE_MEMORY_MB" - - // BrowserMinAvailableShmMB pauses new managed browser contexts while - // /dev/shm available space is below this many MiB. - BrowserMinAvailableShmMB = "K6_BROWSER_MIN_AVAILABLE_SHM_MB" - - // BrowserAdmissionPollInterval controls how often a VU waiting for browser - // capacity rechecks resource headroom. - BrowserAdmissionPollInterval = "K6_BROWSER_ADMISSION_POLL_INTERVAL" - - // BrowserEndpointCooldown controls how long a failed remote browser - // endpoint is quarantined before it can be retried. - BrowserEndpointCooldown = "K6_BROWSER_ENDPOINT_COOLDOWN" ) // Logging and debugging. diff --git a/internal/output/breakingit/breakingit.go b/internal/output/breakingit/breakingit.go index 71bdab7a3..9dcc29d98 100644 --- a/internal/output/breakingit/breakingit.go +++ b/internal/output/breakingit/breakingit.go @@ -6,8 +6,8 @@ import ( "crypto/rand" "crypto/sha256" "crypto/tls" - "encoding/csv" "encoding/hex" + "encoding/csv" "encoding/json" "fmt" "io" @@ -69,9 +69,9 @@ type Logger struct { httpClient *http.Client // batch buffers - mu sync.Mutex - bufHTTP *bytes.Buffer - bufVUs *bytes.Buffer + mu sync.Mutex + bufHTTP *bytes.Buffer + bufVUs *bytes.Buffer bufTrans *bytes.Buffer bufErrors *bytes.Buffer batchTimer *time.Timer @@ -88,10 +88,6 @@ type Logger struct { customPatterns map[string]string isSynthetic bool transactionSource transactionSource - browserAdmission bool - browserActiveVUs int64 - browserActivePeak int64 - browserWaitingVUs int64 } func New(params output.Params) (output.Output, error) { @@ -185,7 +181,6 @@ func New(params output.Params) (output.Output, error) { customPatterns: customPatterns, isSynthetic: isSynthetic, transactionSource: transactionSource, - browserAdmission: os.Getenv("K6_BROWSER_MAX_ACTIVE_CONTEXTS") != "", } l.batchTimer = time.NewTimer(time.Second) go l.batchLoop() @@ -546,21 +541,6 @@ func (l *Logger) AddMetricSamples(samples []metrics.SampleContainer) { for _, sc := range samples { for _, s := range sc.GetSamples() { ts := s.Time.UnixNano() - if s.Metric.Name == "browser_active_vus" { - l.mu.Lock() - l.browserActiveVUs = int64(s.Value) - if l.browserActiveVUs > l.browserActivePeak { - l.browserActivePeak = l.browserActiveVUs - } - l.mu.Unlock() - continue - } - if s.Metric.Name == "browser_waiting_vus" { - l.mu.Lock() - l.browserWaitingVUs = int64(s.Value) - l.mu.Unlock() - continue - } canonicalKey := httpMetricCanonicalKey(s.Metric.Name) if canonicalKey != "" { l.mu.Lock() @@ -702,27 +682,16 @@ func (l *Logger) AddMetricSamples(samples []metrics.SampleContainer) { } // vus -> virtual_users (active_threads) if s.Metric.Name == "vus" && !l.isSynthetic { - activeVUs := int64(s.Value) - l.mu.Lock() - if l.browserAdmission { - if l.browserActivePeak < activeVUs { - activeVUs = l.browserActivePeak - } - // Admission emits a release immediately before the same VU acquires - // its next context. Export the peak seen in this output interval so - // that handoff does not look like a VU disappeared. Seed the next - // interval with the current value so sustained drops remain visible. - l.browserActivePeak = l.browserActiveVUs - } row := []string{ time.Unix(0, ts).UTC().Format(time.RFC3339Nano), fmt.Sprintf("%v", l.envTags["run_id"]), fmt.Sprintf("%v", l.envTags["location"]), fmt.Sprintf("%v", l.envTags["node_name"]), - fmt.Sprintf("%d", activeVUs), // active_threads - "", // started_threads (unknown) - "", // finished_threads (unknown) + fmt.Sprintf("%d", int64(s.Value)), // active_threads + "", // started_threads (unknown) + "", // finished_threads (unknown) } + l.mu.Lock() wv := csv.NewWriter(l.bufVUs) _ = wv.Write(row) wv.Flush() @@ -764,20 +733,20 @@ func (l *Logger) AddMetricSamples(samples []metrics.SampleContainer) { fmt.Sprintf("%v", l.envTags["scenario_name"]), // scenario_name fmt.Sprintf("%v", l.envTags["location"]), // location fmt.Sprintf("%v", l.envTags["node_name"]), // node_name - m["scenario"], // thread_group_name - transactionName, // transaction_name - samplerName, // sampler_name - responseCode, // response_code - responseTime, // response_time - "", // connection_time - url, // url - "", // assertions - checkMsg, // response_message - requestData, // request_headers (used for request data) - "", // response_headers - responseData, // response_data - id, // id (UUIDv7 generated from measurement timestamp) - fmt.Sprintf("%v", l.envTags["run_id"]), // run_id last + m["scenario"], // thread_group_name + transactionName, // transaction_name + samplerName, // sampler_name + responseCode, // response_code + responseTime, // response_time + "", // connection_time + url, // url + "", // assertions + checkMsg, // response_message + requestData, // request_headers (used for request data) + "", // response_headers + responseData, // response_data + id, // id (UUIDv7 generated from measurement timestamp) + fmt.Sprintf("%v", l.envTags["run_id"]), // run_id last } l.mu.Lock() we := csv.NewWriter(l.bufErrors) @@ -1272,19 +1241,19 @@ func (l *Logger) processBrowserError(s metrics.Sample, ts int64) { fmt.Sprintf("%v", l.envTags["scenario_name"]), // scenario_name fmt.Sprintf("%v", l.envTags["location"]), // location fmt.Sprintf("%v", l.envTags["node_name"]), // node_name - m["scenario"], // thread_group_name - transactionName, // transaction_name - samplerName, // sampler_name - "", // response_code - "", // response_time - "", // connection_time - "", // url - "", // assertions - errMsg, // response_message - "", // request_headers - "", // response_headers - screenshotHash, // response_data (screenshot hash reference) - id, // id (UUIDv7) + m["scenario"], // thread_group_name + transactionName, // transaction_name + samplerName, // sampler_name + "", // response_code + "", // response_time + "", // connection_time + "", // url + "", // assertions + errMsg, // response_message + "", // request_headers + "", // response_headers + screenshotHash, // response_data (screenshot hash reference) + id, // id (UUIDv7) fmt.Sprintf("%v", l.envTags["run_id"]), // run_id last } l.mu.Lock() diff --git a/internal/output/breakingit/breakingit_test.go b/internal/output/breakingit/breakingit_test.go deleted file mode 100644 index d9e570b52..000000000 --- a/internal/output/breakingit/breakingit_test.go +++ /dev/null @@ -1,121 +0,0 @@ -package breakingit - -import ( - "bytes" - "encoding/csv" - "strings" - "testing" - "time" - - "github.com/stretchr/testify/require" - "go.k6.io/k6/v2/metrics" -) - -func TestBrowserAdmissionStoresAdmittedVUs(t *testing.T) { - t.Parallel() - - registry := metrics.NewRegistry() - activeMetric := registry.MustNewMetric("browser_active_vus", metrics.Gauge) - waitingMetric := registry.MustNewMetric("browser_waiting_vus", metrics.Gauge) - vusMetric := registry.MustNewMetric("vus", metrics.Gauge) - tags := registry.RootTagSet() - now := time.Now() - logger := &Logger{ - bufVUs: &bytes.Buffer{}, - envTags: map[string]string{"run_id": "run", "location": "local", "node_name": "node"}, - browserAdmission: true, - } - - logger.AddMetricSamples([]metrics.SampleContainer{metrics.ConnectedSamples{ - Samples: []metrics.Sample{ - {TimeSeries: metrics.TimeSeries{Metric: activeMetric, Tags: tags}, Time: now, Value: 7}, - {TimeSeries: metrics.TimeSeries{Metric: waitingMetric, Tags: tags}, Time: now, Value: 13}, - {TimeSeries: metrics.TimeSeries{Metric: vusMetric, Tags: tags}, Time: now, Value: 20}, - }, - }}) - - row, err := csv.NewReader(strings.NewReader(logger.bufVUs.String())).Read() - require.NoError(t, err) - require.Equal(t, "7", row[4]) - require.EqualValues(t, 7, logger.browserActiveVUs) - require.EqualValues(t, 13, logger.browserWaitingVUs) -} - -func TestRegularRunStoresExecutorVUs(t *testing.T) { - t.Parallel() - - registry := metrics.NewRegistry() - vusMetric := registry.MustNewMetric("vus", metrics.Gauge) - now := time.Now() - logger := &Logger{ - bufVUs: &bytes.Buffer{}, - envTags: map[string]string{"run_id": "run", "location": "local", "node_name": "node"}, - } - - logger.AddMetricSamples([]metrics.SampleContainer{metrics.ConnectedSamples{ - Samples: []metrics.Sample{{ - TimeSeries: metrics.TimeSeries{Metric: vusMetric, Tags: registry.RootTagSet()}, - Time: now, - Value: 20, - }}, - }}) - - row, err := csv.NewReader(strings.NewReader(logger.bufVUs.String())).Read() - require.NoError(t, err) - require.Equal(t, "20", row[4]) -} - -func TestBrowserAdmissionDoesNotHideExecutorRampDown(t *testing.T) { - t.Parallel() - - registry := metrics.NewRegistry() - activeMetric := registry.MustNewMetric("browser_active_vus", metrics.Gauge) - vusMetric := registry.MustNewMetric("vus", metrics.Gauge) - now := time.Now() - logger := &Logger{ - bufVUs: &bytes.Buffer{}, - envTags: map[string]string{"run_id": "run", "location": "local", "node_name": "node"}, - browserAdmission: true, - } - tags := registry.RootTagSet() - - logger.AddMetricSamples([]metrics.SampleContainer{metrics.ConnectedSamples{ - Samples: []metrics.Sample{ - {TimeSeries: metrics.TimeSeries{Metric: activeMetric, Tags: tags}, Time: now, Value: 7}, - {TimeSeries: metrics.TimeSeries{Metric: vusMetric, Tags: tags}, Time: now, Value: 5}, - }, - }}) - - row, err := csv.NewReader(strings.NewReader(logger.bufVUs.String())).Read() - require.NoError(t, err) - require.Equal(t, "5", row[4]) -} - -func TestBrowserAdmissionIgnoresBriefContextHandoff(t *testing.T) { - t.Parallel() - - registry := metrics.NewRegistry() - activeMetric := registry.MustNewMetric("browser_active_vus", metrics.Gauge) - vusMetric := registry.MustNewMetric("vus", metrics.Gauge) - tags := registry.RootTagSet() - now := time.Now() - logger := &Logger{ - bufVUs: &bytes.Buffer{}, - envTags: map[string]string{"run_id": "run", "location": "local", "node_name": "node"}, - browserAdmission: true, - } - - logger.AddMetricSamples([]metrics.SampleContainer{metrics.ConnectedSamples{ - Samples: []metrics.Sample{ - {TimeSeries: metrics.TimeSeries{Metric: activeMetric, Tags: tags}, Time: now, Value: 7}, - {TimeSeries: metrics.TimeSeries{Metric: activeMetric, Tags: tags}, Time: now, Value: 6}, - {TimeSeries: metrics.TimeSeries{Metric: vusMetric, Tags: tags}, Time: now, Value: 20}, - {TimeSeries: metrics.TimeSeries{Metric: vusMetric, Tags: tags}, Time: now.Add(time.Second), Value: 20}, - }, - }}) - - rows, err := csv.NewReader(strings.NewReader(logger.bufVUs.String())).ReadAll() - require.NoError(t, err) - require.Equal(t, "7", rows[0][4], "the peak hides a release/reacquire handoff") - require.Equal(t, "6", rows[1][4], "a lower value lasting a full interval remains visible") -} From 9756bfeb76c1a4e3f2014efb913d716658781b72 Mon Sep 17 00:00:00 2001 From: jgaalen Date: Tue, 13 Oct 2026 14:04:01 +0200 Subject: [PATCH 178/182] Make master the canonical fork branch and guard upstream publishing --- .github/workflows/build.yml | 18 +++++++++--------- AGENTS.md | 10 ++++++---- FORK.md | 24 ++++++++++++++++-------- 3 files changed, 31 insertions(+), 21 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ac05e7eb9..aa0f86710 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -92,7 +92,7 @@ jobs: - name: Determine whether to sign the Windows artifacts id: determine_windows_signing env: - SIGN_FILES: ${{ github.ref_name == github.event.repository.default_branch || startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch' }} + SIGN_FILES: ${{ github.repository == 'grafana/k6' && (github.ref_name == github.event.repository.default_branch || startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch') }} run: | set -x # Show exactly what commands are executed if [[ "${SIGN_FILES}" == "true" ]]; then @@ -255,7 +255,7 @@ jobs: -v "$PWD/examples/browser:/tests:ro" \ $CHECK_IMAGE_TAG run -q "/tests/framelocator.js" - name: Login to GAR (Docker Hub mirror) - if: ${{ github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v') }} + if: ${{ github.repository == 'grafana/k6' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')) }} uses: grafana/shared-workflows/actions/login-to-gar@c7ad5f57693ac858c698d95783685a9cbfd91223 # login-to-gar/v1.0.1 with: registry: us-docker.pkg.dev @@ -268,9 +268,9 @@ jobs: registry: ghcr.io username: ${{ env.GITHUB_ACTOR }} password: ${{ env.GITHUB_TOKEN }} - if: ${{ github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v') }} + if: ${{ github.repository == 'grafana/k6' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')) }} - name: Publish k6:master images - if: ${{ github.ref == 'refs/heads/master' }} + if: ${{ github.repository == 'grafana/k6' && (github.ref == 'refs/heads/master') }} run: | echo "Publish $GHCR_IMAGE_ID:master* images" docker buildx build --push \ @@ -284,7 +284,7 @@ jobs: -t $DOCKER_IMAGE_ID:master-with-browser \ -t ghcr.io/$GHCR_IMAGE_ID:master-with-browser . - name: Publish tagged version images - if: ${{ startsWith(github.ref, 'refs/tags/v') }} + if: ${{ github.repository == 'grafana/k6' && (startsWith(github.ref, 'refs/tags/v')) }} run: | VERSION="${VERSION#v}" echo "Publish $GHCR_IMAGE_ID:$VERSION images" @@ -303,7 +303,7 @@ jobs: # and a bugfix released on an older line within the same major # (e.g. v1.4.2 after v1.5.0) does not regress :vN. - name: Publish floating major tag - if: ${{ needs.configure.outputs.is_latest_in_major == 'true' }} + if: ${{ github.repository == 'grafana/k6' && (needs.configure.outputs.is_latest_in_major == 'true') }} env: MAJOR: ${{ needs.configure.outputs.major }} run: | @@ -322,7 +322,7 @@ jobs: # releases on older majors (e.g. v1.x after v2.0.0 ships) and any # pre-release must not move :latest. - name: Publish :latest - if: ${{ needs.configure.outputs.is_latest_stable == 'true' }} + if: ${{ github.repository == 'grafana/k6' && (needs.configure.outputs.is_latest_stable == 'true') }} run: | echo "Publish $GHCR_IMAGE_ID:latest" docker buildx build --push \ @@ -544,7 +544,7 @@ jobs: publish-github: runs-on: ubuntu-latest needs: [configure, sign-binaries, sign-packages] - if: ${{ startsWith(github.ref, 'refs/tags/v') && github.event_name != 'workflow_dispatch' }} + if: ${{ github.repository == 'grafana/k6' && (startsWith(github.ref, 'refs/tags/v') && github.event_name != 'workflow_dispatch') }} env: VERSION: ${{ needs.configure.outputs.k6_version }} permissions: @@ -636,7 +636,7 @@ jobs: publish-packages: runs-on: ubuntu-latest needs: [configure, sign-binaries, sign-packages] - if: ${{ startsWith(github.ref, 'refs/tags/v') && github.event_name != 'workflow_dispatch' }} + if: ${{ github.repository == 'grafana/k6' && (startsWith(github.ref, 'refs/tags/v') && github.event_name != 'workflow_dispatch') }} env: VERSION: ${{ needs.configure.outputs.k6_version }} permissions: diff --git a/AGENTS.md b/AGENTS.md index b52e9f9ce..320d2a736 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -13,10 +13,12 @@ This repository is a personal fork of grafana/k6 with private modifications ``` If a push to upstream fails with `DISABLED`, that is intentional — do not "fix" the URL. -- To pull in a new upstream release: fetch upstream tags, fast-forward `master` - to the release tag, merge `master` into `breakingit`, and gate any new cloud - functionality behind `//go:build !lean` (see `internal/cmd/cloud_lean.go` for - the stub pattern). Release binaries are built with `-tags lean` +- `master` is the canonical fork development and build branch. The historical + `breakingit` work is consolidated there; do not use upstream as a replacement for it. +- To pull in a new stable upstream release: fetch upstream tags, create an integration + branch from `origin/master`, merge the release tag, and open a tested pull request + against jgaalen/k6 `master`. Gate any new cloud functionality behind `//go:build !lean` + (see `internal/cmd/cloud_lean.go` for the stub pattern). Release binaries are built with `-tags lean` (`./build-linux-binaries.sh`). ## Project Overview diff --git a/FORK.md b/FORK.md index 785c2894e..e0ce98e0c 100644 --- a/FORK.md +++ b/FORK.md @@ -11,7 +11,8 @@ license notices are retained. ## Source releases -The `breakingit` branch contains the current fork source. Immutable source-release tags are +The `master` branch contains the current fork source. The historical `breakingit` branch is +retained for reference. Immutable source-release tags are published for distributed builds. The initial public release is [`breakingit-v2.1.0-26`](https://github.com/Breaking-IT/k6/tree/breakingit-v2.1.0-26). @@ -35,17 +36,24 @@ code to the k6 executable. - Restores metric context correctly when native promise settlement re-enters the runtime, preventing browser group paths from accumulating across iterations. - Excludes upstream's Grafana-specific Renovate approval automation. +- Restricts inherited release publishing and Windows signing to the upstream repository. ## Development and builds in jgaalen/k6 -`breakingit` is the custom build branch, based on upstream k6 v2.3.0. Build from `breakingit` to -include the fork customizations, native group transactions and the browser group-context fix together. -Upstream releases are integrated through `master` and then merged into `breakingit`; push custom -changes only to the jgaalen/k6 fork. +`master` is the default development and build branch, based on upstream k6 v2.3.0. It includes +the consolidated `breakingit` customizations, native group transactions and browser group-context +fix. Browser admission control remains reverted. Create feature branches from `origin/master` +and merge tested pull requests into `master` in jgaalen/k6. + +Track stable upstream releases: fetch tags from `upstream`, create an integration branch from +`origin/master`, and merge the new release tag into that branch. Preserve the fork changes, +validate normal and lean builds, and open a pull request against jgaalen/k6 `master`. Do not +replace the fork branch with upstream history. The `upstream` remote is fetch-only; keep its +push URL set to `DISABLED` and push only to `origin` (jgaalen/k6). ```sh -git switch breakingit -git pull --ff-only origin breakingit +git switch master +git pull --ff-only origin master ./build-linux-binaries.sh ``` @@ -53,5 +61,5 @@ The build script reads the source in the current checkout and writes Linux and m amd64 and arm64 into `dist/`. It does not install or deploy them. Its displayed `VERSION` value is informational; use the binary's `version` command and SHA-256 checksum to identify an artifact. -For the complete change history, compare the `breakingit` branch with the upstream +For the complete change history, compare the `master` branch with the upstream [grafana/k6](https://github.com/grafana/k6) repository. From 9eddec8555a34736716378007790f9a1ee13c27e Mon Sep 17 00:00:00 2001 From: jgaalen Date: Tue, 13 Oct 2026 14:22:02 +0200 Subject: [PATCH 179/182] Fix fork lint findings and validate lean build capabilities --- FORK.md | 20 + internal/cmd/build_full_test.go | 5 + internal/cmd/build_lean_test.go | 5 + internal/cmd/config_consolidation_test.go | 3 + internal/cmd/launcher_test.go | 3 + internal/cmd/lean_behavior_test.go | 44 + internal/cmd/root_test.go | 3 + internal/cmd/run.go | 6 +- internal/cmd/tests/build_full_test.go | 5 + internal/cmd/tests/build_lean_test.go | 5 + internal/cmd/tests/build_requirements_test.go | 10 + .../tests/cmd_cloud_load_zone_list_test.go | 1 + internal/cmd/tests/cmd_cloud_login_test.go | 1 + .../cmd/tests/cmd_cloud_project_list_test.go | 1 + .../cmd/tests/cmd_cloud_run_features_test.go | 5 + .../cmd_cloud_run_push_credentials_test.go | 1 + internal/cmd/tests/cmd_cloud_run_test.go | 6 + internal/cmd/tests/cmd_cloud_test.go | 1 + .../cmd/tests/cmd_cloud_test_list_test.go | 1 + internal/cmd/tests/cmd_cloud_upload_test.go | 1 + internal/cmd/tests/cmd_once_test.go | 2 + internal/cmd/tests/cmd_run_test.go | 7 + internal/cmd/tests/cmd_scenarios_test.go | 1 + internal/cmd/tests/cmd_stats_test.go | 2 + internal/cmd/tests/tests_test.go | 1 + .../k6/browser/common/network_manager.go | 83 +- .../js/modules/k6/browser/k6ext/metrics.go | 58 +- internal/output/breakingit/README.md | 7 + internal/output/breakingit/batch_test.go | 70 + internal/output/breakingit/breakingit.go | 1372 ++++++++--------- internal/output/breakingit/config_test.go | 49 + internal/output/breakingit/http_rows_test.go | 65 + .../output/breakingit/transactions_test.go | 8 +- lib/netext/httpext/fork_error_data_test.go | 33 + lib/netext/httpext/transport.go | 73 +- 35 files changed, 1132 insertions(+), 826 deletions(-) create mode 100644 internal/cmd/build_full_test.go create mode 100644 internal/cmd/build_lean_test.go create mode 100644 internal/cmd/lean_behavior_test.go create mode 100644 internal/cmd/tests/build_full_test.go create mode 100644 internal/cmd/tests/build_lean_test.go create mode 100644 internal/cmd/tests/build_requirements_test.go create mode 100644 internal/output/breakingit/batch_test.go create mode 100644 internal/output/breakingit/config_test.go create mode 100644 internal/output/breakingit/http_rows_test.go create mode 100644 lib/netext/httpext/fork_error_data_test.go diff --git a/FORK.md b/FORK.md index e0ce98e0c..0b6b01551 100644 --- a/FORK.md +++ b/FORK.md @@ -63,3 +63,23 @@ informational; use the binary's `version` command and SHA-256 checksum to identi For the complete change history, compare the `master` branch with the upstream [grafana/k6](https://github.com/grafana/k6) repository. + +## Validation before merging + +Run lint and the full race-enabled suite with bounded concurrency. Browser tests launch real +Chromium processes; on a workstation, the upstream 210-second package timeout and default +parallelism can overload the browser suite. + +```sh +make lint +go test -race -p 2 -parallel 2 -timeout 15m ./... +go test -race -p 2 -parallel 2 -tags lean -timeout 210s \ + ./internal/cmd ./internal/cmd/tests ./internal/api ./internal/js \ + ./internal/features ./internal/output/breakingit +go build -o dist/k6 . +go build -tags lean -o dist/k6-lean . +``` + +Cloud, REST API, and excluded-output integration tests require the full build. Lean-specific +checks verify their stubs and output availability; shared runtime and fork regression tests +run in both configurations. diff --git a/internal/cmd/build_full_test.go b/internal/cmd/build_full_test.go new file mode 100644 index 000000000..0a5ef2297 --- /dev/null +++ b/internal/cmd/build_full_test.go @@ -0,0 +1,5 @@ +//go:build !lean + +package cmd + +const leanBuild = false diff --git a/internal/cmd/build_lean_test.go b/internal/cmd/build_lean_test.go new file mode 100644 index 000000000..3be456480 --- /dev/null +++ b/internal/cmd/build_lean_test.go @@ -0,0 +1,5 @@ +//go:build lean + +package cmd + +const leanBuild = true diff --git a/internal/cmd/config_consolidation_test.go b/internal/cmd/config_consolidation_test.go index 6ac0daf0d..852989bb1 100644 --- a/internal/cmd/config_consolidation_test.go +++ b/internal/cmd/config_consolidation_test.go @@ -567,6 +567,9 @@ func getConfigConsolidationTestCases() []configConsolidationTestCase { } func runTestCase(t *testing.T, testCase configConsolidationTestCase, subCmd string) { + if leanBuild && strings.HasPrefix(subCmd, "cloud") { + t.Skip("cloud configuration is excluded from lean builds") + } t.Logf("Test for `k6 %s` with opts=%#v and exp=%#v\n", subCmd, testCase.options, testCase.expected) ts := tests.NewGlobalTestState(t) diff --git a/internal/cmd/launcher_test.go b/internal/cmd/launcher_test.go index 847f1456f..c399127a4 100644 --- a/internal/cmd/launcher_test.go +++ b/internal/cmd/launcher_test.go @@ -444,6 +444,9 @@ func TestGetProviderConfig(t *testing.T) { } config := getProviderConfig(ts.GlobalState) + if leanBuild { + tc.expectConfig.BuildServiceAuth = "" + } assert.Equal(t, tc.expectConfig, config) }) diff --git a/internal/cmd/lean_behavior_test.go b/internal/cmd/lean_behavior_test.go new file mode 100644 index 000000000..94bbd22fd --- /dev/null +++ b/internal/cmd/lean_behavior_test.go @@ -0,0 +1,44 @@ +//go:build lean + +package cmd + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "go.k6.io/k6/v2/internal/cmd/tests" + "go.k6.io/k6/v2/output" +) + +func TestLeanUnavailableOutputs(t *testing.T) { + t.Parallel() + constructors, err := getAllOutputConstructors() + require.NoError(t, err) + for _, name := range []string{"cloud", "influxdb", "experimental-prometheus-rw", "opentelemetry", "web-dashboard"} { + t.Run(name, func(t *testing.T) { + t.Parallel() + constructor, ok := constructors[name] + require.True(t, ok) + out, err := constructor(output.Params{}) + require.ErrorContains(t, err, "not available in this lean build") + assert.Nil(t, out) + }) + } + for _, name := range []string{"json", "csv", "timescaledb-breakingit"} { + assert.Contains(t, constructors, name) + } +} + +func TestLeanCommandStubs(t *testing.T) { + t.Parallel() + ts := tests.NewGlobalTestState(t) + cloud := getCmdCloud(ts.GlobalState) + assert.Contains(t, cloud.Short, "not available in this lean build") + assert.Empty(t, cloud.Commands()) + stats := getCmdStats(ts.GlobalState) + assert.True(t, stats.Hidden) + require.ErrorContains(t, stats.RunE(stats, nil), "not available in this lean build") + assert.ErrorIs(t, getCmdCloudLogin(ts.GlobalState).RunE(nil, nil), errCloudNotAvailable) +} diff --git a/internal/cmd/root_test.go b/internal/cmd/root_test.go index 3b5650b2f..1a568f254 100644 --- a/internal/cmd/root_test.go +++ b/internal/cmd/root_test.go @@ -60,6 +60,9 @@ func TestRootCommandHelpDisplayCommands(t *testing.T) { ts.CmdArgs = []string{"k6", "help"} newRootCommand(ts.GlobalState).execute() + if leanBuild && tc.name == "should have cloud command" { + tc.wantStdoutContains = "cloud Cloud functionality is not available in this lean build" + } if tc.wantStdoutContains != "" { assert.Contains(t, ts.Stdout.String(), tc.wantStdoutContains) } diff --git a/internal/cmd/run.go b/internal/cmd/run.go index a806ace5e..5c9054ef6 100644 --- a/internal/cmd/run.go +++ b/internal/cmd/run.go @@ -232,10 +232,8 @@ func (c *cmdRun) run(cmd *cobra.Command, args []string) (err error) { } summaryMeta := summary.Meta{ - Script: string(test.source.Data), - IsCloud: slices.ContainsFunc(outputs, func(o output.Output) bool { - return isCloudOutput(o) - }), + Script: string(test.source.Data), + IsCloud: slices.ContainsFunc(outputs, isCloudOutput), } // Instantiates the summary output diff --git a/internal/cmd/tests/build_full_test.go b/internal/cmd/tests/build_full_test.go new file mode 100644 index 000000000..074499be2 --- /dev/null +++ b/internal/cmd/tests/build_full_test.go @@ -0,0 +1,5 @@ +//go:build !lean + +package tests + +const leanBuild = false diff --git a/internal/cmd/tests/build_lean_test.go b/internal/cmd/tests/build_lean_test.go new file mode 100644 index 000000000..e875dd263 --- /dev/null +++ b/internal/cmd/tests/build_lean_test.go @@ -0,0 +1,5 @@ +//go:build lean + +package tests + +const leanBuild = true diff --git a/internal/cmd/tests/build_requirements_test.go b/internal/cmd/tests/build_requirements_test.go new file mode 100644 index 000000000..22e3c770c --- /dev/null +++ b/internal/cmd/tests/build_requirements_test.go @@ -0,0 +1,10 @@ +package tests + +import "testing" + +func requireFullBuild(t testing.TB) { + t.Helper() + if leanBuild { + t.Skip("requires cloud, REST API, or an output excluded from the lean build") + } +} diff --git a/internal/cmd/tests/cmd_cloud_load_zone_list_test.go b/internal/cmd/tests/cmd_cloud_load_zone_list_test.go index 9374a2f70..25edcb479 100644 --- a/internal/cmd/tests/cmd_cloud_load_zone_list_test.go +++ b/internal/cmd/tests/cmd_cloud_load_zone_list_test.go @@ -14,6 +14,7 @@ import ( ) func TestCloudLoadZoneList(t *testing.T) { + requireFullBuild(t) t.Parallel() t.Run("lists load zones successfully", func(t *testing.T) { diff --git a/internal/cmd/tests/cmd_cloud_login_test.go b/internal/cmd/tests/cmd_cloud_login_test.go index bad98f35f..784696d00 100644 --- a/internal/cmd/tests/cmd_cloud_login_test.go +++ b/internal/cmd/tests/cmd_cloud_login_test.go @@ -22,6 +22,7 @@ const ( ) func TestCloudLoginWithArgs(t *testing.T) { + requireFullBuild(t) t.Parallel() testCases := []struct { diff --git a/internal/cmd/tests/cmd_cloud_project_list_test.go b/internal/cmd/tests/cmd_cloud_project_list_test.go index cdb16fa0b..49388fc82 100644 --- a/internal/cmd/tests/cmd_cloud_project_list_test.go +++ b/internal/cmd/tests/cmd_cloud_project_list_test.go @@ -14,6 +14,7 @@ import ( ) func TestCloudProjectList(t *testing.T) { + requireFullBuild(t) t.Parallel() t.Run("lists projects successfully", func(t *testing.T) { diff --git a/internal/cmd/tests/cmd_cloud_run_features_test.go b/internal/cmd/tests/cmd_cloud_run_features_test.go index fdf6df56a..95bc208c4 100644 --- a/internal/cmd/tests/cmd_cloud_run_features_test.go +++ b/internal/cmd/tests/cmd_cloud_run_features_test.go @@ -85,6 +85,7 @@ func uploadAndCaptureArchive( } func TestCloudRunPropagatesFeatureFlagsToWorker(t *testing.T) { + requireFullBuild(t) t.Parallel() archiveEnv, archive := uploadAndCaptureArchive(t, @@ -105,6 +106,7 @@ func TestCloudRunPropagatesFeatureFlagsToWorker(t *testing.T) { } func TestCloudRunClearsInheritedFeatureFlags(t *testing.T) { + requireFullBuild(t) t.Parallel() archiveEnv, _ := uploadAndCaptureArchive(t, @@ -115,6 +117,7 @@ func TestCloudRunClearsInheritedFeatureFlags(t *testing.T) { } func TestCloudRunPropagatesFeatureFlagFromEnv(t *testing.T) { + requireFullBuild(t) t.Parallel() // K6_FEATURES set in the process environment (not -e, not --features) must be @@ -128,6 +131,7 @@ func TestCloudRunPropagatesFeatureFlagFromEnv(t *testing.T) { } func TestCloudRunPropagatesFeatureFlagFromLegacyAliasEnv(t *testing.T) { + requireFullBuild(t) t.Parallel() // A legacy alias env var set in the process environment must resolve to its @@ -140,6 +144,7 @@ func TestCloudRunPropagatesFeatureFlagFromLegacyAliasEnv(t *testing.T) { } func TestCloudRunIgnoresFeatureFlagFromScriptOptions(t *testing.T) { + requireFullBuild(t) t.Parallel() // Features in the script's exported options are unsupported, so they must diff --git a/internal/cmd/tests/cmd_cloud_run_push_credentials_test.go b/internal/cmd/tests/cmd_cloud_run_push_credentials_test.go index 8ec84ca92..78c3de812 100644 --- a/internal/cmd/tests/cmd_cloud_run_push_credentials_test.go +++ b/internal/cmd/tests/cmd_cloud_run_push_credentials_test.go @@ -188,6 +188,7 @@ func setupSelfProvisionedRun( // (httptest, no network) and asserts which bearer token k6 pushes with, // using distinct sentinel tokens so the source is unambiguous. func TestCloudMetricsPushCredentials(t *testing.T) { + requireFullBuild(t) t.Parallel() // Self-provisioned: creds come from the provisioning response and must diff --git a/internal/cmd/tests/cmd_cloud_run_test.go b/internal/cmd/tests/cmd_cloud_run_test.go index a2b93ea8d..f1a52174f 100644 --- a/internal/cmd/tests/cmd_cloud_run_test.go +++ b/internal/cmd/tests/cmd_cloud_run_test.go @@ -27,6 +27,7 @@ import ( ) func TestK6CloudRun(t *testing.T) { + requireFullBuild(t) t.Parallel() runCloudTests(t, setupK6CloudRunCmd) } @@ -53,6 +54,7 @@ func setupK6CloudRunCmd(cliFlags []string) []string { // "projectID": 124 // } func TestCloudRunWithArchive(t *testing.T) { + requireFullBuild(t) t.Parallel() ts := NewGlobalTestState(t) @@ -120,6 +122,7 @@ func TestCloudRunWithArchive(t *testing.T) { } func TestCloudRunCommandIncompatibleFlags(t *testing.T) { + requireFullBuild(t) t.Parallel() testCases := []struct { @@ -179,6 +182,7 @@ func TestCloudRunCommandIncompatibleFlags(t *testing.T) { } func TestCloudRunLocalExecution(t *testing.T) { + requireFullBuild(t) t.Parallel() t.Run("should upload the test archive via presigned S3 URL as a default", func(t *testing.T) { @@ -488,6 +492,7 @@ export default function() { } func TestCloudRunLocalExecutionNoCloudSecrets(t *testing.T) { + requireFullBuild(t) t.Parallel() script := ` @@ -553,6 +558,7 @@ export default function() {};` } func TestCloudRunLocalExecutionCloudLogPusher(t *testing.T) { + requireFullBuild(t) t.Parallel() // The VU logs one line so the pusher has a deterministic entry to push; diff --git a/internal/cmd/tests/cmd_cloud_test.go b/internal/cmd/tests/cmd_cloud_test.go index f7f906d78..4f326c689 100644 --- a/internal/cmd/tests/cmd_cloud_test.go +++ b/internal/cmd/tests/cmd_cloud_test.go @@ -17,6 +17,7 @@ import ( ) func TestCloudNoArgsShowsHelp(t *testing.T) { + requireFullBuild(t) t.Parallel() ts := NewGlobalTestState(t) diff --git a/internal/cmd/tests/cmd_cloud_test_list_test.go b/internal/cmd/tests/cmd_cloud_test_list_test.go index 84e84b01f..7159cffba 100644 --- a/internal/cmd/tests/cmd_cloud_test_list_test.go +++ b/internal/cmd/tests/cmd_cloud_test_list_test.go @@ -17,6 +17,7 @@ import ( const projectIDForTests = 42 func TestCloudTestList(t *testing.T) { + requireFullBuild(t) t.Parallel() t.Run("lists tests successfully using --project-id", func(t *testing.T) { diff --git a/internal/cmd/tests/cmd_cloud_upload_test.go b/internal/cmd/tests/cmd_cloud_upload_test.go index 5289f16f3..038aca105 100644 --- a/internal/cmd/tests/cmd_cloud_upload_test.go +++ b/internal/cmd/tests/cmd_cloud_upload_test.go @@ -18,6 +18,7 @@ import ( ) func TestK6CloudUpload(t *testing.T) { + requireFullBuild(t) t.Parallel() t.Run("TestCloudUploadUserNotAuthenticated", func(t *testing.T) { diff --git a/internal/cmd/tests/cmd_once_test.go b/internal/cmd/tests/cmd_once_test.go index 90dfea3d8..418e7b335 100644 --- a/internal/cmd/tests/cmd_once_test.go +++ b/internal/cmd/tests/cmd_once_test.go @@ -88,6 +88,7 @@ func mustExtractSingleSharedIterScenario(t *testing.T, opts lib.Options) executo } func TestCloudRunOnceLocalExecution(t *testing.T) { + requireFullBuild(t) t.Parallel() ts := makeTestState(t, onceCloudScript, @@ -102,6 +103,7 @@ func TestCloudRunOnceLocalExecution(t *testing.T) { } func TestCloudRunOnceUploadsRewrittenArchive(t *testing.T) { + requireFullBuild(t) t.Parallel() _, tarData := uploadAndCaptureArchive(t, diff --git a/internal/cmd/tests/cmd_run_test.go b/internal/cmd/tests/cmd_run_test.go index bf07f5c6e..d3219d632 100644 --- a/internal/cmd/tests/cmd_run_test.go +++ b/internal/cmd/tests/cmd_run_test.go @@ -167,6 +167,9 @@ func TestBinaryNameHelpStdout(t *testing.T) { } for _, tt := range tests { + if leanBuild && tt.cmdName == "cloud" { + continue + } ts.CmdArgs = []string{ts.BinaryName, "help", tt.cmdName, tt.extraCmd} cmd.ExecuteWithGlobalState(ts.GlobalState) stdout := ts.Stdout.String() @@ -577,6 +580,7 @@ func getCloudTestEndChecker( tb testing.TB, testRunID int, testStart http.Handler, expRunStatus cloudapi.RunStatus, expResultStatus cloudapi.ResultStatus, ) *httptest.Server { + requireFullBuild(tb) testFinished := false if testStart == nil { @@ -1188,6 +1192,7 @@ func runTestWithLinger(t *testing.T, ts *GlobalTestState) { } func TestExecutionResultWithLinger(t *testing.T) { + requireFullBuild(t) t.Parallel() addr := getFreeBindAddr(t) @@ -2031,6 +2036,7 @@ export default function() {};` } func TestPrometheusRemoteWriteOutput(t *testing.T) { + requireFullBuild(t) t.Parallel() ts := NewGlobalTestState(t) @@ -2121,6 +2127,7 @@ func TestUIRenderOutput(t *testing.T) { } func TestUIRenderWebDashboard(t *testing.T) { + requireFullBuild(t) t.Parallel() tests := []struct { diff --git a/internal/cmd/tests/cmd_scenarios_test.go b/internal/cmd/tests/cmd_scenarios_test.go index cca1911e5..538168ad4 100644 --- a/internal/cmd/tests/cmd_scenarios_test.go +++ b/internal/cmd/tests/cmd_scenarios_test.go @@ -44,6 +44,7 @@ func TestScenariosFilterArchive(t *testing.T) { return buildArchive(t, scenariosScript, "--scenario", "ui,api") }, "cloud run": func(t *testing.T) []byte { + requireFullBuild(t) _, data := uploadAndCaptureArchive(t, []string{"k6", "cloud", "run", "--scenario", "ui,api", "test.js"}, nil, scenariosScript) return data diff --git a/internal/cmd/tests/cmd_stats_test.go b/internal/cmd/tests/cmd_stats_test.go index e881c1da0..317c8c61b 100644 --- a/internal/cmd/tests/cmd_stats_test.go +++ b/internal/cmd/tests/cmd_stats_test.go @@ -13,6 +13,7 @@ import ( ) func TestStatsCommandWithoutAddressFails(t *testing.T) { + requireFullBuild(t) t.Parallel() ts := NewGlobalTestState(t) @@ -27,6 +28,7 @@ func TestStatsCommandWithoutAddressFails(t *testing.T) { } func TestStatsCommand(t *testing.T) { + requireFullBuild(t) t.Parallel() srv := getTestServer(t, map[string]http.Handler{ diff --git a/internal/cmd/tests/tests_test.go b/internal/cmd/tests/tests_test.go index 4f3483494..dc6957c05 100644 --- a/internal/cmd/tests/tests_test.go +++ b/internal/cmd/tests/tests_test.go @@ -35,6 +35,7 @@ func TestRootCommand(t *testing.T) { } func TestCloudLoginNotPanicking(t *testing.T) { + requireFullBuild(t) t.Parallel() ts := NewGlobalTestState(t) diff --git a/internal/js/modules/k6/browser/common/network_manager.go b/internal/js/modules/k6/browser/common/network_manager.go index 5b10c9314..7dbc58ac3 100644 --- a/internal/js/modules/k6/browser/common/network_manager.go +++ b/internal/js/modules/k6/browser/common/network_manager.go @@ -432,7 +432,7 @@ func (m *NetworkManager) emitResponseMetrics(resp *Response, req *Request) { //n reqHeaders, reqBody := req.formatErrorRequestData() sample.HTTPErrorReqHeaders = reqHeaders sample.HTTPErrorReqBody = reqBody - // Fetch response body so error reporting includes it (formatErrorResponseData only uses already-loaded body otherwise). + // Fetch the response body for error reporting; formatting only uses an already-loaded body. _ = resp.fetchBody() resHeaders, resBody := resp.formatErrorResponseData() sample.HTTPErrorResHeaders = resHeaders @@ -586,68 +586,25 @@ func (m *NetworkManager) emitRequestFailedMetrics(req *Request) { durationMs := k6metrics.D(wallTime.Sub(req.wallTime)) reqHeaders, reqBody := req.formatErrorRequestData() - k6metrics.PushIfNotDone(m.vu.Context(), state.Samples, k6metrics.ConnectedSamples{ - Samples: []k6metrics.Sample{ - { - TimeSeries: k6metrics.TimeSeries{Metric: m.customMetrics.BrowserHTTPReqDuration, Tags: tags}, - Value: durationMs, - Time: wallTime, - Metadata: tagsAndMeta.Metadata, - }, - { - TimeSeries: k6metrics.TimeSeries{Metric: m.customMetrics.BrowserHTTPReqBlocked, Tags: tags}, - Value: 0, - Time: wallTime, - Metadata: tagsAndMeta.Metadata, - }, - { - TimeSeries: k6metrics.TimeSeries{Metric: m.customMetrics.BrowserHTTPReqConnecting, Tags: tags}, - Value: 0, - Time: wallTime, - Metadata: tagsAndMeta.Metadata, - }, - { - TimeSeries: k6metrics.TimeSeries{Metric: m.customMetrics.BrowserHTTPReqTLSHandshaking, Tags: tags}, - Value: 0, - Time: wallTime, - Metadata: tagsAndMeta.Metadata, - }, - { - TimeSeries: k6metrics.TimeSeries{Metric: m.customMetrics.BrowserHTTPReqSending, Tags: tags}, - Value: 0, - Time: wallTime, - Metadata: tagsAndMeta.Metadata, - }, - { - TimeSeries: k6metrics.TimeSeries{Metric: m.customMetrics.BrowserHTTPReqWaiting, Tags: tags}, - Value: 0, - Time: wallTime, - Metadata: tagsAndMeta.Metadata, - }, - { - TimeSeries: k6metrics.TimeSeries{Metric: m.customMetrics.BrowserHTTPReqReceiving, Tags: tags}, - Value: 0, - Time: wallTime, - Metadata: tagsAndMeta.Metadata, - }, - { - TimeSeries: k6metrics.TimeSeries{Metric: m.customMetrics.BrowserDataReceived, Tags: tags}, - Value: 0, - Time: wallTime, - Metadata: tagsAndMeta.Metadata, - }, - { - TimeSeries: k6metrics.TimeSeries{Metric: m.customMetrics.BrowserHTTPReqFailed, Tags: tags}, - Value: 1, - Time: wallTime, - Metadata: tagsAndMeta.Metadata, - HTTPErrorReqHeaders: reqHeaders, - HTTPErrorReqBody: reqBody, - HTTPErrorResHeaders: "", - HTTPErrorResBody: "", - }, - }, - }) + samples := make([]k6metrics.Sample, 0, 9) + for _, metric := range []*k6metrics.Metric{ + m.customMetrics.BrowserHTTPReqDuration, m.customMetrics.BrowserHTTPReqBlocked, + m.customMetrics.BrowserHTTPReqConnecting, m.customMetrics.BrowserHTTPReqTLSHandshaking, + m.customMetrics.BrowserHTTPReqSending, m.customMetrics.BrowserHTTPReqWaiting, + m.customMetrics.BrowserHTTPReqReceiving, m.customMetrics.BrowserDataReceived, + m.customMetrics.BrowserHTTPReqFailed, + } { + samples = append(samples, k6metrics.Sample{ + TimeSeries: k6metrics.TimeSeries{Metric: metric, Tags: tags}, + Time: wallTime, Metadata: tagsAndMeta.Metadata, + }) + } + samples[0].Value = durationMs + failed := &samples[len(samples)-1] + failed.Value = 1 + failed.HTTPErrorReqHeaders = reqHeaders + failed.HTTPErrorReqBody = reqBody + k6metrics.PushIfNotDone(m.vu.Context(), state.Samples, k6metrics.ConnectedSamples{Samples: samples}) } // handleURLTag will check if the url tag needs to be grouped by testing diff --git a/internal/js/modules/k6/browser/k6ext/metrics.go b/internal/js/modules/k6/browser/k6ext/metrics.go index 84963d543..40bb2a6ce 100644 --- a/internal/js/modules/k6/browser/k6ext/metrics.go +++ b/internal/js/modules/k6/browser/k6ext/metrics.go @@ -17,32 +17,32 @@ const ( inpName = "browser_web_vital_inp" fcpName = "browser_web_vital_fcp" - browserDataSentName = "browser_data_sent" - browserDataReceivedName = "browser_data_received" - browserHTTPReqDurationName = "browser_http_req_duration" - browserHTTPReqBlockedName = "browser_http_req_blocked" - browserHTTPReqConnectingName = "browser_http_req_connecting" - browserHTTPReqTLSHandshaking = "browser_http_req_tls_handshaking" - browserHTTPReqSendingName = "browser_http_req_sending" - browserHTTPReqWaitingName = "browser_http_req_waiting" - browserHTTPReqReceivingName = "browser_http_req_receiving" - browserHTTPReqFailedName = "browser_http_req_failed" + browserDataSentName = "browser_data_sent" + browserDataReceivedName = "browser_data_received" + browserHTTPReqDurationName = "browser_http_req_duration" + browserHTTPReqBlockedName = "browser_http_req_blocked" + browserHTTPReqConnectingName = "browser_http_req_connecting" + browserHTTPReqTLSHandshaking = "browser_http_req_tls_handshaking" + browserHTTPReqSendingName = "browser_http_req_sending" + browserHTTPReqWaitingName = "browser_http_req_waiting" + browserHTTPReqReceivingName = "browser_http_req_receiving" + browserHTTPReqFailedName = "browser_http_req_failed" ) // CustomMetrics are the custom k6 metrics used by xk6-browser. type CustomMetrics struct { WebVitals map[string]*k6metrics.Metric - BrowserDataSent *k6metrics.Metric - BrowserDataReceived *k6metrics.Metric - BrowserHTTPReqDuration *k6metrics.Metric - BrowserHTTPReqBlocked *k6metrics.Metric - BrowserHTTPReqConnecting *k6metrics.Metric + BrowserDataSent *k6metrics.Metric + BrowserDataReceived *k6metrics.Metric + BrowserHTTPReqDuration *k6metrics.Metric + BrowserHTTPReqBlocked *k6metrics.Metric + BrowserHTTPReqConnecting *k6metrics.Metric BrowserHTTPReqTLSHandshaking *k6metrics.Metric - BrowserHTTPReqSending *k6metrics.Metric - BrowserHTTPReqWaiting *k6metrics.Metric - BrowserHTTPReqReceiving *k6metrics.Metric - BrowserHTTPReqFailed *k6metrics.Metric + BrowserHTTPReqSending *k6metrics.Metric + BrowserHTTPReqWaiting *k6metrics.Metric + BrowserHTTPReqReceiving *k6metrics.Metric + BrowserHTTPReqFailed *k6metrics.Metric } // RegisterCustomMetrics creates and registers our custom metrics with the k6 @@ -69,16 +69,16 @@ func RegisterCustomMetrics(registry *k6metrics.Registry) *CustomMetrics { } return &CustomMetrics{ - WebVitals: webVitals, - BrowserDataSent: registry.MustNewMetric(browserDataSentName, k6metrics.Counter, k6metrics.Data), - BrowserDataReceived: registry.MustNewMetric(browserDataReceivedName, k6metrics.Counter, k6metrics.Data), - BrowserHTTPReqDuration: registry.MustNewMetric(browserHTTPReqDurationName, k6metrics.Trend, k6metrics.Time), - BrowserHTTPReqBlocked: registry.MustNewMetric(browserHTTPReqBlockedName, k6metrics.Trend, k6metrics.Time), - BrowserHTTPReqConnecting: registry.MustNewMetric(browserHTTPReqConnectingName, k6metrics.Trend, k6metrics.Time), + WebVitals: webVitals, + BrowserDataSent: registry.MustNewMetric(browserDataSentName, k6metrics.Counter, k6metrics.Data), + BrowserDataReceived: registry.MustNewMetric(browserDataReceivedName, k6metrics.Counter, k6metrics.Data), + BrowserHTTPReqDuration: registry.MustNewMetric(browserHTTPReqDurationName, k6metrics.Trend, k6metrics.Time), + BrowserHTTPReqBlocked: registry.MustNewMetric(browserHTTPReqBlockedName, k6metrics.Trend, k6metrics.Time), + BrowserHTTPReqConnecting: registry.MustNewMetric(browserHTTPReqConnectingName, k6metrics.Trend, k6metrics.Time), BrowserHTTPReqTLSHandshaking: registry.MustNewMetric(browserHTTPReqTLSHandshaking, k6metrics.Trend, k6metrics.Time), - BrowserHTTPReqSending: registry.MustNewMetric(browserHTTPReqSendingName, k6metrics.Trend, k6metrics.Time), - BrowserHTTPReqWaiting: registry.MustNewMetric(browserHTTPReqWaitingName, k6metrics.Trend, k6metrics.Time), - BrowserHTTPReqReceiving: registry.MustNewMetric(browserHTTPReqReceivingName, k6metrics.Trend, k6metrics.Time), - BrowserHTTPReqFailed: registry.MustNewMetric(browserHTTPReqFailedName, k6metrics.Rate), + BrowserHTTPReqSending: registry.MustNewMetric(browserHTTPReqSendingName, k6metrics.Trend, k6metrics.Time), + BrowserHTTPReqWaiting: registry.MustNewMetric(browserHTTPReqWaitingName, k6metrics.Trend, k6metrics.Time), + BrowserHTTPReqReceiving: registry.MustNewMetric(browserHTTPReqReceivingName, k6metrics.Trend, k6metrics.Time), + BrowserHTTPReqFailed: registry.MustNewMetric(browserHTTPReqFailedName, k6metrics.Rate), } } diff --git a/internal/output/breakingit/README.md b/internal/output/breakingit/README.md index c30219386..4e7ef0e44 100644 --- a/internal/output/breakingit/README.md +++ b/internal/output/breakingit/README.md @@ -106,3 +106,10 @@ an intentional nested transaction from two measurements of the same step. For a full migration, remove `pages.add()` and use `await group(...)` for timing and context, while keeping any business checks and throwing on failures. + +### Proxy TLS configuration + +`PG_PROXY_INSECURE_SKIP_TLS_VERIFY=false` enables certificate verification for the +PG-proxy connection. The default remains `true` for compatibility with existing +private proxy deployments. This setting applies only to output delivery, not to +HTTP requests generated by the test script. diff --git a/internal/output/breakingit/batch_test.go b/internal/output/breakingit/batch_test.go new file mode 100644 index 000000000..198f9b042 --- /dev/null +++ b/internal/output/breakingit/batch_test.go @@ -0,0 +1,70 @@ +package breakingit + +import ( + "compress/gzip" + "io" + "mime" + "mime/multipart" + "net/http" + "net/http/httptest" + "testing" + "time" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestBatchRetryPreservesConcurrentSamples(t *testing.T) { + t.Parallel() + logger := newTransactionTestLogger(false) + logger.bufTrans.WriteString("original\n") + requests := make(chan string, 3) + attempts := 0 + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + gz, err := gzip.NewReader(r.Body) + if !assert.NoError(t, err) { + w.WriteHeader(http.StatusBadRequest) + return + } + defer func() { assert.NoError(t, gz.Close()) }() + _, params, err := mime.ParseMediaType(r.Header.Get("Content-Type")) + if !assert.NoError(t, err) { + w.WriteHeader(http.StatusBadRequest) + return + } + part, err := multipart.NewReader(gz, params["boundary"]).NextPart() + if !assert.NoError(t, err) { + w.WriteHeader(http.StatusBadRequest) + return + } + assert.Equal(t, "public.transactions", part.Header.Get("X-Table")) + data, err := io.ReadAll(part) + assert.NoError(t, err) + requests <- string(data) + attempts++ + if attempts == 1 { + logger.mu.Lock() + logger.bufTrans.WriteString("arrived during retry\n") + logger.mu.Unlock() + w.WriteHeader(http.StatusServiceUnavailable) + return + } + w.WriteHeader(http.StatusOK) + })) + defer server.Close() + logger.proxyURL, logger.httpClient = server.URL, server.Client() + logger.flush() + for _, want := range []string{"original\n", "original\n", "arrived during retry\n"} { + select { + case got := <-requests: + assert.Equal(t, want, got) + case <-time.After(5 * time.Second): + t.Fatal("missing batch") + } + } + require.Eventually(t, func() bool { + logger.mu.Lock() + defer logger.mu.Unlock() + return !logger.flushing && logger.bufTrans.Len() == 0 + }, 5*time.Second, 10*time.Millisecond) +} diff --git a/internal/output/breakingit/breakingit.go b/internal/output/breakingit/breakingit.go index 9dcc29d98..013243621 100644 --- a/internal/output/breakingit/breakingit.go +++ b/internal/output/breakingit/breakingit.go @@ -1,21 +1,23 @@ +// Package breakingit exports k6 metrics to the Breaking-IT pg-proxy. package breakingit import ( "bytes" "compress/gzip" + "context" "crypto/rand" "crypto/sha256" "crypto/tls" - "encoding/hex" "encoding/csv" + "encoding/hex" "encoding/json" "fmt" "io" + "maps" "mime/multipart" "net/http" "net/textproto" "net/url" - "os" "regexp" "strconv" "strings" @@ -41,16 +43,15 @@ type MetricGroup struct { ErrorResBody string } -// excludedTags to reduce cardinality -var excludedTags = map[string]bool{ - "proto": true, - "tls_version": true, - "url": true, - "scenario": true, - "expected_response": true, - "from_cache": true, - "from_prefetch_cache": true, - "from_service_worker": true, +// excludedTag identifies tags omitted from database rows to reduce cardinality. +func excludedTag(tag string) bool { + switch tag { + case "proto", "tls_version", "url", "scenario", "expected_response", + "from_cache", "from_prefetch_cache", "from_service_worker": + return true + default: + return false + } } // Retry configuration constants @@ -69,19 +70,19 @@ type Logger struct { httpClient *http.Client // batch buffers - mu sync.Mutex - bufHTTP *bytes.Buffer - bufVUs *bytes.Buffer + mu sync.Mutex + bufHTTP *bytes.Buffer + bufVUs *bytes.Buffer bufTrans *bytes.Buffer bufErrors *bytes.Buffer batchTimer *time.Timer flushing bool // flag to prevent recursive flush calls // pending screenshots to upsert via /upsert endpoint (low-volume) - pendingScreenshots [][]interface{} + pendingScreenshots [][]any // merging state - pendingHttpGroups map[int64]*MetricGroup // http and browser (unified) + pendingHTTPGroups map[int64]*MetricGroup // http and browser (unified) cleanupStop chan struct{} batchDone chan struct{} // closed when batchLoop exits envTags map[string]string @@ -90,6 +91,7 @@ type Logger struct { transactionSource transactionSource } +// New constructs a pg-proxy output from the configured environment. func New(params output.Params) (output.Output, error) { // Expect params.ConfigArgument to be pg-proxy base url, e.g. https://proxy/ingest base := params.ConfigArgument @@ -98,14 +100,14 @@ func New(params output.Params) (output.Output, error) { } u, err := url.Parse(base) if err != nil { - return nil, fmt.Errorf("invalid pg-proxy URL: %v", err) + return nil, fmt.Errorf("invalid pg-proxy URL: %w", err) } // Allow env overrides - db := os.Getenv("PG_PROXY_DB") + db := params.Environment["PG_PROXY_DB"] if db == "" { db = "breakingit" } - token := os.Getenv("PG_PROXY_TOKEN") + token := params.Environment["PG_PROXY_TOKEN"] if token == "" { return nil, fmt.Errorf("PG_PROXY_TOKEN is required for Authorization") } @@ -114,26 +116,28 @@ func New(params output.Params) (output.Output, error) { return nil, err } - // HTTP client with keep-alive and TLS skip per proxy config - tr := &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}} + // Preserve the private-proxy TLS default; callers can require certificate verification. + insecure := true + if value := params.Environment["PG_PROXY_INSECURE_SKIP_TLS_VERIFY"]; value != "" { + insecure, err = strconv.ParseBool(value) + if err != nil { + return nil, fmt.Errorf("invalid PG_PROXY_INSECURE_SKIP_TLS_VERIFY: %w", err) + } + } + tr := &http.Transport{TLSClientConfig: &tls.Config{ + InsecureSkipVerify: insecure, //nolint:gosec // Explicit private-proxy configuration, independent of test traffic. + }} client := &http.Client{Transport: tr, Timeout: 30 * time.Second} // Environment tags from generator envTags := make(map[string]string) - isSynthetic := strings.ToLower(os.Getenv("syntheticMonitoring")) == "true" - if isSynthetic { - for _, k := range []string{"nodeName", "location", "scenarioName", "runId"} { - if v := os.Getenv(k); v != "" { - envTags[k] = v - } - } - } else { - for _, k := range []string{"location", "runId", "nodeName", "scenarioName"} { - if v := os.Getenv(k); v != "" { - envTags[k] = v - } + isSynthetic := strings.ToLower(params.Environment["syntheticMonitoring"]) == "true" + for _, key := range []string{"nodeName", "location", "scenarioName", "runId"} { + if value := params.Environment[key]; value != "" { + envTags[key] = value } } + // normalize snake_case keys expected by DB if v, ok := envTags["runId"]; ok { envTags["run_id"] = v @@ -145,24 +149,7 @@ func New(params output.Params) (output.Output, error) { envTags["scenario_name"] = v } - // Parse CUSTOM_URL_PATTERNS env (pattern==replacement comma-separated) - customPatterns := make(map[string]string) - if patterns := os.Getenv("CUSTOM_URL_PATTERNS"); patterns != "" { - fmt.Fprintf(params.StdOut, "Found CUSTOM_URL_PATTERNS environment variable: %s\n", patterns) - pairs := strings.Split(patterns, ",") - for _, pair := range pairs { - parts := strings.Split(pair, "==") - if len(parts) == 2 { - customPatterns[parts[0]] = parts[1] - fmt.Fprintf(params.StdOut, "Added custom pattern: %s -> %s\n", parts[0], parts[1]) - } else { - fmt.Fprintf(params.StdOut, "Warning: Invalid pattern format: %s\n", pair) - } - } - fmt.Fprintf(params.StdOut, "Total custom patterns loaded: %d\n", len(customPatterns)) - } else { - fmt.Fprintf(params.StdOut, "No CUSTOM_URL_PATTERNS environment variable found\n") - } + customPatterns := parseCustomPatterns(params.StdOut, params.Environment["CUSTOM_URL_PATTERNS"]) l := &Logger{ out: params.StdOut, @@ -174,7 +161,7 @@ func New(params output.Params) (output.Output, error) { bufVUs: &bytes.Buffer{}, bufTrans: &bytes.Buffer{}, bufErrors: &bytes.Buffer{}, - pendingHttpGroups: make(map[int64]*MetricGroup), + pendingHTTPGroups: make(map[int64]*MetricGroup), cleanupStop: make(chan struct{}), batchDone: make(chan struct{}), envTags: envTags, @@ -188,19 +175,24 @@ func New(params output.Params) (output.Output, error) { return l, nil } +// Description returns the output name. func (l *Logger) Description() string { return "breakingit" } -func (l *Logger) Start() error { return nil } +// Start satisfies the output lifecycle interface. +func (l *Logger) Start() error { return nil } + +// Stop flushes remaining samples and stops background processing. func (l *Logger) Stop() error { - fmt.Fprintf(l.out, "[screenshot] Stop() called, waiting for batchLoop to finish\n") + _, _ = fmt.Fprintf(l.out, "[screenshot] Stop() called, waiting for batchLoop to finish\n") l.batchTimer.Stop() close(l.cleanupStop) // Wait for any in-progress batchLoop flush to complete <-l.batchDone - fmt.Fprintf(l.out, "[screenshot] batchLoop done, running final flush (pendingScreenshots=%d)\n", len(l.pendingScreenshots)) + _, _ = fmt.Fprintf(l.out, "[screenshot] batchLoop done, running final flush (pendingScreenshots=%d)\n", + len(l.pendingScreenshots)) // Final flush to send any remaining data (including screenshots) l.flush() - fmt.Fprintf(l.out, "[screenshot] Stop() complete\n") + _, _ = fmt.Fprintf(l.out, "[screenshot] Stop() complete\n") return nil } @@ -233,15 +225,15 @@ func (l *Logger) cleanupProcessor() { now := time.Now() toProcessHTTP := make([]*MetricGroup, 0) l.mu.Lock() - for ts, g := range l.pendingHttpGroups { + for ts, g := range l.pendingHTTPGroups { if now.Sub(g.LastUpdate) > time.Second { toProcessHTTP = append(toProcessHTTP, g) - delete(l.pendingHttpGroups, ts) + delete(l.pendingHTTPGroups, ts) } } l.mu.Unlock() for _, g := range toProcessHTTP { - l.processHttpGroup(g) + l.processHTTPGroup(g) } case <-l.cleanupStop: return @@ -284,7 +276,8 @@ func (l *Logger) flush() { // Send screenshots via upsert endpoint (separate from batch COPY path) if len(screenshotsSnapshot) > 0 { - fmt.Fprintf(l.out, "[screenshot] flush: sending %d screenshot(s) to upsert endpoint\n", len(screenshotsSnapshot)) + _, _ = fmt.Fprintf(l.out, "[screenshot] flush: sending %d screenshot(s) to upsert endpoint\n", + len(screenshotsSnapshot)) l.upsertScreenshots(screenshotsSnapshot) } @@ -296,178 +289,30 @@ func (l *Logger) flush() { return } - // Build multipart body (reusable for retries) - var body bytes.Buffer - mw := multipart.NewWriter(&body) - - if len(bufHTTPSnapshot) > 0 { - h := make(textproto.MIMEHeader) - table := "public.requests_raw" - if l.isSynthetic { - table = "public.requests_raw_sm" - } - h.Set("X-Table", table) - h.Set("X-Format", "csv") - pw, _ := mw.CreatePart(h) - _, _ = io.Copy(pw, bytes.NewReader(bufHTTPSnapshot)) - } - if len(bufVUsSnapshot) > 0 && !l.isSynthetic { - h := make(textproto.MIMEHeader) - h.Set("X-Table", "public.virtual_users") - h.Set("X-Format", "csv") - pw, _ := mw.CreatePart(h) - _, _ = io.Copy(pw, bytes.NewReader(bufVUsSnapshot)) - } - if len(bufTransSnapshot) > 0 { - h := make(textproto.MIMEHeader) - table := "public.transactions" - if l.isSynthetic { - table = "public.transactions_sm" - } - h.Set("X-Table", table) - h.Set("X-Format", "csv") - pw, _ := mw.CreatePart(h) - _, _ = io.Copy(pw, bytes.NewReader(bufTransSnapshot)) - } - if len(bufErrorsSnapshot) > 0 { - h := make(textproto.MIMEHeader) - table := "public.requests_error" - if l.isSynthetic { - table = "public.requests_error_sm" - } - h.Set("X-Table", table) - h.Set("X-Format", "csv") - pw, _ := mw.CreatePart(h) - _, _ = io.Copy(pw, bytes.NewReader(bufErrorsSnapshot)) - } - _ = mw.Close() - - // gzip body - var gzBody bytes.Buffer - gz := gzip.NewWriter(&gzBody) - _, _ = gz.Write(body.Bytes()) - _ = gz.Close() - - // Retry logic with exponential backoff - startTime := time.Now() - backoffDelay := time.Duration(initialBackoffMs) * time.Millisecond - attempts := 0 - success := false - boundary := mw.Boundary() - gzBodyBytes := gzBody.Bytes() - - for !success && time.Since(startTime) < maxRetryTimeMs*time.Millisecond { - attempts++ - req, _ := http.NewRequest(http.MethodPost, l.proxyURL+"/ingest/batch", bytes.NewReader(gzBodyBytes)) - req.Header.Set("Authorization", "Bearer "+l.token) - req.Header.Set("Content-Type", "multipart/mixed; boundary="+boundary) - req.Header.Set("Content-Encoding", "gzip") - - resp, err := l.httpClient.Do(req) - if err != nil { - elapsed := time.Since(startTime) - if elapsed+backoffDelay < maxRetryTimeMs*time.Millisecond { - if attempts > 1 { - fmt.Fprintf(l.out, "pg-proxy ingest request error on attempt %d, retrying in %v: %v\n", attempts, backoffDelay, err) - } - time.Sleep(backoffDelay) - nextBackoffMs := backoffDelay.Milliseconds() * 2 - if nextBackoffMs > maxBackoffMs { - nextBackoffMs = maxBackoffMs - } - backoffDelay = time.Duration(nextBackoffMs) * time.Millisecond - } else { - fmt.Fprintf(l.out, "pg-proxy ingest request error after %d attempts (%v elapsed): %v\n", attempts, elapsed, err) - break - } - } else if resp != nil { - if resp.StatusCode == http.StatusOK { - success = true - _ = resp.Body.Close() - if attempts > 1 { - fmt.Fprintf(l.out, "pg-proxy ingest succeeded on attempt %d after %v\n", attempts, time.Since(startTime)) - } - } else { - b, _ := io.ReadAll(resp.Body) - _ = resp.Body.Close() - elapsed := time.Since(startTime) - if elapsed+backoffDelay < maxRetryTimeMs*time.Millisecond { - if attempts > 1 { - fmt.Fprintf(l.out, "pg-proxy ingest error status=%d body=%s on attempt %d, retrying in %v\n", resp.StatusCode, string(b), attempts, backoffDelay) - } - time.Sleep(backoffDelay) - nextBackoffMs := backoffDelay.Milliseconds() * 2 - if nextBackoffMs > maxBackoffMs { - nextBackoffMs = maxBackoffMs - } - backoffDelay = time.Duration(nextBackoffMs) * time.Millisecond - } else { - fmt.Fprintf(l.out, "pg-proxy ingest error after %d attempts (%v elapsed): status=%d body=%s\n", attempts, elapsed, resp.StatusCode, string(b)) - break - } - } - } - } - - if !success { - fmt.Fprintf(l.out, "pg-proxy ingest final failure after %d attempts (%v elapsed)\n", attempts, time.Since(startTime)) - } + body, boundary := l.batchBody(bufHTTPSnapshot, bufVUsSnapshot, bufTransSnapshot, bufErrorsSnapshot) + success := l.sendBatch(body, boundary) // Reset buffers and check for new data that accumulated during retries l.mu.Lock() hasNewData := false - var newHTTPData, newVUsData, newTransData, newErrorsData []byte - - if success { - // Check if any buffers grew during retries (new data accumulated) - // If so, preserve the new data before clearing - if l.bufHTTP.Len() > bufHTTPLen { - hasNewData = true - newHTTPData = make([]byte, l.bufHTTP.Len()-bufHTTPLen) - copy(newHTTPData, l.bufHTTP.Bytes()[bufHTTPLen:]) - } - if l.bufVUs.Len() > bufVUsLen { - hasNewData = true - newVUsData = make([]byte, l.bufVUs.Len()-bufVUsLen) - copy(newVUsData, l.bufVUs.Bytes()[bufVUsLen:]) - } - if l.bufTrans.Len() > bufTransLen { - hasNewData = true - newTransData = make([]byte, l.bufTrans.Len()-bufTransLen) - copy(newTransData, l.bufTrans.Bytes()[bufTransLen:]) - } - if l.bufErrors.Len() > bufErrorsLen { - hasNewData = true - newErrorsData = make([]byte, l.bufErrors.Len()-bufErrorsLen) - copy(newErrorsData, l.bufErrors.Bytes()[bufErrorsLen:]) - } - - // Clear buffers (we successfully sent the snapshot) - l.bufHTTP.Reset() - l.bufVUs.Reset() - l.bufTrans.Reset() - l.bufErrors.Reset() - - // Restore new data that accumulated during retries - if len(newHTTPData) > 0 { - l.bufHTTP.Write(newHTTPData) - } - if len(newVUsData) > 0 { - l.bufVUs.Write(newVUsData) - } - if len(newTransData) > 0 { - l.bufTrans.Write(newTransData) - } - if len(newErrorsData) > 0 { - l.bufErrors.Write(newErrorsData) + for _, item := range []struct { + buffer *bytes.Buffer + sent int + }{ + {l.bufHTTP, bufHTTPLen}, + {l.bufVUs, bufVUsLen}, + {l.bufTrans, bufTransLen}, + {l.bufErrors, bufErrorsLen}, + } { + if success { + item.buffer.Next(item.sent) + hasNewData = hasNewData || item.buffer.Len() > 0 + } else { + // Preserve the existing bounded-memory policy after exhausted retries. + item.buffer.Reset() } - } else { - // Retry loop exited without success (either timeout or early break), clear buffers to prevent unbounded growth - l.bufHTTP.Reset() - l.bufVUs.Reset() - l.bufTrans.Reset() - l.bufErrors.Reset() } + l.flushing = false l.mu.Unlock() @@ -480,32 +325,39 @@ func (l *Logger) flush() { } // upsertScreenshots sends screenshots to the pg-proxy upsert endpoint. -// Uses INSERT ... ON CONFLICT DO NOTHING on the proxy side, so duplicate hashes are silently skipped. -func (l *Logger) upsertScreenshots(rows [][]interface{}) { - payload := map[string]interface{}{ +// Uses INSERT ... ON CONFLICT DO NOTHING on the proxy side, so duplicate hashes are silently +// skipped. +func (l *Logger) upsertScreenshots(rows [][]any) { + payload := map[string]any{ "columns": []string{"hash", "data", "mime_type", "size_bytes"}, "rows": rows, } jsonBody, err := json.Marshal(payload) if err != nil { - fmt.Fprintf(l.out, "screenshot upsert marshal error: %v\n", err) + _, _ = fmt.Fprintf(l.out, "screenshot upsert marshal error: %v\n", err) + return + } + _, _ = fmt.Fprintf(l.out, "[screenshot] upsert: POSTing %d bytes to %s/upsert/public.sm_screenshots\n", + len(jsonBody), l.proxyURL) + req, err := http.NewRequestWithContext(context.Background(), http.MethodPost, + l.proxyURL+"/upsert/public.sm_screenshots", bytes.NewReader(jsonBody)) + if err != nil { + _, _ = fmt.Fprintf(l.out, "screenshot upsert request error: %v\n", err) return } - fmt.Fprintf(l.out, "[screenshot] upsert: POSTing %d bytes to %s/upsert/public.sm_screenshots\n", len(jsonBody), l.proxyURL) - req, _ := http.NewRequest(http.MethodPost, l.proxyURL+"/upsert/public.sm_screenshots", bytes.NewReader(jsonBody)) req.Header.Set("Authorization", "Bearer "+l.token) req.Header.Set("Content-Type", "application/json") resp, err := l.httpClient.Do(req) if err != nil { - fmt.Fprintf(l.out, "screenshot upsert request error: %v\n", err) + _, _ = fmt.Fprintf(l.out, "screenshot upsert request error: %v\n", err) return } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() if resp.StatusCode != http.StatusOK { b, _ := io.ReadAll(resp.Body) - fmt.Fprintf(l.out, "screenshot upsert error status=%d body=%s\n", resp.StatusCode, string(b)) + _, _ = fmt.Fprintf(l.out, "screenshot upsert error status=%d body=%s\n", resp.StatusCode, string(b)) } else { - fmt.Fprintf(l.out, "screenshot upsert ok rows=%d json_bytes=%d\n", len(rows), len(jsonBody)) + _, _ = fmt.Fprintf(l.out, "screenshot upsert ok rows=%d json_bytes=%d\n", len(rows), len(jsonBody)) } } @@ -537,270 +389,17 @@ func httpMetricCanonicalKey(metricName string) string { } } +// AddMetricSamples routes metric samples to the corresponding database rows. func (l *Logger) AddMetricSamples(samples []metrics.SampleContainer) { for _, sc := range samples { for _, s := range sc.GetSamples() { - ts := s.Time.UnixNano() - canonicalKey := httpMetricCanonicalKey(s.Metric.Name) - if canonicalKey != "" { - l.mu.Lock() - g, ok := l.pendingHttpGroups[ts] - if !ok { - g = &MetricGroup{Timestamp: ts, Tags: map[string]string{}, Values: map[string]float64{}, LastUpdate: time.Now()} - l.pendingHttpGroups[ts] = g - copyTagsForHTTP(g.Tags, s.Tags.Map(), l.envTags, l.customPatterns) - } - g.Values[canonicalKey] = s.Value - if canonicalKey == "http_req_failed" { - g.ErrorReqHeaders = s.HTTPErrorReqHeaders - g.ErrorReqBody = s.HTTPErrorReqBody - g.ErrorResHeaders = s.HTTPErrorResHeaders - g.ErrorResBody = s.HTTPErrorResBody - } - g.LastUpdate = time.Now() - // Process when we have the 8 required metrics (including http_req_failed); data_received is optional (browser only) - if _, hasFailed := g.Values["http_req_failed"]; hasFailed && len(g.Values) >= 8 { - delete(l.pendingHttpGroups, ts) - l.mu.Unlock() - l.processHttpGroup(g) - continue - } - l.mu.Unlock() - continue - } - if (s.Metric.Name == "pages" && l.transactionSource == transactionsGroups) || - (s.Metric.Name == "group_duration" && l.transactionSource == transactionsPages) { - continue - } - // pages -> transactions - if s.Metric.Name == "pages" { - m := s.Tags.Map() - // Prefer explicit 'page' tag when available - pageRaw := fmt.Sprintf("%v", m["page"]) - var transactionName string - if pageRaw != "" && pageRaw != "" { - transactionName = pageRaw - } else { - // Derive a stable transaction_name: prefer name, fallback to group, then '/' - nameRaw := fmt.Sprintf("%v", m["name"]) - if nameRaw == "" || nameRaw == "" { - nameRaw = fmt.Sprintf("%v", m["group"]) // sometimes present - } - if nameRaw == "" || nameRaw == "" { - nameRaw = "/" - } - // Process name: if URL, use path; if not URL, use as-is (capped at 64) - _, _, path, _ := processNameTag(nameRaw, l.customPatterns) - transactionName = path - } - // Non-SM transactions table columns: - // time, run_id, location, transaction_name, success, request_size, response_size, response_time - // SM transactions_sm (run_id last): time, scenario_name, location, node_name, thread_group_name, transaction_name, success, request_size, response_size, response_time, run_id - isSM := l.isSynthetic - var row []string - if isSM { - row = []string{ - time.Unix(0, ts).UTC().Format(time.RFC3339Nano), - fmt.Sprintf("%v", l.envTags["scenario_name"]), - fmt.Sprintf("%v", l.envTags["location"]), - fmt.Sprintf("%v", l.envTags["node_name"]), - fmt.Sprintf("%v", m["scenario"]), // thread_group_name from k6 scenario tag - transactionName, - "true", - "", - "", - fmtInt(s.Value), - fmt.Sprintf("%v", l.envTags["run_id"]), - } - } else { - row = []string{ - time.Unix(0, ts).UTC().Format(time.RFC3339Nano), - fmt.Sprintf("%v", l.envTags["run_id"]), - fmt.Sprintf("%v", l.envTags["location"]), - transactionName, - "true", - "", - "", - fmtInt(s.Value), - } - } - l.mu.Lock() - wt := csv.NewWriter(l.bufTrans) - _ = wt.Write(row) - wt.Flush() - l.mu.Unlock() - continue - } - // Native HTTP and browser groups -> transactions. - if s.Metric.Name == "group_duration" { - success := strconv.FormatBool(!s.GroupFailed) - m := s.Tags.Map() - // Derive transaction_name from 'group' tag, fallback to 'name' - nameRaw := fmt.Sprintf("%v", m["group"]) - if nameRaw == "" || nameRaw == "" { - nameRaw = fmt.Sprintf("%v", m["name"]) - } - nameRaw = strings.TrimPrefix(nameRaw, "::") - if nameRaw == "" || nameRaw == "" { - nameRaw = "/" - } - isSM := l.isSynthetic - var row []string - if isSM { - // SM transactions_sm (run_id last) - row = []string{ - time.Unix(0, ts).UTC().Format(time.RFC3339Nano), - fmt.Sprintf("%v", l.envTags["scenario_name"]), - fmt.Sprintf("%v", l.envTags["location"]), - fmt.Sprintf("%v", l.envTags["node_name"]), - fmt.Sprintf("%v", m["scenario"]), // thread_group_name from k6 scenario - nameRaw, - success, - "", - "", - fmtInt(s.Value), - fmt.Sprintf("%v", l.envTags["run_id"]), - } - } else { - row = []string{ - time.Unix(0, ts).UTC().Format(time.RFC3339Nano), - fmt.Sprintf("%v", l.envTags["run_id"]), - fmt.Sprintf("%v", l.envTags["location"]), - nameRaw, - success, - "", - "", - fmtInt(s.Value), - } - } - l.mu.Lock() - wt := csv.NewWriter(l.bufTrans) - _ = wt.Write(row) - wt.Flush() - l.mu.Unlock() - continue - } - // vus -> virtual_users (active_threads) - if s.Metric.Name == "vus" && !l.isSynthetic { - row := []string{ - time.Unix(0, ts).UTC().Format(time.RFC3339Nano), - fmt.Sprintf("%v", l.envTags["run_id"]), - fmt.Sprintf("%v", l.envTags["location"]), - fmt.Sprintf("%v", l.envTags["node_name"]), - fmt.Sprintf("%d", int64(s.Value)), // active_threads - "", // started_threads (unknown) - "", // finished_threads (unknown) - } - l.mu.Lock() - wv := csv.NewWriter(l.bufVUs) - _ = wv.Write(row) - wv.Flush() - l.mu.Unlock() - continue - } - // checks -> requests_error(_sm) when value == 0 (failed check) - if s.Metric.Name == "checks" && s.Value == 0 { - m := s.Tags.Map() - checkMsg := m["check"] // e.g. "is status 301" - if checkMsg == "" { - checkMsg = "check failed" - } - // Derive transaction_name from 'group' tag, strip leading '::' - transactionName := "" - if groupVal := m["group"]; groupVal != "" { - transactionName = strings.TrimPrefix(groupVal, "::") - } - responseCode := m["status"] // may be empty - // Use 'name' tag for sampler_name (this is passed from k6 check tags) - samplerName := m["name"] - if samplerName == "" { - // Fallback to check message or generic name - samplerName = checkMsg - } - // URL can be from 'url' tag or empty - url := m["url"] - // Get request/response data and error_response_time if provided via custom tags - requestData := m["request_data"] - responseData := m["response_data"] - responseTime := m["error_response_time"] // response time in ms from check tags - // Generate UUIDv7 using the measurement timestamp - id := generateUUIDv7(ts) - // Build row per schema (includes id field) - if l.isSynthetic { - // SM requests_error_sm (existing table: run_id last): time, scenario_name, ..., id, run_id - row := []string{ - time.Unix(0, ts).UTC().Format(time.RFC3339Nano), // time - fmt.Sprintf("%v", l.envTags["scenario_name"]), // scenario_name - fmt.Sprintf("%v", l.envTags["location"]), // location - fmt.Sprintf("%v", l.envTags["node_name"]), // node_name - m["scenario"], // thread_group_name - transactionName, // transaction_name - samplerName, // sampler_name - responseCode, // response_code - responseTime, // response_time - "", // connection_time - url, // url - "", // assertions - checkMsg, // response_message - requestData, // request_headers (used for request data) - "", // response_headers - responseData, // response_data - id, // id (UUIDv7 generated from measurement timestamp) - fmt.Sprintf("%v", l.envTags["run_id"]), // run_id last - } - l.mu.Lock() - we := csv.NewWriter(l.bufErrors) - _ = we.Write(row) - we.Flush() - l.mu.Unlock() - } else { - row := []string{ - time.Unix(0, ts).UTC().Format(time.RFC3339Nano), // time - fmt.Sprintf("%v", l.envTags["run_id"]), // run_id - fmt.Sprintf("%v", l.envTags["location"]), // location - fmt.Sprintf("%v", l.envTags["node_name"]), // node_name - transactionName, // transaction_name - samplerName, // sampler_name - responseCode, // response_code - responseTime, // response_time - "", // connection_time - url, // url - "", // assertions - checkMsg, // response_message - requestData, // request_headers (used for request data) - "", // response_headers - responseData, // response_data - id, // id (UUIDv7 generated from measurement timestamp) - } - l.mu.Lock() - we := csv.NewWriter(l.bufErrors) - _ = we.Write(row) - we.Flush() - l.mu.Unlock() - } - continue - } - // browser_errors -> requests_error(_sm) - if s.Metric.Name == "browser_errors" { - l.processBrowserError(s, ts) - continue - } - // WebSocket metrics -> requests_raw(_sm) - if s.Metric.Name == "ws_connecting" || s.Metric.Name == "ws_ping" { - l.processWebSocketMetric(s, ts) - continue - } - // Custom Trend metrics (custom_*) -> requests_raw(_sm) with minimal schema - if strings.HasPrefix(s.Metric.Name, "custom_") { - l.processCustomTrendMetric(s, ts) - continue - } - // removed http_req_failed-specific emission; handled in processHttpGroup when success == false + l.addMetricSample(s) } } } -// formatRequestData combines request headers and body into a single string for the request_headers column. +// formatRequestData combines request headers and body into a single string for the request_headers +// column. func formatRequestData(headers, body string) string { if headers != "" && body != "" { return headers + "\n" + body @@ -811,20 +410,25 @@ func formatRequestData(headers, body string) string { return body } -func (l *Logger) processHttpGroup(g *MetricGroup) { +func (l *Logger) processHTTPGroup(g *MetricGroup) { if g == nil { return } // Map k6 HTTP metrics to requests_raw(_sm) schema - // Non-SM: time, run_id, location, transaction_name, sampler_name, success, request_size, response_size, response_code, response_connect_time, response_latency, response_time - // SM (existing table: run_id last): time, scenario_name, location, node_name, thread_group_name, transaction_name, sampler_name, success, request_size, response_size, response_code, response_connect_time, response_latency, response_time, run_id - - // sampler_name: use path (normalized URL path if name was URL, or name itself capped at 64 chars if not) + // Non-SM: time, run_id, location, transaction_name, sampler_name, success, request_size, + // response_size, response_code, response_connect_time, response_latency, response_time + // SM (existing table: run_id last): time, scenario_name, location, node_name, thread_group_name, + // transaction_name, sampler_name, success, request_size, response_size, response_code, + // response_connect_time, response_latency, response_time, run_id + + // sampler_name: use path (normalized URL path if name was URL, or name itself capped at 64 chars + // if not) samplerName := g.Tags["path"] if samplerName == "" { samplerName = g.Tags["name"] } - // transaction_name: only set when we have an explicit "transaction" tag or "group" (from group()/group_duration). + // transaction_name: only set when we have an explicit "transaction" tag or "group" (from + // group()/group_duration). // If neither is set, leave empty (do not use sampler_name for browser). isBrowser := g.Tags["resource_type"] != "" var transactionName string @@ -841,7 +445,7 @@ func (l *Logger) processHttpGroup(g *MetricGroup) { } // Browser OPTIONS requests (CORS preflight): append _preflight to sampler_name if isBrowser && g.Tags["method"] == "OPTIONS" { - samplerName = samplerName + "_preflight" + samplerName += "_preflight" } // success is the inverse of http_req_failed @@ -856,19 +460,10 @@ func (l *Logger) processHttpGroup(g *MetricGroup) { // Timing fields (cast to integer strings) - matching JMeter definitions // http_req_duration = sending + waiting + receiving (same for k6 HTTP and browser) // See: https://grafana.com/docs/k6/latest/using-k6/metrics/reference/ - connecting := g.Values["http_req_connecting"] - tlsHandshaking := g.Values["http_req_tls_handshaking"] - sending := g.Values["http_req_sending"] - waiting := g.Values["http_req_waiting"] - duration := g.Values["http_req_duration"] - // JMeter-style: connectTime = TCP connect + TLS handshake - connectTime := fmtInt(connecting + tlsHandshaking) - // JMeter-style: latency = from connect until first byte is received - latency := fmtInt(connecting + tlsHandshaking + sending + waiting) - // JMeter-style: responseTime = full time from TCP connect to complete response received - responseTime := fmtInt(connecting + tlsHandshaking + duration) - - // response_size from browser_data_received when present (browser only); k6 HTTP has no per-request size in this group + connectTime, latency, responseTime := requestTimings(g.Values) + + // response_size from browser_data_received when present (browser only); k6 HTTP has no per-request + // size in this group responseSize := "" if v, ok := g.Values["data_received"]; ok && v >= 0 { responseSize = fmtInt(v) @@ -916,98 +511,9 @@ func (l *Logger) processHttpGroup(g *MetricGroup) { w.Flush() // If not successful, also emit into requests_error(_sm) if success == "false" { - // Build response_message from tags - errText := fmt.Sprintf("%v", g.Tags["error"]) // may be empty - if errText == "" { - errText = "" - } - errMsg := fmt.Sprintf("%v", g.Tags["error_message"]) - if errMsg == "" || errMsg == "" { - // fallback to error_code with prefix - errorCode := fmt.Sprintf("%v", g.Tags["error_code"]) - if errorCode != "" && errorCode != "" { - errMsg = fmt.Sprintf("K6 Error code %s", errorCode) - } else { - errMsg = "" - } - } - // Construct responseMessage: use errText if available, errMsg if available, or both with " - " separator - var responseMessage string - if errText != "" && errMsg != "" { - responseMessage = fmt.Sprintf("%s - %s", errText, errMsg) - } else if errText != "" { - responseMessage = errText - } else if errMsg != "" { - responseMessage = errMsg - } else { - responseMessage = "" - } - responseMessage = strings.TrimSpace(responseMessage) - // Browser 4xx/5xx often have no "error" tag; use status for response_message - if responseMessage == "" && responseCode != "" && responseCode != "0" { - responseMessage = "HTTP " + responseCode - } - nameRaw := g.Tags["name"] - // samplerName already derived; ensure non-empty for k6 HTTP (browser: leave empty when no transaction name) - if samplerName == "" || samplerName == "" { - if !isBrowser { - samplerName = transactionName - if samplerName == "" || samplerName == "" { - samplerName = "/" - } - } - } - // Generate UUIDv7 using the measurement timestamp - id := generateUUIDv7(g.Timestamp) - if l.isSynthetic { - // SM requests_error_sm (existing table: run_id last): time, scenario_name, ..., id, run_id - erow := []string{ - time.Unix(0, g.Timestamp).UTC().Format(time.RFC3339Nano), - g.Tags["scenario_name"], - g.Tags["location"], - g.Tags["node_name"], - g.Tags["scenario"], - transactionName, - samplerName, - responseCode, - responseTime, - connectTime, - nameRaw, - "", - responseMessage, - formatRequestData(g.ErrorReqHeaders, g.ErrorReqBody), // request_headers (includes post payload) - g.ErrorResHeaders, // response_headers - g.ErrorResBody, // response_data - id, // id (UUIDv7) - fmt.Sprintf("%v", l.envTags["run_id"]), - } - we := csv.NewWriter(l.bufErrors) - _ = we.Write(erow) - we.Flush() - } else { - erow := []string{ - time.Unix(0, g.Timestamp).UTC().Format(time.RFC3339Nano), - g.Tags["run_id"], - g.Tags["location"], - g.Tags["node_name"], - transactionName, - samplerName, - responseCode, - responseTime, - connectTime, - nameRaw, - "", - responseMessage, - formatRequestData(g.ErrorReqHeaders, g.ErrorReqBody), // request_headers (includes post payload) - g.ErrorResHeaders, // response_headers - g.ErrorResBody, // response_data - id, // id (UUIDv7) - } - we := csv.NewWriter(l.bufErrors) - _ = we.Write(erow) - we.Flush() - } + l.writeHTTPError(g, transactionName, samplerName, responseCode, responseTime, connectTime, isBrowser) } + l.mu.Unlock() } @@ -1025,33 +531,9 @@ func (l *Logger) processWebSocketMetric(s metrics.Sample, ts int64) { transactionName = strings.TrimPrefix(groupVal, "::") } - // sampler_name: derive from name tag (if not URL, capped at 64), else process url tag, else metric name - var samplerName string - // Special handling for ws_ping: always use 'WSPing' - if s.Metric.Name == "ws_ping" { - samplerName = "WSPing" - } else { - // For ws_connecting: prefer name tag (if not URL, capped at 64), else process url tag, else metric name - nameRaw := m["name"] - if nameRaw != "" { - // Check if name is a URL or plain name - _, _, path, _ := processNameTag(nameRaw, l.customPatterns) - // If name was a URL, path contains the normalized path; if not, path contains the name (capped at 64) - samplerName = path - } else { - // No name tag, try url tag - if urlRaw := m["url"]; urlRaw != "" { - _, _, path, _ := processURL(urlRaw, l.customPatterns) - if path != "" { - samplerName = path - } else { - samplerName = s.Metric.Name - } - } else { - samplerName = s.Metric.Name - } - } - } + // sampler_name: derive from name tag (if not URL, capped at 64), else process url tag, else metric + // name + samplerName := l.webSocketSamplerName(s) // response_code from status tag (101 for successful WebSocket connection) responseCode := m["status"] @@ -1089,7 +571,8 @@ func (l *Logger) processWebSocketMetric(s metrics.Sample, ts int64) { fmt.Sprintf("%v", l.envTags["run_id"]), } } else { - // Non-SM: time, run_id, location, transaction_name, sampler_name, success, request_size, response_size, response_code, response_connect_time, response_latency, response_time + // Non-SM: time, run_id, location, transaction_name, sampler_name, success, request_size, + // response_size, response_code, response_connect_time, response_latency, response_time row = []string{ time.Unix(0, ts).UTC().Format(time.RFC3339Nano), tags["run_id"], @@ -1118,9 +601,7 @@ func (l *Logger) processCustomTrendMetric(s metrics.Sample, ts int64) { // Extract basic tags from envTags (already normalized to snake_case) tags := make(map[string]string) - for k, v := range l.envTags { - tags[k] = v - } + maps.Copy(tags, l.envTags) // Ensure per-sample scenario tag is propagated so SM thread_group_name is set if scen, ok := m["scenario"]; ok && scen != "" { @@ -1139,7 +620,8 @@ func (l *Logger) processCustomTrendMetric(s metrics.Sample, ts int64) { if nameRaw != "" { // Check if name is a URL or plain name _, _, path, _ := processNameTag(nameRaw, l.customPatterns) - // If name was a URL, path contains the normalized path; if not, path contains the name (capped at 64) + // If name was a URL, path contains the normalized path; if not, path contains the name (capped at + // 64) samplerName = path } else { // Fallback to metric name @@ -1173,7 +655,8 @@ func (l *Logger) processCustomTrendMetric(s metrics.Sample, ts int64) { fmt.Sprintf("%v", l.envTags["run_id"]), } } else { - // Non-SM: time, run_id, location, transaction_name, sampler_name, success, request_size, response_size, response_code, response_connect_time, response_latency, response_time + // Non-SM: time, run_id, location, transaction_name, sampler_name, success, request_size, + // response_size, response_code, response_connect_time, response_latency, response_time row = []string{ time.Unix(0, ts).UTC().Format(time.RFC3339Nano), tags["run_id"], @@ -1217,16 +700,18 @@ func (l *Logger) processBrowserError(s metrics.Sample, ts int64) { transactionName = strings.TrimPrefix(groupVal, "::") } - // screenshot from the "screenshot" tag (base64-encoded PNG when K6_BROWSER_SCREENSHOT_ON_ERROR is enabled) + // screenshot from the "screenshot" tag (base64-encoded PNG when K6_BROWSER_SCREENSHOT_ON_ERROR is + // enabled) screenshot := m["screenshot"] screenshotHash := "" if screenshot != "" { // Calculate SHA-256 hash of the screenshot data for deduplication h := sha256.Sum256([]byte(screenshot)) screenshotHash = hex.EncodeToString(h[:]) - fmt.Fprintf(l.out, "[screenshot] received browser error with screenshot len=%d hash=%s\n", len(screenshot), screenshotHash) + _, _ = fmt.Fprintf(l.out, "[screenshot] received browser error with screenshot len=%d hash=%s\n", + len(screenshot), screenshotHash) } else { - fmt.Fprintf(l.out, "[screenshot] received browser error WITHOUT screenshot (tag count=%d)\n", len(m)) + _, _ = fmt.Fprintf(l.out, "[screenshot] received browser error WITHOUT screenshot (tag count=%d)\n", len(m)) } // Generate UUIDv7 @@ -1241,27 +726,27 @@ func (l *Logger) processBrowserError(s metrics.Sample, ts int64) { fmt.Sprintf("%v", l.envTags["scenario_name"]), // scenario_name fmt.Sprintf("%v", l.envTags["location"]), // location fmt.Sprintf("%v", l.envTags["node_name"]), // node_name - m["scenario"], // thread_group_name - transactionName, // transaction_name - samplerName, // sampler_name - "", // response_code - "", // response_time - "", // connection_time - "", // url - "", // assertions - errMsg, // response_message - "", // request_headers - "", // response_headers - screenshotHash, // response_data (screenshot hash reference) - id, // id (UUIDv7) + m["scenario"], // thread_group_name + transactionName, // transaction_name + samplerName, // sampler_name + "", // response_code + "", // response_time + "", // connection_time + "", // url + "", // assertions + errMsg, // response_message + "", // request_headers + "", // response_headers + screenshotHash, // response_data (screenshot hash reference) + id, // id (UUIDv7) fmt.Sprintf("%v", l.envTags["run_id"]), // run_id last } l.mu.Lock() if screenshotHash != "" { - l.pendingScreenshots = append(l.pendingScreenshots, []interface{}{ + l.pendingScreenshots = append(l.pendingScreenshots, []any{ screenshotHash, screenshot, "image/png", len(screenshot), }) - fmt.Fprintf(l.out, "[screenshot] queued for upsert, pendingScreenshots=%d\n", len(l.pendingScreenshots)) + _, _ = fmt.Fprintf(l.out, "[screenshot] queued for upsert, pendingScreenshots=%d\n", len(l.pendingScreenshots)) } we := csv.NewWriter(l.bufErrors) _ = we.Write(row) @@ -1288,7 +773,7 @@ func (l *Logger) processBrowserError(s metrics.Sample, ts int64) { } l.mu.Lock() if screenshotHash != "" { - l.pendingScreenshots = append(l.pendingScreenshots, []interface{}{ + l.pendingScreenshots = append(l.pendingScreenshots, []any{ screenshotHash, screenshot, "image/png", len(screenshot), }) } @@ -1299,14 +784,6 @@ func (l *Logger) processBrowserError(s metrics.Sample, ts int64) { } } -func fmtFloat(v float64) string { return fmt.Sprintf("%v", v) } -func fmtBool(v float64) string { - if v != 0 { - return "true" - } - return "false" -} - func fmtInt(v float64) string { return fmt.Sprintf("%d", int64(v)) } // generateUUIDv7 generates a UUIDv7 using the provided timestamp (nanoseconds since Unix epoch) @@ -1315,30 +792,31 @@ func generateUUIDv7(timestampNanos int64) string { t := time.Unix(0, timestampNanos) // Create a UUIDv7 with the specific timestamp - // UUIDv7 format: 48-bit timestamp (ms) + 4-bit version + 12-bit rand_a + 2-bit variant + 62-bit rand_b + // UUIDv7 format: 48-bit timestamp (ms) + 4-bit version + 12-bit rand_a + 2-bit variant + 62-bit + // rand_b timestampMs := uint64(t.UnixMilli()) // Build UUID bytes manually with the correct timestamp var uuidBytes [16]byte // First 48 bits: timestamp in milliseconds (big-endian) - uuidBytes[0] = byte(timestampMs >> 40) - uuidBytes[1] = byte(timestampMs >> 32) - uuidBytes[2] = byte(timestampMs >> 24) - uuidBytes[3] = byte(timestampMs >> 16) - uuidBytes[4] = byte(timestampMs >> 8) - uuidBytes[5] = byte(timestampMs) + uuidBytes[0] = byte((timestampMs >> 40) & 0xff) + uuidBytes[1] = byte((timestampMs >> 32) & 0xff) + uuidBytes[2] = byte((timestampMs >> 24) & 0xff) + uuidBytes[3] = byte((timestampMs >> 16) & 0xff) + uuidBytes[4] = byte((timestampMs >> 8) & 0xff) + uuidBytes[5] = byte(timestampMs & 0xff) // Generate random bytes for the rest randBytes := make([]byte, 10) rand.Read(randBytes) // Bytes 6-7: version (7) in high nibble + random - uuidBytes[6] = (0x70) | (randBytes[0] & 0x0F) // Version 7 + uuidBytes[6] = 0x70 | (randBytes[0] & 0x0F) // Version 7 uuidBytes[7] = randBytes[1] // Bytes 8-15: variant (10) in high 2 bits + random - uuidBytes[8] = (0x80) | (randBytes[2] & 0x3F) // Variant 10 + uuidBytes[8] = 0x80 | (randBytes[2] & 0x3F) // Variant 10 copy(uuidBytes[9:], randBytes[3:]) u, _ := uuid.FromBytes(uuidBytes[:]) @@ -1378,7 +856,8 @@ func truncateUTF8(s string, maxRunes int) string { return string(runes[:maxRunes]) } -// processNameTag processes the "name" tag: if it's a URL, parse and return path; otherwise return as-is (capped at 64 chars) +// processNameTag processes the "name" tag: if it's a URL, parse and return path; otherwise return +// as-is (capped at 64 chars) func processNameTag(nameRaw string, customPatterns map[string]string) (string, string, string, string) { // Try to parse as URL u, err := url.Parse(nameRaw) @@ -1407,10 +886,10 @@ func processNameTag(nameRaw string, customPatterns map[string]string) (string, s return scheme, host, p, cleanURL } -func copyTagsForHTTP(dst map[string]string, tags map[string]string, env map[string]string, customPatterns map[string]string) { +func copyTagsForHTTP(dst, tags, env, customPatterns map[string]string) { // start with env tags for k, v := range env { - if !excludedTags[k] { + if !excludedTag(k) { // map snake_case for consistency if k == "nodeName" { dst["node_name"] = v @@ -1442,7 +921,7 @@ func copyTagsForHTTP(dst map[string]string, tags map[string]string, env map[stri } } for k, v := range tags { - if !excludedTags[k] { + if !excludedTag(k) { // preserve normalized fields if k == "name" || k == "path" || k == "hostname" || k == "scheme" { continue @@ -1454,7 +933,7 @@ func copyTagsForHTTP(dst map[string]string, tags map[string]string, env map[stri if v, ok := tags["scenario"]; ok { dst["scenario"] = fmt.Sprintf("%v", v) } - // Browser samples often lack "group"; use path or name so processHttpGroup gets a transaction name + // Browser samples often lack "group"; use path or name so processHTTPGroup gets a transaction name if dst["group"] == "" { dst["group"] = dst["path"] if dst["group"] == "" { @@ -1466,15 +945,528 @@ func copyTagsForHTTP(dst map[string]string, tags map[string]string, env map[stri } } -func normalizeRegex(p string) string { - // Translate common PCRE shorthands to Go RE2 equivalents - replacer := strings.NewReplacer( - "\\d", "[0-9]", - "\\D", "[^0-9]", - "\\w", "[A-Za-z0-9_]", - "\\W", "[^A-Za-z0-9_]", - "\\s", "[ \t\r\n\f]", - "\\S", "[^ \t\r\n\f]", - ) - return replacer.Replace(p) +func (l *Logger) processHTTPSample(s metrics.Sample, ts int64, canonicalKey string) { + l.mu.Lock() + g, ok := l.pendingHTTPGroups[ts] + if !ok { + g = &MetricGroup{Timestamp: ts, Tags: map[string]string{}, Values: map[string]float64{}, LastUpdate: time.Now()} + l.pendingHTTPGroups[ts] = g + copyTagsForHTTP(g.Tags, s.Tags.Map(), l.envTags, l.customPatterns) + } + g.Values[canonicalKey] = s.Value + if canonicalKey == "http_req_failed" { + g.ErrorReqHeaders = s.HTTPErrorReqHeaders + g.ErrorReqBody = s.HTTPErrorReqBody + g.ErrorResHeaders = s.HTTPErrorResHeaders + g.ErrorResBody = s.HTTPErrorResBody + } + g.LastUpdate = time.Now() + // Process when we have the 8 required metrics (including http_req_failed); data_received is + // optional (browser only) + if _, hasFailed := g.Values["http_req_failed"]; hasFailed && len(g.Values) >= 8 { + delete(l.pendingHTTPGroups, ts) + l.mu.Unlock() + l.processHTTPGroup(g) + return + } + l.mu.Unlock() +} + +func (l *Logger) processPageSample(s metrics.Sample, ts int64) { + m := s.Tags.Map() + // Prefer explicit 'page' tag when available + pageRaw := fmt.Sprintf("%v", m["page"]) + var transactionName string + if pageRaw != "" && pageRaw != "" { + transactionName = pageRaw + } else { + // Derive a stable transaction_name: prefer name, fallback to group, then '/' + nameRaw := fmt.Sprintf("%v", m["name"]) + if nameRaw == "" || nameRaw == "" { + nameRaw = fmt.Sprintf("%v", m["group"]) // sometimes present + } + if nameRaw == "" || nameRaw == "" { + nameRaw = "/" + } + // Process name: if URL, use path; if not URL, use as-is (capped at 64) + _, _, path, _ := processNameTag(nameRaw, l.customPatterns) + transactionName = path + } + // Non-SM transactions table columns: + // time, run_id, location, transaction_name, success, request_size, response_size, response_time + // SM transactions_sm (run_id last): time, scenario_name, location, node_name, thread_group_name, + // transaction_name, success, request_size, response_size, response_time, run_id + isSM := l.isSynthetic + var row []string + if isSM { + row = []string{ + time.Unix(0, ts).UTC().Format(time.RFC3339Nano), + fmt.Sprintf("%v", l.envTags["scenario_name"]), + fmt.Sprintf("%v", l.envTags["location"]), + fmt.Sprintf("%v", l.envTags["node_name"]), + fmt.Sprintf("%v", m["scenario"]), // thread_group_name from k6 scenario tag + transactionName, + "true", + "", + "", + fmtInt(s.Value), + fmt.Sprintf("%v", l.envTags["run_id"]), + } + } else { + row = []string{ + time.Unix(0, ts).UTC().Format(time.RFC3339Nano), + fmt.Sprintf("%v", l.envTags["run_id"]), + fmt.Sprintf("%v", l.envTags["location"]), + transactionName, + "true", + "", + "", + fmtInt(s.Value), + } + } + l.mu.Lock() + wt := csv.NewWriter(l.bufTrans) + _ = wt.Write(row) + wt.Flush() + l.mu.Unlock() +} + +func (l *Logger) processGroupSample(s metrics.Sample, ts int64) { + success := strconv.FormatBool(!s.GroupFailed) + m := s.Tags.Map() + // Derive transaction_name from 'group' tag, fallback to 'name' + nameRaw := fmt.Sprintf("%v", m["group"]) + if nameRaw == "" || nameRaw == "" { + nameRaw = fmt.Sprintf("%v", m["name"]) + } + nameRaw = strings.TrimPrefix(nameRaw, "::") + if nameRaw == "" || nameRaw == "" { + nameRaw = "/" + } + isSM := l.isSynthetic + var row []string + if isSM { + // SM transactions_sm (run_id last) + row = []string{ + time.Unix(0, ts).UTC().Format(time.RFC3339Nano), + fmt.Sprintf("%v", l.envTags["scenario_name"]), + fmt.Sprintf("%v", l.envTags["location"]), + fmt.Sprintf("%v", l.envTags["node_name"]), + fmt.Sprintf("%v", m["scenario"]), // thread_group_name from k6 scenario + nameRaw, + success, + "", + "", + fmtInt(s.Value), + fmt.Sprintf("%v", l.envTags["run_id"]), + } + } else { + row = []string{ + time.Unix(0, ts).UTC().Format(time.RFC3339Nano), + fmt.Sprintf("%v", l.envTags["run_id"]), + fmt.Sprintf("%v", l.envTags["location"]), + nameRaw, + success, + "", + "", + fmtInt(s.Value), + } + } + l.mu.Lock() + wt := csv.NewWriter(l.bufTrans) + _ = wt.Write(row) + wt.Flush() + l.mu.Unlock() +} + +func (l *Logger) processVUsSample(s metrics.Sample, ts int64) { + row := []string{ + time.Unix(0, ts).UTC().Format(time.RFC3339Nano), + fmt.Sprintf("%v", l.envTags["run_id"]), + fmt.Sprintf("%v", l.envTags["location"]), + fmt.Sprintf("%v", l.envTags["node_name"]), + fmt.Sprintf("%d", int64(s.Value)), // active_threads + "", // started_threads (unknown) + "", // finished_threads (unknown) + } + l.mu.Lock() + wv := csv.NewWriter(l.bufVUs) + _ = wv.Write(row) + wv.Flush() + l.mu.Unlock() +} + +func (l *Logger) processCheckSample(s metrics.Sample, ts int64) { + m := s.Tags.Map() + checkMsg := m["check"] // e.g. "is status 301" + if checkMsg == "" { + checkMsg = "check failed" + } + // Derive transaction_name from 'group' tag, strip leading '::' + transactionName := "" + if groupVal := m["group"]; groupVal != "" { + transactionName = strings.TrimPrefix(groupVal, "::") + } + responseCode := m["status"] // may be empty + // Use 'name' tag for sampler_name (this is passed from k6 check tags) + samplerName := m["name"] + if samplerName == "" { + // Fallback to check message or generic name + samplerName = checkMsg + } + // URL can be from 'url' tag or empty + url := m["url"] + // Get request/response data and error_response_time if provided via custom tags + requestData := m["request_data"] + responseData := m["response_data"] + responseTime := m["error_response_time"] // response time in ms from check tags + // Generate UUIDv7 using the measurement timestamp + id := generateUUIDv7(ts) + // Build row per schema (includes id field) + if l.isSynthetic { + // SM requests_error_sm (existing table: run_id last): time, scenario_name, ..., id, run_id + row := []string{ + time.Unix(0, ts).UTC().Format(time.RFC3339Nano), // time + fmt.Sprintf("%v", l.envTags["scenario_name"]), // scenario_name + fmt.Sprintf("%v", l.envTags["location"]), // location + fmt.Sprintf("%v", l.envTags["node_name"]), // node_name + m["scenario"], // thread_group_name + transactionName, // transaction_name + samplerName, // sampler_name + responseCode, // response_code + responseTime, // response_time + "", // connection_time + url, // url + "", // assertions + checkMsg, // response_message + requestData, // request_headers (used for request data) + "", // response_headers + responseData, // response_data + id, // id (UUIDv7 generated from measurement timestamp) + fmt.Sprintf("%v", l.envTags["run_id"]), // run_id last + } + l.mu.Lock() + we := csv.NewWriter(l.bufErrors) + _ = we.Write(row) + we.Flush() + l.mu.Unlock() + } else { + row := []string{ + time.Unix(0, ts).UTC().Format(time.RFC3339Nano), // time + fmt.Sprintf("%v", l.envTags["run_id"]), // run_id + fmt.Sprintf("%v", l.envTags["location"]), // location + fmt.Sprintf("%v", l.envTags["node_name"]), // node_name + transactionName, // transaction_name + samplerName, // sampler_name + responseCode, // response_code + responseTime, // response_time + "", // connection_time + url, // url + "", // assertions + checkMsg, // response_message + requestData, // request_headers (used for request data) + "", // response_headers + responseData, // response_data + id, // id (UUIDv7 generated from measurement timestamp) + } + l.mu.Lock() + we := csv.NewWriter(l.bufErrors) + _ = we.Write(row) + we.Flush() + l.mu.Unlock() + } +} + +func (l *Logger) batchBody( + bufHTTPSnapshot, bufVUsSnapshot, bufTransSnapshot, bufErrorsSnapshot []byte, +) ([]byte, string) { + var body bytes.Buffer + mw := multipart.NewWriter(&body) + + if len(bufHTTPSnapshot) > 0 { + h := make(textproto.MIMEHeader) + table := "public.requests_raw" + if l.isSynthetic { + table = "public.requests_raw_sm" + } + h.Set("X-Table", table) + h.Set("X-Format", "csv") + pw, _ := mw.CreatePart(h) + _, _ = io.Copy(pw, bytes.NewReader(bufHTTPSnapshot)) + } + if len(bufVUsSnapshot) > 0 && !l.isSynthetic { + h := make(textproto.MIMEHeader) + h.Set("X-Table", "public.virtual_users") + h.Set("X-Format", "csv") + pw, _ := mw.CreatePart(h) + _, _ = io.Copy(pw, bytes.NewReader(bufVUsSnapshot)) + } + if len(bufTransSnapshot) > 0 { + h := make(textproto.MIMEHeader) + table := "public.transactions" + if l.isSynthetic { + table = "public.transactions_sm" + } + h.Set("X-Table", table) + h.Set("X-Format", "csv") + pw, _ := mw.CreatePart(h) + _, _ = io.Copy(pw, bytes.NewReader(bufTransSnapshot)) + } + if len(bufErrorsSnapshot) > 0 { + h := make(textproto.MIMEHeader) + table := "public.requests_error" + if l.isSynthetic { + table = "public.requests_error_sm" + } + h.Set("X-Table", table) + h.Set("X-Format", "csv") + pw, _ := mw.CreatePart(h) + _, _ = io.Copy(pw, bytes.NewReader(bufErrorsSnapshot)) + } + _ = mw.Close() + + // gzip body + var gzBody bytes.Buffer + gz := gzip.NewWriter(&gzBody) + _, _ = gz.Write(body.Bytes()) + _ = gz.Close() + + return gzBody.Bytes(), mw.Boundary() +} + +func (l *Logger) sendBatch(body []byte, boundary string) bool { + start := time.Now() + delay := time.Duration(initialBackoffMs) * time.Millisecond + for attempts := 1; time.Since(start) < maxRetryTimeMs*time.Millisecond; attempts++ { + err := l.postBatch(body, boundary) + if err == nil { + return true + } + elapsed := time.Since(start) + _, _ = fmt.Fprintf(l.out, "pg-proxy ingest attempt %d failed (%v elapsed): %v\n", attempts, elapsed, err) + if elapsed+delay >= maxRetryTimeMs*time.Millisecond { + break + } + time.Sleep(delay) + delay = min(delay*2, maxBackoffMs*time.Millisecond) + } + return false +} + +func (l *Logger) postBatch(body []byte, boundary string) error { + req, err := http.NewRequestWithContext(context.Background(), http.MethodPost, + l.proxyURL+"/ingest/batch", bytes.NewReader(body)) + if err != nil { + return err + } + req.Header.Set("Authorization", "Bearer "+l.token) + req.Header.Set("Content-Type", "multipart/mixed; boundary="+boundary) + req.Header.Set("Content-Encoding", "gzip") + resp, err := l.httpClient.Do(req) + if err != nil { + return err + } + defer func() { _ = resp.Body.Close() }() + if resp.StatusCode != http.StatusOK { + body, _ := io.ReadAll(resp.Body) + return fmt.Errorf("status=%d body=%s", resp.StatusCode, body) + } + return nil +} + +// writeHTTPError requires the buffer lock to be held by the caller. +func (l *Logger) writeHTTPError(g *MetricGroup, + transactionName, samplerName, responseCode, responseTime, connectTime string, isBrowser bool, +) { + // Build response_message from tags + errText := fmt.Sprintf("%v", g.Tags["error"]) // may be empty + if errText == "" { + errText = "" + } + errMsg := fmt.Sprintf("%v", g.Tags["error_message"]) + if errMsg == "" || errMsg == "" { + // fallback to error_code with prefix + errorCode := fmt.Sprintf("%v", g.Tags["error_code"]) + if errorCode != "" && errorCode != "" { + errMsg = fmt.Sprintf("K6 Error code %s", errorCode) + } else { + errMsg = "" + } + } + // Construct responseMessage: use errText if available, errMsg if available, or both with " - " + // separator + var responseMessage string + switch { + case errText != "" && errMsg != "": + responseMessage = fmt.Sprintf("%s - %s", errText, errMsg) + case errText != "": + responseMessage = errText + case errMsg != "": + responseMessage = errMsg + default: + responseMessage = "" + } + responseMessage = strings.TrimSpace(responseMessage) + // Browser 4xx/5xx often have no "error" tag; use status for response_message + if responseMessage == "" && responseCode != "" && responseCode != "0" { + responseMessage = "HTTP " + responseCode + } + nameRaw := g.Tags["name"] + // samplerName already derived; ensure non-empty for k6 HTTP (browser: leave empty when no + // transaction name) + if samplerName == "" || samplerName == "" { + if !isBrowser { + samplerName = transactionName + if samplerName == "" || samplerName == "" { + samplerName = "/" + } + } + } + // Generate UUIDv7 using the measurement timestamp + id := generateUUIDv7(g.Timestamp) + if l.isSynthetic { + // SM requests_error_sm (existing table: run_id last): time, scenario_name, ..., id, run_id + erow := []string{ + time.Unix(0, g.Timestamp).UTC().Format(time.RFC3339Nano), + g.Tags["scenario_name"], + g.Tags["location"], + g.Tags["node_name"], + g.Tags["scenario"], + transactionName, + samplerName, + responseCode, + responseTime, + connectTime, + nameRaw, + "", + responseMessage, + formatRequestData(g.ErrorReqHeaders, g.ErrorReqBody), // request_headers (includes post payload) + g.ErrorResHeaders, // response_headers + g.ErrorResBody, // response_data + id, // id (UUIDv7) + fmt.Sprintf("%v", l.envTags["run_id"]), + } + we := csv.NewWriter(l.bufErrors) + _ = we.Write(erow) + we.Flush() + } else { + erow := []string{ + time.Unix(0, g.Timestamp).UTC().Format(time.RFC3339Nano), + g.Tags["run_id"], + g.Tags["location"], + g.Tags["node_name"], + transactionName, + samplerName, + responseCode, + responseTime, + connectTime, + nameRaw, + "", + responseMessage, + formatRequestData(g.ErrorReqHeaders, g.ErrorReqBody), // request_headers (includes post payload) + g.ErrorResHeaders, // response_headers + g.ErrorResBody, // response_data + id, // id (UUIDv7) + } + we := csv.NewWriter(l.bufErrors) + _ = we.Write(erow) + we.Flush() + } +} + +func (l *Logger) webSocketSamplerName(s metrics.Sample) string { + if s.Metric.Name == "ws_ping" { + return "WSPing" + } + tags := s.Tags.Map() + if name := tags["name"]; name != "" { + _, _, path, _ := processNameTag(name, l.customPatterns) + return path + } + if raw := tags["url"]; raw != "" { + _, _, path, _ := processURL(raw, l.customPatterns) + if path != "" { + return path + } + } + return s.Metric.Name +} + +func (l *Logger) addMetricSample(s metrics.Sample) { + ts := s.Time.UnixNano() + canonicalKey := httpMetricCanonicalKey(s.Metric.Name) + if canonicalKey != "" { + l.processHTTPSample(s, ts, canonicalKey) + return + } + if (s.Metric.Name == "pages" && l.transactionSource == transactionsGroups) || + (s.Metric.Name == "group_duration" && l.transactionSource == transactionsPages) { + return + } + // pages -> transactions + if s.Metric.Name == "pages" { + l.processPageSample(s, ts) + return + } + // Native HTTP and browser groups -> transactions. + if s.Metric.Name == "group_duration" { + l.processGroupSample(s, ts) + return + } + // vus -> virtual_users (active_threads) + if s.Metric.Name == "vus" && !l.isSynthetic { + l.processVUsSample(s, ts) + return + } + // checks -> requests_error(_sm) when value == 0 (failed check) + if s.Metric.Name == "checks" && s.Value == 0 { + l.processCheckSample(s, ts) + return + } + // browser_errors -> requests_error(_sm) + if s.Metric.Name == "browser_errors" { + l.processBrowserError(s, ts) + return + } + // WebSocket metrics -> requests_raw(_sm) + if s.Metric.Name == "ws_connecting" || s.Metric.Name == "ws_ping" { + l.processWebSocketMetric(s, ts) + return + } + // Custom Trend metrics (custom_*) -> requests_raw(_sm) with minimal schema + if strings.HasPrefix(s.Metric.Name, "custom_") { + l.processCustomTrendMetric(s, ts) + return + } + // removed http_req_failed-specific emission; handled in processHTTPGroup when success == false +} + +func parseCustomPatterns(out io.Writer, patterns string) map[string]string { + // Parse CUSTOM_URL_PATTERNS env (pattern==replacement comma-separated) + customPatterns := make(map[string]string) + if patterns != "" { + _, _ = fmt.Fprintf(out, "Found CUSTOM_URL_PATTERNS environment variable: %s\n", patterns) + for pair := range strings.SplitSeq(patterns, ",") { + parts := strings.Split(pair, "==") + if len(parts) == 2 { + customPatterns[parts[0]] = parts[1] + _, _ = fmt.Fprintf(out, "Added custom pattern: %s -> %s\n", parts[0], parts[1]) + } else { + _, _ = fmt.Fprintf(out, "Warning: Invalid pattern format: %s\n", pair) + } + } + _, _ = fmt.Fprintf(out, "Total custom patterns loaded: %d\n", len(customPatterns)) + } else { + _, _ = fmt.Fprintf(out, "No CUSTOM_URL_PATTERNS environment variable found\n") + } + + return customPatterns +} + +// requestTimings converts k6 timings to the JMeter-style fields expected by BreakTest. +func requestTimings(values map[string]float64) (connectTime, latency, responseTime string) { + connect := values["http_req_connecting"] + values["http_req_tls_handshaking"] + return fmtInt(connect), + fmtInt(connect + values["http_req_sending"] + values["http_req_waiting"]), + fmtInt(connect + values["http_req_duration"]) } diff --git a/internal/output/breakingit/config_test.go b/internal/output/breakingit/config_test.go new file mode 100644 index 000000000..560070f53 --- /dev/null +++ b/internal/output/breakingit/config_test.go @@ -0,0 +1,49 @@ +package breakingit + +import ( + "io" + "net/http" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "go.k6.io/k6/v2/output" +) + +func TestConfiguredEnvironment(t *testing.T) { + t.Parallel() + exporter, err := New(output.Params{ + ConfigArgument: "https://proxy.example.test", StdOut: io.Discard, + Environment: map[string]string{ + "PG_PROXY_TOKEN": "configured-token", "PG_PROXY_DB": "configured-db", + "PG_PROXY_INSECURE_SKIP_TLS_VERIFY": "false", "syntheticMonitoring": "true", + "runId": "run", "nodeName": "node", "scenarioName": "scenario", "location": "AMS", + "CUSTOM_URL_PATTERNS": "[0-9]+=={id}", + }, + }) + require.NoError(t, err) + t.Cleanup(func() { assert.NoError(t, exporter.Stop()) }) + logger := exporter.(*Logger) + assert.Equal(t, "configured-token", logger.token) + assert.Equal(t, "configured-db", logger.database) + assert.True(t, logger.isSynthetic) + assert.Equal(t, "run", logger.envTags["run_id"]) + assert.Equal(t, "node", logger.envTags["node_name"]) + assert.Equal(t, "scenario", logger.envTags["scenario_name"]) + assert.Equal(t, "AMS", logger.envTags["location"]) + assert.Equal(t, "{id}", logger.customPatterns["[0-9]+"]) + assert.False(t, logger.httpClient.Transport.(*http.Transport).TLSClientConfig.InsecureSkipVerify) +} + +func TestInvalidProxyTLSConfiguration(t *testing.T) { + t.Parallel() + exporter, err := New(output.Params{ + ConfigArgument: "https://proxy.example.test", StdOut: io.Discard, + Environment: map[string]string{ + "PG_PROXY_TOKEN": "test", "PG_PROXY_INSECURE_SKIP_TLS_VERIFY": "invalid", + }, + }) + require.ErrorContains(t, err, "PG_PROXY_INSECURE_SKIP_TLS_VERIFY") + assert.Nil(t, exporter) +} diff --git a/internal/output/breakingit/http_rows_test.go b/internal/output/breakingit/http_rows_test.go new file mode 100644 index 000000000..6e46bb805 --- /dev/null +++ b/internal/output/breakingit/http_rows_test.go @@ -0,0 +1,65 @@ +package breakingit + +import ( + "encoding/csv" + "fmt" + "testing" + "time" + + "github.com/gofrs/uuid/v5" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestFailedHTTPRows(t *testing.T) { + t.Parallel() + for _, synthetic := range []bool{false, true} { + t.Run(fmt.Sprint(synthetic), func(t *testing.T) { + t.Parallel() + logger := newTransactionTestLogger(synthetic) + at := time.Date(2026, 9, 24, 12, 0, 0, 123000000, time.UTC) + logger.processHTTPGroup(&MetricGroup{ + Timestamp: at.UnixNano(), + Tags: map[string]string{ + "group": "::Checkout", "path": "/pay", "name": "https://example.test/pay", + "status": "500", "run_id": "run-123", "location": "Amsterdam", + "node_name": "node-1", "scenario_name": "checkout", "scenario": "browser_checkout", + }, + Values: map[string]float64{ + "http_req_failed": 1, "http_req_connecting": 2, "http_req_tls_handshaking": 3, + "http_req_sending": 4, "http_req_waiting": 5, "http_req_duration": 20, + }, + ErrorReqHeaders: "POST /pay", ErrorReqBody: "payload", + ErrorResHeaders: "HTTP/1.1 500", ErrorResBody: "failure", + }) + requests, err := csv.NewReader(logger.bufHTTP).ReadAll() + require.NoError(t, err) + require.Len(t, requests, 1) + offset := 3 + if synthetic { + offset = 5 + } + assert.Equal(t, []string{"Checkout", "/pay", "false", "", "", "500", "5", "14", "25"}, + requests[0][offset:offset+9]) + errors, err := csv.NewReader(logger.bufErrors).ReadAll() + require.NoError(t, err) + require.Len(t, errors, 1) + offset = 4 + if synthetic { + offset = 5 + } + assert.Equal(t, []string{ + "Checkout", "/pay", "500", "25", "5", "https://example.test/pay", "", + "HTTP 500", "POST /pay\npayload", "HTTP/1.1 500", "failure", + }, errors[0][offset:offset+11]) + id, err := uuid.FromString(errors[0][offset+11]) + require.NoError(t, err) + assert.EqualValues(t, 7, id.Version()) + stamp, err := uuid.TimestampFromV7(id) + require.NoError(t, err) + stampTime, err := stamp.Time() + require.NoError(t, err) + assert.Equal(t, at.UnixMilli(), stampTime.UnixMilli()) + }) + } +} diff --git a/internal/output/breakingit/transactions_test.go b/internal/output/breakingit/transactions_test.go index 9d1368f91..8c8009ab3 100644 --- a/internal/output/breakingit/transactions_test.go +++ b/internal/output/breakingit/transactions_test.go @@ -25,7 +25,7 @@ func newTransactionTestLogger(synthetic bool) *Logger { out: io.Discard, isSynthetic: synthetic, bufHTTP: &bytes.Buffer{}, bufVUs: &bytes.Buffer{}, bufTrans: &bytes.Buffer{}, bufErrors: &bytes.Buffer{}, - pendingHttpGroups: make(map[int64]*MetricGroup), + pendingHTTPGroups: make(map[int64]*MetricGroup), envTags: map[string]string{ "run_id": "run-123", "location": "Amsterdam", "node_name": "node-1", "scenario_name": "checkout", @@ -130,11 +130,11 @@ func TestTransactionSource(t *testing.T) { } func TestTransactionSourceConfiguration(t *testing.T) { - t.Setenv("PG_PROXY_TOKEN", "test-token") + t.Parallel() for _, value := range []string{"", "both", "groups", "pages", "invalid"} { exporter, err := New(output.Params{ ConfigArgument: "http://127.0.0.1", StdOut: io.Discard, - Environment: map[string]string{"BREAKINGIT_TRANSACTION_SOURCE": value}, + Environment: map[string]string{"BREAKINGIT_TRANSACTION_SOURCE": value, "PG_PROXY_TOKEN": "test-token"}, }) if value == "invalid" { require.ErrorContains(t, err, "BREAKINGIT_TRANSACTION_SOURCE") @@ -160,7 +160,7 @@ func TestBrowserRequestKeepsExplicitGroup(t *testing.T) { {"/", "/", ""}, } { l := newTransactionTestLogger(synthetic) - l.processHttpGroup(&MetricGroup{ + l.processHTTPGroup(&MetricGroup{ Tags: map[string]string{"group": test.group, "path": test.path, "resource_type": "Document"}, }) rows, err := csv.NewReader(l.bufHTTP).ReadAll() diff --git a/lib/netext/httpext/fork_error_data_test.go b/lib/netext/httpext/fork_error_data_test.go new file mode 100644 index 000000000..4ca82fdca --- /dev/null +++ b/lib/netext/httpext/fork_error_data_test.go @@ -0,0 +1,33 @@ +package httpext + +import ( + "testing" + + "github.com/stretchr/testify/assert" + + "go.k6.io/k6/v2/metrics" +) + +func TestHTTPErrorBodyRepresentations(t *testing.T) { + t.Parallel() + for _, tc := range []struct { + name string + body any + want string + }{ + {"string", "response", "response"}, + {"bytes", []byte("response"), "response"}, + {"empty string", "", ""}, + {"empty bytes", []byte{}, ""}, + {"nil", nil, ""}, + {"binary string", string([]byte{0xff}), ""}, + {"binary bytes", []byte{0xff}, ""}, + } { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + var sample metrics.Sample + setHTTPErrorFields(&sample, nil, &Response{Body: tc.body}) + assert.Equal(t, tc.want, sample.HTTPErrorResBody) + }) + } +} diff --git a/lib/netext/httpext/transport.go b/lib/netext/httpext/transport.go index 0ab937224..fcb95df7a 100644 --- a/lib/netext/httpext/transport.go +++ b/lib/netext/httpext/transport.go @@ -149,24 +149,9 @@ func (t *transport) measureAndEmitMetrics(unfReq *unfinishedRequest) *finishedRe trail.SaveSamples(t.state.BuiltinMetrics, &tagsAndMeta) if t.responseCallback != nil { - trail.Failed.Valid = true - if failed == 1 { - trail.Failed.Bool = true - } - failedSample := metrics.Sample{ - TimeSeries: metrics.TimeSeries{ - Metric: t.state.BuiltinMetrics.HTTPReqFailed, - Tags: tagsAndMeta.Tags, - }, - Time: trail.EndTime, - Metadata: tagsAndMeta.Metadata, - Value: failed, - } - if failed == 1 && t.state.Options.HTTPErrorData.Bool { - setHTTPErrorFields(&failedSample, t.errorDataReq, t.errorDataResp) - } - trail.Samples = append(trail.Samples, failedSample) + t.addFailedSample(trail, &tagsAndMeta, failed) } + metrics.PushIfNotDone(t.ctx, t.state.Samples, trail) return result } @@ -254,25 +239,14 @@ func setHTTPErrorFields(s *metrics.Sample, req *Request, resp *Response) { if resp != nil { s.HTTPErrorResHeaders = formatResponseHeaders(resp.Proto, resp.StatusText, resp.Headers) } - if resp != nil && resp.Body != nil { - switch body := resp.Body.(type) { - case string: - if body != "" { - if utf8.ValidString(body) { - s.HTTPErrorResBody = body - } else { - s.HTTPErrorResBody = "" - } - } - case []byte: - if len(body) > 0 { - if utf8.Valid(body) { - s.HTTPErrorResBody = string(body) - } else { - s.HTTPErrorResBody = "" - } - } - } + if resp == nil { + return + } + switch body := resp.Body.(type) { + case string: + s.HTTPErrorResBody = printableErrorBody(body) + case []byte: + s.HTTPErrorResBody = printableErrorBody(string(body)) } } @@ -324,3 +298,30 @@ func formatResponseHeaders(proto string, statusText string, headers map[string]s } return b.String() } + +func printableErrorBody(body string) string { + if !utf8.ValidString(body) { + return "" + } + return body +} + +func (t *transport) addFailedSample(trail *Trail, tagsAndMeta *metrics.TagsAndMeta, failed float64) { + trail.Failed.Valid = true + if failed == 1 { + trail.Failed.Bool = true + } + failedSample := metrics.Sample{ + TimeSeries: metrics.TimeSeries{ + Metric: t.state.BuiltinMetrics.HTTPReqFailed, + Tags: tagsAndMeta.Tags, + }, + Time: trail.EndTime, + Metadata: tagsAndMeta.Metadata, + Value: failed, + } + if failed == 1 && t.state.Options.HTTPErrorData.Bool { + setHTTPErrorFields(&failedSample, t.errorDataReq, t.errorDataResp) + } + trail.Samples = append(trail.Samples, failedSample) +} From 0b7fd6efb722df9722a3a411b74ff16cdbff75bd Mon Sep 17 00:00:00 2001 From: jgaalen Date: Tue, 13 Oct 2026 14:29:10 +0200 Subject: [PATCH 180/182] Wait for resized screenshot surfaces to paint before capture --- .../modules/k6/browser/common/screenshotter.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/internal/js/modules/k6/browser/common/screenshotter.go b/internal/js/modules/k6/browser/common/screenshotter.go index d905d8fc7..e4adf3f4f 100644 --- a/internal/js/modules/k6/browser/common/screenshotter.go +++ b/internal/js/modules/k6/browser/common/screenshotter.go @@ -164,6 +164,18 @@ func (s *screenshotter) originalViewportSize(p *Page) (*Size, error) { return &viewportSize, nil } +// setViewportSize waits for a paint at the new size before capturing the compositor surface. +// A device-metrics acknowledgement alone can leave the old surface in place briefly. +func (s *screenshotter) setViewportSize(p *Page, size *Size) error { + if err := p.setViewportSize(s.ctx, size); err != nil { + return err + } + _, err := p.frameManager.MainFrame().evaluate(s.ctx, utilityWorld, + evalOptions{forceCallable: true, returnByValue: true}, + `() => new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)))`) + return err +} + func (s *screenshotter) restoreViewport(p *Page, originalSize *EmulatedSize) error { ctx, cancel := s.cleanupContext() defer cancel() @@ -321,7 +333,7 @@ func (s *screenshotter) screenshotElement( err = errors.Join(err, fmt.Errorf("restoring viewport: %w", restoreErr)) } }() - if err := h.frame.page.setViewportSize(s.ctx, overriddenViewportSize); err != nil { + if err := s.setViewportSize(h.frame.page, overriddenViewportSize); err != nil { return nil, fmt.Errorf("setting viewport size to %s: %w", overriddenViewportSize, err) } @@ -401,7 +413,7 @@ func (s *screenshotter) screenshotPage(p *Page, opts *PageScreenshotOptions) (bu viewportSize, restoreErr)) } }() - if err := p.setViewportSize(s.ctx, fullPageSize); err != nil { + if err := s.setViewportSize(p, fullPageSize); err != nil { return nil, fmt.Errorf("setting viewport size to %s: %w", fullPageSize, err) } From 326d472a4b23c4e07d48a75afa9b80b50d3f5c8f Mon Sep 17 00:00:00 2001 From: jgaalen Date: Fri, 6 Nov 2026 07:29:22 +0100 Subject: [PATCH 181/182] Build and test the lean fork in Breaking-IT/k6 --- .github/workflows/browser_e2e.yml | 82 -- .github/workflows/build.yml | 713 ------------------ .github/workflows/codeql-analysis.yml | 28 - .github/workflows/feature-briefs.yml | 37 - .github/workflows/issue-auto-assign.yml | 54 -- .github/workflows/lean.yml | 48 ++ .github/workflows/lint.yml | 50 -- .github/workflows/publish-techdocs.yaml | 25 - .github/workflows/stale.yml | 32 - .github/workflows/summary-code-generation.yml | 69 -- .github/workflows/tc39.yml | 44 -- .github/workflows/test-browser.yml | 109 --- .github/workflows/test.yml | 106 --- .github/workflows/wpt.yml | 44 -- .../workflows/xk6-tests/xk6-js-test/go.mod | 48 -- .../workflows/xk6-tests/xk6-js-test/go.sum | 128 ---- .../workflows/xk6-tests/xk6-js-test/jstest.go | 69 -- .../xk6-tests/xk6-output-test/go.mod | 40 - .../xk6-tests/xk6-output-test/go.sum | 103 --- .../xk6-tests/xk6-output-test/outputtest.go | 58 -- .github/workflows/xk6-tests/xk6-test.js | 23 - .github/workflows/xk6.yml | 106 --- AGENTS.md | 8 +- FORK.md | 10 +- README.md | 2 +- 25 files changed, 58 insertions(+), 1978 deletions(-) delete mode 100644 .github/workflows/browser_e2e.yml delete mode 100644 .github/workflows/build.yml delete mode 100644 .github/workflows/codeql-analysis.yml delete mode 100644 .github/workflows/feature-briefs.yml delete mode 100644 .github/workflows/issue-auto-assign.yml create mode 100644 .github/workflows/lean.yml delete mode 100644 .github/workflows/lint.yml delete mode 100644 .github/workflows/publish-techdocs.yaml delete mode 100644 .github/workflows/stale.yml delete mode 100644 .github/workflows/summary-code-generation.yml delete mode 100644 .github/workflows/tc39.yml delete mode 100644 .github/workflows/test-browser.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/wpt.yml delete mode 100644 .github/workflows/xk6-tests/xk6-js-test/go.mod delete mode 100644 .github/workflows/xk6-tests/xk6-js-test/go.sum delete mode 100644 .github/workflows/xk6-tests/xk6-js-test/jstest.go delete mode 100644 .github/workflows/xk6-tests/xk6-output-test/go.mod delete mode 100644 .github/workflows/xk6-tests/xk6-output-test/go.sum delete mode 100644 .github/workflows/xk6-tests/xk6-output-test/outputtest.go delete mode 100644 .github/workflows/xk6-tests/xk6-test.js delete mode 100644 .github/workflows/xk6.yml diff --git a/.github/workflows/browser_e2e.yml b/.github/workflows/browser_e2e.yml deleted file mode 100644 index 074183491..000000000 --- a/.github/workflows/browser_e2e.yml +++ /dev/null @@ -1,82 +0,0 @@ -name: E2E -on: - # Enable manually triggering this workflow via the API or web UI - workflow_dispatch: - push: - branches: - - master - - v1.x - pull_request: - paths-ignore: - - 'docs/**' - - 'release notes/**' - -defaults: - run: - shell: bash - -permissions: - contents: read - -jobs: - test: - strategy: - fail-fast: false - matrix: - go: [stable, tip] - platform: [ubuntu-latest, ubuntu-24.04-arm, windows-latest, macos-latest] - runs-on: ${{ matrix.platform }} - steps: - - name: Checkout code - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 - with: - persist-credentials: false - - name: Install Go - uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6 - with: - go-version: 1.x - check-latest: true - cache: false # against cache-poisoning - - name: Install Go tip - if: matrix.go == 'tip' - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - gh release download ${{ matrix.platform }} --repo grafana/gotip --pattern 'go.zip' - unzip go.zip -d $HOME/sdk - echo "GOROOT=$HOME/sdk/gotip" >> "$GITHUB_ENV" - echo "GOPATH=$HOME/go" >> "$GITHUB_ENV" - echo "$HOME/go/bin" >> "$GITHUB_PATH" - echo "$HOME/sdk/gotip/bin" >> "$GITHUB_PATH" - - name: Install chromium - # This is only needed on arm images, chromium comes preinstalled on amd64 runner images. - if: contains(matrix.platform, 'arm') - run: | - sudo apt update && sudo apt install chromium-browser - chromium --version - - name: Build k6 - run: | - which go - go version - - go build . - ./k6 version - - name: Run E2E tests - run: | - set -x - if [ "$RUNNER_OS" == "Linux" ] && [ "$RUNNER_ARCH" == "X64" ]; then - export K6_BROWSER_EXECUTABLE_PATH=/usr/bin/google-chrome - fi - export K6_BROWSER_HEADLESS=true - export K6_FEATURES=async-metric-context - export K6_NO_USAGE_REPORT=true - for f in examples/browser/*.js; do - if [ "$f" == "examples/browser/hosts.js" ] && [ "$RUNNER_OS" == "Windows" ]; then - echo "skipping $f on Windows" - continue - fi - ./k6 run -q "$f" - done - - name: Check screenshot - # TODO: Do something more sophisticated? - run: test -s screenshot.png diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index aa0f86710..000000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,713 +0,0 @@ -name: Build -on: - workflow_dispatch: - inputs: - k6_version: - description: 'The version of the release, it must use the semantic versioning format with the v prefix. It is a development release so it is suggested to append a build metadata (e.g. v0.38.0-dev).' - required: true - go_version: - description: 'Go version for building binaries' - default: '1.x' - required: true - push: - branches: - - master - - v1.x - tags: - - v* - pull_request: - paths-ignore: - - 'docs/**' - - 'release notes/**' - -defaults: - run: - shell: bash - -permissions: - contents: read - -env: - APP_NAME: "k6" - DOCKER_IMAGE_ID: "us-docker.pkg.dev/grafanalabs-global/dockerhub-k6-prod-mirror/k6" - GHCR_IMAGE_ID: ${{ github.repository }} - DEFAULT_GO_VERSION: "1.26.x" - -jobs: - configure: - runs-on: ubuntu-latest - outputs: - k6_version: ${{ steps.get_k6_version.outputs.k6_version }} - go_version: ${{ steps.get_go_version.outputs.go_version }} - sign_windows_artifacts: ${{ steps.determine_windows_signing.outputs.sign_windows_artifacts }} - major: ${{ steps.classify_release.outputs.major }} - is_prerelease: ${{ steps.classify_release.outputs.is_prerelease }} - is_latest_stable: ${{ steps.classify_release.outputs.is_latest_stable }} - is_latest_in_major: ${{ steps.classify_release.outputs.is_latest_in_major }} - steps: - - name: Checkout code - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 - with: - fetch-depth: 0 - persist-credentials: false - - name: Get the k6 version - id: get_k6_version - env: - INPUT_K6_VERSION: ${{ github.event.inputs.k6_version }} - run: | - set -x # Show exactly what commands are executed - if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]] && [[ "${INPUT_K6_VERSION}" != "" ]]; then - VERSION="${INPUT_K6_VERSION}" - echo "Building custom dev build with version '${VERSION}' from manual workflow_dispatch..." - elif [[ "${GITHUB_REF}" =~ ^refs/tags/v.+$ ]]; then - VERSION="${GITHUB_REF##*/}" - echo "Building real version tag '${GITHUB_REF}', parsed '${VERSION}' as the actual version..." - else - VERSION="$(git describe --tags --always --long --dirty)" - echo "Building a non-version ref '${GITHUB_REF}', use '${VERSION}' as the version instead..." - fi - echo "VERSION=${VERSION}" - echo "k6_version=${VERSION}" >> $GITHUB_OUTPUT - - name: Get the used Go version - id: get_go_version - env: - INPUT_GO_VERSION: ${{ github.event.inputs.go_version }} - run: | - set -x # Show exactly what commands are executed - if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]] && [[ "${INPUT_GO_VERSION}" != "" ]]; then - GO_VERSION="${INPUT_GO_VERSION}" - echo "Using custom Go version '${GO_VERSION}' from manual workflow_dispatch..." - else - GO_VERSION="${DEFAULT_GO_VERSION}" - echo "Using the default Go version '${GO_VERSION}'..." - fi - echo "GO_VERSION=${GO_VERSION}" - echo "go_version=${GO_VERSION}" >> $GITHUB_OUTPUT - - # Secrets are unavailable when building from project forks, so this - # will fail for external PRs, even if we wanted to do it. And we don't. - # We are only going to sign packages that are built from the default branch - # or a version tag, or manually triggered dev builds, so we have enough - # assurance that package signing works, but don't sign every PR build. - - name: Determine whether to sign the Windows artifacts - id: determine_windows_signing - env: - SIGN_FILES: ${{ github.repository == 'grafana/k6' && (github.ref_name == github.event.repository.default_branch || startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch') }} - run: | - set -x # Show exactly what commands are executed - if [[ "${SIGN_FILES}" == "true" ]]; then - echo "Windows artifacts will be signed" - sign_windows_artifacts="true" - else - echo "Windows artifacts will not be signed" - sign_windows_artifacts="false" - fi - echo "sign_windows_artifacts=${sign_windows_artifacts}" >> ${GITHUB_OUTPUT} - - # Classify the release so we can decide whether this build should: - # - move the Docker :latest tag (only the highest stable tag overall) - # - move the Docker :vN floating major tag (any stable tag, per major) - # - be marked as the GitHub "Latest release" or as a pre-release - # This prevents pre-releases (e.g. -rc) and maintenance releases on - # older majors (e.g. v1.x after v2.0.0 ships) from claiming "latest". - - name: Classify release - id: classify_release - env: - VERSION: ${{ steps.get_k6_version.outputs.k6_version }} - run: | - set -x - MAJOR="" - IS_PRERELEASE=false - IS_LATEST_STABLE=false - IS_LATEST_IN_MAJOR=false - if [[ "${GITHUB_REF}" =~ ^refs/tags/v.+$ ]]; then - MAJOR=$(echo "${VERSION}" | sed -E 's/^v([0-9]+).*/\1/') - if [[ "${VERSION}" == *-* ]]; then - IS_PRERELEASE=true - fi - # Highest stable tag in the repo (excludes anything with a - # pre-release identifier like -rc, -beta, -dev). - MAX_STABLE=$(git tag --sort=-v:refname | grep -vE '-' | head -n1 || true) - if [[ "${IS_PRERELEASE}" == "false" && "${VERSION}" == "${MAX_STABLE}" ]]; then - IS_LATEST_STABLE=true - fi - # Highest stable tag within this tag's major. Needed because - # we can ship multiple bugfix releases on an older major - # (e.g. v1.4.2 after v1.5.0 is already out on the v1 line): - # only the newest one on that major should move :vN. - MAX_STABLE_IN_MAJOR=$(git tag --sort=-v:refname \ - | grep -vE '-' \ - | grep -E "^v${MAJOR}\." \ - | head -n1 || true) - if [[ "${IS_PRERELEASE}" == "false" && "${VERSION}" == "${MAX_STABLE_IN_MAJOR}" ]]; then - IS_LATEST_IN_MAJOR=true - fi - fi - echo "major=${MAJOR}" >> ${GITHUB_OUTPUT} - echo "is_prerelease=${IS_PRERELEASE}" >> ${GITHUB_OUTPUT} - echo "is_latest_stable=${IS_LATEST_STABLE}" >> ${GITHUB_OUTPUT} - echo "is_latest_in_major=${IS_LATEST_IN_MAJOR}" >> ${GITHUB_OUTPUT} - - build: - runs-on: ubuntu-latest - needs: [configure] - env: - VERSION: ${{ needs.configure.outputs.k6_version }} - steps: - - name: Checkout code - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 - with: - fetch-depth: 0 - persist-credentials: false - - name: Install Go - uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6 - with: - go-version: ${{ needs.configure.outputs.go_version }} - check-latest: true - cache: false # against cache-poisoning - - name: Install nfpm (dep and rpm package builder) - run: | - go install github.com/goreleaser/nfpm/v2/cmd/nfpm@v2.16.0 - - name: Install goversioninfo (.syso file creator) - run: | - go install github.com/josephspurrier/goversioninfo/cmd/goversioninfo@v1.4.0 - - name: Generate Windows binary metadata (.syso files) - run: | - IFS=. read -a version_parts <<< "${VERSION#v}" - IFS=- read -a version_patch <<< "${version_parts[2]}" - - # Need a blank versioninfo.json for the CLI overrides to work. - echo '{}' > versioninfo.json - set -x - goversioninfo -64 \ - -platform-specific=true \ - -charset="1200" \ - -company="Raintank Inc. d.b.a. Grafana Labs" \ - -copyright="© Raintank Inc. d.b.a. Grafana Labs. Licensed under AGPL." \ - -description="A modern load testing tool, using Go and JavaScript" \ - -icon=packaging/k6.ico \ - -internal-name="k6" \ - -original-name="k6.exe" \ - -product-name="k6" \ - -translation="0x0409" \ - -ver-major="${version_parts[0]}" \ - -ver-minor="${version_parts[1]}" \ - -ver-patch="${version_patch[0]}" \ - -special-build=$(IFS='-'; echo "${version_patch[*]:1}";) \ - -product-version="${VERSION#v}" - - set +x - ls -lah | grep -i syso - - - name: Build - run: | - go version - ./build-release.sh "dist" "${VERSION}" - - name: Upload artifacts - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 - with: - name: binaries - path: dist/ - retention-days: 7 - - build-docker: - permissions: - contents: read - packages: write - id-token: write - runs-on: ubuntu-latest - needs: [configure] - env: - VERSION: ${{ needs.configure.outputs.k6_version }} - steps: - - name: Checkout code - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 - with: - fetch-depth: 0 - persist-credentials: false - - name: Build - run: | - docker buildx create \ - --name multibuilder \ - --platform linux/amd64,linux/arm64 \ - --bootstrap --use - docker buildx build \ - --target release \ - --platform linux/amd64,linux/arm64 \ - -t $DOCKER_IMAGE_ID . - - name: Check - run: | - set -x - CHECK_IMAGE_TAG="k6:check" - docker buildx build --target with-browser --load -t $CHECK_IMAGE_TAG . - # Assert that simple cases works for the new built image - docker run --rm --pull never $CHECK_IMAGE_TAG version - docker run --rm --pull never $CHECK_IMAGE_TAG --help - docker run --rm --pull never $CHECK_IMAGE_TAG help - docker run --rm --pull never $CHECK_IMAGE_TAG run --help - docker run --rm --pull never $CHECK_IMAGE_TAG inspect --help - - # Run a browser script to smoke test the browser image - # Using framelocator.js because it does not depend on an external website - docker run --rm \ - --pull never \ - --env K6_NO_USAGE_REPORT=true \ - -v "$PWD/examples/browser:/tests:ro" \ - $CHECK_IMAGE_TAG run -q "/tests/framelocator.js" - - name: Login to GAR (Docker Hub mirror) - if: ${{ github.repository == 'grafana/k6' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')) }} - uses: grafana/shared-workflows/actions/login-to-gar@c7ad5f57693ac858c698d95783685a9cbfd91223 # login-to-gar/v1.0.1 - with: - registry: us-docker.pkg.dev - - name: Login to GitHub Container Registry - uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 - env: - GITHUB_ACTOR: ${{ github.actor }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - registry: ghcr.io - username: ${{ env.GITHUB_ACTOR }} - password: ${{ env.GITHUB_TOKEN }} - if: ${{ github.repository == 'grafana/k6' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')) }} - - name: Publish k6:master images - if: ${{ github.repository == 'grafana/k6' && (github.ref == 'refs/heads/master') }} - run: | - echo "Publish $GHCR_IMAGE_ID:master* images" - docker buildx build --push \ - --target release \ - --platform linux/amd64,linux/arm64 \ - -t $DOCKER_IMAGE_ID:master \ - -t ghcr.io/$GHCR_IMAGE_ID:master . - docker buildx build --push \ - --target with-browser \ - --platform linux/amd64,linux/arm64 \ - -t $DOCKER_IMAGE_ID:master-with-browser \ - -t ghcr.io/$GHCR_IMAGE_ID:master-with-browser . - - name: Publish tagged version images - if: ${{ github.repository == 'grafana/k6' && (startsWith(github.ref, 'refs/tags/v')) }} - run: | - VERSION="${VERSION#v}" - echo "Publish $GHCR_IMAGE_ID:$VERSION images" - docker buildx build --push \ - --target release \ - --platform linux/amd64,linux/arm64 \ - -t $DOCKER_IMAGE_ID:$VERSION \ - -t ghcr.io/$GHCR_IMAGE_ID:$VERSION . - docker buildx build --push \ - --target with-browser \ - --platform linux/amd64,linux/arm64 \ - -t $DOCKER_IMAGE_ID:$VERSION-with-browser \ - -t ghcr.io/$GHCR_IMAGE_ID:$VERSION-with-browser . - # Move the floating major tag (e.g. :v1, :v2) only when this tag is - # the highest stable tag on its major. Pre-releases never move it, - # and a bugfix released on an older line within the same major - # (e.g. v1.4.2 after v1.5.0) does not regress :vN. - - name: Publish floating major tag - if: ${{ github.repository == 'grafana/k6' && (needs.configure.outputs.is_latest_in_major == 'true') }} - env: - MAJOR: ${{ needs.configure.outputs.major }} - run: | - echo "Publish $GHCR_IMAGE_ID:v$MAJOR images" - docker buildx build --push \ - --target release \ - --platform linux/amd64,linux/arm64 \ - -t $DOCKER_IMAGE_ID:v$MAJOR \ - -t ghcr.io/$GHCR_IMAGE_ID:v$MAJOR . - docker buildx build --push \ - --target with-browser \ - --platform linux/amd64,linux/arm64 \ - -t $DOCKER_IMAGE_ID:v$MAJOR-with-browser \ - -t ghcr.io/$GHCR_IMAGE_ID:v$MAJOR-with-browser . - # Only the highest stable tag in the repo gets :latest. Maintenance - # releases on older majors (e.g. v1.x after v2.0.0 ships) and any - # pre-release must not move :latest. - - name: Publish :latest - if: ${{ github.repository == 'grafana/k6' && (needs.configure.outputs.is_latest_stable == 'true') }} - run: | - echo "Publish $GHCR_IMAGE_ID:latest" - docker buildx build --push \ - --target release \ - --platform linux/amd64,linux/arm64 \ - -t $DOCKER_IMAGE_ID:latest \ - -t ghcr.io/$GHCR_IMAGE_ID:latest . - docker buildx build --push \ - --target with-browser \ - --platform linux/amd64,linux/arm64 \ - -t $DOCKER_IMAGE_ID:latest-with-browser \ - -t ghcr.io/$GHCR_IMAGE_ID:latest-with-browser . - - # Forks, PRs etc. won't actually sign the binary, but the workflow will run most of the same steps as - # GitHub Actions workflows don't support conditional `needs` so we have to run the signing step unconditionally. - sign-binaries: - permissions: - contents: read - actions: read - id-token: write # Required for Vault - - env: - VERSION: ${{ needs.configure.outputs.k6_version }} - - environment: - name: azure-trusted-signing - - runs-on: windows-latest - defaults: - run: - shell: pwsh - needs: [configure, build] - outputs: - binary_artifact_name: ${{ steps.assign-artifact-names.outputs.binary-artifact-name }} - windows_binary_artifact_name: ${{ steps.assign-artifact-names.outputs.windows-binary-artifact-name }} - steps: - - name: Download binaries - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 - with: - name: binaries - path: dist - - - name: Unzip Windows binary - run: | - Expand-Archive -Path ".\dist\k6-${env:VERSION}-windows-amd64.zip" -DestinationPath .\packaging\ - - - name: Upload artifact for Windows installer build - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 - with: - name: windows-binary - path: 'packaging/k6-${{ env.VERSION }}-windows-amd64/k6.exe' - retention-days: 7 - if-no-files-found: error - - - name: Get secrets for Azure Trusted Signing - uses: grafana/shared-workflows/actions/get-vault-secrets@a53fc80bc30b0a16a262520465db899fa3af08b7 # get-vault-secrets/v1.3.2 - id: get-signing-secrets - if: needs.configure.outputs.sign_windows_artifacts == 'true' - with: - export_env: false - repo_secrets: | - client-id=azure-trusted-signing:client-id - subscription-id=azure-trusted-signing:subscription-id - tenant-id=azure-trusted-signing:tenant-id - - - name: Sign Windows binary - uses: grafana/shared-workflows/actions/azure-trusted-signing@6a042eda14a697e71944976ab618d27104d9fed4 # azure-trusted-signing/v1.0.3 - id: sign-artifacts - if: needs.configure.outputs.sign_windows_artifacts == 'true' - with: - application-description: 'Grafana k6' - artifact-to-sign: 'windows-binary' - azure-client-id: ${{ fromJSON(steps.get-signing-secrets.outputs.secrets).client-id }} - azure-subscription-id: ${{ fromJSON(steps.get-signing-secrets.outputs.secrets).subscription-id }} - azure-tenant-id: ${{ fromJSON(steps.get-signing-secrets.outputs.secrets).tenant-id }} - signed-artifact-name: 'windows-binary-signed' - - - name: Download signed Windows binary - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 - if: needs.configure.outputs.sign_windows_artifacts == 'true' - with: - name: ${{ steps.sign-artifacts.outputs.artifact-name }} - path: 'packaging/k6-${{ env.VERSION }}-windows-amd64' - - # Re-zip the signed Windows binary to replace the original unsigned version - - name: Zip signed Windows binary - if: needs.configure.outputs.sign_windows_artifacts == 'true' - run: | - Compress-Archive -Path ".\packaging\*" -DestinationPath ".\dist\k6-${env:VERSION}-windows-amd64.zip" -Force - - - name: Upload signed artifacts - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 - if: needs.configure.outputs.sign_windows_artifacts == 'true' - with: - name: binaries-signed - path: dist/ - retention-days: 7 - if-no-files-found: error - - - name: Assign artifact name for Windows binary for installer build - id: assign-artifact-names - env: - BINARY_ARTIFACT_NAME: ${{ needs.configure.outputs.sign_windows_artifacts == 'true' && 'binaries-signed' || 'binaries' }} - WINDOWS_BINARY_ARTIFACT_NAME: ${{ needs.configure.outputs.sign_windows_artifacts == 'true' && steps.sign-artifacts.outputs.artifact-name || 'windows-binary' }} - run: | - echo "binary-artifact-name=${env:BINARY_ARTIFACT_NAME}" >> ${env:GITHUB_OUTPUT} - echo "windows-binary-artifact-name=${env:WINDOWS_BINARY_ARTIFACT_NAME}" >> ${env:GITHUB_OUTPUT} - - package: - permissions: - contents: read - actions: read - - runs-on: windows-latest - defaults: - run: - shell: pwsh - needs: [configure, build, sign-binaries] - env: - VERSION: ${{ needs.configure.outputs.k6_version }} - steps: - - name: Checkout code - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 - with: - persist-credentials: false - - name: Install pandoc - uses: crazy-max/ghaction-chocolatey@dff3862348493b11fba2fbc49147b6d2dfe09b66 # v4.0.0 - with: - args: install -y pandoc - - name: Install wix tools - run: | - curl -Lso wix311-binaries.zip https://github.com/wixtoolset/wix3/releases/download/wix3112rtm/wix311-binaries.zip - Expand-Archive -Path .\wix311-binaries.zip -DestinationPath .\wix311\ - echo "$pwd\wix311" | Out-File -FilePath $env:GITHUB_PATH -Append - - name: Download Windows binary - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 - with: - name: ${{ needs.sign-binaries.outputs.windows_binary_artifact_name }} - path: packaging - - - name: Create the MSI package - run: | - $env:VERSION = $env:VERSION -replace 'v(\d+\.\d+\.\d+).*','$1' - pandoc -s -f markdown -t rtf -o packaging\LICENSE.rtf LICENSE.md - cd .\packaging - candle.exe -arch x64 "-dVERSION=${env:VERSION}" k6.wxs - light.exe -ext WixUIExtension k6.wixobj - - - name: Rename MSI package - # To keep it consistent with the other artifacts - run: move "packaging\k6.msi" "packaging\k6-${env:VERSION}-windows-amd64.msi" - - - name: Upload Windows installer - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 - with: - name: binaries-windows - path: | - packaging/k6-*.msi - retention-days: 7 - if-no-files-found: error - - # Forks, PRs etc. won't actually sign the installer, but the workflow will run most of the same steps as - # GitHub Actions workflows don't support conditional `needs` so we have to run the signing step unconditionally. - sign-packages: - permissions: - actions: read - contents: read - id-token: write # Required for Vault - - environment: - name: azure-trusted-signing - - outputs: - artifact_name: ${{ steps.assign-artifact-name.outputs.artifact-name }} - - runs-on: windows-latest - defaults: - run: - shell: pwsh - needs: [configure, package] - steps: - - name: Download Windows artifacts - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 - if: needs.configure.outputs.sign_windows_artifacts == 'true' - with: - name: binaries-windows - path: packaging - - - name: Get secrets for Azure Trusted Signing - uses: grafana/shared-workflows/actions/get-vault-secrets@a53fc80bc30b0a16a262520465db899fa3af08b7 # get-vault-secrets/v1.3.2 - id: get-signing-secrets - if: needs.configure.outputs.sign_windows_artifacts == 'true' - with: - export_env: false - repo_secrets: | - client-id=azure-trusted-signing:client-id - subscription-id=azure-trusted-signing:subscription-id - tenant-id=azure-trusted-signing:tenant-id - - - name: Sign Windows installer - uses: grafana/shared-workflows/actions/azure-trusted-signing@6a042eda14a697e71944976ab618d27104d9fed4 # azure-trusted-signing/v1.0.3 - id: sign-artifacts - if: needs.configure.outputs.sign_windows_artifacts == 'true' - with: - application-description: 'Grafana k6' - artifact-to-sign: 'binaries-windows' - azure-client-id: ${{ fromJSON(steps.get-signing-secrets.outputs.secrets).client-id }} - azure-subscription-id: ${{ fromJSON(steps.get-signing-secrets.outputs.secrets).subscription-id }} - azure-tenant-id: ${{ fromJSON(steps.get-signing-secrets.outputs.secrets).tenant-id }} - signed-artifact-name: 'binaries-windows-signed' - - - name: Assign artifact name for Windows installer - id: assign-artifact-name - env: - ARTIFACT_NAME: ${{ needs.configure.outputs.sign_windows_artifacts == 'true' && steps.sign-artifacts.outputs.artifact-name || 'binaries-windows' }} - run: | - echo "artifact-name=${env:ARTIFACT_NAME}" >> ${env:GITHUB_OUTPUT} - - publish-github: - runs-on: ubuntu-latest - needs: [configure, sign-binaries, sign-packages] - if: ${{ github.repository == 'grafana/k6' && (startsWith(github.ref, 'refs/tags/v') && github.event_name != 'workflow_dispatch') }} - env: - VERSION: ${{ needs.configure.outputs.k6_version }} - permissions: - actions: read - contents: write - steps: - - name: Checkout code - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 - with: - persist-credentials: false - - name: Download binaries - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 - with: - name: ${{ needs.sign-binaries.outputs.binary_artifact_name }} - path: dist - - name: Download Windows binaries - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 - with: - name: ${{ needs.sign-packages.outputs.artifact_name }} - path: dist - - name: Generate checksum file - run: cd dist && sha256sum * > "k6-${VERSION}-checksums.txt" - - name: Anchore SBOM Action - continue-on-error: true - uses: anchore/sbom-action@e22c389904149dbc22b58101806040fa8d37a610 # v0.24.0 - with: - artifact-name: k6-${{ env.VERSION }}-spdx.json - upload-release-assets: false - output-file: dist/k6-${{ env.VERSION }}-spdx.json - - name: Create release - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - IS_LATEST_STABLE: ${{ needs.configure.outputs.is_latest_stable }} - IS_PRERELEASE: ${{ needs.configure.outputs.is_prerelease }} - run: | - set -x - assets=() - for asset in ./dist/*; do - assets+=("$asset") - done - # --latest=false prevents pre-releases and maintenance releases on - # older majors from being shown as the "Latest release" on GitHub. - extra_args=( "--latest=${IS_LATEST_STABLE}" ) - if [[ "${IS_PRERELEASE}" == "true" ]]; then - extra_args+=( "--prerelease" ) - fi - gh release create "$VERSION" "${assets[@]}" \ - --target "$GITHUB_SHA" \ - -F "./release notes/${VERSION}.md" \ - "${extra_args[@]}" - - submit-winget-manifest: - needs: [configure, publish-github] - runs-on: windows-2025 - permissions: - contents: read - id-token: write - steps: - - - name: Install WingetCreate - shell: pwsh - run: | - Import-Module Appx -UseWindowsPowerShell - $appxBundleFile = Join-Path ${env:RUNNER_TEMP} "wingetcreate.msixbundle" - Invoke-WebRequest https://aka.ms/wingetcreate/latest/msixbundle -OutFile $appxBundleFile - Add-AppxPackage $appxBundleFile - - - name: Get WinGet token - uses: grafana/shared-workflows/actions/get-vault-secrets@a53fc80bc30b0a16a262520465db899fa3af08b7 # get-vault-secrets/v1.3.2 - id: get-token - with: - export_env: false - common_secrets: | - token=winget-packages:token - - - name: Submit WinGet Manifest - env: - PACKAGE_ID: GrafanaLabs.k6 - PACKAGE_VERSION: ${{ needs.configure.outputs.k6_version }} - WINGET_CREATE_GITHUB_TOKEN: ${{ fromJSON(steps.get-token.outputs.secrets).token }} - shell: pwsh - run: | - wingetcreate token --store - wingetcreate update ${env:PACKAGE_ID} ` - --urls "${env:GITHUB_SERVER_URL}/${env:GITHUB_REPOSITORY}/releases/download/${env:PACKAGE_VERSION}/k6-${env:PACKAGE_VERSION}-windows-amd64.msi" ` - --version ${env:PACKAGE_VERSION}.TrimStart("v") ` - --submit - - publish-packages: - runs-on: ubuntu-latest - needs: [configure, sign-binaries, sign-packages] - if: ${{ github.repository == 'grafana/k6' && (startsWith(github.ref, 'refs/tags/v') && github.event_name != 'workflow_dispatch') }} - env: - VERSION: ${{ needs.configure.outputs.k6_version }} - permissions: - actions: read - contents: read - packages: write - id-token: write # Required for Vault - steps: - - name: Checkout code - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 - with: - persist-credentials: false - - name: Download binaries - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 - with: - name: ${{ needs.sign-binaries.outputs.binary_artifact_name }} - path: dist - - name: Download Windows binaries - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 - with: - name: ${{ needs.sign-packages.outputs.artifact_name }} - path: dist - - name: Rename binaries - # To be consistent with the filenames used in dl.k6.io - run: | - mv "dist/k6-$VERSION-windows-amd64.msi" "dist/k6-$VERSION-amd64.msi" - mv "dist/k6-$VERSION-linux-amd64.rpm" "dist/k6-$VERSION-amd64.rpm" - mv "dist/k6-$VERSION-linux-amd64.deb" "dist/k6-$VERSION-amd64.deb" - - uses: grafana/shared-workflows/actions/get-vault-secrets@a53fc80bc30b0a16a262520465db899fa3af08b7 # get-vault-secrets/v1.3.2 - id: get-secrets - with: - export_env: false - repo_secrets: | - IAM_ROLE_ARN=deploy:packager-iam-role - AWS_CF_DISTRIBUTION=cloudfront:AWS_CF_DISTRIBUTION - PGP_SIGN_KEY_PASSPHRASE=pgp:PGP_SIGN_KEY_PASSPHRASE - PGP_SIGN_KEY=pgp:PGP_SIGN_KEY - S3_BUCKET=s3:AWS_S3_BUCKET - - uses: grafana/shared-workflows/actions/aws-auth@bb04b9b1c3903959957c63d1370b2d49a4b978d0 # aws-auth/v1.0.4 - with: - aws-region: "us-east-2" - role-arn: ${{ fromJSON(steps.get-secrets.outputs.secrets).IAM_ROLE_ARN }} - set-creds-in-environment: true - - name: Setup docker compose environment - env: - AWS_CF_DISTRIBUTION: ${{ fromJSON(steps.get-secrets.outputs.secrets).AWS_CF_DISTRIBUTION }} - PGP_SIGN_KEY_PASSPHRASE: ${{ fromJSON(steps.get-secrets.outputs.secrets).PGP_SIGN_KEY_PASSPHRASE }} - PGP_SIGN_KEY: ${{ fromJSON(steps.get-secrets.outputs.secrets).PGP_SIGN_KEY }} - S3_BUCKET: ${{ fromJSON(steps.get-secrets.outputs.secrets).S3_BUCKET }} - run: | - cat > packaging/.env < packaging/sign-key.gpg - - name: Login to GitHub Container Registry - uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 - env: - GITHUB_ACTOR: ${{ github.actor }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - registry: ghcr.io - username: ${{ env.GITHUB_ACTOR }} - password: ${{ env.GITHUB_TOKEN }} - - name: Publish packages - run: | - cd packaging - docker compose pull packager - docker compose run --rm packager diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml deleted file mode 100644 index 69f8eb20c..000000000 --- a/.github/workflows/codeql-analysis.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: "CodeQL" - -on: - push: - branches: [ master, v1.x ] - -permissions: - contents: read - security-events: write - -jobs: - analyze: - name: Analyze - runs-on: ubuntu-latest - - steps: - - name: Checkout repo - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 - with: - persist-credentials: false - - - name: Initialize CodeQL - uses: github/codeql-action/init@68bde559dea0fdcac2102bfdf6230c5f70eb485e # v4.35.4 - with: - languages: go - - - name: CodeQL Analysis - uses: github/codeql-action/analyze@68bde559dea0fdcac2102bfdf6230c5f70eb485e # v4.35.4 diff --git a/.github/workflows/feature-briefs.yml b/.github/workflows/feature-briefs.yml deleted file mode 100644 index fead9838a..000000000 --- a/.github/workflows/feature-briefs.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: Feature briefs -on: - workflow_dispatch: - pull_request: - paths: - - 'docs/features/**' - -defaults: - run: - shell: bash - -permissions: - contents: read - -jobs: - check-size: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 - with: - persist-credentials: false - fetch-depth: 0 - - name: Validate changed feature briefs - env: - BASE: ${{ github.event.pull_request.base.sha }} - HEAD: ${{ github.event.pull_request.head.sha }} - run: | - files=$(git diff --name-only --diff-filter=AM "$BASE" "$HEAD" -- 'docs/features/*.md' \ - | grep -vE '(README|000-TEMPLATE)\.md$' || true) - if [ -z "$files" ]; then - echo "No feature briefs added or changed in this PR." - exit 0 - fi - echo "Checking:"; echo "$files" - # xargs passes each file as a separate argument to the script - echo "$files" | xargs ./.github/scripts/check-feature-briefs.sh diff --git a/.github/workflows/issue-auto-assign.yml b/.github/workflows/issue-auto-assign.yml deleted file mode 100644 index 1ca95166f..000000000 --- a/.github/workflows/issue-auto-assign.yml +++ /dev/null @@ -1,54 +0,0 @@ -name: "Auto assign maintainer to issue" -on: - # makes this workflow re-usable - workflow_call: - issues: - types: [opened] - issue_comment: - types: [created] - -permissions: - issues: write - -jobs: - assign-user: - runs-on: ubuntu-latest - # issue_comment triggers for both, issues and prs, - # as we need to run only on issues, it filter out prs. - if: ${{ !github.event.issue.pull_request }} - steps: - - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9 - with: - script: | - const assignees = ['ankur22', 'inancgumus', 'joanlopez', 'mstoykov', 'szkiba']; - const teamMembers = assignees.concat(['andrewslotin']); - const assigneeCount = 1; - - // Do not automatically assign users if someone was already assigned or it was opened by a team member - if (context.payload.issue.assignees.length > 0 || teamMembers.includes(context.actor)) { - return; - } - const crypto = require("node:crypto"); - - const getNRandom = (n, array) => { - let result = new Array(); - for (;n > 0 && array.length > 0; n--) { - const chosen = array[crypto.randomInt(array.length)]; - result.push(chosen); - array = array.filter(el => el != chosen); - } - return result; - } - - github.rest.issues.addAssignees({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: context.issue.number, - assignees: getNRandom(assigneeCount, assignees), - }); - github.rest.issues.addLabels({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: context.issue.number, - labels: ["triage"] - }); diff --git a/.github/workflows/lean.yml b/.github/workflows/lean.yml new file mode 100644 index 000000000..0c04faeff --- /dev/null +++ b/.github/workflows/lean.yml @@ -0,0 +1,48 @@ +name: Lean CI + +on: + pull_request: + branches: [master] + push: + branches: [master] + workflow_dispatch: + +permissions: + contents: read + +jobs: + build: + name: Build lean release binaries + runs-on: ubuntu-24.04 + timeout-minutes: 45 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + with: + persist-credentials: false + - uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6 + with: + go-version-file: go.mod + cache: false + - run: ./build-linux-binaries.sh + + test: + name: Test lean fork + runs-on: ubuntu-24.04 + timeout-minutes: 40 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + with: + persist-credentials: false + - uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6 + with: + go-version-file: go.mod + cache: false + - name: Run lean CLI, runtime, transport and output tests + run: | + go test -race -tags lean -p 2 -parallel 2 -timeout 15m \ + ./internal/cmd ./internal/cmd/tests ./internal/api ./internal/js ./internal/features \ + ./internal/js/modules/k6 ./internal/output/breakingit ./lib/netext/httpext ./metrics ./output + - name: Run Chromium group regression tests + run: | + go test -race -tags lean -parallel 1 -timeout 15m \ + -run '^(TestAsyncGroup|TestBrowserGroupTransactionOutcomes)' ./internal/js/modules/k6/browser/tests diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index 7a8343d9c..000000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,50 +0,0 @@ -name: Lint -on: - # Enable manually triggering this workflow via the API or web UI - workflow_dispatch: - pull_request: - paths-ignore: - - 'docs/**' - - 'release notes/**' - -defaults: - run: - shell: bash - -permissions: - contents: read - -jobs: - generate-check: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 - with: - persist-credentials: false - fetch-depth: 0 - - name: Resolve Go versions - id: go_versions - uses: grafana/k6-ci/.github/actions/go-versions@03469f9ae7aad25369827832c456e8f8b7b8c1c2 # v0.5.0 - - name: Install Go - uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6 - with: - # Use Go 1.26 until https://github.com/grafana/k6/issues/6399 is resolved. - go-version: ${{ steps.go_versions.outputs.prev }} - check-latest: true - - name: Check code generation - run: | - make generate - if [ -n "$(git status --porcelain)" ]; then - echo "make generate produced changes:" - git status --porcelain - git --no-pager diff - exit 1 - fi - - k6-ci: - uses: grafana/k6-ci/.github/workflows/all.yml@03469f9ae7aad25369827832c456e8f8b7b8c1c2 # v0.5.0 - with: - k6-ci-ref: 03469f9ae7aad25369827832c456e8f8b7b8c1c2 # v0.5.0 - skip-tests: true - skip-extension-testing: true diff --git a/.github/workflows/publish-techdocs.yaml b/.github/workflows/publish-techdocs.yaml deleted file mode 100644 index deb330aec..000000000 --- a/.github/workflows/publish-techdocs.yaml +++ /dev/null @@ -1,25 +0,0 @@ -name: Publish TechDocs -on: - push: - branches: - - master - paths: - - 'docs/docs/**' - - 'docs/mkdocs.yml' - - 'catalog-info.yaml' - - '.github/workflows/publish-techdocs.yaml' -concurrency: - group: '${{ github.workflow }}-${{ github.ref }}' - cancel-in-progress: true -permissions: {} -jobs: - publish-docs: - uses: grafana/shared-workflows/.github/workflows/publish-techdocs.yaml@86e65f7130d6e52d79f4b56a925b431c4aaea359 # main - permissions: - contents: read - id-token: write - with: - namespace: default - kind: component - name: k6 - default-working-directory: . diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml deleted file mode 100644 index 3d5cd1908..000000000 --- a/.github/workflows/stale.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: Close stale PRs - -on: - schedule: - - cron: "0 8 * * 1" # once per week, at 08:00 on Mondays - -permissions: - pull-requests: write - -jobs: - stale: - runs-on: ubuntu-latest - steps: - - name: Run stale action - uses: actions/stale@1e223db275d687790206a7acac4d1a11bd6fe629 # v10 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - operations-per-run: 50 - ascending: true # process oldest PRs first - - days-before-pr-stale: 61 - days-before-pr-close: 7 - - stale-pr-label: stale - exempt-pr-labels: "wip" - - stale-pr-message: | - This pull request has been automatically marked as stale because it has not had - activity in the last two months. It will be closed in one week if no further activity occurs. Please - feel free to give a status update or ping for review. Thank you for your contributions! - close-pr-message: | - Closing this pull request due to two months of inactivity after being marked stale. Thank you for your contributions! diff --git a/.github/workflows/summary-code-generation.yml b/.github/workflows/summary-code-generation.yml deleted file mode 100644 index 4bbd7fe29..000000000 --- a/.github/workflows/summary-code-generation.yml +++ /dev/null @@ -1,69 +0,0 @@ -name: Summary code generation - -on: - push: - branches: - - master - - v1.x - pull_request: - -defaults: - run: - shell: bash - -permissions: - contents: read - -jobs: - check-generated-code: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 - with: - persist-credentials: false - - - name: Install cog - run: | - COG_VERSION="v0.0.46" - curl -sSL "https://github.com/grafana/cog/releases/download/${COG_VERSION}/cog_Linux_x86_64.tar.gz" \ - | sudo tar -xz -C /usr/local/bin - cog --version - - - name: Checkout schemas - run: | - ./internal/lib/summary/machinereadable/checkout.sh - - - name: Generate code - run: | - ./internal/lib/summary/machinereadable/generate.sh - - - name: Check for uncommitted changes - run: | - # Check if there are any changes in the Git working directory - if ! git diff --exit-code; then - echo "❌ Generated code is not up-to-date!" - echo "" - echo "The following files have uncommitted changes:" - git diff --name-only - echo "" - echo "Please run the following commands to update the generated code:" - echo " ./internal/lib/summary/machinereadable/checkout.sh" - echo " ./internal/lib/summary/machinereadable/generate.sh" - echo "" - echo "Then commit the changes." - exit 1 - fi - - # Also check for untracked files - if [ -n "$(git ls-files --others --exclude-standard internal/lib/summary/machinereadable/ | grep -v k6-summary/)" ]; then - echo "❌ There are untracked generated files!" - echo "" - echo "Untracked files:" - git ls-files --others --exclude-standard internal/lib/summary/machinereadable/ | grep -v k6-summary/ - echo "" - echo "Please run the generation scripts and commit all generated files." - exit 1 - fi - - echo "✅ Generated code is up-to-date!" diff --git a/.github/workflows/tc39.yml b/.github/workflows/tc39.yml deleted file mode 100644 index e488aa4a4..000000000 --- a/.github/workflows/tc39.yml +++ /dev/null @@ -1,44 +0,0 @@ -name: TC39 -on: - workflow_dispatch: - push: - branches: - - master - - v1.x - pull_request: - paths: - - 'js/**' - - 'internal/js/**' - - 'vendor/github.com/grafana/sobek/**' - - 'vendor/github.com/evanw/esbuild**' - -defaults: - run: - shell: bash - -permissions: - contents: read - - -jobs: - tc39: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 - with: - persist-credentials: false - - name: Resolve Go versions - id: go_versions - uses: grafana/k6-ci/.github/actions/go-versions@03469f9ae7aad25369827832c456e8f8b7b8c1c2 # v0.5.0 - - name: Install Go - uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6 - with: - go-version: ${{ steps.go_versions.outputs.current }} - check-latest: true - - name: Run tests - run: | - set -x - cd internal/js/tc39 - sh checkout.sh - go test -timeout 1h diff --git a/.github/workflows/test-browser.yml b/.github/workflows/test-browser.yml deleted file mode 100644 index 5176bede4..000000000 --- a/.github/workflows/test-browser.yml +++ /dev/null @@ -1,109 +0,0 @@ -name: Browser tests -on: - push: - branches: - - master - - v.x - pull_request: - paths-ignore: - - 'docs/**' - - 'release notes/**' - -defaults: - run: - shell: bash - -permissions: - contents: read - -jobs: - configure: - runs-on: ubuntu-latest - outputs: - go_current: ${{ steps.go_versions.outputs.current }} - go_prev: ${{ steps.go_versions.outputs.prev }} - steps: - - name: Resolve Go versions - id: go_versions - uses: grafana/k6-ci/.github/actions/go-versions@03469f9ae7aad25369827832c456e8f8b7b8c1c2 # v0.5.0 - - test-prev: - needs: configure - if: ${{ github.ref == 'refs/heads/master' }} - strategy: - fail-fast: false - matrix: - go-version: ["${{ needs.configure.outputs.go_prev }}"] - platform: - [ubuntu-24.04, ubuntu-arm64-large, github-hosted-windows-x64-large] - runs-on: ${{ matrix.platform }} - steps: - - name: Checkout code - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 - with: - fetch-depth: 0 - persist-credentials: false - - name: Run common test steps - uses: ./.github/actions/test-common - with: - go_version: ${{ matrix.go-version }} - platform: ${{ matrix.platform }} - github_token: ${{ secrets.GITHUB_TOKEN }} - - name: Get the k6 version - id: get_k6_version - run: | - echo "Running tests on '${GITHUB_REF}' with '$(git describe --tags --always --long --dirty)' checked out..." - - name: Run tests - uses: ./.github/actions/test-browser - - test-tip: - strategy: - fail-fast: false - matrix: - include: - - platform: ubuntu-24.04 - gotip_platform: ubuntu-24.04 - - platform: ubuntu-arm64-large - gotip_platform: ubuntu-24.04-arm - - platform: github-hosted-windows-x64-large - gotip_platform: windows-latest - runs-on: ${{ matrix.platform }} - continue-on-error: true - steps: - - name: Checkout code - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 - with: - persist-credentials: false - - name: Run common test steps - uses: ./.github/actions/test-common - with: - go_version: "gotip" - platform: ${{ matrix.gotip_platform }} - github_token: ${{ secrets.GITHUB_TOKEN }} - - name: Run tests - uses: ./.github/actions/test-browser - with: - use_gotip: "true" - - test-latest: - needs: configure - strategy: - fail-fast: false - matrix: - go-version: ["${{ needs.configure.outputs.go_current }}"] - platform: - [ubuntu-24.04, ubuntu-arm64-large, github-hosted-windows-x64-large] - runs-on: ${{ matrix.platform }} - steps: - - name: Checkout code - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 - with: - persist-credentials: false - - name: Run common test steps - uses: ./.github/actions/test-common - with: - go_version: ${{ matrix.go-version }} - platform: ${{ matrix.platform }} - github_token: ${{ secrets.GITHUB_TOKEN }} - - name: Run tests - uses: ./.github/actions/test-browser diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index 41e89c9f2..000000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,106 +0,0 @@ -name: Test -on: - push: - branches: - - master - - v1.x - pull_request: - paths-ignore: - - 'docs/**' - - 'release notes/**' - -defaults: - run: - shell: bash - -permissions: - contents: read - -jobs: - configure: - runs-on: ubuntu-latest - outputs: - go_current: ${{ steps.go_versions.outputs.current }} - go_prev: ${{ steps.go_versions.outputs.prev }} - steps: - - name: Resolve Go versions - id: go_versions - uses: grafana/k6-ci/.github/actions/go-versions@03469f9ae7aad25369827832c456e8f8b7b8c1c2 # v0.5.0 - - test-prev: - needs: configure - if: ${{ github.ref == 'refs/heads/master' }} - strategy: - fail-fast: false - matrix: - go-version: ["${{ needs.configure.outputs.go_prev }}"] - platform: [ubuntu-24.04, ubuntu-24.04-arm, windows-latest] - runs-on: ${{ matrix.platform }} - steps: - - name: Checkout code - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 - with: - fetch-depth: 0 - persist-credentials: false - - name: Run common test steps - uses: ./.github/actions/test-common - with: - go_version: ${{ matrix.go-version }} - platform: ${{ matrix.platform }} - github_token: ${{ secrets.GITHUB_TOKEN }} - - name: Get the k6 version - id: get_k6_version - run: | - echo "Running tests on '${GITHUB_REF}' with '$(git describe --tags --always --long --dirty)' checked out..." - - name: Run tests - uses: ./.github/actions/test - with: - platform: ${{ matrix.platform }} - - test-tip: - strategy: - fail-fast: false - matrix: - platform: [ubuntu-24.04, ubuntu-24.04-arm, windows-latest] - runs-on: ${{ matrix.platform }} - continue-on-error: true - steps: - - name: Checkout code - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 - with: - persist-credentials: false - - name: Run common test steps - uses: ./.github/actions/test-common - with: - go_version: "gotip" - platform: ${{ matrix.platform }} - github_token: ${{ secrets.GITHUB_TOKEN }} - - name: Run tests - uses: ./.github/actions/test - with: - use_gotip: "true" - platform: ${{ matrix.platform }} - - test-latest: - needs: configure - strategy: - fail-fast: false - matrix: - go-version: ["${{ needs.configure.outputs.go_current }}"] - platform: [ubuntu-24.04, ubuntu-24.04-arm, windows-latest] - runs-on: ${{ matrix.platform }} - steps: - - name: Checkout code - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 - with: - persist-credentials: false - - name: Run common test steps - uses: ./.github/actions/test-common - with: - go_version: ${{ matrix.go-version }} - platform: ${{ matrix.platform }} - github_token: ${{ secrets.GITHUB_TOKEN }} - - name: Run tests - uses: ./.github/actions/test - with: - platform: ${{ matrix.platform }} diff --git a/.github/workflows/wpt.yml b/.github/workflows/wpt.yml deleted file mode 100644 index 67a0a4f6a..000000000 --- a/.github/workflows/wpt.yml +++ /dev/null @@ -1,44 +0,0 @@ -name: Web Platform Tests -on: - workflow_dispatch: - pull_request: - paths-ignore: - - 'docs/**' - - 'release notes/**' - -defaults: - run: - shell: bash - -permissions: - contents: read - -jobs: - test: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 - with: - persist-credentials: false - - name: Resolve Go versions - id: go_versions - uses: grafana/k6-ci/.github/actions/go-versions@03469f9ae7aad25369827832c456e8f8b7b8c1c2 # v0.5.0 - - name: Install Go - uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6 - with: - go-version: ${{ steps.go_versions.outputs.current }} - check-latest: true - # TODO: combine WebPlatform tests checkout & patch into the single step - - name: Run Streams Tests - run: | - set -x - cd internal/js/modules/k6/experimental/streams/tests - sh checkout.sh - go test -race ../... - - name: Run Webcrypto Tests - run: | - set -x - cd internal/js/modules/k6/webcrypto/tests - sh checkout.sh - go test -race ./... diff --git a/.github/workflows/xk6-tests/xk6-js-test/go.mod b/.github/workflows/xk6-tests/xk6-js-test/go.mod deleted file mode 100644 index af874f432..000000000 --- a/.github/workflows/xk6-tests/xk6-js-test/go.mod +++ /dev/null @@ -1,48 +0,0 @@ -module github.com/grafana/xk6-js-test - -go 1.25.10 - -require go.k6.io/k6/v2 v2.0.0-20260424133653-c3427b0487c8 - -require ( - github.com/cenkalti/backoff/v5 v5.0.3 // indirect - github.com/cespare/xxhash/v2 v2.3.0 // indirect - github.com/dlclark/regexp2 v1.11.5 // indirect - github.com/evanw/esbuild v0.28.0 // indirect - github.com/fatih/color v1.19.0 // indirect - github.com/fsnotify/fsnotify v1.4.9 // indirect - github.com/go-logr/logr v1.4.3 // indirect - github.com/go-logr/stdr v1.2.2 // indirect - github.com/go-sourcemap/sourcemap v2.1.4+incompatible // indirect - github.com/google/pprof v0.0.0-20260115054156-294ebfa9ad83 // indirect - github.com/google/uuid v1.6.0 // indirect - github.com/grafana/sobek v0.0.0-20260331145705-2272ac4993ef // indirect - github.com/grpc-ecosystem/grpc-gateway/v2 v2.28.0 // indirect - github.com/josharian/intern v1.0.0 // indirect - github.com/mailru/easyjson v0.9.2 // indirect - github.com/mattn/go-colorable v0.1.14 // indirect - github.com/mattn/go-isatty v0.0.21 // indirect - github.com/mstoykov/atlas v0.0.0-20220811071828-388f114305dd // indirect - github.com/serenize/snaker v0.0.0-20201027110005-a7ad2135616e // indirect - github.com/sirupsen/logrus v1.9.3 // indirect - github.com/spf13/afero v1.1.2 // indirect - go.opentelemetry.io/auto/sdk v1.2.1 // indirect - go.opentelemetry.io/otel v1.43.0 // indirect - go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.43.0 // indirect - go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.42.0 // indirect - go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.43.0 // indirect - go.opentelemetry.io/otel/metric v1.43.0 // indirect - go.opentelemetry.io/otel/sdk v1.43.0 // indirect - go.opentelemetry.io/otel/trace v1.43.0 // indirect - go.opentelemetry.io/proto/otlp v1.10.0 // indirect - golang.org/x/net v0.53.0 // indirect - golang.org/x/sys v0.43.0 // indirect - golang.org/x/text v0.36.0 // indirect - golang.org/x/time v0.15.0 // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20260401024825-9d38bb4040a9 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20260401024825-9d38bb4040a9 // indirect - google.golang.org/grpc v1.80.0 // indirect - google.golang.org/protobuf v1.36.11 // indirect - gopkg.in/guregu/null.v3 v3.3.0 // indirect - gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect -) diff --git a/.github/workflows/xk6-tests/xk6-js-test/go.sum b/.github/workflows/xk6-tests/xk6-js-test/go.sum deleted file mode 100644 index ce8b91c4d..000000000 --- a/.github/workflows/xk6-tests/xk6-js-test/go.sum +++ /dev/null @@ -1,128 +0,0 @@ -github.com/andybalholm/brotli v1.2.1 h1:R+f5xP285VArJDRgowrfb9DqL18yVK0gKAW/F+eTWro= -github.com/andybalholm/brotli v1.2.1/go.mod h1:rzTDkvFWvIrjDXZHkuS16NPggd91W3kUSvPlQ1pLaKY= -github.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1xcsSM= -github.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw= -github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= -github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dlclark/regexp2 v1.11.5 h1:Q/sSnsKerHeCkc/jSTNq1oCm7KiVgUMZRDUoRu0JQZQ= -github.com/dlclark/regexp2 v1.11.5/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= -github.com/evanw/esbuild v0.28.0 h1:V96ghtc5p5JnNUQIUsc5H3kr+AcFcMqOJll2ZmJW6Lo= -github.com/evanw/esbuild v0.28.0/go.mod h1:D2vIQZqV/vIf/VRHtViaUtViZmG7o+kKmlBfVQuRi48= -github.com/fatih/color v1.19.0 h1:Zp3PiM21/9Ld6FzSKyL5c/BULoe/ONr9KlbYVOfG8+w= -github.com/fatih/color v1.19.0/go.mod h1:zNk67I0ZUT1bEGsSGyCZYZNrHuTkJJB+r6Q9VuMi0LE= -github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= -github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= -github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI= -github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= -github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= -github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= -github.com/go-sourcemap/sourcemap v2.1.4+incompatible h1:a+iTbH5auLKxaNwQFg0B+TCYl6lbukKPc7b5x0n1s6Q= -github.com/go-sourcemap/sourcemap v2.1.4+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg= -github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= -github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= -github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= -github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= -github.com/google/pprof v0.0.0-20260115054156-294ebfa9ad83 h1:z2ogiKUYzX5Is6zr/vP9vJGqPwcdqsWjOt+V8J7+bTc= -github.com/google/pprof v0.0.0-20260115054156-294ebfa9ad83/go.mod h1:MxpfABSjhmINe3F1It9d+8exIHFvUqtLIRCdOGNXqiI= -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/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= -github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/grafana/sobek v0.0.0-20260331145705-2272ac4993ef h1:onLtCR9w3Iqn57s39rYf1PtRl89uSznaM36TKcepxn4= -github.com/grafana/sobek v0.0.0-20260331145705-2272ac4993ef/go.mod h1:YtuqiJX1W3XvRSilL/kUZzduJG3phPJWyzM9DiIEfBo= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.28.0 h1:HWRh5R2+9EifMyIHV7ZV+MIZqgz+PMpZ14Jynv3O2Zs= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.28.0/go.mod h1:JfhWUomR1baixubs02l85lZYYOm7LV6om4ceouMv45c= -github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= -github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= -github.com/klauspost/compress v1.18.5 h1:/h1gH5Ce+VWNLSWqPzOVn6XBO+vJbCNGvjoaGBFW2IE= -github.com/klauspost/compress v1.18.5/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ= -github.com/mailru/easyjson v0.9.2 h1:dX8U45hQsZpxd80nLvDGihsQ/OxlvTkVUXH2r/8cb2M= -github.com/mailru/easyjson v0.9.2/go.mod h1:1+xMtQp2MRNVL/V1bOzuP3aP8VNwRW55fQUto+XFtTU= -github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE= -github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8= -github.com/mattn/go-isatty v0.0.21 h1:xYae+lCNBP7QuW4PUnNG61ffM4hVIfm+zUzDuSzYLGs= -github.com/mattn/go-isatty v0.0.21/go.mod h1:ZXfXG4SQHsB/w3ZeOYbR0PrPwLy+n6xiMrJlRFqopa4= -github.com/mccutchen/go-httpbin/v2 v2.20.0 h1:iMUzhdbAcjo9hepfG5W3hz1yWAyxiYlJMzKQtwyGDms= -github.com/mccutchen/go-httpbin/v2 v2.20.0/go.mod h1:GBy5I7XwZ4ZLhT3hcq39I4ikwN9x4QUt6EAxNiR8Jus= -github.com/mstoykov/atlas v0.0.0-20220811071828-388f114305dd h1:AC3N94irbx2kWGA8f/2Ks7EQl2LxKIRQYuT9IJDwgiI= -github.com/mstoykov/atlas v0.0.0-20220811071828-388f114305dd/go.mod h1:9vRHVuLCjoFfE3GT06X0spdOAO+Zzo4AMjdIwUHBvAk= -github.com/mstoykov/envconfig v1.5.0 h1:E2FgWf73BQt0ddgn7aoITkQHmgwAcHup1s//MsS5/f8= -github.com/mstoykov/envconfig v1.5.0/go.mod h1:vk/d9jpexY2Z9Bb0uB4Ndesss1Sr0Z9ZiGUrg5o9VGk= -github.com/nxadm/tail v1.4.11 h1:8feyoE3OzPrcshW5/MJ4sGESc5cqmGkGCWlco4l0bqY= -github.com/nxadm/tail v1.4.11/go.mod h1:OTaG3NK980DZzxbRq6lEuzgU+mug70nY11sMd4JXXHc= -github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= -github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= -github.com/onsi/gomega v1.39.1 h1:1IJLAad4zjPn2PsnhH70V4DKRFlrCzGBNrNaru+Vf28= -github.com/onsi/gomega v1.39.1/go.mod h1:hL6yVALoTOxeWudERyfppUcZXjMwIMLnuSfruD2lcfg= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/serenize/snaker v0.0.0-20201027110005-a7ad2135616e h1:zWKUYT07mGmVBH+9UgnHXd/ekCK99C8EbDSAt5qsjXE= -github.com/serenize/snaker v0.0.0-20201027110005-a7ad2135616e/go.mod h1:Yow6lPLSAXx2ifx470yD/nUe22Dv5vBvxK/UK9UUTVs= -github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= -github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= -github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI= -github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= -github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= -go.k6.io/k6/v2 v2.0.0-20260424133653-c3427b0487c8 h1:I3utcXRVcS15XNk7pcOR5Ufofup3A3Tt3yJD1pA6RBc= -go.k6.io/k6/v2 v2.0.0-20260424133653-c3427b0487c8/go.mod h1:eLG4XT8rbibmfnjn7N+a4c4+0tUi3+8zbox58DMp9WU= -go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64= -go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y= -go.opentelemetry.io/otel v1.43.0 h1:mYIM03dnh5zfN7HautFE4ieIig9amkNANT+xcVxAj9I= -go.opentelemetry.io/otel v1.43.0/go.mod h1:JuG+u74mvjvcm8vj8pI5XiHy1zDeoCS2LB1spIq7Ay0= -go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.43.0 h1:88Y4s2C8oTui1LGM6bTWkw0ICGcOLCAI5l6zsD1j20k= -go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.43.0/go.mod h1:Vl1/iaggsuRlrHf/hfPJPvVag77kKyvrLeD10kpMl+A= -go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.42.0 h1:zWWrB1U6nqhS/k6zYB74CjRpuiitRtLLi68VcgmOEto= -go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.42.0/go.mod h1:2qXPNBX1OVRC0IwOnfo1ljoid+RD0QK3443EaqVlsOU= -go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.43.0 h1:3iZJKlCZufyRzPzlQhUIWVmfltrXuGyfjREgGP3UUjc= -go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.43.0/go.mod h1:/G+nUPfhq2e+qiXMGxMwumDrP5jtzU+mWN7/sjT2rak= -go.opentelemetry.io/otel/metric v1.43.0 h1:d7638QeInOnuwOONPp4JAOGfbCEpYb+K6DVWvdxGzgM= -go.opentelemetry.io/otel/metric v1.43.0/go.mod h1:RDnPtIxvqlgO8GRW18W6Z/4P462ldprJtfxHxyKd2PY= -go.opentelemetry.io/otel/sdk v1.43.0 h1:pi5mE86i5rTeLXqoF/hhiBtUNcrAGHLKQdhg4h4V9Dg= -go.opentelemetry.io/otel/sdk v1.43.0/go.mod h1:P+IkVU3iWukmiit/Yf9AWvpyRDlUeBaRg6Y+C58QHzg= -go.opentelemetry.io/otel/sdk/metric v1.43.0 h1:S88dyqXjJkuBNLeMcVPRFXpRw2fuwdvfCGLEo89fDkw= -go.opentelemetry.io/otel/sdk/metric v1.43.0/go.mod h1:C/RJtwSEJ5hzTiUz5pXF1kILHStzb9zFlIEe85bhj6A= -go.opentelemetry.io/otel/trace v1.43.0 h1:BkNrHpup+4k4w+ZZ86CZoHHEkohws8AY+WTX09nk+3A= -go.opentelemetry.io/otel/trace v1.43.0/go.mod h1:/QJhyVBUUswCphDVxq+8mld+AvhXZLhe+8WVFxiFff0= -go.opentelemetry.io/proto/otlp v1.10.0 h1:IQRWgT5srOCYfiWnpqUYz9CVmbO8bFmKcwYxpuCSL2g= -go.opentelemetry.io/proto/otlp v1.10.0/go.mod h1:/CV4QoCR/S9yaPj8utp3lvQPoqMtxXdzn7ozvvozVqk= -go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= -go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= -go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc= -go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= -golang.org/x/crypto v0.50.0 h1:zO47/JPrL6vsNkINmLoo/PH1gcxpls50DNogFvB5ZGI= -golang.org/x/crypto v0.50.0/go.mod h1:3muZ7vA7PBCE6xgPX7nkzzjiUq87kRItoJQM1Yo8S+Q= -golang.org/x/net v0.53.0 h1:d+qAbo5L0orcWAr0a9JweQpjXF19LMXJE8Ey7hwOdUA= -golang.org/x/net v0.53.0/go.mod h1:JvMuJH7rrdiCfbeHoo3fCQU24Lf5JJwT9W3sJFulfgs= -golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.43.0 h1:Rlag2XtaFTxp19wS8MXlJwTvoh8ArU6ezoyFsMyCTNI= -golang.org/x/sys v0.43.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= -golang.org/x/text v0.36.0 h1:JfKh3XmcRPqZPKevfXVpI1wXPTqbkE5f7JA92a55Yxg= -golang.org/x/text v0.36.0/go.mod h1:NIdBknypM8iqVmPiuco0Dh6P5Jcdk8lJL0CUebqK164= -golang.org/x/time v0.15.0 h1:bbrp8t3bGUeFOx08pvsMYRTCVSMk89u4tKbNOZbp88U= -golang.org/x/time v0.15.0/go.mod h1:Y4YMaQmXwGQZoFaVFk4YpCt4FLQMYKZe9oeV/f4MSno= -gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4= -gonum.org/v1/gonum v0.17.0/go.mod h1:El3tOrEuMpv2UdMrbNlKEh9vd86bmQ6vqIcDwxEOc1E= -google.golang.org/genproto/googleapis/api v0.0.0-20260401024825-9d38bb4040a9 h1:VPWxll4HlMw1Vs/qXtN7BvhZqsS9cdAittCNvVENElA= -google.golang.org/genproto/googleapis/api v0.0.0-20260401024825-9d38bb4040a9/go.mod h1:7QBABkRtR8z+TEnmXTqIqwJLlzrZKVfAUm7tY3yGv0M= -google.golang.org/genproto/googleapis/rpc v0.0.0-20260401024825-9d38bb4040a9 h1:m8qni9SQFH0tJc1X0vmnpw/0t+AImlSvp30sEupozUg= -google.golang.org/genproto/googleapis/rpc v0.0.0-20260401024825-9d38bb4040a9/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8= -google.golang.org/grpc v1.80.0 h1:Xr6m2WmWZLETvUNvIUmeD5OAagMw3FiKmMlTdViWsHM= -google.golang.org/grpc v1.80.0/go.mod h1:ho/dLnxwi3EDJA4Zghp7k2Ec1+c2jqup0bFkw07bwF4= -google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE= -google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/guregu/null.v3 v3.3.0 h1:8j3ggqq+NgKt/O7mbFVUFKUMWN+l1AmT5jQmJ6nPh2c= -gopkg.in/guregu/null.v3 v3.3.0/go.mod h1:E4tX2Qe3h7QdL+uZ3a0vqvYwKQsRSQKM5V4YltdgH9Y= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/.github/workflows/xk6-tests/xk6-js-test/jstest.go b/.github/workflows/xk6-tests/xk6-js-test/jstest.go deleted file mode 100644 index 9c075d98b..000000000 --- a/.github/workflows/xk6-tests/xk6-js-test/jstest.go +++ /dev/null @@ -1,69 +0,0 @@ -package jstest - -import ( - "fmt" - "time" - - "go.k6.io/k6/v2/js/modules" - "go.k6.io/k6/v2/metrics" -) - -func init() { - modules.Register("k6/x/jsexttest", New()) -} - -type ( - RootModule struct{} - - // JSTest is meant to test xk6 and the JS extension sub-system of k6. - JSTest struct { - vu modules.VU - - foos *metrics.Metric - } -) - -// Ensure the interfaces are implemented correctly. -var ( - _ modules.Module = &RootModule{} - _ modules.Instance = &JSTest{} -) - -// New returns a pointer to a new RootModule instance. -func New() *RootModule { - return &RootModule{} -} - -// NewModuleInstance implements the modules.Module interface and returns -// a new instance for each VU. -func (*RootModule) NewModuleInstance(vu modules.VU) modules.Instance { - return &JSTest{ - vu: vu, - foos: vu.InitEnv().Registry.MustNewMetric("foos", metrics.Counter), - } -} - -// Exports implements the modules.Instance interface and returns the exports -// of the JS module. -func (j *JSTest) Exports() modules.Exports { - return modules.Exports{Default: j} -} - -// Foo emits a foo metric -func (j *JSTest) Foo(arg float64) (bool, error) { - state := j.vu.State() - if state == nil { - return false, fmt.Errorf("the VU State is not available in the init context") - } - - ctx := j.vu.Context() - - tags := state.Tags.GetCurrentValues().Tags.With("foo", "bar") - metrics.PushIfNotDone(ctx, state.Samples, metrics.Sample{ - Time: time.Now(), - TimeSeries: metrics.TimeSeries{Metric: j.foos, Tags: tags}, - Value: arg, - }) - - return true, nil -} diff --git a/.github/workflows/xk6-tests/xk6-output-test/go.mod b/.github/workflows/xk6-tests/xk6-output-test/go.mod deleted file mode 100644 index 1e3fd4747..000000000 --- a/.github/workflows/xk6-tests/xk6-output-test/go.mod +++ /dev/null @@ -1,40 +0,0 @@ -module github.com/grafana/xk6-output-test - -go 1.25.10 - -require go.k6.io/k6/v2 v2.0.0-20260424133653-c3427b0487c8 - -require ( - github.com/cenkalti/backoff/v5 v5.0.3 // indirect - github.com/cespare/xxhash/v2 v2.3.0 // indirect - github.com/fatih/color v1.19.0 // indirect - github.com/go-logr/logr v1.4.3 // indirect - github.com/go-logr/stdr v1.2.2 // indirect - github.com/google/uuid v1.6.0 // indirect - github.com/grpc-ecosystem/grpc-gateway/v2 v2.28.0 // indirect - github.com/josharian/intern v1.0.0 // indirect - github.com/mailru/easyjson v0.9.2 // indirect - github.com/mattn/go-colorable v0.1.14 // indirect - github.com/mattn/go-isatty v0.0.21 // indirect - github.com/mstoykov/atlas v0.0.0-20220811071828-388f114305dd // indirect - github.com/sirupsen/logrus v1.9.3 // indirect - github.com/spf13/afero v1.1.2 // indirect - go.opentelemetry.io/auto/sdk v1.2.1 // indirect - go.opentelemetry.io/otel v1.43.0 // indirect - go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.43.0 // indirect - go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.42.0 // indirect - go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.43.0 // indirect - go.opentelemetry.io/otel/metric v1.43.0 // indirect - go.opentelemetry.io/otel/sdk v1.43.0 // indirect - go.opentelemetry.io/otel/trace v1.43.0 // indirect - go.opentelemetry.io/proto/otlp v1.10.0 // indirect - golang.org/x/net v0.53.0 // indirect - golang.org/x/sys v0.43.0 // indirect - golang.org/x/text v0.36.0 // indirect - golang.org/x/time v0.15.0 // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20260401024825-9d38bb4040a9 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20260401024825-9d38bb4040a9 // indirect - google.golang.org/grpc v1.80.0 // indirect - google.golang.org/protobuf v1.36.11 // indirect - gopkg.in/guregu/null.v3 v3.3.0 // indirect -) diff --git a/.github/workflows/xk6-tests/xk6-output-test/go.sum b/.github/workflows/xk6-tests/xk6-output-test/go.sum deleted file mode 100644 index 2dfb53833..000000000 --- a/.github/workflows/xk6-tests/xk6-output-test/go.sum +++ /dev/null @@ -1,103 +0,0 @@ -github.com/andybalholm/brotli v1.2.1 h1:R+f5xP285VArJDRgowrfb9DqL18yVK0gKAW/F+eTWro= -github.com/andybalholm/brotli v1.2.1/go.mod h1:rzTDkvFWvIrjDXZHkuS16NPggd91W3kUSvPlQ1pLaKY= -github.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1xcsSM= -github.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw= -github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= -github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/fatih/color v1.19.0 h1:Zp3PiM21/9Ld6FzSKyL5c/BULoe/ONr9KlbYVOfG8+w= -github.com/fatih/color v1.19.0/go.mod h1:zNk67I0ZUT1bEGsSGyCZYZNrHuTkJJB+r6Q9VuMi0LE= -github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI= -github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= -github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= -github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= -github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= -github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= -github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= -github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= -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/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= -github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.28.0 h1:HWRh5R2+9EifMyIHV7ZV+MIZqgz+PMpZ14Jynv3O2Zs= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.28.0/go.mod h1:JfhWUomR1baixubs02l85lZYYOm7LV6om4ceouMv45c= -github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= -github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= -github.com/klauspost/compress v1.18.5 h1:/h1gH5Ce+VWNLSWqPzOVn6XBO+vJbCNGvjoaGBFW2IE= -github.com/klauspost/compress v1.18.5/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ= -github.com/mailru/easyjson v0.9.2 h1:dX8U45hQsZpxd80nLvDGihsQ/OxlvTkVUXH2r/8cb2M= -github.com/mailru/easyjson v0.9.2/go.mod h1:1+xMtQp2MRNVL/V1bOzuP3aP8VNwRW55fQUto+XFtTU= -github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE= -github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8= -github.com/mattn/go-isatty v0.0.21 h1:xYae+lCNBP7QuW4PUnNG61ffM4hVIfm+zUzDuSzYLGs= -github.com/mattn/go-isatty v0.0.21/go.mod h1:ZXfXG4SQHsB/w3ZeOYbR0PrPwLy+n6xiMrJlRFqopa4= -github.com/mccutchen/go-httpbin/v2 v2.20.0 h1:iMUzhdbAcjo9hepfG5W3hz1yWAyxiYlJMzKQtwyGDms= -github.com/mccutchen/go-httpbin/v2 v2.20.0/go.mod h1:GBy5I7XwZ4ZLhT3hcq39I4ikwN9x4QUt6EAxNiR8Jus= -github.com/mstoykov/atlas v0.0.0-20220811071828-388f114305dd h1:AC3N94irbx2kWGA8f/2Ks7EQl2LxKIRQYuT9IJDwgiI= -github.com/mstoykov/atlas v0.0.0-20220811071828-388f114305dd/go.mod h1:9vRHVuLCjoFfE3GT06X0spdOAO+Zzo4AMjdIwUHBvAk= -github.com/mstoykov/envconfig v1.5.0 h1:E2FgWf73BQt0ddgn7aoITkQHmgwAcHup1s//MsS5/f8= -github.com/mstoykov/envconfig v1.5.0/go.mod h1:vk/d9jpexY2Z9Bb0uB4Ndesss1Sr0Z9ZiGUrg5o9VGk= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= -github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= -github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI= -github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= -github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= -go.k6.io/k6/v2 v2.0.0-20260424133653-c3427b0487c8 h1:I3utcXRVcS15XNk7pcOR5Ufofup3A3Tt3yJD1pA6RBc= -go.k6.io/k6/v2 v2.0.0-20260424133653-c3427b0487c8/go.mod h1:eLG4XT8rbibmfnjn7N+a4c4+0tUi3+8zbox58DMp9WU= -go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64= -go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y= -go.opentelemetry.io/otel v1.43.0 h1:mYIM03dnh5zfN7HautFE4ieIig9amkNANT+xcVxAj9I= -go.opentelemetry.io/otel v1.43.0/go.mod h1:JuG+u74mvjvcm8vj8pI5XiHy1zDeoCS2LB1spIq7Ay0= -go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.43.0 h1:88Y4s2C8oTui1LGM6bTWkw0ICGcOLCAI5l6zsD1j20k= -go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.43.0/go.mod h1:Vl1/iaggsuRlrHf/hfPJPvVag77kKyvrLeD10kpMl+A= -go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.42.0 h1:zWWrB1U6nqhS/k6zYB74CjRpuiitRtLLi68VcgmOEto= -go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.42.0/go.mod h1:2qXPNBX1OVRC0IwOnfo1ljoid+RD0QK3443EaqVlsOU= -go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.43.0 h1:3iZJKlCZufyRzPzlQhUIWVmfltrXuGyfjREgGP3UUjc= -go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.43.0/go.mod h1:/G+nUPfhq2e+qiXMGxMwumDrP5jtzU+mWN7/sjT2rak= -go.opentelemetry.io/otel/metric v1.43.0 h1:d7638QeInOnuwOONPp4JAOGfbCEpYb+K6DVWvdxGzgM= -go.opentelemetry.io/otel/metric v1.43.0/go.mod h1:RDnPtIxvqlgO8GRW18W6Z/4P462ldprJtfxHxyKd2PY= -go.opentelemetry.io/otel/sdk v1.43.0 h1:pi5mE86i5rTeLXqoF/hhiBtUNcrAGHLKQdhg4h4V9Dg= -go.opentelemetry.io/otel/sdk v1.43.0/go.mod h1:P+IkVU3iWukmiit/Yf9AWvpyRDlUeBaRg6Y+C58QHzg= -go.opentelemetry.io/otel/sdk/metric v1.43.0 h1:S88dyqXjJkuBNLeMcVPRFXpRw2fuwdvfCGLEo89fDkw= -go.opentelemetry.io/otel/sdk/metric v1.43.0/go.mod h1:C/RJtwSEJ5hzTiUz5pXF1kILHStzb9zFlIEe85bhj6A= -go.opentelemetry.io/otel/trace v1.43.0 h1:BkNrHpup+4k4w+ZZ86CZoHHEkohws8AY+WTX09nk+3A= -go.opentelemetry.io/otel/trace v1.43.0/go.mod h1:/QJhyVBUUswCphDVxq+8mld+AvhXZLhe+8WVFxiFff0= -go.opentelemetry.io/proto/otlp v1.10.0 h1:IQRWgT5srOCYfiWnpqUYz9CVmbO8bFmKcwYxpuCSL2g= -go.opentelemetry.io/proto/otlp v1.10.0/go.mod h1:/CV4QoCR/S9yaPj8utp3lvQPoqMtxXdzn7ozvvozVqk= -go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= -go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= -golang.org/x/crypto v0.50.0 h1:zO47/JPrL6vsNkINmLoo/PH1gcxpls50DNogFvB5ZGI= -golang.org/x/crypto v0.50.0/go.mod h1:3muZ7vA7PBCE6xgPX7nkzzjiUq87kRItoJQM1Yo8S+Q= -golang.org/x/net v0.53.0 h1:d+qAbo5L0orcWAr0a9JweQpjXF19LMXJE8Ey7hwOdUA= -golang.org/x/net v0.53.0/go.mod h1:JvMuJH7rrdiCfbeHoo3fCQU24Lf5JJwT9W3sJFulfgs= -golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.43.0 h1:Rlag2XtaFTxp19wS8MXlJwTvoh8ArU6ezoyFsMyCTNI= -golang.org/x/sys v0.43.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= -golang.org/x/text v0.36.0 h1:JfKh3XmcRPqZPKevfXVpI1wXPTqbkE5f7JA92a55Yxg= -golang.org/x/text v0.36.0/go.mod h1:NIdBknypM8iqVmPiuco0Dh6P5Jcdk8lJL0CUebqK164= -golang.org/x/time v0.15.0 h1:bbrp8t3bGUeFOx08pvsMYRTCVSMk89u4tKbNOZbp88U= -golang.org/x/time v0.15.0/go.mod h1:Y4YMaQmXwGQZoFaVFk4YpCt4FLQMYKZe9oeV/f4MSno= -gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4= -gonum.org/v1/gonum v0.17.0/go.mod h1:El3tOrEuMpv2UdMrbNlKEh9vd86bmQ6vqIcDwxEOc1E= -google.golang.org/genproto/googleapis/api v0.0.0-20260401024825-9d38bb4040a9 h1:VPWxll4HlMw1Vs/qXtN7BvhZqsS9cdAittCNvVENElA= -google.golang.org/genproto/googleapis/api v0.0.0-20260401024825-9d38bb4040a9/go.mod h1:7QBABkRtR8z+TEnmXTqIqwJLlzrZKVfAUm7tY3yGv0M= -google.golang.org/genproto/googleapis/rpc v0.0.0-20260401024825-9d38bb4040a9 h1:m8qni9SQFH0tJc1X0vmnpw/0t+AImlSvp30sEupozUg= -google.golang.org/genproto/googleapis/rpc v0.0.0-20260401024825-9d38bb4040a9/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8= -google.golang.org/grpc v1.80.0 h1:Xr6m2WmWZLETvUNvIUmeD5OAagMw3FiKmMlTdViWsHM= -google.golang.org/grpc v1.80.0/go.mod h1:ho/dLnxwi3EDJA4Zghp7k2Ec1+c2jqup0bFkw07bwF4= -google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE= -google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/guregu/null.v3 v3.3.0 h1:8j3ggqq+NgKt/O7mbFVUFKUMWN+l1AmT5jQmJ6nPh2c= -gopkg.in/guregu/null.v3 v3.3.0/go.mod h1:E4tX2Qe3h7QdL+uZ3a0vqvYwKQsRSQKM5V4YltdgH9Y= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/.github/workflows/xk6-tests/xk6-output-test/outputtest.go b/.github/workflows/xk6-tests/xk6-output-test/outputtest.go deleted file mode 100644 index bf06b938f..000000000 --- a/.github/workflows/xk6-tests/xk6-output-test/outputtest.go +++ /dev/null @@ -1,58 +0,0 @@ -package outputtest - -import ( - "io" - "strconv" - - "go.k6.io/k6/v2/metrics" - "go.k6.io/k6/v2/output" -) - -func init() { - output.RegisterExtension("outputtest", func(params output.Params) (output.Output, error) { - return &Output{params: params}, nil - }) -} - -// Output is meant to test xk6 and the output extension sub-system of k6. -type Output struct { - params output.Params - calcResult float64 - outputFile io.WriteCloser -} - -// Description returns a human-readable description of the output. -func (o *Output) Description() string { - return "test output extension" -} - -// Start opens the specified output file. -func (o *Output) Start() error { - out, err := o.params.FS.Create(o.params.ConfigArgument) - if err != nil { - return err - } - o.outputFile = out - - return nil -} - -// AddMetricSamples just plucks out the metric we're interested in. -func (o *Output) AddMetricSamples(sampleContainers []metrics.SampleContainer) { - for _, sc := range sampleContainers { - for _, sample := range sc.GetSamples() { - if sample.Metric.Name == "foos" { - o.calcResult += sample.Value - } - } - } -} - -// Stop saves the dummy results and closes the file. -func (o *Output) Stop() error { - _, err := o.outputFile.Write([]byte(strconv.FormatFloat(o.calcResult, 'f', 0, 64))) - if err != nil { - return err - } - return o.outputFile.Close() -} diff --git a/.github/workflows/xk6-tests/xk6-test.js b/.github/workflows/xk6-tests/xk6-test.js deleted file mode 100644 index 093bad76c..000000000 --- a/.github/workflows/xk6-tests/xk6-test.js +++ /dev/null @@ -1,23 +0,0 @@ - -import { check } from 'k6'; -import jsexttest from 'k6/x/jsexttest'; - -export let options = { - iterations: 5, - thresholds: { - checks: ['rate===1'], - } -}; - -export function handleSummary(data) { - return { - 'summary-results.txt': data.metrics.foos.values.count.toString(), - }; -} - - -export default function () { - check(null, { - "foo is true": () => jsexttest.foo(__ITER), - }); -} \ No newline at end of file diff --git a/.github/workflows/xk6.yml b/.github/workflows/xk6.yml deleted file mode 100644 index 4efcd1611..000000000 --- a/.github/workflows/xk6.yml +++ /dev/null @@ -1,106 +0,0 @@ -name: xk6 -on: - # Enable manually triggering this workflow via the API or web UI - workflow_dispatch: - push: - branches: - - master - - v1.x - pull_request: - paths-ignore: - - 'docs/**' - - 'release notes/**' - -defaults: - run: - shell: bash - -permissions: - contents: read - -jobs: - test-xk6: - strategy: - fail-fast: false - matrix: - go: [stable, tip] - platform: [ubuntu-latest, ubuntu-24.04-arm, windows-latest, macos-latest] - runs-on: ${{ matrix.platform }} - steps: - - name: Checkout code - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 - with: - persist-credentials: false - - name: Resolve Go versions - id: go_versions - if: matrix.go != 'tip' - uses: grafana/k6-ci/.github/actions/go-versions@03469f9ae7aad25369827832c456e8f8b7b8c1c2 # v0.5.0 - - name: Install Go - if: matrix.go != 'tip' - uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6 - with: - go-version: ${{ steps.go_versions.outputs.current }} - check-latest: true - - name: Download Go tip - if: matrix.go == 'tip' - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - gh release download ${{ matrix.platform }} --repo grafana/gotip --pattern 'go.zip' - - name: Install Go tip - if: matrix.go == 'tip' - run: | - unzip go.zip -d $HOME/sdk - echo "GOROOT=$HOME/sdk/gotip" >> "$GITHUB_ENV" - echo "GOPATH=$HOME/go" >> "$GITHUB_ENV" - echo "$HOME/go/bin" >> "$GITHUB_PATH" - echo "$HOME/sdk/gotip/bin" >> "$GITHUB_PATH" - - name: Run tests - env: - PR_REPO: ${{ github.event.pull_request.head.repo.full_name }} - run: | - set -x - which go - go version - - export CGO_ENABLED=0 - - COMMIT_ID="${{ github.event.pull_request.head.sha }}" - if [[ "$COMMIT_ID" == "" ]]; then - COMMIT_ID="$(git rev-parse HEAD)" # branch, not PR merge commit - fi - echo "COMMIT_ID=$COMMIT_ID" - cd .github/workflows/xk6-tests - go install go.k6.io/xk6/cmd/xk6@master - GOPRIVATE="go.k6.io/k6" - if [ "${{ github.event_name }}" == "pull_request" -a \ - "${PR_REPO}" != "${{ github.repository }}" ]; then - export XK6_K6_REPO="github.com/${PR_REPO}" - GOPRIVATE="${GOPRIVATE},${XK6_K6_REPO}" - fi - # The following is a workaround for Windows, cause when using 'shell: bash', the PATH is expressed - # with ':' as separator, but Go code, running on a Windows OS, expects ';' as separator. - XPATH="$PATH" - if [[ "${{ matrix.platform }}" == "windows-latest" || "${{ matrix.platform }}" == "windows-latest" ]]; then - XPATH="$HOME/sdk/gotip/bin;$XPATH" - fi - PATH="$XPATH" \ - GOPRIVATE="${GOPRIVATE}" xk6 build "$COMMIT_ID" \ - --output ./k6ext \ - --with github.com/grafana/xk6-js-test="$(pwd)/xk6-js-test" \ - --with github.com/grafana/xk6-output-test="$(pwd)/xk6-output-test" - export K6_NO_USAGE_REPORT=true - ./k6ext version - ./k6ext run --out outputtest=output-results.txt xk6-test.js - - OUTPUT_RESULT="$(cat output-results.txt)" - if [[ "$OUTPUT_RESULT" != "10" ]]; then - echo "output result was not as expected: $OUTPUT_RESULT" - exit 11 - fi - - SUMMARY_RESULT="$(cat summary-results.txt)" - if [[ "$SUMMARY_RESULT" != "10" ]]; then - echo "summary result was not as expected: $SUMMARY_RESULT" - exit 12 - fi diff --git a/AGENTS.md b/AGENTS.md index 320d2a736..c02b86182 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,11 +1,11 @@ -## Fork Policy (jgaalen/k6) +## Fork Policy (Breaking-IT/k6) -This repository is a personal fork of grafana/k6 with private modifications +This repository is the public Breaking-IT fork of grafana/k6 with BreakTest modifications (lean cloud-free builds via the `lean` build tag, the breakingit output, etc.). - **Never push to upstream (grafana/k6).** Upstream is fetch-only: pull releases from it and merge them into this fork's branches, then push only to `origin` - (github.com/jgaalen/k6). + (github.com/Breaking-IT/k6). - After cloning this fork, disable pushes to upstream once: ```bash git remote add upstream https://github.com/grafana/k6.git @@ -17,7 +17,7 @@ This repository is a personal fork of grafana/k6 with private modifications `breakingit` work is consolidated there; do not use upstream as a replacement for it. - To pull in a new stable upstream release: fetch upstream tags, create an integration branch from `origin/master`, merge the release tag, and open a tested pull request - against jgaalen/k6 `master`. Gate any new cloud functionality behind `//go:build !lean` + against Breaking-IT/k6 `master`. Gate any new cloud functionality behind `//go:build !lean` (see `internal/cmd/cloud_lean.go` for the stub pattern). Release binaries are built with `-tags lean` (`./build-linux-binaries.sh`). diff --git a/FORK.md b/FORK.md index 0b6b01551..6802e5f22 100644 --- a/FORK.md +++ b/FORK.md @@ -36,20 +36,20 @@ code to the k6 executable. - Restores metric context correctly when native promise settlement re-enters the runtime, preventing browser group paths from accumulating across iterations. - Excludes upstream's Grafana-specific Renovate approval automation. -- Restricts inherited release publishing and Windows signing to the upstream repository. +- Runs lean release builds and fork regression tests on standard Linux GitHub Actions runners. -## Development and builds in jgaalen/k6 +## Development and builds in Breaking-IT/k6 `master` is the default development and build branch, based on upstream k6 v2.3.0. It includes the consolidated `breakingit` customizations, native group transactions and browser group-context fix. Browser admission control remains reverted. Create feature branches from `origin/master` -and merge tested pull requests into `master` in jgaalen/k6. +and merge tested pull requests into `master` in Breaking-IT/k6. Track stable upstream releases: fetch tags from `upstream`, create an integration branch from `origin/master`, and merge the new release tag into that branch. Preserve the fork changes, -validate normal and lean builds, and open a pull request against jgaalen/k6 `master`. Do not +validate normal and lean builds, and open a pull request against Breaking-IT/k6 `master`. Do not replace the fork branch with upstream history. The `upstream` remote is fetch-only; keep its -push URL set to `DISABLED` and push only to `origin` (jgaalen/k6). +push URL set to `DISABLED` and push only to `origin` (Breaking-IT/k6). ```sh git switch master diff --git a/README.md b/README.md index 5ea9e5a36..0fee66c56 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@

Github release - Build status + Breaking-IT lean CI Go Report Card Codecov branch
From 4121a15e29e12d91804e8ce139a76bea217b8c32 Mon Sep 17 00:00:00 2001 From: jgaalen Date: Fri, 6 Nov 2026 07:33:19 +0100 Subject: [PATCH 182/182] Launch the hosted Chrome binary for lean browser tests --- .github/workflows/lean.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/lean.yml b/.github/workflows/lean.yml index 0c04faeff..ec2c863be 100644 --- a/.github/workflows/lean.yml +++ b/.github/workflows/lean.yml @@ -43,6 +43,9 @@ jobs: ./internal/cmd ./internal/cmd/tests ./internal/api ./internal/js ./internal/features \ ./internal/js/modules/k6 ./internal/output/breakingit ./lib/netext/httpext ./metrics ./output - name: Run Chromium group regression tests + env: + K6_BROWSER_EXECUTABLE_PATH: /usr/bin/google-chrome + K6_BROWSER_ARGS: no-sandbox run: | go test -race -tags lean -parallel 1 -timeout 15m \ -run '^(TestAsyncGroup|TestBrowserGroupTransactionOutcomes)' ./internal/js/modules/k6/browser/tests